File: CCoverageCell.h

package info (click to toggle)
spring 104.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,512 kB
  • sloc: cpp: 391,093; ansic: 79,943; python: 12,356; java: 12,201; awk: 5,889; sh: 1,826; xml: 655; makefile: 486; perl: 405; php: 211; objc: 194; sed: 2
file content (100 lines) | stat: -rw-r--r-- 2,302 bytes parent folder | download | duplicates (4)
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
#ifndef E323_CCOVERAGECELL_H
#define E323_CCOVERAGECELL_H

#include <string>
#include <map>

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

class AIClasses;
class ARegistrar;
struct UnitType;

class CCoverageCell: public ARegistrar {

public:
	enum NType {
		UNDEFINED,
		DEFENSE_GROUND,   ///< autofire at ground
		DEFENSE_ANTIAIR,  ///< autofire at air
		DEFENSE_UNDERWATER,
		DEFENSE_ANTINUKE, ///< stockpile required, autofire at nuke missles
		DEFENSE_SHIELD,   ///< on-offable defense, does not shoot
		DEFENSE_JAMMER,
		BUILD_ASSISTER,   ///< static builders or assisters
		ECONOMY_BOOSTER   ///< pylons in CA
	};

	CCoverageCell()
			: type(UNDEFINED)
			, ai(NULL)
			, range(0.0f)
			, unit(NULL)
	{
		if (type2str.empty()) {
			type2str[UNDEFINED] = "UNDEFINED";
			type2str[DEFENSE_GROUND] = "DEFENSE_GROUND";
			type2str[DEFENSE_ANTIAIR] = "DEFENSE_ANTIAIR";
			type2str[DEFENSE_UNDERWATER] = "DEFENSE_UNDERWATER";
			type2str[DEFENSE_ANTINUKE] = "DEFENSE_ANTINUKE";
			type2str[DEFENSE_SHIELD] = "DEFENSE_SHIELD";
			type2str[DEFENSE_JAMMER] = "DEFENSE_JAMMER";
			type2str[BUILD_ASSISTER] = "BUILD_ASSISTER";
			type2str[ECONOMY_BOOSTER] = "ECONOMY_BOOSTER";
		}
	}
	CCoverageCell(AIClasses* ai, NType type = UNDEFINED, CUnit* unit = NULL)
			: type(type)
			, ai(ai)
			, range(0.0f)
			, unit(NULL)
	{
		if (unit) {
			setCore(unit);
		}
	}

	bool isVacant() const { return unit == NULL; }

	float3 getCenter() const { return unit ? unit->pos() : ERRORVECTOR; }

	float getRange() { return range; }

	bool isInRange(const float3& pos) const;

	void setCore(CUnit* u);

	CUnit* getCore() const { return unit; }

	void update(std::list<CUnit*>& uncovered);

	void remove();
	/* Overloaded */
	void remove(ARegistrar& obj);
	/* Overloaded */
	ARegistrar::NType regtype() const { return ARegistrar::COVERAGE_CELL; }

	bool addUnit(CUnit* u);
	/* Output stream */
	friend std::ostream& operator<<(std::ostream& out, const CCoverageCell& obj);


	static std::map<NType, std::string> type2str;
	NType type;
	/// units covered by current cell
	std::map<int, CUnit*> units;

//protected:
	AIClasses* ai;

private:
	/// cell range
	float range;
	/// cell core unit: the source of coverage
	CUnit* unit;
};

#endif // E323_CCOVERAGECELL_H