29
/** List of stacks of a single player
31
* All stacks of a player are contained in his stacklist. There is not really
32
* much to do besides saving and loading, so the stacklist contains a lot of
33
* useful functions. It can check if two stacks can join, return the defenders
37
//! A list of Stack objects for a single player.
39
* All stacks owned by a Player are contained in a Stacklist. This class
40
* covers the loading and saving of stack lists, and also some methods for
41
* getting and managing groups of stacks.
37
44
class Stacklist : public std::list<Stack*>, public sigc::trackable
47
//! Default constructor.
41
50
Stacklist(Stacklist *stacklist);
51
//! Loading constructor.
42
52
Stacklist(XML_Helper* helper);
46
//! Return the stack at position (x,y) or 0 if there is none
57
* Scan through every player's Stacklist, for a stack that is located
58
* at the given position on the game map.
60
* @param x The number of tiles down in the vertical axis from the
61
* topmost edge of the map.
62
* @param y The number of tiles right in the horizontal axis from
63
* the leftmost edge of the map.
65
* @return A pointer to a stack at the given position, or NULL if no
66
* Stack could be found.
68
//! Return the stack at position (x,y) or 0 if there is none.
47
69
static Stack* getObjectAt(int x, int y);
49
//! Return stack at position pos or 0 if there is none
50
static Stack* getObjectAt(Vector<int> point);
72
* Scan through every player's Stacklist, for a stack that is located
73
* at the given position on the game map.
75
* @param point The point on the map that we're looking to see
76
* if there is a Stack on.
78
* @return A pointer to a stack at the given position, or NULL if no
79
* Stack could be found.
81
//! Return stack at position pos or 0 if there is none.
82
static Stack* getObjectAt(Vector<int> point)
83
{ return getObjectAt(point.x, point.y);}
52
//! Return position of an army
86
* Scan through all stacks in the list, and then through each Army
87
* unit of every Stack for an Army unit with a particular Id.
89
* @param id The Id of the Army unit that we're looking for.
91
* @return The position of the Army unit. If no Army unit could be
92
* found with the given Id, the position of (-1,-1) is
95
//! Return position of an Army.
53
96
static Vector<int> getPosition(Uint32 id);
55
/** This function finds stacks which occupy the same tile.
56
* For internal and logical reasons, we always assume that a tile is
57
* occupied by at most one stack as strange bugs may happen when this
58
* is violated. However, in some cases, it does happen that stacks
59
* temporarily occupy the same tile. Reasons may be that, on its
60
* route, a stack crosses another stacks tile and can't move further.
62
* @param s the stack which we search an ambiguity for
64
static Stack* getAmbiguity(Stack* s);
66
//! Searches through the player's lists and deletes the stack
67
static void deleteStack(Stack* s);
69
/** Returns stacks defending a city
71
* If a city is attacked, all stacks which occupy a city tile are
72
* regarded as defenders.
74
* @param c the city under attack
75
* @return a list of all stacks defending the city
77
static std::vector<Stack*> defendersInCity(City* c);
79
//! Returns the number of stacks owned by all players
99
* This method finds stacks which occupy the same tile.
100
* For internal and logical reasons, we always assume that a tile is
101
* occupied by at most one stack as strange bugs may happen when this
102
* is violated. However, in some cases, it does happen that stacks
103
* temporarily occupy the same tile. Reasons may be that, on its
104
* route, a stack crosses another stacks tile and can't move further.
106
* We only expect one ambiguity at a time with stacks of the same
107
* player. This never happens except when a stack comes to halt on
108
* another stack during long movements.
110
* @param stack The stack which we search an ambiguity for.
112
* @return The other stack on the same tile occupied by stack.
114
//! Get the other stack on a tile that has more than one stack on it.
115
static Stack* getAmbiguity(Stack* stack);
117
//! Searches through the all players Stacklists and deletes the stack.
118
static void deleteStack(Stack* stack);
121
* Scan each tile occupied by the given city and return a list of
122
* stacks who are in the city.
124
* When a city is attacked, all stacks which occupy a city tile are
125
* regarded as defenders. The purpose of this function is to
126
* enumerate the defending stacks when a stack has attacked a city.
128
* @param city The city to search for stacks in.
130
* @return A list of all stacks defending the city.
132
//! Return a list of stacks defending a city.
133
static std::vector<Stack*> defendersInCity(City* city);
135
//! Returns the total number of stacks owned by all players.
80
136
static unsigned int getNoOfStacks();
82
//! Returns the number of armies in the list
138
//! Returns the total number of armies in the list.
83
139
unsigned int countArmies();
85
/** Sets the activestack. The purpose of this pointer is that the
86
* activestack is assumed to be one the player is currently "touching".
87
* Several functions use this feature for internal purposes, so don't
88
* forget to set the activestack
90
* @param activestack the stack currently moved by the player
142
* Sets the currently selected stack. The purpose of this method is
143
* to designate a stack to be the one the player is currently touching.
144
* It is important to use this method because several functions
145
* expect that there is an active stack.
147
* @param activestack The stack currently selected by the player.
92
149
void setActivestack(Stack* activestack) {d_activestack = activestack;}
94
//! Get the next non-defending stack that can move.
152
* Scan through the list of stacks to find one that is not defending,
153
* and not parked, and can move to another tile.
155
* @return A pointer to the next moveable stack or NULL if no more
158
//! Return the next moveable stack in the list.
95
159
Stack* getNextMovable();
97
//! Returns true if s and d can form one stack (esp. regarding size)
98
bool canJoin(Stack* s, Stack* d) const;
100
//! Save the data. See XML_Helper for details
161
//! Save the data to an opened saved-game file.
101
162
bool save(XML_Helper* helper) const;
103
//! Calls nextTurn of each stack in the list (for healing, upkeep etc.)
164
//! Callback method executed at the end of every turn.
106
//! Returns true if _any_ of the stacks has enough moves for its next step
168
* @return True if any stacks in the list have enough moves for
169
* it's next step along it's Path. Otherwise, false.
171
//! Returns whether or not any stacks can move.
107
172
bool enoughMoves() const;
109
//! Returns the designated activestack
174
//! Returns the currently selected stack.
110
175
Stack* getActivestack() const {return d_activestack;}
113
//! Behaves like std::list::clear(), but frees pointers as well
177
//! Erase all stacks from the list, and their contents too.
116
//! Behaves like std::list::erase(), but frees pointers as well
181
* Erase a Stack from the list, and free the contents of the Stack.
183
* @param it The place in the Stacklist to erase.
185
* @return The place in the list that was erased.
187
//! Erase a stack from the list.
117
188
iterator flErase(iterator object);
119
//! Behaves like std::list::remove(), but frees pointers as well
120
bool flRemove(Stack* object);
191
* Scan the list of stacks for a particular stack. If it is found,
192
* remove it from the list of stacks and free it's contents.
194
* @param stack The stack in the Stacklist to remove.
196
* @return Whether or not the stack was found and deleted.
198
//! Erase a stack from the list.
199
bool flRemove(Stack* stack);
122
//! Return the stack at position (x,y) or 0 if there is none
123
//! only operates on this stacklist, and not all players stacklists.
202
* Scan through the Stacklist, for a stack that is located at the
203
* given position on the game map.
205
* @note This method works only on this Stacklist, rather than all
206
* of the players Stacklists as in Stacklist::getObjectAt.
208
* @param x The number of tiles down in the vertical axis from the
209
* topmost edge of the map.
210
* @param y The number of tiles right in the horizontal axis from
211
* the leftmost edge of the map.
213
* @return A pointer to a stack at the given position, or NULL if no
214
* Stack could be found.
216
//! Return the stack at position (x,y) or 0 if there is none.
124
217
Stack* getOwnObjectAt(int x, int y);
219
Stack *getStackById(Uint32 id);
220
Stack *getArmyStackById(Uint32 army);
127
//! Callback function for loading
223
//! Callback function for loading.
128
224
bool load(std::string tag, XML_Helper* helper);
226
//! A pointer to the currently selected Stack.
130
227
Stack* d_activestack;