Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e676337

Browse files
committedJan 5, 2024
AI Improvements
This fixes some of the issues with the current AI system to make them better. In short: - Most Trainers should correctly recognise when a move is not very effective, and not use it. If they have a supereffective move and a regular-effective move, they will slightly prioritise the supereffective one, but not always use it like in regular RBY. This prevents the Lorelei softlock, for example. - Trainers won't attempt to set status effects on Pokemon that already have one, won't try recovering at full health, and won't attempt to set up multiple Reflects or Light Screen - Certain high-level trainers will recognise when a Pokemon does not have a status, and will try to inflict one if so. This makes Agatha's, Erika's and Koga's team types much more effective. - Youngsters and Cue Balls no longer pick moves randomly and will actually give it some thought - Brock and the Engineers now recognize type effectiveness, Students do not given how early they're encountered. - General improvements to move choices for all Gym Leaders, E4 and Shinjuku Jacky. We're almost done.
1 parent a486ec7 commit e676337

File tree

6 files changed

+153
-123
lines changed

6 files changed

+153
-123
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ and more!
260260

261261
Known Bugs
262262
====
263-
- The new AI (possibly bugged?) behaves quite oddly, such as using Recover at full HP, spamming status-inflicting moves like Lovely Kiss, neglecting supereffective moves, setting up multiple Reflects, etc.
263+
- Currently testing...
264264

265265
Evolution Methods for new Pokemon
266266
====

‎data/predef_pointers.asm

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PredefPointers::
5050
add_predef UpdateHPBar
5151
add_predef HPBarLength
5252
add_predef Diploma_TextBoxBorder
53-
; add_predef DoubleOrHalveSelectedStats
53+
add_predef DoubleOrHalveSelectedStats
5454
add_predef ShowPokedexMenu
5555
add_predef EvolutionAfterBattle
5656
add_predef SaveSAVtoSRAM0

‎data/trainers/move_choices.asm

+25-25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENDM
99
; move choice modification methods that are applied for each trainer class
1010
TrainerClassMoveChoiceModifications:
1111
list_start TrainerClassMoveChoiceModifications
12-
move_choices ; YOUNGSTER
12+
move_choices 1 ; YOUNGSTER
1313
move_choices 1 ; BUG CATCHER
1414
move_choices 1 ; LASS
1515
move_choices 1, 3 ; SAILOR
@@ -20,10 +20,10 @@ TrainerClassMoveChoiceModifications:
2020
move_choices 1 ; HIKER
2121
move_choices 1 ; BIKER
2222
move_choices 1, 3 ; BURGLAR
23-
move_choices 1 ; ENGINEER
23+
move_choices 1, 3 ; ENGINEER
2424
move_choices 1, 3 ; FISHER
2525
move_choices 1, 3 ; SWIMMER
26-
move_choices ; CUE_BALL
26+
move_choices 1 ; CUE_BALL
2727
move_choices 1 ; GAMBLER
2828
move_choices 1, 3 ; BEAUTY
2929
move_choices 1, 2 ; PSYCHIC_TR
@@ -33,32 +33,32 @@ TrainerClassMoveChoiceModifications:
3333
move_choices 1 ; BIRD_KEEPER
3434
move_choices 1 ; BLACKBELT
3535
move_choices 1 ; RIVAL1
36-
move_choices 1, 3 ; PROF_OAK
37-
move_choices 1, 2 ; CHIEF
38-
move_choices 1, 2 ; SCIENTIST
39-
move_choices 1, 3 ; GIOVANNI
36+
move_choices 1, 2, 3, 4 ; PROF_OAK
37+
move_choices 1, 2, 3, 4 ; CHIEF
38+
move_choices 1, 2, 4 ; SCIENTIST
39+
move_choices 1, 2, 3 ; GIOVANNI
4040
move_choices 1 ; ROCKET
41-
move_choices 1, 3 ; COOLTRAINER_M
42-
move_choices 1, 3 ; COOLTRAINER_F
43-
move_choices 1 ; BRUNO
44-
move_choices 1 ; BROCK
45-
move_choices 1, 3 ; MISTY
46-
move_choices 1, 3 ; LT_SURGE
47-
move_choices 1, 3 ; ERIKA
48-
move_choices 1, 3 ; KOGA
49-
move_choices 1, 3 ; BLAINE
50-
move_choices 1, 3 ; SABRINA
41+
move_choices 1, 3, 4 ; COOLTRAINER_M
42+
move_choices 1, 3, 4 ; COOLTRAINER_F
43+
move_choices 1, 2, 3 ; BRUNO
44+
move_choices 1, 3 ; BROCK
45+
move_choices 1, 3, 4 ; MISTY
46+
move_choices 1, 2, 3 ; LT_SURGE
47+
move_choices 1, 3, 4 ; ERIKA
48+
move_choices 1, 3, 4 ; KOGA
49+
move_choices 1, 2, 3 ; BLAINE
50+
move_choices 1, 3, 4 ; SABRINA
5151
move_choices 1, 2 ; GENTLEMAN
5252
move_choices 1, 3 ; RIVAL2
53-
move_choices 1, 3 ; RIVAL3
54-
move_choices 1, 2, 3 ; LORELEI
53+
move_choices 1, 2, 3, 4 ; RIVAL3
54+
move_choices 1, 2, 3, 4 ; LORELEI
5555
move_choices 1 ; CHANNELER
56-
move_choices 1 ; AGATHA
57-
move_choices 1, 3 ; LANCE
58-
move_choices 1, 3, ; YUJIROU, was UNUSED_JUGGLER
59-
move_choices 1, 3, ; STUDENT
56+
move_choices 1, 2, 3, 4 ; AGATHA
57+
move_choices 1, 2, 3, 4 ; LANCE
58+
move_choices 1, 3, ; YUJIROU
59+
move_choices 1 ; STUDENT
6060
move_choices 1, 3, ; FIREFIGHTER
61-
move_choices 1, 3, ; KOICHI
62-
move_choices 1, 3, ; JACK
61+
move_choices 1, 2, 3 ; KOICHI
62+
move_choices 1, 2, 3, 4 ; JACK
6363
move_choices 1, 3, ; JESSIE_JAMES
6464
assert_list_length NUM_TRAINERS

‎engine/battle/trainer_ai.asm

+73-64
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ AIEnemyTrainerChooseMoves:
77
ld [hli], a ; move 2
88
ld [hli], a ; move 3
99
ld [hl], a ; move 4
10+
11+
;;;;;;;;;; shinpokerednote: ADDED: make a backup buffer
12+
push hl
13+
ld a, $ff
14+
inc hl
15+
ld [hli], a ;backup 1
16+
ld [hli], a ;backup 2
17+
ld [hli], a ;backup 3
18+
ld [hl], a ;backup 4
19+
pop hl
20+
;;;;;;;;;;
21+
1022
ld a, [wEnemyDisabledMove] ; forbid disabled move (if any)
1123
swap a
1224
and $f
@@ -52,6 +64,11 @@ AIEnemyTrainerChooseMoves:
5264
ld de, .nextMoveChoiceModification ; set return address
5365
push de
5466
jp hl ; execute modification function
67+
.loopFindMinimumEntries_backupfirst ;shinpokerednote: ADDED: make a backup of the scores
68+
ld hl, wBuffer ; temp move selection array
69+
ld de, wBuffer + NUM_MOVES ;backup buffer
70+
ld bc, NUM_MOVES
71+
rst _CopyData
5572
.loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero
5673
ld hl, wBuffer ; temp move selection array
5774
ld de, wEnemyMonMoves ; enemy moves
@@ -466,10 +483,8 @@ AIMoveChoiceModification3:
466483
jr c, .notEffectiveMove
467484
;ld a, [wEnemyMoveEffect]
468485
; check for reasons not to use a super effective move here
469-
470486
dec [hl] ; slightly encourage this super effective move
471487
.checkSpecificEffects ; we'll further encourage certain moves
472-
call EncouragePriorityIfSlow
473488
call EncourageDrainingMoveIfLowHealth
474489
jr .nextMove
475490
.notEffectiveMove ; discourages non-effective moves if better moves are available
@@ -479,7 +494,7 @@ AIMoveChoiceModification3:
479494
ld a, [wEnemyMoveType]
480495
ld d, a
481496
ld hl, wEnemyMonMoves ; enemy moves
482-
ld b, NUM_MOVES + 1
497+
ld bc, NUM_MOVES + 1
483498
ld c, $0
484499
.loopMoves
485500
dec b
@@ -543,18 +558,6 @@ CompareSpeed:
543558
ret
544559
;;;;;;;;;;
545560

546-
; PureRGBnote: ADDED: encourages priority moves if the enemy's pokemon is slower than the player's and the move is neutral or super effective.
547-
; BUT this effect is only applied after you have the soulbadge to prevent priority moves from being spammed early game.
548-
; Applies to trainers that use AI subroutine 3
549-
EncouragePriorityIfSlow:
550-
ld a, [wObtainedBadges]
551-
bit BIT_SOULBADGE, a
552-
ret z
553-
call CompareSpeed
554-
ret nc
555-
dec [hl] ; encourage the move if it's a priority move and the pokemon is slower
556-
ret
557-
558561
; PureRGBnote: ADDED: if the opponent has less than 1/2 health they will prefer healing moves if they use AI subroutine 3
559562
EncourageDrainingMoveIfLowHealth:
560563
ld a, [wEnemyMoveEffect]
@@ -576,11 +579,11 @@ AIMoveChoiceModification4:
576579
ld b, NUM_MOVES + 1
577580
.nextMove
578581
dec b
579-
jr z, .done ; processed all 4 moves
582+
ret z ; processed all 4 moves
580583
inc hl
581584
ld a, [de]
582585
and a
583-
jr z, .done ; no more moves in move set
586+
ret z ; no more moves in move set
584587
inc de
585588
call ReadMove
586589
ld a, [wEnemyMoveEffect]
@@ -626,8 +629,7 @@ AIMoveChoiceModification4:
626629
jr z, .nextMove ; if the AI thinks the player IS NOT asleep before they switch, we shouldn't encourage based on the new mon's status
627630
ld a, [wBattleMonStatus]
628631
and SLP_MASK
629-
jr nz, .preferMoveEvenMore ; heavier favor for dream eater if the opponent is asleep
630-
jr .nextMove
632+
jr z, .nextMove
631633
.preferMoveEvenMore
632634
dec [hl]
633635
jr .preferMove
@@ -676,9 +678,6 @@ TrainerAI:
676678
ld a, [wIsInBattle]
677679
dec a
678680
ret z ; if not a trainer, we're done here
679-
ld a, [wCurMap]
680-
cp BATTLE_TENT
681-
ret z ; if we are in battle tent, we are done
682681
ld a, [wLinkState]
683682
cp LINK_STATE_BATTLING
684683
ret z ; if in a link battle, we're done as well
@@ -732,12 +731,9 @@ BlackbeltAI:
732731
jp AIUseXAttack
733732

734733
GiovanniAI:
735-
cp 20 percent + 1
734+
cp 25 percent + 1
736735
ret nc
737-
ld a, [wEnemyBattleStatus2]
738-
bit GETTING_PUMPED, a
739-
ret nz
740-
jp AIUseDireHit
736+
jp AIUseXAttack ; Used to use a Guard Spec. This will make the item use have a proper impact - healing doesn't feel right for a trainer fixated on strength.
741737

742738
CooltrainerMAI:
743739
cp 20 percent + 1
@@ -765,41 +761,46 @@ BrockAI:
765761
jp AIUseFullHeal
766762

767763
MistyAI:
768-
cp 20 percent + 1
764+
cp 25 percent + 1
769765
ret nc
770-
jp AIUseXDefend
766+
ld a, 10
767+
call AICheckIfHPBelowFraction
768+
ret nc
769+
jp AIUseSuperPotion ; Replicates Starmie using Recover. Unlike other trainers that heal, Misty will do this 26% of the time instead of 51%.
771770

772771
LtSurgeAI:
773-
cp 10 percent + 1
772+
cp 20 percent + 1
774773
ret nc
775-
jp AIUseXSpeed
774+
jp AIUseXSpecial
776775

777776
ErikaAI:
778777
cp 50 percent + 1
779778
ret nc
780-
ld a, 5
779+
ld a, 10
781780
call AICheckIfHPBelowFraction
782781
ret nc
783782
jp AIUseSuperPotion
784783

785784
KogaAI:
786-
cp 10 percent + 1
785+
cp 50 percent + 1
787786
ret nc
788-
jp AIUseXAttack
787+
ld a, 10
788+
call AICheckIfHPBelowFraction
789+
ret nc
790+
jp AIUseSuperPotion ; Koga is weird - I don't think anything fits. X Attack is certainly not the move though...
789791

790-
BlaineAI: ;blaine needs to check HP. this was an oversight
791-
cp 40 percent + 1
792-
jr nc, .blainereturn
793-
ld a, 2
794-
call AICheckIfHPBelowFraction
795-
jp c, AIUseSuperPotion
796-
.blainereturn
797-
ret
792+
BlaineAI:
793+
cp 25 percent + 1
794+
ret nc
795+
ld a, 10
796+
call AICheckIfHPBelowFraction
797+
ret nc ; this fixes the super potion thing - PvK
798+
jp AIUseHyperPotion ; Instead of a Super Potion though, let's give him this. More impactful for the sixth gym while staying true to the meme that everyone knows Gen 1 Blaine for.
798799

799800
SabrinaAI:
800801
cp 25 percent + 1
801802
ret nc
802-
ld a, 5
803+
ld a, 10
803804
call AICheckIfHPBelowFraction
804805
ret nc
805806
jp AIUseHyperPotion
@@ -810,7 +811,7 @@ Rival2AI:
810811
ld a, 5
811812
call AICheckIfHPBelowFraction
812813
ret nc
813-
jp AIUseHyperPotion
814+
jp AIUseSuperPotion
814815

815816
Rival3AI:
816817
cp 40 percent - 1
@@ -821,39 +822,47 @@ Rival3AI:
821822
jp AIUseFullRestore
822823

823824
LoreleiAI:
824-
cp 50 percent + 1
825+
cp 15 percent + 1
826+
ret nc
827+
jp AIUseXSpecial
828+
cp 40 percent + 1
825829
ret nc
826830
ld a, 5
827831
call AICheckIfHPBelowFraction
828832
ret nc
829-
jp AIUseHyperPotion
833+
jp AIUseFullRestore
830834

831835
BrunoAI:
832-
;cp 10 percent + 1
833-
;ret nc
834-
;jp AIUseXDefend
835-
cp 30 percent + 1
836-
jr nc, .brunoreturn
836+
cp 15 percent + 1
837+
ret nc
838+
jp AIUseXAttack
839+
cp 40 percent + 1
840+
ret nc
837841
ld a, 5
838842
call AICheckIfHPBelowFraction
839-
jp c, AIUseHyperPotion
840-
.brunoreturn
841-
ret
843+
ret nc
844+
jp AIUseFullRestore
842845

843846
AgathaAI:
844847
cp 8 percent
845848
jp c, AISwitchIfEnoughMons
846-
cp 50 percent + 1
849+
cp 15 percent + 1
850+
ret nc
851+
jp AIUseXAccuracy ; hahahahahahahaha
852+
cp 40 percent + 1
847853
ret nc
848-
ld a, 4
854+
ld a, 5
849855
call AICheckIfHPBelowFraction
850856
ret nc
851-
jp AIUseHyperPotion
857+
jp AIUseFullRestore
852858

853859
LanceAI:
860+
cp 15 percent + 1
861+
ret nc
862+
jp AIUseXSpecial
854863
cp 50 percent + 1
855864
ret nc
856-
ld a, 5
865+
ld a, 10
857866
call AICheckIfHPBelowFraction
858867
ret nc
859868
jp AIUseFullRestore
@@ -1087,12 +1096,12 @@ AICureStatus: ;shinpokerednote: CHANGED: modified to be more robust and also und
10871096
res BADLY_POISONED, [hl] ;clear toxic bit
10881097
ret
10891098

1090-
;AIUseXAccuracy: ; unused
1091-
; call AIPlayRestoringSFX
1092-
; ld hl, wEnemyBattleStatus2
1093-
; set 0, [hl]
1094-
; ld a, X_ACCURACY
1095-
; jp AIPrintItemUse
1099+
AIUseXAccuracy:
1100+
call AIPlayRestoringSFX
1101+
ld hl, wEnemyBattleStatus2
1102+
set 0, [hl]
1103+
ld a, X_ACCURACY
1104+
jp AIPrintItemUse
10961105

10971106
;AIUseGuardSpec: ; PureRGBnote: CHANGED: now unused
10981107
; call AIPlayRestoringSFX
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.