From 59f89bde9e8ced4c8240bdaded3b938ee1454def Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Thu, 18 Aug 2022 14:23:45 -0400 Subject: [PATCH 01/21] Misc cleanup --- gflib/sprite.c | 2 +- include/battle.h | 2 +- src/battle_controller_link_opponent.c | 21 +++++++++------------ src/battle_controller_opponent.c | 6 +++--- src/battle_controller_recorded_opponent.c | 6 +++--- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/gflib/sprite.c b/gflib/sprite.c index 9fc597cc3b21..cbcd6fb7c0fb 100644 --- a/gflib/sprite.c +++ b/gflib/sprite.c @@ -103,7 +103,7 @@ typedef void (*AffineAnimCmdFunc)(u8 matrixNum, struct Sprite *); #define DUMMY_OAM_DATA \ { \ .y = DISPLAY_HEIGHT, \ - .affineMode = 0, \ + .affineMode = ST_OAM_AFFINE_OFF, \ .objMode = 0, \ .mosaic = FALSE, \ .bpp = 0, \ diff --git a/include/battle.h b/include/battle.h index 0b349e4b6950..38c4cd779d84 100644 --- a/include/battle.h +++ b/include/battle.h @@ -551,7 +551,7 @@ struct BattleHealthboxInfo u8 specialAnimActive:1; // x40 u8 triedShinyMonAnim:1; u8 finishedShinyMonAnim:1; - u8 field_1_x1E:4; + u8 opponentDrawPartyStatusSummaryDelay:4; u8 bgmRestored:1; u8 waitForCry:1; u8 healthboxSlideInStarted:1; diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index a0756b8cb5f1..a9629f6622d6 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -368,16 +368,13 @@ static void TryShinyAnimAfterMonAnim(void) { TryShinyAnimation(gActiveBattler, &gEnemyParty[gBattlerPartyIndexes[gActiveBattler]]); } - else + else if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); - LinkOpponentBufferExecCompleted(); - } + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE; + FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); + FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + LinkOpponentBufferExecCompleted(); } } } @@ -1758,14 +1755,14 @@ static void LinkOpponentHandleDrawPartyStatusSummary(void) if (gBattleBufferA[gActiveBattler][2] != 0) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E < 2) + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay < 2) { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E++; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay++; return; } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E = 0; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay = 0; } } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index cf155dc76444..641cbd0ace4a 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1929,14 +1929,14 @@ static void OpponentHandleDrawPartyStatusSummary(void) if (gBattleBufferA[gActiveBattler][2] != 0) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E < 2) + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay < 2) { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E++; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay++; return; } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E = 0; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay = 0; } } diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index ebfdbc909ccd..49538b834e29 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -1698,14 +1698,14 @@ static void RecordedOpponentHandleDrawPartyStatusSummary(void) if (gBattleBufferA[gActiveBattler][2] != 0) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E < 2) + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay < 2) { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E++; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay++; return; } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_1_x1E = 0; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].opponentDrawPartyStatusSummaryDelay = 0; } } From 3bc2cf921c79530862c8c4b2fff0ce7a5bfef4c9 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Mon, 8 Aug 2022 10:06:30 -0400 Subject: [PATCH 02/21] Sync src/battle_controllers.c with pokefirered --- include/battle.h | 2 +- include/battle_controllers.h | 14 ---------- include/battle_message.h | 2 +- src/battle_controllers.c | 54 ++++++++++++++++++++++-------------- src/battle_message.c | 4 +-- 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/include/battle.h b/include/battle.h index 38c4cd779d84..0eaa60f30f6f 100644 --- a/include/battle.h +++ b/include/battle.h @@ -368,7 +368,7 @@ struct BattleStruct u8 faintedActionsState; u8 faintedActionsBattlerId; u16 expValue; - u8 field_52; + u8 scriptPartyIdx; // for printing the nickname u8 sentInPokes; bool8 selectionScriptFinished[MAX_BATTLERS_COUNT]; u8 battlerPartyIndexes[MAX_BATTLERS_COUNT]; diff --git a/include/battle_controllers.h b/include/battle_controllers.h index f6ac07b91349..064c080f6181 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -202,9 +202,7 @@ void PrepareBufferDataTransferLink(u8 bufferId, u16 size, u8 *data); // emitters void BtlController_EmitGetMonData(u8 bufferId, u8 requestId, u8 monToCheck); -void BtlController_EmitGetRawMonData(u8 bufferId, u8 monId, u8 bytes); // unused void BtlController_EmitSetMonData(u8 bufferId, u8 requestId, u8 monToCheck, u8 bytes, void *data); -void BtlController_EmitSetRawMonData(u8 bufferId, u8 monId, u8 bytes, void *data); // unused void BtlController_EmitLoadMonSprite(u8 bufferId); void BtlController_EmitSwitchInAnim(u8 bufferId, u8 partyId, bool8 dontClearSubstituteBit); void BtlController_EmitReturnMonToBall(u8 bufferId, bool8 skipAnim); @@ -212,10 +210,7 @@ void BtlController_EmitDrawTrainerPic(u8 bufferId); void BtlController_EmitTrainerSlide(u8 bufferId); void BtlController_EmitTrainerSlideBack(u8 bufferId); void BtlController_EmitFaintAnimation(u8 bufferId); -void BtlController_EmitPaletteFade(u8 bufferId); // unused -void BtlController_EmitSuccessBallThrowAnim(u8 bufferId); // unused void BtlController_EmitBallThrowAnim(u8 bufferId, u8 caseId); -void BtlController_EmitPause(u8 bufferId, u8 toWait, void *data); // unused void BtlController_EmitMoveAnimation(u8 bufferId, u16 move, u8 turnOfMove, u16 movePower, s32 dmg, u8 friendship, struct DisableStruct *disableStructPtr, u8 multihit); void BtlController_EmitPrintString(u8 bufferId, u16 stringId); void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringId); @@ -224,24 +219,15 @@ void BtlController_EmitYesNoBox(u8 bufferId); void BtlController_EmitChooseMove(u8 bufferId, bool8 isDoubleBattle, bool8 NoPpNumber, struct ChooseMoveStruct *movePpData); void BtlController_EmitChooseItem(u8 bufferId, u8 *battlePartyOrder); void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 slotId, u8 abilityId, u8 *data); -void BtlController_EmitCmd23(u8 bufferId); // unused void BtlController_EmitHealthBarUpdate(u8 bufferId, u16 hpValue); void BtlController_EmitExpUpdate(u8 bufferId, u8 partyId, u16 expPoints); void BtlController_EmitStatusIconUpdate(u8 bufferId, u32 status1, u32 status2); void BtlController_EmitStatusAnimation(u8 bufferId, bool8 status2, u32 status); -void BtlController_EmitStatusXor(u8 bufferId, u8 b); // unused void BtlController_EmitDataTransfer(u8 bufferId, u16 size, void *data); -void BtlController_EmitDMA3Transfer(u8 bufferId, void *dst, u16 size, void *data); // unused -void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *data); // unused -void BtlController_EmitCmd32(u8 bufferId, u16 size, void *data); // unused void BtlController_EmitTwoReturnValues(u8 bufferId, u8 ret8, u16 ret16); void BtlController_EmitChosenMonReturnValue(u8 bufferId, u8 partyId, u8 *battlePartyOrder); void BtlController_EmitOneReturnValue(u8 bufferId, u16 ret); void BtlController_EmitOneReturnValue_Duplicate(u8 bufferId, u16 ret); -void BtlController_EmitClearUnkVar(u8 bufferId); // unused -void BtlController_EmitSetUnkVar(u8 bufferId, u8 b); // unused -void BtlController_EmitClearUnkFlag(u8 bufferId); // unused -void BtlController_EmitToggleUnkFlag(u8 bufferId); // unused void BtlController_EmitHitAnimation(u8 bufferId); void BtlController_EmitCantSwitch(u8 bufferId); void BtlController_EmitPlaySE(u8 bufferId, u16 songId); diff --git a/include/battle_message.h b/include/battle_message.h index cc18a13d220b..ed642fb6ec98 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -202,7 +202,7 @@ struct BattleMsgData u16 lastItem; u8 lastAbility; u8 scrActive; - u8 unk1605E; + u8 bakScriptPartyIdx; u8 hpScale; u8 itemEffectBattler; u8 moveType; diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 42bdba8998b2..20681b27ce1e 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -8,7 +8,6 @@ #include "link.h" #include "link_rfu.h" #include "party_menu.h" -#include "pokemon.h" #include "recorded_battle.h" #include "task.h" #include "util.h" @@ -595,7 +594,7 @@ static void SetBattlePartyIds(void) if (GetMonData(&gPlayerParty[j], MON_DATA_HP) != 0 && GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_EGG - && GetMonData(&gPlayerParty[j], MON_DATA_IS_EGG) == 0) + && !GetMonData(&gPlayerParty[j], MON_DATA_IS_EGG)) { gBattlerPartyIndexes[i] = j; break; @@ -606,7 +605,7 @@ static void SetBattlePartyIds(void) if (GetMonData(&gEnemyParty[j], MON_DATA_HP) != 0 && GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_EGG - && GetMonData(&gEnemyParty[j], MON_DATA_IS_EGG) == 0) + && !GetMonData(&gEnemyParty[j], MON_DATA_IS_EGG)) { gBattlerPartyIndexes[i] = j; break; @@ -620,7 +619,7 @@ static void SetBattlePartyIds(void) if (GetMonData(&gPlayerParty[j], MON_DATA_HP) != 0 && GetMonData(&gPlayerParty[j], MON_DATA_SPECIES) != SPECIES_NONE // Probably a typo by Game Freak. The rest use SPECIES2. && GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_EGG - && GetMonData(&gPlayerParty[j], MON_DATA_IS_EGG) == 0 + && !GetMonData(&gPlayerParty[j], MON_DATA_IS_EGG) && gBattlerPartyIndexes[i - 2] != j) { gBattlerPartyIndexes[i] = j; @@ -632,7 +631,7 @@ static void SetBattlePartyIds(void) if (GetMonData(&gEnemyParty[j], MON_DATA_HP) != 0 && GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_EGG - && GetMonData(&gEnemyParty[j], MON_DATA_IS_EGG) == 0 + && !GetMonData(&gEnemyParty[j], MON_DATA_IS_EGG) && gBattlerPartyIndexes[i - 2] != j) { gBattlerPartyIndexes[i] = j; @@ -913,7 +912,8 @@ void BtlController_EmitGetMonData(u8 bufferId, u8 requestId, u8 monToCheck) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitGetRawMonData(u8 bufferId, u8 monId, u8 bytes) +// Unused +static void BtlController_EmitGetRawMonData(u8 bufferId, u8 monId, u8 bytes) { sBattleBuffersTransferData[0] = CONTROLLER_GETRAWMONDATA; sBattleBuffersTransferData[1] = monId; @@ -934,7 +934,8 @@ void BtlController_EmitSetMonData(u8 bufferId, u8 requestId, u8 monToCheck, u8 b PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 3 + bytes); } -void BtlController_EmitSetRawMonData(u8 bufferId, u8 monId, u8 bytes, void *data) +// Unused +static void BtlController_EmitSetRawMonData(u8 bufferId, u8 monId, u8 bytes, void *data) { s32 i; @@ -1007,7 +1008,8 @@ void BtlController_EmitFaintAnimation(u8 bufferId) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitPaletteFade(u8 bufferId) +// Unused +static void BtlController_EmitPaletteFade(u8 bufferId) { sBattleBuffersTransferData[0] = CONTROLLER_PALETTEFADE; sBattleBuffersTransferData[1] = CONTROLLER_PALETTEFADE; @@ -1016,7 +1018,8 @@ void BtlController_EmitPaletteFade(u8 bufferId) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitSuccessBallThrowAnim(u8 bufferId) +// Unused +static void BtlController_EmitSuccessBallThrowAnim(u8 bufferId) { sBattleBuffersTransferData[0] = CONTROLLER_SUCCESSBALLTHROWANIM; sBattleBuffersTransferData[1] = CONTROLLER_SUCCESSBALLTHROWANIM; @@ -1032,7 +1035,8 @@ void BtlController_EmitBallThrowAnim(u8 bufferId, u8 caseId) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); } -void BtlController_EmitPause(u8 bufferId, u8 toWait, void *data) +// Unused +static void BtlController_EmitPause(u8 bufferId, u8 toWait, void *data) { s32 i; @@ -1089,7 +1093,7 @@ void BtlController_EmitPrintString(u8 bufferId, u16 stringID) stringInfo->lastItem = gLastUsedItem; stringInfo->lastAbility = gLastUsedAbility; stringInfo->scrActive = gBattleScripting.battler; - stringInfo->unk1605E = gBattleStruct->field_52; + stringInfo->bakScriptPartyIdx = gBattleStruct->scriptPartyIdx; stringInfo->hpScale = gBattleStruct->hpScale; stringInfo->itemEffectBattler = gPotentialItemEffectBattler; stringInfo->moveType = gBattleMoves[gCurrentMove].type; @@ -1121,7 +1125,7 @@ void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringID) stringInfo->lastItem = gLastUsedItem; stringInfo->lastAbility = gLastUsedAbility; stringInfo->scrActive = gBattleScripting.battler; - stringInfo->unk1605E = gBattleStruct->field_52; + stringInfo->bakScriptPartyIdx = gBattleStruct->scriptPartyIdx; for (i = 0; i < MAX_BATTLERS_COUNT; i++) stringInfo->abilities[i] = gBattleMons[i].ability; @@ -1191,7 +1195,8 @@ void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 slotId, u8 abili PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 8); // Only 7 bytes were written. } -void BtlController_EmitCmd23(u8 bufferId) +// Unused +static void BtlController_EmitCmd23(u8 bufferId) { sBattleBuffersTransferData[0] = CONTROLLER_23; sBattleBuffersTransferData[1] = CONTROLLER_23; @@ -1245,7 +1250,8 @@ void BtlController_EmitStatusAnimation(u8 bufferId, bool8 status2, u32 status) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 6); } -void BtlController_EmitStatusXor(u8 bufferId, u8 b) +// Unused +static void BtlController_EmitStatusXor(u8 bufferId, u8 b) { sBattleBuffersTransferData[0] = CONTROLLER_STATUSXOR; sBattleBuffersTransferData[1] = b; @@ -1265,7 +1271,8 @@ void BtlController_EmitDataTransfer(u8 bufferId, u16 size, void *data) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, size + 4); } -void BtlController_EmitDMA3Transfer(u8 bufferId, void *dst, u16 size, void *data) +// Unused +static void BtlController_EmitDMA3Transfer(u8 bufferId, void *dst, u16 size, void *data) { s32 i; @@ -1282,7 +1289,7 @@ void BtlController_EmitDMA3Transfer(u8 bufferId, void *dst, u16 size, void *data } // Unused -void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *data) +static void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *data) { s32 i; @@ -1297,7 +1304,8 @@ void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *data) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, songId + 3); } -void BtlController_EmitCmd32(u8 bufferId, u16 size, void *data) +// Unused +static void BtlController_EmitCmd32(u8 bufferId, u16 size, void *data) { s32 i; @@ -1347,7 +1355,8 @@ void BtlController_EmitOneReturnValue_Duplicate(u8 bufferId, u16 ret) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitClearUnkVar(u8 bufferId) +// Unused +static void BtlController_EmitClearUnkVar(u8 bufferId) { sBattleBuffersTransferData[0] = CONTROLLER_CLEARUNKVAR; sBattleBuffersTransferData[1] = CONTROLLER_CLEARUNKVAR; @@ -1356,14 +1365,16 @@ void BtlController_EmitClearUnkVar(u8 bufferId) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitSetUnkVar(u8 bufferId, u8 b) +// Unused +static void BtlController_EmitSetUnkVar(u8 bufferId, u8 b) { sBattleBuffersTransferData[0] = CONTROLLER_SETUNKVAR; sBattleBuffersTransferData[1] = b; PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); } -void BtlController_EmitClearUnkFlag(u8 bufferId) +// Unused +static void BtlController_EmitClearUnkFlag(u8 bufferId) { sBattleBuffersTransferData[0] = CONTROLLER_CLEARUNKFLAG; sBattleBuffersTransferData[1] = CONTROLLER_CLEARUNKFLAG; @@ -1372,7 +1383,8 @@ void BtlController_EmitClearUnkFlag(u8 bufferId) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitToggleUnkFlag(u8 bufferId) +// Unused +static void BtlController_EmitToggleUnkFlag(u8 bufferId) { sBattleBuffersTransferData[0] = CONTROLLER_TOGGLEUNKFLAG; sBattleBuffersTransferData[1] = CONTROLLER_TOGGLEUNKFLAG; diff --git a/src/battle_message.c b/src/battle_message.c index 677bb2fe3863..99325e9e805a 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2063,7 +2063,7 @@ void BufferStringBattle(u16 stringID) gLastUsedItem = gBattleMsgDataPtr->lastItem; gLastUsedAbility = gBattleMsgDataPtr->lastAbility; gBattleScripting.battler = gBattleMsgDataPtr->scrActive; - *(&gBattleStruct->field_52) = gBattleMsgDataPtr->unk1605E; + *(&gBattleStruct->scriptPartyIdx) = gBattleMsgDataPtr->bakScriptPartyIdx; *(&gBattleStruct->hpScale) = gBattleMsgDataPtr->hpScale; gPotentialItemEffectBattler = gBattleMsgDataPtr->itemEffectBattler; *(&gBattleStruct->stringMoveType) = gBattleMsgDataPtr->moveType; @@ -2713,7 +2713,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) } break; case B_TXT_26: // ? - HANDLE_NICKNAME_STRING_CASE(gBattleScripting.battler, *(&gBattleStruct->field_52)) + HANDLE_NICKNAME_STRING_CASE(gBattleScripting.battler, *(&gBattleStruct->scriptPartyIdx)) break; case B_TXT_PC_CREATOR_NAME: // lanette pc if (FlagGet(FLAG_SYS_PC_LANETTE)) From 11b4958f230bafa46611c7b4f04142d32d54451d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 19 Aug 2022 19:45:15 -0400 Subject: [PATCH 03/21] Incorporate commented bug fixes in contest AI scripts --- data/contest_ai_scripts.s | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/data/contest_ai_scripts.s b/data/contest_ai_scripts.s index ef4feb25ffd8..ecd3103ae2ec 100644 --- a/data/contest_ai_scripts.s +++ b/data/contest_ai_scripts.s @@ -435,11 +435,15 @@ AI_CGM_BetterWhenAudienceExcited: AI_CGM_BetterWhenAudienceExcited_1stUp: @ BUG: Should be if_appeal_num_eq 0 @ 1st up on 1st appeal excitement will always be 0 - if_appeal_num_not_eq 0, AI_CGM_BetterWhenAudienceExcited_Not1stAppeal +.ifdef BUGFIX + if_appeal_num_eq 0, AI_CGM_BetterWhenAudienceExcited_1stAppeal +.else + if_appeal_num_not_eq 0, AI_CGM_BetterWhenAudienceExcited_1stAppeal +.endif if_excitement_eq 4, AI_CGM_BetterWhenAudienceExcited_1AwayFromMax if_excitement_eq 3, AI_CGM_BetterWhenAudienceExcited_2AwayFromMax end -AI_CGM_BetterWhenAudienceExcited_Not1stAppeal: +AI_CGM_BetterWhenAudienceExcited_1stAppeal: if_random_less_than 125, AI_CGM_End score -15 end @@ -542,7 +546,11 @@ AI_CGM_TargetMonWithJudgesAttention: end AI_CGM_TargetMonWithJudgesAttention_CheckMon1: if_cannot_participate MON_1, AI_CGM_TargetMonWithJudgesAttention_CheckMon2 +.ifdef BUGFIX + if_not_used_combo_starter MON_1, AI_CGM_TargetMonWithJudgesAttention_CheckMon2 +.else if_used_combo_starter MON_1, AI_CGM_TargetMonWithJudgesAttention_CheckMon2 +.endif if_random_less_than 125, AI_CGM_TargetMonWithJudgesAttention_CheckMon2 score +2 if_not_completed_combo MON_1, AI_CGM_TargetMonWithJudgesAttention_CheckMon2 @@ -551,7 +559,11 @@ AI_CGM_TargetMonWithJudgesAttention_CheckMon1: AI_CGM_TargetMonWithJudgesAttention_CheckMon2: if_user_order_eq MON_2, AI_CGM_End if_cannot_participate MON_2, AI_CGM_TargetMonWithJudgesAttention_CheckMon3 +.ifdef BUGFIX + if_not_used_combo_starter MON_2, AI_CGM_TargetMonWithJudgesAttention_CheckMon3 +.else if_used_combo_starter MON_2, AI_CGM_TargetMonWithJudgesAttention_CheckMon3 +.endif if_random_less_than 125, AI_CGM_TargetMonWithJudgesAttention_CheckMon3 score +2 if_not_completed_combo MON_2, AI_CGM_TargetMonWithJudgesAttention_CheckMon3 @@ -560,7 +572,11 @@ AI_CGM_TargetMonWithJudgesAttention_CheckMon2: AI_CGM_TargetMonWithJudgesAttention_CheckMon3: if_user_order_eq MON_3, AI_CGM_End if_cannot_participate MON_3, AI_CGM_End +.ifdef BUGFIX + if_not_used_combo_starter MON_3, AI_CGM_End +.else if_used_combo_starter MON_3, AI_CGM_End +.endif if_random_less_than 125, AI_CGM_End score +2 if_not_completed_combo MON_3, AI_CGM_End From 261b0ff118bc24e7d6353180d1bdac3f3942ef48 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 20 Aug 2022 22:58:46 -0400 Subject: [PATCH 04/21] Standardize judgement vs judgment spelling --- ...symbols.png => arena_judgment_symbols.png} | Bin include/battle_message.h | 2 +- include/constants/battle.h | 4 +- include/graphics.h | 4 +- src/battle_arena.c | 66 +++++++++--------- src/battle_bg.c | 4 +- src/battle_message.c | 10 +-- src/battle_script_commands.c | 6 +- src/graphics.c | 4 +- 9 files changed, 50 insertions(+), 50 deletions(-) rename graphics/battle_frontier/{arena_judgement_symbols.png => arena_judgment_symbols.png} (100%) diff --git a/graphics/battle_frontier/arena_judgement_symbols.png b/graphics/battle_frontier/arena_judgment_symbols.png similarity index 100% rename from graphics/battle_frontier/arena_judgement_symbols.png rename to graphics/battle_frontier/arena_judgment_symbols.png diff --git a/include/battle_message.h b/include/battle_message.h index cc18a13d220b..1ced84f50afe 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -283,7 +283,7 @@ extern const u8 gText_OpponentMon1Name[]; extern const u8 gText_Mind[]; extern const u8 gText_Skill[]; extern const u8 gText_Body[]; -extern const u8 gText_Judgement[]; +extern const u8 gText_Judgment[]; extern const u8 gText_EmptyString3[]; extern const u8 gText_RecordBattleToPass[]; extern const u8 gText_BattleRecordedOnPass[]; diff --git a/include/constants/battle.h b/include/constants/battle.h index 41bdb7a883c5..3eec42f15c14 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -357,8 +357,8 @@ #define ARENA_WIN_MIND 18 #define ARENA_WIN_SKILL 19 #define ARENA_WIN_BODY 20 -#define ARENA_WIN_JUDGEMENT_TITLE 21 -#define ARENA_WIN_JUDGEMENT_TEXT 22 +#define ARENA_WIN_JUDGMENT_TITLE 21 +#define ARENA_WIN_JUDGMENT_TEXT 22 // Flag for BattlePutTextOnWindow. Never set #define B_WIN_COPYTOVRAM (1 << 7) diff --git a/include/graphics.h b/include/graphics.h index 08a2a1c4215c..8bdc85dc4a24 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4138,8 +4138,8 @@ extern const u16 gTilesetAnims_BattleDomePals0_1[]; extern const u16 gTilesetAnims_BattleDomePals0_2[]; extern const u16 gTilesetAnims_BattleDomePals0_3[]; -extern const u32 gBattleArenaJudgementSymbolsGfx[]; -extern const u32 gBattleArenaJudgementSymbolsPalette[]; +extern const u32 gBattleArenaJudgmentSymbolsGfx[]; +extern const u32 gBattleArenaJudgmentSymbolsPalette[]; extern const u32 gBattleWindowTextPalette[]; diff --git a/src/battle_arena.c b/src/battle_arena.c index 79d7d50297d4..cdd1843d7097 100644 --- a/src/battle_arena.c +++ b/src/battle_arena.c @@ -38,9 +38,9 @@ static void BufferArenaOpponentName(void); static void SpriteCB_JudgmentIcon(struct Sprite *sprite); static void ShowJudgmentSprite(u8 x, u8 y, u8 category, u8 battler); -#define JUDGEMENT_STATE_FINISHED 8 +#define JUDGMENT_STATE_FINISHED 8 -#define TAG_JUDGEMENT_ICON 1000 +#define TAG_JUDGMENT_ICON 1000 enum { ANIM_ICON_X, // Player lost @@ -275,7 +275,7 @@ static const s8 sMindRatings[MOVES_COUNT] = [MOVE_PSYCHO_BOOST] = 1, }; -static const struct OamData sOam_JudgementIcon = +static const struct OamData sOam_JudgmentIcon = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -292,52 +292,52 @@ static const struct OamData sOam_JudgementIcon = .affineParam = 0 }; -static const union AnimCmd sAnim_JudgementIcon_X[] = +static const union AnimCmd sAnim_JudgmentIcon_X[] = { ANIMCMD_FRAME(0, 1), ANIMCMD_END }; -static const union AnimCmd sAnim_JudgementIcon_Triangle[] = +static const union AnimCmd sAnim_JudgmentIcon_Triangle[] = { ANIMCMD_FRAME(4, 1), ANIMCMD_END }; -static const union AnimCmd sAnim_JudgementIcon_Circle[] = +static const union AnimCmd sAnim_JudgmentIcon_Circle[] = { ANIMCMD_FRAME(8, 1), ANIMCMD_END }; -static const union AnimCmd sAnim_JudgementIcon_Line[] = +static const union AnimCmd sAnim_JudgmentIcon_Line[] = { ANIMCMD_FRAME(12, 1), ANIMCMD_END }; -static const union AnimCmd *const sAnims_JudgementIcon[] = +static const union AnimCmd *const sAnims_JudgmentIcon[] = { - [ANIM_ICON_X] = sAnim_JudgementIcon_X, - [ANIM_ICON_TRIANGLE] = sAnim_JudgementIcon_Triangle, - [ANIM_ICON_CIRCLE] = sAnim_JudgementIcon_Circle, - [ANIM_ICON_LINE] = sAnim_JudgementIcon_Line, + [ANIM_ICON_X] = sAnim_JudgmentIcon_X, + [ANIM_ICON_TRIANGLE] = sAnim_JudgmentIcon_Triangle, + [ANIM_ICON_CIRCLE] = sAnim_JudgmentIcon_Circle, + [ANIM_ICON_LINE] = sAnim_JudgmentIcon_Line, }; static const struct SpriteTemplate sSpriteTemplate_JudgmentIcon = { - .tileTag = TAG_JUDGEMENT_ICON, + .tileTag = TAG_JUDGMENT_ICON, .paletteTag = TAG_NONE, - .oam = &sOam_JudgementIcon, - .anims = sAnims_JudgementIcon, + .oam = &sOam_JudgmentIcon, + .anims = sAnims_JudgmentIcon, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCB_JudgmentIcon, }; -static const struct CompressedSpriteSheet sBattleArenaJudgementSymbolsSpriteSheet[] = +static const struct CompressedSpriteSheet sBattleArenaJudgmentSymbolsSpriteSheet[] = { - {gBattleArenaJudgementSymbolsGfx, 0x200, TAG_JUDGEMENT_ICON}, + {gBattleArenaJudgmentSymbolsGfx, 0x200, TAG_JUDGMENT_ICON}, {0} }; @@ -389,8 +389,8 @@ u8 BattleArena_ShowJudgmentWindow(u8 *state) case 0: BeginNormalPaletteFade(0x7FFFFF1C, 4, 0, 8, RGB_BLACK); SetGpuReg(REG_OFFSET_WININ, (WININ_WIN0_ALL & ~WININ_WIN0_BG0) | WININ_WIN1_ALL); - LoadCompressedSpriteSheet(sBattleArenaJudgementSymbolsSpriteSheet); - LoadCompressedPalette(gBattleArenaJudgementSymbolsPalette, 0x1F0, 0x20); + LoadCompressedSpriteSheet(sBattleArenaJudgmentSymbolsSpriteSheet); + LoadCompressedPalette(gBattleArenaJudgmentSymbolsPalette, 0x1F0, 0x20); gBattle_WIN0H = 0xFF; gBattle_WIN0V = 0x70; (*state)++; @@ -417,8 +417,8 @@ u8 BattleArena_ShowJudgmentWindow(u8 *state) BattlePutTextOnWindow(gText_Mind, ARENA_WIN_MIND); BattlePutTextOnWindow(gText_Skill, ARENA_WIN_SKILL); BattlePutTextOnWindow(gText_Body, ARENA_WIN_BODY); - BattleStringExpandPlaceholdersToDisplayedString(gText_Judgement); - BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGEMENT_TITLE); + BattleStringExpandPlaceholdersToDisplayedString(gText_Judgment); + BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGMENT_TITLE); (*state)++; } break; @@ -441,8 +441,8 @@ u8 BattleArena_ShowJudgmentWindow(u8 *state) PlaySE(SE_ARENA_TIMEUP1); ShowJudgmentSprite(80, 40, ARENA_CATEGORY_MIND, B_POSITION_PLAYER_LEFT); ShowJudgmentSprite(160, 40, ARENA_CATEGORY_MIND, B_POSITION_OPPONENT_LEFT); - BattleStringExpandPlaceholdersToDisplayedString(gText_Judgement); - BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGEMENT_TITLE); + BattleStringExpandPlaceholdersToDisplayedString(gText_Judgment); + BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGMENT_TITLE); (*state)++; result = ARENA_RESULT_STEP_DONE; break; @@ -450,8 +450,8 @@ u8 BattleArena_ShowJudgmentWindow(u8 *state) PlaySE(SE_ARENA_TIMEUP1); ShowJudgmentSprite(80, 56, ARENA_CATEGORY_SKILL, B_POSITION_PLAYER_LEFT); ShowJudgmentSprite(160, 56, ARENA_CATEGORY_SKILL, B_POSITION_OPPONENT_LEFT); - BattleStringExpandPlaceholdersToDisplayedString(gText_Judgement); - BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGEMENT_TITLE); + BattleStringExpandPlaceholdersToDisplayedString(gText_Judgment); + BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGMENT_TITLE); (*state)++; result = ARENA_RESULT_STEP_DONE; break; @@ -459,8 +459,8 @@ u8 BattleArena_ShowJudgmentWindow(u8 *state) PlaySE(SE_ARENA_TIMEUP1); ShowJudgmentSprite(80, 72, ARENA_CATEGORY_BODY, B_POSITION_PLAYER_LEFT); ShowJudgmentSprite(160, 72, ARENA_CATEGORY_BODY, B_POSITION_OPPONENT_LEFT); - BattleStringExpandPlaceholdersToDisplayedString(gText_Judgement); - BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGEMENT_TITLE); + BattleStringExpandPlaceholdersToDisplayedString(gText_Judgment); + BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGMENT_TITLE); (*state)++; result = ARENA_RESULT_STEP_DONE; break; @@ -482,11 +482,11 @@ u8 BattleArena_ShowJudgmentWindow(u8 *state) } (*state)++; break; - case JUDGEMENT_STATE_FINISHED: - // Finishing this state is the indicator to SpriteCB_JudgmentIcon that its safe to destroy the judgement icon sprites + case JUDGMENT_STATE_FINISHED: + // Finishing this state is the indicator to SpriteCB_JudgmentIcon that its safe to destroy the judgment icon sprites (*state)++; break; - case JUDGEMENT_STATE_FINISHED + 1: + case JUDGMENT_STATE_FINISHED + 1: SetGpuReg(REG_OFFSET_WININ, (WININ_WIN0_ALL & ~WININ_WIN0_BG0) | WININ_WIN1_ALL); HandleBattleWindow(5, 0, 24, 13, WINDOW_CLEAR); CopyBgTilemapBufferToVram(0); @@ -494,11 +494,11 @@ u8 BattleArena_ShowJudgmentWindow(u8 *state) BeginNormalPaletteFade(0x7FFFFF1C, 4, 8, 0, RGB_BLACK); (*state)++; break; - case JUDGEMENT_STATE_FINISHED + 2: + case JUDGMENT_STATE_FINISHED + 2: if (!gPaletteFade.active) { SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_ALL | WININ_WIN1_ALL); - FreeSpriteTilesByTag(TAG_JUDGEMENT_ICON); + FreeSpriteTilesByTag(TAG_JUDGMENT_ICON); result = ARENA_RESULT_STEP_DONE; (*state)++; } @@ -562,7 +562,7 @@ static void ShowJudgmentSprite(u8 x, u8 y, u8 category, u8 battler) static void SpriteCB_JudgmentIcon(struct Sprite *sprite) { - if (gBattleCommunication[0] > JUDGEMENT_STATE_FINISHED) + if (gBattleCommunication[0] > JUDGMENT_STATE_FINISHED) DestroySprite(sprite); } diff --git a/src/battle_bg.c b/src/battle_bg.c index ace4ea24fa11..8bbe18ab2807 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -571,7 +571,7 @@ static const struct WindowTemplate sBattleArenaWindowTemplates[] = .paletteNum = 5, .baseBlock = 0x013c, }, - [ARENA_WIN_JUDGEMENT_TITLE] = { + [ARENA_WIN_JUDGMENT_TITLE] = { .bg = 0, .tilemapLeft = 8, .tilemapTop = 11, @@ -580,7 +580,7 @@ static const struct WindowTemplate sBattleArenaWindowTemplates[] = .paletteNum = 5, .baseBlock = 0x0148, }, - [ARENA_WIN_JUDGEMENT_TEXT] = { + [ARENA_WIN_JUDGMENT_TEXT] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 15, diff --git a/src/battle_message.c b/src/battle_message.c index 677bb2fe3863..fa2fedd85b8d 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -1371,7 +1371,7 @@ const u8 gText_OpponentMon1Name[] = _("{B_OPPONENT_MON1_NAME}"); const u8 gText_Mind[] = _("Mind"); const u8 gText_Skill[] = _("Skill"); const u8 gText_Body[] = _("Body"); -const u8 gText_Judgement[] = _("{B_BUFF1}{CLEAR 13}Judgment{CLEAR 13}{B_BUFF2}"); +const u8 gText_Judgment[] = _("{B_BUFF1}{CLEAR 13}Judgment{CLEAR 13}{B_BUFF2}"); static const u8 sText_TwoTrainersSentPkmn[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME} sent\nout {B_OPPONENT_MON1_NAME}!\p{B_TRAINER2_CLASS} {B_TRAINER2_NAME} sent\nout {B_OPPONENT_MON2_NAME}!"); static const u8 sText_Trainer2SentOutPkmn[] = _("{B_TRAINER2_CLASS} {B_TRAINER2_NAME} sent\nout {B_BUFF1}!"); static const u8 sText_TwoTrainersWantToBattle[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME} and\n{B_TRAINER2_CLASS} {B_TRAINER2_NAME}\lwant to battle!\p"); @@ -2020,7 +2020,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .bgColor = TEXT_DYNAMIC_COLOR_5, .shadowColor = TEXT_DYNAMIC_COLOR_6, }, - [ARENA_WIN_JUDGEMENT_TITLE] = { + [ARENA_WIN_JUDGMENT_TITLE] = { .fillValue = PIXEL_FILL(0xE), .fontId = FONT_NORMAL, .x = -1, @@ -2032,7 +2032,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .bgColor = TEXT_DYNAMIC_COLOR_5, .shadowColor = TEXT_DYNAMIC_COLOR_6, }, - [ARENA_WIN_JUDGEMENT_TEXT] = { + [ARENA_WIN_JUDGMENT_TEXT] = { .fillValue = PIXEL_FILL(0x1), .fontId = FONT_NORMAL, .x = 0, @@ -3081,7 +3081,7 @@ void BattlePutTextOnWindow(const u8 *text, u8 windowId) printerTemplate.x = printerTemplate.currentX = alignX; } - if (windowId == ARENA_WIN_JUDGEMENT_TEXT) + if (windowId == ARENA_WIN_JUDGMENT_TEXT) gTextFlags.useAlternateDownArrow = FALSE; else gTextFlags.useAlternateDownArrow = TRUE; @@ -3091,7 +3091,7 @@ void BattlePutTextOnWindow(const u8 *text, u8 windowId) else gTextFlags.autoScroll = FALSE; - if (windowId == B_WIN_MSG || windowId == ARENA_WIN_JUDGEMENT_TEXT) + if (windowId == B_WIN_MSG || windowId == ARENA_WIN_JUDGMENT_TEXT) { if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK)) speed = 1; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 7c009e0775b5..e4c22000d661 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5226,7 +5226,7 @@ static void Cmd_switchineffects(void) else { // There is a hack here to ensure the truant counter will be 0 when the battler's next turn starts. - // The truant counter is not updated in the case where a mon switches in after a lost judgement in the battle arena. + // The truant counter is not updated in the case where a mon switches in after a lost judgment in the battle arena. if (gBattleMons[gActiveBattler].ability == ABILITY_TRUANT && !gDisableStructs[gActiveBattler].truantSwitchInHack) gDisableStructs[gActiveBattler].truantCounter = 1; @@ -6412,10 +6412,10 @@ static void Cmd_various(void) break; case VARIOUS_ARENA_JUDGMENT_STRING: BattleStringExpandPlaceholdersToDisplayedString(gRefereeStringsTable[gBattlescriptCurrInstr[1]]); - BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGEMENT_TEXT); + BattlePutTextOnWindow(gDisplayedStringBattle, ARENA_WIN_JUDGMENT_TEXT); break; case VARIOUS_ARENA_WAIT_STRING: - if (IsTextPrinterActive(ARENA_WIN_JUDGEMENT_TEXT)) + if (IsTextPrinterActive(ARENA_WIN_JUDGMENT_TEXT)) return; break; case VARIOUS_WAIT_CRY: diff --git a/src/graphics.c b/src/graphics.c index eb798433df01..06007d759b97 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -963,8 +963,8 @@ const u32 gDomeTourneyTree_Pal[] = INCBIN_U32("graphics/battle_frontier/tourney. const u32 gDomeTourneyTreeButtons_Pal[] = INCBIN_U32("graphics/battle_frontier/tourney_buttons.gbapal.lz"); const u32 gDomeTourneyMatchCardBg_Pal[] = INCBIN_U32("graphics/battle_frontier/tourney_match_card_bg.gbapal.lz"); -const u32 gBattleArenaJudgementSymbolsGfx[] = INCBIN_U32("graphics/battle_frontier/arena_judgement_symbols.4bpp.lz"); -const u32 gBattleArenaJudgementSymbolsPalette[] = INCBIN_U32("graphics/battle_frontier/arena_judgement_symbols.gbapal.lz"); +const u32 gBattleArenaJudgmentSymbolsGfx[] = INCBIN_U32("graphics/battle_frontier/arena_judgment_symbols.4bpp.lz"); +const u32 gBattleArenaJudgmentSymbolsPalette[] = INCBIN_U32("graphics/battle_frontier/arena_judgment_symbols.gbapal.lz"); const u32 gBattleWindowTextPalette[] = INCBIN_U32("graphics/battle_interface/text.gbapal.lz"); const u16 gPPTextPalette[] = INCBIN_U16("graphics/battle_interface/text_pp.gbapal"); From 481210b7f318ee4811a4193216d77c3eefadf848 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Aug 2022 00:54:30 -0400 Subject: [PATCH 05/21] Missing uses of MAX_SPRITES --- src/battle_anim_ice.c | 2 +- src/battle_anim_psychic.c | 2 +- src/intro.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/battle_anim_ice.c b/src/battle_anim_ice.c index 6a0ff1154acc..c974ecf661ca 100644 --- a/src/battle_anim_ice.c +++ b/src/battle_anim_ice.c @@ -1454,7 +1454,7 @@ static void AnimHailBegin(struct Sprite *sprite) sprite->data[3], sprite->data[4], sprite->subpriority); sprite->data[0] = spriteId; - if (spriteId != 64) + if (spriteId != MAX_SPRITES) { gSprites[sprite->data[0]].callback = AnimHailContinue; gSprites[sprite->data[0]].data[6] = sprite->data[6]; diff --git a/src/battle_anim_psychic.c b/src/battle_anim_psychic.c index aebf76cc0659..833c46c2f33f 100644 --- a/src/battle_anim_psychic.c +++ b/src/battle_anim_psychic.c @@ -918,7 +918,7 @@ static void AnimTask_SkillSwap_Step(u8 taskId) { task->data[1] = 0; spriteId = CreateSprite(&gSkillSwapOrbSpriteTemplate, task->data[11], task->data[12], 0); - if (spriteId != 64) + if (spriteId != MAX_SPRITES) { gSprites[spriteId].data[0] = 16; gSprites[spriteId].data[2] = task->data[13]; diff --git a/src/intro.c b/src/intro.c index 7e9a751690ee..b067891429fb 100644 --- a/src/intro.c +++ b/src/intro.c @@ -2933,7 +2933,7 @@ static void SpriteCB_WaterDrop_ReachLeafEnd(struct Sprite *sprite) SetOamMatrix(sprite->data[1], sprite->data[6] + 64, 0, 0, sprite->data[6] + 64); SetOamMatrix(sprite->data[1] + 1, sprite->data[6] + 64, 0, 0, sprite->data[6] + 64); SetOamMatrix(sprite->data[1] + 2, sprite->data[6] + 64, 0, 0, sprite->data[6] + 64); - if (sprite->data[4] != 64) + if (sprite->data[4] != MAX_SPRITES) { u16 sinIdx; sprite->data[4] -= 8; From 6c457f42afb948c3697f03d92ee9042dab8e4b5b Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Aug 2022 00:59:12 -0400 Subject: [PATCH 06/21] Corrected uses of GetBattlerSide --- src/battle_anim_bug.c | 6 +++--- src/battle_anim_fire.c | 2 +- src/battle_anim_flying.c | 4 ++-- src/battle_anim_mon_movement.c | 4 ++-- src/battle_anim_mons.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/battle_anim_bug.c b/src/battle_anim_bug.c index 14abc88fb3c1..377665684a0c 100644 --- a/src/battle_anim_bug.c +++ b/src/battle_anim_bug.c @@ -203,7 +203,7 @@ static void AnimMegahornHorn(struct Sprite *sprite) gBattleAnimArgs[2] = -gBattleAnimArgs[2]; gBattleAnimArgs[0] = -gBattleAnimArgs[0]; } - else if (!GetBattlerSide(gBattleAnimTarget)) + else if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) { StartSpriteAffineAnim(sprite, 1); gBattleAnimArgs[1] = -gBattleAnimArgs[1]; @@ -230,7 +230,7 @@ static void AnimLeechLifeNeedle(struct Sprite *sprite) gBattleAnimArgs[0] = -gBattleAnimArgs[0]; StartSpriteAffineAnim(sprite, 2); } - else if (!GetBattlerSide(gBattleAnimTarget)) + else if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) { gBattleAnimArgs[1] = -gBattleAnimArgs[1]; gBattleAnimArgs[0] = -gBattleAnimArgs[0]; @@ -301,7 +301,7 @@ static void AnimStringWrap(struct Sprite *sprite) sprite->x += gBattleAnimArgs[0]; sprite->y += gBattleAnimArgs[1]; - if (!GetBattlerSide(gBattleAnimTarget)) + if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) sprite->y += 8; sprite->callback = AnimStringWrap_Step; diff --git a/src/battle_anim_fire.c b/src/battle_anim_fire.c index 72d802f19ae1..2ac00f443ba7 100644 --- a/src/battle_anim_fire.c +++ b/src/battle_anim_fire.c @@ -926,7 +926,7 @@ static void CreateEruptionLaunchRocks(u8 spriteId, u8 taskId, u8 activeSpritesId u16 y = GetEruptionLaunchRockInitialYPos(spriteId); u16 x = gSprites[spriteId].x; - if(!GetBattlerSide(gBattleAnimAttacker)) + if(GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) { x -= 12; sign = 1; diff --git a/src/battle_anim_flying.c b/src/battle_anim_flying.c index 8609a8e172f2..746e3bdd7365 100644 --- a/src/battle_anim_flying.c +++ b/src/battle_anim_flying.c @@ -910,8 +910,8 @@ static void AnimWhirlwindLine(struct Sprite * sprite) else InitSpritePosToAnimTarget(sprite, FALSE); - if ((gBattleAnimArgs[2] == ANIM_ATTACKER && !GetBattlerSide(gBattleAnimAttacker)) - || (gBattleAnimArgs[2] == ANIM_TARGET && !GetBattlerSide(gBattleAnimTarget))) + if ((gBattleAnimArgs[2] == ANIM_ATTACKER && GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + || (gBattleAnimArgs[2] == ANIM_TARGET && GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER)) { sprite->x += 8; } diff --git a/src/battle_anim_mon_movement.c b/src/battle_anim_mon_movement.c index 09393a2a7b9f..8a11c2c5b572 100644 --- a/src/battle_anim_mon_movement.c +++ b/src/battle_anim_mon_movement.c @@ -885,11 +885,11 @@ void AnimTask_RotateMonSpriteToSide(u8 taskId) { if (gBattleAnimArgs[2] == ANIM_ATTACKER) { - gTasks[taskId].data[7] = !GetBattlerSide(gBattleAnimAttacker); + gTasks[taskId].data[7] = GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER; } else { - gTasks[taskId].data[7] = !GetBattlerSide(gBattleAnimTarget); + gTasks[taskId].data[7] = GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER; } } if (gTasks[taskId].data[7]) diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c index 4ce33251ac6f..f8fc5647eaac 100644 --- a/src/battle_anim_mons.c +++ b/src/battle_anim_mons.c @@ -2519,7 +2519,7 @@ void AnimWeatherBallUp(struct Sprite *sprite) { sprite->x = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X_2); sprite->y = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_Y_PIC_OFFSET); - if (!GetBattlerSide(gBattleAnimAttacker)) + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) sprite->data[0] = 5; else sprite->data[0] = -10; @@ -2545,7 +2545,7 @@ void AnimWeatherBallDown(struct Sprite *sprite) sprite->data[0] = gBattleAnimArgs[2]; sprite->data[2] = sprite->x + gBattleAnimArgs[4]; sprite->data[4] = sprite->y + gBattleAnimArgs[5]; - if (!GetBattlerSide(gBattleAnimTarget)) + if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) { x = (u16)gBattleAnimArgs[4] + 30; sprite->x += x; From 15d611ba65eb5f6f7c0fde16ee487f3650bbf017 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Aug 2022 01:26:13 -0400 Subject: [PATCH 07/21] Usage of BATTLE_PARTNER --- include/constants/battle.h | 4 +-- src/battle_ai_script_commands.c | 12 +++---- src/battle_ai_switch_items.c | 10 +++--- src/battle_anim.c | 8 ++--- src/battle_anim_dark.c | 4 +-- src/battle_anim_fire.c | 2 +- src/battle_anim_ghost.c | 2 +- src/battle_anim_psychic.c | 2 +- src/battle_controller_link_partner.c | 12 +++---- src/battle_controller_opponent.c | 40 +++++++++++------------ src/battle_controller_player.c | 40 +++++++++++------------ src/battle_controller_player_partner.c | 20 ++++++------ src/battle_controller_recorded_opponent.c | 34 +++++++++---------- src/battle_controller_recorded_player.c | 30 ++++++++--------- src/battle_controller_wally.c | 22 ++++++------- src/battle_gfx_sfx_util.c | 6 ++-- src/battle_main.c | 8 ++--- src/battle_script_commands.c | 28 ++++++++-------- src/battle_util.c | 12 +++---- 19 files changed, 148 insertions(+), 148 deletions(-) diff --git a/include/constants/battle.h b/include/constants/battle.h index 41bdb7a883c5..9adeeea91612 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -31,8 +31,8 @@ #define B_POSITION_OPPONENT_RIGHT 3 // These macros can be used with either battler ID or positions to get the partner or the opposite mon -#define BATTLE_OPPOSITE(id) ((id) ^ 1) -#define BATTLE_PARTNER(id) ((id) ^ 2) +#define BATTLE_OPPOSITE(id) ((id) ^ BIT_SIDE) +#define BATTLE_PARTNER(id) ((id) ^ BIT_FLANK) #define B_SIDE_PLAYER 0 #define B_SIDE_OPPONENT 1 diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index e9f55bd8bc9f..93e4768379c3 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -541,7 +541,7 @@ static u8 ChooseMoveOrAction_Doubles(void) bestMovePointsForTarget[i] = mostViableMovesScores[0]; // Don't use a move against ally if it has less than 100 points. - if (i == (sBattler_AI ^ BIT_FLANK) && bestMovePointsForTarget[i] < 100) + if (i == (BATTLE_PARTNER(sBattler_AI)) && bestMovePointsForTarget[i] < 100) { bestMovePointsForTarget[i] = -1; mostViableMovesScores[0] = mostViableMovesScores[0]; // Needed to match. @@ -1151,9 +1151,9 @@ static u8 BattleAI_GetWantedBattler(u8 wantedBattler) default: return gBattlerTarget; case AI_USER_PARTNER: - return sBattler_AI ^ BIT_FLANK; + return BATTLE_PARTNER(sBattler_AI); case AI_TARGET_PARTNER: - return gBattlerTarget ^ BIT_FLANK; + return BATTLE_PARTNER(gBattlerTarget); } } @@ -1316,7 +1316,7 @@ static void Cmd_count_usable_party_mons(void) { u32 position; battlerOnField1 = gBattlerPartyIndexes[battlerId]; - position = GetBattlerPosition(battlerId) ^ BIT_FLANK; + position = BATTLE_PARTNER(GetBattlerPosition(battlerId)); battlerOnField2 = gBattlerPartyIndexes[GetBattlerAtPosition(position)]; } else // In singles there's only one battlerId by side. @@ -1799,7 +1799,7 @@ static void Cmd_if_has_move(void) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); break; case AI_USER_PARTNER: - if (gBattleMons[sBattler_AI ^ BIT_FLANK].hp == 0) + if (gBattleMons[BATTLE_PARTNER(sBattler_AI)].hp == 0) { gAIScriptPtr += 8; break; @@ -1808,7 +1808,7 @@ static void Cmd_if_has_move(void) { for (i = 0; i < MAX_MON_MOVES; i++) { - if (gBattleMons[sBattler_AI ^ BIT_FLANK].moves[i] == *movePtr) + if (gBattleMons[BATTLE_PARTNER(sBattler_AI)].moves[i] == *movePtr) break; } } diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 169fa5f4f6b7..736dfa9d4814 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -458,10 +458,10 @@ static bool8 ShouldSwitch(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { battlerIn1 = *activeBattlerPtr; - if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(GetBattlerPosition(*activeBattlerPtr) ^ BIT_FLANK)]) + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(*activeBattlerPtr)))]) battlerIn2 = *activeBattlerPtr; else - battlerIn2 = GetBattlerAtPosition(GetBattlerPosition(*activeBattlerPtr) ^ BIT_FLANK); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(*activeBattlerPtr))); } else { @@ -557,7 +557,7 @@ void AI_TrySwitchOrUseItem(void) else { battlerIn1 = GetBattlerAtPosition(battlerIdentity); - battlerIn2 = GetBattlerAtPosition(battlerIdentity ^ BIT_FLANK); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(battlerIdentity)); } if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_TOWER_LINK_MULTI)) @@ -653,10 +653,10 @@ u8 GetMostSuitableMonToSwitchInto(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { battlerIn1 = gActiveBattler; - if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_FLANK)]) + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) battlerIn2 = gActiveBattler; else - battlerIn2 = GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_FLANK); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); // UB: It considers the opponent only player's side even though it can battle alongside player. opposingBattler = Random() & BIT_FLANK; diff --git a/src/battle_anim.c b/src/battle_anim.c index 375363212bc7..255028eda352 100644 --- a/src/battle_anim.c +++ b/src/battle_anim.c @@ -883,7 +883,7 @@ static void Cmd_clearmonbg(void) if (sMonAnimTaskIdArray[0] != TASK_NONE) gSprites[gBattlerSpriteIds[battlerId]].invisible = FALSE; if (animBattlerId > 1 && sMonAnimTaskIdArray[1] != TASK_NONE) - gSprites[gBattlerSpriteIds[battlerId ^ BIT_FLANK]].invisible = FALSE; + gSprites[gBattlerSpriteIds[BATTLE_PARTNER(battlerId)]].invisible = FALSE; else animBattlerId = 0; @@ -990,8 +990,8 @@ static void Cmd_clearmonbg_static(void) if (IsBattlerSpriteVisible(battlerId)) gSprites[gBattlerSpriteIds[battlerId]].invisible = FALSE; - if (animBattlerId > 1 && IsBattlerSpriteVisible(battlerId ^ BIT_FLANK)) - gSprites[gBattlerSpriteIds[battlerId ^ BIT_FLANK]].invisible = FALSE; + if (animBattlerId > 1 && IsBattlerSpriteVisible(BATTLE_PARTNER(battlerId))) + gSprites[gBattlerSpriteIds[BATTLE_PARTNER(battlerId)]].invisible = FALSE; else animBattlerId = 0; @@ -1017,7 +1017,7 @@ static void Task_ClearMonBgStatic(u8 taskId) if (IsBattlerSpriteVisible(battlerId)) ResetBattleAnimBg(toBG_2); - if (gTasks[taskId].data[0] > 1 && IsBattlerSpriteVisible(battlerId ^ BIT_FLANK)) + if (gTasks[taskId].data[0] > 1 && IsBattlerSpriteVisible(BATTLE_PARTNER(battlerId))) ResetBattleAnimBg(toBG_2 ^ 1); DestroyTask(taskId); diff --git a/src/battle_anim_dark.c b/src/battle_anim_dark.c index 1281ccc8b47e..b7b98a32882a 100644 --- a/src/battle_anim_dark.c +++ b/src/battle_anim_dark.c @@ -777,8 +777,8 @@ void AnimTask_InitMementoShadow(u8 taskId) if (IsBattlerSpriteVisible(BATTLE_PARTNER(gBattleAnimAttacker))) { - MoveBattlerSpriteToBG(gBattleAnimAttacker ^ 2, toBG2 ^ 1, TRUE); - gSprites[gBattlerSpriteIds[gBattleAnimAttacker ^ 2]].invisible = FALSE; + MoveBattlerSpriteToBG(BATTLE_PARTNER(gBattleAnimAttacker), toBG2 ^ 1, TRUE); + gSprites[gBattlerSpriteIds[BATTLE_PARTNER(gBattleAnimAttacker)]].invisible = FALSE; } DestroyAnimVisualTask(taskId); diff --git a/src/battle_anim_fire.c b/src/battle_anim_fire.c index 2ac00f443ba7..fedd4c919f4c 100644 --- a/src/battle_anim_fire.c +++ b/src/battle_anim_fire.c @@ -1228,7 +1228,7 @@ void AnimTask_MoveHeatWaveTargets(u8 taskId) struct Task *task = &gTasks[taskId]; task->data[12] = GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER ? 1 : -1; - task->data[13] = IsBattlerSpriteVisible(gBattleAnimTarget ^ BIT_FLANK) + 1; + task->data[13] = IsBattlerSpriteVisible(BATTLE_PARTNER(gBattleAnimTarget)) + 1; task->data[14] = GetAnimBattlerSpriteId(ANIM_TARGET); task->data[15] = GetAnimBattlerSpriteId(ANIM_DEF_PARTNER); diff --git a/src/battle_anim_ghost.c b/src/battle_anim_ghost.c index 819b60969bce..792c1ecaf1a8 100644 --- a/src/battle_anim_ghost.c +++ b/src/battle_anim_ghost.c @@ -814,7 +814,7 @@ void AnimTask_DestinyBondWhiteShadow(u8 taskId) for (battler = 0; battler < MAX_BATTLERS_COUNT; battler++) { if (battler != gBattleAnimAttacker - && battler != (gBattleAnimAttacker ^ 2) + && battler != BATTLE_PARTNER(gBattleAnimAttacker) && IsBattlerSpriteVisible(battler)) { spriteId = CreateSprite(&gDestinyBondWhiteShadowSpriteTemplate, baseX, baseY, 55); diff --git a/src/battle_anim_psychic.c b/src/battle_anim_psychic.c index 66b895c4a609..978d14c4cdc9 100644 --- a/src/battle_anim_psychic.c +++ b/src/battle_anim_psychic.c @@ -570,7 +570,7 @@ static void AnimDefensiveWall_Step5(struct Sprite *sprite) if (IsBattlerSpriteVisible(battler)) ResetBattleAnimBg(toBG2); - battler = battlerCopy ^ 2; + battler = BATTLE_PARTNER(battlerCopy); if (IsBattlerSpriteVisible(battler)) ResetBattleAnimBg(toBG2 ^ var0); } diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index c072ae12ff61..5024faaa9d28 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -217,7 +217,7 @@ static void Intro_WaitForHealthbox(void) else { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) { finished = TRUE; } @@ -236,7 +236,7 @@ static void Intro_WaitForHealthbox(void) static void Intro_ShowHealthbox(void) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive && gSprites[gBattleControllerData[gActiveBattler]].callback == SpriteCallbackDummy && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy && ++gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay != 1) @@ -245,10 +245,10 @@ static void Intro_ShowHealthbox(void) if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - DestroySprite(&gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]]); - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], HEALTHBOX_ALL); - StartHealthboxSlideIn(gActiveBattler ^ BIT_FLANK); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]); + DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); + StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]); } DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 641cbd0ace4a..4c274f17e360 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -234,25 +234,25 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) else { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) healthboxAnimDone = TRUE; twoMons = TRUE; } gBattleControllerOpponentHealthboxData = &gBattleSpritesDataPtr->healthBoxesData[gActiveBattler]; - gBattleControllerOpponentFlankHealthboxData = &gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK]; + gBattleControllerOpponentFlankHealthboxData = &gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)]; if (healthboxAnimDone) { if (twoMons == TRUE) { if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim - && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim) + && gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim = FALSE; FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); } @@ -263,8 +263,8 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) { if (GetBattlerPosition(gActiveBattler) == 3) { - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim) + if (!gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim) { FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); @@ -296,20 +296,20 @@ static void Intro_TryShinyAnimShowHealthbox(void) if (!(gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI) && IsDoubleBattle() - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim) - TryShinyAnimation(gActiveBattler ^ BIT_FLANK, &gEnemyParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]]); + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim) + TryShinyAnimation(BATTLE_PARTNER(gActiveBattler), &gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]]); - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive) + if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK], &gEnemyParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], HEALTHBOX_ALL); - StartHealthboxSlideIn(gActiveBattler ^ BIT_FLANK); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]); + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); + StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]); } UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_ALL); StartHealthboxSlideIn(gActiveBattler); @@ -320,7 +320,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].waitForCry && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].waitForCry + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].waitForCry && !IsCryPlayingOrClearCrySongs()) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].bgmRestored) @@ -349,8 +349,8 @@ static void Intro_TryShinyAnimShowHealthbox(void) { if (gSprites[gBattleControllerData[gActiveBattler]].callback == SpriteCallbackDummy && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy - && gSprites[gBattlerSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy + && gSprites[gBattlerSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) { battlerAnimsDone = TRUE; } @@ -360,8 +360,8 @@ static void Intro_TryShinyAnimShowHealthbox(void) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - DestroySprite(&gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]]); - SetBattlerShadowSpriteCallback(gActiveBattler ^ BIT_FLANK, GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], MON_DATA_SPECIES)); + DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); + SetBattlerShadowSpriteCallback(BATTLE_PARTNER(gActiveBattler), GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], MON_DATA_SPECIES)); } DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index cf74fefbe06c..2e1f9417b8db 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -950,26 +950,26 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) else { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) healthboxAnimDone = TRUE; } // If healthbox and shiny anim are done if (healthboxAnimDone && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim - && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim) + && gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim) { // Reset shiny anim (even if it didn't occur) gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim = FALSE; FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); if (IsDoubleBattle()) - HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], gActiveBattler ^ BIT_FLANK); + HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], BATTLE_PARTNER(gActiveBattler)); gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay = 3; gBattlerControllerFuncs[gActiveBattler] = Intro_DelayAndEnd; @@ -987,21 +987,21 @@ static void Intro_TryShinyAnimShowHealthbox(void) TryShinyAnimation(gActiveBattler, &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]]); // Start shiny animation if applicable for 2nd pokemon - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive) - TryShinyAnimation(gActiveBattler ^ BIT_FLANK, &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]]); + if (!gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive) + TryShinyAnimation(BATTLE_PARTNER(gActiveBattler), &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]]); // Show healthbox after ball anim if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive) + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], HEALTHBOX_ALL); - StartHealthboxSlideIn(gActiveBattler ^ BIT_FLANK); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]); + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); + StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]); } UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_ALL); StartHealthboxSlideIn(gActiveBattler); @@ -1013,7 +1013,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) // Restore bgm after cry has played and healthbox anim is started if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].waitForCry && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].waitForCry + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].waitForCry && !IsCryPlayingOrClearCrySongs()) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].bgmRestored) @@ -1040,8 +1040,8 @@ static void Intro_TryShinyAnimShowHealthbox(void) { if (gSprites[gBattleControllerData[gActiveBattler]].callback == SpriteCallbackDummy && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy - && gSprites[gBattlerSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy + && gSprites[gBattlerSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) { battlerAnimsDone = TRUE; } @@ -1051,7 +1051,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) if (bgmRestored && battlerAnimsDone) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) - DestroySprite(&gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]]); + DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); gBattleSpritesDataPtr->animationData->introAnimActive = FALSE; @@ -1178,7 +1178,7 @@ static void Task_GiveExpToMon(u8 taskId) gActiveBattler = savedActiveBattler; if (IsDoubleBattle() == TRUE - && ((u16)(monId) == gBattlerPartyIndexes[battlerId] || (u16)(monId) == gBattlerPartyIndexes[battlerId ^ BIT_FLANK])) + && ((u16)(monId) == gBattlerPartyIndexes[battlerId] || (u16)(monId) == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)])) gTasks[taskId].func = Task_LaunchLvlUpAnim; else gTasks[taskId].func = DestroyExpTaskAndCompleteOnInactiveTextPrinter; @@ -1273,7 +1273,7 @@ static void Task_LaunchLvlUpAnim(u8 taskId) u8 battlerId = gTasks[taskId].tExpTask_battler; u8 monIndex = gTasks[taskId].tExpTask_monId; - if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[battlerId ^ BIT_FLANK]) + if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]) battlerId ^= BIT_FLANK; InitAndLaunchSpecialAnimation(battlerId, battlerId, battlerId, B_ANIM_LVL_UP); @@ -1290,8 +1290,8 @@ static void Task_UpdateLvlInHealthbox(u8 taskId) GetMonData(&gPlayerParty[monIndex], MON_DATA_LEVEL); // Unused return value. - if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[battlerId ^ BIT_FLANK]) - UpdateHealthboxAttribute(gHealthboxSpriteIds[battlerId ^ BIT_FLANK], &gPlayerParty[monIndex], HEALTHBOX_ALL); + if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]) + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(battlerId)], &gPlayerParty[monIndex], HEALTHBOX_ALL); else UpdateHealthboxAttribute(gHealthboxSpriteIds[battlerId], &gPlayerParty[monIndex], HEALTHBOX_ALL); diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 3812a8ffee88..a77144e297f8 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -229,7 +229,7 @@ static void Intro_WaitForHealthbox(void) else { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) { finished = TRUE; } @@ -248,7 +248,7 @@ static void Intro_WaitForHealthbox(void) static void Intro_ShowHealthbox(void) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive && gSprites[gBattleControllerData[gActiveBattler]].callback == SpriteCallbackDummy && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy && ++gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay != 1) @@ -257,10 +257,10 @@ static void Intro_ShowHealthbox(void) if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - DestroySprite(&gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]]); - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], HEALTHBOX_ALL); - StartHealthboxSlideIn(gActiveBattler ^ BIT_FLANK); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]); + DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); + StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]); } DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); @@ -336,7 +336,7 @@ static void Task_GiveExpToMon(u8 taskId) gActiveBattler = savedActiveBank; if (IsDoubleBattle() == TRUE - && ((u16)(monId) == gBattlerPartyIndexes[battlerId] || (u16)(monId) == gBattlerPartyIndexes[battlerId ^ BIT_FLANK])) + && ((u16)(monId) == gBattlerPartyIndexes[battlerId] || (u16)(monId) == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)])) gTasks[taskId].func = Task_LaunchLvlUpAnim; else gTasks[taskId].func = DestroyExpTaskAndCompleteOnInactiveTextPrinter; @@ -431,7 +431,7 @@ static void Task_LaunchLvlUpAnim(u8 taskId) u8 battlerId = gTasks[taskId].tExpTask_bank; u8 monIndex = gTasks[taskId].tExpTask_monId; - if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[battlerId ^ BIT_FLANK]) + if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]) battlerId ^= BIT_FLANK; InitAndLaunchSpecialAnimation(battlerId, battlerId, battlerId, B_ANIM_LVL_UP); @@ -448,8 +448,8 @@ static void Task_UpdateLvlInHealthbox(u8 taskId) GetMonData(&gPlayerParty[monIndex], MON_DATA_LEVEL); // Unused return value - if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[battlerId ^ BIT_FLANK]) - UpdateHealthboxAttribute(gHealthboxSpriteIds[battlerId ^ BIT_FLANK], &gPlayerParty[monIndex], HEALTHBOX_ALL); + if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]) + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(battlerId)], &gPlayerParty[monIndex], HEALTHBOX_ALL); else UpdateHealthboxAttribute(gHealthboxSpriteIds[battlerId], &gPlayerParty[monIndex], HEALTHBOX_ALL); diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 49538b834e29..0fb14f20d5d1 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -226,9 +226,9 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) else { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy + && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy && gSprites[gBattlerSpriteIds[gActiveBattler]].animEnded - && gSprites[gBattlerSpriteIds[gActiveBattler ^ BIT_FLANK]].animEnded) + && gSprites[gBattlerSpriteIds[BATTLE_PARTNER(gActiveBattler)]].animEnded) healthboxAnimDone = TRUE; } @@ -238,13 +238,13 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim) return; - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim) + if (!gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim) return; gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim = FALSE; FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); } @@ -263,19 +263,19 @@ static void Intro_TryShinyAnimShowHealthbox(void) && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive) TryShinyAnimation(gActiveBattler, &gEnemyParty[gBattlerPartyIndexes[gActiveBattler]]); - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive) - TryShinyAnimation(gActiveBattler ^ BIT_FLANK, &gEnemyParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]]); + if (!gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive) + TryShinyAnimation(BATTLE_PARTNER(gActiveBattler), &gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]]); - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive) + if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK], &gEnemyParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], HEALTHBOX_ALL); - StartHealthboxSlideIn(gActiveBattler ^ BIT_FLANK); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]); + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); + StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]); } UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_ALL); StartHealthboxSlideIn(gActiveBattler); @@ -286,7 +286,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].waitForCry && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].waitForCry + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].waitForCry && !IsCryPlayingOrClearCrySongs()) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].bgmRestored) @@ -317,8 +317,8 @@ static void Intro_TryShinyAnimShowHealthbox(void) { if (gSprites[gBattleControllerData[gActiveBattler]].callback == SpriteCallbackDummy && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy - && gSprites[gBattlerSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy + && gSprites[gBattlerSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) { battlerAnimsDone = TRUE; } @@ -328,8 +328,8 @@ static void Intro_TryShinyAnimShowHealthbox(void) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - DestroySprite(&gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]]); - SetBattlerShadowSpriteCallback(gActiveBattler ^ BIT_FLANK, GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], MON_DATA_SPECIES)); + DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); + SetBattlerShadowSpriteCallback(BATTLE_PARTNER(gActiveBattler), GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], MON_DATA_SPECIES)); } DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 6200b5ef63cf..b5f0a465d447 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -215,27 +215,27 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) else { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) { healthboxAnimDone = TRUE; } } if (healthboxAnimDone && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim - && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim) + && gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim = FALSE; FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); if (IsDoubleBattle()) - HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], gActiveBattler ^ BIT_FLANK); + HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], BATTLE_PARTNER(gActiveBattler)); gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay = 3; gBattlerControllerFuncs[gActiveBattler] = Intro_DelayAndEnd; @@ -251,7 +251,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) else { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]].callback == SpriteCallbackDummy) + && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) { healthboxAnimDone = TRUE; } @@ -278,21 +278,21 @@ static void Intro_TryShinyAnimShowHealthbox(void) && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive) TryShinyAnimation(gActiveBattler, &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]]); - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive) - TryShinyAnimation(gActiveBattler ^ BIT_FLANK, &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]]); + if (!gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive) + TryShinyAnimation(BATTLE_PARTNER(gActiveBattler), &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]]); } if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive) + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], HEALTHBOX_ALL); - StartHealthboxSlideIn(gActiveBattler ^ BIT_FLANK); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]); + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); + StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]); } UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_ALL); StartHealthboxSlideIn(gActiveBattler); @@ -303,7 +303,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].waitForCry - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].waitForCry + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].waitForCry && !IsCryPlayingOrClearCrySongs()) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].bgmRestored) @@ -327,7 +327,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) - DestroySprite(&gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]]); + DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); gBattleSpritesDataPtr->animationData->introAnimActive = FALSE; diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index 8e02831776af..f600a46f732c 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -289,21 +289,21 @@ static void Intro_TryShinyAnimShowHealthbox(void) && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive) TryShinyAnimation(gActiveBattler, &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]]); - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive) - TryShinyAnimation(gActiveBattler ^ BIT_FLANK, &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]]); + if (!gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive) + TryShinyAnimation(BATTLE_PARTNER(gActiveBattler), &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]]); if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive - && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive + && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive && gSprites[gBattleControllerData[gActiveBattler]].callback == SpriteCallbackDummy && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) { if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - DestroySprite(&gSprites[gBattleControllerData[gActiveBattler ^ BIT_FLANK]]); - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]], HEALTHBOX_ALL); - StartHealthboxSlideIn(gActiveBattler ^ BIT_FLANK); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler ^ BIT_FLANK]); + DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); + StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]); } DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_ALL); @@ -324,13 +324,13 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) healthboxAnimDone = TRUE; if (healthboxAnimDone && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim - && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim) + && gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim = FALSE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].triedShinyMonAnim = FALSE; + gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].finishedShinyMonAnim = FALSE; FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index ca6be9d4e2e8..f97a460897ba 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -1060,7 +1060,7 @@ void HandleLowHpMusicChange(struct Pokemon *mon, u8 battlerId) { if (!gBattleSpritesDataPtr->battlerData[battlerId].lowHpSong) { - if (!gBattleSpritesDataPtr->battlerData[battlerId ^ BIT_FLANK].lowHpSong) + if (!gBattleSpritesDataPtr->battlerData[BATTLE_PARTNER(battlerId)].lowHpSong) PlaySE(SE_LOW_HEALTH); gBattleSpritesDataPtr->battlerData[battlerId].lowHpSong = 1; } @@ -1073,7 +1073,7 @@ void HandleLowHpMusicChange(struct Pokemon *mon, u8 battlerId) m4aSongNumStop(SE_LOW_HEALTH); return; } - if (IsDoubleBattle() && !gBattleSpritesDataPtr->battlerData[battlerId ^ BIT_FLANK].lowHpSong) + if (IsDoubleBattle() && !gBattleSpritesDataPtr->battlerData[BATTLE_PARTNER(battlerId)].lowHpSong) { m4aSongNumStop(SE_LOW_HEALTH); return; @@ -1087,7 +1087,7 @@ void BattleStopLowHpSound(void) gBattleSpritesDataPtr->battlerData[playerBattler].lowHpSong = 0; if (IsDoubleBattle()) - gBattleSpritesDataPtr->battlerData[playerBattler ^ BIT_FLANK].lowHpSong = 0; + gBattleSpritesDataPtr->battlerData[BATTLE_PARTNER(playerBattler)].lowHpSong = 0; m4aSongNumStop(SE_LOW_HEALTH); } diff --git a/src/battle_main.c b/src/battle_main.c index b748fb5b1ef0..ad4ea88b9e17 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4432,7 +4432,7 @@ static void HandleTurnActionSelectionState(void) if (((gBattleTypeFlags & BATTLE_TYPE_MULTI) || !(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) || (position & BIT_FLANK) != B_FLANK_LEFT - || (*(&gBattleStruct->absentBattlerFlags) & gBitTable[GetBattlerAtPosition(position ^ BIT_FLANK)])) + || (*(&gBattleStruct->absentBattlerFlags) & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(position))])) { BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_STOP_BOUNCE, i); } @@ -4545,9 +4545,9 @@ static void UpdateBattlerPartyOrdersOnSwitch(void) *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0); *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 1) = gBattleBufferB[gActiveBattler][3]; - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleBufferB[gActiveBattler][3]; + *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); + *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; + *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleBufferB[gActiveBattler][3]; } } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 09535e0794b6..61dfa4df6269 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5087,7 +5087,7 @@ static void Cmd_openpartyscreen(void) *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]); - BtlController_EmitChoosePokemon(BUFFER_A, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + (gActiveBattler ^ 2)), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); + BtlController_EmitChoosePokemon(BUFFER_A, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + (BATTLE_PARTNER(gActiveBattler))), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 6; @@ -5164,9 +5164,9 @@ static void Cmd_switchhandleorder(void) *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0); *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 1) = gBattleBufferB[gActiveBattler][3]; - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleBufferB[gActiveBattler][3]; + *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); + *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; + *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleBufferB[gActiveBattler][3]; } else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { @@ -7189,7 +7189,7 @@ static void Cmd_forcerandomswitch(void) monsCount = PARTY_SIZE / 2; minNeeded = 1; battler2PartyId = gBattlerPartyIndexes[gBattlerTarget]; - battler1PartyId = gBattlerPartyIndexes[gBattlerTarget ^ BIT_FLANK]; + battler1PartyId = gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerTarget)]; } else if ((gBattleTypeFlags & BATTLE_TYPE_MULTI && gBattleTypeFlags & BATTLE_TYPE_LINK) || (gBattleTypeFlags & BATTLE_TYPE_MULTI && gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK)) @@ -7207,7 +7207,7 @@ static void Cmd_forcerandomswitch(void) monsCount = PARTY_SIZE / 2; minNeeded = 1; battler2PartyId = gBattlerPartyIndexes[gBattlerTarget]; - battler1PartyId = gBattlerPartyIndexes[gBattlerTarget ^ BIT_FLANK]; + battler1PartyId = gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerTarget)]; } else if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) { @@ -7234,7 +7234,7 @@ static void Cmd_forcerandomswitch(void) minNeeded = 1; } battler2PartyId = gBattlerPartyIndexes[gBattlerTarget]; - battler1PartyId = gBattlerPartyIndexes[gBattlerTarget ^ BIT_FLANK]; + battler1PartyId = gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerTarget)]; } else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { @@ -7243,7 +7243,7 @@ static void Cmd_forcerandomswitch(void) monsCount = PARTY_SIZE; minNeeded = 2; battler2PartyId = gBattlerPartyIndexes[gBattlerTarget]; - battler1PartyId = gBattlerPartyIndexes[gBattlerTarget ^ BIT_FLANK]; + battler1PartyId = gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerTarget)]; } else { @@ -7296,7 +7296,7 @@ static void Cmd_forcerandomswitch(void) || (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI)) { SwitchPartyOrderLinkMulti(gBattlerTarget, i, 0); - SwitchPartyOrderLinkMulti(gBattlerTarget ^ BIT_FLANK, i, 1); + SwitchPartyOrderLinkMulti(BATTLE_PARTNER(gBattlerTarget), i, 1); } if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) @@ -7642,7 +7642,7 @@ static void Cmd_updatestatusicon(void) } if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { - gActiveBattler = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_FLANK); + gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler])) { BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); @@ -8310,7 +8310,7 @@ static void Cmd_healpartystatus(void) gBattleCommunication[MULTISTRING_CHOOSER] |= B_MSG_BELL_SOUNDPROOF_ATTACKER; } - gActiveBattler = gBattleScripting.battler = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_FLANK); + gActiveBattler = gBattleScripting.battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && !(gAbsentBattlerFlags & gBitTable[gActiveBattler])) @@ -8360,7 +8360,7 @@ static void Cmd_healpartystatus(void) gBattleMons[gBattlerAttacker].status1 = 0; gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE; - gActiveBattler = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_FLANK); + gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && !(gAbsentBattlerFlags & gBitTable[gActiveBattler])) { @@ -9068,7 +9068,7 @@ static void Cmd_settaunt(void) static void Cmd_trysethelpinghand(void) { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_FLANK); + gBattlerTarget = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && !(gAbsentBattlerFlags & gBitTable[gBattlerTarget]) @@ -9745,7 +9745,7 @@ static void Cmd_settypetoterrain(void) // Unused static void Cmd_pursuitdoubles(void) { - gActiveBattler = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_FLANK); + gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && !(gAbsentBattlerFlags & gBitTable[gActiveBattler]) diff --git a/src/battle_util.c b/src/battle_util.c index fd63494dde79..f178e03c11f0 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -200,13 +200,13 @@ void HandleAction_UseMove(void) { if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + gBattlerTarget = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerTarget))); } else { gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + gBattlerTarget = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerTarget))); } } } @@ -239,7 +239,7 @@ void HandleAction_UseMove(void) if (gAbsentBattlerFlags & gBitTable[gBattlerTarget] && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + gBattlerTarget = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerTarget))); } } else @@ -249,13 +249,13 @@ void HandleAction_UseMove(void) { if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + gBattlerTarget = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerTarget))); } else { gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + gBattlerTarget = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerTarget))); } } } @@ -1799,7 +1799,7 @@ bool8 HandleWishPerishSongOnTurnEnd(void) BattleScriptExecute(BattleScript_MonTookFutureAttack); if (gWishFutureKnock.futureSightCounter[gActiveBattler] == 0 - && gWishFutureKnock.futureSightCounter[gActiveBattler ^ BIT_FLANK] == 0) + && gWishFutureKnock.futureSightCounter[BATTLE_PARTNER(gActiveBattler)] == 0) { gSideStatuses[GET_BATTLER_SIDE(gBattlerTarget)] &= ~SIDE_STATUS_FUTUREATTACK; } From 1f0a952546c29584b17684581de69cea92d8a19b Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Aug 2022 01:44:39 -0400 Subject: [PATCH 08/21] Usage of BATTLE_OPPOSITE --- src/battle_ai_script_commands.c | 4 ++-- src/battle_ai_switch_items.c | 4 ++-- src/battle_controller_player.c | 2 +- src/battle_gfx_sfx_util.c | 8 ++++---- src/battle_script_commands.c | 36 ++++++++++++++++----------------- src/battle_util.c | 16 +++++++-------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 93e4768379c3..96b2e1184c7a 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -351,14 +351,14 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) // Decide a random target battlerId in doubles. if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - gBattlerTarget = (Random() & BIT_FLANK) + (GetBattlerSide(gActiveBattler) ^ BIT_SIDE); + gBattlerTarget = (Random() & BIT_FLANK) + (BATTLE_OPPOSITE(GetBattlerSide(gActiveBattler))); if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) gBattlerTarget ^= BIT_FLANK; } // There's only one choice in single battles. else { - gBattlerTarget = sBattler_AI ^ BIT_SIDE; + gBattlerTarget = BATTLE_OPPOSITE(sBattler_AI); } // Choose proper trainer ai scripts. diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 736dfa9d4814..9e314286fc59 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -601,7 +601,7 @@ void AI_TrySwitchOrUseItem(void) } } - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, (gActiveBattler ^ BIT_SIDE) << 8); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, BATTLE_OPPOSITE(gActiveBattler) << 8); } static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8 *var) @@ -665,7 +665,7 @@ u8 GetMostSuitableMonToSwitchInto(void) } else { - opposingBattler = GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_SIDE); + opposingBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler))); battlerIn1 = gActiveBattler; battlerIn2 = gActiveBattler; } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 2e1f9417b8db..96a3d6bf01ce 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -498,7 +498,7 @@ static void HandleInputChooseMove(void) if (moveTarget & MOVE_TARGET_USER) gMultiUsePlayerCursor = gActiveBattler; else - gMultiUsePlayerCursor = GetBattlerAtPosition((GetBattlerPosition(gActiveBattler) & BIT_SIDE) ^ BIT_SIDE); + gMultiUsePlayerCursor = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler) & BIT_SIDE)); if (!gBattleBufferA[gActiveBattler][1]) // not a double battle { diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index f97a460897ba..c2d4fad186aa 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -254,7 +254,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) else if (moveTarget == MOVE_TARGET_SELECTED) chosenMoveId |= GetBattlePalaceTarget(); else - chosenMoveId |= (GetBattlerAtPosition((GetBattlerPosition(gActiveBattler) & BIT_SIDE) ^ BIT_SIDE) << 8); + chosenMoveId |= (GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler) & BIT_SIDE)) << 8); return chosenMoveId; } @@ -310,7 +310,7 @@ static u16 GetBattlePalaceTarget(void) } if (gBattleMons[opposing1].hp == gBattleMons[opposing2].hp) - return (((gActiveBattler & BIT_SIDE) ^ BIT_SIDE) + (Random() & 2)) << 8; + return (BATTLE_OPPOSITE(gActiveBattler & BIT_SIDE) + (Random() & 2)) << 8; switch (gBattlePalaceNatureToMoveTarget[GetNatureFromPersonality(gBattleMons[gActiveBattler].personality)]) { @@ -325,11 +325,11 @@ static u16 GetBattlePalaceTarget(void) else return opposing2 << 8; case PALACE_TARGET_RANDOM: - return (((gActiveBattler & BIT_SIDE) ^ BIT_SIDE) + (Random() & 2)) << 8; + return (BATTLE_OPPOSITE(gActiveBattler & BIT_SIDE) + (Random() & 2)) << 8; } } - return (gActiveBattler ^ BIT_SIDE) << 8; + return BATTLE_OPPOSITE(gActiveBattler) << 8; } // Wait for the pokemon to finish appearing out from the pokeball on send out diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 61dfa4df6269..22a2f6caf907 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5108,7 +5108,7 @@ static void Cmd_openpartyscreen(void) } else { - gActiveBattler = GetBattlerAtPosition(GetBattlerPosition(battlerId) ^ BIT_SIDE); + gActiveBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(battlerId))); if (gAbsentBattlerFlags & gBitTable[gActiveBattler]) gActiveBattler ^= BIT_FLANK; @@ -6233,7 +6233,7 @@ static void Cmd_hpthresholds(void) if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - opposingBattler = gActiveBattler ^ BIT_SIDE; + opposingBattler = BATTLE_OPPOSITE(gActiveBattler); result = gBattleMons[opposingBattler].hp * 100 / gBattleMons[opposingBattler].maxHP; if (result == 0) @@ -6261,7 +6261,7 @@ static void Cmd_hpthresholds2(void) if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - opposingBattler = gActiveBattler ^ BIT_SIDE; + opposingBattler = BATTLE_OPPOSITE(gActiveBattler); hpSwitchout = *(gBattleStruct->hpOnSwitchout + GetBattlerSide(opposingBattler)); result = (hpSwitchout - gBattleMons[opposingBattler].hp) * 100 / hpSwitchout; @@ -6299,7 +6299,7 @@ static void Cmd_various(void) break; case VARIOUS_SET_MAGIC_COAT_TARGET: gBattlerAttacker = gBattlerTarget; - side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; + side = BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker)); if (gSideTimers[side].followmeTimer != 0 && gBattleMons[gSideTimers[side].followmeTarget].hp != 0) gBattlerTarget = gSideTimers[side].followmeTarget; else @@ -8399,7 +8399,7 @@ static void Cmd_cursetarget(void) static void Cmd_trysetspikes(void) { - u8 targetSide = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; + u8 targetSide = BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker)); if (gSideTimers[targetSide].spikesAmount == 3) { @@ -9781,7 +9781,7 @@ static void Cmd_snatchsetbattlers(void) // Brick Break static void Cmd_removelightscreenreflect(void) { - u8 opposingSide = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; + u8 opposingSide = BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker)); if (gSideTimers[opposingSide].reflectTimer || gSideTimers[opposingSide].lightscreenTimer) { @@ -9809,7 +9809,7 @@ static void Cmd_handleballthrow(void) return; gActiveBattler = gBattlerAttacker; - gBattlerTarget = gBattlerAttacker ^ BIT_SIDE; + gBattlerTarget = BATTLE_OPPOSITE(gBattlerAttacker); if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { @@ -9951,18 +9951,18 @@ static void Cmd_handleballthrow(void) static void Cmd_givecaughtmon(void) { - if (GiveMonToPlayer(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]]) != MON_GIVEN_TO_PARTY) + if (GiveMonToPlayer(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]]) != MON_GIVEN_TO_PARTY) { if (!ShouldShowBoxWasFullMessage()) { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SENT_SOMEONES_PC; StringCopy(gStringVar1, GetBoxNamePtr(VarGet(VAR_PC_BOX_TO_SEND_MON))); - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gStringVar2); + GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_NICKNAME, gStringVar2); } else { StringCopy(gStringVar1, GetBoxNamePtr(VarGet(VAR_PC_BOX_TO_SEND_MON))); // box the mon was sent to - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gStringVar2); + GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_NICKNAME, gStringVar2); StringCopy(gStringVar3, GetBoxNamePtr(GetPCBoxToSendMon())); //box the mon was going to be sent to gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SOMEONES_BOX_FULL; } @@ -9972,9 +9972,9 @@ static void Cmd_givecaughtmon(void) gBattleCommunication[MULTISTRING_CHOOSER]++; } - gBattleResults.caughtMonSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_SPECIES, NULL); - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gBattleResults.caughtMonNick); - gBattleResults.caughtMonBall = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_POKEBALL, NULL); + gBattleResults.caughtMonSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_SPECIES, NULL); + GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_NICKNAME, gBattleResults.caughtMonNick); + gBattleResults.caughtMonBall = GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_POKEBALL, NULL); gBattlescriptCurrInstr++; } @@ -10162,13 +10162,13 @@ static void Cmd_trygivecaughtmonnick(void) case 2: if (!gPaletteFade.active) { - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick); + GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick); FreeAllWindowBuffers(); DoNamingScreen(NAMING_SCREEN_CAUGHT_MON, gBattleStruct->caughtMonNick, - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_SPECIES), - GetMonGender(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]]), - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_PERSONALITY, NULL), + GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_SPECIES), + GetMonGender(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]]), + GetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_PERSONALITY, NULL), BattleMainCB2); gBattleCommunication[MULTIUSE_STATE]++; @@ -10177,7 +10177,7 @@ static void Cmd_trygivecaughtmonnick(void) case 3: if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { - SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick); + SetMonData(&gEnemyParty[gBattlerPartyIndexes[BATTLE_OPPOSITE(gBattlerAttacker)]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); } break; diff --git a/src/battle_util.c b/src/battle_util.c index f178e03c11f0..4315c8a9b58d 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -146,7 +146,7 @@ void HandleAction_UseMove(void) } // choose target - side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; + side = BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker)); if (gSideTimers[side].followmeTimer != 0 && gBattleMoves[gCurrentMove].target == MOVE_TARGET_SELECTED && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gSideTimers[side].followmeTarget) @@ -204,7 +204,7 @@ void HandleAction_UseMove(void) } else { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); + gBattlerTarget = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gBattlerAttacker))); if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) gBattlerTarget = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerTarget))); } @@ -253,7 +253,7 @@ void HandleAction_UseMove(void) } else { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); + gBattlerTarget = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gBattlerAttacker))); if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) gBattlerTarget = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerTarget))); } @@ -3001,7 +3001,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA if (gBattleMons[i].ability == ABILITY_TRACE && (gStatuses3[i] & STATUS3_TRACE)) { u8 target2; - side = (GetBattlerPosition(i) ^ BIT_SIDE) & BIT_SIDE; // side of the opposing pokemon + side = (BATTLE_OPPOSITE(GetBattlerPosition(i))) & BIT_SIDE; // side of the opposing pokemon target1 = GetBattlerAtPosition(side); target2 = GetBattlerAtPosition(side + BIT_FLANK); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) @@ -3820,7 +3820,7 @@ u8 GetMoveTarget(u16 move, u8 setTarget) switch (moveTarget) { case MOVE_TARGET_SELECTED: - side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; + side = BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker)); if (gSideTimers[side].followmeTimer && gBattleMons[gSideTimers[side].followmeTarget].hp) targetBattler = gSideTimers[side].followmeTarget; else @@ -3844,12 +3844,12 @@ u8 GetMoveTarget(u16 move, u8 setTarget) case MOVE_TARGET_BOTH: case MOVE_TARGET_FOES_AND_ALLY: case MOVE_TARGET_OPPONENTS_FIELD: - targetBattler = GetBattlerAtPosition((GetBattlerPosition(gBattlerAttacker) & BIT_SIDE) ^ BIT_SIDE); + targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gBattlerAttacker) & BIT_SIDE)); if (gAbsentBattlerFlags & gBitTable[targetBattler]) targetBattler ^= BIT_FLANK; break; case MOVE_TARGET_RANDOM: - side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; + side = BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker)); if (gSideTimers[side].followmeTimer && gBattleMons[gSideTimers[side].followmeTarget].hp) targetBattler = gSideTimers[side].followmeTarget; else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && moveTarget & MOVE_TARGET_RANDOM) @@ -3872,7 +3872,7 @@ u8 GetMoveTarget(u16 move, u8 setTarget) targetBattler ^= BIT_FLANK; } else - targetBattler = GetBattlerAtPosition((GetBattlerPosition(gBattlerAttacker) & BIT_SIDE) ^ BIT_SIDE); + targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gBattlerAttacker) & BIT_SIDE)); break; case MOVE_TARGET_USER_OR_SELECTED: case MOVE_TARGET_USER: From 866d916f2fb27c16fc064386766f99d5a9f36bf2 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Aug 2022 02:07:58 -0400 Subject: [PATCH 09/21] SpriteTemplate formatting --- src/cable_car.c | 13 +++++++------ src/easy_chat.c | 18 ++++++++++++------ src/field_effect.c | 3 ++- src/mirage_tower.c | 6 ++++-- src/mystery_gift_view.c | 3 ++- src/roulette.c | 4 ++-- src/union_room_chat.c | 15 ++++++++++----- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/cable_car.c b/src/cable_car.c index 562e9eceb758..dd1da3176216 100644 --- a/src/cable_car.c +++ b/src/cable_car.c @@ -202,7 +202,7 @@ static const struct OamData sOam_Cable = .paletteNum = 0, }; -static const struct SpriteTemplate sSpriteTemplate_CableCar[] = +static const struct SpriteTemplate sSpriteTemplates_CableCar[] = { { .tileTag = TAG_CABLE_CAR, @@ -224,7 +224,8 @@ static const struct SpriteTemplate sSpriteTemplate_CableCar[] = }, }; -static const struct SpriteTemplate sSpriteTemplate_Cable = { +static const struct SpriteTemplate sSpriteTemplate_Cable = +{ .tileTag = TAG_CABLE, .paletteTag = TAG_CABLE_CAR, .oam = &sOam_Cable, @@ -836,12 +837,12 @@ static void CreateCableCarSprites(void) gSprites[spriteId].sYPos = 73; } // Create car sprite - spriteId = CreateSprite(&sSpriteTemplate_CableCar[0], 176, 43, 0x67); + spriteId = CreateSprite(&sSpriteTemplates_CableCar[0], 176, 43, 0x67); gSprites[spriteId].x2 = gSprites[spriteId].y2 = 32; gSprites[spriteId].sXPos = 176; gSprites[spriteId].sYPos = 43; // Create door sprite - spriteId = CreateSprite(&sSpriteTemplate_CableCar[1], 200, 99, 0x65); + spriteId = CreateSprite(&sSpriteTemplates_CableCar[1], 200, 99, 0x65); gSprites[spriteId].x2 = 8; gSprites[spriteId].y2 = 4; gSprites[spriteId].sXPos = 200; @@ -864,12 +865,12 @@ static void CreateCableCarSprites(void) gSprites[spriteId].sYPos = 39; } // Create car sprite - spriteId = CreateSprite(&sSpriteTemplate_CableCar[0], 104, 9, 0x67); + spriteId = CreateSprite(&sSpriteTemplates_CableCar[0], 104, 9, 0x67); gSprites[spriteId].x2 = gSprites[spriteId].y2 = 32; gSprites[spriteId].sXPos = 104; gSprites[spriteId].sYPos = 9; // Create door sprite - spriteId = CreateSprite(&sSpriteTemplate_CableCar[1], 128, 65, 0x65); + spriteId = CreateSprite(&sSpriteTemplates_CableCar[1], 128, 65, 0x65); gSprites[spriteId].x2 = 8; gSprites[spriteId].y2 = 4; gSprites[spriteId].sXPos = 128; diff --git a/src/easy_chat.c b/src/easy_chat.c index 91b44fb26b16..ebc843b3cc22 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -944,7 +944,8 @@ static const struct OamData sOamData_TriangleCursor = { .affineParam = 0, }; -static const struct SpriteTemplate sSpriteTemplate_TriangleCursor = { +static const struct SpriteTemplate sSpriteTemplate_TriangleCursor = +{ .tileTag = PALTAG_TRIANGLE_CURSOR, .paletteTag = GFXTAG_TRIANGLE_CURSOR, .oam = &sOamData_TriangleCursor, @@ -1005,7 +1006,8 @@ static const union AnimCmd *const sAnims_RectangleCursor[] = { [RECTCURSOR_ANIM_ON_LETTER] = sAnim_RectangleCursor_OnLetter, }; -static const struct SpriteTemplate sSpriteTemplate_RectangleCursor = { +static const struct SpriteTemplate sSpriteTemplate_RectangleCursor = +{ .tileTag = GFXTAG_RECTANGLE_CURSOR, .paletteTag = PALTAG_RECTANGLE_CURSOR, .oam = &sOamData_RectangleCursor, @@ -1075,7 +1077,8 @@ static const union AnimCmd *const sAnims_ModeWindow[] = { [MODEWINDOW_ANIM_TRANSITION] = sAnim_ModeWindow_Transition, }; -static const struct SpriteTemplate sSpriteTemplate_ModeWindow = { +static const struct SpriteTemplate sSpriteTemplate_ModeWindow = +{ .tileTag = GFXTAG_MODE_WINDOW, .paletteTag = PALTAG_MISC_UI, .oam = &sOamData_ModeWindow, @@ -1101,7 +1104,8 @@ static const struct OamData sOamData_ButtonWindow = { .affineParam = 0, }; -static const struct SpriteTemplate sSpriteTemplate_ButtonWindow = { +static const struct SpriteTemplate sSpriteTemplate_ButtonWindow = +{ .tileTag = GFXTAG_BUTTON_WINDOW, .paletteTag = PALTAG_MISC_UI, .oam = &sOamData_ButtonWindow, @@ -1159,7 +1163,8 @@ static const union AnimCmd *const sAnims_TwoFrame[] = { sAnim_Frame1, }; -static const struct SpriteTemplate sSpriteTemplate_StartSelectButton = { +static const struct SpriteTemplate sSpriteTemplate_StartSelectButton = +{ .tileTag = GFXTAG_START_SELECT_BUTTONS, .paletteTag = PALTAG_MISC_UI, .oam = &sOamData_StartSelectButton, @@ -1169,7 +1174,8 @@ static const struct SpriteTemplate sSpriteTemplate_StartSelectButton = { .callback = SpriteCallbackDummy, }; -static const struct SpriteTemplate sSpriteTemplate_ScrollIndicator = { +static const struct SpriteTemplate sSpriteTemplate_ScrollIndicator = +{ .tileTag = GFXTAG_SCROLL_INDICATOR, .paletteTag = PALTAG_MISC_UI, .oam = &sOamData_ScrollIndicator, diff --git a/src/field_effect.c b/src/field_effect.c index ba917b56543e..1ab45bb25c26 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -3766,7 +3766,8 @@ static const union AnimCmd *const sAnims_DeoxysRockFragment[] = { sAnim_RockFragment_BottomRight, }; -static const struct SpriteTemplate sSpriteTemplate_DeoxysRockFragment = { +static const struct SpriteTemplate sSpriteTemplate_DeoxysRockFragment = +{ .tileTag = TAG_NONE, .paletteTag = 4378, .oam = &sOam_8x8, diff --git a/src/mirage_tower.c b/src/mirage_tower.c index 69c2e8154035..37096619d36c 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -201,7 +201,8 @@ static const struct OamData sOamData_CeilingCrumbleSmall = .affineParam = 0, }; -static const struct SpriteTemplate sSpriteTemplate_CeilingCrumbleSmall = { +static const struct SpriteTemplate sSpriteTemplate_CeilingCrumbleSmall = +{ .tileTag = TAG_CEILING_CRUMBLE, .paletteTag = TAG_NONE, .oam = &sOamData_CeilingCrumbleSmall, @@ -239,7 +240,8 @@ static const struct OamData sOamData_CeilingCrumbleLarge = .affineParam = 0, }; -static const struct SpriteTemplate sSpriteTemplate_CeilingCrumbleLarge = { +static const struct SpriteTemplate sSpriteTemplate_CeilingCrumbleLarge = +{ .tileTag = TAG_CEILING_CRUMBLE, .paletteTag = TAG_NONE, .oam = &sOamData_CeilingCrumbleLarge, diff --git a/src/mystery_gift_view.c b/src/mystery_gift_view.c index ff34c8853630..384e8ef74b9b 100644 --- a/src/mystery_gift_view.c +++ b/src/mystery_gift_view.c @@ -162,7 +162,8 @@ static const struct SpritePalette sSpritePalettes_StampShadow[] = { {sStampShadowPal8, TAG_STAMP_SHADOW} }; -static const struct SpriteTemplate sSpriteTemplate_StampShadow = { +static const struct SpriteTemplate sSpriteTemplate_StampShadow = +{ .tileTag = TAG_STAMP_SHADOW, .paletteTag = TAG_STAMP_SHADOW, .oam = &gOamData_AffineOff_ObjNormal_32x16, diff --git a/src/roulette.c b/src/roulette.c index a8be6ad7ca64..52efc8779fd3 100644 --- a/src/roulette.c +++ b/src/roulette.c @@ -2662,7 +2662,7 @@ static const struct SpriteTemplate sSpriteTemplates_ColorHeaders[NUM_BOARD_COLOR } }; -static const struct SpriteTemplate sSpriteTemplate_GridIcons[NUM_BOARD_POKES] = +static const struct SpriteTemplate sSpriteTemplates_GridIcons[NUM_BOARD_POKES] = { { .tileTag = GFXTAG_GRID_ICONS, @@ -3537,7 +3537,7 @@ static void CreateGridSprites(void) u8 y = i * 24; for (j = 0; j < NUM_BOARD_POKES; j++) { - spriteId = sRoulette->spriteIds[(i * NUM_BOARD_POKES) + SPR_GRID_ICONS + j] = CreateSprite(&sSpriteTemplate_GridIcons[j], (j * 24) + 148, y + 92, 30); + spriteId = sRoulette->spriteIds[(i * NUM_BOARD_POKES) + SPR_GRID_ICONS + j] = CreateSprite(&sSpriteTemplates_GridIcons[j], (j * 24) + 148, y + 92, 30); gSprites[spriteId].animPaused = TRUE; y += 24; if (y >= 72) diff --git a/src/union_room_chat.c b/src/union_room_chat.c index f8513b9f46b0..5c26d1ea3616 100755 --- a/src/union_room_chat.c +++ b/src/union_room_chat.c @@ -793,7 +793,8 @@ static const union AnimCmd *const sAnims_KeyboardCursor[] = { sAnim_KeyboardCursorWide_Closed }; -static const struct SpriteTemplate sSpriteTemplate_KeyboardCursor = { +static const struct SpriteTemplate sSpriteTemplate_KeyboardCursor = +{ .tileTag = GFXTAG_KEYBOARD_CURSOR, .paletteTag = PALTAG_INTERFACE, .oam = &sOam_KeyboardCursor, @@ -809,7 +810,8 @@ static const struct OamData sOam_TextEntrySprite = { .priority = 2 }; -static const struct SpriteTemplate sSpriteTemplate_TextEntryCursor = { +static const struct SpriteTemplate sSpriteTemplate_TextEntryCursor = +{ .tileTag = GFXTAG_TEXT_ENTRY_CURSOR, .paletteTag = PALTAG_INTERFACE, .oam = &sOam_TextEntrySprite, @@ -819,7 +821,8 @@ static const struct SpriteTemplate sSpriteTemplate_TextEntryCursor = { .callback = SpriteCB_TextEntryCursor }; -static const struct SpriteTemplate sSpriteTemplate_TextEntryArrow = { +static const struct SpriteTemplate sSpriteTemplate_TextEntryArrow = +{ .tileTag = GFXTAG_TEXT_ENTRY_ARROW, .paletteTag = PALTAG_INTERFACE, .oam = &sOam_TextEntrySprite, @@ -868,7 +871,8 @@ static const union AnimCmd *const sAnims_RButtonLabels[] = { sAnim_RegisterIcon }; -static const struct SpriteTemplate sSpriteTemplate_RButtonIcon = { +static const struct SpriteTemplate sSpriteTemplate_RButtonIcon = +{ .tileTag = GFXTAG_RBUTTON_ICON, .paletteTag = PALTAG_INTERFACE, .oam = &sOam_RButtonIcon, @@ -878,7 +882,8 @@ static const struct SpriteTemplate sSpriteTemplate_RButtonIcon = { .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate sSpriteTemplate_RButtonLabels = { +static const struct SpriteTemplate sSpriteTemplate_RButtonLabels = +{ .tileTag = GFXTAG_RBUTTON_LABELS, .paletteTag = PALTAG_INTERFACE, .oam = &sOam_RButtonLabel, From 99fbad92e21003c474b608ba8dc47fe3570184e5 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Aug 2022 02:50:55 -0400 Subject: [PATCH 10/21] IS_BATTLER_OF_TYPE --- src/battle_ai_switch_items.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 9e314286fc59..261349dce1d8 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -446,9 +446,7 @@ static bool8 ShouldSwitch(void) return FALSE; if (ABILITY_ON_FIELD2(ABILITY_MAGNET_PULL)) { - if (gBattleMons[gActiveBattler].type1 == TYPE_STEEL) - return FALSE; - if (gBattleMons[gActiveBattler].type2 == TYPE_STEEL) + if (IS_BATTLER_OF_TYPE(gActiveBattler, TYPE_STEEL)) return FALSE; } if (gBattleTypeFlags & BATTLE_TYPE_ARENA) From 12b32606f5b1a9c764bdfe389c76f0282a471e9e Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Aug 2022 03:05:06 -0400 Subject: [PATCH 11/21] Fixed PokemonSubstruct3 alignment --- include/pokemon.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/pokemon.h b/include/pokemon.h index c05628a5984a..b6c798acca2e 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -142,7 +142,7 @@ struct PokemonSubstruct3 /* 0x02 */ u16 metLevel:7; /* 0x02 */ u16 metGame:4; - /* 0x03 */ u16 unused3_3:4; + /* 0x03 */ u16 unused1:4; /* 0x03 */ u16 otGender:1; /* 0x04 */ u32 hpIV:5; @@ -152,6 +152,7 @@ struct PokemonSubstruct3 /* 0x05 */ u32 spAttackIV:5; /* 0x06 */ u32 spDefenseIV:5; /* 0x07 */ u32 isEgg:1; + /* 0x07 */ u32 unused2:1; /* 0x08 */ u32 coolRibbon:3; /* 0x08 */ u32 beautyRibbon:3; From 1c8d3a49225a16ff28b0507f79ee041b9bddbb0f Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Aug 2022 11:19:50 -0400 Subject: [PATCH 12/21] Removed unnecessary parenthesis --- src/battle_ai_script_commands.c | 4 ++-- src/battle_script_commands.c | 2 +- src/battle_util.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 96b2e1184c7a..1ddcc9805fdf 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -351,7 +351,7 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) // Decide a random target battlerId in doubles. if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - gBattlerTarget = (Random() & BIT_FLANK) + (BATTLE_OPPOSITE(GetBattlerSide(gActiveBattler))); + gBattlerTarget = (Random() & BIT_FLANK) + BATTLE_OPPOSITE(GetBattlerSide(gActiveBattler)); if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) gBattlerTarget ^= BIT_FLANK; } @@ -541,7 +541,7 @@ static u8 ChooseMoveOrAction_Doubles(void) bestMovePointsForTarget[i] = mostViableMovesScores[0]; // Don't use a move against ally if it has less than 100 points. - if (i == (BATTLE_PARTNER(sBattler_AI)) && bestMovePointsForTarget[i] < 100) + if (i == BATTLE_PARTNER(sBattler_AI) && bestMovePointsForTarget[i] < 100) { bestMovePointsForTarget[i] = -1; mostViableMovesScores[0] = mostViableMovesScores[0]; // Needed to match. diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 22a2f6caf907..a40a4b6f0197 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5087,7 +5087,7 @@ static void Cmd_openpartyscreen(void) *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]); - BtlController_EmitChoosePokemon(BUFFER_A, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + (BATTLE_PARTNER(gActiveBattler))), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); + BtlController_EmitChoosePokemon(BUFFER_A, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + BATTLE_PARTNER(gActiveBattler)), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 6; diff --git a/src/battle_util.c b/src/battle_util.c index 4315c8a9b58d..9bfeacd2d2bb 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -3001,7 +3001,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA if (gBattleMons[i].ability == ABILITY_TRACE && (gStatuses3[i] & STATUS3_TRACE)) { u8 target2; - side = (BATTLE_OPPOSITE(GetBattlerPosition(i))) & BIT_SIDE; // side of the opposing pokemon + side = BATTLE_OPPOSITE(GetBattlerPosition(i)) & BIT_SIDE; // side of the opposing pokemon target1 = GetBattlerAtPosition(side); target2 = GetBattlerAtPosition(side + BIT_FLANK); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) From e02b33ee112f9f08c0866a27fb8c2ad1e763ad20 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 31 Aug 2022 22:56:39 -0300 Subject: [PATCH 13/21] Automatized the contents of some sideof in src/item.c --- src/item.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/item.c b/src/item.c index 63287693a8d6..641c1ce6180e 100644 --- a/src/item.c +++ b/src/item.c @@ -740,11 +740,11 @@ bool8 AddPyramidBagItem(u16 itemId, u16 count) u16 *items = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode]; u8 *quantities = gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode]; - u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); - memcpy(newItems, items, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - memcpy(newQuantities, quantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + memcpy(newItems, items, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + memcpy(newQuantities, quantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) { @@ -792,8 +792,8 @@ bool8 AddPyramidBagItem(u16 itemId, u16 count) if (count == 0) { - memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); Free(newItems); Free(newQuantities); return TRUE; @@ -823,11 +823,11 @@ bool8 RemovePyramidBagItem(u16 itemId, u16 count) } else { - u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); - memcpy(newItems, items, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - memcpy(newQuantities, quantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + memcpy(newItems, items, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + memcpy(newQuantities, quantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) { @@ -854,8 +854,8 @@ bool8 RemovePyramidBagItem(u16 itemId, u16 count) if (count == 0) { - memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); Free(newItems); Free(newQuantities); return TRUE; From ea345f90f5d2e9cb8a63ad12343aeea49e67340c Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 31 Aug 2022 23:05:06 -0300 Subject: [PATCH 14/21] Picked the correct pointers for correctness' sake --- src/item.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/item.c b/src/item.c index 641c1ce6180e..0f5746027bb4 100644 --- a/src/item.c +++ b/src/item.c @@ -792,8 +792,8 @@ bool8 AddPyramidBagItem(u16 itemId, u16 count) if (count == 0) { - memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); - memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); + memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(*items)); + memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*quantities)); Free(newItems); Free(newQuantities); return TRUE; @@ -854,8 +854,8 @@ bool8 RemovePyramidBagItem(u16 itemId, u16 count) if (count == 0) { - memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); - memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); + memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(*items)); + memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*quantities)); Free(newItems); Free(newQuantities); return TRUE; From 5d346fd9392eb718dce06875a26538691343f582 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 31 Aug 2022 23:49:43 -0300 Subject: [PATCH 15/21] Updated a couple more sizeofs --- src/battle_pyramid_bag.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index 9fab996da884..7a4d981f0188 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -1404,20 +1404,20 @@ void TryStoreHeldItemsInPyramidBag(void) { u8 i; struct Pokemon *party = gPlayerParty; - u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); u16 heldItem; - memcpy(newItems, gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode], PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - memcpy(newQuantities, gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode], PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + memcpy(newItems, gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode], PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + memcpy(newQuantities, gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode], PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { heldItem = GetMonData(&party[i], MON_DATA_HELD_ITEM); if (heldItem != ITEM_NONE && !AddBagItem(heldItem, 1)) { // Cant store party held items in pyramid bag because bag is full - memcpy(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode], newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); - memcpy(gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode], newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + memcpy(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode], newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newItems)); + memcpy(gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode], newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(*newQuantities)); Free(newItems); Free(newQuantities); gSpecialVar_Result = 1; From c7fc2e13f771cb30a0eb579d1f77e76a85d3be5d Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Fri, 2 Sep 2022 16:54:58 -0400 Subject: [PATCH 16/21] Renamed TM flags to keep consistency with the rest of the repo --- .../AbandonedShip_HiddenFloorRooms/map.json | 2 +- data/maps/AbandonedShip_Room_B1F/map.json | 2 +- data/maps/MeteorFalls_1F_1R/map.json | 2 +- data/maps/MeteorFalls_B1F_2R/map.json | 2 +- data/maps/MtPyre_6F/map.json | 2 +- data/maps/MtPyre_Exterior/map.json | 2 +- data/maps/Route111/map.json | 2 +- data/maps/Route113/map.json | 2 +- data/maps/Route115/map.json | 2 +- data/maps/SafariZone_Northwest/map.json | 2 +- data/maps/ScorchedSlab/map.json | 2 +- data/maps/SeafloorCavern_Room9/map.json | 2 +- data/maps/ShoalCave_LowTideIceRoom/map.json | 2 +- data/maps/VictoryRoad_B1F/map.json | 2 +- include/constants/flags.h | 28 +++++++++---------- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/data/maps/AbandonedShip_HiddenFloorRooms/map.json b/data/maps/AbandonedShip_HiddenFloorRooms/map.json index b81c33c84301..e9442f22e260 100644 --- a/data/maps/AbandonedShip_HiddenFloorRooms/map.json +++ b/data/maps/AbandonedShip_HiddenFloorRooms/map.json @@ -51,7 +51,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "AbandonedShip_HiddenFloorRooms_EventScript_ItemTM18", - "flag": "FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_1_TM_18" + "flag": "FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_1_TM18" }, { "graphics_id": "OBJ_EVENT_GFX_ITEM_BALL", diff --git a/data/maps/AbandonedShip_Room_B1F/map.json b/data/maps/AbandonedShip_Room_B1F/map.json index f5d14ac595b4..537f0ec6456f 100644 --- a/data/maps/AbandonedShip_Room_B1F/map.json +++ b/data/maps/AbandonedShip_Room_B1F/map.json @@ -25,7 +25,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "AbandonedShip_Room_B1F_EventScript_ItemTM13", - "flag": "FLAG_ITEM_ABANDONED_SHIP_ROOMS_B1F_TM_13" + "flag": "FLAG_ITEM_ABANDONED_SHIP_ROOMS_B1F_TM13" } ], "warp_events": [ diff --git a/data/maps/MeteorFalls_1F_1R/map.json b/data/maps/MeteorFalls_1F_1R/map.json index f177410e274a..145289ce798b 100644 --- a/data/maps/MeteorFalls_1F_1R/map.json +++ b/data/maps/MeteorFalls_1F_1R/map.json @@ -25,7 +25,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "MeteorFalls_1F_1R_EventScript_ItemTM23", - "flag": "FLAG_ITEM_METEOR_FALLS_1F_1R_TM_23" + "flag": "FLAG_ITEM_METEOR_FALLS_1F_1R_TM23" }, { "graphics_id": "OBJ_EVENT_GFX_ITEM_BALL", diff --git a/data/maps/MeteorFalls_B1F_2R/map.json b/data/maps/MeteorFalls_B1F_2R/map.json index 57276d86dbd0..7fc43762f585 100644 --- a/data/maps/MeteorFalls_B1F_2R/map.json +++ b/data/maps/MeteorFalls_B1F_2R/map.json @@ -25,7 +25,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "MeteorFalls_B1F_2R_EventScript_ItemTM02", - "flag": "FLAG_ITEM_METEOR_FALLS_B1F_2R_TM_02" + "flag": "FLAG_ITEM_METEOR_FALLS_B1F_2R_TM02" } ], "warp_events": [ diff --git a/data/maps/MtPyre_6F/map.json b/data/maps/MtPyre_6F/map.json index dc2e7f9b00ba..88c091f3e302 100644 --- a/data/maps/MtPyre_6F/map.json +++ b/data/maps/MtPyre_6F/map.json @@ -38,7 +38,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "MtPyre_6F_EventScript_ItemTM30", - "flag": "FLAG_ITEM_MT_PYRE_6F_TM_30" + "flag": "FLAG_ITEM_MT_PYRE_6F_TM30" }, { "graphics_id": "OBJ_EVENT_GFX_PSYCHIC_M", diff --git a/data/maps/MtPyre_Exterior/map.json b/data/maps/MtPyre_Exterior/map.json index 58c865305fd4..2df79262c2c9 100644 --- a/data/maps/MtPyre_Exterior/map.json +++ b/data/maps/MtPyre_Exterior/map.json @@ -38,7 +38,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "MtPyre_Exterior_EventScript_ItemTM48", - "flag": "FLAG_ITEM_MT_PYRE_EXTERIOR_TM_48" + "flag": "FLAG_ITEM_MT_PYRE_EXTERIOR_TM48" } ], "warp_events": [ diff --git a/data/maps/Route111/map.json b/data/maps/Route111/map.json index 4621591e4357..566e7c9629e5 100644 --- a/data/maps/Route111/map.json +++ b/data/maps/Route111/map.json @@ -262,7 +262,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "Route111_EventScript_ItemTM37", - "flag": "FLAG_ITEM_ROUTE_111_TM_37" + "flag": "FLAG_ITEM_ROUTE_111_TM37" }, { "graphics_id": "OBJ_EVENT_GFX_BERRY_TREE", diff --git a/data/maps/Route113/map.json b/data/maps/Route113/map.json index 422b88e6ef6f..783406346ec7 100644 --- a/data/maps/Route113/map.json +++ b/data/maps/Route113/map.json @@ -451,7 +451,7 @@ "y": 5, "elevation": 3, "item": "ITEM_TM32", - "flag": "FLAG_HIDDEN_ITEM_ROUTE_113_TM_32" + "flag": "FLAG_HIDDEN_ITEM_ROUTE_113_TM32" }, { "type": "hidden_item", diff --git a/data/maps/Route115/map.json b/data/maps/Route115/map.json index bbac132f5218..a5e2b10f9e18 100644 --- a/data/maps/Route115/map.json +++ b/data/maps/Route115/map.json @@ -166,7 +166,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "Route115_EventScript_ItemTM01", - "flag": "FLAG_ITEM_ROUTE_115_TM_01" + "flag": "FLAG_ITEM_ROUTE_115_TM01" }, { "graphics_id": "OBJ_EVENT_GFX_ITEM_BALL", diff --git a/data/maps/SafariZone_Northwest/map.json b/data/maps/SafariZone_Northwest/map.json index 1e27def2cd3a..20fffd0498a4 100644 --- a/data/maps/SafariZone_Northwest/map.json +++ b/data/maps/SafariZone_Northwest/map.json @@ -49,7 +49,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "SafariZone_Northwest_EventScript_ItemTM22", - "flag": "FLAG_ITEM_SAFARI_ZONE_NORTH_WEST_TM_22" + "flag": "FLAG_ITEM_SAFARI_ZONE_NORTH_WEST_TM22" } ], "warp_events": [], diff --git a/data/maps/ScorchedSlab/map.json b/data/maps/ScorchedSlab/map.json index e90f1f5c1f90..cb9789490386 100644 --- a/data/maps/ScorchedSlab/map.json +++ b/data/maps/ScorchedSlab/map.json @@ -25,7 +25,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "ScorchedSlab_EventScript_ItemTM11", - "flag": "FLAG_ITEM_SCORCHED_SLAB_TM_11" + "flag": "FLAG_ITEM_SCORCHED_SLAB_TM11" } ], "warp_events": [ diff --git a/data/maps/SeafloorCavern_Room9/map.json b/data/maps/SeafloorCavern_Room9/map.json index 0557b0c3eb73..7942b3d1d40d 100644 --- a/data/maps/SeafloorCavern_Room9/map.json +++ b/data/maps/SeafloorCavern_Room9/map.json @@ -90,7 +90,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "SeafloorCavern_Room9_EventScript_ItemTM26", - "flag": "FLAG_ITEM_SEAFLOOR_CAVERN_ROOM_9_TM_26" + "flag": "FLAG_ITEM_SEAFLOOR_CAVERN_ROOM_9_TM26" }, { "graphics_id": "OBJ_EVENT_GFX_KYOGRE_ASLEEP", diff --git a/data/maps/ShoalCave_LowTideIceRoom/map.json b/data/maps/ShoalCave_LowTideIceRoom/map.json index ea4f0cedf490..3195d408b334 100644 --- a/data/maps/ShoalCave_LowTideIceRoom/map.json +++ b/data/maps/ShoalCave_LowTideIceRoom/map.json @@ -25,7 +25,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "ShoalCave_LowTideIceRoom_EventScript_ItemTM07", - "flag": "FLAG_ITEM_SHOAL_CAVE_ICE_ROOM_TM_07" + "flag": "FLAG_ITEM_SHOAL_CAVE_ICE_ROOM_TM07" }, { "graphics_id": "OBJ_EVENT_GFX_ITEM_BALL", diff --git a/data/maps/VictoryRoad_B1F/map.json b/data/maps/VictoryRoad_B1F/map.json index 6e290ce6de2e..68b013ef4673 100644 --- a/data/maps/VictoryRoad_B1F/map.json +++ b/data/maps/VictoryRoad_B1F/map.json @@ -246,7 +246,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "VictoryRoad_B1F_EventScript_ItemTM29", - "flag": "FLAG_ITEM_VICTORY_ROAD_B1F_TM_29" + "flag": "FLAG_ITEM_VICTORY_ROAD_B1F_TM29" }, { "graphics_id": "OBJ_EVENT_GFX_ITEM_BALL", diff --git a/include/constants/flags.h b/include/constants/flags.h index 8fbc24630038..4e108e1fe98b 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -568,7 +568,7 @@ #define FLAG_HIDDEN_ITEM_LILYCOVE_CITY_HEART_SCALE (FLAG_HIDDEN_ITEMS_START + 0x1B) #define FLAG_HIDDEN_ITEM_FALLARBOR_TOWN_NUGGET (FLAG_HIDDEN_ITEMS_START + 0x1C) #define FLAG_HIDDEN_ITEM_MT_PYRE_EXTERIOR_ULTRA_BALL (FLAG_HIDDEN_ITEMS_START + 0x1D) -#define FLAG_HIDDEN_ITEM_ROUTE_113_TM_32 (FLAG_HIDDEN_ITEMS_START + 0x1E) +#define FLAG_HIDDEN_ITEM_ROUTE_113_TM32 (FLAG_HIDDEN_ITEMS_START + 0x1E) #define FLAG_HIDDEN_ITEM_ABANDONED_SHIP_RM_1_KEY (FLAG_HIDDEN_ITEMS_START + 0x1F) #define FLAG_HIDDEN_ITEM_ABANDONED_SHIP_RM_2_KEY (FLAG_HIDDEN_ITEMS_START + 0x20) #define FLAG_HIDDEN_ITEM_ABANDONED_SHIP_RM_4_KEY (FLAG_HIDDEN_ITEMS_START + 0x21) @@ -1053,7 +1053,7 @@ #define FLAG_ITEM_ROUTE_109_PP_UP 0x3ED #define FLAG_ITEM_ROUTE_109_RARE_CANDY 0x3EE #define FLAG_ITEM_ROUTE_110_DIRE_HIT 0x3EF -#define FLAG_ITEM_ROUTE_111_TM_37 0x3F0 +#define FLAG_ITEM_ROUTE_111_TM37 0x3F0 #define FLAG_ITEM_ROUTE_111_STARDUST 0x3F1 #define FLAG_ITEM_ROUTE_111_HP_UP 0x3F2 #define FLAG_ITEM_ROUTE_112_NUGGET 0x3F3 @@ -1062,7 +1062,7 @@ #define FLAG_ITEM_ROUTE_114_RARE_CANDY 0x3F6 #define FLAG_ITEM_ROUTE_114_PROTEIN 0x3F7 #define FLAG_ITEM_ROUTE_115_SUPER_POTION 0x3F8 -#define FLAG_ITEM_ROUTE_115_TM_01 0x3F9 +#define FLAG_ITEM_ROUTE_115_TM01 0x3F9 #define FLAG_ITEM_ROUTE_115_IRON 0x3FA #define FLAG_ITEM_ROUTE_116_ETHER 0x3FB #define FLAG_ITEM_ROUTE_116_REPEL 0x3FC @@ -1089,7 +1089,7 @@ #define FLAG_ITEM_RUSTBORO_CITY_X_DEFEND 0x411 #define FLAG_ITEM_LILYCOVE_CITY_MAX_REPEL 0x412 #define FLAG_ITEM_MOSSDEEP_CITY_NET_BALL 0x413 -#define FLAG_ITEM_METEOR_FALLS_1F_1R_TM_23 0x414 +#define FLAG_ITEM_METEOR_FALLS_1F_1R_TM23 0x414 #define FLAG_ITEM_METEOR_FALLS_1F_1R_FULL_HEAL 0x415 #define FLAG_ITEM_METEOR_FALLS_1F_1R_MOON_STONE 0x416 #define FLAG_ITEM_METEOR_FALLS_1F_1R_PP_UP 0x417 @@ -1119,35 +1119,35 @@ #define FLAG_ITEM_AQUA_HIDEOUT_B1F_MAX_ELIXIR 0x42F #define FLAG_ITEM_AQUA_HIDEOUT_B2F_NEST_BALL 0x430 #define FLAG_ITEM_MT_PYRE_EXTERIOR_MAX_POTION 0x431 -#define FLAG_ITEM_MT_PYRE_EXTERIOR_TM_48 0x432 +#define FLAG_ITEM_MT_PYRE_EXTERIOR_TM48 0x432 #define FLAG_ITEM_NEW_MAUVILLE_ULTRA_BALL 0x433 #define FLAG_ITEM_NEW_MAUVILLE_ESCAPE_ROPE 0x434 #define FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_6_LUXURY_BALL 0x435 #define FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_4_SCANNER 0x436 -#define FLAG_ITEM_SCORCHED_SLAB_TM_11 0x437 -#define FLAG_ITEM_METEOR_FALLS_B1F_2R_TM_02 0x438 +#define FLAG_ITEM_SCORCHED_SLAB_TM11 0x437 +#define FLAG_ITEM_METEOR_FALLS_B1F_2R_TM02 0x438 #define FLAG_ITEM_SHOAL_CAVE_ENTRANCE_BIG_PEARL 0x439 #define FLAG_ITEM_SHOAL_CAVE_INNER_ROOM_RARE_CANDY 0x43A #define FLAG_ITEM_SHOAL_CAVE_STAIRS_ROOM_ICE_HEAL 0x43B #define FLAG_ITEM_VICTORY_ROAD_1F_MAX_ELIXIR 0x43C #define FLAG_ITEM_VICTORY_ROAD_1F_PP_UP 0x43D -#define FLAG_ITEM_VICTORY_ROAD_B1F_TM_29 0x43E +#define FLAG_ITEM_VICTORY_ROAD_B1F_TM29 0x43E #define FLAG_ITEM_VICTORY_ROAD_B1F_FULL_RESTORE 0x43F #define FLAG_ITEM_VICTORY_ROAD_B2F_FULL_HEAL 0x440 -#define FLAG_ITEM_MT_PYRE_6F_TM_30 0x441 -#define FLAG_ITEM_SEAFLOOR_CAVERN_ROOM_9_TM_26 0x442 +#define FLAG_ITEM_MT_PYRE_6F_TM30 0x441 +#define FLAG_ITEM_SEAFLOOR_CAVERN_ROOM_9_TM26 0x442 #define FLAG_ITEM_FIERY_PATH_TM06 0x443 #define FLAG_ITEM_ROUTE_124_RED_SHARD 0x444 #define FLAG_ITEM_ROUTE_124_BLUE_SHARD 0x445 -#define FLAG_ITEM_SAFARI_ZONE_NORTH_WEST_TM_22 0x446 +#define FLAG_ITEM_SAFARI_ZONE_NORTH_WEST_TM22 0x446 #define FLAG_ITEM_ABANDONED_SHIP_ROOMS_1F_HARBOR_MAIL 0x447 #define FLAG_ITEM_ABANDONED_SHIP_ROOMS_B1F_ESCAPE_ROPE 0x448 #define FLAG_ITEM_ABANDONED_SHIP_ROOMS_2_B1F_DIVE_BALL 0x449 -#define FLAG_ITEM_ABANDONED_SHIP_ROOMS_B1F_TM_13 0x44A +#define FLAG_ITEM_ABANDONED_SHIP_ROOMS_B1F_TM13 0x44A #define FLAG_ITEM_ABANDONED_SHIP_ROOMS_2_1F_REVIVE 0x44B #define FLAG_ITEM_ABANDONED_SHIP_CAPTAINS_OFFICE_STORAGE_KEY 0x44C #define FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_3_WATER_STONE 0x44D -#define FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_1_TM_18 0x44E +#define FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_1_TM18 0x44E #define FLAG_ITEM_ROUTE_121_CARBOS 0x44F #define FLAG_ITEM_ROUTE_123_ULTRA_BALL 0x450 #define FLAG_ITEM_ROUTE_126_GREEN_SHARD 0x451 @@ -1157,7 +1157,7 @@ #define FLAG_ITEM_ROUTE_123_ELIXIR 0x455 #define FLAG_ITEM_NEW_MAUVILLE_THUNDER_STONE 0x456 #define FLAG_ITEM_FIERY_PATH_FIRE_STONE 0x457 -#define FLAG_ITEM_SHOAL_CAVE_ICE_ROOM_TM_07 0x458 +#define FLAG_ITEM_SHOAL_CAVE_ICE_ROOM_TM07 0x458 #define FLAG_ITEM_SHOAL_CAVE_ICE_ROOM_NEVER_MELT_ICE 0x459 #define FLAG_ITEM_ROUTE_103_GUARD_SPEC 0x45A #define FLAG_ITEM_ROUTE_104_X_ACCURACY 0x45B From 03498d7240b47bfb76b410323ebcf53c82c70ff3 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Fri, 2 Sep 2022 23:57:43 -0400 Subject: [PATCH 17/21] Applied remaining instances of BATTLE_OPPOSITE and BATTLE_PARTNER --- include/battle_ai_util.h | 2 +- src/battle_ai_main.c | 2 +- src/battle_ai_util.c | 2 +- src/battle_anim_new.c | 2 +- src/battle_controller_opponent.c | 2 +- src/battle_message.c | 6 +++--- src/battle_script_commands.c | 2 +- src/battle_util.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/battle_ai_util.h b/include/battle_ai_util.h index 5e66577e309f..11eba7b6618f 100644 --- a/include/battle_ai_util.h +++ b/include/battle_ai_util.h @@ -5,7 +5,7 @@ #define AI_IS_FASTER 0 #define AI_IS_SLOWER 1 -#define FOE(battler) ((battler ^ BIT_SIDE) & BIT_SIDE) +#define FOE(battler) ((BATTLE_OPPOSITE(battler)) & BIT_SIDE) bool32 AI_RandLessThan(u8 val); void RecordLastUsedMoveByTarget(void); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index f496b90e81b6..af642aa8dc1f 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -486,7 +486,7 @@ static u8 ChooseMoveOrAction_Doubles(void) bestMovePointsForTarget[i] = mostViableMovesScores[0]; // Don't use a move against ally if it has less than 100 points. - if (i == (sBattler_AI ^ BIT_FLANK) && bestMovePointsForTarget[i] < 100) + if (i == BATTLE_PARTNER(sBattler_AI) && bestMovePointsForTarget[i] < 100) { bestMovePointsForTarget[i] = -1; mostViableMovesScores[0] = mostViableMovesScores[0]; // Needed to match. diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 25c7f3b9d55a..98fcf948a305 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -3248,7 +3248,7 @@ s32 CountUsablePartyMons(u8 battlerId) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { battlerOnField1 = gBattlerPartyIndexes[battlerId]; - battlerOnField2 = gBattlerPartyIndexes[GetBattlerAtPosition(GetBattlerPosition(battlerId) ^ BIT_FLANK)]; + battlerOnField2 = gBattlerPartyIndexes[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battlerId)))]; } else // In singles there's only one battlerId by side. { diff --git a/src/battle_anim_new.c b/src/battle_anim_new.c index 35c12446707f..0a3d433b4687 100644 --- a/src/battle_anim_new.c +++ b/src/battle_anim_new.c @@ -6523,7 +6523,7 @@ const struct SpriteTemplate gSoulStealZStarSpriteTemplate = //general void AnimTask_IsTargetPartner(u8 taskId) { - if (gBattleAnimTarget == (gBattleAnimAttacker ^ BIT_FLANK)) + if (gBattleAnimTarget == BATTLE_PARTNER(gBattleAnimAttacker)) gBattleAnimArgs[0] = 1; else gBattleAnimArgs[0] = 0; diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index d249fc38be7f..8f02fb3e35aa 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -226,7 +226,7 @@ static void Intro_DelayAndEnd(void) static bool32 TwoIntroMons(u32 battlerId) // Double battle with both player pokemon active. { - return (IsDoubleBattle() && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[battlerId ^ BIT_FLANK]])); + return (IsDoubleBattle() && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]])); } static void Intro_WaitForShinyAnimAndHealthbox(void) diff --git a/src/battle_message.c b/src/battle_message.c index 7b263ea65740..8298accf1ff4 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2703,7 +2703,7 @@ void BufferStringBattle(u16 stringID) { if (gBattleTypeFlags & BATTLE_TYPE_LEGENDARY) stringPtr = sText_LegendaryPkmnAppeared; - else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]])) // interesting, looks like they had something planned for wild double battles + else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]])) // interesting, looks like they had something planned for wild double battles stringPtr = sText_TwoWildPkmnAppeared; else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL) stringPtr = sText_WildPkmnAppearedPause; @@ -2714,7 +2714,7 @@ void BufferStringBattle(u16 stringID) case STRINGID_INTROSENDOUT: // poke first send-out if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) { - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]])) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]])) { if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) stringPtr = sText_InGamePartnerSentOutZGoN; @@ -2732,7 +2732,7 @@ void BufferStringBattle(u16 stringID) } else { - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]])) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]])) { if (BATTLE_TWO_VS_ONE_OPPONENT) stringPtr = sText_Trainer1SentOutTwoPkmn; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index c485f4017200..5c4ba2c40161 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -10730,7 +10730,7 @@ static void Cmd_forcerandomswitch(void) monsCount = 6; minNeeded = 2; battler2PartyId = gBattlerPartyIndexes[gBattlerTarget]; - battler1PartyId = gBattlerPartyIndexes[gBattlerTarget ^ BIT_FLANK]; + battler1PartyId = gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerTarget)]; } else if ((gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER && gBattleTypeFlags & BATTLE_TYPE_LINK) || (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER && gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK) diff --git a/src/battle_util.c b/src/battle_util.c index d39b03215bab..1c1cf685d9c3 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -5817,7 +5817,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move { if (gBattleMons[i].ability == ABILITY_TRACE && (gBattleResources->flags->flags[i] & RESOURCE_FLAG_TRACED)) { - u8 side = (GetBattlerPosition(i) ^ BIT_SIDE) & BIT_SIDE; // side of the opposing pokemon + u8 side = (BATTLE_OPPOSITE(GetBattlerPosition(i))) & BIT_SIDE; // side of the opposing pokemon u8 target1 = GetBattlerAtPosition(side); u8 target2 = GetBattlerAtPosition(side + BIT_FLANK); From 790bdd69f81a3ea43f7e30c783eee651f8496b5d Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 3 Sep 2022 00:28:32 -0400 Subject: [PATCH 18/21] Using GET_BATTLER_SIDE and GET_BATTLER_SIDE2 --- src/battle_anim_effects_2.c | 2 +- src/battle_anim_fight.c | 2 +- src/battle_anim_ice.c | 4 ++-- src/battle_controller_player.c | 2 +- src/battle_gfx_sfx_util.c | 2 +- src/battle_util.c | 4 ++-- src/pokemon.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index 5bd28acea112..6b60440528d8 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -1667,7 +1667,7 @@ void AnimTask_AirCutterProjectile(u8 taskId) } else { - if ((gBattlerPositions[gBattleAnimTarget] & BIT_SIDE) == B_SIDE_PLAYER) + if (GET_BATTLER_SIDE2(gBattleAnimTarget) == B_SIDE_PLAYER) { gTasks[taskId].data[4] = 1; gBattleAnimArgs[0] = -gBattleAnimArgs[0]; diff --git a/src/battle_anim_fight.c b/src/battle_anim_fight.c index 0d7b977e9d53..764a951ef81f 100644 --- a/src/battle_anim_fight.c +++ b/src/battle_anim_fight.c @@ -492,7 +492,7 @@ static void AnimFistOrFootRandomPos(struct Sprite *sprite) if (Random2() & 1) y *= -1; - if ((gBattlerPositions[battler] & BIT_SIDE) == B_SIDE_PLAYER) + if (GET_BATTLER_SIDE2(battler) == B_SIDE_PLAYER) y += 0xFFF0; sprite->x += x; diff --git a/src/battle_anim_ice.c b/src/battle_anim_ice.c index d2779d141590..3032db7f3f29 100644 --- a/src/battle_anim_ice.c +++ b/src/battle_anim_ice.c @@ -1193,12 +1193,12 @@ static void InitPoisonGasCloudAnim(struct Sprite *sprite) if (GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X_2) < GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X_2)) sprite->data[7] = 0x8000; - if ((gBattlerPositions[gBattleAnimTarget] & BIT_SIDE) == B_SIDE_PLAYER) + if (GET_BATTLER_SIDE2(gBattleAnimTarget) == B_SIDE_PLAYER) { gBattleAnimArgs[1] = -gBattleAnimArgs[1]; gBattleAnimArgs[3] = -gBattleAnimArgs[3]; - if ((sprite->data[7] & 0x8000) && (gBattlerPositions[gBattleAnimAttacker] & BIT_SIDE) == B_SIDE_PLAYER) + if ((sprite->data[7] & 0x8000) && GET_BATTLER_SIDE2(gBattleAnimAttacker) == B_SIDE_PLAYER) sprite->subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1; sprite->data[6] = 1; diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 96a3d6bf01ce..265bb7f65703 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -498,7 +498,7 @@ static void HandleInputChooseMove(void) if (moveTarget & MOVE_TARGET_USER) gMultiUsePlayerCursor = gActiveBattler; else - gMultiUsePlayerCursor = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler) & BIT_SIDE)); + gMultiUsePlayerCursor = GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(gActiveBattler))); if (!gBattleBufferA[gActiveBattler][1]) // not a double battle { diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index c2d4fad186aa..9c5243548dd7 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -254,7 +254,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) else if (moveTarget == MOVE_TARGET_SELECTED) chosenMoveId |= GetBattlePalaceTarget(); else - chosenMoveId |= (GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler) & BIT_SIDE)) << 8); + chosenMoveId |= (GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(gActiveBattler))) << 8); return chosenMoveId; } diff --git a/src/battle_util.c b/src/battle_util.c index 9bfeacd2d2bb..bbf34ab31631 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -3844,7 +3844,7 @@ u8 GetMoveTarget(u16 move, u8 setTarget) case MOVE_TARGET_BOTH: case MOVE_TARGET_FOES_AND_ALLY: case MOVE_TARGET_OPPONENTS_FIELD: - targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gBattlerAttacker) & BIT_SIDE)); + targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(gBattlerAttacker))); if (gAbsentBattlerFlags & gBitTable[targetBattler]) targetBattler ^= BIT_FLANK; break; @@ -3872,7 +3872,7 @@ u8 GetMoveTarget(u16 move, u8 setTarget) targetBattler ^= BIT_FLANK; } else - targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gBattlerAttacker) & BIT_SIDE)); + targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(gBattlerAttacker))); break; case MOVE_TARGET_USER_OR_SELECTED: case MOVE_TARGET_USER: diff --git a/src/pokemon.c b/src/pokemon.c index 4b22947cb0e2..d4931f8e5e3c 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -3405,7 +3405,7 @@ static bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 battlerId) u8 GetDefaultMoveTarget(u8 battlerId) { - u8 opposing = BATTLE_OPPOSITE(GetBattlerPosition(battlerId) & BIT_SIDE); + u8 opposing = BATTLE_OPPOSITE(GET_BATTLER_SIDE(battlerId)); if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) return GetBattlerAtPosition(opposing); From 41bf6bde258af3e52867800c7b2fdb02f0540674 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 3 Sep 2022 00:28:53 -0400 Subject: [PATCH 19/21] Removed pointless macro --- include/battle.h | 3 +-- src/battle_anim_mons.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/battle.h b/include/battle.h index 0eaa60f30f6f..5cc552185992 100644 --- a/include/battle.h +++ b/include/battle.h @@ -13,9 +13,8 @@ #include "battle_bg.h" #include "pokeball.h" -#define GET_BATTLER_POSITION(battler) (gBattlerPositions[battler]) #define GET_BATTLER_SIDE(battler) (GetBattlerPosition(battler) & BIT_SIDE) -#define GET_BATTLER_SIDE2(battler) (GET_BATTLER_POSITION(battler) & BIT_SIDE) +#define GET_BATTLER_SIDE2(battler) (gBattlerPositions[battler] & BIT_SIDE) // Used to exclude moves learned temporarily by Transform or Mimic #define MOVE_IS_PERMANENT(battler, moveSlot) \ diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c index f8fc5647eaac..25817c0740a9 100644 --- a/src/battle_anim_mons.c +++ b/src/battle_anim_mons.c @@ -857,7 +857,7 @@ u8 GetBattlerSide(u8 battlerId) u8 GetBattlerPosition(u8 battlerId) { - return GET_BATTLER_POSITION(battlerId); + return gBattlerPositions[battlerId]; } u8 GetBattlerAtPosition(u8 position) From ce3dec43a7c0855f03ff74226f8169bba4a637df Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sun, 4 Sep 2022 17:21:23 -0300 Subject: [PATCH 20/21] Fixed ball multiplier fallthroughs --- src/battle_script_commands.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 18fa5bbdffd1..7eebbff1c0dd 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -13721,10 +13721,12 @@ static void Cmd_handleballthrow(void) { case ITEM_ULTRA_BALL: ballMultiplier = 20; + break; case ITEM_GREAT_BALL: case ITEM_SAFARI_BALL: case ITEM_SPORT_BALL: ballMultiplier = 15; + break; case ITEM_NET_BALL: if (IS_BATTLER_OF_TYPE(gBattlerTarget, TYPE_WATER) || IS_BATTLER_OF_TYPE(gBattlerTarget, TYPE_BUG)) #if B_NET_BALL_MODIFIER >= GEN_7 From 89550ed05d3377423f04285551f779ca7b0481c0 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sun, 4 Sep 2022 18:54:23 -0300 Subject: [PATCH 21/21] Updated Sport Ball's modifier. --- include/constants/battle_config.h | 1 + src/battle_script_commands.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 89134daf9187..d9e0abf104c9 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -130,6 +130,7 @@ #define B_LURE_BALL_MODIFIER GEN_7 // In Gen7+, Lure Ball's catch multiplier is x5 instead of x3. #define B_HEAVY_BALL_MODIFIER GEN_7 // In Gen7+, Heavy Ball's ranges change. See Cmd_handleballthrow. #define B_DREAM_BALL_MODIFIER GEN_8 // In Gen8, Dream Ball's catch multiplier is x4 when the target is asleep or has the ability Comatose. +#define B_SPORT_BALL_MODIFIER GEN_8 // In Gen8, Sport Ball's catch multiplier was reduced from x1.5 to x1. #define B_SERENE_GRACE_BOOST GEN_7 // In Gen5+, Serene Grace boosts the added flinch chance of King's Rock and Razor Fang. // Flag settings diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 7eebbff1c0dd..944255cfc95e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -13722,9 +13722,11 @@ static void Cmd_handleballthrow(void) case ITEM_ULTRA_BALL: ballMultiplier = 20; break; + #if B_SPORT_BALL_MODIFIER <= GEN_7 + case ITEM_SPORT_BALL: + #endif case ITEM_GREAT_BALL: case ITEM_SAFARI_BALL: - case ITEM_SPORT_BALL: ballMultiplier = 15; break; case ITEM_NET_BALL: