21 #include <yaml-cpp/yaml.h> 22 #include "BattleUnit.h" 23 #include "../Engine/Language.h" 35 std::string type, rank, race, weapon, weaponAmmo;
38 int mission, turn, id;
40 UnitBodyPart bodypart;
46 return turn += mission * 300;
50 bool hostileTurn()
const 52 if ((turn - 1) % 3 == 0)
return true;
57 void setTurn(
int unitTurn, UnitFaction unitFaction)
59 turn = unitTurn * 3 + (int)unitFaction;
63 void load(
const YAML::Node &node)
65 if (
const YAML::Node n = node[
"name"])
69 type = node[
"type"].as<std::string>(type);
70 rank = node[
"rank"].as<std::string>(rank);
71 race = node[
"race"].as<std::string>(race);
72 weapon = node[
"weapon"].as<std::string>(weapon);
73 weaponAmmo = node[
"weaponAmmo"].as<std::string>(weaponAmmo);
74 status = (UnitStatus)node[
"status"].as<int>();
75 faction = (UnitFaction)node[
"faction"].as<int>();
76 mission = node[
"mission"].as<
int>(mission);
77 turn = node[
"turn"].as<
int>(turn);
78 side = (UnitSide)node[
"side"].as<int>();
79 bodypart = (UnitBodyPart)node[
"bodypart"].as<int>();
80 id = node[
"id"].as<
int>(id);
84 YAML::Node save()
const 93 node[
"weapon"] = weapon;
94 node[
"weaponAmmo"] = weaponAmmo;
95 node[
"status"] = (int)status;
96 node[
"faction"] = (int)faction;
97 node[
"mission"] = mission;
99 node[
"side"] = (int)side;
100 node[
"bodypart"] = (int)bodypart;
106 std::string getKillStatusString()
const 110 case STATUS_DEAD:
return "STR_KILLED";
111 case STATUS_UNCONSCIOUS:
return "STR_STUNNED";
112 case STATUS_PANICKING:
return "STR_PANICKED";
113 case STATUS_TURNING:
return "STR_MINDCONTROLLED";
114 default:
return "status error";
119 std::string getUnitStatusString()
const 123 case STATUS_DEAD:
return "STATUS_DEAD";
124 case STATUS_UNCONSCIOUS:
return "STATUS_UNCONSCIOUS";
125 case STATUS_PANICKING:
return "STATUS_PANICKING";
126 case STATUS_TURNING:
return "STATUS_TURNING";
127 default:
return "status error";
132 std::string getUnitFactionString()
const 136 case FACTION_PLAYER:
return "FACTION_PLAYER";
137 case FACTION_HOSTILE:
return "FACTION_HOSTILE";
138 case FACTION_NEUTRAL:
return "FACTION_NEUTRAL";
139 default:
return "faction error";
144 std::string getUnitSideString()
const 148 case SIDE_FRONT:
return "SIDE_FRONT";
149 case SIDE_LEFT:
return "SIDE_LEFT";
150 case SIDE_RIGHT:
return "SIDE_RIGHT";
151 case SIDE_REAR:
return "SIDE_REAR";
152 case SIDE_UNDER:
return "SIDE_UNDER";
153 default:
return "side error";
158 std::string getUnitBodyPartString()
const 162 case BODYPART_HEAD:
return "BODYPART_HEAD";
163 case BODYPART_TORSO:
return "BODYPART_TORSO";
164 case BODYPART_RIGHTARM:
return "BODYPART_RIGHTARM";
165 case BODYPART_LEFTARM:
return "BODYPART_LEFTARM";
166 case BODYPART_RIGHTLEG:
return "BODYPART_RIGHTLEG";
167 case BODYPART_LEFTLEG:
return "BODYPART_LEFTLEG";
168 default:
return "body part error";
173 std::wstring getUnitName(Language *lang)
const 179 else if (!type.empty())
181 return lang->getString(type);
185 std::wostringstream ss;
186 ss << lang->getString(race) << L
" " << lang->getString(rank);
192 void setUnitStats(BattleUnit *unit)
196 if (unit->getGeoscapeSoldier())
198 name = unit->getGeoscapeSoldier()->getName();
202 type = unit->getType();
205 if (unit->getOriginalFaction() == FACTION_PLAYER)
208 if (unit->getGeoscapeSoldier())
210 if (!unit->getGeoscapeSoldier()->getRankString().empty())
212 rank = unit->getGeoscapeSoldier()->getRankString();
216 rank =
"STR_SOLDIER";
218 if (unit->getUnitRules() != 0 && !unit->getUnitRules()->getRace().empty())
220 race = unit->getUnitRules()->getRace();
224 race =
"STR_FRIENDLY";
230 if (unit->getUnitRules() != 0 && !unit->getUnitRules()->getRank().empty())
232 rank = unit->getUnitRules()->getRank();
238 if (unit->getUnitRules() != 0 && !unit->getUnitRules()->getRace().empty())
240 race = unit->getUnitRules()->getRace();
244 race =
"STR_FRIENDLY";
249 else if (unit->getOriginalFaction() == FACTION_HOSTILE)
251 if (unit->getUnitRules() != 0 && !unit->getUnitRules()->getRank().empty())
253 rank = unit->getUnitRules()->getRank();
257 rank =
"STR_LIVE_SOLDIER";
259 if (unit->getUnitRules() != 0 && !unit->getUnitRules()->getRace().empty())
261 race = unit->getUnitRules()->getRace();
265 race =
"STR_HOSTILE";
269 else if (unit->getOriginalFaction() == FACTION_NEUTRAL)
271 if (unit->getUnitRules() != 0 && !unit->getUnitRules()->getRank().empty())
273 rank = unit->getUnitRules()->getRank();
277 rank =
"STR_CIVILIAN";
279 if (unit->getUnitRules() != 0 && !unit->getUnitRules()->getRace().empty())
281 race = unit->getUnitRules()->getRace();
285 race =
"STR_NEUTRAL";
291 rank =
"STR_UNKNOWN";
292 race =
"STR_UNKNOWN";
296 BattleUnitKills(
const YAML::Node& node) { load(node); }
297 BattleUnitKills(): faction(FACTION_HOSTILE), status(STATUS_IGNORE_ME), mission(0), turn(0), id(0), side(SIDE_FRONT), bodypart(BODYPART_HEAD) { }
298 ~BattleUnitKills() { }
310 int shotByFriendlyCounter;
311 int shotFriendlyCounter;
314 int longDistanceHitCounter;
315 int lowAccuracyHitCounter;
316 int shotsFiredCounter;
317 int shotsLandedCounter;
318 std::vector<BattleUnitKills*> kills;
325 int appliedStimulant;
336 for (std::vector<BattleUnitKills*>::const_iterator i = kills.begin(); i != kills.end(); ++i)
338 if ((*i)->id ==
id && (*i)->status == status)
347 bool hasFriendlyFired()
const 349 for (std::vector<BattleUnitKills*>::const_iterator i = kills.begin(); i != kills.end(); ++i)
351 if ((*i)->faction == FACTION_PLAYER)
358 void load(
const YAML::Node& node)
361 if (
const YAML::Node &YAMLkills = node[
"kills"])
363 for (YAML::const_iterator i = YAMLkills.begin(); i != YAMLkills.end(); ++i)
364 kills.push_back(
new BattleUnitKills(*i));
366 shotAtCounter = node[
"shotAtCounter"].as<
int>(shotAtCounter);
367 hitCounter = node[
"hitCounter"].as<
int>(hitCounter);
368 shotByFriendlyCounter = node[
"shotByFriendlyCounter"].as<
int>(shotByFriendlyCounter);
369 shotFriendlyCounter = node[
"shotFriendlyCounter"].as<
int>(shotFriendlyCounter);
370 loneSurvivor = node[
"loneSurvivor"].as<
bool>(loneSurvivor);
371 ironMan = node[
"ironMan"].as<
bool>(ironMan);
372 longDistanceHitCounter = node[
"longDistanceHitCounter"].as<
int>(longDistanceHitCounter);
373 lowAccuracyHitCounter = node[
"lowAccuracyHitCounter"].as<
int>(lowAccuracyHitCounter);
374 shotsFiredCounter = node[
"shotsFiredCounter"].as<
int>(shotsFiredCounter);
375 shotsLandedCounter = node[
"shotsLandedCounter"].as<
int>(shotsLandedCounter);
376 nikeCross = node[
"nikeCross"].as<
bool>(nikeCross);
377 mercyCross = node[
"mercyCross"].as<
bool>(mercyCross);
378 woundsHealed = node[
"woundsHealed"].as<
int>(woundsHealed);
379 appliedStimulant = node[
"appliedStimulant"].as<
int>(appliedStimulant);
380 appliedPainKill = node[
"appliedPainKill"].as<
int>(appliedPainKill);
381 revivedSoldier = node[
"revivedSoldier"].as<
int>(revivedSoldier);
382 martyr = node[
"martyr"].as<
int>(martyr);
383 slaveKills = node[
"slaveKills"].as<
int>(slaveKills);
387 YAML::Node save()
const 393 for (std::vector<BattleUnitKills*>::const_iterator i = kills.begin(); i != kills.end(); ++i)
394 node[
"kills"].push_back((*i)->save());
396 if (shotAtCounter) node[
"shotAtCounter"] = shotAtCounter;
397 if (hitCounter) node[
"hitCounter"] = hitCounter;
398 if (shotByFriendlyCounter) node[
"shotByFriendlyCounter"] = shotByFriendlyCounter;
399 if (shotFriendlyCounter) node[
"shotFriendlyCounter"] = shotFriendlyCounter;
400 if (loneSurvivor) node[
"loneSurvivor"] = loneSurvivor;
401 if (ironMan) node[
"ironMan"] = ironMan;
402 if (longDistanceHitCounter) node[
"longDistanceHitCounter"] = longDistanceHitCounter;
403 if (lowAccuracyHitCounter) node[
"lowAccuracyHitCounter"] = lowAccuracyHitCounter;
404 if (shotsFiredCounter) node[
"shotsFiredCounter"] = shotsFiredCounter;
405 if (shotsLandedCounter) node[
"shotsLandedCounter"] = shotsLandedCounter;
406 if (nikeCross) node[
"nikeCross"] = nikeCross;
407 if (mercyCross) node[
"mercyCross"] = mercyCross;
408 if (woundsHealed) node[
"woundsHealed"] = woundsHealed;
409 if (appliedStimulant) node[
"appliedStimulant"] = appliedStimulant;
410 if (appliedPainKill) node[
"appliedPainKill"] = appliedPainKill;
411 if (revivedSoldier) node[
"revivedSoldier"] = revivedSoldier;
412 if (martyr) node[
"martyr"] = martyr;
413 if (slaveKills) node[
"slaveKills"] = slaveKills;
417 BattleUnitStatistics(
const YAML::Node& node) { load(node); }
418 BattleUnitStatistics() :
wasUnconcious(false), shotAtCounter(0), hitCounter(0), shotByFriendlyCounter(0), shotFriendlyCounter(0), loneSurvivor(false), ironMan(false), longDistanceHitCounter(0), lowAccuracyHitCounter(0), shotsFiredCounter(0), shotsLandedCounter(0), kills(), daysWounded(0), KIA(false), nikeCross(false), mercyCross(false), woundsHealed(0), appliedStimulant(0), appliedPainKill(0), revivedSoldier(0), MIA(false), martyr(0), slaveKills(0) { }
419 ~BattleUnitStatistics() { }
std::wstring name
Variables.
Definition: BattleUnitStatistics.h:34
static std::wstring utf8ToWstr(const std::string &src)
Converts a UTF-8 string to wide-string.
Definition: Language.cpp:217
Container for battle unit kills statistics.
Definition: BattleUnitStatistics.h:31
static std::string wstrToUtf8(const std::wstring &src)
Converts a wide-string to UTF-8.
Definition: Language.cpp:118
int makeTurnUnique()
Functions.
Definition: BattleUnitStatistics.h:44
This struct holds some plain unit attribute data together.
Definition: Unit.h:30
bool wasUnconcious
Variables.
Definition: BattleUnitStatistics.h:307
Container for battle unit statistics.
Definition: BattleUnitStatistics.h:304
bool duplicateEntry(UnitStatus status, int id) const
Functions.
Definition: BattleUnitStatistics.h:334
Definition: BaseInfoState.cpp:40