sorry, if i am unclear about things in this post, please just ask.
i spent too much time with all this, to be able to think of things that might be non-obvious to others.
current aproximate state of the interface
working interfaces: C/C++, Java
Skirmish AIs that at least load: KAIK, RAI, AAI, NTai, Null*AI
unitsync should contain everything the lobbies need, including:
methods to fetch possible options for Skirmish AIs (works the same way as mod- and map-options)
methods to fetch infos of Skirmish AIs (works in a comparable way like options)
the format for script.txt can be found in the branch under
Documentation/Spring start.txt
example:
Code: Select all
// players in this will share the same units (start with one commander etc)
[TEAM0]
{
TeamLeader=x; // player number that is the "leader"
AllyTeam=number;
RgbColor=red green blue; // red green blue in range [0-1]
Side=Arm/Core; // other sides possible with user mods i suppose
Handicap=0-100; // Percent bonus on all resources collected ?
StartPosX=0; // Use these in combination with StartPosType=3
StartPosZ=0; // range is in map coordinates as returned by unitsync (NOT like StartRectTop et al)
LuaAI=name; // name of the LUA AI that controlls this team
[AI] // [optional]Skirmish AI section
{
Name=RAI; // name of the Skirmish AI that controlls this team
// (see spring.exe --list-skirmish-ais for possible values))
Version=0.1; // [optional] version of the Skirmish AI that controlls this team
[OPTIONS] // [optional] contains AI implementaition specific option values
{
difficultyLevel=1;
}
}
// Either LuaAI is set, the [AI] section is defined or none of the two.
// The TeamLeader field indicates which computer the Skirmish AI will run on.
}
//more teams
How things work
lets first have a look at the source.
like in the past, code that is AI related is under
rts/ExternalAI. this code is mainly C++ and is engine internal only.
Code under
rts/ExternalAI/Interface is meant to be used by AI Interfaces and Skirmish AIs. It is nearly exclusively C. Only some helper methods for AIs or Interfaces are available in C++, for convenience. So a Skirmish AI or Interface dev should only have to look at this code, and not at
rts/ExternalAI.
The dir
AI/Wrappers contains subdirs, which can be seen as small projects. the only one in SVN so far is the LegacyCpp. This is code that is used when compiling Skirmish AIs that use a common way of connecting to an AI Interface, which is codewise independent of the interface, and which is built into the individual AI. example: all Legacy AIs (eg. AAI and KAIK) use the code under
AI/Wrappers/LegacyCpp, so this code ends up compiled in libAAI.so, libKAIK.so, and so on.
Under
AI/Interfaces, we have an other small set of subprojects, currently C and Java. Each of these subprojects lets spring access a set of AIs using a specific technology, this will mainly be programming languages, but if you wanted to make AIs work over the network, you would make an AI Interface aswell.
AI/Skirmish contians skimrish AIs. more about these and interfaces is explained in hte next paragraph.
the end product, and how it is constructed out of the code
AI Interfaces
Every AI Interface will have a native library (.dll, .so or .dylib). If it is an Interface for AIs in a different language, it will likely contain a library in this language aswell (an exception is the C AI Interface, of course). The Java interface for example, consists basically of the following files when installed (eg. under
AI/Interfaces/Java/0.1/):
libJava.so
interface.jar (interface-specific)
InterfaceInfo.lua
jlib/*.jar (interface-specific. currently, this includes mainly the JNA jars)
lib/*.so (interface-specific. currently, this dir is empty, but native libraries could be put here, if the interface would require any in addition to the jvm)
The .so is called by the engine, and (through JNI and JNA) wrapps data from and to Java classes and methods found in the .jar. The first and the third file have to be present for all Interfaces. The .lua tells the engine everything it has to know about the interface. It contains info that is needed for loading the interface.
in the source it looks like this:
AI/Interfaces/Java/*.h
AI/Interfaces/Java/*.c
AI/Interfaces/Java/*.cpp
AI/Interfaces/Java/java/src/*.java
AI/Interfaces/Java/data/InterfaceInfo.lua #*# (see further down)
AI/Interfaces/Java/data/jlib/*.jar
AI/Interfaces/Java/data/lib/*.so
AI/Interfaces/Java/VERSION
The .h, .c and .cpp files are compiled into the .so, while the .java end up as .class in interface.jar. The
java/src dir is the only interface specific thing here. All Interfaces have the
data dir, whichs content is copied directly to the installation directory of the Interface.
VERSION is a text file with only one line, containing the current version of the Interface. This file is used by Scons, CMake and NSIS (installer generator), to construct a version dependant installation dir structure. *
Skirmish AIs
They have a comparable structure like the AI Interfaces. The main differences are: they usually have only one library (in the target language), plus htey may have an AIOptions.lua file.
an installed Java Skirmish AI (eg. under
AI/Skirmish/NullJavaAI/0.1/):
ai.jar (ai-specific)
AIInfo.lua
AIOptions.lua
the source structure:
AI/Skirmish/NullJavaAI/*.java
AI/Skirmish/NullJavaAI/data/AIInfo.lua #*# (see further down)
AI/Skirmish/NullJavaAI/data/AIOptions.lua
AI/Skirmish/NullJavaAI/data/jlib/*.jar
AI/Skirmish/NullJavaAI/data/lib/*.so
AI/Skirmish/NullJavaAI/VERSION
As with the interfaces, the source (in this case, the *.java files) gets compiled into a language specific library (here .jar), and everything under the data dir is copied to the install dir. Exactly as with the interface,
VERSION is a text file with only one line, containing the current version of the Skirmish AI, here for the same purpose.
#*# For both AI Interfaces and Skirmish AIs, a special info key-value pair is added by the engine, the "dataDir".
The value for this info is the absolute path of the Interfaces of AIs root dir at runtime (without a trainling slash), eg "/home/userX/myGames/spring/AI/Skirmish/AAI/0.875"
Interfaces and AIs receive their own infos in the call to thier init() function. The idea is, that they can use log-, cache- and config- files from within their own dir (specifically speaking, this is where the *Info.lua file is located), instead of relying to the CWD that is set by spring.
AIs that i adjusted to use this dir: KAIK, RAI, AAI
Will have a chat with AF about this for NTai.
The Java and the C interface use this aswell.
The problem here is, that this dir may be read only, in some setups under linux (also under windows?). Therefore, i should possibly send an other engine generated absolute info to Interfaces and AIs, called "dataDirWritable". it is now on my todo list. question is, should this dir be created by the engine, if it does not yet exist, or is that job of the Interface/AI?
In addtion to this (in the future: these two) dir, the Interfaces receive a list of all data dirs (eg "~/.spring") in their init() method.