OpenXcom  1.0
Open-source clone of the original X-Com
Craft.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 "MovingTarget.h"
21 #include <utility>
22 #include <vector>
23 #include <string>
24 
25 namespace OpenXcom
26 {
27 
28 typedef std::pair<std::string, int> CraftId;
29 
30 class RuleCraft;
31 class Base;
32 class Soldier;
33 class CraftWeapon;
34 class ItemContainer;
35 class Mod;
36 class SavedGame;
37 class Vehicle;
38 
45 class Craft : public MovingTarget
46 {
47 private:
48  RuleCraft *_rules;
49  Base *_base;
50  int _fuel, _damage, _interceptionOrder, _takeoff;
51  std::vector<CraftWeapon*> _weapons;
52  ItemContainer *_items;
53  std::vector<Vehicle*> _vehicles;
54  std::string _status;
55  bool _lowFuel, _mission, _inBattlescape, _inDogfight;
56  double _speedMaxRadian;
57 
58  using MovingTarget::load;
59 public:
61  Craft(RuleCraft *rules, Base *base, int id = 0);
63  ~Craft();
65  void load(const YAML::Node& node, const Mod *mod, SavedGame *save);
67  YAML::Node save() const;
69  static CraftId loadId(const YAML::Node &node);
71  std::string getType() const;
73  RuleCraft *getRules() const;
75  void changeRules(RuleCraft *rules);
77  std::string getDefaultName(Language *lang) const;
79  int getMarker() const;
81  Base *getBase() const;
83  void setBase(Base *base, bool move = true);
85  std::string getStatus() const;
87  void setStatus(const std::string &status);
89  std::string getAltitude() const;
91  void setDestination(Target *dest);
93  int getNumWeapons() const;
95  int getNumSoldiers() const;
97  int getNumEquipment() const;
99  int getNumVehicles() const;
101  std::vector<CraftWeapon*> *getWeapons();
105  std::vector<Vehicle*> *getVehicles();
107  int getFuel() const;
109  void setFuel(int fuel);
111  int getFuelPercentage() const;
113  int getDamage() const;
115  void setDamage(int damage);
117  int getDamagePercentage() const;
119  bool getLowFuel() const;
121  void setLowFuel(bool low);
123  bool getMissionComplete() const;
125  void setMissionComplete(bool mission);
127  double getDistanceFromBase() const;
129  int getFuelConsumption() const;
131  int getFuelConsumption(int speed) const;
133  int getFuelLimit() const;
135  int getFuelLimit(Base *base) const;
136 
137  double getBaseRange() const;
139  void returnToBase();
141  bool detect(Target *target) const;
143  bool insideRadarRange(Target *target) const;
145  void think();
147  void checkup();
149  void consumeFuel();
151  void repair();
153  void refuel();
155  std::string rearm(const Mod *mod);
157  void setInBattlescape(bool inbattle);
159  bool isInBattlescape() const;
161  bool isDestroyed() const;
163  int getSpaceAvailable() const;
165  int getSpaceUsed() const;
167  int getVehicleCount(const std::string &vehicle) const;
169  void setInDogfight(const bool inDogfight);
171  bool isInDogfight() const;
173  void setInterceptionOrder(const int order);
175  int getInterceptionOrder() const;
177  CraftId getUniqueId() const;
179  void unload(const Mod *mod);
181  void reuseItem(const std::string &item);
182 };
183 
184 }
std::vector< CraftWeapon * > * getWeapons()
Gets the craft&#39;s weapons.
Definition: Craft.cpp:469
Represents a craft stored in a base.
Definition: Craft.h:45
int getDamagePercentage() const
Gets the craft&#39;s percentage of damage.
Definition: Craft.cpp:559
int getFuelLimit() const
Gets the craft&#39;s minimum fuel limit.
Definition: Craft.cpp:642
int getNumEquipment() const
Gets the craft&#39;s amount of equipment.
Definition: Craft.cpp:449
bool detect(Target *target) const
Checks if a target is detected by the craft&#39;s radar.
Definition: Craft.cpp:743
YAML::Node save() const
Saves the craft to YAML.
Definition: Craft.cpp:216
std::vector< Vehicle * > * getVehicles()
Gets the craft&#39;s vehicles.
Definition: Craft.cpp:488
void setInDogfight(const bool inDogfight)
Sets the craft&#39;s dogfight status.
Definition: Craft.cpp:948
void setInBattlescape(bool inbattle)
Sets the craft&#39;s battlescape status.
Definition: Craft.cpp:872
int getSpaceAvailable() const
Gets the amount of space available inside a craft.
Definition: Craft.cpp:896
ItemContainer * getItems()
Gets the craft&#39;s items.
Definition: Craft.cpp:478
void reuseItem(const std::string &item)
Reuses a base item.
Definition: Craft.cpp:1032
The game data that gets written to disk when the game is saved.
Definition: SavedGame.h:99
Contains all the game-specific static data that never changes throughout the game, like rulesets and resources.
Definition: Mod.h:87
bool isInBattlescape() const
Gets if the craft is in battlescape.
Definition: Craft.cpp:863
void refuel()
Refuels the craft.
Definition: Craft.cpp:795
Craft(RuleCraft *rules, Base *base, int id=0)
Creates a craft of the specified type.
Definition: Craft.cpp:50
int getFuel() const
Gets the craft&#39;s amount of fuel.
Definition: Craft.cpp:498
virtual void load(const YAML::Node &node)
Loads the moving target from YAML.
Definition: MovingTarget.cpp:46
int getNumSoldiers() const
Gets the craft&#39;s amount of soldiers.
Definition: Craft.cpp:428
void consumeFuel()
Consumes the craft&#39;s fuel.
Definition: Craft.cpp:773
~Craft()
Cleans up the craft.
Definition: Craft.cpp:71
int getMarker() const
Gets the craft&#39;s marker sprite.
Definition: Craft.cpp:312
std::string getStatus() const
Gets the craft&#39;s status.
Definition: Craft.cpp:349
int getNumWeapons() const
Gets the craft&#39;s amount of weapons.
Definition: Craft.cpp:403
double getDistanceFromBase() const
Gets the craft&#39;s distance from its base.
Definition: Craft.cpp:609
Base * getBase() const
Gets the craft&#39;s base.
Definition: Craft.cpp:325
Contains strings used throughout the game for localization.
Definition: Language.h:39
static CraftId loadId(const YAML::Node &node)
Loads a craft ID from YAML.
Definition: Craft.cpp:259
int getDamage() const
Gets the craft&#39;s amount of damage.
Definition: Craft.cpp:535
double getBaseRange() const
Returns the maximum range the craft can travel from its origin base on its current fuel...
Definition: Craft.cpp:663
int getSpaceUsed() const
Gets the amount of space used inside a craft.
Definition: Craft.cpp:906
void setFuel(int fuel)
Sets the craft&#39;s amount of fuel.
Definition: Craft.cpp:508
void setStatus(const std::string &status)
Sets the craft&#39;s status.
Definition: Craft.cpp:358
void repair()
Repairs the craft.
Definition: Craft.cpp:782
std::string getAltitude() const
Gets the craft&#39;s altitude.
Definition: Craft.cpp:367
Represents the items contained by a certain entity, like base stores, craft equipment, etc.
Definition: ItemContainer.h:34
void load(const YAML::Node &node, const Mod *mod, SavedGame *save)
Loads the craft from YAML.
Definition: Craft.cpp:90
bool getLowFuel() const
Gets whether the craft is running out of fuel.
Definition: Craft.cpp:569
void setBase(Base *base, bool move=true)
Sets the craft&#39;s base.
Definition: Craft.cpp:335
int getInterceptionOrder() const
Gets interception number.
Definition: Craft.cpp:966
Represents a player base on the globe.
Definition: Base.h:45
Represents a specific type of craft.
Definition: RuleCraft.h:36
void setDestination(Target *dest)
Sets the craft&#39;s destination.
Definition: Craft.cpp:385
void setDamage(int damage)
Sets the craft&#39;s amount of damage.
Definition: Craft.cpp:544
std::string rearm(const Mod *mod)
Rearms the craft.
Definition: Craft.cpp:818
void returnToBase()
Returns the craft to its base.
Definition: Craft.cpp:671
bool isInDogfight() const
Gets if the craft is in dogfight.
Definition: Craft.cpp:939
bool insideRadarRange(Target *target) const
Checks if a target is inside the craft&#39;s radar range.
Definition: Craft.cpp:763
bool isDestroyed() const
Gets if craft is destroyed during dogfights.
Definition: Craft.cpp:886
void unload(const Mod *mod)
Unloads the craft.
Definition: Craft.cpp:984
CraftId getUniqueId() const
Gets the craft&#39;s unique id.
Definition: Craft.cpp:975
void think()
Handles craft logic.
Definition: Craft.cpp:679
std::string getDefaultName(Language *lang) const
Gets the craft&#39;s default name.
Definition: Craft.cpp:303
Base class for moving targets on the globe with a certain speed and destination.
Definition: MovingTarget.h:29
void setLowFuel(bool low)
Sets whether the craft is running out of fuel.
Definition: Craft.cpp:579
void checkup()
Does a craft full checkup.
Definition: Craft.cpp:705
int getFuelConsumption() const
Gets the craft&#39;s fuel consumption.
Definition: Craft.cpp:619
int getVehicleCount(const std::string &vehicle) const
Gets the craft&#39;s vehicles of a certain type.
Definition: Craft.cpp:922
std::string getType() const
Gets the craft&#39;s type.
Definition: Craft.cpp:269
void setMissionComplete(bool mission)
Sets whether the craft has just finished a mission.
Definition: Craft.cpp:599
void move()
Move towards the destination.
Definition: MovingTarget.cpp:205
RuleCraft * getRules() const
Gets the craft&#39;s ruleset.
Definition: Craft.cpp:278
Base class for targets on the globe with a set of radian coordinates.
Definition: Target.h:35
int getNumVehicles() const
Gets the craft&#39;s amount of vehicles.
Definition: Craft.cpp:459
Definition: BaseInfoState.cpp:40
void setInterceptionOrder(const int order)
Sets interception order (first craft to leave the base gets 1, second 2, etc.).
Definition: Craft.cpp:957
int getFuelPercentage() const
Gets the craft&#39;s percentage of fuel.
Definition: Craft.cpp:526
bool getMissionComplete() const
Gets whether the craft has just finished a mission.
Definition: Craft.cpp:589
void changeRules(RuleCraft *rules)
Sets the craft&#39;s ruleset.
Definition: Craft.cpp:288