1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef MOBILE_CAI_H
4 #define MOBILE_CAI_H
5 
6 #include "CommandAI.h"
7 #include "Sim/Misc/GlobalConstants.h" // for SQUARE_SIZE
8 #include "System/float3.h"
9 
10 class CUnit;
11 class CFeature;
12 struct Command;
13 
14 class CMobileCAI : public CCommandAI
15 {
16 public:
17 	CR_DECLARE(CMobileCAI)
18 	CMobileCAI(CUnit* owner);
19 	CMobileCAI();
~CMobileCAI()20 	virtual ~CMobileCAI() {}
21 
22 	virtual void SetGoal(const float3& pos, const float3& curPos, float goalRadius = SQUARE_SIZE);
23 	virtual void SetGoal(const float3& pos, const float3& curPos, float goalRadius, float speed);
24 	virtual void BuggerOff(const float3& pos, float radius);
25 	bool SetFrontMoveCommandPos(const float3& pos);
26 	void StopMove();
27 	void StopMoveAndKeepPointing(const float3& p, const float r, bool b);
28 
29 	int GetDefaultCmd(const CUnit* pointed, const CFeature* feature);
30 	void SlowUpdate();
31 	void GiveCommandReal(const Command& c, bool fromSynced = true);
32 	void NonMoving();
33 	void FinishCommand();
CanSetMaxSpeed()34 	bool CanSetMaxSpeed() const { return true; }
35 	void StopSlowGuard();
36 	void StartSlowGuard(float speed);
37 	void ExecuteAttack(Command& c);
38 	void ExecuteStop(Command& c);
39 
40 	bool RefuelIfNeeded();
41 	bool LandRepairIfNeeded();
42 
43 	virtual void Execute();
44 	virtual void ExecuteGuard(Command& c);
45 	virtual void ExecuteFight(Command& c);
46 	virtual void ExecutePatrol(Command& c);
47 	virtual void ExecuteMove(Command& c);
48 	virtual void ExecuteSetWantedMaxSpeed(Command& c);
49 	virtual void ExecuteLoadUnits(Command& c);
50 
GetCancelDistance()51 	int GetCancelDistance() { return cancelDistance; }
52 
53 	virtual bool IsValidTarget(const CUnit* enemy) const;
CanWeaponAutoTarget()54 	virtual bool CanWeaponAutoTarget() const { return (!tempOrder); }
55 
56 	float3 goalPos;
57 	float  goalRadius;
58 	float3 lastBuggerGoalPos;
59 	float3 lastUserGoal;
60 
61 	int lastIdleCheck;
62 	bool tempOrder;
63 
64 	/// helps avoid infinate loops
65 	int lastPC;
66 
67 	int lastBuggerOffTime;
68 	float3 buggerOffPos;
69 	float buggerOffRadius;
70 
71 	/**
72 	 * Used to avoid stuff in maneuvre mode moving too far away from patrol path
73 	 */
74 	float3 commandPos1;
75 	float3 commandPos2;
76 
77 protected:
78 	int cancelDistance;
79 	int lastCloseInTry;
80 	bool slowGuard;
81 	bool moveDir;
82 
PushOrUpdateReturnFight()83 	void PushOrUpdateReturnFight() {
84 		CCommandAI::PushOrUpdateReturnFight(commandPos1, commandPos2);
85 	}
86 
87 	void CalculateCancelDistance();
88 
89 private:
90 	bool MobileAutoGenerateTarget();
91 };
92 
93 #endif /* MOBILE_CAI_H */
94