initial commit, lordsawar source, slightly modified
[lordsawar] / src / armybase.h
1 // Copyright (C) 2000, 2001, 2003 Michael Bartl
2 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2004, 2005 Andrea Paternesi
4 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
5 // Copyright (C) 2007, 2008 Ole Laursen
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 3 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU Library General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
20 //  02110-1301, USA.
21
22 #ifndef ARMY_BASE_H
23 #define ARMY_BASE_H
24
25 #include <gtkmm.h>
26 #include <string>
27
28
29 class XML_Helper;
30
31 class ArmyBase
32 {
33     public:
34
35         //! The bitwise OR-able special bonus that the Army gives.
36         enum Bonus {
37           //! Provides +1 strength to the Army when positioned in the open.
38           ADD1STRINOPEN      = 0x00000001,
39           //! Provides +2 strength to the Army when positioned in the open.
40           ADD2STRINOPEN      = 0x00000002,
41           //! Provides +1 strength to the Army when positioned in the forest.
42           ADD1STRINFOREST    = 0x00000004,
43           //! Provides +1 strength to the Army when positioned in the hills.
44           ADD1STRINHILLS     = 0x00000008, 
45           //! Provides +1 strength to the Army when positioned in a City.
46           ADD1STRINCITY      = 0x00000010,
47           //! Provides +2 strength to the Army when positioned in a City.
48           ADD2STRINCITY      = 0x00000020,
49           //! Provides +1 strength to the Stack when positioned in the hills.
50           ADD1STACKINHILLS   = 0x00000040,
51           //! Negate any City bonuses from an enemy Stack during a Fight.
52           SUBALLCITYBONUS    = 0x00000080,
53           //! Negates 1 strength point from an enemy Stack during a Fight.
54           SUB1ENEMYSTACK     = 0x00000100,
55           //! Provides +1 strength to all Army units in the Stack.
56           ADD1STACK          = 0x00000200,
57           //! Provides +2 strength to all Army units in the Stack.
58           ADD2STACK          = 0x00000400,
59           //! Negate all non-Hero bonuses in an enemy Stack during a Fight.
60           SUBALLNONHEROBONUS = 0x00000800,
61           //! Negate all Hero bonuses in an enemy Stack during a Fight.
62           SUBALLHEROBONUS    = 0x00001000, //0 enemy hero bonus
63           //! Provides a +1 strength to all Army units in a fortified Stack.
64           FORTIFY            = 0x00002000,
65         };
66         
67         //! Various kinds of statistics that an instance of Army unit has.
68         /**
69          * This enumeration assists in getting and setting of statistics in
70          * an instance of an Army unit.
71          */
72         enum Stat {
73           //! How strong the Army unit is in battle.
74           STRENGTH = 0,
75           //! The maximum number of hitpoints that the Army unit can have.
76           HP = 3,
77           //! The maximum number of moves the Army unit has.
78           MOVES = 4,
79           //! The various Tile::Type that the Army moves efficiently in.
80           MOVE_BONUS = 5,
81           //! The special bonus the Army has (Army::Bonus).
82           ARMY_BONUS = 6,
83           //! How far the Army unit can see on a hidden map.
84           SIGHT = 7,
85           //! If the Army unit is in a boat or not.
86           SHIP = 8,
87           //! If the Army unit is having it's movement doubled/tripled or not.
88           MOVES_MULTIPLIER = 9,
89         };
90
91         //! Copy constructor.
92         ArmyBase(const ArmyBase& army);
93
94         //! Loading constructor.
95         ArmyBase(XML_Helper* helper);
96         
97         //! Create an empty army base.
98         ArmyBase();
99
100         //! Destructor.
101         virtual ~ArmyBase();
102
103
104         // Set Methods
105         
106         //! Set how much gold this unit requires per turn.
107         void setUpkeep(guint32 upkeep){d_upkeep = upkeep;}
108         
109         //! Set the strength of the army.
110         void setStrength(guint32 strength) {d_strength = strength;}
111
112         //! Set how much XP this unit is worth when killed.
113         void setXpReward(double xp_value){d_xp_value = xp_value;}
114
115
116         // Get Methods
117         
118         //! Returns how many gold pieces this Army needs per turn.
119         guint32 getUpkeep() const {return d_upkeep;}
120         
121
122         //! Get the army bonus of the army.
123         guint32 getArmyBonus() const {return d_army_bonus;}
124
125         //! Get the move bonus.
126         /**
127          * Get which kinds of terrain tiles this Army moves efficiently 
128          * over top of.
129          *
130          * @return A bitwise OR-ing of the values in Tile::Type.
131          */
132         guint32 getMoveBonus() const {return d_move_bonus;}
133
134         //! Get the move bonus of the army.
135         guint32 getMaxMoves() const {return d_max_moves;}
136
137         //! Get the strength of the army.
138         guint32 getStrength() const {return d_strength;}
139
140         //! Get the distance this army can see on a hidden map.
141         /**
142          * As this army walks on the map, it defogs the map with this radius.
143          */
144         guint32 getSight() const {return d_sight;}
145
146         //! Gets an easy to read string that represents the army's bonuses.
147         std::string getArmyBonusDescription() const;
148
149         //! Returns the number of XP that killing this Army garners it's killer.
150         double getXpReward() const {return d_xp_value;}
151
152         // Static Methods
153
154         //! Convert an ArmyBase::Bonus string to a bitwise OR'd value.
155         /**
156          * Converts a string containing the string representations of one
157          * or more ArmyBase::Bonus values to a bitwise OR'd value of those
158          * ArmyBase::Bonus values.  The terms are separated with a pipe `|'.
159          */
160         static guint32 bonusFlagsFromString(const std::string str);
161
162         //! Convert a series of ArmyBase::Bonus enum values to a string.
163         /**
164          * Converts a bitwise OR'd value that represents many ArmyBase::Bonus
165          * enumerated values into a string, where the terms are separated by a
166          * pipe `|'.
167          */
168         static std::string bonusFlagsToString(const guint32 bonus);
169
170         //! Convert an ArmyBase::Bonus string to it's enum value.
171         /**
172          * Converts a string containing a string representation of an 
173          * ArmyBase::Bonus enumerated value, and converts it to it's enumerated
174          * value.
175          */
176         static ArmyBase::Bonus bonusFlagFromString(const std::string str);
177
178         //! Convert an ArmyBase::Bonus enum value to a string.
179         static std::string bonusFlagToString(const ArmyBase::Bonus bonus);
180
181         //! Convert a Tile::Type string to a bitwise OR'd value.
182         /**
183          * Converts a string containing the string representations of one
184          * or more Tile::Type values to a bitwise OR'd value of those
185          * Tile::Type values.  The terms are separated with a pipe `|'.
186          */
187         static guint32 moveFlagsFromString(const std::string str);
188
189         //! Convert a series of Tile::Type enumerated values to a string.
190         /**
191          * Converts a bitwise OR'd value that represents many Tile::Type
192          * enumerated values into a string, where the terms are separated by a
193          * pipe `|'.
194          */
195         static std::string moveFlagsToString(const guint32 move_bonus);
196
197     protected:
198
199         //! Generic method for saving Army base data.
200         bool saveData(XML_Helper* helper) const;
201
202         //! The amount it costs to maintain this Army unit for this turn.
203         /**
204          * @note The amount is in gold pieces.
205          *
206          * This value does not change during gameplay.
207          *
208          * @note Some special units have an upkeep of 0, but usually this
209          * value is more than zero.
210          */
211         guint32 d_upkeep;
212
213         /**
214          * The strength of the Army unit is the prime factor when 
215          * calculating the outcome of a Fight.  This value should always
216          * be 1 or more, but not exceeding 15.
217          *
218          * This value can permanently increase when the Army unit increases
219          * it's level.
220          *
221          * Temporary increases due to the Army unit being on a certain kind 
222          * of terrain, or because another Army unit has conferred strength 
223          * on it (see Army::Bonus) are not reflected in d_strength.
224          *
225          * This value does not decrease during gameplay.
226          */
227         //! The base strength of the Army unit.
228         guint32 d_strength;
229
230         //! The maximum number of movement points that this Army unit has.
231         /**
232          * This value must always be above 1.  Sane values are above 7.
233          *
234          * This value can be permanently increased when the Army unit 
235          * increases it's level.
236          *
237          * This value does not decrease during gameplay.
238          *
239          * @note When an Army unit is having it's movement doubled, or even
240          * tripled due to a Hero carrying an Item, this value does not 
241          * reflect that doubling or tripling.
242          */
243         guint32 d_max_moves;
244
245         //! How far the Army unit can see on a hidden map.
246         /**
247          * When a stack is moving on a hidden map, a certain number of
248          * tiles get illuminated or unshaded.  d_sight is the radius of
249          * tiles that this Army unit can illuminate.
250          *
251          * This value can be permanently increased when the Army unit 
252          * increases it's level.
253          *
254          * This value does not decrease during gameplay.
255          */
256         guint32 d_sight;
257
258         //! The movement bonus of the Army unit.
259         /**
260          * d_move_bonus represents the terrain tiles that the Army unit
261          * can travel efficiently over.  Traveling efficiently entails
262          * that it only costs 2 movement points to travel over that kind
263          * of terrain, no matter what the actual terrain movement value is.
264          *
265          * The movement bonus is a bitwise OR-ing of the values in 
266          * Tile::Type.
267          *
268          * When each of the members of Tile::Type are included in the
269          * d_move_bonus value, the Army unit is flying.
270          *
271          * This value does not change during gameplay.
272          */
273         guint32 d_move_bonus;
274
275         /**
276          * d_army_bonus represents the special abilities this Army unit has.
277          * The special abilities are enumerated in Army::Bonus.
278          *
279          * The army bonus is a bitwise OR-ing of the values in Army::Bonus.
280          *
281          * This value does not change during gameplay.
282          */
283         //! The special capbilities of the Army unit.
284         guint32 d_army_bonus;
285
286         //! The amount of XP this Army unit worth when killed by an assailant.
287         /**
288          * When this Army unit is killed, d_xp_value is added to the killer's
289          * experience points.
290          *
291          * This value must be over 0.
292          *
293          * This value does not change during gameplay.
294          */
295         double d_xp_value;
296
297
298     private:
299 };
300
301 #endif // ARMY_BASE_H