OpenXcom  1.0
Open-source clone of the original X-Com
DogfightState.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 "../Engine/State.h"
21 #include <vector>
22 #include <string>
23 
24 namespace OpenXcom
25 {
26 
27 const int STANDOFF_DIST = 560;
28 enum ColorNames { CRAFT_MIN, CRAFT_MAX, RADAR_MIN, RADAR_MAX, DAMAGE_MIN, DAMAGE_MAX, BLOB_MIN, RANGE_METER, DISABLED_WEAPON, DISABLED_AMMO, DISABLED_RANGE };
29 
30 class ImageButton;
31 class Text;
32 class Surface;
33 class InteractiveSurface;
34 class Timer;
35 class GeoscapeState;
36 class Craft;
37 class Ufo;
38 class CraftWeaponProjectile;
39 
44 class DogfightState : public State
45 {
46 private:
47  GeoscapeState *_state;
48  Timer *_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  Craft *_craft;
56  Ufo *_ufo;
57  int _timeout, _currentDist, _targetDist, _w1FireInterval, _w2FireInterval, _w1FireCountdown, _w2FireCountdown;
58  bool _end, _destroyUfo, _destroyCraft, _ufoBreakingOff, _weapon1Enabled, _weapon2Enabled;
59  bool _minimized, _endDogfight, _animatingHit, _waitForPoly, _waitForAltitude;
60  std::vector<CraftWeaponProjectile*> _projectiles;
61  static const int _ufoBlobs[8][13][13];
62  static const int _projectileBlobs[4][6][3];
63  int _ufoSize, _craftHeight, _currentCraftDamageColor, _interceptionNumber;
64  size_t _interceptionsCount;
65  int _x, _y, _minimizedIconX, _minimizedIconY;
66  int _colors[11];
67  // Ends the dogfight.
68  void endDogfight();
69 
70 public:
72  DogfightState(GeoscapeState *state, Craft *craft, Ufo *ufo);
76  void think();
78  void animate();
80  void update();
81  // Fires the first weapon.
82  void fireWeapon1();
83  // Fires the second weapon.
84  void fireWeapon2();
85  // Fires UFO weapon.
86  void ufoFireWeapon();
87  // Sets the craft to minimum distance.
88  void minimumDistance();
89  // Sets the craft to maximum distance.
90  void maximumDistance();
92  void setStatus(const std::string &status);
94  void btnMinimizeClick(Action *action);
96  void btnStandoffPress(Action *action);
98  void btnCautiousPress(Action *action);
100  void btnStandardPress(Action *action);
102  void btnAggressivePress(Action *action);
104  void btnDisengagePress(Action *action);
106  void btnUfoClick(Action *action);
108  void previewClick(Action *action);
110  void drawUfo();
112  void drawProjectile(const CraftWeaponProjectile* p);
114  void animateCraftDamage();
116  void drawCraftDamage();
118  void weapon1Click(Action *action);
120  void weapon2Click(Action *action);
122  void recolor(const int weaponNo, const bool currentState);
124  bool isMinimized() const;
126  void setMinimized(const bool minimized);
128  void btnMinimizedIconClick(Action *action);
130  int getInterceptionNumber() const;
132  void setInterceptionNumber(const int number);
134  void setInterceptionsCount(const size_t count);
138  void moveWindow();
140  bool dogfightEnded() const;
142  Ufo *getUfo() const;
144  Craft *getCraft() const;
146  void setWaitForPoly(bool wait);
148  bool getWaitForPoly() const;
150  void setWaitForAltitude(bool wait);
152  bool getWaitForAltitude() const;
153 };
154 
155 }
void btnCautiousPress(Action *action)
Handler for pressing the Cautious Attack button.
Definition: DogfightState.cpp:1345
Represents a craft stored in a base.
Definition: Craft.h:45
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
int getInterceptionNumber() const
Gets interception number.
Definition: DogfightState.cpp:1849
Geoscape screen which shows an overview of the world and lets the player manage the game...
Definition: GeoscapeState.h:42
A game state that receives user input and reacts accordingly.
Definition: State.h:44
void setMinimized(const bool minimized)
Sets state minimized or maximized.
Definition: DogfightState.cpp:1628
Timer used to run code in fixed intervals.
Definition: Timer.h:35
Ufo * getUfo() const
Gets pointer to the UFO in this dogfight.
Definition: DogfightState.cpp:1813
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
void btnStandoffPress(Action *action)
Handler for pressing the Standoff button.
Definition: DogfightState.cpp:1331
void drawCraftDamage()
Updates craft damage.
Definition: DogfightState.cpp:611
void maximumDistance()
Sets the craft to the maximum distance required to fire a weapon.
Definition: DogfightState.cpp:1275
Text string displayed on screen.
Definition: Text.h:40
void minimumDistance()
Sets the craft to the minimum distance required to fire a weapon.
Definition: DogfightState.cpp:1249
void setInterceptionsCount(const size_t count)
Sets interceptions count.
Definition: DogfightState.cpp:1694
void drawProjectile(const CraftWeaponProjectile *p)
Draws projectiles.
Definition: DogfightState.cpp:1505
void setWaitForPoly(bool wait)
Waits until the UFO reaches a polygon.
Definition: DogfightState.cpp:1854
void previewClick(Action *action)
Handler for clicking the Preview graphic.
Definition: DogfightState.cpp:1444
void ufoFireWeapon()
Each time a UFO will try to fire it&#39;s cannons a calculation is made.
Definition: DogfightState.cpp:1228
void animate()
Animates the window.
Definition: DogfightState.cpp:663
void moveWindow()
Moves window to new position.
Definition: DogfightState.cpp:1787
Regular image that works like a button.
Definition: ImageButton.h:32
void animateCraftDamage()
Animates craft damage.
Definition: DogfightState.cpp:594
void btnUfoClick(Action *action)
Handler for clicking the Ufo button.
Definition: DogfightState.cpp:1425
bool dogfightEnded() const
Checks if the dogfight should be ended.
Definition: DogfightState.cpp:1804
void update()
Moves the craft.
Definition: DogfightState.cpp:731
void weapon2Click(Action *action)
Toggles usage of weapon 2.
Definition: DogfightState.cpp:1568
void btnMinimizeClick(Action *action)
Handler for clicking the Minimize button.
Definition: DogfightState.cpp:1312
Shows a dogfight (interception) between a player craft and an UFO.
Definition: DogfightState.h:44
void btnStandardPress(Action *action)
Handler for pressing the Standard Attack button.
Definition: DogfightState.cpp:1367
bool getWaitForPoly() const
Waits until the UFO reaches a polygon.
Definition: DogfightState.cpp:1859
bool getWaitForAltitude() const
Waits until the UFO reaches the right altutude.
Definition: DogfightState.cpp:1869
void setWaitForAltitude(bool wait)
Waits until the UFO reaches the right altitude.
Definition: DogfightState.cpp:1864
void btnMinimizedIconClick(Action *action)
Handler for clicking the minimized interception window icon.
Definition: DogfightState.cpp:1663
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
void btnDisengagePress(Action *action)
Handler for pressing the Disengage button.
Definition: DogfightState.cpp:1411
bool isMinimized() const
Returns true if state is minimized.
Definition: DogfightState.cpp:1619
void setInterceptionNumber(const int number)
Sets interception number.
Definition: DogfightState.cpp:1685
DogfightState(GeoscapeState *state, Craft *craft, Ufo *ufo)
Creates the Dogfight state.
Definition: DogfightState.cpp:235
void drawUfo()
Draws UFO.
Definition: DogfightState.cpp:1464
void weapon1Click(Action *action)
Toggles usage of weapon 1.
Definition: DogfightState.cpp:1558
Craft * getCraft() const
Gets pointer to the craft in this dogfight.
Definition: DogfightState.cpp:1822
Represents an alien UFO on the map.
Definition: Ufo.h:40
void btnAggressivePress(Action *action)
Handler for pressing the Aggressive Attack button.
Definition: DogfightState.cpp:1389
void setStatus(const std::string &status)
Changes the status text.
Definition: DogfightState.cpp:1302
void recolor(const int weaponNo, const bool currentState)
Changes colors of weapon icons, range indicators and ammo texts base on current weapon state...
Definition: DogfightState.cpp:1579
void calculateWindowPosition()
Calculates window position according to opened interception windows.
Definition: DogfightState.cpp:1705
~DogfightState()
Cleans up the Dogfight state.
Definition: DogfightState.cpp:565
void fireWeapon1()
Fires a shot from the first weapon equipped on the craft.
Definition: DogfightState.cpp:1179
void think()
Runs the timers.
Definition: DogfightState.cpp:578
void fireWeapon2()
Fires a shot from the second weapon equipped on the craft.
Definition: DogfightState.cpp:1203
Definition: BaseInfoState.cpp:40
Definition: CraftWeaponProjectile.h:32