Place a monster
SCRIPT_SPAWN_MONSTER · opcode 0xfb · 15 bytes
Script virtual machine · Opcode list · Scripted monster placement
Puts a new monster in a block. The game uses a free monster slot or, when all 30 slots are alive, takes the slot of the monster farthest from the party.
Encoding
Offsets count from the opcode byte. Words are little-endian. The operands are the fields of an INF monster record in a different order, without the slot index.
| Offset | Type | Field | Meaning |
|---|---|---|---|
| 0 | u8 | opcode | 0xfb |
| 1 | u8 | skipped | Not read; no effect. It is 0xf3 in all 283 reference instructions; preserve it. |
| 2 | s8 | unit | Update group: stored as unit * 2 + (slot index & 1) in update_group, which sets how often the monster acts (update cadence). |
| 3 | u16le | block | Destination block. A zero block clears the chosen slot and places nothing. |
| 5 | s8 | position | 0–3 a quarter of the block, 4 its centre (sharing a block); 4 is also special in the checks below. |
| 6 | s8 | direction | Facing, a Direction. |
| 7 | s8 | type_index | Monster type: an entry of the runtime monster-type area (46 bytes each). |
| 8 | s8 | graphics_index | Graphics bank of the level: 0 the first, any other value the second (monster images). |
| 9 | s8 | mode | Initial MonsterMode. |
| 10 | s8 | parameter | Stored as state_counter: the updates left in MONSTER_MODE_DELAYED or MONSTER_MODE_PARALYZED, the moves left while fleeing. |
| 11 | u16le | random_item | When nonzero, item of which the monster leaves a copy when it dies, one time in ten (when a monster dies). |
| 13 | u16le | fixed_item | When nonzero, item of which the monster always leaves a copy when it dies. |
The destination fields belong to MonsterRuntime.
Behavior
When nothing happens
The instruction does nothing, and the script continues, when any of these checks fails. They run in this order:1
- The block's occupancy (low three bits of its state word, see
LevelBlockStateFlags) equals 7. - The block is the party's current block.
- The occupancy is nonzero and either the new monster type's occupancy class (
occupancy_classin INF) is nonzero orpositionis 4. - A monster slot already in the block has
position4 or a type with a nonzero occupancy class. Hit points are not looked at.
Choosing the slot
The game takes the first of the 30 slots whose hit points are zero or
negative. If every slot is alive, it takes, among the slots without
MONSTER_RUNTIME_KEEP_SLOT, the one whose block is farthest from the party (at
a nonzero
distance). If no slot qualifies, nothing happens. A living monster in the
chosen slot is first removed from the level.1
Initializing the monster
The slot is zero-filled and then, for a nonzero block, filled as follows:2
| Slot field | Value |
|---|---|
type_index, position, direction, graphics_index, mode, state_counter, random_item_raw, fixed_item_raw | The operands above. |
update_group | unit * 2 + (slot index & 1). |
max_hp_raw, current_hp_raw | One roll of the type's hit-point dice (type bytes +3, +4, +5), in both. |
ranged_attacks_left | The type's number of ranged attacks. |
ranged_weapon_index | 0. |
slot_mod_3 | Slot index modulo 3. |
ranged_wait | A roll of 1d3, the ranged attack wait counter. |
sublevel | The low byte of the current sublevel word. |
Finally the monster is placed on its block, which raises the monster-enter event of that block; see monster movement events.
Sublevels and eviction
When all slots are alive, the choice does not look at the monsters' sublevel: a monster of another sublevel is measured by its block number like the others, and a monster of the current sublevel can be evicted. Only the monster count of conditions reads it; see sublevels. Whether play can reach 30 living monsters is unknown.1
Observed use
The 283 reachable instructions of the 16 reference INF files use unit 0 (159) or 1 (124); position 4 (163 times),
otherwise 0–3; direction 0–3;
type_index 0–5; graphics_index 0 (202) or 1 (81); mode 0 (186), 4 (50),
5 (33) or 6 (14); parameter always 0; an item word is nonzero in 29. Blocks
range from 12 to 1003. No instruction uses a zero block or a negative operand.