Skip to content

Commit

Permalink
Fix hp-max getter
Browse files Browse the repository at this point in the history
  • Loading branch information
MokhaLeee committed Jan 18, 2025
1 parent 62deefd commit 0b7cdea
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Data/SkillSys/SkillExtraInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const struct SkillExtraInfo gSkillExtraInfo[MAX_SKILL_NUM + 1] = {
#if (defined(SID_HpBonus) && COMMON_SKILL_VALID(SID_HpBonus))
[SID_HpBonus] = {{ 2 }},
[SID_HpBonus] = {{ 5 }},
#endif

#if (defined(SID_StrBonus) && COMMON_SKILL_VALID(SID_StrBonus))
Expand Down
7 changes: 5 additions & 2 deletions Debug/Event/Source/debug-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ static const EventScr EventScr_Beginning[] = {
Evt_AddSkill(SID_FlierGuidance, CHARACTER_VANESSA)
#endif

#if defined(SID_MovBonus) && (COMMON_SKILL_VALID(SID_MovBonus))
Evt_AddSkill(SID_MovBonus, CHARACTER_EPHRAIM)
#if defined(SID_HpBonus) && (COMMON_SKILL_VALID(SID_HpBonus))
Evt_AddSkill(SID_HpBonus, CHARACTER_EPHRAIM)
#endif

#if defined(SID_Pass) && (COMMON_SKILL_VALID(SID_Pass))
Expand Down Expand Up @@ -484,6 +484,9 @@ static const EventScr EventScr_Beginning[] = {
SVAL(EVT_SLOT_1, 40)
SET_HP(CHARACTER_VIGARDE)

SVAL(EVT_SLOT_1, 23)
SET_HP(CHARACTER_EPHRAIM)

NoFade
ENDA
};
Expand Down
35 changes: 31 additions & 4 deletions Wizardry/Core/BattleSys/BattleHitExpasion/RepointBattleHit.event
Original file line number Diff line number Diff line change
@@ -1,78 +1,105 @@
PUSH
ORG $2AEC4
#include "Source/pr_BattleHitArrayRe.lyn.event"
// PROTECT 0x0002AE90 0x0002AED0 // ClearBattleHits

ORG $2C44C
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0002C40C 0x0002C450 // GetUnitExpMultiplier

// Already covered in function: GetBattleUnitStaffExp
ORG $2C660
// #include "Source/pr_BattleHitArrayRe.lyn.event"
#include "Source/pr_BattleHitArrayRe.lyn.event"
// PROTECT 0x0002C638 0x0002C6A0 // GetBattleUnitStaffExp

ORG $2CB0C
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0002CAFC 0x0002CB24 // BattlePrintDebugHitInfo

ORG $2CE98
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0002CE88 0x0002CE9C // BattleIsTriangleAttack

ORG $2CFA8
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT $2CF4C $2D0BC // Port from DebuffRework/Source/MiscHooks.event
PROTECT 0x0002CF4C 0x0002D0BC // BattleUnwindScripted

ORG $2F658
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0002F598 0x0002F664 // sub_802F598

ORG $2F730
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0002F664 0x0002F73C // ExecUnitPromotion

ORG $2F7FC
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0002F760 0x0002F808 // sub_802F760

ORG $58244
prBattleHitArray:
#include "Source/pr_BattleHitArrayRe.lyn.event"
// PROTECT 0x000581EC 0x00058848 // ParseBattleHitToBanimCmd

ORG $58930
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x00058918 0x0005893C // CheckBattleHasHit

ORG $72564
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x00072548 0x00072570 // EfxCheckRetaliation

ORG $7B4CC
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B464 0x0007B4D0 // SetupBattleMOVEUNITs

ORG $7B574
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B4D0 0x0007B5DC // sub_807B4D0

ORG $7B628
prBattleHitArray:
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B5DC 0x0007B634 // BeginMapAnimForPoisonDmg

ORG $7B680
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B634 0x0007B68C // BeginMapAnimForEggDmg

ORG $7B6D8
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B68C 0x0007B6E4 // BeginMapAnimForCritAtk

ORG $7B738
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B6E4 0x0007B740 // BeginMapAnimForSteal

ORG $7B790
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B740 0x0007B798 // BeginMapAnimForSummon

ORG $7B7E8
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B798 0x0007B7F0 // BeginMapAnimForSummonDK

ORG $7B84C
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B7F0 0x0007B854 // BeginMapAnimForDance

ORG $7B8B8
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B854 0x0007B8D4 // BeginBattleMapAnims

ORG $7B9B0
#include "Source/pr_BattleHitArrayRe.lyn.event"
// #include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007B900 0x0007B9B8 // SetupMapBattleAnim

ORG $7C920
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x0007C8FC 0x0007CAA8 // SetupMADebugBattle

ORG $A6D18
#include "Source/pr_BattleHitArrayRe.lyn.event"
PROTECT 0x000A6C8C 0x000A6D1C // ReadExtraMapInfo

ORG 0x2AEB2
BattleHitArrayWidth:
Expand Down
8 changes: 7 additions & 1 deletion Wizardry/Core/MapTask/Source/map-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ void PutUnitSpriteIconsOam(void)
* 1. HpBar
*/
if (unit->curHP != unit->maxHP) {
int _cur = unit->curHP;
int _max = unit->maxHP;

if (_cur > _max)
_cur = _max;

MapTaskPutOamHi(
MTSKCONF_HPBAR,
OAM2_PAL(0) + OAM2_LAYER(2) + OAM2_CHR(gpHpBarChr[Div(unit->curHP * 10, unit->maxHP)]));
OAM2_PAL(0) + OAM2_LAYER(2) + OAM2_CHR(gpHpBarChr[k_udiv(_cur * 10, _max)]));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Wizardry/Core/UnitStatusGetter/UnitStatusGetter.event
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ALIGN 4

#include "source/InjectHPGetters.event"
#include "source/InjectMovGetters.event"

#include "source/MiscHooks.lyn.event"
#include "source/StatusGetterExample.lyn.event"

#include "UnitMaxStatus/UnitMaxStatus.lyn.event"
Expand Down
18 changes: 0 additions & 18 deletions Wizardry/Core/UnitStatusGetter/source/InjectHPGetters.event
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@

PUSH

ORG $193A4 //UnitTryHeal
SHORT $B570 $1C04 $1C0D
BYTE $FF $F7 $D1 $FE
SHORT $1C06 $1C20
BYTE $FF $F7 $ED $FE
SHORT $1C03 $1C30 $1940 $4298 $DD00 $1C18 $74E0 $BC70 $BC01 $4700

PROTECT $193A4 $193E4

ORG $17CE0 //LoadUnit
SHORT $F001 $FA56 $E005
ORG $17CF2
Expand All @@ -30,15 +21,6 @@ ORG $17D18

PROTECT $17AC4 $17D3A

ORG $1936E //SetUnitHp
SHORT $1C0C $F7FF $FF0E $E006
ORG $19384
SHORT $4284 $DD0A $1C20 $E007
ORG $1939C
SHORT $74E8

PROTECT $19368 $193A2

POP

#endif /* HP_GETTER_MESSED_HOOKS_INSTALLED */
24 changes: 24 additions & 0 deletions Wizardry/Core/UnitStatusGetter/source/LynJump.event
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@ ALIGN 4
WORD $46C04778 $E59FC000 $E12FFF1C
POIN GetUnitCurrentHp
POP
PUSH
ORG $18740
ALIGN 4
WORD $46C04778 $E59FC000 $E12FFF1C
POIN MoveActiveUnit
POP
PUSH
ORG $19368
ALIGN 4
WORD $46C04778 $E59FC000 $E12FFF1C
POIN SetUnitHp
POP
PUSH
ORG $193a4
ALIGN 4
WORD $46C04778 $E59FC000 $E12FFF1C
POIN AddUnitHp
POP
PUSH
ORG $7b900
ALIGN 4
WORD $46C04778 $E59FC000 $E12FFF1C
POIN SetupMapBattleAnim
POP
78 changes: 78 additions & 0 deletions Wizardry/Core/UnitStatusGetter/source/MiscHooks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "common-chax.h"
#include "hooks.h"

LYN_REPLACE_CHECK(MoveActiveUnit);
void MoveActiveUnit(int x, int y)
{
gActiveUnit->xPos = x;
gActiveUnit->yPos = y;

gActiveUnit->state |= US_UNSELECTABLE;

PidStatsAddSquaresMoved(gActiveUnit->pCharacterData->number, gActionData.moveCount);

if (GetUnitCurrentHp(gActiveUnit) != 0)
gActiveUnit->state = gActiveUnit->state &~ US_HIDDEN;

UnitFinalizeMovement(gActiveUnit);
}

LYN_REPLACE_CHECK(AddUnitHp);
void AddUnitHp(struct Unit *unit, int amount)
{
int hp = unit->curHP;

hp += amount;

if (hp > GetUnitMaxHp(unit))
hp = GetUnitMaxHp(unit);

if (hp < 0)
hp = 0;

unit->curHP = hp;
}

LYN_REPLACE_CHECK(SetUnitHp);
void SetUnitHp(struct Unit *unit, int value)
{
unit->curHP = value;

if (unit->curHP > GetUnitMaxHp(unit))
unit->curHP = GetUnitMaxHp(unit);
}

LYN_REPLACE_CHECK(SetupMapBattleAnim);
void SetupMapBattleAnim(struct BattleUnit *actor, struct BattleUnit *target, struct BattleHit *hit)
{
int i;

MakeBattleMOVEUNIT(0, actor, &actor->unit);

if (gManimSt.actorCount_maybe > 1) {
HideUnitSprite(&gBattleTarget.unit); // NOTE: uses gBattleTarget instead of target argument
MakeBattleMOVEUNIT(1, target, &target->unit);
}

if (prBattleHitArray[0].attributes & BATTLE_HIT_ATTR_TATTACK) {
MakeBattleMOVEUNIT(2, actor, gBattleStats.taUnitA);
MakeBattleMOVEUNIT(3, actor, gBattleStats.taUnitB);

HideUnitSprite(gBattleStats.taUnitA);
HideUnitSprite(gBattleStats.taUnitB);
}

SetupBattleMOVEUNITs();

for (i = 0; i < gManimSt.actorCount_maybe; ++i) {
gManimSt.actor[i].hp_cur = gManimSt.actor[i].bu->hpInitial;

#if CHAX
gManimSt.actor[i].hp_max = gManimSt.actor[i].bu->unit.maxHP;
#else
gManimSt.actor[i].hp_max = GetUnitMaxHp(gManimSt.actor[i].unit);
#endif
}

SetDefaultColorEffects();
}
1 change: 1 addition & 0 deletions include/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#include "common-chax.h"

extern struct CharacterData const *const gpCharacterData;
extern struct BattleHit *const prBattleHitArray;

0 comments on commit 0b7cdea

Please sign in to comment.