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