From 6f786a2bca64843466316940270005036487d2c9 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Wed, 23 Jul 2014 22:42:04 -0500 Subject: [PATCH 01/13] make a vagrant box to make things easier Maybe a vagrant box will be less work for users. At the moment the Vagrantfile is just pointing to a remote url, but in the future it should contain the actual scripts to construct the box so that the box can be updated as the dependencies in the repository change. --- INSTALL.md | 32 +++++++++++++++++++++++++++++ Vagrantfile | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 Vagrantfile diff --git a/INSTALL.md b/INSTALL.md index ca38695af..12fe3aa03 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,3 +1,35 @@ +# Vagrant + +The simplest way to get pokecrystal to compile is to use Vagrant and +VirtualBox. Follow these steps: + +* [Download and install Vagrant](http://www.vagrantup.com/downloads.html) +* Follow the instructions to [download and install VirtualBox](http://docs-v1.vagrantup.com/v1/docs/getting-started/) +* Run these commands: + + vagrant box add pokecrystal http://diyhpl.us/~bryan/irc/pokecrystal/pokecrystal.box + mkdir vagrantbox + cd vagrantbox + vagrant init pokecrystal + vagrant up + vagrant ssh -c "cd /vagrant && git clone git://github.com/kanzure/pokecrystal.git" + vagrant ssh -c "cd /vagrant/pokecrystal && git submodule init && git submodule update" + vagrant ssh + +Running "vagrant ssh" will give you a shell to type commands into for compiling +the source code. The the "virtualbox" directory on the host appears as a shared +folder inside of the guest virtual machine at "/vagrant". + +To build the project, run these commands in the guest (that is, inside "vagrant +ssh"): + + cd /vagrant/pokecrystal + make + +To make the build work you will need to copy baserom.gbc into the "pokecrystal" +directory inside the "virtualbox" directory on the host machine. Eventually +this will not be required. + # Linux Dependencies: diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 000000000..ef8ee2f03 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,59 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# TODO: insert scripts to build the box instead of trusting the uploaded +# version. The default should be to build the box when running "vagrant up", +# rather than just downloading a pre-existing box. + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + # All Vagrant configuration is done here. The most common configuration + # options are documented and commented below. For a complete reference, + # please see the online documentation at vagrantup.com. + + # Every Vagrant virtual environment requires a box to build off of. + config.vm.box = "pokecrystal" + config.vm.box_url = "http://diyhpl.us/~bryan/irc/pokecrystal/pokecrystal.box" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + config.vm.network "forwarded_port", guest: 80, host: 8650 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + config.vm.network "public_network" + + # If true, then any SSH connections made will enable agent forwarding. + # Default value: false + config.ssh.forward_agent = true + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + config.vm.synced_folder "./", "/vagrant" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + config.vm.provider "virtualbox" do |vb| + # Don't boot with headless mode + vb.gui = false + + # Use VBoxManage to customize the VM. For example to change memory: + vb.customize ["modifyvm", :id, "--memory", "1024"] + end +end From c28be212607ded804539975ae6905f218b73bcca Mon Sep 17 00:00:00 2001 From: IIMarckus Date: Tue, 23 Sep 2014 22:20:27 -0600 Subject: [PATCH 02/13] Use a path argument for find as required by POSIX. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 150e9bb80..b77607436 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ crystal: pokecrystal.gbc clean: rm -f $(roms) $(all_obj) - find -iname '*.tx' -exec rm {} + + find . -iname '*.tx' -exec rm {} + baserom.gbc: ; @echo "Wait! Need baserom.gbc first. Check README and INSTALL for details." && false From df2d027501512bd6311f8d44c21b687e3d1b1f21 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Tue, 21 Oct 2014 13:54:04 +0200 Subject: [PATCH 03/13] Start commenting some AI layers --- battle/ai/scoring.asm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index e7498886f..79afdcd68 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -389,6 +389,9 @@ AIScoring_Smart: ; 386be 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 @@ -413,16 +416,20 @@ AIScoring_LeechHit: ; 387f7 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 the enemy's health is full call AICheckEnemyMaxHP - ret c - call Function39521 +; 80% chance to encourage this move otherwise + call Function39521 ret c dec [hl] ret @@ -544,23 +551,30 @@ AIScoring_LockOn: ; 3881d 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 health is higher than 50% call AICheckEnemyHalfHP jr c, .asm_388c6 +; Do nothing if enemy's health is not higher than 25% call AICheckEnemyQuarterHP ret nc +; If enemy's health is in-between 25% and 50% +; over 90% chance to greatly discourage this move call Random cp 20 ret c From 28097be25ca8054476c6f377ba23d41d79b4c409 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Tue, 21 Oct 2014 14:17:55 +0200 Subject: [PATCH 04/13] Add commentary to some AI layers --- battle/ai/scoring.asm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index 79afdcd68..d495b9808 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -424,7 +424,7 @@ AIScoring_LeechHit: ; 387f7 ; Do nothing if effectiveness is neutral ret z -; Do nothing if the enemy's health is full +; Do nothing if enemy's HP is full call AICheckEnemyMaxHP ret c @@ -565,15 +565,15 @@ AIScoring_Explosion: ; 388a6 jr nz, .asm_388c6 .asm_388b7 -; Greatly discourage this move if enemy's health is higher than 50% +; Greatly discourage this move if enemy's HP is above 50% call AICheckEnemyHalfHP jr c, .asm_388c6 -; Do nothing if enemy's health is not higher than 25% +; Do nothing if enemy's HP is below 25% call AICheckEnemyQuarterHP ret nc -; If enemy's health is in-between 25% and 50% +; If enemy's HP is between 25% and 50%, ; over 90% chance to greatly discourage this move call Random cp 20 @@ -689,13 +689,17 @@ AIScoring_EvasionUp: ; 388d4 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 rasied three or more stages ld a, [PlayerEvaLevel] cp $a - ret c + ret c .asm_38954 call Function39521 @@ -866,6 +870,8 @@ AIScoring_Haze: ; 389f5 AIScoring_Bide: ; 38a1e +; 90% chance to discourage this move unless enemy's HP is full + call AICheckEnemyMaxHP ret c call Random @@ -911,6 +917,8 @@ AIScoring_Moonlight: ; 38a3a AIScoring_Toxic: AIScoring_LeechSeed: ; 38a4e +; Discourage this move if player's HP is below 50% + call AICheckPlayerHalfHP ret c inc [hl] @@ -920,6 +928,7 @@ AIScoring_LeechSeed: ; 38a4e AIScoring_LightScreen: AIScoring_Reflect: ; 38a54 +; Over 90% chance to discourage this move unless enemy's HP is full call AICheckEnemyMaxHP ret c call Random From 44377acb2ae9ffe42d9ac4876c30672739359e5b Mon Sep 17 00:00:00 2001 From: xCrystal Date: Tue, 21 Oct 2014 19:21:13 +0200 Subject: [PATCH 05/13] Rename labels and add more commentary to AI stuff --- battle/ai/scoring.asm | 31 +++++++++++++++++++++------- main.asm | 47 +++++++++++++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index d495b9808..e0009210f 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -1,5 +1,5 @@ AIScoring_RedStatus: ; 38591 -; Don't use status-only moves if the player can't be statused. +; Handle the AI of status-only moves and moves with special effects ld hl, Buffer1 - 1 ld de, EnemyMonMoves @@ -19,15 +19,19 @@ AIScoring_RedStatus: ; 38591 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 Function2c41a + 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 @@ -45,6 +49,7 @@ AIScoring_RedStatus: ; 38591 and a jr nz, .discourage +; Dismiss Safeguard if it's already active ld a, [PlayerScreens] bit SCREENS_SAFEGUARD, a jr z, .checkmove @@ -65,7 +70,9 @@ AIScoring_RedStatus: ; 38591 AIScoring_RedStatMods: ; 385e0 -; Use stat-modifying moves on turn 1. +; 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 @@ -699,7 +706,7 @@ AIScoring_AlwaysHit: ; 38947 ; ...or player's evasion level has been rasied three or more stages ld a, [PlayerEvaLevel] cp $a - ret c + ret c .asm_38954 call Function39521 @@ -929,6 +936,7 @@ AIScoring_LeechSeed: ; 38a4e AIScoring_LightScreen: AIScoring_Reflect: ; 38a54 ; Over 90% chance to discourage this move unless enemy's HP is full + call AICheckEnemyMaxHP ret c call Random @@ -2956,7 +2964,9 @@ AIScoring_Opportunist: ; 39315 AIScoring_Aggressive: ; 39369 -; Use whatever does the most damage. +; Discourage all damaging moves but the one that does the most damage. +; If no damaging move deals damage to the player (immune), +; no move will be discouraged ; Figure out which attack does the most damage and put it in c. ld hl, EnemyMonMoves @@ -2984,6 +2994,7 @@ AIScoring_Aggressive: ; 39369 pop de pop hl +; Update current move if damage is highest so far ld a, [CurDamage + 1] cp e ld a, [CurDamage] @@ -3019,6 +3030,7 @@ AIScoring_Aggressive: ; 39369 cp EnemyMonMovesEnd - EnemyMonMoves + 1 jr z, .done +; Ignore this move if it is the highest damaging one cp c ld a, [de] inc de @@ -3027,15 +3039,17 @@ AIScoring_Aggressive: ; 39369 call AIGetEnemyMove +; Ignore this move if its power is 0 or 1 ld a, [wEnemyMoveStruct + MOVE_POWER] cp 2 jr c, .checkmove2 +; Ignore this move if it is reckless push hl push de push bc ld a, [wEnemyMoveStruct + MOVE_EFFECT] - ld hl, .aggressivemoves + ld hl, .recklessmoves ld de, 1 call IsInArray pop bc @@ -3043,13 +3057,14 @@ AIScoring_Aggressive: ; 39369 pop hl jr c, .checkmove2 +; If we made it this far, discourage this move inc [hl] jr .checkmove2 .done ret -.aggressivemoves +.recklessmoves db EFFECT_EXPLOSION db EFFECT_RAMPAGE db EFFECT_MULTI_HIT @@ -3293,6 +3308,8 @@ AIDiscourageMove: ; 39503 AIGetEnemyMove: ; 39508 +; Load attributes of move a into ram + push hl push de push bc diff --git a/main.asm b/main.asm index 846f75378..98db595d9 100644 --- a/main.asm +++ b/main.asm @@ -41681,11 +41681,13 @@ TrainerClassNames:: ; 2c1ef -Function2c41a: ; 2c41a (b:441a) -; More move AI. +AISpecialEffects: ; 2c41a (b:441a) +; Specific AI for certain move effects +; Return z if the move is a good choice +; Return nz if the move is a bad choice ld a, c ld de, 3 - ld hl, Unknown_2c42c + ld hl, SpecialEffectMoves call IsInArray jp nc, Function2c545 inc hl @@ -41695,7 +41697,7 @@ Function2c41a: ; 2c41a (b:441a) jp [hl] ; 2c42c (b:442c) -Unknown_2c42c: ; 2c42c +SpecialEffectMoves: ; 2c42c dbw EFFECT_DREAM_EATER, Function2c524 dbw EFFECT_HEAL, Function2c539 dbw EFFECT_LIGHT_SCREEN, Function2c487 @@ -47148,7 +47150,7 @@ AIChooseMove: ; 440ce ld a, c cp 16 ; up to 16 scoring layers - jr z, .asm_4415e + jr z, .DecrementScores push bc ld d, $e ; BANK(TrainerAI) @@ -47177,27 +47179,36 @@ AIChooseMove: ; 440ce jr .CheckLayer -.asm_4415e +; Decrement the scores of all moves one by one until one reaches 0 +; If the Pokemon has no moves, the game will loop indefinitely +.DecrementScores ld hl, Buffer1 ld de, EnemyMonMoves ld c, EnemyMonMovesEnd - EnemyMonMoves -.asm_44166 + +.DecrementNextScore ld a, [de] inc de and a - jr z, .asm_4415e + jr z, .DecrementScores + ; We are done whenever a score reaches 0 dec [hl] - jr z, .asm_44174 + jr z, .PickLowestScoreMoves + ; If we just decremented the fourth move's score, go back to the first move inc hl dec c - jr z, .asm_4415e + jr z, .DecrementScores - jr .asm_44166 + jr .DecrementNextScore -.asm_44174 +; In order to avoid bias towards the moves located first in memory, increment the scores +; that were decremented one more time than the rest (in case there was a tie) +; This means that the minimum score will be 1 +.PickLowestScoreMoves ld a, c + .asm_44175 inc [hl] dec hl @@ -47208,11 +47219,15 @@ AIChooseMove: ; 440ce ld hl, Buffer1 ld de, EnemyMonMoves ld c, NUM_MOVES + +; Give a score of 0 to a blank move .asm_44184 ld a, [de] and a jr nz, .asm_44189 - ld [hl], a + ld [hl], a + +; Disregard the move if its score is not 1 .asm_44189 ld a, [hl] dec a @@ -47220,6 +47235,7 @@ AIChooseMove: ; 440ce xor a ld [hli], a jr .asm_44193 + .asm_44191 ld a, [de] ld [hli], a @@ -47228,7 +47244,8 @@ AIChooseMove: ; 440ce dec c jr nz, .asm_44184 -.asm_44197 +; Randomly choose one of the moves with a score of 1 +.ChooseMove ld hl, Buffer1 call Random and 3 @@ -47237,7 +47254,7 @@ AIChooseMove: ; 440ce add hl, bc ld a, [hl] and a - jr z, .asm_44197 + jr z, .ChooseMove ld [CurEnemyMove], a ld a, c From 96a89ffad76f6fb3135400b286e81e2f7aaeb657 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Tue, 21 Oct 2014 20:44:42 +0200 Subject: [PATCH 06/13] More AI commentary --- battle/ai/scoring.asm | 87 +++++++++++++++++++++++++++---------------- main.asm | 14 +++---- 2 files changed, 61 insertions(+), 40 deletions(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index e0009210f..9afe6a6f5 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -1,5 +1,5 @@ AIScoring_RedStatus: ; 38591 -; Handle the AI of status-only moves and moves with special effects +; Handle the AI of status-only moves and moves with special effects. ld hl, Buffer1 - 1 ld de, EnemyMonMoves @@ -49,7 +49,7 @@ AIScoring_RedStatus: ; 38591 and a jr nz, .discourage -; Dismiss Safeguard if it's already active +; Dismiss Safeguard if it's already active. ld a, [PlayerScreens] bit SCREENS_SAFEGUARD, a jr z, .checkmove @@ -70,9 +70,9 @@ AIScoring_RedStatus: ; 38591 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 +; 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 @@ -145,7 +145,10 @@ AIScoring_RedStatMods: ; 385e0 AIScoring_RedSuperEffective: ; 38635 -; Use super-effective moves. +; 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 @@ -234,7 +237,7 @@ AIScoring_RedSuperEffective: ; 38635 AIScoring_Offensive: ; 386a2 -; Discourage non-damaging moves. +; Greatly discourage non-damaging moves. ld hl, Buffer1 - 1 ld de, EnemyMonMoves @@ -396,8 +399,8 @@ AIScoring_Smart: ; 386be 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 +; 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 @@ -423,19 +426,19 @@ AIScoring_LeechHit: ; 387f7 callab Function347c8 pop hl -; 60% chance to discourage this move if not very effective +; 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 +; Do nothing if effectiveness is neutral. ret z -; Do nothing if enemy's HP is full +; Do nothing if enemy's HP is full. call AICheckEnemyMaxHP ret c -; 80% chance to encourage this move otherwise +; 80% chance to encourage this move otherwise. call Function39521 ret c dec [hl] @@ -565,23 +568,23 @@ AIScoring_Explosion: ; 388a6 pop hl jr nc, .asm_388b7 -; ...greatly discourage this move unless this is the player's last Pokemon too +; ...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% +; 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% +; 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 +; over 90% chance to greatly discourage this move. call Random cp 20 ret c @@ -595,8 +598,10 @@ AIScoring_Explosion: ; 388a6 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] @@ -698,12 +703,12 @@ AIScoring_EvasionUp: ; 388d4 AIScoring_AlwaysHit: ; 38947 ; 80% chance to greatly encourage this move if either... -; ...enemy's accuracy level has been lowered three or more stages +; ...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 rasied three or more stages +; ...or player's evasion level has been rasied three or more stages. ld a, [PlayerEvaLevel] cp $a ret c @@ -877,7 +882,7 @@ AIScoring_Haze: ; 389f5 AIScoring_Bide: ; 38a1e -; 90% chance to discourage this move unless enemy's HP is full +; 90% chance to discourage this move unless enemy's HP is full. call AICheckEnemyMaxHP ret c @@ -924,7 +929,7 @@ AIScoring_Moonlight: ; 38a3a AIScoring_Toxic: AIScoring_LeechSeed: ; 38a4e -; Discourage this move if player's HP is below 50% +; Discourage this move if player's HP is below 50%. call AICheckPlayerHalfHP ret c @@ -935,7 +940,7 @@ AIScoring_LeechSeed: ; 38a4e AIScoring_LightScreen: AIScoring_Reflect: ; 38a54 -; Over 90% chance to discourage this move unless enemy's HP is full +; Over 90% chance to discourage this move unless enemy's HP is full. call AICheckEnemyMaxHP ret c @@ -1634,6 +1639,7 @@ AIScoring_PriorityHit: ; 38d5a AIScoring_Thief: ; 38d93 +; Don't use Thief unless it's the only move available. ld a, [hl] add $1e ld [hl], a @@ -2272,24 +2278,32 @@ AIScoring_HiddenPower: ; 3909e push hl ld a, 1 ld [hBattleTurn], a + +; Calculate Hidden Power's type and base power based on enemy's DVs. callab HiddenPowerDamage callab Function347c8 pop hl +; Discourage Hidden Power if not very effective. ld a, [$d265] cp $a jr c, .asm_390c9 - + +; Discourage Hidden Power if its base power is lower than 50. ld a, d cp 50 jr c, .asm_390c9 - + +; Encourage Hidden Power if super-effective. ld a, [$d265] cp $b jr nc, .asm_390c7 - + +; Encourage Hidden Power if its base power is 70. ld a, d - cp 70 + cp 70 + +; Do nothing if none of these conditions meet. ret c .asm_390c7 @@ -2677,6 +2691,7 @@ AICheckEnemyMaxHP: ; 39251 AICheckMaxHP: ; 3925a ; Return carry if hp at de matches max hp at hl. + ld a, [de] inc de cp [hl] @@ -2792,6 +2807,7 @@ AICheckPlayerQuarterHP: ; 392b3 AIHasMove: ; 392ca ; Return carry if the enemy has move b. + push hl ld hl, EnemyMonMoves ld c, EnemyMonMovesEnd - EnemyMonMoves @@ -2882,14 +2898,17 @@ Table_0x39301: ; 39301 AIScoring_Opportunist: ; 39315 -; Don't use stall moves when the player's HP is low. +; Discourage stall moves when the enemy's HP is low. +; Do nothing if enemy's HP is above 50%. call AICheckEnemyHalfHP ret c +; Discourage stall moves if enemy's HP is below 25%. call AICheckEnemyQuarterHP jr nc, .asm_39322 - + +; 50% chance to discourage stall moves if enemy's HP is between 25% and 50%. call Function39527 ret c @@ -3030,7 +3049,7 @@ AIScoring_Aggressive: ; 39369 cp EnemyMonMovesEnd - EnemyMonMoves + 1 jr z, .done -; Ignore this move if it is the highest damaging one +; Ignore this move if it is the highest damaging one. cp c ld a, [de] inc de @@ -3039,12 +3058,14 @@ AIScoring_Aggressive: ; 39369 call AIGetEnemyMove -; Ignore this move if its power is 0 or 1 +; Ignore this move if its power is 0 or 1. +; Moves such as Seismic Toss, Hidden Power, +; Counter and Fissure have a base power of 1. ld a, [wEnemyMoveStruct + MOVE_POWER] cp 2 jr c, .checkmove2 -; Ignore this move if it is reckless +; Ignore this move if it is reckless. push hl push de push bc @@ -3057,7 +3078,7 @@ AIScoring_Aggressive: ; 39369 pop hl jr c, .checkmove2 -; If we made it this far, discourage this move +; If we made it this far, discourage this move. inc [hl] jr .checkmove2 diff --git a/main.asm b/main.asm index 98db595d9..d89d1dc0a 100644 --- a/main.asm +++ b/main.asm @@ -41682,9 +41682,9 @@ TrainerClassNames:: ; 2c1ef AISpecialEffects: ; 2c41a (b:441a) -; Specific AI for certain move effects -; Return z if the move is a good choice -; Return nz if the move is a bad choice +; Specific AI for certain move effects. +; Return z if the move is a good choice. +; Return nz if the move is a bad choice. ld a, c ld de, 3 ld hl, SpecialEffectMoves @@ -47179,8 +47179,8 @@ AIChooseMove: ; 440ce jr .CheckLayer -; Decrement the scores of all moves one by one until one reaches 0 -; If the Pokemon has no moves, the game will loop indefinitely +; Decrement the scores of all moves one by one until one reaches 0. +; If the Pokemon has no moves, the game will loop indefinitely. .DecrementScores ld hl, Buffer1 ld de, EnemyMonMoves @@ -47204,8 +47204,8 @@ AIChooseMove: ; 440ce jr .DecrementNextScore ; In order to avoid bias towards the moves located first in memory, increment the scores -; that were decremented one more time than the rest (in case there was a tie) -; This means that the minimum score will be 1 +; that were decremented one more time than the rest (in case there was a tie). +; This means that the minimum score will be 1. .PickLowestScoreMoves ld a, c From 7cbec0d52a6d4e878db589650686ffb53f0493f3 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 22 Oct 2014 00:28:51 +0200 Subject: [PATCH 07/13] More AI commentary/labels --- battle/ai/scoring.asm | 81 +++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index 9afe6a6f5..db3800474 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -97,7 +97,7 @@ AIScoring_RedStatMods: ; 385e0 jr c, .statup ; cp EFFECT_ATTACK_DOWN - 1 - jr z, .checkmove + jr z, .checkmove ; ignore EFFECT_ALWAYS_HIT cp EFFECT_EVASION_DOWN + 1 jr c, .statdown @@ -107,7 +107,7 @@ AIScoring_RedStatMods: ; 385e0 jr c, .statup ; cp EFFECT_ATTACK_DOWN_2 - 1 - jr z, .checkmove + jr z, .checkmove ; ignore EFFECT_TRANSFROM cp EFFECT_EVASION_DOWN_2 + 1 jr c, .statdown @@ -438,7 +438,7 @@ AIScoring_LeechHit: ; 387f7 call AICheckEnemyMaxHP ret c -; 80% chance to encourage this move otherwise. +; 80% chance to encourage this move otherwise. call Function39521 ret c dec [hl] @@ -703,12 +703,12 @@ AIScoring_EvasionUp: ; 388d4 AIScoring_AlwaysHit: ; 38947 ; 80% chance to greatly encourage this move if either... -; ...enemy's accuracy level has been lowered three or more stages... +; ...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 rasied three or more stages. +; ...or player's evasion level has been raised three or more stages. ld a, [PlayerEvaLevel] cp $a ret c @@ -724,27 +724,36 @@ AIScoring_AlwaysHit: ; 38947 AIScoring_MirrorMove: ; 3895b + +; If the player did not use any move last turn... ld a, [LastEnemyCounterMove] and a jr nz, .asm_38968 - call AICompareSpeed +; ...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, Table_0x39301 + 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 @@ -910,6 +919,10 @@ 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 @@ -953,6 +966,9 @@ AIScoring_Reflect: ; 38a54 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] @@ -1055,13 +1071,17 @@ AIScoring_Unused2B: ; 38a9c AIScoring_Confuse: ; 38adb + +; 90% chance to discourage this move if player's HP is between 25% and 50%. call AICheckPlayerHalfHP ret c call Random cp $19 jr c, .asm_38ae7 inc [hl] + .asm_38ae7 +; Discourage again if player's HP is below 25%. call AICheckPlayerQuarterHP ret c inc [hl] @@ -1100,6 +1120,9 @@ AIScoring_SpDefenseUp2: ; 38aed AIScoring_Fly: ; 38b12 +; Greatly encourage this move if the player is +; flying or underground, and slower than the enemy. + ld a, [PlayerSubStatus3] and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND ret z @@ -1113,6 +1136,8 @@ AIScoring_Fly: ; 38b12 AIScoring_SuperFang: ; 38b20 +; Discourage this move if player's HP is below 25%. + call AICheckPlayerQuarterHP ret c inc [hl] @@ -1121,8 +1146,13 @@ AIScoring_SuperFang: ; 38b20 AIScoring_Paralyze: ; 38b26 + +; 50% chance to discourage this move if player's HP is below 25%. call AICheckPlayerQuarterHP jr nc, .asm_38b3a + +; 80% chance to greatly encourage this move +; if enemy is slower than player and its HP is above 25%. call AICompareSpeed ret c call AICheckEnemyQuarterHP @@ -1162,6 +1192,8 @@ AIScoring_SpeedDownHit: ; 38b40 AIScoring_Substitute: ; 38b5c +; Dismiss this move if enemy's HP is below 50%. + call AICheckEnemyHalfHP ret c jp AIDiscourageMove @@ -1171,6 +1203,8 @@ AIScoring_Substitute: ; 38b5c AIScoring_HyperBeam: ; 38b63 call AICheckEnemyHalfHP jr c, .asm_38b72 + +; 50% chance to encourage this move if enemy's HP is below 25%. call AICheckEnemyQuarterHP ret c call Function39527 @@ -1179,6 +1213,7 @@ AIScoring_HyperBeam: ; 38b63 ret .asm_38b72 +; If enemy's HP is above 50%, discourage this move at random call Random cp 40 ret c @@ -1256,7 +1291,7 @@ AIScoring_Mimic: ; 38ba8 .asm_38bd4 ld a, [LastEnemyCounterMove] push hl - ld hl, Table_0x39301 + ld hl, UsefulMoves ld de, 1 call IsInArray @@ -1640,6 +1675,7 @@ AIScoring_PriorityHit: ; 38d5a AIScoring_Thief: ; 38d93 ; Don't use Thief unless it's the only move available. + ld a, [hl] add $1e ld [hl], a @@ -1695,7 +1731,7 @@ AIScoring_Disable: ; 38dd1 push hl ld a, [LastEnemyCounterMove] - ld hl, Table_0x39301 + ld hl, UsefulMoves ld de, 1 call IsInArray @@ -2641,6 +2677,8 @@ AIScoring_Solarbeam: ; 3920b AIScoring_Thunder: ; 39225 +; 90% chance to discourage this move when it's raining. + ld a, [Weather] cp WEATHER_SUN ret nz @@ -2655,6 +2693,8 @@ AIScoring_Thunder: ; 39225 AICompareSpeed: ; 39233 +; Return carry if enemy is faster than player + push bc ld a, [EnemyMonSpeed + 1] ld b, a @@ -2873,7 +2913,7 @@ AIHasMoveInArray: ; 392e6 ; 39301 -Table_0x39301: ; 39301 +UsefulMoves: ; 39301 db DOUBLE_EDGE db SING db FLAMETHROWER @@ -3034,12 +3074,13 @@ AIScoring_Aggressive: ; 39369 jr .checkmove .gotstrongestmove +; Discourage moves that do less damage unless they're reckless too. + ; Nothing we can do if no attacks did damage. ld a, c and a jr z, .done -; Discourage moves that do less damage unless they're reckless too. ld hl, Buffer1 - 1 ld de, EnemyMonMoves ld b, 0 @@ -3121,7 +3162,7 @@ AIDamageCalc: ; 393e7 AIScoring_Cautious: ; 39418 -; Don't use moves with residual effects after turn 1. +; 90% chance to discourage moves with residual effects after enemy's turn 1. ld a, [EnemyTurnsTaken] and a @@ -3178,7 +3219,7 @@ AIScoring_Cautious: ; 39418 AIScoring_StatusImmunity: ; 39453 -; Don't use status moves that don't affect the player. +; Dismiss status moves that don't affect the player. ld hl, Buffer1 - 1 ld de, EnemyMonMoves @@ -3242,7 +3283,8 @@ AIScoring_StatusImmunity: ; 39453 AIScoring_Risky: ; 394a9 -; Use any move that will KO the opponent. +; Use any move that will KO the target. +; Risky moves will often be an exception (see below). ld hl, Buffer1 - 1 ld de, EnemyMonMoves @@ -3265,19 +3307,20 @@ AIScoring_Risky: ; 394a9 ld a, [wEnemyMoveStruct + MOVE_POWER] and a jr z, .nextmove - -; Don't use risky moves at max hp. + ld a, [wEnemyMoveStruct + MOVE_EFFECT] ld de, 1 ld hl, .riskymoves call IsInArray jr nc, .checkko +; Exclude risky moves if enemy's HP is full. call AICheckEnemyMaxHP jr c, .nextmove +; Otherwise, 80% chance to exclude them. call Random - cp 200 ; 1/5 + cp 200 jr c, .nextmove .checkko From bf60a6b690b2af9edfd8b35634a9bd05513276e1 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 22 Oct 2014 14:47:33 +0200 Subject: [PATCH 08/13] evasionup, accdown, whirlwind, haze --- battle/ai/scoring.asm | 56 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index db3800474..c45db759c 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -612,17 +612,22 @@ AIScoring_DreamEater: ; 388ca 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 @@ -633,21 +638,27 @@ AIScoring_EvasionUp: ; 388d4 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 @@ -655,6 +666,11 @@ AIScoring_EvasionUp: ; 388d4 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 @@ -664,12 +680,14 @@ AIScoring_EvasionUp: ; 388d4 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 @@ -683,6 +701,9 @@ AIScoring_EvasionUp: ; 388d4 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 @@ -691,6 +712,9 @@ AIScoring_EvasionUp: ; 388d4 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 @@ -767,16 +791,21 @@ AIScoring_MirrorMove: ; 3895b 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 @@ -787,20 +816,26 @@ AIScoring_AccuracyDown: ; 38985 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 @@ -809,6 +844,7 @@ AIScoring_AccuracyDown: ; 38985 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 @@ -818,12 +854,14 @@ AIScoring_AccuracyDown: ; 38985 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 @@ -836,6 +874,9 @@ AIScoring_AccuracyDown: ; 38985 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 @@ -844,6 +885,9 @@ AIScoring_AccuracyDown: ; 38985 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 @@ -854,6 +898,8 @@ AIScoring_AccuracyDown: ; 38985 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 @@ -865,6 +911,7 @@ AIScoring_Haze: ; 389f5 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 @@ -883,6 +930,9 @@ AIScoring_Haze: ; 389f5 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] @@ -904,6 +954,10 @@ AIScoring_Bide: ; 38a1e 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] From bb9818e3c34bf0e413e67bdf6e0fc0fd17476a7c Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 22 Oct 2014 17:36:42 +0200 Subject: [PATCH 09/13] More AI commentary/labels --- battle/ai/scoring.asm | 99 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 18 deletions(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index c45db759c..f12da12aa 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -70,8 +70,8 @@ AIScoring_RedStatus: ; 38591 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. +; 50% chance to greatly encourage stat-up moves during the first turn of enemy's Pokemon. +; 50% chance to greatly encourage stat-down moves during the first turn of player's Pokemon. ; Almost 90% chance to greatly discourage stat-modifying moves otherwise. ld hl, Buffer1 - 1 @@ -561,6 +561,7 @@ AIScoring_LockOn: ; 3881d AIScoring_Explosion: ; 388a6 +; Selfdestruct, Explosion ; Unless this is the enemy's last Pokemon... push hl @@ -954,14 +955,16 @@ AIScoring_Bide: ; 38a1e AIScoring_Whirlwind: ; 38a2a +; Whirlwind, Roar. + ; 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. +; Consider player's type(s) if its moves are unknown. push hl callab Function3484e ld a, [$c716] - cp $a + cp 10 ; neutral pop hl ret c inc [hl] @@ -1020,7 +1023,7 @@ AIScoring_Reflect: ; 38a54 AIScoring_Ohko: ; 38a60 -; Dismiss this move if player's level is higher than enemy's level +; 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] @@ -1036,6 +1039,8 @@ AIScoring_Ohko: ; 38a60 AIScoring_Bind: ; 38a71 +; Bind, Wrap, Fire Spin, Clamp + ld a, [$c730] and a jr nz, .asm_38a8b @@ -1144,15 +1149,20 @@ AIScoring_Confuse: ; 38adb AIScoring_SpDefenseUp2: ; 38aed + +; Discourage this move if enemy's HP is lower than 50%. call AICheckEnemyHalfHP jr nc, .asm_38b10 +; Discourage this move if enemy's special defense level is higher than +3. ld a, [EnemySDefLevel] cp $b jr nc, .asm_38b10 + +; 80% chance to greatly encourage this move if +; enemy's Special Defense level is lower than +2, and the player is of a special type. cp $9 ret nc - ld a, [BattleMonType1] cp SPECIAL jr nc, .asm_38b09 @@ -1226,6 +1236,13 @@ AIScoring_Paralyze: ; 38b26 AIScoring_SpeedDownHit: ; 38b40 +; Icy Wind + +; Almost 90% chance to greatly encourage this move if the following conditions all meet: +; Enemy's HP is higher than 25%. +; It's the first turn of player's Pokemon. +; Player is faster than enemy. + ld a, [wEnemyMoveStruct + MOVE_ANIM] cp ICY_WIND ret nz @@ -1284,11 +1301,12 @@ AIScoring_Rage: ; 38b7f bit SUBSTATUS_RAGE, a jr z, .asm_38b9b +; If enemy's Rage is building, 50% chance to encourage this move. call Function39527 jr c, .asm_38b8c - dec [hl] +; Encourage this move based on Rage's counter. .asm_38b8c ld a, [$c72c] cp $2 @@ -1301,9 +1319,11 @@ AIScoring_Rage: ; 38b7f ret .asm_38b9b +; If enemy's Rage is not building, discourage this move if enemy's HP is below 50%. call AICheckEnemyHalfHP jr nc, .asm_38ba6 +; 50% chance to encourage this move otherwise. call Function39521 ret nc dec [hl] @@ -1463,7 +1483,7 @@ AIScoring_Encore: ; 38c3b .asm_38c68 push hl ld a, [LastEnemyCounterMove] - ld hl, .table_38c85 + ld hl, .encoremoves ld de, 1 call IsInArray pop hl @@ -1483,7 +1503,7 @@ AIScoring_Encore: ; 38c3b inc [hl] ret -.table_38c85 +.encoremoves db SWORDS_DANCE db WHIRLWIND db LEER @@ -1519,6 +1539,8 @@ AIScoring_Encore: ; 38c3b AIScoring_PainSplit: ; 38ca4 +; Discourage this move if [enemy's current HP * 2 > player's current HP]. + push hl ld hl, EnemyMonHP ld b, [hl] @@ -1540,6 +1562,9 @@ AIScoring_PainSplit: ; 38ca4 AIScoring_Snore: AIScoring_SleepTalk: ; 38cba +; Greatly encourage this move if enemy is fast asleep. +; Greatly discourage this move otherwise. + ld a, [EnemyMonStatus] and $7 cp $1 @@ -1559,6 +1584,9 @@ AIScoring_SleepTalk: ; 38cba AIScoring_DefrostOpponent: ; 38ccb +; Greatly encourage this move if enemy is frozen. +; No move has EFFECT_DEFROST_OPPONENT, so this layer is unused. + ld a, [EnemyMonStatus] and $20 ret z @@ -1635,6 +1663,8 @@ Function_0x38d16; 38d16 AIScoring_DestinyBond: AIScoring_Reversal: AIScoring_SkullBash: ; 38d19 +; Discourage this move if enemy's HP is above 25%. + call AICheckEnemyQuarterHP ret nc inc [hl] @@ -1643,6 +1673,10 @@ AIScoring_SkullBash: ; 38d19 AIScoring_HealBell: ; 38d1f +; Dismiss this move if none of the opponent's Pokemon is statused. +; Encourage this move if the enemy is statused. +; 50% chance to greatly encourage this move if the enemy is fast asleep or frozen. + push hl ld a, [OTPartyCount] ld b, a @@ -1658,8 +1692,8 @@ AIScoring_HealBell: ; 38d1f dec hl dec hl - dec hl - ld a, [hl] + dec hl ; status + ld a, [hl] or c ld c, a @@ -1698,12 +1732,14 @@ AIScoring_HealBell: ; 38d1f AIScoring_PriorityHit: ; 38d5a call AICompareSpeed - ret c + +; Dismiss this move if the player is flying or underground. ld a, [PlayerSubStatus3] and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND jp nz, AIDiscourageMove +; Greatly encourage this move if it will KO the player. ld a, $1 ld [hBattleTurn], a push hl @@ -1821,18 +1857,22 @@ AIScoring_MeanLook: ; 38dfb pop hl jp z, AIDiscourageMove +; 80% chance to greatly encourage this move if the enemy is badly poisoned (weird). ld a, [EnemySubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_38e26 +; 80% chance to greatly encourage this move if the player is either +; in love, identified, stuck in Rollout, or has a Nightmare. ld a, [PlayerSubStatus1] and 1< Date: Wed, 22 Oct 2014 23:08:51 +0200 Subject: [PATCH 10/13] More AI commentary/labels --- battle/ai/scoring.asm | 217 +++++++++++++++++++++++++++--------------- 1 file changed, 138 insertions(+), 79 deletions(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index f12da12aa..bf4b660e5 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -126,7 +126,7 @@ AIScoring_RedStatMods: ; 385e0 jr nz, .discourage .encourage - call Function39527 + call AIRandom2 jr c, .checkmove dec [hl] @@ -411,7 +411,7 @@ AIScoring_Sleep: ; 387e3 ret nc .asm_387f0 - call Function39527 + call AIRandom2 ret c dec [hl] dec [hl] @@ -439,7 +439,7 @@ AIScoring_LeechHit: ; 387f7 ret c ; 80% chance to encourage this move otherwise. - call Function39521 + call AIRandom1 ret c dec [hl] ret @@ -521,7 +521,7 @@ AIScoring_LockOn: ; 3881d .asm_3887a pop hl - call Function39527 + call AIRandom2 ret c dec [hl] @@ -654,13 +654,13 @@ AIScoring_EvasionUp: ; 388d4 jr nc, .asm_3890a ; If enemy's HP is above 50% but not full, 20% chance to greatly encourage this move. - call Function39521 + call AIRandom1 jr c, .asm_388ef jr .asm_38911 .asm_3890a ; ...50% chance to greatly discourage this move. - call Function39527 + call AIRandom2 jr c, .asm_38911 .asm_3890f @@ -717,7 +717,7 @@ AIScoring_EvasionUp: ; 388d4 ; 50% chance to encourage this move. ; This would partly counter any previous discouragement. .asm_38941 - call Function39527 + call AIRandom2 ret c dec [hl] @@ -739,7 +739,7 @@ AIScoring_AlwaysHit: ; 38947 ret c .asm_38954 - call Function39521 + call AIRandom1 ret c dec [hl] @@ -774,7 +774,7 @@ AIScoring_MirrorMove: ; 3895b ret nc ; If he did, 50% chance to encourage this move... - call Function39527 + call AIRandom2 ret c dec [hl] @@ -832,13 +832,13 @@ AIScoring_AccuracyDown: ; 38985 jr nc, .asm_389b8 ; If player's HP is above 50% but not full, 20% chance to greatly encourage this move. - call Function39521 + call AIRandom1 jr c, .asm_3899d jr .asm_389bf ; ...50% chance to greatly discourage this move. .asm_389b8 - call Function39527 + call AIRandom2 jr c, .asm_389bf .asm_389bd @@ -890,7 +890,7 @@ AIScoring_AccuracyDown: ; 38985 ; 50% chance to encourage this move. ; This would partly counter any previous discouragement. .asm_389ef - call Function39527 + call AIRandom2 ret c dec [hl] @@ -1024,7 +1024,7 @@ AIScoring_Reflect: ; 38a54 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%. +; Else, discourage this move is player's HP is below 50%. ld a, [BattleMonLevel] ld b, a @@ -1041,10 +1041,13 @@ AIScoring_Ohko: ; 38a60 AIScoring_Bind: ; 38a71 ; Bind, Wrap, Fire Spin, Clamp +; 50% chance to discourage this move if the player is already trapped. ld a, [$c730] and a jr nz, .asm_38a8b +; 50% chance to greatly encourage this move if player is either +; badly poisoned, in love, identified, stuck in Rollout, or has a Nightmare. ld a, [PlayerSubStatus5] bit SUBSTATUS_TOXIC, a jr nz, .asm_38a91 @@ -1053,12 +1056,14 @@ AIScoring_Bind: ; 38a71 and 1<