1 // -------------------------------------------------------------------------
2 // AAI
3 //
4 // A skirmish AI for the Spring engine.
5 // Copyright Alexander Seizinger
6 //
7 // Released under GPL license: see LICENSE.html for more information.
8 // -------------------------------------------------------------------------
9 
10 #ifndef AAI_UNITTABLE_H
11 #define AAI_UNITTABLE_H
12 
13 #include <set>
14 
15 using std::set;
16 
17 #include "aidef.h"
18 
19 class AAI;
20 class AAIBuildTable;
21 class AAIExecute;
22 class AAIConstructor;
23 
24 class AAIUnitTable
25 {
26 public:
27 	AAIUnitTable(AAI *ai);
28 	~AAIUnitTable(void);
29 
30 	bool AddUnit(int unit_id, int def_id, AAIGroup *group = 0, AAIConstructor *cons = 0);
31 	void RemoveUnit(int unit_id);
32 
33 	void AddScout(int unit_id);
34 	void RemoveScout(int unit_id);
35 
36 	void AddConstructor(int unit_id, int def_id);
37 	void RemoveConstructor(int unit_id, int def_id);
38 
39 	void AddCommander(int unit_id, int def_id);
40 	void RemoveCommander(int unit_id, int def_id);
41 
42 	void AddExtractor(int unit_id);
43 	void RemoveExtractor(int unit_id);
44 
45 	void AddPowerPlant(int unit_id, int def_id);
46 	void RemovePowerPlant(int unit_id);
47 
48 	void AddMetalMaker(int unit_id, int def_id);
49 	void RemoveMetalMaker(int unit_id);
50 
51 	void AddJammer(int unit_id, int def_id);
52 	void RemoveJammer(int unit_id);
53 
54 	void AddRecon(int unit_id, int def_id);
55 	void RemoveRecon(int unit_id);
56 
57 	void AddStationaryArty(int unit_id, int def_id);
58 	void RemoveStationaryArty(int unit_id);
59 
60 	AAIConstructor* FindBuilder(int building, bool commander);
61 
62 	// finds closest builder and stores its distance to pos in min_dist
63 	AAIConstructor* FindClosestBuilder(int building, float3 *pos, bool commander, float *min_dist);
64 
65 	AAIConstructor* FindClosestAssistant(float3 pos, int importance, bool commander);
66 
67 	void EnemyKilled(int unit);
68 
69 	void SetUnitStatus(int unit, UnitTask status);
70 
71 	void AssignGroupToEnemy(int unit, AAIGroup *group);
72 
73 	// determine whether unit with specified def/unit id is commander/constrcutor
74 	bool IsDefCommander(int def_id);
75 	bool IsBuilder(int unit_id);
76 
77 	// called when unit of specified catgeory has been created (= construction started)
78 	void UnitCreated(UnitCategory category);
79 
80 	// called when construction of unit has been finished
81 	void UnitFinished(UnitCategory category);
82 
83 	// called when unit request failed (e.g. builder has been killed on the way to the crash site)
84 	void UnitRequestFailed(UnitCategory category);
85 
86 	void UnitRequested(UnitCategory category, int number = 1);
87 
88 	// get/set methods
89 	//int GetActiveScouts();
90 	//int GetActiveBuilders();
91 	//int GetActiveFactories();
92 	void ActiveUnitKilled(UnitCategory category);
93 	void FutureUnitKilled(UnitCategory category);
94 
95 	// units[i].unitId = -1 -> not used , -2 -> enemy unit
96 	vector<AAIUnit> units;
97 
98 	// id of commander
99 	int cmdr;
100 	set<int> constructors;
101 	set<int> metal_makers;
102 	set<int> jammers;
103 	set<int> recon;
104 
105 	// number of active/under construction units of all different types
106 	int activeUnits[(int)MOBILE_CONSTRUCTOR+1];
107 	int futureUnits[(int)MOBILE_CONSTRUCTOR+1];
108 	int requestedUnits[(int)MOBILE_CONSTRUCTOR+1];
109 	int activeBuilders, futureBuilders;
110 	int activeFactories, futureFactories;
111 private:
112 	bool IsUnitCommander(int unit_id);
113 	set<int> scouts;
114 	set<int> extractors;
115 	set<int> power_plants;
116 	set<int> stationary_arty;
117 	AAI *ai;
118 
119 };
120 
121 #endif
122 
123