# lib_data function library

Dependencies: lib_2da, lib_anon, lib_array, lib_fn, lib_ini, lib_sfo, lib_sugar, lib_tools, lib_ui

## Description

Contains macros and functions that load various bits of game data (saves, dvs, spell resrefs, etc etc) into WEIDU data structures.

## Public functions

data_hp_range action_macro

Works out the minimum and maximum hit points for all classes for levels 1-40 and stores them in the arrays $class_hp_minimum(class level), $class_hp_maximum(class level), with class in uppercase. Barbarians are also included.

At present this is *hard-coded*, on speed grounds: it will not allow for changes made to the HP tables.

data_joinable_dvs action_macro

Returns the array 'sfo_joinable_dvs', in k=>_ form, containing the lowercased dvs of all joinable creatures

data_levels_by_max_level()=(array:a) action

Returns an array that identifies, for each multiclass and each level N, what level the individual classes are when the highest-level class is level N. For instance, $array(CLERIC_THIEF 10 CLERIC)=8, because thieves reach level 10 before clerics and when a thief has enough XP for level 10, a cleric would be level 8.

data_priest_spells action_macro

Return arrays "sfo_druid_spells" and "sfo_cleric_[alignment]_spells_n", containing the learnable cleric and druid spells of in resref=>level form. [alignment] is each of the nine alignments as presented in align.ids, lowercased. Arrays are ordered from highest to lowest level and from highest-numbered to lowest-numbered spell (this facilitates correctly (or at least intuitively) ordering the learned-spell lists if we use cre_quickset_known_spells).

data_priest_spells_by_type()=(druid_spells:a, cleric_spells:a) dimorphic

Goes through all spells in the SPPR namespace and returns a resref=>discard array of druid and cleric spells. We don't return spells in HIDESPL or in the hardcoded list of spells in the 50-99 namespace that aren't in use

data_proficiencies()=(weapprof:a, profs:a, profsmax:a) dimorphic

Returns the (uppercase-rows/cols) arrays 'weapprof','profs', and 'profsmax', containing the contents of weapprof.2da and prof.2da respectively. For weapprof, columns are indexed by the proficiency ID. Adds SORCERER entries automatically to weapprof, cloning MAGE.

If copies of these files exist in weidu_external/data/dw_shared, use those instead (these are generated by ToF's externalized proficiency system.)

data_saving_throws action_macro

Read in saving throws for all classes and store in a 3da struct, in the form sfo_saves_%class%_%level%_=n, up to level 50 (padding out if necessary)

Here type is 'death','wands','polymorph','breath', or 'spells', and class is lowercased.

data_scroll_resrefs action_macro

Reads in every divine and arcane spell, and stores them like this:

WIZARD_FIREBALL_SCROLL=scrl1g $sfo_arcane_scrolls("WIZARD_FIREBALL")=scrl1g CLERIC_FREE_ACTION_SCROLL=scrl58 $sfo_divine_scrolls("CLERIC_FREE_ACTION")=scrl58

data_spell_resrefs action_macro

Read in every entry in spell.ids and set a variable with that name whose value is the spell resref, and store the data in the sfo_spell_resrefs array. Also store the spell type

e.g. WIZARD_FIREBALL = SPWI304 $sfo_spell_resrefs("WIZARD_FIREBALL") = SPWI304 WIZARD_FIREBALL_LEVEL = wizard $sfo_spell_types("WIZARD_FIREBALL") = wizard

Also, for wizard/priest spells, store the spell level in the format

WIZARD_FIREBALL_LEVEL=3

If extended spell namespace is in use, add the spells from dw_ext_spell.ids too.

Also check for spells in the DWWP, DWPW, DWPI, DWWI namespace (as per ToF naming conventions) , e.g.

CLERIC_FIREBALL=DWWP304 CLERIC_FIREBALL_LEVEL=3 INNATE_WIZARD_FIREBALL=DWWI304

data_spells_by_level action_macro

Read in spell slots for all classes and store in a struct 'sfo_spell_level', in the form

sfo_spell_level_%class%_%level%_%spell_level%"=n (# spells known at level) sfo_spell_level_sl_to_cl_%class%_%level%=n (minimum level at which caster gets spells of this level) sfo_spell_level_cl_to_sl_%class%_%level%=n (maximum level of spells known at caster level) sfo_spell_level_max_%class%=n (max level of spells known)

data_thac0 action_macro

Read in thac0 for all classes and store in a 2da, in the form $sfo_thac0("class" "level")=n up to level 50, padding out if necessary. 'class' is lowercased.

data_vanilla_high_spells()=(vanilla_high_spells:a) dimorphic

This just loads a hardcoded (uppercased, resref=>discard) list of hidden spells in the 50-99 namespace. It allows for the Spell Revisions mod.

## Internal functions

These should not be called from outside the library itself.

data_hp_range()=(class_hp_minimum:a, class_hp_maximum:a) action

Works out the minimum and maximum hit points for all classes for levels 1-40 and stores them in the arrays $class_hp_minimum(class level), $class_hp_maximum(class level), with class in uppercase. Barbarians are also included.

At present this is *hard-coded*, on speed grounds: it will not allow for changes made to the HP tables.

data_internal_scroll_resrefs()=(sfo_arcane_scrolls:a, sfo_divine_scrolls:a) action

data_internal_spell_resrefs()=(sfo_spell_resrefs:a, sfo_spell_levels:a, sfo_spell_types:a) action

data_joinable_dvs_core()=(sfo_joinable_dvs:a) action

data_priest_spells_core()=(sfo_cleric_lawful_good_spells:a, sfo_cleric_neutral_good_spells:a, sfo_cleric_chaotic_good_spells:a, sfo_cleric_lawful_neutral_spells:a, sfo_cleric_neutral_spells:a, sfo_cleric_chaotic_neutral_spells:a, sfo_cleric_lawful_evil_spells:a, sfo_cleric_neutral_evil_spells:a, sfo_cleric_chaotic_evil_spells:a, sfo_druid_spells:a) action

data_thac0_helper()=(sfo_thac0:a) action

Encapsulated innards of the data_thac0 macro.