6#include "sprite/player.h"
9extern Addr WorldEntityHeapBottom;
11#define WORLD_ENTITY_HEAP_BOTTOM (s32) WorldEntityHeapBottom
12#define WORLD_ENTITY_HEAP_BASE (s32) WorldEntityHeapBase
13#define entity_jan_iwa_VRAM (void*) entity_jan_iwa_VRAM
14#define entity_sbk_omo_VRAM (void*) entity_sbk_omo_VRAM
15#define entity_default_VRAM (void*) entity_default_VRAM
17#define WORLD_ENTITY_HEAP_BOTTOM 0x80250000
18#define WORLD_ENTITY_HEAP_BASE 0x80267FF0
19#define entity_jan_iwa_VRAM (void*) 0x802BAE00
20#define entity_sbk_omo_VRAM (void*) 0x802BAE00
21#define entity_default_VRAM (void*) 0x802BAE00
25extern Addr entity_default_ROM_END;
26extern Addr entity_default_ROM_START;
27extern Addr entity_jan_iwa_ROM_END;
28extern Addr entity_jan_iwa_ROM_START;
29extern Addr entity_sbk_omo_ROM_END;
30extern Addr entity_sbk_omo_ROM_START;
97 entity->
flags &= ~ENTITY_FLAG_BOUND_SCRIPT_DIRTY;
121 entity->
flags &= ~ENTITY_FLAG_2000000;
131 if (handleCollision != NULL && handleCollision(entity) != 0) {
145 entity->
flags &= ~ENTITY_FLAG_DETECTED_COLLISION;
146 entity->
flags &= ~ENTITY_FLAG_PARTNER_COLLISION;
211 if (shadow != NULL) {
245 void (*tempfunc)(
Entity*);
261 tempfunc = (void (*)(
Entity*))(*args++);
290 entity->
flags |= *args++;
295 entity->
flags &= ~*args++;
319 gDPSetRenderMode(
gMainGfxPos++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
320 gDPSetCombineMode(
gMainGfxPos++, G_CC_MODULATEIA, G_CC_MODULATEIA);
323 gDPSetPrimColor(
gMainGfxPos++, 0, 0, 0, 0, 0, alpha);
332 s32 alpha = (s32)data;
335 gDPSetPrimColor(
gMainGfxPos++, 0, 0, 0, 0, 0, alpha);
344 if (entity != NULL) {
351 entity->
pos.
z) > 200.0f
430 if (shadow != NULL) {
434 if (shadow->
alpha <= 20) {
450 if (shadow->
alpha <= 20) {
571 if (entity == NULL) {
598 (*gCurrentEntityListPtr)[entityIndex] = NULL;
623 (*gCurrentEntityListPtr)[entityIndex] = NULL;
631 (*gCurrentShadowListPtr)[shadowIndex] = NULL;
641 entity->
flags &= ~ENTITY_FLAG_PARTNER_COLLISION;
678 s32 interacted = FALSE;
685 switch (entityType) {
708 switch (entityType) {
750 if (xCollRadius < xDist || zCollRadius < zDist) {
769 entity->
flags &= ~ENTITY_FLAG_DETECTED_COLLISION;
832 (*gCurrentEntityListPtr)[i] = NULL;
836 (*gCurrentShadowListPtr)[i] = NULL;
877 dataLength = ((bp->dma.end - bp->dma.start) >> 2);
879 totalSize +=
dma_copy(bp->dma.start, bp->dma.end, gfxData) >> 2;
885 temp1 =
dma_copy(dmaList[0].start, dmaList[0].end, gfxData) >> 2;
893 dataLength = ((dmaList[0].
end - dmaList[0].
start) >> 2);
895 gfxData = (
void*)(q - dataLength * 4);
896 totalSize +=
dma_copy(dmaList[0].start, dmaList[0].end, gfxData) >> 2;
898 dataLength = ((dmaList[1].
end - dmaList[1].
start) >> 2);
900 animData = (
void*)(q - dataLength * 4);
901 totalSize +=
dma_copy(dmaList[1].start, dmaList[1].end, animData) >> 2;
927 if ((s32)node->
sibling != -1) {
933 if ((s32)node->
child != -1) {
939 if ((s32)node->
vtxList != -1) {
940 node->
vtxList = (Vtx*)((s32)baseGfx + ((s32)(node->
vtxList) & 0xFFFFF));
967 blueprints[0] = blueprint;
968 blueprints[1] = NULL;
972 entDmaList = blueprint->dmaList;
973 size = (entDmaList[0].
end - entDmaList[0].
start) >> 2;
974 *loadedEnd = *loadedStart + size;
979 entDmaList = blueprint->dmaList;
980 if (bpDmaList == entDmaList) {
982 s32 size = (bpDmaList[0].
end - bpDmaList[0].
start) >> 2;
983 *loadedEnd = *loadedStart + size;
986 }
else if (bp == blueprint) {
988 s32 size = (entDmaList[0].
end - entDmaList[0].
start) >> 2;
989 *loadedEnd = *loadedStart + size;
994 s32 size = (bpDmaList[0].
end - bpDmaList[0].
start) >> 2;
995 *loadedEnd = *loadedStart = *loadedStart + size;
996 size = (bpDmaList[1].
end - bpDmaList[1].
start) >> 2;
997 *loadedStart = *loadedStart + size;
999 *loadedStart += (bp->dma.end - bp->dma.start) >> 2;
1023 if (totalSize + ((bp->dma.end - bp->dma.start) >> 2) > 0x5FFCU) {
1028 entitySize = (bp->dma.end - bp->dma.start) >> 2;
1033 entitySize = (bp->dma.end - bp->dma.start) >> 2;
1046 s32 swizzlePointers = FALSE;
1047 s32 loadedStart, loadedEnd;
1049 s16* animationScript;
1058 DmaEntry* dmaList = entityData->dmaList;
1066 specialSize = 0x1000;
1072 specialSize = 0x2BC0;
1079 if (specialSize != 0) {
1083 specialSize -= 0x1000;
1089 swizzlePointers = TRUE;
1097 if ((totalLoaded + ((dmaList[0].end - dmaList[0].start) >> 2)) > 0x5FFCU) {
1102 if ((totalLoaded + ((dmaList[1].end - dmaList[1].start) >> 2)) > 0x5FFCU) {
1107 dma2size_1 =
dma_copy(dmaList[0].start, dmaList[0].end, dmaList[0].start + ((
gEntityHeapBase - totalLoaded * 4 - (s32)dmaList[0].end) >> 2) * 4) >> 2;
1109 totalLoaded += dma2size_1;
1111 dma2size_2 =
dma_copy(dmaList[1].start, dmaList[1].end, dmaList[1].start + ((
gEntityHeapBase - totalLoaded * 4 - (s32)dmaList[1].end) >> 2) * 4) >> 2;
1112 animBaseAddr = (
void*)(
gEntityHeapBase - totalLoaded * 4 - dma2size_2 * 4);
1113 totalLoaded += dma2size_2;
1121 swizzlePointers = TRUE;
1123 u32 temp = (dmaList[0].
end - dmaList[0].
start) >> 2;
1125 temp = (dmaList[1].
end - dmaList[1].
start) >> 2;
1137 if (swizzlePointers) {
1150 Entity* entity = (*gCurrentEntityListPtr)[i];
1152 if (entity != NULL && entity->
blueprint->dma.start != NULL) {
1166 for (freeSlot = 0; freeSlot <
MAX_ENTITIES; freeSlot++) {
1178 size = ((dmaList[0].
end - dmaList[0].
start) >> 2);
1179 size += ((dmaList[1].
end - dmaList[1].
start) >> 2);
1185 size = (bp->dma.end - bp->dma.start) >> 2;
1207 x = va_arg(ap, s32);
1208 y = va_arg(ap, s32);
1209 z = va_arg(ap, s32);
1210 rotY = va_arg(ap, s32);
1217 s32 arg = va_arg(ap, s32);
1237 (*gCurrentEntityListPtr)[listIndex] = entity =
heap_malloc(
sizeof(*entity));
1260 entity->
rot.
x = 0.0f;
1261 entity->
rot.
y = rotY;
1262 entity->
rot.
z = 0.0f;
1271 entity->
alpha = 255;
1277 if (bp->dma.start != 0) {
1302 if (bp->
fpInit != NULL) {
1323 (*gCurrentShadowListPtr)[i] = shadow;
1327 shadow->
alpha = 128;
1344 if (bp->onCreateCallback != NULL) {
1345 bp->onCreateCallback(shadow);
1352 Bytecode* args = script->ptrReadPos;
1360 if (isInitialCall != TRUE) {
1374 for (idx = 0;; idx++) {
1385 script->varTable[0] = entityIndex;
1391 Bytecode* args = script->ptrReadPos;
1396 }
else if (mode == 1) {
1398 }
else if (mode == 2) {
1409 Bytecode* args = script->ptrReadPos;
1418 entity->
flags &= ~ENTITY_FLAG_HAS_DYNAMIC_SHADOW;
1425 Bytecode* args = script->ptrReadPos;
1427 if (isInitialCall == TRUE) {
1438 Bytecode* args = script->ptrReadPos;
1440 if (isInitialCall == TRUE) {
1456 Bytecode* args = script->ptrReadPos;
1458 if (isInitialCall == TRUE) {
1471 Bytecode* args = script->ptrReadPos;
1473 if (isInitialCall == TRUE) {
1484 Bytecode* args = script->ptrReadPos;
1486 if (isInitialCall == TRUE) {
1497 Bytecode* args = script->ptrReadPos;
1499 if (isInitialCall == TRUE) {
1529 s32 isFixedSize = FALSE;
1563 if (shadow != NULL) {
1572 if (entity->
alpha < 255) {
1582 shadow->
alpha = alphaTemp;
1587 shadow->
flags &= ~ENTITY_FLAG_SHADOW_POS_DIRTY;
1593 rayX = entity->
pos.
x;
1594 rayY = entity->
pos.
y;
1595 rayZ = entity->
pos.
z;
1597 if (!
entity_raycast_down(&rayX, &rayY, &rayZ, &hitYaw, &hitPitch, &hitLength) && hitLength == 32767.0f) {
1601 origHitLength = hitLength;
1608 hitLength = ((hitLength / 150.0f) + 0.95) * 250.0;
1615 shadow->
pos.
y = rayY;
1617 shadow->
rot.
x = hitYaw;
1618 shadow->
rot.
z = hitPitch;
1621 if (entity->
pos.
y < rayY) {
1623 entity->
pos.
y = rayY + 10.0f;
1625 shadow->
flags &= ~ENTITY_FLAG_SKIP_UPDATE;
1638 f32 hitX, hitY, hitZ;
1640 f32 hitNx, hitNy, hitNz;
1645 hitDepth = 32767.0f;
1648 entityID =
test_ray_entities(*x, *y, *z, 0.0f, -1.0f, 0.0f, &hitX, &hitY, &hitZ, &hitDepth, &hitNx, &hitNy, &hitNz);
1654 colliderID =
test_ray_colliders(
COLLIDER_FLAG_IGNORE_PLAYER, *x, *y, *z, 0.0f, -1.0f, 0.0f, &hitX, &hitY, &hitZ, &hitDepth, &hitNx,
1662 *hitLength = hitDepth;
1663 *hitYaw = -
atan2(0.0f, 0.0f, hitNz * 100.0f, hitNy * 100.0f);
1664 *hitPitch = -
atan2(0.0f, 0.0f, hitNx * 100.0f, hitNy * 100.0f);
1667 *hitLength = 32767.0f;
1676 shadow->
scale.
x = 0.13 - (height / 2600.0f);
1678 shadow->
scale.
x = 0.12 - (height / 3600.0f);
1681 if (shadow->
scale.
x < 0.01) {
1689 shadow->
scale.
x = 0.13 - (height / 2600.0f);
1691 shadow->
scale.
x = 0.12 - (height / 3600.0f);
1694 if (shadow->
scale.
x < 0.01) {
1698 if (npcRadius > 60.0f) {
1710 switch (playerStatus->
anim) {
1711 case ANIM_Peach2_Carried:
1712 case ANIM_Peach2_Thrown:
1713 case ANIM_Peach2_Land:
1714 case ANIM_Peach3_TiedSideways:
1715 shadow->
scale.
x = 0.26f - (scale / 2600.0f);
1716 if (shadow->
scale.
x < 0.01) {
1719 shadow->
scale.
z = 0.13f - (scale / 2600.0f);
1720 if (shadow->
scale.
z < 0.01) {
1729 shadow->
scale.
x = phi_f2 - (scale / 3600.0f);
1730 if (shadow->
scale.
x < 0.01) {
1737 f32 x = block->
pos.
x;
1738 f32 y = block->
pos.
y;
1739 f32 z = block->
pos.
z;
struct StaticAnimatorNode * child
struct WoodenCrateData * crate
struct StaticAnimatorNode * sibling
struct SwitchData * swtch
s32(* EntityCallback)(struct Entity *)
struct HiddenPanelData * hiddenPanel
#define ASSERT(condition)
BSS ShadowList gBattleShadowList
Entity * get_entity_by_index(s32 index)
void render_shadows(void)
void update_entity_shadow_position(Entity *entity)
void update_shadows(void)
void render_entities(void)
BSS ShadowList * gCurrentShadowListPtr
s32 gLastCreatedEntityIndex
EntityList * get_entity_list(void)
void init_entity_data(void)
s32 create_entity_shadow(Entity *entity, f32 x, f32 y, f32 z)
BSS EntityList gBattleEntityList
BSS ShadowList gWorldShadowList
BSS EntityList * gCurrentEntityListPtr
void entity_reset_collision(Entity *entity)
s32 test_player_entity_aabb(Entity *entity)
void delete_entity(s32 entityIndex)
BSS s32 bEntityDataLoadedSize
#define WORLD_ENTITY_HEAP_BOTTOM
Shadow * get_shadow_by_index(s32 index)
void entity_free_static_data(EntityBlueprint *data)
s32 isAreaSpecificEntityDataLoaded
BSS EntityBlueprint * bEntityBlueprint[4]
s32 entity_start_script(Entity *entity)
void func_8010FD98(void *arg0, s32 alpha)
void update_entity_transform_matrix(Entity *entity)
void load_simple_entity_data(Entity *entity, EntityBlueprint *bp, s32 listIndex)
void clear_entity_data(b32 arg0)
void entity_swizzle_anim_pointers(EntityBlueprint *entityData, void *baseAnim, void *baseGfx)
void update_entities(void)
void update_entity_inverse_rotation_matrix(Entity *entity)
s32 entity_try_partner_interaction_trigger(s32 entityIdx)
#define WORLD_ENTITY_HEAP_BASE
void load_area_specific_entity_data(void)
s32 CreateEntityVarArgBuffer[4]
void entity_model_set_shadow_color(void *data)
void set_entity_commandlist(Entity *entity, s32 *entityScript)
b32 entity_raycast_down(f32 *x, f32 *y, f32 *z, f32 *hitYaw, f32 *hitPitch, f32 *hitLength)
Mostly used for shadows.
BSS s32 wEntityDataLoadedSize
s32 step_entity_commandlist(Entity *entity)
s32 entity_get_collision_flags(Entity *entity)
void exec_entity_commandlist(Entity *entity)
void set_peach_shadow_scale(Shadow *shadow, f32 scale)
s32 create_shadow_type(s32 type, f32 x, f32 y, f32 z)
void delete_entity_and_unload_data(s32 entityIndex)
void reload_world_entity_data(void)
void update_shadow_transform_matrix(Shadow *shadow)
void delete_shadow(s32 shadowIndex)
BSS EntityList gWorldEntityList
void load_split_entity_data(Entity *entity, EntityBlueprint *entityData, s32 listIndex)
s32 func_80111790(EntityBlueprint *data)
s32 create_shadow_from_data(ShadowBlueprint *bp, f32 x, f32 y, f32 z)
Addr BattleEntityHeapBottom
BSS EntityBlueprint * wEntityBlueprint[MAX_ENTITIES+2]
void func_8010FE44(void *arg0)
void entity_set_render_script(Entity *entity, EntityModelScript *cmdList)
u32 get_entity_type(s32 index)
void set_npc_shadow_scale(Shadow *shadow, f32 height, f32 npcRadius)
s32 create_entity(EntityBlueprint *bp,...)
s32 is_entity_data_loaded(Entity *entity, EntityBlueprint *blueprint, s32 *loadedStart, s32 *loadedEnd)
s32 is_block_on_ground(Entity *block)
s32 is_player_action_state(s8 actionState)
HiddenPanelsData gCurrentHiddenPanels
void set_standard_shadow_scale(Shadow *shadow, f32 height)
ShadowList * get_shadow_list(void)
s32 load_entity_model(EntityModelScript *cmdList)
ShadowBlueprint SquareShadow
ShadowBlueprint CircularShadowB
void set_entity_model_render_command_list(s32 idx, EntityModelScript *cmdList)
EntityModel * get_entity_model(s32 idx)
ShadowBlueprint CircularShadowA
@ ENTITY_SCRIPT_OP_PlaySound
@ ENTITY_SCRIPT_OP_RestartBoundScript
@ ENTITY_SCRIPT_OP_ClearFlags
@ ENTITY_SCRIPT_OP_SetFlags
@ ENTITY_SCRIPT_OP_SetCallback
@ SHADOW_FIXED_ALT_CIRCLE
@ SHADOW_VARYING_ALT_CIRCLE
@ COLLIDER_FLAG_IGNORE_PLAYER
@ ENTITY_TYPE_HAMMER1_BLOCK
@ ENTITY_TYPE_MUNCHLESIA_ENVELOP
@ ENTITY_TYPE_SINGLE_TRIGGER_BLOCK
@ ENTITY_TYPE_SCRIPT_SPRING
@ ENTITY_TYPE_MUNCHLESIA_CHEWING
@ ENTITY_TYPE_MUNCHLESIA_BEGIN_CHEW
@ ENTITY_TYPE_MUNCHLESIA_RESET2
@ ENTITY_TYPE_BOMBABLE_ROCK
@ ENTITY_TYPE_HIDDEN_RED_BLOCK
@ ENTITY_TYPE_SUPER_BLOCK
@ ENTITY_TYPE_HEALING_BLOCK
@ ENTITY_TYPE_BLUE_SWITCH
@ ENTITY_TYPE_MUNCHLESIA_GRAB
@ ENTITY_TYPE_MUNCHLESIA_SPIT_OUT
@ ENTITY_TYPE_MULTI_COIN_BRICK
@ ENTITY_TYPE_SIMPLE_SPRING
@ ENTITY_TYPE_RESET_MUNCHLESIA
@ ENTITY_TYPE_BRICK_BLOCK
@ ENTITY_TYPE_HIDDEN_YELLOW_BLOCK
@ ENTITY_TYPE_MULTI_TRIGGER_BLOCK
@ ENTITY_TYPE_HAMMER1_BLOCK_TINY
@ ENTITY_TYPE_MUNCHLESIA_RESET1
@ ENTITY_TYPE_YELLOW_BLOCK
@ ENTITY_TYPE_STAR_BOX_LAUNCHER
@ ENTITY_COLLISION_PARTNER
@ ENTITY_COLLISION_PLAYER_HAMMER
@ ENTITY_COLLISION_PLAYER_TOUCH_WALL
@ ENTITY_COLLISION_PLAYER_TOUCH_FLOOR
@ ENTITY_COLLISION_PLAYER_TOUCH_CEILING
@ ENTITY_COLLISION_PLAYER_PUSHING_AGAINST
@ ENTITY_COLLISION_PLAYER_LAST_FLOOR
@ ENTITY_FLAG_DETECTED_COLLISION
@ ENTITY_FLAG_CONTINUOUS_COLLISION
@ ENTITY_FLAG_IGNORE_DISTANCE_CULLING
@ ENTITY_FLAG_HAS_ANIMATED_MODEL
@ ENTITY_FLAG_DARK_SHADOW
@ ENTITY_FLAG_SHADOW_POS_DIRTY
@ ENTITY_FLAG_DRAW_IF_CLOSE_HIDE_MODE2
@ ENTITY_FLAG_DRAW_IF_CLOSE_HIDE_MODE1
@ ENTITY_FLAG_HAS_DYNAMIC_SHADOW
@ ENTITY_FLAG_PARTNER_COLLISION
@ ENTITY_FLAG_FIXED_SHADOW_SIZE
@ ENTITY_FLAG_BOUND_SCRIPT_DIRTY
@ ENTITY_FLAG_SKIP_UPDATE_TRANSFORM_MATRIX
@ ENTITY_FLAG_SKIP_UPDATE
@ ENTITY_FLAG_PENDING_INSTANCE_DELETE
@ ENTITY_FLAG_DISABLE_COLLISION
@ ENTITY_FLAG_ALWAYS_FACE_CAMERA
@ ENTITY_FLAG_FADING_AWAY
@ ENTITY_FLAG_PENDING_FULL_DELETE
@ ENTITY_FLAG_CIRCULAR_SHADOW
@ EVT_FLAG_RUN_IMMEDIATELY
don't wait for next update_scripts call
s32 evt_get_variable_index(Evt *script, s32 var)
s32 evt_get_variable(Evt *script, Bytecode var)
void draw_entity_model_A(s32, Mtx *)
void draw_entity_model_B(s32, Mtx *, s32, Vec3s *)
u32 dma_copy(Addr romStart, Addr romEnd, void *vramDest)
void exec_entity_model_commandlist(s32 idx)
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)
void load_mesh_animator_tree(s32 index, StaticAnimatorNode **tree)
s32 create_model_animator(s16 *animPos)
s32 test_ray_entities(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 *hitX, f32 *hitY, f32 *hitZ, f32 *hitDepth, f32 *hitNx, f32 *hitNy, f32 *hitNz)
Test a general ray from a given starting position and direction against all entities.
void bind_entity_model_setupGfx(s32 idx, void *setupGfxCallbackArg0, void(*fpSetupGfxCallback)(void *))
s32 test_ray_colliders(s32 ignoreFlags, f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 *hitX, f32 *hitY, f32 *hitZ, f32 *hitDepth, f32 *hitNx, f32 *hitNy, f32 *hitNz)
s32 does_script_exist(s32 id)
s32 create_mesh_animator(s16 *animPos, s16 *animBuffer)
s8 get_current_partner_id(void)
void free_entity_model_by_index(s32 idx)
void load_model_animator_tree(s32, StaticAnimatorNode **)
void * heap_malloc(s32 size)
BSS u8 WorldEntityHeapBase[0x10]
void render_animated_model_with_vertices(s32 animatorID, Mtx *rootTransform, s32 segment, void *baseAddr)
ModelAnimator * set_animator_render_callback(s32 animModelID, void *callbackArg, void(*callbackFunc)(void *))
void render_animated_model(s32 animatorID, Mtx *rootTransform)
void delete_model_animator(ModelAnimator *animator)
ModelAnimator * get_animator_by_index(s32 animModelID)
void update_model_animator(s32)
void sfx_play_sound(s32 soundID)
ApiStatus AssignCrateFlag(Evt *script, b32 isInitialCall)
ApiStatus AssignChestFlag(Evt *script, b32 isInitialCall)
ApiStatus SetEntityCullMode(Evt *script, b32 isInitialCall)
ApiStatus UseDynamicShadow(Evt *script, b32 isInitialCall)
ApiStatus AssignBlockFlag(Evt *script, b32 isInitialCall)
ApiStatus AssignSwitchFlag(Evt *script, b32 isInitialCall)
ApiStatus AssignPanelFlag(Evt *script, b32 isInitialCall)
ApiStatus AssignScript(Evt *script, b32 isInitialCall)
ApiStatus MakeEntity(Evt *script, b32 isInitialCall)
Creates an entity.
#define DMA_COPY_SEGMENT(segment)
#define COLLISION_WITH_ENTITY_BIT
EntityCallback fpHandleCollision
void * updateEntityScript
void * modelAnimationNodes
void(* fpInit)(struct Entity *)
void(* fpSetupGfxCallback)(void *)
EntityCallback updateMatrixOverride
Matrix4f inverseTransformMatrix
EntityCallback updateScriptCallback
void(* renderSetupFunc)(s32)
EntityBlueprint * blueprint
EvtScript * boundScriptBytecode
struct StaticAnimatorNode ** animModelNode
u8 Addr[]
Linker symbol address, as in ld_addrs.h.
PlayerStatus * gPlayerStatusPtr
CollisionStatus gCollisionStatus
GameStatus * gGameStatusPtr
PlayerStatus gPlayerStatus
s32 get_area_flag(s32 index)