Flag operation targets
ScriptFlagTarget · 1 byte, first operand of Set a flag
and Clear a flag
Scripted characters, flags and messages · Script instructions
Scripts keep state in flags: bits of the current level, bits kept across the whole game, a monster's state, a scratch variable, and whether the party may rest. This byte chooses which one the instruction changes. The two instructions accept slightly different sets of targets.1
Other values are unknown.
typedef enum ScriptFlagTarget {
SCRIPT_FLAG_TARGET_LEVEL = 0xef, /* A bit of the current level's flags. */
SCRIPT_FLAG_TARGET_GLOBAL = 0xf0, /* A bit of the global flags. */
SCRIPT_FLAG_TARGET_MONSTER = 0xf3, /* A bit of a monster slot's flags; set only. */
SCRIPT_FLAG_TARGET_RUN_VARIABLE = 0xe4, /* Write 1 (set) or 0 (clear) to the run variable. */
SCRIPT_FLAG_TARGET_REST_ALLOWED = 0xd1 /* Set allows resting; clear forbids it. */
} ScriptFlagTarget;
Operands
SCRIPT_FLAG_TARGET_LEVELandSCRIPT_FLAG_TARGET_GLOBALtake one bit-index byte. The global bits are described in global script flags.SCRIPT_FLAG_TARGET_MONSTERtakes a monster slot selector and a bit index.SCRIPT_FLAG_TARGET_RUN_VARIABLEandSCRIPT_FLAG_TARGET_REST_ALLOWEDtake no operand, although the clear handler reads the following byte before choosing its branch.
See script flags for the operations.
Provoking a monster
With SCRIPT_FLAG_TARGET_MONSTER, the handler sets the bit in the monster's
state flags and switches the monster to
MONSTER_MODE_PURSUE, without changing its stored destination. All reference
scripts use bit 0, MONSTER_RUNTIME_PROVOKED, which makes the monster pursue
the party. Valid operand ranges are unknown. See
setting a monster flag.
Forbidding rest
SCRIPT_FLAG_TARGET_REST_ALLOWED controls one byte that the rest routine checks
before letting the party rest. Setting the target writes 0, which allows
resting; clearing it writes 1, and the rest routine then refuses with a
message that it is not safe to rest. It is the first of the tests made
before a rest; see resting.2
No other code writes this byte, and it starts at 0. A level change leaves it unchanged: a prohibition set on one level stays in force on the next, until a script allows resting again. The byte is part of the level and party state that the game writes to its saved-game file and reads back, so it also survives saving and reloading.3
Sources
Locations refer to the game executable reference.