lib_cre function library

Dependencies: lib_2da, lib_anon, lib_array, lib_fn, lib_ids, lib_ietool, lib_ini, lib_sfo, lib_spl, lib_struct, lib_sugar, lib_tools

Description

Functions

cre_add_items(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

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

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

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_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

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_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.)

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_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