OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Unit.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_UNIT_H
20 #define OPENXCOM_UNIT_H
21 
22 #include <string>
23 #include <yaml-cpp/yaml.h>
24 
25 namespace OpenXcom
26 {
27 
28 enum SpecialAbility { SPECAB_NONE = 0, SPECAB_EXPLODEONDEATH, SPECAB_BURNFLOOR, SPECAB_RESPAWN };
32 struct UnitStats
33 {
34  int tu, stamina, health, bravery, reactions, firing, throwing, strength, psiStrength, psiSkill, melee;
35 public:
36  UnitStats() : tu(0), stamina(0), health(0), bravery(0), reactions(0), firing(0), throwing(0), strength(0), psiStrength(0), psiSkill(0), melee(0) {};
37  UnitStats(int tu_, int stamina_, int health_, int bravery_, int reactions_, int firing_, int throwing_, int strength_, int psiStrength_, int psiSkill_, int melee_) : tu(tu_), stamina(stamina_), health(health_), bravery(bravery_), reactions(reactions_), firing(firing_), throwing(throwing_), strength(strength_), psiStrength(psiStrength_), psiSkill(psiSkill_), melee(melee_) {};
38  UnitStats& operator+=(const UnitStats& stats) { tu += stats.tu; stamina += stats.stamina; health += stats.health; bravery += stats.bravery; reactions += stats.reactions; firing += stats.firing; throwing += stats.throwing; strength += stats.strength; psiStrength += stats.psiStrength; psiSkill += stats.psiSkill; melee += stats.melee; return *this; }
39  UnitStats operator+(const UnitStats& stats) const { return UnitStats(tu + stats.tu, stamina + stats.stamina, health + stats.health, bravery + stats.bravery, reactions + stats.reactions, firing + stats.firing, throwing + stats.throwing, strength + stats.strength, psiStrength + stats.psiStrength, psiSkill + stats.psiSkill, melee + stats.melee); }
40  UnitStats& operator-=(const UnitStats& stats) { tu -= stats.tu; stamina -= stats.stamina; health -= stats.health; bravery -= stats.bravery; reactions -= stats.reactions; firing -= stats.firing; throwing -= stats.throwing; strength -= stats.strength; psiStrength -= stats.psiStrength; psiSkill -= stats.psiSkill; melee -= stats.melee; return *this; }
41  UnitStats operator-(const UnitStats& stats) const { return UnitStats(tu - stats.tu, stamina - stats.stamina, health - stats.health, bravery - stats.bravery, reactions - stats.reactions, firing - stats.firing, throwing - stats.throwing, strength - stats.strength, psiStrength - stats.psiStrength, psiSkill - stats.psiSkill, melee - stats.melee); }
42  UnitStats operator-() const { return UnitStats(-tu, -stamina, -health, -bravery, -reactions, -firing, -throwing, -strength, -psiStrength, -psiSkill, -melee); }
43  void merge(const UnitStats& stats) { tu = (stats.tu ? stats.tu : tu); stamina = (stats.stamina ? stats.stamina : stamina); health = (stats.health ? stats.health : health); bravery = (stats.bravery ? stats.bravery : bravery); reactions = (stats.reactions ? stats.reactions : reactions); firing = (stats.firing ? stats.firing : firing); throwing = (stats.throwing ? stats.throwing : throwing); strength = (stats.strength ? stats.strength : strength); psiStrength = (stats.psiStrength ? stats.psiStrength : psiStrength); psiSkill = (stats.psiSkill ? stats.psiSkill : psiSkill); melee = (stats.melee ? stats.melee : melee); };
44 };
45 
50 class Unit
51 {
52 private:
53  std::string _type;
54  std::string _race;
55  std::string _rank;
56  UnitStats _stats;
57  std::string _armor;
58  int _standHeight, _kneelHeight, _floatHeight;
59  int _value, _deathSound, _aggroSound, _moveSound;
60  int _intelligence, _aggression, _energyRecovery;
61  SpecialAbility _specab;
62  std::string _spawnUnit;
63  bool _livingWeapon;
64 public:
66  Unit(const std::string &type);
68  ~Unit();
70  void load(const YAML::Node& node, int modIndex);
72  std::string getType() const;
76  int getStandHeight() const;
78  int getKneelHeight() const;
80  int getFloatHeight() const;
82  std::string getArmor() const;
84  std::string getRace() const;
86  std::string getRank() const;
88  int getValue() const;
90  int getDeathSound() const;
92  int getMoveSound() const;
94  int getIntelligence() const;
96  int getAggression() const;
98  int getSpecialAbility() const;
100  std::string getSpawnUnit() const;
102  int getAggroSound() const;
104  bool isLivingWeapon() const;
105  int getEnergyRecovery() const;
106 };
107 
108 }
109 
110 namespace YAML
111 {
112  template<>
113  struct convert<OpenXcom::UnitStats>
114  {
115  static Node encode(const OpenXcom::UnitStats& rhs)
116  {
117  Node node;
118  node["tu"] = rhs.tu;
119  node["stamina"] = rhs.stamina;
120  node["health"] = rhs.health;
121  node["bravery"] = rhs.bravery;
122  node["reactions"] = rhs.reactions;
123  node["firing"] = rhs.firing;
124  node["throwing"] = rhs.throwing;
125  node["strength"] = rhs.strength;
126  node["psiStrength"] = rhs.psiStrength;
127  node["psiSkill"] = rhs.psiSkill;
128  node["melee"] = rhs.melee;
129  return node;
130  }
131 
132  static bool decode(const Node& node, OpenXcom::UnitStats& rhs)
133  {
134  if (!node.IsMap())
135  return false;
136 
137  rhs.tu = node["tu"].as<int>(rhs.tu);
138  rhs.stamina = node["stamina"].as<int>(rhs.stamina);
139  rhs.health = node["health"].as<int>(rhs.health);
140  rhs.bravery = node["bravery"].as<int>(rhs.bravery);
141  rhs.reactions = node["reactions"].as<int>(rhs.reactions);
142  rhs.firing = node["firing"].as<int>(rhs.firing);
143  rhs.throwing = node["throwing"].as<int>(rhs.throwing);
144  rhs.strength = node["strength"].as<int>(rhs.strength);
145  rhs.psiStrength = node["psiStrength"].as<int>(rhs.psiStrength);
146  rhs.psiSkill = node["psiSkill"].as<int>(rhs.psiSkill);
147  rhs.melee = node["melee"].as<int>(rhs.melee);
148  return true;
149  }
150  };
151 }
152 
153 #endif
void load(const YAML::Node &node, int modIndex)
Loads the unit data from YAML.
Definition: Unit.cpp:47
int getIntelligence() const
Gets the intelligence. This is the number of turns AI remembers your troop positions.
Definition: Unit.cpp:192
Unit(const std::string &type)
Creates a blank unit ruleset.
Definition: Unit.cpp:28
int getValue() const
Gets the value - for score calculation.
Definition: Unit.cpp:165
int getAggroSound() const
Gets the unit's war cry.
Definition: Unit.cpp:228
int getAggression() const
Gets the aggression. Determines the chance of revenge and taking cover.
Definition: Unit.cpp:201
std::string getSpawnUnit() const
Gets the unit's spawn unit.
Definition: Unit.cpp:219
std::string getRank() const
Gets the alien rank.
Definition: Unit.cpp:156
std::string getRace() const
Gets the alien race type.
Definition: Unit.cpp:147
~Unit()
Cleans up the unit ruleset.
Definition: Unit.cpp:37
This struct holds some plain unit attribute data together.
Definition: Unit.h:32
std::string getArmor() const
Gets the armor type.
Definition: Unit.cpp:138
int getFloatHeight() const
Gets the unit's float elevation.
Definition: Unit.cpp:129
int getDeathSound() const
Gets the death sound id.
Definition: Unit.cpp:174
bool isLivingWeapon() const
Checks if this unit has a built in weapon.
Definition: Unit.cpp:237
int getSpecialAbility() const
Gets the alien's special ability.
Definition: Unit.cpp:210
UnitStats * getStats()
Gets the unit's stats.
Definition: Unit.cpp:102
int getMoveSound() const
Gets the move sound id.
Definition: Unit.cpp:183
int getStandHeight() const
Gets the unit's height when standing.
Definition: Unit.cpp:111
std::string getType() const
Gets the unit's type.
Definition: Unit.cpp:93
int getKneelHeight() const
Gets the unit's height when kneeling.
Definition: Unit.cpp:120
Represents the static data for a unit that is generated on the battlescape, this includes: HWPs...
Definition: Unit.h:50