VS2008 AIs and the C++ API

AI development under Visual Studio with the Spring Engine is good, but it has a few minor bumps to get over before you can run. Luckily I’ve just done that myself and I’m here to help!

If you download the spring git repository, or the source tarball, you’ll notice there are no visual studio projects for the AIs. To generate them, you would have to run cmake, which isn’t entirely obvious if your under windows with little linux experience. It may not always work either, as happened to me. The same is true of the C++ wrapper around the C API.

So to get over these, with a little help from Hoijui, I created a Visual studio 2008 project from scratch, and set up all the files and include paths. I also corrected the dll exports issue with a .def file and setting the project to use stdcall calling conventions. I even set up AIInfo.lua and AIOptions.lua to autocopy to the target folder upon builds.

I’ve packaged up this AI, the AI logic goes in CppTestAI.h/cpp (its using the C++TestAI in the spring git repository). To use this, extract the contents of the archive into a spring source folder at AI/Skirmish then extract the C++ Wrapper interface into AI/Wrappers/Cpp, open the project in visual studio, and press build.

The AI is built in the game subdirectory of the spring source folder. The game folder is intended to store the result of building spring from source, so its contents will look like an average spring install folder. You can copy paste the AI folder in this directory into your usual spring folder if you want. The AI will build as a skirmishAI.dll in:


To package this up as a release, zip up the folder in /game/AI called <yourvs2008projectname> and be sure to delete the linker subdirectory and skirmishAI.ilk file.

If you want to debug using your existing spring installation, you can go to project properties, and set the linker output target to your my games folder in the appropriate place, which in my case is:

C:UsersAFDocumentsMy GamesSpringAISkirmishMinordevSkirmishAI.dll

This will allow your official spring install to pick up your AI, all you have to do then is, set the debugging page to use your spring folder as the working folder, and to execute spring.exe, or spring.exe script.txt if you have set up a scenario using springlobby.

Download the C++ AI Wrapper here

Download the VS2008 AI Project here

edit: I found an error where it would fail to copy AIInfolua and AIOptions.lua if the target folder did not exist. I’ve updated the project to include commands to create these folders

Leave a Reply