File: IPathController.hpp

package info (click to toggle)
spring 98.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,928 kB
  • ctags: 60,665
  • sloc: cpp: 356,167; ansic: 39,434; python: 12,228; java: 12,203; awk: 5,856; sh: 1,719; xml: 997; perl: 405; php: 253; objc: 194; makefile: 72; sed: 2
file content (120 lines) | stat: -rw-r--r-- 3,494 bytes parent folder | download | duplicates (2)
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef PATH_CONTROLLER_H
#define PATH_CONTROLLER_H

#include "System/float3.h"

class CUnit;
class CFeature;
struct MoveDef;

// provides control inputs for a ground-unit following a path
//
// inputs are not required to obey a unit's "physical" limits
// (but doing so is a good idea because they are NOT clamped
// before being applied)
//
// TODO: for crowds, track units with the same move order
class IPathController {
public:
	static IPathController* GetInstance(CUnit* owner);
	static void FreeInstance(IPathController* instance);

	// if a unit has a path to follow (and is not stunned,
	// being built, etc) this gets called every sim-frame
	virtual float GetDeltaSpeed(
		unsigned int pathID,
		float targetSpeed,  // max. speed <owner> is ALLOWED to be moving at
		float currentSpeed, // speed <owner> is currently moving at
		float maxAccRate,
		float maxDecRate,
		bool wantReverse,
		bool isReversing
	) const = 0;

	// if a unit has a path to follow (and is not stunned,
	// being built, etc) this gets called every sim-frame
	#if 1
	virtual short GetDeltaHeading(
		unsigned int pathID,
		short newHeading,
		short oldHeading,
		float maxTurnRate
	) const = 0;
	#endif

	virtual short GetDeltaHeading(
		unsigned int pathID,
		short newHeading,
		short oldHeading,
		float maxTurnSpeed,
		float maxTurnAccel,
		float turnBrakeDist,
		float* curTurnSpeed
	) const = 0;

	virtual bool AllowSetTempGoalPosition(unsigned int pathID, const float3& pos) const = 0;
	virtual void SetTempGoalPosition(unsigned int pathID, const float3& pos) = 0;
	virtual void SetRealGoalPosition(unsigned int pathID, const float3& pos) = 0;

	virtual bool IgnoreTerrain(const MoveDef& md, const float3& pos) const = 0;
	// if these return true, the respective collisions are NOT handled
	virtual bool IgnoreCollision(const CUnit* collider, const CUnit* collidee) const = 0;
	virtual bool IgnoreCollision(const CUnit* collider, const CFeature* collidee) const = 0;

protected:
	IPathController(CUnit* owner_): owner(owner_) {}
	virtual ~IPathController() {}

	CUnit* owner;
};


class GMTDefaultPathController: public IPathController {
public:
	GMTDefaultPathController(CUnit* owner_): IPathController(owner_) {}

	float GetDeltaSpeed(
		unsigned int pathID,
		float targetSpeed,
		float currentSpeed,
		float maxAccRate,
		float maxDecRate,
		bool wantReverse,
		bool isReversing
	) const;

	#if 1
	short GetDeltaHeading(
		unsigned int pathID,
		short newHeading,
		short oldHeading,
		float maxTurnRate
	) const;
	#endif

	short GetDeltaHeading(
		unsigned int pathID,
		short newHeading,
		short oldHeading,
		float maxTurnSpeed,
		float maxTurnAccel,
		float turnBrakeDist,
		float* curTurnSpeed
	) const;

	bool AllowSetTempGoalPosition(unsigned int pathID, const float3& pos) const { return true; }
	void SetTempGoalPosition(unsigned int pathID, const float3& pos) { realGoalPos = pos; }
	void SetRealGoalPosition(unsigned int pathID, const float3& pos) { tempGoalPos = pos; }

	bool IgnoreTerrain(const MoveDef& md, const float3& pos) const;
	bool IgnoreCollision(const CUnit* collider, const CUnit* collidee) const { return false; }
	bool IgnoreCollision(const CUnit* collider, const CFeature* collidee) const { return false; }

private:
	float3 realGoalPos; // where <owner> ultimately wants to go (its final waypoint)
	float3 tempGoalPos; // where <owner> currently wants to go (its next waypoint)
};

#endif