1 | |
|
|
2 | /* |
1 | /* |
|
|
2 | <<<<<<< treasure.C |
3 | CrossFire, A Multiplayer game for X-windows |
3 | * CrossFire, A Multiplayer game |
4 | |
4 | * |
|
|
5 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
7 | * Copyright (C) 1992 Frank Tore Johansen |
7 | |
8 | * |
8 | This program is free software; you can redistribute it and/or modify |
9 | * This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
10 | * it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
12 | * (at your option) any later version. |
12 | |
13 | * |
13 | This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | |
18 | * |
18 | You should have received a copy of the GNU General Public License |
19 | * You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | * along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
22 | * |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 | */ |
24 | */ |
|
|
25 | ======= |
|
|
26 | * CrossFire, A Multiplayer game for X-windows |
|
|
27 | * |
|
|
28 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
|
|
29 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
|
|
30 | * Copyright (C) 1992 Frank Tore Johansen |
|
|
31 | * |
|
|
32 | * This program is free software; you can redistribute it and/or modify |
|
|
33 | * it under the terms of the GNU General Public License as published by |
|
|
34 | * the Free Software Foundation; either version 2 of the License, or |
|
|
35 | * (at your option) any later version. |
|
|
36 | * |
|
|
37 | * This program is distributed in the hope that it will be useful, |
|
|
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
40 | * GNU General Public License for more details. |
|
|
41 | * |
|
|
42 | * You should have received a copy of the GNU General Public License |
|
|
43 | * along with this program; if not, write to the Free Software |
|
|
44 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
45 | * |
|
|
46 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
|
|
47 | */ |
|
|
48 | >>>>>>> 1.18 |
24 | |
49 | |
25 | /* placing treasure in maps, where appropriate. */ |
50 | /* placing treasure in maps, where appropriate. */ |
26 | |
|
|
27 | |
|
|
28 | |
51 | |
29 | #include <global.h> |
52 | #include <global.h> |
30 | #include <random_map.h> |
53 | #include <random_map.h> |
31 | #include <rproto.h> |
54 | #include <rproto.h> |
32 | |
55 | |
… | |
… | |
48 | |
71 | |
49 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
72 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
50 | * and doors but not monsters. |
73 | * and doors but not monsters. |
51 | * This function is not map tile aware. |
74 | * This function is not map tile aware. |
52 | */ |
75 | */ |
53 | |
|
|
54 | int |
76 | int |
55 | wall_blocked (maptile *m, int x, int y) |
77 | wall_blocked (maptile *m, int x, int y) |
56 | { |
78 | { |
57 | int r; |
|
|
58 | |
|
|
59 | if (OUT_OF_REAL_MAP (m, x, y)) |
79 | if (OUT_OF_REAL_MAP (m, x, y)) |
60 | return 1; |
80 | return 1; |
|
|
81 | |
61 | r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT; |
82 | int r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT; |
62 | return r; |
83 | return r; |
63 | } |
84 | } |
64 | |
85 | |
65 | /* place treasures in the map, given the |
86 | /* place treasures in the map, given the |
66 | map, (required) |
87 | map, (required) |
67 | layout, (required) |
88 | layout, (required) |
68 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
89 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
69 | treasureoptions (may be 0 for random choices or positive) |
90 | treasureoptions (may be 0 for random choices or positive) |
70 | */ |
91 | */ |
71 | |
|
|
72 | void |
92 | void |
73 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
93 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
74 | { |
94 | { |
75 | char styledirname[256]; |
95 | char styledirname[1024]; |
76 | char stylefilepath[256]; |
96 | char stylefilepath[1024]; |
77 | maptile *style_map = 0; |
97 | maptile *style_map = 0; |
78 | int num_treasures; |
98 | int num_treasures; |
79 | |
99 | |
80 | /* bail out if treasure isn't wanted. */ |
100 | /* bail out if treasure isn't wanted. */ |
81 | if (treasure_style) |
101 | if (treasure_style) |
… | |
… | |
211 | if (i == -1) |
231 | if (i == -1) |
212 | { |
232 | { |
213 | the_chest->destroy (); |
233 | the_chest->destroy (); |
214 | return NULL; |
234 | return NULL; |
215 | } |
235 | } |
|
|
236 | |
216 | xl = x + freearr_x[i]; |
237 | xl = x + freearr_x[i]; |
217 | yl = y + freearr_y[i]; |
238 | yl = y + freearr_y[i]; |
218 | |
239 | |
219 | /* if the placement is blocked, return a fail. */ |
240 | /* if the placement is blocked, return a fail. */ |
220 | if (wall_blocked (map, xl, yl)) |
241 | if (wall_blocked (map, xl, yl)) |
… | |
… | |
276 | the lockcode. It's not worth bothering to lock the chest if |
297 | the lockcode. It's not worth bothering to lock the chest if |
277 | there's only 1 treasure.... */ |
298 | there's only 1 treasure.... */ |
278 | |
299 | |
279 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
300 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
280 | { |
301 | { |
281 | char keybuf[256]; |
302 | char keybuf[1024]; |
282 | |
303 | |
283 | sprintf (keybuf, "%d", (int) RANDOM ()); |
304 | sprintf (keybuf, "%d", (int) RANDOM ()); |
284 | the_chest->slaying = keybuf; |
305 | the_chest->slaying = keybuf; |
285 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
306 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
286 | } |
307 | } |
… | |
… | |
331 | it will place 2-4 keys regardless of what nkeys is provided nkeys > 1. |
352 | it will place 2-4 keys regardless of what nkeys is provided nkeys > 1. |
332 | |
353 | |
333 | The idea is that you call keyplace on x,y where a door is, and it'll make |
354 | The idea is that you call keyplace on x,y where a door is, and it'll make |
334 | sure a key is placed on both sides of the door. |
355 | sure a key is placed on both sides of the door. |
335 | */ |
356 | */ |
336 | |
|
|
337 | int |
357 | int |
338 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP) |
358 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP) |
339 | { |
359 | { |
340 | int i, j; |
360 | int i, j; |
341 | int kx, ky; |
361 | int kx = 0, ky = 0; |
342 | object *the_keymaster; /* the monster that gets the key. */ |
362 | object *the_keymaster; /* the monster that gets the key. */ |
343 | object *the_key; |
363 | object *the_key; |
344 | |
364 | |
345 | /* get a key and set its keycode */ |
365 | /* get a key and set its keycode */ |
346 | the_key = get_archetype ("key2"); |
366 | the_key = get_archetype ("key2"); |
… | |
… | |
348 | |
368 | |
349 | if (door_flag == PASS_DOORS) |
369 | if (door_flag == PASS_DOORS) |
350 | { |
370 | { |
351 | int tries = 0; |
371 | int tries = 0; |
352 | |
372 | |
353 | the_keymaster = NULL; |
373 | the_keymaster = 0; |
354 | while (tries < 15 && the_keymaster == NULL) |
374 | while (tries < 15 && !the_keymaster) |
355 | { |
375 | { |
356 | i = (RANDOM () % (RP->Xsize - 2)) + 1; |
376 | i = (RANDOM () % (RP->Xsize - 2)) + 1; |
357 | j = (RANDOM () % (RP->Ysize - 2)) + 1; |
377 | j = (RANDOM () % (RP->Ysize - 2)) + 1; |
358 | tries++; |
378 | tries++; |
359 | the_keymaster = find_closest_monster (map, i, j, RP); |
379 | the_keymaster = find_closest_monster (map, i, j, RP); |
360 | } |
380 | } |
|
|
381 | |
361 | /* if we don't find a good keymaster, drop the key on the ground. */ |
382 | /* if we don't find a good keymaster, drop the key on the ground. */ |
362 | if (the_keymaster == NULL) |
383 | if (!the_keymaster) |
363 | { |
384 | { |
364 | int freeindex; |
385 | int freeindex; |
365 | |
386 | |
366 | freeindex = -1; |
387 | freeindex = -1; |
367 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
388 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
368 | { |
389 | { |
369 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
390 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
370 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
391 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
371 | freeindex = find_first_free_spot (the_key, map, kx, ky); |
392 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
372 | } |
393 | } |
|
|
394 | |
|
|
395 | // can freeindex ever be < 0? |
373 | if (freeindex != -1) |
396 | if (freeindex >= 0) |
374 | { |
397 | { |
375 | kx += freearr_x[freeindex]; |
398 | kx += freearr_x [freeindex]; |
376 | ky += freearr_y[freeindex]; |
399 | ky += freearr_y [freeindex]; |
377 | } |
400 | } |
378 | } |
401 | } |
379 | } |
402 | } |
380 | else |
403 | else |
381 | { /* NO_PASS_DOORS --we have to work harder. */ |
404 | { /* NO_PASS_DOORS --we have to work harder. */ |
… | |
… | |
383 | NO_PASS_DOORS is set. */ |
406 | NO_PASS_DOORS is set. */ |
384 | if (n_keys == 1) |
407 | if (n_keys == 1) |
385 | { |
408 | { |
386 | if (wall_blocked (map, x, y)) |
409 | if (wall_blocked (map, x, y)) |
387 | return 0; |
410 | return 0; |
|
|
411 | |
388 | the_keymaster = find_monster_in_room (map, x, y, RP); |
412 | the_keymaster = find_monster_in_room (map, x, y, RP); |
389 | if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ |
413 | if (!the_keymaster) /* if fail, find a spot to drop the key. */ |
390 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
414 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
391 | } |
415 | } |
392 | else |
416 | else |
393 | { |
417 | { |
394 | int sum = 0; /* count how many keys we actually place */ |
418 | int sum = 0; /* count how many keys we actually place */ |
… | |
… | |
396 | /* I'm lazy, so just try to place in all 4 directions. */ |
420 | /* I'm lazy, so just try to place in all 4 directions. */ |
397 | sum += keyplace (map, x + 1, y, keycode, NO_PASS_DOORS, 1, RP); |
421 | sum += keyplace (map, x + 1, y, keycode, NO_PASS_DOORS, 1, RP); |
398 | sum += keyplace (map, x, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
422 | sum += keyplace (map, x, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
399 | sum += keyplace (map, x - 1, y, keycode, NO_PASS_DOORS, 1, RP); |
423 | sum += keyplace (map, x - 1, y, keycode, NO_PASS_DOORS, 1, RP); |
400 | sum += keyplace (map, x, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
424 | sum += keyplace (map, x, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
|
|
425 | |
401 | if (sum < 2) /* we might have made a disconnected map-place more keys. */ |
426 | if (sum < 2) /* we might have made a disconnected map-place more keys. */ |
402 | { /* diagnoally this time. */ |
427 | { /* diagonally this time. */ |
403 | keyplace (map, x + 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
428 | keyplace (map, x + 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
404 | keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
429 | keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
405 | keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
430 | keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
406 | keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
431 | keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
407 | } |
432 | } |
|
|
433 | |
408 | return 1; |
434 | return 1; |
409 | } |
435 | } |
410 | } |
436 | } |
411 | |
437 | |
412 | if (the_keymaster == NULL) |
438 | if (!the_keymaster) |
413 | { |
439 | { |
414 | the_key->x = kx; |
440 | the_key->x = kx; |
415 | the_key->y = ky; |
441 | the_key->y = ky; |
416 | insert_ob_in_map (the_key, map, NULL, 0); |
442 | insert_ob_in_map (the_key, map, NULL, 0); |
417 | return 1; |
443 | return 1; |
… | |
… | |
505 | free (layout2); |
531 | free (layout2); |
506 | |
532 | |
507 | return theMonsterToFind; |
533 | return theMonsterToFind; |
508 | } |
534 | } |
509 | |
535 | |
510 | |
|
|
511 | |
|
|
512 | |
|
|
513 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
536 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
514 | int *room_free_spots_x; |
537 | int *room_free_spots_x; |
515 | int *room_free_spots_y; |
538 | int *room_free_spots_y; |
516 | int number_of_free_spots_in_room; |
539 | int number_of_free_spots_in_room; |
517 | |
540 | |
518 | /* the workhorse routine, which finds the free spots in a room: |
541 | /* the workhorse routine, which finds the free spots in a room: |
519 | a datastructure of free points is set up, and a position chosen from |
542 | a datastructure of free points is set up, and a position chosen from |
520 | that datastructure. */ |
543 | that datastructure. */ |
521 | |
|
|
522 | void |
544 | void |
523 | find_spot_in_room_recursive (char **layout, int x, int y, random_map_params *RP) |
545 | find_spot_in_room_recursive (char **layout, int x, int y, random_map_params *RP) |
524 | { |
546 | { |
525 | int i, j; |
547 | int i, j; |
526 | |
548 | |
… | |
… | |
537 | /* check off this point */ |
559 | /* check off this point */ |
538 | layout[x][y] = 1; |
560 | layout[x][y] = 1; |
539 | room_free_spots_x[number_of_free_spots_in_room] = x; |
561 | room_free_spots_x[number_of_free_spots_in_room] = x; |
540 | room_free_spots_y[number_of_free_spots_in_room] = y; |
562 | room_free_spots_y[number_of_free_spots_in_room] = y; |
541 | number_of_free_spots_in_room++; |
563 | number_of_free_spots_in_room++; |
|
|
564 | |
542 | /* now search all the 8 squares around recursively for free spots,in random order */ |
565 | /* now search all the 8 squares around recursively for free spots,in random order */ |
543 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
566 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
544 | { |
|
|
545 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
567 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
546 | } |
|
|
547 | |
568 | |
548 | } |
569 | } |
549 | |
570 | |
550 | /* find a random non-blocked spot in this room to drop a key. */ |
571 | /* find a random non-blocked spot in this room to drop a key. */ |
551 | void |
572 | void |
… | |
… | |
562 | /* allocate and copy the layout, converting C to 0. */ |
583 | /* allocate and copy the layout, converting C to 0. */ |
563 | for (i = 0; i < RP->Xsize; i++) |
584 | for (i = 0; i < RP->Xsize; i++) |
564 | { |
585 | { |
565 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
586 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
566 | for (j = 0; j < RP->Ysize; j++) |
587 | for (j = 0; j < RP->Ysize; j++) |
567 | { |
|
|
568 | if (wall_blocked (map, i, j)) |
588 | if (wall_blocked (map, i, j)) |
569 | layout2[i][j] = '#'; |
589 | layout2[i][j] = '#'; |
570 | } |
|
|
571 | } |
590 | } |
572 | |
591 | |
573 | /* setup num_free_spots and room_free_spots */ |
592 | /* setup num_free_spots and room_free_spots */ |
574 | find_spot_in_room_recursive (layout2, x, y, RP); |
593 | find_spot_in_room_recursive (layout2, x, y, RP); |
575 | |
594 | |
… | |
… | |
580 | *ky = room_free_spots_y[i]; |
599 | *ky = room_free_spots_y[i]; |
581 | } |
600 | } |
582 | |
601 | |
583 | /* deallocate the temp. layout */ |
602 | /* deallocate the temp. layout */ |
584 | for (i = 0; i < RP->Xsize; i++) |
603 | for (i = 0; i < RP->Xsize; i++) |
585 | { |
|
|
586 | free (layout2[i]); |
604 | free (layout2[i]); |
587 | } |
605 | |
588 | free (layout2); |
606 | free (layout2); |
589 | free (room_free_spots_x); |
607 | free (room_free_spots_x); |
590 | free (room_free_spots_y); |
608 | free (room_free_spots_y); |
591 | } |
609 | } |
592 | |
610 | |
593 | |
611 | |
594 | /* searches the map for a spot with walls around it. The more |
612 | /* searches the map for a spot with walls around it. The more |
595 | walls the better, but it'll settle for 1 wall, or even 0, but |
613 | walls the better, but it'll settle for 1 wall, or even 0, but |
596 | it'll return 0 if no FREE spots are found.*/ |
614 | it'll return 0 if no FREE spots are found.*/ |
597 | |
|
|
598 | void |
615 | void |
599 | find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params *RP) |
616 | find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params *RP) |
600 | { |
617 | { |
601 | int x, y; |
618 | int x, y; |
602 | int i; |
619 | int i; |
… | |
… | |
653 | *cy = ly; |
670 | *cy = ly; |
654 | return; |
671 | return; |
655 | } |
672 | } |
656 | } |
673 | } |
657 | /* give up and return the closest free spot. */ |
674 | /* give up and return the closest free spot. */ |
658 | i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y); |
675 | i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); |
659 | if (i != -1 && i <= SIZEOFFREE1) |
676 | |
|
|
677 | if (i != -1) |
660 | { |
678 | { |
661 | *cx = x + freearr_x[i]; |
679 | *cx = x + freearr_x[i]; |
662 | *cy = y + freearr_y[i]; |
680 | *cy = y + freearr_y[i]; |
663 | return; |
681 | } |
|
|
682 | else |
664 | } |
683 | { |
665 | /* indicate failure */ |
684 | /* indicate failure */ |
|
|
685 | *cx = -1; |
666 | *cx = *cy = -1; |
686 | *cy = -1; |
|
|
687 | } |
667 | } |
688 | } |
668 | |
689 | |
669 | |
690 | |
670 | void |
691 | void |
671 | remove_monsters (int x, int y, maptile *map) |
692 | remove_monsters (int x, int y, maptile *map) |
… | |
… | |
763 | /* check off this point */ |
784 | /* check off this point */ |
764 | if (layout[x][y] == '#') |
785 | if (layout[x][y] == '#') |
765 | { /* there could be a door here */ |
786 | { /* there could be a door here */ |
766 | layout[x][y] = 1; |
787 | layout[x][y] = 1; |
767 | door = door_in_square (map, x, y); |
788 | door = door_in_square (map, x, y); |
768 | if (door != NULL) |
789 | if (door) |
769 | { |
790 | { |
770 | doorlist[*ndoors] = door; |
791 | doorlist[*ndoors] = door; |
771 | if (*ndoors > 254) /* eek! out of memory */ |
792 | if (*ndoors > 1022) /* eek! out of memory */ |
772 | { |
793 | { |
773 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
794 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
774 | return; |
795 | return; |
775 | } |
796 | } |
|
|
797 | |
776 | *ndoors = *ndoors + 1; |
798 | *ndoors = *ndoors + 1; |
777 | } |
799 | } |
778 | } |
800 | } |
779 | else |
801 | else |
780 | { |
802 | { |
781 | layout[x][y] = 1; |
803 | layout[x][y] = 1; |
782 | /* now search all the 8 squares around recursively for free spots,in random order */ |
804 | /* now search all the 8 squares around recursively for free spots,in random order */ |
783 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
805 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
784 | { |
|
|
785 | find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); |
806 | find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); |
786 | } |
|
|
787 | } |
807 | } |
788 | } |
808 | } |
789 | |
809 | |
790 | /* find a random non-blocked spot in this room to drop a key. */ |
810 | /* find a random non-blocked spot in this room to drop a key. */ |
791 | object ** |
811 | object ** |
… | |
… | |
794 | char **layout2; |
814 | char **layout2; |
795 | object **doorlist; |
815 | object **doorlist; |
796 | int i, j; |
816 | int i, j; |
797 | int ndoors = 0; |
817 | int ndoors = 0; |
798 | |
818 | |
799 | doorlist = (object **) calloc (sizeof (int), 256); |
819 | doorlist = (object **) calloc (sizeof (int), 1024); |
800 | |
|
|
801 | |
820 | |
802 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
821 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
803 | /* allocate and copy the layout, converting C to 0. */ |
822 | /* allocate and copy the layout, converting C to 0. */ |
804 | for (i = 0; i < RP->Xsize; i++) |
823 | for (i = 0; i < RP->Xsize; i++) |
805 | { |
824 | { |
… | |
… | |
814 | /* setup num_free_spots and room_free_spots */ |
833 | /* setup num_free_spots and room_free_spots */ |
815 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
834 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
816 | |
835 | |
817 | /* deallocate the temp. layout */ |
836 | /* deallocate the temp. layout */ |
818 | for (i = 0; i < RP->Xsize; i++) |
837 | for (i = 0; i < RP->Xsize; i++) |
819 | { |
|
|
820 | free (layout2[i]); |
838 | free (layout2[i]); |
821 | } |
839 | |
822 | free (layout2); |
840 | free (layout2); |
823 | return doorlist; |
841 | return doorlist; |
824 | } |
842 | } |
825 | |
843 | |
826 | |
844 | |
… | |
… | |
839 | if (opts & DOORED) |
857 | if (opts & DOORED) |
840 | { |
858 | { |
841 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
859 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
842 | { |
860 | { |
843 | object *new_door = get_archetype ("locked_door1"); |
861 | object *new_door = get_archetype ("locked_door1"); |
844 | char keybuf[256]; |
862 | char keybuf[1024]; |
845 | |
863 | |
846 | door = doorlist[i]; |
864 | door = doorlist[i]; |
847 | new_door->face = door->face; |
865 | new_door->face = door->face; |
848 | new_door->x = door->x; |
866 | new_door->x = door->x; |
849 | new_door->y = door->y; |
867 | new_door->y = door->y; |