SCRMaps
/
Sign in

Making the computer player act

The stock AI scripts that make a computer attack and share vision - and the two reasons its units stop moving: a ceiling at a thousand, and one flag bit.

12 min read

A computer player does nothing on its own. To make it act you run an AI script, which is the Run AI Script action. The list mixes full campaign intelligences with one-shot commands like a single Recall or turning shared vision on.

Some entries are patterns rather than literal names - the race and number slots are filled in on the real list - so check the reference page for the full names.

The kinds you will reach for
Attack orderSend what the computer has gathered at a point. The simplest way to make a wave.
Junk Yard DogUnits wander aimlessly - what you use for mobs that mill about.
Shared visionTurns shared vision between a player and the computer on and off.
Alliance settingsChanges ally and enemy status during the game.
Campaign AIActually builds a base, researches, and attacks.

The campaign intelligences are worse than you expect. Even the Insane Terran goes four Barracks, four Factories, four Starports and happily builds Ghosts and Scouts. Do not design a map on the assumption that the computer will play well.

Enough computer units and they stop working altogether. Past about 1,000 computer-owned units the rest neither retaliate nor move when hit. It is not the unit table running out - it is a ceiling on the Guard AI, and a defence map that spawns a lot of waves lands on it exactly.

What a 2x2x2 experiment found
Hero checkedChecked, the unit never breaks - whether or not its base unit is a hero.
No-guard checkedThat unit does not count toward the 1,000 at all, apparently because it never enters the Guard AI.
No-guard on · hero offAlways broken, even below 1,000 - unless the unit was placed in the editor.

The key is that there are two goals and two answers. For a unit that does not count toward the 1,000, check does-not-become-Guard; for a unit that still works once the 1,000 is passed, check Hero. They are not the same thing.

Both have a price. The Hero flag fixes "does not respond to attacks" and loses the ordinary AI behaviours with it: Zerg burrowing, the plain Arbiter not attacking, spellcasters casting of their own accord, breaking off a chase. Guard-disabled alone needs a dat edit too - set the computer's idle AI to 3, Player Guard, or the unit is unresponsive even below 1,000 - and in that state it cannot perform a spell driven by RunAIScriptAt. Workers, Lurkers and units with subunits are outside the experiment entirely.

And computer units freeze. It is the thing people call "stepping in gum", and the computer's version is not the player's: the unit stands facing its target as if on Hold, and walking behind it or hitting it does not clear it. The cause is one bit in the struct - statusFlags at 0xDC has 0x80000 set, and clearing it starts the unit moving again.

function StopDogEPD(epd) {
    if (MemoryXEPD(epd + 0xDC/4, Exactly, 0x80000, 0x80000))
        SetMemoryXEPD(epd + 0xDC/4, SetTo, 0, 0x80000);
}
Guard it rather than writing every cycle: the test is one condition, and the write then almost never runs.

There are two computer freezes and two fixes. Using only the above leaves the one BetterBrain handles, and using only BetterBrain leaves this one; together they go away. And 0x80000 officially means a ground unit in a transport or burrowed, so if the map has burrowing, bunkers or transports, exclude those from the condition.

The full AI script list