include/entity.h file

Classes

struct UnkStruct
struct Hitbox
Hitbox structure.
struct Hitbox3D
Hitbox structure supporting depth.
struct PACKED
struct Entity
Container for instantiable behavior.
struct Entity::SpriteSettings
struct Entity::SpriteRendering
union Entity::Palette
struct Entity::Palette::PaletteB
struct Entity::SpriteOrientation
struct GenericEntityData
struct GenericEntity
struct LinkedList
Entity linked list structure.
struct CarriedEntity

Enums

enum EntityKind { PLAYER = 1, ENEMY = 3, PROJECTILE = 4, OBJECT = 6, NPC = 7, PLAYER_ITEM = 8, MANAGER = 9 }
Kinds of Entity's supported by the game.
enum EntityFlags { ENT_DID_INIT = 0x1, ENT_SCRIPTED = 0x2, ENT_UNUSED1 = 0x4, ENT_UNUSED2 = 0x8, ENT_DELETED = 0x10, ENT_PERSIST = 0x20, ENT_COLLIDE = 0x80 }
Entity flags.
enum Priority { PRIO_MIN, PRIO_PLAYER, PRIO_MESSAGE, PRIO_NO_BLOCK, PRIO_4, PRIO_5, PRIO_PLAYER_EVENT, PRIO_HIGHEST }
Priority level to determine what events will block an Entity from updating.
enum AnimationState { IdleNorth = 0x0, IdleEast = 0x2, IdleSouth = 0x4, IdleWest = 0x6 }
Animation state.
enum Direction { DirectionNorth = 0x00, DirectionNorthEast = 0x04, DirectionEast = 0x08, DirectionSouthEast = 0x0c, DirectionSouth = 0x10, DirectionSouthWest = 0x14, DirectionWest = 0x18, DirectionNorthWest = 0x1c }
Direction.
enum CollisionLayer { COL_LAYER_NONE = 0x0, COL_LAYER_BOTTOM = 0x1, COL_LAYER_TOP = 0x2, COL_LAYER_BOTH = 0x3 }
Collision layer flags.
enum CollisionClass { COL_CLASS_NONE = 0x0, COL_CLASS_PLAYER = 0x1, COL_CLASS_ITEM = 0x2, COL_CLASS_FLAMMABLE = 0x3, COL_CLASS_4 = 0x4, COL_CLASS_5 = 0x5, COL_CLASS_6 = 0x6, COL_CLASS_PACCI_OBJ = 0x7 }
Collision class flags.
enum CollisionFlags { COL_FLAG_3D = 0x10, COL_FLAG_SOLID = 0x20, COL_FLAG_REFLECT = 0x80 }
Collision flags.

Typedefs

using EntityAction = void()(Entity*)
using EntityActionPtr = void(*)(Entity*)
using EntityActionArray = void(*const)(Entity*)

Functions

void DrawEntity(Entity* entity)
Draw an Entity.
void InitializeAnimation(Entity* entity, u32 animIndex)
void InitAnimationForceUpdate(Entity* entity, u32 animIndex)
void UpdateAnimationSingleFrame(Entity* entity)
void UpdateSpriteForCollisionLayer(Entity* entity)
void GetNextFrame(Entity* entity)
auto LoadExtraSpriteData(Entity* entity, const SpriteLoadData* spriteData) -> bool32
void SetExtraSpriteFrame(Entity* this, u32 param_2, u32 param_3)
void SetSpriteSubEntryOffsetData1(Entity* this, u32 param_2, u32 param_3)
void SetSpriteSubEntryOffsetData2(Entity* this, u32 param_2, u32 param_3)
auto GetSpriteSubEntryOffsetDataPointer(u32 param_1, u32 param_2) -> u8*
auto SetAffineInfo(Entity* ent, u32 param_2, u32 param_3, u32 param_4) -> bool32
auto GetFacingDirection(Entity* origin, Entity* target) -> u32
Return the direction pointing from one Entity to another.
auto ProcessMovement0(Entity* this) -> bool32
void UpdateEntities(void)
Iteratively execute every Entity.
void UpdateManagers(void)
Iteratively execute every Manager.
void DeleteManager(void* manager)
Delete a manager.
void DeleteEntityAny(Entity* entity)
Delete Manager or Entity.
void EraseAllEntities(void)
Erase all Entity's.
void DeleteThisEntity(void)
Delete the Entity currently in execution.
void DeleteEntity(Entity* entity)
Delete an Entity.
void AppendEntityToList(Entity* entity, u32 listIndex)
Add an Entity to the end of a LinkedList.
void PrependEntityToList(Entity* entity, u32 listIndex)
Add an Entity to the start of a LinkedList.
auto FindEntityByID(u32 kind, u32 id, u32 listIndex) -> Entity*
Find an Entity for a given kind and id, and LinkedList.
auto DeepFindEntityByID(u32 kind, u32 id) -> Entity*
Search all lists for an Entity of same kind and id.
auto EntityHasDuplicateID(Entity* entity) -> bool32
Search all lists for Entity of same kind and id.
auto FindNextDuplicateID(Entity* entity, int listIndex) -> Entity*
Find an Entity of same kind and id in LinkedList.
auto FindEntity(u32 kind, u32 id, u32 listIndex, u32 type, u32 type2) -> Entity*
Find an Entity with full identifiers.
void SetEntityPriority(Entity* entity, u32 prio)
Set the default priority for entity.
auto EntityDisabled(Entity* entity) -> bool32
Check if entity is disabled.
auto AnyPrioritySet(void) -> bool32
Check if system or entity is blocking updates.
auto SetMinPriority(u32 prio) -> s32
Set the minimum Entity priority.
void RequestPriority(Entity* entity)
Request indefinite priority for an Entity.
void RevokePriority(Entity* entity)
Revoke priority from an Entity.
void RequestPriorityDuration(Entity* entity, u32 time)
Request update priority over other Entity's for a period of time.
void SetPriorityTimer(u32 time)
Set the remaining frames of Entity priority.
void RequestPriorityOverPlayer(Entity* entity)
Request priority over player update.
void RevokePriorityOverPlayer(Entity* entity)
Revoke priority over player update.
void ResetEntityPriority(void)
Reset a priority event requested by an Entity.
void SetPlayerEventPriority(void)
Set entity and system priority to PRIO_PLAYER_EVENT.
void ResetPlayerEventPriority(void)
Reset entity and system priority to defaults.
void SetRoomReloadPriority(void)
Set system priority to PRIO_PLAYER_EVENT.
void SetInitializationPriority(void)
Set system priority to PRIO_HIGHEST.
void ClearEventPriority(void)
Reset the system update priority.
void sub_0805E958(void)
void DeleteAllEntities(void)

Variables

LinkedList gEntityLists
LinkedList's which point to allocate Entities.
GenericEntity gAuxPlayerEntities
GenericEntity gEntities
CarriedEntity gCarriedEntity
u8 gEntCount
Current number of entities.
u8 gManagerCount
Current number of managers.

Defines

#define MAX_ENTITIES
#define MAX_MANAGERS
#define MAX_AUX_PLAYER_ENTITIES
#define COLLISION_MASK(layer)
#define CONTACT_NOW
#define GENERIC_ENTITY_FIELDS
#define COLLISION_OFF(entity)
#define COLLISION_ON(entity)
#define ANIM_DONE

Tile Macros

#define TILE(x, y)
#define TILE_LOCAL(x, y)
#define TILE_POS(x, y)
#define TILE_POS_X_COMPONENT
#define TILE_POS_Y_COMPONENT
#define COORD_TO_TILE(entity)
#define COORD_TO_TILE_OFFSET(entity, xOff, yOff)

Animation State Macros

#define AnimationStateFlip90(expr)
#define AnimationStateFlip180(expr)
#define AnimationStateIdle(expr)
#define AnimationStateWalk(expr)

Direction Macros

#define DirectionRound(expr)
#define DirectionRoundUp(expr)
#define DirectionIsHorizontal(expr)
#define DirectionIsVertical(expr)
#define DirectionTurnAround(expr)
#define DirectionToAnimationState(expr)
#define DirectionFromAnimationState(expr)
#define DirectionNormalize(expr)
#define Direction8Round(expr)
#define Direction8RoundUp(expr)
#define Direction8TurnAround(expr)
#define Direction8ToAnimationState(expr)
#define Direction8FromAnimationState(expr)

Enum documentation

enum EntityKind

Kinds of Entity's supported by the game.

Enumerators
PLAYER

There is only one id assigned to the Player kind.

The player Entity shares much of its code with LTTP GBA, however the game only supports one player Entity active at a time, assigned to the global gPlayerEntity. Works next to PlayerState to control player behavior.

ENEMY

Can give and take damage in relation to the player.

Most enemies call the a set of external helper functions which calculate what behavior to execute.

PROJECTILE

May damage the player.

They are typically spawned by enemies.

OBJECT

Encapsulates any sort of prop.

Generally they cannot be interacted with directly, but they may react to a player action or script event.

NPC

May be interacted with by the player.

Almost every NPC is assigned a script. NPCs have three entry points: one for the head, one for the body, and one for kinstone fusion.

PLAYER_ITEM

Displays sprites for items outside of the inventory (check).

MANAGER

Utility Entity's that serve as a proxy between gameplay and the engine.

Examples: drawing clouds, ezlo hints, playing cutscenes. Updates independently of other entities, and does not add to maximum entity count.

enum EntityFlags

Entity flags.

Enumerators
ENT_DID_INIT

Graphics and other data loaded.

ENT_SCRIPTED

Execute in a scripted environment.

ENT_UNUSED1

Unused delete flag.

ENT_UNUSED2

Unused delete flag.

ENT_DELETED

Queue deletion next frame.

ENT_PERSIST

Persist between rooms.

ENT_COLLIDE

Collide with other Entity's.

enum Priority

Priority level to determine what events will block an Entity from updating.

Enumerators
PRIO_MIN

Default priority.

PRIO_PLAYER

Default priority for player.

PRIO_MESSAGE

Do not block during message.

PRIO_NO_BLOCK

Do not block during entity requested priority.

PRIO_4

Unused.

PRIO_5

Unused.

PRIO_PLAYER_EVENT

Do not block during special player event.

PRIO_HIGHEST

Do not block EVER.

enum AnimationState

Animation state.

Enumerators
IdleNorth

Idle facing north.

IdleEast

Idle facing east.

IdleSouth

Idle facing south.

IdleWest

Idle facing west.

enum Direction

Direction.

Enumerators
DirectionNorth

North.

DirectionNorthEast

North East.

DirectionEast

East.

DirectionSouthEast

South East.

DirectionSouth

South.

DirectionSouthWest

South West.

DirectionWest

West.

DirectionNorthWest

North West.

enum CollisionClass

Collision class flags.

An Entity's collision class is determined by the first 3 bits of Entity::collisionFlags. What classes an Entity collides with is determined by the bitfield Entity::collisionMask.

Function documentation

void DrawEntity(Entity* entity)

Draw an Entity.

Parameters
entity Entity to be drawn.

u32 GetFacingDirection(Entity* origin, Entity* target)

Return the direction pointing from one Entity to another.

Parameters
origin Entity to orient.
target Entity to look at.
Returns Direction facing target.

void UpdateEntities(void)

Iteratively execute every Entity.

Call once per frame.

void UpdateManagers(void)

Iteratively execute every Manager.

Call once per frame.

void DeleteManager(void* manager)

Delete a manager.

Parameters
manager Manager to delete.

void DeleteEntityAny(Entity* entity)

Delete Manager or Entity.

Parameters
entity Entity or Manager to be deleted.

void DeleteThisEntity(void)

Delete the Entity currently in execution.

void DeleteEntity(Entity* entity)

Delete an Entity.

Parameters
entity Entity to delete.

void AppendEntityToList(Entity* entity, u32 listIndex)

Add an Entity to the end of a LinkedList.

Parameters
entity Entity to add.
listIndex Target LinkedList.

void PrependEntityToList(Entity* entity, u32 listIndex)

Add an Entity to the start of a LinkedList.

Parameters
entity Entity to add.
listIndex Target LinkedList.

Entity* FindEntityByID(u32 kind, u32 id, u32 listIndex)

Find an Entity for a given kind and id, and LinkedList.

Returns Entity* First result or NULL if none found.

Entity* DeepFindEntityByID(u32 kind, u32 id)

Search all lists for an Entity of same kind and id.

Returns Entity* First result or NULL if none found.

bool32 EntityHasDuplicateID(Entity* entity)

Search all lists for Entity of same kind and id.

Returns bool32 Duplicate was found.

Entity* FindNextDuplicateID(Entity* entity, int listIndex)

Find an Entity of same kind and id in LinkedList.

Returns Entity* First result or NULL if none found.

Entity* FindEntity(u32 kind, u32 id, u32 listIndex, u32 type, u32 type2)

Find an Entity with full identifiers.

Returns Entity* First result or NULL if none found.

void SetEntityPriority(Entity* entity, u32 prio)

Set the default priority for entity.

Parameters
entity Entity to set the priority of.
prio Priority level.

bool32 EntityDisabled(Entity* entity)

Check if entity is disabled.

Entities are disabled if:

  • They are deleted.
  • There is an event and the entity doesn't have priority (n/a if entity is in action 0).

s32 SetMinPriority(u32 prio)

Set the minimum Entity priority.

Parameters
prio Minimum Priority.
Returns Success.

void RequestPriority(Entity* entity)

Request indefinite priority for an Entity.

Parameters
entity Entity requesting priority.

void RevokePriority(Entity* entity)

Revoke priority from an Entity.

Parameters
entity Entity which requested priority.

void RequestPriorityDuration(Entity* entity, u32 time)

Request update priority over other Entity's for a period of time.

Parameters
entity Entity requesting priority.
time Number of frames.

void SetPriorityTimer(u32 time)

Set the remaining frames of Entity priority.

Parameters
time Number of frames.

void RequestPriorityOverPlayer(Entity* entity)

Request priority over player update.

Parameters
entity Entity requesting priority.

void RevokePriorityOverPlayer(Entity* entity)

Revoke priority over player update.

Parameters
entity Entity which requested priority.

Variable documentation

LinkedList gEntityLists

LinkedList's which point to allocate Entities.

These work together with Entity.prev and Entity.next fields to allow the iteration of all Entity's.

u8 gEntCount

Current number of entities.

u8 gManagerCount

Current number of managers.