tracking enemy comsat scans
Today I implemented tracking of enemy scans in Steamhammer, a new feature allowed by BWAPI 4.4.0. Before, there was no way for a bot to know if the terran enemy had scanned you, except to notice that a burrowed or cloaked unit you had thought was undetected was suddenly being fired on.
It’s simple. An enemy comsat scan is represented as an unseen enemy detector unit (that potentially exists() from BWAPI’s point of view) with unit type Spell_Scanner_Sweep. To find the scans, iterate through BWAPI::Broodwar->enemy()->getUnits() and pick them out by unit type, done. The scan unit has the same sight range and the same detection range as a science vessel, 10 tiles or 320 pixels.
Unlike the disruption web unit and the dark swarm unit, theSpell_Scanner_Sweepunit is “flying”—the unit type returns true forisFlyer()(I assume that is what makes it equivalent to a science vessel). After realizing that, I searched for related bugs, and found some. One sneaky bug caused by the upgrade to BWAPI 4.4.0 was sending scourge to the location of a scan—“must shoot down the enemy air unit!” Another sneaky bug that was there all along was in analyzing the map: If the map had neutral dwebs or neutral dark swarms, then the tiles under those spells would be marked unwalkable in the internal representation; I never noticed, partly because few maps have permanent spells and partly because Steamhammer doesn’t implement pathfinding yet. I added checks for whether a given unitisSpell()in a number of places.
The scanner sweep unit has getRemoveTimer() so you can tell how long the scan will last. For enemy scans, it always returns 0 in my tests. That kind of makes sense, but it was not what I expected. I thought BWAPI would try to judge the visibility of the scan by whether you could see the swirling sparkles, which tells a human player both where and when the scan occurred, so it is enough information to judge duration. The change log says “the visibility of the scan is approximate and not accurate,” but nothing more.
Comments