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_DOGFIGHTSTATE_H
20 #define OPENXCOM_DOGFIGHTSTATE_H
21 
22 #include "../Engine/State.h"
23 #include <vector>
24 #include <string>
25 
26 namespace OpenXcom
27 {
28 
29 const int STANDOFF_DIST = 560;
30 
31 class ImageButton;
32 class Text;
33 class Surface;
34 class InteractiveSurface;
35 class Timer;
36 class Globe;
37 class Craft;
38 class Ufo;
39 class CraftWeaponProjectile;
40 
41 /**
42  * Shows a dogfight (interception) between a
43  * player craft and an UFO.
44  */
45 class DogfightState : public State
46 {
47 private:
48 	Timer *_animTimer, *_moveTimer, *_w1Timer, *_w2Timer, *_ufoWtimer, *_ufoEscapeTimer, *_craftDamageAnimTimer;
49 	Surface *_window, *_battle, *_range1, *_range2, *_damage;
50 	InteractiveSurface *_btnMinimize, *_preview, *_weapon1, *_weapon2;
51 	ImageButton *_btnStandoff, *_btnCautious, *_btnStandard, *_btnAggressive, *_btnDisengage, *_btnUfo;
52 	ImageButton *_mode;
53 	InteractiveSurface *_btnMinimizedIcon;
54 	Text *_txtAmmo1, *_txtAmmo2, *_txtDistance, *_txtStatus, *_txtInterceptionNumber;
55 	Globe *_globe;
56 	Craft *_craft;
57 	Ufo *_ufo;
58 	int _timeout, _currentDist, _targetDist, _ufoFireInterval;
59 	bool _end, _destroyUfo, _destroyCraft, _ufoBreakingOff, _weapon1Enabled, _weapon2Enabled, _minimized, _endDogfight, _animatingHit;
60 	std::vector<CraftWeaponProjectile*> _projectiles;
61 	static const int _ufoBlobs[8][13][13];
62 	static const int _projectileBlobs[4][6][3];
63 	int _timeScale;
64 	int _ufoSize, _craftHeight, _currentCraftDamageColor, _interceptionNumber;
65 	size_t _interceptionsCount;
66 	int _x, _y, _minimizedIconX, _minimizedIconY;
67 
68 	// Ends the dogfight.
69 	void endDogfight();
70 
71 public:
72 	/// Creates the Dogfight state.
73 	DogfightState(Game *game, Globe *globe, Craft *craft, Ufo *ufo);
74 	/// Cleans up the Dogfight state.
75 	~DogfightState();
76 	/// Runs the timers.
77 	void think();
78 	/// Animates the window.
79 	void animate();
80 	/// Moves the craft.
81 	void move();
82 	// Fires the first weapon.
83 	void fireWeapon1();
84 	// Fires the second weapon.
85 	void fireWeapon2();
86 	// Fires UFO weapon.
87 	void ufoFireWeapon();
88 	// Sets the craft to minimum distance.
89 	void minimumDistance();
90 	// Sets the craft to maximum distance.
91 	void maximumDistance();
92 	/// Changes the status text.
93 	void setStatus(const std::string &status);
94 	/// Handler for clicking the Minimize button.
95 	void btnMinimizeClick(Action *action);
96 	/// Handler for clicking the Standoff button.
97 	void btnStandoffClick(Action *action);
98 	/// Handler for clicking the Cautious Attack button.
99 	void btnCautiousClick(Action *action);
100 	/// Handler for clicking the Standard Attack button.
101 	void btnStandardClick(Action *action);
102 	/// Handler for clicking the Aggressive Attack button.
103 	void btnAggressiveClick(Action *action);
104 	/// Handler for clicking the Disengage button.
105 	void btnDisengageClick(Action *action);
106 	/// Handler for clicking the Ufo button.
107 	void btnUfoClick(Action *action);
108 	/// Handler for clicking the Preview graphic.
109 	void previewClick(Action *action);
110 	/// Makes the UFO break off the interception... or at least tries to.
111 	void ufoBreakOff();
112 	/// Draws UFO.
113 	void drawUfo();
114 	/// Draws projectiles.
115 	void drawProjectile(const CraftWeaponProjectile* p);
116 	/// Animates craft damage.
117 	void animateCraftDamage();
118 	/// Updates craft damage.
119 	void drawCraftDamage();
120 	/// Toggles usage of weapon 1.
121 	void weapon1Click(Action *action);
122 	/// Toggles usage of weapon 2.
123 	void weapon2Click(Action *action);
124 	/// Changes colors of weapon icons, range indicators and ammo texts base on current weapon state.
125 	void recolor(const int weaponNo, const bool currentState);
126 	/// Returns true if state is minimized.
127 	bool isMinimized() const;
128 	/// Sets state minimized or maximized.
129 	void setMinimized(const bool minimized);
130 	/// Handler for clicking the minimized interception window icon.
131 	void btnMinimizedIconClick(Action *action);
132 	/// Gets interception number.
133 	int getInterceptionNumber() const;
134 	/// Sets interception number.
135 	void setInterceptionNumber(const int number);
136 	/// Sets interceptions count.
137 	void setInterceptionsCount(const size_t count);
138 	/// Calculates window position according to opened interception windows.
139 	void calculateWindowPosition();
140 	/// Moves window to new position.
141 	void moveWindow();
142 	/// Checks if the dogfight should be ended.
143 	bool dogfightEnded() const;
144 	/// Gets pointer to the UFO in this dogfight.
145 	Ufo* getUfo() const;
146 
147 };
148 
149 }
150 
151 #endif
152