1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef CLASSICGROUNDMOVETYPE_H
4 #define CLASSICGROUNDMOVETYPE_H
5 
6 #include "MoveType.h"
7 #include "Sim/Objects/SolidObject.h"
8 
9 struct MoveData;
10 
11 class CClassicGroundMoveType : public AMoveType
12 {
13 public:
14 	CClassicGroundMoveType(CUnit* owner);
15 	~CClassicGroundMoveType();
16 
17 	bool Update();
18 	void SlowUpdate();
19 
20 	void StartMoving(float3 pos, float goalRadius);
21 	void StartMoving(float3 pos, float goalRadius, float speed);
22 	void StopMoving(bool callScript = false, bool hardStop = false);
23 
24 	void KeepPointingTo(float3 pos, float distance, bool aggressive);
25 	void KeepPointingTo(CUnit* unit, float distance, bool aggressive);
26 
27 	bool CanApplyImpulse(const float3&);
28 	void SetMaxSpeed(float speed);
29 	void LeaveTransport();
30 
31 	static void CreateLineTable();
32 	static void DeleteLineTable();
33 
34 private:
35 	float BreakingDistance(float speed);
36 	float3 Here();
37 
38 	void StartEngine();
39 	void StopEngine();
40 
41 	void Arrived();
42 	void Fail();
43 	void CheckCollision();
44 
45 	void ChangeSpeed();
46 	void ChangeHeading(short wantedHeading);
47 
48 	void UpdateSkid();
49 	void UpdateControlledDrop();
50 	void CheckCollisionSkid();
51 	float GetFlyTime(float3 pos, float3 speed);
52 	void CalcSkidRot();
53 
54 	void AdjustPosToWaterLine();
55 	bool UpdateDirectControl();
56 	void UpdateOwnerPos();
57 
58 	bool OnSlope();
59 	void TestNewTerrainSquare();
60 	bool CheckGoalFeasability();
61 	void SetMainHeading();
62 
63 	bool CheckColH(int x, int y1, int y2, float xmove, int squareTestX);
64 	bool CheckColV(int y, int x1, int x2, float zmove, int squareTestY);
65 
66 	float3 ObstacleAvoidance(float3 desiredDir);
67 	float Distance2D(CSolidObject* object1, CSolidObject* object2, float marginal = 0.0f);
68 
69 	void GetNewPath();
70 	void GetNextWayPoint();
71 
72 private:
73 	SyncedFloat3 waypoint;
74 	SyncedFloat3 nextWaypoint;
75 
76 	unsigned int pathId;
77 	float goalRadius;
78 
79 	bool atGoal;
80 	bool haveFinalWaypoint;
81 
82 	float turnRate;
83 	float accRate;
84 	float decRate;
85 
86 	float skidRotSpeed;
87 	//float dropSpeed;
88 	//float dropHeight;
89 
90 	float3 skidRotVector;
91 	float skidRotSpeed2;
92 	float skidRotPos2;
93 
94 	float3 flatFrontDir;
95 	float3 mainHeadingPos;
96 	float3 lastGetPathPos;
97 
98 	bool useMainHeading;
99 	short int deltaHeading;
100 
101 	float wantedSpeed;
102 	float currentSpeed;
103 	float requestedSpeed;
104 	float deltaSpeed;
105 	float terrainSpeed;
106 	float currentDistanceToWaypoint;
107 
108 	int etaWaypoint; /// by this time it really should have gotten there genereate new path otherwise
109 	int etaWaypoint2; /// by this time we get suspicious, check if goal is clogged if we are close
110 
111 	int nextDeltaSpeedUpdate;
112 	int nextObstacleAvoidanceUpdate;
113 	unsigned int restartDelay;
114 
115 	unsigned int pathFailures;
116 	unsigned int etaFailures; /// how many times we havent gotten to a waypoint in time
117 	unsigned int nonMovingFailures; /// how many times we have requested a path from the same place
118 
119 	int moveSquareX;
120 	int moveSquareY;
121 
122 	// number of grid-cells along each dimension; should be an odd number
123 	static const int LINETABLE_SIZE = 11;
124 	static std::vector<int2> lineTable[LINETABLE_SIZE][LINETABLE_SIZE];
125 };
126 
127 #endif
128 
129