diff --git a/include/functions.h b/include/functions.h index 07a2201601..92f7ae87c1 100644 --- a/include/functions.h +++ b/include/functions.h @@ -310,7 +310,7 @@ void ActorShadow_DrawFeet(Actor* actor, Lights* lights, PlayState* play); void Actor_SetFeetPos(Actor* actor, s32 limbIndex, s32 leftFootIndex, Vec3f* leftFootPos, s32 rightFootIndex, Vec3f* rightFootPos); void Actor_ProjectPos(PlayState* play, Vec3f* src, Vec3f* xyzDest, f32* cappedInvWDest); -void func_8002C124(TargetContext* targetCtx, PlayState* play); +void Target_Draw(TargetContext* targetCtx, PlayState* play); s32 Flags_GetSwitch(PlayState* play, s32 flag); void Flags_SetSwitch(PlayState* play, s32 flag); void Flags_UnsetSwitch(PlayState* play, s32 flag); diff --git a/include/z64actor.h b/include/z64actor.h index 61e10293b6..4a6185d6d5 100644 --- a/include/z64actor.h +++ b/include/z64actor.h @@ -580,22 +580,22 @@ typedef struct LockOnReticle { typedef struct TargetContext { /* 0x00 */ Vec3f naviRefPos; // possibly wrong - /* 0x0C */ Vec3f targetCenterPos; + /* 0x0C */ Vec3f lockOnPos; /* 0x18 */ Color_RGBAf naviInner; /* 0x28 */ Color_RGBAf naviOuter; /* 0x38 */ Actor* arrowPointedActor; - /* 0x3C */ Actor* targetedActor; + /* 0x3C */ Actor* lockOnActor; /* 0x40 */ f32 unk_40; /* 0x44 */ f32 reticleRadius; - /* 0x48 */ s16 unk_48; + /* 0x48 */ s16 reticleFadeAlphaControl; /* 0x4A */ u8 activeCategory; - /* 0x4B */ u8 unk_4B; - /* 0x4C */ s8 unk_4C; + /* 0x4B */ u8 reticleSpinCounter; + /* 0x4C */ s8 curReticle; // indexes lockOnReticles[] /* 0x4D */ char unk_4D[0x03]; /* 0x50 */ LockOnReticle lockOnReticles[3]; /* 0x8C */ Actor* unk_8C; /* 0x90 */ Actor* bgmEnemy; // The nearest enemy to player with the right flags that will trigger NA_BGM_ENEMY - /* 0x94 */ Actor* unk_94; + /* 0x94 */ Actor* arrowHoverActor; } TargetContext; // size = 0x98 typedef struct TitleCardContext { diff --git a/src/code/z_actor.c b/src/code/z_actor.c index ff44339c25..d0b81e49a0 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -275,10 +275,10 @@ void Target_InitReticle(TargetContext* targetCtx, s32 actorCategory, PlayState* TargetColor* reticleColor = &sTargetColorList[actorCategory]; s32 i; - Math_Vec3f_Copy(&targetCtx->targetCenterPos, &play->view.eye); + Math_Vec3f_Copy(&targetCtx->lockOnPos, &play->view.eye); targetCtx->reticleRadius = 500.0f; - targetCtx->unk_48 = 256; + targetCtx->reticleFadeAlphaControl = 256; reticle = &targetCtx->lockOnReticles[0]; @@ -310,97 +310,107 @@ void Target_SetNaviState(TargetContext* targetCtx, Actor* actor, s32 actorCatego } void Target_Init(TargetContext* targetCtx, Actor* actor, PlayState* play) { - targetCtx->arrowPointedActor = targetCtx->targetedActor = targetCtx->unk_8C = targetCtx->bgmEnemy = NULL; + targetCtx->arrowPointedActor = targetCtx->lockOnActor = targetCtx->unk_8C = targetCtx->bgmEnemy = NULL; - targetCtx->unk_4B = 0; - targetCtx->unk_4C = 0; + targetCtx->reticleSpinCounter = 0; + targetCtx->curReticle = 0; targetCtx->unk_40 = 0.0f; Target_SetNaviState(targetCtx, actor, actor->category, play); Target_InitReticle(targetCtx, actor->category, play); } -void func_8002C124(TargetContext* targetCtx, PlayState* play) { - Actor* actor = targetCtx->targetedActor; +void Target_Draw(TargetContext* targetCtx, PlayState* play) { + Actor* actor = targetCtx->lockOnActor; OPEN_DISPS(play->state.gfxCtx, "../z_actor.c", 2029); - if (targetCtx->unk_48 != 0) { - LockOnReticle* entry; - Player* player; - s16 spCE; - f32 var1; - Vec3f projTargetCenter; - s32 spB8; - f32 projTargetCappedInvW; - s32 spB0; - s32 spAC; - f32 var2; + if (targetCtx->reticleFadeAlphaControl != 0) { + LockOnReticle* reticle; + Player* player = GET_PLAYER(play); + s16 alpha; + f32 projectdPosScale; + Vec3f projectedPos; + s32 numReticles; + f32 invW; s32 i; + s32 curReticle; + f32 lockOnScaleX; + s32 triangleIndex; - player = GET_PLAYER(play); + alpha = 255; + projectdPosScale = 1.0f; - spCE = 0xFF; - var1 = 1.0f; - - if (targetCtx->unk_4B != 0) { - spB8 = 1; + if (targetCtx->reticleSpinCounter != 0) { + // Reticle is spinning so it is active, only need to draw one + numReticles = 1; } else { - spB8 = 3; + // Use multiple reticles for the motion blur effect from the reticle + // quickly zooming in on an actor from off screen + numReticles = ARRAY_COUNT(targetCtx->lockOnReticles); } if (actor != NULL) { - Math_Vec3f_Copy(&targetCtx->targetCenterPos, &actor->focus.pos); - var1 = (500.0f - targetCtx->reticleRadius) / 420.0f; + Math_Vec3f_Copy(&targetCtx->lockOnPos, &actor->focus.pos); + projectdPosScale = (500.0f - targetCtx->reticleRadius) / 420.0f; } else { - targetCtx->unk_48 -= 120; - if (targetCtx->unk_48 < 0) { - targetCtx->unk_48 = 0; + // Not locked on, start fading out + targetCtx->reticleFadeAlphaControl -= 120; + + if (targetCtx->reticleFadeAlphaControl < 0) { + targetCtx->reticleFadeAlphaControl = 0; } - spCE = targetCtx->unk_48; + + // `reticleFadeAlphaControl` is only used as an alpha when fading out. + // Otherwise it defaults to 255, set above. + alpha = targetCtx->reticleFadeAlphaControl; } - Actor_ProjectPos(play, &targetCtx->targetCenterPos, &projTargetCenter, &projTargetCappedInvW); + Actor_ProjectPos(play, &targetCtx->lockOnPos, &projectedPos, &invW); - projTargetCenter.x = (160 * (projTargetCenter.x * projTargetCappedInvW)) * var1; - projTargetCenter.x = CLAMP(projTargetCenter.x, -320.0f, 320.0f); + projectedPos.x = ((SCREEN_WIDTH / 2) * (projectedPos.x * invW)) * projectdPosScale; + projectedPos.x = CLAMP(projectedPos.x, -SCREEN_WIDTH, SCREEN_WIDTH); - projTargetCenter.y = (120 * (projTargetCenter.y * projTargetCappedInvW)) * var1; - projTargetCenter.y = CLAMP(projTargetCenter.y, -240.0f, 240.0f); + projectedPos.y = ((SCREEN_HEIGHT / 2) * (projectedPos.y * invW)) * projectdPosScale; + projectedPos.y = CLAMP(projectedPos.y, -SCREEN_HEIGHT, SCREEN_HEIGHT); - projTargetCenter.z = projTargetCenter.z * var1; + projectedPos.z *= projectdPosScale; - targetCtx->unk_4C--; - if (targetCtx->unk_4C < 0) { - targetCtx->unk_4C = 2; + targetCtx->curReticle--; + + if (targetCtx->curReticle < 0) { + targetCtx->curReticle = ARRAY_COUNT(targetCtx->lockOnReticles) - 1; } - Target_SetReticlePos(targetCtx, targetCtx->unk_4C, projTargetCenter.x, projTargetCenter.y, projTargetCenter.z); + Target_SetReticlePos(targetCtx, targetCtx->curReticle, projectedPos.x, projectedPos.y, projectedPos.z); if (!(player->stateFlags1 & PLAYER_STATE1_6) || (actor != player->unk_664)) { OVERLAY_DISP = Gfx_SetupDL(OVERLAY_DISP, SETUPDL_57); - for (spB0 = 0, spAC = targetCtx->unk_4C; spB0 < spB8; spB0++, spAC = (spAC + 1) % 3) { - entry = &targetCtx->lockOnReticles[spAC]; + for (i = 0, curReticle = targetCtx->curReticle; i < numReticles; + i++, curReticle = (curReticle + 1) % ARRAY_COUNT(targetCtx->lockOnReticles)) { + reticle = &targetCtx->lockOnReticles[curReticle]; - if (entry->radius < 500.0f) { - if (entry->radius <= 120.0f) { - var2 = 0.15f; + if (reticle->radius < 500.0f) { + if (reticle->radius <= 120.0f) { + lockOnScaleX = 0.15f; } else { - var2 = ((entry->radius - 120.0f) * 0.001f) + 0.15f; + lockOnScaleX = ((reticle->radius - 120.0f) * 0.001f) + 0.15f; } - Matrix_Translate(entry->pos.x, entry->pos.y, 0.0f, MTXMODE_NEW); - Matrix_Scale(var2, 0.15f, 1.0f, MTXMODE_APPLY); + Matrix_Translate(reticle->pos.x, reticle->pos.y, 0.0f, MTXMODE_NEW); + Matrix_Scale(lockOnScaleX, 0.15f, 1.0f, MTXMODE_APPLY); - gDPSetPrimColor(OVERLAY_DISP++, 0, 0, entry->color.r, entry->color.g, entry->color.b, (u8)spCE); + gDPSetPrimColor(OVERLAY_DISP++, 0, 0, reticle->color.r, reticle->color.g, reticle->color.b, + (u8)alpha); - Matrix_RotateZ((targetCtx->unk_4B & 0x7F) * (M_PI / 64), MTXMODE_APPLY); + Matrix_RotateZ((targetCtx->reticleSpinCounter & 0x7F) * (M_PI / 64), MTXMODE_APPLY); - for (i = 0; i < 4; i++) { + // Draw the 4 triangles that make up the reticle + for (triangleIndex = 0; triangleIndex < 4; triangleIndex++) { Matrix_RotateZ(M_PI / 2, MTXMODE_APPLY); Matrix_Push(); - Matrix_Translate(entry->radius, entry->radius, 0.0f, MTXMODE_APPLY); + Matrix_Translate(reticle->radius, reticle->radius, 0.0f, MTXMODE_APPLY); gSPMatrix(OVERLAY_DISP++, MATRIX_NEW(play->state.gfxCtx, "../z_actor.c", 2116), G_MTX_MODELVIEW | G_MTX_LOAD); gSPDisplayList(OVERLAY_DISP++, gZTargetLockOnTriangleDL); @@ -408,17 +418,19 @@ void func_8002C124(TargetContext* targetCtx, PlayState* play) { } } - spCE -= 0xFF / 3; - if (spCE < 0) { - spCE = 0; + alpha -= 255 / ARRAY_COUNT(targetCtx->lockOnReticles); + + if (alpha < 0) { + alpha = 0; } } } } - actor = targetCtx->unk_94; + actor = targetCtx->arrowHoverActor; + if ((actor != NULL) && !(actor->flags & ACTOR_FLAG_27)) { - TargetColor* naviColor = &sTargetColorList[actor->category]; + TargetColor* arrowColor = &sTargetColorList[actor->category]; POLY_XLU_DISP = Gfx_SetupDL(POLY_XLU_DISP, SETUPDL_7); @@ -427,7 +439,7 @@ void func_8002C124(TargetContext* targetCtx, PlayState* play) { Matrix_RotateY(BINANG_TO_RAD((u16)(play->gameplayFrames * 3000)), MTXMODE_APPLY); Matrix_Scale((iREG(27) + 35) / 1000.0f, (iREG(28) + 60) / 1000.0f, (iREG(29) + 50) / 1000.0f, MTXMODE_APPLY); - gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, naviColor->inner.r, naviColor->inner.g, naviColor->inner.b, 255); + gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, arrowColor->inner.r, arrowColor->inner.g, arrowColor->inner.b, 255); gSPMatrix(POLY_XLU_DISP++, MATRIX_NEW(play->state.gfxCtx, "../z_actor.c", 2153), G_MTX_MODELVIEW | G_MTX_LOAD); gSPDisplayList(POLY_XLU_DISP++, gZTargetArrowDL); } @@ -446,10 +458,10 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Pl if ((player->unk_664 != NULL) && (player->controlStickDirections[player->controlStickDataIndex] == PLAYER_STICK_DIR_BACKWARD)) { - targetCtx->unk_94 = NULL; + targetCtx->arrowHoverActor = NULL; } else { func_80032AF0(play, &play->actorCtx, &unkActor, player); - targetCtx->unk_94 = unkActor; + targetCtx->arrowHoverActor = unkActor; } if (targetCtx->unk_8C != NULL) { @@ -489,7 +501,7 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Pl Target_SetNaviState(targetCtx, unkActor, actorCategory, play); } - if ((actorArg != NULL) && (targetCtx->unk_4B == 0)) { + if ((actorArg != NULL) && (targetCtx->reticleSpinCounter == 0)) { Actor_ProjectPos(play, &actorArg->focus.pos, &projectedFocusPos, &cappedInvWDest); if (((projectedFocusPos.z <= 0.0f) || (1.0f <= fabsf(projectedFocusPos.x * cappedInvWDest))) || (1.0f <= fabsf(projectedFocusPos.y * cappedInvWDest))) { @@ -498,14 +510,14 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Pl } if (actorArg != NULL) { - if (actorArg != targetCtx->targetedActor) { + if (actorArg != targetCtx->lockOnActor) { s32 lockOnSfxId; Target_InitReticle(targetCtx, actorArg->category, play); - targetCtx->targetedActor = actorArg; + targetCtx->lockOnActor = actorArg; if (actorArg->id == ACTOR_EN_BOOM) { - targetCtx->unk_48 = 0; + targetCtx->reticleFadeAlphaControl = 0; } lockOnSfxId = CHECK_FLAG_ALL(actorArg->flags, ACTOR_FLAG_0 | ACTOR_FLAG_2) ? NA_SE_SY_LOCK_ON @@ -513,23 +525,23 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Pl Sfx_PlaySfxCentered(lockOnSfxId); } - targetCtx->targetCenterPos.x = actorArg->world.pos.x; - targetCtx->targetCenterPos.y = actorArg->world.pos.y - (actorArg->shape.yOffset * actorArg->scale.y); - targetCtx->targetCenterPos.z = actorArg->world.pos.z; + targetCtx->lockOnPos.x = actorArg->world.pos.x; + targetCtx->lockOnPos.y = actorArg->world.pos.y - (actorArg->shape.yOffset * actorArg->scale.y); + targetCtx->lockOnPos.z = actorArg->world.pos.z; - if (targetCtx->unk_4B == 0) { + if (targetCtx->reticleSpinCounter == 0) { f32 temp5 = (500.0f - targetCtx->reticleRadius) * 3.0f; f32 temp6 = (temp5 < 30.0f) ? 30.0f : ((100.0f < temp5) ? 100.0f : temp5); if (Math_StepToF(&targetCtx->reticleRadius, 80.0f, temp6) != 0) { - targetCtx->unk_4B++; + targetCtx->reticleSpinCounter++; } } else { - targetCtx->unk_4B = (targetCtx->unk_4B + 3) | 0x80; + targetCtx->reticleSpinCounter = (targetCtx->reticleSpinCounter + 3) | 0x80; targetCtx->reticleRadius = 120.0f; } } else { - targetCtx->targetedActor = NULL; + targetCtx->lockOnActor = NULL; Math_StepToF(&targetCtx->reticleRadius, 500.0f, 80.0f); } } @@ -2313,8 +2325,8 @@ void Actor_UpdateAll(PlayState* play, ActorContext* actorCtx) { if ((actor == NULL) || (player->unk_66C < 5)) { actor = NULL; - if (actorCtx->targetCtx.unk_4B != 0) { - actorCtx->targetCtx.unk_4B = 0; + if (actorCtx->targetCtx.reticleSpinCounter != 0) { + actorCtx->targetCtx.reticleSpinCounter = 0; Sfx_PlaySfxCentered(NA_SE_SY_LOCK_OFF); } } diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index d4c9825a74..40060d0006 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -3272,7 +3272,7 @@ void Interface_Draw(PlayState* play) { if ((R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_PROCESS) && (R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_READY)) { - func_8002C124(&play->actorCtx.targetCtx, play); // Draw Z-Target + Target_Draw(&play->actorCtx.targetCtx, play); } Gfx_SetupDL_39Overlay(play->state.gfxCtx); diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 1454258048..bb16ecfdfb 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -3480,7 +3480,7 @@ void Player_UpdateShapeYaw(Player* this, PlayState* play) { Actor* unk_664 = this->unk_664; if ((unk_664 != NULL) && - ((play->actorCtx.targetCtx.unk_4B != 0) || (this->actor.category != ACTORCAT_PLAYER))) { + ((play->actorCtx.targetCtx.reticleSpinCounter != 0) || (this->actor.category != ACTORCAT_PLAYER))) { Math_ScaledStepToS(&this->actor.shape.rot.y, Math_Vec3f_Yaw(&this->actor.world.pos, &unk_664->focus.pos), 4000); } else if ((this->stateFlags1 & PLAYER_STATE1_17) && @@ -3588,7 +3588,7 @@ void func_80836BEC(Player* this, PlayState* play) { if ((actorToTarget != NULL) && !(actorToTarget->flags & ACTOR_FLAG_27)) { if ((actorToTarget == this->unk_664) && (this->actor.category == ACTORCAT_PLAYER)) { - actorToTarget = play->actorCtx.targetCtx.unk_94; + actorToTarget = play->actorCtx.targetCtx.arrowHoverActor; } if (actorToTarget != this->unk_664) { @@ -3749,7 +3749,7 @@ s32 Player_GetMovementSpeedAndYaw(Player* this, f32* outSpeedTarget, s16* outYaw *outYawTarget = this->actor.shape.rot.y; if (this->unk_664 != NULL) { - if ((play->actorCtx.targetCtx.unk_4B != 0) && !(this->stateFlags2 & PLAYER_STATE2_6)) { + if ((play->actorCtx.targetCtx.reticleSpinCounter != 0) && !(this->stateFlags2 & PLAYER_STATE2_6)) { *outYawTarget = Math_Vec3f_Yaw(&this->actor.world.pos, &this->unk_664->focus.pos); return false; } diff --git a/tools/disasm/ntsc-1.2/functions.txt b/tools/disasm/ntsc-1.2/functions.txt index c42a988f8a..eebbd66281 100644 --- a/tools/disasm/ntsc-1.2/functions.txt +++ b/tools/disasm/ntsc-1.2/functions.txt @@ -323,7 +323,7 @@ Target_SetReticlePos = 0x8001FE44; // type:func Target_InitReticle = 0x8001FE7C; // type:func Target_SetNaviState = 0x8001FF44; // type:func Target_Init = 0x800200A8; // type:func -func_8002C124 = 0x8002010C; // type:func +Target_Draw = 0x8002010C; // type:func func_8002C7BC = 0x80020748; // type:func Flags_GetSwitch = 0x80020ADC; // type:func Flags_SetSwitch = 0x80020B10; // type:func