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
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.
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.
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
23 #include <sigc++/trackable.h>
24 #include "LocationList.h"
29 //! A list of Temple objects on the game map.
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
35 class Templelist : public LocationList<Temple*>, public sigc::trackable
38 //! The xml tag of this object in a saved-game file.
39 static std::string d_tag;
41 // Methods that operate on class data but do not modify the class.
43 //! Saves the temple data to an opened saved-game file.
44 bool save(XML_Helper* helper) const;
46 //! Find the nearest temple that is not obscured by fog.
48 * Scan through all temples, searching for the closest one that is
49 * not covered by fog-of-war on a hidden map.
51 * @param pos The position to find the nearest temple from.
53 * @return A pointer to the nearest temple that is not obscured by fog.
55 Temple* getNearestVisibleTemple(const Vector<int>& pos) const;
57 //! Find the nearest temple that is unobscured and is not too far away.
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.
63 * @param pos The position to find the nearest temple from.
64 * @param dist The number of tiles away that is deemed "too far".
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.
70 Temple* getNearestVisibleTemple(const Vector<int>& pos, int dist) const;
72 //! Find the nearest temple that the given stack can get blessed at.
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
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
84 Temple* getNearestVisibleAndUsefulTemple(Stack *stack, double percent_can_be_blessed) const;
86 //! Find the nearest temple that the given stack can get blessed at.
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
93 * @param dist Do not consider temples farther away than dist tiles.
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.
101 Temple* getNearestVisibleAndUsefulTemple(Stack *stack, double percent_can_be_blessed, int dist) const;
106 //! Return the singleton instance. Create a new one if needed.
107 static Templelist* getInstance();
109 //! Load the temple list from an opened saved-game file.
111 * @param helper The opened saved-game file to load the list of
114 * @return The list of temples.
116 static Templelist* getInstance(XML_Helper* helper);
118 //! Explicitly delete the singleton instance.
119 static void deleteInstance();
122 //! Default constructor.
125 //! Loading constructor.
127 * Load the list of temples from an opened saved-game file.
129 * @param helper The opened saved-game file to load the temples from.
131 Templelist(XML_Helper* helper);
134 //! Callback for loading temple objects from opened saved game files.
135 bool load(std::string tag, XML_Helper* helper);
137 //! A static pointer for the singleton instance.
138 static Templelist* s_instance;