diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..3971c045e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# No monkey business with line endings +* text=false diff --git a/audio/sfx_pointers.asm b/audio/sfx_pointers.asm index fb06d931b..726e712c2 100644 --- a/audio/sfx_pointers.asm +++ b/audio/sfx_pointers.asm @@ -1,212 +1,213 @@ ; e927c - dbw $3c, $4b3f ; dex fanfare 50-79 - dbw $3c, $4c2f ; item - dbw $3c, $4c89 ; caught mon - dbw $3c, $4941 ; pokeballs placed on table - dbw $3c, $4947 ; potion - dbw $3c, $494a ; full heal - dbw $3c, $494d ; menu - dbw $3c, $4950 ; read text - dbw $3c, $4950 ; read text - dbw $3c, $4bd5 ; dex fanfare 20-49 - dbw $3c, $4cea ; dex fanfare 80-109 - dbw $3c, $4953 ; poison - dbw $3c, $4956 ; got safari balls - dbw $3c, $4959 ; boot pc - dbw $3c, $495c ; shut down pc - dbw $3c, $495f ; choose pc option - dbw $3c, $4962 ; bide / escape rope - dbw $3c, $4965 ; push button - dbw $3c, $4968 ; second part of itemfinder - dbw $3c, $496b ; warp to - dbw $3c, $496e ; warp from - dbw $3c, $4971 ; change dex mode - dbw $3c, $4974 ; jump over ledge - dbw $3c, $4977 ; grass rustle - dbw $3c, $497a ; fly - dbw $3c, $497d ; wrong - dbw $3c, $4983 ; squeak - dbw $3c, $4986 ; strength - dbw $3c, $4989 ; boat - dbw $3c, $498f ; wall open - dbw $3c, $4992 ; place puzzle piece down - dbw $3c, $4995 ; enter door - dbw $3c, $4998 ; switch pokemon - dbw $3c, $499e ; score tally? ; sounds like something out of game corner - dbw $3c, $49a4 ; buy/sell - dbw $3c, $49ad ; exit building - dbw $3c, $49aa ; bump - dbw $3c, $49b0 ; save - dbw $3c, $49f8 ; pokeflute - dbw $3c, $49fb ; elevator end - dbw $3c, $49fe ; throw ball - dbw $3c, $4a04 ; smokescreen - dbw $3c, $4a0a ; ; something skidding on water? - dbw $3c, $4a10 ; run - dbw $3c, $4a13 ; slot machine start - dbw $3c, $4dbe ; fanfare - dbw $3c, $4a3d ; peck - dbw $3c, $4a40 ; kinesis - dbw $3c, $4a43 ; lick - dbw $3c, $4a46 ; pound - dbw $3c, $4a49 ; move puzzle piece - dbw $3c, $4a4c ; comet punch - dbw $3c, $4a4f ; mega punch - dbw $3c, $4a52 ; scratch - dbw $3c, $4a55 ; vicegrip - dbw $3c, $4a58 ; razor wind - dbw $3c, $4a5b ; cut - dbw $3c, $4a5e ; wing attack - dbw $3c, $4a61 ; whirlwind - dbw $3c, $4a64 ; bind - dbw $3c, $4a67 ; vine whip - dbw $3c, $4a6a ; double kick - dbw $3c, $4a6d ; mega kick - dbw $3c, $4a70 ; headbutt - dbw $3c, $4a73 ; horn attack - dbw $3c, $4a76 ; tackle - dbw $3c, $4a79 ; poison sting - dbw $3c, $4a7c ; poisonpowder - dbw $3c, $4a7f ; doubleslap - dbw $3c, $4a82 ; bite - dbw $3c, $4a88 ; jump kick - dbw $3c, $4a8b ; stomp - dbw $3c, $4a8e ; tail whip - dbw $3c, $4a91 ; karate chop - dbw $3c, $4a94 ; submission - dbw $3c, $4a97 ; water gun - dbw $3c, $4a9d ; swords dance - dbw $3c, $4aa0 ; thunder - dbw $3c, $4aa3 ; supersonic - dbw $3c, $4aac ; leer - dbw $3c, $4ab5 ; ember - dbw $3c, $4abb ; bubblebeam - dbw $3c, $4ac4 ; hydro pump - dbw $3c, $4aca ; surf - dbw $3c, $4ad3 ; psybeam - dbw $3c, $4adc ; leech seed - dbw $3c, $4ae5 ; thundershock - dbw $3c, $4aee ; psychic - dbw $3c, $4af7 ; screech - dbw $3c, $4afd ; bone club - dbw $3c, $4b03 ; sharpen - dbw $3c, $4b09 ; egg bomb - dbw $3c, $4b12 ; sing - dbw $3c, $4b18 ; sky attack - dbw $3c, $4b21 ; hyper beam - dbw $3c, $4b24 ; shine - dbw $3c, $4a1c ; - dbw $3c, $4a1f ; $60 - dbw $3c, $4a22 ; tap - dbw $3c, $4a25 ; tap - dbw $3c, $4a28 ; burn ; that is not a burn - dbw $3c, $4a2b ; title screen sound - dbw $3c, $4a2e ; similar to $60 - dbw $3c, $4a31 ; get coin from slots - dbw $3c, $4a34 ; pay day - dbw $3c, $4a3a ; metronome - dbw $3c, $4a19 ; call - dbw $3c, $4b2d ; hang up - dbw $3c, $4b30 ; no signal - dbw $3c, $4b2a ; sandstorm - dbw $3c, $4b33 ; elevator - dbw $3c, $52b4 ; protect - dbw $3c, $52f6 ; sketch - dbw $3c, $5314 ; rain dance - dbw $3c, $5334 ; aeroblast - dbw $3c, $5352 ; spark - dbw $3c, $5360 ; curse - dbw $3c, $537d ; rage - dbw $3c, $539c ; thief - dbw $3c, $53b0 ; thief - dbw $3c, $53ca ; spider web - dbw $3c, $53f7 ; mind reader - dbw $3c, $541d ; nighmare - dbw $3c, $5453 ; snore - dbw $3c, $5469 ; sweet kiss - dbw $3c, $547f ; sweet kiss - dbw $3c, $54a5 ; belly drum - dbw $3c, $54ba ; - dbw $3c, $54d0 ; sludge bomb - dbw $3c, $54f5 ; foresight - dbw $3c, $5515 ; spite - dbw $3c, $553a ; outrage - dbw $3c, $554d ; perish song - dbw $3c, $5570 ; giga drain - dbw $3c, $55b4 ; attract - dbw $3c, $55cc ; kinesis - dbw $3c, $55de ; zap cannon - dbw $3c, $55ef ; mean look - dbw $3c, $5621 ; heal bell - dbw $3c, $5637 ; return - dbw $3c, $5653 ; exp bar - dbw $3c, $567f ; milk drink - dbw $3c, $569f ; present - dbw $3c, $56b9 ; morning sun - dbw $3c, $4b3f ; level up - dbw $3c, $4b86 ; key item - dbw $3c, $4d56 ; fanfare - dbw $3c, $4dc7 ; register phone # - dbw $3c, $4e26 ; 3rd place - dbw $3c, $4e66 ; get egg from daycare man - dbw $3c, $4e66 ; get egg from daycare lady - dbw $3c, $4edc ; move deleted - dbw $3c, $4f5e ; 2nd place - dbw $3c, $4fe2 ; 1st place - dbw $3c, $5069 ; choose a card - dbw $3c, $5104 ; get tm - dbw $3c, $517d ; get badge - dbw $3c, $5236 ; quit slots - dbw $3c, $5775 ; nothing - dbw $3c, $5878 ; dex fanfare <20 - dbw $3c, $58d2 ; dex fanfare 140-169 - dbw $3c, $5951 ; dex fanfare 170-199 - dbw $3c, $59d6 ; dex fanfare 200-229 - dbw $3c, $5a66 ; dex fanfare >=230 - dbw $3c, $5784 ; evolved - dbw $3c, $579b ; master ball - dbw $3c, $57c0 ; egg crack - dbw $3c, $57d9 ; charizard fireball (gs intro) - dbw $3c, $57ff ; pokemon appears (gs intro) - dbw $3c, $5818 ; flash - dbw $3c, $5846 ; game freak logo - dbw $3c, $5b33 ; not very effective - dbw $3c, $5b40 ; damage - dbw $3c, $5b50 ; super effective - dbw $3c, $5b63 ; ball bounce - dbw $3c, $56df ; moonlight - dbw $3c, $56fd ; encore - dbw $3c, $5721 ; beat up - dbw $3c, $574c ; batom pass - dbw $3c, $4944 ; ball wiggle - dbw $3c, $5734 ; sweet scent - dbw $3c, $5bb3 ; sweet scent - dbw $3c, $5bec ; hit end of exp bar - dbw $3c, $5c10 ; give trademon - dbw $3c, $5c3e ; get trademon - dbw $3c, $5c6c ; train arrived - dbw $3c, $675b ; stop slot - dbw $3c, $5cb4 ; 2 boops - dbw $3c, $6769 ; glass ting - dbw $3c, $6773 ; 2 glass ting + dbw $3c, $4b3f ; Dex Fanfare 50-79 + dbw $3c, $4c2f ; Item + dbw $3c, $4c89 ; Caught Mon + dbw $3c, $4941 ; Pokeballs Placed On Table + dbw $3c, $4947 ; Potion + dbw $3c, $494a ; Full Heal + dbw $3c, $494d ; Menu + dbw $3c, $4950 ; Read Text + dbw $3c, $4950 ; Read Text 2 + dbw $3c, $4bd5 ; Dex Fanfare 20-49 + dbw $3c, $4cea ; Dex Fanfare 80-109 + dbw $3c, $4953 ; Poison + dbw $3c, $4956 ; Got Safari Balls + dbw $3c, $4959 ; Boot Pc + dbw $3c, $495c ; Shut Down Pc + dbw $3c, $495f ; Choose Pc Option + dbw $3c, $4962 ; Escape Rope + dbw $3c, $4965 ; Push Button + dbw $3c, $4968 ; Second Part Of Itemfinder + dbw $3c, $496b ; Warp To + dbw $3c, $496e ; Warp From + dbw $3c, $4971 ; Change Dex Mode + dbw $3c, $4974 ; Jump Over Ledge + dbw $3c, $4977 ; Grass Rustle + dbw $3c, $497a ; Fly + dbw $3c, $497d ; Wrong + dbw $3c, $4983 ; Squeak + dbw $3c, $4986 ; Strength + dbw $3c, $4989 ; Boat + dbw $3c, $498f ; Wall Open + dbw $3c, $4992 ; Place Puzzle Piece Down + dbw $3c, $4995 ; Enter Door + dbw $3c, $4998 ; Switch Pokemon + dbw $3c, $499e ; Tally + dbw $3c, $49a4 ; Transaction + dbw $3c, $49ad ; Exit Building + dbw $3c, $49aa ; Bump + dbw $3c, $49b0 ; Save + dbw $3c, $49f8 ; Pokeflute + dbw $3c, $49fb ; Elevator End + dbw $3c, $49fe ; Throw Ball + dbw $3c, $4a04 ; Ball Poof + dbw $3c, $4a0a ; Unknown 3A + dbw $3c, $4a10 ; Run + dbw $3c, $4a13 ; Slot Machine Start + dbw $3c, $4dbe ; Fanfare + dbw $3c, $4a3d ; Peck + dbw $3c, $4a40 ; Kinesis + dbw $3c, $4a43 ; Lick + dbw $3c, $4a46 ; Pound + dbw $3c, $4a49 ; Move Puzzle Piece + dbw $3c, $4a4c ; Comet Punch + dbw $3c, $4a4f ; Mega Punch + dbw $3c, $4a52 ; Scratch + dbw $3c, $4a55 ; Vicegrip + dbw $3c, $4a58 ; Razor Wind + dbw $3c, $4a5b ; Cut + dbw $3c, $4a5e ; Wing Attack + dbw $3c, $4a61 ; Whirlwind + dbw $3c, $4a64 ; Bind + dbw $3c, $4a67 ; Vine Whip + dbw $3c, $4a6a ; Double Kick + dbw $3c, $4a6d ; Mega Kick + dbw $3c, $4a70 ; Headbutt + dbw $3c, $4a73 ; Horn Attack + dbw $3c, $4a76 ; Tackle + dbw $3c, $4a79 ; Poison Sting + dbw $3c, $4a7c ; Powder + dbw $3c, $4a7f ; Doubleslap + dbw $3c, $4a82 ; Bite + dbw $3c, $4a88 ; Jump Kick + dbw $3c, $4a8b ; Stomp + dbw $3c, $4a8e ; Tail Whip + dbw $3c, $4a91 ; Karate Chop + dbw $3c, $4a94 ; Submission + dbw $3c, $4a97 ; Water Gun + dbw $3c, $4a9d ; Swords Dance + dbw $3c, $4aa0 ; Thunder + dbw $3c, $4aa3 ; Supersonic + dbw $3c, $4aac ; Leer + dbw $3c, $4ab5 ; Ember + dbw $3c, $4abb ; Bubblebeam + dbw $3c, $4ac4 ; Hydro Pump + dbw $3c, $4aca ; Surf + dbw $3c, $4ad3 ; Psybeam + dbw $3c, $4adc ; Charge + dbw $3c, $4ae5 ; Thundershock + dbw $3c, $4aee ; Psychic + dbw $3c, $4af7 ; Screech + dbw $3c, $4afd ; Bone Club + dbw $3c, $4b03 ; Sharpen + dbw $3c, $4b09 ; Egg Bomb + dbw $3c, $4b12 ; Sing + dbw $3c, $4b18 ; Hyper Beam + dbw $3c, $4b21 ; Shine + dbw $3c, $4b24 ; Unknown 5F + dbw $3c, $4a1c ; Unknown 60 + dbw $3c, $4a1f ; Unknown 61 + dbw $3c, $4a22 ; Unknown 62 + dbw $3c, $4a25 ; Unknown 63 + dbw $3c, $4a28 ; Burn + dbw $3c, $4a2b ; Title Screen Entrance + dbw $3c, $4a2e ; Unknown 66 + dbw $3c, $4a31 ; Get Coin From Slots + dbw $3c, $4a34 ; Pay Day + dbw $3c, $4a3a ; Metronome + dbw $3c, $4a19 ; Call + dbw $3c, $4b2d ; Hang Up + dbw $3c, $4b30 ; No Signal + dbw $3c, $4b2a ; Sandstorm + dbw $3c, $4b33 ; Elevator + dbw $3c, $52b4 ; Protect + dbw $3c, $52f6 ; Sketch + dbw $3c, $5314 ; Rain Dance + dbw $3c, $5334 ; Aeroblast + dbw $3c, $5352 ; Spark + dbw $3c, $5360 ; Curse + dbw $3c, $537d ; Rage + dbw $3c, $539c ; Thief + dbw $3c, $53b0 ; Thief 2 + dbw $3c, $53ca ; Spider Web + dbw $3c, $53f7 ; Mind Reader + dbw $3c, $541d ; Nightmare + dbw $3c, $5453 ; Snore + dbw $3c, $5469 ; Sweet Kiss + dbw $3c, $547f ; Sweet Kiss 2 + dbw $3c, $54a5 ; Belly Drum + dbw $3c, $54ba ; Unknown 7F + dbw $3c, $54d0 ; Sludge Bomb + dbw $3c, $54f5 ; Foresight + dbw $3c, $5515 ; Spite + dbw $3c, $553a ; Outrage + dbw $3c, $554d ; Perish Song + dbw $3c, $5570 ; Giga Drain + dbw $3c, $55b4 ; Attract + dbw $3c, $55cc ; Kinesis 2 + dbw $3c, $55de ; Zap Cannon + dbw $3c, $55ef ; Mean Look + dbw $3c, $5621 ; Heal Bell + dbw $3c, $5637 ; Return + dbw $3c, $5653 ; Exp Bar + dbw $3c, $567f ; Milk Drink + dbw $3c, $569f ; Present + dbw $3c, $56b9 ; Morning Sun + dbw $3c, $4b3f ; Level Up + dbw $3c, $4b86 ; Key Item + dbw $3c, $4d56 ; Fanfare 2 + dbw $3c, $4dc7 ; Register Phone # + dbw $3c, $4e26 ; 3Rd Place + dbw $3c, $4e66 ; Get Egg From Daycare Man + dbw $3c, $4e66 ; Get Egg From Daycare Lady + dbw $3c, $4edc ; Move Deleted + dbw $3c, $4f5e ; 2Nd Place + dbw $3c, $4fe2 ; 1St Place + dbw $3c, $5069 ; Choose A Card + dbw $3c, $5104 ; Get Tm + dbw $3c, $517d ; Get Badge + dbw $3c, $5236 ; Quit Slots + dbw $3c, $5775 ; Egg Crack + dbw $3c, $5878 ; Dex Fanfare < 20 + dbw $3c, $58d2 ; Dex Fanfare 140-169 + dbw $3c, $5951 ; Dex Fanfare 170-199 + dbw $3c, $59d6 ; Dex Fanfare 200-229 + dbw $3c, $5a66 ; Dex Fanfare 230 + + dbw $3c, $5784 ; Evolved + dbw $3c, $579b ; Master Ball + dbw $3c, $57c0 ; Egg Hatch + dbw $3c, $57d9 ; Gs Intro Charizard Fireball + dbw $3c, $57ff ; Gs Intro Pokemon Appears + dbw $3c, $5818 ; Flash + dbw $3c, $5846 ; Game Freak Logo Gs + dbw $3c, $5b33 ; Not Very Effective + dbw $3c, $5b40 ; Damage + dbw $3c, $5b50 ; Super Effective + dbw $3c, $5b63 ; Ball Bounce + dbw $3c, $56df ; Moonlight + dbw $3c, $56fd ; Encore + dbw $3c, $5721 ; Beat Up + dbw $3c, $574c ; Baton Pass + dbw $3c, $4944 ; Ball Wiggle + dbw $3c, $5734 ; Sweet Scent + dbw $3c, $5bb3 ; Sweet Scent 2 + dbw $3c, $5bec ; Hit End Of Exp Bar + dbw $3c, $5c10 ; Give Trademon + dbw $3c, $5c3e ; Get Trademon + dbw $3c, $5c6c ; Train Arrived + dbw $3c, $675b ; Stop Slot + dbw $3c, $5cb4 ; 2 Boops + dbw $3c, $6769 ; Glass Ting + dbw $3c, $6773 ; Glass Ting 2 ; Crystal adds the following SFX: - dbw $5e, $582d ; intro unown 1 - dbw $5e, $583e ; intro unown 2 - dbw $5e, $584f ; intro unown 3 - dbw $5e, $586e ; boop - dbw $5e, $5888 ; game freak ditto transform - dbw $5e, $58a0 ; intro suicune 1 - dbw $5e, $58aa ; intro pichu - dbw $5e, $58c0 ; intro suicune 2 - dbw $5e, $58f4 ; intro suicune 3 - dbw $5e, $5907 ; game freak ditto bounce - dbw $5e, $591d ; intro suicune 4 - dbw $5e, $5942 ; game freak presents - dbw $5e, $5961 ; tingle - dbw $3c, $5cd0 ; sand? - dbw $5e, $597c ; two pc beeps - dbw $5e, $5992 ; 4 note ditty - dbw $5e, $59cb ; twinkle + dbw $5e, $582d ; Intro Unown 1 + dbw $5e, $583e ; Intro Unown 2 + dbw $5e, $584f ; Intro Unown 3 + dbw $5e, $586e ; Ditto Pop Up + dbw $5e, $5888 ; Ditto Transform + dbw $5e, $58a0 ; Intro Suicune 1 + dbw $5e, $58aa ; Intro Pichu + dbw $5e, $58c0 ; Intro Suicune 2 + dbw $5e, $58f4 ; Intro Suicune 3 + dbw $5e, $5907 ; Ditto Bounce + dbw $5e, $591d ; Intro Suicune 4 + dbw $5e, $5942 ; Game Freak Presents + dbw $5e, $5961 ; Tingle + dbw $3c, $5cd0 ; Unknown Cb + dbw $5e, $597c ; Two Pc Beeps + dbw $5e, $5992 ; 4 Note Ditty + dbw $5e, $59cb ; Twinkle ; e94e9 + diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm new file mode 100644 index 000000000..b48e04bc6 --- /dev/null +++ b/battle/ai/scoring.asm @@ -0,0 +1,3362 @@ +AIScoring_RedStatus: ; 38591 +; Don't use status-only moves if the player can't be statused. + + 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, [EnemyMoveEffect] + ld c, a + + push hl + push de + push bc + ld a, $b + ld hl, $441a + rst FarCall + pop bc + pop de + pop hl + jr nz, .discourage + + ld a, [EnemyMoveEffect] + 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 + + + +AIScoring_RedStatMods: ; 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, [EnemyMoveEffect] + + 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 Function_0x39527 + jr c, .checkmove + + dec [hl] + dec [hl] + jr .checkmove + +.discourage + call RNG + cp 30 + jr c, .checkmove + inc [hl] + inc [hl] + jr .checkmove +; 38635 + + + +AIScoring_RedSuperEffective: ; 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 Function0x347c8 + 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, [EnemyMovePower] + 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, [EnemyMoveType] + 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, [EnemyMoveType] + cp d + jr z, .checkmove2 + ld a, [EnemyMovePower] + 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 +; 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, [EnemyMovePower] + 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, [EnemyMoveEffect] + 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_DEFENSE_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 + ld b, EFFECT_DREAM_EATER + call AIHasMove + jr c, .asm_387f0 + + ld b, EFFECT_NIGHTMARE + call AIHasMove + ret nc + +.asm_387f0 + call Function_0x39527 + ret c + dec [hl] + dec [hl] + ret +; 387f7 + + +AIScoring_LeechHit: ; 387f7 + push hl + ld a, 1 + ld [hBattleTurn], a + callab Function0x347c8 + pop hl + + ld a, [$d265] + cp 10 ; 1.0 + jr c, .asm_38815 + + ret z + call AICheckEnemyMaxHP + + ret c + call Function_0x39521 + + ret c + dec [hl] + ret + +.asm_38815 + call RNG + + cp $64 + ret c + inc [hl] + ret +; 3881d + + +AIScoring_LockOn: ; 3881d + ld a, [PlayerSubStatus5] + bit 5, 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, [EnemyMoveAccuracy] + cp $b4 + jr nc, .asm_3884f + + ld a, $1 + ld [hBattleTurn], a + push hl + push bc + ld a, $d + ld hl, $47c8 + rst FarCall + + 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 Function_0x39527 + + 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, [EnemyMoveAccuracy] + cp $b4 + jr nc, .asm_3888b + + dec [hl] + dec [hl] + jr .asm_3888b + + +.asm_388a2 + pop hl + jp AIDiscourageMove + +; 388a6 + + +AIScoring_Explosion: ; 388a6 + push hl + callba Function0x349f4 + 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 RNG + cp 20 + ret c + +.asm_388c6 + inc [hl] + inc [hl] + inc [hl] + ret +; 388ca + + +AIScoring_DreamEater: ; 388ca + call RNG + + cp $19 + ret c + dec [hl] + dec [hl] + dec [hl] + ret +; 388d4 + + +AIScoring_EvasionUp: ; 388d4 + ld a, [EnemyEvaLevel] + cp $d + jp nc, AIDiscourageMove + + call AICheckEnemyMaxHP + + jr nc, .asm_388f2 + + ld a, [PlayerSubStatus5] + bit 0, a + jr nz, .asm_388ef + + call RNG + + cp $b2 + jr nc, .asm_38911 + + +.asm_388ef + dec [hl] + dec [hl] + ret + +.asm_388f2 + call AICheckEnemyQuarterHP + + jr nc, .asm_3890f + + call RNG + + cp $a + jr c, .asm_388ef + + call AICheckEnemyHalfHP + + jr nc, .asm_3890a + + call Function_0x39521 + + jr c, .asm_388ef + + jr .asm_38911 + + +.asm_3890a + call Function_0x39527 + + jr c, .asm_38911 + + +.asm_3890f + inc [hl] + inc [hl] + +.asm_38911 + ld a, [PlayerSubStatus5] + bit 0, a + jr nz, .asm_38938 + + ld a, [PlayerSubStatus4] + bit 7, 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 6, a + jr nz, .asm_388ef + + +.asm_38936 + inc [hl] + ret + +.asm_38938 + call RNG + cp $50 + ret c + dec [hl] + dec [hl] + ret + +.asm_38941 + call Function_0x39527 + + ret c + dec [hl] + ret +; 38947 + + +AIScoring_AlwaysHit: ; 38947 + ld a, [EnemyAccLevel] + cp $5 + jr c, .asm_38954 + + ld a, [PlayerEvaLevel] + cp $a + ret c + +.asm_38954 + call Function_0x39521 + + ret c + dec [hl] + dec [hl] + ret +; 3895b + + +AIScoring_MirrorMove: ; 3895b + ld a, [LastEnemyCounterMove] + and a + jr nz, .asm_38968 + + call AICompareSpeed + + ret nc + jp AIDiscourageMove + + +.asm_38968 + push hl + ld hl, Table_0x39301 + ld de, 1 + call IsInArray + + pop hl + ret nc + call Function_0x39527 + + ret c + dec [hl] + call AICompareSpeed + + ret nc + call RNG + + cp $19 + ret c + dec [hl] + ret +; 38985 + + +AIScoring_AccuracyDown: ; 38985 + call AICheckPlayerMaxHP + + jr nc, .asm_389a0 + + call AICheckEnemyHalfHP + + jr nc, .asm_389a0 + + ld a, [PlayerSubStatus5] + bit 0, a + jr nz, .asm_3899d + + call RNG + + cp $b2 + jr nc, .asm_389bf + + +.asm_3899d + dec [hl] + dec [hl] + ret + +.asm_389a0 + call AICheckPlayerQuarterHP + + jr nc, .asm_389bd + + call RNG + + cp $a + jr c, .asm_3899d + + call AICheckPlayerHalfHP + + jr nc, .asm_389b8 + + call Function_0x39521 + + jr c, .asm_3899d + + jr .asm_389bf + + +.asm_389b8 + call Function_0x39527 + + jr c, .asm_389bf + + +.asm_389bd + inc [hl] + inc [hl] + +.asm_389bf + ld a, [PlayerSubStatus5] + bit 0, a + jr nz, .asm_389e6 + + ld a, [PlayerSubStatus4] + bit 7, 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 6, a + jr nz, .asm_3899d + + +.asm_389e4 + inc [hl] + ret + +.asm_389e6 + call RNG + cp $50 + ret c + dec [hl] + dec [hl] + ret + +.asm_389ef + call Function_0x39527 + + ret c + dec [hl] + ret +; 389f5 + + +AIScoring_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 RNG + cp $28 + ret c + dec [hl] + ret + +.asm_38a1b + pop hl + inc [hl] + ret +; 38a1e + + +AIScoring_Bide: ; 38a1e + call AICheckEnemyMaxHP + ret c + call RNG + cp $19 + ret c + inc [hl] + ret +; 38a2a + + +AIScoring_Whirlwind: ; 38a2a + push hl + callab Function0x3484e + ld a, [$c716] + cp $a + pop hl + ret c + inc [hl] + ret +; 38a3a + + +AIScoring_Heal: +AIScoring_MorningSun: +AIScoring_Synthesis: +AIScoring_Moonlight: ; 38a3a + call AICheckEnemyQuarterHP + jr nc, .asm_38a45 + call AICheckEnemyHalfHP + ret nc + inc [hl] + ret + +.asm_38a45 + call RNG + cp $19 + ret c + dec [hl] + dec [hl] + ret +; 38a4e + + +AIScoring_Toxic: +AIScoring_LeechSeed: ; 38a4e + call AICheckPlayerHalfHP + ret c + inc [hl] + ret +; 38a54 + + +AIScoring_LightScreen: +AIScoring_Reflect: ; 38a54 + call AICheckEnemyMaxHP + ret c + call RNG + cp $14 + ret c + inc [hl] + ret +; 38a60 + + +AIScoring_Ohko: ; 38a60 + 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<