1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* placing treasure in maps, where appropriate. */ |
24 | /* placing treasure in maps, where appropriate. */ |
25 | |
25 | |
26 | #include <global.h> |
26 | #include <global.h> |
… | |
… | |
45 | /* a macro to get a strongly centered random distribution, |
45 | /* a macro to get a strongly centered random distribution, |
46 | from 0 to x, centered at x/2 */ |
46 | from 0 to x, centered at x/2 */ |
47 | static int |
47 | static int |
48 | bc_random (int x) |
48 | bc_random (int x) |
49 | { |
49 | { |
50 | return (rndm (x) + rndm (x) + rndm (x)) / 3; |
50 | return (rmg_rndm (x) + rmg_rndm (x) + rmg_rndm (x)) / 3; |
51 | } |
51 | } |
52 | |
52 | |
53 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
53 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
54 | * and doors but not monsters. |
54 | * and doors but not monsters. |
55 | * This function is not map tile aware. |
55 | * This function is not map tile aware. |
… | |
… | |
82 | if (treasure_style) |
82 | if (treasure_style) |
83 | if (!strcmp (treasure_style, "none")) |
83 | if (!strcmp (treasure_style, "none")) |
84 | return; |
84 | return; |
85 | |
85 | |
86 | if (treasureoptions <= 0) |
86 | if (treasureoptions <= 0) |
87 | treasureoptions = rndm (2 * LAST_OPTION); |
87 | treasureoptions = rmg_rndm (2 * LAST_OPTION); |
88 | |
88 | |
89 | /* filter out the mutually exclusive options */ |
89 | /* filter out the mutually exclusive options */ |
90 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
90 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
91 | { |
91 | { |
92 | if (rndm (2)) |
92 | if (rmg_rndm (2)) |
93 | treasureoptions -= 1; |
93 | treasureoptions -= 1; |
94 | else |
94 | else |
95 | treasureoptions -= 2; |
95 | treasureoptions -= 2; |
96 | } |
96 | } |
97 | |
97 | |
… | |
… | |
118 | } |
118 | } |
119 | |
119 | |
120 | /* all the treasure at one spot in the map. */ |
120 | /* all the treasure at one spot in the map. */ |
121 | if (treasureoptions & CONCENTRATED) |
121 | if (treasureoptions & CONCENTRATED) |
122 | { |
122 | { |
123 | |
|
|
124 | /* map_layout_style global, and is previously set */ |
123 | /* map_layout_style global, and is previously set */ |
125 | switch (RP->map_layout_style) |
124 | switch (RP->map_layout_style) |
126 | { |
125 | { |
127 | case LAYOUT_ONION: |
126 | case LAYOUT_ONION: |
128 | case LAYOUT_SPIRAL: |
127 | case LAYOUT_SPIRAL: |
… | |
… | |
136 | for (j = 0; j < RP->Ysize; j++) |
135 | for (j = 0; j < RP->Ysize; j++) |
137 | { |
136 | { |
138 | if (layout[i][j] == 'C' || layout[i][j] == '>') |
137 | if (layout[i][j] == 'C' || layout[i][j] == '>') |
139 | { |
138 | { |
140 | int tdiv = RP->symmetry_used; |
139 | int tdiv = RP->symmetry_used; |
141 | object **doorlist; |
|
|
142 | object *chest; |
140 | object *chest; |
143 | |
141 | |
144 | if (tdiv == 3) |
142 | if (tdiv == 3) |
145 | tdiv = 2; /* this symmetry uses a divisor of 2 */ |
143 | tdiv = 2; /* this symmetry uses a divisor of 2 */ |
|
|
144 | |
146 | /* don't put a chest on an exit. */ |
145 | /* don't put a chest on an exit. */ |
147 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP); |
146 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP); |
|
|
147 | |
148 | if (!chest) |
148 | if (!chest) |
149 | continue; /* if no chest was placed NEXT */ |
149 | continue; /* if no chest was placed NEXT */ |
|
|
150 | |
150 | if (treasureoptions & (DOORED | HIDDEN)) |
151 | if (treasureoptions & (DOORED | HIDDEN)) |
151 | { |
152 | { |
152 | doorlist = find_doors_in_room (map, i, j, RP); |
153 | object **doorlist = find_doors_in_room (map, i, j, RP); |
153 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
154 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
154 | free (doorlist); |
155 | free (doorlist); |
155 | } |
156 | } |
156 | } |
157 | } |
157 | } |
158 | } |
158 | } |
159 | } |
159 | break; |
160 | break; |
160 | } |
161 | } |
|
|
162 | |
161 | default: |
163 | default: |
162 | { |
164 | { |
163 | int i, j, tries; |
165 | int i, j, tries; |
164 | object *chest; |
166 | object *chest; |
165 | object **doorlist; |
167 | object **doorlist; |
166 | |
168 | |
167 | i = j = -1; |
169 | i = j = -1; |
168 | tries = 0; |
170 | tries = 0; |
169 | while (i == -1 && tries < 100) |
171 | while (i == -1 && tries < 100) |
170 | { |
172 | { |
171 | i = rndm (RP->Xsize - 2) + 1; |
173 | i = rmg_rndm (RP->Xsize - 2) + 1; |
172 | j = rndm (RP->Ysize - 2) + 1; |
174 | j = rmg_rndm (RP->Ysize - 2) + 1; |
173 | find_enclosed_spot (map, &i, &j, RP); |
175 | find_enclosed_spot (map, &i, &j, RP); |
|
|
176 | |
174 | if (wall_blocked (map, i, j)) |
177 | if (wall_blocked (map, i, j)) |
175 | i = -1; |
178 | i = -1; |
|
|
179 | |
176 | tries++; |
180 | tries++; |
177 | } |
181 | } |
|
|
182 | |
178 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); |
183 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); |
|
|
184 | |
179 | if (!chest) |
185 | if (!chest) |
180 | return; |
186 | return; |
|
|
187 | |
181 | i = chest->x; |
188 | i = chest->x; |
182 | j = chest->y; |
189 | j = chest->y; |
183 | if (treasureoptions & (DOORED | HIDDEN)) |
190 | if (treasureoptions & (DOORED | HIDDEN)) |
184 | { |
191 | { |
185 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
192 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
… | |
… | |
193 | { /* DIFFUSE treasure layout */ |
200 | { /* DIFFUSE treasure layout */ |
194 | int ti, i, j; |
201 | int ti, i, j; |
195 | |
202 | |
196 | for (ti = 0; ti < num_treasures; ti++) |
203 | for (ti = 0; ti < num_treasures; ti++) |
197 | { |
204 | { |
198 | i = rndm (RP->Xsize - 2) + 1; |
205 | i = rmg_rndm (RP->Xsize - 2) + 1; |
199 | j = rndm (RP->Ysize - 2) + 1; |
206 | j = rmg_rndm (RP->Ysize - 2) + 1; |
200 | place_chest (treasureoptions, i, j, map, style_map, 1, RP); |
207 | place_chest (treasureoptions, i, j, map, style_map, 1, RP); |
201 | } |
208 | } |
202 | } |
209 | } |
203 | } |
210 | } |
204 | |
211 | |
205 | /* put a chest into the map, near x and y, with the treasure style |
212 | /* put a chest into the map, near x and y, with the treasure style |
206 | determined (may be null, or may be a treasure list from lib/treasures, |
213 | determined (may be null, or may be a treasure list from lib/treasures, |
207 | if the global variable "treasurestyle" is set to that treasure list's name */ |
214 | if the global variable "treasurestyle" is set to that treasure list's name */ |
208 | |
|
|
209 | object * |
215 | object * |
210 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
216 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
211 | { |
217 | { |
212 | object *the_chest; |
|
|
213 | int i, xl, yl; |
|
|
214 | |
|
|
215 | the_chest = get_archetype ("chest"); /* was "chest_2" */ |
218 | object *the_chest = archetype::get (shstr_chest); /* was "chest_2" */ |
216 | |
219 | |
217 | /* first, find a place to put the chest. */ |
220 | /* first, find a place to put the chest. */ |
218 | i = find_first_free_spot (the_chest, map, x, y); |
221 | int i = find_first_free_spot (the_chest, map, x, y); // this call uses the main rng |
219 | if (i == -1) |
222 | if (i == -1) |
220 | { |
223 | { |
221 | the_chest->destroy (); |
224 | the_chest->destroy (); |
222 | return NULL; |
225 | return NULL; |
223 | } |
226 | } |
224 | |
227 | |
225 | xl = x + freearr_x[i]; |
228 | int xl = x + freearr_x[i]; |
226 | yl = y + freearr_y[i]; |
229 | int yl = y + freearr_y[i]; |
227 | |
230 | |
228 | /* if the placement is blocked, return a fail. */ |
231 | /* if the placement is blocked, return a fail. */ |
229 | if (wall_blocked (map, xl, yl)) |
232 | if (wall_blocked (map, xl, yl)) |
230 | return 0; |
233 | return 0; |
231 | |
234 | |
… | |
… | |
238 | treasurelist *tlist = find_treasurelist (RP->treasurestyle); |
241 | treasurelist *tlist = find_treasurelist (RP->treasurestyle); |
239 | |
242 | |
240 | if (tlist != NULL) |
243 | if (tlist != NULL) |
241 | for (ti = 0; ti < n_treasures; ti++) |
244 | for (ti = 0; ti < n_treasures; ti++) |
242 | { /* use the treasure list */ |
245 | { /* use the treasure list */ |
243 | object *new_treasure = style_map->pick_random_object (); |
246 | object *new_treasure = style_map->pick_random_object (rmg_rndm); |
244 | |
247 | |
245 | insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); |
248 | insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); |
246 | } |
249 | } |
247 | else |
250 | else |
248 | { /* use the style map */ |
251 | { /* use the style map */ |
… | |
… | |
259 | |
262 | |
260 | /* stick a trap in the chest if required */ |
263 | /* stick a trap in the chest if required */ |
261 | if (treasureoptions & TRAPPED) |
264 | if (treasureoptions & TRAPPED) |
262 | { |
265 | { |
263 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
266 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
264 | object *the_trap; |
|
|
265 | |
267 | |
266 | if (trap_map) |
268 | if (trap_map) |
267 | { |
269 | { |
268 | the_trap = trap_map->pick_random_object (); |
270 | object *the_trap = trap_map->pick_random_object (rmg_rndm); |
|
|
271 | |
269 | the_trap->stats.Cha = 10 + RP->difficulty; |
272 | the_trap->stats.Cha = 10 + RP->difficulty; |
270 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
273 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
|
|
274 | |
271 | if (the_trap) |
275 | if (the_trap) |
272 | { |
276 | { |
273 | object *new_trap; |
277 | object *new_trap = the_trap->arch->instance ();//TODO: why not clone? |
274 | |
278 | |
275 | new_trap = arch_to_object (the_trap->arch); |
|
|
276 | new_trap->copy_to (the_trap); |
|
|
277 | new_trap->x = x; |
279 | new_trap->x = x; |
278 | new_trap->y = y; |
280 | new_trap->y = y; |
279 | insert_ob_in_ob (new_trap, the_chest); |
281 | insert_ob_in_ob (new_trap, the_chest); |
280 | } |
282 | } |
281 | } |
283 | } |
… | |
… | |
286 | there's only 1 treasure.... */ |
288 | there's only 1 treasure.... */ |
287 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
289 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
288 | { |
290 | { |
289 | char keybuf[1024]; |
291 | char keybuf[1024]; |
290 | |
292 | |
291 | sprintf (keybuf, "%d", rndm (1000000000)); |
293 | sprintf (keybuf, "%d", rmg_rndm (1000000000)); |
292 | the_chest->slaying = keybuf; |
294 | the_chest->slaying = keybuf; |
293 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
295 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
294 | } |
296 | } |
295 | |
297 | |
296 | /* actually place the chest. */ |
298 | /* actually place the chest. */ |
… | |
… | |
345 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP) |
347 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP) |
346 | { |
348 | { |
347 | int i, j; |
349 | int i, j; |
348 | int kx = 0, ky = 0; |
350 | int kx = 0, ky = 0; |
349 | object *the_keymaster; /* the monster that gets the key. */ |
351 | object *the_keymaster; /* the monster that gets the key. */ |
350 | object *the_key; |
|
|
351 | |
352 | |
352 | /* get a key and set its keycode */ |
353 | /* get a key and set its keycode */ |
353 | the_key = get_archetype ("key2"); |
354 | object *the_key = archetype::get (shstr_key2); |
354 | the_key->slaying = keycode; |
355 | the_key->slaying = keycode; |
355 | |
356 | |
356 | if (door_flag == PASS_DOORS) |
357 | if (door_flag == PASS_DOORS) |
357 | { |
358 | { |
358 | int tries = 0; |
359 | int tries = 0; |
359 | |
360 | |
360 | the_keymaster = 0; |
361 | the_keymaster = 0; |
361 | while (tries < 15 && !the_keymaster) |
362 | while (tries < 15 && !the_keymaster) |
362 | { |
363 | { |
363 | i = rndm (RP->Xsize - 2) + 1; |
364 | i = rmg_rndm (RP->Xsize - 2) + 1; |
364 | j = rndm (RP->Ysize - 2) + 1; |
365 | j = rmg_rndm (RP->Ysize - 2) + 1; |
365 | tries++; |
366 | tries++; |
366 | the_keymaster = find_closest_monster (map, i, j, RP); |
367 | the_keymaster = find_closest_monster (map, i, j, RP); |
367 | } |
368 | } |
368 | |
369 | |
369 | /* if we don't find a good keymaster, drop the key on the ground. */ |
370 | /* if we don't find a good keymaster, drop the key on the ground. */ |
… | |
… | |
372 | int freeindex; |
373 | int freeindex; |
373 | |
374 | |
374 | freeindex = -1; |
375 | freeindex = -1; |
375 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
376 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
376 | { |
377 | { |
377 | kx = rndm (RP->Xsize - 2) + 1; |
378 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
378 | ky = rndm (RP->Ysize - 2) + 1; |
379 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
379 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
380 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
380 | } |
381 | } |
381 | |
382 | |
382 | // can freeindex ever be < 0? |
383 | // can freeindex ever be < 0? |
383 | if (freeindex >= 0) |
384 | if (freeindex >= 0) |
… | |
… | |
428 | the_key->y = ky; |
429 | the_key->y = ky; |
429 | insert_ob_in_map (the_key, map, NULL, 0); |
430 | insert_ob_in_map (the_key, map, NULL, 0); |
430 | return 1; |
431 | return 1; |
431 | } |
432 | } |
432 | |
433 | |
433 | insert_ob_in_ob (the_key, the_keymaster); |
434 | insert_ob_in_ob (the_key, the_keymaster->head_ ()); |
434 | return 1; |
435 | return 1; |
435 | } |
436 | } |
436 | |
437 | |
437 | |
438 | |
438 | |
439 | |
… | |
… | |
475 | return theMonsterToFind; |
476 | return theMonsterToFind; |
476 | } |
477 | } |
477 | } |
478 | } |
478 | |
479 | |
479 | /* now search all the 8 squares around recursively for a monster,in random order */ |
480 | /* now search all the 8 squares around recursively for a monster,in random order */ |
480 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
481 | for (i = rmg_rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
481 | { |
482 | { |
482 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
483 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
483 | if (theMonsterToFind != NULL) |
484 | if (theMonsterToFind != NULL) |
484 | return theMonsterToFind; |
485 | return theMonsterToFind; |
485 | } |
486 | } |
|
|
487 | |
486 | return theMonsterToFind; |
488 | return theMonsterToFind; |
487 | } |
489 | } |
488 | |
|
|
489 | |
490 | |
490 | /* sets up some data structures: the _recursive form does the |
491 | /* sets up some data structures: the _recursive form does the |
491 | real work. */ |
492 | real work. */ |
492 | |
|
|
493 | object * |
493 | object * |
494 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
494 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
495 | { |
495 | { |
496 | char **layout2; |
496 | Layout layout2 (RP); |
497 | int i, j; |
497 | |
|
|
498 | layout2->clear (); |
|
|
499 | |
|
|
500 | /* allocate and copy the layout, converting C to 0. */ |
|
|
501 | for (int i = 0; i < layout2->w; i++) |
|
|
502 | for (int j = 0; j < layout2->h; j++) |
|
|
503 | if (wall_blocked (map, i, j)) |
|
|
504 | layout2[i][j] = '#'; |
498 | |
505 | |
499 | theMonsterToFind = 0; |
506 | theMonsterToFind = 0; |
500 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
|
|
501 | /* allocate and copy the layout, converting C to 0. */ |
|
|
502 | for (i = 0; i < RP->Xsize; i++) |
|
|
503 | { |
|
|
504 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
|
|
505 | for (j = 0; j < RP->Ysize; j++) |
|
|
506 | { |
|
|
507 | if (wall_blocked (map, i, j)) |
|
|
508 | layout2[i][j] = '#'; |
|
|
509 | } |
|
|
510 | } |
|
|
511 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
507 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
512 | |
508 | |
513 | /* deallocate the temp. layout */ |
509 | layout2.free (); |
514 | for (i = 0; i < RP->Xsize; i++) |
|
|
515 | { |
|
|
516 | free (layout2[i]); |
|
|
517 | } |
|
|
518 | free (layout2); |
|
|
519 | |
510 | |
520 | return theMonsterToFind; |
511 | return theMonsterToFind; |
521 | } |
512 | } |
522 | |
513 | |
523 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
514 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
… | |
… | |
548 | room_free_spots_x[number_of_free_spots_in_room] = x; |
539 | room_free_spots_x[number_of_free_spots_in_room] = x; |
549 | room_free_spots_y[number_of_free_spots_in_room] = y; |
540 | room_free_spots_y[number_of_free_spots_in_room] = y; |
550 | number_of_free_spots_in_room++; |
541 | number_of_free_spots_in_room++; |
551 | |
542 | |
552 | /* now search all the 8 squares around recursively for free spots,in random order */ |
543 | /* now search all the 8 squares around recursively for free spots,in random order */ |
553 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
544 | for (i = rmg_rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
554 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
545 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
555 | |
546 | |
556 | } |
547 | } |
557 | |
548 | |
558 | /* find a random non-blocked spot in this room to drop a key. */ |
549 | /* find a random non-blocked spot in this room to drop a key. */ |
… | |
… | |
579 | /* setup num_free_spots and room_free_spots */ |
570 | /* setup num_free_spots and room_free_spots */ |
580 | find_spot_in_room_recursive (layout2, x, y, RP); |
571 | find_spot_in_room_recursive (layout2, x, y, RP); |
581 | |
572 | |
582 | if (number_of_free_spots_in_room > 0) |
573 | if (number_of_free_spots_in_room > 0) |
583 | { |
574 | { |
584 | i = rndm (number_of_free_spots_in_room); |
575 | i = rmg_rndm (number_of_free_spots_in_room); |
585 | *kx = room_free_spots_x[i]; |
576 | *kx = room_free_spots_x[i]; |
586 | *ky = room_free_spots_y[i]; |
577 | *ky = room_free_spots_y[i]; |
587 | } |
578 | } |
588 | |
579 | |
589 | /* deallocate the temp. layout */ |
580 | /* deallocate the temp. layout */ |
… | |
… | |
657 | *cy = ly; |
648 | *cy = ly; |
658 | return; |
649 | return; |
659 | } |
650 | } |
660 | } |
651 | } |
661 | /* give up and return the closest free spot. */ |
652 | /* give up and return the closest free spot. */ |
662 | i = find_free_spot (archetype::find ("chest"), map, x, y, 1, SIZEOFFREE1 + 1); |
653 | i = find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); |
663 | |
654 | |
664 | if (i != -1) |
655 | if (i != -1) |
665 | { |
656 | { |
666 | *cx = x + freearr_x[i]; |
657 | *cx = x + freearr_x[i]; |
667 | *cy = y + freearr_y[i]; |
658 | *cy = y + freearr_y[i]; |
… | |
… | |
746 | if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
737 | if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
747 | return tmp; |
738 | return tmp; |
748 | return NULL; |
739 | return NULL; |
749 | } |
740 | } |
750 | |
741 | |
751 | |
|
|
752 | /* the workhorse routine, which finds the doors in a room */ |
742 | /* the workhorse routine, which finds the doors in a room */ |
753 | void |
743 | void |
754 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
744 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
755 | { |
745 | { |
756 | int i, j; |
746 | int i, j; |
… | |
… | |
770 | layout[x][y] = 1; |
760 | layout[x][y] = 1; |
771 | door = door_in_square (map, x, y); |
761 | door = door_in_square (map, x, y); |
772 | if (door) |
762 | if (door) |
773 | { |
763 | { |
774 | doorlist[*ndoors] = door; |
764 | doorlist[*ndoors] = door; |
|
|
765 | |
775 | if (*ndoors > 1022) /* eek! out of memory */ |
766 | if (*ndoors > 1022) /* eek! out of memory */ |
776 | { |
767 | { |
777 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
768 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
778 | return; |
769 | return; |
779 | } |
770 | } |
… | |
… | |
784 | else |
775 | else |
785 | { |
776 | { |
786 | layout[x][y] = 1; |
777 | layout[x][y] = 1; |
787 | |
778 | |
788 | /* now search all the 8 squares around recursively for free spots,in random order */ |
779 | /* now search all the 8 squares around recursively for free spots,in random order */ |
789 | for (i = rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) |
780 | for (i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) |
790 | find_doors_in_room_recursive (layout, map, |
781 | find_doors_in_room_recursive (layout, map, |
791 | x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], |
782 | x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], |
792 | doorlist, ndoors, RP); |
783 | doorlist, ndoors, RP); |
793 | } |
784 | } |
794 | } |
785 | } |
795 | |
786 | |
796 | /* find a random non-blocked spot in this room to drop a key. */ |
787 | /* find a random non-blocked spot in this room to drop a key. */ |
797 | object ** |
788 | object ** |
798 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
789 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
799 | { |
790 | { |
800 | char **layout2; |
|
|
801 | object **doorlist; |
|
|
802 | int i, j; |
791 | int i, j; |
803 | int ndoors = 0; |
792 | int ndoors = 0; |
804 | |
793 | |
805 | doorlist = (object **) calloc (sizeof (int), 1024); |
794 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
806 | |
795 | |
807 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
796 | LayoutData layout2 (RP->Xsize, RP->Ysize); |
|
|
797 | layout2.clear (); |
|
|
798 | |
808 | /* allocate and copy the layout, converting C to 0. */ |
799 | /* allocate and copy the layout, converting C to 0. */ |
809 | for (i = 0; i < RP->Xsize; i++) |
800 | for (i = 0; i < RP->Xsize; i++) |
810 | { |
|
|
811 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
|
|
812 | for (j = 0; j < RP->Ysize; j++) |
801 | for (j = 0; j < RP->Ysize; j++) |
813 | { |
802 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
814 | if (wall_blocked (map, i, j)) |
|
|
815 | layout2[i][j] = '#'; |
|
|
816 | } |
|
|
817 | } |
|
|
818 | |
803 | |
819 | /* setup num_free_spots and room_free_spots */ |
804 | /* setup num_free_spots and room_free_spots */ |
820 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
805 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
821 | |
806 | |
822 | /* deallocate the temp. layout */ |
|
|
823 | for (i = 0; i < RP->Xsize; i++) |
|
|
824 | free (layout2[i]); |
|
|
825 | |
|
|
826 | free (layout2); |
|
|
827 | return doorlist; |
807 | return doorlist; |
828 | } |
808 | } |
829 | |
|
|
830 | |
|
|
831 | |
809 | |
832 | /* locks and/or hides all the doors in doorlist, or does nothing if |
810 | /* locks and/or hides all the doors in doorlist, or does nothing if |
833 | opts doesn't say to lock/hide doors. */ |
811 | opts doesn't say to lock/hide doors. */ |
834 | |
|
|
835 | void |
812 | void |
836 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) |
813 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) |
837 | { |
814 | { |
838 | object *door; |
815 | object *door; |
839 | int i; |
816 | int i; |
… | |
… | |
853 | new_door->y = door->y; |
830 | new_door->y = door->y; |
854 | door->remove (); |
831 | door->remove (); |
855 | door->destroy (); |
832 | door->destroy (); |
856 | doorlist[i] = new_door; |
833 | doorlist[i] = new_door; |
857 | insert_ob_in_map (new_door, map, NULL, 0); |
834 | insert_ob_in_map (new_door, map, NULL, 0); |
858 | sprintf (keybuf, "%d", rndm (1000000000)); |
835 | sprintf (keybuf, "%d", rmg_rndm (1000000000)); |
859 | new_door->slaying = keybuf; |
836 | new_door->slaying = keybuf; |
860 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
837 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
861 | } |
838 | } |
862 | } |
839 | } |
863 | |
840 | |
… | |
… | |
874 | { |
851 | { |
875 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
852 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
876 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
853 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
877 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
854 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
878 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
855 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
|
|
856 | |
879 | door->face = wallface->face; |
857 | door->face = wallface->face; |
|
|
858 | |
880 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
859 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
881 | wallface->remove (); |
860 | wallface->remove (); |
|
|
861 | |
882 | wallface->destroy (); |
862 | wallface->destroy (); |
883 | } |
863 | } |
884 | } |
864 | } |
885 | } |
865 | } |
886 | } |
866 | } |