1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef MOVETYPE_H
4 #define MOVETYPE_H
5 
6 #include "System/creg/creg_cond.h"
7 #include "Sim/Misc/AirBaseHandler.h"
8 #include "System/Object.h"
9 #include "System/float3.h"
10 
11 class CUnit;
12 
13 class AMoveType : public CObject
14 {
15 	CR_DECLARE(AMoveType)
16 
17 public:
18 	AMoveType(CUnit* owner);
~AMoveType()19 	virtual ~AMoveType() {}
20 
StartMovingRaw(const float3 moveGoalPos,float moveGoalRadius)21 	virtual void StartMovingRaw(const float3 moveGoalPos, float moveGoalRadius) {}
22 	virtual void StartMoving(float3 pos, float goalRadius) = 0;
23 	virtual void StartMoving(float3 pos, float goalRadius, float speed) = 0;
24 	virtual void KeepPointingTo(float3 pos, float distance, bool aggressive) = 0;
25 	virtual void KeepPointingTo(CUnit* unit, float distance, bool aggressive);
26 	virtual void StopMoving(bool callScript = false, bool hardStop = false) = 0;
CanApplyImpulse(const float3 &)27 	virtual bool CanApplyImpulse(const float3&) { return false; }
LeaveTransport()28 	virtual void LeaveTransport() {}
29 
30 	// generic setter for Lua-writable values
31 	virtual bool SetMemberValue(unsigned int memberHash, void* memberValue);
32 
33 	virtual void SetGoal(const float3& pos, float distance = 0.0f) { goalPos = pos; }
34 
35 	// NOTE:
36 	//     SetMaxSpeed is ONLY called by LuaSyncedMoveCtrl now
37 	//     other code (CommandAI) modifies a unit's speed only
38 	//     through SetMaxWantedSpeed, via SET_WANTED_MAX_SPEED
39 	//     commands
40 	// NOTE:
41 	//     clamped because too much code in the derived
42 	//     MoveType classes expects maxSpeed to be != 0
SetMaxSpeed(float speed)43 	virtual void SetMaxSpeed(float speed) { maxSpeed = std::max(0.001f, speed); }
SetWantedMaxSpeed(float speed)44 	virtual void SetWantedMaxSpeed(float speed) { maxWantedSpeed = speed; }
SetManeuverLeash(float leashLength)45 	virtual void SetManeuverLeash(float leashLength) { maneuverLeash = leashLength; }
46 
47 	virtual bool Update() = 0;
48 	virtual void SlowUpdate();
49 
IsSkidding()50 	virtual bool IsSkidding() const { return false; }
IsFlying()51 	virtual bool IsFlying() const { return false; }
IsReversing()52 	virtual bool IsReversing() const { return false; }
53 
ReservePad(CAirBaseHandler::LandingPad * lp)54 	virtual void ReservePad(CAirBaseHandler::LandingPad* lp) { /* AAirMoveType only */ }
UnreservePad(CAirBaseHandler::LandingPad * lp)55 	virtual void UnreservePad(CAirBaseHandler::LandingPad* lp) { /* AAirMoveType only */ }
GetReservedPad()56 	virtual CAirBaseHandler::LandingPad* GetReservedPad() { return NULL; }
57 
58 	bool WantsRepair() const;
59 	bool WantsRefuel() const;
60 
SetRepairBelowHealth(float rbHealth)61 	void SetRepairBelowHealth(float rbHealth) { repairBelowHealth = rbHealth; }
62 
GetMaxSpeed()63 	float GetMaxSpeed() const { return maxSpeed; }
GetMaxSpeedDef()64 	float GetMaxSpeedDef() const { return maxSpeedDef; }
GetMaxWantedSpeed()65 	float GetMaxWantedSpeed() const { return maxWantedSpeed; }
GetRepairBelowHealth()66 	float GetRepairBelowHealth() const { return repairBelowHealth; }
GetManeuverLeash()67 	float GetManeuverLeash() const { return maneuverLeash; }
68 
69 	float CalcStaticTurnRadius() const;
70 
71 public:
72 	CUnit* owner;
73 
74 	float3 goalPos;
75 	float3 oldPos;             // owner position at last Update()
76 	float3 oldSlowUpdatePos;   // owner position at last SlowUpdate()
77 
78 	/// TODO: probably should move the code in CUnit that reads this into the movement classes
79 	bool useHeading;
80 
81 	enum ProgressState {
82 		Done   = 0,
83 		Active = 1,
84 		Failed = 2
85 	};
86 	ProgressState progressState;
87 
88 protected:
89 	float maxSpeed;            // current maximum speed owner is allowed to reach (changes with eg. guard orders)
90 	float maxSpeedDef;         // default maximum speed owner can reach (as defined by its UnitDef, never changes)
91 	float maxWantedSpeed;      // maximum speed (temporarily) set by a CMD_SET_WANTED_MAX_SPEED modifier command
92 
93 	float repairBelowHealth;
94 	float maneuverLeash;       // maximum distance away a target can be and still be chased
95 };
96 
97 #endif // MOVETYPE_H
98