Convert mega related struct fields to a seperate struct

This commit is contained in:
DizzyEggg 2018-09-20 17:33:27 +02:00
parent 13e434f874
commit 2bae70a66b
6 changed files with 51 additions and 46 deletions

View File

@ -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) \

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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]);
}
}