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

« back to all changes in this revision

Viewing changes to src/stacklist.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, 2002, 2003 Michael Bartl
 
2
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
 
3
// Copyright (C) 2004, 2005 Andrea Paternesi
 
4
// Copyright (C) 2004 Andrea Paternesi
 
5
// Copyright (C) 2007, 2008 Ben Asselstine
 
6
// Copyright (C) 2008 Ole Laursen
 
7
//
1
8
//  This program is free software; you can redistribute it and/or modify
2
9
//  it under the terms of the GNU General Public License as published by
3
10
//  the Free Software Foundation; either version 2 of the License, or
10
17
//
11
18
//  You should have received a copy of the GNU General Public License
12
19
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
21
//  02110-1301, USA.
14
22
 
15
23
#ifndef STACKLIST_H
16
24
#define STACKLIST_H
26
34
class Stack;
27
35
class XML_Helper;
28
36
 
29
 
/** List of stacks of a single player
30
 
  *
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
34
 
  * of a city etc.
35
 
  */
 
37
//! A list of Stack objects for a single player.
 
38
/** 
 
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.
 
42
 */
36
43
 
37
44
class Stacklist : public std::list<Stack*>, public sigc::trackable
38
45
{
39
46
    public:
 
47
        //! Default constructor.
40
48
        Stacklist();
 
49
        //! Copy constructor.
41
50
        Stacklist(Stacklist *stacklist);
 
51
        //! Loading constructor.
42
52
        Stacklist(XML_Helper* helper);
 
53
        //! Destructor.
43
54
        ~Stacklist();
44
55
 
45
 
 
46
 
        //! Return the stack at position (x,y) or 0 if there is none
 
56
        /**
 
57
         * Scan through every player's Stacklist, for a stack that is located 
 
58
         * at the given position on the game map.
 
59
         *
 
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.
 
64
         *
 
65
         * @return A pointer to a stack at the given position, or NULL if no
 
66
         *         Stack could be found.
 
67
         */
 
68
        //! Return the stack at position (x,y) or 0 if there is none.
47
69
        static Stack* getObjectAt(int x, int y);
48
70
 
49
 
        //! Return stack at position pos or 0 if there is none
50
 
        static Stack* getObjectAt(Vector<int> point);
 
71
        /**
 
72
         * Scan through every player's Stacklist, for a stack that is located 
 
73
         * at the given position on the game map.
 
74
         *
 
75
         * @param point    The point on the map that we're looking to see
 
76
         *                 if there is a Stack on.
 
77
         *
 
78
         * @return A pointer to a stack at the given position, or NULL if no
 
79
         *         Stack could be found.
 
80
         */
 
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);}
51
84
 
52
 
        //! Return position of an army
 
85
        /**
 
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.
 
88
         *
 
89
         * @param id     The Id of the Army unit that we're looking for.
 
90
         *
 
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
 
93
         *         returned.
 
94
         */
 
95
        //! Return position of an Army.
53
96
        static Vector<int> getPosition(Uint32 id);
54
97
 
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.
61
 
          *
62
 
          * @param s        the stack which we search an ambiguity for
63
 
          */
64
 
        static Stack* getAmbiguity(Stack* s);
65
 
 
66
 
        //! Searches through the player's lists and deletes the stack
67
 
        static void deleteStack(Stack* s);
68
 
 
69
 
        /** Returns stacks defending a city
70
 
          *
71
 
          * If a city is attacked, all stacks which occupy a city tile are
72
 
          * regarded as defenders.
73
 
          *
74
 
          * @param c        the city under attack
75
 
          * @return a list of all stacks defending the city
76
 
          */
77
 
        static std::vector<Stack*> defendersInCity(City* c);
78
 
 
79
 
        //! Returns the number of stacks owned by all players
 
98
        /** 
 
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.
 
105
         *
 
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.
 
109
         *
 
110
         * @param stack        The stack which we search an ambiguity for.
 
111
         *
 
112
         * @return The other stack on the same tile occupied by stack.
 
113
         */
 
114
        //! Get the other stack on a tile that has more than one stack on it.
 
115
        static Stack* getAmbiguity(Stack* stack);
 
116
 
 
117
        //! Searches through the all players Stacklists and deletes the stack.
 
118
        static void deleteStack(Stack* stack);
 
119
 
 
120
        /** 
 
121
         * Scan each tile occupied by the given city and return a list of
 
122
         * stacks who are in the city.
 
123
         *
 
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.
 
127
         *
 
128
         * @param city        The city to search for stacks in.
 
129
         *
 
130
         * @return A list of all stacks defending the city.
 
131
         */
 
132
        //! Return a list of stacks defending a city.
 
133
        static std::vector<Stack*> defendersInCity(City* city);
 
134
 
 
135
        //! Returns the total number of stacks owned by all players.
80
136
        static unsigned int getNoOfStacks();
81
137
 
82
 
        //! Returns the number of armies in the list
 
138
        //! Returns the total number of armies in the list.
83
139
        unsigned int countArmies();
84
140
 
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
89
 
          *
90
 
          * @param activestack      the stack currently moved by the player
91
 
          */
 
141
        /** 
 
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.
 
146
         *
 
147
         * @param activestack      The stack currently selected by the player.
 
148
         */
92
149
        void setActivestack(Stack* activestack) {d_activestack = activestack;}
93
150
 
94
 
        //! Get the next non-defending stack that can move.
 
151
        /**
 
152
         * Scan through the list of stacks to find one that is not defending, 
 
153
         * and not parked, and can move to another tile.
 
154
         *
 
155
         * @return A pointer to the next moveable stack or NULL if no more
 
156
         *         stacks can move.
 
157
         */
 
158
        //! Return the next moveable stack in the list.
95
159
        Stack* getNextMovable();
96
160
 
97
 
        //! Returns true if s and d can form one stack (esp. regarding size)
98
 
        bool canJoin(Stack* s, Stack* d) const;
99
 
 
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;
102
163
 
103
 
        //! Calls nextTurn of each stack in the list (for healing, upkeep etc.)
 
164
        //! Callback method executed at the end of every turn.
104
165
        void nextTurn();
105
166
 
106
 
        //! Returns true if _any_ of the stacks has enough moves for its next step
 
167
        /**
 
168
         * @return True if any stacks in the list have enough moves for 
 
169
         * it's next step along it's Path.  Otherwise, false.
 
170
         */
 
171
        //! Returns whether or not any stacks can move.
107
172
        bool enoughMoves() const;
108
173
 
109
 
        //! Returns the designated activestack
 
174
        //! Returns the currently selected stack.
110
175
        Stack* getActivestack() const {return d_activestack;}
111
176
 
112
 
 
113
 
        //! Behaves like std::list::clear(), but frees pointers as well
 
177
        //! Erase all stacks from the list, and their contents too.
114
178
        void flClear();
115
179
 
116
 
        //! Behaves like std::list::erase(), but frees pointers as well
 
180
        /** 
 
181
         * Erase a Stack from the list, and free the contents of the Stack.
 
182
         *
 
183
         * @param it   The place in the Stacklist to erase.
 
184
         *
 
185
         * @return The place in the list that was erased.
 
186
         */
 
187
        //! Erase a stack from the list.
117
188
        iterator flErase(iterator object);
118
189
 
119
 
        //! Behaves like std::list::remove(), but frees pointers as well
120
 
        bool flRemove(Stack* object);
 
190
        /** 
 
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.
 
193
         *
 
194
         * @param stack  The stack in the Stacklist to remove.
 
195
         *
 
196
         * @return Whether or not the stack was found and deleted.
 
197
         */
 
198
        //! Erase a stack from the list.
 
199
        bool flRemove(Stack* stack);
121
200
 
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.
 
201
        /**
 
202
         * Scan through the Stacklist, for a stack that is located at the 
 
203
         * given position on the game map.
 
204
         *
 
205
         * @note This method works only on this Stacklist, rather than all
 
206
         *       of the players Stacklists as in Stacklist::getObjectAt.
 
207
         *
 
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.
 
212
         *
 
213
         * @return A pointer to a stack at the given position, or NULL if no
 
214
         *         Stack could be found.
 
215
         */
 
216
        //! Return the stack at position (x,y) or 0 if there is none.
124
217
        Stack* getOwnObjectAt(int x, int y);
125
218
 
 
219
        Stack *getStackById(Uint32 id);
 
220
        Stack *getArmyStackById(Uint32 army);
 
221
 
126
222
    private:
127
 
        //! Callback function for loading
 
223
        //! Callback function for loading.
128
224
        bool load(std::string tag, XML_Helper* helper);
129
225
 
 
226
        //! A pointer to the currently selected Stack.
130
227
        Stack* d_activestack;
131
228
};
132
229