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