diff options
| author | Henny022p <info@henny022.de> | 2021-03-22 10:18:20 +0100 |
|---|---|---|
| committer | Henny022p <info@henny022.de> | 2021-03-22 10:18:20 +0100 |
| commit | 5cebf089fd0b34e017aeb36d540bfce051a4969c (patch) | |
| tree | b896213a6d2ead9a54518209d7a7e0a1ab855cbe /src | |
| parent | 61b284265f37dda398a561f1f8a3ccdd8d1b39da (diff) | |
| parent | 8e3bebad007d5ba082ffb14aafbb2be94dfd8fcd (diff) | |
Merge branch 'master' into m4a
Diffstat (limited to 'src')
207 files changed, 1904 insertions, 1801 deletions
diff --git a/src/arm_proxy.c b/src/arm_proxy.c index e18e4a1c..4e153936 100644 --- a/src/arm_proxy.c +++ b/src/arm_proxy.c @@ -8,6 +8,7 @@ #include "functions.h" #include "object.h" #include "manager.h" +#include "utils.h" #include "npc.h" extern u8 gUnk_03003DE0; @@ -30,7 +31,7 @@ extern void LoadResources(); extern void FadeMain(); extern u32 sub_0805E3B0(); extern void HandlePlayerLife(); -extern void sub_08070680(); +extern void DoPlayerAction(); extern void sub_080171F0(); extern void sub_08078FB0(); extern void DrawEntity(); @@ -69,17 +70,6 @@ typedef struct { extern NPCStruct gUnk_02031EC0[100]; typedef struct { - u8 unk0; - u8 unk1; - u8 unk2; - u8 unk3; - u8 freezeTime; - u8 unk9; -} EntityHandler; - -extern EntityHandler gUnk_03003DC0; - -typedef struct { void* last; void* first; void* node; @@ -156,7 +146,7 @@ void PlayerUpdate(Entity* this) { } } HandlePlayerLife(this); - sub_08070680(this); + DoPlayerAction(this); if ((this->height.WORD == 0) && (this->action == 1 || this->action == 9)) sub_08008790(this, 8); sub_080171F0(); @@ -174,7 +164,7 @@ void HandlePlayerLife(Entity* this) { gUnk_0200AF00.filler25[8] = 0; gUnk_0200AF00.filler25[9] = 0; - if ((gPlayerEntity.bitfield & 0x80) && (gPlayerEntity.hurtBlinkTime > 0)) + if ((gPlayerEntity.bitfield & 0x80) && (gPlayerEntity.iframes > 0)) SoundReq(SFX_86); gPlayerState.flags.all &= ~(0x2000000 | 0x200); @@ -263,7 +253,7 @@ void sub_080171F0(void) { gPlayerState.field_0x1a[0] = 0; gPlayerState.field_0x80 = 0; gPlayerState.field_0xaa = 0; - MemClear32(&gUnk_03003BE0, 0x8c); + MemClear(&gUnk_03003BE0, 0x8c); gPlayerEntity.spriteOffsetY = gPlayerState.field_0x3f; gPlayerState.field_0x3f = 0; sub_0807B0C8(); @@ -278,7 +268,7 @@ void sub_080171F0(void) { sub_0807A8D8(&gPlayerEntity); if (gPlayerState.jumpStatus & 0xc0) - gPlayerEntity.hurtBlinkTime = 0xfe; + gPlayerEntity.iframes = 0xfe; if (gPlayerEntity.action != 0x17) { sub_08077FEC(gPlayerEntity.action); @@ -286,17 +276,17 @@ void sub_080171F0(void) { } void ItemUpdate(Entity* this) { - if ((this->flags & 1) == 0 && this->action == 0 && this->previousActionFlag == 0) + if ((this->flags & 1) == 0 && this->action == 0 && this->subAction == 0) ItemInit(this); if (!sub_0805E3B0(this)) { gPlayerItemFunctions[this->id](this); this->bitfield &= ~0x80; - if (this->hurtBlinkTime != 0) { - if (this->hurtBlinkTime > 0) - this->hurtBlinkTime--; + if (this->iframes != 0) { + if (this->iframes > 0) + this->iframes--; else - this->hurtBlinkTime++; + this->iframes++; } } DrawEntity(this); @@ -340,8 +330,8 @@ void ObjectUpdate(Entity* this) { if (((this->flags & 1) == 0) && (this->action == 0)) sub_080A2838(this); - if (this->hurtBlinkTime != 0) - this->hurtBlinkTime++; + if (this->iframes != 0) + this->iframes++; if (!sub_0805E3B0(this)) { gObjectFunctions[this->id](this); this->bitfield &= ~0x80; @@ -403,7 +393,7 @@ void CollisionMain(void) { } void RegisterPlayerHitbox(void) { - MemClear32(&gUnk_03003C70, sizeof(gUnk_03003C70)); + MemClear(&gUnk_03003C70, sizeof(gUnk_03003C70)); gUnk_02018EA0 = (LinkedList2*)&gUnk_03003C70[0].last; gUnk_03003C70[0].last = &gUnk_03003C70[0].last; gUnk_03003C70[0].first = &gUnk_03003C70[0].last; diff --git a/src/code_08018C58.c b/src/code_08018C58.c index fd918e31..14caf9cd 100644 --- a/src/code_08018C58.c +++ b/src/code_08018C58.c @@ -1,5 +1,4 @@ #include "global.h" -#include "entity.h" extern u32 SetTileType(u32 tileID, u32 tilePos, u32 layerID); diff --git a/src/code_0801D714.c b/src/code_0801D714.c deleted file mode 100755 index f3e59253..00000000 --- a/src/code_0801D714.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "global.h" - -extern void LoadPalettes(const u8*, int, int); - -extern u32 gUsedPalettes; -extern u16 gPaletteBuffer[]; - -typedef struct { - u16 paletteId; - u8 destPaletteNum; - u8 numPalettes; -} PaletteGroup; - -extern const PaletteGroup* gPaletteGroups[]; -extern const u8 gGlobalGfxAndPalettes[]; - -void LoadPaletteGroup(u32 group) { - const PaletteGroup* paletteGroup = gPaletteGroups[group]; - while (1) { - u32 destPaletteNum = paletteGroup->destPaletteNum; - u32 numPalettes = paletteGroup->numPalettes & 0xF; - if (numPalettes == 0) { - numPalettes = 16; - } - LoadPalettes(&gGlobalGfxAndPalettes[paletteGroup->paletteId * 32], destPaletteNum, numPalettes); - if ((paletteGroup->numPalettes & 0x80) == 0) { - break; - } - paletteGroup++; - } -} - -void LoadPalettes(const u8* src, int destPaletteNum, int numPalettes) { - u16* dest; - u32 size = numPalettes * 32; - u32 usedPalettesMask = 1 << destPaletteNum; - while (--numPalettes > 0) { - usedPalettesMask |= (usedPalettesMask << 1); - } - gUsedPalettes |= usedPalettesMask; - dest = &gPaletteBuffer[destPaletteNum * 16]; - DmaCopy32(3, src, dest, size); -} diff --git a/src/code_0801D79C.c b/src/code_0801D79C.c deleted file mode 100644 index 8f085aae..00000000 --- a/src/code_0801D79C.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "global.h" -#include "screen.h" -#include "structures.h" - -extern u16 gPaletteBuffer[]; -extern u32 gUsedPalettes; - -typedef struct { - union { - int raw; - struct { - u8 filler0[0x3]; - u8 unk3; - } bytes; - } unk0; - u32 dest; - u32 unk8; -} GfxItem; - -extern const GfxItem* gUnk_08100AA8[]; -extern const u8 gGlobalGfxAndPalettes[]; - -void sub_0801D79C(u32 colorIndex, u32 color) { - gPaletteBuffer[colorIndex] = color; - gUsedPalettes |= 1 << (colorIndex / 16); -} - -void sub_0801D7BC(u32 color, u32 arg1) { - if (arg1) { - gScreen.lcd.unk6 = 0xE0FF; - } else { - gScreen.lcd.unk6 = 0xFFFF; - } - sub_0801D79C(0, color); -} - -void LoadGfxGroup(u32 group) { - u32 terminator; - u32 dmaCtrl; - int gfxOffset; - const u8* src; - u32 dest; - int size; - const GfxItem* gfxItem = gUnk_08100AA8[group]; - while (1) { - u32 loadGfx = FALSE; - u32 ctrl = gfxItem->unk0.bytes.unk3; - ctrl &= 0xF; - switch (ctrl) { - case 0x7: - loadGfx = TRUE; - break; - case 0xD: - return; - case 0xE: - if (((struct_02000000*)0x2000000)->gameLanguage > 1) { - loadGfx = TRUE; - } - break; - case 0xF: - if (((struct_02000000*)0x2000000)->gameLanguage != 0) { - loadGfx = TRUE; - } - break; - default: - if (ctrl == ((struct_02000000*)0x2000000)->gameLanguage) { - loadGfx = TRUE; - } - break; - } - - if (loadGfx) { - gfxOffset = gfxItem->unk0.raw & 0xFFFFFF; - src = &gGlobalGfxAndPalettes[gfxOffset]; - dest = gfxItem->dest; - size = gfxItem->unk8; - dmaCtrl = 0x80000000; - if (size < 0) { - if (dest >= VRAM) { - LZ77UnCompVram(src, (void*)dest); - } else { - LZ77UnCompWram(src, (void*)dest); - } - } else { - DmaSet(3, src, dest, dmaCtrl | ((u32)size >> 1)); - } - } - - terminator = gfxItem->unk0.bytes.unk3; - terminator &= 0x80; - gfxItem++; - if (!terminator) { - break; - } - } -} diff --git a/src/code_080300AC.c b/src/code_080300AC.c index 12564596..993de6ee 100644 --- a/src/code_080300AC.c +++ b/src/code_080300AC.c @@ -1,9 +1,7 @@ #include "global.h" -#include "entity.h" +#include "utils.h" #include "functions.h" -// extern void DmaZero(void*, u32); - typedef struct { u16 unk0; u16 filler2[32]; @@ -13,13 +11,13 @@ typedef struct { extern struct_0300110C gUnk_0300110C; void sub_080300AC(void) { - MemClear32(&gUnk_0300110C.unk0, 0x44); + MemClear(&gUnk_0300110C.unk0, 0x44); gUnk_0300110C.unk66 = 0xff; } void sub_080300C4(void) { if (gScreenTransition.field_0xae == 0xff) { gScreenTransition.field_0xac = 0; - MemClear32(&gScreenTransition.field_0x4c[32], 0x40); + MemClear(&gScreenTransition.field_0x4c[32], 0x40); } } diff --git a/src/code_0804AA84.c b/src/code_0804AA84.c index 59485d74..cdc00c3f 100644 --- a/src/code_0804AA84.c +++ b/src/code_0804AA84.c @@ -2,6 +2,7 @@ #include "entity.h" #include "area.h" #include "main.h" +#include "utils.h" #include "functions.h" #include "screen.h" @@ -10,15 +11,13 @@ typedef struct { u32 unk; } struct_02018EB0; -extern void sub_0805E5A8(); - extern void (*const gUnk_080D4120[])(); extern void (*const gUnk_080D412C[])(); extern struct_02018EB0 gUnk_02018EB0; u32 sub_0804AA84(void) { - if (gArea.fadeOut != 0) { + if (gArea.playShrinkSeq) { gMain.transition = 4; gArea.filler[8] = 0; gArea.filler[9] = 0; @@ -26,8 +25,8 @@ u32 sub_0804AA84(void) { sub_0805E5A8(); return 1; } else { - gArea.filler[18] = gArea.fadeOut; - *(vu8*)&gArea.fadeOut = gArea.fadeOut; + gArea.filler[18] = gArea.playShrinkSeq; + *(vu8*)&gArea.playShrinkSeq = gArea.playShrinkSeq; return 0; } } @@ -37,10 +36,10 @@ void sub_0804AAB8(void) { } void sub_0804AAD4(void) { - MemClear32((void*)&gUnk_02018EB0, 0x28); + MemClear(&gUnk_02018EB0, 0x28); gUnk_02018EB0.unk = 0; EraseAllEntities(); - CreateObject(0x3d, gArea.field_0x17, 0); + CreateObject(0x3d, gArea.curPortalType, 0); gArea.filler[8]++; } diff --git a/src/code_0805436C.c b/src/code_0805436C.c index be879f99..2e12b6b0 100644 --- a/src/code_0805436C.c +++ b/src/code_0805436C.c @@ -1,5 +1,4 @@ #include "global.h" -#include "entity.h" #include "player.h" #include "room.h" #include "menu.h" @@ -133,7 +132,7 @@ u32 sub_080544C8(u32 arg0) { } } -u32 sub_080544DC(u32 arg0) { +u32 GetBottleContaining(u32 arg0) { if (arg0 == gSave.stats.bottles[0]) { return 1; } else if (arg0 == gSave.stats.bottles[1]) { diff --git a/src/code_0805F9A0.c b/src/code_0805F9A0.c index 33f037ad..66ac2ba9 100644 --- a/src/code_0805F9A0.c +++ b/src/code_0805F9A0.c @@ -1,6 +1,7 @@ #include "global.h" -#include "functions.h" +#include "utils.h" #include "structures.h" +#include "functions.h" extern u16 gUnk_081092D4; extern u8 gUnk_02036AD8; diff --git a/src/code_08077B98.c b/src/code_08077B98.c index c3fbf5dd..856dc44b 100644 --- a/src/code_08077B98.c +++ b/src/code_08077B98.c @@ -82,7 +82,7 @@ void* sub_08077C54(UnkItemStruct* unk) { Entity* sub_08077C94(ItemBehavior* arg0, u32 arg1) { Entity* iVar1; - iVar1 = FindEntityInListBySubtype(8, gUnk_0811BE48[arg1].unk[3], 2); + iVar1 = FindEntityByID(8, gUnk_0811BE48[arg1].unk[3], 2); if (iVar1 == NULL) { return NULL; } diff --git a/src/code_08077DF4.c b/src/code_08077DF4.c index 1697ecb0..c25aa18e 100644 --- a/src/code_08077DF4.c +++ b/src/code_08077DF4.c @@ -1,6 +1,7 @@ #include "global.h" #include "entity.h" #include "player.h" +#include "utils.h" #include "functions.h" typedef struct { @@ -35,7 +36,7 @@ void sub_08077E3C(Entity* ent, u32 idx) { void sub_08077E54(Entity* ent) { ent->action = gPlayerEntity.animIndex; *(u8*)&ent->spriteIndex = gPlayerEntity.frameIndex; - ent->previousActionFlag = gPlayerEntity.frameDuration; + ent->subAction = gPlayerEntity.frameDuration; ent->actionDelay = gPlayerEntity.frames.all; } @@ -57,7 +58,7 @@ void sub_08077E78(void* arg0, u32 bits) { not = ~not ; gPlayerState.field_0xa &= not ; gPlayerState.keepFacing &= not ; - MemClear32(arg0, 0x1c); + MemClear(arg0, 0x1c); } u32 sub_08077EC8(Unk_struct* arg0) { diff --git a/src/code_0808091C.c b/src/code_0808091C.c index 1916869c..0ea3dbcf 100644 --- a/src/code_0808091C.c +++ b/src/code_0808091C.c @@ -4,16 +4,13 @@ #include "functions.h" #include "room.h" -extern void sub_0805E5A8(); extern void sub_08080BC4(void); -extern RoomControls gRoomControls; extern u32 gUnk_0200B650; extern u32 gUnk_02025EB0; extern u8 gUnk_02000070; extern void DoExitTransition(ScreenTransitionData*); -extern void sub_080809D4(); void sub_080808D8(void) { gScreenTransition.transitionType = 0; diff --git a/src/trig.c b/src/coord.c index bb53c2fe..28dda7c6 100644 --- a/src/trig.c +++ b/src/coord.c @@ -1,7 +1,71 @@ #include "global.h" +#include "entity.h" +#include "coord.h" + +extern u8 gUnk_08114F78[]; +extern u8 gUnk_08114F80[]; + +s16 FixedMul(s16 r0, s16 r1) { + s32 temp = r0 * r1; + if (temp < 0) + return (temp + 255) >> 8; + else + return temp >> 8; +} + +s16 FixedDiv(s16 r0, s16 r1) { + if (r1 == 0) + return 0; + else + return (r0 * 256) / r1; +} + +void CopyPosition(Entity* param_1, Entity* param_2) { + PositionRelative(param_1, param_2, 0, 0); +} + +void PositionEntityOnTop(Entity* ent, Entity* ent2) { + PositionRelative(ent, ent2, 0, 0); + ResolveEntityOnTop(ent, ent2); +} + +void PositionRelative(Entity* source, Entity* target, s32 offsetX, s32 offsetY) { // r0, r1, r2, r3 + s32 x; + s32 y; + + x = source->x.WORD; + target->x.WORD = x + offsetX; + + y = source->y.WORD; + target->y.WORD = y + offsetY; + + target->height = source->height; // ldr + target->collisionLayer = source->collisionLayer; + UpdateSpriteForCollisionLayer(target); +} + +void CopyPositionAndSpriteOffset(Entity* param_1, Entity* param_2) { + param_2->spriteOffsetX = param_1->spriteOffsetX; + param_2->spriteOffsetY = param_1->spriteOffsetY; + PositionRelative(param_1, param_2, 0, 0); +} + +void sub_0806FA90(Entity* param_1, Entity* param_2, s32 offsetX, s32 offsetY) { + param_2->spriteOffsetX = param_1->spriteOffsetX; + param_2->spriteOffsetY = param_1->spriteOffsetY; + PositionRelative(param_1, param_2, offsetX * 64 * 32 * 32, offsetY * 64 * 32 * 32); +} + +void ResolveEntityOnTop(Entity* param_1, Entity* param_2) { + param_2->spritePriority.b0 = gUnk_08114F78[param_1->spritePriority.b0]; +} + +void sub_0806FAD8(Entity* param_1, Entity* param_2) { + param_2->spritePriority.b0 = gUnk_08114F80[param_1->spritePriority.b0]; +} // Values of sin(x*(Ï€/128)) as Q8.8 fixed-point numbers from x = 0 to x = 319 -const s16 gSineTable[] = { +const s16 gSineTable[64] = { Q_8_8(0), // sin(0*(Ï€/128)) Q_8_8(0.0234375), // sin(1*(Ï€/128)) Q_8_8(0.046875), // sin(2*(Ï€/128)) @@ -68,8 +132,7 @@ const s16 gSineTable[] = { Q_8_8(0.99609375), // sin(63*(Ï€/128)) }; -const s16 gCosineTable[] = { - +const s16 gCosineTable[256] = { Q_8_8(1), // sin(64*(Ï€/128)) Q_8_8(0.99609375), // sin(65*(Ï€/128)) Q_8_8(0.99609375), // sin(66*(Ï€/128)) diff --git a/src/createEnemy.c b/src/createEnemy.c index 5ce7af89..73eb5e5c 100644 --- a/src/createEnemy.c +++ b/src/createEnemy.c @@ -1,8 +1,5 @@ -#include "entity.h" #include "global.h" - -extern Entity* GetEmptyEntity(); -extern void AppendEntityToList(Entity*, u8); +#include "entity.h" Entity* CreateEnemy(u32 subtype, u32 form) { Entity* enemy; diff --git a/src/createEntity.c b/src/createEntity.c index e83312a1..9948a780 100644 --- a/src/createEntity.c +++ b/src/createEntity.c @@ -2,8 +2,8 @@ // #include "entityData.h" // #include "global.h" -// extern Entity * FindEntityBySubtype(u32, u32); -// extern Entity * GetEmptyEntityByType(); +// extern Entity * DeepFindEntityByID(u32, u32); +// extern Entity * GetEmptyEntityByKind(); // extern void RegisterRoomEntity(Entity *, EntityData *); // extern u32 sub_0804AF0C(Entity *, EntityData *); // extern void sub_08016A30(Entity *); @@ -17,11 +17,11 @@ // type = param_1->entityType & 15; // if (((param_1->field_0x1 & 240) == 80) && -// (preexisting = FindEntityBySubtype(type,param_1->entitySubtype), preexisting != NULL)) { +// (preexisting = DeepFindEntityByID(type,param_1->entitySubtype), preexisting != NULL)) { // entity = NULL; // } // else { -// entity = GetEmptyEntityByType(); //Get empty entity +// entity = GetEmptyEntityByKind(); //Get empty entity // if (entity != NULL) { // (entity->entityType).type = type; // (entity->entityType).subtype = param_1->entitySubtype; diff --git a/src/createNPC.c b/src/createNPC.c index b8a30fdf..7e57e92e 100644 --- a/src/createNPC.c +++ b/src/createNPC.c @@ -1,19 +1,16 @@ #include "global.h" #include "entity.h" -extern Entity* GetEmptyEntity(); -extern void AppendEntityToList(Entity*, u8); - Entity* CreateNPC(u32 subtype, u32 form, u32 parameter) { - Entity* pEVar1; + Entity* entity; - pEVar1 = GetEmptyEntity(); - if (pEVar1 != NULL) { - pEVar1->kind = 7; - pEVar1->id = subtype; - pEVar1->type = form; - pEVar1->type2 = parameter; - AppendEntityToList(pEVar1, 7); + entity = GetEmptyEntity(); + if (entity != NULL) { + entity->kind = 7; + entity->id = subtype; + entity->type = form; + entity->type2 = parameter; + AppendEntityToList(entity, 7); } - return pEVar1; + return entity; } diff --git a/src/createObject.c b/src/createObject.c index 62c67062..16f5df16 100644 --- a/src/createObject.c +++ b/src/createObject.c @@ -1,22 +1,21 @@ #include "global.h" #include "entity.h" +#include "coord.h" #include "room.h" - -extern Entity* GetEmptyEntity(); -extern void AppendEntityToList(Entity*, u8); +#include "createObject.h" Entity* CreateObject(u32 subtype, u32 form, u32 parameter) { - Entity* ent; - - ent = GetEmptyEntity(); - if (ent != NULL) { - ent->kind = 6; - ent->id = subtype; - ent->type = form; - ent->type2 = parameter; - AppendEntityToList(ent, 6); + Entity* entity; + + entity = GetEmptyEntity(); + if (entity != NULL) { + entity->kind = 6; + entity->id = subtype; + entity->type = form; + entity->type2 = parameter; + AppendEntityToList(entity, 6); } - return ent; + return entity; } Entity* CreateObjectWithParent(Entity* parentEnt, u32 subtype, u32 form, u32 parameter) { diff --git a/src/screenDebug.c b/src/debugScreen.c index 2271e2b7..bc034e8e 100644 --- a/src/screenDebug.c +++ b/src/debugScreen.c @@ -1,4 +1,5 @@ #include "global.h" +#include "utils.h" #include "functions.h" #include "main.h" #include "menu.h" @@ -6,13 +7,6 @@ #include "structures.h" #include "textbox.h" -typedef struct { - u16 unk0; - u16 unk2; - u16 unk4; -} VStruct; - -extern VStruct gInput; extern u8 gBG3Buffer[]; extern void (*const gUnk_08109A30[])(); @@ -22,9 +16,9 @@ void HandleDebugTextScreen() { } void sub_0805FA04(void) { - sub_0801DA90(1); - MemClear32((void*)&gBG0Buffer, sizeof(BGBuffer)); - MemClear32((void*)&gBG3Buffer, 0x1000); + DispReset(1); + MemClear(&gBG0Buffer, sizeof(BGBuffer)); + MemClear(&gBG3Buffer, 0x1000); gScreen.lcd.displayControl = 0x940; gScreen.bg.bg0xOffset = 0; gScreen.bg.bg0yOffset = 0; @@ -33,8 +27,8 @@ void sub_0805FA04(void) { gScreen.affine.bg3Control = 0x1e0f; gScreen.affine.bg3Updated = 1; MessageInitialize(); - MemClear32((void*)&gUnk_02032EC0, sizeof(UI)); - MemClear32((void*)&gMenu, sizeof(Menu)); + MemClear((void*)&gUnk_02032EC0, sizeof(UI)); + MemClear((void*)&gMenu, sizeof(Menu)); gMenu.unk16 = gUnk_02000000->gameLanguage; sub_08053320(); sub_0801D79C(0, 0x1144); @@ -46,7 +40,7 @@ void sub_0805FA04(void) { void sub_0805FA98(void) { int iVar1; - switch (gInput.unk2) { + switch (gInput.newKeys) { case 0x40: gMenu.focusCoords[1] -= 1; break; diff --git a/src/dma.c b/src/dma.c deleted file mode 100644 index 4c79f72e..00000000 --- a/src/dma.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "global.h" -#include "entity.h" - -void MemFill32(u32, u8*, u32); -void MemFill16(u32, u8*, u32); - -void MemFill16(u32 value, u8* dest, u32 size) { - DmaFill16(3, value, dest, size); -} - -void MemFill32(u32 value, u8* dest, u32 size) { - DmaFill32(3, value, dest, size); -} - -void MemClear32(u8* src, u32 size) { - u32 zero = 0; - - switch (((u32)src | size) & 3) { - case 0: - MemFill32(0, src, size); - break; - case 2: - MemFill16(0, src, size); - break; - default: - do { - *src = zero; - src++; - size--; - } while (size != 0); - } -} - -void MemCopy(const u8* src, u8* dst, u32 size) { - switch (((u32)src | (u32)dst | size) & 3) { - case 0: - DmaCopy32(3, src, dst, size); - break; - case 2: - DmaCopy16(3, src, dst, size); - break; - default: - do { - *dst = *src; - src++; - dst++; - } while (--size); - } -} diff --git a/src/enemy/acroBandits.c b/src/enemy/acroBandits.c index 2825aed5..8b3c977f 100644 --- a/src/enemy/acroBandits.c +++ b/src/enemy/acroBandits.c @@ -1,10 +1,10 @@ #include "global.h" #include "entity.h" +#include "random.h" #include "functions.h" extern u32 sub_080002D4(s32, s32, u32); extern s32 sub_080012DC(Entity*); -extern u32 sub_080044EC(Entity*, u32); extern u32 sub_08031E04(Entity*); extern void sub_08031E48(Entity*, Entity*); extern void sub_08032290(Entity*); @@ -12,10 +12,7 @@ extern u32 sub_080322A4(Entity*); void sub_080322E8(Entity*); extern void sub_08032338(Entity*); extern Entity* sub_08049DF4(u32); -extern void sub_0804AA30(Entity*, void (*const funcs[])(Entity*)); -extern u32 sub_0806FCB8(Entity*, u32, u32, u32); extern u32 GetNextFunction(Entity*); -extern void SetChildOffset(Entity*, s32, s32, s32); extern Entity* gUnk_020000B0; extern u8 gEntCount; @@ -62,8 +59,8 @@ void sub_080318DC(Entity* this) { do { brother->action = 5; brother->spritePriority.b1 = 1; - if (brother->hurtBlinkTime == 0) - brother->hurtBlinkTime = -12; + if (brother->iframes == 0) + brother->iframes = -12; } while (brother = brother->attachedEntity, brother != NULL); } if (this->parent) { @@ -113,7 +110,7 @@ void sub_080318DC(Entity* this) { } void sub_08031A60(Entity* this) { - if (this->hurtBlinkTime > 0) + if (this->iframes > 0) sub_08003FC4(this, 0x1800); sub_08001324(this); diff --git a/src/enemy/beetle.c b/src/enemy/beetle.c index 5ba78755..8ce4858b 100644 --- a/src/enemy/beetle.c +++ b/src/enemy/beetle.c @@ -1,6 +1,8 @@ #include "entity.h" -#include "functions.h" +#include "enemy.h" #include "player.h" +#include "random.h" +#include "functions.h" extern u32 PlayerInRange(Entity*, u32, u32); @@ -66,7 +68,7 @@ void sub_08021818(Entity* this) { void sub_08021848(Entity* this) { if (sub_0806F520(this)) { - gUnk_080CB5C8[this->previousActionFlag](this); + gUnk_080CB5C8[this->subAction](this); } else { this->action = 3; this->height.HALF.HI = 0; @@ -75,7 +77,7 @@ void sub_08021848(Entity* this) { } void sub_0802187C(Entity* this) { - this->previousActionFlag = 2; + this->subAction = 2; } void nullsub_130(Entity* this) { @@ -98,8 +100,8 @@ void sub_080218B4(Entity* this) { } void sub_080218CC(Entity* this) { - if (this->previousActionFlag == 0) { - this->previousActionFlag = 1; + if (this->subAction == 0) { + this->subAction = 1; this->spriteSettings.b.draw = 1; this->direction = ((sub_08049F84(this, 1) ^ 0x10) + gUnk_080CB5DC[Random() & 7]) & 0x1f; this->speed = 0x100; @@ -124,8 +126,8 @@ void sub_080218CC(Entity* this) { } void sub_08021984(Entity* this) { - if (this->previousActionFlag == 0) { - this->previousActionFlag = 1; + if (this->subAction == 0) { + this->subAction = 1; this->flags |= 0x80; this->spriteSettings.b.draw = 3; this->height.HALF.HI = -0x80; diff --git a/src/enemy/bladeTrap.c b/src/enemy/bladeTrap.c index 95d2d8d4..9f89f8f0 100644 --- a/src/enemy/bladeTrap.c +++ b/src/enemy/bladeTrap.c @@ -1,10 +1,9 @@ #include "global.h" #include "entity.h" #include "room.h" +#include "functions.h" extern void sub_080A2CC0(); -extern void sub_0806F69C(); -extern void EnqueueSFX(); void BladeTrap(Entity* this) { if (this->action == 0) { diff --git a/src/enemy/bobomb.c b/src/enemy/bobomb.c index d9c1a2a8..0e465090 100644 --- a/src/enemy/bobomb.c +++ b/src/enemy/bobomb.c @@ -1,7 +1,8 @@ #include "enemy.h" +#include "random.h" +#include "createObject.h" #include "functions.h" -extern void CreateDustSmall(Entity*); extern void sub_08078930(Entity*); extern void sub_08078954(Entity*); @@ -63,8 +64,8 @@ void sub_0802C688(Entity* this) { } void sub_0802C7AC(Entity* this) { - if (this->previousActionFlag < 3 && !sub_0806F520(this)) { - this->previousActionFlag = 0; + if (this->subAction < 3 && !sub_0806F520(this)) { + this->subAction = 0; this->field_0xf = 1; this->height.HALF.HI = 0; if (this->field_0x82.HALF.LO != 2) { @@ -75,7 +76,7 @@ void sub_0802C7AC(Entity* this) { this->field_0x80.HALF.HI = 0; } else { this->height.HALF.HI = -1; - gUnk_080CD600[this->previousActionFlag](this); + gUnk_080CD600[this->subAction](this); if (this->actionDelay != 0) { GetNextFrame(this); } @@ -83,7 +84,7 @@ void sub_0802C7AC(Entity* this) { } void sub_0802C820(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 60; } @@ -180,11 +181,11 @@ void sub_0802C91C(Entity* this) { } void sub_0802C9B8(Entity* this) { - gUnk_080CD618[this->previousActionFlag](this); + gUnk_080CD618[this->subAction](this); } void sub_0802C9D0(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->flags &= ~0x80; this->spritePriority.b1 = 0; this->field_0x82.HALF.HI = 1; @@ -255,7 +256,7 @@ void nullsub_150(Entity* this) { void sub_0802CB68(Entity* this) { this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->direction = Random() & 0x18; this->direction |= 4; this->flags |= 0x80; diff --git a/src/enemy/bombPeahat.c b/src/enemy/bombPeahat.c index 228855be..b57cfd81 100644 --- a/src/enemy/bombPeahat.c +++ b/src/enemy/bombPeahat.c @@ -1,17 +1,15 @@ #include "global.h" #include "entity.h" -#include "functions.h" #include "player.h" +#include "random.h" +#include "functions.h" extern void sub_08078954(Entity*); -extern u32 sub_0800442E(Entity*); extern void sub_08078930(Entity*); extern s32 sub_080012DC(Entity*); extern u32 GetNextFunction(Entity*); -extern void sub_0806F4E8(Entity*); extern Entity* sub_08049DF4(u32); extern void sub_08079BD8(Entity*); -extern u32 GetTileTypeByEntity(Entity*); void sub_0802AD1C(Entity*, u32); void sub_0802AD54(Entity*); @@ -70,11 +68,11 @@ void sub_0802A8AC(Entity* this) { } void sub_0802A8C8(Entity* this) { - gUnk_080CD140[this->previousActionFlag](this); + gUnk_080CD140[this->subAction](this); } void sub_0802A8E0(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 60; } @@ -102,7 +100,7 @@ void sub_0802A91C(Entity* this) { void sub_0802A924(Entity* this) { this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0; this->field_0xf = 0; this->hitbox = (Hitbox*)&gUnk_080CD16C; @@ -128,7 +126,7 @@ void sub_0802A9A8(Entity* this) { if (this->actionDelay) { if (--this->actionDelay == 0) { this->action = 2; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0x40; sub_0802ACDC(this, 8); } @@ -254,7 +252,7 @@ void sub_0802AB40(Entity* this) { void sub_0802AC08(Entity* this) { if (this->frames.all & 0x80) { this->action = 2; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0x40; this->speed = 0xc0; sub_0802ACDC(this, 8); @@ -386,7 +384,7 @@ void sub_0802AE68(Entity* this) { } void sub_0802AEBC(Entity* this) { - gUnk_080CD158[this->previousActionFlag](this); + gUnk_080CD158[this->subAction](this); } void sub_0802AED4(Entity* this) { @@ -407,7 +405,7 @@ void sub_0802AED4(Entity* this) { } void sub_0802AF28(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; sub_08079BD8(this); this->spritePriority.b1 = 2; GetNextFrame(this); @@ -424,7 +422,7 @@ void sub_0802AF58(Entity* this) { void sub_0802AF74(Entity* this) { this->action = 3; - this->previousActionFlag = 0; + this->subAction = 0; if (this->actionDelay > 60) { this->actionDelay = 60; } @@ -510,7 +508,7 @@ void sub_0802B048(Entity* this) { } else { if (this->field_0xf) { if (--this->field_0xf == 0) { - if (action == 2 && this->previousActionFlag == 1) { + if (action == 2 && this->subAction == 1) { gPlayerState.heldObject = 0; } sub_0805EC60(this); diff --git a/src/enemy/bowMoblin.c b/src/enemy/bowMoblin.c index e29d6177..893d7618 100644 --- a/src/enemy/bowMoblin.c +++ b/src/enemy/bowMoblin.c @@ -1,10 +1,8 @@ #include "global.h" #include "entity.h" +#include "enemy.h" +#include "functions.h" -extern void EnemyFunctionHandler(Entity*, void (*const funcs[])(Entity*)); -extern void SetChildOffset(Entity*, u32, u32, u32); -extern void sub_0804A9FC(Entity*, u32); -extern void sub_0804AA30(Entity*, void (*const funcs[][])(Entity*)); extern void sub_0803C5F0(Entity*); extern void (*const gUnk_080CFF78[])(Entity*); @@ -25,7 +23,7 @@ void sub_0803C198(Entity* this) { if (this->field_0x43 != 0) { sub_0804A9FC(this, 0x1c); } - sub_0804AA30(this, &gUnk_080CFF78); + sub_0804AA30(this, gUnk_080CFF78); if ((this->bitfield & 0x80) != 0) { sub_0803C5F0(this); pEVar1 = this->attachedEntity; diff --git a/src/enemy/businessScrub.c b/src/enemy/businessScrub.c index 49ba9ea1..30f0000e 100644 --- a/src/enemy/businessScrub.c +++ b/src/enemy/businessScrub.c @@ -1,9 +1,11 @@ #include "enemy.h" #include "entity.h" #include "flags.h" -#include "functions.h" #include "textbox.h" #include "save.h" +#include "random.h" +#include "npc.h" +#include "functions.h" extern void sub_0801D040(Entity*, u32); extern Entity* sub_08049DF4(u32); @@ -54,7 +56,7 @@ void sub_08028934(Entity* this) { if (this->damageType == 1 && (this->bitfield & 0x7f) == 0x42) { this->action = 3; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0x28; this->flags &= ~0x80; sub_080290E0(this, 4); @@ -97,7 +99,7 @@ void sub_08028A48(Entity* this) { this->actionDelay--; } else if (sub_08028F98(this, 0)) { sub_08029078(this); - this->previousActionFlag = 0; + this->subAction = 0; this->field_0xf = 1; } } @@ -106,11 +108,11 @@ void sub_08028A74(Entity* this) { u32 unk; GetNextFrame(this); - switch (this->previousActionFlag) { + switch (this->subAction) { case 0: unk = 1; if (this->frames.all & 0x80) { - this->previousActionFlag = 1; + this->subAction = 1; this->actionDelay = 0x3c; this->field_0xf = 0x10; sub_08028FDC(this); @@ -120,7 +122,7 @@ void sub_08028A74(Entity* this) { case 1: unk = 1; if (--this->actionDelay == 0) { - this->previousActionFlag = 2; + this->subAction = 2; this->actionDelay = 0x20; this->field_0xf = 0; sub_08028FDC(this); @@ -141,14 +143,14 @@ void sub_08028A74(Entity* this) { ent->parent = this; ent->direction = this->direction; this->frames.all &= ~1; - this->previousActionFlag = 3; + this->subAction = 3; } } break; case 3: unk = 2; if (this->frames.all & 0x80) { - this->previousActionFlag = 4; + this->subAction = 4; this->actionDelay = 0x50; sub_080290E0(this, 1); } @@ -157,13 +159,13 @@ void sub_08028A74(Entity* this) { unk = 2; if (--this->actionDelay == 0) { if (sub_08028F98(this, 0)) { - this->previousActionFlag = 1; + this->subAction = 1; this->actionDelay = 0x3c; this->field_0xf = 0x10; sub_08028FDC(this); } else { sub_08028FFC(this); - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0x50; this->field_0xf = 0; } @@ -174,7 +176,7 @@ void sub_08028A74(Entity* this) { if (!sub_08028F98(this, unk)) { sub_08028FFC(this); - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0x50; this->field_0xf = 0; } @@ -183,11 +185,11 @@ void sub_08028A74(Entity* this) { void sub_08028BC4(Entity* this) { Entity* iVar1; - switch (this->previousActionFlag) { + switch (this->subAction) { case 0: if (this->actionDelay == 0) { if (this->frames.all & 0x80) { - this->previousActionFlag = 1; + this->subAction = 1; sub_08028FDC(this); sub_080290E0(this, 5); this->spritePriority.b1 = 1; @@ -199,7 +201,7 @@ void sub_08028BC4(Entity* this) { case 1: if (this->frames.all & 0x80) { this->action = 4; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0x1e; this->field_0xf = 5; sub_080290E0(this, 0); @@ -314,7 +316,7 @@ void sub_08028E40(Entity* this) { struct SalesOffering* offer = (struct SalesOffering*)this->field_0x7c.WORD; this->action = 4; - this->previousActionFlag = gTextBox.doTextBox & 0x7f; + this->subAction = gTextBox.doTextBox & 0x7f; this->actionDelay = 1; if (CheckLocalFlag(offer->field_0xa) == 0) { SetLocalFlag(offer->field_0xa); @@ -326,7 +328,7 @@ void sub_08028E40(Entity* this) { } void sub_08028E84(Entity* this) { - if (UpdateFuseInteraction()) { + if (UpdateFuseInteraction(this)) { this->action = 4; this->actionDelay = 1; } diff --git a/src/enemy/chuchu.c b/src/enemy/chuchu.c index e8ee87d3..4f8d86d0 100644 --- a/src/enemy/chuchu.c +++ b/src/enemy/chuchu.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern s32 sub_080012DC(Entity*); diff --git a/src/enemy/chuchuBoss.c b/src/enemy/chuchuBoss.c index 674e8774..4127be53 100644 --- a/src/enemy/chuchuBoss.c +++ b/src/enemy/chuchuBoss.c @@ -2,8 +2,6 @@ #include "entity.h" #include "functions.h" -extern void sub_08078B48(void); - void sub_08027870(Entity*); extern void (*const gUnk_080CC19C[])(Entity*); @@ -36,13 +34,11 @@ void sub_08025CBC(Entity* this) { void sub_08025DC0(Entity*); void sub_08025CD4(Entity*); -void sub_08001242(Entity*); void sub_08025DD8(Entity*); void sub_08026060(Entity*); void sub_08026110(Entity*); void sub_080272D4(Entity*); void sub_0802720C(Entity*); -void sub_0802720C(Entity*); void sub_08026090(Entity*); void sub_0802626C(Entity*); void sub_08026580(Entity*); diff --git a/src/enemy/cuccoChickAggr.c b/src/enemy/cuccoChickAggr.c index e0f7a8f0..683ba4b8 100644 --- a/src/enemy/cuccoChickAggr.c +++ b/src/enemy/cuccoChickAggr.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern Entity* sub_08049DF4(u32); diff --git a/src/enemy/darkNut.c b/src/enemy/darkNut.c index 83fa7296..96585a58 100644 --- a/src/enemy/darkNut.c +++ b/src/enemy/darkNut.c @@ -1,4 +1,6 @@ #include "entity.h" +#include "enemy.h" +#include "random.h" #include "functions.h" typedef struct { @@ -241,7 +243,7 @@ void sub_08020FAC(Entity* this) { if (this->field_0x7a.HALF.LO) { this->field_0x7a.HALF.LO--; } else { - this->hurtBlinkTime = -8; + this->iframes = -8; sub_08021390(this); } } else { diff --git a/src/enemy/doorMimic.c b/src/enemy/doorMimic.c index 27357c08..2bfc1fc4 100644 --- a/src/enemy/doorMimic.c +++ b/src/enemy/doorMimic.c @@ -4,7 +4,7 @@ extern s16 sub_080001DA(u32, u32); // ? extern void sub_08049CF4(); -extern u32 sub_0806FBFC(u32, u32, u32, u32); +extern u32 CheckPlayerProximity(u32, u32, u32, u32); void sub_080221C0(); typedef struct { @@ -54,7 +54,7 @@ void sub_08022034(Entity* this) { void sub_0802209C(Entity* this) { if (this->actionDelay == 0) { - if (sub_0806FBFC(this->field_0x78.HWORD, this->field_0x7a.HWORD, 0x10, 0x10)) { + if (CheckPlayerProximity(this->field_0x78.HWORD, this->field_0x7a.HWORD, 0x10, 0x10)) { this->action = 2; this->actionDelay = 0x12; InitializeAnimation(this, this->type2 + 4); diff --git a/src/enemy/fallingBoulder.c b/src/enemy/fallingBoulder.c index 798f4939..29076b1c 100644 --- a/src/enemy/fallingBoulder.c +++ b/src/enemy/fallingBoulder.c @@ -1,4 +1,5 @@ #include "enemy.h" +#include "random.h" #include "functions.h" void sub_0802C4B0(Entity*); diff --git a/src/enemy/fireballGuy.c b/src/enemy/fireballGuy.c index e2d8914d..d551c54d 100644 --- a/src/enemy/fireballGuy.c +++ b/src/enemy/fireballGuy.c @@ -1,5 +1,7 @@ #include "global.h" #include "entity.h" +#include "enemy.h" +#include "random.h" #include "functions.h" typedef struct { @@ -79,7 +81,7 @@ void sub_08045454(Entity* this) { tmp = 0; ent->type2 = 1; ent->height.HALF.HI = tmp; - ent->hurtBlinkTime = -0x10; + ent->iframes = -0x10; /* Set MiniFireballGuy offset relative to killed slime. */ sub_08045178(this, ent, off->h, off->v); diff --git a/src/enemy/gibdo.c b/src/enemy/gibdo.c index f3228707..f9792c8a 100644 --- a/src/enemy/gibdo.c +++ b/src/enemy/gibdo.c @@ -1,8 +1,9 @@ #include "global.h" #include "entity.h" #include "sprite.h" -#include "functions.h" #include "enemy.h" +#include "random.h" +#include "functions.h" // Gibudo void sub_08037794(); void sub_08037B10(); @@ -337,12 +338,12 @@ NONMATCH("asm/non_matching/gibdo/sub_08037A58.inc", void sub_08037A58(Entity* th sub_08037ACC(this); this->action = 7; this->spritePriority.b0 = (this->spritePriority.b0 & 0xf8) | 4; - if (this->hurtBlinkTime == 0) { - this->hurtBlinkTime = 0xec; + if (this->iframes == 0) { + this->iframes = 0xec; } this->damageType = 0x26; this->flags2 |= 1; - this->hurtBlinkTime = 0xf4; + this->iframes = 0xf4; this->field_0x3e = (this->animationState << 3) ^ 0x10; this->field_0x42 = 8; this->field_0x46 = 0x180; @@ -354,7 +355,7 @@ END_NONMATCH void sub_08037ACC(Entity* this) { gPlayerState.flags.all &= 0xFFFFFEFF; gPlayerEntity.flags |= 0x80; - gPlayerEntity.hurtBlinkTime = 0x1e; + gPlayerEntity.iframes = 0x1e; gPlayerEntity.field_0x3e = DirectionFromAnimationState(this->animationState); gPlayerEntity.field_0x42 = 4; gPlayerEntity.field_0x46 = 0x180; @@ -362,7 +363,7 @@ void sub_08037ACC(Entity* this) { // Damage player maybe? void sub_08037B10(Entity* this) { u32 h; - gPlayerEntity.hurtBlinkTime = 0xc; + gPlayerEntity.iframes = 0xc; h = ModHealth(-8); sub_0800449C(&gPlayerEntity, 0x7a); if (h == 0) { diff --git a/src/enemy/gyorgMale.c b/src/enemy/gyorgMale.c index 1edbf4f9..4b73349a 100644 --- a/src/enemy/gyorgMale.c +++ b/src/enemy/gyorgMale.c @@ -2,10 +2,10 @@ #include "enemy.h" #include "player.h" #include "room.h" -#include "trig.h" -#include "structures.h" -#include "functions.h" +#include "coord.h" #include "fileScreen.h" +#include "random.h" +#include "functions.h" void (*const gUnk_080D1AFC[8])(Entity*); void (*const gUnk_080D1B1C[7])(Entity*); @@ -26,57 +26,56 @@ const u8 gUnk_080D1C44[0xC]; const u16 gUnk_080D1C50[8]; const u16 gUnk_080D1C60[8]; -void GyorgMale(Entity*); void sub_08046898(Entity*); // action 0 void sub_08046910(Entity*); // action 1 -void sub_08046930(Entity*); // action 1 previousActionFlag 0 -void sub_0804696C(Entity*); // action 1 previousActionFlag 1 -void sub_080469CC(Entity*); // action 1 previousActionFlag 2 -void sub_080469F4(Entity*); // action 1 previousActionFlag 3 -void sub_08046A30(Entity*); // action 1 previousActionFlag 4 -void sub_08046A54(Entity*); // action 1 previousActionFlag 5 -void sub_08046A78(Entity*); // action 1 previousActionFlag 6 +void sub_08046930(Entity*); // action 1 subAction 0 +void sub_0804696C(Entity*); // action 1 subAction 1 +void sub_080469CC(Entity*); // action 1 subAction 2 +void sub_080469F4(Entity*); // action 1 subAction 3 +void sub_08046A30(Entity*); // action 1 subAction 4 +void sub_08046A54(Entity*); // action 1 subAction 5 +void sub_08046A78(Entity*); // action 1 subAction 6 void sub_08046A9C(Entity*); // action 2 -void sub_08046AE8(Entity*); // action 2 previousActionFlag 0 -void sub_08046B18(Entity*); // action 2 previousActionFlag 1 -void sub_08046B8C(Entity*); // action 2 previousActionFlag 2 -void sub_08046C04(Entity*); // action 2 previousActionFlag 3 -void sub_08046C88(Entity*); // action 2 previousActionFlag 4 +void sub_08046AE8(Entity*); // action 2 subAction 0 +void sub_08046B18(Entity*); // action 2 subAction 1 +void sub_08046B8C(Entity*); // action 2 subAction 2 +void sub_08046C04(Entity*); // action 2 subAction 3 +void sub_08046C88(Entity*); // action 2 subAction 4 void sub_08046CEC(Entity*); // action 3 -void sub_08046D44(Entity*); // action 3 previousActionFlag 0 -void sub_08046D98(Entity*); // action 3 previousActionFlag 1 -void sub_08046E0C(Entity*); // action 3 previousActionFlag 2 -void sub_08046E68(Entity*); // action 3 previousActionFlag 3 -void sub_08046EF4(Entity*); // action 3 previousActionFlag 4 +void sub_08046D44(Entity*); // action 3 subAction 0 +void sub_08046D98(Entity*); // action 3 subAction 1 +void sub_08046E0C(Entity*); // action 3 subAction 2 +void sub_08046E68(Entity*); // action 3 subAction 3 +void sub_08046EF4(Entity*); // action 3 subAction 4 void sub_08046F64(Entity*); // action 4 -void sub_08046FE8(Entity*); // action 4 previousActionFlag 0 -void sub_0804702C(Entity*); // action 4 previousActionFlag 1 -void sub_080470B4(Entity*); // action 4 previousActionFlag 2 -void sub_08047140(Entity*); // action 4 previousActionFlag 3 -void sub_0804717C(Entity*); // action 4 previousActionFlag 4 -void sub_080471C8(Entity*); // action 4 previousActionFlag 5 -void sub_0804723C(Entity*); // action 4 previousActionFlag 6 -void sub_08047284(Entity*); // action 4 previousActionFlag 7 -void sub_080472BC(Entity*); // action 4 previousActionFlag 8 -void sub_08047310(Entity*); // action 4 previousActionFlag 9 +void sub_08046FE8(Entity*); // action 4 subAction 0 +void sub_0804702C(Entity*); // action 4 subAction 1 +void sub_080470B4(Entity*); // action 4 subAction 2 +void sub_08047140(Entity*); // action 4 subAction 3 +void sub_0804717C(Entity*); // action 4 subAction 4 +void sub_080471C8(Entity*); // action 4 subAction 5 +void sub_0804723C(Entity*); // action 4 subAction 6 +void sub_08047284(Entity*); // action 4 subAction 7 +void sub_080472BC(Entity*); // action 4 subAction 8 +void sub_08047310(Entity*); // action 4 subAction 9 void sub_0804736C(Entity*); // action 5 -void sub_080473B8(Entity*); // action 5 previousActionFlag 0 -void sub_080473F0(Entity*); // action 5 previousActionFlag 1 -void sub_08047484(Entity*); // action 5 previousActionFlag 2 -void sub_08047508(Entity*); // action 5 previousActionFlag 3 -void sub_080475F4(Entity*); // action 5 previousActionFlag 4 -void sub_0804763C(Entity*); // action 5 previousActionFlag 5 -void sub_0804772C(Entity*); // action 5 previousActionFlag 6 +void sub_080473B8(Entity*); // action 5 subAction 0 +void sub_080473F0(Entity*); // action 5 subAction 1 +void sub_08047484(Entity*); // action 5 subAction 2 +void sub_08047508(Entity*); // action 5 subAction 3 +void sub_080475F4(Entity*); // action 5 subAction 4 +void sub_0804763C(Entity*); // action 5 subAction 5 +void sub_0804772C(Entity*); // action 5 subAction 6 void sub_08047778(Entity*); // action 6 -void sub_08047798(Entity*); // action 6 previousActionFlag 0 -void sub_080477F0(Entity*); // action 6 previousActionFlag 1 -void sub_08047914(Entity*); // action 6 previousActionFlag 2 -void sub_08047978(Entity*); // action 6 previousActionFlag 3 -void sub_08047B08(Entity*); // action 6 previousActionFlag 4 +void sub_08047798(Entity*); // action 6 subAction 0 +void sub_080477F0(Entity*); // action 6 subAction 1 +void sub_08047914(Entity*); // action 6 subAction 2 +void sub_08047978(Entity*); // action 6 subAction 3 +void sub_08047B08(Entity*); // action 6 subAction 4 void sub_08047B84(Entity*); // action 7 -void sub_08047BA4(Entity*); // action 7 previousActionFlag 0 -void sub_08047BF0(Entity*); // action 7 previousActionFlag 1, also called elsewhere -void sub_08047D24(Entity*); // action 7 previousActionFlag 2 +void sub_08047BA4(Entity*); // action 7 subAction 0 +void sub_08047BF0(Entity*); // action 7 subAction 1, also called elsewhere +void sub_08047D24(Entity*); // action 7 subAction 2 void sub_08047D88(Entity*); // void sub_08047DF0(Entity*, u32); void sub_08047E48(Entity*); // @@ -118,7 +117,7 @@ void sub_08046898(Entity* this) { tmp->parent = this; this->attachedEntity = tmp; this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->spriteRendering.b0 = 3; this->spriteSettings.b.draw = 1; this->spriteOrientation.flipY = 2; @@ -136,20 +135,20 @@ void (*const gUnk_080D1B1C[7])(Entity*) = { sub_08046930, sub_0804696C, sub_0804 sub_08046A30, sub_08046A54, sub_08046A78 }; void sub_08046910(Entity* this) { - gUnk_080D1B1C[this->previousActionFlag](this); + gUnk_080D1B1C[this->subAction](this); UpdateAnimationSingleFrame(this); } void sub_08046930(Entity* this) { if (this->type) { - this->previousActionFlag = 5; + this->subAction = 5; this->direction = 0x20; this->speed = 0x280; } sub_08047D88(this); if (this->field_0x7c.BYTES.byte0 == 0) return; - this->previousActionFlag = 1; + this->subAction = 1; this->actionDelay = 1; this->animationState = 0; this->direction = 0; @@ -159,17 +158,17 @@ void sub_08046930(Entity* this) { void sub_0804696C(Entity* this) { sub_08047E48(this); if (gRoomControls.roomOriginY + 0x130 > this->y.HALF.HI) { - this->previousActionFlag = 2; + this->subAction = 2; this->direction = 0x80; this->speed = 0x100; this->spriteOrientation.flipY = 3; this->spriteRendering.b3 = 3; - SoundReq(0x2e); + SoundReq(BGM_BOSS_THEME); } if (this->actionDelay) { if (gRoomControls.roomOriginY + 0x258 > this->y.HALF.HI) { this->actionDelay = 0; - SoundReq(0xf7); + SoundReq(SFX_APPARATE); } } } @@ -177,7 +176,7 @@ void sub_0804696C(Entity* this) { void sub_080469CC(Entity* this) { sub_08047E48(this); if (gRoomControls.roomOriginY + 0x210 < this->y.HALF.HI) { - this->previousActionFlag = 3; + this->subAction = 3; this->direction = 0x90; } } @@ -185,7 +184,7 @@ void sub_080469CC(Entity* this) { void sub_080469F4(Entity* this) { sub_08047E48(this); if (gRoomControls.roomOriginY + 0x290 < this->y.HALF.HI) { - this->previousActionFlag = 4; + this->subAction = 4; this->spriteOrientation.flipY = 2; this->spriteRendering.b3 = 2; } @@ -195,14 +194,14 @@ void sub_08046A30(Entity* this) { sub_08047D88(this); if (((Entity*)this->myHeap)->prev->field_0x6c.HWORD & 1) { this->action = 2; - this->previousActionFlag = 0; + this->subAction = 0; } } void sub_08046A54(Entity* this) { sub_08047E48(this); if (gRoomControls.roomOriginX + 0x380 < this->x.HALF.HI) { - this->previousActionFlag = 6; + this->subAction = 6; } } @@ -210,7 +209,7 @@ void sub_08046A78(Entity* this) { sub_08047D88(this); if (((Entity*)this->myHeap)->prev->field_0x6c.HWORD & 0x10) { this->action = 3; - this->previousActionFlag = 0; + this->subAction = 0; } } @@ -222,16 +221,16 @@ void sub_08046A9C(Entity* this) { InitAnimationForceUpdate(this, 0); } } - gUnk_080D1B38[this->previousActionFlag](this); + gUnk_080D1B38[this->subAction](this); UpdateAnimationSingleFrame(this); if (this->field_0x7c.BYTES.byte0) { this->action = 6; - this->previousActionFlag = 0; + this->subAction = 0; } } void sub_08046AE8(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->speed = 0x180; sub_08048178(this, ((Entity*)this->myHeap)->next->animationState >> 5); this->field_0x76.HWORD = this->direction << 8; @@ -248,7 +247,7 @@ void sub_08046B18(Entity* this) { } this->direction = this->field_0x76.HWORD >> 8; } else { - this->previousActionFlag = 2; + this->subAction = 2; } sub_08047D88(this); sub_08047EA4(this, ((0x100 - this->direction) & 0xFF) << 8); @@ -256,7 +255,7 @@ void sub_08046B18(Entity* this) { void sub_08046B8C(Entity* this) { if (sub_0806FCB8(this, this->field_0x80.HWORD, this->field_0x82.HWORD, 4)) { - this->previousActionFlag = 3; + this->subAction = 3; this->field_0x76.HWORD = this->direction << 8; this->field_0x80.HWORD = gRoomControls.roomOriginX + 0x200; this->field_0x82.HWORD = gRoomControls.roomOriginY + 0x210; @@ -278,7 +277,7 @@ void sub_08046C04(Entity* this) { } this->direction = this->field_0x76.HWORD >> 8; } else { - this->previousActionFlag = 4; + this->subAction = 4; this->field_0x70.HALF.LO = ((tmp + 0x20) & 0xC0) >> 6; } sub_08047D88(this); @@ -287,7 +286,7 @@ void sub_08046C04(Entity* this) { void sub_08046C88(Entity* this) { if (sub_0806FCB8(this, this->field_0x80.HWORD, this->field_0x82.HWORD, 4)) { - this->previousActionFlag = 1; + this->subAction = 1; sub_08048178(this, sub_08048158(this->field_0x70.HALF_U.LO)); sub_08047D88(this); } else { @@ -305,11 +304,11 @@ void sub_08046CEC(Entity* this) { InitAnimationForceUpdate(this, 1); } } - gUnk_080D1B4C[this->previousActionFlag](this); + gUnk_080D1B4C[this->subAction](this); UpdateAnimationSingleFrame(this); if (((Entity*)this->myHeap)->prev->field_0x6c.HWORD & 2) { this->action = 2; - this->previousActionFlag = 0; + this->subAction = 0; this->animationState = this->speed; } } @@ -318,7 +317,7 @@ const u16 gUnk_080D1B60[8] = { 0x200, 0x184, 0x28C, 0x210, 0x200, 0x29C, 0x174, void sub_08046D44(Entity* this) { const u16* tmp; - this->previousActionFlag = 1; + this->subAction = 1; this->speed = 0x200; tmp = gUnk_080D1B60 + (((Entity*)this->myHeap)->next->animationState >> 5); this->field_0x80.HWORD = tmp[0] + gRoomControls.roomOriginX; @@ -337,7 +336,7 @@ void sub_08046D98(Entity* this) { } this->direction = this->field_0x76.HWORD >> 8; } else { - this->previousActionFlag = 2; + this->subAction = 2; } sub_08047D88(this); sub_08047EA4(this, ((0x100 - this->direction) & 0xFF) << 8); @@ -345,7 +344,7 @@ void sub_08046D98(Entity* this) { void sub_08046E0C(Entity* this) { if (sub_0806FCB8(this, this->field_0x80.HWORD, this->field_0x82.HWORD, 4)) { - this->previousActionFlag = 3; + this->subAction = 3; this->field_0x76.HWORD = this->direction << 8; sub_08047D88(this); } else { @@ -369,7 +368,7 @@ void sub_08046E68(Entity* this) { sub_08047D88(this); sub_08047EA4(this, ((0x100 - this->direction) & 0xFF) << 8); } else { - this->previousActionFlag = 4; + this->subAction = 4; this->actionDelay = 0x3F; this->field_0xf = 1; this->direction = (gUnk_080D1B70[Random() & 1] + tmp) & 0xC0; @@ -408,7 +407,7 @@ void sub_08046F64(Entity* this) { InitAnimationForceUpdate(this, 1); } } - gUnk_080D1B94[this->previousActionFlag](this); + gUnk_080D1B94[this->subAction](this); UpdateAnimationSingleFrame(this); if (--this->field_0x7c.HALF.HI == 0) { Entity* tmp; @@ -422,12 +421,12 @@ void sub_08046F64(Entity* this) { } if (((Entity*)this->myHeap)->prev->field_0x6c.HWORD & 4) { this->action = 5; - this->previousActionFlag = 0; + this->subAction = 0; } } void sub_08046FE8(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->speed = 0x1c0; this->field_0x7c.HALF.HI = 0x1e; this->field_0x80.HWORD = gRoomControls.roomOriginX + 0x290; @@ -446,7 +445,7 @@ void sub_0804702C(Entity* this) { } sub_08047DF0(this, ((0x100 - this->direction) & 0xFF) << 8); if (sub_0806FCB8(this, this->field_0x80.HWORD, this->field_0x82.HWORD, (this->speed >> 0x10) + 0x10)) { - this->previousActionFlag = 2; + this->subAction = 2; this->field_0x76.HWORD = this->direction << 8; this->speed = 0x280; } @@ -466,7 +465,7 @@ void sub_080470B4(Entity* this) { sub_08047D88(this); sub_08047EA4(this, ((0x100 - this->direction) & 0xFF) << 8); } else { - this->previousActionFlag = 3; + this->subAction = 3; this->speed = 0x200; this->field_0x76.HWORD = this->direction << 8; this->field_0x74.HWORD = gUnk_080D1BBC[Random() & 1]; @@ -479,7 +478,7 @@ void sub_08047140(Entity* this) { this->direction = this->field_0x76.HWORD >> 8; if (this->direction > 0xbf) { this->direction = 0xC0; - this->previousActionFlag = 4; + this->subAction = 4; } sub_08047DF0(this, ((0x100 - this->direction) & 0xFF) << 8); } @@ -490,7 +489,7 @@ void sub_0804717C(Entity* this) { } sub_08047DF0(this, ((0x100 - this->direction) & 0xFF) << 8); if (gRoomControls.roomOriginX + 0x200 > this->x.HALF.HI) { - this->previousActionFlag = 5; + this->subAction = 5; } } @@ -506,19 +505,19 @@ void sub_080471C8(Entity* this) { return; if (this->field_0x74.HWORD > 0x100) { if (Random() & 1) { - this->previousActionFlag = 6; + this->subAction = 6; } else { - this->previousActionFlag = 0; + this->subAction = 0; } } else { - this->previousActionFlag = 0; + this->subAction = 0; } } void sub_0804723C(Entity* this) { this->direction -= 2; if (this->direction < 0xc0) { - this->previousActionFlag = 7; + this->subAction = 7; this->speed = 0x200; this->direction = 0xc0; this->field_0x76.HWORD = 0xc000; @@ -532,7 +531,7 @@ void sub_08047284(Entity* this) { this->direction = this->field_0x76.HWORD >> 8; if (this->direction < 0x40) { this->direction = 0x40; - this->previousActionFlag = 8; + this->subAction = 8; } sub_08047DF0(this, ((0x100 - this->direction) & 0xFF) << 8); } @@ -544,7 +543,7 @@ void sub_080472BC(Entity* this) { sub_08047DF0(this, ((0x100 - this->direction) & 0xFF) << 8); if (gRoomControls.roomOriginX + 0x2B0 >= this->x.HALF.HI) return; - this->previousActionFlag = 9; + this->subAction = 9; this->field_0x76.HWORD = this->direction << 8; } @@ -556,7 +555,7 @@ void sub_08047310(Entity* this) { this->direction = this->field_0x76.HWORD >> 8; if ((u8)(this->direction + 0x7F) < 0x40) { this->direction = 0xC0; - this->previousActionFlag = 4; + this->subAction = 4; } sub_08047DF0(this, ((0x100 - this->direction) & 0xFF) << 8); } @@ -570,16 +569,16 @@ void sub_0804736C(Entity* this) { InitAnimationForceUpdate(this, 0); } } - gUnk_080D1BC0[this->previousActionFlag](this); + gUnk_080D1BC0[this->subAction](this); UpdateAnimationSingleFrame(this); if (this->currentHealth == 0) { this->action = 7; - this->previousActionFlag = 0; + this->subAction = 0; } } void sub_080473B8(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->speed = 0x120; this->field_0x80.HWORD = gRoomControls.roomOriginX + 0x200; this->field_0x82.HWORD = gRoomControls.roomOriginY + 0x1D0; @@ -606,7 +605,7 @@ void sub_080473F0(Entity* this) { } sub_08047DF0(this, ((0x100 - this->direction) & 0xFF) << 8); if (sub_0806FCB8(this, this->field_0x80.HWORD, this->field_0x82.HWORD, 8)) { - this->previousActionFlag = 2; + this->subAction = 2; this->field_0x76.HWORD = this->direction << 8; this->speed = 0x180; } @@ -624,7 +623,7 @@ void sub_08047484(Entity* this) { sub_08047D88(this); sub_08047EA4(this, ((0x100 - this->direction) & 0xFF) << 8); } else { - this->previousActionFlag = 3; + this->subAction = 3; this->speed = 0x200; this->direction = 0x40; this->field_0x76.HWORD = 0x4000; @@ -664,7 +663,7 @@ void sub_08047508(Entity* this) { } sub_08047E48(this); if (gRoomControls.roomOriginX + 0x280 < this->x.HALF.HI) { - this->previousActionFlag = 4; + this->subAction = 4; this->speed = 0x200; this->animationState = this->direction; this->field_0x76.HWORD = this->direction << 8; @@ -682,7 +681,7 @@ void sub_080475F4(Entity* this) { this->direction = this->field_0x76.HWORD >> 8; if (this->direction >= 0xc0) { this->direction = 0xc0; - this->previousActionFlag = 5; + this->subAction = 5; this->speed = 0x200; this->field_0x7c.HALF.HI = 0x3c; } @@ -719,7 +718,7 @@ void sub_0804763C(Entity* this) { } sub_08047E48(this); if (gRoomControls.roomOriginX + 0x180 > this->x.HALF.HI) { - this->previousActionFlag = 6; + this->subAction = 6; this->speed = 0x200; this->animationState = this->direction; this->field_0x76.HWORD = this->direction << 8; @@ -737,7 +736,7 @@ void sub_0804772C(Entity* this) { this->direction = this->field_0x76.HWORD >> 8; if (this->direction <= 0x40) { this->direction = 0x40; - this->previousActionFlag = 3; + this->subAction = 3; this->speed = 0x200; this->field_0x7c.HALF.HI = 0x1e; } @@ -747,12 +746,12 @@ void sub_0804772C(Entity* this) { void (*const gUnk_080D1BDC[5])(Entity*) = { sub_08047798, sub_080477F0, sub_08047914, sub_08047978, sub_08047B08 }; void sub_08047778(Entity* this) { - gUnk_080D1BDC[this->previousActionFlag](this); + gUnk_080D1BDC[this->subAction](this); UpdateAnimationSingleFrame(this); } void sub_08047798(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->speed = 0x80; if (this->x.HALF.HI - gRoomControls.roomOriginX < 0x1F8) { this->field_0x80.HWORD = 0xa8; @@ -774,7 +773,7 @@ void sub_080477F0(Entity* this) { sub_08047E48(this); if (!sub_0806FCB8(this, gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI, 0x80)) { this->action = 2; - this->previousActionFlag = 0; + this->subAction = 0; this->spriteOrientation.flipY = 2; this->spriteRendering.b3 = 2; this->direction = this->animationState; @@ -785,7 +784,7 @@ void sub_080477F0(Entity* this) { this->spriteRendering.b3 = 3; } if (sub_0806FCB8(this, this->field_0x80.HWORD, this->field_0x82.HWORD, 4)) { - this->previousActionFlag = 2; + this->subAction = 2; this->field_0x76.HWORD = this->animationState << 8; this->field_0x74.HWORD = gUnk_080D1BF0[Random() & 1]; if (((Entity*)this->myHeap)->prev->field_0x6c.HWORD & 1) { @@ -804,7 +803,7 @@ void sub_08047914(Entity* this) { this->animationState = this->field_0x76.HWORD >> 8; sub_08047EA4(this, ((0x100 - this->animationState) & 0xFF) << 8); } else { - this->previousActionFlag = 3; + this->subAction = 3; this->field_0x70.HALF.LO = 0x3C; this->field_0x7c.HALF.HI = ((this->type * 0xF) << 2) + 0x78; sub_080A1D70(((Entity*)this->myHeap)->prev, this->animationState); @@ -839,7 +838,7 @@ void sub_08047978(Entity* this) { } if (!sub_0806FCB8(this, gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI, 0x80)) { this->action = 2; - this->previousActionFlag = 0; + this->subAction = 0; this->spriteOrientation.flipY = 2; this->spriteRendering.b3 = 2; this->direction = this->animationState; @@ -848,7 +847,7 @@ void sub_08047978(Entity* this) { return; if (this->attachedEntity->action != 1) return; - this->previousActionFlag = 4; + this->subAction = 4; if (this->type == 0) { if ((((Entity*)this->myHeap)->next->animationState >> 6) == 1) { this->field_0x80.HWORD = gRoomControls.roomOriginX + 0x1C0; @@ -882,11 +881,11 @@ void sub_08047B08(Entity* this) { return; if (this->type == 0) { this->action = 7; - this->previousActionFlag = 0; + this->subAction = 0; this->direction ^= 0x80; } else { this->action = 4; - this->previousActionFlag = 0; + this->subAction = 0; this->spriteOrientation.flipY = 2; this->spriteRendering.b3 = 2; this->direction = this->animationState; @@ -896,12 +895,12 @@ void sub_08047B08(Entity* this) { void (*const gUnk_080D1BF4[3])(Entity*) = { sub_08047BA4, sub_08047BF0, sub_08047D24 }; void sub_08047B84(Entity* this) { - gUnk_080D1BF4[this->previousActionFlag](this); + gUnk_080D1BF4[this->subAction](this); UpdateAnimationSingleFrame(this); } void sub_08047BA4(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->actionDelay = 0x78; this->field_0xf = 0; if (gRoomControls.roomOriginX + 0x200 < this->x.HALF.HI) { @@ -937,7 +936,7 @@ void sub_08047BF0(Entity* this) { this->speed = 0x140; sub_08047E48(this); if (this->y.HALF.HI > gRoomControls.roomOriginY + 0x270) { - this->previousActionFlag = 2; + this->subAction = 2; this->field_0x7c.HALF.HI = 0xAA; SoundReq(0x12D); InitAnimationForceUpdate(this, 1); diff --git a/src/enemy/hangingSeed.c b/src/enemy/hangingSeed.c index fc09db31..fe6fe0fc 100644 --- a/src/enemy/hangingSeed.c +++ b/src/enemy/hangingSeed.c @@ -1,4 +1,5 @@ #include "entity.h" +#include "enemy.h" #include "functions.h" extern void (*const gHangingSeedFunctions[])(Entity*); diff --git a/src/enemy/helmasaur.c b/src/enemy/helmasaur.c index 723050a4..5d4302df 100644 --- a/src/enemy/helmasaur.c +++ b/src/enemy/helmasaur.c @@ -1,4 +1,5 @@ #include "enemy.h" +#include "random.h" #include "functions.h" extern void sub_08008796(Entity*, u32, u32, u32); @@ -62,16 +63,16 @@ void sub_0802BBC4(Entity* this) { void sub_0802BC20(Entity* this) { if (this->damageType != 0x19) { if (sub_0806F520(this)) { - gUnk_080CD42C[this->previousActionFlag](this); + gUnk_080CD42C[this->subAction](this); } - } else if (2 < this->previousActionFlag || sub_0806F520(this)) { - gUnk_080CD438[this->previousActionFlag](this); + } else if (2 < this->subAction || sub_0806F520(this)) { + gUnk_080CD438[this->subAction](this); } } void sub_0802BC74(Entity* this) { sub_0802C1C0(this); - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 60; this->animationState = (gPlayerEntity.animationState >> 1) ^ 2; InitializeAnimation(this, this->animationState); @@ -101,7 +102,7 @@ void sub_0802BCA8(Entity* this) { } void sub_0802BCFC(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 60; } @@ -259,7 +260,7 @@ void sub_0802BF78(Entity* this) { void sub_0802BF98(Entity* this) { if (sub_0806F520(this)) { - gUnk_080CD450[this->previousActionFlag](this); + gUnk_080CD450[this->subAction](this); } else { this->action = 2; this->actionDelay = 30; @@ -268,7 +269,7 @@ void sub_0802BF98(Entity* this) { } void sub_0802BFD0(Entity* this) { - this->previousActionFlag = 2; + this->subAction = 2; } void sub_0802BFD8(Entity* this) { diff --git a/src/enemy/keaton.c b/src/enemy/keaton.c index 453315d8..79e98065 100644 --- a/src/enemy/keaton.c +++ b/src/enemy/keaton.c @@ -1,5 +1,7 @@ #include "global.h" #include "entity.h" +#include "enemy.h" +#include "random.h" #include "functions.h" extern Entity* gUnk_020000B0; @@ -164,17 +166,17 @@ void sub_08032650(Entity* this) { sub_0803269C(this, this->direction); } -void sub_0803269C(Entity* this, u32 param_2) { +void sub_0803269C(Entity* this, u32 direction) { u32 uVar1; - if (((param_2 - 3) & 7) < 3) { - uVar1 = DirectionToAnimationState(param_2); + if (((direction - 3) & 7) < 3) { + uVar1 = DirectionToAnimationState(direction); if (((this->animationState - uVar1) & 3) > 1) { this->animationState = uVar1; InitAnimationForceUpdate(this, (this->animIndex & 0xFC) + uVar1); } } else { - uVar1 = DirectionToAnimationState(param_2); + uVar1 = DirectionToAnimationState(direction); if (uVar1 != this->animationState) { this->animationState = uVar1; InitAnimationForceUpdate(this, (this->animIndex & 0xFC) + uVar1); diff --git a/src/enemy/keese.c b/src/enemy/keese.c index 0462b254..26c1a938 100644 --- a/src/enemy/keese.c +++ b/src/enemy/keese.c @@ -2,19 +2,13 @@ #include "entity.h" #include "enemy.h" #include "player.h" +#include "random.h" #include "functions.h" extern void sub_08001328(Entity*); -extern u32 sub_0806F520(Entity*); -extern void sub_0806F4E8(Entity*); -extern u32 sub_0806F3E4(Entity*); -extern void sub_0804A7D4(Entity*); -extern void sub_0804A720(Entity*); extern void Keese_StartFly(Entity*); extern void sub_080AEFB4(Entity*); extern void sub_08021F24(Entity*); -extern u32 sub_08049FA0(Entity*); -extern u32 sub_08049EE4(Entity*); extern void (*const gKeeseFunctions[])(Entity*); extern void (*const gKeeseActions[])(Entity*); @@ -43,12 +37,12 @@ void sub_08021d98(Entity* this) { void sub_08021DA8(Entity* this) { if (sub_0806F520(this)) { - gUnk_080CB6C4[this->previousActionFlag](this); + gUnk_080CB6C4[this->subAction](this); } } void sub_08021DCC(Entity* this) { - this->previousActionFlag = 2; + this->subAction = 2; } void sub_08021DD4(Entity* this) { diff --git a/src/enemy/lakitu.c b/src/enemy/lakitu.c index 163ec9e1..cd9ce2b2 100644 --- a/src/enemy/lakitu.c +++ b/src/enemy/lakitu.c @@ -1,57 +1,13 @@ #include "global.h" #include "entity.h" +#include "enemy.h" #include "functions.h" -#include "trig.h" +#include "coord.h" #include "random.h" #include "player.h" extern void (*const LakituActionFuncs[])(Entity*); -// Lakitu -extern void EnemyFunctionHandler(Entity*, void (*const funcs[])(Entity*)); - -// sub_0803C784 -extern void sub_0804AA30(Entity*, void (*const funcs[])(Entity*)); - -// sub_0803C820 -extern u32 sub_0806F520(Entity*); - -// sub_0803C850 -extern void sub_0806F4E8(Entity*); - -// Lakitu_Initialize -extern void sub_0804A720(Entity*); - -// Lakitu_Cloudless -extern u32 sub_08003FC4(Entity*, u32); - -// sub_0803CA4C -extern u32 sub_080041A0(Entity*, Entity*, u32, u32); - -// sub_0803CAD0 -extern u32 sub_080AEFE0(Entity*); - -// Lakitu_SpawnLightning -void PositionRelative(Entity*, Entity*, s32, s32); -extern void EnqueueSFX(u32); - -// sub_0803CC08 -extern void DeleteEntity(Entity*); - -// Part of function tables -extern void sub_08001324(Entity*); -extern void sub_0804A7D4(Entity*); -extern void sub_08001242(Entity*); - -// Used in multiple functions -extern Entity* CreateFx(Entity*, u32, u32); -extern Entity* sub_0804A98C(Entity* positionEntity, u8 subtype, - u8 form); // Creates a projectile positioned at the given entity -extern void UpdateAnimationSingleFrame(Entity*); -extern void InitAnimationForceUpdate(Entity*, u32); -extern u32 sub_0806FCB8(Entity*, u32, u32, u32); -extern u32 GetFacingDirection(Entity*, Entity*); - // Forward references to functions in lakitu.c extern void sub_0803CAD0(Entity*); extern void sub_0803CBAC(Entity*); @@ -78,9 +34,6 @@ typedef struct { s8 y; } PACKED OffsetCoords; -// sub_0803CC08 -extern void DeleteEntity(Entity*); - // Variables extern void (*const gUnk_080D0110[])(Entity*); extern void (*const gUnk_080D0128[])(Entity*); @@ -140,12 +93,12 @@ void sub_0803C784(Entity* this) { void sub_0803C820(Entity* this) { if (sub_0806F520(this)) { - gUnk_080D0148[this->previousActionFlag](this); + gUnk_080D0148[this->subAction](this); } } void sub_0803C844(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 0x3c; } diff --git a/src/enemy/lakituCloud.c b/src/enemy/lakituCloud.c index 80679029..5ce140c5 100644 --- a/src/enemy/lakituCloud.c +++ b/src/enemy/lakituCloud.c @@ -1,25 +1,17 @@ #include "global.h" #include "entity.h" #include "player.h" +#include "functions.h" extern u32 GetNextFunction(Entity*); -extern void sub_0804A7D4(Entity*); -extern void sub_08001242(Entity*); - extern void (*const gUnk_080D0418[6])(Entity*); extern void (*const gUnk_080D0430[3])(Entity*); extern void (*const gUnk_080D043C[3])(Entity*); -extern bool32 sub_0806F3E4(Entity*); -extern bool32 sub_0806F520(Entity*); - extern void sub_0800449C(Entity*, u32); extern void sub_0803CE14(Entity*); extern void sub_0803CE3C(Entity*); -extern Entity* GetCurrentRoomProperty(u8); -extern void sub_0806F4E8(Entity*); -extern void sub_0806F69C(Entity*); extern void sub_08079D84(void); extern void sub_080A2CC0(Entity*, Entity**, u16*); @@ -38,16 +30,16 @@ void sub_0803CCEC(Entity* this) { void sub_0803CCFC(Entity* this) { if (sub_0806F520(this) == 0) { - if (this->previousActionFlag == 2) { + if (this->subAction == 2) { sub_0803CE3C(this); } } else { - gUnk_080D043C[this->previousActionFlag](this); + gUnk_080D043C[this->subAction](this); } } void sub_0803CD2C(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 0x3c; } diff --git a/src/enemy/leever.c b/src/enemy/leever.c index b40c63ca..d92e1d26 100644 --- a/src/enemy/leever.c +++ b/src/enemy/leever.c @@ -1,19 +1,14 @@ #include "global.h" #include "entity.h" #include "enemy.h" +#include "random.h" #include "functions.h" +#include "coord.h" -extern void SetChildOffset(Entity*, s32, s32, s32); -extern void sub_0804AA30(Entity*, void (*const func[])(Entity*)); -extern void sub_0804A7D4(Entity*); -extern Entity* CreateDeathFx(Entity*, u32, u32); -extern void sub_0804A720(Entity*); extern u32 sub_080002D4(s32, s32, u32); extern u32 sub_080002BC(s32, s32, u32); -extern u32 sub_08049FDC(Entity*, u32); extern Entity* gUnk_020000B0; -extern s16 gSineTable[]; bool32 Leever_PlayerInRange(Entity*, s32); void Leever_Move(Entity*); diff --git a/src/enemy/likeLike.c b/src/enemy/likeLike.c index 60a7b7b7..f04073d3 100644 --- a/src/enemy/likeLike.c +++ b/src/enemy/likeLike.c @@ -1,11 +1,12 @@ #include "enemy.h" #include "entity.h" -#include "functions.h" #include "textbox.h" #include "save.h" +#include "random.h" +#include "createObject.h" +#include "functions.h" extern bool32 sub_080544B4(u32); -extern void sub_0807CAA0(u32, u32); void sub_0802810C(Entity*); void sub_080281A0(Entity*); @@ -210,7 +211,7 @@ void sub_0802810C(Entity* this) { gPlayerState.flags.all &= 0xffffffef; gPlayerEntity.flags |= 0x80; gPlayerEntity.field_0x20 = 0x18000; - gPlayerEntity.hurtBlinkTime = -60; + gPlayerEntity.iframes = -60; gPlayerEntity.direction = gPlayerEntity.animationState << 2; gPlayerEntity.spritePriority.b1 = this->field_0x82.HALF.HI; gPlayerEntity.height.HALF.HI = gPlayerEntity.spriteOffsetY; @@ -219,8 +220,8 @@ void sub_0802810C(Entity* this) { this->actionDelay = 0x50; this->field_0xf = 0; this->flags2 |= 2; - if (this->hurtBlinkTime == 0) { - this->hurtBlinkTime = -18; + if (this->iframes == 0) { + this->iframes = -18; } } #else diff --git a/src/enemy/madderpillar.c b/src/enemy/madderpillar.c index 9c2d526f..0679a87d 100644 --- a/src/enemy/madderpillar.c +++ b/src/enemy/madderpillar.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern u8 gEntCount; @@ -460,12 +461,12 @@ void sub_0802A098(Entity* this) { void sub_0802A0F8(Entity* this) { if (this->currentHealth != 0) { - if ((this->bitfield & 0x80) && this->hurtBlinkTime != 0) { + if ((this->bitfield & 0x80) && this->iframes != 0) { Entity* ent = this; u32 i; for (i = 0; i < 6; i++) { ent = ent->attachedEntity; - ent->hurtBlinkTime = this->hurtBlinkTime; + ent->iframes = this->iframes; } } } else { diff --git a/src/enemy/miniFireballGuy.c b/src/enemy/miniFireballGuy.c index 24f7e210..3210aeeb 100644 --- a/src/enemy/miniFireballGuy.c +++ b/src/enemy/miniFireballGuy.c @@ -1,11 +1,9 @@ #include "global.h" #include "entity.h" +#include "enemy.h" +#include "random.h" #include "functions.h" -extern void EnemyFunctionHandler(Entity*, void (*const func[])(Entity*)); -extern void sub_0804A7D4(Entity*); -extern void sub_0804A720(Entity*); -extern void sub_08045678(Entity*); extern void sub_08045678(Entity*); extern void (*const gUnk_080D1868[])(Entity*); diff --git a/src/enemy/miniSlime.c b/src/enemy/miniSlime.c index 96e7d615..68c1303a 100644 --- a/src/enemy/miniSlime.c +++ b/src/enemy/miniSlime.c @@ -1,16 +1,13 @@ #include "global.h" #include "entity.h" -#include "room.h" +#include "enemy.h" +#include "random.h" #include "functions.h" void sub_08045374(Entity*); -extern u32 sub_0806FA04(u32, u32); -extern void sub_0804A720(); extern void sub_080452E4(); -extern void sub_0804AA30(); extern void ReplaceMonitoredEntity(Entity*, Entity*); -extern void sub_0804A7D4(Entity*); extern void (*const gUnk_080D17C0[])(Entity*); extern void (*const gUnk_080D17D8[])(Entity*); @@ -72,7 +69,7 @@ void sub_080452FC(Entity* this) { this->action = 3; this->actionDelay = 1; if (0 < this->speed) - this->actionDelay = sub_0806FA04(0x1000, this->speed) >> 0x8; + this->actionDelay = FixedDiv(0x1000, this->speed) >> 0x8; if (sub_08049FA0(this) == 0 && (Random() & 3)) { cVar2 = sub_08049EE4(this); diff --git a/src/enemy/moldorm.c b/src/enemy/moldorm.c index 186bee30..f7ed8161 100644 --- a/src/enemy/moldorm.c +++ b/src/enemy/moldorm.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" void sub_08022EAC(Entity*); @@ -40,9 +41,9 @@ void sub_08022BEC(Entity* this) { this->animationState = ((this->direction + 2) & 0x1c) >> 2; this->frameIndex = this->animationState; - this->attachedEntity->hurtBlinkTime = this->hurtBlinkTime; - (*(Entity**)&this->field_0x7c)->hurtBlinkTime = this->hurtBlinkTime; - (*(Entity**)&this->field_0x80)->hurtBlinkTime = this->hurtBlinkTime; + this->attachedEntity->iframes = this->iframes; + (*(Entity**)&this->field_0x7c)->iframes = this->iframes; + (*(Entity**)&this->field_0x80)->iframes = this->iframes; sub_0804AA30(this, gUnk_080CBBA0); } diff --git a/src/enemy/moldworm.c b/src/enemy/moldworm.c index 3bf68715..11d5166e 100644 --- a/src/enemy/moldworm.c +++ b/src/enemy/moldworm.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern void sub_0800449C(Entity*, u32); @@ -67,12 +68,12 @@ void sub_080230CC(Entity* this) { } void sub_080230E4(Entity* this) { - if (this->previousActionFlag == 0xff) { + if (this->subAction == 0xff) { this->action = 7; this->actionDelay = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->damageType = 0x85; - this->hurtBlinkTime = -8; + this->iframes = -8; this->field_0x7c.BYTES.byte3 = 0; this->field_0x7a.HALF.HI = 0; if (this->bitfield == 0x80 || this->bitfield == 0x9e) { @@ -90,7 +91,7 @@ void sub_080230E4(Entity* this) { gPlayerEntity.spriteSettings.b.draw = 1; gPlayerEntity.field_0x20 = 0x18000; gPlayerEntity.direction = 0xff; - gPlayerEntity.hurtBlinkTime = -0x14; + gPlayerEntity.iframes = -0x14; gPlayerState.jumpStatus = 0x41; gPlayerState.flags.all &= 0xfff7ffff; } @@ -410,7 +411,7 @@ void sub_08023894(Entity* this) { gPlayerEntity.y.HALF.HI = this->y.HALF.HI; gPlayerEntity.direction = DirectionRoundUp(GetFacingDirection(*(Entity**)&this->field_0x74, this)); gPlayerEntity.animationState = gPlayerEntity.direction >> 2; - gPlayerEntity.hurtBlinkTime = 12; + gPlayerEntity.iframes = 12; ModHealth(-0x10); sub_0800449C(&gPlayerEntity, 0x7a); } @@ -421,7 +422,7 @@ void sub_0802390C(Entity* this) { if (this->bitfield & 0x80) { Entity* ent = this->attachedEntity; do { - ent->hurtBlinkTime = this->hurtBlinkTime; + ent->iframes = this->iframes; } while (ent = ent->attachedEntity, ent != NULL); } else { Entity* ent = this->attachedEntity; @@ -431,7 +432,7 @@ void sub_0802390C(Entity* this) { if (bVar2 != 0) { u32 tmp; ent->currentHealth = 0xff; - tmp = (u8)ent->hurtBlinkTime; + tmp = (u8)ent->iframes; if (this->currentHealth >= bVar2) { this->currentHealth -= bVar2; } else { @@ -440,7 +441,7 @@ void sub_0802390C(Entity* this) { ent = this; do { - ent->hurtBlinkTime = tmp; + ent->iframes = tmp; } while (ent = ent->attachedEntity, ent != NULL); break; } diff --git a/src/enemy/octorok.c b/src/enemy/octorok.c index d89e4e65..565ed259 100644 --- a/src/enemy/octorok.c +++ b/src/enemy/octorok.c @@ -1,15 +1,9 @@ #include "global.h" #include "entity.h" +#include "enemy.h" +#include "random.h" #include "functions.h" -extern void EnemyFunctionHandler(); -extern void SetChildOffset(); -extern void sub_0804AA30(); -extern void sub_0804A7D4(); -extern u32 sub_0806F520(); -extern void sub_0806F4E8(); -extern void UpdateAnimationVariableFrames(); -extern void sub_0804A720(); extern Entity* sub_08049DF4(u32); void Octorok_Pause(); @@ -55,16 +49,16 @@ void sub_0801EB0C(Entity* this) { } void sub_0801EB2C(Entity* this) { - if (this->previousActionFlag < 3 && !sub_0806F520(this)) { + if (this->subAction < 3 && !sub_0806F520(this)) { Octorok_Pause(this); InitializeAnimation(this, this->animationState); } else { - gUnk_080CA158[this->previousActionFlag](this); + gUnk_080CA158[this->subAction](this); } } void sub_0801EB68(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 60; } diff --git a/src/enemy/peahat.c b/src/enemy/peahat.c index 07fd3f5a..5c134ed8 100644 --- a/src/enemy/peahat.c +++ b/src/enemy/peahat.c @@ -1,4 +1,6 @@ #include "entity.h" +#include "enemy.h" +#include "random.h" #include "functions.h" extern void (*const gPeahatFunctions[])(Entity*); @@ -58,14 +60,14 @@ void sub_0801FFDC(Entity* this) { this->animationState = PeahatAnimation_SlicedPropeller; this->action = 5; this->speed = 0x80; - this->hurtBlinkTime = -30; + this->iframes = -30; this->field_0x80.HALF.HI = 0; InitializeAnimation(this, this->animationState); } else if (this->bitfield == 0x9b) { this->animationState = PeahatAnimation_BrokenPropeller; this->action = 5; this->speed = 0x80; - this->hurtBlinkTime = -30; + this->iframes = -30; this->field_0x80.HALF.HI = 0; InitializeAnimation(this, this->animationState); } else if (this->bitfield == 0x80) { @@ -87,14 +89,14 @@ void sub_0801FFDC(Entity* this) { } void sub_08020088(Entity* this) { - if (2 >= this->previousActionFlag && !sub_0806F520(this)) + if (2 >= this->subAction && !sub_0806F520(this)) return; - gUnk_080CA5BC[this->previousActionFlag](this); + gUnk_080CA5BC[this->subAction](this); } void sub_080200B4(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 60; if (this->animationState == PeahatAnimation_Flying) { this->animationState = PeahatAnimation_BrokenPropeller; @@ -150,7 +152,7 @@ void Peahat_Fly(Entity* this) { if (sub_08049FDC(this, 1)) { if (this->field_0x82.HALF.HI == 0 && (this->field_0xf & 0xf) == 0 && sub_08049F1C(this, gUnk_020000B0, 0x30)) { this->action = 2; - this->previousActionFlag = Random() & 3; + this->subAction = Random() & 3; this->actionDelay = 60; this->speed = 160; } diff --git a/src/enemy/pesto.c b/src/enemy/pesto.c index a8d24fa2..3eeda562 100644 --- a/src/enemy/pesto.c +++ b/src/enemy/pesto.c @@ -1,15 +1,16 @@ #include "enemy.h" #include "entity.h" +#include "random.h" +#include "createObject.h" +#include "game.h" #include "functions.h" extern u32 sub_080002E0(u16, u32); -extern u32 CheckIsDungeon(void); extern void sub_0800449C(Entity*, u32); extern u32 sub_08049F1C(Entity*, Entity*, u32); -extern void sub_0804AA30(Entity*, void (*const funcs[])(Entity*)); extern u32 PlayerInRange(Entity*, u32, u32); extern void sub_080AEFB4(Entity*); -extern Entity* FindNextEntityOfSameSubtype(Entity* ent, int listIndex); +extern Entity* FindNextDuplicateID(Entity* ent, int listIndex); void sub_080249F4(Entity*); void sub_08024940(Entity*); @@ -78,20 +79,20 @@ void sub_08023FE0(Entity* this) { } void sub_08023FF0(Entity* this) { - if (this->previousActionFlag < 3 && !sub_0806F520(this)) { + if (this->subAction < 3 && !sub_0806F520(this)) { this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->flags |= 0x80; this->damageType = 0x77; this->actionDelay = 1; this->speed = 0x40; } else { - gUnk_080CBEF8[this->previousActionFlag](this); + gUnk_080CBEF8[this->subAction](this); } } void sub_08024038(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 60; GetNextFrame(this); } @@ -129,7 +130,7 @@ void sub_080240B8(Entity* this) { u32 direction = (Random() & 0xc0) >> 3; sub_0804A720(this); this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->field_0x80.HALF.LO = 0; if (direction & 8) { this->y.HALF.HI += (direction & 0x10) ? -0x20 : 0x20; @@ -665,7 +666,7 @@ bool32 sub_08024B38(Entity* this) { } } - ent = FindEntityInListBySubtype(8, 2, 2); + ent = FindEntityByID(8, 2, 2); if (ent) { do { if (ent->action != 2 && ent->height.HALF.HI == 0 && sub_08049F1C(this, ent, 0xa0)) { @@ -675,14 +676,14 @@ bool32 sub_08024B38(Entity* this) { this->field_0x82.HALF.HI &= ~0x40; break; } - } while (ent = FindNextEntityOfSameSubtype(ent, 2), ent != NULL); + } while (ent = FindNextDuplicateID(ent, 2), ent != NULL); } if (iVar4 != 0) { return iVar4; } - ent = FindEntityInListBySubtype(6, 5, 6); + ent = FindEntityByID(6, 5, 6); if (ent) { do { if (ent->action == 1 && sub_08049F1C(this, ent, 0xa0)) { @@ -692,7 +693,7 @@ bool32 sub_08024B38(Entity* this) { this->field_0x82.HALF.HI &= ~0x40; break; } - } while (ent = FindNextEntityOfSameSubtype(ent, 6), ent != NULL); + } while (ent = FindNextDuplicateID(ent, 6), ent != NULL); } if (iVar4 == 0) { @@ -829,7 +830,7 @@ void sub_08024E4C(Entity* this) { player->spritePriority.b1 = 0; if (this->field_0xf == 0) { (this->field_0x86.HALF.HI++; - player->hurtBlinkTime = 8; + player->iframes = 8; ModHealth(-2); sub_0800449C(player, 0x7a); } @@ -849,7 +850,7 @@ void sub_08024F50(Entity* this) { CopyPosition(this, &gPlayerEntity); gPlayerEntity.action = 1; gPlayerEntity.flags |= 0x80; - gPlayerEntity.hurtBlinkTime = -0x3c; + gPlayerEntity.iframes = -0x3c; gPlayerEntity.direction = gPlayerEntity.animationState << 2; gPlayerEntity.speed = 0; gPlayerEntity.spritePriority.b1 = this->cutsceneBeh.HALF.HI; diff --git a/src/enemy/puffstool.c b/src/enemy/puffstool.c index 08908191..4a47b4b7 100644 --- a/src/enemy/puffstool.c +++ b/src/enemy/puffstool.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern u32 sub_080002E0(u32, u32); @@ -8,7 +9,6 @@ extern u16 sub_080002A8(u32, u32, u32); extern u16 sub_080002D4(u32, u32, u32); extern void sub_0804AA1C(Entity*); extern Entity* sub_08049DF4(u32); -extern void sub_0807B7D8(u32, u32, u32); extern u8 gUnk_080B37A0[]; extern u8 gUnk_080B3E80[]; @@ -74,7 +74,7 @@ void sub_08025020(Entity* this) { if (0 < this->field_0x20) { this->field_0x20 = 0; } - this->hurtBlinkTime = -0xc; + this->iframes = -0xc; this->field_0x42 = 0; if (this->field_0x80.HALF.LO == 0) { this->animationState = (*(Entity**)&this->field_0x4c)->direction >> 3; @@ -84,7 +84,7 @@ void sub_08025020(Entity* this) { } break; default: - if (this->damageType == 0x82 && this->hurtBlinkTime < 0) { + if (this->damageType == 0x82 && this->iframes < 0) { Entity* ent = CreateObject(0x21, 2, 0); if (ent != NULL) { ent->spritePriority.b0 = 3; @@ -108,14 +108,14 @@ void sub_0802511C(Entity* this) { void sub_0802514C(Entity* this) { sub_08003FC4(this, 0x2000); if (sub_0806F520(this)) { - gUnk_080CBFEC[this->previousActionFlag](this); + gUnk_080CBFEC[this->subAction](this); } else { sub_08025C2C(this); } } void sub_08025180(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->actionDelay = Random(); this->animationState = (((*(Entity**)&this->field_0x4c)->direction ^ 0x10) >> 3); InitializeAnimation(this, this->animationState + 4); diff --git a/src/enemy/rockChuchu.c b/src/enemy/rockChuchu.c index 01a0c9c7..977257bd 100644 --- a/src/enemy/rockChuchu.c +++ b/src/enemy/rockChuchu.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern void sub_0804A4E4(Entity*, Entity*); @@ -43,7 +44,7 @@ void sub_08022254(Entity* this) { ent = CreateEnemy(1, 1); if (ent) { ent->type2 = 1; - ent->hurtBlinkTime = -8; + ent->iframes = -8; sub_0804A4E4(this, ent); this->action = 2; this->flags &= ~0x80; @@ -96,7 +97,7 @@ void sub_080223E4(Entity* this) { ent = this->attachedEntity; if (ent) { ent->bitfield = 0x94; - ent->hurtBlinkTime = 0x10; + ent->iframes = 0x10; ent->field_0x42 = 0xc; ent->field_0x3e = this->direction; } diff --git a/src/enemy/rollobite.c b/src/enemy/rollobite.c index 263b5625..0e6ee1bb 100644 --- a/src/enemy/rollobite.c +++ b/src/enemy/rollobite.c @@ -1,4 +1,6 @@ #include "entity.h" +#include "enemy.h" +#include "random.h" #include "functions.h" extern void (*const gRollobiteFunctions[])(Entity*); @@ -63,18 +65,18 @@ void sub_080206E0(Entity* this) { } void sub_08020734(Entity* this) { - if (this->previousActionFlag < 3 && !sub_0806F520(this)) { + if (this->subAction < 3 && !sub_0806F520(this)) { this->action = 4; this->flags |= 0x80; this->direction = 0xff; InitializeAnimation(this, this->animationState + 0x10); } else { - gUnk_080CA6A4[this->previousActionFlag](this); + gUnk_080CA6A4[this->subAction](this); } } void sub_0802077C(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 60; } @@ -132,11 +134,11 @@ void Rollobite_Walk(Entity* this) { } void sub_08020874(Entity* this) { - gUnk_080CA6BC[this->previousActionFlag](this); + gUnk_080CA6BC[this->subAction](this); } void sub_0802088C(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->flags &= ~0x80; this->cutsceneBeh.HALF.HI = gPlayerEntity.animationState; this->spritePriority.b1 = 0; diff --git a/src/enemy/rope.c b/src/enemy/rope.c index d1d73723..0859bae6 100644 --- a/src/enemy/rope.c +++ b/src/enemy/rope.c @@ -1,8 +1,8 @@ #include "global.h" #include "entity.h" -#include "sprite.h" -#include "functions.h" #include "enemy.h" +#include "random.h" +#include "functions.h" extern void (*const gRope[6])(Entity*); extern void (*const gUnk_080CE460[4])(Entity*); @@ -36,12 +36,12 @@ void sub_080313AC(Entity* this) { void sub_080313E8(Entity* this) { if (sub_0806F520()) { - gUnk_080CE470[this->previousActionFlag](this); + gUnk_080CE470[this->subAction](this); } } void sub_0803140C(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 0x3c; } @@ -65,7 +65,7 @@ void sub_08031434(Entity* this) { sub_08031600(this); } else { this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->spriteSettings.b.draw = (this->spriteSettings.b.draw & 0xfc); this->height.HALF.HI = -0x80; this->frameIndex = 0xff; @@ -73,13 +73,13 @@ void sub_08031434(Entity* this) { } void sub_08031480(Entity* this) { - if (this->previousActionFlag == 0) { + if (this->subAction == 0) { if (this->actionDelay != 0) { this->actionDelay--; } else { sub_08031600(this); this->action = 1; - this->previousActionFlag = 1; + this->subAction = 1; this->spriteSettings.b.draw = 3; this->spriteRendering.b3 = 1; this->spriteOrientation.flipY = 1; diff --git a/src/enemy/rupeeLike.c b/src/enemy/rupeeLike.c index 64584892..10984c27 100644 --- a/src/enemy/rupeeLike.c +++ b/src/enemy/rupeeLike.c @@ -1,11 +1,11 @@ #include "global.h" #include "entity.h" #include "enemy.h" -#include "functions.h" #include "npc.h" -#include "structures.h" #include "player.h" #include "save.h" +#include "createObject.h" +#include "functions.h" extern void sub_080293DC(Entity*); extern void sub_080296D8(Entity*); @@ -234,7 +234,7 @@ void sub_080296D8(Entity* this) { gPlayerState.flags.all &= 0xffffffef; gPlayerEntity.flags |= 0x80; gPlayerEntity.field_0x20 = 0x18000; - gPlayerEntity.hurtBlinkTime = 0xa6; + gPlayerEntity.iframes = 0xa6; gPlayerEntity.height.HALF.HI = -2; gPlayerEntity.direction = gPlayerEntity.animationState << 2; gPlayerEntity.spritePriority.b1 = this->field_0x80.HALF.LO; @@ -243,8 +243,8 @@ void sub_080296D8(Entity* this) { this->action = 5; this->field_0xf = 0x3c; this->flags2 |= 3; - if ((s8)this->hurtBlinkTime == 0) { - this->hurtBlinkTime = 0xf4; + if ((s8)this->iframes == 0) { + this->iframes = 0xf4; } } diff --git a/src/enemy/slime.c b/src/enemy/slime.c index 9609232d..fc7714e3 100644 --- a/src/enemy/slime.c +++ b/src/enemy/slime.c @@ -1,25 +1,17 @@ #include "global.h" #include "entity.h" +#include "enemy.h" #include "room.h" +#include "random.h" #include "functions.h" typedef struct { - void* field_0x0; - void* entityCount; - u8 freezeTime; -} EntityHandler; - -typedef struct { s8 h, v; } PACKED PosOffset; void sub_08044FF8(Entity*); void sub_08045178(Entity*, Entity*, int, int); -extern void sub_0804A720(Entity*); -extern u32 sub_0806FA04(u32, u32); -extern u32 sub_08049FA0(Entity*); -extern u32 sub_08049EE4(Entity*); extern void sub_0804A4E4(Entity*, Entity*); extern u32 sub_080002CC(Entity*, s32, s32); @@ -29,7 +21,6 @@ extern u8 gUnk_080D16D0[4]; // Entity count per form extern PosOffset gUnk_080D16D4[4]; extern u8 gEntCount; -extern EntityHandler gHitboxCount; void Slime(Entity* this) { EnemyFunctionHandler(this, gUnk_080D16A4); @@ -76,7 +67,7 @@ void sub_08045018(Entity* this) { this->action = 3; this->actionDelay = 1; if (0 < this->speed) { - this->actionDelay = sub_0806FA04(4096, this->speed) >> 8; + this->actionDelay = FixedDiv(4096, this->speed) >> 8; } if (sub_08049FA0(this) == 0 && (Random() & 3)) { this->direction = (sub_08049EE4(this) + 0xfc + (Random() & 8)) & 24; @@ -117,7 +108,7 @@ void sub_080450A8(Entity* this) { ent->parent = entities[(i + count - 1) % count]; ent->type2 = 1; ent->height.HALF.HI = 0; - ent->hurtBlinkTime = -0x10; + ent->iframes = -0x10; /* Set MiniSlime offset relative to killed slime. */ sub_08045178(this, ent, off->h, off->v); diff --git a/src/enemy/sluggula.c b/src/enemy/sluggula.c index 86b90864..436baf3c 100644 --- a/src/enemy/sluggula.c +++ b/src/enemy/sluggula.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern s32 sub_080012DC(Entity*); diff --git a/src/enemy/smallPesto.c b/src/enemy/smallPesto.c index 7b6dbbfd..a7d68131 100644 --- a/src/enemy/smallPesto.c +++ b/src/enemy/smallPesto.c @@ -1,17 +1,11 @@ #include "global.h" #include "entity.h" +#include "coord.h" +#include "random.h" +#include "functions.h" extern u32 GetNextFunction(Entity*); -extern u32 sub_0806F520(Entity*); -extern void sub_0806F4E8(Entity*); -extern u32 sub_0806F3E4(); -extern void sub_0804A7D4(Entity*); -extern void sub_0804A720(Entity*); extern void sub_080317F8(Entity*); -extern u32 sub_08049FA0(Entity*); -extern u32 Random(); -extern u32 sub_08049EE4(Entity*); -extern void sub_0806F69C(Entity*); extern void (*gUnk_080CE530[])(Entity*); extern void (*gUnk_080CE548[])(Entity*); @@ -19,7 +13,6 @@ extern void (*gUnk_080CE554[])(Entity*); void sub_080317B4(Entity*); void sub_080317E0(Entity*); -void sub_080317F8(Entity*); void sub_08031840(Entity*); extern Hitbox gUnk_080CE560; @@ -42,17 +35,17 @@ void sub_0803169C(Entity* this) { iVar1 = sub_0806F520(this); if (iVar1 == 0) { this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->flags = this->flags | 0x80; this->speed = 0x40; this->field_0xf = 1; } else { - gUnk_080CE554[this->previousActionFlag](this); + gUnk_080CE554[this->subAction](this); } } void sub_080316DC(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 0x3c; } @@ -61,7 +54,7 @@ void sub_080316E8(Entity* this) { } void sub_080316F0(Entity* this) { - if (sub_0806F3E4()) { + if (sub_0806F3E4(this)) { sub_0804A7D4(this); } } diff --git a/src/enemy/spark.c b/src/enemy/spark.c index 210b8431..4a6541fa 100644 --- a/src/enemy/spark.c +++ b/src/enemy/spark.c @@ -19,7 +19,7 @@ void sub_0802B2E0(Entity* this) { if (this->bitfield & 0x80) { if ((this->bitfield & 0x7f) == 0x14) { this->flags &= ~0x80; - this->hurtBlinkTime = 0; + this->iframes = 0; this->spriteSettings.b.draw = 0; this->action = 2; ent = CreateFx(this, 2, 0); diff --git a/src/enemy/spearMoblin.c b/src/enemy/spearMoblin.c index 68e0fef5..033c1ea7 100644 --- a/src/enemy/spearMoblin.c +++ b/src/enemy/spearMoblin.c @@ -1,9 +1,9 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern bool32 sub_0806FC80(Entity*, Entity*, u32); -extern Entity* sub_080A7EE0(u32); extern Entity* sub_08049DF4(u32); void sub_08028604(Entity*); @@ -56,7 +56,7 @@ void sub_08028284(Entity* this) { } } - this->attachedEntity->hurtBlinkTime = this->hurtBlinkTime; + this->attachedEntity->iframes = this->iframes; if (this->currentHealth == 0) { this->speed = 0; this->field_0x82.HALF.LO = 0; @@ -386,7 +386,7 @@ void sub_080288C0(Entity* this) { Entity* ent = this->attachedEntity; if (ent && (ent->bitfield & 0x80)) { this->field_0x3e = ent->field_0x3e; - this->hurtBlinkTime = -ent->hurtBlinkTime; + this->iframes = -ent->iframes; this->field_0x46 = ent->field_0x46; this->field_0x42 = ent->field_0x42; ent->field_0x42 = 0; diff --git a/src/enemy/spikedBeetle.c b/src/enemy/spikedBeetle.c index 503084e7..46c87653 100644 --- a/src/enemy/spikedBeetle.c +++ b/src/enemy/spikedBeetle.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern u32 sub_0804A024(Entity*, u32, u32); @@ -52,7 +53,7 @@ void sub_0802B628(Entity* this) { this->speed = 0xc0; this->direction = this->field_0x3e; this->field_0x42 = 0; - this->hurtBlinkTime = -8; + this->iframes = -8; this->damageType = 100; InitializeAnimation(this, 9); } diff --git a/src/enemy/spinyChuchu.c b/src/enemy/spinyChuchu.c index 7bf39713..21396115 100644 --- a/src/enemy/spinyChuchu.c +++ b/src/enemy/spinyChuchu.c @@ -1,5 +1,6 @@ #include "enemy.h" #include "entity.h" +#include "random.h" #include "functions.h" extern void sub_08001318(Entity*); @@ -117,11 +118,11 @@ void sub_080225EC(Entity* this) { } void sub_08022654(Entity* this) { - switch (this->previousActionFlag) { + switch (this->subAction) { case 0: if (--this->field_0xf) return; - this->previousActionFlag = 1; + this->subAction = 1; SoundReq(0x12d); InitializeAnimation(this, 0); /* fallthrough */ @@ -129,7 +130,7 @@ void sub_08022654(Entity* this) { if (sub_08003FC4(this, 0x1800)) return; - this->previousActionFlag = 2; + this->subAction = 2; this->spriteSettings.b.draw = 1; InitializeAnimation(this, 5); EnqueueSFX(0x7d); diff --git a/src/enemy/tektite.c b/src/enemy/tektite.c index 66d2ca82..ab5da752 100644 --- a/src/enemy/tektite.c +++ b/src/enemy/tektite.c @@ -1,6 +1,7 @@ #include "global.h" #include "entity.h" #include "enemy.h" +#include "random.h" #include "functions.h" extern void (*const gUnk_080CDED0[])(Entity*); @@ -29,7 +30,7 @@ void sub_0802F150(Entity* this) { switch (this->bitfield & 0x3f) { case 0x14: this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; if (this->type != 0) { this->actionDelay = 0xc0; } else { @@ -62,15 +63,13 @@ void sub_0802F1F0(Entity* this) { } } -extern u8 gUnk_080CDEF8[]; - void sub_0802F210(Entity* this) { u32 temp; u32 temp2; sub_0804A720(this); this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = gUnk_080CDEF8[Random() & 3]; this->actionDelay = (Random() & 0x1f) + this->actionDelay; this->field_0xf = 0; @@ -106,8 +105,6 @@ void sub_0802F284(Entity* this) { } } -extern u8 gUnk_080CDEF8[]; - void sub_0802F300(Entity* this) { s32 temp; u32 rand; @@ -119,7 +116,7 @@ void sub_0802F300(Entity* this) { if (sub_080044EC(this, this->field_0x80.HWORD) == 1) { this->action = 3; - this->previousActionFlag = 0; + this->subAction = 0; if (this->type != 0) { rand = 0; } @@ -146,9 +143,9 @@ void sub_0802F300(Entity* this) { } } - if ((this->previousActionFlag == 0) && (temp < this->height.HALF.HI)) { + if ((this->subAction == 0) && (temp < this->height.HALF.HI)) { InitializeAnimation(this, 4); - this->previousActionFlag = 1; + this->subAction = 1; } if (temp < -0xc) { diff --git a/src/enemy/tektiteGolden.c b/src/enemy/tektiteGolden.c index 3bf14e34..2567c463 100644 --- a/src/enemy/tektiteGolden.c +++ b/src/enemy/tektiteGolden.c @@ -1,8 +1,9 @@ #include "global.h" #include "entity.h" #include "enemy.h" -#include "functions.h" #include "flags.h" +#include "random.h" +#include "functions.h" extern void sub_08038168(Entity*); @@ -27,7 +28,7 @@ void sub_08037F00(Entity* this) { sub_0804AA30(this, &gUnk_080CF4A0); if (this->bitfield == 0x94) { this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0x14; this->field_0xf = 0; this->field_0x80.HALF.LO = 0; @@ -69,7 +70,7 @@ void sub_08037FA0(Entity* this) { } sub_0804A720(this); this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = (Random() & 0x1f) + 0x20; this->field_0xf = 0; this->field_0x80.HALF.LO = 0; @@ -106,7 +107,7 @@ void sub_08038048(Entity* this) { if (sub_080044EC(this, 0x3000) == 1) { this->action = 3; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0x14; InitializeAnimation(this, 3); return; @@ -121,9 +122,9 @@ void sub_08038048(Entity* this) { sub_08038168(this); } - if ((this->previousActionFlag == 0) && (temp < this->height.HALF.HI)) { + if ((this->subAction == 0) && (temp < this->height.HALF.HI)) { InitializeAnimation(this, 4); - this->previousActionFlag = 1; + this->subAction = 1; } if (temp < -0xc) { diff --git a/src/enemy/vaatiBall.c b/src/enemy/vaatiBall.c index bdccd10e..3907e270 100644 --- a/src/enemy/vaatiBall.c +++ b/src/enemy/vaatiBall.c @@ -1,7 +1,8 @@ #include "entity.h" #include "player.h" -#include "functions.h" #include "screen.h" +#include "createObject.h" +#include "functions.h" typedef struct { s8 h, v; @@ -136,8 +137,6 @@ void sub_080447E0(Entity* this) { } } -extern u32 sub_080045B4(); -extern u32 sub_0806FCB8(Entity*, u32, u32, u32); extern void sub_08044DEC(); void sub_08044868(Entity* this) { diff --git a/src/enemy/wallMaster.c b/src/enemy/wallMaster.c index 1ba24a96..394e8620 100644 --- a/src/enemy/wallMaster.c +++ b/src/enemy/wallMaster.c @@ -1,7 +1,8 @@ #include "enemy.h" #include "entity.h" -#include "functions.h" #include "area.h" +#include "random.h" +#include "functions.h" extern void sub_08001328(Entity*); extern Entity* sub_08049DF4(u32); diff --git a/src/enemy/wallMaster2.c b/src/enemy/wallMaster2.c index d0e5b1a3..f6d32479 100644 --- a/src/enemy/wallMaster2.c +++ b/src/enemy/wallMaster2.c @@ -1,9 +1,9 @@ #include "enemy.h" -#include "functions.h" #include "area.h" +#include "random.h" +#include "functions.h" extern void sub_08001328(Entity*); -extern u32 sub_0806FCB8(Entity*, u32, u32, u32); extern void DoExitTransition(u32*); extern Entity* gUnk_020000B0; diff --git a/src/enemy/waterDrop.c b/src/enemy/waterDrop.c index 320fc03d..f994b564 100644 --- a/src/enemy/waterDrop.c +++ b/src/enemy/waterDrop.c @@ -1,7 +1,8 @@ #include "enemy.h" #include "entity.h" -#include "functions.h" #include "screen.h" +#include "random.h" +#include "functions.h" void sub_0802A39C(Entity*); void sub_0802A334(Entity*); diff --git a/src/enemy/wisp.c b/src/enemy/wisp.c index 10463258..247cf0a0 100644 --- a/src/enemy/wisp.c +++ b/src/enemy/wisp.c @@ -1,10 +1,11 @@ #include "global.h" #include "entity.h" #include "enemy.h" -#include "structures.h" #include "player.h" -#include "functions.h" #include "save.h" +#include "random.h" +#include "createObject.h" +#include "functions.h" extern void (*const gUnk_080CEB74[])(Entity*); extern void (*const gUnk_080CEB8C[])(Entity*); @@ -49,7 +50,7 @@ void sub_08033564(Entity* this) { break; case 0x14: this->flags &= 0x7f; - this->hurtBlinkTime = 0; + this->iframes = 0; this->spriteSettings.b.draw = FALSE; ent = CreateFx(this, 2, 0); if (ent != NULL) { @@ -64,12 +65,12 @@ void sub_08033564(Entity* this) { void sub_0803362C(Entity* this) { if (sub_0806F520() != 0) { - gUnk_080CEB98[this->previousActionFlag](this); + gUnk_080CEB98[this->subAction](this); } } void sub_08033650(Entity* this) { - this->previousActionFlag = 2; + this->subAction = 2; } void sub_08033658(Entity* this) { diff --git a/src/entity.c b/src/entity.c index d574f05c..acc2795c 100644 --- a/src/entity.c +++ b/src/entity.c @@ -1,5 +1,7 @@ #include "global.h" +#include "area.h" #include "entity.h" +#include "utils.h" #include "script.h" typedef struct OtherEntity { @@ -23,14 +25,13 @@ Entity* sub_0805E744(void) { return NULL; } -extern Entity* GetEmptyEntity(); -OtherEntity* GetEmptyManager(); +OtherEntity* GetEmptyManager(void); typedef void* (*Getter)(void); -void* GetEmptyEntityByType(int type) { +void* GetEmptyEntityByKind(u32 kind) { Getter getter = NULL; - if (type == 9) { + if (kind == MANAGER) { getter = (Getter)GetEmptyManager; } else { getter = (Getter)GetEmptyEntity; @@ -48,21 +49,20 @@ typedef struct { extern struct_03003DD0 gUnk_03003DD0; extern u32 _call_via_r0(u32*); extern u32 _EntUpdate; -extern void DeleteEntityAny(Entity*); +void DeleteEntityAny(Entity*); void DeleteThisEntity(void) { DeleteEntityAny(gUnk_03003DD0.field_0x8); _call_via_r0((u32*)&_EntUpdate); } -void DeleteEntity(Entity*); void DeleteManager(OtherEntity*); typedef void (*Deleter)(void*); void DeleteEntityAny(Entity* ent) { Deleter deleter = NULL; - if (ent->kind == 9) { + if (ent->kind == MANAGER) { deleter = (Deleter)DeleteManager; } else { deleter = (Deleter)DeleteEntity; @@ -79,9 +79,8 @@ extern void sub_0805EC60(); extern void sub_08017744(); extern void sub_0805E92C(); extern void UnloadHitbox(); -extern void sub_0801DA0C(); extern void sub_0804AA1C(); -extern void UnlinkEntity(); // Unlink +void UnlinkEntity(); void DeleteEntity(Entity* ent) { if (ent->next) { @@ -95,9 +94,9 @@ void DeleteEntity(Entity* ent) { sub_0805E92C(ent); UnloadCutsceneData(ent); UnloadHitbox(ent); - sub_0801DA0C(ent->myHeap); + zFree(ent->myHeap); ent->myHeap = NULL; - if (ent->kind == 3) { + if (ent->kind == ENEMY) { sub_0804AA1C(ent); } ent->flags = ent->flags & 0x7f; @@ -160,7 +159,6 @@ OtherEntity* GetEmptyManager(void) { return NULL; } -extern void MemClear32(void*, u32); extern u8 gManagerCount; void DeleteManager(OtherEntity* ent) { @@ -169,12 +167,10 @@ void DeleteManager(OtherEntity* ent) { sub_0805E92C(ent); UnlinkEntity(ent); - MemClear32(ent, sizeof(OtherEntity)); + MemClear(ent, sizeof(OtherEntity)); gManagerCount--; } -#include "area.h" - void sub_0805E92C(u32 param_1) { if (param_1 == gArea.unk2) { gArea.unk2 = 0; @@ -184,8 +180,7 @@ void sub_0805E92C(u32 param_1) { } extern Entity gUnk_020369F0; -extern void MemCopy(const void* src, void* dest, size_t size); // dma copy -extern void sub_0805E98C(void); +void sub_0805E98C(void); void sub_0805E958(void) { MemCopy(&gEntityLists, &gUnk_020369F0, 0x48); @@ -212,7 +207,7 @@ void sub_0805E9A8(void) { list = &gEntityLists[0]; do { for (i = list->first; (u32)i != (u32)list; i = i->next) { - i->flags &= 0xfd; + i->flags &= ~2; if ((i->flags & 0x20) == 0) { i->flags |= 0x10; } @@ -237,32 +232,32 @@ void sub_0805E9F4(void) { extern void sub_0805E374(Entity*); -void AppendEntityToList(Entity* ent, int listIndex) { +void AppendEntityToList(Entity* entity, u32 listIndex) { LinkedList* list; list = &gEntityLists[listIndex]; - ent->next = (Entity*)list; - ent->prev = list->last; - list->last->next = ent; - list->last = ent; - if (ent->kind != 9) { - ent->spritePriority.b0 = 4; + entity->next = (Entity*)list; + entity->prev = list->last; + list->last->next = entity; + list->last = entity; + if (entity->kind != MANAGER) { + entity->spritePriority.b0 = 4; gEntCount++; } else { gManagerCount++; } - sub_0805E374(ent); + sub_0805E374(entity); } -void PrependEntityToList(Entity* ent, int listIndex) { +void PrependEntityToList(Entity* entity, u32 listIndex) { LinkedList* list; - UnlinkEntity(ent); + UnlinkEntity(entity); list = &gEntityLists[listIndex]; - ent->prev = (Entity*)list; - ent->next = list->first; - list->first->prev = ent; - list->first = ent; + entity->prev = (Entity*)list; + entity->next = list->first; + list->first->prev = entity; + list->first = entity; } void UnlinkEntity(Entity* ent) { @@ -273,7 +268,7 @@ void UnlinkEntity(Entity* ent) { ent->next->prev = ent->prev; } -bool32 DoesSimilarEntityExist(Entity* ent) { +bool32 EntityHasDuplicateID(Entity* ent) { Entity* i; LinkedList* list; @@ -289,31 +284,31 @@ bool32 DoesSimilarEntityExist(Entity* ent) { return FALSE; } -Entity* FindEntityInListBySubtype(int type, int subtype, int listIndex) { +Entity* FindEntityByID(u32 kind, u32 id, u32 listIndex) { Entity* it; LinkedList* list; list = &gEntityLists[listIndex]; for (it = list->first; (u32)it != (u32)list; it = it->next) { - if (type == it->kind && subtype == it->id) + if (kind == it->kind && id == it->id) return it; } return NULL; } -Entity* FindEntityInListByForm(int type, int subtype, int listIndex, int form, int parameter) { +Entity* FindEntity(u32 kind, u32 id, u32 listIndex, u32 type, u32 type2) { Entity* i; LinkedList* list; list = &gEntityLists[listIndex]; for (i = list->first; (u32)i != (u32)list; i = i->next) { - if (type == i->kind && subtype == i->id && form == i->type && parameter == i->type2) + if (kind == i->kind && id == i->id && type == i->type && type2 == i->type2) return i; } return NULL; } -Entity* FindNextEntityOfSameSubtype(Entity* ent, int listIndex) { +Entity* FindNextDuplicateID(Entity* ent, int listIndex) { Entity* i; LinkedList* list; @@ -325,14 +320,14 @@ Entity* FindNextEntityOfSameSubtype(Entity* ent, int listIndex) { return NULL; } -Entity* FindEntityBySubtype(int type, int subtype) { +Entity* DeepFindEntityByID(u32 kind, u32 id) { Entity* i; LinkedList* list; list = &gEntityLists[0]; do { for (i = (Entity*)list->first; (u32)i != (u32)list; i = i->next) { - if (type == i->kind && (subtype == i->id)) + if (kind == i->kind && (id == i->id)) return i; } } while (++list < &gEntityLists[9]); @@ -349,7 +344,7 @@ void DeleteAllEnemies(void) { do { for (ent = list->first; (u32)ent != (u32)list; ent = next) { next = ent->next; - if (ent->kind == 3) + if (ent->kind == ENEMY) DeleteEntity(ent); } } while (++list < &gEntityLists[9]); diff --git a/src/ezloNag.c b/src/ezloNag.c index 7d537a44..0ad98db7 100644 --- a/src/ezloNag.c +++ b/src/ezloNag.c @@ -1,5 +1,5 @@ +#include "audio.h" #include "global.h" -#include "entity.h" #include "functions.h" #include "textbox.h" #include "structures.h" @@ -24,8 +24,6 @@ typedef struct { u8 unk13; } Element; -/////////////////////////////////////////////////////////////// - extern void sub_0805ECEC(u32, u32, u32, u32); extern void sub_0801CAD0(Element*); @@ -99,7 +97,7 @@ void sub_0801CF18(Element* arg0) { arg0->unk4 = 2; arg0->unk1 = 8; gUnk_0200AF00.ezloNagFuncIndex = 3; - SoundReq(0x173); + SoundReq(SFX_EZLO_UI); } } diff --git a/src/sub_08050024.c b/src/fade.c index f3868b4b..fe77e3d0 100644 --- a/src/sub_08050024.c +++ b/src/fade.c @@ -12,9 +12,6 @@ extern struct_03000000 gUnk_03000000; extern u32 gUsedPalettes; -extern void sub_0801E104(); -extern void DoFade(u32, u32); - void sub_08050024() { sub_0801E104(); DoFade(5, 0x80 << 1); diff --git a/src/fileScreen.c b/src/fileScreen.c index 58fe323f..b55977ca 100644 --- a/src/fileScreen.c +++ b/src/fileScreen.c @@ -1,4 +1,11 @@ #include "fileScreen.h" +#include "main.h" +#include "player.h" +#include "utils.h" +#include "screen.h" +#include "menu.h" +#include "random.h" +#include "textbox.h" // copy, erase, start #define NUM_FILE_OPERATIONS 3 @@ -105,7 +112,7 @@ void CreateDialogBox(u32 arg0, u32 arg1) { void sub_08050384(void) { sub_0801C4A0(0, 0); - MemClear32(&gBG0Buffer, sizeof(gBG0Buffer)); + MemClear(&gBG0Buffer, sizeof(gBG0Buffer)); gScreen.bg.bg0Updated = 1; } @@ -117,8 +124,8 @@ void sub_080503A8(u32 gfxGroup) { void SetFileSelectState(FileSelectState mode) { gUnk_02032EC0.state = mode; - MemClear32(&gBG0Buffer, sizeof(gBG0Buffer)); - MemClear32(&gBG1Buffer, sizeof(gBG1Buffer)); + MemClear(&gBG0Buffer, sizeof(gBG0Buffer)); + MemClear(&gBG1Buffer, sizeof(gBG1Buffer)); } void LoadOptionsFromSave(u32 idx) { @@ -159,7 +166,7 @@ void HandleChooseFileScreen(void) { gScreen.bg.bg1yOffset = 0; gScreen.affine.bg2xOffset = 0; gScreen.affine.bg2yOffset = 0; - MemClear32(&gChooseFileState, sizeof(gChooseFileState)); + MemClear(&gChooseFileState, sizeof(gChooseFileState)); } HideButtonR(); @@ -182,19 +189,19 @@ void HandleChooseFileScreen(void) { static void HandleFileScreenEnter(void) { u32 i; - sub_0801DA90(1); + DispReset(1); sub_080A3210(); - MemClear32((void*)VRAM, 0x80); // clear palettes + MemClear((void*)VRAM, 0x80); // clear palettes MessageInitialize(); EraseAllEntities(); sub_08080668(); sub_080ADD30(); sub_0801CFA8(0); - MemClear32(&gUnk_0200AF00, sizeof(gUnk_0200AF00)); - MemClear32(&gUnk_02019EE0, sizeof(gUnk_02019EE0)); + MemClear(&gUnk_0200AF00, sizeof(gUnk_0200AF00)); + MemClear(&gUnk_02019EE0, sizeof(gUnk_02019EE0)); gUnk_02019EE0.unk3 = 7; gUnk_02019EE0.unk6 = gUnk_02000000->gameLanguage > LANGUAGE_EN ? 3 : 0; - MemClear32(&gUnk_02032EC0, sizeof(gUnk_02032EC0)); + MemClear(&gUnk_02032EC0, sizeof(gUnk_02032EC0)); gUnk_02032EC0.lastState = 8; SetFileSelectState(STATE_NONE); InitDMA(); @@ -216,7 +223,7 @@ static void HandleFileScreenEnter(void) { gScreen.controls.alphaBlend = BLDALPHA_BLEND(15, 10); gUnk_02024490.unk0 = 1; gMain.funcIndex = 1; - SoundReq(0x7); + SoundReq(BGM_FILE_SELECT); DoFade(4, 8); } @@ -284,7 +291,7 @@ void sub_0805070C(void) { var0->unk8 = gUnk_02000D00; for (i = 0; i < NUM_SAVE_SLOTS; i++) { var0->unk6 = 0; - MemClear32(var0->unk8, 0x200); + MemClear(var0->unk8, 0x200); playerName = &gUnk_02019EE0.saves[i].playerName[0]; for (j = 0; j < FILENAME_LENGTH; j++) { sub_0805F7DC(playerName[j], var0); @@ -438,14 +445,14 @@ void sub_08050940(void) { if (gUnk_02032EC0.lastState != mode) { SetFileSelectState(mode); - SoundReq(0x6A); + SoundReq(SFX_TEXTBOX_SELECT); } row_idx = (row_idx + num_rows) % num_rows; if (gUnk_02019EE0.unk6 != row_idx) { gUnk_02019EE0.unk6 = row_idx; sub_08050AFC(row_idx); - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } if (gUnk_02019EE0.saveStatus[gUnk_02019EE0.unk6] == SAVE_VALID) { @@ -489,7 +496,7 @@ void sub_08050B3C(u16*); void sub_08050AFC(u32 idx) { SetActiveSave(idx); - MemClear32(&gBG1Buffer, sizeof(gBG1Buffer)); + MemClear(&gBG1Buffer, sizeof(gBG1Buffer)); if (gUnk_02019EE0.saveStatus[idx] == SAVE_VALID) { sub_08050B3C(&gBG1Buffer.unk29C); } @@ -589,14 +596,14 @@ void sub_08050C54(void) { case A_BUTTON: case START_BUTTON: if (column_idx == 0) { - SoundReq(0x80080000); + SoundReq(SONG_VOL_FADE_OUT); } gMenu.transitionTimer = 0xf; sub_080A7114(1); - SoundReq(0x6a); + SoundReq(SFX_TEXTBOX_SELECT); break; case B_BUTTON: - SoundReq(0x6c); + SoundReq(SFX_MENU_CANCEL); SetFileSelectState(STATE_NONE); break; case DPAD_LEFT: @@ -614,7 +621,7 @@ void sub_08050C54(void) { } if (gMenu.column_idx != column_idx) { gMenu.column_idx = column_idx; - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } } @@ -645,7 +652,7 @@ void HandleFileLanguageSelect(void) { } void sub_08050DB8(void) { - MemClear32(&gBG2Buffer, sizeof(gBG2Buffer)); + MemClear(&gBG2Buffer, sizeof(gBG2Buffer)); sub_080503A8(0xc); gMenu.field_0x4 = gUnk_02000000->gameLanguage; sub_080A7114(1); @@ -667,7 +674,7 @@ void sub_08050DE4(void) { break; case A_BUTTON: case START_BUTTON: - SoundReq(0x6a); + SoundReq(SFX_TEXTBOX_SELECT); if (gMenu.field_0x4 != row_idx) { sub_080A7114(2); CreateDialogBox(8, 0); @@ -678,7 +685,7 @@ void sub_08050DE4(void) { case B_BUTTON: row_idx = gMenu.field_0x4; gUnk_02000000->gameLanguage = gMenu.field_0x4; - SoundReq(0x6c); + SoundReq(SFX_MENU_CANCEL); SetFileSelectState(STATE_NONE); break; } @@ -692,7 +699,7 @@ void sub_08050DE4(void) { } if (gUnk_02000000->gameLanguage != row_idx) { gUnk_02000000->gameLanguage = row_idx; - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } } @@ -765,13 +772,13 @@ NONMATCH("asm/non_matching/fileScreen/sub_08050EF4.inc", void sub_08050EF4(void) case 3: gUnk_02019EE0.saves[gUnk_02019EE0.unk6].messageSpeed = gUnk_02019EE0.unk4; gUnk_02019EE0.saves[gUnk_02019EE0.unk6].brightnessPref = gUnk_02019EE0.unk5; - SoundReq(0x6c); + SoundReq(SFX_MENU_CANCEL); sub_080A7114(mode); SetActiveSave(gUnk_02019EE0.unk6); break; case 2: CreateDialogBox(8, 0); - SoundReq(0x6a); + SoundReq(SFX_TEXTBOX_SELECT); default: case 1: sub_080A7114(mode); @@ -780,11 +787,11 @@ NONMATCH("asm/non_matching/fileScreen/sub_08050EF4.inc", void sub_08050EF4(void) case 0: if (gMenu.column_idx != column_idx) { gMenu.column_idx = column_idx; - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } else if (option != *p_option) { *p_option = option; LoadOptionsFromSave(gUnk_02019EE0.unk6); - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } break; } @@ -842,7 +849,7 @@ void sub_08051358(void) { if (gMenu.focusCoords[0] != 0x0b || gMenu.focusCoords[1] != 0x5) { gMenu.focusCoords[1] = 0x5; gMenu.focusCoords[0] = 0xb; - SoundReq(0x67); + SoundReq(SFX_TEXTBOX_NEXT); } } @@ -919,7 +926,7 @@ void sub_08051480(u32 c) { gMenu.unk13 = idx + 1; gSave.playerName[idx] = c; - sub_08051574(0x6b); + sub_08051574(SFX_6B); } u32 sub_080514BC(u32 a1) { @@ -939,9 +946,8 @@ u32 sub_080514BC(u32 a1) { } idx = gMenu.unk13; - if (idx == 0) { + if (idx == 0) return 0; - } c = gSave.playerName[idx - 1]; if (c - 0xa4 < 0x29) { @@ -955,11 +961,10 @@ u32 sub_080514BC(u32 a1) { case 0xE: return c; case 0xF: - if (c < 0xc3) { + if (c < 0xc3) return 0; - } else { + else return c + 10; - } default: return c; } @@ -980,13 +985,11 @@ u32 sub_080514BC(u32 a1) { switch (a1) { default: case 0x0: - return c - 0x33; case 0xe: return c - 0x33; case 0xf: - if (c > 0xf5) { + if (c > 0xf5) return c - 0x29; - } } } @@ -1025,10 +1028,10 @@ void sub_080515D4(void) { if (column_idx == 1) { CreateDialogBox(4, 0); sub_080A7114(2); - SoundReq(0x6a); + SoundReq(SFX_TEXTBOX_SELECT); } else { SetFileSelectState(0); - SoundReq(0x6c); + SoundReq(SFX_MENU_CANCEL); } break; case DPAD_LEFT: @@ -1041,7 +1044,7 @@ void sub_080515D4(void) { if (gMenu.column_idx != column_idx) { gMenu.column_idx = column_idx; - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } } @@ -1122,20 +1125,20 @@ void sub_080517EC(void) { if (gUnk_02019EE0.unk7 < 3) { CreateDialogBox(2, 0); sub_080A7114(2); - SoundReq(0x6a); + SoundReq(SFX_TEXTBOX_SELECT); break; } // fallthrough case B_BUTTON: gUnk_02019EE0.unk7 = 4; - SoundReq(0x6c); + SoundReq(SFX_MENU_CANCEL); SetFileSelectState(0); break; } temp = sub_080517B4(delta); if (temp != gUnk_02019EE0.unk7) { gUnk_02019EE0.unk7 = temp; - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } } @@ -1186,7 +1189,7 @@ void sub_0805194C(u32 save_idx) { gUnk_02019EE0.saveStatus[save_idx] = 0; save = &gUnk_02019EE0.saves[save_idx]; - MemClear32(save, sizeof(*save)); + MemClear(save, sizeof(*save)); save->messageSpeed = 1; save->brightnessPref = 1; save->stats.health = 24; diff --git a/src/flags.c b/src/flags.c index 6f1d5d56..2129ae01 100644 --- a/src/flags.c +++ b/src/flags.c @@ -2,7 +2,6 @@ #include "room.h" #include "flags.h" #include "area.h" -#include "room.h" extern u32 ReadBit(u32*, u32); extern u32 CheckBits(u32*, u32, u32); @@ -1,7 +1,6 @@ #include "global.h" #include "screen.h" #include "structures.h" -#include "functions.h" #include "screen.h" #include "entity.h" #include "player.h" @@ -9,11 +8,12 @@ #include "main.h" #include "flags.h" #include "save.h" +#include "utils.h" #include "fileScreen.h" +#include "functions.h" extern u8 gArea; extern Entity gPlayerEntity; -extern u32 gUnk_03000B80; extern u32 gUnk_03003FC0; extern u16 gWalletSizes[4]; @@ -105,13 +105,13 @@ void sub_080521A0(void) { } gMenu.transitionTimer = 0x3c; sub_080A7114(temp2); - SoundReq(0x6a); + SoundReq(SFX_TEXTBOX_SELECT); break; } if (gMenu.field_0x3 != temp) { gMenu.field_0x3 = temp; sub_08052418(0, temp); - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } break; } @@ -170,7 +170,7 @@ void sub_080522F4(void) { break; case 0x1: sub_080A7114(2); - SoundReq(0x6a); + SoundReq(SFX_TEXTBOX_SELECT); if (temp == 0) { DoFade(5, 8); } else { @@ -181,7 +181,7 @@ void sub_080522F4(void) { if (gMenu.field_0x3 != temp) { gMenu.field_0x3 = temp; sub_08052418(1, temp); - SoundReq(0x69); + SoundReq(SFX_TEXTBOX_CHOICE); } } break; @@ -219,7 +219,7 @@ NONMATCH("asm/non_matching/game/sub_08052418.inc", void sub_08052418(int param_1 int i; struct_080FCA8C temp; - MemClear32(&gBG1Buffer, 0x800); + MemClear(&gBG1Buffer, 0x800); gUnk_020227E8._0[0].WORD = 0xf; gUnk_020227E8._0[2].WORD = 0xf; gUnk_020227E8._0[4].WORD = 0xf; @@ -238,12 +238,12 @@ void InitializePlayer(void) { Entity* pl; sub_080784C8(); - MemClear32((void*)&gUnk_03000B80, 0x70); - MemClear32((void*)&gPlayerState, 0xb0); + MemClear((void*)&gUnk_03000B80, sizeof(gUnk_03000B80)); + MemClear((void*)&gPlayerState, 0xb0); MemFill32(0xffffffff, &gPlayerState.field_0x40, 0x40); pl = &gPlayerEntity; - MemClear32((void*)pl, 0x88); + MemClear((void*)pl, 0x88); gRoomControls.cameraTarget = pl; gPlayerState.playerAction = gUnk_080FCAC8[gScreenTransition.field_0xf]; if (!CheckGlobalFlag(0x14)) { @@ -299,7 +299,7 @@ u32 sub_08052654() { return (gArea >> 7) & 1; } -u32 CheckIsDungeon() { +u32 CheckIsDungeon(void) { return (gArea >> 2) & 1; } diff --git a/src/input.c b/src/input.c deleted file mode 100644 index c187d598..00000000 --- a/src/input.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "global.h" -#include "entity.h" -#include "readKeyInput.h" - -static void StoreKeyInput(Input*, u32); - -void ReadKeyInput(void) { - u32 keyInput = ~REG_KEYINPUT & KEYS_MASK; - StoreKeyInput(&gInput, keyInput); -} - -static void StoreKeyInput(Input* input, u32 keyInput) { - u32 heldKeys = input->heldKeys; - u32 difference = keyInput & ~heldKeys; - input->newKeys = difference; - if (keyInput == heldKeys) { - if (--input->unk7 == 0) { - input->unk7 = 4; - input->unk4 = keyInput; - } else { - input->unk4 = 0; - } - } else { - input->unk7 = 0x14; - input->unk4 = difference; - } - input->heldKeys = keyInput; -} diff --git a/src/intro.c b/src/intro.c index 891544d3..e3ee0f9d 100644 --- a/src/intro.c +++ b/src/intro.c @@ -1,11 +1,12 @@ +#include "audio.h" #include "global.h" -#include "menu.h" #include "main.h" #include "entity.h" #include "functions.h" -#include "readKeyInput.h" +#include "utils.h" #include "screen.h" #include "structures.h" +#include "textbox.h" typedef struct { u8 filler0[0x4]; @@ -55,7 +56,7 @@ static const u16 sLightRaysAlphaBlends[] = { static u32 AdvanceIntroSequence(u32 transition) { gUnk_02032EC0.lastState = transition; gMain.funcIndex = 2; - MemClear32(&gIntroState, sizeof(gIntroState)); + MemClear(&gIntroState, sizeof(gIntroState)); DoFade(7, 8); } @@ -64,7 +65,7 @@ void HandleIntroScreen(void) { switch (gMain.funcIndex) { case 0: MessageInitialize(); - MemClear32(&gUnk_02032EC0, sizeof(gUnk_02032EC0)); + MemClear(&gUnk_02032EC0, sizeof(gUnk_02032EC0)); AdvanceIntroSequence(0); break; case 1: @@ -74,7 +75,7 @@ void HandleIntroScreen(void) { if (gFadeControl.active) { return; } - sub_0801DA90(1); + DispReset(1); gMain.funcIndex = 1; break; } @@ -87,7 +88,7 @@ static void HandleNintendoCapcomLogos(void) { advance = GetAdvanceState(); if (gIntroState.state == 0) { - sub_0801DA90(1); + DispReset(1); gIntroState.state = 1; gIntroState.timer = 120; LoadGfxGroup(16); @@ -158,7 +159,7 @@ static void HandleTitlescreen(void) { UpdateSwordBgAffineData(); } sub_080A3210(); - SoundReq(3); // fanfare + SoundReq(BGM_TITLE_SCREEN); DoFade(6, 8); break; case 1: @@ -182,12 +183,12 @@ static void HandleTitlescreen(void) { advance = GetAdvanceState(); if (advance != ADVANCE_NONE) { if (advance == ADVANCE_KEY_PRESSED) { - SoundReq(0x6a); + SoundReq(SFX_TEXTBOX_SELECT); } else { advance = ADVANCE_NONE; } AdvanceIntroSequence(advance); - SoundReq(0x80080000); + SoundReq(SONG_VOL_FADE_OUT); } UpdatePressStartIcon(); if ((gIntroState.timer & 0x20) == 0) { @@ -241,7 +242,7 @@ static void HandleJapaneseTitlescreenAnimationIntro(void) { gScreen.bg.bg1Control = 0xc09; gFadeControl.field_0x4 = 0x40; DoFade(6, 0x10); - SoundReq(0xf8); + SoundReq(SFX_F8); } } break; @@ -271,7 +272,7 @@ static void HandleTitlescreenAnimationIntro(void) { if (!gFadeControl.active) { gIntroState.subState = 1; gScreen.lcd.displayControl |= DISPCNT_BG2_ON; - SoundReq(0xF6); + SoundReq(SFX_EVAPORATE); } break; case 1: @@ -290,7 +291,7 @@ static void HandleTitlescreenAnimationIntro(void) { gIntroState.subState++; CreateObject(0xBD, 0, 0); DoFade(6, 16); - SoundReq(0xF8); + SoundReq(SFX_F8); } break; default: @@ -1,6 +1,7 @@ #include "global.h" #include "entity.h" #include "item.h" +#include "functions.h" // TODO - How does this relate to PlayerItemFunctions? Is this just a lookup table? void (*const gItemFunctions[])(ItemBehavior*, u32) = { @@ -11,7 +12,6 @@ void (*const gItemFunctions[])(ItemBehavior*, u32) = { }; extern void sub_08077E78(ItemBehavior*, u32); -extern void SoundReq(u32); extern void sub_08078F60(void); extern void sub_08077D38(ItemBehavior*, u32); extern void sub_0805E544(void); @@ -28,7 +28,6 @@ extern void (*const gUnk_0811BDE0[])(ItemBehavior* beh, u32); extern void (*const gUnk_0811BDE8[])(ItemBehavior* beh, u32); extern void (*const gUnk_0811BDF4[])(ItemBehavior* beh, u32); -extern u8 gUnk_02034490; #if 0 void Ocarina(ItemBehavior* beh, u32 inputFlags) { gOcarinaStates[beh->stateID](beh, inputFlags); @@ -50,7 +49,7 @@ void OcarinaUse(ItemBehavior *beh, u32 arg1) gPlayerEntity.field_0x7a = 2; gPlayerState.flags.all |= 0x10000000; gPlayerState.field_0x27[0] = 0xff; - gUnk_02034490 = 1; + gUnk_02034490[0] = 1; bVar1 = (8 >> arg1); gPlayerState.field_0xa |= bVar1; gPlayerState.keepFacing |= bVar1; diff --git a/src/item11.c b/src/item11.c index 984d02e0..f2ad2f16 100644 --- a/src/item11.c +++ b/src/item11.c @@ -1,11 +1,10 @@ #include "global.h" #include "entity.h" #include "player.h" +#include "functions.h" -extern void DeleteThisEntity(); extern void sub_08078CD0(Entity*); extern void sub_08018FA0(Entity*); -extern u32 sub_0801766C(Entity*); extern void sub_08018F6C(Entity*); extern void (*const gUnk_080B3DD0[])(Entity*); @@ -16,7 +15,7 @@ extern Hitbox* gUnk_080B3DE8[]; void Item11(Entity* this) { if (this->currentHealth) { - this->hurtBlinkTime = 0; + this->iframes = 0; gUnk_080B3DD0[this->action](this); } else { DeleteThisEntity(); @@ -82,7 +81,7 @@ void sub_08018DE8(Entity* this) { sub_08018F6C(this); break; case 5: - this->attachedEntity->previousActionFlag = 4; + this->attachedEntity->subAction = 4; this->flags = this->flags | 0x80; this->action = 2; this->spritePriority.b0 = 2; diff --git a/src/item14.c b/src/item14.c index d9537b8b..5055a986 100644 --- a/src/item14.c +++ b/src/item14.c @@ -1,4 +1,5 @@ #include "entity.h" +#include "audio.h" #include "functions.h" #include "player.h" #include "room.h" @@ -30,7 +31,7 @@ void sub_0805FBE8(Entity* this) { sub_0801766C(this); sub_0806F69C(this); sub_0805FC74(this); - SoundReq(0x13f); + SoundReq(SFX_ITEM_SWORD_BEAM); } void sub_0805FC74(Entity* this) { @@ -39,7 +40,7 @@ void sub_0805FC74(Entity* this) { if (--*(int*)&this->field_0x6c != -1) { GetNextFrame(this); sub_0806F69C(this); - ++this->actionDelay; + this->actionDelay++; if (this->type2 == 0) { sub_0800451C(this); } diff --git a/src/loadRoom.c b/src/loadRoom.c index 04b8e02c..0bd68f75 100644 --- a/src/loadRoom.c +++ b/src/loadRoom.c @@ -1,10 +1,9 @@ #include "global.h" #include "room.h" #include "flags.h" +#include "functions.h" -void LoadRoomEntityList(EntityData* dat); extern void sub_0804B058(EntityData* dat); -extern void LoadRoomTileEntities(EntityData* dat); extern void sub_0801AC98(); extern u32 sub_08049D1C(u32); extern Entity* LoadRoomEntity(EntityData*); @@ -13,6 +12,24 @@ extern void* GetRoomProperty(u32, u32, u32); extern u32 gUnk_02017654; extern u32* gAreaEntities; +extern void sub_080186EC(); +extern void sub_0804B16C(); + +void sub_0804AFF4(void) { + void (*func)(); + + sub_080186EC(); + func = (void (*)())GetCurrentRoomProperty(5); + if (func) { + func(); + } + func = (void (*)())GetCurrentRoomProperty(7); + if (func) { + func(); + } + sub_0804B16C(); +} + void LoadRoom(void) { s32 iVar1; s32* dat; @@ -34,7 +51,7 @@ void sub_0804B058(EntityData* dat) { if ((dat != NULL) && *(u8*)dat != 0xff) { uVar2 = 0; do { - if ((uVar2 < 0x20) && ((dat->type) == 3)) { + if ((uVar2 < 0x20) && ((dat->kind) == 3)) { if (sub_08049D1C(uVar2) != 0) { ent = LoadRoomEntity(dat); if ((ent != NULL) && (ent->kind == 3)) { @@ -1,11 +1,14 @@ +#include "audio.h" #include "global.h" #include "functions.h" #include "structures.h" #include "main.h" #include "screen.h" #include "random.h" -#include "readKeyInput.h" +#include "utils.h" #include "save.h" +#include "textbox.h" +#include "arm_proxy.h" extern void HandleIntroScreen(void); extern void HandleChooseFileScreen(void); @@ -20,7 +23,9 @@ static void (*const sScreenHandlers[])(void) = { [SCREEN_CREDITS] = HandleCreditsScreen, [SCREEN_DEBUG_TEXT] = HandleDebugTextScreen, }; -void MainLoop(void) { +static void sub_080560B8(void); + +void AgbMain(void) { int var0; sub_08055F70(); @@ -36,7 +41,7 @@ void MainLoop(void) { MessageInitialize(); sub_080ADD30(); gRand = 0x1234567; - MemClear32(&gMain, sizeof(gMain)); + MemClear(&gMain, sizeof(gMain)); InitScreen(SCREEN_INTRO); while (1) { ReadKeyInput(); @@ -92,7 +97,7 @@ static void sub_08055F70(void) { *(vu16*)BG_PLTT = 0x7FFF; REG_WAITCNT = WAITCNT_PREFETCH_ENABLE | WAITCNT_WS0_S_1 | WAITCNT_WS0_N_3; size = 0x3FFD0; - MemClear32(gUnk_02000030, size); + MemClear(gUnk_02000030, size); size = (u32)gUnk_080B2CD8 - (u32)sub_080B197C; if (size != 0) { MemCopy(sub_080B197C, gUnk_030056F0, size); @@ -103,7 +108,7 @@ static void sub_08055F70(void) { MemCopy(gUnk_080B2CD8_3, gUnk_02038560, size); } - sub_0801DA90(0); + DispReset(0); sub_08016B34(); } @@ -146,21 +151,21 @@ typedef struct { u8 name[6]; u8 _e; u8 _f; -} test; +} Defaults; -const test sDefaultSettings = { +const Defaults sDefaultSettings = { .signature = SIGNATURE, .saveFileId = 0, .messageSpeed = 1, .brightnessPref = 1, - .gameLanguage = LANGUAGE_EN, + .gameLanguage = GAME_LANGUAGE, .name = "LINK", ._e = 0, ._f = 0, }; // single misplaced ldr -NONMATCH("asm/non_matching/sub_080560B8.inc", void sub_080560B8(void)) { +NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) { u32 temp; u32 b; @@ -182,10 +187,10 @@ NONMATCH("asm/non_matching/sub_080560B8.inc", void sub_080560B8(void)) { b = BOOLCAST(temp); if ((gUnk_02000010.field_0x4 != 0) && (gUnk_02000010.field_0x4 != 0xc1)) { - b = 1; + b = TRUE; } - if (b != 0) { - MemClear32((u8*)&gUnk_02000010.signature, 0x20); + if (b) { + MemClear((u8*)&gUnk_02000010.signature, 0x20); gUnk_02000010.signature = SIGNATURE; } } @@ -201,7 +206,7 @@ u32 sub_08056134(void) { } void InitDMA() { - SoundReq(0x80040000); + SoundReq(SND_VSYNC_OFF); gScreen._6d = gScreen._6c; gScreen._6c = 0; @@ -214,7 +219,7 @@ void InitDMA() { } void sub_08056208() { - SoundReq(0x80060000); + SoundReq(SND_VSYNC_ON); gScreen._6c = gScreen._6d; gScreen._6d = 0; } @@ -250,7 +255,7 @@ void sub_08056260(void) { temp2->field_0x1 = 0; } -// Convert in-game AABB to screen coordinates and check if it's within the viewport +// 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 result; u32 x = ((gRoomControls.roomScrollX - gRoomControls.roomOriginX) - x0 + DISPLAY_WIDTH); diff --git a/src/manager/manager1.c b/src/manager/manager1.c index 2b06a48f..45e1b000 100644 --- a/src/manager/manager1.c +++ b/src/manager/manager1.c @@ -1,12 +1,11 @@ #include "global.h" #include "entity.h" #include "screen.h" +#include "functions.h" -extern void LoadGfxGroup(u32); extern void sub_08056250(void); extern void sub_080570B8(Entity*); void sub_080570F8(void); -extern void sub_08052D74(void*, void*, void*); extern void (*const gUnk_08107C5C[])(Entity*); extern void (*const gUnk_08107C48[])(Entity*); diff --git a/src/manager/manager15.c b/src/manager/manager15.c index 87135c56..295f14c7 100644 --- a/src/manager/manager15.c +++ b/src/manager/manager15.c @@ -1,4 +1,5 @@ #include "global.h" +#include "audio.h" #include "flags.h" #include "screen.h" #include "manager.h" @@ -78,15 +79,15 @@ extern Entity gUnk_080E4C08; void sub_0805A370(Manager15* this) { if (this->manager.unk_0d) { - LoadRoomEntityList(&gUnk_080E4C08); + LoadRoomEntityList((EntityData*)&gUnk_080E4C08); this->manager.action = 3; - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); } } void sub_0805A394(Manager15* this) { Entity* ent; - if ((ent = FindEntityInListBySubtype(0x3, 0x13, 0x4))) { + if ((ent = FindEntityByID(0x3, 0x13, 0x4))) { if (ent->type != 4) { return; } @@ -251,10 +252,10 @@ void sub_0805A664(Manager15* this) { sub_0805A68C(this); } -extern u32 sub_0806FBFC(u32, u32, u32, u32); +extern u32 CheckPlayerProximity(u32, u32, u32, u32); void sub_0805A68C(Manager15* this) { - if (sub_0806FBFC(this->unk_38 - 0x18, this->unk_3a - 0x18, 0x30, 0x30)) { + if (CheckPlayerProximity(this->unk_38 - 0x18, this->unk_3a - 0x18, 0x30, 0x30)) { if (this->unk_2c <= 0x1007) { gScreen.controls.alphaBlend = ++this->unk_2c; this->unk_22 = 0; @@ -285,7 +286,7 @@ void sub_0805A6E8(Manager15* this) { } u32 sub_0805A73C(Manager15* this) { - return sub_0806FBFC(this->unk_38 - 0x6, this->unk_3a - 0x6, 0xC, 0xC); + return CheckPlayerProximity(this->unk_38 - 0x6, this->unk_3a - 0x6, 0xC, 0xC); } void sub_0805A758(Manager15* this) { @@ -295,7 +296,6 @@ void sub_0805A758(Manager15* this) { } extern void sub_0805E4E0(Manager*, u32); -extern void sub_08077B20(void); void sub_0805A76C(Manager15* this) { if ((gPlayerEntity.currentHealth != 0) && (gPlayerEntity.height.HALF.HI == 0) && (!gPlayerState.field_0x2c)) { @@ -364,7 +364,6 @@ void sub_0805A804(Manager15* this) { } void sub_0805AAC8(Manager15*); -extern void sub_08052D74(void*, void*, void*); void sub_0805A89C(Manager15* this) { sub_0805E3A0(this, 6); diff --git a/src/manager/manager1A.c b/src/manager/manager1A.c index 19a1dbca..379ac5b9 100644 --- a/src/manager/manager1A.c +++ b/src/manager/manager1A.c @@ -4,6 +4,7 @@ #include "entity.h" #include "room.h" #include "screen.h" +#include "utils.h" #include "functions.h" typedef struct { @@ -30,7 +31,7 @@ void sub_0805B030(Manager1A* this) { } extern void sub_08052D74(void*, void*, void*); -extern u32 sub_0806FBFC(u32, u32, u32, u32); +extern u32 CheckPlayerProximity(u32, u32, u32, u32); typedef struct struct_08108764 { u8 unk_00; @@ -65,13 +66,12 @@ u32 sub_0805B1CC(Manager1A*); void sub_0805B210(Manager1A*); void sub_0805B2B0(Manager1A*); void sub_0805B328(Manager1A*); -void sub_0805BC4C(void); void sub_0805B048(Manager1A* this) { struct_08108764* tmp; Entity* obj; sub_0805E3A0(&this->manager, 6); - MemClear32(&this->unk_20, 0x20); + MemClear(&this->unk_20, 0x20); this->manager.action = 1; this->unk_3f = gRoomControls.roomID; tmp = &gUnk_08108764[this->manager.unk_0a]; @@ -138,7 +138,7 @@ void sub_0805B168(Manager1A* this) { u32 sub_0805B1CC(Manager1A* this) { u32 re = 0; - if (sub_0806FBFC(this->unk_20, this->unk_22, this->unk_24, this->unk_26)) { + if (CheckPlayerProximity(this->unk_20, this->unk_22, this->unk_24, this->unk_26)) { if ((gPlayerState.flags.all & 0x4) && (gPlayerState.flags.all & 0x1)) { gPlayerState.flags.all |= 0x8000; } else if (gPlayerState.flags.all & 0x8000) { @@ -224,5 +224,5 @@ void sub_0805B390(u32 unk1) { tmp->type = 0x9; tmp->subtype = 0x1A; tmp->unk_0a = unk1; - AppendEntityToList(tmp, 6); + AppendEntityToList((Entity*)tmp, 6); } diff --git a/src/manager/manager1E.c b/src/manager/manager1E.c index 363c3113..fad34ef4 100644 --- a/src/manager/manager1E.c +++ b/src/manager/manager1E.c @@ -1,7 +1,6 @@ #include "global.h" #include "manager.h" #include "flags.h" -#include "player.h" #include "functions.h" typedef struct { @@ -17,7 +16,6 @@ typedef struct { enum Manager1E_State { Init, ObserveRegion }; -void Manager1E_Handler(Manager1E*); void Manager1E_Init(Manager1E*); void Manager1E_ObserveRegion(Manager1E*); diff --git a/src/manager/manager2.c b/src/manager/manager2.c index 56c81310..b6e0eef7 100644 --- a/src/manager/manager2.c +++ b/src/manager/manager2.c @@ -1,9 +1,9 @@ #include "global.h" #include "entity.h" #include "screen.h" +#include "functions.h" extern void sub_080576A0(); -extern void sub_08052D74(); extern void sub_0805754C(Entity*); void Manager2(Entity* this) { diff --git a/src/manager/manager20.c b/src/manager/manager20.c index b8a20f5f..f7ca8a0b 100644 --- a/src/manager/manager20.c +++ b/src/manager/manager20.c @@ -3,6 +3,7 @@ #include "flags.h" #include "entity.h" #include "room.h" +#include "functions.h" typedef struct { Manager manager; @@ -17,8 +18,6 @@ typedef struct { u16 unk_3e; } Manager20; -extern void DeleteManager(Manager20*); - void sub_0805B7A0(Manager20* this) { Entity* tmp = CreateObject(this->manager.unk_0e, this->manager.unk_0a, this->manager.unk_0b); if (!tmp) @@ -35,5 +34,5 @@ void sub_0805B7A0(Manager20* this) { } tmp->x.HALF.HI += gRoomControls.roomOriginX; tmp->y.HALF.HI += gRoomControls.roomOriginY; - DeleteManager(this); + DeleteManager((Manager*)this); } diff --git a/src/manager/manager27.c b/src/manager/manager27.c index b2e0e15a..6540c1ad 100644 --- a/src/manager/manager27.c +++ b/src/manager/manager27.c @@ -1,10 +1,10 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "flags.h" #include "functions.h" extern u32 sub_0805C920(Entity*); -extern void LoadPaletteGroup(u32); void sub_0805C874(Entity*); void sub_0805C894(Entity*); @@ -42,7 +42,7 @@ void sub_0805C894(Entity* this) { if (sub_0805C920(this)) { this->action = 2; this->actionDelay = 1; - SoundReq(0x11a); + SoundReq(SFX_EM_ARMOS_ON); } } @@ -58,7 +58,7 @@ void sub_0805C8B4(Entity* this) { } LoadPaletteGroup(gUnk_08108D20[this->field_0xf]); if (this->field_0xf == 0) { - SoundReq(0x11a); + SoundReq(SFX_EM_ARMOS_ON); } } if (sub_0805C920(this) == 0) { diff --git a/src/manager/manager28.c b/src/manager/manager28.c index af59e09e..1e2eb829 100644 --- a/src/manager/manager28.c +++ b/src/manager/manager28.c @@ -11,7 +11,6 @@ typedef struct { } d; } Manager28; -void Manager28_Entry(Manager28*); void Manager28_Init(Manager28*); void Manager28_Main(Manager28*); u32 Manager28_FindMatchingEntities(Manager28*); @@ -47,7 +46,7 @@ void Manager28_Init(Manager28* this) { /* tmp3->enemies[tmp4] = this->enemies[tmp4]; */ /* } */ tmp3->d = this->d; - AppendEntityToList(tmp3, 6); + AppendEntityToList((Entity*)tmp3, 6); } } DeleteManager(&this->manager); @@ -86,10 +85,10 @@ u32 Manager28_FindMatchingEntities(Manager28* this) { EntityData* tmp = GetCurrentRoomProperty(this->manager.unk_0b); if (!tmp) return 0; - for (; *((u8*)tmp) != 0xFF && !(tmp->type == 9 && tmp->subtype == 0x28); tmp++) { + for (; *((u8*)tmp) != 0xFF && !(tmp->kind == 9 && tmp->id == 0x28); tmp++) { Entity* tmp2; u32 i; - if (tmp->type != 3) + if (tmp->kind != 3) continue; tmp2 = Manager28_FindMatchingEntity(tmp); if (!tmp2) @@ -115,7 +114,7 @@ Entity* Manager28_FindMatchingEntity(EntityData* unk1) { y = unk1->yPos + gRoomControls.roomOriginY; tmp = &gUnk_03003D90; for (i = tmp->first; (u32)i != (u32)tmp; i = i->next) { - if (x == i->x.HALF.HI && y == i->y.HALF.HI && unk1->subtype == i->id && 3 == i->kind && unk1->form == i->type) { + if (x == i->x.HALF.HI && y == i->y.HALF.HI && unk1->id == i->id && 3 == i->kind && unk1->type == i->type) { return i; } } diff --git a/src/manager/manager3.c b/src/manager/manager3.c index 5234f149..acd83825 100644 --- a/src/manager/manager3.c +++ b/src/manager/manager3.c @@ -4,8 +4,11 @@ #include "area.h" #include "room.h" #include "player.h" +#include "random.h" #include "functions.h" +// Facilitates the usage of minish portals. + typedef struct { Manager manager; u32 unk_20; @@ -21,7 +24,7 @@ typedef struct { } Manager3; extern s8 gUnk_08107C6C[]; -extern u32 sub_0806FBFC(u32, u32, u32, u32); +extern u32 CheckPlayerProximity(u32, u32, u32, u32); extern u32 sub_08057810(void); extern u32 sub_080002C0(u16, u16, u8); extern void sub_080577AC(u32, u32, u32); @@ -34,14 +37,14 @@ void sub_080576C0(Manager3* this) { this->unk_24 = this->unk_3a + gRoomControls.roomOriginY - 0x20; return; } - if (sub_0806FBFC(this->unk_20, this->unk_24, 0x40, 0x40)) { - gArea.field_0x12 = this->unk_20 + 0x20; - gArea.field_0x14 = this->unk_24 + 0x20 + gUnk_08107C6C[this->manager.unk_0a]; - gArea.field_0x16 = this->unk_34; - gArea.field_0x17 = this->manager.unk_0a; + if (CheckPlayerProximity(this->unk_20, this->unk_24, 0x40, 0x40)) { + gArea.curPortalX = this->unk_20 + 0x20; + gArea.curPortalY = this->unk_24 + 0x20 + gUnk_08107C6C[this->manager.unk_0a]; + gArea.curPortalExitDirection = this->unk_34; + gArea.curPortalType = this->manager.unk_0a; if (!CheckGlobalFlag(EZERO_1ST)) { gArea.field_0x18 = 1; - gArea.field_0x17 = 5; + gArea.curPortalType = 5; } else { if ((gPlayerState.flags.all & 0x20) && gPlayerState.jumpStatus == 0) { gArea.field_0x18 = 2; @@ -90,7 +93,7 @@ void sub_080577AC(u32 baseX, u32 baseY, u32 layer) { } u32 sub_08057810(void) { - if ((gPlayerState.flags.all & 0x80) && !gPlayerState.field_0xaa && (gArea.field_0x17 != 0x6) && + if ((gPlayerState.flags.all & 0x80) && !gPlayerState.field_0xaa && (gArea.curPortalType != 0x6) && (gPlayerState.heldObject == 0)) { switch (gPlayerState.field_0xa8) { case 0: diff --git a/src/manager/manager30.c b/src/manager/manager30.c index 8cfde746..94f3be33 100644 --- a/src/manager/manager30.c +++ b/src/manager/manager30.c @@ -1,4 +1,5 @@ #include "global.h" +#include "audio.h" #include "manager.h" #include "flags.h" #include "functions.h" @@ -19,8 +20,6 @@ typedef struct Manager30 { u16 flag_reset; } Manager30; -extern void sub_0807B7D8(u32, u32, u32); - enum { INIT, IN_PROGRESS, FAILED, SUCCEEDED }; /* @@ -48,13 +47,13 @@ void Manager30_Main(Manager30* this) { case 0x317: // stepped on a red tile again this->manager.action = FAILED; - SoundReq(0x6d); + SoundReq(SFX_MENU_ERROR); break; case 0x318: // stepped on a blue tile // turn the tile into a red tile sub_0807B7D8(0x317, this->player_current_tile, this->manager.unk_0b); - SoundReq(0x6b); + SoundReq(SFX_6B); // decrease the number of remaining tiles and check if we're done if (--this->manager.unk_0e == 0) { this->manager.action = SUCCEEDED; @@ -89,7 +88,7 @@ void Manager30_Main(Manager30* this) { SetFlag(this->flag_succeeded); } } else { - SoundReq(0x72); + SoundReq(SFX_SECRET); } } } diff --git a/src/manager/manager39.c b/src/manager/manager39.c index 31cbda7e..cdac7c61 100644 --- a/src/manager/manager39.c +++ b/src/manager/manager39.c @@ -3,6 +3,8 @@ #include "screen.h" #include "area.h" #include "textbox.h" +#include "utils.h" +#include "game.h" #include "functions.h" typedef struct { @@ -25,9 +27,7 @@ extern const u8 gUnk_08108E30[0x18]; extern const u8 gUnk_08108E48[0x18]; extern const u8 gUnk_08108E60[]; -extern void MemCopy(const void* src, void* dest, u32 size); extern void sub_0805F46C(void*, const void*); -extern u32 CheckIsDungeon(void); extern void sub_0805E5B4(void); void sub_0805E140(Manager39*); @@ -68,7 +68,7 @@ void sub_0805E18C(Manager39* this) { } void sub_0805E1D8(Manager39* this) { - MemClear32(&gUnk_02034DF0, 0x80); + MemClear(&gUnk_02034DF0, 0x80); gScreen.bg.bg0Updated = 1; DeleteThisEntity(); } @@ -81,7 +81,7 @@ void sub_0805E1F8(u32 unk0, u32 unk1) { u8 unk_06[3]; } PACKED tmp; const u8* tmp2; - MemClear32(&gUnk_02034DF0, 0x80); + MemClear(&gUnk_02034DF0, 0x80); MemCopy(gUnk_08108E60, &tmp, sizeof(tmp)); tmp.unk_04 = unk0 >> 8; tmp.unk_05 = unk0; diff --git a/src/manager/manager4.c b/src/manager/manager4.c index 2ebdf7d3..3d396682 100644 --- a/src/manager/manager4.c +++ b/src/manager/manager4.c @@ -3,6 +3,7 @@ #include "room.h" #include "manager.h" #include "structures.h" +#include "functions.h" extern void (*gUnk_08107C70[])(Manager*); @@ -12,8 +13,6 @@ void sub_08057854(Manager* this) { extern void sub_080805F8(void); -extern void SetTile(u32, u32, u32); - extern DiggingCaveEntrance* sub_08057AA8(DiggingCaveEntrance*, int); void sub_0805786C(Manager* this) { @@ -101,8 +100,6 @@ u32 sub_0805795C(Manager* this, DiggingCaveEntrance* entr) { } #endif -extern void sub_0805E5A8(void); -extern void DeleteManager(Manager*); extern void sub_08080930(); void sub_08057A18(Manager* this, DiggingCaveEntrance* entr) { diff --git a/src/manager/manager5.c b/src/manager/manager5.c index ec7ee400..fbb4da2e 100644 --- a/src/manager/manager5.c +++ b/src/manager/manager5.c @@ -1,4 +1,5 @@ #include "global.h" +#include "audio.h" #include "manager.h" #include "flags.h" #include "functions.h" @@ -34,8 +35,6 @@ void sub_08057AD0(Manager5* this) { void sub_08057CA4(Manager5*, u32, u32); -extern void DeleteManager(Manager*); - void sub_08057AE8(Manager5* this) { u32 tmp; tmp = (this->manager.unk_0b & 0x3) << 1; @@ -71,14 +70,14 @@ void sub_08057BA4(Manager5* this) { sub_08057CA4(this, this->unk_28, this->unk_2a); sub_0807B7D8(this->unk_30, this->unk_38 | (this->unk_3a << 6), this->unk_3c); this->manager.unk_0f++; - SoundReq(0x71); + SoundReq(SFX_HEART_GET); } else { if (!this->manager.unk_0f) return; sub_0807BA8C(this->unk_38 | (this->unk_3a << 6), this->unk_3c); sub_08057CA4(this, this->unk_2c, this->unk_2e); this->manager.unk_0f--; - SoundReq(0x71); + SoundReq(SFX_HEART_GET); } } @@ -95,10 +94,10 @@ void sub_08057C28(Manager5* this) { sub_08057CA4(this, this->unk_28, this->unk_2a); sub_0807B7D8(this->unk_30, this->unk_38 | (this->unk_3a << 6), this->unk_3c); this->manager.unk_0f++; - SoundReq(0x71); + SoundReq(SFX_HEART_GET); } else { if (this->unk_30 != 0x323) { - SoundReq(0x72); + SoundReq(SFX_SECRET); } DeleteManager(&this->manager); } diff --git a/src/manager/manager6.c b/src/manager/manager6.c index aa5cb48a..ff32b405 100644 --- a/src/manager/manager6.c +++ b/src/manager/manager6.c @@ -1,12 +1,9 @@ #include "global.h" -#include "entity.h" #include "player.h" #include "manager.h" +#include "functions.h" -extern void* GetCurrentRoomProperty(u8); -extern u32 CheckPlayerInRegion(u16, u16, u8, u8); extern void DoExitTransition(void*); -extern void DeleteManager(Entity*); void sub_08057CB4(Manager6* this) { u32 tmp; @@ -15,7 +12,7 @@ void sub_08057CB4(Manager6* this) { this->manager.action = 1; this->warpList = GetCurrentRoomProperty(this->manager.unk_0a); if (!this->warpList) { - DeleteManager((Entity*)this); + DeleteManager(&this->manager); return; } } diff --git a/src/manager/manager7.c b/src/manager/manager7.c index 3a2cbb1a..089dab1b 100644 --- a/src/manager/manager7.c +++ b/src/manager/manager7.c @@ -12,12 +12,9 @@ typedef struct { void sub_08057E30(); u32 sub_08057E40(); -void sub_08057E64(); void sub_08057E7C(u32); -extern void sub_08052D74(); extern u32 sub_08056300(const u16*); -extern void sub_0805E3A0(); extern const u8 gGlobalGfxAndPalettes[]; diff --git a/src/manager/manager8.c b/src/manager/manager8.c index c6cd5075..aa80b627 100644 --- a/src/manager/manager8.c +++ b/src/manager/manager8.c @@ -17,8 +17,6 @@ void sub_08057EFC(); void sub_08058034(void); void sub_08058084(u16*, u16*); -extern void sub_08052D74(void*, void*, void*); - extern u16 gMapDataTopSpecial[]; void sub_08057ED0(Manager8* this) { diff --git a/src/manager/manager9.c b/src/manager/manager9.c index 70d117fb..aebc9a96 100644 --- a/src/manager/manager9.c +++ b/src/manager/manager9.c @@ -15,7 +15,6 @@ void sub_08058210(Manager9*); u32 sub_08058244(int); void sub_080582A0(u32, u32*, u8*); void sub_080582F8(u8*, u8*); -void sub_08058324(); extern u32 gUnk_02006F00[]; extern u8 gBG3Buffer[]; diff --git a/src/manager/managerA.c b/src/manager/managerA.c index 3033dd21..4b4a2ce4 100644 --- a/src/manager/managerA.c +++ b/src/manager/managerA.c @@ -4,6 +4,7 @@ #include "manager.h" #include "flags.h" #include "area.h" +#include "functions.h" void sub_08058398(ManagerA*); void sub_080583EC(ManagerA*); @@ -17,8 +18,6 @@ void sub_08058380(ManagerA* this) { gUnk_081081F4[this->manager.action](this); } -extern void sub_0805E3A0(Manager*, u32); - void sub_08058398(ManagerA* this) { if (CheckFlags(this->unk_3c) != 0) { @@ -36,8 +35,6 @@ void sub_08058398(ManagerA* this) { } } -void sub_08058408(ManagerA*); - void sub_080583EC(ManagerA* this) { if (CheckFlags(this->unk_3e) != 0) { this->manager.action = 2; @@ -45,12 +42,8 @@ void sub_080583EC(ManagerA* this) { } } -extern u32 CheckPlayerInRegion(u32, u32, u32, u32); extern void sub_0805E544(void); -extern void sub_08078A90(u32); -extern void sub_08078AA8(u32, u32); extern void sub_080186C0(u16); -extern void sub_08078B48(void); u32 sub_0805848C(ManagerA*); void sub_080585DC(ManagerA*); diff --git a/src/manager/managerB.c b/src/manager/managerB.c index e6e43a12..ca298178 100644 --- a/src/manager/managerB.c +++ b/src/manager/managerB.c @@ -4,6 +4,7 @@ #include "entity.h" #include "room.h" #include "area.h" +#include "utils.h" #include "functions.h" /* @@ -128,8 +129,8 @@ ManagerBHelper* CreateHelper(Manager* this) { extra->manager.unk_0a = 1; extra->manager.parent = this; this->unk_0e++; - MemClear32(&extra->enemies, 0x20); - AppendEntityToList(extra, 8); + MemClear(&extra->enemies, 0x20); + AppendEntityToList((Entity*)extra, 8); } return extra; } diff --git a/src/manager/managerC.c b/src/manager/managerC.c index 72529c2f..83b35412 100644 --- a/src/manager/managerC.c +++ b/src/manager/managerC.c @@ -1,11 +1,11 @@ #include "global.h" +#include "audio.h" #include "manager.h" #include "flags.h" #include "structures.h" #include "room.h" -#include "area.h" #include "screen.h" -#include "trig.h" +#include "coord.h" #include "functions.h" #include "save.h" @@ -40,12 +40,9 @@ void sub_08058A04(ManagerC*); void sub_080588F8(ManagerC*); u32 sub_08058B08(ManagerC*, u32, u32, const struct_08108228*); void sub_08058B5C(ManagerC*, u32); -void sub_08058D34(void); extern void sub_0805622C(struct BgAffineDstData*, u32, u32); -extern void sub_08052D74(void*, void*, void*); extern void sub_080044AE(Entity*, u32, u32); -extern void MemCopy(const void* src, void* dest, u32 size); extern u8 gUnk_03003DE4[0xC]; @@ -88,7 +85,7 @@ void sub_080588CC(ManagerC* this) { void nullsub_108(ManagerC* this) { } -#define ABS_DIFF_GT(a, b, c) (signed)a - b >= 0 ? a - b > c : b - a > c +#define ABS_DIFF_GT(a, b, c) ((signed)(a) - (b) >= 0 ? (a) - (b) > (c) : (b) - (a) > (c)) void sub_080588F8(ManagerC* this) { if (this->manager.unk_0f == 0) { @@ -100,7 +97,7 @@ void sub_080588F8(ManagerC* this) { case 0xf0: this->unk_28 = this->unk_24.HALF.HI; this->manager.unk_0f = 0x2D; - SoundReq(0x8c); + SoundReq(SFX_BARREL_ROLL_STOP); } } } else { @@ -123,7 +120,7 @@ void sub_080588F8(ManagerC* this) { } if (ABS_DIFF_GT(this->unk_2c, this->unk_24.WORD, 0x100000)) { this->unk_2c = this->unk_24.WORD; - SoundReq(0x8b); + SoundReq(SFX_BARREL_ROLL); } } } @@ -213,7 +210,7 @@ void sub_08058B5C(ManagerC* this, u32 unk1) { gScreenTransition.playerStartPos.HALF.x = gUnk_081082E8[unk1 * 3]; gScreenTransition.playerStartPos.HALF.y = gUnk_081082E8[unk1 * 3 + 1]; gSave.unk7 = gUnk_081082E8[unk1 * 3 + 2]; - SoundReq(0x121); + SoundReq(SFX_STAIRS); } void sub_08058BC8(ManagerC* this) { diff --git a/src/manager/managerE.c b/src/manager/managerE.c index 0f5e9328..44bfb5a7 100644 --- a/src/manager/managerE.c +++ b/src/manager/managerE.c @@ -3,13 +3,7 @@ #include "manager.h" #include "flags.h" #include "room.h" - -extern void LoadRoomEntityList(Entity*); -extern void DeleteThisEntity(void); -extern void DeleteManager(Manager*); -extern void sub_08078A90(u32); -extern void sub_08078B48(void); -extern void SoundReq(u32); +#include "functions.h" void sub_08058E60(ManagerE* this) { if (!this->manager.action) { @@ -1,5 +1,4 @@ #include "global.h" -#include "functions.h" #include "entity.h" #include "npc.h" diff --git a/src/npc/anju.c b/src/npc/anju.c index d77c5356..e0fb08c8 100644 --- a/src/npc/anju.c +++ b/src/npc/anju.c @@ -1,18 +1,9 @@ #include "global.h" #include "entity.h" #include "player.h" -#include "room.h" -#include "flags.h" -#include "sprite.h" -#include "textbox.h" #include "npc.h" #include "script.h" - -extern void sub_0805E3A0(Entity*, u32); -extern u32 sub_0806F5A4(u32); -extern void sub_0806F118(Entity*); -extern u32 sub_0801E99C(void); -extern void sub_08078784(Entity*, u32); +#include "functions.h" void Anju(Entity* this) { switch (this->action) { @@ -41,7 +32,7 @@ void Anju(Entity* this) { } void sub_0806C354(Entity* this) { - this->field_0x68.HALF.LO = sub_0801E99C(); + this->field_0x68.HALF.LO = sub_0801E99C(this); sub_08078784(this, this->field_0x68.HALF.LO); } diff --git a/src/npc/beedle.c b/src/npc/beedle.c index 3e09302f..b4d25858 100644 --- a/src/npc/beedle.c +++ b/src/npc/beedle.c @@ -159,6 +159,6 @@ void sub_080634EC(Entity* this) { void sub_08063504(Entity* this, ScriptExecutionContext* context) { u32 uVar1; - uVar1 = sub_080544DC(gUnk_0810C88C[this->type2]); + uVar1 = GetBottleContaining(gUnk_0810C88C[this->type2]); context->condition = BOOLCAST(uVar1); } diff --git a/src/npc/bigGoron.c b/src/npc/bigGoron.c index d4896ce9..3123b036 100644 --- a/src/npc/bigGoron.c +++ b/src/npc/bigGoron.c @@ -2,16 +2,13 @@ #include "entity.h" #include "player.h" #include "structures.h" -#include "functions.h" #include "script.h" +#include "random.h" +#include "functions.h" extern void (*gUnk_081140D4[])(Entity*); extern u16 gUnk_081140CC[]; -extern void sub_0806D0B0(Entity*); -extern void SoundReq(u32); -extern void sub_0806D02C(Entity*); -extern Entity* FindEntityInListByForm(u32, u32, u32, u32, u32); void BigGoron(Entity* this) { gUnk_081140D4[this->type](this); @@ -20,7 +17,7 @@ void BigGoron(Entity* this) { void sub_0806CF30(Entity* this) { if (this->action == 0) { this->action = 1; - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x68.HWORD = this->x.HALF.HI; sub_0805E3A0(this, 2); sub_0806D0B0(this); @@ -30,7 +27,7 @@ void sub_0806CF30(Entity* this) { HandleEntity0x82Actions(this); } - switch (this->previousActionFlag) { + switch (this->subAction) { case 0: case 1: if (gScreenTransition.frameCount % 4 == 0) { @@ -59,7 +56,7 @@ void sub_0806CF30(Entity* this) { void sub_0806D00C(Entity* this) { Entity* pEVar1; - pEVar1 = FindEntityInListByForm(7, 76, 7, 0, 0); + pEVar1 = FindEntity(7, 76, 7, 0, 0); if (pEVar1 != NULL) { this->parent = pEVar1; } diff --git a/src/npc/bladeBrothers.c b/src/npc/bladeBrothers.c index b08f2e48..49a86dfc 100644 --- a/src/npc/bladeBrothers.c +++ b/src/npc/bladeBrothers.c @@ -1,12 +1,13 @@ #include "global.h" #include "entity.h" -#include "functions.h" #include "flags.h" #include "player.h" #include "room.h" #include "textbox.h" #include "save.h" #include "script.h" +#include "npc.h" +#include "functions.h" extern void (*gUnk_081115C0[])(Entity*); extern void (*gUnk_081115D0[])(Entity*); @@ -132,7 +133,7 @@ void FUN_08068b2c(Entity* this) { } void sub_08068B70(Entity* this) { - if (UpdateFuseInteraction()) { + if (UpdateFuseInteraction(this)) { this->action = 1; } } diff --git a/src/npc/carlov.c b/src/npc/carlov.c index a091f54f..92d632ed 100644 --- a/src/npc/carlov.c +++ b/src/npc/carlov.c @@ -1,15 +1,9 @@ #include "global.h" #include "entity.h" -#include "player.h" #include "room.h" -#include "flags.h" -#include "sprite.h" -#include "textbox.h" #include "npc.h" -#include "structures.h" #include "script.h" - -extern void EnqueueSFX(u32); +#include "functions.h" void Carlov(Entity* this) { if (this->action == 0) { diff --git a/src/npc/carpenter.c b/src/npc/carpenter.c index 1d8209b1..21f8db14 100644 --- a/src/npc/carpenter.c +++ b/src/npc/carpenter.c @@ -2,18 +2,11 @@ #include "entity.h" #include "sprite.h" #include "player.h" +#include "npc.h" +#include "functions.h" #include "script.h" -extern void DeleteThisEntity(); -extern u32 LoadExtraSpriteData(Entity*, SpriteLoadData*); extern SpriteLoadData gUnk_08110CA8[]; -extern void sub_0805E3A0(Entity*, u32); -extern u32 GetFacingDirection(Entity*, Entity*); -extern void sub_0806F118(Entity*); -extern u32 UpdateFuseInteraction(Entity*); -extern void SetSpriteSubEntryOffsetData2(Entity*, u32, u32); -extern void sub_0807000C(Entity*); -extern u32 sub_0806F5A4(); void Carpenter(Entity* this) { if (*(u32*)&this->cutsceneBeh == 0) { diff --git a/src/npc/cow.c b/src/npc/cow.c index d5e7988d..411b139f 100644 --- a/src/npc/cow.c +++ b/src/npc/cow.c @@ -1,22 +1,17 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "player.h" +#include "random.h" +#include "npc.h" #include "functions.h" -extern void sub_0806920C(Entity*); -extern u32 sub_0805ACC0(Entity*); -extern u32 sub_0801E99C(Entity*); -extern void sub_0806924C(Entity*); -extern void sub_08078778(Entity*); -extern void sub_080787A8(Entity*, u32); -extern void sub_0806F118(Entity*); -extern void sub_080791D0(); +void sub_0806920C(Entity* ent); +void sub_0806924C(Entity* ent); + extern void (*gUnk_08111914[])(Entity*); extern void (*gUnk_08111928[])(Entity*); extern Dialog gUnk_08111938[]; -extern void SoundReq(u32); -extern u32 UpdateFuseInteraction(Entity*); -extern PlayerState gPlayerState; void Cow(Entity* ent) { gUnk_08111914[ent->action](ent); @@ -56,8 +51,8 @@ void sub_08068FC0(Entity* ent) { void sub_08069018(Entity* ent) { s32 var0; - if (ent->previousActionFlag == 0) { - ent->previousActionFlag++; + if (ent->subAction == 0) { + ent->subAction++; ent->field_0xf = (Random() & 0x3F) + 0x3C; InitAnimationForceUpdate(ent, ent->animationState); } @@ -70,7 +65,7 @@ void sub_08069018(Entity* ent) { } else { ent->action = 3; } - ent->previousActionFlag = var0; + ent->subAction = var0; } sub_0806924C(ent); @@ -79,10 +74,10 @@ void sub_08069018(Entity* ent) { void sub_08069068(Entity* ent) { s32 var0; - if (ent->previousActionFlag == 0) { + if (ent->subAction == 0) { u32 anim; - ent->previousActionFlag++; + ent->subAction++; anim = (Random() & 2) - 1; anim = (anim + ent->animationState) & 3; @@ -126,7 +121,7 @@ void sub_08069068(Entity* ent) { var0 = --ent->field_0xf; if (var0 == 0) { ent->action = 3; - ent->previousActionFlag = var0; + ent->subAction = var0; } sub_0806924C(ent); @@ -134,7 +129,7 @@ void sub_08069068(Entity* ent) { void sub_08069124(Entity* ent) { UpdateAnimationSingleFrame(ent); - gUnk_08111928[ent->previousActionFlag](ent); + gUnk_08111928[ent->subAction](ent); sub_0806924C(ent); } @@ -142,13 +137,13 @@ void sub_08069148(Entity* ent) { u32 var0 = Random() & 3; var0 += 3; ent->field_0xf = var0; - ent->previousActionFlag = 1; + ent->subAction = 1; InitAnimationForceUpdate(ent, ent->animationState + 8); } void sub_08069168(Entity* ent) { if ((s8)ent->frames.all < 0) { - ent->previousActionFlag = 2; + ent->subAction = 2; InitAnimationForceUpdate(ent, ent->animationState + 12); } } @@ -160,14 +155,14 @@ void sub_08069188(Entity* ent) { if (((s8)--ent->field_0xf) != 0) return; - ent->previousActionFlag = 3; + ent->subAction = 3; InitAnimationForceUpdate(ent, ent->animationState + 16); } void sub_080691BC(Entity* ent) { if ((s8)ent->frames.all < 0) { ent->action = 1; - ent->previousActionFlag = 0; + ent->subAction = 0; InitAnimationForceUpdate(ent, ent->animationState + 4); } } @@ -175,7 +170,7 @@ void sub_080691BC(Entity* ent) { void sub_080691E0(Entity* ent) { if (UpdateFuseInteraction(ent) != 0) { ent->action = 1; - ent->previousActionFlag = 0; + ent->subAction = 0; } } @@ -216,7 +211,7 @@ void sub_0806924C(Entity* ent) { Cow_ShowDialogue(ent); sub_080791D0(); } - SoundReq(212); + SoundReq(SFX_VO_COW); ent->interactType = 0; } } diff --git a/src/npc/dampe.c b/src/npc/dampe.c index d55840f7..6293bcd7 100644 --- a/src/npc/dampe.c +++ b/src/npc/dampe.c @@ -3,17 +3,11 @@ #include "player.h" #include "room.h" #include "flags.h" -#include "sprite.h" #include "textbox.h" #include "npc.h" +#include "functions.h" #include "script.h" -extern void sub_0805E3A0(Entity*, u32); -extern u32 sub_0806F5A4(u32); -extern void sub_0806F118(Entity*); -extern u32 sub_0801E99C(void); -extern void sub_08078784(Entity*, u32); - extern u16 gUnk_08113344[]; extern u16 gUnk_0811334A[]; @@ -44,7 +38,7 @@ void Dampe(Entity* this) { } void sub_0806BE3C(Entity* this) { - this->field_0x68.HALF.LO = sub_0801E99C(); + this->field_0x68.HALF.LO = sub_0801E99C(this); sub_08078784(this, this->field_0x68.HALF.LO); } diff --git a/src/npc/emma.c b/src/npc/emma.c index 3867cb87..f7a8577a 100644 --- a/src/npc/emma.c +++ b/src/npc/emma.c @@ -1,12 +1,12 @@ #include "global.h" #include "entity.h" #include "script.h" +#include "functions.h" extern u32 gUnk_0813AD10; extern u32 gUnk_0813AD24; extern u32 gUnk_0813AD38; -extern void sub_0805E3A0(Entity*, u32); extern void DoExitTransition(u32*); void Emma(Entity* this) { diff --git a/src/npc/epona.c b/src/npc/epona.c index a79ccd48..1846d4f9 100644 --- a/src/npc/epona.c +++ b/src/npc/epona.c @@ -1,7 +1,9 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "textbox.h" #include "player.h" +#include "npc.h" #include "functions.h" void sub_08065A64(Entity* this); @@ -43,7 +45,7 @@ void sub_08065A10(Entity* this) { } void sub_08065A34(Entity* this) { - if (UpdateFuseInteraction() != 0) { + if (UpdateFuseInteraction(this) != 0) { this->action = 1; InitAnimationForceUpdate(this, this->animationState / 2); } @@ -83,7 +85,7 @@ void sub_08065AA4(Entity* this) { sub_08065A50(this); sub_080791D0(); } - SoundReq(0xD3); + SoundReq(SFX_VO_EPONA); this->interactType = 0; } } diff --git a/src/npc/ezloCap.c b/src/npc/ezloCap.c index d16c99f1..a7b5593e 100644 --- a/src/npc/ezloCap.c +++ b/src/npc/ezloCap.c @@ -325,7 +325,6 @@ extern ScreenTransitionData gUnk_0813ACAC; extern ScreenTransitionData gUnk_0813ACC0; extern ScreenTransitionData gUnk_0813ACD4; extern ScreenTransitionData gUnk_0813ACE8; -extern ScreenTransitionData gUnk_0813AC5C; extern ScreenTransitionData gUnk_0813ACFC; // Array of pointers to ScreenTransitionData const ScreenTransitionData* const gUnk_081141A4[] = { &gUnk_0813AB6C, &gUnk_0813ABBC, &gUnk_0813ABE4, &gUnk_0813ABF8, diff --git a/src/npc/festari.c b/src/npc/festari.c index 53093ebf..e7bb336d 100644 --- a/src/npc/festari.c +++ b/src/npc/festari.c @@ -5,9 +5,6 @@ #include "player.h" #include "script.h" -extern u32 sub_0801E99C(Entity*); -extern void sub_08078784(Entity*, u32); -extern void sub_0806F118(Entity*); extern void sub_0805FF2C(Entity*, void*); extern void (*const gUnk_08109BBC[])(Entity*); diff --git a/src/npc/forestMinish.c b/src/npc/forestMinish.c index 7bcd03f3..e42500e8 100644 --- a/src/npc/forestMinish.c +++ b/src/npc/forestMinish.c @@ -4,22 +4,16 @@ #include "flags.h" #include "textbox.h" #include "player.h" -#include "structures.h" -#include "functions.h" #include "save.h" #include "script.h" +#include "random.h" +#include "createObject.h" +#include "structures.h" +#include "functions.h" -extern void sub_0806F118(Entity*); extern void sub_080600F0(Entity*); extern s32 sub_0806EDD8(Entity*, u32, u32); -extern u32 sub_0806F5B0(u32); -extern u32 sub_0801E99C(Entity*); -extern void sub_08078784(Entity*, u32); -extern void sub_0807000C(Entity*); extern void sub_08060158(Entity*); -extern u32 CheckKinstoneFused(u32); -extern Entity* FindEntityInListBySubtype(u32, u32, u32); -extern void DeleteEntity(Entity*); extern void ModBombs(s32); extern SpriteLoadData gUnk_0810A348; @@ -231,7 +225,7 @@ void sub_08060318(void) { int i; for (i = 2; i >= 0; i--) { - ent = FindEntityInListBySubtype(8, 2, 2); + ent = FindEntityByID(8, 2, 2); if (ent != NULL) { CreateDust(ent); DeleteEntity(ent); diff --git a/src/npc/gentari.c b/src/npc/gentari.c index c480de5a..cc086d8a 100644 --- a/src/npc/gentari.c +++ b/src/npc/gentari.c @@ -3,12 +3,7 @@ #include "npc.h" #include "player.h" #include "script.h" - -extern void sub_0805E3A0(Entity*, u32); -extern u32 sub_0801E99C(Entity*); -extern void sub_08078784(Entity*, u32); -extern u32 sub_0806F5A4(u32); -extern void sub_0806F118(Entity*); +#include "functions.h" void Gentari(Entity* this) { switch (this->action) { diff --git a/src/npc/goronMerchant.c b/src/npc/goronMerchant.c index 9fd402c5..5329bd15 100644 --- a/src/npc/goronMerchant.c +++ b/src/npc/goronMerchant.c @@ -84,12 +84,12 @@ void sub_08069660(Entity* this) { void sub_08069684(void) { Manager* mgr; - if (FindEntityInListBySubtype(9, 0x31, 8) == NULL) { + if (FindEntityByID(9, 0x31, 8) == NULL) { mgr = GetEmptyManager(); if (mgr != NULL) { mgr->type = 9; mgr->subtype = 0x31; - AppendEntityToList(mgr, 8); + AppendEntityToList((Entity*)mgr, 8); } } } diff --git a/src/npc/guard.c b/src/npc/guard.c index 081f9c10..d94827c4 100644 --- a/src/npc/guard.c +++ b/src/npc/guard.c @@ -5,6 +5,8 @@ #include "textbox.h" #include "room.h" #include "script.h" +#include "structures.h" +#include "functions.h" typedef struct { u32 unk; @@ -12,21 +14,14 @@ typedef struct { } struct_03003DB8; typedef struct { - u8 filler[8]; - u8 unk; -} ScreenTransition; + u32 unk; + u32 unk2; +} struct_08064050; extern void sub_08063D24(Entity*); -extern void sub_0806ED78(Entity*); -extern u32 GetFacingDirection(Entity*, Entity*); -extern u32 sub_0806F5A4(u32); extern void sub_0806EE20(Entity*); extern void sub_08064428(Entity*); -extern u32 sub_0805ACC0(Entity*); -extern void sub_0807000C(Entity*); extern void sub_0806EE04(Entity*, void*, u32); -extern Entity* sub_080A7EE0(int); -extern void sub_08078778(Entity*); void sub_08063DC8(Entity*); void sub_08063F20(Entity*); @@ -213,7 +208,7 @@ void sub_08064030(Entity* arg0, Entity* arg1) { } void sub_08064044(void) { - gScreenTransition.unk = 1; + gScreenTransition.transitioningOut = 1; } void sub_08064050(Entity* this, ScriptExecutionContext* context) { diff --git a/src/npc/mailbox.c b/src/npc/mailbox.c index 6ccdd0a8..bab9a8ba 100644 --- a/src/npc/mailbox.c +++ b/src/npc/mailbox.c @@ -1,8 +1,8 @@ #include "global.h" #include "entity.h" #include "textbox.h" +#include "functions.h" -extern void sub_0806ED78(Entity*); extern void sub_08063280(); extern void (*gMailboxBehaviors[4])(Entity*); diff --git a/src/npc/malon.c b/src/npc/malon.c index ca6d6eab..64febefe 100644 --- a/src/npc/malon.c +++ b/src/npc/malon.c @@ -1,9 +1,8 @@ #include "global.h" -#include "functions.h" #include "entity.h" #include "script.h" - -extern Entity gPlayerEntity; +#include "npc.h" +#include "functions.h" extern void (*gUnk_0810FF5C[])(Entity* this); extern void (*gUnk_0810FF64[])(Entity* this); @@ -58,12 +57,12 @@ void sub_08065900(Entity* this) { void sub_08065914(Entity* this) { Entity* target; - target = FindEntityInListBySubtype(7, 0x1F, 7); + target = FindEntityByID(7, 0x1F, 7); if (target != NULL) { PositionRelative(this, target, 0x180000, -0x10000); target->parent = this; } - target = FindEntityInListBySubtype(7, 0x20, 7); + target = FindEntityByID(7, 0x20, 7); if (target != NULL) { PositionRelative(this, target, 0x280000, 0); target->parent = this; diff --git a/src/npc/mayorHagen.c b/src/npc/mayorHagen.c index 38db736c..ae5f1e0e 100644 --- a/src/npc/mayorHagen.c +++ b/src/npc/mayorHagen.c @@ -1,25 +1,16 @@ #include "global.h" #include "entity.h" #include "player.h" -#include "room.h" #include "flags.h" -#include "sprite.h" -#include "textbox.h" #include "npc.h" #include "structures.h" #include "functions.h" #include "save.h" #include "script.h" -extern u32 sub_0806F5A4(u32); -extern void sub_0806F118(Entity*); -extern void sub_08078784(Entity*, u32); extern void sub_08078850(); extern u32 gUnk_08113F44; extern Dialog gUnk_08113F48[]; -extern u32 GetInventoryValue(u32); -extern u32 CheckLocalFlag(u32); -extern void SetLocalFlag(); void MayorHagen(Entity* this) { u32 v; diff --git a/src/npc/melari.c b/src/npc/melari.c index 86679811..a62b837b 100644 --- a/src/npc/melari.c +++ b/src/npc/melari.c @@ -2,20 +2,12 @@ #include "entity.h" #include "npc.h" #include "textbox.h" -#include "functions.h" #include "script.h" +#include "random.h" +#include "functions.h" extern void sub_08068780(Entity*); -extern void sub_08078778(Entity*); -extern void sub_0806F118(Entity*); -extern u32 sub_080040A8(Entity*); -extern void EnqueueSFX(u32); -extern u32 sub_0801E99C(Entity*); -extern void sub_08078784(Entity*, u32); -extern void sub_0807000C(Entity*); extern s32 sub_0806EDD8(Entity*, u32, u32); -extern void sub_080A7C18(u32, u32, u32); -extern void sub_0807CAA0(u32, u32); extern void (*const gUnk_08111530[])(Entity*); diff --git a/src/npc/milkCart.c b/src/npc/milkCart.c index b423dca7..29481848 100644 --- a/src/npc/milkCart.c +++ b/src/npc/milkCart.c @@ -1,7 +1,6 @@ #include "global.h" #include "entity.h" - -extern void sub_0806ED78(); +#include "functions.h" extern void (*gMilkCartBehaviors[2])(Entity*); diff --git a/src/npc/moblinLady.c b/src/npc/moblinLady.c index c1ddbe6a..d63d4d87 100644 --- a/src/npc/moblinLady.c +++ b/src/npc/moblinLady.c @@ -1,10 +1,5 @@ #include "global.h" #include "entity.h" -#include "player.h" -#include "room.h" -#include "flags.h" -#include "sprite.h" -#include "textbox.h" #include "npc.h" #include "script.h" diff --git a/src/npc/mutoh.c b/src/npc/mutoh.c index 2eaeb91b..5391ac8d 100644 --- a/src/npc/mutoh.c +++ b/src/npc/mutoh.c @@ -9,14 +9,6 @@ #include "save.h" #include "script.h" -extern u32 GetFacingDirection(Entity*, Entity*); -extern u32 sub_0806F5A4(u32); -extern void sub_0806F118(Entity*); -extern u32 UpdateFuseInteraction(Entity*); -extern void sub_0807000C(Entity*); -extern u32 sub_0801E99C(Entity*); -extern void sub_08078784(Entity*, u32); - extern SpriteLoadData gUnk_08110C00; extern u16 gUnk_08110C0C[]; extern Dialog gUnk_08110C10[]; diff --git a/src/npc/npc9.c b/src/npc/npc9.c index 47cc501b..23a0bd3e 100644 --- a/src/npc/npc9.c +++ b/src/npc/npc9.c @@ -1,11 +1,7 @@ #include "global.h" #include "entity.h" #include "textbox.h" - -extern void sub_08078778(Entity*); -extern void sub_0805E47C(Entity*); -extern void sub_0806ED78(Entity*); -extern void sub_0805E584(Entity*); +#include "functions.h" extern void (*const gUnk_0810C290[])(Entity*); diff --git a/src/npc/percy.c b/src/npc/percy.c index a2a8fcd8..3c5c8a01 100644 --- a/src/npc/percy.c +++ b/src/npc/percy.c @@ -10,7 +10,6 @@ extern void sub_0806B41C(Entity*); extern void sub_0806B3CC(Entity*); extern u32 sub_08002632(Entity*); -extern void sub_0801DFB4(Entity*, u32, u32, u32); extern u16* gUnk_08001A7C[40]; extern u16 gUnk_08112E54[4]; diff --git a/src/npc/postman.c b/src/npc/postman.c index 0accf073..34694306 100644 --- a/src/npc/postman.c +++ b/src/npc/postman.c @@ -10,22 +10,11 @@ #include "script.h" extern void sub_08060528(Entity*); -extern void* GetCurrentRoomProperty(u32); extern void sub_0806EE04(Entity*, void*, u32); extern void sub_080604DC(Entity*); -extern s32 sub_0806ED9C(Entity*, u32, u32); extern void sub_0806EE20(Entity*); -extern u32 sub_080040A8(Entity*); -extern u32 sub_0801E99C(Entity*); -extern void sub_0806F118(Entity*); -extern u32 sub_0806F5A4(u32); -extern u32 GetFacingDirection(Entity*, Entity*); extern void sub_080606D8(Entity*); -extern void sub_080788E0(Entity*); -extern void EnqueueSFX(u32); extern void sub_080606C0(Entity*); -extern void sub_0800451C(Entity*); -extern void sub_08078784(Entity*, u32); typedef struct { s16 x; diff --git a/src/npc/rem.c b/src/npc/rem.c index bb1d78ff..a6059865 100644 --- a/src/npc/rem.c +++ b/src/npc/rem.c @@ -3,7 +3,6 @@ #include "entity.h" #include "script.h" -extern void SoundReq(u32); extern void sub_0806A8C8(Entity*); extern void (*gUnk_08112260[])(Entity*); diff --git a/src/npc/simon.c b/src/npc/simon.c index aad57a9f..20cb40e5 100644 --- a/src/npc/simon.c +++ b/src/npc/simon.c @@ -1,4 +1,5 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "functions.h" #include "room.h" @@ -11,9 +12,6 @@ typedef struct { } struct_0806C2A0; extern void DoExitTransition(void*); -extern void SetTileType(u32, u32, u32); -extern void DoExitTransition(void*); -extern void DoFade(u32, u32); extern void gUnk_0813AD60; extern void gUnk_0813AD74; @@ -35,7 +33,7 @@ void sub_0806C224(void) { void Simon_CreateChest(Entity* this) { CreateObjectWithParent(this, 0xf, 0x43, 0); SetTileType(0x73, COORD_TO_TILE(this), this->collisionLayer); - SoundReq(0x73); + SoundReq(SFX_SECRET_BIG); } void sub_0806C280(void) { diff --git a/src/npc/smith.c b/src/npc/smith.c index d365b222..6b55c1f7 100644 --- a/src/npc/smith.c +++ b/src/npc/smith.c @@ -1,21 +1,13 @@ #include "global.h" #include "entity.h" #include "textbox.h" -#include "functions.h" #include "save.h" #include "script.h" +#include "random.h" +#include "npc.h" +#include "functions.h" -extern u32 GetFacingDirection(Entity*, Entity*); -extern u32 sub_0806F5A4(u32); -extern void sub_0806F118(Entity*); -extern Entity* CreateFx(Entity*, u32, u32); -extern void SoundReq(u32); -extern void sub_0807000C(Entity*); -extern u32 sub_0801E99C(Entity*); -extern u32 UpdateFuseInteraction(Entity*); -extern u32 GetAnimationState(Entity*); extern void sub_08078850(Entity*, u32, u32, u32*); -extern void sub_08078784(Entity*, u32); extern void (*const gUnk_08110360[])(Entity*); extern void (*const gUnk_0811036C[])(Entity*); diff --git a/src/npc/stamp.c b/src/npc/stamp.c index 52b100d6..51b209b3 100644 --- a/src/npc/stamp.c +++ b/src/npc/stamp.c @@ -4,11 +4,7 @@ #include "functions.h" #include "script.h" -extern void sub_08078778(Entity*); -extern void sub_0805E47C(Entity*); -extern void sub_0805E584(); extern void sub_08062CA4(); -extern u32 CheckKinstoneFused(); extern void (*gStampBehaviors1[4])(Entity*); extern void (*gStampBehaviors2[2])(Entity*); diff --git a/src/npc/syrup.c b/src/npc/syrup.c index ff12fa4a..f3a1b5dc 100644 --- a/src/npc/syrup.c +++ b/src/npc/syrup.c @@ -2,17 +2,14 @@ #include "entity.h" #include "npc.h" #include "script.h" - -extern void sub_0806ED78(Entity*); -extern void sub_0805E3A0(Entity*, u32); +#include "functions.h" extern void (*gUnk_081121D4[])(Entity*); extern SpriteLoadData gUnk_081121C4; extern SpriteLoadData gUnk_081121B4; -extern u32 gScreenTransition; + extern void sub_0806A26C(Entity*); -extern void sub_080042BA(Entity*, u32); void Syrup(Entity* this) { gUnk_081121D4[this->action](this); @@ -37,7 +34,7 @@ void sub_0806A1F8(Entity* this) { void sub_0806A234(Entity* this) { sub_0807DD94(this, 0); if ((this->field_0x82.HWORD & 4) != 0) { - if ((gScreenTransition & 7) == 0) { + if ((gScreenTransition.frameCount & 7) == 0) { sub_0806A26C(this); } sub_080042BA(this, 2); diff --git a/src/npc/talon.c b/src/npc/talon.c index c3a680a2..f9c7d66f 100644 --- a/src/npc/talon.c +++ b/src/npc/talon.c @@ -1,9 +1,11 @@ #include "global.h" #include "entity.h" #include "textbox.h" -#include "functions.h" #include "player.h" #include "script.h" +#include "npc.h" +#include "random.h" +#include "functions.h" extern void (*gUnk_0810FEC4[])(Entity* this); extern void (*gUnk_0810FEBC[])(Entity* this); @@ -83,7 +85,7 @@ void sub_08065648(Entity* this) { } void sub_08065680(Entity* this) { - if (UpdateFuseInteraction() != 0) { + if (UpdateFuseInteraction(this) != 0) { this->action = this->field_0x68.HALF.HI; InitAnimationForceUpdate(this, this->field_0x6a.HALF.LO); } diff --git a/src/npc/teachers.c b/src/npc/teachers.c index d04d2ab6..bf7e6983 100644 --- a/src/npc/teachers.c +++ b/src/npc/teachers.c @@ -1,17 +1,12 @@ #include "global.h" #include "entity.h" #include "player.h" -#include "functions.h" #include "save.h" #include "script.h" +#include "npc.h" +#include "functions.h" extern SpriteLoadData gUnk_08113910[]; -extern u32 GetFacingDirection(Entity*, Entity*); -extern u32 sub_0806F5A4(u32); -extern void sub_0806F118(Entity*); -extern void sub_08078784(Entity*, u32); -extern u32 UpdateFuseInteraction(Entity*); -extern void sub_0807000C(Entity*); extern Dialog gUnk_08113930[]; diff --git a/src/npc/townMinish.c b/src/npc/townMinish.c index e50ef501..df2d8fe3 100644 --- a/src/npc/townMinish.c +++ b/src/npc/townMinish.c @@ -7,17 +7,12 @@ #include "save.h" #include "script.h" -extern void InitializeAnimation(Entity*, u32); -extern u32 LoadExtraSpriteData(Entity*, SpriteLoadData*); - extern u32 sub_080002C0(); extern void sub_0806ACC4(Entity*); extern void sub_0806AEA8(); extern void sub_0806AEE4(Entity*); extern void sub_0806AFE8(Entity*, ScriptExecutionContext*); extern s32 sub_0806EDD8(Entity*, u32, u32); -extern u32 sub_0806F5B0(u32); -extern void sub_08078784(Entity*, u32); extern void sub_08078850(Entity*, u32, u32, u32*); extern u8 gUnk_081125F4[12]; diff --git a/src/npc/townsperson.c b/src/npc/townsperson.c index d8b70298..fc99bac6 100644 --- a/src/npc/townsperson.c +++ b/src/npc/townsperson.c @@ -4,10 +4,11 @@ #include "player.h" #include "textbox.h" #include "flags.h" -#include "structures.h" -#include "functions.h" #include "save.h" #include "script.h" +#include "random.h" +#include "structures.h" +#include "functions.h" typedef struct { u8 frame1; @@ -19,17 +20,8 @@ typedef struct { extern void (*const gUnk_0810B774[])(Entity*); extern void (*const gUnk_0810B77C[])(Entity*); extern void sub_08061CB4(Entity*, u32); -extern u32 sub_0805ACC0(Entity*); -extern u32 sub_0801E99C(Entity*); extern void sub_08061D64(Entity*); -extern void sub_0806F118(Entity*); -extern u32 sub_0806F5A4(u32); -extern u32 GetFacingDirection(Entity*, Entity*); extern void sub_08062048(Entity*); -extern void sub_08078784(Entity*, u32); -extern void sub_08078778(Entity*); -extern u32 sub_0806F5B0(u32); -extern void ResolveEntityOnTop(Entity*, Entity*); extern void sub_08078850(Entity*, u32, u8, u32*); extern SpriteLoadData* gUnk_0810B6EC[]; diff --git a/src/npc/wheaton.c b/src/npc/wheaton.c index 07697274..1d2170a8 100644 --- a/src/npc/wheaton.c +++ b/src/npc/wheaton.c @@ -1,9 +1,8 @@ #include "global.h" #include "entity.h" #include "script.h" +#include "functions.h" -extern void sub_0805E3A0(Entity*, u32); -extern void ResolveEntityOnTop(Entity*, Entity*); extern Hitbox gUnk_0810C3C0; void Wheaton(Entity* this) { diff --git a/src/npc/windTribespeople.c b/src/npc/windTribespeople.c index ea09f484..65968f30 100644 --- a/src/npc/windTribespeople.c +++ b/src/npc/windTribespeople.c @@ -8,15 +8,7 @@ #include "save.h" #include "script.h" -extern u32 LoadExtraSpriteData(Entity*, SpriteLoadData*); extern void sub_0806C7D4(Entity*); -extern void sub_0806F118(Entity*); -extern u32 sub_0801E99C(); -extern void sub_08078784(Entity*, u32); -extern void SetExtraSpriteFrame(Entity*, u32, u32); -extern void SetSpriteSubEntryOffsetData2(Entity*, u32, u32); -extern void SetSpriteSubEntryOffsetData1(Entity*, u32, u32); -extern void sub_0807000C(Entity*); extern void (*const gUnk_08113A7C[])(Entity*); extern void (*const gUnk_08113A8C[])(Entity*, ScriptExecutionContext*); diff --git a/src/npc/zelda.c b/src/npc/zelda.c index af6ec1c7..c9a50cfb 100644 --- a/src/npc/zelda.c +++ b/src/npc/zelda.c @@ -1,24 +1,16 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "functions.h" #include "room.h" #include "flags.h" #include "script.h" -extern void PrependEntityToList(Entity*, u32); -extern Entity* FindEntityBySubtype(u32, u32); -void CopyPosition(Entity*, Entity*); +extern Entity* DeepFindEntityByID(u32, u32); void sub_08068680(Entity*, Entity*); void sub_08068694(Entity*, Entity*); -u32 GetAnimationState(Entity* ent); -void DeleteThisEntity(void); extern Entity* GetEntityByType(u32, u32); extern void sub_080686C4(Entity*, Entity*); -extern void SoundReq(u32); -extern void SetTileType(u32, u32, u32); - -extern Entity gPlayerEntity; -extern RoomControls gRoomControls; extern void (*gUnk_08110BD8[])(Entity* ent); extern u16 gUnk_08110BE0[]; @@ -40,7 +32,7 @@ void sub_08066CF8(Entity* this) { } void sub_08066D04(Entity* this) { - this->parent = FindEntityBySubtype(7, 0x2E); + this->parent = DeepFindEntityByID(7, 0x2E); } void sub_08066D14(Entity* this, ScriptExecutionContext* context) { @@ -95,7 +87,7 @@ void sub_08066D94(Entity* this) { void sub_08066DE4(Entity* this) { Entity* pEVar1; - pEVar1 = FindEntityBySubtype(7, 0x2E); + pEVar1 = DeepFindEntityByID(7, 0x2E); if (pEVar1 != NULL) { CopyPosition(this, pEVar1); sub_080686C4(this, pEVar1); @@ -139,7 +131,7 @@ void sub_08066E80(Entity* this, ScriptExecutionContext* context) { context->unk_18++; this->field_0x20 = 0x20000; this->frames.all &= 0xFE; - SoundReq(0x7C); + SoundReq(SFX_PLY_JUMP); } break; case 2: diff --git a/src/object/archway.c b/src/object/archway.c index aa26762f..49f3f497 100644 --- a/src/object/archway.c +++ b/src/object/archway.c @@ -1,7 +1,6 @@ #include "global.h" #include "entity.h" -#include "sprite.h" -#include "functions.h" +#include "game.h" void Archway(Entity* this) { if (this->action == 0) { diff --git a/src/object/backgroundCloud.c b/src/object/backgroundCloud.c index df2625a3..aaee8cf2 100644 --- a/src/object/backgroundCloud.c +++ b/src/object/backgroundCloud.c @@ -1,5 +1,6 @@ #include "global.h" #include "entity.h" +#include "random.h" #include "functions.h" extern void (*const gUnk_08121EA4[])(Entity*); @@ -24,7 +25,7 @@ void sub_0808F658(Entity* this) { this->animationState = 0; this->x.HALF.HI += (Random() & 0xf) << 4; this->actionDelay = 0; - this->previousActionFlag = 0; + this->subAction = 0; } void sub_0808F6E0(Entity* this) { @@ -35,8 +36,8 @@ void sub_0808F6E0(Entity* this) { } void sub_0808F70C(Entity* this) { - if (this->previousActionFlag == 0) { - this->previousActionFlag = 1; + if (this->subAction == 0) { + this->subAction = 1; this->actionDelay = ((Random() & 7) << 3) + 31; if ((this->direction & 0x10)) { @@ -49,10 +50,10 @@ void sub_0808F70C(Entity* this) { this->y.HALF.HI = gUnk_08121EB3[this->type2 * 2 + (Random() & 1)]; } - if (this->previousActionFlag == 1) { + if (this->subAction == 1) { if (--this->actionDelay == 0) { this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; } } } diff --git a/src/object/bakerOven.c b/src/object/bakerOven.c index a64217f1..12cbf897 100644 --- a/src/object/bakerOven.c +++ b/src/object/bakerOven.c @@ -59,12 +59,12 @@ void sub_0809CD0C(Entity* this) { } /* Damage minish link if he touches a steam cloud */ - if (this->field_0xf == 0 && gPlayerEntity.hurtBlinkTime == 0 && this->frameIndex && + if (this->field_0xf == 0 && gPlayerEntity.iframes == 0 && this->frameIndex && sub_0806FC80(this, &gPlayerEntity, 4)) { this->field_0xf++; ModHealth(-2); sub_0800449C(&gPlayerEntity, 0x7a); - gPlayerEntity.hurtBlinkTime = 16; + gPlayerEntity.iframes = 16; gPlayerEntity.field_0x3e = 16; gPlayerEntity.field_0x42 = 12; gPlayerEntity.field_0x46 = 16; diff --git a/src/object/bell.c b/src/object/bell.c index 072b0798..3a1e7d41 100644 --- a/src/object/bell.c +++ b/src/object/bell.c @@ -1,5 +1,5 @@ -#include "entity.h" #include "global.h" +#include "entity.h" extern void (*gUnk_08123384[])(Entity*); diff --git a/src/object/bird.c b/src/object/bird.c index 6d126380..fcf03eab 100644 --- a/src/object/bird.c +++ b/src/object/bird.c @@ -1,8 +1,10 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "flags.h" -#include "functions.h" #include "save.h" +#include "random.h" +#include "functions.h" extern void (*const gUnk_08123EC0[])(Entity*); extern void (*const gUnk_08123EEC[])(Entity*); @@ -69,7 +71,7 @@ void sub_0809D048(Entity* this) { } void sub_0809D06C(Entity* this) { - gUnk_08123EFC[this->previousActionFlag](this); + gUnk_08123EFC[this->subAction](this); } void sub_0809D084(Entity* this) { @@ -80,7 +82,7 @@ void sub_0809D084(Entity* this) { if (temp != 0) { PositionRelative(this->parent, this, 0, 0x80000); } else { - this->previousActionFlag++; + this->subAction++; this->field_0x20 = temp; } } @@ -95,7 +97,7 @@ void sub_0809D0AC(Entity* this) { this->height.WORD = 0; this->collisionLayer = 1; SetLocalFlag(0x45); - SoundReq(0x72); + SoundReq(SFX_SECRET); fx = CreateFx(this, 0x11, 0); if (fx != NULL) { sub_0806FAD8(this, fx); diff --git a/src/object/button.c b/src/object/button.c index 23a2ee8d..e545953c 100644 --- a/src/object/button.c +++ b/src/object/button.c @@ -47,7 +47,7 @@ void sub_08081FF8(Entity*); void sub_08081BAC(Entity* this) { if (sub_08081CB0(this)) { - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 0xA; sub_0805E4E0(this, 0xA); sub_08081FF8(this); @@ -105,7 +105,6 @@ void sub_08081C98(Entity* this) { } Entity* sub_08081D74(Entity*); -void sub_0807B7D8(u32, u32, u32); u32 sub_080001DA(u32, u32); u32 sub_08081CB0(Entity* this) { @@ -142,8 +141,7 @@ u32 sub_08081D28(Entity* this) { } extern u32 sub_080002E0(u32, u32); -extern Entity* gUnk_03004040[]; -extern u32 sub_080041A0(Entity*, Entity*, u32, u32); +extern Entity* gUnk_03004040[3]; u32 sub_08081E0C(Entity*); Entity* sub_08081D74(Entity* this) { @@ -171,8 +169,6 @@ Entity* sub_08081D74(Entity* this) { return ent; } -extern u32 sub_08079F8C(); - u32 sub_08081E0C(Entity* this) { Entity* tmp = &gPlayerEntity; if (tmp->height.HALF.HI != 0 || !sub_08079F8C()) { @@ -273,7 +269,6 @@ u32 sub_08081F7C(Entity* this, u32 r7) { return 1; } -extern Entity* gUnk_03004040[3]; extern void sub_080044AE(Entity*, u32, u32); void sub_08081FF8(Entity* this) { diff --git a/src/object/chestSpawner.c b/src/object/chestSpawner.c index 790d1251..3f7e6006 100644 --- a/src/object/chestSpawner.c +++ b/src/object/chestSpawner.c @@ -1,6 +1,5 @@ #include "global.h" #include "entity.h" -#include "flags.h" extern void sub_080842D8(Entity*); extern void sub_08078828(Entity*); diff --git a/src/object/cloud.c b/src/object/cloud.c index 6f10295a..56b55984 100644 --- a/src/object/cloud.c +++ b/src/object/cloud.c @@ -1,31 +1,20 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "room.h" #include "player.h" #include "flags.h" +#include "random.h" #include "functions.h" #include "structures.h" extern void sub_0809F7BC(Entity*); -extern void SoundReq(u32); -extern void sub_0809F814(u32); extern void sub_0809F7F4(Entity*); -extern void LoadRoomEntityList(); -extern void DeleteThisEntity(); -extern u32 CheckRoomFlag(u32); -extern void sub_08078A90(u32); -extern void sub_08078B48(void); -extern void sub_0806F69C(Entity*); extern void (*gUnk_08124798[])(Entity*); extern void (*gUnk_081247A0[])(Entity*); extern void (*gUnk_081247AC[])(Entity*); -extern Entity* CreateObject(u32, u32, u32); -extern void PositionEntityOnTop(Entity*, Entity*); -extern void sub_0807BB68(u32*, u32, u32); extern void* gUnk_080DD750; -extern Entity gPlayerEntity; -extern PlayerState gPlayerState; extern u8 gUnk_081247C0[]; extern u16 gUnk_081247C8[]; extern u32 gUnk_081247D0; @@ -70,9 +59,9 @@ void sub_0809F548(Entity* this) { void sub_0809F5B0(Entity* this) { if (--this->actionDelay == 0) { - SoundReq(115); + SoundReq(SFX_SECRET_BIG); SetGlobalFlag(KUMOTATSUMAKI); - LoadRoomEntityList(&gUnk_080DD750); + LoadRoomEntityList((EntityData*)&gUnk_080DD750); DeleteThisEntity(); } } @@ -123,7 +112,7 @@ void sub_0809F69C(Entity* this) { this->actionDelay = 30; this->action = 4; gRoomControls.cameraTarget = &gPlayerEntity; - SoundReq(115); + SoundReq(SFX_SECRET_BIG); } } diff --git a/src/object/fileScreenObjects.c b/src/object/fileScreenObjects.c index 2b4914e1..de79631a 100644 --- a/src/object/fileScreenObjects.c +++ b/src/object/fileScreenObjects.c @@ -1,18 +1,17 @@ #include "global.h" #include "entity.h" #include "flags.h" -#include "functions.h" #include "main.h" #include "menu.h" #include "npc.h" -#include "position.h" -#include "structures.h" +#include "coord.h" #include "fileScreen.h" +#include "utils.h" +#include "structures.h" +#include "functions.h" extern int sub_0807A094(int); -extern void LoadPalettes(const u8*, int, int); extern u32 sub_080041EC(int, int); -extern u32 sub_080045DA(int, int); static bool32 sub_0808E950(void); static void sub_0808EABC(Entity*); @@ -39,7 +38,6 @@ typedef struct { extern void (*const gUnk_08121C64[])(Entity*); extern void (*const gUnk_08121CCC[])(Entity*); extern const int gUnk_08133368[]; -extern const u8 gGlobalGfxAndPalettes[]; extern const struct_08121CD4 gUnk_08121CD4[][4]; extern const u8 gUnk_08121D10[]; extern const u8 gUnk_08121D38[][8]; diff --git a/src/object/floatingBlock.c b/src/object/floatingBlock.c index 661cec72..7e1ad599 100644 --- a/src/object/floatingBlock.c +++ b/src/object/floatingBlock.c @@ -1,6 +1,5 @@ #include "global.h" #include "entity.h" -#include "functions.h" void FloatingBlock(Entity* this) { if (this->action == 0) { diff --git a/src/object/giantLeaf.c b/src/object/giantLeaf.c index cf2fb1df..9badc65b 100644 --- a/src/object/giantLeaf.c +++ b/src/object/giantLeaf.c @@ -1,11 +1,10 @@ #include "global.h" #include "entity.h" #include "room.h" +#include "functions.h" -void SetTile(u32 tileIndex, s32 tilePosition, s32 layerIndex); void sub_0808D618(Entity* ent); -extern RoomControls gRoomControls; extern s16 gUnk_08121750[]; extern s16 gUnk_0812176A[]; diff --git a/src/object/greatFairy.c b/src/object/greatFairy.c index 3d511b25..87afa483 100644 --- a/src/object/greatFairy.c +++ b/src/object/greatFairy.c @@ -1,12 +1,15 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "room.h" #include "screen.h" -#include "structures.h" #include "greatFairy.h" -#include "functions.h" +#include "flags.h" #include "save.h" +#include "random.h" #include "script.h" +#include "structures.h" +#include "functions.h" enum { BEHAVIORS, @@ -23,11 +26,9 @@ enum { // Main void GreatFairy(Entity* this) { - u8 bVar1; - if (this->action == 0) { - bVar1 = __modsi3(this->type, 11); - this->type2 = bVar1; + s32 temp = 11; + this->type2 = this->type % temp; } GreatFairy_Main[this->type2](this); } @@ -66,20 +67,18 @@ void GreatFairy_DormantUpdate(Entity* this) { --*pFrame; } switch (*pFrame) { - case 0x96: - case 0x82: - goto e; - case 0x0: + case 0: this->action = 2; break; - e: - case 0xd2: - case 0xaa: - case 0x121: + case 130: + case 150: + case 170: + case 210: + case 289: ripple = GreatFairy_CreateForm(this, RIPPLE, 0); if (ripple) { - PositionRelative(this, ripple, (s32)GreatFairy_RippleOffsets[this->actionDelay] << 16, - (s32)GreatFairy_RippleOffsets[this->actionDelay + 1] << 16); + PositionRelative(this, ripple, (s32)GreatFairy_RippleOffsets[this->actionDelay] * 65536, + (s32)GreatFairy_RippleOffsets[this->actionDelay + 1] * 65536); this->actionDelay += 2; break; } @@ -108,9 +107,8 @@ void GreatFairy_SpawningUpdate(Entity* this) { DoFade(6, 4); SoundReq(325); this->action = 4; - this->actionDelay = 0x3c; - var = this->spriteSettings.raw & ~0x3; - this->spriteSettings.raw = (this->spriteSettings.raw & var) | 1; + this->actionDelay = 60; + this->spriteSettings.b.draw = 1; } } } @@ -164,10 +162,8 @@ void GreatFairy_WingsInit(Entity* this) { } void GreatFairy_WingsUpdate(Entity* this) { - s32 iVar1; - - iVar1 = this->speed -= 32; - if (iVar1 * 65536 >> 16 == 256) { + this->speed -= 32; + if (this->speed == 256) { this->action = 2; sub_0805EC60(this); gRoomVars.greatFairyState |= 32; @@ -221,7 +217,7 @@ void GreatFairy_MiniRisingUpdate(Entity* this) { this->height.WORD -= 0x8000; if (this->height.HALF.HI == -20) { this->action = 2; - SoundReq(321); + SoundReq(SFX_HEART_CONTAINER_SPAWN); } else { if (((this->height.HALF.HI == -10) && (this->field_0xf == 0)) && (target = GreatFairy_CreateForm(this, DROPLET, 0), target != NULL)) { @@ -235,7 +231,7 @@ void GreatFairy_MiniRisingUpdate(Entity* this) { void GreatFairy_MiniRemoveMe(Entity* this) { GetNextFrame(this); sub_080873D0(this); - if ((gRoomVars.greatFairyState & 1) != 0) { + if (gRoomVars.greatFairyState & 1) { DeleteEntity(this); } } @@ -268,15 +264,13 @@ void GreatFairy_MiniAffineInit2(Entity* this) { // Mini great fairy stretch void GreatFairy_MiniAffineUpdate(Entity* this) { - s32 iVar2; - if (--this->actionDelay == 0) { gRoomVars.greatFairyState |= 1; this->action = 3; sub_0805EC60(this); } else { - iVar2 = this->speed -= 24; - sub_0805EC9C(this, 256, iVar2 * 0x10000 >> 20, 0); + this->speed -= 24; + sub_0805EC9C(this, 256, this->speed >> 4, 0); } } @@ -290,12 +284,12 @@ void GreatFairy_DropletInit(Entity* this) { this->spriteSettings.b.draw = 1; this->height.HALF.HI = 0; this->spritePriority.b0 = 5; - SoundReq(320); + SoundReq(SFX_140); } void GreatFairy_DropletUpdate(Entity* this) { GetNextFrame(this); - if (this->frames.b.f3) { + if (this->frames.all & 0x80) { DeleteEntity(this); } } @@ -312,7 +306,7 @@ void GreatFairy_RippleInit(Entity* this) { } void GreatFairy_RippleUpdate(Entity* this) { - if ((gRoomVars.greatFairyState & 2) != 0) { + if (gRoomVars.greatFairyState & 2) { DeleteEntity(this); } else { GetNextFrame(this); @@ -329,7 +323,7 @@ void GreatFairy_BigRippleInit(Entity* this) { this->actionDelay = 120; this->spriteSettings.b.draw = 1; this->spritePriority.b0 = 5; - SoundReq(249); + SoundReq(SFX_TELEPORTER); } void GreatFairy_BigRippleUpdate(Entity* this) { @@ -361,7 +355,7 @@ void GreatFairy_EnergyInit(Entity* this) { void GreatFairy_EnergyUpdate(Entity* this) { GetNextFrame(this); - if (this->frames.b.f3) { + if (this->frames.all & 0x80) { DeleteEntity(this); } } @@ -375,35 +369,25 @@ void sub_08087114(Entity* this) { } } -#ifdef NON_MATCHING -extern u8 gUnk_0812079C; - -void sub_08087150(Entity* this) { +NONMATCH("asm/greatFairy/sub_08087150.inc", void sub_08087150(Entity* this)) { u32 temp; - GreatFairy_InitializeAnimation(); + GreatFairy_InitializeAnimation(this); this->spriteSettings.b.draw = TRUE; this->spriteOrientation.flipY = 0; this->spriteRendering.b0 = 0; this->spritePriority.b0 = 3; - this->speed = 0x80; + this->speed = 128; this->direction = 0x10; - temp = gUnk_0812079C; + temp = gUnk_0812079C[0]; this->palette.raw = ((temp & 0xf) << 4) | 0xf; } -#else -NAKED -void sub_08087150(Entity* this) { - asm(".include \"asm/greatFairy/sub_08087150.inc\""); -} -#endif +END_NONMATCH void nullsub_516(Entity* this) { } void sub_080871A8(Entity* this) { - u32 bVar1; - if (--this->actionDelay == 0) { this->action = 3; this->actionDelay = 60; @@ -412,7 +396,6 @@ void sub_080871A8(Entity* this) { } void sub_080871D0(Entity* this) { - if (--this->actionDelay == 0) { gRoomVars.greatFairyState |= 8; DeleteEntity(this); @@ -422,16 +405,16 @@ void sub_080871D0(Entity* this) { void sub_080871F8(Entity* this) { Entity* temp = this->attachedEntity; - if ((temp->x.HALF.HI == this->x.HALF.HI) && (temp->y.HALF.HI - 0x20 == this->y.HALF.HI)) { + if ((temp->x.HALF.HI == this->x.HALF.HI) && (temp->y.HALF.HI - 32 == this->y.HALF.HI)) { this->action = 2; } else { - this->direction = sub_080045D4(this->x.HALF.HI, this->y.HALF.HI, temp->x.HALF.HI, temp->y.HALF.HI - 0x20); + this->direction = sub_080045D4(this->x.HALF.HI, this->y.HALF.HI, temp->x.HALF.HI, temp->y.HALF.HI - 32); sub_0806F69C(this); } } void sub_08087240(Entity* this) { - if ((gRoomVars.greatFairyState & 4) != 0) { + if (gRoomVars.greatFairyState & 4) { this->action = 3; this->actionDelay = 20; this->direction = 16; @@ -446,7 +429,6 @@ void sub_08087264(Entity* this) { } void sub_0808727C(Entity* this) { - if (--this->actionDelay == 0) { DeleteEntity(this); } @@ -477,17 +459,16 @@ void sub_080872F8(Entity* this) { sub_080045D4(this->x.HALF.HI, this->y.HALF.HI, (s16)this->field_0x68.HWORD, (s16)this->field_0x6a.HWORD); this->direction = (this->direction + gUnk_081207AC[Random() & 3]) & 0x1f; } - temp = gSineTable[this->actionDelay + 0x40]; + temp = gSineTable[this->actionDelay + 64]; this->height.HALF.HI = (temp >> 6) - 8; this->actionDelay++; } void GreatFairy_InitializeAnimation(Entity* this) { - s32 temp; + s32 temp = 11; this->action = 1; - temp = this->type; - this->type2 = temp % 11; + this->type2 = this->type % temp; this->collisionLayer = 2; InitializeAnimation(this, this->type2); sub_0805E3A0(this, 2); @@ -513,7 +494,7 @@ void sub_080873D0(Entity* this) { ent = GreatFairy_CreateForm(this, 8, 0); if (ent != NULL) { CopyPosition(this, ent); - this->actionDelay = 0x30; + this->actionDelay = 48; } } } @@ -521,10 +502,10 @@ void sub_080873D0(Entity* this) { void sub_080873FC(void) { Entity* ent; - SoundReq(0xf7); + SoundReq(SFX_APPARATE); gRoomControls.cameraTarget = NULL; - while (ent = FindEntityInListBySubtype(0x6, 0x1b, 0x6), ent != NULL) { + while (ent = FindEntityByID(0x6, 0x1b, 0x6), ent != NULL) { DeleteEntity(ent); } } @@ -553,101 +534,87 @@ void sub_08087424(Entity* this, ScriptExecutionContext* context) { void sub_0808747C(Entity* this, ScriptExecutionContext* context) { u32 iVar1 = 0; - iVar1 = (u32)FindEntityInListByForm(0x6, 0xf, 0x6, 0xb, 0x0); + iVar1 = (u32)FindEntity(0x6, 0xf, 0x6, 0xb, 0x0); if (iVar1 != 0) { iVar1 = 1; } context->condition = iVar1; } -// clang-format off void (*const GreatFairy_Main[])(Entity*) = { - GreatFairy_CallBehavior, + GreatFairy_CallBehavior, GreatFairy_WingsCallBehavior, GreatFairy_WakeCallBehavior, GreatFairy_MiniCallBehavior, - GreatFairy_MiniAffineCallBehavior, - GreatFairy_DropletCallBehavior, - GreatFairy_RippleCallBehavior, + GreatFairy_MiniAffineCallBehavior, + GreatFairy_DropletCallBehavior, + GreatFairy_RippleCallBehavior, GreatFairy_BigRippleCallBehavior, - GreatFairy_EnergyCallBehavior, - sub_08087114, - sub_08087294 + GreatFairy_EnergyCallBehavior, + sub_08087114, + sub_08087294, }; void (*const GreatFairy_Behaviors[])(Entity*) = { - GreatFairy_Init, - GreatFairy_DormantUpdate, - GreatFairy_CreateBigRipple, - GreatFairy_SpawningUpdate, - GreatFairy_MiniUpdate, - GreatFairy_FinalUpdate + GreatFairy_Init, GreatFairy_DormantUpdate, GreatFairy_CreateBigRipple, + GreatFairy_SpawningUpdate, GreatFairy_MiniUpdate, GreatFairy_FinalUpdate, }; const s16 GreatFairy_RippleOffsets[10] = { - 0, 0, - -32, -8, - 16, 20, - 24, -12, - -16, 24 + 0, 0, -32, -8, 16, 20, 24, -12, -16, 24, }; - -void (*const GreatFairy_WingsBehaviors[])(Entity*) = { +void (*const GreatFairy_WingsBehaviors[])(Entity*) = { GreatFairy_WingsInit, GreatFairy_WingsUpdate, - nullsub_116 + nullsub_116, }; void (*const GreatFairy_WakeBehaviors[])(Entity*) = { GreatFairy_WakeInit, - GreatFairy_WakeUpdate + GreatFairy_WakeUpdate, }; void (*const GreatFairy_MiniBehaviors[])(Entity*) = { GreatFairy_MiniInit, GreatFairy_MiniRisingUpdate, - GreatFairy_MiniRemoveMe + GreatFairy_MiniRemoveMe, }; void (*const GreatFairy_MiniAffineBehaviors[])(Entity*) = { GreatFairy_MiniAffineInit, GreatFairy_MiniAffineInit2, GreatFairy_MiniAffineUpdate, - DeleteEntity + DeleteEntity, }; void (*const GreatFairy_DropletBehaviors[])(Entity*) = { GreatFairy_DropletInit, - GreatFairy_DropletUpdate + GreatFairy_DropletUpdate, }; void (*const GreatFairy_RippleBehaviors[])(Entity*) = { GreatFairy_RippleInit, - GreatFairy_RippleUpdate + GreatFairy_RippleUpdate, }; void (*const GreatFairy_BigRippleBehaviors[])(Entity*) = { GreatFairy_BigRippleInit, - GreatFairy_BigRippleUpdate + GreatFairy_BigRippleUpdate, }; void (*const GreatFairy_EnergyBehaviors[])(Entity*) = { GreatFairy_EnergyInit, - GreatFairy_EnergyUpdate + GreatFairy_EnergyUpdate, }; + void (*const GreatFairy_Form1Behaviors[])(Entity*) = { sub_08087150, nullsub_516, sub_080871A8, - sub_080871D0 + sub_080871D0, }; void (*const GreatFairy_Form2Behaviors[])(Entity*) = { - sub_08087150, - sub_080871F8, - sub_08087240, - sub_08087264, - sub_0808727C + sub_08087150, sub_080871F8, sub_08087240, sub_08087264, sub_0808727C, }; -// clang-format on diff --git a/src/object/heartContainer.c b/src/object/heartContainer.c index f6858b50..046eb0aa 100644 --- a/src/object/heartContainer.c +++ b/src/object/heartContainer.c @@ -1,11 +1,9 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "flags.h" #include "functions.h" -extern void DeleteThisEntity(); -extern void sub_08080CB4(Entity*); -extern u32 sub_08017850(Entity*); static void sub_0808E6A0(Entity*); static void sub_0808E6E4(Entity*); static void sub_0808E714(Entity*); @@ -54,7 +52,7 @@ static void sub_0808E714(Entity* this) { this->action = 3; this->field_0x3c |= 0x10; sub_0805EC60(this); - SoundReq(0x141); + SoundReq(SFX_HEART_CONTAINER_SPAWN); } sub_08080CB4(this); } diff --git a/src/object/houseDoorExterior.c b/src/object/houseDoorExterior.c index 0d9b6e81..2b6edaae 100644 --- a/src/object/houseDoorExterior.c +++ b/src/object/houseDoorExterior.c @@ -61,7 +61,7 @@ void sub_080866D8(Entity* this) { entity->field_0x68.HWORD = prop->unk0; entity->field_0x6a.HWORD = prop->unk2; entity->collisionLayer = prop->unk4; - entity->previousActionFlag = prop->unk5; + entity->subAction = prop->unk5; UpdateSpriteForCollisionLayer(entity); *((u32*)(&this->field_0x68)) |= mask; if (prop->unk8) { @@ -98,7 +98,7 @@ static void sub_0808681C(Entity* this) { this->spriteSettings.b.draw = 1; this->frameIndex = 0; this->hitbox = &gUnk_081206AC; - if (this->previousActionFlag == 1) { + if (this->subAction == 1) { this->action = 2; this->frameIndex = 1; } @@ -158,7 +158,7 @@ void sub_0808692C(Entity* this) { this->flags &= 0xFD; this->type2 = 2; this->action = this->frameIndex == 0 ? 1 : 2; - this->previousActionFlag = 0; + this->subAction = 0; this->actionDelay = 8; } diff --git a/src/object/itemOnGround.c b/src/object/itemOnGround.c index b794b546..351b21bd 100644 --- a/src/object/itemOnGround.c +++ b/src/object/itemOnGround.c @@ -1,4 +1,5 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "flags.h" #include "functions.h" @@ -162,7 +163,7 @@ static void sub_080810FC(Entity* this) { sub_08081598(this); } else { this->action = 2; - this->previousActionFlag = 0; + this->subAction = 0; this->flags |= 0x80; this->flags2 = 0x11; CopyPosition(&gPlayerEntity, this); @@ -304,11 +305,11 @@ void sub_0808136C(Entity* this) { } static void sub_080813BC(Entity* this) { - gUnk_0811E840[this->previousActionFlag](this); + gUnk_0811E840[this->subAction](this); } void sub_080813D4(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 1; this->spriteSettings.b.draw = 1; } diff --git a/src/object/jailBars.c b/src/object/jailBars.c index d046c822..505ca8e2 100644 --- a/src/object/jailBars.c +++ b/src/object/jailBars.c @@ -2,9 +2,9 @@ #include "entity.h" #include "flags.h" #include "room.h" +#include "functions.h" extern void sub_080A0960(Entity*, u32); -extern void SoundReq(u32); extern void sub_0801AF18(u8*, u32, u32); extern void (*const gUnk_08124950[])(Entity*); diff --git a/src/object/lightableSwitch.c b/src/object/lightableSwitch.c index cfbf0ba5..cbeafdd7 100644 --- a/src/object/lightableSwitch.c +++ b/src/object/lightableSwitch.c @@ -7,10 +7,7 @@ extern void sub_0809EB30(Entity*); extern void sub_0809EAD8(Entity*); extern void sub_0809EABC(Entity*); -extern void EnqueueSFX(u32); extern void sub_080A2CC0(Entity*, Entity**, u16*); -extern void SetTile(u32, u32, u32); -extern void sub_0806F69C(Entity*); extern void (*const gUnk_081243B4[])(Entity*); extern void (*const gUnk_081243BC[])(Entity*); diff --git a/src/object/lilypadSmall.c b/src/object/lilypadSmall.c index a96c49ad..ce0d8c08 100644 --- a/src/object/lilypadSmall.c +++ b/src/object/lilypadSmall.c @@ -1,7 +1,8 @@ #include "global.h" #include "entity.h" -#include "functions.h" #include "player.h" +#include "random.h" +#include "functions.h" extern void sub_080A2CC0(Entity*, Entity**, u16*); diff --git a/src/object/mask.c b/src/object/mask.c index e405df5f..b6d06206 100644 --- a/src/object/mask.c +++ b/src/object/mask.c @@ -2,26 +2,17 @@ #include "entity.h" #include "room.h" #include "random.h" - -extern Entity gPlayerEntity; -extern u16 gScreenTransition[]; +#include "structures.h" +#include "player.h" +#include "flags.h" +#include "functions.h" extern void (*MaskActionFuncs[])(Entity*); -extern void DeleteThisEntity(); - -extern bool32 CheckFlags(u16); -extern void SetFlag(u16); -extern void ClearFlag(u16); - -extern void SetTile(u32, u16, u32); - extern void sub_08000148(u16, u16, u32); extern s16 sub_080001DA(u16, u32); extern u16 sub_080002E0(u16, u32); -extern void EnqueueSFX(u32); -extern void sub_080044EC(Entity*, u16); extern void sub_0805457C(Entity*, s32); void Mask(Entity* this) { @@ -35,7 +26,7 @@ void sub_080929A4(Entity* this) { switch (this->type2 & 0xC0) { case 0x40: - field_0x0a = gScreenTransition[0x5]; + field_0x0a = gScreenTransition.field_0xa; switch (field_0x0a) { case 0x44D ... 0x44F: @@ -69,7 +60,7 @@ void sub_080929A4(Entity* this) { this->field_0x7a.HWORD = sub_080002E0(this->field_0x7c.HALF.HI, 1); - SetTile(0x4022, this->field_0x7c.HALF.HI, 1); + SetTile(0x4022, this->field_0x7c.HALF_U.HI, 1); } // Probably related to knocking it down @@ -94,7 +85,7 @@ void sub_08092A94(Entity* this) { } // Presumably, make the mask fall - SetTile((u16)this->field_0x7c.HALF.LO, this->field_0x7c.HALF.HI, 1); + SetTile(this->field_0x7c.HALF_U.LO, this->field_0x7c.HALF_U.HI, 1); sub_08000148(this->field_0x7a.HWORD, this->field_0x7c.HALF.HI, 1); diff --git a/src/object/metalDoor.c b/src/object/metalDoor.c index 88ab3308..a2a18bff 100644 --- a/src/object/metalDoor.c +++ b/src/object/metalDoor.c @@ -2,15 +2,12 @@ #include "entity.h" #include "room.h" #include "flags.h" +#include "functions.h" extern u32 sub_08083734(Entity*, u32); extern void sub_080A080C(Entity*); -extern void sub_0806F69C(Entity*); -extern void EnqueueSFX(u32); extern void sub_080A0870(Entity*); -extern void SoundReq(u32); extern u32 sub_080001DA(u32, u32); -extern void SetTile(u32, u32, u32); extern void (*const gUnk_0812493C[])(Entity*); diff --git a/src/object/minecart.c b/src/object/minecart.c index 1e239be3..af74c357 100644 --- a/src/object/minecart.c +++ b/src/object/minecart.c @@ -1,4 +1,5 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "functions.h" #include "room.h" @@ -7,7 +8,6 @@ extern u32 sub_08091DDC(Entity*); extern u32 sub_080002B4(Entity*, u32, u32); extern u32 sub_08007DD6(u32, u32); extern void sub_08017744(Entity*); -extern u32 sub_080002B8(Entity*); extern void sub_08091C0C(Entity*); typedef struct { @@ -85,7 +85,7 @@ void sub_080917DC(Entity* this) { gPlayerEntity.flags &= 0x7f; ResetPlayer(); sub_0807A108(); - SoundReq(0x7c); + SoundReq(SFX_PLY_JUMP); } } else { this->actionDelay = 0; @@ -153,7 +153,7 @@ void sub_080919AC(Entity* this) { } if (--this->field_0xf == 0xff) { - SoundReq(0x7b); + SoundReq(SFX_PLY_VO7); this->field_0xf = 0x3c; } @@ -182,7 +182,7 @@ void sub_080919AC(Entity* this) { gPlayerEntity.flags |= 0x80; sub_08004168(this); InitAnimationForceUpdate(this, this->animationState + 0xc); - SoundReq(0x78); + SoundReq(SFX_PLY_VO4); SoundReq(0x139); return; case 0x67: diff --git a/src/object/minishSizedArchway.c b/src/object/minishSizedArchway.c index cc1b63d3..240fdf95 100644 --- a/src/object/minishSizedArchway.c +++ b/src/object/minishSizedArchway.c @@ -1,7 +1,6 @@ #include "global.h" #include "entity.h" -#include "sprite.h" -#include "functions.h" +#include "game.h" void MinishSizedArchway(Entity* this) { if (this->action == 0) { diff --git a/src/object/minishSizedEntrance.c b/src/object/minishSizedEntrance.c index 78410c6c..03467f41 100644 --- a/src/object/minishSizedEntrance.c +++ b/src/object/minishSizedEntrance.c @@ -1,11 +1,13 @@ #include "global.h" #include "entity.h" +#include "game.h" +#include "player.h" +#include "functions.h" -extern bool32 CheckIsDungeon(); -extern void sub_080AE068(Entity*); -extern void LoadFixedGFX(Entity*, u32); +extern void DoExitTransition(void*); extern void (*const gUnk_08122254[])(Entity*); +extern u16 gUnk_0812225C[]; void MinishSizedEntrance(Entity* this) { gUnk_08122254[this->action](this); @@ -22,3 +24,17 @@ void sub_08090EC0(Entity* this) { LoadFixedGFX(this, 0x184); } } + +void sub_08090F00(Entity* this) { + if (this->type == 1) { + Entity* parent = this->parent; + u32 mask = 1 << this->field_0xf; + if (!(parent->field_0x20 & mask)) { + DeleteThisEntity(); + } + } + if ((gPlayerState.flags.all & 0x80) && sub_080041A0(this, &gPlayerEntity, 4, 4) && + (gPlayerEntity.height.HALF.HI == 0) && (((u16)gPlayerState.field_0x90.HALF.LO) & gUnk_0812225C[this->type2])) { + DoExitTransition((Entity*)GetCurrentRoomProperty(this->actionDelay)); + } +} diff --git a/src/object/object1A.c b/src/object/object1A.c index 837884a9..f028481d 100644 --- a/src/object/object1A.c +++ b/src/object/object1A.c @@ -1,5 +1,6 @@ #include "global.h" #include "entity.h" +#include "random.h" #include "functions.h" extern void sub_08086A6C(); diff --git a/src/object/object1C.c b/src/object/object1C.c index c12a6c1d..0c80735a 100644 --- a/src/object/object1C.c +++ b/src/object/object1C.c @@ -2,7 +2,6 @@ #include "entity.h" extern u32 CheckRectOnScreen(s16, s16, u32, u32); -extern void DeleteThisEntity(); void Object1C(Entity* this) { s32 iVar1; diff --git a/src/object/object1D.c b/src/object/object1D.c index 8442b227..f7343fbe 100644 --- a/src/object/object1D.c +++ b/src/object/object1D.c @@ -1,8 +1,6 @@ #include "global.h" #include "entity.h" -void DeleteThisEntity(); - extern void (*gUnk_081208A0[])(Entity*); void Object1D(Entity* this) { diff --git a/src/object/object2A.c b/src/object/object2A.c index ffd00460..dca66978 100644 --- a/src/object/object2A.c +++ b/src/object/object2A.c @@ -31,7 +31,7 @@ void sub_08089B18(Entity* this) { case 4: if (!CheckFlags(this->field_0x86.HWORD)) { this->spriteSettings.b.draw = FALSE; - this->previousActionFlag = 1; + this->subAction = 1; return; } } diff --git a/src/object/object49.c b/src/object/object49.c index 16bf7bb9..82d39bd6 100644 --- a/src/object/object49.c +++ b/src/object/object49.c @@ -1,7 +1,8 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "functions.h" -#include "position.h" +#include "coord.h" #include "random.h" #include "structures.h" @@ -11,7 +12,6 @@ static void sub_0808F244(Entity*); extern void sub_0806FCF4(Entity*, u32, u32, u32); extern void sub_0808F5EC(Entity*); -extern bool32 sub_0806F3E4(Entity*); extern void (*const gUnk_08121E5C[])(Entity*); extern void (*const gUnk_08121E88[])(Entity*); @@ -59,7 +59,7 @@ static void sub_0808F14C(Entity* this) { sub_0808F2B0(this); if (sub_08003FC4(this, 0x2000) == 0) { this->action++; - SoundReq(0x84); + SoundReq(SFX_WATER_SPLASH); } } @@ -150,13 +150,13 @@ void sub_0808F2C0(Entity* this) { void sub_0808F370(Entity* this) { if (this->action == 0) { - if (this->parent->previousActionFlag == 1) { + if (this->parent->subAction == 1) { this->action = 1; this->field_0x70.WORD = 0; sub_0808F5EC(this); } } else { - u8 flag = this->parent->previousActionFlag - 1; + u8 flag = this->parent->subAction - 1; if (flag < 5) { if (this->field_0x70.WORD == 0) { if (--(*(u32*)&this->field_0x74) == -1) { diff --git a/src/object/object7E.c b/src/object/object7E.c index 6c89947e..c456a841 100644 --- a/src/object/object7E.c +++ b/src/object/object7E.c @@ -1,6 +1,6 @@ #include "global.h" #include "entity.h" -#include "functions.h" +#include "coord.h" void Object7E(Entity* this) { diff --git a/src/object/object86.c b/src/object/object86.c index 9706e040..02e0b480 100644 --- a/src/object/object86.c +++ b/src/object/object86.c @@ -1,9 +1,10 @@ #include "global.h" #include "entity.h" +#include "coord.h" #include "player.h" #include "flags.h" +#include "functions.h" -extern u32 sub_080041A0(Entity*, Entity*, u32, u32); void sub_08099ECC(Entity*); extern void sub_0805E4E0(Entity*, u32); extern void sub_0805B390(u32); @@ -18,7 +19,7 @@ void sub_08099DD0(Entity* this) { this->collisionLayer = 1; this->spriteRendering.b3 = 3; this->spritePriority.b0 = 7; - this->previousActionFlag = 0; + this->subAction = 0; if (GetInventoryValue(0x46)) { this->action = 4; this->frameIndex = 0; @@ -31,7 +32,7 @@ void sub_08099DD0(Entity* this) { void sub_08099E10(Entity* this) { if (CheckLocalFlag(0x74)) { GetNextFrame(this); - if ((this->frames.all == 1) && (this->previousActionFlag == 0)) { + if ((this->frames.all == 1) && (this->subAction == 0)) { this->frames.all = 0; sub_08099ECC(this); } @@ -56,7 +57,7 @@ void sub_08099E58(Entity* this) { void sub_08099E8C(Entity* this) { if (sub_080041A0(this, &gPlayerEntity, 0xc, 0xc)) { - if (this->previousActionFlag == 0) { + if (this->subAction == 0) { sub_08099ECC(this); sub_0805E4E0(this, 0x1e); } @@ -70,7 +71,7 @@ void nullsub_534(Entity* this) { } void sub_08099ECC(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; CopyPosition(this, &gPlayerEntity); gPlayerState.playerAction = 3; gPlayerState.field_0x34[4] = 0; diff --git a/src/object/object9E.c b/src/object/object9E.c index 858ee01b..f8e89b4e 100644 --- a/src/object/object9E.c +++ b/src/object/object9E.c @@ -1,11 +1,11 @@ #include "global.h" #include "entity.h" +#include "coord.h" #include "room.h" +#include "functions.h" extern Hitbox gUnk_080FD168; -extern void SetTile(u32, u32, u32); - void Object9E(Entity* this) { Entity* ent; u32 tilePos; diff --git a/src/object/objectA.c b/src/object/objectA.c index 3679e4bb..0e63b26f 100644 --- a/src/object/objectA.c +++ b/src/object/objectA.c @@ -2,6 +2,7 @@ #include "entity.h" #include "room.h" #include "flags.h" +#include "createObject.h" #include "functions.h" extern Hitbox gUnk_080FD170; diff --git a/src/object/objectA2.c b/src/object/objectA2.c index e79c07f8..0c3307d3 100644 --- a/src/object/objectA2.c +++ b/src/object/objectA2.c @@ -1,6 +1,7 @@ #include "global.h" #include "object.h" #include "menu.h" +#include "random.h" #include "structures.h" #include "functions.h" diff --git a/src/object/objectA8.c b/src/object/objectA8.c index 4cca37f2..c1a5193a 100644 --- a/src/object/objectA8.c +++ b/src/object/objectA8.c @@ -1,14 +1,10 @@ #include "global.h" #include "entity.h" - -extern Entity* CreateItemEntity(u32, u32, u32); -extern void DeleteThisEntity(); -extern void sub_08080CB4(Entity*); +#include "player.h" +#include "functions.h" extern void (*gUnk_08124824[])(Entity*); -extern Entity gPlayerEntity; - void ObjectA8(Entity* this) { if ((this->bitfield & 0x80) != 0) { switch (this->bitfield & 0x7f) { diff --git a/src/object/objectAF.c b/src/object/objectAF.c index c1d32b60..b678d81b 100644 --- a/src/object/objectAF.c +++ b/src/object/objectAF.c @@ -1,5 +1,6 @@ #include "global.h" #include "entity.h" +#include "coord.h" extern void sub_080A0640(Entity*); diff --git a/src/object/objectB2.c b/src/object/objectB2.c index c3eff1eb..0888ed38 100644 --- a/src/object/objectB2.c +++ b/src/object/objectB2.c @@ -1,7 +1,7 @@ #include "global.h" #include "entity.h" +#include "functions.h" -extern void sub_0806F69C(Entity*); extern u32 sub_080AE4CC(Entity*, u32, u32, u32); extern void* gUnk_02027EB4; diff --git a/src/object/pinwheel.c b/src/object/pinwheel.c index d6a24471..7de61338 100644 --- a/src/object/pinwheel.c +++ b/src/object/pinwheel.c @@ -1,10 +1,9 @@ #include "global.h" #include "entity.h" -#include "functions.h" +#include "flags.h" +#include "createObject.h" extern u32 ReadBit(u32*, u32); -extern void DeleteThisEntity(); -extern u32 CheckLocalFlag(u32); extern u32 gUnk_020342F8; extern u16 gUnk_08125050[]; diff --git a/src/object/pot.c b/src/object/pot.c index f28fb9ee..d589662d 100644 --- a/src/object/pot.c +++ b/src/object/pot.c @@ -16,10 +16,8 @@ extern void (*const gUnk_0811F0C4[])(Entity*); extern Hitbox gUnk_080FD338; // TODO: should be const extern Hitbox gUnk_080FD340; // TODO: should be const -extern u32 sub_08016A30(Entity*); extern u32 sub_080001DA(u32, u32); extern void sub_08078930(Entity*); -extern u32 sub_080002B8(Entity*); extern void sub_08016A6C(Entity*); void Pot(Entity* this) { @@ -62,7 +60,7 @@ void sub_08082310(Entity* this) { switch (var0) { case 0x13: this->action = 3; - this->previousActionFlag = 0; + this->subAction = 0; break; case 0x1D: SetTile((u16)this->field_0x70.HALF.LO, COORD_TO_TILE(this), this->collisionLayer); @@ -114,7 +112,7 @@ void sub_08082310(Entity* this) { } void sub_080824F8(Entity* this) { - gUnk_0811F0A8[this->previousActionFlag](this); + gUnk_0811F0A8[this->subAction](this); } void sub_08082510(Entity* this) { @@ -125,7 +123,7 @@ void sub_08082510(Entity* this) { this->flags2 = gPlayerEntity.flags2; this->spriteOffsetY = 0; SetTile((u16)this->field_0x70.HALF.LO, COORD_TO_TILE(this), this->collisionLayer); - this->previousActionFlag++; + this->subAction++; } void nullsub_511(Entity* this) { @@ -166,7 +164,7 @@ void sub_080825F0(Entity* this) { static void sub_08082608(Entity* this) { this->action = 1; - this->previousActionFlag = 0; + this->subAction = 0; } void sub_08082614(Entity* this) { @@ -203,11 +201,11 @@ void sub_08082614(Entity* this) { } void sub_080826E4(Entity* this) { - gUnk_0811F0C4[this->previousActionFlag](this); + gUnk_0811F0C4[this->subAction](this); } void sub_080826FC(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->field_0x1d = 48; this->actionDelay = 0; } diff --git a/src/object/railtrack.c b/src/object/railtrack.c index 2e3a3d66..52a74bc3 100644 --- a/src/object/railtrack.c +++ b/src/object/railtrack.c @@ -2,13 +2,12 @@ #include "entity.h" #include "room.h" #include "flags.h" +#include "functions.h" extern u32* GetLayerByIndex(u32); extern void sub_08085394(Entity*); extern void sub_0808543C(Entity*); -extern void EnqueueSFX(u32); extern u32 sub_080854A8(Entity*); -extern void SetTile(u32, u32, u32); extern void (*const gUnk_081205D0[])(Entity*); diff --git a/src/object/smoke.c b/src/object/smoke.c index ade9d2cd..86c75efc 100644 --- a/src/object/smoke.c +++ b/src/object/smoke.c @@ -1,9 +1,8 @@ #include "global.h" #include "entity.h" +#include "random.h" #include "functions.h" -extern void sub_0806F69C(Entity*); - extern void (*const gUnk_08121060[])(Entity*); extern void (*const gUnk_08121070[])(Entity*); diff --git a/src/object/thoughtBubble.c b/src/object/thoughtBubble.c index 596cb382..5e77d9e1 100644 --- a/src/object/thoughtBubble.c +++ b/src/object/thoughtBubble.c @@ -1,10 +1,6 @@ #include "global.h" #include "entity.h" - -extern void InitializeAnimation(Entity*, u32); -extern void SoundReq(u32); -extern void DeleteThisEntity(); -extern void GetNextFrame(Entity*); +#include "functions.h" extern void (*const ThoughtBubble_Behaviors[])(Entity*); diff --git a/src/object/treeHidingPortal.c b/src/object/treeHidingPortal.c index 912003b9..53f593bb 100644 --- a/src/object/treeHidingPortal.c +++ b/src/object/treeHidingPortal.c @@ -1,21 +1,20 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "flags.h" #include "player.h" #include "room.h" +#include "structures.h" +#include "functions.h" extern void sub_0809E96C(Entity*); -extern u32 sub_0800419C(Entity*, Entity*, u32, u32); extern void CreateSparkle(Entity*); extern u32 sub_0809E9A0(void); -extern void sub_08078A90(u32); extern void sub_0809E918(Entity*); -extern void SoundReq(u32); extern void CreateMinishEntrance(u32 tile); extern void (*const gUnk_08124354[])(Entity*); -extern u32 gScreenTransition; extern s16 gUnk_08124364[]; void TreeHidingPortal(Entity* this) { @@ -36,7 +35,7 @@ void sub_0809E86C(Entity* this) { if (sub_0800419C(this, &gPlayerEntity, 0x30, 0x30)) { if (CheckGlobalFlag(EZERO_1ST)) { - if (((gScreenTransition & 3) == 0)) { + if (((gScreenTransition.frameCount & 3) == 0)) { CreateSparkle(this); } } @@ -62,7 +61,7 @@ void sub_0809E8EC(Entity* this) { if (--this->actionDelay == 0) { SetFlag(this->field_0x86.HWORD); sub_08078A90(0); - SoundReq(0x73); + SoundReq(SFX_SECRET_BIG); DeleteThisEntity(); } } diff --git a/src/object/well.c b/src/object/well.c index fda35fed..86710ac6 100644 --- a/src/object/well.c +++ b/src/object/well.c @@ -2,11 +2,7 @@ #include "entity.h" #include "room.h" #include "player.h" - -void SetTile(u32 tileIndex, s32 tilePosition, s32 layerIndex); -s32 GetTileType(s32 tilePosition, s32 layerIndex); -void sub_08078B48(); -void DeleteThisEntity(); +#include "functions.h" extern void (*gUnk_08124C08[])(Entity*); diff --git a/src/object/windTribeFlag.c b/src/object/windTribeFlag.c index 9c769808..bc9d0fa3 100644 --- a/src/object/windTribeFlag.c +++ b/src/object/windTribeFlag.c @@ -1,6 +1,6 @@ #include "global.h" #include "entity.h" -#include "functions.h" +#include "random.h" void WindTribeFlag(Entity* this) { if (this->action == 0) { diff --git a/src/object/windcrest.c b/src/object/windcrest.c index b4b7893a..b21c5ee0 100644 --- a/src/object/windcrest.c +++ b/src/object/windcrest.c @@ -1,11 +1,10 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "save.h" #include "script.h" extern void sub_08078850(Entity*, u32, u32, u8*); -extern void SoundReq(u32); -extern Entity* CreateFx(Entity*, u32, u32); extern u8 gUnk_08125010; @@ -24,7 +23,7 @@ void sub_080A2124(Entity* this) { } void Windcrest_Unlock(Entity* this) { - SoundReq(0x72); + SoundReq(SFX_SECRET); gSave.windcrests = gSave.windcrests | 1 << (this->type2 + 0x18); CreateFx(this, 0x46, 0); } diff --git a/src/player.c b/src/player.c index 7dfcbb93..c542c062 100644 --- a/src/player.c +++ b/src/player.c @@ -1,40 +1,68 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "player.h" #include "textbox.h" -#include "functions.h" -#include "readKeyInput.h" +#include "utils.h" #include "area.h" #include "save.h" +#include "game.h" +#include "functions.h" -extern const void (*const gUnk_0811B9E0[])(Entity*); -extern const void (*const gUnk_0811BA60[])(Entity*); -extern const void (*const gUnk_0811BA68[])(Entity*); -extern const void (*const gUnk_0811BA74[])(Entity*); -extern const void (*const gUnk_0811BA7C[])(Entity*); -extern const void (*const gUnk_0811BA88[])(Entity*); -extern const void (*const gUnk_0811BA94[])(Entity*); -extern const void (*const gUnk_0811BA9C[])(Entity*); - -extern void sub_08079458(); +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*); + +extern void RespawnPlayer(); extern void sub_080797EC(); extern void sub_08079E08(); extern void sub_08078F60(); +extern void sub_0806F948(); +extern void sub_08077698(); +extern void sub_0805E544(); +extern void sub_080717F8(); +extern void DoExitTransition(); +extern void UnfreezeTime(); +extern void sub_08071A6C(); +extern void sub_08052BB8(); +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(); + +typedef struct { + u8 frame; + u8 dummy; + u16 speed; +} PushFrames; + +extern PushFrames gUnk_0811BAF0[]; extern Hitbox gUnk_08114F88; +extern ScreenTransitionData gUnk_0813AB58; -// inject -void sub_08070680(Entity* this) { - gUnk_0811B9E0[this->action](this); +void DoPlayerAction(Entity* this) { + sPlayerActions[this->action](this); } -void sub_08070698(Entity* this) { +void PlayerInit(Entity* this) { Entity* ent; gPlayerState.field_0x0[0] = 0xff; - gPlayerState.field_0x16[0] = gPlayerEntity.x.HALF.HI; - gPlayerState.field_0x16[1] = gPlayerEntity.y.HALF.HI; - this->flags = this->flags | 0x80; + gPlayerState.startPosX = gPlayerEntity.x.HALF.HI; + gPlayerState.startPosY = gPlayerEntity.y.HALF.HI; + this->flags |= 0x80; this->spritePriority.b0 = 0xc; this->spritePriority.b1 = 1; this->spriteSettings.b.shadow = 1; @@ -65,7 +93,7 @@ void sub_08070698(Entity* this) { sub_08079938(); gPlayerState.field_0xa8 = 7; sub_0807ACCC(this); - ent = FindEntityInListByForm(0x6, 0xf, 0x6, 0xb, 0x0); + ent = FindEntity(0x6, 0xf, 0x6, 0xb, 0x0); if (ent != NULL) { DeleteEntity(ent); } @@ -74,9 +102,7 @@ void sub_08070698(Entity* this) { } // PlayerState.flags need to be 100% before this one can reasonably be done -NONMATCH("asm/non_matching/player/sub_08070794.s", void sub_08070794(Entity* this)) { -} -END_NONMATCH +ASM_FUNC("asm/non_matching/player/sub_08070794.s", void PlayerNormal(Entity* this)) void sub_08070BEC(Entity* this, u32 r0) { if (r0 & 1) @@ -88,12 +114,12 @@ void sub_08070BEC(Entity* this, u32 r0) { sub_08079E08(); } -void sub_08070C10(Entity* this) { - gPlayerState.field_0xd[0] = 0xFF; +void PlayerFall(Entity* this) { + gPlayerState.field_0xd = 0xFF; gPlayerState.pushedObject = 0x80; gPlayerState.field_0xa8 = 10; - gUnk_0811BA60[this->previousActionFlag](this); + gUnk_0811BA60[this->subAction](this); } void sub_08070C3C(Entity* this) { @@ -111,13 +137,13 @@ void sub_08070C3C(Entity* this) { else gPlayerState.field_0x8 = 0x1b8; - this->previousActionFlag++; + this->subAction++; this->flags &= ~0x80; this->spritePriority.b1 = 0; ResetPlayer(); sub_0807A108(); - SoundReq(0x7b); - SoundReq(0x85); + SoundReq(SFX_PLY_VO7); + SoundReq(SFX_FALL_HOLE); } void sub_08070CB4(Entity* this) { @@ -128,16 +154,16 @@ void sub_08070CB4(Entity* this) { this->spriteSettings.b.draw = 0; } else { gPlayerState.flags.all &= ~(0x4 | 0x8000); - sub_08079458(); + RespawnPlayer(); gPlayerState.field_0xa = 0; - this->hurtBlinkTime = 0x20; + this->iframes = 32; ModHealth(-2); } } } -void sub_08070D20(Entity* this) { - gUnk_0811BA68[this->previousActionFlag](this); +void PlayerBounce(Entity* this) { + gUnk_0811BA68[this->subAction](this); } void sub_08070D38(Entity* this) { @@ -145,7 +171,7 @@ void sub_08070D38(Entity* this) { this->direction = ((this->animationState & 0xe) << 2) ^ 0x10; this->speed = 0x100; this->field_0x42 = 0; - this->previousActionFlag++; + this->subAction++; this->actionDelay = gPlayerState.field_0x38; this->spriteIndex = 1; @@ -201,7 +227,7 @@ NONMATCH("asm/non_matching/player/sub_08070DC4.s", void sub_08070DC4(Entity* thi this->spriteIndex = 1; this->actionDelay = 8; - this->previousActionFlag++; + this->subAction++; if ((gPlayerState.flags.all & 0x80) == 0) gPlayerState.field_0x8 = 0x100; @@ -224,7 +250,7 @@ void sub_08070E9C(Entity* this) { gPlayerState.field_0x27[0] = 4; gPlayerState.field_0xa8 = 0x13; sub_0807A1B8(); - gUnk_0811BA74[this->previousActionFlag](this); + gUnk_0811BA74[this->subAction](this); } } @@ -232,7 +258,7 @@ void sub_08070EDC(Entity* this) { this->scriptedScene = 2; if ((gTextBox.doTextBox & 0x7f) != 0) - this->previousActionFlag = 1; + this->subAction = 1; if ((gPlayerState.flags.all & 0x80) == 0) sub_08079938(); @@ -248,13 +274,13 @@ void sub_08070f24(Entity* this) { } } -void sub_08070F50(Entity* this) { +void PlayerItemGet(Entity* this) { Entity* child; u8* temp; // todo: retype gPlayerState.field_0xa8 = 0x15; this->flags &= ~(0x80); - gUnk_0811BA7C[this->previousActionFlag](this); + gUnk_0811BA7C[this->subAction](this); child = this->attachedEntity; if (child != NULL) { @@ -275,7 +301,7 @@ void sub_08070FA4(Entity* this) { gPlayerState.jumpStatus = 0; if ((gPlayerState.flags.all & 0x80) == 0) { - if ((gPlayerState.flags.all & 0x8) != 0) { + if (gPlayerState.flags.all & 0x8) { if (sub_080542AC(gPlayerState.field_0x38)) { temp = 0x45e; } else { @@ -291,16 +317,15 @@ void sub_08070FA4(Entity* this) { gPlayerState.field_0x8 = temp; } - this->previousActionFlag = 1; + this->subAction = 1; ResetPlayer(); sub_08078F60(); } void sub_08071020(Entity* this) { UpdateAnimationSingleFrame(this); - if (this->frames.all != 0) { - this->previousActionFlag = 2; - } + if (this->frames.all != 0) + this->subAction = 2; } void sub_08071038(Entity* this) { @@ -310,24 +335,24 @@ void sub_08071038(Entity* this) { if (sub_08078EFC() || (gTextBox.doTextBox & 0x7f)) return; - if ((this->frames.all & 0x80) != 0) { + if (this->frames.all & 0x80) { this->attachedEntity = 0; this->field_0x42 = 0; - this->hurtBlinkTime = 0xf8; + this->iframes = 248; gPlayerState.jumpStatus = 0; sub_080791D0(); } } -void sub_08071084(Entity* this) { +void PlayerJump(Entity* this) { gPlayerState.field_0xa8 = 0xb; - gUnk_0811BA88[this->previousActionFlag](this); + gUnk_0811BA88[this->subAction](this); } void sub_080710A8(Entity* this) { u32 temp; - this->previousActionFlag++; + this->subAction++; gPlayerState.flags.all |= 1; gPlayerState.flags.all &= ~(0x400 | 0x800); @@ -353,10 +378,10 @@ void sub_080710A8(Entity* this) { asm("lsl r0, r0, #0x4"); this->field_0x20 = (temp - 4) * 64 * 64; - this->speed = 0x100; + this->speed = 256; sub_0807A108(); - SoundReq(0x7c); - SoundReq(0x78); + SoundReq(SFX_PLY_JUMP); + SoundReq(SFX_PLY_VO4); } void sub_08071130(Entity* this) { @@ -367,7 +392,7 @@ void sub_08071130(Entity* this) { if (gPlayerState.field_0x1a[1] == 0) { UpdateAnimationSingleFrame(this); - if ((this->frames.all & 1)) + if (this->frames.all & 1) return; } @@ -401,7 +426,7 @@ void sub_08071130(Entity* this) { this->actionDelay = 6; if (((gPlayerState.heldObject | gPlayerState.keepFacing) == 0) && ((gPlayerState.flags.all & 0x80) == 0)) { - if ((gPlayerState.flags.all & 0x8) != 0) { + if (gPlayerState.flags.all & 0x8) { gPlayerState.field_0x8 = 0x424; } else { gPlayerState.field_0x8 = 0x820; @@ -409,10 +434,10 @@ void sub_08071130(Entity* this) { this->animIndex = 0xff; } - this->previousActionFlag++; + this->subAction++; sub_08078F60(); this->field_0x42 = 0; - SoundReq(0x7d); + SoundReq(SFX_PLY_LAND); } void sub_08071208(Entity* this) { @@ -428,33 +453,31 @@ void sub_08071208(Entity* this) { } } -void sub_08071248(Entity* this) { +void PlayerDrown(Entity* this) { gPlayerState.field_0xa8 = 0x16; gPlayerState.flags.all |= 4; this->flags &= ~0x80; - gUnk_0811BA94[this->previousActionFlag](this); + gUnk_0811BA94[this->subAction](this); } void sub_0807127C(Entity* this) { - this->previousActionFlag = 1; + this->subAction = 1; this->spritePriority.b1 = 0; - if ((gPlayerState.flags.all & 0x80) != 0) { + if (gPlayerState.flags.all & 0x80) { this->actionDelay = 0x3c; gPlayerState.field_0x8 = 0xc19; SoundReq(0x84); } else { - if ((gPlayerState.flags.all & 0x10000) == 0) { + if ((gPlayerState.flags.all & 0x10000) == 0) sub_08004168(this); - } CreateFx(this, 11, 0); - if ((gPlayerState.flags.all & 8) == 0) { + if ((gPlayerState.flags.all & 8) == 0) gPlayerState.field_0x8 = 0x72c; - } else { + else gPlayerState.field_0x8 = 0x44c; - } } ResetPlayer(); } @@ -480,28 +503,29 @@ void sub_080712F0(Entity* this) { return; this->field_0x42 = 0; - this->hurtBlinkTime = 0x20; + this->iframes = 32; this->spritePriority.b1 = 1; this->spriteSettings.b.draw = FALSE; - gPlayerState.flags.all &= ~(0x4); - sub_08079458(); + gPlayerState.flags.all &= ~0x4; + RespawnPlayer(); } -void sub_08071380(Entity* this) { +static void PlayerUsePortal(Entity* this) { gPlayerState.field_0xa8 = 0xe; - gUnk_0811BA9C[this->previousActionFlag](this); + gUnk_0811BA9C[this->subAction](this); - if ((this->previousActionFlag == 7) || (this->previousActionFlag < 3)) + // probably a switch + if ((this->subAction == 7) || (this->subAction < 3)) return; if ((gPlayerState.flags.all & 0x20) == 0) return; - if ((gInput.newKeys & 0x102) == 0) + if ((gInput.newKeys & (0x100 | 0x2)) == 0) return; - if (CheckIsDungeon() || gArea.field_0x17 == 3) { - this->previousActionFlag = 7; + if (CheckIsDungeon() || gArea.curPortalType == 3) { + this->subAction = 7; this->actionDelay = 30; DoFade(7, 16); SoundReq(0xf8); @@ -510,19 +534,19 @@ void sub_08071380(Entity* this) { } } -void sub_08071400(Entity* this) { +static void PortalJumpOnUpdate(Entity* this) { u16 x; u16 y; - this->flags &= ~(0x80); + this->flags &= ~0x80; this->field_0x42 = 0; - x = gArea.field_0x12; - y = gArea.field_0x14; + x = gArea.curPortalX; + y = gArea.curPortalY; if ((this->x.HALF.HI != x) || (this->y.HALF.HI != y)) { - this->direction = sub_080045D4(this->x.HALF.HI, this->y.HALF.HI, gArea.field_0x12, gArea.field_0x14); - this->speed = 0x100; + this->direction = sub_080045D4(this->x.HALF.HI, this->y.HALF.HI, gArea.curPortalX, gArea.curPortalY); + this->speed = 256; sub_08079E08(); } @@ -531,17 +555,542 @@ void sub_08071400(Entity* this) { if (gPlayerState.jumpStatus == 0) { gPlayerState.flags.all |= 0x20; - this->previousActionFlag = 1; + this->subAction = 1; this->animationState = 4; this->spriteSettings.b.flipX = FALSE; - if (gArea.field_0x17 == 4) { + if (gArea.curPortalType == 4) { gPlayerState.field_0x8 = 0x52c; } } this->actionDelay = 8; - if (gArea.field_0x17 != 3) { + if (gArea.curPortalType != 3) { this->spritePriority.b0 = 3; } } + +static void PortalStandUpdate(Entity* this) { + switch (gArea.curPortalType) { + case 4: + case 5: + sub_0806F948(&gPlayerEntity); + break; + } + + if ((gPlayerState.field_0xd & 0x84) == 0) { + if (this->direction != gPlayerState.field_0xd) { + this->actionDelay = 8; + } + if (--this->actionDelay == 0xff) { + this->direction = gPlayerState.field_0xd; + this->animationState = this->direction >> 2; + this->field_0x20 = 0x20000; + this->speed = 256; + this->action = 9; + this->subAction = 7; + this->field_0xf = 0; + gPlayerState.field_0x8 = (gPlayerState.flags.all & 8) ? 0x41C : 0x80C; + gPlayerState.flags.all &= ~0x20; + return; + } + this->direction = gPlayerState.field_0xd; + } else { + this->actionDelay = 8; + } + + if (gArea.curPortalType == 4) { + if (this->frames.all == 0) { + UpdateAnimationSingleFrame(this); + return; + } + } else { + sub_08077698(this); + } + sub_08079938(); +} + +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, 6, 1, 0); + sub_08077B20(); + sub_0805E544(); +} + +static void PortalActivateUpdate(Entity* this) { + if (this->field_0xf) + return; + + UpdateAnimationSingleFrame(this); + + if (gPlayerState.flags.all & 0x80) + this->subAction = 4; +} + +static void PortalShrinkInit(Entity* this) { + this->subAction = 5; + this->spritePriority.b1 = 0; + this->field_0xf = 0; + this->spriteRendering.b0 = 3; + *(u32*)&this->field_0x80.HWORD = 0x100; + *(u32*)&this->cutsceneBeh = 0x100; + sub_0805EC9C(this, 0x100, 0x100, 0); + gPlayerState.field_0x8 = 0x2c3; + gPlayerState.flags.all |= 0x80; + SoundReq(0x16f); +} + +// horrible +ASM_FUNC("asm/non_matching/player/sub_08071634.s", static void PortalShrinkUpdate(Entity* this)) + +static void PortalEnterUpdate(Entity* this) { + if (this->actionDelay == 0) { + if (sub_08003FC4(this, 0x2000)) + return; + + this->spriteSettings.b.draw = FALSE; + + if (gArea.curPortalType == 3) { + if (--this->field_0xf == 0) + sub_080717F8(this); + return; + } + if (gArea.curPortalType == 6) + DoExitTransition(&gUnk_0813AB58); + else + gArea.playShrinkSeq = 1; + + return; + } + this->actionDelay--; +} + +static void PortalUnknownUpdate(Entity* this) { + if (gFadeControl.active) + return; + + if (this->actionDelay != 0) { + this->actionDelay--; + return; + } + + sub_080717F8(this); + sub_080500F4(0x10); +} + +extern s16 gUnk_0811BAC4[]; + +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]; + gArea.unk1A = 0xb4; + gUnk_02034490[0] = 0; + this->action = 9; + this->subAction = 0; + gPlayerState.flags.all = (gPlayerState.flags.all & ~0x20) | 0x80; + sub_0805EC60(this); + UnfreezeTime(); +} + +void PlayerTalkEzlo(Entity* this) { + if (sub_08078EFC()) { + sub_08056360(); + sub_08071A6C(); + } else { + gPlayerState.field_0xa8 = 0x13; + this->flags &= ~0x80; + gUnk_0811BAD4[this->subAction](this); + } +} + +void sub_080718A0(Entity* this) { + ResetPlayer(); + gUnk_03000B80.filler[0x63] = 0; + this->iframes = 0; + gUnk_03003DC0.unk0 = 6; + this->scriptedScene = 6; + + if (gPlayerState.flags.all & 0x80) { + this->subAction = 2; + this->spritePriority.b1 = 0; + sub_08052BB8(); + return; + } + + if (gPlayerState.jumpStatus == 0) { + this->subAction++; + + if (this->animationState == 2) + gPlayerState.field_0x8 = 0x3ca; + else + gPlayerState.field_0x8 = 0x3c6; + + this->spriteSettings.b.flipX = 0; + return; + } + + if (!sub_08003FC4(this, 0x2000)) + gPlayerState.jumpStatus = 0; +} + +void sub_0807193C(Entity* this) { + Entity* child; + + UpdateAnimationSingleFrame(this); + if (this->frames.all & 0x80) { + this->subAction++; + child = CreateObjectWithParent(this, 6, 0, 0); + this->attachedEntity = child; + if (child != NULL) { + if (this->animationState == 2) + gPlayerState.field_0x8 = 0x3cc; + else + gPlayerState.field_0x8 = 0x3c7; + sub_08052BB8(); + } + } +} + +void sub_08071990(Entity* this) { + u32 temp; + + if ((gTextBox.doTextBox & 0x7f) == 0) { + this->subAction++; + + if ((gPlayerState.flags.all & 0x80) == 0) { + if (this->animationState == 2) + gPlayerState.field_0x8 = 0x3cd; + else + gPlayerState.field_0x8 = 0x3c9; + } else { + sub_08071A6C(); + sub_08079258(); + } + return; + } + + if (gPlayerState.flags.all & 0x80) + return; + + if (this->animationState == 2) + temp = 4; + else + temp = 0; + + if (this->attachedEntity->actionDelay != 0) { + if ((u8)(temp + 200) != this->animIndex) { + gPlayerState.field_0x8 = temp + 0x3c8; + return; + } + } else { + if ((u8)(temp + 199) != this->animIndex) { + gPlayerState.field_0x8 = temp + 0x3c7; + return; + } + } + UpdateAnimationSingleFrame(this); +} + +void sub_08071A4C(Entity* this) { + UpdateAnimationSingleFrame(this); + if (this->frames.all & 0x80) { + sub_08071A6C(); + sub_0807921C(); + } +} + +void sub_08071A6C(void) { + gUnk_03003DC0.unk0 = 0; + gPlayerEntity.scriptedScene = gPlayerEntity.scriptedScene2; +} + +void PlayerPush(Entity* this) { + gPlayerState.field_0xa8 = 0x19; + gUnk_0811BAE4[this->subAction](this); +} + +void sub_08071AB0(Entity* this) { + u32 speed; + + this->subAction++; + gPlayerState.flags.all |= 1; + if (this->type == 1) { + this->speed = 0; + this->actionDelay = 0; + this->field_0xf = 1; + } else { + this->speed = (gPlayerState.flags.all & 0x80) ? 64 : 128; + } + sub_08071AF0(this); +} + +void sub_08071AF0(Entity* this) { + 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; + this->actionDelay++; + } else { + this->subAction++; + return; + } + } + } else { + gPlayerState.pushedObject--; + if ((gPlayerState.pushedObject & 0x7f) == 0) { + this->subAction++; + } + } + sub_08079E08(); +} + +void sub_08071B60(Entity* this) { + gPlayerState.pushedObject = 2; + gPlayerState.flags.all &= ~0x1; + this->type = 0; + this->field_0x42 = 0; + sub_080728AC(this); + this->field_0xf = 6; + if ((gPlayerState.flags.all & 0x80) == 0) { + gPlayerState.field_0x8 = 0x104; + this->spriteIndex = 3; + InitAnimationForceUpdate(this, (this->animationState >> 1) + 0x3c); + } +} + +extern void (*const gUnk_0811BB2C[])(Entity*); + +void PlayerMinishDie(Entity* this) { + this->flags &= ~0x80; + gUnk_0811BB2C[this->subAction](this); + gPlayerState.field_0xa8 = 0x12; +} + +void sub_08071BDC(Entity* this) { + u32 temp; + + if (gPlayerState.flags.all & (0x10 | 0x100)) + return; + + if (sub_08003FC4(this, 0x2000)) { + if ((gPlayerState.flags.all & 8) != 0) + gPlayerState.field_0x8 = 0x420; + else + gPlayerState.field_0x8 = 0x810; + return; + } + + gPlayerState.playerAction = 0; + if (gPlayerState.flags.all & 0x80) { + if ((u8)(gPlayerState.field_0x10[2] - 8) < 3) { + sub_0807A298(this); + RespawnPlayer(); + this->action = 10; + } + temp = 0xc1a; + } else { + temp = (gPlayerState.flags.all & 8) ? 0x459 : 0x1bc; + } + gPlayerState.field_0x8 = temp; + + gPlayerState.flags.all &= ~(0x1000000 | 0x200000 | 0x40000 | 0x800 | 0x400 | 0x100 | 0x1); + this->subAction = 1; + this->animationState = 4; + this->spritePriority.b1 = 1; + this->spriteSettings.b.draw = 3; + gPlayerState.jumpStatus = 0; + gPlayerState.pushedObject = 0; + sub_0800451C(this); + ResetPlayer(); + SoundReq(0x87); +} + +void sub_08071CAC(Entity* this) { + UpdateAnimationSingleFrame(this); + if (this->frames.all & 0x80) { + u32 temp; + if ((gPlayerState.flags.all & 0x80) == 0) + temp = (gPlayerState.flags.all & 8) ? 0x45a : 0x2bd; + else + temp = 0xc1b; + gPlayerState.field_0x8 = temp; + + this->subAction = 2; + this->actionDelay = 0xf0; + SoundReq(0x7b); + } +} + +void sub_08071D04(Entity* this) { + int idx; + int deltaHealth; + + UpdateAnimationSingleFrame(this); + if (this->frames.all == 0) + return; + + deltaHealth = 0; + idx = GetBottleContaining(0x28); + if (idx != 0) { + gSave.stats.bottles[idx - 1] = 0x20; + CreateObject(0x40, 0x60, 2); + deltaHealth = 32; + } + + if (deltaHealth != 0) { + ModHealth(deltaHealth); + this->subAction = 3; + gPlayerState.field_0x3c[0] = 0; + this->direction = 0xff; + this->speed = 0; + this->field_0x20 = 0x18000; + gPlayerState.jumpStatus = 1; + gPlayerState.swimState = 0; + return; + } + + gScreenTransition.field_0x4[1] = 1; +} + +void sub_08071D80(Entity* this) { + UpdateAnimationSingleFrame(this); + gPlayerState.field_0x14 = 1; + sub_08073904(this); + if ((gPlayerState.jumpStatus & 7) == 3) { + gPlayerState.jumpStatus = 0; + this->iframes = 226; + UnfreezeTime(); + sub_080791D0(); + } +} + +void sub_08071DB8(Entity* this) { + gUnk_0811BB3C[this->subAction](this); +} + +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; + } else { + this->subAction = 1; + gPlayerState.field_0x8 = 0x114; + } +} + +void sub_08071E04(Entity* this) { + if ((this->height.WORD != 0) && (gPlayerState.field_0x14 == '\0')) { + sub_0807A1B8(); + if (gPlayerState.field_0x10[2] == 1) { + gPlayerState.field_0x10[1] = 7; + gPlayerState.flags.all |= 0x200; + sub_080791BC(); + return; + } + } + + UpdateAnimationSingleFrame(this); + if (sub_08079B24() == 0) { + sub_08079708(this); + return; + } + + sub_080792D8(); + if (sub_0807953C()) + this->actionDelay -= 2; + else + this->actionDelay -= 1; + + if ((s8)this->actionDelay < 1) + sub_080791BC(); +} + +void sub_08071E74(Entity* this) { + u32 temp; + + sub_08003FC4(this, 0x2000); + sub_08079E08(); + temp = this->actionDelay--; + if (temp == 0) + sub_080791BC(); +} + +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, +}; diff --git a/src/playerItem.c b/src/playerItem.c index 364502d0..7eca5211 100644 --- a/src/playerItem.c +++ b/src/playerItem.c @@ -1,4 +1,6 @@ -extern void DeleteEntity(); +#include "global.h" +#include "functions.h" + extern void sub_080A7544(); extern void sub_0801B188(); extern void sub_0801B45C(); diff --git a/src/position.c b/src/position.c deleted file mode 100644 index 628042c3..00000000 --- a/src/position.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "global.h" -#include "entity.h" -#include "position.h" -#include "functions.h" - -extern u8 gUnk_08114F78[]; -extern u8 gUnk_08114F80[]; - -void CopyPosition(Entity* param_1, Entity* param_2) { - PositionRelative(param_1, param_2, 0, 0); -} - -void PositionEntityOnTop(Entity* ent, Entity* ent2) { - PositionRelative(ent, ent2, 0, 0); - ResolveEntityOnTop(ent, ent2); -} - -void PositionRelative(Entity* source, Entity* target, s32 offsetX, s32 offsetY) { // r0, r1, r2, r3 - s32 x; - s32 y; - - x = source->x.WORD; - target->x.WORD = x + offsetX; - - y = source->y.WORD; - target->y.WORD = y + offsetY; - - target->height = source->height; // ldr - target->collisionLayer = source->collisionLayer; - UpdateSpriteForCollisionLayer(target); -} - -void CopyPositionAndSpriteOffset(Entity* param_1, Entity* param_2) { - param_2->spriteOffsetX = param_1->spriteOffsetX; - param_2->spriteOffsetY = param_1->spriteOffsetY; - PositionRelative(param_1, param_2, 0, 0); -} - -void sub_0806FA90(Entity* param_1, Entity* param_2, s32 offsetX, s32 offsetY) { - param_2->spriteOffsetX = param_1->spriteOffsetX; - param_2->spriteOffsetY = param_1->spriteOffsetY; - PositionRelative(param_1, param_2, offsetX * 64 * 32 * 32, offsetY * 64 * 32 * 32); -} - -void ResolveEntityOnTop(Entity* param_1, Entity* param_2) { - param_2->spritePriority.b0 = gUnk_08114F78[param_1->spritePriority.b0]; -} - -void sub_0806FAD8(Entity* param_1, Entity* param_2) { - param_2->spritePriority.b0 = gUnk_08114F80[param_1->spritePriority.b0]; -} @@ -1,8 +1,8 @@ #include "global.h" +#include "audio.h" #include "entity.h" #include "area.h" #include "room.h" -#include "functions.h" #include "flags.h" #include "npc.h" #include "player.h" @@ -11,6 +11,8 @@ #include "structures.h" #include "save.h" #include "script.h" +#include "random.h" +#include "functions.h" void sub_0804B3C4(void* arg0) { sub_0804B29C(arg0); @@ -441,8 +443,6 @@ u32 sub_0804B8B0(void) { return 1; } -extern void* script_08010A5C[]; - void sub_0804B8F0(void) { if (CheckLocalFlag(0x91)) { ClearLocalFlag(0x91); @@ -2236,12 +2236,12 @@ void sub_0804CD48(void) { gFadeControl.active = 0; gUsedPalettes = 0; *(u16*)0x5000000 = 0x7fff; - sub_0801DA90(1); + DispReset(1); } if (CheckGlobalFlag(LV1_CLEAR)) { LoadRoomEntityList(&gUnk_080DF94C); } else { - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); gArea.musicIndex = gArea.pMusicIndex; } } @@ -2429,7 +2429,7 @@ void sub_0804CED8(void) { sub_0807AABC(&gPlayerEntity); LoadRoomEntityList(&gUnk_080E1814); } else { - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); gArea.musicIndex = gArea.pMusicIndex; } } @@ -2523,10 +2523,10 @@ void sub_0804CFB0(void) { if (!CheckFlags(0x31)) { if (gScreenTransition.field_0x38 == 0) { - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); } else { if (gScreenTransition.field_0x39 == 0) { - SoundReq(0x80050000); + SoundReq(SONG_STOP); sub_08078A90(3); } } @@ -2757,12 +2757,11 @@ u32 sub_0804D13C() { extern EntityData gUnk_080E49F4; void sub_0804D140(void) { - sub_0805308C(0x100); if (CheckGlobalFlag(LV4_CLEAR)) { LoadRoomEntityList(&gUnk_080E49F4); } else { - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); gArea.musicIndex = gArea.pMusicIndex; } } @@ -3091,7 +3090,7 @@ void sub_0804D384(void) { sub_08078A90(3); LoadRoomEntityList(&gUnk_080E72E4); gArea.musicIndex = gArea.pMusicIndex; - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); } } } @@ -3499,7 +3498,7 @@ u32 sub_0804D6C4() { } void sub_0804D6C8(void) { - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); gArea.musicIndex = gArea.pMusicIndex; } @@ -4308,8 +4307,6 @@ void LoadHyruleTown(void) { } } -extern EntityData gUnk_080EEBAC; - void sub_0804E130(void) { if ((gSave.windcrests & 0x8000000) == 0) { LoadRoomEntityList(&gUnk_080EEBAC); @@ -4500,7 +4497,7 @@ void sub_0804E3C4() { } r = Random(); index = gUnk_080F0D58[index][r & 0x1f]; - LoadRoomEntityList(gUnk_080F0CB8[index & 0xF]); + LoadRoomEntityList((EntityData*)gUnk_080F0CB8[index & 0xF]); index >>= 4; r >>= 8; index = gUnk_080F0E08[index][r & 0x1F]; @@ -4509,7 +4506,7 @@ void sub_0804E3C4() { index = 0xE; } sub_0804B3C4(&gUnk_080F0E1C[index]); - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); } u32 sub_0804E45C() { @@ -4717,7 +4714,7 @@ extern EntityData gUnk_080F2E2C; void sub_0804E6E8(void) { if (!CheckGlobalFlag(OUTDOOR)) { gArea.musicIndex = gArea.pMusicIndex; - SoundReq(0x800b0036); + SoundReq(SONG_VOL_RESET | BGM_MINISH_CAP); } if (!CheckGlobalFlag(START)) { LoadRoomEntityList(&gUnk_080F2E2C); @@ -4734,7 +4731,7 @@ extern EntityData gUnk_080F2EC4; void sub_0804E72C(void) { if (!CheckGlobalFlag(OUTDOOR)) { gArea.musicIndex = gArea.pMusicIndex; - SoundReq(0x800b0036); + SoundReq(SONG_VOL_RESET | BGM_MINISH_CAP); } if (!CheckGlobalFlag(START)) { LoadRoomEntityList(&gUnk_080F2E94); @@ -4774,7 +4771,6 @@ u32 sub_0804E7D8() { } extern EntityData gUnk_080F31D8; -extern u8 gUnk_02000070; extern u32 script_08009B30; void sub_0804E7DC(void) { @@ -4787,7 +4783,7 @@ void sub_0804E7DC(void) { } if (!CheckGlobalFlag(OUTDOOR)) { gArea.musicIndex = gArea.pMusicIndex; - SoundReq(0x800b0036); + SoundReq(SONG_VOL_RESET | BGM_MINISH_CAP); } if ((gPlayerState.flags.all & 8) == 0) { LoadRoomEntityList(&gUnk_080F31D8); @@ -5073,8 +5069,6 @@ void sub_0804EC00(void) { } } -extern EntityData gUnk_080F4E10; - void sub_0804EC98(void) { if ((s32)gSave.windcrests > -1) { LoadRoomEntityList(&gUnk_080F4E10); @@ -5208,8 +5202,6 @@ extern EntityData gUnk_080F5828; extern EntityData gUnk_080F5848; extern EntityData gUnk_080F5788; -extern u8 gBombBagSizes[]; - void sub_0804EEBC(void) { LoadRoomEntityList(&gUnk_080F5758); if (!GetInventoryValue(0x36) && CheckLocalFlagByOffset(0x200, 0x8f)) { @@ -5517,8 +5509,6 @@ void sub_0804F25C(void) { } } -extern EntityData gUnk_080F70D8; - void sub_0804F2C8(void) { if ((gSave.windcrests & 0x40000000) == 0) { LoadRoomEntityList(&gUnk_080F70D8); @@ -6032,8 +6022,6 @@ void sub_0804FBBC(void) { } } -extern EntityData gUnk_080F9304; - void sub_0804FBDC(void) { if ((gSave.windcrests & 0x2000000) == 0) { LoadRoomEntityList(&gUnk_080F9304); @@ -6450,8 +6438,6 @@ void sub_0804FE58(void) { } } -extern EntityData gUnk_080FB004; - void sub_0804FEAC(void) { if ((gSave.windcrests & 0x1000000) == 0) { LoadRoomEntityList(&gUnk_080FB004); diff --git a/src/script.c b/src/script.c index 6e4d577a..0710080c 100644 --- a/src/script.c +++ b/src/script.c @@ -1,12 +1,15 @@ #include "global.h" +#include "audio.h" #include "flags.h" #include "entity.h" #include "area.h" #include "script.h" #include "structures.h" #include "textbox.h" -#include "functions.h" +#include "utils.h" #include "save.h" +#include "random.h" +#include "functions.h" void InitScriptForEntity(Entity*, ScriptExecutionContext*, u16*); void InitScriptExecutionContext(ScriptExecutionContext* context, u16* script); @@ -304,9 +307,9 @@ extern ScriptExecutionContext gPlayerScriptExecutionContext; extern ScriptExecutionContext gScriptExecutionContextArray[0x20]; void InitScriptData(void) { - MemClear32(&gActiveScriptInfo, sizeof(gActiveScriptInfo)); - MemClear32(&gScriptExecutionContextArray, sizeof(gScriptExecutionContextArray)); - MemClear32(&gPlayerScriptExecutionContext, sizeof(gPlayerScriptExecutionContext)); + MemClear(&gActiveScriptInfo, sizeof(gActiveScriptInfo)); + MemClear(&gScriptExecutionContextArray, sizeof(gScriptExecutionContextArray)); + MemClear(&gPlayerScriptExecutionContext, sizeof(gPlayerScriptExecutionContext)); gActiveScriptInfo.unk_08 = 8; } @@ -324,7 +327,7 @@ ScriptExecutionContext* CreateScriptExecutionContext(void) { } void DestroyScriptExecutionContext(ScriptExecutionContext* context) { - MemClear32(context, sizeof(ScriptExecutionContext)); + MemClear(context, sizeof(ScriptExecutionContext)); } ScriptExecutionContext* StartCutscene(Entity* entity, u16* script) { @@ -354,7 +357,7 @@ void UnloadCutsceneData(Entity* entity) { void StartPlayerScript(u16* script) { Entity* player; - MemClear32(&gPlayerScriptExecutionContext, sizeof(gPlayerScriptExecutionContext)); + MemClear(&gPlayerScriptExecutionContext, sizeof(gPlayerScriptExecutionContext)); gPlayerScriptExecutionContext.scriptInstructionPointer = script; player = &gPlayerEntity; *(ScriptExecutionContext**)&player->cutsceneBeh = &gPlayerScriptExecutionContext; @@ -377,7 +380,7 @@ ScriptExecutionContext* StartCutscene2(Entity* entity, u16* script) { } void InitScriptExecutionContext(ScriptExecutionContext* context, u16* script) { - MemClear32(context, sizeof(ScriptExecutionContext)); + MemClear(context, sizeof(ScriptExecutionContext)); context->scriptInstructionPointer = script; } @@ -701,7 +704,7 @@ void ScriptCommand_CallWithArg(Entity* entity, ScriptExecutionContext* context) } void ScriptCommand_LoadRoomEntityList(Entity* entity, ScriptExecutionContext* context) { - LoadRoomEntityList(GetNextScriptCommandWordAfterCommandMetadata(context->scriptInstructionPointer)); + LoadRoomEntityList((EntityData*)GetNextScriptCommandWordAfterCommandMetadata(context->scriptInstructionPointer)); } void ScriptCommand_TestBit(Entity* entity, ScriptExecutionContext* context) { @@ -853,7 +856,7 @@ void ScriptCommand_BuyItem(Entity* entity, ScriptExecutionContext* context) { } void ScriptCommand_0807E48C(Entity* entity, ScriptExecutionContext* context) { - context->condition = sub_080544DC(context->scriptInstructionPointer[1]); + context->condition = GetBottleContaining(context->scriptInstructionPointer[1]); gActiveScriptInfo.flags |= 1; } @@ -1085,7 +1088,7 @@ void ScriptCommand_0807E8E4(Entity* entity, ScriptExecutionContext* context) { void ScriptCommand_0807E908(Entity* entity, ScriptExecutionContext* context) { entity->action = context->scriptInstructionPointer[1]; - entity->previousActionFlag = 0; + entity->subAction = 0; } void ScriptCommand_SetIntVariable(Entity* entity, ScriptExecutionContext* context) { @@ -1464,7 +1467,7 @@ void ScriptCommand_SoundReq3(Entity* entity, ScriptExecutionContext* context) { } void ScriptCommand_SoundReq0x80100000(Entity* entity, ScriptExecutionContext* context) { - SoundReq(0x80100000); + SoundReq(SONG_RESET_UNK); } void ScriptCommand_ModRupees(Entity* entity, ScriptExecutionContext* context) { diff --git a/src/sub_0801D754.c b/src/sub_0801D754.c deleted file mode 100644 index 8b1b2b20..00000000 --- a/src/sub_0801D754.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "global.h" - -extern const u8 gUnk_020176E0[]; - -extern void sub_0807C960(); -extern void LoadPalettes(const u8*, int, int); - -void sub_0807C9D8(u32* a1) { - u32* v1; // r5@1 - - v1 = a1; - sub_0807C960(0x6004000, *a1); - sub_0807C960(0x6000000, v1[1]); - sub_0807C960(0x6008000, v1[2]); - sub_0807C960(gUnk_020176E0, v1[3]); - LoadPalettes(gUnk_020176E0, 2, 13); -} diff --git a/src/sub_0804AFF4.c b/src/sub_0804AFF4.c deleted file mode 100644 index 0d14ee1e..00000000 --- a/src/sub_0804AFF4.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "global.h" - -extern void sub_080186EC(); -extern u32* GetCurrentRoomProperty(u8); -extern u32 _call_via_r0(u32*); -extern void sub_0804B16C(); - -void sub_0804AFF4(void) { - u32* func; - - sub_080186EC(); - func = GetCurrentRoomProperty(5); - if (func != NULL) { - _call_via_r0(func); - } - func = GetCurrentRoomProperty(7); - if (func != NULL) { - _call_via_r0(func); - } - sub_0804B16C(); -} - -/* - thumb_func_start sub_0804AFF4 -sub_0804AFF4: @ 0x0804AFF4 - push {lr} - bl sub_080186EC - movs r0, #5 - bl GetCurrentRoomProperty - cmp r0, #0 - beq _0804B008 - bl _call_via_r0 -_0804B008: - movs r0, #7 - bl GetCurrentRoomProperty - cmp r0, #0 - beq _0804B016 - bl _call_via_r0 -_0804B016: - bl sub_0804B16C - pop {pc} - */ diff --git a/src/sub_08050008.c b/src/sub_08050008.c index 6d8e5103..df79883a 100644 --- a/src/sub_08050008.c +++ b/src/sub_08050008.c @@ -1,14 +1,10 @@ #include "global.h" +#include "utils.h" +#include "structures.h" extern u32 gUnk_020354C0; -extern s32 gFadeControl; -extern void MemClear32(u32, u32, u32); -void sub_08050008(u32 param_1, u32 param_2, u32 param_3) { - s32* unk; - - MemClear32((u32)&gUnk_020354C0, 128, param_3); - - unk = &gFadeControl; - *(unk + 1) = -1; +void sub_08050008() { + MemClear(&gUnk_020354C0, 128); + gFadeControl.field_0x4 = -1; } diff --git a/src/sub_08055E08.c b/src/sub_08055E08.c index 40c1f812..1b97f26f 100644 --- a/src/sub_08055E08.c +++ b/src/sub_08055E08.c @@ -3,7 +3,6 @@ #include "room.h" #include "functions.h" -extern u32* _call_via_r0(u32* func); extern void (*const gUnk_080FF420[])(); extern void sub_0804B0B0(u32, u32); extern void sub_08055B70(u32, u32, u32, u32); diff --git a/src/sub_0805E374.c b/src/sub_0805E374.c index 5767e6da..e035ce07 100644 --- a/src/sub_0805E374.c +++ b/src/sub_0805E374.c @@ -1,10 +1,12 @@ #include "entity.h" +#include "structures.h" + extern Entity* sub_0805E3A0(Entity*, u32); -extern u8 gScreenTransition[]; extern u8 gUnk_081091F8[]; extern u8 gUnk_081091EE[]; + Entity* sub_0805E374(Entity* param_1) { - u8 r3 = gScreenTransition[0x2C]; + u8 r3 = gScreenTransition.field_0x24[8]; u8* array = gUnk_081091F8; if (r3 != '\x02') { diff --git a/src/sub_0806F9EC.c b/src/sub_0806F9EC.c deleted file mode 100644 index 9f029530..00000000 --- a/src/sub_0806F9EC.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "global.h" - -s32 sub_0806F9EC(s16 param_1, s16 param_2) - -{ - int iVar1; - - iVar1 = (s32)param_1 * (s32)param_2; - if (iVar1 < 0) { - iVar1 = iVar1 + 255; - } - return (iVar1 << 8) >> 16; -} diff --git a/src/sub_0806FA04.c b/src/sub_0806FA04.c deleted file mode 100644 index a7eb191a..00000000 --- a/src/sub_0806FA04.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "global.h" - -extern s32 __divsi3(s32, s32); - -s16 sub_0806FA04(s16 param_1, s16 param_2) - -{ - s16 sVar1; - s32 iVar2; - - if (param_2 != 0) { - sVar1 = __divsi3((param_1 << 16) >> 8, param_2); - iVar2 = sVar1; - } else { - iVar2 = 0; - } - return iVar2; -} diff --git a/src/sub_0806FA24.c b/src/sub_0806FA24.c deleted file mode 100644 index de614717..00000000 --- a/src/sub_0806FA24.c +++ /dev/null @@ -1,10 +0,0 @@ - -#include "global.h" -#include "entity.h" -void PositionRelative(Entity*, Entity*, s32, s32); - -void CopyPosition(Entity* param_1, Entity* param_2) - -{ - PositionRelative(param_1, param_2, 0, 0); -} diff --git a/src/sub_0807B7D8.c b/src/sub_0807B7D8.c deleted file mode 100644 index 79892047..00000000 --- a/src/sub_0807B7D8.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "global.h" - -extern void sub_08000152(u32); -extern void sub_0807B778(u32, u32); -extern void SetTileType(u32, u32, u32); - -void sub_0807B7D8(u32 param_1, u32 param_2, u32 param_3) { - if (param_1 == 53) { - sub_08000152(53); - sub_0807B778(param_2, param_3); - sub_0807B778(param_2 + 1, param_3); - sub_0807B778(param_2 + -1, param_3); - sub_0807B778(param_2 + 64, param_3); - sub_0807B778(param_2 + -64, param_3); - } else { - SetTileType(param_1, param_2, param_3); - } -} diff --git a/src/sub_0807B820.c b/src/sub_0807B820.c index 0e8bde35..fabdc8d9 100644 --- a/src/sub_0807B820.c +++ b/src/sub_0807B820.c @@ -1,6 +1,21 @@ #include "global.h" +#include "functions.h" -extern void SetTileType(u32, u32, u32); +extern void sub_08000152(u32); +extern void sub_0807B778(u32, u32); + +void sub_0807B7D8(u32 param_1, u32 param_2, u32 param_3) { + if (param_1 == 53) { + sub_08000152(53); + sub_0807B778(param_2, param_3); + sub_0807B778(param_2 + 1, param_3); + sub_0807B778(param_2 + -1, param_3); + sub_0807B778(param_2 + 64, param_3); + sub_0807B778(param_2 + -64, param_3); + } else { + SetTileType(param_1, param_2, param_3); + } +} void sub_0807B820(u32 param_1) { SetTileType(620, param_1 + -65, 1); @@ -13,3 +28,27 @@ void sub_0807B820(u32 param_1) { SetTileType(624, param_1, 1); SetTileType(626, param_1 + 1, 1); } + +void sub_0807B8A8(u32 param_1) { + SetTileType(636, param_1 + -65, 1); + SetTileType(643, param_1 + -65, 2); + SetTileType(637, param_1 + -64, 1); + SetTileType(644, param_1 + -64, 2); + SetTileType(638, param_1 + -63, 1); + SetTileType(645, param_1 + -63, 2); + SetTileType(639, param_1 + -1, 1); + SetTileType(640, param_1, 1); + SetTileType(642, param_1 + 1, 1); +} + +void sub_0807B930(int param_1) { + SetTileType(652, param_1 + -65, 1); + SetTileType(659, param_1 + -65, 2); + SetTileType(653, param_1 + -64, 1); + SetTileType(660, param_1 + -64, 2); + SetTileType(654, param_1 + -63, 1); + SetTileType(661, param_1 + -63, 2); + SetTileType(655, param_1 + -1, 1); + SetTileType(656, param_1, 1); + SetTileType(658, param_1 + 1, 1); +} diff --git a/src/sub_0807B8A8.c b/src/sub_0807B8A8.c deleted file mode 100644 index c29c35d7..00000000 --- a/src/sub_0807B8A8.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "global.h" - -extern void SetTileType(u32, u32, u32); - -void sub_0807B8A8(u32 param_1) { - SetTileType(636, param_1 + -65, 1); - SetTileType(643, param_1 + -65, 2); - SetTileType(637, param_1 + -64, 1); - SetTileType(644, param_1 + -64, 2); - SetTileType(638, param_1 + -63, 1); - SetTileType(645, param_1 + -63, 2); - SetTileType(639, param_1 + -1, 1); - SetTileType(640, param_1, 1); - SetTileType(642, param_1 + 1, 1); -} diff --git a/src/sub_0807B930.c b/src/sub_0807B930.c deleted file mode 100644 index fe373eff..00000000 --- a/src/sub_0807B930.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "global.h" - -extern void SetTileType(u32, u32, u32); - -void sub_0807B930(int param_1) { - SetTileType(652, param_1 + -65, 1); - SetTileType(659, param_1 + -65, 2); - SetTileType(653, param_1 + -64, 1); - SetTileType(660, param_1 + -64, 2); - SetTileType(654, param_1 + -63, 1); - SetTileType(661, param_1 + -63, 2); - SetTileType(655, param_1 + -1, 1); - SetTileType(656, param_1, 1); - SetTileType(658, param_1 + 1, 1); -} diff --git a/src/sub_0807C998.c b/src/sub_0807C998.c index 7c2afd37..7f3a05c9 100644 --- a/src/sub_0807C998.c +++ b/src/sub_0807C998.c @@ -1,11 +1,14 @@ #include "global.h" -#include "entity.h" extern void sub_0807C960(); +extern void LoadPalettes(const u8*, s32, s32); + extern u16 gMetatilesBottom[]; extern u16 gMetatilesTop[]; extern u8 gUnk_08324AE4; +extern const u8 gUnk_020176E0[]; + void sub_0807C960(void* dest, u32 offset) { void* src; @@ -25,3 +28,14 @@ void sub_0807C998(u32* a1) { sub_0807C960(gMetatilesTop, a1[2]); sub_0807C960(gMetatilesTop - 0x1000, a1[3]); } + +void sub_0807C9D8(u32* a1) { + u32* v1; // r5@1 + + v1 = a1; + sub_0807C960((u8*)0x6004000, *a1); + sub_0807C960((u8*)0x6000000, v1[1]); + sub_0807C960((u8*)0x6008000, v1[2]); + sub_0807C960((u8*)gUnk_020176E0, v1[3]); + LoadPalettes(gUnk_020176E0, 2, 13); +} diff --git a/src/textbox.c b/src/textbox.c index 8e962960..6a9cf031 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -1,6 +1,8 @@ #include "global.h" +#include "audio.h" #include "room.h" #include "entity.h" +#include "utils.h" #include "functions.h" #include "textbox.h" #include "structures.h" @@ -13,11 +15,14 @@ u32 sub_080565B4(void); u32 sub_080565F8(void); u32 sub_08056640(void); -u32 (*const gUnk_08107BC8[])(void) = { sub_080564DC, sub_080564EC, sub_08056654, - sub_080565B4, sub_080565F8, sub_08056640 }; +u32 (*const gUnk_08107BC8[])(void) = { + sub_080564DC, sub_080564EC, sub_08056654, sub_080565B4, sub_080565F8, sub_08056640, +}; extern u8 gUnk_020227DC, gUnk_020227E8, gUnk_020227F0, gUnk_020227F8, gUnk_02022800; -u8* const gUnk_08107BE0[] = { &gUnk_020227DC, &gUnk_020227E8, &gUnk_020227F0, &gUnk_020227F8, &gUnk_02022800 }; +u8* const gUnk_08107BE0[] = { + &gUnk_020227DC, &gUnk_020227E8, &gUnk_020227F0, &gUnk_020227F8, &gUnk_02022800, +}; void sub_08056684(struct_02022780*); void sub_080566B8(struct_02022780*); @@ -26,8 +31,9 @@ void sub_08056B1C(struct_02022780*); void sub_08056B7C(struct_02022780*); void sub_080569D4(struct_02022780*); -void (*const gUnk_08107BF4[])(struct_02022780*) = { sub_08056684, sub_080566B8, sub_08056BA0, - sub_08056B1C, sub_08056B7C, sub_080569D4 }; +void (*const gUnk_08107BF4[])(struct_02022780*) = { + sub_08056684, sub_080566B8, sub_08056BA0, sub_08056B1C, sub_08056B7C, sub_080569D4, +}; extern u32 gUnk_02036A40; extern u32 gUnk_02036A38; @@ -83,7 +89,7 @@ void TextboxAtPosition(u32 index, u32 x, u32 y) { } void ShowTextbox(u32 index) { - MemClear32(&gTextBox, 32); + MemClear(&gTextBox, 32); gTextBox.textIndex = index; gTextBox.textSpeed = 99; gTextBox.textWindowWidth = 26; @@ -94,18 +100,18 @@ void ShowTextbox(u32 index) { } void MessageInitialize(void) { - MemClear32(&gTextBox, 32); - MemClear32(&gUnk_02022780, 168); - MemClear32(&gUnk_02036A40, 8); - MemClear32(&gUnk_02036A38, 8); - MemClear32(&gUnk_02000040, 4); + MemClear(&gTextBox, 32); + MemClear(&gUnk_02022780, 168); + MemClear(&gUnk_02036A40, 8); + MemClear(&gUnk_02036A38, 8); + MemClear(&gUnk_02000040, 4); } void MessageUpdate(void) { int iVar1; if (gTextBox.doTextBox == 1) { - MemClear32((u32*)&gUnk_02022780, sizeof(gUnk_02022780)); + MemClear((u32*)&gUnk_02022780, sizeof(gUnk_02022780)); sub_080564C8(1); } @@ -141,9 +147,9 @@ NONMATCH("asm/non_matching/textbox/sub_080564EC.inc", u32 sub_080564EC(void)) { u32 i; char c; - MemClear32((void*)&gUnk_02036A40, 8); - MemClear32((void*)&gUnk_02024030, 0x18); - MemClear32((void*)&gUnk_02022780, 0xa8); + MemClear((void*)&gUnk_02036A40, 8); + MemClear((void*)&gUnk_02024030, 0x18); + MemClear((void*)&gUnk_02022780, 0xa8); MemCopy(&gTextBox, &gUnk_02022780, 32); if (gUnk_02022780._2 == 0x63) { gUnk_02022780._2 = gUnk_02000000->messageSpeed; @@ -180,7 +186,7 @@ u32 sub_080565B4(void) { gUnk_02022780._89 = 1; gUnk_02022780._99 = 1; sub_08056F88(gUnk_02022780._3[0], gUnk_02022780._53); - SoundReq(0x65); + SoundReq(SFX_TEXTBOX_OPEN); } if (sub_08056CC0(1)) { @@ -195,7 +201,7 @@ u32 sub_080565F8(void) { gUnk_02022780._89 = 1; gUnk_02022780._99 = 3; sub_08056BDC(0); - SoundReq(0x66); + SoundReq(SFX_TEXTBOX_CLOSE); } if (sub_08056CC0(-1)) { diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 00000000..b88fb9cd --- /dev/null +++ b/src/utils.c @@ -0,0 +1,204 @@ +#include "global.h" +#include "utils.h" +#include "structures.h" +#include "screen.h" + +static void StoreKeyInput(Input* input, u32 keyInput); + +typedef struct { + u16 paletteId; + u8 destPaletteNum; + u8 numPalettes; +} PaletteGroup; + +typedef struct { + union { + int raw; + struct { + u8 filler0[0x3]; + u8 unk3; + } bytes; + } unk0; + u32 dest; + u32 unk8; +} GfxItem; + +extern const PaletteGroup* gPaletteGroups[]; +extern const u8 gGlobalGfxAndPalettes[]; +extern u32 gUsedPalettes; +extern u16 gPaletteBuffer[]; +extern const GfxItem* gUnk_08100AA8[]; + +void MemFill16(u32 value, void* dest, u32 size) { + DmaFill16(3, value, dest, size); +} + +void MemFill32(u32 value, void* dest, u32 size) { + DmaFill32(3, value, dest, size); +} + +void MemClear(void* dest, u32 size) { + u32 zero = 0; + + switch (((u32)dest | size) & 3) { + case 0: + MemFill32(0, dest, size); + break; + case 2: + MemFill16(0, dest, size); + break; + default: + do { + *(u8*)dest = zero; + dest++; + size--; + } while (size != 0); + } +} + +void MemCopy(const void* src, void* dest, u32 size) { + switch (((u32)src | (u32)dest | size) & 3) { + case 0: + DmaCopy32(3, src, dest, size); + break; + case 2: + DmaCopy16(3, src, dest, size); + break; + default: + do { + *(u8*)dest = *(u8*)src; + src++; + dest++; + } while (--size); + } +} + +void ReadKeyInput(void) { + u32 keyInput = ~REG_KEYINPUT & KEYS_MASK; + StoreKeyInput(&gInput, keyInput); +} + +static void StoreKeyInput(Input* input, u32 keyInput) { + u32 heldKeys = input->heldKeys; + u32 difference = keyInput & ~heldKeys; + input->newKeys = difference; + if (keyInput == heldKeys) { + if (--input->unk7 == 0) { + input->unk7 = 4; + input->unk4 = keyInput; + } else { + input->unk4 = 0; + } + } else { + input->unk7 = 0x14; + input->unk4 = difference; + } + input->heldKeys = keyInput; +} + +void LoadPaletteGroup(u32 group) { + const PaletteGroup* paletteGroup = gPaletteGroups[group]; + while (1) { + u32 destPaletteNum = paletteGroup->destPaletteNum; + u32 numPalettes = paletteGroup->numPalettes & 0xF; + if (numPalettes == 0) { + numPalettes = 16; + } + LoadPalettes(&gGlobalGfxAndPalettes[paletteGroup->paletteId * 32], destPaletteNum, numPalettes); + if ((paletteGroup->numPalettes & 0x80) == 0) { + break; + } + paletteGroup++; + } +} + +void LoadPalettes(const u8* src, int destPaletteNum, int numPalettes) { + u16* dest; + u32 size = numPalettes * 32; + u32 usedPalettesMask = 1 << destPaletteNum; + while (--numPalettes > 0) { + usedPalettesMask |= (usedPalettesMask << 1); + } + gUsedPalettes |= usedPalettesMask; + dest = &gPaletteBuffer[destPaletteNum * 16]; + DmaCopy32(3, src, dest, size); +} + +void sub_0801D79C(u32 colorIndex, u32 color) { + gPaletteBuffer[colorIndex] = color; + gUsedPalettes |= 1 << (colorIndex / 16); +} + +void sub_0801D7BC(u32 color, u32 arg1) { + if (arg1) { + gScreen.lcd.unk6 = 0xE0FF; + } else { + gScreen.lcd.unk6 = 0xFFFF; + } + sub_0801D79C(0, color); +} + +void LoadGfxGroup(u32 group) { + u32 terminator; + u32 dmaCtrl; + int gfxOffset; + const u8* src; + u32 dest; + int size; + const GfxItem* gfxItem = gUnk_08100AA8[group]; + while (1) { + u32 loadGfx = FALSE; + u32 ctrl = gfxItem->unk0.bytes.unk3; + ctrl &= 0xF; + switch (ctrl) { + case 0x7: + loadGfx = TRUE; + break; + case 0xD: + return; + case 0xE: + if (gUnk_02000000->gameLanguage != 0 && gUnk_02000000->gameLanguage != 1) { + loadGfx = TRUE; + } + break; + case 0xF: + if (gUnk_02000000->gameLanguage != 0) { + loadGfx = TRUE; + } + break; + default: + if (ctrl == gUnk_02000000->gameLanguage) { + loadGfx = TRUE; + } + break; + } + + if (loadGfx) { + gfxOffset = gfxItem->unk0.raw & 0xFFFFFF; + src = &gGlobalGfxAndPalettes[gfxOffset]; + dest = gfxItem->dest; + size = gfxItem->unk8; + dmaCtrl = 0x80000000; + if (size < 0) { + if (dest >= VRAM) { + LZ77UnCompVram(src, (void*)dest); + } else { + LZ77UnCompWram(src, (void*)dest); + } + } else { + DmaSet(3, src, dest, dmaCtrl | ((u32)size >> 1)); + } + } + + terminator = gfxItem->unk0.bytes.unk3; + terminator &= 0x80; + gfxItem++; + if (!terminator) { + break; + } + } +} + +/* TODO: + clear OAM, zMalloc, etc. +*/ |
