Skip to content

types-decl

Branded types for type safety

type ObjectPtr<T extends string = string> = number & { __type: T }

Object pointer - an integer handle to a game object

type CritterPtr = ObjectPtr<'critter'>

Critter object (NPCs, player, creatures)

type ItemPtr = ObjectPtr<'item' | 'container'>

Item object (weapons, armor, ammo, misc items, containers)

type ContainerPtr = ObjectPtr<'container'>

Container object (lockers, chests, bags) - subtype of Item

type SceneryPtr = ObjectPtr<'scenery' | 'door'>

Scenery object (includes doors)

type DoorPtr = ObjectPtr<'door'>

Door object - subtype of Scenery

type ArrayID = number & { __brand: 'ArrayID' }

Array ID - an integer handle to a sfall array

type HookID = | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
| 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19
| 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29
| 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39
| 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48
| 61

Hook ID - valid sfall hook identifiers (0-48, 61)

type IfaceTag = number & { __brand: 'IfaceTag' }

Interface tag ID for show_iface_tag, hide_iface_tag, is_iface_tag_active

type GameMode = number & { __brand: 'GameMode' }

Game mode bitmask returned by get_game_mode()

type ObjType = 0 | 1 | 2 | 3 | 4 | 5 | 6

Object type returned by obj_type()

type WeaponType = 0 | 1 | 2 | 3 | 4

Weapon type classification

type InvenSlot = -2 | 0 | 1 | 2

Inventory slot for critter_inven_obj

type DamageType = 0 | 1 | 2 | 3 | 4 | 5 | 6

Damage type (0-6), can be combined with DMG_BYPASS_ARMOR/DMG_NOANIMATE flags

type FloatMsgColor = -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

Float message color for float_msg

type PerkID = number & { __brand: 'PerkID' }

Perk ID for has_perk, set_perk, etc.

type TraitID = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15

Character trait ID (0-15)

type TraitType = 0 | 1 | 2

Trait type for has_trait function (TRAIT_PERK=0, TRAIT_OBJECT=1, TRAIT_TRAIT=2)

type PcStatID = 0 | 1 | 2 | 3 | 4 | 5

PC-only stat ID for get_pc_stat (0-5)

type RollResult = 0 | 1 | 2 | 3

Roll/skill check result

type AttackType = | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
| 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19

Attack type for combat hooks (0-19)

type AttackMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

Attack mode for weapons (0-8)

type Gender = 0 | 1

Gender (0=male, 1=female)

type Hand = 0 | 1

Active hand (0=left, 1=right)

type Difficulty = 0 | 1 | 2

Difficulty level (0=easy, 1=normal, 2=hard)

type Elevation = 0 | 1 | 2

Elevation level (0-2)

type Direction = 0 | 1 | 2 | 3 | 4 | 5

Direction on hex grid (0-5, clockwise from NE)

type CritterState = number & { __brand: 'CritterState' }

Critter state bitmask from critter_state()

type HitResult = 0 | 1 | 2 | 3

Hit result from HOOK_AFTERHITROLL (0=critical miss, 1=miss, 2=hit, 3=critical hit)

type SfallList<T> = {
[index: number]: T;
readonly __brand: 'SfallList';
} & Iterable<T>

Sfall list array - numeric index, iterable over values

type SfallMap<K, V> = {
[key: string]: V;
[key: number]: V;
readonly __brand: 'SfallMap';
} & Iterable<[K, V]>

Sfall map array - key/value pairs, iterable as [key, value] tuples

function list<T>(items: T[]): SfallList<T>

Create a typed list from items. Transpiles to array literal [a, b, c].

function map<K extends string | number, V>(obj: Record<K, V>): SfallMap<K, V>

Create a typed map from object literal. Transpiles to map literal {a: 1}.