mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-11-16 11:37:40 +01:00
battle9 is being worked on
This commit is contained in:
parent
8914645231
commit
57e5624e06
1487
asm/battle_9.s
1487
asm/battle_9.s
File diff suppressed because it is too large
Load Diff
@ -5243,7 +5243,7 @@ sub_8061FB8: @ 8061FB8
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
_08061FD6:
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
_08061FDA:
|
||||
bl OpponentBufferExecCompleted
|
||||
b _08062156
|
||||
@ -5347,7 +5347,7 @@ _0806209C:
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
adds r2, r4, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
b _08061FDA
|
||||
.pool
|
||||
_080620C4:
|
||||
@ -5378,7 +5378,7 @@ _080620C6:
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
adds r2, r4, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
b _08062152
|
||||
.pool
|
||||
_08062108:
|
||||
@ -5401,7 +5401,7 @@ _08062108:
|
||||
orrs r2, r4
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
b _08062152
|
||||
.pool
|
||||
_0806213C:
|
||||
@ -5413,7 +5413,7 @@ _0806213C:
|
||||
orrs r2, r4
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
_08062152:
|
||||
bl OpponentBufferExecCompleted
|
||||
_08062156:
|
||||
|
@ -226,7 +226,7 @@ _0805764C:
|
||||
movs r0, 0x1
|
||||
movs r1, 0x3
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
b _080577C2
|
||||
_08057658:
|
||||
movs r0, 0x20
|
||||
@ -393,7 +393,7 @@ _080577B2:
|
||||
movs r1, 0xC
|
||||
_080577BC:
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
_080577C2:
|
||||
bl PlayerBufferExecCompleted
|
||||
b _080577E8
|
||||
@ -518,7 +518,7 @@ _080578A0:
|
||||
orrs r2, r0
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
ldrb r0, [r4]
|
||||
movs r1, 0x1
|
||||
bl dp11b_obj_free
|
||||
@ -1086,7 +1086,7 @@ _08057E14:
|
||||
_08057E1C:
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl PlayerBufferExecCompleted
|
||||
b _08057F9E
|
||||
.pool
|
||||
@ -3413,7 +3413,7 @@ _080591FE:
|
||||
lsrs r2, 16
|
||||
movs r0, 0x1
|
||||
movs r1, 0xB
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
strb r5, [r4]
|
||||
bl battle_type_is_double
|
||||
lsls r0, 24
|
||||
@ -3686,7 +3686,7 @@ _08059430:
|
||||
lsrs r2, 16
|
||||
movs r0, 0x1
|
||||
movs r1, 0xB
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
strb r5, [r4]
|
||||
ldr r0, =sub_8059544
|
||||
str r0, [r6]
|
||||
@ -4291,14 +4291,14 @@ _08059A2C:
|
||||
movs r0, 0x1
|
||||
movs r1, 0xE
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
b _08059A76
|
||||
.pool
|
||||
_08059A6C:
|
||||
movs r0, 0x1
|
||||
movs r1, 0xD
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
_08059A76:
|
||||
bl PlayerBufferExecCompleted
|
||||
_08059A7A:
|
||||
@ -8658,7 +8658,7 @@ sub_805C158: @ 805C158
|
||||
lsrs r2, 16
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl PlayerBufferExecCompleted
|
||||
_0805C194:
|
||||
pop {r0}
|
||||
@ -9378,7 +9378,7 @@ sub_805C80C: @ 805C80C
|
||||
movs r0, 0x1
|
||||
movs r1, 0
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl PlayerBufferExecCompleted
|
||||
pop {r0}
|
||||
bx r0
|
||||
|
@ -645,7 +645,7 @@ _081BB2E2:
|
||||
lsrs r2, 16
|
||||
movs r0, 0x1
|
||||
movs r1, 0xB
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
strb r5, [r4]
|
||||
bl battle_type_is_double
|
||||
lsls r0, 24
|
||||
@ -918,7 +918,7 @@ _081BB514:
|
||||
lsrs r2, 16
|
||||
movs r0, 0x1
|
||||
movs r1, 0xB
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
strb r5, [r4]
|
||||
ldr r0, =sub_81BB628
|
||||
str r0, [r6]
|
||||
@ -5068,7 +5068,7 @@ _081BDB3C:
|
||||
orrs r2, r5
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl PlayerPartnerBufferExecCompleted
|
||||
pop {r4-r6}
|
||||
pop {r0}
|
||||
|
@ -4754,7 +4754,7 @@ sub_8188EF0: @ 8188EF0
|
||||
lsrs r1, 24
|
||||
movs r0, 0x1
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl RecordedOpponentBufferExecCompleted
|
||||
pop {r0}
|
||||
bx r0
|
||||
@ -4785,7 +4785,7 @@ sub_8188F20: @ 8188F20
|
||||
lsrs r2, 16
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
b _08188F6C
|
||||
.pool
|
||||
_08188F48:
|
||||
@ -4803,7 +4803,7 @@ _08188F48:
|
||||
orrs r2, r4
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
_08188F6C:
|
||||
bl RecordedOpponentBufferExecCompleted
|
||||
pop {r4,r5}
|
||||
|
@ -4861,7 +4861,7 @@ sub_818C49C: @ 818C49C
|
||||
lsrs r1, 24
|
||||
movs r0, 0x1
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl RecordedPlayerBufferExecCompleted
|
||||
_0818C4C6:
|
||||
pop {r0}
|
||||
@ -4897,7 +4897,7 @@ _0818C508:
|
||||
lsrs r1, 24
|
||||
movs r0, 0x1
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl RecordedPlayerBufferExecCompleted
|
||||
_0818C522:
|
||||
pop {r0}
|
||||
@ -4929,7 +4929,7 @@ sub_818C538: @ 818C538
|
||||
lsrs r2, 16
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
b _0818C584
|
||||
.pool
|
||||
_0818C560:
|
||||
@ -4947,7 +4947,7 @@ _0818C560:
|
||||
orrs r2, r4
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
_0818C584:
|
||||
bl RecordedPlayerBufferExecCompleted
|
||||
pop {r4,r5}
|
||||
|
@ -103,13 +103,13 @@ _0815942A:
|
||||
movs r1, 0x7
|
||||
_0815942E:
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
b _08159440
|
||||
_08159436:
|
||||
movs r0, 0x1
|
||||
movs r1, 0x8
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
_08159440:
|
||||
bl SafariBufferExecCompleted
|
||||
b _0815954E
|
||||
|
@ -153,7 +153,7 @@ _081684CE:
|
||||
movs r1, 0x9
|
||||
_081684E4:
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl WallyBufferExecCompleted
|
||||
ldr r1, [r4]
|
||||
adds r1, 0x94
|
||||
@ -208,7 +208,7 @@ _08168540:
|
||||
movs r0, 0x1
|
||||
movs r1, 0x1
|
||||
movs r2, 0
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl WallyBufferExecCompleted
|
||||
_08168564:
|
||||
pop {r4,r5}
|
||||
@ -3777,7 +3777,7 @@ _0816A550:
|
||||
lsls r2, 1
|
||||
movs r0, 0x1
|
||||
movs r1, 0xA
|
||||
bl dp01_build_cmdbuf_x21_a_bb
|
||||
bl EmitCmd_x21
|
||||
bl WallyBufferExecCompleted
|
||||
_0816A574:
|
||||
pop {r4}
|
||||
|
@ -3259,8 +3259,8 @@ _0803413E:
|
||||
.pool
|
||||
thumb_func_end sub_8034110
|
||||
|
||||
thumb_func_start dp01_build_cmdbuf_x21_a_bb
|
||||
dp01_build_cmdbuf_x21_a_bb: @ 8034158
|
||||
thumb_func_start EmitCmd_x21
|
||||
EmitCmd_x21: @ 8034158
|
||||
push {r4,lr}
|
||||
adds r4, r1, 0
|
||||
lsls r0, 24
|
||||
@ -3280,7 +3280,7 @@ dp01_build_cmdbuf_x21_a_bb: @ 8034158
|
||||
pop {r0}
|
||||
bx r0
|
||||
.pool
|
||||
thumb_func_end dp01_build_cmdbuf_x21_a_bb
|
||||
thumb_func_end EmitCmd_x21
|
||||
|
||||
thumb_func_start dp01_build_cmdbuf_x22_a_three_bytes
|
||||
dp01_build_cmdbuf_x22_a_three_bytes: @ 8034184
|
||||
|
@ -84,5 +84,6 @@ void Emit_x32(u8 bufferId);
|
||||
void EmitPrintString(u8 bufferId, u16 stringId);
|
||||
void EmitResetActionMoveSelection(u8 bufferId, u8 caseId);
|
||||
void EmitBallThrow(u8 bufferId, u8 caseId);
|
||||
void EmitCmd_x21(u8 bufferId, u8 arg1, u16 arg2);
|
||||
|
||||
#endif // GUARD_BATTLE_CONTROLLERS_H
|
||||
|
@ -43,7 +43,7 @@
|
||||
|
||||
void AI_CalcDmg(u8 bankAtk, u8 bankDef);
|
||||
u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef);
|
||||
u8 AI_TypeCalc(u16 move, u16 species, u8 ability);
|
||||
u8 AI_TypeCalc(u16 move, u16 targetSpecies, u8 targetAbility);
|
||||
u8 BankGetTurnOrder(u8 bank);
|
||||
void SetMoveEffect(bool8 primary, u8 certain);
|
||||
void BattleDestroyCursorAt(u8 cursorPosition);
|
||||
|
@ -64,6 +64,7 @@ SECTIONS {
|
||||
asm/battle_controller_player.o(.text);
|
||||
asm/battle_7.o(.text);
|
||||
asm/battle_controller_opponent.o(.text);
|
||||
src/battle_9.o(.text);
|
||||
asm/battle_9.o(.text);
|
||||
asm/battle_controller_linkopponent.o(.text);
|
||||
src/pokemon_1.o(.text);
|
||||
|
525
src/battle_9.c
Normal file
525
src/battle_9.c
Normal file
@ -0,0 +1,525 @@
|
||||
#include "global.h"
|
||||
#include "battle.h"
|
||||
#include "battle_controllers.h"
|
||||
#include "abilities.h"
|
||||
#include "moves.h"
|
||||
#include "pokemon.h"
|
||||
#include "species.h"
|
||||
#include "rng.h"
|
||||
#include "util.h"
|
||||
|
||||
extern u8 gActiveBank;
|
||||
extern u8 gAbsentBankFlags;
|
||||
extern u32 gBattleTypeFlags;
|
||||
extern u32 gStatuses3[BATTLE_BANKS_COUNT];
|
||||
extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT];
|
||||
extern u16 gBattlePartyID[BATTLE_BANKS_COUNT];
|
||||
extern u16 gUnknown_02024250[BATTLE_BANKS_COUNT];
|
||||
extern u8 gUnknown_02024270[BATTLE_BANKS_COUNT];
|
||||
|
||||
extern const struct BattleMove gBattleMoves[];
|
||||
extern const struct BaseStats gBaseStats[];
|
||||
|
||||
// this file's functions
|
||||
bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng);
|
||||
bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent);
|
||||
|
||||
bool8 ShouldSwitchIfPerishSong(void)
|
||||
{
|
||||
if (gStatuses3[gActiveBank] & STATUS3_PERISH_SONG
|
||||
&& gDisableStructs[gActiveBank].perishSong1 == 0)
|
||||
{
|
||||
*(gBattleStruct->field_294 + gActiveBank) = 6;
|
||||
EmitCmd_x21(1, 2, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool8 ShouldSwitchIfWonderGuard(void)
|
||||
{
|
||||
u8 opposingIdentity;
|
||||
u8 opposingBank;
|
||||
u8 moveFlags;
|
||||
s32 i, j;
|
||||
s32 firstId;
|
||||
s32 lastId; // + 1
|
||||
struct Pokemon *party = NULL;
|
||||
u16 move;
|
||||
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||
return FALSE;
|
||||
|
||||
opposingIdentity = GetBankIdentity(gActiveBank) ^ BIT_SIDE;
|
||||
|
||||
if (gBattleMons[GetBankByIdentity(opposingIdentity)].ability != ABILITY_WONDER_GUARD)
|
||||
return FALSE;
|
||||
|
||||
// check if pokemon has a super effective move
|
||||
for (opposingBank = GetBankByIdentity(opposingIdentity), i = 0; i < 4; i++)
|
||||
{
|
||||
move = gBattleMons[gActiveBank].moves[i];
|
||||
if (move == MOVE_NONE)
|
||||
continue;
|
||||
|
||||
moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability);
|
||||
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// get party information
|
||||
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||
{
|
||||
if ((gActiveBank & BIT_MON) == 0)
|
||||
firstId = 0, lastId = 3;
|
||||
else
|
||||
firstId = 3, lastId = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstId = 0, lastId = 6;
|
||||
}
|
||||
|
||||
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||
party = gPlayerParty;
|
||||
else
|
||||
party = gEnemyParty;
|
||||
|
||||
// find a pokemon in the party that has a super effective move
|
||||
for (i = firstId; i < lastId; i++)
|
||||
{
|
||||
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||
continue;
|
||||
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE)
|
||||
continue;
|
||||
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
|
||||
continue;
|
||||
if (i == gBattlePartyID[gActiveBank])
|
||||
continue;
|
||||
|
||||
GetMonData(&party[i], MON_DATA_SPECIES); // unused return value
|
||||
GetMonData(&party[i], MON_DATA_ALT_ABILITY); // unused return value
|
||||
|
||||
for (opposingBank = GetBankByIdentity(opposingIdentity), j = 0; j < 4; j++)
|
||||
{
|
||||
move = GetMonData(&party[i], MON_DATA_MOVE1 + j);
|
||||
if (move == MOVE_NONE)
|
||||
continue;
|
||||
|
||||
moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability);
|
||||
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE && Random() % 3 < 2)
|
||||
{
|
||||
// we found a mon
|
||||
*(gBattleStruct->field_294 + gActiveBank) = i;
|
||||
EmitCmd_x21(1, 2, 0);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE; // at this point there is not a single pokemon in the party that has a super effective move against a pokemon with wonder guard
|
||||
}
|
||||
|
||||
bool8 sub_8062E54(void)
|
||||
{
|
||||
u8 bankIn1, bankIn2;
|
||||
u8 absorbingTypeAbility;
|
||||
s32 firstId;
|
||||
s32 lastId; // + 1
|
||||
struct Pokemon *party;
|
||||
s32 i;
|
||||
|
||||
if (HasSuperEffectiveMoveAgainstOpponents(TRUE) && Random() % 3 != 0)
|
||||
return FALSE;
|
||||
if (gUnknown_02024250[gActiveBank] == 0)
|
||||
return FALSE;
|
||||
if (gUnknown_02024250[gActiveBank] == 0xFFFF)
|
||||
return FALSE;
|
||||
if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0)
|
||||
return FALSE;
|
||||
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||
{
|
||||
bankIn1 = gActiveBank;
|
||||
if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)])
|
||||
bankIn2 = gActiveBank;
|
||||
else
|
||||
bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON);
|
||||
}
|
||||
else
|
||||
{
|
||||
bankIn1 = gActiveBank;
|
||||
bankIn2 = gActiveBank;
|
||||
}
|
||||
|
||||
if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_FIRE)
|
||||
absorbingTypeAbility = ABILITY_FLASH_FIRE;
|
||||
else if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_WATER)
|
||||
absorbingTypeAbility = ABILITY_WATER_ABSORB;
|
||||
else if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_ELECTRIC)
|
||||
absorbingTypeAbility = ABILITY_VOLT_ABSORB;
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
if (gBattleMons[gActiveBank].ability == absorbingTypeAbility)
|
||||
return FALSE;
|
||||
|
||||
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||
{
|
||||
if ((gActiveBank & BIT_MON) == 0)
|
||||
firstId = 0, lastId = 3;
|
||||
else
|
||||
firstId = 3, lastId = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstId = 0, lastId = 6;
|
||||
}
|
||||
|
||||
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||
party = gPlayerParty;
|
||||
else
|
||||
party = gEnemyParty;
|
||||
|
||||
for (i = firstId; i < lastId; i++)
|
||||
{
|
||||
u16 species;
|
||||
u8 monAbility;
|
||||
|
||||
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||
continue;
|
||||
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE)
|
||||
continue;
|
||||
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
|
||||
continue;
|
||||
if (i == gBattlePartyID[bankIn1])
|
||||
continue;
|
||||
if (i == gBattlePartyID[bankIn2])
|
||||
continue;
|
||||
if (i == *(gBattleStruct->field_5C + bankIn1))
|
||||
continue;
|
||||
if (i == *(gBattleStruct->field_5C + bankIn2))
|
||||
continue;
|
||||
|
||||
species = GetMonData(&party[i], MON_DATA_SPECIES);
|
||||
if (GetMonData(&party[i], MON_DATA_ALT_ABILITY) != 0)
|
||||
monAbility = gBaseStats[species].ability2;
|
||||
else
|
||||
monAbility = gBaseStats[species].ability1;
|
||||
|
||||
if (absorbingTypeAbility == monAbility && Random() & 1)
|
||||
{
|
||||
// we found a mon
|
||||
*(gBattleStruct->field_294 + gActiveBank) = i;
|
||||
EmitCmd_x21(1, 2, 0);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool8 ShouldSwitchIfNaturalCure(void)
|
||||
{
|
||||
if (!(gBattleMons[gActiveBank].status1 & STATUS_SLEEP))
|
||||
return FALSE;
|
||||
if (gBattleMons[gActiveBank].ability != ABILITY_NATURAL_CURE)
|
||||
return FALSE;
|
||||
if (gBattleMons[gActiveBank].hp < gBattleMons[gActiveBank].maxHP / 2)
|
||||
return FALSE;
|
||||
|
||||
if ((gUnknown_02024250[gActiveBank] == 0 || gUnknown_02024250[gActiveBank] == 0xFFFF) && Random() & 1)
|
||||
{
|
||||
*(gBattleStruct->field_294 + gActiveBank) = 6;
|
||||
EmitCmd_x21(1, 2, 0);
|
||||
return TRUE;
|
||||
}
|
||||
else if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0 && Random() & 1)
|
||||
{
|
||||
*(gBattleStruct->field_294 + gActiveBank) = 6;
|
||||
EmitCmd_x21(1, 2, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTAFFECTED, 1))
|
||||
return TRUE;
|
||||
if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTVERYEFFECTIVE, 1))
|
||||
return TRUE;
|
||||
if (Random() & 1)
|
||||
{
|
||||
*(gBattleStruct->field_294 + gActiveBank) = 6;
|
||||
EmitCmd_x21(1, 2, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng)
|
||||
{
|
||||
u8 opposingIdentity;
|
||||
u8 opposingBank;
|
||||
s32 i;
|
||||
u8 moveFlags;
|
||||
u16 move;
|
||||
|
||||
opposingIdentity = GetBankIdentity(gActiveBank) ^ BIT_SIDE;
|
||||
opposingBank = GetBankByIdentity(opposingIdentity);
|
||||
|
||||
if (!(gAbsentBankFlags & gBitTable[opposingBank]))
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
move = gBattleMons[gActiveBank].moves[i];
|
||||
if (move == MOVE_NONE)
|
||||
continue;
|
||||
|
||||
moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability);
|
||||
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE)
|
||||
{
|
||||
if (noRng)
|
||||
return TRUE;
|
||||
if (Random() % 10 != 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
|
||||
return FALSE;
|
||||
|
||||
opposingBank = GetBankByIdentity(opposingIdentity ^ BIT_MON);
|
||||
|
||||
if (!(gAbsentBankFlags & gBitTable[opposingBank]))
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
move = gBattleMons[gActiveBank].moves[i];
|
||||
if (move == MOVE_NONE)
|
||||
continue;
|
||||
|
||||
moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability);
|
||||
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE)
|
||||
{
|
||||
if (noRng)
|
||||
return TRUE;
|
||||
if (Random() % 10 != 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool8 AreStatsRaised(void)
|
||||
{
|
||||
u8 buffedStatsValue = 0;
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < BATTLE_STATS_NO; i++)
|
||||
{
|
||||
if (gBattleMons[gActiveBank].statStages[i] > 6)
|
||||
buffedStatsValue += gBattleMons[gActiveBank].statStages[i] - 6;
|
||||
}
|
||||
|
||||
return (buffedStatsValue > 3);
|
||||
}
|
||||
|
||||
bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent)
|
||||
{
|
||||
u8 bankIn1, bankIn2;
|
||||
s32 firstId;
|
||||
s32 lastId; // + 1
|
||||
struct Pokemon *party;
|
||||
s32 i, j;
|
||||
u16 move;
|
||||
u8 moveFlags;
|
||||
|
||||
if (gUnknown_02024250[gActiveBank] == 0)
|
||||
return FALSE;
|
||||
if (gUnknown_02024250[gActiveBank] == 0xFFFF)
|
||||
return FALSE;
|
||||
if (gUnknown_02024270[gActiveBank] == 0xFF)
|
||||
return FALSE;
|
||||
if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0)
|
||||
return FALSE;
|
||||
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||
{
|
||||
bankIn1 = gActiveBank;
|
||||
if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)])
|
||||
bankIn2 = gActiveBank;
|
||||
else
|
||||
bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON);
|
||||
}
|
||||
else
|
||||
{
|
||||
bankIn1 = gActiveBank;
|
||||
bankIn2 = gActiveBank;
|
||||
}
|
||||
|
||||
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||
{
|
||||
if ((gActiveBank & BIT_MON) == 0)
|
||||
firstId = 0, lastId = 3;
|
||||
else
|
||||
firstId = 3, lastId = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstId = 0, lastId = 6;
|
||||
}
|
||||
|
||||
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||
party = gPlayerParty;
|
||||
else
|
||||
party = gEnemyParty;
|
||||
|
||||
for (i = firstId; i < lastId; i++)
|
||||
{
|
||||
u16 species;
|
||||
u8 monAbility;
|
||||
|
||||
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||
continue;
|
||||
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE)
|
||||
continue;
|
||||
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
|
||||
continue;
|
||||
if (i == gBattlePartyID[bankIn1])
|
||||
continue;
|
||||
if (i == gBattlePartyID[bankIn2])
|
||||
continue;
|
||||
if (i == *(gBattleStruct->field_5C + bankIn1))
|
||||
continue;
|
||||
if (i == *(gBattleStruct->field_5C + bankIn2))
|
||||
continue;
|
||||
|
||||
species = GetMonData(&party[i], MON_DATA_SPECIES);
|
||||
if (GetMonData(&party[i], MON_DATA_ALT_ABILITY) != 0)
|
||||
monAbility = gBaseStats[species].ability2;
|
||||
else
|
||||
monAbility = gBaseStats[species].ability1;
|
||||
|
||||
moveFlags = AI_TypeCalc(gUnknown_02024250[gActiveBank], species, monAbility);
|
||||
if (moveFlags & flags)
|
||||
{
|
||||
bankIn1 = gUnknown_02024270[gActiveBank];
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
move = GetMonData(&party[i], MON_DATA_MOVE1 + j);
|
||||
if (move == 0)
|
||||
continue;
|
||||
|
||||
moveFlags = AI_TypeCalc(move, gBattleMons[bankIn1].species, gBattleMons[bankIn1].ability);
|
||||
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE && Random() % moduloPercent == 0)
|
||||
{
|
||||
*(gBattleStruct->field_294 + gActiveBank) = i;
|
||||
EmitCmd_x21(1, 2, 0);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool8 ShouldSwitch(void)
|
||||
{
|
||||
u8 bankIn1, bankIn2;
|
||||
s32 firstId;
|
||||
s32 lastId; // + 1
|
||||
struct Pokemon *party;
|
||||
s32 i;
|
||||
s32 availableToSwitch;
|
||||
|
||||
if (gBattleMons[gActiveBank].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION))
|
||||
return FALSE;
|
||||
if (gStatuses3[gActiveBank] & STATUS3_ROOTED)
|
||||
return FALSE;
|
||||
if (AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, gActiveBank, ABILITY_SHADOW_TAG, 0, 0))
|
||||
return FALSE;
|
||||
if (AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, gActiveBank, ABILITY_ARENA_TRAP, 0, 0))
|
||||
return FALSE; // misses the flying or levitate check
|
||||
if (AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, gActiveBank, ABILITY_MAGNET_PULL, 0, 0)
|
||||
&& (gBattleMons[gActiveBank].type1 == TYPE_STEEL || gBattleMons[gActiveBank].type2 == TYPE_STEEL))
|
||||
return FALSE;
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_ARENA)
|
||||
return FALSE;
|
||||
|
||||
availableToSwitch = 0;
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||
{
|
||||
bankIn1 = gActiveBank;
|
||||
if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)])
|
||||
bankIn2 = gActiveBank;
|
||||
else
|
||||
bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON);
|
||||
}
|
||||
else
|
||||
{
|
||||
bankIn1 = gActiveBank;
|
||||
bankIn2 = gActiveBank;
|
||||
}
|
||||
|
||||
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||
{
|
||||
if ((gActiveBank & BIT_MON) == 0)
|
||||
firstId = 0, lastId = 3;
|
||||
else
|
||||
firstId = 3, lastId = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstId = 0, lastId = 6;
|
||||
}
|
||||
|
||||
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||
party = gPlayerParty;
|
||||
else
|
||||
party = gEnemyParty;
|
||||
|
||||
for (i = firstId; i < lastId; i++)
|
||||
{
|
||||
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||
continue;
|
||||
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE)
|
||||
continue;
|
||||
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
|
||||
continue;
|
||||
if (i == gBattlePartyID[bankIn1])
|
||||
continue;
|
||||
if (i == gBattlePartyID[bankIn2])
|
||||
continue;
|
||||
if (i == *(gBattleStruct->field_5C + bankIn1))
|
||||
continue;
|
||||
if (i == *(gBattleStruct->field_5C + bankIn2))
|
||||
continue;
|
||||
|
||||
availableToSwitch++;
|
||||
}
|
||||
|
||||
if (availableToSwitch == 0)
|
||||
return FALSE;
|
||||
if (ShouldSwitchIfPerishSong())
|
||||
return TRUE;
|
||||
if (ShouldSwitchIfWonderGuard())
|
||||
return TRUE;
|
||||
if (sub_8062E54())
|
||||
return TRUE;
|
||||
if (ShouldSwitchIfNaturalCure())
|
||||
return TRUE;
|
||||
if (HasSuperEffectiveMoveAgainstOpponents(FALSE))
|
||||
return FALSE;
|
||||
if (AreStatsRaised())
|
||||
return FALSE;
|
||||
if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTAFFECTED, 2))
|
||||
return TRUE;
|
||||
if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTVERYEFFECTIVE, 3))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
@ -1772,11 +1772,11 @@ u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef)
|
||||
return flags;
|
||||
}
|
||||
|
||||
u8 AI_TypeCalc(u16 move, u16 species, u8 ability)
|
||||
u8 AI_TypeCalc(u16 move, u16 targetSpecies, u8 targetAbility)
|
||||
{
|
||||
s32 i = 0;
|
||||
u8 flags = 0;
|
||||
u8 type1 = gBaseStats[species].type1, type2 = gBaseStats[species].type2;
|
||||
u8 type1 = gBaseStats[targetSpecies].type1, type2 = gBaseStats[targetSpecies].type2;
|
||||
u8 moveType;
|
||||
|
||||
if (move == MOVE_STRUGGLE)
|
||||
@ -1784,7 +1784,7 @@ u8 AI_TypeCalc(u16 move, u16 species, u8 ability)
|
||||
|
||||
moveType = gBattleMoves[move].type;
|
||||
|
||||
if (ability == ABILITY_LEVITATE && moveType == TYPE_GROUND)
|
||||
if (targetAbility == ABILITY_LEVITATE && moveType == TYPE_GROUND)
|
||||
{
|
||||
flags = MOVESTATUS_MISSED | MOVESTATUS_NOTAFFECTED;
|
||||
}
|
||||
@ -1809,7 +1809,7 @@ u8 AI_TypeCalc(u16 move, u16 species, u8 ability)
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
if (ability == ABILITY_WONDER_GUARD
|
||||
if (targetAbility == ABILITY_WONDER_GUARD
|
||||
&& (!(flags & MOVESTATUS_SUPEREFFECTIVE) || ((flags & (MOVESTATUS_SUPEREFFECTIVE | MOVESTATUS_NOTVERYEFFECTIVE)) == (MOVESTATUS_SUPEREFFECTIVE | MOVESTATUS_NOTVERYEFFECTIVE)))
|
||||
&& gBattleMoves[move].power)
|
||||
flags |= MOVESTATUS_NOTAFFECTED;
|
||||
|
Loading…
Reference in New Issue
Block a user