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
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.
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.
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
25 #include "LocationList.h"
26 #include <sigc++/trackable.h>
30 //! A list of Ruin objects on the game map.
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
36 class Ruinlist : public LocationList<Ruin*>, public sigc::trackable
39 //! The xml tag of this object in a saved-game file.
40 static std::string d_tag;
43 // Methods that operate on class data and modify the class.
45 //! Change ownership of all Ruin objects in the list.
47 * Changes all ruins owned by old owner, to be owned by the new owner.
49 void changeOwnership(Player *old_owner, Player *new_owner);
52 // Methods that operate on class data and do not modify the class.
54 //! Save the list of Ruin objects to the opened saved-game file.
55 bool save(XML_Helper* helper) const;
57 //! Find the nearest Ruin object that has not been searched.
59 * Scan through all of the Ruin objects searching for the closest one
60 * that has not already had a Hero successfully search it.
62 * @note This method does not return hidden ruins that do not belong
63 * to the active player.
65 * @param pos The position on the game map to search for the nearest
66 * unsearched Ruin object from.
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.
72 Ruin* getNearestUnsearchedRuin(const Vector<int>& pos) const;
73 Ruin* getNearestUnsearchedRuin(const Vector<int>& pos, int dist) const;
75 //! Find the nearest ruin.
77 * Scan through all of the Ruin objects searching for the closest one.
79 * @note This method does not return hidden ruins that do not belong
80 * to the active player.
82 * @param pos The position on the game map to search for the nearest
85 * @return A pointer to the nearest Ruin object. Returns NULL when
86 * there are no Ruin object in this list.
88 Ruin* getNearestRuin(const Vector<int>& pos) const;
90 //! Find the nearest ruin that is not too far away.
92 * Scan through all of the Ruin objects searching for the closest one
93 * that is no far than the given distance.
95 * @note This method does not return hidden ruins that do not belong
96 * to the active player.
98 * @param pos The position on the game map to search for the nearest
100 * @param dist The number of tiles away that is deemed "too far".
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.
106 Ruin* getNearestRuin(const Vector<int>& pos, int dist) const;
108 //! Find the nearest Ruin object that is not obscured by fog.
110 * Scan through all ruins, searching for the closest one that is
111 * not covered by fog-of-war on a hidden map.
113 * @note This method does not return hidden ruins that do not belong
114 * to the active player.
116 * @param pos The position to find the nearest ruin from.
118 * @return A pointer to the nearest ruin that is not obscured by fog.
120 Ruin* getNearestVisibleRuin(const Vector<int>& pos) const;
122 //! Find the nearest ruin that is unobscured and is not too far away.
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.
128 * @note This method does not return hidden ruins that do not belong
129 * to the active player.
131 * @param pos The position to find the nearest ruin from.
132 * @param dist The number of tiles away that is deemed "too far".
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.
138 Ruin* getNearestVisibleRuin(const Vector<int>& pos, int dist) const;
140 guint32 countUnexploredRuins(Player *owner) const;
141 guint32 countExploredRuins(Player *owner) const;
145 //! Returns the singleton instance. Creates a new one if required.
146 static Ruinlist* getInstance();
148 //! Loads the singleton instance from the opened saved-game file.
149 static Ruinlist* getInstance(XML_Helper* helper);
151 //! Explicitly deletes the singleton instance.
152 static void deleteInstance();
156 //! Default constructor.
159 //! Loading constructor.
161 * Make a new list of Road objects by loading it from an opened
164 * @param helper The opened saved-game file to load the Ruin objects
167 Ruinlist(XML_Helper* helper);
170 //! Loading callback for loading Ruin objects into the list.
171 bool load(std::string tag, XML_Helper* helper);
175 //! A static pointer for the singleton instance.
176 static Ruinlist* s_instance;