initial commit, lordsawar source, slightly modified
[lordsawar] / src / ruinlist.h
1 // Copyright (C) 2000, 2001 Michael Bartl
2 // Copyright (C) 2001, 2003, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2004 John Farrell
4 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
5 //
6 //  This program is free software; you can redistribute it and/or modify
7 //  it under the terms of the GNU General Public License as published by
8 //  the Free Software Foundation; either version 3 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU Library General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
19 //  02110-1301, USA.
20
21 #ifndef RUINLIST_H
22 #define RUINLIST_H
23
24 #include "ruin.h"
25 #include "LocationList.h"
26 #include <sigc++/trackable.h>
27
28 class XML_Helper;
29
30 //! A list of Ruin objects on the game map.
31 /** 
32  * The ruinlist keeps track of the Ruin objects located on the game map. It
33  * is implemented as a singleton because many classes use it for looking 
34  * up ruins.
35  */
36 class Ruinlist : public LocationList<Ruin*>, public sigc::trackable
37 {
38     public:
39         //! The xml tag of this object in a saved-game file.
40         static std::string d_tag; 
41
42
43         // Methods that operate on class data and modify the class.
44
45         //! Change ownership of all Ruin objects in the list.
46         /**
47          * Changes all ruins owned by old owner, to be owned by the new owner.
48          */
49         void changeOwnership(Player *old_owner, Player *new_owner);
50
51         
52         // Methods that operate on class data and do not modify the class.
53
54         //! Save the list of Ruin objects to the opened saved-game file.
55         bool save(XML_Helper* helper) const;
56
57         //! Find the nearest Ruin object that has not been searched.
58         /**
59          * Scan through all of the Ruin objects searching for the closest one
60          * that has not already had a Hero successfully search it.
61          *
62          * @note This method does not return hidden ruins that do not belong
63          *       to the active player.
64          *
65          * @param pos  The position on the game map to search for the nearest
66          *             unsearched Ruin object from.
67          *
68          * @return A pointer to the nearest Ruin object that has not been 
69          *         successfully searched already.  Returns NULL when all Ruin 
70          *         objects have been searched.
71          */
72         Ruin* getNearestUnsearchedRuin(const Vector<int>& pos) const;
73         Ruin* getNearestUnsearchedRuin(const Vector<int>& pos, int dist) const;
74
75         //! Find the nearest ruin.
76         /**
77          * Scan through all of the Ruin objects searching for the closest one.
78          *
79          * @note This method does not return hidden ruins that do not belong
80          *       to the active player.
81          *
82          * @param pos  The position on the game map to search for the nearest
83          *             Ruin object from.
84          *
85          * @return A pointer to the nearest Ruin object.  Returns NULL when 
86          *         there are no Ruin object in this list.
87          */
88         Ruin* getNearestRuin(const Vector<int>& pos) const;
89
90         //! Find the nearest ruin that is not too far away.
91         /**
92          * Scan through all of the Ruin objects searching for the closest one
93          * that is no far than the given distance.
94          *
95          * @note This method does not return hidden ruins that do not belong
96          *       to the active player.
97          *
98          * @param pos  The position on the game map to search for the nearest
99          *             Ruin object from.
100          * @param dist The number of tiles away that is deemed "too far".
101          *
102          * @return A pointer to the nearest Ruin object that isn't too far 
103          *         away.  If all of the Ruin objects in the list are too far 
104          *         away, this method returns NULL.
105          */
106         Ruin* getNearestRuin(const Vector<int>& pos, int dist) const;
107
108         //! Find the nearest Ruin object that is not obscured by fog.
109         /**
110          * Scan through all ruins, searching for the closest one that is
111          * not covered by fog-of-war on a hidden map.
112          *
113          * @note This method does not return hidden ruins that do not belong
114          *       to the active player.
115          *
116          * @param pos  The position to find the nearest ruin from.
117          *
118          * @return A pointer to the nearest ruin that is not obscured by fog.
119          */
120         Ruin* getNearestVisibleRuin(const Vector<int>& pos) const;
121
122         //! Find the nearest ruin that is unobscured and is not too far away.
123         /**
124          * Scan through all the ruins, searching for the closest one that
125          * is not covered by fog-of-war on a hidden map, but is not farther
126          * away than a given distance.
127          *
128          * @note This method does not return hidden ruins that do not belong
129          *       to the active player.
130          *
131          * @param pos  The position to find the nearest ruin from.
132          * @param dist The number of tiles away that is deemed "too far".
133          *
134          * @return A pointer to the nearest ruin that is not obscured by fog 
135          *         and is within the prescribed number of tiles.  Returns NULL 
136          *         if no ruin could be found.
137          */
138         Ruin* getNearestVisibleRuin(const Vector<int>& pos, int dist) const;
139
140         guint32 countUnexploredRuins(Player *owner) const;
141         guint32 countExploredRuins(Player *owner) const;
142
143         // Static Methods
144         
145         //! Returns the singleton instance.  Creates a new one if required.
146         static Ruinlist* getInstance();
147
148         //! Loads the singleton instance from the opened saved-game file.
149         static Ruinlist* getInstance(XML_Helper* helper);
150
151         //! Explicitly deletes the singleton instance.
152         static void deleteInstance();
153         
154     protected:
155
156         //! Default constructor.
157         Ruinlist();
158
159         //! Loading constructor.
160         /**
161          * Make a new list of Road objects by loading it from an opened 
162          * saved-game file.
163          *
164          * @param helper  The opened saved-game file to load the Ruin objects
165          *                from.
166          */
167         Ruinlist(XML_Helper* helper);
168
169     private:
170         //! Loading callback for loading Ruin objects into the list.
171         bool load(std::string tag, XML_Helper* helper);
172
173         // DATA
174
175         //! A static pointer for the singleton instance.
176         static Ruinlist* s_instance;
177 };
178
179 #endif