For example next CppTestAI will build radar inside factory (spring 100 + BA 9.10)
Code: Select all
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "CppTestAI.h"
#include "ExternalAI/Interface/AISEvents.h"
#include "ExternalAI/Interface/AISCommands.h"
// generated by the C++ Wrapper scripts
#include "OOAICallback.h"
#include "UnitDef.h"
#include "WrappUnit.h"
#include "Map.h"
#include <string>
cpptestai::CCppTestAI::CCppTestAI(springai::OOAICallback* callback):
callback(callback),
skirmishAIId(callback != NULL ? callback->GetSkirmishAIId() : -1)
{}
cpptestai::CCppTestAI::~CCppTestAI() {}
int cpptestai::CCppTestAI::HandleEvent(int topic, const void* data) {
switch (topic) {
case EVENT_UNIT_CREATED: {
struct SUnitCreatedEvent* evt = (struct SUnitCreatedEvent*)data;
springai::Unit* unit = springai::WrappUnit::GetInstance(skirmishAIId, evt->unit);
static springai::AIFloat3 labPos = ZeroVector;
static springai::Unit* com = nullptr; // leak
springai::UnitDef* def = unit->GetDef();
if (std::string("armcom") == def->GetName()) {
com = unit;
springai::UnitDef* buildDef = callback->GetUnitDefByName("armlab");
com->Build(buildDef, com->GetPos(), 0);
delete buildDef;
} else if (std::string("armlab") == def->GetName()) {
labPos = unit->GetPos() + springai::AIFloat3(0, 0, 32);
springai::UnitDef* buildDef = callback->GetUnitDefByName("armpw");
unit->Build(buildDef, labPos, 0);
delete unit, delete buildDef;
} else if (std::string("armpw") == def->GetName()) {
springai::UnitDef* buildDef = callback->GetUnitDefByName("armrad");
springai::Map* map = callback->GetMap();
springai::AIFloat3 buildPos = map->FindClosestBuildSite(buildDef, labPos, 600.0f, 0, 0);
com->Build(buildDef, buildPos, 0);
delete unit, delete buildDef, delete map;
}
delete def;
break;
}
default: break;
}
// signal: everything went OK
return 0;
}
Also same behaviour is allowed for players (can't think of any reason for that in perspective of BA, ZK, S44).
Didn't mantise it as my ai uses own implementation of FindClosestBuildSite so it's not affected by described "feature" and i'm not sure it's a bug.