dsekai
World engine for retrocomputers.
Loading...
Searching...
No Matches
Mobile Objects

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

Collaboration diagram for Mobile Objects:

Topics

 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_COORDS_QUEUE_SZ   5
 Number of positions available in the MOBILE::coords queue.
 
#define mobile_get_dir(m)
 Get the Cardinal Directions the mobile is facing.
 
#define mobile_set_dir(m, v)
 Set MOBILE_DIR_MASK in MOBILE::flags to the specified Cardinal Directions.
 
#define mobile_get_icount(m)
 Get the current interaction count of the specified MOBILE.
 
#define mobile_incr_icount(m, v)
 Increment MOBILE_ICOUNT_MASK by a given value.
 
#define mobile_get_gid(m)
 Get the globally unique identifier of the given MOBILE.
 
#define mobile_get_map_gid(m, state)
 Get the GID of the TILEMAP the given MOBILE is currently on.
 
#define mobile_get_sprite(m)
 Get the pointer to the sprite graphic to use for a MOBILE.
 
#define mobile_get_tx(m)
 
#define mobile_get_ty(m)
 
#define mobile_break_if_last(m)
 
#define mobile_is_active(m)
 
#define mobile_is_walking(m)
 

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.

◆ mobile_break_if_last

#define mobile_break_if_last ( m)
Value:
if( MOBILE_FLAG_NOT_LAST != (MOBILE_FLAG_NOT_LAST & (m)->flags) ) { debug_printf( 0, "breaking early on mobile" ); break; }
#define MOBILE_FLAG_NOT_LAST
MOBILE::flags indicating this mobile is not the last used mobile slot.
Definition mobile.h:211

◆ mobile_get_dir

#define mobile_get_dir ( m)
related
Value:
((m)->flags & MOBILE_DIR_MASK)
#define MOBILE_DIR_MASK
Bitmask defining bits in MOBILE::flags used to indicate which of the Cardinal Directions a mobile is ...
Definition mobile.h:157

Get the Cardinal Directions the mobile is facing.

◆ mobile_get_gid

#define mobile_get_gid ( m)
related
Value:
(MOBILE_GID)((((MOBILE_GID)((m)->map_gid)) << (sizeof( TILEMAP_GID ) * 8)) & (m)->spawner_gid)
uint16_t TILEMAP_GID
Globally unique identifier for TILEMAP objects.
Definition gid.h:26
uint32_t MOBILE_GID
Globally unique identifier for MOBILE objects.
Definition gid.h:22
SPAWN_GID spawner_gid
TILEMAP_SPAWN::gid of the spawner that spawned this mobile.
Definition mobile.h:259
TILEMAP_GID map_gid
TILEMAP::gid of the tilemap this mobile was spawned on.
Definition mobile.h:265

Get the globally unique identifier of the given MOBILE.

This identifier is/must be unique among all ::MOBILEs in DSEKAI_STATE::mobiles_handle and persists between Engine Locking cycles.

Parameters
mLocked MEMORY_PTR to MOBILE to query.
Returns
MOBILE_GID of the mobile m constructed from MOBILE::map_gid and MOBILE::spawner_gid.

◆ mobile_get_icount

#define mobile_get_icount ( m)
related
Value:
(((m)->flags & MOBILE_ICOUNT_MASK) >> 12)
#define MOBILE_ICOUNT_MASK
Bitmask defining bits in MOBILE::flags used to indicate the number of Scripting Interactions this mob...
Definition mobile.h:151

Get the current interaction count of the specified MOBILE.

Parameters
mLocked MEMORY_PTR to MOBILE to query.

◆ mobile_get_map_gid

#define mobile_get_map_gid ( m,
state )
related
Value:
((MOBILE_GID_PLAYER == mobile_get_gid( m )) ? (state)->tilemap->gid : (m)->map_gid)
#define MOBILE_GID_PLAYER
Special case unique identifier for the player-controlled MOBILE.
Definition gid.h:40
#define mobile_get_gid(m)
Get the globally unique identifier of the given MOBILE.
Definition mobile.h:129

Get the GID of the TILEMAP the given MOBILE is currently on.

Parameters
mLocked MEMORY_PTR to MOBILE to query.
Warning
Engine state must be locked with Engine Locking before use here!

◆ mobile_get_sprite

#define mobile_get_sprite ( m)
related
Value:
((m)->sprite_cache_id)

Get the pointer to the sprite graphic to use for a MOBILE.

◆ mobile_get_tx

#define mobile_get_tx ( m)
Value:
((m)->coords[1].x)

◆ mobile_get_ty

#define mobile_get_ty ( m)
Value:
((m)->coords[1].y)

◆ mobile_incr_icount

#define mobile_incr_icount ( m,
v )
related
Value:
(m)->flags = (((m)->flags & ~MOBILE_ICOUNT_MASK) | ((mobile_get_icount( m ) + (((v) << 12) & MOBILE_ICOUNT_MASK)) & MOBILE_ICOUNT_MASK))
#define mobile_get_icount(m)
Get the current interaction count of the specified MOBILE.
Definition mobile.h:108
uint16_t flags
Mobile Object Flags affecting this mobile's display and behavior.
Definition mobile.h:253

Increment MOBILE_ICOUNT_MASK by a given value.

Parameters
mLocked MEMORY_PTR to MOBILE to modify.
vValue to increment counter by.

◆ mobile_is_active

#define mobile_is_active ( m)
Value:
#define MOBILE_FLAG_ACTIVE
MOBILE::flags indicating that this mobile is extant and active.
Definition mobile.h:192

◆ mobile_is_walking

#define mobile_is_walking ( m)
Value:
((m)->coords[1].y != (m)->coords[0].y || (m)->coords[1].x != (m)->coords[0].x)

◆ mobile_set_dir

#define mobile_set_dir ( m,
v )
related
Value:
(m)->flags = (((m)->flags & ~MOBILE_DIR_MASK) | ((v) & MOBILE_DIR_MASK))

Set MOBILE_DIR_MASK in MOBILE::flags to the specified Cardinal Directions.

Parameters
mLocked MEMORY_PTR to MOBILE to modify.
vCardinal Directions to set the mobile facing.

◆ 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.