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,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * 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 |
9 | * the terms of the Affero GNU General Public License as published by the |
… | |
… | |
24 | |
24 | |
25 | /* Specials in this file: |
25 | /* Specials in this file: |
26 | included maps */ |
26 | included maps */ |
27 | |
27 | |
28 | #include <global.h> |
28 | #include <global.h> |
29 | #include <random_map.h> |
29 | #include <rmg.h> |
30 | #include <rproto.h> |
30 | #include <rproto.h> |
31 | |
31 | |
|
|
32 | enum { |
|
|
33 | NO_SPECIAL, |
|
|
34 | SPECIAL_SUBMAP, |
|
|
35 | SPECIAL_FOUNTAIN, |
|
|
36 | SPECIAL_EXIT, |
32 | #define NUM_OF_SPECIAL_TYPES 4 |
37 | NUM_OF_SPECIAL_TYPES |
33 | #define NO_SPECIAL 0 |
38 | }; |
34 | #define SPECIAL_SUBMAP 1 |
|
|
35 | #define SPECIAL_FOUNTAIN 2 |
|
|
36 | #define SPECIAL_EXIT 3 |
|
|
37 | |
39 | |
38 | #define GLORY_HOLE 1 |
40 | enum { |
39 | #define ORC_ZONE 2 |
41 | GLORY_HOLE = 1, |
40 | #define MINING_ZONE 3 |
42 | ORC_ZONE, |
|
|
43 | MINING_ZONE, |
41 | #define NR_OF_HOLE_TYPES 3 |
44 | NR_OF_HOLE_TYPES |
|
|
45 | }; |
42 | |
46 | |
43 | /* clear map completely of all !floor objects: |
47 | /* clear map completely of all !floor objects: |
44 | * a rectangular area of xsize, ysize |
48 | * a rectangular area of xsize, ysize |
45 | * is cleared with the top left corner at xstart, ystart |
49 | * is cleared with the top left corner at xstart, ystart |
46 | */ |
50 | */ |
47 | static void |
51 | static void |
48 | nuke_map_region (maptile *map, char **layout, int xstart, int ystart, int xsize, int ysize) |
52 | nuke_map_region (maptile *map, layout &maze, int xstart, int ystart, int xsize, int ysize) |
49 | { |
53 | { |
50 | for (int i = xstart; i < xstart + xsize; i++) |
54 | for (int i = xstart; i < xstart + xsize; i++) |
51 | for (int j = ystart; j < ystart + ysize; j++) |
55 | for (int j = ystart; j < ystart + ysize; j++) |
52 | { |
56 | { |
53 | layout[i][j] = 'S'; |
57 | maze[i][j] = 'S'; |
54 | |
58 | |
55 | for (object *tmp = map->at (i, j).bot; tmp; ) |
59 | for (object *tmp = map->at (i, j).bot; tmp; ) |
56 | if (tmp->flag [FLAG_IS_FLOOR]) |
60 | if (tmp->flag [FLAG_IS_FLOOR]) |
57 | tmp = tmp->above; |
61 | tmp = tmp->above; |
58 | else |
62 | else |
… | |
… | |
76 | if (!tmp->is_head ()) |
80 | if (!tmp->is_head ()) |
77 | continue; |
81 | continue; |
78 | |
82 | |
79 | object *new_ob = tmp->deep_clone (); |
83 | object *new_ob = tmp->deep_clone (); |
80 | |
84 | |
81 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
85 | if (tmp->flag [FLAG_IS_LINKED]) |
82 | new_ob->add_link (dest_map, tmp->find_link ()->id); |
86 | new_ob->add_link (dest_map, tmp->find_link ()->id); |
83 | |
87 | |
84 | dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
88 | dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
85 | } |
89 | } |
86 | } |
90 | } |
87 | |
91 | |
88 | static int |
92 | static int |
89 | find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize) |
93 | find_spot_for_submap (maptile *map, layout &maze, int *ix, int *iy, int xsize, int ysize) |
90 | { |
94 | { |
91 | int blocked, i, j; |
95 | int blocked, i, j; |
92 | |
96 | |
93 | /* don't even try to place a submap into a map if the big map isn't |
97 | /* don't even try to place a submap into a map if the big map isn't |
94 | sufficiently large. */ |
98 | sufficiently large. */ |
… | |
… | |
98 | /* search a bit for a completely free spot. */ |
102 | /* search a bit for a completely free spot. */ |
99 | for (int tries = 0; tries < 20; tries++) |
103 | for (int tries = 0; tries < 20; tries++) |
100 | { |
104 | { |
101 | blocked = 0; |
105 | blocked = 0; |
102 | |
106 | |
103 | /* pick a random location in the layout */ |
107 | /* pick a random location in the maze */ |
104 | i = rmg_rndm (1, map->width - xsize - 2); |
108 | i = rmg_rndm (1, map->width - xsize - 2); |
105 | j = rmg_rndm (1, map->height - ysize - 2); |
109 | j = rmg_rndm (1, map->height - ysize - 2); |
106 | |
110 | |
107 | for (int l = i; l < i + xsize; l++) |
111 | for (int l = i; l < i + xsize; l++) |
108 | for (int m = j; m < j + ysize; m++) |
112 | for (int m = j; m < j + ysize; m++) |
… | |
… | |
116 | } |
120 | } |
117 | |
121 | |
118 | /* if we failed, relax the restrictions */ |
122 | /* if we failed, relax the restrictions */ |
119 | if (blocked) |
123 | if (blocked) |
120 | { /* failure, try a relaxed placer. */ |
124 | { /* failure, try a relaxed placer. */ |
121 | /* pick a random location in the layout */ |
125 | /* pick a random location in the maze */ |
122 | for (int tries = 0; tries < 10; tries++) |
126 | for (int tries = 0; tries < 10; tries++) |
123 | { |
127 | { |
124 | i = rmg_rndm (1, map->width - xsize - 2); |
128 | i = rmg_rndm (1, map->width - xsize - 2); |
125 | j = rmg_rndm (1, map->height - ysize - 2); |
129 | j = rmg_rndm (1, map->height - ysize - 2); |
126 | |
130 | |
127 | blocked = 0; |
131 | blocked = 0; |
128 | |
132 | |
129 | for (int l = i; l < i + xsize; l++) |
133 | for (int l = i; l < i + xsize; l++) |
130 | for (int m = j; m < j + ysize; m++) |
134 | for (int m = j; m < j + ysize; m++) |
131 | if (layout[l][m] != '#' && layout[l][m] != 'D' && layout[l][m] != 0) |
135 | if (maze[l][m] != '#' && maze[l][m] != 'D' && maze[l][m] != 0) |
132 | { |
136 | { |
133 | blocked = 1; |
137 | blocked = 1; |
134 | break; |
138 | break; |
135 | } |
139 | } |
136 | } |
140 | } |
… | |
… | |
162 | |
166 | |
163 | while (i < 0 && tries < 10) |
167 | while (i < 0 && tries < 10) |
164 | { |
168 | { |
165 | ix = rmg_rndm (map->width - 2) + 1; |
169 | ix = rmg_rndm (map->width - 2) + 1; |
166 | iy = rmg_rndm (map->height - 2) + 1; |
170 | iy = rmg_rndm (map->height - 2) + 1; |
167 | i = find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); |
171 | i = rmg_find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); |
168 | tries++; |
172 | tries++; |
169 | } |
173 | } |
170 | |
174 | |
171 | if (i == -1) |
175 | if (i == -1) |
172 | { /* can't place fountain */ |
176 | { /* can't place fountain */ |
… | |
… | |
176 | } |
180 | } |
177 | |
181 | |
178 | ix += freearr_x[i]; |
182 | ix += freearr_x[i]; |
179 | iy += freearr_y[i]; |
183 | iy += freearr_y[i]; |
180 | potion->face = fountain->face; |
184 | potion->face = fountain->face; |
181 | SET_FLAG (potion, FLAG_NO_PICK); |
185 | potion->set_flag (FLAG_NO_PICK); |
182 | SET_FLAG (potion, FLAG_IDENTIFIED); |
186 | potion->set_flag (FLAG_IDENTIFIED); |
183 | potion->name = potion->name_pl = shstr_fountain; |
187 | potion->name = potion->name_pl = shstr_fountain; |
184 | potion->x = ix; |
188 | potion->x = ix; |
185 | potion->y = iy; |
189 | potion->y = iy; |
186 | potion->material = name_to_material (shstr_adamantium); |
190 | potion->material = name_to_material (shstr_adamantium); |
187 | fountain->x = ix; |
191 | fountain->x = ix; |
… | |
… | |
191 | } |
195 | } |
192 | |
196 | |
193 | static void |
197 | static void |
194 | place_special_exit (maptile *map, int hole_type, random_map_params *RP) |
198 | place_special_exit (maptile *map, int hole_type, random_map_params *RP) |
195 | { |
199 | { |
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); |
200 | maptile *exit_style = find_style ("/styles/misc", "obscure_exits", RP->difficulty); |
200 | int g_xsize, g_ysize; |
|
|
201 | |
|
|
202 | if (!exit_style) |
201 | if (!exit_style) |
203 | { |
202 | { |
204 | LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n"); |
203 | LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n"); |
205 | return; |
204 | return; |
206 | } |
205 | } |
… | |
… | |
211 | object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone (); |
210 | object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone (); |
212 | |
211 | |
213 | // put an upper bound here, just in case |
212 | // put an upper bound here, just in case |
214 | for (int repeat = 8192; --repeat; ) |
213 | for (int repeat = 8192; --repeat; ) |
215 | { |
214 | { |
216 | ix = rmg_rndm (1, map->width - 2); |
215 | int ix = rmg_rndm (1, map->width - 2); |
217 | iy = rmg_rndm (1, map->height - 2); |
216 | int iy = rmg_rndm (1, map->height - 2); |
218 | |
217 | |
219 | i = find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); |
218 | int i = rmg_find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); |
220 | if (i >= 0) |
219 | if (i >= 0) |
221 | { |
220 | { |
222 | ix += freearr_x[i]; |
221 | the_exit->x = ix + freearr_x[i]; |
223 | iy += freearr_y[i]; |
222 | the_exit->y = iy + freearr_y[i]; |
224 | break; |
223 | break; |
225 | } |
224 | } |
226 | } |
225 | } |
227 | |
226 | |
228 | the_exit->x = ix; |
|
|
229 | the_exit->y = iy; |
|
|
230 | |
|
|
231 | if (!hole_type) |
227 | if (!hole_type) |
232 | hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1; |
228 | hole_type = rmg_rndm (1, NR_OF_HOLE_TYPES - 1); |
|
|
229 | |
|
|
230 | const char *style, *decor, *mon; |
|
|
231 | int g_xsize, g_ysize; |
233 | |
232 | |
234 | switch (hole_type) |
233 | switch (hole_type) |
235 | { |
234 | { |
236 | case GLORY_HOLE: /* treasures */ |
235 | case GLORY_HOLE: /* treasures */ |
237 | { |
236 | { |
238 | g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
237 | g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
239 | g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
238 | g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
240 | style = "onion"; |
239 | style = "onion"; |
241 | decor = "wealth2"; |
240 | decor = "special_wealth"; |
242 | mon = "none"; |
241 | mon = "none"; |
243 | break; |
242 | break; |
244 | } |
243 | } |
245 | |
244 | |
246 | case ORC_ZONE: /* hole with orcs in it. */ |
245 | case ORC_ZONE: /* hole with orcs in it. */ |
247 | { |
246 | { |
248 | g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
247 | g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
249 | g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
248 | g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
250 | style = "onion"; |
249 | style = "onion"; |
251 | decor = "wealth2"; |
250 | decor = "special_wealth"; |
252 | mon = "orc"; |
251 | mon = "orc"; |
253 | break; |
252 | break; |
254 | } |
253 | } |
255 | |
254 | |
256 | case MINING_ZONE: /* hole with orcs in it. */ |
255 | case MINING_ZONE: /* hole with orcs in it. */ |
… | |
… | |
264 | } |
263 | } |
265 | |
264 | |
266 | default: /* undefined */ |
265 | default: /* undefined */ |
267 | LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type); |
266 | LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type); |
268 | return; |
267 | return; |
269 | break; |
|
|
270 | } |
268 | } |
271 | |
269 | |
272 | /* Need to be at least this size, otherwise the load |
270 | /* Need to be at least this size, otherwise the load |
273 | * code will generate new size values which are too large. |
271 | * code will generate new size values which are too large. |
274 | */ |
272 | */ |
275 | if (g_xsize < MIN_RANDOM_MAP_SIZE) g_xsize = MIN_RANDOM_MAP_SIZE; |
273 | max_it (g_xsize, MIN_RANDOM_MAP_SIZE); |
276 | if (g_ysize < MIN_RANDOM_MAP_SIZE) g_ysize = MIN_RANDOM_MAP_SIZE; |
274 | max_it (g_ysize, MIN_RANDOM_MAP_SIZE); |
277 | |
275 | |
278 | write_parameters_to_string (buf, g_xsize, g_ysize, RP->wallstyle, RP->floorstyle, mon, |
276 | dynbuf_text buf; |
279 | "none", style, decor, "none", RP->exitstyle, 0, 0, 0, |
277 | |
280 | RMOPT_WALLS_ONLY, 0, 0, 1, RP->dungeon_level, RP->dungeon_level, |
278 | { |
281 | RP->difficulty, RP->difficulty, -1, 1, 0, 0, 0, 0, RP->difficulty_increase); |
279 | random_map_params &rp = *new random_map_params; // for zero_intiialised to work... |
|
|
280 | |
|
|
281 | rp.hv = (HV *)newHV (); |
|
|
282 | |
|
|
283 | rp.xsize = g_xsize; |
|
|
284 | rp.ysize = g_ysize; |
|
|
285 | |
|
|
286 | rp.set ("wallstyle" , RP->get_str ("wallstyle" , 0)); |
|
|
287 | rp.set ("floorstyle" , RP->get_str ("floorstyle", 0)); |
|
|
288 | rp.set ("exitstyle" , RP->get_str ("exitstyle" , 0)); |
|
|
289 | rp.set ("region" , RP->get_str ("region" , 0)); |
|
|
290 | rp.set ("monsterstyle" , mon); |
|
|
291 | rp.set ("treasurestyle", "none"); |
|
|
292 | rp.set ("layoutstyle" , style); |
|
|
293 | rp.set ("decorstyle" , decor); |
|
|
294 | rp.set ("decoroptions" , (IV)-1); |
|
|
295 | rp.set ("symmetry" , (IV)SYMMETRY_NONE); |
|
|
296 | rp.set ("orientation" , (IV)1); |
|
|
297 | rp.set ("random_seed" , RP->get_uv ("random_seed") + 0xdeadbeefU); |
|
|
298 | |
|
|
299 | rp.layoutoptions1 = RMOPT_WALLS_ONLY; |
|
|
300 | rp.dungeon_depth = RP->dungeon_level; |
|
|
301 | rp.dungeon_level = RP->dungeon_level; |
|
|
302 | rp.difficulty = RP->difficulty; |
|
|
303 | rp.difficulty_given = RP->difficulty; |
|
|
304 | rp.difficulty_increase = RP->difficulty_increase; |
|
|
305 | |
282 | the_exit->slaying = shstr_random_map_exit; |
306 | the_exit->slaying = shstr_random_map_exit; |
283 | the_exit->msg = buf; |
307 | the_exit->msg = rp.as_shstr (); |
|
|
308 | |
|
|
309 | delete &rp; |
|
|
310 | } |
284 | |
311 | |
285 | insert_ob_in_map (the_exit, map, NULL, 0); |
312 | insert_ob_in_map (the_exit, map, NULL, 0); |
286 | } |
313 | } |
287 | |
314 | |
288 | void |
315 | void |
289 | place_specials_in_map (maptile *map, char **layout, random_map_params *RP) |
316 | place_specials_in_map (maptile *map, layout &maze, random_map_params *RP) |
290 | { |
317 | { |
291 | switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) |
318 | switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) // can be NO_SPECIAL as well |
292 | { |
319 | { |
293 | case SPECIAL_SUBMAP: |
320 | case SPECIAL_SUBMAP: |
294 | { |
321 | { |
295 | /* includes a special map into the random map being made. */ |
322 | /* includes a special map into the random map being made. */ |
296 | maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty); |
323 | maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty, true); |
297 | |
324 | |
298 | if (!special_map) |
325 | if (!special_map) |
299 | break; |
326 | break; |
300 | |
327 | |
301 | int ix, iy; /* map insertion locatons */ |
328 | int ix, iy; /* map insertion locatons */ |
302 | |
329 | |
303 | if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height)) |
330 | if (find_spot_for_submap (map, maze, &ix, &iy, special_map->width, special_map->height)) |
304 | { |
331 | { |
305 | /* First, splatter everything in the dest map at the location */ |
332 | /* First, splatter everything in the dest map at the location */ |
306 | nuke_map_region (map, layout, ix, iy, special_map->width, special_map->height); |
333 | nuke_map_region (map, maze, ix, iy, special_map->width, special_map->height); |
307 | include_map_in_map (map, special_map, ix, iy); |
334 | include_map_in_map (map, special_map, ix, iy); |
308 | } |
335 | } |
309 | } |
336 | } |
310 | |
337 | |
311 | break; |
338 | break; |