The container
A scenario is a flat run of sections, with no header of its own. Each section is a four-character name, a 32-bit length, and that many bytes of data:
| Offset | Type | Holds |
|---|---|---|
| 0 | 4 characters | The name, padded with spaces to four: VER , DIM , STR |
| 4 | i32 | The length of the data, in bytes |
| 8 | the length | The data |
The next section starts straight after the data. The order of the sections in the file does not matter: the game first lists every section, and then handles them in an order of its own. StarEdit's order, the order of this reference, is only a convention.
All numbers in every section are little-endian. Unsigned unless a layout says i32.
Positions are in pixels, and a tile is 32 pixels square. Player slots are numbered from 0
for Player 1 to 11 for Player 12. Text is never stored in a section itself: a section
holds a string number, the position of the text in the string table, and 0 means
no text.
Odd lengths#
The game finds the sections by reading a header, jumping over the length it gives, and reading the next header there. It does not check the names, and it does not check that a jump goes forward.
- A name the game does not know is passed over. It need not be text: any four bytes will do.
- A negative length jumps backwards. The game then reads bytes it has already read as new headers, which lets a file hide a section inside another one's data. A length of −8 lands on the same header again and again, and the game hangs.
- A length that runs past the end of the file ends the walk. The section is still
kept, cut short, and refuses the map if the game reads that section, because every read
checks that a section's bytes are really there. On a section the game never reads, such
as
ISOM, it does no harm. - Bytes after the last section: fewer than 8 are ignored. Eight or more are read as one more header.
Lengths#
Every section the game reads has a length it insists on, and a section of any other length refuses the map. A fixed-size section one byte too long makes the map invalid, and a record section must hold whole records.
| The game wants | Sections | A different length |
|---|---|---|
| Exactly this many bytes | VER␠ 2, VCOD 1040, OWNR 12, ERA␠ 2, DIM␠ 4, SIDE 12, PUNI 5700, UPGR 1748, PTEC 912, UPRP 1280, MRGN 1280 (VER 59) or 5100, SPRP 4, UNIS 4048, UPGS 598, TECS 216, COLR 8, PUPx 2318, PTEx 1672, UNIx 4168, UPGx 794, TECx 396 |
Refuses the map |
| Whole records of this size | UNIT 36, THG2 10, TRIG 2400, MBRF 2400 |
Refuses the map |
| At most this many bytes | MTXM 131072, FORC 20 |
Longer refuses the map; shorter is taken |
| Any length | MASK, STR␠ |
Taken |
Three sections may be shorter than the map needs. A short MTXM leaves the rest
of the map's tiles as the game found them in memory. A short FORC is filled out
with zeros. MASK takes any length, and the tiles it does not reach start
unexplored. Each section's page gives its rule in the row The game accepts.
Repeated sections#
A section can appear more than once. The game hands every copy, in file order, to the part of its code that reads that section, and what happens then depends on the section. Each section's page says which in its More than one copy row; there are four main ways:
- The last copy replaces the others. Most sections: with two
DIMsections the map has the size the second one gives. Every copy is still checked, so a decoy copy of the wrong length refuses the map rather than being passed over. - Each copy is written over the start of the same space. The terrain and the fog: the
copies go into one space of a fixed size in file order, so a later copy replaces only as
many bytes as it carries. A second
MTXMhalf the size of the map rewrites the top half of the terrain and leaves the bottom as the first copy had it. - The copies are joined into one list. Units, sprites, triggers and briefings: the
records of all the copies, in file order, so two
TRIGsections are one longer trigger list. - The settings tables are combined entry by entry. A copy of
UNIxchanges only the unit types it marks as not using the game's own values. A unit type it leaves on the defaults keeps what an earlier copy gave it.
A few sections have rules of their own:
VCOD: every copy is checked, and one bad copy refuses the map.STR: in 1.16.1 the last copy wins whatever its length, even 1 byte. Remastered passes over a copy shorter than 2 bytes.MRGN: every copy must be the full size.COLR: each copy rearranges the colours the copy before left.UNIT: the start locations come from the last copy alone, and an add-on or nydus canal is linked only to a unit in its own copy.