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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "AIAICheats.h"
#include "ExternalAI/Interface/SSkirmishAICallback.h"
#include "AIAICallback.h"
#include "ExternalAI/Interface/AISCommands.h"
static inline int getResourceIndex_Metal(const SSkirmishAICallback* sAICallback, int skirmishAIId) {
static int resIndMetal = -1;
if (resIndMetal == -1) {
resIndMetal = sAICallback->getResourceByName(skirmishAIId, "Metal");
}
return resIndMetal;
}
static inline int getResourceIndex_Energy(const SSkirmishAICallback* sAICallback, int skirmishAIId) {
static int resIndEnergy = -1;
if (resIndEnergy == -1) {
resIndEnergy = sAICallback->getResourceByName(skirmishAIId, "Energy");
}
return resIndEnergy;
}
springLegacyAI::CAIAICheats::CAIAICheats()
: IAICheats(), skirmishAIId(-1), sAICallback(NULL), aiCallback(NULL) {}
springLegacyAI::CAIAICheats::CAIAICheats(int skirmishAIId, const SSkirmishAICallback* sAICallback, CAIAICallback* aiCallback)
: IAICheats(), skirmishAIId(skirmishAIId), sAICallback(sAICallback), aiCallback(aiCallback) {}
void springLegacyAI::CAIAICheats::SetCheatsEnabled(bool enabled) {
sAICallback->Cheats_setEnabled(skirmishAIId, enabled);
}
void springLegacyAI::CAIAICheats::EnableCheatEvents(bool enable) {
SetCheatsEnabled(true);
sAICallback->Cheats_setEventsEnabled(skirmishAIId, enable);
SetCheatsEnabled(false);
}
void springLegacyAI::CAIAICheats::SetMyHandicap(float handicap) {
SetCheatsEnabled(true);
SSetMyIncomeMultiplierCheatCommand cmd = { (handicap / 100.0f) + 1.0f };
sAICallback->Engine_handleCommand(skirmishAIId, COMMAND_TO_ID_ENGINE, -1,
COMMAND_CHEATS_SET_MY_INCOME_MULTIPLIER, &cmd);
SetCheatsEnabled(false);
}
void springLegacyAI::CAIAICheats::GiveMeMetal(float amount) {
const static int m = getResourceIndex_Metal(sAICallback, skirmishAIId);
SetCheatsEnabled(true);
SGiveMeResourceCheatCommand cmd = {m, amount};
sAICallback->Engine_handleCommand(skirmishAIId, COMMAND_TO_ID_ENGINE, -1,
COMMAND_CHEATS_GIVE_ME_RESOURCE, &cmd);
SetCheatsEnabled(false);
}
void springLegacyAI::CAIAICheats::GiveMeEnergy(float amount) {
const static int e = getResourceIndex_Energy(sAICallback, skirmishAIId);
SetCheatsEnabled(true);
SGiveMeResourceCheatCommand cmd = {e, amount};
sAICallback->Engine_handleCommand(skirmishAIId, COMMAND_TO_ID_ENGINE, -1,
COMMAND_CHEATS_GIVE_ME_RESOURCE, &cmd);
SetCheatsEnabled(false);
}
int springLegacyAI::CAIAICheats::CreateUnit(const char* unitDefName, float3 pos) {
SetCheatsEnabled(true);
const int unitDefId = sAICallback->getUnitDefByName(skirmishAIId, unitDefName);
float pos_f3[3];
pos.copyInto(pos_f3);
SGiveMeNewUnitCheatCommand cmd = {unitDefId, pos_f3};
const int unitId = sAICallback->Engine_handleCommand(skirmishAIId, COMMAND_TO_ID_ENGINE,
-1, COMMAND_CHEATS_GIVE_ME_NEW_UNIT, &cmd);
SetCheatsEnabled(false);
return unitId;
}
const springLegacyAI::UnitDef* springLegacyAI::CAIAICheats::GetUnitDef(int unitId) {
SetCheatsEnabled(true);
const UnitDef* unitDef = aiCallback->GetUnitDef(unitId);
SetCheatsEnabled(false);
return unitDef;
}
float3 springLegacyAI::CAIAICheats::GetUnitPos(int unitId) {
SetCheatsEnabled(true);
const float3 pos = aiCallback->GetUnitPos(unitId);
SetCheatsEnabled(false);
return pos;
}
float3 springLegacyAI::CAIAICheats::GetUnitVel(int unitId) {
SetCheatsEnabled(true);
const float3 pos = aiCallback->GetUnitVel(unitId);
SetCheatsEnabled(false);
return pos;
}
int springLegacyAI::CAIAICheats::GetEnemyUnits(int* unitIds, int unitIds_max) {
SetCheatsEnabled(true);
const int numUnits = aiCallback->GetEnemyUnits(unitIds, unitIds_max);
SetCheatsEnabled(false);
return numUnits;
}
int springLegacyAI::CAIAICheats::GetEnemyUnits(int* unitIds, const float3& pos, float radius,
int unitIds_max) {
SetCheatsEnabled(true);
const int numUnits = aiCallback->GetEnemyUnits(unitIds, pos, radius, unitIds_max);
SetCheatsEnabled(false);
return numUnits;
}
int springLegacyAI::CAIAICheats::GetNeutralUnits(int* unitIds, int unitIds_max) {
SetCheatsEnabled(true);
const int numUnits = aiCallback->GetNeutralUnits(unitIds, unitIds_max);
SetCheatsEnabled(false);
return numUnits;
}
int springLegacyAI::CAIAICheats::GetNeutralUnits(int* unitIds, const float3& pos, float radius,
int unitIds_max) {
SetCheatsEnabled(true);
const int numUnits = aiCallback->GetNeutralUnits(unitIds, pos, radius, unitIds_max);
SetCheatsEnabled(false);
return numUnits;
}
int springLegacyAI::CAIAICheats::GetFeatures(int* featureIds, int featureIds_max) {
SetCheatsEnabled(true);
const int numFeatures = aiCallback->GetFeatures(featureIds, featureIds_max);
SetCheatsEnabled(false);
return numFeatures;
}
int springLegacyAI::CAIAICheats::GetFeatures(int* featureIds, int featureIds_max, const float3& pos, float radius) {
SetCheatsEnabled(true);
const int numFeatures = aiCallback->GetFeatures(featureIds, featureIds_max, pos, radius);
SetCheatsEnabled(false);
return numFeatures;
}
int springLegacyAI::CAIAICheats::GetUnitTeam(int unitId) {
SetCheatsEnabled(true);
const int t = aiCallback->GetUnitTeam(unitId);
SetCheatsEnabled(false);
return t;
}
int springLegacyAI::CAIAICheats::GetUnitAllyTeam(int unitId) {
SetCheatsEnabled(true);
const int allyTeam = aiCallback->GetUnitAllyTeam(unitId);
SetCheatsEnabled(false);
return allyTeam;
}
float springLegacyAI::CAIAICheats::GetUnitHealth(int unitId) {
SetCheatsEnabled(true);
const float health = aiCallback->GetUnitHealth(unitId);
SetCheatsEnabled(false);
return health;
}
float springLegacyAI::CAIAICheats::GetUnitMaxHealth(int unitId) {
SetCheatsEnabled(true);
const float health = aiCallback->GetUnitMaxHealth(unitId);
SetCheatsEnabled(false);
return health;
}
float springLegacyAI::CAIAICheats::GetUnitPower(int unitId) {
SetCheatsEnabled(true);
const float power = aiCallback->GetUnitPower(unitId);
SetCheatsEnabled(false);
return power;
}
float springLegacyAI::CAIAICheats::GetUnitExperience(int unitId) {
SetCheatsEnabled(true);
const float experience = aiCallback->GetUnitExperience(unitId);
SetCheatsEnabled(false);
return experience;
}
bool springLegacyAI::CAIAICheats::IsUnitActivated(int unitId) {
SetCheatsEnabled(true);
const bool activated = aiCallback->IsUnitActivated(unitId);
SetCheatsEnabled(false);
return activated;
}
bool springLegacyAI::CAIAICheats::UnitBeingBuilt(int unitId) {
SetCheatsEnabled(true);
const bool isBeingBuilt = aiCallback->UnitBeingBuilt(unitId);
SetCheatsEnabled(false);
return isBeingBuilt;
}
bool springLegacyAI::CAIAICheats::IsUnitNeutral(int unitId) {
SetCheatsEnabled(true);
const bool neutral = aiCallback->IsUnitNeutral(unitId);
SetCheatsEnabled(false);
return neutral;
}
bool springLegacyAI::CAIAICheats::GetUnitResourceInfo(int unitId,
UnitResourceInfo* resourceInfo) {
SetCheatsEnabled(true);
const bool fetchOk = aiCallback->GetUnitResourceInfo(unitId, resourceInfo);
SetCheatsEnabled(false);
return fetchOk;
}
const springLegacyAI::CCommandQueue* springLegacyAI::CAIAICheats::GetCurrentUnitCommands(int unitId) {
SetCheatsEnabled(true);
const CCommandQueue* cc = aiCallback->GetCurrentUnitCommands(unitId);
SetCheatsEnabled(false);
return cc;
}
int springLegacyAI::CAIAICheats::GetBuildingFacing(int unitId) {
SetCheatsEnabled(true);
const int facing = aiCallback->GetBuildingFacing(unitId);
SetCheatsEnabled(false);
return facing;
}
bool springLegacyAI::CAIAICheats::IsUnitCloaked(int unitId) {
SetCheatsEnabled(true);
const bool cloaked = aiCallback->IsUnitCloaked(unitId);
SetCheatsEnabled(false);
return cloaked;
}
bool springLegacyAI::CAIAICheats::IsUnitParalyzed(int unitId) {
SetCheatsEnabled(true);
const bool paralyzed = aiCallback->IsUnitParalyzed(unitId);
SetCheatsEnabled(false);
return paralyzed;
}
bool springLegacyAI::CAIAICheats::GetProperty(int id, int property, void* dst) {
// SetCheatsEnabled(true);
// bool fetchOk = aiCallback->GetProperty(id, property, dst);
// SetCheatsEnabled(false);
// return fetchOk;
// this returns always false, cause these values are now available through
// individual callback functions -> this method is deprecated
return false;
}
bool springLegacyAI::CAIAICheats::GetValue(int id, void* dst) {
// SetCheatsEnabled(true);
// bool fetchOk = aiCallback->GetValue(id, dst);
// SetCheatsEnabled(false);
// return fetchOk;
// this returns always false, cause these values are now available through
// individual callback functions -> this method is deprecated
return false;
}
int springLegacyAI::CAIAICheats::HandleCommand(int commandId, void* data) {
SetCheatsEnabled(true);
const int ret = aiCallback->HandleCommand(commandId, data);
SetCheatsEnabled(false);
return ret;
}
|