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
|
/*
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/>.
*/
#include "AIAICheats.h"
#include "ExternalAI/Interface/SSkirmishAICallback.h"
#include "AIAICallback.h"
#include "ExternalAI/Interface/AISCommands.h"
static int resIndMetal = -1;
static int resIndEnergy = -1;
static inline int getResourceIndex_Metal(const SSkirmishAICallback* sAICallback, int teamId) {
if (resIndMetal == -1) {
resIndMetal = sAICallback->Clb_0MULTI1FETCH3ResourceByName0Resource(
teamId, "Metal");
}
return resIndMetal;
}
static inline int getResourceIndex_Energy(const SSkirmishAICallback* sAICallback, int teamId)
{
if (resIndEnergy == -1) {
resIndEnergy = sAICallback->Clb_0MULTI1FETCH3ResourceByName0Resource(
teamId, "Energy");
}
return resIndEnergy;
}
CAIAICheats::CAIAICheats()
: IAICheats(), teamId(-1), sAICallback(NULL), aiCallback(NULL) {}
CAIAICheats::CAIAICheats(int teamId, const SSkirmishAICallback* sAICallback,
CAIAICallback* aiCallback)
: IAICheats(), teamId(teamId), sAICallback(sAICallback),
aiCallback(aiCallback) {}
void CAIAICheats::setCheatsEnabled(bool enabled) {
sAICallback->Clb_Cheats_setEnabled(teamId, enabled);
}
void CAIAICheats::SetMyHandicap(float handicap) {
setCheatsEnabled(true);
SSetMyHandicapCheatCommand cmd = {handicap};
sAICallback->Clb_Engine_handleCommand(teamId, COMMAND_TO_ID_ENGINE, -1,
COMMAND_CHEATS_SET_MY_HANDICAP, &cmd);
setCheatsEnabled(false);
}
void CAIAICheats::GiveMeMetal(float amount) {
static int m = getResourceIndex_Metal(sAICallback, teamId);
setCheatsEnabled(true);
SGiveMeResourceCheatCommand cmd = {m, amount};
sAICallback->Clb_Engine_handleCommand(teamId, COMMAND_TO_ID_ENGINE, -1,
COMMAND_CHEATS_GIVE_ME_RESOURCE, &cmd);
setCheatsEnabled(false);
}
void CAIAICheats::GiveMeEnergy(float amount) {
static int e = getResourceIndex_Energy(sAICallback, teamId);
setCheatsEnabled(true);
SGiveMeResourceCheatCommand cmd = {e, amount};
sAICallback->Clb_Engine_handleCommand(teamId, COMMAND_TO_ID_ENGINE, -1,
COMMAND_CHEATS_GIVE_ME_RESOURCE, &cmd);
setCheatsEnabled(false);
}
int CAIAICheats::CreateUnit(const char* unitDefName, float3 pos) {
setCheatsEnabled(true);
int unitDefId = sAICallback->Clb_0MULTI1FETCH3UnitDefByName0UnitDef(
teamId, unitDefName);
SGiveMeNewUnitCheatCommand cmd = {unitDefId, pos.toSAIFloat3()};
int unitId = sAICallback->Clb_Engine_handleCommand(teamId, COMMAND_TO_ID_ENGINE,
-1, COMMAND_CHEATS_GIVE_ME_NEW_UNIT, &cmd);
setCheatsEnabled(false);
return unitId;
}
const UnitDef* CAIAICheats::GetUnitDef(int unitId) {
setCheatsEnabled(true);
const UnitDef* unitDef = aiCallback->GetUnitDef(unitId);
setCheatsEnabled(false);
return unitDef;
}
float3 CAIAICheats::GetUnitPos(int unitId) {
setCheatsEnabled(true);
float3 pos = aiCallback->GetUnitPos(unitId);
setCheatsEnabled(false);
return pos;
}
int CAIAICheats::GetEnemyUnits(int* unitIds, int unitIds_max) {
setCheatsEnabled(true);
int numUnits = aiCallback->GetEnemyUnits(unitIds, unitIds_max);
setCheatsEnabled(false);
return numUnits;
}
int CAIAICheats::GetEnemyUnits(int* unitIds, const float3& pos, float radius,
int unitIds_max) {
setCheatsEnabled(true);
int numUnits = aiCallback->GetEnemyUnits(unitIds, pos, radius, unitIds_max);
setCheatsEnabled(false);
return numUnits;
}
int CAIAICheats::GetNeutralUnits(int* unitIds, int unitIds_max) {
setCheatsEnabled(true);
int numUnits = aiCallback->GetNeutralUnits(unitIds, unitIds_max);
setCheatsEnabled(false);
return numUnits;
}
int CAIAICheats::GetNeutralUnits(int* unitIds, const float3& pos, float radius,
int unitIds_max) {
setCheatsEnabled(true);
int numUnits = aiCallback->GetNeutralUnits(unitIds, pos, radius,
unitIds_max);
setCheatsEnabled(false);
return numUnits;
}
int CAIAICheats::GetFeatures(int* featureIds, int featureIds_max) {
setCheatsEnabled(true);
int numFeatures = aiCallback->GetFeatures(featureIds, featureIds_max);
setCheatsEnabled(false);
return numFeatures;
}
int CAIAICheats::GetFeatures(int* featureIds, int featureIds_max, const float3& pos, float radius) {
setCheatsEnabled(true);
int numFeatures = aiCallback->GetFeatures(featureIds, featureIds_max, pos, radius);
setCheatsEnabled(false);
return numFeatures;
}
int CAIAICheats::GetUnitTeam(int unitId) {
setCheatsEnabled(true);
int t = aiCallback->GetUnitTeam(unitId);
setCheatsEnabled(false);
return t;
}
int CAIAICheats::GetUnitAllyTeam(int unitId) {
setCheatsEnabled(true);
int t = aiCallback->GetUnitAllyTeam(unitId);
setCheatsEnabled(false);
return t;
}
float CAIAICheats::GetUnitHealth(int unitId) {
setCheatsEnabled(true);
float health = aiCallback->GetUnitHealth(unitId);
setCheatsEnabled(false);
return health;
}
float CAIAICheats::GetUnitMaxHealth(int unitId) {
setCheatsEnabled(true);
float health = aiCallback->GetUnitMaxHealth(unitId);
setCheatsEnabled(false);
return health;
}
float CAIAICheats::GetUnitPower(int unitId) {
setCheatsEnabled(true);
float power = aiCallback->GetUnitPower(unitId);
setCheatsEnabled(false);
return power;
}
float CAIAICheats::GetUnitExperience(int unitId) {
setCheatsEnabled(true);
float experience = aiCallback->GetUnitExperience(unitId);
setCheatsEnabled(false);
return experience;
}
bool CAIAICheats::IsUnitActivated(int unitId) {
setCheatsEnabled(true);
bool activated = aiCallback->IsUnitActivated(unitId);
setCheatsEnabled(false);
return activated;
}
bool CAIAICheats::UnitBeingBuilt(int unitId) {
setCheatsEnabled(true);
bool isBeingBuilt = aiCallback->UnitBeingBuilt(unitId);
setCheatsEnabled(false);
return isBeingBuilt;
}
bool CAIAICheats::IsUnitNeutral(int unitId) {
setCheatsEnabled(true);
bool neutral = aiCallback->IsUnitNeutral(unitId);
setCheatsEnabled(false);
return neutral;
}
bool CAIAICheats::GetUnitResourceInfo(int unitId,
UnitResourceInfo* resourceInfo) {
setCheatsEnabled(true);
bool fetchOk = aiCallback->GetUnitResourceInfo(unitId, resourceInfo);
setCheatsEnabled(false);
return fetchOk;
}
const CCommandQueue* CAIAICheats::GetCurrentUnitCommands(int unitId) {
setCheatsEnabled(true);
const CCommandQueue* cc = aiCallback->GetCurrentUnitCommands(unitId);
setCheatsEnabled(false);
return cc;
}
int CAIAICheats::GetBuildingFacing(int unitId) {
setCheatsEnabled(true);
int facing = aiCallback->GetBuildingFacing(unitId);
setCheatsEnabled(false);
return facing;
}
bool CAIAICheats::IsUnitCloaked(int unitId) {
setCheatsEnabled(true);
bool cloaked = aiCallback->IsUnitCloaked(unitId);
setCheatsEnabled(false);
return cloaked;
}
bool CAIAICheats::IsUnitParalyzed(int unitId) {
setCheatsEnabled(true);
bool paralyzed = aiCallback->IsUnitParalyzed(unitId);
setCheatsEnabled(false);
return paralyzed;
}
bool CAIAICheats::OnlyPassiveCheats() {
return sAICallback->Clb_Cheats_isOnlyPassive(teamId);
}
void CAIAICheats::EnableCheatEvents(bool enable) {
sAICallback->Clb_Cheats_setEventsEnabled(teamId, enable);
}
bool 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 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 CAIAICheats::HandleCommand(int commandId, void* data) {
setCheatsEnabled(true);
int ret = aiCallback->HandleCommand(commandId, data);
setCheatsEnabled(false);
return ret;
}
|