-
Notifications
You must be signed in to change notification settings - Fork 2
/
BaczekKPAI.h
163 lines (117 loc) · 4.44 KB
/
BaczekKPAI.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// GroupAI.h: interface for the CGroupAI class.
// Dont modify this file
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_GroupAI_H__10718E36_5CDF_4CD4_8D90_F41311DD2694__INCLUDED_)
#define AFX_GroupAI_H__10718E36_5CDF_4CD4_8D90_F41311DD2694__INCLUDED_
#pragma once
#include <map>
#include <set>
#include <vector>
#include "ExternalAI/IGlobalAI.h"
#include "ExternalAI/IAICallback.h"
#include "ExternalAI/IAICheats.h"
#include "GUI/StatusFrame.h"
#include "InfluenceMap.h"
#include "PythonScripting.h"
#include "TopLevelAI.h"
using namespace std;
class Log;
class Unit;
class BaczekKPAI : public IGlobalAI
{
public:
static const char AI_NAME[];
static const char AI_VERSION[];
BaczekKPAI();
virtual ~BaczekKPAI();
void InitAI(IGlobalAICallback* callback, int team);
void UnitCreated(int unit, int builder); //called when a new unit is created on ai team
void UnitFinished(int unit); //called when an unit has finished building
void UnitDestroyed(int unit,int attacker); //called when a unit is destroyed
void EnemyEnterLOS(int enemy);
void EnemyLeaveLOS(int enemy);
void EnemyEnterRadar(int enemy);
void EnemyLeaveRadar(int enemy);
void EnemyDamaged(int damaged,int attacker,float damage,float3 dir); //called when an enemy inside los or radar is damaged
void EnemyDestroyed(int enemy,int attacker); //will be called if an enemy inside los or radar dies (note that leave los etc will not be called then)
void UnitIdle(int unit); //called when a unit go idle and is not assigned to any group
void GotChatMsg(const char* msg,int player); //called when someone writes a chat msg
void UnitDamaged(int damaged,int attacker,float damage,float3 dir); //called when one of your units are damaged
void UnitMoveFailed(int unit);
int HandleEvent (int msg,const void *data);
//called every frame
void Update();
void DumpStatus();
void FindGeovents();
IGlobalAICallback* callback;
IAICallback* cb;
IAICheats* cheatcb;
set<int> myUnits;
set<int> losEnemies;
// oldEnemies is used to find units that changed
vector<int> oldEnemies;
vector<int> allEnemies;
vector<int> friends;
// units
Unit* unitTable[MAX_UNITS];
virtual void Load(IGlobalAICallback* callback,std::ifstream *ifs){};
virtual void Save(std::ifstream *ifs){};
const char *datadir;
const char *statusName;
struct MapInfo {
int w, h;
int squareSize;
};
MapInfo map;
vector<float3> geovents;
set<int> enemyBases;
InfluenceMap *influence;
PythonScripting *python;
TopLevelAI* toplevel;
bool debugLines;
bool debugMsgs;
#ifdef USE_STATUS_WINDOW
MyFrame *frame;
#endif
std::vector<const UnitDef*> unitDefById;
void InitializeUnitDefs();
const UnitDef* GetUnitDefById(int id) { return unitDefById[id]; }
Unit* GetUnit(int id) { return unitTable[id]; }
void GetAllUnitsInRadius(std::vector<int>& vec, float3 pos, float radius);
float EstimateSqDistancePF(int unitID, const float3& start, const float3& end);
float EstimateSqDistancePF(const UnitDef* unitdef, const float3& start, const float3& end);
// slower versions for precise distance
float EstimateDistancePF(int unitID, const float3& start, const float3& end);
float EstimateDistancePF(const UnitDef* unitdef, const float3& start, const float3& end);
// heightmap
float GetGroundHeight(float x, float y);
// easier spatial queries
void GetEnemiesInRadius(float3 pos, float radius, std::vector<int>& output)
{
int enemies[MAX_UNITS];
int numenemies;
numenemies = cheatcb->GetEnemyUnits(enemies, pos, radius);
output.clear();
output.reserve(numenemies);
for (int i=0; i<numenemies; ++i)
output.push_back(enemies[i]);
}
std::string GetRoleUnitName(const char* role)
{
const char* side = cb->GetTeamSide(cb->GetMyTeam());
std::string configval = (std::string(side)+"_"+role);
return python->GetStringValue(configval.c_str(), std::string());
}
void SendTextMsg(const char *msg, int zone)
{
if (debugMsgs)
cb->SendTextMsg(msg, zone);
}
int CreateLineFigure(float3 pos1, float3 pos2, float width, int arrow, int lifeTime, int figureGroupId)
{
if (debugLines)
return cb->CreateLineFigure(pos1, pos2, width, arrow, lifeTime, figureGroupId);
else return 0;
}
};
#endif // !defined(AFX_GroupAI_H__10718E36_5CDF_4CD4_8D90_F41311DD2694__INCLUDED_)