File: MoveType.h

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 (97 lines) | stat: -rw-r--r-- 3,469 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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef MOVETYPE_H
#define MOVETYPE_H

#include "System/creg/creg_cond.h"
#include "Sim/Misc/AirBaseHandler.h"
#include "System/Object.h"
#include "System/float3.h"

class CUnit;

class AMoveType : public CObject
{
	CR_DECLARE(AMoveType)

public:
	AMoveType(CUnit* owner);
	virtual ~AMoveType() {}

	virtual void StartMovingRaw(const float3 moveGoalPos, float moveGoalRadius) {}
	virtual void StartMoving(float3 pos, float goalRadius) = 0;
	virtual void StartMoving(float3 pos, float goalRadius, float speed) = 0;
	virtual void KeepPointingTo(float3 pos, float distance, bool aggressive) = 0;
	virtual void KeepPointingTo(CUnit* unit, float distance, bool aggressive);
	virtual void StopMoving(bool callScript = false, bool hardStop = false) = 0;
	virtual bool CanApplyImpulse(const float3&) { return false; }
	virtual void LeaveTransport() {}

	// generic setter for Lua-writable values
	virtual bool SetMemberValue(unsigned int memberHash, void* memberValue);

	virtual void SetGoal(const float3& pos, float distance = 0.0f) { goalPos = pos; }

	// NOTE:
	//     SetMaxSpeed is ONLY called by LuaSyncedMoveCtrl now
	//     other code (CommandAI) modifies a unit's speed only
	//     through SetMaxWantedSpeed, via SET_WANTED_MAX_SPEED
	//     commands
	// NOTE:
	//     clamped because too much code in the derived
	//     MoveType classes expects maxSpeed to be != 0
	virtual void SetMaxSpeed(float speed) { maxSpeed = std::max(0.001f, speed); }
	virtual void SetWantedMaxSpeed(float speed) { maxWantedSpeed = speed; }
	virtual void SetManeuverLeash(float leashLength) { maneuverLeash = leashLength; }

	virtual bool Update() = 0;
	virtual void SlowUpdate();

	virtual bool IsSkidding() const { return false; }
	virtual bool IsFlying() const { return false; }
	virtual bool IsReversing() const { return false; }

	virtual void ReservePad(CAirBaseHandler::LandingPad* lp) { /* AAirMoveType only */ }
	virtual void UnreservePad(CAirBaseHandler::LandingPad* lp) { /* AAirMoveType only */ }
	virtual CAirBaseHandler::LandingPad* GetReservedPad() { return NULL; }

	bool WantsRepair() const;
	bool WantsRefuel() const;

	void SetRepairBelowHealth(float rbHealth) { repairBelowHealth = rbHealth; }

	float GetMaxSpeed() const { return maxSpeed; }
	float GetMaxSpeedDef() const { return maxSpeedDef; }
	float GetMaxWantedSpeed() const { return maxWantedSpeed; }
	float GetRepairBelowHealth() const { return repairBelowHealth; }
	float GetManeuverLeash() const { return maneuverLeash; }

	float CalcStaticTurnRadius() const;

public:
	CUnit* owner;

	float3 goalPos;
	float3 oldPos;             // owner position at last Update()
	float3 oldSlowUpdatePos;   // owner position at last SlowUpdate()

	/// TODO: probably should move the code in CUnit that reads this into the movement classes
	bool useHeading;

	enum ProgressState {
		Done   = 0,
		Active = 1,
		Failed = 2
	};
	ProgressState progressState;

protected:
	float maxSpeed;            // current maximum speed owner is allowed to reach (changes with eg. guard orders)
	float maxSpeedDef;         // default maximum speed owner can reach (as defined by its UnitDef, never changes)
	float maxWantedSpeed;      // maximum speed (temporarily) set by a CMD_SET_WANTED_MAX_SPEED modifier command

	float repairBelowHealth;
	float maneuverLeash;       // maximum distance away a target can be and still be chased
};

#endif // MOVETYPE_H