Refactor GF's idiotic coding

This commit is contained in:
DizzyEggg 2019-01-27 13:52:02 +01:00
parent 88b788bfab
commit abd518b668
4 changed files with 70 additions and 187 deletions

View file

@ -481,12 +481,10 @@ struct BattleStruct
{ {
u8 turnEffectsTracker; u8 turnEffectsTracker;
u8 turnEffectsBattlerId; u8 turnEffectsBattlerId;
u8 unused_0;
u8 turnCountersTracker; u8 turnCountersTracker;
u8 wrappedMove[MAX_BATTLERS_COUNT * 2]; // Leftover from Ruby's ewram access. u16 wrappedMove[MAX_BATTLERS_COUNT];
u8 moveTarget[MAX_BATTLERS_COUNT]; u8 moveTarget[MAX_BATTLERS_COUNT];
u8 expGetterMonId; u8 expGetterMonId;
u8 unused_1;
u8 wildVictorySong; u8 wildVictorySong;
u8 dynamicMoveType; u8 dynamicMoveType;
u8 wrappedBy[MAX_BATTLERS_COUNT]; u8 wrappedBy[MAX_BATTLERS_COUNT];
@ -507,7 +505,6 @@ struct BattleStruct
u8 field_60[4][3]; u8 field_60[4][3];
u8 runTries; u8 runTries;
u8 caughtMonNick[POKEMON_NAME_LENGTH + 1]; u8 caughtMonNick[POKEMON_NAME_LENGTH + 1];
u8 unused_2;
u8 safariGoNearCounter; u8 safariGoNearCounter;
u8 safariPkblThrowCounter; u8 safariPkblThrowCounter;
u8 safariEscapeFactor; u8 safariEscapeFactor;
@ -517,12 +514,9 @@ struct BattleStruct
u8 formToChangeInto; u8 formToChangeInto;
u8 chosenMovePositions[MAX_BATTLERS_COUNT]; u8 chosenMovePositions[MAX_BATTLERS_COUNT];
u8 stateIdAfterSelScript[MAX_BATTLERS_COUNT]; u8 stateIdAfterSelScript[MAX_BATTLERS_COUNT];
u8 unused_3[3];
u8 field_8B; // related to player's pokemon switching u8 field_8B; // related to player's pokemon switching
u8 unused_4[2];
u8 stringMoveType; u8 stringMoveType;
u8 expGetterBattlerId; u8 expGetterBattlerId;
u8 unused_5;
u8 field_91; // related to gAbsentBattlerFlags, possibly absent flags turn ago? u8 field_91; // related to gAbsentBattlerFlags, possibly absent flags turn ago?
u8 field_92; // battle palace related u8 field_92; // battle palace related
u8 field_93; // related to choosing pokemon? u8 field_93; // related to choosing pokemon?
@ -530,7 +524,7 @@ struct BattleStruct
u8 wallyMovesState; u8 wallyMovesState;
u8 wallyWaitFrames; u8 wallyWaitFrames;
u8 wallyMoveFrames; u8 wallyMoveFrames;
u8 lastTakenMove[MAX_BATTLERS_COUNT * 2 * 2]; // Last move that a battler was hit with. This field seems to erroneously take 16 bytes instead of 8. u16 lastTakenMove[MAX_BATTLERS_COUNT]; // Last move that a battler was hit with.
u16 hpOnSwitchout[2]; u16 hpOnSwitchout[2];
u32 savedBattleTypeFlags; u32 savedBattleTypeFlags;
u8 abilityPreventingSwitchout; u8 abilityPreventingSwitchout;
@ -539,7 +533,7 @@ struct BattleStruct
bool8 anyMonHasTransformed; bool8 anyMonHasTransformed;
void (*savedCallback)(void); void (*savedCallback)(void);
u16 usedHeldItems[MAX_BATTLERS_COUNT]; u16 usedHeldItems[MAX_BATTLERS_COUNT];
u8 chosenItem[MAX_BATTLERS_COUNT]; // why is this an u8? u16 chosenItem[MAX_BATTLERS_COUNT];
u8 AI_itemType[2]; u8 AI_itemType[2];
u8 AI_itemFlags[2]; u8 AI_itemFlags[2];
u16 choicedMove[MAX_BATTLERS_COUNT]; u16 choicedMove[MAX_BATTLERS_COUNT];
@ -548,9 +542,8 @@ struct BattleStruct
u8 switchInItemsCounter; u8 switchInItemsCounter;
u8 arenaTurnCounter; u8 arenaTurnCounter;
u8 turnSideTracker; u8 turnSideTracker;
u8 unused_6[3];
u8 givenExpMons; // Bits for enemy party's pokemon that gave exp to player's party. u8 givenExpMons; // Bits for enemy party's pokemon that gave exp to player's party.
u8 lastTakenMoveFrom[MAX_BATTLERS_COUNT * MAX_BATTLERS_COUNT * 2]; // a 3-D array [target][attacker][byte] u16 lastTakenMoveFrom[MAX_BATTLERS_COUNT][MAX_BATTLERS_COUNT]; // a 2-D array [target][attacker]
u16 castformPalette[MAX_BATTLERS_COUNT][16]; u16 castformPalette[MAX_BATTLERS_COUNT][16];
u8 field_180; // weird field, used in battle_main.c, once accessed as an array of u32 overwriting the field below u8 field_180; // weird field, used in battle_main.c, once accessed as an array of u32 overwriting the field below
u8 field_181; u8 field_181;
@ -563,7 +556,6 @@ struct BattleStruct
u8 atkCancellerTracker; u8 atkCancellerTracker;
struct BattleTvMovePoints tvMovePoints; struct BattleTvMovePoints tvMovePoints;
struct BattleTv tv; struct BattleTv tv;
u8 unused_7[0x28];
u8 AI_monToSwitchIntoId[MAX_BATTLERS_COUNT]; u8 AI_monToSwitchIntoId[MAX_BATTLERS_COUNT];
s8 arenaMindPoints[2]; s8 arenaMindPoints[2];
s8 arenaSkillPoints[2]; s8 arenaSkillPoints[2];

View file

@ -2871,20 +2871,20 @@ static void BattleMainCB1(void)
static void BattleStartClearSetData(void) static void BattleStartClearSetData(void)
{ {
s32 i; s32 i;
u32 j;
u8 *dataPtr;
TurnValuesCleanUp(FALSE); TurnValuesCleanUp(FALSE);
SpecialStatusesClear(); SpecialStatusesClear();
memset(&gDisableStructs, 0, sizeof(gDisableStructs));
memset(&gFieldTimers, 0, sizeof(gFieldTimers));
memset(&gSideStatuses, 0, sizeof(gSideStatuses));
memset(&gSideTimers, 0, sizeof(gSideTimers));
memset(&gWishFutureKnock, 0, sizeof(gWishFutureKnock));
memset(&gBattleResults, 0, sizeof(gBattleResults));
for (i = 0; i < MAX_BATTLERS_COUNT; i++) for (i = 0; i < MAX_BATTLERS_COUNT; i++)
{ {
gStatuses3[i] = 0; gStatuses3[i] = 0;
dataPtr = (u8 *)&gDisableStructs[i];
for (j = 0; j < sizeof(struct DisableStruct); j++)
dataPtr[j] = 0;
gDisableStructs[i].isFirstTurn = 2; gDisableStructs[i].isFirstTurn = 2;
gLastMoves[i] = 0; gLastMoves[i] = 0;
gLastLandedMoves[i] = 0; gLastLandedMoves[i] = 0;
@ -2895,29 +2895,23 @@ static void BattleStartClearSetData(void)
gLastPrintedMoves[i] = 0; gLastPrintedMoves[i] = 0;
gBattleResources->flags->flags[i] = 0; gBattleResources->flags->flags[i] = 0;
gPalaceSelectionBattleScripts[i] = 0; gPalaceSelectionBattleScripts[i] = 0;
gBattleStruct->lastTakenMove[i] = 0;
gBattleStruct->usedHeldItems[i] = 0;
gBattleStruct->choicedMove[i] = 0;
gBattleStruct->changedItems[i] = 0;
gBattleStruct->lastTakenMoveFrom[i][0] = 0;
gBattleStruct->lastTakenMoveFrom[i][1] = 0;
gBattleStruct->lastTakenMoveFrom[i][2] = 0;
gBattleStruct->lastTakenMoveFrom[i][3] = 0;
gBattleStruct->AI_monToSwitchIntoId[i] = PARTY_SIZE;
} }
gLastUsedMove = 0; gLastUsedMove = 0;
gFieldStatuses = 0; gFieldStatuses = 0;
memset(&gFieldTimers, 0, sizeof(gFieldTimers));
for (i = 0; i < 2; i++)
{
gSideStatuses[i] = 0;
dataPtr = (u8 *)&gSideTimers[i];
for (j = 0; j < sizeof(struct SideTimer); j++)
dataPtr[j] = 0;
}
gBattlerAttacker = 0; gBattlerAttacker = 0;
gBattlerTarget = 0; gBattlerTarget = 0;
gBattleWeather = 0; gBattleWeather = 0;
dataPtr = (u8 *)&gWishFutureKnock;
for (i = 0; i < sizeof(struct WishFutureKnock); i++)
dataPtr[i] = 0;
gHitMarker = 0; gHitMarker = 0;
if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED))
@ -2926,7 +2920,9 @@ static void BattleStartClearSetData(void)
gHitMarker |= HITMARKER_NO_ANIMATIONS; gHitMarker |= HITMARKER_NO_ANIMATIONS;
} }
else if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) && GetBattleSceneInRecordedBattle()) else if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) && GetBattleSceneInRecordedBattle())
{
gHitMarker |= HITMARKER_NO_ANIMATIONS; gHitMarker |= HITMARKER_NO_ANIMATIONS;
}
gBattleScripting.battleStyle = gSaveBlock2Ptr->optionsBattleStyle; gBattleScripting.battleStyle = gSaveBlock2Ptr->optionsBattleStyle;
gBattleScripting.expOnCatch = (B_EXP_CATCH >= GEN_6); gBattleScripting.expOnCatch = (B_EXP_CATCH >= GEN_6);
@ -2952,37 +2948,16 @@ static void BattleStartClearSetData(void)
gBattleStruct->runTries = 0; gBattleStruct->runTries = 0;
gBattleStruct->safariGoNearCounter = 0; gBattleStruct->safariGoNearCounter = 0;
gBattleStruct->safariPkblThrowCounter = 0; gBattleStruct->safariPkblThrowCounter = 0;
*(&gBattleStruct->safariCatchFactor) = gBaseStats[GetMonData(&gEnemyParty[0], MON_DATA_SPECIES)].catchRate * 100 / 1275; gBattleStruct->safariCatchFactor = gBaseStats[GetMonData(&gEnemyParty[0], MON_DATA_SPECIES)].catchRate * 100 / 1275;
gBattleStruct->safariEscapeFactor = 3; gBattleStruct->safariEscapeFactor = 3;
gBattleStruct->wildVictorySong = 0; gBattleStruct->wildVictorySong = 0;
gBattleStruct->moneyMultiplier = 1; gBattleStruct->moneyMultiplier = 1;
for (i = 0; i < 8; i++)
{
*((u8 *)gBattleStruct->lastTakenMove + i) = 0;
*((u8 *)gBattleStruct->usedHeldItems + i) = 0;
*((u8 *)gBattleStruct->choicedMove + i) = 0;
*((u8 *)gBattleStruct->changedItems + i) = 0;
*(i + 0 * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(i + 1 * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(i + 2 * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(i + 3 * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
}
for (i = 0; i < MAX_BATTLERS_COUNT; i++)
{
*(gBattleStruct->AI_monToSwitchIntoId + i) = PARTY_SIZE;
}
gBattleStruct->givenExpMons = 0; gBattleStruct->givenExpMons = 0;
gBattleStruct->field_92 = 0; gBattleStruct->field_92 = 0;
gRandomTurnNumber = Random(); gRandomTurnNumber = Random();
dataPtr = (u8 *)(&gBattleResults);
for (i = 0; i < sizeof(struct BattleResults); i++)
dataPtr[i] = 0;
gBattleResults.shinyWildMon = IsMonShiny(&gEnemyParty[0]); gBattleResults.shinyWildMon = IsMonShiny(&gEnemyParty[0]);
gBattleStruct->arenaLostPlayerMons = 0; gBattleStruct->arenaLostPlayerMons = 0;
@ -2995,9 +2970,8 @@ static void BattleStartClearSetData(void)
void SwitchInClearSetData(void) void SwitchInClearSetData(void)
{ {
struct DisableStruct disableStructCopy = gDisableStructs[gActiveBattler];
s32 i; s32 i;
u8 *ptr; struct DisableStruct disableStructCopy = gDisableStructs[gActiveBattler];
if (gBattleMoves[gCurrentMove].effect != EFFECT_BATON_PASS) if (gBattleMoves[gCurrentMove].effect != EFFECT_BATON_PASS)
{ {
@ -3049,9 +3023,7 @@ void SwitchInClearSetData(void)
gActionSelectionCursor[gActiveBattler] = 0; gActionSelectionCursor[gActiveBattler] = 0;
gMoveSelectionCursor[gActiveBattler] = 0; gMoveSelectionCursor[gActiveBattler] = 0;
ptr = (u8 *)&gDisableStructs[gActiveBattler]; memset(&gDisableStructs[gActiveBattler], 0, sizeof(struct DisableStruct));
for (i = 0; i < sizeof(struct DisableStruct); i++)
ptr[i] = 0;
if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS) if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS)
{ {
@ -3072,33 +3044,23 @@ void SwitchInClearSetData(void)
gLastPrintedMoves[gActiveBattler] = 0; gLastPrintedMoves[gActiveBattler] = 0;
gLastHitBy[gActiveBattler] = 0xFF; gLastHitBy[gActiveBattler] = 0xFF;
*(gBattleStruct->lastTakenMove + gActiveBattler * 2 + 0) = 0; gBattleStruct->lastTakenMove[gActiveBattler] = 0;
*(gBattleStruct->lastTakenMove + gActiveBattler * 2 + 1) = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][0] = 0;
*(0 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][1] = 0;
*(0 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][2] = 0;
*(1 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0;
*(1 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
*(2 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(2 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
*(3 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(3 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
gBattleStruct->field_92 &= ~(gBitTable[gActiveBattler]); gBattleStruct->field_92 &= ~(gBitTable[gActiveBattler]);
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
if (i != gActiveBattler && GetBattlerSide(i) != GetBattlerSide(gActiveBattler)) if (i != gActiveBattler && GetBattlerSide(i) != GetBattlerSide(gActiveBattler))
{ gBattleStruct->lastTakenMove[i] = 0;
*(gBattleStruct->lastTakenMove + i * 2 + 0) = 0;
*(gBattleStruct->lastTakenMove + i * 2 + 1) = 0; gBattleStruct->lastTakenMoveFrom[i][gActiveBattler] = 0;
}
*(i * 8 + gActiveBattler * 2 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(i * 8 + gActiveBattler * 2 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
} }
*(u8*)((u8*)(&gBattleStruct->choicedMove[gActiveBattler]) + 0) = 0; gBattleStruct->choicedMove[gActiveBattler] = 0;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gActiveBattler]) + 1) = 0;
gBattleResources->flags->flags[gActiveBattler] = 0; gBattleResources->flags->flags[gActiveBattler] = 0;
gCurrentMove = 0; gCurrentMove = 0;
gBattleStruct->arenaTurnCounter = 0xFF; gBattleStruct->arenaTurnCounter = 0xFF;
@ -3110,7 +3072,6 @@ void SwitchInClearSetData(void)
void FaintClearSetData(void) void FaintClearSetData(void)
{ {
s32 i; s32 i;
u8 *ptr;
for (i = 0; i < NUM_BATTLE_STATS; i++) for (i = 0; i < NUM_BATTLE_STATS; i++)
gBattleMons[gActiveBattler].statStages[i] = 6; gBattleMons[gActiveBattler].statStages[i] = 6;
@ -3131,9 +3092,7 @@ void FaintClearSetData(void)
gActionSelectionCursor[gActiveBattler] = 0; gActionSelectionCursor[gActiveBattler] = 0;
gMoveSelectionCursor[gActiveBattler] = 0; gMoveSelectionCursor[gActiveBattler] = 0;
ptr = (u8 *)&gDisableStructs[gActiveBattler]; memset(&gDisableStructs[gActiveBattler], 0, sizeof(struct DisableStruct));
for (i = 0; i < sizeof(struct DisableStruct); i++)
ptr[i] = 0;
gProtectStructs[gActiveBattler].protected = 0; gProtectStructs[gActiveBattler].protected = 0;
gProtectStructs[gActiveBattler].spikyShielded = 0; gProtectStructs[gActiveBattler].spikyShielded = 0;
@ -3170,31 +3129,21 @@ void FaintClearSetData(void)
gLastPrintedMoves[gActiveBattler] = 0; gLastPrintedMoves[gActiveBattler] = 0;
gLastHitBy[gActiveBattler] = 0xFF; gLastHitBy[gActiveBattler] = 0xFF;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gActiveBattler]) + 0) = 0; gBattleStruct->choicedMove[gActiveBattler] = 0;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gActiveBattler]) + 1) = 0; gBattleStruct->lastTakenMove[gActiveBattler] = 0;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][0] = 0;
*(gBattleStruct->lastTakenMove + gActiveBattler * 2 + 0) = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][1] = 0;
*(gBattleStruct->lastTakenMove + gActiveBattler * 2 + 1) = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][2] = 0;
*(0 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0;
*(0 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
*(1 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(1 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
*(2 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(2 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
*(3 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(3 * 2 + gActiveBattler * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
gBattleStruct->field_92 &= ~(gBitTable[gActiveBattler]); gBattleStruct->field_92 &= ~(gBitTable[gActiveBattler]);
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
if (i != gActiveBattler && GetBattlerSide(i) != GetBattlerSide(gActiveBattler)) if (i != gActiveBattler && GetBattlerSide(i) != GetBattlerSide(gActiveBattler))
{ gBattleStruct->lastTakenMove[i] = 0;
*(gBattleStruct->lastTakenMove + i * 2 + 0) = 0;
*(gBattleStruct->lastTakenMove + i * 2 + 1) = 0; gBattleStruct->lastTakenMoveFrom[i][gActiveBattler] = 0;
}
*(i * 8 + gActiveBattler * 2 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = 0;
*(i * 8 + gActiveBattler * 2 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = 0;
} }
gBattleResources->flags->flags[gActiveBattler] = 0; gBattleResources->flags->flags[gActiveBattler] = 0;
@ -4612,7 +4561,6 @@ static void SetActionsAndBattlersTurnOrder(void)
static void TurnValuesCleanUp(bool8 var0) static void TurnValuesCleanUp(bool8 var0)
{ {
s32 i; s32 i;
u8 *dataPtr;
for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++)
{ {
@ -4625,9 +4573,7 @@ static void TurnValuesCleanUp(bool8 var0)
} }
else else
{ {
dataPtr = (u8*)(&gProtectStructs[gActiveBattler]); memset(&gProtectStructs[gActiveBattler], 0, sizeof(struct ProtectStruct));
for (i = 0; i < sizeof(struct ProtectStruct); i++)
dataPtr[i] = 0;
if (gDisableStructs[gActiveBattler].isFirstTurn) if (gDisableStructs[gActiveBattler].isFirstTurn)
gDisableStructs[gActiveBattler].isFirstTurn--; gDisableStructs[gActiveBattler].isFirstTurn--;
@ -4652,14 +4598,7 @@ static void TurnValuesCleanUp(bool8 var0)
static void SpecialStatusesClear(void) static void SpecialStatusesClear(void)
{ {
for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) memset(&gSpecialStatuses, 0, sizeof(gSpecialStatuses));
{
s32 i;
u8 *dataPtr = (u8*)(&gSpecialStatuses[gActiveBattler]);
for (i = 0; i < sizeof(struct SpecialStatus); i++)
dataPtr[i] = 0;
}
} }
static void CheckMegaEvolutionBeforeTurn(void) static void CheckMegaEvolutionBeforeTurn(void)

View file

@ -2383,9 +2383,8 @@ void SetMoveEffect(bool8 primary, u8 certain)
else else
gDisableStructs[gEffectBattler].wrapTurns = ((Random() % 2) + 4); gDisableStructs[gEffectBattler].wrapTurns = ((Random() % 2) + 4);
*(gBattleStruct->wrappedMove + gEffectBattler * 2 + 0) = gCurrentMove; gBattleStruct->wrappedMove[gEffectBattler] = gCurrentMove;
*(gBattleStruct->wrappedMove + gEffectBattler * 2 + 1) = gCurrentMove >> 8; gBattleStruct->wrappedBy[gEffectBattler] = gBattlerAttacker;
*(gBattleStruct->wrappedBy + gEffectBattler) = gBattlerAttacker;
BattleScriptPush(gBattlescriptCurrInstr + 1); BattleScriptPush(gBattlescriptCurrInstr + 1);
gBattlescriptCurrInstr = sMoveEffectBS_Ptrs[gBattleCommunication[MOVE_EFFECT_BYTE]]; gBattlescriptCurrInstr = sMoveEffectBS_Ptrs[gBattleCommunication[MOVE_EFFECT_BYTE]];
@ -2548,8 +2547,7 @@ void SetMoveEffect(bool8 primary, u8 certain)
} }
else else
{ {
u16* changedItem = &gBattleStruct->changedItems[gBattlerAttacker]; gLastUsedItem = gBattleStruct->changedItems[gBattlerAttacker] = gBattleMons[gBattlerTarget].item;
gLastUsedItem = *changedItem = gBattleMons[gBattlerTarget].item;
gBattleMons[gBattlerTarget].item = 0; gBattleMons[gBattlerTarget].item = 0;
gActiveBattler = gBattlerAttacker; gActiveBattler = gBattlerAttacker;
@ -2563,8 +2561,7 @@ void SetMoveEffect(bool8 primary, u8 certain)
BattleScriptPush(gBattlescriptCurrInstr + 1); BattleScriptPush(gBattlescriptCurrInstr + 1);
gBattlescriptCurrInstr = BattleScript_ItemSteal; gBattlescriptCurrInstr = BattleScript_ItemSteal;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerTarget]) + 0) = 0; gBattleStruct->choicedMove[gBattlerTarget] = 0;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerTarget]) + 1) = 0;
} }
} }
@ -2673,8 +2670,7 @@ void SetMoveEffect(bool8 primary, u8 certain)
BattleScriptPush(gBattlescriptCurrInstr + 1); BattleScriptPush(gBattlescriptCurrInstr + 1);
gBattlescriptCurrInstr = BattleScript_KnockedOff; gBattlescriptCurrInstr = BattleScript_KnockedOff;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gEffectBattler]) + 0) = 0; gBattleStruct->choicedMove[gEffectBattler] = 0;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gEffectBattler]) + 1) = 0;
} }
else else
{ {
@ -4228,11 +4224,10 @@ static void atk49_moveend(void)
case ATK49_CHANGED_ITEMS: // changed held items case ATK49_CHANGED_ITEMS: // changed held items
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
u16* changedItem = &gBattleStruct->changedItems[i]; if (gBattleStruct->changedItems[i] != 0)
if (*changedItem != 0)
{ {
gBattleMons[i].item = *changedItem; gBattleMons[i].item = gBattleStruct->changedItems[i];
*changedItem = 0; gBattleStruct->changedItems[i] = 0;
} }
} }
gBattleScripting.atk49_state++; gBattleScripting.atk49_state++;
@ -4354,18 +4349,8 @@ static void atk49_moveend(void)
&& gBattlerAttacker != gBattlerTarget && !(gHitMarker & HITMARKER_FAINTED(gBattlerTarget)) && gBattlerAttacker != gBattlerTarget && !(gHitMarker & HITMARKER_FAINTED(gBattlerTarget))
&& !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT))
{ {
u8 target, attacker; gBattleStruct->lastTakenMove[gBattlerTarget] = gChosenMove;
gBattleStruct->lastTakenMoveFrom[gBattlerTarget][gBattlerAttacker] = gChosenMove;
*(gBattleStruct->lastTakenMove + gBattlerTarget * 2 + 0) = gChosenMove;
*(gBattleStruct->lastTakenMove + gBattlerTarget * 2 + 1) = gChosenMove >> 8;
target = gBattlerTarget;
attacker = gBattlerAttacker;
*(attacker * 2 + target * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) = gChosenMove;
target = gBattlerTarget;
attacker = gBattlerAttacker;
*(attacker * 2 + target * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) = gChosenMove >> 8;
} }
gBattleScripting.atk49_state++; gBattleScripting.atk49_state++;
break; break;
@ -5790,12 +5775,8 @@ static void atk69_setgravity(void)
static void atk6A_removeitem(void) static void atk6A_removeitem(void)
{ {
u16 *usedHeldItem;
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
gBattleStruct->usedHeldItems[gActiveBattler] = gBattleMons[gActiveBattler].item;
usedHeldItem = &gBattleStruct->usedHeldItems[gActiveBattler];
*usedHeldItem = gBattleMons[gActiveBattler].item;
gBattleMons[gActiveBattler].item = 0; gBattleMons[gActiveBattler].item = 0;
BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gActiveBattler].item); BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gActiveBattler].item);
@ -6385,22 +6366,18 @@ static void atk76_various(void)
case VARIOUS_UPDATE_CHOICE_MOVE_ON_LVL_UP: case VARIOUS_UPDATE_CHOICE_MOVE_ON_LVL_UP:
if (gBattlerPartyIndexes[0] == gBattleStruct->expGetterMonId || gBattlerPartyIndexes[2] == gBattleStruct->expGetterMonId) if (gBattlerPartyIndexes[0] == gBattleStruct->expGetterMonId || gBattlerPartyIndexes[2] == gBattleStruct->expGetterMonId)
{ {
u16 *choicedMove;
if (gBattlerPartyIndexes[0] == gBattleStruct->expGetterMonId) if (gBattlerPartyIndexes[0] == gBattleStruct->expGetterMonId)
gActiveBattler = 0; gActiveBattler = 0;
else else
gActiveBattler = 2; gActiveBattler = 2;
choicedMove = &gBattleStruct->choicedMove[gActiveBattler];
for (i = 0; i < MAX_MON_MOVES; i++) for (i = 0; i < MAX_MON_MOVES; i++)
{ {
if (gBattleMons[gActiveBattler].moves[i] == *choicedMove) if (gBattleMons[gActiveBattler].moves[i] == gBattleStruct->choicedMove[gActiveBattler])
break; break;
} }
if (i == MAX_MON_MOVES) if (i == MAX_MON_MOVES)
*choicedMove = 0; gBattleStruct->choicedMove[gActiveBattler] = 0;
} }
break; break;
case 7: case 7:
@ -7371,18 +7348,13 @@ static void atk7C_trymirrormove(void)
s32 validMovesCount; s32 validMovesCount;
s32 i; s32 i;
u16 move; u16 move;
u16 movesArray[4]; u16 movesArray[4] = {0};
for (i = 0; i < 3; i++)
movesArray[i] = 0;
for (validMovesCount = 0, i = 0; i < gBattlersCount; i++) for (validMovesCount = 0, i = 0; i < gBattlersCount; i++)
{ {
if (i != gBattlerAttacker) if (i != gBattlerAttacker)
{ {
move = *(i * 2 + gBattlerAttacker * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 0) move = gBattleStruct->lastTakenMoveFrom[gBattlerAttacker][i];
| (*(i * 2 + gBattlerAttacker * 8 + (u8*)(gBattleStruct->lastTakenMoveFrom) + 1) << 8);
if (move != 0 && move != 0xFFFF) if (move != 0 && move != 0xFFFF)
{ {
movesArray[validMovesCount] = move; movesArray[validMovesCount] = move;
@ -7391,9 +7363,7 @@ static void atk7C_trymirrormove(void)
} }
} }
move = *(gBattleStruct->lastTakenMove + gBattlerAttacker * 2 + 0) move = gBattleStruct->lastTakenMove[gBattlerAttacker];
| (*(gBattleStruct->lastTakenMove + gBattlerAttacker * 2 + 1) << 8);
if (move != 0 && move != 0xFFFF) if (move != 0 && move != 0xFFFF)
{ {
gHitMarker &= ~(HITMARKER_ATTACKSTRING_PRINTED); gHitMarker &= ~(HITMARKER_ATTACKSTRING_PRINTED);
@ -9534,13 +9504,7 @@ static void atkBE_rapidspinfree(void)
gBattleScripting.battler = gBattlerTarget; gBattleScripting.battler = gBattlerTarget;
gBattleMons[gBattlerAttacker].status2 &= ~(STATUS2_WRAPPED); gBattleMons[gBattlerAttacker].status2 &= ~(STATUS2_WRAPPED);
gBattlerTarget = *(gBattleStruct->wrappedBy + gBattlerAttacker); gBattlerTarget = *(gBattleStruct->wrappedBy + gBattlerAttacker);
PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleStruct->wrappedMove[gBattlerAttacker]);
gBattleTextBuff1[0] = B_BUFF_PLACEHOLDER_BEGIN;
gBattleTextBuff1[1] = B_BUFF_MOVE;
gBattleTextBuff1[2] = *(gBattleStruct->wrappedMove + gBattlerAttacker * 2 + 0);
gBattleTextBuff1[3] = *(gBattleStruct->wrappedMove + gBattlerAttacker * 2 + 1);
gBattleTextBuff1[4] = B_BUFF_EOS;
BattleScriptPushCursor(); BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_WrapFree; gBattlescriptCurrInstr = BattleScript_WrapFree;
} }
@ -9941,11 +9905,8 @@ static void atkD2_tryswapitems(void) // trick
BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gBattlerTarget].item); BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gBattlerTarget].item);
MarkBattlerForControllerExec(gBattlerTarget); MarkBattlerForControllerExec(gBattlerTarget);
*(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerTarget]) + 0) = 0; gBattleStruct->choicedMove[gBattlerTarget] = 0;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerTarget]) + 1) = 0; gBattleStruct->choicedMove[gBattlerAttacker] = 0;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerAttacker]) + 0) = 0;
*(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerAttacker]) + 1) = 0;
gBattlescriptCurrInstr += 5; gBattlescriptCurrInstr += 5;

View file

@ -1496,14 +1496,9 @@ u8 DoBattlerEndTurnEffects(void)
{ {
if (--gDisableStructs[gActiveBattler].wrapTurns != 0) // damaged by wrap if (--gDisableStructs[gActiveBattler].wrapTurns != 0) // damaged by wrap
{ {
// This is the only way I could get this array access to match. gBattleScripting.animArg1 = gBattleStruct->wrappedMove[gActiveBattler];
gBattleScripting.animArg1 = *(gBattleStruct->wrappedMove + gActiveBattler * 2 + 0); gBattleScripting.animArg2 = gBattleStruct->wrappedMove[gActiveBattler] >> 8;
gBattleScripting.animArg2 = *(gBattleStruct->wrappedMove + gActiveBattler * 2 + 1); PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleStruct->wrappedMove[gActiveBattler]);
gBattleTextBuff1[0] = B_BUFF_PLACEHOLDER_BEGIN;
gBattleTextBuff1[1] = B_BUFF_MOVE;
gBattleTextBuff1[2] = *(gBattleStruct->wrappedMove + gActiveBattler * 2 + 0);
gBattleTextBuff1[3] = *(gBattleStruct->wrappedMove + gActiveBattler * 2 + 1);
gBattleTextBuff1[4] = EOS;
gBattlescriptCurrInstr = BattleScript_WrapTurnDmg; gBattlescriptCurrInstr = BattleScript_WrapTurnDmg;
if (GetBattlerHoldEffect(gBattleStruct->wrappedBy[gActiveBattler], TRUE) == HOLD_EFFECT_BINDING_BAND) if (GetBattlerHoldEffect(gBattleStruct->wrappedBy[gActiveBattler], TRUE) == HOLD_EFFECT_BINDING_BAND)
gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8;
@ -1516,11 +1511,7 @@ u8 DoBattlerEndTurnEffects(void)
else // broke free else // broke free
{ {
gBattleMons[gActiveBattler].status2 &= ~(STATUS2_WRAPPED); gBattleMons[gActiveBattler].status2 &= ~(STATUS2_WRAPPED);
gBattleTextBuff1[0] = B_BUFF_PLACEHOLDER_BEGIN; PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleStruct->wrappedMove[gActiveBattler]);
gBattleTextBuff1[1] = B_BUFF_MOVE;
gBattleTextBuff1[2] = *(gBattleStruct->wrappedMove + gActiveBattler * 2 + 0);
gBattleTextBuff1[3] = *(gBattleStruct->wrappedMove + gActiveBattler * 2 + 1);
gBattleTextBuff1[4] = EOS;
gBattlescriptCurrInstr = BattleScript_WrapEnds; gBattlescriptCurrInstr = BattleScript_WrapEnds;
} }
BattleScriptExecute(gBattlescriptCurrInstr); BattleScriptExecute(gBattlescriptCurrInstr);