I just started out buildin my own AI and I have some nice ideas for
it, but for the moment I'm stuck with an AI that can't build
anything... I'm able to make a commander move, but I'm not able to
make him build something.
Here is the code I'm using at the moment:
Code: Select all
void TestGlobalAI::UnitFinished(int unit)
{
const UnitDef *unitdef = aicallback->GetUnitDef(unit);
if (unitdef->isCommander) {
char buf[1024];
sprintf(buf, "Command id is %d\n", unit);
aicallback->SendTextMsg(buf, 0);
const int unitnumber = aicallback->GetNumUnitDefs();
const UnitDef* unitList[unitnumber];
aicallback->GetUnitDefList(unitList);
const UnitDef* solarDef;
// Search for the solar collector we want to build.
for (int i = 0; i < unitnumber; i++) {
if (unitList[i]->energyMake > 0) {
solarDef = unitList[i];
sprintf(buf, "Solar unit ID is: %d\n", solarDef->id);
aicallback->SendTextMsg(buf, 0);
break;
}
}
if (solarDef == 0) {
aicallback->SendTextMsg("No solar unit found :(", 0);
} else {
float3 commanderpos = aicallback->GetUnitPos(unit);
float3 buildSite = aicallback->ClosestBuildSite(solarDef,
commanderpos, 1400.0, true);
buildSite.x += 200;
aicallback->CreateLineFigure(commanderpos, buildSite,
(float)10, 10, 10000, 0);
sprintf(buf, "Location: %f, %f, %f\n", buildSite.x,
buildSite.y, buildSite.z);
aicallback->SendTextMsg(buf, 0);
aicallback->SendTextMsg("Lets build some shite!", 0);
Command c;
c.id = -solarDef->id;
c.params.resize(3);
c.params[0] = buildSite.x;
c.params[1] = aicallback->GetElevation(buildSite.x, buildSite.z);
c.params[2] = buildSite.z;
if (aicallback->GiveOrder(unit, &c) == -1)
aicallback->SendTextMsg("Build action failed :(", 0);
}
}
}
empty plane with more then enough space to build something, but the
commander simply won't move. In the Infolog the following information
is shown:
[ 0] Spring 0.78.2.1
[ 0] Build date/time: Jan 18 2009 20:20:06
[ 0] Player Player connected with number 0 (client version 0.78.2.1)
[ 0] Player Player finished loading and is now ingame
[ 0] GameID: 15e67949dc2f3621fd6b0c81fa320045
[ 0] /home/u0/apas2008/bridder/Spring/AI/Bot-libs/TestAI.so has a C++ interface
[ 0] GlobalAI1: Hello world v2
[ 0] GlobalAI1: Command id is 6372
[ 0] GlobalAI1: Solar unit ID is: 1
[ 0] GlobalAI1: Location: 5296.000000, 91.718750, 440.000000
[ 0] GlobalAI1: Lets build some shite!
There are some messages about a LUA widget called Lups which fails, but I don't think it's relevant.
This is the picture in game with the arrow designating where the commander should build:

If someone could give me some pointers I'd be very very happy! Also is there a description for the API used by AIs? I have a hard time to skip through the code of TA Spring and other AIs to figure out which parameters I should pass to commands, etc.
Thanks!
Bram