1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <time.h> |
25 | #include <time.h> |
… | |
… | |
26 | #include <global.h> |
27 | #include <global.h> |
27 | #include <random_map.h> |
28 | #include <random_map.h> |
28 | #include <rproto.h> |
29 | #include <rproto.h> |
29 | #include <sproto.h> |
30 | #include <sproto.h> |
30 | |
31 | |
31 | #define CEDE coroapi::cede_to_tick (); rndm.seed (RP->random_seed + __LINE__); |
32 | #define CEDE coroapi::cede_to_tick () |
32 | |
33 | |
33 | static void symmetrize_layout (Layout maze, random_map_params *RP); |
34 | static void symmetrize_layout (Layout maze, random_map_params *RP); |
34 | static void rotate_layout (Layout maze, int rotation); |
35 | static void rotate_layout (Layout maze, int rotation); |
35 | |
36 | |
36 | void |
37 | void |
… | |
… | |
43 | |
44 | |
44 | putc ('\n', stdout); |
45 | putc ('\n', stdout); |
45 | } |
46 | } |
46 | |
47 | |
47 | putc ('\n', stdout); |
48 | putc ('\n', stdout); |
48 | } |
|
|
49 | |
|
|
50 | bool |
|
|
51 | maptile::generate_random_map (random_map_params *RP) |
|
|
52 | { |
|
|
53 | char buf[16384]; |
|
|
54 | int i; |
|
|
55 | |
|
|
56 | RP->Xsize = RP->xsize; |
|
|
57 | RP->Ysize = RP->ysize; |
|
|
58 | |
|
|
59 | /* pick a random seed, or use the one from the input file */ |
|
|
60 | RP->random_seed = RP->random_seed |
|
|
61 | ? RP->random_seed + RP->dungeon_level |
|
|
62 | : time (0); |
|
|
63 | CEDE; |
|
|
64 | |
|
|
65 | write_map_parameters_to_string (buf, RP); |
|
|
66 | |
|
|
67 | if (RP->difficulty == 0) |
|
|
68 | { |
|
|
69 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
|
|
70 | |
|
|
71 | if (RP->difficulty_increase > 0.001) |
|
|
72 | RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); |
|
|
73 | |
|
|
74 | if (RP->difficulty < 1) |
|
|
75 | RP->difficulty = 1; |
|
|
76 | } |
|
|
77 | else |
|
|
78 | RP->difficulty_given = 1; |
|
|
79 | |
|
|
80 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
|
|
81 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
|
|
82 | |
|
|
83 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
|
|
84 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
|
|
85 | |
|
|
86 | if (RP->symmetry == SYMMETRY_RANDOM) |
|
|
87 | RP->symmetry_used = rndm (SYMMETRY_XY) + 1; |
|
|
88 | else |
|
|
89 | RP->symmetry_used = RP->symmetry; |
|
|
90 | |
|
|
91 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
|
|
92 | RP->Ysize = RP->Ysize / 2 + 1; |
|
|
93 | |
|
|
94 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
|
|
95 | RP->Xsize = RP->Xsize / 2 + 1; |
|
|
96 | |
|
|
97 | if (RP->expand2x > 0) |
|
|
98 | { |
|
|
99 | RP->Xsize /= 2; |
|
|
100 | RP->Ysize /= 2; |
|
|
101 | } |
|
|
102 | |
|
|
103 | RP->map_layout_style = LAYOUT_NONE; |
|
|
104 | |
|
|
105 | /* Redo this - there was a lot of redundant code of checking for preset |
|
|
106 | * layout style and then random layout style. Instead, figure out |
|
|
107 | * the numeric layoutstyle, so there is only one area that actually |
|
|
108 | * calls the code to make the maps. |
|
|
109 | */ |
|
|
110 | if (strstr (RP->layoutstyle, "onion")) |
|
|
111 | RP->map_layout_style = LAYOUT_ONION; |
|
|
112 | else if (strstr (RP->layoutstyle, "maze")) |
|
|
113 | RP->map_layout_style = LAYOUT_MAZE; |
|
|
114 | else if (strstr (RP->layoutstyle, "spiral")) |
|
|
115 | RP->map_layout_style = LAYOUT_SPIRAL; |
|
|
116 | else if (strstr (RP->layoutstyle, "rogue")) |
|
|
117 | RP->map_layout_style = LAYOUT_ROGUELIKE; |
|
|
118 | else if (strstr (RP->layoutstyle, "snake")) |
|
|
119 | RP->map_layout_style = LAYOUT_SNAKE; |
|
|
120 | else if (strstr (RP->layoutstyle, "squarespiral")) |
|
|
121 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
|
|
122 | else if (RP->map_layout_style == LAYOUT_NONE) |
|
|
123 | RP->map_layout_style = rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ |
|
|
124 | else |
|
|
125 | abort (); |
|
|
126 | |
|
|
127 | Layout layout = layoutgen (RP); |
|
|
128 | |
|
|
129 | #ifdef RMAP_DEBUG |
|
|
130 | dump_layout (layout); |
|
|
131 | #endif |
|
|
132 | |
|
|
133 | /* increment these for the current map */ |
|
|
134 | ++RP->dungeon_level; |
|
|
135 | |
|
|
136 | // need to patch RP becasue following code doesn't use the Layout object |
|
|
137 | RP->Xsize = layout->w; |
|
|
138 | RP->Ysize = layout->h; |
|
|
139 | |
|
|
140 | /* allocate the map and set the floor */ |
|
|
141 | make_map_floor (layout, RP->floorstyle, RP); |
|
|
142 | |
|
|
143 | /* set region */ |
|
|
144 | default_region = RP->region; |
|
|
145 | |
|
|
146 | CEDE; |
|
|
147 | |
|
|
148 | /* create walls unless the wallstyle is "none" */ |
|
|
149 | if (strcmp (RP->wallstyle, "none")) |
|
|
150 | { |
|
|
151 | make_map_walls (this, layout, RP->wallstyle, RP); |
|
|
152 | |
|
|
153 | /* place doors unless doorstyle or wallstyle is "none" */ |
|
|
154 | if (strcmp (RP->doorstyle, "none")) |
|
|
155 | put_doors (this, layout, RP->doorstyle, RP); |
|
|
156 | } |
|
|
157 | |
|
|
158 | CEDE; |
|
|
159 | |
|
|
160 | /* create exits unless the exitstyle is "none" */ |
|
|
161 | if (strcmp (RP->exitstyle, "none")) |
|
|
162 | place_exits (this, layout, RP->exitstyle, RP->orientation, RP); |
|
|
163 | |
|
|
164 | CEDE; |
|
|
165 | |
|
|
166 | place_specials_in_map (this, layout, RP); |
|
|
167 | |
|
|
168 | CEDE; |
|
|
169 | |
|
|
170 | /* create monsters unless the monsterstyle is "none" */ |
|
|
171 | if (strcmp (RP->monsterstyle, "none")) |
|
|
172 | place_monsters (this, RP->monsterstyle, RP->difficulty, RP); |
|
|
173 | |
|
|
174 | CEDE; |
|
|
175 | |
|
|
176 | /* treasures needs to have a proper difficulty set for the map. */ |
|
|
177 | difficulty = estimate_difficulty (); |
|
|
178 | |
|
|
179 | CEDE; |
|
|
180 | |
|
|
181 | /* create treasure unless the treasurestyle is "none" */ |
|
|
182 | if (strcmp (RP->treasurestyle, "none")) |
|
|
183 | place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); |
|
|
184 | |
|
|
185 | CEDE; |
|
|
186 | |
|
|
187 | /* create decor unless the decorstyle is "none" */ |
|
|
188 | if (strcmp (RP->decorstyle, "none")) |
|
|
189 | put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); |
|
|
190 | |
|
|
191 | CEDE; |
|
|
192 | |
|
|
193 | /* generate treasures, etc. */ |
|
|
194 | fix_auto_apply (); |
|
|
195 | |
|
|
196 | CEDE; |
|
|
197 | |
|
|
198 | unblock_exits (this, layout, RP); |
|
|
199 | |
|
|
200 | msg = strdup (buf); |
|
|
201 | in_memory = MAP_ACTIVE; |
|
|
202 | |
|
|
203 | CEDE; |
|
|
204 | |
|
|
205 | return 1; |
|
|
206 | } |
|
|
207 | |
|
|
208 | /* function selects the layout function and gives it whatever |
|
|
209 | arguments it needs. */ |
|
|
210 | Layout |
|
|
211 | layoutgen (random_map_params *RP) |
|
|
212 | { |
|
|
213 | Layout layout (RP); |
|
|
214 | |
|
|
215 | switch (RP->map_layout_style) |
|
|
216 | { |
|
|
217 | case LAYOUT_ONION: |
|
|
218 | map_gen_onion (layout, RP->layoutoptions1, RP->layoutoptions2); |
|
|
219 | |
|
|
220 | if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
|
|
221 | roomify_layout (layout, RP); |
|
|
222 | |
|
|
223 | break; |
|
|
224 | |
|
|
225 | case LAYOUT_MAZE: |
|
|
226 | maze_gen (layout, rndm (2)); |
|
|
227 | |
|
|
228 | if (!(rndm (2))) |
|
|
229 | doorify_layout (layout, RP); |
|
|
230 | |
|
|
231 | break; |
|
|
232 | |
|
|
233 | case LAYOUT_SPIRAL: |
|
|
234 | map_gen_spiral (layout, RP->layoutoptions1); |
|
|
235 | |
|
|
236 | if (!(rndm (2))) |
|
|
237 | doorify_layout (layout, RP); |
|
|
238 | |
|
|
239 | break; |
|
|
240 | |
|
|
241 | case LAYOUT_ROGUELIKE: |
|
|
242 | /* Don't put symmetry in rogue maps. There isn't much reason to |
|
|
243 | * do so in the first place (doesn't make it any more interesting), |
|
|
244 | * but more importantly, the symmetry code presumes we are symmetrizing |
|
|
245 | * spirals, or maps with lots of passages - making a symmetric rogue |
|
|
246 | * map fails because its likely that the passages the symmetry process |
|
|
247 | * creates may not connect the rooms. |
|
|
248 | */ |
|
|
249 | RP->symmetry_used = SYMMETRY_NONE; |
|
|
250 | roguelike_layout_gen (layout, RP->layoutoptions1); |
|
|
251 | /* no doorifying... done already */ |
|
|
252 | break; |
|
|
253 | |
|
|
254 | case LAYOUT_SNAKE: |
|
|
255 | make_snake_layout (layout, RP->layoutoptions1); |
|
|
256 | |
|
|
257 | if (rndm (2)) |
|
|
258 | roomify_layout (layout, RP); |
|
|
259 | |
|
|
260 | break; |
|
|
261 | |
|
|
262 | case LAYOUT_SQUARE_SPIRAL: |
|
|
263 | make_square_spiral_layout (layout, RP->layoutoptions1); |
|
|
264 | |
|
|
265 | if (rndm (2)) |
|
|
266 | roomify_layout (layout, RP); |
|
|
267 | |
|
|
268 | break; |
|
|
269 | |
|
|
270 | default: |
|
|
271 | abort (); |
|
|
272 | } |
|
|
273 | |
|
|
274 | /* rotate the layout randomly */ |
|
|
275 | rotate_layout (layout, rndm (4)); |
|
|
276 | |
|
|
277 | symmetrize_layout (layout, RP); |
|
|
278 | |
|
|
279 | #ifdef RMAP_DEBUG |
|
|
280 | dump_layout (layout); |
|
|
281 | #endif |
|
|
282 | |
|
|
283 | if (RP->expand2x) |
|
|
284 | expand2x (layout); |
|
|
285 | |
|
|
286 | return layout; |
|
|
287 | } |
49 | } |
288 | |
50 | |
289 | /* takes a map and makes it symmetric: adjusts Xsize and |
51 | /* takes a map and makes it symmetric: adjusts Xsize and |
290 | * Ysize to produce a symmetric map. |
52 | * Ysize to produce a symmetric map. |
291 | */ |
53 | */ |
… | |
… | |
382 | } |
144 | } |
383 | break; |
145 | break; |
384 | } |
146 | } |
385 | } |
147 | } |
386 | |
148 | |
387 | /* take a layout and make some rooms in it. |
|
|
388 | --works best on onions.*/ |
|
|
389 | void |
|
|
390 | roomify_layout (char **maze, random_map_params *RP) |
|
|
391 | { |
|
|
392 | int tries = RP->Xsize * RP->Ysize / 30; |
|
|
393 | int ti; |
|
|
394 | |
|
|
395 | for (ti = 0; ti < tries; ti++) |
|
|
396 | { |
|
|
397 | int dx, dy; /* starting location for looking at creating a door */ |
|
|
398 | int cx, cy; /* results of checking on creating walls. */ |
|
|
399 | |
|
|
400 | dx = rndm (RP->Xsize); |
|
|
401 | dy = rndm (RP->Ysize); |
|
|
402 | |
|
|
403 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
|
|
404 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
|
|
405 | if (cx == -1) |
|
|
406 | { |
|
|
407 | if (cy != -1) |
|
|
408 | make_wall (maze, dx, dy, 1); |
|
|
409 | |
|
|
410 | continue; |
|
|
411 | } |
|
|
412 | |
|
|
413 | if (cy == -1) |
|
|
414 | { |
|
|
415 | make_wall (maze, dx, dy, 0); |
|
|
416 | continue; |
|
|
417 | } |
|
|
418 | |
|
|
419 | if (cx < cy) |
|
|
420 | make_wall (maze, dx, dy, 0); |
|
|
421 | else |
|
|
422 | make_wall (maze, dx, dy, 1); |
|
|
423 | } |
|
|
424 | } |
|
|
425 | |
|
|
426 | /* checks the layout to see if I can stick a horizontal(dir = 0) wall |
149 | /* checks the layout to see if I can stick a horizontal(dir = 0) wall |
427 | (or vertical, dir == 1) |
150 | (or vertical, dir == 1) |
428 | here which ends up on other walls sensibly. */ |
151 | here which ends up on other walls sensibly. */ |
429 | |
152 | static int |
430 | int |
|
|
431 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP) |
153 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP) |
432 | { |
154 | { |
433 | int i1; |
155 | int i1; |
434 | int length = 0; |
156 | int length = 0; |
435 | |
157 | |
… | |
… | |
499 | return -1; /* can't make verti. wall here */ |
221 | return -1; /* can't make verti. wall here */ |
500 | if (maze[x][i1] != 0) |
222 | if (maze[x][i1] != 0) |
501 | return -1; /* can't make horiz. wall here */ |
223 | return -1; /* can't make horiz. wall here */ |
502 | length++; |
224 | length++; |
503 | } |
225 | } |
|
|
226 | |
504 | return length; |
227 | return length; |
505 | } |
228 | } |
|
|
229 | |
506 | return -1; |
230 | return -1; |
507 | } |
231 | } |
508 | |
232 | |
|
|
233 | /* take a layout and make some rooms in it. |
|
|
234 | --works best on onions.*/ |
|
|
235 | static void |
|
|
236 | roomify_layout (char **maze, random_map_params *RP) |
|
|
237 | { |
|
|
238 | int tries = RP->Xsize * RP->Ysize / 30; |
|
|
239 | int ti; |
|
|
240 | |
|
|
241 | for (ti = 0; ti < tries; ti++) |
|
|
242 | { |
|
|
243 | int dx, dy; /* starting location for looking at creating a door */ |
|
|
244 | int cx, cy; /* results of checking on creating walls. */ |
|
|
245 | |
|
|
246 | dx = rmg_rndm (RP->Xsize); |
|
|
247 | dy = rmg_rndm (RP->Ysize); |
|
|
248 | |
|
|
249 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
|
|
250 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
|
|
251 | if (cx == -1) |
|
|
252 | { |
|
|
253 | if (cy != -1) |
|
|
254 | make_wall (maze, dx, dy, 1); |
|
|
255 | |
|
|
256 | continue; |
|
|
257 | } |
|
|
258 | |
|
|
259 | if (cy == -1) |
|
|
260 | { |
|
|
261 | make_wall (maze, dx, dy, 0); |
|
|
262 | continue; |
|
|
263 | } |
|
|
264 | |
|
|
265 | if (cx < cy) |
|
|
266 | make_wall (maze, dx, dy, 0); |
|
|
267 | else |
|
|
268 | make_wall (maze, dx, dy, 1); |
|
|
269 | } |
|
|
270 | } |
509 | |
271 | |
510 | int |
272 | int |
511 | make_wall (char **maze, int x, int y, int dir) |
273 | make_wall (char **maze, int x, int y, int dir) |
512 | { |
274 | { |
513 | maze[x][y] = 'D'; /* mark a door */ |
275 | maze[x][y] = 'D'; /* mark a door */ |
… | |
… | |
537 | |
299 | |
538 | return 0; |
300 | return 0; |
539 | } |
301 | } |
540 | |
302 | |
541 | /* puts doors at appropriate locations in a layout. */ |
303 | /* puts doors at appropriate locations in a layout. */ |
542 | void |
304 | static void |
543 | doorify_layout (char **maze, random_map_params *RP) |
305 | doorify_layout (char **maze, random_map_params *RP) |
544 | { |
306 | { |
545 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
307 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
546 | int doorlocs = 0; /* # of available doorlocations */ |
308 | int doorlocs = 0; /* # of available doorlocations */ |
547 | int i, j; |
|
|
548 | |
309 | |
549 | char *doorlist_x = salloc<char> (RP->Xsize * RP->Ysize); |
310 | uint16 *doorlist_x = salloc<uint16> (RP->Xsize * RP->Ysize); |
550 | char *doorlist_y = salloc<char> (RP->Xsize * RP->Ysize); |
311 | uint16 *doorlist_y = salloc<uint16> (RP->Xsize * RP->Ysize); |
551 | |
312 | |
552 | /* make a list of possible door locations */ |
313 | /* make a list of possible door locations */ |
553 | for (i = 1; i < RP->Xsize - 1; i++) |
314 | for (int i = 1; i < RP->Xsize - 1; i++) |
554 | for (j = 1; j < RP->Ysize - 1; j++) |
315 | for (int j = 1; j < RP->Ysize - 1; j++) |
555 | { |
316 | { |
556 | int sindex = surround_flag (maze, i, j, RP); |
317 | int sindex = surround_flag (maze, i, j, RP); |
557 | |
318 | |
558 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
319 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
559 | { |
320 | { |
… | |
… | |
563 | } |
324 | } |
564 | } |
325 | } |
565 | |
326 | |
566 | while (ndoors > 0 && doorlocs > 0) |
327 | while (ndoors > 0 && doorlocs > 0) |
567 | { |
328 | { |
568 | int di; |
|
|
569 | int sindex; |
|
|
570 | |
|
|
571 | di = rndm (doorlocs); |
329 | int di = rmg_rndm (doorlocs); |
572 | i = doorlist_x[di]; |
330 | int i = doorlist_x[di]; |
573 | j = doorlist_y[di]; |
331 | int j = doorlist_y[di]; |
574 | sindex = surround_flag (maze, i, j, RP); |
332 | int sindex = surround_flag (maze, i, j, RP); |
575 | |
333 | |
576 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
334 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
577 | { |
335 | { |
578 | maze[i][j] = 'D'; |
336 | maze[i][j] = 'D'; |
579 | ndoors--; |
337 | ndoors--; |
… | |
… | |
696 | { |
454 | { |
697 | sprintf (small_buf, "difficulty %d\n", RP->difficulty); |
455 | sprintf (small_buf, "difficulty %d\n", RP->difficulty); |
698 | strcat (buf, small_buf); |
456 | strcat (buf, small_buf); |
699 | } |
457 | } |
700 | |
458 | |
701 | if (RP->difficulty_increase != 1.0) |
459 | if (fabs (RP->difficulty_increase - 1.f) >= (1.f / 1024.f)) |
702 | { |
460 | { |
703 | sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase); |
461 | sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase); |
704 | strcat (buf, small_buf); |
462 | strcat (buf, small_buf); |
705 | } |
463 | } |
706 | |
464 | |
… | |
… | |
940 | sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); |
698 | sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); |
941 | strcat (buf, small_buf); |
699 | strcat (buf, small_buf); |
942 | } |
700 | } |
943 | } |
701 | } |
944 | |
702 | |
945 | /* copy an object with an inventory... i.e., duplicate the inv too. */ |
|
|
946 | void |
|
|
947 | copy_object_with_inv (object *src_ob, object *dest_ob)//TODO, replace by clone |
|
|
948 | { |
|
|
949 | object *walk, *tmp; |
|
|
950 | |
|
|
951 | src_ob->copy_to (dest_ob); |
|
|
952 | |
|
|
953 | for (walk = src_ob->inv; walk; walk = walk->below) |
|
|
954 | { |
|
|
955 | tmp = object::create (); |
|
|
956 | |
|
|
957 | walk->copy_to (tmp); |
|
|
958 | insert_ob_in_ob (tmp, dest_ob); |
|
|
959 | } |
|
|
960 | } |
|
|
961 | |
|
|
962 | ///////////////////////////////////////////////////////////////////////////// |
703 | ///////////////////////////////////////////////////////////////////////////// |
963 | |
704 | |
964 | LayoutData::LayoutData (int w, int h) |
705 | LayoutData::LayoutData (int w, int h) |
965 | : w(w), h(h) |
706 | : w(w), h(h) |
966 | { |
707 | { |
… | |
… | |
990 | { |
731 | { |
991 | for (int i = 0; i < w; i++) col [i][0] = col [i][h - 1] = fill; |
732 | for (int i = 0; i < w; i++) col [i][0] = col [i][h - 1] = fill; |
992 | for (int j = 0; j < h; j++) col [0][j] = col [w - 1][j] = fill; |
733 | for (int j = 0; j < h; j++) col [0][j] = col [w - 1][j] = fill; |
993 | } |
734 | } |
994 | |
735 | |
|
|
736 | /* function selects the layout function and gives it whatever |
|
|
737 | arguments it needs. */ |
|
|
738 | static Layout |
|
|
739 | layoutgen (random_map_params *RP) |
|
|
740 | { |
|
|
741 | Layout layout (RP); |
|
|
742 | |
|
|
743 | switch (RP->map_layout_style) |
|
|
744 | { |
|
|
745 | case LAYOUT_ONION: |
|
|
746 | map_gen_onion (layout, RP->layoutoptions1, RP->layoutoptions2); |
|
|
747 | |
|
|
748 | if (!(rmg_rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
|
|
749 | roomify_layout (layout, RP); |
|
|
750 | |
|
|
751 | break; |
|
|
752 | |
|
|
753 | case LAYOUT_MAZE: |
|
|
754 | maze_gen (layout, rmg_rndm (2)); |
|
|
755 | |
|
|
756 | if (!(rmg_rndm (2))) |
|
|
757 | doorify_layout (layout, RP); |
|
|
758 | |
|
|
759 | break; |
|
|
760 | |
|
|
761 | case LAYOUT_SPIRAL: |
|
|
762 | map_gen_spiral (layout, RP->layoutoptions1); |
|
|
763 | |
|
|
764 | if (!(rmg_rndm (2))) |
|
|
765 | doorify_layout (layout, RP); |
|
|
766 | |
|
|
767 | break; |
|
|
768 | |
|
|
769 | case LAYOUT_ROGUELIKE: |
|
|
770 | /* Don't put symmetry in rogue maps. There isn't much reason to |
|
|
771 | * do so in the first place (doesn't make it any more interesting), |
|
|
772 | * but more importantly, the symmetry code presumes we are symmetrizing |
|
|
773 | * spirals, or maps with lots of passages - making a symmetric rogue |
|
|
774 | * map fails because its likely that the passages the symmetry process |
|
|
775 | * creates may not connect the rooms. |
|
|
776 | */ |
|
|
777 | RP->symmetry_used = SYMMETRY_NONE; |
|
|
778 | roguelike_layout_gen (layout, RP->layoutoptions1); |
|
|
779 | /* no doorifying... done already */ |
|
|
780 | break; |
|
|
781 | |
|
|
782 | case LAYOUT_SNAKE: |
|
|
783 | make_snake_layout (layout, RP->layoutoptions1); |
|
|
784 | |
|
|
785 | if (rmg_rndm (2)) |
|
|
786 | roomify_layout (layout, RP); |
|
|
787 | |
|
|
788 | break; |
|
|
789 | |
|
|
790 | case LAYOUT_SQUARE_SPIRAL: |
|
|
791 | make_square_spiral_layout (layout, RP->layoutoptions1); |
|
|
792 | |
|
|
793 | if (rmg_rndm (2)) |
|
|
794 | roomify_layout (layout, RP); |
|
|
795 | |
|
|
796 | break; |
|
|
797 | |
|
|
798 | default: |
|
|
799 | abort (); |
|
|
800 | } |
|
|
801 | |
|
|
802 | /* rotate the layout randomly */ |
|
|
803 | rotate_layout (layout, rmg_rndm (4)); |
|
|
804 | |
|
|
805 | symmetrize_layout (layout, RP); |
|
|
806 | |
|
|
807 | #ifdef RMAP_DEBUG |
|
|
808 | dump_layout (layout); |
|
|
809 | #endif |
|
|
810 | |
|
|
811 | if (RP->expand2x) |
|
|
812 | expand2x (layout); |
|
|
813 | |
|
|
814 | return layout; |
|
|
815 | } |
|
|
816 | |
|
|
817 | bool |
|
|
818 | maptile::generate_random_map (random_map_params *RP) |
|
|
819 | { |
|
|
820 | char buf[16384]; |
|
|
821 | int i; |
|
|
822 | |
|
|
823 | RP->Xsize = RP->xsize; |
|
|
824 | RP->Ysize = RP->ysize; |
|
|
825 | |
|
|
826 | /* pick a random seed, or use the one from the input file */ |
|
|
827 | RP->random_seed = RP->random_seed |
|
|
828 | ? RP->random_seed + RP->dungeon_level |
|
|
829 | : time (0); |
|
|
830 | |
|
|
831 | // we run "single-threaded" |
|
|
832 | rmg_rndm.seed (RP->random_seed); |
|
|
833 | |
|
|
834 | write_map_parameters_to_string (buf, RP); |
|
|
835 | |
|
|
836 | if (RP->difficulty == 0) |
|
|
837 | { |
|
|
838 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
|
|
839 | |
|
|
840 | if (RP->difficulty_increase > 0.001) |
|
|
841 | RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); |
|
|
842 | |
|
|
843 | if (RP->difficulty < 1) |
|
|
844 | RP->difficulty = 1; |
|
|
845 | } |
|
|
846 | else |
|
|
847 | RP->difficulty_given = 1; |
|
|
848 | |
|
|
849 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
|
|
850 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
|
|
851 | |
|
|
852 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
|
|
853 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
|
|
854 | |
|
|
855 | if (RP->symmetry == SYMMETRY_RANDOM) |
|
|
856 | RP->symmetry_used = rmg_rndm (SYMMETRY_XY) + 1; |
|
|
857 | else |
|
|
858 | RP->symmetry_used = RP->symmetry; |
|
|
859 | |
|
|
860 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
|
|
861 | RP->Ysize = RP->Ysize / 2 + 1; |
|
|
862 | |
|
|
863 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
|
|
864 | RP->Xsize = RP->Xsize / 2 + 1; |
|
|
865 | |
|
|
866 | if (RP->expand2x > 0) |
|
|
867 | { |
|
|
868 | RP->Xsize /= 2; |
|
|
869 | RP->Ysize /= 2; |
|
|
870 | } |
|
|
871 | |
|
|
872 | RP->map_layout_style = LAYOUT_NONE; |
|
|
873 | |
|
|
874 | /* Redo this - there was a lot of redundant code of checking for preset |
|
|
875 | * layout style and then random layout style. Instead, figure out |
|
|
876 | * the numeric layoutstyle, so there is only one area that actually |
|
|
877 | * calls the code to make the maps. |
|
|
878 | */ |
|
|
879 | if (strstr (RP->layoutstyle, "onion")) |
|
|
880 | RP->map_layout_style = LAYOUT_ONION; |
|
|
881 | else if (strstr (RP->layoutstyle, "maze")) |
|
|
882 | RP->map_layout_style = LAYOUT_MAZE; |
|
|
883 | else if (strstr (RP->layoutstyle, "spiral")) |
|
|
884 | RP->map_layout_style = LAYOUT_SPIRAL; |
|
|
885 | else if (strstr (RP->layoutstyle, "rogue")) |
|
|
886 | RP->map_layout_style = LAYOUT_ROGUELIKE; |
|
|
887 | else if (strstr (RP->layoutstyle, "snake")) |
|
|
888 | RP->map_layout_style = LAYOUT_SNAKE; |
|
|
889 | else if (strstr (RP->layoutstyle, "squarespiral")) |
|
|
890 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
|
|
891 | else if (RP->map_layout_style == LAYOUT_NONE) |
|
|
892 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ |
|
|
893 | else |
|
|
894 | abort (); |
|
|
895 | |
|
|
896 | Layout layout = layoutgen (RP); |
|
|
897 | |
|
|
898 | #ifdef RMAP_DEBUG |
|
|
899 | dump_layout (layout); |
|
|
900 | #endif |
|
|
901 | |
|
|
902 | /* increment these for the current map */ |
|
|
903 | ++RP->dungeon_level; |
|
|
904 | |
|
|
905 | // need to patch RP becasue following code doesn't use the Layout object |
|
|
906 | RP->Xsize = layout->w; |
|
|
907 | RP->Ysize = layout->h; |
|
|
908 | |
|
|
909 | /* allocate the map and set the floor */ |
|
|
910 | make_map_floor (layout, RP->floorstyle, RP); |
|
|
911 | |
|
|
912 | /* set region */ |
|
|
913 | default_region = RP->region; |
|
|
914 | |
|
|
915 | CEDE; |
|
|
916 | |
|
|
917 | place_specials_in_map (this, layout, RP); |
|
|
918 | |
|
|
919 | CEDE; |
|
|
920 | |
|
|
921 | /* create walls unless the wallstyle is "none" */ |
|
|
922 | if (strcmp (RP->wallstyle, "none")) |
|
|
923 | { |
|
|
924 | make_map_walls (this, layout, RP->wallstyle, RP); |
|
|
925 | |
|
|
926 | /* place doors unless doorstyle or wallstyle is "none" */ |
|
|
927 | if (strcmp (RP->doorstyle, "none")) |
|
|
928 | put_doors (this, layout, RP->doorstyle, RP); |
|
|
929 | } |
|
|
930 | |
|
|
931 | CEDE; |
|
|
932 | |
|
|
933 | /* create exits unless the exitstyle is "none" */ |
|
|
934 | if (strcmp (RP->exitstyle, "none")) |
|
|
935 | place_exits (this, layout, RP->exitstyle, RP->orientation, RP); |
|
|
936 | |
|
|
937 | CEDE; |
|
|
938 | |
|
|
939 | /* create monsters unless the monsterstyle is "none" */ |
|
|
940 | if (strcmp (RP->monsterstyle, "none")) |
|
|
941 | place_monsters (this, RP->monsterstyle, RP->difficulty, RP); |
|
|
942 | |
|
|
943 | CEDE; |
|
|
944 | |
|
|
945 | /* treasures needs to have a proper difficulty set for the map. */ |
|
|
946 | difficulty = estimate_difficulty (); |
|
|
947 | |
|
|
948 | CEDE; |
|
|
949 | |
|
|
950 | /* create treasure unless the treasurestyle is "none" */ |
|
|
951 | place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); |
|
|
952 | |
|
|
953 | CEDE; |
|
|
954 | |
|
|
955 | /* create decor unless the decorstyle is "none" */ |
|
|
956 | if (strcmp (RP->decorstyle, "none")) |
|
|
957 | put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); |
|
|
958 | |
|
|
959 | CEDE; |
|
|
960 | |
|
|
961 | /* generate treasures, etc. */ |
|
|
962 | fix_auto_apply (); |
|
|
963 | |
|
|
964 | CEDE; |
|
|
965 | |
|
|
966 | unblock_exits (this, layout, RP); |
|
|
967 | |
|
|
968 | msg = strdup (buf); |
|
|
969 | in_memory = MAP_ACTIVE; |
|
|
970 | |
|
|
971 | CEDE; |
|
|
972 | |
|
|
973 | return 1; |
|
|
974 | } |
|
|
975 | |