diff --git a/asm/battle_5.s b/asm/battle_5.s deleted file mode 100644 index f2d6797f9..000000000 --- a/asm/battle_5.s +++ /dev/null @@ -1,582 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start AllocateBattleResrouces -AllocateBattleResrouces: @ 8056F28 - push {r4-r6,lr} - ldr r5, =gBattleResources - ldr r6, =gBattleTypeFlags - ldr r0, [r6] - movs r1, 0x80 - lsls r1, 19 - ands r0, r1 - cmp r0, 0 - beq _08056F3E - bl sub_81D55D0 -_08056F3E: - ldr r4, =gBattleStruct - movs r0, 0xA9 - lsls r0, 2 - bl AllocZeroed - str r0, [r4] - movs r0, 0x20 - bl AllocZeroed - str r0, [r5] - movs r0, 0xA0 - bl AllocZeroed - ldr r1, [r5] - str r0, [r1] - movs r0, 0x10 - bl AllocZeroed - ldr r1, [r5] - str r0, [r1, 0x4] - movs r0, 0x24 - bl AllocZeroed - ldr r1, [r5] - str r0, [r1, 0x8] - movs r0, 0x24 - bl AllocZeroed - ldr r1, [r5] - str r0, [r1, 0xC] - movs r0, 0xC - bl AllocZeroed - ldr r1, [r5] - str r0, [r1, 0x10] - movs r0, 0x1C - bl AllocZeroed - ldr r1, [r5] - str r0, [r1, 0x14] - movs r0, 0x54 - bl AllocZeroed - ldr r1, [r5] - str r0, [r1, 0x18] - movs r0, 0x24 - bl AllocZeroed - ldr r1, [r5] - str r0, [r1, 0x1C] - ldr r4, =gLinkBattleSendBuffer - movs r5, 0x80 - lsls r5, 5 - adds r0, r5, 0 - bl AllocZeroed - str r0, [r4] - ldr r4, =gLinkBattleRecvBuffer - adds r0, r5, 0 - bl AllocZeroed - str r0, [r4] - ldr r4, =gUnknown_0202305C - movs r0, 0x80 - lsls r0, 6 - bl AllocZeroed - str r0, [r4] - ldr r4, =gUnknown_02023060 - adds r0, r5, 0 - bl AllocZeroed - str r0, [r4] - ldr r0, [r6] - movs r1, 0x80 - lsls r1, 20 - ands r0, r1 - cmp r0, 0 - beq _08056FFA - ldr r0, =0x00004054 - bl VarGet - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gSaveBlock1Ptr - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 5 - ldr r0, =0x00001a9c - adds r1, r0 - ldr r0, [r2] - adds r0, r1 - bl CreateSecretBaseEnemyParty -_08056FFA: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end AllocateBattleResrouces - - thumb_func_start FreeBattleResources -FreeBattleResources: @ 8057028 - push {r4-r6,lr} - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 19 - ands r0, r1 - cmp r0, 0 - beq _0805703C - bl sub_81D5694 -_0805703C: - ldr r6, =gBattleResources - ldr r0, [r6] - cmp r0, 0 - beq _080570D0 - ldr r4, =gBattleStruct - ldr r0, [r4] - bl Free - movs r5, 0 - str r5, [r4] - ldr r0, [r6] - ldr r0, [r0] - bl Free - ldr r0, [r6] - str r5, [r0] - ldr r0, [r0, 0x4] - bl Free - ldr r0, [r6] - str r5, [r0, 0x4] - ldr r0, [r0, 0x8] - bl Free - ldr r0, [r6] - str r5, [r0, 0x8] - ldr r0, [r0, 0xC] - bl Free - ldr r0, [r6] - str r5, [r0, 0xC] - ldr r0, [r0, 0x10] - bl Free - ldr r0, [r6] - str r5, [r0, 0x10] - ldr r0, [r0, 0x14] - bl Free - ldr r0, [r6] - str r5, [r0, 0x14] - ldr r0, [r0, 0x18] - bl Free - ldr r0, [r6] - str r5, [r0, 0x18] - ldr r0, [r0, 0x1C] - bl Free - ldr r0, [r6] - str r5, [r0, 0x1C] - bl Free - str r5, [r6] - ldr r4, =gLinkBattleSendBuffer - ldr r0, [r4] - bl Free - str r5, [r4] - ldr r4, =gLinkBattleRecvBuffer - ldr r0, [r4] - bl Free - str r5, [r4] - ldr r4, =gUnknown_0202305C - ldr r0, [r4] - bl Free - str r5, [r4] - ldr r4, =gUnknown_02023060 - ldr r0, [r4] - bl Free - str r5, [r4] -_080570D0: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end FreeBattleResources - - thumb_func_start AdjustFriendshipOnBattleFaint -AdjustFriendshipOnBattleFaint: @ 80570F4 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - beq _08057140 - movs r0, 0x1 - bl GetBankByIdentity - lsls r0, 24 - lsrs r4, r0, 24 - movs r0, 0x3 - bl GetBankByIdentity - lsls r0, 24 - lsrs r3, r0, 24 - ldr r2, =gBattleMons - movs r0, 0x58 - adds r1, r3, 0 - muls r1, r0 - adds r1, r2 - adds r1, 0x2A - muls r0, r4 - adds r0, r2 - adds r0, 0x2A - ldrb r1, [r1] - ldrb r0, [r0] - cmp r1, r0 - bls _0805714A - adds r4, r3, 0 - b _0805714A - .pool -_08057140: - movs r0, 0x1 - bl GetBankByIdentity - lsls r0, 24 - lsrs r4, r0, 24 -_0805714A: - ldr r2, =gBattleMons - movs r1, 0x58 - adds r0, r4, 0 - muls r0, r1 - adds r0, r2 - adds r3, r0, 0 - adds r3, 0x2A - adds r0, r5, 0 - muls r0, r1 - adds r0, r2 - adds r1, r0, 0 - adds r1, 0x2A - ldrb r0, [r3] - ldrb r2, [r1] - cmp r0, r2 - bls _080571B8 - ldrb r1, [r1] - subs r0, r1 - cmp r0, 0x1D - ble _08057198 - ldr r1, =gBattlePartyID - lsls r0, r5, 1 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0x8 - bl AdjustFriendship - b _080571CE - .pool -_08057198: - ldr r1, =gBattlePartyID - lsls r0, r5, 1 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0x6 - bl AdjustFriendship - b _080571CE - .pool -_080571B8: - ldr r1, =gBattlePartyID - lsls r0, r5, 1 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0x6 - bl AdjustFriendship -_080571CE: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end AdjustFriendshipOnBattleFaint - - thumb_func_start sub_80571DC -sub_80571DC: @ 80571DC - push {r4-r7,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r7, r1, 24 - adds r0, r4, 0 - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - beq _08057248 - movs r2, 0 - ldr r6, =gBattlePartyID - lsls r3, r4, 1 - ldr r5, =gUnknown_0203CF00 - ldr r4, =gBattleStruct -_080571FE: - adds r0, r2, r5 - ldr r1, [r4] - adds r1, r2, r1 - adds r1, 0x60 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x2 - ble _080571FE - adds r0, r3, r6 - ldrb r0, [r0] - bl pokemon_order_func - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r7, 0 - bl pokemon_order_func - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - bl sub_81B8FB0 - movs r2, 0 - ldr r4, =gBattleStruct - ldr r3, =gUnknown_0203CF00 -_08057236: - ldr r0, [r4] - adds r0, r2, r0 - adds r0, 0x60 - adds r1, r2, r3 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x2 - ble _08057236 -_08057248: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80571DC - - thumb_func_start sub_805725C -sub_805725C: @ 805725C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - movs r0, 0 - mov r8, r0 - ldr r1, =gBattleCommunication - mov r10, r1 - b _08057284 - .pool -_0805727C: - mov r2, r8 - cmp r2, 0 - beq _08057284 - b _08057406 -_08057284: - mov r1, r10 - ldrb r0, [r1] - cmp r0, 0x1 - bne _0805728E - b _08057390 -_0805728E: - cmp r0, 0x1 - ble _08057294 - b _080573FC -_08057294: - cmp r0, 0 - beq _0805729A - b _080573FC -_0805729A: - ldr r6, =gBattleMons - movs r0, 0x58 - mov r5, r9 - muls r5, r0 - adds r0, r6, 0 - adds r0, 0x4C - adds r4, r5, r0 - ldr r0, [r4] - movs r7, 0x7 - ands r0, r7 - cmp r0, 0 - beq _08057372 - mov r0, r9 - bl UproarWakeUpCheck - lsls r0, 24 - cmp r0, 0 - beq _080572FC - ldr r0, [r4] - movs r1, 0x8 - negs r1, r1 - ands r0, r1 - str r0, [r4] - adds r2, r6, 0 - adds r2, 0x50 - adds r2, r5, r2 - ldr r0, [r2] - ldr r1, =0xf7ffffff - ands r0, r1 - str r0, [r2] - bl BattleScriptPushCursor - movs r0, 0x1 - mov r2, r10 - strb r0, [r2, 0x5] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =BattleScript_MoveUsedWokeUp - str r0, [r1] - movs r0, 0x2 - mov r8, r0 - b _08057372 - .pool -_080572FC: - adds r0, r5, r6 - adds r0, 0x20 - ldrb r0, [r0] - movs r2, 0x1 - cmp r0, 0x30 - bne _0805730A - movs r2, 0x2 -_0805730A: - ldr r1, [r4] - adds r0, r1, 0 - ands r0, r7 - cmp r0, r2 - bcs _0805731E - movs r0, 0x8 - negs r0, r0 - ands r1, r0 - str r1, [r4] - b _08057322 -_0805731E: - subs r0, r1, r2 - str r0, [r4] -_08057322: - ldr r2, =gBattleMons - movs r0, 0x58 - mov r1, r9 - muls r1, r0 - adds r0, r2, 0 - adds r0, 0x4C - adds r0, r1, r0 - ldr r4, [r0] - movs r0, 0x7 - ands r4, r0 - cmp r4, 0 - beq _08057354 - ldr r1, =gBattlescriptCurrInstr - ldr r0, =BattleScript_MoveUsedIsAsleep - str r0, [r1] - movs r1, 0x2 - mov r8, r1 - b _08057372 - .pool -_08057354: - adds r2, 0x50 - adds r2, r1, r2 - ldr r0, [r2] - ldr r1, =0xf7ffffff - ands r0, r1 - str r0, [r2] - bl BattleScriptPushCursor - ldr r0, =gBattleCommunication - strb r4, [r0, 0x5] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =BattleScript_MoveUsedWokeUp - str r0, [r1] - movs r2, 0x2 - mov r8, r2 -_08057372: - ldr r1, =gBattleCommunication - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - mov r10, r1 - b _080573FC - .pool -_08057390: - ldr r1, =gBattleMons - movs r0, 0x58 - mov r2, r9 - muls r2, r0 - adds r0, r2, 0 - adds r1, 0x4C - adds r4, r0, r1 - ldr r0, [r4] - movs r1, 0x20 - ands r0, r1 - cmp r0, 0 - beq _080573F4 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x5 - bl __umodsi3 - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, 0 - beq _080573D4 - ldr r1, =gBattlescriptCurrInstr - ldr r0, =BattleScript_MoveUsedIsFrozen - str r0, [r1] - b _080573EC - .pool -_080573D4: - ldr r0, [r4] - movs r1, 0x21 - negs r1, r1 - ands r0, r1 - str r0, [r4] - bl BattleScriptPushCursor - ldr r1, =gBattlescriptCurrInstr - ldr r0, =BattleScript_MoveUsedUnfroze - str r0, [r1] - mov r0, r10 - strb r5, [r0, 0x5] -_080573EC: - movs r1, 0x2 - mov r8, r1 - ldr r2, =gBattleCommunication - mov r10, r2 -_080573F4: - mov r1, r10 - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] -_080573FC: - mov r2, r10 - ldrb r0, [r2] - cmp r0, 0x2 - beq _08057406 - b _0805727C -_08057406: - mov r0, r8 - cmp r0, 0x2 - bne _08057430 - ldr r4, =gActiveBank - mov r1, r9 - strb r1, [r4] - ldrb r1, [r4] - movs r0, 0x58 - muls r0, r1 - ldr r1, =gBattleMons + 0x4C - adds r0, r1 - str r0, [sp] - movs r0, 0 - movs r1, 0x28 - movs r2, 0 - movs r3, 0x4 - bl EmitSetMonData - ldrb r0, [r4] - bl MarkBufferBankForExecution -_08057430: - mov r0, r8 - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_805725C - - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/berry_fix_program.s b/asm/berry_fix_program.s deleted file mode 100755 index 2428f2984..000000000 --- a/asm/berry_fix_program.s +++ /dev/null @@ -1,8 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - .align 2, 0 @ Don't pad with nop. diff --git a/include/battle.h b/include/battle.h index 4cf0d2e03..0939c92b6 100644 --- a/include/battle.h +++ b/include/battle.h @@ -7,6 +7,7 @@ #include "battle_2.h" #include "battle_ai_switch_items.h" #include "battle_gfx_sfx_util.h" +#include "battle_util2.h" /* Banks are a name given to what could be called a 'battlerId' or 'monControllerId'. @@ -253,11 +254,21 @@ #define MOVE_TARGET_FOES_AND_ALLY 0x20 #define MOVE_TARGET_OPPONENTS_FIELD 0x40 +// defines for the u8 array gTypeEffectiveness +#define TYPE_EFFECT_ATK_TYPE(i)((gTypeEffectiveness[i + 0])) +#define TYPE_EFFECT_DEF_TYPE(i)((gTypeEffectiveness[i + 1])) +#define TYPE_EFFECT_MULTIPLIER(i)((gTypeEffectiveness[i + 2])) + +// defines for the gTypeEffectiveness multipliers #define TYPE_MUL_NO_EFFECT 0 #define TYPE_MUL_NOT_EFFECTIVE 5 #define TYPE_MUL_NORMAL 10 #define TYPE_MUL_SUPER_EFFECTIVE 20 +// special type table Ids +#define TYPE_FORESIGHT 0xFE +#define TYPE_ENDTABLE 0xFF + #define BS_GET_TARGET 0 #define BS_GET_ATTACKER 1 #define BS_GET_EFFECT_BANK 2 @@ -362,8 +373,8 @@ struct DisableStruct /*0x0D*/ u8 unkD; /*0x0E*/ u8 encoreTimer1 : 4; /*0x0E*/ u8 encoreTimer2 : 4; - /*0x0F*/ u8 perishSong1 : 4; - /*0x0F*/ u8 perishSong2 : 4; + /*0x0F*/ u8 perishSongTimer1 : 4; + /*0x0F*/ u8 perishSongTimer2 : 4; /*0x10*/ u8 furyCutterCounter; /*0x11*/ u8 rolloutCounter1 : 4; /*0x11*/ u8 rolloutCounter2 : 4; @@ -612,7 +623,7 @@ struct BattleStruct u8 sentInPokes; bool8 selectionScriptFinished[BATTLE_BANKS_COUNT]; u8 field_58[4]; - u8 field_5C[4]; + u8 monToSwitchIntoId[BATTLE_BANKS_COUNT]; u8 field_60[4][3]; u8 runTries; u8 caughtMonNick[11]; @@ -684,7 +695,7 @@ struct BattleStruct u8 field_1A4[96]; u8 field_204[104]; u8 field_26C[40]; - u8 field_294[4]; + u8 AI_monToSwitchIntoId[BATTLE_BANKS_COUNT]; u8 field_298[8]; u8 field_2A0; u8 field_2A1; @@ -870,13 +881,6 @@ bool8 LoadChosenBattleElement(u8 caseId); void DrawMainBattleBackground(void); void task00_0800F6FC(u8 taskId); -// battle_5 -void AllocateBattleResrouces(void); -void FreeBattleResources(void); -void AdjustFriendshipOnBattleFaint(u8 bank); -void sub_80571DC(u8 bank, u8 arg1); -u32 sub_805725C(u8 bank); - enum { BACK_PIC_BRENDAN, @@ -979,6 +983,9 @@ extern struct BattleSpriteData *gBattleSpritesDataPtr; extern u8 *gLinkBattleSendBuffer; extern u8 *gLinkBattleRecvBuffer; +extern u8 *gUnknown_0202305C; +extern u8 *gUnknown_02023060; + // Move this somewhere else #include "sprite.h" diff --git a/include/battle_util2.h b/include/battle_util2.h new file mode 100644 index 000000000..3954e42dc --- /dev/null +++ b/include/battle_util2.h @@ -0,0 +1,10 @@ +#ifndef GUARD_BATTLE_UTIL2_H +#define GUARD_BATTLE_UTIL2_H + +void AllocateBattleResources(void); +void FreeBattleResources(void); +void AdjustFriendshipOnBattleFaint(u8 bank); +void sub_80571DC(u8 bank, u8 arg1); +u32 sub_805725C(u8 bank); + +#endif // GUARD_BATTLE_UTIL_H diff --git a/ld_script.txt b/ld_script.txt index 4ceaf1aa8..417fe6c47 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -60,7 +60,7 @@ SECTIONS { src/battle_2.o(.text); src/battle_util.o(.text); src/battle_script_commands.o(.text); - asm/battle_5.o(.text); + src/battle_util2.o(.text); src/battle_controller_player.o(.text); src/battle_gfx_sfx_util.o(.text); src/battle_controller_opponent.o(.text); diff --git a/src/battle_2.c b/src/battle_2.c index e4ee624fb..703315374 100644 --- a/src/battle_2.c +++ b/src/battle_2.c @@ -353,7 +353,7 @@ static const u8 sUnknown_0831BCF3[] = {4, 4, 4, 4}; void CB2_InitBattle(void) { MoveSaveBlocks_ResetHeap(); - AllocateBattleResrouces(); + AllocateBattleResources(); AllocateBattleSpritesData(); AllocateMonSpritesGfx(); sub_8185F84(); @@ -2853,9 +2853,9 @@ static void BattleStartClearSetData(void) *(i + 3 * 8 + (u8*)(gBattleStruct->mirrorMoveArrays) + 0) = 0; } - for (i = 0; i < 4; i++) + for (i = 0; i < BATTLE_BANKS_COUNT; i++) { - *(gBattleStruct->field_294 + i) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + i) = 6; } gBattleStruct->field_DF = 0; @@ -2935,8 +2935,8 @@ void SwitchInClearSetData(void) { gDisableStructs[gActiveBank].substituteHP = disableStructCopy.substituteHP; gDisableStructs[gActiveBank].bankWithSureHit = disableStructCopy.bankWithSureHit; - gDisableStructs[gActiveBank].perishSong1 = disableStructCopy.perishSong1; - gDisableStructs[gActiveBank].perishSong2 = disableStructCopy.perishSong2; + gDisableStructs[gActiveBank].perishSongTimer1 = disableStructCopy.perishSongTimer1; + gDisableStructs[gActiveBank].perishSongTimer2 = disableStructCopy.perishSongTimer2; gDisableStructs[gActiveBank].bankPreventingEscape = disableStructCopy.bankPreventingEscape; } @@ -3682,7 +3682,7 @@ static void TryDoEventsBeforeFirstTurn(void) } for (i = 0; i < BATTLE_BANKS_COUNT; i++) { - *(gBattleStruct->field_5C + i) = 6; + *(gBattleStruct->monToSwitchIntoId + i) = 6; gActionForBanks[i] = ACTION_INIT_VALUE; gChosenMovesByBanks[i] = MOVE_NONE; } @@ -3793,7 +3793,7 @@ void BattleTurnPassed(void) } for (i = 0; i < 4; i++) - *(gBattleStruct->field_5C + i) = 6; + *(gBattleStruct->monToSwitchIntoId + i) = 6; *(&gBattleStruct->field_91) = gAbsentBankFlags; BattleHandleAddTextPrinter(gText_EmptyString3, 0); @@ -3884,7 +3884,7 @@ void sub_803BDA0(u8 bank) gUnknown_0203CF00[i] = *(bank * 3 + i + (u8*)(gBattleStruct->field_60)); r4 = pokemon_order_func(gBattlePartyID[bank]); - r1 = pokemon_order_func(*(gBattleStruct->field_5C + bank)); + r1 = pokemon_order_func(*(gBattleStruct->monToSwitchIntoId + bank)); sub_81B8FB0(r4, r1); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) @@ -3932,7 +3932,7 @@ static void HandleTurnActionSelectionState(void) gBattleCommunication[gActiveBank] = STATE_BEFORE_ACTION_CHOSEN; break; case STATE_BEFORE_ACTION_CHOSEN: // choose an action - *(gBattleStruct->field_5C + gActiveBank) = 6; + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = 6; if (gBattleTypeFlags & BATTLE_TYPE_MULTI || !(identity & BIT_MON) || gBattleStruct->field_91 & gBitTable[GetBankByIdentity(identity ^ BIT_MON)] @@ -4050,9 +4050,9 @@ static void HandleTurnActionSelectionState(void) else { if (gActiveBank == 2 && gActionForBanks[0] == ACTION_SWITCH) - EmitChoosePokemon(0, 0, *(gBattleStruct->field_5C + 0), ABILITY_NONE, gBattleStruct->field_60[gActiveBank]); + EmitChoosePokemon(0, 0, *(gBattleStruct->monToSwitchIntoId + 0), ABILITY_NONE, gBattleStruct->field_60[gActiveBank]); else if (gActiveBank == 3 && gActionForBanks[1] == ACTION_SWITCH) - EmitChoosePokemon(0, 0, *(gBattleStruct->field_5C + 1), ABILITY_NONE, gBattleStruct->field_60[gActiveBank]); + EmitChoosePokemon(0, 0, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->field_60[gActiveBank]); else EmitChoosePokemon(0, 0, 6, ABILITY_NONE, gBattleStruct->field_60[gActiveBank]); } @@ -4339,7 +4339,7 @@ static void HandleTurnActionSelectionState(void) for (i = 0; i < gNoOfAllBanks; i++) { if (gActionForBanks[i] == ACTION_SWITCH) - sub_80571DC(i, *(gBattleStruct->field_5C + i)); + sub_80571DC(i, *(gBattleStruct->monToSwitchIntoId + i)); } } } @@ -4363,7 +4363,7 @@ static bool8 sub_803CDB8(void) static void sub_803CDF8(void) { - *(gBattleStruct->field_5C + gActiveBank) = gBattleBufferB[gActiveBank][1]; + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = gBattleBufferB[gActiveBank][1]; RecordedBattle_SetBankAction(gActiveBank, gBattleBufferB[gActiveBank][1]); if (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI) @@ -5618,7 +5618,7 @@ static void HandleAction_NothingIsFainted(void) static void HandleAction_ActionFinished(void) { - *(gBattleStruct->field_5C + gBanksByTurnOrder[gCurrentTurnActionNumber]) = 6; + *(gBattleStruct->monToSwitchIntoId + gBanksByTurnOrder[gCurrentTurnActionNumber]) = 6; gCurrentTurnActionNumber++; gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; SpecialStatusesClear(); diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index a57df85fb..75d144c3d 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -36,9 +36,9 @@ static bool8 ShouldUseItem(void); static bool8 ShouldSwitchIfPerishSong(void) { if (gStatuses3[gActiveBank] & STATUS3_PERISH_SONG - && gDisableStructs[gActiveBank].perishSong1 == 0) + && gDisableStructs[gActiveBank].perishSongTimer1 == 0) { - *(gBattleStruct->field_294 + gActiveBank) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; EmitTwoReturnValues(1, ACTION_SWITCH, 0); return TRUE; } @@ -120,7 +120,7 @@ static bool8 ShouldSwitchIfWonderGuard(void) if (moveFlags & MOVESTATUS_SUPEREFFECTIVE && Random() % 3 < 2) { // we found a mon - *(gBattleStruct->field_294 + gActiveBank) = i; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = i; EmitTwoReturnValues(1, ACTION_SWITCH, 0); return TRUE; } @@ -206,9 +206,9 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) continue; if (i == gBattlePartyID[bankIn2]) continue; - if (i == *(gBattleStruct->field_5C + bankIn1)) + if (i == *(gBattleStruct->monToSwitchIntoId + bankIn1)) continue; - if (i == *(gBattleStruct->field_5C + bankIn2)) + if (i == *(gBattleStruct->monToSwitchIntoId + bankIn2)) continue; species = GetMonData(&party[i], MON_DATA_SPECIES); @@ -220,7 +220,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) if (absorbingTypeAbility == monAbility && Random() & 1) { // we found a mon - *(gBattleStruct->field_294 + gActiveBank) = i; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = i; EmitTwoReturnValues(1, ACTION_SWITCH, 0); return TRUE; } @@ -240,13 +240,13 @@ static bool8 ShouldSwitchIfNaturalCure(void) if ((gUnknown_02024250[gActiveBank] == 0 || gUnknown_02024250[gActiveBank] == 0xFFFF) && Random() & 1) { - *(gBattleStruct->field_294 + gActiveBank) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; EmitTwoReturnValues(1, ACTION_SWITCH, 0); return TRUE; } else if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0 && Random() & 1) { - *(gBattleStruct->field_294 + gActiveBank) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; EmitTwoReturnValues(1, ACTION_SWITCH, 0); return TRUE; } @@ -257,7 +257,7 @@ static bool8 ShouldSwitchIfNaturalCure(void) return TRUE; if (Random() & 1) { - *(gBattleStruct->field_294 + gActiveBank) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; EmitTwoReturnValues(1, ACTION_SWITCH, 0); return TRUE; } @@ -400,9 +400,9 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) continue; if (i == gBattlePartyID[bankIn2]) continue; - if (i == *(gBattleStruct->field_5C + bankIn1)) + if (i == *(gBattleStruct->monToSwitchIntoId + bankIn1)) continue; - if (i == *(gBattleStruct->field_5C + bankIn2)) + if (i == *(gBattleStruct->monToSwitchIntoId + bankIn2)) continue; species = GetMonData(&party[i], MON_DATA_SPECIES); @@ -425,7 +425,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) moveFlags = AI_TypeCalc(move, gBattleMons[bankIn1].species, gBattleMons[bankIn1].ability); if (moveFlags & MOVESTATUS_SUPEREFFECTIVE && Random() % moduloPercent == 0) { - *(gBattleStruct->field_294 + gActiveBank) = i; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = i; EmitTwoReturnValues(1, ACTION_SWITCH, 0); return TRUE; } @@ -508,9 +508,9 @@ static bool8 ShouldSwitch(void) continue; if (i == gBattlePartyID[bankIn2]) continue; - if (i == *(gBattleStruct->field_5C + bankIn1)) + if (i == *(gBattleStruct->monToSwitchIntoId + bankIn1)) continue; - if (i == *(gBattleStruct->field_5C + bankIn2)) + if (i == *(gBattleStruct->monToSwitchIntoId + bankIn2)) continue; availableToSwitch++; @@ -554,7 +554,7 @@ void AI_TrySwitchOrUseItem(void) { if (ShouldSwitch()) { - if (*(gBattleStruct->field_294 + gActiveBank) == 6) + if (*(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) == 6) { s32 monToSwitchId = GetMostSuitableMonToSwitchInto(); if (monToSwitchId == 6) @@ -590,19 +590,19 @@ void AI_TrySwitchOrUseItem(void) continue; if (monToSwitchId == gBattlePartyID[bankIn2]) continue; - if (monToSwitchId == *(gBattleStruct->field_5C + bankIn1)) + if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + bankIn1)) continue; - if (monToSwitchId == *(gBattleStruct->field_5C + bankIn2)) + if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + bankIn2)) continue; break; } } - *(gBattleStruct->field_294 + gActiveBank) = monToSwitchId; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = monToSwitchId; } - *(gBattleStruct->field_5C + gActiveBank) = *(gBattleStruct->field_294 + gActiveBank); + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank); return; } else if (ShouldUseItem()) @@ -614,28 +614,25 @@ void AI_TrySwitchOrUseItem(void) EmitTwoReturnValues(1, ACTION_USE_MOVE, (gActiveBank ^ BIT_SIDE) << 8); } -#define TYPE_FORESIGHT 0xFE -#define TYPE_ENDTABLE 0xFF - static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8 *var) { s32 i = 0; - while (gTypeEffectiveness[i] != TYPE_ENDTABLE) + while (TYPE_EFFECT_ATK_TYPE(i) != TYPE_ENDTABLE) { - if (gTypeEffectiveness[i] == TYPE_FORESIGHT) + if (TYPE_EFFECT_ATK_TYPE(i) == TYPE_FORESIGHT) { i += 3; continue; } - else if (gTypeEffectiveness[i] == atkType) + else if (TYPE_EFFECT_ATK_TYPE(i) == atkType) { // check type1 - if (gTypeEffectiveness[i + 1] == defType1) - *var = (*var * gTypeEffectiveness[i + 2]) / 10; + if (TYPE_EFFECT_DEF_TYPE(i) == defType1) + *var = (*var * TYPE_EFFECT_MULTIPLIER(i)) / 10; // check type2 - if (gTypeEffectiveness[i + 1] == defType2 && defType1 != defType2) - *var = (*var * gTypeEffectiveness[i + 2]) / 10; + if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2) + *var = (*var * TYPE_EFFECT_MULTIPLIER(i)) / 10; } i += 3; } @@ -654,8 +651,8 @@ u8 GetMostSuitableMonToSwitchInto(void) u8 invalidMons; u16 move; - if (*(gBattleStruct->field_5C + gActiveBank) != 6) - return *(gBattleStruct->field_5C + gActiveBank); + if (*(gBattleStruct->monToSwitchIntoId + gActiveBank) != 6) + return *(gBattleStruct->monToSwitchIntoId + gActiveBank); if (gBattleTypeFlags & BATTLE_TYPE_ARENA) return gBattlePartyID[gActiveBank] + 1; @@ -711,8 +708,8 @@ u8 GetMostSuitableMonToSwitchInto(void) && !(gBitTable[i] & invalidMons) && gBattlePartyID[bankIn1] != i && gBattlePartyID[bankIn2] != i - && i != *(gBattleStruct->field_5C + bankIn1) - && i != *(gBattleStruct->field_5C + bankIn2)) + && i != *(gBattleStruct->monToSwitchIntoId + bankIn1) + && i != *(gBattleStruct->monToSwitchIntoId + bankIn2)) { u8 type1 = gBaseStats[species].type1; u8 type2 = gBaseStats[species].type2; @@ -771,9 +768,9 @@ u8 GetMostSuitableMonToSwitchInto(void) continue; if (gBattlePartyID[bankIn2] == i) continue; - if (i == *(gBattleStruct->field_5C + bankIn1)) + if (i == *(gBattleStruct->monToSwitchIntoId + bankIn1)) continue; - if (i == *(gBattleStruct->field_5C + bankIn2)) + if (i == *(gBattleStruct->monToSwitchIntoId + bankIn2)) continue; for (j = 0; j < 4; j++) diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 831f434b0..0aac4cbe4 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1168,7 +1168,7 @@ static void OpponentHandleLoadMonSprite(void) static void OpponentHandleSwitchInAnim(void) { - *(gBattleStruct->field_5C + gActiveBank) = 6; + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = 6; gBattlePartyID[gActiveBank] = gBattleBufferA[gActiveBank][1]; sub_80613DC(gActiveBank, gBattleBufferA[gActiveBank][2]); gBattleBankFunc[gActiveBank] = sub_805FDF0; @@ -1627,7 +1627,7 @@ static void OpponentHandleChoosePokemon(void) { s32 chosenMonId; - if (*(gBattleStruct->field_294 + gActiveBank) == 6) + if (*(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) == 6) { chosenMonId = GetMostSuitableMonToSwitchInto(); @@ -1670,12 +1670,12 @@ static void OpponentHandleChoosePokemon(void) } else { - chosenMonId = *(gBattleStruct->field_294 + gActiveBank); - *(gBattleStruct->field_294 + gActiveBank) = 6; + chosenMonId = *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank); + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; } - *(gBattleStruct->field_5C + gActiveBank) = chosenMonId; + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = chosenMonId; EmitChosenMonReturnValue(1, chosenMonId, NULL); OpponentBufferExecCompleted(); } diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 6ace9121c..4d1afbf11 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -1581,7 +1581,7 @@ static void PlayerPartnerHandleChoosePokemon(void) } } - *(gBattleStruct->field_5C + gActiveBank) = chosenMonId; + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = chosenMonId; EmitChosenMonReturnValue(1, chosenMonId, NULL); PlayerPartnerBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 914ad9c43..096d548a7 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -1474,8 +1474,8 @@ static void RecordedOpponentHandleChooseItem(void) static void RecordedOpponentHandleChoosePokemon(void) { - *(gBattleStruct->field_5C + gActiveBank) = RecordedBattle_ReadBankAction(gActiveBank); - EmitChosenMonReturnValue(1, *(gBattleStruct->field_5C + gActiveBank), NULL); + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = RecordedBattle_ReadBankAction(gActiveBank); + EmitChosenMonReturnValue(1, *(gBattleStruct->monToSwitchIntoId + gActiveBank), NULL); RecordedOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 8db7b5626..108200a33 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -1492,8 +1492,8 @@ static void RecordedPlayerHandleChooseItem(void) static void RecordedPlayerHandleChoosePokemon(void) { - *(gBattleStruct->field_5C + gActiveBank) = RecordedBattle_ReadBankAction(gActiveBank); - EmitChosenMonReturnValue(1, *(gBattleStruct->field_5C + gActiveBank), NULL); + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = RecordedBattle_ReadBankAction(gActiveBank); + EmitChosenMonReturnValue(1, *(gBattleStruct->monToSwitchIntoId + gActiveBank), NULL); RecordedPlayerBufferExecCompleted(); } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 91be4fd9d..9dec308bb 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -13,6 +13,7 @@ #include "calculate_base_damage.h" #include "rng.h" #include "battle_controllers.h" +#include "battle_interface.h" #include "species.h" #include "songs.h" #include "text.h" @@ -118,9 +119,7 @@ struct TrainerMoney extern const struct BattleMove gBattleMoves[]; extern const struct BaseStats gBaseStats[]; -extern const u8 gTypeEffectiveness[]; -extern const u16 gMissStringIds[]; -extern const u16 gTrappingMoves[]; +extern const u8 gTypeEffectiveness[336]; extern const struct TrainerMoney gTrainerMoneyTable[]; extern const u8* const gBattleScriptsForMoveEffects[]; @@ -139,7 +138,6 @@ extern void sub_81A5BF8(void); // battle frontier 2 extern void sub_81A5D44(void); // battle frontier 2 extern void sub_81B8E80(u8 bank, u8, u8); // party menu extern bool8 sub_81B1250(void); // ? -extern u8 GetScaledHPFraction(s16 hp, s16 maxhp, u8 scale); // battle interface extern bool8 InBattlePike(void); extern bool8 InBattlePyramid(void); extern u16 GetBattlePyramidPickupItemId(void); @@ -340,7 +338,7 @@ static void atk48_playstatchangeanimation(void); static void atk49_moveend(void); static void atk4A_typecalc2(void); static void atk4B_return_atk_to_ball(void); -static void atk4C_copy_poke_data(void); +static void atk4C_get_switched_mon_data(void); static void atk4D_switch_data_update(void); static void atk4E_switchin_anim(void); static void atk4F_jump_if_cannot_switch(void); @@ -368,7 +366,7 @@ static void atk64_statusanimation(void); static void atk65_status2animation(void); static void atk66_chosenstatusanimation(void); static void atk67_yesnobox(void); -static void atk68_80246A0(void); +static void atk68_cancel_everyones_actions(void); static void atk69_dmg_adjustment3(void); static void atk6A_removeitem(void); static void atk6B_atknameinbuff1(void); @@ -457,7 +455,7 @@ static void atkBD_copyfoestats(void); static void atkBE_rapidspinfree(void); static void atkBF_set_defense_curl(void); static void atkC0_recoverbasedonsunlight(void); -static void atkC1_hidden_power(void); +static void atkC1_hidden_power_calc(void); static void atkC2_selectnexttarget(void); static void atkC3_setfutureattack(void); static void atkC4_beat_up(void); @@ -592,7 +590,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atk49_moveend, atk4A_typecalc2, atk4B_return_atk_to_ball, - atk4C_copy_poke_data, + atk4C_get_switched_mon_data, atk4D_switch_data_update, atk4E_switchin_anim, atk4F_jump_if_cannot_switch, @@ -620,7 +618,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atk65_status2animation, atk66_chosenstatusanimation, atk67_yesnobox, - atk68_80246A0, + atk68_cancel_everyones_actions, atk69_dmg_adjustment3, atk6A_removeitem, atk6B_atknameinbuff1, @@ -709,7 +707,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atkBE_rapidspinfree, atkBF_set_defense_curl, atkC0_recoverbasedonsunlight, - atkC1_hidden_power, + atkC1_hidden_power_calc, atkC2_selectnexttarget, atkC3_setfutureattack, atkC4_beat_up, @@ -828,7 +826,7 @@ static const u32 sStatusFlagsForMoveEffects[] = 0x00000000, 0x00000000, STATUS2_ESCAPE_PREVENTION, - 0x08000000, + STATUS2_NIGHTMARE, 0x00000000, 0x00000000, 0x00000000, @@ -1244,7 +1242,7 @@ bool8 JumpIfMoveAffectedByProtect(u16 move) return affected; } -bool8 AccuracyCalcHelper(u16 move) +static bool8 AccuracyCalcHelper(u16 move) { if (gStatuses3[gBankTarget] & STATUS3_ALWAYS_HITS && gDisableStructs[gBankTarget].bankWithSureHit == gBankAttacker) { @@ -1543,9 +1541,6 @@ static void ModulateDmgByType(u8 multiplier) } } -#define TYPE_FORESIGHT 0xFE -#define TYPE_ENDTABLE 0xFF - static void atk06_typecalc(void) { s32 i = 0; @@ -1577,24 +1572,24 @@ static void atk06_typecalc(void) } else { - while (gTypeEffectiveness[i] != TYPE_ENDTABLE) + while (TYPE_EFFECT_ATK_TYPE(i) != TYPE_ENDTABLE) { - if (gTypeEffectiveness[i] == TYPE_FORESIGHT) + if (TYPE_EFFECT_ATK_TYPE(i) == TYPE_FORESIGHT) { if (gBattleMons[gBankTarget].status2 & STATUS2_FORESIGHT) break; i += 3; continue; } - else if (gTypeEffectiveness[i] == moveType) + else if (TYPE_EFFECT_ATK_TYPE(i) == moveType) { // check type1 - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type1) - ModulateDmgByType(gTypeEffectiveness[i + 2]); + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type1) + ModulateDmgByType(TYPE_EFFECT_MULTIPLIER(i)); // check type2 - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 && + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type2 && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2) - ModulateDmgByType(gTypeEffectiveness[i + 2]); + ModulateDmgByType(TYPE_EFFECT_MULTIPLIER(i)); } i += 3; } @@ -1636,45 +1631,46 @@ static void CheckWonderGuardAndLevitate(void) return; } - while (gTypeEffectiveness[i] != TYPE_ENDTABLE) + while (TYPE_EFFECT_ATK_TYPE(i) != TYPE_ENDTABLE) { - if (gTypeEffectiveness[i] == TYPE_FORESIGHT) + if (TYPE_EFFECT_ATK_TYPE(i) == TYPE_FORESIGHT) { if (gBattleMons[gBankTarget].status2 & STATUS2_FORESIGHT) break; i += 3; continue; } - if (gTypeEffectiveness[i] == moveType) + if (TYPE_EFFECT_ATK_TYPE(i) == moveType) { // check no effect - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type1 && gTypeEffectiveness[i + 2] == 0) + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type1 + && TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NO_EFFECT) { gBattleMoveFlags |= MOVESTATUS_NOTAFFECTED; gProtectStructs[gBankAttacker].targetNotAffected = 1; } - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 && + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type2 && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 && - gTypeEffectiveness[i + 2] == TYPE_MUL_NO_EFFECT) + TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NO_EFFECT) { gBattleMoveFlags |= MOVESTATUS_NOTAFFECTED; gProtectStructs[gBankAttacker].targetNotAffected = 1; } // check super effective - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type1 && gTypeEffectiveness[i + 2] == 20) + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type1 && TYPE_EFFECT_MULTIPLIER(i) == 20) flags |= 1; - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type2 && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 - && gTypeEffectiveness[i + 2] == TYPE_MUL_SUPER_EFFECTIVE) + && TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE) flags |= 1; // check not very effective - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type1 && gTypeEffectiveness[i + 2] == 5) + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type1 && TYPE_EFFECT_MULTIPLIER(i) == 5) flags |= 2; - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type2 && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 - && gTypeEffectiveness[i + 2] == TYPE_MUL_NOT_EFFECTIVE) + && TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NOT_EFFECTIVE) flags |= 2; } i += 3; @@ -1749,9 +1745,9 @@ u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef) } else { - while (gTypeEffectiveness[i]!= TYPE_ENDTABLE) + while (TYPE_EFFECT_ATK_TYPE(i) != TYPE_ENDTABLE) { - if (gTypeEffectiveness[i] == TYPE_FORESIGHT) + if (TYPE_EFFECT_ATK_TYPE(i) == TYPE_FORESIGHT) { if (gBattleMons[bankDef].status2 & STATUS2_FORESIGHT) break; @@ -1759,15 +1755,15 @@ u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef) continue; } - else if (gTypeEffectiveness[i] == moveType) + else if (TYPE_EFFECT_ATK_TYPE(i) == moveType) { // check type1 - if (gTypeEffectiveness[i + 1] == gBattleMons[bankDef].type1) - ModulateDmgByType2(gTypeEffectiveness[i + 2], move, &flags); + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[bankDef].type1) + ModulateDmgByType2(TYPE_EFFECT_MULTIPLIER(i), move, &flags); // check type2 - if (gTypeEffectiveness[i + 1] == gBattleMons[bankDef].type2 && + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[bankDef].type2 && gBattleMons[bankDef].type1 != gBattleMons[bankDef].type2) - ModulateDmgByType2(gTypeEffectiveness[i + 2], move, &flags); + ModulateDmgByType2(TYPE_EFFECT_MULTIPLIER(i), move, &flags); } i += 3; } @@ -1801,21 +1797,21 @@ u8 AI_TypeCalc(u16 move, u16 targetSpecies, u8 targetAbility) } else { - while (gTypeEffectiveness[i] != TYPE_ENDTABLE) + while (TYPE_EFFECT_ATK_TYPE(i) != TYPE_ENDTABLE) { - if (gTypeEffectiveness[i] == TYPE_FORESIGHT) + if (TYPE_EFFECT_ATK_TYPE(i) == TYPE_FORESIGHT) { i += 3; continue; } - if (gTypeEffectiveness[i] == moveType) + if (TYPE_EFFECT_ATK_TYPE(i) == moveType) { // check type1 - if (gTypeEffectiveness[i + 1] == type1) - ModulateDmgByType2(gTypeEffectiveness[i + 2], move, &flags); + if (TYPE_EFFECT_DEF_TYPE(i) == type1) + ModulateDmgByType2(TYPE_EFFECT_MULTIPLIER(i), move, &flags); // check type2 - if (gTypeEffectiveness[i + 1] == type2 && type1 != type2) - ModulateDmgByType2(gTypeEffectiveness[i + 2], move, &flags); + if (TYPE_EFFECT_DEF_TYPE(i) == type2 && type1 != type2) + ModulateDmgByType2(TYPE_EFFECT_MULTIPLIER(i), move, &flags); } i += 3; } @@ -5235,9 +5231,9 @@ static void atk4A_typecalc2(void) } else { - while (gTypeEffectiveness[i]!= TYPE_ENDTABLE) + while (TYPE_EFFECT_ATK_TYPE(i) != TYPE_ENDTABLE) { - if (gTypeEffectiveness[i] == TYPE_FORESIGHT) + if (TYPE_EFFECT_ATK_TYPE(i) == TYPE_FORESIGHT) { if (gBattleMons[gBankTarget].status2 & STATUS2_FORESIGHT) { @@ -5250,43 +5246,43 @@ static void atk4A_typecalc2(void) } } - if (gTypeEffectiveness[i] == moveType) + if (TYPE_EFFECT_ATK_TYPE(i) == moveType) { // check type1 - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type1) + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type1) { - if (gTypeEffectiveness[i + 2] == 0) + if (TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NO_EFFECT) { gBattleMoveFlags |= MOVESTATUS_NOTAFFECTED; break; } - if (gTypeEffectiveness[i + 2] == 5) + if (TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NOT_EFFECTIVE) { flags |= MOVESTATUS_NOTVERYEFFECTIVE; } - if (gTypeEffectiveness[i + 2] == 20) + if (TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE) { flags |= MOVESTATUS_SUPEREFFECTIVE; } } // check type2 - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2) + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type2) { if (gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 - && gTypeEffectiveness[i + 2] == 0) + && TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NO_EFFECT) { gBattleMoveFlags |= MOVESTATUS_NOTAFFECTED; break; } - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type2 && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 - && gTypeEffectiveness[i + 2] == 5) + && TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NOT_EFFECTIVE) { flags |= MOVESTATUS_NOTVERYEFFECTIVE; } - if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 + if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBankTarget].type2 && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 - && gTypeEffectiveness[i + 2] == 20) + && TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE) { flags |= MOVESTATUS_SUPEREFFECTIVE; } @@ -5325,16 +5321,16 @@ static void atk4B_return_atk_to_ball(void) gBattlescriptCurrInstr++; } -static void atk4C_copy_poke_data(void) +static void atk4C_get_switched_mon_data(void) { if (gBattleExecBuffer) return; gActiveBank = GetBattleBank(gBattlescriptCurrInstr[1]); - gBattlePartyID[gActiveBank] = *(gBattleStruct->field_5C + gActiveBank); + gBattlePartyID[gActiveBank] = *(gBattleStruct->monToSwitchIntoId + gActiveBank); - EmitGetMonData(0, 0, gBitTable[gBattlePartyID[gActiveBank]]); + EmitGetMonData(0, REQUEST_ALL_BATTLE, gBitTable[gBattlePartyID[gActiveBank]]); MarkBufferBankForExecution(gActiveBank); gBattlescriptCurrInstr += 2; @@ -5371,7 +5367,7 @@ static void atk4D_switch_data_update(void) if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS) { - for (i = 0; i < 8; i++) + for (i = 0; i < BATTLE_STATS_NO; i++) { gBattleMons[gActiveBank].statStages[i] = oldData.statStages[i]; } @@ -5387,11 +5383,8 @@ static void atk4D_switch_data_update(void) } gBattleScripting.bank = gActiveBank; - gBattleTextBuff1[0] = PLACEHOLDER_BEGIN; - gBattleTextBuff1[1] = 7; - gBattleTextBuff1[2] = gActiveBank; - gBattleTextBuff1[3] = gBattlePartyID[gActiveBank]; - gBattleTextBuff1[4] = EOS; + + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gActiveBank, gBattlePartyID[gActiveBank]); gBattlescriptCurrInstr += 2; } @@ -5579,7 +5572,7 @@ static void atk4F_jump_if_cannot_switch(void) static void sub_804CF10(u8 arg0) { *(gBattleStruct->field_58 + gActiveBank) = gBattlePartyID[gActiveBank]; - *(gBattleStruct->field_5C + gActiveBank) = 6; + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = 6; gBattleStruct->field_93 &= ~(gBitTable[gActiveBank]); EmitChoosePokemon(0, 1, arg0, 0, gBattleStruct->field_60[gActiveBank]); @@ -5643,7 +5636,7 @@ static void atk50_openpartyscreen(void) } else if (!gSpecialStatuses[gActiveBank].flag40) { - sub_804CF10(gBattleStruct->field_5C[2]); + sub_804CF10(gBattleStruct->monToSwitchIntoId[2]); gSpecialStatuses[gActiveBank].flag40 = 1; } else @@ -5665,7 +5658,7 @@ static void atk50_openpartyscreen(void) } else if (!gSpecialStatuses[gActiveBank].flag40) { - sub_804CF10(gBattleStruct->field_5C[0]); + sub_804CF10(gBattleStruct->monToSwitchIntoId[0]); gSpecialStatuses[gActiveBank].flag40 = 1; } else if (!(flags & 1)) @@ -5686,7 +5679,7 @@ static void atk50_openpartyscreen(void) } else if (!gSpecialStatuses[gActiveBank].flag40) { - sub_804CF10(gBattleStruct->field_5C[3]); + sub_804CF10(gBattleStruct->monToSwitchIntoId[3]); gSpecialStatuses[gActiveBank].flag40 = 1; } else @@ -5708,7 +5701,7 @@ static void atk50_openpartyscreen(void) } else if (!gSpecialStatuses[gActiveBank].flag40) { - sub_804CF10(gBattleStruct->field_5C[1]); + sub_804CF10(gBattleStruct->monToSwitchIntoId[1]); gSpecialStatuses[gActiveBank].flag40 = 1; } else if (!(flags & 2)) @@ -5771,7 +5764,7 @@ static void atk50_openpartyscreen(void) } else if (!gSpecialStatuses[gActiveBank].flag40) { - sub_804CF10(gBattleStruct->field_5C[0]); + sub_804CF10(gBattleStruct->monToSwitchIntoId[0]); gSpecialStatuses[gActiveBank].flag40 = 1; } } @@ -5787,7 +5780,7 @@ static void atk50_openpartyscreen(void) } else if (!gSpecialStatuses[gActiveBank].flag40) { - sub_804CF10(gBattleStruct->field_5C[1]); + sub_804CF10(gBattleStruct->monToSwitchIntoId[1]); gSpecialStatuses[gActiveBank].flag40 = 1; } } @@ -5841,10 +5834,10 @@ static void atk50_openpartyscreen(void) { gActiveBank = bank; *(gBattleStruct->field_58 + gActiveBank) = gBattlePartyID[gActiveBank]; - *(gBattleStruct->field_5C + gActiveBank) = 6; + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = 6; gBattleStruct->field_93 &= ~(gBitTable[gActiveBank]); - EmitChoosePokemon(0, hitmarkerFaintBits, *(gBattleStruct->field_5C + (gActiveBank ^ 2)), 0, gBattleStruct->field_60[gActiveBank]); + EmitChoosePokemon(0, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + (gActiveBank ^ 2)), 0, gBattleStruct->field_60[gActiveBank]); MarkBufferBankForExecution(gActiveBank); gBattlescriptCurrInstr += 6; @@ -5891,7 +5884,7 @@ static void atk51_switch_handle_order(void) { if (gBattleBufferB[i][0] == 0x22) { - *(gBattleStruct->field_5C + i) = gBattleBufferB[i][1]; + *(gBattleStruct->monToSwitchIntoId + i) = gBattleBufferB[i][1]; if (!(gBattleStruct->field_93 & gBitTable[i])) { RecordedBattle_SetBankAction(i, gBattleBufferB[i][1]); @@ -5913,7 +5906,7 @@ static void atk51_switch_handle_order(void) // fall through case 3: gBattleCommunication[0] = gBattleBufferB[gActiveBank][1]; - *(gBattleStruct->field_5C + gActiveBank) = gBattleBufferB[gActiveBank][1]; + *(gBattleStruct->monToSwitchIntoId + gActiveBank) = gBattleBufferB[gActiveBank][1]; if (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI) { @@ -5927,7 +5920,7 @@ static void atk51_switch_handle_order(void) } else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { - sub_80571DC(gActiveBank, *(gBattleStruct->field_5C + gActiveBank)); + sub_80571DC(gActiveBank, *(gBattleStruct->monToSwitchIntoId + gActiveBank)); } else { @@ -6576,7 +6569,7 @@ static void atk67_yesnobox(void) } } -static void atk68_80246A0(void) +static void atk68_cancel_everyones_actions(void) { s32 i; @@ -8034,7 +8027,7 @@ static void atk8F_forcerandomswitch(void) || GetMonData(&party[i], MON_DATA_IS_EGG) == TRUE || GetMonData(&party[i], MON_DATA_HP) == 0); } - *(gBattleStruct->field_5C + gBankTarget) = i; + *(gBattleStruct->monToSwitchIntoId + gBankTarget) = i; if (!sub_81B1250()) sub_803BDA0(gBankTarget); @@ -8558,13 +8551,11 @@ static void atk9D_mimicattackcopy(void) } } -#ifdef NONMATCHING static void atk9E_metronome(void) { while (1) { - const u16 *move; - s32 i, j; + s32 i; gCurrentMove = (Random() & 0x1FF) + 1; if (gCurrentMove > LAST_MOVE_INDEX) @@ -8572,102 +8563,26 @@ static void atk9E_metronome(void) for (i = 0; i < 4; i++); // ? - for (move = sMovesForbiddenToCopy; ; move++) + i = -1; + while (1) { - if (*move == gCurrentMove) + i++; + if (sMovesForbiddenToCopy[i] == gCurrentMove) break; - if (*move == METRONOME_FORBIDDEN_END) + if (sMovesForbiddenToCopy[i] == METRONOME_FORBIDDEN_END) break; } - if (*move == METRONOME_FORBIDDEN_END) - break; + if (sMovesForbiddenToCopy[i] == METRONOME_FORBIDDEN_END) + { + gHitMarker &= ~(HITMARKER_ATTACKSTRING_PRINTED); + gBattlescriptCurrInstr = gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]; + gBankTarget = GetMoveTarget(gCurrentMove, 0); + return; + } } - - gHitMarker &= ~(HITMARKER_ATTACKSTRING_PRINTED); - gBattlescriptCurrInstr = gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]; - gBankTarget = GetMoveTarget(gCurrentMove, 0); } -#else -__attribute__((naked)) -static void atk9E_metronome(void) -{ - asm( - "\n\ - .syntax unified\n\ - push {r4-r7,lr}\n\ - mov r7, r8\n\ - push {r7}\n\ - ldr r7, =gCurrentMove\n\ - movs r6, 0xB1\n\ - lsls r6, 1\n\ - ldr r5, =sMovesForbiddenToCopy\n\ - ldr r0, =gBattlescriptCurrInstr\n\ - mov r8, r0\n\ -_080524EE:\n\ - bl Random\n\ - ldr r2, =0x000001ff\n\ - adds r1, r2, 0\n\ - ands r0, r1\n\ - adds r0, 0x1\n\ - strh r0, [r7]\n\ - cmp r0, r6\n\ - bhi _080524EE\n\ - movs r0, 0x3\n\ -_08052502:\n\ - subs r0, 0x1\n\ - cmp r0, 0\n\ - bge _08052502\n\ - ldr r4, =gCurrentMove\n\ - ldrh r2, [r4]\n\ - ldr r3, =0x0000ffff\n\ - subs r0, r5, 0x2\n\ -_08052510:\n\ - adds r0, 0x2\n\ - ldrh r1, [r0]\n\ - cmp r1, r2\n\ - beq _0805251C\n\ - cmp r1, r3\n\ - bne _08052510\n\ -_0805251C:\n\ - ldr r0, =0x0000ffff\n\ - cmp r1, r0\n\ - bne _080524EE\n\ - ldr r2, =gHitMarker\n\ - ldr r0, [r2]\n\ - ldr r1, =0xfffffbff\n\ - ands r0, r1\n\ - str r0, [r2]\n\ - ldr r3, =gBattleScriptsForMoveEffects\n\ - ldr r2, =gBattleMoves\n\ - ldrh r1, [r4]\n\ - lsls r0, r1, 1\n\ - adds r0, r1\n\ - lsls r0, 2\n\ - adds r0, r2\n\ - ldrb r0, [r0]\n\ - lsls r0, 2\n\ - adds r0, r3\n\ - ldr r0, [r0]\n\ - mov r1, r8\n\ - str r0, [r1]\n\ - ldrh r0, [r4]\n\ - movs r1, 0\n\ - bl GetMoveTarget\n\ - ldr r1, =gBankTarget\n\ - strb r0, [r1]\n\ - pop {r3}\n\ - mov r8, r3\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .pool\n\ - .syntax divided"); -} - -#endif // NONMATCHING - static void atk9F_dmgtolevel(void) { gBattleMoveDamage = gBattleMons[gBankAttacker].level; @@ -8814,7 +8729,6 @@ static void atkA5_painsplitdmgcalc(void) } } -#ifdef NONMATCHING static void atkA6_settypetorandomresistance(void) // conversion 2 { if (gUnknown_02024250[gBankAttacker] == 0 @@ -8829,298 +8743,58 @@ static void atkA6_settypetorandomresistance(void) // conversion 2 } else { - s32 type = 0, rands = 0; - do + s32 i, j, rands; + + for (rands = 0; rands < 1000; rands++) { - while (((type = (Random() & 0x7F)) > 0x70)); + while (((i = (Random() & 0x7F)) > sizeof(gTypeEffectiveness) / 3)); - type *= 3; + i *= 3; - if (gTypeEffectiveness[type] == gUnknown_02024258[gBankAttacker] - && gTypeEffectiveness[type + 2] <= 5 - && gBattleMons[gBankAttacker].type1 != gTypeEffectiveness[type + 1] - && gBattleMons[gBankAttacker].type2 != gTypeEffectiveness[type + 1]) + if (TYPE_EFFECT_ATK_TYPE(i) == gUnknown_02024258[gBankAttacker] + && TYPE_EFFECT_MULTIPLIER(i) <= TYPE_MUL_NOT_EFFECTIVE + && gBattleMons[gBankAttacker].type1 != TYPE_EFFECT_DEF_TYPE(i) + && gBattleMons[gBankAttacker].type2 != TYPE_EFFECT_DEF_TYPE(i)) { - gBattleMons[gBankAttacker].type1 = type; - gBattleMons[gBankAttacker].type2 = type; + gBattleMons[gBankAttacker].type1 = TYPE_EFFECT_DEF_TYPE(i); + gBattleMons[gBankAttacker].type2 = TYPE_EFFECT_DEF_TYPE(i); - PREPARE_TYPE_BUFFER(gBattleTextBuff1, type) + PREPARE_TYPE_BUFFER(gBattleTextBuff1, TYPE_EFFECT_DEF_TYPE(i)) gBattlescriptCurrInstr += 5; return; } + } - rands++; - } while (rands <= 999); - - type = 0, rands = 0; - do + for (j = 0, rands = 0; rands < sizeof(gTypeEffectiveness); j += 3, rands += 3) { - s8 var = (s8)(gTypeEffectiveness[type]); - if (var > -1 || var < -2) + switch (TYPE_EFFECT_ATK_TYPE(j)) { - if (gTypeEffectiveness[type] == gUnknown_02024258[gBankAttacker] - && gTypeEffectiveness[type + 2] <= 5 - && gBattleMons[gBankAttacker].type1 != gTypeEffectiveness[type + 1] - && gBattleMons[gBankAttacker].type2 != gTypeEffectiveness[type + 1]) + case TYPE_ENDTABLE: + case TYPE_FORESIGHT: + break; + default: + if (TYPE_EFFECT_ATK_TYPE(j) == gUnknown_02024258[gBankAttacker] + && TYPE_EFFECT_MULTIPLIER(j) <= 5 + && gBattleMons[gBankAttacker].type1 != TYPE_EFFECT_DEF_TYPE(i) + && gBattleMons[gBankAttacker].type2 != TYPE_EFFECT_DEF_TYPE(i)) { - gBattleMons[gBankAttacker].type1 = gTypeEffectiveness[rands + 1]; - gBattleMons[gBankAttacker].type2 = gTypeEffectiveness[rands + 1]; + gBattleMons[gBankAttacker].type1 = TYPE_EFFECT_DEF_TYPE(rands); + gBattleMons[gBankAttacker].type2 = TYPE_EFFECT_DEF_TYPE(rands); - PREPARE_TYPE_BUFFER(gBattleTextBuff1, gTypeEffectiveness[rands + 1]) + PREPARE_TYPE_BUFFER(gBattleTextBuff1, TYPE_EFFECT_DEF_TYPE(rands)) gBattlescriptCurrInstr += 5; return; } + break; } - type += 3, rands += 3; - } while (rands < 336); + } gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 1); } } -#else -__attribute__((naked)) -static void atkA6_settypetorandomresistance(void) // conversion 2 -{ - asm(".syntax unified\n\ - push {r4-r7,lr}\n\ - mov r7, r10\n\ - mov r6, r9\n\ - mov r5, r8\n\ - push {r5-r7}\n\ - ldr r1, =gUnknown_02024250\n\ - ldr r4, =gBankAttacker\n\ - ldrb r0, [r4]\n\ - lsls r0, 1\n\ - adds r2, r0, r1\n\ - ldrh r1, [r2]\n\ - cmp r1, 0\n\ - beq _08052B7E\n\ - ldr r0, =0x0000ffff\n\ - cmp r1, r0\n\ - beq _08052B7E\n\ - ldrh r0, [r2]\n\ - bl IsTwoTurnsMove\n\ - lsls r0, 24\n\ - cmp r0, 0\n\ - beq _08052C1C\n\ - ldr r1, =gBattleMons\n\ - ldr r2, =gUnknown_02024270\n\ - ldrb r0, [r4]\n\ - adds r0, r2\n\ - ldrb r2, [r0]\n\ - movs r0, 0x58\n\ - muls r0, r2\n\ - adds r1, 0x50\n\ - adds r0, r1\n\ - ldr r0, [r0]\n\ - movs r1, 0x80\n\ - lsls r1, 5\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _08052C1C\n\ -_08052B7E:\n\ - ldr r3, =gBattlescriptCurrInstr\n\ - ldr r2, [r3]\n\ - ldrb r1, [r2, 0x1]\n\ - ldrb r0, [r2, 0x2]\n\ - lsls r0, 8\n\ - orrs r1, r0\n\ - ldrb r0, [r2, 0x3]\n\ - lsls r0, 16\n\ - orrs r1, r0\n\ - ldrb r0, [r2, 0x4]\n\ - lsls r0, 24\n\ - orrs r1, r0\n\ - str r1, [r3]\n\ - b _08052D08\n\ - .pool\n\ -_08052BB4:\n\ - mov r0, r12\n\ - strb r5, [r0]\n\ - mov r1, r10\n\ - ldrb r0, [r1]\n\ - muls r0, r2\n\ - adds r0, r7\n\ - adds r0, 0x22\n\ - strb r5, [r0]\n\ - ldr r1, =gBattleTextBuff1\n\ - movs r0, 0xFD\n\ - strb r0, [r1]\n\ - movs r0, 0x3\n\ - strb r0, [r1, 0x1]\n\ - strb r5, [r1, 0x2]\n\ - movs r0, 0xFF\n\ - strb r0, [r1, 0x3]\n\ - ldr r1, =gBattlescriptCurrInstr\n\ - b _08052C0A\n\ - .pool\n\ -_08052BE0:\n\ - mov r0, r8\n\ - adds r0, 0x1\n\ - adds r0, r3\n\ - ldrb r2, [r0]\n\ - strb r2, [r4]\n\ - mov r4, r10\n\ - ldrb r0, [r4]\n\ - muls r0, r6\n\ - ldr r7, =gBattleMons\n\ - adds r0, r7\n\ - adds r0, 0x22\n\ - strb r2, [r0]\n\ - ldr r1, =gBattleTextBuff1\n\ - movs r0, 0xFD\n\ - strb r0, [r1]\n\ - movs r0, 0x3\n\ - strb r0, [r1, 0x1]\n\ - strb r2, [r1, 0x2]\n\ - movs r0, 0xFF\n\ - strb r0, [r1, 0x3]\n\ - mov r1, r12\n\ -_08052C0A:\n\ - ldr r0, [r1]\n\ - adds r0, 0x5\n\ - str r0, [r1]\n\ - b _08052D08\n\ - .pool\n\ -_08052C1C:\n\ - movs r4, 0\n\ - mov r8, r4\n\ - movs r7, 0x7F\n\ - mov r9, r7\n\ -_08052C24:\n\ - bl Random\n\ - mov r4, r9\n\ - ands r4, r0\n\ - cmp r4, 0x70\n\ - bhi _08052C24\n\ - lsls r0, r4, 1\n\ - adds r4, r0, r4\n\ - ldr r6, =gTypeEffectiveness\n\ - adds r3, r4, r6\n\ - ldr r1, =gUnknown_02024258\n\ - ldr r2, =gBankAttacker\n\ - ldrb r5, [r2]\n\ - lsls r0, r5, 1\n\ - adds r0, r1\n\ - ldrb r1, [r3]\n\ - mov r10, r2\n\ - ldrh r0, [r0]\n\ - cmp r1, r0\n\ - bne _08052C80\n\ - adds r0, r4, 0x2\n\ - adds r0, r6\n\ - ldrb r0, [r0]\n\ - cmp r0, 0x5\n\ - bhi _08052C80\n\ - ldr r7, =gBattleMons\n\ - movs r2, 0x58\n\ - adds r0, r5, 0\n\ - muls r0, r2\n\ - adds r3, r0, r7\n\ - movs r0, 0x21\n\ - adds r0, r3\n\ - mov r12, r0\n\ - adds r0, r4, 0x1\n\ - adds r0, r6\n\ - ldrb r5, [r0]\n\ - mov r1, r12\n\ - ldrb r0, [r1]\n\ - adds r1, r5, 0\n\ - cmp r0, r1\n\ - beq _08052C80\n\ - adds r0, r3, 0\n\ - adds r0, 0x22\n\ - ldrb r0, [r0]\n\ - cmp r0, r1\n\ - bne _08052BB4\n\ -_08052C80:\n\ - movs r7, 0x1\n\ - add r8, r7\n\ - ldr r0, =0x000003e7\n\ - cmp r8, r0\n\ - ble _08052C24\n\ - movs r0, 0\n\ - mov r8, r0\n\ - ldr r1, =gBattlescriptCurrInstr\n\ - mov r12, r1\n\ - ldr r3, =gTypeEffectiveness\n\ - adds r0, r4, 0x1\n\ - adds r0, r3\n\ - mov r9, r0\n\ - adds r5, r3, 0\n\ -_08052C9C:\n\ - ldrb r1, [r5]\n\ - cmp r1, 0xFF\n\ - bgt _08052CA6\n\ - cmp r1, 0xFE\n\ - bge _08052CE0\n\ -_08052CA6:\n\ - mov r4, r10\n\ - ldrb r2, [r4]\n\ - lsls r0, r2, 1\n\ - ldr r7, =gUnknown_02024258\n\ - adds r0, r7\n\ - ldrh r0, [r0]\n\ - cmp r1, r0\n\ - bne _08052CE0\n\ - ldrb r0, [r5, 0x2]\n\ - cmp r0, 0x5\n\ - bhi _08052CE0\n\ - movs r6, 0x58\n\ - adds r0, r2, 0\n\ - muls r0, r6\n\ - ldr r1, =gBattleMons\n\ - adds r2, r0, r1\n\ - adds r4, r2, 0\n\ - adds r4, 0x21\n\ - ldrb r0, [r4]\n\ - mov r7, r9\n\ - ldrb r1, [r7]\n\ - cmp r0, r1\n\ - beq _08052CE0\n\ - adds r0, r2, 0\n\ - adds r0, 0x22\n\ - ldrb r0, [r0]\n\ - cmp r0, r1\n\ - beq _08052CE0\n\ - b _08052BE0\n\ -_08052CE0:\n\ - adds r5, 0x3\n\ - movs r0, 0x3\n\ - add r8, r0\n\ - ldr r0, =0x0000014f\n\ - cmp r8, r0\n\ - bls _08052C9C\n\ - mov r1, r12\n\ - ldr r2, [r1]\n\ - ldrb r1, [r2, 0x1]\n\ - ldrb r0, [r2, 0x2]\n\ - lsls r0, 8\n\ - orrs r1, r0\n\ - ldrb r0, [r2, 0x3]\n\ - lsls r0, 16\n\ - orrs r1, r0\n\ - ldrb r0, [r2, 0x4]\n\ - lsls r0, 24\n\ - orrs r1, r0\n\ - mov r4, r12\n\ - str r1, [r4]\n\ -_08052D08:\n\ - pop {r3-r5}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - mov r10, r5\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .pool\n\ - .syntax divided"); -} -#endif // NONMATCHING - static void atkA7_setalwayshitflag(void) { gStatuses3[gBankTarget] &= ~(STATUS3_ALWAYS_HITS); @@ -9504,8 +9178,8 @@ static void atkB2_setperishsong(void) else { gStatuses3[i] |= STATUS3_PERISH_SONG; - gDisableStructs[i].perishSong1 = 3; - gDisableStructs[i].perishSong2 = 3; + gDisableStructs[i].perishSongTimer1 = 3; + gDisableStructs[i].perishSongTimer2 = 3; } } @@ -9859,24 +9533,24 @@ static void atkC0_recoverbasedonsunlight(void) } #ifdef NONMATCHING -static void atkC1_hidden_power(void) +static void atkC1_hidden_power_calc(void) { - s32 powerBits; - s32 typeBits; + u32 powerBits = 0; + u32 typeBits = 0; - powerBits = ((gBattleMons[gBankAttacker].hpIV & 2) >> 1) - | ((gBattleMons[gBankAttacker].attackIV & 2) << 0) - | ((gBattleMons[gBankAttacker].defenseIV & 2) << 1) - | ((gBattleMons[gBankAttacker].speedIV & 2) << 2) - | ((gBattleMons[gBankAttacker].spAttackIV & 2) << 3) - | ((gBattleMons[gBankAttacker].spDefenseIV & 2) << 4); + powerBits |= ((gBattleMons[gBankAttacker].hpIV & 2) >> 1); + powerBits |= ((gBattleMons[gBankAttacker].attackIV & 2) << 0); + powerBits |= ((gBattleMons[gBankAttacker].defenseIV & 2) << 1); + powerBits |= ((gBattleMons[gBankAttacker].speedIV & 2) << 2); + powerBits |= ((gBattleMons[gBankAttacker].spAttackIV & 2) << 3); + powerBits |= ((gBattleMons[gBankAttacker].spDefenseIV & 2) << 4); - typeBits = ((gBattleMons[gBankAttacker].hpIV & 1) << 0) - | ((gBattleMons[gBankAttacker].attackIV & 1) << 1) - | ((gBattleMons[gBankAttacker].defenseIV & 1) << 2) - | ((gBattleMons[gBankAttacker].speedIV & 1) << 3) - | ((gBattleMons[gBankAttacker].spAttackIV & 1) << 4) - | ((gBattleMons[gBankAttacker].spDefenseIV & 1) << 5); + typeBits |= ((gBattleMons[gBankAttacker].hpIV & 1) << 0); + typeBits |= ((gBattleMons[gBankAttacker].attackIV & 1) << 1); + typeBits |= ((gBattleMons[gBankAttacker].defenseIV & 1) << 2); + typeBits |= ((gBattleMons[gBankAttacker].speedIV & 1) << 3); + typeBits |= ((gBattleMons[gBankAttacker].spAttackIV & 1) << 4); + typeBits |= ((gBattleMons[gBankAttacker].spDefenseIV & 1) << 5); gDynamicBasePower = (40 * powerBits) / 63 + 30; @@ -9890,7 +9564,7 @@ static void atkC1_hidden_power(void) #else __attribute__((naked)) -static void atkC1_hidden_power(void) +static void atkC1_hidden_power_calc(void) { asm(".syntax unified\n\ push {r4-r7,lr}\n\ diff --git a/src/battle_util.c b/src/battle_util.c index 468b2c46d..b5357a0e0 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1292,9 +1292,9 @@ bool8 sub_8041364(void) gBattleTextBuff1[1] = 1; gBattleTextBuff1[2] = 1; gBattleTextBuff1[3] = 1; - gBattleTextBuff1[4] = gDisableStructs[gActiveBank].perishSong1; + gBattleTextBuff1[4] = gDisableStructs[gActiveBank].perishSongTimer1; gBattleTextBuff1[5] = EOS; - if (gDisableStructs[gActiveBank].perishSong1 == 0) + if (gDisableStructs[gActiveBank].perishSongTimer1 == 0) { gStatuses3[gActiveBank] &= ~STATUS3_PERISH_SONG; gBattleMoveDamage = gBattleMons[gActiveBank].hp; @@ -1302,7 +1302,7 @@ bool8 sub_8041364(void) } else { - gDisableStructs[gActiveBank].perishSong1--; + gDisableStructs[gActiveBank].perishSongTimer1--; gBattlescriptCurrInstr = gUnknown_082DAF20; } BattleScriptExecute(gBattlescriptCurrInstr); @@ -1805,7 +1805,7 @@ bool8 sub_80423F4(u8 bank, u8 r1, u8 r2) && GetMonData(&party[i], MON_DATA_SPECIES2) != 0 && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG // FIXME: Using index[array] instead of array[index] is BAD! - && i != r1 && i != r2 && i != r7[gBattleStruct->field_5C] && i != r6[gBattleStruct->field_5C]) + && i != r1 && i != r2 && i != r7[gBattleStruct->monToSwitchIntoId] && i != r6[gBattleStruct->monToSwitchIntoId]) break; } return (i == 6); diff --git a/src/battle_util2.c b/src/battle_util2.c new file mode 100644 index 000000000..e119c85d7 --- /dev/null +++ b/src/battle_util2.c @@ -0,0 +1,219 @@ +#include "global.h" +#include "battle.h" +#include "battle_controllers.h" +#include "malloc.h" +#include "pokemon.h" +#include "event_data.h" +#include "abilities.h" +#include "rng.h" + +extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT]; +extern u16 gBattlePartyID[BATTLE_BANKS_COUNT]; +extern u8 gUnknown_0203CF00[]; +extern const u8* gBattlescriptCurrInstr; +extern u8 gBattleCommunication[]; +extern u8 gActiveBank; + +extern const u8 BattleScript_MoveUsedWokeUp[]; +extern const u8 BattleScript_MoveUsedIsFrozen[]; +extern const u8 BattleScript_MoveUsedUnfroze[]; +extern const u8 BattleScript_MoveUsedIsAsleep[]; + +extern void sub_81D55D0(void); +extern void sub_81D5694(void); +extern u8 pokemon_order_func(u8); +extern void sub_81B8FB0(u8, u8); + +void AllocateBattleResources(void) +{ + gBattleResources = gBattleResources; // something dumb needed to match + + if (gBattleTypeFlags & BATTLE_TYPE_x4000000) + sub_81D55D0(); + + gBattleStruct = AllocZeroed(sizeof(*gBattleStruct)); + + gBattleResources = AllocZeroed(sizeof(*gBattleResources)); + gBattleResources->secretBase = AllocZeroed(sizeof(*gBattleResources->secretBase)); + gBattleResources->flags = AllocZeroed(sizeof(*gBattleResources->flags)); + gBattleResources->battleScriptsStack = AllocZeroed(sizeof(*gBattleResources->battleScriptsStack)); + gBattleResources->battleCallbackStack = AllocZeroed(sizeof(*gBattleResources->battleCallbackStack)); + gBattleResources->statsBeforeLvlUp = AllocZeroed(sizeof(*gBattleResources->statsBeforeLvlUp)); + gBattleResources->ai = AllocZeroed(sizeof(*gBattleResources->ai)); + gBattleResources->battleHistory = AllocZeroed(sizeof(*gBattleResources->battleHistory)); + gBattleResources->AI_ScriptsStack = AllocZeroed(sizeof(*gBattleResources->AI_ScriptsStack)); + + gLinkBattleSendBuffer = AllocZeroed(BATTLE_BUFFER_LINK_SIZE); + gLinkBattleRecvBuffer = AllocZeroed(BATTLE_BUFFER_LINK_SIZE); + + gUnknown_0202305C = AllocZeroed(0x2000); + gUnknown_02023060 = AllocZeroed(0x1000); + + if (gBattleTypeFlags & BATTLE_TYPE_SECRET_BASE) + { + u16 currSecretBaseId = VarGet(VAR_0x4054); + CreateSecretBaseEnemyParty(&gSaveBlock1Ptr->secretBases[currSecretBaseId]); + } +} + +void FreeBattleResources(void) +{ + if (gBattleTypeFlags & BATTLE_TYPE_x4000000) + sub_81D5694(); + + if (gBattleResources != NULL) + { + FREE_AND_SET_NULL(gBattleStruct); + + FREE_AND_SET_NULL(gBattleResources->secretBase); + FREE_AND_SET_NULL(gBattleResources->flags); + FREE_AND_SET_NULL(gBattleResources->battleScriptsStack); + FREE_AND_SET_NULL(gBattleResources->battleCallbackStack); + FREE_AND_SET_NULL(gBattleResources->statsBeforeLvlUp); + FREE_AND_SET_NULL(gBattleResources->ai); + FREE_AND_SET_NULL(gBattleResources->battleHistory); + FREE_AND_SET_NULL(gBattleResources->AI_ScriptsStack); + FREE_AND_SET_NULL(gBattleResources); + + FREE_AND_SET_NULL(gLinkBattleSendBuffer); + FREE_AND_SET_NULL(gLinkBattleRecvBuffer); + + FREE_AND_SET_NULL(gUnknown_0202305C); + FREE_AND_SET_NULL(gUnknown_02023060); + } +} + +void AdjustFriendshipOnBattleFaint(u8 bank) +{ + u8 opposingBank; + + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + { + u8 opposingBank2; + + opposingBank = GetBankByIdentity(IDENTITY_OPPONENT_MON1); + opposingBank2 = GetBankByIdentity(IDENTITY_OPPONENT_MON2); + + if (gBattleMons[opposingBank2].level > gBattleMons[opposingBank].level) + opposingBank = opposingBank2; + } + else + { + opposingBank = GetBankByIdentity(IDENTITY_OPPONENT_MON1); + } + + if (gBattleMons[opposingBank].level > gBattleMons[bank].level) + { + if (gBattleMons[opposingBank].level - gBattleMons[bank].level > 29) + AdjustFriendship(&gPlayerParty[gBattlePartyID[bank]], 8); + else + AdjustFriendship(&gPlayerParty[gBattlePartyID[bank]], 6); + } + else + { + AdjustFriendship(&gPlayerParty[gBattlePartyID[bank]], 6); + } +} + +void sub_80571DC(u8 bank, u8 arg1) +{ + if (GetBankSide(bank) != SIDE_OPPONENT) + { + s32 i; + + // gBattleStruct->field_60[0][i] + + for (i = 0; i < 3; i++) + gUnknown_0203CF00[i] = *(0 * 3 + i + (u8*)(gBattleStruct->field_60)); + + sub_81B8FB0(pokemon_order_func(gBattlePartyID[bank]), pokemon_order_func(arg1)); + + for (i = 0; i < 3; i++) + *(0 * 3 + i + (u8*)(gBattleStruct->field_60)) = gUnknown_0203CF00[i]; + } +} + +u32 sub_805725C(u8 bank) +{ + u32 effect = 0; + + do + { + switch (gBattleCommunication[MULTIUSE_STATE]) + { + case 0: + if (gBattleMons[bank].status1 & STATUS_SLEEP) + { + if (UproarWakeUpCheck(bank)) + { + gBattleMons[bank].status1 &= ~(STATUS_SLEEP); + gBattleMons[bank].status2 &= ~(STATUS2_NIGHTMARE); + BattleScriptPushCursor(); + gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattlescriptCurrInstr = BattleScript_MoveUsedWokeUp; + effect = 2; + } + else + { + u32 toSub; + + if (gBattleMons[bank].ability == ABILITY_EARLY_BIRD) + toSub = 2; + else + toSub = 1; + + if ((gBattleMons[bank].status1 & STATUS_SLEEP) < toSub) + gBattleMons[bank].status1 &= ~(STATUS_SLEEP); + else + gBattleMons[bank].status1 -= toSub; + + if (gBattleMons[bank].status1 & STATUS_SLEEP) + { + gBattlescriptCurrInstr = BattleScript_MoveUsedIsAsleep; + effect = 2; + } + else + { + gBattleMons[bank].status2 &= ~(STATUS2_NIGHTMARE); + BattleScriptPushCursor(); + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattlescriptCurrInstr = BattleScript_MoveUsedWokeUp; + effect = 2; + } + } + } + gBattleCommunication[MULTIUSE_STATE]++; + break; + case 1: + if (gBattleMons[bank].status1 & STATUS_FREEZE) + { + if (Random() % 5 != 0) + { + gBattlescriptCurrInstr = BattleScript_MoveUsedIsFrozen; + } + else + { + gBattleMons[bank].status1 &= ~(STATUS_FREEZE); + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_MoveUsedUnfroze; + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + } + effect = 2; + } + gBattleCommunication[MULTIUSE_STATE]++; + break; + case 2: + break; + } + + } while (gBattleCommunication[MULTIUSE_STATE] != 2 && effect == 0); + + if (effect == 2) + { + gActiveBank = bank; + EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBank].status1); + MarkBufferBankForExecution(gActiveBank); + } + + return effect; +}