diff --git a/include/entity.h b/include/entity.h index 7440c198..c4537dce 100644 --- a/include/entity.h +++ b/include/entity.h @@ -175,6 +175,8 @@ extern void PositionRelative(Entity*, Entity*, s32, s32); #define DirectionIsVertical(expr) ((expr) & 0x10) #define DirectionTurnHorizontal(expr) (DirectionRoundUp(expr) ^ 0x08) #define DirectionTurnVertical(expr) (DirectionRoundUp(expr) ^ 0x10) +#define DirectionToAnimationState(expr) (DirectionRoundUp(expr) >> 3) +#define DirectionFromAnimationState(expr) (expr << 3) extern Entity gUnk_03003DA0; diff --git a/src/enemy/darkNut.c b/src/enemy/darkNut.c index 03c9c91e..b7e5bf0f 100644 --- a/src/enemy/darkNut.c +++ b/src/enemy/darkNut.c @@ -62,7 +62,7 @@ void sub_08020BB8(Entity* this) { this->action = 11; this->actionDelay = gUnk_080CAB0C[this->entityType.form]; this->damageType = 81; - sub_08021218(this, 8, (((this->field_0x3e ^ 0x10) + 4) & 0x18) >> 3); + sub_08021218(this, 8, DirectionToAnimationState(this->field_0x3e ^ 0x10)); sub_08021588(this); sub_0804A9FC(this, 0x1c); break; @@ -70,7 +70,7 @@ void sub_08020BB8(Entity* this) { this->action = 11; this->actionDelay = gUnk_080CAB10[this->entityType.form]; this->damageType = 81; - sub_08021218(this, 8, (((this->field_0x3e ^ 0x10) + 4) & 0x18) >> 3); + sub_08021218(this, 8, DirectionToAnimationState(this->field_0x3e ^ 0x10)); sub_08021588(this); sub_0804A9FC(this, 0x1c); break; @@ -427,7 +427,7 @@ void sub_08021328(Entity* this) { void sub_0802134C(Entity* this) { this->action = 15; - this->direction = this->animationState << 3; + this->direction = DirectionFromAnimationState(this->animationState); this->nonPlanarMovement = 0x200; this->field_0x76.HWORD = 0x78; sub_08021218(this, 0xe, this->animationState); @@ -534,7 +534,7 @@ u32 sub_080214FC(Entity* this) { if (4 < (direction - (this->frames.all & 0x1f)) - 2) return 0; - this->animationState = ((direction + 4) & 0x18) >> 3; + this->animationState = DirectionToAnimationState(direction); return 1; } @@ -544,9 +544,9 @@ void sub_08021540(Entity* this) { rand = Random(); if (!sub_08049FA0(this) && (rand & 1)) { - tmp2 = (sub_08049EE4(this) + 4) & 0x18; + tmp2 = DirectionRoundUp(sub_08049EE4(this)); } else { - tmp2 = (rand >> 0x10) & 0x18; + tmp2 = DirectionRound(rand >> 0x10); } this->direction = tmp2; diff --git a/src/enemy/fireballGuy.c b/src/enemy/fireballGuy.c index b194ed07..bd033058 100644 --- a/src/enemy/fireballGuy.c +++ b/src/enemy/fireballGuy.c @@ -102,7 +102,7 @@ void sub_08045524(Entity *this) { tmp = sub_0804A024(this,1,8); if (tmp != 0xff && (Random() & 3) == 0) { this->actionDelay = Random() & 3; - this->direction = tmp & 0x18; + this->direction = DirectionRound(tmp); } else { if (this->actionDelay) { this->actionDelay--; @@ -113,9 +113,9 @@ void sub_08045524(Entity *this) { tmp1 = sub_08049EE4(this); tmp2 = Random() & 8; tmp2 += 0xfc; - this->direction = (tmp1 + tmp2) & 0x18; + this->direction = DirectionRound(tmp1 + tmp2); } else { - this->direction = Random() & 0x18; + this->direction = DirectionRound(Random()); } } } diff --git a/src/enemy/keaton.c b/src/enemy/keaton.c index afc0e4b6..b900cfea 100644 --- a/src/enemy/keaton.c +++ b/src/enemy/keaton.c @@ -37,9 +37,8 @@ void sub_080323F4(Entity* this) { if (this->action != 3 && this->action != 4) { this->action = 3; this->actionDelay = 0xC; - var = ((this->field_0x3e + 4) & 0x18) ^ 0x10; - this->direction = var; - InitAnimationForceUpdate(this, var >> 3); + this->direction = DirectionTurnVertical(this->field_0x3e); + InitAnimationForceUpdate(this, this->direction >> 3); } else if (this->bitfield == 0xCC) { if (this->field_0x43 == 0) { sub_0803275C(this); @@ -142,10 +141,10 @@ void sub_080325C4(Entity* this) { u32 sub_080325E8(Entity* this) { if (((sub_08049FA0(this) != 0) && (sub_08049FDC(this, 1) != 0)) && (sub_080041A0(this, gUnk_020000B0, 0x68, 0x40) != 0)) { - if (((GetFacingDirection(this, gUnk_020000B0) - ((this->frames.all & 0x18)) + 2) & 0x1F) < 5) { + if (((GetFacingDirection(this, gUnk_020000B0) - (DirectionRound(this->frames.all)) + 2) & 0x1F) < 5) { this->action = 3; this->actionDelay = 0xC; - this->direction = this->frames.all & 0x18; + this->direction = DirectionRound(this->frames.all); return 1; } } @@ -158,9 +157,9 @@ void sub_08032650(Entity* this) { uVar3 = Random(); this->actionDelay = gUnk_080CE7E0[uVar3 & 0xf]; if (!((sub_08049FA0(this) == 0) && ((uVar3 >> 8 & 1) == 0))) { - this->direction = (uVar3 >> 0x10) & 0x18; + this->direction = DirectionRound(uVar3 >> 0x10); } else { - this->direction = (sub_08049EE4(this) + 4) & 0x18; + this->direction = DirectionRoundUp(sub_08049EE4(this)); } sub_0803269C(this, this->direction); } @@ -169,13 +168,13 @@ void sub_0803269C(Entity* this, u32 param_2) { u32 uVar1; if (((param_2 - 3) & 7) < 3) { - uVar1 = ((param_2 + 4) & 0x18) >> 3; + uVar1 = DirectionToAnimationState(param_2); if (((this->animationState - uVar1) & 3) > 1) { this->animationState = uVar1; InitAnimationForceUpdate(this, (this->animIndex & 0xFC) + uVar1); } } else { - uVar1 = ((param_2 + 4) & 0x18) >> 3; + uVar1 = DirectionToAnimationState(param_2); if (uVar1 != this->animationState) { this->animationState = uVar1; InitAnimationForceUpdate(this, (this->animIndex & 0xFC) + uVar1); diff --git a/src/enemy/lakitu.c b/src/enemy/lakitu.c index b4bbc198..cf41451e 100644 --- a/src/enemy/lakitu.c +++ b/src/enemy/lakitu.c @@ -280,8 +280,7 @@ void sub_0803CA84(Entity *this, u32 unkParameter) { u32 altAnimState = GetFacingDirection(this, &gPlayerEntity); if (((altAnimState - 3) & 7) > 2 || ((this->animationState - (altAnimState >> 3)) & 3) > 1) { - u32 intermediate = (altAnimState + 4) & 0x18; - altAnimState = intermediate >> 3; + altAnimState = DirectionRoundUp(altAnimState) >> 3; if (altAnimState != this->animationState) { this->animationState = altAnimState; diff --git a/src/enemy/leever.c b/src/enemy/leever.c index 959d8617..a71c28c0 100644 --- a/src/enemy/leever.c +++ b/src/enemy/leever.c @@ -79,7 +79,7 @@ void Leever_Idle(Entity* this) { InitializeAnimation(this, LeeverAnimation_DigUp); UpdateSpriteForCollisionLayer(this); } else { - this->actionDelay = (Random() & 0x18) + 8; + this->actionDelay = DirectionRound(Random()) + 8; } } } diff --git a/src/enemy/miniFireballGuy.c b/src/enemy/miniFireballGuy.c index 9ca6ad24..e9cc6eee 100644 --- a/src/enemy/miniFireballGuy.c +++ b/src/enemy/miniFireballGuy.c @@ -11,66 +11,59 @@ extern void sub_08045678(Entity*); extern void (*const gUnk_080D1868[])(Entity*); extern void (*const gUnk_080D1880[])(Entity*); -void MiniFireballGuy(Entity *this) -{ - EnemyFunctionHandler(this, gUnk_080D1868); +void MiniFireballGuy(Entity* this) { + EnemyFunctionHandler(this, gUnk_080D1868); } -void sub_080455BC(Entity *this) -{ - gUnk_080D1880[this->action](this); +void sub_080455BC(Entity* this) { + gUnk_080D1880[this->action](this); } -void sub_080455D4(Entity *this) -{ - sub_0804AA30(this, gUnk_080D1868); +void sub_080455D4(Entity* this) { + sub_0804AA30(this, gUnk_080D1868); } -void sub_080455E4(Entity *this) -{ - if ((this != this->parent) && (this->parent != NULL)) { - this->field_0x6c.HALF.LO &= 0x7f; - this->parent->attachedEntity = this->attachedEntity; - this->attachedEntity->parent = this->parent; - } - sub_0804A7D4(this); +void sub_080455E4(Entity* this) { + if ((this != this->parent) && (this->parent != NULL)) { + this->field_0x6c.HALF.LO &= 0x7f; + this->parent->attachedEntity = this->attachedEntity; + this->attachedEntity->parent = this->parent; + } + sub_0804A7D4(this); } -void nullsub_23(Entity* this) {} - -void sub_08045618(Entity *this) -{ - this->action = 1; - this->spriteSettings.b.draw = 1; - this->nonPlanarMovement = 0x80; - this->field_0x3c = this->field_0x3c | 0x10; - sub_0804A720(this); - InitializeAnimation(this, 1); - sub_08045678(this); +void nullsub_23(Entity* this) { } -void sub_08045654(Entity *this) -{ - sub_080AEFE0(this); - GetNextFrame(this); - if (sub_08003FC4(this, 0x1800) == 0) { +void sub_08045618(Entity* this) { + this->action = 1; + this->spriteSettings.b.draw = 1; + this->nonPlanarMovement = 0x80; + this->field_0x3c = this->field_0x3c | 0x10; + sub_0804A720(this); + InitializeAnimation(this, 1); sub_08045678(this); - } } -void sub_08045678(Entity *this) -{ - - this->field_0x20 = 0x1c000; - if (this->actionDelay != 0) { - this->actionDelay--; - } else { - this->actionDelay = Random() & 3; - if ((sub_08049FA0(this) == 0) && (Random() & 3)) { - this->direction = (sub_08049EE4(this) - 4 + (Random() & 8)) & 0x18; +void sub_08045654(Entity* this) { + sub_080AEFE0(this); + GetNextFrame(this); + if (sub_08003FC4(this, 0x1800) == 0) { + sub_08045678(this); } - else { - this->direction = Random() & 0x18; +} + +void sub_08045678(Entity* this) { + + this->field_0x20 = 0x1c000; + if (this->actionDelay != 0) { + this->actionDelay--; + } else { + this->actionDelay = Random() & 3; + if ((sub_08049FA0(this) == 0) && (Random() & 3)) { + this->direction = DirectionRound(sub_08049EE4(this) - 4 + (Random() & 8)); + } else { + this->direction = DirectionRound(Random()); + } } - } } \ No newline at end of file diff --git a/src/enemy/miniSlime.c b/src/enemy/miniSlime.c index 70b1a029..973f8839 100644 --- a/src/enemy/miniSlime.c +++ b/src/enemy/miniSlime.c @@ -78,9 +78,9 @@ void sub_080452FC(Entity *this) { cVar2 = sub_08049EE4(this); bVar3 = Random() & 8; bVar3 += 0xfc; - this->direction = (cVar2 + bVar3) & 0x18; + this->direction = DirectionRound(cVar2 + bVar3); } else { - this->direction = Random() & 0x18; + this->direction = DirectionRound(Random()); sub_08045374(this); } } diff --git a/src/enemy/rollobite.c b/src/enemy/rollobite.c index 45d6f118..74e80188 100644 --- a/src/enemy/rollobite.c +++ b/src/enemy/rollobite.c @@ -110,7 +110,7 @@ void Rollobite_Initialize(Entity* this) { this->field_0x16 = 0x30; this->field_0x1c = 18; this->cutsceneBeh.HALF.LO = 0; - this->direction = Random() & 0x18; + this->direction = DirectionRound(Random()); sub_08020A30(this); } @@ -197,7 +197,7 @@ void Rollobite_Unroll(Entity* this) { this->nonPlanarMovement = 0x100; this->damageType = 34; sub_08020A30(this); - this->direction = this->animationState << 3; + this->direction = DirectionFromAnimationState(this->animationState); InitializeAnimation(this, this->animationState); } else { if ((this->frames.all & 1) == 0) @@ -236,10 +236,10 @@ void sub_08020A30(Entity* this) { void sub_08020A7C(Entity* this) { int tmp = Random(); - u32 state = (this->direction + gUnk_080CA6D4[tmp % 3]) & 0x18; + u32 state = DirectionRound(this->direction + gUnk_080CA6D4[tmp % 3]); if (sub_08049FA0(this) == 0) { - int tmp = (sub_08049EE4(this) + 4) & 0x18; + int tmp = DirectionRoundUp(sub_08049EE4(this)); if ((state ^ 0x10) == tmp) state ^= 0x10; } diff --git a/src/npc/townsperson.c b/src/npc/townsperson.c index 242d85a1..d1951553 100644 --- a/src/npc/townsperson.c +++ b/src/npc/townsperson.c @@ -192,7 +192,7 @@ void sub_08061E90(Entity* this, Entity* arg1) { if (arg1->spriteSettings.raw == 0) { arg1->spriteSettings.raw++; arg1->spriteIndex = (Random() & 0x3f) + 0x20; - animIndex = Random() & 0x18; + animIndex = DirectionRound(Random()); switch (this->direction) { case 0x0: if (animIndex == 0x10) { diff --git a/src/object/minecart.c b/src/object/minecart.c index 783e9696..9207c8c0 100644 --- a/src/object/minecart.c +++ b/src/object/minecart.c @@ -50,7 +50,7 @@ void sub_080916EC(Entity* this) { this->field_0x3c = 0x47; this->field_0x40 = 0x44; this->flags2 = 0x80; - this->direction = this->animationState << 3; + this->direction = DirectionFromAnimationState(this->animationState); this->nonPlanarMovement = 0x700; this->spritePriority.b1 = 3; InitAnimationForceUpdate(this, this->entityType.parameter + 4 + this->animationState);