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/asm/src/player.s b/asm/src/player.s index fefcf695..488fdbaa 100644 --- a/asm/src/player.s +++ b/asm/src/player.s @@ -83,7 +83,7 @@ _080085E6: ldr r3, _080088A8 @ =gPlayerState ldrb r2, [r3, #0x1c] orrs r2, r2 - bne _0800861A // field_0x1c != 0 + bne _0800861A // gustJarState != 0 ldrb r2, [r3, #5] orrs r2, r2 bne _0800861A // heldObject != 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/include/player.h b/include/player.h index e344d0af..dbd1f923 100644 --- a/include/player.h +++ b/include/player.h @@ -11,8 +11,8 @@ typedef struct { /*0x6d*/ u8 unk_6d; /*0x6e*/ u8 unk_6e; /*0x6f*/ u8 unk_6f; - /*0x70*/ Entity* unk_70; - /*0x74*/ Entity* unk_74; + /*0x70*/ Entity* pulledJarEntity; + /*0x74*/ Entity* carriedEntity; /*0x78*/ u8 unk_78; /*0x79*/ u8 unk_79; /*0x7a*/ u16 unk_7a; @@ -298,6 +298,24 @@ typedef enum { SWORD_MOVE_LOW_BEAM, } SwordMove; +typedef enum { + PL_JAR_NONE = 0x0, + PL_JAR_SUCK = 0x1, + PL_JAR_2 = 0x2, + PL_JAR_3 = 0x3, + PL_JAR_BLAST_INIT = 0x4, + PL_JAR_BLAST_UPDATE = 0x5, + PL_JAR_BLAST_DONE = 0x6, + PL_JAR_ENT_ATTACHED = 0x7, +} GustJarState; + +typedef enum { + JAR_CHARGE_NONE = 0, + JAR_CHARGE_SMALL = 1, + JAR_CHARGE_MID = 2, + JAR_CHARGE_BIG = 3, +} GustJarCharge; + typedef enum { ANIM_DEFAULT = 0x100, ANIM_WALK = 0x104, @@ -492,8 +510,8 @@ typedef struct { /*0x18*/ u16 startPosY; /*0x1a*/ u8 mobility; /*0x1b*/ u8 sword_state; - /*0x1c*/ u8 field_0x1c; - /*0x1d*/ u8 gustJarSpeed; + /*0x1c*/ u8 gustJarState; + /*0x1d*/ u8 gustJarCharge; /*0x1e*/ u8 dash_state; /*0x1f*/ u8 field_0x1f[2]; /*0x21*/ u8 bow_state; diff --git a/src/beanstalkSubtask.c b/src/beanstalkSubtask.c index beacfffc..2eb16f89 100644 --- a/src/beanstalkSubtask.c +++ b/src/beanstalkSubtask.c @@ -208,7 +208,7 @@ u32 UpdatePlayerCollision(void) { ((gPlayerState.sword_state & 0x10) != 0)) || ((sub_080806BC(gPlayerEntity.base.x.HALF.HI - gRoomControls.origin_x, gPlayerEntity.base.y.HALF.HI - gRoomControls.origin_y, index, 5) == 0 && - (((gPlayerState.heldObject != 0 || ((gPlayerState.field_0x1c & 0xf) != 0)) || + (((gPlayerState.heldObject != 0 || ((gPlayerState.gustJarState & 0xf) != 0)) || (sub_0807BD14(&gPlayerEntity.base, index) == 0)))))) { return 3; } diff --git a/src/collision.c b/src/collision.c index 95595906..b8c0bbd3 100644 --- a/src/collision.c +++ b/src/collision.c @@ -391,7 +391,7 @@ CollisionResult sub_08017B1C(Entity* org, Entity* tgt, u32 direction, ColSetting CollisionResult sub_08017B58(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if ((tgt->gustJarState & 4) != 0) { if (tgt->gustJarTolerance) { - tgt->gustJarTolerance = tgt->gustJarTolerance - gPlayerState.gustJarSpeed; + tgt->gustJarTolerance = tgt->gustJarTolerance - gPlayerState.gustJarCharge; if ((s8)tgt->gustJarTolerance <= 0) { tgt->gustJarTolerance = 0; tgt->subAction = 2; diff --git a/src/enemy/bombPeahat.c b/src/enemy/bombPeahat.c index 44ea5007..64bff4f2 100644 --- a/src/enemy/bombPeahat.c +++ b/src/enemy/bombPeahat.c @@ -96,8 +96,8 @@ void sub_0802A8F4(BombPeahatEntity* this) { } void sub_0802A8FC(BombPeahatEntity* this) { - if ((gPlayerState.field_0x1c & 0xf) == 0) { - super->health = gPlayerState.field_0x1c & 0xf; + if ((gPlayerState.gustJarState & 0xf) == 0) { + super->health = gPlayerState.gustJarState & 0xf; } } diff --git a/src/enemy/dust.c b/src/enemy/dust.c index e6d3ca7a..7fd8c6d0 100644 --- a/src/enemy/dust.c +++ b/src/enemy/dust.c @@ -303,7 +303,7 @@ void sub_08044550(DustEntity* this) { u8 uVar1; const s8* ptr; - if ((gPlayerState.field_0x1c & 0xf) == 1) { + if ((gPlayerState.gustJarState & 0xf) == 1) { if (super->speed < 0x100) { super->speed += 0x10; } diff --git a/src/enemy/enemy64.c b/src/enemy/enemy64.c index be47abc9..41566f7b 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,8 +290,8 @@ void Enemy64_Action3(Enemy64Entity* this) { } void Enemy64_Action3_SubAction0(Enemy64Entity* this) { - u32 tmp = sub_080045DA(gRoomControls.origin_x + 0xa8 - super->x.HALF.HI, - gRoomControls.origin_y + 0x80 - super->y.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) { super->direction--; @@ -490,8 +490,8 @@ 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, - (s32)gPlayerEntity.base.y.HALF.HI - super->y.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/flyingPot.c b/src/enemy/flyingPot.c index 0402aac5..46490d61 100644 --- a/src/enemy/flyingPot.c +++ b/src/enemy/flyingPot.c @@ -156,7 +156,7 @@ void FlyingPot_SubAction2(FlyingPotEntity* this) { } void FlyingPot_SubAction3(FlyingPotEntity* this) { - if (!(gPlayerState.field_0x1c & 0xF)) { + if (!(gPlayerState.gustJarState & 0xF)) { sub_08037408(this); } } diff --git a/src/enemy/flyingSkull.c b/src/enemy/flyingSkull.c index 4e5acb0e..4af30c9f 100644 --- a/src/enemy/flyingSkull.c +++ b/src/enemy/flyingSkull.c @@ -100,7 +100,7 @@ void sub_08039CE0(FlyingSkullEntity* this) { } void sub_08039D4C(FlyingSkullEntity* this) { - if ((gPlayerState.field_0x1c & 0xf) == 0) { + if ((gPlayerState.gustJarState & 0xf) == 0) { sub_0803A0E0(this); } } diff --git a/src/enemy/gyorgMale.c b/src/enemy/gyorgMale.c index 40c43de4..70598f81 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,8 +1066,8 @@ 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, - gPlayerEntity.base.y.HALF.HI - super->y.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; gPlayerEntity.base.x.WORD += (gSineTable[tmp] - gSineTable[dir]) * tmp2; @@ -1149,8 +1149,8 @@ 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, - gPlayerEntity.base.y.HALF.HI - super->y.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..1e0f70c7 100644 --- a/src/enemy/octorokBoss.c +++ b/src/enemy/octorokBoss.c @@ -167,12 +167,12 @@ 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), - (((gRoomControls.origin_y + 0x88) << 0x10) - super->y.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, - gRoomControls.origin_y + 0x88 - super->y.HALF.HI)) >> + super->direction = ((s32)CalcOffsetAngle(gRoomControls.origin_x + 0x108 - super->x.HALF.HI, + gRoomControls.origin_y + 0x88 - super->y.HALF.HI)) >> 3; #endif super->speed = 0x100; @@ -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,8 +912,8 @@ 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, - (gRoomControls.origin_y + 0x88) * 0x10000 - super->y.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,8 +1178,8 @@ 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, - heap->tailObjects[index - 1]->base.y.WORD - heap->tailObjects[index]->base.y.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); heap->tailObjects[index - 1]->base.x.WORD = heap->tailObjects[index]->base.x.WORD + ((s32)tmp << 8); diff --git a/src/item/itemGustJar.c b/src/item/itemGustJar.c index a1c8b4f0..ea2da874 100644 --- a/src/item/itemGustJar.c +++ b/src/item/itemGustJar.c @@ -18,9 +18,9 @@ void sub_08076DF4(ItemBehavior* this, u32 index) { this->playerAnimationState = gPlayerEntity.base.animationState; this->priority |= 0x80; this->priority++; - gPlayerState.gustJarSpeed = 1; - gPlayerEntity.unk_74 = NULL; - gPlayerState.field_0x1c = 1; + gPlayerState.gustJarCharge = JAR_CHARGE_SMALL; + gPlayerEntity.carriedEntity = NULL; + gPlayerState.gustJarState = PL_JAR_SUCK; sub_08077BB8(this); } else { DeleteItemBehavior(this, index); @@ -30,7 +30,7 @@ void sub_08076DF4(ItemBehavior* this, u32 index) { void sub_08076E60(ItemBehavior* this, u32 index) { Entity* playerItem; - if ((gPlayerState.field_0x1c & 0xf) == 0) { + if ((gPlayerState.gustJarState & 0xf) == 0) { DeleteItemBehavior(this, index); } if ((this->playerFrame & 0x80) != 0) { @@ -47,7 +47,7 @@ void sub_08076E60(ItemBehavior* this, u32 index) { } void sub_08076EC8(ItemBehavior* this, u32 index) { - if ((gPlayerState.field_0x1c & 0xf) == 0) { + if ((gPlayerState.gustJarState & 0xf) == PL_JAR_NONE) { DeleteItemBehavior(this, index); return; } @@ -55,11 +55,11 @@ void sub_08076EC8(ItemBehavior* this, u32 index) { if (IsItemActive(this)) { u32 animIndex; if (this->timer > 0xef) { - gPlayerState.gustJarSpeed = 3; + gPlayerState.gustJarCharge = JAR_CHARGE_BIG; } else if (++this->timer > 0x77) { - gPlayerState.gustJarSpeed = 2; + gPlayerState.gustJarCharge = JAR_CHARGE_MID; } else { - gPlayerState.gustJarSpeed = 1; + gPlayerState.gustJarCharge = JAR_CHARGE_SMALL; } if (gPlayerEntity.base.subAction == 0x1b) { @@ -87,16 +87,16 @@ void sub_08076EC8(ItemBehavior* this, u32 index) { void sub_08076F64(ItemBehavior* this, u32 index) { Entity* item; PlayerEntity* player; - switch (gPlayerState.field_0x1c & 0xf) { - case 5: + switch (gPlayerState.gustJarState & 0xf) { + case PL_JAR_BLAST_UPDATE: if (this->playerFrame & 0x80) { if (this->subtimer) { this->subtimer = 0; this->timer = 0; - gPlayerState.gustJarSpeed = 1; + gPlayerState.gustJarCharge = JAR_CHARGE_SMALL; player = &gPlayerEntity; - player->unk_74 = NULL; - gPlayerState.field_0x1c = 1; + player->carriedEntity = NULL; + gPlayerState.gustJarState = PL_JAR_SUCK; gPlayerState.field_0xa &= ~(8 >> index); this->stateID = 2; SetItemAnim(this, ANIM_GUSTJAR_SUCK); @@ -106,7 +106,7 @@ void sub_08076F64(ItemBehavior* this, u32 index) { } return; } else { - gPlayerState.field_0x1c = 6; + gPlayerState.gustJarState = PL_JAR_BLAST_DONE; SetItemAnim(this, ANIM_GUSTJAR_END); return; } @@ -126,18 +126,18 @@ void sub_08076F64(ItemBehavior* this, u32 index) { return; } return; - case 3: - gPlayerState.field_0x1c = 4; - case 4: + case PL_JAR_3: + gPlayerState.gustJarState = PL_JAR_BLAST_INIT; + case PL_JAR_BLAST_INIT: if (IsItemActive(this)) { this->subtimer = 1; } UpdateItemAnim(this); if (this->playerFrame & 1) { - gPlayerState.field_0x1c = 5; - gPlayerEntity.unk_70 = NULL; - if (gPlayerState.gustJarSpeed) { + gPlayerState.gustJarState = PL_JAR_BLAST_UPDATE; + gPlayerEntity.pulledJarEntity = NULL; + if (gPlayerState.gustJarCharge) { CreatePlayerItem(PLAYER_ITEM_GUST_BIG, 0, 0, 0); } } @@ -149,27 +149,27 @@ void sub_08076F64(ItemBehavior* this, u32 index) { gPlayerEntity.base.speed = 0x80; UpdatePlayerMovement(); return; - case 6: + case PL_JAR_BLAST_DONE: UpdateItemAnim(this); if ((this->playerFrame & 0x80) == 0) return; break; - case 7: + case PL_JAR_ENT_ATTACHED: SetItemAnim(this, ANIM_GUSTJAR_BLOW); - gPlayerState.field_0x1c = 3; - gPlayerState.gustJarSpeed = 0; + gPlayerState.gustJarState = PL_JAR_3; + gPlayerState.gustJarCharge = JAR_CHARGE_NONE; return; - case 1: - case 2: + case PL_JAR_SUCK: + case PL_JAR_2: default: - gPlayerState.field_0x1c = 3; + gPlayerState.gustJarState = PL_JAR_3; SetItemAnim(this, ANIM_GUSTJAR_BLOW); return; - case 0: + case PL_JAR_NONE: break; } - gPlayerState.field_0x1c = 0; - gPlayerEntity.unk_70 = NULL; + gPlayerState.gustJarState = PL_JAR_NONE; + gPlayerEntity.pulledJarEntity = NULL; DeleteItemBehavior(this, index); } diff --git a/src/item/itemPegasusBoots.c b/src/item/itemPegasusBoots.c index a79c4788..fca72541 100644 --- a/src/item/itemPegasusBoots.c +++ b/src/item/itemPegasusBoots.c @@ -62,7 +62,7 @@ void sub_080768F8(ItemBehavior* this, u32 index) { u32 bVar1; u32 bVar2; - bVar1 = gPlayerState.field_0x1c | gPlayerState.attack_status | gPlayerState.heldObject | gPlayerState.jump_status; + bVar1 = gPlayerState.gustJarState | gPlayerState.attack_status | gPlayerState.heldObject | gPlayerState.jump_status; bVar2 = (gPlayerState.flags & PL_IN_MINECART); bVar1 |= bVar2; if (bVar1 == 0) { diff --git a/src/item/itemRocsCape.c b/src/item/itemRocsCape.c index ed7f6526..60d290c1 100644 --- a/src/item/itemRocsCape.c +++ b/src/item/itemRocsCape.c @@ -35,7 +35,7 @@ void ItemRocsCape(ItemBehavior* this, u32 index) { } } else { if (((u8)(gPlayerState.sword_state | gPlayerState.field_0xa | gPlayerState.attack_status | - gPlayerState.heldObject | gPlayerState.field_0x1c | gPlayerState.moleMittsState) == 0) && + gPlayerState.heldObject | gPlayerState.gustJarState | gPlayerState.moleMittsState) == 0) && ((((gPlayerState.floor_type != SURFACE_DOOR && gPlayerState.floor_type != SURFACE_DOOR_13 && gPlayerState.floor_type != SURFACE_PIT) || (gPlayerEntity.base.z.WORD != 0)) || diff --git a/src/item/itemTryPickupObject.c b/src/item/itemTryPickupObject.c index c908f04f..c6122f1f 100644 --- a/src/item/itemTryPickupObject.c +++ b/src/item/itemTryPickupObject.c @@ -56,7 +56,7 @@ void sub_08076088(ItemBehavior* this, Entity* param_2, u32 param_3) { PlayerCancelHoldItem(this, param_3); } else { PlayerEntity* playerEnt = &gPlayerEntity; - playerEnt->unk_74 = param_2; + playerEnt->carriedEntity = param_2; playerEnt->base.subtimer = 0; param_2->child = this->field_0x18; param_2->carryFlags = playerEnt->base.carryFlags; 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/bush.c b/src/object/bush.c index d0fbc49e..895e6747 100644 --- a/src/object/bush.c +++ b/src/object/bush.c @@ -73,7 +73,7 @@ void Bush_Init(BushEntity* this) { } void Bush_Action1(BushEntity* this) { - if (((gPlayerState.field_0x1c & 0xf) != 1) || ((super->contactFlags & 0x7f) != 0x13)) { + if (((gPlayerState.gustJarState & 0xf) != 1) || ((super->contactFlags & 0x7f) != 0x13)) { RestorePrevTileEntity(COORD_TO_TILE(super), super->collisionLayer); DeleteThisEntity(); } @@ -108,7 +108,7 @@ void Bush_Action2SubAction2(BushEntity* this) { super->spriteOffsetX = 0; sub_0807B9B8(this->unk_70, COORD_TO_TILE(super), super->collisionLayer); } - if (((gPlayerState.field_0x1c & 0xf) != 1) || ((super->contactFlags & 0x7f) != 0x13)) { + if (((gPlayerState.gustJarState & 0xf) != 1) || ((super->contactFlags & 0x7f) != 0x13)) { Bush_Action2SubAction5(this); } if (sub_0806F3E4(super) && ((super->gustJarFlags & 0xf) == 1)) { diff --git a/src/object/chuchuBossStartParticle.c b/src/object/chuchuBossStartParticle.c index ddd7032a..286c414c 100644 --- a/src/object/chuchuBossStartParticle.c +++ b/src/object/chuchuBossStartParticle.c @@ -264,7 +264,7 @@ void ChuchuBossStartParticle_Type9(ChuchuBossStartParticleEntity* this) { DeleteThisEntity(); } - if (gPlayerState.field_0x1c != 1) { + if (gPlayerState.gustJarState != 1) { DeleteThisEntity(); } } else { 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..2ab38f90 100644 --- a/src/object/evilSpirit.c +++ b/src/object/evilSpirit.c @@ -83,11 +83,12 @@ 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) ^ - 0x80; + 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) { super->direction += 3; @@ -178,7 +179,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/gustJarParticle.c b/src/object/gustJarParticle.c index afbc0aa1..0da0d398 100644 --- a/src/object/gustJarParticle.c +++ b/src/object/gustJarParticle.c @@ -44,7 +44,7 @@ void GustJarParticle_Action1(Entity* this) { if (sub_0806F3E4(this)) { DeleteThisEntity(); - } else if ((gPlayerState.field_0x1c & 0xf) != 1) { + } else if ((gPlayerState.gustJarState & 0xf) != 1) { DeleteThisEntity(); } } diff --git a/src/object/itemForSale.c b/src/object/itemForSale.c index 0b99381d..60cfe8f2 100644 --- a/src/object/itemForSale.c +++ b/src/object/itemForSale.c @@ -91,7 +91,7 @@ void ItemForSale_Action1(ItemForSaleEntity* this) { PausePlayer(); ResetActiveItems(); gPlayerState.heldObject = 4; - gPlayerEntity.unk_74 = super; + gPlayerEntity.carriedEntity = super; gUnk_0200AF00.rActionPlayerState = R_ACTION_DROP; MessageClose(); } @@ -104,7 +104,7 @@ void ItemForSale_Action2(ItemForSaleEntity* this) { gUnk_0200AF00.rActionPlayerState = R_ACTION_DROP; super->spriteSettings.draw = gPlayerEntity.base.spriteSettings.draw; - if ((gPlayerState.heldObject == 0) || (super != gPlayerEntity.unk_74)) { + if ((gPlayerState.heldObject == 0) || (super != gPlayerEntity.carriedEntity)) { sub_080819B4(this); } else { ptr = sub_080784E4(); @@ -129,7 +129,7 @@ void sub_080819B4(ItemForSaleEntity* this) { DeleteThisEntity(); } gPlayerState.heldObject = 0; - gPlayerEntity.unk_74 = 0; + gPlayerEntity.carriedEntity = 0; ptr = &gUnk_0200AF00; gRoomVars.shopItemType = 0; ptr->rActionInteractObject = R_ACTION_NONE; 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/lilypadLarge.c b/src/object/lilypadLarge.c index d90c1610..b34360a2 100644 --- a/src/object/lilypadLarge.c +++ b/src/object/lilypadLarge.c @@ -125,8 +125,8 @@ void LilypadLarge_Action1(LilypadLargeEntity* this) { this->unk_70 = 0; this->unk_6c = 0; } - if (gPlayerState.field_0x1c == 3) { - tmp = gUnk_08120620[gPlayerState.gustJarSpeed - 1]; + if (gPlayerState.gustJarState == PL_JAR_3) { + tmp = gUnk_08120620[gPlayerState.gustJarCharge - 1]; switch (gPlayerEntity.base.animationState & 6) { case 4: this->unk_70 -= tmp; @@ -154,7 +154,7 @@ void LilypadLarge_Action1(LilypadLargeEntity* this) { uVar4 = gPlayerEntity.base.y.HALF.HI + gUnk_08126EE4[gPlayerEntity.base.animationState | 1]; super->direction = CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, sVar10, uVar4); - switch (gPlayerState.gustJarSpeed) { + switch (gPlayerState.gustJarCharge) { case 3: tmp = 0x400; break; diff --git a/src/object/minecart.c b/src/object/minecart.c index 30594d6d..58138b3b 100644 --- a/src/object/minecart.c +++ b/src/object/minecart.c @@ -70,7 +70,7 @@ void Minecart_Action1(MinecartEntity* this) { SoundReq(SFX_13B); } else { if (sub_0800445C(super) != 0) { - if (!((gPlayerState.flags & (PL_MINISH | PL_ROLLING)) || gPlayerState.field_0x1c || + if (!((gPlayerState.flags & (PL_MINISH | PL_ROLLING)) || gPlayerState.gustJarState || gPlayerState.heldObject || gPlayerState.jump_status)) { super->timer++; } else { 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/objectA8.c b/src/object/objectA8.c index 4f602fd0..c5e95687 100644 --- a/src/object/objectA8.c +++ b/src/object/objectA8.c @@ -116,7 +116,7 @@ void ObjectA8_Action2Subaction0(ObjectA8Entity* this) { } void ObjectA8_Action2Subaction1(ObjectA8Entity* this) { - if ((gPlayerState.field_0x1c & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) { + if ((gPlayerState.gustJarState & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) { super->action = 3; } else { sub_0806F4E8(super); @@ -124,7 +124,7 @@ void ObjectA8_Action2Subaction1(ObjectA8Entity* this) { } void ObjectA8_Action2Subaction2(ObjectA8Entity* this) { - if ((gPlayerState.field_0x1c & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) { + if ((gPlayerState.gustJarState & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) { super->action = 3; } else { if (sub_0806F3E4(super)) { diff --git a/src/object/objectOnSpinyBeetle.c b/src/object/objectOnSpinyBeetle.c index fda7b417..52c575ca 100644 --- a/src/object/objectOnSpinyBeetle.c +++ b/src/object/objectOnSpinyBeetle.c @@ -204,7 +204,7 @@ void ObjectOnSpinyBeetle_Action3Subaction0(ObjectOnSpinyBeetleEntity* this) { } void ObjectOnSpinyBeetle_Action3Subaction1(ObjectOnSpinyBeetleEntity* this) { - if ((gPlayerState.field_0x1c & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) { + if ((gPlayerState.gustJarState & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) { super->spriteOffsetX = 0; super->action = 1; } else { @@ -219,7 +219,7 @@ void ObjectOnSpinyBeetle_Action3Subaction2(ObjectOnSpinyBeetleEntity* this) { super->spriteOffsetY = -2; (super->parent)->child = NULL; } - if ((gPlayerState.field_0x1c & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) { + if ((gPlayerState.gustJarState & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) { sub_080989C0(this); } else { if ((sub_0806F3E4(super) != 0) && (super->type == 0)) { @@ -229,7 +229,7 @@ void ObjectOnSpinyBeetle_Action3Subaction2(ObjectOnSpinyBeetleEntity* this) { } void ObjectOnSpinyBeetle_Action3Subaction3(ObjectOnSpinyBeetleEntity* this) { - if (gPlayerState.field_0x1c == 0) { + if (gPlayerState.gustJarState == 0) { sub_080989C0(this); } else { (this->base).flags &= ~ENT_COLLIDE; diff --git a/src/object/octorokBossObject.c b/src/object/octorokBossObject.c index ddab7bce..075c858f 100644 --- a/src/object/octorokBossObject.c +++ b/src/object/octorokBossObject.c @@ -181,8 +181,8 @@ void OctorokBossObject_Action1(OctorokBossObjectEntity* this) { return; } case 1: - super->direction = sub_080045DA(this->helper->tailObjects[super->timer]->x.WORD - super->x.WORD, - this->helper->tailObjects[super->timer]->y.WORD - super->y.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) { return; @@ -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/pot.c b/src/object/pot.c index 444c14bb..150705f2 100644 --- a/src/object/pot.c +++ b/src/object/pot.c @@ -250,7 +250,7 @@ void sub_080826FC(PotEntity* this) { } void sub_0808270C(PotEntity* this) { - if ((gPlayerState.field_0x1c & 0xF) != 0x1 || (super->contactFlags & 0x7F) != 0x13) { + if ((gPlayerState.gustJarState & 0xF) != 0x1 || (super->contactFlags & 0x7F) != 0x13) { super->spriteOffsetX = 0; super->action = 1; SetBottomTile(0x4000, COORD_TO_TILE(super), super->collisionLayer); @@ -267,7 +267,7 @@ void sub_08082778(PotEntity* this) { SetBottomTile((u16)this->unk_70, COORD_TO_TILE(super), super->collisionLayer); } - if ((gPlayerState.field_0x1c & 0xF) != 0x1 || (super->contactFlags & 0x7F) != 0x13) { + if ((gPlayerState.gustJarState & 0xF) != 0x1 || (super->contactFlags & 0x7F) != 0x13) { BreakPot(this, NULL); } else { sub_0806F3E4(super); @@ -275,7 +275,7 @@ void sub_08082778(PotEntity* this) { } void sub_080827F8(PotEntity* this) { - if (gPlayerState.field_0x1c == 0) { + if (gPlayerState.gustJarState == 0) { BreakPot(this, NULL); } } diff --git a/src/object/pullableMushroom.c b/src/object/pullableMushroom.c index de90f11d..17333ae3 100644 --- a/src/object/pullableMushroom.c +++ b/src/object/pullableMushroom.c @@ -65,7 +65,7 @@ void PullableMushroom_Init(PullableMushroomEntity* this) { super->hitType = 0x6e; super->collisionMask = 0x0e; super->gustJarFlags = 1; - super->flags |= 0x80; + COLLISION_ON(super); super->spriteOffsetY = 4; break; case 1: @@ -116,13 +116,14 @@ void PullableMushroom_Action1_Type0(PullableMushroomEntity* this) { } void PullableMushroom_Action1_Type1(PullableMushroomEntity* this) { - if (*(u16*)&super->parent->action == 0x201) { + if (super->parent->action == 1 && super->parent->subAction == 2) { super->parent->child = NULL; DeleteThisEntity(); } else if (super->parent->action == 2) { sub_0808B168(this, 0); } } + void sub_0808ABC4(PullableMushroomEntity* this) { static const s8 gUnk_081211CC[] = { 0, -128, 0, -6, 0, 0, 5, -4, 0, 0, 0, 0, 0, -128, -5, -4 }; u32 tmp; @@ -292,7 +293,7 @@ void sub_0808AEB0(PullableMushroomEntity* this) { this->unk_7c = 1; super->animationState = AnimationStateFlip90(gPlayerEntity.base.animationState >> 1); super->direction = (super->animationState << 3); - super->flags &= ~0x80; + COLLISION_OFF(super); super->spriteSettings.flipX = gPlayerEntity.base.spriteSettings.flipX; InitializeAnimation(super, super->animationState + 5); if (sub_0808B21C(this, 0)) { @@ -320,7 +321,7 @@ void PullableMushroom_Action3(PullableMushroomEntity* this) { }; funcs[super->subAction](this); - if ((((gPlayerState.field_0x1c & 0xf) != 1) || ((super->contactFlags & 0x7f) != 0x13)) && (super->type == 1)) { + if ((((gPlayerState.gustJarState & 0xf) != 1) || ((super->contactFlags & 0x7f) != 0x13)) && (super->type == 1)) { (super->parent)->action = 1; (super->parent)->subAction = 1; super->direction = DirectionTurnAround(super->parent->direction); @@ -336,7 +337,7 @@ void sub_0808B05C(PullableMushroomEntity* this) { super->animationState = AnimationStateFlip90(gPlayerEntity.base.animationState >> 1); super->direction = super->animationState << 3; super->spriteSettings.flipX = gPlayerEntity.base.spriteSettings.flipX; - super->flags &= ~0x80; + COLLISION_OFF(super); InitializeAnimation(super, super->animationState + 5); if (sub_0808B21C(this, 1)) { sub_0808B168((PullableMushroomEntity*)super->child, 1); 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/physics.c b/src/physics.c index 421c2474..7daea2e3 100644 --- a/src/physics.c +++ b/src/physics.c @@ -55,16 +55,16 @@ bool32 sub_0806F3E4(Entity* ent) { GenericEntity tmp_ent; s8* p; - if ((gPlayerState.field_0x1c & 0x7F) != 1) + if ((gPlayerState.gustJarState & 0x7F) != PL_JAR_SUCK) return 0; - switch (gPlayerState.gustJarSpeed) { - case 1: + switch (gPlayerState.gustJarCharge) { + case JAR_CHARGE_SMALL: ent->knockbackSpeed += 64; break; - case 2: + case JAR_CHARGE_MID: ent->knockbackSpeed += 128; break; - case 3: + case JAR_CHARGE_BIG: ent->knockbackSpeed += 192; break; } @@ -76,18 +76,18 @@ bool32 sub_0806F3E4(Entity* ent) { LinearMoveDirection(ent, ent->knockbackSpeed, GetFacingDirection(ent, &tmp_ent.base)); if (sub_0800419C(&tmp_ent.base, ent, 4, 4)) { u32 state = ent->gustJarFlags & 0xF; - if (state == 2) { + if (state == PL_JAR_2) { Entity* item; ent->subAction = 3; - gPlayerEntity.unk_70 = ent; - gPlayerState.field_0x1c = 7; + gPlayerEntity.pulledJarEntity = ent; + gPlayerState.gustJarState = PL_JAR_ENT_ATTACHED; item = CreatePlayerItem(PLAYER_ITEM_GUST_BIG, 0, 0, 0); if (item != NULL) { item->child = ent; ent->parent = item; } SoundReq(SFX_ED); - } else if (state == 1) { + } else if (state == PL_JAR_SUCK) { gPlayerState.item->type = 1; SoundReq(SFX_EF); } diff --git a/src/player.c b/src/player.c index ffb4ca6c..2ffa311e 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; - } else if (gPlayerState.field_0x1c) { - super->speed = GUST_JAR_SPEED; + super->speed = kWalkSpeedSwordCharge; + } else if (gPlayerState.gustJarState != PL_JAR_NONE) { + 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,14 +884,14 @@ static void sub_08071130(PlayerEntity* this) { LinearMoveUpdate(super); - if (GravityUpdate(super, GRAVITY_RATE)) + if (GravityUpdate(super, kGravityRate)) return; gPlayerState.jump_status = 0; ResetCollisionLayer(super); - if (this->unk_74 != NULL) - ResetCollisionLayer(this->unk_74); + if (this->carriedEntity != NULL) + ResetCollisionLayer(this->carriedEntity); DoTileInteractionHere(super, 7); @@ -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; @@ -1983,7 +1982,7 @@ static void sub_080724DC(PlayerEntity* this) { if (gRoomControls.reload_flags == 0) { super->updatePriority = super->updatePriorityPrev; PlayerWaitForScroll(this); - } else if (gPlayerState.field_0x1c == 0) { + } else if (gPlayerState.gustJarState == PL_JAR_NONE) { UpdateAnimationSingleFrame(super); } } else { @@ -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/playerItem/playerItemGust.c b/src/playerItem/playerItemGust.c index 94fd1bdb..286c06f3 100644 --- a/src/playerItem/playerItemGust.c +++ b/src/playerItem/playerItemGust.c @@ -61,7 +61,7 @@ void PlayerItemGust(Entity* this) { PlayerItemGust_Update, }; - if ((gPlayerState.field_0x1c & 0x7f) != 1) { + if ((gPlayerState.gustJarState & 0x7f) != 1) { DeleteThisEntity(); } PlayerItemGust_Actions[this->action]((PlayerItemGustEntity*)this); diff --git a/src/playerItem/playerItemGustBig.c b/src/playerItem/playerItemGustBig.c index 228ca1a3..566ef948 100644 --- a/src/playerItem/playerItemGustBig.c +++ b/src/playerItem/playerItemGustBig.c @@ -85,7 +85,7 @@ void PlayerItemGustBig_Init(PlayerItemGustBigEntity* this) { super->child->spriteOffsetX = 0; super->child->spriteSettings.draw = 0; } else { - if (gPlayerState.field_0x1c == 0) { + if (gPlayerState.gustJarState == PL_JAR_NONE) { DeleteThisEntity(); } super->action = 2; @@ -93,14 +93,14 @@ void PlayerItemGustBig_Init(PlayerItemGustBigEntity* this) { super->spriteIndex = 0xa6; super->palette.raw = 0x33; super->spriteVramOffset = 0; - super->type = gPlayerState.gustJarSpeed - 1; + super->type = gPlayerState.gustJarCharge - 1; super->timer = gUnk_080B3DE0[super->type * 2]; super->damage = gUnk_080B3DE0[super->type * 2 + 1]; super->hurtType = 0x1b; super->hitbox = (Hitbox*)gUnk_080B3DE8[super->type]; - gPlayerEntity.unk_70 = super; + gPlayerEntity.pulledJarEntity = super; sub_08078CD0(&gPlayerEntity.base); - gPlayerEntity.unk_70 = pEVar3; + gPlayerEntity.pulledJarEntity = pEVar3; InitializeAnimation(super, super->type + 10); sub_08018FA0(super); } @@ -108,18 +108,15 @@ void PlayerItemGustBig_Init(PlayerItemGustBigEntity* this) { } void PlayerItemGustBig_Action1(PlayerItemGustBigEntity* this) { - u8 bVar1; - - bVar1 = super->child->gustJarState & 4; - if (bVar1 == 0) { - gPlayerState.field_0x1c = bVar1; + if ((super->child->gustJarState & 4) == 0) { + gPlayerState.gustJarState = PL_JAR_NONE; DeleteThisEntity(); } - switch (gPlayerState.field_0x1c) { - case 0: + switch (gPlayerState.gustJarState) { + case PL_JAR_NONE: PlayerItemGustBig_Action3(this); break; - case 5: + case PL_JAR_BLAST_UPDATE: super->child->subAction = 4; COLLISION_ON(super); super->action = 2; diff --git a/src/playerItem/playerItemGustJar.c b/src/playerItem/playerItemGustJar.c index b3ebcb29..10cbca1b 100644 --- a/src/playerItem/playerItemGustJar.c +++ b/src/playerItem/playerItemGustJar.c @@ -29,7 +29,7 @@ void PlayerItemGustJar(Entity* this) { PlayerItemGustJar_Action3, PlayerItemGustJar_Action4, }; - if (((Entity*)gPlayerState.item != this) || (gPlayerState.field_0x1c == 0)) { + if (((Entity*)gPlayerState.item != this) || (gPlayerState.gustJarState == PL_JAR_NONE)) { DeleteThisEntity(); } PlayerItemGustJar_Actions[this->action](this); @@ -63,10 +63,10 @@ void PlayerItemGustJar_Action2(Entity* this) { u32 in_r2; int windSound; - if (gPlayerState.field_0x1c == 3) { + if (gPlayerState.gustJarState == PL_JAR_3) { this->action++; InitAnimationForceUpdate(this, (gPlayerEntity.base.animationState >> 1) + 8); - } else if (gPlayerState.field_0x1c == 6) { + } else if (gPlayerState.gustJarState == PL_JAR_BLAST_DONE) { this->action = 4; InitAnimationForceUpdate(this, (gPlayerEntity.base.animationState >> 1) + 4); } else { @@ -84,11 +84,11 @@ void PlayerItemGustJar_Action2(Entity* this) { } } } else { - if ((gPlayerState.field_0x1c & 0xf) == 7) { + if ((gPlayerState.gustJarState & 0xf) == PL_JAR_ENT_ATTACHED) { this->frameDuration = 0x7f; } - switch (gPlayerState.gustJarSpeed) { + switch (gPlayerState.gustJarCharge) { case 3: sub_080ADCDC(this, 3); this->palette.b.b0 = 0; @@ -109,7 +109,7 @@ void PlayerItemGustJar_Action2(Entity* this) { break; } - if ((gPlayerState.field_0x1c & 0xf) == 7) { + if ((gPlayerState.gustJarState & 0xf) == PL_JAR_ENT_ATTACHED) { windSound = SFX_EE; in_r2 = 1; } @@ -126,12 +126,12 @@ void PlayerItemGustJar_Action2(Entity* this) { } void PlayerItemGustJar_Action3(Entity* this) { - switch (gPlayerState.field_0x1c & 0xf) { - case 6: + switch (gPlayerState.gustJarState & 0xf) { + case PL_JAR_BLAST_DONE: this->action++; InitAnimationForceUpdate(this, (gPlayerEntity.base.animationState >> 1) + 4); break; - case 1: + case PL_JAR_SUCK: sub_080ADCA0(this, 0); this->action = 2; break; diff --git a/src/playerItem/playerItemHeldObject.c b/src/playerItem/playerItemHeldObject.c index 520d8359..f20236d4 100644 --- a/src/playerItem/playerItemHeldObject.c +++ b/src/playerItem/playerItemHeldObject.c @@ -235,7 +235,7 @@ void sub_080AD27C(PlayerItemHeldObjectEntity* this) { static const u32 gUnk_081320D4[] = { Q_16_16(0), Q_16_16(0.5), Q_16_16(1.25), Q_16_16(1.25) }; u32 tmp; PlayerItemHeldObjectEntity* child = (PlayerItemHeldObjectEntity*)super->child; - gPlayerEntity.unk_74 = NULL; + gPlayerEntity.carriedEntity = NULL; if ((this->unk_6c == (u16)(child->base).kind) && (this->unk_6e == (u16)(child->base).id)) { if (child != this) { (child->base).subAction = 2; diff --git a/src/playerUtils.c b/src/playerUtils.c index 85656344..ba020870 100644 --- a/src/playerUtils.c +++ b/src/playerUtils.c @@ -229,7 +229,7 @@ bool32 IsPreventedFromUsingItem(void) { } return FALSE; default: - if ((((gUnk_0200AF00.rActionInteractObject == R_ACTION_ROLL) && (gPlayerState.field_0x1c == 0)) && + if ((((gUnk_0200AF00.rActionInteractObject == R_ACTION_ROLL) && (gPlayerState.gustJarState == 0)) && (gPlayerState.floor_type != SURFACE_SWAMP)) && ((((gPlayerState.playerInput.heldInput & INPUT_ANY_DIRECTION) != 0 && ((gPlayerState.flags & (PL_BURNING | PL_ROLLING)) == 0)) && @@ -339,7 +339,7 @@ ItemBehavior* CreateItem3(Item itemId) { gItemDefinitions[itemId].priority >= gActiveItems[ACTIVE_ITEM_0].priority) { DeleteItemBehavior(&gActiveItems[ACTIVE_ITEM_0], 0); gPlayerState.grab_status = 0; - gPlayerState.field_0x1c = 0; + gPlayerState.gustJarState = 0; gPlayerState.sword_state = 0; return &gActiveItems[ACTIVE_ITEM_0]; } @@ -395,7 +395,7 @@ void ResetActiveItems() { } gPlayerState.moleMittsState = 0; - gPlayerState.field_0x1c = 0; + gPlayerState.gustJarState = PL_JAR_NONE; gPlayerState.bow_state = 0; gPlayerState.grab_status = 0; gPlayerState.itemAnimPriority = 0; @@ -405,7 +405,7 @@ void ResetActiveItems() { gPlayerState.heldObject = 0; gPlayerState.flags &= ~(PL_ROLLING | PL_SWORD_THRUST); - gPlayerEntity.unk_70 = NULL; + gPlayerEntity.pulledJarEntity = NULL; if ((gPlayerState.jump_status & 0xc0) == 0) { gPlayerState.jump_status = 0; @@ -1104,7 +1104,8 @@ bool32 sub_080782C0(void) { if (gPlayerState.heldObject != 4) { return FALSE; } - if ((gPlayerEntity.unk_74)->child->kind != OBJECT || (gPlayerEntity.unk_74)->child->id != SHOP_ITEM) { + if ((gPlayerEntity.carriedEntity)->child->kind != OBJECT || + (gPlayerEntity.carriedEntity)->child->id != SHOP_ITEM) { return FALSE; } } @@ -1580,7 +1581,7 @@ void sub_08078CD0(PlayerEntity* this) { u32 tmp; const s8* ptr; - entity = this->unk_70; + entity = this->pulledJarEntity; entity->z.HALF.HI = super->z.HALF.HI - 1; entity->spriteOrientation.flipY = super->spriteOrientation.flipY; entity->collisionLayer = super->collisionLayer; @@ -1605,7 +1606,7 @@ void sub_08078D60(void) { Entity* player; player = &gPlayerEntity.base; - iVar4 = (*(Entity**)&((GenericEntity*)player)->field_0x74)->child; + iVar4 = ((PlayerEntity*)player)->carriedEntity->child; if (iVar4->action != 2) return; @@ -1815,7 +1816,7 @@ void sub_080790E4(Entity* this) { void PlayerDropHeldObject(void) { gPlayerState.heldObject = 0; gPlayerState.grab_status = 0; - gPlayerEntity.unk_74 = NULL; + gPlayerEntity.carriedEntity = NULL; } void PlayerResetStateFromFusion(void) { @@ -2109,7 +2110,7 @@ void sub_080797EC(void) { animation = ANIM_BOW_WALK; } } else { - if (gPlayerState.field_0x1c) { + if (gPlayerState.gustJarState) { return; } else if (gPlayerState.heldObject) { animation = ANIM_CARRY; @@ -2166,7 +2167,7 @@ void ResolvePlayerAnimation(void) { if (gPlayerState.heldObject) { anim = ANIM_CARRY_STAND_NOCAP; } else { - if (gPlayerState.field_0x1c | gPlayerState.moleMittsState) { + if (gPlayerState.gustJarState | gPlayerState.moleMittsState) { return; } if (gPlayerState.flags & PL_CONVEYOR_PUSHED) { @@ -2209,7 +2210,7 @@ void ResolvePlayerAnimation(void) { if (gPlayerState.heldObject) { anim = ANIM_CARRY_STAND; } else { - if (gPlayerState.field_0x1c | gPlayerState.moleMittsState) { + if (gPlayerState.gustJarState | gPlayerState.moleMittsState) { return; } if (gPlayerState.flags & PL_MOLDWORM_CAPTURED) { @@ -2722,7 +2723,7 @@ void sub_0807A5B8(u32 direction) { pbVar4 = gUnk_0800833C; } else if (((gPlayerState.flags & PL_PARACHUTE) != 0) || gPlayerState.jump_status != 0) { pbVar4 = gUnk_0800845C; - } else if (gPlayerState.heldObject != 0 || gPlayerState.field_0x1c != 0) { + } else if (gPlayerState.heldObject != 0 || gPlayerState.gustJarState != 0) { pbVar4 = gUnk_080084BC; } else if (gPlayerState.attachedBeetleCount != 0) { pbVar4 = gUnk_0800851C; 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;