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.4 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.7 by root, Sat Sep 16 22:24:13 2006 UTC

1
2/*
3 * static char *rcsid_treasure_c =
4 * "$Id: treasure.C,v 1.4 2006/09/10 16:06:37 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30/* placing treasure in maps, where appropriate. */ 24/* placing treasure in maps, where appropriate. */
31 25
32 26
55 * and doors but not monsters. 49 * and doors but not monsters.
56 * This function is not map tile aware. 50 * This function is not map tile aware.
57 */ 51 */
58 52
59int 53int
60wall_blocked (mapstruct *m, int x, int y) 54wall_blocked (maptile *m, int x, int y)
61{ 55{
62 int r; 56 int r;
63 57
64 if (OUT_OF_REAL_MAP (m, x, y)) 58 if (OUT_OF_REAL_MAP (m, x, y))
65 return 1; 59 return 1;
73treasure style (may be empty or NULL, or "none" to cause no treasure.) 67treasure style (may be empty or NULL, or "none" to cause no treasure.)
74treasureoptions (may be 0 for random choices or positive) 68treasureoptions (may be 0 for random choices or positive)
75*/ 69*/
76 70
77void 71void
78place_treasure (mapstruct *map, char **layout, char *treasure_style, int treasureoptions, RMParms * RP) 72place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, RMParms * RP)
79{ 73{
80 char styledirname[256]; 74 char styledirname[256];
81 char stylefilepath[256]; 75 char stylefilepath[256];
82 mapstruct *style_map = 0; 76 maptile *style_map = 0;
83 int num_treasures; 77 int num_treasures;
84 78
85 /* bail out if treasure isn't wanted. */ 79 /* bail out if treasure isn't wanted. */
86 if (treasure_style) 80 if (treasure_style)
87 if (!strcmp (treasure_style, "none")) 81 if (!strcmp (treasure_style, "none"))
204/* put a chest into the map, near x and y, with the treasure style 198/* put a chest into the map, near x and y, with the treasure style
205 determined (may be null, or may be a treasure list from lib/treasures, 199 determined (may be null, or may be a treasure list from lib/treasures,
206 if the global variable "treasurestyle" is set to that treasure list's name */ 200 if the global variable "treasurestyle" is set to that treasure list's name */
207 201
208object * 202object *
209place_chest (int treasureoptions, int x, int y, mapstruct *map, mapstruct *style_map, int n_treasures, RMParms * RP) 203place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, RMParms * RP)
210{ 204{
211 object *the_chest; 205 object *the_chest;
212 int i, xl, yl; 206 int i, xl, yl;
213 207
214 the_chest = get_archetype ("chest"); /* was "chest_2" */ 208 the_chest = get_archetype ("chest"); /* was "chest_2" */
258 } 252 }
259 253
260 /* stick a trap in the chest if required */ 254 /* stick a trap in the chest if required */
261 if (treasureoptions & TRAPPED) 255 if (treasureoptions & TRAPPED)
262 { 256 {
263 mapstruct *trap_map = find_style ("/styles/trapstyles", "traps", -1); 257 maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1);
264 object *the_trap; 258 object *the_trap;
265 259
266 if (trap_map) 260 if (trap_map)
267 { 261 {
268 the_trap = pick_random_object (trap_map); 262 the_trap = pick_random_object (trap_map);
303 297
304 298
305/* finds the closest monster and returns him, regardless of doors 299/* finds the closest monster and returns him, regardless of doors
306 or walls */ 300 or walls */
307object * 301object *
308find_closest_monster (mapstruct *map, int x, int y, RMParms * RP) 302find_closest_monster (maptile *map, int x, int y, RMParms * RP)
309{ 303{
310 int i; 304 int i;
311 305
312 for (i = 0; i < SIZEOFFREE; i++) 306 for (i = 0; i < SIZEOFFREE; i++)
313 { 307 {
342 The idea is that you call keyplace on x,y where a door is, and it'll make 336 The idea is that you call keyplace on x,y where a door is, and it'll make
343 sure a key is placed on both sides of the door. 337 sure a key is placed on both sides of the door.
344*/ 338*/
345 339
346int 340int
347keyplace (mapstruct *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms * RP) 341keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms * RP)
348{ 342{
349 int i, j; 343 int i, j;
350 int kx, ky; 344 int kx, ky;
351 object *the_keymaster; /* the monster that gets the key. */ 345 object *the_keymaster; /* the monster that gets the key. */
352 object *the_key; 346 object *the_key;
438 432
439/* a recursive routine which will return a monster, eventually,if there is one. 433/* a recursive routine which will return a monster, eventually,if there is one.
440 it does a check-off on the layout, converting 0's to 1's */ 434 it does a check-off on the layout, converting 0's to 1's */
441 435
442object * 436object *
443find_monster_in_room_recursive (char **layout, mapstruct *map, int x, int y, RMParms * RP) 437find_monster_in_room_recursive (char **layout, maptile *map, int x, int y, RMParms * RP)
444{ 438{
445 int i, j; 439 int i, j;
446 440
447 /* if we've found a monster already, leave */ 441 /* if we've found a monster already, leave */
448 if (theMonsterToFind != NULL) 442 if (theMonsterToFind != NULL)
485 479
486/* sets up some data structures: the _recursive form does the 480/* sets up some data structures: the _recursive form does the
487 real work. */ 481 real work. */
488 482
489object * 483object *
490find_monster_in_room (mapstruct *map, int x, int y, RMParms * RP) 484find_monster_in_room (maptile *map, int x, int y, RMParms * RP)
491{ 485{
492 char **layout2; 486 char **layout2;
493 int i, j; 487 int i, j;
494 488
495 theMonsterToFind = 0; 489 theMonsterToFind = 0;
556 550
557} 551}
558 552
559/* find a random non-blocked spot in this room to drop a key. */ 553/* find a random non-blocked spot in this room to drop a key. */
560void 554void
561find_spot_in_room (mapstruct *map, int x, int y, int *kx, int *ky, RMParms * RP) 555find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, RMParms * RP)
562{ 556{
563 char **layout2; 557 char **layout2;
564 int i, j; 558 int i, j;
565 559
566 number_of_free_spots_in_room = 0; 560 number_of_free_spots_in_room = 0;
603/* searches the map for a spot with walls around it. The more 597/* searches the map for a spot with walls around it. The more
604 walls the better, but it'll settle for 1 wall, or even 0, but 598 walls the better, but it'll settle for 1 wall, or even 0, but
605 it'll return 0 if no FREE spots are found.*/ 599 it'll return 0 if no FREE spots are found.*/
606 600
607void 601void
608find_enclosed_spot (mapstruct *map, int *cx, int *cy, RMParms * RP) 602find_enclosed_spot (maptile *map, int *cx, int *cy, RMParms * RP)
609{ 603{
610 int x, y; 604 int x, y;
611 int i; 605 int i;
612 606
613 x = *cx; 607 x = *cx;
662 *cy = ly; 656 *cy = ly;
663 return; 657 return;
664 } 658 }
665 } 659 }
666 /* give up and return the closest free spot. */ 660 /* give up and return the closest free spot. */
667 i = find_first_free_spot (&find_archetype ("chest")->clone, map, x, y); 661 i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y);
668 if (i != -1 && i <= SIZEOFFREE1) 662 if (i != -1 && i <= SIZEOFFREE1)
669 { 663 {
670 *cx = x + freearr_x[i]; 664 *cx = x + freearr_x[i];
671 *cy = y + freearr_y[i]; 665 *cy = y + freearr_y[i];
672 return; 666 return;
675 *cx = *cy = -1; 669 *cx = *cy = -1;
676} 670}
677 671
678 672
679void 673void
680remove_monsters (int x, int y, mapstruct *map) 674remove_monsters (int x, int y, maptile *map)
681{ 675{
682 object *tmp; 676 object *tmp;
683 677
684 for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) 678 for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above)
685 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 679 if (QUERY_FLAG (tmp, FLAG_ALIVE))
698/* surrounds the point x,y by doors, so as to enclose something, like 692/* surrounds the point x,y by doors, so as to enclose something, like
699 a chest. It only goes as far as the 8 squares surrounding, and 693 a chest. It only goes as far as the 8 squares surrounding, and
700 it'll remove any monsters it finds.*/ 694 it'll remove any monsters it finds.*/
701 695
702object ** 696object **
703surround_by_doors (mapstruct *map, char **layout, int x, int y, int opts) 697surround_by_doors (maptile *map, char **layout, int x, int y, int opts)
704{ 698{
705 int i; 699 int i;
706 char *doors[2]; 700 char *doors[2];
707 object **doorlist; 701 object **doorlist;
708 int ndoors_made = 0; 702 int ndoors_made = 0;
741} 735}
742 736
743 737
744/* returns the first door in this square, or NULL if there isn't a door. */ 738/* returns the first door in this square, or NULL if there isn't a door. */
745object * 739object *
746door_in_square (mapstruct *map, int x, int y) 740door_in_square (maptile *map, int x, int y)
747{ 741{
748 object *tmp; 742 object *tmp;
749 743
750 for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) 744 for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above)
751 if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) 745 if (tmp->type == DOOR || tmp->type == LOCKED_DOOR)
754} 748}
755 749
756 750
757/* the workhorse routine, which finds the doors in a room */ 751/* the workhorse routine, which finds the doors in a room */
758void 752void
759find_doors_in_room_recursive (char **layout, mapstruct *map, int x, int y, object **doorlist, int *ndoors, RMParms * RP) 753find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, RMParms * RP)
760{ 754{
761 int i, j; 755 int i, j;
762 object *door; 756 object *door;
763 757
764 /* bounds check x and y */ 758 /* bounds check x and y */
796 } 790 }
797} 791}
798 792
799/* find a random non-blocked spot in this room to drop a key. */ 793/* find a random non-blocked spot in this room to drop a key. */
800object ** 794object **
801find_doors_in_room (mapstruct *map, int x, int y, RMParms * RP) 795find_doors_in_room (maptile *map, int x, int y, RMParms * RP)
802{ 796{
803 char **layout2; 797 char **layout2;
804 object **doorlist; 798 object **doorlist;
805 int i, j; 799 int i, j;
806 int ndoors = 0; 800 int ndoors = 0;
836 830
837/* locks and/or hides all the doors in doorlist, or does nothing if 831/* locks and/or hides all the doors in doorlist, or does nothing if
838 opts doesn't say to lock/hide doors. */ 832 opts doesn't say to lock/hide doors. */
839 833
840void 834void
841lock_and_hide_doors (object **doorlist, mapstruct *map, int opts, RMParms * RP) 835lock_and_hide_doors (object **doorlist, maptile *map, int opts, RMParms * RP)
842{ 836{
843 object *door; 837 object *door;
844 int i; 838 int i;
845 839
846 /* lock the doors and hide the keys. */ 840 /* lock the doors and hide the keys. */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines