diff options
| author | theo3 <arisstephenson2@gmail.com> | 2021-12-14 23:31:27 -0800 |
|---|---|---|
| committer | theo3 <arisstephenson2@gmail.com> | 2021-12-14 23:31:27 -0800 |
| commit | 34e69959df548688ef8535eb4cab18e5a53992a8 (patch) | |
| tree | d5a822be15b8f06323912e90ad2a25746b47b76e /src | |
| parent | 83fc0285020c456beb809d9918515ad1c1c73245 (diff) | |
cleanup
Diffstat (limited to 'src')
110 files changed, 1220 insertions, 1035 deletions
diff --git a/src/collision.c b/src/collision.c index 026724ed..9d3380e4 100644 --- a/src/collision.c +++ b/src/collision.c @@ -65,7 +65,7 @@ void CollisionMain(void) { doCollision = &gDoCollision; // Check to see if we should disable collision this frame - if (gPlayerState.field_0x8b != 0) { + if (gPlayerState.controlMode != CONTROL_ENABLED) { u32 flags = gPlayerEntity.flags; COLLISION_OFF(&gPlayerEntity); doCollision(); diff --git a/src/coord.c b/src/coord.c index 82d994ea..ffa12162 100644 --- a/src/coord.c +++ b/src/coord.c @@ -29,7 +29,7 @@ void PositionEntityOnTop(Entity* ent, Entity* ent2) { ResolveEntityOnTop(ent, ent2); } -void PositionRelative(Entity* source, Entity* target, s32 offsetX, s32 offsetY) { // r0, r1, r2, r3 +void PositionRelative(Entity* source, Entity* target, s32 offsetX, s32 offsetY) { s32 x; s32 y; @@ -39,7 +39,7 @@ void PositionRelative(Entity* source, Entity* target, s32 offsetX, s32 offsetY) y = source->y.WORD; target->y.WORD = y + offsetY; - target->z = source->z; // ldr + target->z = source->z; target->collisionLayer = source->collisionLayer; UpdateSpriteForCollisionLayer(target); } diff --git a/src/createEnemy.c b/src/createEnemy.c index 73eb5e5c..b67546a1 100644 --- a/src/createEnemy.c +++ b/src/createEnemy.c @@ -6,7 +6,7 @@ Entity* CreateEnemy(u32 subtype, u32 form) { enemy = GetEmptyEntity(); if (enemy != NULL) { - enemy->kind = 3; + enemy->kind = ENEMY; enemy->id = subtype; enemy->type = form; AppendEntityToList(enemy, 4); diff --git a/src/debugScreen.c b/src/debugScreen.c index a12ec0a1..dcd22601 100644 --- a/src/debugScreen.c +++ b/src/debugScreen.c @@ -17,12 +17,12 @@ void sub_0805FA04(void) { DispReset(1); MemClear(&gBG0Buffer, sizeof(gBG0Buffer)); MemClear(&gBG3Buffer, sizeof(gBG3Buffer)); - gScreen.lcd.displayControl = 0x940; + gScreen.lcd.displayControl = DISPCNT_BG0_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_1D_MAP; gScreen.bg0.xOffset = 0; gScreen.bg0.yOffset = 0; gScreen.bg3.xOffset = 0; gScreen.bg3.yOffset = 0; - gScreen.bg3.control = 0x1e0f; + gScreen.bg3.control = BGCNT_SCREENBASE(30) | BGCNT_PRIORITY(3) | BGCNT_CHARBASE(3); gScreen.bg3.updated = 1; MessageInitialize(); MemClear((void*)&gUnk_02032EC0, sizeof(UI)); @@ -39,35 +39,35 @@ void sub_0805FA98(void) { int iVar1; switch (gInput.newKeys) { - case 0x40: + case DPAD_UP: gMenu.focusCoords[1] -= 1; break; - case 0x80: + case DPAD_DOWN: gMenu.focusCoords[1] += 1; break; - case 0x200: + case L_BUTTON: gMenu.focusCoords[0] ^= 1; if (gMenu.focusCoords[0] == 0) { - gScreen.bg0.control = 0x1f0c; - gScreen.bg3.control = 0x1e0f; + gScreen.bg0.control = BGCNT_SCREENBASE(31) | BGCNT_CHARBASE(3); + gScreen.bg3.control = BGCNT_SCREENBASE(30) | BGCNT_CHARBASE(3) | BGCNT_PRIORITY(3); } else { - gScreen.bg0.control = 0x1f0f; - gScreen.bg3.control = 0x1e0c; + gScreen.bg0.control = BGCNT_SCREENBASE(31) | BGCNT_CHARBASE(3) | BGCNT_PRIORITY(3); + gScreen.bg3.control = BGCNT_SCREENBASE(30) | BGCNT_CHARBASE(3); } break; - case 0x100: + case R_BUTTON: gSaveHeader->gameLanguage = gMenu.unk16; MessageFromTarget(gMenu.unk14 * 0x100 + gMenu.unk15); break; - case 0x2: + case B_BUTTON: MessageInitialize(); break; default: switch (gInput.unk4) { - case 0x20: + case DPAD_LEFT: iVar1 = -1; break; - case 0x10: + case DPAD_RIGHT: iVar1 = 1; break; default: diff --git a/src/demoScreen.c b/src/demoScreen.c index b2620204..f2b3315a 100644 --- a/src/demoScreen.c +++ b/src/demoScreen.c @@ -31,14 +31,14 @@ void HandleChooseDemoScreen(void) { void sub_080A2E40(void) { DispReset(1); InitSoundPlayingInfo(); - MemClear((void*)0x6000000, 0x80); + MemClear((void*)VRAM, 0x80); MessageInitialize(); EraseAllEntities(); sub_080ADD30(); sub_0801CFA8(0); - MemClear(&gUnk_02032EC0, 0x3b4); - MemClear(&gChooseFileState, 0x30); - MemClear(&gBG0Buffer, 0x800); + MemClear(&gUnk_02032EC0, sizeof gUnk_02032EC0); + MemClear(&gChooseFileState, sizeof gChooseFileState); + MemClear(&gBG0Buffer, sizeof gBG0Buffer); sub_08053320(); LoadPaletteGroup(0xb5); LoadGfxGroup(0x56); diff --git a/src/enemy/acroBandits.c b/src/enemy/acroBandits.c index 368606f2..c4784ee0 100644 --- a/src/enemy/acroBandits.c +++ b/src/enemy/acroBandits.c @@ -81,7 +81,7 @@ void sub_080318DC(Entity* this) { } if (this->health == 0) { - this->knockbackDirection = ((this->knockbackDirection + (7 & Random())) - 4) & 0x1f; + this->knockbackDirection = DirectionNormalize((this->knockbackDirection + (7 & Random())) - 4); this->knockbackDuration += this->type2 * 3; sub_08032338(this); } diff --git a/src/enemy/beetle.c b/src/enemy/beetle.c index c1b560d1..b2b3e5ed 100644 --- a/src/enemy/beetle.c +++ b/src/enemy/beetle.c @@ -150,7 +150,7 @@ void sub_08021984(Entity* this) { void sub_08021A10(Entity* this) { GetNextFrame(this); - if (sub_080041A0(this, &gPlayerEntity, 120, 80) && sub_08021D00(this) == 0) { + if (EntityInRectRadius(this, &gPlayerEntity, 120, 80) && sub_08021D00(this) == 0) { if (--this->actionDelay == 0) { this->action = 3; this->actionDelay = (Random() & 0x3f) + 30; diff --git a/src/enemy/businessScrub.c b/src/enemy/businessScrub.c index a0c18290..6e75d855 100644 --- a/src/enemy/businessScrub.c +++ b/src/enemy/businessScrub.c @@ -210,7 +210,7 @@ void sub_08028BC4(Entity* this) { if (iVar1 != NULL) { iVar1->spritePriority.b0 = 3; iVar1->z.HALF.HI -= 12; - SetDefaultPriority(iVar1, 2); + SetDefaultPriority(iVar1, PRIO_MESSAGE); } SetFlag(this->field_0x86.HWORD); sub_0802925C(this); @@ -390,14 +390,14 @@ void sub_08028F0C(Entity* this) { bool32 sub_08028F98(Entity* this, u32 param_2) { Entity* ent = sub_08049DF4(1); - if (ent == NULL || sub_080041A0(this, ent, 0x28, 0x28)) { + if (ent == NULL || EntityInRectRadius(this, ent, 0x28, 0x28)) { return FALSE; } if (param_2 != 2) { u32 distance = param_2 ? 0x58 : 0x50; - if (!sub_080041A0(this, ent, distance, distance)) { + if (!EntityInRectRadius(this, ent, distance, distance)) { return FALSE; } } diff --git a/src/enemy/cuccoChickAggr.c b/src/enemy/cuccoChickAggr.c index fa2fb63a..d3295203 100644 --- a/src/enemy/cuccoChickAggr.c +++ b/src/enemy/cuccoChickAggr.c @@ -134,7 +134,7 @@ u32 sub_08022B20(Entity* this) { if (!sub_08049DF4(2)) return 0; - return sub_080041A0(this, &gPlayerEntity, 0x24, 0x24); + return EntityInRectRadius(this, &gPlayerEntity, 36, 36); } void sub_08022B44(Entity* this) { diff --git a/src/enemy/darkNut.c b/src/enemy/darkNut.c index aa7d5993..e9061ad0 100644 --- a/src/enemy/darkNut.c +++ b/src/enemy/darkNut.c @@ -180,7 +180,7 @@ void sub_08020E78(Entity* this) { } void sub_08020E98(Entity* this) { - if (PlayerInRange(this, 1, 0x38)) { + if (PlayerInRange(this, 1, 56)) { if (sub_0802169C(this, gUnk_020000B0)) { this->action = 8; sub_08021218(this, 7, this->animationState); @@ -190,7 +190,7 @@ void sub_08020E98(Entity* this) { this->action = 8; sub_08021218(this, 7, this->animationState); } else { - this->direction ^= 0x10; + this->direction = DirectionTurnAround(this->direction); sub_0802124C(this); sub_08021644(this); } diff --git a/src/enemy/fireballGuy.c b/src/enemy/fireballGuy.c index 3ec57bc7..c6e0123e 100644 --- a/src/enemy/fireballGuy.c +++ b/src/enemy/fireballGuy.c @@ -67,7 +67,7 @@ void sub_08045454(Entity* this) { /* Can we create enough new entities? */ count = gUnk_080D180C[this->type]; - if (72 - count <= gEntCount) + if (MAX_ENTITIES + 1 - count <= gEntCount) return; /* Create 2-5 new MiniFireballGuy */ diff --git a/src/enemy/keaton.c b/src/enemy/keaton.c index 0c9adb33..b5bbef3f 100644 --- a/src/enemy/keaton.c +++ b/src/enemy/keaton.c @@ -143,7 +143,7 @@ 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)) { + (EntityInRectRadius(this, gUnk_020000B0, 0x68, 0x40) != 0)) { if (((GetFacingDirection(this, gUnk_020000B0) - (DirectionRound(this->frame)) + 2) & 0x1F) < 5) { this->action = 3; this->actionDelay = 0xC; diff --git a/src/enemy/lakitu.c b/src/enemy/lakitu.c index d96950d7..8e4ae08e 100644 --- a/src/enemy/lakitu.c +++ b/src/enemy/lakitu.c @@ -241,7 +241,7 @@ void Lakitu_Cloudless(Entity* this) { bool32 sub_0803CA4C(Entity* this) { if (sub_0806FCB8(this, gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI, 0x28) == 0) { - if (sub_080041A0(this, &gPlayerEntity, 0x70, 0x50)) { + if (EntityInRectRadius(this, &gPlayerEntity, 0x70, 0x50)) { return 1; } } diff --git a/src/enemy/likeLike.c b/src/enemy/likeLike.c index 6dce5fba..42e8d88f 100644 --- a/src/enemy/likeLike.c +++ b/src/enemy/likeLike.c @@ -58,7 +58,7 @@ void sub_08027DA4(Entity* this) { void sub_08027E40(Entity* this) { if (this->actionDelay == 2 && this->field_0x80.HALF.LO != 0xff) { - SetDefaultPriority(this, 3); + SetDefaultPriority(this, PRIO_NO_BLOCK); sub_08028224(this->field_0x80.HALF.LO); } sub_0804A7D4(this); diff --git a/src/enemy/mazaalHead.c b/src/enemy/mazaalHead.c index ce77d2c4..b282e776 100644 --- a/src/enemy/mazaalHead.c +++ b/src/enemy/mazaalHead.c @@ -224,7 +224,7 @@ void sub_08033FFC(Entity* this) { if (((*(Entity**)&this->field_0x74)->flags & 0x80) != 0) { gRoomControls.cameraTarget = &gPlayerEntity; sub_08034420(this); - gPlayerState.field_0x8b = 1; + gPlayerState.controlMode = 1; sub_080791D0(); SoundReq(BGM_BOSS_THEME); } diff --git a/src/enemy/moldworm.c b/src/enemy/moldworm.c index 7fb15f46..ce7f9249 100644 --- a/src/enemy/moldworm.c +++ b/src/enemy/moldworm.c @@ -139,7 +139,7 @@ void sub_080231BC(Entity* this) { this->field_0x78.HWORD = 0x1e; this->palette.b.b0 = 5; this->direction = Random() & 0x1f; - this->animationState = Direction8ToAnimationState(this->direction); + this->animationState = Direction8ToAnimationState(Direction8RoundUp(this->direction)); InitializeAnimation(this, this->animationState); } } @@ -225,7 +225,7 @@ void sub_08023398(Entity* this) { u32 uVar4; sub_08004596(this, sub_08049F84(this, 1)); - uVar4 = Direction8ToAnimationState(this->direction); + uVar4 = Direction8ToAnimationState(Direction8RoundUp(this->direction)); if (uVar4 != this->animationState) { this->animationState = uVar4; InitializeAnimation(this, uVar4 + this->field_0x7a.HALF.HI); @@ -249,7 +249,7 @@ void sub_080234D8(Entity* this) { this->action = 2; this->palette.b.b0 = 5; this->direction = Random() & 0x1f; - this->animationState = Direction8ToAnimationState(this->direction); + this->animationState = Direction8ToAnimationState(Direction8RoundUp(this->direction)); sub_08023A88(this, this->animationState); } } diff --git a/src/enemy/pesto.c b/src/enemy/pesto.c index 3f0e0c51..472d982d 100644 --- a/src/enemy/pesto.c +++ b/src/enemy/pesto.c @@ -403,7 +403,7 @@ void sub_080244E8(Entity* this) { } break; case 1: - if (sub_080041A0(this, this->child, 6, 6)) { + if (EntityInRectRadius(this, this->child, 6, 6)) { Entity* ent; this->field_0x80.HALF.LO += 1; @@ -424,7 +424,7 @@ void sub_080244E8(Entity* this) { } break; case 2: - if (sub_080041A0(this, this->child, 6, 6)) { + if (EntityInRectRadius(this, this->child, 6, 6)) { Entity* ent; this->field_0x80.HALF.LO += 1; diff --git a/src/enemy/slime.c b/src/enemy/slime.c index 92de7a7f..ab7666f8 100644 --- a/src/enemy/slime.c +++ b/src/enemy/slime.c @@ -95,7 +95,7 @@ void sub_080450A8(Entity* this) { /* Can we create enough new entities? */ count = gUnk_080D16D0[this->type]; - if (72 - count <= gEntCount) + if (MAX_ENTITIES + 1 - count <= gEntCount) return; /* Create 2-4 new MiniSlime */ diff --git a/src/enemy/vaatiWrath.c b/src/enemy/vaatiWrath.c index 43d870c1..d96b04ee 100644 --- a/src/enemy/vaatiWrath.c +++ b/src/enemy/vaatiWrath.c @@ -220,7 +220,7 @@ void VaatiWrathType0Action1(Entity* this) { this->actionDelay = 0x1e; gScreenTransition.field_0x38 |= 1; gRoomControls.cameraTarget = &gPlayerEntity; - gPlayerState.field_0x8b = 1; + gPlayerState.controlMode = 1; break; default: sub_08042004(this); @@ -567,7 +567,7 @@ void sub_08041BE8(Entity* this) { if (sub_08079F8C() != 0) { this->subAction = 1; this->actionDelay = 120; - this->updatePriority = 3; + this->updatePriority = PRIO_NO_BLOCK; InitAnimationForceUpdate(this, 10); entity = ((VaatiWrathHeapStruct*)this->myHeap)->type1; @@ -576,7 +576,7 @@ void sub_08041BE8(Entity* this) { ((VaatiWrathHeapStruct*)this->myHeap)->type1 = NULL; entity = ((VaatiWrathHeapStruct*)this->myHeap)->type2; - entity->updatePriority = 3; + entity->updatePriority = PRIO_NO_BLOCK; sub_080AE068(entity); LoadFixedGFX(entity, 0x1f5); sub_0801D2B4(entity, 0x16b); diff --git a/src/entity.c b/src/entity.c index c308b2b6..c0d5b62d 100644 --- a/src/entity.c +++ b/src/entity.c @@ -136,15 +136,15 @@ void ResetEntityPriority(void) { void RequestPriority(Entity* this) { this->updatePriorityPrev = this->updatePriority; - this->updatePriority = PRIO_REQUESTED; - if (SetMinPriority(PRIO_REQUESTED)) + this->updatePriority = PRIO_MESSAGE; + if (SetMinPriority(PRIO_MESSAGE)) gPriorityHandler.requester = this; } void RequestPriorityOverPlayer(Entity* this) { SetPlayerControl(1); this->updatePriorityPrev = this->updatePriority; - this->updatePriority = PRIO_OVERRIDE_MESSAGE; + this->updatePriority = PRIO_NO_BLOCK; if (SetMinPriority(PRIO_PLAYER)) gPriorityHandler.requester = this; } @@ -157,7 +157,7 @@ void RevokePriorityOverPlayer(Entity* this) { void RequestPriorityDuration(Entity* this, u32 time) { if (this != NULL) { this->updatePriorityPrev = this->updatePriority; - this->updatePriority = PRIO_OVERRIDE_MESSAGE; + this->updatePriority = PRIO_NO_BLOCK; } if (SetMinPriority(PRIO_PLAYER)) gPriorityHandler.requester = this; @@ -197,7 +197,7 @@ void SetRoomReloadPriority() { } void SetInitializationPriority() { - gPriorityHandler.sys_priority = PRIO_INITIALIZING; + gPriorityHandler.sys_priority = PRIO_HIGHEST; } void ResetSystemPriority() { @@ -38,9 +38,9 @@ void DoFade(u32 fadeType, u32 fadeSpeed) { } if ((fadeType & 8) != 0) { gUnk_03000000.spritesOffset = 1; - gScreen.bg1.control |= 0x40; - gScreen.bg2.control |= 0x40; - gScreen.bg3.control |= 0x40; + gScreen.bg1.control |= BGCNT_MOSAIC; + gScreen.bg2.control |= BGCNT_MOSAIC; + gScreen.bg3.control |= BGCNT_MOSAIC; } if ((fadeType & 0x10) != 0) { sub_0801E1B8(gFadeControl.field_0x16, gFadeControl.field_0x18); @@ -57,7 +57,7 @@ void sub_080500F4(u32 arg0) { gFadeControl.fadeSpeed = arg0; gFadeControl.fadeType ^= 1; gFadeControl.active = 1; - gFadeControl.fadeDuration = 0x100; + gFadeControl.fadeDuration = 256; } void sub_08050110(u32 param_1, u32 param_2, u32 fadeType, u32 fadeSpeed) { diff --git a/src/flagDebug.c b/src/flagDebug.c index e65edcf4..4f03efd9 100644 --- a/src/flagDebug.c +++ b/src/flagDebug.c @@ -1,12 +1,4 @@ -// #define DEF_FLAGS( name, ... ) \ -// const char* const name##_flags[] = { \ -// "BEGIN", \ -// __VA_ARGS__ \ -// "END" \ -// }; - -// DEF_FLAGS(global, "a", -// "b"); +#include "flags.h" const char* const globalFlagNames[] = { "BEGIN", diff --git a/src/interrupts.c b/src/interrupts.c index a7431d95..8a44a61b 100644 --- a/src/interrupts.c +++ b/src/interrupts.c @@ -71,8 +71,8 @@ void DummyIntr(void) { void EnableVBlankIntr(void) { INTR_VECTOR = gIntrMain; - REG_DISPSTAT = 0x5028; - REG_IE = 0x2005; + REG_DISPSTAT = DISPSTAT_VCOUNT_INTR | DISPSTAT_VBLANK_INTR | (80 << 8); + REG_IE = INTR_FLAG_VBLANK | INTR_FLAG_VCOUNT | INTR_FLAG_GAMEPAK; REG_IME = 1; } @@ -89,7 +89,7 @@ void VBlankIntr(void) { } void HBlankIntr(void) { - REG_DISPSTAT = 0x5028; + REG_DISPSTAT = DISPSTAT_VCOUNT_INTR | DISPSTAT_VBLANK_INTR | (80 << 8); m4aSoundMain(); } @@ -111,9 +111,9 @@ void sub_08016BF8(void) { } void UpdateDisplayControls(void) { - if (gUnk_03000000.update && ((gScreen.lcd.displayControl & 0x1000) != 0)) { + if (gUnk_03000000.update && (gScreen.lcd.displayControl & DISPCNT_OBJ_ON)) { gUnk_03000000.update = 0; - DmaCopy32(3, &gUnk_03000000.oam, 0x07000000, 0x400); + DmaCopy32(3, &gUnk_03000000.oam, OAM, OAM_SIZE); } sub_08016CA8(&gScreen.bg0); sub_08016CA8(&gScreen.bg1); @@ -126,7 +126,7 @@ void sub_08016CA8(BgSettings* bg) { u32 dest; bg->updated = 0; dest = bg->control; - DmaCopy32(3, bg->tilemap, ((dest << 3) & 0xF800) + 0x06000000, gUnk_080B2CD8[dest >> 14]); + DmaCopy32(3, bg->tilemap, ((dest << 3) & 0xF800) + VRAM, gUnk_080B2CD8[dest >> 14]); } } @@ -189,9 +189,9 @@ void PlayerUpdate(Entity* this) { if ((gPlayerState.flags & 0x80000) != 0) { sub_08077B20(); if ((gPlayerState.flags & 0x200000) != 0) { - gPlayerState.playerAction = 0x18; + gPlayerState.playerAction = PLAYER_ROLL; gPlayerState.flags &= ~0x80000; - gPlayerState.hurtBlinkSpeed = 0xf0; + gPlayerState.hurtBlinkSpeed = 240; COLLISION_ON(this); } else { COLLISION_OFF(this); @@ -224,7 +224,7 @@ void HandlePlayerLife(Entity* this) { SoundReq(SFX_86); gPlayerState.flags &= ~(0x2000000 | 0x200); - if (gPlayerState.flags & 0x400) + if (gPlayerState.flags & PL_BURNING) ResetPlayer(); if ((gPlayerState.flags & 0x400000) && !gPlayerState.field_0xa0[0]) sub_0807A108(); @@ -242,7 +242,7 @@ void HandlePlayerLife(Entity* this) { return; } - if ((gPlayerState.field_0x8b != 0) || (gMessage.doTextBox & 0x7f)) + if ((gPlayerState.controlMode != CONTROL_ENABLED) || (gMessage.doTextBox & 0x7f)) return; gRoomVars.unk2 = gMessage.doTextBox & 0x7f; @@ -294,7 +294,7 @@ void sub_080171F0(void) { gPlayerEntity.field_0x7a.HWORD--; gPlayerEntity.bitfield &= ~0x80; - if (gPlayerEntity.action != 0x14) + if (gPlayerEntity.action != PLAYER_DROWN) COPY_FLAG_FROM_TO(gPlayerState.flags, 0x2, 0x10000); gPlayerState.flags &= ~2; @@ -318,7 +318,7 @@ void sub_080171F0(void) { if (gPlayerState.flags & 0x400000) gUnk_03004040[0]->spriteOffsetY = gUnk_03004040[1]->spriteOffsetY = gUnk_03004040[2]->spriteOffsetY = 0; - if (gPlayerEntity.action == 0x1d) + if (gPlayerEntity.action == PLAYER_08072F34) gPlayerState.flags |= 0x20000000; else gPlayerState.flags &= ~0x20000000; @@ -327,7 +327,7 @@ void sub_080171F0(void) { if (gPlayerState.jumpStatus & 0xc0) gPlayerEntity.iframes = 0xfe; - if (gPlayerEntity.action != 0x17) { + if (gPlayerEntity.action != PLAYER_ROOMTRANSITION) { sub_08077FEC(gPlayerEntity.action); } } diff --git a/src/intro.c b/src/intro.c index b74c67a8..4a563487 100644 --- a/src/intro.c +++ b/src/intro.c @@ -158,17 +158,17 @@ static void HandleTitlescreen(void) { // Blend first and second layer gScreen.controls.layerFXControl = BLDCNT_TGT1_BG2 | BLDCNT_TGT2_BG3 | BLDCNT_EFFECT_BLEND; gScreen.controls.alphaBlend = BLDALPHA_BLEND(9, 9); - gScreen.bg1.control = 0x1c09; + gScreen.bg1.control = BGCNT_SCREENBASE(28) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(2); gScreen.bg2.control = BGCNT_SCREENBASE(29) | BGCNT_PRIORITY(2); gScreen.bg3.control = BGCNT_SCREENBASE(30) | BGCNT_PRIORITY(3); gScreen.lcd.displayControl |= DISPCNT_BG1_ON | DISPCNT_BG2_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; - gScreen.bg1.yOffset = 0xff60; + gScreen.bg1.yOffset = -160; } else { gScreen.controls.layerFXControl = BLDCNT_TGT1_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_EFFECT_BLEND; gScreen.controls.alphaBlend = BLDALPHA_BLEND(9, 9); gScreen.bg0.control = BGCNT_SCREENBASE(29) | BGCNT_PRIORITY(2); - gScreen.bg1.control = 0x1E03; - gScreen.bg2.control = BGCNT_PRIORITY(1) | BGCNT_CHARBASE(2) | BGCNT_256COLOR | BGCNT_SCREENBASE(28) | + gScreen.bg1.control = BGCNT_SCREENBASE(30) | BGCNT_PRIORITY(3); + gScreen.bg2.control = BGCNT_SCREENBASE(28) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(2) | BGCNT_256COLOR | BGCNT_WRAP | BGCNT_TXT512x256; gScreen.lcd.displayControl |= DISPCNT_MODE_1; gScreen.lcd.displayControl |= DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_ON; @@ -284,7 +284,7 @@ static void HandleJapaneseTitlescreenAnimationIntro(void) { if (GetAdvanceState() == ADVANCE_KEY_PRESSED || gScreen.bg1.yOffset == 0) { gIntroState.subState++; gScreen.bg1.yOffset = 0; - gScreen.bg1.control = 0xc09; + gScreen.bg1.control = BGCNT_SCREENBASE(12) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(2); gFadeControl.mask = 0x00000040; DoFade(6, 0x10); SoundReq(SFX_F8); diff --git a/src/item/itemPegasusBoots.c b/src/item/itemPegasusBoots.c index 6804c425..e66f8240 100644 --- a/src/item/itemPegasusBoots.c +++ b/src/item/itemPegasusBoots.c @@ -61,7 +61,7 @@ void sub_080768F8(ItemBehavior* this, u32 arg1) { if ((gPlayerState.flags & PL_MINISH) == 0) { this->field_0x5[2] = 0x10; } else { - gPlayerState.field_0x8 = 0xc14; + gPlayerState.animation = 0xc14; } sub_08077D38(this, arg1); sub_08076964(this, arg1); diff --git a/src/item/itemRocsCape.c b/src/item/itemRocsCape.c index 56aa2947..dd4c69bd 100644 --- a/src/item/itemRocsCape.c +++ b/src/item/itemRocsCape.c @@ -72,7 +72,7 @@ void sub_08076758(ItemBehavior* this, u32 arg1) { gPlayerEntity.field_0x7a.HWORD = 2; gPlayerEntity.zVelocity = 0x20000; gPlayerState.jumpStatus |= 0x10; - gPlayerState.field_0x8 = 0x288; + gPlayerState.animation = 0x288; SoundReq(SFX_172); } } else { @@ -18,7 +18,7 @@ extern void HandleGameOverScreen(void); extern void HandleCreditsScreen(void); extern void HandleDebugTextScreen(void); -static void sub_08055F70(void); +static void InitOverlays(void); static bool32 SoftResetKeysPressed(void); void (*const sScreenHandlers[])(void) = { @@ -40,7 +40,7 @@ static void sub_080560B8(void); void AgbMain(void) { int var0; - sub_08055F70(); + InitOverlays(); InitSound(); InitDMA(); InitSaveData(); @@ -101,7 +101,7 @@ extern u8 gUnk_080B2CD8_2[]; extern u8 gUnk_080B2CD8_3[]; extern u8 gUnk_02000030[]; -static void sub_08055F70(void) { +static void InitOverlays(void) { u32 size; DisableInterruptsAndDMA(); @@ -185,15 +185,15 @@ NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) { u32 temp; u32 b; - if (!sub_08056134()) { - switch ((s32)Read_02000000((void*)0x2000000)) { + if (!CheckHeaderValid()) { + switch ((s32)Read_02000000(gSaveHeader)) { case 1: - if (sub_08056134()) + if (CheckHeaderValid()) break; case 0: case -1: default: - MemCopy(&sDefaultSettings, (void*)0x2000000, 16); + MemCopy(&sDefaultSettings, gSaveHeader, sizeof *gSaveHeader); Write_02000000(gSaveHeader); break; } @@ -206,14 +206,13 @@ NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) { b = TRUE; } if (b) { - MemClear((u8*)&gUnk_02000010.signature, 0x20); + MemClear(&gUnk_02000010, sizeof gUnk_02000010); gUnk_02000010.signature = SIGNATURE; } } END_NONMATCH -u32 sub_08056134(void) { - +u32 CheckHeaderValid(void) { if ((gSaveHeader->signature != SIGNATURE) || (gSaveHeader->saveFileId >= NUM_SAVE_SLOTS) || (gSaveHeader->messageSpeed >= MAX_MSG_SPEED) || (gSaveHeader->brightnessPref >= MAX_BRIGHTNESS) #ifdef EU @@ -259,26 +258,27 @@ void sub_08056250() { } void sub_08056260(void) { - u32 temp; - Main* temp2; + u32 restore; + Main* m; - REG_DISPCNT = 0x80; - REG_KEYCNT = 0x8304; + REG_DISPCNT = DISPCNT_FORCED_BLANK; + REG_KEYCNT = KEY_AND_INTR | L_BUTTON | R_BUTTON | SELECT_BUTTON; REG_IME = 0; - temp = REG_IE; - REG_IE = 0x3000; + restore = REG_IE; + REG_IE = INTR_FLAG_KEYPAD | INTR_FLAG_GAMEPAK; REG_IME = 1; Stop(); REG_IME = 0; - REG_IE = temp; + REG_IE = restore; REG_IME = 1; - temp2 = &gMain; - asm("ldrb r1, [r0, #0x1]"); - temp2->field_0x1 = 0; + m = &gMain; + *(vu8*)&m->field_0x1; // force a read + m->field_0x1 = 0; } + // Convert AABB to screen coordinates and check if it's within the viewport -u32 sub_080562CC(u32 x0, u32 y0, u32 x1, u32 y1) { +u32 CheckRegionOnScreen(u32 x0, u32 y0, u32 x1, u32 y1) { u32 result; u32 x = ((gRoomControls.roomScrollX - gRoomControls.roomOriginX) - x0 + DISPLAY_WIDTH); u32 y = ((gRoomControls.roomScrollY - gRoomControls.roomOriginY) - y0 + DISPLAY_HEIGHT); @@ -292,10 +292,10 @@ u32 sub_080562CC(u32 x0, u32 y0, u32 x1, u32 y1) { } // Iterate over array of AABBs and check if any fit on screen -u16 sub_08056300(u16* arr) { +u16 CheckRegionsOnScreen(u16* arr) { u16* i; for (i = arr; *i != 0xff; i += 5) { - if (sub_080562CC(i[1], i[2], i[3], i[4]) != 0) + if (CheckRegionOnScreen(i[1], i[2], i[3], i[4])) return *i; } return 0xff; diff --git a/src/manager/manager1.c b/src/manager/manager1.c index bbc743ce..51b28137 100644 --- a/src/manager/manager1.c +++ b/src/manager/manager1.c @@ -4,8 +4,6 @@ #include "functions.h" extern void sub_08056250(void); -extern void sub_080570B8(Entity*); -void sub_080570F8(void); extern void (*const gUnk_08107C5C[])(Entity*); extern void (*const gUnk_08107C48[])(Entity*); @@ -25,7 +23,7 @@ void Manager1_Main(Entity* this) { } } -void sub_080570B8(Entity* this) { +static void sub_080570B8(Entity* this) { u8* pbVar1; LoadGfxGroup(((u8*)&this->zVelocity)[0]); @@ -38,8 +36,8 @@ void sub_080570B8(Entity* this) { } } -void sub_080570F8(void) { - gScreen.lcd.displayControl &= 0xf7ff; +static void sub_080570F8(void) { + gScreen.lcd.displayControl &= ~DISPCNT_BG3_ON; gScreen.controls.layerFXControl = 0; sub_08056250(); } @@ -51,7 +49,7 @@ void sub_08057118(Entity* this) { ((u8*)&this->zVelocity)[2] = 0; this->action = 1; gScreen.bg3.control = 0x1e04; - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gScreen.controls.layerFXControl = 0x3648; gScreen.controls.alphaBlend = 0x1000; RegisterTransitionManager(this, sub_080570B8, sub_080570F8); diff --git a/src/manager/manager12.c b/src/manager/manager12.c index 36a044d4..6a1c5982 100644 --- a/src/manager/manager12.c +++ b/src/manager/manager12.c @@ -15,7 +15,7 @@ void sub_08059A58(Manager12*); void sub_08059A2C(Manager12*); -u32 sub_08056300(u16* arr); +u32 CheckRegionsOnScreen(u16* arr); extern u16 gUnk_081083DA; extern u16 gUnk_081083F2; extern u16 gUnk_08108398; @@ -48,7 +48,7 @@ void Manager12_Main(Manager12* this) { this->field_0x21 = 0xff; this->field_0x20 = 0xff; RegisterTransitionManager(this, sub_08059A2C, NULL); - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); } sub_08059A58(this); } @@ -128,7 +128,7 @@ void sub_08059B18(void) { bool32 sub_08059C8C(Manager12* this, u32 param_2, u8* param_3, u16* param_4) { bool32 bVar2; - *param_3 = sub_08056300(param_4); + *param_3 = CheckRegionsOnScreen(param_4); if ((*param_3 != 0xff) && (gRoomVars.unk_10[param_2] != *param_3)) { gRoomVars.unk_10[param_2] = *param_3; return TRUE; @@ -154,24 +154,24 @@ void TryLoadPrologueHyruleTown(void) { u32 tmp; if (gRoomControls.areaID != AREA_FESTIVAL_TOWN) { - tmp = sub_08056300(&gUnk_08108398); + tmp = CheckRegionsOnScreen(&gUnk_08108398); if (tmp != 0xff) { sub_08059CC0(0, tmp); } - tmp = sub_08056300(&gUnk_081083AE); + tmp = CheckRegionsOnScreen(&gUnk_081083AE); if ((tmp != 0xff) && (sub_08059CC0(1, tmp), tmp == 2)) { sub_08059B18(); } - tmp = sub_08056300(&gUnk_081083C4); + tmp = CheckRegionsOnScreen(&gUnk_081083C4); if (tmp != 0xff) { sub_08059CC0(2, tmp); } } else { - tmp = sub_08056300(&gUnk_081083DA); + tmp = CheckRegionsOnScreen(&gUnk_081083DA); if (tmp != 0xff) { sub_08059CC0(0, tmp); } - tmp = sub_08056300(&gUnk_081083F2); + tmp = CheckRegionsOnScreen(&gUnk_081083F2); if (tmp != 0xff) { sub_08059CC0(2, tmp); } diff --git a/src/manager/manager14.c b/src/manager/manager14.c index 31f827c0..65bb296d 100644 --- a/src/manager/manager14.c +++ b/src/manager/manager14.c @@ -56,7 +56,7 @@ void sub_08059E80(Manager14* this) { this->manager.action = 4; this->manager.unk_10 |= 0x20; gScreen.bg3.control = 0x1E04; - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gScreen.controls.layerFXControl = 0x3E48; gScreen.controls.alphaBlend = 0x1000; gScreen.bg3.xOffset = 0x80; @@ -142,7 +142,7 @@ void sub_0805A0C0(Manager14* this) { this->manager.unk_0f = 4; gScreen.controls.alphaBlend = gUnk_08108588[this->manager.unk_0e--]; if (this->manager.unk_0e == 0xFF) { - gScreen.lcd.displayControl &= ~0x800; + gScreen.lcd.displayControl &= ~DISPCNT_BG3_ON; sub_08056250(); DeleteThisEntity(); } @@ -179,7 +179,7 @@ void sub_0805A1D8(Manager14* this) { gScreen.bg3.xOffset = gRoomControls.bg3OffsetX.HALF.HI; gRoomControls.bg3OffsetY.WORD -= 0x1000; gScreen.bg3.yOffset = gRoomControls.bg3OffsetY.HALF.HI; - if (gScreen.lcd.displayControl & 0x800) { + if (gScreen.lcd.displayControl & DISPCNT_BG3_ON) { sub_0805A114(6, this->unk_20 >> 1); if (this->unk_22 == 0 && (gMain.ticks & 0x1F) == 0) { this->unk_24++; @@ -194,6 +194,6 @@ void nullsub_495() { void sub_0805A25C() { gScreen.controls.layerFXControl = 0; - gScreen.lcd.displayControl &= ~0x800; + gScreen.lcd.displayControl &= ~DISPCNT_BG3_ON; sub_08056250(); } diff --git a/src/manager/manager15.c b/src/manager/manager15.c index 27a5e825..867a9429 100644 --- a/src/manager/manager15.c +++ b/src/manager/manager15.c @@ -46,7 +46,7 @@ void sub_0805A298(Manager15* this) { this->unk_23 = 2; } sub_0805AAF0(this->unk_23); - gScreen.lcd.displayControl |= 0x4800; + gScreen.lcd.displayControl |= DISPCNT_WIN1_ON | DISPCNT_BG3_ON; } sub_0805A8EC(this); } @@ -67,7 +67,7 @@ void sub_0805A2E4(Manager15* this) { } else { this->manager.action = 3; } - gScreen.lcd.displayControl |= 0x4800; + gScreen.lcd.displayControl |= DISPCNT_WIN1_ON | DISPCNT_BG3_ON; } } else { gUnk_081085F8[this->manager.action](this); @@ -96,7 +96,7 @@ void sub_0805A394(Manager15* this) { } SetLocalFlag(LV1_16_1STEND); ClearRoomFlag(0); - gScreen.lcd.displayControl &= 0xB7FF; + gScreen.lcd.displayControl &= ~(DISPCNT_WIN1_ON | DISPCNT_BG3_ON); DeleteThisEntity(); } @@ -117,11 +117,11 @@ void sub_0805A3D4(Manager15* this) { if (!CheckLocalFlag(this->unk_3e)) { ClearFlag(this->unk_3c); this->manager.action = 1; - gScreen.lcd.displayControl &= 0xB7FF; + gScreen.lcd.displayControl &= ~(DISPCNT_WIN1_ON | DISPCNT_BG3_ON); } else { SetFlag(this->unk_3c); this->manager.action = 3; - gScreen.lcd.displayControl |= 0x4800; + gScreen.lcd.displayControl |= DISPCNT_WIN1_ON | DISPCNT_BG3_ON; } } else { gUnk_0810860C[this->manager.action](this); @@ -181,16 +181,16 @@ void sub_0805A500(Manager15* this) { if (CheckLocalFlag(0x36)) { this->unk_23 = 3; this->manager.action = 5; - gScreen.lcd.displayControl |= 0x4800; + gScreen.lcd.displayControl |= DISPCNT_WIN1_ON | DISPCNT_BG3_ON; } else { if (CheckLocalFlag(0x34)) { this->unk_23 = 4; this->manager.action = 3; - gScreen.lcd.displayControl |= 0x4800; + gScreen.lcd.displayControl |= DISPCNT_WIN1_ON | DISPCNT_BG3_ON; } else { this->unk_23 = 4; this->manager.action = 1; - gScreen.lcd.displayControl &= 0xB7FF; + gScreen.lcd.displayControl &= ~(DISPCNT_WIN1_ON | DISPCNT_BG3_ON); } } sub_0805AAF0(this->unk_23); @@ -200,7 +200,7 @@ void sub_0805A500(Manager15* this) { sub_0805AA58(this); sub_0805A9CC(this); if (gRoomControls.unk2 == 1) { - gScreen.lcd.displayControl |= 0x80 << 7; + gScreen.lcd.displayControl |= DISPCNT_WIN1_ON; this->manager.unk_0d = 1; return; } @@ -209,7 +209,7 @@ void sub_0805A500(Manager15* this) { this->manager.unk_0d = 0; if (this->unk_20 == gRoomControls.roomID) return; - gScreen.lcd.displayControl &= 0xB7FF; + gScreen.lcd.displayControl &= ~(DISPCNT_WIN1_ON | DISPCNT_BG3_ON); DeleteThisEntity(); } @@ -281,12 +281,12 @@ void sub_0805A6E8(Manager15* this) { this->manager.action++; } this->unk_2c = 0x1000; - tmp = gScreen.lcd.displayControl | 0x4800; + tmp = gScreen.lcd.displayControl | DISPCNT_WIN1_ON | DISPCNT_BG3_ON; gScreen.lcd.displayControl = tmp; } u32 sub_0805A73C(Manager15* this) { - return CheckPlayerProximity(this->unk_38 - 0x6, this->unk_3a - 0x6, 0xC, 0xC); + return CheckPlayerProximity(this->unk_38 - 6, this->unk_3a - 6, 12, 12); } void sub_0805A758(Manager15* this) { @@ -304,10 +304,10 @@ void sub_0805A76C(Manager15* this) { this->manager.action++; sub_08004168(&gPlayerEntity); gPlayerEntity.animationState = 4; - RequestPriorityDuration((Entity*)this, 0x258); + RequestPriorityDuration((Entity*)this, 600); SetPlayerControl(0xFF); gUnk_02034490[0] = 1; - gRoomControls.cameraTarget = 0; + gRoomControls.cameraTarget = NULL; sub_08077B20(); } } @@ -315,8 +315,8 @@ void sub_0805A76C(Manager15* this) { } void sub_0805A7E4(Manager15* this) { - if (gPlayerState.playerAction != 0x12) { - gPlayerState.playerAction = 0x12; + if (gPlayerState.playerAction != PLAYER_WARP) { + gPlayerState.playerAction = PLAYER_WARP; gPlayerState.field_0x38 = 0; gPlayerState.field_0x39 = 0; } @@ -332,7 +332,7 @@ void sub_0805A804(Manager15* this) { } this->manager.unk_0d = 1; this->manager.unk_10 |= 0x20; - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); break; case 1: if (CheckLocalFlag(this->unk_3e)) @@ -364,7 +364,7 @@ void sub_0805A804(Manager15* this) { void sub_0805AAC8(Manager15*); void sub_0805A89C(Manager15* this) { - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); this->manager.action = 1; this->manager.unk_10 |= 0x20; this->manager.unk_0e = 8; @@ -383,7 +383,7 @@ void sub_0805A8EC(Manager15* this) { sub_0805AA58(this); sub_0805A94C(this); if (gRoomControls.unk2 == 1) { - gScreen.lcd.displayControl |= 0x4000; + gScreen.lcd.displayControl |= DISPCNT_WIN1_ON; this->manager.unk_0d = 1; } else { if (!this->manager.unk_0d) @@ -391,7 +391,7 @@ void sub_0805A8EC(Manager15* this) { this->manager.unk_0d = 0; if (this->unk_20 == gRoomControls.roomID) return; - gScreen.lcd.displayControl &= 0xB7FF; + gScreen.lcd.displayControl &= ~(DISPCNT_WIN1_ON | DISPCNT_BG3_ON); DeleteThisEntity(); } } @@ -404,23 +404,23 @@ void sub_0805A94C(Manager15* this) { tmp2 = tmp1 + 0x100; if (tmp1 < 0) tmp1 = 0; - if (tmp1 > 0xF0) - tmp1 = 0xF0; + if (tmp1 > DISPLAY_WIDTH) + tmp1 = DISPLAY_WIDTH; if (tmp2 < 0) tmp2 = 0; - if (tmp2 > 0xF0) - tmp2 = 0xF0; + if (tmp2 > DISPLAY_WIDTH) + tmp2 = DISPLAY_WIDTH; gScreen.controls.window1HorizontalDimensions = (tmp1 << 8 | tmp2); tmp1 = -gScreen.bg3.yOffset; tmp2 = tmp1 + 0x100; if (tmp1 < 0) tmp1 = 0; - if (tmp1 > 0xA0) - tmp1 = 0xA0; + if (tmp1 > DISPLAY_HEIGHT) + tmp1 = DISPLAY_HEIGHT; if (tmp2 < 0) tmp2 = 0; - if (tmp2 > 0xA0) - tmp2 = 0xA0; + if (tmp2 > DISPLAY_HEIGHT) + tmp2 = DISPLAY_HEIGHT; gScreen.controls.window1VerticalDimensions = (tmp1 << 8 | tmp2); } @@ -432,18 +432,18 @@ void sub_0805A9CC(Manager15* this) { tmp2 = tmp1 + 0x100; if (tmp1 < 0) tmp1 = 0; - if (tmp1 > 0xF0) - tmp1 = 0xF0; + if (tmp1 > DISPLAY_WIDTH) + tmp1 = DISPLAY_WIDTH; if (tmp2 < 0) tmp2 = 0; - if (tmp2 > 0xF0) - tmp2 = 0xF0; + if (tmp2 > DISPLAY_WIDTH) + tmp2 = DISPLAY_WIDTH; gScreen.controls.window1HorizontalDimensions = tmp1 << 8 | tmp2; tmp1 = gRoomControls.roomScrollY - this->unk_26 + this->unk_36; gScreen.bg3.yOffset = tmp1 & 0x3F; tmp3 = (&gBG3Buffer[((tmp1 / 0x40) << 8)]); gScreen.bg3.tilemap = (u32*)tmp3; - gScreen.controls.window1VerticalDimensions = 0xa0; + gScreen.controls.window1VerticalDimensions = DISPLAY_HEIGHT; if (this->unk_28 == tmp3) return; this->unk_28 = tmp3; @@ -483,14 +483,16 @@ void sub_0805AADC(u32 unk0) { void sub_0805AAF0(u32 unk0) { sub_0805AADC(unk0); gScreen.controls.layerFXControl = 0x3E48; - gScreen.controls.alphaBlend = 0x1008; - gScreen.bg3.control = 0x1E04; + gScreen.controls.alphaBlend = BLDALPHA_BLEND(8, 16); + gScreen.bg3.control = BGCNT_SCREENBASE(30) | BGCNT_CHARBASE(1); gScreen.bg3.tilemap = &gBG3Buffer; gScreen.bg3.xOffset = 0; gScreen.bg3.yOffset = 0; gScreen.bg3.updated = 1; - gScreen.controls.windowInsideControl = 0x3F3F; - gScreen.controls.windowOutsideControl = 0x37; - gScreen.controls.window1HorizontalDimensions = 0xF0; - gScreen.controls.window1VerticalDimensions = 0xA0; + gScreen.controls.windowInsideControl = + WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN1_BG_ALL | WININ_WIN1_OBJ | WININ_WIN0_CLR | WININ_WIN1_CLR; + gScreen.controls.windowOutsideControl = + WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR; + gScreen.controls.window1HorizontalDimensions = DISPLAY_WIDTH; + gScreen.controls.window1VerticalDimensions = DISPLAY_HEIGHT; } diff --git a/src/manager/manager18.c b/src/manager/manager18.c index 1d797c5c..e18fd94e 100644 --- a/src/manager/manager18.c +++ b/src/manager/manager18.c @@ -24,7 +24,7 @@ void Manager18_Main(Manager18* this) { this->manager.unk_0e = 0; this->manager.unk_0f = 8; this->field_0x20 = gUnk_0810865C[0]; - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); if (gArea.onEnter == NULL) { RegisterTransitionManager(this, sub_0805AEDC, sub_0805AF3C); } else { @@ -47,10 +47,10 @@ void Manager18_Main(Manager18* this) { } void sub_0805AEDC(Manager18* this) { - gScreen.bg3.control = 0x1e05; - gScreen.lcd.displayControl |= 0x800; - gScreen.controls.layerFXControl = 0x3648; - gScreen.controls.alphaBlend = (this != NULL) ? this->field_0x20 : 0x1000; + gScreen.bg3.control = BGCNT_SCREENBASE(30) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1); + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; + gScreen.controls.layerFXControl = BLDCNT_TGT1_BG3 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD; + gScreen.controls.alphaBlend = (this != NULL) ? this->field_0x20 : BLDALPHA_BLEND(0, 16); gScreen.bg3.xOffset = gRoomControls.roomScrollX + gRoomControls.bg3OffsetX.HALF.HI; gScreen.bg3.yOffset = gRoomControls.roomScrollY + gRoomControls.bg3OffsetY.HALF.HI; if (this != NULL) { @@ -60,6 +60,6 @@ void sub_0805AEDC(Manager18* this) { void sub_0805AF3C(Manager18* this) { this->manager.unk_10 &= 0xdf; - gScreen.lcd.displayControl &= 0xf7ff; + gScreen.lcd.displayControl &= ~DISPCNT_BG3_ON; gScreen.controls.layerFXControl = 0; } diff --git a/src/manager/manager19.c b/src/manager/manager19.c index a6118c5c..0207ab56 100644 --- a/src/manager/manager19.c +++ b/src/manager/manager19.c @@ -15,7 +15,7 @@ void Manager19_Main(Manager* this) { if (this->action == 0) { this->action = 1; this->unk_10 |= 0x20; - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); if (gArea.onEnter == NULL) { RegisterTransitionManager(this, sub_0805AFFC, NULL); } else { @@ -30,8 +30,8 @@ void Manager19_Main(Manager* this) { } void sub_0805AFFC(Manager* this) { - gScreen.bg3.control = 0x1e03; - gScreen.lcd.displayControl |= 0x800; + gScreen.bg3.control = BGCNT_PRIORITY(3) | BGCNT_SCREENBASE(30); + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gScreen.bg3.xOffset = gRoomControls.roomScrollX + gRoomControls.bg3OffsetX.HALF.HI; gScreen.bg3.yOffset = gRoomControls.roomScrollY + gRoomControls.bg3OffsetY.HALF.HI; } diff --git a/src/manager/manager1A.c b/src/manager/manager1A.c index cc5ab45e..dc09ea5f 100644 --- a/src/manager/manager1A.c +++ b/src/manager/manager1A.c @@ -68,7 +68,7 @@ void sub_0805B328(Manager1A*); void sub_0805B048(Manager1A* this) { struct_08108764* tmp; Entity* obj; - SetDefaultPriority((Entity*)&this->manager, 6); + SetDefaultPriority((Entity*)&this->manager, PRIO_PLAYER_EVENT); MemClear(&this->unk_20, 0x20); this->manager.action = 1; this->unk_3f = gRoomControls.roomID; @@ -197,7 +197,7 @@ void sub_0805B2B0(Manager1A* this) { if (tmp2 > 12) { tmp2 = 12; } - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gRoomControls.bg3OffsetX.HALF.HI = gRoomControls.roomScrollX + this->unk_34 + tmp; gScreen.bg3.xOffset = gRoomControls.roomScrollX + this->unk_34 + tmp; gRoomControls.bg3OffsetY.HALF.HI = gRoomControls.roomScrollY + this->unk_36 + tmp2; @@ -211,7 +211,7 @@ void sub_0805B328(Manager1A* this) { tmp = &gUnk_08108764[this->manager.unk_0a]; LoadResourceAsync(&gGlobalGfxAndPalettes[tmp->unk_0c->unk_00], 0x0600F000, 0x800); gScreen.bg3.control = 0x1E07; - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gScreen.bg3.xOffset = gRoomControls.bg3OffsetX.HALF.HI; gScreen.bg3.yOffset = gRoomControls.bg3OffsetY.HALF.HI; gScreen.controls.layerFXControl &= ~0x8; diff --git a/src/manager/manager1B.c b/src/manager/manager1B.c index c2392fdc..a172bcfc 100644 --- a/src/manager/manager1B.c +++ b/src/manager/manager1B.c @@ -29,7 +29,7 @@ void Manager1B_Main(Manager1B* this) { if (this->manager.action == 0) { this->manager.action = 1; this->manager.unk_10 |= 0x20; - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); if (this->manager.unk_0a != 0) { RegisterTransitionManager(this, sub_0805B4B4, NULL); } @@ -70,7 +70,7 @@ void sub_0805B4D0(u32 param_1) { LoadGfxGroup(gUnk_08108C5C[param_1]); gScreen.bg3.control = 0x1e07; - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gScreen.bg3.xOffset = (gRoomControls.roomScrollX - gRoomControls.roomOriginX) >> 2; uVar2 = (gRoomControls.roomScrollY - gRoomControls.roomOriginY) >> 1; diff --git a/src/manager/manager1D.c b/src/manager/manager1D.c index 63ffcf8c..b9039a05 100644 --- a/src/manager/manager1D.c +++ b/src/manager/manager1D.c @@ -13,7 +13,7 @@ void Manager1D_Main(Manager* this) { void sub_0805B5E0(Manager* this) { this->action = 1; - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gScreen.bg3.control = gUnk_08108C88[this->unk_0a]; gRoomControls.bg3OffsetY.WORD = 0; gRoomControls.bg3OffsetX.WORD = 0; diff --git a/src/manager/manager2.c b/src/manager/manager2.c index 9dcb74f2..3f74d209 100644 --- a/src/manager/manager2.c +++ b/src/manager/manager2.c @@ -53,7 +53,7 @@ void sub_080575C8(u32 param) { s32 bgOffset; gUnk_0200B650 = 0; - *(u16*)0x4000000 = 0; + REG_DISPCNT = 0; LoadGfxGroup(param); gRoomVars.unk_10[0] = param; @@ -62,7 +62,7 @@ void sub_080575C8(u32 param) { gScreen.bg3.yOffset = bgOffset & 0x3f; gScreen.bg3.xOffset = 0; gScreen.bg3.tilemap = &gMapDataTopSpecial[(bgOffset / 0x40) * 0x200]; - gScreen.bg3.control = 0x1d49; + gScreen.bg3.control = BGCNT_SCREENBASE(29) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(2) | BGCNT_MOSAIC; gScreen.bg3.updated = 1; bgOffset = (gRoomControls.roomScrollY - gRoomControls.roomOriginY); @@ -70,16 +70,17 @@ void sub_080575C8(u32 param) { gScreen.bg1.yOffset = bgOffset & 0x3f; gScreen.bg1.xOffset = 0; gScreen.bg1.tilemap = &gMapDataTopSpecial[0x2000 + (bgOffset / 0x40) * 0x200]; - gScreen.bg1.control = 0x1e49; + gScreen.bg1.control = BGCNT_SCREENBASE(30) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(2) | BGCNT_MOSAIC; gScreen.bg1.updated = 1; - gScreen.controls.layerFXControl = 0x3c48; - gScreen.controls.alphaBlend = 0x609; - gScreen.lcd.displayControl |= 0xa00; + gScreen.controls.layerFXControl = + BLDCNT_TGT1_BG3 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD; + gScreen.controls.alphaBlend = BLDALPHA_BLEND(9, 6); + gScreen.lcd.displayControl |= DISPCNT_BG3_ON | DISPCNT_BG1_ON; } void sub_08057688(void) { - gScreen.bg3.control = 0x1d48; - gScreen.bg1.control = 0x1e48; + gScreen.bg3.control = BGCNT_SCREENBASE(29) | BGCNT_CHARBASE(2) | BGCNT_MOSAIC; + gScreen.bg1.control = BGCNT_SCREENBASE(30) | BGCNT_CHARBASE(2) | BGCNT_MOSAIC; } void sub_080576A0(Manager2* this) { diff --git a/src/manager/manager2E.c b/src/manager/manager2E.c index 19205a28..7dbb3aa5 100644 --- a/src/manager/manager2E.c +++ b/src/manager/manager2E.c @@ -42,7 +42,7 @@ void sub_0805D280(Manager2E* this) { if (this->manager.unk_0e == 0) { this->manager.unk_0e = 0x1e; } - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); } void sub_0805D2C0(Manager2E* this) { @@ -80,7 +80,7 @@ void sub_0805D344(Manager2E* this) { this->manager.unk_0e = 0x1e; } this->manager.unk_0f = this->manager.unk_0e; - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); } void sub_0805D36C(Manager2E* this) { diff --git a/src/manager/manager2F.c b/src/manager/manager2F.c index 84619e66..d35c67a8 100644 --- a/src/manager/manager2F.c +++ b/src/manager/manager2F.c @@ -16,7 +16,7 @@ void Manager2F_Main(Manager* this) { if (this->action == 0) { this->action = 1; this->unk_10 |= 0x20; - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); if (gArea.onEnter == NULL) { RegisterTransitionManager(this, sub_0805D470, NULL); } else { @@ -34,7 +34,7 @@ void Manager2F_Main(Manager* this) { void sub_0805D470(Manager* this) { LoadGfxGroup(0x4c); gScreen.bg3.control = 0x1e07; - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gScreen.bg3.xOffset = gRoomControls.roomScrollX + gRoomControls.bg3OffsetX.HALF.HI; gScreen.bg3.yOffset = gRoomControls.roomScrollY + gRoomControls.bg3OffsetY.HALF.HI; } diff --git a/src/manager/manager31.c b/src/manager/manager31.c index 2dcf7727..bb7ebdde 100644 --- a/src/manager/manager31.c +++ b/src/manager/manager31.c @@ -28,7 +28,7 @@ void Manager31_Main(Manager31* this) { s32 count; if (this->manager.action == 0) { - this->manager.action += 1; + this->manager.action++; if (CheckGlobalFlag(GORON_KAKERA_L) != 0 && CheckGlobalFlag(GORON_KAKERA_M) != 0 && CheckGlobalFlag(GORON_KAKERA_R) != 0) { if (CheckGlobalFlag(GORON_KAKERA_LV2) == 0) { @@ -36,28 +36,22 @@ void Manager31_Main(Manager31* this) { SetGlobalFlag(GORON_KAKERA_LV2); goto clearGlobalFlags; } - } else { - if (CheckGlobalFlag(GORON_KAKERA_LV3) == 0) { - if (CheckGlobalFlag(LV2_CLEAR) != 0) { - SetGlobalFlag(GORON_KAKERA_LV3); - goto clearGlobalFlags; - } - } else { - if (CheckGlobalFlag(GORON_KAKERA_LV4) == 0) { - if (CheckGlobalFlag(LV3_CLEAR) != 0) { - SetGlobalFlag(GORON_KAKERA_LV4); - goto clearGlobalFlags; - } - } else { - if (CheckGlobalFlag(GORON_KAKERA_LV5) == 0 && CheckGlobalFlag(LV4_CLEAR) != 0) { - SetGlobalFlag(GORON_KAKERA_LV5); - clearGlobalFlags: - ClearGlobalFlag(GORON_KAKERA_L); - ClearGlobalFlag(GORON_KAKERA_M); - ClearGlobalFlag(GORON_KAKERA_R); - } - } + } else if (CheckGlobalFlag(GORON_KAKERA_LV3) == 0) { + if (CheckGlobalFlag(LV2_CLEAR) != 0) { + SetGlobalFlag(GORON_KAKERA_LV3); + goto clearGlobalFlags; + } + } else if (CheckGlobalFlag(GORON_KAKERA_LV4) == 0) { + if (CheckGlobalFlag(LV3_CLEAR) != 0) { + SetGlobalFlag(GORON_KAKERA_LV4); + goto clearGlobalFlags; } + } else if (CheckGlobalFlag(GORON_KAKERA_LV5) == 0 && CheckGlobalFlag(LV4_CLEAR) != 0) { + SetGlobalFlag(GORON_KAKERA_LV5); + clearGlobalFlags: + ClearGlobalFlag(GORON_KAKERA_L); + ClearGlobalFlag(GORON_KAKERA_M); + ClearGlobalFlag(GORON_KAKERA_R); } } this->itemActive[2] = 0; diff --git a/src/manager/manager32.c b/src/manager/manager32.c index 409840de..606f07ea 100644 --- a/src/manager/manager32.c +++ b/src/manager/manager32.c @@ -73,7 +73,7 @@ void sub_0805D860(Manager32* this) { case 0: this->manager.unk_0d = 1; this->field_0x20 = 0x80; - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; break; case 1: if (--this->field_0x20 == 0x10) { @@ -95,7 +95,7 @@ void sub_0805D860(Manager32* this) { default: if (--this->manager.unk_0e == 0) { sub_0801E104(); - gScreen.lcd.displayControl &= 0xf7ff; + gScreen.lcd.displayControl &= ~DISPCNT_BG3_ON; DeleteThisEntity(); } } @@ -107,7 +107,7 @@ void sub_0805D900(Manager32* this) { this->manager.unk_0d = 1; this->manager.unk_0e = 0x2d; this->field_0x20 = 1; - gScreen.lcd.displayControl |= 0x800; + gScreen.lcd.displayControl |= DISPCNT_BG3_ON; break; case 1: if (--this->manager.unk_0e == 0) { @@ -126,7 +126,7 @@ void sub_0805D900(Manager32* this) { this->field_0x20 += 4; if (this->field_0x20 > 0x80) { sub_0801E104(); - gScreen.lcd.displayControl &= 0xf7ff; + gScreen.lcd.displayControl &= ~DISPCNT_BG3_ON; DeleteThisEntity(); } break; @@ -164,7 +164,7 @@ void sub_0805DA08(u32 x, u32 y, u32 param_3) { affineDstData->pa = ((gSineTable[(param_3 + i + y) & 0xff] * x) >> 8) + gScreen.bg3.xOffset; affineDstData = (struct BgAffineDstData*)&affineDstData->pb; } - sub_0805622C(&gUnk_02017AA0[gUnk_03003DE4[0] * 0xa0], 0x400001c, 0xa2600001); + sub_0805622C(&gUnk_02017AA0[gUnk_03003DE4[0] * 0xa0], REG_ADDR_BG3HOFS, 0xa2600001); } void sub_0805DA90(Manager32* this, u32 param_2) { @@ -177,7 +177,7 @@ void sub_0805DA90(Manager32* this, u32 param_2) { AppendEntityToList((Entity*)manager, 8); } if (gArea.onEnter != NULL) { - gScreen.lcd.displayControl &= 0xf7ff; + gScreen.lcd.displayControl &= ~DISPCNT_BG3_ON; RoomExitCallback(); //! @bug: this always variable points to ROM, not a Manager* DeleteManager((Manager*)gArea.onEnter); diff --git a/src/manager/manager36.c b/src/manager/manager36.c index c955425f..96e8b1a3 100644 --- a/src/manager/manager36.c +++ b/src/manager/manager36.c @@ -32,7 +32,7 @@ void CreateManager36(Entity* entity, ScriptExecutionContext* context) { manager->subtype = 0x36; manager->unk_0a = context->intVariable; AppendEntityToList((Entity*)manager, 6); - SetDefaultPriority((Entity*)manager, 6); + SetDefaultPriority((Entity*)manager, PRIO_PLAYER_EVENT); } } diff --git a/src/manager/manager39.c b/src/manager/manager39.c index 1e51d22e..65355f84 100644 --- a/src/manager/manager39.c +++ b/src/manager/manager39.c @@ -48,7 +48,7 @@ void sub_0805E140(Manager39* this) { this->unk_20 = gRoomControls.roomID; this->manager.unk_0e = 0x78; this->manager.unk_0f = 0x3c; - SetDefaultPriority((Entity*)this, 7); + SetDefaultPriority((Entity*)this, PRIO_HIGHEST); sub_0805E1F8(gUnk_08108DE8[gArea.locationIndex], CheckIsDungeon()); } @@ -58,7 +58,7 @@ void sub_0805E18C(Manager39* this) { if (this->manager.unk_0b) { if (!--this->manager.unk_0f) { this->manager.unk_0b = 0; - gPlayerState.field_0x8b = 1; + gPlayerState.controlMode = 1; ResetSystemPriority(); } } diff --git a/src/manager/manager7.c b/src/manager/manager7.c index b081b4ff..59cf85b6 100644 --- a/src/manager/manager7.c +++ b/src/manager/manager7.c @@ -14,7 +14,7 @@ void sub_08057E30(); u32 sub_08057E40(); void sub_08057E7C(u32); -extern u32 sub_08056300(const u16*); +extern u32 CheckRegionsOnScreen(const u16*); extern const u8 gGlobalGfxAndPalettes[]; @@ -66,7 +66,7 @@ void Manager7_Main(Manager7* this) { this->manager.unk_0e = 8; this->unk_20 = 0xFF; - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); RegisterTransitionManager(this, sub_08057E30, 0); } if (sub_08057E40(this)) { @@ -113,7 +113,7 @@ void sub_08057E30(Manager7* this) { } u32 sub_08057E40(Manager7* this) { - u32 tmp = sub_08056300(gUnk_08108050); + u32 tmp = CheckRegionsOnScreen(gUnk_08108050); if (tmp != 0xFF) { gRoomVars.unk_10[0] = tmp; return 1; @@ -124,7 +124,7 @@ u32 sub_08057E40(Manager7* this) { void sub_08057E64() { u32 tmp; - tmp = sub_08056300(gUnk_08108050); + tmp = CheckRegionsOnScreen(gUnk_08108050); if (tmp != 0xFF) { sub_08057E7C(tmp); } diff --git a/src/manager/managerA.c b/src/manager/managerA.c index 76cab147..564c1cac 100644 --- a/src/manager/managerA.c +++ b/src/manager/managerA.c @@ -136,7 +136,7 @@ void sub_08058514(ManagerA* this) { case 3: if (gPlayerEntity.action != 1 && gPlayerEntity.action != 9) return; - gPlayerState.field_0x8b = 1; + gPlayerState.controlMode = 1; ResetPlayerEventPriority(); SetFlag(this->unk_3c); DeleteThisEntity(); diff --git a/src/manager/managerB.c b/src/manager/managerB.c index f52c4138..82182094 100644 --- a/src/manager/managerB.c +++ b/src/manager/managerB.c @@ -42,7 +42,7 @@ void ManagerB_Init(ManagerB* this) { if (!this->unk_3c) { ManagerB_LoadFight(&this->manager); } - SetDefaultPriority((Entity*)this, 3); + SetDefaultPriority((Entity*)this, PRIO_NO_BLOCK); } else { DeleteThisEntity(); } @@ -148,7 +148,7 @@ void ManagerBHelper_Main(Manager* this) { Entity* current; if (this->action == 0) { this->action = 1; - SetDefaultPriority((Entity*)this, 3); + SetDefaultPriority((Entity*)this, PRIO_NO_BLOCK); } // go through and check all monitored enemies. anyRemaining = 0; diff --git a/src/manager/managerC.c b/src/manager/managerC.c index d4a83f64..2583ce98 100644 --- a/src/manager/managerC.c +++ b/src/manager/managerC.c @@ -286,7 +286,7 @@ void sub_08058D34() { LoadGfxGroup(0x16); tmp = gScreen.lcd.displayControl; tmp2 = 0; - gScreen.lcd.displayControl |= 1; + gScreen.lcd.displayControl |= DISPCNT_MODE_1; gScreen.bg2.control = 0xBC82; gScreen.bg1.control = 0x5E86; gScreen.bg1.xOffset = 0; diff --git a/src/manager/managerF.c b/src/manager/managerF.c index 432ec49f..2fb9972b 100644 --- a/src/manager/managerF.c +++ b/src/manager/managerF.c @@ -209,7 +209,7 @@ void sub_08059094(ManagerF* this) { void sub_080590E0(ManagerF* this) { if (!this->manager.action) { this->manager.action = 1; - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); } if (CheckLocalFlag(0x6c)) { if (CheckLocalFlag(0x4b)) { @@ -427,7 +427,7 @@ void sub_080594DC(ManagerF* this) { #if defined(USA) || defined(DEMO_USA) || defined(DEMO_JP) void sub_08059548(ManagerF* this) { - SetDefaultPriority((Entity*)this, 6); + SetDefaultPriority((Entity*)this, PRIO_PLAYER_EVENT); if (gPlayerEntity.action == 0x16) { DeleteThisEntity(); } @@ -82,7 +82,7 @@ void (*const gNPCFunctions[][3])(Entity* ent) = { [GREGAL] = { Gregal, NULL, Gregal_Fusion }, [MAYOR_HAGEN] = { MayorHagen, NULL, MayorHagen_Fusion }, [BIG_GORON] = { BigGoron, NULL, NULL }, - [EZLO_CAP] = { EzloCap, NULL, NULL }, + [EZLO] = { Ezlo, NULL, NULL }, [NPC_UNK_4E] = { NPC4E, NULL, NPC4E_Fusion }, [NPC_UNK_4F] = { NPC4F, NULL, NULL }, [CLOTHES_RACK] = { ClothesRack, NULL, NULL }, diff --git a/src/npc/beedle.c b/src/npc/beedle.c index ce9c7722..ada9a485 100644 --- a/src/npc/beedle.c +++ b/src/npc/beedle.c @@ -153,7 +153,7 @@ void sub_080634E4(Entity* this, ScriptExecutionContext* context) { } void sub_080634EC(Entity* this) { - gRoomVars.itemForSaleIndex = gUnk_0810C88C[this->type2]; + gRoomVars.shopItemType = gUnk_0810C88C[this->type2]; } void sub_08063504(Entity* this, ScriptExecutionContext* context) { diff --git a/src/npc/bigGoron.c b/src/npc/bigGoron.c index 797c9f6f..e76a26e2 100644 --- a/src/npc/bigGoron.c +++ b/src/npc/bigGoron.c @@ -44,7 +44,7 @@ void sub_0806CF30(Entity* this) { this->action = 1; this->subAction = 1; this->field_0x68.HWORD = this->x.HALF.HI; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0806D0B0(this); sub_0807DD64(this); } else { @@ -133,7 +133,7 @@ void sub_0806D1D0(Entity* this) { this->spriteSettings.draw = 3; this->frameIndex = 0; this->actionDelay = 0x1e; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } switch (this->subAction) { @@ -174,7 +174,7 @@ void sub_0806D274(Entity* this) { this->spritePriority.b0 = 7; this->frameIndex = 2; this->actionDelay = 8; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); npc = CreateNPC(0x4c, 3, 0); if (npc != NULL) { npc->child = this; @@ -221,7 +221,7 @@ void sub_0806D348(Entity* this) { this->spritePriority.b0 = 6; this->spriteSettings.draw = 0; this->frameIndex = 5; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } if (this->child->frameIndex == 4) { this->spriteSettings.draw = 3; @@ -239,7 +239,7 @@ void sub_0806D3C0(Entity* this) { } this->action = 1; this->hitbox = &gHitbox_3; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD64(this); } else { this->x.HALF.HI = this->parent->x.HALF.HI; @@ -262,7 +262,7 @@ void sub_0806D41C(Entity* this) { sub_0806D4C0(this, 1); sub_0806D4C0(this, 2); sub_0806D4C0(this, 3); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } else { ExecuteScriptForEntity(this, NULL); HandleEntity0x82Actions(this); @@ -286,7 +286,7 @@ void sub_0806D4C0(Entity* this, u32 param) { npc->parent = this; CopyPosition(this, npc); ResolveEntityOnTop(this, npc); - SetDefaultPriority(npc, 2); + SetDefaultPriority(npc, PRIO_MESSAGE); } } diff --git a/src/npc/carpenter.c b/src/npc/carpenter.c index f489ad72..8663b241 100644 --- a/src/npc/carpenter.c +++ b/src/npc/carpenter.c @@ -24,7 +24,7 @@ void Carpenter(Entity* this) { break; this->action = 1; this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD64(this); case 1: @@ -52,14 +52,14 @@ void Carpenter(Entity* this) { void Carpenter_Head(Entity* this) { if (this->type < 2) { - SetExtraSpriteFrame(this, 0, this->frame & 0xffffff7f); + SetExtraSpriteFrame(this, 0, this->frame & ~0x80); SetExtraSpriteFrame(this, 1, this->frameIndex); SetExtraSpriteFrame(this, 2, this->frameSpriteSettings & 0x3f); SetSpriteSubEntryOffsetData1(this, 1, 0); SetSpriteSubEntryOffsetData2(this, 1, 2); sub_0807000C(this); } else { - SetExtraSpriteFrame(this, 0, this->frame & 0xffffff7f); + SetExtraSpriteFrame(this, 0, this->frame & ~0x80); SetExtraSpriteFrame(this, 1, this->frameIndex); SetSpriteSubEntryOffsetData1(this, 1, 0); sub_0807000C(this); @@ -94,7 +94,7 @@ void Carpenter_Fusion(Entity* this) { if (LoadExtraSpriteData(this, &gUnk_08110CA8[this->type * 4]) != 0) { this->action = this->action + 1; this->spriteSettings.draw = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitializeAnimation(this, (u32)this->type * 8 + 2); } } else { diff --git a/src/npc/cat.c b/src/npc/cat.c index 3371284c..3fec5ab9 100644 --- a/src/npc/cat.c +++ b/src/npc/cat.c @@ -153,7 +153,7 @@ void sub_0806799C(Entity* this) { UpdateAnimationSingleFrame(this); if ((gMessage.doTextBox & 0x7f) == 0) { sub_08067B08(this); - SetDefaultPriority(this, 1); + SetDefaultPriority(this, PRIO_PLAYER); } } @@ -319,7 +319,7 @@ void sub_08067C44(Entity* this) { } else { this->action = 4; sub_08067790(this); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } this->interactType = 0; SoundReq(SFX_VO_CAT); diff --git a/src/npc/cucco.c b/src/npc/cucco.c index 8bd30005..b935dc7b 100644 --- a/src/npc/cucco.c +++ b/src/npc/cucco.c @@ -21,7 +21,7 @@ void sub_0806E4B8(Entity* this) { this->action += 1; this->field_0x68.HALF.LO = sub_0801E99C(this); sub_080787A8(this, this->field_0x68.HALF.LO); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); this->subAction = 0; sub_0806E4EC(this); } diff --git a/src/npc/cuccoChick.c b/src/npc/cuccoChick.c index 0cb4b76c..bfadc897 100644 --- a/src/npc/cuccoChick.c +++ b/src/npc/cuccoChick.c @@ -22,7 +22,7 @@ void sub_0806E730(Entity* this) { this->action += 1; this->field_0x68.HALF.LO = sub_0801E99C(this); sub_080787A8(this, this->field_0x68.HALF.LO); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); this->subAction = 0; sub_0806E764(this); } diff --git a/src/npc/dampe.c b/src/npc/dampe.c index 096ac1e8..afb9ef63 100644 --- a/src/npc/dampe.c +++ b/src/npc/dampe.c @@ -16,7 +16,7 @@ void Dampe(Entity* this) { case 0: this->action = 1; this->spriteSettings.draw = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); return; case 1: diff --git a/src/npc/dog.c b/src/npc/dog.c index 3dc8641e..e749ea7e 100644 --- a/src/npc/dog.c +++ b/src/npc/dog.c @@ -66,7 +66,7 @@ void sub_08069B44(Entity* this) { this->animationState = 2; this->field_0x6a.HALF.LO = 0xff; this->field_0x74.HALF.LO = sub_0801E99C(this); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitAnimationForceUpdate(this, 10); if ((this->flags & 2) != 0) { sub_0807DD50(this); @@ -273,7 +273,7 @@ u32 sub_08069F90(Entity* this) { if ((this->type == 2) && (CheckLocalFlag(MACHI_02_DOG) == 0)) { return 1; } else { - return sub_080041A0(this, &gPlayerEntity, 0x14, 0x14); + return EntityInRectRadius(this, &gPlayerEntity, 0x14, 0x14); } } @@ -362,7 +362,7 @@ void Dog_Fusion(Entity* this) { if (sub_08069EF0(this) != 0) { this->action += 1; this->spriteSettings.draw = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitializeAnimation(this, 0x23); } } else { diff --git a/src/npc/drLeft.c b/src/npc/drLeft.c index cdc05551..06de67f8 100644 --- a/src/npc/drLeft.c +++ b/src/npc/drLeft.c @@ -17,7 +17,7 @@ void DrLeft(Entity* this) { if (this->type == 0) { if (this->action == 0) { this->action += 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } ExecuteScriptForEntity(this, NULL); diff --git a/src/npc/emma.c b/src/npc/emma.c index fa75eea0..ed4d6025 100644 --- a/src/npc/emma.c +++ b/src/npc/emma.c @@ -10,7 +10,7 @@ extern ScreenTransitionData gUnk_0813AD38; void Emma(Entity* this) { if (this->action == 0) { this->action += 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } else { sub_0807DD94(this, 0); diff --git a/src/npc/epona.c b/src/npc/epona.c index 540184c2..4c3d9174 100644 --- a/src/npc/epona.c +++ b/src/npc/epona.c @@ -77,7 +77,7 @@ void sub_08065AA4(Entity* this) { sub_0806F118(this); } else { this->action = 3; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_08065A50(this); } InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); diff --git a/src/npc/ezloCap.c b/src/npc/ezlo.c index 6860455b..4f1dcd62 100644 --- a/src/npc/ezloCap.c +++ b/src/npc/ezlo.c @@ -9,10 +9,10 @@ const u8 gUnk_08114134[]; const u8 gUnk_08114144[]; // Ezlo as a cap in the Minish Woods, is destroyed as soon as link wears ezlo -void EzloCap(Entity* this) { +void Ezlo(Entity* this) { if (this->action == 0) { this->action += 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } ExecuteScriptForEntity(this, NULL); diff --git a/src/npc/farmers.c b/src/npc/farmers.c index c2f633fe..d31a7a3a 100644 --- a/src/npc/farmers.c +++ b/src/npc/farmers.c @@ -12,7 +12,7 @@ void sub_0806BC58(Entity* this); ASM_FUNC("asm/non_matching/farmers/Farmers.inc", void Farmers(Entity* this)) void sub_0806BC58(Entity* this) { - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } void Farmers_Head(Entity* this) { diff --git a/src/npc/festari.c b/src/npc/festari.c index 114ac046..49dde08c 100644 --- a/src/npc/festari.c +++ b/src/npc/festari.c @@ -18,7 +18,7 @@ void Festari(Entity* this) { void sub_0805FE10(Entity* this) { this->action = 1; this->spriteSettings.draw = TRUE; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); this->field_0x68.HALF.LO = sub_0801E99C(this); sub_08078784(this, this->field_0x68.HALF.LO); sub_0807DD50(this); @@ -113,7 +113,7 @@ void Festari_Fusion(Entity* this) { if (this->action == 0) { this->action += 1; this->spriteSettings.draw = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitAnimationForceUpdate(this, 8); } else { UpdateAnimationSingleFrame(this); diff --git a/src/npc/forestMinish.c b/src/npc/forestMinish.c index c0a9f88d..a8e04f9c 100644 --- a/src/npc/forestMinish.c +++ b/src/npc/forestMinish.c @@ -32,7 +32,7 @@ void ForestMinish(Entity* this) { this->spriteSettings.draw = TRUE; this->field_0x68.HALF.HI = this->animationState = this->actionDelay << 1; this->actionDelay = 0; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); StartCutscene(this, (u16*)gUnk_08109D18[this->type2]); sub_0807DD50(this); } @@ -267,7 +267,7 @@ void ForestMinish_Fusion(Entity* this) { if (LoadExtraSpriteData(this, &gUnk_0810A348)) { this->action++; this->spriteSettings.draw = TRUE; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitializeAnimation(this, 6); } } else { diff --git a/src/npc/gentari.c b/src/npc/gentari.c index 46b8500f..d4938806 100644 --- a/src/npc/gentari.c +++ b/src/npc/gentari.c @@ -10,7 +10,7 @@ void Gentari(Entity* this) { case 0: this->action = 1; this->spriteSettings.draw = TRUE; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); this->field_0x68.HALF.LO = sub_0801E99C(this); sub_08078784(this, this->field_0x68.HALF.LO); sub_0807DD50(this); @@ -36,7 +36,7 @@ void Gentari_Fusion(Entity* this) { if (this->action == 0) { this->action++; this->spriteSettings.draw = TRUE; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitAnimationForceUpdate(this, 10); } else { UpdateAnimationSingleFrame(this); diff --git a/src/npc/ghostBrothers.c b/src/npc/ghostBrothers.c index 1cdbdd8a..de04427b 100644 --- a/src/npc/ghostBrothers.c +++ b/src/npc/ghostBrothers.c @@ -94,7 +94,7 @@ void sub_08065D18(Entity* this) { this->spriteSettings.draw = 1; this->spriteRendering.alphaBlend = 1; *(u32**)&this->field_0x6c = &gUnk_08110188; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitAnimationForceUpdate(this, 2); gScreen.controls.layerFXControl = 0x3f40; gScreen.controls.alphaBlend = 0x1000; diff --git a/src/npc/goronMerchant.c b/src/npc/goronMerchant.c index 28962706..9c1b107c 100644 --- a/src/npc/goronMerchant.c +++ b/src/npc/goronMerchant.c @@ -8,12 +8,12 @@ #include "script.h" #include "save.h" -extern u32 GoronMerchant_GetSalePrice(Entity*); +static u32 GoronMerchant_GetSalePrice(Entity*); extern void (*const gUnk_08111B88[])(Entity*); extern void (*const gUnk_08111B98[])(Entity*); -const u16 GoronMerchant_KinstonePrices[]; +static const u16 sKinstonePrices[]; extern u32 sub_0801E7D0(u32); @@ -78,8 +78,6 @@ void sub_08069654(Entity* this) { } void sub_08069660(Entity* this) { - u32 uVar1; - MessageNoOverlap(0x2c1c, this); gMessage.field_0x10 = (u16)GoronMerchant_GetSalePrice(this); } @@ -98,16 +96,16 @@ void sub_08069684(void) { } void sub_080696B0(void) { - gRoomVars.itemForSaleIndex = 0; + gRoomVars.shopItemType = 0; } -u32 GoronMerchant_GetSalePrice(Entity* this) { +static u32 GoronMerchant_GetSalePrice(Entity* this) { u32 restockCount; u32 temp; u32 kinstoneType; s32 itemForSale; - itemForSale = gRoomVars.field_0x7; + itemForSale = gRoomVars.shopItemType2; if (itemForSale > 0x70) { kinstoneType = 1; } else { @@ -129,17 +127,17 @@ u32 GoronMerchant_GetSalePrice(Entity* this) { if (CheckGlobalFlag(GORON_KAKERA_LV5)) { restockCount = 4; } - return GoronMerchant_KinstonePrices[restockCount * 3 + kinstoneType]; + return sKinstonePrices[restockCount * 3 + kinstoneType]; } void GoronMerchant_TryToBuyKinstone(Entity* this, ScriptExecutionContext* context) { s32 salePrice = GoronMerchant_GetSalePrice(this); if (salePrice <= gSave.stats.rupees) { - if (sub_0801E7D0(gRoomVars.field_0x7) < 99) { + if (sub_0801E7D0(gRoomVars.shopItemType2) < 99) { ModRupees(-salePrice); - sub_080A7C18(0x5c, gRoomVars.field_0x7, 0); - gRoomVars.itemForSaleIndex = 0; - gRoomVars.field_0x7 = 0; + sub_080A7C18(0x5c, gRoomVars.shopItemType2, 0); + gRoomVars.shopItemType = 0; + gRoomVars.shopItemType2 = 0; context->condition = 1; } else { MessageNoOverlap(0x2c1f, this); @@ -149,7 +147,7 @@ void GoronMerchant_TryToBuyKinstone(Entity* this, ScriptExecutionContext* contex MessageNoOverlap(0x2c1e, this); context->condition = 0; } - gActiveScriptInfo.flags = gActiveScriptInfo.flags | 1; + gActiveScriptInfo.flags |= 1; } void (*const gUnk_08111B88[])(Entity*) = { @@ -163,7 +161,7 @@ void (*const gUnk_08111B98[])(Entity*) = { sub_08069654, }; -const u16 GoronMerchant_KinstonePrices[] = { +static const u16 sKinstonePrices[] = { #ifdef EU 200, 100, diff --git a/src/npc/gregal.c b/src/npc/gregal.c index db60132d..60003505 100644 --- a/src/npc/gregal.c +++ b/src/npc/gregal.c @@ -19,7 +19,7 @@ void sub_0806CAF4(Entity* this) { if (this->action == 0) { this->action += 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); npc = CreateNPC(0x4a, 1, 0); if (npc != NULL) { npc->parent = this; @@ -46,7 +46,7 @@ void sub_0806CB80(Entity* this) { this->action += 1; this->animationState = 2; this->frameIndex = 0; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } if (this->parent != NULL) { this->frameIndex = (this->parent->frame & 3) + 0x21; @@ -57,7 +57,7 @@ void sub_0806CBB4(Entity* this) { if (this->action == 0) { this->action += 1; this->animationState = 2; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitializeAnimation(this, 0x11); } GetNextFrame(this); @@ -74,7 +74,7 @@ void sub_0806CC08(Entity* this) { case 0: this->action = 1; this->spriteSettings.draw = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD64(this); case 1: if (this->interactType == 2) { @@ -154,7 +154,7 @@ void Gregal_Fusion(Entity* this) { if (this->action == 0) { this->action += 1; this->spriteSettings.draw = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitAnimationForceUpdate(this, 6); } else { UpdateAnimationSingleFrame(this); diff --git a/src/npc/hurdyGurdyMan.c b/src/npc/hurdyGurdyMan.c index 8fbd8b0d..52277dff 100644 --- a/src/npc/hurdyGurdyMan.c +++ b/src/npc/hurdyGurdyMan.c @@ -20,7 +20,7 @@ void HurdyGurdyMan(Entity* this) { if (LoadExtraSpriteData(this, &gUnk_081144F0) != 0) { this->action = 1; this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } break; @@ -36,7 +36,7 @@ void HurdyGurdyMan(Entity* this) { pointerToArray = pointerToArray + 3; } sub_0801DFB4(this, (u32)*pointerToArray, (u32)pointerToArray[1], (u32)pointerToArray[2]); - gPlayerState.field_0x8b = 3; + gPlayerState.controlMode = CONTROL_DISABLED; } else { sub_0807DD94(this, NULL); } @@ -79,7 +79,7 @@ void HurdyGurdyMan_Fusion(Entity* this) { if (uVar1 != 0) { this->action += 1; this->spriteSettings.draw = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitializeAnimation(this, 10); } } else { diff --git a/src/npc/kingGustaf.c b/src/npc/kingGustaf.c index 596e0b90..a40a19f6 100644 --- a/src/npc/kingGustaf.c +++ b/src/npc/kingGustaf.c @@ -11,7 +11,7 @@ void KingGustaf(Entity* this) { this->action += 1; this->spriteRendering.alphaBlend = 1; this->collisionLayer = 2; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); gScreen.controls.layerFXControl = 0x3f40; gScreen.controls.alphaBlend = 0x1000; diff --git a/src/npc/librari.c b/src/npc/librari.c index 0d484d2a..509d790e 100644 --- a/src/npc/librari.c +++ b/src/npc/librari.c @@ -16,7 +16,7 @@ void Librari(Entity* this) { this->animationState = this->actionDelay; this->field_0x68.HALF.LO = sub_0801E99C(this); sub_08078784(this, this->field_0x68.HALF.LO); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); break; case 1: diff --git a/src/npc/mama.c b/src/npc/mama.c index 5c85f121..d5ea5950 100644 --- a/src/npc/mama.c +++ b/src/npc/mama.c @@ -48,7 +48,7 @@ bool32 sub_0806C454(Entity* this) { if (LoadExtraSpriteData(this, &gUnk_08113754) == 0) { return FALSE; } else { - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); return TRUE; } } diff --git a/src/npc/marcy.c b/src/npc/marcy.c index 0b6d0dcc..01c94bc4 100644 --- a/src/npc/marcy.c +++ b/src/npc/marcy.c @@ -9,7 +9,7 @@ extern u16 gUnk_0810C34C[]; void Marcy(Entity* this) { if (this->action == 0) { this->action += 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD64(this); } sub_0807DD94(this, NULL); diff --git a/src/npc/mayorHagen.c b/src/npc/mayorHagen.c index a9353164..1c569e92 100644 --- a/src/npc/mayorHagen.c +++ b/src/npc/mayorHagen.c @@ -19,7 +19,7 @@ void MayorHagen(Entity* this) { this->action = 1; this->field_0x68.HALF.HI = 0; this->field_0x68.HALF.LO = sub_0801E99C(this); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); break; case 1: diff --git a/src/npc/melari.c b/src/npc/melari.c index e0879f3b..146ae078 100644 --- a/src/npc/melari.c +++ b/src/npc/melari.c @@ -65,7 +65,7 @@ void sub_08068780(Entity* this) { this->action = 1; this->spriteSettings.draw = TRUE; this->animationState = this->type; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); break; case 1: diff --git a/src/npc/minishEzlo.c b/src/npc/minishEzlo.c index a6824c50..0d2d017b 100644 --- a/src/npc/minishEzlo.c +++ b/src/npc/minishEzlo.c @@ -12,7 +12,7 @@ void MinishEzlo(Entity* this) { } this->action += 1; this->animationState = this->actionDelay * 2; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } ExecuteScriptForEntity(this, NULL); diff --git a/src/npc/mutoh.c b/src/npc/mutoh.c index b1263127..7cae63d1 100644 --- a/src/npc/mutoh.c +++ b/src/npc/mutoh.c @@ -23,7 +23,7 @@ void Mutoh(Entity* this) { if (LoadExtraSpriteData(this, &gUnk_08110C00)) { this->action = 1; this->spriteSettings.draw = TRUE; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } break; diff --git a/src/npc/percy.c b/src/npc/percy.c index 85eb80fc..90e10b28 100644 --- a/src/npc/percy.c +++ b/src/npc/percy.c @@ -79,7 +79,7 @@ void sub_0806B41C(Entity* this) { if (this->field_0x68.HALF.LO == 33) tmp += 3; sub_0801DFB4(this, tmp[0], tmp[1], tmp[2]); - gPlayerState.field_0x8b = 3; + gPlayerState.controlMode = CONTROL_DISABLED; } else { sub_0807DD94(this, NULL); } diff --git a/src/npc/pita.c b/src/npc/pita.c index b379ba8f..36856cb5 100644 --- a/src/npc/pita.c +++ b/src/npc/pita.c @@ -15,7 +15,7 @@ extern u32 sub_080028F4(const u8*); void Pita(Entity* this) { if (this->action == 0) { this->action += 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); ResolveEntityOnTop(this, this); this->hitbox = &gUnk_0810C428; sub_0807DD64(this); diff --git a/src/npc/rem.c b/src/npc/rem.c index 7298b531..09f4464e 100644 --- a/src/npc/rem.c +++ b/src/npc/rem.c @@ -55,7 +55,7 @@ void sub_0806A3D8(Entity* this) { this->action = 1; this->actionDelay = 0xb4; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0806A8C8(this); uVar1 = StartCutscene(this, &script_08012F0C); *(ScriptExecutionContext**)&this->cutsceneBeh = uVar1; @@ -196,7 +196,7 @@ void sub_0806A830(Entity* this) { if (this->action == 0) { this->action = 1; InitializeAnimation(this, 0x14); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } if ((gActiveScriptInfo.unk_00 & 0x200) != 0) { DeleteThisEntity(); @@ -215,7 +215,7 @@ void sub_0806A890(Entity* this) { if (this->action == 0) { this->action = 1; InitializeAnimation(this, 0x15); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } GetNextFrame(this); if ((this->frame & 0x80) != 0) { diff --git a/src/npc/stockwell.c b/src/npc/stockwell.c index dc38b634..ef0f0486 100644 --- a/src/npc/stockwell.c +++ b/src/npc/stockwell.c @@ -28,7 +28,7 @@ void sub_08065080(Entity* this) { this->action = 1; this->spriteSettings.draw = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitializeAnimation(this, 4); sub_08078778(this); #ifndef EU diff --git a/src/npc/syrup.c b/src/npc/syrup.c index 92b4c8b5..3554d95a 100644 --- a/src/npc/syrup.c +++ b/src/npc/syrup.c @@ -27,7 +27,7 @@ void sub_0806A1F8(Entity* this) { iVar1 = LoadExtraSpriteData(this, paVar2); if (iVar1) { this->action = 1; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); InitializeAnimation(this, 0); } diff --git a/src/npc/teachers.c b/src/npc/teachers.c index dc811ab9..645361d2 100644 --- a/src/npc/teachers.c +++ b/src/npc/teachers.c @@ -18,7 +18,7 @@ void Teachers(Entity* this) { this->spriteSettings.draw = TRUE; this->animationState = this->actionDelay; this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } break; diff --git a/src/npc/townMinish.c b/src/npc/townMinish.c index 5f97093c..cde7c526 100644 --- a/src/npc/townMinish.c +++ b/src/npc/townMinish.c @@ -57,7 +57,7 @@ void sub_0806AC3C(Entity* this) { if (this->animIndex <= 3) { s32 unk; Entity* link = &gPlayerEntity; - if (sub_080041A0(this, link, 0x18, 0x18)) { + if (EntityInRectRadius(this, link, 0x18, 0x18)) { unk = GetFacingDirection(this, link) & 0x1e; } else { unk = this->animationState * 4; diff --git a/src/npc/vaati.c b/src/npc/vaati.c index bae2bdac..751a1be6 100644 --- a/src/npc/vaati.c +++ b/src/npc/vaati.c @@ -27,7 +27,7 @@ void VaatiAction0(Entity* this) { this->spriteSettings.draw = 1; this->field_0x68.HALF.LO = 0; this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD64(this); VaatiAction1(this); } diff --git a/src/npc/wheaton.c b/src/npc/wheaton.c index 338ff377..7eafda20 100644 --- a/src/npc/wheaton.c +++ b/src/npc/wheaton.c @@ -9,7 +9,7 @@ void Wheaton(Entity* this) { if (this->action == 0) { this->action++; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); ResolveEntityOnTop(this, this); diff --git a/src/npc/zelda.c b/src/npc/zelda.c index f1da1c47..834679fa 100644 --- a/src/npc/zelda.c +++ b/src/npc/zelda.c @@ -23,7 +23,7 @@ void sub_08066CCC(Entity* this) { this->action = 1; this->spriteSettings.draw = 1; PrependEntityToList(this, 7); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } diff --git a/src/npc/zeldaFollower.c b/src/npc/zeldaFollower.c index 72e650ff..93d1ca3f 100644 --- a/src/npc/zeldaFollower.c +++ b/src/npc/zeldaFollower.c @@ -16,7 +16,7 @@ void ZeldaFollower(Entity* this) { this->animationState = 4; this->field_0x68.HALF.LO = 0; this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); InitAnimationForceUpdate(this, 0); sub_0806854C(this, NULL); } diff --git a/src/object.c b/src/object.c index 18b401c3..1df8d22e 100644 --- a/src/object.c +++ b/src/object.c @@ -10,7 +10,7 @@ void (*const gObjectFunctions[])(Entity*) = { [BUTTON] = Button, [OBJECT_4] = Object4, [POT] = Pot, - [OBJECT_6] = Object6, + [EZLO_CAP] = EzloCap, [PUSHED_BLOCK] = BlockPushed, [LOCKED_DOOR] = LockedDoor, [OBJECT_9] = Object9, diff --git a/src/object/bigVortex.c b/src/object/bigVortex.c index f2743031..5e7f87eb 100644 --- a/src/object/bigVortex.c +++ b/src/object/bigVortex.c @@ -34,7 +34,7 @@ void sub_08098D1C(Entity* this) { this->spriteSettings.draw = TRUE; sub_08098E88(this); } - SetDefaultPriority(this, 6); + SetDefaultPriority(this, PRIO_PLAYER_EVENT); InitAnimationForceUpdate(this, 0); } diff --git a/src/object/book.c b/src/object/book.c index d069a149..3430e4ef 100644 --- a/src/object/book.c +++ b/src/object/book.c @@ -211,7 +211,7 @@ void sub_0809B5EC(Entity* this) { u32 sub_0809B688(Entity* this) { u32 ret; - ret = sub_080041A0(this, &gPlayerEntity, 6, 12); + ret = EntityInRectRadius(this, &gPlayerEntity, 6, 12); if (ret == 1 && gPlayerState.field_0xd != 16) { ret = 0; } diff --git a/src/object/button.c b/src/object/button.c index c1efa9ae..4c026baf 100644 --- a/src/object/button.c +++ b/src/object/button.c @@ -16,7 +16,7 @@ extern u32 sub_08081E3C(Entity*); void sub_08081AE0(Entity* this) { COLLISION_OFF(this); - this->updatePriority = 3; + this->updatePriority = PRIO_NO_BLOCK; this->y.HALF.HI++; if (this->cutsceneBeh.HWORD != 0) { this->collisionLayer = this->cutsceneBeh.HWORD; @@ -158,11 +158,11 @@ Entity* sub_08081D74(Entity* this) { } } else { if (gPlayerState.flags & 0x400000) { - if (sub_080041A0(this, gUnk_03004040[0], 5, 6)) { + if (EntityInRectRadius(this, gUnk_03004040[0], 5, 6)) { ent = gUnk_03004040[0]; - } else if (sub_080041A0(this, gUnk_03004040[1], 5, 6)) { + } else if (EntityInRectRadius(this, gUnk_03004040[1], 5, 6)) { ent = gUnk_03004040[1]; - } else if (sub_080041A0(this, gUnk_03004040[2], 5, 6)) { + } else if (EntityInRectRadius(this, gUnk_03004040[2], 5, 6)) { ent = gUnk_03004040[2]; } } @@ -176,7 +176,7 @@ u32 sub_08081E0C(Entity* this) { if (tmp->z.HALF.HI != 0 || !sub_08079F8C()) { return 0; } else { - return sub_080041A0(this, tmp, 5, 6); + return EntityInRectRadius(this, tmp, 5, 6); } } @@ -234,13 +234,13 @@ u32 sub_08081F00(u32* unk1, u32* unk2) { void sub_08081F24(Entity* this) { Entity* fx = CreateFx(this, FX_DASH, 0x40); if (fx) { - fx->updatePriority = 3; + fx->updatePriority = PRIO_NO_BLOCK; fx->x.HALF.HI += 7; fx->y.HALF.HI += 5; } fx = CreateFx(this, FX_DASH, 0x40); if (fx) { - fx->updatePriority = 3; + fx->updatePriority = PRIO_NO_BLOCK; fx->x.HALF.HI -= 7; fx->y.HALF.HI += 5; } @@ -252,7 +252,7 @@ u32 sub_08081F7C(Entity* this, u32 r7) { return 1; if (--this->actionDelay > 6) { if (this->child) - this->child->spriteOffsetY = 0xfc; + this->child->spriteOffsetY = -4; } else { if (this->actionDelay == 6) { SetFlag(this->field_0x86.HWORD); diff --git a/src/object/cloud.c b/src/object/cloud.c index 8b53e550..d8915514 100644 --- a/src/object/cloud.c +++ b/src/object/cloud.c @@ -120,7 +120,7 @@ void sub_0809F69C(Entity* this) { void sub_0809F6CC(Entity* this) { if (((gRoomControls.unk6 & 4) == 0) && (--this->actionDelay == 0)) { - gPlayerState.field_0x8b = 1; + gPlayerState.controlMode = 1; DeleteThisEntity(); } } diff --git a/src/object/greatFairy.c b/src/object/greatFairy.c index 0aca5575..e5575a47 100644 --- a/src/object/greatFairy.c +++ b/src/object/greatFairy.c @@ -469,7 +469,7 @@ void GreatFairy_InitializeAnimation(Entity* this) { this->type2 = this->type % temp; this->collisionLayer = 2; InitializeAnimation(this, this->type2); - SetDefaultPriority(this, 2); + SetDefaultPriority(this, PRIO_MESSAGE); } Entity* GreatFairy_CreateForm(Entity* this, u32 curForm, u32 parameter) { @@ -516,7 +516,7 @@ void sub_08087424(Entity* this, ScriptExecutionContext* context) { if (ent != NULL) { ent->parent = &gPlayerEntity; CopyPosition(&gPlayerEntity, ent); - SetDefaultPriority(ent, 2); + SetDefaultPriority(ent, PRIO_MESSAGE); } switch (context->intVariable) { diff --git a/src/object/heartContainer.c b/src/object/heartContainer.c index 7664546c..b0fb32e1 100644 --- a/src/object/heartContainer.c +++ b/src/object/heartContainer.c @@ -31,7 +31,7 @@ static void sub_0808E6A0(Entity* this) { this->spriteSettings.draw = 0; this->hitbox = &gUnk_08121C58; this->collisionLayer = 3; - this->updatePriority = 3; + this->updatePriority = PRIO_NO_BLOCK; } static void sub_0808E6E4(Entity* this) { diff --git a/src/object/houseDoorExterior.c b/src/object/houseDoorExterior.c index ae4f133d..b9747788 100644 --- a/src/object/houseDoorExterior.c +++ b/src/object/houseDoorExterior.c @@ -27,7 +27,7 @@ static bool32 sub_080867CC(u32); void sub_0808681C(Entity*); static u8 sub_08086954(Entity*); -extern u32 sub_080562CC(u32, u32, u32, u32); +extern u32 CheckRegionOnScreen(u32, u32, u32, u32); extern void sub_08078AC0(u32, u32, u32); extern void (*const gUnk_081206B4[])(Entity*); @@ -46,14 +46,14 @@ void sub_080866D8(Entity* this) { this->action = 1; *((u32*)(&this->field_0x68)) = 0; this->field_0x6c.HALF.LO = this->actionDelay; - SetDefaultPriority(this, 6); + SetDefaultPriority(this, PRIO_PLAYER_EVENT); } prop = GetCurrentRoomProperty(this->field_0x6c.HALF.LO); for (i = 0; prop->unk0 != 0xFFFF && i < 32; prop++, i++) { int mask = 1 << i; if ((*((u32*)(&this->field_0x68)) & mask) == 0 && sub_080867CC(prop->unk5) && - sub_080562CC(prop->unk0, prop->unk2, 32, 32)) { + CheckRegionOnScreen(prop->unk0, prop->unk2, 32, 32)) { entity = CreateObject(HOUSE_DOOR_EXT, prop->unk7, prop->unk6); if (entity) { entity->field_0x6c.HALF.LO = i; @@ -85,7 +85,7 @@ static bool32 sub_080867CC(u32 arg0) { } void sub_080867E4(Entity* this) { - if (!sub_080562CC(this->field_0x68.HWORD, this->field_0x6a.HWORD, 32, 32)) { + if (!CheckRegionOnScreen(this->field_0x68.HWORD, this->field_0x6a.HWORD, 32, 32)) { *((u32*)(&this->parent->field_0x68)) = *((u32*)(&this->parent->field_0x68)) & ~(1 << this->field_0x6c.HALF.LO); DeleteThisEntity(); } diff --git a/src/object/itemOnGround.c b/src/object/itemOnGround.c index de9e52a0..2c025c77 100644 --- a/src/object/itemOnGround.c +++ b/src/object/itemOnGround.c @@ -120,7 +120,7 @@ void sub_08080F20(Entity* this) { this->field_0x6c.HWORD = 0; this->field_0x68.HALF.LO = 0; this->actionDelay = 0; - SetDefaultPriority(this, 3); + SetDefaultPriority(this, PRIO_NO_BLOCK); this->field_0x1c = sub_0808147C(this->type); gUnk_0811E7E8[this->field_0x68.HALF.HI](this); } else { @@ -338,7 +338,7 @@ void sub_08081404(Entity* this, u32 arg1) { bool32 sub_08081420(Entity* this) { if (CheckShouldPlayItemGetCutscene(this)) { - SetDefaultPriority(this, 6); + SetDefaultPriority(this, PRIO_PLAYER_EVENT); CreateItemEntity(this->type, this->type2, 0); return TRUE; } else { diff --git a/src/object/lilypadSmall.c b/src/object/lilypadSmall.c index b98ff330..ae74c9c8 100644 --- a/src/object/lilypadSmall.c +++ b/src/object/lilypadSmall.c @@ -34,7 +34,7 @@ void LilypadSmall(Entity* this) { u32 sub_08097ADC(Entity* this) { if ((gPlayerState.flags & PL_MINISH) == 0) { return 0; - } else if (sub_080041A0(this, &gPlayerEntity, 8, 8) == 0) { + } else if (EntityInRectRadius(this, &gPlayerEntity, 8, 8) == 0) { return 0; } else if (sub_08079F8C() == 0) { return 0; diff --git a/src/object/minecart.c b/src/object/minecart.c index 002c4946..fe333927 100644 --- a/src/object/minecart.c +++ b/src/object/minecart.c @@ -94,7 +94,7 @@ void sub_080917DC(Entity* this) { } void sub_080918A4(Entity* this) { - if (sub_080041A0(this, &gPlayerEntity, 2, 2) != 0) { + if (EntityInRectRadius(this, &gPlayerEntity, 2, 2) != 0) { gPlayerEntity.x.HALF.HI = this->x.HALF.HI; gPlayerEntity.y.HALF.HI = this->y.HALF.HI; if (gPlayerEntity.z.HALF.HI > -0x10) { diff --git a/src/object/minishSizedEntrance.c b/src/object/minishSizedEntrance.c index 4d7bc406..9338bca5 100644 --- a/src/object/minishSizedEntrance.c +++ b/src/object/minishSizedEntrance.c @@ -31,7 +31,7 @@ void sub_08090F00(Entity* this) { DeleteThisEntity(); } } - if ((gPlayerState.flags & PL_MINISH) && sub_080041A0(this, &gPlayerEntity, 4, 4) && + if ((gPlayerState.flags & PL_MINISH) && EntityInRectRadius(this, &gPlayerEntity, 4, 4) && (gPlayerEntity.z.HALF.HI == 0) && (((u16)gPlayerState.field_0x90.HALF.LO) & gUnk_0812225C[this->type2])) { DoExitTransition(GetCurrentRoomProperty(this->actionDelay)); } diff --git a/src/object/object1A.c b/src/object/object1A.c index e515a30b..7f76d0f7 100644 --- a/src/object/object1A.c +++ b/src/object/object1A.c @@ -55,6 +55,6 @@ void sub_08086A6C(Entity* ent) { uVar1 = Random(); ent->zVelocity = 163840; - ent->direction = (uVar1 >> 16) & 31; + ent->direction = DirectionNormalize(uVar1 >> 16); ent->speed = uVar1 & 480; } diff --git a/src/object/object86.c b/src/object/object86.c index 6829c813..147e623c 100644 --- a/src/object/object86.c +++ b/src/object/object86.c @@ -56,7 +56,7 @@ void sub_08099E58(Entity* this) { } void sub_08099E8C(Entity* this) { - if (sub_080041A0(this, &gPlayerEntity, 0xc, 0xc)) { + if (EntityInRectRadius(this, &gPlayerEntity, 0xc, 0xc)) { if (this->subAction == 0) { sub_08099ECC(this); RequestPriorityDuration(this, 0x1e); diff --git a/src/object/objectA2.c b/src/object/objectA2.c index de21a664..4bcfa284 100644 --- a/src/object/objectA2.c +++ b/src/object/objectA2.c @@ -40,7 +40,7 @@ void sub_0809F318(Entity* this) { this->spriteOrientation.flipY = 2; this->action = 1; sub_0801D2B4(this, gUnk_08124704[this->type]); - SetDefaultPriority(this, 7); + SetDefaultPriority(this, PRIO_HIGHEST); } void sub_0809F374(Entity* this) { diff --git a/src/object/warpPoint.c b/src/object/warpPoint.c index a43d9552..58b2722b 100644 --- a/src/object/warpPoint.c +++ b/src/object/warpPoint.c @@ -41,7 +41,7 @@ void sub_0808B474(Entity* this) { this->palette.b.b0 = tmp; this->spritePriority.b0 = 6; this->hitbox = &gHitbox_1; - this->updatePriority = 3; + this->updatePriority = PRIO_NO_BLOCK; InitializeAnimation(this, 0); if (CheckFlags(this->field_0x86.HWORD)) { sub_0808B830(this); @@ -207,7 +207,7 @@ void sub_0808B73C(Entity* this) { u32 sub_0808B7C8(Entity* this) { if (!(gPlayerState.flags & PL_MINISH) && gPlayerState.field_0xa8 != 0x12 && gPlayerEntity.health != 0 && - sub_08079F8C() && sub_080041A0(this, &gPlayerEntity, 5, 5) && gPlayerEntity.z.HALF.HI == 0) { + sub_08079F8C() && EntityInRectRadius(this, &gPlayerEntity, 5, 5) && gPlayerEntity.z.HALF.HI == 0) { if (this->actionDelay == 0 && gPlayerEntity.action == 0x1b) { sub_080791D0(); } diff --git a/src/overworld.c b/src/overworld.c index c529f530..a61a665f 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -637,7 +637,7 @@ static void HandleRoomEnter(void) { u32 sub_08052B24(void) { s32 tmp = 1; - if (!(gInput.heldKeys & SELECT_BUTTON) || gPlayerState.field_0x8b || gUnk_02034490[0] || gUnk_0200AF00.filler0[1]) + if (!(gInput.heldKeys & SELECT_BUTTON) || gPlayerState.controlMode != CONTROL_ENABLED || gUnk_02034490[0] || gUnk_0200AF00.filler0[1]) return 0; if ((gPlayerState.flags & 0x118) || (gPlayerState.field_0xa9 > tmp) || gPlayerState.field_0x2c || diff --git a/src/player.c b/src/player.c index 78b22379..a31d841c 100644 --- a/src/player.c +++ b/src/player.c @@ -11,18 +11,170 @@ #include "functions.h" #include "object.h" #include "effects.h" - -static void (*const sPlayerActions[])(Entity*); -extern void (*const gUnk_0811BA60[])(Entity*); -extern void (*const gUnk_0811BA68[])(Entity*); -extern void (*const gUnk_0811BA74[])(Entity*); -extern void (*const gUnk_0811BA7C[])(Entity*); -extern void (*const gUnk_0811BA88[])(Entity*); -extern void (*const gUnk_0811BA94[])(Entity*); -extern void (*const gUnk_0811BA9C[])(Entity*); -extern void (*const gUnk_0811BAD4[])(Entity*); -extern void (*const gUnk_0811BAE4[])(Entity*); -extern void (*const gUnk_0811BB3C[])(Entity*); +#include "random.h" +#include "hitbox.h" + +typedef void(EntityAction)(Entity*); + +static EntityAction* const sPlayerActions[]; + +static EntityAction PlayerInit; +static EntityAction PlayerNormal; +static EntityAction PlayerInit; +static EntityAction PlayerFall; +static EntityAction PlayerJump; +static EntityAction PlayerPush; +static EntityAction PlayerBounce; +static EntityAction sub_08070E9C; +static EntityAction PlayerItemGet; +EntityAction PlayerMinish; +static EntityAction PlayerMinishDie; +static EntityAction sub_08071DB8; +static EntityAction PlayerEmptyBottle; +static EntityAction PlayerFrozen; +static EntityAction sub_0807204C; +static EntityAction sub_080720DC; +static EntityAction PlayerPull; +static EntityAction PlayerLava; +EntityAction PlayerWarp; +static EntityAction sub_08072454; +static EntityAction PlayerDrown; +static EntityAction PlayerUsePortal; +static EntityAction PlayerTalkEzlo; +static EntityAction PlayerRoomTransition; +static EntityAction PlayerRoll; +static EntityAction sub_080728AC; +static EntityAction PlayerInHole; +static EntityAction sub_08072C9C; +EntityAction sub_08074C44; +static EntityAction sub_08072F34; +static EntityAction PlayerUseEntrance; +EntityAction PlayerParachute; + +// PLAYER_FALL +static EntityAction sub_08070C3C; +static EntityAction sub_08070CB4; + +// PLAYER_BOUNCE +static EntityAction sub_08070D38; +static EntityAction sub_08070DC4; +static EntityAction sub_08070E7C; + +// PLAYER_08070E9C +static EntityAction sub_08070EDC; +static EntityAction sub_08070f24; + +// PLAYER_ITEMGET +static EntityAction sub_08070FA4; +static EntityAction sub_08071020; +static EntityAction sub_08071038; + +// PLAYER_JUMP +static EntityAction sub_080710A8; +static EntityAction sub_08071130; +static EntityAction sub_08071208; + +// PLAYER_DROWN +static EntityAction sub_0807127C; +static EntityAction sub_080712F0; + +// PLAYER_USEPORTAL +static EntityAction PortalJumpOnUpdate; +static EntityAction PortalStandUpdate; +static EntityAction PortalActivateInit; +static EntityAction PortalActivateUpdate; +static EntityAction PortalShrinkInit; +static EntityAction PortalShrinkUpdate; +static EntityAction PortalEnterUpdate; +static EntityAction PortalUnknownUpdate; + +// PLAYER_TALKEZLO +static EntityAction sub_080718A0; +static EntityAction sub_0807193C; +static EntityAction sub_08071990; +static EntityAction sub_08071A4C; + +// PLAYER_PUSH +static EntityAction sub_08071AB0; +static EntityAction sub_08071AF0; +static EntityAction sub_08071B60; + +// PLAYER_MINISHDIE +static EntityAction sub_08071BDC; +static EntityAction sub_08071CAC; +static EntityAction sub_08071D04; +static EntityAction sub_08071D80; + +// PLAYER_08071DB8 +static EntityAction sub_08071DD0; +static EntityAction sub_08071E04; +static EntityAction sub_08071E74; + +// PLAYER_EMPTYBOTTLE +static EntityAction sub_08071EB0; +static EntityAction sub_08071F14; + +// PLAYER_FROZEN +static EntityAction sub_08071F50; +static EntityAction sub_08071F80; + +// PLAYER_0807204C +static EntityAction sub_08072064; +static EntityAction sub_08072098; + +// PLAYER_080720DC +static EntityAction sub_08072100; +static EntityAction sub_08072168; + +// PLAYER_PULL +static EntityAction sub_08072214; +static EntityAction sub_08072260; + +// PLAYER_LAVA +static EntityAction sub_080722DC; +static EntityAction sub_08072354; +static EntityAction sub_080723D0; +static EntityAction sub_0807240C; + +// PLAYER_08072454 +static EntityAction sub_0807246C; +static EntityAction sub_08072490; + +// PLAYER_ROOMTRANSITION +static EntityAction sub_080724DC; +static EntityAction sub_0807258C; + +// PLAYER_ROLL +static EntityAction sub_08072650; +static EntityAction sub_080726F4; + +// PLAYER_INHOLE +static EntityAction sub_08072970; +static EntityAction sub_08072A60; +static EntityAction sub_08072ACC; +static EntityAction sub_08072B5C; +static EntityAction sub_08072C48; + +// PLAYER_08072C9C +static EntityAction sub_08072CC0; +static EntityAction sub_08072CFC; +static EntityAction sub_08072D54; +static EntityAction sub_08072F14; + +// PLAYER_08072F34 +static EntityAction sub_08072F94; +static EntityAction sub_08073094; + +// PLAYER_USEENTRANCE +EntityAction sub_080731D8; +EntityAction sub_080732D0; +EntityAction sub_0807332C; +EntityAction sub_080733BC; + +static void sub_080717F8(Entity*); +static void ResetPlayerPriority(); +static void sub_080728AC(Entity*); +static void BreakOut(); extern void RespawnPlayer(); extern void sub_080797EC(); @@ -30,63 +182,73 @@ extern void sub_08079E08(); extern void sub_08078F60(); extern void sub_0806F948(); extern void sub_08077698(); -extern void SetPlayerEventPriority(); -extern void sub_080717F8(); -extern void ResetPlayerEventPriority(); -extern void sub_08071A6C(); extern void DisplayEzloMessage(); extern void sub_08079258(); -extern void sub_08071AF0(); -extern void sub_080728AC(); extern void sub_0807A298(); extern u32 sub_08079B24(); extern void sub_08079708(); extern void sub_080792D8(); extern Entity* CreatePlayerBomb(); -extern void sub_08072008(); extern void sub_080791BC(); -extern void sub_08072168(); extern u32 sub_0806F854(); extern u32 sub_08019840(); -extern void sub_08072260(); extern void sub_08079744(); extern void sub_0807AE20(); extern u32 sub_0807A894(); extern u32 sub_080797C4(); -extern u32 Random(); extern u32 sub_0807AC54(); extern void sub_0800892E(); extern void sub_08078F24(); extern void sub_0807B068(); extern u32 sub_080001DA(); -extern void sub_08072A60(); extern u32 sub_0807A2F8(); extern u32 CheckIsOverworld(); extern u32 sub_0806F730(); extern u32 sub_08007DD6(); extern u32 GetSurfaceCalcType(); -extern void sub_08073094(); extern void sub_08074808(); -extern void RequestPriorityDuration(); - -typedef struct { - u8 frame; - u8 dummy; - u16 speed; -} PushFrames; -extern PushFrames gUnk_0811BAF0[]; - -extern Hitbox gUnk_08114F88; extern ScreenTransitionData gUnk_0813AB58; void DoPlayerAction(Entity* this) { + static void (*const sPlayerActions[])(Entity*) = { + [PLAYER_INIT] = PlayerInit, + [PLAYER_NORMAL] = PlayerNormal, + [PLAYER_DUMMY] = PlayerInit, + [PLAYER_FALL] = PlayerFall, + [PLAYER_JUMP] = PlayerJump, + [PLAYER_PUSH] = PlayerPush, + [PLAYER_BOUNCE] = PlayerBounce, + [PLAYER_08070E9C] = sub_08070E9C, + [PLAYER_ITEMGET] = PlayerItemGet, + [PLAYER_MINISH] = PlayerMinish, + [PLAYER_MINISHDIE] = PlayerMinishDie, + [PLAYER_08071DB8] = sub_08071DB8, + [PLAYER_EMPTYBOTTLE] = PlayerEmptyBottle, + [PLAYER_FROZEN] = PlayerFrozen, + [PLAYER_0807204C] = sub_0807204C, + [PLAYER_080720DC] = sub_080720DC, + [PLAYER_PULL] = PlayerPull, + [PLAYER_LAVA] = PlayerLava, + [PLAYER_WARP] = PlayerWarp, + [PLAYER_08072454] = sub_08072454, + [PLAYER_DROWN] = PlayerDrown, + [PLAYER_USEPORTAL] = PlayerUsePortal, + [PLAYER_TALKEZLO] = PlayerTalkEzlo, + [PLAYER_ROOMTRANSITION] = PlayerRoomTransition, + [PLAYER_ROLL] = PlayerRoll, + [PLAYER_080728AC] = sub_080728AC, + [PLAYER_INHOLE] = PlayerInHole, + [PLAYER_08072C9C] = sub_08072C9C, + [PLAYER_08074C44] = sub_08074C44, + [PLAYER_08072F34] = sub_08072F34, + [PLAYER_USEENTRANCE] = PlayerUseEntrance, + [PLAYER_PARACHUTE] = PlayerParachute, + }; sPlayerActions[this->action](this); } -void PlayerInit(Entity* this) { - Entity* ent; - +static void PlayerInit(Entity* this) { gPlayerState.field_0x0[0] = 0xff; gPlayerState.startPosX = gPlayerEntity.x.HALF.HI; gPlayerState.startPosY = gPlayerEntity.y.HALF.HI; @@ -97,10 +259,10 @@ void PlayerInit(Entity* this) { this->field_0x16 = 0x20; this->flags2 = 8; this->hitType = 0x79; - this->hitbox = &gUnk_08114F88; + this->hitbox = (Hitbox*)&gPlayerHitbox; this->spriteIndex = 1; #ifndef EU - gPlayerState.field_0x8 = 0x100; + gPlayerState.animation = 0x100; #endif sub_0806FDA0(this); LoadSwapGFX(this, 1, 2); @@ -119,6 +281,7 @@ void PlayerInit(Entity* this) { sub_0807921C(); sub_0807A1B8(); if (gPlayerState.swimState != 0) { + Entity* ent; gPlayerState.swimState = 1; sub_08079938(); gPlayerState.field_0xa8 = 7; @@ -132,9 +295,9 @@ void PlayerInit(Entity* this) { } // PlayerState.flags need to be 100% before this one can reasonably be done -ASM_FUNC("asm/non_matching/player/PlayerNormal.inc", void PlayerNormal(Entity* this)) +static ASM_FUNC("asm/non_matching/player/PlayerNormal.inc", void PlayerNormal(Entity* this)); -void sub_08070BEC(Entity* this, u32 r0) { +static void sub_08070BEC(Entity* this, u32 r0) { if (r0 & 1) sub_080797EC(); else @@ -144,28 +307,33 @@ void sub_08070BEC(Entity* this, u32 r0) { sub_08079E08(); } -void PlayerFall(Entity* this) { +static void PlayerFall(Entity* this) { + static EntityAction* const sPlayerFallStates[] = { + sub_08070C3C, + sub_08070CB4, + }; + gPlayerState.field_0xd = 0xFF; gPlayerState.pushedObject = 0x80; gPlayerState.field_0xa8 = 10; - gUnk_0811BA60[this->subAction](this); + sPlayerFallStates[this->subAction](this); } -void sub_08070C3C(Entity* this) { +static void sub_08070C3C(Entity* this) { sub_08004168(this); - gPlayerState.flags |= 0x1 | 0x4; - gPlayerState.flags &= ~0x400; + gPlayerState.flags |= PL_BUSY | PL_DROWNING; + gPlayerState.flags &= ~PL_BURNING; gPlayerState.jumpStatus = 0; if ((gPlayerState.flags & PL_MINISH) != 0) - gPlayerState.field_0x8 = 0x1ba; + gPlayerState.animation = 0x1ba; else if ((gPlayerState.flags & 8) != 0) - gPlayerState.field_0x8 = 0x458; + gPlayerState.animation = 0x458; else - gPlayerState.field_0x8 = 0x1b8; + gPlayerState.animation = 0x1b8; this->subAction++; COLLISION_OFF(this); @@ -176,14 +344,14 @@ void sub_08070C3C(Entity* this) { SoundReq(SFX_FALL_HOLE); } -void sub_08070CB4(Entity* this) { +static void sub_08070CB4(Entity* this) { UpdateAnimationSingleFrame(this); if ((this->frame & 0x80) != 0) { if ((gSave.stats.health != 0) && ((gPlayerState.flags & 0x8000) != 0)) { - gPlayerState.flags &= ~(0x1 | 0x4); + gPlayerState.flags &= ~(PL_BUSY | PL_DROWNING); this->spriteSettings.draw = 0; } else { - gPlayerState.flags &= ~(0x4 | 0x8000); + gPlayerState.flags &= ~(PL_DROWNING | 0x8000); RespawnPlayer(); gPlayerState.field_0xa = 0; this->iframes = 32; @@ -192,13 +360,18 @@ void sub_08070CB4(Entity* this) { } } -void PlayerBounce(Entity* this) { - gUnk_0811BA68[this->subAction](this); +static void PlayerBounce(Entity* this) { + static EntityAction* const sPlayerBounceStates[] = { + sub_08070D38, + sub_08070DC4, + sub_08070E7C, + }; + sPlayerBounceStates[this->subAction](this); } -void sub_08070D38(Entity* this) { +static void sub_08070D38(Entity* this) { COLLISION_OFF(this); - this->direction = ((this->animationState & 0xe) << 2) ^ 0x10; + this->direction = DirectionTurnAround(Direction8FromAnimationState(AnimationStateWalk(this->animationState))); this->speed = 0x100; this->knockbackDuration = 0; this->subAction++; @@ -207,10 +380,10 @@ void sub_08070D38(Entity* this) { if ((gPlayerState.flags & PL_MINISH) == 0) { this->zVelocity = 0x20000; - gPlayerState.field_0x8 = 0x114; + gPlayerState.animation = 0x114; sub_08080964(16, 0); } else { - gPlayerState.field_0x8 = 0xc18; + gPlayerState.animation = 0xc18; this->zVelocity = 0x18000; } @@ -221,7 +394,7 @@ void sub_08070D38(Entity* this) { } // minor regalloc -NONMATCH("asm/non_matching/player/sub_08070DC4.inc", void sub_08070DC4(Entity* this)) { +static NONMATCH("asm/non_matching/player/sub_08070DC4.inc", void sub_08070DC4(Entity* this)) { UpdateAnimationSingleFrame(this); sub_080085B0(this); sub_08079E08(); @@ -260,20 +433,23 @@ NONMATCH("asm/non_matching/player/sub_08070DC4.inc", void sub_08070DC4(Entity* t this->subAction++; if ((gPlayerState.flags & PL_MINISH) == 0) - gPlayerState.field_0x8 = 0x100; + gPlayerState.animation = 0x100; } END_NONMATCH -void sub_08070E7C(Entity* this) { - u8 timer = --this->actionDelay; - - if (timer == 0) { - gPlayerState.jumpStatus = timer; +static void sub_08070E7C(Entity* this) { + if (--this->actionDelay == 0) { + gPlayerState.jumpStatus = 0; sub_080791D0(); } } -void sub_08070E9C(Entity* this) { +static void sub_08070E9C(Entity* this) { + static EntityAction* const gUnk_0811BA74[] = { + sub_08070EDC, + sub_08070f24, + }; + if (sub_08078EFC() != 0) { MessageClose(); } else { @@ -284,8 +460,8 @@ void sub_08070E9C(Entity* this) { } } -void sub_08070EDC(Entity* this) { - this->updatePriority = 2; +static void sub_08070EDC(Entity* this) { + this->updatePriority = PRIO_MESSAGE; if ((gMessage.doTextBox & 0x7f) != 0) this->subAction = 1; @@ -293,10 +469,10 @@ void sub_08070EDC(Entity* this) { if ((gPlayerState.flags & PL_MINISH) == 0) sub_08079938(); else - gPlayerState.field_0x8 = 0xc18; + gPlayerState.animation = 0xc18; } -void sub_08070f24(Entity* this) { +static void sub_08070f24(Entity* this) { UpdateAnimationSingleFrame(this); if ((gMessage.doTextBox & 0x7f) == 0) { this->updatePriority = this->updatePriorityPrev; @@ -304,47 +480,52 @@ void sub_08070f24(Entity* this) { } } -void PlayerItemGet(Entity* this) { +static void PlayerItemGet(Entity* this) { + static EntityAction* const sPlayerItemGetStates[] = { + sub_08070FA4, + sub_08071020, + sub_08071038, + }; + Entity* child; - u8* temp; // todo: retype + u8* temp; gPlayerState.field_0xa8 = 0x15; COLLISION_OFF(this); - gUnk_0811BA7C[this->subAction](this); + sPlayerItemGetStates[this->subAction](this); child = this->child; if (child != NULL) { PositionEntityOnTop(this, child); temp = GetSpriteSubEntryOffsetDataPointer((u16)this->spriteIndex, this->frameIndex); - child->spriteOffsetX = *temp; + child->spriteOffsetX = temp[0]; child->spriteOffsetY = temp[1]; } } -void sub_08070FA4(Entity* this) { - u16 temp; - +static void sub_08070FA4(Entity* this) { this->spriteSettings.flipX = FALSE; - this->animationState = 4; + this->animationState = IdleSouth; - gPlayerState.flags |= 1; + gPlayerState.flags |= PL_BUSY; gPlayerState.jumpStatus = 0; if ((gPlayerState.flags & PL_MINISH) == 0) { - if (gPlayerState.flags & 0x8) { + u32 anim; + if (gPlayerState.flags & PL_NO_CAP) { if (sub_080542AC(gPlayerState.field_0x38)) { - temp = 0x45e; + anim = 0x45e; } else { - temp = 0x45b; + anim = 0x45b; } } else { if (sub_080542AC(gPlayerState.field_0x38)) { - temp = 0x2e0; + anim = 0x2e0; } else { - temp = 0x1b9; + anim = 0x1b9; } } - gPlayerState.field_0x8 = temp; + gPlayerState.animation = anim; } this->subAction = 1; @@ -352,21 +533,20 @@ void sub_08070FA4(Entity* this) { sub_08078F60(); } -void sub_08071020(Entity* this) { +static void sub_08071020(Entity* this) { UpdateAnimationSingleFrame(this); if (this->frame != 0) this->subAction = 2; } -void sub_08071038(Entity* this) { - +static void sub_08071038(Entity* this) { UpdateAnimationSingleFrame(this); if (sub_08078EFC() || (gMessage.doTextBox & 0x7f)) return; if (this->frame & 0x80) { - this->child = 0; + this->child = NULL; this->knockbackDuration = 0; this->iframes = 248; gPlayerState.jumpStatus = 0; @@ -374,18 +554,24 @@ void sub_08071038(Entity* this) { } } -void PlayerJump(Entity* this) { +static void PlayerJump(Entity* this) { + static EntityAction* const sPlayerJumpStates[] = { + sub_080710A8, + sub_08071130, + sub_08071208, + }; + gPlayerState.field_0xa8 = 0xb; - gUnk_0811BA88[this->subAction](this); + sPlayerJumpStates[this->subAction](this); } -void sub_080710A8(Entity* this) { +static void sub_080710A8(Entity* this) { u32 temp; this->subAction++; - gPlayerState.flags |= 1; - gPlayerState.flags &= ~(0x400 | 0x800); + gPlayerState.flags |= PL_BUSY; + gPlayerState.flags &= ~(PL_BURNING | 0x800); gPlayerState.playerAction = 0; @@ -393,16 +579,16 @@ void sub_080710A8(Entity* this) { if ((gPlayerState.flags & PL_MINISH) == 0) { ResetPlayer(); - if ((gPlayerState.flags & 0x8) != 0) { - gPlayerState.field_0x8 = 0x420; + if (gPlayerState.flags & PL_NO_CAP) { + gPlayerState.animation = 0x420; } else { - gPlayerState.field_0x8 = 0x810; + gPlayerState.animation = 0x810; } } } gPlayerState.field_0x1d[1] = 0; - this->direction = ((this->animationState & 0xe) << 2); + this->direction = Direction8FromAnimationState(AnimationStateWalk(this->animationState)); temp = sub_08079FC4(1); asm("lsl r0, r0, #0x4"); @@ -414,7 +600,7 @@ void sub_080710A8(Entity* this) { SoundReq(SFX_PLY_VO4); } -void sub_08071130(Entity* this) { +static void sub_08071130(Entity* this) { if (sub_08078EFC(this)) return; @@ -456,10 +642,10 @@ void sub_08071130(Entity* this) { this->actionDelay = 6; if (((gPlayerState.heldObject | gPlayerState.keepFacing) == 0) && ((gPlayerState.flags & PL_MINISH) == 0)) { - if (gPlayerState.flags & 0x8) { - gPlayerState.field_0x8 = 0x424; + if (gPlayerState.flags & PL_NO_CAP) { + gPlayerState.animation = 0x424; } else { - gPlayerState.field_0x8 = 0x820; + gPlayerState.animation = 0x820; } this->animIndex = 0xff; } @@ -470,7 +656,7 @@ void sub_08071130(Entity* this) { SoundReq(SFX_PLY_LAND); } -void sub_08071208(Entity* this) { +static void sub_08071208(Entity* this) { if ((gPlayerState.heldObject | gPlayerState.keepFacing) == 0) { if ((gPlayerState.flags & PL_MINISH) == 0) { UpdateAnimationSingleFrame(this); @@ -483,20 +669,25 @@ void sub_08071208(Entity* this) { } } -void PlayerDrown(Entity* this) { +static void PlayerDrown(Entity* this) { + static EntityAction* const sPlayerDrownStates[] = { + sub_0807127C, + sub_080712F0, + }; + gPlayerState.field_0xa8 = 0x16; - gPlayerState.flags |= 4; + gPlayerState.flags |= PL_DROWNING; COLLISION_OFF(this); - gUnk_0811BA94[this->subAction](this); + sPlayerDrownStates[this->subAction](this); } -void sub_0807127C(Entity* this) { +static void sub_0807127C(Entity* this) { this->subAction = 1; this->spritePriority.b1 = 0; if (gPlayerState.flags & PL_MINISH) { this->actionDelay = 0x3c; - gPlayerState.field_0x8 = 0xc19; + gPlayerState.animation = 0xc19; SoundReq(SFX_WATER_SPLASH); } else { if ((gPlayerState.flags & 0x10000) == 0) @@ -504,15 +695,15 @@ void sub_0807127C(Entity* this) { CreateFx(this, FX_WATER_SPLASH, 0); - if ((gPlayerState.flags & 8) == 0) - gPlayerState.field_0x8 = 0x72c; + if ((gPlayerState.flags & PL_NO_CAP) == 0) + gPlayerState.animation = 0x72c; else - gPlayerState.field_0x8 = 0x44c; + gPlayerState.animation = 0x44c; } ResetPlayer(); } -void sub_080712F0(Entity* this) { +static void sub_080712F0(Entity* this) { u32 temp; UpdateAnimationSingleFrame(this); @@ -524,7 +715,7 @@ void sub_080712F0(Entity* this) { temp = TRUE; } else if ((this->frame & 0x80) != 0) { if (this->animIndex != 0xce) - gPlayerState.field_0x8 = 0x2ce; + gPlayerState.animation = 0x2ce; else temp = TRUE; } @@ -541,17 +732,22 @@ void sub_080712F0(Entity* this) { } static void PlayerUsePortal(Entity* this) { + static EntityAction* const sPlayerUsePortalStates[] = { + PortalJumpOnUpdate, PortalStandUpdate, PortalActivateInit, PortalActivateUpdate, + PortalShrinkInit, PortalShrinkUpdate, PortalEnterUpdate, PortalUnknownUpdate, + }; + gPlayerState.field_0xa8 = 0xe; - gUnk_0811BA9C[this->subAction](this); + sPlayerUsePortalStates[this->subAction](this); // probably a switch if ((this->subAction == 7) || (this->subAction < 3)) return; - if ((gPlayerState.flags & 0x20) == 0) + if ((gPlayerState.flags & PL_USE_PORTAL) == 0) return; - if ((gInput.newKeys & (0x100 | 0x2)) == 0) + if ((gInput.newKeys & (B_BUTTON | R_BUTTON)) == 0) return; if (CheckIsDungeon() || gArea.curPortalType == 3) { @@ -564,7 +760,7 @@ static void PlayerUsePortal(Entity* this) { } } -void PortalJumpOnUpdate(Entity* this) { +static void PortalJumpOnUpdate(Entity* this) { u16 x; u16 y; @@ -584,12 +780,12 @@ void PortalJumpOnUpdate(Entity* this) { UpdateAnimationSingleFrame(this); if (gPlayerState.jumpStatus == 0) { - gPlayerState.flags |= 0x20; + gPlayerState.flags |= PL_USE_PORTAL; this->subAction = 1; - this->animationState = 4; + this->animationState = IdleSouth; this->spriteSettings.flipX = FALSE; if (gArea.curPortalType == 4) { - gPlayerState.field_0x8 = 0x52c; + gPlayerState.animation = 0x52c; } } @@ -600,7 +796,7 @@ void PortalJumpOnUpdate(Entity* this) { } } -void PortalStandUpdate(Entity* this) { +static void PortalStandUpdate(Entity* this) { switch (gArea.curPortalType) { case 4: case 5: @@ -614,14 +810,14 @@ void PortalStandUpdate(Entity* this) { } if (--this->actionDelay == 0xff) { this->direction = gPlayerState.field_0xd; - this->animationState = this->direction >> 2; + this->animationState = Direction8ToAnimationState(this->direction); this->zVelocity = 0x20000; this->speed = 256; this->action = 9; this->subAction = 7; this->field_0xf = 0; - gPlayerState.field_0x8 = (gPlayerState.flags & 8) ? 0x41C : 0x80C; - gPlayerState.flags &= ~0x20; + gPlayerState.animation = (gPlayerState.flags & PL_NO_CAP) ? 0x41C : 0x80C; + gPlayerState.flags &= ~PL_USE_PORTAL; return; } this->direction = gPlayerState.field_0xd; @@ -640,18 +836,18 @@ void PortalStandUpdate(Entity* this) { sub_08079938(); } -void PortalActivateInit(Entity* this) { +static void PortalActivateInit(Entity* this) { gRoomControls.cameraTarget = NULL; gUnk_02034490[0] = 1; this->subAction = 3; this->field_0xf = 0x1e; - gPlayerState.field_0x8 = 0x738; - CreateObjectWithParent(this, OBJECT_6, 1, 0); + gPlayerState.animation = 0x738; + CreateObjectWithParent(this, EZLO_CAP, 1, 0); sub_08077B20(); SetPlayerEventPriority(); } -void PortalActivateUpdate(Entity* this) { +static void PortalActivateUpdate(Entity* this) { if (this->field_0xf) return; @@ -661,7 +857,7 @@ void PortalActivateUpdate(Entity* this) { this->subAction = 4; } -void PortalShrinkInit(Entity* this) { +static void PortalShrinkInit(Entity* this) { this->subAction = 5; this->spritePriority.b1 = 0; this->field_0xf = 0; @@ -669,15 +865,19 @@ void PortalShrinkInit(Entity* this) { *(u32*)&this->field_0x80.HWORD = 0x100; *(u32*)&this->cutsceneBeh = 0x100; sub_0805EC9C(this, 0x100, 0x100, 0); - gPlayerState.field_0x8 = 0x2c3; + gPlayerState.animation = 0x2c3; gPlayerState.flags |= 0x80; SoundReq(SFX_PLY_SHRINKING); } +static const u8 gUnk_0811BABC[] = { + 1, 1, 1, 1, 2, 4, 8, 16, +}; + // horrible -ASM_FUNC("asm/non_matching/player/PortalShrinkUpdate.inc", void PortalShrinkUpdate(Entity* this)) +static ASM_FUNC("asm/non_matching/player/PortalShrinkUpdate.inc", void PortalShrinkUpdate(Entity* this)); -void PortalEnterUpdate(Entity* this) { +static void PortalEnterUpdate(Entity* this) { if (this->actionDelay == 0) { if (sub_08003FC4(this, 0x2000)) return; @@ -699,7 +899,7 @@ void PortalEnterUpdate(Entity* this) { this->actionDelay--; } -void PortalUnknownUpdate(Entity* this) { +static void PortalUnknownUpdate(Entity* this) { if (gFadeControl.active) return; @@ -712,40 +912,49 @@ void PortalUnknownUpdate(Entity* this) { sub_080500F4(0x10); } -extern s16 gUnk_0811BAC4[]; +static void sub_080717F8(Entity* this) { + static const s16 sOffsets[] = { + 0, -22, 22, 0, 0, 22, -22, 0, + }; -void sub_080717F8(Entity* this) { u32 x; u32 y; this->animationState = gArea.curPortalExitDirection << 1; - this->x.HALF.HI = gArea.curPortalX + gUnk_0811BAC4[gArea.curPortalExitDirection * 2]; - this->y.HALF.HI = gArea.curPortalY + gUnk_0811BAC4[gArea.curPortalExitDirection * 2 + 1]; + this->x.HALF.HI = gArea.curPortalX + sOffsets[gArea.curPortalExitDirection * 2]; + this->y.HALF.HI = gArea.curPortalY + sOffsets[gArea.curPortalExitDirection * 2 + 1]; gArea.unk1A = 0xb4; gUnk_02034490[0] = 0; this->action = 9; this->subAction = 0; - gPlayerState.flags = (gPlayerState.flags & ~0x20) | 0x80; + gPlayerState.flags = (gPlayerState.flags & ~PL_USE_PORTAL) | 0x80; sub_0805EC60(this); ResetPlayerEventPriority(); } -void PlayerTalkEzlo(Entity* this) { +static void PlayerTalkEzlo(Entity* this) { + static EntityAction* const sPlayerTalkEzloStates[] = { + sub_080718A0, + sub_0807193C, + sub_08071990, + sub_08071A4C, + }; + if (sub_08078EFC()) { MessageClose(); - sub_08071A6C(); + ResetPlayerPriority(); } else { gPlayerState.field_0xa8 = 0x13; COLLISION_OFF(this); - gUnk_0811BAD4[this->subAction](this); + sPlayerTalkEzloStates[this->subAction](this); } } -void sub_080718A0(Entity* this) { +static void sub_080718A0(Entity* this) { ResetPlayer(); gUnk_03000B80.filler[0x63] = 0; this->iframes = 0; - gPriorityHandler.sys_priority = 6; - this->updatePriority = 6; + gPriorityHandler.sys_priority = PRIO_PLAYER_EVENT; + this->updatePriority = PRIO_PLAYER_EVENT; if (gPlayerState.flags & PL_MINISH) { this->subAction = 2; @@ -757,10 +966,10 @@ void sub_080718A0(Entity* this) { if (gPlayerState.jumpStatus == 0) { this->subAction++; - if (this->animationState == 2) - gPlayerState.field_0x8 = 0x3ca; + if (this->animationState == IdleEast) + gPlayerState.animation = 0x3ca; else - gPlayerState.field_0x8 = 0x3c6; + gPlayerState.animation = 0x3c6; this->spriteSettings.flipX = 0; return; @@ -770,37 +979,37 @@ void sub_080718A0(Entity* this) { gPlayerState.jumpStatus = 0; } -void sub_0807193C(Entity* this) { +static void sub_0807193C(Entity* this) { Entity* child; UpdateAnimationSingleFrame(this); if (this->frame & 0x80) { this->subAction++; - child = CreateObjectWithParent(this, OBJECT_6, 0, 0); + child = CreateObjectWithParent(this, EZLO_CAP, 0, 0); this->child = child; if (child != NULL) { - if (this->animationState == 2) - gPlayerState.field_0x8 = 0x3cc; + if (this->animationState == IdleEast) + gPlayerState.animation = 0x3cc; else - gPlayerState.field_0x8 = 0x3c7; + gPlayerState.animation = 0x3c7; DisplayEzloMessage(); } } } -void sub_08071990(Entity* this) { +static void sub_08071990(Entity* this) { u32 temp; if ((gMessage.doTextBox & 0x7f) == 0) { this->subAction++; if ((gPlayerState.flags & PL_MINISH) == 0) { - if (this->animationState == 2) - gPlayerState.field_0x8 = 0x3cd; + if (this->animationState == IdleEast) + gPlayerState.animation = 0x3cd; else - gPlayerState.field_0x8 = 0x3c9; + gPlayerState.animation = 0x3c9; } else { - sub_08071A6C(); + ResetPlayerPriority(); sub_08079258(); } return; @@ -809,48 +1018,54 @@ void sub_08071990(Entity* this) { if (gPlayerState.flags & PL_MINISH) return; - if (this->animationState == 2) + if (this->animationState == IdleEast) temp = 4; else temp = 0; if (this->child->actionDelay != 0) { if ((u8)(temp + 200) != this->animIndex) { - gPlayerState.field_0x8 = temp + 0x3c8; + gPlayerState.animation = temp + 0x3c8; return; } } else { if ((u8)(temp + 199) != this->animIndex) { - gPlayerState.field_0x8 = temp + 0x3c7; + gPlayerState.animation = temp + 0x3c7; return; } } UpdateAnimationSingleFrame(this); } -void sub_08071A4C(Entity* this) { +static void sub_08071A4C(Entity* this) { UpdateAnimationSingleFrame(this); if (this->frame & 0x80) { - sub_08071A6C(); + ResetPlayerPriority(); sub_0807921C(); } } -void sub_08071A6C(void) { +static void ResetPlayerPriority(void) { gPriorityHandler.sys_priority = 0; gPlayerEntity.updatePriority = gPlayerEntity.updatePriorityPrev; } -void PlayerPush(Entity* this) { +static void PlayerPush(Entity* this) { + static EntityAction* const sPlayerPushStates[] = { + sub_08071AB0, + sub_08071AF0, + sub_08071B60, + }; + gPlayerState.field_0xa8 = 0x19; - gUnk_0811BAE4[this->subAction](this); + sPlayerPushStates[this->subAction](this); } -void sub_08071AB0(Entity* this) { +static void sub_08071AB0(Entity* this) { u32 speed; this->subAction++; - gPlayerState.flags |= 1; + gPlayerState.flags |= PL_BUSY; if (this->type == 1) { this->speed = 0; this->actionDelay = 0; @@ -861,14 +1076,23 @@ void sub_08071AB0(Entity* this) { sub_08071AF0(this); } -void sub_08071AF0(Entity* this) { +static void sub_08071AF0(Entity* this) { + typedef struct { + u8 frame; + u16 speed; + } PushFrame; + + static const PushFrame sPushFrames[] = { { 5, 0x0 }, { 1, 0x100 }, { 5, 0x0 }, { 1, 0x100 }, { 2, 0x0 }, + { 1, 0x100 }, { 2, 0x0 }, { 1, 0x100 }, { 3, 0x0 }, { 1, 0x100 }, + { 8, 0x60 }, { 8, 0x60 }, { 8, 0x60 }, { 8, 0x40 }, { 0xFF, 0x0 } }; + gPlayerState.field_0x80 = 0; UpdateAnimationSingleFrame(this); if (this->type == 1) { if (--this->field_0xf == 0) { - if (gUnk_0811BAF0[this->actionDelay].frame != 0xff) { - this->field_0xf = gUnk_0811BAF0[this->actionDelay].frame; - this->speed = gUnk_0811BAF0[this->actionDelay].speed; + if (sPushFrames[this->actionDelay].frame != 0xff) { + this->field_0xf = sPushFrames[this->actionDelay].frame; + this->speed = sPushFrames[this->actionDelay].speed; this->actionDelay++; } else { this->subAction++; @@ -884,7 +1108,7 @@ void sub_08071AF0(Entity* this) { sub_08079E08(); } -void sub_08071B60(Entity* this) { +static void sub_08071B60(Entity* this) { gPlayerState.pushedObject = 2; gPlayerState.flags &= ~0x1; this->type = 0; @@ -892,31 +1116,36 @@ void sub_08071B60(Entity* this) { sub_080728AC(this); this->field_0xf = 6; if ((gPlayerState.flags & PL_MINISH) == 0) { - gPlayerState.field_0x8 = 0x104; + gPlayerState.animation = 0x104; this->spriteIndex = 3; InitAnimationForceUpdate(this, (this->animationState >> 1) + 0x3c); } } -extern void (*const gUnk_0811BB2C[])(Entity*); +static void PlayerMinishDie(Entity* this) { + static EntityAction* const sPlayerMinishDieStates[] = { + sub_08071BDC, + sub_08071CAC, + sub_08071D04, + sub_08071D80, + }; -void PlayerMinishDie(Entity* this) { COLLISION_OFF(this); - gUnk_0811BB2C[this->subAction](this); + sPlayerMinishDieStates[this->subAction](this); gPlayerState.field_0xa8 = 0x12; } -void sub_08071BDC(Entity* this) { +static void sub_08071BDC(Entity* this) { u32 temp; if (gPlayerState.flags & (0x10 | 0x100)) return; if (sub_08003FC4(this, 0x2000)) { - if ((gPlayerState.flags & 8) != 0) - gPlayerState.field_0x8 = 0x420; + if (gPlayerState.flags & PL_NO_CAP) + gPlayerState.animation = 0x420; else - gPlayerState.field_0x8 = 0x810; + gPlayerState.animation = 0x810; return; } @@ -931,11 +1160,11 @@ void sub_08071BDC(Entity* this) { } else { temp = (gPlayerState.flags & 8) ? 0x459 : 0x1bc; } - gPlayerState.field_0x8 = temp; + gPlayerState.animation = temp; - gPlayerState.flags &= ~(0x1000000 | 0x200000 | 0x40000 | 0x800 | 0x400 | 0x100 | 0x1); + gPlayerState.flags &= ~(0x1000000 | 0x200000 | 0x40000 | 0x800 | 0x400 | 0x100 | PL_BUSY); this->subAction = 1; - this->animationState = 4; + this->animationState = IdleSouth; this->spritePriority.b1 = 1; this->spriteSettings.draw = 3; gPlayerState.jumpStatus = 0; @@ -945,7 +1174,7 @@ void sub_08071BDC(Entity* this) { SoundReq(SFX_PLY_DIE); } -void sub_08071CAC(Entity* this) { +static void sub_08071CAC(Entity* this) { UpdateAnimationSingleFrame(this); if (this->frame & 0x80) { u32 temp; @@ -953,7 +1182,7 @@ void sub_08071CAC(Entity* this) { temp = (gPlayerState.flags & 8) ? 0x45a : 0x2bd; else temp = 0xc1b; - gPlayerState.field_0x8 = temp; + gPlayerState.animation = temp; this->subAction = 2; this->actionDelay = 0xf0; @@ -961,7 +1190,7 @@ void sub_08071CAC(Entity* this) { } } -void sub_08071D04(Entity* this) { +static void sub_08071D04(Entity* this) { int idx; int deltaHealth; @@ -992,7 +1221,7 @@ void sub_08071D04(Entity* this) { gScreenTransition.field_0x4[1] = 1; } -void sub_08071D80(Entity* this) { +static void sub_08071D80(Entity* this) { UpdateAnimationSingleFrame(this); gPlayerState.field_0x14 = 1; sub_08073904(this); @@ -1004,23 +1233,29 @@ void sub_08071D80(Entity* this) { } } -void sub_08071DB8(Entity* this) { +static void sub_08071DB8(Entity* this) { + static EntityAction* const gUnk_0811BB3C[] = { + sub_08071DD0, + sub_08071E04, + sub_08071E74, + }; + gUnk_0811BB3C[this->subAction](this); } -void sub_08071DD0(Entity* this) { +static void sub_08071DD0(Entity* this) { this->actionDelay = gPlayerState.field_0x38; if (gPlayerState.field_0x39 != 0) { gPlayerState.field_0x39 = 0; this->subAction = 2; - gPlayerState.field_0x8 = 0x100; + gPlayerState.animation = 0x100; } else { this->subAction = 1; - gPlayerState.field_0x8 = 0x114; + gPlayerState.animation = 0x114; } } -void sub_08071E04(Entity* this) { +static void sub_08071E04(Entity* this) { if ((this->z.WORD != 0) && (gPlayerState.field_0x14 == '\0')) { sub_0807A1B8(); if (gPlayerState.field_0x10[2] == 1) { @@ -1047,7 +1282,7 @@ void sub_08071E04(Entity* this) { sub_080791BC(); } -void sub_08071E74(Entity* this) { +static void sub_08071E74(Entity* this) { u32 temp; sub_08003FC4(this, 0x2000); @@ -1057,13 +1292,16 @@ void sub_08071E74(Entity* this) { sub_080791BC(); } -extern void (*const gUnk_0811BB48[])(Entity*); +static void PlayerEmptyBottle(Entity* this) { + static EntityAction* const sPlayerEmptyBottleStates[] = { + sub_08071EB0, + sub_08071F14, + }; -void PlayerEmptyBottle(Entity* this) { - gUnk_0811BB48[this->subAction](this); + sPlayerEmptyBottleStates[this->subAction](this); } -void sub_08071EB0(Entity* this) { +static void sub_08071EB0(Entity* this) { Entity* ent; ResetPlayer(); @@ -1073,20 +1311,20 @@ void sub_08071EB0(Entity* this) { this->subAction++; switch (gPlayerState.field_0x38) { case 0x20: - gPlayerState.field_0x8 = 0x614; + gPlayerState.animation = 0x614; break; case 0x21 ... 0x25: - gPlayerState.field_0x8 = 0x2df; + gPlayerState.animation = 0x2df; break; default: - gPlayerState.field_0x8 = 0x610; + gPlayerState.animation = 0x610; sub_0807CAA0(gPlayerState.field_0x38, 2); break; } } } -void sub_08071F14(Entity* this) { +static void sub_08071F14(Entity* this) { UpdateAnimationSingleFrame(this); if (this->frame & 0x80) { gPlayerState.field_0x2c = NULL; @@ -1094,28 +1332,31 @@ void sub_08071F14(Entity* this) { } } -extern void (*const gUnk_0811BB50[])(Entity*); +static void PlayerFrozen(Entity* this) { + static EntityAction* const sPlayerFrozenStates[] = { + sub_08071F50, + sub_08071F80, + }; -void PlayerFrozen(Entity* this) { - gUnk_0811BB50[this->subAction](this); + sPlayerFrozenStates[this->subAction](this); } -void sub_08071F50(Entity* this) { +static void sub_08071F50(Entity* this) { COLLISION_OFF(this); - this->actionDelay = 0x78; + this->actionDelay = 120; this->subAction++; - gPlayerState.field_0x8 = 0x294; + gPlayerState.animation = 0x294; sub_08077B20(); SoundReq(SFX_195); } -void sub_08071F80(Entity* this) { +static void sub_08071F80(Entity* this) { if (sub_08003FC4(this, 0x2000) == 0) { UpdateSpriteForCollisionLayer(this); gPlayerState.jumpStatus = 0; if (gPlayerState.field_0x14 == 0) { if (sub_08079D48() == 0) { - sub_08072008(this); + BreakOut(this); return; } } @@ -1135,34 +1376,37 @@ void sub_08071F80(Entity* this) { } } } - sub_08072008(this); + BreakOut(this); } -void sub_08072008(Entity* this) { +static void BreakOut(Entity* this) { this->iframes = 160; this->knockbackDuration = 0; COLLISION_ON(this); this->spriteOffsetX = 0; - gPlayerState.flags &= ~(0x800 | 0x1); + gPlayerState.flags &= ~(0x800 | PL_BUSY); CreateFx(this, FX_ICE, 0); sub_080791BC(); } -extern void (*const gUnk_0811BB58[])(Entity*); +static void sub_0807204C(Entity* this) { + static EntityAction* const gUnk_0811BB58[] = { + sub_08072064, + sub_08072098, + }; -void sub_0807204C(Entity* this) { gUnk_0811BB58[this->subAction](this); } -void sub_08072064(Entity* this) { +static void sub_08072064(Entity* this) { this->subAction = 1; COLLISION_OFF(this); this->actionDelay = gPlayerState.field_0x3a; - gPlayerState.field_0x8 = gPlayerState.field_0x38 | (gPlayerState.field_0x39 << 8); + gPlayerState.animation = gPlayerState.field_0x38 | (gPlayerState.field_0x39 << 8); ResetPlayer(); } -void sub_08072098(Entity* this) { +static void sub_08072098(Entity* this) { UpdateAnimationSingleFrame(this); if (this->actionDelay != 0) if (--this->actionDelay != 0xFF) @@ -1177,33 +1421,36 @@ void sub_08072098(Entity* this) { sub_080791BC(); } -extern void (*const gUnk_0811BB60[])(Entity*); +static void sub_080720DC(Entity* this) { + static EntityAction* const gUnk_0811BB60[] = { + sub_08072100, + sub_08072168, + }; -void sub_080720DC(Entity* this) { if (sub_08078EFC() == 0) gUnk_0811BB60[this->subAction](this); } -void sub_08072100(Entity* this) { +static void sub_08072100(Entity* this) { this->spriteSettings.draw = 3; this->speed = 0x140; - this->hitbox = &gUnk_08114F88; + this->hitbox = (Hitbox*)&gPlayerHitbox; this->actionDelay = gPlayerState.field_0x38; this->subAction = 1; COLLISION_OFF(this); if (gPlayerState.field_0x39) this->direction = 0xff; - if ((gPlayerState.flags & 8)) { - gPlayerState.field_0x8 = 0x404; + if (gPlayerState.flags & PL_NO_CAP) { + gPlayerState.animation = 0x404; } else { - gPlayerState.field_0x8 = 0x104; + gPlayerState.animation = 0x104; } ResetPlayer(); sub_08072168(this); } -void sub_08072168(Entity* this) { +static void sub_08072168(Entity* this) { u32 i; UpdateAnimationSingleFrame(this); @@ -1224,75 +1471,83 @@ void sub_08072168(Entity* this) { } } -extern void (*const gUnk_0811BB68[])(Entity*); +static void PlayerPull(Entity* this) { + static EntityAction* const sPlayerPullStates[] = { + sub_08072214, + sub_08072260, + }; -void PlayerPull(Entity* this) { gPlayerState.field_0xa8 = 0x1a; - gUnk_0811BB68[this->subAction](this); + sPlayerPullStates[this->subAction](this); gUnk_0200AF00.filler25[9] = 8; } -void sub_08072214(Entity* this) { +static void sub_08072214(Entity* this) { this->subAction = 1; this->speed = 128; this->actionDelay = gPlayerState.field_0x38; - this->direction = (this->animationState ^ 4) << 2; - if (!(gPlayerState.flags & 8)) { - gPlayerState.field_0x8 = 0x34c; + this->direction = Direction8FromAnimationState(AnimationStateTurnAround(this->animationState)); + if ((gPlayerState.flags & PL_NO_CAP) == 0) { + gPlayerState.animation = 0x34c; } else { - gPlayerState.field_0x8 = 0x944; + gPlayerState.animation = 0x944; } - gPlayerState.flags |= 1; + gPlayerState.flags |= PL_BUSY; sub_08072260(this); } -void sub_08072260(Entity* this) { +static void sub_08072260(Entity* this) { gPlayerState.field_0x80 = 0; sub_08079E08(); UpdateAnimationSingleFrame(this); if (--this->actionDelay == 0) { - gPlayerState.flags &= ~0x1; - if (!(gPlayerState.flags & 8)) { - gPlayerState.field_0x8 = 0x34c; + gPlayerState.flags &= ~PL_BUSY; + if ((gPlayerState.flags & PL_NO_CAP) == 0) { + gPlayerState.animation = 0x34c; } else { - gPlayerState.field_0x8 = 0x944; + gPlayerState.animation = 0x944; } this->knockbackDuration = 0; sub_080791BC(); } } -extern void (*const gUnk_0811BB70[])(Entity*); +static void PlayerLava(Entity* this) { + static EntityAction* const sPlayerLavaStates[] = { + sub_080722DC, + sub_08072354, + sub_080723D0, + sub_0807240C, + }; -void PlayerLava(Entity* this) { gPlayerState.field_0xa8 = 10; - gUnk_0811BB70[this->subAction](this); + sPlayerLavaStates[this->subAction](this); } -void sub_080722DC(Entity* this) { +static void sub_080722DC(Entity* this) { Entity* ent; COLLISION_OFF(this); - if (!(gPlayerState.flags & PL_MINISH)) { + if ((gPlayerState.flags & PL_MINISH) == 0) { this->subAction = 1; this->zVelocity = 0x28000; ent = CreateObject(OBJECT_42, 0x80, 0); if (ent != NULL) { ent->child = this; } - gPlayerState.field_0x8 = 0x114; + gPlayerState.animation = 0x114; } else { this->spriteSettings.draw = 0; this->subAction = 3; this->knockbackDuration = 10; } - gPlayerState.flags |= (0x400 | 0x1); + gPlayerState.flags |= (PL_BURNING | PL_BUSY); ResetPlayer(); SoundReq(SFX_124); SoundReq(SFX_PLY_VO6); } -void sub_08072354(Entity* this) { +static void sub_08072354(Entity* this) { sub_0806F854(this, 0, -12); UpdateAnimationSingleFrame(this); sub_08079744(this); @@ -1303,47 +1558,50 @@ void sub_08072354(Entity* this) { this->knockbackDuration = 0; this->subAction = 2; this->actionDelay = 0x3c; - gPlayerState.field_0x8 = 0x2c1; - gPlayerState.flags &= ~0x400; + gPlayerState.animation = 0x2c1; + gPlayerState.flags &= ~PL_BURNING; UpdateSpriteForCollisionLayer(this); CreateFx(this, FX_LAVA_SPLASH, 0); SoundReq(SFX_1A6); } -void sub_080723D0(Entity* this) { +static void sub_080723D0(Entity* this) { UpdateAnimationSingleFrame(this); if (--this->actionDelay == 0xff) { this->spritePriority.b1 = 1; - this->iframes = 0x14; + this->iframes = 20; ModHealth(-2); RespawnPlayer(); } } -void sub_0807240C(Entity* this) { +static void sub_0807240C(Entity* this) { if (--this->knockbackDuration == 0xff) { this->spriteSettings.draw = 3; - this->iframes = 0x14; - gPlayerState.flags &= ~0x400; + this->iframes = 20; + gPlayerState.flags &= ~PL_BURNING; ModHealth(-2); RespawnPlayer(); } } -extern void (*const gUnk_0811BB80[])(Entity*); +static void sub_08072454(Entity* this) { + static EntityAction* const gUnk_0811BB80[] = { + sub_0807246C, + sub_08072490, + }; -void sub_08072454(Entity* this) { gUnk_0811BB80[this->subAction](this); } -void sub_0807246C(Entity* this) { +static void sub_0807246C(Entity* this) { this->subAction = 1; this->actionDelay = gPlayerState.field_0x38; - gPlayerState.field_0x8 = 0x3c0; + gPlayerState.animation = 0x3c0; SoundReq(0x7b); } -void sub_08072490(Entity* this) { +static void sub_08072490(Entity* this) { if (--this->actionDelay != 0xff) { UpdateAnimationSingleFrame(this); sub_08079E08(); @@ -1354,13 +1612,15 @@ void sub_08072490(Entity* this) { } } -extern void (*const gUnk_0811BB88[])(Entity*); - -void PlayerRoomTransition(Entity* this) { - gUnk_0811BB88[this->subAction](this); +static void PlayerRoomTransition(Entity* this) { + static EntityAction* const sPlayerRoomTransitionStates[] = { + sub_080724DC, + sub_0807258C, + }; + sPlayerRoomTransitionStates[this->subAction](this); } -void sub_080724DC(Entity* this) { +static void sub_080724DC(Entity* this) { this->knockbackDuration = 0; sub_0807A108(); if (sub_080002B8(this) != 0x29) { @@ -1378,16 +1638,16 @@ void sub_080724DC(Entity* this) { this->subAction = 1; if (gRoomVars.field_0x0 == 0) { if (gPlayerState.flags & PL_MINISH) { - gPlayerState.field_0x8 = 0xc18; + gPlayerState.animation = 0xc18; } else { - gPlayerState.field_0x8 = 0x104; + gPlayerState.animation = 0x104; } - this->direction = this->animationState << 2; + this->direction = Direction8FromAnimationState(this->animationState); } } } -void sub_0807258C(Entity* this) { +static void sub_0807258C(Entity* this) { if (gRoomControls.unk2 == 0) { if (sub_0807A894(this) == 0x29) { sub_08079E08(); @@ -1411,14 +1671,17 @@ void sub_0807258C(Entity* this) { } } -extern void (*const gUnk_0811BB90[])(Entity*); +static void PlayerRoll(Entity* this) { + static EntityAction* const sPlayerRollStates[] = { + sub_08072650, + sub_080726F4, + }; -void PlayerRoll(Entity* this) { gPlayerState.field_0xa8 = 9; - gUnk_0811BB90[this->subAction](this); + sPlayerRollStates[this->subAction](this); } -void sub_08072650(Entity* this) { +static void sub_08072650(Entity* this) { u32 temp; if ((gPlayerState.flags & 0x200000) == 0) { @@ -1431,16 +1694,16 @@ void sub_08072650(Entity* this) { temp = gPlayerState.flags; if (gPlayerState.flags & PL_MINISH) { this->spritePriority.b1 = 0; - gPlayerState.field_0x8 = 0xc08; + gPlayerState.animation = 0xc08; } else { this->hurtType = 0x1e; if (temp & 8) { - gPlayerState.field_0x8 = 0x438; + gPlayerState.animation = 0x438; } else { - gPlayerState.field_0x8 = 0x2ac; + gPlayerState.animation = 0x2ac; } } - gPlayerState.flags |= 0x40000; + gPlayerState.flags |= PL_ROLLING; if (Random() & 1) { SoundReq(SFX_PLY_VO5); } else { @@ -1449,16 +1712,16 @@ void sub_08072650(Entity* this) { SoundReq(SFX_7E); } -void sub_080726F4(Entity* this) { - if (((gPlayerState.flags & (0x40000 | 0x80000)) != 0x40000) || +static void sub_080726F4(Entity* this) { + if (((gPlayerState.flags & (PL_ROLLING | 0x80000)) != PL_ROLLING) || (!(gPlayerState.flags & 0x200000) && (this->iframes != 0) && (this->bitfield & 0x80))) { - gPlayerState.flags &= ~0x40000; + gPlayerState.flags &= ~PL_ROLLING; if (!sub_08078EFC()) sub_080728AC(this); return; } - this->direction = (this->animationState & 6) << 2; + this->direction = Direction8FromAnimationState(AnimationStateIdle(this->animationState)); if (((gPlayerState.flags & PL_MINISH) == 0) && (--this->actionDelay == 0xff)) { CreateFx(&gPlayerEntity, FX_DASH, 0x40); this->actionDelay = 4; @@ -1467,12 +1730,12 @@ void sub_080726F4(Entity* this) { sub_0807A1B8(); } if (sub_08078EFC()) { - gPlayerState.flags &= ~0x40000; + gPlayerState.flags &= ~PL_ROLLING; return; } if ((gPlayerState.flags & 0x80000) != 0) { - gPlayerState.flags &= ~0x40000; + gPlayerState.flags &= ~PL_ROLLING; return; } @@ -1480,8 +1743,8 @@ void sub_080726F4(Entity* this) { return; } - if (gPlayerState.flags & 0x250) { - gPlayerState.flags &= ~0x40000; + if (gPlayerState.flags & (0x200 | 0x40 | 0x10)) { + gPlayerState.flags &= ~PL_ROLLING; sub_080728AC(this); return; } @@ -1518,12 +1781,12 @@ void sub_080726F4(Entity* this) { sub_080791D0(); } if ((this->frame & 0x80) != 0) { - gPlayerState.flags &= ~(0x200000 | 0x40000); + gPlayerState.flags &= ~(0x200000 | PL_ROLLING); } UpdateAnimationSingleFrame(this); } -void sub_080728AC(Entity* this) { +static void sub_080728AC(Entity* this) { sub_08079938(); if (gPlayerState.flags & PL_MINISH) sub_0807B068(this); @@ -1547,14 +1810,16 @@ void sub_080728AC(Entity* this) { } } -extern void (*const gUnk_0811BB98[])(Entity*); +static void PlayerInHole(Entity* this) { + static EntityAction* const sPlayerInHoleStates[] = { + sub_08072970, sub_08072A60, sub_08072ACC, sub_08072B5C, sub_08072C48, + }; -void PlayerInHole(Entity* this) { gPlayerState.field_0xa8 = 0x17; - gUnk_0811BB98[this->subAction](this); + sPlayerInHoleStates[this->subAction](this); } -void sub_08072970(Entity* this) { +static void sub_08072970(Entity* this) { if (this->health != 0) { this->subAction = 1; this->x.HALF.HI = (this->x.HALF.HI & ~0xF) | 8; @@ -1563,11 +1828,11 @@ void sub_08072970(Entity* this) { this->spritePriority.b0 = 7; this->spritePriority.b1 = 0; this->actionDelay = 0; - gPlayerState.flags |= 0x100000; - if (gPlayerState.flags & 8) { - gPlayerState.field_0x8 = 0x950; + gPlayerState.flags |= PL_IN_HOLE; + if (gPlayerState.flags & PL_NO_CAP) { + gPlayerState.animation = 0x950; } else { - gPlayerState.field_0x8 = 0x61c; + gPlayerState.animation = 0x61c; if (sub_080001DA(COORD_TO_TILE(this), this->collisionLayer) == 0x4020) { this->actionDelay = 1; } @@ -1579,47 +1844,47 @@ void sub_08072970(Entity* this) { } } -void sub_08072A60(Entity* this) { +static void sub_08072A60(Entity* this) { if (this->frame & 0x80) { if (this->actionDelay == 1) { this->subAction = 3; this->actionDelay = 0x28; this->spritePriority.b1 = 1; - gPlayerState.field_0x8 = 0x624; + gPlayerState.animation = 0x624; return; } this->subAction = 2; - if (gPlayerState.flags & 8) { - gPlayerState.field_0x8 = 0x954; + if (gPlayerState.flags & PL_NO_CAP) { + gPlayerState.animation = 0x954; } else { - gPlayerState.field_0x8 = 0x620; + gPlayerState.animation = 0x620; } } else { UpdateAnimationSingleFrame(this); } } -void sub_08072ACC(Entity* this) { +static void sub_08072ACC(Entity* this) { if (gPlayerState.field_0xd == 0xff) { this->field_0xf = 0; } else if (this->field_0xf > 7) { COLLISION_ON(this); this->direction = gPlayerState.field_0xd; this->zVelocity = 0x1a000; - this->speed = 0x78; + this->speed = 120; this->spritePriority.b0 = 4; this->spritePriority.b1 = 1; gPlayerState.jumpStatus = 0x41; sub_0807921C(); sub_0807BA8C(COORD_TO_TILE(this), this->collisionLayer); } else { - this->animationState = gPlayerState.field_0xd >> 2; + this->animationState = Direction8ToAnimationState(gPlayerState.field_0xd); this->field_0xf++; } } -void sub_08072B5C(Entity* this) { +static void sub_08072B5C(Entity* this) { u32 temp; sub_080042BA(this, ((0x28 - this->actionDelay) >> 4) + 1); @@ -1630,7 +1895,7 @@ void sub_08072B5C(Entity* this) { } SetTile(0x4021, COORD_TO_TILE(this), this->collisionLayer); - this->direction = this->animationState << 2; + this->direction = Direction8FromAnimationState(this->animationState); temp = sub_0807A2F8(1); if (!temp) { COLLISION_ON(this); @@ -1653,11 +1918,11 @@ void sub_08072B5C(Entity* this) { temp <<= 12; this->zVelocity = temp; this->speed = 0x100; - gPlayerState.field_0x8 = 0x810; + gPlayerState.animation = 0x810; SoundReq(0x7c); } -void sub_08072C48(Entity* this) { +static void sub_08072C48(Entity* this) { UpdateAnimationSingleFrame(this); sub_0806F69C(this); if (sub_08003FC4(this, 0x2000)) @@ -1676,24 +1941,28 @@ void sub_08072C48(Entity* this) { } } -extern void (*const gUnk_0811BBAC[])(Entity*); - -void sub_08072C9C(Entity* this) { +static void sub_08072C9C(Entity* this) { + static EntityAction* const gUnk_0811BBAC[] = { + sub_08072CC0, + sub_08072CFC, + sub_08072D54, + sub_08072F14, + }; gPlayerState.field_0xa8 = 0x11; gUnk_0811BBAC[this->subAction](this); } -void sub_08072CC0(Entity* this) { +static void sub_08072CC0(Entity* this) { this->subAction = 1; COLLISION_OFF(this); this->field_0xf = (gPlayerState.field_0x3a >> 2) + 1; this->direction = gPlayerState.field_0x39; this->speed = 0x400; - gPlayerState.field_0x8 = 0x524; + gPlayerState.animation = 0x524; gPlayerState.heldObject = 0; } -void sub_08072CFC(Entity* this) { +static void sub_08072CFC(Entity* this) { sub_080042BA(this, 2); if (--this->field_0xf != 0xff) { sub_0806F69C(this); @@ -1706,15 +1975,24 @@ void sub_08072CFC(Entity* this) { } this->zVelocity = gPlayerState.field_0x38 << 0xc; this->speed = 0x200; - gPlayerState.field_0x8 = 0x810; + gPlayerState.animation = 0x810; this->actionDelay = 5; this->field_0xf = 0; ResetPlayer(); } -extern const u16* gUnk_0811BBD4[]; +static const u16 sTiles[] = { + 0x1AD, 1, 0, 0x1AE, 1, 0, 0x1AC, 1, 0, 0x1AF, 1, 0, +}; -NONMATCH("asm/non_matching/player/sub_08072D54.inc", void sub_08072D54(Entity* this)) { +static const u16* const sTileTable[] = { + sTiles, + sTiles + 3, + sTiles + 6, + sTiles + 9, +}; + +static NONMATCH("asm/non_matching/player/sub_08072D54.inc", void sub_08072D54(Entity* this)) { u32 bVar1; u32 uVar2; u32 iVar3; @@ -1728,13 +2006,13 @@ NONMATCH("asm/non_matching/player/sub_08072D54.inc", void sub_08072D54(Entity* t uVar2 = GetTileType(uVar2, this->collisionLayer); switch (this->field_0xf) { case 0: - if (sub_08007DD6(uVar2, gUnk_0811BBD4[gPlayerEntity.animationState >> 1])) { + if (sub_08007DD6(uVar2, sTileTable[gPlayerEntity.animationState >> 1])) { this->actionDelay = 1; this->field_0xf = 1; } break; case 1: - if (sub_08007DD6(uVar2, gUnk_0811BBD4[gPlayerEntity.animationState >> 1])) { + if (sub_08007DD6(uVar2, sTileTable[gPlayerEntity.animationState >> 1])) { this->actionDelay = 1; this->field_0xf = 1; } @@ -1748,14 +2026,14 @@ NONMATCH("asm/non_matching/player/sub_08072D54.inc", void sub_08072D54(Entity* t break; case 2: this->animationState ^= 4; - if (sub_08007DD6(uVar2, gUnk_0811BBD4[gPlayerEntity.animationState >> 1]) != 0) { + if (sub_08007DD6(uVar2, sTileTable[gPlayerEntity.animationState >> 1]) != 0) { this->actionDelay = 1; this->field_0xf = 3; } break; default: this->animationState ^= 4; - if (sub_08007DD6(uVar2, gUnk_0811BBD4[gPlayerEntity.animationState >> 1])) { + if (sub_08007DD6(uVar2, sTileTable[gPlayerEntity.animationState >> 1])) { this->field_0xf = 4; } else { this->actionDelay = 1; @@ -1789,9 +2067,9 @@ NONMATCH("asm/non_matching/player/sub_08072D54.inc", void sub_08072D54(Entity* t } } else { if ((gPlayerState.flags & 8)) { - gPlayerState.field_0x8 = 0x424; + gPlayerState.animation = 0x424; } else { - gPlayerState.field_0x8 = 0x820; + gPlayerState.animation = 0x820; } this->actionDelay = 6; this->subAction = 3; @@ -1802,7 +2080,7 @@ NONMATCH("asm/non_matching/player/sub_08072D54.inc", void sub_08072D54(Entity* t } END_NONMATCH -void sub_08072F14(Entity* this) { +static void sub_08072F14(Entity* this) { if (--this->actionDelay != 0xff) { sub_0807921C(); } else { @@ -1810,9 +2088,12 @@ void sub_08072F14(Entity* this) { } } -extern void (*const gUnk_0811BBE4[])(Entity*); +static void sub_08072F34(Entity* this) { + static EntityAction* const gUnk_0811BBE4[] = { + sub_08072F94, + sub_08073094, + }; -void sub_08072F34(Entity* this) { if (!sub_08078EFC()) { gPlayerState.field_0xa8 = 0x18; gPlayerState.field_0x10[2] = GetSurfaceCalcType(this, 0, 0); @@ -1823,13 +2104,13 @@ void sub_08072F34(Entity* this) { this->action = 0x1d; this->subAction = 0; this->y.HALF.LO = 0; - gPlayerState.field_0x8 = 0x2cf; + gPlayerState.animation = 0x2cf; } } } } -void sub_08072F94(Entity* this) { +static void sub_08072F94(Entity* this) { u32 bVar1; switch (gPlayerState.field_0x10[2]) { @@ -1847,9 +2128,9 @@ void sub_08072F94(Entity* this) { return; } if ((this->frame & 0x10)) { - gPlayerState.field_0x8 = 0x2d4; + gPlayerState.animation = 0x2d4; } else { - gPlayerState.field_0x8 = 0x2d5; + gPlayerState.animation = 0x2d5; } sub_08073094(this); } else { @@ -1858,38 +2139,40 @@ void sub_08072F94(Entity* this) { } if (this->direction & 0x10) { if (this->frame & 0x10) { - gPlayerState.field_0x8 = 0x2d1; + gPlayerState.animation = 0x2d1; } else { - gPlayerState.field_0x8 = 0x2d2; + gPlayerState.animation = 0x2d2; } } else { if (this->frame & 0x10) { - gPlayerState.field_0x8 = 0x2cf; + gPlayerState.animation = 0x2cf; } else { - gPlayerState.field_0x8 = 0x2d0; + gPlayerState.animation = 0x2d0; } } } this->subAction++; } else { if (this->frame & 0x10) { - gPlayerState.field_0x8 = 0x2d4; + gPlayerState.animation = 0x2d4; } else { - gPlayerState.field_0x8 = 0x2d5; + gPlayerState.animation = 0x2d5; } } break; } } -extern const u16 gUnk_0811BBEC[]; +static void sub_08073094(Entity* this) { + static const u16 sSpeeds[] = { + 0x0, 0x40, 0x60, 0x80, 0x100, 0xC0, + }; -void sub_08073094(Entity* this) { this->spritePriority.b1 = 0; - this->speed = gUnk_0811BBEC[this->frame & 0xf]; + this->speed = sSpeeds[this->frame & 0xf]; sub_08079E08(); if (!sub_08019840()) { - gPlayerState.pushedObject = gPlayerState.pushedObject ^ 0x80; + gPlayerState.pushedObject ^= 0x80; if ((gPlayerState.field_0x10[2] != 0x2a) && (gPlayerState.field_0x10[2] != 0x2c)) { sub_0807A1B8(); } @@ -1930,78 +2213,15 @@ void sub_08073094(Entity* this) { } } -extern void (*const gUnk_0811BBF8[])(Entity*); +static void PlayerUseEntrance(Entity* this) { + static EntityAction* const sPlayerUseEntranceStates[] = { + sub_080731D8, + sub_080732D0, + sub_0807332C, + sub_080733BC, + }; -void PlayerUseEntrance(Entity* this) { gPlayerState.field_0xa8 = 0x1c; RequestPriorityDuration(NULL, 8); - gUnk_0811BBF8[this->subAction](this); -} - -void PlayerInit(Entity*); -void PlayerNormal(Entity*); -void PlayerInit(Entity*); -void PlayerFall(Entity*); -void PlayerJump(Entity*); -void PlayerPush(Entity*); -void PlayerBounce(Entity*); -void sub_08070E9C(Entity*); -void PlayerItemGet(Entity*); -void PlayerMinish(Entity*); -void PlayerMinishDie(Entity*); -void sub_08071DB8(Entity*); -void PlayerEmptyBottle(Entity*); -void PlayerFrozen(Entity*); -void sub_0807204C(Entity*); -void sub_080720DC(Entity*); -void PlayerPull(Entity*); -void PlayerLava(Entity*); -void PlayerWarp(Entity*); -void sub_08072454(Entity*); -void PlayerDrown(Entity*); -void PlayerUsePortal(Entity*); -void PlayerTalkEzlo(Entity*); -void PlayerRoomTransition(Entity*); -void PlayerRoll(Entity*); -void sub_080728AC(Entity*); -void PlayerInHole(Entity*); -void sub_08072C9C(Entity*); -void sub_08074C44(Entity*); -void sub_08072F34(Entity*); -void PlayerUseEntrance(Entity*); -void PlayerParachute(Entity*); - -static void (*const sPlayerActions[])(Entity*) = { - [PLAYER_INIT] = PlayerInit, - [PLAYER_NORMAL] = PlayerNormal, - [PLAYER_DUMMY] = PlayerInit, - [PLAYER_FALL] = PlayerFall, - [PLAYER_JUMP] = PlayerJump, - [PLAYER_PUSH] = PlayerPush, - [PLAYER_BOUNCE] = PlayerBounce, - [PLAYER_08070E9C] = sub_08070E9C, - [PLAYER_ITEMGET] = PlayerItemGet, - [PLAYER_MINISH] = PlayerMinish, - [PLAYER_MINISHDIE] = PlayerMinishDie, - [PLAYER_08071DB8] = sub_08071DB8, - [PLAYER_EMPTYBOTTLE] = PlayerEmptyBottle, - [PLAYER_FROZEN] = PlayerFrozen, - [PLAYER_0807204C] = sub_0807204C, - [PLAYER_080720DC] = sub_080720DC, - [PLAYER_PULL] = PlayerPull, - [PLAYER_LAVA] = PlayerLava, - [PLAYER_WARP] = PlayerWarp, - [PLAYER_08072454] = sub_08072454, - [PLAYER_DROWN] = PlayerDrown, - [PLAYER_USEPORTAL] = PlayerUsePortal, - [PLAYER_TALKEZLO] = PlayerTalkEzlo, - [PLAYER_ROOMTRANSITION] = PlayerRoomTransition, - [PLAYER_ROLL] = PlayerRoll, - [PLAYER_080728AC] = sub_080728AC, - [PLAYER_INHOLE] = PlayerInHole, - [PLAYER_08072C9C] = sub_08072C9C, - [PLAYER_08074C44] = sub_08074C44, - [PLAYER_08072F34] = sub_08072F34, - [PLAYER_USEENTRANCE] = PlayerUseEntrance, - [PLAYER_PARACHUTE] = PlayerParachute, -}; + sPlayerUseEntranceStates[this->subAction](this); +} diff --git a/src/projectile/dirtBallProjectile.c b/src/projectile/dirtBallProjectile.c index 9d4d7187..4a805082 100644 --- a/src/projectile/dirtBallProjectile.c +++ b/src/projectile/dirtBallProjectile.c @@ -97,7 +97,7 @@ void DirtBallProjectile_Action1(Entity* this) { break; case 2: this->z.HALF.HI += 0xe; - if (sub_080041A0(this, &gPlayerEntity, 0xe, 0xe) != 0) { + if (EntityInRectRadius(this, &gPlayerEntity, 0xe, 0xe) != 0) { this->action = 2; parent->field_0x82.HALF.HI = 0xc0; } @@ -96,12 +96,9 @@ u32 sub_unk3_ArmosInteriors_FortressOfWindsLeft() { } void sub_StateChange_ArmosInteriors_FortressOfWindsLeft() { - Area* a; - sub_08030118(9); - a = &gArea; - *((u8*)&a->localFlagOffset - 1) = 3; - a->areaMetadata = 0x4e; + gArea.dungeon_idx = 3; + gArea.areaMetadata = 0x4e; } u32 sub_unk3_ArmosInteriors_FortressOfWindsRight() { @@ -109,12 +106,9 @@ u32 sub_unk3_ArmosInteriors_FortressOfWindsRight() { } void sub_StateChange_ArmosInteriors_FortressOfWindsRight() { - Area* a; - sub_08030118(10); - a = &gArea; - *((u8*)&a->localFlagOffset - 1) = 3; - a->areaMetadata = 0x4e; + gArea.dungeon_idx = 3; + gArea.areaMetadata = 0x4e; } u32 sub_unk3_CrenelMinishPaths_CrenelBean() { @@ -279,14 +273,14 @@ void sub_StateChange_HouseInteriors1_PostOffice(void) { j++; } } - if (CheckLocalFlag(0x8b)) { + if (CheckLocalFlag(BILL01_TESSIN_RESERVED)) { flagArr = &gUnk_080D6508; i = 0; while (i < j) { if (CheckLocalFlag(*flagArr) == 0) { SetLocalFlag(*flagArr); - ClearLocalFlag(0x8b); - SetLocalFlag(0x8c); + ClearLocalFlag(BILL01_TESSIN_RESERVED); + SetLocalFlag(BILL01_TESSIN_BRANDNEW); break; } i++; @@ -294,28 +288,28 @@ void sub_StateChange_HouseInteriors1_PostOffice(void) { } } - if (CheckLocalFlag(0x1f)) + if (CheckLocalFlag(BILL01_TESSIN_1)) LoadRoomEntityList(&gUnk_080D6360); - if (CheckLocalFlag(0x20)) + if (CheckLocalFlag(BILL01_TESSIN_2)) LoadRoomEntityList(&gUnk_080D6380); - if (CheckLocalFlag(0x21)) + if (CheckLocalFlag(BILL01_TESSIN_3)) LoadRoomEntityList(&gUnk_080D63A0); - if (CheckLocalFlag(0x22)) + if (CheckLocalFlag(BILL01_TESSIN_4)) LoadRoomEntityList(&gUnk_080D63C0); - if (CheckLocalFlag(0x23)) + if (CheckLocalFlag(BILL01_TESSIN_5)) LoadRoomEntityList(&gUnk_080D63E0); - if (CheckLocalFlag(0x24)) + if (CheckLocalFlag(BILL01_TESSIN_6)) LoadRoomEntityList(&gUnk_080D6400); - if (CheckLocalFlag(0x25)) + if (CheckLocalFlag(BILL01_TESSIN_7)) LoadRoomEntityList(&gUnk_080D6420); - if (CheckLocalFlag(0x26)) + if (CheckLocalFlag(BILL01_TESSIN_8)) LoadRoomEntityList(&gUnk_080D6440); } @@ -332,7 +326,7 @@ void sub_StateChange_HouseInteriors1_Library2F(void) { // flippers if (GetInventoryValue(0x46) == 0) { LoadRoomEntityList(&gUnk_080D6578); - if (CheckLocalFlag(0x73) == 0) { + if (CheckLocalFlag(MIZUKAKI_BOOK_ALLBACK) == 0) { LoadRoomEntityList(&gUnk_080D6638); return; } @@ -355,7 +349,7 @@ void sub_StateChange_HouseInteriors1_Library1F(void) { LoadRoomEntityList(&gUnk_080D6714); } // flippers - if (!GetInventoryValue(0x46) && CheckGlobalFlag(MIZUKAKI_START) && CheckLocalFlag(0x6a)) { + if (!GetInventoryValue(0x46) && CheckGlobalFlag(MIZUKAKI_START) && CheckLocalFlag(MIZUKAKI_KOBITO)) { LoadRoomEntityList(&gUnk_additional_9_HouseInteriors1_Library1F); } else { LoadRoomEntityList(&gUnk_additional_8_HouseInteriors1_Library1F); @@ -379,12 +373,12 @@ extern u32* gUnk_080D6A74[]; u32 sub_unk3_HouseInteriors1_InnWestRoom(void) { u32 index; - if (CheckLocalFlag(0x91) != 0) { + if (CheckLocalFlag(YADO_CHECKIN) != 0) { index = (s32)Random() % 3; - ClearLocalFlag(1); + ClearLocalFlag(BILL05_YADO1F_MATSU_T0); } else { index = 0; - SetLocalFlag(1); + SetLocalFlag(BILL05_YADO1F_MATSU_T0); } gRoomVars.field_0x6c[3] = gUnk_080D6A74[index]; return 1; @@ -393,8 +387,8 @@ u32 sub_unk3_HouseInteriors1_InnWestRoom(void) { extern void* script_08010A5C[]; void sub_StateChange_HouseInteriors1_InnWestRoom(void) { - if (CheckLocalFlag(0x91)) { - ClearLocalFlag(0x91); + if (CheckLocalFlag(YADO_CHECKIN)) { + ClearLocalFlag(YADO_CHECKIN); DoFade(5, 0x100); gPlayerEntity.x.HALF.HI = gRoomControls.roomOriginX + 0x50; gPlayerEntity.y.HALF.HI = gRoomControls.roomOriginY + 0x38; @@ -407,20 +401,20 @@ extern u32* gUnk_080D6B18[]; u32 sub_unk3_HouseInteriors1_InnMiddleRoom(void) { u32 index; - if (CheckLocalFlag(0x91) != 0) { + if (CheckLocalFlag(YADO_CHECKIN) != 0) { index = Random() & 1; - ClearLocalFlag(2); + ClearLocalFlag(BILL06_YADO1F_TAKE_T0); } else { index = 0; - SetLocalFlag(2); + SetLocalFlag(BILL06_YADO1F_TAKE_T0); } gRoomVars.field_0x6c[3] = gUnk_080D6B18[index]; return 1; } void sub_StateChange_HouseInteriors1_InnMiddleRoom(void) { - if (CheckLocalFlag(0x91) != 0) { - ClearLocalFlag(0x91); + if (CheckLocalFlag(YADO_CHECKIN) != 0) { + ClearLocalFlag(YADO_CHECKIN); DoFade(5, 0x100); gPlayerEntity.x.HALF.HI = gRoomControls.roomOriginX + 0x50; gPlayerEntity.y.HALF.HI = gRoomControls.roomOriginY + 0x38; @@ -433,20 +427,20 @@ extern u32* gUnk_080D6BB8[]; u32 sub_unk3_HouseInteriors1_InnEastRoom(void) { s32 index; - if (CheckLocalFlag(0x91) != 0) { + if (CheckLocalFlag(YADO_CHECKIN) != 0) { index = (s32)Random() % 3; - ClearLocalFlag(3); + ClearLocalFlag(BILL07_YADO1F_UME_T0); } else { index = 0; - SetLocalFlag(3); + SetLocalFlag(BILL07_YADO1F_UME_T0); } gRoomVars.field_0x6c[3] = gUnk_080D6BB8[index]; return 1; } void sub_StateChange_HouseInteriors1_InnEastRoom(void) { - if (CheckLocalFlag(0x91)) { - ClearLocalFlag(0x91); + if (CheckLocalFlag(YADO_CHECKIN)) { + ClearLocalFlag(YADO_CHECKIN); DoFade(5, 0x100); gPlayerEntity.x.HALF.HI = gRoomControls.roomOriginX + 0x60; gPlayerEntity.y.HALF.HI = gRoomControls.roomOriginY + 0x38; @@ -567,20 +561,22 @@ void sub_StateChange_HyruleCastle_0(void) { if (!CheckGlobalFlag(LV2_CLEAR)) { LoadRoomEntityList(&gUnk_080D7328); } + #if defined(JP) || defined(DEMO_JP) if (CheckGlobalFlag(CASTLE_BGM) || CheckGlobalFlag(ENDING)) { -#else -#ifdef EU + gArea.pMusicIndex = gArea.musicIndex; + } +#elif defined(EU) if (CheckGlobalFlag(ENDING)) { + gArea.pMusicIndex = gArea.musicIndex; + } #else if (CheckGlobalFlag(CASTLE_BGM)) { - - gArea.pMusicIndex = 0x1b; + gArea.pMusicIndex = BGM_HYRULE_CASTLE_NOINTRO; } else if (CheckGlobalFlag(ENDING)) { -#endif -#endif gArea.pMusicIndex = gArea.musicIndex; } +#endif } extern u32 gUnk_080D7410; @@ -597,7 +593,6 @@ extern EntityData gUnk_080D73B0; extern EntityData gUnk_080D73E0; void sub_StateChange_HyruleCastle_1(void) { -#ifdef EU if (CheckGlobalFlag(ENDING)) { gArea.pMusicIndex = gArea.musicIndex; } else { @@ -607,22 +602,12 @@ void sub_StateChange_HyruleCastle_1(void) { if (!CheckGlobalFlag(LV1_CLEAR) && CheckGlobalFlag(TABIDACHI)) { LoadRoomEntityList(&gUnk_080D73E0); } - } -#else - if (!CheckGlobalFlag(ENDING)) { - if (!CheckGlobalFlag(LV2_CLEAR)) { - LoadRoomEntityList(&gUnk_080D73B0); - } - if (!CheckGlobalFlag(LV1_CLEAR) && CheckGlobalFlag(TABIDACHI)) { - LoadRoomEntityList(&gUnk_080D73E0); - } +#ifndef EU if (CheckGlobalFlag(CASTLE_BGM)) { gArea.pMusicIndex = gArea.musicIndex; } - } else { - gArea.pMusicIndex = gArea.musicIndex; - } #endif + } } u32 sub_unk3_HyruleCastle_2() { @@ -646,7 +631,7 @@ void sub_StateChange_HyruleCastle_2(void) { gArea.pMusicIndex = gArea.musicIndex; } else if (CheckGlobalFlag(TABIDACHI) == 0) { LoadRoomEntityList(&gUnk_080D74C8); - gArea.pMusicIndex = 0x1b; + gArea.pMusicIndex = BGM_HYRULE_CASTLE_NOINTRO; } else if (CheckGlobalFlag(LV1_CLEAR) == 0) { LoadRoomEntityList(&gUnk_080D7588); } else { @@ -661,21 +646,13 @@ u32 sub_unk3_HyruleCastle_3() { extern EntityData gUnk_additional_8_HyruleCastle_3; void sub_StateChange_HyruleCastle_3(void) { -#if defined(JP) || defined(EU) || defined(DEMO_JP) - if (CheckLocalFlag(0x9b)) { -#else - if (CheckLocalFlag(0x9c)) { -#endif + if (CheckLocalFlag(SOUGEN_08_TORITSUKI)) { LoadRoomEntityList(&gUnk_additional_8_HyruleCastle_3); } } u32 sub_unk3_HyruleCastle_4(void) { -#if defined(JP) || defined(EU) || defined(DEMO_JP) - if (!CheckLocalFlag(0x9e)) { -#else - if (!CheckLocalFlag(0x9f)) { -#endif + if (!CheckLocalFlag(CASTLE_04_MEZAME)) { gScreenTransition.player_status.spawn_type = 5; ClearGlobalFlag(ZELDA_CHASE); } @@ -685,11 +662,7 @@ u32 sub_unk3_HyruleCastle_4(void) { extern u32 script_08009E88; void sub_StateChange_HyruleCastle_4(void) { -#if defined(JP) || defined(DEMO_JP) || defined(EU) - if (!CheckLocalFlag(0x9e)) { -#else - if (!CheckLocalFlag(0x9f)) { -#endif + if (!CheckLocalFlag(CASTLE_04_MEZAME)) { DoFade(5, 0x100); gPlayerEntity.x.HALF.HI = gRoomControls.roomOriginX + 0xb0; gPlayerEntity.y.HALF.HI = gRoomControls.roomOriginY + 0x40; @@ -958,8 +931,8 @@ extern u32 gUnk_080D8BFA; extern u32 gUnk_080D8C68; void sub_StateChange_GoronCave_Main(void) { - if (!CheckLocalFlag(0x68)) - SetLocalFlag(0x68); + if (!CheckLocalFlag(GORON_DOUKUTU_APPEAR)) + SetLocalFlag(GORON_DOUKUTU_APPEAR); if (CheckKinstoneFused(0x2f)) LoadRoomEntityList(&gUnk_080D8B24); @@ -1220,7 +1193,7 @@ void sub_StateChange_CastorCaves_HeartPiece() { extern u32 gUnk_080DA230; u32 sub_unk3_CastorDarknut_Main(void) { - if (!CheckLocalFlag(0x39)) + if (!CheckLocalFlag(LV4_0a_TSUBO)) gRoomVars.field_0x6c[0] = &gUnk_080DA230; return 1; @@ -1542,7 +1515,7 @@ extern EntityData gUnk_080DB4A0; void sub_StateChange_TownMinishHoles_MayorsHouse(void) { // flippers and history of masks book - if (!GetInventoryValue(0x46) && !GetInventoryValue(0x3b) && CheckLocalFlag(0x71)) + if (!GetInventoryValue(0x46) && !GetInventoryValue(0x3b) && CheckLocalFlag(KOBITO_DOUKUTU_04_T0)) LoadRoomEntityList(&gUnk_080DB4D0); else LoadRoomEntityList(&gUnk_080DB4A0); @@ -1593,7 +1566,7 @@ void sub_StateChange_TownMinishHoles_5() { extern u32 gUnk_080DB910; u32 sub_unk3_TownMinishHoles_LibraryBookshelf(void) { - if (CheckGlobalFlag(MIZUKAKI_START) && !CheckLocalFlag(0x73)) { + if (CheckGlobalFlag(MIZUKAKI_START) && !CheckLocalFlag(KOBITO_DOUKUTU_09_T0)) { gRoomVars.field_0x6c[1] = &gUnk_080DB910; } return 1; @@ -1621,7 +1594,7 @@ extern EntityData gUnk_080DBA08; void sub_StateChange_TownMinishHoles_LibrariBookHouse(void) { // flippers - if (GetInventoryValue(0x46) || !CheckLocalFlag(0x73)) { + if (GetInventoryValue(0x46) || !CheckLocalFlag(KOBITO_DOUKUTU_09_T0)) { LoadRoomEntityList(&gUnk_080DBA08); } sub_0801AFE4(); @@ -1641,7 +1614,7 @@ void sub_StateChange_TownMinishHoles_RemShoeShop(void) { u32 tilePos; u32 i; - if (!CheckLocalFlag(0x60)) { + if (!CheckLocalFlag(KOBITO_DOUKUTU_00_T0)) { LoadRoomEntityList(&gUnk_080DBB50); } @@ -1652,7 +1625,7 @@ void sub_StateChange_TownMinishHoles_RemShoeShop(void) { } else { LoadRoomEntityList(&gUnk_080DBAD0); } - if (!CheckLocalFlag(0x62)) { + if (!CheckLocalFlag(KOBITO_DOUKUTU_05_T0)) { tilePos = 0x140; for (i = 0; i < 0x13; i++, tilePos++) { SetTileType(0x4072, tilePos, 1); @@ -6756,5 +6729,5 @@ void sub_StateChange_CrenelCaves_ToGrayblade() { void sub_0804FF84(u32 arg0) { ((struct_02000000*)0x02000000)->brightnessPref = arg0; - gUsedPalettes = (u32)-1; + gUsedPalettes = 0xffffffff; } @@ -79,7 +79,7 @@ static const SaveFileStatus sSaveDescInit = { 0xffff, 0xffff, 'TINI' }; // Save file is deleted static const SaveFileStatus sSaveDescDeleted = { 0xffff, 0xffff, 'FleD' }; -const char gUnk_0811E4B4[8] = "DAMEDAME"; +const char sDummyData[8] = "DAMEDAME"; const SaveFileEEPROMAddresses gSaveFileEEPROMAddresses[] = { { 0x500, 0x30, 0x1030, 0x80, 0x1080 }, { 0x500, 0x40, 0x1040, 0x580, 0x1580 }, { 0x500, 0x50, 0x1050, 0xa80, 0x1a80 }, @@ -438,7 +438,7 @@ bool32 DataWrite(u32 address, const void* data, u32 size) { address /= 8; while (size-- > 0) { if (EEPROMWrite0_8k_Check(address, data)) { - EEPROMWrite0_8k_Check(address, (const u16*)gUnk_0811E4B4); + EEPROMWrite0_8k_Check(address, (const u16*)sDummyData); return FALSE; } address++; diff --git a/src/script.c b/src/script.c index 34da5deb..7f5d1fb9 100644 --- a/src/script.c +++ b/src/script.c @@ -70,7 +70,7 @@ void ScriptCommand_ClearRoomFlag(Entity* entity, ScriptExecutionContext* context void ScriptCommand_Wait(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_WaitForSomething(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_WaitForSomething2(Entity* entity, ScriptExecutionContext* context); -void ScriptCommand_WaitPlayerAction8(Entity* entity, ScriptExecutionContext* context); +void ScriptCommand_WaitPlayerGetItem(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_WaitForPlayerAction0x17(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_WaitFor_1(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_WaitFor_2(Entity* entity, ScriptExecutionContext* context); @@ -122,7 +122,7 @@ void ScriptCommand_SetEntityDirectionWithAnimationState(Entity* entity, ScriptEx void ScriptCommand_SetEntitySpeed(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_SetEntity0x20(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_SetEntityPositionRelative(Entity* entity, ScriptExecutionContext* context); -void ScriptCommand_SetEntityPosition(Entity* entity, ScriptExecutionContext* context); +void ScriptCommand_OffsetEntityPosition(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_MoveEntityToPlayer(Entity* entity, ScriptExecutionContext* context); void ScriptCommandNop3(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_0807EC1C(Entity* entity, ScriptExecutionContext* context); @@ -163,145 +163,7 @@ extern void RecoverUI(u32); typedef void (*ScriptCommand)(Entity*, ScriptExecutionContext*); -const ScriptCommand gScriptCommands[] = { ScriptCommandNop, - ScriptCommand_BeginBlock, - ScriptCommand_EndBlock, - ScriptCommand_Jump, - ScriptCommand_JumpIf, - ScriptCommand_JumpIfNot, - ScriptCommand_JumpTable, - ScriptCommand_JumpAbsolute, - ScriptCommand_JumpAbsoluteIf, - ScriptCommand_JumpAbsoluteIfNot, - ScriptCommand_JumpAbsoluteTable, - ScriptCommand_Call, - ScriptCommand_CallWithArg, - ScriptCommand_LoadRoomEntityList, - ScriptCommand_TestBit, - ScriptCommand_CheckInventory1, - ScriptCommand_CheckInventory2, - ScriptCommand_HasRoomItemForSale, - ScriptCommand_CheckLocalFlag, - ScriptCommand_CheckLocalFlagByBank, - ScriptCommand_CheckGlobalFlag, - ScriptCommand_CheckRoomFlag, - ScriptCommand_CheckPlayerInRegion, - ScriptCommand_CheckPlayerInRegion2, - ScriptCommand_CheckEntityInteractType, - ScriptCommand_0807E30C, - ScriptCommand_HasRupees, - ScriptCommand_0807E3BC, - ScriptCommand_0807E3E8, - ScriptCommand_CheckKinstoneFused, - ScriptCommand_BuyItem, - ScriptCommand_0807E48C, - ScriptCommand_0807E4CC, - ScriptCommand_0807E4EC, - ScriptCommand_0807E514, - ScriptCommand_CheckPlayerFlags, - ScriptCommand_0807E564, - ScriptCommand_EntityHasHeight, - ScriptCommand_ComparePlayerAction, - ScriptCommand_ComparePlayerAnimationState, - ScriptCommand_0807E5F8, - ScriptCommand_0807E610, - ScriptCommand_SetLocalFlag, - ScriptCommand_SetLocalFlagByBank, - ScriptCommand_ClearLocalFlag, - ScriptCommand_SetGlobalFlag, - ScriptCommand_ClearGlobalFlag, - ScriptCommand_SetRoomFlag, - ScriptCommand_ClearRoomFlag, - ScriptCommand_Wait, - ScriptCommand_WaitForSomething, - ScriptCommand_WaitForSomething2, - ScriptCommand_WaitPlayerAction8, - ScriptCommand_WaitForPlayerAction0x17, - ScriptCommand_WaitFor_1, - ScriptCommand_WaitFor_2, - ScriptCommand_0807E778, - ScriptCommand_SetFadeMask, - ScriptCommand_0807E79C, - ScriptCommandNop2, - ScriptCommand_DoFade4, - ScriptCommand_DoFade5, - ScriptCommand_DoFade6, - ScriptCommand_DoFade7, - ScriptCommand_0807E800, - ScriptCommand_0807E80C, - ScriptCommand_0807E858, - ScriptCommand_0807E864, - ScriptCommand_0807E878, - ScriptCommand_0807E888, - ScriptCommand_SetPlayerAction, - ScriptCommand_StartPlayerScript, - ScriptCommand_0807E8D4, - ScriptCommand_0807E8E4, - ScriptCommand_0807E8E4, - ScriptCommand_0807E8E4, - ScriptCommand_0807E8E4, - ScriptCommand_0807E908, - ScriptCommand_SetIntVariable, - ScriptCommand_0807E924, - ScriptCommand_0807E930, - ScriptCommand_0807E944, - ScriptCommand_0807E974, - ScriptCommand_0807E9D4, - ScriptCommand_0807E9DC, - ScriptCommand_0807E9E4, - ScriptCommand_0807E9F0, - ScriptCommand_0807EA4C, - ScriptCommand_0807EA88, - ScriptCommand_WaitUntilTextboxCloses, - ScriptCommand_MessageFromTarget, - ScriptCommand_MessageNoOverlap, - ScriptCommand_MessageFromTargetPos, - ScriptCommand_MessageFromTargetTable, - ScriptCommand_MessageNoOverlapVar, - ScriptCommand_0807EB28, - ScriptCommand_0807EB38, - ScriptCommand_0807EB44, - ScriptCommand_0807EB4C, - ScriptCommand_0807EB74, - ScriptCommand_0807EB8C, - ScriptCommand_SetEntityDirection, - ScriptCommand_SetEntityDirectionWithAnimationState, - ScriptCommand_SetEntitySpeed, - ScriptCommand_SetEntity0x20, - ScriptCommand_SetEntityPositionRelative, - ScriptCommand_SetEntityPosition, - ScriptCommand_MoveEntityToPlayer, - ScriptCommandNop3, - ScriptCommand_0807EC1C, - ScriptCommand_0807EC64, - ScriptCommand_0807EC94, - ScriptCommand_0807ECC4, - ScriptCommand_0807ECF4, - ScriptCommand_0807ED24, - ScriptCommand_0807EDD4, - ScriptCommand_0807EE04, - ScriptCommand_0807EE30, - ScriptCommand_0807EEB4, - ScriptCommand_0807EEF4, - ScriptCommand_0807EF3C, - ScriptCommand_DoPostScriptAction, - ScriptCommand_DoPostScriptAction2, - ScriptCommand_PlaySound, - ScriptCommand_PlayBgm, - ScriptCommand_SoundReq, - ScriptCommand_StopBgm, - ScriptCommand_ModRupees, - ScriptCommand_ModHealth, - ScriptCommand_IncreaseMaxHealth, - ScriptCommand_0807F034, - ScriptCommand_0807F050, - ScriptCommand_GetInventoryValue, - ScriptCommand_0807F078, - ScriptCommand_0807F088, - ScriptCommand_CameraTargetEntity, - ScriptCommand_CameraTargetPlayer, - ScriptCommand_0807F0B4, - ScriptCommand_0807F0C8 }; +extern const ScriptCommand gScriptCommands[]; extern u16* gUnk_08001A7C[]; extern u8 gUnk_08114F30[]; @@ -432,10 +294,10 @@ void HandlePostScriptActions(Entity* entity, ScriptExecutionContext* context) { entity->field_0x82.HWORD |= 2; break; case 1 << 0x0b: - entity->field_0x82.HWORD &= 0xfffd; + entity->field_0x82.HWORD &= ~2; break; case 1 << 0x0c: - entity->field_0x82.HWORD &= 0xfffe; + entity->field_0x82.HWORD &= ~1; break; case 1 << 0x0d: entity->field_0x82.HWORD |= 1; @@ -456,7 +318,7 @@ void HandlePostScriptActions(Entity* entity, ScriptExecutionContext* context) { entity->field_0x82.HWORD |= 0x20; break; case 1 << 0x13: - entity->field_0x82.HWORD &= 0xffdf; + entity->field_0x82.HWORD &= ~0x20; break; default: break; @@ -515,22 +377,23 @@ void HandleEntity0x82Actions(Entity* entity) { loopVar = loopVar ^ bit; switch (bit) { case 1 << 1: - if (entity->kind == 7) { + if (entity->kind == NPC) { sub_0806ED78(entity); } else { sub_0800445C(entity); } break; case 1 << 3: - if ((gScreenTransition.frameCount & 3) == 0) { - temp = (entity->field_0xf + 2U) & 7; + if (gScreenTransition.frameCount % 4 == 0) { + temp = (entity->field_0xf + 2) & 7; entity->animationState = temp; entity->field_0xf = temp; } break; case 1 << 4: - if ((gScreenTransition.frameCount & 1) == 0) { - entity->spriteOffsetX = gUnk_0811E510[Random() & 3]; + if (gScreenTransition.frameCount % 2 == 0) { + static const s8 sOffsets[] = { -1, -2, 0, 1 }; + entity->spriteOffsetX = sOffsets[Random() % 4]; } break; case 1 << 5: @@ -573,6 +436,7 @@ void sub_0807DE80(Entity* entity) { } void sub_0807DEDC(Entity* entity, ScriptExecutionContext* context, u32 x, u32 y) { + static const u8 sDirectionTable[] = { 0, 0, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 0, 0 }; int direction; s32 xOffset, yOffset; @@ -585,7 +449,7 @@ void sub_0807DEDC(Entity* entity, ScriptExecutionContext* context, u32 x, u32 y) yOffset = context->y.HALF.HI - entity->y.HALF.HI; direction = sub_080045DA(xOffset, yOffset); entity->direction = direction; - entity->animationState = (entity->animationState & 0x80) | gUnk_0811E514[(u32)(direction << 0x18) >> 0x1c]; + entity->animationState = (entity->animationState & 0x80) | sDirectionTable[(u8)direction >> 4]; } void sub_0807DF28(void) { @@ -608,6 +472,148 @@ void sub_0807DF50(void) { } void ExecuteScript(Entity* entity, ScriptExecutionContext* context) { + static const ScriptCommand gScriptCommands[] = { + ScriptCommandNop, + ScriptCommand_BeginBlock, + ScriptCommand_EndBlock, + ScriptCommand_Jump, + ScriptCommand_JumpIf, + ScriptCommand_JumpIfNot, + ScriptCommand_JumpTable, + ScriptCommand_JumpAbsolute, + ScriptCommand_JumpAbsoluteIf, + ScriptCommand_JumpAbsoluteIfNot, + ScriptCommand_JumpAbsoluteTable, + ScriptCommand_Call, + ScriptCommand_CallWithArg, + ScriptCommand_LoadRoomEntityList, + ScriptCommand_TestBit, + ScriptCommand_CheckInventory1, + ScriptCommand_CheckInventory2, + ScriptCommand_HasRoomItemForSale, + ScriptCommand_CheckLocalFlag, + ScriptCommand_CheckLocalFlagByBank, + ScriptCommand_CheckGlobalFlag, + ScriptCommand_CheckRoomFlag, + ScriptCommand_CheckPlayerInRegion, + ScriptCommand_CheckPlayerInRegion2, + ScriptCommand_CheckEntityInteractType, + ScriptCommand_0807E30C, + ScriptCommand_HasRupees, + ScriptCommand_0807E3BC, + ScriptCommand_0807E3E8, + ScriptCommand_CheckKinstoneFused, + ScriptCommand_BuyItem, + ScriptCommand_0807E48C, + ScriptCommand_0807E4CC, + ScriptCommand_0807E4EC, + ScriptCommand_0807E514, + ScriptCommand_CheckPlayerFlags, + ScriptCommand_0807E564, + ScriptCommand_EntityHasHeight, + ScriptCommand_ComparePlayerAction, + ScriptCommand_ComparePlayerAnimationState, + ScriptCommand_0807E5F8, + ScriptCommand_0807E610, + ScriptCommand_SetLocalFlag, + ScriptCommand_SetLocalFlagByBank, + ScriptCommand_ClearLocalFlag, + ScriptCommand_SetGlobalFlag, + ScriptCommand_ClearGlobalFlag, + ScriptCommand_SetRoomFlag, + ScriptCommand_ClearRoomFlag, + ScriptCommand_Wait, + ScriptCommand_WaitForSomething, + ScriptCommand_WaitForSomething2, + ScriptCommand_WaitPlayerGetItem, + ScriptCommand_WaitForPlayerAction0x17, + ScriptCommand_WaitFor_1, + ScriptCommand_WaitFor_2, + ScriptCommand_0807E778, + ScriptCommand_SetFadeMask, + ScriptCommand_0807E79C, + ScriptCommandNop2, + ScriptCommand_DoFade4, + ScriptCommand_DoFade5, + ScriptCommand_DoFade6, + ScriptCommand_DoFade7, + ScriptCommand_0807E800, + ScriptCommand_0807E80C, + ScriptCommand_0807E858, + ScriptCommand_0807E864, + ScriptCommand_0807E878, + ScriptCommand_0807E888, + ScriptCommand_SetPlayerAction, + ScriptCommand_StartPlayerScript, + ScriptCommand_0807E8D4, + ScriptCommand_0807E8E4, + ScriptCommand_0807E8E4, + ScriptCommand_0807E8E4, + ScriptCommand_0807E8E4, + ScriptCommand_0807E908, + ScriptCommand_SetIntVariable, + ScriptCommand_0807E924, + ScriptCommand_0807E930, + ScriptCommand_0807E944, + ScriptCommand_0807E974, + ScriptCommand_0807E9D4, + ScriptCommand_0807E9DC, + ScriptCommand_0807E9E4, + ScriptCommand_0807E9F0, + ScriptCommand_0807EA4C, + ScriptCommand_0807EA88, + ScriptCommand_WaitUntilTextboxCloses, + ScriptCommand_MessageFromTarget, + ScriptCommand_MessageNoOverlap, + ScriptCommand_MessageFromTargetPos, + ScriptCommand_MessageFromTargetTable, + ScriptCommand_MessageNoOverlapVar, + ScriptCommand_0807EB28, + ScriptCommand_0807EB38, + ScriptCommand_0807EB44, + ScriptCommand_0807EB4C, + ScriptCommand_0807EB74, + ScriptCommand_0807EB8C, + ScriptCommand_SetEntityDirection, + ScriptCommand_SetEntityDirectionWithAnimationState, + ScriptCommand_SetEntitySpeed, + ScriptCommand_SetEntity0x20, + ScriptCommand_SetEntityPositionRelative, + ScriptCommand_OffsetEntityPosition, + ScriptCommand_MoveEntityToPlayer, + ScriptCommandNop3, + ScriptCommand_0807EC1C, + ScriptCommand_0807EC64, + ScriptCommand_0807EC94, + ScriptCommand_0807ECC4, + ScriptCommand_0807ECF4, + ScriptCommand_0807ED24, + ScriptCommand_0807EDD4, + ScriptCommand_0807EE04, + ScriptCommand_0807EE30, + ScriptCommand_0807EEB4, + ScriptCommand_0807EEF4, + ScriptCommand_0807EF3C, + ScriptCommand_DoPostScriptAction, + ScriptCommand_DoPostScriptAction2, + ScriptCommand_PlaySound, + ScriptCommand_PlayBgm, + ScriptCommand_SoundReq, + ScriptCommand_StopBgm, + ScriptCommand_ModRupees, + ScriptCommand_ModHealth, + ScriptCommand_IncreaseMaxHealth, + ScriptCommand_0807F034, + ScriptCommand_0807F050, + ScriptCommand_GetInventoryValue, + ScriptCommand_0807F078, + ScriptCommand_0807F088, + ScriptCommand_CameraTargetEntity, + ScriptCommand_CameraTargetPlayer, + ScriptCommand_0807F0B4, + ScriptCommand_0807F0C8, + }; + if (!context->scriptInstructionPointer) return; if (context->wait) { @@ -714,13 +720,13 @@ void ScriptCommand_LoadRoomEntityList(Entity* entity, ScriptExecutionContext* co } void ScriptCommand_TestBit(Entity* entity, ScriptExecutionContext* context) { - u32 tmp = GetNextScriptCommandWordAfterCommandMetadata(context->scriptInstructionPointer); - u32 tmp2 = 0; - u32 tmp3 = gActiveScriptInfo.unk_00; - if ((tmp3 & tmp) == tmp) - tmp2 = 1; - context->condition = tmp2; - gActiveScriptInfo.unk_00 = tmp3 & ~tmp; + u32 flag = GetNextScriptCommandWordAfterCommandMetadata(context->scriptInstructionPointer); + u32 set = 0; + u32 field = gActiveScriptInfo.unk_00; + if ((field & flag) == flag) + set = 1; + context->condition = set; + gActiveScriptInfo.unk_00 = field & ~flag; gActiveScriptInfo.flags |= 1; } @@ -807,7 +813,7 @@ void ScriptCommand_CheckEntityInteractType(Entity* entity, ScriptExecutionContex void ScriptCommand_0807E30C(Entity* entity, ScriptExecutionContext* context) { if ((context->unk_1A & 0xF) == 0 && (gPlayerState.flags & PL_MINISH) == 0 && - sub_080041A0(entity, &gPlayerEntity, 0x28, 0x28)) { + EntityInRectRadius(entity, &gPlayerEntity, 40, 40)) { entity->animationState = sub_0806F5B0(GetFacingDirection(entity, &gPlayerEntity)); } context->unk_1A++; @@ -847,16 +853,16 @@ void ScriptCommand_BuyItem(Entity* entity, ScriptExecutionContext* context) { item = context->scriptInstructionPointer[1]; tmp2 = context->scriptInstructionPointer[2]; if (!item) { - item = gRoomVars.itemForSaleIndex; - tmp2 = gRoomVars.field_0x7; + item = gRoomVars.shopItemType; + tmp2 = gRoomVars.shopItemType2; } price = GetItemPrice(item); context->condition = (price <= gSave.stats.rupees); if (context->condition) { ModRupees(-price); sub_080A7C18(item, tmp2, 0); - gRoomVars.itemForSaleIndex = 0; - gRoomVars.field_0x7 = 0; + gRoomVars.shopItemType = 0; + gRoomVars.shopItemType2 = 0; } gActiveScriptInfo.flags |= 1; } @@ -867,7 +873,7 @@ void ScriptCommand_0807E48C(Entity* entity, ScriptExecutionContext* context) { } void ScriptCommand_HasRoomItemForSale(Entity* entity, ScriptExecutionContext* context) { - context->condition = !!gRoomVars.itemForSaleIndex; + context->condition = !!gRoomVars.shopItemType; gActiveScriptInfo.flags |= 1; } @@ -971,11 +977,11 @@ void ScriptCommand_WaitForSomething2(Entity* entity, ScriptExecutionContext* con } } -void ScriptCommand_WaitPlayerAction8(Entity* entity, ScriptExecutionContext* context) { - if (gPlayerEntity.action == 8) { +void ScriptCommand_WaitPlayerGetItem(Entity* entity, ScriptExecutionContext* context) { + if (gPlayerEntity.action == PLAYER_ITEMGET) { gActiveScriptInfo.commandSize = 0; } else { - context->wait = 0x2D; + context->wait = 45; } } @@ -1058,16 +1064,16 @@ void ScriptCommand_0807E858(Entity* entity, ScriptExecutionContext* context) { } void ScriptCommand_0807E864(Entity* entity, ScriptExecutionContext* context) { - gPlayerState.field_0x8b = 3; + gPlayerState.controlMode = CONTROL_DISABLED; sub_08078B48(); } void ScriptCommand_0807E878(Entity* entity, ScriptExecutionContext* context) { - gPlayerState.field_0x8b = 1; + gPlayerState.controlMode = 1; } void ScriptCommand_0807E888(Entity* entity, ScriptExecutionContext* context) { - gPlayerState.field_0x8b = 3; + gPlayerState.controlMode = CONTROL_DISABLED; } void ScriptCommand_SetPlayerAction(Entity* entity, ScriptExecutionContext* context) { @@ -1083,7 +1089,7 @@ void ScriptCommand_StartPlayerScript(Entity* entity, ScriptExecutionContext* con } void ScriptCommand_0807E8D4(Entity* entity, ScriptExecutionContext* context) { - gPlayerState.field_0x8 = context->scriptInstructionPointer[1]; + gPlayerState.animation = context->scriptInstructionPointer[1]; } void ScriptCommand_0807E8E4(Entity* entity, ScriptExecutionContext* context) { @@ -1161,7 +1167,7 @@ void ScriptCommand_0807E9F0(Entity* entity, ScriptExecutionContext* context) { tmp = 1; switch (gUnk_02022740[0]) { case 2: - gPlayerState.field_0x8b = 3; + gPlayerState.controlMode = CONTROL_DISABLED; gUnk_02034490[0] = tmp; context->condition = tmp; break; @@ -1173,7 +1179,7 @@ void ScriptCommand_0807E9F0(Entity* entity, ScriptExecutionContext* context) { } if (tmp) { sub_0807919C(); - gPlayerState.field_0x8b = 1; + gPlayerState.controlMode = 1; } else { lbl: gActiveScriptInfo.commandSize = 0; @@ -1275,7 +1281,7 @@ void ScriptCommand_SetEntityPositionRelative(Entity* entity, ScriptExecutionCont entity->y.HALF.HI = gRoomControls.roomOriginY + context->scriptInstructionPointer[2]; } -void ScriptCommand_SetEntityPosition(Entity* entity, ScriptExecutionContext* context) { +void ScriptCommand_OffsetEntityPosition(Entity* entity, ScriptExecutionContext* context) { entity->x.HALF.HI += context->scriptInstructionPointer[1]; entity->y.HALF.HI += context->scriptInstructionPointer[2]; } @@ -1308,7 +1314,7 @@ void ScriptCommand_0807EC64(Entity* entity, ScriptExecutionContext* context) { context->unk_18 = 1; context->unk_12 = context->scriptInstructionPointer[1]; entity->animationState = 0; - entity->direction = 0; + entity->direction = DirectionNorth; context->postScriptActions |= 2; } sub_0807EC44(entity, context); @@ -1319,7 +1325,7 @@ void ScriptCommand_0807EC94(Entity* entity, ScriptExecutionContext* context) { context->unk_18 = 1; context->unk_12 = context->scriptInstructionPointer[1]; entity->animationState = 2; - entity->direction = 8; + entity->direction = DirectionEast; context->postScriptActions |= 2; } sub_0807EC44(entity, context); @@ -1330,7 +1336,7 @@ void ScriptCommand_0807ECC4(Entity* entity, ScriptExecutionContext* context) { context->unk_18 = 1; context->unk_12 = context->scriptInstructionPointer[1]; entity->animationState = 4; - entity->direction = 0x10; + entity->direction = DirectionSouth; context->postScriptActions |= 2; } sub_0807EC44(entity, context); @@ -1341,7 +1347,7 @@ void ScriptCommand_0807ECF4(Entity* entity, ScriptExecutionContext* context) { context->unk_18 = 1; context->unk_12 = context->scriptInstructionPointer[1]; entity->animationState = 6; - entity->direction = 0x18; + entity->direction = DirectionWest; context->postScriptActions |= 2; } sub_0807EC44(entity, context); @@ -1543,19 +1549,20 @@ void sub_0807F0EC(Entity* entity, ScriptExecutionContext* context) { } void sub_0807F100(Entity* entity, ScriptExecutionContext* context) { - u32 rand; + static const u8 sValues[] = { 0xa, 0x14, 0x1e, 0x12, 0x1c, 0x26, 0xc, 0x18 }; - rand = Random(); + u32 rand = Random(); entity->animationState = rand & 6; - context->unk_1A = gUnk_0811E750[(rand >> 8) & 7]; + context->unk_1A = sValues[(rand >> 8) % 8]; } void sub_0807F128(Entity* entity, ScriptExecutionContext* context) { - u32 rand; + static const u8 sAnimations[] = { 6, 2, 6, 2, 4, 6, 4, 2 }; + static const u8 sValues[] = { 0xa, 0x14, 0x1e, 0x12, 0x1c, 0x26, 0xc, 0x18 }; - rand = Random(); - entity->animationState = gUnk_0811E758[rand & 7]; - context->unk_1A = gUnk_0811E760[(rand >> 8) & 7]; + u32 rand = Random(); + entity->animationState = sAnimations[rand & 7]; + context->unk_1A = sValues[(rand >> 8) % 8]; } void sub_0807F158(Entity* entity, ScriptExecutionContext* context) { @@ -1583,31 +1590,31 @@ void sub_0807F1A0(Entity* entity, ScriptExecutionContext* context) { } void sub_0807F1C4(Entity* entity, ScriptExecutionContext* context) { - if ((gPlayerState.flags & 8) != 0) { - gPlayerState.field_0x8 = 0x459; + if (gPlayerState.flags & PL_NO_CAP) { + gPlayerState.animation = 0x459; } else { - gPlayerState.field_0x8 = 0x1bc; + gPlayerState.animation = 0x1bc; } } void sub_0807F1E8(Entity* entity, ScriptExecutionContext* context) { - if ((gPlayerState.flags & 8) != 0) { - gPlayerState.field_0x8 = 0x45a; + if (gPlayerState.flags & PL_NO_CAP) { + gPlayerState.animation = 0x45a; } else { - gPlayerState.field_0x8 = 0x2bd; + gPlayerState.animation = 0x2bd; } } void sub_0807F210(Entity* entity, ScriptExecutionContext* context) { - if ((gPlayerState.flags & 8) != 0) { - gPlayerState.field_0x8 = 0x41c; + if (gPlayerState.flags & PL_NO_CAP) { + gPlayerState.animation = 0x41c; } else { - gPlayerState.field_0x8 = 0x80c; + gPlayerState.animation = 0x80c; } } void sub_0807F238(Entity* entity, ScriptExecutionContext* context) { - gPlayerState.field_0x8 = context->intVariable; + gPlayerState.animation = context->intVariable; } void sub_0807F244(Entity* entity, ScriptExecutionContext* context) { @@ -1672,15 +1679,15 @@ void sub_0807F338(Entity* entity, ScriptExecutionContext* context) { } void sub_0807F348(Entity* entity, ScriptExecutionContext* context) { - SetDefaultPriority(entity, 2); + SetDefaultPriority(entity, PRIO_MESSAGE); } void sub_0807F354(Entity* entity, ScriptExecutionContext* context) { - SetDefaultPriority(entity, 6); + SetDefaultPriority(entity, PRIO_PLAYER_EVENT); } void sub_0807F360(Entity* entity, ScriptExecutionContext* context) { - SetDefaultPriority(entity, 3); + SetDefaultPriority(entity, PRIO_NO_BLOCK); } void sub_0807F36C(Entity* entity, ScriptExecutionContext* context) { @@ -1688,7 +1695,7 @@ void sub_0807F36C(Entity* entity, ScriptExecutionContext* context) { fx = CreateFx(entity, FX_REFLECT4, 0); if (fx != NULL) { fx->spritePriority.b0 = 1; - PositionRelative(entity, fx, 0, -524288); + PositionRelative(entity, fx, 0, -0x80000); if (Random() & 1) fx->spriteSettings.flipX = 1; if (Random() & 1) @@ -1823,13 +1830,13 @@ void sub_0807F5C0(Entity* entity, ScriptExecutionContext* context) { void sub_0807F634(Entity* entity, ScriptExecutionContext* context) { u16* p = (u16*)context->intVariable; sub_0801DFB4(entity, p[0], p[1], p[2]); - gPlayerState.field_0x8b = 3; + gPlayerState.controlMode = CONTROL_DISABLED; } void sub_0807F650(Entity* entity, ScriptExecutionContext* context) { u32 p = sub_08002632(entity); sub_0801DFB4(entity, gUnk_08001A7C[p][0], gUnk_08001A7C[p][1], gUnk_08001A7C[p][2]); - gPlayerState.field_0x8b = 3; + gPlayerState.controlMode = CONTROL_DISABLED; } void sub_0807F680(Entity* entity, ScriptExecutionContext* context) { @@ -1883,7 +1890,7 @@ void sub_0807F78C(Entity* entity, ScriptExecutionContext* context) { u32 price; if (context->intVariable == 0) - item = gRoomVars.itemForSaleIndex; + item = gRoomVars.shopItemType; msg = GetSaleItemConfirmMessageID(item); price = GetItemPrice(item); @@ -1897,7 +1904,7 @@ void sub_0807F7C4(Entity* entity, ScriptExecutionContext* context) { u32 price; if (context->intVariable == 0) - item = gRoomVars.itemForSaleIndex; + item = gRoomVars.shopItemType; context->condition = GetItemPrice(item) <= gSave.stats.rupees; gActiveScriptInfo.flags |= 1; @@ -1909,12 +1916,12 @@ void sub_0807F800(Entity* entity, ScriptExecutionContext* context) { u32 price; if (context->intVariable == 0) - item = gRoomVars.itemForSaleIndex; + item = gRoomVars.shopItemType; price = GetItemPrice(item); ModRupees(-price); sub_080A7C18(item, 0, 0); - gRoomVars.itemForSaleIndex = 0; + gRoomVars.shopItemType = 0; gActiveScriptInfo.flags |= 1; } |
