~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

Viewing changes to src/stack.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2000, 2001, 2003 Michael Bartl
 
2
// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Ulf Lorenz
 
3
// Copyright (C) 2004, 2005, 2006 Andrea Paternesi
 
4
// Copyright (C) 2007, 2008 Ben Asselstine
 
5
// Copyright (C) 2007, 2008 Ole Laursen
 
6
//
1
7
//  This program is free software; you can redistribute it and/or modify
2
8
//  it under the terms of the GNU General Public License as published by
3
9
//  the Free Software Foundation; either version 2 of the License, or
10
16
//
11
17
//  You should have received a copy of the GNU General Public License
12
18
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
20
//  02110-1301, USA.
14
21
 
15
22
#ifndef STACK_H
16
23
#define STACK_H
22
29
#include <sigc++/signal.h>
23
30
#include <sstream>
24
31
 
25
 
#include "Object.h"
 
32
#include "UniquelyIdentified.h"
 
33
#include "Ownable.h"
 
34
#include "Movable.h"
26
35
 
27
36
class Player;
28
37
class Path;
29
38
class Army;
30
39
class XML_Helper;
31
40
 
32
 
/** Group of up to eight armies
33
 
  * 
34
 
  * While armies are the actual troops you command, they always belong to a
35
 
  * stack. The stack holds these armies together in one object. The player
36
 
  * usually doesn't command the armies but the stack, so all functionality and
37
 
  * data which affects player's controls is bundled in the stack class. Among
38
 
  * this is the location of the units, the movement etc.
39
 
  */
 
41
//! A set of up to eight Army units that move as a single entity on the map.
 
42
/** 
 
43
 * While Army units are the actual troops you command, they always belong to a
 
44
 * stack. The stack holds these armies together in one object. The player
 
45
 * usually doesn't command the armies but the stack, so all functionality and
 
46
 * data which affects player's controls is bundled in the stack class. Among
 
47
 * this is the location of the units, the intended movement path, and more.
 
48
 */
40
49
 
41
 
class Stack : public ::Object, public std::list<Army*>, public sigc::trackable
 
50
class Stack : public ::UniquelyIdentified, public Movable, public Ownable, public std::list<Army*>, public sigc::trackable
42
51
{
43
52
    public:
44
 
        /** Default constructor
45
 
          * 
46
 
          * @param player       the owning player or 0 if e.g. ruin keeper
47
 
          * @param pos          the position where the stack is created
48
 
          */
 
53
        /** 
 
54
         * Make a new stack.
 
55
         * 
 
56
         * @param player       A pointer to the owning player.
 
57
         * @param pos          The position on the map where the stack is to 
 
58
         *                     be created.
 
59
         */
 
60
        //! Default constructor.
49
61
        Stack(Player* player, Vector<int> pos);
50
62
 
51
 
        //! Copy constructor, it does a deep copy of the other stack's armies!
 
63
        /**
 
64
         * Copy the whole stack into a new stack.  This method performs a 
 
65
         * deep copy of the stack's Army units.
 
66
         */
 
67
        //! Copy constructor.
52
68
        Stack(Stack& s);
53
69
 
54
 
        //! Loading constructor. See XML_Helper for details
 
70
        //! Loading constructor.
55
71
        Stack(XML_Helper* helper);
 
72
 
 
73
        //! Destructor.
56
74
        ~Stack();
57
75
 
58
 
        
59
 
        //! In rare cases it may be wanted to change the stack's loyality...
 
76
        //! Change the loyalty of the stack.
60
77
        void setPlayer(Player* p);
61
78
 
62
 
        //! ...or its position (for testing reasons)
63
 
        void setPosition(Vector<int> pos){d_pos = pos;}
64
 
 
65
 
        /** Sets the defending value. Defending means that this stack is ignored
66
 
          * when a player cycles through his list of stacks with Stack::setNext().
67
 
          * If a stack stays defending, it gets a fortify bonus.
68
 
          * (this isn't implemented yet) fixme
69
 
          */
 
79
        /** 
 
80
         * Sets the defending value.  Defending entails that this stack is 
 
81
         * ignored when a user cycles through the list of stacks with 
 
82
         * Stacklist::getNextMovable().  If a stack stays defending to the
 
83
         * next round, it gets a fortify bonus in battle.
 
84
         */
 
85
        //! Set the defending status of the stack.
70
86
        void setDefending(bool defending){d_defending = defending;}
71
 
        /** Sets the parked value. Parked means that this stack is ignored
72
 
          * when a player cycles through his list of stacks with Stack::setNext().
73
 
          * this is just like defending, but there's no bonus conferred if 
74
 
          * a stack remains in this state.
75
 
          */
 
87
 
 
88
        /** 
 
89
         * Sets the parked value. Parking entails that this stack is ignored
 
90
         * when a player cycles through his list of stacks with 
 
91
         * Stacklist::getNextMovable().  This value behaves just like 
 
92
         * defending, but there's no bonus conferred if a stack remains in 
 
93
         * this state.
 
94
         */
 
95
        //! Set the parked status of the stack.
76
96
        void setParked(bool parked){d_parked = parked;}
77
97
 
78
 
 
79
 
        //! Save the stack's data. See XML_Helper for more details.
 
98
        //! Save the stack to an opened saved-game file.
80
99
        bool save(XML_Helper* helper) const;
81
100
 
82
 
        //! Heals the armies of the stack etc.
 
101
        /**
 
102
         * When the end of a turn occurs, this callback is used to calculate
 
103
         * stack bonuses, moves, paths, and it also charges the player the
 
104
         * upkeep fee for every Army unit in the Stack.
 
105
         */
 
106
        //! Callback when the end of a turn happens.
83
107
        void nextTurn();
84
108
 
85
 
        //! Reduces movement points of the armies.
 
109
        //! Reduces movement points of the Army units in the Stack.
86
110
        void decrementMoves(Uint32 moves);
87
111
 
88
 
        //! Sets the stack's position to the next item of the internal path
89
 
        bool moveOneStep();
90
 
 
91
 
        //! Blesses all armies of the stack (strength +1)
92
 
        //! Returns the number of blessed armies.
 
112
        //! Sets the stack's position to the next point in it's Path.
 
113
        void moveOneStep();
 
114
 
 
115
        void moveToDest(Vector<int> dest);
 
116
 
 
117
        /**
 
118
         * Adds one to the strength of each Army unit in the stack.
 
119
         * If the Army unit has already visited the temple co-located with
 
120
         * the stack's position, no strength bonus will be added.
 
121
         *
 
122
         * @return The number of Army units blessed.
 
123
         */
 
124
        //! Bless the Army units in the stack.
93
125
        int bless();
94
126
 
95
 
        //! Returns whether the stack has enough moves for the next step
 
127
        /**
 
128
         * @return True if the stack has enough moves to traverse to
 
129
         * the next step in it's Path.  Otherwise, false.
 
130
         */
 
131
        //! Returns whether or not the stack can move.
96
132
        bool enoughMoves() const;
97
133
 
98
 
        // returns whether the stack can move in any direction
 
134
        /**
 
135
         * @return Whether or not the stack has enough moves to travel to
 
136
         *         an adjacent tile.  The adjacent tile does not have to be
 
137
         *         in the stack's Path.
 
138
         */
 
139
        //! Returns whether the stack can move in any direction.
99
140
        bool canMove() const;
100
141
        
101
 
        //! Returns the owning player
102
 
        Player* getPlayer() const {return d_player;}
103
 
 
104
 
        //! Returns the internal path object of the stack
 
142
        //! Returns the Path object of the stack.
105
143
        Path* getPath() const {return d_path;}
106
144
 
107
 
        //! Returns the minimum number of MP of all armies
 
145
        //! Returns the minimum number of movement points of all Army units.
108
146
        Uint32 getGroupMoves() const;
109
147
 
110
 
        //! Returns true if all armies in the stack are grouped
 
148
        //! Returns true if all Army units in the stack are grouped.
111
149
        bool isGrouped();
112
150
 
113
 
        //! Returns the minimum number of MP of all tiles around the stack, or
114
 
        // -1 if the stack can't move
 
151
        /**
 
152
         * Scan all adjacent tiles relative to the stack's position and 
 
153
         * see how much a move would cost in terms of movement points.
 
154
         * Determine the minimum amount of movement points to make a move.
 
155
         * 
 
156
         * @return The minimum number of movement points to travel to the
 
157
         *         cheapest adjacent tile that the stack can afford to
 
158
         *         move to.  If the stack cannot afford to move there, this
 
159
         *         method returns -1.
 
160
         */
115
161
        int getMinTileMoves() const;
116
162
 
117
 
        //! Get the next item of the stack's path
 
163
        //! Get the next position in the stack's intended Path.
118
164
        Vector<int> nextStep();
119
165
 
120
 
        //! Get the strongest army (most strength) for displaying
 
166
        //! Return the Army unit in the Stack that has the best strength value.
121
167
        Army* getStrongestArmy() const;
122
168
 
123
 
        //! Get the strongest hero (most strength) for bonus calculations
 
169
        //! Return the Hero unit in the Stack that has the best strength value.
124
170
        Army* getStrongestHero() const;
125
 
        // FIXME: reconcile these "strongest" functions into one
126
171
 
127
 
        //! Used for splitting stacks. See Player::stackSplit how it works.
 
172
        /**
 
173
         * Scan through the Army units in the stack and return the first
 
174
         * one that is ungrouped.  This method is used for splitting stacks.  
 
175
         * See Player::stackSplit for more information.
 
176
         *
 
177
         * @return A pointer to the first ungrouped army in the stack or NULL
 
178
         *         if an ungrouped Army unit could not be found.
 
179
         */
 
180
        //! Get the first ungrouped Army unit in the Stack.
128
181
        Army* getFirstUngroupedArmy() const;
129
182
 
130
 
        //! True if the stack has a hero. They add strength to the other armies.
 
183
        Army* getArmyById(Uint32 id) const;
 
184
        
 
185
        //! True if the stack contains a Hero unit.  Otherwise, false.
131
186
        bool hasHero() const;
132
187
 
133
 
        //! Return the first hero in the stack
 
188
        //! Return the first Hero unit in the stack, or NULL if no Hero found.
134
189
        Army* getFirstHero() const;
135
190
 
136
191
        //! Returns the ids of all (living) heroes in the stack in the dst reference
 
192
        /**
 
193
         * Scan the Army units in the Stack for heroes that have more than
 
194
         * zero hitpoints.
 
195
         *
 
196
         * @param dst       Passed in as an empty or non-empty list, and
 
197
         *                  filled up with the Ids belonging to Hero army 
 
198
         *                  units in the stack.
 
199
         */
 
200
        // Return the Ids of all of the Hero units in the Stack.
137
201
        void getHeroes(std::vector<Uint32>& dst) const;
138
202
 
139
 
        //! Return true if the stack belongs to player or his allies
140
 
        bool isFriend(Player* player) const;
141
 
 
142
 
        //! Return the defending status of the stack (see setDefending)
 
203
        //! Return the defending status of the stack.
143
204
        bool getDefending() const {return d_defending;}
144
 
        //! Return the parked status of the stack (see setParked)
 
205
 
 
206
        //! Return the parked status of the stack.
145
207
        bool getParked() const {return d_parked;}
146
208
 
147
 
        //! Returns whether the stack is being deleted (set to true in the destructor)
 
209
        //! Returns whether the stack is being deleted.
148
210
        bool getDeleting() const {return d_deleting;}
149
211
 
150
 
        //! Return the maximum sight of the stack
 
212
        //! Return the maximum sight of the stack.
151
213
        Uint32 getMaxSight() const;
152
214
 
153
 
 
154
 
        //! The same as std::list::clear, but alse frees pointers
 
215
        //! Erase the stack, deleting the Army units too.
155
216
        void flClear();
156
217
 
157
 
        //! The same as std::list::erase, but also frees pointers
 
218
        /** 
 
219
         * Erase an Army unit from the Stack, and free the contents of 
 
220
         * the Army unit too (e.g. Items a Hero might be carrying).
 
221
         *
 
222
         * @param it   The place in the Stack to erase.
 
223
         *
 
224
         * @return The place in the stack that was erased.
 
225
         */
 
226
        //! Erase an Army unit from the list.
158
227
        iterator flErase(iterator object);
159
228
 
160
 
       /** Calculates group move bonuses.
161
 
          *
162
 
          */
 
229
       /** 
 
230
        * Determine which terrain kinds (Tile::Type) the Stack can travel 
 
231
        * efficiently on.  When one Army unit is good at traveling through 
 
232
        * the forest, and another in the same stack is good at traveling 
 
233
        * through the hills, the movement capabilities of each individual 
 
234
        * army is given to the other Army units in the Stack.  This means 
 
235
        * the whole stack can move well through hills and forest.
 
236
        * Traveling efficently on a tile means it takes 2 movement points
 
237
        * to traverse.
 
238
        *
 
239
        * The calculation also takes into account a movement-changing Item
 
240
        * that the Hero may be carrying (e.g. `Wings of Flying', or 
 
241
        * `Swamp Boots').
 
242
        *
 
243
        * This calculation also lets Hero units `ride' flying Army units;
 
244
        * meaning that the Hero doesn't have the ability to fly, but it
 
245
        * has the special ability to ride on the back of another flying
 
246
        * Army unit.
 
247
        *
 
248
        * @return A bitwise OR-ing of the values in Tile::Type.
 
249
        */
 
250
        //! Calculate the move bonus for the Stack.
163
251
        Uint32 calculateMoveBonus() const;
 
252
 
 
253
        //! Calculate if the Stack has the gift of flight.
164
254
        bool isFlying () const;
 
255
 
 
256
        //! Calculate if the Stack is in a boat.
165
257
        bool hasShip () const;
166
258
 
167
 
        //! how much does it cost in movement points for the stack
168
 
        //to move to move onto a tile that has the characteristics of the
169
 
        //tile located at POS. (this is not a distance calculation)
 
259
        /**
 
260
         * Calculate the number of movement points it costs for the Stack
 
261
         * to move to an adjacent tile.
 
262
         *
 
263
         * @note This is not a distance calculation.
 
264
         *
 
265
         * @param pos    The adjacent tile to calculate the movement points for.
 
266
         *
 
267
         * @return The number of movement points, or -1 if moving to the
 
268
         *         adjacent tile is impossible.
 
269
         */
 
270
        //! Return the movement points it costs to travel to an adjacent tile.
170
271
        Uint32 calculateTileMovementCost(Vector<int> pos) const;
171
272
 
172
 
        sigc::signal<void, Stack*> sdying;
173
 
 
 
273
        //! Set each Army unit in the Stack to a grouped state.
174
274
        void group();
 
275
 
 
276
        //! Set all armies in the Stack except the first one to be ungrouped.
175
277
        void ungroup();
 
278
 
 
279
        /**
 
280
         * Alter the order of the Army units in the stack according to each
 
281
         * unit's groupedness, and fight order.
 
282
         *
 
283
         * The purpose of this sorting is to show the units in the stack
 
284
         * info window.
 
285
         *
 
286
         * @param reverse     Invert the sort.
 
287
         */
 
288
        //! Sort the Army units in the stack.
176
289
        void sortForViewing(bool reverse);
 
290
 
 
291
        //! Set all Army units in the stack to have this fortified state.
177
292
        void setFortified(bool fortified);
 
293
 
 
294
        //! Return true if any of the Army units in the stack are fortified.
178
295
        bool getFortified();
 
296
        
 
297
        //! Calculate the number of gold pieces this stack costs this turn.
179
298
        Uint32 getUpkeep();
180
299
        
181
 
        static bool armyCompareFightOrder (const Army *, const Army *);
182
 
        Uint32 getMovesExhaustedAtPoint() {return d_moves_exhausted_at_point;}
183
 
        void setMovesExhaustedAtPoint(Uint32 index) {d_moves_exhausted_at_point = index;}
 
300
        /**
 
301
         * This comparator function compares the fight order of two Army units.
 
302
         *
 
303
         * @param left    An army that we want to sort by fight order.
 
304
         * @param right   An army that we want to sort by fight order.
 
305
         *
 
306
         * @return True if the fight order of the left army is more than
 
307
         *         the fight order of the right army.
 
308
         */
 
309
        //! Comparator function to assist in sorting the armies in the stack.
 
310
        static bool armyCompareFightOrder (const Army *left, const Army *right);
 
311
 
 
312
        //! Emitted when a stack dies.
 
313
        sigc::signal<void, Stack*> sdying;
 
314
 
184
315
    private:    
 
316
 
185
317
        //! Callback for loading the stack
186
318
        bool load(std::string tag, XML_Helper* helper);
187
319
    
 
320
        //! Helper method for returning strongest army.
 
321
        Army* getStrongestArmy(bool hero) const;
 
322
 
188
323
        // DATA
189
 
        Player* d_player;
 
324
        //! The stack's intended path.
190
325
        Path* d_path;
 
326
        //! Whether or not the stack is defending.
191
327
        bool d_defending;
 
328
        //! Whether or not the stack is parked.
192
329
        bool d_parked;
193
330
        
194
 
        // true if the stack is currently being deleted. This is neccessary as
195
 
        // some things may happen in the destructor of the contained armies and
196
 
        // we don't want bigmap to draw the stack when it is being removed.
 
331
        /**
 
332
         * True if the stack is currently being deleted. This is neccessary as
 
333
         * some things may happen in the destructor of the contained armies and
 
334
         * we don't want bigmap to draw the stack when it is being removed.
 
335
         */
 
336
        //! Whether or not this stack is in the midst of being deleted.
197
337
        bool d_deleting;
198
 
        Uint32 d_moves_exhausted_at_point;
199
338
};
200
339
 
201
340
#endif // STACK_H