dsekai
World engine for retrocomputers.
Loading...
Searching...
No Matches
mobile.h
Go to the documentation of this file.
1
2#ifndef MOBILE_H
3#define MOBILE_H
4
20#define MOBILE_COORDS_QUEUE_SZ 5
21
68#define MOBILE_HP_MASK 0x00ff
69
73#define MOBILE_MP_MASK 0xff00
74
78#define MOBILE_HP_DEATH -10
79
84#define mobile_incr_hp( m, v ) (m)->mp_hp = (((m)->mp_hp & MOBILE_MP_MASK) | (((((m)->mp_hp & MOBILE_HP_MASK) + (v)) & MOBILE_HP_MASK) & MOBILE_HP_MASK))
85
92#define mobile_get_dir( m ) ((m)->flags & MOBILE_DIR_MASK)
93
101#define mobile_set_dir( m, v ) (m)->flags = (((m)->flags & ~MOBILE_DIR_MASK) | ((v) & MOBILE_DIR_MASK))
102
108#define mobile_get_icount( m ) (((m)->flags & MOBILE_ICOUNT_MASK) >> 12)
109
116#define mobile_incr_icount( m, v ) (m)->flags = (((m)->flags & ~MOBILE_ICOUNT_MASK) | ((mobile_get_icount( m ) + (((v) << 12) & MOBILE_ICOUNT_MASK)) & MOBILE_ICOUNT_MASK))
117
129#define mobile_get_gid( m ) (MOBILE_GID)((((MOBILE_GID)((m)->map_gid)) << (sizeof( TILEMAP_GID ) * 8)) & (m)->spawner_gid)
130
138#define mobile_get_map_gid( m, state ) ((MOBILE_GID_PLAYER == mobile_get_gid( m )) ? (state)->tilemap->gid : (m)->map_gid)
139
151#define MOBILE_ICOUNT_MASK 0xf000
152
157#define MOBILE_DIR_MASK 0x0007
158
168#define MOBILE_TYPE_NORMAL 0x0000
169
173#define MOBILE_TYPE_SPECIAL 0x0008
174
176#define MOBILE_TYPE_RES1 0x0010
177
179#define MOBILE_TYPE_RES2 0x0018
180 /* dsekai_mobiles_flags_type */
182
187#define MOBILE_TYPE_MASK 0x0018
188
192#define MOBILE_FLAG_ACTIVE 0x0100
193
197#define MOBILE_FLAG_PLAYER 0x0200
198
202#define MOBILE_FLAG_DISABLED 0x0400
203
211#define MOBILE_FLAG_NOT_LAST 0x0800
212 /* dsekai_mobiles_flags */
214
215#ifdef PLATFORM_CURSES
216# define mobile_get_sprite( m ) ((m)->ascii)
217#else
222# define mobile_get_sprite( m ) ((m)->sprite_cache_id)
223#endif /* PLATFORM_CURSES */
224
225#define mobile_get_tx( m ) ((m)->coords[1].x)
226#define mobile_get_ty( m ) ((m)->coords[1].y)
227
228#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; }
229
230#define mobile_is_active( m ) (MOBILE_FLAG_ACTIVE == (MOBILE_FLAG_ACTIVE & (m)->flags))
231
232#define mobile_is_walking( m ) ((m)->coords[1].y != (m)->coords[0].y || (m)->coords[1].x != (m)->coords[0].x)
233
243#define MOBILE_ERROR_BLOCKED -1
244 /* dsekai_mobiles_errors */
246
248struct MOBILE {
253 uint16_t flags;
266 char name[TILEMAP_SPAWN_NAME_SZ];
267 char sprite_name[RESOURCE_NAME_MAX];
271 int16_t mp_hp;
278 int16_t screen_px;
285 int16_t screen_py;
293 unsigned char ascii;
295 int8_t coords_sz;
314 int16_t script_id;
316 int16_t script_pc;
333};
334
343#define MOBILE_DIR_SOUTH 0
345#define MOBILE_DIR_NORTH 1
347#define MOBILE_DIR_EAST 2
349#define MOBILE_DIR_WEST 3
350 /* dsekai_mobiles_directions */
352
364uint8_t mobile_walk_start( struct MOBILE* m, uint8_t dir ) SECTION_MOBILE;
365
372 uint8_t x, uint8_t y, uint8_t dir, struct DSEKAI_STATE* state );
373
374struct MOBILE* mobile_from_gid( MOBILE_GID m_gid, struct DSEKAI_STATE* state );
375
383struct MOBILE* mobile_interact(
384 struct MOBILE* actor, struct MOBILE* actee, struct DSEKAI_STATE* state
385) SECTION_MOBILE;
386
391void mobile_state_animate( struct DSEKAI_STATE* state );
392
398void mobile_animate( struct MOBILE* m, struct DSEKAI_STATE* state );
399
406 struct MOBILE* m, struct DSEKAI_STATE* state ) SECTION_MOBILE;
407
413void mobile_stack_push( struct MOBILE* m, int8_t v ) SECTION_MOBILE;
414
420int8_t mobile_stack_pop( struct MOBILE* m ) SECTION_MOBILE;
421
428void mobile_execute( struct MOBILE* m, struct DSEKAI_STATE* state );
429
437 uint16_t flags, struct DSEKAI_STATE* state ) SECTION_MOBILE;
438
439int16_t mobile_spawner_match(
440 struct TILEMAP_SPAWN* spawner, struct DSEKAI_STATE* state ) SECTION_MOBILE;
441
447void mobile_spawns( struct DSEKAI_STATE* state ) SECTION_MOBILE;
448
449#ifdef MOBILE_C
450# ifndef NO_SMOOTH_WALK
451const int8_t gc_mobile_step_table_normal_pos[16] = {
452 0, 0, 0, 0, /* 0, 1, 2, 3 */
453 3, 3, 3, 3, /* 4, 5, 6, 7 */
454 7, 7, 7, 7, /* 8, 9, 10, 11 */
455 11, 11, 11, 11 /* 12, 13, 14, 15 */
456};
457# endif /* !NO_SMOOTH_WALK */
458
459const int8_t gc_mobile_y_offsets[4] = {
460 1, -1, 0, 0
461};
462
463const int8_t gc_mobile_x_offsets[4] = {
464 0, 0, 1, -1
465};
466#else
467# ifndef NO_SMOOTH_WALK
471extern const int8_t gc_mobile_step_table_normal_pos[16];
472# endif /* !NO_SMOOTH_WALK */
474extern const int8_t gc_mobile_y_offsets[4];
476extern const int8_t gc_mobile_x_offsets[4];
477#endif /* MOBILE_C */
478 /* dsekai_mobiles */
480
481#endif /* MOBILE_H */
482
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
uint16_t SPAWN_GID
Globally unique identifier for TILEMAP_SPAWN objects.
Definition: gid.h:24
void mobile_stack_push(struct MOBILE *m, int8_t v) SECTION_MOBILE
Push a value onto MOBILE::script_stack.
Definition: mobile.c:113
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.
void mobile_animate(struct MOBILE *m, struct DSEKAI_STATE *state)
Perform animation frame for the given MOBILE.
Definition: mobile.c:335
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.
Definition: mobile.c:26
const int8_t gc_mobile_x_offsets[4]
Lookup table for horizontal offset based on mobile_get_dir().
void mobile_spawns(struct DSEKAI_STATE *state) SECTION_MOBILE
Spawn from ::TILEMAP::spawners according to spawner rules.
Definition: mobile.c:479
uint8_t mobile_walk_start(struct MOBILE *m, uint8_t dir) SECTION_MOBILE
Have the given MOBILE attempt to begin walking movement/animation.
Definition: mobile.c:5
void mobile_state_animate(struct DSEKAI_STATE *state)
Map MOBILE animation frames to a number of real frames elapsed.
Definition: mobile.c:99
const int8_t gc_mobile_y_offsets[4]
Lookup table for vertical offset based on mobile_get_dir().
struct MOBILE * mobile_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 mo...
Definition: mobile.c:382
#define SCRIPT_STACK_DEPTH
Maximum depth of available local stack for each MOBILE executing a script. Each stack is individual t...
Definition: src/config.h:123
struct MOBILE * mobile_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.
Definition: mobile.c:147
int8_t mobile_stack_pop(struct MOBILE *m) SECTION_MOBILE
Pop a value from a MOBILE::script_stack.
Definition: mobile.c:128
void mobile_deactivate(struct MOBILE *m, struct DSEKAI_STATE *state) SECTION_MOBILE
Prepare a MOBILE for deallocation.
Definition: mobile.c:324
void mobile_execute(struct MOBILE *m, struct DSEKAI_STATE *state)
Execute the next available SCRIPT_STEP in the currently running SCRIPT on a MOBILE.
Definition: mobile.c:233
General/shared state of the running engine in memory.
Definition: engines.h:196
A moving/interactive object in the world.
Definition: mobile.h:248
int16_t script_id
Index currently executing behavior script in TILEMAP::scripts.
Definition: mobile.h:314
int8_t script_stack[SCRIPT_STACK_DEPTH]
Local stack used to store state for this mobile's SCRIPT.
Definition: mobile.h:325
int16_t script_pc
Position in currently executing behavior script.
Definition: mobile.h:316
uint8_t steps_remaining
Number of steps remaining in current walk animation.
Definition: mobile.h:312
int16_t screen_py
Current on-screen pixel left of sprite. -1 if off-screen.
Definition: mobile.h:285
uint16_t flags
Mobile Object Flags affecting this mobile's display and behavior.
Definition: mobile.h:253
int16_t sprite_cache_id
Index of the mobile's Mobile Spritesheets loaded in the Unilayer Graphics Cache.
Definition: mobile.h:292
#define MOBILE_COORDS_QUEUE_SZ
Number of positions available in the MOBILE::coords queue.
Definition: mobile.h:20
int8_t coords_sz
Number of coordinates in MOBILE::coords.
Definition: mobile.h:295
int16_t screen_px
Current on-screen pixel left of sprite. -1 if off-screen.
Definition: mobile.h:278
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
int16_t mp_hp
The combined dsekai_mobiles_mp_hp field.
Definition: mobile.h:271
uint16_t script_wait_frames
Delay script for this many frames.
Definition: mobile.h:332
struct TILEMAP_COORDS coords[MOBILE_COORDS_QUEUE_SZ]
The mobile's current location (in tiles) as well as queued future locations.
Definition: mobile.h:305
X/Y coordinates of a tile on the current map.
Definition: tmstruct.h:33
Defines a spawner to create mobiles in the world.
Definition: tmstruct.h:59
#define RESOURCE_NAME_MAX
Definition: unilayer.h:54