lib_cre function library

Dependencies: alter_effect, ds, lib_2da, lib_2daq, lib_anon, lib_array, lib_class, 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

Functions for editing CRE files. Most but not all are struct functions.

Public functions

cre_add_items(replace:i, struct:s, arguments:s, default:s)=(struct:a) dimorphic

(This is a struct function.)

Add a list of items. Each can have, in parentheses, a list of comma-separated instructions, which can be either:

  • 'unequipped', in which case the item isn't equipped even if it's a weapon. (By default, it is.)
  • 'undroppable',unstealable', 'identified', 'stolen', in which case the appropriate flag is set
  • An integer, interpreted successively as the first, second, third charge number
  • A slot. (If no slots are specified, we choose on the basis of the item type.)
You can set 'default' and it will be added to the instructions for each item.

If 'replace' is set to 1 (default 0) then the item in the slot will be replaced; if not it will be bumped.

cre_add_spells(known:b=1, memorized:b=1, struct:s, arguments:s)=(struct:a) dimorphic

(This is a struct function.)

Add a list of spells, by default to both the 'known' and 'memorized' lists (set 'known' or 'memorized' to 0 to override this). You can use the ids name or the resref, and you can omit 'wizard_' or 'cleric_' where that's unambiguous. Adding (n) after the spell adds it n times (to the memorized list only).

cre_copy(tv:i, allow_missing:i, debug:i=1, cre:s, source_path:s, source_location:s, source_locbase:s, path:s, location:s, locbase:s, edits:s)=() action

General copier for cre files. No special features.

cre_delete_original_class()=() patch

NOT a struct function. Remove the 'original class' flag from the currently-edited creature.

cre_delete_spells_of_type(core_namespace_only:i, known:i=1, memorized:i=1, arguments:s)=() patch

NOT a struct function. Deletes all spells of given type(s) in the CRE file. 'arguments' should be a space-separated (case-insensitive) list containing one or more of 'wizard', 'priest', or 'innate'

If core_namespace_only=1, require spells to be in the SPPR/SPWI/SPIN/SPCL namespace.

By default we delete both known and memorized spells. Set known=0 or memorized=0 to override.

cre_edit(tv:i, allow_missing:i, debug:i=1, edit_strrefs_in_place:i, cre:s, path:s, location:s, locbase:s, edits:s)=() action

General editer for cre files. No special features.

cre_enforce_saves(struct:s, arguments:[at_worst|at_best|within_tolerance])=(struct:a) dimorphic

(This is a struct function.)

Set the creature's saving throws to their legal values. 'arguments' can be blank (the default), 'at_worst', 'at_best', and 'within_tolerance', where tolerance is set by the ini value 'save_tolerance' and saves are modified if the old and new versions are close enough.

Requires data_saving_throws macro to have been run

cre_enforce_saves_notstruct(arguments:s)=() patch

NOT a struct function.

Enforce a correct set of saving throws.

Arguments can be: - "" (default) - just sets it - at worst - at_best - only_if_new - a little delicate, responds only to zero - within_tolerance - adjust if within the 'save_tolerance' value of the correct #

cre_enforce_thac0(struct:s, arguments:[at_worst|at_best|within_tolerance])=(struct:a) dimorphic

(This is a struct function.)

Set the creature's thac0 to its legal value. 'arguments' can be blank (the default), 'at_worst', 'at_best', and 'within_tolerance', where tolerance is set by the ini value 'save_tolerance' and thac0 is modified if the old and new versions are close enough.

Requires data_thac0 macro to have been run

cre_enforce_thac0_notstruct(arguments:s="exact")=() patch

cre_insert_script(struct:s, arguments:s, script:s, loc:s)=(struct:a) dimorphic

(This is a struct function.)

Given the usual array of combat scripts (override/class/race/general/default), and a script 'script' (synonym: 'arguments'), insert a new one in position 'loc'. Insert position can be 'high', 'low', 'after x' (defaults to 'high' if x isn't present), or 'before x' (defaults to 'low' if x isn't present). If there isn't space, merge the two lowest scripts to make space.

cre_make(debug:i=1, cre:s, version:s, path:s, location:s, locbase:s, edits:s)=() action

General maker for cre files. No special features.

cre_min_stats(struct:s, arguments:s)=(struct:a) dimorphic

(This is a struct function.)

Supply a space-separated list of 6 integers (the first can be a strength score like 18/76). Set the creatures STR/DEX/CON/INT/WIS/CHA to those integers, if lower.

cre_quickset_known_spells(max_level:i=9, arguments:s, type:[wizard|priest|innate])=() patch

Given an array 'arguments' in the form resref=>level, and 'type' either 'wizard', 'priest', or 'innate', add the spells to the creature's known spells (removing any previous version if appropriate). The spells are added in place using WEIDU's built-in ADD_KNOWN_SPELL function (i.e. this is not a struct function). Use this for bulk spell adding when speed matters: it's much faster than the struct system.

If max_level is set, add spells only up to this level.

cre_quickset_memorized_spells(arguments:s, type:[wizard|priest|innate])=() patch

Given a 2d array 'arguments' in the form (level,resref)=>number_memorized, and 'type' either 'wizard', 'priest', or 'innate', add the spells to the creature's memorized spells. The spells are added in place using WEIDU's built-in ADD_MEMORIZED_SPELL function (i.e. this is not a struct function). Use this for bulk spell adding when speed matters: it's much faster than the struct system.

cre_read_kit()=(value:s) patch

NOT a struct function. Find the kit ID of the current kit. We don't look it up directly because that means parsing kitlist and it might be more efficient (depending on context) to do it directly.

cre_read_original_class()=(value:s) patch

NOT a struct function. Returns (as lower-case ascii) a creature's original class, or 'none' if they don't have one.

cre_remove_items(struct:s, arguments:s)=(struct:a) dimorphic

(This is a struct function.)

Input a list of resrefs. Remove any items matching the list from item slots. (The items are then deleted when the struct is written back into the cre file.) If the argument is 'all', everything is deleted.

cre_remove_spells(known:b=1, memorized:b=1, struct:s, arguments:s)=(struct:a) dimorphic

(This is a struct function.)

Delete a list of spells, by default from both the known and memorized lists (you can override this by setting 'known' or 'memorized' to 0). You can use the ids name or the resref, and you can omit 'wizard_' or 'cleric_' where that's unambiguous. Using 'all' removes all spells.

cre_set_joinable_priest_spells()=() action

Assign the correct known spells to all party-joinable characters who can cast (non-spontaneous) priest spells. Requires data_joinable_dvs to have been run

cre_set_kit(kitnum:i="-1", kit:s)=() patch

NOT a struct function. Given a kit (a kitids entry 'kit' or an integer 'kitnum'), sets the current creature's kit to that

cre_set_known_priest_spells()=() patch

On the current creature, set the appropriate priest spells as known, based on class, level and alignment. (This is fairly hardcoded as it'll tend to be applied in bulk.)

Requires the data_priest_spells and data_spells_by_level functions/macros to have been run

cre_set_proficiencies(struct:s, arguments:s, default:s)=(struct:a) dimorphic

(This is a struct function.)

Input a k=>v list. Each k is a proficiency; each v is its value. Set each of them.

cre_strip_scripts(struct:s, arguments:s)=(struct:a) dimorphic

(This is a struct function.)

Input a list of scripts. Remove any script on the list from the creature. If 'all' is inputted, remove all scripts.

cre_swap_items(struct:s, arguments:s)=(struct:a) dimorphic

(This is a struct function.)

Input a list of resref1=>resref2 pairs. Swap each resref1 for resref2 in the creature item list.

cre_swap_scripts(struct:s, arguments:s)=(struct:a) dimorphic

(This is a struct function.)

Input a k=>v list of pairs of scripts. Swap any k script for a v script.

Internal functions

These should not be called from outside the library itself.

cre_add_known_spells_helper()=() patch

cre_add_spells_helper_match()=(value:s) patch

cre_add_spells_helper_patch()=() patch

cre_remove_spells_helper()=(value:s) patch

cre_set_proficiencies_helper()=() patch