Modularize Hurt Container mode hook (#5874)

* Modularize Hurt Container mode hook

* Hook condition was wrong - fixed it

* Change type of hurtEnabled for clarity

* Change type back to bool

* Add VB hook

* Don't duplicate health capacity modifier calculation

* Add constants, replace magic numbers

* Clang format

* Publicize more health unit macros

* Make mod file self-contained
This commit is contained in:
Jordan Longstaff
2025-11-24 12:30:34 -05:00
committed by GitHub
parent 3e6b590db4
commit 0f41ecb145
24 changed files with 117 additions and 93 deletions

View File

@@ -1707,7 +1707,7 @@ void Item_DropCollectibleRandom(PlayState* play, Actor* fromActor, Vec3f* spawnP
}
if (dropId == ITEM00_FLEXIBLE) {
if (gSaveContext.health <= 0x10) { // 1 heart or less
if (gSaveContext.health <= FULL_HEART_HEALTH) { // 1 heart or less
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_ELF, spawnPos->x, spawnPos->y + 40.0f, spawnPos->z, 0, 0, 0,
FAIRY_HEAL_TIMED, true);
EffectSsDeadSound_SpawnStationary(play, spawnPos, NA_SE_EV_BUTTERFRY_TO_FAIRY, true,

View File

@@ -393,9 +393,9 @@ void HealthMeter_Draw(PlayState* play) {
InterfaceContext* interfaceCtx = &play->interfaceCtx;
GraphicsContext* gfxCtx = play->state.gfxCtx;
Vtx* sp154 = interfaceCtx->beatingHeartVtx;
s32 curHeartFraction = gSaveContext.health % 0x10;
s16 totalHeartCount = gSaveContext.healthCapacity / 0x10;
s16 fullHeartCount = gSaveContext.health / 0x10;
s32 curHeartFraction = gSaveContext.health % FULL_HEART_HEALTH;
s16 totalHeartCount = gSaveContext.healthCapacity / FULL_HEART_HEALTH;
s16 fullHeartCount = gSaveContext.health / FULL_HEART_HEALTH;
s32 pad2;
f32 sp144 = interfaceCtx->unk_22A * 0.1f;
s32 curCombineModeSet = 0;
@@ -410,7 +410,7 @@ void HealthMeter_Draw(PlayState* play) {
OPEN_DISPS(gfxCtx);
if (!(gSaveContext.health % 0x10)) {
if (!(gSaveContext.health % FULL_HEART_HEALTH)) {
fullHeartCount--;
}

View File

@@ -4653,7 +4653,7 @@ void Message_Update(PlayState* play) {
}
if ((msgCtx->textId >= 0xC2 && msgCtx->textId < 0xC7) ||
(msgCtx->textId >= 0xFA && msgCtx->textId < 0xFE)) {
gSaveContext.healthAccumulator = 0x140; // Refill 20 hearts
gSaveContext.healthAccumulator = MAX_HEALTH; // Refill 20 hearts
}
if (msgCtx->textId == 0x301F || msgCtx->textId == 0xA || msgCtx->textId == 0xC || msgCtx->textId == 0xCF ||
msgCtx->textId == 0x21C || msgCtx->textId == 9 || msgCtx->textId == 0x4078 ||
@@ -4691,12 +4691,9 @@ void Message_Update(PlayState* play) {
}
if ((s32)(gSaveContext.inventory.questItems & 0xF0000000) == 0x40000000) {
gSaveContext.inventory.questItems ^= 0x40000000;
if (!CVarGetInteger(CVAR_ENHANCEMENT("HurtContainer"), 0)) {
gSaveContext.healthCapacity += 0x10;
gSaveContext.health += 0x10;
} else {
gSaveContext.healthCapacity -= 0x10;
gSaveContext.health -= 0x10;
if (GameInteractor_Should(VB_HEARTS_INCREASE_WITH_CONTAINERS, true)) {
gSaveContext.healthCapacity += FULL_HEART_HEALTH;
gSaveContext.health += FULL_HEART_HEALTH;
}
}
if (msgCtx->ocarinaAction != OCARINA_ACTION_CHECK_NOWARP_DONE) {

View File

@@ -2318,19 +2318,16 @@ u8 Item_Give(PlayState* play, u8 item) {
gSaveContext.ship.stats.heartPieces++;
return Return_Item(item, MOD_NONE, ITEM_NONE);
} else if (item == ITEM_HEART_CONTAINER) {
if (!CVarGetInteger(CVAR_ENHANCEMENT("HurtContainer"), 0)) {
gSaveContext.healthCapacity += 0x10;
gSaveContext.health += 0x10;
} else {
gSaveContext.healthCapacity -= 0x10;
gSaveContext.health -= 0x10;
if (GameInteractor_Should(VB_HEARTS_INCREASE_WITH_CONTAINERS, true)) {
gSaveContext.healthCapacity += FULL_HEART_HEALTH;
gSaveContext.health += FULL_HEART_HEALTH;
}
gSaveContext.ship.stats.heartContainers++;
return Return_Item(item, MOD_NONE, ITEM_NONE);
} else if (item == ITEM_HEART) {
osSyncPrintf("回復ハート回復ハート回復ハート\n"); // "Recovery Heart"
if (play != NULL) {
Health_ChangeBy(play, 0x10);
Health_ChangeBy(play, FULL_HEART_HEALTH);
}
return Return_Item(item, MOD_NONE, item);
} else if (item == ITEM_MAGIC_SMALL) {
@@ -2905,7 +2902,7 @@ s32 Health_ChangeBy(PlayState* play, s16 healthChange) {
gSaveContext.health = gSaveContext.healthCapacity;
}
heartCount = gSaveContext.health % 0x10;
heartCount = gSaveContext.health % FULL_HEART_HEALTH;
healthLevel = heartCount;
if (heartCount != 0) {
@@ -3516,7 +3513,7 @@ void Interface_DrawMagicBar(PlayState* play) {
R_MAGIC_FILL_X - 1;
}
} else {
if ((gSaveContext.healthCapacity - 1) / 0x10 >= lineLength && lineLength != 0) {
if ((gSaveContext.healthCapacity - 1) / FULL_HEART_HEALTH >= lineLength && lineLength != 0) {
magicBarY =
magicBarY_original_l +
magicDrop * (lineLength == 0 ? 0 : ((gSaveContext.healthCapacity - 1) / (0x10 * lineLength) - 1));

View File

@@ -150,9 +150,9 @@ void Sram_OpenSave() {
osSyncPrintf("scene_no = %d\n", gSaveContext.entranceIndex);
osSyncPrintf(VT_RST);
if (gSaveContext.health < 0x30) {
if (gSaveContext.health < STARTING_HEALTH) {
gSaveContext.health =
CVarGetInteger(CVAR_ENHANCEMENT("FullHealthSpawn"), 0) ? gSaveContext.healthCapacity : 0x30;
CVarGetInteger(CVAR_ENHANCEMENT("FullHealthSpawn"), 0) ? gSaveContext.healthCapacity : STARTING_HEALTH;
}
if (gSaveContext.scarecrowLongSongSet) {