OpenXcom  1.0
Open-source clone of the original X-Com
Unit.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom 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  * OpenXcom 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 General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <string>
21 #include <vector>
22 #include <yaml-cpp/yaml.h>
23 
24 namespace OpenXcom
25 {
26 enum SpecialAbility { SPECAB_NONE, SPECAB_EXPLODEONDEATH, SPECAB_BURNFLOOR, SPECAB_BURN_AND_EXPLODE };
30 struct UnitStats
31 {
32  int tu, stamina, health, bravery, reactions, firing, throwing, strength, psiStrength, psiSkill, melee;
33 public:
34  UnitStats() : tu(0), stamina(0), health(0), bravery(0), reactions(0), firing(0), throwing(0), strength(0), psiStrength(0), psiSkill(0), melee(0) {};
35  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_) {};
36  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; }
37  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); }
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 { return UnitStats(-tu, -stamina, -health, -bravery, -reactions, -firing, -throwing, -strength, -psiStrength, -psiSkill, -melee); }
41  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); };
42 };
43 
45 {
46  UnitStats statGrowth;
47  int growthMultiplier;
48  double aimAndArmorMultiplier;
49 };
50 
51 class Mod;
52 
57 class Unit
58 {
59 private:
60  std::string _type;
61  std::string _race;
62  std::string _rank;
63  UnitStats _stats;
64  std::string _armor;
65  int _standHeight, _kneelHeight, _floatHeight;
66  std::vector<int> _deathSound;
67  int _value, _aggroSound, _moveSound;
68  int _intelligence, _aggression, _energyRecovery;
69  SpecialAbility _specab;
70  std::string _spawnUnit;
71  bool _livingWeapon;
72  std::string _meleeWeapon, _psiWeapon;
73  std::vector<std::vector<std::string> > _builtInWeapons;
74  bool _capturable;
75 public:
77  Unit(const std::string &type);
79  ~Unit();
81  void load(const YAML::Node& node, Mod *mod);
83  std::string getType() const;
87  int getStandHeight() const;
89  int getKneelHeight() const;
91  int getFloatHeight() const;
93  std::string getArmor() const;
95  std::string getRace() const;
97  std::string getRank() const;
99  int getValue() const;
101  const std::vector<int> &getDeathSounds() const;
103  int getMoveSound() const;
105  int getIntelligence() const;
107  int getAggression() const;
109  int getSpecialAbility() const;
111  std::string getSpawnUnit() const;
113  int getAggroSound() const;
115  int getEnergyRecovery() const;
117  bool isLivingWeapon() const;
119  std::string getMeleeWeapon() const;
121  std::string getPsiWeapon() const;
123  const std::vector<std::vector<std::string> > &getBuiltInWeapons() const;
125  bool getCapturable() const;
126 };
127 
128 }
129 
130 namespace YAML
131 {
132  template<>
133  struct convert<OpenXcom::UnitStats>
134  {
135  static Node encode(const OpenXcom::UnitStats& rhs)
136  {
137  Node node;
138  node["tu"] = rhs.tu;
139  node["stamina"] = rhs.stamina;
140  node["health"] = rhs.health;
141  node["bravery"] = rhs.bravery;
142  node["reactions"] = rhs.reactions;
143  node["firing"] = rhs.firing;
144  node["throwing"] = rhs.throwing;
145  node["strength"] = rhs.strength;
146  node["psiStrength"] = rhs.psiStrength;
147  node["psiSkill"] = rhs.psiSkill;
148  node["melee"] = rhs.melee;
149  return node;
150  }
151 
152  static bool decode(const Node& node, OpenXcom::UnitStats& rhs)
153  {
154  if (!node.IsMap())
155  return false;
156 
157  rhs.tu = node["tu"].as<int>(rhs.tu);
158  rhs.stamina = node["stamina"].as<int>(rhs.stamina);
159  rhs.health = node["health"].as<int>(rhs.health);
160  rhs.bravery = node["bravery"].as<int>(rhs.bravery);
161  rhs.reactions = node["reactions"].as<int>(rhs.reactions);
162  rhs.firing = node["firing"].as<int>(rhs.firing);
163  rhs.throwing = node["throwing"].as<int>(rhs.throwing);
164  rhs.strength = node["strength"].as<int>(rhs.strength);
165  rhs.psiStrength = node["psiStrength"].as<int>(rhs.psiStrength);
166  rhs.psiSkill = node["psiSkill"].as<int>(rhs.psiSkill);
167  rhs.melee = node["melee"].as<int>(rhs.melee);
168  return true;
169  }
170  };
171 }
std::string getPsiWeapon() const
Gets the name of any psi weapon that may be built in to this unit.
Definition: Unit.cpp:279
int getFloatHeight() const
Gets the unit&#39;s float elevation.
Definition: Unit.cpp:142
std::string getRace() const
Gets the alien race type.
Definition: Unit.cpp:160
Unit(const std::string &type)
Creates a blank unit ruleset.
Definition: Unit.cpp:30
int getSpecialAbility() const
Gets the alien&#39;s special ability.
Definition: Unit.cpp:223
Contains all the game-specific static data that never changes throughout the game, like rulesets and resources.
Definition: Mod.h:87
Definition: Unit.h:44
int getEnergyRecovery() const
Gets how much energy this unit recovers per turn.
Definition: Unit.cpp:250
const std::vector< int > & getDeathSounds() const
Gets the death sound id.
Definition: Unit.cpp:187
std::string getType() const
Gets the unit&#39;s type.
Definition: Unit.cpp:106
std::string getArmor() const
Gets the armor type.
Definition: Unit.cpp:151
bool isLivingWeapon() const
Checks if this unit has a built in weapon.
Definition: Unit.cpp:261
const std::vector< std::vector< std::string > > & getBuiltInWeapons() const
Gets a vector of integrated items this unit has available.
Definition: Unit.cpp:292
int getAggression() const
Gets the aggression. Determines the chance of revenge and taking cover.
Definition: Unit.cpp:214
Definition: Position.h:81
int getKneelHeight() const
Gets the unit&#39;s height when kneeling.
Definition: Unit.cpp:133
~Unit()
Cleans up the unit ruleset.
Definition: Unit.cpp:37
void load(const YAML::Node &node, Mod *mod)
Loads the unit data from YAML.
Definition: Unit.cpp:47
This struct holds some plain unit attribute data together.
Definition: Unit.h:30
int getAggroSound() const
Gets the unit&#39;s war cry.
Definition: Unit.cpp:241
std::string getRank() const
Gets the alien rank.
Definition: Unit.cpp:169
int getIntelligence() const
Gets the intelligence. This is the number of turns AI remembers your troop positions.
Definition: Unit.cpp:205
std::string getSpawnUnit() const
Gets the unit&#39;s spawn unit.
Definition: Unit.cpp:232
int getMoveSound() const
Gets the move sound id.
Definition: Unit.cpp:196
bool getCapturable() const
Gets whether the alien can be captured alive.
Definition: Unit.cpp:301
UnitStats * getStats()
Gets the unit&#39;s stats.
Definition: Unit.cpp:115
std::string getMeleeWeapon() const
Gets the name of any melee weapon that may be built in to this unit.
Definition: Unit.cpp:270
int getStandHeight() const
Gets the unit&#39;s height when standing.
Definition: Unit.cpp:124
int getValue() const
Gets the value - for score calculation.
Definition: Unit.cpp:178
Definition: BaseInfoState.cpp:40
Represents the static data for a unit that is generated on the battlescape, this includes: HWPs...
Definition: Unit.h:57