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 | } |
… | |
… | |
366 | freeindex = -1; |
367 | freeindex = -1; |
367 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
368 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
368 | { |
369 | { |
369 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
370 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
370 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
371 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
371 | freeindex = find_first_free_spot (the_key, map, kx, ky); |
372 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
372 | } |
373 | } |
|
|
374 | |
373 | if (freeindex != -1) |
375 | if (freeindex != -1) |
374 | { |
376 | { |
375 | kx += freearr_x[freeindex]; |
377 | kx += freearr_x[freeindex]; |
376 | ky += freearr_y[freeindex]; |
378 | ky += freearr_y[freeindex]; |
377 | } |
379 | } |
… | |
… | |
383 | NO_PASS_DOORS is set. */ |
385 | NO_PASS_DOORS is set. */ |
384 | if (n_keys == 1) |
386 | if (n_keys == 1) |
385 | { |
387 | { |
386 | if (wall_blocked (map, x, y)) |
388 | if (wall_blocked (map, x, y)) |
387 | return 0; |
389 | return 0; |
|
|
390 | |
388 | the_keymaster = find_monster_in_room (map, x, y, RP); |
391 | the_keymaster = find_monster_in_room (map, x, y, RP); |
389 | if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ |
392 | if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ |
390 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
393 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
391 | } |
394 | } |
392 | else |
395 | else |
… | |
… | |
763 | /* check off this point */ |
766 | /* check off this point */ |
764 | if (layout[x][y] == '#') |
767 | if (layout[x][y] == '#') |
765 | { /* there could be a door here */ |
768 | { /* there could be a door here */ |
766 | layout[x][y] = 1; |
769 | layout[x][y] = 1; |
767 | door = door_in_square (map, x, y); |
770 | door = door_in_square (map, x, y); |
768 | if (door != NULL) |
771 | if (door) |
769 | { |
772 | { |
770 | doorlist[*ndoors] = door; |
773 | doorlist[*ndoors] = door; |
771 | if (*ndoors > 254) /* eek! out of memory */ |
774 | if (*ndoors > 1022) /* eek! out of memory */ |
772 | { |
775 | { |
773 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
776 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
774 | return; |
777 | return; |
775 | } |
778 | } |
|
|
779 | |
776 | *ndoors = *ndoors + 1; |
780 | *ndoors = *ndoors + 1; |
777 | } |
781 | } |
778 | } |
782 | } |
779 | else |
783 | else |
780 | { |
784 | { |
781 | layout[x][y] = 1; |
785 | layout[x][y] = 1; |
782 | /* now search all the 8 squares around recursively for free spots,in random order */ |
786 | /* 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++) |
787 | 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); |
788 | find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); |
786 | } |
|
|
787 | } |
789 | } |
788 | } |
790 | } |
789 | |
791 | |
790 | /* find a random non-blocked spot in this room to drop a key. */ |
792 | /* find a random non-blocked spot in this room to drop a key. */ |
791 | object ** |
793 | object ** |
… | |
… | |
794 | char **layout2; |
796 | char **layout2; |
795 | object **doorlist; |
797 | object **doorlist; |
796 | int i, j; |
798 | int i, j; |
797 | int ndoors = 0; |
799 | int ndoors = 0; |
798 | |
800 | |
799 | doorlist = (object **) calloc (sizeof (int), 256); |
801 | doorlist = (object **) calloc (sizeof (int), 1024); |
800 | |
|
|
801 | |
802 | |
802 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
803 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
803 | /* allocate and copy the layout, converting C to 0. */ |
804 | /* allocate and copy the layout, converting C to 0. */ |
804 | for (i = 0; i < RP->Xsize; i++) |
805 | for (i = 0; i < RP->Xsize; i++) |
805 | { |
806 | { |
… | |
… | |
814 | /* setup num_free_spots and room_free_spots */ |
815 | /* setup num_free_spots and room_free_spots */ |
815 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
816 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
816 | |
817 | |
817 | /* deallocate the temp. layout */ |
818 | /* deallocate the temp. layout */ |
818 | for (i = 0; i < RP->Xsize; i++) |
819 | for (i = 0; i < RP->Xsize; i++) |
819 | { |
|
|
820 | free (layout2[i]); |
820 | free (layout2[i]); |
821 | } |
821 | |
822 | free (layout2); |
822 | free (layout2); |
823 | return doorlist; |
823 | return doorlist; |
824 | } |
824 | } |
825 | |
825 | |
826 | |
826 | |
… | |
… | |
839 | if (opts & DOORED) |
839 | if (opts & DOORED) |
840 | { |
840 | { |
841 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
841 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
842 | { |
842 | { |
843 | object *new_door = get_archetype ("locked_door1"); |
843 | object *new_door = get_archetype ("locked_door1"); |
844 | char keybuf[256]; |
844 | char keybuf[1024]; |
845 | |
845 | |
846 | door = doorlist[i]; |
846 | door = doorlist[i]; |
847 | new_door->face = door->face; |
847 | new_door->face = door->face; |
848 | new_door->x = door->x; |
848 | new_door->x = door->x; |
849 | new_door->y = door->y; |
849 | new_door->y = door->y; |