1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef HOVER_AIR_MOVE_TYPE_H 4 #define HOVER_AIR_MOVE_TYPE_H 5 6 #include "AAirMoveType.h" 7 8 struct float4; 9 10 class CHoverAirMoveType: public AAirMoveType 11 { 12 CR_DECLARE(CHoverAirMoveType) 13 public: 14 CHoverAirMoveType(CUnit* owner); 15 16 // MoveType interface 17 bool Update(); 18 void SlowUpdate(); 19 void StartMoving(float3 pos, float goalRadius); 20 void StartMoving(float3 pos, float goalRadius, float speed); 21 void KeepPointingTo(float3 pos, float distance, bool aggressive); 22 void StopMoving(bool callScript = false, bool hardStop = false); 23 24 bool SetMemberValue(unsigned int memberHash, void* memberValue); 25 26 void ForceHeading(short h); 27 void SetGoal(const float3& pos, float distance = 0.0f); 28 void SetState(AircraftState newState); 29 void SetAllowLanding(bool b); 30 GetLandingState()31 AircraftState GetLandingState() const { return AIRCRAFT_FLYING; } 32 void SetWantedAltitude(float altitude); 33 void SetDefaultAltitude(float altitude); 34 35 // Main state handlers 36 void UpdateLanded(); 37 void UpdateTakeoff(); 38 void UpdateLanding(); 39 void UpdateFlying(); 40 void UpdateCircling(); 41 void UpdateHovering(); 42 GetWantedHeading()43 short GetWantedHeading() const { return wantedHeading; } GetForcedHeading()44 short GetForcedHeading() const { return forceHeadingTo; } 45 GetAllowLanding()46 bool GetAllowLanding() const { return !dontLand; } 47 48 private: 49 // Helpers for (multiple) state handlers 50 void UpdateHeading(); 51 void UpdateBanking(bool noBanking); 52 void UpdateAirPhysics(); 53 void UpdateMoveRate(); 54 55 void UpdateVerticalSpeed(const float4& spd, float curRelHeight, float curVertSpeed) const; 56 CanLand(bool busy)57 bool CanLand(bool busy) const { return (!busy && ((!dontLand && autoLand) || (reservedPad != NULL))); } 58 bool CanLandAt(const float3& pos) const; 59 60 void ExecuteStop(); 61 void Takeoff(); 62 void Land(); 63 64 bool HandleCollisions(bool checkCollisions); 65 66 public: 67 enum FlyState { 68 FLY_CRUISING, 69 FLY_CIRCLING, 70 FLY_ATTACKING, 71 FLY_LANDING 72 } flyState; 73 74 bool bankingAllowed; 75 bool airStrafe; 76 /// Set to true on StopMove, to be able to not stop if a new order comes directly after 77 bool wantToStop; 78 79 /// Used when circling something 80 float goalDistance; 81 82 float currentBank; 83 float currentPitch; 84 85 float turnRate; 86 87 float maxDrift; 88 float maxTurnAngle; 89 90 private: 91 float3 wantedSpeed; 92 /// Used to determine banking (since it is the current acceleration) 93 float3 deltaSpeed; 94 95 float3 circlingPos; 96 /// buffets the plane when idling 97 float3 randomWind; 98 99 /// force the aircraft to turn toward specific heading (for transports) 100 bool forceHeading; 101 /// Set to true when transporting stuff 102 bool dontLand; 103 104 /// TODO: Seems odd to use heading in unit, since we have toggled useHeading to false.. 105 short wantedHeading; 106 short forceHeadingTo; 107 108 /// need to pause between circling steps 109 int waitCounter; 110 /// Scripts expect moverate functions to be called 111 int lastMoveRate; 112 }; 113 114 #endif // TA_AIR_MOVE_TYPE_H 115