I'm attempting to dive into writing a Java AI, but I'm kind of lost. I followed all the instructions at http://springrts.com/wiki/AI:Development:Lang:Java but when I attempt to test it in game, at the end of the countdown the game crashes. I don't see any output or know of a way to make it do output, so I don't know where to start looking for mistakes.
Code: Select all
package myjavaai;
import com.springrts.ai.oo.*;
public class MyJavaAIFactory extends OOAIFactory {
OOAICallback callback;
public OOAI createAI(int teamId, OOAICallback callback)
{
return new myjavaai.MyJavaAI(teamId, callback);
}
}
Code: Select all
package myjavaai;
import java.util.ArrayList;
import java.util.List;
import com.springrts.ai.AICommand;
import com.springrts.ai.AICommandWrapper;
import com.springrts.ai.command.BuildUnitAICommand;
import com.springrts.ai.oo.*;
public class MyJavaAI extends AbstractOOAI {
OOAICallback clb;
public int myteamID=0;
private Unit commander;
List<UnitDef> unitDefs = this.clb.getUnitDefs();
UnitDef solarPlant = null;
public MyJavaAI(int teamId, OOAICallback callback)
{init(teamId, callback);
}
@Override public int init(int teamId, OOAICallback callback) {
this.clb = callback;
myteamID=teamId;
for (UnitDef def : unitDefs)
if (def.getName().equals("armsolar"))
{
solarPlant = def;
break;
}
return 0;
}
@Override public int unitFinished(Unit unit) {
if (unit.getDef().getName().equals("armcom"))
this.commander = unit;
return 0;
}
@Override public int update(int frame) {
if (frame == 0)
{
AICommand command = new BuildUnitAICommand(this.commander, -1,
new ArrayList<AICommand.Option>(), 10000, solarPlant,
this.commander.getPos(), 0);
this.clb.getEngine().handleCommand(AICommandWrapper.COMMAND_TO_ID_ENGINE,
-1, command);
}
return 0;
}
}
Code: Select all
--
-- Info Definition Table format
--
--
-- These keywords must be lowercase for LuaParser to read them.
--
-- key: user defined or one of the SKIRMISH_AI_PROPERTY_* defines in
-- SSkirmishAILibrary.h
-- value: the value of the property
-- desc: the description (could be used as a tooltip)
--
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local infos = {
{
key = 'shortName',
value = 'MyJavaAI',
desc = 'machine conform name.',
},
{
key = 'version',
value = '0.1', -- AI version - !This comment is used for parsing!
},
{
key = 'className',
value = 'myjavaai.MyJavaAIFactory',
desc = 'fully qualified name of a class that implements interface com.springrts.ai.AI',
},
{
key = 'name',
value = 'high-level Java stub Skirmish AI',
desc = 'human readable name.',
},
{
key = 'loadSupported',
value = 'no',
desc = 'whether this AI supports loading or not',
},
{
key = 'interfaceShortName',
value = 'Java', -- AI Interface name - !This comment is used for parsing!
desc = 'the shortName of the AI interface this AI needs',
},
{
key = 'interfaceVersion',
value = '0.1', -- AI Interface version - !This comment is used for parsing!
desc = 'the minimum version of the AI interface required by this AI',
},
}
return infos