55
56
//! Default constructor.
57
59
//! Copy constructor.
58
60
Stacklist(Stacklist *stacklist);
59
62
//! Loading constructor.
60
63
Stacklist(XML_Helper* helper);
65
* Scan through every player's Stacklist, for a stack that is located
66
* at the given position on the game map.
68
* @param x The number of tiles down in the vertical axis from the
69
* topmost edge of the map.
70
* @param y The number of tiles right in the horizontal axis from
71
* the leftmost edge of the map.
73
* @return A pointer to a stack at the given position, or NULL if no
74
* Stack could be found.
76
//! Return the stack at position (x,y) or 0 if there is none.
77
static Stack* getObjectAt(int x, int y);
78
void getObjectAt(Vector<int> pos, Stack *& s1, Stack *& s2);
81
* Scan through every player's Stacklist, for a stack that is located
82
* at the given position on the game map.
84
* @param point The point on the map that we're looking to see
85
* if there is a Stack on.
87
* @return A pointer to a stack at the given position, or NULL if no
88
* Stack could be found.
90
//! Return stack at position pos or 0 if there is none.
91
static Stack* getObjectAt(Vector<int> point)
92
{ return getObjectAt(point.x, point.y);}
95
* Scan through all stacks in the list, and then through each Army
96
* unit of every Stack for an Army unit with a particular Id.
98
* @param id The Id of the Army unit that we're looking for.
100
* @return The position of the Army unit. If no Army unit could be
101
* found with the given Id, the position of (-1,-1) is
104
//! Return position of an Army.
105
static Vector<int> getPosition(guint32 id);
70
//!Set the stack the player is currently working with.
72
* Sets the currently selected stack. The purpose of this method is
73
* to designate a stack to be the one the player is currently touching.
74
* It is important to use this method because several functions
75
* expect that there is an active stack.
77
* @param activestack The stack currently selected by the player.
79
void setActivestack(Stack* activestack);
84
//! Returns the currently selected stack.
85
Stack* getActivestack() const {return d_activestack;}
88
// Methods that operate on class data and do not modify the class.
108
91
* This method finds stacks which occupy the same tile.
123
106
//! Get the other stack on a tile that has more than one stack on it.
124
107
static Stack* getAmbiguity(Stack* stack);
126
//! Searches through the all players Stacklists and deletes the stack.
127
static bool deleteStack(Stack* stack);
128
static bool deleteStack(guint32 id);
131
* Scan each tile occupied by the given city and return a list of
132
* stacks who are in the city.
134
* When a city is attacked, all stacks which occupy a city tile are
135
* regarded as defenders. The purpose of this function is to
136
* enumerate the defending stacks when a stack has attacked a city.
138
* @param city The city to search for stacks in.
140
* @return A list of all stacks defending the city.
142
//! Return a list of stacks defending a city.
143
static std::vector<Stack*> defendersInCity(City* city);
145
//! Returns the total number of stacks owned by all players.
146
static unsigned int getNoOfStacks();
148
109
//! Returns the total number of armies in the list.
149
unsigned int countArmies();
151
//! Returns the total number of heroes in the list.
152
unsigned int countHeroes();
155
* Sets the currently selected stack. The purpose of this method is
156
* to designate a stack to be the one the player is currently touching.
157
* It is important to use this method because several functions
158
* expect that there is an active stack.
160
* @param activestack The stack currently selected by the player.
162
void setActivestack(Stack* activestack);
110
unsigned int countArmies() const;
112
//! Returns the total number of armies in the list that are awardable.
113
unsigned int countAllies() const;
165
116
* Scan through the list of stacks to find one that is not defending,
169
120
* stacks can move.
171
122
//! Return the next moveable stack in the list.
172
Stack* getNextMovable();
123
Stack* getNextMovable() const;
126
* @return True if any stacks in the list have enough moves for
127
* it's next step along it's Path. Otherwise, false.
129
//! Returns whether or not any stacks can move.
130
bool enoughMoves() const;
174
132
//! Save the data to an opened saved-game file.
175
133
bool save(XML_Helper* helper) const;
135
//! Find a stack in this stacklist given this id.
136
Stack *getStackById(guint32 id) const;
138
//! Find the stack in this stacklist that contains an army with this id.
139
Stack *getArmyStackById(guint32 army) const;
141
//! Collect gold pieces from army units in the list that give money.
143
* Heroes in a stacklist can provide gold pieces by carrying items.
144
* These items are +3 gold per city, etc so the number of cities
145
* must be passed into this method.
147
* This method increases the given player's treasury.
149
void collectTaxes(Player *p, guint32 num_cities) const;
151
//! Return a list of the heroes in the stacklist.
152
std::list<Hero*> getHeroes() const;
154
//! Return a hero from this stacklist that is closest to the given pos.
156
* The hero must be within a given distance, provided by the dist
157
* parameter. The distance is measured in tiles (not movement points).
159
Hero *getNearestHero(Vector<int> pos, int dist) const;
162
// Methods that operate on class data and modify the class.
164
//! remove all movement points from every army in every stack.
165
void drainAllMovement();
177
167
//! Callback method executed at the end of every turn.
170
//! Have everyone in this stacklist collect their upkeep from a player.
172
* This method decreases the given player's treasury.
179
174
void payUpkeep(Player *p);
182
* @return True if any stacks in the list have enough moves for
183
* it's next step along it's Path. Otherwise, false.
185
//! Returns whether or not any stacks can move.
186
bool enoughMoves() const;
188
//! Returns the currently selected stack.
189
Stack* getActivestack() const {return d_activestack;}
191
176
//! Erase all stacks from the list, and their contents too.
194
179
//! Add a stack to the list.
195
180
void add(Stack *stack);
197
183
* Erase a Stack from the list, and free the contents of the Stack.
214
200
//! Erase a stack from the list.
215
201
bool flRemove(Stack* stack);
203
//! Erase a stack from the list, given the stack id.
216
204
bool flRemove(guint32 id);
219
* Scan through the Stacklist, for a stack that is located at the
220
* given position on the game map.
222
* @note This method works only on this Stacklist, rather than all
223
* of the players Stacklists as in Stacklist::getObjectAt.
225
* @param x The number of tiles down in the vertical axis from the
226
* topmost edge of the map.
227
* @param y The number of tiles right in the horizontal axis from
228
* the leftmost edge of the map.
230
* @return A pointer to a stack at the given position, or NULL if no
231
* Stack could be found.
233
//! Return the stack at position (x,y) or 0 if there is none.
234
Stack* getOwnObjectAt(int x, int y);
235
Stack* getOwnObjectAt(Vector<int> point)
236
{ return getOwnObjectAt(point.x, point.y);}
238
Stack *getStackById(guint32 id);
239
Stack *getArmyStackById(guint32 army);
241
void collectTaxes(Player *p, guint32 num_cities);
243
std::list<Hero*> getTopHeroes(int num);
209
//! The stack in the stacklist has been grouped or ungrouped.
210
sigc::signal<void, Stack*, bool> sgrouped;
212
//! The stack in the stacklist is arriving on a new tile.
213
sigc::signal<void, Stack*, Vector<int> > snewpos;
215
//! The stack in the stacklist is leaving an old tile.
216
sigc::signal<void, Stack*, Vector<int> > soldpos;
221
//! Searches through the all players Stacklists and deletes the stack.
222
static bool deleteStack(Stack* stack);
224
//! Searches for the stack id in all lists, and deletes it.
225
static bool deleteStack(guint32 id);
228
* Scan each tile occupied by the given city and return a list of
229
* stacks who are in the city.
231
* When a city is attacked, all stacks which occupy a city tile are
232
* regarded as defenders. The purpose of this function is to
233
* enumerate the defending stacks when a stack has attacked a city.
235
* @param city The city to search for stacks in.
237
* @return A list of all stacks defending the city.
239
//! Return a list of stacks defending a city.
240
static std::vector<Stack*> getDefendersInCity(const City* city);
242
//! Returns the total number of stacks owned by all players.
243
static unsigned int getNoOfStacks();
245
//! Returns the total number of armies owned by all players.
246
static unsigned int getNoOfArmies();
249
* This method removes the given stack from it's owner's stacklist and
250
* places it in the new owner's stacklist.
252
//! Change allegience of the given stack to a new owner.
253
static void changeOwnership(Stack *stack, Player *new_owner);
255
//! Can this stack reach a point where it is not blocked by friendlies?
257
* The idea here is that the stack is blocked by a friendly stack on
258
* it's path. This method checks to see if the stack has enough
259
* movement points to proceed through the friendly stacks (that are
260
* too big to join with), and land on a point in it's path beyond it.
245
262
static bool canJumpOverTooLargeStack(Stack *s);
247
std::list<Hero*> getHeroes();
249
Hero *getNearestHero(Vector<int> pos, int dist);
251
sigc::signal<void, Stack*, bool> sgrouped;
253
//! remove all movement points from every army in every stack.
254
void drainAllMovement();
264
//! Return position of an Army with the given id in this stacklist.
266
* Scan through all stacks in the list, and then through each Army
267
* unit of every Stack for an Army unit with a particular Id.
269
* @param id The Id of the Army unit that we're looking for.
271
* @return The position of the Army unit. If no Army unit could be
272
* found with the given Id, the position of (-1,-1) is
275
static Vector<int> getPosition(guint32 id);
278
std::list<Vector<int> > getPositions() const;
280
std::list<Stack*> getStacksWithItems() const;
257
//! Callback function for loading.
285
//! Callback for loading this object from an opened saved-game file.
258
286
bool load(std::string tag, XML_Helper* helper);
260
//! Callbacks for when things happen to stack in our list.
288
//! Callback for when a stack initiates movement after being stopped.
261
289
void on_stack_starts_moving (Stack *s);
291
//! Callback for when a stack halts.
262
292
void on_stack_stops_moving (Stack *s);
294
//! Callback for when a stack has been killed, or disbanded.
263
295
void on_stack_died (Stack *stack);
297
//! Callback for when a stack has been grouped or ungrouped.
264
298
void on_stack_grouped (Stack *stack, bool grouped);
266
void getHeroes(std::vector<guint32>& dst);
300
void getHeroes(std::vector<guint32>& dst) const;
302
//! Notify the game map that a stack is leaving it's tile.
303
bool deletePositionFromMap(Stack *stack);
305
//! Notify the game map that a stack is arriving on a tile.
306
bool addPositionToMap(Stack *s);
267
310
//! A pointer to the currently selected Stack.
268
311
Stack* d_activestack;
270
//! methods for managing the dual hash maps.
271
bool deletePositionFromMap(Stack *stack);
272
bool addPositionToMap(Stack *s);
273
//! a hash map of where the stacks are on the map.
274
typedef std::map<Vector<int>, Stack*> PositionMap;
275
PositionMap d_object1;
276
PositionMap d_object2;
277
313
typedef std::map<Stack *, std::list<sigc::connection> > ConnectionMap;
314
// A set of signal connections for each stack in our list.
316
* We can use this map to lookup the outstanding signals connections
317
* that a given stack has. This is so that we can destroy them
318
* when the stack is deleted.
278
320
ConnectionMap d_connections;
322
typedef std::map<guint32, Stack*> IdMap;
323
//! A map to quickly lookup the stack by it's unique id.