initial commit, lordsawar source, slightly modified
[lordsawar] / src / templelist.h
1 // Copyright (C) 2000, 2001, 2003 Michael Bartl
2 // Copyright (C) 2001, 2003, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Library General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
18 //  02110-1301, USA.
19
20 #ifndef TEMPLELIST_H
21 #define TEMPLELIST_H
22
23 #include <sigc++/trackable.h>
24 #include "LocationList.h"
25 #include "temple.h"
26 class Stack;
27 class XML_Helper;
28
29 //! A list of Temple objects on the game map.
30 /** 
31  * The templelist keeps track of the temples located on the game map. It
32  * is implemented as a singleton because many classes use it for looking 
33  * up temples.
34  */
35 class Templelist : public LocationList<Temple*>, public sigc::trackable
36 {
37     public:
38         //! The xml tag of this object in a saved-game file.
39         static std::string d_tag; 
40
41         // Methods that operate on class data but do not modify the class.
42         
43         //! Saves the temple data to an opened saved-game file.
44         bool save(XML_Helper* helper) const;
45
46         //! Find the nearest temple that is not obscured by fog.
47         /**
48          * Scan through all temples, searching for the closest one that is
49          * not covered by fog-of-war on a hidden map.
50          *
51          * @param pos  The position to find the nearest temple from.
52          *
53          * @return A pointer to the nearest temple that is not obscured by fog.
54          */
55         Temple* getNearestVisibleTemple(const Vector<int>& pos) const;
56
57         //! Find the nearest temple that is unobscured and is not too far away.
58         /**
59          * Scan through all the temples, searching for the closest one that
60          * is not covered by fog-of-war on a hidden map, but is not farther
61          * away than a given distance.
62          *
63          * @param pos  The position to find the nearest temple from.
64          * @param dist The number of tiles away that is deemed "too far".
65          *
66          * @return A pointer to the nearest temple that is not obscured by fog 
67          *         and is within the prescribed number of tiles.  Returns NULL 
68          *         if no temple could be found.
69          */
70         Temple* getNearestVisibleTemple(const Vector<int>& pos, int dist) const;
71
72         //! Find the nearest temple that the given stack can get blessed at.
73         /**
74          * @param stack  The stack that wants to get blessed at a temple.
75          * @param percent_can_be_blessed  
76          *               Consider temples where the minimum percentage of army 
77          *               units in the stack that have not been blessed at a
78          *               temple.
79          * @return A pointer to the nearest temple that is not obscured by fog
80          *         and has more than the given percentage of army units that
81          *         can be blessed there.  Returns NULL if no temple could be
82          *         found.
83          */
84         Temple* getNearestVisibleAndUsefulTemple(Stack *stack, double percent_can_be_blessed) const;
85
86         //! Find the nearest temple that the given stack can get blessed at.
87         /**
88          * @param stack  The stack that wants to get blessed at a temple.
89          * @param percent_can_be_blessed  
90          *               Consider temples where the minimum percentage of army 
91          *               units in the stack that have not been blessed at a
92          *               temple.
93          * @param dist   Do not consider temples farther away than dist tiles.
94          *
95          * @return A pointer to the nearest temple that is not obscured by fog
96          *         and has more than the given percentage of army units that
97          *         can be blessed there, and is within a certain number of 
98          *         tiles from the stack's position on the map.  Returns NULL if 
99          *         no temple could be found.
100          */
101         Temple* getNearestVisibleAndUsefulTemple(Stack *stack, double percent_can_be_blessed, int dist) const;
102
103
104         // Static Methods
105
106         //! Return the singleton instance.  Create a new one if needed.
107         static Templelist* getInstance();
108
109         //! Load the temple list from an opened saved-game file.
110         /**
111          * @param helper  The opened saved-game file to load the list of 
112          *                temples from.
113          *
114          * @return The list of temples.
115          */
116         static Templelist* getInstance(XML_Helper* helper);
117
118         //! Explicitly delete the singleton instance.
119         static void deleteInstance();
120
121     protected:
122         //! Default constructor.
123         Templelist();
124
125         //! Loading constructor.
126         /**
127          * Load the list of temples from an opened saved-game file.
128          *
129          * @param helper  The opened saved-game file to load the temples from.
130          */
131         Templelist(XML_Helper* helper);
132
133     private:
134         //! Callback for loading temple objects from opened saved game files.
135         bool load(std::string tag, XML_Helper* helper);
136
137         //! A static pointer for the singleton instance.
138         static Templelist* s_instance;
139 };
140
141 #endif