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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
#ifndef KAIK_CLASSES_HDR
#define KAIK_CLASSES_HDR
#include <list>
#include <set>
#include <vector>
#include <string>
#include "System/float3.h"
#include "IncCREG.h"
#include "Defines.h"
namespace springLegacyAI {
struct UnitDef;
class IGlobalAICallback;
class IAICallback;
class IAICheats;
} // namespace springLegacyAI
using namespace springLegacyAI;
class CMetalMap;
class CMaths;
class CPathFinder;
class CUnitTable;
class CThreatMap;
class CUnitHandler;
class CUNIT;
class CDefenseMatrix;
class CEconomyTracker;
class CBuildUp;
class CAttackHandler;
class CDGunControllerHandler;
class CLogger;
class CCommandTracker;
struct LuaParser;
struct AIClasses {
public:
CR_DECLARE_STRUCT(AIClasses)
AIClasses(): initialized(true) { /* CREG-only */ }
AIClasses(IGlobalAICallback*);
~AIClasses();
void Init();
void Load();
bool Initialized() const { return initialized; }
int InitFrame() const { return initFrame; }
IAICallback* GetCallbackHandler() { return callbackHandler; }
IAICheats* GetCheatCallbackHandler() { return ccallbackHandler; }
CEconomyTracker* GetEcoTracker() { return ecoTracker; }
CBuildUp* GetBuildUp() { return buildupHandler; }
CMetalMap* GetMetalMap() { return metalMap; }
CMaths* GetMathHandler() { return mathHandler; }
CPathFinder* GetPathFinder() { return pathFinder; }
CUnitTable* GetUnitTable() { return unitTable; }
CThreatMap* GetThreatMap() { return threatMap; }
CUnitHandler* GetUnitHandler() { return unitHandler; }
CDefenseMatrix* GetDefenseMatrix() { return defenseMatrix; }
CAttackHandler* GetAttackHandler() { return attackHandler; }
CDGunControllerHandler* GetDGunControllerHandler() { return dgunControllerHandler; }
CCommandTracker* GetCommandTracker() { return commandTracker; }
CLogger* GetLogger() { return logHandler; }
LuaParser* GetLuaParser() { return luaConfigParser; }
CUNIT* GetUnit(int id) const {
assert((id >= 0) && (id < activeUnits.size()));
return activeUnits[id];
}
std::vector<CUNIT*>& GetActiveUnits() { return activeUnits; }
std::vector<int>& GetUnitIDs() { return unitIDs; }
private:
IAICallback* callbackHandler;
IAICheats* ccallbackHandler;
CEconomyTracker* ecoTracker;
CBuildUp* buildupHandler;
CMetalMap* metalMap;
CMaths* mathHandler;
CPathFinder* pathFinder;
CUnitTable* unitTable;
CThreatMap* threatMap;
CUnitHandler* unitHandler;
CDefenseMatrix* defenseMatrix;
CAttackHandler* attackHandler;
CDGunControllerHandler* dgunControllerHandler;
CCommandTracker* commandTracker;
CLogger* logHandler;
LuaParser* luaConfigParser;
std::vector<CUNIT*> activeUnits;
std::vector<int> unitIDs;
bool initialized; //! true if the current mod was on the AIInfo whitelist
int initFrame; //! frame that this->InitAI() was called in
};
#define cb GetCallbackHandler()
#define ccb GetCheatCallbackHandler()
#define econTracker GetEcoTracker()
#define mm GetMetalMap()
#define bu GetBuildUp()
#define math GetMathHandler()
#define pather GetPathFinder()
#define ut GetUnitTable()
#define thm GetThreatMap()
#define uh GetUnitHandler()
#define dm GetDefenseMatrix()
#define ah GetAttackHandler()
#define dgunConHandler GetDGunControllerHandler()
#define ct GetCommandTracker()
#define luaParser GetLuaParser()
#define unitIDs GetUnitIDs()
// NOTE: CUNIT does not know about this structure
struct UnitType {
CR_DECLARE_STRUCT(UnitType)
void PostLoad();
std::vector<int> canBuildList;
std::vector<int> builtByList;
std::vector<float> DPSvsUnit;
const UnitDef* def;
UnitCategory category;
bool isHub;
int techLevel;
float costMultiplier;
};
class integer2 {
public:
CR_DECLARE_STRUCT(integer2)
integer2(): x(0), y(0) {};
integer2(const int x,const int y): x(x), y(y) {}
~integer2() {};
inline bool operator == (const integer2 &f) const {
return ((x - f.x == 0) && (y - f.y == 0));
}
union {
struct{
int x;
int y;
};
};
};
/*
* builder container: main task is to make sure that
* tracking builders is easy (making asserts and tests)
*/
struct BuilderTracker {
CR_DECLARE_STRUCT(BuilderTracker)
int builderID;
// if not NULL then this worker belongs to this BuildTask.
int buildTaskId;
// if not NULL then this worker belongs to this TaskPlan.
int taskPlanId;
// if not NULL then this worker belongs to this Factory.
int factoryId;
// if not NULL then this worker is stuck or something
int stuckCount;
// if this builder ends up without orders for some time, try IdleUnitAdd()
int idleStartFrame;
// the frame an order is given, needed for lag tolerance when verifying unit command
int commandOrderPushFrame;
// TODO: this is (or will be in the future) a hint of what this builder will make
UnitCategory categoryMaker;
// these are unused
// what frame this builder will start working
int estimateRealStartFrame;
// this will be constant or based on the last startup time
int estimateFramesForNanoBuildActivation;
// Simple ETA, updated every 16 frames or so (0 means it's there)
int estimateETAforMoveingToBuildSite;
// the def -> buildDistance or something
float distanceToSiteBeforeItCanStartBuilding;
};
struct BuildTask {
CR_DECLARE_STRUCT(BuildTask)
void PostLoad(void);
int id;
UnitCategory category;
// temp only, for compatibility (will be removed)
std::list<int> builders;
// the new container
std::list<BuilderTracker*> builderTrackers;
float currentBuildPower;
// for speed up, and debugging
const UnitDef* def;
// needed for command verify and debugging
float3 pos;
};
struct TaskPlan {
CR_DECLARE_STRUCT(TaskPlan)
void PostLoad(void);
// this will be some smart number (a counter?)
int id;
// temp only, for compatibility (will be removed)
std::list<int> builders;
std::list<BuilderTracker*> builderTrackers;
float currentBuildPower;
const UnitDef* def;
std::string defName;
float3 pos;
};
struct UpgradeTask {
CR_DECLARE_STRUCT(UpgradeTask)
void PostLoad(void);
UpgradeTask() {
oldBuildingID = -1;
oldBuildingPos = float3(-1.0f, -1.0f, -1.0f);
newBuildingDef = NULL;
creationFrame = -1;
reclaimStatus = false;
}
UpgradeTask(int buildingID, int frame, const float3& buildingPos, const UnitDef* buildingDef) {
oldBuildingID = buildingID;
oldBuildingPos = buildingPos;
newBuildingDef = buildingDef;
creationFrame = frame;
reclaimStatus = false;
}
int oldBuildingID;
float3 oldBuildingPos;
const UnitDef* newBuildingDef;
int creationFrame;
bool reclaimStatus;
std::set<int> builderIDs;
};
struct Factory {
CR_DECLARE_STRUCT(Factory)
int id;
// temp only, for compatibility (will be removed)
std::list<int> supportbuilders;
std::list<BuilderTracker*> supportBuilderTrackers;
};
struct NukeSilo {
CR_DECLARE_STRUCT(NukeSilo)
int id;
int numNukesReady;
int numNukesQueued;
};
struct MetalExtractor {
CR_DECLARE_STRUCT(MetalExtractor)
int id;
int buildFrame;
};
#endif
|