when will that enemy building complete?
Today I pretended to have enough time to play around, fired up my development vm for the first time in days, and took an hour out to solve a niggling issue: How do you correctly predict when an enemy building will finish? My first try gave inaccurate predictions.
If it’s your own building, call building->getRemainingBuildTime()
, done. If it’s an enemy building, that doesn’t work. You can see the building’s hit points and predict its completion time from that, but it’s a little tricky. Today I learned the 2 tricks.
One: A building just starting construction doesn’t start at 0 hp and work up, it starts at 10% of its final hp. Over the course of construction, it progresses smoothly from 10% to 100%. Liquipedia on buildings explained it to me. Two: After the hp reach 100%, there is extra latency before the building is actually complete. I didn’t read OpenBW, but a few quick experiments let me measure the latency fairly closely. I got 2 frames for a terran building, 72 or 73 frames for a protoss building for the warping-in animation, and 9 frames for a zerg building. Knowing that, with one glance you can predict the completion of an enemy building to within a few frames (usually to +/- 1 frame in my tests).
// Predict the completion of a building under construction from its current HP. // isBeingConstructed() is false for a terran building with no SCV building it. // It's also false for non-buildings, so we don't need to check that separately. // A morphed zerg building cannot be predicted this way, so skip those. if (unit->isBeingConstructed() && !UnitUtil::IsMorphedBuildingType(type)) { // Interpolate the HP to predict the completion time. // This only works for buildings. The prediction is usually accurate to within a few frames. // Known cases where the prediction is wrong: // * The building was damaged. // * The prediction is made during the extra latency period (see below). // A building begins with 10% of its final HP. double finalHP = double(type.maxHitPoints()); double hpRatio = (unit->getHitPoints() - 0.1 * finalHP) / (0.9 * finalHP); // Buildings have extra latency for their completion animations. int extra; if (type.getRace() == BWAPI::Races::Terran) { extra = 2; } else if (type.getRace() == BWAPI::Races::Protoss) { extra = 72; } else // zerg { extra = 9; } return extra + BWAPI::Broodwar->getFrameCount() + int((1.0 - hpRatio) * type.buildTime()); }
Here unit
is the building and type
is equal to unit->getType()
.
As the code comments point out, there are ways for it to go wrong. It doesn’t work on a terran building if the constructing SCV has wandered off to play pinochle. It doesn’t work on a zerg morphed building, like a sunken colony morphed from a creep colony or a lair morphed from a hatchery, only on a zerg building made from a drone. If you shoot at the building and hurt it, you’ll get a wrong answer. If the HP have already reached 100% and the building is in its extra latency period, then there’s not enough information to know. I think all those issues can be corrected for if you make the effort, but I didn’t today.
Did I miss anything else? My short time was not enough for many tests.
Using the building completion times for enemy static defense will help the combat simulator avoid mistakes. And the times of tech buildings will help decipher the enemy build order.
Comments
Dan on :
https://github.com/dgant/PurpleWave/blob/master/src/ProxyBwapi/UnitInfo/UnitInfo.scala#L107-L121
plus
https://github.com/dgant/PurpleWave/blob/master/src/ProxyBwapi/UnitInfo/ForeignUnitInfo.scala#L372-L379
I think it's the same as yours, but handles non-building units, and correctly tracks units in fog, but doesn't account for the extra frames to finish construction.
Dan on :
Johan de Jong on :
Jay Scott on :
Dan on :
https://www.reddit.com/r/broodwar/comments/fix1q9/another_starcraft_subtlety_protoss_building_delay/
https://docs.google.com/spreadsheets/d/1RsH2f-hQv26zV9831xbpnO4tCMXuTCorXYc9pjwrdSk/edit#gid=0
I vaguely suspect based on recent exposure to BW mechanics that this chart might actually not be accurate either, and that it's based on something like an every-4-second check that a warping building is now complete.
Jay Scott on :