G3

Identifying subraces

This is a quick note for modders who want to detect or use subraces in their own mods.

Subraces are identified by a combination of two variables: (i) their race; (ii) the value of stat 134(=EXTRAPROFICIENCY20). (For instance, in a clean install of ToF, gold dwarves are race=4 (DWARF), stat=1; aasimar are race=185 (AASIMAR), stat=1). Detecting them is then just a matter of checking both variables; for instance,

Race(Player1,4)CheckStat(Player1,1,EXTRAPROFICIENCY20)
returns true iff Player1 is a gold dwarf.

The race and stat values for a given subrace are stored in the table 'weidu_external/data/dw_shared/dw_subrace_ids.2da'. It is not a good idea to assume their values are fixed; your mod should collect them at install time. The simplest way is to use a function generated by ToF's subrace component. In the ALWAYS block of your mod, put this include instruction:

INCLUDE "weidu_external/data/dw_shared/subrace_ids.tpa"
This defines an action/patch function 'subrace_ids', which you use like this:
LAF subrace_ids
STR_VAR subrace=dwarf_gold 
RET 
	race_id 
	subrace_id 
END
Assuming the subrace 'dwarf_gold' is defined in dw_subrace_ids.2da, this will spit out its race ('race_id') and stat value ('subrace_id'). If it doesn't exist, both values will be -1. (You can also return 'success', which is 1 if the subrace is defined and 0 otherwise.)

If you want to give a subrace to a joinable NPC, it's as simple as setting the race and stat correctly. Note that the subrace component in ToF only does anything to joinable NPCs (and only when they join the party) - there is no point assigning subraces to non-joinables.

It is admittedly a bit problematic that ToF is pretty late in the install order, later than most NPC mods for instance. If you want your mod to apply a subrace to an NPC, a simple way is to ask me - all I need is the subrace and the NPC's dv. If you want to do something more complicated, maybe talk to me.