AI_Basic: ; 38591 ; Don't do anything redundant: ; -Using status-only moves if the player can't be statused ; -Using moves that fail if they've already been used ld hl, Buffer1 - 1 ld de, EnemyMonMoves ld b, EnemyMonMovesEnd - EnemyMonMoves + 1 .checkmove dec b ret z inc hl ld a, [de] and a ret z inc de call AIGetEnemyMove ld a, [wEnemyMoveStruct + MOVE_EFFECT] ld c, a push hl push de push bc callba AI_Redundant pop bc pop de pop hl jr nz, .discourage ld a, [wEnemyMoveStruct + MOVE_EFFECT] push hl push de push bc ld hl, .statusonlyeffects ld de, 1 call IsInArray pop bc pop de pop hl jr nc, .checkmove ld a, [BattleMonStatus] and a jr nz, .discourage ld a, [PlayerScreens] bit SCREENS_SAFEGUARD, a jr z, .checkmove .discourage call AIDiscourageMove jr .checkmove ; 385db .statusonlyeffects db EFFECT_SLEEP db EFFECT_TOXIC db EFFECT_POISON db EFFECT_PARALYZE db $ff ; 385e0 AI_Setup: ; 385e0 ; Use stat-modifying moves on turn 1. ld hl, Buffer1 - 1 ld de, EnemyMonMoves ld b, EnemyMonMovesEnd - EnemyMonMoves + 1 .checkmove dec b ret z inc hl ld a, [de] and a ret z inc de call AIGetEnemyMove ld a, [wEnemyMoveStruct + MOVE_EFFECT] cp EFFECT_ATTACK_UP jr c, .checkmove cp EFFECT_EVASION_UP + 1 jr c, .statup ; cp EFFECT_ATTACK_DOWN - 1 jr z, .checkmove cp EFFECT_EVASION_DOWN + 1 jr c, .statdown cp EFFECT_ATTACK_UP_2 jr c, .checkmove cp EFFECT_EVASION_UP_2 + 1 jr c, .statup ; cp EFFECT_ATTACK_DOWN_2 - 1 jr z, .checkmove cp EFFECT_EVASION_DOWN_2 + 1 jr c, .statdown jr .checkmove .statup ld a, [EnemyTurnsTaken] and a jr nz, .discourage jr .encourage .statdown ld a, [PlayerTurnsTaken] and a jr nz, .discourage .encourage call AI_50_50 jr c, .checkmove dec [hl] dec [hl] jr .checkmove .discourage call Random cp 30 jr c, .checkmove inc [hl] inc [hl] jr .checkmove ; 38635 AI_Types: ; 38635 ; Use super-effective moves. ld hl, Buffer1 - 1 ld de, EnemyMonMoves ld b, EnemyMonMovesEnd - EnemyMonMoves + 1 .checkmove dec b ret z inc hl ld a, [de] and a ret z inc de call AIGetEnemyMove push hl push bc push de ld a, 1 ld [hBattleTurn], a callab Function347c8 pop de pop bc pop hl ld a, [$d265] and a jr z, .immune cp 10 ; 1.0 jr z, .checkmove jr c, .noteffective ; effective ld a, [wEnemyMoveStruct + MOVE_POWER] and a jr z, .checkmove dec [hl] jr .checkmove .noteffective ; Discourage this move if there are any moves ; that do damage of a different type. push hl push de push bc ld a, [wEnemyMoveStruct + MOVE_TYPE] ld d, a ld hl, EnemyMonMoves ld b, EnemyMonMovesEnd - EnemyMonMoves + 1 ld c, 0 .checkmove2 dec b jr z, .asm_38693 ld a, [hli] and a jr z, .asm_38693 call AIGetEnemyMove ld a, [wEnemyMoveStruct + MOVE_TYPE] cp d jr z, .checkmove2 ld a, [wEnemyMoveStruct + MOVE_POWER] and a jr nz, .asm_38692 jr .checkmove2 .asm_38692 ld c, a .asm_38693 ld a, c pop bc pop de pop hl and a jr z, .checkmove inc [hl] jr .checkmove .immune call AIDiscourageMove jr .checkmove ; 386a2 AI_Offensive: ; 386a2 ; Discourage non-damaging moves. ld hl, Buffer1 - 1 ld de, EnemyMonMoves ld b, EnemyMonMovesEnd - EnemyMonMoves + 1 .checkmove dec b ret z inc hl ld a, [de] and a ret z inc de call AIGetEnemyMove ld a, [wEnemyMoveStruct + MOVE_POWER] and a jr nz, .checkmove inc [hl] inc [hl] jr .checkmove ; 386be AI_Smart: ; 386be ; Context-specific scoring. ld hl, Buffer1 ld de, EnemyMonMoves ld b, EnemyMonMovesEnd - EnemyMonMoves + 1 .checkmove dec b ret z ld a, [de] inc de and a ret z push de push bc push hl call AIGetEnemyMove ld a, [wEnemyMoveStruct + MOVE_EFFECT] ld hl, .table_386f2 ld de, 3 call IsInArray inc hl jr nc, .nextmove ld a, [hli] ld e, a ld d, [hl] pop hl push hl ld bc, .nextmove push bc push de ret .nextmove pop hl pop bc pop de inc hl jr .checkmove .table_386f2 dbw EFFECT_SLEEP, AI_Smart_Sleep dbw EFFECT_LEECH_HIT, AI_Smart_LeechHit dbw EFFECT_EXPLOSION, AI_Smart_Explosion dbw EFFECT_DREAM_EATER, AI_Smart_DreamEater dbw EFFECT_MIRROR_MOVE, AI_Smart_MirrorMove dbw EFFECT_EVASION_UP, AI_Smart_EvasionUp dbw EFFECT_ALWAYS_HIT, AI_Smart_AlwaysHit dbw EFFECT_ACCURACY_DOWN, AI_Smart_AccuracyDown dbw EFFECT_HAZE, AI_Smart_Haze dbw EFFECT_BIDE, AI_Smart_Bide dbw EFFECT_WHIRLWIND, AI_Smart_Whirlwind dbw EFFECT_HEAL, AI_Smart_Heal dbw EFFECT_TOXIC, AI_Smart_Toxic dbw EFFECT_LIGHT_SCREEN, AI_Smart_LightScreen dbw EFFECT_OHKO, AI_Smart_Ohko dbw EFFECT_RAZOR_WIND, AI_Smart_RazorWind dbw EFFECT_SUPER_FANG, AI_Smart_SuperFang dbw EFFECT_BIND, AI_Smart_Bind dbw EFFECT_UNUSED_2B, AI_Smart_Unused2B dbw EFFECT_CONFUSE, AI_Smart_Confuse dbw EFFECT_SP_DEF_UP_2, AI_Smart_SpDefenseUp2 dbw EFFECT_REFLECT, AI_Smart_Reflect dbw EFFECT_PARALYZE, AI_Smart_Paralyze dbw EFFECT_SPEED_DOWN_HIT, AI_Smart_SpeedDownHit dbw EFFECT_SUBSTITUTE, AI_Smart_Substitute dbw EFFECT_HYPER_BEAM, AI_Smart_HyperBeam dbw EFFECT_RAGE, AI_Smart_Rage dbw EFFECT_MIMIC, AI_Smart_Mimic dbw EFFECT_LEECH_SEED, AI_Smart_LeechSeed dbw EFFECT_DISABLE, AI_Smart_Disable dbw EFFECT_COUNTER, AI_Smart_Counter dbw EFFECT_ENCORE, AI_Smart_Encore dbw EFFECT_PAIN_SPLIT, AI_Smart_PainSplit dbw EFFECT_SNORE, AI_Smart_Snore dbw EFFECT_CONVERSION2, AI_Smart_Conversion2 dbw EFFECT_LOCK_ON, AI_Smart_LockOn dbw EFFECT_DEFROST_OPPONENT, AI_Smart_DefrostOpponent dbw EFFECT_SLEEP_TALK, AI_Smart_SleepTalk dbw EFFECT_DESTINY_BOND, AI_Smart_DestinyBond dbw EFFECT_REVERSAL, AI_Smart_Reversal dbw EFFECT_SPITE, AI_Smart_Spite dbw EFFECT_HEAL_BELL, AI_Smart_HealBell dbw EFFECT_PRIORITY_HIT, AI_Smart_PriorityHit dbw EFFECT_THIEF, AI_Smart_Thief dbw EFFECT_MEAN_LOOK, AI_Smart_MeanLook dbw EFFECT_NIGHTMARE, AI_Smart_Nightmare dbw EFFECT_FLAME_WHEEL, AI_Smart_FlameWheel dbw EFFECT_CURSE, AI_Smart_Curse dbw EFFECT_PROTECT, AI_Smart_Protect dbw EFFECT_FORESIGHT, AI_Smart_Foresight dbw EFFECT_PERISH_SONG, AI_Smart_PerishSong dbw EFFECT_SANDSTORM, AI_Smart_Sandstorm dbw EFFECT_ENDURE, AI_Smart_Endure dbw EFFECT_ROLLOUT, AI_Smart_Rollout dbw EFFECT_SWAGGER, AI_Smart_Swagger dbw EFFECT_FURY_CUTTER, AI_Smart_FuryCutter dbw EFFECT_ATTRACT, AI_Smart_Attract dbw EFFECT_SAFEGUARD, AI_Smart_Safeguard dbw EFFECT_MAGNITUDE, AI_Smart_Magnitude dbw EFFECT_BATON_PASS, AI_Smart_BatonPass dbw EFFECT_PURSUIT, AI_Smart_Pursuit dbw EFFECT_RAPID_SPIN, AI_Smart_RapidSpin dbw EFFECT_MORNING_SUN, AI_Smart_MorningSun dbw EFFECT_SYNTHESIS, AI_Smart_Synthesis dbw EFFECT_MOONLIGHT, AI_Smart_Moonlight dbw EFFECT_HIDDEN_POWER, AI_Smart_HiddenPower dbw EFFECT_RAIN_DANCE, AI_Smart_RainDance dbw EFFECT_SUNNY_DAY, AI_Smart_SunnyDay dbw EFFECT_BELLY_DRUM, AI_Smart_BellyDrum dbw EFFECT_PSYCH_UP, AI_Smart_PsychUp dbw EFFECT_MIRROR_COAT, AI_Smart_MirrorCoat dbw EFFECT_SKULL_BASH, AI_Smart_SkullBash dbw EFFECT_TWISTER, AI_Smart_Twister dbw EFFECT_EARTHQUAKE, AI_Smart_Earthquake dbw EFFECT_FUTURE_SIGHT, AI_Smart_FutureSight dbw EFFECT_GUST, AI_Smart_Gust dbw EFFECT_STOMP, AI_Smart_Stomp dbw EFFECT_SOLARBEAM, AI_Smart_Solarbeam dbw EFFECT_THUNDER, AI_Smart_Thunder dbw EFFECT_FLY, AI_Smart_Fly db $ff ; 387e3 AI_Smart_Sleep: ; 387e3 ld b, EFFECT_DREAM_EATER call AIHasMoveEffect jr c, .asm_387f0 ld b, EFFECT_NIGHTMARE call AIHasMoveEffect ret nc .asm_387f0 call AI_50_50 ret c dec [hl] dec [hl] ret ; 387f7 AI_Smart_LeechHit: ; 387f7 push hl ld a, 1 ld [hBattleTurn], a callab Function347c8 pop hl ld a, [$d265] cp 10 ; 1.0 jr c, .asm_38815 ret z call AICheckEnemyMaxHP ret c call AI_80_20 ret c dec [hl] ret .asm_38815 call Random cp 100 ret c inc [hl] ret ; 3881d AI_Smart_LockOn: ; 3881d ld a, [PlayerSubStatus5] bit SUBSTATUS_LOCK_ON, a jr nz, .asm_38882 push hl call AICheckEnemyQuarterHP jr nc, .asm_38877 call AICheckEnemyHalfHP jr c, .asm_38834 call AICompareSpeed jr nc, .asm_38877 .asm_38834 ld a, [PlayerEvaLevel] cp $a jr nc, .asm_3887a cp $8 jr nc, .asm_38875 ld a, [EnemyAccLevel] cp $5 jr c, .asm_3887a cp $7 jr c, .asm_38875 ld hl, EnemyMonMoves ld c, EnemyMonMovesEnd - EnemyMonMoves + 1 .asm_3884f dec c jr z, .asm_38877 ld a, [hli] and a jr z, .asm_38877 call AIGetEnemyMove ld a, [wEnemyMoveStruct + MOVE_ACC] cp 180 jr nc, .asm_3884f ld a, $1 ld [hBattleTurn], a push hl push bc callba Function347c8 ld a, [$d265] cp $a pop bc pop hl jr c, .asm_3884f .asm_38875 pop hl ret .asm_38877 pop hl inc [hl] ret .asm_3887a pop hl call AI_50_50 ret c dec [hl] dec [hl] ret .asm_38882 push hl ld hl, Buffer1 - 1 ld de, EnemyMonMoves ld c, EnemyMonMovesEnd - EnemyMonMoves + 1 .asm_3888b inc hl dec c jr z, .asm_388a2 ld a, [de] and a jr z, .asm_388a2 inc de call AIGetEnemyMove ld a, [wEnemyMoveStruct + MOVE_ACC] cp 180 jr nc, .asm_3888b dec [hl] dec [hl] jr .asm_3888b .asm_388a2 pop hl jp AIDiscourageMove ; 388a6 AI_Smart_Explosion: ; 388a6 push hl callba CountEnemyAliveMons pop hl jr nc, .asm_388b7 push hl call AICheckLastPlayerMon pop hl jr nz, .asm_388c6 .asm_388b7 call AICheckEnemyHalfHP jr c, .asm_388c6 call AICheckEnemyQuarterHP ret nc call Random cp 20 ret c .asm_388c6 inc [hl] inc [hl] inc [hl] ret ; 388ca AI_Smart_DreamEater: ; 388ca call Random cp $19 ret c dec [hl] dec [hl] dec [hl] ret ; 388d4 AI_Smart_EvasionUp: ; 388d4 ld a, [EnemyEvaLevel] cp $d jp nc, AIDiscourageMove call AICheckEnemyMaxHP jr nc, .asm_388f2 ld a, [PlayerSubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_388ef call Random cp $b2 jr nc, .asm_38911 .asm_388ef dec [hl] dec [hl] ret .asm_388f2 call AICheckEnemyQuarterHP jr nc, .asm_3890f call Random cp $a jr c, .asm_388ef call AICheckEnemyHalfHP jr nc, .asm_3890a call AI_80_20 jr c, .asm_388ef jr .asm_38911 .asm_3890a call AI_50_50 jr c, .asm_38911 .asm_3890f inc [hl] inc [hl] .asm_38911 ld a, [PlayerSubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_38938 ld a, [PlayerSubStatus4] bit SUBSTATUS_LEECH_SEED, a jr nz, .asm_38941 ld a, [EnemyEvaLevel] ld b, a ld a, [PlayerAccLevel] cp b jr c, .asm_38936 ld a, [PlayerFuryCutterCount] and a jr nz, .asm_388ef ld a, [PlayerSubStatus1] bit SUBSTATUS_ROLLOUT, a jr nz, .asm_388ef .asm_38936 inc [hl] ret .asm_38938 call Random cp $50 ret c dec [hl] dec [hl] ret .asm_38941 call AI_50_50 ret c dec [hl] ret ; 38947 AI_Smart_AlwaysHit: ; 38947 ld a, [EnemyAccLevel] cp $5 jr c, .asm_38954 ld a, [PlayerEvaLevel] cp $a ret c .asm_38954 call AI_80_20 ret c dec [hl] dec [hl] ret ; 3895b AI_Smart_MirrorMove: ; 3895b ld a, [LastEnemyCounterMove] and a jr nz, .asm_38968 call AICompareSpeed ret nc jp AIDiscourageMove .asm_38968 push hl ld hl, GoodMoves ld de, 1 call IsInArray pop hl ret nc call AI_50_50 ret c dec [hl] call AICompareSpeed ret nc call Random cp $19 ret c dec [hl] ret ; 38985 AI_Smart_AccuracyDown: ; 38985 call AICheckPlayerMaxHP jr nc, .asm_389a0 call AICheckEnemyHalfHP jr nc, .asm_389a0 ld a, [PlayerSubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_3899d call Random cp $b2 jr nc, .asm_389bf .asm_3899d dec [hl] dec [hl] ret .asm_389a0 call AICheckPlayerQuarterHP jr nc, .asm_389bd call Random cp $a jr c, .asm_3899d call AICheckPlayerHalfHP jr nc, .asm_389b8 call AI_80_20 jr c, .asm_3899d jr .asm_389bf .asm_389b8 call AI_50_50 jr c, .asm_389bf .asm_389bd inc [hl] inc [hl] .asm_389bf ld a, [PlayerSubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_389e6 ld a, [PlayerSubStatus4] bit SUBSTATUS_LEECH_SEED, a jr nz, .asm_389ef ld a, [EnemyEvaLevel] ld b, a ld a, [PlayerAccLevel] cp b jr c, .asm_389e4 ld a, [PlayerFuryCutterCount] and a jr nz, .asm_3899d ld a, [PlayerSubStatus1] bit SUBSTATUS_ROLLOUT, a jr nz, .asm_3899d .asm_389e4 inc [hl] ret .asm_389e6 call Random cp $50 ret c dec [hl] dec [hl] ret .asm_389ef call AI_50_50 ret c dec [hl] ret ; 389f5 AI_Smart_Haze: ; 389f5 push hl ld hl, EnemyAtkLevel ld c, $8 .asm_389fb dec c jr z, .asm_38a05 ld a, [hli] cp $5 jr c, .asm_38a12 jr .asm_389fb .asm_38a05 ld hl, PlayerAtkLevel ld c, $8 .asm_38a0a dec c jr z, .asm_38a1b ld a, [hli] cp $a jr c, .asm_38a0a .asm_38a12 pop hl call Random cp $28 ret c dec [hl] ret .asm_38a1b pop hl inc [hl] ret ; 38a1e AI_Smart_Bide: ; 38a1e call AICheckEnemyMaxHP ret c call Random cp $19 ret c inc [hl] ret ; 38a2a AI_Smart_Whirlwind: ; 38a2a push hl callab Function3484e ld a, [$c716] cp $a pop hl ret c inc [hl] ret ; 38a3a AI_Smart_Heal: AI_Smart_MorningSun: AI_Smart_Synthesis: AI_Smart_Moonlight: ; 38a3a call AICheckEnemyQuarterHP jr nc, .asm_38a45 call AICheckEnemyHalfHP ret nc inc [hl] ret .asm_38a45 call Random cp $19 ret c dec [hl] dec [hl] ret ; 38a4e AI_Smart_Toxic: AI_Smart_LeechSeed: ; 38a4e call AICheckPlayerHalfHP ret c inc [hl] ret ; 38a54 AI_Smart_LightScreen: AI_Smart_Reflect: ; 38a54 call AICheckEnemyMaxHP ret c call Random cp $14 ret c inc [hl] ret ; 38a60 AI_Smart_Ohko: ; 38a60 ld a, [BattleMonLevel] ld b, a ld a, [EnemyMonLevel] cp b jp c, AIDiscourageMove call AICheckPlayerHalfHP ret c inc [hl] ret ; 38a71 AI_Smart_Bind: ; 38a71 ld a, [$c730] and a jr nz, .asm_38a8b ld a, [PlayerSubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_38a91 ld a, [PlayerSubStatus1] and 1<