File: AAIUnitTable.h

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (120 lines) | stat: -rwxr-xr-x 3,279 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
// -------------------------------------------------------------------------
// AAI
//
// A skirmish AI for the Spring engine.
// Copyright Alexander Seizinger
//
// Released under GPL license: see LICENSE.html for more information.
// -------------------------------------------------------------------------

#pragma once

#include <set>
#include "aidef.h"

using std::set;

class AAI;
class AAIBuildTable;
class AAIExecute;

class AAIUnitTable
{
public:
	AAIUnitTable(AAI *ai, AAIBuildTable *bt);
	~AAIUnitTable(void);

	bool AddUnit(int unit_id, int def_id, AAIGroup *group = 0, AAIConstructor *cons = 0);
	void RemoveUnit(int unit_id);

	void AddScout(int unit_id);
	void RemoveScout(int unit_id);

	void AddConstructor(int unit_id, int def_id);
	void RemoveConstructor(int unit_id, int def_id);

	void AddCommander(int unit_id, int def_id);
	void RemoveCommander(int unit_id, int def_id);

	void AddExtractor(int unit_id);
	void RemoveExtractor(int unit_id);

	void AddPowerPlant(int unit_id, int def_id);
	void RemovePowerPlant(int unit_id);

	void AddMetalMaker(int unit_id, int def_id);
	void RemoveMetalMaker(int unit_id);

	void AddJammer(int unit_id, int def_id);
	void RemoveJammer(int unit_id);

	void AddRecon(int unit_id, int def_id);
	void RemoveRecon(int unit_id);

	void AddStationaryArty(int unit_id, int def_id);
	void RemoveStationaryArty(int unit_id);

	AAIConstructor* FindBuilder(int building, bool commander);

	// finds closest builder and stores its distance to pos in min_dist
	AAIConstructor* FindClosestBuilder(int building, float3 *pos, bool commander, float *min_dist);

	AAIConstructor* FindClosestAssistant(float3 pos, int importance, bool commander);

	void EnemyKilled(int unit);

	void SetUnitStatus(int unit, UnitTask status);

	void AssignGroupToEnemy(int unit, AAIGroup *group);

	// determine whether unit with specified def/unit id is commander/constrcutor
	bool IsUnitCommander(int unit_id);
	bool IsDefCommander(int def_id);
	bool IsBuilder(int unit_id);

	// called when unit of specified catgeory has been created (= construction started)
	void UnitCreated(UnitCategory category);

	// called when construction of unit has been finished
	void UnitFinished(UnitCategory category);

	// called when unit request failed (e.g. builder has been killed on the way to the crash site)
	void UnitRequestFailed(UnitCategory category);

	void UnitRequested(UnitCategory category, int number = 1);

	// get/set methods
	//int GetActiveScouts();
	//int GetActiveBuilders();
	//int GetActiveFactories();
	void ActiveUnitKilled(UnitCategory category);
	void FutureUnitKilled(UnitCategory category);

	AAI *ai;
	AAIExecute *execute;
	AAIBuildTable *bt;
	IAICallback* cb;

	// units[i].unitId = -1 -> not used , -2 -> enemy unit
	vector<AAIUnit> units;

	// id of commander
	int cmdr;

	set<int> scouts;
	set<int> constructors;
	set<int> metal_makers;
	set<int> jammers;
	set<int> recon;
	set<int> extractors;
	set<int> power_plants;
	set<int> stationary_arty;

	// number of active/under construction units of all different types
	int activeUnits[(int)MOBILE_CONSTRUCTOR+1];
	int futureUnits[(int)MOBILE_CONSTRUCTOR+1];
	int requestedUnits[(int)MOBILE_CONSTRUCTOR+1];

	int activeBuilders, futureBuilders;
	int activeFactories, futureFactories;
};