# lib_prof 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_bonus_spells, 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

This library manipulates (largely kit) proficiencies, outside the struct format. One of its purposes is to permit compatibility with mods (like Tweaks Anthology) that adjust the proficiency system.

## Public functions

prof_adjust(reexternalize:b=1, kit:s, patch:s, arguments:s)=() action

Apply the SFO standard function 'patch' to all proficiencies of a certain type belonging to the kit 'kit' (can be a space-separated list). Possible arguments are (i) a space-separated list of standard prof names; (ii), 'melee', 'ranged', or 'all'. In each case prof_lookup is used to try to preserve compatibility, and each proficiency will be patched only once even if multiple BG2-style proficiencies point at the same proficiency. You can use the anonymous function construct.

prof_build_lookup(overwrite:b)=(prof_lookup_array:a, prof_lookup_rows:a, profs_used_array:a, profs_used_rows:a, unused_profs:a) action

Construct

1. a 2da lookup table (prof_lookup.2da) mapping vanilla BG2 proficiencies to actual proficiencies, using prototype weapons as a source. (e.g. we check BOW03, and map 'LONGBOW' to whatever proficiency is assigned to it). The table rows are indexed by old proficiency names, and has these columns: 'ID', 'NAME' (the weapprof row name for the new proficiency added), 'STRREF' (the name of the proficiency, taken from weapprof) 'WEAPON_STRREF' (the name of the actual prototype weapon in the BG2 proficiency - this is 'scimitar' for SCIMITARWAKISASHININJATO), 'TYPE' (either MELEE, MISSILE, or STYLE). Styles are automatically included.
2. a 2da lookup table (profs_used.2da) listing the actual proficiencies in use. (A proficiency is in use if either (i) it is the proficiency of any of the prototype weapons, or (ii) in the case of styles, unkitted fighters have at least one pip in it.) The table rows are indexed by weapprof row names and have these columns: 'ID', 'STRREF' (the name of the proficiency, taken from weapprof) and 'TYPE' (either MELEE, MISSILE, or STYLE).
3. a text table (profs_unused.txt) listing the unused profs in the format 'NAME ID'.

All these are stored in data_loc and are generated if present already only if the INT_VAR overwrite is set to 1. In any case, each is then read into memory, into the 2D arrays 'prof_lookup_array' and 'profs_used_array' and the k=>v array 'unused_profs', respectively. The rows of the two 2das are also returned as the arrays 'prof_lookup_rows' and 'profs_used_rows'.

prof_copy(only_if_nonzero:b, reexternalize:b=1, copy_to:s, copy_from:s)=() action

Copy the proficiencies from kit 'copy_from' to kit 'copy_to'. If 'only_if_nonzero' is set to 1, proficiencies set to 0 in kit copy_to remain at zero. Only weapon proficiencies, not weapon styles, are done.

If the proficiencies have been externalized (i.e. if weapprof.2da is present in data_loc_shared) then copy it over to override first. If reexternalize=1, reexternalize afterwards.