Party and character routines
Routines · Data · Address index
Portraits, swapping and removing characters, hit points, experience and levels, and saving throws. The routines page explains how the entries are written.
0x1ff4e — Party status check
- Range:
0x1ff4e–0x20014 - Role: Counts the characters passing the
eligibility test with mask 13 (present, conscious, neither
flag bit 2 nor 3). When none passes and its argument is nonzero, it runs
the defeat sequence: redraw the portraits (
0x1ff80); the defeat scene when bit 20 of the global flags is set (0x1ff85–0x1ff97); the two-choice question with string 67 of the list at file offset0x2c170(0x1ffa8); on No, the exit (0x1ffb4–0x1ffc1); on Yes,0x1ed9b(closes the inventory panel and the spell book), then the load menu with window position 0, 0 (0x1ffdc), and the exit when it returns 0 (0x1ffe8–0x1fff5). It returns 1 only when nobody can act and its argument is 0. Callers: the game loop first in every pass and the camp menu on leaving (0x44c87), both with 1; the rest routine with 0 (0x45975). - Comparative source: REF-SCUMM-014,
checkPartyStatus. - Used by: The game loop › When the party is defeated, Character eligibility tests › Masks used by character actions, The game loop › One pass of the game loop, Resting: special cases › Anomalies while resting, Conditions › Conditions, Resting › Every hour and every eight hours, Resting › When the rest ends, Global script flags, Level 12: reference tables › Khelben's vision
0x1e8c6 — Redraw every portrait
- Range:
0x1e8c6–0x1e8de - Role: Calls the portrait and sheet routine
0x29b09for each of the six character slots. The defeat sequence starts with it. - Used by: The game loop › When the party is defeated
0x1f267, 0x1ef59, 0x1f062 — Ask a two-choice question
- Ranges:
0x1f267–0x1f55b;0x1ef59–0x1f061;0x1f062–0x1f0c2 - Role:
0x1ef59(window, string)shows a button: it saves the button's area to page 2 through the page copy, unless the button, in the wordsDS:0xf100–0xf106(height, width, x, y), is over 84 rows high or 22 columns wide, draws the box and label on page 2 and copies them to the screen.0x1f062(window)puts the area back under the same condition, when the box closes (0x1f25c,0x1f54c).0x1f267(window, string, initial)selects a text window, prints string numberstringof the list at file offset0x2c170and draws two buttons labelled from the table atDS:0x5500("Yes" atDS:0x5528, "No" atDS:0x552c). The buttons are 32 × 14 pixels, Yes 8 pixels from the window's left edge and No 40 pixels from its right edge, 21 pixels above its bottom (0x1f2ac–0x1f2e9). initial 1 highlights Yes first, 0 No. In mouse control the button under the pointer is highlighted. A press of either mouse button on a button chooses it. Y chooses Yes, N No, Enter or Space the highlighted button, and keypad 4 or 6 (or the grey arrows) move the highlight; Shift, Ctrl and Alt are ignored (0x1f391), keypad 5 is not handled and Escape does nothing (0x1f39c–0x1f3d5). The highlighted label is drawn in colour 6, the other in 15. The chosen button is shown pressed for a moment. The routine returns 1 for Yes and 0 for No (0x1f551). The defeat sequence calls it with window 14 and string 67. - Used by: The game loop › When the party is defeated, The start menu, questions and text › Questions and messages, Texts, Camp menus
0x1be79 — Cancel a swap
- Range:
0x1be79–0x1beaf - Role: Callback of the last of the swap buttons: record
DS:0x46d8, code0x39, x 184, y 0, 136 × 120 pixels, either mouse button or Escape (key0x6e). It stops the blink (timed callback 0), clearsDS:0xee20, redraws the character and rebuilds the main button list. - Used by: Formation › Changing the formation, The play screen › Waiting for a character
0x1bd9c, 0x1959f — Swap two characters
- Ranges:
0x1bd9c–0x1be78;0x1959f–0x195f3 - Role: Triggered by a press of the right mouse button on the name
(button flags
0x1000, mouse button 2), or by Shift with F1 to F6 for characters 0 to 5. Handler of a character's name button (character number at button offset0x38). Returns unless the character passes the eligibility test with mask 1 (present). WhenDS:0xee20is0xff, stores the character there and redraws it with the "Swapping" label. Otherwise resetsDS:0xee20, swaps the two0x159-byte records through the shared buffer with0x1959f(three far copies), redraws both, makes the second the selected character through0x1e280and re-arms the character timers. WhenDS:0xe441is set, it first calls0x222c7, which closes the spell book. - Comparative source: REF-SCUMM-018,
clickedCharNameLabelRightandexchangeCharacters. - Used by: Character eligibility tests › Masks used by character actions, Formation › Changing the formation, Conditions › Conditions, Resting: special cases › Insal leaves, Character record › Unused bytes, The play screen › Click areas, How input works › The active button list
0x1c2e1, 0x1c3e6 — Eat the item in hand
- Ranges:
0x1c2e1–0x1c3e5;0x1c3e6–0x1c3fc - Role: Refuses with "%s isn't capable of eating food!" (
DS:0x35c6) unless the character passes the eligibility test with mask 5 (present and conscious); then takes the held item. Only type 31 is eaten: value −1 is refused withDS:0x35e8; otherwisefoodbecomesfood+ value, at most 100, the item'slocation_raw0xffffand the held item 0 (0x18c77), with sound 9. Another item prints "You may only eat food!" (DS:0x361b). Called by the use routine in keyboard control and by the button handler0x1c3e6(pointer atDS:0x44ec), the plate icon of the inventory page, for the selected character. - Comparative source: REF-SCUMM-018,
eatItemInHand. - Used by: Conditions › Conditions, Character eligibility tests › Masks used by character actions, Using items › Food and other uses, Sound effects, The play screen › The character panel, Item types
0x1b54d — Saving-throw table lookup
- Range:
0x1b54d–0x1b5c1 - Role: Arguments: group, level, category (signed bytes). Limits the
level to the group's cap (
0x1b578), divides it by the group's divisor (0x1b591), adds category × row length (0x1b5aa) and returns the signed byte at that index of the group's threshold table, through the group parameters. The category is not checked: the index is kept to a signed byte (0x1b5ac–0x1b5bd), so an unchecked category reaches −128 to 127 from the table start. Called only by the saving throw (0x204f5). - Used by: Saving throws › A character's saving throw, Saving-throw categories › How the saving throw is rolled
0x1e67c — Remove a character from the party
- Range:
0x1e67c–0x1e78d - Role: Removes a character, dropping its items, and makes character 0
the selected character (
0x1e77e) when it was the removed one. It writes 0 intostatus_flags(0x1e698), then inserts every item of the 27 inventory slots except the quiver into the party's block, each on one of the two front positions chosen by a 1d2 roll, and clears the slot (0x1e69d–0x1e709); it then unlinks the quiver's items one by one and drops them the same way (0x1e70d–0x1e76e). It ends by re-arming the character timers. No other field of the record is written. Overlay code reaches it through a fixed-up far call (see overlays). - Comparative source: REF-SCUMM-009,
removeCharacterFromParty. - Used by: Resting: special cases › Insal leaves, Recruiting and dismissing characters › Recruiting and dismissing characters, Run a sequence › Joining a full party, Run a special event › Recruit a character (event 4), Character record › Status, hit points and class, Character conditions
0x1e929 — Character eligibility test
- Role: Tests a character against
CharacterEligibilityMaskbits. It does not check the range of its arguments. - Used by: Award experience › Behavior, Change hit points › Behavior, Character conditions, Character eligibility tests, Character record › Status, hit points and class, Condition expression tokens › Operand layouts, Damage characters › Behavior, Print a message › Behavior, Run a special event › Choose a party member (event 1), Test a condition › Behavior, Values passed on to other routines › The routines, Level 13: reference tables › The guardian of the labyrinth
0x1edfc — Count eligible characters
- Range:
0x1edfc–0x1ee38 - Role: Arguments: an item type and a value. Counts the characters 0 to
5 that pass the eligibility test with mask 1 (present) and
carry an item of that type and value, found by the
inventory search. Used by expression token
0xf1with selector0xf5. - Used by: Character eligibility tests › Masks used by scripts, Condition expression tokens › Operand layouts, How a script runs › What the conditions test, Values passed on to other routines › The routines, Test a condition, Level 11: reference tables › The challenge, Level 13: reference tables › The guardian of the labyrinth
0x1ba55 — Experience threshold for a class level
- Range:
0x1ba55–0x1baa8 - Role: For a class, a component index and a level L, returns entry L − 1 of the experience table of the component's base class, or −1 when the class has no such component. Entry 13 of every table is −1, so no class reaches level 14; the level is not bounded.
- Comparative source: REF-SCUMM-014,
getRequiredExperience. - Used by: Experience and levels › Experience and levels, Run a special event › Level gain (event 2)
0x1b5c2, 0x1b5dc — Class components
- Role:
0x1b5c2returns the base class of component i of a class from the class components (0xffwhen there is none);0x1b5dcreturns the component index of a given base class, or −1. - Comparative source: REF-SCUMM-014,
getCharacterClassType. - Used by: Resting › A step of rest, Resting: special cases › Anomalies while resting
0x1b70e — Constitution hit-point modifier
- Range:
0x1b70e–0x1b73a - Role: Reads the constitution table for a score and
lowers a result above +2 to +2 unless the class mask has
the fighter, paladin or ranger bit (
0x31). - Comparative source: REF-SCUMM-014,
getClassAndConstHitpointsModifier. - Used by: Attributes and classes › Classes
0x1b73b — Hit points for a level
- Range:
0x1b73b–0x1b7fc - Role: For each component selected by a bit mask, adds a roll of the base class's hit die — or its fixed gain above the last rolled level — and the constitution modifier; divides the sum by the number of classes and returns at least 1.
- Comparative source: REF-SCUMM-014,
generateCharacterHitpointsByLevel. - Used by: Experience and levels › Gaining a level
0x1b7fd, 0x1b88e, 0x1b94a — Hit-point limits
- Ranges:
0x1b7fd–0x1b88d,0x1b88e–0x1b949,0x1b94a–0x1ba05 - Role:
0x1b7fd(type, modifier, level, mode)returns the hit points of one base class: the rolled levels, at most the last rolled level of the hit-point tables, times the hit die (mode 0) or once each (mode 1); plus the fixed gain for each level above; plus level × modifier, except in mode 1 when the modifier is not positive.0x1b88e(mode 0, maximum) and0x1b94a(mode 1, minimum) take a class, a constitution and three levels, apply the constitution modifier, add0x1b7fdover the components and divide by the number of classes. The literal calls of0x1b88eand0x1b94aare in modify a character. - Comparative source: REF-SCUMM-017,
getModifiedHpLimits,getMaxHpandgetMinHp. - Used by: The creation screen › Modifying a character
0x1ba06 — Strength text
- Range:
0x1ba06–0x1ba54 - Role: Formats a strength for display:
%d/%02dwhen the exceptional strength is positive, 100 being shown as00, and%dotherwise. - Used by: Attributes and classes › Attributes
0x20015 — Adjust hit points
- Range:
0x20015–0x20070 - Role: Arguments: slot and signed amount. Returns unless the slot passes
eligibility mask 3 (
0x20024); adds the amount tohit_points(0x20046) and lowers a result abovehit_points_maxto it (0x2004e–0x20058), with no lower limit and no death test, unlike damage (ANOMALY-86); then redraws the hit-point display and the portrait. Callers: potions (0x1dad9,0x1db03), spell routines (0x24780,0x249fb,0x24a74,0x24b26,0x24e33) and the handler of0xf4(0x265ca,0x265dc). With the original files, slots 6 and 7 fail the test, so neither redraw runs for them. - Used by: Change hit points › Behavior, Character eligibility tests › Masks used by scripts, Scripted characters, flags and messages › Characters, Change hit points, Values passed on to other routines › The routines, Change hit points › Edge cases, Anomalies and bugs
0x20071, 0x2015f — Award experience
- Ranges:
0x20071–0x2015e,0x2015f–0x201bb - Role:
0x2015fshares an award between the eligible party members.0x20071divides a character's award by its number of classes at0x2009d, with the signed 32-bit division0x18551, whose quotient rounds toward zero, adds the share to the 32-bit experience of each component (0x200df–0x200e3), and calls gain a level for a component whose experience is strictly above its next threshold in an unsigned comparison (0x20136–0x20140), so experience taken below zero by a negative award counts as above every threshold (ANOMALY-87). Special event 2 calls it once per class at0x27a1c(range0x2797d–0x27a2f) with that class's missing experience, which the division reduces. - Comparative source: REF-SCUMM-014,
increasePartyExperienceandincreaseCharacterExperience. - Used by: Award experience › Behavior, Character eligibility tests › Masks used by scripts, Character record › Attributes, Experience award target, When a monster dies › In what order, Experience and levels › Experience and levels, Run a special event, Run a special event › Level gain (event 2), Scripted characters, flags and messages › Characters, Award experience, Level data (INF), Anomalies and bugs
0x201bc — Gain a level
- Range:
0x201bc–0x20246 - Role: Adds one to the component's level, adds the
hit points for a level to
hit_pointsandhit_points_max, prints the level message formatted fromDS:0x5590with the name, redraws the portrait and plays sound 23. - Comparative source: REF-SCUMM-014,
increaseCharacterLevel. - Used by: Character record › Attributes, Experience and levels › Gaining a level, Award experience › Behavior, Sound effects
0x204da, 0x20574 — Saving throw and damage reduction
- Ranges:
0x204da–0x20573,0x20574–0x2059c - Role:
0x204datakes a record, a group, a level, a category and a race. It returns 0 for category 5 (0x204de); otherwise it takes the threshold from the table lookup and subtracts the constitution adjustment of the record's byte+0x17when the race is 3 or 5 and the category 0, 1 or 4 (0x20502–0x20534), or 4 and the category 4 or 1 (0x20538–0x20553). It returns 1 when 1d20 is at least the threshold (0x20566). Callers: the character saving throw (0x1e91d), the damage calculation (0x208e2), the monster damage calculation (0x206f7) and the spell effects on a monster (0x20cae); the two monster callers pass group 0, the type's level and race 6.0x20574then reduces the damage: effects 0 and 1 halve it, effect 3 cancels it. The caller lists of0x204da,0x1e8dfand0x2098ecome from a search of the whole file, overlays included, for direct calls, stored far pointers and code loading their offsets; it found no stored pointer and no loaded offset. - Used by: Saving throws › A character's saving throw, Damage to a monster › How the damage is reduced, Damage characters › Behavior, Saving-throw categories › How the saving throw is rolled, Saving-throw categories, Saving-throw effects on damage
0x1e8df — A character's saving throw against an effect
- Range:
0x1e8df–0x1e928 - Role: Arguments: a character and a saving-throw category. Calls the
saving throw with the character's record, the
class modifier index of its class, its first class
level (
+0x26), the category andrace_and_sexshifted right once; returns 1 when the character saves. Called by afflict a character with a condition and by the ray saving throw. - Comparative source: REF-SCUMM-021,
specialAttackSavingThrow. - Used by: Character conditions › How a character gets a condition, Melee attacks › Effects on characters, Saving-throw categories › Other uses of the categories
0x204a0 — Saving throw against a monster ray
- Range:
0x204a0–0x204d9; faulty comparison0x204cc–0x204cf - Role: Arguments: a character and a value. Rolls the
character's saving throw with category 4, which gives 0 or 1,
then 1d20. The comparison at
0x204ccand the jump at0x204cfreturn the value unchanged only when the d20 is below that 0 or 1, which never happens; otherwise the routine returns the value halved. The monster spell hits call it with 1 for disintegration (always 0: never saved) and 2 for petrification (always 1: always saved). - Comparative source: REF-SCUMM-021,
charDeathSavingThrow. - Used by: Ranged attacks › Monster spells, Saving-throw categories › Other uses of the categories, Anomalies and bugs
0x2098e, 0x20854, 0x209fc, 0x209cf — Damage characters
- Ranges:
0x2098e–0x209ce,0x20854–0x2098d,0x209fc–0x20b21, and0x209cf - Role: Calculate damage, apply it to a character, and kill a character
whose hit points reach −10 or less. The saving throw of the damage
calculation passes the character's whole byte
+0x21as the race (0x208bf), where the other saving-throw path shifts it right once.0x2098eis called at0x1f890,0x20df4,0x2193b,0x21a47,0x2667c,0x2669dand0x28664. - Used by: Character conditions, Character eligibility tests › Masks used by scripts, Character eligibility tests, Character record › Character timers, Character record › Status, hit points and class, Damage characters › Behavior, Damage flags › Effects, Damage flags, Lasting spell effects, Melee attacks › The attack sequence, Resting: special cases › Anomalies while resting, Resting › Every hour and every eight hours, Resting › When the rest ends, Saving-throw categories › How the saving throw is rolled, Saving-throw categories, Saving-throw effects on damage, Scripted characters, flags and messages › Characters, Change hit points, Values passed on to other routines › The routines, Sound effects, Flying weapons › What a flying item hits, Anomalies and bugs