Regeneration

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:

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 - k × 65535 = 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 the Fastest speed, which runs at about 24 frames per second (see Frame Rate), we can calculate the approximate rates of healing: