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 public:
76  Unit(const std::string &type);
78  ~Unit();
80  void load(const YAML::Node& node, Mod *mod);
82  std::string getType() const;
84  UnitStats *getStats();
86  int getStandHeight() const;
88  int getKneelHeight() const;
90  int getFloatHeight() const;
92  std::string getArmor() const;
94  std::string getRace() const;
96  std::string getRank() const;
98  int getValue() const;
100  const std::vector<int> &getDeathSounds() const;
102  int getMoveSound() const;
104  int getIntelligence() const;
106  int getAggression() const;
108  int getSpecialAbility() const;
110  std::string getSpawnUnit() const;
112  int getAggroSound() const;
114  int getEnergyRecovery() const;
116  bool isLivingWeapon() const;
118  std::string getMeleeWeapon() const;
120  std::string getPsiWeapon() const;
122  const std::vector<std::vector<std::string> > &getBuiltInWeapons() const;
123 };
124 
125 }
126 
127 namespace YAML
128 {
129  template<>
130  struct convert<OpenXcom::UnitStats>
131  {
132  static Node encode(const OpenXcom::UnitStats& rhs)
133  {
134  Node node;
135  node["tu"] = rhs.tu;
136  node["stamina"] = rhs.stamina;
137  node["health"] = rhs.health;
138  node["bravery"] = rhs.bravery;
139  node["reactions"] = rhs.reactions;
140  node["firing"] = rhs.firing;
141  node["throwing"] = rhs.throwing;
142  node["strength"] = rhs.strength;
143  node["psiStrength"] = rhs.psiStrength;
144  node["psiSkill"] = rhs.psiSkill;
145  node["melee"] = rhs.melee;
146  return node;
147  }
148 
149  static bool decode(const Node& node, OpenXcom::UnitStats& rhs)
150  {
151  if (!node.IsMap())
152  return false;
153 
154  rhs.tu = node["tu"].as<int>(rhs.tu);
155  rhs.stamina = node["stamina"].as<int>(rhs.stamina);
156  rhs.health = node["health"].as<int>(rhs.health);
157  rhs.bravery = node["bravery"].as<int>(rhs.bravery);
158  rhs.reactions = node["reactions"].as<int>(rhs.reactions);
159  rhs.firing = node["firing"].as<int>(rhs.firing);
160  rhs.throwing = node["throwing"].as<int>(rhs.throwing);
161  rhs.strength = node["strength"].as<int>(rhs.strength);
162  rhs.psiStrength = node["psiStrength"].as<int>(rhs.psiStrength);
163  rhs.psiSkill = node["psiSkill"].as<int>(rhs.psiSkill);
164  rhs.melee = node["melee"].as<int>(rhs.melee);
165  return true;
166  }
167  };
168 }
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
Definition: Position.h:88
This struct holds some plain unit attribute data together.
Definition: Unit.h:30
Definition: BaseInfoState.cpp:40
Represents the static data for a unit that is generated on the battlescape, this includes: HWPs...
Definition: Unit.h:57