i'm trying to write an ai, but i'm really unsure what functions i should use, there are to few docs for the new c/c++ interface. (Or i haven't found it?)
This is, what i have:
SpringAI.h
Code: Select all
EXPORT(int) handleEvent(int teamId, int topic, const void* data);
EXPORT(int) init(int teamId, const struct SSkirmishAICallback* callback);
class AI{
const struct SSkirmishAICallback * cb;
public:
void InitAi(const SSkirmishAICallback* callback);
void HandleEvent(int teamId, int topic, const void* data);
};
Code: Select all
#include <map>
#include <stdio.h>
#include "SpringAI.h"
#include "ExternalAI/Interface/SSkirmishAICallback.h"
#include "ExternalAI/Interface/AISEvents.h"
#include "ExternalAI/Interface/AISCommands.h"
const struct SSkirmishAICallback *teamId_callback;
AI *ai;
EXPORT(int) handleEvent(int teamId, int topic, const void* data) {
ai->HandleEvent(teamId, topic, data);
return 0;
}
EXPORT(int) init(int teamId, const struct SSkirmishAICallback* callback){
ai=new AI();
ai->InitAi(callback);
return 0;
}
EXPORT(int) release(int teamId){
delete(ai);
return 0;
}
void AI::InitAi(const SSkirmishAICallback* callback){
cb = callback;
}
void AI::HandleEvent(int teamId, int topic, const void* data){
switch (topic){
case EVENT_UNIT_FINISHED:{
SMoveUnitCommand cmd;
SUnitFinishedEvent *tmp;
tmp=(SUnitFinishedEvent*)data;
cmd.unitId=tmp->unit;
cmd.groupId=0;
cmd.options=0;
cmd.timeOut=0;
cmd.toPos.x=1;
cmd.toPos.y=1;
cmd.toPos.z=1;
cb->Clb_Engine_handleCommand(teamId,0,0,COMMAND_UNIT_MOVE,&cmd);
}
break;
}
}
Code: Select all
SPRINGSRC=/path/to/spring/src
INCLUDE=-I${SPRINGSRC}/AI/rts/System -I${SPRINGSRC}/AI/Wrappers/CUtils -I${SPRINGSRC}/AI/Interfaces/C -I${SPRINGSRC}/rts
all:
c++ -shared -fPIC SpringAI.cpp ${INCLUDE} -o libSkirmishAI.so
are the include-files ok?
I've read http://springrts.com/wiki/AIInterface:C but there was an error in the first sentence... (i've fixed it).
I think the usage of cb->Clb_Engine_handleCommand() is wrong...?!
Any ideas what function to use, to send commands to the engine or was it right?
KAIK and RAI are using ../Wrappers/LegacyCpp/ as include, this is confusing...
Every hint is welcome