ui_spell_system function library

Dependencies: alter_effect, lib_fn, lib_ui, ui_detect_class_kit.tpa

Description

Set up and add to SFO's externalized spell system. You can define any number of spell lists, labelled by a string (the 'key'). Each class and kit then has four lists of spell-list keys: allow_learn, block_learn, allow_priest and block_priest. A combination of UI editing and item alterations then enforces those lists on all classes and kits.

Functions

define_spell_list(determine_empty_levels:b, empty_level_max:i=9, silent:b, spells:s, key:s, spell_array:s)=() action

Given a space-separated list of spells 'spells', and/or an array spell=>_ or spell=>spell_level of spells, and a string 'key', construct a spell list 'key' comprising those spells. If you use the spell=>spell_level format, it saves looking up the levels of the spells).

Spells can be given either as resrefs or as IDS entries (if the latter, they need to have been loaded into memory using data_spell_resrefs). If a spell is missing, whine unless silent=1.

If determine_empty_levels=1, also record which levels are empty in the lua output. (empty_level_max is the highest level at which this is done.)

Spell system is automatically set up if it isn't already.

get_spell_array(list:s, root:s)=(this_array:a) action

Given 'root' either SPPR or SPWI, and 'list' a list of spell-list keys, return an array of all spells in that list, in the format resref=>1

parse_spell_lists(allow_learn:s, block_learn:s, allow_priest:s, block_priest:s, type:s="priest")=(spell_array:a) action

Given the 'allow_learn', 'block_learn', 'allow_priest', 'block_priest' values for some (actual or fictional) kit, and its type (either 'priest' or 'mage') return an array of all usable spells, in the format resref=>1

scroll_usability(class_id:i, kit_ids_entry:i, block_learn:s, allow_learn:s="every_spell", block_priest:s, allow_priest:s="every_spell", type:s=priest)=() action

Given the block_learn, allow_learn, block_priest, allow_priest entries for a kit, the (unused) class_id and kit_id for the kit, and the type (mage or priest), go through every scroll in the game and issue 319s to any unusable scrolls.

set_specialist_spells(chargen_choose_spells:b, number_required:i=1, list_spells:b, strref_school:i, strref_school2:i, old_line:i=100010, old_line:s, string_school:s, string_school2:s, kit:s, spell_list:s, tra:s, tra_path:s="weidu_external/lang/MOD_FOLDER")=() action

Given a kit (a rowname entry in kitlist.2da), an integer (number_required, default=1) and a space-separated list of spell-list keys, require that kit to learn at least number_required spells from that list.

The various other variables control how this is documented in the kit description:

  • list_spells, if set, includes a list of all spells from the preferred list in the kit description
  • [to do & NB the lines here are not fully externalized, some are hard-coded]
  • tra and tra_path specify where the strings used are drawn from

set_spell_list(chargen_choose_spells:b, update_scroll_usability:b=1, class:s, kit:s, kit_clastext:s, block_learn:s="no_change", allow_learn:s="no_change", block_priest:s="no_change", allow_priest:s="no_change")=() action

Set the spell lists available to, or blocked for, a given class or kit (either set class to a class.ids entry, or kit to a kitlist.2da rowname). Each of block_learn, allow_learn, block_priest, or allow_priest can be a space-separated or comma-separated list of spell-list keys, or 'no_change' (the default) in which case whatever it's currently set to will be unchanged.

If chargen_choose_spells=1, the lua also sets dwChargenChooseSpells to 1 for that class or kit. (DW: I can't remember what that does. :))

If update_scroll_usability=1, we also go through all scrolls and mark them up as usable/unusable for that class/kit.

If the spell system is not already set up, we set it up.

ui_spell_system_setup()=() action

Set up the externalized spell system. (Idempotent.)

Internal functions

These should not be called from outside the library itself.

chargen_memorize_mage_spells()=() patch

choose_spells_edit()=() patch

choose_spells_function_edit()=() patch

edit_rightbuttonenabled()=() patch

get_no_spell_level_string(list:s)=(no_spell_level_string:s) action

get_strrefs_for_lua()=(cleric_strref:s, druid_strref:s, shaman_strref:s) action

learn_spell_bonus_patch()=() patch

list_spec_spells(list:s)=(spell_list_string:s) action

memorize_priest_spells_edit()=() patch

memorize_priest_spells_function_edit()=() patch

patch_spec_bg()=() patch

patch_spec_iwd()=() patch

priest_spell_book_edit_bg()=() patch

priest_spell_book_edit_iwd()=() patch

scroll_data()=() action

specialist_spell_edit()=() patch

spell_data_baseline()=() action