File: Unit.h

package info (click to toggle)
spring 106.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 55,260 kB
  • sloc: cpp: 543,946; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (107 lines) | stat: -rw-r--r-- 2,766 bytes parent folder | download | duplicates (3)
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
#ifndef KAIK_UNIT_HDR
#define KAIK_UNIT_HDR

#include "Defines.h"

namespace springLegacyAI {
	struct UnitDef;
} // namespace springLegacyAI

struct AIClasses;
struct Command;

class CUNIT {
public:
	CR_DECLARE(CUNIT)

	CUNIT(void);
	CUNIT(AIClasses* ai);
	~CUNIT();
	void PostLoad();

	// misc. info
	float3 pos() const;
	float Health() const;
	UnitCategory category() const;

	const UnitDef* def() const;
	int uid;
	bool isDead;

	// the attackgroup that the unit might belong to
	// (added to support some AttackHandler/group features)
	int groupID;

	// 0: mine, 1: allied, 2: enemy -1: non-existant
	int owner() const;

	bool CanAttack(int otherUnit) const;
	bool CanAttackMe(int otherUnit) const;

	// used in groups when units don't respond to move orders
	int stuckCounter;
	float3 earlierPosition;
	// used in groups to microcontrol units to their max range of the chosen target
	int maneuverCounter;

	// specialized
	bool ReclaimBestFeature(bool metal, float radius = 2048);

	// construction
	int GetBestBuildFacing(const float3& pos) const;
	bool Build_ClosestSite(const UnitDef* def, const float3& pos, int separation = DEFCBS_SEPARATION, float radius = DEFCBS_RADIUS);
	bool FactoryBuild(const UnitDef* built) const;

	// nuke- and hub-related functions
	bool NukeSiloBuild(void) const;
	bool isHub(void) const;
	bool HubBuild(const UnitDef* built) const;


	// target-based abilities
	bool Attack(int target) const;
	bool Capture(int target) const;
	bool Guard(int target) const;
	bool Load(int target) const;
	bool Reclaim(int target) const;
	bool Repair(int target) const;
	bool Ressurect(int target) const;
	bool Upgrade(int target, const UnitDef*) const;

	// location point abilities
	bool Build(float3 pos, const UnitDef* unit, int facing) const;
	bool BuildShift(float3 pos, const UnitDef* unit, int facing) const;
	bool Move(float3 pos) const;
	bool MoveShift(float3 pos) const;
	bool Patrol(float3 pos) const;
	bool PatrolShift(float3 pos) const;

	// radius abilities
	bool Attack(float3 pos, float radius) const;
	bool Ressurect(float3 pos, float radius) const;
	bool Reclaim(float3 pos, float radius) const;
	bool Capture(float3 pos, float radius) const;
	bool Restore(float3 pos, float radius) const;
	bool Load(float3 pos, float radius) const;
	bool Unload(float3 pos, float radius) const;

	// toggable abilities
	bool Cloaking(bool on) const;
	bool OnOff(bool on) const;

	// special abilities
	bool SelfDestruct() const;
	bool SetFireState(int state) const;
	bool Stop() const;

	static bool IsCommander(const UnitDef* udef);
private:
	AIClasses* ai;

	// command generators
	Command MakePosCommand(int cmdID, float3 pos, float radius = -1.0f, int facing = -1) const;
	Command MakeIntCommand(int cmdID, int param) const;
};


#endif