diff --git a/asm/macros/scripts.inc b/asm/macros/scripts.inc index eabc99cbb..7d0ba66a1 100644 --- a/asm/macros/scripts.inc +++ b/asm/macros/scripts.inc @@ -462,7 +462,7 @@ .2byte \s .endm -.macro _0807E9F0 +.macro UpdateFusion .2byte 0x0456 .endm diff --git a/data/scripts/castorWilds/script_CastorWildsStatueLeft.inc b/data/scripts/castorWilds/script_CastorWildsStatueLeft.inc index 874dff2a6..1439e7fe5 100644 --- a/data/scripts/castorWilds/script_CastorWildsStatueLeft.inc +++ b/data/scripts/castorWilds/script_CastorWildsStatueLeft.inc @@ -8,7 +8,7 @@ SCRIPT_START script_CastorWildsStatueLeft EndBlock script_0800B268: _0807EA4C - _0807E9F0 + UpdateFusion SetPlayerIdle CheckKinstoneFused KINSTONE_CASTOR_WILDS_STATUE_LEFT JumpIf script_0800B2E2 diff --git a/data/scripts/castorWilds/script_CastorWildsStatueMiddle.inc b/data/scripts/castorWilds/script_CastorWildsStatueMiddle.inc index 7abd69e1c..4541edf92 100644 --- a/data/scripts/castorWilds/script_CastorWildsStatueMiddle.inc +++ b/data/scripts/castorWilds/script_CastorWildsStatueMiddle.inc @@ -8,7 +8,7 @@ SCRIPT_START script_CastorWildsStatueMiddle EndBlock script_0800B298: _0807EA4C - _0807E9F0 + UpdateFusion SetPlayerIdle CheckKinstoneFused KINSTONE_CASTOR_WILDS_STATUE_MIDDLE JumpIf script_0800B2E2 diff --git a/data/scripts/castorWilds/script_CastorWildsStatueRight.inc b/data/scripts/castorWilds/script_CastorWildsStatueRight.inc index c4549d85e..8beacfa73 100644 --- a/data/scripts/castorWilds/script_CastorWildsStatueRight.inc +++ b/data/scripts/castorWilds/script_CastorWildsStatueRight.inc @@ -8,7 +8,7 @@ SCRIPT_START script_CastorWildsStatueRight EndBlock script_0800B2C8: _0807EA4C - _0807E9F0 + UpdateFusion SetPlayerIdle CheckKinstoneFused KINSTONE_CASTOR_WILDS_STATUE_RIGHT JumpIf script_0800B2E2 diff --git a/data/scripts/cloudTops/script_Npc4EFirstCloud.inc b/data/scripts/cloudTops/script_Npc4EFirstCloud.inc index 76d025fa1..3ed822d77 100644 --- a/data/scripts/cloudTops/script_Npc4EFirstCloud.inc +++ b/data/scripts/cloudTops/script_Npc4EFirstCloud.inc @@ -12,7 +12,7 @@ SCRIPT_START script_Npc4EFirstCloud EndBlock script_0800D636: _0807EA4C - _0807E9F0 + UpdateFusion Call NPC4E_IsKinstoneFused JumpIf script_0800D650 Call EnablePauseMenu diff --git a/data/scripts/lonLonRanch/script_GoronPunching.inc b/data/scripts/lonLonRanch/script_GoronPunching.inc index 992ee9ebc..d38d47cd6 100644 --- a/data/scripts/lonLonRanch/script_GoronPunching.inc +++ b/data/scripts/lonLonRanch/script_GoronPunching.inc @@ -23,7 +23,7 @@ script_0800B9F4: FacePlayer DoPostScriptAction 0x0000 Call sub_0807F650 - _0807E9F0 + UpdateFusion SetPlayerIdle Call sub_0806948C JumpIf script_0800BA24 diff --git a/data/scripts/npc/script_Farmer.inc b/data/scripts/npc/script_Farmer.inc index 11f0566f3..d59dad994 100644 --- a/data/scripts/npc/script_Farmer.inc +++ b/data/scripts/npc/script_Farmer.inc @@ -28,7 +28,7 @@ script_0800B134: FacePlayer CallWithArg sub_0806BC94, 0x00000004 Call sub_0807F650 - _0807E9F0 + UpdateFusion .ifndef EU @! @bug: In EU, Eenie is marked as done fusing if kinstone menu is closed without fusing JumpIfNot script_0800B160 diff --git a/data/scripts/npc/script_MysteriousWall.inc b/data/scripts/npc/script_MysteriousWall.inc index 28ab2c5e1..8d10f21db 100644 --- a/data/scripts/npc/script_MysteriousWall.inc +++ b/data/scripts/npc/script_MysteriousWall.inc @@ -10,7 +10,7 @@ SCRIPT_START script_MysteriousWall EndBlock script_0800B98A: _0807EA4C - _0807E9F0 + UpdateFusion JumpIf script_0800B99E Call EnablePauseMenu EnablePlayerControl diff --git a/data/scripts/veilFalls/script_NPC4ESourceOfTheFlow.inc b/data/scripts/veilFalls/script_NPC4ESourceOfTheFlow.inc index 0c4a11a3f..b176121d5 100644 --- a/data/scripts/veilFalls/script_NPC4ESourceOfTheFlow.inc +++ b/data/scripts/veilFalls/script_NPC4ESourceOfTheFlow.inc @@ -10,7 +10,7 @@ SCRIPT_START script_NPC4ESourceOfTheFlow EndBlock script_08015FE4: _0807EA4C - _0807E9F0 + UpdateFusion SetPlayerIdle CheckKinstoneFused KINSTONE_SOURCE_FLOW JumpIf script_08015FFE diff --git a/include/common.h b/include/common.h index 011e5a8a9..871e5f057 100644 --- a/include/common.h +++ b/include/common.h @@ -120,8 +120,8 @@ void sub_0801E1EC(u32, u32, u32); void sub_0801DD58(u32, u32); void sub_0801E1B8(u32, u32); void AddKinstoneToBag(u32); -void sub_0801DFB4(struct Entity_*, u32, u32, u32); -u32 sub_0801E00C(void); +void InitializeFuseInfo(struct Entity_* entity, u32 textIndex, u32 cancelledTextIndex, u32 fusingTextIndex); +u32 PerformFuseAction(void); bool32 CheckFusionMapMarkerDisabled(u32); u32 sub_0801DB94(void); u32 GetRandomSharedFusion(u8*); diff --git a/include/functions.h b/include/functions.h index 0e7b79f88..a770563be 100644 --- a/include/functions.h +++ b/include/functions.h @@ -98,7 +98,6 @@ extern void sub_0805EC60(Entity*); extern void InitPlayerMacro(PlayerMacroEntry*); extern u32* sub_0805F25C(u32); extern void sub_0805F8E4(u32 r0, WStruct* r1); -extern void sub_08060158(Entity*); extern void sub_0806D0B0(Entity*); extern bool32 sub_080806BC(u32, u32, u32, u32); extern void sub_0808091C(const ScreenTransitionData* screenTransition, u32 transitionType); diff --git a/include/kinstone.h b/include/kinstone.h index ac6b9b83e..c5b638744 100644 --- a/include/kinstone.h +++ b/include/kinstone.h @@ -6,17 +6,27 @@ extern void sub_08018C58(u32); +typedef enum { + FUSION_STATE_0, // fusion was not yet started + FUSION_STATE_1, // failed? + FUSION_STATE_2, // successful? + FUSION_STATE_3, // fusion is being performed + FUSION_STATE_4, // player has closed the first messagebox + FUSION_STATE_5, // fusion declined by the player + FUSION_STATE_6, // Successful, but not yet finished? +} FusionState; + typedef struct { - u8 _0; + u8 fusionState; /** @see FusionState */ u8 action; u8 _2; u8 kinstoneId; u8 prevUpdatePriority; u8 _5; u16 textIndex; - u16 _8; - u16 _a; - Entity* ent; + u16 cancelledTextIndex; + u16 fusingTextIndex; + Entity* entity; } FuseInfo; static_assert(sizeof(FuseInfo) == 0x10); extern FuseInfo gFuseInfo; diff --git a/include/npc.h b/include/npc.h index 6b9e5cb54..525cc5d12 100644 --- a/include/npc.h +++ b/include/npc.h @@ -73,7 +73,7 @@ s32 GetFacingDirectionInRectRadius(Entity* ent, u32 x, u32 y); void sub_0806EE04(Entity* ent, void* a2, u32 a3); u32 sub_0806EE20(Entity* ent); s32 sub_0806F078(Entity* ent, s32 a2); -void sub_0806F118(Entity* ent); +void InitializeNPCFusion(Entity* ent); void MarkFuserDone(Entity* ent); void ShowNPCDialogue(Entity* ent, const Dialog* dia); @@ -85,7 +85,6 @@ void CollideFollowers(void); // TODO move? void AddInteractableWhenBigFuser(Entity* ent, u32 kinstoneId); -u32 sub_0806F5A4(u32); u32 GetFusionToOffer(Entity*); void AddInteractableWhenBigObject(Entity*); void sub_0807000C(Entity*); @@ -222,23 +221,23 @@ enum NPC { /*0x7f*/ NPC_NONE_39, }; -void Gentari(Entity*); +void Gentari(); void Gentari_Fusion(Entity*); -void Festari(Entity*); -void Festari_Fusion(Entity*); -void ForestMinish(Entity*); +void Festari(); +void Festari_Fusion(); +void ForestMinish(); void ForestMinish_Head(Entity*); void ForestMinish_Fusion(Entity*); -void Postman(Entity*); +void Postman(); void Postman_Fusion(Entity*); -void NPC5(Entity*); +void NPC5(); void Townsperson(Entity*); void Townsperson_Head(Entity*); void Townsperson_Fusion(Entity*); -void Kid(Entity*); +void Kid(); void Kid_Head(Entity*); void Kid_Fusion(Entity*); -void Guard(Entity*); +void Guard(); void Guard_Head(Entity*); void NPC9(Entity*); void Stamp(Entity*); @@ -246,90 +245,90 @@ void Maid(Entity*); void Maid_Head(Entity*); void Marcy(Entity*); void Wheaton(Entity*); -void Pita(Entity*); +void Pita(); void MinishEzlo(Entity*); void MinishEzlo_Head(Entity*); void Mailbox(Entity*); void Beedle(Entity*); void Beedle_Head(Entity*); -void Brocco(Entity*); +void Brocco(); void Brocco_Fusion(Entity*); -void SittingPerson(Entity*); +void SittingPerson(); void SittingPerson_Head(Entity*); void SittingPerson_Fusion(Entity*); -void Pina(Entity*); +void Pina(); void Pina_Fusion(Entity*); -void Din(Entity*); +void Din(); void Din_Fusion(Entity*); -void Nayru(Entity*); +void Nayru(); void Nayru_Fusion(Entity*); -void Farore(Entity*); +void Farore(); void Farore_Fusion(Entity*); -void Sturgeon(Entity*); +void Sturgeon(); void Sturgeon_Head(Entity*); void Sturgeon_Fusion(Entity*); void TingleSiblings(Entity*); void TingleSiblings_Fusion(Entity*); -void Stockwell(Entity*); -void Talon(Entity*); +void Stockwell(); +void Talon(); void Talon_Head(Entity*); void Talon_Fusion(Entity*); -void Malon(Entity*); +void Malon(); void Malon_Fusion(Entity*); -void Epona(Entity*); -void Epona_Fusion(Entity*); +void Epona(); +void Epona_Fusion(); void MilkCart(Entity*); -void GhostBrothers(Entity*); +void GhostBrothers(); void GhostBrothers_Fusion(Entity*); -void Smith(Entity*); +void Smith(); void Smith_Head(Entity*); void Smith_Fusion(Entity*); -void NPC23(Entity*); -void KingDaltus(Entity*); +void NPC23(); +void KingDaltus(); void KingDaltus_Fusion(Entity*); -void MinisterPotho(Entity*); +void MinisterPotho(); void MinisterPotho_Fusion(Entity*); void NPC26(Entity*); void Vaati(Entity*); void Zelda(Entity*); -void Mutoh(Entity*); +void Mutoh(); void Mutoh_Head(Entity*); void Mutoh_Fusion(Entity*); -void Carpenter(Entity*); +void Carpenter(); void Carpenter_Head(Entity*); void Carpenter_Fusion(Entity*); -void CastorWildsStatue(Entity*); +void CastorWildsStatue(); void CastorWildsStatue_Fusion(Entity*); -void Cat(Entity*); +void Cat(); void Cat_Fusion(Entity*); -void MountainMinish(Entity*); +void MountainMinish(); void MountainMinish_Head(Entity*); void MountainMinish_Fusion(Entity*); void ZeldaFollower(Entity*); void Melari(Entity*); void Melari_Head(Entity*); void Melari_Fusion(Entity*); -void BladeBrothers(Entity*); +void BladeBrothers(); void BladeBrothers_Fusion(Entity*); -void Cow(Entity*); -void Cow_Fusion(Entity*); -void Goron(Entity*); +void Cow(); +void Cow_Fusion(); +void Goron(); void Goron_Fusion(Entity*); void GoronMerchant(Entity*); -void Gorman(Entity*); +void Gorman(); void Gorman_Head(Entity*); -void Dog(Entity*); -void Dog_Head(Entity*); -void Dog_Fusion(Entity*); -void Syrup(Entity*); +void Dog(); +void Dog_Head(); +void Dog_Fusion(); +void Syrup(); void Syrup_Head(Entity*); -void Rem(Entity*); -void TownMinish(Entity*); -void TownMinish_Head(Entity*); +void Rem(); +void TownMinish(); +void TownMinish_Head(); void TownMinish_Fusion(Entity*); -void Librari(Entity*); +void Librari(); void Librari_Fusion(Entity*); -void Percy(Entity*); +void Percy(); void Percy_Head(Entity*); void Percy_Fusion(Entity*); void VaatiReborn(Entity*); @@ -343,26 +342,26 @@ void Dampe(Entity*); void Dampe_Fusion(Entity*); void DrLeft(Entity*); void KingGustaf(Entity*); -void Gina(Entity*); +void Gina(); void Gina_Fusion(Entity*); void Simon(Entity*); -void Anju(Entity*); -void Anju_Fusion(Entity*); -void Mama(Entity*); +void Anju(); +void Anju_Fusion(); +void Mama(); void Mama_Head(Entity*); void Mama_Fusion(Entity*); void Emma(Entity*); -void Teachers(Entity*); +void Teachers(); void Teachers_Head(Entity*); void Teachers_Fusion(Entity*); void WindTribespeople(Entity*); void WindTribespeople_Head(Entity*); void WindTribespeople_Fusion(Entity*); -void Gregal(Entity*); +void Gregal(); void Gregal_Fusion(Entity*); -void MayorHagen(Entity*); +void MayorHagen(); void MayorHagen_Fusion(Entity*); -void BigGoron(Entity*); +void BigGoron(); void Ezlo(Entity*); void NPC4E(Entity*); void NPC4E_Fusion(Entity*); @@ -370,18 +369,18 @@ void NPC4F(Entity*); void ClothesRack(Entity*); void PicolyteBottle(Entity*); void SmallTownMinish(Entity*); -void HurdyGurdyMan(Entity*); +void HurdyGurdyMan(); void HurdyGurdyMan_Head(Entity*); void HurdyGurdyMan_Fusion(Entity*); -void Cucco(Entity*); +void Cucco(); void Cucco_Fusion(Entity*); -void CuccoChick(Entity*); -void CuccoChick_Fusion(Entity*); +void CuccoChick(); +void CuccoChick_Fusion(); void FusionMenuNPC(Entity*); void FusionMenuNPC_Head(Entity*); void Phonograph(Entity*); -void NPC58(Entity*); -void NPC58_Head(Entity*); +void NPC58(); +void NPC58_Head(); extern void (*const gNPCFunctions[128][3])(Entity*); diff --git a/include/npc/zelda.h b/include/npc/zelda.h new file mode 100644 index 000000000..715795866 --- /dev/null +++ b/include/npc/zelda.h @@ -0,0 +1,20 @@ +#ifndef ZELDA_H +#define ZELDA_H + +#include "entity.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unused[24]; + /*0x80*/ u16 unk_80; +} ZeldaEntity; + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ s8 unk_68; + /*0x69*/ s8 unk_69; + /*0x6a*/ u8 unused[10]; + /*0x74*/ u16 unk_74; +} ZeldaFollowerEntity; + +#endif // ZELDA_H diff --git a/include/physics.h b/include/physics.h index 9afd0f9e0..36b6e594d 100644 --- a/include/physics.h +++ b/include/physics.h @@ -25,7 +25,6 @@ bool32 EntityWithinDistance(Entity*, s32, s32, s32); u32 sub_0806FCA0(Entity*, Entity*); u32 sub_0806F58C(Entity*, Entity*); u32 PointInsideRadius(s32 x, s32 y, s32 radius); -u32 sub_0806F5A4(u32 idx); bool32 sub_0806F3E4(Entity*); void LinearMoveUpdate(Entity*); bool32 sub_0806FD54(Entity*); @@ -35,7 +34,10 @@ u32 sub_0806F730(Entity*); bool32 sub_0806F520(Entity*); void sub_0806F4E8(Entity*); bool32 sub_0806FC80(Entity*, Entity*, s32); -u32 sub_0806F5B0(u32); +/** Maps the direction to an animation state 0 to 3. */ +u32 GetAnimationStateForDirection4(u32 direction); +/** Maps the direction to an animation state 0 to 8. */ +u32 GetAnimationStateForDirection8(u32 direction); u32 sub_0806F824(Entity*, Entity*, s32, s32); u32 sub_0806F948(Entity*); void sub_0806FBB4(Entity*); diff --git a/include/script.h b/include/script.h index c6e41f174..4fbb2eef4 100644 --- a/include/script.h +++ b/include/script.h @@ -51,7 +51,7 @@ extern u32 GetNextScriptCommandHalfwordAfterCommandMetadata(u16*); void UnloadCutsceneData(Entity* entity); void StartPlayerScript(Script* script); -void sub_0807DD50(Entity* entity); +void InitScriptForNPC(Entity* entity); void sub_0807DD64(Entity* entity); void sub_0807DD80(Entity* entity, Script* script); void sub_0807DEDC(Entity*, ScriptExecutionContext*, u32, u32); @@ -60,7 +60,7 @@ ScriptExecutionContext* StartCutscene(Entity* entity, Script* script); void ExecuteScriptForEntity(Entity* entity, void (*postScriptCallback)(Entity*, ScriptExecutionContext*)); void HandlePostScriptActions(Entity* entity, ScriptExecutionContext* context); void HandleEntity0x82Actions(Entity* entity); -void sub_0807DD94(Entity*, void (*function)(Entity*, ScriptExecutionContext*)); +void ExecuteScriptAndHandleAnimation(Entity* entity, void (*postScriptCallback)(Entity*, ScriptExecutionContext*)); ScriptExecutionContext* CreateScriptExecutionContext(void); void InitScriptForEntity(Entity* entity, ScriptExecutionContext* context, Script* script); diff --git a/src/common.c b/src/common.c index 1aa305df9..3b661be72 100644 --- a/src/common.c +++ b/src/common.c @@ -28,7 +28,7 @@ extern u8 gzHeap[0x1000]; extern u32 gUnk_0201AEE0[0x800]; extern s16 gUnk_02018EE0[]; -extern void (*const gUnk_080C9CAC[])(void); +extern void (*const gFuseActions[])(void); static void StoreKeyInput(Input* input, u32 keyInput); void ClearOAM(void); @@ -619,69 +619,71 @@ bool32 IsRoomVisited(TileEntity* tileEntity, u32 bank) { return FALSE; } -void sub_0801DFB4(Entity* entity, u32 textIndex, u32 a3, u32 a4) { +void InitializeFuseInfo(Entity* entity, u32 textIndex, u32 cancelledTextIndex, u32 fusingTextIndex) { MemClear(&gFuseInfo, sizeof(gFuseInfo)); gFuseInfo.textIndex = textIndex; - gFuseInfo._8 = a3; - gFuseInfo._a = a4; - gFuseInfo.ent = entity; + gFuseInfo.cancelledTextIndex = cancelledTextIndex; + gFuseInfo.fusingTextIndex = fusingTextIndex; + gFuseInfo.entity = entity; gFuseInfo.kinstoneId = gPossibleInteraction.kinstoneId; if (entity != NULL) { gFuseInfo.prevUpdatePriority = entity->updatePriority; entity->updatePriority = 2; } - gFuseInfo._0 = 0; + gFuseInfo.fusionState = FUSION_STATE_0; } -u32 sub_0801E00C(void) { - gUnk_080C9CAC[gFuseInfo.action](); - return gFuseInfo._0; +// returns the fusion state +u32 PerformFuseAction(void) { + gFuseActions[gFuseInfo.action](); + return gFuseInfo.fusionState; } -void sub_0801E02C(void) { +void Fuse_Action0(void) { MessageFromFusionTarget(gFuseInfo.textIndex); - gFuseInfo._0 = 3; + gFuseInfo.fusionState = FUSION_STATE_3; gFuseInfo.action = 1; } -void sub_0801E044(void) { +void Fuse_Action1(void) { if ((gMessage.doTextBox & 0x7F) == 0) { MenuFadeIn(4, 0); - gFuseInfo._0 = 4; + gFuseInfo.fusionState = FUSION_STATE_4; gFuseInfo.action = 2; SoundReq(SFX_6B); } } -void sub_0801E074(void) { - u32 tmp; - switch (gFuseInfo._0) { - case 5: - tmp = gFuseInfo._8; +// Waits until FUSION_STATE_5 or FUSION_STATE_6 is reached and displays the corresponding message. +void Fuse_Action2(void) { + u32 textIndex; + switch (gFuseInfo.fusionState) { + case FUSION_STATE_5: + textIndex = gFuseInfo.cancelledTextIndex; break; - case 6: - tmp = gFuseInfo._a; + case FUSION_STATE_6: + textIndex = gFuseInfo.fusingTextIndex; break; default: return; } - MessageFromFusionTarget(tmp); + MessageFromFusionTarget(textIndex); gFuseInfo.action = 3; } -void sub_0801E0A0(void) { +void Fuse_Action3(void) { if ((gMessage.doTextBox & 0x7f) == 0) { - if (gFuseInfo.ent != NULL) { - gFuseInfo.ent->updatePriority = gFuseInfo.prevUpdatePriority; + if (gFuseInfo.entity != NULL) { + gFuseInfo.entity->updatePriority = gFuseInfo.prevUpdatePriority; } - gFuseInfo._0 = gFuseInfo._0 == 6 ? 2 : 1; + gFuseInfo.fusionState = gFuseInfo.fusionState == FUSION_STATE_6 ? FUSION_STATE_2 : FUSION_STATE_1; } } void MessageFromFusionTarget(u32 textIndex) { if (textIndex != 0) { - if (gFuseInfo.ent != NULL) { - MessageNoOverlap(textIndex, gFuseInfo.ent); + if (gFuseInfo.entity != NULL) { + MessageNoOverlap(textIndex, gFuseInfo.entity); } else { MessageFromTarget(textIndex); } @@ -841,7 +843,7 @@ void NotifyFusersOnFusionDone(KinstoneId kinstoneId) { gSave.fuserOffers[index] = KINSTONE_NEEDS_REPLACEMENT; } } - tmp = GetFuserId(gFuseInfo.ent); + tmp = GetFuserId(gFuseInfo.entity); if ((tmp - 1 < 0x7f) && (gSave.fuserOffers[tmp] == KINSTONE_NEEDS_REPLACEMENT)) { gSave.fuserOffers[tmp] = KINSTONE_JUST_FUSED; } @@ -1118,11 +1120,11 @@ const struct_080C9C6C gUnk_080C9C6C[] = { { 1, 3, 3 }, { 1, 3, 3 }, { 1, 3, 3 }, { 1, 3, 3 }, { 1, 3, 3 }, { 1, 3, 3 }, { 1, 3, 3 }, { 1, 3, 3 }, }; -void (*const gUnk_080C9CAC[])(void) = { - sub_0801E02C, - sub_0801E044, - sub_0801E074, - sub_0801E0A0, +void (*const gFuseActions[])(void) = { + Fuse_Action0, + Fuse_Action1, + Fuse_Action2, + Fuse_Action3, }; // TODO merge diff --git a/src/enemy/businessScrub.c b/src/enemy/businessScrub.c index 823a87403..704674018 100644 --- a/src/enemy/businessScrub.c +++ b/src/enemy/businessScrub.c @@ -361,7 +361,7 @@ void sub_08028F0C(Entity* this) { if (this->interactType == 2) { this->action = 8; this->interactType = 0; - sub_0806F118(this); + InitializeNPCFusion(this); } else if (this->interactType != 0) { u16 dialog; const struct SalesOffering* offer = (const struct SalesOffering*)this->field_0x7c.WORD; diff --git a/src/enemy/businessScrubPrologue.c b/src/enemy/businessScrubPrologue.c index ba7349e96..aeaa5f6fe 100644 --- a/src/enemy/businessScrubPrologue.c +++ b/src/enemy/businessScrubPrologue.c @@ -75,7 +75,7 @@ void sub_08045C3C(BusinessScrubPrologueEntity* this) { sub_08046030(this, 0); sub_08095C48(super); StartCutscene(super, script_BusinessScrubIntro); - sub_0807DD50(super); + InitScriptForNPC(super); } void sub_08045CA4(BusinessScrubPrologueEntity* this) { @@ -200,7 +200,7 @@ void sub_08045E14(BusinessScrubPrologueEntity* this) { } void sub_08045EC8(BusinessScrubPrologueEntity* this) { - sub_0807DD94(super, 0); + ExecuteScriptAndHandleAnimation(super, NULL); } void sub_08045ED4(BusinessScrubPrologueEntity* this) { diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index c1a569a38..b04a0d247 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -1128,7 +1128,7 @@ void sub_0802E300(GleerokEntity* this) { this->unk_79 &= ~0x80; heap = this->unk_84; - dir = sub_0806F5A4(GetFacingDirection(super, &gPlayerEntity)) << 3; + dir = GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) << 3; index = 0; ptr2 = &this->unk_80; tmp = 0; diff --git a/src/menu/kinstoneMenu.c b/src/menu/kinstoneMenu.c index 77b558180..53cf6655f 100644 --- a/src/menu/kinstoneMenu.c +++ b/src/menu/kinstoneMenu.c @@ -229,7 +229,7 @@ void KinstoneMenu_Type1(void) { void KinstoneMenu_Type2(void) { const KinstoneWorldEvent* ptr; if (gMenu.column_idx == 6) { - gFuseInfo._0 = 6; + gFuseInfo.fusionState = FUSION_STATE_6; ptr = &gKinstoneWorldEvents[gFuseInfo.kinstoneId]; if (ptr->subtask != 0) { MenuFadeIn(ptr->subtask, ptr->worldEventId); @@ -237,7 +237,7 @@ void KinstoneMenu_Type2(void) { Subtask_Exit(); } } else { - gFuseInfo._0 = 5; + gFuseInfo.fusionState = FUSION_STATE_5; Subtask_Exit(); } } @@ -625,9 +625,9 @@ u32 KinstoneMenu_080A4494(void) { psVar1->unk1 = 0; sub_080A44E0(psVar1, gSave.name, 0x80); #if NON_MATCHING - ret = sub_080A44E0(psVar1, GetFuserId(gFuseInfo.ent) >> 0x20, 0xa0); + ret = sub_080A44E0(psVar1, GetFuserId(gFuseInfo.entity) >> 0x20, 0xa0); #else - GetFuserId(gFuseInfo.ent); + GetFuserId(gFuseInfo.entity); asm("" : "=r"(r1)); ret = sub_080A44E0(psVar1, r1, 0xa0); #endif @@ -652,13 +652,13 @@ u32 sub_080A44E0(WStruct* param_1, u8* param_2, u32 param_3) { void KinstoneMenu_080A4528(void) { Entity* entity; - if (gFuseInfo.ent->kind == NPC) { - entity = CreateNPC(gFuseInfo.ent->id, gFuseInfo.ent->type, gFuseInfo.ent->type2); + if (gFuseInfo.entity->kind == NPC) { + entity = CreateNPC(gFuseInfo.entity->id, gFuseInfo.entity->type, gFuseInfo.entity->type2); } else { - if (gFuseInfo.ent->kind != ENEMY) { + if (gFuseInfo.entity->kind != ENEMY) { return; } - entity = CreateEnemy(gFuseInfo.ent->id, gFuseInfo.ent->type); + entity = CreateEnemy(gFuseInfo.entity->id, gFuseInfo.entity->type); } if (entity != NULL) { if (entity->kind == NPC) { diff --git a/src/npc/anju.c b/src/npc/anju.c index fa66f5375..721b7f44a 100644 --- a/src/npc/anju.c +++ b/src/npc/anju.c @@ -1,44 +1,56 @@ +/** + * @file anju.c + * @ingroup NPCs + * + * @brief Anju NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" #include "npc.h" +#include "player.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} AnjuEntity; -void Anju(Entity* this) { - switch (this->action) { +void Anju(AnjuEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - this->animationState = this->timer; - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = 1; + super->animationState = super->timer; + InitScriptForNPC(super); return; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitializeAnimation(this, - (this->animIndex & -4) + sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitializeAnimation(super, (super->animIndex & -4) + GetAnimationStateForDirection4( + GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(super, NULL); } return; case 2: - if (UpdateFuseInteraction(this)) { - this->action = 1; + if (UpdateFuseInteraction(super)) { + super->action = 1; } } } -void Anju_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Anju_MakeInteractable(AnjuEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } -void Anju_Fusion(Entity* this) { - if (this->action == 0) { - this->action++; - this->spriteSettings.draw = 1; - InitAnimationForceUpdate(this, 6); +void Anju_Fusion(AnjuEntity* this) { + if (super->action == 0) { + super->action++; + super->spriteSettings.draw = 1; + InitAnimationForceUpdate(super, 6); } else { - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } } diff --git a/src/npc/beedle.c b/src/npc/beedle.c index 16ed2ec23..4ab2e5212 100644 --- a/src/npc/beedle.c +++ b/src/npc/beedle.c @@ -1,12 +1,18 @@ -#include "global.h" +/** + * @file beedle.c + * @ingroup NPCs + * + * @brief Beedle NPC + */ +#define NENT_DEPRECATED #include "entity.h" +#include "functions.h" +#include "game.h" +#include "item.h" #include "message.h" +#include "npc.h" #include "room.h" #include "script.h" -#include "npc.h" -#include "game.h" -#include "functions.h" -#include "item.h" typedef struct { Rect customHitbox; @@ -14,10 +20,10 @@ typedef struct { u8 unused[3]; } InteractCollisionData; -void sub_080632E0(Entity* this); -void sub_08063314(Entity* this); -void sub_0806336C(Entity* this); -void sub_08063390(Entity* this); +void Beedle_Init(Entity* this); +void Beedle_Action1(Entity* this); +void Beedle_Action2(Entity* this); +void Beedle_Action3(Entity* this); static const u8 gBeedleItems[] = { ITEM_NONE, @@ -41,30 +47,30 @@ static const SpriteLoadData gUnk_0810C8D4[] = { { 0, 0, 0 }, }; -void sub_080632C8(Entity* this); +void Beedle_Update(Entity* this); void sub_08063410(Entity* this); -s32 sub_080633C8(Entity* this); +s32 Beedle_GetAnimIndexFacingPlayer(Entity* this); void sub_0806346C(Entity* this); void Beedle(Entity* this) { if (this->flags & ENT_SCRIPTED) { sub_08063410(this); } else { - sub_080632C8(this); + Beedle_Update(this); } } -void sub_080632C8(Entity* this) { - static void (*const gUnk_0810C8E0[])(Entity*) = { - sub_080632E0, - sub_08063314, - sub_0806336C, - sub_08063390, +void Beedle_Update(Entity* this) { + static void (*const beedleActions[])(Entity*) = { + Beedle_Init, + Beedle_Action1, + Beedle_Action2, + Beedle_Action3, }; - gUnk_0810C8E0[this->action](this); + beedleActions[this->action](this); } -void sub_080632E0(Entity* this) { +void Beedle_Init(Entity* this) { if (LoadExtraSpriteData(this, gUnk_0810C8D4)) { InitializeAnimation(this, 0); AddInteractableWhenBigObject(this); @@ -73,11 +79,12 @@ void sub_080632E0(Entity* this) { } } -void sub_08063314(Entity* this) { - u32 offset; +void Beedle_Action1(Entity* this) { + u32 animIndex; - if (((++this->subtimer & 0xF) == 0) && (offset = sub_080633C8(this), this->animIndex != offset)) { - InitializeAnimation(this, offset); + if (((++this->subtimer & 0xF) == 0) && + (animIndex = Beedle_GetAnimIndexFacingPlayer(this), this->animIndex != animIndex)) { + InitializeAnimation(this, animIndex); } if (this->interactType != 0) { MessageFromTarget(this->timer + TEXT_INDEX(TEXT_EMPTY, 0x01)); @@ -86,14 +93,14 @@ void sub_08063314(Entity* this) { sub_0806ED78(this); } -void sub_0806336C(Entity* this) { +void Beedle_Action2(Entity* this) { if ((gMessage.doTextBox & 0x7F) == 0) { this->action++; InitializeAnimation(this, 8); } } -void sub_08063390(Entity* this) { +void Beedle_Action3(Entity* this) { GetNextFrame(this); if (this->frame & ANIM_DONE) { this->action = 1; @@ -103,14 +110,13 @@ void sub_08063390(Entity* this) { sub_0806ED78(this); } -s32 sub_080633C8(Entity* this) { - s32 uVar1; - - uVar1 = GetAnimationStateInRectRadius(this, 0x20, 0x20); - if (uVar1 < 0) { - uVar1 = this->animIndex; +// If the player is inside a 32x32 rect, face the player. Otherwise keep facing the same direction. +s32 Beedle_GetAnimIndexFacingPlayer(Entity* this) { + s32 animationState = GetAnimationStateInRectRadius(this, 32, 32); + if (animationState < 0) { + animationState = this->animIndex; } - return uVar1; + return animationState; } void Beedle_Head(Entity* this) { diff --git a/src/npc/bigGoron.c b/src/npc/bigGoron.c index 1497f185a..2e3c3c114 100644 --- a/src/npc/bigGoron.c +++ b/src/npc/bigGoron.c @@ -1,8 +1,20 @@ -#include "npc.h" +/** + * @file bigGoron.c + * @ingroup NPCs + * + * @brief BigGoron NPC + */ +#define NENT_DEPRECATED #include "functions.h" -#include "screen.h" #include "hitbox.h" #include "item.h" +#include "npc.h" +#include "screen.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u16 originalX; +} BigGoronEntity; static const u16 goronSounds[] = { SFX_VO_GORON1, @@ -14,19 +26,18 @@ static const u16 goronSounds[] = { extern u8 gMapDataTopSpecial[]; extern u8 gUnk_02006F00[]; -void sub_0806D520(Entity*, u32); -void sub_0806D41C(Entity*); -void sub_0806CF30(Entity*); -void sub_0806D1D0(Entity*); -void sub_0806D274(Entity*); -void sub_0806D348(Entity*); -void sub_0806D3C0(Entity*); -void sub_0806D41C(Entity*); -void sub_0806D4F0(Entity*); -void sub_0806D4FC(Entity*); -void sub_0806D508(Entity*); -void sub_0806D514(Entity*); -void sub_0806D40C(Entity*); +void sub_0806D520(BigGoronEntity* this, u32); +void sub_0806CF30(BigGoronEntity* this); +void sub_0806D1D0(BigGoronEntity* this); +void sub_0806D274(BigGoronEntity* this); +void sub_0806D348(BigGoronEntity* this); +void sub_0806D3C0(BigGoronEntity* this); +void sub_0806D41C(BigGoronEntity* this); +void sub_0806D4F0(BigGoronEntity* this); +void sub_0806D4FC(BigGoronEntity* this); +void sub_0806D508(BigGoronEntity* this); +void sub_0806D514(BigGoronEntity* this); +void sub_0806D40C(BigGoronEntity* this); static void sub_0806D02C(Entity* this); @@ -48,7 +59,7 @@ void sub_0806D164(Entity* this); Entity* sub_0806D00C(Entity* this); -void sub_0806D4C0(Entity*, u32); +void sub_0806D4C0(BigGoronEntity* this, u32 type); typedef struct { s8 type; @@ -57,51 +68,51 @@ typedef struct { u8 direction; } struct_08114104; -void BigGoron(Entity* this) { - static void (*const typeFunctions[])(Entity*) = { +void BigGoron(BigGoronEntity* this) { + static void (*const typeFunctions[])(BigGoronEntity*) = { sub_0806CF30, sub_0806D1D0, sub_0806D274, sub_0806D348, sub_0806D3C0, sub_0806D41C, sub_0806D4F0, sub_0806D4FC, sub_0806D508, sub_0806D514, sub_0806D40C, }; - typeFunctions[this->type](this); + typeFunctions[super->type](this); } -void sub_0806CF30(Entity* this) { - if (this->action == 0) { - this->action = 1; - this->subAction = 1; - this->field_0x68.HWORD = this->x.HALF.HI; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0806D0B0(this); - sub_0807DD64(this); +void sub_0806CF30(BigGoronEntity* this) { + if (super->action == 0) { + super->action = 1; + super->subAction = 1; + this->originalX = super->x.HALF.HI; + SetDefaultPriority(super, PRIO_MESSAGE); + sub_0806D0B0(super); + sub_0807DD64(super); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); } - switch (this->subAction) { + switch (super->subAction) { case 0: case 1: if (gRoomTransition.frameCount % 4 == 0) { - if (gPlayerEntity.x.HALF.HI < this->x.HALF.HI && this->field_0x68.HWORD - 32 < this->x.HALF.HI) { - this->x.HALF.HI--; + if (gPlayerEntity.x.HALF.HI < super->x.HALF.HI && this->originalX - 32 < super->x.HALF.HI) { + super->x.HALF.HI--; } - if (gPlayerEntity.x.HALF.HI > this->x.HALF.HI && this->field_0x68.HWORD + 32 > this->x.HALF.HI) { - this->x.HALF.HI++; + if (gPlayerEntity.x.HALF.HI > super->x.HALF.HI && this->originalX + 32 > super->x.HALF.HI) { + super->x.HALF.HI++; } } break; case 2: - if (--this->timer == 0) { + if (--super->timer == 0) { u32 uVar2 = Random(); SoundReq(goronSounds[uVar2 % 4]); - this->timer = ((u8)uVar2 & 7) * 16; - this->timer += 128; + super->timer = ((u8)uVar2 & 7) * 16; + super->timer += 128; } break; case 3: break; } - sub_0806D02C(this); + sub_0806D02C(super); } Entity* sub_0806D00C(Entity* this) { @@ -192,228 +203,228 @@ void sub_0806D164(Entity* this) { gScreen.bg1.updated = 1; } -void sub_0806D1D0(Entity* this) { - if (this->action == 0) { - if (sub_0806D00C(this) == NULL) { +void sub_0806D1D0(BigGoronEntity* this) { + if (super->action == 0) { + if (sub_0806D00C(super) == NULL) { DeleteThisEntity(); } - this->action = 1; - this->spriteOrientation.flipY = 3; - this->spriteRendering.b3 = 3; - this->spritePriority.b0 = 7; - this->spriteSettings.draw = 3; - this->frameIndex = 0; - this->timer = 30; - SetDefaultPriority(this, PRIO_MESSAGE); + super->action = 1; + super->spriteOrientation.flipY = 3; + super->spriteRendering.b3 = 3; + super->spritePriority.b0 = 7; + super->spriteSettings.draw = 3; + super->frameIndex = 0; + super->timer = 30; + SetDefaultPriority(super, PRIO_MESSAGE); } - switch (this->subAction) { + switch (super->subAction) { case 0: default: - if (--this->timer == 0) { - this->timer = (Random() & 0x7f) + 48; - this->subtimer = 8; - this->frameIndex = 1; + if (--super->timer == 0) { + super->timer = (Random() & 0x7f) + 48; + super->subtimer = 8; + super->frameIndex = 1; } - if (this->subtimer != 0) { - if (--this->subtimer == 0) { - this->frameIndex = 0; + if (super->subtimer != 0) { + if (--super->subtimer == 0) { + super->frameIndex = 0; } } break; case 1: - this->frameIndex = this->subAction; + super->frameIndex = super->subAction; break; case 2: - this->spriteSettings.draw = 0; + super->spriteSettings.draw = 0; break; } - this->x.HALF.HI = this->parent->x.HALF.HI; - this->y.HALF.HI = this->parent->y.HALF.HI; + super->x.HALF.HI = super->parent->x.HALF.HI; + super->y.HALF.HI = super->parent->y.HALF.HI; } -void sub_0806D274(Entity* this) { +void sub_0806D274(BigGoronEntity* this) { Entity* npc; - if (this->action == 0) { - if (sub_0806D00C(this) == NULL) { + if (super->action == 0) { + if (sub_0806D00C(super) == NULL) { DeleteThisEntity(); } - this->action = 1; - this->spriteOrientation.flipY = 3; - this->spriteRendering.b3 = 3; - this->spritePriority.b0 = 7; - this->frameIndex = 2; - this->timer = 8; - SetDefaultPriority(this, PRIO_MESSAGE); + super->action = 1; + super->spriteOrientation.flipY = 3; + super->spriteRendering.b3 = 3; + super->spritePriority.b0 = 7; + super->frameIndex = 2; + super->timer = 8; + SetDefaultPriority(super, PRIO_MESSAGE); npc = CreateNPC(BIG_GORON, 3, 0); if (npc != NULL) { - npc->child = this; + npc->child = super; } } - switch (this->subAction) { + switch (super->subAction) { case 0: case 1: default: if ((gMessage.doTextBox & 0x7f) == 0) { - this->frameIndex = 2; + super->frameIndex = 2; break; } - if (--this->timer == 0) { - this->timer = 8; - this->frameIndex ^= 1; + if (--super->timer == 0) { + super->timer = 8; + super->frameIndex ^= 1; } break; case 2: - if (--this->timer == 0) { - this->timer = 8; - this->frameIndex ^= 1; + if (--super->timer == 0) { + super->timer = 8; + super->frameIndex ^= 1; } break; case 3: - this->frameIndex = 4; + super->frameIndex = 4; break; case 4: - this->frameIndex = 2; + super->frameIndex = 2; break; } - this->x.HALF.HI = this->parent->x.HALF.HI; - this->y.HALF.HI = this->parent->y.HALF.HI; + super->x.HALF.HI = super->parent->x.HALF.HI; + super->y.HALF.HI = super->parent->y.HALF.HI; } -void sub_0806D348(Entity* this) { - if (this->action == 0) { - if (sub_0806D00C(this) == NULL) { +void sub_0806D348(BigGoronEntity* this) { + if (super->action == 0) { + if (sub_0806D00C(super) == NULL) { DeleteThisEntity(); } - this->action = 1; - this->spriteOrientation.flipY = 3; - this->spriteRendering.b3 = 3; - this->spritePriority.b0 = 6; - this->spriteSettings.draw = 0; - this->frameIndex = 5; - SetDefaultPriority(this, PRIO_MESSAGE); + super->action = 1; + super->spriteOrientation.flipY = 3; + super->spriteRendering.b3 = 3; + super->spritePriority.b0 = 6; + super->spriteSettings.draw = 0; + super->frameIndex = 5; + SetDefaultPriority(super, PRIO_MESSAGE); } - if (this->child->frameIndex == 4) { - this->spriteSettings.draw = 3; + if (super->child->frameIndex == 4) { + super->spriteSettings.draw = 3; } else { - this->spriteSettings.draw = 0; + super->spriteSettings.draw = 0; } - this->x.HALF.HI = this->parent->x.HALF.HI; - this->y.HALF.HI = this->parent->y.HALF.HI; + super->x.HALF.HI = super->parent->x.HALF.HI; + super->y.HALF.HI = super->parent->y.HALF.HI; } -void sub_0806D3C0(Entity* this) { - if (this->action == 0) { - if (sub_0806D00C(this) == NULL) { +void sub_0806D3C0(BigGoronEntity* this) { + if (super->action == 0) { + if (sub_0806D00C(super) == NULL) { DeleteThisEntity(); } - this->action = 1; - this->hitbox = (Hitbox*)&gHitbox_3; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD64(this); + super->action = 1; + super->hitbox = (Hitbox*)&gHitbox_3; + SetDefaultPriority(super, PRIO_MESSAGE); + sub_0807DD64(super); } else { - this->x.HALF.HI = this->parent->x.HALF.HI; - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); + super->x.HALF.HI = super->parent->x.HALF.HI; + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); } } -void sub_0806D40C(Entity* this) { - this->spriteSettings.flipX = 1; +void sub_0806D40C(BigGoronEntity* this) { + super->spriteSettings.flipX = 1; sub_0806D41C(this); } -void sub_0806D41C(Entity* this) { - if (this->action == 0) { - this->action = 1; - this->frameIndex = 6; - sub_0807DD64(this); +void sub_0806D41C(BigGoronEntity* this) { + if (super->action == 0) { + super->action = 1; + super->frameIndex = 6; + sub_0807DD64(super); sub_0806D4C0(this, 0); sub_0806D4C0(this, 1); sub_0806D4C0(this, 2); sub_0806D4C0(this, 3); - SetDefaultPriority(this, PRIO_MESSAGE); + SetDefaultPriority(super, PRIO_MESSAGE); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); } if ((gRoomTransition.frameCount & 1) == 0) { - if (CheckPlayerProximity(this->x.HALF.HI - 0x20, this->y.HALF.HI, 0x40, 0x40) != 0) { - if (this->spriteOffsetY > -8) { - this->spriteOffsetY--; + if (CheckPlayerProximity(super->x.HALF.HI - 0x20, super->y.HALF.HI, 0x40, 0x40) != 0) { + if (super->spriteOffsetY > -8) { + super->spriteOffsetY--; } } else { - if (this->spriteOffsetY < 0) { - this->spriteOffsetY++; + if (super->spriteOffsetY < 0) { + super->spriteOffsetY++; } } } } -void sub_0806D4C0(Entity* this, u32 param) { - Entity* npc = CreateNPC(BIG_GORON, param + 6, 0); +void sub_0806D4C0(BigGoronEntity* this, u32 type) { + Entity* npc = CreateNPC(BIG_GORON, type + 6, 0); if (npc != NULL) { - npc->parent = this; - CopyPosition(this, npc); - SortEntityAbove(this, npc); + npc->parent = super; + CopyPosition(super, npc); + SortEntityAbove(super, npc); SetDefaultPriority(npc, PRIO_MESSAGE); } } -void sub_0806D4F0(Entity* this) { +void sub_0806D4F0(BigGoronEntity* this) { sub_0806D520(this, 0); } -void sub_0806D4FC(Entity* this) { +void sub_0806D4FC(BigGoronEntity* this) { sub_0806D520(this, 1); } -void sub_0806D508(Entity* this) { +void sub_0806D508(BigGoronEntity* this) { sub_0806D520(this, 2); } -void sub_0806D514(Entity* this) { +void sub_0806D514(BigGoronEntity* this) { sub_0806D520(this, 3); } -void sub_0806D520(Entity* this, u32 param_2) { +void sub_0806D520(BigGoronEntity* this, u32 param_2) { static const u8 gUnk_08114100[] = { 10, 7, 4, 1, }; - if (this->action == 0) { - this->action = 1; - this->subtimer = gUnk_08114100[param_2] + 6; - this->frameIndex = this->subtimer; - this->timer = 8; + if (super->action == 0) { + super->action = 1; + super->subtimer = gUnk_08114100[param_2] + 6; + super->frameIndex = super->subtimer; + super->timer = 8; } - this->x.HALF.HI = this->parent->x.HALF.HI; - this->y.HALF.HI = this->parent->y.HALF.HI; - this->spriteOffsetX = this->parent->spriteOffsetX; - this->spriteOffsetY = this->parent->spriteOffsetY; - this->spriteOrientation.flipY = this->parent->spriteOrientation.flipY; - if (this->subAction != 0 || - CheckPlayerProximity(this->x.HALF.HI + param_2 * -0x10 + 0xc, this->y.HALF.HI, 0x18, 0x40)) { - if (this->frameIndex >= this->subtimer + 2) { + super->x.HALF.HI = super->parent->x.HALF.HI; + super->y.HALF.HI = super->parent->y.HALF.HI; + super->spriteOffsetX = super->parent->spriteOffsetX; + super->spriteOffsetY = super->parent->spriteOffsetY; + super->spriteOrientation.flipY = super->parent->spriteOrientation.flipY; + if (super->subAction != 0 || + CheckPlayerProximity(super->x.HALF.HI + param_2 * -0x10 + 0xc, super->y.HALF.HI, 0x18, 0x40)) { + if (super->frameIndex >= super->subtimer + 2) { return; } - if (--this->timer != 0) { + if (--super->timer != 0) { return; } - this->timer = 8; - this->frameIndex++; + super->timer = 8; + super->frameIndex++; } else { - if (this->frameIndex <= this->subtimer) { + if (super->frameIndex <= super->subtimer) { return; } - if (--this->timer != 0) { + if (--super->timer != 0) { return; } - this->timer = 8; - this->frameIndex--; + super->timer = 8; + super->frameIndex--; } } diff --git a/src/npc/bladeBrothers.c b/src/npc/bladeBrothers.c index 2133d8098..4e862e68a 100644 --- a/src/npc/bladeBrothers.c +++ b/src/npc/bladeBrothers.c @@ -1,15 +1,28 @@ -#include "global.h" +/** + * @file bladeBrothers.c + * @ingroup NPCs + * + * @brief Blade Brothers NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "flags.h" +#include "functions.h" +#include "game.h" +#include "item.h" +#include "message.h" +#include "npc.h" #include "player.h" #include "room.h" -#include "message.h" #include "save.h" #include "script.h" -#include "npc.h" -#include "functions.h" -#include "game.h" -#include "item.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 itemSlotA; + /*0x6a*/ u8 itemSlotB; +} BladeBrothersEntity; void sub_08068A1C(Entity*); void sub_08068A4C(Entity*); @@ -21,10 +34,10 @@ void (*const gUnk_081115C0[])(Entity*) = { sub_08068AA4, sub_08068ADC, }; -void sub_08068AFC(Entity*); -void sub_08068b2c(Entity*); -void sub_08068B70(Entity*); -void (*const gUnk_081115D0[])(Entity*) = { +void sub_08068AFC(BladeBrothersEntity*); +void sub_08068b2c(BladeBrothersEntity*); +void sub_08068B70(BladeBrothersEntity*); +void (*const gUnk_081115D0[])(BladeBrothersEntity*) = { sub_08068AFC, sub_08068b2c, sub_08068B70, @@ -212,16 +225,16 @@ extern EntityData gUnk_080F3494; static void sub_08068BEC(Entity* this, u32 unused); -void BladeBrothers(Entity* this) { - if ((this->flags & ENT_SCRIPTED) != 0) { - gUnk_081115D0[this->action](this); +void BladeBrothers(BladeBrothersEntity* this) { + if ((super->flags & ENT_SCRIPTED) != 0) { + gUnk_081115D0[super->action](this); } else { - gUnk_081115C0[this->action](this); - sub_0806ED78(this); + gUnk_081115C0[super->action](super); + sub_0806ED78(super); } - if ((this->frame & 1) != 0) { - this->frame &= 0xfe; - sub_08068BEC(this, 0); + if ((super->frame & 1) != 0) { + super->frame &= 0xfe; + sub_08068BEC(super, 0); } } @@ -288,31 +301,30 @@ void sub_08068ADC(Entity* this) { sub_0806FD3C(this); } -void sub_08068AFC(Entity* this) { - this->action = 1; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); - sub_0807DD50(this); +void sub_08068AFC(BladeBrothersEntity* this) { + super->action = 1; + super->spriteSettings.draw = 1; + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); + InitScriptForNPC(super); } -void sub_08068b2c(Entity* this) { - u32 uVar1; - - if (this->interactType == '\x02') { - this->action = 2; - this->interactType = 0; - uVar1 = sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)); - InitAnimationForceUpdate(this, uVar1); - sub_0806F118(this); +void sub_08068b2c(BladeBrothersEntity* this) { + u32 animationState; + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + animationState = GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)); + InitAnimationForceUpdate(super, animationState); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } } -void sub_08068B70(Entity* this) { - if (UpdateFuseInteraction(this)) { - this->action = 1; +void sub_08068B70(BladeBrothersEntity* this) { + if (UpdateFuseInteraction(super)) { + super->action = 1; } } @@ -326,18 +338,18 @@ void BladeBrothers_StartPlayerDemonstration(Entity* this, ScriptExecutionContext InitPlayerMacro((PlayerMacroEntry*)BladeBrothers_PlayerMacros[this->timer]); } -void sub_08068BB4(Entity* this) { +void sub_08068BB4(BladeBrothersEntity* this) { u32 item = gSave.stats.itemButtons[SLOT_A]; - this->field_0x68.HALF.HI = item; + this->itemSlotA = item; item = gSave.stats.itemButtons[SLOT_B]; - *(&this->field_0x68.HALF.HI + 1) = item; + this->itemSlotB = item; } // Restore previous equipped items. -void sub_08068BD0(Entity* this) { - ForceEquipItem(this->field_0x68.HALF.HI, EQUIP_SLOT_A); - ForceEquipItem(*(u8*)(&this->field_0x68.HALF.HI + 1), EQUIP_SLOT_B); +void sub_08068BD0(BladeBrothersEntity* this) { + ForceEquipItem(this->itemSlotA, EQUIP_SLOT_A); + ForceEquipItem(this->itemSlotB, EQUIP_SLOT_B); } static void sub_08068BEC(Entity* this, u32 unused) { diff --git a/src/npc/brocco.c b/src/npc/brocco.c index e02ca622a..6edb285c1 100644 --- a/src/npc/brocco.c +++ b/src/npc/brocco.c @@ -1,19 +1,32 @@ +/** + * @file brocco.c + * @ingroup NPCs + * + * @brief Brocco NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "message.h" -#include "save.h" #include "npc.h" +#include "save.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; +} BroccoEntity; void sub_08063544(Entity*); -void sub_0806362C(Entity*); +void sub_0806362C(BroccoEntity*); void sub_0806355C(Entity*); void sub_08063584(Entity*); void sub_08063608(Entity*); -void Brocco(Entity* this) { - if ((this->flags & ENT_SCRIPTED) != 0) { +void Brocco(BroccoEntity* this) { + if ((super->flags & ENT_SCRIPTED) != 0) { sub_0806362C(this); } else { - sub_08063544(this); + sub_08063544(super); } } @@ -67,32 +80,33 @@ void sub_08063608(Entity* this) { } } -void sub_0806362C(Entity* this) { - switch (this->action) { +void sub_0806362C(BroccoEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.HI = 0; - sub_0807DD64(this); + super->action = 1; + super->spriteSettings.draw = 1; + this->animIndex = 0; + sub_0807DD64(super); case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 4); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + this->animIndex = super->animIndex; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) + 4); + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - UpdateAnimationSingleFrame(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + UpdateAnimationSingleFrame(super); } break; case 2: - if (UpdateFuseInteraction(this) == 0) { + if (UpdateFuseInteraction(super) == 0) { return; } - this->action = 1; - InitAnimationForceUpdate(this, this->field_0x68.HALF.HI); + super->action = 1; + InitAnimationForceUpdate(super, this->animIndex); break; } } @@ -114,9 +128,9 @@ void sub_080636D8(Entity* this) { ShowNPCDialogue(this, &gUnk_0810CAAC[gSave.global_progress]); } -void Brocco_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Brocco_MakeInteractable(BroccoEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Brocco_Fusion(Entity* this) { diff --git a/src/npc/carlov.c b/src/npc/carlov.c index ec97c9ba1..0cc920084 100644 --- a/src/npc/carlov.c +++ b/src/npc/carlov.c @@ -1,14 +1,21 @@ -#include "sound.h" +/** + * @file carlov.c + * @ingroup NPCs + * + * @brief Carlov NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "room.h" #include "npc.h" +#include "room.h" +#include "sound.h" void Carlov(Entity* this) { if (this->action == 0) { this->action++; - sub_0807DD50(this); + InitScriptForNPC(this); } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(this, NULL); } if ((this->frame & 0x10) != 0) { this->frame &= ~0x10; diff --git a/src/npc/carpenter.c b/src/npc/carpenter.c index f54795e04..3ddee3001 100644 --- a/src/npc/carpenter.c +++ b/src/npc/carpenter.c @@ -1,8 +1,22 @@ -#include "global.h" +/** + * @file carpenter.c + * @ingroup NPCs + * + * @brief Carpenter NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" -#include "npc.h" #include "item.h" +#include "npc.h" +#include "player.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; + /*0x6a*/ u8 unused[26]; + /*0x84*/ ScriptExecutionContext* context; +} CarpenterEntity; static const SpriteLoadData gUnk_08110CA8[] = { { 0x51, 0x3f, 0x4 }, { 0x1451, 0x3f, 0x4 }, { 0x4001, 0x3f, 0x4 }, { 0, 0, 0 }, @@ -11,38 +25,38 @@ static const SpriteLoadData gUnk_08110CA8[] = { { 0x51, 0x3f, 0x4 }, { 0x1451, 0x3f, 0x4 }, { 0, 0, 0 }, { 0, 0, 0 }, }; -void Carpenter(Entity* this) { - if (*(u32*)&this->cutsceneBeh == 0) { +void Carpenter(CarpenterEntity* this) { + if (this->context == NULL) { DeleteThisEntity(); } - switch (this->action) { + switch (super->action) { case 0: - if (!LoadExtraSpriteData(this, gUnk_08110CA8 + this->type * 4)) + if (!LoadExtraSpriteData(super, gUnk_08110CA8 + super->type * 4)) break; - this->action = 1; - this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD64(this); + super->action = 1; + this->animIndex = 0; + SetDefaultPriority(super, PRIO_MESSAGE); + sub_0807DD64(super); case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitializeAnimation(this, - sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 4 + (this->type * 8)); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + this->animIndex = super->animIndex; + InitializeAnimation(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) + + 4 + (super->type * 8)); + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, 0); - HandleEntity0x82Actions(this); - GetNextFrame(this); + ExecuteScriptForEntity(super, 0); + HandleEntity0x82Actions(super); + GetNextFrame(super); } break; case 2: - if (!UpdateFuseInteraction(this)) + if (!UpdateFuseInteraction(super)) break; - this->action = 1; - InitializeAnimation(this, this->field_0x68.HALF.HI); + super->action = 1; + InitializeAnimation(super, this->animIndex); break; } } @@ -91,15 +105,15 @@ void sub_08067304(Entity* this) { ShowNPCDialogue(this, &dialog); } -void Carpenter_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Carpenter_MakeInteractable(CarpenterEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Carpenter_Fusion(Entity* this) { if (this->action == 0) { if (LoadExtraSpriteData(this, &gUnk_08110CA8[this->type * 4])) { - this->action = this->action + 1; + this->action++; this->spriteSettings.draw = 1; SetDefaultPriority(this, PRIO_MESSAGE); InitializeAnimation(this, (u32)this->type * 8 + 2); diff --git a/src/npc/castleMaid.c b/src/npc/castleMaid.c index c17db2f85..7ce579838 100644 --- a/src/npc/castleMaid.c +++ b/src/npc/castleMaid.c @@ -1,12 +1,18 @@ +/** + * @file castleMaid.c + * @ingroup NPCs + * + * @brief Castle Maid NPC + */ #define NENT_DEPRECATED #include "entity.h" -#include "script.h" -#include "save.h" #include "flags.h" +#include "functions.h" +#include "manager.h" #include "message.h" #include "npc.h" -#include "manager.h" -#include "functions.h" +#include "save.h" +#include "script.h" typedef struct { Entity base; @@ -80,13 +86,13 @@ void sub_08064570(CastleMaidEntity* this) { this->field_0x6e = tmp2; } this->dialogFunc = NULL; - sub_0807DD50(super); + InitScriptForNPC(super); case 1: - sub_0807DD94(super, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); if (super->interactType != 0) { super->action++; super->interactType = 0; - InitializeAnimation(super, sub_0806F5A4(GetFacingDirection(super, &gPlayerEntity))); + InitializeAnimation(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); if (this->dialogFunc != NULL) { this->dialogFunc(); } @@ -172,7 +178,7 @@ void sub_080646A4(CastleMaidEntity* this, ScriptExecutionContext* context) { break; } super->direction = dir; - super->animationState = sub_0806F5B0(dir); + super->animationState = GetAnimationStateForDirection8(dir); super->speed = 0x80; } diff --git a/src/npc/castorWildsStatue.c b/src/npc/castorWildsStatue.c index c0557905d..1c08dd62b 100644 --- a/src/npc/castorWildsStatue.c +++ b/src/npc/castorWildsStatue.c @@ -1,10 +1,22 @@ -#include "sound.h" +/** + * @file castorWildsStatue.c + * @ingroup NPCs + * + * @brief Castor Wilds Statue NPC + */ +#define NENT_DEPRECATED +#include "effects.h" #include "entity.h" -#include "script.h" -#include "functions.h" #include "flags.h" -#include "effects.h" +#include "functions.h" #include "npc.h" +#include "script.h" +#include "sound.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unused[12]; + /*0x74*/ u16 tilePos; +} CastorWildsStatueEntity; static const Hitbox gUnk_08110E94; @@ -17,25 +29,25 @@ void sub_080673C0(Entity*); void sub_080673F4(Entity*); void sub_08067410(Entity*); void sub_0806752C(Entity*); -void sub_08067418(Entity*); -void sub_08067514(Entity*); +void sub_08067418(CastorWildsStatueEntity*); +void sub_08067514(CastorWildsStatueEntity*); -void CastorWildsStatue(Entity* this) { +void CastorWildsStatue(CastorWildsStatueEntity* this) { static void (*const actionFuncs[])(Entity*) = { sub_080673C0, sub_080673F4, sub_08067410, sub_0806752C, }; - static void (*const scriptedActionFuncs[])(Entity*) = { + static void (*const scriptedActionFuncs[])(CastorWildsStatueEntity*) = { sub_08067418, sub_08067514, }; - if ((this->flags & ENT_SCRIPTED) != 0) { - scriptedActionFuncs[this->action](this); + if ((super->flags & ENT_SCRIPTED) != 0) { + scriptedActionFuncs[super->action](this); } else { - actionFuncs[this->action](this); - sub_0806ED78(this); + actionFuncs[super->action](super); + sub_0806ED78(super); } } @@ -62,20 +74,20 @@ void sub_08067410(Entity* this) { this->action = 1; } -void sub_08067418(Entity* this) { - this->action = 1; - this->field_0x74.HWORD = COORD_TO_TILE(this); - if (this->type == 0) { - this->hitbox = (Hitbox*)&gUnk_08110E94; - SetTile(0x4022, this->field_0x74.HWORD - 1, this->collisionLayer); - SetTile(0x4022, this->field_0x74.HWORD, this->collisionLayer); - SetTile(0x4022, this->field_0x74.HWORD + 0x3f, this->collisionLayer); - SetTile(0x4022, this->field_0x74.HWORD + 0x40, this->collisionLayer); +void sub_08067418(CastorWildsStatueEntity* this) { + super->action = 1; + this->tilePos = COORD_TO_TILE(super); + if (super->type == 0) { + super->hitbox = (Hitbox*)&gUnk_08110E94; + SetTile(0x4022, this->tilePos - 1, super->collisionLayer); + SetTile(0x4022, this->tilePos, super->collisionLayer); + SetTile(0x4022, this->tilePos + 0x3f, super->collisionLayer); + SetTile(0x4022, this->tilePos + 0x40, super->collisionLayer); } else { - this->collisionLayer = 3; - this->spriteOrientation.flipY = 1; - this->spriteRendering.b3 = 1; - this->spritePriority.b0 = 2; + super->collisionLayer = 3; + super->spriteOrientation.flipY = 1; + super->spriteRendering.b3 = 1; + super->spritePriority.b0 = 2; if (CheckLocalFlag(HIKYOU_00_SEKIZOU) == 0) { SetTile(0x4022, 0xe81, 1); SetTile(0x4022, 0xe82, 1); @@ -83,13 +95,13 @@ void sub_08067418(Entity* this) { SetTile(0x4022, 0xec3, 1); } } - sub_0807DD50(this); + InitScriptForNPC(super); } -void sub_08067514(Entity* this) { - sub_0807DD94(this, NULL); - if (this->type == 0) { - sub_0806ED78(this); +void sub_08067514(CastorWildsStatueEntity* this) { + ExecuteScriptAndHandleAnimation(super, NULL); + if (super->type == 0) { + sub_0806ED78(super); } } diff --git a/src/npc/cat.c b/src/npc/cat.c index 33586cb91..149276575 100644 --- a/src/npc/cat.c +++ b/src/npc/cat.c @@ -1,35 +1,55 @@ -#include "global.h" +/** + * @file cat.c + * @ingroup NPCs + * + * @brief Cat NPC + */ +#define NENT_DEPRECATED +#include "enemy.h" #include "entity.h" #include "functions.h" -#include "save.h" #include "message.h" #include "npc.h" -#include "enemy.h" +#include "save.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unk_69; + /*0x6a*/ u8 unused[2]; + /*0x6c*/ u16 unk_6c; + /*0x6e*/ u16 unk_6e; + /*0x70*/ u8 unk_70; + /*0x71*/ u8 unk_71; + /*0x72*/ u16 unk_72; + /*0x74*/ u8 unk_74; + /*0x75*/ u8 unk_75; +} CatEntity; static const Hitbox gUnk_08110EF0 = { 0, -1, { 5, 3, 3, 5 }, 5, 4 }; -void sub_08067C44(Entity*); -void sub_08067B08(Entity*); -u32 sub_08067D20(Entity*); -void sub_08067AAC(Entity*); -void sub_08067B34(Entity*); -void sub_08067B80(Entity*, u32); -void sub_08067B70(Entity*); -void sub_08067C24(Entity*); +void sub_08067C44(CatEntity*); +void sub_08067B08(CatEntity*); +bool32 sub_08067D20(CatEntity*); +void sub_08067AAC(CatEntity*); +void sub_08067B34(CatEntity*); +void sub_08067B80(CatEntity*, u32); +void sub_08067B70(CatEntity*); +void sub_08067C24(CatEntity*); void sub_08067BD4(Entity*); -u32 sub_08067D74(Entity*); +bool32 sub_08067D74(Entity*); void sub_08067C18(Entity*); -void sub_08067DCC(Entity*, u32); +void sub_08067DCC(CatEntity*, u32); void sub_08067DDC(Entity*); -void sub_080677EC(Entity*); -void sub_080678AC(Entity*); -void sub_08067904(Entity*); -void sub_0806797C(Entity*); -void sub_0806799C(Entity*); -void sub_080679C4(Entity*); -void sub_08067A0C(Entity*); -void sub_08067A78(Entity*); -void sub_08067A98(Entity*); +void sub_080677EC(CatEntity*); +void sub_080678AC(CatEntity*); +void sub_08067904(CatEntity*); +void sub_0806797C(CatEntity*); +void sub_0806799C(CatEntity*); +void sub_080679C4(CatEntity*); +void sub_08067A0C(CatEntity*); +void sub_08067A78(CatEntity*); +void sub_08067A98(CatEntity*); extern Hitbox* gUnk_08111154[8]; @@ -100,159 +120,154 @@ void sub_08067790(Entity* this) { } // Main -void Cat(Entity* ent) { - static void (*const actionFuncs[9])(Entity*) = { +void Cat(CatEntity* this) { + static void (*const actionFuncs[9])(CatEntity*) = { sub_080677EC, sub_080678AC, sub_08067904, sub_0806797C, sub_0806799C, sub_080679C4, sub_08067A0C, sub_08067A78, sub_08067A98, }; - actionFuncs[ent->action](ent); - sub_08067C44(ent); - if (((ent->flags & ENT_COLLIDE) == 0) && (ent->type != 5)) { - sub_0806ED78(ent); + actionFuncs[super->action](this); + sub_08067C44(this); + if (((super->flags & ENT_COLLIDE) == 0) && (super->type != 5)) { + sub_0806ED78(super); } } -void sub_080677EC(Entity* this) { +void sub_080677EC(CatEntity* this) { u32 uVar2; - this->spriteSettings.draw = 1; - this->direction = 8; - this->speed = 0x80; - this->collisionFlags = 7; - this->hurtType = 0x48; - this->hitType = -0x58; - this->flags2 = 1; - this->field_0x68.HALF.HI = 0xff; - if (this->x.HALF.HI < gPlayerEntity.x.HALF.HI) { - this->spriteSettings.flipX = 1; + super->spriteSettings.draw = 1; + super->direction = 8; + super->speed = 0x80; + super->collisionFlags = 7; + super->hurtType = 0x48; + super->hitType = -0x58; + super->flags2 = 1; + this->unk_69 = 0xff; + if (super->x.HALF.HI < gPlayerEntity.x.HALF.HI) { + super->spriteSettings.flipX = 1; } else { - this->spriteSettings.flipX = 0; + super->spriteSettings.flipX = 0; } - this->field_0x68.HALF.LO = GetFusionToOffer(this); - this->hitbox = (Hitbox*)&gUnk_08110EF0; - uVar2 = sub_0805ACC0(this); + this->fusionOffer = GetFusionToOffer(super); + super->hitbox = (Hitbox*)&gUnk_08110EF0; + uVar2 = sub_0805ACC0(super); if (uVar2 == 0) { - uVar2 = this->x.HALF.HI; + uVar2 = super->x.HALF.HI; } else { uVar2 >>= 0x10; } - this->field_0x6c.HWORD = uVar2; - this->field_0x6e.HWORD = this->timer + uVar2; - this->timer = 0; - this->field_0x74.HALF.HI = 0; - this->field_0x74.HALF.LO = (Random() & 0x7f) + 0x1e; - this->field_0x68.HALF.HI = 0xff; + this->unk_6c = uVar2; + this->unk_6e = super->timer + uVar2; + super->timer = 0; + this->unk_75 = 0; + this->unk_74 = (Random() & 0x7f) + 0x1e; + this->unk_69 = 0xff; sub_08067B08(this); } -void sub_080678AC(Entity* this) { - u32 iVar1; - u16* psVar2; - - iVar1 = sub_08067D20(this); - if (iVar1 != 0) { +void sub_080678AC(CatEntity* this) { + if (sub_08067D20(this)) { sub_08067B80(this, 5); } else { - psVar2 = (u16*)&this->field_0x70.HALF.HI; - if (*psVar2 != 0) { - *psVar2 = *psVar2 - 1; + if (this->unk_72 != 0) { + this->unk_72--; } - if ((this->frame == 1) && (*psVar2 == 0)) { + if ((super->frame == 1) && (this->unk_72 == 0)) { sub_08067AAC(this); } else { - UpdateAnimationSingleFrame(this); - if ((this->frame & ANIM_DONE) != 0) { + UpdateAnimationSingleFrame(super); + if ((super->frame & ANIM_DONE) != 0) { sub_08067B34(this); } } } } -void sub_08067904(Entity* this) { +void sub_08067904(CatEntity* this) { if (sub_08067D20(this) != 0) { sub_08067B80(this, 8); return; } - this->field_0x70.HALF.HI--; - if (this->field_0x70.HALF.HI == 0) { + this->unk_72--; + if (this->unk_72 == 0) { sub_08067B70(this); return; } - if (this->direction == 8) { - if (this->x.HALF.HI > this->field_0x6e.HWORD) { - this->direction = 0x18; - this->spriteSettings.flipX = 0; + if (super->direction == 8) { + if (super->x.HALF.HI > this->unk_6e) { + super->direction = 0x18; + super->spriteSettings.flipX = 0; } } else { - if (this->x.HALF.HI < this->field_0x6c.HWORD) { - this->direction = 8; - this->spriteSettings.flipX = 1; + if (super->x.HALF.HI < this->unk_6c) { + super->direction = 8; + super->spriteSettings.flipX = 1; } } - LinearMoveUpdate(this); - UpdateAnimationSingleFrame(this); + LinearMoveUpdate(super); + UpdateAnimationSingleFrame(super); } -void sub_0806797C(Entity* this) { - UpdateAnimationSingleFrame(this); - if (this->frame & ANIM_DONE) { +void sub_0806797C(CatEntity* this) { + UpdateAnimationSingleFrame(super); + if (super->frame & ANIM_DONE) { sub_08067B08(this); } } -void sub_0806799C(Entity* this) { - UpdateAnimationSingleFrame(this); +void sub_0806799C(CatEntity* this) { + UpdateAnimationSingleFrame(super); if ((gMessage.doTextBox & 0x7f) == 0) { sub_08067B08(this); - SetDefaultPriority(this, PRIO_PLAYER); + SetDefaultPriority(super, PRIO_PLAYER); } } -void sub_080679C4(Entity* this) { - if (this->field_0x74.HALF.LO == 0 || --this->field_0x74.HALF.LO == 0 || sub_08067D20(this) == 0) { +void sub_080679C4(CatEntity* this) { + if (this->unk_74 == 0 || --this->unk_74 == 0 || sub_08067D20(this) == 0) { sub_08067C24(this); } else { - UpdateAnimationSingleFrame(this); - sub_08067BD4(this); - if (sub_08067D74(this) != 0) { - sub_08067C18(this); + UpdateAnimationSingleFrame(super); + sub_08067BD4(super); + if (sub_08067D74(super) != 0) { + sub_08067C18(super); } } } -void sub_08067A0C(Entity* this) { +void sub_08067A0C(CatEntity* this) { u8 tmp; - UpdateAnimationSingleFrame(this); - if (this->frame & ANIM_DONE) { - if (sub_08067D20(this) != 0) { + UpdateAnimationSingleFrame(super); + if (super->frame & ANIM_DONE) { + if (sub_08067D20(this)) { sub_08067B80(this, 5); - this->timer += 20; + super->timer += 20; } else { sub_08067C24(this); } } else { - tmp = (this->frame & 7); + tmp = (super->frame & 7); if (tmp != 0) { - COLLISION_ON(this); - this->hitbox = gUnk_08111154[tmp - 1 + ((this->spriteSettings.flipX << 2))]; + COLLISION_ON(super); + super->hitbox = gUnk_08111154[tmp - 1 + ((super->spriteSettings.flipX << 2))]; } else { - sub_08067DDC(this); + sub_08067DDC(super); } } } -void sub_08067A78(Entity* this) { - UpdateAnimationSingleFrame(this); - if (this->frame & ANIM_DONE) { +void sub_08067A78(CatEntity* this) { + UpdateAnimationSingleFrame(super); + if (super->frame & ANIM_DONE) { sub_08067AAC(this); } } -void sub_08067A98(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { +void sub_08067A98(CatEntity* this) { + if (UpdateFuseInteraction(super) != 0) { sub_08067B08(this); } } @@ -274,43 +289,43 @@ static const u16 gUnk_08111104[] = { static const u8 gUnk_0811110C[] = { 0x3c, 0x96, 0x14 }; static const u8 gUnk_0811110F[] = { 0, -4, 8, 8, 0 }; -void sub_08067AAC(Entity* this) { - this->action = 2; - this->field_0x70.HALF.HI = gUnk_081110FC[(Random() & 3)]; +void sub_08067AAC(CatEntity* this) { + super->action = 2; + this->unk_72 = gUnk_081110FC[(Random() & 3)]; - this->spriteSettings.flipX = this->direction >> 4 ^ 1; + super->spriteSettings.flipX = super->direction >> 4 ^ 1; sub_08067DCC(this, 3); - SetInteractableObjectCollision(this, 0, gUnk_0811110C[2], gUnk_0811110F); + SetInteractableObjectCollision(super, 0, gUnk_0811110C[2], gUnk_0811110F); } -void sub_08067B08(Entity* this) { - this->action = 1; - this->field_0x70.HALF.HI = gUnk_08111104[Random() & 3]; +void sub_08067B08(CatEntity* this) { + super->action = 1; + this->unk_72 = gUnk_08111104[Random() & 3]; sub_08067B34(this); } -void sub_08067B34(Entity* this) { +void sub_08067B34(CatEntity* this) { sub_08067DCC(this, 0); - this->frameDuration = (Random() & 0x30) + 0xb4; - SetInteractableObjectCollision(this, 0, gUnk_0811110C[this->spriteSettings.flipX], gUnk_0811110F); + super->frameDuration = (Random() & 0x30) + 0xb4; + SetInteractableObjectCollision(super, 0, gUnk_0811110C[super->spriteSettings.flipX], gUnk_0811110F); } -void sub_08067B70(Entity* this) { - this->action = 3; +void sub_08067B70(CatEntity* this) { + super->action = 3; sub_08067DCC(this, 4); } -void sub_08067B80(Entity* this, u32 param) { - this->action = 5; - this->timer = 20; - this->field_0x74.HALF.LO = (Random() & 0x7f) + 0x1e; - InitAnimationForceUpdate(this, param); - sub_08067DDC(this); - if (this->x.HALF.HI < gPlayerEntity.x.HALF.HI) { - this->spriteSettings.flipX = 1; +void sub_08067B80(CatEntity* this, u32 animIndex) { + super->action = 5; + super->timer = 20; + this->unk_74 = (Random() & 0x7f) + 0x1e; + InitAnimationForceUpdate(super, animIndex); + sub_08067DDC(super); + if (super->x.HALF.HI < gPlayerEntity.x.HALF.HI) { + super->spriteSettings.flipX = 1; } else { - this->spriteSettings.flipX = 0; + super->spriteSettings.flipX = 0; } } @@ -331,14 +346,14 @@ void sub_08067C18(Entity* this) { InitAnimationForceUpdate(this, 6); } -void sub_08067C24(Entity* this) { - this->action = 7; - this->field_0x74.HALF.HI = 0x14; - sub_08067DDC(this); - InitAnimationForceUpdate(this, 7); +void sub_08067C24(CatEntity* this) { + super->action = 7; + this->unk_75 = 0x14; + sub_08067DDC(super); + InitAnimationForceUpdate(super, 7); } -void sub_08067C44(Entity* this) { +void sub_08067C44(CatEntity* this) { s32 iVar4; u32 uVar5; @@ -348,78 +363,78 @@ void sub_08067C44(Entity* this) { uVar5 = FALSE; } - if (uVar5 != this->field_0x68.HALF.HI) { + if (uVar5 != this->unk_69) { if (uVar5 == 0) { - AddInteractableWhenBigObject(this); + AddInteractableWhenBigObject(super); } else { - AddInteractableAsMinishFuser(this, this->field_0x68.HALF.LO); + AddInteractableAsMinishFuser(super, this->fusionOffer); } } - this->field_0x68.HALF.HI = uVar5; + this->unk_69 = uVar5; - if (this->interactType == 0) { + if (super->interactType == 0) { return; } - iVar4 = sub_0806FCA0(this, &gPlayerEntity); - switch (this->animIndex) { + iVar4 = sub_0806FCA0(super, &gPlayerEntity); + switch (super->animIndex) { case 0: default: if (iVar4 == 2) { - InitAnimationForceUpdate(this, 2); + InitAnimationForceUpdate(super, 2); } else { - InitAnimationForceUpdate(this, 1); + InitAnimationForceUpdate(super, 1); } break; case 3: if (iVar4 == 1) { - this->spriteSettings.flipX = 1; + super->spriteSettings.flipX = 1; } else { - if (this->spriteSettings.flipX == 3) { // TODO 3 ??? - this->spriteSettings.flipX = 0; + if (super->spriteSettings.flipX == 3) { // TODO 3 ??? + super->spriteSettings.flipX = 0; } } if (iVar4 != 2) { - InitAnimationForceUpdate(this, 1); + InitAnimationForceUpdate(super, 1); } else { - InitAnimationForceUpdate(this, 2); + InitAnimationForceUpdate(super, 2); } break; } - if (this->interactType == 2) { - this->action = 8; - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 8; + InitializeNPCFusion(super); } else { - this->action = 4; - sub_08067790(this); - SetDefaultPriority(this, PRIO_MESSAGE); + super->action = 4; + sub_08067790(super); + SetDefaultPriority(super, PRIO_MESSAGE); } - this->interactType = 0; + super->interactType = 0; SoundReq(SFX_VO_CAT); } -u32 sub_08067D20(Entity* this) { +bool32 sub_08067D20(CatEntity* this) { s32 tmp; Entity* entity; int iVar4; - if (this->field_0x74.HALF.HI != 0) { - this->field_0x74.HALF.HI--; + if (this->unk_75 != 0) { + this->unk_75--; } else { entity = sub_08049DF4(2); if (entity != NULL) { - iVar4 = this->spriteSettings.flipX ? 0x10 : 0x28; - if (((u32)(entity->x.HALF.HI - (this->x.HALF.HI - iVar4)) < 0x31) && - ((((u32)entity->y.HALF.HI) - (this->y.HALF.HI - 4)) < 0x39)) { - return 1; + iVar4 = super->spriteSettings.flipX ? 0x10 : 0x28; + if (((u32)(entity->x.HALF.HI - (super->x.HALF.HI - iVar4)) < 0x31) && + ((((u32)entity->y.HALF.HI) - (super->y.HALF.HI - 4)) < 0x39)) { + return TRUE; } } } - return 0; + return FALSE; } -u32 sub_08067D74(Entity* this) { +bool32 sub_08067D74(Entity* this) { Entity* entity; int iVar2; @@ -433,16 +448,16 @@ u32 sub_08067D74(Entity* this) { if ((((u32)(entity->x.HALF.HI - (this->x.HALF.HI - iVar2)) < 0x1f) && ((u32)(entity->y.HALF.HI - this->y.HALF.HI) < 0x17)) && (this->timer == 0)) { - return 1; + return TRUE; } } } - return 0; + return FALSE; } -void sub_08067DCC(Entity* this, u32 param) { - this->field_0x70.BYTES.byte1 = param; - InitAnimationForceUpdate(this, param); +void sub_08067DCC(CatEntity* this, u32 animIndex) { + this->unk_71 = animIndex; + InitAnimationForceUpdate(super, animIndex); } void sub_08067DDC(Entity* this) { diff --git a/src/npc/clothesRack.c b/src/npc/clothesRack.c index 883999f86..1d63c3762 100644 --- a/src/npc/clothesRack.c +++ b/src/npc/clothesRack.c @@ -1,4 +1,11 @@ +/** + * @file clothesRack.c + * @ingroup NPCs + * + * @brief Clothes Rack NPC + */ #include "npc.h" +#define NENT_DEPRECATED void sub_0806DD90(Entity*); void sub_0806DEC8(Entity*); @@ -12,23 +19,22 @@ void ClothesRack(Entity* this) { } void sub_0806DD90(Entity* this) { - u32 uVar1; - u32 uVar2; + u32 animIndex; u32 x; u32 y; this->action = 1; - uVar2 = 0; + animIndex = 0; if (CheckGlobalFlag(DRUG_1)) { - uVar2 = 1; + animIndex = 1; } - if (CheckGlobalFlag(DRUG_2) != 0) { - uVar2 = 2; + if (CheckGlobalFlag(DRUG_2)) { + animIndex = 2; } - if (CheckGlobalFlag(DRUG_3) != 0) { - uVar2 = 3; + if (CheckGlobalFlag(DRUG_3)) { + animIndex = 3; } - InitializeAnimation(this, uVar2); + InitializeAnimation(this, animIndex); x = this->x.HALF.HI; y = this->y.HALF.HI; SetTile(0x4072, TILE(x - 0x18, y - 0x10), this->collisionLayer); diff --git a/src/npc/cow.c b/src/npc/cow.c index e74ed30a4..9fd35f7d3 100644 --- a/src/npc/cow.c +++ b/src/npc/cow.c @@ -1,194 +1,208 @@ -#include "global.h" -#include "sound.h" +/** + * @file cow.c + * @ingroup NPCs + * + * @brief Cow NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" -#include "npc.h" #include "functions.h" +#include "npc.h" +#include "player.h" +#include "sound.h" -void sub_0806920C(Entity* ent); -void sub_0806924C(Entity* ent); -void sub_08068FC0(Entity* ent); -void sub_08069018(Entity* ent); -void sub_08069068(Entity* ent); -void sub_08069124(Entity* ent); -void sub_080691E0(Entity* ent); -void sub_08069148(Entity* ent); -void sub_08069168(Entity* ent); -void sub_08069188(Entity* ent); -void sub_080691BC(Entity* ent); - -void Cow(Entity* ent) { - static void (*const actionFuncs[])(Entity*) = { +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u16 unk_68; + /*0x6a*/ u16 unk_6a; + /*0x6c*/ u8 fusionOffer; + /*0x6d*/ u8 unk_6d; +} CowEntity; + +void sub_0806920C(CowEntity* this); +void sub_0806924C(CowEntity* this); +void sub_08068FC0(CowEntity* this); +void sub_08069018(CowEntity* this); +void sub_08069068(CowEntity* this); +void sub_08069124(CowEntity* this); +void sub_080691E0(CowEntity* this); +void sub_08069148(CowEntity* this); +void sub_08069168(CowEntity* this); +void sub_08069188(CowEntity* this); +void sub_080691BC(CowEntity* this); + +void Cow(CowEntity* this) { + static void (*const actionFuncs[])(CowEntity*) = { sub_08068FC0, sub_08069018, sub_08069068, sub_08069124, sub_080691E0, }; - actionFuncs[ent->action](ent); - sub_0806ED78(ent); - sub_0806920C(ent); + actionFuncs[super->action](this); + sub_0806ED78(super); + sub_0806920C(this); } -void sub_08068FC0(Entity* ent) { +void sub_08068FC0(CowEntity* this) { u32 r2; - ent->action = 1; - ent->animationState = ent->type2; - ent->speed = 0x40; + super->action = 1; + super->animationState = super->type2; + super->speed = 0x40; - ent->field_0x6c.HALF.HI = 0xFF; + this->unk_6d = 0xff; - r2 = sub_0805ACC0(ent); + r2 = sub_0805ACC0(super); if (r2 == 0) { u16 x, y; - x = ent->x.HALF.HI; - *(u16*)&ent->field_0x68 = x; + x = super->x.HALF.HI; + this->unk_68 = x; - y = ent->y.HALF.HI; - ent->field_0x6a.HWORD = y; + y = super->y.HALF.HI; + this->unk_6a = y; } else { u32 var1 = r2 >> 16; // 0x68+0x69 probably a SplitWord - *(u16*)&ent->field_0x68 = var1; - ent->field_0x6a.HWORD = r2; + this->unk_68 = var1; + this->unk_6a = r2; } - ent->field_0x6c.HALF.LO = GetFusionToOffer(ent); + this->fusionOffer = GetFusionToOffer(super); - InitAnimationForceUpdate(ent, ent->animationState + 4); + InitAnimationForceUpdate(super, super->animationState + 4); } -void sub_08069018(Entity* ent) { +void sub_08069018(CowEntity* this) { s32 var0; - if (ent->subAction == 0) { - ent->subAction++; - ent->subtimer = (Random() & 0x3F) + 0x3C; - InitAnimationForceUpdate(ent, ent->animationState); + if (super->subAction == 0) { + super->subAction++; + super->subtimer = (Random() & 0x3F) + 0x3C; + InitAnimationForceUpdate(super, super->animationState); } - UpdateAnimationSingleFrame(ent); - var0 = --ent->subtimer; + UpdateAnimationSingleFrame(super); + var0 = --super->subtimer; if (var0 == 0) { - if (ent->timer == 0) { - ent->action = 2; + if (super->timer == 0) { + super->action = 2; } else { - ent->action = 3; + super->action = 3; } - ent->subAction = var0; + super->subAction = var0; } - sub_0806924C(ent); + sub_0806924C(this); } -void sub_08069068(Entity* ent) { +void sub_08069068(CowEntity* this) { s32 var0; - if (ent->subAction == 0) { + if (super->subAction == 0) { u32 anim; - ent->subAction++; + super->subAction++; anim = (Random() & 2) - 1; - anim = (anim + ent->animationState) & 3; - ent->animationState = anim; - ent->direction = anim <<= 3; + anim = (anim + super->animationState) & 3; + super->animationState = anim; + super->direction = anim <<= 3; - ent->subtimer = (Random() & 0x3F) + 60; - InitAnimationForceUpdate(ent, ent->animationState + 4); + super->subtimer = (Random() & 0x3F) + 60; + InitAnimationForceUpdate(super, super->animationState + 4); } - ProcessMovement0(ent); - UpdateAnimationSingleFrame(ent); + ProcessMovement0(super); + UpdateAnimationSingleFrame(super); { - s32 x = ent->x.HALF.HI; - s16* x2 = (s16*)&ent->field_0x68; + s32 x = super->x.HALF.HI; + s16* x2 = (s16*)&this->unk_68; x -= *x2; if (x > 16) { - ent->x.HALF.HI = *x2 + 16; - ent->subtimer = 1; + super->x.HALF.HI = *x2 + 16; + super->subtimer = 1; } if (x < -16) { - ent->x.HALF.HI = *x2 - 16; - ent->subtimer = 1; + super->x.HALF.HI = *x2 - 16; + super->subtimer = 1; } } { - s32 y = ent->y.HALF.HI; - s16* y2 = &ent->field_0x6a.HWORD; + s32 y = super->y.HALF.HI; + s16* y2 = &this->unk_6a; y -= *y2; if (y > 16) { - ent->y.HALF.HI = *y2 + 16; - ent->subtimer = 1; + super->y.HALF.HI = *y2 + 16; + super->subtimer = 1; } if (y < -16) { - ent->y.HALF.HI = *y2 - 16; - ent->subtimer = 1; + super->y.HALF.HI = *y2 - 16; + super->subtimer = 1; } } - var0 = --ent->subtimer; + var0 = --super->subtimer; if (var0 == 0) { - ent->action = 3; - ent->subAction = var0; + super->action = 3; + super->subAction = var0; } - sub_0806924C(ent); + sub_0806924C(this); } -void sub_08069124(Entity* ent) { - static void (*const subActionFuncs[])(Entity*) = { +void sub_08069124(CowEntity* this) { + static void (*const subActionFuncs[])(CowEntity*) = { sub_08069148, sub_08069168, sub_08069188, sub_080691BC, }; - UpdateAnimationSingleFrame(ent); - subActionFuncs[ent->subAction](ent); - sub_0806924C(ent); + UpdateAnimationSingleFrame(super); + subActionFuncs[super->subAction](this); + sub_0806924C(this); } -void sub_08069148(Entity* ent) { +void sub_08069148(CowEntity* this) { u32 var0 = Random() & 3; var0 += 3; - ent->subtimer = var0; - ent->subAction = 1; - InitAnimationForceUpdate(ent, ent->animationState + 8); + super->subtimer = var0; + super->subAction = 1; + InitAnimationForceUpdate(super, super->animationState + 8); } -void sub_08069168(Entity* ent) { - if ((s8)ent->frame < 0) { - ent->subAction = 2; - InitAnimationForceUpdate(ent, ent->animationState + 12); +void sub_08069168(CowEntity* this) { + if ((s8)super->frame < 0) { + super->subAction = 2; + InitAnimationForceUpdate(super, super->animationState + 12); } } -void sub_08069188(Entity* ent) { - if ((ent->frame & 1) == 0) +void sub_08069188(CowEntity* this) { + if ((super->frame & 1) == 0) return; - ent->frame = 0; + super->frame = 0; - if (--ent->subtimer != 0) + if (--super->subtimer != 0) return; - ent->subAction = 3; - InitAnimationForceUpdate(ent, ent->animationState + 16); + super->subAction = 3; + InitAnimationForceUpdate(super, super->animationState + 16); } -void sub_080691BC(Entity* ent) { - if ((s8)ent->frame < 0) { - ent->action = 1; - ent->subAction = 0; - InitAnimationForceUpdate(ent, ent->animationState + 4); +void sub_080691BC(CowEntity* this) { + if ((s8)super->frame < 0) { + super->action = 1; + super->subAction = 0; + InitAnimationForceUpdate(super, super->animationState + 4); } } -void sub_080691E0(Entity* ent) { - if (UpdateFuseInteraction(ent) != 0) { - ent->action = 1; - ent->subAction = 0; +void sub_080691E0(CowEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + super->subAction = 0; } } // Show dialogue -void Cow_ShowDialogue(Entity* ent) { +void Cow_ShowDialogue(CowEntity* this) { static const Dialog gUnk_08111938[] = { { 0x0, 0x0, DIALOG_MINISH, 1, { TEXT_INDEX(TEXT_LON_LON, 0X18), TEXT_INDEX(TEXT_TINGLE, 0x34) } }, { 0x0, 0x0, DIALOG_MINISH, 1, { TEXT_INDEX(TEXT_LON_LON, 0X18), TEXT_INDEX(TEXT_TINGLE, 0x35) } }, @@ -196,10 +210,10 @@ void Cow_ShowDialogue(Entity* ent) { { 0x0, 0x0, DIALOG_MINISH, 1, { TEXT_INDEX(TEXT_LON_LON, 0X18), TEXT_INDEX(TEXT_TINGLE, 0x37) } }, { 0x0, 0x0, DIALOG_MINISH, 1, { TEXT_INDEX(TEXT_LON_LON, 0X18), TEXT_INDEX(TEXT_TINGLE, 0x38) } } }; - ShowNPCDialogue(ent, &gUnk_08111938[ent->type]); + ShowNPCDialogue(super, &gUnk_08111938[super->type]); } -void sub_0806920C(Entity* ent) { +void sub_0806920C(CowEntity* this) { u32 var1; if ((gPlayerState.flags & PL_MINISH) != 0) { var1 = TRUE; @@ -207,43 +221,43 @@ void sub_0806920C(Entity* ent) { var1 = FALSE; } - if (var1 != ent->field_0x6c.HALF.HI) { + if (var1 != this->unk_6d) { if (var1 == 0) { - AddInteractableWhenBigObject(ent); + AddInteractableWhenBigObject(super); } else { - AddInteractableAsMinishFuser(ent, ent->field_0x6c.HALF.LO); + AddInteractableAsMinishFuser(super, this->fusionOffer); } } - ent->field_0x6c.HALF.HI = var1; + this->unk_6d = var1; } // Check if player interacting -void sub_0806924C(Entity* ent) { - s8 itype = ent->interactType; +void sub_0806924C(CowEntity* this) { + s8 itype = super->interactType; if (itype != 0) { if ((gPlayerState.flags & PL_MINISH) != 0) { if (itype == 2) { - ent->action = 4; - sub_0806F118(ent); + super->action = 4; + InitializeNPCFusion(super); } else { - Cow_ShowDialogue(ent); + Cow_ShowDialogue(this); } } else { - Cow_ShowDialogue(ent); + Cow_ShowDialogue(this); ResetPlayerAnimationAndAction(); } SoundReq(SFX_VO_COW); - ent->interactType = 0; + super->interactType = 0; } } -void Cow_Fusion(Entity* ent) { - if (ent->action == 0) { - ent->action++; - ent->spriteSettings.draw = 1; - InitAnimationForceUpdate(ent, 15); +void Cow_Fusion(CowEntity* this) { + if (super->action == 0) { + super->action++; + super->spriteSettings.draw = 1; + InitAnimationForceUpdate(super, 15); } else { - UpdateAnimationSingleFrame(ent); + UpdateAnimationSingleFrame(super); } } diff --git a/src/npc/cucco.c b/src/npc/cucco.c index 287096078..ab4554495 100644 --- a/src/npc/cucco.c +++ b/src/npc/cucco.c @@ -1,96 +1,108 @@ -#include "npc.h" +/** + * @file cucco.c + * @ingroup NPCs + * + * @brief Cucco NPC + */ +#define NENT_DEPRECATED #include "functions.h" #include "kinstone.h" +#include "npc.h" -void (*const Cucco_Actions[])(Entity*); +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} CuccoEntity; + +void (*const Cucco_Actions[])(CuccoEntity*); const u16 Cucco_Sounds[]; const u16 Cucco_Messages[]; -void sub_0806E4EC(Entity*); +void sub_0806E4EC(CuccoEntity*); void Cucco_ShowMessage(Entity*); void sub_0806E65C(Entity* this); -void Cucco(Entity* this) { - Cucco_Actions[this->action](this); +void Cucco(CuccoEntity* this) { + Cucco_Actions[super->action](this); } -void Cucco_Init(Entity* this) { - this->action++; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableAsMinishFuser(this, this->field_0x68.HALF.LO); - SetDefaultPriority(this, PRIO_MESSAGE); - this->subAction = 0; +void Cucco_Init(CuccoEntity* this) { + super->action++; + this->fusionOffer = GetFusionToOffer(super); + AddInteractableAsMinishFuser(super, this->fusionOffer); + SetDefaultPriority(super, PRIO_MESSAGE); + super->subAction = 0; sub_0806E4EC(this); } -void sub_0806E4EC(Entity* this) { - if (this->subAction == 0) { - this->subAction++; - this->timer = (Random() & 0x1f) + 60; - InitAnimationForceUpdate(this, 0); +void sub_0806E4EC(CuccoEntity* this) { + if (super->subAction == 0) { + super->subAction++; + super->timer = (Random() & 0x1f) + 60; + InitAnimationForceUpdate(super, 0); } - if (--this->timer == 0) { + if (--super->timer == 0) { if ((Random() & 1) != 0) { - this->action = 3; + super->action = 3; } else { - this->action = 2; + super->action = 2; } - this->subAction = 0; + super->subAction = 0; if ((Random() & 1) != 0) { EnqueueSFX(Cucco_Sounds[Random() & 3]); } } - sub_0806E65C(this); - UpdateAnimationSingleFrame(this); + sub_0806E65C(super); + UpdateAnimationSingleFrame(super); } -void Cucco_Fly(Entity* this) { - if (this->subAction == 0) { - this->subAction++; +void Cucco_Fly(CuccoEntity* this) { + if (super->subAction == 0) { + super->subAction++; if (Random() & 1) { - this->spriteSettings.flipX ^= 1; + super->spriteSettings.flipX ^= 1; } - this->timer = (Random() & 1) + 1; - this->zVelocity = Q_16_16(1.5); - InitAnimationForceUpdate(this, 1); + super->timer = (Random() & 1) + 1; + super->zVelocity = Q_16_16(1.5); + InitAnimationForceUpdate(super, 1); } - if (GravityUpdate(this, Q_8_8(40.0)) == 0) { - if (--this->timer == 0) { - this->action = 1; - this->subAction = 0; + if (GravityUpdate(super, Q_8_8(40.0)) == 0) { + if (--super->timer == 0) { + super->action = 1; + super->subAction = 0; } else { - this->zVelocity = Q_16_16(1.5); + super->zVelocity = Q_16_16(1.5); } } - sub_0806E65C(this); - UpdateAnimationSingleFrame(this); + sub_0806E65C(super); + UpdateAnimationSingleFrame(super); } -void Cucco_Idle(Entity* this) { - if (this->subAction == 0) { - this->subAction++; +void Cucco_Idle(CuccoEntity* this) { + if (super->subAction == 0) { + super->subAction++; if (Random() & 1) { - this->spriteSettings.flipX ^= 1; + super->spriteSettings.flipX ^= 1; } - InitAnimationForceUpdate(this, (Random() & 1) + 2); + InitAnimationForceUpdate(super, (Random() & 1) + 2); } - if (this->frame & ANIM_DONE) { - this->action = 1; - this->subAction = 0; + if (super->frame & ANIM_DONE) { + super->action = 1; + super->subAction = 0; } - sub_0806E65C(this); - UpdateAnimationSingleFrame(this); + sub_0806E65C(super); + UpdateAnimationSingleFrame(super); } -void sub_0806E648(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; +void sub_0806E648(CuccoEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; } } @@ -99,7 +111,7 @@ void sub_0806E65C(Entity* this) { if ((gPlayerState.flags & PL_MINISH) != 0) { if (this->interactType == 2) { this->action = 4; - sub_0806F118(this); + InitializeNPCFusion(this); } else { Cucco_ShowMessage(this); } @@ -131,7 +143,7 @@ void Cucco_Fusion(Entity* this) { } } -void (*const Cucco_Actions[])(Entity*) = { +void (*const Cucco_Actions[])(CuccoEntity*) = { Cucco_Init, sub_0806E4EC, Cucco_Fly, Cucco_Idle, sub_0806E648, }; diff --git a/src/npc/cuccoChick.c b/src/npc/cuccoChick.c index 75ccdce38..60ec8829b 100644 --- a/src/npc/cuccoChick.c +++ b/src/npc/cuccoChick.c @@ -1,44 +1,56 @@ -#include "npc.h" +/** + * @file cuccoChick.c + * @ingroup NPCs + * + * @brief Cucco Chick NPC + */ +#define NENT_DEPRECATED #include "functions.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} CuccoChickEntity; -void CuccoChick_Init(Entity*); -void sub_0806E764(Entity*); -void CuccoChick_Fly(Entity*); -void sub_0806E824(Entity*); +void CuccoChick_Init(CuccoChickEntity*); +void sub_0806E764(CuccoChickEntity*); +void CuccoChick_Fly(CuccoChickEntity*); +void sub_0806E824(CuccoChickEntity*); -void sub_0806E838(Entity* this); +void sub_0806E838(CuccoChickEntity* this); -void sub_0806E884(Entity* this); +void sub_0806E884(CuccoChickEntity* this); -void CuccoChick(Entity* this) { - static void (*const CuccoChick_Actions[])(Entity*) = { +void CuccoChick(CuccoChickEntity* this) { + static void (*const CuccoChick_Actions[])(CuccoChickEntity*) = { CuccoChick_Init, sub_0806E764, CuccoChick_Fly, sub_0806E824, }; - CuccoChick_Actions[this->action](this); - sub_0806ED78(this); + CuccoChick_Actions[super->action](this); + sub_0806ED78(super); } -void CuccoChick_Init(Entity* this) { - this->action++; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableAsMinishFuser(this, this->field_0x68.HALF.LO); - SetDefaultPriority(this, PRIO_MESSAGE); - this->subAction = 0; +void CuccoChick_Init(CuccoChickEntity* this) { + super->action++; + this->fusionOffer = GetFusionToOffer(super); + AddInteractableAsMinishFuser(super, this->fusionOffer); + SetDefaultPriority(super, PRIO_MESSAGE); + super->subAction = 0; sub_0806E764(this); } -void sub_0806E764(Entity* this) { - if (this->subAction == 0) { - this->subAction++; - this->timer = (Random() & 0x1f) + 30; - this->frameIndex = 0; +void sub_0806E764(CuccoChickEntity* this) { + if (super->subAction == 0) { + super->subAction++; + super->timer = (Random() & 0x1f) + 30; + super->frameIndex = 0; } - if (--this->timer == 0) { - this->action = 2; - this->subAction = 0; + if (--super->timer == 0) { + super->action = 2; + super->subAction = 0; if ((Random() & 1) != 0) { EnqueueSFX(SFX_VO_CHEEP); } @@ -46,39 +58,39 @@ void sub_0806E764(Entity* this) { sub_0806E838(this); } -void CuccoChick_Fly(Entity* this) { - if (this->subAction == 0) { - this->subAction++; +void CuccoChick_Fly(CuccoChickEntity* this) { + if (super->subAction == 0) { + super->subAction++; if ((Random() & 1) != 0) { - this->spriteSettings.flipX ^= 1; + super->spriteSettings.flipX ^= 1; } - this->timer = (Random() & 3) + 1; - this->zVelocity = Q_16_16(1.0); - this->frameIndex = 1; + super->timer = (Random() & 3) + 1; + super->zVelocity = Q_16_16(1.0); + super->frameIndex = 1; } - if (GravityUpdate(this, Q_8_8(48.0)) == 0) { - if (--this->timer == 0) { - this->action = 1; - this->subAction = 0; + if (GravityUpdate(super, Q_8_8(48.0)) == 0) { + if (--super->timer == 0) { + super->action = 1; + super->subAction = 0; } else { - this->zVelocity = Q_16_16(1.0); + super->zVelocity = Q_16_16(1.0); } } sub_0806E838(this); } -void sub_0806E824(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; +void sub_0806E824(CuccoChickEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; } } -void sub_0806E838(Entity* this) { - if (this->interactType != 0) { +void sub_0806E838(CuccoChickEntity* this) { + if (super->interactType != 0) { if ((gPlayerState.flags & PL_MINISH) != 0) { - if (this->interactType == 2) { - this->action = 3; - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 3; + InitializeNPCFusion(super); } else { sub_0806E884(this); } @@ -86,22 +98,22 @@ void sub_0806E838(Entity* this) { ResetPlayerAnimationAndAction(); } SoundReq(SFX_VO_CHEEP); - this->interactType = 0; + super->interactType = 0; } } -void sub_0806E884(Entity* this) { - MessageNoOverlap(TEXT_INDEX(TEXT_MINISH, 0Xb6), this); +void sub_0806E884(CuccoChickEntity* this) { + MessageNoOverlap(TEXT_INDEX(TEXT_MINISH, 0xB6), super); } -void CuccoChick_Fusion(Entity* this) { - if (this->action == 0) { - this->action++; - this->spriteSettings.draw = 1; - this->frameIndex = 1; +void CuccoChick_Fusion(CuccoChickEntity* this) { + if (super->action == 0) { + super->action++; + super->spriteSettings.draw = 1; + super->frameIndex = 1; } else { - if (GravityUpdate(this, Q_8_8(48.0)) == 0) { - this->zVelocity = Q_16_16(1.0); + if (GravityUpdate(super, Q_8_8(48.0)) == 0) { + super->zVelocity = Q_16_16(1.0); } } } diff --git a/src/npc/dampe.c b/src/npc/dampe.c index fad258931..2426f6f2f 100644 --- a/src/npc/dampe.c +++ b/src/npc/dampe.c @@ -1,11 +1,22 @@ -#include "global.h" +/** + * @file dampe.c + * @ingroup NPCs + * + * @brief Dampe NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" -#include "room.h" #include "flags.h" +#include "item.h" #include "message.h" #include "npc.h" -#include "item.h" +#include "player.h" +#include "room.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} DampeEntity; void Dampe(Entity* this) { switch (this->action) { @@ -13,16 +24,17 @@ void Dampe(Entity* this) { this->action = 1; this->spriteSettings.draw = 1; SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + InitScriptForNPC(this); return; case 1: if (this->interactType == 2) { this->action = 2; this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 4); - sub_0806F118(this); + InitAnimationForceUpdate(this, + GetAnimationStateForDirection4(GetFacingDirection(this, &gPlayerEntity)) + 4); + InitializeNPCFusion(this); } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(this, NULL); } return; case 2: @@ -33,9 +45,9 @@ void Dampe(Entity* this) { } } -void Dampe_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Dampe_MakeInteractable(DampeEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Dampe_Fusion(Entity* this) { diff --git a/src/npc/din.c b/src/npc/din.c index c5608c7ef..ced621416 100644 --- a/src/npc/din.c +++ b/src/npc/din.c @@ -1,30 +1,42 @@ -#include "global.h" +/** + * @file din.c + * @ingroup NPCs + * + * @brief Din NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "npc.h" #include "kinstone.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 animIndex; +} DinEntity; -void Din(Entity* this) { - switch (this->action) { +void Din(DinEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = 1; + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - sub_0806F118(this); - this->field_0x68.HALF.LO = this->animIndex; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitializeNPCFusion(super); + this->animIndex = super->animIndex; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitAnimationForceUpdate(this, this->field_0x68.HALF.LO); + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitAnimationForceUpdate(super, this->animIndex); } break; } diff --git a/src/npc/dog.c b/src/npc/dog.c index 104274199..aa2065d0c 100644 --- a/src/npc/dog.c +++ b/src/npc/dog.c @@ -1,18 +1,37 @@ -#include "entity.h" +/** + * @file dog.c + * @ingroup NPCs + * + * @brief Dog NPC + */ +#define NENT_DEPRECATED #include "collision.h" +#include "entity.h" #include "functions.h" -#include "npc.h" #include "item.h" +#include "npc.h" -void sub_08069FE8(Entity*); -bool32 sub_08069EF0(Entity*); -bool32 sub_08069F90(Entity*); -void sub_08069F6C(Entity*); -void sub_08069D00(Entity*); -void sub_08069CB8(Entity*); -void sub_0806A028(Entity*); -void sub_08069FBC(Entity*); -void sub_0806A080(Entity*); +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u16 unk_68; + /*0x6a*/ u8 unk_6a; + /*0x6b*/ u8 unk_6b; + /*0x6c*/ u16 unk_6c; + /*0x6e*/ u16 unk_6e; + /*0x70*/ u16 unk_70; + /*0x72*/ u16 unk_72; + /*0x74*/ u8 unk_74; +} DogEntity; + +void sub_08069FE8(DogEntity*); +bool32 sub_08069EF0(DogEntity*); +bool32 sub_08069F90(DogEntity*); +void sub_08069F6C(DogEntity*); +void sub_08069D00(DogEntity*); +void sub_08069CB8(DogEntity*); +void sub_0806A028(DogEntity*); +void sub_08069FBC(DogEntity*); +void sub_0806A080(DogEntity*); const SpriteLoadData gUnk_08111D58[] = { #ifdef EU @@ -23,15 +42,15 @@ const SpriteLoadData gUnk_08111D58[] = { { 4, 68, 4 }, { 7172, 68, 4 }, { 0, 0, 0 }, { 83, 69, 4 }, { 7251, 69, 4 }, { 0, 0, 0 }, }; -void sub_08069B44(Entity*); -void sub_08069C40(Entity*); -void sub_08069D54(Entity*); -void sub_08069DF8(Entity*); -void sub_08069E44(Entity*); -void sub_08069E50(Entity*); -void sub_08069ECC(Entity*); -void sub_08069EE0(Entity*); -void (*const gUnk_08111D88[])(Entity*) = { +void sub_08069B44(DogEntity*); +void sub_08069C40(DogEntity*); +void sub_08069D54(DogEntity*); +void sub_08069DF8(DogEntity*); +void sub_08069E44(DogEntity*); +void sub_08069E50(DogEntity*); +void sub_08069ECC(DogEntity*); +void sub_08069EE0(DogEntity*); +void (*const gUnk_08111D88[])(DogEntity*) = { sub_08069B44, sub_08069C40, sub_08069D54, sub_08069DF8, sub_08069E44, sub_08069E50, sub_08069ECC, sub_08069EE0, }; @@ -175,254 +194,254 @@ const u16 gUnk_08111FD8[] = { TEXT_INDEX(TEXT_TOWN8, 0x7), TEXT_INDEX(TEXT_TOWN8, 0x8), TEXT_INDEX(TEXT_TOWN8, 0x9), TEXT_INDEX(TEXT_TOWN8, 0x11), TEXT_INDEX(TEXT_TOWN8, 0x3), }; -void Dog(Entity* this) { - gUnk_08111D88[this->action](this); - sub_0806ED78(this); +void Dog(DogEntity* this) { + gUnk_08111D88[super->action](this); + sub_0806ED78(super); sub_08069FE8(this); } -void sub_08069B44(Entity* this) { +void sub_08069B44(DogEntity* this) { u32 uVar2; u32 sVar3; u32 uVar4; u32 uVar5; if (sub_08069EF0(this)) { - uVar5 = sub_0805ACC0(this); + uVar5 = sub_0805ACC0(super); if (uVar5 == 0) { - sVar3 = this->x.HALF.HI; - uVar2 = this->y.HALF.HI; + sVar3 = super->x.HALF.HI; + uVar2 = super->y.HALF.HI; } else { sVar3 = uVar5 >> 0x10; uVar2 = uVar5; } - uVar4 = this->timer == 0 ? 0x20 : this->timer; - - this->field_0x6e.HWORD = sVar3 - uVar4; - this->field_0x6c.HWORD = sVar3 + uVar4; - this->field_0x70.HALF.LO = uVar2 - 8; - this->field_0x70.HALF.HI = uVar2 + 8; - this->speed = 0x100; - this->timer = 30; - this->animationState = 2; - this->field_0x6a.HALF.LO = 0xff; - this->field_0x74.HALF.LO = GetFusionToOffer(this); - SetDefaultPriority(this, PRIO_MESSAGE); - InitAnimationForceUpdate(this, 10); - if ((this->flags & ENT_SCRIPTED) != 0) { - sub_0807DD50(this); + uVar4 = super->timer == 0 ? 0x20 : super->timer; + + this->unk_6e = sVar3 - uVar4; + this->unk_6c = sVar3 + uVar4; + this->unk_70 = uVar2 - 8; + this->unk_72 = uVar2 + 8; + super->speed = 0x100; + super->timer = 30; + super->animationState = 2; + this->unk_6a = 0xff; + this->unk_74 = GetFusionToOffer(super); + SetDefaultPriority(super, PRIO_MESSAGE); + InitAnimationForceUpdate(super, 10); + if ((super->flags & ENT_SCRIPTED) != 0) { + InitScriptForNPC(super); } - if (((this->type == 0) && ((gPlayerState.flags & PL_MINISH) == 0)) && + if (((super->type == 0) && ((gPlayerState.flags & PL_MINISH) == 0)) && (GetInventoryValue(ITEM_QST_DOGFOOD) != 2)) { - this->action = 4; + super->action = 4; } - if ((this->type == 2) && (CheckLocalFlag(MACHI_02_DOG) == 0)) { - SetTile(0x4072, TILE(this->x.HALF.HI, this->y.HALF.HI - 8), this->collisionLayer); + if ((super->type == 2) && (CheckLocalFlag(MACHI_02_DOG) == 0)) { + SetTile(0x4072, TILE(super->x.HALF.HI, super->y.HALF.HI - 8), super->collisionLayer); } } } -void sub_08069C40(Entity* this) { - UpdateAnimationSingleFrame(this); +void sub_08069C40(DogEntity* this) { + UpdateAnimationSingleFrame(super); if (sub_08069F90(this)) { if ((gPlayerState.flags & PL_MINISH) != 0) { sub_08069CB8(this); } else { - this->animationState = GetAnimationState(this); + super->animationState = GetAnimationState(super); sub_08069D00(this); } - this->timer = 30; + super->timer = 30; } else { - this->timer--; - if (this->timer == 0) { - this->action = 2; - this->timer = (Random() & 0x1f) + 30; - this->direction = gUnk_08111DA8[Random() & 7]; + super->timer--; + if (super->timer == 0) { + super->action = 2; + super->timer = (Random() & 0x1f) + 30; + super->direction = gUnk_08111DA8[Random() & 7]; sub_08069F6C(this); } } } -void sub_08069CB8(Entity* this) { +void sub_08069CB8(DogEntity* this) { u32 direction; u32 animState; - direction = GetFacingDirection(this, &gPlayerEntity); - animState = gUnk_08111DB0[direction + this->animationState * 0x20]; - this->animationState = animState >> 6; - this->field_0x6a.HALF.HI = animState & 0x3f; + direction = GetFacingDirection(super, &gPlayerEntity); + animState = gUnk_08111DB0[direction + super->animationState * 0x20]; + super->animationState = animState >> 6; + this->unk_6b = animState & 0x3f; sub_0806A028(this); - if (this->animIndex != this->field_0x6a.HALF.HI) { - InitAnimationForceUpdate(this, this->field_0x6a.HALF.HI); + if (super->animIndex != this->unk_6b) { + InitAnimationForceUpdate(super, this->unk_6b); } } -void sub_08069D00(Entity* this) { - this->field_0x6a.HALF.HI = 8; +void sub_08069D00(DogEntity* this) { + this->unk_6b = 8; sub_0806A028(this); - if (0x1f < this->animIndex) { - if ((this->frame & ANIM_DONE) == 0) { + if (0x1f < super->animIndex) { + if ((super->frame & ANIM_DONE) == 0) { return; } - this->field_0x6a.HALF.HI = 8; + this->unk_6b = 8; } if ((Random() & 0x1ff) < 3) { sub_08069FBC(this); } - if (this->animIndex != this->field_0x6a.HALF.HI + this->animationState) { - InitAnimationForceUpdate(this, this->field_0x6a.HALF.HI + this->animationState); + if (super->animIndex != this->unk_6b + super->animationState) { + InitAnimationForceUpdate(super, this->unk_6b + super->animationState); } } -void sub_08069D54(Entity* this) { +void sub_08069D54(DogEntity* this) { u16 collisions; if (!sub_08069F90(this)) { - this->timer--; - if (this->timer != 0) { - UpdateAnimationSingleFrame(this); - ProcessMovement0(this); - collisions = this->collisions; - - if (this->x.HALF.HI < this->field_0x6e.HWORD) { - this->x.HALF.HI = this->field_0x6e.HWORD + 1; + super->timer--; + if (super->timer != 0) { + UpdateAnimationSingleFrame(super); + ProcessMovement0(super); + collisions = super->collisions; + + if (super->x.HALF.HI < this->unk_6e) { + super->x.HALF.HI = this->unk_6e + 1; collisions = COL_WEST_ANY; - } else if (this->x.HALF.HI > this->field_0x6c.HWORD) { - this->x.HALF.HI = this->field_0x6c.HWORD - 1; + } else if (super->x.HALF.HI > this->unk_6c) { + super->x.HALF.HI = this->unk_6c - 1; collisions = COL_EAST_ANY; } - if (this->y.HALF.HI < this->field_0x70.HALF_U.LO) { - this->y.HALF.HI = this->field_0x70.HALF_U.LO + 1; + if (super->y.HALF.HI < this->unk_70) { + super->y.HALF.HI = this->unk_70 + 1; collisions = COL_NORTH_ANY; - } else if (this->y.HALF.HI > this->field_0x70.HALF_U.HI) { - this->y.HALF.HI = this->field_0x70.HALF_U.HI - 1; + } else if (super->y.HALF.HI > this->unk_72) { + super->y.HALF.HI = this->unk_72 - 1; collisions = COL_SOUTH_ANY; } - sub_0800417E(this, collisions); + sub_0800417E(super, collisions); sub_08069F6C(this); return; } } if (sub_08069F90(this)) { - this->action = 1; + super->action = 1; } else { - this->action = 3; + super->action = 3; } - this->timer = (Random() & 0x1f) + 30; + super->timer = (Random() & 0x1f) + 30; } -void sub_08069DF8(Entity* this) { - UpdateAnimationSingleFrame(this); +void sub_08069DF8(DogEntity* this) { + UpdateAnimationSingleFrame(super); if (sub_08069F90(this)) { - this->action = 1; + super->action = 1; } else { - this->timer--; - if (this->timer != 0) { + super->timer--; + if (super->timer != 0) { sub_08069D00(this); return; } if ((Random() & 0xff) < 0x30) { - this->action = 2; + super->action = 2; } else { - this->action = 3; + super->action = 3; } } - this->timer = (Random() & 0x1f) + 30; + super->timer = (Random() & 0x1f) + 30; } -void sub_08069E44(Entity* this) { - sub_0807DD94(this, NULL); +void sub_08069E44(DogEntity* this) { + ExecuteScriptAndHandleAnimation(super, NULL); } -void sub_08069E50(Entity* this) { - this->animationState = GetAnimationState(this); - this->field_0x6a.HALF.HI = 8; +void sub_08069E50(DogEntity* this) { + super->animationState = GetAnimationState(super); + this->unk_6b = 8; sub_0806A028(this); - UpdateAnimationSingleFrame(this); - if (this->animIndex > 0x1f) { - if ((this->frame & ANIM_DONE) == 0) { + UpdateAnimationSingleFrame(super); + if (super->animIndex > 0x1f) { + if ((super->frame & ANIM_DONE) == 0) { return; } - this->field_0x6a.HALF.HI = 8; + this->unk_6b = 8; } sub_08069FBC(this); - if (this->animIndex != this->field_0x6a.HALF.HI + this->animationState) { - InitAnimationForceUpdate(this, this->field_0x6a.HALF.HI + this->animationState); + if (super->animIndex != this->unk_6b + super->animationState) { + InitAnimationForceUpdate(super, this->unk_6b + super->animationState); } if (GetInventoryValue(ITEM_QST_DOGFOOD) == 2) { - this->action = 7; - InitAnimationForceUpdate(this, 0x29); - RemoveInteractableObject(this); + super->action = 7; + InitAnimationForceUpdate(super, 0x29); + RemoveInteractableObject(super); EnqueueSFX(SFX_VO_DOG); EnqueueSFX(SFX_TASK_COMPLETE); } } -void sub_08069ECC(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { +void sub_08069ECC(DogEntity* this) { + if (UpdateFuseInteraction(super) != 0) { #ifdef EU if (GetInventoryValue(ITEM_QST_DOGFOOD) != 2) { - this->action = 5; + super->action = 5; } else { - this->action = 1; + super->action = 1; } #else - this->action = 1; + super->action = 1; #endif } } -void sub_08069EE0(Entity* this) { - UpdateAnimationSingleFrame(this); +void sub_08069EE0(DogEntity* this) { + UpdateAnimationSingleFrame(super); } -void sub_08069EE8(Entity* this) { - this->action = 5; +void sub_08069EE8(DogEntity* this) { + super->action = 5; } -bool32 sub_08069EF0(Entity* this) { - if (!LoadExtraSpriteData(this, &gUnk_08111D58[this->type * 3])) { +bool32 sub_08069EF0(DogEntity* this) { + if (!LoadExtraSpriteData(super, &gUnk_08111D58[super->type * 3])) { return FALSE; } - this->action = 1; - this->field_0x68.HWORD = gUnk_08111E30[this->type]; + super->action = 1; + this->unk_68 = gUnk_08111E30[super->type]; return TRUE; } -void Dog_Head(Entity* this) { +void Dog_Head(DogEntity* this) { u32 frame; - frame = this->frame & ~ANIM_DONE; + frame = super->frame & ~ANIM_DONE; if (frame != 0) { - frame += this->field_0x68.HWORD; + frame += this->unk_68; } - SetExtraSpriteFrame(this, 0, frame - 1); - SetExtraSpriteFrame(this, 1, this->frameIndex); - SetSpriteSubEntryOffsetData1(this, 1, 0); - sub_0807000C(this); + SetExtraSpriteFrame(super, 0, frame - 1); + SetExtraSpriteFrame(super, 1, super->frameIndex); + SetSpriteSubEntryOffsetData1(super, 1, 0); + sub_0807000C(super); } -void sub_08069F6C(Entity* this) { - this->animationState = sub_0806F5A4(this->direction); - if (this->animationState + 4 != this->animIndex) { - InitAnimationForceUpdate(this, this->animationState + 4); +void sub_08069F6C(DogEntity* this) { + super->animationState = GetAnimationStateForDirection4(super->direction); + if (super->animationState + 4 != super->animIndex) { + InitAnimationForceUpdate(super, super->animationState + 4); } } -bool32 sub_08069F90(Entity* this) { - if ((this->type == 2) && (CheckLocalFlag(MACHI_02_DOG) == 0)) { +bool32 sub_08069F90(DogEntity* this) { + if ((super->type == 2) && (CheckLocalFlag(MACHI_02_DOG) == 0)) { return TRUE; } else { - return EntityInRectRadius(this, &gPlayerEntity, 0x14, 0x14); + return EntityInRectRadius(super, &gPlayerEntity, 0x14, 0x14); } } -void sub_08069FBC(Entity* this) { +void sub_08069FBC(DogEntity* this) { u32 tmp = (gPlayerState.flags & PL_MINISH) != 0 ? 0x24 : 0x20; - if ((this->animationState == 1) || (this->animationState == 3)) { - this->field_0x6a.HALF.HI = tmp; + if ((super->animationState == 1) || (super->animationState == 3)) { + this->unk_6b = tmp; } } -void sub_08069FE8(Entity* this) { +void sub_08069FE8(DogEntity* this) { u32 tmp; if ((gPlayerState.flags & PL_MINISH) != 0) { tmp = TRUE; @@ -430,22 +449,22 @@ void sub_08069FE8(Entity* this) { tmp = FALSE; } - if (tmp != this->field_0x6a.HALF.LO) { + if (tmp != this->unk_6a) { if (tmp == 0) { - AddInteractableWhenBigObject(this); + AddInteractableWhenBigObject(super); } else { - AddInteractableAsMinishFuser(this, this->field_0x74.HALF.LO); + AddInteractableAsMinishFuser(super, this->unk_74); } } - this->field_0x6a.HALF.LO = tmp; + this->unk_6a = tmp; } -void sub_0806A028(Entity* this) { - if (this->interactType != 0) { +void sub_0806A028(DogEntity* this) { + if (super->interactType != 0) { if ((gPlayerState.flags & PL_MINISH) != 0) { - if (this->interactType == 2) { - this->action = 6; - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 6; + InitializeNPCFusion(super); } else { sub_0806A080(this); } @@ -455,12 +474,12 @@ void sub_0806A028(Entity* this) { SoundReq(SFX_VO_DOG); ResetPlayerAnimationAndAction(); } - this->interactType = 0; + super->interactType = 0; } } -void sub_0806A080(Entity* this) { - ShowNPCDialogue(this, &(gUnk_08111E34[this->type2][gSave.global_progress])); +void sub_0806A080(DogEntity* this) { + ShowNPCDialogue(super, &(gUnk_08111E34[super->type2][gSave.global_progress])); } void sub_0806A0A4(Entity* this) { @@ -501,15 +520,15 @@ void sub_0806A144(Entity* this) { MessageNoOverlap(gUnk_08111FD8[dialog], this); } -void Dog_Fusion(Entity* this) { - if (this->action == 0) { +void Dog_Fusion(DogEntity* this) { + if (super->action == 0) { if (sub_08069EF0(this)) { - this->action++; - this->spriteSettings.draw = 1; - SetDefaultPriority(this, PRIO_MESSAGE); - InitializeAnimation(this, 0x23); + super->action++; + super->spriteSettings.draw = 1; + SetDefaultPriority(super, PRIO_MESSAGE); + InitializeAnimation(super, 0x23); } } else { - GetNextFrame(this); + GetNextFrame(super); } } diff --git a/src/npc/drLeft.c b/src/npc/drLeft.c index aef5ecc4a..f65194078 100644 --- a/src/npc/drLeft.c +++ b/src/npc/drLeft.c @@ -1,6 +1,13 @@ -#include "npc.h" +/** + * @file drLeft.c + * @ingroup NPCs + * + * @brief Dr Left NPC + */ +#define NENT_DEPRECATED #include "functions.h" #include "item.h" +#include "npc.h" void sub_0806BFD8(Entity* this); @@ -9,7 +16,7 @@ void DrLeft(Entity* this) { if (this->action == 0) { this->action++; SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + InitScriptForNPC(this); } ExecuteScriptForEntity(this, NULL); HandleEntity0x82Actions(this); diff --git a/src/npc/emma.c b/src/npc/emma.c index 0f0f1c36f..098d61b7d 100644 --- a/src/npc/emma.c +++ b/src/npc/emma.c @@ -1,3 +1,10 @@ +/** + * @file emma.c + * @ingroup NPCs + * + * @brief Emma NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "functions.h" #include "screenTransitions.h" @@ -7,9 +14,9 @@ void Emma(Entity* this) { if (this->action == 0) { this->action++; SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + InitScriptForNPC(this); } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(this, NULL); } } diff --git a/src/npc/epona.c b/src/npc/epona.c index b06a7777f..e165faf94 100644 --- a/src/npc/epona.c +++ b/src/npc/epona.c @@ -1,68 +1,80 @@ -#include "global.h" -#include "sound.h" +/** + * @file epona.c + * @ingroup NPCs + * + * @brief Epona NPC + */ +#define NENT_DEPRECATED #include "entity.h" +#include "functions.h" #include "message.h" #include "npc.h" -#include "functions.h" +#include "sound.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unk_69; +} EponaEntity; -void sub_08065A64(Entity* this); -void sub_08065AA4(Entity*); -void sub_080659B8(Entity*); -void sub_080659F0(Entity*); -void sub_08065A00(Entity*); -void sub_08065A10(Entity*); -void sub_08065A34(Entity*); +void sub_08065A64(EponaEntity* this); +void sub_08065AA4(EponaEntity* this); +void sub_080659B8(EponaEntity* this); +void sub_080659F0(EponaEntity* this); +void sub_08065A00(EponaEntity* this); +void sub_08065A10(EponaEntity* this); +void sub_08065A34(EponaEntity* this); -void Epona(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void Epona(EponaEntity* this) { + static void (*const actionFuncs[])(EponaEntity*) = { sub_080659B8, sub_080659F0, sub_08065A00, sub_08065A10, sub_08065A34, }; - actionFuncs[this->action](this); + actionFuncs[super->action](this); sub_08065A64(this); - sub_0806ED78(this); + sub_0806ED78(super); } -void sub_080659B8(Entity* this) { - this->action = 1; - this->spriteSettings.draw = 1; - this->animationState = 6; - this->field_0x68.HALF.HI = -1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - InitAnimationForceUpdate(this, this->animationState / 2); +void sub_080659B8(EponaEntity* this) { + super->action = 1; + super->spriteSettings.draw = 1; + super->animationState = 6; + this->unk_69 = -1; + this->fusionOffer = GetFusionToOffer(super); + InitAnimationForceUpdate(super, super->animationState / 2); } -void sub_080659F0(Entity* this) { - UpdateAnimationSingleFrame(this); +void sub_080659F0(EponaEntity* this) { + UpdateAnimationSingleFrame(super); sub_08065AA4(this); } -void sub_08065A00(Entity* this) { - UpdateAnimationSingleFrame(this); +void sub_08065A00(EponaEntity* this) { + UpdateAnimationSingleFrame(super); sub_08065AA4(this); } -void sub_08065A10(Entity* this) { +void sub_08065A10(EponaEntity* this) { if ((gMessage.doTextBox & 0x7F) == 0) { - this->action = 1; - InitAnimationForceUpdate(this, this->animationState / 2); + super->action = 1; + InitAnimationForceUpdate(super, super->animationState / 2); } } -void sub_08065A34(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitAnimationForceUpdate(this, this->animationState / 2); +void sub_08065A34(EponaEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitAnimationForceUpdate(super, super->animationState / 2); } } -void sub_08065A50(Entity* this) { +void sub_08065A50(EponaEntity* this) { static const Dialog typeDialogs[] = { { 0, 0, DIALOG_MINISH, 1, { TEXT_INDEX(TEXT_LON_LON, 0X17), TEXT_INDEX(TEXT_TINGLE, 0x3c) } }, }; - ShowNPCDialogue(this, &typeDialogs[this->type]); + ShowNPCDialogue(super, &typeDialogs[super->type]); } -void sub_08065A64(Entity* this) { +void sub_08065A64(EponaEntity* this) { u32 uVar2; if ((gPlayerState.flags & PL_MINISH) != 0) { @@ -71,43 +83,43 @@ void sub_08065A64(Entity* this) { uVar2 = FALSE; } - if (uVar2 != this->field_0x68.HALF.HI) { + if (uVar2 != this->unk_69) { if (uVar2 == 0) { - AddInteractableWhenBigObject(this); + AddInteractableWhenBigObject(super); } else { - AddInteractableAsMinishFuser(this, this->field_0x68.HALF.LO); + AddInteractableAsMinishFuser(super, this->fusionOffer); } } - this->field_0x68.HALF.HI = uVar2; + this->unk_69 = uVar2; } -void sub_08065AA4(Entity* this) { - if (this->interactType != 0) { +void sub_08065AA4(EponaEntity* this) { + if (super->interactType != 0) { if (gPlayerState.flags & PL_MINISH) { - if (this->interactType == 2) { - this->action = 4; - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 4; + InitializeNPCFusion(super); } else { - this->action = 3; - SetDefaultPriority(this, PRIO_MESSAGE); + super->action = 3; + SetDefaultPriority(super, PRIO_MESSAGE); sub_08065A50(this); } - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + InitAnimationForceUpdate(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } else { sub_08065A50(this); ResetPlayerAnimationAndAction(); } SoundReq(SFX_VO_EPONA); - this->interactType = 0; + super->interactType = 0; } } -void Epona_Fusion(Entity* this) { - if (this->action == 0) { - this->action++; - this->spriteSettings.draw = 1; - InitAnimationForceUpdate(this, 7); +void Epona_Fusion(EponaEntity* this) { + if (super->action == 0) { + super->action++; + super->spriteSettings.draw = 1; + InitAnimationForceUpdate(super, 7); } else { - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } } diff --git a/src/npc/ezlo.c b/src/npc/ezlo.c index 307ec5500..453681475 100644 --- a/src/npc/ezlo.c +++ b/src/npc/ezlo.c @@ -1,3 +1,10 @@ +/** + * @file ezlo.c + * @ingroup NPCs + * + * @brief Ezlo NPC + */ +#define NENT_DEPRECATED #include "npc.h" const u8 gUnk_08114134[]; @@ -8,7 +15,7 @@ void Ezlo(Entity* this) { if (this->action == 0) { this->action++; SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + InitScriptForNPC(this); } ExecuteScriptForEntity(this, NULL); HandleEntity0x82Actions(this); diff --git a/src/npc/farmers.c b/src/npc/farmers.c index d2c4e2fc7..7b9e10366 100644 --- a/src/npc/farmers.c +++ b/src/npc/farmers.c @@ -1,7 +1,14 @@ +/** + * @file farmers.c + * @ingroup NPCs + * + * @brief Farmers NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "script.h" #include "functions.h" #include "npc.h" +#include "script.h" static const SpriteLoadData gUnk_08113140[] = { { 0xf7, 0x48, 0x4 }, { 0x40f7, 0x48, 0x4 }, { 0, 0, 0 }, { 0xf8, 0x49, 0x4 }, { 0x40f8, 0x49, 0x4 }, { 0, 0, 0 }, diff --git a/src/npc/farore.c b/src/npc/farore.c index c802bf6f8..f65a757d9 100644 --- a/src/npc/farore.c +++ b/src/npc/farore.c @@ -1,30 +1,42 @@ -#include "global.h" +/** + * @file farore.c + * @ingroup NPCs + * + * @brief Farore NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "npc.h" #include "kinstone.h" -void Farore(Entity* this) { - switch (this->action) { +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 animIndex; +} FaroreEntity; + +void Farore(FaroreEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = 1; + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - sub_0806F118(this); - this->field_0x68.HALF.LO = this->animIndex; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitializeNPCFusion(super); + this->animIndex = super->animIndex; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitAnimationForceUpdate(this, this->field_0x68.HALF.LO); + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitAnimationForceUpdate(super, this->animIndex); } break; } diff --git a/src/npc/festari.c b/src/npc/festari.c index f9e0cb578..0bcc639ef 100644 --- a/src/npc/festari.c +++ b/src/npc/festari.c @@ -1,79 +1,94 @@ -#include "global.h" +/** + * @file festari.c + * @ingroup NPCs + * + * @brief Festari NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "functions.h" #include "npc.h" -void sub_0805FF2C(Entity*, ScriptExecutionContext*); -void sub_0805FE10(Entity* this); -void sub_0805FE48(Entity* this); -void sub_0805FF18(Entity* this); +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unused[23]; + /*0x80*/ u16 unk_80; + /*0x82*/ u16 unk_82; + /*0x84*/ ScriptExecutionContext* context; +} FestariEntity; -void Festari(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void sub_0805FF2C(FestariEntity* this, ScriptExecutionContext* context); +void sub_0805FE10(FestariEntity* this); +void sub_0805FE48(FestariEntity* this); +void sub_0805FF18(FestariEntity* this); + +void Festari(FestariEntity* this) { + static void (*const actionFuncs[])(FestariEntity*) = { sub_0805FE10, sub_0805FE48, sub_0805FF18, }; - actionFuncs[this->action](this); + actionFuncs[super->action](this); } -void sub_0805FE10(Entity* this) { - this->action = 1; - this->spriteSettings.draw = TRUE; - SetDefaultPriority(this, PRIO_MESSAGE); - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); - sub_0807DD50(this); +void sub_0805FE10(FestariEntity* this) { + super->action = 1; + super->spriteSettings.draw = TRUE; + SetDefaultPriority(super, PRIO_MESSAGE); + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); + InitScriptForNPC(super); } -void sub_0805FE48(Entity* this) { +void sub_0805FE48(FestariEntity* this) { u32 uVar4; - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitAnimationForceUpdate(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - ExecuteScript(this, *(ScriptExecutionContext**)&this->cutsceneBeh); - sub_0805FF2C(this, *(ScriptExecutionContext**)&this->cutsceneBeh); - uVar4 = this->field_0x80.HWORD; + ExecuteScript(super, this->context); + sub_0805FF2C(this, this->context); + uVar4 = this->unk_80; if (uVar4 < 8) { - if ((this->field_0x82.HWORD & 1) != 0) { - uVar4 = (uVar4 & 0xfc) + (this->subtimer >> 1); + if ((this->unk_82 & 1) != 0) { + uVar4 = (uVar4 & 0xfc) + (super->subtimer >> 1); } else { - uVar4 = (uVar4 & 0xfc) + (this->animationState >> 1); - this->subtimer = this->animationState; + uVar4 = (uVar4 & 0xfc) + (super->animationState >> 1); + super->subtimer = super->animationState; } } - if (uVar4 != this->animIndex) { - InitAnimationForceUpdate(this, uVar4); + if (uVar4 != super->animIndex) { + InitAnimationForceUpdate(super, uVar4); } - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); - if (this->frame & ANIM_DONE) { - switch (this->animIndex) { + if (super->frame & ANIM_DONE) { + switch (super->animIndex) { case 8: case 10: case 11: case 12: - this->field_0x80.HWORD = 0; + this->unk_80 = 0; break; } } - if ((this->field_0x82.HWORD & (~this->field_0x82.HWORD + 1)) == 2) { - sub_0806ED78(this); + if ((this->unk_82 & (~this->unk_82 + 1)) == 2) { + sub_0806ED78(super); } } } -void sub_0805FF18(Entity* this) { - if (UpdateFuseInteraction(this)) { - this->action = 1; +void sub_0805FF18(FestariEntity* this) { + if (UpdateFuseInteraction(super)) { + super->action = 1; } } -void sub_0805FF2C(Entity* this, ScriptExecutionContext* context) { +void sub_0805FF2C(FestariEntity* this, ScriptExecutionContext* context) { u32 actions; u32 bit; @@ -86,35 +101,35 @@ void sub_0805FF2C(Entity* this, ScriptExecutionContext* context) { actions ^= bit; switch (bit) { case 4: - this->field_0x80.HWORD = 9; + this->unk_80 = 9; break; case 0x200000: - this->field_0x80.HWORD = 10; + this->unk_80 = 10; break; case 0x400000: - if (this->animationState == 2) { - this->field_0x80.HWORD = 0xb; + if (super->animationState == 2) { + this->unk_80 = 0xb; } else { - this->field_0x80.HWORD = 0xc; + this->unk_80 = 0xc; } break; case 0x100000: - this->field_0x80.HWORD = 8; + this->unk_80 = 8; break; } } } - HandlePostScriptActions(this, context); + HandlePostScriptActions(super, context); } -void Festari_Fusion(Entity* this) { - if (this->action == 0) { - this->action++; - this->spriteSettings.draw = 1; - SetDefaultPriority(this, PRIO_MESSAGE); - InitAnimationForceUpdate(this, 8); +void Festari_Fusion(FestariEntity* this) { + if (super->action == 0) { + super->action++; + super->spriteSettings.draw = 1; + SetDefaultPriority(super, PRIO_MESSAGE); + InitAnimationForceUpdate(super, 8); } else { - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } } diff --git a/src/npc/forestMinish.c b/src/npc/forestMinish.c index b002d976d..2392515b6 100644 --- a/src/npc/forestMinish.c +++ b/src/npc/forestMinish.c @@ -1,3 +1,10 @@ +/** + * @file forestMinish.c + * @ingroup NPCs + * + * @brief Forest Minish NPC + */ +#define NENT_DEPRECATED #include "functions.h" #include "item.h" #include "kinstone.h" @@ -5,6 +12,15 @@ #include "object.h" #include "playeritem.h" #include "structures.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; + /*0x6a*/ u8 unused[22]; + /*0x80*/ u16 unk_80; + /*0x82*/ u16 unk_82; + /*0x84*/ ScriptExecutionContext* context; +} ForestMinishEntity; const FrameStruct gUnk_08109C98[] = { { 36, 26 }, { 37, 26 }, { 38, 26 }, { 39, 155 }, { 40, 155 }, { 41, 155 }, { 42, 155 }, { 43, 152 }, @@ -499,44 +515,45 @@ const u16 gUnk_0810A362[] = { TEXT_INDEX(TEXT_BELARI, 0x8), }; -static void sub_080600F0(Entity* this); +static void sub_080600F0(ForestMinishEntity* this); +extern void sub_08060158(ForestMinishEntity* this); -void ForestMinish(Entity* this) { - switch (this->action) { +void ForestMinish(ForestMinishEntity* this) { + switch (super->action) { case 0: - if (LoadExtraSpriteData(this, gUnk_0810A348)) { - this->action = 1; - this->spriteSettings.draw = TRUE; - this->field_0x68.HALF.HI = this->animationState = this->timer << 1; - this->timer = 0; - SetDefaultPriority(this, PRIO_MESSAGE); - StartCutscene(this, (u16*)gUnk_08109D18[this->type2]); - sub_0807DD50(this); + if (LoadExtraSpriteData(super, gUnk_0810A348)) { + super->action = 1; + super->spriteSettings.draw = TRUE; + this->animIndex = super->animationState = super->timer << 1; + super->timer = 0; + SetDefaultPriority(super, PRIO_MESSAGE); + StartCutscene(super, (u16*)gUnk_08109D18[super->type2]); + InitScriptForNPC(super); } break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - if (this->frameDuration != 0xf0) { + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + if (super->frameDuration != 0xf0) { sub_080600F0(this); } } break; case 2: - if (UpdateFuseInteraction(this)) { - this->action = 1; + if (UpdateFuseInteraction(super)) { + super->action = 1; } } } -void ForestMinish_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void ForestMinish_MakeInteractable(ForestMinishEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void ForestMinish_Head(Entity* this) { @@ -555,64 +572,64 @@ void ForestMinish_Head(Entity* this) { sub_0807000C(this); } -static void sub_080600F0(Entity* this) { +static void sub_080600F0(ForestMinishEntity* this) { u32 uVar1; u32 uVar2; - uVar2 = this->field_0x80.HWORD; - if (this->field_0x80.HWORD < 8) { - if ((this->field_0x82.HWORD & 1) != 0) { - uVar2 = (uVar2 & 0xfc) + (this->subtimer >> 1); + uVar2 = this->unk_80; + if (this->unk_80 < 8) { + if ((this->unk_82 & 1) != 0) { + uVar2 = (uVar2 & 0xfc) + (super->subtimer >> 1); } else { - uVar2 = (uVar2 & 0xfc) + (this->animationState >> 1); - this->subtimer = this->animationState; + uVar2 = (uVar2 & 0xfc) + (super->animationState >> 1); + super->subtimer = super->animationState; } } - if (uVar2 != this->animIndex) { - InitAnimationForceUpdate(this, uVar2); + if (uVar2 != super->animIndex) { + InitAnimationForceUpdate(super, uVar2); } - if ((this->field_0x82.HWORD & 4) != 0) { + if ((this->unk_82 & 4) != 0) { uVar1 = 2; } else { uVar1 = 1; } - sub_080042BA(this, uVar1); + sub_080042BA(super, uVar1); } -void sub_0806014C(Entity* this) { - this->timer = 0; +void sub_0806014C(ForestMinishEntity* this) { + super->timer = 0; sub_08060158(this); } -void sub_08060158(Entity* this) { +void sub_08060158(ForestMinishEntity* this) { int index; const FrameStruct* idx3; u8 tmp1, tmp2; - if (this->timer) { - this->timer--; + if (super->timer) { + super->timer--; } else { - this->timer = 2; - index = GetFacingDirectionInRectRadius(this, 0x20, 0x20); + super->timer = 2; + index = GetFacingDirectionInRectRadius(super, 0x20, 0x20); if (index < 0) { - int state = this->field_0x68.HALF.HI; - this->animationState = state; + int state = this->animIndex; + super->animationState = state; index = state * 4; } - idx3 = gUnk_08109C98 + (this->animationState / 2) * 0x10 + (index >> 1); + idx3 = gUnk_08109C98 + (super->animationState / 2) * 0x10 + (index >> 1); tmp1 = idx3->frame; tmp2 = idx3->frameIndex; if (tmp2 & 0x80) { - this->animationState = sub_0806F5B0(index); + super->animationState = GetAnimationStateForDirection8(index); } tmp2 &= ~0x80; - this->frame = tmp1; - this->frameIndex = tmp2; - this->frameSpriteSettings = 1; - this->animIndex = 0; - this->frameDuration = 0xf0; + super->frame = tmp1; + super->frameIndex = tmp2; + super->frameSpriteSettings = 1; + super->animIndex = 0; + super->frameDuration = 0xf0; } } diff --git a/src/npc/fusionMenuNPC.c b/src/npc/fusionMenuNPC.c index 01f5c1113..01d970e37 100644 --- a/src/npc/fusionMenuNPC.c +++ b/src/npc/fusionMenuNPC.c @@ -1,4 +1,12 @@ -#include "global.h" +/** + * @file fusionMenuNPC.c + * @ingroup NPCs + * + * @brief Fusion Menu NPC + * + * Representation for the NPCs in the fusion menu. + */ +#define NENT_DEPRECATED #include "entity.h" #include "npc.h" diff --git a/src/npc/gentari.c b/src/npc/gentari.c index d2d360280..331774152 100644 --- a/src/npc/gentari.c +++ b/src/npc/gentari.c @@ -1,30 +1,42 @@ -#include "global.h" +/** + * @file gentari.c + * @ingroup NPCs + * + * @brief Gentari NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "npc.h" -void Gentari(Entity* this) { - switch (this->action) { +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} GentariEntity; + +void Gentari(GentariEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = TRUE; - SetDefaultPriority(this, PRIO_MESSAGE); - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = TRUE; + SetDefaultPriority(super, PRIO_MESSAGE); + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this)) { - this->action = 1; + if (UpdateFuseInteraction(super)) { + super->action = 1; } } } diff --git a/src/npc/ghostBrothers.c b/src/npc/ghostBrothers.c index 2fe80a975..1dec3eb56 100644 --- a/src/npc/ghostBrothers.c +++ b/src/npc/ghostBrothers.c @@ -1,47 +1,60 @@ +/** + * @file ghostBrothers.c + * @ingroup NPCs + * + * @brief Ghost Brothers NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "functions.h" -#include "save.h" -#include "screen.h" #include "message.h" #include "npc.h" +#include "save.h" +#include "screen.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unused[3]; + /*0x6c*/ const u16* unk_6c; +} GhostBrothersEntity; extern u32 gSpriteAnimations_GhostBrothers[]; -void sub_08065C0C(Entity* this); -void sub_08065BF4(Entity* this); -void sub_08065EBC(Entity* this); -void sub_08065D18(Entity* this); -void sub_08065D74(Entity* this); -void sub_08065DB8(Entity* this); -void sub_08065D18(Entity* this); -void sub_08065EDC(Entity* this); -void sub_08065F20(Entity* this); +void sub_08065C0C(GhostBrothersEntity* this); +void sub_08065BF4(GhostBrothersEntity* this); +void sub_08065EBC(GhostBrothersEntity* this); +void sub_08065D18(GhostBrothersEntity* this); +void sub_08065D74(GhostBrothersEntity* this); +void sub_08065DB8(GhostBrothersEntity* this); +void sub_08065EDC(GhostBrothersEntity* this); +void sub_08065F20(GhostBrothersEntity* this); -void GhostBrothers(Entity* this) { +void GhostBrothers(GhostBrothersEntity* this) { static const s8 gUnk_0811015C[8] = { -14, -16, -18, -20, -22, -20, -18, -16 }; - static EntityAction* const actionFuncs[] = { + static void (*const actionFuncs[])(GhostBrothersEntity*) = { sub_08065BF4, sub_08065BF4, sub_08065BF4, sub_08065BF4, sub_08065EBC, sub_08065EBC, }; - if (this->flags & ENT_SCRIPTED) { + if (super->flags & ENT_SCRIPTED) { sub_08065C0C(this); } else { - actionFuncs[this->type](this); + actionFuncs[super->type](this); - if (this->type < 3) { + if (super->type < 3) { const s8* ptr = gUnk_0811015C; - u32 subtimer = this->subtimer++; - this->z.HALF_U.HI = *(ptr + (((subtimer << 0x18) >> 0x1b) & 0x7)); + u32 subtimer = super->subtimer++; + super->z.HALF_U.HI = *(ptr + (((subtimer << 0x18) >> 0x1b) & 0x7)); } } } -void sub_08065BF4(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void sub_08065BF4(GhostBrothersEntity* this) { + static void (*const actionFuncs[])(GhostBrothersEntity*) = { sub_08065D18, sub_08065D74, sub_08065DB8, }; - actionFuncs[this->action](this); + actionFuncs[super->action](this); } static const u16 gUnk_08110188[] = { 0x1000, 0x4, 0xf01, 0x4, 0xe02, 0x4, 0xd03, 0x4, 0xc04, 0x8, 0xd03, 0x4, @@ -55,139 +68,140 @@ static const u16 gUnk_0811022E[] = { 0x10, 0x2, 0x10f, 0x2, 0x20e, 0x2, 0x30d, 0x60a, 0x2, 0x709, 0x2, 0x808, 0x2, 0x907, 0x2, 0xa06, 0x2, 0xb05, 0x2, 0xc04, 0x2, 0xd03, 0x2, 0xe02, 0x2, 0xf01, 0x2, 0x1000, 0x2, 0xffff }; -void sub_08065C0C(Entity* this) { - u16* puVar3; +void sub_08065C0C(GhostBrothersEntity* this) { + const u16* puVar3; - switch (this->action) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = 1; + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this) == 0) { + if (UpdateFuseInteraction(super) == 0) { return; } - this->action = 1; + super->action = 1; break; case 3: - if (--this->timer != 0) { + if (--super->timer != 0) { return; } - puVar3 = *(u16**)&this->field_0x6c.HWORD; + puVar3 = this->unk_6c; if (*puVar3 != 0xffff) { gScreen.controls.alphaBlend = *puVar3; - this->timer = (u8) * (++puVar3); - *(u16**)&this->field_0x6c = ++puVar3; + super->timer = (u8) * (++puVar3); + this->unk_6c = ++puVar3; return; } - this->spriteSettings.draw = 0; + super->spriteSettings.draw = 0; - this->action = 1; + super->action = 1; break; } } -void sub_08065CCC(Entity* this) { - this->action = 3; - this->timer = 30; - this->spriteRendering.alphaBlend = 1; - *(const u16**)&this->field_0x6c = gUnk_0811022E; +void sub_08065CCC(GhostBrothersEntity* this) { + super->action = 3; + super->timer = 30; + super->spriteRendering.alphaBlend = 1; + this->unk_6c = gUnk_0811022E; gScreen.controls.layerFXControl = 0x3f40; gScreen.controls.alphaBlend = 0x10; } -void GhostBrothers_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void GhostBrothers_MakeInteractable(GhostBrothersEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } -void sub_08065D18(Entity* this) { - this->action = 1; - this->timer = 30; - this->subtimer = 0; - this->spriteSettings.draw = 1; - this->spriteRendering.alphaBlend = 1; - *(const u16**)&this->field_0x6c = gUnk_08110188; - SetDefaultPriority(this, PRIO_MESSAGE); - InitAnimationForceUpdate(this, 2); +void sub_08065D18(GhostBrothersEntity* this) { + super->action = 1; + super->timer = 30; + super->subtimer = 0; + super->spriteSettings.draw = 1; + super->spriteRendering.alphaBlend = 1; + this->unk_6c = gUnk_08110188; + SetDefaultPriority(super, PRIO_MESSAGE); + InitAnimationForceUpdate(super, 2); gScreen.controls.layerFXControl = 0x3f40; gScreen.controls.alphaBlend = 0x1000; } -void sub_08065D74(Entity* this) { - u16* ptr; - if (--this->timer) { +void sub_08065D74(GhostBrothersEntity* this) { + const u16* ptr; + if (--super->timer) { return; } - ptr = *(u16**)&this->field_0x6c; + ptr = this->unk_6c; if (*ptr != 0xffff) { gScreen.controls.alphaBlend = *ptr; - this->timer = *(ptr + 1); - *(u32*)&this->field_0x6c = (u32)(ptr + 2); + super->timer = *(ptr + 1); + this->unk_6c = (ptr + 2); } else { - this->action++; + super->action++; MessageFromTarget(0); } } -void sub_08065DB8(Entity* this) { - switch (this->subAction) { +void sub_08065DB8(GhostBrothersEntity* this) { + switch (super->subAction) { case 0: { if ((gMessage.doTextBox & 0x7f) == 0) { - this->subAction++; - this->timer = 60; - InitAnimationForceUpdate(this, 4); + super->subAction++; + super->timer = 60; + InitAnimationForceUpdate(super, 4); } break; } case 1: { - if (--this->timer == 0) { - this->subAction++; - this->timer = 180; + if (--super->timer == 0) { + super->subAction++; + super->timer = 180; gUnk_02018EB0.unk_1++; - InitAnimationForceUpdate(this, 2); + InitAnimationForceUpdate(super, 2); } break; } case 2: break; case 3: { - if (--this->timer == 0) { + if (--super->timer == 0) { MessageFromTarget(0); - this->subAction++; + super->subAction++; } break; } case 4: { if ((gMessage.doTextBox & 0x7f) == 0) { - this->subAction++; - this->timer = 30; - *(const u16**)&this->field_0x6c = gUnk_0811022E; + super->subAction++; + super->timer = 30; + this->unk_6c = gUnk_0811022E; } break; } default: { - if (--this->timer == 0) { - u16* puVar3 = *(u16**)&this->field_0x6c.HWORD; + if (--super->timer == 0) { + const u16* puVar3 = this->unk_6c; if (*puVar3 != 0xffff) { gScreen.controls.alphaBlend = *puVar3; - this->timer = (u8) * (puVar3 + 1); - *(u16**)&this->field_0x6c = (puVar3 + 2); + super->timer = (u8) * (puVar3 + 1); + this->unk_6c = (puVar3 + 2); } else { gUnk_02018EB0.unk_0++; DeleteThisEntity(); @@ -197,43 +211,43 @@ void sub_08065DB8(Entity* this) { } } - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } -void sub_08065EBC(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void sub_08065EBC(GhostBrothersEntity* this) { + static void (*const actionFuncs[])(GhostBrothersEntity*) = { sub_08065D18, sub_08065EDC, sub_08065F20, }; - actionFuncs[this->action](this); - sub_0806ED78(this); + actionFuncs[super->action](this); + sub_0806ED78(super); } -void sub_08065EDC(Entity* this) { - if (--this->timer == 0) { - u16* puVar3 = *(u16**)&this->field_0x6c.HWORD; +void sub_08065EDC(GhostBrothersEntity* this) { + if (--super->timer == 0) { + const u16* puVar3 = this->unk_6c; if (*puVar3 != 0xffff) { gScreen.controls.alphaBlend = *puVar3; - this->timer = (u8) * (++puVar3); - *(u16**)&this->field_0x6c = (++puVar3); + super->timer = (u8) * (++puVar3); + this->unk_6c = (++puVar3); } else { - this->action++; - AddInteractableWhenBigObject(this); + super->action++; + AddInteractableWhenBigObject(super); } } } -void sub_08065F20(Entity* this) { - UpdateAnimationSingleFrame(this); - if (this->interactType != 0) { - this->interactType = 0; +void sub_08065F20(GhostBrothersEntity* this) { + UpdateAnimationSingleFrame(super); + if (super->interactType != 0) { + super->interactType = 0; MessageFromTarget(0); - this->animIndex++; - if (gSpriteAnimations_GhostBrothers[this->animIndex] == 0) { - this->animIndex = 0; + super->animIndex++; + if (gSpriteAnimations_GhostBrothers[super->animIndex] == 0) { + super->animIndex = 0; } - InitAnimationForceUpdate(this, this->animIndex); + InitAnimationForceUpdate(super, super->animIndex); } } diff --git a/src/npc/gina.c b/src/npc/gina.c index 0095f7b33..97667460a 100644 --- a/src/npc/gina.c +++ b/src/npc/gina.c @@ -1,31 +1,43 @@ -#include "global.h" +/** + * @file gina.c + * @ingroup NPCs + * + * @brief Gina NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" #include "npc.h" +#include "player.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} GinaEntity; -void Gina(Entity* this) { - switch (this->action) { +void Gina(GinaEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; + super->action = 1; + super->spriteSettings.draw = 1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); - sub_0807DD50(this); + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; #if defined(USA) || defined(DEMO_USA) SetLocalFlag(KS_B15); #endif diff --git a/src/npc/gorman.c b/src/npc/gorman.c index abec9aae6..e5bfdd866 100644 --- a/src/npc/gorman.c +++ b/src/npc/gorman.c @@ -1,8 +1,21 @@ +/** + * @file gorman.c + * @ingroup NPCs + * + * @brief Gorman NPC + */ +#define NENT_DEPRECATED #include "functions.h" #include "npc.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unk_68; + /*0x69*/ s8 unk_69; +} GormanEntity; + void sub_080697A4(Entity* this); -void sub_08069838(Entity* this); +void sub_08069838(GormanEntity* this); void sub_08069888(Entity* this); const SpriteLoadData gUnk_08111C3C[] = { @@ -53,11 +66,11 @@ const u8 gUnk_08111CB8[] = { 0, }; -void Gorman(Entity* this) { - if ((this->flags & ENT_SCRIPTED) != 0) { +void Gorman(GormanEntity* this) { + if ((super->flags & ENT_SCRIPTED) != 0) { sub_08069838(this); } else { - sub_080697A4(this); + sub_080697A4(super); } } @@ -94,20 +107,20 @@ void sub_080697EC(Entity* this) { } } -void sub_08069838(Entity* this) { - if (this->action == 0) { - if (!LoadExtraSpriteData(this, gUnk_08111C3C)) { +void sub_08069838(GormanEntity* this) { + if (super->action == 0) { + if (!LoadExtraSpriteData(super, gUnk_08111C3C)) { return; } - this->action++; - this->field_0x68.HALF.LO = 0; - this->field_0x68.HALF.HI = 0; - sub_0807DD64(this); + super->action++; + this->unk_68 = 0; + this->unk_69 = 0; + sub_0807DD64(super); } - sub_0807DD94(this, NULL); - if (this->interactType != 0) { - this->interactType = 0; - sub_08069888(this); + ExecuteScriptAndHandleAnimation(super, NULL); + if (super->interactType != 0) { + super->interactType = 0; + sub_08069888(super); } } @@ -132,56 +145,56 @@ void sub_08069888(Entity* this) { MessageNoOverlap(gUnk_08111C50[index], this); } -void sub_0806991C(Entity* this, ScriptExecutionContext* context) { +void sub_0806991C(GormanEntity* this, ScriptExecutionContext* context) { u32 tmp; const Coords* ptr; - this->field_0x68.HALF.LO = (Random() & 0x1f) + 0x3c; - ptr = &gUnk_08111C5C[*(s8*)&this->field_0x68.HALF.HI]; + this->unk_68 = (Random() & 0x1f) + 0x3c; + ptr = &gUnk_08111C5C[this->unk_69]; context->x.HALF.HI = gRoomControls.origin_x + ptr->HALF.x; context->y.HALF.HI = gRoomControls.origin_y + ptr->HALF.y; context->unk_19 = 8; context->postScriptActions |= 2; context->condition = 0; - tmp = sub_080045DA(context->x.HALF.HI - this->x.HALF.HI, context->y.HALF.HI - this->y.HALF.HI); - this->direction = tmp; - this->animationState = (this->animationState & 0x80) | gUnk_08111C74[(tmp << 0x18) >> 0x1c]; + tmp = sub_080045DA(context->x.HALF.HI - super->x.HALF.HI, context->y.HALF.HI - super->y.HALF.HI); + super->direction = tmp; + super->animationState = (super->animationState & 0x80) | gUnk_08111C74[(tmp << 0x18) >> 0x1c]; gActiveScriptInfo.flags |= 1; } -void sub_080699AC(Entity* this, ScriptExecutionContext* context) { +void sub_080699AC(GormanEntity* this, ScriptExecutionContext* context) { u32 tmp; const Coords* ptr; - this->field_0x68.HALF.LO = (Random() & 0x1f) + 0x3c; - ptr = &gUnk_08111C84[*(s8*)&this->field_0x68.HALF.HI]; + this->unk_68 = (Random() & 0x1f) + 0x3c; + ptr = &gUnk_08111C84[this->unk_69]; context->x.HALF.HI = gRoomControls.origin_x + ptr->HALF.x; context->y.HALF.HI = gRoomControls.origin_y + ptr->HALF.y; context->unk_19 = 8; context->postScriptActions |= 2; context->condition = 0; - tmp = sub_080045DA(context->x.HALF.HI - this->x.HALF.HI, context->y.HALF.HI - this->y.HALF.HI); - this->direction = tmp; - this->animationState = (this->animationState & 0x80) | gUnk_08111C8C[(tmp << 0x18) >> 0x1c]; + tmp = sub_080045DA(context->x.HALF.HI - super->x.HALF.HI, context->y.HALF.HI - super->y.HALF.HI); + super->direction = tmp; + super->animationState = (super->animationState & 0x80) | gUnk_08111C8C[(tmp << 0x18) >> 0x1c]; gActiveScriptInfo.flags |= 1; } -void sub_08069A3C(Entity* this) { - this->field_0x68.HALF.HI = gUnk_08111C9C[(Random() & 1) + (s8)this->field_0x68.HALF.HI * 2]; +void sub_08069A3C(GormanEntity* this) { + this->unk_69 = gUnk_08111C9C[(Random() & 1) + this->unk_69 * 2]; } -void sub_08069A60(Entity* this) { - this->field_0x68.HALF.HI = gUnk_08111CA8[(Random() & 1) + (s8)this->field_0x68.HALF.HI * 2]; +void sub_08069A60(GormanEntity* this) { + this->unk_69 = gUnk_08111CA8[(Random() & 1) + this->unk_69 * 2]; } -void sub_08069A84(Entity* this) { - this->field_0x68.HALF.HI = gUnk_08111CB4[(Random() & 1) + (s8)this->field_0x68.HALF.HI * 2]; +void sub_08069A84(GormanEntity* this) { + this->unk_69 = gUnk_08111CB4[(Random() & 1) + this->unk_69 * 2]; } -void sub_08069AA8(Entity* this) { - this->field_0x68.HALF.HI = gUnk_08111CB8[(Random() & 1) + (s8)this->field_0x68.HALF.HI * 2]; +void sub_08069AA8(GormanEntity* this) { + this->unk_69 = gUnk_08111CB8[(Random() & 1) + this->unk_69 * 2]; } -void sub_08069ACC(Entity* this, ScriptExecutionContext* context) { - if (--this->field_0x68.HALF.LO * 0x1000000 < 1) { +void sub_08069ACC(GormanEntity* this, ScriptExecutionContext* context) { + if (--this->unk_68 * 0x1000000 < 1) { context->condition = 1; } else { context->condition = 0; diff --git a/src/npc/goron.c b/src/npc/goron.c index ce2fb731f..f2f2f8bb6 100644 --- a/src/npc/goron.c +++ b/src/npc/goron.c @@ -1,3 +1,10 @@ +/** + * @file goron.c + * @ingroup NPCs + * + * @brief Goron NPC + */ +#define NENT_DEPRECATED #include "effects.h" #include "entity.h" #include "functions.h" @@ -5,27 +12,34 @@ #include "message.h" #include "npc.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unused[24]; + /*0x80*/ u16 unk_80; + /*0x82*/ u16 unk_82; +} GoronEntity; + void sub_08069310(Entity*); void sub_08069328(Entity*); void sub_08069390(Entity*); -void sub_080693C4(Entity*); -void sub_080693D0(Entity*); +void sub_080693C4(GoronEntity*); +void sub_080693D0(GoronEntity*); -void Goron(Entity* this) { +void Goron(GoronEntity* this) { static void (*const actionFuncs[])(Entity*) = { sub_08069310, sub_08069328, sub_08069390, }; - static void (*const scriptedActionFuncs[])(Entity*) = { + static void (*const scriptedActionFuncs[])(GoronEntity*) = { sub_080693C4, sub_080693D0, }; - if (this->flags & ENT_SCRIPTED) { - scriptedActionFuncs[this->action](this); + if (super->flags & ENT_SCRIPTED) { + scriptedActionFuncs[super->action](this); } else { - actionFuncs[this->action](this); - sub_0806ED78(this); + actionFuncs[super->action](super); + sub_0806ED78(super); } } @@ -66,25 +80,25 @@ void sub_08069390(Entity* this) { } } -void sub_080693C4(Entity* this) { - this->action = 1; - sub_0807DD50(this); +void sub_080693C4(GoronEntity* this) { + super->action = 1; + InitScriptForNPC(super); } void sub_08069428(Entity* this, s32 offsetX, bool32 createFx65); -void sub_080693D0(Entity* this) { - sub_0807DD94(this, NULL); - if (this->animIndex == 8) { - bool32 createFx65 = (this->field_0x82.HWORD & 0xF) != 0; +void sub_080693D0(GoronEntity* this) { + ExecuteScriptAndHandleAnimation(super, NULL); + if (super->animIndex == 8) { + bool32 createFx65 = (this->unk_82 & 0xF) != 0; - if (this->frame == 1) { - this->frame = 0; - sub_08069428(this, Q_16_16(-8.0), createFx65); + if (super->frame == 1) { + super->frame = 0; + sub_08069428(super, Q_16_16(-8.0), createFx65); } - if (this->frame == 2) { - this->frame = 0; - sub_08069428(this, Q_16_16(8.0), createFx65); + if (super->frame == 2) { + super->frame = 0; + sub_08069428(super, Q_16_16(8.0), createFx65); } } } @@ -154,14 +168,14 @@ void sub_080694D8(Entity* this) { ShowNPCDialogue(this, &gUnk_08111A94[this->type]); } -void sub_080694EC(Entity* this) { +void sub_080694EC(GoronEntity* this) { u32 anim; - this->animationState = 4; + super->animationState = 4; anim = 2; if (!CheckKinstoneFused(KINSTONE_2F)) anim = 8; - InitAnimationForceUpdate(this, anim); - this->field_0x80.HWORD = anim; + InitAnimationForceUpdate(super, anim); + this->unk_80 = anim; } void Goron_Fusion(Entity* this) { diff --git a/src/npc/goronMerchant.c b/src/npc/goronMerchant.c index a26eb4b1c..24bb04e77 100644 --- a/src/npc/goronMerchant.c +++ b/src/npc/goronMerchant.c @@ -1,11 +1,17 @@ -#include "global.h" +/** + * @file goronMerchant.c + * @ingroup NPCs + * + * @brief Goron Merchant NPC + */ +#define NENT_DEPRECATED #include "entity.h" +#include "flags.h" #include "functions.h" +#include "item.h" #include "message.h" -#include "flags.h" -#include "save.h" #include "npc.h" -#include "item.h" +#include "save.h" static u32 GoronMerchant_GetSalePrice(Entity*); @@ -69,11 +75,11 @@ void sub_0806961C(Entity* this) { void sub_0806963C(Entity* this) { this->action = 1; this->spriteSettings.draw = TRUE; - sub_0807DD50(this); + InitScriptForNPC(this); } void sub_08069654(Entity* this) { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(this, NULL); } void sub_08069660(Entity* this) { diff --git a/src/npc/gregal.c b/src/npc/gregal.c index 8a279a068..35e972c3e 100644 --- a/src/npc/gregal.c +++ b/src/npc/gregal.c @@ -1,109 +1,123 @@ +/** + * @file gregal.c + * @ingroup NPCs + * + * @brief Gregal NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "script.h" #include "functions.h" #include "npc.h" +#include "script.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; +} GregalEntity; static const u32 gUnk_08113D84[] = { 0x100c0200, 0x4, }; -void sub_0806CAF4(Entity*); -void sub_0806CB80(Entity*); -void sub_0806CBB4(Entity*); -void sub_0806CC08(Entity*); +void sub_0806CAF4(GregalEntity*); +void sub_0806CB80(GregalEntity*); +void sub_0806CBB4(GregalEntity*); +void sub_0806CC08(GregalEntity*); -void Gregal(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void Gregal(GregalEntity* this) { + static void (*const actionFuncs[])(GregalEntity*) = { sub_0806CAF4, sub_0806CB80, sub_0806CBB4, sub_0806CC08, }; - actionFuncs[this->type](this); + actionFuncs[super->type](this); } -void sub_0806CAF4(Entity* this) { +void sub_0806CAF4(GregalEntity* this) { Entity* npc; - if (this->action == 0) { - this->action++; - SetDefaultPriority(this, PRIO_MESSAGE); + if (super->action == 0) { + super->action++; + SetDefaultPriority(super, PRIO_MESSAGE); npc = CreateNPC(GREGAL, 1, 0); if (npc != NULL) { - npc->parent = this; - CopyPosition(this, npc); - SortEntityBelow(this, npc); + npc->parent = super; + CopyPosition(super, npc); + SortEntityBelow(super, npc); } npc = CreateNPC(GREGAL, 2, 0); if (npc != NULL) { - npc->parent = this; - CopyPosition(this, npc); - SortEntityAbove(this, npc); + npc->parent = super; + CopyPosition(super, npc); + SortEntityAbove(super, npc); } - sub_0807DD64(this); - AddInteractableWhenBigObject(this); - SetInteractableObjectCollision(this, 1, (u8)gUnk_08113D84[1], gUnk_08113D84); + sub_0807DD64(super); + AddInteractableWhenBigObject(super); + SetInteractableObjectCollision(super, 1, (u8)gUnk_08113D84[1], gUnk_08113D84); } - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - GetNextFrame(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + GetNextFrame(super); } -void sub_0806CB80(Entity* this) { - if (this->action == 0) { - this->action++; - this->animationState = 2; - this->frameIndex = 0; - SetDefaultPriority(this, PRIO_MESSAGE); +void sub_0806CB80(GregalEntity* this) { + if (super->action == 0) { + super->action++; + super->animationState = 2; + super->frameIndex = 0; + SetDefaultPriority(super, PRIO_MESSAGE); } - if (this->parent != NULL) { - this->frameIndex = (this->parent->frame & 3) + 0x21; + if (super->parent != NULL) { + super->frameIndex = (super->parent->frame & 3) + 0x21; } } -void sub_0806CBB4(Entity* this) { - if (this->action == 0) { - this->action++; - this->animationState = 2; - SetDefaultPriority(this, PRIO_MESSAGE); - InitializeAnimation(this, 0x11); +void sub_0806CBB4(GregalEntity* this) { + if (super->action == 0) { + super->action++; + super->animationState = 2; + SetDefaultPriority(super, PRIO_MESSAGE); + InitializeAnimation(super, 0x11); } - GetNextFrame(this); - if (this->parent != NULL) { - this->spriteSettings.draw = 0; - if ((this->parent->frame & 4) != 0) { - this->spriteSettings.draw = 1; + GetNextFrame(super); + if (super->parent != NULL) { + super->spriteSettings.draw = 0; + if ((super->parent->frame & 4) != 0) { + super->spriteSettings.draw = 1; } } } -void sub_0806CC08(Entity* this) { - switch (this->action) { +void sub_0806CC08(GregalEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD64(this); + super->action = 1; + super->spriteSettings.draw = 1; + SetDefaultPriority(super, PRIO_MESSAGE); + sub_0807DD64(super); case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 8); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + this->animIndex = super->animIndex; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) + 8); + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - GetNextFrame(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + GetNextFrame(super); } break; case 2: - if (UpdateFuseInteraction(this) == 0) { + if (UpdateFuseInteraction(super) == 0) { return; } - this->action = 1; - InitAnimationForceUpdate(this, this->field_0x68.HALF.HI); + super->action = 1; + InitAnimationForceUpdate(super, this->animIndex); break; } } @@ -154,9 +168,9 @@ void sub_0806CD4C(Entity* this) { ChangeObjPalette(this, 0x110); } -void Gregal_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Gregal_MakeInteractable(GregalEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Gregal_Fusion(Entity* this) { diff --git a/src/npc/guard.c b/src/npc/guard.c index 834c2f1b8..c963285d1 100644 --- a/src/npc/guard.c +++ b/src/npc/guard.c @@ -1,13 +1,28 @@ -#include "global.h" +/** + * @file guard.c + * @ingroup NPCs + * + * @brief Guard NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" #include "flags.h" -#include "message.h" -#include "room.h" -#include "script.h" #include "functions.h" +#include "message.h" #include "npc.h" +#include "player.h" #include "projectile.h" +#include "room.h" +#include "script.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u16 unk_68; + /*0x6a*/ u16 unk_6a; + /*0x6c*/ u8 unused[4]; + /*0x70*/ s8 unk_70; + /*0x71*/ u8 unk_71; +} GuardEntity; typedef struct { u32 unk; @@ -22,7 +37,6 @@ typedef struct { extern void sub_08063D24(Entity*); extern void sub_08064428(Entity*); void sub_08063DC8(Entity*); -void sub_08063F20(Entity*); // TODO guardWithSpear rodata before this const Dialog gUnk_0810CF4C[] = { @@ -240,10 +254,10 @@ const SpriteLoadData gUnk_0810F524[] = { { 55, 43, 4 }, { 6199, 43, 4 }, { 22583, 43, 4 }, { 0, 0, 0 }, { 4, 43, 4 }, { 16388, 43, 4 }, { 8196, 43, 4 }, { 0, 0, 0 }, }; -void sub_08063E90(Entity*); -void sub_08063F20(Entity*); -void sub_08063F78(Entity*); -void (*const gUnk_0810F544[])(Entity*) = { +void sub_08063E90(GuardEntity*); +void sub_08063F20(GuardEntity*); +void sub_08063F78(GuardEntity*); +void (*const gUnk_0810F544[])(GuardEntity*) = { sub_08063E90, sub_08063F20, sub_08063F78, @@ -261,11 +275,11 @@ void (*const gUnk_0810F550[])(Entity*) = { extern void* gUnk_0810F6BC[]; // TODO find out type of second param for sub_0806EE04 -void Guard(Entity* this) { - if ((this->flags & ENT_SCRIPTED) != 0) { - gUnk_0810F544[this->action](this); +void Guard(GuardEntity* this) { + if ((super->flags & ENT_SCRIPTED) != 0) { + gUnk_0810F544[super->action](this); } else { - sub_08063D24(this); + sub_08063D24(super); } } @@ -306,7 +320,7 @@ void sub_08063DC8(Entity* this) { if (this->type == 0xff) { this->action = 2; this->timer = 30; - this->animationState = sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)); + this->animationState = GetAnimationStateForDirection4(GetFacingDirection(this, &gPlayerEntity)); InitAnimationForceUpdate(this, this->animationState + 4); } else { sub_0806EE20(this); @@ -319,7 +333,7 @@ void sub_08063DC8(Entity* this) { if (this->interactType != 0) { this->action = 3; this->interactType = 0; - InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + InitializeAnimation(this, GetAnimationStateForDirection4(GetFacingDirection(this, &gPlayerEntity))); sub_08064428(this); } } @@ -338,53 +352,54 @@ void sub_08063E6C(Entity* this) { } } -void sub_08063E90(Entity* this) { +void sub_08063E90(GuardEntity* this) { u32 idx; u32 unk; - idx = (this->id ^ 0x15) ? 1 : 0; - if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx * 4])) + idx = (super->id ^ 0x15) ? 1 : 0; + if (!LoadExtraSpriteData(super, &gUnk_0810F524[idx * 4])) return; - this->action++; - if (this->timer) { - this->field_0x70.BYTES.byte0 = 8; + super->action++; + if (super->timer) { + this->unk_70 = 8; } else { - this->field_0x70.BYTES.byte0 = 0; + this->unk_70 = 0; } - this->timer = 0; + super->timer = 0; - unk = sub_0805ACC0(this); + unk = sub_0805ACC0(super); if (unk == 0) { - this->field_0x68.HWORD = this->x.HALF.HI; - this->field_0x6a.HWORD = this->y.HALF.HI; + this->unk_68 = super->x.HALF.HI; + this->unk_6a = super->y.HALF.HI; } else { - this->field_0x68.HWORD = unk >> 0x10; - this->field_0x6a.HWORD = unk; + this->unk_68 = unk >> 0x10; + this->unk_6a = unk; } - this->field_0x70.BYTES.byte1 = 0; - this->collisionLayer = 1; - UpdateSpriteForCollisionLayer(this); - sub_0807DD64(this); + this->unk_71 = 0; + super->collisionLayer = 1; + UpdateSpriteForCollisionLayer(super); + sub_0807DD64(super); sub_08063F20(this); } -void sub_08063F20(Entity* this) { - ExecuteScriptForEntity(this, 0); - HandleEntity0x82Actions(this); - GetNextFrame(this); - if (this->interactType != 0) { - this->action++; - this->interactType = 0; - InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + *(s8*)&this->field_0x70); - sub_08064428(this); +void sub_08063F20(GuardEntity* this) { + ExecuteScriptForEntity(super, 0); + HandleEntity0x82Actions(super); + GetNextFrame(super); + if (super->interactType != 0) { + super->action++; + super->interactType = 0; + InitializeAnimation(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) + this->unk_70); + sub_08064428(super); } } -void sub_08063F78(Entity* this) { +void sub_08063F78(GuardEntity* this) { if ((gMessage.doTextBox & 0x7f) == 0) { - this->action = this->action - 1; - InitializeAnimation(this, (this->animationState >> 1) + 4 + *(s8*)&this->field_0x70); + super->action = super->action - 1; + InitializeAnimation(super, (super->animationState >> 1) + 4 + this->unk_70); } } diff --git a/src/npc/guardWithSpear.c b/src/npc/guardWithSpear.c index f74b97ce0..52f035873 100644 --- a/src/npc/guardWithSpear.c +++ b/src/npc/guardWithSpear.c @@ -1,20 +1,26 @@ +/** + * @file guardWithSpear.c + * @ingroup NPCs + * + * @brief Guard with Spear NPC + */ #define NENT_DEPRECATED #include "entity.h" -#include "script.h" -#include "player.h" -#include "npc.h" #include "functions.h" -#include "object.h" #include "item.h" +#include "npc.h" +#include "object.h" +#include "player.h" +#include "script.h" typedef struct { - Entity base; - s16 unk68; - s16 unk6a; - s16 unk6c; - s16 unk6e; - s8 unk70; - s8 unk71; + /*0x00*/ Entity base; + /*0x68*/ s16 unk_68; + /*0x6a*/ s16 unk_6a; + /*0x6c*/ s16 unk_6c; + /*0x6e*/ s16 unk_6e; + /*0x70*/ s8 unk_70; + /*0x71*/ s8 unk_71; } GuardWithSpearEntity; extern Dialog gUnk_0810CF4C[]; @@ -53,34 +59,34 @@ void sub_0806407C(GuardWithSpearEntity* this, ScriptExecutionContext* context) { } super->direction = dir; - super->animationState = sub_0806F5B0(dir); + super->animationState = GetAnimationStateForDirection8(dir); super->speed = 0x80; } uVar7 = super->animationState >> 1; if (uVar7 + 4 != super->animIndex) { - InitializeAnimation(super, uVar7 + 4 + this->unk70); + InitializeAnimation(super, uVar7 + 4 + this->unk_70); } ProcessMovement0(super); - x = super->x.HALF.HI - this->unk68; + x = super->x.HALF.HI - this->unk_68; if (0x10 < x) { - super->x.HALF.HI = this->unk68 + 0x10; + super->x.HALF.HI = this->unk_68 + 0x10; context->unk_12 = 1; } if (x < -0x10) { - super->x.HALF.HI = this->unk68 + -0x10; + super->x.HALF.HI = this->unk_68 + -0x10; context->unk_12 = 1; } - y = super->y.HALF.HI - this->unk6a; + y = super->y.HALF.HI - this->unk_6a; if (0x10 < y) { - super->y.HALF.HI = this->unk6a + 0x10; + super->y.HALF.HI = this->unk_6a + 0x10; context->unk_12 = 1; } if (y < -0x10) { - super->y.HALF.HI = this->unk6a + -0x10; + super->y.HALF.HI = this->unk_6a + -0x10; context->unk_12 = 1; } @@ -102,8 +108,8 @@ void sub_08064198(GuardWithSpearEntity* this) { u32 animIndex; u32 animationState; - if (this->unk71 > 0) { - this->unk71--; + if (this->unk_71 > 0) { + this->unk_71--; } yDiff = gPlayerEntity.y.HALF.HI - super->y.HALF.HI; @@ -129,17 +135,18 @@ void sub_08064198(GuardWithSpearEntity* this) { if (0x140 < gPlayerEntity.speed && gRoomTransition.frameCount % 6 == 0) { CreateDustSmall(super); } - this->unk71 = 10; - animationState = super->animationState = sub_0806F5B0(super->direction); - animIndex = (animationState >> 1) + 4 + this->unk70; + this->unk_71 = 10; + animationState = super->animationState = GetAnimationStateForDirection8(super->direction); + animIndex = (animationState >> 1) + 4 + this->unk_70; if (animIndex != super->animIndex) { InitializeAnimation(super, animIndex); } } } - if (this->unk71 == 0) { - animationState = super->animationState = sub_0806F5B0(GetFacingDirection(super, &gPlayerEntity)); - animIndex = (animationState >> 1) + this->unk70; + if (this->unk_71 == 0) { + animationState = super->animationState = + GetAnimationStateForDirection8(GetFacingDirection(super, &gPlayerEntity)); + animIndex = (animationState >> 1) + this->unk_70; if (animIndex != super->animIndex) { InitializeAnimation(super, animIndex); } @@ -158,8 +165,8 @@ void sub_080642B8(GuardWithSpearEntity* this) { u32 animIndex; u32 animationState; - if (this->unk71 > 0) { - this->unk71--; + if (this->unk_71 > 0) { + this->unk_71--; } yDiff = gPlayerEntity.x.HALF.HI - super->x.HALF.HI; @@ -185,17 +192,18 @@ void sub_080642B8(GuardWithSpearEntity* this) { if (0x140 < gPlayerEntity.speed && gRoomTransition.frameCount % 6 == 0) { CreateDustSmall(super); } - this->unk71 = 10; - animationState = super->animationState = sub_0806F5B0(super->direction); - animIndex = (animationState >> 1) + 4 + this->unk70; + this->unk_71 = 10; + animationState = super->animationState = GetAnimationStateForDirection8(super->direction); + animIndex = (animationState >> 1) + 4 + this->unk_70; if (animIndex != super->animIndex) { InitializeAnimation(super, animIndex); } } } - if (this->unk71 == 0) { - animationState = super->animationState = sub_0806F5B0(GetFacingDirection(super, &gPlayerEntity)); - animIndex = (animationState >> 1) + this->unk70; + if (this->unk_71 == 0) { + animationState = super->animationState = + GetAnimationStateForDirection8(GetFacingDirection(super, &gPlayerEntity)); + animIndex = (animationState >> 1) + this->unk_70; if (animIndex != super->animIndex) { InitializeAnimation(super, animIndex); } diff --git a/src/npc/hurdyGurdyMan.c b/src/npc/hurdyGurdyMan.c index 1c45bbf34..d9dfa77d2 100644 --- a/src/npc/hurdyGurdyMan.c +++ b/src/npc/hurdyGurdyMan.c @@ -1,47 +1,60 @@ +/** + * @file hurdyGurdyMan.c + * @ingroup NPCs + * + * @brief Hurdy Gurdy Man NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "functions.h" -#include "save.h" #include "npc.h" +#include "save.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unk_69; +} HurdyGurdyManEntity; static const SpriteLoadData gUnk_081144F0[] = { { 0x163, 0x59, 0x4 }, { 0x4163, 0x59, 0x4 }, { 0, 0, 0 } }; extern u16* gUnk_08001A7C[]; -void HurdyGurdyMan(Entity* this) { +void HurdyGurdyMan(HurdyGurdyManEntity* this) { u32 index; u16* pointerToArray; - switch (this->action) { + switch (super->action) { case 0: - if (LoadExtraSpriteData(this, gUnk_081144F0)) { - this->action = 1; - this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + if (LoadExtraSpriteData(super, gUnk_081144F0)) { + super->action = 1; + this->unk_69 = 0; + SetDefaultPriority(super, PRIO_MESSAGE); + InitScriptForNPC(super); } break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - index = GetFuserId(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + this->unk_69 = super->animIndex; + InitializeAnimation(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + index = GetFuserId(super); pointerToArray = gUnk_08001A7C[index]; - if (this->field_0x68.HALF.LO == 0x32) { + if (this->fusionOffer == 0x32) { pointerToArray = pointerToArray + 3; } - sub_0801DFB4(this, *pointerToArray, pointerToArray[1], (u32)pointerToArray[2]); + InitializeFuseInfo(super, *pointerToArray, pointerToArray[1], (u32)pointerToArray[2]); gPlayerState.controlMode = CONTROL_DISABLED; } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if ((UpdateFuseInteraction(this) != 0)) { - this->action = 1; - InitializeAnimation(this, this->field_0x68.HALF.HI); + if ((UpdateFuseInteraction(super) != 0)) { + super->action = 1; + InitializeAnimation(super, this->unk_69); } break; } @@ -100,9 +113,9 @@ void sub_0806E418(Entity* this) { ShowNPCDialogue(this, &dialogs[tmp]); } -void HurdyGurdyMan_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void HurdyGurdyMan_MakeInteractable(HurdyGurdyManEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void HurdyGurdyMan_Fusion(Entity* this) { diff --git a/src/npc/kid.c b/src/npc/kid.c index 685d7da84..dcd2d761e 100644 --- a/src/npc/kid.c +++ b/src/npc/kid.c @@ -1,7 +1,28 @@ +/** + * @file kid.c + * @ingroup NPCs + * + * @brief Kid NPC + */ +#define NENT_DEPRECATED #include "functions.h" #include "message.h" #include "npc.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unk_68; + /*0x69*/ u8 unk_69; + /*0x6a*/ u8 fusionOffer; + /*0x6b*/ u8 unk_6b; + /*0x6c*/ u16 unk_6c; + /*0x6e*/ u16 unk_6e; + /*0x70*/ u8 unused1[16]; + /*0x80*/ u16 unk_80; + /*0x82*/ u8 unused2[2]; + /*0x84*/ ScriptExecutionContext* context; +} KidEntity; + const SpriteLoadData gUnk_0810BD7C[] = { { 58, 59, 4 }, { 10298, 59, 4 }, @@ -72,13 +93,12 @@ const u16 gUnk_0810BDE8[][2] = { { TEXT_INDEX(TEXT_EMPTY, 0x1), TEXT_INDEX(TEXT_EMPTY, 0x1), } }; -void sub_080620F4(Entity*); -void sub_08062130(Entity*); -void sub_08062194(Entity*); -void (*const gUnk_0810BE0C[])(Entity*) = { sub_080620F4, sub_08062130, sub_08062194 }; +void sub_080620F4(KidEntity*); +void sub_08062130(KidEntity*); +void sub_08062194(KidEntity*); +void (*const gUnk_0810BE0C[])(KidEntity*) = { sub_080620F4, sub_08062130, sub_08062194 }; extern s32 sub_080041E8(s32 x1, s32 y1, s32 x2, s32 y2); -void sub_08062194(Entity*); const Dialog gUnk_0810BE10[] = { { 0, 0, DIALOG_NORMAL, 1, { 0, TEXT_INDEX(TEXT_FESTIVAL, 0xf) } }, { 0, 0, DIALOG_NORMAL, 1, { 0, TEXT_INDEX(TEXT_TOWN4, 0x33) } }, @@ -178,10 +198,10 @@ const FrameStruct gUnk_0810C0A0[] = { { 120, 83 }, { 128, 15 }, { 131, 102 }, { 128, 15 }, { 139, 111 }, { 128, 15 }, }; -void sub_080621AC(Entity*); -void sub_080622F4(Entity*); -void sub_0806265C(Entity*, ScriptExecutionContext*); -void sub_0806252C(Entity*); +void sub_080621AC(KidEntity* this); +void sub_080622F4(KidEntity* this); +void sub_0806265C(Entity* this, ScriptExecutionContext* context); +void sub_0806252C(Entity* this); typedef union { struct { @@ -197,114 +217,115 @@ typedef union { #define KID_HEAP_COUNT 0x14 typedef KidHeapItem KidHeap[KID_HEAP_COUNT]; -#define KID_HEAP ((KidHeapItem*)this->myHeap) +#define KID_HEAP ((KidHeapItem*)super->myHeap) -void Kid(Entity* this) { - if ((this->flags & ENT_SCRIPTED) != 0) { +void Kid(KidEntity* this) { + if ((super->flags & ENT_SCRIPTED) != 0) { sub_080621AC(this); } else { - gUnk_0810BE0C[this->action](this); + gUnk_0810BE0C[super->action](this); } } -void sub_080620F4(Entity* this) { - if (LoadExtraSpriteData(this, gUnk_0810BDC4[this->type])) { - this->animationState = 4; - this->field_0x68.HALF.LO = 0; - this->action = 1; - InitAnimationForceUpdate(this, 2); - AddInteractableWhenBigObject(this); +void sub_080620F4(KidEntity* this) { + if (LoadExtraSpriteData(super, gUnk_0810BDC4[super->type])) { + super->animationState = 4; + this->unk_68 = 0; + super->action = 1; + InitAnimationForceUpdate(super, 2); + AddInteractableWhenBigObject(super); } } -void sub_08062130(Entity* this) { - if (this->interactType != 0) { - this->action = 2; - InitAnimationForceUpdate(this, GetAnimationState(this)); +void sub_08062130(KidEntity* this) { + if (super->interactType != 0) { + super->action = 2; + InitAnimationForceUpdate(super, GetAnimationState(super)); } - if (this->subtimer++ >= 0x79) { - this->subtimer = 0; - this->timer = (this->timer + 1) & 7; - if (this->type == 6) { - this->timer = this->timer + 16; + if (super->subtimer++ >= 0x79) { + super->subtimer = 0; + super->timer = (super->timer + 1) & 7; + if (super->type == 6) { + super->timer = super->timer + 16; } - InitAnimationForceUpdate(this, this->timer); + InitAnimationForceUpdate(super, super->timer); } else { - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } - sub_0806ED78(this); + sub_0806ED78(super); } -void sub_08062194(Entity* this) { +void sub_08062194(KidEntity* this) { MessageFromTarget(0); - this->action = 1; - this->interactType = 0; + super->action = 1; + super->interactType = 0; } -void sub_080621AC(Entity* this) { +void sub_080621AC(KidEntity* this) { u32 tmp; - switch (this->action) { + switch (super->action) { case 0: - if (LoadExtraSpriteData(this, gUnk_0810BDC4[this->type])) { - this->action = 1; - this->animationState = this->timer; - this->timer = 0; - this->field_0x68.HALF.LO = 0; - this->field_0x68.HALF.HI = 0; - this->field_0x6a.HALF.HI = 0xff; - tmp = sub_0805ACC0(this); + if (LoadExtraSpriteData(super, gUnk_0810BDC4[super->type])) { + super->action = 1; + super->animationState = super->timer; + super->timer = 0; + this->unk_68 = 0; + this->unk_69 = 0; + this->unk_6b = 0xff; + tmp = sub_0805ACC0(super); if (tmp == 0) { - this->field_0x6c.HWORD = this->x.HALF.HI; - this->field_0x6e.HWORD = this->y.HALF.HI; + this->unk_6c = super->x.HALF.HI; + this->unk_6e = super->y.HALF.HI; } else { - this->field_0x6c.HWORD = tmp >> 0x10; - this->field_0x6e.HWORD = tmp; + this->unk_6c = tmp >> 0x10; + this->unk_6e = tmp; } - sub_0807DD50(this); + InitScriptForNPC(super); } break; case 1: - if (this->interactType == 2) { - this->action = 3; - this->interactType = 0; - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 3; + super->interactType = 0; + InitializeNPCFusion(super); } else { - if ((s8)this->field_0x68.HALF.LO != 0) { - if (this->interactType != 0) { - this->action = 2; - this->interactType = 0; + if ((s8)this->unk_68 != 0) { + if (super->interactType != 0) { + super->action = 2; + super->interactType = 0; } else { sub_080622F4(this); return; } } else { - sub_0807DD94(this, NULL); - if (this->interactType != 0) { - this->action = 2; - this->interactType = 0; + ExecuteScriptAndHandleAnimation(super, NULL); + if (super->interactType != 0) { + super->action = 2; + super->interactType = 0; } else { return; } } - sub_0806265C(this, *(ScriptExecutionContext**)&this->cutsceneBeh); - tmp = this->animIndex; + sub_0806265C(super, this->context); + tmp = super->animIndex; } - this->field_0x6a.HALF.HI = this->animIndex; - if (this->animIndex < 8) { - InitializeAnimation(this, (this->animIndex & 0xfffffffc) + - sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + this->unk_6b = super->animIndex; + if (super->animIndex < 8) { + InitializeAnimation(super, + (super->animIndex & 0xfffffffc) + + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } break; case 2: - GetNextFrame(this); + GetNextFrame(super); if ((gMessage.doTextBox & 0x7f) == 0) { - this->action = 1; + super->action = 1; } break; case 3: - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; } break; default: @@ -320,7 +341,7 @@ void sub_080621AC(Entity* this) { heapPtr--; \ } -void sub_080622F4(Entity* this) { +void sub_080622F4(KidEntity* this) { s32 dx; s32 dy; s32 dist; @@ -340,10 +361,10 @@ void sub_080622F4(Entity* this) { item.FIELDS.animationState = gPlayerEntity.animationState; item.FIELDS.collisionLayer = gPlayerEntity.collisionLayer; - heapPtr = this->myHeap; + heapPtr = super->myHeap; if (heapPtr->FIELDS.framestate == 0x16 && item.FIELDS.framestate != 0x16) { - dx = this->x.HALF.HI - gPlayerEntity.x.HALF.HI; - dy = this->y.HALF.HI - gPlayerEntity.y.HALF.HI; + dx = super->x.HALF.HI - gPlayerEntity.x.HALF.HI; + dy = super->y.HALF.HI - gPlayerEntity.y.HALF.HI; if (dx < 0) dx = -dx; @@ -351,11 +372,11 @@ void sub_080622F4(Entity* this) { dy = -dy; if (dx > 120 || dy > 80) { - this->field_0x68.HALF.LO = 0; + this->unk_68 = 0; return; } - sub_0806252C(this); + sub_0806252C(super); } animIndex = 0; @@ -366,8 +387,8 @@ void sub_080622F4(Entity* this) { heapPtr[0] = item; animIndex = 0x4; - if ((s8)this->field_0x68.HALF.HI > 0) { - this->field_0x68.HALF.HI = this->field_0x68.HALF.HI - 1; + if ((s8)this->unk_69 > 0) { + this->unk_69 = this->unk_69 - 1; } } else { heapPtr += KID_HEAP_COUNT - 1; @@ -387,40 +408,40 @@ void sub_080622F4(Entity* this) { } heapPtr = KID_HEAP; heapPtr += +KID_HEAP_COUNT - 1; - this->x.HALF.HI = heapPtr->FIELDS.x; - this->y.HALF.HI = heapPtr->FIELDS.y; - this->z.HALF.HI = heapPtr->FIELDS.z; - this->animationState = heapPtr->FIELDS.animationState; - this->collisionLayer = heapPtr->FIELDS.collisionLayer; - - if (((s8)this->field_0x68.HALF.HI) > 0) { - this->field_0x68.HALF.HI = this->field_0x68.HALF.HI - 1; + super->x.HALF.HI = heapPtr->FIELDS.x; + super->y.HALF.HI = heapPtr->FIELDS.y; + super->z.HALF.HI = heapPtr->FIELDS.z; + super->animationState = heapPtr->FIELDS.animationState; + super->collisionLayer = heapPtr->FIELDS.collisionLayer; + + if (((s8)this->unk_69) > 0) { + this->unk_69 = this->unk_69 - 1; } animIndexTmp = animIndex; - animIndex += this->animationState >> 1; - if (this->type == OBJECT) { + animIndex += super->animationState >> 1; + if (super->type == OBJECT) { animIndex += 0x10; } - if (!(animIndex == this->animIndex || (animIndexTmp == 0 && ((s8)this->field_0x68.HALF.HI) > 0))) { - InitAnimationForceUpdate(this, animIndex); - this->field_0x68.HALF.HI = 0x1e; + if (!(animIndex == super->animIndex || (animIndexTmp == 0 && ((s8)this->unk_69) > 0))) { + InitAnimationForceUpdate(super, animIndex); + this->unk_69 = 0x1e; } else { - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } - sub_0800451C(this); + sub_0800451C(super); return; } -void sub_08062500(Entity* this) { - this->myHeap = zMalloc(sizeof(KidHeap)); - if (this->myHeap != NULL) { - this->field_0x68.HALF.LO = 1; - RemoveInteractableObject(this); - this->hitbox = NULL; - sub_0806252C(this); +void sub_08062500(KidEntity* this) { + super->myHeap = zMalloc(sizeof(KidHeap)); + if (super->myHeap != NULL) { + this->unk_68 = 1; + RemoveInteractableObject(super); + super->hitbox = NULL; + sub_0806252C(super); } } @@ -636,7 +657,7 @@ void Kid_Head(Entity* this) { } } -void sub_08062948(Entity* this, ScriptExecutionContext* context) { +void sub_08062948(KidEntity* this, ScriptExecutionContext* context) { s32 bVar1; u16 uVar2; u32 uVar3; @@ -646,7 +667,7 @@ void sub_08062948(Entity* this, ScriptExecutionContext* context) { context->unk_18++; context->unk_12 = (Random() & 0x3f) + 0x20; uVar3 = Random() & 0x18; - switch (this->direction) { + switch (super->direction) { case 0: if (uVar3 == 0x10) { uVar3 = 8; @@ -668,32 +689,32 @@ void sub_08062948(Entity* this, ScriptExecutionContext* context) { } } - this->direction = (u8)uVar3; - this->animationState = sub_0806F5B0(uVar3); - this->speed = 0x80; + super->direction = (u8)uVar3; + super->animationState = GetAnimationStateForDirection8(uVar3); + super->speed = 0x80; } - uVar3 = (this->animationState >> 1) + 4; - if (uVar3 != this->animIndex) { - InitializeAnimation(this, uVar3); - this->field_0x80.HWORD = (u16)this->animIndex; + uVar3 = (super->animationState >> 1) + 4; + if (uVar3 != super->animIndex) { + InitializeAnimation(super, uVar3); + this->unk_80 = (u16)super->animIndex; } - ProcessMovement0(this); - iVar4 = this->x.HALF.HI - (s16)this->field_0x6c.HWORD; + ProcessMovement0(super); + iVar4 = super->x.HALF.HI - (s16)this->unk_6c; if (0x10 < iVar4) { - this->x.HALF.HI = this->field_0x6c.HWORD + 0x10; + super->x.HALF.HI = this->unk_6c + 0x10; context->unk_12 = 1; } if (iVar4 < -0x10) { - this->x.HALF.HI = this->field_0x6c.HWORD - 0x10; + super->x.HALF.HI = this->unk_6c - 0x10; context->unk_12 = 1; } - iVar4 = this->y.HALF.HI - (s16)this->field_0x6e.HWORD; + iVar4 = super->y.HALF.HI - (s16)this->unk_6e; if (0x10 < iVar4) { - this->y.HALF.HI = this->field_0x6e.HWORD + 0x10; + super->y.HALF.HI = this->unk_6e + 0x10; context->unk_12 = 1; } if (iVar4 < -0x10) { - this->y.HALF.HI = this->field_0x6e.HWORD - 0x10; + super->y.HALF.HI = this->unk_6e - 0x10; context->unk_12 = 1; } if (--context->unk_12 != 0) { @@ -701,9 +722,9 @@ void sub_08062948(Entity* this, ScriptExecutionContext* context) { } } -void Kid_MakeInteractable(Entity* this, ScriptExecutionContext* context) { - this->field_0x6a.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x6a.HALF.LO); +void Kid_MakeInteractable(KidEntity* this, ScriptExecutionContext* context) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Kid_Fusion(Entity* this) { diff --git a/src/npc/kingDaltus.c b/src/npc/kingDaltus.c index 3bdf60a24..b11a8a340 100644 --- a/src/npc/kingDaltus.c +++ b/src/npc/kingDaltus.c @@ -1,93 +1,105 @@ +/** + * @file kingDaltus.c + * @ingroup NPCs + * + * @brief King Daltus NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "script.h" #include "functions.h" -#include "npc.h" #include "item.h" +#include "npc.h" +#include "script.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} KingDaltusEntity; -void sub_08066654(Entity*); -void sub_08066688(Entity*); -void sub_080666DC(Entity*); -void sub_080666E4(Entity*); -void sub_0806670C(Entity*); -void sub_08066718(Entity*); +void sub_08066654(KingDaltusEntity*); +void sub_08066688(KingDaltusEntity*); +void sub_080666DC(KingDaltusEntity*); +void sub_080666E4(KingDaltusEntity*); +void sub_0806670C(KingDaltusEntity*); +void sub_08066718(KingDaltusEntity*); -void KingDaltus(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void KingDaltus(KingDaltusEntity* this) { + static void (*const actionFuncs[])(KingDaltusEntity*) = { sub_08066654, sub_08066688, sub_080666DC, }; - static void (*const scriptedActionFuncs[])(Entity*) = { + static void (*const scriptedActionFuncs[])(KingDaltusEntity*) = { sub_080666E4, sub_0806670C, sub_08066718, }; - if ((this->flags & ENT_SCRIPTED) != 0) { - if (this->interactType == 2) { - this->interactType = 0; - this->action = 2; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if ((super->flags & ENT_SCRIPTED) != 0) { + if (super->interactType == 2) { + super->interactType = 0; + super->action = 2; + InitAnimationForceUpdate(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } - scriptedActionFuncs[this->action](this); + scriptedActionFuncs[super->action](this); } else { - actionFuncs[this->action](this); - sub_0806ED78(this); + actionFuncs[super->action](this); + sub_0806ED78(super); } } -void sub_08066654(Entity* this) { - this->action = 1; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); - InitAnimationForceUpdate(this, 2); +void sub_08066654(KingDaltusEntity* this) { + super->action = 1; + super->spriteSettings.draw = 1; + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); + InitAnimationForceUpdate(super, 2); } -void sub_08066688(Entity* this) { - s32 tmp = GetAnimationStateInRectRadius(this, 0x28, 0x28); +void sub_08066688(KingDaltusEntity* this) { + s32 tmp = GetAnimationStateInRectRadius(super, 0x28, 0x28); if (tmp < 0) { tmp = 2; } else { - if (this->subtimer == 0) { - this->subtimer = 16; + if (super->subtimer == 0) { + super->subtimer = 16; } else { - this->subtimer--; - tmp = this->animIndex; + super->subtimer--; + tmp = super->animIndex; } } - if (sub_0806F078(this, tmp) == 0) { - UpdateAnimationSingleFrame(this); + if (sub_0806F078(super, tmp) == 0) { + UpdateAnimationSingleFrame(super); } - if (this->interactType != 0) { - this->action = 2; - this->interactType = 0; + if (super->interactType != 0) { + super->action = 2; + super->interactType = 0; } } -void sub_080666DC(Entity* this) { - this->action = 1; +void sub_080666DC(KingDaltusEntity* this) { + super->action = 1; } -void sub_080666E4(Entity* this) { - this->action = 1; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - sub_0807DD50(this); +void sub_080666E4(KingDaltusEntity* this) { + super->action = 1; + super->spriteSettings.draw = 1; + this->fusionOffer = GetFusionToOffer(super); + InitScriptForNPC(super); } -void sub_0806670C(Entity* this) { - sub_0807DD94(this, NULL); +void sub_0806670C(KingDaltusEntity* this) { + ExecuteScriptAndHandleAnimation(super, NULL); } -void sub_08066718(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; +void sub_08066718(KingDaltusEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; } } -void KingDaltus_MakeInteractable(Entity* this) { - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void KingDaltus_MakeInteractable(KingDaltusEntity* this) { + AddInteractableWhenBigFuser(super, this->fusionOffer); } void sub_0806673C(Entity* this) { diff --git a/src/npc/kingGustaf.c b/src/npc/kingGustaf.c index c09d7de0c..880441c8a 100644 --- a/src/npc/kingGustaf.c +++ b/src/npc/kingGustaf.c @@ -1,4 +1,10 @@ -#include "global.h" +/** + * @file kingGustaf.c + * @ingroup NPCs + * + * @brief King Gustaf NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "functions.h" #include "screen.h" @@ -11,13 +17,13 @@ void KingGustaf(Entity* this) { this->spriteRendering.alphaBlend = 1; this->collisionLayer = 2; SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + InitScriptForNPC(this); gScreen.controls.layerFXControl = 0x3f40; gScreen.controls.alphaBlend = 0x1000; this->speed = 0x1000; this->zVelocity = 0; } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(this, NULL); speed = 0x100; speed *= this->speed; speed += this->zVelocity; diff --git a/src/npc/librari.c b/src/npc/librari.c index e725b6696..0d8773167 100644 --- a/src/npc/librari.c +++ b/src/npc/librari.c @@ -1,33 +1,44 @@ -#include "global.h" +/** + * @file librari.c + * @ingroup NPCs + * + * @brief Librari NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "npc.h" #include "item.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} LibrariEntity; -void Librari(Entity* this) { - switch (this->action) { +void Librari(LibrariEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = TRUE; - this->animationState = this->timer; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = TRUE; + super->animationState = super->timer; + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); + SetDefaultPriority(super, PRIO_MESSAGE); + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - UpdateAnimationSingleFrame(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + UpdateAnimationSingleFrame(super); } break; case 2: - if (UpdateFuseInteraction(this)) { - this->action = 1; + if (UpdateFuseInteraction(super)) { + super->action = 1; } } } diff --git a/src/npc/librarians.c b/src/npc/librarians.c index 1a58777da..86558d16c 100644 --- a/src/npc/librarians.c +++ b/src/npc/librarians.c @@ -1,10 +1,17 @@ +/** + * @file librarians.c + * @ingroup NPCs + * + * @brief Librarians NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "script.h" -#include "functions.h" #include "flags.h" +#include "functions.h" +#include "item.h" #include "message.h" +#include "script.h" #include "sound.h" -#include "item.h" extern void sub_08095BE0(Entity*, u32); @@ -13,7 +20,7 @@ extern const u8 gUnk_08114F30[]; void Librarians(Entity* this) { if (this->action == 0) { this->action = 1; - sub_0807DD50(this); + InitScriptForNPC(this); this->spriteRendering.b3 = gUnk_08114F30[this->spriteRendering.b3]; } ExecuteScriptForEntity(this, NULL); diff --git a/src/npc/mailbox.c b/src/npc/mailbox.c index 5c92eefc8..afb295a9e 100644 --- a/src/npc/mailbox.c +++ b/src/npc/mailbox.c @@ -1,7 +1,13 @@ -#include "global.h" +/** + * @file mailbox.c + * @ingroup NPCs + * + * @brief Mailbox NPC + */ +#define NENT_DEPRECATED +#include "effects.h" #include "entity.h" #include "message.h" -#include "effects.h" #include "npc.h" void sub_08063280(Entity*); diff --git a/src/npc/malon.c b/src/npc/malon.c index 1ab967c0a..93365be67 100644 --- a/src/npc/malon.c +++ b/src/npc/malon.c @@ -1,30 +1,41 @@ -#include "global.h" +/** + * @file malon.c + * @ingroup NPCs + * + * @brief Malon NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "script.h" #include "npc.h" +#include "script.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} MalonEntity; void sub_08065864(Entity* this); void sub_08065880(Entity* this); -void sub_08065888(Entity* this); -void sub_080658BC(Entity* this); -void sub_08065900(Entity* this); +void sub_08065888(MalonEntity* this); +void sub_080658BC(MalonEntity* this); +void sub_08065900(MalonEntity* this); -void Malon(Entity* this) { +void Malon(MalonEntity* this) { static void (*const actionFuncs[])(Entity * this) = { sub_08065864, sub_08065880, }; - static void (*const scriptedActionFuncs[])(Entity * this) = { + static void (*const scriptedActionFuncs[])(MalonEntity * this) = { sub_08065888, sub_080658BC, sub_08065900, }; - if (this->flags & ENT_SCRIPTED) { - scriptedActionFuncs[this->action](this); + if (super->flags & ENT_SCRIPTED) { + scriptedActionFuncs[super->action](this); } else { - actionFuncs[this->action](this); - if (this->action != 0) { - sub_0806ED78(this); + actionFuncs[super->action](super); + if (super->action != 0) { + sub_0806ED78(super); } } } @@ -39,29 +50,29 @@ void sub_08065880(Entity* this) { UpdateAnimationSingleFrame(this); } -void sub_08065888(Entity* this) { - this->action = 1; - this->spriteSettings.draw = 1; - this->animationState = 4; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); - sub_0807DD50(this); +void sub_08065888(MalonEntity* this) { + super->action = 1; + super->spriteSettings.draw = 1; + super->animationState = 4; + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); + InitScriptForNPC(super); } -void sub_080658BC(Entity* this) { - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); +void sub_080658BC(MalonEntity* this) { + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitAnimationForceUpdate(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } } -void sub_08065900(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; +void sub_08065900(MalonEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; } } diff --git a/src/npc/mama.c b/src/npc/mama.c index 0e2b76203..11f40b150 100644 --- a/src/npc/mama.c +++ b/src/npc/mama.c @@ -1,7 +1,20 @@ +/** + * @file mama.c + * @ingroup NPCs + * + * @brief Mama NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "script.h" -#include "save.h" #include "npc.h" +#include "save.h" +#include "script.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; +} MamaEntity; static const SpriteLoadData gUnk_08113754[] = { { 0x101, 0x4e, 0x4 }, @@ -11,35 +24,35 @@ static const SpriteLoadData gUnk_08113754[] = { bool32 sub_0806C454(Entity* this); -void Mama(Entity* this) { - switch (this->action) { +void Mama(MamaEntity* this) { + switch (super->action) { case 0: - if (sub_0806C454(this) != 0) { - this->action = 1; - this->spriteSettings.draw = 1; - this->animationState = this->timer; - this->field_0x68.HALF.HI = 0; - sub_0807DD50(this); + if (sub_0806C454(super) != 0) { + super->action = 1; + super->spriteSettings.draw = 1; + super->animationState = super->timer; + this->animIndex = 0; + InitScriptForNPC(super); } break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + this->animIndex = super->animIndex; + InitializeAnimation(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - GetNextFrame(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + GetNextFrame(super); } break; case 2: - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitializeAnimation(this, this->field_0x68.HALF.HI); + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitializeAnimation(super, this->animIndex); } break; } @@ -92,9 +105,9 @@ void sub_0806C4DC(Entity* this) { ShowNPCDialogue(this, &dialogs[gSave.global_progress]); } -void Mama_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Mama_MakeInteractable(MamaEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Mama_Fusion(Entity* this) { diff --git a/src/npc/marcy.c b/src/npc/marcy.c index 57f979ddf..d30ef4419 100644 --- a/src/npc/marcy.c +++ b/src/npc/marcy.c @@ -1,8 +1,15 @@ +/** + * @file marcy.c + * @ingroup NPCs + * + * @brief Marcy NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "functions.h" #include "flags.h" -#include "message.h" +#include "functions.h" #include "item.h" +#include "message.h" void Marcy(Entity* this) { if (this->action == 0) { @@ -10,7 +17,7 @@ void Marcy(Entity* this) { SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD64(this); } - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(this, NULL); } void sub_08062D18(Entity* this, ScriptExecutionContext* context) { diff --git a/src/npc/mayorHagen.c b/src/npc/mayorHagen.c index e5e5cad3b..42a69dda6 100644 --- a/src/npc/mayorHagen.c +++ b/src/npc/mayorHagen.c @@ -1,38 +1,51 @@ -#include "global.h" +/** + * @file mayorHagen.c + * @ingroup NPCs + * + * @brief Mayor Hagen NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" #include "flags.h" -#include "npc.h" #include "item.h" +#include "npc.h" +#include "player.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; +} MayorHagenEntity; -void MayorHagen(Entity* this) { +void MayorHagen(MayorHagenEntity* this) { u32 v; - switch (this->action) { + switch (super->action) { case 0: - this->action = 1; - this->field_0x68.HALF.HI = 0; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + super->action = 1; + this->animIndex = 0; + this->fusionOffer = GetFusionToOffer(super); + SetDefaultPriority(super, PRIO_MESSAGE); + InitScriptForNPC(super); break; case 1: - v = this->interactType; + v = super->interactType; if (v == 2) { - this->action = v; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitAnimationForceUpdate(this, 4 + sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + super->action = v; + super->interactType = 0; + this->animIndex = super->animIndex; + InitAnimationForceUpdate(super, + 4 + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); break; } - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - UpdateAnimationSingleFrame(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + UpdateAnimationSingleFrame(super); break; case 2: - if (UpdateFuseInteraction(this)) { - this->action = 1; - InitAnimationForceUpdate(this, this->field_0x68.HALF.HI); + if (UpdateFuseInteraction(super)) { + super->action = 1; + InitAnimationForceUpdate(super, this->animIndex); } } } diff --git a/src/npc/melari.c b/src/npc/melari.c index 59760a787..43666e8dd 100644 --- a/src/npc/melari.c +++ b/src/npc/melari.c @@ -1,5 +1,17 @@ -#include "npc.h" +/** + * @file melari.c + * @ingroup NPCs + * + * @brief Melari NPC + */ +#define NENT_DEPRECATED #include "item.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} MelariEntity; void sub_08068780(Entity*); void sub_08068708(Entity*); @@ -67,13 +79,13 @@ void sub_08068780(Entity* this) { this->spriteSettings.draw = TRUE; this->animationState = this->type; SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + InitScriptForNPC(this); break; case 1: if (this->interactType == 2) { this->action = 2; this->interactType = 0; - sub_0806F118(this); + InitializeNPCFusion(this); } else { ExecuteScriptForEntity(this, NULL); HandleEntity0x82Actions(this); @@ -100,9 +112,9 @@ void sub_08068780(Entity* this) { } } -void Melari_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Melari_MakeInteractable(MelariEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Melari_Head(Entity* this) { @@ -136,7 +148,7 @@ void sub_08068910(Entity* this) { iVar1 = 0x10; } else { } - iVar1 = sub_0806F5A4(iVar1); + iVar1 = GetAnimationStateForDirection4(iVar1); InitializeAnimation(this, (this->animIndex & -0x4) + iVar1); } } diff --git a/src/npc/milkCart.c b/src/npc/milkCart.c index 5736b5b6d..37b7f54dd 100644 --- a/src/npc/milkCart.c +++ b/src/npc/milkCart.c @@ -1,3 +1,10 @@ +/** + * @file milkCart.c + * @ingroup NPCs + * + * @brief Milk Cart NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "npc.h" diff --git a/src/npc/minishEzlo.c b/src/npc/minishEzlo.c index 921452de5..2306f1076 100644 --- a/src/npc/minishEzlo.c +++ b/src/npc/minishEzlo.c @@ -1,16 +1,22 @@ +/** + * @file minishEzlo.c + * @ingroup NPCs + * + * @brief Minish Ezlo NPC + */ #define NENT_DEPRECATED #include "entity.h" -#include "sound.h" -#include "script.h" #include "npc.h" +#include "script.h" +#include "sound.h" typedef struct { - Entity base; - u32 filler; - union SplitWord field_0x6c; - u32 field_0x70; - u8 filler2[0xC]; - s16 field_0x80; + /*0x00*/ Entity base; + /*0x68*/ u32 filler; + /*0x6c*/ union SplitWord field_0x6c; + /*0x70*/ u32 field_0x70; + /*0x74*/ u8 filler2[0xC]; + /*0x80*/ s16 field_0x80; } MinishEzloEntity; extern void sub_0806FF10(Entity* this, u32 param_2, u32 param_3); @@ -28,7 +34,7 @@ void MinishEzlo(Entity* this) { this->action++; this->animationState = this->timer * 2; SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + InitScriptForNPC(this); } ExecuteScriptForEntity(this, NULL); HandleEntity0x82Actions(this); diff --git a/src/npc/ministerPotho.c b/src/npc/ministerPotho.c index fe5806c14..c56c67492 100644 --- a/src/npc/ministerPotho.c +++ b/src/npc/ministerPotho.c @@ -1,25 +1,37 @@ +/** + * @file ministerPotho.c + * @ingroup NPCs + * + * @brief Minister Potho NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "flags.h" +#include "item.h" #include "message.h" #include "npc.h" -#include "item.h" -void sub_08066864(Entity*); +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} MinisterPothoEntity; + +void sub_08066864(MinisterPothoEntity*); void sub_080667E4(Entity*); void sub_08066808(Entity*); void sub_0806685C(Entity*); -void MinisterPotho(Entity* this) { +void MinisterPotho(MinisterPothoEntity* this) { static void (*const actionFuncs[])(Entity*) = { sub_080667E4, sub_08066808, sub_0806685C, }; - if ((this->flags & ENT_SCRIPTED) != 0) { + if ((super->flags & ENT_SCRIPTED) != 0) { sub_08066864(this); } else { - actionFuncs[this->action](this); - sub_0806ED78(this); + actionFuncs[super->action](super); + sub_0806ED78(super); } } @@ -55,27 +67,28 @@ void sub_0806685C(Entity* this) { this->action = 1; } -void sub_08066864(Entity* this) { - switch (this->action) { +void sub_08066864(MinisterPothoEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = 1; + this->fusionOffer = GetFusionToOffer(super); + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; } break; } diff --git a/src/npc/moblinLady.c b/src/npc/moblinLady.c index 7aa448f18..2aa0e0b3e 100644 --- a/src/npc/moblinLady.c +++ b/src/npc/moblinLady.c @@ -1,11 +1,18 @@ +/** + * @file moblinLady.c + * @ingroup NPCs + * + * @brief Moblin Lady NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "npc.h" void MoblinLady(Entity* this) { if (this->action == 0) { this->action++; - sub_0807DD50(this); + InitScriptForNPC(this); } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(this, NULL); } } diff --git a/src/npc/mountainMinish.c b/src/npc/mountainMinish.c index 44739b9d3..0a3358511 100644 --- a/src/npc/mountainMinish.c +++ b/src/npc/mountainMinish.c @@ -1,10 +1,23 @@ +/** + * @file mountainMinish.c + * @ingroup NPCs + * + * @brief Mountain Minish NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "script.h" +#include "flags.h" #include "functions.h" +#include "item.h" #include "message.h" -#include "flags.h" #include "npc.h" -#include "item.h" +#include "script.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; +} MountainMinishEntity; const u8 gUnk_08111284[][0x20] = { { 0x8, 0x1, 0x9, 0x1, 0xa, 0x1, 0xb, 0x83, 0xc, 0x83, 0xd, 0x83, 0xe, 0x83, 0xf, 0x80, @@ -34,21 +47,21 @@ const SpriteLoadData gUnk_08111358[] = { { 0x0, 0x0, 0x0 }, }; -void sub_08067EF0(Entity*); +void sub_08067EF0(MountainMinishEntity*); void sub_08068190(Entity*); void sub_08067E60(Entity*); void sub_08067E88(Entity*); void sub_08067EE8(Entity*); -void MountainMinish(Entity* this) { +void MountainMinish(MountainMinishEntity* this) { static void (*const MountainMinish_Actions[])(Entity*) = { sub_08067E60, sub_08067E88, sub_08067EE8, }; - if ((this->flags & ENT_SCRIPTED) == 0) { - MountainMinish_Actions[this->action](this); - sub_0806ED78(this); + if ((super->flags & ENT_SCRIPTED) == 0) { + MountainMinish_Actions[super->action](super); + sub_0806ED78(super); } else { sub_08067EF0(this); } @@ -90,7 +103,7 @@ void sub_08067EE8(Entity* this) { this->action = 1; } -void sub_08067EF0(Entity* this) { +void sub_08067EF0(MountainMinishEntity* this) { static const u16 gUnk_08111374[] = { SFX_HAMMER1, SFX_HAMMER2, @@ -104,84 +117,85 @@ void sub_08067EF0(Entity* this) { }; Entity* fxEnt; - switch (this->action) { + switch (super->action) { case 0: - if (!LoadExtraSpriteData(this, gUnk_08111358)) { + if (!LoadExtraSpriteData(super, gUnk_08111358)) { return; } - this->action = 1; - this->spriteSettings.draw = 1; - this->animationState = this->type; - this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, 2); - sub_0807DD50(this); - InitializeAnimation(this, gUnk_08111304[this->type2]); + super->action = 1; + super->spriteSettings.draw = 1; + super->animationState = super->type; + this->animIndex = 0; + SetDefaultPriority(super, 2); + InitScriptForNPC(super); + InitializeAnimation(super, gUnk_08111304[super->type2]); break; case 1: - if (this->interactType == 2) { - this->action = 3; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 3; + super->interactType = 0; + this->animIndex = super->animIndex; + InitializeAnimation(super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, 0); - HandleEntity0x82Actions(this); - if ((this->type2 == 3) && (this->interactType != 0)) { - this->action = 2; - this->interactType = 0; - InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_08068190(this); + ExecuteScriptForEntity(super, 0); + HandleEntity0x82Actions(super); + if ((super->type2 == 3) && (super->interactType != 0)) { + super->action = 2; + super->interactType = 0; + InitializeAnimation(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + sub_08068190(super); } } break; case 2: if ((gMessage.doTextBox & 0x7f) != 0) break; - this->action = 1; - InitializeAnimation(this, (this->animationState >> 1) + 4); + super->action = 1; + InitializeAnimation(super, (super->animationState >> 1) + 4); break; case 3: - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitializeAnimation(this, this->field_0x68.HALF.HI); + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitializeAnimation(super, this->animIndex); } } - if (this->frameDuration != 0xff) { - GetNextFrame(this); + if (super->frameDuration != 0xff) { + GetNextFrame(super); } - if ((this->frameSpriteSettings & 1) != 0) { - this->frameSpriteSettings &= 0xfe; - if (CheckOnScreen(this) == 0) { + if ((super->frameSpriteSettings & 1) != 0) { + super->frameSpriteSettings &= 0xfe; + if (CheckOnScreen(super) == 0) { SoundReq(gUnk_0811137A[((s32)Random()) % 3]); } else { EnqueueSFX(gUnk_08111374[((s32)Random()) % 3]); } } - if ((this->frameSpriteSettings & 2) != 0) { - this->frameSpriteSettings &= ~2; - fxEnt = CreateFx(this, FX_ROCK, 0); + if ((super->frameSpriteSettings & 2) != 0) { + super->frameSpriteSettings &= ~2; + fxEnt = CreateFx(super, FX_ROCK, 0); if (fxEnt != NULL) { - PositionRelative(this, fxEnt, 0, Q_16_16(-24)); + PositionRelative(super, fxEnt, 0, Q_16_16(-24)); } } - if ((this->frameSpriteSettings & 4) != 0) { - this->frameSpriteSettings &= 0xfb; - fxEnt = CreateFx(this, FX_STARS2, 0x20); + if ((super->frameSpriteSettings & 4) != 0) { + super->frameSpriteSettings &= 0xfb; + fxEnt = CreateFx(super, FX_STARS2, 0x20); if (fxEnt != NULL) { - PositionRelative(this, fxEnt, Q_16_16(-20), Q_16_16(-10)); + PositionRelative(super, fxEnt, Q_16_16(-20), Q_16_16(-10)); } } - if ((this->frameSpriteSettings & 8) != 0) { - this->frameSpriteSettings &= 0xf7; - this->frameDuration += Random() & 0x1f; + if ((super->frameSpriteSettings & 8) != 0) { + super->frameSpriteSettings &= 0xf7; + super->frameDuration += Random() & 0x1f; } } -void MountainMinish_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void MountainMinish_MakeInteractable(MountainMinishEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void sub_0806811C(Entity* this) { @@ -205,7 +219,7 @@ void sub_0806811C(Entity* this) { bVar1 = ptr[0]; bVar2 = ptr[1]; if ((bVar2 & 0x80) != 0) { - this->animationState = sub_0806F5B0(iVar4); + this->animationState = GetAnimationStateForDirection8(iVar4); } this->frame = bVar1 | 0x40; this->frameIndex = bVar2 & 0x7f; diff --git a/src/npc/mutoh.c b/src/npc/mutoh.c index a93b7258c..833614cd1 100644 --- a/src/npc/mutoh.c +++ b/src/npc/mutoh.c @@ -1,10 +1,24 @@ -#include "global.h" + +/** + * @file mutoh.c + * @ingroup NPCs + * + * @brief Mutoh NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" #include "flags.h" +#include "item.h" #include "message.h" #include "npc.h" -#include "item.h" +#include "player.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unused[27]; + /*0x84*/ ScriptExecutionContext* context; +} MutohEntity; static const SpriteLoadData gUnk_08110C00[] = { { 0x51, 0x3e, 0x4 }, @@ -12,33 +26,34 @@ static const SpriteLoadData gUnk_08110C00[] = { { 0, 0, 0 }, }; -void Mutoh(Entity* this) { - if (*(u32*)&this->cutsceneBeh == 0) { +void Mutoh(MutohEntity* this) { + if (this->context == NULL) { DeleteThisEntity(); } - switch (this->action) { + switch (super->action) { case 0: - if (LoadExtraSpriteData(this, gUnk_08110C00)) { - this->action = 1; - this->spriteSettings.draw = TRUE; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + if (LoadExtraSpriteData(super, gUnk_08110C00)) { + super->action = 1; + super->spriteSettings.draw = TRUE; + SetDefaultPriority(super, PRIO_MESSAGE); + InitScriptForNPC(super); } break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 4); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) + 4); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this)) { - this->action = 1; + if (UpdateFuseInteraction(super)) { + super->action = 1; } } } @@ -82,9 +97,9 @@ void sub_080670E4(Entity* this) { ShowNPCDialogue(this, &dialogs[gSave.global_progress]); } -void Mutoh_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Mutoh_MakeInteractable(MutohEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Mutoh_Fusion(Entity* this) { diff --git a/src/npc/nayru.c b/src/npc/nayru.c index b9ea0df47..d56d6dfad 100644 --- a/src/npc/nayru.c +++ b/src/npc/nayru.c @@ -1,30 +1,42 @@ -#include "global.h" +/** + * @file nayru.c + * @ingroup NPCs + * + * @brief Nayru NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "npc.h" #include "kinstone.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 animIndex; +} NayruEntity; -void Nayru(Entity* this) { - switch (this->action) { +void Nayru(NayruEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = 1; + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - sub_0806F118(this); - this->field_0x68.HALF.LO = this->animIndex; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitializeNPCFusion(super); + this->animIndex = super->animIndex; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitAnimationForceUpdate(this, this->field_0x68.HALF.LO); + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitAnimationForceUpdate(super, this->animIndex); } break; } diff --git a/src/npc/npc23.c b/src/npc/npc23.c index a07b14b14..846c1bdef 100644 --- a/src/npc/npc23.c +++ b/src/npc/npc23.c @@ -1,122 +1,138 @@ +/** + * @file npc23.c + * @ingroup NPCs + * + * @brief NPC 23 + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" -#include "structures.h" #include "functions.h" #include "message.h" #include "npc.h" +#include "player.h" +#include "structures.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unused[22]; + /*0x7e*/ u16 unk_7e; + /*0x80*/ u16 unk_80; + /*0x82*/ u16 unk_82; + /*0x84*/ u16 unk_84; + /*0x86*/ u16 unk_86; +} NPC23Entity; -bool32 sub_0806650C(Entity*); +bool32 sub_0806650C(NPC23Entity*); -void sub_08066490(Entity*, Entity*); +void sub_08066490(NPC23Entity*, Entity*); void sub_08066570(Entity* this); -void sub_080662F8(Entity* this); -void sub_08066358(Entity* this); -void nullsub_110(Entity* this); -void sub_080663D4(Entity* this); -void sub_0806643C(Entity* this); -void sub_08066474(Entity* this); - -void NPC23(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void sub_080662F8(NPC23Entity* this); +void sub_08066358(NPC23Entity* this); +void nullsub_110(NPC23Entity* this); +void sub_080663D4(NPC23Entity* this); +void sub_0806643C(NPC23Entity* this); +void sub_08066474(NPC23Entity* this); + +void NPC23(NPC23Entity* this) { + static void (*const actionFuncs[])(NPC23Entity*) = { sub_080662F8, sub_08066358, nullsub_110, sub_080663D4, sub_0806643C, sub_08066474, }; - actionFuncs[this->action](this); - sub_0806ED78(this); + actionFuncs[super->action](this); + sub_0806ED78(super); } -void sub_080662F8(Entity* this) { - this->action = 1; - this->subAction = 0; - this->spriteSettings.draw = 1; - this->animationState = this->type << 1; - InitializeAnimation(this, this->type); - this->field_0x7c.HALF.HI = this->x.HALF.HI; - this->field_0x80.HWORD = this->y.HALF.HI; - this->field_0x86.HWORD = 0; - this->field_0x82.HWORD = this->timer; - this->parent = &gPlayerEntity; - this->cutsceneBeh.HWORD = 0; - sub_08066490(this, this->parent); - AddInteractableWhenBigObject(this); +void sub_080662F8(NPC23Entity* this) { + super->action = 1; + super->subAction = 0; + super->spriteSettings.draw = 1; + super->animationState = super->type << 1; + InitializeAnimation(super, super->type); + this->unk_7e = super->x.HALF.HI; + this->unk_80 = super->y.HALF.HI; + this->unk_86 = 0; + this->unk_82 = super->timer; + super->parent = &gPlayerEntity; + this->unk_84 = 0; + sub_08066490(this, super->parent); + AddInteractableWhenBigObject(super); } -void sub_08066358(Entity* this) { - if (this->interactType != 0) { - this->interactType = 0; +void sub_08066358(NPC23Entity* this) { + if (super->interactType != 0) { + super->interactType = 0; MessageFromTarget(0); - if ((this->type2 & 0x10) != 0) { - this->action = 3; - this->subAction = 0; - if ((this->field_0x7c.HALF_U.HI - this->x.HALF.HI) > 8) { - this->direction = 8; + if ((super->type2 & 0x10) != 0) { + super->action = 3; + super->subAction = 0; + if ((this->unk_7e - super->x.HALF.HI) > 8) { + super->direction = 8; } else { - this->direction = 0x18; + super->direction = 0x18; } - this->speed = 0x80; - this->cutsceneBeh.HWORD = 1; + super->speed = 0x80; + this->unk_84 = 1; gPauseMenuOptions.disabled = 1; - RemoveInteractableObject(this); + RemoveInteractableObject(super); } } else { - sub_08066490(this, this->parent); + sub_08066490(this, super->parent); } - GetNextFrame(this); - sub_08066570(this); + GetNextFrame(super); + sub_08066570(super); } -void nullsub_110(Entity* this) { +void nullsub_110(NPC23Entity* this) { } -void sub_080663D4(Entity* this) { - if (this->x.HALF.HI == this->field_0x7c.HALF_U.HI - 8) { +void sub_080663D4(NPC23Entity* this) { + if (super->x.HALF.HI == this->unk_7e - 8) { if (gPlayerEntity.action != PLAYER_ROOM_EXIT) { - this->action = 4; - this->direction = 0; - this->speed = 0; - this->cutsceneBeh.HWORD = 0; - InitializeAnimation(this, 2); + super->action = 4; + super->direction = 0; + super->speed = 0; + this->unk_84 = 0; + InitializeAnimation(super, 2); } } else { - if (this->subAction == 0) { - InitializeAnimation(this, (this->direction >> 3) + 4); - this->subAction = this->subAction + 1; + if (super->subAction == 0) { + InitializeAnimation(super, (super->direction >> 3) + 4); + super->subAction = super->subAction + 1; } - ProcessMovement0(this); + ProcessMovement0(super); } sub_08078B48(); - GetNextFrame(this); + GetNextFrame(super); } -void sub_0806643C(Entity* this) { - bool32 tmp = sub_0806650C(this); - if (tmp == FALSE) { - this->action = 5; +void sub_0806643C(NPC23Entity* this) { + if (!sub_0806650C(this)) { + super->action = 5; gRoomControls.camera_target = NULL; sub_08078AC0(0x40, 0, 0); gPlayerEntity.animationState = 0; gPlayerEntity.direction = 0; } - GetNextFrame(this); + GetNextFrame(super); } -void sub_08066474(Entity* this) { +void sub_08066474(NPC23Entity* this) { if (gPlayerEntity.action != PLAYER_ROOM_EXIT) { gPauseMenuOptions.disabled = 0; } } -NONMATCH("asm/non_matching/npc23/sub_08066490.inc", void sub_08066490(Entity* this, Entity* entity)) { +NONMATCH("asm/non_matching/npc23/sub_08066490.inc", void sub_08066490(NPC23Entity* this, Entity* entity)) { u32 uVar1; u32 uVar2; u32 uVar3; u32 uVar4; - if ((this->type2 & 0x10) != 0) { - this->field_0x86.HWORD = this->x.HALF.HI; - uVar2 = this->field_0x7c.HALF_U.HI; - uVar3 = uVar2 + this->field_0x82.HWORD; - uVar4 = uVar2 - this->field_0x82.HWORD; + if ((super->type2 & 0x10) != 0) { + this->unk_86 = super->x.HALF.HI; + uVar2 = this->unk_7e; + uVar3 = uVar2 + this->unk_82; + uVar4 = uVar2 - this->unk_82; if (((entity->x.HALF.HI < (int)uVar3) && (entity->x.HALF.HI > (int)uVar4))) { uVar2 = entity->x.HALF.HI; } else { @@ -127,35 +143,35 @@ NONMATCH("asm/non_matching/npc23/sub_08066490.inc", void sub_08066490(Entity* th } } - if (this->field_0x86.HWORD == uVar2) { - if (this->cutsceneBeh.HWORD == 1) { - this->cutsceneBeh.HWORD = 0; - InitializeAnimation(this, 2); + if (this->unk_86 == uVar2) { + if (this->unk_84 == 1) { + this->unk_84 = 0; + InitializeAnimation(super, 2); } } else { - this->x.HALF.HI = (short)uVar2; - if (this->cutsceneBeh.HWORD == 0) { - this->cutsceneBeh.HWORD = 1; - InitializeAnimation(this, 6); + super->x.HALF.HI = (short)uVar2; + if (this->unk_84 == 0) { + this->unk_84 = 1; + InitializeAnimation(super, 6); } } } } END_NONMATCH -bool32 sub_0806650C(Entity* this) { +bool32 sub_0806650C(NPC23Entity* this) { u32 dir = 0; s32 px = gPlayerEntity.x.HALF_U.HI; s32 px2 = px; s32 py = gPlayerEntity.y.HALF_U.HI; - if (py < this->field_0x80.HWORD + 16) { + if (py < this->unk_80 + 16) { dir = 4; } else { - if (px < this->field_0x7c.HALF_U.HI + 2) { + if (px < this->unk_7e + 2) { dir = 2; } - if (px2 > this->field_0x7c.HALF_U.HI + 6) { + if (px2 > this->unk_7e + 6) { dir = 6; } if (dir == 0) { diff --git a/src/npc/npc26.c b/src/npc/npc26.c index fddbf4602..ff7754eeb 100644 --- a/src/npc/npc26.c +++ b/src/npc/npc26.c @@ -1,4 +1,10 @@ -#include "global.h" +/** + * @file npc26.c + * @ingroup NPCs + * + * @brief NPC 26 + */ +#define NENT_DEPRECATED #include "entity.h" #include "npc.h" @@ -53,11 +59,11 @@ static void sub_08066A30(Entity* this) { static void sub_08066A38(Entity* this) { this->action = 1; this->spriteSettings.draw = 1; - sub_0807DD50(this); + InitScriptForNPC(this); } static void sub_08066A50(Entity* this) { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(this, NULL); } static void (*const gUnk_081106D4[])(Entity*) = { sub_080669B8, sub_080669DC, sub_08066A30 }; diff --git a/src/npc/npc4E.c b/src/npc/npc4E.c index cdfd7abe7..910fb485c 100644 --- a/src/npc/npc4E.c +++ b/src/npc/npc4E.c @@ -1,3 +1,10 @@ +/** + * @file npc4E.c + * @ingroup NPCs + * + * @brief NPC 4E + */ +#define NENT_DEPRECATED #include "entity.h" #include "flags.h" #include "functions.h" @@ -11,6 +18,12 @@ #include "screenTransitions.h" #include "sound.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unk_68; + /*0x69*/ u8 unk_69; +} NPC4EEntity; + typedef struct { Rect customHitbox; u8 interactDirections; @@ -37,9 +50,9 @@ void NPC4E(Entity* this) { this->action = 1; this->spriteSettings.draw = 4; this->hitbox = (Hitbox*)&gHitbox_2; - sub_0807DD50(this); + InitScriptForNPC(this); } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(this, NULL); } } @@ -131,17 +144,19 @@ void NPC4E_IsEveryPinwheelActivated(Entity* this, ScriptExecutionContext* contex } void sub_0806DB84(Entity* this, ScriptExecutionContext* context) { - Entity* ent; + GenericEntity* ent; this->hitbox = (Hitbox*)&gUnk_08114154; - ent = CreateObject(MINISH_VILLAGE_OBJECT, 4, 0); + ent = (GenericEntity*)CreateObject(MINISH_VILLAGE_OBJECT, 4, 0); if (ent != NULL) { - PositionRelative(this, ent, Q_16_16(-8.0), 0); - *(ScriptExecutionContext**)&ent->cutsceneBeh = StartCutscene(ent, &script_MinishVillageObjectLeftStoneOpening); + PositionRelative(this, &ent->base, Q_16_16(-8.0), 0); + *(ScriptExecutionContext**)&ent->cutsceneBeh = + StartCutscene(&ent->base, &script_MinishVillageObjectLeftStoneOpening); } - ent = CreateObject(MINISH_VILLAGE_OBJECT, 5, 0); + ent = (GenericEntity*)CreateObject(MINISH_VILLAGE_OBJECT, 5, 0); if (ent != NULL) { - PositionRelative(this, ent, Q_16_16(8.0), 0); - *(ScriptExecutionContext**)&ent->cutsceneBeh = StartCutscene(ent, &script_MinishVillageObjectRightStoneOpening); + PositionRelative(this, &ent->base, Q_16_16(8.0), 0); + *(ScriptExecutionContext**)&ent->cutsceneBeh = + StartCutscene(&ent->base, &script_MinishVillageObjectRightStoneOpening); } } @@ -170,14 +185,14 @@ Item NPC4E_GetItemWithSwordUpgraded(Item itemId) { return itemId; } -void NPC4E_SaveEquippedItems(Entity* this) { - this->field_0x68.HALF.LO = gSave.stats.itemButtons[SLOT_A]; - this->field_0x68.HALF.HI = gSave.stats.itemButtons[SLOT_B]; +void NPC4E_SaveEquippedItems(NPC4EEntity* this) { + this->unk_68 = gSave.stats.itemButtons[SLOT_A]; + this->unk_69 = gSave.stats.itemButtons[SLOT_B]; } -void NPC4E_RestoreEquippedItems(Entity* this) { - ForceEquipItem(NPC4E_GetItemWithSwordUpgraded(this->field_0x68.HALF.LO), EQUIP_SLOT_A); - ForceEquipItem(NPC4E_GetItemWithSwordUpgraded(this->field_0x68.HALF.HI), EQUIP_SLOT_B); +void NPC4E_RestoreEquippedItems(NPC4EEntity* this) { + ForceEquipItem(NPC4E_GetItemWithSwordUpgraded(this->unk_68), EQUIP_SLOT_A); + ForceEquipItem(NPC4E_GetItemWithSwordUpgraded(this->unk_69), EQUIP_SLOT_B); } void sub_0806DC7C(void) { diff --git a/src/npc/npc4F.c b/src/npc/npc4F.c index 69cee66da..baaf9e4e0 100644 --- a/src/npc/npc4F.c +++ b/src/npc/npc4F.c @@ -1,3 +1,10 @@ +/** + * @file npc4F.c + * @ingroup NPCs + * + * @brief NPC 4F + */ +#define NENT_DEPRECATED #include "npc.h" void NPC4F(Entity* this) { diff --git a/src/npc/npc5.c b/src/npc/npc5.c index f8e6707e4..2527fdc0a 100644 --- a/src/npc/npc5.c +++ b/src/npc/npc5.c @@ -1,8 +1,27 @@ +/** + * @file npc5.c + * @ingroup NPCs + * + * @brief NPC 5 + */ +#define NENT_DEPRECATED +#include "collision.h" #include "functions.h" +#include "hitbox.h" #include "message.h" #include "npc.h" -#include "hitbox.h" -#include "collision.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u16* unk_68; + /*0x6c*/ u8 unk_6c; + /*0x6d*/ u8 unused1; + /*0x6e*/ u16 unk_6e; + /*0x70*/ u8 unused2[4]; + /*0x74*/ u16 unk_74; + /*0x76*/ u8 unused3[2]; + /*0x78*/ Entity* unk_78; +} NPC5Entity; typedef struct { u8 unk_0; // u8 @@ -17,34 +36,34 @@ typedef struct { u16 unk_8; // u16 } UnkHeap; -void sub_08060E70(Entity*, u32); +void sub_08060E70(NPC5Entity*, u32); -u32 sub_08061230(Entity*); +u32 sub_08061230(NPC5Entity*); u32 sub_08060F80(Entity*); -void sub_08060EDC(Entity*); -void sub_08061090(Entity*, u32, u32); +void sub_08060EDC(NPC5Entity*); +void sub_08061090(NPC5Entity*, u32, u32); bool32 sub_08060FD0(Entity*, u32, u32); -void sub_08061464(Entity*, u32, u32); -void sub_08061120(Entity*, u32, u32, u32); -bool32 sub_08061170(Entity*); +void sub_08061464(NPC5Entity*, u32, u32); +void sub_08061120(NPC5Entity*, u32, u32, u32); +bool32 sub_08061170(NPC5Entity*); -void sub_08061358(Entity*); +void sub_08061358(NPC5Entity*); void sub_08060E94(Entity*); -void sub_08060A00(Entity*); -void sub_08061AA0(Entity*); -void sub_08061AA8(Entity*); -void sub_08061B58(Entity*); -void sub_08060AE0(Entity*); -void sub_08060B5C(Entity*); -void sub_08060BA0(Entity*); -void sub_08060D78(Entity*); -void sub_08060DD0(Entity*); -void sub_08060DF4(Entity*); -void sub_08060DFC(Entity*); -void sub_08060E34(Entity*); -void sub_08061ACC(Entity*); -void sub_08061B18(Entity*); +void sub_08060A00(NPC5Entity*); +void sub_08061AA0(NPC5Entity*); +void sub_08061AA8(NPC5Entity*); +void sub_08061B58(NPC5Entity*); +void sub_08060AE0(NPC5Entity*); +void sub_08060B5C(NPC5Entity*); +void sub_08060BA0(NPC5Entity*); +void sub_08060D78(NPC5Entity*); +void sub_08060DD0(NPC5Entity*); +void sub_08060DF4(NPC5Entity*); +void sub_08060DFC(NPC5Entity*); +void sub_08060E34(NPC5Entity*); +void sub_08061ACC(NPC5Entity*); +void sub_08061B18(NPC5Entity*); u32 PointInsideRadius(s32, s32, s32); @@ -52,14 +71,14 @@ u32 sub_080611D4(Entity*); extern u32 sub_08079FD4(Entity*, u32); extern void sub_08016AD2(Entity*); -bool32 sub_08061630(Entity*, s32, s32, s32); -bool32 sub_08061720(Entity*, s32, s32, s32); -bool32 sub_080616A8(Entity*, s32, s32, s32); -bool32 sub_08061798(Entity*, s32, s32, s32); -bool32 sub_08061888(Entity*, s32, s32, s32); -bool32 sub_08061978(Entity*, s32, s32, s32); -bool32 sub_08061810(Entity*, s32, s32, s32); -bool32 sub_08061900(Entity*, s32, s32, s32); +bool32 sub_08061630(NPC5Entity*, s32, s32, s32); +bool32 sub_08061720(NPC5Entity*, s32, s32, s32); +bool32 sub_080616A8(NPC5Entity*, s32, s32, s32); +bool32 sub_08061798(NPC5Entity*, s32, s32, s32); +bool32 sub_08061888(NPC5Entity*, s32, s32, s32); +bool32 sub_08061978(NPC5Entity*, s32, s32, s32); +bool32 sub_08061810(NPC5Entity*, s32, s32, s32); +bool32 sub_08061900(NPC5Entity*, s32, s32, s32); bool32 sub_08061A74(u8*, s32, s32, s32); @@ -69,7 +88,7 @@ bool32 sub_080619F0(u8*, s32, s32, s32); bool32 sub_08061A48(u8*, s32, s32, s32); -void sub_08061AFC(Entity*); +void sub_08061AFC(NPC5Entity*); extern u16* gUnk_0810B660[8]; @@ -86,119 +105,120 @@ void CreateZeldaFollower(void) { } // UNUSED zelda follower, probably because it was too resource heavy -void NPC5(Entity* this) { - static void (*const gUnk_0810AC1C[])(Entity*) = { +void NPC5(NPC5Entity* this) { + static void (*const gUnk_0810AC1C[])(NPC5Entity*) = { sub_08060A00, sub_08061AA0, sub_08061AA8, sub_08061B58, }; - gUnk_0810AC1C[this->type](this); + gUnk_0810AC1C[super->type](this); } -void sub_08060A00(Entity* this) { - static void (*const Npc5_Actions[])(Entity*) = { +void sub_08060A00(NPC5Entity* this) { + static void (*const Npc5_Actions[])(NPC5Entity*) = { sub_08060AE0, sub_08060B5C, sub_08060BA0, sub_08060D78, sub_08060DD0, sub_08060DF4, sub_08060DFC, sub_08060E34, }; u32 tmp; if ((gPlayerState.jump_status & 0x80) != 0) { - if (this->action != 0) { - if (((((UnkHeap*)this->myHeap)->unk_0) & 4) == 0) { - ((UnkHeap*)this->myHeap)->unk_0 |= 4; - ((UnkHeap*)this->myHeap)->unk_5 = (gPlayerEntity.x.HALF.HI & 0xfff0) + 8; - ((UnkHeap*)this->myHeap)->unk_6 = (gPlayerEntity.y.HALF.HI & 0xfff0) + 8; + if (super->action != 0) { + if (((((UnkHeap*)super->myHeap)->unk_0) & 4) == 0) { + ((UnkHeap*)super->myHeap)->unk_0 |= 4; + ((UnkHeap*)super->myHeap)->unk_5 = (gPlayerEntity.x.HALF.HI & 0xfff0) + 8; + ((UnkHeap*)super->myHeap)->unk_6 = (gPlayerEntity.y.HALF.HI & 0xfff0) + 8; } } } - if ((this->action == 0) || (this->spriteSettings.draw != 0)) { - Npc5_Actions[this->action](this); + if ((super->action == 0) || (super->spriteSettings.draw != 0)) { + Npc5_Actions[super->action](this); } - if (this->action != 0) { - ((UnkHeap*)this->myHeap)->unk_1 = gPlayerEntity.x.HALF.HI; - ((UnkHeap*)this->myHeap)->unk_2 = gPlayerEntity.y.HALF.HI; + if (super->action != 0) { + ((UnkHeap*)super->myHeap)->unk_1 = gPlayerEntity.x.HALF.HI; + ((UnkHeap*)super->myHeap)->unk_2 = gPlayerEntity.y.HALF.HI; } - if (this->field_0x74.HWORD != gRoomControls.room) { - this->field_0x74.HWORD = gRoomControls.room; - CopyPosition(&gPlayerEntity, this); - this->action = 1; - this->spriteSettings.draw = 1; - this->speed = 0x120; + if (this->unk_74 != gRoomControls.room) { + this->unk_74 = gRoomControls.room; + CopyPosition(&gPlayerEntity, super); + super->action = 1; + super->spriteSettings.draw = 1; + super->speed = 0x120; tmp = gRoomControls.scroll_direction; - this->animationState = tmp * 2; - InitAnimationForceUpdate(this, tmp << 0x19 >> 0x19); // TODO some conversion between u8 and u32? - this->frameDuration = (Random() & 0x7f) + 0x80; - ((UnkHeap*)this->myHeap)->unk_0 &= 0xfb; + super->animationState = tmp * 2; + InitAnimationForceUpdate(super, tmp << 0x19 >> 0x19); // TODO some conversion between u8 and u32? + super->frameDuration = (Random() & 0x7f) + 0x80; + ((UnkHeap*)super->myHeap)->unk_0 &= 0xfb; } } -void sub_08060AE0(Entity* this) { +void sub_08060AE0(NPC5Entity* this) { UnkHeap* heapObj; Entity* otherNpc; heapObj = (UnkHeap*)zMalloc(0x14); // TODO UnkHeap struct should have size 0x14? if (heapObj != NULL) { - this->myHeap = (u32*)heapObj; + super->myHeap = (u32*)heapObj; heapObj->unk_0b = 0x20; - this->action = 1; - COLLISION_ON(this); - this->animationState &= 3; - this->collisionFlags = 7; - this->hurtType = 0x48; - this->hitType = 0x49; - this->flags2 = 3; - this->hitbox = (Hitbox*)&gHitbox_0; - this->followerFlag &= 0xfe; - this->field_0x6c.HALF.LO = 0xff; - sub_08060E70(this, this->animationState); + super->action = 1; + COLLISION_ON(super); + super->animationState &= 3; + super->collisionFlags = 7; + super->hurtType = 0x48; + super->hitType = 0x49; + super->flags2 = 3; + super->hitbox = (Hitbox*)&gHitbox_0; + super->followerFlag &= 0xfe; + this->unk_6c = 0xff; + sub_08060E70(this, super->animationState); otherNpc = CreateNPC(NPC_UNK_5, 2, 0); if (otherNpc != NULL) { - otherNpc->parent = this; - *(Entity**)&this->field_0x78 = otherNpc; + otherNpc->parent = super; + this->unk_78 = otherNpc; } } } -void sub_08060B5C(Entity* this) { +void sub_08060B5C(NPC5Entity* this) { if (sub_08061230(this) == 0) { - if ((sub_08060F80(this) == 0) && - (((GetFacingDirection(this, &gPlayerEntity) + (this->animationState * -4) + 4) & 0x1f)) < 9) { - this->action = 2; - this->subtimer = 0; + if ((sub_08060F80(super) == 0) && + (((GetFacingDirection(super, &gPlayerEntity) + (super->animationState * -4) + 4) & 0x1f)) < 9) { + super->action = 2; + super->subtimer = 0; return; } sub_08060EDC(this); } } -void sub_08060BA0(Entity* this) { +void sub_08060BA0(NPC5Entity* this) { Entity* r5; //! @bug: r5 is uninitialized if (sub_08061230(this) != 0) { return; } - if ((((UnkHeap*)this->myHeap)->unk_0 & 4) != 0) { - if ((((UnkHeap*)this->myHeap)->unk_0 & 8) != 0) { - this->speed = 0x1e0; - sub_08061120(this, ((UnkHeap*)this->myHeap)->unk_7, ((UnkHeap*)this->myHeap)->unk_8, 0xc); + if ((((UnkHeap*)super->myHeap)->unk_0 & 4) != 0) { + if ((((UnkHeap*)super->myHeap)->unk_0 & 8) != 0) { + super->speed = 0x1e0; + sub_08061120(this, ((UnkHeap*)super->myHeap)->unk_7, ((UnkHeap*)super->myHeap)->unk_8, 0xc); sub_08061170(this); - if (EntityWithinDistance(this, ((UnkHeap*)this->myHeap)->unk_7, ((UnkHeap*)this->myHeap)->unk_8, 4) != 0) { - ((UnkHeap*)this->myHeap)->unk_0 &= 0xf7; + if (EntityWithinDistance(super, ((UnkHeap*)super->myHeap)->unk_7, ((UnkHeap*)super->myHeap)->unk_8, 4) != + 0) { + ((UnkHeap*)super->myHeap)->unk_0 &= 0xf7; } } else { - if (sub_08060FD0(this, ((UnkHeap*)this->myHeap)->unk_5, ((UnkHeap*)this->myHeap)->unk_6) != 0) { - if (EntityWithinDistance(this, ((UnkHeap*)this->myHeap)->unk_5, ((UnkHeap*)this->myHeap)->unk_6, 4) != - 0) { - ((UnkHeap*)this->myHeap)->unk_0 &= 0xfb; - this->action = 5; - this->direction = r5->direction; - this->speed = 0x160; + if (sub_08060FD0(super, ((UnkHeap*)super->myHeap)->unk_5, ((UnkHeap*)super->myHeap)->unk_6) != 0) { + if (EntityWithinDistance(super, ((UnkHeap*)super->myHeap)->unk_5, ((UnkHeap*)super->myHeap)->unk_6, + 4) != 0) { + ((UnkHeap*)super->myHeap)->unk_0 &= 0xfb; + super->action = 5; + super->direction = r5->direction; + super->speed = 0x160; sub_08060E70(this, 8); } else { - this->speed = 0x1e0; + super->speed = 0x1e0; sub_08061120(this, r5->x.HALF.HI, r5->y.HALF.HI, 0xc); sub_08061170(this); } @@ -208,104 +228,104 @@ void sub_08060BA0(Entity* this) { } } else { - if (sub_08060FD0(this, gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI) != 0) { + if (sub_08060FD0(super, gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI) != 0) { sub_08061090(this, gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI); sub_08061170(this); - ((UnkHeap*)this->myHeap)->unk_0 &= 0xf5; + ((UnkHeap*)super->myHeap)->unk_0 &= 0xf5; } else { - ((UnkHeap*)this->myHeap) = (UnkHeap*)this->myHeap; - if ((((UnkHeap*)this->myHeap)->unk_0 & 8) != 0) { - this->speed = 0x1e0; - sub_08061120(this, ((UnkHeap*)this->myHeap)->unk_7, ((UnkHeap*)this->myHeap)->unk_8, 0xc); + ((UnkHeap*)super->myHeap) = (UnkHeap*)super->myHeap; + if ((((UnkHeap*)super->myHeap)->unk_0 & 8) != 0) { + super->speed = 0x1e0; + sub_08061120(this, ((UnkHeap*)super->myHeap)->unk_7, ((UnkHeap*)super->myHeap)->unk_8, 0xc); sub_08061170(this); - if (EntityWithinDistance(this, ((UnkHeap*)this->myHeap)->unk_7, ((UnkHeap*)this->myHeap)->unk_8, 4) != - 0) { - ((UnkHeap*)this->myHeap)->unk_0 &= 0xf7; + if (EntityWithinDistance(super, ((UnkHeap*)super->myHeap)->unk_7, ((UnkHeap*)super->myHeap)->unk_8, + 4) != 0) { + ((UnkHeap*)super->myHeap)->unk_0 &= 0xf7; } } else { - if ((((UnkHeap*)this->myHeap)->unk_0 & 2) == 0) { - ((UnkHeap*)this->myHeap)->unk_0 |= 2; - ((UnkHeap*)this->myHeap)->unk_3 = ((UnkHeap*)this->myHeap)->unk_1; - ((UnkHeap*)this->myHeap)->unk_4 = ((UnkHeap*)this->myHeap)->unk_2; + if ((((UnkHeap*)super->myHeap)->unk_0 & 2) == 0) { + ((UnkHeap*)super->myHeap)->unk_0 |= 2; + ((UnkHeap*)super->myHeap)->unk_3 = ((UnkHeap*)super->myHeap)->unk_1; + ((UnkHeap*)super->myHeap)->unk_4 = ((UnkHeap*)super->myHeap)->unk_2; } - if (sub_08060FD0(this, ((UnkHeap*)this->myHeap)->unk_3, ((UnkHeap*)this->myHeap)->unk_4) != 0) { - this->speed = 0x1e0; - sub_08061120(this, ((UnkHeap*)this->myHeap)->unk_3, ((UnkHeap*)this->myHeap)->unk_4, 0xc); + if (sub_08060FD0(super, ((UnkHeap*)super->myHeap)->unk_3, ((UnkHeap*)super->myHeap)->unk_4) != 0) { + super->speed = 0x1e0; + sub_08061120(this, ((UnkHeap*)super->myHeap)->unk_3, ((UnkHeap*)super->myHeap)->unk_4, 0xc); sub_08061170(this); - if (EntityWithinDistance(this, ((UnkHeap*)this->myHeap)->unk_3, ((UnkHeap*)this->myHeap)->unk_4, + if (EntityWithinDistance(super, ((UnkHeap*)super->myHeap)->unk_3, ((UnkHeap*)super->myHeap)->unk_4, 4) != 0) { - ((UnkHeap*)this->myHeap)->unk_0 &= 0xfd; + ((UnkHeap*)super->myHeap)->unk_0 &= 0xfd; } } else { - ((UnkHeap*)this->myHeap)->unk_0 &= 0xfd; + ((UnkHeap*)super->myHeap)->unk_0 &= 0xfd; sub_08061464(this, gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI); } } } } - if (sub_08060F80(this) != 0) { - this->action = 1; - ((UnkHeap*)this->myHeap)->unk_0 &= 0xfb; + if (sub_08060F80(super) != 0) { + super->action = 1; + ((UnkHeap*)super->myHeap)->unk_0 &= 0xfb; sub_08060E70(this, 0); } } -void sub_08060D78(Entity* this) { +void sub_08060D78(NPC5Entity* this) { sub_08061358(this); - if (sub_08060F80(this) != 0) { - if ((u32)this->animIndex - 0x20 < 0x10) { - if ((this->frame & 7) != 0) { - this->frameDuration = 1; - UpdateAnimationSingleFrame(this); + if (sub_08060F80(super) != 0) { + if ((u32)super->animIndex - 0x20 < 0x10) { + if ((super->frame & 7) != 0) { + super->frameDuration = 1; + UpdateAnimationSingleFrame(super); } - this->animationState = this->frame & 0x18; - this->field_0x6c.HALF.LO = 0xff; + super->animationState = super->frame & 0x18; + this->unk_6c = 0xff; } - this->action = 1; + super->action = 1; sub_08060E70(this, 0); } } -void sub_08060DD0(Entity* this) { - UpdateAnimationSingleFrame(this); - if ((this->frame & ANIM_DONE) != 0) { - this->action = 1; +void sub_08060DD0(NPC5Entity* this) { + UpdateAnimationSingleFrame(super); + if ((super->frame & ANIM_DONE) != 0) { + super->action = 1; sub_08060E70(this, 0); } } -void sub_08060DF4(Entity* this) { +void sub_08060DF4(NPC5Entity* this) { sub_08061170(this); } -void sub_08060DFC(Entity* this) { +void sub_08060DFC(NPC5Entity* this) { u32 uVar1; - LinearMoveUpdate(this); - sub_08060E94(this); - uVar1 = GravityUpdate(this, Q_8_8(32.0)); + LinearMoveUpdate(super); + sub_08060E94(super); + uVar1 = GravityUpdate(super, Q_8_8(32.0)); if (uVar1 == 0) { - this->action = 7; - this->collisionLayer = 1; - UpdateSpriteForCollisionLayer(this); + super->action = 7; + super->collisionLayer = 1; + UpdateSpriteForCollisionLayer(super); sub_08060E70(this, 0x1c); } } -void sub_08060E34(Entity* this) { - UpdateAnimationSingleFrame(this); - if ((this->frame & ANIM_DONE) != 0) { - this->action = 2; - this->animationState = DirectionToAnimationState(GetFacingDirection(this, &gPlayerEntity)) * 2; +void sub_08060E34(NPC5Entity* this) { + UpdateAnimationSingleFrame(super); + if ((super->frame & ANIM_DONE) != 0) { + super->action = 2; + super->animationState = DirectionToAnimationState(GetFacingDirection(super, &gPlayerEntity)) * 2; sub_08060E70(this, 8); } } -void sub_08060E70(Entity* this, u32 param) { - u32 tmp = param + this->animationState / 2; - if (tmp != this->animIndex) { - this->field_0x6c.HALF.LO = param; - InitAnimationForceUpdate(this, tmp); +void sub_08060E70(NPC5Entity* this, u32 param) { + u32 tmp = param + super->animationState / 2; + if (tmp != super->animIndex) { + this->unk_6c = param; + InitAnimationForceUpdate(super, tmp); } } @@ -318,27 +338,27 @@ void sub_08060E94(Entity* this) { } } -void sub_08060EDC(Entity* this) { +void sub_08060EDC(NPC5Entity* this) { s32 tmp; - if (((u32)this->animIndex - 0x20 < 0x10) && ((this->frame & ANIM_DONE) == 0)) { - UpdateAnimationSingleFrame(this); + if (((u32)super->animIndex - 0x20 < 0x10) && ((super->frame & ANIM_DONE) == 0)) { + UpdateAnimationSingleFrame(super); } else { - tmp = GetFacingDirection(this, &gPlayerEntity) + this->animationState * -4; + tmp = GetFacingDirection(super, &gPlayerEntity) + super->animationState * -4; if (((tmp + 3) & 0x1f) >= 7) { if ((tmp & 0x1f) < 0x10) { - InitAnimationForceUpdate(this, this->animationState + 0x20); - this->animationState = (this->animationState + 1) & 7; + InitAnimationForceUpdate(super, super->animationState + 0x20); + super->animationState = (super->animationState + 1) & 7; } else { - InitAnimationForceUpdate(this, this->animationState + 0x28); - this->animationState = (this->animationState - 1) & 7; + InitAnimationForceUpdate(super, super->animationState + 0x28); + super->animationState = (super->animationState - 1) & 7; } } else { - if ((this->animationState & 1) == 0) { - if (((this->frame & ANIM_DONE) != 0) && (0xf >= (u32)this->animIndex - 0x20)) { + if ((super->animationState & 1) == 0) { + if (((super->frame & ANIM_DONE) != 0) && (0xf >= (u32)super->animIndex - 0x20)) { sub_08060E70(this, 0); } else { - sub_08060E94(this); + sub_08060E94(super); } } } @@ -391,27 +411,27 @@ bool32 sub_08060FD0(Entity* this, u32 a, u32 b) { } } -void sub_08061090(Entity* this, u32 a, u32 b) { +void sub_08061090(NPC5Entity* this, u32 a, u32 b) { s32 xDist; s32 yDist; s32 sqrDist; u32 tmp; - xDist = gPlayerEntity.x.HALF.HI - this->x.HALF.HI; - yDist = gPlayerEntity.y.HALF.HI - this->y.HALF.HI; + xDist = gPlayerEntity.x.HALF.HI - super->x.HALF.HI; + yDist = gPlayerEntity.y.HALF.HI - super->y.HALF.HI; sqrDist = (xDist * xDist) + (yDist * yDist); if (sqrDist < 0x900) { - this->speed = 0x120; + super->speed = 0x120; } else { if (sqrDist < 0x1900) { - this->speed = ((sqrDist - 0x900) >> 4) + 0x120; + super->speed = ((sqrDist - 0x900) >> 4) + 0x120; } else { - this->speed = 0x220; + super->speed = 0x220; } } - if (this->speed == 0x120) { + if (super->speed == 0x120) { tmp = 4; - } else if (this->speed < 0x160) { + } else if (super->speed < 0x160) { tmp = 8; } else { tmp = 0xc; @@ -419,31 +439,31 @@ void sub_08061090(Entity* this, u32 a, u32 b) { sub_08061120(this, a, b, tmp); } -void sub_08061120(Entity* this, u32 param_a, u32 param_b, u32 param_c) { - this->direction = CalculateDirectionTo(this->x.HALF.HI, this->y.HALF.HI, param_a, param_b); - if ((param_c != this->field_0x6c.HALF.LO) || (10 < ((this->direction + this->animationState * -4 + 5) & 0x1f))) { - this->animationState = DirectionRoundUp(this->direction) >> 2; +void sub_08061120(NPC5Entity* this, u32 param_a, u32 param_b, u32 param_c) { + super->direction = CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, param_a, param_b); + if ((param_c != this->unk_6c) || (10 < ((super->direction + super->animationState * -4 + 5) & 0x1f))) { + super->animationState = DirectionRoundUp(super->direction) >> 2; sub_08060E70(this, param_c); } } -bool32 sub_08061170(Entity* this) { +bool32 sub_08061170(NPC5Entity* this) { u32 direction; u32 tmp; - UpdateAnimationSingleFrame(this); - if (ProcessMovement6(this) == 0) { - direction = sub_080611D4(this); + UpdateAnimationSingleFrame(super); + if (ProcessMovement6(super) == 0) { + direction = sub_080611D4(super); if (direction != 0xff) { - this->action = 6; - tmp = (sub_08079FD4(this, 1)); + super->action = 6; + tmp = (sub_08079FD4(super, 1)); tmp <<= 4; tmp -= 4; tmp = tmp << 0xc; - this->zVelocity = tmp; - this->speed = 0x100; - this->direction = direction; - this->animationState = direction >> 2; + super->zVelocity = tmp; + super->speed = 0x100; + super->direction = direction; + super->animationState = direction >> 2; if (tmp >> 0x10 != 0) { sub_08060E70(this, 0x14); } else { @@ -452,7 +472,7 @@ bool32 sub_08061170(Entity* this) { } return FALSE; } else { - sub_08016AD2(this); + sub_08016AD2(super); return TRUE; } } @@ -504,10 +524,10 @@ u32 sub_080611D4(Entity* this) { return 0xff; } -u32 sub_08061230(Entity* this) { - if ((((UnkHeap*)this->myHeap)->unk_0 & 1) == 0) { - if ((this->contactFlags & 0x80) != 0) { - switch (this->contactFlags & 0x7f) { +u32 sub_08061230(NPC5Entity* this) { + if ((((UnkHeap*)super->myHeap)->unk_0 & 1) == 0) { + if ((super->contactFlags & 0x80) != 0) { + switch (super->contactFlags & 0x7f) { case 0: case 1: case 2: @@ -519,176 +539,176 @@ u32 sub_08061230(Entity* this) { case 0x1f: break; default: - ((UnkHeap*)this->myHeap)->unk_0 = ((UnkHeap*)this->myHeap)->unk_0 | 1; - InitAnimationForceUpdate(this, (this->animationState >> 1) + 0x40); + ((UnkHeap*)super->myHeap)->unk_0 = ((UnkHeap*)super->myHeap)->unk_0 | 1; + InitAnimationForceUpdate(super, (super->animationState >> 1) + 0x40); return 1; } } } else { - UpdateAnimationSingleFrame(this); - if ((this->frame & ANIM_DONE) == 0) { + UpdateAnimationSingleFrame(super); + if ((super->frame & ANIM_DONE) == 0) { return 1; } - ((UnkHeap*)this->myHeap)->unk_0 &= 0xfe; - InitAnimationForceUpdate(this, this->field_0x6c.HALF.LO + (this->animationState >> 1)); + ((UnkHeap*)super->myHeap)->unk_0 &= 0xfe; + InitAnimationForceUpdate(super, this->unk_6c + (super->animationState >> 1)); } - this->contactFlags = this->contactFlags & 0x7f; - if (this->iframes != 0) { - this->iframes++; + super->contactFlags = super->contactFlags & 0x7f; + if (super->iframes != 0) { + super->iframes++; } return 0; } -void sub_08061358(Entity* this) { +void sub_08061358(NPC5Entity* this) { static const u8 gUnk_0810AC5D[] = { 0x30, 0x31, 0x38, 0x39, 0x32, 0x33, 0x3a, 0x3b, 0x34, 0x35, 0x3c, 0x3d, 0x36, 0x37, 0x3e, 0x3f, 0x0, 0x0, 0x0, }; u32 uVar2; u32 bVar4; - switch (this->subAction) { + switch (super->subAction) { case 0: - UpdateAnimationSingleFrame(this); - if ((this->frame & ANIM_DONE) == 0) { + UpdateAnimationSingleFrame(super); + if ((super->frame & ANIM_DONE) == 0) { return; } - this->subAction = 1; - this->timer = 15; + super->subAction = 1; + super->timer = 15; sub_08060E70(this, 0); break; case 1: - this->timer--; - if (this->timer != 0) { + super->timer--; + if (super->timer != 0) { return; } uVar2 = Random(); bVar4 = uVar2; if ((uVar2 & 1) == 0) { - this->subAction = 3; - this->timer = (bVar4 & 0x18) + 30; + super->subAction = 3; + super->timer = (bVar4 & 0x18) + 30; sub_08060E70(this, 4); return; } - this->subAction = 2; - InitAnimationForceUpdate(this, gUnk_0810AC5D[(u32)this->animationState * 2 + ((uVar2 >> 4) & 3)]); + super->subAction = 2; + InitAnimationForceUpdate(super, gUnk_0810AC5D[(u32)super->animationState * 2 + ((uVar2 >> 4) & 3)]); break; case 2: - UpdateAnimationSingleFrame(this); - if ((this->frame & ANIM_DONE) == 0) { + UpdateAnimationSingleFrame(super); + if ((super->frame & ANIM_DONE) == 0) { return; } - this->animationState = ((this->frame & 0x18) >> 2); + super->animationState = ((super->frame & 0x18) >> 2); if ((Random() & 1)) { - this->subAction = 3; - this->timer = (bVar4 & 0x18) + 30; + super->subAction = 3; + super->timer = (bVar4 & 0x18) + 30; sub_08060E70(this, 4); return; } - this->subAction = 0; + super->subAction = 0; sub_08060E70(this, 0x10); break; case 3: if (sub_08061170(this) == 0) { - this->subAction = 2; + super->subAction = 2; //! @bug bVar4 (r6) is uninitialized. - InitAnimationForceUpdate(this, gUnk_0810AC5D[this->animationState * 2 + (bVar4 >> 4 & 3)]); + InitAnimationForceUpdate(super, gUnk_0810AC5D[super->animationState * 2 + (bVar4 >> 4 & 3)]); return; } - if (--this->timer != 0) { + if (--super->timer != 0) { return; } - this->subAction = 0; + super->subAction = 0; sub_08060E70(this, 0x10); break; } } -void sub_08061464(Entity* this, u32 param_a, u32 param_b) { +void sub_08061464(NPC5Entity* this, u32 param_a, u32 param_b) { s32 iVar10; s32 iVar9; u32 bVar1; - iVar10 = this->x.HALF.HI; - iVar9 = this->y.HALF.HI; + iVar10 = super->x.HALF.HI; + iVar9 = super->y.HALF.HI; - switch (((CalculateDirectionTo(this->x.HALF.HI, this->y.HALF.HI, param_a, param_b) + 2) & 0x1c) >> 2) { + switch (((CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, param_a, param_b) + 2) & 0x1c) >> 2) { case 0: - this->field_0x6e.HWORD = param_b; - if (this->x.HALF.HI > (s32)param_a) { + this->unk_6e = param_b; + if (super->x.HALF.HI > (s32)param_a) { sub_08061630(this, iVar10, iVar9 + -8, param_a); break; } sub_080616A8(this, iVar10, iVar9 + -8, param_a); break; case 1: - this->field_0x6e.HWORD = param_a; + this->unk_6e = param_a; if (sub_08061720(this, iVar10 + 8, iVar9, param_b) != 0) break; - this->field_0x6e.HWORD = param_b; + this->unk_6e = param_b; sub_080616A8(this, iVar10, iVar9 + -8, param_a); break; case 2: - this->field_0x6e.HWORD = param_a; - if (this->y.HALF.HI > (s32)param_b) { + this->unk_6e = param_a; + if (super->y.HALF.HI > (s32)param_b) { sub_08061720(this, iVar10 + 8, iVar9, param_b); } else { sub_08061798(this, iVar10 + 8, iVar9, param_b); } break; case 3: - this->field_0x6e.HWORD = param_a; + this->unk_6e = param_a; if (sub_08061798(this, iVar10 + 8, iVar9, param_b) != 0) break; - this->field_0x6e.HWORD = param_b; + this->unk_6e = param_b; sub_08061888(this, iVar10, iVar9 + 8, param_a); break; case 4: - this->field_0x6e.HWORD = param_b; - if (this->x.HALF.HI > (s32)param_a) { + this->unk_6e = param_b; + if (super->x.HALF.HI > (s32)param_a) { sub_08061810(this, iVar10, iVar9 + 8, param_a); break; } sub_08061888(this, iVar10, iVar9 + 8, param_a); break; case 5: - this->field_0x6e.HWORD = param_a; + this->unk_6e = param_a; if (sub_08061978(this, iVar10 + -8, iVar9, param_b) != 0) break; - this->field_0x6e.HWORD = param_b; + this->unk_6e = param_b; sub_08061810(this, iVar10, iVar9 + 8, param_a); break; case 6: - this->field_0x6e.HWORD = param_a; - if (this->y.HALF.HI > (s32)param_b) { + this->unk_6e = param_a; + if (super->y.HALF.HI > (s32)param_b) { sub_08061900(this, iVar10 + -8, iVar9, param_b); } else { sub_08061978(this, iVar10 + -8, iVar9, param_b); } break; case 7: - this->field_0x6e.HWORD = param_a; + this->unk_6e = param_a; if (sub_08061900(this, iVar10 + -8, iVar9, param_b) == 0) { - this->field_0x6e.HWORD = param_b; + this->unk_6e = param_b; sub_08061630(this, iVar10, iVar9 + -8, param_a); } } - bVar1 = ((UnkHeap*)this->myHeap)->unk_0 & 8; + bVar1 = ((UnkHeap*)super->myHeap)->unk_0 & 8; if (bVar1 == 0) { - this->action = 3; - this->subAction = bVar1; + super->action = 3; + super->subAction = bVar1; } } -bool32 sub_08061630(Entity* this, s32 x, s32 y, s32 param) { +bool32 sub_08061630(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_y = y; - u8* layer = (this->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; + u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { if (sub_08061A74(layer, x, y, param)) { - ((UnkHeap*)this->myHeap)->unk_7 = x; - ((UnkHeap*)this->myHeap)->unk_8 = param_y; - ((UnkHeap*)this->myHeap)->unk_0 |= 8; - if (this->field_0x6e.HWORD >= y) { + ((UnkHeap*)super->myHeap)->unk_7 = x; + ((UnkHeap*)super->myHeap)->unk_8 = param_y; + ((UnkHeap*)super->myHeap)->unk_0 |= 8; + if (this->unk_6e >= y) { return TRUE; } } @@ -697,15 +717,15 @@ bool32 sub_08061630(Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_080616A8(Entity* this, s32 x, s32 y, s32 param) { +bool32 sub_080616A8(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_y = y; - u8* layer = (this->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; + u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { if (sub_08061A1C(layer, x, y, param)) { - ((UnkHeap*)this->myHeap)->unk_7 = x; - ((UnkHeap*)this->myHeap)->unk_8 = param_y; - ((UnkHeap*)this->myHeap)->unk_0 |= 8; - if (this->field_0x6e.HWORD >= y) { + ((UnkHeap*)super->myHeap)->unk_7 = x; + ((UnkHeap*)super->myHeap)->unk_8 = param_y; + ((UnkHeap*)super->myHeap)->unk_0 |= 8; + if (this->unk_6e >= y) { return TRUE; } } @@ -714,15 +734,15 @@ bool32 sub_080616A8(Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061720(Entity* this, s32 x, s32 y, s32 param) { +bool32 sub_08061720(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_x = x; - u8* layer = (this->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; + u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { if (sub_080619F0(layer, x, y, param)) { - ((UnkHeap*)this->myHeap)->unk_7 = param_x; - ((UnkHeap*)this->myHeap)->unk_8 = y; - ((UnkHeap*)this->myHeap)->unk_0 |= 8; - if (this->field_0x6e.HWORD <= x) { + ((UnkHeap*)super->myHeap)->unk_7 = param_x; + ((UnkHeap*)super->myHeap)->unk_8 = y; + ((UnkHeap*)super->myHeap)->unk_0 |= 8; + if (this->unk_6e <= x) { return TRUE; } } @@ -731,15 +751,15 @@ bool32 sub_08061720(Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061798(Entity* this, s32 x, s32 y, s32 param) { +bool32 sub_08061798(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_x = x; - u8* layer = (this->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; + u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { if (sub_08061A48(layer, x, y, param)) { - ((UnkHeap*)this->myHeap)->unk_7 = param_x; - ((UnkHeap*)this->myHeap)->unk_8 = y; - ((UnkHeap*)this->myHeap)->unk_0 |= 8; - if (this->field_0x6e.HWORD <= x) { + ((UnkHeap*)super->myHeap)->unk_7 = param_x; + ((UnkHeap*)super->myHeap)->unk_8 = y; + ((UnkHeap*)super->myHeap)->unk_0 |= 8; + if (this->unk_6e <= x) { return TRUE; } } @@ -748,15 +768,15 @@ bool32 sub_08061798(Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061810(Entity* this, s32 x, s32 y, s32 param) { +bool32 sub_08061810(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_y = y; - u8* layer = (this->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; + u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { if (sub_08061A74(layer, x, y, param)) { - ((UnkHeap*)this->myHeap)->unk_7 = x; - ((UnkHeap*)this->myHeap)->unk_8 = param_y; - ((UnkHeap*)this->myHeap)->unk_0 |= 8; - if (this->field_0x6e.HWORD <= y) { + ((UnkHeap*)super->myHeap)->unk_7 = x; + ((UnkHeap*)super->myHeap)->unk_8 = param_y; + ((UnkHeap*)super->myHeap)->unk_0 |= 8; + if (this->unk_6e <= y) { return TRUE; } } @@ -765,15 +785,15 @@ bool32 sub_08061810(Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061888(Entity* this, s32 x, s32 y, s32 param) { +bool32 sub_08061888(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_y = y; - u8* layer = (this->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; + u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { if (sub_08061A1C(layer, x, y, param)) { - ((UnkHeap*)this->myHeap)->unk_7 = x; - ((UnkHeap*)this->myHeap)->unk_8 = param_y; - ((UnkHeap*)this->myHeap)->unk_0 |= 8; - if (this->field_0x6e.HWORD <= y) { + ((UnkHeap*)super->myHeap)->unk_7 = x; + ((UnkHeap*)super->myHeap)->unk_8 = param_y; + ((UnkHeap*)super->myHeap)->unk_0 |= 8; + if (this->unk_6e <= y) { return TRUE; } } @@ -782,15 +802,15 @@ bool32 sub_08061888(Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061900(Entity* this, s32 x, s32 y, s32 param) { +bool32 sub_08061900(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_x = x; - u8* layer = (this->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; + u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { if (sub_080619F0(layer, x, y, param)) { - ((UnkHeap*)this->myHeap)->unk_7 = param_x; - ((UnkHeap*)this->myHeap)->unk_8 = y; - ((UnkHeap*)this->myHeap)->unk_0 |= 8; - if (this->field_0x6e.HWORD >= x) { + ((UnkHeap*)super->myHeap)->unk_7 = param_x; + ((UnkHeap*)super->myHeap)->unk_8 = y; + ((UnkHeap*)super->myHeap)->unk_0 |= 8; + if (this->unk_6e >= x) { return TRUE; } } @@ -799,15 +819,15 @@ bool32 sub_08061900(Entity* this, s32 x, s32 y, s32 param) { return FALSE; } -bool32 sub_08061978(Entity* this, s32 x, s32 y, s32 param) { +bool32 sub_08061978(NPC5Entity* this, s32 x, s32 y, s32 param) { u32 param_x = x; - u8* layer = (this->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; + u8* layer = (super->collisionLayer == 2) ? gMapTop.collisionData : gMapBottom.collisionData; while (!IsTileCollision(layer, x, y, 6)) { if (sub_08061A48(layer, x, y, param)) { - ((UnkHeap*)this->myHeap)->unk_7 = param_x; - ((UnkHeap*)this->myHeap)->unk_8 = y; - ((UnkHeap*)this->myHeap)->unk_0 |= 8; - if (this->field_0x6e.HWORD >= x) { + ((UnkHeap*)super->myHeap)->unk_7 = param_x; + ((UnkHeap*)super->myHeap)->unk_8 = y; + ((UnkHeap*)super->myHeap)->unk_0 |= 8; + if (this->unk_6e >= x) { return TRUE; } } @@ -856,64 +876,64 @@ bool32 sub_08061A74(u8* layer, s32 x, s32 y, s32 param) { return TRUE; } -void sub_08061AA0(Entity* this) { +void sub_08061AA0(NPC5Entity* this) { DeleteThisEntity(); } -void sub_08061AA8(Entity* this) { - static void (*const gUnk_0810AC70[])(Entity*) = { +void sub_08061AA8(NPC5Entity* this) { + static void (*const gUnk_0810AC70[])(NPC5Entity*) = { sub_08061ACC, sub_08061B18, }; - gUnk_0810AC70[this->action](this); - CopyPosition(this->parent, this); + gUnk_0810AC70[super->action](this); + CopyPosition(super->parent, super); } -void sub_08061ACC(Entity* this) { - this->flags = this->flags | ENT_PERSIST; - this->action = 1; - this->subAction = 0xff; - this->timer = 0; - this->followerFlag = this->followerFlag & 0xfe; - AddInteractableWhenBigObject(this); +void sub_08061ACC(NPC5Entity* this) { + super->flags = super->flags | ENT_PERSIST; + super->action = 1; + super->subAction = 0xff; + super->timer = 0; + super->followerFlag = super->followerFlag & 0xfe; + AddInteractableWhenBigObject(super); sub_08061AFC(this); } -void sub_08061AFC(Entity* this) { +void sub_08061AFC(NPC5Entity* this) { u32 tmp = 0; - if (this->subAction != 0) { - this->subAction = tmp; - *((u16**)&this->field_0x68) = gUnk_0810B660[0]; - this->timer = 0; + if (super->subAction != 0) { + super->subAction = tmp; + this->unk_68 = gUnk_0810B660[0]; + super->timer = 0; } } -void sub_08061B18(Entity* this) { +void sub_08061B18(NPC5Entity* this) { u16* puVar2; - switch (this->interactType) { + switch (super->interactType) { case 0: break; case 1: - this->interactType = 0; + super->interactType = 0; sub_08061AFC(this); - puVar2 = *(u16**)&this->field_0x68; - puVar2 += (this->timer++); + puVar2 = this->unk_68; + puVar2 += (super->timer++); if (puVar2[1] == 0) { - this->timer = 0; + super->timer = 0; } - MessageNoOverlap(puVar2[0], this); + MessageNoOverlap(puVar2[0], super); break; } } -void sub_08061B58(Entity* this) { - if (this->action == 0) { - this->action = 1; - InitAnimationForceUpdate(this, 2); +void sub_08061B58(NPC5Entity* this) { + if (super->action == 0) { + super->action = 1; + InitAnimationForceUpdate(super, 2); } if (gRoomTransition.entity_update_type == 2) { - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } - sub_0806FD3C(this); + sub_0806FD3C(super); } diff --git a/src/npc/npc58.c b/src/npc/npc58.c index 0409dc4fe..53f841f7a 100644 --- a/src/npc/npc58.c +++ b/src/npc/npc58.c @@ -1,41 +1,55 @@ +/** + * @file npc58.c + * @ingroup NPCs + * + * @brief NPC 58 + */ +#define NENT_DEPRECATED #include "entity.h" #include "npc.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ s16 unk_68; + /*0x6a*/ s16 unk_6a; + /*0x6c*/ s16 unk_6c; +} NPC58Entity; + extern void sub_0806FFBC(Entity*, u32, u32, u32); static const SpriteLoadData gUnk_081146D0[] = { { 0, 0x61, 0x4 }, { 0x800, 0x61, 0x4 }, { 0x1000, 0x61, 0x4 }, { 0x1800, 0x61, 0x4 }, { 0, 0, 0 }, }; -void NPC58(Entity* this) { +void NPC58(NPC58Entity* this) { s32 sVar1; s32 uVar2; s32 uVar4; - Entity* entity; + GenericEntity* entity; - if (this->action == 0) { - if (!LoadExtraSpriteData(this, gUnk_081146D0)) { + if (super->action == 0) { + if (!LoadExtraSpriteData(super, gUnk_081146D0)) { return; } - this->action++; - this->spriteSettings.draw = 2; - this->spriteRendering.b3 = 0; - this->spritePriority.b0 = 0; - this->spriteOrientation.flipY = 1; - this->x.HALF.HI = 0x78; - this->y.HALF.HI = 0x10; + super->action++; + super->spriteSettings.draw = 2; + super->spriteRendering.b3 = 0; + super->spritePriority.b0 = 0; + super->spriteOrientation.flipY = 1; + super->x.HALF.HI = 0x78; + super->y.HALF.HI = 0x10; } - entity = this->parent; + entity = (GenericEntity*)super->parent; if (entity != NULL) { sVar1 = *(s16*)&entity->field_0x68.HWORD; uVar2 = (s32)sVar1 / 600; - this->field_0x68.HWORD = uVar2; + this->unk_68 = uVar2; uVar4 = (s32)sVar1 % 600; - this->field_0x6a.HWORD = uVar4 / 0x3c; + this->unk_6a = uVar4 / 0x3c; uVar4 = uVar4 % 0x3c; uVar2 = uVar4 / 6; - this->field_0x6c.HWORD = uVar2; - if (entity->next == NULL) { + this->unk_6c = uVar2; + if (entity->base.next == NULL) { DeleteThisEntity(); } } else { @@ -43,14 +57,14 @@ void NPC58(Entity* this) { } } -void NPC58_Head(Entity* this) { - this->frameIndex = 0xff; - SetExtraSpriteFrame(this, 0, (s16)this->field_0x68.HWORD); - SetExtraSpriteFrame(this, 1, (s16)this->field_0x6a.HWORD); - SetExtraSpriteFrame(this, 2, (s16)this->field_0x6c.HWORD); - SetExtraSpriteFrame(this, 3, 10); - sub_0806FFBC(this, 0, -12, 0); - sub_0806FFBC(this, 1, -4, 0); - sub_0806FFBC(this, 2, 0xc, 0); - sub_0807000C(this); +void NPC58_Head(NPC58Entity* this) { + super->frameIndex = 0xff; + SetExtraSpriteFrame(super, 0, this->unk_68); + SetExtraSpriteFrame(super, 1, this->unk_6a); + SetExtraSpriteFrame(super, 2, this->unk_6c); + SetExtraSpriteFrame(super, 3, 10); + sub_0806FFBC(super, 0, -12, 0); + sub_0806FFBC(super, 1, -4, 0); + sub_0806FFBC(super, 2, 0xc, 0); + sub_0807000C(super); } diff --git a/src/npc/npc9.c b/src/npc/npc9.c index a8361648c..cf1fd130d 100644 --- a/src/npc/npc9.c +++ b/src/npc/npc9.c @@ -1,4 +1,10 @@ -#include "global.h" +/** + * @file npc9.c + * @ingroup NPCs + * + * @brief NPC 9 + */ +#define NENT_DEPRECATED #include "entity.h" #include "message.h" #include "npc.h" diff --git a/src/npc/percy.c b/src/npc/percy.c index 145bbea75..c8647de7c 100644 --- a/src/npc/percy.c +++ b/src/npc/percy.c @@ -1,9 +1,22 @@ -#include "global.h" +/** + * @file percy.c + * @ingroup NPCs + * + * @brief Percy NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "npc.h" #include "functions.h" -#include "kinstone.h" #include "item.h" +#include "kinstone.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unused[27]; + /*0x84*/ ScriptExecutionContext* context; +} PercyEntity; static const SpriteLoadData gUnk_08112E1C[] = { { 0x30f6, 0x47, 0x4 }, @@ -11,7 +24,7 @@ static const SpriteLoadData gUnk_08112E1C[] = { { 0x1cf6, 0x47, 0x4 }, { 0, 0, 0 }, }; -void sub_0806B41C(Entity*); +void sub_0806B41C(PercyEntity*); void sub_0806B3CC(Entity*); void sub_0806B504(Entity*); void sub_0806B540(Entity*); @@ -27,11 +40,11 @@ void Percy_Head(Entity* this) { sub_0807000C(this); } -void Percy(Entity* this) { - if ((this->flags & ENT_SCRIPTED) != 0) { +void Percy(PercyEntity* this) { + if ((super->flags & ENT_SCRIPTED) != 0) { sub_0806B41C(this); } else { - sub_0806B3CC(this); + sub_0806B3CC(super); } } @@ -52,39 +65,40 @@ void sub_0806B3CC(Entity* this) { sub_0806ED78(this); } -void sub_0806B41C(Entity* this) { +void sub_0806B41C(PercyEntity* this) { u16* tmp; u32 idx; - switch (this->action) { + switch (super->action) { case 0: - if (LoadExtraSpriteData(this, gUnk_08112E1C)) { - this->action = 1; - this->spriteSettings.draw = 1; - if (this->type2 == 2) { - CreateFx(this, FX_SWEAT, 0); + if (LoadExtraSpriteData(super, gUnk_08112E1C)) { + super->action = 1; + super->spriteSettings.draw = 1; + if (super->type2 == 2) { + CreateFx(super, FX_SWEAT, 0); } - sub_0807DD50(this); + InitScriptForNPC(super); } break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 4); - idx = GetFuserId(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + InitializeAnimation(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) + 4); + idx = GetFuserId(super); tmp = gUnk_08001A7C[idx]; - if (this->field_0x68.HALF.LO == 33) + if (this->fusionOffer == 33) tmp += 3; - sub_0801DFB4(this, tmp[0], tmp[1], tmp[2]); + InitializeFuseInfo(super, tmp[0], tmp[1], tmp[2]); gPlayerState.controlMode = CONTROL_DISABLED; } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this)) { - this->action = 1; + if (UpdateFuseInteraction(super)) { + super->action = 1; } break; } @@ -124,7 +138,7 @@ void sub_0806B504(Entity* this) { void sub_0806B540(Entity* this) { ScriptExecutionContext* context; - context = *(ScriptExecutionContext**)&this->cutsceneBeh; + context = ((PercyEntity*)this)->context; switch (context->unk_18) { case 0: MessageNoOverlap(TEXT_INDEX(TEXT_PERCY, 0x12), this); @@ -162,9 +176,9 @@ void sub_0806B540(Entity* this) { gActiveScriptInfo.commandSize = 0; } -void Percy_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Percy_MakeInteractable(PercyEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Percy_Fusion(Entity* this) { diff --git a/src/npc/phonograph.c b/src/npc/phonograph.c index 071f5b6e4..bd25c4060 100644 --- a/src/npc/phonograph.c +++ b/src/npc/phonograph.c @@ -1,29 +1,43 @@ +/** + * @file phonograph.c + * @ingroup NPCs + * + * @brief Phonograph NPC + */ +#define NENT_DEPRECATED +#include "common.h" #include "entity.h" -#include "script.h" -#include "functions.h" #include "fileselect.h" -#include "screen.h" -#include "common.h" #include "flags.h" +#include "functions.h" #include "message.h" +#include "screen.h" +#include "script.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ s16 unk_68; + /*0x6a*/ s16 unk_6a; + /*0x6c*/ s16 unk_6c; +} PhonographEntity; #ifdef EU -void sub_0806EABC(Entity* this); +void sub_0806EABC(PhonographEntity* this); #else void sub_0806EABC(Entity* this, u32 param); #endif -void Phonograph(Entity* this) { - if (this->action == 0) { - this->action++; - this->spriteSettings.draw = 1; - this->field_0x68.HWORD = 1; - this->field_0x6a.HWORD = -1; - sub_0807DD64(this); - this->frameIndex = 0; +void Phonograph(PhonographEntity* this) { + if (super->action == 0) { + super->action++; + super->spriteSettings.draw = 1; + this->unk_68 = 1; + this->unk_6a = -1; + sub_0807DD64(super); + super->frameIndex = 0; } - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); } static const s16 gUnk_081145E4[] = { @@ -36,7 +50,7 @@ static const s16 gUnk_081145E4[] = { }; #ifdef EU -void sub_0806E964(Entity* this, ScriptExecutionContext* context) { +void sub_0806E964(PhonographEntity* this, ScriptExecutionContext* context) { if (gInput.newKeys & B_BUTTON) { sub_08050384(); return; @@ -44,13 +58,13 @@ void sub_0806E964(Entity* this, ScriptExecutionContext* context) { if (context->unk_18 == 0) { context->unk_18++; - this->field_0x6c.HWORD = 0; + this->unk_6c = 0; sub_0806EABC(this); } if (gInput.unk4 & 0xc0) { s32 val2, val3; - s32 val = (s16)this->field_0x68.HWORD; + s32 val = this->unk_68; if (gInput.unk4 & 0x40) { val++; } else { @@ -70,39 +84,39 @@ void sub_0806E964(Entity* this, ScriptExecutionContext* context) { val = val2; } - this->field_0x68.HWORD = val; + this->unk_68 = val; sub_0806EABC(this); - if ((s16)this->field_0x6c.HWORD > 0) { - this->field_0x6c.HWORD--; + if (this->unk_6c > 0) { + this->unk_6c--; } } if (gInput.newKeys & A_BUTTON) { - if ((s16)this->field_0x68.HWORD != (s16)this->field_0x6a.HWORD || (s16)this->field_0x6c.HWORD == 0) { + if (this->unk_68 != this->unk_6a || this->unk_6c == 0) { const s16* ptr2 = gUnk_081145E4; s32 field_0x68; - SoundReq(*(ptr2 + (s16)this->field_0x68.HWORD * 2)); - this->field_0x6a.HWORD = this->field_0x68.HWORD; - field_0x68 = (s16)this->field_0x68.HWORD * 4; + SoundReq(*(ptr2 + this->unk_68 * 2)); + this->unk_6a = this->unk_68; + field_0x68 = this->unk_68 * 4; ptr2++; - this->field_0x6c.HWORD = *(s16*)((((s32)ptr2 + field_0x68))); + this->unk_6c = *(s16*)((((s32)ptr2 + field_0x68))); } else { SoundReq(SONG_STOP_ALL); - this->field_0x6a.HWORD = 0; + this->unk_6a = 0; } } - if ((s16)this->field_0x6c.HWORD > 0) { - if ((s16)-- this->field_0x6c.HWORD <= 0) { - this->field_0x6a.HWORD = 0; - this->field_0x6c.HWORD = 0; + if (this->unk_6c > 0) { + if (--this->unk_6c <= 0) { + this->unk_6a = 0; + this->unk_6c = 0; } } gActiveScriptInfo.commandSize = 0; } #else -void sub_0806E964(Entity* this, ScriptExecutionContext* context) { +void sub_0806E964(PhonographEntity* this, ScriptExecutionContext* context) { s32 val, val2, val3; if (gInput.newKeys & B_BUTTON) { sub_08050384(); @@ -111,15 +125,15 @@ void sub_0806E964(Entity* this, ScriptExecutionContext* context) { if (context->unk_18 == 0) { context->unk_18++; - this->field_0x6c.HWORD = 0; - sub_0806EABC(this, (s16)this->field_0x68.HWORD); + this->unk_6c = 0; + sub_0806EABC(super, this->unk_68); } val2 = 0x1c; if (CheckGlobalFlag(GAMECLEAR)) { val2 = 0x34; } - val = (s16)this->field_0x68.HWORD; + val = this->unk_68; if (gInput.newKeys & 0xc0) { if (gInput.newKeys & 0x40) { val++; @@ -150,34 +164,34 @@ void sub_0806E964(Entity* this, ScriptExecutionContext* context) { } } - if (val != (s16)this->field_0x68.HWORD) { - sub_0806EABC(this, val); - if ((s16)this->field_0x6c.HWORD > 0) { - this->field_0x6c.HWORD--; + if (val != this->unk_68) { + sub_0806EABC(super, val); + if (this->unk_6c > 0) { + this->unk_6c--; } } - this->field_0x68.HWORD = val; + this->unk_68 = val; if (gInput.newKeys & A_BUTTON) { - if ((s16)this->field_0x68.HWORD != (s16)this->field_0x6a.HWORD || (s16)this->field_0x6c.HWORD == 0) { + if (this->unk_68 != this->unk_6a || this->unk_6c == 0) { const s16* ptr2 = gUnk_081145E4; s32 field_0x68; - SoundReq(*(ptr2 + (s16)this->field_0x68.HWORD * 2)); - this->field_0x6a.HWORD = this->field_0x68.HWORD; - field_0x68 = (s16)this->field_0x68.HWORD * 4; + SoundReq(*(ptr2 + this->unk_68 * 2)); + this->unk_6a = this->unk_68; + field_0x68 = this->unk_68 * 4; ptr2++; - this->field_0x6c.HWORD = *(s16*)((((s32)ptr2 + field_0x68))); + this->unk_6c = *(s16*)((((s32)ptr2 + field_0x68))); } else { SoundReq(SONG_STOP_ALL); - this->field_0x6a.HWORD = 0; + this->unk_6a = 0; } } - if ((s16)this->field_0x6c.HWORD > 0) { - if ((s16)-- this->field_0x6c.HWORD <= 0) { - this->field_0x6a.HWORD = 0; - this->field_0x6c.HWORD = 0; + if (this->unk_6c > 0) { + if (--this->unk_6c <= 0) { + this->unk_6a = 0; + this->unk_6c = 0; } } @@ -190,9 +204,9 @@ const static Font gUnk_081146B8 = { }; #ifdef EU -void sub_0806EABC(Entity* this) { +void sub_0806EABC(PhonographEntity* this) { sub_08050384(); - sub_08057044((s16)this->field_0x68.HWORD, gUnk_020227E8, 0x202020); + sub_08057044(this->unk_68, gUnk_020227E8, 0x202020); ShowTextBox(0x3302, &gUnk_081146B8); gScreen.bg0.updated = 1; } diff --git a/src/npc/picolyteBottle.c b/src/npc/picolyteBottle.c index 80ebfc0ac..764ee858e 100644 --- a/src/npc/picolyteBottle.c +++ b/src/npc/picolyteBottle.c @@ -1,3 +1,9 @@ +/** + * @file picolyteBottle.c + * @ingroup NPCs + * + * @brief Picolyte Bottle NPC + */ #define NENT_DEPRECATED #include "entity.h" #include "functions.h" @@ -11,12 +17,12 @@ #include "structures.h" typedef struct { - Entity base; - Entity* ent1; - Entity* ent2; - Entity* ent3; - u16 unk74; - u16 unk76; + /*0x00*/ Entity base; + /*0x68*/ Entity* ent1; + /*0x6c*/ Entity* ent2; + /*0x70*/ Entity* ent3; + /*0x74*/ u16 unk74; + /*0x76*/ u16 unk76; } PicolyteBottleEntity; void sub_0806E014(PicolyteBottleEntity* this); @@ -60,7 +66,7 @@ void PicolyteBottle_Init(PicolyteBottleEntity* this) { this->unk76 = 10; gRoomTransition.field_0x6 = 10; sub_0806E014(this); - sub_0807DD50(super); + InitScriptForNPC(super); } else { super->hitbox = (Hitbox*)&gHitbox_0; super->collisionLayer = 1; @@ -69,7 +75,7 @@ void PicolyteBottle_Init(PicolyteBottleEntity* this) { } void PicolyteBottle_Action1(PicolyteBottleEntity* this) { - sub_0807DD94(super, 0); + ExecuteScriptAndHandleAnimation(super, NULL); if (super->timer != 0xff) { if (super->damage != 0) { this->ent3->timer++; diff --git a/src/npc/pina.c b/src/npc/pina.c index f11cbdd96..8fed940fd 100644 --- a/src/npc/pina.c +++ b/src/npc/pina.c @@ -1,21 +1,34 @@ +/** + * @file pina.c + * @ingroup NPCs + * + * @brief Pina NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "functions.h" #include "message.h" -#include "save.h" #include "npc.h" #include "object.h" +#include "save.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; +} PinaEntity; -void sub_08063B68(Entity* this); +void sub_08063B68(PinaEntity* this); void sub_08063A80(Entity* this); void sub_08063A98(Entity* this); void sub_08063AC0(Entity* this); void sub_08063B44(Entity* this); -void Pina(Entity* this) { - if ((this->flags & ENT_SCRIPTED) != 0) { +void Pina(PinaEntity* this) { + if ((super->flags & ENT_SCRIPTED) != 0) { sub_08063B68(this); } else { - sub_08063A80(this); + sub_08063A80(super); } } @@ -69,32 +82,33 @@ void sub_08063B44(Entity* this) { } } -void sub_08063B68(Entity* this) { - switch (this->action) { +void sub_08063B68(PinaEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.HI = 0; - sub_0807DD64(this); + super->action = 1; + super->spriteSettings.draw = 1; + this->animIndex = 0; + sub_0807DD64(super); case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 4); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + this->animIndex = super->animIndex; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) + 4); + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - UpdateAnimationSingleFrame(this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + UpdateAnimationSingleFrame(super); } break; case 2: - if (UpdateFuseInteraction(this) == 0) { + if (UpdateFuseInteraction(super) == 0) { return; } - this->action = 1; - InitAnimationForceUpdate(this, this->field_0x68.HALF.HI); + super->action = 1; + InitAnimationForceUpdate(super, this->animIndex); break; } } @@ -150,9 +164,9 @@ void sub_08063C90(Entity* this) { ShowNPCDialogue(this, &gUnk_0810CE04[gSave.global_progress]); } -void Pina_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Pina_MakeInteractable(PinaEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Pina_Fusion(Entity* this) { diff --git a/src/npc/pita.c b/src/npc/pita.c index 8414accca..ccf79c69f 100644 --- a/src/npc/pita.c +++ b/src/npc/pita.c @@ -1,33 +1,42 @@ -#include "npc.h" +/** + * @file pita.c + * @ingroup NPCs + * + * @brief Pita NPC + */ +#define NENT_DEPRECATED #include "item.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unused[24]; + /*0x80*/ u16 unk_80; +} PitaEntity; -void Pita(Entity* this) { +void Pita(PitaEntity* this) { static const Hitbox gUnk_0810C428 = { -#if EU 0, 2, { 0, 0, 0, 0 }, +#if EU 6, - 18, #else - 0, - 2, - { 0, 0, 0, 0 }, 10, - 18, #endif + 18, }; - if (this->action == 0) { - this->action++; - SetDefaultPriority(this, PRIO_MESSAGE); - SortEntityAbove(this, this); - this->hitbox = (Hitbox*)&gUnk_0810C428; - sub_0807DD64(this); + if (super->action == 0) { + super->action++; + SetDefaultPriority(super, PRIO_MESSAGE); + SortEntityAbove(super, super); + super->hitbox = (Hitbox*)&gUnk_0810C428; + sub_0807DD64(super); } - sub_0807DD94(this, NULL); - if ((this->frame & 1) != 0) { - InitAnimationForceUpdate(this, (u32)(this->animationState >> 1)); - this->field_0x80.HWORD = this->animIndex; + ExecuteScriptAndHandleAnimation(super, NULL); + if ((super->frame & 1) != 0) { + InitAnimationForceUpdate(super, (u32)(super->animationState >> 1)); + this->unk_80 = super->animIndex; } } diff --git a/src/npc/postman.c b/src/npc/postman.c index 9e7ce5296..5d910dae5 100644 --- a/src/npc/postman.c +++ b/src/npc/postman.c @@ -1,14 +1,29 @@ -#include "global.h" -#include "sound.h" +/** + * @file postman.c + * @ingroup NPCs + * + * @brief Postman NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "functions.h" #include "npc.h" +#include "sound.h" #include "structures.h" -extern void sub_08060528(Entity*); +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ s8 unk_68; + /*0x69*/ s8 unk_69; + /*0x6a*/ s16 unk_6a; + /*0x6c*/ u8 fusionOffer; + /*0x6d*/ u8 unk_6d; +} PostmanEntity; + +extern void sub_08060528(PostmanEntity*); extern void sub_080604DC(Entity*); extern void sub_080606D8(Entity*); -extern void Postman_MakeInteractable(Entity*); +extern void Postman_MakeInteractable(PostmanEntity*); const Coords gUnk_0810A66C[] = { { .HALF = { 0x0, 0x0 } }, { .HALF = { 0x48, 0xa8 } }, { .HALF = { 0x0, 0xf0 } }, @@ -149,11 +164,11 @@ const Rect gUnk_0810AA70[][4] = { }, }; -void Postman(Entity* this) { - if ((this->flags & ENT_SCRIPTED) != 0) { +void Postman(PostmanEntity* this) { + if ((super->flags & ENT_SCRIPTED) != 0) { sub_08060528(this); } else { - gUnk_0810AA24[this->action](this); + gUnk_0810AA24[super->action](super); } } @@ -225,76 +240,78 @@ void sub_080604DC(Entity* this) { } } -void sub_08060528(Entity* this) { - switch (this->action) { +void sub_08060528(PostmanEntity* this) { + switch (super->action) { case 0: - this->action = 1; - this->spriteSettings.draw = TRUE; - this->field_0x68.HALF.LO = 0; - this->field_0x68.HALF.HI = 0; - this->field_0x6a.HWORD = 0; - this->field_0x6c.HALF.HI = 0; - this->field_0x6c.HALF.LO = GetFusionToOffer(this); - sub_0807DD50(this); + super->action = 1; + super->spriteSettings.draw = TRUE; + this->unk_68 = 0; + this->unk_69 = 0; + this->unk_6a = 0; + this->unk_6d = 0; + this->fusionOffer = GetFusionToOffer(super); + InitScriptForNPC(super); break; case 1: - if (this->interactType == 2) { - this->action = 3; - this->interactType = 0; - sub_0806F118(this); - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + if (super->interactType == 2) { + super->action = 3; + super->interactType = 0; + InitializeNPCFusion(super); + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } else { - if (this->interactType != 0) { - this->action = 2; - this->interactType = 0; - sub_080606D8(this); - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + if (super->interactType != 0) { + super->action = 2; + super->interactType = 0; + sub_080606D8(super); + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } } break; case 2: - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); if ((gMessage.doTextBox & 0x7f) != 0) { break; } - this->action = 1; + super->action = 1; break; case 3: - UpdateAnimationSingleFrame(this); - if (!UpdateFuseInteraction(this)) { + UpdateAnimationSingleFrame(super); + if (!UpdateFuseInteraction(super)) { break; } - this->action = 1; + super->action = 1; } - sub_080604DC(this); - if (0 < (s16)this->field_0x6a.HWORD) { - if ((s16)this->field_0x6a.HWORD > 0x12b) { - this->field_0x6a.HWORD = 0; - this->zVelocity = Q_16_16(2.0); - this->field_0x6c.HALF.HI = 1; - RemoveInteractableObject(this); + sub_080604DC(super); + if (0 < (s16)this->unk_6a) { + if ((s16)this->unk_6a > 0x12b) { + this->unk_6a = 0; + super->zVelocity = Q_16_16(2.0); + this->unk_6d = 1; + RemoveInteractableObject(super); EnqueueSFX(SFX_PLY_JUMP); } else { - this->field_0x6a.HWORD--; + this->unk_6a--; } } - GravityUpdate(this, Q_8_8(24.0)); - if (((this->field_0x6c.HALF.HI != 0) && (this->zVelocity == 0)) && this->z.WORD == 0) { - this->field_0x6c.HALF.HI = 0; + GravityUpdate(super, Q_8_8(24.0)); + if (((this->unk_6d != 0) && (super->zVelocity == 0)) && super->z.WORD == 0) { + this->unk_6d = 0; Postman_MakeInteractable(this); } - if (this->z.WORD >= 0 && - ((gPlayerEntity.collisionLayer == 0 || (this->collisionLayer == gPlayerEntity.collisionLayer)))) { - sub_0806ED78(this); + if (super->z.WORD >= 0 && + ((gPlayerEntity.collisionLayer == 0 || (super->collisionLayer == gPlayerEntity.collisionLayer)))) { + sub_0806ED78(super); } - sub_0800451C(this); + sub_0800451C(super); } -void Postman_MakeInteractable(Entity* this) { - this->field_0x6c.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x6c.HALF.LO); +void Postman_MakeInteractable(PostmanEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void sub_080606D8(Entity* this) { @@ -307,21 +324,21 @@ void sub_080606D8(Entity* this) { ShowNPCDialogue(this, &gUnk_0810AA30[index]); } -void sub_08060700(Entity* entity, ScriptExecutionContext* context) { - const s8* var0 = gUnk_0810A918[(s8)entity->field_0x68.HALF.LO]; - const Coords* coords = &gUnk_0810A66C[var0[(s8)entity->field_0x68.HALF.HI]]; +void sub_08060700(PostmanEntity* this, ScriptExecutionContext* context) { + const s8* var0 = gUnk_0810A918[(s8)this->unk_68]; + const Coords* coords = &gUnk_0810A66C[var0[(s8)this->unk_69]]; u32 x = coords->HALF.x + gRoomControls.origin_x; u32 y = coords->HALF.y + gRoomControls.origin_y; - sub_0807DEDC(entity, context, x, y); + sub_0807DEDC(super, context, x, y); gActiveScriptInfo.flags |= 1; } -void sub_0806075C(Entity* this) { - this->field_0x68.HALF.LO = 0xb; - this->field_0x68.HALF.HI = 0xff; +void sub_0806075C(PostmanEntity* this) { + this->unk_68 = 0xb; + this->unk_69 = 0xff; } -void sub_0806076C(Entity* this, ScriptExecutionContext* context) { +void sub_0806076C(PostmanEntity* this, ScriptExecutionContext* context) { s32 cVar2; int iVar4; u32 uVar6; @@ -330,15 +347,15 @@ void sub_0806076C(Entity* this, ScriptExecutionContext* context) { const Coords* ptr; const s8* pbVar10; - if (this->z.WORD < 0) { + if (super->z.WORD < 0) { gActiveScriptInfo.commandSize = 0; return; } - this->field_0x68.HALF.HI++; - this->collisionLayer = 1; + this->unk_69++; + super->collisionLayer = 1; Postman_MakeInteractable(this); - pbVar10 = gUnk_0810A918[(s8)this->field_0x68.HALF.LO]; - pbVar10 += (s8)this->field_0x68.HALF.HI; + pbVar10 = gUnk_0810A918[this->unk_68]; + pbVar10 += this->unk_69; do { switch ((s8)(pbVar10[0] + 5)) { case 5: @@ -346,21 +363,21 @@ void sub_0806076C(Entity* this, ScriptExecutionContext* context) { uVar9 = pbVar10[0]; pbVar10++; iVar4 = (s32)Random() % uVar9; - this->field_0x68.HALF.LO = pbVar10[iVar4]; - this->field_0x68.HALF.HI = 0; + this->unk_68 = pbVar10[iVar4]; + this->unk_69 = 0; return; case 4: - this->field_0x6a.HWORD = 300; + this->unk_6a = 300; break; case 3: - this->collisionLayer = 1; + super->collisionLayer = 1; break; case 2: - this->collisionLayer = 2; + super->collisionLayer = 2; break; case 1: context->wait = 0x1e; - this->spriteSettings.draw = 0; + super->spriteSettings.draw = 0; break; case 0: pbVar10++; @@ -368,40 +385,40 @@ void sub_0806076C(Entity* this, ScriptExecutionContext* context) { local_24 = ((s32)Random()) % uVar9; for (uVar6 = 0; uVar6 < uVar9; uVar6++) { - this->field_0x68.HALF.LO = pbVar10[local_24]; - cVar2 = gUnk_0810A918[(s8)this->field_0x68.HALF.LO][0]; + this->unk_68 = pbVar10[local_24]; + cVar2 = gUnk_0810A918[this->unk_68][0]; ptr = &gUnk_0810A66C[cVar2]; - this->x.HALF_U.HI = gRoomControls.origin_x + ptr->HALF.x; - this->y.HALF_U.HI = gRoomControls.origin_y + ptr->HALF.y; - if (CheckOnScreen(this) == 0) + super->x.HALF_U.HI = gRoomControls.origin_x + ptr->HALF.x; + super->y.HALF_U.HI = gRoomControls.origin_y + ptr->HALF.y; + if (CheckOnScreen(super) == 0) break; local_24 = (s32)(local_24 + 1) % uVar9; } - this->field_0x68.HALF.HI = 0; + this->unk_69 = 0; return; default: return; } - this->field_0x68.HALF.HI++; + this->unk_69++; pbVar10++; } while (TRUE); } -void sub_080608E4(Entity* this, ScriptExecutionContext* context) { +void sub_080608E4(PostmanEntity* this, ScriptExecutionContext* context) { context->condition = 0; - if (this->z.WORD >= 0) { - if ((this->collisionLayer != 1 || gPlayerEntity.collisionLayer != 2) && - (this->collisionLayer != 2 || gPlayerEntity.collisionLayer != 1)) { - const Rect* ptr = &gUnk_0810AA70[context->intVariable][this->animationState >> 1]; - u32 x = this->x.HALF.HI + ptr->x; - u32 y = this->y.HALF.HI + ptr->y; + if (super->z.WORD >= 0) { + if ((super->collisionLayer != 1 || gPlayerEntity.collisionLayer != 2) && + (super->collisionLayer != 2 || gPlayerEntity.collisionLayer != 1)) { + const Rect* ptr = &gUnk_0810AA70[context->intVariable][super->animationState >> 1]; + u32 x = super->x.HALF.HI + ptr->x; + u32 y = super->y.HALF.HI + ptr->y; x = gPlayerEntity.x.HALF.HI - x; y = gPlayerEntity.y.HALF.HI - y; x += ptr->width; y += ptr->height; if (ptr->width * 2 > x && ptr->height * 2 > y) { context->condition = 1; - this->field_0x6a.HWORD += 2; + this->unk_6a += 2; } } } diff --git a/src/npc/rem.c b/src/npc/rem.c index 01db2ab1b..d1dd03c0c 100644 --- a/src/npc/rem.c +++ b/src/npc/rem.c @@ -1,6 +1,24 @@ +/** + * @file rem.c + * @ingroup NPCs + * + * @brief Rem NPC + */ +#define NENT_DEPRECATED #include "functions.h" -#include "npc.h" #include "item.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unk_68; + /*0x69*/ u8 unk_69; + /*0x6a*/ u16 unk_6a; + /*0x6c*/ u8 unused1[20]; + /*0x80*/ u16 unk_80; + /*0x82*/ u8 unused2[2]; + /*0x84*/ ScriptExecutionContext* context; +} RemEntity; extern void sub_0806A8C8(Entity*); @@ -8,259 +26,259 @@ extern void script_Rem; extern void DeleteThoughtBubble(Entity* this, ScriptExecutionContext* context); -void sub_0806A9B0(Entity*, ScriptExecutionContext*); +void sub_0806A9B0(RemEntity*, ScriptExecutionContext*); void sub_0806A914(Entity* this); -void sub_0806a370(Entity* this); -void sub_0806A5E8(Entity* this); -void sub_0806A630(Entity* this); -void sub_0806A674(Entity* this); -void sub_0806A830(Entity* this); -void sub_0806A890(Entity* this); - -void sub_0806A3D8(Entity* this); -void sub_0806A410(Entity* this); -void sub_0806A458(Entity* this); -void sub_0806A4CC(Entity* this); -void sub_0806A550(Entity* this); -void nullsub_503(Entity* this); -void sub_0806A5C0(Entity* this); - -void Rem(Entity* this) { - static void (*const typeFuncs[])(Entity*) = { +void sub_0806a370(RemEntity* this); +void sub_0806A5E8(RemEntity* this); +void sub_0806A630(RemEntity* this); +void sub_0806A674(RemEntity* this); +void sub_0806A830(RemEntity* this); +void sub_0806A890(RemEntity* this); + +void sub_0806A3D8(RemEntity* this); +void sub_0806A410(RemEntity* this); +void sub_0806A458(RemEntity* this); +void sub_0806A4CC(RemEntity* this); +void sub_0806A550(RemEntity* this); +void nullsub_503(RemEntity* this); +void sub_0806A5C0(RemEntity* this); + +void Rem(RemEntity* this) { + static void (*const typeFuncs[])(RemEntity*) = { sub_0806a370, sub_0806A5E8, sub_0806A630, sub_0806A674, sub_0806A830, sub_0806A890, }; - typeFuncs[this->type](this); + typeFuncs[super->type](this); } -void sub_0806a370(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void sub_0806a370(RemEntity* this) { + static void (*const actionFuncs[])(RemEntity*) = { sub_0806A3D8, sub_0806A410, sub_0806A458, sub_0806A4CC, sub_0806A550, nullsub_503, sub_0806A5C0, }; - actionFuncs[this->action](this); - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - UpdateAnimationSingleFrame(this); - sub_0806ED78(this); - if (this->animIndex == 0xf) { - if (this->frame == 1) { - this->frame = 0; + actionFuncs[super->action](this); + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + UpdateAnimationSingleFrame(super); + sub_0806ED78(super); + if (super->animIndex == 0xf) { + if (super->frame == 1) { + super->frame = 0; SoundReq(SFX_218); } - if (this->frame == 2) { - this->frame = 0; + if (super->frame == 2) { + super->frame = 0; SoundReq(SFX_219); } } } -void sub_0806A3D8(Entity* this) { - this->action = 1; - this->timer = 180; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0806A8C8(this); - *(ScriptExecutionContext**)&this->cutsceneBeh = StartCutscene(this, &script_Rem); - sub_0807DD94(this, NULL); +void sub_0806A3D8(RemEntity* this) { + super->action = 1; + super->timer = 180; + SetDefaultPriority(super, PRIO_MESSAGE); + sub_0806A8C8(super); + this->context = StartCutscene(super, &script_Rem); + ExecuteScriptAndHandleAnimation(super, NULL); } -void sub_0806A410(Entity* this) { - switch (this->subAction) { +void sub_0806A410(RemEntity* this) { + switch (super->subAction) { case 0: - if (--this->timer == 0) { - this->subAction++; - InitializeAnimation(this, 8); + if (--super->timer == 0) { + super->subAction++; + InitializeAnimation(super, 8); } break; case 1: - if (((this->frame & ANIM_DONE) != 0)) { - sub_0806A9B0(this, *(ScriptExecutionContext**)&this->cutsceneBeh); + if (((super->frame & ANIM_DONE) != 0)) { + sub_0806A9B0(this, this->context); } break; } } -void sub_0806A458(Entity* this) { - switch (this->subAction) { +void sub_0806A458(RemEntity* this) { + switch (super->subAction) { case 0: - if (--this->timer == 0) { - this->subAction++; + if (--super->timer == 0) { + super->subAction++; } break; case 1: - if ((this->frame & ANIM_DONE) != 0) { - this->subAction = 2; - InitializeAnimation(this, 10); + if ((super->frame & ANIM_DONE) != 0) { + super->subAction = 2; + InitializeAnimation(super, 10); ClearLocalFlag(0x62); } break; case 2: - if (((this->frame & ANIM_DONE) != 0)) { - this->action = 1; - this->subAction = 0; - this->timer = 60; - InitializeAnimation(this, 2); + if (((super->frame & ANIM_DONE) != 0)) { + super->action = 1; + super->subAction = 0; + super->timer = 60; + InitializeAnimation(super, 2); } break; } } -void sub_0806A4CC(Entity* this) { - switch (this->subAction) { +void sub_0806A4CC(RemEntity* this) { + switch (super->subAction) { case 0: - if ((this->frame & ANIM_DONE) != 0) { - if ((u8)(this->animIndex - 8) < 2) { - this->subAction = 1; - this->field_0x6a.HWORD = 1; - InitializeAnimation(this, 10); + if ((super->frame & ANIM_DONE) != 0) { + if ((u8)(super->animIndex - 8) < 2) { + super->subAction = 1; + this->unk_6a = 1; + InitializeAnimation(super, 10); } else { - this->subAction = 2; - this->field_0x6a.HWORD = 0; - InitializeAnimation(this, GetAnimationState(this)); + super->subAction = 2; + this->unk_6a = 0; + InitializeAnimation(super, GetAnimationState(super)); } break; case 1: - if ((this->frame & ANIM_DONE) != 0) { - this->subAction = 2; - InitializeAnimation(this, GetAnimationState(this)); + if ((super->frame & ANIM_DONE) != 0) { + super->subAction = 2; + InitializeAnimation(super, GetAnimationState(super)); } break; default: - this->timer = 180; + super->timer = 180; break; } } } -void sub_0806A550(Entity* this) { - if (this->subAction == 0) { - this->subAction = 1; - InitializeAnimation(this, 0xc); +void sub_0806A550(RemEntity* this) { + if (super->subAction == 0) { + super->subAction = 1; + InitializeAnimation(super, 0xc); } else { - if (this->frame == 1) { - this->frame = 0; + if (super->frame == 1) { + super->frame = 0; InitScreenShake(8, 2); gActiveScriptInfo.syncFlags |= 0x100; SoundReq(SFX_CHEST_OPEN); } - if ((this->frame & ANIM_DONE) != 0) { - this->action = 5; - this->subAction = 0; - InitializeAnimation(this, 0xd); - sub_0806A914(this); + if ((super->frame & ANIM_DONE) != 0) { + super->action = 5; + super->subAction = 0; + InitializeAnimation(super, 0xd); + sub_0806A914(super); } } } -void nullsub_503(Entity* this) { +void nullsub_503(RemEntity* this) { } -void sub_0806A5C0(Entity* this) { - GetNextFrame(this); - if ((this->frame & ANIM_DONE) != 0) { - InitializeAnimation(this, (Random() & 3) + 4); +void sub_0806A5C0(RemEntity* this) { + GetNextFrame(super); + if ((super->frame & ANIM_DONE) != 0) { + InitializeAnimation(super, (Random() & 3) + 4); } } -void sub_0806A5E8(Entity* this) { - if (this->action == 0) { - this->action = 1; - InitializeAnimation(this, 0x10); - this->timer = (Random() & 0x3f) + 60; +void sub_0806A5E8(RemEntity* this) { + if (super->action == 0) { + super->action = 1; + InitializeAnimation(super, 0x10); + super->timer = (Random() & 0x3f) + 60; } - this->timer--; - if (this->timer == 0) { - this->timer = (Random() & 0x3f) + 120; + super->timer--; + if (super->timer == 0) { + super->timer = (Random() & 0x3f) + 120; SoundReq(SFX_REM_SLEEP); } - GetNextFrame(this); + GetNextFrame(super); } -void sub_0806A630(Entity* this) { - if (this->action == 0) { - this->action = 1; - InitializeAnimation(this, 0x12); +void sub_0806A630(RemEntity* this) { + if (super->action == 0) { + super->action = 1; + InitializeAnimation(super, 0x12); } if ((gActiveScriptInfo.syncFlags & 0x100) != 0) { - GetNextFrame(this); + GetNextFrame(super); } - if (this->frame == 1) { - this->frame = 0; + if (super->frame == 1) { + super->frame = 0; SoundReq(SFX_SECRET); } } -void sub_0806A674(Entity* this) { +void sub_0806A674(RemEntity* this) { static const u8 gUnk_08112294[] = { 0, -1, 0, 1, 0, -1, 0, 1 }; u32 rand; u8 auStack16[8]; memcpy(auStack16, &gUnk_08112294, 8); - switch (this->action) { + switch (super->action) { case 0: - this->action = 1; - this->spritePriority.b0 = 6; - InitializeAnimation(this, 0x13); + super->action = 1; + super->spritePriority.b0 = 6; + InitializeAnimation(super, 0x13); break; case 1: if ((gActiveScriptInfo.syncFlags & 0x100) != 0) { - this->action = 2; - this->spriteOffsetY = 0; - this->spriteOffsetX = 0; + super->action = 2; + super->spriteOffsetY = 0; + super->spriteOffsetX = 0; } else { - if (this->parent->animIndex == 9) { - this->spritePriority.b0 = 3; + if (super->parent->animIndex == 9) { + super->spritePriority.b0 = 3; - if (this->timer == 0) { + if (super->timer == 0) { rand = Random(); - this->timer = rand & 7; - this->field_0x68.HALF.LO = auStack16[rand >> 8 & 7]; + super->timer = rand & 7; + this->unk_68 = auStack16[rand >> 8 & 7]; } else if ((gRoomTransition.frameCount & 3U) == 0) { - this->timer--; - if ((s8)this->spriteOffsetX < 1) { - this->field_0x68.HALF.LO = 1; + super->timer--; + if ((s8)super->spriteOffsetX < 1) { + this->unk_68 = 1; } - if (0xf < (s8)this->spriteOffsetX) { - this->field_0x68.HALF.LO = -1; + if (0xf < (s8)super->spriteOffsetX) { + this->unk_68 = -1; } - this->spriteOffsetX += this->field_0x68.HALF.LO; + super->spriteOffsetX += this->unk_68; } - if (this->subtimer == 0) { + if (super->subtimer == 0) { rand = Random(); - this->subtimer = rand & 7; - this->field_0x68.HALF.HI = auStack16[rand >> 8 & 7]; + super->subtimer = rand & 7; + this->unk_69 = auStack16[rand >> 8 & 7]; } else if (((u32)gRoomTransition.frameCount >> 4 & 3) == 0) { - this->subtimer--; - if (-1 < this->spriteOffsetY) { - this->field_0x68.HALF.HI = -1; + super->subtimer--; + if (-1 < super->spriteOffsetY) { + this->unk_69 = -1; } - if (this->spriteOffsetY <= -8) { - this->field_0x68.HALF.HI = 1; + if (super->spriteOffsetY <= -8) { + this->unk_69 = 1; } - this->spriteOffsetY += this->field_0x68.HALF.HI; + super->spriteOffsetY += this->unk_69; } } else { - this->spritePriority.b0 = 6; - if ((s8)this->spriteOffsetX != 0) { - if (0 < (s8)this->spriteOffsetX) { - this->spriteOffsetX--; + super->spritePriority.b0 = 6; + if ((s8)super->spriteOffsetX != 0) { + if (0 < (s8)super->spriteOffsetX) { + super->spriteOffsetX--; } - if ((s8)this->spriteOffsetX < 0) { - this->spriteOffsetX++; + if ((s8)super->spriteOffsetX < 0) { + super->spriteOffsetX++; } } - if (this->spriteOffsetY != 0) { - if (0 < this->spriteOffsetY) { - this->spriteOffsetY--; + if (super->spriteOffsetY != 0) { + if (0 < super->spriteOffsetY) { + super->spriteOffsetY--; } - if (this->spriteOffsetY < 0) { - this->spriteOffsetY++; + if (super->spriteOffsetY < 0) { + super->spriteOffsetY++; } } } @@ -268,40 +286,40 @@ void sub_0806A674(Entity* this) { break; case 2: - GetNextFrame(this); + GetNextFrame(super); break; } } -void sub_0806A830(Entity* this) { +void sub_0806A830(RemEntity* this) { Entity* npc; - if (this->action == 0) { - this->action = 1; - InitializeAnimation(this, 0x14); - SetDefaultPriority(this, PRIO_MESSAGE); + if (super->action == 0) { + super->action = 1; + InitializeAnimation(super, 0x14); + SetDefaultPriority(super, PRIO_MESSAGE); } if ((gActiveScriptInfo.syncFlags & 0x200) != 0) { DeleteThisEntity(); } - GetNextFrame(this); - if (this->frame == 1) { - this->frame = 0; + GetNextFrame(super); + if (super->frame == 1) { + super->frame = 0; npc = CreateNPC(REM, 5, 0); if (npc != NULL) { - PositionEntityOnTop(this, npc); + PositionEntityOnTop(super, npc); } } } -void sub_0806A890(Entity* this) { - if (this->action == 0) { - this->action = 1; - InitializeAnimation(this, 0x15); - SetDefaultPriority(this, PRIO_MESSAGE); +void sub_0806A890(RemEntity* this) { + if (super->action == 0) { + super->action = 1; + InitializeAnimation(super, 0x15); + SetDefaultPriority(super, PRIO_MESSAGE); } - GetNextFrame(this); - if ((this->frame & ANIM_DONE) != 0) { + GetNextFrame(super); + if ((super->frame & ANIM_DONE) != 0) { DeleteThisEntity(); } } @@ -356,13 +374,13 @@ void sub_0806A96C(Entity* this, ScriptExecutionContext* context) { } } -void sub_0806A9B0(Entity* this, ScriptExecutionContext* context) { +void sub_0806A9B0(RemEntity* this, ScriptExecutionContext* context) { static const u8 gUnk_081122A0[] = { 60, 100, 200, 60, 100, 200, 80, 80 }; - this->action = 2; - this->subAction = 0; - this->timer = gUnk_081122A0[Random() & 7]; - this->field_0x80.HWORD = 9; - InitializeAnimation(this, 9); + super->action = 2; + super->subAction = 0; + super->timer = gUnk_081122A0[Random() & 7]; + this->unk_80 = 9; + InitializeAnimation(super, 9); SetLocalFlag(NPC37_REM_SLEEP); } @@ -378,16 +396,16 @@ void sub_0806AA10(Entity* this) { sub_0806A914(this); } -void sub_0806AA18(Entity* this) { +void sub_0806AA18(RemEntity* this) { u32 index; - if (this->field_0x6a.HWORD != 0) { + if (this->unk_6a != 0) { index = TEXT_INDEX(TEXT_REM, 0x8); } else if ((gRoomTransition.frameCount & 1) == 0) { index = TEXT_INDEX(TEXT_REM, 0x7); } else { index = TEXT_INDEX(TEXT_REM, 0xd); } - MessageNoOverlap(index, this); + MessageNoOverlap(index, super); } void sub_0806AA50(Entity* this, ScriptExecutionContext* context) { diff --git a/src/npc/simon.c b/src/npc/simon.c index 647eae41e..1e599c5f2 100644 --- a/src/npc/simon.c +++ b/src/npc/simon.c @@ -1,3 +1,10 @@ +/** + * @file simon.c + * @ingroup NPCs + * + * @brief Simon NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "flags.h" #include "functions.h" @@ -16,9 +23,9 @@ typedef struct { void Simon(Entity* this) { if (this->action == 0) { this->action++; - sub_0807DD50(this); + InitScriptForNPC(this); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(this, NULL); } } diff --git a/src/npc/sittingPerson.c b/src/npc/sittingPerson.c index c5f63d07c..b972962c1 100644 --- a/src/npc/sittingPerson.c +++ b/src/npc/sittingPerson.c @@ -1,6 +1,21 @@ +/** + * @file sittingPerson.c + * @ingroup NPCs + * + * @brief Sitting Person NPC + */ +#define NENT_DEPRECATED #include "npc.h" #include "functions.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; + /*0x6a*/ u8 unused[26]; + /*0x84*/ u32* unk_84; +} SittingPersonEntity; + const SpriteLoadData gUnk_0810CB78[] = { { 63, 61, 4 }, { 8255, 61, 4 }, { 0, 0, 0 }, { 62, 61, 4 }, { 8255, 61, 4 }, { 0, 0, 0 }, { 64, 61, 4 }, { 8254, 61, 4 }, { 0, 0, 0 }, { 64, 61, 4 }, { 8256, 61, 4 }, { 0, 0, 0 }, @@ -10,10 +25,10 @@ const FrameStruct gUnk_0810CBC0[] = { { 4, 0 }, { 0, 0 }, { 12, 0 }, { 0, 0 }, { 20, 0 }, { 0, 0 }, { 28, 1 }, { 0, 0 }, { 36, 1 }, { 0, 0 }, { 44, 0 }, { 0, 0 }, }; -void SittingPersion_Init(Entity*); -void sub_080637B8(Entity*); -void sub_08063830(Entity*); -void (*const SittingPersion_Actions[])(Entity*) = { +void SittingPersion_Init(SittingPersonEntity*); +void sub_080637B8(SittingPersonEntity*); +void sub_08063830(SittingPersonEntity*); +void (*const SittingPersion_Actions[])(SittingPersonEntity*) = { SittingPersion_Init, sub_080637B8, sub_08063830, @@ -106,55 +121,55 @@ const u8 gUnk_0810CD88[][4] = { }; extern void sub_08096208(Entity*, u32); -void sub_080637B8(Entity* this); +void sub_080637B8(SittingPersonEntity* this); -void SittingPerson(Entity* this) { - SittingPersion_Actions[this->action](this); +void SittingPerson(SittingPersonEntity* this) { + SittingPersion_Actions[super->action](this); } -void SittingPersion_Init(Entity* this) { - if (LoadExtraSpriteData(this, &gUnk_0810CB78[this->type * 3])) { - this->action = 1; - this->spriteSettings.flipX = this->timer; +void SittingPersion_Init(SittingPersonEntity* this) { + if (LoadExtraSpriteData(super, &gUnk_0810CB78[super->type * 3])) { + super->action = 1; + super->spriteSettings.flipX = super->timer; - if (this->spriteSettings.flipX == 0) { - this->animationState = 6; + if (super->spriteSettings.flipX == 0) { + super->animationState = 6; } else { - this->animationState = 2; + super->animationState = 2; } - this->timer = this->animationState; - this->field_0x68.HALF.HI = 0; - sub_0807DD50(this); + super->timer = super->animationState; + this->animIndex = 0; + InitScriptForNPC(super); sub_080637B8(this); } } -void sub_080637B8(Entity* this) { +void sub_080637B8(SittingPersonEntity* this) { u32 tmp; - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - tmp = sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)); - tmp += this->spriteSettings.flipX ? 4 : 0; - InitializeAnimation(this, tmp); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + this->animIndex = super->animIndex; + tmp = GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)); + tmp += super->spriteSettings.flipX ? 4 : 0; + InitializeAnimation(super, tmp); + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - if (this->frameDuration == 0xfe) { - this->frameDuration = (Random() & 0x1f) + 0x1e; + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + if (super->frameDuration == 0xfe) { + super->frameDuration = (Random() & 0x1f) + 0x1e; } - GetNextFrame(this); + GetNextFrame(super); } } -void sub_08063830(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitializeAnimation(this, this->field_0x68.HALF.HI); +void sub_08063830(SittingPersonEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitializeAnimation(super, this->animIndex); } } @@ -210,7 +225,7 @@ void sub_0806390C(Entity* this) { if (CheckLocalFlag(MACHI_MES_60) == 0) { r5 = 0; SetLocalFlag(MACHI_MES_60); - (*(u32**)&this->cutsceneBeh)[0x5] = 1; + ((SittingPersonEntity*)this)->unk_84[5] = 1; } MessageNoOverlap(gUnk_0810CC04[r5], this); @@ -235,9 +250,9 @@ void SittingPerson_Head(Entity* this) { sub_0807000C(this); } -void SittingPerson_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void SittingPerson_MakeInteractable(SittingPersonEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void SittingPerson_Fusion(Entity* this) { diff --git a/src/npc/smallTownMinish.c b/src/npc/smallTownMinish.c index 5bbe8040c..99566202e 100644 --- a/src/npc/smallTownMinish.c +++ b/src/npc/smallTownMinish.c @@ -1,11 +1,17 @@ -#include "global.h" +/** + * @file smallTownMinish.c + * @ingroup NPCs + * + * @brief Small Town Minish NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "player.h" -#include "script.h" -#include "save.h" -#include "npc.h" #include "functions.h" #include "item.h" +#include "npc.h" +#include "player.h" +#include "save.h" +#include "script.h" void SmallTownMinish(Entity* this) { static const Hitbox gUnk_081142FC = { -2, 1, { 0, 0, 0, 0 }, 6, 6 }; @@ -13,10 +19,10 @@ void SmallTownMinish(Entity* this) { if (this->action == 0) { this->action++; this->hitbox = (Hitbox*)&gUnk_081142FC; - sub_0807DD50(this); + InitScriptForNPC(this); SetInteractableObjectCollision(this, 1, 0, &gUnk_08114304); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(this, NULL); } if ((gPlayerState.flags & PL_MINISH) != 0) { this->spriteSettings.draw = 1; diff --git a/src/npc/smith.c b/src/npc/smith.c index bc5df016d..19e95758c 100644 --- a/src/npc/smith.c +++ b/src/npc/smith.c @@ -1,5 +1,19 @@ -#include "npc.h" +/** + * @file smith.c + * @ingroup NPCs + * + * @brief Smith NPC + */ +#define NENT_DEPRECATED #include "functions.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unused[23]; + /*0x80*/ u16 unk_80; +} SmithEntity; static const SpriteLoadData gUnk_08110354[] = { { 0x4d, 0x38, 0x4 }, @@ -7,22 +21,22 @@ static const SpriteLoadData gUnk_08110354[] = { { 0, 0, 0 }, }; -void sub_080660EC(Entity*); -void sub_08066118(Entity*); -void sub_08066170(Entity*); -void sub_08066178(Entity*); -void sub_080661B0(Entity*); -void sub_080661BC(Entity*); -void sub_08066200(Entity*); -void sub_08066218(Entity*); - -void Smith(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void sub_080660EC(SmithEntity*); +void sub_08066118(SmithEntity*); +void sub_08066170(SmithEntity*); +void sub_08066178(SmithEntity*); +void sub_080661B0(SmithEntity*); +void sub_080661BC(SmithEntity*); +void sub_08066200(SmithEntity*); +void sub_08066218(SmithEntity*); + +void Smith(SmithEntity* this) { + static void (*const actionFuncs[])(SmithEntity*) = { sub_080660EC, sub_08066118, sub_08066170, }; - static void (*const scriptedActionFuncs[])(Entity*) = { + static void (*const scriptedActionFuncs[])(SmithEntity*) = { sub_08066178, sub_080661B0, sub_080661BC, sub_08066200, sub_08066218, }; static const u16 gUnk_08110380[] = { @@ -30,28 +44,28 @@ void Smith(Entity* this) { }; u32 index; - if ((this->flags & ENT_SCRIPTED) != 0) { - if (this->interactType == 2) { - this->action = 4; - this->interactType = 0; - index = (this->animIndex == 0xc) ? 8 : 0; - index += sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)); - InitAnimationForceUpdate(this, index); - sub_0806F118(this); + if ((super->flags & ENT_SCRIPTED) != 0) { + if (super->interactType == 2) { + super->action = 4; + super->interactType = 0; + index = (super->animIndex == 0xc) ? 8 : 0; + index += GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)); + InitAnimationForceUpdate(super, index); + InitializeNPCFusion(super); } - scriptedActionFuncs[this->action](this); + scriptedActionFuncs[super->action](this); } else { - actionFuncs[this->action](this); - sub_0806ED78(this); + actionFuncs[super->action](this); + sub_0806ED78(super); } - if (this->animIndex == 0xc) { - this->spritePriority.b1 = 0; + if (super->animIndex == 0xc) { + super->spritePriority.b1 = 0; } else { - this->spritePriority.b1 = 1; + super->spritePriority.b1 = 1; } - if ((this->frame & 1) != 0) { - this->frame &= 0xfe; - CreateFx(this, FX_STARS2, 0x20); + if ((super->frame & 1) != 0) { + super->frame &= 0xfe; + CreateFx(super, FX_STARS2, 0x20); SoundReq(gUnk_08110380[(Random() & 7)]); } } @@ -70,75 +84,75 @@ void Smith_Head(Entity* this) { sub_0807000C(this); } -void sub_080660EC(Entity* this) { - if (LoadExtraSpriteData(this, gUnk_08110354)) { - this->action = 1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - InitAnimationForceUpdate(this, 2); +void sub_080660EC(SmithEntity* this) { + if (LoadExtraSpriteData(super, gUnk_08110354)) { + super->action = 1; + this->fusionOffer = GetFusionToOffer(super); + InitAnimationForceUpdate(super, 2); } } -void sub_08066118(Entity* this) { +void sub_08066118(SmithEntity* this) { s32 uVar1; - uVar1 = GetAnimationStateInRectRadius(this, 0x28, 0x28); + uVar1 = GetAnimationStateInRectRadius(super, 0x28, 0x28); if (uVar1 < 0) { uVar1 = 2; } else { - if (this->subtimer == 0) { - this->subtimer = 16; + if (super->subtimer == 0) { + super->subtimer = 16; } else { - --this->subtimer; - uVar1 = this->animIndex; + --super->subtimer; + uVar1 = super->animIndex; } } - if (sub_0806F078(this, uVar1) == 0) { - UpdateAnimationSingleFrame(this); + if (sub_0806F078(super, uVar1) == 0) { + UpdateAnimationSingleFrame(super); } - if (this->interactType != 0) { - this->action = 2; + if (super->interactType != 0) { + super->action = 2; MessageFromTarget(0); } } -void sub_08066170(Entity* this) { - this->action = 1; +void sub_08066170(SmithEntity* this) { + super->action = 1; } -void sub_08066178(Entity* this) { - if (LoadExtraSpriteData(this, gUnk_08110354)) { - this->action = 1; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - sub_0807DD50(this); +void sub_08066178(SmithEntity* this) { + if (LoadExtraSpriteData(super, gUnk_08110354)) { + super->action = 1; + super->spriteSettings.draw = 1; + this->fusionOffer = GetFusionToOffer(super); + InitScriptForNPC(super); } } -void sub_080661B0(Entity* this) { - sub_0807DD94(this, NULL); +void sub_080661B0(SmithEntity* this) { + ExecuteScriptAndHandleAnimation(super, NULL); } -void sub_080661BC(Entity* this) { - if (this->animIndex == 0xc) { - UpdateAnimationSingleFrame(this); - if (this->frame & ANIM_DONE) { - this->field_0x80.HWORD = GetAnimationState(this) + 8; - InitAnimationForceUpdate(this, this->field_0x80.HWORD); +void sub_080661BC(SmithEntity* this) { + if (super->animIndex == 0xc) { + UpdateAnimationSingleFrame(super); + if (super->frame & ANIM_DONE) { + this->unk_80 = GetAnimationState(super) + 8; + InitAnimationForceUpdate(super, this->unk_80); } } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } } -void sub_08066200(Entity* this) { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - UpdateAnimationSingleFrame(this); +void sub_08066200(SmithEntity* this) { + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + UpdateAnimationSingleFrame(super); } -void sub_08066218(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; +void sub_08066218(SmithEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; } } @@ -210,8 +224,8 @@ void Smith_ChangeInteractableHitbox(Entity* this) { SetInteractableObjectCollision(this, 1, 0, &gUnk_081103E0); } -void Smith_MakeInteractable(Entity* this) { - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Smith_MakeInteractable(SmithEntity* this) { + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Smith_Fusion(Entity* this) { diff --git a/src/npc/stamp.c b/src/npc/stamp.c index 0ac805ec0..220b4c9a6 100644 --- a/src/npc/stamp.c +++ b/src/npc/stamp.c @@ -1,10 +1,16 @@ -#include "global.h" +/** + * @file stamp.c + * @ingroup NPCs + * + * @brief Stamp NPC + */ +#define NENT_DEPRECATED +#include "effects.h" #include "entity.h" -#include "message.h" #include "functions.h" -#include "effects.h" -#include "npc.h" #include "kinstone.h" +#include "message.h" +#include "npc.h" void sub_08062CA4(Entity*); void sub_08062BD4(Entity*); @@ -13,7 +19,7 @@ void sub_08062C24(Entity*); void sub_08062C54(Entity*); void sub_08062C7C(Entity*); -void Stamp(Entity* ent) { +void Stamp(Entity* this) { static void (*const actionFuncs[4])(Entity*) = { sub_08062BD4, sub_08062BF8, @@ -24,62 +30,62 @@ void Stamp(Entity* ent) { sub_08062C7C, sub_08062CA4, }; - if ((ent->flags & ENT_SCRIPTED) != 0) { - scriptedActionFuncs[ent->action](ent); + if ((this->flags & ENT_SCRIPTED) != 0) { + scriptedActionFuncs[this->action](this); } else { - actionFuncs[ent->action](ent); + actionFuncs[this->action](this); } } -void sub_08062BD4(Entity* ent) { - ent->action = 1; - ent->spriteSettings.draw = 1; - InitializeAnimation(ent, 0); - AddInteractableWhenBigObject(ent); +void sub_08062BD4(Entity* this) { + this->action = 1; + this->spriteSettings.draw = 1; + InitializeAnimation(this, 0); + AddInteractableWhenBigObject(this); } -void sub_08062BF8(Entity* ent) { - GetNextFrame(ent); - if (ent->interactType != 0) { - ent->interactType = 0; - ent->action++; - RequestPriority(ent); +void sub_08062BF8(Entity* this) { + GetNextFrame(this); + if (this->interactType != 0) { + this->interactType = 0; + this->action++; + RequestPriority(this); } - sub_0806ED78(ent); + sub_0806ED78(this); } -void sub_08062C24(Entity* ent) { - GetNextFrame(ent); - if ((ent->frame & 128) != 0) { - InitializeAnimation(ent, 4); +void sub_08062C24(Entity* this) { + GetNextFrame(this); + if ((this->frame & 128) != 0) { + InitializeAnimation(this, 4); MessageFromTarget(TEXT_INDEX(TEXT_EMPTY, 0x01)); - ent->action++; + this->action++; } } -void sub_08062C54(Entity* ent) { +void sub_08062C54(Entity* this) { if ((gMessage.doTextBox & 127) == 0) { - ent->action = 1; - InitializeAnimation(ent, 0); - RevokePriority(ent); + this->action = 1; + InitializeAnimation(this, 0); + RevokePriority(this); } } -void sub_08062C7C(Entity* ent) { - ent->action = 1; - sub_0807DD64(ent); - InitializeAnimation(ent, 0); - CreateFx(ent, FX_SWEAT, 0); - sub_08062CA4(ent); +void sub_08062C7C(Entity* this) { + this->action = 1; + sub_0807DD64(this); + InitializeAnimation(this, 0); + CreateFx(this, FX_SWEAT, 0); + sub_08062CA4(this); } -void sub_08062CA4(Entity* ent) { - ExecuteScriptForEntity(ent, NULL); - HandleEntity0x82Actions(ent); - GetNextFrame(ent); +void sub_08062CA4(Entity* this) { + ExecuteScriptForEntity(this, NULL); + HandleEntity0x82Actions(this); + GetNextFrame(this); } -void sub_08062CBC(Entity* ent) { +void sub_08062CBC(Entity* this) { static const Dialog gUnk_0810C2E4[2] = { { 0, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_POST, 0x1), TEXT_INDEX(TEXT_POST, 0x0) } }, { 0, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_POST, 0x3), TEXT_INDEX(TEXT_POST, 0x2) } }, @@ -90,11 +96,11 @@ void sub_08062CBC(Entity* ent) { } else { uVar1 = 0; } - ShowNPCDialogue(ent, &gUnk_0810C2E4[uVar1]); + ShowNPCDialogue(this, &gUnk_0810C2E4[uVar1]); } -void sub_08062CE0(Entity* ent) { - if (ent->action == 0) { - ent->action = 1; +void sub_08062CE0(Entity* this) { + if (this->action == 0) { + this->action = 1; } } diff --git a/src/npc/stockwell.c b/src/npc/stockwell.c index fa1e1305f..e327cda9d 100644 --- a/src/npc/stockwell.c +++ b/src/npc/stockwell.c @@ -1,28 +1,41 @@ +/** + * @file stockwell.c + * @ingroup NPCs + * + * @brief Stockwell NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "script.h" -#include "room.h" -#include "message.h" #include "functions.h" +#include "game.h" +#include "item.h" +#include "message.h" #include "npc.h" #include "object.h" -#include "item.h" -#include "game.h" +#include "room.h" +#include "script.h" #ifndef EU static const Rect gUnk_0810FDA0 = { 0, 8, 10, 16 }; #endif +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unused[28]; + /*0x84*/ ScriptExecutionContext* context; +} StockwellEntity; + extern u16 script_StockwellBuy[]; extern u16 script_StockwellDogFood[]; extern void InitScriptExecutionContext(ScriptExecutionContext* context, u16* script); extern u16 script_Stockwell; -void sub_08065080(Entity*); -void sub_080650CC(Entity*); -void sub_080651AC(Entity*); -void sub_080651D8(Entity*); -void sub_08065368(Entity*); +void sub_08065080(StockwellEntity*); +void sub_080650CC(StockwellEntity*); +void sub_080651AC(StockwellEntity*); +void sub_080651D8(StockwellEntity*); +void sub_08065368(StockwellEntity*); void sub_080651F8(Entity*); void sub_0806522C(Entity*); void sub_08065250(Entity*); @@ -32,82 +45,82 @@ void sub_080652E4(Entity*); void sub_08065314(Entity*); void sub_08065338(Entity*); -void Stockwell(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void Stockwell(StockwellEntity* this) { + static void (*const actionFuncs[])(StockwellEntity*) = { sub_08065080, sub_080650CC, sub_080651AC, sub_080651D8, sub_08065368, }; - actionFuncs[this->action](this); - ExecuteScript(this, *(ScriptExecutionContext**)&this->cutsceneBeh); - sub_0806ED78(this); + actionFuncs[super->action](this); + ExecuteScript(super, this->context); + sub_0806ED78(super); } -void sub_08065080(Entity* this) { +void sub_08065080(StockwellEntity* this) { ScriptExecutionContext* context; - this->action = 1; - this->spriteSettings.draw = 1; - SetDefaultPriority(this, PRIO_MESSAGE); - InitializeAnimation(this, 4); - AddInteractableWhenBigObject(this); + super->action = 1; + super->spriteSettings.draw = 1; + SetDefaultPriority(super, PRIO_MESSAGE); + InitializeAnimation(super, 4); + AddInteractableWhenBigObject(super); #ifndef EU - SetInteractableObjectCollision(this, 0, 0, &gUnk_0810FDA0); + SetInteractableObjectCollision(super, 0, 0, &gUnk_0810FDA0); #endif - context = StartCutscene(this, &script_Stockwell); - *(ScriptExecutionContext**)&this->cutsceneBeh = context; + context = StartCutscene(super, &script_Stockwell); + this->context = context; } -void sub_080650CC(Entity* this) { +void sub_080650CC(StockwellEntity* this) { static const u8 gUnk_0810FDB8[] = { 4, 6, 6, 5, 6, 6, 6, 5, 6, 6, 6, 5, 6, 6, 6, 5 }; u32 bVar2; u32 confirmMsgId; u32 itemPrice; if ((gRoomVars.animFlags & 1)) { - this->action = 4; - this->subAction = 0; - InitScriptExecutionContext(*(ScriptExecutionContext**)&this->cutsceneBeh, script_StockwellDogFood); + super->action = 4; + super->subAction = 0; + InitScriptExecutionContext(this->context, script_StockwellDogFood); } else { - bVar2 = this->frame & 0x20; - if ((bVar2 == 0) && (this->interactType != 0)) { - this->interactType = bVar2; - this->action++; - InitializeAnimation(this, 7); + bVar2 = super->frame & 0x20; + if ((bVar2 == 0) && (super->interactType != 0)) { + super->interactType = bVar2; + super->action++; + InitializeAnimation(super, 7); if (gRoomVars.shopItemType == 0) { confirmMsgId = TEXT_INDEX(TEXT_STOCKWELL, 0x1); } else { confirmMsgId = GetSaleItemConfirmMessageID(gRoomVars.shopItemType); itemPrice = GetItemPrice(gRoomVars.shopItemType); - this->action = 4; - this->subAction = bVar2; - InitScriptExecutionContext(*(ScriptExecutionContext**)&this->cutsceneBeh, script_StockwellBuy); + super->action = 4; + super->subAction = bVar2; + InitScriptExecutionContext(this->context, script_StockwellBuy); } - MessageNoOverlap(confirmMsgId, this); + MessageNoOverlap(confirmMsgId, super); //! @bug itemPrice (r8) is not initialized if gRoomVars.shopItemType == 0 gMessage.rupees = (u16)itemPrice; - } else if ((this->frame & 0x40)) { - InitializeAnimation(this, gUnk_0810FDB8[Random() & 0xf]); + } else if ((super->frame & 0x40)) { + InitializeAnimation(super, gUnk_0810FDB8[Random() & 0xf]); } else { - GetNextFrame(this); + GetNextFrame(super); } } } -void sub_080651AC(Entity* this) { - GetNextFrame(this); +void sub_080651AC(StockwellEntity* this) { + GetNextFrame(super); if ((gMessage.doTextBox & 0x7f) == 0) { - this->interactType = gMessage.doTextBox & 0x7f; - this->action = 1; - InitializeAnimation(this, 4); + super->interactType = gMessage.doTextBox & 0x7f; + super->action = 1; + InitializeAnimation(super, 4); } } -void sub_080651D8(Entity* this) { +void sub_080651D8(StockwellEntity* this) { static void (*const subActionFuncs[])(Entity*) = { sub_080651F8, sub_0806522C, sub_08065250, sub_0806528C, sub_080652B0, sub_080652E4, sub_08065314, sub_08065338, }; - GetNextFrame(this); - subActionFuncs[this->subAction](this); + GetNextFrame(super); + subActionFuncs[super->subAction](super); } void sub_080651F8(Entity* this) { @@ -186,8 +199,8 @@ void sub_08065338(Entity* this) { } } -void sub_08065368(Entity* this) { - GetNextFrame(this); +void sub_08065368(StockwellEntity* this) { + GetNextFrame(super); } void sub_08065370(Entity* this, ScriptExecutionContext* context) { diff --git a/src/npc/sturgeon.c b/src/npc/sturgeon.c index 05416de9b..830f1c0a8 100644 --- a/src/npc/sturgeon.c +++ b/src/npc/sturgeon.c @@ -1,19 +1,31 @@ +/** + * @file sturgeon.c + * @ingroup NPCs + * + * @brief Sturgeon NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "functions.h" +#include "item.h" #include "npc.h" #include "object.h" -#include "item.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} SturgeonEntity; const SpriteLoadData gUnk_0810FA38[] = { { 59, 140, 0 }, { 59, 140, 0 }, { 0, 0, 0 }, }; -void sub_08064B44(Entity*); -void sub_08064B88(Entity*); -void sub_08064C2C(Entity*); -void sub_08064C50(Entity*); -void (*const gUnk_0810FA44[])(Entity*) = { +void sub_08064B44(SturgeonEntity*); +void sub_08064B88(SturgeonEntity*); +void sub_08064C2C(SturgeonEntity*); +void sub_08064C50(SturgeonEntity*); +void (*const gUnk_0810FA44[])(SturgeonEntity*) = { sub_08064B44, sub_08064B88, sub_08064C2C, @@ -28,102 +40,103 @@ extern const u16 gUnk_0810FA54[]; // }; extern u32 gUnk_0810FA5A; // TODO second parameter of sub_0806EE04 -void Sturgeon_MakeInteractable(Entity* this); +void Sturgeon_MakeInteractable(SturgeonEntity* this); void sub_08064C9C(Entity* this); void sub_08064CD8(Entity* this); -void Sturgeon(Entity* this) { - if ((this->flags & ENT_SCRIPTED) == 0) { - gUnk_0810FA44[this->action](this); - sub_0806ED78(this); +void Sturgeon(SturgeonEntity* this) { + if ((super->flags & ENT_SCRIPTED) == 0) { + gUnk_0810FA44[super->action](this); + sub_0806ED78(super); } else { - if (this->action == 0) { - if (LoadExtraSpriteData(this, gUnk_0810FA38)) { - this->action = 1; - this->timer = 0; - sub_0807DD50(this); + if (super->action == 0) { + if (LoadExtraSpriteData(super, gUnk_0810FA38)) { + super->action = 1; + super->timer = 0; + InitScriptForNPC(super); } } else { - u32 tmp = this->action & 0x80; + u32 tmp = super->action & 0x80; if (tmp) { - if (UpdateFuseInteraction(this)) { - this->action = 1; + if (UpdateFuseInteraction(super)) { + super->action = 1; } } else { - if (this->interactType == 2) { - this->action = this->action | 0xff; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = super->action | 0xff; + super->interactType = 0; + InitAnimationForceUpdate(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); - sub_08064C9C(this); + ExecuteScriptAndHandleAnimation(super, NULL); + sub_08064C9C(super); } } } } } -void sub_08064B44(Entity* this) { - if (LoadExtraSpriteData(this, gUnk_0810FA38)) { - InitializeAnimation(this, 2); - sub_0806EE04(this, &gUnk_0810FA5A, 0); +void sub_08064B44(SturgeonEntity* this) { + if (LoadExtraSpriteData(super, gUnk_0810FA38)) { + InitializeAnimation(super, 2); + sub_0806EE04(super, &gUnk_0810FA5A, 0); Sturgeon_MakeInteractable(this); - this->action = 1; - this->subAction = 0; - this->spriteSettings.draw = 1; + super->action = 1; + super->subAction = 0; + super->spriteSettings.draw = 1; } } -void sub_08064B88(Entity* this) { +void sub_08064B88(SturgeonEntity* this) { s32 temp; s32 temp2; - switch (this->interactType) { + switch (super->interactType) { case 0: - temp = sub_0806EE20(this); - this->animationState = this->knockbackDirection; + temp = sub_0806EE20(super); + super->animationState = super->knockbackDirection; if (temp != 0) { - InitializeAnimation(this, temp & 0x7f); + InitializeAnimation(super, temp & 0x7f); } - GetNextFrame(this); + GetNextFrame(super); break; case 2: - this->action = 3; - temp2 = GetAnimationState(this); + super->action = 3; + temp2 = GetAnimationState(super); if (temp2 < 0) { - temp2 = this->animationState; + temp2 = super->animationState; } - this->subtimer = this->animIndex; - InitializeAnimation(this, temp2); - this->interactType = 0; - sub_0806F118(this); + super->subtimer = super->animIndex; + InitializeAnimation(super, temp2); + super->interactType = 0; + InitializeNPCFusion(super); break; case 1: default: - this->action = 2; - temp2 = GetAnimationState(this); + super->action = 2; + temp2 = GetAnimationState(super); if (temp2 < 0) { - temp2 = this->animationState; + temp2 = super->animationState; } - this->subtimer = this->animIndex; - InitializeAnimation(this, temp2); - this->interactType = 0; - sub_08064CD8(this); + super->subtimer = super->animIndex; + InitializeAnimation(super, temp2); + super->interactType = 0; + sub_08064CD8(super); } } -void sub_08064C2C(Entity* this) { +void sub_08064C2C(SturgeonEntity* this) { if ((gMessage.doTextBox & 0x7f) == 0) { - this->action = 1; - InitializeAnimation(this, (u32)this->subtimer); + super->action = 1; + InitializeAnimation(super, (u32)super->subtimer); } } -void sub_08064C50(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitializeAnimation(this, this->subtimer); +void sub_08064C50(SturgeonEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitializeAnimation(super, super->subtimer); } } @@ -140,9 +153,9 @@ void sub_08064C9C(Entity* this) { } } -void Sturgeon_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Sturgeon_MakeInteractable(SturgeonEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void sub_08064CD8(Entity* this) { diff --git a/src/npc/syrup.c b/src/npc/syrup.c index 1668d4f72..ae1f8eb1a 100644 --- a/src/npc/syrup.c +++ b/src/npc/syrup.c @@ -1,7 +1,20 @@ -#include "npc.h" +/** + * @file syrup.c + * @ingroup NPCs + * + * @brief Syrup NPC + */ +#define NENT_DEPRECATED #include "functions.h" +#include "npc.h" #include "object.h" +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unused[26]; + /*0x82*/ u16 unk_82; +} SyrupEntity; + static const SpriteLoadData gUnk_081121B4[] = { { 0xc2, 0x46, 0x4 }, { 0x44c2, 0x46, 0x4 }, @@ -16,38 +29,38 @@ static const SpriteLoadData gUnk_081121C4[] = { }; void sub_0806A26C(Entity*); -void sub_0806A1F8(Entity*); -void sub_0806A234(Entity*); +void sub_0806A1F8(SyrupEntity*); +void sub_0806A234(SyrupEntity*); -void Syrup(Entity* this) { - static void (*const actionFuncs[])(Entity*) = { +void Syrup(SyrupEntity* this) { + static void (*const actionFuncs[])(SyrupEntity*) = { sub_0806A1F8, sub_0806A234, }; - actionFuncs[this->action](this); - sub_0806ED78(this); + actionFuncs[super->action](this); + sub_0806ED78(super); } -void sub_0806A1F8(Entity* this) { +void sub_0806A1F8(SyrupEntity* this) { const SpriteLoadData* paVar2; - this->type == 0 ? (paVar2 = gUnk_081121B4) : (paVar2 = gUnk_081121C4); + super->type == 0 ? (paVar2 = gUnk_081121B4) : (paVar2 = gUnk_081121C4); - if (LoadExtraSpriteData(this, paVar2)) { - this->action = 1; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); - InitializeAnimation(this, 0); + if (LoadExtraSpriteData(super, paVar2)) { + super->action = 1; + SetDefaultPriority(super, PRIO_MESSAGE); + InitScriptForNPC(super); + InitializeAnimation(super, 0); } } -void sub_0806A234(Entity* this) { - sub_0807DD94(this, 0); - if ((this->field_0x82.HWORD & 4) != 0) { +void sub_0806A234(SyrupEntity* this) { + ExecuteScriptAndHandleAnimation(super, NULL); + if ((this->unk_82 & 4) != 0) { if ((gRoomTransition.frameCount & 7) == 0) { - sub_0806A26C(this); + sub_0806A26C(super); } - sub_080042BA(this, 2); + sub_080042BA(super, 2); } } diff --git a/src/npc/talon.c b/src/npc/talon.c index dc86ba851..24fbe741e 100644 --- a/src/npc/talon.c +++ b/src/npc/talon.c @@ -1,6 +1,22 @@ -#include "npc.h" +/** + * @file talon.c + * @ingroup NPCs + * + * @brief Talon NPC + */ +#define NENT_DEPRECATED #include "functions.h" #include "item.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unk_69; + /*0x6a*/ u8 unk_6a; + /*0x6b*/ u8 unused[25]; + /*0x84*/ u32 unk_84; +} TalonEntity; static const SpriteLoadData gUnk_0810FEB0[] = { { 0x4b, 0x8b, 0 }, @@ -10,27 +26,27 @@ static const SpriteLoadData gUnk_0810FEB0[] = { extern u8 script_TalonGotKey; -void sub_0806574C(Entity* this); +void sub_0806574C(TalonEntity* this); void sub_08065570(Entity* this); void sub_0806559C(Entity* this); -void sub_08065608(Entity* this); -void sub_08065648(Entity* this); -void sub_080656D4(Entity* this); -void sub_080656A4(Entity* this); -void sub_08065680(Entity* this); - -void Talon(Entity* this) { - static void (*const actionFuncs[])(Entity * this) = { +void sub_08065608(TalonEntity* this); +void sub_08065648(TalonEntity* this); +void sub_080656D4(TalonEntity* this); +void sub_080656A4(TalonEntity* this); +void sub_08065680(TalonEntity* this); + +void Talon(TalonEntity* this) { + static void (*const actionFuncs[])(Entity*) = { sub_08065570, sub_0806559C, }; - static void (*const scriptedActionFuncs[])(Entity * this) = { + static void (*const scriptedActionFuncs[])(TalonEntity*) = { sub_08065608, sub_08065648, sub_080656D4, sub_080656A4, sub_08065680, }; - if (this->flags & ENT_SCRIPTED) { - scriptedActionFuncs[this->action](this); + if (super->flags & ENT_SCRIPTED) { + scriptedActionFuncs[super->action](this); } else { - actionFuncs[this->action](this); + actionFuncs[super->action](super); } } @@ -74,74 +90,74 @@ void sub_0806559C(Entity* this) { } } -void sub_08065608(Entity* this) { - if (LoadExtraSpriteData(this, gUnk_0810FEB0)) { - this->action = 1; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); - sub_0807DD50(this); +void sub_08065608(TalonEntity* this) { + if (LoadExtraSpriteData(super, gUnk_0810FEB0)) { + super->action = 1; + super->spriteSettings.draw = 1; + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); + InitScriptForNPC(super); } } -void sub_08065648(Entity* this) { - if (this->interactType == 2) { - this->field_0x68.HALF.HI = this->action; - this->action = 4; - this->interactType = 0; - sub_0806F118(this); +void sub_08065648(TalonEntity* this) { + if (super->interactType == 2) { + this->unk_69 = super->action; + super->action = 4; + super->interactType = 0; + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } } -void sub_08065680(Entity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = this->field_0x68.HALF.HI; - InitAnimationForceUpdate(this, this->field_0x6a.HALF.LO); +void sub_08065680(TalonEntity* this) { + if (UpdateFuseInteraction(super) != 0) { + super->action = this->unk_69; + InitAnimationForceUpdate(super, this->unk_6a); } } -void sub_080656A4(Entity* this) { +void sub_080656A4(TalonEntity* this) { if ((gMessage.doTextBox & 0x7F) == 0) { - this->action = this->field_0x68.HALF.HI; - InitAnimationForceUpdate(this, this->field_0x6a.HALF.LO); + super->action = this->unk_69; + InitAnimationForceUpdate(super, this->unk_6a); } - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } -void sub_080656D4(Entity* this) { - if (this->interactType == 2) { - this->field_0x68.HALF.HI = this->action; - this->action = 4; - this->interactType = 0; - sub_0806F118(this); +void sub_080656D4(TalonEntity* this) { + if (super->interactType == 2) { + this->unk_69 = super->action; + super->action = 4; + super->interactType = 0; + InitializeNPCFusion(super); sub_0806574C(this); } else { - if (this->interactType != 0) { + if (super->interactType != 0) { if (GetInventoryValue(ITEM_QST_LONLON_KEY) != 0) { - StartCutscene(this, (u16*)&script_TalonGotKey); + StartCutscene(super, (u16*)&script_TalonGotKey); } else { - this->field_0x68.HALF.HI = this->action; - this->action = 3; - this->interactType = 0; - MessageNoOverlap(*(u32*)(*(u32*)&this->cutsceneBeh.HWORD + 4), this); + this->unk_69 = super->action; + super->action = 3; + super->interactType = 0; + MessageNoOverlap(*(u32*)(*(u32*)&this->unk_84 + 4), super); sub_0806574C(this); return; } } - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } } -void sub_0806574C(Entity* this) { +void sub_0806574C(TalonEntity* this) { u32 j; - j = (this->animIndex & ~3) + sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)); - if (this->animIndex != j) { - InitAnimationForceUpdate(this, j); + j = (super->animIndex & ~3) + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)); + if (super->animIndex != j) { + InitAnimationForceUpdate(super, j); } - this->field_0x6a.HALF.LO = this->animIndex; + this->unk_6a = super->animIndex; } void sub_08065780(Entity* this, ScriptExecutionContext* context) { diff --git a/src/npc/teachers.c b/src/npc/teachers.c index 05e0d3f69..dddb574f4 100644 --- a/src/npc/teachers.c +++ b/src/npc/teachers.c @@ -1,50 +1,62 @@ -#include "global.h" +/** + * @file teachers.c + * @ingroup NPCs + * + * @brief Teachers NPC + */ +#define NENT_DEPRECATED #include "entity.h" +#include "npc.h" #include "player.h" #include "save.h" #include "script.h" -#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 animIndex; +} TeachersEntity; static const SpriteLoadData gUnk_08113910[] = { { 0x103, 0x4f, 0x4 }, { 0x2103, 0x4f, 0x4 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0x50, 0x4 }, { 0x2002, 0x50, 0x4 }, { 0x4000, 0x50, 0x4 }, { 0, 0, 0 }, }; -void Teachers(Entity* this) { - switch (this->action) { +void Teachers(TeachersEntity* this) { + switch (super->action) { case 0: - if (LoadExtraSpriteData(this, &gUnk_08113910[this->type * 4])) { - this->action = 1; - this->spriteSettings.draw = TRUE; - this->animationState = this->timer; - this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + if (LoadExtraSpriteData(super, &gUnk_08113910[super->type * 4])) { + super->action = 1; + super->spriteSettings.draw = TRUE; + super->animationState = super->timer; + this->animIndex = 0; + SetDefaultPriority(super, PRIO_MESSAGE); + InitScriptForNPC(super); } break; case 1: - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - this->field_0x68.HALF.HI = this->animIndex; - InitializeAnimation(this, - (this->animIndex & -4) + sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 2; + super->interactType = 0; + this->animIndex = super->animIndex; + InitializeAnimation(super, (super->animIndex & -4) + GetAnimationStateForDirection4( + GetFacingDirection(super, &gPlayerEntity))); + InitializeNPCFusion(super); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(super, NULL); } break; case 2: - if (UpdateFuseInteraction(this)) { - this->action = 1; - InitializeAnimation(this, this->field_0x68.HALF.HI); + if (UpdateFuseInteraction(super)) { + super->action = 1; + InitializeAnimation(super, this->animIndex); } } } -void Teachers_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Teachers_MakeInteractable(TeachersEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void Teachers_Head(Entity* this) { diff --git a/src/npc/tingleSiblings.c b/src/npc/tingleSiblings.c index 1d5cfabfa..2d3a20b80 100644 --- a/src/npc/tingleSiblings.c +++ b/src/npc/tingleSiblings.c @@ -1,9 +1,20 @@ -#include "global.h" +/** + * @file tingleSiblings.c + * @ingroup NPCs + * + * @brief Tingle Siblings NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "npc.h" #include "functions.h" #include "item.h" #include "kinstone.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} TingleSiblingsEntity; extern void sub_08064DE4(Entity*); extern void sub_08064D78(Entity*); @@ -53,16 +64,17 @@ void sub_08064DE4(Entity* this) { this->action = 1; this->spriteSettings.draw = 1; this->animationState = 4; - sub_0807DD50(this); + InitScriptForNPC(this); break; case 1: if (this->interactType == 2) { this->action = 2; this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); - sub_0806F118(this); + InitAnimationForceUpdate(this, + GetAnimationStateForDirection4(GetFacingDirection(this, &gPlayerEntity))); + InitializeNPCFusion(this); } else { - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(this, NULL); } break; case 2: @@ -83,28 +95,28 @@ void sub_08064DE4(Entity* this) { } } -void TingleSiblings_MakeInteractable(Entity* this) { - this->field_0x68.HALF.LO = GetFusionToOffer(this); - switch (this->type) { +void TingleSiblings_MakeInteractable(TingleSiblingsEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + switch (super->type) { case 0: if ((CheckKinstoneFused(KINSTONE_59) != 0) && (GetInventoryValue(ITEM_MAGIC_BOOMERANG) == 0)) { - this->field_0x68.HALF.LO = 0; + this->fusionOffer = 0; } break; case 3: if ((CheckKinstoneFused(KINSTONE_5A) != 0) && (GetInventoryValue(ITEM_MAGIC_BOOMERANG) == 0)) { - this->field_0x68.HALF.LO = 0; + this->fusionOffer = 0; } break; default: break; } - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void sub_08064EE8(Entity* this) { u32 bVar1; - Entity* fxEnt; + Entity* fxEntity; u32 confettiFx; UpdateAnimationSingleFrame(this); @@ -117,9 +129,9 @@ void sub_08064EE8(Entity* this) { confettiFx = FX_CONFETTI_LARGE; } - fxEnt = CreateFx(this, confettiFx, 0); - if ((fxEnt != NULL) && (bVar1 == 2)) { - fxEnt->spriteSettings.flipX = 1; + fxEntity = CreateFx(this, confettiFx, 0); + if ((fxEntity != NULL) && (bVar1 == 2)) { + fxEntity->spriteSettings.flipX = 1; } } } diff --git a/src/npc/townMinish.c b/src/npc/townMinish.c index 721c800f0..ee8c580a8 100644 --- a/src/npc/townMinish.c +++ b/src/npc/townMinish.c @@ -1,15 +1,31 @@ -#include "global.h" +/** + * @file townMinish.c + * @ingroup NPCs + * + * @brief Town Minish NPC + */ +#define NENT_DEPRECATED #include "entity.h" -#include "npc.h" #include "functions.h" #include "item.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unk_69; + /*0x6a*/ u8 unk_6a; + /*0x6b*/ u8 unused[23]; + /*0x82*/ u16 unk_82; + /*0x84*/ ScriptExecutionContext* context; +} TownMinishEntity; extern u32 sub_080B1AC8(u32, u32, u32); -void sub_0806ACC4(Entity*); -void sub_0806ABFC(Entity*); -void sub_0806AC3C(Entity*); -void sub_0806AEA8(Entity*); -void sub_0806AEE4(Entity*); +void sub_0806ACC4(TownMinishEntity*); +void sub_0806ABFC(TownMinishEntity*); +void sub_0806AC3C(TownMinishEntity*); +void sub_0806AEA8(TownMinishEntity*); +void sub_0806AEE4(TownMinishEntity*); void sub_0806AFE8(Entity*, ScriptExecutionContext*); void sub_0806B004(Entity*, ScriptExecutionContext*); void sub_0806B098(Entity*, ScriptExecutionContext*); @@ -137,98 +153,99 @@ static const Rect gUnk_081126D4[4] = { }; static const u8 gUnk_081126E4[4] = { 0x0e, 0x0d, 0x0b, 0x07 }; -void TownMinish(Entity* this) { - static void (*const scriptedActionFuncs[])(Entity*) = { +void TownMinish(TownMinishEntity* this) { + static void (*const scriptedActionFuncs[])(TownMinishEntity*) = { sub_0806ABFC, sub_0806AC3C, }; - if ((this->flags & ENT_SCRIPTED) == 0) { - scriptedActionFuncs[this->action](this); - sub_0806ED78(this); + if ((super->flags & ENT_SCRIPTED) == 0) { + scriptedActionFuncs[super->action](this); + sub_0806ED78(super); } else { sub_0806ACC4(this); } } -void sub_0806ABFC(Entity* this) { - const SpriteLoadData* SpriteLoadData = gUnk_08112674[this->type]; - if (!LoadExtraSpriteData(this, SpriteLoadData)) { +void sub_0806ABFC(TownMinishEntity* this) { + const SpriteLoadData* SpriteLoadData = gUnk_08112674[super->type]; + if (!LoadExtraSpriteData(super, SpriteLoadData)) { return; } - InitializeAnimation(this, 2); - this->action = 1; - this->field_0x6a.HALF.LO = this->timer; + InitializeAnimation(super, 2); + super->action = 1; + this->unk_6a = super->timer; - this->animationState = this->field_0x6a.HALF.LO << 1; - this->field_0x68.HALF.HI = this->animationState * 4; + super->animationState = this->unk_6a << 1; + this->unk_69 = super->animationState * 4; - this->timer = 0; + super->timer = 0; } -void sub_0806AC3C(Entity* this) { - if (this->animIndex <= 3) { +void sub_0806AC3C(TownMinishEntity* this) { + if (super->animIndex <= 3) { s32 unk; Entity* link = &gPlayerEntity; - if (EntityInRectRadius(this, link, 0x18, 0x18)) { - unk = GetFacingDirection(this, link) & 0x1e; + if (EntityInRectRadius(super, link, 0x18, 0x18)) { + unk = GetFacingDirection(super, link) & 0x1e; } else { - unk = this->animationState * 4; + unk = super->animationState * 4; } - if (unk != this->field_0x68.HALF.HI) { - if (((unk - this->field_0x68.HALF.HI) & 0x1f) <= 0xf) { - this->field_0x68.HALF.HI--; + if (unk != this->unk_69) { + if (((unk - this->unk_69) & 0x1f) <= 0xf) { + this->unk_69--; } else { - this->field_0x68.HALF.HI++; + this->unk_69++; } - this->field_0x68.HALF.HI &= 0x1f; + this->unk_69 &= 0x1f; } - if (!(this->field_0x68.HALF.HI & 7)) { - this->animationState = sub_0806F5B0(this->field_0x68.HALF.HI); - InitializeAnimation(this, AnimationStateFlip90(this->animationState / 2)); + if (!(this->unk_69 & 7)) { + super->animationState = GetAnimationStateForDirection8(this->unk_69); + InitializeAnimation(super, AnimationStateFlip90(super->animationState / 2)); } } - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } -void sub_0806ACC4(Entity* this) { +void sub_0806ACC4(TownMinishEntity* this) { u8 delay; - switch (this->action) { + switch (super->action) { case 0: - if (!LoadExtraSpriteData(this, gUnk_08112674[this->type])) + if (!LoadExtraSpriteData(super, gUnk_08112674[super->type])) return; - this->action = 1; - delay = this->timer; - this->field_0x6a.HALF.LO = delay; - this->animationState = delay * 2; - this->timer = 0; + super->action = 1; + delay = super->timer; + this->unk_6a = delay; + super->animationState = delay * 2; + super->timer = 0; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - sub_0807DD50(this); - InitializeAnimation(this, (this->animationState / 2) + 8); + this->fusionOffer = GetFusionToOffer(super); + InitScriptForNPC(super); + InitializeAnimation(super, (super->animationState / 2) + 8); break; case 1: - if (this->interactType == 2) { - this->action = 3; - this->interactType = 0; - sub_0806F118(this); + if (super->interactType == 2) { + super->action = 3; + super->interactType = 0; + InitializeNPCFusion(super); } else { - ExecuteScriptForEntity(this, NULL); + ExecuteScriptForEntity(super, NULL); sub_0806AEA8(this); - if (this->type2 == 10 && this->interactType) { - this->action = 2; - this->interactType = 0; - InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 8); - sub_0806AFE8(this, *(ScriptExecutionContext**)&this->cutsceneBeh); + if (super->type2 == 10 && super->interactType) { + super->action = 2; + super->interactType = 0; + InitializeAnimation(super, + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity)) + 8); + sub_0806AFE8(super, this->context); } - if (this->type == 1) { + if (super->type == 1) { u8 idx = gPlayerEntity.animationState >> 1; - SetInteractableObjectCollision(this, 1, gUnk_081126E4[idx], &gUnk_081126D4[idx]); + SetInteractableObjectCollision(super, 1, gUnk_081126E4[idx], &gUnk_081126D4[idx]); } } break; @@ -236,96 +253,96 @@ void sub_0806ACC4(Entity* this) { if (gMessage.doTextBox & 0x7f) break; - this->action = 1; - InitializeAnimation(this, this->animationState / 2 + 4); + super->action = 1; + InitializeAnimation(super, super->animationState / 2 + 4); break; case 3: - if (UpdateFuseInteraction(this)) - this->action = 1; + if (UpdateFuseInteraction(super)) + super->action = 1; break; } - if (this->frameDuration != 0xff) { - GetNextFrame(this); + if (super->frameDuration != 0xff) { + GetNextFrame(super); } } -void TownMinish_MakeInteractable(Entity* this) { - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void TownMinish_MakeInteractable(TownMinishEntity* this) { + AddInteractableWhenBigFuser(super, this->fusionOffer); } -void TownMinish_Head(Entity* this) { +void TownMinish_Head(TownMinishEntity* this) { u32 frames; - if ((this->flags & ENT_SCRIPTED) == 0) { - frames = this->field_0x68.HALF.HI / 2; - if ((this->frameSpriteSettings & 1)) { - SetExtraSpriteFrame(this, 0, frames + 0x1c); + if ((super->flags & ENT_SCRIPTED) == 0) { + frames = this->unk_69 / 2; + if ((super->frameSpriteSettings & 1)) { + SetExtraSpriteFrame(super, 0, frames + 0x1c); } else { - SetExtraSpriteFrame(this, 0, 0xff); + SetExtraSpriteFrame(super, 0, 0xff); } - SetExtraSpriteFrame(this, 1, this->frameIndex); - SetSpriteSubEntryOffsetData1(this, 1, 0); - sub_0807000C(this); + SetExtraSpriteFrame(super, 1, super->frameIndex); + SetSpriteSubEntryOffsetData1(super, 1, 0); + sub_0807000C(super); } else { - frames = this->frame; + frames = super->frame; if (frames != 0xff) { frames &= ~0x80; } - if ((this->frameSpriteSettings & 1) == 0) { + if ((super->frameSpriteSettings & 1) == 0) { frames = 0xff; } - SetExtraSpriteFrame(this, 0, frames); - SetExtraSpriteFrame(this, 1, this->frameIndex); - SetSpriteSubEntryOffsetData1(this, 1, 0); - sub_0807000C(this); + SetExtraSpriteFrame(super, 0, frames); + SetExtraSpriteFrame(super, 1, super->frameIndex); + SetSpriteSubEntryOffsetData1(super, 1, 0); + sub_0807000C(super); } } -void sub_0806AEA8(Entity* this) { - int old = this->field_0x82.HWORD; - this->field_0x82.HWORD &= ~0x20; +void sub_0806AEA8(TownMinishEntity* this) { + int old = this->unk_82; + this->unk_82 &= ~0x20; if (old & 0x20) { - GravityUpdate(this, Q_8_8(64.0)); + GravityUpdate(super, Q_8_8(64.0)); } - HandleEntity0x82Actions(this); - this->field_0x82.HWORD = old; + HandleEntity0x82Actions(super); + this->unk_82 = old; } -void sub_0806AED8(Entity* this) { - this->timer = 0; +void sub_0806AED8(TownMinishEntity* this) { + super->timer = 0; sub_0806AEE4(this); } -void sub_0806AEE4(Entity* this) { +void sub_0806AEE4(TownMinishEntity* this) { int index; const u8* idx3; u8 tmp1, tmp2; - if (this->timer) { - this->timer--; + if (super->timer) { + super->timer--; } else { - this->timer = 2; - index = GetFacingDirectionInRectRadius(this, 0x20, 0x20); + super->timer = 2; + index = GetFacingDirectionInRectRadius(super, 0x20, 0x20); if (index < 0) { - int state = this->field_0x6a.HALF.LO; - this->animationState = state * 2; + int state = this->unk_6a; + super->animationState = state * 2; index = state * 8; } - idx3 = gUnk_081125F4[this->animationState / 2][index >> 1]; + idx3 = gUnk_081125F4[super->animationState / 2][index >> 1]; tmp1 = idx3[0]; tmp2 = idx3[1]; if (tmp2 & 0x80) { - this->animationState = sub_0806F5B0(index); + super->animationState = GetAnimationStateForDirection8(index); } tmp2 &= ~0x80; - this->frame = tmp1; - this->frameIndex = tmp2; - this->frameSpriteSettings = 1; - this->animIndex = 0; - this->frameDuration = 0xff; + super->frame = tmp1; + super->frameIndex = tmp2; + super->frameSpriteSettings = 1; + super->animIndex = 0; + super->frameDuration = 0xff; } } diff --git a/src/npc/townsperson.c b/src/npc/townsperson.c index adb973cbd..0e6f1c368 100644 --- a/src/npc/townsperson.c +++ b/src/npc/townsperson.c @@ -1,6 +1,21 @@ -#include "npc.h" +/** + * @file townsperson.c + * @ingroup NPCs + * + * @brief Townsperson NPC + */ +#define NENT_DEPRECATED #include "functions.h" #include "item.h" +#include "npc.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; + /*0x69*/ u8 unk_69; + /*0x6a*/ s16 unk_6a; + /*0x6c*/ s16 unk_6c; +} TownspersonEntity; typedef struct { u8 frame1; @@ -10,7 +25,7 @@ typedef struct { } struct_0810B680; extern void sub_08061CB4(Entity*, u32); -extern void sub_08061D64(Entity*); +extern void sub_08061D64(TownspersonEntity*); extern void sub_08062048(Entity*); extern struct_0810B680 gUnk_0810B680[]; @@ -88,77 +103,79 @@ void sub_08061CB4(Entity* this, u32 arg1) { } } -void sub_08061CEC(Entity* this) { +void sub_08061CEC(TownspersonEntity* this) { u32 uVar2; - if (LoadExtraSpriteData(this, gUnk_0810B6EC[this->type])) { - this->action = 1; - this->spriteSettings.draw = TRUE; - this->animationState = this->timer; - this->field_0x68.HALF.HI = 0xff; - uVar2 = sub_0805ACC0(this); + if (LoadExtraSpriteData(super, gUnk_0810B6EC[super->type])) { + super->action = 1; + super->spriteSettings.draw = TRUE; + super->animationState = super->timer; + this->unk_69 = 0xff; + uVar2 = sub_0805ACC0(super); if (uVar2 == 0) { - this->field_0x6a.HWORD = this->x.HALF.HI; - uVar2 = (u16)this->y.HALF.HI; + this->unk_6a = super->x.HALF.HI; + uVar2 = (u16)super->y.HALF.HI; } else { - this->field_0x6a.HWORD = (uVar2 >> 0x10); + this->unk_6a = (uVar2 >> 0x10); } - *(u16*)&this->field_0x6c = uVar2; - this->field_0x68.HALF.LO = GetFusionToOffer(this); - sub_0807DD64(this); + this->unk_6c = uVar2; + this->fusionOffer = GetFusionToOffer(super); + sub_0807DD64(super); sub_08061D64(this); } } -void sub_08061D64(Entity* this) { - if (this->interactType == 2) { - this->action = 3; - this->interactType = 0; - sub_0806F118(this); - this->field_0x68.HALF.HI = this->animIndex; - InitializeAnimation(this, (this->animIndex & -4) + sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); +void sub_08061D64(TownspersonEntity* this) { + if (super->interactType == 2) { + super->action = 3; + super->interactType = 0; + InitializeNPCFusion(super); + this->unk_69 = super->animIndex; + InitializeAnimation(super, (super->animIndex & -4) + + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } else { - ExecuteScriptForEntity(this, NULL); - HandleEntity0x82Actions(this); - if (this->frameDuration == 0xff) { - this->frameDuration = gUnk_0810B680[this->type].unk2; + ExecuteScriptForEntity(super, NULL); + HandleEntity0x82Actions(super); + if (super->frameDuration == 0xff) { + super->frameDuration = gUnk_0810B680[super->type].unk2; } - GetNextFrame(this); - if (this->interactType != 0) { - this->action = 2; - this->interactType = 0; - sub_08062048(this); - this->field_0x68.HALF.HI = this->animIndex; - InitializeAnimation(this, (this->animIndex & -4) + sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity))); + GetNextFrame(super); + if (super->interactType != 0) { + super->action = 2; + super->interactType = 0; + sub_08062048(super); + this->unk_69 = super->animIndex; + InitializeAnimation(super, (super->animIndex & -4) + + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity))); } } } -void sub_08061E24(Entity* this) { - GetNextFrame(this); +void sub_08061E24(TownspersonEntity* this) { + GetNextFrame(super); if ((gMessage.doTextBox & 0x7f) == 0) { - this->action = 1; - InitializeAnimation(this, this->field_0x68.HALF.HI); + super->action = 1; + InitializeAnimation(super, this->unk_69); } } -void sub_08061E50(Entity* this) { +void sub_08061E50(TownspersonEntity* this) { - if (UpdateFuseInteraction(this) != 0) { - this->action = 1; - InitializeAnimation(this, this->field_0x68.HALF.HI); + if (UpdateFuseInteraction(super) != 0) { + super->action = 1; + InitializeAnimation(super, this->unk_69); } } -void Townsperson_MakeInteractable(Entity* this) { - if (this->id == 6) { - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void Townsperson_MakeInteractable(TownspersonEntity* this) { + if (super->id == 6) { + AddInteractableWhenBigFuser(super, this->fusionOffer); } else { - AddInteractableWhenBigObject(this); + AddInteractableWhenBigObject(super); } } -void sub_08061E90(Entity* this, ScriptExecutionContext* context) { +void sub_08061E90(TownspersonEntity* this, ScriptExecutionContext* context) { u32 animIndex; s32 iVar4; @@ -166,7 +183,7 @@ void sub_08061E90(Entity* this, ScriptExecutionContext* context) { context->unk_18++; context->unk_12 = (Random() & 0x3f) + 0x20; animIndex = DirectionRound(Random()); - switch (this->direction) { + switch (super->direction) { case 0x0: if (animIndex == 0x10) { animIndex = 0x8; @@ -187,32 +204,32 @@ void sub_08061E90(Entity* this, ScriptExecutionContext* context) { animIndex = 0; } } - this->direction = (u8)animIndex; - this->animationState = sub_0806F5B0(animIndex); - this->speed = gUnk_0810B74A[this->type]; + super->direction = (u8)animIndex; + super->animationState = GetAnimationStateForDirection8(animIndex); + super->speed = gUnk_0810B74A[super->type]; } - animIndex = (this->animationState >> 1) + 4; - if (animIndex != this->animIndex) { - InitializeAnimation(this, animIndex); + animIndex = (super->animationState >> 1) + 4; + if (animIndex != super->animIndex) { + InitializeAnimation(super, animIndex); } - ProcessMovement0(this); - iVar4 = this->x.HALF.HI - *(s16*)&this->field_0x6a.HWORD; + ProcessMovement0(super); + iVar4 = super->x.HALF.HI - this->unk_6a; if (0x10 < iVar4) { - this->x.HALF.HI = this->field_0x6a.HWORD + 0x10; + super->x.HALF.HI = this->unk_6a + 0x10; context->unk_12 = 1; } if (iVar4 < -0x10) { - this->x.HALF.HI = *(s16*)&this->field_0x6a.HWORD - 0x10; + super->x.HALF.HI = this->unk_6a - 0x10; context->unk_12 = 1; } - iVar4 = this->y.HALF.HI - *(s16*)&this->field_0x6c; + iVar4 = super->y.HALF.HI - this->unk_6c; if (0x10 < iVar4) { - this->y.HALF.HI = *(s16*)&this->field_0x6c + 0x10; + super->y.HALF.HI = this->unk_6c + 0x10; context->unk_12 = 1; } if (iVar4 < -0x10) { - this->y.HALF.HI = *(s16*)&this->field_0x6c - 0x10; + super->y.HALF.HI = this->unk_6c - 0x10; context->unk_12 = 1; } if (--context->unk_12 != 0) { diff --git a/src/npc/vaati.c b/src/npc/vaati.c index e9197a559..f55e285f8 100644 --- a/src/npc/vaati.c +++ b/src/npc/vaati.c @@ -1,45 +1,61 @@ -#include "global.h" +/** + * @file vaati.c + * @ingroup NPCs + * + * @brief Vaati NPC + */ +#define NENT_DEPRECATED #include "entity.h" +#include "functions.h" #include "script.h" #include "sound.h" -#include "functions.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unk_68; + /*0x69*/ s8 unk_69; + /*0x6a*/ u8 unused1[22]; + /*0x80*/ u16 unk_80; + /*0x82*/ u8 unused2[2]; + /*0x84*/ ScriptExecutionContext* context; +} VaatiEntity; extern void sub_08095CB0(Entity*); extern void CreateRepeatedSoundManager(Entity*); extern void DeleteRepeatedSoundManager(Entity*); extern void CreateVaatiApparateManager(Entity*, u32); -void VaatiAction0(Entity*); -void VaatiAction1(Entity*); +void VaatiAction0(VaatiEntity*); +void VaatiAction1(VaatiEntity*); void sub_08066B74(Entity*, ScriptExecutionContext*); -void (*const vaatiActions[])(Entity*) = { VaatiAction0, VaatiAction1 }; +void (*const vaatiActions[])(VaatiEntity*) = { VaatiAction0, VaatiAction1 }; -void Vaati(Entity* this) { - vaatiActions[this->action](this); - this->palette.b.b0 = this->palette.b.b4 + (this->frameSpriteSettings & 1); +void Vaati(VaatiEntity* this) { + vaatiActions[super->action](this); + super->palette.b.b0 = super->palette.b.b4 + (super->frameSpriteSettings & 1); } -void VaatiAction0(Entity* this) { - this->action = 1; - this->subAction = 0; - this->spriteSettings.draw = 1; - this->field_0x68.HALF.LO = 0; - this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD64(this); +void VaatiAction0(VaatiEntity* this) { + super->action = 1; + super->subAction = 0; + super->spriteSettings.draw = 1; + this->unk_68 = 0; + this->unk_69 = 0; + SetDefaultPriority(super, PRIO_MESSAGE); + sub_0807DD64(super); VaatiAction1(this); } -void VaatiAction1(Entity* this) { - ScriptExecutionContext* tmp; - sub_0807DD94(this, sub_08066B74); - if ((*(s8*)&this->field_0x68.HALF.HI != 0) && ((gRoomTransition.frameCount & 3) == 0)) { - sub_08095CB0(this); +void VaatiAction1(VaatiEntity* this) { + ScriptExecutionContext* context; + ExecuteScriptAndHandleAnimation(super, sub_08066B74); + if ((*(s8*)&this->unk_69 != 0) && ((gRoomTransition.frameCount & 3) == 0)) { + sub_08095CB0(super); } - if ((this->frame & ~0x80) != 0) { - switch (this->frame & ~0x80u) { + if ((super->frame & ~0x80) != 0) { + switch (super->frame & ~0x80u) { case 1: EnqueueSFX(SFX_21C); break; @@ -47,18 +63,18 @@ void VaatiAction1(Entity* this) { EnqueueSFX(SFX_21E); break; case 3: - tmp = (*(ScriptExecutionContext**)&this->cutsceneBeh); - tmp->intVariable = 4; - CreateRepeatedSoundManager(this); + context = this->context; + context->intVariable = 4; + CreateRepeatedSoundManager(super); break; case 4: - tmp = (*(ScriptExecutionContext**)&this->cutsceneBeh); - tmp->intVariable = 4; - DeleteRepeatedSoundManager(this); + context = this->context; + context->intVariable = 4; + DeleteRepeatedSoundManager(super); EnqueueSFX(SFX_21D); break; } - this->frame &= ~0x80; + super->frame &= ~0x80; } } @@ -77,45 +93,45 @@ void sub_08066B74(Entity* this, ScriptExecutionContext* context) { switch (currentAction) { case 1 << 20: - this->field_0x80.HWORD = animationState + 0x10; + ((VaatiEntity*)this)->unk_80 = animationState + 0x10; break; case 1 << 21: - this->field_0x80.HWORD = animationState + 0x14; + ((VaatiEntity*)this)->unk_80 = animationState + 0x14; break; case 1 << 22: - this->field_0x80.HWORD = animationState + 0x18; + ((VaatiEntity*)this)->unk_80 = animationState + 0x18; break; case 1 << 23: - this->field_0x80.HWORD = animationState + 0x1c; + ((VaatiEntity*)this)->unk_80 = animationState + 0x1c; break; case 1 << 24: - this->field_0x80.HWORD = animationState + 0x20; + ((VaatiEntity*)this)->unk_80 = animationState + 0x20; break; case 1 << 25: - this->field_0x80.HWORD = animationState + 0x24; + ((VaatiEntity*)this)->unk_80 = animationState + 0x24; break; case 1 << 26: - this->field_0x80.HWORD = animationState + 0x28; + ((VaatiEntity*)this)->unk_80 = animationState + 0x28; break; case 1 << 27: - this->field_0x80.HWORD = animationState + 0x2c; + ((VaatiEntity*)this)->unk_80 = animationState + 0x2c; break; case 1 << 28: - this->field_0x80.HWORD = animationState + 0x30; + ((VaatiEntity*)this)->unk_80 = animationState + 0x30; break; case 1 << 29: - this->field_0x68.HALF.LO = 1; + ((VaatiEntity*)this)->unk_68 = 1; break; case 1 << 30: - this->field_0x68.HALF.LO = 0xff; + ((VaatiEntity*)this)->unk_68 = 0xff; break; case 1 << 31: - this->field_0x68.HALF.HI ^= 1; + ((VaatiEntity*)this)->unk_69 ^= 1; break; } } while (actions != 0); } - HandlePostScriptActions(this, *(ScriptExecutionContext**)&this->cutsceneBeh); + HandlePostScriptActions(this, ((VaatiEntity*)this)->context); } void Vaati_Apparate(Entity* this) { diff --git a/src/npc/vaatiReborn.c b/src/npc/vaatiReborn.c index f2837926a..5e80be89a 100644 --- a/src/npc/vaatiReborn.c +++ b/src/npc/vaatiReborn.c @@ -1,6 +1,12 @@ -#include "global.h" -#include "npc.h" +/** + * @file vaatiReborn.c + * @ingroup NPCs + * + * @brief Vaati Reborn NPC + */ +#define NENT_DEPRECATED #include "functions.h" +#include "npc.h" void VaatiRebornAction0(Entity* this); void VaatiRebornAction1(Entity* this); diff --git a/src/npc/wheaton.c b/src/npc/wheaton.c index daa98a6f8..aa24f3211 100644 --- a/src/npc/wheaton.c +++ b/src/npc/wheaton.c @@ -1,3 +1,10 @@ +/** + * @file wheaton.c + * @ingroup NPCs + * + * @brief Wheaton NPC + */ +#define NENT_DEPRECATED #include "npc.h" void Wheaton(Entity* this) { @@ -11,5 +18,5 @@ void Wheaton(Entity* this) { this->spriteOffsetY = 0xfe; sub_0807DD64(this); } - sub_0807DD94(this, 0); + ExecuteScriptAndHandleAnimation(this, NULL); } diff --git a/src/npc/windTribespeople.c b/src/npc/windTribespeople.c index aa5c9c869..d8af4afa2 100644 --- a/src/npc/windTribespeople.c +++ b/src/npc/windTribespeople.c @@ -1,7 +1,18 @@ -#include "global.h" -#include "sound.h" +/** + * @file windTribespeople.c + * @ingroup NPCs + * + * @brief Wind Tribespeople NPC + */ +#define NENT_DEPRECATED #include "entity.h" #include "npc.h" +#include "sound.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 fusionOffer; +} WindTribespeopleEntity; void sub_0806C798(Entity*); void sub_0806C7D4(Entity*); @@ -43,7 +54,7 @@ void sub_0806C798(Entity* this) { this->action = 1; this->spriteSettings.draw = 1; this->animationState = this->timer; - sub_0807DD50(this); + InitScriptForNPC(this); sub_0806C7D4(this); } } @@ -52,12 +63,12 @@ void sub_0806C7D4(Entity* this) { u32 iVar1; u32 uVar2; - if (this->interactType == '\x02') { + if (this->interactType == 2) { this->action = 3; this->interactType = 0; - sub_0806F118(this); + InitializeNPCFusion(this); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(this, NULL); if ((this->type2 == 3) && (!CheckGlobalFlag(WARP_EVENT_END)) && (CheckLocalFlag(SORA_ELDER_RECOVER)) && (CheckRoomFlag(0))) { this->type2 = 7; @@ -79,12 +90,9 @@ void sub_0806C85C(Entity* this) { } } -void WindTribespeople_MakeInteractable(Entity* this) { - u8 bVar1; - - bVar1 = GetFusionToOffer(this); - this->field_0x68.HALF.LO = bVar1; - AddInteractableWhenBigFuser(this, this->field_0x68.HALF.LO); +void WindTribespeople_MakeInteractable(WindTribespeopleEntity* this) { + this->fusionOffer = GetFusionToOffer(super); + AddInteractableWhenBigFuser(super, this->fusionOffer); } void WindTribespeople_Head(Entity* this) { diff --git a/src/npc/zelda.c b/src/npc/zelda.c index 64898ef7f..a2882348f 100644 --- a/src/npc/zelda.c +++ b/src/npc/zelda.c @@ -1,9 +1,16 @@ -#include "global.h" -#include "sound.h" +/** + * @file zelda.c + * @ingroup NPCs + * + * @brief Zelda NPC + */ +#define NENT_DEPRECATED +#include "npc/zelda.h" #include "entity.h" -#include "functions.h" #include "flags.h" +#include "functions.h" #include "npc.h" +#include "sound.h" void ZeldaFollower_Hide(Entity*, Entity*); void ZeldaFollower_Show(Entity*, Entity*); @@ -25,11 +32,11 @@ void sub_08066CCC(Entity* this) { this->spriteSettings.draw = 1; PrependEntityToList(this, 7); SetDefaultPriority(this, PRIO_MESSAGE); - sub_0807DD50(this); + InitScriptForNPC(this); } void sub_08066CF8(Entity* this) { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(this, NULL); } void sub_08066D04(Entity* this) { @@ -68,17 +75,17 @@ void sub_08066D4C(Entity* this, ScriptExecutionContext* context) { void sub_08066D94(Entity* this) { u32 room; - Entity* npc; + ZeldaFollowerEntity* npc; SetGlobalFlag(ZELDA_CHASE); - npc = CreateNPC(ZELDA_FOLLOWER, 0, 0); + npc = (ZeldaFollowerEntity*)CreateNPC(ZELDA_FOLLOWER, 0, 0); if (npc != NULL) { - npc->animationState = gPlayerEntity.animationState; - npc->flags |= ENT_PERSIST; - npc->animationState = GetAnimationState(this); + npc->base.animationState = gPlayerEntity.animationState; + npc->base.flags |= ENT_PERSIST; + npc->base.animationState = GetAnimationState(this); room = gRoomControls.room; - npc->field_0x74.HWORD = room; - CopyPosition(this, npc); + npc->unk_74 = room; + CopyPosition(this, &npc->base); } DeleteThisEntity(); } @@ -91,29 +98,29 @@ void SetZeldaFollowTarget(Entity* target) { } } -void sub_08066E08(Entity* this) { - InitAnimationForceUpdate(this, 0x50); - this->field_0x80.HWORD = this->animIndex; +void sub_08066E08(ZeldaEntity* this) { + InitAnimationForceUpdate(super, 0x50); + this->unk_80 = super->animIndex; } -void sub_08066E20(Entity* this) { - InitAnimationForceUpdate(this, 0x44); - this->field_0x80.HWORD = this->animIndex; +void sub_08066E20(ZeldaEntity* this) { + InitAnimationForceUpdate(super, 0x44); + this->unk_80 = super->animIndex; } -void sub_08066E38(Entity* this) { - InitAnimationForceUpdate(this, 0x48); - this->field_0x80.HWORD = this->animIndex; +void sub_08066E38(ZeldaEntity* this) { + InitAnimationForceUpdate(super, 0x48); + this->unk_80 = super->animIndex; } -void sub_08066E50(Entity* this) { - InitAnimationForceUpdate(this, 0x4C); - this->field_0x80.HWORD = this->animIndex; +void sub_08066E50(ZeldaEntity* this) { + InitAnimationForceUpdate(super, 0x4C); + this->unk_80 = super->animIndex; } -void sub_08066E68(Entity* this) { - InitAnimationForceUpdate(this, 0x54); - this->field_0x80.HWORD = this->animIndex; +void sub_08066E68(ZeldaEntity* this) { + InitAnimationForceUpdate(super, 0x54); + this->unk_80 = super->animIndex; } void sub_08066E80(Entity* this, ScriptExecutionContext* context) { @@ -156,7 +163,7 @@ void sub_08066E80(Entity* this, ScriptExecutionContext* context) { return; } } - this->field_0x80.HWORD = this->animIndex; + ((ZeldaEntity*)this)->unk_80 = this->animIndex; gActiveScriptInfo.commandSize = 0; } diff --git a/src/npc/zeldaFollower.c b/src/npc/zeldaFollower.c index 2402823d1..fd9c71d96 100644 --- a/src/npc/zeldaFollower.c +++ b/src/npc/zeldaFollower.c @@ -1,3 +1,11 @@ +/** + * @file zeldaFollower.c + * @ingroup NPCs + * + * @brief Zelda Follower NPC + */ +#define NENT_DEPRECATED +#include "npc/zelda.h" #include "common.h" #include "entity.h" #include "functions.h" @@ -18,8 +26,8 @@ typedef union { #define ZELDA_FOLLOWER_HEAP_LEN 20 -#define ZELDA_FOLLOWER_HEAP ((ZeldaFollowerItem*)this->myHeap) -#define ZELDA_FOLLOWER_HEAP_END ((ZeldaFollowerItem*)this->myHeap + (ZELDA_FOLLOWER_HEAP_LEN - 1)) +#define ZELDA_FOLLOWER_HEAP ((ZeldaFollowerItem*)super->myHeap) +#define ZELDA_FOLLOWER_HEAP_END ((ZeldaFollowerItem*)super->myHeap + (ZELDA_FOLLOWER_HEAP_LEN - 1)) #define ZELDA_FOLLOWER_HEAP_SHIFT_RIGHT(this, heapPtr) \ do { \ @@ -32,29 +40,29 @@ typedef union { } \ } while (0) -void sub_08068318(Entity*); -void sub_0806854C(Entity*, u32*); +void sub_08068318(ZeldaFollowerEntity*); +void sub_0806854C(ZeldaFollowerEntity*, u32*); void sub_08068578(Entity* this); -void ZeldaFollower(Entity* this) { - if (this->action == 0) { - this->action++; - this->spriteSettings.draw = TRUE; - this->animationState = 4; - this->field_0x68.HALF.LO = 0; - this->field_0x68.HALF.HI = 0; - SetDefaultPriority(this, PRIO_MESSAGE); - InitAnimationForceUpdate(this, 0); +void ZeldaFollower(ZeldaFollowerEntity* this) { + if (super->action == 0) { + super->action++; + super->spriteSettings.draw = TRUE; + super->animationState = 4; + this->unk_68 = 0; + this->unk_69 = 0; + SetDefaultPriority(super, PRIO_MESSAGE); + InitAnimationForceUpdate(super, 0); sub_0806854C(this, NULL); } - if ((s8)this->field_0x68.HALF.LO != 0) { + if ((s8)this->unk_68 != 0) { sub_08068318(this); } else { - this->spriteSettings.draw = FALSE; + super->spriteSettings.draw = FALSE; } } -void sub_08068318(Entity* this) { +void sub_08068318(ZeldaFollowerEntity* this) { s32 dist; s16 z; @@ -71,39 +79,39 @@ void sub_08068318(Entity* this) { item.FIELDS.animationState = gPlayerEntity.animationState; item.FIELDS.collisionLayer = gPlayerEntity.collisionLayer; - heapPtr = this->myHeap; + heapPtr = super->myHeap; if ((heapPtr->FIELDS.framestate == 0xa && item.FIELDS.framestate != 0xa) || (heapPtr->FIELDS.framestate == 0x16 && item.FIELDS.framestate != 0x16)) { - this->x.HALF.HI = gPlayerEntity.x.HALF.HI; - this->y.HALF.HI = gPlayerEntity.y.HALF.HI; - this->spriteSettings.draw = 1; - sub_08068578(this); + super->x.HALF.HI = gPlayerEntity.x.HALF.HI; + super->y.HALF.HI = gPlayerEntity.y.HALF.HI; + super->spriteSettings.draw = 1; + sub_08068578(super); } animIndex = 0; if (item.DWORD != heapPtr->DWORD || item.FIELDS.framestate == 0x16 || item.FIELDS.framestate == 0xa) { - ZELDA_FOLLOWER_HEAP_SHIFT_RIGHT(this, heapPtr); + ZELDA_FOLLOWER_HEAP_SHIFT_RIGHT(super, heapPtr); heapPtr = ZELDA_FOLLOWER_HEAP; heapPtr[0] = item; animIndex = 0x4; - if ((s8)this->field_0x68.HALF.HI > 0) { - this->field_0x68.HALF.HI = this->field_0x68.HALF.HI - 1; + if ((s8)this->unk_69 > 0) { + this->unk_69 = this->unk_69 - 1; } } else { heapPtr += ZELDA_FOLLOWER_HEAP_LEN - 1; z = heapPtr->FIELDS.z; if (z < 0) { - ZELDA_FOLLOWER_HEAP_SHIFT_RIGHT(this, heapPtr); + ZELDA_FOLLOWER_HEAP_SHIFT_RIGHT(super, heapPtr); animIndex = 0x4; } else { dist = sub_080041E8(gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI, (u16)heapPtr->FIELDS.x, (u16)heapPtr->FIELDS.y); dist = ((u32)dist) >> 0x4; if (dist > 0x18) { - ZELDA_FOLLOWER_HEAP_SHIFT_RIGHT(this, heapPtr); + ZELDA_FOLLOWER_HEAP_SHIFT_RIGHT(super, heapPtr); animIndex = 0x4; } } @@ -111,43 +119,43 @@ void sub_08068318(Entity* this) { heapPtr = ZELDA_FOLLOWER_HEAP; heapPtr += ZELDA_FOLLOWER_HEAP_LEN - 1; - this->x.HALF.HI = heapPtr->FIELDS.x; - this->y.HALF.HI = heapPtr->FIELDS.y; - this->z.HALF.HI = heapPtr->FIELDS.z; - this->animationState = heapPtr->FIELDS.animationState; - this->collisionLayer = heapPtr->FIELDS.collisionLayer; + super->x.HALF.HI = heapPtr->FIELDS.x; + super->y.HALF.HI = heapPtr->FIELDS.y; + super->z.HALF.HI = heapPtr->FIELDS.z; + super->animationState = heapPtr->FIELDS.animationState; + super->collisionLayer = heapPtr->FIELDS.collisionLayer; if (heapPtr->FIELDS.framestate == 0x16 || heapPtr->FIELDS.framestate == 0xa) { - this->spriteSettings.draw = 0; + super->spriteSettings.draw = 0; } - if (((s8)this->field_0x68.HALF.HI) > 0) { - this->field_0x68.HALF.HI = this->field_0x68.HALF.HI - 1; + if (((s8)this->unk_69) > 0) { + this->unk_69 = this->unk_69 - 1; } animIndexTmp = animIndex; - animIndex += this->animationState >> 1; + animIndex += super->animationState >> 1; - if (!(animIndex == this->animIndex || (animIndexTmp == 0 && ((s8)this->field_0x68.HALF.HI) > 0))) { - InitAnimationForceUpdate(this, animIndex); - this->field_0x68.HALF.HI = 0x1e; + if (!(animIndex == super->animIndex || (animIndexTmp == 0 && ((s8)this->unk_69) > 0))) { + InitAnimationForceUpdate(super, animIndex); + this->unk_69 = 0x1e; } else { - UpdateAnimationSingleFrame(this); + UpdateAnimationSingleFrame(super); } - sub_0800451C(this); - if (this->z.HALF.HI < 0) { - sub_0806F854(this, 0x0, -0xc); + sub_0800451C(super); + if (super->z.HALF.HI < 0) { + sub_0806F854(super, 0x0, -0xc); } } -void sub_0806854C(Entity* this, u32* none) { - this->myHeap = zMalloc(sizeof(ZeldaFollowerItem[ZELDA_FOLLOWER_HEAP_LEN])); - if (this->myHeap != NULL) { - this->field_0x68.HALF.LO = 1; - RemoveInteractableObject(this); - this->hitbox = NULL; - sub_08068578(this); +void sub_0806854C(ZeldaFollowerEntity* this, u32* none) { + super->myHeap = zMalloc(sizeof(ZeldaFollowerItem[ZELDA_FOLLOWER_HEAP_LEN])); + if (super->myHeap != NULL) { + this->unk_68 = 1; + RemoveInteractableObject(super); + super->hitbox = NULL; + sub_08068578(super); } } @@ -272,17 +280,17 @@ void sub_08068578(Entity* this) { } } -void ZeldaFollower_Hide(Entity* zelda, Entity* follower) { - follower->field_0x68.HALF.LO = 0; - follower->spriteSettings.draw = 0; +void ZeldaFollower_Hide(Entity* zelda, ZeldaFollowerEntity* follower) { + follower->unk_68 = 0; + follower->base.spriteSettings.draw = 0; } -void ZeldaFollower_Show(Entity* zelda, Entity* follower) { - follower->field_0x68.HALF.LO = 1; - follower->spriteSettings.draw = 1; - follower->animationState = zelda->animationState; - sub_08068578(follower); - InitAnimationForceUpdate(follower, follower->animationState / 2); +void ZeldaFollower_Show(Entity* zelda, ZeldaFollowerEntity* follower) { + follower->unk_68 = 1; + follower->base.spriteSettings.draw = 1; + follower->base.animationState = zelda->animationState; + sub_08068578(&follower->base); + InitAnimationForceUpdate(&follower->base, follower->base.animationState / 2); } void sub_080686C4(Entity* zelda, Entity* follower) { diff --git a/src/npcUtils.c b/src/npcUtils.c index 8702f3eb4..4804a6479 100644 --- a/src/npcUtils.c +++ b/src/npcUtils.c @@ -12,8 +12,8 @@ extern const NPCDefinition gNPCDefinitions[]; typedef struct { u16 textIndex; - u16 _2; - u16 _4; + u16 cancelledTextIndex; + u16 fusingTextIndex; } NPCData; extern NPCData* gUnk_08001A7C[]; @@ -128,7 +128,7 @@ s32 GetAnimationStateInRectRadius(Entity* ent, u32 x, u32 y) { u32 GetAnimationState(Entity* ent) { u32 direction = GetFacingDirection(ent, &gPlayerEntity); - return sub_0806F5A4(direction); + return GetAnimationStateForDirection4(direction); } s32 GetFacingDirectionInRectRadius(Entity* ent, u32 x, u32 y) { @@ -161,7 +161,7 @@ u32 sub_0806EE20(Entity* ent) { } else { ent->knockbackSpeed = 8; v3 = GetFacingDirection(ent, &gPlayerEntity); - ent->knockbackDirection = sub_0806F5A4(v3); + ent->knockbackDirection = GetAnimationStateForDirection4(v3); } return 0; } @@ -206,7 +206,7 @@ static void sub_0806EF14(Entity* ent) { sub_0806EF4C(ent, xy); ent->direction = sub_080045B4(ent, xy[0], xy[1]); if ((ent->collisionFlags & 1) == 0) - ent->knockbackDirection = sub_0806F5A4(ent->direction); + ent->knockbackDirection = GetAnimationStateForDirection4(ent->direction); } static void sub_0806EF4C(Entity* ent, u16* xy) { @@ -326,36 +326,37 @@ void CollideFollowers(void) { } } -void sub_0806F118(Entity* ent) { - u32 idx = GetFuserId(ent); - NPCData* data = gUnk_08001A7C[idx]; - sub_0801DFB4(ent, data->textIndex, data->_2, data->_4); +void InitializeNPCFusion(Entity* entity) { + u32 fuserId = GetFuserId(entity); + NPCData* data = gUnk_08001A7C[fuserId]; + InitializeFuseInfo(entity, data->textIndex, data->cancelledTextIndex, data->fusingTextIndex); gPlayerState.controlMode = CONTROL_DISABLED; } -u32 UpdateFuseInteraction(Entity* ent) { - u32 ret; - sub_0801E00C(); - ret = -1; - switch (gFuseInfo._0) { +// Returns -1, 0, or 1 +u32 UpdateFuseInteraction(Entity* entity) { + u32 result; + PerformFuseAction(); + result = -1; + switch (gFuseInfo.fusionState) { default: - ret = 0; + result = 0; break; - case 2: + case FUSION_STATE_2: gPlayerState.controlMode = CONTROL_DISABLED; - ret = 1; - case 1: + result = 1; + case FUSION_STATE_1: PlayerResetStateFromFusion(); gPlayerState.controlMode = CONTROL_1; break; } - return ret; + return result; } -void MarkFuserDone(Entity* ent) { - u32 idx = GetFuserId(ent); - if (idx != 0) - gSave.fuserOffers[idx] = KINSTONE_FUSER_DONE; +void MarkFuserDone(Entity* entity) { + u32 fuserId = GetFuserId(entity); + if (fuserId != 0) + gSave.fuserOffers[fuserId] = KINSTONE_FUSER_DONE; } void ShowNPCDialogue(Entity* ent, const Dialog* dia) { diff --git a/src/object/cameraTarget.c b/src/object/cameraTarget.c index 57a5623ac..9c0019157 100644 --- a/src/object/cameraTarget.c +++ b/src/object/cameraTarget.c @@ -49,10 +49,10 @@ void CameraTarget(Entity* this) { u32 uVar2 = gPlayerState.field_0x27[0] > 0; - switch (gFuseInfo._0) { - case 0: - case 1: - case 2: + switch (gFuseInfo.fusionState) { + case FUSION_STATE_0: + case FUSION_STATE_1: + case FUSION_STATE_2: if ((gMessage.doTextBox & 0x7f) == 0) { break; } diff --git a/src/object/cuccoMinigame.c b/src/object/cuccoMinigame.c index f6b02dd18..efdf3a417 100644 --- a/src/object/cuccoMinigame.c +++ b/src/object/cuccoMinigame.c @@ -108,7 +108,7 @@ void CuccoMinigame(CuccoMinigameEntity* this) { sub_0807DD64(super); sub_0806EC20(super); } - sub_0807DD94(super, 0); + ExecuteScriptAndHandleAnimation(super, NULL); } NONMATCH("asm/non_matching/objectB9/sub_080A1270.inc", void sub_080A1270(CuccoMinigameEntity* this)) { diff --git a/src/object/cutsceneOrchestrator.c b/src/object/cutsceneOrchestrator.c index aee672f17..efc726a3b 100644 --- a/src/object/cutsceneOrchestrator.c +++ b/src/object/cutsceneOrchestrator.c @@ -13,9 +13,9 @@ void CutsceneOrchestrator(Entity* this) { if (this->action == 0) { this->action = 1; this->hitbox = (Hitbox*)&gHitbox_2; - sub_0807DD50(this); + InitScriptForNPC(this); } else { - sub_0807DD94(this, NULL); + ExecuteScriptAndHandleAnimation(this, NULL); } } else { this->action = 1; diff --git a/src/object/keyStealingTakkuri.c b/src/object/keyStealingTakkuri.c index 1b166cab5..a3f516d56 100644 --- a/src/object/keyStealingTakkuri.c +++ b/src/object/keyStealingTakkuri.c @@ -478,7 +478,7 @@ void sub_0809E1F0(KeyStealingTakkuriEntity* this) { } void sub_0809E210(KeyStealingTakkuriEntity* this) { - gPlayerEntity.animationState = sub_0806F5B0(GetFacingDirection(&gPlayerEntity, super)) & 0xfe; + gPlayerEntity.animationState = GetAnimationStateForDirection8(GetFacingDirection(&gPlayerEntity, super)) & 0xfe; gPlayerState.animation = 0x100; } diff --git a/src/object/pullableMushroom.c b/src/object/pullableMushroom.c index 3200afbf3..b231911a8 100644 --- a/src/object/pullableMushroom.c +++ b/src/object/pullableMushroom.c @@ -198,7 +198,7 @@ void sub_0808ACEC(PullableMushroomEntity* this) { case 0x14: case 0x16: COLLISION_OFF(super); - super->animationState = sub_0806F5A4(super->knockbackDirection); + super->animationState = GetAnimationStateForDirection4(super->knockbackDirection); super->subAction = 2; super->timer = 2; break; diff --git a/src/physics.c b/src/physics.c index 023af557e..63f29f149 100644 --- a/src/physics.c +++ b/src/physics.c @@ -13,8 +13,8 @@ const u8 gSpriteSortAboveTable[]; const u8 gSpriteSortBelowTable[]; -const u8 gUnk_08114F58[]; -const u8 gUnk_08114F38[]; +const u8 gMapDirectionToAnimationState8[]; +const u8 gMapDirectionToAnimationState4[]; extern u16 gExtraFrameOffsets[]; extern s8 gUnk_08126EE4[]; @@ -131,19 +131,19 @@ u32 sub_0806F548(Entity* a, Entity* b, u32 x, u32 y) { u32 sub_0806F564(Entity* ent, u32 b, u32 c) { u32 tmp = CalculateDirectionTo(ent->x.HALF.HI, ent->y.HALF.HI, b, c); - return ent->animationState == sub_0806F5A4(tmp); + return ent->animationState == GetAnimationStateForDirection4(tmp); } u32 sub_0806F58C(Entity* a, Entity* b) { return a->animationState >> 1 == sub_0806FCA0(a, b); } -u32 sub_0806F5A4(u32 idx) { - return gUnk_08114F38[idx]; +u32 GetAnimationStateForDirection4(u32 direction) { + return gMapDirectionToAnimationState4[direction]; } -u32 sub_0806F5B0(u32 idx) { - return gUnk_08114F58[idx]; +u32 GetAnimationStateForDirection8(u32 idx) { + return gMapDirectionToAnimationState8[idx]; } void LinearMoveDirection(Entity* ent, u32 a, u32 b) { @@ -434,11 +434,11 @@ bool32 sub_0806FC80(Entity* ent, Entity* ent2, s32 param_3) { } u32 sub_0806FCA0(Entity* this, Entity* other) { - return sub_0806F5A4(GetFacingDirection(this, other)); + return GetAnimationStateForDirection4(GetFacingDirection(this, other)); } u32 sub_0806FCAC(Entity* this, Entity* other) { - return sub_0806F5B0(GetFacingDirection(this, other)); + return GetAnimationStateForDirection8(GetFacingDirection(this, other)); } bool32 EntityWithinDistance(Entity* ent, s32 x, s32 y, s32 distance) { @@ -679,11 +679,11 @@ u8* GetSpriteSubEntryOffsetDataPointer(u32 param_1, u32 param_2) { return (u8*)val; } -const u8 gUnk_08114F38[] = { +const u8 gMapDirectionToAnimationState4[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, }; -const u8 gUnk_08114F58[] = { +const u8 gMapDirectionToAnimationState8[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 0, 0, }; diff --git a/src/script.c b/src/script.c index d5101f4ad..2a1165679 100644 --- a/src/script.c +++ b/src/script.c @@ -97,7 +97,7 @@ void ScriptCommand_0807E974(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_AddInteractableWhenBigObject(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_RemoveInteractableObject(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_AddInteractableWhenBigFuser(Entity* entity, ScriptExecutionContext* context); -void ScriptCommand_0807E9F0(Entity* entity, ScriptExecutionContext* context); +void ScriptCommand_UpdateFusion(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_0807EA4C(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_AddInteractableFuser(Entity* entity, ScriptExecutionContext* context); void ScriptCommand_WaitUntilTextboxCloses(Entity* entity, ScriptExecutionContext* context); @@ -313,9 +313,10 @@ void HandlePostScriptActions(Entity* entity, ScriptExecutionContext* context) { } } -void sub_0807DD50(Entity* entity) { +// Init some script related variables, execute the script and do something regarding the animation. +void InitScriptForNPC(Entity* entity) { sub_0807DD64(entity); - sub_0807DD94(entity, 0); + ExecuteScriptAndHandleAnimation(entity, NULL); } void sub_0807DD64(Entity* entity) { @@ -330,8 +331,8 @@ void sub_0807DD80(Entity* entity, Script* script) { sub_0807DD64(entity); } -void sub_0807DD94(Entity* entity, void (*function)(Entity*, ScriptExecutionContext*)) { - ExecuteScriptForEntity(entity, function); +void ExecuteScriptAndHandleAnimation(Entity* entity, void (*postScriptCallback)(Entity*, ScriptExecutionContext*)) { + ExecuteScriptForEntity(entity, postScriptCallback); HandleEntity0x82Actions(entity); sub_0807DE80(entity); } @@ -390,6 +391,7 @@ void HandleEntity0x82Actions(Entity* entity) { } } +// Handles animation for NPCs? Uses u16 0x80 and 0x82 of the entity. void sub_0807DE80(Entity* entity) { u32 local1; u16 local2; @@ -546,7 +548,7 @@ void ExecuteScript(Entity* entity, ScriptExecutionContext* context) { ScriptCommand_AddInteractableWhenBigObject, ScriptCommand_RemoveInteractableObject, ScriptCommand_AddInteractableWhenBigFuser, - ScriptCommand_0807E9F0, + ScriptCommand_UpdateFusion, ScriptCommand_0807EA4C, ScriptCommand_AddInteractableFuser, ScriptCommand_WaitUntilTextboxCloses, @@ -801,13 +803,13 @@ void ScriptCommand_CheckEntityInteractType(Entity* entity, ScriptExecutionContex void ScriptCommand_FacePlayerAndCheckDist(Entity* entity, ScriptExecutionContext* context) { if ((context->unk_1A & 0xF) == 0 && (gPlayerState.flags & PL_MINISH) == 0 && EntityInRectRadius(entity, &gPlayerEntity, 40, 40)) { - entity->animationState = sub_0806F5B0(GetFacingDirection(entity, &gPlayerEntity)); + entity->animationState = GetAnimationStateForDirection8(GetFacingDirection(entity, &gPlayerEntity)); } context->unk_1A++; if (entity->interactType) { entity->interactType = 0; context->condition = 1; - entity->animationState = sub_0806F5B0(GetFacingDirection(entity, &gPlayerEntity)); + entity->animationState = GetAnimationStateForDirection8(GetFacingDirection(entity, &gPlayerEntity)); } else { context->condition = 0; } @@ -1148,25 +1150,25 @@ void ScriptCommand_AddInteractableWhenBigFuser(Entity* entity, ScriptExecutionCo AddInteractableWhenBigFuser(entity, context->scriptInstructionPointer[1]); } -void ScriptCommand_0807E9F0(Entity* entity, ScriptExecutionContext* context) { - bool32 tmp; - sub_0801E00C(); - tmp = TRUE; - switch (gFuseInfo._0) { +void ScriptCommand_UpdateFusion(Entity* entity, ScriptExecutionContext* context) { + bool32 isFusionSuccessful; + PerformFuseAction(); + isFusionSuccessful = TRUE; + switch (gFuseInfo.fusionState) { default: - tmp = FALSE; + isFusionSuccessful = FALSE; break; - case 2: + case FUSION_STATE_2: gPlayerState.controlMode = CONTROL_DISABLED; - gPauseMenuOptions.disabled = tmp; - context->condition = tmp; + gPauseMenuOptions.disabled = isFusionSuccessful; + context->condition = isFusionSuccessful; break; - case 1: + case FUSION_STATE_1: context->condition = 0; break; } - if (tmp) { + if (isFusionSuccessful) { PlayerResetStateFromFusion(); gPlayerState.controlMode = CONTROL_1; } else { @@ -1176,7 +1178,7 @@ void ScriptCommand_0807E9F0(Entity* entity, ScriptExecutionContext* context) { void ScriptCommand_0807EA4C(Entity* entity, ScriptExecutionContext* context) { if (entity->interactType == 2) { - sub_0801DFB4(entity, 0, 0, 0); + InitializeFuseInfo(entity, 0, 0, 0); entity->interactType = 0; gActiveScriptInfo.flags |= 1; } else { @@ -1234,17 +1236,17 @@ void ScriptCommand_SetAnimationState(Entity* entity, ScriptExecutionContext* con } void ScriptCommand_0807EB4C(Entity* entity, ScriptExecutionContext* context) { - entity->animationState = - sub_0806F5B0(sub_080045B4(entity, context->scriptInstructionPointer[1] + gRoomControls.origin_x, - context->scriptInstructionPointer[2] + gRoomControls.origin_y)); + entity->animationState = GetAnimationStateForDirection8( + sub_080045B4(entity, context->scriptInstructionPointer[1] + gRoomControls.origin_x, + context->scriptInstructionPointer[2] + gRoomControls.origin_y)); } void ScriptCommand_FacePlayer(Entity* entity, ScriptExecutionContext* context) { - entity->animationState = sub_0806F5B0(GetFacingDirection(entity, &gPlayerEntity)); + entity->animationState = GetAnimationStateForDirection8(GetFacingDirection(entity, &gPlayerEntity)); } void ScriptCommand_FaceAwayFromPlayer(Entity* entity, ScriptExecutionContext* context) { - gPlayerEntity.animationState = sub_0806F5B0(GetFacingDirection(&gPlayerEntity, entity)) & ~1; + gPlayerEntity.animationState = GetAnimationStateForDirection8(GetFacingDirection(&gPlayerEntity, entity)) & ~1; } void ScriptCommand_SetEntityDirection(Entity* entity, ScriptExecutionContext* context) { @@ -1352,9 +1354,9 @@ void ScriptCommand_0807ED24(Entity* entity, ScriptExecutionContext* context) { tmp = context->scriptInstructionPointer[2]; tmp3 = entity->y.HALF.HI - gRoomControls.origin_y; context->y.WORD = ((tmp - tmp3) << 0x10) / context->unk_12; - entity->animationState = - sub_0806F5B0(sub_080045B4(entity, context->scriptInstructionPointer[1] + gRoomControls.origin_x, - context->scriptInstructionPointer[2] + gRoomControls.origin_y)); + entity->animationState = GetAnimationStateForDirection8( + sub_080045B4(entity, context->scriptInstructionPointer[1] + gRoomControls.origin_x, + context->scriptInstructionPointer[2] + gRoomControls.origin_y)); context->postScriptActions |= 2; } else { if (!--context->unk_12) { @@ -1817,14 +1819,14 @@ void WaitForCameraTouchRoomBorder(Entity* entity, ScriptExecutionContext* contex } void sub_0807F634(Entity* entity, ScriptExecutionContext* context) { - u16* p = (u16*)context->intVariable; - sub_0801DFB4(entity, p[0], p[1], p[2]); + u16* textIndices = (u16*)context->intVariable; + InitializeFuseInfo(entity, textIndices[0], textIndices[1], textIndices[2]); gPlayerState.controlMode = CONTROL_DISABLED; } void sub_0807F650(Entity* entity, ScriptExecutionContext* context) { - u32 p = GetFuserId(entity); - sub_0801DFB4(entity, gUnk_08001A7C[p][0], gUnk_08001A7C[p][1], gUnk_08001A7C[p][2]); + u32 fuserId = GetFuserId(entity); + InitializeFuseInfo(entity, gUnk_08001A7C[fuserId][0], gUnk_08001A7C[fuserId][1], gUnk_08001A7C[fuserId][2]); gPlayerState.controlMode = CONTROL_DISABLED; }