Regeneration

From StarCraft AI, the resource for custom StarCraft Brood War AIs
Jump to: navigation, search
Original article at Staredit Network Wiki

In StarCraft, regeneration is the slow increase of a unit's health, shields, or energy.

How It Works

To understand regeneration, you have to understand that Starcraft hides data from you. Health and Shields each are stored in memory in 4 bytes, however Starcraft only tells you the last 3 bytes. The first byte is actually a hidden value which acts as a timer for regeneration. 1 byte = 8 bits, or 28 = 256.

Each frame, a certain regeneration amount is added (or subtracted) to the first byte, according to values in the mpqs:

  • Protoss Shields: 7
  • Zerg Health: 4
  • Energy: 8
  • Shield Battery: 1280
  • Recharge Shields: -640 (-632 net)
  • Burning Terran Building: -20
  • Medic: 200
  • Personnel Cloaking(Ghost): -18 (-10 net)
  • Cloaking Field(Wraith): -21 (-13 net)
  • Heal: -100 (-92 net)

SCVs repair units and buildings in a similar way, based on build time and total HP. Multiple SCVs increase the repair rate by adding them together.
R = roundup(.9 * H/B)
where R = repair rate in 1/256 of hp per frame, H = HP, B = build rate in SCMDraft.
One important note is that R is a 2 byte value, which means that when R > 65535, it loops back over to 0. Here is an example:
A Terran Barracks with a build time of 1, HP of 9999.
R = roundup(.9 * 256*9999/1) = 2303770. R>65535, so it rolls over in multiples of 65535.
R = 2303770- k65535, R = 10010. Note that this is still fairly large, and means that each SCV will repair approximately 39 HP every frame.
A slightly more realistic value is that of the default battlecruiser with 500 HP, 2000 Build time:
R= roundup(.9 * 500*256/2000) = 58.

Building units follows the same formula, and this explains why some buildings/units come out injured, except they start out with 10% of the base HP, plus 1 frame of "repairing", plus the time it takes to build. In the case of the terran barracks, it will build in 1 frame and come out with .1 * 9999 + 10010/256 + 10010/256 = 1078.1 HP.

Healing Rates

Since Starcraft is normally played on fastest, or 24 fps, we can calculate the approximate rates of healing:

  • Protoss shields use 7, so 256/7/24=~1.5 seconds per shield point.
  • Zerg Health use 4, so 256/4/24=~2.67 seconds per health point.
  • Medics' Healing uses 200, so 256/200/24=0.053 seconds per health point or 18.75 health per second.
  • Shield batteries use 1280, so 256/1280/24=0.0083 seconds per shield point or 120 shields per second.