diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/battle_ai_switch_items.c | 107 | ||||
-rw-r--r-- | src/battle_controller_opponent.c | 14 | ||||
-rw-r--r-- | src/battle_main.c | 77 | ||||
-rw-r--r-- | src/battle_script_commands.c | 34 | ||||
-rw-r--r-- | src/battle_util.c | 20 |
5 files changed, 130 insertions, 122 deletions
diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 9de1e9b1f..b68a60c74 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -13,6 +13,7 @@ #include "constants/items.h" #include "constants/moves.h" #include "constants/species.h" +#include "constants/item_effects.h" extern u8 gUnknown_02023A14_50; @@ -39,7 +40,7 @@ static bool8 ShouldSwitchIfPerishSong(void) if (gStatuses3[gActiveBattler] & STATUS3_PERISH_SONG && gDisableStructs[gActiveBattler].perishSongTimer1 == 0) { - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = 6; // gBattleStruct->AI_monToSwitchIntoId[GetBattlerPosition(gActiveBattler)] = 6; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler)) / 2] = 6; BtlController_EmitTwoReturnValues(1, 2, 0); return TRUE; } @@ -92,7 +93,7 @@ static bool8 ShouldSwitchIfWonderGuard(void) if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE && Random() % 3 < 2) { // We found a mon. - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = i; // gBattleStruct->AI_monToSwitchIntoId[GetBattlerPosition(gActiveBattler)] = i; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] = i; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } @@ -158,9 +159,9 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) continue; if (i == gBattlerPartyIndexes[battlerIn2]) continue; - if (i == ewram16068arr(battlerIn1)) + if (i == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn1]) continue; - if (i == ewram16068arr(battlerIn2)) + if (i == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn2]) continue; species = GetMonData(&gEnemyParty[i], MON_DATA_SPECIES); @@ -172,7 +173,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) if (absorbingTypeAbility == monAbility && Random() & 1) { // we found a mon - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = i; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] = i; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } @@ -192,13 +193,13 @@ static bool8 ShouldSwitchIfNaturalCure(void) if ((gLastLandedMoves[gActiveBattler] == 0 || gLastLandedMoves[gActiveBattler] == 0xFFFF) && Random() & 1) { - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = 6; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] = 6; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].power == 0 && Random() & 1) { - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = 6; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] = 6; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } @@ -209,7 +210,7 @@ static bool8 ShouldSwitchIfNaturalCure(void) return TRUE; if (Random() & 1) { - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = 6; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] = 6; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } @@ -328,9 +329,9 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) continue; if (i == gBattlerPartyIndexes[battlerIn2]) continue; - if (i == ewram16068arr(battlerIn1)) + if (i == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn1]) continue; - if (i == ewram16068arr(battlerIn2)) + if (i == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn2]) continue; species = GetMonData(&gEnemyParty[i], MON_DATA_SPECIES); @@ -353,7 +354,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) moveFlags = AI_TypeCalc(move, gBattleMons[battlerIn1].species, gBattleMons[battlerIn1].ability); if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE && Random() % moduloPercent == 0) { - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = i; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] = i; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } @@ -413,9 +414,9 @@ static bool8 ShouldSwitch(void) continue; if (i == gBattlerPartyIndexes[battlerIn2]) continue; - if (i == ewram16068arr(battlerIn1)) + if (i == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn1]) continue; - if (i == ewram16068arr(battlerIn2)) + if (i == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn2]) continue; availableToSwitch++; @@ -450,7 +451,7 @@ void AI_TrySwitchOrUseItem(void) { if (ShouldSwitch()) { - if (ewram160C8arr(GetBattlerPosition(gActiveBattler)) == 6) + if (gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] == 6) { s32 monToSwitchId = GetMostSuitableMonToSwitchInto(); if (monToSwitchId == 6) @@ -474,19 +475,19 @@ void AI_TrySwitchOrUseItem(void) continue; if (monToSwitchId == gBattlerPartyIndexes[battlerIn2]) continue; - if (monToSwitchId == ewram16068arr(battlerIn1)) + if (monToSwitchId == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn1]) continue; - if (monToSwitchId == ewram16068arr(battlerIn2)) + if (monToSwitchId == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn2]) continue; break; } } - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = monToSwitchId; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] = monToSwitchId; } - ewram16068arr(gActiveBattler) = ewram160C8arr(GetBattlerPosition(gActiveBattler)); + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + gActiveBattler] = gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)]; return; } else @@ -573,8 +574,8 @@ u8 GetMostSuitableMonToSwitchInto(void) && !(gBitTable[i] & invalidMons) && gBattlerPartyIndexes[battlerIn1] != i && gBattlerPartyIndexes[battlerIn2] != i - && i != ewram16068arr(battlerIn1) - && i != ewram16068arr(battlerIn2)) + && i != gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn1] + && i != gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn2]) { u8 type1 = gBaseStats[species].type1; u8 type2 = gBaseStats[species].type2; @@ -633,9 +634,9 @@ u8 GetMostSuitableMonToSwitchInto(void) continue; if (gBattlerPartyIndexes[battlerIn2] == i) continue; - if (i == ewram16068arr(battlerIn1)) + if (i == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn1]) continue; - if (i == ewram16068arr(battlerIn2)) + if (i == gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + battlerIn2]) continue; for (j = 0; j < 4; j++) @@ -711,9 +712,9 @@ static bool8 ShouldUseItem(void) else itemEffects = gItemEffectTable[item - 13]; - ewram160D8(gActiveBattler) = GetAI_ItemType(item, itemEffects); + gSharedMem[BSTRUCT_OFF(AI_usedItemType) + (gActiveBattler / 2)] = GetAI_ItemType(item, itemEffects); - switch (ewram160D8(gActiveBattler)) + switch (gSharedMem[BSTRUCT_OFF(AI_usedItemType) + (gActiveBattler / 2)]) { case AI_ITEM_FULL_RESTORE: if (gBattleMons[gActiveBattler].hp >= gBattleMons[gActiveBattler].maxHP / 4) @@ -732,54 +733,54 @@ static bool8 ShouldUseItem(void) shouldUse = TRUE; break; case AI_ITEM_CURE_CONDITION: - ewram160DA(gActiveBattler) = 0; - if (itemEffects[3] & 0x20 && gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP) + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] = 0; + if (itemEffects[3] & ITEM3_SLEEP && gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP) { - ewram160DA(gActiveBattler) |= 0x20; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x20; shouldUse = TRUE; } - if (itemEffects[3] & 0x10 && (gBattleMons[gActiveBattler].status1 & STATUS1_POISON || gBattleMons[gActiveBattler].status1 & STATUS1_TOXIC_POISON)) + if (itemEffects[3] & ITEM3_POISON && (gBattleMons[gActiveBattler].status1 & STATUS1_POISON || gBattleMons[gActiveBattler].status1 & STATUS1_TOXIC_POISON)) { - ewram160DA(gActiveBattler) |= 0x10; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x10; shouldUse = TRUE; } - if (itemEffects[3] & 0x8 && gBattleMons[gActiveBattler].status1 & STATUS1_BURN) + if (itemEffects[3] & ITEM3_BURN && gBattleMons[gActiveBattler].status1 & STATUS1_BURN) { - ewram160DA(gActiveBattler) |= 0x8; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x8; shouldUse = TRUE; } - if (itemEffects[3] & 0x4 && gBattleMons[gActiveBattler].status1 & STATUS1_FREEZE) + if (itemEffects[3] & ITEM3_FREEZE && gBattleMons[gActiveBattler].status1 & STATUS1_FREEZE) { - ewram160DA(gActiveBattler) |= 0x4; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x4; shouldUse = TRUE; } - if (itemEffects[3] & 0x2 && gBattleMons[gActiveBattler].status1 & STATUS1_PARALYSIS) + if (itemEffects[3] & ITEM3_PARALYSIS && gBattleMons[gActiveBattler].status1 & STATUS1_PARALYSIS) { - ewram160DA(gActiveBattler) |= 0x2; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x2; shouldUse = TRUE; } - if (itemEffects[3] & 0x1 && gBattleMons[gActiveBattler].status2 & STATUS2_CONFUSION) + if (itemEffects[3] & ITEM3_CONFUSION && gBattleMons[gActiveBattler].status2 & STATUS2_CONFUSION) { - ewram160DA(gActiveBattler) |= 0x1; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x1; shouldUse = TRUE; } break; case AI_ITEM_X_STAT: - ewram160DA(gActiveBattler) = 0; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] = 0; if (gDisableStructs[gActiveBattler].isFirstTurn == 0) break; - if (itemEffects[0] & 0xF) - ewram160DA(gActiveBattler) |= 0x1; - if (itemEffects[1] & 0xF0) - ewram160DA(gActiveBattler) |= 0x2; - if (itemEffects[1] & 0xF) - ewram160DA(gActiveBattler) |= 0x4; - if (itemEffects[2] & 0xF) - ewram160DA(gActiveBattler) |= 0x8; - if (itemEffects[2] & 0xF0) - ewram160DA(gActiveBattler) |= 0x20; - if (itemEffects[0] & 0x30) - ewram160DA(gActiveBattler) |= 0x80; + if (itemEffects[0] & ITEM0_X_ATTACK) + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x1; + if (itemEffects[1] & ITEM1_X_DEFEND) + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x2; + if (itemEffects[1] & ITEM1_X_SPEED) + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x4; + if (itemEffects[2] & ITEM2_X_SPATK) + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x8; + if (itemEffects[2] & ITEM2_X_ACCURACY) + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x20; + if (itemEffects[0] & ITEM0_DIRE_HIT) + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gActiveBattler / 2)] |= 0x80; shouldUse = TRUE; break; case AI_ITEM_GUARD_SPECS: @@ -794,7 +795,11 @@ static bool8 ShouldUseItem(void) if (shouldUse) { BtlController_EmitTwoReturnValues(1, B_ACTION_USE_ITEM, 0); - ewram160D4(gActiveBattler) = item; + // The AI will only ever use an item whose ID fits in 8 bits. + // If you want the AI to use an item with a higher ID, uncomment the line below. + // See also: battle_controller_opponent.c:OpponentHandleOpenBag + gSharedMem[BSTRUCT_OFF(AI_usedItemId) + (gActiveBattler / 2) * 2] = item; +// gSharedMem[BSTRUCT_OFF(AI_usedItemId) + (gActiveBattler / 2) * 2 + 1] = item >> 8; AI_BATTLE_HISTORY->trainerItems[i] = 0; return shouldUse; } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index ae2082ec0..f45e80198 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1800,8 +1800,10 @@ void OpponentHandlecmd20(void) void OpponentHandleOpenBag(void) { - // What is this? - BtlController_EmitOneReturnValue(1, ewram160D4(gActiveBattler)); + // The AI will only ever use an item whose ID fits in 8 bits. + // If you want the AI to use an item with a higher ID, uncomment the code + // in the line below. + BtlController_EmitOneReturnValue(1, gSharedMem[BSTRUCT_OFF(AI_usedItemId) + (gActiveBattler / 2) * 2]/* | (gSharedMem[BSTRUCT_OFF(AI_usedItemId) + (gActiveBattler / 2) * 2 + 1] */); OpponentBufferExecCompleted(); } @@ -1809,7 +1811,7 @@ void OpponentHandlecmd22(void) { s32 r4; - if (ewram160C8arr(GetBattlerPosition(gActiveBattler)) == 6) + if (gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] == PARTY_SIZE) { u8 r6; u8 r5; @@ -1838,10 +1840,10 @@ void OpponentHandlecmd22(void) } else { - r4 = ewram160C8arr(GetBattlerPosition(gActiveBattler)); - ewram160C8arr(GetBattlerPosition(gActiveBattler)) = 6; + r4 = gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)]; + gSharedMem[BSTRUCT_OFF(AI_monToSwitchIntoId) + (GetBattlerPosition(gActiveBattler) / 2)] = PARTY_SIZE; } - ewram16068arr(gActiveBattler) = r4; + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + gActiveBattler] = r4; BtlController_EmitChosenMonReturnValue(1, r4, 0); OpponentBufferExecCompleted(); } diff --git a/src/battle_main.c b/src/battle_main.c index ad53e7c94..1b8e75cda 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -47,6 +47,7 @@ #include "scanline_effect.h" #include "util.h" #include "ewram.h" +#include "battle_string_ids.h" struct UnknownStruct7 { @@ -4019,7 +4020,7 @@ void BattleBeginFirstTurn(void) ; for (i = 0; i < 4; i++) { - ewram16068arr(i) = 6; + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + i] = PARTY_SIZE; gActionForBanks[i] = 0xFF; gChosenMovesByBanks[i] = 0; } @@ -4111,7 +4112,7 @@ void BattleTurnPassed(void) gChosenMovesByBanks[i] = 0; } for (i = 0; i < 4; i++) - ewram16068arr(i) = 6; + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + i] = 6; gBattleStruct->unk160A6 = gAbsentBattlerFlags; gBattleMainFunc = sub_8012324; gRandomTurnNumber = Random(); @@ -4185,23 +4186,23 @@ void sub_8012258(u8 a) u8 r1; for (i = 0; i < 3; i++) - gUnknown_02038470[i] = ewram1606Carr(i, a); + gUnknown_02038470[i] = gSharedMem[BSTRUCT_OFF(unk1606C) + i + a * 3]; r4 = pokemon_order_func(gBattlerPartyIndexes[a]); - r1 = pokemon_order_func(ewram16068arr(a)); + r1 = pokemon_order_func(gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + a]); sub_8094C98(r4, r1); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { for (i = 0; i < 3; i++) { - ewram1606Carr(i, a) = gUnknown_02038470[i]; - ewram1606Carr(i, (a ^ 2)) = gUnknown_02038470[i]; + gSharedMem[BSTRUCT_OFF(unk1606C) + i + a * 3] = gUnknown_02038470[i]; + gSharedMem[BSTRUCT_OFF(unk1606C) + i + (a ^ BIT_FLANK) * 3] = gUnknown_02038470[i]; } } else { for (i = 0; i < 3; i++) { - ewram1606Carr(i, a) = gUnknown_02038470[i]; + gSharedMem[BSTRUCT_OFF(unk1606C) + i + a * 3] = gUnknown_02038470[i]; } } } @@ -4238,7 +4239,7 @@ void sub_8012324(void) switch (gBattleCommunication[gActiveBattler]) { case STATE_BEFORE_ACTION_CHOSEN: - ewram16068arr(gActiveBattler) = 6; + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + gActiveBattler] = 6; if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && (position & BIT_FLANK) != B_FLANK_LEFT && !(gBattleStruct->unk160A6 & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(position))]) @@ -4279,8 +4280,8 @@ void sub_8012324(void) if (AreAllMovesUnusable()) { gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - ewram16060(gActiveBattler) = FALSE; - ewram16094arr(gActiveBattler) = STATE_WAIT_ACTION_CONFIRMED_STANDBY; + gSharedMem[BSTRUCT_OFF(unk16060) + gActiveBattler] = FALSE; + gSharedMem[BSTRUCT_OFF(unk16094) + gActiveBattler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; gSharedMem[BSTRUCT_OFF(moveTarget) + gActiveBattler] = gBattleBufferB[gActiveBattler][3]; return; } @@ -4326,8 +4327,8 @@ void sub_8012324(void) { gSelectionBattleScripts[gActiveBattler] = BattleScript_ActionSelectionItemsCantBeUsed; gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - ewram16060(gActiveBattler) = FALSE; - ewram16094arr(gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; + gSharedMem[BSTRUCT_OFF(unk16060) + gActiveBattler] = FALSE; + gSharedMem[BSTRUCT_OFF(unk16094) + gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; return; } else @@ -4337,7 +4338,7 @@ void sub_8012324(void) } break; case B_ACTION_SWITCH: - BATTLE_PARTY_ID(gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; + gSharedMem[BSTRUCT_OFF(unk16064) + gActiveBattler] = gBattlerPartyIndexes[gActiveBattler]; if (gBattleMons[gActiveBattler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION) || gStatuses3[gActiveBattler] & STATUS3_ROOTED) { @@ -4355,9 +4356,9 @@ void sub_8012324(void) else { if (gActiveBattler == 2 && gActionForBanks[0] == B_ACTION_SWITCH) - BtlController_EmitChoosePokemon(0, PARTY_CHOOSE_MON, ewram16068arr(0), ABILITY_NONE, &gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 0]); + BtlController_EmitChoosePokemon(0, PARTY_CHOOSE_MON, gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + 0], ABILITY_NONE, &gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 0]); else if (gActiveBattler == 3 && gActionForBanks[1] == B_ACTION_SWITCH) - BtlController_EmitChoosePokemon(0, PARTY_CHOOSE_MON, ewram16068arr(1), ABILITY_NONE, &gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 0]); + BtlController_EmitChoosePokemon(0, PARTY_CHOOSE_MON, gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + 1], ABILITY_NONE, &gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 0]); else BtlController_EmitChoosePokemon(0, PARTY_CHOOSE_MON, 6, ABILITY_NONE, &gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 0]); } @@ -4368,8 +4369,8 @@ void sub_8012324(void) { gSelectionBattleScripts[gActiveBattler] = BattleScript_PrintFullBox; gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - ewram16060(gActiveBattler) = FALSE; - ewram16094arr(gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; + gSharedMem[BSTRUCT_OFF(unk16060) + gActiveBattler] = FALSE; + gSharedMem[BSTRUCT_OFF(unk16094) + gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; return; } break; @@ -4397,8 +4398,8 @@ void sub_8012324(void) { gSelectionBattleScripts[gActiveBattler] = BattleScript_PrintCantEscapeFromBattle; gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - ewram16060(gActiveBattler) = FALSE; - ewram16094arr(gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; + gSharedMem[BSTRUCT_OFF(unk16060) + gActiveBattler] = FALSE; + gSharedMem[BSTRUCT_OFF(unk16094) + gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; return; } else @@ -4432,9 +4433,9 @@ void sub_8012324(void) else if (TrySetCantSelectMoveBattleScript()) { gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - ewram16060(gActiveBattler) = FALSE; + gSharedMem[BSTRUCT_OFF(unk16060) + gActiveBattler] = FALSE; gBattleBufferB[gActiveBattler][1] = 0; - ewram16094arr(gActiveBattler) = STATE_WAIT_ACTION_CHOSEN; + gSharedMem[BSTRUCT_OFF(unk16094) + gActiveBattler] = STATE_WAIT_ACTION_CHOSEN; return; } else @@ -4465,7 +4466,7 @@ void sub_8012324(void) } else { - ewram16068arr(gActiveBattler) = gBattleBufferB[gActiveBattler][1]; + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + gActiveBattler] = gBattleBufferB[gActiveBattler][1]; if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { @@ -4473,9 +4474,9 @@ void sub_8012324(void) gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 0] |= (gBattleBufferB[gActiveBattler][2] & 0xF0); gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 1] = gBattleBufferB[gActiveBattler][3]; - ewram1606Carr(0, (gActiveBattler ^ BIT_FLANK)) &= (0xF0); - ewram1606Carr(0, (gActiveBattler ^ BIT_FLANK)) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; - ewram1606Carr(2, (gActiveBattler ^ BIT_FLANK)) = gBattleBufferB[gActiveBattler][3]; + gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * (gActiveBattler ^ BIT_FLANK) + 0] &= (0xF0); + gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * (gActiveBattler ^ BIT_FLANK) + 0] |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; + gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * (gActiveBattler ^ BIT_FLANK) + 2] = gBattleBufferB[gActiveBattler][3]; } gBattleCommunication[gActiveBattler]++; } @@ -4537,9 +4538,9 @@ void sub_8012324(void) } break; case STATE_SELECTION_SCRIPT: - if (ewram16060(gActiveBattler)) + if (gSharedMem[BSTRUCT_OFF(unk16060) + gActiveBattler]) { - gBattleCommunication[gActiveBattler] = ewram16094arr(gActiveBattler); + gBattleCommunication[gActiveBattler] = gSharedMem[BSTRUCT_OFF(unk16094) + gActiveBattler]; } else { @@ -5366,7 +5367,7 @@ void HandleAction_Switch(void) gActionSelectionCursor[gBattlerAttacker] = 0; gMoveSelectionCursor[gBattlerAttacker] = 0; - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, BATTLE_PARTY_ID(gBattlerAttacker)) + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, gSharedMem[BSTRUCT_OFF(unk16064) + gBattlerAttacker]) gBattleStruct->scriptingActive = gBattlerAttacker; gBattlescriptCurrInstr = BattleScript_ActionSwitch; @@ -5399,41 +5400,41 @@ void HandleAction_UseItem(void) else { - switch (ewram160D8((gBattleStruct->scriptingActive = gBattlerAttacker))) + switch (gSharedMem[BSTRUCT_OFF(AI_usedItemType) + ((gBattleStruct->scriptingActive = gBattlerAttacker) / 2)]) { case AI_ITEM_FULL_RESTORE: case AI_ITEM_HEAL_HP: break; case AI_ITEM_CURE_CONDITION: gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if (ewram160DA(gBattlerAttacker) & 1) + if (gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gBattlerAttacker >> 1)] & 1) { - if (ewram160DA(gBattlerAttacker) & 0x3E) + if (gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gBattlerAttacker >> 1)] & 0x3E) gBattleCommunication[MULTISTRING_CHOOSER] = 5; } else { - while (!(ewram160DA(gBattlerAttacker) & 1)) + while (!(gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gBattlerAttacker >> 1)] & 1)) { - ewram160DA(gBattlerAttacker) >>= 1; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gBattlerAttacker >> 1)] >>= 1; gBattleCommunication[MULTISTRING_CHOOSER]++; } } break; case AI_ITEM_X_STAT: gBattleCommunication[MULTISTRING_CHOOSER] = 4; - if (ewram160DA(gBattlerAttacker) & 0x80) + if (gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gBattlerAttacker >> 1)] & 0x80) { gBattleCommunication[MULTISTRING_CHOOSER] = 5; } else { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK) - PREPARE_STRING_BUFFER(gBattleTextBuff2, 0xD2) + PREPARE_STRING_BUFFER(gBattleTextBuff2, STRINGID_STATROSE) - while (!(ewram160DA(gBattlerAttacker) & 1)) + while (!(gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gBattlerAttacker >> 1)] & 1)) { - ewram160DA(gBattlerAttacker) >>= 1; + gSharedMem[BSTRUCT_OFF(AI_usedItemEffect) + (gBattlerAttacker >> 1)] >>= 1; gBattleTextBuff1[2]++; } @@ -5449,7 +5450,7 @@ void HandleAction_UseItem(void) break; } - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[ewram160D8(gBattlerAttacker)]; + gBattlescriptCurrInstr = gBattlescriptsForUsingItem[gSharedMem[BSTRUCT_OFF(AI_usedItemType) + (gBattlerAttacker / 2)]]; } gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 43a8e14eb..23e988dd2 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2686,7 +2686,7 @@ void SetMoveEffect(bool8 primary, u8 certainArg) {gBattlescriptCurrInstr++; return;} gLastUsedItem = gBattleMons[gBattlerTarget].item; - *USED_HELD_ITEM(gBattlerTarget) = gLastUsedItem; + *((u16 *)&gSharedMem[BSTRUCT_OFF(usedHeldItems) + gBattlerTarget * 2]) = gLastUsedItem; gBattleMons[gBattlerTarget].item = 0; gActiveBattler = gBattlerAttacker; @@ -2700,7 +2700,7 @@ void SetMoveEffect(bool8 primary, u8 certainArg) BattleScriptPush(gBattlescriptCurrInstr + 1); gBattlescriptCurrInstr = BattleScript_ItemSteal; - *CHOICED_MOVE(gBattlerTarget) = 0; + *((u16 *)&gSharedMem[BSTRUCT_OFF(choicedMove) + gBattlerTarget * 2]) = MOVE_NONE; } break; case 32: //escape prevention @@ -6010,7 +6010,7 @@ static void atk43_jumpifabilitypresent(void) static void atk44_endselectionscript(void) { - ewram16060(gBattlerAttacker) = 1; + gSharedMem[BSTRUCT_OFF(unk16060) + gBattlerAttacker] = 1; } static void atk45_playanimation(void) @@ -6863,7 +6863,7 @@ static void atk4C_getswitchedmondata(void) gActiveBattler = GetBattlerForBattleScript(T2_READ_8(gBattlescriptCurrInstr + 1)); - gBattlerPartyIndexes[gActiveBattler] = ewram16068arr(gActiveBattler); + gBattlerPartyIndexes[gActiveBattler] = gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + gActiveBattler]; BtlController_EmitGetMonData(0, 0, gBitTable[gBattlerPartyIndexes[gActiveBattler]]); MarkBattlerForControllerExec(gActiveBattler); @@ -7006,7 +7006,7 @@ static void atk4F_jumpifcantswitch(void) void sub_8022A3C(u8 unkown) { - BATTLE_PARTY_ID(gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; + gSharedMem[BSTRUCT_OFF(unk16064) + gActiveBattler] = gBattlerPartyIndexes[gActiveBattler]; BtlController_EmitChoosePokemon(0, 1, unkown, 0, gBattleStruct->unk1606C[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); } @@ -8094,7 +8094,7 @@ static void atk51_switchhandleorder(void) for (i = 0; i < gBattlersCount; i++) { if (gBattleBufferB[i][0] == 0x22) - ewram16068arr(i) = gBattleBufferB[i][1]; + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + i] = gBattleBufferB[i][1]; } break; case 1: @@ -8103,15 +8103,15 @@ static void atk51_switchhandleorder(void) break; case 2: gBattleCommunication[0] = gBattleBufferB[gActiveBattler][1]; - ewram16068arr(gActiveBattler) = gBattleBufferB[gActiveBattler][1]; + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + gActiveBattler] = gBattleBufferB[gActiveBattler][1]; if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 0] &= 0xF; gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 0] |= (gBattleBufferB[gActiveBattler][2] & 0xF0); gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * gActiveBattler + 1] = gBattleBufferB[gActiveBattler][3]; - ewram1606Carr(0, (gActiveBattler ^ 2)) &= (0xF0); - ewram1606Carr(0, (gActiveBattler ^ 2)) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; - ewram1606Carr(2, (gActiveBattler ^ 2)) = gBattleBufferB[gActiveBattler][3]; + gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * (gActiveBattler ^ BIT_FLANK) + 0] &= (0xF0); + gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * (gActiveBattler ^ BIT_FLANK) + 0] |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; + gSharedMem[BSTRUCT_OFF(unk1606C) + 3 * (gActiveBattler ^ BIT_FLANK) + 2] = gBattleBufferB[gActiveBattler][3]; } else sub_8012258(gActiveBattler); @@ -9038,7 +9038,7 @@ static void atk69_adjustsetdamage(void) //literally a copy of atk07 except there void atk6A_removeitem(void) { gActiveBattler = GetBattlerForBattleScript(T2_READ_8(gBattlescriptCurrInstr + 1)); - USED_HELD_ITEMS(gActiveBattler) = gBattleMons[gActiveBattler].item; + *((u16 *)&gSharedMem[BSTRUCT_OFF(usedHeldItems) + gActiveBattler * 2]) = gBattleMons[gActiveBattler].item; gBattleMons[gActiveBattler].item = 0; BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gActiveBattler].item); @@ -9570,7 +9570,7 @@ static void atk74_hpthresholds2(void) { gActiveBattler = GetBattlerForBattleScript(T2_READ_8(gBattlescriptCurrInstr + 1)); opposing_bank = gActiveBattler ^ 1; - hp_switchout = eHpOnSwitchout(GetBattlerSide(opposing_bank)); //gBattleStruct->HP_OnSwitchout[GetBattlerSide(opposing_bank)]; + hp_switchout = gSharedMem[BSTRUCT_OFF(HP_OnSwitchout) + GetBattlerSide(opposing_bank) * 2]; result = (hp_switchout - gBattleMons[opposing_bank].hp) * 100 / hp_switchout; if (gBattleMons[opposing_bank].hp >= hp_switchout) @@ -10294,7 +10294,7 @@ static bool8 sub_80264C0(void) { if (gBattleMons[gBattlerAttacker].level >= gBattleMons[gBattlerTarget].level) { - BATTLE_PARTY_ID(gBattlerTarget) = gBattlerPartyIndexes[gBattlerTarget]; + gSharedMem[BSTRUCT_OFF(unk16064) + gBattlerTarget] = gBattlerPartyIndexes[gBattlerTarget]; } else { @@ -10304,7 +10304,7 @@ static bool8 sub_80264C0(void) gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); return 0; } - BATTLE_PARTY_ID(gBattlerTarget) = gBattlerPartyIndexes[gBattlerTarget]; + gSharedMem[BSTRUCT_OFF(unk16064) + gBattlerTarget] = gBattlerPartyIndexes[gBattlerTarget]; } gBattlescriptCurrInstr = BattleScript_SuccessForceOut; return 1; @@ -10385,7 +10385,7 @@ static void atk8F_forcerandomswitch(void) } while (i == gBattlerPartyIndexes[gBattlerTarget] || !MON_CAN_BATTLE(&party[i])); } } - ewram16068arr(gBattlerTarget) = i; + gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + gBattlerTarget] = i; if (!IsLinkDoubleBattle()) sub_8012258(gBattlerTarget); sub_8094B6C(gBattlerTarget, i, 0); @@ -13114,7 +13114,7 @@ static void atkE2_switchoutabilities(void) { case ABILITY_NATURAL_CURE: gBattleMons[gActiveBattler].status1 = 0; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, gBitTable[BATTLE_PARTY_ID(gActiveBattler)], 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, gBitTable[gSharedMem[BSTRUCT_OFF(unk16064) + gActiveBattler]], 4, &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); break; } @@ -13266,7 +13266,7 @@ static void atkEA_tryrecycleitem(void) { u16* used_item; gActiveBattler = gBattlerAttacker; - used_item = &USED_HELD_ITEMS(gActiveBattler); + used_item = ((u16 *)&gSharedMem[BSTRUCT_OFF(usedHeldItems) + gActiveBattler * 2]); if (*used_item && gBattleMons[gActiveBattler].item == 0) { gLastUsedItem = *used_item; diff --git a/src/battle_util.c b/src/battle_util.c index 66263c254..06f807d89 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1657,28 +1657,28 @@ bool8 sub_8018018(u8 bank, u8 r1, u8 r2) } else { - if (GetBattlerSide(bank) == 1) + if (GetBattlerSide(bank) == B_SIDE_OPPONENT) { - r7 = GetBattlerAtPosition(1); - r6 = GetBattlerAtPosition(3); + r7 = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + r6 = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); party = gEnemyParty; } else { - r7 = GetBattlerAtPosition(0); - r6 = GetBattlerAtPosition(2); + r7 = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + r6 = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); party = gPlayerParty; } - if (r1 == 6) + if (r1 == PARTY_SIZE) r1 = gBattlerPartyIndexes[r7]; - if (r2 == 6) + if (r2 == PARTY_SIZE) r2 = gBattlerPartyIndexes[r6]; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { - if (GetMonData(&party[i], MON_DATA_HP) && GetMonData(&party[i], MON_DATA_SPECIES2) && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG && i != r1 && i != r2 && i != ewram16068arr(r7) && i != ewram16068arr(r6)) + if (GetMonData(&party[i], MON_DATA_HP) && GetMonData(&party[i], MON_DATA_SPECIES2) && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG && i != r1 && i != r2 && i != gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + r7] && i != gSharedMem[BSTRUCT_OFF(monToSwitchIntoId) + r6]) break; } - return (i == 6); + return (i == PARTY_SIZE); } } |