Using TryBattleFormChange in place of certain TryFormChange

This commit is contained in:
Eduardo Quezada 2022-11-01 23:50:26 -03:00
parent 797c5514d3
commit 15c12af2cf
6 changed files with 27 additions and 22 deletions

View File

@ -188,6 +188,8 @@ void TryToRevertMimicry(void);
void RestoreBattlerOriginalTypes(u8 battlerId);
u32 GetBattlerMoveTargetType(u8 battlerId, u16 move);
bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move);
void CopyMonLevelAndBaseStatsToBattleMon(u32 battler, struct Pokemon *mon);
void CopyMonAbilityAndTypesToBattleMon(u32 battler, struct Pokemon *mon);
void RecalcBattlerStats(u32 battler, struct Pokemon *mon);
// Ability checks
bool32 IsRolePlayBannedAbilityAtk(u16 ability);

View File

@ -565,7 +565,7 @@ u16 GetFormChangeTargetSpecies(struct Pokemon *mon, u16 method, u32 arg);
u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg);
u16 MonTryLearningNewMoveEvolution(struct Pokemon *mon, bool8 firstMove);
bool32 ShouldShowFemaleDifferences(u16 species, u32 personality);
void TryFormChange(u32 monId, u32 side, u16 method);
bool32 TryFormChange(u32 monId, u32 side, u16 method);
void TryToSetBattleFormChangeMoves(struct Pokemon *mon, u16 method);
u32 GetMonFriendshipScore(struct Pokemon *pokemon);

View File

@ -3247,7 +3247,7 @@ void FaintClearSetData(void)
gBattleMons[gActiveBattler].type3 = TYPE_MYSTERY;
Ai_UpdateFaintData(gActiveBattler);
TryFormChange(gBattlerPartyIndexes[gActiveBattler], GET_BATTLER_SIDE(gActiveBattler), FORM_CHANGE_FAINT);
TryBattleFormChange(gActiveBattler, FORM_CHANGE_FAINT);
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
UndoMegaEvolution(gBattlerPartyIndexes[gActiveBattler]);

View File

@ -4213,15 +4213,7 @@ static void Cmd_getexp(void)
if (battlerId != 0xFF)
{
gBattleMons[battlerId].level = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_LEVEL);
gBattleMons[battlerId].hp = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_HP);
gBattleMons[battlerId].maxHP = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_MAX_HP);
gBattleMons[battlerId].attack = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_ATK);
gBattleMons[battlerId].defense = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_DEF);
gBattleMons[battlerId].speed = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPEED);
gBattleMons[battlerId].spAttack = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPATK);
gBattleMons[battlerId].spDefense = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPDEF);
CopyMonLevelAndBaseStatsToBattleMon(battlerId, &gPlayerParty[gBattleStruct->expGetterMonId]);
if (gStatuses3[battlerId] & STATUS3_POWER_TRICK)
SWAP(gBattleMons[battlerId].attack, gBattleMons[battlerId].defense, temp);
}
@ -14064,7 +14056,7 @@ static void Cmd_handleballthrow(void)
{
BtlController_EmitBallThrowAnim(BUFFER_A, BALL_3_SHAKES_SUCCESS);
MarkBattlerForControllerExec(gActiveBattler);
TryFormChange(gBattlerPartyIndexes[gBattlerTarget], GET_BATTLER_SIDE(gBattlerTarget), FORM_CHANGE_BATTLE_END),
TryBattleFormChange(gBattlerTarget, FORM_CHANGE_BATTLE_END);
gBattlescriptCurrInstr = BattleScript_SuccessBallThrow;
SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_POKEBALL, &gLastUsedItem);
@ -14118,7 +14110,7 @@ static void Cmd_handleballthrow(void)
if (IsCriticalCapture())
gBattleSpritesDataPtr->animationData->criticalCaptureSuccess = TRUE;
TryFormChange(gBattlerPartyIndexes[gBattlerTarget], GET_BATTLER_SIDE(gBattlerTarget), FORM_CHANGE_BATTLE_END),
TryBattleFormChange(gBattlerTarget, FORM_CHANGE_BATTLE_END);
gBattlescriptCurrInstr = BattleScript_SuccessBallThrow;
SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_POKEBALL, &gLastUsedItem);

View File

@ -518,7 +518,7 @@ void HandleAction_Switch(void)
if (gBattleResults.playerSwitchesCounter < 255)
gBattleResults.playerSwitchesCounter++;
TryFormChange(gBattlerPartyIndexes[gBattlerAttacker], GetBattlerSide(gBattlerAttacker), FORM_CHANGE_BATTLE_SWITCH);
TryBattleFormChange(gBattlerAttacker, FORM_CHANGE_BATTLE_SWITCH);
}
void HandleAction_UseItem(void)
@ -9698,16 +9698,14 @@ bool32 IsBattlerPrimalReverted(u8 battlerId)
void TryBattleFormChange(u8 battlerId, u16 method)
{
u16 targetSpecies;
u8 monId = gBattlerPartyIndexes[battlerId];
u8 side = GET_BATTLER_SIDE(battlerId);
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
targetSpecies = GetFormChangeTargetSpecies(&party[monId], method, 0);
if (targetSpecies != SPECIES_NONE)
if (TryFormChange(monId, side, method))
{
SetMonData(&party[monId], MON_DATA_SPECIES, &targetSpecies);
RecalcBattlerStats(battlerId, &party[monId]);
CopyMonLevelAndBaseStatsToBattleMon(battlerId, &party[monId]);
CopyMonAbilityAndTypesToBattleMon(battlerId, &party[monId]);
}
}
@ -10370,9 +10368,8 @@ bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move)
return TRUE;
}
void RecalcBattlerStats(u32 battler, struct Pokemon *mon)
void CopyMonLevelAndBaseStatsToBattleMon(u32 battler, struct Pokemon *mon)
{
CalculateMonStats(mon);
gBattleMons[battler].level = GetMonData(mon, MON_DATA_LEVEL);
gBattleMons[battler].hp = GetMonData(mon, MON_DATA_HP);
gBattleMons[battler].maxHP = GetMonData(mon, MON_DATA_MAX_HP);
@ -10381,7 +10378,19 @@ void RecalcBattlerStats(u32 battler, struct Pokemon *mon)
gBattleMons[battler].speed = GetMonData(mon, MON_DATA_SPEED);
gBattleMons[battler].spAttack = GetMonData(mon, MON_DATA_SPATK);
gBattleMons[battler].spDefense = GetMonData(mon, MON_DATA_SPDEF);
}
void CopyMonAbilityAndTypesToBattleMon(u32 battler, struct Pokemon *mon)
{
gBattleMons[battler].ability = GetMonAbility(mon);
gBattleMons[battler].type1 = gBaseStats[gBattleMons[battler].species].type1;
gBattleMons[battler].type2 = gBaseStats[gBattleMons[battler].species].type2;
gBattleMons[battler].type3 = TYPE_MYSTERY;
}
void RecalcBattlerStats(u32 battler, struct Pokemon *mon)
{
CalculateMonStats(mon);
CopyMonLevelAndBaseStatsToBattleMon(battler, mon);
CopyMonAbilityAndTypesToBattleMon(battler, mon);
}

View File

@ -8495,7 +8495,7 @@ bool32 ShouldShowFemaleDifferences(u16 species, u32 personality)
return (gBaseStats[species].flags & SPECIES_FLAG_GENDER_DIFFERENCE) && GetGenderFromSpeciesAndPersonality(species, personality) == MON_FEMALE;
}
void TryFormChange(u32 monId, u32 side, u16 method)
bool32 TryFormChange(u32 monId, u32 side, u16 method)
{
u32 targetSpecies;
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
@ -8506,7 +8506,9 @@ void TryFormChange(u32 monId, u32 side, u16 method)
TryToSetBattleFormChangeMoves(&party[monId], method);
SetMonData(&party[monId], MON_DATA_SPECIES, &targetSpecies);
CalculateMonStats(&party[monId]);
return TRUE;
}
return FALSE;
}
void TryToSetBattleFormChangeMoves(struct Pokemon *mon, u16 method)