11
13
// You should have received a copy of the GNU General Public License
12
14
// along with this program; if not, write to the Free Software
13
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
18
#ifndef VECTOREDUNITLIST_H
16
19
#define VECTOREDUNITLIST_H
18
21
#include "vectoredunit.h"
19
#include "ObjectList.h"
22
#include "LocationList.h"
20
23
#include <sigc++/trackable.h>
23
/** An object list which keeps track of all vectoredunits. It cannot do much more than
24
* saving and loading the elements. Implemented as a singleton again.
26
//! A list of VectoredUnit objects.
28
* This class loads and saves the VectoredUnit objects in the game. It
29
* facilitates looking up VectoredUnit objects in the list.
31
* This class is loaded from, and saved to the lordsawar.vectoredunitlist XML
32
* entity in the saved-game file.
34
* Implemented as a singleton.
27
36
class VectoredUnitlist : public std::list<VectoredUnit*>, public sigc::trackable
30
//! Returns the singleton instance. Creates a new one if required.
39
//! Gets the singleton instance or creates a new one.
31
40
static VectoredUnitlist* getInstance();
33
//! Loads the singleton instance with a savegame.
42
//! Loads the VectoredUnitlist from a saved-game file.
44
* Load all VectoredUnit objects in the VectoredUnitlist from a
47
* @param helper The opened saved-game file to read from.
49
* @return The loaded VectoredUnitlist.
34
51
static VectoredUnitlist* getInstance(XML_Helper* helper);
36
//! Explicitely deletes the singleton instance.
53
//! Explicitly deletes the singleton instance.
37
54
static void deleteInstance();
39
//! updates the vectored units belonging to the player
56
//! Processes all VectoredUnit objects belonging to the given Player.
40
57
void nextTurn(Player* p);
42
//! Save function. See XML_Helper for details.
59
//! Save the list of VectoredUnit objects to a saved-game file.
43
60
bool save(XML_Helper* helper) const;
45
//! When destination cities get conquered, this list needs to be
62
//! Cull the list of VectoredUnit objects going to the given position.
64
* Scan through the VectoredUnitlist for VectoredUnit objects that
65
* have the given destination position on the game map. When found,
66
* remove it from the list.
68
* When a planted standard is picked up by another Player's Hero this
71
* @param pos Any VectoredUnit object in the list that is being
72
* vectored to this tile is deleted from the list.
47
74
void removeVectoredUnitsGoingTo(Vector<int> pos);
48
void removeVectoredUnitsGoingTo(City *c);
50
//! When source cities get conquered, this list needs to be
76
//! Cull the list of VectoredUnit objects going to the given city.
78
* Scan through the VectoredUnitlist for VectoredUnit objects that
79
* have a destination position of the given city. When found, remove
82
* This method gets called when a destination city is conquered.
84
* @param city Any VectoredUnit object in the list that is being
85
* vectored to one of the tiles in this City are deleted
88
void removeVectoredUnitsGoingTo(City *city);
90
//! Cull the list of VectoredUnit objects being vectored from a place.
92
* Scan through the VectoredUnitlist for VectoredUnit objects that
93
* have a source tile of the given position on the game map. When
94
* found, remove the VectoredUnit object from this list.
96
* When a source city gets conquered, VectoredUnit objects need to be
97
* deleted from this list.
99
* @param pos Any VectoredUnit object in the list that is being
100
* vectored from this tile is deleted from the list.
52
102
void removeVectoredUnitsComingFrom(Vector<int> pos);
53
void removeVectoredUnitsComingFrom(City *c);
55
//! When showing info we need to know who's going to where.
56
//! vectored is filled up with the results.
57
void getVectoredUnitsGoingTo(Vector<int> pos, std::list<VectoredUnit*>& vectored);
58
void getVectoredUnitsGoingTo(City *c, std::list<VectoredUnit*>& vectored);
60
//! When showing info we need to know who's coming from where.
61
//! vectored is filled up with the results.
62
void getVectoredUnitsComingFrom(Vector<int> pos, std::list<VectoredUnit*>& vectored);
64
//! Instead of returning the the vector, just return how many units
65
//! are going to a particular destination.
104
//! Cull the list of VectoredUnit objects coming from the given city.
106
* Scan through the VectoredUnitlist for VectoredUnit objects that
107
* have a source position of a tile in the given city. When found,
108
* remove it from the list.
110
* This method gets called when a destination city is conquered.
112
* @param city Any VectoredUnit object in the list that is being
113
* vectored to one of the tiles in this City are deleted
116
void removeVectoredUnitsComingFrom(City *city);
118
//! Return the list of VectoredUnit objects with the given destination.
120
* Scan through the list of VectoredUnit objects for the ones that are
121
* being vectored to the given position. Return all of the
122
* VectoredUnit objects that match.
124
* This method is used for showing who's going where.
126
* @param pos Any VectoredUnit object in the list that is being
127
* vectored to this tile is returned.
129
* @param vectored This list is filled with the VectoredUnit objects
130
* being vectored to the given position.
132
void getVectoredUnitsGoingTo(Vector<int> pos,
133
std::list<VectoredUnit*>& vectored);
135
//! Return the list of VectoredUnit objects going to the given city.
137
* Scan through the list of VectoredUnit objects for the ones that are
138
* being vectored to the tiles on the game map assocaited with the
139
* given city. Return all of the VectoredUnit objects that match.
141
* This method is used for showing who's going where.
143
* @param city Any VectoredUnit object in the list that is being
144
* vectored to this city is returned.
146
* @param vectored This list is filled with the VectoredUnit objects
147
* being vectored to the given city.
149
void getVectoredUnitsGoingTo(City *city,
150
std::list<VectoredUnit*>& vectored);
152
//! Return the list of VectoredUnit objects with the given source.
154
* Scan through the list of VectoredUnit objects for the ones that are
155
* being vectored from the given position. Return all of the
156
* VectoredUnit objects that match.
158
* This method is used for showing who's coming from where.
160
* @param pos Any VectoredUnit object in the list that is being
161
* vectored from this tile is returned.
163
* @param vectored This list is filled with the VectoredUnit objects
164
* being vectored from the given position.
166
void getVectoredUnitsComingFrom(Vector<int> pos,
167
std::list<VectoredUnit*>& vectored);
169
//! Return the number of VectoredUnits being vectored to a given place.
171
* Scan through all of the VectoredUnit objects in the list for ones
172
* that are being vectored to the given position on the game map.
173
* Count all of the matching VectoredUnit objects, and return the
176
* @return The number of VectoredUnit objects that are being vectored
177
* to the given position on the game map.
66
179
Uint32 getNumberOfVectoredUnitsGoingTo(Vector<int> pos);
68
181
//! Change the destination of vectored units as they are "in the air".
69
void changeDestination(City *c, Vector<int> new_dest);
183
* Scan through all of the VectoredUnit objects in the list for the
184
* ones that are being vectored to the given city. When found,
185
* change the destination to be the given destination.
187
* @param city A pointer to the city to change VectoredUnit objects
189
* @param new_dest A position on the game map to change where the
190
* VectoredUnit objects are going to.
192
void changeDestination(City *city, Vector<int> new_dest);
196
//! Default constructor.
72
197
VectoredUnitlist();
198
//! Loading constructor.
199
VectoredUnitlist(XML_Helper* helper);
73
201
~VectoredUnitlist();
74
VectoredUnitlist(XML_Helper* helper);
77
//! Loading callback. See XML_Helper as well.
205
//! Callback for loading the VectoredUnitlist from a saved-game file.
78
206
bool load(std::string tag, XML_Helper* helper);
208
//! A static pointer for the singleton instance.
80
209
static VectoredUnitlist* s_instance;