… | |
… | |
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 |
… | |
… | |
76 | if (!tmp->is_head ()) |
76 | if (!tmp->is_head ()) |
77 | continue; |
77 | continue; |
78 | |
78 | |
79 | object *new_ob = tmp->deep_clone (); |
79 | object *new_ob = tmp->deep_clone (); |
80 | |
80 | |
81 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
81 | if (tmp->flag [FLAG_IS_LINKED]) |
82 | new_ob->add_link (dest_map, tmp->find_link ()->id); |
82 | new_ob->add_link (dest_map, tmp->find_link ()->id); |
83 | |
83 | |
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 | } |
… | |
… | |
162 | |
162 | |
163 | while (i < 0 && tries < 10) |
163 | while (i < 0 && tries < 10) |
164 | { |
164 | { |
165 | ix = rmg_rndm (map->width - 2) + 1; |
165 | ix = rmg_rndm (map->width - 2) + 1; |
166 | iy = rmg_rndm (map->height - 2) + 1; |
166 | iy = rmg_rndm (map->height - 2) + 1; |
167 | i = find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); |
167 | i = rmg_find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); |
168 | tries++; |
168 | tries++; |
169 | } |
169 | } |
170 | |
170 | |
171 | if (i == -1) |
171 | if (i == -1) |
172 | { /* can't place fountain */ |
172 | { /* can't place fountain */ |
… | |
… | |
176 | } |
176 | } |
177 | |
177 | |
178 | ix += freearr_x[i]; |
178 | ix += freearr_x[i]; |
179 | iy += freearr_y[i]; |
179 | iy += freearr_y[i]; |
180 | potion->face = fountain->face; |
180 | potion->face = fountain->face; |
181 | SET_FLAG (potion, FLAG_NO_PICK); |
181 | potion->set_flag (FLAG_NO_PICK); |
182 | SET_FLAG (potion, FLAG_IDENTIFIED); |
182 | potion->set_flag (FLAG_IDENTIFIED); |
183 | potion->name = potion->name_pl = shstr_fountain; |
183 | potion->name = potion->name_pl = shstr_fountain; |
184 | potion->x = ix; |
184 | potion->x = ix; |
185 | potion->y = iy; |
185 | potion->y = iy; |
186 | potion->material = name_to_material (shstr_adamantium); |
186 | potion->material = name_to_material (shstr_adamantium); |
187 | fountain->x = ix; |
187 | fountain->x = ix; |
… | |
… | |
191 | } |
191 | } |
192 | |
192 | |
193 | static void |
193 | static void |
194 | place_special_exit (maptile *map, int hole_type, random_map_params *RP) |
194 | place_special_exit (maptile *map, int hole_type, random_map_params *RP) |
195 | { |
195 | { |
196 | int ix, iy, i = -1; |
|
|
197 | char buf[16384]; |
|
|
198 | const char *style, *decor, *mon; |
|
|
199 | maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1); |
196 | maptile *exit_style = find_style ("/styles/misc", "obscure_exits", RP->difficulty); |
200 | int g_xsize, g_ysize; |
|
|
201 | |
|
|
202 | if (!exit_style) |
197 | if (!exit_style) |
203 | { |
198 | { |
204 | LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n"); |
199 | LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n"); |
205 | return; |
200 | return; |
206 | } |
201 | } |
… | |
… | |
211 | object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone (); |
206 | object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone (); |
212 | |
207 | |
213 | // put an upper bound here, just in case |
208 | // put an upper bound here, just in case |
214 | for (int repeat = 8192; --repeat; ) |
209 | for (int repeat = 8192; --repeat; ) |
215 | { |
210 | { |
216 | ix = rmg_rndm (1, map->width - 2); |
211 | int ix = rmg_rndm (1, map->width - 2); |
217 | iy = rmg_rndm (1, map->height - 2); |
212 | int iy = rmg_rndm (1, map->height - 2); |
218 | |
213 | |
219 | i = find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); |
214 | int i = rmg_find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); |
220 | if (i >= 0) |
215 | if (i >= 0) |
221 | { |
216 | { |
222 | ix += freearr_x[i]; |
217 | the_exit->x = ix + freearr_x[i]; |
223 | iy += freearr_y[i]; |
218 | the_exit->y = iy + freearr_y[i]; |
224 | break; |
219 | break; |
225 | } |
220 | } |
226 | } |
221 | } |
227 | |
|
|
228 | the_exit->x = ix; |
|
|
229 | the_exit->y = iy; |
|
|
230 | |
222 | |
231 | if (!hole_type) |
223 | if (!hole_type) |
232 | hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1; |
224 | hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1; |
|
|
225 | |
|
|
226 | const char *style, *decor, *mon; |
|
|
227 | int g_xsize, g_ysize; |
233 | |
228 | |
234 | switch (hole_type) |
229 | switch (hole_type) |
235 | { |
230 | { |
236 | case GLORY_HOLE: /* treasures */ |
231 | case GLORY_HOLE: /* treasures */ |
237 | { |
232 | { |
238 | g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
233 | g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
239 | g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
234 | g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
240 | style = "onion"; |
235 | style = "onion"; |
241 | decor = "wealth2"; |
236 | decor = "special_wealth"; |
242 | mon = "none"; |
237 | mon = "none"; |
243 | break; |
238 | break; |
244 | } |
239 | } |
245 | |
240 | |
246 | case ORC_ZONE: /* hole with orcs in it. */ |
241 | case ORC_ZONE: /* hole with orcs in it. */ |
247 | { |
242 | { |
248 | g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
243 | g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
249 | g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
244 | g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
250 | style = "onion"; |
245 | style = "onion"; |
251 | decor = "wealth2"; |
246 | decor = "special_wealth"; |
252 | mon = "orc"; |
247 | mon = "orc"; |
253 | break; |
248 | break; |
254 | } |
249 | } |
255 | |
250 | |
256 | case MINING_ZONE: /* hole with orcs in it. */ |
251 | case MINING_ZONE: /* hole with orcs in it. */ |
… | |
… | |
264 | } |
259 | } |
265 | |
260 | |
266 | default: /* undefined */ |
261 | default: /* undefined */ |
267 | LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type); |
262 | LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type); |
268 | return; |
263 | return; |
269 | break; |
|
|
270 | } |
264 | } |
271 | |
265 | |
272 | /* Need to be at least this size, otherwise the load |
266 | /* Need to be at least this size, otherwise the load |
273 | * code will generate new size values which are too large. |
267 | * code will generate new size values which are too large. |
274 | */ |
268 | */ |
275 | if (g_xsize < MIN_RANDOM_MAP_SIZE) g_xsize = MIN_RANDOM_MAP_SIZE; |
269 | max_it (g_xsize, MIN_RANDOM_MAP_SIZE); |
276 | if (g_ysize < MIN_RANDOM_MAP_SIZE) g_ysize = MIN_RANDOM_MAP_SIZE; |
270 | max_it (g_ysize, MIN_RANDOM_MAP_SIZE); |
277 | |
271 | |
278 | write_parameters_to_string (buf, g_xsize, g_ysize, RP->wallstyle, RP->floorstyle, mon, |
272 | dynbuf_text buf; |
279 | "none", style, decor, "none", RP->exitstyle, 0, 0, 0, |
273 | |
280 | RMOPT_WALLS_ONLY, 0, 0, 1, RP->dungeon_level, RP->dungeon_level, |
274 | { |
281 | RP->difficulty, RP->difficulty, -1, 1, 0, 0, 0, 0, RP->difficulty_increase); |
275 | random_map_params &rp = *new random_map_params; // for zero_intiialised to work... |
|
|
276 | |
|
|
277 | rp.hv = (HV *)newHV (); |
|
|
278 | |
|
|
279 | rp.xsize = g_xsize; |
|
|
280 | rp.ysize = g_ysize; |
|
|
281 | |
|
|
282 | rp.set ("wallstyle" , RP->get_str ("wallstyle" , 0)); |
|
|
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)); |
|
|
286 | rp.set ("monsterstyle" , mon); |
|
|
287 | rp.set ("treasurestyle", "none"); |
|
|
288 | rp.set ("layoutstyle" , style); |
|
|
289 | rp.set ("decorstyle" , decor); |
|
|
290 | rp.set ("decoroptions" , (IV)-1); |
|
|
291 | |
|
|
292 | rp.layoutoptions1 = RMOPT_WALLS_ONLY; |
|
|
293 | rp.symmetry = SYMMETRY_NONE; |
|
|
294 | rp.dungeon_depth = RP->dungeon_level; |
|
|
295 | rp.dungeon_level = RP->dungeon_level; |
|
|
296 | rp.difficulty = RP->difficulty; |
|
|
297 | rp.difficulty_given = RP->difficulty; |
|
|
298 | rp.difficulty_increase = RP->difficulty_increase; |
|
|
299 | rp.orientation = 1; |
|
|
300 | rp.random_seed = uint32_t (RP->random_seed + 0xdeadbeef); |
|
|
301 | |
282 | the_exit->slaying = shstr_random_map_exit; |
302 | the_exit->slaying = shstr_random_map_exit; |
283 | the_exit->msg = buf; |
303 | the_exit->msg = rp.as_shstr (); |
|
|
304 | |
|
|
305 | delete &rp; |
|
|
306 | } |
284 | |
307 | |
285 | insert_ob_in_map (the_exit, map, NULL, 0); |
308 | insert_ob_in_map (the_exit, map, NULL, 0); |
286 | } |
309 | } |
287 | |
310 | |
288 | void |
311 | void |
289 | 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) |
290 | { |
313 | { |
291 | switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) |
314 | switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) |
292 | { |
315 | { |
293 | case SPECIAL_SUBMAP: |
316 | case SPECIAL_SUBMAP: |
294 | { |
317 | { |
295 | /* includes a special map into the random map being made. */ |
318 | /* includes a special map into the random map being made. */ |
296 | maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty); |
319 | maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty, true); |
297 | |
320 | |
298 | if (!special_map) |
321 | if (!special_map) |
299 | break; |
322 | break; |
300 | |
323 | |
301 | int ix, iy; /* map insertion locatons */ |
324 | int ix, iy; /* map insertion locatons */ |
302 | |
325 | |
303 | 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)) |
304 | { |
327 | { |
305 | /* First, splatter everything in the dest map at the location */ |
328 | /* First, splatter everything in the dest map at the location */ |
306 | 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); |
307 | include_map_in_map (map, special_map, ix, iy); |
330 | include_map_in_map (map, special_map, ix, iy); |
308 | } |
331 | } |
309 | } |
332 | } |
310 | |
333 | |
311 | break; |
334 | break; |