Skip to content

Commit

Permalink
Convert BowReticle to ShipInit
Browse files Browse the repository at this point in the history
  • Loading branch information
Archez committed Jan 1, 2025
1 parent 2c79f92 commit a6960d9
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions mm/2s2h/Enhancements/Graphics/BowReticle.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#include "libultraship/libultraship.h"
#include "2s2h/GameInteractor/GameInteractor.h"
#include "2s2h/Enhancements/FrameInterpolation/FrameInterpolation.h"
#include "2s2h/ShipInit.hpp"

extern "C" {
#include "functions.h"
#include "variables.h"
#include "objects/gameplay_keep/gameplay_keep.h"
}

#define CVAR_NAME "gEnhancements.Graphics.BowReticle"
#define CVAR CVarGetInteger(CVAR_NAME, 0)

void DrawBowReticle(PlayState* play, Player* player, f32 bowDistance) {
static Vec3f D_801C094C = { -500.0f, -100.0f, 0.0f };
CollisionPoly* poly;
Expand Down Expand Up @@ -50,22 +54,22 @@ void DrawBowReticle(PlayState* play, Player* player, f32 bowDistance) {
}

void RegisterBowReticle() {
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::OnPlayerPostLimbDraw>(
PLAYER_LIMB_RIGHT_HAND, [](Player* player, s32 limbIndex) {
if (player->actor.scale.y >= 0.0f &&
((player->heldItemAction == PLAYER_IA_BOW_FIRE) || (player->heldItemAction == PLAYER_IA_BOW_ICE) ||
(player->heldItemAction == PLAYER_IA_BOW_LIGHT) || (player->heldItemAction == PLAYER_IA_BOW)) &&
CVarGetInteger("gEnhancements.Graphics.BowReticle", 0)) {

if (func_800B7128(player) != 0) {
// Rotation from link's right hand that aligns with arrow projection
Matrix_RotateZYX(0, -0x3B33, -0x4423, MTXMODE_APPLY);
Matrix_Translate(575.0f, 345.0f, 0.0f, MTXMODE_APPLY);

// 341000 as a value is selected roughly as a ratio of the hookshot value to maximum hookshot
// distance from player, multiplied by maximum arrow distance from player -- (77600 / 770) * 3385
DrawBowReticle(gPlayState, player, 341000.0f);
}
COND_ID_HOOK(OnPlayerPostLimbDraw, PLAYER_LIMB_RIGHT_HAND, CVAR, [](Player* player, s32 limbIndex) {
if (player->actor.scale.y >= 0.0f &&
((player->heldItemAction == PLAYER_IA_BOW_FIRE) || (player->heldItemAction == PLAYER_IA_BOW_ICE) ||
(player->heldItemAction == PLAYER_IA_BOW_LIGHT) || (player->heldItemAction == PLAYER_IA_BOW))) {

if (func_800B7128(player) != 0) {
// Rotation from link's right hand that aligns with arrow projection
Matrix_RotateZYX(0, -0x3B33, -0x4423, MTXMODE_APPLY);
Matrix_Translate(575.0f, 345.0f, 0.0f, MTXMODE_APPLY);

// 341000 as a value is selected roughly as a ratio of the hookshot value to maximum hookshot
// distance from player, multiplied by maximum arrow distance from player -- (77600 / 770) * 3385
DrawBowReticle(gPlayState, player, 341000.0f);
}
});
}
});
}

static RegisterShipInitFunc initFunc(RegisterBowReticle, { CVAR_NAME });

0 comments on commit a6960d9

Please sign in to comment.