1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_treasure_c = |
|
|
4 | * "$Id: treasure.C,v 1.5 2006/09/14 21:16:12 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 | |
59 | int |
53 | int |
60 | wall_blocked (mapstruct *m, int x, int y) |
54 | wall_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; |
… | |
… | |
73 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
67 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
74 | treasureoptions (may be 0 for random choices or positive) |
68 | treasureoptions (may be 0 for random choices or positive) |
75 | */ |
69 | */ |
76 | |
70 | |
77 | void |
71 | void |
78 | place_treasure (mapstruct *map, char **layout, char *treasure_style, int treasureoptions, RMParms * RP) |
72 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params * 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")) |
… | |
… | |
119 | { |
113 | { |
120 | |
114 | |
121 | /* map_layout_style global, and is previously set */ |
115 | /* map_layout_style global, and is previously set */ |
122 | switch (RP->map_layout_style) |
116 | switch (RP->map_layout_style) |
123 | { |
117 | { |
124 | case ONION_LAYOUT: |
118 | case LAYOUT_ONION: |
125 | case SPIRAL_LAYOUT: |
119 | case LAYOUT_SPIRAL: |
126 | case SQUARE_SPIRAL_LAYOUT: |
120 | case LAYOUT_SQUARE_SPIRAL: |
127 | { |
121 | { |
128 | int i, j; |
122 | int i, j; |
129 | |
123 | |
130 | /* search the onion for C's or '>', and put treasure there. */ |
124 | /* search the onion for C's or '>', and put treasure there. */ |
131 | for (i = 0; i < RP->Xsize; i++) |
125 | for (i = 0; i < RP->Xsize; i++) |
… | |
… | |
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 | |
208 | object * |
202 | object * |
209 | place_chest (int treasureoptions, int x, int y, mapstruct *map, mapstruct *style_map, int n_treasures, RMParms * RP) |
203 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params * 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" */ |
215 | |
209 | |
216 | /* first, find a place to put the chest. */ |
210 | /* first, find a place to put the chest. */ |
217 | i = find_first_free_spot (the_chest, map, x, y); |
211 | i = find_first_free_spot (the_chest, map, x, y); |
218 | if (i == -1) |
212 | if (i == -1) |
219 | { |
213 | { |
220 | free_object (the_chest); |
214 | the_chest->destroy (); |
221 | return NULL; |
215 | return NULL; |
222 | } |
216 | } |
223 | xl = x + freearr_x[i]; |
217 | xl = x + freearr_x[i]; |
224 | yl = y + freearr_y[i]; |
218 | yl = y + freearr_y[i]; |
225 | |
219 | |
… | |
… | |
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); |
… | |
… | |
271 | if (the_trap) |
265 | if (the_trap) |
272 | { |
266 | { |
273 | object *new_trap; |
267 | object *new_trap; |
274 | |
268 | |
275 | new_trap = arch_to_object (the_trap->arch); |
269 | new_trap = arch_to_object (the_trap->arch); |
276 | copy_object (new_trap, the_trap); |
270 | new_trap->copy_to (the_trap); |
277 | new_trap->x = x; |
271 | new_trap->x = x; |
278 | new_trap->y = y; |
272 | new_trap->y = y; |
279 | insert_ob_in_ob (new_trap, the_chest); |
273 | insert_ob_in_ob (new_trap, the_chest); |
280 | } |
274 | } |
281 | } |
275 | } |
… | |
… | |
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 */ |
307 | object * |
301 | object * |
308 | find_closest_monster (mapstruct *map, int x, int y, RMParms * RP) |
302 | find_closest_monster (maptile *map, int x, int y, random_map_params * 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 | { |
… | |
… | |
318 | /* boundscheck */ |
312 | /* boundscheck */ |
319 | if (lx >= 0 && ly >= 0 && lx < RP->Xsize && ly < RP->Ysize) |
313 | if (lx >= 0 && ly >= 0 && lx < RP->Xsize && ly < RP->Ysize) |
320 | /* don't bother searching this square unless the map says life exists. */ |
314 | /* don't bother searching this square unless the map says life exists. */ |
321 | if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) |
315 | if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) |
322 | { |
316 | { |
323 | object *the_monster = get_map_ob (map, lx, ly); |
317 | object *the_monster = GET_MAP_OB (map, lx, ly); |
324 | |
318 | |
325 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_MONSTER)); the_monster = the_monster->above); |
319 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_MONSTER)); the_monster = the_monster->above); |
326 | if (the_monster && QUERY_FLAG (the_monster, FLAG_MONSTER)) |
320 | if (the_monster && QUERY_FLAG (the_monster, FLAG_MONSTER)) |
327 | return the_monster; |
321 | return the_monster; |
328 | } |
322 | } |
… | |
… | |
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 | |
346 | int |
340 | int |
347 | keyplace (mapstruct *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms * RP) |
341 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params * 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 | |
442 | object * |
436 | object * |
443 | find_monster_in_room_recursive (char **layout, mapstruct *map, int x, int y, RMParms * RP) |
437 | find_monster_in_room_recursive (char **layout, maptile *map, int x, int y, random_map_params * 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) |
… | |
… | |
459 | /* check the current square for a monster. If there is one, |
453 | /* check the current square for a monster. If there is one, |
460 | set theMonsterToFind and return it. */ |
454 | set theMonsterToFind and return it. */ |
461 | layout[x][y] = 1; |
455 | layout[x][y] = 1; |
462 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
456 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
463 | { |
457 | { |
464 | object *the_monster = get_map_ob (map, x, y); |
458 | object *the_monster = GET_MAP_OB (map, x, y); |
465 | |
459 | |
466 | /* check off this point */ |
460 | /* check off this point */ |
467 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_ALIVE)); the_monster = the_monster->above); |
461 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_ALIVE)); the_monster = the_monster->above); |
468 | if (the_monster && QUERY_FLAG (the_monster, FLAG_ALIVE)) |
462 | if (the_monster && QUERY_FLAG (the_monster, FLAG_ALIVE)) |
469 | { |
463 | { |
… | |
… | |
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 | |
489 | object * |
483 | object * |
490 | find_monster_in_room (mapstruct *map, int x, int y, RMParms * RP) |
484 | find_monster_in_room (maptile *map, int x, int y, random_map_params * 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; |
… | |
… | |
527 | /* the workhorse routine, which finds the free spots in a room: |
521 | /* the workhorse routine, which finds the free spots in a room: |
528 | a datastructure of free points is set up, and a position chosen from |
522 | a datastructure of free points is set up, and a position chosen from |
529 | that datastructure. */ |
523 | that datastructure. */ |
530 | |
524 | |
531 | void |
525 | void |
532 | find_spot_in_room_recursive (char **layout, int x, int y, RMParms * RP) |
526 | find_spot_in_room_recursive (char **layout, int x, int y, random_map_params * RP) |
533 | { |
527 | { |
534 | int i, j; |
528 | int i, j; |
535 | |
529 | |
536 | /* bounds check x and y */ |
530 | /* bounds check x and y */ |
537 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
531 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
… | |
… | |
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. */ |
560 | void |
554 | void |
561 | find_spot_in_room (mapstruct *map, int x, int y, int *kx, int *ky, RMParms * RP) |
555 | find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, random_map_params * 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 | |
607 | void |
601 | void |
608 | find_enclosed_spot (mapstruct *map, int *cx, int *cy, RMParms * RP) |
602 | find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params * 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; |
… | |
… | |
675 | *cx = *cy = -1; |
669 | *cx = *cy = -1; |
676 | } |
670 | } |
677 | |
671 | |
678 | |
672 | |
679 | void |
673 | void |
680 | remove_monsters (int x, int y, mapstruct *map) |
674 | remove_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)) |
686 | { |
680 | { |
687 | if (tmp->head) |
681 | if (tmp->head) |
688 | tmp = tmp->head; |
682 | tmp = tmp->head; |
689 | remove_ob (tmp); |
683 | tmp->remove (); |
690 | free_object (tmp); |
684 | tmp->destroy (); |
691 | tmp = get_map_ob (map, x, y); |
685 | tmp = GET_MAP_OB (map, x, y); |
692 | if (tmp == NULL) |
686 | if (tmp == NULL) |
693 | break; |
687 | break; |
694 | }; |
688 | }; |
695 | } |
689 | } |
696 | |
690 | |
… | |
… | |
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 | |
702 | object ** |
696 | object ** |
703 | surround_by_doors (mapstruct *map, char **layout, int x, int y, int opts) |
697 | surround_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. */ |
745 | object * |
739 | object * |
746 | door_in_square (mapstruct *map, int x, int y) |
740 | door_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) |
752 | return tmp; |
746 | return tmp; |
753 | return NULL; |
747 | return NULL; |
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 */ |
758 | void |
752 | void |
759 | find_doors_in_room_recursive (char **layout, mapstruct *map, int x, int y, object **doorlist, int *ndoors, RMParms * RP) |
753 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params * 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. */ |
800 | object ** |
794 | object ** |
801 | find_doors_in_room (mapstruct *map, int x, int y, RMParms * RP) |
795 | find_doors_in_room (maptile *map, int x, int y, random_map_params * 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 | |
840 | void |
834 | void |
841 | lock_and_hide_doors (object **doorlist, mapstruct *map, int opts, RMParms * RP) |
835 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params * 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. */ |
… | |
… | |
854 | |
848 | |
855 | door = doorlist[i]; |
849 | door = doorlist[i]; |
856 | new_door->face = door->face; |
850 | new_door->face = door->face; |
857 | new_door->x = door->x; |
851 | new_door->x = door->x; |
858 | new_door->y = door->y; |
852 | new_door->y = door->y; |
859 | remove_ob (door); |
853 | door->remove (); |
860 | free_object (door); |
854 | door->destroy (); |
861 | doorlist[i] = new_door; |
855 | doorlist[i] = new_door; |
862 | insert_ob_in_map (new_door, map, NULL, 0); |
856 | insert_ob_in_map (new_door, map, NULL, 0); |
863 | sprintf (keybuf, "%d", (int) RANDOM ()); |
857 | sprintf (keybuf, "%d", (int) RANDOM ()); |
864 | new_door->slaying = keybuf; |
858 | new_door->slaying = keybuf; |
865 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
859 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
… | |
… | |
881 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
875 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
882 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
876 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
883 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
877 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
884 | door->face = wallface->face; |
878 | door->face = wallface->face; |
885 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
879 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
886 | remove_ob (wallface); |
880 | wallface->remove (); |
887 | free_object (wallface); |
881 | wallface->destroy (); |
888 | } |
882 | } |
889 | } |
883 | } |
890 | } |
884 | } |
891 | } |
885 | } |