1 |
elmex |
1.1 |
/* |
2 |
root |
1.26 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
pippijn |
1.16 |
* |
4 |
root |
1.41 |
* Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.40 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
7 |
pippijn |
1.16 |
* |
8 |
root |
1.37 |
* 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 |
10 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
11 |
|
|
* option) any later version. |
12 |
pippijn |
1.16 |
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
root |
1.24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
pippijn |
1.16 |
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
root |
1.37 |
* You should have received a copy of the Affero GNU General Public License |
19 |
|
|
* and the GNU General Public License along with this program. If not, see |
20 |
|
|
* <http://www.gnu.org/licenses/>. |
21 |
root |
1.24 |
* |
22 |
root |
1.26 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
pippijn |
1.16 |
*/ |
24 |
elmex |
1.1 |
|
25 |
|
|
/* Specials in this file: |
26 |
root |
1.2 |
included maps */ |
27 |
elmex |
1.1 |
|
28 |
|
|
#include <global.h> |
29 |
|
|
#include <random_map.h> |
30 |
|
|
#include <rproto.h> |
31 |
|
|
|
32 |
|
|
#define NUM_OF_SPECIAL_TYPES 4 |
33 |
|
|
#define NO_SPECIAL 0 |
34 |
|
|
#define SPECIAL_SUBMAP 1 |
35 |
|
|
#define SPECIAL_FOUNTAIN 2 |
36 |
|
|
#define SPECIAL_EXIT 3 |
37 |
|
|
|
38 |
|
|
#define GLORY_HOLE 1 |
39 |
|
|
#define ORC_ZONE 2 |
40 |
|
|
#define MINING_ZONE 3 |
41 |
|
|
#define NR_OF_HOLE_TYPES 3 |
42 |
|
|
|
43 |
root |
1.32 |
/* clear map completely of all !floor objects: |
44 |
|
|
* a rectangular area of xsize, ysize |
45 |
|
|
* is cleared with the top left corner at xstart, ystart |
46 |
|
|
*/ |
47 |
|
|
static void |
48 |
|
|
nuke_map_region (maptile *map, char **layout, int xstart, int ystart, int xsize, int ysize) |
49 |
root |
1.4 |
{ |
50 |
root |
1.32 |
for (int i = xstart; i < xstart + xsize; i++) |
51 |
|
|
for (int j = ystart; j < ystart + ysize; j++) |
52 |
|
|
{ |
53 |
|
|
layout[i][j] = 'S'; |
54 |
root |
1.4 |
|
55 |
root |
1.32 |
for (object *tmp = map->at (i, j).bot; tmp; ) |
56 |
|
|
if (tmp->flag [FLAG_IS_FLOOR]) |
57 |
|
|
tmp = tmp->above; |
58 |
|
|
else |
59 |
|
|
{ |
60 |
|
|
object *head = tmp->head_ (); |
61 |
|
|
tmp = tmp->above; |
62 |
root |
1.35 |
head->destroy (); |
63 |
root |
1.32 |
} |
64 |
elmex |
1.1 |
} |
65 |
|
|
} |
66 |
|
|
|
67 |
root |
1.4 |
/* copy in_map into dest_map at point x,y */ |
68 |
root |
1.32 |
static void |
69 |
root |
1.6 |
include_map_in_map (maptile *dest_map, maptile *in_map, int x, int y) |
70 |
root |
1.4 |
{ |
71 |
root |
1.30 |
for (int i = 0; i < in_map->width; i++) |
72 |
|
|
for (int j = 0; j < in_map->height; j++) |
73 |
|
|
for (object *tmp = GET_MAP_OB (in_map, i, j); tmp; tmp = tmp->above) |
74 |
|
|
{ |
75 |
root |
1.32 |
/* don't copy tails: must be dealt with specially. */ |
76 |
root |
1.30 |
if (!tmp->is_head ()) |
77 |
|
|
continue; |
78 |
|
|
|
79 |
root |
1.31 |
object *new_ob = tmp->deep_clone (); |
80 |
root |
1.30 |
|
81 |
|
|
if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
82 |
root |
1.36 |
new_ob->add_link (dest_map, tmp->find_link ()->id); |
83 |
root |
1.30 |
|
84 |
root |
1.31 |
dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
85 |
root |
1.30 |
} |
86 |
elmex |
1.1 |
} |
87 |
|
|
|
88 |
root |
1.32 |
static int |
89 |
root |
1.6 |
find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize) |
90 |
root |
1.4 |
{ |
91 |
root |
1.32 |
int blocked, i, j; |
92 |
root |
1.4 |
|
93 |
elmex |
1.1 |
/* don't even try to place a submap into a map if the big map isn't |
94 |
|
|
sufficiently large. */ |
95 |
root |
1.10 |
if (2 * xsize > map->width || 2 * ysize > map->height) |
96 |
root |
1.4 |
return 0; |
97 |
|
|
|
98 |
elmex |
1.1 |
/* search a bit for a completely free spot. */ |
99 |
root |
1.32 |
for (int tries = 0; tries < 20; tries++) |
100 |
root |
1.4 |
{ |
101 |
root |
1.32 |
blocked = 0; |
102 |
|
|
|
103 |
root |
1.4 |
/* pick a random location in the layout */ |
104 |
root |
1.33 |
i = rmg_rndm (1, map->width - xsize - 2); |
105 |
|
|
j = rmg_rndm (1, map->height - ysize - 2); |
106 |
root |
1.32 |
|
107 |
|
|
for (int l = i; l < i + xsize; l++) |
108 |
|
|
for (int m = j; m < j + ysize; m++) |
109 |
|
|
{ |
110 |
|
|
blocked = 1; |
111 |
|
|
break; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
if (!blocked) |
115 |
root |
1.4 |
break; |
116 |
|
|
} |
117 |
|
|
|
118 |
elmex |
1.1 |
/* if we failed, relax the restrictions */ |
119 |
root |
1.32 |
if (blocked) |
120 |
root |
1.4 |
{ /* failure, try a relaxed placer. */ |
121 |
|
|
/* pick a random location in the layout */ |
122 |
root |
1.32 |
for (int tries = 0; tries < 10; tries++) |
123 |
root |
1.4 |
{ |
124 |
root |
1.33 |
i = rmg_rndm (1, map->width - xsize - 2); |
125 |
|
|
j = rmg_rndm (1, map->height - ysize - 2); |
126 |
root |
1.32 |
|
127 |
|
|
blocked = 0; |
128 |
|
|
|
129 |
|
|
for (int l = i; l < i + xsize; l++) |
130 |
|
|
for (int m = j; m < j + ysize; m++) |
131 |
|
|
if (layout[l][m] != '#' && layout[l][m] != 'D' && layout[l][m] != 0) |
132 |
|
|
{ |
133 |
|
|
blocked = 1; |
134 |
|
|
break; |
135 |
|
|
} |
136 |
root |
1.4 |
} |
137 |
elmex |
1.1 |
} |
138 |
root |
1.27 |
|
139 |
root |
1.32 |
if (blocked) |
140 |
root |
1.4 |
return 0; |
141 |
root |
1.27 |
|
142 |
root |
1.4 |
*ix = i; |
143 |
|
|
*iy = j; |
144 |
root |
1.32 |
|
145 |
elmex |
1.1 |
return 1; |
146 |
root |
1.4 |
} |
147 |
elmex |
1.1 |
|
148 |
root |
1.32 |
static void |
149 |
root |
1.6 |
place_fountain_with_specials (maptile *map) |
150 |
root |
1.4 |
{ |
151 |
|
|
int ix, iy, i = -1, tries = 0; |
152 |
root |
1.6 |
maptile *fountain_style = find_style ("/styles/misc", "fountains", -1); |
153 |
root |
1.18 |
|
154 |
|
|
if (!fountain_style) |
155 |
root |
1.19 |
{ |
156 |
pippijn |
1.20 |
LOG (llevError, "unable to load stylemap /styles/misc fountains\n"); |
157 |
root |
1.19 |
return; |
158 |
|
|
} |
159 |
root |
1.18 |
|
160 |
root |
1.32 |
object *fountain = archetype::get (shstr_fountain); |
161 |
|
|
object *potion = fountain_style->pick_random_object (rmg_rndm)->clone (); |
162 |
root |
1.4 |
|
163 |
|
|
while (i < 0 && tries < 10) |
164 |
|
|
{ |
165 |
root |
1.32 |
ix = rmg_rndm (map->width - 2) + 1; |
166 |
|
|
iy = rmg_rndm (map->height - 2) + 1; |
167 |
root |
1.15 |
i = find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); |
168 |
root |
1.4 |
tries++; |
169 |
root |
1.8 |
} |
170 |
|
|
|
171 |
root |
1.4 |
if (i == -1) |
172 |
|
|
{ /* can't place fountain */ |
173 |
root |
1.35 |
fountain->destroy (); |
174 |
|
|
potion->destroy (); |
175 |
root |
1.4 |
return; |
176 |
|
|
} |
177 |
root |
1.8 |
|
178 |
elmex |
1.1 |
ix += freearr_x[i]; |
179 |
|
|
iy += freearr_y[i]; |
180 |
root |
1.4 |
potion->face = fountain->face; |
181 |
|
|
SET_FLAG (potion, FLAG_NO_PICK); |
182 |
|
|
SET_FLAG (potion, FLAG_IDENTIFIED); |
183 |
root |
1.38 |
potion->name = potion->name_pl = shstr_fountain; |
184 |
elmex |
1.1 |
potion->x = ix; |
185 |
|
|
potion->y = iy; |
186 |
root |
1.38 |
potion->material = name_to_material (shstr_adamantium); |
187 |
elmex |
1.1 |
fountain->x = ix; |
188 |
|
|
fountain->y = iy; |
189 |
root |
1.4 |
insert_ob_in_map (fountain, map, NULL, 0); |
190 |
|
|
insert_ob_in_map (potion, map, NULL, 0); |
191 |
elmex |
1.1 |
} |
192 |
|
|
|
193 |
root |
1.32 |
static void |
194 |
root |
1.12 |
place_special_exit (maptile *map, int hole_type, random_map_params *RP) |
195 |
root |
1.4 |
{ |
196 |
|
|
int ix, iy, i = -1; |
197 |
root |
1.23 |
char buf[16384]; |
198 |
|
|
const char *style, *decor, *mon; |
199 |
root |
1.6 |
maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1); |
200 |
root |
1.4 |
int g_xsize, g_ysize; |
201 |
|
|
|
202 |
root |
1.18 |
if (!exit_style) |
203 |
root |
1.19 |
{ |
204 |
root |
1.28 |
LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n"); |
205 |
root |
1.19 |
return; |
206 |
|
|
} |
207 |
root |
1.18 |
|
208 |
root |
1.4 |
if (!exit_style) |
209 |
|
|
return; |
210 |
|
|
|
211 |
root |
1.32 |
object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone (); |
212 |
root |
1.4 |
|
213 |
root |
1.25 |
// put an upper bound here, just in case |
214 |
|
|
for (int repeat = 8192; --repeat; ) |
215 |
root |
1.4 |
{ |
216 |
root |
1.33 |
ix = rmg_rndm (1, map->width - 2); |
217 |
|
|
iy = rmg_rndm (1, map->height - 2); |
218 |
root |
1.25 |
|
219 |
root |
1.15 |
i = find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); |
220 |
root |
1.25 |
if (i >= 0) |
221 |
|
|
{ |
222 |
|
|
ix += freearr_x[i]; |
223 |
|
|
iy += freearr_y[i]; |
224 |
|
|
break; |
225 |
|
|
} |
226 |
elmex |
1.1 |
} |
227 |
root |
1.4 |
|
228 |
|
|
the_exit->x = ix; |
229 |
|
|
the_exit->y = iy; |
230 |
|
|
|
231 |
|
|
if (!hole_type) |
232 |
root |
1.32 |
hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1; |
233 |
root |
1.4 |
|
234 |
|
|
switch (hole_type) |
235 |
|
|
{ |
236 |
root |
1.12 |
case GLORY_HOLE: /* treasures */ |
237 |
|
|
{ |
238 |
root |
1.32 |
g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
239 |
|
|
g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
240 |
root |
1.12 |
style = "onion"; |
241 |
|
|
decor = "wealth2"; |
242 |
|
|
mon = "none"; |
243 |
|
|
break; |
244 |
|
|
} |
245 |
root |
1.4 |
|
246 |
root |
1.12 |
case ORC_ZONE: /* hole with orcs in it. */ |
247 |
|
|
{ |
248 |
root |
1.32 |
g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
249 |
|
|
g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; |
250 |
root |
1.12 |
style = "onion"; |
251 |
|
|
decor = "wealth2"; |
252 |
|
|
mon = "orc"; |
253 |
|
|
break; |
254 |
|
|
} |
255 |
root |
1.4 |
|
256 |
root |
1.12 |
case MINING_ZONE: /* hole with orcs in it. */ |
257 |
|
|
{ |
258 |
root |
1.32 |
g_xsize = rmg_rndm (9) + 4 + RP->difficulty / 4; |
259 |
|
|
g_ysize = rmg_rndm (9) + 4 + RP->difficulty / 4; |
260 |
root |
1.12 |
style = "maze"; |
261 |
|
|
decor = "minerals2"; |
262 |
|
|
mon = "none"; |
263 |
|
|
break; |
264 |
|
|
} |
265 |
root |
1.4 |
|
266 |
root |
1.12 |
default: /* undefined */ |
267 |
|
|
LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type); |
268 |
|
|
return; |
269 |
|
|
break; |
270 |
elmex |
1.1 |
} |
271 |
|
|
|
272 |
root |
1.4 |
/* Need to be at least this size, otherwise the load |
273 |
|
|
* code will generate new size values which are too large. |
274 |
|
|
*/ |
275 |
root |
1.27 |
if (g_xsize < MIN_RANDOM_MAP_SIZE) g_xsize = MIN_RANDOM_MAP_SIZE; |
276 |
|
|
if (g_ysize < MIN_RANDOM_MAP_SIZE) g_ysize = MIN_RANDOM_MAP_SIZE; |
277 |
root |
1.4 |
|
278 |
|
|
write_parameters_to_string (buf, g_xsize, g_ysize, RP->wallstyle, RP->floorstyle, mon, |
279 |
root |
1.42 |
"none", style, decor, "none", 0, RP->exitstyle, 0, 0, 0, |
280 |
root |
1.11 |
RMOPT_WALLS_ONLY, 0, 0, 1, RP->dungeon_level, RP->dungeon_level, |
281 |
root |
1.4 |
RP->difficulty, RP->difficulty, -1, 1, 0, 0, 0, 0, RP->difficulty_increase); |
282 |
root |
1.39 |
the_exit->slaying = shstr_random_map_exit; |
283 |
root |
1.4 |
the_exit->msg = buf; |
284 |
elmex |
1.1 |
|
285 |
root |
1.4 |
insert_ob_in_map (the_exit, map, NULL, 0); |
286 |
elmex |
1.1 |
} |
287 |
root |
1.4 |
|
288 |
|
|
void |
289 |
root |
1.12 |
place_specials_in_map (maptile *map, char **layout, random_map_params *RP) |
290 |
root |
1.4 |
{ |
291 |
root |
1.32 |
switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) |
292 |
root |
1.4 |
{ |
293 |
root |
1.19 |
case SPECIAL_SUBMAP: |
294 |
root |
1.32 |
{ |
295 |
|
|
/* includes a special map into the random map being made. */ |
296 |
|
|
maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty); |
297 |
|
|
|
298 |
|
|
if (!special_map) |
299 |
|
|
break; |
300 |
root |
1.4 |
|
301 |
root |
1.32 |
int ix, iy; /* map insertion locatons */ |
302 |
root |
1.19 |
|
303 |
root |
1.32 |
if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height)) |
304 |
|
|
{ |
305 |
|
|
/* First, splatter everything in the dest map at the location */ |
306 |
|
|
nuke_map_region (map, layout, ix, iy, special_map->width, special_map->height); |
307 |
|
|
include_map_in_map (map, special_map, ix, iy); |
308 |
|
|
} |
309 |
|
|
} |
310 |
root |
1.12 |
|
311 |
root |
1.19 |
break; |
312 |
root |
1.4 |
|
313 |
root |
1.19 |
case SPECIAL_FOUNTAIN: |
314 |
root |
1.12 |
/* Make a special fountain: an unpickable potion disguised as |
315 |
|
|
a fountain, or rather, colocated with a fountain. */ |
316 |
root |
1.19 |
place_fountain_with_specials (map); |
317 |
|
|
break; |
318 |
root |
1.4 |
|
319 |
root |
1.19 |
case SPECIAL_EXIT: |
320 |
root |
1.12 |
/* Make an exit to another random map, e.g. a gloryhole. */ |
321 |
root |
1.19 |
place_special_exit (map, 0, RP); |
322 |
|
|
break; |
323 |
root |
1.4 |
} |
324 |
root |
1.27 |
} |
325 |
elmex |
1.1 |
|