Skip to content

Commit

Permalink
RemoteBombchu enhancement, steering math needs some work
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox committed Jan 29, 2025
1 parent 26012da commit 1b379e5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mm/2s2h/BenGui/BenMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,10 @@ void BenMenu::AddEnhancements() {
.CVar("gEnhancements.PlayerActions.ArrowCycle")
.Options(CheckboxOptions().Tooltip(
"While aiming the bow, use L to cycle between Normal, Fire, Ice and Light arrows."));
AddWidget(path, "Remote Bombchu Control", WIDGET_CVAR_CHECKBOX)
.CVar("gEnhancements.PlayerActions.RemoteBombchu")
.Options(CheckboxOptions().Tooltip(
"While aiming the bow, use L to cycle between Normal, Fire, Ice and Light arrows."));

path.column = 2;
AddWidget(path, "Modes", WIDGET_SEPARATOR_TEXT);
Expand Down
76 changes: 76 additions & 0 deletions mm/2s2h/Enhancements/Equipment/RemoteBombchu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <libultraship/bridge.h>
#include "2s2h/GameInteractor/GameInteractor.h"
#include "2s2h/ShipInit.hpp"

extern "C" {
#include "variables.h"
#include "src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.h"

void EnBomChu_Move(EnBomChu*, PlayState*);
void EnBomChu_Explode(EnBomChu*, PlayState*);
}

#define CVAR_NAME "gEnhancements.PlayerActions.RemoteBombchu"
#define CVAR CVarGetInteger(CVAR_NAME, 0)

static bool focused = false;
static EnBomChu* activeBombchu = nullptr;

void RegisterRemoteBombchu() {
COND_ID_HOOK(OnActorInit, ACTOR_EN_BOM_CHU, CVAR, [](Actor* actor) {
activeBombchu = (EnBomChu*)actor;
});

COND_ID_HOOK(OnActorDestroy, ACTOR_EN_BOM_CHU, CVAR, [](Actor* actor) {
Player* player = GET_PLAYER(gPlayState);

if (actor == (Actor*)activeBombchu) {
activeBombchu = nullptr;

if (focused) {
Camera_SetFocalActor(Play_GetCamera(gPlayState, player->subCamId), &player->actor);
player->stateFlags1 &= ~PLAYER_STATE1_20;
focused = false;
}
}
});

COND_ID_HOOK(OnActorUpdate, ACTOR_EN_BOM_CHU, CVAR, [](Actor* actor) {
if (actor != (Actor*)activeBombchu) {
return;
}

Player* player = GET_PLAYER(gPlayState);
Input* input = &gPlayState->state.input[0];

if (activeBombchu->actionFunc == EnBomChu_Move) {
if (!focused) {
Camera_SetFocalActor(Play_GetCamera(gPlayState, CutsceneManager_GetCurrentSubCamId(actor->csId)), actor);
player->stateFlags1 |= PLAYER_STATE1_20;
focused = true;
}

f32 turnRate = 1500.0f;
f32 stickX = input->cur.stick_x;
if (fabsf(stickX) > 10.0f) {
f32 turnAngle = turnRate * (stickX / 85.0f);
// TODO: This works on flat ground, but not when the chu starts going up or down slopes/walls
activeBombchu->actor.shape.rot.y -= turnAngle;
activeBombchu->actor.world.rot.y -= turnAngle;
}

if (input->press.button & BTN_B) {
EnBomChu_Explode(activeBombchu, gPlayState);
}

if (input->press.button & BTN_A) {
activeBombchu = nullptr;
Camera_SetFocalActor(Play_GetCamera(gPlayState, player->subCamId), &player->actor);
player->stateFlags1 &= ~PLAYER_STATE1_20;
focused = false;
}
}
});
}

static RegisterShipInitFunc initFunc(RegisterRemoteBombchu, { CVAR_NAME });

0 comments on commit 1b379e5

Please sign in to comment.