ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/special.C
Revision: 1.46
Committed: Tue Apr 13 02:52:10 2010 UTC (14 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.45: +2 -0 lines
Log Message:
ring mountain book

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.26 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.16 *
4 root 1.41 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.40 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992 Frank Tore Johansen
7 pippijn 1.16 *
8 root 1.37 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 pippijn 1.16 *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 root 1.24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 pippijn 1.16 * GNU General Public License for more details.
17     *
18 root 1.37 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.24 *
22 root 1.26 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.16 */
24 elmex 1.1
25     /* Specials in this file:
26 root 1.2 included maps */
27 elmex 1.1
28     #include <global.h>
29     #include <random_map.h>
30     #include <rproto.h>
31    
32     #define NUM_OF_SPECIAL_TYPES 4
33     #define NO_SPECIAL 0
34     #define SPECIAL_SUBMAP 1
35     #define SPECIAL_FOUNTAIN 2
36     #define SPECIAL_EXIT 3
37    
38     #define GLORY_HOLE 1
39     #define ORC_ZONE 2
40     #define MINING_ZONE 3
41     #define NR_OF_HOLE_TYPES 3
42    
43 root 1.32 /* clear map completely of all !floor objects:
44     * a rectangular area of xsize, ysize
45     * is cleared with the top left corner at xstart, ystart
46     */
47     static void
48     nuke_map_region (maptile *map, char **layout, int xstart, int ystart, int xsize, int ysize)
49 root 1.4 {
50 root 1.32 for (int i = xstart; i < xstart + xsize; i++)
51     for (int j = ystart; j < ystart + ysize; j++)
52     {
53     layout[i][j] = 'S';
54 root 1.4
55 root 1.32 for (object *tmp = map->at (i, j).bot; tmp; )
56     if (tmp->flag [FLAG_IS_FLOOR])
57     tmp = tmp->above;
58     else
59     {
60     object *head = tmp->head_ ();
61     tmp = tmp->above;
62 root 1.35 head->destroy ();
63 root 1.32 }
64 elmex 1.1 }
65     }
66    
67 root 1.4 /* copy in_map into dest_map at point x,y */
68 root 1.32 static void
69 root 1.6 include_map_in_map (maptile *dest_map, maptile *in_map, int x, int y)
70 root 1.4 {
71 root 1.30 for (int i = 0; i < in_map->width; i++)
72     for (int j = 0; j < in_map->height; j++)
73     for (object *tmp = GET_MAP_OB (in_map, i, j); tmp; tmp = tmp->above)
74     {
75 root 1.32 /* don't copy tails: must be dealt with specially. */
76 root 1.30 if (!tmp->is_head ())
77     continue;
78    
79 root 1.31 object *new_ob = tmp->deep_clone ();
80 root 1.30
81 root 1.44 if (tmp->flag [FLAG_IS_LINKED])
82 root 1.36 new_ob->add_link (dest_map, tmp->find_link ()->id);
83 root 1.30
84 root 1.31 dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON);
85 root 1.30 }
86 elmex 1.1 }
87    
88 root 1.32 static int
89 root 1.6 find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize)
90 root 1.4 {
91 root 1.32 int blocked, i, j;
92 root 1.4
93 elmex 1.1 /* don't even try to place a submap into a map if the big map isn't
94     sufficiently large. */
95 root 1.10 if (2 * xsize > map->width || 2 * ysize > map->height)
96 root 1.4 return 0;
97    
98 elmex 1.1 /* search a bit for a completely free spot. */
99 root 1.32 for (int tries = 0; tries < 20; tries++)
100 root 1.4 {
101 root 1.32 blocked = 0;
102    
103 root 1.4 /* pick a random location in the layout */
104 root 1.33 i = rmg_rndm (1, map->width - xsize - 2);
105     j = rmg_rndm (1, map->height - ysize - 2);
106 root 1.32
107     for (int l = i; l < i + xsize; l++)
108     for (int m = j; m < j + ysize; m++)
109     {
110     blocked = 1;
111     break;
112     }
113    
114     if (!blocked)
115 root 1.4 break;
116     }
117    
118 elmex 1.1 /* if we failed, relax the restrictions */
119 root 1.32 if (blocked)
120 root 1.4 { /* failure, try a relaxed placer. */
121     /* pick a random location in the layout */
122 root 1.32 for (int tries = 0; tries < 10; tries++)
123 root 1.4 {
124 root 1.33 i = rmg_rndm (1, map->width - xsize - 2);
125     j = rmg_rndm (1, map->height - ysize - 2);
126 root 1.32
127     blocked = 0;
128    
129     for (int l = i; l < i + xsize; l++)
130     for (int m = j; m < j + ysize; m++)
131     if (layout[l][m] != '#' && layout[l][m] != 'D' && layout[l][m] != 0)
132     {
133     blocked = 1;
134     break;
135     }
136 root 1.4 }
137 elmex 1.1 }
138 root 1.27
139 root 1.32 if (blocked)
140 root 1.4 return 0;
141 root 1.27
142 root 1.4 *ix = i;
143     *iy = j;
144 root 1.32
145 elmex 1.1 return 1;
146 root 1.4 }
147 elmex 1.1
148 root 1.32 static void
149 root 1.6 place_fountain_with_specials (maptile *map)
150 root 1.4 {
151     int ix, iy, i = -1, tries = 0;
152 root 1.6 maptile *fountain_style = find_style ("/styles/misc", "fountains", -1);
153 root 1.18
154     if (!fountain_style)
155 root 1.19 {
156 pippijn 1.20 LOG (llevError, "unable to load stylemap /styles/misc fountains\n");
157 root 1.19 return;
158     }
159 root 1.18
160 root 1.32 object *fountain = archetype::get (shstr_fountain);
161     object *potion = fountain_style->pick_random_object (rmg_rndm)->clone ();
162 root 1.4
163     while (i < 0 && tries < 10)
164     {
165 root 1.32 ix = rmg_rndm (map->width - 2) + 1;
166     iy = rmg_rndm (map->height - 2) + 1;
167 root 1.45 i = rmg_find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1);
168 root 1.4 tries++;
169 root 1.8 }
170    
171 root 1.4 if (i == -1)
172     { /* can't place fountain */
173 root 1.35 fountain->destroy ();
174     potion->destroy ();
175 root 1.4 return;
176     }
177 root 1.8
178 elmex 1.1 ix += freearr_x[i];
179     iy += freearr_y[i];
180 root 1.4 potion->face = fountain->face;
181 root 1.44 potion->set_flag (FLAG_NO_PICK);
182     potion->set_flag (FLAG_IDENTIFIED);
183 root 1.38 potion->name = potion->name_pl = shstr_fountain;
184 elmex 1.1 potion->x = ix;
185     potion->y = iy;
186 root 1.38 potion->material = name_to_material (shstr_adamantium);
187 elmex 1.1 fountain->x = ix;
188     fountain->y = iy;
189 root 1.4 insert_ob_in_map (fountain, map, NULL, 0);
190     insert_ob_in_map (potion, map, NULL, 0);
191 elmex 1.1 }
192    
193 root 1.32 static void
194 root 1.12 place_special_exit (maptile *map, int hole_type, random_map_params *RP)
195 root 1.4 {
196 root 1.43 maptile *exit_style = find_style ("/styles/misc", "obscure_exits", RP->difficulty);
197 root 1.18 if (!exit_style)
198 root 1.19 {
199 root 1.28 LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n");
200 root 1.19 return;
201     }
202 root 1.18
203 root 1.4 if (!exit_style)
204     return;
205    
206 root 1.32 object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone ();
207 root 1.4
208 root 1.25 // put an upper bound here, just in case
209     for (int repeat = 8192; --repeat; )
210 root 1.4 {
211 root 1.45 int ix = rmg_rndm (1, map->width - 2);
212     int iy = rmg_rndm (1, map->height - 2);
213 root 1.25
214 root 1.45 int i = rmg_find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1);
215 root 1.25 if (i >= 0)
216     {
217 root 1.45 the_exit->x = ix + freearr_x[i];
218     the_exit->y = iy + freearr_y[i];
219 root 1.25 break;
220     }
221 elmex 1.1 }
222 root 1.4
223     if (!hole_type)
224 root 1.32 hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1;
225 root 1.4
226 root 1.45 char buf[16384];
227     const char *style, *decor, *mon;
228     int g_xsize, g_ysize;
229    
230 root 1.4 switch (hole_type)
231     {
232 root 1.12 case GLORY_HOLE: /* treasures */
233     {
234 root 1.32 g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4;
235     g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4;
236 root 1.12 style = "onion";
237     decor = "wealth2";
238     mon = "none";
239     break;
240     }
241 root 1.4
242 root 1.12 case ORC_ZONE: /* hole with orcs in it. */
243     {
244 root 1.32 g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4;
245     g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4;
246 root 1.12 style = "onion";
247     decor = "wealth2";
248     mon = "orc";
249     break;
250     }
251 root 1.4
252 root 1.12 case MINING_ZONE: /* hole with orcs in it. */
253     {
254 root 1.32 g_xsize = rmg_rndm (9) + 4 + RP->difficulty / 4;
255     g_ysize = rmg_rndm (9) + 4 + RP->difficulty / 4;
256 root 1.12 style = "maze";
257     decor = "minerals2";
258     mon = "none";
259     break;
260     }
261 root 1.4
262 root 1.12 default: /* undefined */
263     LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type);
264     return;
265 elmex 1.1 }
266    
267 root 1.4 /* Need to be at least this size, otherwise the load
268     * code will generate new size values which are too large.
269     */
270 root 1.45 max_it (g_xsize, MIN_RANDOM_MAP_SIZE);
271     max_it (g_ysize, MIN_RANDOM_MAP_SIZE);
272    
273     {
274     random_map_params &rp = *new random_map_params; // for zero_intiialised to work...
275    
276     rp.xsize = g_xsize;
277     rp.ysize = g_ysize;
278    
279     assign (rp.wallstyle , RP->wallstyle);
280     assign (rp.floorstyle , RP->floorstyle);
281     assign (rp.monsterstyle , mon);
282     assign (rp.treasurestyle, "none");
283     assign (rp.layoutstyle , style);
284     assign (rp.decorstyle , decor);
285     assign (rp.exitstyle , RP->exitstyle);
286    
287     rp.layoutoptions1 = RMOPT_WALLS_ONLY;
288     rp.symmetry = SYMMETRY_NONE;
289     rp.dungeon_depth = RP->dungeon_level;
290     rp.dungeon_level = RP->dungeon_level;
291     rp.difficulty = RP->difficulty;
292     rp.difficulty_given = RP->difficulty;
293     rp.difficulty_increase = RP->difficulty_increase;
294     rp.decoroptions = -1;
295     rp.orientation = 1;
296     rp.random_seed = RP->random_seed ^ 0xdeadbeef;
297     rp.region = RP->region;
298 root 1.46 rp.difficulty=99;//D
299 root 1.45
300     write_map_parameters_to_string (buf, &rp);
301     delete &rp;
302     }
303 root 1.4
304 root 1.39 the_exit->slaying = shstr_random_map_exit;
305 root 1.4 the_exit->msg = buf;
306 elmex 1.1
307 root 1.4 insert_ob_in_map (the_exit, map, NULL, 0);
308 elmex 1.1 }
309 root 1.4
310     void
311 root 1.12 place_specials_in_map (maptile *map, char **layout, random_map_params *RP)
312 root 1.4 {
313 root 1.46 for(int i=0;i<100;++i)//D
314 root 1.32 switch (rmg_rndm (NUM_OF_SPECIAL_TYPES))
315 root 1.4 {
316 root 1.19 case SPECIAL_SUBMAP:
317 root 1.32 {
318     /* includes a special map into the random map being made. */
319     maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty);
320    
321     if (!special_map)
322     break;
323 root 1.4
324 root 1.32 int ix, iy; /* map insertion locatons */
325 root 1.19
326 root 1.32 if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height))
327     {
328     /* First, splatter everything in the dest map at the location */
329     nuke_map_region (map, layout, ix, iy, special_map->width, special_map->height);
330     include_map_in_map (map, special_map, ix, iy);
331     }
332     }
333 root 1.12
334 root 1.19 break;
335 root 1.4
336 root 1.19 case SPECIAL_FOUNTAIN:
337 root 1.12 /* Make a special fountain: an unpickable potion disguised as
338     a fountain, or rather, colocated with a fountain. */
339 root 1.19 place_fountain_with_specials (map);
340     break;
341 root 1.4
342 root 1.19 case SPECIAL_EXIT:
343 root 1.12 /* Make an exit to another random map, e.g. a gloryhole. */
344 root 1.45 //place_special_exit (map, 0, RP);
345     place_special_exit (map, GLORY_HOLE, RP);
346 root 1.19 break;
347 root 1.4 }
348 root 1.27 }
349 elmex 1.1