File: GroundMoveType.h

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (162 lines) | stat: -rwxr-xr-x 3,830 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef GROUNDMOVETYPE_H
#define GROUNDMOVETYPE_H

#include "MoveType.h"
#include "Sim/Objects/SolidObject.h"

struct UnitDef;
struct MoveData;
class CMoveMath;

class CGroundMoveType : public AMoveType
{
	CR_DECLARE(CGroundMoveType);

public:
	CGroundMoveType(CUnit* owner);
	~CGroundMoveType();

	void PostLoad();

	bool Update();
	void SlowUpdate();

	void SetDeltaSpeed(float, bool, bool = false);

	void StartMoving(float3 pos, float goalRadius);
	void StartMoving(float3 pos, float goalRadius, float speed);
	void StopMoving();

	void SetMaxSpeed(float speed);

	void ImpulseAdded(const float3&);

	void KeepPointingTo(float3 pos, float distance, bool aggressive);
	void KeepPointingTo(CUnit* unit, float distance, bool aggressive);

	bool OnSlope(float minSlideTolerance);

	void TestNewTerrainSquare();
	void LeaveTransport();

	void StartSkidding() { skidding = true; }
	void StartFlying() { skidding = true; flying = true; } // flying requires skidding

	bool IsSkidding() const { return skidding; }
	bool IsFlying() const { return flying; }
	bool IsReversing() const { return reversing; }

	static void CreateLineTable();
	static void DeleteLineTable();


	float turnRate;
	float accRate;
	float decRate;

	float maxReverseSpeed;
	float wantedSpeed;
	float currentSpeed;
	float requestedSpeed;
	float deltaSpeed;

	unsigned int pathId;
	float goalRadius;

	SyncedFloat3 currWayPoint;
	SyncedFloat3 nextWayPoint;

protected:
	float3 ObstacleAvoidance(const float3& desiredDir);
	float Distance2D(CSolidObject* object1, CSolidObject* object2, float marginal = 0.0f);

	void GetNewPath();
	void GetNextWayPoint();

	float BreakingDistance(float speed) const;
	float3 Here();

	void StartEngine();
	void StopEngine();

	void Arrived();
	void Fail();
	void HandleObjectCollisions();
	void HandleUnitCollisions(
		CUnit* collider,
		const float colliderSpeed,
		const float colliderRadius,
		const float3& sepDirMask,
		const UnitDef* colliderUD,
		const MoveData* colliderMD,
		const CMoveMath* colliderMM);
	void HandleFeatureCollisions(
		CUnit* collider,
		const float colliderSpeed,
		const float colliderRadius,
		const float3& sepDirMask,
		const UnitDef* colliderUD,
		const MoveData* colliderMD,
		const CMoveMath* colliderMM);

	void SetMainHeading();
	void ChangeHeading(short newHeading);

	void UpdateSkid();
	void UpdateControlledDrop();
	void CheckCollisionSkid();
	void CalcSkidRot();

	float GetGroundHeight(const float3&) const;
	void AdjustPosToWaterLine();
	bool UpdateDirectControl();
	void UpdateOwnerPos(bool);
	bool FollowPath();
	bool WantReverse(const float3&) const;


	bool atGoal;
	bool haveFinalWaypoint;

	float currWayPointDist;
	float prevWayPointDist;

	bool skidding;
	bool flying;
	bool reversing;
	bool idling;
	bool canReverse;
	bool useMainHeading;

	float3 skidRotVector;  /// vector orthogonal to skidDir
	float skidRotSpeed;    /// rotational speed when skidding (radians / (GAME_SPEED frames))
	float skidRotAccel;    /// rotational acceleration when skidding (radians / (GAME_SPEED frames^2))

	CSolidObject::PhysicalState oldPhysState;

	float3 waypointDir;
	float3 flatFrontDir;
	float3 lastAvoidanceDir;
	float3 mainHeadingPos;

	// number of grid-cells along each dimension; should be an odd number
	static const int LINETABLE_SIZE = 11;
	static std::vector<int2> lineTable[LINETABLE_SIZE][LINETABLE_SIZE];

	unsigned int nextObstacleAvoidanceUpdate;
	unsigned int pathRequestDelay;

	/// {in, de}creased every Update if idling is true/false and pathId != 0
	unsigned int numIdlingUpdates;
	/// {in, de}creased every SlowUpdate if idling is true/false and pathId != 0
	unsigned int numIdlingSlowUpdates;

	int moveSquareX;
	int moveSquareY;

	short wantedHeading;
};

#endif // GROUNDMOVETYPE_H