# lib_opcode function library

Dependencies: alter_effect, lib_anon, lib_fn, lib_sugar, lib_tools

## Description

Functions here are associated with the association of opcodes to various secondary effects, and the extraction of those opcodes and secondary effects into subspells. At the moment we are trying to avoid dependencies here so the library can be self-contained.

This came out of a project linked to the EE fixpack, but ended up not being used. No promise that it's still useful.

## Public functions

opcode_extract(opcode:i="-1", header:i="-1", saves:b, probs:b, include_primary:b, sectype:i, file:s, eff:s)=(subspell:s) action

Given 'file', which should be an item or spell, and 'opcode', we extract the any associated effects from file and cast them as a subspell. If header is set to a nonnegative number, we do this only for that header (header is required for item files). Returns the resref of the subspell.

By default, the saving throws/MR checks and probabilities are checked when the subspell is called. Set saves=1 and probs=1 to keep those checks with the individual effects in the subspell.

Also by default, the opcode itself is not extracted. Set include_primary=1 to extract it.

If you set sectype to a positive number, the subspell receives that sectype. (Otherwise it has sectype 0).

opcode_load_data action_macro

Load the library data used by lib_opcode functions. The default assumption is that the data is in MOD_FOLDER/sfo/data, but you can override by setting sfo_opcode_data_path to the (full) path to the data. Returns sfo_opcode_data_loaded=1.

opcode_secondary_effects(primary_opcode:i="-1", fx_off:i, include_all_cosmetics:b, include_primary:b, parent_resource:s="lib_opcode")=(value:s, opcode:s) patch

Given the offset of an fx block, and a primary opcode, returns 1 if the opcode of the block is associated with the primary opcode (that is: it is an appropriate icon or other cosmetic effect, or else is a reliably-associated secondary effect). If include_primary is set to 1 (default=0) return the primary opcode itself here. If include_all_cosmetics is set to 1 (default=0), returns true for any cosmetic effect (except icons and strrefs, which always get checked).

For convenience, we also return the opcode itself (as 'opcode').

parent_resource should be set to the file in which the block is assumed to be (defaults to SOURCE_RES)

## Internal functions

These should not be called from outside the library itself.

opcode_load_data(data_path:s="MOD_FOLDER/sfo/data")=(opcode_strrefs:a, opcode_glows:a, opcode_icons:a, opcode_animations:a, opcode_sparkles:a, opcode_eff_arr:a) action

Load the library data used by lib_opcode functions. The default assumption is that the data is in MOD_FOLDER/sfo/data, but you can override by setting sfo_opcode_data_path to the (full) path to the data. Returns sfo_opcode_data_loaded=1.