From ad44d63b73b52fa49f1698526e1d77b414a1991d Mon Sep 17 00:00:00 2001 From: octorock <79596758+octorock@users.noreply.github.com> Date: Tue, 9 Aug 2022 18:48:05 +0200 Subject: [PATCH] Document some player item stuff --- asm/lib/libagbsyscall.s | 4 +- .../itemTryPickupObject/sub_080762D8.inc | 4 +- asm/non_matching/playerUtils/sub_080792D8.inc | 2 +- asm/non_matching/playerUtils/sub_080797EC.inc | 2 +- asm/src/code_08003FC4.s | 4 +- asm/src/intr.s | 4 +- assets/assets.json | 4 +- assets/sounds.json | 2 +- data/data_0811BE38.s | 28 +- data/item.s | 11 + .../hyruleCastleGarden/script_GuardEntry3.inc | 3 +- data/scripts/hyruleTown/script_GuardWest.inc | 8 +- data/scripts/npc/script_BladeBrothers.inc | 6 +- data/sound/sounds.s | 2 +- include/collision.h | 7 + include/enemy/octorokBoss.h | 6 +- include/entity.h | 12 +- include/game.h | 2 +- include/item.h | 17 +- include/object.h | 2 +- include/player.h | 103 ++-- include/playeritem.h | 24 +- include/room.h | 8 +- include/script.h | 3 +- include/sound.h | 2 +- include/structures.h | 52 +- linker.ld | 7 +- src/beanstalkSubtask.c | 80 +-- src/collision.c | 297 +++++---- src/color.c | 4 +- src/enemy/armos.c | 8 +- src/enemy/beetle.c | 2 +- src/enemy/chuchuBoss.c | 2 +- src/enemy/dust.c | 2 +- src/enemy/enemy64.c | 6 +- src/enemy/ghini.c | 2 +- src/enemy/gibdo.c | 2 +- src/enemy/gleerok.c | 2 +- src/enemy/gyorgMaleEye.c | 2 +- src/enemy/likeLike.c | 2 +- src/enemy/mazaalBracelet.c | 4 +- src/enemy/miniFireballGuy.c | 2 +- src/enemy/miniSlime.c | 2 +- src/enemy/mulldozer.c | 2 +- src/enemy/octorokBoss.c | 2 +- src/enemy/pesto.c | 2 +- src/enemy/rupeeLike.c | 2 +- src/enemy/vaatiProjectile.c | 2 +- src/enemy/wizzrobeFire.c | 2 +- src/enemy/wizzrobeIce.c | 2 +- src/enemy/wizzrobeWind.c | 4 +- src/game.c | 99 +-- src/gba/m4a.c | 2 +- src/interrupts.c | 26 +- src/item.c | 42 +- src/item/itemBomb.c | 67 +- src/item/itemBoomerang.c | 26 +- src/item/itemBow.c | 57 +- src/item/itemDebug.c | 10 +- src/item/itemGustJar.c | 74 +-- src/item/itemJarEmpty.c | 32 +- src/item/itemLantern.c | 63 +- src/item/itemMoleMitts.c | 34 +- src/item/itemOcarina.c | 23 +- src/item/itemPacciCane.c | 26 +- src/item/itemPegasusBoots.c | 60 +- src/item/itemRocsCape.c | 38 +- src/item/itemShield.c | 46 +- src/item/itemSword.c | 167 ++--- src/item/itemTryPickupObject.c | 123 +++- src/itemDefinitions.c | 43 ++ src/itemMetaData.c | 2 +- src/manager/minishPortalManager.c | 2 +- src/manager/miscManager.c | 2 +- src/menu/pause_menu.c | 6 +- src/npc.c | 3 +- src/npc/bigGoron.c | 8 +- src/npc/bladeBrothers.c | 17 +- src/npc/castleMaid.c | 4 +- src/npc/drLeft.c | 4 +- src/npc/epona.c | 2 +- src/npc/forestMinish.c | 2 +- src/npc/guardWithSpear.c | 14 +- src/npc/mama.c | 2 +- src/npc/npc4E.c | 4 +- src/npc/npc58.c | 2 +- src/npc/pina.c | 4 +- src/npc/townMinish.c | 2 +- src/object.c | 2 +- src/object/barrelSpiderweb.c | 2 +- src/object/bigIceBlock.c | 2 +- src/object/bird.c | 2 +- src/object/book.c | 2 +- src/object/crenelBeanSprout.c | 8 +- src/object/fileScreenObjects.c | 4 +- src/object/frozenOctorok.c | 2 +- src/object/houseDoorExterior.c | 2 +- src/object/houseDoorInterior.c | 2 +- src/object/itemForSale.c | 6 +- src/object/lampParticle.c | 2 +- src/object/lilypadLarge.c | 2 +- src/object/macroPlayer.c | 5 +- src/object/minecart.c | 8 +- src/object/minishSizedEntrance.c | 2 +- src/object/octorokBossObject.c | 4 +- src/object/playerClone.c | 2 +- src/object/pot.c | 2 +- src/object/pullableMushroom.c | 6 +- src/object/pushableRock.c | 2 +- src/object/smallIceBlock.c | 2 +- src/object/smokeParticle.c | 2 +- src/object/swordParticle.c | 4 +- src/object/thunderbold.c | 2 +- src/object/unusedSkull.c | 2 +- src/objectDefinitions.c | 176 +++--- src/objectUtils.c | 4 +- src/physics.c | 6 +- src/player.c | 193 +++--- src/playerItem.c | 51 +- src/playerItem/playerItemBomb.c | 10 +- src/playerItem/playerItemBoomerang.c | 30 +- src/playerItem/playerItemBow.c | 6 +- src/playerItem/playerItemFireRodProjectile.c | 2 +- src/playerItem/playerItemGust.c | 2 +- src/playerItem/playerItemHeldObject.c | 6 +- src/playerItem/playerItemLantern.c | 2 +- src/playerItem/playerItemShield.c | 16 +- src/playerItem/playerItemSword.c | 10 +- src/playerItem/playerItemSwordBeam.c | 4 +- src/playerItemUtils.c | 4 +- src/playerUtils.c | 583 +++++++++--------- src/projectile/v1DarkMagicProjectile.c | 4 +- src/scroll.c | 2 +- src/sound.c | 4 +- 134 files changed, 1616 insertions(+), 1484 deletions(-) create mode 100644 data/item.s create mode 100644 src/itemDefinitions.c diff --git a/asm/lib/libagbsyscall.s b/asm/lib/libagbsyscall.s index f505a206..5754dd9a 100644 --- a/asm/lib/libagbsyscall.s +++ b/asm/lib/libagbsyscall.s @@ -78,7 +78,7 @@ SoftReset: @ 0x080B1504 ldr r3, _080B1518 @ =0x04000208 movs r2, #0 strb r2, [r3] - ldr r3, _080B151C @ =gUnk_03007FFA + ldr r3, _080B151C @ =soft_reset_flag movs r2, #0 strb r2, [r3] subs r3, #0xfa @@ -87,4 +87,4 @@ SoftReset: @ 0x080B1504 svc #0 .align 2, 0 _080B1518: .4byte 0x04000208 -_080B151C: .4byte gUnk_03007FFA +_080B151C: .4byte soft_reset_flag diff --git a/asm/non_matching/itemTryPickupObject/sub_080762D8.inc b/asm/non_matching/itemTryPickupObject/sub_080762D8.inc index 51d0ea00..09315195 100644 --- a/asm/non_matching/itemTryPickupObject/sub_080762D8.inc +++ b/asm/non_matching/itemTryPickupObject/sub_080762D8.inc @@ -122,7 +122,7 @@ _080763C8: cmp r1, r0 beq _080763D4 adds r0, r5, #0 - bl sub_08077DF4 + bl SetItemAnim _080763D4: ldrb r0, [r4, #5] movs r1, #0x10 @@ -208,7 +208,7 @@ _08076472: lsls r1, r1, #4 _08076476: adds r0, r5, #0 - bl sub_08077DF4 + bl SetItemAnim b _08076486 _0807647E: adds r0, r5, #0 diff --git a/asm/non_matching/playerUtils/sub_080792D8.inc b/asm/non_matching/playerUtils/sub_080792D8.inc index 18b746ba..e14695a1 100644 --- a/asm/non_matching/playerUtils/sub_080792D8.inc +++ b/asm/non_matching/playerUtils/sub_080792D8.inc @@ -109,7 +109,7 @@ _08079374: ldrb r0, [r4, #2] cmp r0, #0 bne _080793CA - bl ResetPlayerItem + bl ResetActiveItems ldr r0, [r4, #0x30] movs r1, #8 ands r0, r1 diff --git a/asm/non_matching/playerUtils/sub_080797EC.inc b/asm/non_matching/playerUtils/sub_080797EC.inc index d3beb3c8..6dd3af5e 100644 --- a/asm/non_matching/playerUtils/sub_080797EC.inc +++ b/asm/non_matching/playerUtils/sub_080797EC.inc @@ -127,7 +127,7 @@ _080798CE: bl sub_080793E4 cmp r0, #0 beq _0807991E - bl sub_0807A500 + bl GetPlayerTilePos ldr r1, _080798F8 @ =gPlayerEntity adds r1, #0x38 ldrb r1, [r1] diff --git a/asm/src/code_08003FC4.s b/asm/src/code_08003FC4.s index ee3bd1d7..25bfc6ec 100644 --- a/asm/src/code_08003FC4.s +++ b/asm/src/code_08003FC4.s @@ -537,7 +537,7 @@ sub_080042D0: @ 0x080042D0 ldrb r3, [r0, r3] movs r4, #0xc muls r3, r4, r3 - ldr r4, _080043A4 @ =gUnk_02024494 + ldr r4, _080043A4 @ =gGFXSlots+4 adds r4, r4, r3 ldrb r3, [r4] movs r5, #0xf @@ -619,7 +619,7 @@ _08004394: .4byte gUnk_08000228 _08004398: .4byte 0x00004000 _0800439C: .4byte gSpritePtrs _080043A0: .4byte gSpritePtrs -_080043A4: .4byte gUnk_02024494 +_080043A4: .4byte gGFXSlots+4 thumb_func_start sub_080043A8 sub_080043A8: @ 0x080043A8 diff --git a/asm/src/intr.s b/asm/src/intr.s index 04681cd1..4d59c9d7 100644 --- a/asm/src/intr.s +++ b/asm/src/intr.s @@ -437,7 +437,7 @@ _080B1E74: ldrb r0, [r3] cmp r0, #0xff ldrheq r1, [r3, #2] - ldr r0, _080B2018 @ =gUnk_080B3744 + ldr r0, _080B2018 @ =gCollisionHandlers ldr r7, [r0, r1, lsl #2] mov r0, r4 mov r1, r5 @@ -548,7 +548,7 @@ _080B2008: .4byte ram_sub_080B1FE4 _080B200C: .4byte gCollidableList _080B2010: .4byte gCollidableCount _080B2014: .4byte gCollisionMtx -_080B2018: .4byte gUnk_080B3744 +_080B2018: .4byte gCollisionHandlers arm_func_start IntrMain IntrMain: diff --git a/assets/assets.json b/assets/assets.json index b73136b4..0dde9765 100644 --- a/assets/assets.json +++ b/assets/assets.json @@ -40117,7 +40117,7 @@ "size": 8 }, { - "path": "data_0811BE38/gUnk_0811BE48_EU.bin", + "path": "data_0811BE38/gItemDefinitions_EU.bin", "variants": [ "EU" ], @@ -40127,7 +40127,7 @@ "size": 384 }, { - "path": "data_0811BE38/gUnk_0811BE48_1_USA-JP-DEMO_USA-DEMO_JP.bin", + "path": "data_0811BE38/gItemDefinitions_1_USA-JP-DEMO_USA-DEMO_JP.bin", "variants": [ "USA", "JP", diff --git a/assets/sounds.json b/assets/sounds.json index af97a90f..49423f07 100644 --- a/assets/sounds.json +++ b/assets/sounds.json @@ -3818,7 +3818,7 @@ "size": 36 }, { - "path": "sounds/sfx163.bin", + "path": "sounds/sfxToggleDiving.bin", "start": 14564384, "type": "midi", "options": { diff --git a/data/data_0811BE38.s b/data/data_0811BE38.s index 175dc403..726c4935 100644 --- a/data/data_0811BE38.s +++ b/data/data_0811BE38.s @@ -4,27 +4,13 @@ .section .rodata .align 2 -gUnk_0811BE38:: @ 0811BE38 - .incbin "data_0811BE38/gUnk_0811BE38.bin" - -gUnk_0811BE40:: @ 0811BE40 - .incbin "data_0811BE38/gUnk_0811BE40.bin" - -gUnk_0811BE48:: @ 0811BE48 -.ifdef EU - @ TODO only small differences - .incbin "data_0811BE38/gUnk_0811BE48_EU.bin" -.else - .incbin "data_0811BE38/gUnk_0811BE48_1_USA-JP-DEMO_USA-DEMO_JP.bin" -.endif - -gUnk_0811BFC8:: @ 0811BFC8 - .4byte sub_080779E8 - .4byte sub_080779EC - .4byte sub_08077A18 - .4byte sub_08077A48 - .4byte sub_08077A98 - .4byte sub_08077AC8 +gCreateItemsFuncs:: @ 0811BFC8 + .4byte CreateItemNone + .4byte CreateItem1 + .4byte CreateItem2 + .4byte CreateItem3 + .4byte CreateItem4 + .4byte CreateItem5 gUnk_0811BFE0:: @ 0811BFE0 .incbin "data_0811BE38/gUnk_0811BFE0.bin" diff --git a/data/item.s b/data/item.s new file mode 100644 index 00000000..f52c59d6 --- /dev/null +++ b/data/item.s @@ -0,0 +1,11 @@ + .include "asm/macros.inc" + .include "constants/constants.inc" + + .section .rodata + .align 2 + +gUnk_0811BE38:: @ 0811BE38 + .incbin "data_0811BE38/gUnk_0811BE38.bin" + +gUnk_0811BE40:: @ 0811BE40 + .incbin "data_0811BE38/gUnk_0811BE40.bin" diff --git a/data/scripts/hyruleCastleGarden/script_GuardEntry3.inc b/data/scripts/hyruleCastleGarden/script_GuardEntry3.inc index 36916c9c..663e740c 100644 --- a/data/scripts/hyruleCastleGarden/script_GuardEntry3.inc +++ b/data/scripts/hyruleCastleGarden/script_GuardEntry3.inc @@ -12,7 +12,8 @@ script_08011A7C: SetPlayerIdle FacePlayer CallWithArg sub_0807F3D8, 0x00000000 - CallWithArg sub_080644B4, 0x00000006 + @ Check if player has performed great spin. + CallWithArg CheckLastSwordMove, 0x00000006 JumpIf script_08011AFA MessageFromTarget TEXT_VAATI, 0x20 WaitUntilTextboxCloses diff --git a/data/scripts/hyruleTown/script_GuardWest.inc b/data/scripts/hyruleTown/script_GuardWest.inc index ced896a7..26ad9095 100644 --- a/data/scripts/hyruleTown/script_GuardWest.inc +++ b/data/scripts/hyruleTown/script_GuardWest.inc @@ -4,7 +4,7 @@ SCRIPT_START script_GuardWest SetAnimationState 0x0002 _0807E9D4 CallWithArg sub_0807F3D8, 0x00000008 - Call sub_080644A4 + Call GuardWithSpear_ResetLastSwordMove .ifndef EU ClearLocalFlag MACHI_02_HEISHI_TALK .endif @@ -19,10 +19,10 @@ script_0800FF92: Call sub_08064198 CheckLocalFlag MACHI_02_HEISHI_TALK JumpIfNot script_0800FFCC - Call sub_08064488 + Call GuardWithSpear_ResetLastSwordMoveIfNotInSwordState CheckPlayerInRegion2 0x4040 JumpIfNot script_0800FFCC - Call sub_08064470 + Call GuardWithSpear_CheckSwordMoveSpin JumpIf script_08010014 script_0800FFCC: CheckEntityInteractType @@ -65,7 +65,7 @@ script_08010014: CallWithArg sub_0807F3D8, 0x00000008 SetLocalFlag MACHI_02_HEISHI script_08010060: - Call sub_080644A4 + Call GuardWithSpear_ResetLastSwordMove CallWithArg sub_0807F5B0, 0x0000000a EnablePlayerControl Jump script_0800FF92 diff --git a/data/scripts/npc/script_BladeBrothers.inc b/data/scripts/npc/script_BladeBrothers.inc index 1a0c3f0b..6f888cb4 100644 --- a/data/scripts/npc/script_BladeBrothers.inc +++ b/data/scripts/npc/script_BladeBrothers.inc @@ -37,7 +37,7 @@ script_08016262: WaitUntilTextboxCloses DoPostScriptAction 0x0001 Call WaitForAnimDone - Call sub_08068E90 + Call BladeBrothers_LearnSkill Call sub_08068C8C JumpIf script_0801631C Call sub_08068F00 @@ -50,13 +50,13 @@ script_08016262: Wait 0x001e Call sub_08068E18 WaitUntilTextboxCloses - Call sub_08068EB4 + Call BladeBrothers_ResetLastSwordMove Call EnablePauseMenu EnablePlayerControl script_080162CC: EndBlock BeginBlock - Call sub_08068EC4 + Call BladeBrothers_CheckLastSwordMove JumpIf script_080162F6 CheckEntityInteractType JumpIf script_080162E4 diff --git a/data/sound/sounds.s b/data/sound/sounds.s index 840cb9fe..a1913004 100644 --- a/data/sound/sounds.s +++ b/data/sound/sounds.s @@ -319,7 +319,7 @@ .include "sounds/sfx160.s" .include "sounds/sfx161.s" .include "sounds/sfx162.s" - .include "sounds/sfx163.s" + .include "sounds/sfxToggleDiving.s" .include "sounds/sfx164.s" .include "sounds/sfx165.s" .include "sounds/sfx166.s" diff --git a/include/collision.h b/include/collision.h index bc7a632b..eb5ec380 100644 --- a/include/collision.h +++ b/include/collision.h @@ -5,6 +5,7 @@ #include "entity.h" /** Collisions. */ + typedef enum { COL_NONE = 0x0, COL_NORTH_WEST = 0x2, @@ -25,6 +26,12 @@ typedef enum { COL_EAST_ANY = 0xe000, } Collisions; +typedef enum { + RESULT_NO_COLLISION = 0, + RESULT_COLLISION = 1, + RESULT_COLLISION_WITHOUT_SET = 2, +} CollisionResult; + bool32 IsTileCollision(const u8*, s32, s32, u32); bool32 IsColliding(Entity*, Entity*); bool32 IsCollidingPlayer(Entity*); diff --git a/include/enemy/octorokBoss.h b/include/enemy/octorokBoss.h index d977c0c2..d57c8665 100644 --- a/include/enemy/octorokBoss.h +++ b/include/enemy/octorokBoss.h @@ -1,5 +1,5 @@ -#ifndef ENEMY_OCTOROK_BOSS_H -#define ENEMY_OCTOROK_BOSS_H +#ifndef OCTOROKBOSS_H +#define OCTOROKBOSS_H #include "enemy.h" @@ -74,4 +74,4 @@ enum OctorokBossAction1SubAction { ACTION1_ATTACK, // Attack }; -#endif \ No newline at end of file +#endif // OCTOROKBOSS_H diff --git a/include/entity.h b/include/entity.h index c20af84a..e9966de0 100644 --- a/include/entity.h +++ b/include/entity.h @@ -249,12 +249,12 @@ typedef void (*const* EntityActionArray)(Entity*); */ void DrawEntity(Entity* entity); -void InitializeAnimation(Entity*, u32); -void InitAnimationForceUpdate(Entity*, u32); -void UpdateAnimationSingleFrame(Entity*); -void UpdateSpriteForCollisionLayer(Entity*); -void GetNextFrame(Entity*); -u32 LoadExtraSpriteData(Entity*, const SpriteLoadData*); +void InitializeAnimation(Entity* entity, u32 animIndex); +void InitAnimationForceUpdate(Entity* entity, u32 animIndex); +void UpdateAnimationSingleFrame(Entity* entity); +void UpdateSpriteForCollisionLayer(Entity* entity); +void GetNextFrame(Entity* entity); +u32 LoadExtraSpriteData(Entity* entity, const SpriteLoadData* spriteData); void SetExtraSpriteFrame(Entity*, u32, u32); void SetSpriteSubEntryOffsetData1(Entity*, u32, u32); void SetSpriteSubEntryOffsetData2(Entity*, u32, u32); diff --git a/include/game.h b/include/game.h index 46a82750..e3d9922e 100644 --- a/include/game.h +++ b/include/game.h @@ -149,7 +149,7 @@ void PutItemOnSlot(u32 item); * @param item The item to equip. * @param slot The slot to equip the item in. */ -void ForceEquipItem(u32 item, u32 slot); +void ForceEquipItem(u32 item, /*EquipSlot*/ u32 slot); /** * Get item price. diff --git a/include/item.h b/include/item.h index e8e3917c..97fa95a8 100644 --- a/include/item.h +++ b/include/item.h @@ -7,6 +7,7 @@ void CreateItemEntity(u32, u32, u32); void sub_08081404(Entity*, u32); +extern void ExecuteItemFunction(ItemBehavior* this, u32 index); extern void ItemDebug(ItemBehavior*, u32); extern void ItemSword(ItemBehavior*, u32); @@ -52,11 +53,12 @@ typedef enum { ITEM_ORB_GREEN, ITEM_ORB_BLUE, ITEM_ORB_RED, - ITEM_TRAP, + ITEM_TRY_PICKUP_OBJECT, ITEM_BOTTLE1, ITEM_BOTTLE2, ITEM_BOTTLE3, ITEM_BOTTLE4, + // End of activatable items. ITEM_BOTTLE_EMPTY, ITEM_BOTTLE_BUTTER, ITEM_BOTTLE_MILK, @@ -151,4 +153,17 @@ typedef enum { ITEM_ENEMY_BEETLE } Item; +/** Slot that the item is equipped in. */ +typedef enum { EQUIP_SLOT_A, EQUIP_SLOT_B, EQUIP_SLOT_NONE } EquipSlot; + +/** Function used to create the item. */ +typedef enum { + CREATE_ITEM_0, + CREATE_ITEM_1, + CREATE_ITEM_2, + CREATE_ITEM_3, + CREATE_ITEM_4, + CREATE_ITEM_5, +} CreateItemFunc; + #endif // ITEM_H diff --git a/include/object.h b/include/object.h index e7a20267..4d312d43 100644 --- a/include/object.h +++ b/include/object.h @@ -227,7 +227,7 @@ typedef enum { PINWHEEL, OBJECT_BF, ENEMY_ITEM, - OBJECT_C1, + LINK_ANIMATION, } Object; void ItemOnGround(); diff --git a/include/player.h b/include/player.h index 6e6229f7..59054cd1 100644 --- a/include/player.h +++ b/include/player.h @@ -12,7 +12,7 @@ enum PlayerActions { PLAYER_JUMP, PLAYER_PUSH, PLAYER_BOUNCE, - PLAYER_08070E9C, + PLAYER_08070E9C, // sub_080782C0, only when PLAYER_INPUT_1000 is newInput PLAYER_ITEMGET, PLAYER_MINISH, PLAYER_MINISHDIE, @@ -236,35 +236,50 @@ typedef struct { typedef enum { PLAYER_INPUT_1 = 0x1, // A PLAYER_INPUT_2 = 0x2, // B - PLAYER_INPUT_8 = 0x8, // A sub_080782C0, sub_0807953C, sub_0807AE20, sub_08076518. ItemForSale_Action2 - PLAYER_INPUT_10 = 0x10, // B sub_0807953C, sub_0807ADB8, sub_08076518, ItemForSale_Action2 + PLAYER_INPUT_8 = 0x8, // A sub_080782C0, sub_0807953C, PlayerUpdateSwimming, sub_08076518. ItemForSale_Action2 + PLAYER_INPUT_10 = 0x10, // B sub_0807953C, ToggleDiving, sub_08076518, ItemForSale_Action2 PLAYER_INPUT_20 = 0x20, // R sub_0807953C PLAYER_INPUT_40 = 0x40, // A CrenelBeanSprout_Action1 - PLAYER_INPUT_80 = 0x80, // R sub_08073584, sub_080777A0, sub_080782C0, CrenelBeanSprout_Action1, ItemForSale_Action2 + PLAYER_INPUT_80 = + 0x80, // R sub_08073584, IsPreventedFromUsingItem, sub_080782C0, CrenelBeanSprout_Action1, ItemForSale_Action2 PLAYER_INPUT_RIGHT = 0x100, PLAYER_INPUT_LEFT = 0x200, PLAYER_INPUT_UP = 0x400, PLAYER_INPUT_DOWN = 0x800, PLAYER_INPUT_ANY_DIRECTION = 0xf00, - PLAYER_INPUT_1000 = 0x1000, // where is it set? sub_080782C0 - PLAYER_INPUT_8000 = 0x8000, // R, sub_080778CC, sub_08076518 + PLAYER_INPUT_1000 = 0x1000, // L, where is it set? sub_080782C0 + PLAYER_INPUT_8000 = 0x8000, // R, IsTryingToPickupObject, sub_08076518 // TODO What is the result of u32 result = (s32) - (keys & 0x200) >> 0x1f & 0x1000;? } PlayerInputState; typedef struct { - /*0x90*/ u16 field_0x90; - /*0x92*/ u16 field_0x92; + /*0x90*/ u16 heldInput; /**< Input currently held @see PlayerInputState */ + /*0x92*/ u16 newInput; /**< New input this frame @see PlayerInputState */ /*0x94*/ u32 field_0x94; /*0x98*/ u16 playerMacroWaiting; /*0x9a*/ u16 playerMacroHeldKeys; /*0x9c*/ PlayerMacroEntry* playerMacro; } PlayerInput; +typedef enum { + SWORD_MOVE_NONE, + SWORD_MOVE_SPIN, + SWORD_MOVE_ROLL, + SWORD_MOVE_DASH, + SWORD_MOVE_BREAK_POT, + SWORD_MOVE_FULL_BEAM, + SWORD_MOVE_GREAT_SPIN, + SWORD_MOVE_DOWN_THRUST, + SWORD_MOVE_LOW_BEAM, +} SwordMove; + typedef struct { - /*0x00*/ u8 field_0x0[2]; + /*0x00*/ u8 prevAnim; + /*0x00*/ u8 grab_status; /*0x02*/ u8 jump_status; - /*0x03*/ u8 field_0x3[2]; + /*0x03*/ u8 shield_status; + /*0x04*/ u8 attack_status; /*0x05*/ u8 heldObject; /*0x06*/ u8 pushedObject; // hi bit is special, rest is used as a timer /*0x07*/ u8 field_0x7; @@ -272,8 +287,8 @@ typedef struct { /*0x0a*/ u8 field_0xa; /*0x0b*/ u8 keepFacing; /*0x0c*/ u8 queued_action; - /*0x0d*/ u8 field_0xd; - /*0x0e*/ u8 field_0xe; + /*0x0d*/ u8 direction; + /*0x0e*/ u8 itemAnimPriority; /*0x0f*/ u8 hurtBlinkSpeed; /*0x10*/ u8 field_0x10; /*0x11*/ u8 surfacePositionSameTimer; @@ -291,7 +306,7 @@ typedef struct { /*0x1f*/ u8 field_0x1f[3]; /*0x22*/ u16 tilePosition; /*0x24*/ u16 tileType; - /*0x26*/ u8 swim_state; + /*0x26*/ u8 swim_state; /**< Is the player swimming? 0x80 for diving */ /*0x27*/ u8 field_0x27[5]; /*0x2c*/ Entity* item; /*0x30*/ u32 flags; @@ -323,10 +338,10 @@ typedef struct { /*0xa0*/ ChargeState chargeState; /*0xa8*/ u8 framestate; /*0xa9*/ u8 framestate_last; - /*0xaa*/ u8 field_0xaa; - /*0xab*/ u8 field_0xab; - /*0xac*/ u16 skills; /**< Bitfield of skills @see PlayerSkill */ - /*0xae*/ u16 field_0xae; + /*0xaa*/ u8 attachedBeetleCount; /**< Count of the Beetles attached to the player. */ + /*0xab*/ u8 lastSwordMove; /**< The last move that has been performed with the sword. @see SwordMove */ + /*0xac*/ u16 skills; /**< Bitfield of skills @see PlayerSkill */ + /*0xae*/ u8 pad[2]; } PlayerState; typedef struct { @@ -359,23 +374,25 @@ typedef struct { typedef struct { /*0x0*/ u8 field_0x0; - /*0x1*/ u8 behaviorID; + /*0x1*/ u8 behaviorId; /*0x2*/ u8 field_0x2[2]; /*0x4*/ u8 stateID; /*0x5*/ u8 field_0x5; /*0x6*/ u8 field_0x6; /*0x7*/ u8 timer; /*0x8*/ u8 subtimer; - /*0x9*/ u8 field_0x9; + /*0x9*/ u8 priority; /*0xa*/ u8 playerAnimationState; /*0xb*/ u8 direction; - /*0xc*/ u8 playerAnimIndex; - /*0xd*/ u8 playerFrameDuration; - /*0xe*/ u8 playerFrame; - /*0xf*/ u8 field_0xf; - /*0x10*/ u16 field_0x10; - /*0xf*/ u8 playerFrameIndex; - /*0x12*/ u8 field_0x12[5]; + /*0xc*/ u8 playerAnimIndex; /**< Stored animIndex of the player entity. */ + /*0xd*/ u8 playerFrameDuration; /**< Stored frameDuration of the player entity. */ + /*0xe*/ u8 + playerFrame; /**< Stored frame of the player entity. But also used for general purpose in item behaviours? */ + /*0xf*/ u8 + animPriority; /**< In sub_08079064 the animIndex of the ItemBehavior with the max animPriority is selected. */ + /*0x10*/ u16 animIndex; + /*0x12*/ u8 playerFrameIndex; /**< Stored frameIndex of the player entity. */ + /*0x13*/ u8 field_0x13[5]; /*0x18*/ Entity* field_0x18; } ItemBehavior; @@ -392,7 +409,7 @@ extern Entity gPlayerEntity; void DoPlayerAction(Entity*); bool32 CheckInitPauseMenu(void); void SetPlayerControl(PlayerControlMode mode); -void ResetPlayerItem(void); +void ResetActiveItems(void); void ResetPlayerVelocity(void); void ResetPlayerAnimationAndAction(void); void SetPlayerActionNormal(void); @@ -407,7 +424,7 @@ void CreateEzloHint(u32, u32); // game.c /** @see Item */ -u32 IsItemEquipped(u32); +/*EquipSlot*/ u32 IsItemEquipped(u32 itemId); /** @see Item */ u32 GetInventoryValue(u32); /** @see Item */ @@ -418,7 +435,7 @@ void ModBombs(s32 delta); // playerUtils.c void DeleteClones(void); -void sub_08077728(u32); +void CreateItemEquippedAtSlot(/*EquipSlot*/ u32 equipSlot); void PutAwayItems(void); void sub_08079E58(s32 speed, u32 direction); void RespawnPlayer(void); @@ -430,13 +447,13 @@ void PlayerMinishSetNormalAndCollide(void); u32 sub_08079B24(void); void sub_08079708(Entity*); void sub_08079744(Entity*); -void sub_0807AE20(Entity*); -u32 sub_0807A894(Entity*); +void PlayerUpdateSwimming(Entity*); +u32 GetCollisionTileInFront(Entity*); u32 sub_080797C4(void); void CheckPlayerVelocity(void); void sub_0807B068(Entity*); u32 sub_0807A2F8(u32); -void sub_08077698(/* PlayerEntity* */); +void UpdateActiveItems(/* PlayerEntity* */); bool32 sub_0807A2B8(void); u32 sub_08079550(void); u32 sub_080782C0(void); @@ -467,20 +484,20 @@ void RegisterCarryEntity(Entity*); void FreeCarryEntity(Entity*); void PlayerDropHeldObject(); void PlayerResetStateFromFusion(); -void DeletePlayerItem(ItemBehavior*, u32); +void DeleteItemBehavior(ItemBehavior*, u32); void sub_08077D38(ItemBehavior*, u32); -void sub_08077DF4(ItemBehavior*, u32); +void SetItemAnim(ItemBehavior* this, u32 animIndex); void sub_08077E3C(ItemBehavior*, u32); void sub_080751E8(u32, u32, void*); void sub_08077B98(ItemBehavior*); void sub_08077BB8(ItemBehavior*); -Entity* sub_08077C0C(ItemBehavior*, u32); -Entity* sub_08077C94(ItemBehavior*, u32); +Entity* CreatePlayerItemIfNotExists(ItemBehavior*, u32); +Entity* FindPlayerItemForItem(ItemBehavior*, u32); bool32 PlayerCanBeMoved(void); bool32 sub_08077EC8(ItemBehavior*); -bool32 sub_08077EFC(ItemBehavior*); -bool32 sub_08077F10(ItemBehavior*); -bool32 sub_08077F24(ItemBehavior*, u32); +bool32 IsItemActive(ItemBehavior*); +bool32 IsItemActivatedThisFrame(ItemBehavior*); +bool32 IsItemActiveByInput(ItemBehavior*, PlayerInputState); bool32 sub_08077FEC(u32); void sub_08078180(void); void sub_080784C8(); @@ -500,17 +517,19 @@ void sub_08079BD8(Entity*); u32 sub_08079D48(); void sub_08079D84(void); u32 sub_08079FC4(u32); -void sub_0807A050(void); +void UpdatePlayerPalette(void); void sub_0807A5B8(u32); void sub_0807A8D8(Entity*); void sub_0807AA80(Entity*); void sub_0807AABC(Entity*); -void sub_0807ACCC(Entity*); -u32 sub_0807B014(); +void PlayerSwimming(Entity*); +u32 GetSwordBeam(); void sub_0807B0C8(void); bool32 sub_0807BD14(Entity*, u32); Entity* CreatePlayerItemWithParent(ItemBehavior*, u32); bool32 HasSwordEquipped(); +u32 GetPlayerPalette(bool32 use); +void PlayerShrinkByRay(void); // player.s extern u32 PlayerCheckNEastTile(); diff --git a/include/playeritem.h b/include/playeritem.h index 8ca8d783..3736cb31 100644 --- a/include/playeritem.h +++ b/include/playeritem.h @@ -5,27 +5,27 @@ typedef enum { PLAYER_ITEM_NONE, PLAYER_ITEM_SWORD, PLAYER_ITEM_BOMB, - PLAYER_ITEM_3, + PLAYER_ITEM_BOOMERANG, PLAYER_ITEM_BOW, PLAYER_ITEM_SHIELD, PLAYER_ITEM_LANTERN, - PLAYER_ITEM_7, + PLAYER_ITEM_NULLED, PLAYER_ITEM_GUST_JAR, PLAYER_ITEM_PACCI_CANE, - PLAYER_ITEM_A, - PLAYER_ITEM_B, - PLAYER_ITEM_C, + PLAYER_ITEM_NONE2, // Mole Mitts + PLAYER_ITEM_NONE3, // Rocs Cape + PLAYER_ITEM_DASH_SWORD, PLAYER_ITEM_CELL_OVERWRITE_SET, PLAYER_ITEM_BOTTLE, PLAYER_ITEM_SWORD_BEAM1, - PLAYER_ITEM_10, - PLAYER_ITEM_11, - PLAYER_ITEM_12, - PLAYER_ITEM_13, - PLAYER_ITEM_14, - PLAYER_ITEM_15, + PLAYER_ITEM_GUST, + PLAYER_ITEM_GUST_BIG, + PLAYER_ITEM_PACCI_CANE_PROJECTILE, + PLAYER_ITEM_HELD_OBJECT, + PLAYER_ITEM_SPIRAL_BEAM, + PLAYER_ITEM_FIRE_ROD_PROJECTILE, PLAYER_ITEM_SWORD_BEAM2, - PLAYER_ITEM_17, + PLAYER_ITEM_NULLED2, PLAYER_ITEM_CELL_OVERWRITE_SET2, } PlayerItem; diff --git a/include/room.h b/include/room.h index b13fc21a..d5cc5c81 100644 --- a/include/room.h +++ b/include/room.h @@ -113,13 +113,13 @@ typedef struct { u8 animationState; u8 field_0x6; u8 field_0x7; -} struct_030010EC; +} MinecartData; typedef struct { u16 data[32]; u16 field_0xac; u16 field_0xae; -} struct_0300110C; +} ArmosData; // Status of the player's positioning within the scene. typedef struct { @@ -168,8 +168,8 @@ typedef struct { /* 0x46 */ u16 field_0x46; /* 0x48 */ u16 field_0x48; /* 0x4a */ u16 field_0x4a; - /* 0x4c */ struct_030010EC minecart_data[4]; - /* 0x6c */ struct_0300110C armos_data; + /* 0x4c */ MinecartData minecart_data[4]; + /* 0x6c */ ArmosData armos_data; } RoomTransition; static_assert(sizeof(RoomTransition) == 0xB0); extern RoomTransition gRoomTransition; diff --git a/include/script.h b/include/script.h index 78e29963..a040b755 100644 --- a/include/script.h +++ b/include/script.h @@ -59,5 +59,6 @@ void ExecuteScriptForEntity(Entity* entity, void (*postScriptCallback)(Entity*, void HandlePostScriptActions(Entity* entity, ScriptExecutionContext* context); void HandleEntity0x82Actions(Entity* entity); void sub_0807DD94(Entity*, void (*function)(Entity*, ScriptExecutionContext*)); - +ScriptExecutionContext* CreateScriptExecutionContext(void); +void InitScriptForEntity(Entity* entity, ScriptExecutionContext* context, u16* script); #endif // SCRIPT_H diff --git a/include/sound.h b/include/sound.h index 86fa8ac9..f62768ad 100644 --- a/include/sound.h +++ b/include/sound.h @@ -387,7 +387,7 @@ typedef enum { SFX_160, SFX_161, SFX_162, - SFX_163, + SFX_TOGGLE_DIVING, SFX_164, SFX_165, SFX_166, diff --git a/include/structures.h b/include/structures.h index a87a820a..d9339a7f 100644 --- a/include/structures.h +++ b/include/structures.h @@ -148,21 +148,21 @@ typedef enum { } GfxSlotVramStatus; typedef struct { - u8 status : 4; - u8 vramStatus : 4; // Whether the gfx was uploaded to the vram? - u8 slotCount; - u8 referenceCount; /**< How many entities use this gfx slot */ - u8 unk_3; - u16 gfxIndex; - u16 paletteIndex; - const void* palettePointer; + /*0x00*/ u8 status : 4; + /*0x00*/ u8 vramStatus : 4; // Whether the gfx was uploaded to the vram? + /*0x01*/ u8 slotCount; + /*0x02*/ u8 referenceCount; /**< How many entities use this gfx slot */ + /*0x03*/ u8 unk_3; + /*0x04*/ u16 gfxIndex; + /*0x06*/ u16 paletteIndex; + /*0x08*/ const void* palettePointer; } GfxSlot; typedef struct { - u8 unk0; - u8 unk_1; - u8 unk_2; - u8 unk_3; - GfxSlot slots[MAX_GFX_SLOTS]; + /*0x00*/ u8 unk0; + /*0x01*/ u8 unk_1; + /*0x02*/ u8 unk_2; + /*0x03*/ u8 unk_3; + /*0x04*/ GfxSlot slots[MAX_GFX_SLOTS]; } GfxSlotList; extern GfxSlotList gGFXSlots; @@ -179,8 +179,16 @@ extern u16 gBG1Buffer[0x400]; extern u16 gBG2Buffer[0x400]; extern u16 gBG3Buffer[0x800]; -extern ItemBehavior gUnk_03000B80[4]; -static_assert(sizeof(gUnk_03000B80) == 0x70); +typedef enum { ACTIVE_ITEM_0, ACTIVE_ITEM_1, ACTIVE_ITEM_2, ACTIVE_ITEM_LANTERN, MAX_ACTIVE_ITEMS } ActiveItemIndex; +/** + * Currently active items. + * 0: Active items? + * 1: Boots, Cape + * 2: would be used by CreateItem1 if gActiveItems[1] was already filled + * 3: Lamp + */ +extern ItemBehavior gActiveItems[MAX_ACTIVE_ITEMS]; +static_assert(sizeof(gActiveItems) == 0x70); typedef struct { u8 sys_priority; // system requested priority @@ -323,4 +331,18 @@ typedef struct { s16 position; } TileData; +typedef struct { + /*0x00*/ bool8 isOnlyActiveFirstFrame; /**< Is the behavior for this item only created on the first frame */ + /*0x01*/ u8 priority; + /*0x02*/ u8 createFunc; + /*0x03*/ u8 playerItemId; /**< Id for the corresponsing PlayerItem. */ + /*0x04*/ u16 frameIndex; + /*0x06*/ u8 animPriority; + /*0x07*/ bool8 isChangingAttackStatus; + /*0x08*/ bool8 isUseableAsMinish; + /*0x09*/ u8 pad[3]; +} ItemDefinition; + +static_assert(sizeof(ItemDefinition) == 0xc); + #endif // STRUCTURES_H diff --git a/linker.ld b/linker.ld index f25dbc52..e54990d2 100644 --- a/linker.ld +++ b/linker.ld @@ -75,7 +75,6 @@ SECTIONS { . = 0x00024050; gRoomMemory = .; . = 0x00024090; gUnk_02024090 = .; . = 0x00024490; gGFXSlots = .; - . = 0x00024494; gUnk_02024494 = .; . = 0x000246B0; gUnk_020246B0 = .; . = 0x00025EB0; gMapBottom = .; . = 0x00031EC0; gNPCData = .; @@ -131,7 +130,7 @@ SECTIONS { iwram (NOLOAD) : ALIGN(4) { . = 0x00000000; gOAMControls = .; . = 0x00000420; gUnk_03000420 = .; - . = 0x00000B80; gUnk_03000B80 = .; + . = 0x00000B80; gActiveItems = .; . = 0x00000BF0; gRoomControls = .; . = 0x00000C24; gUnk_03000C24 = .; . = 0x00000C30; gUnk_03000C30 = .; @@ -236,7 +235,7 @@ SECTIONS { #endif . = 0x00007F00; usr_stack_begin = .; . = 0x00007FA0; irq_stack_begin = .; - . = 0x00007FFA; gUnk_03007FFA = .; + . = 0x00007FFA; soft_reset_flag = .; . = 0x00008000; } >iwram @@ -1290,6 +1289,8 @@ SECTIONS { src/item/itemGustJar.o(.rodata); src/item/itemMoleMitts.o(.rodata); src/item/itemJarEmpty.o(.rodata); + data/item.o(.rodata); + src/itemDefinitions.o(.rodata); data/data_0811BE38.o(.rodata); data/map/room_headers.o(.rodata); src/flags.o(.rodata); diff --git a/src/beanstalkSubtask.c b/src/beanstalkSubtask.c index c0a82532..0b872fca 100644 --- a/src/beanstalkSubtask.c +++ b/src/beanstalkSubtask.c @@ -39,7 +39,16 @@ extern const u16* gUnk_080B4550[]; extern const u16 gUnk_080B77C0[]; extern BgAnimationFrame* gUnk_080B7278[]; -void sub_0801AD6C(u16*, u32); +typedef struct { + u16 tileType; + u16 kind; + u16 id; + u16 type; + u16 type2; + u16 unk_a; +} Data; + +void sub_0801AD6C(const Data*, u32); bool32 sub_0801A4F8(void); bool32 sub_0801AA58(Entity*, u32, u32); void sub_0801AB08(u16*, LayerStruct*); @@ -146,7 +155,7 @@ NONMATCH("asm/non_matching/beanstalkSubtask/sub_0801A2B0.inc", u32 temp5; uVar1 = gUnk_080B4488[gPlayerEntity.animationState >> 1]; - if ((((gPlayerState.field_0x35 | gPlayerState.field_0xd) & 0x80) == 0) && ((gPlayerEntity.frame & 1) != 0)) { + if ((((gPlayerState.field_0x35 | gPlayerState.direction) & 0x80) == 0) && ((gPlayerEntity.frame & 1) != 0)) { position = (u16)(position + uVar1); temp4 = sub_080B1B54(GetTileType(position, gPlayerEntity.collisionLayer)); switch (temp4) { @@ -264,10 +273,10 @@ bool32 sub_0801A4F8(void) { if (GetInventoryValue(ITEM_POWER_BRACELETS) != 1) { return FALSE; } - if ((gPlayerState.field_0xd & 0x80) != 0) { + if ((gPlayerState.direction & 0x80) != 0) { return FALSE; } - if (gPlayerState.field_0xd != gPlayerEntity.direction) { + if (gPlayerState.direction != gPlayerEntity.direction) { return FALSE; } tmp = (((gPlayerEntity.direction + 4) & 0x18) >> 3); @@ -275,7 +284,7 @@ bool32 sub_0801A4F8(void) { return FALSE; } } else { - if (((gPlayerState.field_0x35 | gPlayerState.field_0xd) & 0x80) != 0) { + if (((gPlayerState.field_0x35 | gPlayerState.direction) & 0x80) != 0) { return FALSE; } if ((gPlayerEntity.frame & 1) == 0) { @@ -411,19 +420,18 @@ u32 sub_0801AC68(u32 position, u32 data) { return data << 2; } -extern const u16 gUnk_080B44C0[]; -extern const u16 gUnk_080B44C2[]; +extern const Data gUnk_080B44C0[]; +extern const Data gUnk_080B44C2[]; extern const u32 gUnk_080B44B8[]; NONMATCH("asm/non_matching/beanstalkSubtask/sub_0801AC98.inc", void sub_0801AC98()) { + u32 width; u32 height; u32 indexX; - u32 width; u32 indexY; - const u16* puVar7; + const Data* ptr1; + const Data* ptr2; u32 position; - const u32* ptr; - u32 tmp; width = gRoomControls.width >> 4; height = gRoomControls.height >> 4; @@ -431,32 +439,30 @@ NONMATCH("asm/non_matching/beanstalkSubtask/sub_0801AC98.inc", void sub_0801AC98 for (indexY = 0; indexY < height; indexY++) { for (indexX = 0; indexX < width; indexX++, position++) { - for (puVar7 = gUnk_080B44C0; puVar7[0] != 0xffff; puVar7 += 6) { - if (puVar7[0] == GetTileType(position, 1)) { - ptr = gUnk_080B44B8 + puVar7[5]; - if (ptr[0] != 0) { - sub_0801AD6C((u16*)puVar7, position); + for (ptr1 = gUnk_080B44C0; ptr1->tileType != 0xffff; ptr1++) { + if (ptr1->tileType == GetTileType(position, 1)) { + if (gUnk_080B44B8[ptr1->unk_a] != 0) { + sub_0801AD6C(ptr1, position); break; } } } - for (puVar7 = gUnk_080B44C2; puVar7[0] != 0xffff; puVar7 += 6) { - if (puVar7[0] == GetTileType(position, 2)) { - ptr = gUnk_080B44B8 + puVar7[5]; - if (ptr[0] != 0) { - sub_0801AD6C((u16*)puVar7, position); + + for (ptr2 = gUnk_080B44C2; ptr2->tileType != 0xffff; ptr2++) { + if (ptr2->tileType == GetTileType(position, 2)) { + if (gUnk_080B44B8[ptr2->unk_a] != 0) { + sub_0801AD6C(ptr2, position); break; } } } } - tmp = (position + 0x40); - position = tmp - width; + position = position + (0x40 - width); } } END_NONMATCH -void sub_0801AD6C(u16* param_1, u32 param_2) { +void sub_0801AD6C(const Data* param_1, u32 tilePosition) { Entity* entity; Manager* manager; s32 tmpX1; @@ -464,16 +470,16 @@ void sub_0801AD6C(u16* param_1, u32 param_2) { s32 tmpX2; s32 tmpY2; - if (param_1[1] != MANAGER) { + if (param_1->kind != MANAGER) { entity = GetEmptyEntity(); if (entity != NULL) { - entity->kind = (u8)param_1[1]; - entity->id = (u8)param_1[2]; - entity->type = (u8)param_1[3]; - entity->type2 = (u8)param_1[4]; - tmpX1 = ((u16)param_2 & 0x3f) * 0x10 + 8; + entity->kind = (u8)param_1->kind; + entity->id = (u8)param_1->id; + entity->type = (u8)param_1->type; + entity->type2 = (u8)param_1->type2; + tmpX1 = ((u16)tilePosition & 0x3f) * 0x10 + 8; entity->x.HALF.HI = tmpX1 + gRoomControls.origin_x; - tmpY1 = (s16)((param_2 & 0xfc0) >> 2) + 8; + tmpY1 = (s16)((tilePosition & 0xfc0) >> 2) + 8; entity->y.HALF.HI = tmpY1 + gRoomControls.origin_y; entity->collisionLayer = 0; ResolveCollisionLayer(entity); @@ -482,14 +488,14 @@ void sub_0801AD6C(u16* param_1, u32 param_2) { } else { manager = GetEmptyManager(); if (manager != NULL) { - manager->kind = (u8)param_1[1]; - manager->id = (u8)param_1[2]; - manager->type = (u8)param_1[3]; - manager->type2 = (u8)param_1[4]; + manager->kind = (u8)param_1->kind; + manager->id = (u8)param_1->id; + manager->type = (u8)param_1->type; + manager->type2 = (u8)param_1->type2; // TODO are these fields common for all managers or does this usually create managers of certain types? - tmpX2 = ((u16)param_2 & 0x3f) * 0x10 + 8; + tmpX2 = ((u16)tilePosition & 0x3f) * 0x10 + 8; *(u16*)(&manager[1].timer + 10) = tmpX2 + gRoomControls.origin_x; - tmpY2 = (s16)((param_2 & 0xfc0) >> 2) + 8; + tmpY2 = (s16)((tilePosition & 0xfc0) >> 2) + 8; *(u16*)(&manager[1].timer + 12) = tmpY2 + gRoomControls.origin_y; AppendEntityToList((Entity*)manager, gUnk_081091E4[manager->kind]); } diff --git a/src/collision.c b/src/collision.c index 7b6f2cb4..d857d56b 100644 --- a/src/collision.c +++ b/src/collision.c @@ -1,17 +1,26 @@ -#include "global.h" #include "asm.h" +#include "collision.h" +#include "common.h" +#include "enemy.h" #include "entity.h" +#include "functions.h" +#include "game.h" +#include "global.h" +#include "item.h" +#include "object.h" #include "player.h" #include "save.h" -#include "common.h" -#include "functions.h" -#include "enemy.h" -#include "object.h" -#include "game.h" extern u8 gCollidableCount; extern u8 gUnk_080B3740[]; +typedef enum { + COL_FLAG_1 = 1, + COL_FLAG_2 = 2, + COL_FLAG_4 = 4, + COL_FLAG_8 = 8, +} ColSettingsFlags; + typedef struct { /*0x00*/ u8 orgKnockbackSpeed; /*0x01*/ u8 orgIframes; @@ -23,8 +32,8 @@ typedef struct { /*0x07*/ u8 tgtKnockbackDuration; /*0x08*/ u8 orgDamage; /*0x09*/ u8 tgtConfusedTime; - /*0x0a*/ u8 _a; - /*0x0b*/ u8 _b; + /*0x0a*/ u8 flags; /**< @see ColSettingsFlags */ + /*0x0b*/ u8 pad; } ColSettings; extern ColSettings gCollisionMtx[173 * 34]; @@ -32,10 +41,8 @@ extern ColSettings gCollisionMtx[173 * 34]; extern void ram_CollideAll(void); u32 sub_08081420(Entity*); extern void SoundReqClipped(Entity*, u32); -s32 sub_08018308(Entity*, Entity*, u32, ColSettings*); void sub_08079D84(void); void sub_080180BC(Entity*, Entity*); -void sub_0807AFE8(void); typedef struct { void* last; @@ -208,51 +215,49 @@ bool32 IsCollidingPlayer(Entity* this) { return FALSE; } -s32 sub_08017874(Entity* a, Entity* b) { - s32 newDmg; - s32 v5; - s32 v6; +s32 CalculateDamage(Entity* org, Entity* tgt) { + s32 damage; + s32 health; - asm("" ::: "r1"); - if (a->kind == PLAYER) { - newDmg = b->damage; + if (org->kind == PLAYER) { + damage = tgt->damage; switch (gSave.stats.charm) { - case 47: - newDmg /= 4; + case BOTTLE_CHARM_NAYRU: + damage /= 4; break; - case 48: - newDmg /= 2; + case BOTTLE_CHARM_FARORE: + damage /= 2; break; } - if (newDmg <= 0) - newDmg = 1; - v5 = ModHealth(-newDmg); - SoundReqClipped(a, SFX_PLY_VO6); + if (damage <= 0) + damage = 1; + health = ModHealth(-damage); + SoundReqClipped(org, SFX_PLY_VO6); } else { - v6 = b->damage; - if (b->kind == PLAYER_ITEM) { + damage = tgt->damage; + if (tgt->kind == PLAYER_ITEM) { switch (gSave.stats.charm) { - case 48: - v6 = 3 * v6 / 2; + case BOTTLE_CHARM_FARORE: + damage = 3 * damage / 2; break; - case 49: - v6 *= 2; + case BOTTLE_CHARM_DIN: + damage *= 2; break; } } - v5 = a->health - v6; - if (a->kind == ENEMY) { - if ((a->field_0x6c.HALF.HI & 1) != 0) - SoundReqClipped(a, SFX_BOSS_HIT); + health = org->health - damage; + if (org->kind == ENEMY) { + if ((org->field_0x6c.HALF.HI & 1) != 0) + SoundReqClipped(org, SFX_BOSS_HIT); else - SoundReqClipped(a, SFX_HIT); + SoundReqClipped(org, SFX_HIT); } } - if (v5 <= 0) { - COLLISION_OFF(a); + if (health <= 0) { + COLLISION_OFF(org); return 0; } - return v5; + return health; } void sub_08017940(Entity* org, Entity* tgt) { @@ -308,51 +313,71 @@ Entity* sub_08017A90(Entity* a1, Entity* parent) { return NULL; } -typedef s32 (*CollisionHandler)(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 CollisionNoOp(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 CollisionGroundItem(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017B58(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017EB0(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017F3C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017F40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_0801802C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017DD4(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_080180E8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017BBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017C40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017D6C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017D28(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08018168(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08018228(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08018250(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08018288(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_080182A8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017B1C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017CBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -s32 sub_08017E88(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +typedef CollisionResult (*CollisionHandler)(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult CollisionDefault(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult CollisionNoOp(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult CollisionGroundItem(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017B58(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017EB0(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017F3C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017F40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_0801802C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017DD4(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_080180E8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017BBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017C40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017D6C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017D28(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08018168(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08018228(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08018250(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult CollisionMazaalShrinkRay(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_080182A8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017B1C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017CBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); +CollisionResult sub_08017E88(Entity* org, Entity* tgt, u32 direction, ColSettings* settings); -const CollisionHandler gUnk_080B3744[] = { - sub_08018308, CollisionNoOp, CollisionNoOp, CollisionGroundItem, sub_08017B58, sub_08017EB0, - sub_08017F3C, sub_08017F40, sub_0801802C, sub_08017DD4, sub_080180E8, sub_08017BBC, - sub_08017C40, sub_08017D6C, sub_08017D28, sub_08018168, sub_08018228, sub_08018250, - sub_08018288, sub_080182A8, sub_08017B1C, sub_08017CBC, sub_08017E88, +const CollisionHandler gCollisionHandlers[] = { + CollisionDefault, + CollisionNoOp, + CollisionNoOp, + CollisionGroundItem, + sub_08017B58, + sub_08017EB0, + sub_08017F3C, + sub_08017F40, + sub_0801802C, + sub_08017DD4, + sub_080180E8, + sub_08017BBC, + sub_08017C40, + sub_08017D6C, + sub_08017D28, + sub_08018168, + sub_08018228, + sub_08018250, + CollisionMazaalShrinkRay, + sub_080182A8, + sub_08017B1C, + sub_08017CBC, + sub_08017E88, }; -s32 CollisionNoOp(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { - return 0; +CollisionResult CollisionNoOp(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { + return RESULT_NO_COLLISION; } // origin: player or sword // target: item -s32 CollisionGroundItem(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult CollisionGroundItem(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { COLLISION_OFF(tgt); tgt->contactFlags = org->hurtType | 0x80; if ((tgt->type == 0x5F || tgt->type == 0x60) && sub_08081420(tgt)) tgt->health = 0; - return 2; + return RESULT_COLLISION_WITHOUT_SET; } -s32 sub_08017B1C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017B1C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if ((gPlayerState.dash_state & 0x60) != 0) { COLLISION_OFF(tgt); } else { @@ -360,10 +385,10 @@ s32 sub_08017B1C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) org->iframes = -20; org->knockbackSpeed = 640; } - return 1; + return RESULT_COLLISION; } -s32 sub_08017B58(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017B58(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if ((tgt->gustJarState & 4) != 0) { if (tgt->gustJarTolerance) { tgt->gustJarTolerance = tgt->gustJarTolerance - gPlayerState.gustJarSpeed; @@ -379,10 +404,10 @@ s32 sub_08017B58(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) } if (tgt->iframes == 0) tgt->iframes = -1; - return 1; + return RESULT_COLLISION; } -s32 sub_08017BBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017BBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if ((gPlayerState.flags & (PL_BUSY | PL_MINISH | PL_BURNING | PL_IN_MINECART)) == 0) { Entity* e = CreateObject(LINK_FIRE, 1, 0); if (e != NULL) { @@ -392,21 +417,21 @@ s32 sub_08017BBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) } } tgt->damage = 4; - org->health = sub_08017874(org, tgt); + org->health = CalculateDamage(org, tgt); org->knockbackDuration = 12; org->iframes = 30; org->knockbackSpeed = 384; if (tgt->iframes == 0) tgt->iframes = -1; - return 1; + return RESULT_COLLISION; } -s32 sub_08017C40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017C40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if ((gPlayerState.flags & (PL_BUSY | PL_MINISH | PL_FROZEN | PL_IN_MINECART)) == 0 && gPlayerState.queued_action == PLAYER_INIT) { if (org->action == 1 || org->action == 24) { tgt->damage = 4; - org->health = sub_08017874(org, tgt); + org->health = CalculateDamage(org, tgt); gPlayerState.flags = PL_FROZEN; gPlayerState.queued_action = PLAYER_FROZEN; } @@ -416,10 +441,10 @@ s32 sub_08017C40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) org->knockbackSpeed = 640; if (tgt->iframes == 0) tgt->iframes = -1; - return 1; + return RESULT_COLLISION; } -s32 sub_08017CBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017CBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { direction = DirectionNormalize(DirectionTurnAround(direction) - 0xc); if (DirectionNormalize(-direction + tgt->direction) < 0x19) { org->iframes = -12; @@ -433,10 +458,10 @@ s32 sub_08017CBC(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) if (org->iframes == 0) org->iframes = -1; } - return 1; + return RESULT_COLLISION; } -s32 sub_08017D28(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017D28(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { gPlayerState.mobility = 1; org->field_0x7a.HWORD = 600; org->knockbackDuration = 12; @@ -444,10 +469,10 @@ s32 sub_08017D28(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) org->knockbackSpeed = 640; if (tgt->iframes == 0) tgt->iframes = -1; - return 1; + return RESULT_COLLISION; } -s32 sub_08017D6C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017D6C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { u32 x; u32 y; ColSettings* p; @@ -463,16 +488,16 @@ s32 sub_08017D6C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) y = 0xae4; } p = &gCollisionMtx[x + y]; - return sub_08018308(org, tgt, direction, p); + return CollisionDefault(org, tgt, direction, p); } -int sub_08017DD4(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017DD4(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { org->contactFlags = 0; if (tgt->damage & 0x80) tgt->damage &= ~0x80; else tgt->damage = 4; - gPlayerEntity.health = sub_08017874(&gPlayerEntity, tgt); + gPlayerEntity.health = CalculateDamage(&gPlayerEntity, tgt); tgt->iframes = -12; if ((gPlayerState.flags & PL_MINISH) == 0) { sub_08079D84(); @@ -486,25 +511,25 @@ int sub_08017DD4(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) } if (tgt->iframes == 0) tgt->iframes = -1; - return 1; + return RESULT_COLLISION; } -s32 sub_08017E88(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017E88(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { org->knockbackDuration = 2; org->knockbackSpeed = 640; if (tgt->iframes == 0) tgt->iframes = -1; - return 1; + return RESULT_COLLISION; } -s32 sub_08017EB0(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017EB0(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if (tgt->damage == 0) - return 0; + return RESULT_NO_COLLISION; if (org == &gPlayerEntity) { - u32 temp = tgt->damage; + u32 prevDamage = tgt->damage; tgt->damage = 8; - gPlayerEntity.health = sub_08017874(&gPlayerEntity, tgt); - tgt->damage = temp; + gPlayerEntity.health = CalculateDamage(&gPlayerEntity, tgt); + tgt->damage = prevDamage; gPlayerEntity.knockbackDuration = 12; gPlayerEntity.iframes = 16; gPlayerEntity.knockbackSpeed = 384; @@ -516,14 +541,14 @@ s32 sub_08017EB0(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) } if (tgt->iframes == 0) tgt->iframes = -1; - return 1; + return RESULT_COLLISION; } -s32 sub_08017F3C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { - return 1; +CollisionResult sub_08017F3C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { + return RESULT_COLLISION; } -s32 sub_08017F40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08017F40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if (tgt->confusedTime == 0) { if (org == &gPlayerEntity) { if (PlayerCanBeMoved() && @@ -548,8 +573,8 @@ s32 sub_08017F40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) org->spriteOrientation.flipY = tgt->spriteOrientation.flipY; org->iframes = -1; tgt->iframes = -8; - ResetPlayerItem(); - return 1; + ResetActiveItems(); + return RESULT_COLLISION; } } else { org->health = 0; @@ -557,39 +582,39 @@ s32 sub_08017F40(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) } else if (tgt->kind == ENEMY && org == &gPlayerEntity) { sub_08004484(tgt, org); } - return 0; + return RESULT_NO_COLLISION; } -s32 sub_0801802C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_0801802C(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { int kind; u32 x; kind = org->kind; - if (kind == 1) { + if (kind == PLAYER) { if (PlayerCanBeMoved()) { if (((DirectionNormalize(DirectionTurnAround(direction) - Direction8FromAnimationState(tgt->animationState) + 5))) > 0xA) { x = 0x11aa; - return sub_08018308(org, tgt, direction, &gCollisionMtx[x + org->hurtType]); + return CollisionDefault(org, tgt, direction, &gCollisionMtx[x + org->hurtType]); } else { sub_080180BC(org, tgt); - return 1; + return RESULT_COLLISION; } } - } else if (kind == 8) { + } else if (kind == PLAYER_ITEM) { if (DirectionNormalize( (DirectionTurnAround(org->direction) - Direction8FromAnimationState(tgt->animationState) + 5)) <= 0xA) { org->health = 0; sub_080180BC(org, tgt); - return 1; + return RESULT_COLLISION; } } else { org->health = 0; - return 0; + return RESULT_NO_COLLISION; } x = 0x11aa; - return sub_08018308(org, tgt, direction, &gCollisionMtx[x + org->hurtType]); + return CollisionDefault(org, tgt, direction, &gCollisionMtx[x + org->hurtType]); } void sub_080180BC(Entity* org, Entity* tgt) { @@ -600,7 +625,7 @@ void sub_080180BC(Entity* org, Entity* tgt) { tgt->subAction = -1; } -s32 sub_080180E8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_080180E8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { u32 v3; u32 x; @@ -613,13 +638,13 @@ s32 sub_080180E8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) tgt->iframes = -16; tgt->knockbackSpeed = 768; sub_08017940(org, tgt); - return 1; + return RESULT_COLLISION; } x = 0x352; - return sub_08018308(org, tgt, v3, &gCollisionMtx[org->hurtType + x]); + return CollisionDefault(org, tgt, v3, &gCollisionMtx[org->hurtType + x]); } -s32 sub_08018168(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08018168(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if (tgt->confusedTime == 0) { if (org == &gPlayerEntity) { if (PlayerCanBeMoved() && @@ -639,7 +664,7 @@ s32 sub_08018168(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) gPlayerEntity.iframes = 0xff; tgt->iframes = -8; PutAwayItems(); - return 1; + return RESULT_COLLISION; } } else { org->health = 0; @@ -647,16 +672,16 @@ s32 sub_08018168(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) } else if ((tgt->kind == ENEMY) && (org == &gPlayerEntity)) { sub_08004484(tgt, &gPlayerEntity); } - return 0; + return RESULT_NO_COLLISION; } -s32 sub_08018228(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08018228(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if (org == &gPlayerEntity && PlayerCanBeMoved()) sub_08004484(tgt, org); - return 0; + return RESULT_NO_COLLISION; } -s32 sub_08018250(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_08018250(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { org->iframes = -1; if (org->direction == 0) { tgt->iframes = 16; @@ -664,18 +689,18 @@ s32 sub_08018250(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) } else { tgt->iframes = -1; } - return 1; + return RESULT_COLLISION; } -s32 sub_08018288(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult CollisionMazaalShrinkRay(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if (org == &gPlayerEntity) - sub_0807AFE8(); + PlayerShrinkByRay(); else org->health = 0; - return 1; + return RESULT_COLLISION; } -s32 sub_080182A8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult sub_080182A8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { if (tgt->confusedTime == 0) { if (org->iframes == 0) org->iframes = -1; @@ -683,12 +708,12 @@ s32 sub_080182A8(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) tgt->iframes = -1; } else { u32 x = 0x92a; - return sub_08018308(org, tgt, direction, &gCollisionMtx[org->hurtType + x]); + return CollisionDefault(org, tgt, direction, &gCollisionMtx[org->hurtType + x]); } - return 1; + return RESULT_COLLISION; } -s32 sub_08018308(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { +CollisionResult CollisionDefault(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) { u32 confused = 0; if (tgt->confusedTime && tgt->kind == ENEMY && org == &gPlayerEntity) { sub_08004484(tgt, org); @@ -697,7 +722,7 @@ s32 sub_08018308(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) if ((org->kind == PLAYER_ITEM && org->id == PL_ITEM_SHIELD) && gPlayerEntity.animationState == AnimationStateFlip180(Direction8ToAnimationState(DirectionRoundUp(direction)))) { - return 0; + return RESULT_NO_COLLISION; } if (!confused) { u32 tmp2; @@ -709,7 +734,7 @@ s32 sub_08018308(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) tgt->damage = settings->tgtDamage; tmp2 = 0xFF; if (settings->tgtDamage != 0) - org->health = sub_08017874(org, tgt); + org->health = CalculateDamage(org, tgt); if (settings->orgConfusedTime > org->confusedTime) org->confusedTime = settings->orgConfusedTime; tgt->knockbackSpeed = 16 * settings->tgtKnockbackSpeed; @@ -719,15 +744,15 @@ s32 sub_08018308(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) tgt->knockbackDuration = settings->tgtKnockbackDuration; tmp2 &= (org->damage = settings->orgDamage); if (tmp2 != 0) - tgt->health = sub_08017874(tgt, org); + tgt->health = CalculateDamage(tgt, org); if (settings->tgtConfusedTime > tgt->confusedTime) tgt->confusedTime = settings->tgtConfusedTime; } - if (settings->_a & 1) + if (settings->flags & COL_FLAG_1) sub_08017940(org, tgt); - if (settings->_a & 2) + if (settings->flags & COL_FLAG_2) org->contactFlags = 0xca; - if (settings->_a & 4) { + if (settings->flags & COL_FLAG_4) { Entity* parent = tgt->parent; if (parent != NULL) { parent->contactFlags = 0xcc; @@ -746,7 +771,7 @@ s32 sub_08018308(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) sub_080179EC(org, tgt); } } else if (org->id == PL_ITEM_BOW) { - if (org->damage || (settings->_a & 8)) { + if (org->damage || (settings->flags & COL_FLAG_8)) { sub_08017A90(org, tgt); } } else if (org->id == PL_ITEM_BOOMERANG) { @@ -760,5 +785,5 @@ s32 sub_08018308(Entity* org, Entity* tgt, u32 direction, ColSettings* settings) if (tgt->kind == PLAYER_ITEM && org->id == PL_ITEM_SHIELD) { gPlayerEntity.iframes = 0x80; } - return 1; + return RESULT_COLLISION; } diff --git a/src/color.c b/src/color.c index 5add643a..01e678e8 100644 --- a/src/color.c +++ b/src/color.c @@ -30,8 +30,8 @@ void ResetPaletteTable(u32 a1) { sub_0801D000(a1); } -void sub_0801CFD0(u32 a1) { - Palette* p = &gPaletteList[a1]; +void sub_0801CFD0(u32 index) { + Palette* p = &gPaletteList[index]; p->_0_0 = 4; p->_0_4 = 1; p->_1 = 0x80; diff --git a/src/enemy/armos.c b/src/enemy/armos.c index 709f0630..7e0c3b7a 100644 --- a/src/enemy/armos.c +++ b/src/enemy/armos.c @@ -69,11 +69,11 @@ void sub_080300E8(void) { } } -void sub_08030118(u32 param_1) { - if (((s32)(u32)gRoomTransition.armos_data.field_0xac >> (param_1)&1) != 0) { - SetLocalFlagByBank(FLAG_BANK_3, param_1 + 0x67); +void sub_08030118(u32 armosId) { + if (((gRoomTransition.armos_data.field_0xac >> armosId) & 1) != 0) { + SetLocalFlagByBank(FLAG_BANK_3, armosId + 0x67); } else { - ClearLocalFlagByBank(FLAG_BANK_3, param_1 + 0x67); + ClearLocalFlagByBank(FLAG_BANK_3, armosId + 0x67); } } diff --git a/src/enemy/beetle.c b/src/enemy/beetle.c index 63ef0959..ace73b7f 100644 --- a/src/enemy/beetle.c +++ b/src/enemy/beetle.c @@ -252,7 +252,7 @@ void sub_08021B64(Entity* this) { } else { gPlayerState.mobility |= 0x80; gPlayerState.speed_modifier -= 0x50; - gPlayerState.field_0xaa++; + gPlayerState.attachedBeetleCount++; CopyPositionAndSpriteOffset(&gPlayerEntity, this); this->x.HALF.HI += gUnk_080CB5E4[(this->subtimer++ & 0xe) >> 1]; this->z.HALF.HI--; diff --git a/src/enemy/chuchuBoss.c b/src/enemy/chuchuBoss.c index ea2eab93..2726a05c 100644 --- a/src/enemy/chuchuBoss.c +++ b/src/enemy/chuchuBoss.c @@ -1830,7 +1830,7 @@ Entity* sub_08027D20(ChuchuBossEntity* this) { r4->spriteVramOffset = super->spriteVramOffset; r4->palette.b.b0 = super->palette.b.b0; #endif - r4->y.HALF.HI += 1; + r4->y.HALF.HI++; r4->spriteOffsetY = 8; #ifndef EU LoadFixedGFX(r4, 0x3e); diff --git a/src/enemy/dust.c b/src/enemy/dust.c index 74da343e..9880333a 100644 --- a/src/enemy/dust.c +++ b/src/enemy/dust.c @@ -277,7 +277,7 @@ void sub_08044498(DustEntity* this) { u32 xdiff, ydiff; uVar4 = COORD_TO_TILE(&gPlayerEntity); - tmp = (gPlayerState.playerInput.field_0x92 & 0xf00); + tmp = (gPlayerState.playerInput.newInput & 0xf00); if (tmp != this->unk_75 || uVar4 != this->unk_76) { this->unk_75 = tmp; this->unk_76 = uVar4; diff --git a/src/enemy/enemy64.c b/src/enemy/enemy64.c index e1b3e51a..5cfd1a60 100644 --- a/src/enemy/enemy64.c +++ b/src/enemy/enemy64.c @@ -411,13 +411,13 @@ void Enemy64_Action4_SubAction5(Enemy64Entity* this) { super->subAction = 6; super->spriteSettings.draw = 0; entity = super->child; - entity->flags &= 0x7f; + entity->flags &= ~0x80; entity->spriteSettings.draw = 0; entity = entity->child; - entity->flags &= 0x7f; + entity->flags &= ~0x80; entity->spriteSettings.draw = 0; entity = entity->child; - entity->flags &= 0x7f; + entity->flags &= ~0x80; entity->spriteSettings.draw = 0; entity = &gPlayerEntity; entity->x.HALF.HI = gRoomControls.origin_x + 0xa8; diff --git a/src/enemy/ghini.c b/src/enemy/ghini.c index 86b9f00c..d74709c7 100644 --- a/src/enemy/ghini.c +++ b/src/enemy/ghini.c @@ -384,7 +384,7 @@ void sub_0803F6EC(GhiniEntity* this) { } void sub_0803F738(GhiniEntity* this) { - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.mobility |= 0x80; gPlayerState.field_0xa |= 0x80; sub_0806FA90(&gPlayerEntity, super, 0, 1); diff --git a/src/enemy/gibdo.c b/src/enemy/gibdo.c index 5d6fac5d..f28fb1e4 100644 --- a/src/enemy/gibdo.c +++ b/src/enemy/gibdo.c @@ -166,7 +166,7 @@ void sub_08037690(GibdoEntity* this) { void sub_080376D0(GibdoEntity* this) { if (!sub_080379EC(this)) { - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.mobility |= 0x80; gPlayerState.field_0xa |= 0x80; CopyPositionAndSpriteOffset(&gPlayerEntity, super); diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index 319e9add..0fea006f 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -1076,7 +1076,7 @@ void sub_0802E300(GleerokEntity* this) { } } - this->unk_79 &= 0x7f; + this->unk_79 &= ~0x80; heap = this->unk_84; dir = sub_0806F5A4(GetFacingDirection(super, &gPlayerEntity)) << 3; index = 0; diff --git a/src/enemy/gyorgMaleEye.c b/src/enemy/gyorgMaleEye.c index 51ecacd4..8f257b7c 100644 --- a/src/enemy/gyorgMaleEye.c +++ b/src/enemy/gyorgMaleEye.c @@ -90,7 +90,7 @@ void GyorgMaleEye_Action2(GyorgMaleEyeEntity* this) { sub_08048F50(this); if (--super->timer == 0) { super->action = 3; - super->flags &= 0x7f; + super->flags &= ~0x80; InitializeAnimation(super, super->animIndex + 4); } } diff --git a/src/enemy/likeLike.c b/src/enemy/likeLike.c index 9125158f..886aa8b7 100644 --- a/src/enemy/likeLike.c +++ b/src/enemy/likeLike.c @@ -198,7 +198,7 @@ void sub_0802805C(LikeLikeEntity* this) { if (super->subtimer >= 0x19 || gSave.stats.health == 0) { LikeLike_ReleasePlayer(this); } else { - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.mobility |= 0x80; PositionRelative(super, &gPlayerEntity, 0, Q_16_16(1.0)); diff --git a/src/enemy/mazaalBracelet.c b/src/enemy/mazaalBracelet.c index 08aadab8..d21e8636 100644 --- a/src/enemy/mazaalBracelet.c +++ b/src/enemy/mazaalBracelet.c @@ -557,7 +557,7 @@ void sub_0803A978(Entity* this) { this->action = 0x12; this->timer = 3; COLLISION_OFF(this); - *(u8*)(*(int*)&this->field_0x74 + 0x10) &= 0x7f; + *(u8*)(*(int*)&this->field_0x74 + 0x10) &= ~0x80; InitializeAnimation(this, 8); InitAnimationForceUpdate(this->child, 3); } @@ -1244,7 +1244,7 @@ void sub_0803B804(Entity* this) { } void sub_0803B824(Entity* this) { - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.mobility |= 0x80; sub_0806FA90(this, &gPlayerEntity, gUnk_080CFD1D[this->type], 1); gPlayerEntity.spriteOffsetY = -6; diff --git a/src/enemy/miniFireballGuy.c b/src/enemy/miniFireballGuy.c index f0fb29b2..be66f3da 100644 --- a/src/enemy/miniFireballGuy.c +++ b/src/enemy/miniFireballGuy.c @@ -39,7 +39,7 @@ void MiniFireballGuy_OnCollision(Entity* this) { void MiniFireballGuy_OnDeath(Entity* this) { if ((this != this->parent) && (this->parent != NULL)) { - this->field_0x6c.HALF.LO &= 0x7f; + this->field_0x6c.HALF.LO &= ~0x80; this->parent->child = this->child; this->child->parent = this->parent; } diff --git a/src/enemy/miniSlime.c b/src/enemy/miniSlime.c index 6352e5ee..67e7675b 100644 --- a/src/enemy/miniSlime.c +++ b/src/enemy/miniSlime.c @@ -50,7 +50,7 @@ void MiniSlime_OnCollision(Entity* this) { void MiniSlime_OnDeath(Entity* this) { Entity* parent = this->parent; if ((this != parent) && (parent != NULL)) { - this->field_0x6c.HALF.LO &= 0x7f; + this->field_0x6c.HALF.LO &= ~0x80; this->parent->child = this->child; this->child->parent = this->parent; if (this->field_0x6c.HALF.HI & 0x40) diff --git a/src/enemy/mulldozer.c b/src/enemy/mulldozer.c index 44404582..fbb376e0 100644 --- a/src/enemy/mulldozer.c +++ b/src/enemy/mulldozer.c @@ -237,7 +237,7 @@ void sub_08033000(MulldozerEntity* this) { super->subtimer = 16; if ((this->unk_82 & 0x80) != 0) { super->direction = (super->direction + 0x18) & 0x1c; - this->unk_82 &= 0x7f; + this->unk_82 &= ~0x80; } else { super->direction = (super->direction + 8) & 0x1c; this->unk_82 |= 0x80; diff --git a/src/enemy/octorokBoss.c b/src/enemy/octorokBoss.c index c9343196..aea3acb2 100644 --- a/src/enemy/octorokBoss.c +++ b/src/enemy/octorokBoss.c @@ -1226,7 +1226,7 @@ void sub_08036F60(OctorokBossEntity* this) { void OctorokBoss_StepSound(OctorokBossEntity* this, u32 frameMask) { if ((gRoomTransition.frameCount & frameMask) == 0) { if (IS_FROZEN(this) == FALSE) { - SoundReq(SFX_163); + SoundReq(SFX_TOGGLE_DIVING); } else { SoundReq(SFX_ICE_BLOCK_SLIDE); } diff --git a/src/enemy/pesto.c b/src/enemy/pesto.c index a9552cc9..b395ba9e 100644 --- a/src/enemy/pesto.c +++ b/src/enemy/pesto.c @@ -828,7 +828,7 @@ void sub_08024E4C(Entity* this) { sub_08024A14(this, 0, 8); } else { Entity* player = &gPlayerEntity; - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.flags |= PL_DISABLE_ITEMS; gPlayerState.field_0xa |= 0x80; gPlayerState.queued_action = PLAYER_0807204C; diff --git a/src/enemy/rupeeLike.c b/src/enemy/rupeeLike.c index c9e4833f..39a8e586 100644 --- a/src/enemy/rupeeLike.c +++ b/src/enemy/rupeeLike.c @@ -167,7 +167,7 @@ void sub_0802953C(Entity* this) { if (((this->subtimer > 0x2d) || (gSave.stats.rupees == 0)) && (this->timer == 0)) { sub_080296D8(this); } else { - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.mobility |= 0x80; PositionRelative(this, &gPlayerEntity, 0, Q_16_16(1.0)); pbVar3 = GetSpriteSubEntryOffsetDataPointer((u16)this->spriteIndex, this->frameIndex); diff --git a/src/enemy/vaatiProjectile.c b/src/enemy/vaatiProjectile.c index 8f013a02..49afbea7 100644 --- a/src/enemy/vaatiProjectile.c +++ b/src/enemy/vaatiProjectile.c @@ -226,7 +226,7 @@ void VaatiProjectileFunction0Action9(Entity* this) { } void sub_0803E444(Entity* this) { - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.mobility |= 0x80; gPlayerState.field_0xa |= 0x80; sub_0806FA90(this, this->contactedEntity, 0, -2); diff --git a/src/enemy/wizzrobeFire.c b/src/enemy/wizzrobeFire.c index ef83c4f8..820bd8ea 100644 --- a/src/enemy/wizzrobeFire.c +++ b/src/enemy/wizzrobeFire.c @@ -113,7 +113,7 @@ void WizzrobeFire_Action2(WizzrobeEntity* this) { this->timer1 = 0x28; super->timer = 40; super->subtimer = 0; - super->flags &= 0x7f; + super->flags &= ~0x80; SetTile(this->tileIndex, this->tilePosition, super->collisionLayer); EnqueueSFX(SFX_156); InitializeAnimation(super, super->direction >> 3); diff --git a/src/enemy/wizzrobeIce.c b/src/enemy/wizzrobeIce.c index a467200d..edd48331 100644 --- a/src/enemy/wizzrobeIce.c +++ b/src/enemy/wizzrobeIce.c @@ -120,7 +120,7 @@ void WizzrobeIce_Action2(WizzrobeEntity* this) { this->timer1 = 0x28; super->timer = 40; super->subtimer = 0; - super->flags &= 0x7f; + super->flags &= ~0x80; SetTile(this->tileIndex, this->tilePosition, super->collisionLayer); EnqueueSFX(SFX_156); InitializeAnimation(super, super->direction >> 3); diff --git a/src/enemy/wizzrobeWind.c b/src/enemy/wizzrobeWind.c index ed28e49f..4d407677 100644 --- a/src/enemy/wizzrobeWind.c +++ b/src/enemy/wizzrobeWind.c @@ -136,7 +136,7 @@ void WizzrobeWind_Action2(WizzrobeEntity* this) { this->timer1 = 0x28; super->timer = 40; super->subtimer = 0; - super->flags &= 0x7f; + super->flags &= ~0x80; EnqueueSFX(SFX_156); SetTile(this->tileIndex, this->tilePosition, super->collisionLayer); InitializeAnimation(super, super->direction >> 3); @@ -264,7 +264,7 @@ void sub_0802F9C8(WizzrobeEntity* this) { if (super->type2 != 0) { ProcessMovement0(super); if (super->collisions != COL_NONE) { - super->flags &= 0x7f; + super->flags &= ~0x80; this->timer1 = 0x28; } } diff --git a/src/game.c b/src/game.c index 19740478..d70d19fd 100644 --- a/src/game.c +++ b/src/game.c @@ -972,10 +972,10 @@ static void InitializePlayer(void) { Entity* pl; sub_080784C8(); - MemClear(&gUnk_03000B80, sizeof gUnk_03000B80); - MemClear(&gPlayerState, sizeof gPlayerState); - MemFill32(0xffffffff, &gPlayerState.path_memory, sizeof gPlayerState.path_memory); - MemClear(&gPlayerEntity, sizeof gPlayerEntity); + MemClear(&gActiveItems, sizeof(gActiveItems)); + MemClear(&gPlayerState, sizeof(gPlayerState)); + MemFill32(0xffffffff, &gPlayerState.path_memory, sizeof(gPlayerState.path_memory)); + MemClear(&gPlayerEntity, sizeof(gPlayerEntity)); pl = &gPlayerEntity; @@ -2463,68 +2463,69 @@ void ModArrows(s32 arrows) { * 1: B * 2: Not equipped */ -u32 IsItemEquipped(u32 itemID) { - u32 itemSlot; +EquipSlot IsItemEquipped(u32 itemId) { + EquipSlot equipSlot; - if (itemID == gSave.stats.itemButtons[SLOT_A]) - itemSlot = 0; - else if (itemID == gSave.stats.itemButtons[SLOT_B]) - itemSlot = 1; - else - itemSlot = 2; - return itemSlot; + if (itemId == gSave.stats.itemButtons[SLOT_A]) { + equipSlot = EQUIP_SLOT_A; + } else if (itemId == gSave.stats.itemButtons[SLOT_B]) { + equipSlot = EQUIP_SLOT_B; + } else { + equipSlot = EQUIP_SLOT_NONE; + } + return equipSlot; } -void PutItemOnSlot(u32 itemID) { - u32 itemSlot; - u32 itemID2 = itemID; - if (itemID2 < 0x47) { +void PutItemOnSlot(u32 itemId) { + EquipSlot equipSlot; + u32 itemId2 = itemId; + if (itemId2 < 0x47) { SetInventoryValue(0, 1); } - if (itemID2 - 1 < 0x1f) { - itemSlot = 2; + if (itemId2 - 1 < 0x1f) { + equipSlot = EQUIP_SLOT_NONE; if (gSave.stats.itemButtons[SLOT_A] == ITEM_NONE) { - itemSlot = 0; + equipSlot = EQUIP_SLOT_A; } else if (gSave.stats.itemButtons[SLOT_B] == ITEM_NONE) { - itemSlot = 1; + equipSlot = EQUIP_SLOT_B; } - if (itemSlot == 2) { - u32 temp = gItemMetaData[itemID2].menuSlot; + if (equipSlot == EQUIP_SLOT_NONE) { + u32 temp = gItemMetaData[itemId2].menuSlot; if (temp == gItemMetaData[gSave.stats.itemButtons[SLOT_A]].menuSlot) { - itemSlot = 0; + equipSlot = EQUIP_SLOT_A; } else { if (temp == gItemMetaData[gSave.stats.itemButtons[SLOT_B]].menuSlot) { - itemSlot = 1; + equipSlot = EQUIP_SLOT_B; } } - if (itemSlot == 2) { + if (equipSlot == EQUIP_SLOT_NONE) { return; } } - ForceEquipItem(itemID2, itemSlot); + ForceEquipItem(itemId2, equipSlot); } } -void ForceEquipItem(u32 itemID, u32 itemSlot) { +void ForceEquipItem(u32 itemId, u32 equipSlot) { u32 otherItem; - u32 otherItemIndex; + u32 otherItemSlot; u32 replacedItem; - if ((itemID - 1 < 0x1f) && (itemSlot < 2)) { - otherItemIndex = itemSlot == 0; - replacedItem = gSave.stats.itemButtons[itemSlot]; - otherItem = gSave.stats.itemButtons[otherItemIndex]; - if (gItemMetaData[otherItem].menuSlot == gItemMetaData[itemID].menuSlot) { + if ((itemId - 1 < 0x1f) && (equipSlot < EQUIP_SLOT_NONE)) { + otherItemSlot = equipSlot == EQUIP_SLOT_A; + replacedItem = gSave.stats.itemButtons[equipSlot]; + otherItem = gSave.stats.itemButtons[otherItemSlot]; + if (gItemMetaData[otherItem].menuSlot == gItemMetaData[itemId].menuSlot) { otherItem = replacedItem; } - gSave.stats.itemButtons[itemSlot] = itemID; - gSave.stats.itemButtons[otherItemIndex] = otherItem; + gSave.stats.itemButtons[equipSlot] = itemId; + gSave.stats.itemButtons[otherItemSlot] = otherItem; gUnk_0200AF00.unk_13 = 0x7f; gUnk_0200AF00.unk_14 = 0x7f; } } -u32 SetBottleContents(u32 itemID, u32 bottleIndex) { +u32 SetBottleContents(u32 itemId, u32 bottleIndex) { if (bottleIndex > 3) { bottleIndex = 0; for (bottleIndex = 0; gSave.stats.bottles[bottleIndex] != ITEM_BOTTLE_EMPTY;) { @@ -2536,7 +2537,7 @@ u32 SetBottleContents(u32 itemID, u32 bottleIndex) { return bottleIndex; } } - gSave.stats.bottles[bottleIndex] = itemID; + gSave.stats.bottles[bottleIndex] = itemId; return bottleIndex; } @@ -2614,7 +2615,7 @@ void EnableRandomDrops(void) { extern void sub_08000F14(s16*, const s16*, const s16*, const s16*); extern u32 sub_08000F2C(s16*, const s16*, const s16*, const s16*); -u32 CreateItemDrop(Entity* arg0, u32 itemID, u32 itemParameter); +u32 CreateItemDrop(Entity* arg0, u32 itemId, u32 itemParameter); u32 CreateRandomItemDrop(Entity* arg0, u32 arg1) { extern const u8 gUnk_080FE1B4[] /* = { ITEM_NONE, ITEM_RUPEE1, ITEM_RUPEE5, ITEM_RUPEE20, ITEM_HEART, ITEM_FAIRY, @@ -2717,11 +2718,11 @@ u32 CreateRandomItemDrop(Entity* arg0, u32 arg1) { return ITEM_NONE; } -u32 CreateItemDrop(Entity* arg0, u32 itemID, u32 itemParameter) { +u32 CreateItemDrop(Entity* arg0, u32 itemId, u32 itemParameter) { u32 adjustedParam = itemParameter; Entity* itemEntity; - switch (itemID) { + switch (itemId) { case ITEM_ENEMY_BEETLE: if (!GetInventoryValue(ITEM_SMITH_SWORD)) { return ITEM_NONE; @@ -2757,22 +2758,22 @@ u32 CreateItemDrop(Entity* arg0, u32 itemID, u32 itemParameter) { return ITEM_NONE; } - if (itemID != ITEM_KINSTONE) { - adjustedParam = itemID - ITEM_KINSTONE_GREEN; + if (itemId != ITEM_KINSTONE) { + adjustedParam = itemId - ITEM_KINSTONE_GREEN; rand = (Random() & 0x3f); adjustedParam = gUnk_080FE1DD[(rand + adjustedParam * 0x40)]; if (adjustedParam == 0) { - itemID = ITEM_NONE; + itemId = ITEM_NONE; } else { - itemID = ITEM_KINSTONE; + itemId = ITEM_KINSTONE; } } break; } } - if (itemID != ITEM_NONE) { - if (itemID != ITEM_ENEMY_BEETLE) { - itemEntity = CreateObject(GROUND_ITEM, itemID, adjustedParam); + if (itemId != ITEM_NONE) { + if (itemId != ITEM_ENEMY_BEETLE) { + itemEntity = CreateObject(GROUND_ITEM, itemId, adjustedParam); if (itemEntity != NULL) { if (arg0 == &gPlayerEntity) { itemEntity->timer = 1; @@ -2800,7 +2801,7 @@ u32 CreateItemDrop(Entity* arg0, u32 itemID, u32 itemParameter) { } } } - return itemID; + return itemId; } void Subtask_WorldEvent(void) { diff --git a/src/gba/m4a.c b/src/gba/m4a.c index b5e2e13e..e1f30b0e 100644 --- a/src/gba/m4a.c +++ b/src/gba/m4a.c @@ -1313,7 +1313,7 @@ void CgbSound(void) { if (channels->n4 & 0x80) { *nrx0ptr = 0x80; *nrx4ptr = channels->n4; - channels->n4 &= 0x7f; + channels->n4 &= ~0x80; } } else { envelopeStepTimeAndDir &= 0xf; diff --git a/src/interrupts.c b/src/interrupts.c index 84784698..33a7d5e7 100644 --- a/src/interrupts.c +++ b/src/interrupts.c @@ -1,14 +1,14 @@ -#include "global.h" -#include "sound.h" -#include "main.h" -#include "player.h" -#include "structures.h" -#include "save.h" -#include "message.h" #include "functions.h" -#include "screen.h" #include "gba/m4a.h" +#include "global.h" +#include "main.h" +#include "message.h" #include "object.h" +#include "player.h" +#include "save.h" +#include "screen.h" +#include "sound.h" +#include "structures.h" #include "ui.h" extern u8 gUnk_03003DE0; @@ -197,7 +197,7 @@ void PlayerUpdate(Entity* this) { else gPlayerState.flags &= ~PL_DRUGGED; - if (EntityIsDeleted(this) == 0) { + if (!EntityIsDeleted(this)) { if (gPlayerState.flags & PL_MOLDWORM_CAPTURED) { PutAwayItems(); if (gPlayerState.flags & PL_MOLDWORM_RELEASED) { @@ -218,7 +218,7 @@ void PlayerUpdate(Entity* this) { } sub_08078FB0(this); DrawEntity(this); - sub_0807A050(); + UpdatePlayerPalette(); } // Responsible for some life things like low health beep and initiating the death sequence @@ -234,7 +234,7 @@ static void HandlePlayerLife(Entity* this) { gPlayerState.flags &= ~(PL_FALLING | PL_CONVEYOR_PUSHED); if (gPlayerState.flags & PL_BURNING) - ResetPlayerItem(); + ResetActiveItems(); if ((gPlayerState.flags & PL_CLONING) && gPlayerState.chargeState.action == 0) DeleteClones(); if (sub_08079B24() == 0) @@ -309,7 +309,7 @@ static void HandlePlayerLife(Entity* this) { static void sub_080171F0(void) { if (gPlayerState.mobility != 0) - ResetPlayerItem(); + ResetActiveItems(); if (gPlayerState.field_0x14 != 0) gPlayerState.field_0x14--; if (gPlayerEntity.field_0x7a.HWORD != 0) @@ -331,7 +331,7 @@ static void sub_080171F0(void) { gPlayerState.keepFacing &= ~0x80; gPlayerState.mobility = 0; gPlayerState.speed_modifier = 0; - gPlayerState.field_0xaa = 0; + gPlayerState.attachedBeetleCount = 0; MemClear(&gCarriedEntity, sizeof(gCarriedEntity)); gPlayerEntity.spriteOffsetY = gPlayerState.spriteOffsetY; gPlayerState.spriteOffsetY = 0; diff --git a/src/item.c b/src/item.c index 3e6cbb2d..1fa970e3 100644 --- a/src/item.c +++ b/src/item.c @@ -3,14 +3,40 @@ // TODO - How does this relate to PlayerItemFunctions? Is this just a lookup table? void (*const gItemFunctions[])(ItemBehavior*, u32) = { - - ItemDebug, ItemSword, ItemSword, ItemSword, ItemSword, ItemSword, ItemSword, - ItemBomb, ItemBomb, ItemBow, ItemBow, ItemBoomerang, ItemBoomerang, ItemShield, - ItemShield, ItemLantern, ItemLantern, ItemGustJar, ItemPacciCane, ItemMoleMitts, ItemRocsCape, - ItemPegasusBoots, ItemDebug, ItemOcarina, ItemDebug, ItemDebug, ItemDebug, ItemTryPickupObject, - ItemJarEmpty, ItemJarEmpty, ItemJarEmpty, ItemJarEmpty, + [ITEM_NONE] = ItemDebug, + [ITEM_SMITH_SWORD] = ItemSword, + [ITEM_GREEN_SWORD] = ItemSword, + [ITEM_RED_SWORD] = ItemSword, + [ITEM_BLUE_SWORD] = ItemSword, + [ITEM_UNUSED_SWORD] = ItemSword, + [ITEM_FOURSWORD] = ItemSword, + [ITEM_BOMBS] = ItemBomb, + [ITEM_REMOTE_BOMBS] = ItemBomb, + [ITEM_BOW] = ItemBow, + [ITEM_LIGHT_ARROW] = ItemBow, + [ITEM_BOOMERANG] = ItemBoomerang, + [ITEM_MAGIC_BOOMERANG] = ItemBoomerang, + [ITEM_SHIELD] = ItemShield, + [ITEM_MIRROR_SHIELD] = ItemShield, + [ITEM_LANTERN_OFF] = ItemLantern, + [ITEM_LANTERN_ON] = ItemLantern, + [ITEM_GUST_JAR] = ItemGustJar, + [ITEM_PACCI_CANE] = ItemPacciCane, + [ITEM_MOLE_MITTS] = ItemMoleMitts, + [ITEM_ROCS_CAPE] = ItemRocsCape, + [ITEM_PEGASUS_BOOTS] = ItemPegasusBoots, + [ITEM_FIRE_ROD] = ItemDebug, + [ITEM_OCARINA] = ItemOcarina, + [ITEM_ORB_GREEN] = ItemDebug, + [ITEM_ORB_BLUE] = ItemDebug, + [ITEM_ORB_RED] = ItemDebug, + [ITEM_TRY_PICKUP_OBJECT] = ItemTryPickupObject, + [ITEM_BOTTLE1] = ItemJarEmpty, + [ITEM_BOTTLE2] = ItemJarEmpty, + [ITEM_BOTTLE3] = ItemJarEmpty, + [ITEM_BOTTLE4] = ItemJarEmpty, }; -void sub_080752E8(ItemBehavior* behavior, u32 idx) { - gItemFunctions[behavior->behaviorID](behavior, idx); +void ExecuteItemFunction(ItemBehavior* behavior, u32 index) { + gItemFunctions[behavior->behaviorId](behavior, index); } diff --git a/src/item/itemBomb.c b/src/item/itemBomb.c index ce5358a4..74264e17 100644 --- a/src/item/itemBomb.c +++ b/src/item/itemBomb.c @@ -10,14 +10,14 @@ void sub_08076488(ItemBehavior*, u32); void sub_08076518(ItemBehavior*, u32); void sub_080765E0(ItemBehavior*, u32); -void ItemBomb(ItemBehavior* this, u32 idx) { +void ItemBomb(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08075FF8, NULL, sub_08076488, sub_08076518, sub_080765E0, }; - stateFuncs[this->stateID](this, idx); + stateFuncs[this->stateID](this, index); } -void sub_08075FF8(ItemBehavior* this, u32 idx) { +void sub_08075FF8(ItemBehavior* this, u32 index) { static const s8 gUnk_0811BDAC[] = { 0, -8, 4, -1, 0, 2, -4, -1, }; @@ -28,13 +28,13 @@ void sub_08075FF8(ItemBehavior* this, u32 idx) { s32 x; s32 y; - if ((gPlayerState.jump_status | gPlayerState.field_0x3[1]) == 0) { + if ((gPlayerState.jump_status | gPlayerState.attack_status) == 0) { bombCount = 0; for (entity = FindEntityByID(PLAYER_ITEM, PLAYER_ITEM_BOMB, 2); entity != NULL; entity = FindNextDuplicateID(entity, 2)) { bombCount++; } - maxBombs = this->behaviorID == 7 ? 3 : 1; + maxBombs = this->behaviorId == 7 ? 3 : 1; if (maxBombs > bombCount) { entity = CreatePlayerItemWithParent(this, PLAYER_ITEM_BOMB); if (entity != NULL) { @@ -45,60 +45,5 @@ void sub_08075FF8(ItemBehavior* this, u32 idx) { } } } - DeletePlayerItem(this, idx); -} - -void sub_08076088(ItemBehavior* this, Entity* param_2, u32 param_3) { - if (param_2 != NULL) { - if ((param_2->carryFlags & 1) != 0) { - return; - } - param_2->action = 2; - param_2->subAction = param_2->carryFlags & 1; - } - - this->field_0x18 = param_2; - if ((gPlayerState.flags & PL_NO_CAP)) { - sub_08077DF4(this, 0x928); - } else { - sub_08077DF4(this, 0x338); - } - gPlayerState.heldObject = 3; - gPlayerState.framestate = PL_STATE_HOLD; - this->stateID = 2; - this->field_0xf = 0xf; - if ((gPlayerEntity.field_0x78.HALF.HI & 0x80)) { - gPlayerEntity.field_0x78.HALF.HI = 0; - COLLISION_ON(&gPlayerEntity); - gPlayerState.heldObject = 4; - gPlayerState.keepFacing = ~(8 >> param_3) & gPlayerState.keepFacing; - gPlayerState.field_0xa = ~(8 >> param_3) & gPlayerState.field_0xa; - this->stateID = 3; - this->field_0xf = 0; - } else { - gPlayerState.field_0xa |= (8 >> param_3); - gPlayerState.keepFacing |= (8 >> param_3); - } - - param_2 = CreatePlayerItemWithParent(this, PLAYER_ITEM_13); - if (param_2 == NULL) { - PlayerCancelHoldItem(this, param_3); - } else { - Entity* playerEnt = &gPlayerEntity; - *(Entity**)&playerEnt->field_0x74 = param_2; - playerEnt->subtimer = 0; - param_2->child = this->field_0x18; - param_2->carryFlags = playerEnt->carryFlags; - param_2->parent = (Entity*)this; - this->field_0x18 = param_2; - param_2->type2 = this->field_0x2[1]; - param_2->timer = this->timer; - param_2->subtimer = this->subtimer; - if ((this->field_0x18->carryFlags & 0xf0) == 0x10) { - this->timer = 8; - } else { - this->timer = 0; - } - SoundReq(SFX_PLY_LIFT); - } + DeleteItemBehavior(this, index); } diff --git a/src/item/itemBoomerang.c b/src/item/itemBoomerang.c index 34475d09..64c78d87 100644 --- a/src/item/itemBoomerang.c +++ b/src/item/itemBoomerang.c @@ -4,29 +4,29 @@ void sub_08075D2C(ItemBehavior*, u32); void sub_08075D88(ItemBehavior*, u32); -void ItemBoomerang(ItemBehavior* this, u32 idx) { +void ItemBoomerang(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08075D2C, sub_08075D88, }; - stateFuncs[this->stateID](this, idx); + stateFuncs[this->stateID](this, index); } -void sub_08075D2C(ItemBehavior* this, u32 idx) { - if (((gPlayerState.field_0x3[1] & 8) == 0) && (sub_08077C94(this, this->behaviorID) == NULL)) { - this->field_0x9 |= 0xf; +void sub_08075D2C(ItemBehavior* this, u32 index) { + if (((gPlayerState.attack_status & 8) == 0) && (FindPlayerItemForItem(this, this->behaviorId) == NULL)) { + this->priority |= 0xf; sub_0806F948(&gPlayerEntity); - sub_08077C0C(this, 0xb); - sub_08077D38(this, idx); - gPlayerState.field_0x3[1] |= 8; + CreatePlayerItemIfNotExists(this, ITEM_BOOMERANG); + sub_08077D38(this, index); + gPlayerState.attack_status |= 8; } else { - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } -void sub_08075D88(ItemBehavior* this, u32 idx) { - if ((gPlayerState.field_0x3[1] & 0x80) == 0) { - if (((this->behaviorID == 0xc) && ((gPlayerState.field_0xa & 0x80) != 0)) && ((this->playerFrame & 2) != 0)) { +void sub_08075D88(ItemBehavior* this, u32 index) { + if ((gPlayerState.attack_status & 0x80) == 0) { + if (((this->behaviorId == 0xc) && ((gPlayerState.field_0xa & 0x80) != 0)) && ((this->playerFrame & 2) != 0)) { ResetPlayerVelocity(); return; } @@ -35,5 +35,5 @@ void sub_08075D88(ItemBehavior* this, u32 idx) { return; } } - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } diff --git a/src/item/itemBow.c b/src/item/itemBow.c index 8e916091..7714734f 100644 --- a/src/item/itemBow.c +++ b/src/item/itemBow.c @@ -9,81 +9,78 @@ void sub_08075F38(ItemBehavior*, u32); void sub_08075F84(ItemBehavior*, u32); void sub_08075D88(ItemBehavior*, u32); -void ItemBow(ItemBehavior* this, u32 idx) { +void ItemBow(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08075DF4, sub_08075E40, sub_08075EC0, sub_08075F38, sub_08075F84, sub_08075D88, }; - stateFuncs[this->stateID](this, idx); + stateFuncs[this->stateID](this, index); } -void sub_08075DF4(ItemBehavior* this, u32 idx) { - if ((gPlayerState.field_0x3[1] & 8) == 0) { - this->field_0x9 |= 0x80; +void sub_08075DF4(ItemBehavior* this, u32 index) { + if ((gPlayerState.attack_status & 8) == 0) { + this->priority |= 0x80; sub_0806F948(&gPlayerEntity); sub_08077BB8(this); - sub_08077D38(this, idx); + sub_08077D38(this, index); gPlayerState.field_0x1f[2] = 1; } else { - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } -void sub_08075E40(ItemBehavior* this, u32 idx) { - u8 bVar1; - +void sub_08075E40(ItemBehavior* this, u32 index) { if (gPlayerState.field_0x1f[2] != 0) { - bVar1 = gPlayerState.field_0x3[1] & 0x80; - if (bVar1 == 0) { + if ((gPlayerState.attack_status & 0x80) == 0) { UpdateItemAnim(this); if ((this->playerFrame & 0x80) != 0) { this->stateID = 2; - this->field_0x9 &= ~0x80; + this->priority &= ~0x80; if (gSave.stats.arrowCount != 0) { - this->field_0xf = bVar1; - gPlayerState.field_0xa &= ~(8 >> idx); + this->animPriority = 0; + gPlayerState.field_0xa &= ~(8 >> index); } } return; } } gPlayerState.field_0x1f[2] = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } -void sub_08075EC0(ItemBehavior* this, u32 idx) { +void sub_08075EC0(ItemBehavior* this, u32 index) { u8 arrowCount; s32 iVar2; arrowCount = gSave.stats.arrowCount; - iVar2 = sub_08077EFC(this); + iVar2 = IsItemActive(this); if (iVar2 != 0 && arrowCount != 0) { - if (((gPlayerState.field_0x3[1] & 0x80) != 0) || (gPlayerState.field_0x1f[2] == 0)) { + if (((gPlayerState.attack_status & 0x80) != 0) || (gPlayerState.field_0x1f[2] == 0)) { gPlayerState.field_0x1f[2] = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } else { - gPlayerState.field_0xa = (8 >> idx) | gPlayerState.field_0xa; - sub_08077DF4(this, 0x27c); - this->field_0xf = 0xf; - this->field_0x9 |= 0xf; + gPlayerState.field_0xa = (8 >> index) | gPlayerState.field_0xa; + SetItemAnim(this, 0x27c); + this->animPriority = 0xf; + this->priority |= 0xf; this->stateID = 3; } } -void sub_08075F38(ItemBehavior* this, u32 idx) { - if (((gPlayerState.field_0x3[1] & 0x80) == 0) && (gPlayerState.field_0x1f[2] != 0)) { +void sub_08075F38(ItemBehavior* this, u32 index) { + if (((gPlayerState.attack_status & 0x80) == 0) && (gPlayerState.field_0x1f[2] != 0)) { UpdateItemAnim(this); if ((this->playerFrame & 1) != 0) { this->stateID = 4; } } else { gPlayerState.field_0x1f[2] = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } -void sub_08075F84(ItemBehavior* this, u32 idx) { - if (((gPlayerState.field_0x3[1] & 0x80) == 0) && (gPlayerState.field_0x1f[2] != 0)) { +void sub_08075F84(ItemBehavior* this, u32 index) { + if (((gPlayerState.attack_status & 0x80) == 0) && (gPlayerState.field_0x1f[2] != 0)) { if (GetInventoryValue(ITEM_ARROW_BUTTERFLY) == 1) { sub_08077E3C(this, 5); } else { @@ -94,5 +91,5 @@ void sub_08075F84(ItemBehavior* this, u32 idx) { } } gPlayerState.field_0x1f[2] = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } diff --git a/src/item/itemDebug.c b/src/item/itemDebug.c index e0d9f2f9..0cfd333b 100644 --- a/src/item/itemDebug.c +++ b/src/item/itemDebug.c @@ -1,9 +1,9 @@ #include "item.h" -extern Entity* sub_08077BD4(ItemBehavior*); -extern void DeletePlayerItem(ItemBehavior*, u32); +extern Entity* CreatePlayerItemForItemIfNotExists(ItemBehavior*); +extern void DeleteItemBehavior(ItemBehavior*, u32); -void ItemDebug(ItemBehavior* beh, u32 idx) { - sub_08077BD4(beh); - DeletePlayerItem(beh, idx); +void ItemDebug(ItemBehavior* this, u32 index) { + CreatePlayerItemForItemIfNotExists(this); + DeleteItemBehavior(this, index); } diff --git a/src/item/itemGustJar.c b/src/item/itemGustJar.c index c26314e1..c567f197 100644 --- a/src/item/itemGustJar.c +++ b/src/item/itemGustJar.c @@ -4,41 +4,41 @@ #include "functions.h" #include "playeritem.h" -void (*const ItemGustJar_StateFunctions[])(ItemBehavior* beh, u32); +void (*const ItemGustJar_StateFunctions[])(ItemBehavior* this, u32); -void ItemGustJar(ItemBehavior* this, u32 idx) { +void ItemGustJar(ItemBehavior* this, u32 index) { gPlayerState.framestate = PL_STATE_GUSTJAR; - ItemGustJar_StateFunctions[this->stateID](this, idx); + ItemGustJar_StateFunctions[this->stateID](this, index); } -void sub_08076DF4(ItemBehavior* this, u32 idx) { - if (sub_0807A894(&gPlayerEntity) != 0x29 && gPlayerState.floor_type != SURFACE_DOOR && +void sub_08076DF4(ItemBehavior* this, u32 index) { + if (GetCollisionTileInFront(&gPlayerEntity) != 0x29 && gPlayerState.floor_type != SURFACE_DOOR && gPlayerState.floor_type != SURFACE_DOOR_13 && gPlayerState.jump_status == 0) { - sub_08077D38(this, idx); + sub_08077D38(this, index); this->timer = 0; this->playerAnimationState = gPlayerEntity.animationState; - this->field_0x9 |= 0x80; - this->field_0x9++; + this->priority |= 0x80; + this->priority++; gPlayerState.gustJarSpeed = 1; *(u32*)&gPlayerEntity.field_0x74 = 0; gPlayerState.field_0x1c = 1; sub_08077BB8(this); } else { - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } -void sub_08076E60(ItemBehavior* this, u32 idx) { +void sub_08076E60(ItemBehavior* this, u32 index) { Entity* playerItem; if ((gPlayerState.field_0x1c & 0xf) == 0) { - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } if ((this->playerFrame & 0x80) != 0) { this->stateID = 2; - sub_08077DF4(this, 0x504); - gPlayerState.field_0xa = gPlayerState.field_0xa & ~(8 >> idx); - playerItem = CreatePlayerItem(PLAYER_ITEM_10, 0, 0, 0); + SetItemAnim(this, 0x504); + gPlayerState.field_0xa = gPlayerState.field_0xa & ~(8 >> index); + playerItem = CreatePlayerItem(PLAYER_ITEM_GUST, 0, 0, 0); if (playerItem != NULL) { playerItem->parent = &gPlayerEntity; } @@ -47,14 +47,14 @@ void sub_08076E60(ItemBehavior* this, u32 idx) { } } -void sub_08076EC8(ItemBehavior* this, u32 idx) { +void sub_08076EC8(ItemBehavior* this, u32 index) { if ((gPlayerState.field_0x1c & 0xf) == 0) { - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); return; } - if (sub_08077EFC(this)) { - u32 val; + if (IsItemActive(this)) { + u32 animIndex; if (this->timer > 0xef) { gPlayerState.gustJarSpeed = 3; } else if (++this->timer > 0x77) { @@ -64,17 +64,17 @@ void sub_08076EC8(ItemBehavior* this, u32 idx) { } if (gPlayerEntity.subAction == 0x1b) { - val = 0x524; + animIndex = 0x524; } else { - if (gPlayerState.field_0xd & 0x80) { - val = 0x504; + if (gPlayerState.direction & 0x80) { + animIndex = 0x504; } else { - val = 0x518; + animIndex = 0x518; } } - if (val != *(u16*)&this->field_0x10) { - sub_08077DF4(this, val); + if (animIndex != this->animIndex) { + SetItemAnim(this, animIndex); } else { UpdateItemAnim(this); } @@ -82,10 +82,10 @@ void sub_08076EC8(ItemBehavior* this, u32 idx) { } this->stateID++; - gPlayerState.field_0xa |= 8 >> idx; + gPlayerState.field_0xa |= 8 >> index; } -void sub_08076F64(ItemBehavior* this, u32 idx) { +void sub_08076F64(ItemBehavior* this, u32 index) { Entity* item; Entity* player; switch (gPlayerState.field_0x1c & 0xf) { @@ -98,21 +98,21 @@ void sub_08076F64(ItemBehavior* this, u32 idx) { player = &gPlayerEntity; *(u32*)&player->field_0x74 = 0; gPlayerState.field_0x1c = 1; - gPlayerState.field_0xa &= ~(8 >> idx); + gPlayerState.field_0xa &= ~(8 >> index); this->stateID = 2; - sub_08077DF4(this, 0x504); - item = CreatePlayerItem(PLAYER_ITEM_10, 0, 0, 0); + SetItemAnim(this, 0x504); + item = CreatePlayerItem(PLAYER_ITEM_GUST, 0, 0, 0); if (item) { item->parent = player; } return; } else { gPlayerState.field_0x1c = 6; - sub_08077DF4(this, 0x510); + SetItemAnim(this, 0x510); return; } } else { - if (sub_08077EFC(this)) { + if (IsItemActive(this)) { this->subtimer = 1; } @@ -130,7 +130,7 @@ void sub_08076F64(ItemBehavior* this, u32 idx) { case 3: gPlayerState.field_0x1c = 4; case 4: - if (sub_08077EFC(this)) { + if (IsItemActive(this)) { this->subtimer = 1; } @@ -139,7 +139,7 @@ void sub_08076F64(ItemBehavior* this, u32 idx) { gPlayerState.field_0x1c = 5; gPlayerEntity.field_0x70.WORD = 0; if (gPlayerState.gustJarSpeed) { - CreatePlayerItem(PLAYER_ITEM_11, 0, 0, 0); + CreatePlayerItem(PLAYER_ITEM_GUST_BIG, 0, 0, 0); } } @@ -155,7 +155,7 @@ void sub_08076F64(ItemBehavior* this, u32 idx) { return; break; case 7: - sub_08077DF4(this, 0x514); + SetItemAnim(this, 0x514); gPlayerState.field_0x1c = 3; gPlayerState.gustJarSpeed = 0; return; @@ -163,17 +163,17 @@ void sub_08076F64(ItemBehavior* this, u32 idx) { case 2: default: gPlayerState.field_0x1c = 3; - sub_08077DF4(this, 0x514); + SetItemAnim(this, 0x514); return; case 0: break; } gPlayerState.field_0x1c = 0; gPlayerEntity.field_0x70.WORD = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } -void (*const ItemGustJar_StateFunctions[])(ItemBehavior* beh, u32) = { +void (*const ItemGustJar_StateFunctions[])(ItemBehavior*, u32) = { sub_08076DF4, sub_08076E60, sub_08076EC8, diff --git a/src/item/itemJarEmpty.c b/src/item/itemJarEmpty.c index ff2e1c61..60997922 100644 --- a/src/item/itemJarEmpty.c +++ b/src/item/itemJarEmpty.c @@ -7,27 +7,27 @@ void sub_08077618(ItemBehavior*, u32); void sub_08077640(ItemBehavior*, u32); void sub_0807766C(ItemBehavior*, u32); -void ItemJarEmpty(ItemBehavior* this, u32 idx) { +void ItemJarEmpty(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08077534, sub_08077618, sub_08077640, sub_0807766C, }; - stateFuncs[this->stateID](this, idx); + stateFuncs[this->stateID](this, index); } -void sub_08077534(ItemBehavior* this, u32 idx) { +void sub_08077534(ItemBehavior* this, u32 index) { u32 tmp; - sub_08077D38(this, idx); + sub_08077D38(this, index); sub_0806F948(&gPlayerEntity); sub_08077BB8(this); - this->field_0x9 |= 0xf; - tmp = this->behaviorID; + this->priority |= 0xf; + tmp = this->behaviorId; this->timer = gSave.filler86[tmp + 0x14]; switch (this->timer) { case 0x20: - sub_08077DF4(this, 0x614); + SetItemAnim(this, 0x614); return; case 0x21: case 0x22: @@ -43,40 +43,40 @@ void sub_08077534(ItemBehavior* this, u32 idx) { this->stateID = 3; gPlayerEntity.animationState = 4; gPlayerEntity.spriteSettings.flipX = 0; - sub_08077DF4(this, 0x2df); + SetItemAnim(this, 0x2df); break; case 0x2f: case 0x30: case 0x31: default: this->stateID = 3; - sub_08077DF4(this, 0x610); + SetItemAnim(this, 0x610); break; } gPlayerEntity.flags &= ~ENT_COLLIDE; } -void sub_08077618(ItemBehavior* this, u32 idx) { +void sub_08077618(ItemBehavior* this, u32 index) { if ((this->playerFrame & 0x80) != 0) { - sub_08077DF4(this, 0x618); - this->stateID += 1; + SetItemAnim(this, 0x618); + this->stateID++; } else { UpdateItemAnim(this); } } -void sub_08077640(ItemBehavior* this, u32 idx) { +void sub_08077640(ItemBehavior* this, u32 index) { UpdateItemAnim(this); if ((this->playerFrame & 0x80) != 0) { gPlayerEntity.flags |= ENT_COLLIDE; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } -void sub_0807766C(ItemBehavior* this, u32 idx) { +void sub_0807766C(ItemBehavior* this, u32 index) { UpdateItemAnim(this); if ((this->playerFrame & 0x80) != 0) { gPlayerEntity.flags |= ENT_COLLIDE; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } diff --git a/src/item/itemLantern.c b/src/item/itemLantern.c index 758b6244..4e9902a0 100644 --- a/src/item/itemLantern.c +++ b/src/item/itemLantern.c @@ -5,41 +5,41 @@ #include "game.h" extern s8 gUnk_08126EEC[]; -extern Entity* sub_08077BD4(ItemBehavior*); +extern Entity* CreatePlayerItemForItemIfNotExists(ItemBehavior*); extern void sub_0807AB44(Entity*, s32, s32); void sub_08075A0C(ItemBehavior*, u32); void sub_08075ADC(ItemBehavior*, u32); void sub_08075B54(ItemBehavior*, u32); void sub_08075C9C(ItemBehavior*, u32); -void ItemLantern(ItemBehavior* this, u32 idx) { +void ItemLantern(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08075A0C, sub_08075ADC, sub_08075B54, sub_08075C9C, }; - stateFuncs[this->stateID](this, idx); + stateFuncs[this->stateID](this, index); } -void sub_08075A0C(ItemBehavior* this, u32 idx) { +void sub_08075A0C(ItemBehavior* this, u32 index) { Entity* object; - u32 itemSlot; + EquipSlot equipSlot; s8* tmp; - itemSlot = IsItemEquipped(this->behaviorID); + equipSlot = IsItemEquipped(this->behaviorId); if (gPlayerState.heldObject != 0 || gPlayerState.queued_action == PLAYER_ROLL || gPlayerState.jump_status != 0 || gPlayerState.item != NULL || (gPlayerState.flags & PL_MINISH) != 0) { - ForceEquipItem(ITEM_LANTERN_OFF, itemSlot); + ForceEquipItem(ITEM_LANTERN_OFF, equipSlot); gPlayerState.flags &= ~PL_USE_LANTERN; - ForceEquipItem(ITEM_LANTERN_OFF, itemSlot); - DeletePlayerItem(this, idx); + ForceEquipItem(ITEM_LANTERN_OFF, equipSlot); + DeleteItemBehavior(this, index); } else { - this->field_0x9 |= 0x80; - sub_08077D38(this, idx); - sub_08077BD4(this); + this->priority |= 0x80; + sub_08077D38(this, index); + CreatePlayerItemForItemIfNotExists(this); sub_0806F948(&gPlayerEntity); - this->behaviorID = 0x10; - ForceEquipItem(ITEM_LANTERN_ON, itemSlot); + this->behaviorId = 0x10; + ForceEquipItem(ITEM_LANTERN_ON, equipSlot); tmp = &gUnk_08126EEC[gPlayerEntity.animationState & 6]; object = CreateObjectWithParent(&gPlayerEntity, LAMP_PARTICLE, 1, 0); if (object != NULL) { @@ -50,7 +50,7 @@ void sub_08075A0C(ItemBehavior* this, u32 idx) { } } -void sub_08075ADC(ItemBehavior* this, u32 idx) { +void sub_08075ADC(ItemBehavior* this, u32 index) { u32 bVar1; if ( @@ -59,11 +59,11 @@ void sub_08075ADC(ItemBehavior* this, u32 idx) { #endif (this->playerFrame & 1) == 0 || (gPlayerState.flags & (PL_DISABLE_ITEMS | PL_CAPTURED)) != 0 || sub_08079D48() == 0) { - this->field_0xf = 0; + this->animPriority = 0; this->stateID++; gPlayerState.flags |= PL_USE_LANTERN; - bVar1 = 8 >> idx; - gPlayerState.field_0x3[1] = gPlayerState.field_0x3[1] & ~((bVar1 << 4) | bVar1); + bVar1 = 8 >> index; + gPlayerState.attack_status &= ~((bVar1 << 4) | bVar1); bVar1 = ~bVar1; gPlayerState.field_0xa = bVar1 & gPlayerState.field_0xa; gPlayerState.keepFacing = bVar1 & gPlayerState.keepFacing; @@ -73,18 +73,19 @@ void sub_08075ADC(ItemBehavior* this, u32 idx) { } } -void sub_08075B54(ItemBehavior* this, u32 idx) { +void sub_08075B54(ItemBehavior* this, u32 index) { u32 bVar1; - u32 itemSlot; + EquipSlot equipSlot; Entity* object; s8* tmp; if ((gPlayerState.flags & (PL_CAPTURED | PL_DISABLE_ITEMS)) == 0) { - itemSlot = IsItemEquipped(this->behaviorID); - if (!(((sub_08077F10(this) == 0) && (itemSlot < 2)) || (gPlayerState.jump_status != 0))) { - ForceEquipItem(ITEM_LANTERN_OFF, itemSlot); + equipSlot = IsItemEquipped(this->behaviorId); + if (!(((IsItemActivatedThisFrame(this) == 0) && (equipSlot < EQUIP_SLOT_NONE)) || + (gPlayerState.jump_status != 0))) { + ForceEquipItem(ITEM_LANTERN_OFF, equipSlot); gPlayerState.flags &= ~PL_USE_LANTERN; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); SoundReq(SFX_ITEM_LANTERN_OFF); } else { if (((gPlayerState.queued_action != PLAYER_ROLL) && (gPlayerEntity.frameIndex < 0x37)) && @@ -94,7 +95,7 @@ void sub_08075B54(ItemBehavior* this, u32 idx) { if ((gPlayerState.jump_status == 0) && (sub_080B1BA4(TILE(gPlayerEntity.x.HALF.HI + tmp[0], gPlayerEntity.y.HALF.HI + tmp[1]), gPlayerEntity.collisionLayer, 0x40) != 0)) { - this->field_0xf = 0xf; + this->animPriority = 0xf; this->stateID++; gPlayerEntity.field_0x7a.HWORD = 2; object = CreateObjectWithParent(&gPlayerEntity, LAMP_PARTICLE, 1, 0); @@ -103,8 +104,8 @@ void sub_08075B54(ItemBehavior* this, u32 idx) { object->x.HALF.HI = tmp[0] + object->x.HALF.HI; object->y.HALF.HI = tmp[1] + object->y.HALF.HI; } - sub_08077DF4(this, 0x60c); - bVar1 = (8 >> (idx)); + SetItemAnim(this, 0x60c); + bVar1 = (8 >> (index)); gPlayerState.field_0xa |= bVar1; gPlayerState.keepFacing |= bVar1; } @@ -113,7 +114,7 @@ void sub_08075B54(ItemBehavior* this, u32 idx) { } } -void sub_08075C9C(ItemBehavior* this, u32 idx) { +void sub_08075C9C(ItemBehavior* this, u32 index) { s8* tmp; UpdateItemAnim(this); @@ -122,10 +123,10 @@ void sub_08075C9C(ItemBehavior* this, u32 idx) { sub_0807AB44(&gPlayerEntity, tmp[0], tmp[1]); } if ((this->playerFrame & 0x80) != 0) { - this->field_0xf = 0; + this->animPriority = 0; this->stateID--; - gPlayerState.field_0xa = (~(8 >> idx)) & gPlayerState.field_0xa; - gPlayerState.keepFacing = (~(8 >> idx)) & gPlayerState.keepFacing; + gPlayerState.field_0xa = (~(8 >> index)) & gPlayerState.field_0xa; + gPlayerState.keepFacing = (~(8 >> index)) & gPlayerState.keepFacing; } else { gPlayerEntity.field_0x7a.HWORD++; } diff --git a/src/item/itemMoleMitts.c b/src/item/itemMoleMitts.c index d3a938a6..ee3aaa1b 100644 --- a/src/item/itemMoleMitts.c +++ b/src/item/itemMoleMitts.c @@ -14,27 +14,27 @@ void sub_080771C8(ItemBehavior*, u32); void sub_080772A8(ItemBehavior*, u32); void sub_08077448(ItemBehavior*, u32); -void ItemMoleMitts(ItemBehavior* this, u32 idx) { +void ItemMoleMitts(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08077130, sub_080771C8, sub_080772A8, sub_08077448, }; - stateFuncs[this->stateID](this, idx); + stateFuncs[this->stateID](this, index); } -void sub_08077130(ItemBehavior* this, u32 idx) { +void sub_08077130(ItemBehavior* this, u32 index) { s32 iVar1; if (gPlayerState.jump_status == 0) { - sub_08077D38(this, idx); + sub_08077D38(this, index); gPlayerState.moleMittsState = 1; - this->field_0x9 |= 0x80; + this->priority |= 0x80; iVar1 = sub_080774A0(); if (iVar1 != 0) { if (this->timer == 0) { - sub_08077DF4(this, 0x50c); + SetItemAnim(this, 0x50c); this->stateID = 2; if (iVar1 == 0x56) { if ((gPlayerEntity.animationState & 2) != 0) { @@ -45,16 +45,16 @@ void sub_08077130(ItemBehavior* this, u32 idx) { } } } else { - sub_08077DF4(this, 0x508); + SetItemAnim(this, 0x508); this->stateID = 1; } } else { - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); gPlayerState.moleMittsState = 0; } } -void sub_080771C8(ItemBehavior* this, u32 idx) { +void sub_080771C8(ItemBehavior* this, u32 index) { static const u8 gUnk_0811BE14[] = { 0x1, 0x12, @@ -63,7 +63,7 @@ void sub_080771C8(ItemBehavior* this, u32 idx) { UpdateItemAnim(this); if ((this->playerFrame & 0x80) != 0) { - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); gPlayerState.moleMittsState = 0; } else { if (((this->playerFrame & 0x20) != 0) && (this->subtimer == 0xff)) { @@ -71,7 +71,7 @@ void sub_080771C8(ItemBehavior* this, u32 idx) { } if ((this->playerFrame & 0x10) != 0) { if (sub_0800875A(&gPlayerEntity, 0xd, this) == 0) { - sub_08077DF4(this, 0x520); + SetItemAnim(this, 0x520); this->stateID = 3; SoundReq(SFX_107); } else { @@ -95,7 +95,7 @@ void sub_080771C8(ItemBehavior* this, u32 idx) { } } -void sub_080772A8(ItemBehavior* this, u32 idx) { +void sub_080772A8(ItemBehavior* this, u32 index) { static const s16 gUnk_0811BE16[] = { 0, 0xc0, @@ -104,7 +104,7 @@ void sub_080772A8(ItemBehavior* this, u32 idx) { }; Entity* effect; - if (((this->playerFrame & 8) != 0) && sub_08077F10(this)) { + if (((this->playerFrame & 8) != 0) && IsItemActivatedThisFrame(this)) { this->timer = 1; } if (GetInventoryValue(ITEM_DIG_BUTTERFLY) == 1) { @@ -131,7 +131,7 @@ void sub_080772A8(ItemBehavior* this, u32 idx) { return; } } - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); gPlayerState.moleMittsState = 0; } else { if ((this->playerFrame & 0x60) != 0) { @@ -140,7 +140,7 @@ void sub_080772A8(ItemBehavior* this, u32 idx) { SoundReq(SFX_108); CreateObjectWithParent(&gPlayerEntity, MOLE_MITTS_PARTICLE, this->playerFrame, 0); } else { - sub_08077DF4(this, 0x51c); + SetItemAnim(this, 0x51c); effect = CreateFx(&gPlayerEntity, FX_STARS_STRIKE, 0); if (effect != NULL) { effect->animationState = this->playerAnimationState; @@ -160,7 +160,7 @@ void sub_080772A8(ItemBehavior* this, u32 idx) { } } -void sub_08077448(ItemBehavior* this, u32 idx) { +void sub_08077448(ItemBehavior* this, u32 index) { gPlayerEntity.direction = gPlayerEntity.animationState << 2 ^ 0x10; gPlayerEntity.speed = 0x100; if (((this->playerFrame & 1) != 0) && (this->field_0x5 != 0)) { @@ -169,7 +169,7 @@ void sub_08077448(ItemBehavior* this, u32 idx) { UpdateItemAnim(this); if ((this->playerFrame & 0x80) != 0) { gPlayerState.moleMittsState = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } diff --git a/src/item/itemOcarina.c b/src/item/itemOcarina.c index a3310c7b..e4b2ad0e 100644 --- a/src/item/itemOcarina.c +++ b/src/item/itemOcarina.c @@ -7,20 +7,20 @@ extern void CreateBird(Entity*); void OcarinaUse(ItemBehavior*, u32); void OcarinaUpdate(ItemBehavior*, u32); -void ItemOcarina(ItemBehavior* this, u32 idx) { +void ItemOcarina(ItemBehavior* this, u32 index) { static void (*const gOcarinaStates[])(ItemBehavior*, u32) = { OcarinaUse, OcarinaUpdate, }; - gOcarinaStates[this->stateID](this, idx); - gPlayerEntity.field_0x7a.HWORD += 1; + gOcarinaStates[this->stateID](this, index); + gPlayerEntity.field_0x7a.HWORD++; } -void OcarinaUse(ItemBehavior* this, u32 idx) { +void OcarinaUse(ItemBehavior* this, u32 index) { if (gPlayerState.queued_action == PLAYER_ROLL) { - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } else { - this->field_0x9 |= 0xf; + this->priority |= 0xf; gPlayerEntity.animationState = 0x04; gPlayerEntity.spriteSettings.flipX = 0; gPlayerEntity.flags &= ~ENT_COLLIDE; @@ -28,17 +28,16 @@ void OcarinaUse(ItemBehavior* this, u32 idx) { gPlayerState.flags |= PL_USE_OCARINA; gPlayerState.field_0x27[0] = -1; gPauseMenuOptions.disabled = 1; - gPlayerState.field_0xa = (8 >> idx) | gPlayerState.field_0xa; - gPlayerState.keepFacing = (8 >> idx) | gPlayerState.keepFacing; + gPlayerState.field_0xa = (8 >> index) | gPlayerState.field_0xa; + gPlayerState.keepFacing = (8 >> index) | gPlayerState.keepFacing; ResetPlayerVelocity(); - sub_08077D38(this, idx); + sub_08077D38(this, index); SoundReq(SFX_216); SetPlayerEventPriority(); } } -void OcarinaUpdate(ItemBehavior* this, u32 idx) { - // TODO regalloc +void OcarinaUpdate(ItemBehavior* this, u32 index) { UpdateItemAnim(this); if ((this->playerFrame & 0x80) != 0) { gPlayerEntity.flags |= ENT_COLLIDE; @@ -47,6 +46,6 @@ void OcarinaUpdate(ItemBehavior* this, u32 idx) { gPauseMenuOptions.disabled = 0; CreateBird(&gPlayerEntity); ResetPlayerEventPriority(); - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } } diff --git a/src/item/itemPacciCane.c b/src/item/itemPacciCane.c index 42c3f53b..879f2051 100644 --- a/src/item/itemPacciCane.c +++ b/src/item/itemPacciCane.c @@ -7,28 +7,28 @@ void sub_08076C98(ItemBehavior*, u32); void sub_08076CBC(ItemBehavior*, u32); -void ItemPacciCane(ItemBehavior* beh, u32 idx) { - static void (*const stateFuncs[])(ItemBehavior * beh, u32) = { +void ItemPacciCane(ItemBehavior* this, u32 index) { + static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08076C98, sub_08076CBC, }; - stateFuncs[beh->stateID](beh, idx); + stateFuncs[this->stateID](this, index); } -void sub_08076C98(ItemBehavior* beh, u32 idx) { - beh->field_0x9 |= 0xf; - sub_08077D38(beh, idx); +void sub_08076C98(ItemBehavior* this, u32 index) { + this->priority |= 0xf; + sub_08077D38(this, index); sub_0806F948(&gPlayerEntity); - sub_08077BB8(beh); + sub_08077BB8(this); } -void sub_08076CBC(ItemBehavior* beh, u32 idx) { - if ((beh->playerFrame & 0x80) != 0) { - DeletePlayerItem(beh, idx); +void sub_08076CBC(ItemBehavior* this, u32 index) { + if ((this->playerFrame & 0x80) != 0) { + DeleteItemBehavior(this, index); } else { - if ((beh->playerFrame & 0x40) != 0) { - CreatePlayerItemWithParent(beh, PLAYER_ITEM_12); + if ((this->playerFrame & 0x40) != 0) { + CreatePlayerItemWithParent(this, PLAYER_ITEM_PACCI_CANE_PROJECTILE); } - UpdateItemAnim(beh); + UpdateItemAnim(this); } } diff --git a/src/item/itemPegasusBoots.c b/src/item/itemPegasusBoots.c index 81cdf137..7b487cee 100644 --- a/src/item/itemPegasusBoots.c +++ b/src/item/itemPegasusBoots.c @@ -14,7 +14,7 @@ void sub_08076A88(ItemBehavior*, u32); extern u16 gUnk_0800275C[]; extern u8 gUnk_0811BE38[]; -void ItemPegasusBoots(ItemBehavior* this, u32 idx) { +void ItemPegasusBoots(ItemBehavior* this, u32 index) { static void (*const ItemPegasusBoots_StateFunctions[])(ItemBehavior * beh, u32) = { sub_080768F8, sub_08076964, @@ -26,8 +26,8 @@ void ItemPegasusBoots(ItemBehavior* this, u32 idx) { if (gPlayerEntity.field_0x7a.HWORD != 0) { gPlayerState.dash_state = 0; - gPlayerState.field_0xe = 0; - DeletePlayerItem(this, idx); + gPlayerState.itemAnimPriority = 0; + DeleteItemBehavior(this, index); } else { --this->timer; if ((this->timer & 7) == 0) { @@ -54,15 +54,15 @@ void ItemPegasusBoots(ItemBehavior* this, u32 idx) { } } } - ItemPegasusBoots_StateFunctions[this->stateID](this, idx); + ItemPegasusBoots_StateFunctions[this->stateID](this, index); } } -void sub_080768F8(ItemBehavior* this, u32 idx) { +void sub_080768F8(ItemBehavior* this, u32 index) { u32 bVar1; u32 bVar2; - bVar1 = gPlayerState.field_0x1c | gPlayerState.field_0x3[1] | gPlayerState.heldObject | gPlayerState.jump_status; + bVar1 = gPlayerState.field_0x1c | gPlayerState.attack_status | gPlayerState.heldObject | gPlayerState.jump_status; bVar2 = (gPlayerState.flags & PL_IN_MINECART); bVar1 |= bVar2; if (bVar1 == 0) { @@ -73,19 +73,19 @@ void sub_080768F8(ItemBehavior* this, u32 idx) { } else { gPlayerState.animation = 0xc14; } - sub_08077D38(this, idx); - sub_08076964(this, idx); + sub_08077D38(this, index); + sub_08076964(this, index); } else { gPlayerState.dash_state = 0; - gPlayerState.field_0xe = 0; - DeletePlayerItem(this, idx); + gPlayerState.itemAnimPriority = 0; + DeleteItemBehavior(this, index); } } -void sub_08076964(ItemBehavior* this, u32 idx) { - Entity* bombEntity; +void sub_08076964(ItemBehavior* this, u32 index) { + Entity* entity; u32 uVar3; - if (sub_08077EFC(this) && gPlayerEntity.z.WORD == 0 && gPlayerState.dash_state) { + if (IsItemActive(this) && gPlayerEntity.z.WORD == 0 && gPlayerState.dash_state) { UpdateItemAnim(this); if ((gPlayerState.flags & PL_MINISH) == 0) { @@ -95,28 +95,28 @@ void sub_08076964(ItemBehavior* this, u32 idx) { if ((++gPlayerState.dash_state) == 0x1e) { if ((gPlayerState.flags & PL_FLAGS2) != 0) { gPlayerState.dash_state = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); return; } gPlayerState.dash_state = 0x40; - gPlayerState.field_0xa &= ~(8 >> idx); + gPlayerState.field_0xa &= ~(8 >> index); this->stateID++; if (HasSwordEquipped() && (gPlayerState.flags & PL_MINISH) == 0 && (gPlayerState.skills & SKILL_DASH_ATTACK) != 0) { - gPlayerState.field_0xab = 3; - sub_08077DF4(this, 0x298); - bombEntity = CreatePlayerItemWithParent(this, PLAYER_ITEM_C); - if (bombEntity != NULL) { + gPlayerState.lastSwordMove = SWORD_MOVE_DASH; + SetItemAnim(this, 0x298); + entity = CreatePlayerItemWithParent(this, PLAYER_ITEM_DASH_SWORD); + if (entity != NULL) { if (ItemIsSword(gSave.stats.itemButtons[SLOT_A]) != 0) { uVar3 = gSave.stats.itemButtons[SLOT_A]; } else { uVar3 = gSave.stats.itemButtons[SLOT_B]; } - bombEntity->field_0x68.HALF.LO = uVar3; + entity->field_0x68.HALF.LO = uVar3; return; } } else if ((gPlayerState.flags & PL_MINISH) == 0) { - sub_08077DF4(this, 0x104); + SetItemAnim(this, 0x104); return; } else { gPlayerState.animation = 0xc10; @@ -127,15 +127,15 @@ void sub_08076964(ItemBehavior* this, u32 idx) { } } gPlayerState.dash_state = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } -void sub_08076A88(ItemBehavior* this, u32 idx) { +void sub_08076A88(ItemBehavior* this, u32 index) { u32 uVar1; u32 uVar2; u8* ptr; - if ((sub_08077EFC(this) != 0) && (gPlayerState.dash_state != 0)) { + if ((IsItemActive(this) != 0) && (gPlayerState.dash_state != 0)) { if ((gPlayerState.flags & PL_MINISH) == 0) { gPlayerEntity.speed = 0x300; } else { @@ -148,27 +148,27 @@ void sub_08076A88(ItemBehavior* this, u32 idx) { gPlayerEntity.subAction = 0; COLLISION_OFF(&gPlayerEntity); gPlayerState.field_0x38 = 0; - gPlayerState.field_0xd = 0xff; + gPlayerState.direction = 0xff; return; } this->subtimer = 1; return; } ptr = gUnk_0811BE38; - if ((*(u16*)&ptr[(gPlayerEntity.animationState & 0xfe)] & gPlayerState.playerInput.field_0x90) == 0) { + if ((*(u16*)&ptr[(gPlayerEntity.animationState & 0xfe)] & gPlayerState.playerInput.heldInput) == 0) { this->direction = (this->playerAnimationState & 0xe) * 4; - if ((gPlayerState.field_0xd != 0xff) && (gPlayerState.field_0xd != this->direction)) { - if (((gPlayerState.field_0xd - this->direction) & 0x1f) < 0x10) { + if ((gPlayerState.direction != 0xff) && (gPlayerState.direction != this->direction)) { + if (((gPlayerState.direction - this->direction) & 0x1f) < 0x10) { this->direction = this->direction + 2; } this->direction--; this->direction &= 0x1f; } - gPlayerState.field_0xd = this->direction; + gPlayerState.direction = this->direction; UpdateItemAnim(this); return; } } gPlayerState.dash_state = 0; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } diff --git a/src/item/itemRocsCape.c b/src/item/itemRocsCape.c index 75b74e49..dee55950 100644 --- a/src/item/itemRocsCape.c +++ b/src/item/itemRocsCape.c @@ -5,23 +5,23 @@ void sub_08076758(ItemBehavior*, u32); extern void sub_08077F84(void); -void ItemRocsCape(ItemBehavior* this, u32 arg1) { +void ItemRocsCape(ItemBehavior* this, u32 index) { if (this->stateID != 0) { - sub_08076758(this, arg1); + sub_08076758(this, index); return; } if (gPlayerState.item == NULL) { - if (gPlayerState.field_0x0[1]) { - if (((gPlayerState.field_0x3[1] | gPlayerState.heldObject) == 0) && + if (gPlayerState.grab_status) { + if (((gPlayerState.attack_status | gPlayerState.heldObject) == 0) && (((gPlayerState.floor_type != SURFACE_DOOR && (gPlayerState.floor_type != SURFACE_PIT)) || ((gPlayerEntity.z.WORD != 0 || (gPlayerState.field_0x14 != 0)))))) { if ((gPlayerState.jump_status == 0) || ((gPlayerState.jump_status & 7) == 3)) { if (-1 < gPlayerEntity.z.WORD) { - gPlayerState.field_0x0[1] = 0; - this->stateID += 1; + gPlayerState.grab_status = 0; + this->stateID++; gPlayerState.keepFacing = 0; gPlayerState.jump_status = 1; - gPlayerState.field_0xe = -1; + gPlayerState.itemAnimPriority = -1; gPlayerState.item = NULL; gPlayerEntity.zVelocity = Q_16_16(2.0); sub_08077F84(); @@ -29,25 +29,25 @@ void ItemRocsCape(ItemBehavior* this, u32 arg1) { return; } } else { - sub_08076758(this, arg1); + sub_08076758(this, index); return; } } } else { - if (((u8)(gPlayerState.sword_state | gPlayerState.field_0xa | gPlayerState.field_0x3[1] | + if (((u8)(gPlayerState.sword_state | gPlayerState.field_0xa | gPlayerState.attack_status | gPlayerState.heldObject | gPlayerState.field_0x1c | gPlayerState.moleMittsState) == 0) && ((((gPlayerState.floor_type != SURFACE_DOOR && gPlayerState.floor_type != SURFACE_DOOR_13 && gPlayerState.floor_type != SURFACE_PIT) || (gPlayerEntity.z.WORD != 0)) || (gPlayerState.field_0x14 != 0)))) { if ((gPlayerState.jump_status != 0) && ((gPlayerState.jump_status & 7) != 3)) { - sub_08076758(this, arg1); + sub_08076758(this, index); return; } else if (gPlayerEntity.z.WORD >= 0) { gPlayerEntity.zVelocity = Q_16_16(2.0); gPlayerState.jump_status = 1; gPlayerState.item = NULL; - this->stateID += 1; + this->stateID++; sub_08077F84(); SoundReq(SFX_PLY_VO4); return; @@ -55,16 +55,14 @@ void ItemRocsCape(ItemBehavior* this, u32 arg1) { } } } - DeletePlayerItem(this, arg1); + DeleteItemBehavior(this, index); } -void sub_08076758(ItemBehavior* this, u32 arg1) { - s32 iVar1; - - gPlayerState.field_0xe = 0; +void sub_08076758(ItemBehavior* this, u32 index) { + gPlayerState.itemAnimPriority = 0; if ((((gPlayerState.jump_status & 0x28) == 0) && (gPlayerState.jump_status != 0)) && ((gPlayerState.jump_status & 7) != 3)) { - if (sub_08077EFC(this)) { + if (IsItemActive(this)) { if (this->stateID < 2) { if ((gPlayerEntity.zVelocity <= 0) && ((gPlayerState.jump_status & 0x10) == 0)) { this->stateID = 2; @@ -75,15 +73,15 @@ void sub_08076758(ItemBehavior* this, u32 arg1) { SoundReq(SFX_172); } } else { - gPlayerEntity.field_0x7a.HWORD += 1; + gPlayerEntity.field_0x7a.HWORD++; } } else { if (this->stateID > 1) { - gPlayerEntity.field_0x7a.HWORD += 1; + gPlayerEntity.field_0x7a.HWORD++; gPlayerState.jump_status &= 0xef; } } } else { - DeletePlayerItem(this, arg1); + DeleteItemBehavior(this, index); } } diff --git a/src/item/itemShield.c b/src/item/itemShield.c index 4ab16a4e..f9320d79 100644 --- a/src/item/itemShield.c +++ b/src/item/itemShield.c @@ -8,45 +8,45 @@ void sub_08076D04(ItemBehavior*, u32); void sub_08076D34(ItemBehavior*, u32); void sub_08076D94(ItemBehavior*, u32); -void ItemShield(ItemBehavior* beh, u32 idx) { +void ItemShield(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08076D04, sub_08076D34, sub_08076D94, }; - stateFuncs[beh->stateID](beh, idx); + stateFuncs[this->stateID](this, index); } -void sub_08076D04(ItemBehavior* beh, u32 idx) { - gPlayerState.field_0x3[0] = 0x81; - beh->field_0x9 = 2; +void sub_08076D04(ItemBehavior* this, u32 index) { + gPlayerState.shield_status = 0x81; + this->priority = 2; sub_0806F948(&gPlayerEntity); - sub_08077D38(beh, idx); - sub_08077BB8(beh); + sub_08077D38(this, index); + sub_08077BB8(this); } -void sub_08076D34(ItemBehavior* beh, u32 idx) { - if (sub_08077EFC(beh) != 0) { - gPlayerState.field_0x3[0] |= 1; - UpdateItemAnim(beh); - if (beh->playerFrame != 0) { - beh->stateID++; - beh->field_0xf = 0; - gPlayerState.field_0xa &= ~(u8)(8 >> idx); +void sub_08076D34(ItemBehavior* this, u32 index) { + if (IsItemActive(this) != 0) { + gPlayerState.shield_status |= 1; + UpdateItemAnim(this); + if (this->playerFrame != 0) { + this->stateID++; + this->animPriority = 0; + gPlayerState.field_0xa &= ~(u8)(8 >> index); SoundReq(SFX_15D); } } else { - gPlayerState.field_0x3[0] = 0; - DeletePlayerItem(beh, idx); + gPlayerState.shield_status = 0; + DeleteItemBehavior(this, index); } } -void sub_08076D94(ItemBehavior* beh, u32 idx) { - if (sub_08077EFC(beh)) { - gPlayerState.field_0x3[0] |= 1; - UpdateItemAnim(beh); +void sub_08076D94(ItemBehavior* this, u32 index) { + if (IsItemActive(this)) { + gPlayerState.shield_status |= 1; + UpdateItemAnim(this); } else { - gPlayerState.field_0x3[0] = 0; - DeletePlayerItem(beh, idx); + gPlayerState.shield_status = 0; + DeleteItemBehavior(this, index); } } diff --git a/src/item/itemSword.c b/src/item/itemSword.c index 9dcaba2e..87b1070a 100644 --- a/src/item/itemSword.c +++ b/src/item/itemSword.c @@ -1,8 +1,9 @@ -#include "item.h" #include "functions.h" -#include "sound.h" +#include "item.h" #include "object.h" +#include "player.h" #include "playeritem.h" +#include "sound.h" void sub_080759B8(ItemBehavior*, u32); void sub_080754B8(ItemBehavior*, u32); @@ -16,20 +17,20 @@ void sub_080758B0(ItemBehavior*, u32); void sub_08075900(ItemBehavior*, u32); void sub_08075694(ItemBehavior*, u32); -void ItemSword(ItemBehavior* this, u32 idx) { +void ItemSword(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { sub_08075338, sub_080754B8, sub_080755F0, sub_0807564C, sub_08075738, sub_08075580, sub_08075898, sub_080758B0, sub_08075900, }; gPlayerState.framestate = PL_STATE_SWORD; - stateFuncs[this->stateID](this, idx); + stateFuncs[this->stateID](this, index); } -void sub_08075338(ItemBehavior* this, u32 idx) { +void sub_08075338(ItemBehavior* this, u32 index) { u32 temp, temp2; if (gPlayerState.flags & PL_MINISH) { - this->field_0x9 |= 0x80; - sub_08077D38(this, idx); + this->priority |= 0x80; + sub_08077D38(this, index); gPlayerState.animation = 0xc00; SoundReq(SFX_PLY_VO1); return; @@ -40,20 +41,20 @@ void sub_08075338(ItemBehavior* this, u32 idx) { if ((gPlayerState.jump_status & 0x78) == 0 && (u32)gPlayerEntity.zVelocity < Q_16_16(1.5) && (gPlayerState.skills & SKILL_DOWN_THRUST) && gPlayerEntity.z.WORD != 0) { gPlayerState.jump_status |= 0x20; - gPlayerState.field_0xab = 7; - gPlayerState.field_0x3[1] |= (8 >> idx) | ((8 >> idx) << 4); + gPlayerState.lastSwordMove = SWORD_MOVE_DOWN_THRUST; + gPlayerState.attack_status |= (8 >> index) | ((8 >> index) << 4); sub_08077B98(this); this->stateID = 6; - sub_08075898(this, idx); + sub_08075898(this, index); return; } } #ifndef EU - sub_080759B8(this, idx); + sub_080759B8(this, index); return; } else if (gPlayerEntity.z.WORD) { #endif - sub_080759B8(this, idx); + sub_080759B8(this, index); return; } @@ -67,19 +68,19 @@ void sub_08075338(ItemBehavior* this, u32 idx) { } // Do the roll attack. - sub_08077D38(this, idx); + sub_08077D38(this, index); sub_08077B98(this); - temp = (8 >> idx); - gPlayerState.field_0x3[1] |= temp | (temp << 4); + temp = (8 >> index); + gPlayerState.attack_status |= temp | (temp << 4); gPlayerState.field_0xa |= temp; gPlayerState.keepFacing |= temp; this->stateID = 8; this->timer = 0x14; - this->field_0xf = 6; - this->field_0x9 |= 0x80; - gPlayerState.field_0xab = 2; + this->animPriority = 6; + this->priority |= 0x80; + gPlayerState.lastSwordMove = SWORD_MOVE_ROLL; gPlayerState.flags |= PL_SWORD_THRUST; - sub_08077DF4(this, 0x130); + SetItemAnim(this, 0x130); SoundReq(SFX_PLY_VO3); return; } @@ -96,105 +97,107 @@ void sub_08075338(ItemBehavior* this, u32 idx) { } } - sub_08077D38(this, idx); + sub_08077D38(this, index); sub_08077B98(this); } -void sub_080754B8(ItemBehavior* this, u32 idx) { - u32 iVar1; +void sub_080754B8(ItemBehavior* this, u32 index) { + u32 swordBeam; if ((gPlayerState.sword_state & 0x80) != 0) { - sub_08075694(this, idx); - } else if (gPlayerState.field_0x3[1] != 0) { + sub_08075694(this, index); + } else if (gPlayerState.attack_status != 0) { UpdateItemAnim(this); if (this->playerFrame != 0) { - this->field_0x9 &= ~0x80; + this->priority &= ~0x80; } if (gPlayerEntity.frameSpriteSettings & 1) { - iVar1 = sub_0807B014(); - if (iVar1 && FindEntityByID(PLAYER_ITEM, PLAYER_ITEM_SWORD_BEAM1, 2) == 0) { + swordBeam = GetSwordBeam(); + if (swordBeam && FindEntityByID(PLAYER_ITEM, PLAYER_ITEM_SWORD_BEAM1, 2) == 0) { CreatePlayerItemWithParent(this, PLAYER_ITEM_SWORD_BEAM1); - if (iVar1 == 0xf) { - gPlayerState.field_0xab = 5; + if (swordBeam == 0xf) { + // SKILL_SWORD_BEAM (full health) + gPlayerState.lastSwordMove = SWORD_MOVE_FULL_BEAM; } else { - gPlayerState.field_0xab = 8; + // SKILL_PERIL_BEAM (low health) + gPlayerState.lastSwordMove = SWORD_MOVE_LOW_BEAM; } } } if ((this->playerFrame & 0x80) != 0) { if (((gPlayerState.flags & 0x80) != 0) || ((gPlayerState.skills & SKILL_SPIN_ATTACK) == 0)) { - sub_080759B8(this, idx); + sub_080759B8(this, index); } else { - sub_08075580(this, idx); + sub_08075580(this, index); } } } else { - sub_080759B8(this, idx); + sub_080759B8(this, index); } } -void sub_08075580(ItemBehavior* this, u32 idx) { - if ((sub_08077EFC(this) != 0) && (gPlayerState.jump_status == 0)) { - gPlayerState.field_0xa = gPlayerState.field_0xa & ~(8 >> idx); +void sub_08075580(ItemBehavior* this, u32 index) { + if ((IsItemActive(this) != 0) && (gPlayerState.jump_status == 0)) { + gPlayerState.field_0xa = gPlayerState.field_0xa & ~(8 >> index); gPlayerState.sword_state = 1; gPlayerState.item->hurtType = 0xd; - this->field_0xf = 0; + this->animPriority = 0; this->stateID = 2; if ((gPlayerState.skills & SKILL_FAST_SPIN) != 0) { this->timer = 0x28; // TODO spin speed? } else { this->timer = 0x50; } - sub_08077DF4(this, 0x168); + SetItemAnim(this, 0x168); CreateObject(SWORD_PARTICLE, 0, 0); return; } - sub_080759B8(this, idx); + sub_080759B8(this, index); } -void sub_080755F0(ItemBehavior* this, u32 idx) { - if (sub_08077EFC(this) != 0) { +void sub_080755F0(ItemBehavior* this, u32 index) { + if (IsItemActive(this) != 0) { if (sub_08077EC8(this) == 0) { - if ((gPlayerState.sword_state | gPlayerState.field_0x3[1]) != 0) { + if ((gPlayerState.sword_state | gPlayerState.attack_status) != 0) { if (--this->timer == 0) { this->stateID = 3; - this->field_0x9 |= 0x80; + this->priority |= 0x80; gPlayerState.sword_state = gPlayerState.sword_state | 0x20; } } else { - sub_080759B8(this, idx); + sub_080759B8(this, index); } } } else { - sub_080759B8(this, idx); + sub_080759B8(this, index); } } -void sub_0807564C(ItemBehavior* this, u32 idx) { - if ((gPlayerState.sword_state | gPlayerState.field_0x3[1]) == 0) { - sub_080759B8(this, idx); +void sub_0807564C(ItemBehavior* this, u32 index) { + if ((gPlayerState.sword_state | gPlayerState.attack_status) == 0) { + sub_080759B8(this, index); } else { - if ((sub_08077EC8(this) == 0) && ((sub_08077EFC(this) == 0 || ((gPlayerState.sword_state & 0x80) != 0)))) { - sub_08075694(this, idx); + if ((sub_08077EC8(this) == 0) && ((IsItemActive(this) == 0 || ((gPlayerState.sword_state & 0x80) != 0)))) { + sub_08075694(this, index); } } } -void sub_08075694(ItemBehavior* this, u32 idx) { +void sub_08075694(ItemBehavior* this, u32 index) { this->timer = 1; if (gPlayerState.flags & PL_SWORD_THRUST) { gPlayerState.flags &= ~PL_SWORD_THRUST; gPlayerState.flags &= ~PL_ROLLING; - sub_08077DF4(this, 300); + SetItemAnim(this, 300); } else { - gPlayerState.field_0xab = 1; - sub_08077DF4(this, 0x124); + gPlayerState.lastSwordMove = SWORD_MOVE_SPIN; + SetItemAnim(this, 0x124); } - gPlayerState.field_0xa = (8 >> idx) | gPlayerState.field_0xa; + gPlayerState.field_0xa = (8 >> index) | gPlayerState.field_0xa; this->stateID = 4; - this->field_0xf = 6; + this->animPriority = 6; gPlayerEntity.hurtType = 0x1e; gPlayerState.sword_state |= 0x40; gPlayerState.sword_state &= 0xdf; @@ -205,20 +208,20 @@ void sub_08075694(ItemBehavior* this, u32 idx) { SoundReq(SFX_PLY_VO2); } -void sub_08075738(ItemBehavior* this, u32 idx) { +void sub_08075738(ItemBehavior* this, u32 index) { u32 bVar6; - if (gPlayerState.field_0x3[1] == 0) { - sub_080759B8(this, idx); + if (gPlayerState.attack_status == 0) { + sub_080759B8(this, index); } else { UpdateItemAnim(this); - if (sub_08077F10(this)) { + if (IsItemActivatedThisFrame(this)) { this->timer = 2; } if ((gPlayerState.sword_state & 0x10) != 0) { - if ((gPlayerState.field_0xd & 0x80) == 0) { - this->direction = gPlayerState.field_0xd; + if ((gPlayerState.direction & 0x80) == 0) { + this->direction = gPlayerState.direction; } gPlayerEntity.direction = this->direction; gPlayerEntity.speed = 0x180; @@ -229,13 +232,13 @@ void sub_08075738(ItemBehavior* this, u32 idx) { } if ((bVar6 <= ++this->subtimer) || (--this->timer == 0)) { - sub_080759B8(this, idx); + sub_080759B8(this, index); } } } else { if (((((gPlayerEntity.frameSpriteSettings & 1) != 0) && ((gPlayerState.sword_state & 0x80) == 0)) && ((gPlayerState.skills & SKILL_FOURSWORD) != 0))) { - Entity* bombEnt = CreatePlayerItemWithParent(this, PLAYER_ITEM_14); + Entity* bombEnt = CreatePlayerItemWithParent(this, PLAYER_ITEM_SPIRAL_BEAM); if (bombEnt) { bombEnt->animationState = (gPlayerEntity.animationState & 6) | 0x80; } @@ -244,34 +247,34 @@ void sub_08075738(ItemBehavior* this, u32 idx) { if ((((gPlayerEntity.frameSpriteSettings & 2) != 0) && ((gPlayerState.sword_state & 0x80) == 0)) && (((gPlayerState.skills & SKILL_GREAT_SPIN) != 0 && (--this->timer != 0)))) { gPlayerState.sword_state |= 0x10; - gPlayerState.field_0xab = 6; + gPlayerState.lastSwordMove = SWORD_MOVE_GREAT_SPIN; this->direction = gPlayerEntity.animationState << 2; this->timer = 1; this->subtimer = 1; - gPlayerState.field_0xa = gPlayerState.field_0xa & ~(8 >> idx); - sub_08077DF4(this, 0x128); + gPlayerState.field_0xa = gPlayerState.field_0xa & ~(8 >> index); + SetItemAnim(this, 0x128); } if ((this->playerFrame & 0x80) != 0) { - sub_080759B8(this, idx); + sub_080759B8(this, index); } } } } -void sub_08075898(ItemBehavior* this, u32 idx) { - if (gPlayerState.field_0x3[1] == 0) { - sub_080759B8(this, idx); +void sub_08075898(ItemBehavior* this, u32 index) { + if (gPlayerState.attack_status == 0) { + sub_080759B8(this, index); } } -void sub_080758B0(ItemBehavior* this, u32 idx) { - if (gPlayerState.field_0x3[1] == 0) { - sub_080759B8(this, idx); +void sub_080758B0(ItemBehavior* this, u32 index) { + if (gPlayerState.attack_status == 0) { + sub_080759B8(this, index); } else { UpdateItemAnim(this); if ((this->playerFrame & 0x80) != 0) { - this->field_0xf = 0; + this->animPriority = 0; if ((gPlayerState.sword_state & 0x20) != 0) { this->stateID = 3; } else { @@ -282,20 +285,20 @@ void sub_080758B0(ItemBehavior* this, u32 idx) { } } -void sub_08075900(ItemBehavior* this, u32 idx) { +void sub_08075900(ItemBehavior* this, u32 index) { if (gPlayerState.floor_type == SURFACE_SWAMP) { gPlayerState.flags &= ~PL_ROLLING; - sub_080759B8(this, idx); + sub_080759B8(this, index); } else { UpdateItemAnim(this); if ((gPlayerState.sword_state & 0x80) != 0) { gPlayerState.sword_state = 0xa0; - sub_0807564C(this, idx); + sub_0807564C(this, index); } else { if (this->timer != 0) { if (--this->timer == 0) { - sub_08077DF4(this, 0x134); + SetItemAnim(this, 0x134); } gPlayerEntity.direction = (gPlayerEntity.animationState >> 1) << 3; gPlayerEntity.speed = 0x300; @@ -306,19 +309,19 @@ void sub_08075900(ItemBehavior* this, u32 idx) { } else { if ((this->playerFrame & 0x80) != 0) { gPlayerState.flags &= ~PL_ROLLING; - sub_080759B8(this, idx); + sub_080759B8(this, index); } } } } } -void sub_080759B8(ItemBehavior* this, u32 idx) { +void sub_080759B8(ItemBehavior* this, u32 index) { if ((gPlayerState.flags & PL_MINISH) == 0) { gPlayerEntity.hurtType = 0; } gPlayerState.flags &= ~PL_SWORD_THRUST; gPlayerState.sword_state = 0; gPlayerState.item = NULL; - DeletePlayerItem(this, idx); + DeleteItemBehavior(this, index); } diff --git a/src/item/itemTryPickupObject.c b/src/item/itemTryPickupObject.c index 6de4eb66..8a7b40dc 100644 --- a/src/item/itemTryPickupObject.c +++ b/src/item/itemTryPickupObject.c @@ -1,11 +1,12 @@ #include "item.h" #include "functions.h" #include "sound.h" +#include "playeritem.h" -u32 sub_08077F64(ItemBehavior* arg0, u32 idx); +u32 sub_08077F64(ItemBehavior* arg0, u32 index); u32 sub_080789A8(void); void sub_080762C4(ItemBehavior*, Entity*, u8, u32); -void sub_08076088(ItemBehavior*, void*, u32); +void sub_08076088(ItemBehavior*, Entity*, u32); void ItemPickupCheck(ItemBehavior*, u32); void sub_080762D8(ItemBehavior*, u32); void sub_08076488(ItemBehavior*, u32); @@ -13,24 +14,79 @@ void sub_08076518(ItemBehavior*, u32); void sub_080765E0(ItemBehavior*, u32); void sub_0807660C(ItemBehavior*, u32); -void ItemTryPickupObject(ItemBehavior* this, u32 idx) { +void sub_08076088(ItemBehavior* this, Entity* param_2, u32 param_3) { + if (param_2 != NULL) { + if ((param_2->carryFlags & 1) != 0) { + return; + } + param_2->action = 2; + param_2->subAction = param_2->carryFlags & 1; + } + + this->field_0x18 = param_2; + if ((gPlayerState.flags & PL_NO_CAP)) { + SetItemAnim(this, 0x928); + } else { + SetItemAnim(this, 0x338); + } + gPlayerState.heldObject = 3; + gPlayerState.framestate = 4; + this->stateID = 2; + this->animPriority = 0xf; + if ((gPlayerEntity.field_0x78.HALF.HI & 0x80)) { + gPlayerEntity.field_0x78.HALF.HI = 0; + COLLISION_ON(&gPlayerEntity); + gPlayerState.heldObject = 4; + gPlayerState.keepFacing = ~(8 >> param_3) & gPlayerState.keepFacing; + gPlayerState.field_0xa = ~(8 >> param_3) & gPlayerState.field_0xa; + this->stateID = 3; + this->animPriority = 0; + } else { + gPlayerState.field_0xa |= (8 >> param_3); + gPlayerState.keepFacing |= (8 >> param_3); + } + + param_2 = CreatePlayerItemWithParent(this, PLAYER_ITEM_HELD_OBJECT); + if (param_2 == NULL) { + PlayerCancelHoldItem(this, param_3); + } else { + Entity* playerEnt = &gPlayerEntity; + *(Entity**)&playerEnt->field_0x74 = param_2; + playerEnt->subtimer = 0; + param_2->child = this->field_0x18; + param_2->carryFlags = playerEnt->carryFlags; + param_2->parent = (Entity*)this; + this->field_0x18 = param_2; + param_2->type2 = this->field_0x2[1]; + param_2->timer = this->timer; + param_2->subtimer = this->subtimer; + if ((this->field_0x18->carryFlags & 0xf0) == 0x10) { + this->timer = 8; + } else { + this->timer = 0; + } + SoundReq(SFX_PLY_LIFT); + } +} + +void ItemTryPickupObject(ItemBehavior* this, u32 index) { static void (*const stateFuncs[])(ItemBehavior*, u32) = { ItemPickupCheck, sub_080762D8, sub_08076488, sub_08076518, sub_080765E0, sub_0807660C, }; - stateFuncs[this->stateID](this, idx); + stateFuncs[this->stateID](this, index); } -void ItemPickupCheck(ItemBehavior* this, u32 idx) { +void ItemPickupCheck(ItemBehavior* this, u32 index) { Entity* carried; - if (!(((gPlayerState.field_0x3[1] != 0) || - (((gPlayerState.jump_status != 0 && ((gPlayerState.flags & (PL_BUSY | PL_FALLING | PL_IN_MINECART)) == 0)) || - (gPlayerState.field_0x0[1] = gPlayerEntity.animationState | 0x80, 8 < gPlayerEntity.iframes)))))) { + if (gPlayerState.attack_status == 0 && + (gPlayerState.jump_status == 0 || (gPlayerState.flags & (PL_BUSY | PL_FALLING | PL_IN_MINECART)) != 0) && + (gPlayerState.grab_status = gPlayerEntity.animationState | 0x80, gPlayerEntity.iframes <= 8)) { switch (sub_080789A8()) { case 2: if (((gCarriedEntity.unk_8)->carryFlags & 0xf) == 0) { - sub_08076088(this, gCarriedEntity.unk_8, idx); + sub_08076088(this, gCarriedEntity.unk_8, index); return; } carried = gCarriedEntity.unk_8; @@ -38,24 +94,24 @@ void ItemPickupCheck(ItemBehavior* this, u32 idx) { carried->action = 2; carried->subAction = 5; gPlayerState.framestate = PL_STATE_THROW; - sub_080762C4(this, carried, 2, idx); + sub_080762C4(this, carried, 2, index); gUnk_0200AF00.unk_2e = 8; SoundReq(SFX_102); break; case 1: - sub_080762C4(this, 0, 1, idx); + sub_080762C4(this, 0, 1, index); SoundReq(SFX_102); break; case 0: this->stateID = 5; this->timer = 0x0f; - this->field_0xf = 6; - gPlayerState.field_0xa = (8 >> idx) | gPlayerState.field_0xa; - gPlayerState.keepFacing = (8 >> idx) | gPlayerState.keepFacing; + this->animPriority = 6; + gPlayerState.field_0xa = (8 >> index) | gPlayerState.field_0xa; + gPlayerState.keepFacing = (8 >> index) | gPlayerState.keepFacing; if ((gPlayerState.flags & PL_NO_CAP) == 0) { - sub_08077DF4(this, 0x378); + SetItemAnim(this, 0x378); } else { - sub_08077DF4(this, 0x948); + SetItemAnim(this, 0x948); } SoundReq(SFX_88); break; @@ -63,7 +119,7 @@ void ItemPickupCheck(ItemBehavior* this, u32 idx) { break; } } else { - PlayerCancelHoldItem(this, idx); + PlayerCancelHoldItem(this, index); } } @@ -73,14 +129,14 @@ void sub_080762C4(ItemBehavior* this, Entity* arg1, u8 arg2, u32 arg3) { sub_08077D38(this, arg3); } -ASM_FUNC("asm/non_matching/itemTryPickupObject/sub_080762D8.inc", void sub_080762D8(ItemBehavior* this, u32 idx)) +ASM_FUNC("asm/non_matching/itemTryPickupObject/sub_080762D8.inc", void sub_080762D8(ItemBehavior* this, u32 index)) -void sub_08076488(ItemBehavior* this, u32 idx) { +void sub_08076488(ItemBehavior* this, u32 index) { u32 bVar1; s32 iVar2; if (this->timer == 0) { - if (PlayerTryDropObject(this, idx) != 0) { + if (PlayerTryDropObject(this, index) != 0) { if ((((this->field_0x18->carryFlags) & 0xf0) == 0x10) && ((gRoomTransition.frameCount & 1U) != 0)) { return; } @@ -88,11 +144,11 @@ void sub_08076488(ItemBehavior* this, u32 idx) { if ((this->playerFrame & 0x80) != 0) { gPlayerEntity.flags |= ENT_COLLIDE; gPlayerState.heldObject = 4; - bVar1 = ~(8 >> idx); + bVar1 = ~(8 >> index); gPlayerState.keepFacing = bVar1 & gPlayerState.keepFacing; gPlayerState.field_0xa = bVar1 & gPlayerState.field_0xa; this->stateID++; - this->field_0xf = 0; + this->animPriority = 0; } } } else { @@ -108,19 +164,18 @@ void sub_08076518(ItemBehavior* this, u32 index) { if (gPlayerEntity.knockbackDuration != 0) { PlayerCancelHoldItem(this, index); } else { - if ((gPlayerState.playerInput.field_0x92 & (PLAYER_INPUT_8000 | PLAYER_INPUT_10 | PLAYER_INPUT_8)) != - 0) { + if ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_8000 | PLAYER_INPUT_10 | PLAYER_INPUT_8)) != 0) { sub_0806F948(&gPlayerEntity); gPlayerState.heldObject = 5; this->field_0x18->subAction = 2; this->field_0x18->direction = (gPlayerEntity.animationState & 0xe) << 2; this->field_0x18 = NULL; this->stateID++; - this->field_0xf = 0x0f; + this->animPriority = 0x0f; if ((gPlayerState.flags & PL_NO_CAP) != 0) { - sub_08077DF4(this, 0x930); + SetItemAnim(this, 0x930); } else { - sub_08077DF4(this, 0x344); + SetItemAnim(this, 0x344); } gPlayerState.field_0xa |= 8 >> index; gPlayerState.keepFacing |= 8 >> index; @@ -130,20 +185,20 @@ void sub_08076518(ItemBehavior* this, u32 index) { } } -void sub_080765E0(ItemBehavior* this, u32 idx) { - if (PlayerTryDropObject(this, idx) != 0) { +void sub_080765E0(ItemBehavior* this, u32 index) { + if (PlayerTryDropObject(this, index) != 0) { if ((this->playerFrame & 0x80) != 0) { - PlayerCancelHoldItem(this, idx); + PlayerCancelHoldItem(this, index); } else { UpdateItemAnim(this); } } } -void sub_0807660C(ItemBehavior* this, u32 idx) { +void sub_0807660C(ItemBehavior* this, u32 index) { UpdateItemAnim(this); - if ((this->timer-- == 0) || (gPlayerState.field_0x0[1] == 0)) { - gPlayerState.field_0x0[1] = 0; - DeletePlayerItem(this, idx); + if ((this->timer-- == 0) || (gPlayerState.grab_status == 0)) { + gPlayerState.grab_status = 0; + DeleteItemBehavior(this, index); } } diff --git a/src/itemDefinitions.c b/src/itemDefinitions.c new file mode 100644 index 00000000..c6a8567b --- /dev/null +++ b/src/itemDefinitions.c @@ -0,0 +1,43 @@ +#include "item.h" +#include "playeritem.h" +#include "structures.h" + +const ItemDefinition gItemDefinitions[] = { + [ITEM_NONE] = { TRUE, 1, CREATE_ITEM_0, PLAYER_ITEM_NONE, 0, 0, FALSE, FALSE }, + [ITEM_SMITH_SWORD] = { TRUE, 7, CREATE_ITEM_3, PLAYER_ITEM_SWORD, 264, 6, TRUE, TRUE }, + [ITEM_GREEN_SWORD] = { TRUE, 7, CREATE_ITEM_3, PLAYER_ITEM_SWORD, 264, 6, TRUE, TRUE }, + [ITEM_RED_SWORD] = { TRUE, 7, CREATE_ITEM_3, PLAYER_ITEM_SWORD, 264, 6, TRUE, TRUE }, + [ITEM_BLUE_SWORD] = { TRUE, 7, CREATE_ITEM_3, PLAYER_ITEM_SWORD, 264, 6, TRUE, TRUE }, + [ITEM_UNUSED_SWORD] = { TRUE, 7, CREATE_ITEM_3, PLAYER_ITEM_SWORD, 264, 6, TRUE, TRUE }, + [ITEM_FOURSWORD] = { TRUE, 7, CREATE_ITEM_3, PLAYER_ITEM_SWORD, 264, 6, TRUE, TRUE }, + [ITEM_BOMBS] = { TRUE, 3, CREATE_ITEM_4, PLAYER_ITEM_BOMB, 0, 3, FALSE, FALSE }, + [ITEM_REMOTE_BOMBS] = { TRUE, 3, CREATE_ITEM_4, PLAYER_ITEM_BOMB, 0, 3, FALSE, FALSE }, + [ITEM_BOW] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_BOW, 540, 3, FALSE, FALSE }, + [ITEM_LIGHT_ARROW] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_BOW, 540, 3, FALSE, FALSE }, + [ITEM_BOOMERANG] = { TRUE, 5, CREATE_ITEM_3, PLAYER_ITEM_BOOMERANG, 2072, 3, FALSE, FALSE }, + [ITEM_MAGIC_BOOMERANG] = { TRUE, 5, CREATE_ITEM_3, PLAYER_ITEM_BOOMERANG, 1796, 3, FALSE, FALSE }, + [ITEM_SHIELD] = { FALSE, 1, CREATE_ITEM_3, PLAYER_ITEM_SHIELD, 344, 2, FALSE, FALSE }, + [ITEM_MIRROR_SHIELD] = { TRUE, 1, CREATE_ITEM_3, PLAYER_ITEM_SHIELD, 344, 2, FALSE, FALSE }, +#ifdef EU + [ITEM_LANTERN_OFF] = { TRUE, 3, CREATE_ITEM_5, PLAYER_ITEM_LANTERN, 1536, 6, FALSE, FALSE }, + [ITEM_LANTERN_ON] = { TRUE, 3, CREATE_ITEM_5, PLAYER_ITEM_LANTERN, 1536, 6, FALSE, FALSE }, +#else + [ITEM_LANTERN_OFF] = { TRUE, 3, CREATE_ITEM_5, PLAYER_ITEM_LANTERN, 1536, 2, FALSE, FALSE }, + [ITEM_LANTERN_ON] = { TRUE, 3, CREATE_ITEM_5, PLAYER_ITEM_LANTERN, 1536, 2, FALSE, FALSE }, +#endif + [ITEM_GUST_JAR] = { TRUE, 6, CREATE_ITEM_3, PLAYER_ITEM_GUST_JAR, 1280, 2, FALSE, FALSE }, + [ITEM_PACCI_CANE] = { TRUE, 4, CREATE_ITEM_3, PLAYER_ITEM_PACCI_CANE, 1576, 6, TRUE, FALSE }, + [ITEM_MOLE_MITTS] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_NONE2, 0, 2, TRUE, FALSE }, + [ITEM_ROCS_CAPE] = { TRUE, 1, CREATE_ITEM_1, PLAYER_ITEM_NONE3, 2060, 0, FALSE, FALSE }, + [ITEM_PEGASUS_BOOTS] = { TRUE, CREATE_ITEM_1, PLAYER_ITEM_SWORD, 12, 260, 6, FALSE, FALSE }, + [ITEM_FIRE_ROD] = { TRUE, 4, CREATE_ITEM_3, PLAYER_ITEM_CELL_OVERWRITE_SET, 260, 6, FALSE, FALSE }, + [ITEM_OCARINA] = { TRUE, 7, CREATE_ITEM_3, PLAYER_ITEM_NONE, 2273, 6, FALSE, FALSE }, + [ITEM_ORB_GREEN] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_NULLED2, 0, 1, TRUE, TRUE }, + [ITEM_ORB_BLUE] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_NULLED, 0, 1, TRUE, TRUE }, + [ITEM_ORB_RED] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_CELL_OVERWRITE_SET2, 0, 1, TRUE, TRUE }, + [ITEM_TRY_PICKUP_OBJECT] = { TRUE, 2, CREATE_ITEM_3, PLAYER_ITEM_HELD_OBJECT, 832, 4, FALSE, TRUE }, + [ITEM_BOTTLE1] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_BOTTLE, 0, 6, TRUE, FALSE }, + [ITEM_BOTTLE2] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_BOTTLE, 0, 6, TRUE, FALSE }, + [ITEM_BOTTLE3] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_BOTTLE, 0, 6, TRUE, FALSE }, + [ITEM_BOTTLE4] = { TRUE, 3, CREATE_ITEM_3, PLAYER_ITEM_BOTTLE, 0, 6, TRUE, FALSE }, +}; diff --git a/src/itemMetaData.c b/src/itemMetaData.c index c71f9495..ec3e1fe8 100644 --- a/src/itemMetaData.c +++ b/src/itemMetaData.c @@ -31,7 +31,7 @@ const ItemMetaData gItemMetaData[] = { [ITEM_ORB_GREEN] = { 0x63u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }, [ITEM_ORB_BLUE] = { 0x63u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }, [ITEM_ORB_RED] = { 0x63u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }, - [ITEM_TRAP] = { 0x63u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }, + [ITEM_TRY_PICKUP_OBJECT] = { 0x63u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }, [ITEM_BOTTLE1] = { MENU_SLOT_BOTTLE0, 0x3u, 0u, 0x1u, 0x20u, TEXT_ITEM_GET, 0x20u, 0x5u }, [ITEM_BOTTLE2] = { MENU_SLOT_BOTTLE1, 0x3u, 0u, 0x1u, 0x20u, TEXT_ITEM_GET, 0x20u, 0x5u }, [ITEM_BOTTLE3] = { MENU_SLOT_BOTTLE2, 0x3u, 0u, 0x1u, 0x20u, TEXT_ITEM_GET, 0x20u, 0x5u }, diff --git a/src/manager/minishPortalManager.c b/src/manager/minishPortalManager.c index fe312d14..d86549c3 100644 --- a/src/manager/minishPortalManager.c +++ b/src/manager/minishPortalManager.c @@ -83,7 +83,7 @@ void CreateMagicSparkles(u32 baseX, u32 baseY, u32 layer) { } bool32 PortalReadyForMinish(void) { - if ((gPlayerState.flags & PL_MINISH) && !gPlayerState.field_0xaa && (gArea.portal_type != 0x6) && + if ((gPlayerState.flags & PL_MINISH) && gPlayerState.attachedBeetleCount == 0 && (gArea.portal_type != 0x6) && (gPlayerState.heldObject == 0)) { switch (gPlayerState.framestate) { case PL_STATE_IDLE: diff --git a/src/manager/miscManager.c b/src/manager/miscManager.c index cca46468..4bd03591 100644 --- a/src/manager/miscManager.c +++ b/src/manager/miscManager.c @@ -365,7 +365,7 @@ void MiscManager_TypeB(MiscManager* this) { bool32 sub_080593CC(MiscManager* this) { if (!(gPlayerState.flags & PL_MINISH) && gPlayerState.swim_state != 0 && gPlayerEntity.animationState == 0 && - (gPlayerState.playerInput.field_0x90 & PLAYER_INPUT_ANY_DIRECTION) == PLAYER_INPUT_UP) { + (gPlayerState.playerInput.heldInput & PLAYER_INPUT_ANY_DIRECTION) == PLAYER_INPUT_UP) { return EntityWithinDistance(&gPlayerEntity, this->unk_38, this->unk_3a + 0xC, 6); } return FALSE; diff --git a/src/menu/pause_menu.c b/src/menu/pause_menu.c index 0d16d8cc..957dc751 100644 --- a/src/menu/pause_menu.c +++ b/src/menu/pause_menu.c @@ -75,7 +75,7 @@ void PauseMenu_Variant0(void) { (u16)gRoomTransition.player_status.overworld_map_y); gPauseMenuOptions.unk2[4] = ptr->_4; gPauseMenuOptions.unk2[5] = sub_0801DB94(); - if (IsItemEquipped(ITEM_LANTERN_ON) != 2) { + if (IsItemEquipped(ITEM_LANTERN_ON) != EQUIP_SLOT_NONE) { r1 = 0x10; } else { r1 = 0xf; @@ -399,8 +399,8 @@ void PauseMenu_ItemMenu_Update(void) { } case B_BUTTON: if (gPauseMenu.items[menuSlot] != 0) { - u32 t = !!(gInput.newKeys ^ 1); - ForceEquipItem(gPauseMenu.items[menuSlot], t); + u32 slot = !!(gInput.newKeys ^ 1); + ForceEquipItem(gPauseMenu.items[menuSlot], slot); SoundReq(SFX_TEXTBOX_SELECT); } break; diff --git a/src/npc.c b/src/npc.c index 99c07fee..94896d5e 100644 --- a/src/npc.c +++ b/src/npc.c @@ -20,7 +20,8 @@ void NPCUpdate(Entity* this) { if (gNPCFunctions[this->id][1] != NULL) gNPCFunctions[this->id][1](this); - if (this->health % 0x80) { + if (this->health % 0x80) { // If this NPC was created by DelayedEntityLoadManager_Main, we need to update the + // location in gNPCData. NPCStruct* npc = gNPCData; npc += (this->health - 1); npc->x = this->x.HALF.HI - gRoomControls.origin_x; diff --git a/src/npc/bigGoron.c b/src/npc/bigGoron.c index e94a54ff..1497f185 100644 --- a/src/npc/bigGoron.c +++ b/src/npc/bigGoron.c @@ -418,12 +418,12 @@ void sub_0806D520(Entity* this, u32 param_2) { } void sub_0806D5D4(void) { - u32 itemSlot; + EquipSlot equipSlot; InitBiggoronTimer(); - itemSlot = IsItemEquipped(ITEM_SHIELD); - if (itemSlot != 2) { - gSave.stats.itemButtons[itemSlot] = ITEM_NONE; + equipSlot = IsItemEquipped(ITEM_SHIELD); + if (equipSlot != EQUIP_SLOT_NONE) { + gSave.stats.itemButtons[equipSlot] = ITEM_NONE; } SetInventoryValue(ITEM_SHIELD, 0); } diff --git a/src/npc/bladeBrothers.c b/src/npc/bladeBrothers.c index 8e05ed27..7e4f161a 100644 --- a/src/npc/bladeBrothers.c +++ b/src/npc/bladeBrothers.c @@ -144,7 +144,7 @@ void BladeBrothers_StartPlayerDemonstration(Entity* this, ScriptExecutionContext if (BladeBrothers_EquippedItem) {} if (p = this->timer, BladeBrothers_EquippedItem[p]) { - ForceEquipItem(BladeBrothers_EquippedItem[this->timer], 0); + ForceEquipItem(BladeBrothers_EquippedItem[this->timer], EQUIP_SLOT_A); } InitPlayerMacro(BladeBrothers_PlayerMacros[this->timer]); } @@ -157,9 +157,10 @@ void sub_08068BB4(Entity* this) { *(&this->field_0x68.HALF.HI + 1) = item; } +// Restore previous equipped items. void sub_08068BD0(Entity* this) { - ForceEquipItem(this->field_0x68.HALF.HI, 0); - ForceEquipItem(*(u8*)(&this->field_0x68.HALF.HI + 1), 1); + ForceEquipItem(this->field_0x68.HALF.HI, EQUIP_SLOT_A); + ForceEquipItem(*(u8*)(&this->field_0x68.HALF.HI + 1), EQUIP_SLOT_B); } static void sub_08068BEC(Entity* this, u32 unused) { @@ -337,18 +338,18 @@ void sub_08068E78(Entity* this) { MessageNoOverlap(gUnk_08111714[this->timer], this); } -void sub_08068E90(Entity* this) { +void BladeBrothers_LearnSkill(Entity* this) { // Learn a skill. PlayerState* s = &gPlayerState; *(u16*)&s->skills = (1 << (gUnk_08111740[this->timer] - 1)) | *(u16*)&s->skills; } -void sub_08068EB4(void) { - gPlayerState.field_0xab = 0; +void BladeBrothers_ResetLastSwordMove(void) { + gPlayerState.lastSwordMove = SWORD_MOVE_NONE; } -void sub_08068EC4(Entity* this, ScriptExecutionContext* context) { - if (gUnk_08111740[this->timer] == gPlayerState.field_0xab) { +void BladeBrothers_CheckLastSwordMove(Entity* this, ScriptExecutionContext* context) { + if (gUnk_08111740[this->timer] == gPlayerState.lastSwordMove) { context->wait = gUnk_0811172A[this->timer]; context->condition = 1; } else { diff --git a/src/npc/castleMaid.c b/src/npc/castleMaid.c index 257bc451..cb327cdc 100644 --- a/src/npc/castleMaid.c +++ b/src/npc/castleMaid.c @@ -69,7 +69,7 @@ void sub_08064570(CastleMaidEntity* this) { if (LoadExtraSpriteData(super, data) == 0) { return; } - super->action += 1; + super->action++; super->timer = 0; tmp2 = sub_0805ACC0(super); if (tmp2 == 0) { @@ -84,7 +84,7 @@ void sub_08064570(CastleMaidEntity* this) { case 1: sub_0807DD94(super, NULL); if (super->interactType != 0) { - super->action += 1; + super->action++; super->interactType = 0; InitializeAnimation(super, sub_0806F5A4(GetFacingDirection(super, &gPlayerEntity))); if (this->dialogFunc != NULL) { diff --git a/src/npc/drLeft.c b/src/npc/drLeft.c index 4168d951..d991340e 100644 --- a/src/npc/drLeft.c +++ b/src/npc/drLeft.c @@ -7,7 +7,7 @@ void sub_0806BFD8(Entity* this); void DrLeft(Entity* this) { if (this->type == 0) { if (this->action == 0) { - this->action += 1; + this->action++; SetDefaultPriority(this, PRIO_MESSAGE); sub_0807DD50(this); } @@ -17,7 +17,7 @@ void DrLeft(Entity* this) { sub_0806BFD8(this); } else { if (this->action == 0) { - this->action += 1; + this->action++; this->frameIndex = 0; SortEntityBelow(this, this); } diff --git a/src/npc/epona.c b/src/npc/epona.c index ce180670..5c5adafa 100644 --- a/src/npc/epona.c +++ b/src/npc/epona.c @@ -104,7 +104,7 @@ void sub_08065AA4(Entity* this) { void Epona_Fusion(Entity* this) { if (this->action == 0) { - this->action += 1; + this->action++; this->spriteSettings.draw = 1; InitAnimationForceUpdate(this, 7); } else { diff --git a/src/npc/forestMinish.c b/src/npc/forestMinish.c index 78661fae..1e833a02 100644 --- a/src/npc/forestMinish.c +++ b/src/npc/forestMinish.c @@ -121,7 +121,7 @@ void sub_08060158(Entity* this) { if (tmp2 & 0x80) { this->animationState = sub_0806F5B0(index); } - tmp2 &= 0x7f; + tmp2 &= ~0x80; this->frame = tmp1; this->frameIndex = tmp2; this->frameSpriteSettings = 1; diff --git a/src/npc/guardWithSpear.c b/src/npc/guardWithSpear.c index ed298050..f74b97ce 100644 --- a/src/npc/guardWithSpear.c +++ b/src/npc/guardWithSpear.c @@ -253,25 +253,25 @@ void sub_08064428(GuardWithSpearEntity* this) { ShowNPCDialogue(super, pDialog); } -void sub_08064470(Entity* this, ScriptExecutionContext* context) { - if (gPlayerState.field_0xab == 1) { +void GuardWithSpear_CheckSwordMoveSpin(Entity* this, ScriptExecutionContext* context) { + if (gPlayerState.lastSwordMove == SWORD_MOVE_SPIN) { context->condition = 1; } else { context->condition = 0; } } -void sub_08064488(void) { +void GuardWithSpear_ResetLastSwordMoveIfNotInSwordState(void) { if (gPlayerState.framestate != PL_STATE_SWORD) { - gPlayerState.field_0xab = 0; + gPlayerState.lastSwordMove = SWORD_MOVE_NONE; } } -void sub_080644A4(void) { - gPlayerState.field_0xab = 0; +void GuardWithSpear_ResetLastSwordMove(void) { + gPlayerState.lastSwordMove = SWORD_MOVE_NONE; } -void sub_080644B4(Entity* this, ScriptExecutionContext* context) { +void CheckLastSwordMove(Entity* this, ScriptExecutionContext* context) { context->condition = this->animationState == context->intVariable; } diff --git a/src/npc/mama.c b/src/npc/mama.c index 205c8e5a..ffe8abb6 100644 --- a/src/npc/mama.c +++ b/src/npc/mama.c @@ -100,7 +100,7 @@ void sub_0806C4F8(Entity* this) { void Mama_Fusion(Entity* this) { if (this->action == 0) { if (sub_0806C454(this) != 0) { - this->action += 1; + this->action++; this->spriteSettings.draw = 1; this->y.HALF.HI -= 4; InitializeAnimation(this, 2); diff --git a/src/npc/npc4E.c b/src/npc/npc4E.c index ea11cd38..91cfcbd1 100644 --- a/src/npc/npc4E.c +++ b/src/npc/npc4E.c @@ -180,8 +180,8 @@ void NPC4E_SaveEquippedItems(Entity* this) { } void NPC4E_RestoreEquippedItems(Entity* this) { - ForceEquipItem(sub_0806DBF4(this->field_0x68.HALF.LO), 0); - ForceEquipItem(sub_0806DBF4(this->field_0x68.HALF.HI), 1); + ForceEquipItem(sub_0806DBF4(this->field_0x68.HALF.LO), EQUIP_SLOT_A); + ForceEquipItem(sub_0806DBF4(this->field_0x68.HALF.HI), EQUIP_SLOT_B); } void sub_0806DC7C(void) { diff --git a/src/npc/npc58.c b/src/npc/npc58.c index 5a360a9a..5b916583 100644 --- a/src/npc/npc58.c +++ b/src/npc/npc58.c @@ -17,7 +17,7 @@ void NPC58(Entity* this) { if (LoadExtraSpriteData(this, gUnk_081146D0) == 0) { return; } - this->action += 1; + this->action++; this->spriteSettings.draw = 2; this->spriteRendering.b3 = 0; this->spritePriority.b0 = 0; diff --git a/src/npc/pina.c b/src/npc/pina.c index fecc2bf3..545a4097 100644 --- a/src/npc/pina.c +++ b/src/npc/pina.c @@ -29,7 +29,7 @@ void sub_08063A80(Entity* this) { } void sub_08063A98(Entity* this) { - this->action += 1; + this->action++; this->spriteSettings.draw = 1; InitAnimationForceUpdate(this, 4); sub_08078778(this); @@ -157,7 +157,7 @@ void sub_08063CAC(Entity* this) { void Pina_Fusion(Entity* this) { if (this->action == 0) { - this->action += 1; + this->action++; this->spriteSettings.draw = 1; this->y.HALF.HI -= 4; InitAnimationForceUpdate(this, 2); diff --git a/src/npc/townMinish.c b/src/npc/townMinish.c index abf4c69c..10de6135 100644 --- a/src/npc/townMinish.c +++ b/src/npc/townMinish.c @@ -320,7 +320,7 @@ void sub_0806AEE4(Entity* this) { if (tmp2 & 0x80) { this->animationState = sub_0806F5B0(index); } - tmp2 &= 0x7f; + tmp2 &= ~0x80; this->frame = tmp1; this->frameIndex = tmp2; this->frameSpriteSettings = 1; diff --git a/src/object.c b/src/object.c index d4771b3f..96729ee1 100644 --- a/src/object.c +++ b/src/object.c @@ -195,7 +195,7 @@ void (*const gObjectFunctions[])(Entity*) = { [PINWHEEL] = Pinwheel, [OBJECT_BF] = ObjectBF, [ENEMY_ITEM] = EnemyItem, - [OBJECT_C1] = LinkAnimation, + [LINK_ANIMATION] = LinkAnimation, }; void ObjectInit(Entity*); diff --git a/src/object/barrelSpiderweb.c b/src/object/barrelSpiderweb.c index 4c608779..3e555ece 100644 --- a/src/object/barrelSpiderweb.c +++ b/src/object/barrelSpiderweb.c @@ -71,7 +71,7 @@ void sub_0808BBE0(BarrelSpiderwebEntity* this) { ptr = &gUnk_0812144C[diff * 2]; SetAffineInfo(super, ptr[0], ptr[1], 0); } else { - super->contactFlags &= 0x7f; + super->contactFlags &= ~0x80; } } diff --git a/src/object/bigIceBlock.c b/src/object/bigIceBlock.c index bb0fb7ca..8814fe63 100644 --- a/src/object/bigIceBlock.c +++ b/src/object/bigIceBlock.c @@ -97,7 +97,7 @@ void BigIceBlock_Action2(BigIceBlockEntity* this) { } super->action = 3; super->timer = 60; - super->flags &= 0x7f; + super->flags &= ~0x80; } void sub_08099880(BigIceBlockEntity* this) { diff --git a/src/object/bird.c b/src/object/bird.c index 55f080ad..e6243f22 100644 --- a/src/object/bird.c +++ b/src/object/bird.c @@ -238,7 +238,7 @@ void Bird_Type8(Entity* this) { PutAwayItems(); gPlayerState.swim_state = 0; gPlayerState.jump_status = 0; - gPlayerEntity.flags &= 0x7f; + gPlayerEntity.flags &= ~0x80; gPlayerEntity.spriteSettings.draw = 0; gPriorityHandler.sys_priority = 6; gPauseMenuOptions.disabled = 1; diff --git a/src/object/book.c b/src/object/book.c index 941b5c52..ece50550 100644 --- a/src/object/book.c +++ b/src/object/book.c @@ -213,7 +213,7 @@ void Book_Action5(Entity* this) { u32 sub_0809B688(Entity* this) { u32 ret = EntityInRectRadius(this, &gPlayerEntity, 6, 12); - if (ret == 1 && gPlayerState.field_0xd != 16) { + if (ret == 1 && gPlayerState.direction != 16) { ret = 0; } diff --git a/src/object/crenelBeanSprout.c b/src/object/crenelBeanSprout.c index 0bf59d92..a0fb206d 100644 --- a/src/object/crenelBeanSprout.c +++ b/src/object/crenelBeanSprout.c @@ -140,7 +140,7 @@ void CrenelBeanSprout_Action1(CrenelBeanSproutEntity* this) { if (super->parent->action == 2) { switch (super->parent->subAction) { case 1: - if ((gPlayerState.field_0xd & 0x80) != 0) { + if ((gPlayerState.direction & 0x80) != 0) { InitializeAnimation(super, 4); } else { GetNextFrame(super); @@ -163,7 +163,7 @@ void CrenelBeanSprout_Action1(CrenelBeanSproutEntity* this) { } else { gPlayerState.mobility |= 0x80; gPlayerState.heldObject = 5; - if ((gPlayerState.field_0xd & 0x80) != 0) { + if ((gPlayerState.direction & 0x80) != 0) { InitializeAnimation(super, (super->type >> 1) + 3); } else { GetNextFrame(super); @@ -181,7 +181,7 @@ void CrenelBeanSprout_Action1(CrenelBeanSproutEntity* this) { RestorePrevTileEntity(0xdc, super->collisionLayer); sub_08096A78(this); } - if ((gPlayerState.playerInput.field_0x92 & (PLAYER_INPUT_80 | PLAYER_INPUT_40)) == 0) { + if ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_40)) == 0) { return; } if (gUnk_0200AF00.unk_2f != 3) { @@ -297,7 +297,7 @@ void CrenelBeanSprout_Action6SubAction1(CrenelBeanSproutEntity* this) { sub_0807B7D8(gUnk_081231AE[super->type2], COORD_TO_TILE(super), super->collisionLayer); super->type2++; if (super->type2 == super->subtimer) { - gPlayerState.keepFacing &= 0x7f; + gPlayerState.keepFacing &= ~0x80; super->subAction++; super->timer = 60; } else { diff --git a/src/object/fileScreenObjects.c b/src/object/fileScreenObjects.c index 868902b1..43dde1a2 100644 --- a/src/object/fileScreenObjects.c +++ b/src/object/fileScreenObjects.c @@ -9,8 +9,8 @@ #include "main.h" #include "menu.h" #include "object.h" +#include "player.h" -extern int sub_0807A094(int); extern u32 sub_080041EC(int, int); static bool32 sub_0808E950(void); @@ -104,7 +104,7 @@ void sub_0808E818(Entity* this) { this->field_0x68.HWORD = CheckGlobalFlag(EZERO_1ST) == 0 ? 0x400 : 0x100; this->field_0x70.BYTES.byte0 = 4; this->animationState = 2; - var1 = gUnk_08133368[sub_0807A094(1) - 22] & 0xFFFFFF; + var1 = gUnk_08133368[GetPlayerPalette(TRUE) - 22] & 0xFFFFFF; LoadPalettes(&gGlobalGfxAndPalettes[var1], 31, 1); } diff --git a/src/object/frozenOctorok.c b/src/object/frozenOctorok.c index 5415125e..85fbb2c0 100644 --- a/src/object/frozenOctorok.c +++ b/src/object/frozenOctorok.c @@ -319,7 +319,7 @@ void FrozenOctorok_Action1SubAction6(FrozenOctorokEntity* this) { super->subAction = 7; } if ((gRoomTransition.frameCount & 0xf) == 0) { - SoundReq(SFX_163); + SoundReq(SFX_TOGGLE_DIVING); } } diff --git a/src/object/houseDoorExterior.c b/src/object/houseDoorExterior.c index 225147a7..332a3ab4 100644 --- a/src/object/houseDoorExterior.c +++ b/src/object/houseDoorExterior.c @@ -179,7 +179,7 @@ void sub_0808692C(Entity* this) { static u8 sub_08086954(Entity* this) { if (sub_0800445C(this)) { if (GetAnimationStateInRectRadius(this, 6, 20) >= 0 && gPlayerEntity.animationState == 0 && - (u16)gPlayerState.playerInput.field_0x90 == PLAYER_INPUT_UP && gPlayerState.jump_status == 0) { + (u16)gPlayerState.playerInput.heldInput == PLAYER_INPUT_UP && gPlayerState.jump_status == 0) { this->timer--; } } else { diff --git a/src/object/houseDoorInterior.c b/src/object/houseDoorInterior.c index c8cc5334..50e8a7ba 100644 --- a/src/object/houseDoorInterior.c +++ b/src/object/houseDoorInterior.c @@ -92,7 +92,7 @@ void HouseDoorInterior_Action1(HouseDoorInteriorEntity* this) { if (sub_0800445C(super) && this->unk7d == 0) { ptr = gUnk_081227CC + super->type2; if (GetAnimationStateInRectRadius(super, ptr->x, ptr->y) >= 0 && - ptr->animationState == gPlayerEntity.animationState && gPlayerState.playerInput.field_0x90 & ptr->unk2) { + ptr->animationState == gPlayerEntity.animationState && gPlayerState.playerInput.heldInput & ptr->unk2) { --super->timer; } } else { diff --git a/src/object/itemForSale.c b/src/object/itemForSale.c index 283969f8..e4629fa1 100644 --- a/src/object/itemForSale.c +++ b/src/object/itemForSale.c @@ -99,7 +99,7 @@ void ItemForSale_Action1(ItemForSaleEntity* this) { super->interactType = 0; super->subAction = 1; sub_08078B48(); - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.heldObject = 4; gNewPlayerEntity.unk_74 = super; gUnk_0200AF00.unk_2f = 2; @@ -119,9 +119,9 @@ void ItemForSale_Action2(ItemForSaleEntity* this) { } else { ptr = sub_080784E4(); if (((*(int*)(ptr + 8) == 0) || - ((*(u8*)(ptr + 1) != 1 || (gUnk_0200AF00.unk_2f = 7, (gPlayerState.playerInput.field_0x92 & + ((*(u8*)(ptr + 1) != 1 || (gUnk_0200AF00.unk_2f = 7, (gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_8)) == 0)))) && - ((gPlayerState.playerInput.field_0x92 & (PLAYER_INPUT_80 | PLAYER_INPUT_10 | PLAYER_INPUT_8)) != 0)) { + ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_10 | PLAYER_INPUT_8)) != 0)) { sub_080819B4(this); } } diff --git a/src/object/lampParticle.c b/src/object/lampParticle.c index 38f1ed64..85c73532 100644 --- a/src/object/lampParticle.c +++ b/src/object/lampParticle.c @@ -28,7 +28,7 @@ void LampParticle_Init(Entity* this) { } void LampParticle_Action1(Entity* this) { - if (1 < IsItemEquipped(ITEM_LANTERN_ON)) { + if (IsItemEquipped(ITEM_LANTERN_ON) >= EQUIP_SLOT_NONE) { DeleteThisEntity(); } GetNextFrame(this); diff --git a/src/object/lilypadLarge.c b/src/object/lilypadLarge.c index e03dd38f..88cf601a 100644 --- a/src/object/lilypadLarge.c +++ b/src/object/lilypadLarge.c @@ -570,7 +570,7 @@ void sub_08085E74(LilypadLargeEntity* this) { if (gPlayerState.item != NULL) { DeleteEntity(gPlayerState.item); } - ResetPlayerItem(); + ResetActiveItems(); } void sub_08085EFC(LilypadLargeEntity* this) { diff --git a/src/object/macroPlayer.c b/src/object/macroPlayer.c index 79921a39..075d749e 100644 --- a/src/object/macroPlayer.c +++ b/src/object/macroPlayer.c @@ -10,6 +10,7 @@ #include "functions.h" #include "object.h" #include "physics.h" +#include "player.h" typedef struct { Entity base; @@ -17,8 +18,6 @@ typedef struct { u16 unk6a; } MacroPlayerEntity; -extern int sub_0807A094(int); - void MacroPlayer_Type0(MacroPlayerEntity*); void MacroPlayer_Type1(MacroPlayerEntity*); void MacroPlayer_Type0_Init(MacroPlayerEntity*); @@ -118,7 +117,7 @@ void MacroPlayer_Type0_Init(MacroPlayerEntity* this) { super->spriteRendering.b0 = 3; SetAffineInfo(super, 4, 4, 0); gUnk_02018EB0.unk_14 = super; - ChangeObjPalette(super, sub_0807A094(0)); + ChangeObjPalette(super, GetPlayerPalette(FALSE)); pEVar1 = CreateObject(PORTAL_FALLING_PLAYER, 1, 0); if (pEVar1 != NULL) { pEVar1->parent = super; diff --git a/src/object/minecart.c b/src/object/minecart.c index bb839de4..eba55180 100644 --- a/src/object/minecart.c +++ b/src/object/minecart.c @@ -12,7 +12,7 @@ typedef struct { Entity base; u8 filler[0x1C]; - struct_030010EC* minecartData; + MinecartData* minecartData; } MinecartEntity; extern void sub_08017744(Entity*); @@ -39,7 +39,7 @@ void Minecart(Entity* this) { } void Minecart_Init(MinecartEntity* this) { - struct_030010EC* unk = &gRoomTransition.minecart_data[super->timer]; + MinecartData* unk = &gRoomTransition.minecart_data[super->timer]; this->minecartData = unk; if ((gRoomControls.room != unk->room) || (gPlayerState.flags & PL_IN_MINECART) != 0) { @@ -88,7 +88,7 @@ void Minecart_Action1(MinecartEntity* this) { gPlayerEntity.zVelocity = Q_16_16(2.0); gPlayerEntity.speed = 0x100; gPlayerEntity.flags &= ~PL_MINISH; - ResetPlayerItem(); + ResetActiveItems(); DeleteClones(); SoundReq(SFX_PLY_JUMP); } @@ -279,7 +279,7 @@ void Minecart_Action5(MinecartEntity* this) { } void Minecart_Action6(MinecartEntity* this) { - struct_030010EC* minecartData; + MinecartData* minecartData; if (gPlayerState.jump_status == 0) { super->action = 1; diff --git a/src/object/minishSizedEntrance.c b/src/object/minishSizedEntrance.c index f8904c9c..c12192c2 100644 --- a/src/object/minishSizedEntrance.c +++ b/src/object/minishSizedEntrance.c @@ -46,7 +46,7 @@ void MinishSizedEntrance_Action1(Entity* this) { } } if ((gPlayerState.flags & PL_MINISH) && EntityInRectRadius(this, &gPlayerEntity, 4, 4) && - (gPlayerEntity.z.HALF.HI == 0) && (((u16)gPlayerState.playerInput.field_0x90) & gUnk_0812225C[this->type2])) { + (gPlayerEntity.z.HALF.HI == 0) && (((u16)gPlayerState.playerInput.heldInput) & gUnk_0812225C[this->type2])) { DoExitTransition(GetCurrentRoomProperty(this->timer)); } } diff --git a/src/object/octorokBossObject.c b/src/object/octorokBossObject.c index ad3afd84..eb1a2f1e 100644 --- a/src/object/octorokBossObject.c +++ b/src/object/octorokBossObject.c @@ -166,7 +166,7 @@ NONMATCH("asm/non_matching/octorokBossObject/OctorokBossObject_Action1.inc", this->child->parent = this->parent; GET_HELPER(this->child) = GET_HELPER(this); } - this->type2 += 1; + this->type2++; } CopyPosition(GET_HELPER(this)->tailObjects[0], this); return; @@ -193,7 +193,7 @@ NONMATCH("asm/non_matching/octorokBossObject/OctorokBossObject_Action1.inc", this->parent->subAction = 0; return; } - this->timer += 1; + this->timer++; return; case 2: if (this->parent->type2 == 3) { diff --git a/src/object/playerClone.c b/src/object/playerClone.c index 3dd8b990..e898dcfe 100644 --- a/src/object/playerClone.c +++ b/src/object/playerClone.c @@ -169,7 +169,7 @@ void sub_08084B1C(PlayerCloneEntity* this) { super->collisionFlags = gPlayerEntity.collisionFlags; super->hurtType = gPlayerEntity.hurtType; CopyPosition(super, super->child); - if (gPlayerState.field_0x3[1] != 0) { + if (gPlayerState.attack_status != 0) { super->child->damage = gPlayerState.item->damage; super->child->frameIndex = gPlayerState.item->frameIndex; super->child->spriteSettings.flipX = gPlayerState.item->spriteSettings.flipX; diff --git a/src/object/pot.c b/src/object/pot.c index 6c62da39..0e024f6f 100644 --- a/src/object/pot.c +++ b/src/object/pot.c @@ -121,7 +121,7 @@ void Pot_Action1(Entity* this) { if (GetTileUnderEntity(this) == 13) { CreateFx(this, FX_FALL_DOWN, 0); } else if (tileType == 0x4005) { - gPlayerState.field_0xab = 4; + gPlayerState.lastSwordMove = SWORD_MOVE_BREAK_POT; SetTile((u16)this->field_0x70.HALF.LO, COORD_TO_TILE(this), this->collisionLayer); } sub_08082850(this, NULL); diff --git a/src/object/pullableMushroom.c b/src/object/pullableMushroom.c index c03f3444..22982728 100644 --- a/src/object/pullableMushroom.c +++ b/src/object/pullableMushroom.c @@ -222,7 +222,7 @@ void sub_0808AEB0(PullableMushroomEntity* this) { u32 uVar1; if (super->timer != 0) { uVar1 = sub_0808B1F0(this, super->child); - if ((gPlayerState.playerInput.field_0x90 & gUnk_081211E4[super->animationState]) != 0) { + if ((gPlayerState.playerInput.heldInput & gUnk_081211E4[super->animationState]) != 0) { GetNextFrame(super); if (uVar1 < 0x40) { sub_080044AE(&gPlayerEntity, 0x40, super->direction); @@ -247,7 +247,7 @@ void sub_0808AEB0(PullableMushroomEntity* this) { this->unk_7c = 1; super->animationState = AnimationStateFlip90(gPlayerEntity.animationState >> 1); super->direction = (super->animationState << 3); - super->flags &= 0x7f; + super->flags &= ~0x80; super->spriteSettings.flipX = gPlayerEntity.spriteSettings.flipX; InitializeAnimation(super, super->animationState + 5); if (sub_0808B21C(this, 0)) { @@ -291,7 +291,7 @@ void sub_0808B05C(PullableMushroomEntity* this) { super->animationState = AnimationStateFlip90(gPlayerEntity.animationState >> 1); super->direction = super->animationState << 3; super->spriteSettings.flipX = gPlayerEntity.spriteSettings.flipX; - super->flags &= 0x7f; + super->flags &= ~0x80; InitializeAnimation(super, super->animationState + 5); if (sub_0808B21C(this, 1)) { sub_0808B168((PullableMushroomEntity*)super->child, 1); diff --git a/src/object/pushableRock.c b/src/object/pushableRock.c index 56b2e10c..29b3fdd8 100644 --- a/src/object/pushableRock.c +++ b/src/object/pushableRock.c @@ -32,7 +32,7 @@ void PushableRock(PushableRockEntity* this) { void PushableRock_Init(PushableRockEntity* this) { super->spriteSettings.draw = 1; - super->action += 1; + super->action++; super->spriteRendering.b3 = 2; super->spritePriority.b0 = 4; super->spritePriority.b1 = 3; diff --git a/src/object/smallIceBlock.c b/src/object/smallIceBlock.c index 54a5bd7e..edd3aac5 100644 --- a/src/object/smallIceBlock.c +++ b/src/object/smallIceBlock.c @@ -148,7 +148,7 @@ void SmallIceBlock_Action3(SmallIceBlockEntity* this) { } super->action = 4; super->timer = 60; - super->flags &= 0x7f; + super->flags &= ~0x80; } void SmallIceBlock_Action4(SmallIceBlockEntity* this) { diff --git a/src/object/smokeParticle.c b/src/object/smokeParticle.c index 8cca7eff..de97206b 100644 --- a/src/object/smokeParticle.c +++ b/src/object/smokeParticle.c @@ -53,7 +53,7 @@ void SmokeParticle_Action1(Entity* this) { if (this->frame < 5) { this->hitbox = (Hitbox*)gUnk_08120A54[this->frame]; } else { - this->flags &= 0x7f; + this->flags &= ~0x80; } } } diff --git a/src/object/swordParticle.c b/src/object/swordParticle.c index fbdb0e52..3e197a29 100644 --- a/src/object/swordParticle.c +++ b/src/object/swordParticle.c @@ -70,7 +70,7 @@ void SwordParticle_Action1(SwordParticleEntity* this) { u32 tmp2; if (super->type2 != 0) { - if ((gPlayerState.field_0x1f[2] == 0) || ((gPlayerState.field_0x3[1] & 0x80) != 0)) { + if ((gPlayerState.field_0x1f[2] == 0) || ((gPlayerState.attack_status & 0x80) != 0)) { DeleteThisEntity(); } if (gPlayerState.field_0x1f[2] >= 0x50) { @@ -85,7 +85,7 @@ void SwordParticle_Action1(SwordParticleEntity* this) { DeleteThisEntity(); } } else { - if (gPlayerState.field_0x3[1] == 0) { + if (gPlayerState.attack_status == 0) { DeleteThisEntity(); } if ((gPlayerState.sword_state & 1) != 0) { diff --git a/src/object/thunderbold.c b/src/object/thunderbold.c index 6128b74d..3b3f7fa3 100644 --- a/src/object/thunderbold.c +++ b/src/object/thunderbold.c @@ -42,7 +42,7 @@ void Thunderbold(ThunderboldEntity* this) { void Thunderbold_Init(ThunderboldEntity* this) { const struct_08122950* ptr; super->action = 1; - super->flags &= 0x7f; + super->flags &= ~0x80; super->spriteSettings.draw = 1; if (super->collisionLayer == 0) { ResolveCollisionLayer(super); diff --git a/src/object/unusedSkull.c b/src/object/unusedSkull.c index 30c6ec1f..c6a2e1f5 100644 --- a/src/object/unusedSkull.c +++ b/src/object/unusedSkull.c @@ -53,7 +53,7 @@ void UnusedSkull_Init(UnusedSkullEntity* this) { void UnusedSkull_Action1(UnusedSkullEntity* this) { if (super->contactFlags == 0x9c) { super->action = 2; - super->flags &= 0x7f; + super->flags &= ~0x80; CreateFx(super, FX_ICE, 0); EnqueueSFX(SFX_10D); } diff --git a/src/objectDefinitions.c b/src/objectDefinitions.c index 4a0186a1..29c5e352 100644 --- a/src/objectDefinitions.c +++ b/src/objectDefinitions.c @@ -6,94 +6,94 @@ const Hitbox* const gObjectHitboxes[] = { NULL, &gHitbox_0, &gHitbox_30, &gHitbox_2, &gHitbox_3 }; const ObjectDefinition gObjectDefinition_F[] = { - { { 1, 0, 0, 0, 59, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_FALL_DOWN - { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_EXPLOSION - { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_DEATH - { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BUSH - { { 1, 0, 0, 0, 81, 2, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ROCK - { { 1, 0, 0, 0, 236, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_POT_SHATTER - { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_6 - { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SPARKLE - { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_8 - { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_9 - { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_A - { { 1, 0, 0, 0, 72, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_WATER_SPLASH - { { 1, 0, 0, 0, 78, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_LAVA_SPLASH - { { 1, 0, 0, 0, 85, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ICE - { { 1, 0, 0, 0, 18, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ROCK_HUGE - { { 1, 0, 0, 0, 81, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ROCK_SMALL - { { 1, 0, 0, 0, 93, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_REFLECT - { { 1, 0, 0, 0, 89, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_DASH - { { 1, 0, 0, 0, 0, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BLUE_SPARKLE - { { 1, 0, 0, 0, 228, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_RED_BUSH - { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SPARKLE2 - { { 1, 0, 0, 0, 81, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ROCK2 - { { 1, 0, 0, 0, 176, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_FIRE - { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT - { { 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }, // FX_18 - { { 1, 0, 0, 0, 0, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SWORD_MAGIC - { { 1, 0, 0, 0, 64, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_LIGHTNING - { { 1, 0, 0, 0, 4, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_LIGHTNING_STRIKE - { { 1, 0, 0, 0, 32, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_STARS - { { 1, 0, 0, 0, 32, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_STARS_STRIKE - { { 1, 0, 0, 0, 32, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_STARS_STRIKE2 - { { 1, 0, 0, 0, 28, 0, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_REFLECT2 - { { 1, 0, 0, 0, 20, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_RIPPLE - { { 1, 0, 0, 0, 30, 0, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_RIPPLE_LARGE - { { 1, 0, 0, 0, 154, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BROWN_SMOKE - { { 1, 0, 0, 0, 154, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BROWN_SMOKE_LARGE - { { 1, 0, 0, 0, 154, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BROWN_SMOKE2 - { { 1, 0, 0, 0, 243, 0, 0 }, { 1, 0, 0, 0, 163, 0, 0 } }, // FX_SWEAT - { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_26 - { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, 163, 0, 0 } }, // FX_27 - { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SLOW_EXPLOSION - { { 1, 0, 0, 0, 113, 0, 0 }, { 71, 0, 0, 0, 163, 0, 0 } }, // FX_CONFETTI - { { 1, 0, 0, 0, 113, 0, 0 }, { 71, 0, 0, 0, 163, 0, 0 } }, // FX_CONFETTI_LARGE - { { 1, 0, 0, 0, 72, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GREEN_SPLASH2 - { { 1, 0, 0, 0, 93, 2, 0 }, { 1, 0, 0, 0, 163, 0, 0 } }, // FX_REFLECT3 - { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, 163, 0, 0 } }, // FX_SIGN - { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SLOW_SMOKE2 - { { 1, 0, 0, 0, 89, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SLOW_SMOKE_SMALL - { { 1, 0, 0, 0, 57, 2, 0 }, { 171, 0, 0, 0, 163, 0, 0 } }, // FX_SPARKLE_SECRET - { { 1, 0, 0, 0, 205, 2, 0 }, { 3, 0, 0, 0, 163, 0, 0 } }, // FX_MAILBOX_UNUSED - { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, 163, 0, 0 } }, // FX_32 - { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, 163, 0, 0 } }, // FX_33 - { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, 163, 0, 0 } }, // FX_34 - { { 1, 0, 0, 0, 96, 2, 0 }, { 3, 0, 0, 0, 162, 0, 1 } }, // FX_BIG_EXPLOSION - { { 1, 0, 0, 0, 78, 2, 0 }, { 0, 0, 0, 0, 163, 0, 1 } }, // FX_LAVA_SPLASH_HUGE - { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT2 - { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BUSH_CUT2 - { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BUSH_CUT3 - { { 1, 0, 0, 0, 29, 2, 0 }, { 3, 0, 0, 0, 163, 0, 0 } }, // FX_EGG - { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, 163, 0, 0 } }, // FX_WOOD - { { 1, 0, 0, 0, 366, 0, 0 }, { 0, 0, 0, 0, 163, 0, 0 } }, // FX_BONE - { { 1, 0, 0, 0, 379, 0, 0 }, { 4, 0, 0, 0, 163, 0, 1 } }, // FX_STARS2 - { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT3 - { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT4 - { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT5 - { { 1, 0, 0, 0, 28, 0, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_REFLECT4 - { { 1, 0, 0, 0, 372, 0, 0 }, { 0, 0, 0, 0, 163, 0, 1 } }, // FX_STEAM_EFC - { { 1, 0, 0, 0, 96, 2, 0 }, { 3, 0, 0, 0, 162, 0, 1 } }, // FX_BIG_EXPLOSION2 - { { 1, 0, 0, 0, 446, 0, 0 }, { 184, 0, 0, 0, 163, 0, 1 } }, // FX_WHITE_SPLASH - { { 1, 0, 0, 0, 85, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_WHITE_ROCK - { { 1, 0, 0, 0, 452, 0, 0 }, { 0, 0, 0, 0, 163, 0, 1 } }, // FX_GIANT_EXPLOSION - { { 1, 0, 0, 0, 452, 0, 0 }, { 0, 0, 0, 0, 163, 0, 1 } }, // FX_GIANT_EXPLOSION2 - { { 1, 0, 0, 0, 452, 0, 0 }, { 0, 0, 0, 0, 163, 0, 1 } }, // FX_GIANT_EXPLOSION3 - { { 1, 0, 0, 0, 457, 0, 0 }, { 285, 0, 0, 0, 163, 0, 1 } }, // FX_GREEN_ORB - { { 1, 0, 0, 0, 458, 0, 0 }, { 285, 0, 0, 0, 163, 0, 1 } }, // FX_GREEN_ORB_SLOW - { { 1, 0, 0, 0, 459, 0, 0 }, { 3, 0, 0, 0, 163, 0, 1 } }, // FX_WHITE_AURA - { { 1, 0, 0, 0, 29, 2, 0 }, { 4, 0, 0, 0, 163, 0, 0 } }, // FX_WOOD2 - { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SPARKLE3 - { { 1, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 163, 0, 1 } }, // FX_MAGIC_STORM - { { 1, 0, 0, 0, 0, 0, 0 }, { 4, 0, 0, 0, 163, 0, 1 } }, // FX_BLUE_EFC - { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, 163, 0, 1 } }, // FX_REFLECT5 - { { 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 163, 0, 1 } }, // FX_GIANT_EXPLOSION4 - { { 1, 0, 0, 0, 78, 2, 0 }, { 382, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GREEN_SPLASH - { { 1, 0, 0, 0, 154, 2, 0 }, { 319, 0, 0, 0, 162, 0, 1 } }, // FX_BLUE_PUFF - { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, 162, 0, 1 } }, // FX_WHITE_PUFF - { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_AURA_BASE - { { 1, 0, 0, 0, 217, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_READ_AURA - { { 1, 0, 0, 0, 217, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_BLUE_AURA + { { 1, 0, 0, 0, 59, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_FALL_DOWN + { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_EXPLOSION + { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_DEATH + { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BUSH + { { 1, 0, 0, 0, 81, 2, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ROCK + { { 1, 0, 0, 0, 236, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_POT_SHATTER + { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_6 + { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SPARKLE + { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_8 + { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_9 + { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_A + { { 1, 0, 0, 0, 72, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_WATER_SPLASH + { { 1, 0, 0, 0, 78, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_LAVA_SPLASH + { { 1, 0, 0, 0, 85, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ICE + { { 1, 0, 0, 0, 18, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ROCK_HUGE + { { 1, 0, 0, 0, 81, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ROCK_SMALL + { { 1, 0, 0, 0, 93, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_REFLECT + { { 1, 0, 0, 0, 89, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_DASH + { { 1, 0, 0, 0, 0, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BLUE_SPARKLE + { { 1, 0, 0, 0, 228, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_RED_BUSH + { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SPARKLE2 + { { 1, 0, 0, 0, 81, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_ROCK2 + { { 1, 0, 0, 0, 176, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_FIRE + { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT + { { 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }, // FX_18 + { { 1, 0, 0, 0, 0, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SWORD_MAGIC + { { 1, 0, 0, 0, 64, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_LIGHTNING + { { 1, 0, 0, 0, 4, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_LIGHTNING_STRIKE + { { 1, 0, 0, 0, 32, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_STARS + { { 1, 0, 0, 0, 32, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_STARS_STRIKE + { { 1, 0, 0, 0, 32, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_STARS_STRIKE2 + { { 1, 0, 0, 0, 28, 0, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_REFLECT2 + { { 1, 0, 0, 0, 20, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_RIPPLE + { { 1, 0, 0, 0, 30, 0, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_RIPPLE_LARGE + { { 1, 0, 0, 0, 154, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BROWN_SMOKE + { { 1, 0, 0, 0, 154, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BROWN_SMOKE_LARGE + { { 1, 0, 0, 0, 154, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BROWN_SMOKE2 + { { 1, 0, 0, 0, 243, 0, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_SWEAT + { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_26 + { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_27 + { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SLOW_EXPLOSION + { { 1, 0, 0, 0, 113, 0, 0 }, { 71, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_CONFETTI + { { 1, 0, 0, 0, 113, 0, 0 }, { 71, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_CONFETTI_LARGE + { { 1, 0, 0, 0, 72, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GREEN_SPLASH2 + { { 1, 0, 0, 0, 93, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_REFLECT3 + { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_SIGN + { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SLOW_SMOKE2 + { { 1, 0, 0, 0, 89, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SLOW_SMOKE_SMALL + { { 1, 0, 0, 0, 57, 2, 0 }, { 171, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_SPARKLE_SECRET + { { 1, 0, 0, 0, 205, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_MAILBOX_UNUSED + { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_32 + { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_33 + { { 1, 0, 0, 0, 96, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_34 + { { 1, 0, 0, 0, 96, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 1 } }, // FX_BIG_EXPLOSION + { { 1, 0, 0, 0, 78, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_LAVA_SPLASH_HUGE + { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT2 + { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BUSH_CUT2 + { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_BUSH_CUT3 + { { 1, 0, 0, 0, 29, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_EGG + { { 1, 0, 0, 0, 0, 0, 0 }, { 5, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_WOOD + { { 1, 0, 0, 0, 366, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_BONE + { { 1, 0, 0, 0, 379, 0, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_STARS2 + { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT3 + { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT4 + { { 1, 0, 0, 0, 228, 2, 0 }, { 2, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GRASS_CUT5 + { { 1, 0, 0, 0, 28, 0, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_REFLECT4 + { { 1, 0, 0, 0, 372, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_STEAM_EFC + { { 1, 0, 0, 0, 96, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 1 } }, // FX_BIG_EXPLOSION2 + { { 1, 0, 0, 0, 446, 0, 0 }, { 184, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_WHITE_SPLASH + { { 1, 0, 0, 0, 85, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_WHITE_ROCK + { { 1, 0, 0, 0, 452, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_GIANT_EXPLOSION + { { 1, 0, 0, 0, 452, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_GIANT_EXPLOSION2 + { { 1, 0, 0, 0, 452, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_GIANT_EXPLOSION3 + { { 1, 0, 0, 0, 457, 0, 0 }, { 285, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_GREEN_ORB + { { 1, 0, 0, 0, 458, 0, 0 }, { 285, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_GREEN_ORB_SLOW + { { 1, 0, 0, 0, 459, 0, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_WHITE_AURA + { { 1, 0, 0, 0, 29, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 0 } }, // FX_WOOD2 + { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_SPARKLE3 + { { 1, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_MAGIC_STORM + { { 1, 0, 0, 0, 0, 0, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_BLUE_EFC + { { 1, 0, 0, 0, 60, 2, 0 }, { 4, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_REFLECT5 + { { 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_GIANT_EXPLOSION4 + { { 1, 0, 0, 0, 78, 2, 0 }, { 382, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_GREEN_SPLASH + { { 1, 0, 0, 0, 154, 2, 0 }, { 319, 0, 0, 0, SPRITE_SPECIALFX, 0, 1 } }, // FX_BLUE_PUFF + { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 1 } }, // FX_WHITE_PUFF + { { 1, 0, 0, 0, 154, 2, 0 }, { 3, 0, 0, 0, SPRITE_SPECIALFX, 0, 0 } }, // FX_AURA_BASE + { { 1, 0, 0, 0, 217, 2, 0 }, { 0, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_READ_AURA + { { 1, 0, 0, 0, 217, 2, 0 }, { 1, 0, 0, 0, SPRITE_SPECIALFX_1, 0, 1 } }, // FX_BLUE_AURA }; #ifdef EU const ObjectDefinition gObjectDefinition_7[] = { diff --git a/src/objectUtils.c b/src/objectUtils.c index 7b748c6d..a3dc0132 100644 --- a/src/objectUtils.c +++ b/src/objectUtils.c @@ -13,10 +13,10 @@ extern const ObjectDefinition gObjectDefinitions[]; static Entity* CreateSpeechBubble(Entity*, u32, s32, s32); -Entity* sub_080A276C(Entity* parent, u32 type, u32 type2) { +Entity* CreateLinkAnimation(Entity* parent, u32 type, u32 type2) { Entity* e = CreateItemGetEntity(); if (e != NULL) { - e->id = OBJECT_C1; + e->id = LINK_ANIMATION; e->kind = OBJECT; e->type = type; e->type2 = type2; diff --git a/src/physics.c b/src/physics.c index cd09c05b..dcc2eaa3 100644 --- a/src/physics.c +++ b/src/physics.c @@ -83,7 +83,7 @@ bool32 sub_0806F3E4(Entity* ent) { ent->subAction = 3; gNewPlayerEntity.unk_70 = ent; gPlayerState.field_0x1c = 7; - item = CreatePlayerItem(PLAYER_ITEM_11, 0, 0, 0); + item = CreatePlayerItem(PLAYER_ITEM_GUST_BIG, 0, 0, 0); if (item != NULL) { item->child = ent; ent->parent = item; @@ -247,10 +247,10 @@ bool32 sub_0806F8DC(Entity* ent) { u32 sub_0806F948(Entity* ent) { u32 v1; - if (gPlayerState.field_0xd == 0xFF) + if (gPlayerState.direction == 0xFF) return ent->animationState; - v1 = gPlayerState.field_0xd / 4; + v1 = gPlayerState.direction / 4; if ((v1 & 1) && !(((v1 + 1) - ent->animationState) & 4)) { return ent->animationState; } else { diff --git a/src/player.c b/src/player.c index c5299bc1..242a5322 100644 --- a/src/player.c +++ b/src/player.c @@ -5,24 +5,24 @@ * @brief Player entity */ -#include "global.h" -#include "collision.h" -#include "asm.h" -#include "sound.h" -#include "entity.h" -#include "player.h" -#include "message.h" -#include "common.h" #include "area.h" -#include "item.h" -#include "save.h" -#include "object.h" +#include "asm.h" +#include "collision.h" +#include "common.h" +#include "entity.h" #include "functions.h" -#include "hitbox.h" #include "game.h" -#include "screen.h" +#include "global.h" +#include "hitbox.h" +#include "item.h" #include "main.h" +#include "message.h" +#include "object.h" +#include "player.h" #include "playeritem.h" +#include "save.h" +#include "screen.h" +#include "sound.h" #define GRAVITY_RATE Q_8_8(32) #define SLOPE_SPEED_MODIFIER 0x50 @@ -340,9 +340,9 @@ void DoPlayerAction(Entity* this) { } static void PlayerInit(Entity* this) { - u32 equip_status; + u32 equipSlot; - gPlayerState.field_0x0[0] = 0xff; + gPlayerState.prevAnim = 0xff; gPlayerState.startPosX = gPlayerEntity.x.HALF.HI; gPlayerState.startPosY = gPlayerEntity.y.HALF.HI; COLLISION_ON(this); @@ -364,9 +364,9 @@ static void PlayerInit(Entity* this) { ResolveCollisionLayer(this); } - equip_status = IsItemEquipped(ITEM_LANTERN_ON); - if (equip_status != 2) { - sub_08077728(equip_status); + equipSlot = IsItemEquipped(ITEM_LANTERN_ON); + if (equipSlot != EQUIP_SLOT_NONE) { + CreateItemEquippedAtSlot(equipSlot); } DeleteClones(); UpdatePlayerSkills(); @@ -379,7 +379,7 @@ static void PlayerInit(Entity* this) { gPlayerState.swim_state = 1; ResolvePlayerAnimation(); gPlayerState.framestate = PL_STATE_SWIM; - sub_0807ACCC(this); + PlayerSwimming(this); ent = FindEntity(OBJECT, SPECIAL_FX, 0x6, FX_WATER_SPLASH, 0x0); if (ent != NULL) { DeleteEntity(ent); @@ -401,12 +401,11 @@ static void PlayerNormal(Entity* this) { else gPlayerState.animation = 604; sub_0806F948(&gPlayerEntity); - ResetPlayerItem(); - sub_08077698(this); + ResetActiveItems(); + UpdateActiveItems(this); return; } if (gPlayerState.flags & PL_IN_MINECART) { - u32 x; this->hurtType = 30; gPlayerState.framestate = PL_STATE_C; sub_08070BEC(this, this->speed == 0 ? 1 : 0); @@ -422,7 +421,7 @@ static void PlayerNormal(Entity* this) { return; } if (!gPlayerState.swim_state && (gPlayerState.jump_status & 0xC0) == 0) { - if (gPlayerState.field_0x3[0] || gPlayerState.field_0x1f[2]) { + if (gPlayerState.shield_status || gPlayerState.field_0x1f[2]) { this->speed = SHIELDING_SPEED; } else { if (gPlayerState.sword_state) { @@ -446,7 +445,7 @@ static void PlayerNormal(Entity* this) { if (gPlayerState.jump_status == 0 && (gPlayerState.flags & PL_BURNING) == 0) { if (this->knockbackDuration == 0 && sub_080782C0()) { if (gRoomVars.shopItemType == 0) { - ResetPlayerItem(); + ResetActiveItems(); } if ((gPlayerState.flags & (PL_USE_OCARINA | PL_FLAGS2)) == 0) { UpdateFloorType(); @@ -456,7 +455,7 @@ static void PlayerNormal(Entity* this) { } if (((gPlayerState.flags & (PL_BUSY | PL_DROWNING | PL_USE_PORTAL | PL_CAPTURED | PL_FALLING | PL_BURNING | PL_IN_MINECART | PL_ROLLING)) | - gPlayerState.field_0xaa) == 0) { + gPlayerState.attachedBeetleCount) == 0) { switch (UpdatePlayerCollision()) { case 0: gPlayerState.pushedObject ^= 0x80; @@ -486,7 +485,7 @@ static void PlayerNormal(Entity* this) { if (sub_0807AC54(this)) { return; } - sub_08077698(this); + UpdateActiveItems(this); if (CheckQueuedAction()) return; @@ -511,7 +510,7 @@ static void PlayerNormal(Entity* this) { } } UpdatePlayerMovement(); - if ((this->frame & 2) == 0 && !gPlayerState.field_0x3[1]) + if ((this->frame & 2) == 0 && !gPlayerState.attack_status) UpdateAnimationSingleFrame(this); return; } @@ -520,7 +519,7 @@ static void PlayerNormal(Entity* this) { if (gPlayerState.swim_state) { gPlayerState.framestate = PL_STATE_SWIM; - sub_0807ACCC(this); + PlayerSwimming(this); } else { if ((gPlayerState.flags & PL_CONVEYOR_PUSHED) == 0) this->spritePriority.b1 = 1; @@ -536,10 +535,10 @@ static void PlayerNormal(Entity* this) { } } if ((gPlayerState.sword_state & 0x10) == 0) { - this->direction = gPlayerState.field_0xd; + this->direction = gPlayerState.direction; if (gPlayerState.flags & PL_BURNING) { this->speed = BURNING_SPEED; - if ((gPlayerState.field_0xd & 0x80) != 0) + if ((gPlayerState.direction & 0x80) != 0) this->direction = 4 * (this->animationState & 0xE); DeleteClones(); } @@ -582,7 +581,7 @@ static void PlayerFall(Entity* this) { PlayerFallUpdate, }; - gPlayerState.field_0xd = 0xFF; + gPlayerState.direction = 0xFF; gPlayerState.pushedObject = 0x80; gPlayerState.framestate = PL_STATE_FALL; @@ -607,7 +606,7 @@ static void PlayerFallInit(Entity* this) { this->subAction++; COLLISION_OFF(this); this->spritePriority.b1 = 0; - ResetPlayerItem(); + ResetActiveItems(); DeleteClones(); SoundReq(SFX_PLY_VO7); SoundReq(SFX_FALL_HOLE); @@ -660,7 +659,7 @@ static void PlayerBounceInit(Entity* this) { gPlayerState.jump_status = 0x80; SoundReq(SFX_14C); - ResetPlayerItem(); + ResetActiveItems(); ResetPlayerVelocity(); } @@ -798,7 +797,7 @@ static void PlayerItemGetInit(Entity* this) { } this->subAction = 1; - ResetPlayerItem(); + ResetActiveItems(); ResetPlayerVelocity(); } @@ -849,7 +848,7 @@ static void PlayerJumpInit(Entity* this) { if ((gPlayerState.heldObject | gPlayerState.sword_state) == 0) { if ((gPlayerState.flags & PL_MINISH) == 0) { - ResetPlayerItem(); + ResetActiveItems(); if (gPlayerState.flags & PL_NO_CAP) { gPlayerState.animation = 0x420; } else { @@ -970,7 +969,7 @@ static void PlayerDrownInit(Entity* this) { else gPlayerState.animation = 0x44c; } - ResetPlayerItem(); + ResetActiveItems(); } static void sub_080712F0(Entity* this) { @@ -1073,12 +1072,12 @@ static void PortalStandUpdate(Entity* this) { break; } - if ((gPlayerState.field_0xd & 0x84) == 0) { - if (this->direction != gPlayerState.field_0xd) { + if ((gPlayerState.direction & 0x84) == 0) { + if (this->direction != gPlayerState.direction) { this->timer = 8; } if (this->timer-- == 0) { - this->direction = gPlayerState.field_0xd; + this->direction = gPlayerState.direction; this->animationState = Direction8ToAnimationState(this->direction); this->zVelocity = Q_16_16(2.0); this->speed = JUMP_SPEED_FWD; @@ -1089,7 +1088,7 @@ static void PortalStandUpdate(Entity* this) { gPlayerState.flags &= ~PL_USE_PORTAL; return; } - this->direction = gPlayerState.field_0xd; + this->direction = gPlayerState.direction; } else { this->timer = 8; } @@ -1100,7 +1099,7 @@ static void PortalStandUpdate(Entity* this) { return; } } else { - sub_08077698(this); + UpdateActiveItems(this); } ResolvePlayerAnimation(); } @@ -1285,8 +1284,8 @@ static void PlayerTalkEzlo(Entity* this) { } static void PlayerTalkEzlo_Init(Entity* this) { - ResetPlayerItem(); - gUnk_03000B80[3].field_0xf = 0; + ResetActiveItems(); + gActiveItems[ACTIVE_ITEM_LANTERN].animPriority = 0; this->iframes = 0; gPriorityHandler.sys_priority = PRIO_PLAYER_EVENT; this->updatePriority = PRIO_PLAYER_EVENT; @@ -1522,7 +1521,7 @@ static void PlayerMinishDieInit(Entity* this) { gPlayerState.jump_status = 0; gPlayerState.pushedObject = 0; sub_0800451C(this); - ResetPlayerItem(); + ResetActiveItems(); SoundReq(SFX_PLY_DIE); } @@ -1656,7 +1655,7 @@ static void PlayerEmptyBottle(Entity* this) { static void PlayerEmptyBottleInit(Entity* this) { Entity* ent; - ResetPlayerItem(); + ResetActiveItems(); ent = CreatePlayerItemWithParent((ItemBehavior*)this, PLAYER_ITEM_BOTTLE); if (ent != NULL) { ent->field_0x68.HALF.LO = gPlayerState.field_0x38; @@ -1755,7 +1754,7 @@ static void sub_08072064(Entity* this) { COLLISION_OFF(this); this->timer = gPlayerState.field_0x3a; gPlayerState.animation = gPlayerState.field_0x38 | (gPlayerState.field_0x39 << 8); - ResetPlayerItem(); + ResetActiveItems(); } static void sub_08072098(Entity* this) { @@ -1799,7 +1798,7 @@ static void sub_08072100(Entity* this) { } else { gPlayerState.animation = 0x104; } - ResetPlayerItem(); + ResetActiveItems(); sub_08072168(this); } @@ -1814,7 +1813,7 @@ static void sub_08072168(Entity* this) { } else { UpdatePlayerMovement(); } - gPlayerState.field_0xd = this->direction; + gPlayerState.direction = this->direction; UpdatePlayerCollision(); if (this->timer-- == 0) { this->knockbackDuration = 0; @@ -1895,7 +1894,7 @@ static void PlayerLavaInit(Entity* this) { this->knockbackDuration = 10; } gPlayerState.flags |= (PL_BURNING | PL_BUSY); - ResetPlayerItem(); + ResetActiveItems(); SoundReq(SFX_124); SoundReq(SFX_PLY_VO6); } @@ -1978,7 +1977,7 @@ static void sub_080724DC(Entity* this) { DeleteClones(); if (GetTileUnderEntity(this) != 0x29) { if ((gPlayerState.remainingDiveTime == 0) && (gPlayerState.swim_state != 0)) { - sub_0807AE20(this); + PlayerUpdateSwimming(this); } if (gRoomControls.reload_flags == 0) { this->updatePriority = this->updatePriorityPrev; @@ -2002,7 +2001,7 @@ static void sub_080724DC(Entity* this) { static void sub_0807258C(Entity* this) { if (gRoomControls.reload_flags == 0) { - if (sub_0807A894(this) == 0x29) { + if (GetCollisionTileInFront(this) == 0x29) { UpdatePlayerMovement(); if (sub_080797C4() != 0) { gPlayerState.startPosX = gPlayerEntity.x.HALF.HI; @@ -2020,7 +2019,7 @@ static void sub_0807258C(Entity* this) { } } if ((gPlayerState.remainingDiveTime == 0) && (gPlayerState.swim_state != 0)) { - sub_0807AE20(this); + PlayerUpdateSwimming(this); } } @@ -2043,7 +2042,7 @@ static void PlayerRollInit(Entity* this) { } this->subAction = 1; this->timer = 0; - ResetPlayerItem(); + ResetActiveItems(); temp = gPlayerState.flags; if (gPlayerState.flags & PL_MINISH) { this->spritePriority.b1 = 0; @@ -2132,9 +2131,9 @@ static void PlayerRollUpdate(Entity* this) { this->hurtType = 0; } if (this->frame & 0x40) { - sub_08077698(this); + UpdateActiveItems(this); } - if ((this->frame & ANIM_DONE) || (gPlayerState.field_0x3[1] != 0)) { + if ((this->frame & ANIM_DONE) || (gPlayerState.attack_status != 0)) { ResetPlayerAnimationAndAction(); } if (this->frame & ANIM_DONE) { @@ -2195,7 +2194,7 @@ static void PlayerInHoleInit(Entity* this) { } } SetTile(0x4070, COORD_TO_TILE(this), this->collisionLayer); - ResetPlayerItem(); + ResetActiveItems(); PlayerInHoleUpdate(this); SoundReq(SFX_81); } @@ -2223,11 +2222,11 @@ static void PlayerInHoleUpdate(Entity* this) { } static void sub_08072ACC(Entity* this) { - if (gPlayerState.field_0xd == 0xff) { + if (gPlayerState.direction == 0xff) { this->subtimer = 0; } else if (this->subtimer > 7) { COLLISION_ON(this); - this->direction = gPlayerState.field_0xd; + this->direction = gPlayerState.direction; this->zVelocity = JUMP_SPEED_HOLE_Z; this->speed = JUMP_SPEED_HOLE_FWD; this->spritePriority.b0 = 4; @@ -2236,7 +2235,7 @@ static void sub_08072ACC(Entity* this) { PlayerSetNormalAndCollide(); RestorePrevTileEntity(COORD_TO_TILE(this), this->collisionLayer); } else { - this->animationState = Direction8ToAnimationState(gPlayerState.field_0xd); + this->animationState = Direction8ToAnimationState(gPlayerState.direction); this->subtimer++; } } @@ -2335,7 +2334,7 @@ static void sub_08072CFC(Entity* this) { gPlayerState.animation = 0x810; this->timer = 5; this->subtimer = 0; - ResetPlayerItem(); + ResetActiveItems(); } static const u16 sTiles[] = { @@ -2471,10 +2470,10 @@ static void sub_08072F94(Entity* this) { case SURFACE_CLIMB_WALL: case SURFACE_2C: this->spritePriority.b1 = 0; - bVar1 = gPlayerState.field_0xd; - if ((gPlayerState.field_0xd & 0x80) == 0) { - this->direction = gPlayerState.field_0xd; - if ((gPlayerState.field_0xd == 8) || (gPlayerState.field_0xd == 0x18)) { + bVar1 = gPlayerState.direction; + if ((gPlayerState.direction & 0x80) == 0) { + this->direction = gPlayerState.direction; + if ((gPlayerState.direction == 8) || (gPlayerState.direction == 0x18)) { if (gPlayerState.floor_type == SURFACE_LADDER) { return; } @@ -2613,7 +2612,7 @@ static void sub_080731D8(Entity* this) { } gRoomControls.camera_target = NULL; DeleteClones(); - ResetPlayerItem(); + ResetActiveItems(); } static void sub_080732D0(Entity* this) { @@ -2714,7 +2713,7 @@ static void sub_08073468(Entity* this) { gPlayerState.flags |= PL_PARACHUTE; CreateObjectWithParent(this, EZLO_CAP_FLYING, 0, 0); } - ResetPlayerItem(); + ResetActiveItems(); if (this->zVelocity > 0 || gPlayerState.field_0x38 == 1) COLLISION_OFF(this); } @@ -2749,7 +2748,7 @@ static void sub_08073504(Entity* this) { static void sub_08073584(Entity* this) { u32 state, dir, idx; - if ((gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_80) || this->iframes > 0 || gPlayerState.field_0x3c || + if ((gPlayerState.playerInput.newInput & PLAYER_INPUT_80) || this->iframes > 0 || gPlayerState.field_0x3c || (gPlayerState.flags & PL_PARACHUTE) == 0) { gPlayerState.jump_status |= 0x40; PlayerSetNormalAndCollide(); @@ -2771,9 +2770,9 @@ static void sub_08073584(Entity* this) { else this->speed = 0x80; - if ((gPlayerState.field_0xd & 0x80) == 0) { - if (this->direction != gPlayerState.field_0xd) { - if (((this->direction - gPlayerState.field_0xd) & 0x1F) < 0x10) + if ((gPlayerState.direction & 0x80) == 0) { + if (this->direction != gPlayerState.direction) { + if (((this->direction - gPlayerState.direction) & 0x1F) < 0x10) *(u32*)&this->field_0x80 -= 0x20; else *(u32*)&this->field_0x80 += 0x20; @@ -2802,8 +2801,8 @@ static void sub_08073584(Entity* this) { this->animationState = state; idx = 0; - state = gPlayerState.field_0xd >> 2; - if (!this->field_0x86.HALF.HI || ((gPlayerState.field_0xd & 0x80) == 0 && this->animationState != state)) { + state = gPlayerState.direction >> 2; + if (!this->field_0x86.HALF.HI || ((gPlayerState.direction & 0x80) == 0 && this->animationState != state)) { static const u16 sAnims1[] = { 0x0708, 0x071C, @@ -2811,7 +2810,7 @@ static void sub_08073584(Entity* this) { 0x0714, }; - if ((gPlayerState.field_0xd & 0x80) == 0) { + if ((gPlayerState.direction & 0x80) == 0) { if (this->animationState != state) { if (this->animationState == (state ^ 4)) { idx = 2; @@ -2947,7 +2946,7 @@ static void DoJump(Entity* this) { static void sub_08073924(Entity* this) { if ((gPlayerState.flags & PL_ROLLING) == 0 && (this->z.HALF.HI & 0x8000) && !gPlayerState.field_0xa) { gPlayerState.jump_status = 0x40; - gPlayerState.field_0xd = 0xff; + gPlayerState.direction = 0xff; this->direction = 0xff; PutAwayItems(); sub_08073968(this); @@ -2956,7 +2955,7 @@ static void sub_08073924(Entity* this) { static void sub_08073968(Entity* this) { if ((gPlayerState.jump_status & 0xC0) == 0) { - this->direction = gPlayerState.field_0xd; + this->direction = gPlayerState.direction; } CheckPlayerVelocity(); if ((gPlayerState.heldObject | gPlayerState.keepFacing) == 0) { @@ -2983,7 +2982,7 @@ static void sub_080739EC(Entity* this) { u32 v; if ((gPlayerState.jump_status & 0xC0) != 0) { - gPlayerState.field_0xd = this->direction; + gPlayerState.direction = this->direction; if (gPlayerState.jump_status & 0x80) this->collisions = COL_NONE; v = GRAVITY_RATE; @@ -3037,7 +3036,7 @@ static void sub_08073AD4(Entity* this) { if (gPlayerState.queued_action != PLAYER_INIT || gPlayerState.swim_state != 0) { return; } - if (gPlayerState.field_0x3[1]) + if (gPlayerState.attack_status) sub_08073B60(this); } gPlayerState.jump_status = tmp + 1; @@ -3050,7 +3049,7 @@ static void sub_08073AD4(Entity* this) { static void sub_08073B60(Entity* this) { gPlayerState.sword_state = 0; - gPlayerState.field_0x3[1] = 0; + gPlayerState.attack_status = 0; gPlayerState.jump_status = 0; ResolvePlayerAnimation(); sub_080085B0(this); @@ -3060,7 +3059,7 @@ static void sub_08073B60(Entity* this) { } void sub_08073B8C(Entity* this) { - if (!gPlayerState.field_0x3[1]) { + if (!gPlayerState.attack_status) { sub_08073B60(this); return; } @@ -3087,7 +3086,7 @@ void sub_08073B8C(Entity* this) { } void sub_08073C30(Entity* this) { - if (!gPlayerState.field_0x3[1] || this->timer-- == 0) { + if (!gPlayerState.attack_status || this->timer-- == 0) { sub_08073B60(this); } else { COLLISION_ON(this); @@ -3165,18 +3164,18 @@ static void sub_08073D20(Entity* this) { COLLISION_ON(this); } if (!UpdatePlayerCollision()) { - sub_08077698(this); + UpdateActiveItems(this); if (!GravityUpdate(this, GRAVITY_RATE)) gPlayerState.jump_status = 0; if ((gPlayerState.field_0x7 & 0x80) == 0 && !gPlayerState.field_0xa) { if (this->iframes <= 8) { if (gPlayerState.swim_state) { gPlayerState.framestate = PL_STATE_SWIM; - sub_0807ACCC(this); + PlayerSwimming(this); UpdatePlayerMovement(); } else { - this->direction = gPlayerState.field_0xd; - if ((gPlayerState.field_0xd & 0x80) == 0) { + this->direction = gPlayerState.direction; + if ((gPlayerState.direction & 0x80) == 0) { gPlayerState.framestate = PL_STATE_WALK; UpdatePlayerMovement(); } @@ -3211,7 +3210,7 @@ static void sub_08073F04(Entity* this) { this->zVelocity = Q_16_16(2.5); this->speed = 0x100; gPlayerState.flags &= ~PL_MINISH; - ResetPlayerItem(); + ResetActiveItems(); } static void sub_08073F4C(Entity* this) { @@ -3332,7 +3331,7 @@ void SurfaceAction_DoNothing(Entity* this) { void SurfaceAction_Pit(Entity* this) { if (!sub_080741C4() && sub_08079C30(this)) { if (this->action != PLAYER_FALL) { - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.queued_action = PLAYER_FALL; } } @@ -3355,7 +3354,7 @@ static void sub_08074244(Entity* this, u32 a1, u32 a2) { if (!sub_080741C4()) { u32 tmp; if (gPlayerState.dash_state == 0) { - tmp = gPlayerState.field_0xd; + tmp = gPlayerState.direction; } else { tmp = 4 * this->animationState; } @@ -3421,7 +3420,7 @@ static void hide(Entity* this) { this->spriteSettings.draw = 0; COLLISION_OFF(this); this->knockbackDuration = 0; - ResetPlayerItem(); + ResetActiveItems(); } void SurfaceAction_14(Entity* this) { @@ -3519,7 +3518,7 @@ void SurfaceAction_ShallowWater(Entity* this) { this->spritePriority.b0 = 4; gPlayerState.swim_state = 0; } - if ((gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_ANY_DIRECTION) || + if ((gPlayerState.playerInput.newInput & PLAYER_INPUT_ANY_DIRECTION) || gPlayerState.surfacePositionSameTimer == 1) SoundReq(SFX_WATER_WALK); } @@ -3563,7 +3562,7 @@ void SurfaceAction_Swamp(Entity* this) { CreateObjectWithParent(this, OBJECT_70, 0, 0); CreateFx(this, FX_GREEN_SPLASH, 0); SoundReq(SFX_161); - } else if ((gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_ANY_DIRECTION) != 0) { + } else if ((gPlayerState.playerInput.newInput & PLAYER_INPUT_ANY_DIRECTION) != 0) { SoundReq(SFX_161); } else if ((gRoomTransition.frameCount & 0xf) == 0) { SoundReq(SFX_161); @@ -3611,11 +3610,11 @@ static void sub_08074808(Entity* this) { if ((gPlayerState.flags & PL_MINISH) == 0) CreateFx(this, FX_WATER_SPLASH, 0); SoundReq(SFX_1A5); - ResetPlayerItem(); + ResetActiveItems(); } if ((gPlayerState.swim_state & 0xF) != 1) { sub_08079744(this); - --gPlayerState.swim_state; + gPlayerState.swim_state--; } gPlayerState.flags &= ~(PL_BURNING | PL_FROZEN); if ((gPlayerState.flags & PL_DRUGGED) != 0 && this->field_0x7a.HWORD <= 0xEu) @@ -3668,7 +3667,7 @@ void SurfaceAction_Ladder(Entity* this) { this->spriteOrientation.flipY = 1; this->animationState = IdleNorth; this->collisionLayer = 3; - ResetPlayerItem(); + ResetActiveItems(); } } @@ -3696,7 +3695,7 @@ void SurfaceAction_AutoLadder(Entity* this) { gPlayerState.animation = 726; this->direction = DirectionNorth; } - ResetPlayerItem(); + ResetActiveItems(); } } @@ -3719,7 +3718,7 @@ void SurfaceAction_Dust(Entity* this) { if (!sub_080741C4()) { gPlayerState.speed_modifier -= 128; if (gPlayerState.surfacePositionSameTimer == 1 || - (gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_ANY_DIRECTION) != 0) { + (gPlayerState.playerInput.newInput & PLAYER_INPUT_ANY_DIRECTION) != 0) { if (gPlayerState.floor_type == SURFACE_DUST) CreateObjectWithParent(this, DIRT_PARTICLE, 1, 0); else @@ -3732,7 +3731,7 @@ void SurfaceAction_26(Entity* this) { u32 v1; if (gPlayerState.dash_state == 0) - v1 = gPlayerState.field_0xd; + v1 = gPlayerState.direction; else v1 = 4 * this->animationState; sub_08074244(this, v1, v1); @@ -3780,7 +3779,7 @@ void SurfaceAction_ConveyerEast(Entity* this) { } static void conveyer_push(Entity* this) { - ResetPlayerItem(); + ResetActiveItems(); this->spritePriority.b1 = 0; this->speed = WALK_SPEED; gPlayerState.flags |= PL_CONVEYOR_PUSHED; diff --git a/src/playerItem.c b/src/playerItem.c index 2c61016e..b5248f8a 100644 --- a/src/playerItem.c +++ b/src/playerItem.c @@ -1,6 +1,7 @@ #include "global.h" #include "functions.h" #include "player.h" +#include "playeritem.h" typedef void(PlayerItemFunc)(Entity*); @@ -38,31 +39,31 @@ extern const PlayerItemDefinition gPlayerItemDefinitions[]; extern const PlayerItemDefinition* gAdditionalPlayerItemDefinitions[3]; PlayerItemFunc* const gPlayerItemFunctions[] = { - DeleteEntity, - PlayerItemSword, - PlayerItemBomb, - PlayerItemBoomerang, - PlayerItemBow, - PlayerItemShield, - PlayerItemLantern, - PlayerItemNulled, - PlayerItemGustJar, - PlayerItemPacciCane, - DeleteEntity, - DeleteEntity, - PlayerItemDashSword, - PlayerItemCellOverwriteSet, - PlayerItemBottle, - PlayerItemSwordBeam, - PlayerItemGust, - PlayerItemGustBig, - PlayerItemPacciCaneProjectile, - PlayerItemHeldObject, - PlayerItemSpiralBeam, - PlayerItemFireRodProjectile, - PlayerItemSwordBeam, - PlayerItemNulled2, - PlayerItemCellOverwriteSet, + [PLAYER_ITEM_NONE] = DeleteEntity, + [PLAYER_ITEM_SWORD] = PlayerItemSword, + [PLAYER_ITEM_BOMB] = PlayerItemBomb, + [PLAYER_ITEM_BOOMERANG] = PlayerItemBoomerang, + [PLAYER_ITEM_BOW] = PlayerItemBow, + [PLAYER_ITEM_SHIELD] = PlayerItemShield, + [PLAYER_ITEM_LANTERN] = PlayerItemLantern, + [PLAYER_ITEM_NULLED] = PlayerItemNulled, + [PLAYER_ITEM_GUST_JAR] = PlayerItemGustJar, + [PLAYER_ITEM_PACCI_CANE] = PlayerItemPacciCane, + [PLAYER_ITEM_NONE2] = DeleteEntity, + [PLAYER_ITEM_NONE3] = DeleteEntity, + [PLAYER_ITEM_DASH_SWORD] = PlayerItemDashSword, + [PLAYER_ITEM_CELL_OVERWRITE_SET] = PlayerItemCellOverwriteSet, + [PLAYER_ITEM_BOTTLE] = PlayerItemBottle, + [PLAYER_ITEM_SWORD_BEAM1] = PlayerItemSwordBeam, + [PLAYER_ITEM_GUST] = PlayerItemGust, + [PLAYER_ITEM_GUST_BIG] = PlayerItemGustBig, + [PLAYER_ITEM_PACCI_CANE_PROJECTILE] = PlayerItemPacciCaneProjectile, + [PLAYER_ITEM_HELD_OBJECT] = PlayerItemHeldObject, + [PLAYER_ITEM_SPIRAL_BEAM] = PlayerItemSpiralBeam, + [PLAYER_ITEM_FIRE_ROD_PROJECTILE] = PlayerItemFireRodProjectile, + [PLAYER_ITEM_SWORD_BEAM2] = PlayerItemSwordBeam, + [PLAYER_ITEM_NULLED2] = PlayerItemNulled2, + [PLAYER_ITEM_CELL_OVERWRITE_SET2] = PlayerItemCellOverwriteSet, }; void ItemInit(Entity*); diff --git a/src/playerItem/playerItemBomb.c b/src/playerItem/playerItemBomb.c index f6ed0c1c..a1e5e560 100644 --- a/src/playerItem/playerItemBomb.c +++ b/src/playerItem/playerItemBomb.c @@ -80,7 +80,7 @@ void sub_0801B250(PlayerItemBombEntity* this) { super->spriteSettings.draw = 1; super->action = 1; super->spritePriority.b1 = 3; - super->flags &= 0x7f; + super->flags &= ~0x80; if (super->type == 0xff) { super->timer = 60; } else if (super->type == 0xfe) { @@ -105,17 +105,17 @@ void sub_0801B2CC(PlayerItemBombEntity* this) { RegisterCarryEntity(super); } switch (IsItemEquipped(ITEM_REMOTE_BOMBS)) { - case 0: + case EQUIP_SLOT_A: unaff_r5 = PLAYER_INPUT_1; break; - case 1: + case EQUIP_SLOT_B: unaff_r5 = PLAYER_INPUT_2; break; - case 2: + case EQUIP_SLOT_NONE: unaff_r5 = 0; break; } - if ((gPlayerState.playerInput.field_0x92 & unaff_r5) != 0) { + if ((gPlayerState.playerInput.newInput & unaff_r5) != 0) { super->timer = 0; super->subtimer = 1; } diff --git a/src/playerItem/playerItemBoomerang.c b/src/playerItem/playerItemBoomerang.c index 4dc62bca..6557a08c 100644 --- a/src/playerItem/playerItemBoomerang.c +++ b/src/playerItem/playerItemBoomerang.c @@ -68,8 +68,8 @@ void PlayerItemBoomerang_Init(Entity* this) { uVar1 = 30; } this->timer = uVar1; - if (((s8)gPlayerState.field_0xd) >= 0) { - this->direction = gPlayerState.field_0xd; + if (((s8)gPlayerState.direction) >= 0) { + this->direction = gPlayerState.direction; } else { this->direction = this->animationState << 2; } @@ -89,7 +89,7 @@ void sub_0801B584(Entity* this) { u32 cVar3; sub_0801B804(this); - if ((gPlayerState.field_0x3[1] == 0) || (gPlayerState.mobility != 0) || gPlayerState.item != this || + if ((gPlayerState.attack_status == 0) || (gPlayerState.mobility != 0) || gPlayerState.item != this || (gPlayerState.item == this && gPlayerEntity.action != PLAYER_NORMAL)) { if (gPlayerState.item == this) { gPlayerState.item = NULL; @@ -124,7 +124,7 @@ void sub_0801B584(Entity* this) { this->y.HALF.HI += gUnk_080B7826[iVar2 + 1]; InitializeAnimation(this, 0); gPlayerState.item = NULL; - gPlayerState.field_0x3[1] |= 0x80; + gPlayerState.attack_status |= 0x80; } } @@ -133,8 +133,8 @@ void sub_0801B680(Entity* this) { u32 uVar6; sub_0801B804(this); - if ((this->field_0x68.HALF.LO == 12) && (this->field_0x80.HALF.LO == 0) && ((gPlayerState.field_0xd & 0x80) == 0)) { - if (((this->field_0x82.HALF.HI - gPlayerState.field_0xd) & 0x1f) > 0x10) { + if ((this->field_0x68.HALF.LO == 12) && (this->field_0x80.HALF.LO == 0) && ((gPlayerState.direction & 0x80) == 0)) { + if (((this->field_0x82.HALF.HI - gPlayerState.direction) & 0x1f) > 0x10) { this->field_0x82.HWORD += 0x40; this->field_0x82.HALF.HI &= 0x1f; this->direction = this->field_0x82.HALF.HI; @@ -208,26 +208,26 @@ void sub_0801B7A8(Entity* this) { } void sub_0801B804(Entity* this) { - u32 itemSlot; + EquipSlot equipSlot; u32 uVar1; - itemSlot = IsItemEquipped(ITEM_MAGIC_BOOMERANG); - switch (itemSlot) { - case 0: + equipSlot = IsItemEquipped(ITEM_MAGIC_BOOMERANG); + switch (equipSlot) { + case EQUIP_SLOT_A: uVar1 = 1; break; - case 1: + case EQUIP_SLOT_B: uVar1 = 2; break; - case 2: + case EQUIP_SLOT_NONE: uVar1 = 0; break; } - if ((uVar1 & gPlayerState.playerInput.field_0x90) == 0) { + if ((uVar1 & gPlayerState.playerInput.heldInput) == 0) { this->field_0x80.HALF.LO = 1; - gPlayerState.field_0xa &= 0x7f; - gPlayerState.keepFacing &= 0x7f; + gPlayerState.field_0xa &= ~0x80; + gPlayerState.keepFacing &= ~0x80; } else { gPlayerState.field_0xa |= 0x80; gPlayerState.keepFacing |= 0x80; diff --git a/src/playerItem/playerItemBow.c b/src/playerItem/playerItemBow.c index 6526b4e8..ee32b950 100644 --- a/src/playerItem/playerItemBow.c +++ b/src/playerItem/playerItemBow.c @@ -170,7 +170,7 @@ void sub_0801917C(PlayerItemBowEntity* this) { InitializeAnimation(super, super->animIndex + 2); } sub_08017744(super); - super->flags &= 0x7f; + super->flags &= ~0x80; super->speed = 0; tmp3 = super->x.WORD; if (tmp3 < 0) { @@ -195,7 +195,7 @@ void sub_0801917C(PlayerItemBowEntity* this) { super->direction ^= 0x10; super->speed = 0x100; super->zVelocity = Q_16_16(0.5); - super->flags &= 0x7f; + super->flags &= ~0x80; InitializeAnimation(super, 6); } else { super->action++; @@ -230,7 +230,7 @@ void sub_0801917C(PlayerItemBowEntity* this) { if ((gPlayerEntity.frame & 1) != 0 && arrowCount != 0) { entity = CreatePlayerItem(PLAYER_ITEM_BOW, 1, super->hurtType, 9); if (entity != NULL) { - gPlayerState.field_0x3[1] |= 0x80; + gPlayerState.attack_status |= 0x80; ModArrows(-1); } } diff --git a/src/playerItem/playerItemFireRodProjectile.c b/src/playerItem/playerItemFireRodProjectile.c index 57e26a75..3c65c353 100644 --- a/src/playerItem/playerItemFireRodProjectile.c +++ b/src/playerItem/playerItemFireRodProjectile.c @@ -77,7 +77,7 @@ void sub_080A310C(FireRodProjectileEntity* this) { if (sub_08008790(super, 0xc)) { DeleteThisEntity(); } - super->child = CreatePlayerItem(PLAYER_ITEM_15, 1, 0, this->unk68); + super->child = CreatePlayerItem(PLAYER_ITEM_FIRE_ROD_PROJECTILE, 1, 0, this->unk68); if (super->child != NULL) { super->child->parent = super; } diff --git a/src/playerItem/playerItemGust.c b/src/playerItem/playerItemGust.c index e3bb729a..8d62b981 100644 --- a/src/playerItem/playerItemGust.c +++ b/src/playerItem/playerItemGust.c @@ -221,7 +221,7 @@ static void sub_080ACECC(GustEntity* this) { Entity* entity; if (super->type < 3 && super->child == NULL && (s32)this->unk78 >= 0 && gUnk_0812AAE8[super->type] <= this->unk78) { - entity = CreatePlayerItem(PLAYER_ITEM_10, super->type + 1, 0, 0); + entity = CreatePlayerItem(PLAYER_ITEM_GUST, super->type + 1, 0, 0); if (entity != NULL) { entity->parent = super; super->child = entity; diff --git a/src/playerItem/playerItemHeldObject.c b/src/playerItem/playerItemHeldObject.c index 8f8c42d2..8421c8fa 100644 --- a/src/playerItem/playerItemHeldObject.c +++ b/src/playerItem/playerItemHeldObject.c @@ -34,7 +34,7 @@ void sub_080ACF2C(PlayerItemHeldObjectEntity*); void sub_080ACFCC(PlayerItemHeldObjectEntity*); void sub_080AD040(PlayerItemHeldObjectEntity*); void sub_080AD274(PlayerItemHeldObjectEntity*); -u32 sub_0806F8DC(Entity*); +bool32 sub_0806F8DC(Entity*); void PlayerItemHeldObject(Entity* this) { static void (*const subActionFuncs[])(PlayerItemHeldObjectEntity*) = { @@ -91,7 +91,7 @@ void sub_080ACFCC(PlayerItemHeldObjectEntity* this) { if ((gPlayerState.heldObject == 0) || ((gNewPlayerEntity.unk_79 & 0x7f) != 0)) { sub_080AD27C(this); super->subAction++; - super->flags &= 0x7f; + super->flags &= ~0x80; super->direction = 0xff; super->zVelocity = 0; } @@ -216,7 +216,7 @@ void sub_080AD040(PlayerItemHeldObjectEntity* this) { return; } sub_080AD27C(this); - super->flags &= 0x7f; + super->flags &= ~0x80; super->direction = 0xff; super->zVelocity = tmp & 1; return; diff --git a/src/playerItem/playerItemLantern.c b/src/playerItem/playerItemLantern.c index 3158f698..6d22375e 100644 --- a/src/playerItem/playerItemLantern.c +++ b/src/playerItem/playerItemLantern.c @@ -56,7 +56,7 @@ void sub_08054AC8(Entity* this) { this->frame = gPlayerEntity.frame; this->frameSpriteSettings = gPlayerEntity.frameSpriteSettings; } - if (IsItemEquipped(ITEM_LANTERN_ON) < 2) { + if (IsItemEquipped(ITEM_LANTERN_ON) < EQUIP_SLOT_NONE) { if (((this->frameIndex != 0xff) && (gPlayerEntity.spriteSettings.draw != 0)) && (this->timer-- == 0)) { this->timer = 4; object = CreateObject(LAMP_PARTICLE, 0, 0x10); diff --git a/src/playerItem/playerItemShield.c b/src/playerItem/playerItemShield.c index afe8feb1..0c1a98ee 100644 --- a/src/playerItem/playerItemShield.c +++ b/src/playerItem/playerItemShield.c @@ -55,19 +55,19 @@ NONMATCH("asm/non_matching/playerItemShield/sub_080A2E00.inc", void sub_080A2E00 this->iframes = 0; } - uVar4 = gPlayerState.field_0x3[0]; + uVar4 = gPlayerState.shield_status; if ((uVar4 != 0) && (this == gPlayerState.item)) { if ((uVar4 & 0x80) != 0) { this->hitbox = gUnk_08127240[this->animationState >> 1]; this->collisionFlags = (gPlayerEntity.collisionFlags + 1) | 0x20; this->flags = this->flags | 0x80; - gPlayerState.field_0x3[0] = uVar4 & 0x7f; + gPlayerState.shield_status = uVar4 & 0x7f; sub_080176E4(this); } else { if ((this->contactFlags & 0x80) != 0) { if ((((this->contactFlags & 0x7f) == 0x42) && (*(char*)&this->field_0x68 == 0xe)) && ((uVar4 & 0x40) == 0)) { - pEVar1 = CreatePlayerItem(PLAYER_ITEM_15, 0, 0, *(char*)&this->field_0x68); + pEVar1 = CreatePlayerItem(PLAYER_ITEM_FIRE_ROD_PROJECTILE, 0, 0, *(char*)&this->field_0x68); this->child = pEVar1; if (pEVar1 != NULL) { pEVar1->subtimer = 1; @@ -77,7 +77,7 @@ NONMATCH("asm/non_matching/playerItemShield/sub_080A2E00.inc", void sub_080A2E00 *(u32*)&this->field_0x78 = gUnk_08127220[1]; *(u32*)&this->field_0x74 = uVar4 & 0x40; *(u8**)&this->field_0x7c = gUnk_08127220; - gPlayerState.field_0x3[0] = gPlayerState.field_0x3[0] | 0x40; + gPlayerState.shield_status |= 0x40; } if (*(int*)&this->field_0x6c == 0) { SoundReq(0x118); @@ -86,7 +86,7 @@ NONMATCH("asm/non_matching/playerItemShield/sub_080A2E00.inc", void sub_080A2E00 } } } else { - gPlayerState.field_0x3[0] = 0; + gPlayerState.shield_status = 0; if (gPlayerState.item == this) { gPlayerState.item = NULL; } @@ -109,16 +109,16 @@ NONMATCH("asm/non_matching/playerItemShield/sub_080A2E00.inc", void sub_080A2E00 iVar5 = (*(int*)&this->field_0x74) * 4; iVar2 = *(u8**)&this->field_0x7c; if (iVar2[iVar5] == 0xff) { - if ((gPlayerState.field_0x3[0] & 0x40) != 0) { + if ((gPlayerState.shield_status & 0x40) != 0) { *(u8**)&this->field_0x7c = gUnk_081271DC; - gPlayerState.field_0x3[0] = gPlayerState.field_0x3[0] & 0xbf; + gPlayerState.shield_status = gPlayerState.shield_status & 0xbf; } *(u32*)&this->field_0x74 = 0; iVar2 = *(u8**)&this->field_0x7c; } pbVar3 = &iVar2[*(int*)&this->field_0x74 * 4]; *(u32*)&this->field_0x78 = pbVar3[1]; - if ((gPlayerState.field_0x3[0] & 0x40) != 0) { + if ((gPlayerState.shield_status & 0x40) != 0) { u32 temp = (gPlayerEntity.frame & 0x7f) + 8; sub_080042D0(this, temp + *pbVar3, (u16)this->spriteIndex); } else { diff --git a/src/playerItem/playerItemSword.c b/src/playerItem/playerItemSword.c index 76ae377f..52b9dcbf 100644 --- a/src/playerItem/playerItemSword.c +++ b/src/playerItem/playerItemSword.c @@ -46,7 +46,7 @@ void sub_080A758C(PlayerItemSwordEntity* this) { SFX_PLY_VO4, SFX_PLY_VO5, }; - if (((super->type == 0) && (gPlayerState.field_0x3[1] == 0)) && ((gPlayerState.jump_status & 0x20) == 0)) { + if (((super->type == 0) && (gPlayerState.attack_status == 0)) && ((gPlayerState.jump_status & 0x20) == 0)) { DeleteThisEntity(); } if (AllocMutableHitbox(super) == NULL) { @@ -157,7 +157,7 @@ void sub_080A76CC(PlayerItemSwordEntity* this) { if ((PlayerItemSwordEntity*)gPlayerState.item != this) { DeleteThisEntity(); } - if (gPlayerState.field_0x3[1] == 0) { + if (gPlayerState.attack_status == 0) { gPlayerState.item = NULL; gPlayerState.sword_state = 0; DeleteThisEntity(); @@ -209,7 +209,7 @@ void sub_080A76CC(PlayerItemSwordEntity* this) { sub_080A78B8(this, &gPlayerEntity); sub_080A7A84(this); } else { - if (!((gPlayerState.field_0x3[1] == 0) || (gPlayerState.item->hurtType == 0))) { + if (!((gPlayerState.attack_status == 0) || (gPlayerState.item->hurtType == 0))) { super->flags |= ENT_COLLIDE; super->hurtType = gPlayerState.item->hurtType; sub_080A7A54(this); @@ -225,7 +225,7 @@ void sub_080A7824(PlayerItemSwordEntity* this) { if (gPlayerState.item != super) { DeleteThisEntity(); } - if (gPlayerState.field_0x3[1] != 0) { + if (gPlayerState.attack_status != 0) { if (gPlayerState.jump_status == 0) { gPlayerState.item = NULL; DeleteThisEntity(); @@ -306,7 +306,7 @@ void sub_080A78B8(PlayerItemSwordEntity* this, Entity* param_2) { default: if ((gPlayerState.sword_state & 0xc0) == 0) { gPlayerState.sword_state = 0; - gPlayerState.field_0x3[1] = 0; + gPlayerState.attack_status = 0; gPlayerState.item = NULL; DeleteThisEntity(); } diff --git a/src/playerItem/playerItemSwordBeam.c b/src/playerItem/playerItemSwordBeam.c index 35f844da..dfd78d5d 100644 --- a/src/playerItem/playerItemSwordBeam.c +++ b/src/playerItem/playerItemSwordBeam.c @@ -70,11 +70,11 @@ void sub_08019580(Entity* this) { if (--*(int*)&this->field_0x6c != -1) { GetNextFrame(this); LinearMoveUpdate(this); - this->timer += 1; + this->timer++; if (this->type2 == 0) { sub_0800451C(this); } - if ((sub_080B1BA4(TILE(this->x.HALF.HI, this->y.HALF.HI), gPlayerEntity.collisionLayer, 0x80) == 0) && + if ((sub_080B1BA4(COORD_TO_TILE(this), gPlayerEntity.collisionLayer, 0x80) == 0) && (sub_080040D8(this, &gUnk_08003E44, this->x.HALF.HI, this->y.HALF.HI) != 0)) { CreateFx(this, FX_SWORD_MAGIC, 0); DeleteThisEntity(); diff --git a/src/playerItemUtils.c b/src/playerItemUtils.c index f6a4d67c..b09ed736 100644 --- a/src/playerItemUtils.c +++ b/src/playerItemUtils.c @@ -12,13 +12,13 @@ static Entity* GiveItemWithCutscene(u32, u32, u32); static void InitTileMessage(u32, u32); -Entity* sub_080A276C(Entity*, u32, u32); +Entity* CreateLinkAnimation(Entity*, u32, u32); void SetPlayerItemGetState(Entity*, u32, u32); void CreateItemEntity(u32 type, u32 type2, u32 delay) { Entity* e = GiveItemWithCutscene(type, type2, delay); if (e != NULL) { - e->parent = sub_080A276C(e, e->type, 0); + e->parent = CreateLinkAnimation(e, e->type, 0); } } diff --git a/src/playerUtils.c b/src/playerUtils.c index 08af08f3..df6022b8 100644 --- a/src/playerUtils.c +++ b/src/playerUtils.c @@ -1,26 +1,24 @@ #define NENT_DEPRECATED -#include "global.h" #include "area.h" #include "asm.h" #include "common.h" #include "entity.h" #include "functions.h" #include "game.h" +#include "global.h" +#include "item.h" #include "kinstone.h" +#include "manager/diggingCaveEntranceManager.h" +#include "message.h" +#include "new_player.h" #include "object.h" #include "player.h" #include "room.h" #include "save.h" -#include "new_player.h" -#include "item.h" -#include "message.h" #include "screen.h" -#include "screen.h" -#include "manager/diggingCaveEntranceManager.h" static void sub_08077E54(ItemBehavior* beh); -extern void sub_080752E8(ItemBehavior* behavior, u32 arg1); // item.c extern void sub_0800857C(Entity*); extern void SetDefaultPriorityForKind(Entity*); extern void sub_0809D738(Entity*); @@ -31,36 +29,28 @@ extern void sub_08080BC4(void); void sub_080790E4(Entity* this); void sub_08079064(Entity*); -typedef struct { - u8 unk0[4]; - u16 unk4; - u8 unk6[6]; -} struct_0811BE48; - extern u8 gMapData; extern const u8 gUnk_020176E0[]; extern const ScreenTransitionData gUnk_0813AD88[]; -bool32 sub_08077758(PlayerEntity*); -bool32 sub_080777A0(); -void sub_08077880(u32, u32, u32); -bool32 sub_080778CC(); -ItemBehavior* sub_0807794C(u32); +bool32 IsAbleToUseItem(PlayerEntity*); +bool32 IsPreventedFromUsingItem(); +void CreateItemIfInputMatches(Item itemId, PlayerInputState input, bool32 forceCreate); +bool32 IsTryingToPickupObject(void); +ItemBehavior* CreateItem(u32); u32 sub_080789A8(void); -ItemBehavior* sub_080779EC(u32); -void DeletePlayerItem(ItemBehavior*, u32); +ItemBehavior* CreateItem1(u32); +void DeleteItemBehavior(ItemBehavior*, u32); bool32 sub_08079E90(u32); void PlayerMinishSetNormalAndCollide(void); void sub_08078D60(void); -void* sub_08077C54(ItemBehavior*); +void* CreateItemGetPlayerItemWithParent(ItemBehavior*); u32 sub_08079FD4(Entity*, u32); void LoadRoomGfx(void); -u32 sub_0807A094(u32); SurfaceType GetSurfaceCalcType(Entity*, s32, s32); void sub_0807AAF8(Entity*, u32); -extern u32 gUnk_02022830[]; -extern struct_0811BE48 gUnk_0811BE48[]; +extern ItemDefinition gItemDefinitions[]; extern void (*const gUnk_0811C27C[])(Entity*); extern void (*const gUnk_0811C284[])(PlayerEntity*); extern void (*const gUnk_0811C298[])(PlayerEntity*); @@ -69,7 +59,7 @@ extern u8 gUnk_0811C000[]; extern const u8 gUnk_0811C118[]; extern void (*const gUnk_0811C120[])(Entity*); extern u16 gUnk_0811C268[]; -extern ItemBehavior* (*const gUnk_0811BFC8[])(u32); +extern ItemBehavior* (*const gCreateItemsFuncs[])(Item); extern void DeleteLoadedTileEntity(u32, u32); @@ -90,7 +80,7 @@ struct_03003DF8* sub_080784E4(void); extern const u16 gUnk_0811C0F8[]; u32 sub_08079778(void); -u32 sub_0807A500(void); +u32 GetPlayerTilePos(void); extern const u16 gUnk_0811C108[]; @@ -126,7 +116,7 @@ bool32 sub_0807B464(u32 param_1, u32 param_2); extern void CreateRandomWaterTrace(Entity* parent, int range); void sub_08079520(Entity* this); -bool32 sub_0807ADB8(Entity*); +bool32 ToggleDiving(Entity*); extern const u16* sub_0806FC50(u32 param_1, u32 param_2); @@ -174,40 +164,36 @@ extern u32 sub_08004202(Entity*, u8*, u32); extern s8* gUnk_0811C0B0[]; extern u8 gUnk_0811C01C[]; -void sub_08077698(PlayerEntity* this) { - ItemBehavior* puVar2; - u32 idx; +extern u32 gUnk_02022830[]; - gPlayerState.field_0x3[0] &= 0xfe; - gPlayerState.field_0x3[1] &= 0xf; - if ((((((gPlayerState.field_0x7 | gPlayerState.jump_status) & 0x80) == 0) && - ((gPlayerState.jump_status & 0x40) == 0)) && - (gPlayerState.swim_state == 0)) && - ((sub_08077758(this) && (sub_080777A0() == 0)))) { - sub_08077880(gSave.stats.itemButtons[SLOT_A], 1, 0); - sub_08077880(gSave.stats.itemButtons[SLOT_B], 2, 0); - sub_080778CC(); +void UpdateActiveItems(PlayerEntity* this) { + u32 index; + + gPlayerState.shield_status &= 0xfe; + gPlayerState.attack_status &= 0xf; + if (((gPlayerState.field_0x7 | gPlayerState.jump_status) & 0x80) == 0 && (gPlayerState.jump_status & 0x40) == 0 && + gPlayerState.swim_state == 0 && IsAbleToUseItem(this) && !IsPreventedFromUsingItem()) { + CreateItemIfInputMatches(gSave.stats.itemButtons[SLOT_A], PLAYER_INPUT_1, FALSE); + CreateItemIfInputMatches(gSave.stats.itemButtons[SLOT_B], PLAYER_INPUT_2, FALSE); + IsTryingToPickupObject(); } - idx = 0; - puVar2 = gUnk_03000B80; - do { - if (puVar2->field_0x9 != 0) { - sub_080752E8(puVar2, idx); + + for (index = 0; index < MAX_ACTIVE_ITEMS; index++) { + if (gActiveItems[index].priority != 0) { + ExecuteItemFunction(&gActiveItems[index], index); } - puVar2++; - idx++; - } while (idx < 4); -} - -void sub_08077728(u32 param_1) { - if (param_1 == 0) { - sub_08077880(gSave.stats.itemButtons[SLOT_A], 1, 1); - } else { - sub_08077880(gSave.stats.itemButtons[SLOT_B], 2, 1); } } -bool32 sub_08077758(PlayerEntity* this) { +void CreateItemEquippedAtSlot(EquipSlot equipSlot) { + if (equipSlot == EQUIP_SLOT_A) { + CreateItemIfInputMatches(gSave.stats.itemButtons[SLOT_A], PLAYER_INPUT_1, TRUE); + } else { + CreateItemIfInputMatches(gSave.stats.itemButtons[SLOT_B], PLAYER_INPUT_2, TRUE); + } +} + +bool32 IsAbleToUseItem(PlayerEntity* this) { if ((gPlayerState.flags & PL_DRUGGED) == 0) { if ((gPlayerState.flags & (PL_CAPTURED | PL_HIDDEN | PL_DISABLE_ITEMS | PL_BURNING | PL_FROZEN)) == 0) { if ((((gPlayerState.dash_state | gPlayerState.mobility) | this->unk_7a) == 0) && @@ -221,8 +207,8 @@ bool32 sub_08077758(PlayerEntity* this) { return FALSE; } -bool32 sub_080777A0(void) { - if ((gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_80) != 0) { +bool32 IsPreventedFromUsingItem(void) { + if ((gPlayerState.playerInput.newInput & PLAYER_INPUT_80) != 0) { if ((gPlayerState.flags & PL_CLONING) != 0) { gPlayerState.chargeState.action = 1; DeleteClones(); @@ -245,9 +231,9 @@ bool32 sub_080777A0(void) { default: if ((((gUnk_0200AF00.unk_2c == 0xc) && (gPlayerState.field_0x1c == 0)) && (gPlayerState.floor_type != SURFACE_SWAMP)) && - ((((gPlayerState.playerInput.field_0x90 & PLAYER_INPUT_ANY_DIRECTION) != 0 && + ((((gPlayerState.playerInput.heldInput & PLAYER_INPUT_ANY_DIRECTION) != 0 && ((gPlayerState.flags & (PL_BURNING | PL_ROLLING)) == 0)) && - ((gPlayerState.jump_status == 0 && (gPlayerState.field_0x3[1] == 0)))))) { + ((gPlayerState.jump_status == 0 && (gPlayerState.attack_status == 0)))))) { gPlayerState.queued_action = PLAYER_ROLL; } return FALSE; @@ -262,158 +248,150 @@ bool32 sub_080777A0(void) { } } -void sub_08077880(Item itemId, u32 param_2, u32 param_3) { - ItemBehavior* item; - u16* puVar2; - +void CreateItemIfInputMatches(Item itemId, PlayerInputState input, bool32 forceCreate) { if (itemId - 1 < 0x1f) { - struct_0811BE48* ptr = &gUnk_0811BE48[itemId]; - puVar2 = &gPlayerState.playerInput.field_0x90; - if (ptr->unk0[0] != 0) { - puVar2 = &gPlayerState.playerInput.field_0x92; + ItemDefinition* ptr = &gItemDefinitions[itemId]; + u16* inputPtr = &gPlayerState.playerInput.heldInput; + if (ptr->isOnlyActiveFirstFrame) { + inputPtr = &gPlayerState.playerInput.newInput; } - if (((*puVar2 & param_2) != 0) || (param_3 != 0)) { - item = sub_0807794C(itemId); + if ((*inputPtr & input) || forceCreate) { + ItemBehavior* item = CreateItem(itemId); if (item != NULL) { - item->field_0x9 = gUnk_0811BE48[itemId].unk0[1]; - item->behaviorID = itemId; - item->field_0x2[1] = param_2; + item->priority = gItemDefinitions[itemId].priority; + item->behaviorId = itemId; + item->field_0x2[1] = input; } } } } -bool32 sub_080778CC(void) { +bool32 IsTryingToPickupObject(void) { ItemBehavior* item; if (!((((gPlayerState.flags & (PL_USE_PORTAL | PL_MINISH | PL_ROLLING)) == 0) && (((gNewPlayerEntity.unk_79 != 0 || (gPlayerState.heldObject != 0)) || - ((gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_8000) != 0)))) && - (((sub_080789A8() != 0 || ((gPlayerState.playerInput.field_0x90 & + ((gPlayerState.playerInput.newInput & PLAYER_INPUT_8000) != 0)))) && + (((sub_080789A8() != 0 || ((gPlayerState.playerInput.heldInput & (PLAYER_INPUT_ANY_DIRECTION | PLAYER_INPUT_1 | PLAYER_INPUT_2)) == 0)))))) { return FALSE; } - item = sub_0807794C(ITEM_TRAP); + item = CreateItem(ITEM_TRY_PICKUP_OBJECT); if (item != NULL) { - item->behaviorID = ITEM_TRAP; - item->field_0x9 = gUnk_0811BE48[0].unk0[0x145]; + item->behaviorId = ITEM_TRY_PICKUP_OBJECT; + item->priority = gItemDefinitions[ITEM_TRY_PICKUP_OBJECT].priority; return TRUE; } else { return FALSE; } } -ItemBehavior* sub_0807794C(Item itemId) { - if (((((gPlayerState.queued_action == PLAYER_ROLL) && (itemId != ITEM_TRAP)) || +ItemBehavior* CreateItem(Item itemId) { + if (((((gPlayerState.queued_action == PLAYER_ROLL) && (itemId != ITEM_TRY_PICKUP_OBJECT)) || (((gPlayerState.flags & (PL_ROLLING | PL_CLONING)) != 0 && (ITEM_FOURSWORD < itemId)))) || ((((gPlayerState.jump_status != 0 || (gPlayerEntity.z.WORD != 0)) && (ITEM_FOURSWORD < itemId)) || - (((gPlayerState.flags & PL_MINISH) != 0 && (gUnk_0811BE48[itemId].unk6[2] == 0)))))) || + (((gPlayerState.flags & PL_MINISH) && !gItemDefinitions[itemId].isUseableAsMinish))))) || ((gPlayerState.floor_type == SURFACE_SWAMP && ((gPlayerState.surfaceTimer != 0 && (1 < itemId - 0x14)))))) { return NULL; } else { - u32 tmp = gUnk_0811BE48[itemId].unk0[2]; - return gUnk_0811BFC8[tmp](itemId); + u32 createFunc = gItemDefinitions[itemId].createFunc; + return gCreateItemsFuncs[createFunc](itemId); } } -u32 sub_080779E8(void) { - return 0; +ItemBehavior* CreateItemNone(Item itemId) { + return NULL; } -ItemBehavior* sub_080779EC(u32 param_1) { - if (gUnk_03000B80[1].field_0x9 == 0) { - return gUnk_03000B80 + 1; - } else if (gUnk_03000B80[2].field_0x9 == 0) { - return gUnk_03000B80 + 2; +ItemBehavior* CreateItem1(Item itemId) { + if (gActiveItems[ACTIVE_ITEM_1].priority == 0) { + return &gActiveItems[ACTIVE_ITEM_1]; + } else if (gActiveItems[ACTIVE_ITEM_2].priority == 0) { + return &gActiveItems[ACTIVE_ITEM_2]; } else { return NULL; } } -ItemBehavior* sub_08077A18(u32 param_1) { - ItemBehavior* pIVar1; - - if (((gPlayerState.heldObject == 0) && (param_1 != gUnk_03000B80[1].behaviorID)) && - (param_1 != gUnk_03000B80[2].behaviorID)) { - return sub_080779EC(param_1); +ItemBehavior* CreateItem2(Item itemId) { + if (((gPlayerState.heldObject == 0) && (itemId != gActiveItems[ACTIVE_ITEM_1].behaviorId)) && + (itemId != gActiveItems[ACTIVE_ITEM_2].behaviorId)) { + return CreateItem1(itemId); } else { return NULL; } } -ItemBehavior* sub_08077A48(s32 param_1) { +ItemBehavior* CreateItem3(Item itemId) { if (gPlayerState.heldObject == 0) { - u32 tmp = gPlayerState.jump_status & 0x20; - if ((((gPlayerState.jump_status & 0x20) == 0)) && - (gUnk_0811BE48[param_1].unk0[1] >= gUnk_03000B80[0].field_0x9)) { - DeletePlayerItem(gUnk_03000B80, 0); - gPlayerState.field_0x0[1] = tmp; - gPlayerState.field_0x1c = tmp; - gPlayerState.sword_state = tmp; - return gUnk_03000B80; + if ((gPlayerState.jump_status & 0x20) == 0 && + gItemDefinitions[itemId].priority >= gActiveItems[ACTIVE_ITEM_0].priority) { + DeleteItemBehavior(&gActiveItems[ACTIVE_ITEM_0], 0); + gPlayerState.grab_status = 0; + gPlayerState.field_0x1c = 0; + gPlayerState.sword_state = 0; + return &gActiveItems[ACTIVE_ITEM_0]; } } return NULL; } -ItemBehavior* sub_08077A98(void) { - if (!(((gSave.stats.bombCount == 0) || (gPlayerState.heldObject != 0)) || (gUnk_03000B80[0].field_0x9 != 0))) { - return gUnk_03000B80; +ItemBehavior* CreateItem4(Item itemId) { + if (gSave.stats.bombCount != 0 && gPlayerState.heldObject == 0 && gActiveItems[ACTIVE_ITEM_0].priority == 0) { + return &gActiveItems[ACTIVE_ITEM_0]; } else { return NULL; } } -ItemBehavior* sub_08077AC8(void) { - ItemBehavior* pIVar1; +ItemBehavior* CreateItem5(Item itemId) { + ItemBehavior* activeItem; u32 index; index = 0; - pIVar1 = gUnk_03000B80; + activeItem = gActiveItems; while (index < 4) { - if (pIVar1->field_0x9 != 0) { + // Lantern can only be active if no other item is active. + if (activeItem->priority != 0) { return NULL; } - pIVar1++; + activeItem++; index++; } - return gUnk_03000B80 + 3; + return &gActiveItems[ACTIVE_ITEM_LANTERN]; } void ResetLantern(void) { - u32 slot; + EquipSlot slot; - DeletePlayerItem(gUnk_03000B80 + 3, 3); + DeleteItemBehavior(&gActiveItems[ACTIVE_ITEM_LANTERN], ACTIVE_ITEM_LANTERN); gPlayerState.flags &= ~PL_USE_LANTERN; slot = IsItemEquipped(ITEM_LANTERN_ON); - if (slot != 2) { + if (slot != EQUIP_SLOT_NONE) { ForceEquipItem(ITEM_LANTERN_OFF, slot); } } void PutAwayItems(void) { - ResetPlayerItem(); + ResetActiveItems(); ResetLantern(); } -void ResetPlayerItem() { - u32 index = 0; - ItemBehavior* ptr = gUnk_03000B80; - do { - DeletePlayerItem(ptr, index); - ptr++; - index++; - } while (index <= 2); +void ResetActiveItems() { + u32 index; + for (index = 0; index < MAX_ACTIVE_ITEMS - 1; index++) { + DeleteItemBehavior(&gActiveItems[index], index); + } gPlayerState.moleMittsState = 0; gPlayerState.field_0x1c = 0; gPlayerState.field_0x1f[2] = 0; - gPlayerState.field_0x0[1] = 0; - gPlayerState.field_0xe = 0; + gPlayerState.grab_status = 0; + gPlayerState.itemAnimPriority = 0; gPlayerState.dash_state = 0; gPlayerState.sword_state = 0; - gPlayerState.field_0x3[0] = 0; + gPlayerState.shield_status = 0; gPlayerState.heldObject = 0; gPlayerState.flags &= ~(PL_ROLLING | PL_SWORD_THRUST); @@ -434,121 +412,111 @@ void ResetPlayerItem() { void sub_08077B98(ItemBehavior* unk) { if ((gPlayerState.item == NULL) || (gPlayerState.item->id != 1)) { - gPlayerState.item = sub_08077C54(unk); + gPlayerState.item = CreateItemGetPlayerItemWithParent(unk); } } void sub_08077BB8(ItemBehavior* beh) { - Entity* temp = sub_08077C54(beh); + Entity* temp = CreateItemGetPlayerItemWithParent(beh); if (temp != NULL) { temp->flags = ENT_PERSIST; } gPlayerState.item = temp; } -Entity* sub_08077BD4(ItemBehavior* beh) { - if (sub_08077C94(beh, gUnk_0811BE48[beh->behaviorID].unk0[3]) != 0) { +Entity* CreatePlayerItemForItemIfNotExists(ItemBehavior* this) { + if (FindPlayerItemForItem(this, gItemDefinitions[this->behaviorId].playerItemId) != 0) { return NULL; } else { - return CreatePlayerItemWithParent(beh, gUnk_0811BE48[beh->behaviorID].unk0[3]); + return CreatePlayerItemWithParent(this, gItemDefinitions[this->behaviorId].playerItemId); } } -Entity* sub_08077C0C(ItemBehavior* beh, u32 arg1) { - u8 bVar1; - Entity* pEVar3; - - bVar1 = gUnk_0811BE48[arg1].unk0[3]; - - if (sub_08077C94(beh, bVar1) != 0) { +Entity* CreatePlayerItemIfNotExists(ItemBehavior* this, u32 index) { + u8 id = gItemDefinitions[index].playerItemId; + if (FindPlayerItemForItem(this, id) != 0) { return NULL; } else { - return CreatePlayerItemWithParent(beh, bVar1); + return CreatePlayerItemWithParent(this, id); } } -Entity* CreatePlayerItemWithParent(ItemBehavior* beh, u32 subtype) { - Entity* pEVar1; - - pEVar1 = CreatePlayerItem(subtype, 0, 0, beh->behaviorID); - if (pEVar1 != NULL) { - *(ItemBehavior**)&pEVar1->parent = beh; +Entity* CreatePlayerItemWithParent(ItemBehavior* this, u32 id) { + Entity* playerItem = CreatePlayerItem(id, 0, 0, this->behaviorId); + if (playerItem != NULL) { + playerItem->parent = (Entity*)this; } - return pEVar1; + return playerItem; } -void* sub_08077C54(ItemBehavior* unk) { - GenericEntity* item; - - item = (GenericEntity*)CreateItemGetEntity(); - if (item != NULL) { - item->base.id = gUnk_0811BE48[unk->behaviorID].unk0[3]; - item->base.kind = PLAYER_ITEM; - item->base.flags = 0xa0; - item->base.parent = (Entity*)unk; - item->field_0x68.HALF.LO = unk->behaviorID; - AppendEntityToList(&item->base, 2); +void* CreateItemGetPlayerItemWithParent(ItemBehavior* this) { + GenericEntity* playerItem = (GenericEntity*)CreateItemGetEntity(); + if (playerItem != NULL) { + playerItem->base.id = gItemDefinitions[this->behaviorId].playerItemId; + playerItem->base.kind = PLAYER_ITEM; + playerItem->base.flags = 0xa0; + playerItem->base.parent = (Entity*)this; + playerItem->field_0x68.HALF.LO = this->behaviorId; + AppendEntityToList(&playerItem->base, 2); } - return item; + return playerItem; } -Entity* sub_08077C94(ItemBehavior* arg0, u32 arg1) { - Entity* iVar1; - - iVar1 = FindEntityByID(PLAYER_ITEM, gUnk_0811BE48[arg1].unk0[3], 2); - if (iVar1 == NULL) { +Entity* FindPlayerItemForItem(ItemBehavior* this, u32 index) { + Entity* entity = FindEntityByID(PLAYER_ITEM, gItemDefinitions[index].playerItemId, 2); + if (entity == NULL) { return NULL; } - return iVar1; + return entity; } -Entity* CreatePlayerItem(u32 subtype, u32 form, u32 parameter, u32 unk) { +Entity* CreatePlayerItem(u32 id, u32 type, u32 type2, u32 unk) { GenericEntity* ent; ent = (GenericEntity*)GetEmptyEntity(); if (ent != NULL) { ent->base.flags = ENT_COLLIDE; ent->base.kind = PLAYER_ITEM; - ent->base.id = subtype; - ent->base.type = form; - ent->base.type2 = parameter; + ent->base.id = id; + ent->base.type = type; + ent->base.type2 = type2; ent->field_0x68.HALF.LO = unk; AppendEntityToList(&ent->base, 2); } return &ent->base; } -Entity* sub_08077CF8(u32 subtype, u32 form, u32 parameter, u32 unk) { +Entity* sub_08077CF8(u32 id, u32 type, u32 type2, u32 unk) { GenericEntity* ent; ent = (GenericEntity*)CreateItemGetEntity(); if (ent != NULL) { ent->base.flags = ENT_COLLIDE; ent->base.kind = PLAYER_ITEM; - ent->base.id = subtype; - ent->base.type = form; - ent->base.type2 = parameter; + ent->base.id = id; + ent->base.type = type; + ent->base.type2 = type2; ent->field_0x68.HALF.LO = unk; AppendEntityToList(&ent->base, 2); } return &ent->base; } -void sub_08077D38(ItemBehavior* beh, u32 idx) { +void sub_08077D38(ItemBehavior* this, u32 index) { u32 r6; - struct_0811BE48* ptr; + ItemDefinition* ptr; - gPlayerState.field_0xa |= 8 >> idx; - gPlayerState.keepFacing |= 8 >> idx; - beh->playerAnimationState = gPlayerEntity.animationState; - if (beh->stateID == 0) { - beh->stateID++; + gPlayerState.field_0xa |= 8 >> index; + gPlayerState.keepFacing |= 8 >> index; + this->playerAnimationState = gPlayerEntity.animationState; + if (this->stateID == 0) { + this->stateID++; } - ptr = &gUnk_0811BE48[beh->behaviorID]; - if (ptr->unk4) { + ptr = &gItemDefinitions[this->behaviorId]; + if (ptr->frameIndex) { if ((gPlayerState.flags & PL_NO_CAP)) { - switch (beh->behaviorID) { + switch (this->behaviorId) { case 0x1b: r6 = 0x948; break; @@ -559,15 +527,15 @@ void sub_08077D38(ItemBehavior* beh, u32 idx) { r6 = 0x40c; break; } - sub_08077DF4(beh, r6); + SetItemAnim(this, r6); } else { - sub_08077DF4(beh, ptr->unk4); + SetItemAnim(this, ptr->frameIndex); } } - beh->field_0xf = ptr->unk6[0]; - if (ptr->unk6[1]) { - gPlayerState.field_0x3[1] |= (8 >> idx) | ((8 >> idx) << 4); + this->animPriority = ptr->animPriority; + if (ptr->isChangingAttackStatus) { + gPlayerState.attack_status |= (8 >> index) | ((8 >> index) << 4); } } @@ -580,37 +548,37 @@ typedef struct { u8 unk[16]; } Unk_struct_in_08077EC8; -void sub_08077DF4(ItemBehavior* beh, u32 animation) { - beh->field_0x10 = animation; - if ((animation & 0xff) > 0xb8) { - animation += beh->playerAnimationState >> 1; +void SetItemAnim(ItemBehavior* this, u32 animIndex) { + this->animIndex = animIndex; + if ((animIndex & 0xff) > 0xb8) { + animIndex += this->playerAnimationState >> 1; } - gPlayerEntity.spriteIndex = (short)(animation >> 8); - InitAnimationForceUpdate(&gPlayerEntity, (u8)animation); - sub_08077E54(beh); + gPlayerEntity.spriteIndex = (s16)(animIndex >> 8); + InitAnimationForceUpdate(&gPlayerEntity, (u8)animIndex); + sub_08077E54(this); } -void UpdateItemAnim(ItemBehavior* beh) { +void UpdateItemAnim(ItemBehavior* this) { UpdateAnimationSingleFrame(&gPlayerEntity); - sub_08077E54(beh); + sub_08077E54(this); } -void sub_08077E3C(ItemBehavior* ent, u32 idx) { - sub_080042BA(&gPlayerEntity, idx); - sub_08077E54(ent); +void sub_08077E3C(ItemBehavior* this, u32 index) { + sub_080042BA(&gPlayerEntity, index); + sub_08077E54(this); } -static void sub_08077E54(ItemBehavior* beh) { - beh->playerAnimIndex = gPlayerEntity.animIndex; - beh->playerFrameIndex = gPlayerEntity.frameIndex; - beh->playerFrameDuration = gPlayerEntity.frameDuration; - beh->playerFrame = gPlayerEntity.frame; +static void sub_08077E54(ItemBehavior* this) { + this->playerAnimIndex = gPlayerEntity.animIndex; + this->playerFrameIndex = gPlayerEntity.frameIndex; + this->playerFrameDuration = gPlayerEntity.frameDuration; + this->playerFrame = gPlayerEntity.frame; } -void DeletePlayerItem(ItemBehavior* arg0, u32 idx) { +void DeleteItemBehavior(ItemBehavior* this, u32 index) { u32 not ; - if (idx == 0) { + if (index == 0) { if (gPlayerState.item != NULL) { ((Unk_bitfield*)gPlayerState.item)[0x11].b0 = 6; gPlayerState.item = NULL; @@ -619,62 +587,62 @@ void DeletePlayerItem(ItemBehavior* arg0, u32 idx) { } } - not = (8 >> idx); - gPlayerState.field_0x3[1] &= ~((u8)((8 >> idx) << 4) | not ); + not = (8 >> index); + gPlayerState.attack_status &= ~((u8)((8 >> index) << 4) | not ); not = ~not ; gPlayerState.field_0xa &= not ; gPlayerState.keepFacing &= not ; - MemClear(arg0, sizeof(ItemBehavior)); + MemClear(this, sizeof(ItemBehavior)); } -bool32 sub_08077EC8(ItemBehavior* beh) { +bool32 sub_08077EC8(ItemBehavior* this) { if ((gPlayerState.sword_state & 8) != 0) { - sub_08077DF4(beh, 0x170); - beh->timer = 0x28; - beh->stateID = 7; - beh->field_0xf = 6; + SetItemAnim(this, 0x170); + this->timer = 0x28; + this->stateID = 7; + this->animPriority = 6; return TRUE; } else { return FALSE; } } -bool32 sub_08077EFC(ItemBehavior* arg0) { - return sub_08077F24(arg0, (u16)gPlayerState.playerInput.field_0x90); +bool32 IsItemActive(ItemBehavior* this) { + return IsItemActiveByInput(this, gPlayerState.playerInput.heldInput); } -bool32 sub_08077F10(ItemBehavior* arg0) { - return sub_08077F24(arg0, (u16)gPlayerState.playerInput.field_0x92); +bool32 IsItemActivatedThisFrame(ItemBehavior* this) { + return IsItemActiveByInput(this, gPlayerState.playerInput.newInput); } -bool32 sub_08077F24(ItemBehavior* beh, u32 arg1) { +bool32 IsItemActiveByInput(ItemBehavior* this, PlayerInputState input) { u32 val; Stats* stats = &gSave.stats; - u32 id = beh->behaviorID; + u32 id = this->behaviorId; if (stats->itemButtons[SLOT_A] == id) { - val = 1; + val = PLAYER_INPUT_1; } else if (stats->itemButtons[SLOT_B] == id) { - val = 2; + val = PLAYER_INPUT_2; } else { val = 0; } - return (val & arg1) ? 1 : 0; + return (val & input) ? TRUE : FALSE; } -void PlayerCancelHoldItem(ItemBehavior* beh, u32 arg1) { +void PlayerCancelHoldItem(ItemBehavior* this, u32 index) { PlayerDropHeldObject(); - DeletePlayerItem(beh, arg1); + DeleteItemBehavior(this, index); } /** * Check if player state believes the held item is valid? * If it's not delete the item? */ -bool32 PlayerTryDropObject(ItemBehavior* arg0, u32 unk) { +bool32 PlayerTryDropObject(ItemBehavior* this, u32 index) { u32 temp; if (gPlayerState.heldObject == 0) { - PlayerCancelHoldItem(arg0, unk); + PlayerCancelHoldItem(this, index); temp = FALSE; } else { temp = TRUE; @@ -682,6 +650,8 @@ bool32 PlayerTryDropObject(ItemBehavior* arg0, u32 unk) { return temp; } +// TODO move above into a itemUtils.c ? + void sub_08077F84(void) { Entity* obj; @@ -917,7 +887,7 @@ bool32 sub_080782C0(void) { return FALSE; } } - if (((gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_1000) != 0) && ((u8)(gUnk_03003DF0.unk_4[3] - 1) < 100)) { + if (((gPlayerState.playerInput.newInput & PLAYER_INPUT_1000) != 0) && ((u8)(gUnk_03003DF0.unk_4[3] - 1) < 100)) { sub_0801E738(0); if (gSave.unk12B[0] != 0) { gUnk_03003DF0.unk_2 = gUnk_03003DF0.unk_4[3]; @@ -929,7 +899,7 @@ bool32 sub_080782C0(void) { ForceSetPlayerState(PL_STATE_TALKEZLO); return TRUE; } - if ((gPlayerState.playerInput.field_0x92 & (PLAYER_INPUT_80 | PLAYER_INPUT_8)) == 0) { + if ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_8)) == 0) { return FALSE; } switch (gUnk_03003DF0.unk_4[1]) { @@ -1167,11 +1137,11 @@ void sub_08078B48(void) { } void ClearPlayerState(void) { - gPlayerState.field_0x0[0] = 0; - gPlayerState.field_0x0[1] = 0; + gPlayerState.prevAnim = 0; + gPlayerState.grab_status = 0; gPlayerState.jump_status = 0; - gPlayerState.field_0x3[0] = 0; - gPlayerState.field_0x3[1] = 0; + gPlayerState.shield_status = 0; + gPlayerState.attack_status = 0; gPlayerState.heldObject = 0; gPlayerState.pushedObject = 0; gPlayerState.field_0x7 = 0; @@ -1181,8 +1151,8 @@ void ClearPlayerState(void) { gPlayerState.field_0x35 = 0; gPlayerState.field_0x36 = 0; gPlayerState.queued_action = PLAYER_INIT; - gPlayerState.field_0xd = 0; - gPlayerState.field_0xe = 0; + gPlayerState.direction = 0; + gPlayerState.itemAnimPriority = 0; gPlayerState.surfacePositionSameTimer = 0; gPlayerState.floor_type = SURFACE_NORMAL; gPlayerState.floor_type_last = SURFACE_NORMAL; @@ -1273,7 +1243,7 @@ bool32 CheckQueuedAction(void) { // this doesnt seem to have any real function where its used void CheckPlayerVelocity(void) { - u32 angle = gPlayerState.field_0xd; + u32 angle = gPlayerState.direction; if ((angle & 0x80) != 0) { ResetPlayerVelocity(); } else { @@ -1345,20 +1315,20 @@ void sub_08078FB0(Entity* this) { void sub_08079064(Entity* this) { u32 i; - u32 bVar4; - u32 animation; + u32 maxAnimPriority; + u32 animIndex; if ((gPlayerState.flags & (PL_IN_HOLE | PL_MINISH)) == 0) { - bVar4 = 0; + maxAnimPriority = 0; for (i = 0; i < 4; i++) { - if (gUnk_03000B80[i].field_0xf > bVar4) { - bVar4 = gUnk_03000B80[i].field_0xf; - animation = gUnk_03000B80[i].field_0x10; + if (gActiveItems[i].animPriority > maxAnimPriority) { + maxAnimPriority = gActiveItems[i].animPriority; + animIndex = gActiveItems[i].animIndex; } } - if (gPlayerState.field_0xe < bVar4) { - gPlayerState.animation = animation; + if (gPlayerState.itemAnimPriority < maxAnimPriority) { + gPlayerState.animation = animIndex; } else if ((gPlayerState.swim_state & 0x80) != 0) { gPlayerState.animation = 0x2be; } else { @@ -1408,7 +1378,7 @@ void sub_080790E4(Entity* this) { void PlayerDropHeldObject(void) { gPlayerState.heldObject = 0; - gPlayerState.field_0x0[1] = 0; + gPlayerState.grab_status = 0; gNewPlayerEntity.unk_74 = NULL; } @@ -1480,9 +1450,9 @@ bool32 sub_080793E4(u32 param_1) { } else { tmp = gUnk_0811C0F8[gPlayerEntity.direction >> 2]; } - if (sub_08079778() && ((gPlayerState.playerInput.field_0x90 & tmp) != 0)) { + if (sub_08079778() && ((gPlayerState.playerInput.heldInput & tmp) != 0)) { if (param_1 != 0) { - if (!sub_080B1BA4(sub_0807A500(), gPlayerEntity.collisionLayer, param_1)) { + if (!sub_080B1BA4(GetPlayerTilePos(), gPlayerEntity.collisionLayer, param_1)) { return FALSE; } } @@ -1535,9 +1505,9 @@ code_3: } void sub_08079520(Entity* this) { - s32 tmp = gPlayerState.field_0xd; + s32 tmp = gPlayerState.direction; if (tmp < 0x80) { - this->direction = gPlayerState.field_0xd; + this->direction = gPlayerState.direction; } else { this->direction = (this->animationState >> 1) << 3; } @@ -1545,7 +1515,7 @@ void sub_08079520(Entity* this) { u32 sub_0807953C(void) { u32 tmp = PLAYER_INPUT_ANY_DIRECTION | PLAYER_INPUT_20 | PLAYER_INPUT_10 | PLAYER_INPUT_8; - return gPlayerState.playerInput.field_0x92 & tmp; + return gPlayerState.playerInput.newInput & tmp; } ASM_FUNC("asm/non_matching/playerUtils/sub_08079550.inc", u32 sub_08079550(void)) @@ -1601,7 +1571,7 @@ ASM_FUNC("asm/non_matching/playerUtils/sub_080797EC.inc", void sub_080797EC()) void ResolvePlayerAnimation(void) { u32 index; - u32 tmp; + u32 maxAnimPriority; u32 anim; if ((gPlayerState.flags & PL_NO_CAP) != 0) { if (gPlayerState.heldObject != 0) { @@ -1612,7 +1582,7 @@ void ResolvePlayerAnimation(void) { } if ((gPlayerState.flags & PL_CONVEYOR_PUSHED) != 0) { anim = 0x810; - } else if (gPlayerState.field_0x3[0] != 0) { + } else if (gPlayerState.shield_status != 0) { anim = 0x414; } else if (gPlayerState.field_0x1f[2] != 0) { anim = 0x280; @@ -1623,7 +1593,7 @@ void ResolvePlayerAnimation(void) { return; } if (gPlayerState.sword_state == 0) { - if (gPlayerState.field_0x3[1] != 0) { + if (gPlayerState.attack_status != 0) { return; } if ((gPlayerState.flags & PL_USE_PORTAL) != 0) { @@ -1661,7 +1631,7 @@ void ResolvePlayerAnimation(void) { anim = 0x298; } else if ((gPlayerState.flags & PL_IN_MINECART) != 0) { anim = 0x70c; - } else if (gPlayerState.field_0x3[0] != 0) { + } else if (gPlayerState.shield_status != 0) { anim = 0x164; } else if (gPlayerState.field_0x1f[2] != 0) { anim = 0x280; @@ -1677,11 +1647,11 @@ void ResolvePlayerAnimation(void) { if (gPlayerState.sword_state != 0) { anim = 0x168; } else { - if (gPlayerState.field_0x3[1] != 0) { + if (gPlayerState.attack_status != 0) { return; } - if ((gPlayerState.flags & PL_USE_LANTERN) != 0) { - if (gUnk_03000B80[3].field_0xf != 0) { + if (gPlayerState.flags & PL_USE_LANTERN) { + if (gActiveItems[ACTIVE_ITEM_LANTERN].animPriority != 0) { return; } anim = 0x604; @@ -1696,20 +1666,20 @@ void ResolvePlayerAnimation(void) { gPlayerState.animation = anim; if (gPlayerState.heldObject == 0) { - tmp = 0; + maxAnimPriority = 0; for (index = 0; index < 4; index++) { - if (gUnk_03000B80[index].field_0xf > tmp) { - tmp = gUnk_03000B80[index].field_0xf; + if (gActiveItems[index].animPriority > maxAnimPriority) { + maxAnimPriority = gActiveItems[index].animPriority; } } - if (gPlayerState.field_0xe < tmp) { + if (gPlayerState.itemAnimPriority < maxAnimPriority) { return; } - if ((u8)anim == gPlayerState.field_0x0[0]) { + if ((u8)anim == gPlayerState.prevAnim) { UpdateAnimationSingleFrame(&gPlayerEntity); } } - gPlayerState.field_0x0[0] = anim; + gPlayerState.prevAnim = anim; } bool32 sub_08079B24(void) { @@ -1728,7 +1698,7 @@ bool32 sub_08079B24(void) { if ((gPlayerState.jump_status & 0x41) == 0) { gPlayerState.jump_status = 0x41; gPlayerEntity.direction = 0xff; - gPlayerState.field_0xd = 0xff; + gPlayerState.direction = 0xff; return TRUE; } else { return TRUE; @@ -1934,49 +1904,49 @@ u32 sub_08079FD4(Entity* this, u32 param_2) { return index; } -void sub_0807A050(void) { +void UpdatePlayerPalette(void) { u32 palette; if ((gPlayerState.hurtBlinkSpeed != 0) && ((gMessage.doTextBox & 0x7f) == 0)) { gPlayerState.hurtBlinkSpeed--; } - palette = sub_0807A094(0); + palette = GetPlayerPalette(FALSE); if (palette != gPlayerState.playerPalette) { gPlayerState.playerPalette = palette; ChangeObjPalette(&gPlayerEntity, palette); } } -u32 sub_0807A094(u32 param_1) { +u32 GetPlayerPalette(bool32 affectedBy) { bool32 condition; - u32 result = 0x16; + u32 palette = 0x16; if (gPlayerState.hurtBlinkSpeed != 0) { - result = 0x1b; - if (0x78 < gPlayerState.hurtBlinkSpeed) { - result = 0x1a; + palette = 0x1b; + if (gPlayerState.hurtBlinkSpeed > 0x78) { + palette = 0x1a; } } else { if (gSave.stats.charm != 0) { condition = TRUE; - if (((param_1 == 0) && (gSave.stats.charmTimer < 0xb4)) && ((gSave.stats.charmTimer & 8) != 0)) { + if (!affectedBy && (gSave.stats.charmTimer < 0xb4) && ((gSave.stats.charmTimer & 8) != 0)) { condition = FALSE; } if (condition) { switch (gSave.stats.charm) { - case 0x2f: - result = 0x18; + case BOTTLE_CHARM_NAYRU: + palette = 0x18; break; - case 0x31: - result = 0x17; + case BOTTLE_CHARM_DIN: + palette = 0x17; break; - case 0x30: + case BOTTLE_CHARM_FARORE: default: - result = 0x19; + palette = 0x19; break; } } } } - return result; + return palette; } void DeleteClones(void) { @@ -2052,7 +2022,7 @@ bool32 sub_0807A2B8(void) { ASM_FUNC("asm/non_matching/playerUtils/sub_0807A2F8.inc", u32 sub_0807A2F8(u32 a1)) -u32 sub_0807A500(void) { +u32 GetPlayerTilePos(void) { switch (gPlayerEntity.animationState >> 1) { case 0: return TILE(gPlayerEntity.x.HALF.HI, @@ -2074,7 +2044,7 @@ ASM_FUNC("asm/non_matching/playerUtils/sub_0807A5B8.inc", void sub_0807A5B8(u32 ASM_FUNC("asm/non_matching/playerUtils/sub_0807A750.inc", void sub_0807A750()) -u32 sub_0807A894(Entity* this) { +u32 GetCollisionTileInFront(Entity* this) { s32 x; s32 y; switch (this->direction) { @@ -2217,7 +2187,7 @@ bool32 sub_0807AC54(Entity* this) { } } -void sub_0807ACCC(Entity* this) { +void PlayerSwimming(Entity* this) { s32 speed; this->spritePriority.b1 = 0; this->knockbackDuration = 0; @@ -2226,9 +2196,9 @@ void sub_0807ACCC(Entity* this) { } else { speed = 0xc0; } - if (speed > *(s16*)&this->speed) { + if (speed > this->speed) { this->speed = speed; - this->direction = gPlayerState.field_0xd; + this->direction = gPlayerState.direction; if ((gPlayerState.swim_state & 0xf) != 1) { return; } @@ -2236,17 +2206,18 @@ void sub_0807ACCC(Entity* this) { this->speed -= 4; } if (gPlayerState.remainingDiveTime == 0) { - if (!sub_0807ADB8(this)) { - sub_0807AE20(this); + if (!ToggleDiving(this)) { + PlayerUpdateSwimming(this); } } else { gPlayerState.remainingDiveTime--; if (gPlayerState.remainingDiveTime != 0) { - sub_0807ADB8(this); + ToggleDiving(this); } else { - gPlayerState.swim_state &= 0x7f; + // End diving. + gPlayerState.swim_state &= ~0x80; this->spritePriority.b0 = 4; - SoundReq(SFX_163); + SoundReq(SFX_TOGGLE_DIVING); } } if ((gPlayerState.swim_state & 0x80) != 0) { @@ -2257,27 +2228,25 @@ void sub_0807ACCC(Entity* this) { } } -bool32 sub_0807ADB8(Entity* this) { - u8 tmp; - if ((gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_10) != 0) { +bool32 ToggleDiving(Entity* this) { + if (gPlayerState.playerInput.newInput & PLAYER_INPUT_10) { gPlayerState.swim_state ^= 0x80; - tmp = (gPlayerState.swim_state & 0x80); - if (tmp != 0) { + if (gPlayerState.swim_state & 0x80) { gPlayerState.remainingDiveTime = 0x78; } else { this->spritePriority.b0 = 4; - gPlayerState.remainingDiveTime = tmp; + gPlayerState.remainingDiveTime = 0; } - SoundReq(SFX_163); + SoundReq(SFX_TOGGLE_DIVING); return TRUE; } else { return FALSE; } } -void sub_0807AE20(Entity* this) { +void PlayerUpdateSwimming(Entity* this) { if ((((this->action != 0x17) || (gPlayerState.field_0xa == 0)) && (gRoomControls.reload_flags == 0)) && - ((gPlayerState.playerInput.field_0x92 & PLAYER_INPUT_8) != 0)) { + ((gPlayerState.playerInput.newInput & PLAYER_INPUT_8) != 0)) { if (GetInventoryValue(ITEM_SWIM_BUTTERFLY) == 1) { this->speed = 0x1c0; } else { @@ -2344,7 +2313,7 @@ void UpdatePlayerSkills(void) { } } -void sub_0807AFE8(void) { +void PlayerShrinkByRay(void) { Entity* effect; PutAwayItems(); effect = CreateFx(&gPlayerEntity, FX_BIG_EXPLOSION2, 0); @@ -2355,11 +2324,11 @@ void sub_0807AFE8(void) { } /** Returns which kind of sword projectile is created. */ -u32 sub_0807B014(void) { - if (((gPlayerState.skills & SKILL_SWORD_BEAM) != 0) && gSave.stats.health == gSave.stats.maxHealth) { +u32 GetSwordBeam(void) { + if ((gPlayerState.skills & SKILL_SWORD_BEAM) && gSave.stats.health == gSave.stats.maxHealth) { return 0xf; } else { - if ((gPlayerState.skills & SKILL_PERIL_BEAM) != SKILL_NONE && gSave.stats.health <= 8) { + if ((gPlayerState.skills & SKILL_PERIL_BEAM) && gSave.stats.health <= 8) { return 0x16; } else { return 0; @@ -2368,7 +2337,7 @@ u32 sub_0807B014(void) { } void sub_0807B068(Entity* entity) { - if ((gPlayerState.dash_state | gPlayerState.field_0x3[1]) == 0) { + if ((gPlayerState.dash_state | gPlayerState.attack_status) == 0) { if (gPlayerState.swim_state != 0) { if ((gPlayerState.swim_state & 0x80) != 0) { gPlayerState.animation = 0xc1c; @@ -2376,7 +2345,7 @@ void sub_0807B068(Entity* entity) { gPlayerState.animation = 0xc0c; } } else { - if ((gPlayerState.field_0xd & 0x80) != 0) { + if ((gPlayerState.direction & 0x80) != 0) { if (gPlayerState.animation != 0xc18) { gPlayerState.animation = 0xc18; } diff --git a/src/projectile/v1DarkMagicProjectile.c b/src/projectile/v1DarkMagicProjectile.c index d6c4b568..6bf78af5 100644 --- a/src/projectile/v1DarkMagicProjectile.c +++ b/src/projectile/v1DarkMagicProjectile.c @@ -35,7 +35,7 @@ void sub_080AAC44(Entity* this) { } else { SortEntityAbove(this->parent, this); } - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.mobility |= 0x80; gPlayerState.field_0xa |= 0x80; } @@ -215,7 +215,7 @@ void sub_080AAF74(Entity* this) { gPlayerState.mobility = 0; this->health = 0; } else { - ResetPlayerItem(); + ResetActiveItems(); gPlayerState.mobility |= 0x80; gPlayerState.field_0xa |= 0x80; CopyPosition(&gPlayerEntity, this); diff --git a/src/scroll.c b/src/scroll.c index 37af7af7..e6a0fa6d 100644 --- a/src/scroll.c +++ b/src/scroll.c @@ -297,7 +297,7 @@ void sub_0807FF6C(RoomControls* controls) { gScreen.controls.windowOutsideControl = (gScreen.controls.windowOutsideControl & 0xff00) | 7; gScreen.controls.window1HorizontalDimensions = 0xf0; gScreen.controls.window1VerticalDimensions = 0xf0; - ResetPlayerItem(); + ResetActiveItems(); ResetPlayerAnimationAndAction(); if (gDiggingCaveEntranceTransition.isDiggingCave) { gPlayerEntity.animationState = 4; diff --git a/src/sound.c b/src/sound.c index 532d964f..f888af22 100644 --- a/src/sound.c +++ b/src/sound.c @@ -549,7 +549,7 @@ extern const SongHeader sfx15F; extern const SongHeader sfx160; extern const SongHeader sfx161; extern const SongHeader sfx162; -extern const SongHeader sfx163; +extern const SongHeader sfxToggleDiving; extern const SongHeader sfx164; extern const SongHeader sfx165; extern const SongHeader sfx166; @@ -1181,7 +1181,7 @@ const Song gSongTable[] = { [SFX_160] = { &sfx160, MUSIC_PLAYER_04, MUSIC_PLAYER_04 }, [SFX_161] = { &sfx161, MUSIC_PLAYER_1D, MUSIC_PLAYER_1D }, [SFX_162] = { &sfx162, MUSIC_PLAYER_1C, MUSIC_PLAYER_1C }, - [SFX_163] = { &sfx163, MUSIC_PLAYER_1B, MUSIC_PLAYER_1B }, + [SFX_TOGGLE_DIVING] = { &sfxToggleDiving, MUSIC_PLAYER_1B, MUSIC_PLAYER_1B }, [SFX_164] = { &sfx164, MUSIC_PLAYER_1A, MUSIC_PLAYER_1A }, [SFX_165] = { &sfx165, MUSIC_PLAYER_19, MUSIC_PLAYER_19 }, [SFX_166] = { &sfx166, MUSIC_PLAYER_18, MUSIC_PLAYER_18 },