1 | /* |
1 | /* |
2 | <<<<<<< treasure.C |
|
|
3 | * CrossFire, A Multiplayer game |
2 | * CrossFire, A Multiplayer game |
4 | * |
3 | * |
5 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
6 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
7 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
20 | * along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 | * |
21 | * |
23 | * 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> |
24 | */ |
23 | */ |
25 | ======= |
|
|
26 | * CrossFire, A Multiplayer game for X-windows |
|
|
27 | * |
|
|
28 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
|
|
29 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
|
|
30 | * Copyright (C) 1992 Frank Tore Johansen |
|
|
31 | * |
|
|
32 | * This program is free software; you can redistribute it and/or modify |
|
|
33 | * it under the terms of the GNU General Public License as published by |
|
|
34 | * the Free Software Foundation; either version 2 of the License, or |
|
|
35 | * (at your option) any later version. |
|
|
36 | * |
|
|
37 | * This program is distributed in the hope that it will be useful, |
|
|
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
40 | * GNU General Public License for more details. |
|
|
41 | * |
|
|
42 | * You should have received a copy of the GNU General Public License |
|
|
43 | * along with this program; if not, write to the Free Software |
|
|
44 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
45 | * |
|
|
46 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
|
|
47 | */ |
|
|
48 | >>>>>>> 1.18 |
|
|
49 | |
24 | |
50 | /* placing treasure in maps, where appropriate. */ |
25 | /* placing treasure in maps, where appropriate. */ |
51 | |
26 | |
52 | #include <global.h> |
27 | #include <global.h> |
53 | #include <random_map.h> |
28 | #include <random_map.h> |
… | |
… | |
99 | |
74 | |
100 | /* bail out if treasure isn't wanted. */ |
75 | /* bail out if treasure isn't wanted. */ |
101 | if (treasure_style) |
76 | if (treasure_style) |
102 | if (!strcmp (treasure_style, "none")) |
77 | if (!strcmp (treasure_style, "none")) |
103 | return; |
78 | return; |
|
|
79 | |
104 | if (treasureoptions <= 0) |
80 | if (treasureoptions <= 0) |
105 | treasureoptions = RANDOM () % (2 * LAST_OPTION); |
81 | treasureoptions = RANDOM () % (2 * LAST_OPTION); |
106 | |
82 | |
107 | /* filter out the mutually exclusive options */ |
83 | /* filter out the mutually exclusive options */ |
108 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
84 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
109 | { |
85 | { |
110 | if (RANDOM () % 2) |
86 | if (rndm (2)) |
111 | treasureoptions -= 1; |
87 | treasureoptions -= 1; |
112 | else |
88 | else |
113 | treasureoptions -= 2; |
89 | treasureoptions -= 2; |
114 | } |
90 | } |
115 | |
91 | |
… | |
… | |
488 | return theMonsterToFind; |
464 | return theMonsterToFind; |
489 | } |
465 | } |
490 | } |
466 | } |
491 | |
467 | |
492 | /* now search all the 8 squares around recursively for a monster,in random order */ |
468 | /* now search all the 8 squares around recursively for a monster,in random order */ |
493 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
469 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
494 | { |
470 | { |
495 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
471 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
496 | if (theMonsterToFind != NULL) |
472 | if (theMonsterToFind != NULL) |
497 | return theMonsterToFind; |
473 | return theMonsterToFind; |
498 | } |
474 | } |
… | |
… | |
561 | room_free_spots_x[number_of_free_spots_in_room] = x; |
537 | room_free_spots_x[number_of_free_spots_in_room] = x; |
562 | room_free_spots_y[number_of_free_spots_in_room] = y; |
538 | room_free_spots_y[number_of_free_spots_in_room] = y; |
563 | number_of_free_spots_in_room++; |
539 | number_of_free_spots_in_room++; |
564 | |
540 | |
565 | /* now search all the 8 squares around recursively for free spots,in random order */ |
541 | /* now search all the 8 squares around recursively for free spots,in random order */ |
566 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
542 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
567 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
543 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
568 | |
544 | |
569 | } |
545 | } |
570 | |
546 | |
571 | /* find a random non-blocked spot in this room to drop a key. */ |
547 | /* find a random non-blocked spot in this room to drop a key. */ |
… | |
… | |
685 | *cx = -1; |
661 | *cx = -1; |
686 | *cy = -1; |
662 | *cy = -1; |
687 | } |
663 | } |
688 | } |
664 | } |
689 | |
665 | |
690 | |
|
|
691 | void |
666 | void |
692 | remove_monsters (int x, int y, maptile *map) |
667 | remove_monsters (int x, int y, maptile *map) |
693 | { |
668 | { |
694 | object *tmp; |
669 | object *tmp; |
695 | |
670 | |
696 | for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above) |
671 | for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) |
697 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
672 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
698 | { |
673 | { |
699 | if (tmp->head) |
674 | if (tmp->head) |
700 | tmp = tmp->head; |
675 | tmp = tmp->head; |
701 | tmp->remove (); |
676 | tmp->remove (); |
… | |
… | |
704 | if (tmp == NULL) |
679 | if (tmp == NULL) |
705 | break; |
680 | break; |
706 | }; |
681 | }; |
707 | } |
682 | } |
708 | |
683 | |
709 | |
|
|
710 | /* surrounds the point x,y by doors, so as to enclose something, like |
684 | /* surrounds the point x,y by doors, so as to enclose something, like |
711 | a chest. It only goes as far as the 8 squares surrounding, and |
685 | a chest. It only goes as far as the 8 squares surrounding, and |
712 | it'll remove any monsters it finds.*/ |
686 | it'll remove any monsters it finds.*/ |
713 | |
|
|
714 | object ** |
687 | object ** |
715 | surround_by_doors (maptile *map, char **layout, int x, int y, int opts) |
688 | surround_by_doors (maptile *map, char **layout, int x, int y, int opts) |
716 | { |
689 | { |
717 | int i; |
690 | int i; |
718 | char *doors[2]; |
691 | char *doors[2]; |
… | |
… | |
735 | /* place doors in all the 8 adjacent unblocked squares. */ |
708 | /* place doors in all the 8 adjacent unblocked squares. */ |
736 | for (i = 1; i < 9; i++) |
709 | for (i = 1; i < 9; i++) |
737 | { |
710 | { |
738 | int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; |
711 | int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; |
739 | |
712 | |
740 | if (!wall_blocked (map, x1, y1) || layout[x1][y1] == '>') |
713 | if (!wall_blocked (map, x1, y1) && layout[x1][y1] == '>') |
741 | { /* place a door */ |
714 | { /* place a door */ |
|
|
715 | remove_monsters (x1, y1, map); |
|
|
716 | |
742 | object *new_door = get_archetype ((freearr_x[i] == 0) ? doors[1] : doors[0]); |
717 | object *new_door = get_archetype (freearr_x[i] == 0 ? doors[1] : doors[0]); |
743 | |
718 | map->insert (new_door, x1, y1); |
744 | new_door->x = x + freearr_x[i]; |
|
|
745 | new_door->y = y + freearr_y[i]; |
|
|
746 | remove_monsters (new_door->x, new_door->y, map); |
|
|
747 | insert_ob_in_map (new_door, map, NULL, 0); |
|
|
748 | doorlist[ndoors_made] = new_door; |
719 | doorlist[ndoors_made] = new_door; |
749 | ndoors_made++; |
720 | ndoors_made++; |
750 | } |
721 | } |
751 | } |
722 | } |
|
|
723 | |
752 | return doorlist; |
724 | return doorlist; |
753 | } |
725 | } |
754 | |
726 | |
755 | |
727 | |
756 | /* returns the first door in this square, or NULL if there isn't a door. */ |
728 | /* returns the first door in this square, or NULL if there isn't a door. */ |
… | |
… | |
800 | } |
772 | } |
801 | else |
773 | else |
802 | { |
774 | { |
803 | layout[x][y] = 1; |
775 | layout[x][y] = 1; |
804 | /* now search all the 8 squares around recursively for free spots,in random order */ |
776 | /* now search all the 8 squares around recursively for free spots,in random order */ |
805 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
777 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
806 | find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); |
778 | find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); |
807 | } |
779 | } |
808 | } |
780 | } |
809 | |
781 | |
810 | /* find a random non-blocked spot in this room to drop a key. */ |
782 | /* find a random non-blocked spot in this room to drop a key. */ |