# ui_bonus_spells function library

Dependencies: alter_effect, ds, lib_2da, lib_2daq, lib_anon, lib_array, lib_class, lib_cre, lib_data, lib_eff, lib_fn, lib_ids, lib_ietool, lib_ini, lib_kit, lib_script, lib_sfo, lib_spl, lib_splconv, lib_ssl, lib_struct, lib_sugar, lib_tools, lib_ui, lib_vtable, resolve_spell, ui_add_subraces, ui_deolvynize, ui_detect_class_kit, ui_dual_class_kits, ui_externalize_hlas, ui_externalize_proficiencies, ui_extra_spells, ui_on_open, ui_shared_code, ui_spell_system, ui_system_call, ui_virtual_class

## Description

Resources to add 'bonus spells', i.e. additional spells known at each level by a given class or kit. EE-only (edits the UI).

## Public functions

assign_bonus_spells(update_description:b=1, skip_clab:b, class:s, kit:s, spells:s, spell_array:s, tra:s="sfo_lua", tra_path:s="DEFAULT")=() action

Given kit 'kit, and a space-separated list of spells 'spells' and/or a k=>_ array of spells 'spell_array', grant those spells as bonus learned spells at the appropriate level, making appropriate LUA and CLAB changes to do so.

Spells can be given as bare resrefs, or as spell.ids entries, or as dw_ext_spell.ids entries, or as abbreviated entries (i.e., with the 'WIZARD_' or 'CLERIC_' preamble stripped (if ambiguous, we assume WIZARD). Spells of the wrong type (i.e. cleric spells for wizards, or vice versa) are autoconverted to the appropriate type using the lib_splconv library.

Multiclass kits can be handled, but only if they're in SFO format and only on a full sfo install (we use lib_kit functionality). The parent class can normally be inferred; if you are adding bonus spells to a cleric/mage, you need to specify 'class' explicitly as cleric or mage.

The function will attempt to update the kit description (you can tell it not to by setting update_description=0). It needs to be given a tra file and a tra path; the defaults point to lua/lang and to sfo-lua's default tra file. (Look at that file for format if you want to do your own.) The same tra file is also passed to the splconv function to make any cleric->wizard and wizard->cleric conversion descriptions.

If you set skip_clab to 1, the new spells are added to the LUA and the kit description, but not to the CLAB. (This is useful if you're cloning an existing kit.)

bonus_spells_from_list(skip_clab:b, update_description:i=1, kit:s, path:s, class:s)=() action

Loads the file in 'path' (which should be a 2-column table - the first column is conventionally a level, but need not be). Go through the entries in the second column. Each is a |-separated list of spell ids entries (possibly including extended-namespace ids). Assign the first entry in each column that actually exists as an installed spell as a bonus spell to the kit 'kit'.

## Internal functions

These should not be called from outside the library itself.

bonus_spell_data_helper(spell:s)=(resref:s, level:s, splconv_array:a) dimorphic

resolve_bonus_granting_spell(level:i, resref:s)=(grant_resref:s) dimorphic

ui_bonus_spells_setup()=() action

Set up initially-required resources to add bonus spells. Called automatically by assign_bonus_spells, shouldn't need to be called externally.