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.17 by root, Mon Jan 15 15:54:19 2007 UTC

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
72void 73void
73place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) 74place_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)
211 if (i == -1) 212 if (i == -1)
212 { 213 {
213 the_chest->destroy (); 214 the_chest->destroy ();
214 return NULL; 215 return NULL;
215 } 216 }
217
216 xl = x + freearr_x[i]; 218 xl = x + freearr_x[i];
217 yl = y + freearr_y[i]; 219 yl = y + freearr_y[i];
218 220
219 /* if the placement is blocked, return a fail. */ 221 /* if the placement is blocked, return a fail. */
220 if (wall_blocked (map, xl, yl)) 222 if (wall_blocked (map, xl, yl))
276 the lockcode. It's not worth bothering to lock the chest if 278 the lockcode. It's not worth bothering to lock the chest if
277 there's only 1 treasure.... */ 279 there's only 1 treasure.... */
278 280
279 if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) 281 if ((treasureoptions & KEYREQUIRED) && n_treasures > 1)
280 { 282 {
281 char keybuf[256]; 283 char keybuf[1024];
282 284
283 sprintf (keybuf, "%d", (int) RANDOM ()); 285 sprintf (keybuf, "%d", (int) RANDOM ());
284 the_chest->slaying = keybuf; 286 the_chest->slaying = keybuf;
285 keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); 287 keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP);
286 } 288 }
366 freeindex = -1; 368 freeindex = -1;
367 for (tries = 0; tries < 15 && freeindex == -1; tries++) 369 for (tries = 0; tries < 15 && freeindex == -1; tries++)
368 { 370 {
369 kx = (RANDOM () % (RP->Xsize - 2)) + 1; 371 kx = (RANDOM () % (RP->Xsize - 2)) + 1;
370 ky = (RANDOM () % (RP->Ysize - 2)) + 1; 372 ky = (RANDOM () % (RP->Ysize - 2)) + 1;
371 freeindex = find_first_free_spot (the_key, map, kx, ky); 373 freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1);
372 } 374 }
375
373 if (freeindex != -1) 376 if (freeindex != -1)
374 { 377 {
375 kx += freearr_x[freeindex]; 378 kx += freearr_x[freeindex];
376 ky += freearr_y[freeindex]; 379 ky += freearr_y[freeindex];
377 } 380 }
383 NO_PASS_DOORS is set. */ 386 NO_PASS_DOORS is set. */
384 if (n_keys == 1) 387 if (n_keys == 1)
385 { 388 {
386 if (wall_blocked (map, x, y)) 389 if (wall_blocked (map, x, y))
387 return 0; 390 return 0;
391
388 the_keymaster = find_monster_in_room (map, x, y, RP); 392 the_keymaster = find_monster_in_room (map, x, y, RP);
389 if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ 393 if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */
390 find_spot_in_room (map, x, y, &kx, &ky, RP); 394 find_spot_in_room (map, x, y, &kx, &ky, RP);
391 } 395 }
392 else 396 else
653 *cy = ly; 657 *cy = ly;
654 return; 658 return;
655 } 659 }
656 } 660 }
657 /* give up and return the closest free spot. */ 661 /* give up and return the closest free spot. */
658 i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y); 662 i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1);
659 if (i != -1 && i <= SIZEOFFREE1) 663
664 if (i != -1)
660 { 665 {
661 *cx = x + freearr_x[i]; 666 *cx = x + freearr_x[i];
662 *cy = y + freearr_y[i]; 667 *cy = y + freearr_y[i];
663 return; 668 }
669 else
664 } 670 {
665 /* indicate failure */ 671 /* indicate failure */
672 *cx = -1;
666 *cx = *cy = -1; 673 *cy = -1;
674 }
667} 675}
668 676
669 677
670void 678void
671remove_monsters (int x, int y, maptile *map) 679remove_monsters (int x, int y, maptile *map)
763 /* check off this point */ 771 /* check off this point */
764 if (layout[x][y] == '#') 772 if (layout[x][y] == '#')
765 { /* there could be a door here */ 773 { /* there could be a door here */
766 layout[x][y] = 1; 774 layout[x][y] = 1;
767 door = door_in_square (map, x, y); 775 door = door_in_square (map, x, y);
768 if (door != NULL) 776 if (door)
769 { 777 {
770 doorlist[*ndoors] = door; 778 doorlist[*ndoors] = door;
771 if (*ndoors > 254) /* eek! out of memory */ 779 if (*ndoors > 1022) /* eek! out of memory */
772 { 780 {
773 LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); 781 LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n");
774 return; 782 return;
775 } 783 }
784
776 *ndoors = *ndoors + 1; 785 *ndoors = *ndoors + 1;
777 } 786 }
778 } 787 }
779 else 788 else
780 { 789 {
781 layout[x][y] = 1; 790 layout[x][y] = 1;
782 /* now search all the 8 squares around recursively for free spots,in random order */ 791 /* 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++) 792 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); 793 find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP);
786 }
787 } 794 }
788} 795}
789 796
790/* find a random non-blocked spot in this room to drop a key. */ 797/* find a random non-blocked spot in this room to drop a key. */
791object ** 798object **
794 char **layout2; 801 char **layout2;
795 object **doorlist; 802 object **doorlist;
796 int i, j; 803 int i, j;
797 int ndoors = 0; 804 int ndoors = 0;
798 805
799 doorlist = (object **) calloc (sizeof (int), 256); 806 doorlist = (object **) calloc (sizeof (int), 1024);
800
801 807
802 layout2 = (char **) calloc (sizeof (char *), RP->Xsize); 808 layout2 = (char **) calloc (sizeof (char *), RP->Xsize);
803 /* allocate and copy the layout, converting C to 0. */ 809 /* allocate and copy the layout, converting C to 0. */
804 for (i = 0; i < RP->Xsize; i++) 810 for (i = 0; i < RP->Xsize; i++)
805 { 811 {
814 /* setup num_free_spots and room_free_spots */ 820 /* setup num_free_spots and room_free_spots */
815 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); 821 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP);
816 822
817 /* deallocate the temp. layout */ 823 /* deallocate the temp. layout */
818 for (i = 0; i < RP->Xsize; i++) 824 for (i = 0; i < RP->Xsize; i++)
819 {
820 free (layout2[i]); 825 free (layout2[i]);
821 } 826
822 free (layout2); 827 free (layout2);
823 return doorlist; 828 return doorlist;
824} 829}
825 830
826 831
839 if (opts & DOORED) 844 if (opts & DOORED)
840 { 845 {
841 for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) 846 for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++)
842 { 847 {
843 object *new_door = get_archetype ("locked_door1"); 848 object *new_door = get_archetype ("locked_door1");
844 char keybuf[256]; 849 char keybuf[1024];
845 850
846 door = doorlist[i]; 851 door = doorlist[i];
847 new_door->face = door->face; 852 new_door->face = door->face;
848 new_door->x = door->x; 853 new_door->x = door->x;
849 new_door->y = door->y; 854 new_door->y = door->y;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines