Skip to main content

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.

OffsetTypeFieldMeaning
0u8opcode0xf3
1s8characterParty slot, or SCRIPT_CHARACTER_ALL (−1) from ScriptCharacterTarget.
2s8dice_countNumber of dice rolled for each target.
3s8dice_sidesNumber of sides of each die.
4s8bonusAdded to the dice total; with no dice it is the whole damage.
5s8flagsScriptDamageFlags, sign-extended to 16 bits before use.
6s8saving_throw_typeScriptSavingThrowType; SCRIPT_SAVING_THROW_NONE disables the throw.
7s8saving_throw_effectScriptSavingThrowEffect, 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

  1. Roll. dice_count dice with dice_sides sides, plus bonus. A count or a side count that is zero or negative adds no dice, so only bonus remains. Each slot rolls separately.
  2. Saving throw. Unless saving_throw_type is SCRIPT_SAVING_THROW_NONE, the character makes a saving throw. On success, the damage is changed as selected by saving_throw_effect.
  3. Flags. The flag bits adjust the damage (ScriptDamageFlags).
  4. Inflict. If the result is nonzero and the character is present and not dead (CHARACTER_ELIGIBLE_PRESENT and CHARACTER_ELIGIBLE_NOT_DEAD of CharacterEligibilityMask), 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, clears food, 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:

UsesDice and bonusFlagsSaving throw typeSaving throw effect
1332d6+0SCRIPT_DAMAGE_RING_NEGATESnonenegate
226d6+0SCRIPT_DAMAGE_IGNORED_00024halve
24d6+0SCRIPT_DAMAGE_IGNORED_00024halve
1 each5d6+0, 2d6+0SCRIPT_DAMAGE_IGNORED_00024halve
13d6+24SCRIPT_DAMAGE_IGNORED_00024negate
1 each6d6+0, 3d6+0, 5d6+0, 0d0+8nonenonenegate (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.

Sources​

Footnotes​

  1. Handler for 0xf3, the damage calculation, the dice roll, the saving throw and the eligibility test. Comparative source: oeob_calcAndInflictCharacterDamage in REF-SCUMM-003. Statistics come from decoding the scripts reachable in the 16 reference INF files. ↩

  2. Damage infliction and death. Comparative source: EoBCoreEngine::calcAndInflictCharacterDamage in REF-SCUMM-013. ↩