Setting up StarCraft
2 machines (or Virtual Machines of course), one that will create the game that we will call host, the other that will connect to it that we will call client.
The host should have a bwapi.ini with things like:
Code: Select all
ai_dll = C:StarCraftAIBroodwarBotQReleaseHostModule.dll; your host dll
auto_menu = LAN
lan_mode = Local Area Network (UDP)
auto_restart = ON
map = mapsBroodWarTournamentSC-t1mapsdragoons.scm; the map on which you want to play
The client should have a bwapi.ini with things like:
ai_dll = C:StarCraftAIBroodwarBotQReleaseClientModule.dll; your client dll
auto_menu = LAN
lan_mode = Local Area Network (UDP)
auto_restart = ON
map =; auto-joins games
Launch both and launch the game (host, then client, then you click OK on the game lobby menu). It should work but stop in the same state (game lobby). That's why we want to click on OK automatically.
Setting up AutoHotkey
On your host, Grab and install AutoHotkey (I took the Basic version and it works).
Use AutoIt3 Windows Spy (installed with AutoHotkey) to find the In Active Window coordinates of the OK button in the game lobby. It helps to have your starcraft either full screen of windowed and pinned down (in the upper right icons of W-Mode). You can freeze the current mouse position for AutoIt3 Windows Spy on Windows XP by doing Alt+Maj+Tab.
Create a text file ending in .ahk and paste something like this while changing the mouse coordinates to your "In Active Window" ones:
Code: Select all
Sleep 6000
WinGetActiveTitle, PreviouslyActive
IfWinExist Brood War
{
WinActivate
Click 517, 426
}
IfWinExist, %PreviouslyActive%
{
WinActivate
}
This waits 6 secondes avec been called (in onEnd(bool isWinner), see next section) so that we can skip the menus and have the client joined back the game. You may need to change that for more if your network is slow.
You can right click on the .ahk file and create an executable with Compile Script (AutoHotkey compiles it). You will use this executable in the next section. I called mine startGame.exe.
Tuning your code
All that's left is calling the AutoHotkey process that will restart the game when the games end. This code has to be in the host code (HostModule.dll in the example above). The client will reconnect automatically (thanks to map = . Here is the snippet of code I use. I put myRestartGame() in my utils and then just call it in onEnd(bool isWinner).
Code: Select all
void myRestartGame()
{
/////////// Launch an AutoHotkey that will click on "OK" in 10 sec
char procName[200];
sprintf_s(procName,
"C:StarCraftAIBroodwarBotQscriptsstartGame.exe");
// Initialize StartupInfo structure
STARTUPINFO StartupInfo;
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
// This will contain the information about the newly created process
PROCESS_INFORMATION ProcessInformation;
BOOL results = CreateProcess(0,
procName, // Process and arguments
0, // Process Attributes
0, // Thread Attributes
FALSE, // Inherit Handles
0, // CreationFlags,
0, // Environment
0, // Current Directory
&StartupInfo, // StartupInfo
&ProcessInformation // Process Information
);
// Cleanup
CloseHandle(ProcessInformation.hProcess);
CloseHandle(ProcessInformation.hThread);
}
Now, you only have to click on OK in the game lobby once, the first time you start the series of games. The bots will continue playing automatically, as long as you want (and don't crash

The tutorial wasn't written by me. The original author is [CsT]Snippy (could be found on #BWAPI @ freenode, his website: http://emotion.inrialpes.fr/people/synnaeve/)