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 Ben Asselstine
5
// Copyright (C) 2007, 2008 Ole Laursen
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 2 of the License, or
10
// (at your option) any later version.
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.
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
25
#include "ucompose.hpp"
27
#include "xmlhelper.h"
31
//#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<std::endl<<std::flush;}
34
ArmyBase::ArmyBase(const ArmyBase& a)
35
: d_upkeep(a.d_upkeep), d_strength(a.d_strength), d_max_moves(a.d_max_moves),
36
d_sight(a.d_sight), d_move_bonus(a.d_move_bonus),
37
d_army_bonus(a.d_army_bonus), d_xp_value(a.d_xp_value)
43
d_strength(0), d_max_moves(0), d_sight(0),
44
d_move_bonus(0), d_army_bonus(0), d_xp_value(0.0)
48
ArmyBase::ArmyBase(XML_Helper* helper)
50
helper->getData(d_upkeep, "upkeep");
51
std::string move_bonus_str;
52
helper->getData(move_bonus_str, "move_bonus");
53
d_move_bonus = moveFlagsFromString(move_bonus_str);
54
std::string army_bonus_str;
55
helper->getData(army_bonus_str, "army_bonus");
56
d_army_bonus = bonusFlagsFromString(army_bonus_str);
58
helper->getData(d_max_moves, "max_moves");
59
helper->getData(d_strength, "strength");
60
helper->getData(d_sight, "sight");
61
helper->getData(d_xp_value, "expvalue");
68
bool ArmyBase::saveData(XML_Helper* helper) const
71
retval &= helper->saveData("upkeep", d_upkeep);
72
std::string move_bonus_str = moveFlagsToString(d_move_bonus);
73
retval &= helper->saveData("move_bonus", move_bonus_str);
74
std::string army_bonus_str = bonusFlagsToString(d_army_bonus);
75
retval &= helper->saveData("army_bonus", army_bonus_str);
76
retval &= helper->saveData("max_moves", d_max_moves);
77
retval &= helper->saveData("strength", d_strength);
78
retval &= helper->saveData("sight", d_sight);
79
retval &= helper->saveData("expvalue", d_xp_value);
83
std::string ArmyBase::getArmyBonusDescription() const
85
Uint32 bonus = d_army_bonus;
87
if (bonus & ArmyBase::ADD1STRINOPEN)
88
s += String::ucompose(_("%1%2"), s == "" ? " " : "& ",
90
if (bonus & ArmyBase::ADD2STRINOPEN)
91
s += String::ucompose(_("%1%2"), s == "" ? " " : "& ",
93
if (bonus & ArmyBase::ADD1STRINFOREST)
94
s += String::ucompose(_("%1%2"), s == "" ? " " : "& ",
95
_("+1 str in woods"));
96
if (bonus & ArmyBase::ADD1STRINHILLS)
97
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ",
98
_("+1 str in hills"));
99
if (bonus & ArmyBase::ADD1STRINCITY)
100
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ",
101
_("+1 str in city"));
102
if (bonus & ArmyBase::ADD2STRINCITY)
103
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ",
104
_("+2 str in city"));
105
if (bonus & ArmyBase::ADD1STACKINHILLS)
106
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ",
107
_("+1 stack in hills"));
108
if (bonus & ArmyBase::SUBALLCITYBONUS)
109
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ",
110
_("Cancel city bonus"));
111
if (bonus & ArmyBase::SUB1ENEMYSTACK)
112
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ",
113
_("-1 enemy stack"));
114
if (bonus & ArmyBase::ADD1STACK)
115
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ", _("+1 stack"));
116
if (bonus & ArmyBase::ADD2STACK)
117
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ", _("+2 stack"));
118
if (bonus & ArmyBase::SUBALLNONHEROBONUS)
119
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ",
120
_("cancel non-hero"));
121
if (bonus & ArmyBase::SUBALLHEROBONUS)
122
s += String::ucompose(_("%1%2"), s == "" ? " " : " & ",
127
std::string ArmyBase::moveFlagsToString(const Uint32 bonus)
129
std::string move_bonuses;
130
//we don't add grass, because it's always implied.
131
if (bonus & Tile::WATER)
132
move_bonuses += " " + Tile::tileTypeToString(Tile::WATER);
133
if (bonus & Tile::FOREST)
134
move_bonuses += " " + Tile::tileTypeToString(Tile::FOREST);
135
if (bonus & Tile::HILLS)
136
move_bonuses += " " + Tile::tileTypeToString(Tile::HILLS);
137
if (bonus & Tile::MOUNTAIN)
138
move_bonuses += " " + Tile::tileTypeToString(Tile::MOUNTAIN);
139
if (bonus & Tile::SWAMP)
140
move_bonuses += " " + Tile::tileTypeToString(Tile::SWAMP);
141
if (bonus & Tile::VOID)
142
move_bonuses += " " + Tile::tileTypeToString(Tile::VOID);
146
Uint32 ArmyBase::moveFlagsFromString(const std::string str)
149
std::stringstream bonuses;
152
while (bonuses.eof() == false)
156
if (bonus.size() == 0)
158
total += Tile::tileTypeFromString(bonus);
163
std::string ArmyBase::bonusFlagToString(const ArmyBase::Bonus bonus)
167
case ArmyBase::ADD1STRINOPEN:
168
return "ArmyBase::ADD1STRINOPEN";
169
case ArmyBase::ADD2STRINOPEN:
170
return "ArmyBase::ADD2STRINOPEN";
171
case ArmyBase::ADD1STRINFOREST:
172
return "ArmyBase::ADD1STRINFOREST";
173
case ArmyBase::ADD1STRINHILLS:
174
return "ArmyBase::ADD1STRINHILLS";
175
case ArmyBase::ADD1STRINCITY:
176
return "ArmyBase::ADD1STRINCITY";
177
case ArmyBase::ADD2STRINCITY:
178
return "ArmyBase::ADD2STRINCITY";
179
case ArmyBase::ADD1STACKINHILLS:
180
return "ArmyBase::ADD1STACKINHILLS";
181
case ArmyBase::SUBALLCITYBONUS:
182
return "ArmyBase::SUBALLCITYBONUS";
183
case ArmyBase::SUB1ENEMYSTACK:
184
return "ArmyBase::SUB1ENEMYSTACK";
185
case ArmyBase::ADD1STACK:
186
return "ArmyBase::ADD1STACK";
187
case ArmyBase::ADD2STACK:
188
return "ArmyBase::ADD2STACK";
189
case ArmyBase::SUBALLNONHEROBONUS:
190
return "ArmyBase::SUBALLNONHEROBONUS";
191
case ArmyBase::SUBALLHEROBONUS:
192
return "ArmyBase::SUBALLHEROBONUS";
193
case ArmyBase::FORTIFY:
194
return "ArmyBase::FORTIFY";
199
std::string ArmyBase::bonusFlagsToString(const Uint32 bonus)
202
if (bonus & ArmyBase::ADD1STRINOPEN)
203
bonuses += " " + bonusFlagToString(ArmyBase::ADD1STRINOPEN);
204
if (bonus & ArmyBase::ADD2STRINOPEN)
205
bonuses += " " + bonusFlagToString(ArmyBase::ADD2STRINOPEN);
206
if (bonus & ArmyBase::ADD1STRINFOREST)
207
bonuses += " " + bonusFlagToString(ArmyBase::ADD1STRINFOREST);
208
if (bonus & ArmyBase::ADD1STRINHILLS)
209
bonuses += " " + bonusFlagToString(ArmyBase::ADD1STRINHILLS);
210
if (bonus & ArmyBase::ADD1STRINCITY)
211
bonuses += " " + bonusFlagToString(ArmyBase::ADD1STRINCITY);
212
if (bonus & ArmyBase::ADD2STRINCITY)
213
bonuses += " " + bonusFlagToString(ArmyBase::ADD2STRINCITY);
214
if (bonus & ArmyBase::ADD1STACKINHILLS)
215
bonuses += " " + bonusFlagToString(ArmyBase::ADD1STACKINHILLS);
216
if (bonus & ArmyBase::SUBALLCITYBONUS)
217
bonuses += " " + bonusFlagToString(ArmyBase::SUBALLCITYBONUS);
218
if (bonus & ArmyBase::SUB1ENEMYSTACK)
219
bonuses += " " + bonusFlagToString(ArmyBase::SUB1ENEMYSTACK);
220
if (bonus & ArmyBase::ADD1STACK)
221
bonuses += " " + bonusFlagToString(ArmyBase::ADD1STACK);
222
if (bonus & ArmyBase::ADD2STACK)
223
bonuses += " " + bonusFlagToString(ArmyBase::ADD2STACK);
224
if (bonus & ArmyBase::SUBALLNONHEROBONUS)
225
bonuses += " " + bonusFlagToString(ArmyBase::SUBALLNONHEROBONUS);
226
if (bonus & ArmyBase::SUBALLHEROBONUS)
227
bonuses += " " + bonusFlagToString(ArmyBase::SUBALLHEROBONUS);
228
if (bonus & ArmyBase::FORTIFY)
229
bonuses += " " + bonusFlagToString(ArmyBase::FORTIFY);
233
Uint32 ArmyBase::bonusFlagsFromString(const std::string str)
236
std::stringstream bonuses;
239
while (bonuses.eof() == false)
243
if (bonus.size() == 0)
245
total += bonusFlagFromString(bonus);
250
ArmyBase::Bonus ArmyBase::bonusFlagFromString(const std::string str)
252
if (str.size() > 0 && isdigit(str.c_str()[0]))
253
return ArmyBase::Bonus(atoi(str.c_str()));
254
if (str == "ArmyBase::ADD1STRINOPEN")
255
return ArmyBase::ADD1STRINOPEN;
256
else if (str == "ArmyBase::ADD2STRINOPEN")
257
return ArmyBase::ADD2STRINOPEN;
258
else if (str == "ArmyBase::ADD1STRINFOREST")
259
return ArmyBase::ADD1STRINFOREST;
260
else if (str == "ArmyBase::ADD1STRINHILLS")
261
return ArmyBase::ADD1STRINHILLS;
262
else if (str == "ArmyBase::ADD1STRINCITY")
263
return ArmyBase::ADD1STRINCITY;
264
else if (str == "ArmyBase::ADD2STRINCITY")
265
return ArmyBase::ADD2STRINCITY;
266
else if (str == "ArmyBase::ADD1STACKINHILLS")
267
return ArmyBase::ADD1STACKINHILLS;
268
else if (str == "ArmyBase::SUBALLCITYBONUS")
269
return ArmyBase::SUBALLCITYBONUS;
270
else if (str == "ArmyBase::ADD2GOLDPERCITY")
271
return ArmyBase::SUB1ENEMYSTACK;
272
else if (str == "ArmyBase::SUB1ENEMYSTACK")
273
return ArmyBase::ADD1STACK;
274
else if (str == "ArmyBase::ADD1STACK")
275
return ArmyBase::ADD2STACK;
276
else if (str == "ArmyBase::ADD2STACK")
277
return ArmyBase::ADD2STACK;
278
else if (str == "ArmyBase::SUBALLNONHEROBONUS")
279
return ArmyBase::SUBALLNONHEROBONUS;
280
else if (str == "ArmyBase::SUBALLHEROBONUS")
281
return ArmyBase::SUBALLHEROBONUS;
282
return ArmyBase::ADD1STRINOPEN;