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_UFO_H
20 #define OPENXCOM_UFO_H
21 
22 #include "MovingTarget.h"
23 #include <string>
24 #include <yaml-cpp/yaml.h>
25 
26 namespace OpenXcom
27 {
28 
29 class RuleUfo;
30 class AlienMission;
31 class UfoTrajectory;
32 class SavedGame;
33 class Ruleset;
34 
35 /**
36  * Represents an alien UFO on the map.
37  * Contains variable info about a UFO like
38  * position, damage, speed, etc.
39  * @sa RuleUfo
40  */
41 class Ufo : public MovingTarget
42 {
43 public:
44 	enum UfoStatus { FLYING, LANDED, CRASHED, DESTROYED };
45 private:
46 	RuleUfo *_rules;
47 	int _id, _crashId, _landId, _damage;
48 	std::string _direction, _altitude;
49 	enum UfoStatus _status;
50 	size_t _secondsRemaining;
51 	bool _inBattlescape;
52 	int _shotDownByCraftId;
53 	AlienMission *_mission;
54 	const UfoTrajectory *_trajectory;
55 	size_t _trajectoryPoint;
56 	bool _detected, _hyperDetected;
57 	int _shootingAt, _hitFrame;
58 	/// Calculates a new speed vector to the destination.
59 	void calculateSpeed();
60 public:
61 	/// Creates a UFO of the specified type.
62 	Ufo(RuleUfo *rules);
63 	/// Cleans up the UFO.
64 	~Ufo();
65 	/// Loads the UFO from YAML.
66 	void load(const YAML::Node& node, const Ruleset &ruleset, SavedGame &game);
67 	/// Saves the UFO to YAML.
68 	YAML::Node save(bool newBattle) const;
69 	/// Saves the UFO's ID to YAML.
70 	YAML::Node saveId() const;
71 	/// Gets the UFO's ruleset.
72 	RuleUfo *getRules() const;
73 	/// Gets the UFO's ID.
74 	int getId() const;
75 	/// Sets the UFO's ID.
76 	void setId(int id);
77 	/// Gets the UFO's name.
78 	std::wstring getName(Language *lang) const;
79 	/// Gets the UFO's amount of damage.
80 	int getDamage() const;
81 	/// Sets the UFO's amount of damage.
82 	void setDamage(int damage);
83 	/// Gets the UFO's detection status.
84 	bool getDetected() const;
85 	/// Sets the UFO's detection status.
86 	void setDetected(bool detected);
87 	/// Gets the UFO's seconds left on the ground.
88 	size_t getSecondsRemaining() const;
89 	/// Sets the UFO's seconds left on the ground.
90 	void setSecondsRemaining(size_t seconds);
91 	/// Gets the UFO's direction.
92 	std::string getDirection() const;
93 	/// Gets the UFO's altitude.
94 	std::string getAltitude() const;
95 	/// Sets the UFO's altitude.
96 	void setAltitude(const std::string &altitude);
97 	/// Gets the UFO status
getStatus()98 	enum UfoStatus getStatus() const { return _status; }
99 	/// Set the UFO's status.
setStatus(enum UfoStatus status)100 	void setStatus(enum UfoStatus status) {_status = status; }
101 	/// Gets if the UFO has crashed.
102 	bool isCrashed() const;
103 	/// Gets if the UFO has been destroyed.
104 	bool isDestroyed() const;
105 	/// Handles UFO logic.
106 	void think();
107 	/// Sets the UFO's battlescape status.
108 	void setInBattlescape(bool inbattle);
109 	/// Gets if the UFO is in battlescape.
110 	bool isInBattlescape() const;
111 	/// Gets the UFO's alien race.
112 	const std::string &getAlienRace() const;
113 	/// Sets the ID of craft which shot down the UFO.
114 	void setShotDownByCraftId(const int id);
115 	/// Gets the ID of craft which shot down the UFO.
116 	int getShotDownByCraftId() const;
117 	/// Gets the UFO's visibility.
118 	int getVisibility() const;
119 	/// Gets the UFO's Mission type.
120 	const std::string &getMissionType() const;
121 	/// Sets the UFO's mission information.
122 	void setMissionInfo(AlienMission *mission, const UfoTrajectory *trajectory);
123 	/// Gets the UFO's hyper detection status.
124 	bool getHyperDetected() const;
125 	/// Sets the UFO's hyper detection status.
126 	void setHyperDetected(bool hyperdetected);
127 	/// Gets the UFO's progress on the trajectory track.
getTrajectoryPoint()128 	size_t getTrajectoryPoint() const { return _trajectoryPoint; }
129 	/// Sets the UFO's progress on the trajectory track.
setTrajectoryPoint(size_t np)130 	void setTrajectoryPoint(size_t np) { _trajectoryPoint = np; }
131 	/// Gets the UFO's trajectory.
getTrajectory()132 	const UfoTrajectory &getTrajectory() const { return *_trajectory; }
133 	/// Gets the UFO's mission object.
getMission()134 	AlienMission *getMission() const { return _mission; }
135 	/// Sets the UFO's destination.
136 	void setDestination(Target *dest);
137 	/// Get which interceptor this ufo is engaging.
138 	int getShootingAt() const;
139 	/// Set which interceptor this ufo is engaging.
140 	void setShootingAt(int target);
141 	/// Gets the UFO's landing site ID.
142 	int getLandId() const;
143 	/// Sets the UFO's landing site ID.
144 	void setLandId(int id);
145 	/// Gets the UFO's crash site ID.
146 	int getCrashId() const;
147 	/// Sets the UFO's crash site ID.
148 	void setCrashId(int id);
149 	/// Sets the UFO's hit frame.
150 	void setHitFrame(int frame);
151 	/// Gets the UFO's hit frame.
152 	int getHitFrame();
153 
154 };
155 
156 }
157 
158 #endif
159