… | |
… | |
43 | /* clear map completely of all !floor objects: |
43 | /* clear map completely of all !floor objects: |
44 | * a rectangular area of xsize, ysize |
44 | * a rectangular area of xsize, ysize |
45 | * is cleared with the top left corner at xstart, ystart |
45 | * is cleared with the top left corner at xstart, ystart |
46 | */ |
46 | */ |
47 | static void |
47 | static void |
48 | nuke_map_region (maptile *map, char **layout, int xstart, int ystart, int xsize, int ysize) |
48 | nuke_map_region (maptile *map, char **maze, int xstart, int ystart, int xsize, int ysize) |
49 | { |
49 | { |
50 | for (int i = xstart; i < xstart + xsize; i++) |
50 | for (int i = xstart; i < xstart + xsize; i++) |
51 | for (int j = ystart; j < ystart + ysize; j++) |
51 | for (int j = ystart; j < ystart + ysize; j++) |
52 | { |
52 | { |
53 | layout[i][j] = 'S'; |
53 | maze[i][j] = 'S'; |
54 | |
54 | |
55 | for (object *tmp = map->at (i, j).bot; tmp; ) |
55 | for (object *tmp = map->at (i, j).bot; tmp; ) |
56 | if (tmp->flag [FLAG_IS_FLOOR]) |
56 | if (tmp->flag [FLAG_IS_FLOOR]) |
57 | tmp = tmp->above; |
57 | tmp = tmp->above; |
58 | else |
58 | else |
… | |
… | |
84 | dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
84 | dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
85 | } |
85 | } |
86 | } |
86 | } |
87 | |
87 | |
88 | static int |
88 | static int |
89 | find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize) |
89 | find_spot_for_submap (maptile *map, char **maze, int *ix, int *iy, int xsize, int ysize) |
90 | { |
90 | { |
91 | int blocked, i, j; |
91 | int blocked, i, j; |
92 | |
92 | |
93 | /* don't even try to place a submap into a map if the big map isn't |
93 | /* don't even try to place a submap into a map if the big map isn't |
94 | sufficiently large. */ |
94 | sufficiently large. */ |
… | |
… | |
98 | /* search a bit for a completely free spot. */ |
98 | /* search a bit for a completely free spot. */ |
99 | for (int tries = 0; tries < 20; tries++) |
99 | for (int tries = 0; tries < 20; tries++) |
100 | { |
100 | { |
101 | blocked = 0; |
101 | blocked = 0; |
102 | |
102 | |
103 | /* pick a random location in the layout */ |
103 | /* pick a random location in the maze */ |
104 | i = rmg_rndm (1, map->width - xsize - 2); |
104 | i = rmg_rndm (1, map->width - xsize - 2); |
105 | j = rmg_rndm (1, map->height - ysize - 2); |
105 | j = rmg_rndm (1, map->height - ysize - 2); |
106 | |
106 | |
107 | for (int l = i; l < i + xsize; l++) |
107 | for (int l = i; l < i + xsize; l++) |
108 | for (int m = j; m < j + ysize; m++) |
108 | for (int m = j; m < j + ysize; m++) |
… | |
… | |
116 | } |
116 | } |
117 | |
117 | |
118 | /* if we failed, relax the restrictions */ |
118 | /* if we failed, relax the restrictions */ |
119 | if (blocked) |
119 | if (blocked) |
120 | { /* failure, try a relaxed placer. */ |
120 | { /* failure, try a relaxed placer. */ |
121 | /* pick a random location in the layout */ |
121 | /* pick a random location in the maze */ |
122 | for (int tries = 0; tries < 10; tries++) |
122 | for (int tries = 0; tries < 10; tries++) |
123 | { |
123 | { |
124 | i = rmg_rndm (1, map->width - xsize - 2); |
124 | i = rmg_rndm (1, map->width - xsize - 2); |
125 | j = rmg_rndm (1, map->height - ysize - 2); |
125 | j = rmg_rndm (1, map->height - ysize - 2); |
126 | |
126 | |
127 | blocked = 0; |
127 | blocked = 0; |
128 | |
128 | |
129 | for (int l = i; l < i + xsize; l++) |
129 | for (int l = i; l < i + xsize; l++) |
130 | for (int m = j; m < j + ysize; m++) |
130 | for (int m = j; m < j + ysize; m++) |
131 | if (layout[l][m] != '#' && layout[l][m] != 'D' && layout[l][m] != 0) |
131 | if (maze[l][m] != '#' && maze[l][m] != 'D' && maze[l][m] != 0) |
132 | { |
132 | { |
133 | blocked = 1; |
133 | blocked = 1; |
134 | break; |
134 | break; |
135 | } |
135 | } |
136 | } |
136 | } |
… | |
… | |
221 | } |
221 | } |
222 | |
222 | |
223 | if (!hole_type) |
223 | if (!hole_type) |
224 | hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1; |
224 | hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1; |
225 | |
225 | |
226 | char buf[16384]; |
|
|
227 | const char *style, *decor, *mon; |
226 | const char *style, *decor, *mon; |
228 | int g_xsize, g_ysize; |
227 | int g_xsize, g_ysize; |
229 | |
228 | |
230 | switch (hole_type) |
229 | switch (hole_type) |
231 | { |
230 | { |
… | |
… | |
268 | * code will generate new size values which are too large. |
267 | * code will generate new size values which are too large. |
269 | */ |
268 | */ |
270 | max_it (g_xsize, MIN_RANDOM_MAP_SIZE); |
269 | max_it (g_xsize, MIN_RANDOM_MAP_SIZE); |
271 | max_it (g_ysize, MIN_RANDOM_MAP_SIZE); |
270 | max_it (g_ysize, MIN_RANDOM_MAP_SIZE); |
272 | |
271 | |
|
|
272 | dynbuf_text buf; |
|
|
273 | |
273 | { |
274 | { |
274 | random_map_params &rp = *new random_map_params; // for zero_intiialised to work... |
275 | random_map_params &rp = *new random_map_params; // for zero_intiialised to work... |
275 | |
276 | |
|
|
277 | rp.hv = (HV *)newHV (); |
|
|
278 | |
276 | rp.xsize = g_xsize; |
279 | rp.xsize = g_xsize; |
277 | rp.ysize = g_ysize; |
280 | rp.ysize = g_ysize; |
278 | |
281 | |
279 | assign (rp.wallstyle , RP->wallstyle); |
282 | rp.set ("wallstyle" , RP->get_str ("wallstyle" , 0)); |
280 | assign (rp.floorstyle , RP->floorstyle); |
283 | rp.set ("floorstyle" , RP->get_str ("floorstyle", 0)); |
|
|
284 | rp.set ("exitstyle" , RP->get_str ("exitstyle" , 0)); |
|
|
285 | rp.set ("region" , RP->get_str ("region" , 0)); |
281 | assign (rp.monsterstyle , mon); |
286 | rp.set ("monsterstyle" , mon); |
282 | assign (rp.treasurestyle, "none"); |
287 | rp.set ("treasurestyle", "none"); |
283 | assign (rp.layoutstyle , style); |
288 | rp.set ("layoutstyle" , style); |
284 | assign (rp.decorstyle , decor); |
289 | rp.set ("decorstyle" , decor); |
285 | assign (rp.exitstyle , RP->exitstyle); |
290 | rp.set ("decoroptions" , (IV)-1); |
286 | |
291 | |
287 | rp.layoutoptions1 = RMOPT_WALLS_ONLY; |
292 | rp.layoutoptions1 = RMOPT_WALLS_ONLY; |
288 | rp.symmetry = SYMMETRY_NONE; |
293 | rp.symmetry = SYMMETRY_NONE; |
289 | rp.dungeon_depth = RP->dungeon_level; |
294 | rp.dungeon_depth = RP->dungeon_level; |
290 | rp.dungeon_level = RP->dungeon_level; |
295 | rp.dungeon_level = RP->dungeon_level; |
291 | rp.difficulty = RP->difficulty; |
296 | rp.difficulty = RP->difficulty; |
292 | rp.difficulty_given = RP->difficulty; |
297 | rp.difficulty_given = RP->difficulty; |
293 | rp.difficulty_increase = RP->difficulty_increase; |
298 | rp.difficulty_increase = RP->difficulty_increase; |
294 | rp.decoroptions = -1; |
|
|
295 | rp.orientation = 1; |
299 | rp.orientation = 1; |
296 | rp.random_seed = RP->random_seed ^ 0xdeadbeef; |
300 | rp.random_seed = uint32_t (RP->random_seed + 0xdeadbeef); |
297 | rp.region = RP->region; |
|
|
298 | |
301 | |
299 | write_map_parameters_to_string (buf, &rp); |
302 | the_exit->slaying = shstr_random_map_exit; |
|
|
303 | the_exit->msg = rp.as_shstr (); |
|
|
304 | |
300 | delete &rp; |
305 | delete &rp; |
301 | } |
306 | } |
302 | |
307 | |
303 | the_exit->slaying = shstr_random_map_exit; |
|
|
304 | the_exit->msg = buf; |
|
|
305 | |
|
|
306 | insert_ob_in_map (the_exit, map, NULL, 0); |
308 | insert_ob_in_map (the_exit, map, NULL, 0); |
307 | } |
309 | } |
308 | |
310 | |
309 | void |
311 | void |
310 | place_specials_in_map (maptile *map, char **layout, random_map_params *RP) |
312 | place_specials_in_map (maptile *map, char **maze, random_map_params *RP) |
311 | { |
313 | { |
312 | switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) |
314 | switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) |
313 | { |
315 | { |
314 | case SPECIAL_SUBMAP: |
316 | case SPECIAL_SUBMAP: |
315 | { |
317 | { |
… | |
… | |
319 | if (!special_map) |
321 | if (!special_map) |
320 | break; |
322 | break; |
321 | |
323 | |
322 | int ix, iy; /* map insertion locatons */ |
324 | int ix, iy; /* map insertion locatons */ |
323 | |
325 | |
324 | if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height)) |
326 | if (find_spot_for_submap (map, maze, &ix, &iy, special_map->width, special_map->height)) |
325 | { |
327 | { |
326 | /* First, splatter everything in the dest map at the location */ |
328 | /* First, splatter everything in the dest map at the location */ |
327 | nuke_map_region (map, layout, ix, iy, special_map->width, special_map->height); |
329 | nuke_map_region (map, maze, ix, iy, special_map->width, special_map->height); |
328 | include_map_in_map (map, special_map, ix, iy); |
330 | include_map_in_map (map, special_map, ix, iy); |
329 | } |
331 | } |
330 | } |
332 | } |
331 | |
333 | |
332 | break; |
334 | break; |
… | |
… | |
337 | place_fountain_with_specials (map); |
339 | place_fountain_with_specials (map); |
338 | break; |
340 | break; |
339 | |
341 | |
340 | case SPECIAL_EXIT: |
342 | case SPECIAL_EXIT: |
341 | /* Make an exit to another random map, e.g. a gloryhole. */ |
343 | /* Make an exit to another random map, e.g. a gloryhole. */ |
342 | //place_special_exit (map, 0, RP); |
344 | place_special_exit (map, 0, RP); |
343 | place_special_exit (map, GLORY_HOLE, RP); |
|
|
344 | break; |
345 | break; |
345 | } |
346 | } |
346 | } |
347 | } |
347 | |
348 | |