Last modified 18 months ago
Last modified on 11/30/10 02:35:58
Sample VLO file:
script "player1.slo" run { me int 1 }
Sample SLO file:
///////////////////////////////////////////////////////////////////// // New ai for skirmish game ///////////////////////////////////////////////////////////////////// // How many world coordinate points per tile #define TILE 128 // From VLO file public int me; // Who we are // Global state private bool bRunning; private GROUP buildGroup; private int baseX, baseY; // Global function references to be used in trigger definitions private string message; private int sender; // Declaring triggers, events and functions #region triggers trigger startLevelTr (CALL_START_NEXT_LEVEL); trigger consoleTr (CALL_CONSOLE, ref sender, ref message); #endregion triggers event startLevel(startLevelTr) { console(getPlayerName(me) & " AI is started"); } function void shutDownAI() { bRunning = false; setEventTrigger(startLevel, inactive); } /* returns TRUE if AI is responsible for the _player */ function bool aiResponsibleForPlayer(int _player) { if (_player == selectedPlayer or not myResponsibility(_player)) { return FALSE; } return TRUE; } event initialisedEvent(CALL_GAMEINIT) { local DROID droid; // setup build group - all initial droids are in buildgroup! groupAddArea(buildGroup, me, 0, 0, (mapWidth * TILE), (mapHeight * TILE)); // note where our base is. initIterateGroup(buildGroup); // find idle droids in build group. droid = iterateGroup(buildGroup); if (droid != NULLOBJECT) { baseX = droid.x; baseY = droid.y; } if (aiResponsibleForPlayer(me)) { bRunning = true; } else { bRunning = false; shutDownAI(); } } function void reassignAI() { bRunning = true; setEventTrigger(startLevel, startLevelTr); } event consoleEv(consoleTr) { // Turn on 'autogame' if (message == "autogame on" && (sender == me)) { if (debugModeEnabled()) { if (myResponsibility(me)) { if (not bRunning) //make sure current machine is responsible for this AI and it's not already active { console(getPlayerName(me) & " is active"); reassignAI(); } } } } // Turn off 'autogames' if (message == "autogame off" && debugModeEnabled() && (sender == me)) { if (bRunning) //make sure this AI is active { console(getPlayerName(me) & " is deactivated"); shutDownAI(); } } }
This is a basic AI skeleton that should be well behaving in respect to expected start up sequences and commands.
