Document datahpupdate
This commit is contained in:
@@ -1836,6 +1836,7 @@ static void Cmd_healthbarupdate(void)
|
||||
gBattlescriptCurrInstr += 2;
|
||||
}
|
||||
|
||||
// Update the active battler's HP and various HP trackers (Substitute, Bide, etc.)
|
||||
static void Cmd_datahpupdate(void)
|
||||
{
|
||||
u32 moveType;
|
||||
@@ -1843,9 +1844,13 @@ static void Cmd_datahpupdate(void)
|
||||
if (gBattleControllerExecFlags)
|
||||
return;
|
||||
|
||||
// moveType will be used later to record for Counter/Mirror Coat whether this was physical or special damage.
|
||||
// For moves with a dynamic type that have F_DYNAMIC_TYPE_IGNORE_PHYSICALITY set (in vanilla, just Hidden Power) this will ignore
|
||||
// the dynamic type and use the move's base type instead, meaning (as a Normal type) Hidden Power will only ever trigger Counter.
|
||||
// It also means that Hidden Power Fire is unable to defrost targets.
|
||||
if (gBattleStruct->dynamicMoveType == 0)
|
||||
moveType = gBattleMoves[gCurrentMove].type;
|
||||
else if (!(gBattleStruct->dynamicMoveType & F_DYNAMIC_TYPE_1))
|
||||
else if (!(gBattleStruct->dynamicMoveType & F_DYNAMIC_TYPE_IGNORE_PHYSICALITY))
|
||||
moveType = gBattleStruct->dynamicMoveType & DYNAMIC_TYPE_MASK;
|
||||
else
|
||||
moveType = gBattleMoves[gCurrentMove].type;
|
||||
@@ -1855,23 +1860,26 @@ static void Cmd_datahpupdate(void)
|
||||
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
|
||||
if (gBattleMons[gActiveBattler].status2 & STATUS2_SUBSTITUTE && gDisableStructs[gActiveBattler].substituteHP && !(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE))
|
||||
{
|
||||
// Target has an active Substitute, deal damage to that instead.
|
||||
if (gDisableStructs[gActiveBattler].substituteHP >= gBattleMoveDamage)
|
||||
{
|
||||
if (gSpecialStatuses[gActiveBattler].dmg == 0)
|
||||
gSpecialStatuses[gActiveBattler].dmg = gBattleMoveDamage;
|
||||
if (gSpecialStatuses[gActiveBattler].shellBellDmg == 0)
|
||||
gSpecialStatuses[gActiveBattler].shellBellDmg = gBattleMoveDamage;
|
||||
gDisableStructs[gActiveBattler].substituteHP -= gBattleMoveDamage;
|
||||
gHpDealt = gBattleMoveDamage;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gSpecialStatuses[gActiveBattler].dmg == 0)
|
||||
gSpecialStatuses[gActiveBattler].dmg = gDisableStructs[gActiveBattler].substituteHP;
|
||||
// Substitute has less HP than the damage dealt, set its HP to 0.
|
||||
if (gSpecialStatuses[gActiveBattler].shellBellDmg == 0)
|
||||
gSpecialStatuses[gActiveBattler].shellBellDmg = gDisableStructs[gActiveBattler].substituteHP;
|
||||
gHpDealt = gDisableStructs[gActiveBattler].substituteHP;
|
||||
gDisableStructs[gActiveBattler].substituteHP = 0;
|
||||
}
|
||||
// check substitute fading
|
||||
|
||||
if (gDisableStructs[gActiveBattler].substituteHP == 0)
|
||||
{
|
||||
// Substitute fades
|
||||
gBattlescriptCurrInstr += 2;
|
||||
BattleScriptPushCursor();
|
||||
gBattlescriptCurrInstr = BattleScript_SubstituteFade;
|
||||
@@ -1881,28 +1889,30 @@ static void Cmd_datahpupdate(void)
|
||||
else
|
||||
{
|
||||
gHitMarker &= ~HITMARKER_IGNORE_SUBSTITUTE;
|
||||
if (gBattleMoveDamage < 0) // hp goes up
|
||||
if (gBattleMoveDamage < 0)
|
||||
{
|
||||
gBattleMons[gActiveBattler].hp -= gBattleMoveDamage;
|
||||
// Negative damage is HP gain
|
||||
gBattleMons[gActiveBattler].hp += -gBattleMoveDamage;
|
||||
if (gBattleMons[gActiveBattler].hp > gBattleMons[gActiveBattler].maxHP)
|
||||
gBattleMons[gActiveBattler].hp = gBattleMons[gActiveBattler].maxHP;
|
||||
|
||||
}
|
||||
else // hp goes down
|
||||
else
|
||||
{
|
||||
if (gHitMarker & HITMARKER_SKIP_DMG_TRACK)
|
||||
if (gHitMarker & HITMARKER_IGNORE_BIDE)
|
||||
{
|
||||
gHitMarker &= ~HITMARKER_SKIP_DMG_TRACK;
|
||||
gHitMarker &= ~HITMARKER_IGNORE_BIDE;
|
||||
}
|
||||
else
|
||||
{
|
||||
gTakenDmg[gActiveBattler] += gBattleMoveDamage;
|
||||
// Record damage/attacker for Bide
|
||||
gBideDmg[gActiveBattler] += gBattleMoveDamage;
|
||||
if (gBattlescriptCurrInstr[1] == BS_TARGET)
|
||||
gTakenDmgByBattler[gActiveBattler] = gBattlerAttacker;
|
||||
gBideTarget[gActiveBattler] = gBattlerAttacker;
|
||||
else
|
||||
gTakenDmgByBattler[gActiveBattler] = gBattlerTarget;
|
||||
gBideTarget[gActiveBattler] = gBattlerTarget;
|
||||
}
|
||||
|
||||
// Deal damage to the battler
|
||||
if (gBattleMons[gActiveBattler].hp > gBattleMoveDamage)
|
||||
{
|
||||
gBattleMons[gActiveBattler].hp -= gBattleMoveDamage;
|
||||
@@ -1914,11 +1924,16 @@ static void Cmd_datahpupdate(void)
|
||||
gBattleMons[gActiveBattler].hp = 0;
|
||||
}
|
||||
|
||||
if (!gSpecialStatuses[gActiveBattler].dmg && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE))
|
||||
gSpecialStatuses[gActiveBattler].dmg = gHpDealt;
|
||||
// Record damage for Shell Bell
|
||||
if (gSpecialStatuses[gActiveBattler].shellBellDmg == 0 && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE))
|
||||
gSpecialStatuses[gActiveBattler].shellBellDmg = gHpDealt;
|
||||
|
||||
// Note: While physicalDmg/specialDmg below are only distinguished between for Counter/Mirror Coat, they are
|
||||
// used in combination as general damage trackers for other purposes. specialDmg is additionally used
|
||||
// to help determine if a fire move should defrost the target.
|
||||
if (IS_TYPE_PHYSICAL(moveType) && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE) && gCurrentMove != MOVE_PAIN_SPLIT)
|
||||
{
|
||||
// Record physical damage/attacker for Counter
|
||||
gProtectStructs[gActiveBattler].physicalDmg = gHpDealt;
|
||||
gSpecialStatuses[gActiveBattler].physicalDmg = gHpDealt;
|
||||
if (gBattlescriptCurrInstr[1] == BS_TARGET)
|
||||
@@ -1934,6 +1949,7 @@ static void Cmd_datahpupdate(void)
|
||||
}
|
||||
else if (!IS_TYPE_PHYSICAL(moveType) && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE))
|
||||
{
|
||||
// Record special damage/attacker for Mirror Coat
|
||||
gProtectStructs[gActiveBattler].specialDmg = gHpDealt;
|
||||
gSpecialStatuses[gActiveBattler].specialDmg = gHpDealt;
|
||||
if (gBattlescriptCurrInstr[1] == BS_TARGET)
|
||||
@@ -1949,15 +1965,18 @@ static void Cmd_datahpupdate(void)
|
||||
}
|
||||
}
|
||||
gHitMarker &= ~HITMARKER_PASSIVE_DAMAGE;
|
||||
|
||||
// Send updated HP
|
||||
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp);
|
||||
MarkBattlerForControllerExec(gActiveBattler);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// MOVE_RESULT_NO_EFFECT was set
|
||||
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
|
||||
if (gSpecialStatuses[gActiveBattler].dmg == 0)
|
||||
gSpecialStatuses[gActiveBattler].dmg = 0xFFFF;
|
||||
if (gSpecialStatuses[gActiveBattler].shellBellDmg == 0)
|
||||
gSpecialStatuses[gActiveBattler].shellBellDmg = IGNORE_SHELL_BELL;
|
||||
}
|
||||
gBattlescriptCurrInstr += 2;
|
||||
}
|
||||
@@ -7092,7 +7111,7 @@ static void Cmd_setbide(void)
|
||||
{
|
||||
gBattleMons[gBattlerAttacker].status2 |= STATUS2_MULTIPLETURNS;
|
||||
gLockedMoves[gBattlerAttacker] = gCurrentMove;
|
||||
gTakenDmg[gBattlerAttacker] = 0;
|
||||
gBideDmg[gBattlerAttacker] = 0;
|
||||
gBattleMons[gBattlerAttacker].status2 |= STATUS2_BIDE_TURN(2);
|
||||
|
||||
gBattlescriptCurrInstr++;
|
||||
@@ -7984,7 +8003,7 @@ static void Cmd_painsplitdmgcalc(void)
|
||||
storeLoc[3] = (painSplitHp & 0xFF000000) >> 24;
|
||||
|
||||
gBattleMoveDamage = gBattleMons[gBattlerAttacker].hp - hpDiff;
|
||||
gSpecialStatuses[gBattlerTarget].dmg = 0xFFFF;
|
||||
gSpecialStatuses[gBattlerTarget].shellBellDmg = IGNORE_SHELL_BELL;
|
||||
|
||||
gBattlescriptCurrInstr += 5;
|
||||
}
|
||||
@@ -8822,7 +8841,7 @@ static void Cmd_hiddenpowercalc(void)
|
||||
gBattleStruct->dynamicMoveType = ((NUMBER_OF_MON_TYPES - 3) * typeBits) / 63 + 1;
|
||||
if (gBattleStruct->dynamicMoveType >= TYPE_MYSTERY)
|
||||
gBattleStruct->dynamicMoveType++;
|
||||
gBattleStruct->dynamicMoveType |= F_DYNAMIC_TYPE_1 | F_DYNAMIC_TYPE_2;
|
||||
gBattleStruct->dynamicMoveType |= F_DYNAMIC_TYPE_IGNORE_PHYSICALITY | F_DYNAMIC_TYPE_UNREAD;
|
||||
|
||||
gBattlescriptCurrInstr++;
|
||||
}
|
||||
@@ -9699,15 +9718,15 @@ static void Cmd_setweatherballtype(void)
|
||||
if (gBattleWeather & B_WEATHER_ANY)
|
||||
gBattleScripting.dmgMultiplier = 2;
|
||||
if (gBattleWeather & B_WEATHER_RAIN)
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_WATER | F_DYNAMIC_TYPE_2;
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_WATER | F_DYNAMIC_TYPE_UNREAD;
|
||||
else if (gBattleWeather & B_WEATHER_SANDSTORM)
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_ROCK | F_DYNAMIC_TYPE_2;
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_ROCK | F_DYNAMIC_TYPE_UNREAD;
|
||||
else if (gBattleWeather & B_WEATHER_SUN)
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_FIRE | F_DYNAMIC_TYPE_2;
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_FIRE | F_DYNAMIC_TYPE_UNREAD;
|
||||
else if (gBattleWeather & B_WEATHER_HAIL)
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_ICE | F_DYNAMIC_TYPE_2;
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_ICE | F_DYNAMIC_TYPE_UNREAD;
|
||||
else
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_NORMAL | F_DYNAMIC_TYPE_2;
|
||||
*(&gBattleStruct->dynamicMoveType) = TYPE_NORMAL | F_DYNAMIC_TYPE_UNREAD;
|
||||
}
|
||||
|
||||
gBattlescriptCurrInstr++;
|
||||
|
||||
Reference in New Issue
Block a user