Cleanup by syncing src/battle_script_commands.c with pokefirered

This commit is contained in:
Eduardo Quezada 2022-07-29 09:43:16 -04:00
parent 09af7422d5
commit 9caca17064
5 changed files with 47 additions and 54 deletions

View File

@ -53,17 +53,17 @@
#define BATTLE_TYPE_MULTI (1 << 6)
#define BATTLE_TYPE_SAFARI (1 << 7)
#define BATTLE_TYPE_BATTLE_TOWER (1 << 8)
#define BATTLE_TYPE_WALLY_TUTORIAL (1 << 9)
#define BATTLE_TYPE_WALLY_TUTORIAL (1 << 9) // Used in pokefirered as BATTLE_TYPE_OLD_MAN_TUTORIAL.
#define BATTLE_TYPE_ROAMER (1 << 10)
#define BATTLE_TYPE_EREADER_TRAINER (1 << 11)
#define BATTLE_TYPE_KYOGRE_GROUDON (1 << 12)
#define BATTLE_TYPE_LEGENDARY (1 << 13)
#define BATTLE_TYPE_REGI (1 << 14)
#define BATTLE_TYPE_TWO_OPPONENTS (1 << 15)
#define BATTLE_TYPE_DOME (1 << 16)
#define BATTLE_TYPE_PALACE (1 << 17)
#define BATTLE_TYPE_ARENA (1 << 18)
#define BATTLE_TYPE_FACTORY (1 << 19)
#define BATTLE_TYPE_TWO_OPPONENTS (1 << 15) // Used in pokefirered as BATTLE_TYPE_GHOST.
#define BATTLE_TYPE_DOME (1 << 16) // Used in pokefirered as BATTLE_TYPE_POKEDUDE.
#define BATTLE_TYPE_PALACE (1 << 17) // Used in pokefirered as BATTLE_TYPE_WILD_SCRIPTED.
#define BATTLE_TYPE_ARENA (1 << 18) // Used in pokefirered as BATTLE_TYPE_LEGENDARY_FRLG.
#define BATTLE_TYPE_FACTORY (1 << 19) // Used in pokefirered as BATTLE_TYPE_TRAINER_TOWER.
#define BATTLE_TYPE_PIKE (1 << 20)
#define BATTLE_TYPE_PYRAMID (1 << 21)
#define BATTLE_TYPE_INGAME_PARTNER (1 << 22)

View File

@ -53,15 +53,15 @@
#define BS_EFFECT_BATTLER 2
#define BS_FAINTED 3
#define BS_ATTACKER_WITH_PARTNER 4 // for Cmd_updatestatusicon
#define BS_FAINTED_LINK_MULTIPLE_1 5
#define BS_FAINTED_LINK_MULTIPLE_2 6
#define BS_FAINTED_LINK_MULTIPLE_1 5 // for openpartyscreen
#define BS_FAINTED_LINK_MULTIPLE_2 6 // for openpartyscreen
#define BS_BATTLER_0 7
#define BS_ATTACKER_SIDE 8 // for Cmd_jumpifability
#define BS_NOT_ATTACKER_SIDE 9 // for Cmd_jumpifability
#define BS_SCRIPTING 10
#define BS_PLAYER1 11
#define BS_OPPONENT1 12
#define BS_PLAYER2 13
#define BS_PLAYER2 13 // for Cmd_updatestatusicon
#define BS_OPPONENT2 14
// Cmd_accuracycheck

View File

@ -719,7 +719,7 @@ void BattleArena_AddSkillPoints(u8 battler)
}
else if (gMoveResultFlags & MOVE_RESULT_NO_EFFECT)
{
if (!(gMoveResultFlags & MOVE_RESULT_MISSED) || gBattleCommunication[6] != 1)
if (!(gMoveResultFlags & MOVE_RESULT_MISSED) || gBattleCommunication[MISS_TYPE] != 1)
skillPoints[battler] -= 2;
}
else if ((gMoveResultFlags & MOVE_RESULT_SUPER_EFFECTIVE) && (gMoveResultFlags & MOVE_RESULT_NOT_VERY_EFFECTIVE))

View File

@ -667,7 +667,8 @@ static const u8* const sMoveEffectBS_Ptrs[] =
[MOVE_EFFECT_RECOIL_33] = BattleScript_MoveEffectRecoil,
};
static const struct WindowTemplate sUnusedWinTemplate = {
static const struct WindowTemplate sUnusedWinTemplate =
{
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 3,
@ -1190,7 +1191,8 @@ static void Cmd_accuracycheck(void)
static void Cmd_attackstring(void)
{
if (gBattleControllerExecFlags)
return;
return;
if (!(gHitMarker & (HITMARKER_NO_ATTACKSTRING | HITMARKER_ATTACKSTRING_PRINTED)))
{
PrepareStringBattle(STRINGID_USEDMOVE, gBattlerAttacker);
@ -1751,8 +1753,8 @@ static void Cmd_attackanimation(void)
else
{
if ((gBattleMoves[gCurrentMove].target & MOVE_TARGET_BOTH
|| gBattleMoves[gCurrentMove].target & MOVE_TARGET_FOES_AND_ALLY
|| gBattleMoves[gCurrentMove].target & MOVE_TARGET_DEPENDS)
|| gBattleMoves[gCurrentMove].target & MOVE_TARGET_FOES_AND_ALLY
|| gBattleMoves[gCurrentMove].target & MOVE_TARGET_DEPENDS)
&& gBattleScripting.animTargetsHit)
{
gBattlescriptCurrInstr++;
@ -1777,8 +1779,8 @@ static void Cmd_attackanimation(void)
multihit = gMultiHitCounter;
BtlController_EmitMoveAnimation(BUFFER_A, gCurrentMove, gBattleScripting.animTurn, gBattleMovePower, gBattleMoveDamage, gBattleMons[gBattlerAttacker].friendship, &gDisableStructs[gBattlerAttacker], multihit);
gBattleScripting.animTurn += 1;
gBattleScripting.animTargetsHit += 1;
gBattleScripting.animTurn++;
gBattleScripting.animTargetsHit++;
MarkBattlerForControllerExec(gBattlerAttacker);
gBattlescriptCurrInstr++;
}
@ -2154,7 +2156,7 @@ static void Cmd_printfromtable(void)
{
if (gBattleControllerExecFlags == 0)
{
const u16 *ptr = (const u16*) T1_READ_PTR(gBattlescriptCurrInstr + 1);
const u16* ptr = (const u16*) T1_READ_PTR(gBattlescriptCurrInstr + 1);
ptr += gBattleCommunication[MULTISTRING_CHOOSER];
PrepareStringBattle(*ptr, gBattlerAttacker);
@ -2168,7 +2170,7 @@ static void Cmd_printselectionstringfromtable(void)
{
if (gBattleControllerExecFlags == 0)
{
const u16 *ptr = (const u16*) T1_READ_PTR(gBattlescriptCurrInstr + 1);
const u16* ptr = (const u16*) T1_READ_PTR(gBattlescriptCurrInstr + 1);
ptr += gBattleCommunication[MULTISTRING_CHOOSER];
gActiveBattler = gBattlerAttacker;
@ -2537,7 +2539,6 @@ void SetMoveEffect(bool8 primary, u8 certain)
case MOVE_EFFECT_UPROAR:
if (!(gBattleMons[gEffectBattler].status2 & STATUS2_UPROAR))
{
gBattleMons[gEffectBattler].status2 |= STATUS2_MULTIPLETURNS;
gLockedMoves[gEffectBattler] = gCurrentMove;
gBattleMons[gEffectBattler].status2 |= STATUS2_UPROAR_TURN((Random() & 3) + 2); // 2-5 turns
@ -2641,7 +2642,7 @@ void SetMoveEffect(bool8 primary, u8 certain)
case MOVE_EFFECT_EVS_MINUS_1:
if (ChangeStatBuffs(SET_STAT_BUFF_VALUE(1) | STAT_BUFF_NEGATIVE,
gBattleCommunication[MOVE_EFFECT_BYTE] - MOVE_EFFECT_ATK_MINUS_1 + 1,
affectsUser, 0))
affectsUser, 0))
{
gBattlescriptCurrInstr++;
}
@ -2770,7 +2771,6 @@ void SetMoveEffect(bool8 primary, u8 certain)
*(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerTarget]) + 0) = 0;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerTarget]) + 1) = 0;
}
}
break;
case MOVE_EFFECT_PREVENT_ESCAPE:
@ -2834,7 +2834,7 @@ void SetMoveEffect(bool8 primary, u8 certain)
case MOVE_EFFECT_KNOCK_OFF:
if (gBattleMons[gEffectBattler].ability == ABILITY_STICKY_HOLD)
{
if (gBattleMons[gEffectBattler].item == 0)
if (gBattleMons[gEffectBattler].item == ITEM_NONE)
{
gBattlescriptCurrInstr++;
}
@ -3446,7 +3446,7 @@ static void Cmd_getexp(void)
gBattleMons[0].spAttack = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPATK);
gBattleMons[0].spDefense = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPDEF);
}
// What is else if?
if (gBattlerPartyIndexes[2] == gBattleStruct->expGetterMonId && gBattleMons[2].hp && (gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{
gBattleMons[2].level = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_LEVEL);
@ -4246,7 +4246,7 @@ static void Cmd_moveend(void)
effect = TRUE;
gBattleScripting.moveendState++;
break;
case MOVEEND_ON_DAMAGE_ABILITIES: // Contact abilities and Color Change
case MOVEEND_ON_DAMAGE_ABILITIES: // Such as abilities activating on contact(Poison Spore, Rough Skin, etc.).
if (AbilityBattleEffects(ABILITYEFFECT_ON_DAMAGE, gBattlerTarget, 0, 0, 0))
effect = TRUE;
gBattleScripting.moveendState++;
@ -4270,19 +4270,19 @@ static void Cmd_moveend(void)
{
if (gChosenMove == MOVE_BATON_PASS && !(gMoveResultFlags & MOVE_RESULT_FAILED))
{
++gBattleScripting.moveendState;
gBattleScripting.moveendState++;
break;
}
*choicedMoveAtk = gChosenMove;
}
for (i = 0; i < MAX_MON_MOVES; ++i)
for (i = 0; i < MAX_MON_MOVES; i++)
{
if (gBattleMons[gBattlerAttacker].moves[i] == *choicedMoveAtk)
break;
}
if (i == MAX_MON_MOVES)
*choicedMoveAtk = MOVE_NONE;
++gBattleScripting.moveendState;
gBattleScripting.moveendState++;
break;
case MOVEEND_CHANGED_ITEMS: // changed held items
for (i = 0; i < gBattlersCount; i++)
@ -4653,7 +4653,7 @@ static void Cmd_switchinanim(void)
| BATTLE_TYPE_RECORDED_LINK
| BATTLE_TYPE_TRAINER_HILL
| BATTLE_TYPE_FRONTIER)))
HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gActiveBattler].species), FLAG_SET_SEEN, gBattleMons[gActiveBattler].personality);
HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gActiveBattler].species), FLAG_SET_SEEN, gBattleMons[gActiveBattler].personality);
gAbsentBattlerFlags &= ~(gBitTable[gActiveBattler]);
@ -6225,19 +6225,19 @@ static void Cmd_jumpifplayerran(void)
static void Cmd_hpthresholds(void)
{
u8 opposingBank;
u8 opposingBattler;
s32 result;
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
opposingBank = gActiveBattler ^ BIT_SIDE;
opposingBattler = gActiveBattler ^ BIT_SIDE;
result = gBattleMons[opposingBank].hp * 100 / gBattleMons[opposingBank].maxHP;
result = gBattleMons[opposingBattler].hp * 100 / gBattleMons[opposingBattler].maxHP;
if (result == 0)
result = 1;
if (result > 69 || !gBattleMons[opposingBank].hp)
if (result > 69 || !gBattleMons[opposingBattler].hp)
gBattleStruct->hpScale = 0;
else if (result > 39)
gBattleStruct->hpScale = 1;
@ -6252,18 +6252,18 @@ static void Cmd_hpthresholds(void)
static void Cmd_hpthresholds2(void)
{
u8 opposingBank;
u8 opposingBattler;
s32 result;
u8 hpSwitchout;
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
opposingBank = gActiveBattler ^ BIT_SIDE;
hpSwitchout = *(gBattleStruct->hpOnSwitchout + GetBattlerSide(opposingBank));
result = (hpSwitchout - gBattleMons[opposingBank].hp) * 100 / hpSwitchout;
opposingBattler = gActiveBattler ^ BIT_SIDE;
hpSwitchout = *(gBattleStruct->hpOnSwitchout + GetBattlerSide(opposingBattler));
result = (hpSwitchout - gBattleMons[opposingBattler].hp) * 100 / hpSwitchout;
if (gBattleMons[opposingBank].hp >= hpSwitchout)
if (gBattleMons[opposingBattler].hp >= hpSwitchout)
gBattleStruct->hpScale = 0;
else if (result <= 29)
gBattleStruct->hpScale = 1;
@ -6280,7 +6280,7 @@ static void Cmd_useitemonopponent(void)
{
gBattlerInMenuId = gBattlerAttacker;
PokemonUseItemEffects(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker]], gLastUsedItem, gBattlerPartyIndexes[gBattlerAttacker], 0, TRUE);
gBattlescriptCurrInstr += 1;
gBattlescriptCurrInstr++;
}
static void Cmd_various(void)
@ -6337,7 +6337,7 @@ static void Cmd_various(void)
break;
}
if (i == MAX_MON_MOVES)
*choicedMove = 0;
*choicedMove = MOVE_NONE;
}
break;
case VARIOUS_RESET_PLAYER_FAINTED:
@ -6608,8 +6608,7 @@ static void Cmd_trymirrormove(void)
{
if (i != gBattlerAttacker)
{
move = *(i * 2 + gBattlerAttacker * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0)
| (*(i * 2 + gBattlerAttacker * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) << 8);
move = T1_READ_16(i * 2 + gBattlerAttacker * 8 + gBattleStruct->lastTakenMoveFrom);
if (move != MOVE_NONE && move != MOVE_UNAVAILABLE)
{
@ -6619,8 +6618,7 @@ static void Cmd_trymirrormove(void)
}
}
move = *(gBattleStruct->lastTakenMove + gBattlerAttacker * 2 + 0)
| (*(gBattleStruct->lastTakenMove + gBattlerAttacker * 2 + 1) << 8);
move = T1_READ_16(gBattleStruct->lastTakenMove + gBattlerAttacker * 2);
if (move != MOVE_NONE && move != MOVE_UNAVAILABLE)
{
@ -7026,7 +7024,6 @@ static u8 ChangeStatBuffs(s8 statValue, u8 statId, u8 flags, const u8 *BS_ptr)
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STAT_WONT_DECREASE;
else
gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == gActiveBattler); // B_MSG_ATTACKER_STAT_FELL or B_MSG_DEFENDER_STAT_FELL
}
}
else // stat increase
@ -7351,7 +7348,6 @@ static void Cmd_tryconversiontypechange(void) // randomly changes user's type to
{
do
{
while ((moveChecked = Random() & (MAX_MON_MOVES - 1)) >= validMoves);
moveType = gBattleMoves[gBattleMons[gBattlerAttacker].moves[moveChecked]].type;
@ -7795,7 +7791,6 @@ static void Cmd_mimicattackcopy(void)
else
gBattleMons[gBattlerAttacker].pp[gCurrMovePos] = 5;
PREPARE_MOVE_BUFFER(gBattleTextBuff1, gLastMoves[gBattlerTarget])
gDisableStructs[gBattlerAttacker].mimickedMoves |= gBitTable[gCurrMovePos];
@ -8166,7 +8161,6 @@ static void Cmd_trychoosesleeptalkmove(void)
{
unusableMovesBits |= gBitTable[i];
}
}
unusableMovesBits = CheckMoveLimitations(gBattlerAttacker, unusableMovesBits, ~MOVE_LIMITATION_PP);
@ -8611,7 +8605,6 @@ static void Cmd_magnitudedamagecalculation(void)
magnitude = 10;
}
PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff1, 2, magnitude)
for (gBattlerTarget = 0; gBattlerTarget < gBattlersCount; gBattlerTarget++)
@ -8879,7 +8872,7 @@ static void Cmd_trydobeatup(void)
&& GetMonData(&party[gBattleCommunication[0]], MON_DATA_SPECIES2)
&& GetMonData(&party[gBattleCommunication[0]], MON_DATA_SPECIES2) != SPECIES_EGG
&& !GetMonData(&party[gBattleCommunication[0]], MON_DATA_STATUS))
break;
break;
}
if (gBattleCommunication[0] < PARTY_SIZE)
{
@ -9230,9 +9223,9 @@ static void Cmd_trysetroots(void) // ingrain
static void Cmd_doubledamagedealtifdamaged(void)
{
if ((gProtectStructs[gBattlerAttacker].physicalDmg
if ((gProtectStructs[gBattlerAttacker].physicalDmg != 0
&& gProtectStructs[gBattlerAttacker].physicalBattlerId == gBattlerTarget)
|| (gProtectStructs[gBattlerAttacker].specialDmg
|| (gProtectStructs[gBattlerAttacker].specialDmg != 0
&& gProtectStructs[gBattlerAttacker].specialBattlerId == gBattlerTarget))
{
gBattleScripting.dmgMultiplier = 2;
@ -9485,7 +9478,7 @@ static void Cmd_switchoutabilities(void)
{
case ABILITY_NATURAL_CURE:
gBattleMons[gActiveBattler].status1 = 0;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE,
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE,
gBitTable[*(gBattleStruct->battlerPartyIndexes + gActiveBattler)],
sizeof(gBattleMons[gActiveBattler].status1),
&gBattleMons[gActiveBattler].status1);
@ -10164,7 +10157,7 @@ static void Cmd_trygivecaughtmonnick(void)
}
break;
case 3:
if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active )
if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active)
{
SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick);
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1);

View File

@ -93,7 +93,7 @@ void HandleAction_UseMove(void)
gBattleStruct->atkCancellerTracker = 0;
gMoveResultFlags = 0;
gMultiHitCounter = 0;
gBattleCommunication[6] = 0;
gBattleCommunication[MISS_TYPE] = 0;
gCurrMovePos = gChosenMovePos = *(gBattleStruct->chosenMovePositions + gBattlerAttacker);
// choose move