summaryrefslogtreecommitdiff
path: root/src/battle_script_commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/battle_script_commands.c')
-rw-r--r--src/battle_script_commands.c122
1 files changed, 56 insertions, 66 deletions
diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c
index 8f7013e45..6ec9d16b1 100644
--- a/src/battle_script_commands.c
+++ b/src/battle_script_commands.c
@@ -16,7 +16,6 @@
#include "random.h"
#include "battle_controllers.h"
#include "battle_interface.h"
-#include "constants/species.h"
#include "constants/songs.h"
#include "constants/trainers.h"
#include "constants/battle_anim.h"
@@ -954,7 +953,7 @@ static void Cmd_attackcanceler(void)
gHitMarker |= HITMARKER_OBEYS;
- if (gProtectStructs[gBattlerTarget].bounceMove && gBattleMoves[gCurrentMove].flags & FLAG_MAGICCOAT_AFFECTED)
+ if (gProtectStructs[gBattlerTarget].bounceMove && gBattleMoves[gCurrentMove].flags & FLAG_MAGIC_COAT_AFFECTED)
{
PressurePPLose(gBattlerAttacker, gBattlerTarget, MOVE_MAGIC_COAT);
gProtectStructs[gBattlerTarget].bounceMove = 0;
@@ -3519,7 +3518,7 @@ static void Cmd_unknown_24(void)
if (HP_count == 0)
gBattleOutcome |= B_OUTCOME_LOST;
-
+
HP_count = 0;
for (i = 0; i < PARTY_SIZE; i++)
@@ -3536,14 +3535,17 @@ static void Cmd_unknown_24(void)
if (gBattleOutcome == 0 && (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)))
{
- s32 foundPlayer = 0, foundOpponent;
+ s32 foundPlayer = 0;
+ s32 foundOpponent;
+
for (i = 0; i < gBattlersCount; i += 2)
{
if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40))
foundPlayer++;
}
-
+
foundOpponent = 0;
+
for (i = 1; i < gBattlersCount; i += 2)
{
if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40))
@@ -3553,14 +3555,14 @@ static void Cmd_unknown_24(void)
if (gBattleTypeFlags & BATTLE_TYPE_MULTI)
{
if (foundOpponent + foundPlayer > 1)
- gBattlescriptCurrInstr = (u8*) T2_READ_32(gBattlescriptCurrInstr + 1);
+ gBattlescriptCurrInstr = T2_READ_PTR(gBattlescriptCurrInstr + 1);
else
gBattlescriptCurrInstr += 5;
}
else
{
if (foundOpponent != 0 && foundPlayer != 0)
- gBattlescriptCurrInstr = (u8*) T2_READ_32(gBattlescriptCurrInstr + 1);
+ gBattlescriptCurrInstr = T2_READ_PTR(gBattlescriptCurrInstr + 1);
else
gBattlescriptCurrInstr += 5;
}
@@ -4664,19 +4666,16 @@ static void Cmd_jumpifcantswitch(void)
}
else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
{
- #ifndef NONMATCHING
- asm("":::"r5");
- #endif // NONMATCHING
if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT)
party = gEnemyParty;
else
party = gPlayerParty;
- i = 0;
+ lastMonId = 0;
if (gActiveBattler & 2)
- i = 3;
+ lastMonId = 3;
- for (lastMonId = i + 3; i < lastMonId; i++)
+ for (i = lastMonId; i < lastMonId + 3; i++)
{
if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE
&& !GetMonData(&party[i], MON_DATA_IS_EGG)
@@ -4685,7 +4684,7 @@ static void Cmd_jumpifcantswitch(void)
break;
}
- if (i == lastMonId)
+ if (i == lastMonId + 3)
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2);
else
gBattlescriptCurrInstr += 6;
@@ -4698,18 +4697,18 @@ static void Cmd_jumpifcantswitch(void)
{
party = gPlayerParty;
- i = 0;
+ lastMonId = 0;
if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gActiveBattler)) == TRUE)
- i = 3;
+ lastMonId = 3;
}
else
{
party = gEnemyParty;
if (gActiveBattler == 1)
- i = 0;
+ lastMonId = 0;
else
- i = 3;
+ lastMonId = 3;
}
}
else
@@ -4719,12 +4718,12 @@ static void Cmd_jumpifcantswitch(void)
else
party = gPlayerParty;
- i = 0;
+ lastMonId = 0;
if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gActiveBattler)) == TRUE)
- i = 3;
+ lastMonId = 3;
}
- for (lastMonId = i + 3; i < lastMonId; i++)
+ for (i = lastMonId; i < lastMonId + 3; i++)
{
if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE
&& !GetMonData(&party[i], MON_DATA_IS_EGG)
@@ -4733,7 +4732,7 @@ static void Cmd_jumpifcantswitch(void)
break;
}
- if (i == lastMonId)
+ if (i == lastMonId + 3)
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2);
else
gBattlescriptCurrInstr += 6;
@@ -4742,11 +4741,11 @@ static void Cmd_jumpifcantswitch(void)
{
party = gEnemyParty;
- i = 0;
+ lastMonId = 0;
if (gActiveBattler == B_POSITION_OPPONENT_RIGHT)
- i = 3;
+ lastMonId = 3;
- for (lastMonId = i + 3; i < lastMonId; i++)
+ for (i = lastMonId; i < lastMonId + 3; i++)
{
if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE
&& !GetMonData(&party[i], MON_DATA_IS_EGG)
@@ -4755,7 +4754,7 @@ static void Cmd_jumpifcantswitch(void)
break;
}
- if (i == lastMonId)
+ if (i == lastMonId + 3)
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2);
else
gBattlescriptCurrInstr += 6;
@@ -5033,14 +5032,9 @@ static void Cmd_openpartyscreen(void)
hitmarkerFaintBits = gHitMarker >> 0x1C;
gBattlerFainted = 0;
- while (1)
- {
- if (gBitTable[gBattlerFainted] & hitmarkerFaintBits)
- break;
- if (gBattlerFainted >= gBattlersCount)
- break;
+ while (!(gBitTable[gBattlerFainted] & hitmarkerFaintBits)
+ && gBattlerFainted < gBattlersCount)
gBattlerFainted++;
- }
if (gBattlerFainted == gBattlersCount)
gBattlescriptCurrInstr = jumpPtr;
@@ -5360,21 +5354,21 @@ static void Cmd_yesnoboxlearnmove(void)
BattleCreateYesNoCursorAt(0);
break;
case 1:
- if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0)
+ if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]);
gBattleCommunication[CURSOR_POSITION] = 0;
BattleCreateYesNoCursorAt(0);
}
- if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0)
+ if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]);
gBattleCommunication[CURSOR_POSITION] = 1;
BattleCreateYesNoCursorAt(1);
}
- if (gMain.newKeys & A_BUTTON)
+ if (JOY_NEW(A_BUTTON))
{
PlaySE(SE_SELECT);
if (gBattleCommunication[1] == 0)
@@ -5388,7 +5382,7 @@ static void Cmd_yesnoboxlearnmove(void)
gBattleScripting.learnMoveState = 5;
}
}
- else if (gMain.newKeys & B_BUTTON)
+ else if (JOY_NEW(B_BUTTON))
{
PlaySE(SE_SELECT);
gBattleScripting.learnMoveState = 5;
@@ -5477,21 +5471,21 @@ static void Cmd_yesnoboxstoplearningmove(void)
BattleCreateYesNoCursorAt(0);
break;
case 1:
- if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0)
+ if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]);
gBattleCommunication[CURSOR_POSITION] = 0;
BattleCreateYesNoCursorAt(0);
}
- if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0)
+ if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]);
gBattleCommunication[CURSOR_POSITION] = 1;
BattleCreateYesNoCursorAt(1);
}
- if (gMain.newKeys & A_BUTTON)
+ if (JOY_NEW(A_BUTTON))
{
PlaySE(SE_SELECT);
@@ -5502,7 +5496,7 @@ static void Cmd_yesnoboxstoplearningmove(void)
HandleBattleWindow(0x18, 0x8, 0x1D, 0xD, WINDOW_CLEAR);
}
- else if (gMain.newKeys & B_BUTTON)
+ else if (JOY_NEW(B_BUTTON))
{
PlaySE(SE_SELECT);
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1);
@@ -5535,8 +5529,8 @@ static void Cmd_hitanimation(void)
static u32 GetTrainerMoneyToGive(u16 trainerId)
{
u32 i = 0;
+ u32 lastMonLevel = 0;
u32 moneyReward;
- u8 lastMonLevel = 0;
if (trainerId == TRAINER_SECRET_BASE)
{
@@ -5772,28 +5766,28 @@ static void Cmd_yesnobox(void)
BattleCreateYesNoCursorAt(0);
break;
case 1:
- if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0)
+ if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]);
gBattleCommunication[CURSOR_POSITION] = 0;
BattleCreateYesNoCursorAt(0);
}
- if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0)
+ if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]);
gBattleCommunication[CURSOR_POSITION] = 1;
BattleCreateYesNoCursorAt(1);
}
- if (gMain.newKeys & B_BUTTON)
+ if (JOY_NEW(B_BUTTON))
{
gBattleCommunication[CURSOR_POSITION] = 1;
PlaySE(SE_SELECT);
HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR);
gBattlescriptCurrInstr++;
}
- else if (gMain.newKeys & A_BUTTON)
+ else if (JOY_NEW(A_BUTTON))
{
PlaySE(SE_SELECT);
HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR);
@@ -7128,17 +7122,12 @@ static void Cmd_forcerandomswitch(void)
s32 battler1PartyId = 0;
s32 battler2PartyId = 0;
- #ifdef NONMATCHING
- s32 lastMonId = 0; // + 1
- #else
- register s32 lastMonId asm("r8") = 0; // + 1
- #endif // NONMATCHING
-
- s32 firstMonId = 0;
- s32 monsCount = 0;
+ s32 firstMonId;
+ s32 lastMonId = 0; // + 1
+ s32 monsCount;
struct Pokemon* party = NULL;
s32 validMons = 0;
- s32 minNeeded = 0;
+ s32 minNeeded;
if ((gBattleTypeFlags & BATTLE_TYPE_TRAINER))
{
@@ -7250,14 +7239,15 @@ static void Cmd_forcerandomswitch(void)
{
do
{
- i = Random() % monsCount;
- i += firstMonId;
- }
- while (i == battler2PartyId
- || i == battler1PartyId
- || GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE
+ do
+ {
+ i = Random() % monsCount;
+ i += firstMonId;
+ }
+ while (i == battler2PartyId || i == battler1PartyId);
+ } while (GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE
|| GetMonData(&party[i], MON_DATA_IS_EGG) == TRUE
- || GetMonData(&party[i], MON_DATA_HP) == 0);
+ || GetMonData(&party[i], MON_DATA_HP) == 0); //should be one while loop, but that doesn't match.
}
*(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = i;
@@ -10076,21 +10066,21 @@ static void Cmd_trygivecaughtmonnick(void)
BattleCreateYesNoCursorAt(0);
break;
case 1:
- if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0)
+ if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]);
gBattleCommunication[CURSOR_POSITION] = 0;
BattleCreateYesNoCursorAt(0);
}
- if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0)
+ if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]);
gBattleCommunication[CURSOR_POSITION] = 1;
BattleCreateYesNoCursorAt(1);
}
- if (gMain.newKeys & A_BUTTON)
+ if (JOY_NEW(A_BUTTON))
{
PlaySE(SE_SELECT);
if (gBattleCommunication[CURSOR_POSITION] == 0)
@@ -10103,7 +10093,7 @@ static void Cmd_trygivecaughtmonnick(void)
gBattleCommunication[MULTIUSE_STATE] = 4;
}
}
- else if (gMain.newKeys & B_BUTTON)
+ else if (JOY_NEW(B_BUTTON))
{
PlaySE(SE_SELECT);
gBattleCommunication[MULTIUSE_STATE] = 4;