1 // Copyright (C) 2007, 2008 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #ifndef VECTOREDUNITLIST_H
19 #define VECTOREDUNITLIST_H
30 #include <sigc++/trackable.h>
33 //! A list of VectoredUnit objects.
35 * This class loads and saves the VectoredUnit objects in the game. It
36 * facilitates looking up VectoredUnit objects in the list.
38 * This class is loaded from, and saved to the lordsawar.vectoredunitlist XML
39 * entity in the saved-game file.
41 * Implemented as a singleton.
43 class VectoredUnitlist : public std::list<VectoredUnit*>, public sigc::trackable
46 //! The xml tag of this object in a saved-game file.
47 static std::string d_tag;
50 // Methods that operate on the class data and modify the class.
52 //! Processes all VectoredUnit objects belonging to the given Player.
53 void nextTurn(Player* p);
56 //! Cull the list of VectoredUnit objects going to the given position.
58 * Scan through the VectoredUnitlist for VectoredUnit objects that
59 * have the given destination position on the game map. When found,
60 * remove it from the list.
62 * When a planted standard is picked up by another Player's Hero this
65 * @param pos Any VectoredUnit object in the list that is being
66 * vectored to this tile is deleted from the list.
68 bool removeVectoredUnitsGoingTo(Vector<int> pos);
70 //! Cull the list of VectoredUnit objects going to the given city.
72 * Scan through the VectoredUnitlist for VectoredUnit objects that
73 * have a destination position of the given city. When found, remove
76 * This method gets called when a destination city is conquered.
78 * @param city Any VectoredUnit object in the list that is being
79 * vectored to one of the tiles in this City are deleted
82 bool removeVectoredUnitsGoingTo(City *city);
84 //! Cull the list of VectoredUnit objects being vectored from a place.
86 * Scan through the VectoredUnitlist for VectoredUnit objects that
87 * have a source tile of the given position on the game map. When
88 * found, remove the VectoredUnit object from this list.
90 * When a source city gets conquered, VectoredUnit objects need to be
91 * deleted from this list.
93 * @param pos Any VectoredUnit object in the list that is being
94 * vectored from this tile is deleted from the list.
96 bool removeVectoredUnitsComingFrom(Vector<int> pos);
98 //! Cull the list of VectoredUnit objects coming from the given city.
100 * Scan through the VectoredUnitlist for VectoredUnit objects that
101 * have a source position of a tile in the given city. When found,
102 * remove it from the list.
104 * This method gets called when a destination city is conquered.
106 * @param city Any VectoredUnit object in the list that is being
107 * vectored to one of the tiles in this City are deleted
110 bool removeVectoredUnitsComingFrom(City *city);
112 //! Change the destination of vectored units as they are "in the air".
114 * Scan through all of the VectoredUnit objects in the list for the
115 * ones that are being vectored to the given city. When found,
116 * change the destination to be the given destination.
118 * @param city A pointer to the city to change VectoredUnit objects
120 * @param new_dest A position on the game map to change where the
121 * VectoredUnit objects are going to.
123 bool changeDestination(City *city, Vector<int> new_dest);
125 //! Change the owner of all of the vectored units in the list.
127 * Change the vectored units belonging to the old_player, to the
130 void changeOwnership(Player *old_owner, Player *new_owner);
132 //! Remove a vectored unit from the list. Also deletes it.
133 iterator flErase(iterator object);
136 // Methods that operate on the class data but do not modify the class.
138 //! Save the list of VectoredUnit objects to a saved-game file.
139 bool save(XML_Helper* helper) const;
141 //! Return the list of VectoredUnit objects with the given destination.
143 * Scan through the list of VectoredUnit objects for the ones that are
144 * being vectored to the given position. Return all of the
145 * VectoredUnit objects that match.
147 * This method is used for showing who's going where.
149 * @param pos Any VectoredUnit object in the list that is being
150 * vectored to this tile is returned.
152 * @param vectored This list is filled with the VectoredUnit objects
153 * being vectored to the given position.
155 void getVectoredUnitsGoingTo(Vector<int> pos,
156 std::list<VectoredUnit*>& vectored) const;
158 //! Return the list of VectoredUnit objects going to the given city.
160 * Scan through the list of VectoredUnit objects for the ones that are
161 * being vectored to the tiles on the game map assocaited with the
162 * given city. Return all of the VectoredUnit objects that match.
164 * This method is used for showing who's going where.
166 * @param city Any VectoredUnit object in the list that is being
167 * vectored to this city is returned.
169 * @param vectored This list is filled with the VectoredUnit objects
170 * being vectored to the given city.
172 void getVectoredUnitsGoingTo(City *city,
173 std::list<VectoredUnit*>& vectored) const;
175 //! Return the list of VectoredUnit objects with the given source.
177 * Scan through the list of VectoredUnit objects for the ones that are
178 * being vectored from the given position. Return all of the
179 * VectoredUnit objects that match.
181 * This method is used for showing who's coming from where.
183 * @param pos Any VectoredUnit object in the list that is being
184 * vectored from this tile is returned.
186 * @param vectored This list is filled with the VectoredUnit objects
187 * being vectored from the given position.
189 void getVectoredUnitsComingFrom(Vector<int> pos,
190 std::list<VectoredUnit*>& vectored) const;
192 //! Return the number of VectoredUnits being vectored to a given place.
194 * Scan through all of the VectoredUnit objects in the list for ones
195 * that are being vectored to the given position on the game map.
196 * Count all of the matching VectoredUnit objects, and return the
199 * @return The number of VectoredUnit objects that are being vectored
200 * to the given position on the game map.
202 guint32 getNumberOfVectoredUnitsGoingTo(Vector<int> pos) const;
206 //! Gets the singleton instance or creates a new one.
207 static VectoredUnitlist* getInstance();
209 //! Loads the VectoredUnitlist from a saved-game file.
211 * Load all VectoredUnit objects in the VectoredUnitlist from a
214 * @param helper The opened saved-game file to read from.
216 * @return The loaded VectoredUnitlist.
218 static VectoredUnitlist* getInstance(XML_Helper* helper);
220 //! Explicitly deletes the singleton instance.
221 static void deleteInstance();
225 //! Default constructor.
228 //! Loading constructor.
229 VectoredUnitlist(XML_Helper* helper);
236 //! Callback for loading the VectoredUnitlist from a saved-game file.
237 bool load(std::string tag, XML_Helper* helper);
241 //! A static pointer for the singleton instance.
242 static VectoredUnitlist* s_instance;