AIScoring_RedStatus: ; 38591 ; Handle the AI of status-only moves and moves with special effects. 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 ; Dismiss moves with special effects if they are ; useless or not a good choice right now. ; For example, healing moves, weather moves, Dream Eater... push hl push de push bc callba AISpecialEffects pop bc pop de pop hl jr nz, .discourage ; Dismiss status-only moves if the player can't be statused. 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 ; Dismiss Safeguard if it's already active. 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 AIScoring_RedStatMods: ; 385e0 ; 50% chance to greatly encourage stat-up moves during enemy's first turn. ; 50% chance to greatly encourage stat-down moves during player's first turn. ; Almost 90% chance to greatly discourage stat-modifying moves otherwise. 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 ; ignore EFFECT_ALWAYS_HIT 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 ; ignore EFFECT_TRANSFROM 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 Function39527 jr c, .checkmove dec [hl] dec [hl] jr .checkmove .discourage call Random cp 30 jr c, .checkmove inc [hl] inc [hl] jr .checkmove ; 38635 AIScoring_RedSuperEffective: ; 38635 ; Dismiss any move that the player is immune to. ; Encourage super-effective moves. ; Discourage not very effective moves unless ; all damaging moves are of the same type. 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 AIScoring_Offensive: ; 386a2 ; Greatly 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 AIScoring_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, AIScoring_Sleep dbw EFFECT_LEECH_HIT, AIScoring_LeechHit dbw EFFECT_EXPLOSION, AIScoring_Explosion dbw EFFECT_DREAM_EATER, AIScoring_DreamEater dbw EFFECT_MIRROR_MOVE, AIScoring_MirrorMove dbw EFFECT_EVASION_UP, AIScoring_EvasionUp dbw EFFECT_ALWAYS_HIT, AIScoring_AlwaysHit dbw EFFECT_ACCURACY_DOWN, AIScoring_AccuracyDown dbw EFFECT_HAZE, AIScoring_Haze dbw EFFECT_BIDE, AIScoring_Bide dbw EFFECT_WHIRLWIND, AIScoring_Whirlwind dbw EFFECT_HEAL, AIScoring_Heal dbw EFFECT_TOXIC, AIScoring_Toxic dbw EFFECT_LIGHT_SCREEN, AIScoring_LightScreen dbw EFFECT_OHKO, AIScoring_Ohko dbw EFFECT_RAZOR_WIND, AIScoring_RazorWind dbw EFFECT_SUPER_FANG, AIScoring_SuperFang dbw EFFECT_BIND, AIScoring_Bind dbw EFFECT_UNUSED_2B, AIScoring_Unused2B dbw EFFECT_CONFUSE, AIScoring_Confuse dbw EFFECT_SP_DEF_UP_2, AIScoring_SpDefenseUp2 dbw EFFECT_REFLECT, AIScoring_Reflect dbw EFFECT_PARALYZE, AIScoring_Paralyze dbw EFFECT_SPEED_DOWN_HIT, AIScoring_SpeedDownHit dbw EFFECT_SUBSTITUTE, AIScoring_Substitute dbw EFFECT_HYPER_BEAM, AIScoring_HyperBeam dbw EFFECT_RAGE, AIScoring_Rage dbw EFFECT_MIMIC, AIScoring_Mimic dbw EFFECT_LEECH_SEED, AIScoring_LeechSeed dbw EFFECT_DISABLE, AIScoring_Disable dbw EFFECT_COUNTER, AIScoring_Counter dbw EFFECT_ENCORE, AIScoring_Encore dbw EFFECT_PAIN_SPLIT, AIScoring_PainSplit dbw EFFECT_SNORE, AIScoring_Snore dbw EFFECT_CONVERSION2, AIScoring_Conversion2 dbw EFFECT_LOCK_ON, AIScoring_LockOn dbw EFFECT_DEFROST_OPPONENT, AIScoring_DefrostOpponent dbw EFFECT_SLEEP_TALK, AIScoring_SleepTalk dbw EFFECT_DESTINY_BOND, AIScoring_DestinyBond dbw EFFECT_REVERSAL, AIScoring_Reversal dbw EFFECT_SPITE, AIScoring_Spite dbw EFFECT_HEAL_BELL, AIScoring_HealBell dbw EFFECT_PRIORITY_HIT, AIScoring_PriorityHit dbw EFFECT_THIEF, AIScoring_Thief dbw EFFECT_MEAN_LOOK, AIScoring_MeanLook dbw EFFECT_NIGHTMARE, AIScoring_Nightmare dbw EFFECT_FLAME_WHEEL, AIScoring_FlameWheel dbw EFFECT_CURSE, AIScoring_Curse dbw EFFECT_PROTECT, AIScoring_Protect dbw EFFECT_FORESIGHT, AIScoring_Foresight dbw EFFECT_PERISH_SONG, AIScoring_PerishSong dbw EFFECT_SANDSTORM, AIScoring_Sandstorm dbw EFFECT_ENDURE, AIScoring_Endure dbw EFFECT_ROLLOUT, AIScoring_Rollout dbw EFFECT_SWAGGER, AIScoring_Swagger dbw EFFECT_FURY_CUTTER, AIScoring_FuryCutter dbw EFFECT_ATTRACT, AIScoring_Attract dbw EFFECT_SAFEGUARD, AIScoring_Safeguard dbw EFFECT_MAGNITUDE, AIScoring_Magnitude dbw EFFECT_BATON_PASS, AIScoring_BatonPass dbw EFFECT_PURSUIT, AIScoring_Pursuit dbw EFFECT_RAPID_SPIN, AIScoring_RapidSpin dbw EFFECT_MORNING_SUN, AIScoring_MorningSun dbw EFFECT_SYNTHESIS, AIScoring_Synthesis dbw EFFECT_MOONLIGHT, AIScoring_Moonlight dbw EFFECT_HIDDEN_POWER, AIScoring_HiddenPower dbw EFFECT_RAIN_DANCE, AIScoring_RainDance dbw EFFECT_SUNNY_DAY, AIScoring_SunnyDay dbw EFFECT_BELLY_DRUM, AIScoring_BellyDrum dbw EFFECT_PSYCH_UP, AIScoring_PsychUp dbw EFFECT_MIRROR_COAT, AIScoring_MirrorCoat dbw EFFECT_SKULL_BASH, AIScoring_SkullBash dbw EFFECT_TWISTER, AIScoring_Twister dbw EFFECT_EARTHQUAKE, AIScoring_Earthquake dbw EFFECT_FUTURE_SIGHT, AIScoring_FutureSight dbw EFFECT_GUST, AIScoring_Gust dbw EFFECT_STOMP, AIScoring_Stomp dbw EFFECT_SOLARBEAM, AIScoring_Solarbeam dbw EFFECT_THUNDER, AIScoring_Thunder dbw EFFECT_FLY, AIScoring_Fly db $ff ; 387e3 AIScoring_Sleep: ; 387e3 ; Greatly encourage sleep inducing moves if the enemy has either Dream Eater or Nightmare. ; 50% chance to greatly encourage sleep inducing moves otherwise. ld b, EFFECT_DREAM_EATER call AIHasMove jr c, .asm_387f0 ld b, EFFECT_NIGHTMARE call AIHasMove ret nc .asm_387f0 call Function39527 ret c dec [hl] dec [hl] ret ; 387f7 AIScoring_LeechHit: ; 387f7 push hl ld a, 1 ld [hBattleTurn], a callab Function347c8 pop hl ; 60% chance to discourage this move if not very effective. ld a, [$d265] cp 10 ; 1.0 jr c, .asm_38815 ; Do nothing if effectiveness is neutral. ret z ; Do nothing if enemy's HP is full. call AICheckEnemyMaxHP ret c ; 80% chance to encourage this move otherwise. call Function39521 ret c dec [hl] ret .asm_38815 call Random cp $64 ret c inc [hl] ret ; 3881d AIScoring_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 Function39527 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 AIScoring_Explosion: ; 388a6 ; Unless this is the enemy's last Pokemon... push hl callba Function349f4 pop hl jr nc, .asm_388b7 ; ...greatly discourage this move unless this is the player's last Pokemon too. push hl call AICheckLastPlayerMon pop hl jr nz, .asm_388c6 .asm_388b7 ; Greatly discourage this move if enemy's HP is above 50%. call AICheckEnemyHalfHP jr c, .asm_388c6 ; Do nothing if enemy's HP is below 25%. call AICheckEnemyQuarterHP ret nc ; If enemy's HP is between 25% and 50%, ; over 90% chance to greatly discourage this move. call Random cp 20 ret c .asm_388c6 inc [hl] inc [hl] inc [hl] ret ; 388ca AIScoring_DreamEater: ; 388ca ; 90% chance to greatly encourage this move. ; The AIScoring_RedStatus layer will make sure that ; Dream Eater is only used against sleeping targets. call Random cp $19 ret c dec [hl] dec [hl] dec [hl] ret ; 388d4 AIScoring_EvasionUp: ; 388d4 ; Dismiss this move if enemy's evasion can't raise anymore. ld a, [EnemyEvaLevel] cp $d jp nc, AIDiscourageMove ; If enemy's HP is full... call AICheckEnemyMaxHP jr nc, .asm_388f2 ; ...greatly encourage this move if player is badly poisoned. ld a, [PlayerSubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_388ef ; ...70% chance to greatly encourage this move if player is not badly poisoned. call Random cp $b2 jr nc, .asm_38911 .asm_388ef dec [hl] dec [hl] ret .asm_388f2 ; Greatly discourage this move if enemy's HP is below 25%. call AICheckEnemyQuarterHP jr nc, .asm_3890f ; If enemy's HP is above 25% but not full, 4% chance to greatly encourage this move. call Random cp $a jr c, .asm_388ef ; If enemy's HP is between 25% and 50%,... call AICheckEnemyHalfHP jr nc, .asm_3890a ; If enemy's HP is above 50% but not full, 20% chance to greatly encourage this move. call Function39521 jr c, .asm_388ef jr .asm_38911 .asm_3890a ; ...50% chance to greatly discourage this move. call Function39527 jr c, .asm_38911 .asm_3890f inc [hl] inc [hl] ; 30% chance to end up here if enemy's HP is full and player is not badly poisoned. ; 77% chance to end up here if enemy's HP is above 50% but not full. ; 96% chance to end up here if enemy's HP is between 25% and 50%. ; 100% chance to end up here if enemy's HP is below 25%. ; In other words, we only end up here if the move has not been encouraged or dismissed. .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 ; Discourage this move if enemy's evasion level is higher than player's accuracy level. ld a, [EnemyEvaLevel] ld b, a ld a, [PlayerAccLevel] cp b jr c, .asm_38936 ; Greatly encourage this move if the player is in the middle of Fury Cutter or Rollout. 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 ; Player is badly poisoned. ; 80% chance to greatly encourage this move. ; This would counter any previous discouragement. .asm_38938 call Random cp $50 ret c dec [hl] dec [hl] ret ; Player is seeded. ; 50% chance to encourage this move. ; This would partly counter any previous discouragement. .asm_38941 call Function39527 ret c dec [hl] ret ; 38947 AIScoring_AlwaysHit: ; 38947 ; 80% chance to greatly encourage this move if either... ; ...enemy's accuracy level has been lowered three or more stages ld a, [EnemyAccLevel] cp $5 jr c, .asm_38954 ; ...or player's evasion level has been raised three or more stages. ld a, [PlayerEvaLevel] cp $a ret c .asm_38954 call Function39521 ret c dec [hl] dec [hl] ret ; 3895b AIScoring_MirrorMove: ; 3895b ; If the player did not use any move last turn... ld a, [LastEnemyCounterMove] and a jr nz, .asm_38968 ; ...do nothing if enemy is slower than player call AICompareSpeed ret nc ; ...or dismiss this move if enemy is faster than player. jp AIDiscourageMove ; If the player did use a move last turn... .asm_38968 push hl ld hl, UsefulMoves ld de, 1 call IsInArray pop hl ; ...do nothing if he didn't use a useful move. ret nc ; If he did, 50% chance to encourage this move... call Function39527 ret c dec [hl] ; ...and 90% chance to encourage this move again if the enemy is faster. call AICompareSpeed ret nc call Random cp $19 ret c dec [hl] ret ; 38985 AIScoring_AccuracyDown: ; 38985 ; If player's HP is full... call AICheckPlayerMaxHP jr nc, .asm_389a0 ; ...and enemy's HP is above 50%... call AICheckEnemyHalfHP jr nc, .asm_389a0 ; ...greatly encourage this move if player is badly poisoned. ld a, [PlayerSubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_3899d ; ...70% chance to greatly encourage this move if player is not badly poisoned. call Random cp $b2 jr nc, .asm_389bf .asm_3899d dec [hl] dec [hl] ret .asm_389a0 ; Greatly discourage this move if player's HP is below 25%. call AICheckPlayerQuarterHP jr nc, .asm_389bd ; If player's HP is above 25% but not full, 4% chance to greatly encourage this move. call Random cp $a jr c, .asm_3899d ; If player's HP is between 25% and 50%,... call AICheckPlayerHalfHP jr nc, .asm_389b8 ; If player's HP is above 50% but not full, 20% chance to greatly encourage this move. call Function39521 jr c, .asm_3899d jr .asm_389bf ; ...50% chance to greatly discourage this move. .asm_389b8 call Function39527 jr c, .asm_389bf .asm_389bd inc [hl] inc [hl] ; We only end up here if the move has not been already encouraged. .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 ; Discourage this move if enemy's evasion level is higher than player's accuracy level. ld a, [EnemyEvaLevel] ld b, a ld a, [PlayerAccLevel] cp b jr c, .asm_389e4 ; Greatly encourage this move if the player is in the middle of Fury Cutter or Rollout. 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 ; Player is badly poisoned. ; 80% chance to greatly encourage this move. ; This would counter any previous discouragement. .asm_389e6 call Random cp $50 ret c dec [hl] dec [hl] ret ; Player is seeded. ; 50% chance to encourage this move. ; This would partly counter any previous discouragement. .asm_389ef call Function39527 ret c dec [hl] ret ; 389f5 AIScoring_Haze: ; 389f5 ; 85% chance to encourage this move if any of enemy's stat levels is lower than -2. 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 ; 85% chance to encourage this move if any of player's stat levels is higher than +2. .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 ; Discourage this move if neither: ; Any of enemy's stat levels is lower than -2. ; Any of player's stat levels is higher than +2. .asm_38a1b pop hl inc [hl] ret ; 38a1e AIScoring_Bide: ; 38a1e ; 90% chance to discourage this move unless enemy's HP is full. call AICheckEnemyMaxHP ret c call Random cp $19 ret c inc [hl] ret ; 38a2a AIScoring_Whirlwind: ; 38a2a ; Discourage this move if the player has not shown ; a super-effective move against the enemy. ; Consider player's type if its moves are unknown. push hl callab Function3484e ld a, [$c716] cp $a pop hl ret c inc [hl] ret ; 38a3a AIScoring_Heal: AIScoring_MorningSun: AIScoring_Synthesis: AIScoring_Moonlight: ; 38a3a ; 90% chance to greatly encourage this move if enemy's HP is below 25%. ; Discourage this move if enemy's HP is higher than 50%. ; Do nothing otherwise. 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 AIScoring_Toxic: AIScoring_LeechSeed: ; 38a4e ; Discourage this move if player's HP is below 50%. call AICheckPlayerHalfHP ret c inc [hl] ret ; 38a54 AIScoring_LightScreen: AIScoring_Reflect: ; 38a54 ; Over 90% chance to discourage this move unless enemy's HP is full. call AICheckEnemyMaxHP ret c call Random cp $14 ret c inc [hl] ret ; 38a60 AIScoring_Ohko: ; 38a60 ; Dismiss this move if player's level is higher than enemy's level ; Otherwise, discourage this move is player's HP is below 50%. ld a, [BattleMonLevel] ld b, a ld a, [EnemyMonLevel] cp b jp c, AIDiscourageMove call AICheckPlayerHalfHP ret c inc [hl] ret ; 38a71 AIScoring_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<