1 | |
1 | |
2 | /* |
2 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
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 |
… | |
… | |
70 | */ |
71 | */ |
71 | |
72 | |
72 | void |
73 | void |
73 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
74 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
74 | { |
75 | { |
75 | char styledirname[256]; |
76 | char styledirname[1024]; |
76 | char stylefilepath[256]; |
77 | char stylefilepath[1024]; |
77 | maptile *style_map = 0; |
78 | maptile *style_map = 0; |
78 | int num_treasures; |
79 | int num_treasures; |
79 | |
80 | |
80 | /* bail out if treasure isn't wanted. */ |
81 | /* bail out if treasure isn't wanted. */ |
81 | if (treasure_style) |
82 | if (treasure_style) |
… | |
… | |
276 | the lockcode. It's not worth bothering to lock the chest if |
277 | the lockcode. It's not worth bothering to lock the chest if |
277 | there's only 1 treasure.... */ |
278 | there's only 1 treasure.... */ |
278 | |
279 | |
279 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
280 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
280 | { |
281 | { |
281 | char keybuf[256]; |
282 | char keybuf[1024]; |
282 | |
283 | |
283 | sprintf (keybuf, "%d", (int) RANDOM ()); |
284 | sprintf (keybuf, "%d", (int) RANDOM ()); |
284 | the_chest->slaying = keybuf; |
285 | the_chest->slaying = keybuf; |
285 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
286 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
286 | } |
287 | } |
… | |
… | |
763 | /* check off this point */ |
764 | /* check off this point */ |
764 | if (layout[x][y] == '#') |
765 | if (layout[x][y] == '#') |
765 | { /* there could be a door here */ |
766 | { /* there could be a door here */ |
766 | layout[x][y] = 1; |
767 | layout[x][y] = 1; |
767 | door = door_in_square (map, x, y); |
768 | door = door_in_square (map, x, y); |
768 | if (door != NULL) |
769 | if (door) |
769 | { |
770 | { |
770 | doorlist[*ndoors] = door; |
771 | doorlist[*ndoors] = door; |
771 | if (*ndoors > 254) /* eek! out of memory */ |
772 | if (*ndoors > 1022) /* eek! out of memory */ |
772 | { |
773 | { |
773 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
774 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
774 | return; |
775 | return; |
775 | } |
776 | } |
|
|
777 | |
776 | *ndoors = *ndoors + 1; |
778 | *ndoors = *ndoors + 1; |
777 | } |
779 | } |
778 | } |
780 | } |
779 | else |
781 | else |
780 | { |
782 | { |
781 | layout[x][y] = 1; |
783 | layout[x][y] = 1; |
782 | /* now search all the 8 squares around recursively for free spots,in random order */ |
784 | /* 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++) |
785 | 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); |
786 | find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); |
786 | } |
|
|
787 | } |
787 | } |
788 | } |
788 | } |
789 | |
789 | |
790 | /* find a random non-blocked spot in this room to drop a key. */ |
790 | /* find a random non-blocked spot in this room to drop a key. */ |
791 | object ** |
791 | object ** |
… | |
… | |
794 | char **layout2; |
794 | char **layout2; |
795 | object **doorlist; |
795 | object **doorlist; |
796 | int i, j; |
796 | int i, j; |
797 | int ndoors = 0; |
797 | int ndoors = 0; |
798 | |
798 | |
799 | doorlist = (object **) calloc (sizeof (int), 256); |
799 | doorlist = (object **) calloc (sizeof (int), 1024); |
800 | |
|
|
801 | |
800 | |
802 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
801 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
803 | /* allocate and copy the layout, converting C to 0. */ |
802 | /* allocate and copy the layout, converting C to 0. */ |
804 | for (i = 0; i < RP->Xsize; i++) |
803 | for (i = 0; i < RP->Xsize; i++) |
805 | { |
804 | { |
… | |
… | |
814 | /* setup num_free_spots and room_free_spots */ |
813 | /* setup num_free_spots and room_free_spots */ |
815 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
814 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
816 | |
815 | |
817 | /* deallocate the temp. layout */ |
816 | /* deallocate the temp. layout */ |
818 | for (i = 0; i < RP->Xsize; i++) |
817 | for (i = 0; i < RP->Xsize; i++) |
819 | { |
|
|
820 | free (layout2[i]); |
818 | free (layout2[i]); |
821 | } |
819 | |
822 | free (layout2); |
820 | free (layout2); |
823 | return doorlist; |
821 | return doorlist; |
824 | } |
822 | } |
825 | |
823 | |
826 | |
824 | |
… | |
… | |
839 | if (opts & DOORED) |
837 | if (opts & DOORED) |
840 | { |
838 | { |
841 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
839 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
842 | { |
840 | { |
843 | object *new_door = get_archetype ("locked_door1"); |
841 | object *new_door = get_archetype ("locked_door1"); |
844 | char keybuf[256]; |
842 | char keybuf[1024]; |
845 | |
843 | |
846 | door = doorlist[i]; |
844 | door = doorlist[i]; |
847 | new_door->face = door->face; |
845 | new_door->face = door->face; |
848 | new_door->x = door->x; |
846 | new_door->x = door->x; |
849 | new_door->y = door->y; |
847 | new_door->y = door->y; |