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_CRAFT_H
20 #define OPENXCOM_CRAFT_H
21 
22 #include "MovingTarget.h"
23 #include <vector>
24 #include <string>
25 
26 namespace OpenXcom
27 {
28 
29 class RuleCraft;
30 class Base;
31 class Soldier;
32 class CraftWeapon;
33 class ItemContainer;
34 class Ruleset;
35 class SavedGame;
36 class Vehicle;
37 
38 /**
39  * Represents a craft stored in a base.
40  * Contains variable info about a craft like
41  * position, fuel, damage, etc.
42  * @sa RuleCraft
43  */
44 class Craft : public MovingTarget
45 {
46 private:
47 	RuleCraft *_rules;
48 	Base *_base;
49 	int _id, _fuel, _damage, _interceptionOrder, _takeoff;
50 	std::vector<CraftWeapon*> _weapons;
51 	ItemContainer *_items;
52 	std::vector<Vehicle*> _vehicles;
53 	std::string _status;
54 	bool _lowFuel, _inBattlescape, _inDogfight;
55 	std::wstring _name;
56 public:
57 	/// Creates a craft of the specified type.
58 	Craft(RuleCraft *rules, Base *base, int id = 0);
59 	/// Cleans up the craft.
60 	~Craft();
61 	/// Loads the craft from YAML.
62 	void load(const YAML::Node& node, const Ruleset *rule, SavedGame *save);
63 	/// Saves the craft to YAML.
64 	YAML::Node save() const;
65 	/// Saves the craft's ID to YAML.
66 	YAML::Node saveId() const;
67 	/// Gets the craft's ruleset.
68 	RuleCraft *getRules() const;
69 	/// Sets the craft's ruleset.
70 	void setRules(RuleCraft *rules);
71 	/// Gets the craft's ID.
72 	int getId() const;
73 	/// Gets the craft's name.
74 	std::wstring getName(Language *lang) const;
75 	/// Sets the craft's name.
76 	void setName(const std::wstring &newName);
77 	/// Gets the craft's base.
78 	Base *getBase() const;
79 	/// Sets the craft's base.
80 	void setBase(Base *base);
81 	/// Sets the craft's base. (without setting the craft's coordinates)
82 	void setBaseOnly(Base *base);
83 	/// Gets the craft's status.
84 	std::string getStatus() const;
85 	/// Sets the craft's status.
86 	void setStatus(const std::string &status);
87 	/// Gets the craft's altitude.
88 	std::string getAltitude() const;
89 	/// Sets the craft's destination.
90 	void setDestination(Target *dest);
91 	/// Gets the craft's amount of weapons.
92 	int getNumWeapons() const;
93 	/// Gets the craft's amount of soldiers.
94 	int getNumSoldiers() const;
95 	/// Gets the craft's amount of equipment.
96 	int getNumEquipment() const;
97 	/// Gets the craft's amount of vehicles.
98 	int getNumVehicles() const;
99 	/// Gets the craft's weapons.
100 	std::vector<CraftWeapon*> *getWeapons();
101 	/// Gets the craft's items.
102 	ItemContainer *getItems();
103 	/// Gets the craft's vehicles.
104 	std::vector<Vehicle*> *getVehicles();
105 	/// Gets the craft's amount of fuel.
106 	int getFuel() const;
107 	/// Sets the craft's amount of fuel.
108 	void setFuel(int fuel);
109 	/// Gets the craft's percentage of fuel.
110 	int getFuelPercentage() const;
111 	/// Gets the craft's amount of damage.
112 	int getDamage() const;
113 	/// Sets the craft's amount of damage.
114 	void setDamage(int damage);
115 	/// Gets the craft's percentage of damage.
116 	int getDamagePercentage() const;
117 	/// Gets whether the craft is running out of fuel.
118 	bool getLowFuel() const;
119 	/// Sets whether the craft is running out of fuel.
120 	void setLowFuel(bool low);
121 	/// Gets the craft's distance from its base.
122 	double getDistanceFromBase() const;
123 	/// Gets the craft's fuel consumption.
124 	int getFuelConsumption() const;
125 	/// Gets the craft's minimum fuel limit.
126 	int getFuelLimit() const;
127 	/// Gets the craft's minimum fuel limit to go to a base.
128 	int getFuelLimit(Base *base) const;
129 	/// Returns the craft to its base.
130 	void returnToBase();
131 	/// Checks if a target is detected by the craft's radar.
132 	bool detect(Target *target) const;
133 	/// Handles craft logic.
134 	void think();
135 	/// Does a craft full checkup.
136 	void checkup();
137 	/// Consumes the craft's fuel.
138 	void consumeFuel();
139 	/// Repairs the craft.
140 	void repair();
141 	/// Refuels the craft.
142 	void refuel();
143 	/// Rearms the craft.
144 	std::string rearm(Ruleset *rules);
145 	/// Sets the craft's battlescape status.
146 	void setInBattlescape(bool inbattle);
147 	/// Gets if the craft is in battlescape.
148 	bool isInBattlescape() const;
149 	/// Gets if craft is destroyed during dogfights.
150 	bool isDestroyed() const;
151 	/// Gets the amount of space available inside a craft.
152 	int getSpaceAvailable() const;
153 	/// Gets the amount of space used inside a craft.
154 	int getSpaceUsed() const;
155 	/// Gets the craft's vehicles of a certain type.
156 	int getVehicleCount(const std::string &vehicle) const;
157 	/// Sets the craft's dogfight status.
158 	void setInDogfight(const bool inDogfight);
159 	/// Gets if the craft is in dogfight.
160 	bool isInDogfight() const;
161 	/// Sets interception order (first craft to leave the base gets 1, second 2, etc.).
162 	void setInterceptionOrder(const int order);
163 	/// Gets interception number.
164 	int getInterceptionOrder() const;
165 };
166 
167 }
168 
169 #endif
170