dsekai
World engine for retrocomputers.
Loading...
Searching...
No Matches
Modules | Files | Data Structures | Macros | Typedefs | Functions | Variables
Scripting

Control mobile behavior and interaction. More...

Collaboration diagram for Scripting:

Modules

 Script Instruction Arguments
 Immediate arguments for script instructions.
 
 Scripting Interactions
 Details on scripting interactions with MOBILE actors.
 
 Scripting Instructions
 Overview of the mobile scripting language.
 
 Script Compiler
 

Files

file  script.h
 Functions and macros for executing in-world behavior.
 
file  scstruct.h
 Structs representing behavior scripts.
 

Data Structures

struct  SCRIPT_STEP
 Contains a single instruction in a script, in SCRIPT::steps. More...
 
struct  SCRIPT
 Contains immutable state for scripts attached to a TILEMAP. More...
 
struct  SCRIPT_COMPILE_STATE
 

Macros

#define SCRIPT_GLOBALS_MAX   20
 Maximum number of global script flags available.
 
#define SCRIPT_STACK_MAX   127
 Maximum value an item stored on MOBILE::script_stack.
 
#define SCRIPT_ERROR_OVERFLOW   -1
 
#define script_trace_printf(...)
 Alias for debug_printf() enabled when SCRIPT_TRACE is defined.
 
#define SCRIPT_CB_TABLE_PROTOTYPES(idx, name, c)   uint16_t script_handle_ ## name( uint16_t pc, int16_t arg, struct SCRIPT* script, struct MOBILE* actor, struct MOBILE* actee, struct TILEMAP_COORDS* tile, struct DSEKAI_STATE* state );
 Define prototypes for the script action callbacks.
 
#define SCRIPT_CB_TABLE_CONSTS(idx, name, c)   extern RES_CONST uint16_t SCRIPT_ACTION_ ## name;
 Define extern constants that can be used e.g. in spawners.
 
#define SCRIPT_TOKEN_ITER_SZ_MAX   255
 

Typedefs

typedef uint16_t(* SCRIPT_CB) (uint16_t pc, int16_t arg, struct SCRIPT *script, struct MOBILE *actor, struct MOBILE *actee, struct TILEMAP_COORDS *tile, struct DSEKAI_STATE *state)
 Callback to execute a behavior action. Step in a script.
 

Functions

uint16_t script_parse_str (int8_t script_idx, char *script_txt, int16_t script_txt_sz, struct SCRIPT *script) SECTION_SCRIPT
 Parse the given script string into an in-memory script.
 
uint8_t script_init () SECTION_SCRIPT
 Script subsystem init function that should be called in main().
 
void script_shutdown () SECTION_SCRIPT
 Script subsystem cleanup function that should be called in main().
 
uint16_t script_goto_label (uint16_t pc, struct SCRIPT *script, uint16_t label_type, uint16_t label_id)
 Find a label of the given type and return the program counter (e.g. MOBILE::script_pc) at which it exists.
 

Variables

int8_t g_script_globals [SCRIPT_GLOBALS_MAX]
 Global flag storage for all scripts.
 
RES_CONST SCRIPT_CB gc_script_handlers []
 

Detailed Description

Control mobile behavior and interaction.

Macro Definition Documentation

◆ script_trace_printf

#define script_trace_printf (   ...)

Alias for debug_printf() enabled when SCRIPT_TRACE is defined.

This was made its own alias since scripting can get rather chatty when it's enabled!

Typedef Documentation

◆ SCRIPT_CB

typedef uint16_t(* SCRIPT_CB) (uint16_t pc, int16_t arg, struct SCRIPT *script, struct MOBILE *actor, struct MOBILE *actee, struct TILEMAP_COORDS *tile, struct DSEKAI_STATE *state)

Callback to execute a behavior action. Step in a script.

Parameters
pcCurrent program counter for this mobile.
scriptCurrently executing script.
tMEMORY_PTR to currently loaded TILEMAP.
actorMEMORY_PTR to MOBILE executing the action.
acteeMEMORY_PTR to MOBILE being acted upon.
tileMEMORY_PTR to tilemap tile being acted upon.
argArgument passed from script.
Returns
New value for this script's program counter (e.g. MOBILE::script_pc).

Function Documentation

◆ script_goto_label()

uint16_t script_goto_label ( uint16_t  pc,
struct SCRIPT script,
uint16_t  label_type,
uint16_t  label_id 
)

Find a label of the given type and return the program counter (e.g. MOBILE::script_pc) at which it exists.

Parameters
pcCurrent program counter value.
scriptSCRIPT to search for label.
label_typeSCRIPT_STEP::action to consider as the label type.
label_idSCRIPT_STEP::arg to consider as the label ID.
Returns
Index of the found label, or pc if it was not found.

◆ script_init()

uint8_t script_init ( )

Script subsystem init function that should be called in main().

Returns
1 if successful or 0 otherwise.

◆ script_parse_str()

uint16_t script_parse_str ( int8_t  script_idx,
char *  script_txt,
int16_t  script_txt_sz,
struct SCRIPT script 
)

Parse the given script string into an in-memory script.

Parameters
script_idxIndex of the script, used for debug messages.
script_txtThe script string.
script_txt_szThe length of the script string.
scriptMEMORY_PTR to the SCRIPT struct to populate.