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_H
11 #define AAI_H
12 
13 #include "LegacyCpp/IGlobalAI.h"
14 #include <list>
15 #include <vector>
16 
17 namespace springLegacyAI {
18 	class IAICallback;
19 }
20 
21 using namespace springLegacyAI;
22 using namespace std;
23 
24 class AAIExecute;
25 class Profiler;
26 class AAIBrain;
27 class AAIBuildTask;
28 class AAIAirForceManager;
29 class AAIAttackManager;
30 class AAIBuildTable;
31 class AAIUnitTable;
32 class AAIMap;
33 class AAIGroup;
34 
35 class AAI : public IGlobalAI
36 {
37 public:
38 	AAI();
39 	virtual ~AAI();
40 
41 	void InitAI(IGlobalAICallback* callback, int team);
42 
43 	void UnitCreated(int unit, int builder);								//called when a new unit is created on ai team
44 	void UnitFinished(int unit);											//called when an unit has finished building
45 	void UnitIdle(int unit);												//called when a unit go idle and is not assigned to any group
46 	void UnitDestroyed(int unit, int attacker);								//called when a unit is destroyed
47 	void UnitDamaged(int damaged,int attacker,float damage,float3 dir);		//called when one of your units are damaged
48 	void UnitMoveFailed(int unit);
49 
50 	void EnemyEnterLOS(int enemy);
51 	void EnemyLeaveLOS(int enemy);
52 
53 	void EnemyEnterRadar(int enemy);				//called when an enemy enters radar coverage (not called if enemy go directly from not known -> los)
54 	void EnemyLeaveRadar(int enemy);				//called when an enemy leaves radar coverage (not called if enemy go directly from inlos -> now known)
55 
RecvChatMessage(const char *,int)56 	void RecvChatMessage(const char* /*msg*/,int /*player*/) {}	//called when someone writes a chat msg
RecvLuaMessage(const char *,const char **)57 	void RecvLuaMessage(const char* /*inData*/, const char** /*outData*/) {}
58 
EnemyDamaged(int,int,float,float3)59 	void EnemyDamaged(int /*damaged*/,int /*attacker*/,float /*damage*/,float3 /*dir*/) {}	//called when an enemy inside los or radar is damaged
60 	void EnemyDestroyed(int enemy, int attacker);
61 	void Log(const char* format, ...);
62 	void LogConsole(const char* format, ...);
63 
64 	int HandleEvent(int msg, const void *data);
65 	//return count of aai instances
GetInstances()66 	int GetInstances() { return aai_instance; }
67 
68 	// called every frame
69 	void Update();
70 
Getcb()71 	IAICallback* Getcb() { return cb; }
Getaicb()72 	IGlobalAICallback* Getaicb() { return aicb; }
Getside()73 	int Getside()
74 	{
75 		assert(side>=0);
76 		assert(side<=2);
77 		return side;
78 	}
Getbuild_tasks()79 	list<AAIBuildTask*>& Getbuild_tasks() { return build_tasks; }
Getbrain()80 	AAIBrain* Getbrain() { return brain; }
Getexecute()81 	AAIExecute* Getexecute() { return execute; }
Getut()82 	AAIUnitTable* Getut() { return ut; }
Getmap()83 	AAIMap* Getmap() { return map; }
Getaf()84 	AAIAirForceManager* Getaf() { return af; }
Getam()85 	AAIAttackManager* Getam() { return am; }
Getbt()86 	AAIBuildTable* Getbt() { return bt; }
Getgroup_list()87 	vector<list<AAIGroup*> >& Getgroup_list() { return group_list; }
88 
89 private:
GetProfiler()90 	Profiler* GetProfiler(){ return profiler; }
91 
92 	// callbacks
93 	IAICallback* cb;
94 	IGlobalAICallback* aicb;
95 
96 	// side 1= arm, 2 = core, 0 = neutral
97 	int side;
98 
99 	// list of buildtasks
100 	list<AAIBuildTask*> build_tasks;
101 
102 	AAIBrain *brain;			// makes decisions
103 	AAIExecute *execute;		// executes all kinds of tasks
104 	AAIUnitTable *ut;			// unit table
105 	AAIBuildTable *bt;			// buildtable for the different units
106 	AAIMap *map;				// keeps track of all constructed buildings and searches new constr. sites
107 	AAIAirForceManager *af;		// coordinates the airforce
108 	AAIAttackManager *am;		// coordinates combat forces
109 
110 	vector<list<AAIGroup*> > group_list;  // unit groups
111 
112 	Profiler* profiler;
113 	FILE *file;
114 	bool initialized;
115 
116 	// if there is more than one instance of AAI, make sure to allocate/free memory only once
117 	static int aai_instance;
118 
119 };
120 
121 #endif
122 
123