dsekai
World engine for retrocomputers.
All Data Structures Files Functions Variables Typedefs Friends Macros Modules Pages
Modules | Files | Data Structures | Macros | Functions | Variables
Mobile Objects

Player- or script-controlled world objects or "mobiles". More...

Collaboration diagram for Mobile Objects:

Modules

 Mobile Spritesheets
 
 Mobile MP/HP
 Details of how the MOBILE::mp_hp field works.
 
 Mobile Object Flags
 Flags controlling MOBILE object behavior.
 
 Mobile-Related Errors
 Error codes for MOBILE-related functions.
 
 Cardinal Directions
 Directions in which MOBILE objects may face.
 

Files

file  mobile.h
 Structs, functions and macros pertaining to interactive objects.
 

Data Structures

struct  MOBILE
 A moving/interactive object in the world. More...
 

Macros

#define DSEKAI_MOBILES_MAX   200
 Maximum count of DSEKAI_STATE::mobile.
 
#define DSEKAI_MOBILES_ONSCREEN   (GRAPHICS_SPRITES_ONSCREEN / 3)
 
#define SCRIPT_STACK_DEPTH   10
 Maximum depth of available local stack for each MOBILE executing a script. Each stack is individual to that particular mobile. When this depth is exceeded, old excess items will be discarded off the bottom.
 
#define mobile_get_tx(m)   ((m)->coords[1].x)
 
#define mobile_get_ty(m)   ((m)->coords[1].y)
 
#define mobile_break_if_last(m)   if( MOBILE_FLAG_NOT_LAST != (MOBILE_FLAG_NOT_LAST & (m)->flags) ) { debug_printf( 0, "breaking early on mobile" ); break; }
 
#define mobile_is_active(m)   (MOBILE_FLAG_ACTIVE == (MOBILE_FLAG_ACTIVE & (m)->flags))
 
#define mobile_is_walking(m)   ((m)->coords[1].y != (m)->coords[0].y || (m)->coords[1].x != (m)->coords[0].x)
 

Functions

uint8_t mobile_walk_start (struct MOBILE *m, uint8_t dir) SECTION_MOBILE
 Have the given MOBILE attempt to begin walking movement/animation.
 
struct MOBILEmobile_get_facing (uint8_t x, uint8_t y, uint8_t dir, struct DSEKAI_STATE *state)
 Get a MEMORY_PTR to the mobile m is currently facing.
 
struct MOBILEmobile_from_gid (MOBILE_GID m_gid, struct DSEKAI_STATE *state)
 
struct MOBILEmobile_interact (struct MOBILE *actor, struct MOBILE *actee, struct DSEKAI_STATE *state) SECTION_MOBILE
 Force a MOBILE to jump to the SCRIPT_ACTION_INTERACT in its SCRIPT.
 
void mobile_state_animate (struct DSEKAI_STATE *state)
 Map MOBILE animation frames to a number of real frames elapsed.
 
void mobile_animate (struct MOBILE *m, struct DSEKAI_STATE *state)
 Perform animation frame for the given MOBILE.
 
void mobile_deactivate (struct MOBILE *m, struct DSEKAI_STATE *state) SECTION_MOBILE
 Prepare a MOBILE for deallocation.
 
void mobile_stack_push (struct MOBILE *m, int8_t v) SECTION_MOBILE
 Push a value onto MOBILE::script_stack.
 
int8_t mobile_stack_pop (struct MOBILE *m) SECTION_MOBILE
 Pop a value from a MOBILE::script_stack.
 
void mobile_execute (struct MOBILE *m, struct DSEKAI_STATE *state)
 Execute the next available SCRIPT_STEP in the currently running SCRIPT on a MOBILE.
 
struct MOBILEmobile_spawn_single (uint16_t flags, struct DSEKAI_STATE *state) SECTION_MOBILE
 Allocate a mobile or select player mobile slot and initialize it with configuration generic to ALL mobiles.
 
int16_t mobile_spawner_match (struct TILEMAP_SPAWN *spawner, struct DSEKAI_STATE *state) SECTION_MOBILE
 
void mobile_spawns (struct DSEKAI_STATE *state) SECTION_MOBILE
 Spawn from ::TILEMAP::spawners according to spawner rules.
 

Variables

const int8_t gc_mobile_step_table_normal_pos [16]
 Lookup table for next walking offset to assign to MOBILE::steps_remaining based on current offset.
 
const int8_t gc_mobile_y_offsets [4]
 Lookup table for vertical offset based on mobile_get_dir().
 
const int8_t gc_mobile_x_offsets [4]
 Lookup table for horizontal offset based on mobile_get_dir().
 

Detailed Description

Player- or script-controlled world objects or "mobiles".

Macro Definition Documentation

◆ DSEKAI_MOBILES_MAX

#define DSEKAI_MOBILES_MAX   200

Maximum count of DSEKAI_STATE::mobile.

Note
This may be overridden by passing a -D argument to the compiler.
Attention
Changing this value may break compatibility with tilemaps or saves! Please use caution.

◆ SCRIPT_STACK_DEPTH

#define SCRIPT_STACK_DEPTH   10

Maximum depth of available local stack for each MOBILE executing a script. Each stack is individual to that particular mobile. When this depth is exceeded, old excess items will be discarded off the bottom.

Note
This may be overridden by passing a -D argument to the compiler.
Attention
Changing this value may break compatibility with tilemaps or saves! Please use caution.

Function Documentation

◆ mobile_animate()

void mobile_animate ( struct MOBILE m,
struct DSEKAI_STATE state 
)

Perform animation frame for the given MOBILE.

Parameters
mMEMORY_PTR to MOBILE to animate.
stateLocked MEMORY_PTR to current engine DSEKAI_STATE.

◆ mobile_deactivate()

void mobile_deactivate ( struct MOBILE m,
struct DSEKAI_STATE state 
)

Prepare a MOBILE for deallocation.

Parameters
tMEMORY_PTR to a MOBILE to deinitialize.
stateLocked MEMORY_PTR to current engine DSEKAI_STATE.

◆ mobile_execute()

void mobile_execute ( struct MOBILE m,
struct DSEKAI_STATE state 
)

Execute the next available SCRIPT_STEP in the currently running SCRIPT on a MOBILE.

Parameters
mMEMORY_PTR to the MOBILE running the desired SCRIPT.
stateLocked MEMORY_PTR to current engine DSEKAI_STATE.

◆ mobile_get_facing()

struct MOBILE * mobile_get_facing ( uint8_t  x,
uint8_t  y,
uint8_t  dir,
struct DSEKAI_STATE state 
)

Get a MEMORY_PTR to the mobile m is currently facing.

Parameters
stateMEMORY_PTR to current engine DSEKAI_STATE.
Returns
MEMORY_PTR to the colliding mobile in ms.

◆ mobile_interact()

struct MOBILE * mobile_interact ( struct MOBILE actor,
struct MOBILE actee,
struct DSEKAI_STATE state 
)

Force a MOBILE to jump to the SCRIPT_ACTION_INTERACT in its SCRIPT.

Parameters
actorMEMORY_PTR to the MOBILE sending the interact call.
acteeMEMORY_PTR to the MOBILE which should jump the interaction.
tMEMORY_PTR to the currently loaded TILEMAP.

◆ mobile_spawn_single()

struct MOBILE * mobile_spawn_single ( uint16_t  flags,
struct DSEKAI_STATE state 
)

Allocate a mobile or select player mobile slot and initialize it with configuration generic to ALL mobiles.

Parameters
stateLocked MEMORY_PTR to current engine DSEKAI_STATE.
flagsMobile Object Flags applying to the spawned MOBILE.

◆ mobile_spawns()

void mobile_spawns ( struct DSEKAI_STATE state)

Spawn from ::TILEMAP::spawners according to spawner rules.

Parameters
stateLocked MEMORY_PTR to the current engine DSEKAI_STATE.
tLocked MEMORY_PTR to TILEMAP on which to execute spawners.

◆ mobile_stack_pop()

int8_t mobile_stack_pop ( struct MOBILE m)

Pop a value from a MOBILE::script_stack.

Parameters
mMEMORY_PTR to MOBILE from which to pop MOBILE::script_stack.
Returns
The value popped.

◆ mobile_stack_push()

void mobile_stack_push ( struct MOBILE m,
int8_t  v 
)

Push a value onto MOBILE::script_stack.

Parameters
mMEMORY_PTR to MOBILE on which to push to MOBILE::script_stack.
vValue to push onto the stack.

◆ mobile_state_animate()

void mobile_state_animate ( struct DSEKAI_STATE state)

Map MOBILE animation frames to a number of real frames elapsed.

Parameters
stateLocked MEMORY_PTR to current engine DSEKAI_STATE.

◆ mobile_walk_start()

uint8_t mobile_walk_start ( struct MOBILE m,
uint8_t  dir 
)

Have the given MOBILE attempt to begin walking movement/animation.

Parameters
mMEMORY_PTR to MOBILE that should attempt moving.
dirIndex of direction offsets in gc_mobile_x_offsets.

This may fail if the mobile is already walking, or is blocked from moving in that direction by a map obstacle or other mobile.

This uses MOBILE::steps_remaining and gc_mobile_step_table_normal_pos to track walking accross ticks.