… | |
… | |
26 | #include <global.h> |
26 | #include <global.h> |
27 | #include <random_map.h> |
27 | #include <random_map.h> |
28 | #include <rproto.h> |
28 | #include <rproto.h> |
29 | #include <sproto.h> |
29 | #include <sproto.h> |
30 | |
30 | |
31 | #define CEDE coroapi::cede_to_tick (); rndm.seed (RP->random_seed + __LINE__); |
31 | #define CEDE coroapi::cede_to_tick () |
32 | |
32 | |
33 | static void symmetrize_layout (Layout maze, random_map_params *RP); |
33 | static void symmetrize_layout (Layout maze, random_map_params *RP); |
34 | static void rotate_layout (Layout maze, int rotation); |
34 | static void rotate_layout (Layout maze, int rotation); |
35 | |
35 | |
36 | void |
36 | void |
… | |
… | |
58 | |
58 | |
59 | /* pick a random seed, or use the one from the input file */ |
59 | /* pick a random seed, or use the one from the input file */ |
60 | RP->random_seed = RP->random_seed |
60 | RP->random_seed = RP->random_seed |
61 | ? RP->random_seed + RP->dungeon_level |
61 | ? RP->random_seed + RP->dungeon_level |
62 | : time (0); |
62 | : time (0); |
63 | CEDE; |
63 | |
|
|
64 | // we run "single-threaded" |
|
|
65 | rmg_rndm.seed (RP->random_seed); |
64 | |
66 | |
65 | write_map_parameters_to_string (buf, RP); |
67 | write_map_parameters_to_string (buf, RP); |
66 | |
68 | |
67 | if (RP->difficulty == 0) |
69 | if (RP->difficulty == 0) |
68 | { |
70 | { |
… | |
… | |
76 | } |
78 | } |
77 | else |
79 | else |
78 | RP->difficulty_given = 1; |
80 | RP->difficulty_given = 1; |
79 | |
81 | |
80 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
82 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
81 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
83 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
82 | |
84 | |
83 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
85 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
84 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
86 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
85 | |
87 | |
86 | if (RP->symmetry == SYMMETRY_RANDOM) |
88 | if (RP->symmetry == SYMMETRY_RANDOM) |
87 | RP->symmetry_used = rndm (SYMMETRY_XY) + 1; |
89 | RP->symmetry_used = rmg_rndm (SYMMETRY_XY) + 1; |
88 | else |
90 | else |
89 | RP->symmetry_used = RP->symmetry; |
91 | RP->symmetry_used = RP->symmetry; |
90 | |
92 | |
91 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
93 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
92 | RP->Ysize = RP->Ysize / 2 + 1; |
94 | RP->Ysize = RP->Ysize / 2 + 1; |
… | |
… | |
118 | else if (strstr (RP->layoutstyle, "snake")) |
120 | else if (strstr (RP->layoutstyle, "snake")) |
119 | RP->map_layout_style = LAYOUT_SNAKE; |
121 | RP->map_layout_style = LAYOUT_SNAKE; |
120 | else if (strstr (RP->layoutstyle, "squarespiral")) |
122 | else if (strstr (RP->layoutstyle, "squarespiral")) |
121 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
123 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
122 | else if (RP->map_layout_style == LAYOUT_NONE) |
124 | else if (RP->map_layout_style == LAYOUT_NONE) |
123 | RP->map_layout_style = rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ |
125 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ |
124 | else |
126 | else |
125 | abort (); |
127 | abort (); |
126 | |
128 | |
127 | Layout layout = layoutgen (RP); |
129 | Layout layout = layoutgen (RP); |
128 | |
130 | |
… | |
… | |
143 | /* set region */ |
145 | /* set region */ |
144 | default_region = RP->region; |
146 | default_region = RP->region; |
145 | |
147 | |
146 | CEDE; |
148 | CEDE; |
147 | |
149 | |
|
|
150 | place_specials_in_map (this, layout, RP); |
|
|
151 | |
|
|
152 | CEDE; |
|
|
153 | |
148 | /* create walls unless the wallstyle is "none" */ |
154 | /* create walls unless the wallstyle is "none" */ |
149 | if (strcmp (RP->wallstyle, "none")) |
155 | if (strcmp (RP->wallstyle, "none")) |
150 | { |
156 | { |
151 | make_map_walls (this, layout, RP->wallstyle, RP); |
157 | make_map_walls (this, layout, RP->wallstyle, RP); |
152 | |
158 | |
… | |
… | |
158 | CEDE; |
164 | CEDE; |
159 | |
165 | |
160 | /* create exits unless the exitstyle is "none" */ |
166 | /* create exits unless the exitstyle is "none" */ |
161 | if (strcmp (RP->exitstyle, "none")) |
167 | if (strcmp (RP->exitstyle, "none")) |
162 | place_exits (this, layout, RP->exitstyle, RP->orientation, RP); |
168 | place_exits (this, layout, RP->exitstyle, RP->orientation, RP); |
163 | |
|
|
164 | CEDE; |
|
|
165 | |
|
|
166 | place_specials_in_map (this, layout, RP); |
|
|
167 | |
169 | |
168 | CEDE; |
170 | CEDE; |
169 | |
171 | |
170 | /* create monsters unless the monsterstyle is "none" */ |
172 | /* create monsters unless the monsterstyle is "none" */ |
171 | if (strcmp (RP->monsterstyle, "none")) |
173 | if (strcmp (RP->monsterstyle, "none")) |
… | |
… | |
215 | switch (RP->map_layout_style) |
217 | switch (RP->map_layout_style) |
216 | { |
218 | { |
217 | case LAYOUT_ONION: |
219 | case LAYOUT_ONION: |
218 | map_gen_onion (layout, RP->layoutoptions1, RP->layoutoptions2); |
220 | map_gen_onion (layout, RP->layoutoptions1, RP->layoutoptions2); |
219 | |
221 | |
220 | if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
222 | if (!(rmg_rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
221 | roomify_layout (layout, RP); |
223 | roomify_layout (layout, RP); |
222 | |
224 | |
223 | break; |
225 | break; |
224 | |
226 | |
225 | case LAYOUT_MAZE: |
227 | case LAYOUT_MAZE: |
226 | maze_gen (layout, rndm (2)); |
228 | maze_gen (layout, rmg_rndm (2)); |
227 | |
229 | |
228 | if (!(rndm (2))) |
230 | if (!(rmg_rndm (2))) |
229 | doorify_layout (layout, RP); |
231 | doorify_layout (layout, RP); |
230 | |
232 | |
231 | break; |
233 | break; |
232 | |
234 | |
233 | case LAYOUT_SPIRAL: |
235 | case LAYOUT_SPIRAL: |
234 | map_gen_spiral (layout, RP->layoutoptions1); |
236 | map_gen_spiral (layout, RP->layoutoptions1); |
235 | |
237 | |
236 | if (!(rndm (2))) |
238 | if (!(rmg_rndm (2))) |
237 | doorify_layout (layout, RP); |
239 | doorify_layout (layout, RP); |
238 | |
240 | |
239 | break; |
241 | break; |
240 | |
242 | |
241 | case LAYOUT_ROGUELIKE: |
243 | case LAYOUT_ROGUELIKE: |
… | |
… | |
252 | break; |
254 | break; |
253 | |
255 | |
254 | case LAYOUT_SNAKE: |
256 | case LAYOUT_SNAKE: |
255 | make_snake_layout (layout, RP->layoutoptions1); |
257 | make_snake_layout (layout, RP->layoutoptions1); |
256 | |
258 | |
257 | if (rndm (2)) |
259 | if (rmg_rndm (2)) |
258 | roomify_layout (layout, RP); |
260 | roomify_layout (layout, RP); |
259 | |
261 | |
260 | break; |
262 | break; |
261 | |
263 | |
262 | case LAYOUT_SQUARE_SPIRAL: |
264 | case LAYOUT_SQUARE_SPIRAL: |
263 | make_square_spiral_layout (layout, RP->layoutoptions1); |
265 | make_square_spiral_layout (layout, RP->layoutoptions1); |
264 | |
266 | |
265 | if (rndm (2)) |
267 | if (rmg_rndm (2)) |
266 | roomify_layout (layout, RP); |
268 | roomify_layout (layout, RP); |
267 | |
269 | |
268 | break; |
270 | break; |
269 | |
271 | |
270 | default: |
272 | default: |
271 | abort (); |
273 | abort (); |
272 | } |
274 | } |
273 | |
275 | |
274 | /* rotate the layout randomly */ |
276 | /* rotate the layout randomly */ |
275 | rotate_layout (layout, rndm (4)); |
277 | rotate_layout (layout, rmg_rndm (4)); |
276 | |
278 | |
277 | symmetrize_layout (layout, RP); |
279 | symmetrize_layout (layout, RP); |
278 | |
280 | |
279 | #ifdef RMAP_DEBUG |
281 | #ifdef RMAP_DEBUG |
280 | dump_layout (layout); |
282 | dump_layout (layout); |
… | |
… | |
395 | for (ti = 0; ti < tries; ti++) |
397 | for (ti = 0; ti < tries; ti++) |
396 | { |
398 | { |
397 | int dx, dy; /* starting location for looking at creating a door */ |
399 | int dx, dy; /* starting location for looking at creating a door */ |
398 | int cx, cy; /* results of checking on creating walls. */ |
400 | int cx, cy; /* results of checking on creating walls. */ |
399 | |
401 | |
400 | dx = rndm (RP->Xsize); |
402 | dx = rmg_rndm (RP->Xsize); |
401 | dy = rndm (RP->Ysize); |
403 | dy = rmg_rndm (RP->Ysize); |
402 | |
404 | |
403 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
405 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
404 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
406 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
405 | if (cx == -1) |
407 | if (cx == -1) |
406 | { |
408 | { |
… | |
… | |
566 | while (ndoors > 0 && doorlocs > 0) |
568 | while (ndoors > 0 && doorlocs > 0) |
567 | { |
569 | { |
568 | int di; |
570 | int di; |
569 | int sindex; |
571 | int sindex; |
570 | |
572 | |
571 | di = rndm (doorlocs); |
573 | di = rmg_rndm (doorlocs); |
572 | i = doorlist_x[di]; |
574 | i = doorlist_x[di]; |
573 | j = doorlist_y[di]; |
575 | j = doorlist_y[di]; |
574 | sindex = surround_flag (maze, i, j, RP); |
576 | sindex = surround_flag (maze, i, j, RP); |
575 | |
577 | |
576 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
578 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |