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:
- A start location (type 214) makes no unit. Its place becomes the owner's start location.
- 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.
- 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.
- 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. - A Brood War unit in a game of the original StarCraft is not made.
- 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.
Some of what the game does with the fields is not what the layout suggests:
- The link flags at offset 10 are never read. An add-on is attached to its building, and a
nydus canal paired with its exit, only when each of the two records names the other's
serial number, as StarEdit writes them, and only with a unit in the same
UNITsection. A link written on one side alone leaves the add-on detached and the canal without an exit. An add-on also attaches only to the building it is made for: a Comsat Station to a Command Center, a Machine Shop to a Factory. - The owner bit of the fields-set word, and bit 0x40, are never read: the owner byte always counts.
- Hit points, shields and energy are per cent of the unit's maximum, and capped at it. Hit points of 0% leave the unit with 1/256 of a hit point, the least the game can store.
- Resources are kept in 16 bits, so 70,000 minerals become 4,464.
- The hangar count is used only for Carriers, Reavers and their heroes, only its low byte, and no more than the unit can hold: 300 is read as 44, and a Carrier gets 4.
- A state is applied only when its bit is set in both the special-states-set word and the states word. A Ghost placed cloaked starts cloaked only if its owner has Personal Cloaking, and a Zerg unit placed burrowed starts burrowed only if its owner has Burrowing (a Lurker burrows without it).
- The screen starts at the local player's start location.
- Start locations come from the last
UNITsection alone. A map that splits its units over two sections and puts the start locations in the first loses all of them: in a melee game the starting buildings and workers have nowhere to go, and every player is defeated at once. When a player has two start locations, the later record counts. - Only Players 1 to 8 can have a start location. Remastered ignores one for Players 9 to 12; 1.16.1 writes it past the end of its table of eight, over whatever the game keeps there.
| 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