Damage characters
SCRIPT_DAMAGE_CHARACTERS · opcode 0xf3 · 8 bytes
Script virtual machine · Opcode list · Adjusting character hit points
Rolls damage and inflicts it on one party member or on the whole party, with an optional saving throw.
Encoding
Offsets count from the opcode byte.
| Offset | Type | Field | Meaning |
|---|---|---|---|
| 0 | u8 | opcode | 0xf3 |
| 1 | s8 | character | Party slot, or SCRIPT_CHARACTER_ALL (−1) from ScriptCharacterTarget. |
| 2 | s8 | dice_count | Number of dice rolled for each target. |
| 3 | s8 | dice_sides | Number of sides of each die. |
| 4 | s8 | bonus | Added to the dice total; with no dice it is the whole damage. |
| 5 | s8 | flags | ScriptDamageFlags, sign-extended to 16 bits before use. |
| 6 | s8 | saving_throw_type | ScriptSavingThrowType; SCRIPT_SAVING_THROW_NONE disables the throw. |
| 7 | s8 | saving_throw_effect | ScriptSavingThrowEffect, applied after a successful throw. |
The operand names are inferred. With SCRIPT_DAMAGE_ITEM_BASED set, the three dice
operands name a character, an item and a strength switch instead, a form the
reference scripts do not use; see
item-based damage.
Example: f3 ff 02 06 00 04 05 03 rolls 2d6 for every party member, negated
by SCRIPT_DAMAGE_RING_NEGATES for a member wearing a ring of Feather Fall,
with no saving throw. It is the most frequent pattern in the reference scripts.
Behavior
The handler runs the steps below once for the given slot, or for slots 0 to
5 in turn with SCRIPT_CHARACTER_ALL. It does not check the slot range. For
each slot:1
- Roll.
dice_countdice withdice_sidessides, plusbonus. A count or a side count that is zero or negative adds no dice, so onlybonusremains. Each slot rolls separately. - Saving throw. Unless
saving_throw_typeisSCRIPT_SAVING_THROW_NONE, the character makes a saving throw. On success, the damage is changed as selected bysaving_throw_effect. - Flags. The flag bits adjust the damage
(
ScriptDamageFlags). - Inflict. If the result is nonzero and the character is present and not
dead (
CHARACTER_ELIGIBLE_PRESENTandCHARACTER_ELIGIBLE_NOT_DEADofCharacterEligibilityMask), the damage is inflicted.
Inflicting damage subtracts the amount from hit_points of
CharacterRuntime and stores its low
byte in last_damage. The reserves of Aid and Armor, aid_bonus_points if
nonzero and armor_spell_points if positive, are reduced by the same amount
and clamped at zero; when the Armor reserve reaches zero, the Armor
effect ends. These reserves do not reduce the damage.2
- Death. When the hit points reach −10 or less, the death routine sets them
to −10, keeps only the lowest bit of
status_flags, clearsfood, removes all the character's effects — lasting spells, timers, the reserves above — and plays sound effect 22. - Survival. Otherwise it plays sound effect 21.
Both paths also redraw the portraits. Damage that is rolled but not inflicted, for example for a missing character, has no other effect. The sound numbers are those of Play a sound.
Edge cases and unknowns
- The slot range is not checked: slots other than 0–5 and −1 read and write the memory past (or before) the six character records as if it held a character.
Observed use
The 164 reachable instructions of the 16 reference INF files all use
SCRIPT_CHARACTER_ALL. They have ten distinct operand patterns:
| Uses | Dice and bonus | Flags | Saving throw type | Saving throw effect |
|---|---|---|---|---|
| 133 | 2d6+0 | SCRIPT_DAMAGE_RING_NEGATES | none | negate |
| 22 | 6d6+0 | SCRIPT_DAMAGE_IGNORED_0002 | 4 | halve |
| 2 | 4d6+0 | SCRIPT_DAMAGE_IGNORED_0002 | 4 | halve |
| 1 each | 5d6+0, 2d6+0 | SCRIPT_DAMAGE_IGNORED_0002 | 4 | halve |
| 1 | 3d6+24 | SCRIPT_DAMAGE_IGNORED_0002 | 4 | negate |
| 1 each | 6d6+0, 3d6+0, 5d6+0, 0d0+8 | none | none | negate (no effect without a throw) |
Every 2d6 instruction is immediately followed by a level transition (72 of 133) or a party move (61 of 133). Of the other 31 instructions, 27 immediately follow Run a special event with the lightning event, which is the only use of that event in the reference scripts. These patterns are consistent with falling damage, a lightning trap and a resisted spell; those readings are inferred, since the DOS code does not name them.