From 2bae70a66b88250c415f910ccb18e75e6d88d4a1 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 20 Sep 2018 17:33:27 +0200 Subject: [PATCH] Convert mega related struct fields to a seperate struct --- include/battle.h | 23 ++++++++++++++--------- src/battle_controller_player.c | 14 +++++++------- src/battle_interface.c | 18 +++++++++--------- src/battle_main.c | 22 +++++++++++----------- src/battle_script_commands.c | 10 +++++----- src/battle_util.c | 10 +++++----- 6 files changed, 51 insertions(+), 46 deletions(-) diff --git a/include/battle.h b/include/battle.h index f839f8b96..b605e352b 100644 --- a/include/battle.h +++ b/include/battle.h @@ -478,6 +478,19 @@ struct BattleTvMovePoints s16 points[2][PARTY_SIZE * 4]; }; +struct MegaEvolutionData +{ + u8 toEvolve; // As flags using gBitTable. + u8 evolvedPartyIds[2]; // As flags using gBitTable; + bool8 alreadyEvolved[4]; // Array id is used for mon position. + u16 evolvedSpecies[MAX_BATTLERS_COUNT]; + u16 playerEvolvedSpecies; + u8 battlerId; + bool8 playerSelect; + u8 triggerSpriteId; + u8 indicatorSpriteIds[MAX_BATTLERS_COUNT]; +}; + struct BattleStruct { u8 turnEffectsTracker; @@ -598,15 +611,7 @@ struct BattleStruct bool8 ateBoost[MAX_BATTLERS_COUNT]; u32 debugAIFlags; bool8 notfirstTimeAIFlags; - u8 toMegaEvolve; // As flags using gBitTable. - u8 megaEvolvedPartyIds[2]; // As flags using gBitTable; - bool8 alreadyMegaEvolved[4]; // Array id is used for mon position. - u16 speciesThatMegaEvolved[MAX_BATTLERS_COUNT]; - u16 playerSpeciesThatMegaEvolved; - u8 megaEvoBattlerId; - bool8 playerMegaEvoSelect; - u8 megaEvoTriggerSpriteId; - u8 megaEvoIndicatorSpriteId[MAX_BATTLERS_COUNT]; + struct MegaEvolutionData mega; }; #define GET_MOVE_TYPE(move, typeArg) \ diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 6d6f665f2..23a01616e 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -386,7 +386,7 @@ static void HandleInputChooseTarget(void) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039B2C; - if (gBattleStruct->playerMegaEvoSelect) + if (gBattleStruct->mega.playerSelect) BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); else BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); @@ -544,7 +544,7 @@ static void HandleInputChooseMove(void) if (!canSelectTarget) { - if (gBattleStruct->playerMegaEvoSelect) + if (gBattleStruct->mega.playerSelect) BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); else BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); @@ -568,7 +568,7 @@ static void HandleInputChooseMove(void) else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) { PlaySE(SE_SELECT); - gBattleStruct->playerMegaEvoSelect = FALSE; + gBattleStruct->mega.playerSelect = FALSE; BtlController_EmitTwoReturnValues(1, 10, 0xFFFF); HideMegaTriggerSprite(); PlayerBufferExecCompleted(); @@ -643,8 +643,8 @@ static void HandleInputChooseMove(void) { if (CanMegaEvolve(gActiveBattler)) { - gBattleStruct->playerMegaEvoSelect ^= 1; - SetMegaTriggerSpritePal(gBattleStruct->megaEvoTriggerSpriteId, gBattleStruct->playerMegaEvoSelect); + gBattleStruct->mega.playerSelect ^= 1; + SetMegaTriggerSpritePal(gBattleStruct->mega.triggerSpriteId, gBattleStruct->mega.playerSelect); PlaySE(SE_SELECT); } } @@ -2646,9 +2646,9 @@ static void PlayerHandleChooseMove(void) else { InitMoveSelectionsVarsAndStrings(); - gBattleStruct->playerMegaEvoSelect = FALSE; + gBattleStruct->mega.playerSelect = FALSE; if (!IsMegaTriggerSpriteActive()) - gBattleStruct->megaEvoTriggerSpriteId = 0xFF; + gBattleStruct->mega.triggerSpriteId = 0xFF; if (CanMegaEvolve(gActiveBattler)) CreateMegaTriggerSprite(gActiveBattler, 0); gBattlerControllerFuncs[gActiveBattler] = HandleChooseMoveAfterDma3; diff --git a/src/battle_interface.c b/src/battle_interface.c index 3506e6382..d8b103762 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1561,16 +1561,16 @@ void CreateMegaTriggerSprite(u8 battlerId, u8 palId) { if (GetSpriteTileStartByTag(TAG_MEGA_TRIGGER_TILE) == 0xFFFF) LoadSpriteSheet(&sSpriteSheet_MegaTrigger); - if (gBattleStruct->megaEvoTriggerSpriteId == 0xFF) + if (gBattleStruct->mega.triggerSpriteId == 0xFF) { - gBattleStruct->megaEvoTriggerSpriteId = CreateSprite(&sSpriteTemplate_MegaTrigger, + gBattleStruct->mega.triggerSpriteId = CreateSprite(&sSpriteTemplate_MegaTrigger, gSprites[gHealthboxSpriteIds[battlerId]].pos1.x, gSprites[gHealthboxSpriteIds[battlerId]].pos1.y - MEGA_TRIGGER_POS_Y_DIFF, 0); } - gSprites[gBattleStruct->megaEvoTriggerSpriteId].tBattler = battlerId; - gSprites[gBattleStruct->megaEvoTriggerSpriteId].tHide = FALSE; + gSprites[gBattleStruct->mega.triggerSpriteId].tBattler = battlerId; + gSprites[gBattleStruct->mega.triggerSpriteId].tHide = FALSE; - SetMegaTriggerSpritePal(gBattleStruct->megaEvoTriggerSpriteId, palId); + SetMegaTriggerSpritePal(gBattleStruct->mega.triggerSpriteId, palId); } static void SpriteCb_MegaTrigger(struct Sprite *sprite) @@ -1612,7 +1612,7 @@ bool32 IsMegaTriggerSpriteActive(void) void HideMegaTriggerSprite(void) { - gSprites[gBattleStruct->megaEvoTriggerSpriteId].tHide = TRUE; + gSprites[gBattleStruct->mega.triggerSpriteId].tHide = TRUE; } void DestroyMegaTriggerSprite(void) @@ -1620,9 +1620,9 @@ void DestroyMegaTriggerSprite(void) FreeSpritePaletteByTag(TAG_MEGA_TRIGGER_OFF_PAL); FreeSpritePaletteByTag(TAG_MEGA_TRIGGER_ON_PAL); FreeSpriteTilesByTag(TAG_MEGA_TRIGGER_TILE); - if (gBattleStruct->megaEvoTriggerSpriteId != 0xFF) - DestroySprite(&gSprites[gBattleStruct->megaEvoTriggerSpriteId]); - gBattleStruct->megaEvoTriggerSpriteId = 0xFF; + if (gBattleStruct->mega.triggerSpriteId != 0xFF) + DestroySprite(&gSprites[gBattleStruct->mega.triggerSpriteId]); + gBattleStruct->mega.triggerSpriteId = 0xFF; } #undef tBattler diff --git a/src/battle_main.c b/src/battle_main.c index f01d1b52b..98e28ec1d 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3099,9 +3099,9 @@ static void BattleStartClearSetData(void) gBattleStruct->field_2A0 = 0; gBattleStruct->field_2A1 = 0; - gBattleStruct->megaEvoTriggerSpriteId = 0xFF; + gBattleStruct->mega.triggerSpriteId = 0xFF; for (i = 0; i < MAX_BATTLERS_COUNT; i++) - gBattleStruct->megaEvoIndicatorSpriteId[i] = 0xFF; + gBattleStruct->mega.indicatorSpriteIds[i] = 0xFF; } void SwitchInClearSetData(void) @@ -4339,7 +4339,7 @@ static void HandleTurnActionSelectionState(void) RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 3); } - gBattleStruct->toMegaEvolve &= ~(gBitTable[BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))]); + gBattleStruct->mega.toEvolve &= ~(gBitTable[BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))]); BtlController_EmitEndBounceEffect(0); MarkBattlerForControllerExec(gActiveBattler); return; @@ -4429,7 +4429,7 @@ static void HandleTurnActionSelectionState(void) gChosenMoveByBattler[gActiveBattler] = gBattleMons[gActiveBattler].moves[*(gBattleStruct->chosenMovePositions + gActiveBattler)]; *(gBattleStruct->moveTarget + gActiveBattler) = gBattleBufferB[gActiveBattler][3]; if (gBattleBufferB[gActiveBattler][2] & RET_MEGA_EVOLUTION) - gBattleStruct->toMegaEvolve |= gBitTable[gActiveBattler]; + gBattleStruct->mega.toEvolve |= gBitTable[gActiveBattler]; gBattleCommunication[gActiveBattler]++; } break; @@ -4856,7 +4856,7 @@ static void SetActionsAndBattlersTurnOrder(void) } } gBattleMainFunc = CheckMegaEvolutionBeforeTurn; - gBattleStruct->megaEvoBattlerId = 0; + gBattleStruct->mega.battlerId = 0; return; } else @@ -4898,7 +4898,7 @@ static void SetActionsAndBattlersTurnOrder(void) } } gBattleMainFunc = CheckMegaEvolutionBeforeTurn; - gBattleStruct->megaEvoBattlerId = 0; + gBattleStruct->mega.battlerId = 0; } static void TurnValuesCleanUp(bool8 var0) @@ -4954,14 +4954,14 @@ static void CheckMegaEvolutionBeforeTurn(void) { if (!(gHitMarker & HITMARKER_RUN)) { - while (gBattleStruct->megaEvoBattlerId < gBattlersCount) + while (gBattleStruct->mega.battlerId < gBattlersCount) { - gActiveBattler = gBattlerAttacker = gBattleStruct->megaEvoBattlerId; - gBattleStruct->megaEvoBattlerId++; - if (gBattleStruct->toMegaEvolve & gBitTable[gActiveBattler] + gActiveBattler = gBattlerAttacker = gBattleStruct->mega.battlerId; + gBattleStruct->mega.battlerId++; + if (gBattleStruct->mega.toEvolve & gBitTable[gActiveBattler] && !(gProtectStructs[gActiveBattler].noValidMoves)) { - gBattleStruct->toMegaEvolve &= ~(gBitTable[gActiveBattler]); + gBattleStruct->mega.toEvolve &= ~(gBitTable[gActiveBattler]); gLastUsedItem = gBattleMons[gActiveBattler].item; BattleScriptExecute(BattleScript_MegaEvolution); return; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 4db5eb4b1..68fe31bbc 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6595,14 +6595,14 @@ static void atk76_various(void) else mon = &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]]; - gBattleStruct->speciesThatMegaEvolved[gActiveBattler] = gBattleMons[gActiveBattler].species; + gBattleStruct->mega.evolvedSpecies[gActiveBattler] = gBattleMons[gActiveBattler].species; if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_LEFT || (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT && !(gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER)))) { - gBattleStruct->playerSpeciesThatMegaEvolved = gBattleStruct->speciesThatMegaEvolved[gActiveBattler]; + gBattleStruct->mega.playerEvolvedSpecies = gBattleStruct->mega.evolvedSpecies[gActiveBattler]; } - gBattleMons[gActiveBattler].species = GetMegaEvolutionSpecies(gBattleStruct->speciesThatMegaEvolved[gActiveBattler], gBattleMons[gActiveBattler].item); + gBattleMons[gActiveBattler].species = GetMegaEvolutionSpecies(gBattleStruct->mega.evolvedSpecies[gActiveBattler], gBattleMons[gActiveBattler].item); SetMonData(mon, MON_DATA_SPECIES, &gBattleMons[gActiveBattler].species); PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gActiveBattler].species); @@ -6620,8 +6620,8 @@ static void atk76_various(void) gBattleMons[gActiveBattler].type2 = gBaseStats[gBattleMons[gActiveBattler].species].type2; UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], mon, HEALTHBOX_ALL); - gBattleStruct->alreadyMegaEvolved[GetBattlerPosition(gActiveBattler)] = TRUE; - gBattleStruct->megaEvolvedPartyIds[GetBattlerSide(gActiveBattler)] |= gBitTable[gBattlerPartyIndexes[gActiveBattler]]; + gBattleStruct->mega.alreadyEvolved[GetBattlerPosition(gActiveBattler)] = TRUE; + gBattleStruct->mega.evolvedPartyIds[GetBattlerSide(gActiveBattler)] |= gBitTable[gBattlerPartyIndexes[gActiveBattler]]; BtlController_EmitSetMonData(0, REQUEST_ALL_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]], sizeof(struct BattlePokemon), &gBattleMons[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); diff --git a/src/battle_util.c b/src/battle_util.c index 549f16bac..ffa409d7f 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -5607,12 +5607,12 @@ bool32 CanMegaEvolve(u8 battlerId) u8 partnerPosition = GetBattlerPosition(BATTLE_PARTNER(battlerId)); // Check if trainer already mega evolved a pokemon. - if (gBattleStruct->alreadyMegaEvolved[battlerPosition]) + if (gBattleStruct->mega.alreadyEvolved[battlerPosition]) return FALSE; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { if (IsPartnerMonFromSameTrainer(battlerId) - && (gBattleStruct->alreadyMegaEvolved[partnerPosition] || (gBattleStruct->toMegaEvolve & gBitTable[BATTLE_PARTNER(battlerId)]))) + && (gBattleStruct->mega.alreadyEvolved[partnerPosition] || (gBattleStruct->mega.toEvolve & gBitTable[BATTLE_PARTNER(battlerId)]))) return FALSE; } @@ -5641,10 +5641,10 @@ bool32 CanMegaEvolve(u8 battlerId) void UndoMegaEvolution(u8 monId) { - if (gBattleStruct->megaEvolvedPartyIds[B_SIDE_PLAYER] & gBitTable[monId]) + if (gBattleStruct->mega.evolvedPartyIds[B_SIDE_PLAYER] & gBitTable[monId]) { - gBattleStruct->megaEvolvedPartyIds[B_SIDE_PLAYER] &= ~(gBitTable[monId]); - SetMonData(&gPlayerParty[monId], MON_DATA_SPECIES, &gBattleStruct->playerSpeciesThatMegaEvolved); + gBattleStruct->mega.evolvedPartyIds[B_SIDE_PLAYER] &= ~(gBitTable[monId]); + SetMonData(&gPlayerParty[monId], MON_DATA_SPECIES, &gBattleStruct->mega.playerEvolvedSpecies); CalculateMonStats(&gPlayerParty[monId]); } }