AI:CSAIInterface: Difference between revisions
Hughperkins (talk | contribs) First created |
Hughperkins (talk | contribs) No edit summary |
||
| Line 54: | Line 54: | ||
This will automatically configure your project to build as a dll, and make the types from CSAIInterfaces.dll available to your project. | This will automatically configure your project to build as a dll, and make the types from CSAIInterfaces.dll available to your project. | ||
== CSAI Interface Architecture == | |||
You won't need to know this unless you want to extend the interface, but it might be interesting as background. | |||
=== spring.exe === | |||
Spring.exe is the Spring RTS game that loads the AI. | |||
The main classes that are important are: | |||
- IGlobalAI The AI's main class should derive from this | |||
- AICallback Passed to AI, to provide functions for AI to drive Spring | |||
- UnitDef Unit definitions | |||
- Command Commands passed to AICallback->GiveOrder | |||
- MoveData Information on movements, part of a UnitDef | |||
Other helper classes include: | |||
- float3 vector of 3 floats | |||
=== csailoader.dll === | |||
This is a managed C++ component that binds Spring.exe to CSAI.dll | |||
- CSAIProxy derives from Spring.exe/IGlobalAI. This is the proxy from Spring.exe to CSAI.dll | |||
- AICallbackProxy derives from CSAI.dll/IAICallback. This proxies requests from CSAI.dll to Spring.exe | |||
- UnitDefProxy derives from CSAI.dll/IUnitDef. This is a proxy of the actual Spring.exe UnitDef | |||
=== CSAIInterfaces.dll === | |||
This holds interfaces that are used to abstract CSAI.dll classes away from csailoader.dll It is written in C# | |||
This gives us the possibility to dynamically reload CSAI without reloading Spring. | |||
- CSharpAI.IGlobalAI C# version of Spring.exe/IGlobalAI | |||
- CSharpAI.IAICallback C# version of Spring.exe/IAICallback | |||
Some helper classes: | |||
- CSharpAI.Command used to hold commands passed to IAICallback.GiveOrder | |||
- CSharpAI.IUnitDef holds definition of a unit | |||
- CSharpAI.Float3 holds vectors of 3 floats | |||
=== CSAI.dll === | |||
This is the C# AI component. | |||
- CSAI the main class, equivalent to a C++ IGLobalAI derivative | |||
+ The C# AI's classes go here, eg: | |||
- ScoutController.cs | |||
- TankController.cs | |||
- CommanderController.cs | |||
- StrategyController.cs | |||
- ... | |||
Revision as of 20:14, 23 October 2006
CSAI Interface
CSAI Interface makes it possible to build Global AIs for Spring using C# .Net 1.1.
C# runs fast and is easy to debug. In addition, using CSAI Interface makes it possible to dynamically recompile and reload your AI dll in the middle of a game.
You can get CSAI Interface from:
http://manageddreams.com/csai/CSharpAI_20061024.zip
CSAI Interface was written by Hugh Perkins
How to use
- AI:CSAI Please see the CSAI installation instructions for installation instructions; for now these are integrated and identical
- CSAI Build Instructions For now, the build instructions for CSAI and CSAI Interface are integrated and identical
Dynamic dll recompilation and reloading
To dynamically recompile and reload your AI dll in the middle of a game:
- recompile your dll
- in the game say ".reloadai"
You can do this whilst paused if you want.
Note that this only applies to the C# AI dll itself. CSAIInterfaces.dll and CSAILoader.dll require the game to be shut down during recompilation.
dll loading, CSAILoader.dll configuration
CSAILoader.dll searches for a configuration file with the same name (ie CSAILoader.xml), in the same directory. This configuration file defines the C# AI dll to reload. If you want you can name your C# dll mysuperai.dll , as long as you change the name of the dll in the configuration file. You can also change the name of the directory and the name of the main C# dll class.
Be really careful to double-check the name of the dll, directory and class if you change them. Your only warning that something is wrong will be an AI exception when you start the game ;-)
You can rename CSAILoader.dll to anything you like. The dll will look for a configuration file with the same name.
All this means that it is very easy for you to create your own C# AI dlls with your own name, and that it wont conflict with other people's C# AIs.
Note that CSAIInterfaces.dll is immutable, never needs to be renamed.
C# AI base class
Your C# AI needs to have a class that derives from CSharpAI.IGlobalAI
You can see the definition of this interfaces in CSAIInterfaces\IGlobalAI.cs
You will need to ensure that the name of the class specified in your CSAILoader.xml configuration file matches the name and namespace of this class.
If you're unsure, just call this class CSAI, in namespace CSharpAI. Then you won't need to change the configuration file
Creating a C# dll using Visual Studio
- Create a new project of type "class library"
- Add a reference to CSAIInterfaces\CSAIInterfaces.dll
This will automatically configure your project to build as a dll, and make the types from CSAIInterfaces.dll available to your project.
CSAI Interface Architecture
You won't need to know this unless you want to extend the interface, but it might be interesting as background.
spring.exe
Spring.exe is the Spring RTS game that loads the AI.
The main classes that are important are: - IGlobalAI The AI's main class should derive from this - AICallback Passed to AI, to provide functions for AI to drive Spring - UnitDef Unit definitions - Command Commands passed to AICallback->GiveOrder - MoveData Information on movements, part of a UnitDef
Other helper classes include: - float3 vector of 3 floats
csailoader.dll
This is a managed C++ component that binds Spring.exe to CSAI.dll
- CSAIProxy derives from Spring.exe/IGlobalAI. This is the proxy from Spring.exe to CSAI.dll - AICallbackProxy derives from CSAI.dll/IAICallback. This proxies requests from CSAI.dll to Spring.exe - UnitDefProxy derives from CSAI.dll/IUnitDef. This is a proxy of the actual Spring.exe UnitDef
CSAIInterfaces.dll
This holds interfaces that are used to abstract CSAI.dll classes away from csailoader.dll It is written in C#
This gives us the possibility to dynamically reload CSAI without reloading Spring.
- CSharpAI.IGlobalAI C# version of Spring.exe/IGlobalAI - CSharpAI.IAICallback C# version of Spring.exe/IAICallback
Some helper classes: - CSharpAI.Command used to hold commands passed to IAICallback.GiveOrder - CSharpAI.IUnitDef holds definition of a unit - CSharpAI.Float3 holds vectors of 3 floats
CSAI.dll
This is the C# AI component.
- CSAI the main class, equivalent to a C++ IGLobalAI derivative
+ The C# AI's classes go here, eg: - ScoutController.cs - TankController.cs - CommanderController.cs - StrategyController.cs - ...