Skip to content

Commit

Permalink
Add OneHit KO (HarbourMasters#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz authored Aug 27, 2022
1 parent b57e44a commit af5313d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions soh/soh/Enhancements/debugconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ uint32_t minishLink;
uint32_t gravityLevel;
uint32_t resetLinkScale;
uint32_t invisibleLink;
uint32_t oneHitKO;

static bool ActorSpawnHandler(std::shared_ptr<Ship::Console> Console, const std::vector<std::string>& args) {
if ((args.size() != 9) && (args.size() != 3) && (args.size() != 6)) {
Expand Down Expand Up @@ -631,7 +632,13 @@ static bool OneHitKOHandler(std::shared_ptr<Ship::Console> Console, const std::v
return CMD_FAILED;
}

// TODO: Implement
try {
oneHitKO = std::stoi(args[1], nullptr, 10) == 0 ? 0 : 1;
return CMD_SUCCESS;
} catch (std::invalid_argument const& ex) {
SohImGui::console->SendErrorMessage("[SOH] One-hit KO value must be a number.");
return CMD_FAILED;
}
}

static bool PacifistHandler(std::shared_ptr<Ship::Console> Console, const std::vector<std::string>& args) {
Expand Down Expand Up @@ -975,7 +982,7 @@ void DebugConsole_Init(void) {
{ "value", Ship::ArgumentType::NUMBER }
}});

CMD_REGISTER("ohko", { OneHitKOHandler, "Activates one hit KO.", {
CMD_REGISTER("ohko", { OneHitKOHandler, "Activates one hit KO. Any damage kills Link and he cannot gain health in this mode.", {
{ "value", Ship::ArgumentType::NUMBER }
}});

Expand Down
1 change: 1 addition & 0 deletions soh/soh/Enhancements/debugconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern uint32_t minishLink;
extern uint32_t gravityLevel;
extern uint32_t resetLinkScale;
extern uint32_t invisibleLink;
extern uint32_t oneHitKO;
#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 10 additions & 0 deletions soh/src/code/z_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <assert.h>
#endif

#include "soh/Enhancements/debugconsole.h"


static uint16_t _doActionTexWidth, _doActionTexHeight = -1;
static uint16_t DO_ACTION_TEX_WIDTH() {
Expand Down Expand Up @@ -2641,6 +2643,14 @@ s32 Health_ChangeBy(GlobalContext* globalCtx, s16 healthChange) {
osSyncPrintf("***** 増減=%d (now=%d, max=%d) ***", healthChange, gSaveContext.health,
gSaveContext.healthCapacity);

// If one-hit ko mode is on, any damage kills you and you cannot gain health.
if (oneHitKO) {
if (healthChange < 0)
gSaveContext.health = 0;

return 0;
}

// clang-format off
if (healthChange > 0) { Audio_PlaySoundGeneral(NA_SE_SY_HP_RECOVER, &D_801333D4, 4,
&D_801333E0, &D_801333E0, &D_801333E8);
Expand Down
3 changes: 1 addition & 2 deletions soh/src/overlays/actors/ovl_player_actor/z_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -3607,8 +3607,7 @@ s32 func_80837B18_modified(GlobalContext* globalCtx, Player* this, s32 damage, u
}

s32 modifiedDamage = damage;
if (modified)
{
if (modified) {
modifiedDamage *= (1 << CVar_GetS32("gDamageMul", 0));
}

Expand Down

0 comments on commit af5313d

Please sign in to comment.