File: CGroup.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 (129 lines) | stat: -rw-r--r-- 2,544 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
#ifndef CGROUP_H
#define CGROUP_H

#include <map>

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

class ATask;
class CUnit;
class AIClasses;
class UnitType;

/* NOTE: CGroup silently assumes that waterunits will not be merged with
 * non-water units as a group, aswell as builders with attackers
 */
class CGroup: public ARegistrar {
	public:

		CGroup(AIClasses *ai): ARegistrar(counter, std::string("group")) {
			this->ai = ai;
			reset();
			counter++;
		}
		CGroup() {};
		~CGroup() {};

		/* Group counter */
		static int counter;

		/* Tech level */
		int techlvl;

		/* movetype, the movetype with the smallest slope */
		int moveType;

		/* corresponding maxSlope */
		float maxSlope;

		/* The group strength */
		float strength;

		/* The group's moveSpeed */
		float speed;

		/* The group's buildSpeed */
		float buildSpeed;

		/* The group's footprint */
		int size;

		/* The group maxrange */
		float range, buildRange, los;

		/* Is this group busy? */
		bool busy;

		/* Remove this group, preserve units */
		void remove();

		/* Overload */
		void remove(ARegistrar &unit);

		/* Reset for object re-usage */
		void reset();

		/* The units <id, CUnit*> */
		std::map<int, CUnit*> units;

		/* Reclaim an entity (unit, feature etc.) */
		void reclaim(int entity);

		/* Set this group to micro mode true/false */
		void micro(bool on);

		/* Add a unit to the group */
		void addUnit(CUnit &unit);

		/* Get the first unit of the group */
		CUnit* firstUnit();

		/* Merge another group with this group */
		void merge(CGroup &group);

		/* Enable abilities on units like cloaking */
		void abilities(bool on);

		/* See if the entire group is idle */
		bool isIdle();

		/* See if the group is microing */
		bool isMicroing();

		/* Get the position of the group */
		float3 pos();

		void assist(ATask &task);
		void attack(int target, bool enqueue = false);
		void build(float3 &pos, UnitType *ut);
		void stop();
		void move(float3 &pos, bool enqueue = false);
		void guard(int target, bool enqueue = false);
		void wait();
		void unwait();

		/* Get the maximal lateral dispersion */
		int maxLength();

		/* Is position reachable by group? */
		bool canReach(float3 &pos);

		bool canAttack(int uid);

		bool canAdd(CUnit *unit);
		
		bool canMerge(CGroup *group);

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

		RegistrarType regtype() { return REGT_GROUP; }

	private:
		AIClasses *ai;

		void recalcProperties(CUnit *unit, bool reset = false);
};

#endif