From 2277fb7a1e35d8983125fda6804875eedf3e102a Mon Sep 17 00:00:00 2001 From: Blake Warner Date: Wed, 6 Apr 2022 20:43:37 -0400 Subject: [PATCH] fixed ztarget reticule --- include/def/z_actor.h | 7 +- include/def/z_player_lib.h | 2 +- include/framerate.h | 2 + include/player_state.h | 75 +++++++++++++++ include/z64actor.h | 2 +- src/code/framerate.cpp | 31 +++++-- src/code/z_actor.cpp | 27 +++--- src/code/z_camera.cpp | 1 + src/code/z_player_lib.cpp | 11 ++- .../actors/ovl_En_Dekunuts/z_en_dekunuts.cpp | 12 ++- .../actors/ovl_En_Dekunuts/z_en_dekunuts.h | 2 +- src/overlays/actors/ovl_En_Elf/z_en_elf.cpp | 8 +- src/overlays/actors/ovl_En_Ge1/z_en_ge1.cpp | 1 + src/overlays/actors/ovl_En_In/z_en_in.cpp | 1 + src/overlays/actors/ovl_En_Ma3/z_en_ma3.cpp | 1 + .../actors/ovl_En_Po_Field/z_en_po_field.cpp | 1 + src/overlays/actors/ovl_En_Wf/z_en_wf.cpp | 2 +- src/overlays/actors/ovl_En_Zf/z_en_zf.cpp | 2 +- .../actors/ovl_player_actor/z_player.cpp | 93 ++++++++++--------- .../actors/ovl_player_actor/z_player.h | 2 +- 20 files changed, 194 insertions(+), 89 deletions(-) create mode 100644 include/player_state.h diff --git a/include/def/z_actor.h b/include/def/z_actor.h index b4beb5d6b..876c70195 100644 --- a/include/def/z_actor.h +++ b/include/def/z_actor.h @@ -203,10 +203,5 @@ u16 func_80037C30(GlobalContext* globalCtx, s16 arg1); s32 func_80037D98(GlobalContext* globalCtx, Actor* actor, s16 arg2, s32* arg3); s32 func_80038290(GlobalContext* globalCtx, Actor* actor, Vec3s* arg2, Vec3s* arg3, Vec3f arg4); -enum PlayerState1 -{ - PLAYER_STATE_SWORD_CHARGE = 0x1000, - PLAYER_STATE_HORSE_MOUNTED = 0x800000, - PLAYER_STATE_SWIMMING = 0x8000000 -}; + diff --git a/include/def/z_player_lib.h b/include/def/z_player_lib.h index e5c76c105..d277e85da 100644 --- a/include/def/z_player_lib.h +++ b/include/def/z_player_lib.h @@ -55,7 +55,7 @@ Player* Player_UnsetMask(GlobalContext* globalCtx); void Player_UpdateBottleHeld(GlobalContext* globalCtx, Player* player, s32 item, s32 actionParam); s32 func_8008E9C4(Player* player); void func_8008EC70(Player* player); -void func_8008EDF0(Player* player); +void Player_ClearZTarget(Player* player); void func_8008EE08(Player* player); void func_8008EEAC(GlobalContext* globalCtx, Actor* actor); s32 func_8008EF44(GlobalContext* globalCtx, s32 ammo); diff --git a/include/framerate.h b/include/framerate.h index 85af935b4..201bde5e0 100644 --- a/include/framerate.h +++ b/include/framerate.h @@ -98,6 +98,8 @@ class Timer Timer& operator^=(u64 n); s32 operator%(s32 n) const; Timer operator&(long n) const; + Timer operator|(long n) const; + Timer operator^(long n) const; s32 operator<<(long n); s32 operator>>(long n); diff --git a/include/player_state.h b/include/player_state.h new file mode 100644 index 000000000..0eb08cc15 --- /dev/null +++ b/include/player_state.h @@ -0,0 +1,75 @@ +#pragma once + +enum PlayerState1 +{ + PLAYER_STATE1_0 = 1 << 0, // 0x00000001 + PLAYER_STATE1_1 = 1 << 1, // 0x00000002 + PLAYER_STATE1_2 = 1 << 2, // 0x00000004 + PLAYER_STATE1_3 = 1 << 3, // 0x00000008 + PLAYER_STATE1_4 = 1 << 4, // 0x00000010 + PLAYER_STATE1_5 = 1 << 5, // 0x00000020 + PLAYER_STATE1_6 = 1 << 6, // 0x00000040 + PLAYER_STATE1_7 = 1 << 7, // 0x00000080 + PLAYER_STATE1_8 = 1 << 8, // 0x00000100 + PLAYER_STATE1_9 = 1 << 9, // 0x00000200 + PLAYER_STATE1_10 = 1 << 10, // 0x00000400 + PLAYER_STATE1_11 = 1 << 11, // 0x00000800 + PLAYER_STATE_SWORD_CHARGE = 1 << 12, // 0x00001000 + PLAYER_STATE1_13 = 1 << 13, // 0x00002000 + PLAYER_STATE1_14 = 1 << 14, // 0x00004000 + PLAYER_STATE1_15 = 1 << 15, // 0x00008000 + PLAYER_STATE1_16 = 1 << 16, // 0x00010000 + PLAYER_STATE1_17 = 1 << 17, // 0x00020000 + PLAYER_STATE1_18 = 1 << 18, // 0x00040000 + PLAYER_STATE1_19 = 1 << 19, // 0x00080000 + PLAYER_STATE1_20 = 1 << 20, // 0x00100000 + PLAYER_STATE1_21 = 1 << 21, // 0x00200000 + PLAYER_STATE1_22 = 1 << 22, // 0x00400000 + PLAYER_STATE_HORSE_MOUNTED = 1 << 23, // 0x00800000 + PLAYER_STATE1_24 = 1 << 24, // 0x01000000 + PLAYER_STATE1_25 = 1 << 25, // 0x02000000 + PLAYER_STATE1_26 = 1 << 26, // 0x04000000 + PLAYER_STATE_SWIMMING = 1 << 27, // 0x08000000 + PLAYER_STATE1_28 = 1 << 28, // 0x10000000 + PLAYER_STATE1_29 = 1 << 29, // 0x20000000 + PLAYER_STATE1_30 = 1 << 30, // 0x40000000 + PLAYER_STATE1_31 = 1 << 31, // 0x80000000 +}; + +enum PlayerState2 +{ + PLAYER_STATE2_0 = 1 << 0, // 0x00000001 + PLAYER_STATE2_1 = 1 << 1, // 0x00000002 + PLAYER_STATE2_2 = 1 << 2, // 0x00000004 + PLAYER_STATE2_3 = 1 << 3, // 0x00000008 + PLAYER_STATE2_4 = 1 << 4, // 0x00000010 + PLAYER_STATE2_5 = 1 << 5, // 0x00000020 + PLAYER_STATE2_6 = 1 << 6, // 0x00000040 + PLAYER_STATE2_7 = 1 << 7, // 0x00000080 + PLAYER_STATE2_8 = 1 << 8, // 0x00000100 + PLAYER_STATE2_9 = 1 << 9, // 0x00000200 + PLAYER_STATE2_10 = 1 << 10, // 0x00000400 + PLAYER_STATE2_11 = 1 << 11, // 0x00000800 + PLAYER_STATE2_12 = 1 << 12, // 0x00001000 + PLAYER_STATE2_ZTARGET_CHANGED = 1 << 13, // 0x00002000 + PLAYER_STATE2_14 = 1 << 14, // 0x00004000 + PLAYER_STATE2_15 = 1 << 15, // 0x00008000 + PLAYER_STATE2_16 = 1 << 16, // 0x00010000 + PLAYER_STATE2_17 = 1 << 17, // 0x00020000 + PLAYER_STATE2_18 = 1 << 18, // 0x00040000 + PLAYER_STATE2_19 = 1 << 19, // 0x00080000 + PLAYER_STATE2_20 = 1 << 20, // 0x00100000 + PLAYER_STATE2_21 = 1 << 21, // 0x00200000 + PLAYER_STATE2_22 = 1 << 22, // 0x00400000 + PLAYER_STATE2_23 = 1 << 23, // 0x00800000 + PLAYER_STATE2_24 = 1 << 24, // 0x01000000 + PLAYER_STATE2_25 = 1 << 25, // 0x02000000 + PLAYER_STATE2_26 = 1 << 26, // 0x04000000 + PLAYER_STATE2_27 = 1 << 27, // 0x08000000 + PLAYER_STATE2_28 = 1 << 28, // 0x10000000 + PLAYER_STATE2_29 = 1 << 29, // 0x20000000 + PLAYER_STATE2_30 = 1 << 30, // 0x40000000 + PLAYER_STATE2_31 = 1 << 31, // 0x80000000 +}; + +static_assert((1 << 13) == 0x2000, "bah"); \ No newline at end of file diff --git a/include/z64actor.h b/include/z64actor.h index 83d7bcf03..544ff4d97 100644 --- a/include/z64actor.h +++ b/include/z64actor.h @@ -408,7 +408,7 @@ struct TargetContext { /* 0x44 */ f32 unk_44; /* 0x48 */ s16 unk_48; /* 0x4A */ u8 activeCategory; - /* 0x4B */ u8 unk_4B; + /* 0x4B */ Counter unk_4B; /* 0x4C */ s8 unk_4C; /* 0x4D */ char unk_4D[0x03]; /* 0x50 */ TargetContextEntry arr_50[3]; diff --git a/src/code/framerate.cpp b/src/code/framerate.cpp index a3dbcef19..d4bc3d9e9 100644 --- a/src/code/framerate.cpp +++ b/src/code/framerate.cpp @@ -3,7 +3,7 @@ #include "z64game.h" #include "regs.h" -#define COUNTER_STEP 20.0f / FRAME_RATE +#define COUNTER_STEP 20 / FRAME_RATE #define COUNTER_SCALER FRAME_RATE / 20 static FramerateProfile g_profile = PROFILE_BOOT; @@ -119,7 +119,7 @@ Timer Timer::invalid() void Timer::update() { - m_counter = m_counterInt * COUNTER_STEP; + m_counter = (float)m_counterInt * COUNTER_STEP; } Timer& Timer::operator++() // pre @@ -233,19 +233,22 @@ Timer& Timer::operator/=(float f) Timer& Timer::operator&=(u64 n) { - *this = whole() & n; + *this = m_counterInt & (n * COUNTER_SCALER); + update(); return *this; } Timer& Timer::operator|=(u64 n) { - *this = whole() | n; + *this = m_counterInt | (n * COUNTER_SCALER); + update(); return *this; } Timer& Timer::operator^=(u64 n) { - *this = whole() ^ n; + *this = m_counterInt ^ (n * COUNTER_SCALER); + update(); return *this; } @@ -256,7 +259,23 @@ s32 Timer::operator%(s32 n) const Timer Timer::operator&(long n) const { - return Timer(whole() & n); + Timer t = *this; + t &= n; + return t; +} + +Timer Timer::operator|(long n) const +{ + Timer t = *this; + t |= n; + return t; +} + +Timer Timer::operator^(long n) const +{ + Timer t = *this; + t ^= n; + return t; } s32 Timer::operator<<(long n) diff --git a/src/code/z_actor.cpp b/src/code/z_actor.cpp index 095b1ea4a..26774727d 100644 --- a/src/code/z_actor.cpp +++ b/src/code/z_actor.cpp @@ -12,6 +12,7 @@ #include "z64actor.h" #include "gfx_align.h" #include "port/options.h" +#include "player_state.h" #include "overlays/actors/ovl_Arms_Hook/z_arms_hook.h" #include "overlays/actors/ovl_En_Part/z_en_part.h" @@ -405,7 +406,7 @@ void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx) { func_8002BE64(targetCtx, targetCtx->unk_4C, spBC.x, spBC.y, spBC.z); - if ((!(player->stateFlags1 & 0x40)) || (actor != player->unk_664)) { + if ((!(player->stateFlags1 & PLAYER_STATE1_6)) || (actor != player->targetedActor)) { OVERLAY_DISP = Gfx_CallSetupDL(OVERLAY_DISP, 0x39); for (spB0 = 0, spAC = targetCtx->unk_4C; spB0 < spB8; spB0++, spAC = (spAC + 1) % 3) { @@ -423,7 +424,7 @@ void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx) { gDPSetPrimColor(OVERLAY_DISP++, 0, 0, entry->color.r, entry->color.g, entry->color.b, (u8)spCE); - Matrix_RotateZ((targetCtx->unk_4B & 0x7F) * (M_PI / 64), MTXMODE_APPLY); + Matrix_RotateZ(targetCtx->unk_4B * (M_PI / 64), MTXMODE_APPLY); for (i = 0; i < 4; i++) { Matrix_RotateZ(M_PI / 2, MTXMODE_APPLY); @@ -480,7 +481,7 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Gl unkActor = NULL; - if ((player->unk_664 != NULL) && (player->unk_84B[player->unk_846] == 2)) { + if ((player->targetedActor != NULL) && (player->unk_84B[player->unk_846] == 2)) { targetCtx->unk_94 = NULL; } else { func_80032AF0(globalCtx, &globalCtx->actorCtx, &unkActor, player); @@ -554,7 +555,7 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Gl targetCtx->unk_4B++; } } else { - targetCtx->unk_4B = (targetCtx->unk_4B + 3) | 0x80; + targetCtx->unk_4B += 3; targetCtx->unk_44 = 120.0f; } } else { @@ -1483,7 +1484,7 @@ f32 func_8002EFC0(Actor* actor, Player* player, s16 arg2) { s16 yawTemp = (s16)(actor->yawTowardsPlayer - 0x8000) - arg2; s16 yawTempAbs = ABS(yawTemp); - if (player->unk_664 != NULL) { + if (player->targetedActor != NULL) { if ((yawTempAbs > 0x4000) || (actor->flags & ACTOR_FLAG_27)) { return FLT_MAX; } else { @@ -1529,7 +1530,7 @@ s32 func_8002F0C8(Actor* actor, Player* player, s32 flag) { s16 abs_var = ABS(var); f32 dist; - if ((player->unk_664 == NULL) && (abs_var > 0x2AAA)) { + if ((player->targetedActor == NULL) && (abs_var > 0x2AAA)) { dist = FLT_MAX; } else { dist = actor->xyzDistToPlayerSq; @@ -2139,13 +2140,13 @@ void Actor_UpdateAll(GlobalContext* globalCtx, ActorContext* actorCtx) { actor->flags &= ~ACTOR_FLAG_24; if ((DECR(actor->freezeTimer) == 0) && (actor->flags & (ACTOR_FLAG_4 | ACTOR_FLAG_UNCULLED))) { - if (actor == player->unk_664) { + if (actor == player->targetedActor) { actor->isTargeted = true; } else { actor->isTargeted = false; } - if ((actor->targetPriority != 0) && (player->unk_664 == NULL)) { + if ((actor->targetPriority != 0) && (player->targetedActor == NULL)) { actor->targetPriority = 0; } @@ -2168,11 +2169,11 @@ void Actor_UpdateAll(GlobalContext* globalCtx, ActorContext* actorCtx) { } } - actor = player->unk_664; + actor = player->targetedActor; if ((actor != NULL) && (actor->update == NULL)) { actor = NULL; - func_8008EDF0(player); + Player_ClearZTarget(player); } if ((actor == NULL) || (player->unk_66C < 5)) { @@ -2887,8 +2888,8 @@ Actor* Actor_Delete(ActorContext* actorCtx, Actor* actor, GlobalContext* globalC osSyncPrintf("Actor class deleted [%s]\n", name); // "Actor class deleted [%s]" } - if ((player != NULL) && (actor == player->unk_664)) { - func_8008EDF0(player); + if ((player != NULL) && (actor == player->targetedActor)) { + Player_ClearZTarget(player); Camera_ChangeMode(Gameplay_GetCamera(globalCtx, Gameplay_GetActiveCamId(globalCtx)), 0); } @@ -2950,7 +2951,7 @@ void func_800328D4(GlobalContext* globalCtx, ActorContext* actorCtx, Player* pla Vec3f sp70; actor = actorCtx->actorLists[actorCategory].head; - sp84 = player->unk_664; + sp84 = player->targetedActor; while (actor != NULL) { if ((actor->update != NULL) && ((Player*)actor != player) && CHECK_FLAG_ALL(actor->flags, ACTOR_FLAG_0)) { diff --git a/src/code/z_camera.cpp b/src/code/z_camera.cpp index cc59da0ef..af66e907d 100644 --- a/src/code/z_camera.cpp +++ b/src/code/z_camera.cpp @@ -13,6 +13,7 @@ #include "quake.h" #include "vt.h" #include "overlays/actors/ovl_En_Horse/z_en_horse.h" +#include "player_state.h" #include "port/player/players.h" #include "port/options.h" #include "def/code_800BB0A0.h" diff --git a/src/code/z_player_lib.cpp b/src/code/z_player_lib.cpp index e803fcfde..7dce083f4 100644 --- a/src/code/z_player_lib.cpp +++ b/src/code/z_player_lib.cpp @@ -6,6 +6,7 @@ #include "z64save.h" #include "z64object.h" #include "z64item.h" +#include "player_state.h" #include "objects/gameplay_keep/gameplay_keep.h" #include "objects/object_link_boy/object_link_boy.h" #include "objects/object_link_child/object_link_child.h" @@ -460,9 +461,9 @@ void Player_UpdateBottleHeld(GlobalContext* globalCtx, Player* pthis, s32 item, pthis->itemActionParam = actionParam; } -void func_8008EDF0(Player* pthis) { - pthis->unk_664 = NULL; - pthis->stateFlags2 &= ~0x2000; +void Player_ClearZTarget(Player* pthis) { + pthis->targetedActor = NULL; + pthis->stateFlags2 &= ~PLAYER_STATE2_ZTARGET_CHANGED; } void func_8008EE08(Player* pthis) { @@ -473,14 +474,14 @@ void func_8008EE08(Player* pthis) { pthis->stateFlags1 |= 0x80000; } - func_8008EDF0(pthis); + Player_ClearZTarget(pthis); } void func_8008EEAC(GlobalContext* globalCtx, Actor* actor) { Player* pthis = GET_PLAYER(globalCtx); func_8008EE08(pthis); - pthis->unk_664 = actor; + pthis->targetedActor = actor; pthis->unk_684 = actor; pthis->stateFlags1 |= 0x10000; Camera_SetParam(Gameplay_GetCamera(globalCtx, 0), 8, actor); diff --git a/src/overlays/actors/ovl_En_Dekunuts/z_en_dekunuts.cpp b/src/overlays/actors/ovl_En_Dekunuts/z_en_dekunuts.cpp index 8f35dc84d..7f509ae9e 100644 --- a/src/overlays/actors/ovl_En_Dekunuts/z_en_dekunuts.cpp +++ b/src/overlays/actors/ovl_En_Dekunuts/z_en_dekunuts.cpp @@ -279,7 +279,7 @@ void EnDekunuts_Wait(EnDekunuts* pthis, GlobalContext* globalCtx) { if (hasSlowPlaybackSpeed && ((pthis->actor.xzDistToPlayer > 160.0f) && (fabsf(pthis->actor.yDistToPlayer) < 120.0f)) && ((pthis->animFlagAndTimer == 0) || (pthis->actor.xzDistToPlayer < 480.0f))) { - pthis->skelAnime.playSpeed = 1.0f; + pthis->skelAnime.playSpeed = 1.0f * FRAMERATE_SCALER; } } @@ -312,6 +312,12 @@ void EnDekunuts_Stand(EnDekunuts* pthis, GlobalContext* globalCtx) { } } +#if FRAME_RATE == 20 +#define DEKU_NUT_SPAWN_SCALER 1.0f +#else +#define DEKU_NUT_SPAWN_SCALER 1.2f +#endif + void EnDekunuts_ThrowNut(EnDekunuts* pthis, GlobalContext* globalCtx) { Vec3f spawnPos; @@ -319,9 +325,9 @@ void EnDekunuts_ThrowNut(EnDekunuts* pthis, GlobalContext* globalCtx) { if (SkelAnime_Update(&pthis->skelAnime)) { EnDekunuts_SetupStand(pthis); } else if (Animation_OnFrame(&pthis->skelAnime, 6.0f)) { - spawnPos.x = pthis->actor.world.pos.x + (Math_SinS(pthis->actor.shape.rot.y) * 23.0f); + spawnPos.x = pthis->actor.world.pos.x + (Math_SinS(pthis->actor.shape.rot.y) * 23.0f * DEKU_NUT_SPAWN_SCALER); spawnPos.y = pthis->actor.world.pos.y + 12.0f; - spawnPos.z = pthis->actor.world.pos.z + (Math_CosS(pthis->actor.shape.rot.y) * 23.0f); + spawnPos.z = pthis->actor.world.pos.z + (Math_CosS(pthis->actor.shape.rot.y) * 23.0f * DEKU_NUT_SPAWN_SCALER); if (Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_NUTSBALL, spawnPos.x, spawnPos.y, spawnPos.z, pthis->actor.shape.rot.x, pthis->actor.shape.rot.y, pthis->actor.shape.rot.z, 0) != NULL) { Audio_PlayActorSound2(&pthis->actor, NA_SE_EN_NUTS_THROW); diff --git a/src/overlays/actors/ovl_En_Dekunuts/z_en_dekunuts.h b/src/overlays/actors/ovl_En_Dekunuts/z_en_dekunuts.h index 99b2d203e..0fca827c3 100644 --- a/src/overlays/actors/ovl_En_Dekunuts/z_en_dekunuts.h +++ b/src/overlays/actors/ovl_En_Dekunuts/z_en_dekunuts.h @@ -15,7 +15,7 @@ struct EnDekunuts { /* 0x014C */ SkelAnime skelAnime; /* 0x0190 */ EnDekunutsActionFunc actionFunc; /* 0x0194 */ u8 playWalkSound; - /* 0x0195 */ u8 runAwayCount; + /* 0x0195 */ Timer runAwayCount; /* 0x0196 */ Timer animFlagAndTimer; /* 0x0198 */ s16 runDirection; /* 0x019A */ s16 shotsPerRound; diff --git a/src/overlays/actors/ovl_En_Elf/z_en_elf.cpp b/src/overlays/actors/ovl_En_Elf/z_en_elf.cpp index c76577aa5..b9c33ff08 100644 --- a/src/overlays/actors/ovl_En_Elf/z_en_elf.cpp +++ b/src/overlays/actors/ovl_En_Elf/z_en_elf.cpp @@ -1057,11 +1057,11 @@ void func_80A04414(EnElf* pthis, GlobalContext* globalCtx) { } if (pthis->fairyFlags & 1) { - if ((arrowPointedActor == NULL) || (player->unk_664 == NULL)) { + if ((arrowPointedActor == NULL) || (player->targetedActor == NULL)) { pthis->fairyFlags ^= 1; } } else { - if ((arrowPointedActor != NULL) && (player->unk_664 != NULL)) { + if ((arrowPointedActor != NULL) && (player->targetedActor != NULL)) { if (arrowPointedActor->category == ACTORCAT_NPC) { targetSound = NA_SE_VO_NAVY_HELLO; } else { @@ -1240,7 +1240,7 @@ void func_80A04DE4(EnElf* pthis, GlobalContext* globalCtx) { if (pthis->fairyFlags & 0x10) { naviRefPos = globalCtx->actorCtx.targetCtx.naviRefPos; - if ((player->unk_664 == NULL) || (&player->actor == player->unk_664) || (&pthis->actor == player->unk_664)) { + if ((player->targetedActor == NULL) || (&player->actor == player->targetedActor) || (&pthis->actor == player->targetedActor)) { naviRefPos.x = player->bodyPartsPos[7].x + (Math_SinS(player->actor.shape.rot.y) * 20.0f); naviRefPos.y = player->bodyPartsPos[7].y + 5.0f; naviRefPos.z = player->bodyPartsPos[7].z + (Math_CosS(player->actor.shape.rot.y) * 20.0f); @@ -1391,7 +1391,7 @@ void func_80A053F0(Actor* thisx, GlobalContext* globalCtx) { EnElf* pthis = (EnElf*)thisx; if (player->naviTextId == 0) { - if (player->unk_664 == NULL) { + if (player->targetedActor == NULL) { if (((gSaveContext.naviTimer >= 600) && (gSaveContext.naviTimer <= 3000)) || (nREG(89) != 0)) { player->naviTextId = ElfMessage_GetCUpText(globalCtx); diff --git a/src/overlays/actors/ovl_En_Ge1/z_en_ge1.cpp b/src/overlays/actors/ovl_En_Ge1/z_en_ge1.cpp index 7ece67733..15d86947d 100644 --- a/src/overlays/actors/ovl_En_Ge1/z_en_ge1.cpp +++ b/src/overlays/actors/ovl_En_Ge1/z_en_ge1.cpp @@ -9,6 +9,7 @@ #include "z_en_ge1.h" #include "vt.h" #include "objects/object_ge1/object_ge1.h" +#include "player_state.h" #include "def/sys_matrix.h" #include "def/z_actor.h" #include "def/z_collision_check.h" diff --git a/src/overlays/actors/ovl_En_In/z_en_in.cpp b/src/overlays/actors/ovl_En_In/z_en_in.cpp index 4e761ed63..761a8462f 100644 --- a/src/overlays/actors/ovl_En_In/z_en_in.cpp +++ b/src/overlays/actors/ovl_En_In/z_en_in.cpp @@ -3,6 +3,7 @@ #include "z_en_in.h" #include "overlays/actors/ovl_En_Horse/z_en_horse.h" #include "objects/object_in/object_in.h" +#include "player_state.h" #include "def/audio.h" #include "def/audio_bank.h" #include "def/random.h" diff --git a/src/overlays/actors/ovl_En_Ma3/z_en_ma3.cpp b/src/overlays/actors/ovl_En_Ma3/z_en_ma3.cpp index 44920830c..11313f6bc 100644 --- a/src/overlays/actors/ovl_En_Ma3/z_en_ma3.cpp +++ b/src/overlays/actors/ovl_En_Ma3/z_en_ma3.cpp @@ -7,6 +7,7 @@ */ #include "z_en_ma3.h" +#include "player_state.h" #include "objects/object_ma2/object_ma2.h" #include "def/audio.h" #include "def/sys_matrix.h" diff --git a/src/overlays/actors/ovl_En_Po_Field/z_en_po_field.cpp b/src/overlays/actors/ovl_En_Po_Field/z_en_po_field.cpp index 03d47fb3e..530ef5abb 100644 --- a/src/overlays/actors/ovl_En_Po_Field/z_en_po_field.cpp +++ b/src/overlays/actors/ovl_En_Po_Field/z_en_po_field.cpp @@ -9,6 +9,7 @@ #include "z_en_po_field.h" #include "objects/gameplay_keep/gameplay_keep.h" #include "objects/object_po_field/object_po_field.h" +#include "player_state.h" #include "def/audio_bank.h" #include "def/random.h" #include "def/sys_matrix.h" diff --git a/src/overlays/actors/ovl_En_Wf/z_en_wf.cpp b/src/overlays/actors/ovl_En_Wf/z_en_wf.cpp index 84d741cc8..ee63da5ad 100644 --- a/src/overlays/actors/ovl_En_Wf/z_en_wf.cpp +++ b/src/overlays/actors/ovl_En_Wf/z_en_wf.cpp @@ -1229,7 +1229,7 @@ void EnWf_Die(EnWf* pthis, GlobalContext* globalCtx) { pthis->actionTimer--; - for (i = ((s32)pthis->skelAnime.animLength - pthis->actionTimer) >> 1; i >= 0; i--) { + for (i = ((s32)(pthis->skelAnime.animLength - pthis->actionTimer)) >> 1; i >= 0; i--) { pos.x = Rand_CenteredFloat(60.0f) + pthis->actor.world.pos.x; pos.z = Rand_CenteredFloat(60.0f) + pthis->actor.world.pos.z; pos.y = Rand_CenteredFloat(50.0f) + (pthis->actor.world.pos.y + 20.0f); diff --git a/src/overlays/actors/ovl_En_Zf/z_en_zf.cpp b/src/overlays/actors/ovl_En_Zf/z_en_zf.cpp index f46f56327..5c11dabe3 100644 --- a/src/overlays/actors/ovl_En_Zf/z_en_zf.cpp +++ b/src/overlays/actors/ovl_En_Zf/z_en_zf.cpp @@ -564,7 +564,7 @@ s32 EnZf_CanAttack(GlobalContext* globalCtx, EnZf* pthis) { return true; } if (pthis->actor.params == ENZF_TYPE_DINOLFOS) { - targetedActor = player->unk_664; + targetedActor = player->targetedActor; if (targetedActor == NULL) { return false; } else { diff --git a/src/overlays/actors/ovl_player_actor/z_player.cpp b/src/overlays/actors/ovl_player_actor/z_player.cpp index 5067b97dc..1874a479e 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.cpp +++ b/src/overlays/actors/ovl_player_actor/z_player.cpp @@ -5,6 +5,7 @@ #include "z_player.h" #include "framerate.h" #include "z_scene_table.h" +#include "player_state.h" #include "hack.h" #include "port/controller/controller.h" #include "port/options.h" @@ -1791,7 +1792,7 @@ s32 func_80833B2C(Player* pthis) { } s32 func_80833B54(Player* pthis) { - if ((pthis->unk_664 != NULL) && CHECK_FLAG_ALL(pthis->unk_664->flags, ACTOR_FLAG_0 | ACTOR_FLAG_2)) { + if ((pthis->targetedActor != NULL) && CHECK_FLAG_ALL(pthis->targetedActor->flags, ACTOR_FLAG_0 | ACTOR_FLAG_2)) { pthis->stateFlags1 |= 0x10; return 1; } @@ -2542,14 +2543,14 @@ s32 func_808359FC(Player* pthis, GlobalContext* globalCtx) { } else if (LinkAnimation_OnFrame(&pthis->skelAnime2, 6.0f)) { f32 posX = (Math_SinS(pthis->actor.shape.rot.y) * 10.0f) + pthis->actor.world.pos.x; f32 posZ = (Math_CosS(pthis->actor.shape.rot.y) * 10.0f) + pthis->actor.world.pos.z; - s32 yaw = (pthis->unk_664 != NULL) ? pthis->actor.shape.rot.y + 14000 : (float)pthis->actor.shape.rot.y; + s32 yaw = (pthis->targetedActor != NULL) ? pthis->actor.shape.rot.y + 14000 : (float)pthis->actor.shape.rot.y; EnBoom* boomerang = (EnBoom*)Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_BOOM, posX, pthis->actor.world.pos.y + 30.0f, posZ, pthis->actor.focus.rot.x, yaw, 0, 0); pthis->boomerangActor = &boomerang->actor; if (boomerang != NULL) { - boomerang->moveTo = pthis->unk_664; + boomerang->moveTo = pthis->targetedActor; boomerang->returnTimer = 20; pthis->stateFlags1 |= 0x2000000; if (!func_8008E9C4(pthis)) { @@ -2968,10 +2969,10 @@ void func_808368EC(Player* pthis, GlobalContext* globalCtx) { s16 previousYaw = pthis->actor.shape.rot.y; if (!(pthis->stateFlags2 & 0x60)) { - if ((pthis->unk_664 != NULL) && + if ((pthis->targetedActor != NULL) && ((globalCtx->actorCtx.targetCtx.unk_4B != 0) || (pthis->actor.category != ACTORCAT_PLAYER))) { Math_ScaledStepToS(&pthis->actor.shape.rot.y, - Math_Vec3f_Yaw(&pthis->actor.world.pos, &pthis->unk_664->focus.pos), 4000); + Math_Vec3f_Yaw(&pthis->actor.world.pos, &pthis->targetedActor->focus.pos), 4000); } else if ((pthis->stateFlags1 & 0x20000) && !(pthis->stateFlags2 & 0x60)) { Math_ScaledStepToS(&pthis->actor.shape.rot.y, pthis->targetYaw, 4000); } @@ -3041,7 +3042,7 @@ void func_80836BEC(Player* pthis, GlobalContext* globalCtx) { if ((globalCtx->csCtx.state != CS_STATE_IDLE) || (pthis->csMode != 0) || (pthis->stateFlags1 & 0x20000080) || (pthis->stateFlags3 & 0x80)) { pthis->unk_66C = 0; - } else if (zTrigPressed || (pthis->stateFlags2 & 0x2000) || (pthis->unk_684 != NULL)) { + } else if (zTrigPressed || (pthis->stateFlags2 & PLAYER_STATE2_ZTARGET_CHANGED) || (pthis->unk_684 != NULL)) { if (pthis->unk_66C <= 5) { pthis->unk_66C = 5; } else { @@ -3074,20 +3075,20 @@ void func_80836BEC(Player* pthis, GlobalContext* globalCtx) { pthis->stateFlags1 |= 0x8000; if ((actorToTarget != NULL) && !(actorToTarget->flags & ACTOR_FLAG_27)) { - if ((actorToTarget == pthis->unk_664) && (pthis->actor.category == ACTORCAT_PLAYER)) { + if ((actorToTarget == pthis->targetedActor) && (pthis->actor.category == ACTORCAT_PLAYER)) { actorToTarget = globalCtx->actorCtx.targetCtx.unk_94; } - if (actorToTarget != pthis->unk_664) { + if (actorToTarget != pthis->targetedActor) { if (!holdTarget) { - pthis->stateFlags2 |= 0x2000; + pthis->stateFlags2 |= PLAYER_STATE2_ZTARGET_CHANGED; } - pthis->unk_664 = actorToTarget; + pthis->targetedActor = actorToTarget; pthis->unk_66C = 15; pthis->stateFlags2 &= ~0x200002; } else { if (!holdTarget) { - func_8008EDF0(pthis); + Player_ClearZTarget(pthis); } } @@ -3099,27 +3100,27 @@ void func_80836BEC(Player* pthis, GlobalContext* globalCtx) { } } - if (pthis->unk_664 != NULL) { - if ((pthis->actor.category == ACTORCAT_PLAYER) && (pthis->unk_664 != pthis->unk_684) && - func_8002F0C8(pthis->unk_664, pthis, sp1C)) { - func_8008EDF0(pthis); + if (pthis->targetedActor != NULL) { + if ((pthis->actor.category == ACTORCAT_PLAYER) && (pthis->targetedActor != pthis->unk_684) && + func_8002F0C8(pthis->targetedActor, pthis, sp1C)) { + Player_ClearZTarget(pthis); pthis->stateFlags1 |= 0x40000000; - } else if (pthis->unk_664 != NULL) { - pthis->unk_664->targetPriority = 40; + } else if (pthis->targetedActor != NULL) { + pthis->targetedActor->targetPriority = 40; } } else if (pthis->unk_684 != NULL) { - pthis->unk_664 = pthis->unk_684; + pthis->targetedActor = pthis->unk_684; } } - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { pthis->stateFlags1 &= ~0x30000; - if ((pthis->stateFlags1 & 0x800) || !CHECK_FLAG_ALL(pthis->unk_664->flags, ACTOR_FLAG_0 | ACTOR_FLAG_2)) { + if ((pthis->stateFlags1 & 0x800) || !CHECK_FLAG_ALL(pthis->targetedActor->flags, ACTOR_FLAG_0 | ACTOR_FLAG_2)) { pthis->stateFlags1 |= 0x10000; } } else { if (pthis->stateFlags1 & 0x20000) { - pthis->stateFlags2 &= ~0x2000; + pthis->stateFlags2 &= ~PLAYER_STATE2_ZTARGET_CHANGED; } else { func_8008EE08(pthis); } @@ -3184,9 +3185,9 @@ s32 func_80837268(Player* pthis, f32* arg1, s16* arg2, f32 arg3, GlobalContext* if (!func_80836FAC(globalCtx, pthis, arg1, arg2, arg3)) { *arg2 = pthis->actor.shape.rot.y; - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { if ((globalCtx->actorCtx.targetCtx.unk_4B != 0) && !(pthis->stateFlags2 & 0x40)) { - *arg2 = Math_Vec3f_Yaw(&pthis->actor.world.pos, &pthis->unk_664->focus.pos); + *arg2 = Math_Vec3f_Yaw(&pthis->actor.world.pos, &pthis->targetedActor->focus.pos); return 0; } } else if (func_80833B2C(pthis)) { @@ -4451,7 +4452,7 @@ void func_8083A2F8(GlobalContext* globalCtx, Player* pthis) { if (pthis->actor.textId != 0) { Message_StartTextbox(globalCtx, pthis->actor.textId, pthis->targetActor); - pthis->unk_664 = pthis->targetActor; + pthis->targetedActor = pthis->targetActor; } } @@ -4824,7 +4825,7 @@ s32 func_8083B040(Player* pthis, GlobalContext* globalCtx) { pthis->unk_84F = -1; } targetActor->flags |= ACTOR_FLAG_8; - pthis->unk_664 = pthis->targetActor; + pthis->targetedActor = pthis->targetActor; } else if (sp2C == EXCH_ITEM_LETTER_RUTO) { pthis->unk_84F = 1; pthis->actor.textId = 0x4005; @@ -4902,7 +4903,7 @@ s32 func_8083B040(Player* pthis, GlobalContext* globalCtx) { s32 func_8083B644(Player* pthis, GlobalContext* globalCtx) { Actor* sp34 = pthis->targetActor; - Actor* sp30 = pthis->unk_664; + Actor* sp30 = pthis->targetedActor; Actor* sp2C = NULL; s32 sp28 = 0; s32 sp24; @@ -4993,8 +4994,8 @@ s32 func_8083B998(Player* pthis, GlobalContext* globalCtx) { return 1; } - if ((pthis->unk_664 != NULL) && - (CHECK_FLAG_ALL(pthis->unk_664->flags, ACTOR_FLAG_0 | ACTOR_FLAG_18) || (pthis->unk_664->naviEnemyId != 0xFF))) { + if ((pthis->targetedActor != NULL) && + (CHECK_FLAG_ALL(pthis->targetedActor->flags, ACTOR_FLAG_0 | ACTOR_FLAG_18) || (pthis->targetedActor->naviEnemyId != 0xFF))) { pthis->stateFlags2 |= 0x200000; } else if ((pthis->naviTextId == 0) && !func_8008E9C4(pthis) && CHECK_BTN_ALL(sControlInput->press.button, BTN_CUP) && (YREG(15) != 0x10) && (YREG(15) != 0x20) && !func_8083B8F4(pthis, globalCtx)) { @@ -5184,7 +5185,7 @@ s32 func_8083C2B0(Player* pthis, GlobalContext* globalCtx) { if ((globalCtx->shootingGalleryStatus == 0) && (pthis->currentShield != PLAYER_SHIELD_NONE) && CHECK_BTN_ALL(sControlInput->cur.button, BTN_R) && - (Player_IsChildWithHylianShield(pthis) || (!func_80833B2C(pthis) && (pthis->unk_664 == NULL)))) { + (Player_IsChildWithHylianShield(pthis) || (!func_80833B2C(pthis) && (pthis->targetedActor == NULL)))) { func_80832318(pthis); func_808323B4(globalCtx, pthis); @@ -5725,7 +5726,7 @@ void func_8083D6EC(GlobalContext* globalCtx, Player* pthis) { } s32 func_8083DB98(Player* pthis, s32 arg1) { - Actor* unk_664 = pthis->unk_664; + Actor* unk_664 = pthis->targetedActor; Vec3f sp30; s16 sp2E; s16 sp2C; @@ -5750,7 +5751,7 @@ void func_8083DC54(Player* pthis, GlobalContext* globalCtx) { f32 temp1; Vec3f sp34; - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { if (func_8002DD78(pthis) || func_808334B4(pthis)) { func_8083DB98(pthis, 1); } else { @@ -6462,7 +6463,7 @@ s32 func_8083FC68(Player* pthis, f32 arg1, s16 arg2) { f32 sp1C = (s16)(arg2 - pthis->actor.shape.rot.y); f32 temp; - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { func_8083DB98(pthis, func_8002DD78(pthis) || func_808334B4(pthis)); } @@ -6481,7 +6482,7 @@ s32 func_8083FD78(Player* pthis, f32* arg1, s16* arg2, GlobalContext* globalCtx) s16 sp2E = *arg2 - pthis->targetYaw; u16 sp2C = ABS(sp2E); - if ((func_8002DD78(pthis) || func_808334B4(pthis)) && (pthis->unk_664 == NULL)) { + if ((func_8002DD78(pthis) || func_808334B4(pthis)) && (pthis->targetedActor == NULL)) { *arg1 *= Math_SinS(sp2C); if (*arg1 != 0.0f) { @@ -6490,14 +6491,14 @@ s32 func_8083FD78(Player* pthis, f32* arg1, s16* arg2, GlobalContext* globalCtx) *arg2 = pthis->actor.shape.rot.y; } - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { func_8083DB98(pthis, 1); } else { Math_SmoothStepToS(&pthis->actor.focus.rot.x, sControlInput->rel.stick_y * 240.0f, 14, 4000, 30); func_80836AB8(pthis, 1); } } else { - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { return func_8083FC68(pthis, *arg1, *arg2); } else { func_8083DC54(pthis, globalCtx); @@ -6765,7 +6766,7 @@ void func_808409CC(GlobalContext* globalCtx, Player* pthis) { s32 sp38; s32 sp34; - if ((pthis->unk_664 != NULL) || + if ((pthis->targetedActor != NULL) || (!(heathIsCritical = HealthMeter_IsCritical()) && ((pthis->unk_6AC = (pthis->unk_6AC + 1) & 1) != 0))) { pthis->stateFlags2 &= ~0x10000000; anim = func_80833338(pthis); @@ -9385,7 +9386,7 @@ void func_808473D4(GlobalContext* globalCtx, Player* pthis) { Interface_SetDoAction(globalCtx, doAction); if (pthis->stateFlags2 & 0x200000) { - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { Interface_SetNaviCall(globalCtx, 0x1E); } else { Interface_SetNaviCall(globalCtx, 0x1D); @@ -9707,7 +9708,7 @@ void Player_UpdateCamAndSeqModes(GlobalContext* globalCtx, Player* pthis) { camMode = CAM_MODE_STILL; } else if (pthis->stateFlags2 & 0x100) { camMode = CAM_MODE_PUSHPULL; - } else if ((unk_664 = pthis->unk_664) != NULL) { + } else if ((unk_664 = pthis->targetedActor) != NULL) { if (CHECK_FLAG_ALL(pthis->actor.flags, ACTOR_FLAG_8)) { camMode = CAM_MODE_TALK; } else if (pthis->stateFlags1 & 0x10000) { @@ -10194,7 +10195,7 @@ void Player_UpdateCommon(Player* pthis, GlobalContext* globalCtx, Input* input) func_8083D6EC(globalCtx, pthis); - if ((pthis->unk_664 == NULL) && (pthis->naviTextId == 0)) { + if ((pthis->targetedActor == NULL) && (pthis->naviTextId == 0)) { pthis->stateFlags2 &= ~0x200002; } @@ -10706,7 +10707,7 @@ void func_8084B1D8(Player* pthis, GlobalContext* globalCtx) { } if ((pthis->csMode != 0) || (pthis->unk_6AD == 0) || (pthis->unk_6AD >= 4) || func_80833B54(pthis) || - (pthis->unk_664 != NULL) || !func_8083AD4C(globalCtx, pthis) || + (pthis->targetedActor != NULL) || !func_8083AD4C(globalCtx, pthis) || (((pthis->unk_6AD == 2) && (CHECK_BTN_ANY(sControlInput->press.button, BTN_A | BTN_B | BTN_R) || func_80833B2C(pthis) || (!func_8002DD78(pthis) && !func_808334B4(pthis)))) || ((pthis->unk_6AD == 1) && @@ -10770,7 +10771,7 @@ void func_8084B530(Player* pthis, GlobalContext* globalCtx) { pthis->actor.flags &= ~ACTOR_FLAG_8; if (!CHECK_FLAG_ALL(pthis->targetActor->flags, ACTOR_FLAG_0 | ACTOR_FLAG_2)) { - pthis->stateFlags2 &= ~0x2000; + pthis->stateFlags2 &= ~PLAYER_STATE2_ZTARGET_CHANGED; } func_8005B1A4(Gameplay_GetCamera(globalCtx, 0)); @@ -10811,7 +10812,7 @@ void func_8084B530(Player* pthis, GlobalContext* globalCtx) { } } - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { pthis->currentYaw = pthis->actor.shape.rot.y = func_8083DB98(pthis, 0); } } @@ -11547,7 +11548,7 @@ void func_8084CC98(Player* pthis, GlobalContext* globalCtx) { } if ((pthis->csMode != 0) || (!func_8084C9BC(pthis, globalCtx) && !func_8083B040(pthis, globalCtx))) { - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { if (func_8002DD78(pthis) != 0) { pthis->unk_6BE = func_8083DB98(pthis, 1) - pthis->actor.shape.rot.y; pthis->unk_6BE = CLAMP(pthis->unk_6BE, -0x4AAA, 0x4AAA); @@ -12361,7 +12362,7 @@ void func_8084F104(Player* pthis, GlobalContext* globalCtx) { func_80832924(pthis, D_80854A3C); } - if ((pthis->unk_84F == 0) && (pthis->unk_664 != NULL)) { + if ((pthis->unk_84F == 0) && (pthis->targetedActor != NULL)) { pthis->currentYaw = pthis->actor.shape.rot.y = func_8083DB98(pthis, 0); } } @@ -13389,9 +13390,9 @@ void func_80851314(Player* pthis) { pthis->unk_448 = NULL; } - pthis->unk_664 = pthis->unk_448; + pthis->targetedActor = pthis->unk_448; - if (pthis->unk_664 != NULL) { + if (pthis->targetedActor != NULL) { pthis->actor.shape.rot.y = func_8083DB98(pthis, 0); } } diff --git a/src/overlays/actors/ovl_player_actor/z_player.h b/src/overlays/actors/ovl_player_actor/z_player.h index fbe04d476..3e4aa71ee 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.h +++ b/src/overlays/actors/ovl_player_actor/z_player.h @@ -178,7 +178,7 @@ struct Player { /* 0x0498 */ ColliderCylinder cylinder; /* 0x04E4 */ ColliderQuad swordQuads[2]; /* 0x05E4 */ ColliderQuad shieldQuad; - /* 0x0664 */ Actor* unk_664; + /* 0x0664 */ Actor* targetedActor; /* 0x0668 */ char unk_668[0x004]; /* 0x066C */ s32 unk_66C; /* 0x0670 */ s32 swordEffectIndex;