File: AIAICallback.h

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (229 lines) | stat: -rw-r--r-- 8,177 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
	Copyright (c) 2008 Robin Vobruba <hoijui.quaero@gmail.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _AIAICALLBACK_H
#define _AIAICALLBACK_H

#include "ExternalAI/IAICallback.h"

struct SSkirmishAICallback;

/**
 * The AI side wrapper over the C AI interface for IAICallback.
 */
class CAIAICallback : public IAICallback {
public:
	CAIAICallback();
	CAIAICallback(int teamId, const SSkirmishAICallback* sAICallback);

	virtual void SendTextMsg(const char* text, int zone);
	virtual void SetLastMsgPos(float3 pos);
	virtual void AddNotification(float3 pos, float3 color, float alpha);

	virtual bool SendResources(float mAmount, float eAmount, int receivingTeam);

	virtual int SendUnits(const std::vector<int>& unitIDs, int receivingTeam);

	virtual bool PosInCamera(float3 pos, float radius);

	virtual int GetCurrentFrame();

	virtual int GetMyTeam();
	virtual int GetMyAllyTeam();
	virtual int GetPlayerTeam(int player);
	virtual const char* GetTeamSide(int team);

	virtual void* CreateSharedMemArea(char* name, int size);

	virtual void ReleasedSharedMemArea(char* name);

	virtual int CreateGroup();

	virtual void EraseGroup(int groupid);
	virtual bool AddUnitToGroup(int unitid, int groupid);

	virtual bool RemoveUnitFromGroup(int unitid);
	virtual int GetUnitGroup(int unitid);
	virtual const std::vector<CommandDescription>* GetGroupCommands(int unitid);
	virtual int GiveGroupOrder(int unitid, Command* c);

	virtual int GiveOrder(int unitid, Command* c);

	virtual const std::vector<CommandDescription>* GetUnitCommands(int unitid);
	virtual const CCommandQueue* GetCurrentUnitCommands(int unitid);

	virtual int GetUnitAiHint(int unitid);
	virtual int GetUnitTeam(int unitid);
	virtual int GetUnitAllyTeam(int unitid);
	virtual float GetUnitHealth(int unitid);
	virtual float GetUnitMaxHealth(int unitid);
	virtual float GetUnitSpeed(int unitid);
	virtual float GetUnitPower(int unitid);
	virtual float GetUnitExperience(int unitid);
	virtual float GetUnitMaxRange(int unitid);
	virtual bool IsUnitActivated (int unitid);
	virtual bool UnitBeingBuilt(int unitid);
	virtual const UnitDef* GetUnitDef(int unitid);

	virtual float3 GetUnitPos(int unitid);
	virtual int GetBuildingFacing(int unitid);
	virtual bool IsUnitCloaked(int unitid);
	virtual bool IsUnitParalyzed(int unitid);
	virtual bool IsUnitNeutral(int unitid);
	virtual bool GetUnitResourceInfo(int unitid,
			UnitResourceInfo* resourceInfo);

	virtual const UnitDef* GetUnitDef(const char* unitName);
	virtual const UnitDef* GetUnitDefById(int unitDefId);

	virtual int InitPath(float3 start, float3 end, int pathType);
	virtual float3 GetNextWaypoint(int pathid);
	virtual void FreePath(int pathid);

	virtual float GetPathLength(float3 start, float3 end, int pathType);

	virtual int GetEnemyUnits(int* unitIds, int unitIds_max);
	virtual int GetEnemyUnitsInRadarAndLos(int* unitIds, int unitIds_max);
	virtual int GetEnemyUnits(int* unitIds, const float3& pos, float radius,
			int unitIds_max);
	virtual int GetFriendlyUnits(int* unitIds, int unitIds_max);
	virtual int GetFriendlyUnits(int* unitIds, const float3& pos, float radius,
			int unitIds_max);
	virtual int GetNeutralUnits(int* unitIds, int unitIds_max);
	virtual int GetNeutralUnits(int* unitIds, const float3& pos, float radius,
			int unitIds_max);

	virtual int GetMapWidth();
	virtual int GetMapHeight();
	virtual const float* GetHeightMap();
	virtual const float* GetCornersHeightMap();
	virtual float GetMinHeight();
	virtual float GetMaxHeight();
	virtual const float* GetSlopeMap();

	virtual const unsigned short* GetLosMap();
	virtual int GetLosMapResolution();
	virtual const unsigned short* GetRadarMap();
	virtual const unsigned short* GetJammerMap();
	virtual const unsigned char* GetMetalMap();
	virtual const char* GetMapName();
	virtual const char* GetModName();

	virtual float GetElevation(float x, float z);

	virtual float GetMaxMetal() const;
	virtual float GetExtractorRadius() const;
	virtual float GetMinWind() const;
	virtual float GetMaxWind() const;
	virtual float GetCurWind() const;
	virtual float GetTidalStrength() const;
	virtual float GetGravity() const;

	virtual void LineDrawerStartPath(const float3& pos, const float* color);
	virtual void LineDrawerFinishPath();
	virtual void LineDrawerDrawLine(const float3& endPos, const float* color);
	virtual void LineDrawerDrawLineAndIcon(int cmdID, const float3& endPos,
			const float* color);
	virtual void LineDrawerDrawIconAtLastPos(int cmdID);
	virtual void LineDrawerBreak(const float3& endPos, const float* color);
	virtual void LineDrawerRestart();
	virtual void LineDrawerRestartSameColor();

	virtual int CreateSplineFigure(float3 pos1, float3 pos2, float3 pos3,
			float3 pos4, float width, int arrow, int lifetime, int group);
	virtual int CreateLineFigure(float3 pos1, float3 pos2, float width,
			int arrow, int lifetime, int group);
	virtual void SetFigureColor(int group, float red, float green, float blue,
			float alpha);
	virtual void DeleteFigureGroup(int group);

	virtual void DrawUnit(const char* name, float3 pos, float rotation,
			int lifetime, int team, bool transparent, bool drawBorder,
			int facing);

	virtual bool CanBuildAt(const UnitDef* unitDef, float3 pos, int facing);

	virtual float3 ClosestBuildSite(const UnitDef* unitdef, float3 pos,
			float searchRadius, int minDist, int facing);

	virtual bool GetProperty(int id, int property, void* dst);
	virtual bool GetValue(int id, void* dst);
	virtual int HandleCommand(int commandId, void* data);

	virtual int GetFileSize(const char* name);
	virtual bool ReadFile(const char* name, void* buffer, int bufferLen);

	virtual int GetSelectedUnits(int* unitIds, int unitIds_max);
	virtual float3 GetMousePos();
	virtual int GetMapPoints(PointMarker* pm, int pm_sizeMax, bool includeAllies);
	virtual int GetMapLines(LineMarker* lm, int lm_sizeMax, bool includeAllies);

	virtual float GetMetal();
	virtual float GetMetalIncome();
	virtual float GetMetalUsage();
	virtual float GetMetalStorage();

	virtual float GetEnergy();
	virtual float GetEnergyIncome();
	virtual float GetEnergyUsage();
	virtual float GetEnergyStorage();

	virtual int GetFeatures(int *features, int max);
	virtual int GetFeatures(int *features, int max, const float3& pos,
			float radius);
	virtual const FeatureDef* GetFeatureDef(int feature);
	virtual const FeatureDef* GetFeatureDefById(int featureDefId);
	virtual float GetFeatureHealth(int feature);
	virtual float GetFeatureReclaimLeft(int feature);
	virtual float3 GetFeaturePos(int feature);

	virtual int GetNumUnitDefs();
	virtual void GetUnitDefList(const UnitDef** list);
	virtual float GetUnitDefHeight(int def);
	virtual float GetUnitDefRadius(int def);

	virtual const WeaponDef* GetWeapon(const char* weaponName);
	virtual const WeaponDef* GetWeaponDefById(int weaponDefId);

	virtual const float3* GetStartPos();


	virtual const char* CallLuaRules(const char* data, int inSize = -1,
			int* outSize = NULL);

private:
	int teamId;
	const SSkirmishAICallback* sAICallback;
//	int currentFrame;
	void init();
//	void setCurrentFrame(int frame) { currentFrame = frame; }
	int Internal_GiveOrder(int unitId, int groupId, Command* c);

	// caches
	WeaponDef** weaponDefs;
	int* weaponDefFrames;
	UnitDef** unitDefs;
	int* unitDefFrames;
	// the following three are needed to prevent memory leacks
	std::vector<CommandDescription>** groupPossibleCommands;
	std::vector<CommandDescription>** unitPossibleCommands;
	CCommandQueue** unitCurrentCommandQueues;
	FeatureDef** featureDefs;
	int* featureDefFrames;
};

#endif // _AIAICALLBACK_H