File: CUnit.h

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (121 lines) | stat: -rw-r--r-- 2,517 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
#ifndef CUNIT_H
#define CUNIT_H

#include <map>
#include <iostream>

#include "ARegistrar.h"
#include "headers/HEngine.h"

class AIClasses;
class UnitType;
class CGroup;

/* Building facings, NOTE: this order is important! */
enum facing{SOUTH, EAST, NORTH, WEST, NONE};

/* Map quadrants */
enum quadrant {NORTH_WEST, NORTH_EAST, SOUTH_WEST, SOUTH_EAST};

class CUnit: public ARegistrar {
	public:
		CUnit(): ARegistrar() {}
		CUnit(AIClasses *ai, int uid, int bid): ARegistrar(uid) {
			this->ai = ai;
			reset(uid, bid);
		}
		~CUnit(){}

		const UnitDef *def;
		UnitType *type;
		int builtBy;
		int techlvl;

		/* Remove the unit from everywhere registered */
		void remove();

		/* Overloaded */
		void remove(ARegistrar &reg);

		/* Reset this object */
		void reset(int uid, int bid);

		int queueSize();

		/* Attack a unit */
		bool attack(int target, bool enqueue = false);

		/* Move a unit forward by dist */
		bool moveForward(float dist, bool enqueue = true);

		/* Move random */
		bool moveRandom(float radius, bool enqueue = false);

		/* Move unit with id uid to position pos */
		bool move(float3 &pos, bool enqueue = false);

		/* Set a unit (e.g. mmaker) on or off */
		bool setOnOff(bool on);

		/* Let unit with id uid build a unit with a certain facing (NORTH,
		 * SOUTH, EAST, WEST) at position pos 
		 */
		bool build(UnitType *toBuild, float3 &pos);

		/* Build a unit in a certain factory */
		bool factoryBuild(UnitType *toBuild, bool enqueue = false);

		/* Repair (or assist) a certain unit */
		bool repair(int target);

		/* Cloak a unit */
		bool cloak(bool on);

		/* Guard a certain unit */
		bool guard(int target, bool enqueue = true);

		/* Stop doing what you did */
		bool stop();

		/* Wait with what you are doing */
		bool wait();

		bool reclaim(float3 pos, float radius);
		bool reclaim(int target, bool enqueue = false);

		/* Undo wait command */
		bool unwait();

		bool waiting;

		bool micro(bool on);

		bool isMicroing();

		bool isOn();

		float3 pos();

		CGroup *group; // group unit belongs to

		/* Get best facing */
		facing getBestFacing(float3 &pos);

		/* Get quadrant */
		quadrant getQuadrant(float3 &pos);

		RegistrarType regtype() { return REGT_UNIT; } 

		/* output stream */
		friend std::ostream& operator<<(std::ostream &out, const CUnit &unit);

	private:
		AIClasses *ai;

		bool microing;

		Command createPosCommand(int cmd, float3 pos, float radius = -1.0f, facing f = NONE);
		Command createTargetCommand(int cmd, int target);
};

#endif