scmJS docs

UNIT

The units placed on the map, 36 bytes each. Start locations are units too, of type 214.

A unit record can set the unit's hit points, shields, energy, resources and hangar as percentages or amounts, and states such as cloaked or burrowed. Each of these is used only when its bit is set in the record's fields-set or special-states word, so a record can set the hit points alone.

When a game starts, each record goes through these checks, in this order, before a unit is made:

  1. A start location (type 214) makes no unit. Its place becomes the owner's start location.
  2. An owner among Players 1 to 8 whose slot is empty in this game: the unit is dropped. Neutral units stay. 1.16.1 and Remastered both do this.
  3. Melee, or any game type but Use Map Settings: the unit is kept only if it is a Player 12 mineral field, geyser or critter.
  4. Use Map Settings, and the owner's race is User Selectable (see SIDE): the unit is kept only if it is a neutral kind: a mineral field, geyser, critter, power-up, door or trap, or a Map Revealer, Dark Swarm or Disruption Web.
  5. A Brood War unit in a game of the original StarCraft is not made.
  6. No room to place it: a ground unit standing on another is moved aside to the nearest free spot, but one whose footprint touches ground it cannot walk on, such as water or a cliff, is removed, with WARNING: Unit unplaceable! on screen. Buildings are made where the record puts them, on any ground and over other units. Checked against 1.16.1; Remastered removed a Marine placed on water the same way.

Then the unit is made, and the record's fields are applied, each only when its bit is set.

What the game does with a placed unit

Some of what the game does with the fields is not what the layout suggests:

The unit record, byte by byte

Name UNIT (55 4E 49 54)
Size 36 bytes per unit.
Read by The game, at the start of every game, whatever its type.
Required Yes. Without it the map is listed, but every game on it stops at the start with Error loading scenario file.
The game accepts Whole units only. A length that is not a multiple of 36 refuses the map.
More than one copy The copies are joined into one list, with two exceptions: start locations come from the last copy alone, and an add-on or nydus canal is linked only to a unit in the same copy.
In scmJS Read, and written again when you change what it holds.

Each unit:

Offset Type Holds
0 u32 The unit's serial number, unique in the map; add-ons and nydus canals are linked by it
4 u16 X position in pixels
6 u16 Y position in pixels
8 u16 Unit type
10 u16 Link flags editors write; the game ignores them (below)
12 u16 Which special states the record sets (below)
14 u16 Which of the following fields the record sets (fields set, below)
16 u8 Owner, 0 for Player 1
17 u8 Hit points, per cent of the maximum
18 u8 Shields, per cent
19 u8 Energy, per cent
20 u32 Resources, for a mineral field or geyser
24 u16 Units in the hangar: interceptors or scarabs
26 u16 The special states themselves
28 u32 Unused
32 u32 Serial number of the linked unit

Link flags:

Bit Meaning
0x0200 StarEdit writes it on both units of every linked pair, an add-on and its building or two nydus canals. The game ignores it
0x0400 Called the add-on link in older references. The game ignores it

Special states:

Bit Meaning
0x01 Cloaked
0x02 Burrowed
0x04 In transit: a Terran building that can fly starts lifted off
0x08 Hallucinated
0x10 Invincible

Fields set:

Bit Meaning
0x01 Owner
0x02 Hit points
0x04 Shields
0x08 Energy
0x10 Resources
0x20 Hangar
0x40 State

Example#

A Protoss Carrier for Player 2 with half its hit points, full shields and four interceptors. The record's fields-set word names the owner, hit points, shields and hangar, so the game uses the hit points, shields and hangar and ignores energy and resources. The owner bit is set as StarEdit sets it, though the game reads the owner byte either way:

   0  11 00 00 00  serial number 17
   4  50 06        x 1616 px (tile 50)
   6  50 03        y 848 px (tile 26)
   8  48 00        unit type 72, Protoss Carrier
  10  00 00        no link flags (the game ignores them)
  12  00 00        sets no special states
  14  27 00        sets: owner, hit points, shields, hangar
  16  01           owner: Player 2
  17  32           hit points 50%
  18  64           shields 100%
  19  00           energy 0% (not set, so not used)
  20  00 00 00 00  resources 0 (not set)
  24  04 00        4 in the hangar
  26  00 00        no special states
  28  00 00 00 00  unused
  32  00 00 00 00  no linked unit