diff --git a/asm/src/code_08003FC4.s b/asm/src/code_08003FC4.s index ff872eb4..cf5a3f86 100644 --- a/asm/src/code_08003FC4.s +++ b/asm/src/code_08003FC4.s @@ -348,8 +348,8 @@ sub_080041E8: @ 0x080041E8 subs r0, r0, r2 subs r1, r1, r3 - thumb_func_start sub_080041EC -sub_080041EC: @ 0x080041EC + thumb_func_start CalcDistance +CalcDistance: @ 0x080041EC adds r2, r0, #0 muls r0, r2, r0 adds r3, r1, #0 diff --git a/asm/src/code_080043E8.s b/asm/src/code_080043E8.s index 3d723136..fa2ddead 100644 --- a/asm/src/code_080043E8.s +++ b/asm/src/code_080043E8.s @@ -301,8 +301,8 @@ CalculateDirectionTo: @ 0x080045D4 ldr r3, _08004694 @ =ram_CalcCollisionDirection bx r3 - non_word_aligned_thumb_func_start sub_080045DA -sub_080045DA: @ 0x080045DA + non_word_aligned_thumb_func_start CalcOffsetAngle +CalcOffsetAngle: @ 0x080045DA push {r0, r1, r4, r5, r6, lr} movs r6, #0x40 cmp r0, #0 diff --git a/data/animations/npc/npc5.s b/data/animations/npc/npc5.s index 7bd4a442..fab530f9 100644 --- a/data/animations/npc/npc5.s +++ b/data/animations/npc/npc5.s @@ -339,7 +339,7 @@ gUnk_0810B65C:: @ 0810B65C gUnk_0810B65E:: @ 0810B65E .incbin "npc5/gUnk_0810B65E.bin" -gUnk_0810B660:: @ 0810B660 +gZeldaFollowerText:: @ 0810B660 .4byte gUnk_0810B650 .4byte gUnk_0810B652 .4byte gUnk_0810B654 diff --git a/include/asm.h b/include/asm.h index a6c7db62..d42458ee 100644 --- a/include/asm.h +++ b/include/asm.h @@ -39,7 +39,7 @@ extern void ResetCollisionLayer(struct Entity_*); extern void sub_08004596(struct Entity_*, u32); extern u32 sub_080045B4(struct Entity_*, u32, u32); extern u32 CalculateDirectionTo(u32, u32, u32, u32); -extern u32 sub_080045DA(s32, s32); +extern u32 CalcOffsetAngle(s32, s32); extern u32 sub_080086B4(u32, u32, const u8*); extern u32 ResolveCollisionLayer(struct Entity_*); extern void sub_0800417E(struct Entity_*, u32); diff --git a/src/enemy/enemy64.c b/src/enemy/enemy64.c index be47abc9..c929ae8d 100644 --- a/src/enemy/enemy64.c +++ b/src/enemy/enemy64.c @@ -189,7 +189,7 @@ void Enemy64_Action2_SubAction0(Enemy64Entity* this) { } void Enemy64_Action2_SubAction1(Enemy64Entity* this) { - u32 tmp = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + u32 tmp = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); if (4 < (((super->direction - tmp) + 2) & 0xff)) { if (((tmp - super->direction) & 0x80) != 0) { super->direction--; @@ -290,7 +290,7 @@ void Enemy64_Action3(Enemy64Entity* this) { } void Enemy64_Action3_SubAction0(Enemy64Entity* this) { - u32 tmp = sub_080045DA(gRoomControls.origin_x + 0xa8 - super->x.HALF.HI, + u32 tmp = CalcOffsetAngle(gRoomControls.origin_x + 0xa8 - super->x.HALF.HI, gRoomControls.origin_y + 0x80 - super->y.HALF.HI); if (tmp != super->direction) { if (((tmp - super->direction) & 0x80) != 0) { @@ -490,7 +490,7 @@ void sub_080499F0(Enemy64Entity* this) { ((this->unk_7c & 1) == 0)) { if (EntityWithinDistance(&gPlayerEntity.base, super->x.HALF.HI, super->y.HALF.HI, 0x24) && ((this->unk_7c & 2) == 0)) { - tmp = sub_080045DA((s32)gPlayerEntity.base.x.HALF.HI - super->x.HALF.HI, + tmp = CalcOffsetAngle((s32)gPlayerEntity.base.x.HALF.HI - super->x.HALF.HI, (s32)gPlayerEntity.base.y.HALF.HI - super->y.HALF.HI); gPlayerEntity.base.x.WORD = super->x.WORD + gSineTable[tmp] * 0x2400; gPlayerEntity.base.y.WORD = super->y.WORD + gSineTable[tmp + 0x40] * -0x2400; diff --git a/src/enemy/gyorgMale.c b/src/enemy/gyorgMale.c index 40c43de4..30a4273f 100644 --- a/src/enemy/gyorgMale.c +++ b/src/enemy/gyorgMale.c @@ -260,7 +260,7 @@ void sub_08046AE8(GyorgMaleEntity* this) { } void sub_08046B18(GyorgMaleEntity* this) { - u32 tmp = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + u32 tmp = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); if (tmp != super->direction) { if (((tmp - super->direction) & 0xFF) > 0x80) { this->unk_76 -= 0x100; @@ -283,13 +283,13 @@ void sub_08046B8C(GyorgMaleEntity* this) { this->unk_82 = gRoomControls.origin_y + 0x210; sub_08047D88(this); } else { - super->direction = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + super->direction = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); sub_08047DF0(this, ((0x100 - super->direction) & 0xFF) << 8); } } void sub_08046C04(GyorgMaleEntity* this) { - u32 tmp = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + u32 tmp = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); if (tmp != super->direction) { if (((tmp - super->direction) & 0xFF) > 0x80) { this->unk_76 -= 0x100; @@ -311,7 +311,7 @@ void sub_08046C88(GyorgMaleEntity* this) { sub_08048178(this, sub_08048158(this->unk_70)); sub_08047D88(this); } else { - super->direction = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + super->direction = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); sub_08047DF0(this, ((0x100 - super->direction) & 0xFF) << 8); } } @@ -348,7 +348,7 @@ void sub_08046D44(GyorgMaleEntity* this) { } void sub_08046D98(GyorgMaleEntity* this) { - u32 tmp = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + u32 tmp = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); if (tmp != super->direction) { if (((tmp - super->direction) & 0xFF) > 0x80) { this->unk_76 -= 0x100; @@ -369,7 +369,7 @@ void sub_08046E0C(GyorgMaleEntity* this) { this->unk_76 = super->direction << 8; sub_08047D88(this); } else { - super->direction = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + super->direction = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); sub_08047DF0(this, ((0x100 - super->direction) & 0xFF) << 8); } } @@ -456,7 +456,7 @@ void sub_08046FE8(GyorgMaleEntity* this) { } void sub_0804702C(GyorgMaleEntity* this) { - u32 tmp = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + u32 tmp = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); if (((super->direction - tmp + 2) & 0xFF) > 4) { if ((tmp - super->direction) & 0x80) { super->direction--; @@ -607,7 +607,7 @@ void sub_080473B8(GyorgMaleEntity* this) { } void sub_080473F0(GyorgMaleEntity* this) { - u32 tmp = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + u32 tmp = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); if (((super->direction - tmp + 2) & 0xFF) > 4) { s32 tmp2 = tmp - super->direction; if (tmp2 & 0x80) { @@ -791,7 +791,7 @@ void sub_080477F0(GyorgMaleEntity* this) { if (super->speed < 0x300) { super->speed += 8; } - super->direction = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + super->direction = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); sub_08047E48(this); if (!EntityWithinDistance(super, gPlayerEntity.base.x.HALF.HI, gPlayerEntity.base.y.HALF.HI, 0x80)) { super->action = 2; @@ -896,7 +896,7 @@ void sub_08047978(GyorgMaleEntity* this) { void sub_08047B08(GyorgMaleEntity* this) { sub_08047D88(this); - super->direction = sub_080045DA(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); + super->direction = CalcOffsetAngle(this->unk_80 - super->x.HALF.HI, this->unk_82 - super->y.HALF.HI); super->speed = 0x200; sub_08047E58(this); if (!EntityWithinDistance(super, this->unk_80, this->unk_82, 4)) @@ -1066,7 +1066,7 @@ void sub_08047EA4(GyorgMaleEntity* this, u32 unk1) { return; if (this->unk_7c & 1) { tmp2 = sub_08047F68(this) << 8; - dir = sub_080045DA(gPlayerEntity.base.x.HALF.HI - super->x.HALF.HI, + dir = CalcOffsetAngle(gPlayerEntity.base.x.HALF.HI - super->x.HALF.HI, gPlayerEntity.base.y.HALF.HI - super->y.HALF.HI); tmp = dir - (tmp / 256); tmp &= 0xFF; @@ -1149,7 +1149,7 @@ void sub_08048004(GyorgMaleEntity* this) { if (b != 3) { if (EntityWithinDistance(&gPlayerEntity.base, super->x.HALF.HI, super->y.HALF.HI, 0x24)) { if (!(this->unk_7c & 2)) { - u32 tmp = sub_080045DA(gPlayerEntity.base.x.HALF.HI - super->x.HALF.HI, + u32 tmp = CalcOffsetAngle(gPlayerEntity.base.x.HALF.HI - super->x.HALF.HI, gPlayerEntity.base.y.HALF.HI - super->y.HALF.HI); gPlayerEntity.base.x.WORD = super->x.WORD + (gSineTable[tmp] * 9216); gPlayerEntity.base.y.WORD = super->y.WORD - (gSineTable[tmp + 0x40] * 9216); diff --git a/src/enemy/octorokBoss.c b/src/enemy/octorokBoss.c index 762ba7e2..1279f133 100644 --- a/src/enemy/octorokBoss.c +++ b/src/enemy/octorokBoss.c @@ -167,11 +167,11 @@ void OctorokBoss_Hit_SubAction1(OctorokBossEntity* this) { if (diffX > 8 || diffY > 8) { this->heap->field_0x2 = 1; #if defined(JP) || defined(DEMO_JP) || defined(EU) - super->direction = ((s32)sub_080045DA((((gRoomControls.origin_x + 0x108) << 0x10) - super->x.WORD), + super->direction = ((s32)CalcOffsetAngle((((gRoomControls.origin_x + 0x108) << 0x10) - super->x.WORD), (((gRoomControls.origin_y + 0x88) << 0x10) - super->y.WORD))) >> 3; #else - super->direction = ((s32)sub_080045DA(gRoomControls.origin_x + 0x108 - super->x.HALF.HI, + super->direction = ((s32)CalcOffsetAngle(gRoomControls.origin_x + 0x108 - super->x.HALF.HI, gRoomControls.origin_y + 0x88 - super->y.HALF.HI)) >> 3; #endif @@ -689,7 +689,7 @@ void OctorokBoss_Action1_AimTowardsPlayer(OctorokBossEntity* this) { s32 tmp1; s32 tmp2; - tmp1 = (u8)(sub_080045DA(gPlayerEntity.base.x.WORD - super->x.WORD, gPlayerEntity.base.y.WORD - super->y.WORD) - + tmp1 = (u8)(CalcOffsetAngle(gPlayerEntity.base.x.WORD - super->x.WORD, gPlayerEntity.base.y.WORD - super->y.WORD) - (((u8)(-this->angle.HALF.HI) ^ 0x80))); if (IS_FROZEN(this) == FALSE) { tmp2 = 8; @@ -898,7 +898,7 @@ void OctorokBoss_ExecuteAttackVacuum(OctorokBossEntity* this) { if (this->unk_80 == 0) { super->direction = - sub_080045DA(gPlayerEntity.base.x.WORD - super->x.WORD, gPlayerEntity.base.y.WORD - super->y.WORD); + CalcOffsetAngle(gPlayerEntity.base.x.WORD - super->x.WORD, gPlayerEntity.base.y.WORD - super->y.WORD); tmp = ((u8) - (this->angle.HALF.HI + 0x80)) - super->direction; if (tmp < 0) { tmp = -tmp; @@ -912,7 +912,7 @@ void OctorokBoss_ExecuteAttackVacuum(OctorokBossEntity* this) { this->unk_80 = 1; this->timer = 2; this->heap->targetAngle = - sub_080045DA((gRoomControls.origin_x + 0x108) * 0x10000 - super->x.WORD, + CalcOffsetAngle((gRoomControls.origin_x + 0x108) * 0x10000 - super->x.WORD, (gRoomControls.origin_y + 0x88) * 0x10000 - super->y.WORD); this->heap->targetAngle = (u8) - (this->heap->targetAngle + 0x80); SoundReq(SFX_ED); @@ -956,7 +956,7 @@ void OctorokBoss_ExecuteAttackVacuum(OctorokBossEntity* this) { } else { this->timer--; if ((gPlayerState.flags == PL_FROZEN) && (this->timer == 0x3c)) { - tmp = sub_080045DA(gPlayerEntity.base.x.WORD - super->x.WORD, gPlayerEntity.base.y.WORD - super->y.WORD); + tmp = CalcOffsetAngle(gPlayerEntity.base.x.WORD - super->x.WORD, gPlayerEntity.base.y.WORD - super->y.WORD); if ((u8)((tmp - ((u8) - this->angle.HALF.HI ^ 0x80))) > 0x80) { this->heap->targetAngle = this->angle.HALF.HI + 0x30; } else { @@ -1178,7 +1178,7 @@ void sub_08036AF0(OctorokBossEntity* this, s32 radius, s32 angleSpeed) { continue; } else { heap->tailObjects[index - 1]->angle.HALF.HI = - sub_080045DA(heap->tailObjects[index - 1]->base.x.WORD - heap->tailObjects[index]->base.x.WORD, + CalcOffsetAngle(heap->tailObjects[index - 1]->base.x.WORD - heap->tailObjects[index]->base.x.WORD, heap->tailObjects[index - 1]->base.y.WORD - heap->tailObjects[index]->base.y.WORD); tmp = FixedMul(gSineTable[heap->tailObjects[index - 1]->angle.HALF.HI], radius << 4); tmp = FixedDiv(tmp, 0x100); diff --git a/src/npc/ezlo.c b/src/npc/ezlo.c index b80078cb..26de89ef 100644 --- a/src/npc/ezlo.c +++ b/src/npc/ezlo.c @@ -38,7 +38,7 @@ void sub_0806D8A0(Entity* this, ScriptExecutionContext* context) { context->y.HALF.HI = yOffset; xOffset -= this->x.HALF.HI; - this->direction = sub_080045DA(xOffset, yOffset - this->y.HALF.HI); + this->direction = CalcOffsetAngle(xOffset, yOffset - this->y.HALF.HI); this->animationState = (this->animationState & 0x80) | gUnk_08114134[this->direction >> 4]; } diff --git a/src/npc/gorman.c b/src/npc/gorman.c index d4a8683a..bb679c80 100644 --- a/src/npc/gorman.c +++ b/src/npc/gorman.c @@ -154,7 +154,7 @@ void sub_0806991C(GormanEntity* this, ScriptExecutionContext* context) { context->unk_19 = 8; context->postScriptActions |= 2; context->condition = 0; - tmp = sub_080045DA(context->x.HALF.HI - super->x.HALF.HI, context->y.HALF.HI - super->y.HALF.HI); + tmp = CalcOffsetAngle(context->x.HALF.HI - super->x.HALF.HI, context->y.HALF.HI - super->y.HALF.HI); super->direction = tmp; super->animationState = (super->animationState & 0x80) | gUnk_08111C74[(tmp << 0x18) >> 0x1c]; gActiveScriptInfo.flags |= 1; @@ -170,7 +170,7 @@ void sub_080699AC(GormanEntity* this, ScriptExecutionContext* context) { context->unk_19 = 8; context->postScriptActions |= 2; context->condition = 0; - tmp = sub_080045DA(context->x.HALF.HI - super->x.HALF.HI, context->y.HALF.HI - super->y.HALF.HI); + tmp = CalcOffsetAngle(context->x.HALF.HI - super->x.HALF.HI, context->y.HALF.HI - super->y.HALF.HI); super->direction = tmp; super->animationState = (super->animationState & 0x80) | gUnk_08111C8C[(tmp << 0x18) >> 0x1c]; gActiveScriptInfo.flags |= 1; diff --git a/src/npc/kid.c b/src/npc/kid.c index 0faaac1b..fd51fd2f 100644 --- a/src/npc/kid.c +++ b/src/npc/kid.c @@ -524,7 +524,7 @@ void sub_080626E0(Entity* this, ScriptExecutionContext* context) { } if (--context->unk_19 == 0) { context->unk_19 = 10; - uVar4 = sub_080045DA(context->x.HALF.HI - this->x.HALF.HI, context->y.HALF.HI - this->y.HALF.HI); + uVar4 = CalcOffsetAngle(context->x.HALF.HI - this->x.HALF.HI, context->y.HALF.HI - this->y.HALF.HI); this->direction = (u8)uVar4; uVar4 = Random(); this->direction = (this->direction + uVar4 % 0xb) - 5; diff --git a/src/npc/npc5.c b/src/npc/npc5.c index b6b17ca6..d266d96c 100644 --- a/src/npc/npc5.c +++ b/src/npc/npc5.c @@ -10,86 +10,112 @@ #include "message.h" #include "npc.h" +#define kFollowDistance 32 // distance to follow player +#define kPoiDistance 4 // point of interest distance +#define kGravity Q_8_8(32.0) + +#define kCloseDistance 48 // distance to player to walk slowly +#define kFarDistance 80 // distance to player to walk fast +#define kCloseSpeed 0x120 // speed when close to player +#define kMidSpeed 0x160 // speed when mid distance from player +#define kFarSpeed 0x220 // speed when far from player +#define kNavigateSpeed 0x1e0 // speed when navigating + +#define FLAG_FLINCHING 0x1 +#define FLAG_GOTO_PLAYER 0x2 +#define FLAG_GOTO_JUMPED 0x4 +#define FLAG_NAVIGATE 0x8 + +typedef enum { + ZELDA_STATE_INIT, + ZELDA_STATE_IDLE, + ZELDA_STATE_FOLLOW, + ZELDA_STATE_LOST, + ZELDA_STATE_ANIM_SCRIPTED, + ZELDA_STATE_WALK_PRE_JUMP, + ZELDA_STATE_JUMP, + ZELDA_STATE_LAND, +} ZeldaState; + +#define HEAP ((ZeldaData*)super->myHeap) + typedef struct { /*0x00*/ Entity base; - /*0x68*/ u16* unk_68; - /*0x6c*/ u8 unk_6c; + /*0x68*/ u16* messageData; + /*0x6c*/ u8 baseAnimation; /*0x6d*/ u8 unused1; - /*0x6e*/ u16 unk_6e; + /*0x6e*/ u16 linear_move_dist; /*0x70*/ u8 unused2[4]; - /*0x74*/ u16 unk_74; + /*0x74*/ u16 currentRoom; /*0x76*/ u8 unused3[2]; - /*0x78*/ Entity* unk_78; + /*0x78*/ Entity* interactEntity; } NPC5Entity; typedef struct { - u8 unk_0; // u8 - u8 unk_0b; // u8 - u16 unk_1; // u16 - u16 unk_2; // u16 - u16 unk_3; - u16 unk_4; - u16 unk_5; // u16 - u16 unk_6; // u16 - u16 unk_7; // u16 - u16 unk_8; // u16 -} UnkHeap; + u8 flags; // u8 + u8 followDistance; // u8 + u16 playerX; // u16 + u16 playerY; // u16 + u16 destX; + u16 destY; + u16 playerJumpedX; // u16 + u16 playerJumpedY; // u16 + u16 navX; // u16 + u16 navY; // u16 +} ZeldaData; -void sub_08060E70(NPC5Entity*, u32); +void ZeldaSetAnim(NPC5Entity*, u32); -u32 sub_08061230(NPC5Entity*); -u32 sub_08060F80(Entity*); -void sub_08060EDC(NPC5Entity*); -void sub_08061090(NPC5Entity*, u32, u32); +u32 CheckIsFlinching(NPC5Entity*); +u32 ZeldaAtDestination(Entity*); +void ZeldaUpdateIdleAnim(NPC5Entity*); +void ZeldaCalcWalkSpeed(NPC5Entity*, u32, u32); -bool32 sub_08060FD0(Entity*, u32, u32); -void sub_08061464(NPC5Entity*, u32, u32); -void sub_08061120(NPC5Entity*, u32, u32, u32); -bool32 sub_08061170(NPC5Entity*); +bool32 CheckDirectPathUnblocked(Entity*, u32, u32); +void ZeldaInitNavigate(NPC5Entity*, u32, u32); +void ZeldaCalcWalkAnim(NPC5Entity*, u32, u32, u32); +bool32 ZeldaProcessMovement(NPC5Entity*); -void sub_08061358(NPC5Entity*); -void sub_08060E94(Entity*); -void sub_08060A00(NPC5Entity*); -void sub_08061AA0(NPC5Entity*); -void sub_08061AA8(NPC5Entity*); -void sub_08061B58(NPC5Entity*); -void sub_08060AE0(NPC5Entity*); -void sub_08060B5C(NPC5Entity*); -void sub_08060BA0(NPC5Entity*); -void sub_08060D78(NPC5Entity*); -void sub_08060DD0(NPC5Entity*); -void sub_08060DF4(NPC5Entity*); -void sub_08060DFC(NPC5Entity*); -void sub_08060E34(NPC5Entity*); +void ZeldaDoLostAnim(NPC5Entity*); +void ZeldaUpdateAnim(Entity*); +void ZeldaType0Init(NPC5Entity*); +void ZeldaType1Init(NPC5Entity*); +void ZeldaType2Init(NPC5Entity*); +void ZeldaType3Init(NPC5Entity*); +void ZeldaInitAction(NPC5Entity*); +void ZeldaIdleAction(NPC5Entity*); +void ZeldaFollowAction(NPC5Entity*); +void ZeldaLostAction(NPC5Entity*); +void ZeldaAnimScripted(NPC5Entity*); +void ZeldaWalkPreJump(NPC5Entity*); +void ZeldaJumpAction(NPC5Entity*); +void ZeldaLandAction(NPC5Entity*); void sub_08061ACC(NPC5Entity*); void sub_08061B18(NPC5Entity*); u32 PointInsideRadius(s32, s32, s32); -u32 sub_080611D4(Entity*); +u32 CalcJumpDirection(Entity*); extern u32 sub_08079FD4(Entity*, u32); extern void UpdateCollisionLayer(Entity*); -bool32 sub_08061630(NPC5Entity*, s32, s32, s32); -bool32 sub_08061720(NPC5Entity*, s32, s32, s32); -bool32 sub_080616A8(NPC5Entity*, s32, s32, s32); -bool32 sub_08061798(NPC5Entity*, s32, s32, s32); -bool32 sub_08061888(NPC5Entity*, s32, s32, s32); -bool32 sub_08061978(NPC5Entity*, s32, s32, s32); -bool32 sub_08061810(NPC5Entity*, s32, s32, s32); -bool32 sub_08061900(NPC5Entity*, s32, s32, s32); +bool32 TryNavRightFromAbove(NPC5Entity*, s32, s32, s32); +bool32 TryNavUpFromRight(NPC5Entity*, s32, s32, s32); +bool32 TryNavLeftFromAbove(NPC5Entity*, s32, s32, s32); +bool32 TryNavBelowFromRight(NPC5Entity*, s32, s32, s32); +bool32 TryNavLeftFromBelow(NPC5Entity*, s32, s32, s32); +bool32 TryNavBelowFromLeft(NPC5Entity*, s32, s32, s32); +bool32 TryNavRightFromBelow(NPC5Entity*, s32, s32, s32); +bool32 TryNavUpFromLeft(NPC5Entity*, s32, s32, s32); -bool32 sub_08061A74(u8*, s32, s32, s32); - -bool32 sub_08061A1C(u8*, s32, s32, s32); - -bool32 sub_080619F0(u8*, s32, s32, s32); - -bool32 sub_08061A48(u8*, s32, s32, s32); +bool32 CheckPathRight(u8*, s32, s32, s32); +bool32 CheckPathLeft(u8*, s32, s32, s32); +bool32 CheckPathUp(u8*, s32, s32, s32); +bool32 CheckPathBelow(u8*, s32, s32, s32); void sub_08061AFC(NPC5Entity*); -extern u16* gUnk_0810B660[8]; +extern u16* gZeldaFollowerText[8]; void CreateZeldaFollower(void) { Entity* npc; @@ -106,61 +132,62 @@ void CreateZeldaFollower(void) { // UNUSED zelda follower, probably because it was too resource heavy void NPC5(NPC5Entity* this) { static void (*const gUnk_0810AC1C[])(NPC5Entity*) = { - sub_08060A00, - sub_08061AA0, - sub_08061AA8, - sub_08061B58, + ZeldaType0Init, + ZeldaType1Init, + ZeldaType2Init, + ZeldaType3Init, }; gUnk_0810AC1C[super->type](this); } -void sub_08060A00(NPC5Entity* this) { +void ZeldaType0Init(NPC5Entity* this) { static void (*const Npc5_Actions[])(NPC5Entity*) = { - sub_08060AE0, sub_08060B5C, sub_08060BA0, sub_08060D78, sub_08060DD0, sub_08060DF4, sub_08060DFC, sub_08060E34, + ZeldaInitAction, ZeldaIdleAction, ZeldaFollowAction, ZeldaLostAction, + ZeldaAnimScripted, ZeldaWalkPreJump, ZeldaJumpAction, ZeldaLandAction, }; u32 tmp; - if ((gPlayerState.jump_status & 0x80) != 0) { - if (super->action != 0) { - if (((((UnkHeap*)super->myHeap)->unk_0) & 4) == 0) { - ((UnkHeap*)super->myHeap)->unk_0 |= 4; - ((UnkHeap*)super->myHeap)->unk_5 = (gPlayerEntity.base.x.HALF.HI & 0xfff0) + 8; - ((UnkHeap*)super->myHeap)->unk_6 = (gPlayerEntity.base.y.HALF.HI & 0xfff0) + 8; + if (gPlayerState.jump_status & 0x80) { + if (super->action != ZELDA_STATE_INIT) { + if ((HEAP->flags & FLAG_GOTO_JUMPED) == 0) { + HEAP->flags |= FLAG_GOTO_JUMPED; + HEAP->playerJumpedX = (gPlayerEntity.base.x.HALF.HI & 0xfff0) + 8; + HEAP->playerJumpedY = (gPlayerEntity.base.y.HALF.HI & 0xfff0) + 8; } } } - if ((super->action == 0) || (super->spriteSettings.draw != 0)) { + if ((super->action == ZELDA_STATE_INIT) || (super->spriteSettings.draw != 0)) { Npc5_Actions[super->action](this); } - if (super->action != 0) { - ((UnkHeap*)super->myHeap)->unk_1 = gPlayerEntity.base.x.HALF.HI; - ((UnkHeap*)super->myHeap)->unk_2 = gPlayerEntity.base.y.HALF.HI; + if (super->action != ZELDA_STATE_INIT) { + HEAP->playerX = gPlayerEntity.base.x.HALF.HI; + HEAP->playerY = gPlayerEntity.base.y.HALF.HI; } - if (this->unk_74 != gRoomControls.room) { - this->unk_74 = gRoomControls.room; + if (this->currentRoom != gRoomControls.room) { + this->currentRoom = gRoomControls.room; CopyPosition(&gPlayerEntity.base, super); - super->action = 1; + super->action = ZELDA_STATE_IDLE; super->spriteSettings.draw = 1; - super->speed = 0x120; + super->speed = kCloseSpeed; tmp = gRoomControls.scroll_direction; super->animationState = tmp * 2; InitAnimationForceUpdate(super, tmp << 0x19 >> 0x19); // TODO some conversion between u8 and u32? super->frameDuration = (Random() & 0x7f) + 0x80; - ((UnkHeap*)super->myHeap)->unk_0 &= 0xfb; + HEAP->flags &= ~FLAG_GOTO_JUMPED; } } -void sub_08060AE0(NPC5Entity* this) { - UnkHeap* heapObj; +void ZeldaInitAction(NPC5Entity* this) { + ZeldaData* heapObj; Entity* otherNpc; - heapObj = (UnkHeap*)zMalloc(0x14); // TODO UnkHeap struct should have size 0x14? + heapObj = (ZeldaData*)zMalloc(sizeof(ZeldaData)); if (heapObj != NULL) { super->myHeap = (u32*)heapObj; - heapObj->unk_0b = 0x20; - super->action = 1; + heapObj->followDistance = kFollowDistance; + super->action = ZELDA_STATE_IDLE; COLLISION_ON(super); super->animationState &= 3; super->collisionFlags = 7; @@ -168,167 +195,172 @@ void sub_08060AE0(NPC5Entity* this) { super->hitType = 0x49; super->collisionMask = 3; super->hitbox = (Hitbox*)&gHitbox_0; - super->followerFlag &= 0xfe; - this->unk_6c = 0xff; - sub_08060E70(this, super->animationState); + super->followerFlag &= ~1; + this->baseAnimation = 0xff; + ZeldaSetAnim(this, super->animationState); otherNpc = CreateNPC(NPC_UNK_5, 2, 0); if (otherNpc != NULL) { otherNpc->parent = super; - this->unk_78 = otherNpc; + this->interactEntity = otherNpc; } } } -void sub_08060B5C(NPC5Entity* this) { - if (sub_08061230(this) == 0) { - if ((sub_08060F80(super) == 0) && - (((GetFacingDirection(super, &gPlayerEntity.base) + (super->animationState * -4) + 4) & 0x1f)) < 9) { - super->action = 2; - super->subtimer = 0; - return; - } - sub_08060EDC(this); +void ZeldaIdleAction(NPC5Entity* this) { + if (CheckIsFlinching(this)) { + return; } + + if (!ZeldaAtDestination(super) && + DirectionNormalize(GetFacingDirection(super, &gPlayerEntity.base) + (super->animationState * -4) + 4) < 9) { + super->action = ZELDA_STATE_FOLLOW; + super->subtimer = 0; + return; + } + ZeldaUpdateIdleAnim(this); } -void sub_08060BA0(NPC5Entity* this) { +void ZeldaFollowAction(NPC5Entity* this) { Entity* r5; //! @bug: r5 is uninitialized - if (sub_08061230(this) != 0) { + if (CheckIsFlinching(this)) { return; } - if ((((UnkHeap*)super->myHeap)->unk_0 & 4) != 0) { - if ((((UnkHeap*)super->myHeap)->unk_0 & 8) != 0) { - super->speed = 0x1e0; - sub_08061120(this, ((UnkHeap*)super->myHeap)->unk_7, ((UnkHeap*)super->myHeap)->unk_8, 0xc); - sub_08061170(this); - if (EntityWithinDistance(super, ((UnkHeap*)super->myHeap)->unk_7, ((UnkHeap*)super->myHeap)->unk_8, 4) != - 0) { - ((UnkHeap*)super->myHeap)->unk_0 &= 0xf7; - } - } else { - if (sub_08060FD0(super, ((UnkHeap*)super->myHeap)->unk_5, ((UnkHeap*)super->myHeap)->unk_6) != 0) { - if (EntityWithinDistance(super, ((UnkHeap*)super->myHeap)->unk_5, ((UnkHeap*)super->myHeap)->unk_6, - 4) != 0) { - ((UnkHeap*)super->myHeap)->unk_0 &= 0xfb; - super->action = 5; - super->direction = r5->direction; - super->speed = 0x160; - sub_08060E70(this, 8); - } else { - super->speed = 0x1e0; - sub_08061120(this, r5->x.HALF.HI, r5->y.HALF.HI, 0xc); - sub_08061170(this); - } - } else { - sub_08061464(this, r5->x.HALF.HI, r5->y.HALF.HI); - } - } - } else { - if (sub_08060FD0(super, gPlayerEntity.base.x.HALF.HI, gPlayerEntity.base.y.HALF.HI) != 0) { - sub_08061090(this, gPlayerEntity.base.x.HALF.HI, gPlayerEntity.base.y.HALF.HI); - sub_08061170(this); - ((UnkHeap*)super->myHeap)->unk_0 &= 0xf5; - } else { - ((UnkHeap*)super->myHeap) = (UnkHeap*)super->myHeap; - if ((((UnkHeap*)super->myHeap)->unk_0 & 8) != 0) { - super->speed = 0x1e0; - sub_08061120(this, ((UnkHeap*)super->myHeap)->unk_7, ((UnkHeap*)super->myHeap)->unk_8, 0xc); - sub_08061170(this); - if (EntityWithinDistance(super, ((UnkHeap*)super->myHeap)->unk_7, ((UnkHeap*)super->myHeap)->unk_8, - 4) != 0) { - ((UnkHeap*)super->myHeap)->unk_0 &= 0xf7; - } - } else { - if ((((UnkHeap*)super->myHeap)->unk_0 & 2) == 0) { - ((UnkHeap*)super->myHeap)->unk_0 |= 2; - ((UnkHeap*)super->myHeap)->unk_3 = ((UnkHeap*)super->myHeap)->unk_1; - ((UnkHeap*)super->myHeap)->unk_4 = ((UnkHeap*)super->myHeap)->unk_2; - } - if (sub_08060FD0(super, ((UnkHeap*)super->myHeap)->unk_3, ((UnkHeap*)super->myHeap)->unk_4) != 0) { - super->speed = 0x1e0; - sub_08061120(this, ((UnkHeap*)super->myHeap)->unk_3, ((UnkHeap*)super->myHeap)->unk_4, 0xc); - sub_08061170(this); - if (EntityWithinDistance(super, ((UnkHeap*)super->myHeap)->unk_3, ((UnkHeap*)super->myHeap)->unk_4, - 4) != 0) { - ((UnkHeap*)super->myHeap)->unk_0 &= 0xfd; - } - } else { - ((UnkHeap*)super->myHeap)->unk_0 &= 0xfd; - sub_08061464(this, gPlayerEntity.base.x.HALF.HI, gPlayerEntity.base.y.HALF.HI); - } + if (HEAP->flags & FLAG_GOTO_JUMPED) { + // goto position where player jumped + if (HEAP->flags & FLAG_NAVIGATE) { + // navigate to jump position + super->speed = kNavigateSpeed; + ZeldaCalcWalkAnim(this, HEAP->navX, HEAP->navY, 0xc); + ZeldaProcessMovement(this); + if (EntityWithinDistance(super, HEAP->navX, HEAP->navY, kPoiDistance)) { + // reached navigation position + HEAP->flags &= ~FLAG_NAVIGATE; } + } else if (CheckDirectPathUnblocked(super, HEAP->playerJumpedX, HEAP->playerJumpedY)) { + // At jump location, begin jumping + if (EntityWithinDistance(super, HEAP->playerJumpedX, HEAP->playerJumpedY, kPoiDistance)) { + HEAP->flags &= ~FLAG_GOTO_JUMPED; + super->action = ZELDA_STATE_WALK_PRE_JUMP; + super->direction = r5->direction; + super->speed = kMidSpeed; + ZeldaSetAnim(this, 8); + } else { + // walk to jump location + super->speed = kNavigateSpeed; + ZeldaCalcWalkAnim(this, r5->x.HALF.HI, r5->y.HALF.HI, 0xc); + ZeldaProcessMovement(this); + } + } else { + // navigate to jump location (bugged) + ZeldaInitNavigate(this, r5->x.HALF.HI, r5->y.HALF.HI); + } + } else if (CheckDirectPathUnblocked(super, gPlayerEntity.base.x.HALF.HI, gPlayerEntity.base.y.HALF.HI)) { + // walk directly to player + ZeldaCalcWalkSpeed(this, gPlayerEntity.base.x.HALF.HI, gPlayerEntity.base.y.HALF.HI); + ZeldaProcessMovement(this); + HEAP->flags &= ~(FLAG_NAVIGATE | FLAG_GOTO_PLAYER); + } else if (HEAP->flags & FLAG_NAVIGATE) { + // navigating to a position + super->speed = kNavigateSpeed; + ZeldaCalcWalkAnim(this, HEAP->navX, HEAP->navY, 0xc); + ZeldaProcessMovement(this); + if (EntityWithinDistance(super, HEAP->navX, HEAP->navY, kPoiDistance)) { + // reached navigation position + HEAP->flags &= ~FLAG_NAVIGATE; + } + } else { // player not found and no position set to navigate to + if ((HEAP->flags & FLAG_GOTO_PLAYER) == 0) { + // get player position + HEAP->flags |= FLAG_GOTO_PLAYER; + HEAP->destX = HEAP->playerX; + HEAP->destY = HEAP->playerY; + } + if (CheckDirectPathUnblocked(super, HEAP->destX, HEAP->destY)) { + // can walk directly to player + super->speed = kNavigateSpeed; + ZeldaCalcWalkAnim(this, HEAP->destX, HEAP->destY, 0xc); + ZeldaProcessMovement(this); + if (EntityWithinDistance(super, HEAP->destX, HEAP->destY, kPoiDistance)) { + // reached player position + HEAP->flags &= ~FLAG_GOTO_PLAYER; + } + } else { // try to navigate to player + HEAP->flags &= ~FLAG_GOTO_PLAYER; + ZeldaInitNavigate(this, gPlayerEntity.base.x.HALF.HI, gPlayerEntity.base.y.HALF.HI); } } - if (sub_08060F80(super) != 0) { - super->action = 1; - ((UnkHeap*)super->myHeap)->unk_0 &= 0xfb; - sub_08060E70(this, 0); + + if (ZeldaAtDestination(super)) { + super->action = ZELDA_STATE_IDLE; + HEAP->flags &= ~FLAG_GOTO_JUMPED; + ZeldaSetAnim(this, 0); } } -void sub_08060D78(NPC5Entity* this) { - sub_08061358(this); - if (sub_08060F80(super) != 0) { - if ((u32)super->animIndex - 0x20 < 0x10) { - if ((super->frame & 7) != 0) { - super->frameDuration = 1; - UpdateAnimationSingleFrame(super); - } - super->animationState = super->frame & 0x18; - this->unk_6c = 0xff; - } - super->action = 1; - sub_08060E70(this, 0); +void ZeldaLostAction(NPC5Entity* this) { + ZeldaDoLostAnim(this); + + // wait to be found + if (!ZeldaAtDestination(super)) { + return; } + + if ((u32)super->animIndex - 0x20 < 0x10) { + if ((super->frame & 7) != 0) { + super->frameDuration = 1; + UpdateAnimationSingleFrame(super); + } + super->animationState = super->frame & 0x18; + this->baseAnimation = 0xff; + } + super->action = ZELDA_STATE_IDLE; + ZeldaSetAnim(this, 0); } -void sub_08060DD0(NPC5Entity* this) { +void ZeldaAnimScripted(NPC5Entity* this) { UpdateAnimationSingleFrame(super); - if ((super->frame & ANIM_DONE) != 0) { - super->action = 1; - sub_08060E70(this, 0); + if (super->frame & ANIM_DONE) { + super->action = ZELDA_STATE_IDLE; + ZeldaSetAnim(this, 0); } } -void sub_08060DF4(NPC5Entity* this) { - sub_08061170(this); +void ZeldaWalkPreJump(NPC5Entity* this) { + ZeldaProcessMovement(this); } -void sub_08060DFC(NPC5Entity* this) { - u32 uVar1; - +void ZeldaJumpAction(NPC5Entity* this) { LinearMoveUpdate(super); - sub_08060E94(super); - uVar1 = GravityUpdate(super, Q_8_8(32.0)); - if (uVar1 == 0) { - super->action = 7; + ZeldaUpdateAnim(super); + if (GravityUpdate(super, kGravity) == 0) { + super->action = ZELDA_STATE_LAND; super->collisionLayer = 1; UpdateSpriteForCollisionLayer(super); - sub_08060E70(this, 0x1c); + ZeldaSetAnim(this, 0x1c); } } -void sub_08060E34(NPC5Entity* this) { +void ZeldaLandAction(NPC5Entity* this) { UpdateAnimationSingleFrame(super); - if ((super->frame & ANIM_DONE) != 0) { - super->action = 2; + if (super->frame & ANIM_DONE) { + super->action = ZELDA_STATE_FOLLOW; super->animationState = DirectionToAnimationState(GetFacingDirection(super, &gPlayerEntity.base)) * 2; - sub_08060E70(this, 8); + ZeldaSetAnim(this, 8); } } -void sub_08060E70(NPC5Entity* this, u32 param) { +void ZeldaSetAnim(NPC5Entity* this, u32 param) { u32 tmp = param + super->animationState / 2; if (tmp != super->animIndex) { - this->unk_6c = param; + this->baseAnimation = param; InitAnimationForceUpdate(super, tmp); } } -void sub_08060E94(Entity* this) { +void ZeldaUpdateAnim(Entity* this) { if (((*(u32*)&this->animIndex & 0x80ff00) == 0x800100) && (this->animIndex < 4)) { InitAnimationForceUpdate(this, (this->animationState >> 1)); this->frameDuration = (Random() & 0x7f) + 0x80; @@ -337,80 +369,88 @@ void sub_08060E94(Entity* this) { } } -void sub_08060EDC(NPC5Entity* this) { +void ZeldaUpdateIdleAnim(NPC5Entity* this) { s32 tmp; if (((u32)super->animIndex - 0x20 < 0x10) && ((super->frame & ANIM_DONE) == 0)) { UpdateAnimationSingleFrame(super); - } else { - tmp = GetFacingDirection(super, &gPlayerEntity.base) + super->animationState * -4; - if (((tmp + 3) & 0x1f) >= 7) { - if ((tmp & 0x1f) < 0x10) { - InitAnimationForceUpdate(super, super->animationState + 0x20); - super->animationState = (super->animationState + 1) & 7; - } else { - InitAnimationForceUpdate(super, super->animationState + 0x28); - super->animationState = (super->animationState - 1) & 7; - } + return; + } + + tmp = GetFacingDirection(super, &gPlayerEntity.base) + super->animationState * -4; + if (((tmp + 3) & 0x1f) > 6) { + if ((tmp & 0x1f) < 0x10) { + InitAnimationForceUpdate(super, super->animationState + 0x20); + super->animationState = (super->animationState + 1) & 7; } else { - if ((super->animationState & 1) == 0) { - if (((super->frame & ANIM_DONE) != 0) && (0xf >= (u32)super->animIndex - 0x20)) { - sub_08060E70(this, 0); - } else { - sub_08060E94(super); - } - } + InitAnimationForceUpdate(super, super->animationState + 0x28); + super->animationState = (super->animationState - 1) & 7; + } + return; + } + + if ((super->animationState & 1) == 0) { + if ((super->frame & ANIM_DONE) && (0xf >= (u32)super->animIndex - 0x20)) { + ZeldaSetAnim(this, 0); + } else { + ZeldaUpdateAnim(super); } } } -u32 sub_08060F80(Entity* this) { - if (sub_08060FD0(this, (s32)gPlayerEntity.base.x.HALF.HI, (s32)gPlayerEntity.base.y.HALF.HI) == 0) { + +u32 ZeldaAtDestination(Entity* this) { + if (CheckDirectPathUnblocked(this, (s32)gPlayerEntity.base.x.HALF.HI, (s32)gPlayerEntity.base.y.HALF.HI) == 0) { return 0; } - ((UnkHeap*)this->myHeap)->unk_0 &= 0xfb; + ((ZeldaData*)this->myHeap)->flags &= ~FLAG_GOTO_JUMPED; if (PointInsideRadius(gPlayerEntity.base.x.HALF.HI - this->x.HALF.HI, - gPlayerEntity.base.y.HALF.HI - this->y.HALF.HI, ((UnkHeap*)this->myHeap)->unk_0b) != 0) { + gPlayerEntity.base.y.HALF.HI - this->y.HALF.HI, ((ZeldaData*)this->myHeap)->followDistance)) { return 1; } return 0; } -bool32 sub_08060FD0(Entity* this, u32 a, u32 b) { - s32 sVar1; - s32 sVar2; - int iVar3; +bool32 CheckDirectPathUnblocked(Entity* this, u32 target_x, u32 target_y) { + s32 dx; + s32 dy; + int angle; int x; int y; - u8* puVar8; + u8* layer; + + const int col_check_length = 6; x = this->x.HALF.HI; y = this->y.HALF.HI; - iVar3 = sub_080045DA(a - x, b - y); + angle = CalcOffsetAngle(target_x - x, target_y - y); x <<= 8; y <<= 8; - sVar1 = gSineTable[iVar3] * 6; - sVar2 = gSineTable[(iVar3 + 0x40)] * 6; + + // get vector to target + dx = gSineTable[angle] * col_check_length; + dy = gSineTable[(angle + 0x40)] * col_check_length; if (this->collisionLayer != 2) { - puVar8 = gMapBottom.collisionData; + layer = gMapBottom.collisionData; } else { - puVar8 = gMapTop.collisionData; + layer = gMapTop.collisionData; } while (1) { - if (IsTileCollision(puVar8, x / 0x100, y / 0x100, 6)) { + if (IsTileCollision(layer, x / 0x100, y / 0x100, col_check_length)) { return 0; } - if (((a - (x / 0x100)) + 6 >= 0xd) || ((b - (y / 0x100)) + 6 >= 0xd)) { - x += sVar1; - y -= sVar2; + if (((target_x - (x / 0x100)) + col_check_length > col_check_length * 2) || + ((target_y - (y / 0x100)) + col_check_length > col_check_length * 2)) { + x += dx; + y -= dy; continue; } return 1; } } -void sub_08061090(NPC5Entity* this, u32 a, u32 b) { +void ZeldaCalcWalkSpeed(NPC5Entity* this, u32 a, u32 b) { s32 xDist; s32 yDist; s32 sqrDist; @@ -419,42 +459,42 @@ void sub_08061090(NPC5Entity* this, u32 a, u32 b) { xDist = gPlayerEntity.base.x.HALF.HI - super->x.HALF.HI; yDist = gPlayerEntity.base.y.HALF.HI - super->y.HALF.HI; sqrDist = (xDist * xDist) + (yDist * yDist); - if (sqrDist < 0x900) { - super->speed = 0x120; + if (sqrDist < kCloseDistance * kCloseDistance) { + super->speed = kCloseSpeed; } else { - if (sqrDist < 0x1900) { - super->speed = ((sqrDist - 0x900) >> 4) + 0x120; + if (sqrDist < kFarDistance * kFarDistance) { + super->speed = ((sqrDist - (kCloseDistance * kCloseDistance)) >> 4) + kCloseSpeed; } else { - super->speed = 0x220; + super->speed = kFarSpeed; } } - if (super->speed == 0x120) { + if (super->speed == kCloseSpeed) { tmp = 4; - } else if (super->speed < 0x160) { + } else if (super->speed < kMidSpeed) { tmp = 8; } else { tmp = 0xc; } - sub_08061120(this, a, b, tmp); + ZeldaCalcWalkAnim(this, a, b, tmp); } -void sub_08061120(NPC5Entity* this, u32 param_a, u32 param_b, u32 param_c) { - super->direction = CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, param_a, param_b); - if ((param_c != this->unk_6c) || (10 < ((super->direction + super->animationState * -4 + 5) & 0x1f))) { - super->animationState = DirectionRoundUp(super->direction) >> 2; - sub_08060E70(this, param_c); +void ZeldaCalcWalkAnim(NPC5Entity* this, u32 target_x, u32 target_y, u32 anim) { + super->direction = CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, target_x, target_y); + if ((anim != this->baseAnimation) || (10 < ((super->direction + super->animationState * -4 + 5) & 0x1f))) { + super->animationState = Direction8ToAnimationState(DirectionRoundUp(super->direction)); + ZeldaSetAnim(this, anim); } } -bool32 sub_08061170(NPC5Entity* this) { +bool32 ZeldaProcessMovement(NPC5Entity* this) { u32 direction; u32 tmp; UpdateAnimationSingleFrame(super); if (ProcessMovement6(super) == 0) { - direction = sub_080611D4(super); + direction = CalcJumpDirection(super); if (direction != 0xff) { - super->action = 6; + super->action = ZELDA_STATE_JUMP; tmp = (sub_08079FD4(super, 1)); tmp <<= 4; tmp -= 4; @@ -464,9 +504,9 @@ bool32 sub_08061170(NPC5Entity* this) { super->direction = direction; super->animationState = direction >> 2; if (tmp >> 0x10 != 0) { - sub_08060E70(this, 0x14); + ZeldaSetAnim(this, 0x14); } else { - sub_08060E70(this, 0x18); + ZeldaSetAnim(this, 0x18); } } return FALSE; @@ -476,36 +516,37 @@ bool32 sub_08061170(NPC5Entity* this) { } } -u32 sub_080611D4(Entity* this) { +// TODO: this relies on tiles 0x2a - 0x2d, do these exist in the game? +u32 CalcJumpDirection(Entity* this) { static const struct { s8 unk_0; s8 unk_1; - } PACKED gUnk_0810AC4C[] = { + } PACKED sOffsets[] = { { 0, -8 }, { 8, 0 }, { 0, 3 }, { -8, 0 }, }; - static const u8 gUnk_0810AC54[] = { - 0x2b, 0x10, 0x2a, 0x0, 0x2d, 0x8, 0x2c, 0x18, 0x0, + static const u8 sTable[] = { + 0x2b, DirectionSouth, 0x2a, DirectionNorth, 0x2d, DirectionEast, 0x2c, DirectionWest, 0x0, }; - u32 uVar2; + u32 tile; u32 x; - s32 a; - s32 b; + s32 x_offset; + s32 y_offset; s8* ptr; const u8* ptr2; - x = this->animationState & 6; - ptr = (s8*)gUnk_0810AC4C; - a = ptr[x]; - b = ptr[x + 1]; - uVar2 = GetActTileRelative(this, a, b); - ptr2 = gUnk_0810AC54; + x = AnimationStateIdle(this->animationState); + ptr = (s8*)sOffsets; + x_offset = ptr[x]; + y_offset = ptr[x + 1]; + tile = GetActTileRelative(this, x_offset, y_offset); + ptr2 = sTable; do { - if (*ptr2 != uVar2 || this->animationState != (ptr2[1] >> 2)) { + if (*ptr2 != tile || this->animationState != (ptr2[1] >> 2)) { continue; } @@ -523,9 +564,9 @@ u32 sub_080611D4(Entity* this) { return 0xff; } -u32 sub_08061230(NPC5Entity* this) { - if ((((UnkHeap*)super->myHeap)->unk_0 & 1) == 0) { - if ((super->contactFlags & CONTACT_NOW) != 0) { +u32 CheckIsFlinching(NPC5Entity* this) { + if ((HEAP->flags & FLAG_FLINCHING) == 0) { + if (super->contactFlags & CONTACT_NOW) { switch (super->contactFlags & 0x7f) { case 0: case 1: @@ -538,7 +579,7 @@ u32 sub_08061230(NPC5Entity* this) { case 0x1f: break; default: - ((UnkHeap*)super->myHeap)->unk_0 = ((UnkHeap*)super->myHeap)->unk_0 | 1; + HEAP->flags |= FLAG_FLINCHING; InitAnimationForceUpdate(super, (super->animationState >> 1) + 0x40); return 1; } @@ -548,17 +589,17 @@ u32 sub_08061230(NPC5Entity* this) { if ((super->frame & ANIM_DONE) == 0) { return 1; } - ((UnkHeap*)super->myHeap)->unk_0 &= 0xfe; - InitAnimationForceUpdate(super, this->unk_6c + (super->animationState >> 1)); + HEAP->flags &= ~FLAG_FLINCHING; + InitAnimationForceUpdate(super, this->baseAnimation + (super->animationState >> 1)); } - super->contactFlags = super->contactFlags & 0x7f; + super->contactFlags &= 0x7f; if (super->iframes != 0) { super->iframes++; } return 0; } -void sub_08061358(NPC5Entity* this) { +void ZeldaDoLostAnim(NPC5Entity* this) { static const u8 gUnk_0810AC5D[] = { 0x30, 0x31, 0x38, 0x39, 0x32, 0x33, 0x3a, 0x3b, 0x34, 0x35, 0x3c, 0x3d, 0x36, 0x37, 0x3e, 0x3f, 0x0, 0x0, 0x0, }; @@ -573,7 +614,7 @@ void sub_08061358(NPC5Entity* this) { } super->subAction = 1; super->timer = 15; - sub_08060E70(this, 0); + ZeldaSetAnim(this, 0); break; case 1: super->timer--; @@ -585,7 +626,7 @@ void sub_08061358(NPC5Entity* this) { if ((uVar2 & 1) == 0) { super->subAction = 3; super->timer = (bVar4 & 0x18) + 30; - sub_08060E70(this, 4); + ZeldaSetAnim(this, 4); return; } super->subAction = 2; @@ -600,14 +641,14 @@ void sub_08061358(NPC5Entity* this) { if ((Random() & 1)) { super->subAction = 3; super->timer = (bVar4 & 0x18) + 30; - sub_08060E70(this, 4); + ZeldaSetAnim(this, 4); return; } super->subAction = 0; - sub_08060E70(this, 0x10); + ZeldaSetAnim(this, 0x10); break; case 3: - if (sub_08061170(this) == 0) { + if (ZeldaProcessMovement(this) == 0) { super->subAction = 2; //! @bug bVar4 (r6) is uninitialized. @@ -618,96 +659,95 @@ void sub_08061358(NPC5Entity* this) { return; } super->subAction = 0; - sub_08060E70(this, 0x10); + ZeldaSetAnim(this, 0x10); break; } } -void sub_08061464(NPC5Entity* this, u32 param_a, u32 param_b) { - s32 iVar10; - s32 iVar9; - u32 bVar1; +void ZeldaInitNavigate(NPC5Entity* this, u32 tgt_x, u32 tgt_y) { + s32 x; + s32 y; - iVar10 = super->x.HALF.HI; - iVar9 = super->y.HALF.HI; + x = super->x.HALF.HI; + y = super->y.HALF.HI; - switch (((CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, param_a, param_b) + 2) & 0x1c) >> 2) { + switch (((CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, tgt_x, tgt_y) + 2) & 0x1c) >> 2) { case 0: - this->unk_6e = param_b; - if (super->x.HALF.HI > (s32)param_a) { - sub_08061630(this, iVar10, iVar9 + -8, param_a); + this->linear_move_dist = tgt_y; + if (super->x.HALF.HI > (s32)tgt_x) { + TryNavRightFromAbove(this, x, y + -8, tgt_x); break; } - sub_080616A8(this, iVar10, iVar9 + -8, param_a); + TryNavLeftFromAbove(this, x, y + -8, tgt_x); break; case 1: - this->unk_6e = param_a; - if (sub_08061720(this, iVar10 + 8, iVar9, param_b) != 0) + this->linear_move_dist = tgt_x; + if (TryNavUpFromRight(this, x + 8, y, tgt_y) != 0) break; - this->unk_6e = param_b; - sub_080616A8(this, iVar10, iVar9 + -8, param_a); + this->linear_move_dist = tgt_y; + TryNavLeftFromAbove(this, x, y + -8, tgt_x); break; case 2: - this->unk_6e = param_a; - if (super->y.HALF.HI > (s32)param_b) { - sub_08061720(this, iVar10 + 8, iVar9, param_b); + this->linear_move_dist = tgt_x; + if (super->y.HALF.HI > (s32)tgt_y) { + TryNavUpFromRight(this, x + 8, y, tgt_y); } else { - sub_08061798(this, iVar10 + 8, iVar9, param_b); + TryNavBelowFromRight(this, x + 8, y, tgt_y); } break; case 3: - this->unk_6e = param_a; - if (sub_08061798(this, iVar10 + 8, iVar9, param_b) != 0) + this->linear_move_dist = tgt_x; + if (TryNavBelowFromRight(this, x + 8, y, tgt_y) != 0) break; - this->unk_6e = param_b; - sub_08061888(this, iVar10, iVar9 + 8, param_a); + this->linear_move_dist = tgt_y; + TryNavLeftFromBelow(this, x, y + 8, tgt_x); break; case 4: - this->unk_6e = param_b; - if (super->x.HALF.HI > (s32)param_a) { - sub_08061810(this, iVar10, iVar9 + 8, param_a); + this->linear_move_dist = tgt_y; + if (super->x.HALF.HI > (s32)tgt_x) { + TryNavRightFromBelow(this, x, y + 8, tgt_x); break; } - sub_08061888(this, iVar10, iVar9 + 8, param_a); + TryNavLeftFromBelow(this, x, y + 8, tgt_x); break; case 5: - this->unk_6e = param_a; - if (sub_08061978(this, iVar10 + -8, iVar9, param_b) != 0) + this->linear_move_dist = tgt_x; + if (TryNavBelowFromLeft(this, x + -8, y, tgt_y) != 0) break; - this->unk_6e = param_b; - sub_08061810(this, iVar10, iVar9 + 8, param_a); + this->linear_move_dist = tgt_y; + TryNavRightFromBelow(this, x, y + 8, tgt_x); break; case 6: - this->unk_6e = param_a; - if (super->y.HALF.HI > (s32)param_b) { - sub_08061900(this, iVar10 + -8, iVar9, param_b); + this->linear_move_dist = tgt_x; + if (super->y.HALF.HI > (s32)tgt_y) { + TryNavUpFromLeft(this, x + -8, y, tgt_y); } else { - sub_08061978(this, iVar10 + -8, iVar9, param_b); + TryNavBelowFromLeft(this, x + -8, y, tgt_y); } break; case 7: - this->unk_6e = param_a; - if (sub_08061900(this, iVar10 + -8, iVar9, param_b) == 0) { - this->unk_6e = param_b; - sub_08061630(this, iVar10, iVar9 + -8, param_a); + this->linear_move_dist = tgt_x; + if (TryNavUpFromLeft(this, x + -8, y, tgt_y) == 0) { + this->linear_move_dist = tgt_y; + TryNavRightFromAbove(this, x, y + -8, tgt_x); } } - bVar1 = ((UnkHeap*)super->myHeap)->unk_0 & 8; - if (bVar1 == 0) { - super->action = 3; - super->subAction = bVar1; + + if ((HEAP->flags & FLAG_NAVIGATE) == 0) { + super->action = ZELDA_STATE_LOST; + super->subAction = 0; } } -bool32 sub_08061630(NPC5Entity* this, s32 x, s32 y, s32 param) { +bool32 TryNavRightFromAbove(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_y = y; u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { - if (sub_08061A74(layer, x, y, param)) { - ((UnkHeap*)super->myHeap)->unk_7 = x; - ((UnkHeap*)super->myHeap)->unk_8 = param_y; - ((UnkHeap*)super->myHeap)->unk_0 |= 8; - if (this->unk_6e >= y) { + if (CheckPathRight(layer, x, y, param)) { + HEAP->navX = x; + HEAP->navY = param_y; + HEAP->flags |= FLAG_NAVIGATE; + if (this->linear_move_dist >= y) { return TRUE; } } @@ -716,15 +756,15 @@ bool32 sub_08061630(NPC5Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_080616A8(NPC5Entity* this, s32 x, s32 y, s32 param) { +bool32 TryNavLeftFromAbove(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_y = y; u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { - if (sub_08061A1C(layer, x, y, param)) { - ((UnkHeap*)super->myHeap)->unk_7 = x; - ((UnkHeap*)super->myHeap)->unk_8 = param_y; - ((UnkHeap*)super->myHeap)->unk_0 |= 8; - if (this->unk_6e >= y) { + if (CheckPathLeft(layer, x, y, param)) { + HEAP->navX = x; + HEAP->navY = param_y; + HEAP->flags |= FLAG_NAVIGATE; + if (this->linear_move_dist >= y) { return TRUE; } } @@ -733,15 +773,15 @@ bool32 sub_080616A8(NPC5Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061720(NPC5Entity* this, s32 x, s32 y, s32 param) { +bool32 TryNavUpFromRight(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_x = x; u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { - if (sub_080619F0(layer, x, y, param)) { - ((UnkHeap*)super->myHeap)->unk_7 = param_x; - ((UnkHeap*)super->myHeap)->unk_8 = y; - ((UnkHeap*)super->myHeap)->unk_0 |= 8; - if (this->unk_6e <= x) { + if (CheckPathUp(layer, x, y, param)) { + HEAP->navX = param_x; + HEAP->navY = y; + HEAP->flags |= FLAG_NAVIGATE; + if (this->linear_move_dist <= x) { return TRUE; } } @@ -750,15 +790,15 @@ bool32 sub_08061720(NPC5Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061798(NPC5Entity* this, s32 x, s32 y, s32 param) { +bool32 TryNavBelowFromRight(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_x = x; u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { - if (sub_08061A48(layer, x, y, param)) { - ((UnkHeap*)super->myHeap)->unk_7 = param_x; - ((UnkHeap*)super->myHeap)->unk_8 = y; - ((UnkHeap*)super->myHeap)->unk_0 |= 8; - if (this->unk_6e <= x) { + if (CheckPathBelow(layer, x, y, param)) { + HEAP->navX = param_x; + HEAP->navY = y; + HEAP->flags |= FLAG_NAVIGATE; + if (this->linear_move_dist <= x) { return TRUE; } } @@ -767,15 +807,15 @@ bool32 sub_08061798(NPC5Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061810(NPC5Entity* this, s32 x, s32 y, s32 param) { +bool32 TryNavRightFromBelow(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_y = y; u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { - if (sub_08061A74(layer, x, y, param)) { - ((UnkHeap*)super->myHeap)->unk_7 = x; - ((UnkHeap*)super->myHeap)->unk_8 = param_y; - ((UnkHeap*)super->myHeap)->unk_0 |= 8; - if (this->unk_6e <= y) { + if (CheckPathRight(layer, x, y, param)) { + HEAP->navX = x; + HEAP->navY = param_y; + HEAP->flags |= FLAG_NAVIGATE; + if (this->linear_move_dist <= y) { return TRUE; } } @@ -784,15 +824,15 @@ bool32 sub_08061810(NPC5Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061888(NPC5Entity* this, s32 x, s32 y, s32 param) { +bool32 TryNavLeftFromBelow(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_y = y; u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { - if (sub_08061A1C(layer, x, y, param)) { - ((UnkHeap*)super->myHeap)->unk_7 = x; - ((UnkHeap*)super->myHeap)->unk_8 = param_y; - ((UnkHeap*)super->myHeap)->unk_0 |= 8; - if (this->unk_6e <= y) { + if (CheckPathLeft(layer, x, y, param)) { + HEAP->navX = x; + HEAP->navY = param_y; + HEAP->flags |= FLAG_NAVIGATE; + if (this->linear_move_dist <= y) { return TRUE; } } @@ -801,15 +841,15 @@ bool32 sub_08061888(NPC5Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061900(NPC5Entity* this, s32 x, s32 y, s32 param) { +bool32 TryNavUpFromLeft(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_x = x; u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { - if (sub_080619F0(layer, x, y, param)) { - ((UnkHeap*)super->myHeap)->unk_7 = param_x; - ((UnkHeap*)super->myHeap)->unk_8 = y; - ((UnkHeap*)super->myHeap)->unk_0 |= 8; - if (this->unk_6e >= x) { + if (CheckPathUp(layer, x, y, param)) { + HEAP->navX = param_x; + HEAP->navY = y; + HEAP->flags |= FLAG_NAVIGATE; + if (this->linear_move_dist >= x) { return TRUE; } } @@ -818,15 +858,15 @@ bool32 sub_08061900(NPC5Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061978(NPC5Entity* this, s32 x, s32 y, s32 param) { +bool32 TryNavBelowFromLeft(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_x = x; u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { - if (sub_08061A48(layer, x, y, param)) { - ((UnkHeap*)super->myHeap)->unk_7 = param_x; - ((UnkHeap*)super->myHeap)->unk_8 = y; - ((UnkHeap*)super->myHeap)->unk_0 |= 8; - if (this->unk_6e >= x) { + if (CheckPathBelow(layer, x, y, param)) { + HEAP->navX = param_x; + HEAP->navY = y; + HEAP->flags |= FLAG_NAVIGATE; + if (this->linear_move_dist >= x) { return TRUE; } } @@ -835,7 +875,7 @@ bool32 sub_08061978(NPC5Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_080619F0(u8* layer, s32 x, s32 y, s32 param) { +bool32 CheckPathUp(u8* layer, s32 x, s32 y, s32 param) { while (param <= y) { if (IsTileCollision(layer, x, y, 6) != 0) { return FALSE; @@ -845,7 +885,7 @@ bool32 sub_080619F0(u8* layer, s32 x, s32 y, s32 param) { return TRUE; } -bool32 sub_08061A1C(u8* layer, s32 x, s32 y, s32 param) { +bool32 CheckPathLeft(u8* layer, s32 x, s32 y, s32 param) { while (param >= x) { if (IsTileCollision(layer, x, y, 6) != 0) { return FALSE; @@ -855,7 +895,7 @@ bool32 sub_08061A1C(u8* layer, s32 x, s32 y, s32 param) { return TRUE; } -bool32 sub_08061A48(u8* layer, s32 x, s32 y, s32 param) { +bool32 CheckPathBelow(u8* layer, s32 x, s32 y, s32 param) { while (param >= y) { if (IsTileCollision(layer, x, y, 6) != 0) { return FALSE; @@ -865,7 +905,7 @@ bool32 sub_08061A48(u8* layer, s32 x, s32 y, s32 param) { return TRUE; } -bool32 sub_08061A74(u8* layer, s32 x, s32 y, s32 param) { +bool32 CheckPathRight(u8* layer, s32 x, s32 y, s32 param) { while (param <= x) { if (IsTileCollision(layer, x, y, 6) != 0) { return FALSE; @@ -875,11 +915,11 @@ bool32 sub_08061A74(u8* layer, s32 x, s32 y, s32 param) { return TRUE; } -void sub_08061AA0(NPC5Entity* this) { +void ZeldaType1Init(NPC5Entity* this) { DeleteThisEntity(); } -void sub_08061AA8(NPC5Entity* this) { +void ZeldaType2Init(NPC5Entity* this) { static void (*const gUnk_0810AC70[])(NPC5Entity*) = { sub_08061ACC, sub_08061B18, @@ -889,11 +929,11 @@ void sub_08061AA8(NPC5Entity* this) { } void sub_08061ACC(NPC5Entity* this) { - super->flags = super->flags | ENT_PERSIST; + super->flags |= ENT_PERSIST; super->action = 1; super->subAction = 0xff; super->timer = 0; - super->followerFlag = super->followerFlag & 0xfe; + super->followerFlag = super->followerFlag & ~1; AddInteractableWhenBigObject(super); sub_08061AFC(this); } @@ -902,7 +942,7 @@ void sub_08061AFC(NPC5Entity* this) { u32 tmp = 0; if (super->subAction != 0) { super->subAction = tmp; - this->unk_68 = gUnk_0810B660[0]; + this->messageData = gZeldaFollowerText[0]; super->timer = 0; } } @@ -916,7 +956,7 @@ void sub_08061B18(NPC5Entity* this) { case INTERACTION_TALK: super->interactType = INTERACTION_NONE; sub_08061AFC(this); - puVar2 = this->unk_68; + puVar2 = this->messageData; puVar2 += (super->timer++); if (puVar2[1] == 0) { super->timer = 0; @@ -926,7 +966,7 @@ void sub_08061B18(NPC5Entity* this) { } } -void sub_08061B58(NPC5Entity* this) { +void ZeldaType3Init(NPC5Entity* this) { if (super->action == 0) { super->action = 1; InitAnimationForceUpdate(super, 2); diff --git a/src/object/cutsceneMiscObject.c b/src/object/cutsceneMiscObject.c index c2320d91..fa787b35 100644 --- a/src/object/cutsceneMiscObject.c +++ b/src/object/cutsceneMiscObject.c @@ -710,7 +710,7 @@ void sub_0809567C(CutsceneMiscObjectEntity* this) { super->action = 3; super->subAction = 1; super->speed = 0x400; - super->direction = sub_080045DA(super->x.WORD - ((s16)this->px << 16), super->y.WORD - ((s16)this->py << 16)); + super->direction = CalcOffsetAngle(super->x.WORD - ((s16)this->px << 16), super->y.WORD - ((s16)this->py << 16)); } void CutsceneMiscObject_Type15(CutsceneMiscObjectEntity* this) { diff --git a/src/object/evilSpirit.c b/src/object/evilSpirit.c index 43dc00ab..a2943a52 100644 --- a/src/object/evilSpirit.c +++ b/src/object/evilSpirit.c @@ -83,10 +83,10 @@ void EvilSpirit_Action1(EvilSpiritEntity* this) { this->unk7a = this->unk7c; super->speed = 0x300; super->direction = - sub_080045DA(super->parent->x.WORD - super->x.WORD, super->parent->y.WORD - super->y.WORD) ^ 0x80; + CalcOffsetAngle(super->parent->x.WORD - super->x.WORD, super->parent->y.WORD - super->y.WORD) ^ 0x80; } else { super->speed = 0x600; - dir = sub_080045DA(gPlayerEntity.base.x.WORD - super->x.WORD, gPlayerEntity.base.y.WORD - super->y.WORD) ^ + dir = CalcOffsetAngle(gPlayerEntity.base.x.WORD - super->x.WORD, gPlayerEntity.base.y.WORD - super->y.WORD) ^ 0x80; if (dir != super->direction) { if ((u8)(dir - super->direction) > 0x80) { @@ -178,7 +178,7 @@ void EvilSpirit_Action3(EvilSpiritEntity* this) { short iVar4; int iVar6; - super->direction = sub_080045DA(this->x - super->x.WORD, this->y - super->y.WORD); + super->direction = CalcOffsetAngle(this->x - super->x.WORD, this->y - super->y.WORD); if ((super->contactFlags & 0x7f) == 0x13) { super->speed = 0x100; super->gustJarTolerance--; diff --git a/src/object/fileScreenObjects.c b/src/object/fileScreenObjects.c index b474fdd6..19842f23 100644 --- a/src/object/fileScreenObjects.c +++ b/src/object/fileScreenObjects.c @@ -20,7 +20,7 @@ typedef struct { /*0x70*/ u8 unk_70; } FileScreenObjectsEntity; -extern u32 sub_080041EC(s32, s32); +extern u32 CalcDistance(s32, s32); static bool32 sub_0808E950(void); static void sub_0808EABC(FileScreenObjectsEntity*); @@ -550,14 +550,14 @@ static u32 sub_0808EF6C(FileScreenObjectsEntity* this) { return 0; } - var4 = var7 = sub_080041EC(var0, var2); + var4 = var7 = CalcDistance(var0, var2); var4 += 128; var7 = var4 + var7 * 16; if (this->unk_6c < var7) { var7 = this->unk_6c; } super->speed = var7; - super->direction = sub_080045DA(var0, var2) >> 3; + super->direction = CalcOffsetAngle(var0, var2) >> 3; LinearMoveUpdate(super); return 1; } diff --git a/src/object/keyStealingTakkuri.c b/src/object/keyStealingTakkuri.c index 2f67e69f..2fceaa87 100644 --- a/src/object/keyStealingTakkuri.c +++ b/src/object/keyStealingTakkuri.c @@ -433,7 +433,7 @@ void sub_0809E0D4(KeyStealingTakkuriEntity* this, ScriptExecutionContext* contex varY2 = varY; if (--context->unk_19 == 0) { context->unk_19 = 8; - super->direction = sub_080045DA(varX2 - super->x.HALF.HI, varY2 - super->y.HALF.HI); + super->direction = CalcOffsetAngle(varX2 - super->x.HALF.HI, varY2 - super->y.HALF.HI); } varX3 = super->x.HALF.HI - varX2; varY3 = super->y.HALF.HI - varY2; diff --git a/src/object/objectA2.c b/src/object/objectA2.c index 0617ce3e..9e82aeb3 100644 --- a/src/object/objectA2.c +++ b/src/object/objectA2.c @@ -117,5 +117,5 @@ void sub_0809F448(Entity* this) { break; } this->speed = (tmp > 0 ? tmp : -tmp) / (tmp2->unk_1 << 8); - this->direction = sub_080045DA(tmp, 0) >> 3; + this->direction = CalcOffsetAngle(tmp, 0) >> 3; } diff --git a/src/object/octorokBossObject.c b/src/object/octorokBossObject.c index ddab7bce..bc77267c 100644 --- a/src/object/octorokBossObject.c +++ b/src/object/octorokBossObject.c @@ -181,7 +181,7 @@ void OctorokBossObject_Action1(OctorokBossObjectEntity* this) { return; } case 1: - super->direction = sub_080045DA(this->helper->tailObjects[super->timer]->x.WORD - super->x.WORD, + super->direction = CalcOffsetAngle(this->helper->tailObjects[super->timer]->x.WORD - super->x.WORD, this->helper->tailObjects[super->timer]->y.WORD - super->y.WORD); LinearMoveAngle(super, super->speed, super->direction); if (EntityInRectRadius(super, this->helper->tailObjects[super->timer], 2, 2) == 0) { @@ -207,7 +207,7 @@ void OctorokBossObject_Action1(OctorokBossObjectEntity* this) { case 2: if (super->parent->type2 == 3) { Entity* object = ((OctorokBossObjectEntity*)super->parent)->helper->mouthObject; - super->direction = sub_080045DA(object->x.WORD - super->x.WORD, object->y.WORD - super->y.WORD); + super->direction = CalcOffsetAngle(object->x.WORD - super->x.WORD, object->y.WORD - super->y.WORD); LinearMoveAngle(super, 0x280, super->direction); if (sub_0806FC80(super, super->parent, 0x48) == 0) { return; diff --git a/src/object/specialFx.c b/src/object/specialFx.c index bfe1a5e5..622aa059 100644 --- a/src/object/specialFx.c +++ b/src/object/specialFx.c @@ -199,7 +199,7 @@ void sub_080845DC(SpecialFxObject* this) { void sub_080845F8(SpecialFxObject* this) { if (((8 - (super->x.HALF.HI & 0xF)) | (8 - (super->y.HALF.HI & 0xF))) != 0) { - super->direction = sub_080045DA((8 - (super->x.HALF.HI & 0xF)), (8 - (super->y.HALF.HI & 0xF))) >> 3; + super->direction = CalcOffsetAngle((8 - (super->x.HALF.HI & 0xF)), (8 - (super->y.HALF.HI & 0xF))) >> 3; LinearMoveUpdate(super); } sub_08084630(this); diff --git a/src/player.c b/src/player.c index ffb4ca6c..303bc8ff 100644 --- a/src/player.c +++ b/src/player.c @@ -25,28 +25,27 @@ #include "screenTransitions.h" #include "sound.h" -#define GRAVITY_RATE Q_8_8(32) -#define SLOPE_SPEED_MODIFIER 0x50 +#define kGravityRate Q_8_8(32) +#define kWalkSpeedSlopeSubtractor Q_8_8(0.3125) +#define kWalkSpeed Q_8_8(1.25) +#define kWalkSpeedRolling Q_8_8(2.0) +#define kWalkSpeedGustJar Q_8_8(0.5) +#define kWalkSpeedShield Q_8_8(0.75) +#define kWalkSpeedSwordCharge Q_8_8(0.875) +#define kWalkSpeedBurning Q_8_8(3) -#define WALK_SPEED Q_8_8(1.25) -#define ROLL_SPEED Q_8_8(2.0) -#define GUST_JAR_SPEED Q_8_8(0.5) -#define SHIELDING_SPEED Q_8_8(0.75) -#define SWORD_CHARGE_SPEED Q_8_8(0.875) -#define BURNING_SPEED Q_8_8(3) - -#define JUMP_SPEED_FWD Q_8_8(1) +#define kJumpSpeedForward Q_8_8(1) /* Jumping out of a hole */ -#define JUMP_SPEED_HOLE_FWD Q_8_8(0.46875) -#define JUMP_SPEED_HOLE_Z Q_16_16(1.625) +#define kJumpSpeedHoleForward Q_8_8(0.46875) +#define kJumpSpeedHoleZ Q_16_16(1.625) /* Bouncing off a wall */ -#define BOUNCE_SPEED_FWD Q_8_8(1.0) -#define BOUNCE_SPEED_Z Q_16_16(2.0) +#define kBounceSpeedForward Q_8_8(1.0) +#define kBounceSpeedZ Q_16_16(2.0) -#define PULL_SPEED Q_8_8(0.5) -#define PUSH_SPEED Q_8_8(0.5) +#define kPullSpeed Q_8_8(0.5) +#define kPushSpeed Q_8_8(0.5) -#define FALL_DAMAGE 2 +#define kFallDamage 2 typedef void(PlayerEntityAction)(PlayerEntity*); @@ -392,7 +391,7 @@ static void PlayerNormal(PlayerEntity* this) { if (gPlayerState.flags & PL_CAPTURED) { super->spritePriority.b1 = 0; super->knockbackDuration = 0; - super->speed = WALK_SPEED; + super->speed = kWalkSpeed; gPlayerState.pushedObject = 0x80; gPlayerState.framestate = PL_STATE_TRAPPED; if ((super->animationState >> 1) + 92 == super->animIndex && (u16)super->spriteIndex == 2) @@ -421,14 +420,14 @@ static void PlayerNormal(PlayerEntity* this) { } if (!gPlayerState.swim_state && (gPlayerState.jump_status & 0xC0) == 0) { if (gPlayerState.shield_status || gPlayerState.bow_state) { - super->speed = SHIELDING_SPEED; + super->speed = kWalkSpeedShield; } else { if (gPlayerState.sword_state) { - super->speed = SWORD_CHARGE_SPEED; + super->speed = kWalkSpeedSwordCharge; } else if (gPlayerState.field_0x1c) { - super->speed = GUST_JAR_SPEED; + super->speed = kWalkSpeedGustJar; } else { - super->speed = WALK_SPEED; + super->speed = kWalkSpeed; } } } @@ -536,7 +535,7 @@ static void PlayerNormal(PlayerEntity* this) { if ((gPlayerState.sword_state & 0x10) == 0) { super->direction = gPlayerState.direction; if (gPlayerState.flags & PL_BURNING) { - super->speed = BURNING_SPEED; + super->speed = kWalkSpeedBurning; if ((gPlayerState.direction & DIR_NOT_MOVING_CHECK) != 0) super->direction = 4 * (super->animationState & 0xE); DeleteClones(); @@ -624,7 +623,7 @@ static void PlayerFallUpdate(PlayerEntity* this) { RespawnPlayer(); gPlayerState.field_0xa = 0; super->iframes = 32; - ModHealth(-FALL_DAMAGE); + ModHealth(-kFallDamage); } } } @@ -641,19 +640,19 @@ static void PlayerBounce(PlayerEntity* this) { static void PlayerBounceInit(PlayerEntity* this) { COLLISION_OFF(super); super->direction = DirectionTurnAround(Direction8FromAnimationState(AnimationStateWalk(super->animationState))); - super->speed = BOUNCE_SPEED_FWD; + super->speed = kBounceSpeedForward; super->knockbackDuration = 0; super->subAction++; super->timer = gPlayerState.field_0x38; super->spriteIndex = 1; if (!(gPlayerState.flags & PL_MINISH)) { - super->zVelocity = BOUNCE_SPEED_Z; + super->zVelocity = kBounceSpeedZ; gPlayerState.animation = ANIM_BOUNCE; InitScreenShake(16, 0); } else { gPlayerState.animation = ANIM_BOUNCE_MINISH; - super->zVelocity = (BOUNCE_SPEED_Z * 3) / 4; + super->zVelocity = (kBounceSpeedZ * 3) / 4; } gPlayerState.jump_status = 0x80; @@ -668,7 +667,7 @@ static void PlayerBounceUpdate(PlayerEntity* this) { UpdatePlayerMovement(); UpdateFloorType(); - if (CheckQueuedAction() || GravityUpdate(super, GRAVITY_RATE)) + if (CheckQueuedAction() || GravityUpdate(super, kGravityRate)) return; gPlayerState.jump_status = 0; @@ -866,7 +865,7 @@ static void PlayerJumpInit(PlayerEntity* this) { temp <<= 12; super->zVelocity = temp; - super->speed = JUMP_SPEED_FWD; + super->speed = kJumpSpeedForward; DeleteClones(); SoundReq(SFX_PLY_JUMP); SoundReq(SFX_PLY_VO4); @@ -885,7 +884,7 @@ static void sub_08071130(PlayerEntity* this) { LinearMoveUpdate(super); - if (GravityUpdate(super, GRAVITY_RATE)) + if (GravityUpdate(super, kGravityRate)) return; gPlayerState.jump_status = 0; @@ -1041,7 +1040,7 @@ static void PortalJumpOnUpdate(PlayerEntity* this) { if ((super->x.HALF.HI != x) || (super->y.HALF.HI != y)) { super->direction = CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, gArea.portal_x, gArea.portal_y); - super->speed = JUMP_SPEED_FWD; + super->speed = kJumpSpeedForward; UpdatePlayerMovement(); } @@ -1081,7 +1080,7 @@ static void PortalStandUpdate(PlayerEntity* this) { super->direction = gPlayerState.direction; super->animationState = Direction8ToAnimationState(super->direction); super->zVelocity = Q_16_16(2.0); - super->speed = JUMP_SPEED_FWD; + super->speed = kJumpSpeedForward; super->action = PLAYER_MINISH; super->subAction = 7; super->subtimer = 0; @@ -1216,7 +1215,7 @@ static void PortalShrinkUpdate(PlayerEntity* this) { static void PortalEnterUpdate(PlayerEntity* this) { if (super->timer == 0) { - if (GravityUpdate(super, GRAVITY_RATE)) + if (GravityUpdate(super, kGravityRate)) return; super->spriteSettings.draw = FALSE; @@ -1311,7 +1310,7 @@ static void PlayerTalkEzlo_Init(PlayerEntity* this) { return; } - if (!GravityUpdate(super, GRAVITY_RATE)) { + if (!GravityUpdate(super, kGravityRate)) { gPlayerState.jump_status = 0; } } @@ -1406,7 +1405,7 @@ static void PlayerPushInit(PlayerEntity* this) { super->timer = 0; super->subtimer = 1; } else { - super->speed = (gPlayerState.flags & PL_MINISH) ? PUSH_SPEED / 2 : PUSH_SPEED; + super->speed = (gPlayerState.flags & PL_MINISH) ? kPushSpeed / 2 : kPushSpeed; } PlayerPushUpdate(this); } @@ -1419,19 +1418,19 @@ static void PlayerPushUpdate(PlayerEntity* this) { static const PushFrame sPushFrames[] = { { 5, 0 }, - { 1, PUSH_SPEED * 2 }, + { 1, kPushSpeed * 2 }, { 5, 0 }, - { 1, PUSH_SPEED * 2 }, + { 1, kPushSpeed * 2 }, { 2, 0 }, - { 1, PUSH_SPEED * 2 }, + { 1, kPushSpeed * 2 }, { 2, 0 }, - { 1, PUSH_SPEED * 2 }, + { 1, kPushSpeed * 2 }, { 3, 0 }, - { 1, PUSH_SPEED * 2 }, - { 8, PUSH_SPEED * 3 / 4 }, - { 8, PUSH_SPEED * 3 / 4 }, - { 8, PUSH_SPEED * 3 / 4 }, - { 8, PUSH_SPEED / 2 }, + { 1, kPushSpeed * 2 }, + { 8, kPushSpeed * 3 / 4 }, + { 8, kPushSpeed * 3 / 4 }, + { 8, kPushSpeed * 3 / 4 }, + { 8, kPushSpeed / 2 }, { 0xFF, 0 }, }; @@ -1491,7 +1490,7 @@ static void PlayerMinishDieInit(PlayerEntity* this) { if (gPlayerState.flags & (PL_CAPTURED | PL_DISABLE_ITEMS)) return; - if (GravityUpdate(super, GRAVITY_RATE)) { + if (GravityUpdate(super, kGravityRate)) { if (gPlayerState.flags & PL_NO_CAP) gPlayerState.animation = ANIM_JUMP_NOCAP; else @@ -1637,7 +1636,7 @@ static void sub_08071E04(PlayerEntity* this) { static void sub_08071E74(PlayerEntity* this) { u32 temp; - GravityUpdate(super, GRAVITY_RATE); + GravityUpdate(super, kGravityRate); UpdatePlayerMovement(); temp = super->timer--; if (temp == 0) @@ -1703,7 +1702,7 @@ static void PlayerFrozenInit(PlayerEntity* this) { } static void PlayerFrozenUpdate(PlayerEntity* this) { - if (GravityUpdate(super, GRAVITY_RATE) == 0) { + if (GravityUpdate(super, kGravityRate) == 0) { UpdateSpriteForCollisionLayer(super); gPlayerState.jump_status = 0; if (gPlayerState.field_0x14 == 0) { @@ -1807,7 +1806,7 @@ static void sub_08072168(PlayerEntity* this) { u32 i; UpdateAnimationSingleFrame(super); - i = (u16)sub_0806F854(super, 0, -12) ? GRAVITY_RATE * 2 : GRAVITY_RATE; + i = (u16)sub_0806F854(super, 0, -12) ? kGravityRate * 2 : kGravityRate; GravityUpdate(super, i); if (gPlayerState.field_0x3a) { LinearMoveUpdate(super); @@ -1837,7 +1836,7 @@ static void PlayerPull(PlayerEntity* this) { static void sub_08072214(PlayerEntity* this) { super->subAction = 1; - super->speed = PULL_SPEED; + super->speed = kPullSpeed; super->timer = gPlayerState.field_0x38; super->direction = Direction8FromAnimationState(AnimationStateFlip180(super->animationState)); if ((gPlayerState.flags & PL_NO_CAP) == 0) { @@ -1904,7 +1903,7 @@ static void sub_08072354(PlayerEntity* this) { sub_0806F854(super, 0, -12); UpdateAnimationSingleFrame(super); sub_08079744(super); - if (GravityUpdate(super, GRAVITY_RATE)) + if (GravityUpdate(super, kGravityRate)) return; super->spritePriority.b1 = 0; @@ -2112,14 +2111,14 @@ static void PlayerRollUpdate(PlayerEntity* this) { switch (super->frame & 0xf) { case 0: if ((super->frame & 0xf) == 0) { - super->speed = ROLL_SPEED; + super->speed = kWalkSpeedRolling; } break; case 1: - super->speed += ROLL_SPEED / 16; + super->speed += kWalkSpeedRolling / 16; break; case 2: - super->speed = (ROLL_SPEED * 3 / 2); + super->speed = (kWalkSpeedRolling * 3 / 2); break; case 3: super->speed = 0; @@ -2229,8 +2228,8 @@ static void sub_08072ACC(PlayerEntity* this) { } else if (super->subtimer > 7) { COLLISION_ON(super); super->direction = gPlayerState.direction; - super->zVelocity = JUMP_SPEED_HOLE_Z; - super->speed = JUMP_SPEED_HOLE_FWD; + super->zVelocity = kJumpSpeedHoleZ; + super->speed = kJumpSpeedHoleForward; super->spritePriority.b0 = 4; super->spritePriority.b1 = 1; gPlayerState.jump_status = 0x41; @@ -2277,7 +2276,7 @@ static void sub_08072B5C(PlayerEntity* this) { temp <<= 12; super->zVelocity = temp; - super->speed = JUMP_SPEED_FWD; + super->speed = kJumpSpeedForward; gPlayerState.animation = ANIM_JUMP; SoundReq(SFX_PLY_JUMP); } @@ -2285,7 +2284,7 @@ static void sub_08072B5C(PlayerEntity* this) { static void sub_08072C48(PlayerEntity* this) { UpdateAnimationSingleFrame(super); LinearMoveUpdate(super); - if (GravityUpdate(super, GRAVITY_RATE)) + if (GravityUpdate(super, kGravityRate)) return; DoTileInteractionHere(super, 7); @@ -2403,7 +2402,7 @@ static void sub_08072D54(PlayerEntity* this) { super->timer = 0; } - if (!GravityUpdate(super, GRAVITY_RATE)) { + if (!GravityUpdate(super, kGravityRate)) { COLLISION_ON(super); if (super->collisionLayer == 1) { ResetCollisionLayer(super); @@ -2724,7 +2723,7 @@ static void sub_08073468(PlayerEntity* this) { } static void sub_080734D4(PlayerEntity* this) { - GravityUpdate(super, -(GRAVITY_RATE / 2)); + GravityUpdate(super, -(kGravityRate / 2)); if (super->zVelocity > 0 || gPlayerState.field_0x38 == 1) { super->zVelocity = Q_16_16(4.5625); super->subAction++; @@ -2732,7 +2731,7 @@ static void sub_080734D4(PlayerEntity* this) { } static void sub_08073504(PlayerEntity* this) { - GravityUpdate(super, super->zVelocity < 0 ? GRAVITY_RATE / 4 : GRAVITY_RATE * 2); + GravityUpdate(super, super->zVelocity < 0 ? kGravityRate / 4 : kGravityRate * 2); if (super->zVelocity < 0 && super->z.HALF.HI > -32) { super->subAction++; this->unk_80.WORD = super->direction << 8; @@ -2908,7 +2907,7 @@ static void sub_0807380C(PlayerEntity* this) { } gPlayerState.animation = sAnims[super->animationState >> 1]; if (super->z.HALF.HI < -16) { - GravityUpdate(super, GRAVITY_RATE / 16); + GravityUpdate(super, kGravityRate / 16); } else { if (--super->timer == 0) { super->subAction = 7; @@ -2939,7 +2938,7 @@ void sub_08073884(PlayerEntity* this) { else InitParachuteRoom(); } - GravityUpdate(super, -((GRAVITY_RATE * 3) / 4)); + GravityUpdate(super, -((kGravityRate * 3) / 4)); UpdateAnimationSingleFrame(super); } @@ -2993,13 +2992,13 @@ static void sub_080739EC(PlayerEntity* this) { gPlayerState.direction = super->direction; if (gPlayerState.jump_status & 0x80) super->collisions = COL_NONE; - v = GRAVITY_RATE; + v = kGravityRate; } else { if ((u16)sub_0806F854(super, 0, -12)) { gPlayerState.jump_status |= 8; - v = GRAVITY_RATE * 2; + v = kGravityRate * 2; } else { - v = GRAVITY_RATE; + v = kGravityRate; if (gPlayerState.jump_status & 0x10) v /= 2; } @@ -3079,7 +3078,7 @@ void sub_08073B8C(PlayerEntity* this) { --super->timer; return; } - GravityUpdate(super, GRAVITY_RATE * 2); + GravityUpdate(super, kGravityRate * 2); if (super->z.HALF.HI >= -8) { if (!gPlayerState.field_0x14 && (sub_0807A2B8() || !sub_08079D48())) { COLLISION_ON(super); @@ -3173,7 +3172,7 @@ static void sub_08073D20(PlayerEntity* this) { } if (!UpdatePlayerCollision()) { UpdateActiveItems(super); - if (!GravityUpdate(super, GRAVITY_RATE)) + if (!GravityUpdate(super, kGravityRate)) gPlayerState.jump_status = 0; if ((gPlayerState.field_0x7 & 0x80) == 0 && !gPlayerState.field_0xa) { if (super->iframes <= 8) { @@ -3251,7 +3250,7 @@ static void sub_08073FD0(PlayerEntity* this) { SoundReq(SFX_PLY_JUMP); } } - GravityUpdate(super, GRAVITY_RATE); + GravityUpdate(super, kGravityRate); if (super->zVelocity == 0) { super->subAction++; SoundReq(SFX_PLY_GROW); @@ -3270,7 +3269,7 @@ static void sub_08074018(PlayerEntity* this) { } static void sub_08074060(PlayerEntity* this) { - if (!GravityUpdate(super, GRAVITY_RATE)) { + if (!GravityUpdate(super, kGravityRate)) { super->hitbox = (Hitbox*)&gPlayerHitbox; super->direction = DirectionSouth; super->animationState = IdleSouth; @@ -3320,7 +3319,7 @@ void sub_080740D8(PlayerEntity* this) { LinearMoveUpdate(super); else super->subtimer = 1; - if (!GravityUpdate(super, GRAVITY_RATE)) + if (!GravityUpdate(super, kGravityRate)) PlayerSetNormalAndCollide(); } @@ -3367,7 +3366,7 @@ static void sub_08074244(PlayerEntity* this, u32 a1, u32 a2) { tmp = 4 * super->animationState; } if (a1 != tmp || a2 != tmp) { - gPlayerState.speed_modifier -= SLOPE_SPEED_MODIFIER; + gPlayerState.speed_modifier -= kWalkSpeedSlopeSubtractor; } } } @@ -3788,7 +3787,7 @@ void SurfaceAction_ConveyerEast(PlayerEntity* this) { static void conveyer_push(PlayerEntity* this) { ResetActiveItems(); super->spritePriority.b1 = 0; - super->speed = WALK_SPEED; + super->speed = kWalkSpeed; gPlayerState.flags |= PL_CONVEYOR_PUSHED; gPlayerState.field_0xa |= 0x80; gPlayerState.mobility |= 0x80; @@ -3839,7 +3838,7 @@ static void sub_08074CF8(PlayerEntity* this) { sub_08074D34(this, *(ScriptExecutionContext**)&this->unk_84.WORD); if ((this->unk_80.HALF.HI & 1) != 0) super->animationState = v3; - GravityUpdate(super, GRAVITY_RATE); + GravityUpdate(super, kGravityRate); UpdateAnimationSingleFrame(super); } @@ -3995,7 +3994,7 @@ void sub_0807501C(PlayerEntity* this) { void sub_0807508C(PlayerEntity* this) { UpdateAnimationSingleFrame(super); - if (GravityUpdate(super, GRAVITY_RATE)) { + if (GravityUpdate(super, kGravityRate)) { LinearMoveUpdate(super); } else { if (!gPlayerState.field_0x39) { diff --git a/src/script.c b/src/script.c index 6a10ec96..3a826a34 100644 --- a/src/script.c +++ b/src/script.c @@ -436,7 +436,7 @@ void sub_0807DEDC(Entity* entity, ScriptExecutionContext* context, u32 x, u32 y) context->y.HALF.HI = y; xOffset = context->x.HALF.HI - entity->x.HALF.HI; yOffset = context->y.HALF.HI - entity->y.HALF.HI; - direction = sub_080045DA(xOffset, yOffset); + direction = CalcOffsetAngle(xOffset, yOffset); entity->direction = direction; entity->animationState = (entity->animationState & 0x80) | sDirectionTable[(u8)direction >> 4]; } @@ -1394,7 +1394,7 @@ void ScriptCommand_0807EE30(Entity* entity, ScriptExecutionContext* context) { if (!--context->unk_19) { context->unk_19 = 8; entity->direction = - sub_080045DA(context->x.HALF.HI - entity->x.HALF.HI, context->y.HALF.HI - entity->y.HALF.HI); + CalcOffsetAngle(context->x.HALF.HI - entity->x.HALF.HI, context->y.HALF.HI - entity->y.HALF.HI); } tmp = entity->x.HALF.HI - context->x.HALF.HI; tmp2 = entity->y.HALF.HI - context->y.HALF.HI;