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 _id, _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 
57  using MovingTarget::load;
58 public:
60  Craft(RuleCraft *rules, Base *base, int id = 0);
62  ~Craft();
64  void load(const YAML::Node& node, const Mod *mod, SavedGame *save);
66  YAML::Node save() const;
68  YAML::Node saveId() const;
70  static CraftId loadId(const YAML::Node &node);
72  RuleCraft *getRules() const;
74  void changeRules(RuleCraft *rules);
76  int getId() const;
78  std::wstring getDefaultName(Language *lang) const;
80  int getMarker() const;
82  Base *getBase() const;
84  void setBase(Base *base, bool move = true);
86  std::string getStatus() const;
88  void setStatus(const std::string &status);
90  std::string getAltitude() const;
92  void setDestination(Target *dest);
94  int getNumWeapons() const;
96  int getNumSoldiers() const;
98  int getNumEquipment() const;
100  int getNumVehicles() const;
102  std::vector<CraftWeapon*> *getWeapons();
106  std::vector<Vehicle*> *getVehicles();
108  int getFuel() const;
110  void setFuel(int fuel);
112  int getFuelPercentage() const;
114  int getDamage() const;
116  void setDamage(int damage);
118  int getDamagePercentage() const;
120  bool getLowFuel() const;
122  void setLowFuel(bool low);
124  bool getMissionComplete() const;
126  void setMissionComplete(bool mission);
128  double getDistanceFromBase() const;
130  int getFuelConsumption() const;
132  int getFuelLimit() const;
134  int getFuelLimit(Base *base) const;
136  void returnToBase();
138  bool detect(Target *target) const;
140  bool insideRadarRange(Target *target) const;
142  void think();
144  void checkup();
146  void consumeFuel();
148  void repair();
150  void refuel();
152  std::string rearm(const Mod *mod);
154  void setInBattlescape(bool inbattle);
156  bool isInBattlescape() const;
158  bool isDestroyed() const;
160  int getSpaceAvailable() const;
162  int getSpaceUsed() const;
164  int getVehicleCount(const std::string &vehicle) const;
166  void setInDogfight(const bool inDogfight);
168  bool isInDogfight() const;
170  void setInterceptionOrder(const int order);
172  int getInterceptionOrder() const;
174  CraftId getUniqueId() const;
176  void unload(const Mod *mod);
178  void reuseItem(const std::string &item);
179 };
180 
181 }
std::vector< CraftWeapon * > * getWeapons()
Gets the craft&#39;s weapons.
Definition: Craft.cpp:483
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:573
int getFuelLimit() const
Gets the craft&#39;s minimum fuel limit.
Definition: Craft.cpp:645
int getNumEquipment() const
Gets the craft&#39;s amount of equipment.
Definition: Craft.cpp:463
bool detect(Target *target) const
Checks if a target is detected by the craft&#39;s radar.
Definition: Craft.cpp:736
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:502
void setInDogfight(const bool inDogfight)
Sets the craft&#39;s dogfight status.
Definition: Craft.cpp:941
void setInBattlescape(bool inbattle)
Sets the craft&#39;s battlescape status.
Definition: Craft.cpp:865
int getSpaceAvailable() const
Gets the amount of space available inside a craft.
Definition: Craft.cpp:889
ItemContainer * getItems()
Gets the craft&#39;s items.
Definition: Craft.cpp:492
void reuseItem(const std::string &item)
Reuses a base item.
Definition: Craft.cpp:1020
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:856
void refuel()
Refuels the craft.
Definition: Craft.cpp:788
Craft(RuleCraft *rules, Base *base, int id=0)
Creates a craft of the specified type.
Definition: Craft.cpp:50
std::wstring getDefaultName(Language *lang) const
Gets the craft&#39;s default name.
Definition: Craft.cpp:317
int getFuel() const
Gets the craft&#39;s amount of fuel.
Definition: Craft.cpp:512
virtual void load(const YAML::Node &node)
Loads the moving target from YAML.
Definition: MovingTarget.cpp:56
int getNumSoldiers() const
Gets the craft&#39;s amount of soldiers.
Definition: Craft.cpp:442
void consumeFuel()
Consumes the craft&#39;s fuel.
Definition: Craft.cpp:766
~Craft()
Cleans up the craft.
Definition: Craft.cpp:70
int getId() const
Gets the craft&#39;s ID.
Definition: Craft.cpp:307
int getMarker() const
Gets the craft&#39;s marker.
Definition: Craft.cpp:326
std::string getStatus() const
Gets the craft&#39;s status.
Definition: Craft.cpp:363
int getNumWeapons() const
Gets the craft&#39;s amount of weapons.
Definition: Craft.cpp:417
double getDistanceFromBase() const
Gets the craft&#39;s distance from its base.
Definition: Craft.cpp:623
Base * getBase() const
Gets the craft&#39;s base.
Definition: Craft.cpp:339
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:260
int getDamage() const
Gets the craft&#39;s amount of damage.
Definition: Craft.cpp:549
int getSpaceUsed() const
Gets the amount of space used inside a craft.
Definition: Craft.cpp:899
void setFuel(int fuel)
Sets the craft&#39;s amount of fuel.
Definition: Craft.cpp:522
void setStatus(const std::string &status)
Sets the craft&#39;s status.
Definition: Craft.cpp:372
void repair()
Repairs the craft.
Definition: Craft.cpp:775
std::string getAltitude() const
Gets the craft&#39;s altitude.
Definition: Craft.cpp:381
Represents the items contained by a certain entity, like base stores, craft equipment, etc.
Definition: ItemContainer.h:34
YAML::Node saveId() const
Saves the craft&#39;s ID to YAML.
Definition: Craft.cpp:269
void load(const YAML::Node &node, const Mod *mod, SavedGame *save)
Loads the craft from YAML.
Definition: Craft.cpp:89
bool getLowFuel() const
Gets whether the craft is running out of fuel.
Definition: Craft.cpp:583
void setBase(Base *base, bool move=true)
Sets the craft&#39;s base.
Definition: Craft.cpp:349
int getInterceptionOrder() const
Gets interception number.
Definition: Craft.cpp:959
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:399
void setDamage(int damage)
Sets the craft&#39;s amount of damage.
Definition: Craft.cpp:558
std::string rearm(const Mod *mod)
Rearms the craft.
Definition: Craft.cpp:811
void returnToBase()
Returns the craft to its base.
Definition: Craft.cpp:664
bool isInDogfight() const
Gets if the craft is in dogfight.
Definition: Craft.cpp:932
bool insideRadarRange(Target *target) const
Checks if a target is inside the craft&#39;s radar range.
Definition: Craft.cpp:756
bool isDestroyed() const
Gets if craft is destroyed during dogfights.
Definition: Craft.cpp:879
void unload(const Mod *mod)
Unloads the craft.
Definition: Craft.cpp:977
CraftId getUniqueId() const
Gets the craft&#39;s unique id.
Definition: Craft.cpp:968
void think()
Handles craft logic.
Definition: Craft.cpp:672
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:593
void checkup()
Does a craft full checkup.
Definition: Craft.cpp:698
int getFuelConsumption() const
Gets the craft&#39;s fuel consumption.
Definition: Craft.cpp:633
int getVehicleCount(const std::string &vehicle) const
Gets the craft&#39;s vehicles of a certain type.
Definition: Craft.cpp:915
void setMissionComplete(bool mission)
Sets whether the craft has just finished a mission.
Definition: Craft.cpp:613
void move()
Move towards the destination.
Definition: MovingTarget.cpp:199
RuleCraft * getRules() const
Gets the craft&#39;s ruleset.
Definition: Craft.cpp:282
Base class for targets on the globe with a set of radian coordinates.
Definition: Target.h:33
int getNumVehicles() const
Gets the craft&#39;s amount of vehicles.
Definition: Craft.cpp:473
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:950
int getFuelPercentage() const
Gets the craft&#39;s percentage of fuel.
Definition: Craft.cpp:540
bool getMissionComplete() const
Gets whether the craft has just finished a mission.
Definition: Craft.cpp:603
void changeRules(RuleCraft *rules)
Sets the craft&#39;s ruleset.
Definition: Craft.cpp:292