ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/treasure.C
(Generate patch)

Comparing deliantra/server/random_maps/treasure.C (file contents):
Revision 1.12 by root, Sun Dec 31 19:02:24 2006 UTC vs.
Revision 1.18 by pippijn, Mon Jan 15 21:06:19 2007 UTC

1
2/* 1/*
3 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
4 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * 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 9 * 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 10 * the Free Software Foundation; either version 2 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,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
23*/ 23 */
24 24
25/* placing treasure in maps, where appropriate. */ 25/* placing treasure in maps, where appropriate. */
26 26
27 27
28 28
70*/ 70*/
71 71
72void 72void
73place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) 73place_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)
211 if (i == -1) 211 if (i == -1)
212 { 212 {
213 the_chest->destroy (); 213 the_chest->destroy ();
214 return NULL; 214 return NULL;
215 } 215 }
216
216 xl = x + freearr_x[i]; 217 xl = x + freearr_x[i];
217 yl = y + freearr_y[i]; 218 yl = y + freearr_y[i];
218 219
219 /* if the placement is blocked, return a fail. */ 220 /* if the placement is blocked, return a fail. */
220 if (wall_blocked (map, xl, yl)) 221 if (wall_blocked (map, xl, yl))
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
653 *cy = ly; 656 *cy = ly;
654 return; 657 return;
655 } 658 }
656 } 659 }
657 /* give up and return the closest free spot. */ 660 /* give up and return the closest free spot. */
658 i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y); 661 i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1);
659 if (i != -1 && i <= SIZEOFFREE1) 662
663 if (i != -1)
660 { 664 {
661 *cx = x + freearr_x[i]; 665 *cx = x + freearr_x[i];
662 *cy = y + freearr_y[i]; 666 *cy = y + freearr_y[i];
663 return; 667 }
668 else
664 } 669 {
665 /* indicate failure */ 670 /* indicate failure */
671 *cx = -1;
666 *cx = *cy = -1; 672 *cy = -1;
673 }
667} 674}
668 675
669 676
670void 677void
671remove_monsters (int x, int y, maptile *map) 678remove_monsters (int x, int y, maptile *map)
763 /* check off this point */ 770 /* check off this point */
764 if (layout[x][y] == '#') 771 if (layout[x][y] == '#')
765 { /* there could be a door here */ 772 { /* there could be a door here */
766 layout[x][y] = 1; 773 layout[x][y] = 1;
767 door = door_in_square (map, x, y); 774 door = door_in_square (map, x, y);
768 if (door != NULL) 775 if (door)
769 { 776 {
770 doorlist[*ndoors] = door; 777 doorlist[*ndoors] = door;
771 if (*ndoors > 254) /* eek! out of memory */ 778 if (*ndoors > 1022) /* eek! out of memory */
772 { 779 {
773 LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); 780 LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n");
774 return; 781 return;
775 } 782 }
783
776 *ndoors = *ndoors + 1; 784 *ndoors = *ndoors + 1;
777 } 785 }
778 } 786 }
779 else 787 else
780 { 788 {
781 layout[x][y] = 1; 789 layout[x][y] = 1;
782 /* now search all the 8 squares around recursively for free spots,in random order */ 790 /* 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++) 791 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); 792 find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP);
786 }
787 } 793 }
788} 794}
789 795
790/* find a random non-blocked spot in this room to drop a key. */ 796/* find a random non-blocked spot in this room to drop a key. */
791object ** 797object **
794 char **layout2; 800 char **layout2;
795 object **doorlist; 801 object **doorlist;
796 int i, j; 802 int i, j;
797 int ndoors = 0; 803 int ndoors = 0;
798 804
799 doorlist = (object **) calloc (sizeof (int), 256); 805 doorlist = (object **) calloc (sizeof (int), 1024);
800
801 806
802 layout2 = (char **) calloc (sizeof (char *), RP->Xsize); 807 layout2 = (char **) calloc (sizeof (char *), RP->Xsize);
803 /* allocate and copy the layout, converting C to 0. */ 808 /* allocate and copy the layout, converting C to 0. */
804 for (i = 0; i < RP->Xsize; i++) 809 for (i = 0; i < RP->Xsize; i++)
805 { 810 {
814 /* setup num_free_spots and room_free_spots */ 819 /* setup num_free_spots and room_free_spots */
815 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); 820 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP);
816 821
817 /* deallocate the temp. layout */ 822 /* deallocate the temp. layout */
818 for (i = 0; i < RP->Xsize; i++) 823 for (i = 0; i < RP->Xsize; i++)
819 {
820 free (layout2[i]); 824 free (layout2[i]);
821 } 825
822 free (layout2); 826 free (layout2);
823 return doorlist; 827 return doorlist;
824} 828}
825 829
826 830
839 if (opts & DOORED) 843 if (opts & DOORED)
840 { 844 {
841 for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) 845 for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++)
842 { 846 {
843 object *new_door = get_archetype ("locked_door1"); 847 object *new_door = get_archetype ("locked_door1");
844 char keybuf[256]; 848 char keybuf[1024];
845 849
846 door = doorlist[i]; 850 door = doorlist[i];
847 new_door->face = door->face; 851 new_door->face = door->face;
848 new_door->x = door->x; 852 new_door->x = door->x;
849 new_door->y = door->y; 853 new_door->y = door->y;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines