summaryrefslogtreecommitdiff
path: root/engine/battle
diff options
context:
space:
mode:
Diffstat (limited to 'engine/battle')
-rw-r--r--engine/battle/ai/items.asm190
-rw-r--r--[-rwxr-xr-x]engine/battle/ai/move.asm10
-rw-r--r--[-rwxr-xr-x]engine/battle/ai/redundant.asm58
-rw-r--r--engine/battle/ai/scoring.asm595
-rw-r--r--[-rwxr-xr-x]engine/battle/ai/switch.asm38
-rw-r--r--[-rwxr-xr-x]engine/battle/anim_hp_bar.asm41
-rw-r--r--engine/battle/battle_transition.asm224
-rw-r--r--engine/battle/battlestart_copytilemapatonce.asm2
-rw-r--r--engine/battle/check_battle_scene.asm (renamed from engine/battle/checkbattlescene.asm)2
-rw-r--r--engine/battle/consume_held_item.asm (renamed from engine/battle/consumehelditem.asm)31
-rw-r--r--engine/battle/core.asm1141
-rw-r--r--engine/battle/effect_commands.asm3873
-rw-r--r--engine/battle/hidden_power.asm5
-rw-r--r--[-rwxr-xr-x]engine/battle/link_result.asm24
-rw-r--r--[-rwxr-xr-x]engine/battle/menu.asm57
-rw-r--r--engine/battle/misc.asm63
-rw-r--r--[-rwxr-xr-x]engine/battle/move_effects/attract.asm (renamed from engine/battle/effect_commands/attract.asm)9
-rw-r--r--engine/battle/move_effects/baton_pass.asm217
-rw-r--r--engine/battle/move_effects/beat_up.asm224
-rw-r--r--engine/battle/move_effects/belly_drum.asm34
-rw-r--r--engine/battle/move_effects/bide.asm100
-rw-r--r--engine/battle/move_effects/conversion.asm96
-rw-r--r--engine/battle/move_effects/conversion2.asm64
-rw-r--r--engine/battle/move_effects/counter.asm59
-rw-r--r--engine/battle/move_effects/curse.asm (renamed from engine/battle/effect_commands/curse.asm)6
-rw-r--r--engine/battle/move_effects/destiny_bond.asm9
-rw-r--r--engine/battle/move_effects/disable.asm72
-rw-r--r--engine/battle/move_effects/encore.asm120
-rw-r--r--engine/battle/move_effects/endure.asm (renamed from engine/battle/effect_commands/endure.asm)3
-rw-r--r--engine/battle/move_effects/false_swipe.asm48
-rw-r--r--engine/battle/move_effects/focus_energy.asm15
-rw-r--r--engine/battle/move_effects/foresight.asm (renamed from engine/battle/effect_commands/foresight.asm)5
-rw-r--r--engine/battle/move_effects/frustration.asm27
-rw-r--r--engine/battle/move_effects/fury_cutter.asm55
-rw-r--r--engine/battle/move_effects/future_sight.asm81
-rw-r--r--engine/battle/move_effects/heal_bell.asm34
-rw-r--r--engine/battle/move_effects/hidden_power.asm8
-rw-r--r--engine/battle/move_effects/leech_seed.asm40
-rw-r--r--engine/battle/move_effects/lock_on.asm21
-rw-r--r--engine/battle/move_effects/magnitude.asm29
-rw-r--r--engine/battle/move_effects/metronome.asm (renamed from engine/battle/effect_commands/metronome.asm)24
-rw-r--r--engine/battle/move_effects/mimic.asm50
-rw-r--r--engine/battle/move_effects/mirror_coat.asm60
-rw-r--r--engine/battle/move_effects/mirror_move.asm (renamed from engine/battle/effect_commands/mirror_move.asm)3
-rw-r--r--engine/battle/move_effects/mist.asm15
-rw-r--r--engine/battle/move_effects/nightmare.asm (renamed from engine/battle/effect_commands/nightmare.asm)3
-rw-r--r--engine/battle/move_effects/pain_split.asm93
-rw-r--r--engine/battle/move_effects/pay_day.asm26
-rw-r--r--engine/battle/move_effects/perish_song.asm (renamed from engine/battle/effect_commands/perish_song.asm)4
-rw-r--r--[-rwxr-xr-x]engine/battle/move_effects/present.asm (renamed from engine/battle/effect_commands/present.asm)27
-rw-r--r--engine/battle/move_effects/protect.asm (renamed from engine/battle/effect_commands/protect.asm)9
-rw-r--r--engine/battle/move_effects/psych_up.asm49
-rw-r--r--engine/battle/move_effects/pursuit.asm24
-rw-r--r--engine/battle/move_effects/rage.asm6
-rw-r--r--engine/battle/move_effects/rain_dance.asm9
-rw-r--r--engine/battle/move_effects/rapid_spin.asm36
-rw-r--r--engine/battle/move_effects/return.asm25
-rw-r--r--engine/battle/move_effects/rollout.asm (renamed from engine/battle/effect_commands/rollout.asm)8
-rw-r--r--engine/battle/move_effects/safeguard.asm23
-rw-r--r--engine/battle/move_effects/sandstorm.asm (renamed from engine/battle/effect_commands/sandstorm.asm)3
-rw-r--r--engine/battle/move_effects/selfdestruct.asm29
-rw-r--r--engine/battle/move_effects/sketch.asm117
-rw-r--r--engine/battle/move_effects/sleep_talk.asm143
-rw-r--r--engine/battle/move_effects/snore.asm11
-rw-r--r--engine/battle/move_effects/spikes.asm (renamed from engine/battle/effect_commands/spikes.asm)5
-rw-r--r--engine/battle/move_effects/spite.asm86
-rw-r--r--engine/battle/move_effects/splash.asm4
-rw-r--r--engine/battle/move_effects/substitute.asm88
-rw-r--r--engine/battle/move_effects/sunny_day.asm9
-rw-r--r--engine/battle/move_effects/teleport.asm89
-rw-r--r--engine/battle/move_effects/thief.asm (renamed from engine/battle/effect_commands/thief.asm)6
-rw-r--r--engine/battle/move_effects/thunder.asm18
-rw-r--r--[-rwxr-xr-x]engine/battle/move_effects/transform.asm (renamed from engine/battle/effect_commands/transform.asm)4
-rw-r--r--engine/battle/move_effects/triple_kick.asm34
-rw-r--r--engine/battle/read_trainer_attributes.asm8
-rw-r--r--engine/battle/read_trainer_dvs.asm5
-rw-r--r--[-rwxr-xr-x]engine/battle/read_trainer_party.asm36
-rw-r--r--engine/battle/returntobattle_useball.asm4
-rw-r--r--[-rwxr-xr-x]engine/battle/sliding_intro.asm18
-rw-r--r--engine/battle/start_battle.asm10
-rw-r--r--[-rwxr-xr-x]engine/battle/trainer_huds.asm45
-rw-r--r--engine/battle/unreferenced_getgen1trainerclassname.asm21
-rw-r--r--engine/battle/update_battle_huds.asm (renamed from engine/battle/updatebattlehuds.asm)0
-rw-r--r--[-rwxr-xr-x]engine/battle/used_move_text.asm45
84 files changed, 3719 insertions, 5343 deletions
diff --git a/engine/battle/ai/items.asm b/engine/battle/ai/items.asm
index 4d1eea2e8..29bc23b20 100644
--- a/engine/battle/ai/items.asm
+++ b/engine/battle/ai/items.asm
@@ -1,4 +1,4 @@
-AI_SwitchOrTryItem: ; 38000
+AI_SwitchOrTryItem:
and a
ld a, [wBattleMode]
@@ -38,12 +38,11 @@ AI_SwitchOrTryItem: ; 38000
jp nz, SwitchSometimes
; fallthrough
-DontSwitch: ; 38041
+DontSwitch:
call AI_TryItem
ret
-; 38045
-SwitchOften: ; 38045
+SwitchOften:
callfar CheckAbleToSwitch
ld a, [wEnemySwitchMonParam]
and $f0
@@ -52,7 +51,7 @@ SwitchOften: ; 38045
cp $10
jr nz, .not_10
call Random
- cp 1 + 50 percent
+ cp 50 percent + 1
jr c, .switch
jp DontSwitch
.not_10
@@ -60,7 +59,7 @@ SwitchOften: ; 38045
cp $20
jr nz, .not_20
call Random
- cp -1 + 79 percent
+ cp 79 percent - 1
jr c, .switch
jp DontSwitch
.not_20
@@ -74,12 +73,11 @@ SwitchOften: ; 38045
ld a, [wEnemySwitchMonParam]
and $f
inc a
- ; In register 'a' is the number (1-6) of the Pkmn to switch to
+ ; In register 'a' is the number (1-6) of the mon to switch to
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
-; 38083
-SwitchRarely: ; 38083
+SwitchRarely:
callfar CheckAbleToSwitch
ld a, [wEnemySwitchMonParam]
and $f0
@@ -103,7 +101,7 @@ SwitchRarely: ; 38083
; $30
call Random
- cp -1 + 79 percent
+ cp 79 percent - 1
jp c, DontSwitch
.switch
@@ -112,9 +110,8 @@ SwitchRarely: ; 38083
inc a
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
-; 380c1
-SwitchSometimes: ; 380c1
+SwitchSometimes:
callfar CheckAbleToSwitch
ld a, [wEnemySwitchMonParam]
and $f0
@@ -123,7 +120,7 @@ SwitchSometimes: ; 380c1
cp $10
jr nz, .not_10
call Random
- cp -1 + 20 percent
+ cp 20 percent - 1
jr c, .switch
jp DontSwitch
.not_10
@@ -131,14 +128,14 @@ SwitchSometimes: ; 380c1
cp $20
jr nz, .not_20
call Random
- cp 1 + 50 percent
+ cp 50 percent + 1
jr c, .switch
jp DontSwitch
.not_20
; $30
call Random
- cp -1 + 20 percent
+ cp 20 percent - 1
jp c, DontSwitch
.switch
@@ -147,17 +144,13 @@ SwitchSometimes: ; 380c1
inc a
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
-; 380ff
-
-CheckSubstatusCantRun: ; 380ff
+CheckSubstatusCantRun:
ld a, [wEnemySubStatus5]
bit SUBSTATUS_CANT_RUN, a
ret
-; 38105
-
-AI_TryItem: ; 38105
+AI_TryItem:
; items are not allowed in the BattleTower
ld a, [wInBattleTowerBattle]
and a
@@ -243,8 +236,7 @@ AI_TryItem: ; 38105
scf
ret
-
-.IsHighestLevel: ; 38170
+.IsHighestLevel:
ld a, [wOTPartyCount]
ld d, a
ld e, 0
@@ -274,10 +266,8 @@ AI_TryItem: ; 38105
.yes
scf
ret
-; 38196
-
-AI_Items: ; 39196
+AI_Items:
dbw FULL_RESTORE, .FullRestore
dbw MAX_POTION, .MaxPotion
dbw HYPER_POTION, .HyperPotion
@@ -292,16 +282,14 @@ AI_Items: ; 39196
dbw X_SPEED, .XSpeed
dbw X_SPECIAL, .XSpecial
db -1 ; end
-; 381be
-.FullHeal: ; 381be
+.FullHeal:
call .Status
jp c, .DontUse
call EnemyUsedFullHeal
jp .Use
-; 381ca
-.Status: ; 381ca (e:41ca)
+.Status:
ld a, [wEnemyMonStatus]
and a
jp z, .DontUse
@@ -313,7 +301,7 @@ AI_Items: ; 39196
bit ALWAYS_USE_F, a
jp nz, .Use
call Random
- cp -1 + 20 percent
+ cp 20 percent - 1
jp c, .Use
jp .DontUse
@@ -325,16 +313,15 @@ AI_Items: ; 39196
cp 4
jr c, .FailToxicCheck
call Random
- cp 1 + 50 percent
+ cp 50 percent + 1
jp c, .Use
.FailToxicCheck:
ld a, [wEnemyMonStatus]
and 1 << FRZ | SLP
jp z, .DontUse
jp .Use
-; 38208
-.FullRestore: ; 38208
+.FullRestore:
call .HealItem
jp nc, .UseFullRestore
ld a, [bc]
@@ -346,15 +333,14 @@ AI_Items: ; 39196
.UseFullRestore:
call EnemyUsedFullRestore
jp .Use
-; 38220
-.MaxPotion: ; 38220
+.MaxPotion:
call .HealItem
jp c, .DontUse
call EnemyUsedMaxPotion
jp .Use
-.HealItem: ; 3822c (e:422c)
+.HealItem:
ld a, [bc]
bit CONTEXT_USE_F, a
jr nz, .CheckHalfOrQuarterHP
@@ -366,54 +352,50 @@ AI_Items: ; 39196
callfar AICheckEnemyQuarterHP
jp nc, .UseHealItem
call Random
- cp 1 + 50 percent
+ cp 50 percent + 1
jp c, .UseHealItem
jp .DontUse
-.CheckQuarterHP: ; 38254 (e:4254)
+.CheckQuarterHP:
callfar AICheckEnemyQuarterHP
jp c, .DontUse
call Random
- cp -1 + 20 percent
+ cp 20 percent - 1
jp c, .DontUse
jr .UseHealItem
-.CheckHalfOrQuarterHP: ; 38267 (e:4267)
+.CheckHalfOrQuarterHP:
callfar AICheckEnemyHalfHP
jp c, .DontUse
callfar AICheckEnemyQuarterHP
jp nc, .UseHealItem
call Random
- cp -1 + 20 percent
+ cp 20 percent - 1
jp nc, .DontUse
-.UseHealItem: ; 38281 (e:4281)
+.UseHealItem:
jp .Use
-; 38284
-.HyperPotion: ; 38284
+.HyperPotion:
call .HealItem
jp c, .DontUse
ld b, 200
call EnemyUsedHyperPotion
jp .Use
-; 38292 (e:4292)
-.SuperPotion: ; 38292
+.SuperPotion:
call .HealItem
jp c, .DontUse
ld b, 50
call EnemyUsedSuperPotion
jp .Use
-; 382a0
-.Potion: ; 382a0
+.Potion:
call .HealItem
jp c, .DontUse
ld b, 20
call EnemyUsedPotion
jp .Use
-; 382ae
.asm_382ae ; This appears to be unused
callfar AICheckEnemyMaxHP
@@ -442,7 +424,7 @@ AI_Items: ; 39196
bit UNKNOWN_USE_F, a
jp z, .Use
call Random
- cp 1 + 50 percent
+ cp 50 percent + 1
jp c, .Use
.dont_use
@@ -454,61 +436,53 @@ AI_Items: ; 39196
bit UNKNOWN_USE_F, a
jp z, .DontUse
call Random
- cp 1 + 39 percent
+ cp 39 percent + 1
jp c, .Use
jp .DontUse
-; 382f9
-.XAccuracy: ; 382f9
+.XAccuracy:
call .XItem
jp c, .DontUse
call EnemyUsedXAccuracy
jp .Use
-; 38305
-.GuardSpec: ; 38305
+.GuardSpec:
call .XItem
jp c, .DontUse
call EnemyUsedGuardSpec
jp .Use
-; 38311
-.DireHit: ; 38311
+.DireHit:
call .XItem
jp c, .DontUse
call EnemyUsedDireHit
jp .Use
-; 3831d (e:431d)
-.XAttack: ; 3831d
+.XAttack:
call .XItem
jp c, .DontUse
call EnemyUsedXAttack
jp .Use
-; 38329
-.XDefend: ; 38329
+.XDefend:
call .XItem
jp c, .DontUse
call EnemyUsedXDefend
jp .Use
-; 38335
-.XSpeed: ; 38335
+.XSpeed:
call .XItem
jp c, .DontUse
call EnemyUsedXSpeed
jp .Use
-; 38341
-.XSpecial: ; 38341
+.XSpecial:
call .XItem
jp c, .DontUse
call EnemyUsedXSpecial
jp .Use
-; 3834d
-.XItem: ; 3834d (e:434d)
+.XItem:
ld a, [wEnemyTurnsTaken]
and a
jr nz, .notfirstturnout
@@ -516,13 +490,13 @@ AI_Items: ; 39196
bit ALWAYS_USE_F, a
jp nz, .Use
call Random
- cp 1 + 50 percent
+ cp 50 percent + 1
jp c, .DontUse
ld a, [bc]
bit CONTEXT_USE_F, a
jp nz, .Use
call Random
- cp 1 + 50 percent
+ cp 50 percent + 1
jp c, .DontUse
jp .Use
.notfirstturnout
@@ -530,7 +504,7 @@ AI_Items: ; 39196
bit ALWAYS_USE_F, a
jp z, .DontUse
call Random
- cp -1 + 20 percent
+ cp 20 percent - 1
jp nc, .DontUse
jp .Use
@@ -542,8 +516,7 @@ AI_Items: ; 39196
and a
ret
-
-AIUpdateHUD: ; 38387
+AIUpdateHUD:
call UpdateEnemyMonInParty
farcall UpdateEnemyHUD
ld a, $1
@@ -552,29 +525,26 @@ AIUpdateHUD: ; 38387
dec [hl]
scf
ret
-; 3839a
-AIUsedItemSound: ; 3839a
+AIUsedItemSound:
push de
ld de, SFX_FULL_HEAL
call PlaySFX
pop de
ret
-; 383a3
-
-EnemyUsedFullHeal: ; 383a3 (e:43a3)
+EnemyUsedFullHeal:
call AIUsedItemSound
call AI_HealStatus
ld a, FULL_HEAL
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-EnemyUsedMaxPotion: ; 383ae (e:43ae)
+EnemyUsedMaxPotion:
ld a, MAX_POTION
ld [wCurEnemyItem], a
jr FullRestoreContinue
-EnemyUsedFullRestore: ; 383b5 (e:43b5)
+EnemyUsedFullRestore:
call AI_HealStatus
ld a, FULL_RESTORE
ld [wCurEnemyItem], a
@@ -583,7 +553,7 @@ EnemyUsedFullRestore: ; 383b5 (e:43b5)
xor a
ld [wEnemyConfuseCount], a
-FullRestoreContinue: ; 383c6
+FullRestoreContinue:
ld de, wCurHPAnimOldHP
ld hl, wEnemyMonHP + 1
ld a, [hld]
@@ -603,23 +573,22 @@ FullRestoreContinue: ; 383c6
ld [wCurHPAnimMaxHP + 1], a
ld [wEnemyMonHP], a
jr EnemyPotionFinish
-; 383e8 (e:43e8)
-EnemyUsedPotion: ; 383e8
+EnemyUsedPotion:
ld a, POTION
ld b, 20
jr EnemyPotionContinue
-EnemyUsedSuperPotion: ; 383ee
+EnemyUsedSuperPotion:
ld a, SUPER_POTION
ld b, 50
jr EnemyPotionContinue
-EnemyUsedHyperPotion: ; 383f4 (e:43f4)
+EnemyUsedHyperPotion:
ld a, HYPER_POTION
ld b, 200
-EnemyPotionContinue: ; 383f8
+EnemyPotionContinue:
ld [wCurEnemyItem], a
ld hl, wEnemyMonHP + 1
ld a, [hl]
@@ -658,7 +627,7 @@ EnemyPotionContinue: ; 383f8
ld [hl], a
ld [wCurHPAnimNewHP + 1], a
-EnemyPotionFinish: ; 38436
+EnemyPotionFinish:
call PrintText_UsedItemOn
hlcoord 2, 2
xor a
@@ -667,8 +636,7 @@ EnemyPotionFinish: ; 38436
predef AnimateHPBar
jp AIUpdateHUD
-
-AI_TrySwitch: ; 3844b
+AI_TrySwitch:
; Determine whether the AI can switch based on how many Pokemon are still alive.
; If it can switch, it will.
ld a, [wOTPartyCount]
@@ -695,9 +663,8 @@ AI_TrySwitch: ; 3844b
jp nc, AI_Switch
and a
ret
-; 3846c
-AI_Switch: ; 3846c
+AI_Switch:
ld a, $1
ld [wEnemyIsSwitching], a
ld [wEnemyGoesFirst], a
@@ -739,21 +706,18 @@ AI_Switch: ; 3846c
ret nz
scf
ret
-; 384d0
-TextJump_EnemyWithdrew: ; 384d0
+TextJump_EnemyWithdrew:
text_jump Text_EnemyWithdrew
db "@"
-; 384d5
Function384d5: ; This appears to be unused
call AIUsedItemSound
call AI_HealStatus
ld a, FULL_HEAL_RED ; X_SPEED
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-; 384e0
-AI_HealStatus: ; 384e0
+AI_HealStatus:
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Status
ld bc, PARTYMON_STRUCT_LENGTH
@@ -768,31 +732,27 @@ AI_HealStatus: ; 384e0
ld hl, wEnemySubStatus5
res SUBSTATUS_TOXIC, [hl]
ret
-; 384f7
-EnemyUsedXAccuracy: ; 384f7
+EnemyUsedXAccuracy:
call AIUsedItemSound
ld hl, wEnemySubStatus4
set SUBSTATUS_X_ACCURACY, [hl]
ld a, X_ACCURACY
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-; 38504
-EnemyUsedGuardSpec: ; 38504
+EnemyUsedGuardSpec:
call AIUsedItemSound
ld hl, wEnemySubStatus4
set SUBSTATUS_MIST, [hl]
ld a, GUARD_SPEC
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-; 38511
-EnemyUsedDireHit: ; 38511
+EnemyUsedDireHit:
call AIUsedItemSound
ld hl, wEnemySubStatus4
set SUBSTATUS_FOCUS_ENERGY, [hl]
ld a, DIRE_HIT
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-; 3851e
Function3851e: ; This appears to be unused
ld [hDivisor], a
@@ -818,31 +778,26 @@ Function3851e: ; This appears to be unused
ld a, e
sub c
ret
-; 38541
-EnemyUsedXAttack: ; 38541
+EnemyUsedXAttack:
ld b, ATTACK
ld a, X_ATTACK
jr EnemyUsedXItem
-; 38547
-EnemyUsedXDefend: ; 38547
+EnemyUsedXDefend:
ld b, DEFENSE
ld a, X_DEFEND
jr EnemyUsedXItem
-; 3854d
-EnemyUsedXSpeed: ; 3854d
+EnemyUsedXSpeed:
ld b, SPEED
ld a, X_SPEED
jr EnemyUsedXItem
-; 38553
-EnemyUsedXSpecial: ; 38553
+EnemyUsedXSpecial:
ld b, SP_ATTACK
ld a, X_SPECIAL
-
; Parameter
; a = ITEM_CONSTANT
; b = BATTLE_CONSTANT (ATTACK, DEFENSE, SPEED, SP_ATTACK, SP_DEFENSE, ACCURACY, EVASION)
@@ -853,18 +808,15 @@ EnemyUsedXItem:
pop bc
farcall CheckIfStatCanBeRaised
jp AIUpdateHUD
-; 38568
-
; Parameter
; a = ITEM_CONSTANT
-PrintText_UsedItemOn_AND_AIUpdateHUD: ; 38568
+PrintText_UsedItemOn_AND_AIUpdateHUD:
ld [wCurEnemyItem], a
call PrintText_UsedItemOn
jp AIUpdateHUD
-; 38571
-PrintText_UsedItemOn: ; 38571
+PrintText_UsedItemOn:
ld a, [wCurEnemyItem]
ld [wd265], a
call GetItemName
@@ -874,9 +826,7 @@ PrintText_UsedItemOn: ; 38571
call CopyBytes
ld hl, TextJump_EnemyUsedOn
jp PrintText
-; 3858c
-TextJump_EnemyUsedOn: ; 3858c
+TextJump_EnemyUsedOn:
text_jump Text_EnemyUsedOn
db "@"
-; 38591
diff --git a/engine/battle/ai/move.asm b/engine/battle/ai/move.asm
index b5ac966f8..df0053141 100755..100644
--- a/engine/battle/ai/move.asm
+++ b/engine/battle/ai/move.asm
@@ -1,4 +1,4 @@
-AIChooseMove: ; 440ce
+AIChooseMove:
; Score each move in wEnemyMonMoves starting from wBuffer1. Lower is better.
; Pick the move with the lowest score.
@@ -15,7 +15,6 @@ AIChooseMove: ; 440ce
farcall CheckEnemyLockedIn
ret nz
-
; The default score is 20. Unusable moves are given a score of 80.
ld a, 20
ld hl, wBuffer1
@@ -61,7 +60,6 @@ AIChooseMove: ; 440ce
ld [hl], 80
jr .CheckMovePP
-
; Apply AI scoring layers depending on the trainer class.
.ApplyLayers:
ld hl, TrainerClassAttributes + TRNATTR_AI_MOVE_WEIGHTS
@@ -198,10 +196,9 @@ AIChooseMove: ; 440ce
ld a, c
ld [wCurEnemyMoveNum], a
ret
-; 441af
-
-AIScoringPointers: ; 441af
+AIScoringPointers:
+; entries correspond to AI_* constants
dw AI_Basic
dw AI_Setup
dw AI_Types
@@ -218,4 +215,3 @@ AIScoringPointers: ; 441af
dw AI_None
dw AI_None
dw AI_None
-; 441cf
diff --git a/engine/battle/ai/redundant.asm b/engine/battle/ai/redundant.asm
index d09b4da73..d78fccb84 100755..100644
--- a/engine/battle/ai/redundant.asm
+++ b/engine/battle/ai/redundant.asm
@@ -1,4 +1,4 @@
-AI_Redundant: ; 2c41a
+AI_Redundant:
; Check if move effect c will fail because it's already been used.
; Return z if the move is a good choice.
; Return nz if the move is a bad choice.
@@ -13,7 +13,7 @@ AI_Redundant: ; 2c41a
ld l, a
jp hl
-.Moves: ; 2c42c
+.Moves:
dbw EFFECT_DREAM_EATER, .DreamEater
dbw EFFECT_HEAL, .Heal
dbw EFFECT_LIGHT_SCREEN, .LightScreen
@@ -46,22 +46,22 @@ AI_Redundant: ; 2c41a
dbw EFFECT_FUTURE_SIGHT, .FutureSight
db -1
-.LightScreen: ; 2c487
+.LightScreen:
ld a, [wEnemyScreens]
bit SCREENS_LIGHT_SCREEN, a
ret
-.Mist: ; 2c48d
+.Mist:
ld a, [wEnemySubStatus4]
bit SUBSTATUS_MIST, a
ret
-.FocusEnergy: ; 2c493
+.FocusEnergy:
ld a, [wEnemySubStatus4]
bit SUBSTATUS_FOCUS_ENERGY, a
ret
-.Confuse: ; 2c499
+.Confuse:
ld a, [wPlayerSubStatus3]
bit SUBSTATUS_CONFUSED, a
ret nz
@@ -69,49 +69,49 @@ AI_Redundant: ; 2c41a
bit SCREENS_SAFEGUARD, a
ret
-.Transform: ; 2c4a5
+.Transform:
ld a, [wEnemySubStatus5]
bit SUBSTATUS_TRANSFORMED, a
ret
-.Reflect: ; 2c4ab
+.Reflect:
ld a, [wEnemyScreens]
bit SCREENS_REFLECT, a
ret
-.Substitute: ; 2c4b1
+.Substitute:
ld a, [wEnemySubStatus4]
bit SUBSTATUS_SUBSTITUTE, a
ret
-.LeechSeed: ; 2c4b7
+.LeechSeed:
ld a, [wPlayerSubStatus4]
bit SUBSTATUS_LEECH_SEED, a
ret
-.Disable: ; 2c4bd
+.Disable:
ld a, [wPlayerDisableCount]
and a
ret
-.Encore: ; 2c4c2
+.Encore:
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_ENCORED, a
ret
.Snore:
-.SleepTalk: ; 2c4c8
+.SleepTalk:
ld a, [wEnemyMonStatus]
and SLP
jr z, .Redundant
jr .NotRedundant
-.MeanLook: ; 2c4d1
+.MeanLook:
ld a, [wEnemySubStatus5]
bit SUBSTATUS_CANT_RUN, a
ret
-.Nightmare: ; 2c4d7
+.Nightmare:
ld a, [wBattleMonStatus]
and a
jr z, .Redundant
@@ -119,63 +119,63 @@ AI_Redundant: ; 2c41a
bit SUBSTATUS_NIGHTMARE, a
ret
-.Spikes: ; 2c4e3
+.Spikes:
ld a, [wPlayerScreens]
bit SCREENS_SPIKES, a
ret
-.Foresight: ; 2c4e9
+.Foresight:
ld a, [wPlayerSubStatus1]
bit SUBSTATUS_IDENTIFIED, a
ret
-.PerishSong: ; 2c4ef
+.PerishSong:
ld a, [wPlayerSubStatus1]
bit SUBSTATUS_PERISH, a
ret
-.Sandstorm: ; 2c4f5
+.Sandstorm:
ld a, [wBattleWeather]
cp WEATHER_SANDSTORM
jr z, .Redundant
jr .NotRedundant
-.Attract: ; 2c4fe
+.Attract:
farcall CheckOppositeGender
jr c, .Redundant
ld a, [wPlayerSubStatus1]
bit SUBSTATUS_IN_LOVE, a
ret
-.Safeguard: ; 2c50c
+.Safeguard:
ld a, [wEnemyScreens]
bit SCREENS_SAFEGUARD, a
ret
-.RainDance: ; 2c512
+.RainDance:
ld a, [wBattleWeather]
cp WEATHER_RAIN
jr z, .Redundant
jr .NotRedundant
-.SunnyDay: ; 2c51b
+.SunnyDay:
ld a, [wBattleWeather]
cp WEATHER_SUN
jr z, .Redundant
jr .NotRedundant
-.DreamEater: ; 2c524
+.DreamEater:
ld a, [wBattleMonStatus]
and SLP
jr z, .Redundant
jr .NotRedundant
-.Swagger: ; 2c52d
+.Swagger:
ld a, [wPlayerSubStatus3]
bit SUBSTATUS_CONFUSED, a
ret
-.FutureSight: ; 2c533
+.FutureSight:
ld a, [wEnemyScreens]
bit 5, a
ret
@@ -183,16 +183,16 @@ AI_Redundant: ; 2c41a
.Heal:
.MorningSun:
.Synthesis:
-.Moonlight: ; 2c539
+.Moonlight:
farcall AICheckEnemyMaxHP
jr nc, .NotRedundant
.Teleport:
-.Redundant: ; 2c541
+.Redundant:
ld a, 1
and a
ret
-.NotRedundant: ; 2c545
+.NotRedundant:
xor a
ret
diff --git a/engine/battle/ai/scoring.asm b/engine/battle/ai/scoring.asm
index b250128a4..3cd0e56c4 100644
--- a/engine/battle/ai/scoring.asm
+++ b/engine/battle/ai/scoring.asm
@@ -1,6 +1,6 @@
-AIScoring: ; 38591
+AIScoring: ; used only for BANK(AIScoring)
-AI_Basic: ; 38591
+AI_Basic:
; Don't do anything redundant:
; -Using status-only moves if the player can't be statused
; -Using moves that fail if they've already been used
@@ -40,7 +40,7 @@ AI_Basic: ; 38591
push hl
push de
push bc
- ld hl, .statusonlyeffects
+ ld hl, StatusOnlyEffects
ld de, 1
call IsInArray
@@ -61,19 +61,11 @@ AI_Basic: ; 38591
.discourage
call AIDiscourageMove
jr .checkmove
-; 385db
-
-.statusonlyeffects
- db EFFECT_SLEEP
- db EFFECT_TOXIC
- db EFFECT_POISON
- db EFFECT_PARALYZE
- db -1 ; end
-; 385e0
+INCLUDE "data/battle/ai/status_only_effects.asm"
-AI_Setup: ; 385e0
+AI_Setup:
; Use stat-modifying moves on turn 1.
; 50% chance to greatly encourage stat-up moves during the first turn of enemy's Pokemon.
@@ -146,11 +138,9 @@ AI_Setup: ; 385e0
inc [hl]
inc [hl]
jr .checkmove
-; 38635
-
-AI_Types: ; 38635
+AI_Types:
; Dismiss any move that the player is immune to.
; Encourage super-effective moves.
; Discourage not very effective moves unless
@@ -238,11 +228,9 @@ AI_Types: ; 38635
.immune
call AIDiscourageMove
jr .checkmove
-; 386a2
-
-AI_Offensive: ; 386a2
+AI_Offensive:
; Greatly discourage non-damaging moves.
ld hl, wBuffer1 - 1
@@ -267,11 +255,9 @@ AI_Offensive: ; 386a2
inc [hl]
inc [hl]
jr .checkmove
-; 386be
-
-AI_Smart: ; 386be
+AI_Smart:
; Context-specific scoring.
ld hl, wBuffer1
@@ -401,10 +387,8 @@ AI_Smart: ; 386be
dbw EFFECT_THUNDER, AI_Smart_Thunder
dbw EFFECT_FLY, AI_Smart_Fly
db -1 ; end
-; 387e3
-
-AI_Smart_Sleep: ; 387e3
+AI_Smart_Sleep:
; Greatly encourage sleep inducing moves if the enemy has either Dream Eater or Nightmare.
; 50% chance to greatly encourage sleep inducing moves otherwise.
@@ -422,10 +406,8 @@ AI_Smart_Sleep: ; 387e3
dec [hl]
dec [hl]
ret
-; 387f7
-
-AI_Smart_LeechHit: ; 387f7
+AI_Smart_LeechHit:
push hl
ld a, 1
ld [hBattleTurn], a
@@ -458,10 +440,8 @@ AI_Smart_LeechHit: ; 387f7
inc [hl]
ret
-; 3881d
-
-AI_Smart_LockOn: ; 3881d
+AI_Smart_LockOn:
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_LOCK_ON, a
jr nz, .asm_38882
@@ -564,10 +544,8 @@ AI_Smart_LockOn: ; 3881d
.asm_388a2
pop hl
jp AIDiscourageMove
-; 388a6
-
-AI_Smart_Selfdestruct: ; 388a6
+AI_Smart_Selfdestruct:
; Selfdestruct, Explosion
; Unless this is the enemy's last Pokemon...
@@ -602,10 +580,8 @@ AI_Smart_Selfdestruct: ; 388a6
inc [hl]
inc [hl]
ret
-; 388ca
-
-AI_Smart_DreamEater: ; 388ca
+AI_Smart_DreamEater:
; 90% chance to greatly encourage this move.
; The AI_Basic layer will make sure that
; Dream Eater is only used against sleeping targets.
@@ -616,11 +592,8 @@ AI_Smart_DreamEater: ; 388ca
dec [hl]
dec [hl]
ret
-; 388d4
-
-
-AI_Smart_EvasionUp: ; 388d4
+AI_Smart_EvasionUp:
; Dismiss this move if enemy's evasion can't raise anymore.
ld a, [wEnemyEvaLevel]
cp $d
@@ -704,7 +677,6 @@ AI_Smart_EvasionUp: ; 388d4
bit SUBSTATUS_ROLLOUT, a
jr nz, .asm_388ef
-
.asm_38936
inc [hl]
ret
@@ -729,10 +701,8 @@ AI_Smart_EvasionUp: ; 388d4
dec [hl]
ret
-; 38947
-
-AI_Smart_AlwaysHit: ; 38947
+AI_Smart_AlwaysHit:
; 80% chance to greatly encourage this move if either...
; ...enemy's accuracy level has been lowered three or more stages
@@ -752,11 +722,8 @@ AI_Smart_AlwaysHit: ; 38947
dec [hl]
dec [hl]
ret
-; 3895b
-
-
-AI_Smart_MirrorMove: ; 3895b
+AI_Smart_MirrorMove:
; If the player did not use any move last turn...
ld a, [wLastPlayerCounterMove]
and a
@@ -796,11 +763,8 @@ AI_Smart_MirrorMove: ; 3895b
dec [hl]
ret
-; 38985
-
-
-AI_Smart_AccuracyDown: ; 38985
+AI_Smart_AccuracyDown:
; If player's HP is full...
call AICheckPlayerMaxHP
jr nc, .asm_389a0
@@ -903,11 +867,8 @@ AI_Smart_AccuracyDown: ; 38985
dec [hl]
ret
-; 389f5
-
-
-AI_Smart_ResetStats: ; 389f5
+AI_Smart_ResetStats:
; 85% chance to encourage this move if any of enemy's stat levels is lower than -2.
push hl
ld hl, wEnemyAtkLevel
@@ -946,10 +907,8 @@ AI_Smart_ResetStats: ; 389f5
pop hl
inc [hl]
ret
-; 38a1e
-
-AI_Smart_Bide: ; 38a1e
+AI_Smart_Bide:
; 90% chance to discourage this move unless enemy's HP is full.
call AICheckEnemyMaxHP
@@ -959,10 +918,8 @@ AI_Smart_Bide: ; 38a1e
ret c
inc [hl]
ret
-; 38a2a
-
-AI_Smart_ForceSwitch: ; 38a2a
+AI_Smart_ForceSwitch:
; Whirlwind, Roar.
; Discourage this move if the player has not shown
@@ -977,13 +934,11 @@ AI_Smart_ForceSwitch: ; 38a2a
ret c
inc [hl]
ret
-; 38a3a
-
AI_Smart_Heal:
AI_Smart_MorningSun:
AI_Smart_Synthesis:
-AI_Smart_Moonlight: ; 38a3a
+AI_Smart_Moonlight:
; 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.
@@ -1002,22 +957,18 @@ AI_Smart_Moonlight: ; 38a3a
dec [hl]
dec [hl]
ret
-; 38a4e
-
AI_Smart_Toxic:
-AI_Smart_LeechSeed: ; 38a4e
+AI_Smart_LeechSeed:
; Discourage this move if player's HP is below 50%.
call AICheckPlayerHalfHP
ret c
inc [hl]
ret
-; 38a54
-
AI_Smart_LightScreen:
-AI_Smart_Reflect: ; 38a54
+AI_Smart_Reflect:
; Over 90% chance to discourage this move unless enemy's HP is full.
call AICheckEnemyMaxHP
@@ -1027,10 +978,8 @@ AI_Smart_Reflect: ; 38a54
ret c
inc [hl]
ret
-; 38a60
-
-AI_Smart_Ohko: ; 38a60
+AI_Smart_Ohko:
; Dismiss this move if player's level is higher than enemy's level.
; Else, discourage this move is player's HP is below 50%.
@@ -1043,10 +992,8 @@ AI_Smart_Ohko: ; 38a60
ret c
inc [hl]
ret
-; 38a71
-
-AI_Smart_TrapTarget: ; 38a71
+AI_Smart_TrapTarget:
; Bind, Wrap, Fire Spin, Clamp
; 50% chance to discourage this move if the player is already trapped.
@@ -1061,7 +1008,7 @@ AI_Smart_TrapTarget: ; 38a71
jr nz, .asm_38a91
ld a, [wPlayerSubStatus1]
- and 1<<SUBSTATUS_IN_LOVE | 1<<SUBSTATUS_ROLLOUT | 1<<SUBSTATUS_IDENTIFIED | 1<<SUBSTATUS_NIGHTMARE
+ and 1 << SUBSTATUS_IN_LOVE | 1 << SUBSTATUS_ROLLOUT | 1 << SUBSTATUS_IDENTIFIED | 1 << SUBSTATUS_NIGHTMARE
jr nz, .asm_38a91
; Else, 50% chance to greatly encourage this move if it's the player's Pokemon first turn.
@@ -1084,11 +1031,9 @@ AI_Smart_TrapTarget: ; 38a71
dec [hl]
dec [hl]
ret
-; 38a9c
-
AI_Smart_RazorWind:
-AI_Smart_Unused2B: ; 38a9c
+AI_Smart_Unused2B:
ld a, [wEnemySubStatus1]
bit SUBSTATUS_PERISH, a
jr z, .asm_38aaa
@@ -1139,11 +1084,8 @@ AI_Smart_Unused2B: ; 38a9c
add 6
ld [hl], a
ret
-; 38adb
-
-
-AI_Smart_Confuse: ; 38adb
+AI_Smart_Confuse:
; 90% chance to discourage this move if player's HP is between 25% and 50%.
call AICheckPlayerHalfHP
ret c
@@ -1158,11 +1100,8 @@ AI_Smart_Confuse: ; 38adb
ret c
inc [hl]
ret
-; 38aed
-
-
-AI_Smart_SpDefenseUp2: ; 38aed
+AI_Smart_SpDefenseUp2:
; Discourage this move if enemy's HP is lower than 50%.
call AICheckEnemyHalfHP
jr nc, .asm_38b10
@@ -1194,10 +1133,8 @@ AI_Smart_SpDefenseUp2: ; 38aed
.asm_38b10
inc [hl]
ret
-; 38b12
-
-AI_Smart_Fly: ; 38b12
+AI_Smart_Fly:
; Fly, Dig
; Greatly encourage this move if the player is
@@ -1214,21 +1151,16 @@ AI_Smart_Fly: ; 38b12
dec [hl]
dec [hl]
ret
-; 38b20
-
-AI_Smart_SuperFang: ; 38b20
+AI_Smart_SuperFang:
; Discourage this move if player's HP is below 25%.
call AICheckPlayerQuarterHP
ret c
inc [hl]
ret
-; 38b26
-
-
-AI_Smart_Paralyze: ; 38b26
+AI_Smart_Paralyze:
; 50% chance to discourage this move if player's HP is below 25%.
call AICheckPlayerQuarterHP
jr nc, .asm_38b3a
@@ -1250,10 +1182,8 @@ AI_Smart_Paralyze: ; 38b26
ret c
inc [hl]
ret
-; 38b40
-
-AI_Smart_SpeedDownHit: ; 38b40
+AI_Smart_SpeedDownHit:
; Icy Wind
; Almost 90% chance to greatly encourage this move if the following conditions all meet:
@@ -1277,19 +1207,15 @@ AI_Smart_SpeedDownHit: ; 38b40
dec [hl]
dec [hl]
ret
-; 38b5c
-
-AI_Smart_Substitute: ; 38b5c
+AI_Smart_Substitute:
; Dismiss this move if enemy's HP is below 50%.
call AICheckEnemyHalfHP
ret c
jp AIDiscourageMove
-; 38b63
-
-AI_Smart_HyperBeam: ; 38b63
+AI_Smart_HyperBeam:
call AICheckEnemyHalfHP
jr c, .asm_38b72
@@ -1311,10 +1237,8 @@ AI_Smart_HyperBeam: ; 38b63
ret c
inc [hl]
ret
-; 38b7f
-
-AI_Smart_Rage: ; 38b7f
+AI_Smart_Rage:
ld a, [wEnemySubStatus4]
bit SUBSTATUS_RAGE, a
jr z, .asm_38b9b
@@ -1351,10 +1275,8 @@ AI_Smart_Rage: ; 38b7f
.asm_38ba6
inc [hl]
ret
-; 38ba8
-
-AI_Smart_Mimic: ; 38ba8
+AI_Smart_Mimic:
ld a, [wLastPlayerCounterMove]
and a
jr z, .asm_38be9
@@ -1402,10 +1324,8 @@ AI_Smart_Mimic: ; 38ba8
.asm_38bef
inc [hl]
ret
-; 38bf1
-
-AI_Smart_Counter: ; 38bf1
+AI_Smart_Counter:
push hl
ld hl, wPlayerUsedMoves
ld c, 4
@@ -1454,7 +1374,6 @@ AI_Smart_Counter: ; 38bf1
cp SPECIAL
jr nc, .asm_38c38
-
.asm_38c30
call Random
cp 39 percent + 1
@@ -1468,10 +1387,8 @@ AI_Smart_Counter: ; 38bf1
.asm_38c39
inc [hl]
ret
-; 38c3b
-
-AI_Smart_Encore: ; 38c3b
+AI_Smart_Encore:
call AICompareSpeed
jr nc, .asm_38c81
@@ -1502,7 +1419,7 @@ AI_Smart_Encore: ; 38c3b
.asm_38c68
push hl
ld a, [wLastPlayerCounterMove]
- ld hl, .EncoreMoves
+ ld hl, EncoreMoves
ld de, 1
call IsInArray
pop hl
@@ -1522,42 +1439,9 @@ AI_Smart_Encore: ; 38c3b
inc [hl]
ret
-.EncoreMoves:
- db SWORDS_DANCE
- db WHIRLWIND
- db LEER
- db ROAR
- db DISABLE
- db MIST
- db LEECH_SEED
- db GROWTH
- db POISONPOWDER
- db STRING_SHOT
- db MEDITATE
- db AGILITY
- db TELEPORT
- db SCREECH
- db HAZE
- db FOCUS_ENERGY
- db DREAM_EATER
- db POISON_GAS
- db SPLASH
- db SHARPEN
- db CONVERSION
- db SUPER_FANG
- db SUBSTITUTE
- db TRIPLE_KICK
- db SPIDER_WEB
- db MIND_READER
- db FLAME_WHEEL
- db AEROBLAST
- db COTTON_SPORE
- db POWDER_SNOW
- db -1 ; end
-; 38ca4
-
+INCLUDE "data/battle/ai/encore_moves.asm"
-AI_Smart_PainSplit: ; 38ca4
+AI_Smart_PainSplit:
; Discourage this move if [enemy's current HP * 2 > player's current HP].
push hl
@@ -1576,11 +1460,9 @@ AI_Smart_PainSplit: ; 38ca4
ret nc
inc [hl]
ret
-; 38cba
-
AI_Smart_Snore:
-AI_Smart_SleepTalk: ; 38cba
+AI_Smart_SleepTalk:
; Greatly encourage this move if enemy is fast asleep.
; Greatly discourage this move otherwise.
@@ -1599,24 +1481,20 @@ AI_Smart_SleepTalk: ; 38cba
inc [hl]
inc [hl]
ret
-; 38ccb
-
-AI_Smart_DefrostOpponent: ; 38ccb
+AI_Smart_DefrostOpponent:
; Greatly encourage this move if enemy is frozen.
; No move has EFFECT_DEFROST_OPPONENT, so this layer is unused.
ld a, [wEnemyMonStatus]
- and $20
+ and 1 << FRZ
ret z
dec [hl]
dec [hl]
dec [hl]
ret
-; 38cd5
-
-AI_Smart_Spite: ; 38cd5
+AI_Smart_Spite:
ld a, [wLastPlayerCounterMove]
and a
jr nz, .asm_38ce7
@@ -1671,27 +1549,21 @@ AI_Smart_Spite: ; 38cd5
dec [hl]
dec [hl]
ret
-; 38d16
-
-Function_0x38d16; 38d16
+Function_0x38d16:
jp AIDiscourageMove
-; 38d19
-
AI_Smart_DestinyBond:
AI_Smart_Reversal:
-AI_Smart_SkullBash: ; 38d19
+AI_Smart_SkullBash:
; Discourage this move if enemy's HP is above 25%.
call AICheckEnemyQuarterHP
ret nc
inc [hl]
ret
-; 38d1f
-
-AI_Smart_HealBell: ; 38d1f
+AI_Smart_HealBell:
; 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.
@@ -1747,10 +1619,8 @@ AI_Smart_HealBell: ; 38d1f
ret nz
jp AIDiscourageMove
-; 38d5a
-
-AI_Smart_PriorityHit: ; 38d5a
+AI_Smart_PriorityHit:
call AICompareSpeed
ret c
@@ -1780,20 +1650,16 @@ AI_Smart_PriorityHit: ; 38d5a
dec [hl]
dec [hl]
ret
-; 38d93
-
-AI_Smart_Thief: ; 38d93
+AI_Smart_Thief:
; Don't use Thief unless it's the only move available.
ld a, [hl]
add $1e
ld [hl], a
ret
-; 38d98
-
-AI_Smart_Conversion2: ; 38d98
+AI_Smart_Conversion2:
ld a, [wLastPlayerMove]
and a
jr nz, .asm_38dc9
@@ -1831,10 +1697,8 @@ AI_Smart_Conversion2: ; 38d98
ret c
inc [hl]
ret
-; 38dd1
-
-AI_Smart_Disable: ; 38dd1
+AI_Smart_Disable:
call AICompareSpeed
jr nc, .asm_38df3
@@ -1864,10 +1728,8 @@ AI_Smart_Disable: ; 38dd1
ret c
inc [hl]
ret
-; 38dfb
-
-AI_Smart_MeanLook: ; 38dfb
+AI_Smart_MeanLook:
call AICheckEnemyHalfHP
jr nc, .asm_38e24
@@ -1885,7 +1747,7 @@ AI_Smart_MeanLook: ; 38dfb
; 80% chance to greatly encourage this move if the player is either
; in love, identified, stuck in Rollout, or has a Nightmare.
ld a, [wPlayerSubStatus1]
- and 1<<SUBSTATUS_IN_LOVE | 1<<SUBSTATUS_ROLLOUT | 1<<SUBSTATUS_IDENTIFIED | 1<<SUBSTATUS_NIGHTMARE
+ and 1 << SUBSTATUS_IN_LOVE | 1 << SUBSTATUS_ROLLOUT | 1 << SUBSTATUS_IDENTIFIED | 1 << SUBSTATUS_NIGHTMARE
jr nz, .asm_38e26
; Otherwise, discourage this move unless the player only has not very effective moves against the enemy.
@@ -1907,10 +1769,8 @@ AI_Smart_MeanLook: ; 38dfb
dec [hl]
dec [hl]
ret
-; 38e2e
-
-AICheckLastPlayerMon: ; 38e2e
+AICheckLastPlayerMon:
ld a, [wPartyCount]
ld b, a
ld c, 0
@@ -1934,10 +1794,8 @@ AICheckLastPlayerMon: ; 38e2e
jr nz, .loop
ret
-; 38e4a
-
-AI_Smart_Nightmare: ; 38e4a
+AI_Smart_Nightmare:
; 50% chance to encourage this move.
; The AI_Basic layer will make sure that
; Dream Eater is only used against sleeping targets.
@@ -1946,10 +1804,8 @@ AI_Smart_Nightmare: ; 38e4a
ret c
dec [hl]
ret
-; 38e50
-
-AI_Smart_FlameWheel: ; 38e50
+AI_Smart_FlameWheel:
; Use this move if the enemy is frozen.
ld a, [wEnemyMonStatus]
@@ -1959,10 +1815,8 @@ rept 5
dec [hl]
endr
ret
-; 38e5c
-
-AI_Smart_Curse: ; 38e5c
+AI_Smart_Curse:
ld a, [wEnemyMonType1]
cp GHOST
jr z, .ghostcurse
@@ -2019,14 +1873,12 @@ AI_Smart_Curse: ; 38e5c
jr .asm_38eb7
-
.asm_38eb0
push hl
call AICheckLastPlayerMon
pop hl
jr z, .asm_38ecb
-
.asm_38eb7
call AICheckEnemyQuarterHP
jp nc, .asm_38e90
@@ -2048,10 +1900,8 @@ AI_Smart_Curse: ; 38e5c
dec [hl]
dec [hl]
ret
-; 38ed2
-
-AI_Smart_Protect: ; 38ed2
+AI_Smart_Protect:
ld a, [wEnemyProtectCount]
and a
jr nz, .asm_38f13
@@ -2101,10 +1951,8 @@ AI_Smart_Protect: ; 38ed2
inc [hl]
inc [hl]
ret
-; 38f1d
-
-AI_Smart_Foresight: ; 38f1d
+AI_Smart_Foresight:
ld a, [wEnemyAccLevel]
cp $5
jr c, .asm_38f41
@@ -2132,10 +1980,8 @@ AI_Smart_Foresight: ; 38f1d
dec [hl]
dec [hl]
ret
-; 38f4a
-
-AI_Smart_PerishSong: ; 38f4a
+AI_Smart_PerishSong:
push hl
callfar FindAliveEnemyMons
pop hl
@@ -2170,11 +2016,8 @@ AI_Smart_PerishSong: ; 38f4a
add 5
ld [hl], a
ret
-; 38f7a
-
-
-AI_Smart_Sandstorm: ; 38f7a
+AI_Smart_Sandstorm:
; Greatly discourage this move if the player is immune to Sandstorm damage.
ld a, [wBattleMonType1]
push hl
@@ -2215,10 +2058,8 @@ AI_Smart_Sandstorm: ; 38f7a
db GROUND
db STEEL
db -1 ; end
-; 38fac
-
-AI_Smart_Endure: ; 38fac
+AI_Smart_Endure:
ld a, [wEnemyProtectCount]
and a
jr nz, .asm_38fd8
@@ -2259,10 +2100,8 @@ AI_Smart_Endure: ; 38fac
.asm_38fd9
inc [hl]
ret
-; 38fdb
-
-AI_Smart_FuryCutter: ; 38fdb
+AI_Smart_FuryCutter:
; Encourage this move based on Fury Cutter's count.
ld a, [wEnemyFuryCutterCount]
@@ -2284,10 +2123,8 @@ AI_Smart_FuryCutter: ; 38fdb
.end
; fallthrough
-; 38fef
-
-AI_Smart_Rollout: ; 38fef
+AI_Smart_Rollout:
; Rollout, Fury Cutter
; 80% chance to discourage this move if the enemy is in love, confused, or paralyzed.
@@ -2328,11 +2165,9 @@ AI_Smart_Rollout: ; 38fef
ret c
inc [hl]
ret
-; 39026
-
AI_Smart_Swagger:
-AI_Smart_Attract: ; 39026
+AI_Smart_Attract:
; 80% chance to encourage this move during the first turn of player's Pokemon.
; 80% chance to discourage this move otherwise.
@@ -2351,10 +2186,8 @@ AI_Smart_Attract: ; 39026
ret nc
dec [hl]
ret
-; 3903a
-
-AI_Smart_Safeguard: ; 3903a
+AI_Smart_Safeguard:
; 80% chance to discourage this move if player's HP is below 50%.
call AICheckPlayerHalfHP
@@ -2363,12 +2196,9 @@ AI_Smart_Safeguard: ; 3903a
ret c
inc [hl]
ret
-; 39044
-
AI_Smart_Magnitude:
-AI_Smart_Earthquake: ; 39044
-
+AI_Smart_Earthquake:
; Greatly encourage this move if the player is underground and the enemy is faster.
ld a, [wLastPlayerCounterMove]
cp DIG
@@ -2396,10 +2226,8 @@ AI_Smart_Earthquake: ; 39044
dec [hl]
ret
-; 39062
-
-AI_Smart_BatonPass: ; 39062
+AI_Smart_BatonPass:
; Discourage this move if the player hasn't shown super-effective moves against the enemy.
; Consider player's type(s) if its moves are unknown.
@@ -2411,10 +2239,8 @@ AI_Smart_BatonPass: ; 39062
ret c
inc [hl]
ret
-; 39072
-
-AI_Smart_Pursuit: ; 39072
+AI_Smart_Pursuit:
; 50% chance to greatly encourage this move if player's HP is below 25%.
; 80% chance to discourage this move otherwise.
@@ -2431,10 +2257,8 @@ AI_Smart_Pursuit: ; 39072
dec [hl]
dec [hl]
ret
-; 39084
-
-AI_Smart_RapidSpin: ; 39084
+AI_Smart_RapidSpin:
; 80% chance to greatly encourage this move if the enemy is
; trapped (Bind effect), seeded, or scattered with spikes.
@@ -2457,10 +2281,8 @@ AI_Smart_RapidSpin: ; 39084
dec [hl]
dec [hl]
ret
-; 3909e
-
-AI_Smart_HiddenPower: ; 3909e
+AI_Smart_HiddenPower:
push hl
ld a, 1
ld [hBattleTurn], a
@@ -2497,11 +2319,8 @@ AI_Smart_HiddenPower: ; 3909e
.bad
inc [hl]
ret
-; 390cb
-
-
-AI_Smart_RainDance: ; 390cb
+AI_Smart_RainDance:
; Greatly discourage this move if it would favour the player type-wise.
; Particularly, if the player is a Water-type.
ld a, [wBattleMonType1]
@@ -2519,26 +2338,10 @@ AI_Smart_RainDance: ; 390cb
push hl
ld hl, RainDanceMoves
jr AI_Smart_WeatherMove
-; 390e7
-
-RainDanceMoves: ; 390e7
- db WATER_GUN
- db HYDRO_PUMP
- db SURF
- db BUBBLEBEAM
- db THUNDER
- db WATERFALL
- db CLAMP
- db BUBBLE
- db CRABHAMMER
- db OCTAZOOKA
- db WHIRLPOOL
- db -1 ; end
-; 390f3
-
-AI_Smart_SunnyDay: ; 390f3
+INCLUDE "data/battle/ai/rain_dance_moves.asm"
+AI_Smart_SunnyDay:
; Greatly discourage this move if it would favour the player type-wise.
; Particularly, if the player is a Fire-type.
ld a, [wBattleMonType1]
@@ -2557,10 +2360,8 @@ AI_Smart_SunnyDay: ; 390f3
ld hl, SunnyDayMoves
; fallthrough
-; 3910d
-
-AI_Smart_WeatherMove: ; 3910d
+AI_Smart_WeatherMove:
; Rain Dance, Sunny Day
; Greatly discourage this move if the enemy doesn't have
@@ -2579,16 +2380,14 @@ AI_Smart_WeatherMove: ; 3910d
dec [hl]
ret
-; 3911e
-AIBadWeatherType: ; 3911e
+AIBadWeatherType:
inc [hl]
inc [hl]
inc [hl]
ret
-; 39122
-AIGoodWeatherType: ; 39122
+AIGoodWeatherType:
; Rain Dance, Sunny Day
; Greatly encourage this move if it would disfavour the player type-wise and player's HP is above 50%...
@@ -2610,23 +2409,10 @@ AIGoodWeatherType: ; 39122
dec [hl]
dec [hl]
ret
-; 39134
+INCLUDE "data/battle/ai/sunny_day_moves.asm"
-SunnyDayMoves: ; 39134
- db FIRE_PUNCH
- db EMBER
- db FLAMETHROWER
- db FIRE_SPIN
- db FIRE_BLAST
- db SACRED_FIRE
- db MORNING_SUN
- db SYNTHESIS
- db -1 ; end
-; 3913d
-
-
-AI_Smart_BellyDrum: ; 3913d
+AI_Smart_BellyDrum:
; Dismiss this move if enemy's attack is higher than +2 or if enemy's HP is below 50%.
; Else, discourage this move if enemy's HP is not full.
@@ -2647,10 +2433,8 @@ AI_Smart_BellyDrum: ; 3913d
add $5
ld [hl], a
ret
-; 39152
-
-AI_Smart_PsychUp: ; 39152
+AI_Smart_PsychUp:
push hl
ld hl, wEnemyAtkLevel
ld b, $8
@@ -2706,10 +2490,8 @@ AI_Smart_PsychUp: ; 39152
inc [hl]
inc [hl]
ret
-; 3918b
-
-AI_Smart_MirrorCoat: ; 3918b
+AI_Smart_MirrorCoat:
push hl
ld hl, wPlayerUsedMoves
ld c, $4
@@ -2758,7 +2540,6 @@ AI_Smart_MirrorCoat: ; 3918b
cp SPECIAL
jr c, .asm_391d2
-
.asm_391ca
call Random
cp 100
@@ -2771,12 +2552,9 @@ AI_Smart_MirrorCoat: ; 3918b
.asm_391d3
inc [hl]
ret
-; 391d5
-
AI_Smart_Twister:
-AI_Smart_Gust: ; 391d5
-
+AI_Smart_Gust:
; Greatly encourage this move if the player is flying and the enemy is faster.
ld a, [wLastPlayerCounterMove]
cp FLY
@@ -2803,10 +2581,8 @@ AI_Smart_Gust: ; 391d5
ret c
dec [hl]
ret
-; 391f3
-
-AI_Smart_FutureSight: ; 391f3
+AI_Smart_FutureSight:
; Greatly encourage this move if the player is
; flying or underground, and slower than the enemy.
@@ -2820,10 +2596,8 @@ AI_Smart_FutureSight: ; 391f3
dec [hl]
dec [hl]
ret
-; 39200
-
-AI_Smart_Stomp: ; 39200
+AI_Smart_Stomp:
; 80% chance to encourage this move if the player has used Minimize.
ld a, [wPlayerMinimized]
@@ -2835,10 +2609,8 @@ AI_Smart_Stomp: ; 39200
dec [hl]
ret
-; 3920b
-
-AI_Smart_Solarbeam: ; 3920b
+AI_Smart_Solarbeam:
; 80% chance to encourage this move when it's sunny.
; 90% chance to discourage this move when it's raining.
@@ -2864,10 +2636,8 @@ AI_Smart_Solarbeam: ; 3920b
dec [hl]
dec [hl]
ret
-; 39225
-
-AI_Smart_Thunder: ; 39225
+AI_Smart_Thunder:
; 90% chance to discourage this move when it's sunny.
ld a, [wBattleWeather]
@@ -2880,10 +2650,8 @@ AI_Smart_Thunder: ; 39225
inc [hl]
ret
-; 39233
-
-AICompareSpeed: ; 39233
+AICompareSpeed:
; Return carry if enemy is faster than player.
push bc
@@ -2897,30 +2665,24 @@ AICompareSpeed: ; 39233
sbc b
pop bc
ret
-; 39246
-
-AICheckPlayerMaxHP: ; 39246
+AICheckPlayerMaxHP:
push hl
push de
push bc
ld de, wBattleMonHP
ld hl, wBattleMonMaxHP
jr AICheckMaxHP
-; 39251
-
-AICheckEnemyMaxHP: ; 39251
+AICheckEnemyMaxHP:
push hl
push de
push bc
ld de, wEnemyMonHP
ld hl, wEnemyMonMaxHP
; fallthrough
-; 3925a
-
-AICheckMaxHP: ; 3925a
+AICheckMaxHP:
; Return carry if hp at de matches max hp at hl.
ld a, [de]
@@ -2945,10 +2707,8 @@ AICheckMaxHP: ; 3925a
pop hl
and a
ret
-; 3926e
-
-AICheckPlayerHalfHP: ; 3926e
+AICheckPlayerHalfHP:
push hl
ld hl, wBattleMonHP
ld b, [hl]
@@ -2964,10 +2724,8 @@ AICheckPlayerHalfHP: ; 3926e
sbc b
pop hl
ret
-; 39281
-
-AICheckEnemyHalfHP: ; 39281
+AICheckEnemyHalfHP:
push hl
push de
push bc
@@ -2987,10 +2745,8 @@ AICheckEnemyHalfHP: ; 39281
pop de
pop hl
ret
-; 39298
-
-AICheckEnemyQuarterHP: ; 39298
+AICheckEnemyQuarterHP:
push hl
push de
push bc
@@ -3012,10 +2768,8 @@ AICheckEnemyQuarterHP: ; 39298
pop de
pop hl
ret
-; 392b3
-
-AICheckPlayerQuarterHP: ; 392b3
+AICheckPlayerQuarterHP:
push hl
ld hl, wBattleMonHP
ld b, [hl]
@@ -3033,10 +2787,8 @@ AICheckPlayerQuarterHP: ; 392b3
sbc b
pop hl
ret
-; 392ca
-
-AIHasMoveEffect: ; 392ca
+AIHasMoveEffect:
; Return carry if the enemy has move b.
push hl
@@ -3066,10 +2818,8 @@ AIHasMoveEffect: ; 392ca
pop hl
scf
ret
-; 392e6
-
-AIHasMoveInArray: ; 392e6
+AIHasMoveInArray:
; Return carry if the enemy has a move in array hl.
push hl
@@ -3101,35 +2851,10 @@ AIHasMoveInArray: ; 392e6
pop de
pop hl
ret
-; 39301
-
-
-UsefulMoves: ; 39301
-; Moves that are usable all-around.
- db DOUBLE_EDGE
- db SING
- db FLAMETHROWER
- db HYDRO_PUMP
- db SURF
- db ICE_BEAM
- db BLIZZARD
- db HYPER_BEAM
- db SLEEP_POWDER
- db THUNDERBOLT
- db THUNDER
- db EARTHQUAKE
- db TOXIC
- db PSYCHIC_M
- db HYPNOSIS
- db RECOVER
- db FIRE_BLAST
- db SOFTBOILED
- db SUPER_FANG
- db -1 ; end
-; 39315
+INCLUDE "data/battle/ai/useful_moves.asm"
-AI_Opportunist: ; 39315
+AI_Opportunist:
; Discourage stall moves when the enemy's HP is low.
; Do nothing if enemy's HP is above 50%.
@@ -3161,7 +2886,7 @@ AI_Opportunist: ; 39315
push hl
push de
push bc
- ld hl, .stallmoves
+ ld hl, StallMoves
ld de, 1
call IsInArray
@@ -3176,45 +2901,10 @@ AI_Opportunist: ; 39315
.asm_39347
ret
-.stallmoves
- db SWORDS_DANCE
- db TAIL_WHIP
- db LEER
- db GROWL
- db DISABLE
- db MIST
- db COUNTER
- db LEECH_SEED
- db GROWTH
- db STRING_SHOT
- db MEDITATE
- db AGILITY
- db RAGE
- db MIMIC
- db SCREECH
- db HARDEN
- db WITHDRAW
- db DEFENSE_CURL
- db BARRIER
- db LIGHT_SCREEN
- db HAZE
- db REFLECT
- db FOCUS_ENERGY
- db BIDE
- db AMNESIA
- db TRANSFORM
- db SPLASH
- db ACID_ARMOR
- db SHARPEN
- db CONVERSION
- db SUBSTITUTE
- db FLAME_WHEEL
- db -1 ; end
-; 39369
-
+INCLUDE "data/battle/ai/stall_moves.asm"
-AI_Aggressive: ; 39369
+AI_Aggressive:
; Use whatever does the most damage.
; Discourage all damaging moves but the one that does the most damage.
@@ -3304,7 +2994,7 @@ AI_Aggressive: ; 39369
push de
push bc
ld a, [wEnemyMoveStruct + MOVE_EFFECT]
- ld hl, .RecklessMoves
+ ld hl, RecklessMoves
ld de, 1
call IsInArray
pop bc
@@ -3319,21 +3009,14 @@ AI_Aggressive: ; 39369
.done
ret
-.RecklessMoves:
- db EFFECT_SELFDESTRUCT
- db EFFECT_RAMPAGE
- db EFFECT_MULTI_HIT
- db EFFECT_DOUBLE_HIT
- db -1 ; end
-; 393e7
-
+INCLUDE "data/battle/ai/reckless_moves.asm"
-AIDamageCalc: ; 393e7
+AIDamageCalc:
ld a, 1
ld [hBattleTurn], a
ld a, [wEnemyMoveStruct + MOVE_EFFECT]
ld de, 1
- ld hl, .ConstantDamageEffects
+ ld hl, ConstantDamageEffects
call IsInArray
jr nc, .asm_39400
callfar BattleCommand_ConstantDamage
@@ -3345,16 +3028,9 @@ AIDamageCalc: ; 393e7
callfar BattleCommand_Stab
ret
-.ConstantDamageEffects:
- db EFFECT_SUPER_FANG
- db EFFECT_STATIC_DAMAGE
- db EFFECT_LEVEL_DAMAGE
- db EFFECT_PSYWAVE
- db -1 ; end
-; 39418
-
+INCLUDE "data/battle/ai/constant_damage_effects.asm"
-AI_Cautious: ; 39418
+AI_Cautious:
; 90% chance to discourage moves with residual effects after the first turn.
ld a, [wEnemyTurnsTaken]
@@ -3377,7 +3053,7 @@ AI_Cautious: ; 39418
push hl
push de
push bc
- ld hl, .residualmoves
+ ld hl, ResidualMoves
ld de, 1
call IsInArray
@@ -3393,25 +3069,10 @@ AI_Cautious: ; 39418
inc [hl]
jr .asm_39425
-.residualmoves
- db MIST
- db LEECH_SEED
- db POISONPOWDER
- db STUN_SPORE
- db THUNDER_WAVE
- db FOCUS_ENERGY
- db BIDE
- db POISON_GAS
- db TRANSFORM
- db CONVERSION
- db SUBSTITUTE
- db SPIKES
- db -1 ; end
-; 39453
-
+INCLUDE "data/battle/ai/residual_moves.asm"
-AI_Status: ; 39453
+AI_Status:
; Dismiss status moves that don't affect the player.
ld hl, wBuffer1 - 1
@@ -3471,11 +3132,9 @@ AI_Status: ; 39453
.immune
call AIDiscourageMove
jr .checkmove
-; 394a9
-
-AI_Risky: ; 394a9
+AI_Risky:
; Use any move that will KO the target.
; Risky moves will often be an exception (see below).
@@ -3504,7 +3163,7 @@ AI_Risky: ; 394a9
; Don't use risky moves at max hp.
ld a, [wEnemyMoveStruct + MOVE_EFFECT]
ld de, 1
- ld hl, .RiskyMoves
+ ld hl, RiskyEffects
call IsInArray
jr nc, .checkko
@@ -3541,28 +3200,19 @@ endr
pop de
jr .checkmove
-.RiskyMoves:
- db EFFECT_SELFDESTRUCT
- db EFFECT_OHKO
- db -1 ; end
-; 39502
-
+INCLUDE "data/battle/ai/risky_effects.asm"
-AI_None: ; 39502
+AI_None:
ret
-; 39503
-
-AIDiscourageMove: ; 39503
+AIDiscourageMove:
ld a, [hl]
add 10
ld [hl], a
ret
-; 39508
-
-AIGetEnemyMove: ; 39508
+AIGetEnemyMove:
; Load attributes of move a into ram
push hl
@@ -3581,18 +3231,13 @@ AIGetEnemyMove: ; 39508
pop de
pop hl
ret
-; 39521
-
-AI_80_20: ; 39521
+AI_80_20:
call Random
cp 20 percent - 1
ret
-; 39527
-
-AI_50_50: ; 39527
+AI_50_50:
call Random
cp 50 percent + 1
ret
-; 3952d
diff --git a/engine/battle/ai/switch.asm b/engine/battle/ai/switch.asm
index d397c8d32..b9bd2ea60 100755..100644
--- a/engine/battle/ai/switch.asm
+++ b/engine/battle/ai/switch.asm
@@ -1,4 +1,4 @@
-CheckPlayerMoveTypeMatchups: ; 3484e
+CheckPlayerMoveTypeMatchups:
; Check how well the moves you've already used
; fare against the enemy's Pokemon. Used to
; score a potential switch.
@@ -95,10 +95,8 @@ CheckPlayerMoveTypeMatchups: ; 3484e
pop de
pop hl
ret
-; 348de
-
-.CheckEnemyMoveMatchups: ; 348de
+.CheckEnemyMoveMatchups:
ld de, wEnemyMonMoves
ld b, NUM_MOVES + 1
ld c, 0
@@ -163,21 +161,19 @@ CheckPlayerMoveTypeMatchups: ; 3484e
.doubledown
call .DecreaseScore
-.DecreaseScore: ; 34931
+.DecreaseScore:
ld a, [wEnemyAISwitchScore]
dec a
ld [wEnemyAISwitchScore], a
ret
-; 34939
-.IncreaseScore: ; 34939
+.IncreaseScore:
ld a, [wEnemyAISwitchScore]
inc a
ld [wEnemyAISwitchScore], a
ret
-; 34941
-CheckAbleToSwitch: ; 34941
+CheckAbleToSwitch:
xor a
ld [wEnemySwitchMonParam], a
call FindAliveEnemyMons
@@ -292,10 +288,8 @@ CheckAbleToSwitch: ; 34941
add $10
ld [wEnemySwitchMonParam], a
ret
-; 349f4
-
-FindAliveEnemyMons: ; 349f4
+FindAliveEnemyMons:
ld a, [wOTPartyCount]
cp 2
jr c, .only_one
@@ -344,10 +338,8 @@ FindAliveEnemyMons: ; 349f4
.more_than_one
and a
ret
-; 34a2a
-
-FindEnemyMonsImmuneToLastCounterMove: ; 34a2a
+FindEnemyMonsImmuneToLastCounterMove:
ld hl, wOTPartyMon1
ld a, [wOTPartyCount]
ld b, a
@@ -412,10 +404,8 @@ FindEnemyMonsImmuneToLastCounterMove: ; 34a2a
inc d
srl c
jr .loop
-; 34a85
-
-FindAliveEnemyMonsWithASuperEffectiveMove: ; 34a85
+FindAliveEnemyMonsWithASuperEffectiveMove:
push bc
ld a, [wOTPartyCount]
ld e, a
@@ -445,8 +435,9 @@ FindAliveEnemyMonsWithASuperEffectiveMove: ; 34a85
and c
ld c, a
-FindEnemyMonsWithASuperEffectiveMove: ; 34aa7
+ ; fallthrough
+FindEnemyMonsWithASuperEffectiveMove:
ld a, -1
ld [wEnemyAISwitchScore], a
ld hl, wOTPartyMon1Moves
@@ -551,10 +542,8 @@ FindEnemyMonsWithASuperEffectiveMove: ; 34aa7
ld [wEnemyAISwitchScore], a
pop bc
ret
-; 34b20
-
-FindEnemyMonsThatResistPlayer: ; 34b20
+FindEnemyMonsThatResistPlayer:
push bc
ld hl, wOTPartySpecies
ld b, 1 << (PARTY_LENGTH - 1)
@@ -613,10 +602,8 @@ FindEnemyMonsThatResistPlayer: ; 34b20
and c
ld c, a
ret
-; 34b77
-
-FindEnemyMonsWithAtLeastQuarterMaxHP: ; 34b77
+FindEnemyMonsWithAtLeastQuarterMaxHP:
push bc
ld de, wOTPartySpecies
ld b, 1 << (PARTY_LENGTH - 1)
@@ -669,4 +656,3 @@ FindEnemyMonsWithAtLeastQuarterMaxHP: ; 34b77
and c
ld c, a
ret
-; 34bb1
diff --git a/engine/battle/anim_hp_bar.asm b/engine/battle/anim_hp_bar.asm
index 7d51a8629..fd9c783ce 100755..100644
--- a/engine/battle/anim_hp_bar.asm
+++ b/engine/battle/anim_hp_bar.asm
@@ -1,4 +1,4 @@
-_AnimateHPBar: ; d627
+_AnimateHPBar:
call .IsMaximumMoreThan48Pixels
jr c, .MoreThan48Pixels
call .ComputePixels
@@ -38,9 +38,8 @@ _AnimateHPBar: ; d627
pop af
jr nc, .LongAnimLoop
ret
-; d65f
-.IsMaximumMoreThan48Pixels: ; d65f
+.IsMaximumMoreThan48Pixels:
ld a, [wCurHPAnimMaxHP + 1]
and a
jr nz, .player
@@ -53,9 +52,8 @@ _AnimateHPBar: ; d627
.player
scf
ret
-; d670
-.ComputePixels: ; d670
+.ComputePixels:
push hl
ld hl, wCurHPAnimMaxHP
ld a, [hli]
@@ -127,9 +125,8 @@ _AnimateHPBar: ; d627
ld a, e
ld [wCurHPAnimDeltaHP + 1], a
ret
-; d6e2
-ShortAnim_UpdateVariables: ; d6e2
+ShortAnim_UpdateVariables:
ld hl, wCurHPBarPixels
ld a, [wNewHPBarPixels]
cp [hl]
@@ -144,9 +141,8 @@ ShortAnim_UpdateVariables: ; d6e2
call ShortHPBar_CalcPixelFrame
and a
ret
-; d6f5
-LongAnim_UpdateVariables: ; d6f5
+LongAnim_UpdateVariables:
.loop
ld hl, wCurHPAnimOldHP
ld a, [hli]
@@ -199,9 +195,8 @@ LongAnim_UpdateVariables: ; d6f5
ld [hl], a
and a
ret
-; d730
-ShortHPBarAnim_UpdateTiles: ; d730
+ShortHPBarAnim_UpdateTiles:
call HPBarAnim_UpdateHPRemaining
ld d, HP_BAR_LENGTH
ld a, [wWhichHPBar]
@@ -215,9 +210,8 @@ ShortHPBarAnim_UpdateTiles: ; d730
pop de
call HPBarAnim_PaletteUpdate
ret
-; d749
-LongHPBarAnim_UpdateTiles: ; d749
+LongHPBarAnim_UpdateTiles:
call HPBarAnim_UpdateHPRemaining
ld a, [wCurHPAnimOldHP]
ld c, a
@@ -238,9 +232,8 @@ LongHPBarAnim_UpdateTiles: ; d749
pop de
call HPBarAnim_PaletteUpdate
ret
-; d771
-HPBarAnim_RedrawHPBar: ; d771
+HPBarAnim_RedrawHPBar:
ld a, [wWhichHPBar]
cp $2
jr nz, .skip
@@ -253,9 +246,8 @@ HPBarAnim_RedrawHPBar: ; d771
.skip
call DrawBattleHPBar
ret
-; d784
-HPBarAnim_UpdateHPRemaining: ; d784
+HPBarAnim_UpdateHPRemaining:
ld a, [wWhichHPBar]
and a
ret z
@@ -283,9 +275,8 @@ HPBarAnim_UpdateHPRemaining: ; d784
call PrintNum
pop hl
ret
-; d7b4
-HPBarAnim_PaletteUpdate: ; d7b4
+HPBarAnim_PaletteUpdate:
ld a, [hCGB]
and a
ret z
@@ -295,9 +286,8 @@ HPBarAnim_PaletteUpdate: ; d7b4
ld c, a
farcall ApplyHPBarPals
ret
-; d7c9
-HPBarAnim_BGMapUpdate: ; d7c9
+HPBarAnim_BGMapUpdate:
ld a, [hCGB]
and a
jr nz, .cgb
@@ -369,9 +359,8 @@ HPBarAnim_BGMapUpdate: ; d7c9
ld [hBGMapThird], a
call DelayFrame
ret
-; d839
-ShortHPBar_CalcPixelFrame: ; d839
+ShortHPBar_CalcPixelFrame:
ld a, [wCurHPAnimMaxHP]
ld c, a
ld b, 0
@@ -384,8 +373,9 @@ ShortHPBar_CalcPixelFrame: ; d839
call AddNTimes
ld b, 0
-; This routine is buggy. If [wCurHPAnimMaxHP] * [wCurHPBarPixels] is divisible
-; by 48, the loop runs one extra time. To fix, uncomment the line below.
+; This routine is buggy. If [wCurHPAnimMaxHP] * [wCurHPBarPixels] is
+; divisible by HP_BAR_LENGTH_PX, the loop runs one extra time.
+; To fix, uncomment the line below.
.loop
ld a, l
sub HP_BAR_LENGTH_PX
@@ -432,4 +422,3 @@ ShortHPBar_CalcPixelFrame: ; d839
ld a, [wCurHPAnimMaxHP]
ld [wCurHPAnimOldHP], a
ret
-; d88c
diff --git a/engine/battle/battle_transition.asm b/engine/battle/battle_transition.asm
index 29b2d8663..8747f46a6 100644
--- a/engine/battle/battle_transition.asm
+++ b/engine/battle/battle_transition.asm
@@ -1,4 +1,14 @@
-DoBattleTransition: ; 8c20f
+; BattleTransitionJumptable.Jumptable indexes
+BATTLETRANSITION_CAVE EQU $01
+BATTLETRANSITION_CAVE_STRONGER EQU $09
+BATTLETRANSITION_NO_CAVE EQU $10
+BATTLETRANSITION_NO_CAVE_STRONGER EQU $18
+BATTLETRANSITION_FINISH EQU $20
+BATTLETRANSITION_END EQU $80
+
+BATTLETRANSITION_SQUARE EQUS "\"8\"" ; $fe
+
+DoBattleTransition:
call .InitGFX
ld a, [rBGP]
ld [wBGP], a
@@ -14,7 +24,7 @@ DoBattleTransition: ; 8c20f
.loop
ld a, [wJumptableIndex]
- bit 7, a
+ bit 7, a ; BATTLETRANSITION_END?
jr nz, .done
call BattleTransitionJumptable
call DelayFrame
@@ -50,9 +60,8 @@ DoBattleTransition: ; 8c20f
ld [hVBlank], a
call DelayFrame
ret
-; 8c26d
-.InitGFX: ; 8c26d
+.InitGFX:
ld a, [wLinkMode]
cp LINK_MOBILE
jr z, .mobile
@@ -79,20 +88,18 @@ DoBattleTransition: ; 8c20f
ld [hl], a
call WipeLYOverrides
ret
-; 8c2a0
-.NonMobile_LoadPokeballTiles: ; 8c2a0
+.NonMobile_LoadPokeballTiles:
call LoadTrainerBattlePokeballTiles
hlbgcoord 0, 0
call ConvertTrainerBattlePokeballTilesTo2bpp
ret
-; 8c2aa
LoadTrainerBattlePokeballTiles:
; Load the tiles used in the Pokeball Graphic that fills the screen
; at the start of every Trainer battle.
ld de, TrainerBattlePokeballTiles
- ld hl, vTiles1 tile $7e
+ ld hl, vTiles0 tile BATTLETRANSITION_SQUARE
ld b, BANK(TrainerBattlePokeballTiles)
ld c, 2
call Request2bpp
@@ -103,7 +110,7 @@ LoadTrainerBattlePokeballTiles:
ld [rVBK], a
ld de, TrainerBattlePokeballTiles
- ld hl, vTiles4 tile $7e
+ ld hl, vTiles3 tile BATTLETRANSITION_SQUARE
ld b, BANK(TrainerBattlePokeballTiles)
ld c, 2
call Request2bpp
@@ -111,9 +118,8 @@ LoadTrainerBattlePokeballTiles:
pop af
ld [rVBK], a
ret
-; 8c2cf
-ConvertTrainerBattlePokeballTilesTo2bpp: ; 8c2cf
+ConvertTrainerBattlePokeballTilesTo2bpp:
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
@@ -138,20 +144,17 @@ ConvertTrainerBattlePokeballTilesTo2bpp: ; 8c2cf
pop af
ld [rSVBK], a
ret
-; 8c2f4
-TrainerBattlePokeballTiles: ; 8c2f4
+TrainerBattlePokeballTiles:
INCBIN "gfx/overworld/trainer_battle_pokeball_tiles.2bpp"
+BattleTransitionJumptable:
+ jumptable .Jumptable, wJumptableIndex
-BattleTransitionJumptable: ; 8c314
- jumptable .dw, wJumptableIndex
-; 8c323
-
-.dw ; 8c323 (23:4323)
+.Jumptable
dw StartTrainerBattle_DetermineWhichAnimation ; 00
- ; Animation 1: cave
+ ; BATTLETRANSITION_CAVE
dw StartTrainerBattle_LoadPokeBallGraphics ; 01
dw StartTrainerBattle_SetUpBGMap ; 02
dw StartTrainerBattle_Flash ; 03
@@ -161,7 +164,7 @@ BattleTransitionJumptable: ; 8c314
dw StartTrainerBattle_SetUpForWavyOutro ; 07
dw StartTrainerBattle_SineWave ; 08
- ; Animation 2: cave, stronger
+ ; BATTLETRANSITION_CAVE_STRONGER
dw StartTrainerBattle_LoadPokeBallGraphics ; 09
dw StartTrainerBattle_SetUpBGMap ; 0a
dw StartTrainerBattle_Flash ; 0b
@@ -171,7 +174,7 @@ BattleTransitionJumptable: ; 8c314
; There is no setup for this one
dw StartTrainerBattle_ZoomToBlack ; 0f
- ; Animation 3: no cave
+ ; BATTLETRANSITION_NO_CAVE
dw StartTrainerBattle_LoadPokeBallGraphics ; 10
dw StartTrainerBattle_SetUpBGMap ; 11
dw StartTrainerBattle_Flash ; 12
@@ -181,7 +184,7 @@ BattleTransitionJumptable: ; 8c314
dw StartTrainerBattle_SetUpForSpinOutro ; 16
dw StartTrainerBattle_SpinToBlack ; 17
- ; Animation 4: no cave, stronger
+ ; BATTLETRANSITION_NO_CAVE_STRONGER
dw StartTrainerBattle_LoadPokeBallGraphics ; 18
dw StartTrainerBattle_SetUpBGMap ; 19
dw StartTrainerBattle_Flash ; 1a
@@ -191,11 +194,21 @@ BattleTransitionJumptable: ; 8c314
dw StartTrainerBattle_SetUpForRandomScatterOutro ; 1e
dw StartTrainerBattle_SpeckleToBlack ; 1f
- ; All animations jump to here.
+ ; BATTLETRANSITION_FINISH
dw StartTrainerBattle_Finish ; 20
+; transition animations
+ const_def
+ const TRANS_CAVE
+ const TRANS_CAVE_STRONGER
+ const TRANS_NO_CAVE
+ const TRANS_NO_CAVE_STRONGER
+
+; transition animation bits
+TRANS_STRONGER_F EQU 0 ; bit set in TRANS_CAVE_STRONGER and TRANS_NO_CAVE_STRONGER
+TRANS_NO_CAVE_F EQU 1 ; bit set in TRANS_NO_CAVE and TRANS_NO_CAVE_STRONGER
-StartTrainerBattle_DetermineWhichAnimation: ; 8c365 (23:4365)
+StartTrainerBattle_DetermineWhichAnimation:
; The screen flashes a different number of times depending on the level of
; your lead Pokemon relative to the opponent's.
; BUG: wBattleMonLevel and wEnemyMonLevel are not set at this point, so whatever
@@ -205,55 +218,56 @@ StartTrainerBattle_DetermineWhichAnimation: ; 8c365 (23:4365)
add 3
ld hl, wEnemyMonLevel
cp [hl]
- jr nc, .okay
- set 0, e
-.okay
+ jr nc, .not_stronger
+ set TRANS_STRONGER_F, e
+.not_stronger
ld a, [wEnvironment]
cp CAVE
- jr z, .okay2
+ jr z, .cave
cp ENVIRONMENT_5
- jr z, .okay2
+ jr z, .cave
cp DUNGEON
- jr z, .okay2
- set 1, e
-.okay2
+ jr z, .cave
+ set TRANS_NO_CAVE_F, e
+.cave
ld hl, .StartingPoints
add hl, de
ld a, [hl]
ld [wJumptableIndex], a
ret
-; 8c38f (23:438f)
-.StartingPoints: ; 8c38f
- db 1, 9
- db 16, 24
-; 8c393
+.StartingPoints:
+; entries correspond to TRANS_* constants
+ db BATTLETRANSITION_CAVE
+ db BATTLETRANSITION_CAVE_STRONGER
+ db BATTLETRANSITION_NO_CAVE
+ db BATTLETRANSITION_NO_CAVE_STRONGER
-StartTrainerBattle_Finish: ; 8c393 (23:4393)
+StartTrainerBattle_Finish:
call ClearSprites
- ld a, $80
+ ld a, BATTLETRANSITION_END
ld [wJumptableIndex], a
ret
-StartTrainerBattle_NextScene: ; 8c39c (23:439c)
+StartTrainerBattle_NextScene:
ld hl, wJumptableIndex
inc [hl]
ret
-StartTrainerBattle_SetUpBGMap: ; 8c3a1 (23:43a1)
+StartTrainerBattle_SetUpBGMap:
call StartTrainerBattle_NextScene
xor a
ld [wcf64], a
ld [hBGMapMode], a
ret
-StartTrainerBattle_Flash: ; 8c3ab (23:43ab)
+StartTrainerBattle_Flash:
call .DoFlashAnimation
ret nc
call StartTrainerBattle_NextScene
ret
-.DoFlashAnimation: ; 8c3b3 (23:43b3)
+.DoFlashAnimation:
ld a, [wTimeOfDayPalset]
cp %11111111 ; dark cave
jr z, .done
@@ -278,9 +292,8 @@ StartTrainerBattle_Flash: ; 8c3ab (23:43ab)
ld [wcf64], a
scf
ret
-; 8c3db (23:43db)
-.pals ; 8c3db
+.pals
db %11111001 ; 3321
db %11111110 ; 3332
db %11111111 ; 3333
@@ -294,9 +307,8 @@ StartTrainerBattle_Flash: ; 8c3ab (23:43ab)
db %10010000 ; 2100
db %11100100 ; 3210
db %00000001 ; 0001
-; 8c3e8
-StartTrainerBattle_SetUpForWavyOutro: ; 8c3e8 (23:43e8)
+StartTrainerBattle_SetUpForWavyOutro:
farcall Function5602
ld a, BANK(wLYOverrides)
ld [rSVBK], a
@@ -314,7 +326,7 @@ StartTrainerBattle_SetUpForWavyOutro: ; 8c3e8 (23:43e8)
ld [wcf65], a
ret
-StartTrainerBattle_SineWave: ; 8c408 (23:4408)
+StartTrainerBattle_SineWave:
ld a, [wcf64]
cp $60
jr nc, .end
@@ -322,11 +334,11 @@ StartTrainerBattle_SineWave: ; 8c408 (23:4408)
ret
.end
- ld a, $20
+ ld a, BATTLETRANSITION_FINISH
ld [wJumptableIndex], a
ret
-.DoSineWave: ; 8c419 (23:4419)
+.DoSineWave:
ld hl, wcf65
ld a, [hl]
inc [hl]
@@ -354,7 +366,7 @@ StartTrainerBattle_SineWave: ; 8c408 (23:4408)
jr nz, .loop
ret
-StartTrainerBattle_SetUpForSpinOutro: ; 8c43d (23:443d)
+StartTrainerBattle_SetUpForSpinOutro:
farcall Function5602
ld a, BANK(wLYOverrides)
ld [rSVBK], a
@@ -363,7 +375,7 @@ StartTrainerBattle_SetUpForSpinOutro: ; 8c43d (23:443d)
ld [wcf64], a
ret
-StartTrainerBattle_SpinToBlack: ; 8c44f (23:444f)
+StartTrainerBattle_SpinToBlack:
xor a
ld [hBGMapMode], a
ld a, [wcf64]
@@ -394,10 +406,9 @@ endr
call DelayFrame
xor a
ld [hBGMapMode], a
- ld a, $20
+ ld a, BATTLETRANSITION_FINISH
ld [wJumptableIndex], a
ret
-; 8c490 (23:4490)
; quadrants
const_def
@@ -406,7 +417,11 @@ endr
const LOWER_LEFT
const LOWER_RIGHT
-.spintable ; 8c490
+; quadrant bits
+RIGHT_QUADRANT_F EQU 0 ; bit set in UPPER_RIGHT and LOWER_RIGHT
+LOWER_QUADRANT_F EQU 1 ; bit set in LOWER_LEFT and LOWER_RIGHT
+
+.spintable
spintable_entry: MACRO
db \1
dw .wedge\2
@@ -433,9 +448,8 @@ ENDM
spintable_entry LOWER_LEFT, 2, 0, 14
spintable_entry LOWER_LEFT, 1, 1, 11
db -1
-; 8c4f5
-.load ; 8c4f5 (23:44f5)
+.load
ld a, [hli]
ld e, a
ld a, [hli]
@@ -451,7 +465,7 @@ ENDM
.loop1
ld [hl], $ff
ld a, [wcf65]
- bit 0, a
+ bit RIGHT_QUADRANT_F, a
jr z, .leftside
inc hl
jr .okay1
@@ -462,7 +476,7 @@ ENDM
jr nz, .loop1
pop hl
ld a, [wcf65]
- bit 1, a
+ bit LOWER_QUADRANT_F, a
ld bc, SCREEN_WIDTH
jr z, .upper
ld bc, -SCREEN_WIDTH
@@ -477,7 +491,7 @@ ENDM
ld c, a
.loop2
ld a, [wcf65]
- bit 0, a
+ bit RIGHT_QUADRANT_F, a
jr z, .leftside2
dec hl
jr .okay2
@@ -487,16 +501,14 @@ ENDM
dec c
jr nz, .loop2
jr .loop
-; 8c538 (23:4538)
.wedge1 db 2, 3, 5, 4, 9, -1
.wedge2 db 1, 1, 2, 2, 4, 2, 4, 2, 3, -1
.wedge3 db 2, 1, 3, 1, 4, 1, 4, 1, 4, 1, 3, 1, 2, 1, 1, 1, 1, -1
.wedge4 db 4, 1, 4, 0, 3, 1, 3, 0, 2, 1, 2, 0, 1, -1
.wedge5 db 4, 0, 3, 0, 3, 0, 2, 0, 2, 0, 1, 0, 1, 0, 1, -1
-; 8c578
-StartTrainerBattle_SetUpForRandomScatterOutro: ; 8c578 (23:4578)
+StartTrainerBattle_SetUpForRandomScatterOutro:
farcall Function5602
ld a, BANK(wLYOverrides)
ld [rSVBK], a
@@ -507,7 +519,7 @@ StartTrainerBattle_SetUpForRandomScatterOutro: ; 8c578 (23:4578)
ld [hBGMapMode], a
ret
-StartTrainerBattle_SpeckleToBlack: ; 8c58f (23:458f)
+StartTrainerBattle_SpeckleToBlack:
ld hl, wcf64
ld a, [hl]
and a
@@ -530,11 +542,11 @@ StartTrainerBattle_SpeckleToBlack: ; 8c58f (23:458f)
call DelayFrame
xor a
ld [hBGMapMode], a
- ld a, $20
+ ld a, BATTLETRANSITION_FINISH
ld [wJumptableIndex], a
ret
-.BlackOutRandomTile: ; 8c5b8 (23:45b8)
+.BlackOutRandomTile:
.y_loop
call Random
cp SCREEN_HEIGHT
@@ -565,7 +577,7 @@ StartTrainerBattle_SpeckleToBlack: ; 8c58f (23:458f)
ld [hl], $ff
ret
-StartTrainerBattle_LoadPokeBallGraphics: ; 8c5dc (23:45dc)
+StartTrainerBattle_LoadPokeBallGraphics:
ld a, [wOtherTrainerClass]
and a
jp z, .nextscene ; don't need to be here if wild
@@ -606,7 +618,7 @@ StartTrainerBattle_LoadPokeBallGraphics: ; 8c5dc (23:45dc)
jr z, .done
sla a
jr nc, .no_load
- ld [hl], $fe
+ ld [hl], BATTLETRANSITION_SQUARE
.no_load
inc hl
jr .loop4
@@ -665,11 +677,11 @@ StartTrainerBattle_LoadPokeBallGraphics: ; 8c5dc (23:45dc)
call DelayFrame
call BattleStart_CopyTilemapAtOnce
-.nextscene ; 8c673 (23:4673)
+.nextscene
call StartTrainerBattle_NextScene
ret
-.copypals ; 8c677 (23:4677)
+.copypals
ld de, wBGPals1 palette PAL_BG_TEXT
call .copy
ld de, wBGPals2 palette PAL_BG_TEXT
@@ -682,21 +694,18 @@ StartTrainerBattle_LoadPokeBallGraphics: ; 8c5dc (23:45dc)
call .copy
ld de, wOBPals2 palette PAL_OW_ROCK
-.copy ; 8c698 (23:4698)
+.copy
push hl
ld bc, 1 palettes
call CopyBytes
pop hl
ret
-; 8c6a1 (23:46a1)
-.daypals ; 8c6a1
+.daypals
INCLUDE "gfx/overworld/trainer_battle_day.pal"
-; 8c6a9
-.nightpals ; 8c6a9
+.nightpals
INCLUDE "gfx/overworld/trainer_battle_nite.pal"
-; 8c6b1
.loadpokeballgfx
ld a, [wOtherTrainerClass]
@@ -721,7 +730,7 @@ PokeBallTransition:
db %00001111, %11110000
db %00000011, %11000000
-WipeLYOverrides: ; 8c6d8
+WipeLYOverrides:
ld a, [rSVBK]
push af
ld a, BANK(wLYOverrides)
@@ -735,9 +744,8 @@ WipeLYOverrides: ; 8c6d8
pop af
ld [rSVBK], a
ret
-; 8c6ef
-.wipe ; 8c6ef
+.wipe
xor a
ld c, SCREEN_HEIGHT_PX
.loop
@@ -745,54 +753,11 @@ WipeLYOverrides: ; 8c6d8
dec c
jr nz, .loop
ret
-; 8c6f7
-
-
-StartTrainerBattle_DrawSineWave: ; 8c6f7 (23:46f7)
-; a = d * sin(a * pi/32)
- and %111111
- cp %100000
- jr nc, .negative
- call .ApplySineWave
- ld a, h
- ret
-
-.negative
- and %011111
- call .ApplySineWave
- ld a, h
- xor $ff
- inc a
- ret
-
-.ApplySineWave: ; 8c70c (23:470c)
- ld e, a
- ld a, d
- ld d, 0
- ld hl, .sinewave
- add hl, de
- add hl, de
- ld e, [hl]
- inc hl
- ld d, [hl]
- ld hl, 0
-.multiply
- srl a
- jr nc, .even
- add hl, de
-.even
- sla e
- rl d
- and a
- jr nz, .multiply
- ret
-; 8c728 (23:4728)
-.sinewave ; 8c728
- sine_wave $100
-; 8c768
+StartTrainerBattle_DrawSineWave:
+ calc_sine_wave
-StartTrainerBattle_ZoomToBlack: ; 8c768 (23:4768)
+StartTrainerBattle_ZoomToBlack:
farcall Function5602
ld de, .boxes
@@ -818,12 +783,11 @@ StartTrainerBattle_ZoomToBlack: ; 8c768 (23:4768)
jr .loop
.done
- ld a, $20
+ ld a, BATTLETRANSITION_FINISH
ld [wJumptableIndex], a
ret
-; 8c792 (23:4792)
-.boxes ; 8c792
+.boxes
zoombox: MACRO
; width, height, start y, start x
db \1, \2
@@ -839,9 +803,8 @@ ENDM
zoombox 18, 16, 1, 1
zoombox 20, 18, 0, 0
db -1
-; 8c7b7
-.Copy: ; 8c7b7 (23:47b7)
+.Copy:
ld a, $ff
.row
push bc
@@ -857,7 +820,6 @@ ENDM
dec b
jr nz, .row
ret
-; 8c7c9 (23:47c9)
Unreferenced_Function8c7c9:
ld a, $1
diff --git a/engine/battle/battlestart_copytilemapatonce.asm b/engine/battle/battlestart_copytilemapatonce.asm
index 2952e833b..9d4d48d3a 100644
--- a/engine/battle/battlestart_copytilemapatonce.asm
+++ b/engine/battle/battlestart_copytilemapatonce.asm
@@ -1,3 +1,3 @@
-BattleStart_CopyTilemapAtOnce: ; 8cf4f
+BattleStart_CopyTilemapAtOnce:
call CGBOnly_CopyTilemapAtOnce
ret
diff --git a/engine/battle/checkbattlescene.asm b/engine/battle/check_battle_scene.asm
index 577c36e33..13d0c665e 100644
--- a/engine/battle/checkbattlescene.asm
+++ b/engine/battle/check_battle_scene.asm
@@ -1,4 +1,4 @@
-CheckBattleScene: ; 4ea44
+CheckBattleScene:
; Return carry if battle scene is turned off.
ld a, BANK(wLinkMode)
diff --git a/engine/battle/consumehelditem.asm b/engine/battle/consume_held_item.asm
index 39ddbc27e..fe63d40a8 100644
--- a/engine/battle/consumehelditem.asm
+++ b/engine/battle/consume_held_item.asm
@@ -1,4 +1,4 @@
-ConsumeHeldItem: ; 27192
+ConsumeHeldItem:
push hl
push de
push bc
@@ -18,7 +18,7 @@ ConsumeHeldItem: ; 27192
ld a, [de]
ld b, a
farcall GetItemHeldEffect
- ld hl, .ConsumableEffects
+ ld hl, ConsumableEffects
.loop
ld a, [hli]
cp b
@@ -46,7 +46,7 @@ ConsumeHeldItem: ; 27192
jr z, .done
.ourturn
- ld [hl], $0
+ ld [hl], NO_ITEM
.done
pop bc
@@ -54,27 +54,4 @@ ConsumeHeldItem: ; 27192
pop hl
ret
-.ConsumableEffects: ; 271de
-; Consumable items?
- db HELD_BERRY
- db HELD_2
- db HELD_5
- db HELD_HEAL_POISON
- db HELD_HEAL_FREEZE
- db HELD_HEAL_BURN
- db HELD_HEAL_SLEEP
- db HELD_HEAL_PARALYZE
- db HELD_HEAL_STATUS
- db HELD_30
- db HELD_ATTACK_UP
- db HELD_DEFENSE_UP
- db HELD_SPEED_UP
- db HELD_SP_ATTACK_UP
- db HELD_SP_DEFENSE_UP
- db HELD_ACCURACY_UP
- db HELD_EVASION_UP
- db HELD_38
- db HELD_71
- db HELD_ESCAPE
- db HELD_CRITICAL_UP
- db -1
+INCLUDE "data/battle/held_consumables.asm"
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index 0fe77df40..d1bd41b84 100644
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -1,6 +1,6 @@
; Core components of the battle engine.
-BattleCore:
-DoBattle: ; 3c000
+
+DoBattle:
xor a
ld [wBattleParticipantsNotFainted], a
ld [wBattleParticipantsIncludingFainted], a
@@ -47,7 +47,7 @@ DoBattle: ; 3c000
.player_2
call LoadTileMapToTempTileMap
- call CheckPlayerPartyForFitPkmn
+ call CheckPlayerPartyForFitMon
ld a, d
and a
jp z, LostBattle
@@ -86,7 +86,7 @@ DoBattle: ; 3c000
call ResetBattleParticipants
call InitBattleMon
call ResetPlayerStatLevels
- call SendOutPkmnText
+ call SendOutMonText
call NewBattleMonStatus
call BreakAttraction
call SendOutPlayerMon
@@ -114,13 +114,12 @@ DoBattle: ; 3c000
.tutorial_debug
jp BattleMenu
-; 3c0e5
-WildFled_EnemyFled_LinkBattleCanceled: ; 3c0e5
+WildFled_EnemyFled_LinkBattleCanceled:
call Call_LoadTempTileMapToTileMap
ld a, [wBattleResult]
- and $c0
- add $2
+ and BATTLERESULT_BITMASK
+ add DRAW
ld [wBattleResult], a
ld a, [wLinkMode]
and a
@@ -128,8 +127,8 @@ WildFled_EnemyFled_LinkBattleCanceled: ; 3c0e5
jr z, .print_text
ld a, [wBattleResult]
- and $c0
- ld [wBattleResult], a
+ and BATTLERESULT_BITMASK
+ ld [wBattleResult], a ; WIN
ld hl, BattleText_EnemyFled
call CheckMobileBattleError
jr nc, .print_text
@@ -156,9 +155,8 @@ WildFled_EnemyFled_LinkBattleCanceled: ; 3c0e5
ld a, 1
ld [wBattleEnded], a
ret
-; 3c12f
-BattleTurn: ; 3c12f
+BattleTurn:
.loop
call Stubbed_Function3c1bf
call CheckContestBattleOver
@@ -229,7 +227,6 @@ BattleTurn: ; 3c12f
.quit
ret
-; 3c1bf
Stubbed_Function3c1bf:
ret
@@ -248,9 +245,8 @@ Stubbed_Function3c1bf:
.finish
call CloseSRAM
ret
-; 3c1d6
-HandleBetweenTurnEffects: ; 3c1d6
+HandleBetweenTurnEffects:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .CheckEnemyFirst
@@ -289,7 +285,7 @@ HandleBetweenTurnEffects: ; 3c1d6
.NoMoreFaintingConditions:
call HandleLeftovers
call HandleMysteryberry
- call HanleDefrost
+ call HandleDefrost
call HandleSafeguard
call HandleScreens
call HandleStatBoostingHeldItems
@@ -297,9 +293,8 @@ HandleBetweenTurnEffects: ; 3c1d6
call UpdateBattleMonInParty
call LoadTileMapToTempTileMap
jp HandleEncore
-; 3c23c
-CheckFaint_PlayerThenEnemy: ; 3c23c
+CheckFaint_PlayerThenEnemy:
call HasPlayerFainted
jr nz, .PlayerNotFainted
call HandlePlayerMonFaint
@@ -322,9 +317,8 @@ CheckFaint_PlayerThenEnemy: ; 3c23c
.BattleIsOver:
scf
ret
-; 3c25c
-CheckFaint_EnemyThenPlayer: ; 3c25c
+CheckFaint_EnemyThenPlayer:
call HasEnemyFainted
jr nz, .EnemyNotFainted
call HandleEnemyMonFaint
@@ -347,9 +341,8 @@ CheckFaint_EnemyThenPlayer: ; 3c25c
.BattleIsOver:
scf
ret
-; 3c27c
-HandleBerserkGene: ; 3c27c
+HandleBerserkGene:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .reverse
@@ -424,9 +417,8 @@ HandleBerserkGene: ; 3c27c
call SwitchTurnCore
ld hl, BecameConfusedText
jp StdBattleTextBox
-; 3c300
-EnemyTriesToFlee: ; 3c300
+EnemyTriesToFlee:
ld a, [wLinkMode]
and a
jr z, .not_linked
@@ -442,9 +434,8 @@ EnemyTriesToFlee: ; 3c300
call WildFled_EnemyFled_LinkBattleCanceled
scf
ret
-; 3c314
-DetermineMoveOrder: ; 3c314
+DetermineMoveOrder:
ld a, [wLinkMode]
and a
jr z, .use_move
@@ -463,13 +454,13 @@ DetermineMoveOrder: ; 3c314
jr z, .player_2
call BattleRandom
- cp 1 + (50 percent)
+ cp 50 percent + 1
jp c, .player_first
jp .enemy_first
.player_2
call BattleRandom
- cp 1 + (50 percent)
+ cp 50 percent + 1
jp c, .enemy_first
jp .player_first
@@ -549,25 +540,23 @@ DetermineMoveOrder: ; 3c314
cp USING_INTERNAL_CLOCK
jr z, .player_2c
call BattleRandom
- cp 1 + (50 percent)
+ cp 50 percent + 1
jp c, .player_first
jp .enemy_first
.player_2c
call BattleRandom
- cp 1 + (50 percent)
+ cp 50 percent + 1
jp c, .enemy_first
.player_first
scf
ret
-; 3c3f3
-.enemy_first ; 3c3f3
+.enemy_first
and a
ret
-; 3c3f5
-CheckContestBattleOver: ; 3c3f5
+CheckContestBattleOver:
ld a, [wBattleType]
cp BATTLETYPE_CONTEST
jr nz, .contest_not_over
@@ -575,8 +564,8 @@ CheckContestBattleOver: ; 3c3f5
and a
jr nz, .contest_not_over
ld a, [wBattleResult]
- and $c0
- add $2
+ and BATTLERESULT_BITMASK
+ add DRAW
ld [wBattleResult], a
scf
ret
@@ -584,9 +573,8 @@ CheckContestBattleOver: ; 3c3f5
.contest_not_over
and a
ret
-; 3c410
-CheckPlayerLockedIn: ; 3c410
+CheckPlayerLockedIn:
ld a, [wPlayerSubStatus4]
and 1 << SUBSTATUS_RECHARGE
jp nz, .quit
@@ -610,9 +598,8 @@ CheckPlayerLockedIn: ; 3c410
.quit
scf
ret
-; 3c434
-ParsePlayerAction: ; 3c434
+ParsePlayerAction:
call CheckPlayerLockedIn
jp c, .locked_in
ld hl, wPlayerSubStatus5
@@ -706,9 +693,8 @@ ParsePlayerAction: ; 3c434
res SUBSTATUS_RAGE, [hl]
xor a
ret
-; 3c4df
-HandleEncore: ; 3c4df
+HandleEncore:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .player_1
@@ -764,9 +750,8 @@ HandleEncore: ; 3c4df
call SetPlayerTurn
ld hl, BattleText_TargetsEncoreEnded
jp StdBattleTextBox
-; 3c543
-TryEnemyFlee: ; 3c543
+TryEnemyFlee:
ld a, [wBattleMode]
dec a
jr nz, .Stay
@@ -791,7 +776,7 @@ TryEnemyFlee: ; 3c543
call BattleRandom
ld b, a
- cp 1 + (50 percent)
+ cp 50 percent + 1
jr nc, .Stay
push bc
@@ -803,7 +788,7 @@ TryEnemyFlee: ; 3c543
jr c, .Flee
ld a, b
- cp 1 + (10 percent)
+ cp 10 percent + 1
jr nc, .Stay
ld a, [wTempEnemyMonSpecies]
@@ -819,11 +804,10 @@ TryEnemyFlee: ; 3c543
.Flee:
scf
ret
-; 3c59a
INCLUDE "data/wild/flee_mons.asm"
-CompareMovePriority: ; 3c5b4
+CompareMovePriority:
; Compare the priority of the player and enemy's moves.
; Return carry if the player goes first, or z if they match.
@@ -836,9 +820,8 @@ CompareMovePriority: ; 3c5b4
pop bc
cp b
ret
-; 3c5c5
-GetMovePriority: ; 3c5c5
+GetMovePriority:
; Return the priority (0-3) of move a.
ld b, a
@@ -864,11 +847,10 @@ GetMovePriority: ; 3c5c5
.done
ld a, [hl]
ret
-; 3c5df
INCLUDE "data/moves/effects_priorities.asm"
-GetMoveEffect: ; 3c5ec
+GetMoveEffect:
ld a, b
dec a
ld hl, Moves + MOVE_EFFECT
@@ -878,9 +860,8 @@ GetMoveEffect: ; 3c5ec
call GetFarByte
ld b, a
ret
-; 3c5fe
-Battle_EnemyFirst: ; 3c5fe
+Battle_EnemyFirst:
call LoadTileMapToTempTileMap
call TryEnemyFlee
jp c, WildFled_EnemyFled_LinkBattleCanceled
@@ -922,9 +903,8 @@ Battle_EnemyFirst: ; 3c5fe
xor a
ld [wBattlePlayerAction], a
ret
-; 3c664
-Battle_PlayerFirst: ; 3c664
+Battle_PlayerFirst:
xor a
ld [wEnemyGoesFirst], a
call SetEnemyTurn
@@ -972,23 +952,20 @@ Battle_PlayerFirst: ; 3c664
xor a
ld [wBattlePlayerAction], a
ret
-; 3c6cf
-PlayerTurn_EndOpponentProtectEndureDestinyBond: ; 3c6cf
+PlayerTurn_EndOpponentProtectEndureDestinyBond:
call SetPlayerTurn
call EndUserDestinyBond
callfar DoPlayerTurn
jp EndOpponentProtectEndureDestinyBond
-; 3c6de
-EnemyTurn_EndOpponentProtectEndureDestinyBond: ; 3c6de
+EnemyTurn_EndOpponentProtectEndureDestinyBond:
call SetEnemyTurn
call EndUserDestinyBond
callfar DoEnemyTurn
jp EndOpponentProtectEndureDestinyBond
-; 3c6ed
-EndOpponentProtectEndureDestinyBond: ; 3c6ed
+EndOpponentProtectEndureDestinyBond:
ld a, BATTLE_VARS_SUBSTATUS1_OPP
call GetBattleVarAddr
res SUBSTATUS_PROTECT, [hl]
@@ -997,33 +974,30 @@ EndOpponentProtectEndureDestinyBond: ; 3c6ed
call GetBattleVarAddr
res SUBSTATUS_DESTINY_BOND, [hl]
ret
-; 3c6fe
-EndUserDestinyBond: ; 3c6fe
+EndUserDestinyBond:
ld a, BATTLE_VARS_SUBSTATUS5
call GetBattleVarAddr
res SUBSTATUS_DESTINY_BOND, [hl]
ret
-; 3c706
-HasUserFainted: ; 3c706
+HasUserFainted:
ld a, [hBattleTurn]
and a
jr z, HasPlayerFainted
-HasEnemyFainted: ; 3c70b
+HasEnemyFainted:
ld hl, wEnemyMonHP
jr CheckIfHPIsZero
-HasPlayerFainted: ; 3c710
+HasPlayerFainted:
ld hl, wBattleMonHP
-CheckIfHPIsZero: ; 3c713
+CheckIfHPIsZero:
ld a, [hli]
or [hl]
ret
-; 3c716
-ResidualDamage: ; 3c716
+ResidualDamage:
; Return z if the user fainted before
; or as a result of residual damage.
; For Sandstorm damage, see HandleWeather.
@@ -1158,9 +1132,8 @@ ResidualDamage: ; 3c716
call DelayFrames
xor a
ret
-; 3c801
-HandlePerishSong: ; 3c801
+HandlePerishSong:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .EnemyFirst
@@ -1227,9 +1200,8 @@ HandlePerishSong: ; 3c801
ld [hli], a
ld [hl], a
ret
-; 3c874
-HandleWrap: ; 3c874
+HandleWrap:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .EnemyFirst
@@ -1292,16 +1264,14 @@ HandleWrap: ; 3c874
.print_text
jp StdBattleTextBox
-; 3c8e4
-SwitchTurnCore: ; 3c8e4
+SwitchTurnCore:
ld a, [hBattleTurn]
xor 1
ld [hBattleTurn], a
ret
-; 3c8eb
-HandleLeftovers: ; 3c8eb
+HandleLeftovers:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .DoEnemyFirst
@@ -1349,9 +1319,8 @@ HandleLeftovers: ; 3c8eb
call RestoreHP
ld hl, BattleText_TargetRecoveredWithItem
jp StdBattleTextBox
-; 3c93c
-HandleMysteryberry: ; 3c93c
+HandleMysteryberry:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .DoEnemyFirst
@@ -1488,9 +1457,8 @@ HandleMysteryberry: ; 3c93c
call SwitchTurnCore
ld hl, BattleText_UserRecoveredPPUsing
jp StdBattleTextBox
-; 3ca26
-HandleFutureSight: ; 3ca26
+HandleFutureSight:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .enemy_first
@@ -1533,7 +1501,7 @@ HandleFutureSight: ; 3ca26
xor a
ld [wAttackMissed], a
ld [wAlreadyDisobeyed], a
- ld a, 10
+ ld a, EFFECTIVE
ld [wTypeModifier], a
callfar DoMove
xor a
@@ -1547,9 +1515,8 @@ HandleFutureSight: ; 3ca26
call UpdateBattleMonInParty
jp UpdateEnemyMonInParty
-; 3ca8f
-HanleDefrost: ; 3ca8f
+HandleDefrost:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .enemy_first
@@ -1607,9 +1574,8 @@ HanleDefrost: ; 3ca8f
call SetPlayerTurn
ld hl, DefrostedOpponentText
jp StdBattleTextBox
-; 3cafb
-HandleSafeguard: ; 3cafb
+HandleSafeguard:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .player1
@@ -1646,7 +1612,7 @@ HandleSafeguard: ; 3cafb
ld hl, BattleText_SafeguardFaded
jp StdBattleTextBox
-HandleScreens: ; 3cb36
+HandleScreens:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .Both
@@ -1681,15 +1647,13 @@ HandleScreens: ; 3cb36
.Copy:
ld hl, wStringBuffer1
jp CopyName2
-; 3cb75
.Your:
db "Your@"
.Enemy:
db "Enemy@"
-; 3cb80
-.LightScreenTick: ; 3cb80
+.LightScreenTick:
ld a, [de]
dec a
ld [de], a
@@ -1697,25 +1661,23 @@ HandleScreens: ; 3cb36
res SCREENS_LIGHT_SCREEN, [hl]
push hl
push de
- ld hl, BattleText_PkmnLightScreenFell
+ ld hl, BattleText_MonsLightScreenFell
call StdBattleTextBox
pop de
pop hl
ret
-; 3cb91
-.ReflectTick: ; 3cb91
+.ReflectTick:
inc de
ld a, [de]
dec a
ld [de], a
ret nz
res SCREENS_REFLECT, [hl]
- ld hl, BattleText_PkmnReflectFaded
+ ld hl, BattleText_MonsReflectFaded
jp StdBattleTextBox
-; 3cb9e
-HandleWeather: ; 3cb9e
+HandleWeather:
ld a, [wBattleWeather]
cp WEATHER_NONE
ret z
@@ -1804,30 +1766,29 @@ HandleWeather: ; 3cb9e
ld h, [hl]
ld l, a
jp StdBattleTextBox
-; 3cc2d
.WeatherMessages:
+; entries correspond to WEATHER_* constants
dw BattleText_RainContinuesToFall
dw BattleText_TheSunlightIsStrong
dw BattleText_TheSandstormRages
+
.WeatherEndedMessages:
+; entries correspond to WEATHER_* constants
dw BattleText_TheRainStopped
dw BattleText_TheSunlightFaded
dw BattleText_TheSandstormSubsided
-; 3cc39
-SubtractHPFromTarget: ; 3cc39
+SubtractHPFromTarget:
call SubtractHP
jp UpdateHPBar
-; 3cc3f
-SubtractHPFromUser: ; 3cc3f
-; Subtract HP from Pkmn
+SubtractHPFromUser:
+; Subtract HP from mon
call SubtractHP
jp UpdateHPBarBattleHuds
-; 3cc45
-SubtractHP: ; 3cc45
+SubtractHP:
ld hl, wBattleMonHP
ld a, [hBattleTurn]
and a
@@ -1857,9 +1818,8 @@ SubtractHP: ; 3cc45
ld [wBuffer5], a
ld [wBuffer6], a
ret
-; 3cc76
-GetSixteenthMaxHP: ; 3cc76
+GetSixteenthMaxHP:
call GetQuarterMaxHP
; quarter result
srl c
@@ -1871,9 +1831,8 @@ GetSixteenthMaxHP: ; 3cc76
inc c
.ok
ret
-; 3cc83
-GetEighthMaxHP: ; 3cc83
+GetEighthMaxHP:
; output: bc
call GetQuarterMaxHP
; assumes nothing can have 1024 or more hp
@@ -1886,9 +1845,8 @@ GetEighthMaxHP: ; 3cc83
inc c
.end
ret
-; 3cc8e
-GetQuarterMaxHP: ; 3cc8e
+GetQuarterMaxHP:
; output: bc
call GetMaxHP
@@ -1906,9 +1864,8 @@ GetQuarterMaxHP: ; 3cc8e
inc c
.end
ret
-; 3cc9f
-GetHalfMaxHP: ; 3cc9f
+GetHalfMaxHP:
; output: bc
call GetMaxHP
@@ -1923,9 +1880,8 @@ GetHalfMaxHP: ; 3cc9f
inc c
.end
ret
-; 3ccac
-GetMaxHP: ; 3ccac
+GetMaxHP:
; output: bc, wBuffer1-2
ld hl, wBattleMonMaxHP
@@ -1942,9 +1898,8 @@ GetMaxHP: ; 3ccac
ld [wBuffer1], a
ld c, a
ret
-; 3ccc2
-Unreferenced_GetHalfHP: ; 3ccc2
+Unreferenced_GetHalfHP:
ld hl, wBattleMonHP
ld a, [hBattleTurn]
and a
@@ -1962,9 +1917,8 @@ Unreferenced_GetHalfHP: ; 3ccc2
ld a, [hl]
ld [wBuffer1], a
ret
-; 3ccde
-CheckUserHasEnoughHP: ; 3ccde
+CheckUserHasEnoughHP:
ld hl, wBattleMonHP + 1
ld a, [hBattleTurn]
and a
@@ -1977,9 +1931,8 @@ CheckUserHasEnoughHP: ; 3ccde
ld a, b
sbc [hl]
ret
-; 3ccef
-RestoreHP ; 3ccef
+RestoreHP
ld hl, wEnemyMonMaxHP
ld a, [hBattleTurn]
and a
@@ -2022,14 +1975,12 @@ RestoreHP ; 3ccef
call SwitchTurnCore
call UpdateHPBarBattleHuds
jp SwitchTurnCore
-; 3cd36
-UpdateHPBarBattleHuds: ; 3cd36
+UpdateHPBarBattleHuds:
call UpdateHPBar
jp UpdateBattleHuds
-; 3cd3c
-UpdateHPBar: ; 3cd3c
+UpdateHPBar:
hlcoord 10, 9
ld a, [hBattleTurn]
and a
@@ -2043,9 +1994,8 @@ UpdateHPBar: ; 3cd3c
predef AnimateHPBar
pop bc
ret
-; 3cd55
-HandleEnemyMonFaint: ; 3cd55
+HandleEnemyMonFaint:
call FaintEnemyPokemon
ld hl, wBattleMonHP
ld a, [hli]
@@ -2054,7 +2004,7 @@ HandleEnemyMonFaint: ; 3cd55
xor a
ld [wWhichMonFaintedFirst], a
call UpdateBattleStateAndExperienceAfterEnemyFaint
- call CheckPlayerPartyForFitPkmn
+ call CheckPlayerPartyForFitMon
ld a, d
and a
jp z, LostBattle
@@ -2112,9 +2062,8 @@ HandleEnemyMonFaint: ; 3cd55
xor a
ld [wBattlePlayerAction], a
ret
-; 3cdca
-DoubleSwitch: ; 3cdca
+DoubleSwitch:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .player_1
@@ -2142,9 +2091,8 @@ DoubleSwitch: ; 3cdca
xor a
ld [wBattlePlayerAction], a
ret
-; 3ce01
-UpdateBattleStateAndExperienceAfterEnemyFaint: ; 3ce01
+UpdateBattleStateAndExperienceAfterEnemyFaint:
call UpdateBattleMonInParty
ld a, [wBattleMode]
dec a
@@ -2186,7 +2134,7 @@ UpdateBattleStateAndExperienceAfterEnemyFaint: ; 3ce01
call PlayerMonFaintHappinessMod
.player_mon_did_not_faint
- call CheckPlayerPartyForFitPkmn
+ call CheckPlayerPartyForFitMon
ld a, d
and a
ret z
@@ -2196,8 +2144,8 @@ UpdateBattleStateAndExperienceAfterEnemyFaint: ; 3ce01
call EmptyBattleTextBox
call LoadTileMapToTempTileMap
ld a, [wBattleResult]
- and $c0
- ld [wBattleResult], a
+ and BATTLERESULT_BITMASK
+ ld [wBattleResult], a ; WIN
call IsAnyMonHoldingExpShare
jr z, .skip_exp
ld hl, wEnemyMonBaseStats
@@ -2233,9 +2181,8 @@ UpdateBattleStateAndExperienceAfterEnemyFaint: ; 3ce01
pop af
ld [wBattleParticipantsNotFainted], a
ret
-; 3ceaa
-IsAnyMonHoldingExpShare: ; 3ceaa
+IsAnyMonHoldingExpShare:
ld a, [wPartyCount]
ld b, a
ld hl, wPartyMon1
@@ -2289,15 +2236,13 @@ IsAnyMonHoldingExpShare: ; 3ceaa
ld a, e
and a
ret
-; 3ceec
-StopDangerSound: ; 3ceec
+StopDangerSound:
xor a
ld [wLowHealthAlarm], a
ret
-; 3cef1
-FaintYourPokemon: ; 3cef1
+FaintYourPokemon:
call StopDangerSound
call WaitSFX
ld a, $f0
@@ -2308,11 +2253,10 @@ FaintYourPokemon: ; 3cef1
hlcoord 9, 7
lb bc, 5, 11
call ClearBox
- ld hl, BattleText_PkmnFainted
+ ld hl, BattleText_MonFainted
jp StdBattleTextBox
-; 3cf14
-FaintEnemyPokemon: ; 3cf14
+FaintEnemyPokemon:
call WaitSFX
ld de, SFX_KINESIS
call PlaySFX
@@ -2322,11 +2266,10 @@ FaintEnemyPokemon: ; 3cf14
hlcoord 1, 0
lb bc, 4, 10
call ClearBox
- ld hl, BattleText_EnemyPkmnFainted
+ ld hl, BattleText_EnemyMonFainted
jp StdBattleTextBox
-; 3cf35
-CheckEnemyTrainerDefeated: ; 3cf35
+CheckEnemyTrainerDefeated:
ld a, [wOTPartyCount]
ld b, a
xor a
@@ -2344,9 +2287,8 @@ CheckEnemyTrainerDefeated: ; 3cf35
and a
ret
-; 3cf4a
-HandleEnemySwitch: ; 3cf4a
+HandleEnemySwitch:
ld hl, wEnemyHPPal
ld e, HP_BAR_LENGTH_PX
call UpdateHPPal
@@ -2371,9 +2313,8 @@ HandleEnemySwitch: ; 3cf4a
jr nz, EnemyPartyMonEntrance
inc a
ret
-; 3cf78
-EnemyPartyMonEntrance: ; 3cf78
+EnemyPartyMonEntrance:
push af
xor a
ld [wEnemySwitchMonIndex], a
@@ -2397,9 +2338,8 @@ EnemyPartyMonEntrance: ; 3cf78
ld [wBattlePlayerAction], a
inc a
ret
-; 3cfa4
-WinTrainerBattle: ; 3cfa4
+WinTrainerBattle:
; Player won the battle
call StopDangerSound
ld a, $1
@@ -2471,22 +2411,22 @@ WinTrainerBattle: ; 3cfa4
call nz, .DoubleReward
call .CheckMaxedOutMomMoney
push af
- ld a, $0
+ ld a, FALSE
jr nc, .okay
ld a, [wMomSavingMoney]
- and $7
- cp $3
+ and MOM_SAVING_MONEY_MASK
+ cp (1 << MOM_SAVING_SOME_MONEY_F) | (1 << MOM_SAVING_HALF_MONEY_F)
jr nz, .okay
- inc a
+ inc a ; TRUE
.okay
ld b, a
- ld c, $4
+ ld c, 4
.loop
ld a, b
and a
jr z, .loop2
- call .SendMoneyToMom
+ call .AddMoneyToMom
dec c
dec b
jr .loop
@@ -2505,7 +2445,7 @@ WinTrainerBattle: ; 3cfa4
pop af
jr nc, .KeepItAll
ld a, [wMomSavingMoney]
- and $7
+ and MOM_SAVING_MONEY_MASK
jr z, .KeepItAll
ld hl, .SentToMomTexts
dec a
@@ -2521,27 +2461,24 @@ WinTrainerBattle: ; 3cfa4
.KeepItAll:
ld hl, GotMoneyForWinningText
jp StdBattleTextBox
-; 3d081
-.SendMoneyToMom: ; 3d081
+.AddMoneyToMom:
push bc
ld hl, wBattleReward + 2
ld de, wMomsMoney + 2
call AddBattleMoneyToAccount
pop bc
ret
-; 3d08d
-.AddMoneyToWallet: ; 3d08d
+.AddMoneyToWallet:
push bc
ld hl, wBattleReward + 2
ld de, wMoney + 2
call AddBattleMoneyToAccount
pop bc
ret
-; 3d099
-.DoubleReward: ; 3d099
+.DoubleReward:
ld hl, wBattleReward + 2
sla [hl]
dec hl
@@ -2554,15 +2491,14 @@ WinTrainerBattle: ; 3cfa4
ld [hli], a
ld [hl], a
ret
-; 3d0ab
-.SentToMomTexts: ; 3d0ab
+.SentToMomTexts:
+; entries correspond to MOM_SAVING_* constants
dw SentSomeToMomText
dw SentHalfToMomText
dw SentAllToMomText
-; 3d0b1
-.CheckMaxedOutMomMoney: ; 3d0b1
+.CheckMaxedOutMomMoney:
ld hl, wMomsMoney + 2
ld a, [hld]
cp LOW(MAX_MONEY)
@@ -2571,10 +2507,9 @@ WinTrainerBattle: ; 3cfa4
ld a, [hl]
sbc HIGH(MAX_MONEY >> 8)
ret
-; 3d0be
-AddBattleMoneyToAccount: ; 3d0be
- ld c, $3
+AddBattleMoneyToAccount:
+ ld c, 3
and a
push de
push hl
@@ -2606,9 +2541,8 @@ AddBattleMoneyToAccount: ; 3d0be
inc hl
ld [hl], LOW(MAX_MONEY)
ret
-; 3d0ea
-PlayVictoryMusic: ; 3d0ea
+PlayVictoryMusic:
push de
ld de, MUSIC_NONE
call PlayMusic
@@ -2642,26 +2576,24 @@ PlayVictoryMusic: ; 3d0ea
.lost
pop de
ret
-; 3d123
-IsKantoGymLeader: ; 0x3d123
+IsKantoGymLeader:
ld hl, KantoGymLeaders
jr IsGymLeaderCommon
-IsGymLeader: ; 0x3d128
+IsGymLeader:
ld hl, GymLeaders
IsGymLeaderCommon:
push de
ld a, [wOtherTrainerClass]
- ld de, $1
+ ld de, 1
call IsInArray
pop de
ret
-; 0x3d137
INCLUDE "data/trainers/leaders.asm"
-HandlePlayerMonFaint: ; 3d14e
+HandlePlayerMonFaint:
call FaintYourPokemon
ld hl, wEnemyMonHP
ld a, [hli]
@@ -2670,7 +2602,7 @@ HandlePlayerMonFaint: ; 3d14e
ld a, $1
ld [wWhichMonFaintedFirst], a
call PlayerMonFaintHappinessMod
- call CheckPlayerPartyForFitPkmn
+ call CheckPlayerPartyForFitMon
ld a, d
and a
jp z, LostBattle
@@ -2709,9 +2641,8 @@ HandlePlayerMonFaint: ; 3d14e
call HandleEnemySwitch
jp z, WildFled_EnemyFled_LinkBattleCanceled
jp DoubleSwitch
-; 3d1aa
-PlayerMonFaintHappinessMod: ; 3d1aa
+PlayerMonFaintHappinessMod:
ld a, [wCurBattleMon]
ld c, a
ld hl, wBattleParticipantsNotFainted
@@ -2741,16 +2672,15 @@ PlayerMonFaintHappinessMod: ; 3d1aa
ld [wCurPartyMon], a
callfar ChangeHappiness
ld a, [wBattleResult]
- and %11000000
- add $1
+ and BATTLERESULT_BITMASK
+ add LOSE
ld [wBattleResult], a
ld a, [wWhichMonFaintedFirst]
and a
ret z
ret ; ??????????
-; 3d1f8
-AskUseNextPokemon: ; 3d1f8
+AskUseNextPokemon:
call EmptyBattleTextBox
call LoadTileMapToTempTileMap
; We don't need to be here if we're in a Trainer battle,
@@ -2777,11 +2707,10 @@ AskUseNextPokemon: ; 3d1f8
ld hl, wPartyMon1Speed
ld de, wEnemyMonSpeed
jp TryToRunAwayFromBattle
-; 3d227
-ForcePlayerMonChoice: ; 3d227
+ForcePlayerMonChoice:
call EmptyBattleTextBox
- call LoadStandardMenuDataHeader
+ call LoadStandardMenuHeader
call SetUpBattlePartyMenu_NoLoop
call ForcePickPartyMonInBattle
ld a, [wLinkMode]
@@ -2829,7 +2758,7 @@ ForcePlayerMonChoice: ; 3d227
call CloseWindow
call GetMemSGBLayout
call SetPalettes
- call SendOutPkmnText
+ call SendOutMonText
call NewBattleMonStatus
call BreakAttraction
call SendOutPlayerMon
@@ -2841,9 +2770,8 @@ ForcePlayerMonChoice: ; 3d227
and a
ld c, a
ret
-; 3d2b3
-PlayerPartyMonEntrance: ; 3d2b3
+PlayerPartyMonEntrance:
ld a, [wCurBattleMon]
ld [wLastPlayerMon], a
ld a, [wCurPartyMon]
@@ -2851,7 +2779,7 @@ PlayerPartyMonEntrance: ; 3d2b3
call AddBattleParticipant
call InitBattleMon
call ResetPlayerStatLevels
- call SendOutPkmnText
+ call SendOutMonText
call NewBattleMonStatus
call BreakAttraction
call SendOutPlayerMon
@@ -2859,9 +2787,8 @@ PlayerPartyMonEntrance: ; 3d2b3
call LoadTileMapToTempTileMap
call SetPlayerTurn
jp SpikesDamage
-; 3d2e0
-CheckMobileBattleError: ; 3d2e0
+CheckMobileBattleError:
ld a, [wLinkMode]
cp LINK_MOBILE
jr nz, .not_mobile ; It's not a mobile battle
@@ -2877,15 +2804,13 @@ CheckMobileBattleError: ; 3d2e0
.not_mobile
xor a
ret
-; 3d2f1
-IsMobileBattle: ; 3d2f1
+IsMobileBattle:
ld a, [wLinkMode]
cp LINK_MOBILE
ret
-; 3d2f7
-SetUpBattlePartyMenu_NoLoop: ; 3d2f7
+SetUpBattlePartyMenu_NoLoop:
call ClearBGPalettes
SetUpBattlePartyMenu: ; switch to fullscreen menu?
farcall LoadPartyMenuGFX
@@ -2893,18 +2818,16 @@ SetUpBattlePartyMenu: ; switch to fullscreen menu?
farcall InitPartyMenuBGPal7
farcall InitPartyMenuGFX
ret
-; 3d313
-JumpToPartyMenuAndPrintText: ; 3d313
+JumpToPartyMenuAndPrintText:
farcall WritePartyMenuTilemap
farcall PrintPartyMenuText
call WaitBGMap
call SetPalettes
call DelayFrame
ret
-; 3d329
-SelectBattleMon: ; 3d329
+SelectBattleMon:
call IsMobileBattle
jr z, .mobile
farcall PartyMenuSelect
@@ -2913,9 +2836,8 @@ SelectBattleMon: ; 3d329
.mobile
farcall Mobile_PartyMenuSelect
ret
-; 3d33c
-PickPartyMonInBattle: ; 3d33c
+PickPartyMonInBattle:
.loop
ld a, PARTYMENUACTION_SWITCH ; Which PKMN?
ld [wPartyMenuActionText], a
@@ -2926,15 +2848,14 @@ PickPartyMonInBattle: ; 3d33c
jr z, .loop
xor a
ret
-; 3d34f
-SwitchMonAlreadyOut: ; 3d34f
+SwitchMonAlreadyOut:
ld hl, wCurBattleMon
ld a, [wCurPartyMon]
cp [hl]
jr nz, .notout
- ld hl, BattleText_PkmnIsAlreadyOut
+ ld hl, BattleText_MonIsAlreadyOut
call StdBattleTextBox
scf
ret
@@ -2942,9 +2863,8 @@ SwitchMonAlreadyOut: ; 3d34f
.notout
xor a
ret
-; 3d362
-ForcePickPartyMonInBattle: ; 3d362
+ForcePickPartyMonInBattle:
; Can't back out.
.pick
@@ -2957,9 +2877,8 @@ ForcePickPartyMonInBattle: ; 3d362
call PlaySFX
call WaitSFX
jr .pick
-; 3d375
-PickSwitchMonInBattle: ; 3d375
+PickSwitchMonInBattle:
.pick
call PickPartyMonInBattle
ret c
@@ -2967,9 +2886,8 @@ PickSwitchMonInBattle: ; 3d375
jr c, .pick
xor a
ret
-; 3d380
-ForcePickSwitchMonInBattle: ; 3d380
+ForcePickSwitchMonInBattle:
; Can't back out.
.pick
@@ -2981,9 +2899,8 @@ ForcePickSwitchMonInBattle: ; 3d380
xor a
ret
-; 3d38e
-LostBattle: ; 3d38e
+LostBattle:
ld a, 1
ld [wBattleEnded], a
@@ -3046,8 +2963,8 @@ LostBattle: ; 3d38e
jr nz, .not_tied
ld hl, TiedAgainstText
ld a, [wBattleResult]
- and $c0
- add 2
+ and BATTLERESULT_BITMASK
+ add DRAW
ld [wBattleResult], a
jr .text
@@ -3077,21 +2994,18 @@ LostBattle: ; 3d38e
farcall Mobile_PrintOpponentBattleMessage
scf
ret
-; 3d432
-EnemyMonFaintedAnimation: ; 3d432
+EnemyMonFaintedAnimation:
hlcoord 12, 5
decoord 12, 6
jp MonFaintedAnimation
-; 3d43b
-PlayerMonFaintedAnimation: ; 3d43b
+PlayerMonFaintedAnimation:
hlcoord 1, 10
decoord 1, 11
jp MonFaintedAnimation
-; 3d444
-MonFaintedAnimation: ; 3d444
+MonFaintedAnimation:
ld a, [wcfbe]
push af
set 6, a
@@ -3140,13 +3054,11 @@ MonFaintedAnimation: ; 3d444
pop af
ld [wcfbe], a
ret
-; 3d488
.Spaces:
db " @"
-; 3d490
-SlideBattlePicOut: ; 3d490
+SlideBattlePicOut:
ld [hMapObjectIndexBuffer], a
ld c, a
.loop
@@ -3168,9 +3080,8 @@ SlideBattlePicOut: ; 3d490
dec c
jr nz, .loop
ret
-; 3d4ae
-.DoFrame: ; 3d4ae
+.DoFrame:
ld a, [hMapObjectIndexBuffer]
ld c, a
cp $8
@@ -3190,39 +3101,37 @@ SlideBattlePicOut: ; 3d490
dec c
jr nz, .back
ret
-; 3d4c3
-ForceEnemySwitch: ; 3d4c3
+ForceEnemySwitch:
call ResetEnemyBattleVars
ld a, [wEnemySwitchMonIndex]
dec a
ld b, a
- call LoadEnemyPkmnToSwitchTo
+ call LoadEnemyMonToSwitchTo
call ClearEnemyMonBox
call NewEnemyMonStatus
call ResetEnemyStatLevels
- call Function_SetEnemyPkmnAndSendOutAnimation
+ call Function_SetEnemyMonAndSendOutAnimation
call BreakAttraction
call ResetBattleParticipants
ret
-; 3d4e1
-EnemySwitch: ; 3d4e1
+EnemySwitch:
call CheckWhetherToAskSwitch
jr nc, EnemySwitch_SetMode
; Shift Mode
call ResetEnemyBattleVars
call CheckWhetherSwitchmonIsPredetermined
jr c, .skip
- call FindPkmnInOTPartyToSwitchIntoBattle
+ call FindMonInOTPartyToSwitchIntoBattle
.skip
- ; 'b' contains the PartyNr of the Pkmn the AI will switch to
- call LoadEnemyPkmnToSwitchTo
+ ; 'b' contains the PartyNr of the mon the AI will switch to
+ call LoadEnemyMonToSwitchTo
call OfferSwitch
push af
call ClearEnemyMonBox
call Function_BattleTextEnemySentOut
- call Function_SetEnemyPkmnAndSendOutAnimation
+ call Function_SetEnemyMonAndSendOutAnimation
pop af
ret c
; If we're here, then we're switching too
@@ -3234,24 +3143,22 @@ EnemySwitch: ; 3d4e1
ld [wEnemyIsSwitching], a
call LoadTileMapToTempTileMap
jp PlayerSwitch
-; 3d517
-EnemySwitch_SetMode: ; 3d517
+EnemySwitch_SetMode:
call ResetEnemyBattleVars
call CheckWhetherSwitchmonIsPredetermined
jr c, .skip
- call FindPkmnInOTPartyToSwitchIntoBattle
+ call FindMonInOTPartyToSwitchIntoBattle
.skip
- ; 'b' contains the PartyNr of the Pkmn the AI will switch to
- call LoadEnemyPkmnToSwitchTo
+ ; 'b' contains the PartyNr of the mon the AI will switch to
+ call LoadEnemyMonToSwitchTo
ld a, 1
ld [wEnemyIsSwitching], a
call ClearEnemyMonBox
call Function_BattleTextEnemySentOut
- jp Function_SetEnemyPkmnAndSendOutAnimation
-; 3d533
+ jp Function_SetEnemyMonAndSendOutAnimation
-CheckWhetherSwitchmonIsPredetermined: ; 3d533
+CheckWhetherSwitchmonIsPredetermined:
; returns carry if: ???
ld a, [wLinkMode]
and a
@@ -3283,9 +3190,8 @@ CheckWhetherSwitchmonIsPredetermined: ; 3d533
.return_carry
scf
ret
-; 3d557
-ResetEnemyBattleVars: ; 3d557
+ResetEnemyBattleVars:
; and draw empty TextBox
xor a
ld [wLastPlayerCounterMove], a
@@ -3300,14 +3206,13 @@ ResetEnemyBattleVars: ; 3d557
ld a, 8
call SlideBattlePicOut
call EmptyBattleTextBox
- jp LoadStandardMenuDataHeader
-; 3d57a
+ jp LoadStandardMenuHeader
-ResetBattleParticipants: ; 3d57a
+ResetBattleParticipants:
xor a
ld [wBattleParticipantsNotFainted], a
ld [wBattleParticipantsIncludingFainted], a
-AddBattleParticipant: ; 3d581
+AddBattleParticipant:
ld a, [wCurBattleMon]
ld c, a
ld hl, wBattleParticipantsNotFainted
@@ -3317,10 +3222,9 @@ AddBattleParticipant: ; 3d581
pop bc
ld hl, wBattleParticipantsIncludingFainted
predef_jump SmallFarFlagAction
-; 3d599
-FindPkmnInOTPartyToSwitchIntoBattle: ; 3d599
- ld b, $ff
+FindMonInOTPartyToSwitchIntoBattle:
+ ld b, -1
ld a, $1
ld [wBuffer1], a
ld [wBuffer2], a
@@ -3347,16 +3251,15 @@ FindPkmnInOTPartyToSwitchIntoBattle: ; 3d599
pop bc
jr z, .discourage
call LookUpTheEffectivenessOfEveryMove
- call IsThePlayerPkmnTypesEffectiveAgainstOTPkmn
+ call IsThePlayerMonTypesEffectiveAgainstOTMon
jr .loop
.discourage
ld hl, wBuffer2
set 0, [hl]
jr .loop
-; 3d5d7
-LookUpTheEffectivenessOfEveryMove: ; 3d5d7
+LookUpTheEffectivenessOfEveryMove:
push bc
ld hl, wOTPartyMon1Moves
ld a, b
@@ -3392,11 +3295,10 @@ LookUpTheEffectivenessOfEveryMove: ; 3d5d7
ret
.done
ret
-; 3d618
-IsThePlayerPkmnTypesEffectiveAgainstOTPkmn: ; 3d618
-; Calculates the effectiveness of the types of the PlayerPkmn
-; against the OTPkmn
+IsThePlayerMonTypesEffectiveAgainstOTMon:
+; Calculates the effectiveness of the types of the PlayerMon
+; against the OTMon
push bc
ld hl, wOTPartyCount
ld a, b
@@ -3441,9 +3343,8 @@ IsThePlayerPkmnTypesEffectiveAgainstOTPkmn: ; 3d618
.reset
res 0, [hl]
ret
-; 3d672
-ScoreMonTypeMatchups: ; 3d672
+ScoreMonTypeMatchups:
.loop1
ld hl, wBuffer1
sla [hl]
@@ -3464,7 +3365,7 @@ ScoreMonTypeMatchups: ; 3d672
ld a, [wBuffer1]
and a
jr z, .okay2
- ld b, $ff
+ ld b, -1
ld c, a
.loop3
inc b
@@ -3473,7 +3374,7 @@ ScoreMonTypeMatchups: ; 3d672
jr .quit
.okay2
- ld b, $ff
+ ld b, -1
ld a, [wBuffer2]
ld c, a
.loop4
@@ -3506,10 +3407,9 @@ ScoreMonTypeMatchups: ; 3d672
.quit
ret
-; 3d6ca
-LoadEnemyPkmnToSwitchTo: ; 3d6ca
- ; 'b' contains the PartyNr of the Pkmn the AI will switch to
+LoadEnemyMonToSwitchTo:
+ ; 'b' contains the PartyNr of the mon the AI will switch to
ld a, b
ld [wCurPartyMon], a
ld hl, wOTPartyMon1Level
@@ -3545,9 +3445,8 @@ LoadEnemyPkmnToSwitchTo: ; 3d6ca
ld a, [hl]
ld [wEnemyHPAtTimeOfPlayerSwitch + 1], a
ret
-; 3d714
-CheckWhetherToAskSwitch: ; 3d714
+CheckWhetherToAskSwitch:
ld a, [wBattleHasJustStarted]
dec a
jp z, .return_nc
@@ -3575,13 +3474,12 @@ CheckWhetherToAskSwitch: ; 3d714
.return_nc
and a
ret
-; 3d74b
-OfferSwitch: ; 3d74b
+OfferSwitch:
ld a, [wCurPartyMon]
push af
callfar Battle_GetTrainerName
- ld hl, BattleText_EnemyIsAboutToUseWillPlayerChangePkmn
+ ld hl, BattleText_EnemyIsAboutToUseWillPlayerChangeMon
call StdBattleTextBox
lb bc, 1, 7
call PlaceYesNoBox
@@ -3616,9 +3514,8 @@ OfferSwitch: ; 3d74b
ld [wCurPartyMon], a
scf
ret
-; 3d7a0
-ClearEnemyMonBox: ; 3d7a0
+ClearEnemyMonBox:
xor a
ld [hBGMapMode], a
call ExitMenu
@@ -3628,23 +3525,21 @@ ClearEnemyMonBox: ; 3d7a0
call ClearBox
call WaitBGMap
jp FinishBattleAnim
-; 3d7b8
-Function_BattleTextEnemySentOut: ; 3d7b8
+Function_BattleTextEnemySentOut:
callfar Battle_GetTrainerName
ld hl, BattleText_EnemySentOut
call StdBattleTextBox
jp WaitBGMap
-; 3d7c7
-Function_SetEnemyPkmnAndSendOutAnimation: ; 3d7c7
+Function_SetEnemyMonAndSendOutAnimation:
ld a, [wTempEnemyMonSpecies]
ld [wCurPartySpecies], a
ld [wCurSpecies], a
call GetBaseData
ld a, OTPARTYMON
ld [wMonType], a
- predef CopyPkmnToTempMon
+ predef CopyMonToTempMon
call GetEnemyMonFrontpic
xor a
@@ -3684,9 +3579,8 @@ Function_SetEnemyPkmnAndSendOutAnimation: ; 3d7c7
ld a, $1
ld [hBGMapMode], a
ret
-; 3d834
-NewEnemyMonStatus: ; 3d834
+NewEnemyMonStatus:
xor a
ld [wLastPlayerCounterMove], a
ld [wLastEnemyCounterMove], a
@@ -3708,9 +3602,8 @@ endr
ld hl, wPlayerSubStatus5
res SUBSTATUS_CANT_RUN, [hl]
ret
-; 3d867
-ResetEnemyStatLevels: ; 3d867
+ResetEnemyStatLevels:
ld a, BASE_STAT_LEVEL
ld b, NUM_LEVEL_STATS
ld hl, wEnemyStatLevels
@@ -3719,27 +3612,25 @@ ResetEnemyStatLevels: ; 3d867
dec b
jr nz, .loop
ret
-; 3d873
-CheckPlayerPartyForFitPkmn: ; 3d873
-; Has the player any Pkmn in his Party that can fight?
+CheckPlayerPartyForFitMon:
+; Has the player any mon in his Party that can fight?
ld a, [wPartyCount]
ld e, a
xor a
ld hl, wPartyMon1HP
- ld bc, wPartyMon2 - (wPartyMon1 + 1)
+ ld bc, PARTYMON_STRUCT_LENGTH - 1
.loop
or [hl]
- inc hl
+ inc hl ; + 1
or [hl]
add hl, bc
dec e
jr nz, .loop
ld d, a
ret
-; 3d887
-CheckIfCurPartyMonIsFitToFight: ; 3d887
+CheckIfCurPartyMonIsFitToFight:
ld a, [wCurPartyMon]
ld hl, wPartyMon1HP
call GetPartyLocation
@@ -3768,9 +3659,8 @@ CheckIfCurPartyMonIsFitToFight: ; 3d887
.finish_fail
xor a
ret
-; 3d8b3
-TryToRunAwayFromBattle: ; 3d8b3
+TryToRunAwayFromBattle:
; Run away from battle, with or without item
ld a, [wBattleType]
cp BATTLETYPE_DEBUG
@@ -3924,11 +3814,11 @@ TryToRunAwayFromBattle: ; 3d8b3
cp BATTLEACTION_FORFEIT
ld a, DRAW
jr z, .fled
- dec a
+ dec a ; LOSE
.fled
ld b, a
ld a, [wBattleResult]
- and $c0
+ and BATTLERESULT_BITMASK
add b
ld [wBattleResult], a
call StopDangerSound
@@ -3957,9 +3847,8 @@ TryToRunAwayFromBattle: ; 3d8b3
call LoadTileMapToTempTileMap
scf
ret
-; 3da0d
-InitBattleMon: ; 3da0d
+InitBattleMon:
ld a, MON_SPECIES
call GetPartyParamLocation
ld de, wBattleMonSpecies
@@ -3998,23 +3887,21 @@ InitBattleMon: ; 3da0d
call ApplyStatusEffectOnPlayerStats
call BadgeStatBoosts
ret
-; 3da74
-BattleCheckPlayerShininess: ; 3da74
+BattleCheckPlayerShininess:
call GetPartyMonDVs
jr BattleCheckShininess
-BattleCheckEnemyShininess: ; 3da79
+BattleCheckEnemyShininess:
call GetEnemyMonDVs
-BattleCheckShininess: ; 3da7c
+BattleCheckShininess:
ld b, h
ld c, l
callfar CheckShininess
ret
-; 3da85
-GetPartyMonDVs: ; 3da85
+GetPartyMonDVs:
ld hl, wBattleMonDVs
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TRANSFORMED, a
@@ -4022,9 +3909,8 @@ GetPartyMonDVs: ; 3da85
ld hl, wPartyMon1DVs
ld a, [wCurBattleMon]
jp GetPartyLocation
-; 3da97
-GetEnemyMonDVs: ; 3da97
+GetEnemyMonDVs:
ld hl, wEnemyMonDVs
ld a, [wEnemySubStatus5]
bit SUBSTATUS_TRANSFORMED, a
@@ -4036,9 +3922,8 @@ GetEnemyMonDVs: ; 3da97
ld hl, wOTPartyMon1DVs
ld a, [wCurOTMon]
jp GetPartyLocation
-; 3dab1
-ResetPlayerStatLevels: ; 3dab1
+ResetPlayerStatLevels:
ld a, BASE_STAT_LEVEL
ld b, NUM_LEVEL_STATS
ld hl, wPlayerStatLevels
@@ -4047,9 +3932,8 @@ ResetPlayerStatLevels: ; 3dab1
dec b
jr nz, .loop
ret
-; 3dabd
-InitEnemyMon: ; 3dabd
+InitEnemyMon:
ld a, [wCurPartyMon]
ld hl, wOTPartyMon1Species
call GetPartyLocation
@@ -4100,9 +3984,8 @@ InitEnemyMon: ; 3dabd
ld a, [wCurPartyMon]
ld [wCurOTMon], a
ret
-; 3db32
-SwitchPlayerMon: ; 3db32
+SwitchPlayerMon:
call ClearSprites
ld a, [wCurBattleMon]
ld [wLastPlayerMon], a
@@ -4120,9 +4003,8 @@ SwitchPlayerMon: ; 3db32
ld a, [hli]
or [hl]
ret
-; 3db5f
-SendOutPlayerMon: ; 3db5f
+SendOutPlayerMon:
ld hl, wBattleMonDVs
predef GetUnownLetter
hlcoord 1, 5
@@ -4176,9 +4058,8 @@ SendOutPlayerMon: ; 3db5f
ld a, $1
ld [hBGMapMode], a
ret
-; 3dbde
-NewBattleMonStatus: ; 3dbde
+NewBattleMonStatus:
xor a
ld [wLastPlayerCounterMove], a
ld [wLastEnemyCounterMove], a
@@ -4205,17 +4086,15 @@ endr
ld hl, wEnemySubStatus5
res SUBSTATUS_CANT_RUN, [hl]
ret
-; 3dc18
-BreakAttraction: ; 3dc18
+BreakAttraction:
ld hl, wPlayerSubStatus1
res SUBSTATUS_IN_LOVE, [hl]
ld hl, wEnemySubStatus1
res SUBSTATUS_IN_LOVE, [hl]
ret
-; 3dc23
-SpikesDamage: ; 3dc23
+SpikesDamage:
ld hl, wPlayerScreens
ld de, wBattleMonType
ld bc, UpdatePlayerHUD
@@ -4254,9 +4133,8 @@ SpikesDamage: ; 3dc23
.hl
jp hl
-; 3dc5b
-PursuitSwitch: ; 3dc5b
+PursuitSwitch:
ld a, BATTLE_VARS_MOVE
call GetBattleVar
ld b, a
@@ -4308,7 +4186,7 @@ PursuitSwitch: ; 3dc5b
ld b, RESET_FLAG
predef SmallFarFlagAction
call PlayerMonFaintedAnimation
- ld hl, BattleText_PkmnFainted
+ ld hl, BattleText_MonFainted
jr .done_fainted
.check_enemy_fainted
@@ -4324,7 +4202,7 @@ PursuitSwitch: ; 3dc5b
call PlaySFX
call WaitSFX
call EnemyMonFaintedAnimation
- ld hl, BattleText_EnemyPkmnFainted
+ ld hl, BattleText_EnemyMonFainted
.done_fainted
call StdBattleTextBox
@@ -4334,9 +4212,8 @@ PursuitSwitch: ; 3dc5b
.done
and a
ret
-; 3dce6
-RecallPlayerMon: ; 3dce6
+RecallPlayerMon:
ld a, [hBattleTurn]
push af
xor a
@@ -4347,9 +4224,8 @@ RecallPlayerMon: ; 3dce6
pop af
ld [hBattleTurn], a
ret
-; 3dcf9
-HandleHealingItems: ; 3dcf9
+HandleHealingItems:
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .player_1
@@ -4371,9 +4247,8 @@ HandleHealingItems: ; 3dcf9
call HandleHPHealingItem
call UseHeldStatusHealingItem
jp UseConfusionHealingItem
-; 3dd2f
-HandleHPHealingItem: ; 3dd2f
+HandleHPHealingItem:
callfar GetOpponentItem
ld a, b
cp HELD_BERRY
@@ -4427,7 +4302,7 @@ HandleHPHealingItem: ; 3dd2f
ld c, a
dec de
ld a, [de]
- adc $0
+ adc 0
ld [wBuffer6], a
ld b, a
ld a, [hld]
@@ -4465,9 +4340,8 @@ UseOpponentItem:
callfar ConsumeHeldItem
ld hl, RecoveredUsingText
jp StdBattleTextBox
-; 3ddc8
-ItemRecoveryAnim: ; 3ddc8
+ItemRecoveryAnim:
push hl
push de
push bc
@@ -4484,11 +4358,10 @@ ItemRecoveryAnim: ; 3ddc8
pop de
pop hl
ret
-; 3dde9
-UseHeldStatusHealingItem: ; 3dde9
+UseHeldStatusHealingItem:
callfar GetOpponentItem
- ld hl, .Statuses
+ ld hl, HeldStatusHealingEffects
.loop
ld a, [hli]
cp $ff
@@ -4539,19 +4412,10 @@ UseHeldStatusHealingItem: ; 3dde9
ld a, $1
and a
ret
-; 3de44
-.Statuses: ; 3de44
- db HELD_HEAL_POISON, 1 << PSN
- db HELD_HEAL_FREEZE, 1 << FRZ
- db HELD_HEAL_BURN, 1 << BRN
- db HELD_HEAL_SLEEP, SLP
- db HELD_HEAL_PARALYZE, 1 << PAR
- db HELD_HEAL_STATUS, ALL_STATUS
- db -1 ; end
-; 3de51
+INCLUDE "data/battle/held_heal_status.asm"
-UseConfusionHealingItem: ; 3de51
+UseConfusionHealingItem:
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVar
bit SUBSTATUS_CONFUSED, a
@@ -4591,9 +4455,8 @@ UseConfusionHealingItem: ; 3de51
ld [bc], a
ld [hl], a
ret
-; 3de97
-HandleStatBoostingHeldItems: ; 3de97
+HandleStatBoostingHeldItems:
; The effects handled here are not used in-game.
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
@@ -4604,18 +4467,16 @@ HandleStatBoostingHeldItems: ; 3de97
.player_1
call .DoEnemy
jp .DoPlayer
-; 3dea9
-.DoPlayer: ; 3dea9
+.DoPlayer:
call GetPartymonItem
ld a, $0
jp .HandleItem
-; 3deb1
-.DoEnemy: ; 3deb1
+.DoEnemy:
call GetOTPartymonItem
ld a, $1
-.HandleItem: ; 3deb6
+.HandleItem:
ld [hBattleTurn], a
ld d, h
ld e, l
@@ -4624,10 +4485,10 @@ HandleStatBoostingHeldItems: ; 3de97
ld a, [bc]
ld b, a
callfar GetItemHeldEffect
- ld hl, .StatUpItems
+ ld hl, HeldStatUpItems
.loop
ld a, [hli]
- cp $ff
+ cp -1
jr z, .finish
inc hl
inc hl
@@ -4662,36 +4523,24 @@ HandleStatBoostingHeldItems: ; 3de97
pop bc
pop de
ret
-; 3defc
-.StatUpItems:
- dbw HELD_ATTACK_UP, BattleCommand_AttackUp
- dbw HELD_DEFENSE_UP, BattleCommand_DefenseUp
- dbw HELD_SPEED_UP, BattleCommand_SpeedUp
- dbw HELD_SP_ATTACK_UP, BattleCommand_SpecialAttackUp
- dbw HELD_SP_DEFENSE_UP, BattleCommand_SpecialDefenseUp
- dbw HELD_ACCURACY_UP, BattleCommand_AccuracyUp
- dbw HELD_EVASION_UP, BattleCommand_EvasionUp
- db -1 ; end
-; 3df12
+INCLUDE "data/battle/held_stat_up.asm"
-GetPartymonItem: ; 3df12
+GetPartymonItem:
ld hl, wPartyMon1Item
ld a, [wCurBattleMon]
call GetPartyLocation
ld bc, wBattleMonItem
ret
-; 3df1f
-GetOTPartymonItem: ; 3df1f
+GetOTPartymonItem:
ld hl, wOTPartyMon1Item
ld a, [wCurOTMon]
call GetPartyLocation
ld bc, wEnemyMonItem
ret
-; 3df2c
-UpdateBattleHUDs: ; 3df2c
+UpdateBattleHUDs:
push hl
push de
push bc
@@ -4706,9 +4555,8 @@ UpdateBattleHUDs: ; 3df2c
pop de
pop hl
ret
-; 3df48
-UpdatePlayerHUD:: ; 3df48
+UpdatePlayerHUD::
push hl
push de
push bc
@@ -4719,9 +4567,8 @@ UpdatePlayerHUD:: ; 3df48
pop de
pop hl
ret
-; 3df58
-DrawPlayerHUD: ; 3df58
+DrawPlayerHUD:
xor a
ld [hBGMapMode], a
@@ -4757,14 +4604,12 @@ DrawPlayerHUD: ; 3df58
call FillInExpBar
pop de
ret
-; 3df98
-UpdatePlayerHPPal: ; 3df98
+UpdatePlayerHPPal:
ld hl, wPlayerHPPal
jp UpdateHPPal
-; 3df9e
-CheckDanger: ; 3df9e
+CheckDanger:
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
@@ -4787,9 +4632,8 @@ CheckDanger: ; 3df9e
.done
ret
-; 3dfbf
-PrintPlayerHUD: ; 3dfbf
+PrintPlayerHUD:
ld de, wBattleMonNick
hlcoord 10, 7
call ret_3e138
@@ -4850,9 +4694,8 @@ PrintPlayerHUD: ; 3dfbf
ld a, [wBattleMonLevel]
ld [wTempMonLevel], a
jp PrintLevel
-; 3e036
-UpdateEnemyHUD:: ; 3e036
+UpdateEnemyHUD::
push hl
push de
push bc
@@ -4862,9 +4705,8 @@ UpdateEnemyHUD:: ; 3e036
pop de
pop hl
ret
-; 3e043
-DrawEnemyHUD: ; 3e043
+DrawEnemyHUD:
xor a
ld [hBGMapMode], a
@@ -4995,28 +4837,24 @@ DrawEnemyHUD: ; 3e043
ld b, 0
call DrawBattleHPBar
ret
-; 3e127
-UpdateEnemyHPPal: ; 3e127
+UpdateEnemyHPPal:
ld hl, wEnemyHPPal
call UpdateHPPal
ret
-; 3e12e
-UpdateHPPal: ; 3e12e
+UpdateHPPal:
ld b, [hl]
call SetHPPal
ld a, [hl]
cp b
ret z
jp FinishBattleAnim
-; 3e138
-ret_3e138: ; 3e138
+ret_3e138:
ret
-; 3e139
-BattleMenu: ; 3e139
+BattleMenu:
xor a
ld [hBGMapMode], a
call LoadTempTileMapToTileMap
@@ -5062,17 +4900,15 @@ BattleMenu: ; 3e139
cp $4
jp z, BattleMenu_Run
jr .loop
-; 3e192
-BattleMenu_Fight: ; 3e192
+BattleMenu_Fight:
xor a
ld [wNumFleeAttempts], a
call Call_LoadTempTileMapToTileMap
and a
ret
-; 3e19b
-LoadBattleMenu2: ; 3e19b
+LoadBattleMenu2:
call IsMobileBattle
jr z, .mobile
@@ -5096,9 +4932,8 @@ LoadBattleMenu2: ; 3e19b
.error
scf
ret
-; 3e1c7
-BattleMenu_Pack: ; 3e1c7
+BattleMenu_Pack:
ld a, [wLinkMode]
and a
jp nz, .ItemsCantBeUsed
@@ -5107,7 +4942,7 @@ BattleMenu_Pack: ; 3e1c7
and a
jp nz, .ItemsCantBeUsed
- call LoadStandardMenuDataHeader
+ call LoadStandardMenuHeader
ld a, [wBattleType]
cp BATTLETYPE_TUTORIAL
@@ -5148,15 +4983,13 @@ BattleMenu_Pack: ; 3e1c7
call FinishBattleAnim
call LoadTileMapToTempTileMap
jp BattleMenu
-; 3e22b
-.ItemsCantBeUsed: ; 3e22b
+.ItemsCantBeUsed:
ld hl, BattleText_ItemsCantBeUsedHere
call StdBattleTextBox
jp BattleMenu
-; 3e234
-.UseItem: ; 3e234
+.UseItem:
ld a, [wWildMon]
and a
jr nz, .run
@@ -5193,19 +5026,18 @@ BattleMenu_Pack: ; 3e1c7
xor a
ld [wWildMon], a
ld a, [wBattleResult]
- and $c0
- ld [wBattleResult], a
+ and BATTLERESULT_BITMASK
+ ld [wBattleResult], a ; WIN
call ClearWindowData
call SetPalettes
scf
ret
-; 3e28d
-BattleMenu_PKMN: ; 3e28d
- call LoadStandardMenuDataHeader
+BattleMenu_PKMN:
+ call LoadStandardMenuHeader
BattleMenuPKMN_ReturnFromStats:
call ExitMenu
- call LoadStandardMenuDataHeader
+ call LoadStandardMenuHeader
call ClearBGPalettes
BattleMenuPKMN_Loop:
call SetUpBattlePartyMenu
@@ -5249,9 +5081,8 @@ BattleMenuPKMN_Loop:
call GetMemSGBLayout
call SetPalettes
jp BattleMenu
-; 3e2f5
-.GetMenu: ; 3e2f5
+.GetMenu:
call IsMobileBattle
jr z, .mobile
farcall BattleMonMenu
@@ -5260,9 +5091,8 @@ BattleMenuPKMN_Loop:
.mobile
farcall MobileBattleMonMenu
ret
-; 3e308
-Battle_StatsScreen: ; 3e308
+Battle_StatsScreen:
call DisableLCD
ld hl, vTiles2 tile $31
@@ -5298,15 +5128,14 @@ Battle_StatsScreen: ; 3e308
call EnableLCD
ret
-; 3e358
-TryPlayerSwitch: ; 3e358
+TryPlayerSwitch:
ld a, [wCurBattleMon]
ld d, a
ld a, [wCurPartyMon]
cp d
jr nz, .check_trapped
- ld hl, BattleText_PkmnIsAlreadyOut
+ ld hl, BattleText_MonIsAlreadyOut
call StdBattleTextBox
jp BattleMenuPKMN_Loop
@@ -5319,7 +5148,7 @@ TryPlayerSwitch: ; 3e358
jr z, .try_switch
.trapped
- ld hl, BattleText_PkmnCantBeRecalled
+ ld hl, BattleText_MonCantBeRecalled
call StdBattleTextBox
jp BattleMenuPKMN_Loop
@@ -5339,13 +5168,13 @@ TryPlayerSwitch: ; 3e358
call SetPalettes
ld a, [wCurPartyMon]
ld [wCurBattleMon], a
-PlayerSwitch: ; 3e3ad
+PlayerSwitch:
ld a, 1
ld [wPlayerIsSwitching], a
ld a, [wLinkMode]
and a
jr z, .not_linked
- call LoadStandardMenuDataHeader
+ call LoadStandardMenuHeader
call LinkBattleSendReceiveAction
call CloseWindow
@@ -5387,16 +5216,14 @@ PlayerSwitch: ; 3e3ad
call BattleMonEntrance
and a
ret
-; 3e3ff
-EnemyMonEntrance: ; 3e3ff
+EnemyMonEntrance:
callfar AI_Switch
call SetEnemyTurn
jp SpikesDamage
-; 3e40b
-BattleMonEntrance: ; 3e40b
- call WithdrawPkmnText
+BattleMonEntrance:
+ call WithdrawMonText
ld c, 50
call DelayFrames
@@ -5419,7 +5246,7 @@ BattleMonEntrance: ; 3e40b
call AddBattleParticipant
call InitBattleMon
call ResetPlayerStatLevels
- call SendOutPkmnText
+ call SendOutMonText
call NewBattleMonStatus
call BreakAttraction
call SendOutPlayerMon
@@ -5430,9 +5257,8 @@ BattleMonEntrance: ; 3e40b
ld a, $2
ld [wMenuCursorY], a
ret
-; 3e459
-PassedBattleMonEntrance: ; 3e459
+PassedBattleMonEntrance:
ld c, 50
call DelayFrames
@@ -5452,9 +5278,8 @@ PassedBattleMonEntrance: ; 3e459
call LoadTileMapToTempTileMap
call SetPlayerTurn
jp SpikesDamage
-; 3e489
-BattleMenu_Run: ; 3e489
+BattleMenu_Run:
call Call_LoadTempTileMapToTileMap
ld a, $3
ld [wMenuCursorY], a
@@ -5468,9 +5293,8 @@ BattleMenu_Run: ; 3e489
and a
ret nz
jp BattleMenu
-; 3e4a8
-CheckAmuletCoin: ; 3e4a8
+CheckAmuletCoin:
ld a, [wBattleMonItem]
ld b, a
callfar GetItemHeldEffect
@@ -5480,9 +5304,8 @@ CheckAmuletCoin: ; 3e4a8
ld a, 1
ld [wAmuletCoin], a
ret
-; 3e4bc
-MoveSelectionScreen: ; 3e4bc
+MoveSelectionScreen:
call IsMobileBattle
jr nz, .not_mobile
farcall MobileMoveSelectionScreen
@@ -5684,11 +5507,9 @@ MoveSelectionScreen: ; 3e4bc
call StdBattleTextBox
call Call_LoadTempTileMapToTileMap
jp MoveSelectionScreen
-; 3e61c
-.string_3e61c ; 3e61c
+.string_3e61c
db "@"
-; 3e61d
.pressed_up
ld a, [wMenuCursorY]
@@ -5698,9 +5519,8 @@ MoveSelectionScreen: ; 3e4bc
inc a
ld [wMenuCursorY], a
jp .menu_loop
-; 3e62e
-.pressed_down ; 3e62e
+.pressed_down
ld a, [wMenuCursorY]
ld b, a
ld a, [wNumMoves]
@@ -5711,9 +5531,8 @@ MoveSelectionScreen: ; 3e4bc
ld a, $1
ld [wMenuCursorY], a
jp .menu_loop
-; 3e643
-.pressed_select ; 3e643
+.pressed_select
ld a, [wMoveSwapBuffer]
and a
jr z, .start_swap
@@ -5796,9 +5615,8 @@ MoveSelectionScreen: ; 3e4bc
ld a, [wMenuCursorY]
ld [wMoveSwapBuffer], a
jp MoveSelectionScreen
-; 3e6c8
-MoveInfoBox: ; 3e6c8
+MoveInfoBox:
xor a
ld [hBGMapMode], a
@@ -5868,15 +5686,13 @@ MoveInfoBox: ; 3e6c8
.done
ret
-; 3e74f
.Disabled:
db "Disabled!@"
.Type:
db "TYPE/@"
-; 3e75f
-.PrintPP: ; 3e75f
+.PrintPP:
hlcoord 5, 11
ld a, [wLinkMode] ; What's the point of this check?
cp LINK_MOBILE
@@ -5896,9 +5712,8 @@ MoveInfoBox: ; 3e6c8
lb bc, 1, 2
call PrintNum
ret
-; 3e786
-CheckPlayerHasUsableMoves: ; 3e786
+CheckPlayerHasUsableMoves:
ld a, STRUGGLE
ld [wCurPlayerMove], a
ld a, [wPlayerDisableCount]
@@ -5938,15 +5753,14 @@ CheckPlayerHasUsableMoves: ; 3e786
ret nz
.force_struggle
- ld hl, BattleText_PkmnHasNoMovesLeft
+ ld hl, BattleText_MonHasNoMovesLeft
call StdBattleTextBox
ld c, 60
call DelayFrames
xor a
ret
-; 3e7c1
-ParseEnemyAction: ; 3e7c1
+ParseEnemyAction:
ld a, [wEnemyIsSwitching]
and a
ret nz
@@ -6094,9 +5908,8 @@ ParseEnemyAction: ; 3e7c1
.struggle
ld a, STRUGGLE
jr .finish
-; 3e8c1
-ResetVarsForSubstatusRage: ; 3e8c1
+ResetVarsForSubstatusRage:
xor a
ld [wEnemyFuryCutterCount], a
ld [wEnemyProtectCount], a
@@ -6104,9 +5917,8 @@ ResetVarsForSubstatusRage: ; 3e8c1
ld hl, wEnemySubStatus4
res SUBSTATUS_RAGE, [hl]
ret
-; 3e8d1
-CheckEnemyLockedIn: ; 3e8d1
+CheckEnemyLockedIn:
ld a, [wEnemySubStatus4]
and 1 << SUBSTATUS_RECHARGE
ret nz
@@ -6119,14 +5931,12 @@ CheckEnemyLockedIn: ; 3e8d1
ld hl, wEnemySubStatus1
bit SUBSTATUS_ROLLOUT, [hl]
ret
-; 3e8e4
-LinkBattleSendReceiveAction: ; 3e8e4
+LinkBattleSendReceiveAction:
farcall _LinkBattleSendReceiveAction
ret
-; 3e8eb
-LoadEnemyMon: ; 3e8eb
+LoadEnemyMon:
; Initialize enemy monster parameters
; To do this we pull the species from wTempEnemyMonSpecies
@@ -6190,7 +6000,7 @@ LoadEnemyMon: ; 3e8eb
; 25% chance of getting an item
call BattleRandom
- cp 1 + (75 percent)
+ cp 75 percent + 1
ld a, NO_ITEM
jr c, .UpdateItem
@@ -6226,7 +6036,6 @@ LoadEnemyMon: ; 3e8eb
jp .Happiness
.InitDVs:
-
; Trainer DVs
; All trainers have preset DVs, determined by class
@@ -6408,7 +6217,7 @@ LoadEnemyMon: ; 3e8eb
ld de, wEnemyMonMaxHP
ld b, FALSE
ld hl, wEnemyMonDVs - (MON_DVS - MON_STAT_EXP + 1) ; wLinkBattleRNs + 7 ; ?
- predef CalcPkmnStats
+ predef CalcMonStats
; If we're in a trainer battle,
; get the rest of the parameters from the party struct
@@ -6464,7 +6273,7 @@ LoadEnemyMon: ; 3e8eb
.InitRoamHP:
; HP only uses the lo byte in the RoamMon struct since
-; Raikou/Entei/Suicune will have < 256 hp at level 40
+; Raikou and Entei will have < 256 hp at level 40
ld a, [wEnemyMonHP + 1]
ld [hl], a
jr .Moves
@@ -6595,9 +6404,8 @@ LoadEnemyMon: ; 3e8eb
call CopyBytes
ret
-; 3eb38
-CheckSleepingTreeMon: ; 3eb38
+CheckSleepingTreeMon:
; Return carry if species is in the list
; for the current time of day
@@ -6628,7 +6436,7 @@ CheckSleepingTreeMon: ; 3eb38
INCLUDE "data/wild/treemons_asleep.asm"
-CheckUnownLetter: ; 3eb75
+CheckUnownLetter:
; Return carry if the Unown letter hasn't been unlocked yet
ld a, [wUnlockedUnowns]
@@ -6642,7 +6450,7 @@ CheckUnownLetter: ; 3eb75
jr nc, .next
; Is our letter in the set?
- ld hl, .LetterSets
+ ld hl, UnlockedUnownLetterSets
add hl, de
ld a, [hli]
ld h, [hl]
@@ -6663,7 +6471,7 @@ CheckUnownLetter: ; 3eb75
inc e
inc e
ld a, e
- cp .Set1 - .LetterSets
+ cp UnlockedUnownLetterSets.End - UnlockedUnownLetterSets
jr c, .loop
; Hasn't been unlocked, or the letter is invalid
@@ -6675,28 +6483,9 @@ CheckUnownLetter: ; 3eb75
and a
ret
-.LetterSets:
- dw .Set1
- dw .Set2
- dw .Set3
- dw .Set4
-
-.Set1:
- ; A B C D E F G H I J K
- db 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, $ff
-.Set2:
- ; L M N O P Q R
- db 12, 13, 14, 15, 16, 17, 18, $ff
-.Set3:
- ; S T U V W
- db 19, 20, 21, 22, 23, $ff
-.Set4:
- ; X Y Z
- db 24, 25, 26, $ff
-
-; 3ebc7
+INCLUDE "data/wild/unlocked_unowns.asm"
-Unreferenced_SwapBattlerLevels: ; 3ebc7
+Unreferenced_SwapBattlerLevels:
push bc
ld a, [wBattleMonLevel]
ld b, a
@@ -6706,9 +6495,8 @@ Unreferenced_SwapBattlerLevels: ; 3ebc7
ld [wEnemyMonLevel], a
pop bc
ret
-; 3ebd8
-BattleWinSlideInEnemyTrainerFrontpic: ; 3ebd8
+BattleWinSlideInEnemyTrainerFrontpic:
xor a
ld [wTempEnemyMonSpecies], a
call FinishBattleAnim
@@ -6748,9 +6536,8 @@ BattleWinSlideInEnemyTrainerFrontpic: ; 3ebd8
pop bc
dec hl
jr .outer_loop
-; 3ec1a
-.CopyColumn: ; 3ec1a
+.CopyColumn:
push hl
push de
push bc
@@ -6768,24 +6555,20 @@ BattleWinSlideInEnemyTrainerFrontpic: ; 3ebd8
pop de
pop hl
ret
-; 3ec2c
-ApplyStatusEffectOnPlayerStats: ; 3ec2c
+ApplyStatusEffectOnPlayerStats:
ld a, 1
jr ApplyStatusEffectOnStats
-; 3ec30
-ApplyStatusEffectOnEnemyStats: ; 3ec30
+ApplyStatusEffectOnEnemyStats:
xor a
-; 3ec31
-ApplyStatusEffectOnStats: ; 3ec31
+ApplyStatusEffectOnStats:
ld [hBattleTurn], a
call ApplyPrzEffectOnSpeed
jp ApplyBrnEffectOnAttack
-; 3ec39
-ApplyPrzEffectOnSpeed: ; 3ec39
+ApplyPrzEffectOnSpeed:
ld a, [hBattleTurn]
and a
jr z, .enemy
@@ -6829,9 +6612,8 @@ ApplyPrzEffectOnSpeed: ; 3ec39
.enemy_ok
ld [hl], b
ret
-; 3ec76
-ApplyBrnEffectOnAttack: ; 3ec76
+ApplyBrnEffectOnAttack:
ld a, [hBattleTurn]
and a
jr z, .enemy
@@ -6871,9 +6653,8 @@ ApplyBrnEffectOnAttack: ; 3ec76
.enemy_ok
ld [hl], b
ret
-; 3ecab
-ApplyStatLevelMultiplierOnAllStats: ; 3ecab
+ApplyStatLevelMultiplierOnAllStats:
; Apply StatLevelMultipliers on all 5 Stats
ld c, 0
.stat_loop
@@ -6883,9 +6664,8 @@ ApplyStatLevelMultiplierOnAllStats: ; 3ecab
cp 5
jr nz, .stat_loop
ret
-; 3ecb7
-ApplyStatLevelMultiplier: ; 3ecb7
+ApplyStatLevelMultiplier:
push bc
push bc
ld a, [wd265]
@@ -6920,7 +6700,7 @@ ApplyStatLevelMultiplier: ; 3ecb7
.okay2
pop bc
push hl
- ld hl, .StatLevelMultipliers
+ ld hl, StatLevelMultipliers_Applied
dec b
sla b
ld c, b
@@ -6967,28 +6747,10 @@ ApplyStatLevelMultiplier: ; 3ecb7
.okay4
pop bc
ret
-; 3ed2b
-.StatLevelMultipliers:
-; /
- db 25, 100 ; 25%
- db 28, 100 ; 28%
- db 33, 100 ; 33%
- db 40, 100 ; 40%
- db 50, 100 ; 50%
- db 66, 100 ; 66%
+INCLUDE "data/battle/stat_multipliers_2.asm"
- db 1, 1 ; 100%
-
- db 15, 10 ; 150%
- db 2, 1 ; 200%
- db 25, 10 ; 250%
- db 3, 1 ; 300%
- db 35, 10 ; 350%
- db 4, 1 ; 400%
-; 3ed45
-
-BadgeStatBoosts: ; 3ed45
+BadgeStatBoosts:
; Raise the stats of the battle mon in wBattleMon
; depending on which badges have been obtained.
@@ -7045,9 +6807,8 @@ BadgeStatBoosts: ; 3ed45
srl a
call c, BoostStat
ret
-; 3ed7c
-BoostStat: ; 3ed7c
+BoostStat:
; Raise stat at hl by 1/8.
ld a, [hli]
@@ -7077,17 +6838,14 @@ BoostStat: ; 3ed7c
ld a, LOW(MAX_STAT_VALUE)
ld [hld], a
ret
-; 3ed9f
-_LoadBattleFontsHPBar: ; 3ed9f
+_LoadBattleFontsHPBar:
callfar LoadBattleFontsHPBar
ret
-; 3eda6
-_LoadHPBar: ; 3eda6
+_LoadHPBar:
callfar LoadHPBar
ret
-; 3edad
Unreferenced_LoadHPExpBarGFX:
ld de, EnemyHPBarBorderGFX
@@ -7102,16 +6860,14 @@ Unreferenced_LoadHPExpBarGFX:
ld hl, vTiles2 tile $55
lb bc, BANK(ExpBarGFX), 8
jp Get2bpp
-; 3edd1
-EmptyBattleTextBox: ; 3edd1
+EmptyBattleTextBox:
ld hl, .empty
jp BattleTextBox
.empty
db "@"
-; 3edd8
-_BattleRandom:: ; 3edd8
+_BattleRandom::
; If the normal RNG is used in a link battle it'll desync.
; To circumvent this a shared PRNG is used instead.
@@ -7178,25 +6934,22 @@ _BattleRandom:: ; 3edd8
pop bc
pop hl
ret
-; 3ee0f
-Call_PlayBattleAnim_OnlyIfVisible: ; 3ee0f
+Call_PlayBattleAnim_OnlyIfVisible:
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVar
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
ret nz
-; 3ee17
-Call_PlayBattleAnim: ; 3ee17
+Call_PlayBattleAnim:
ld a, e
ld [wFXAnimID], a
ld a, d
ld [wFXAnimID + 1], a
call WaitBGMap
predef_jump PlayBattleAnim
-; 3ee27
-FinishBattleAnim: ; 3ee27
+FinishBattleAnim:
push af
push bc
push de
@@ -7210,9 +6963,8 @@ FinishBattleAnim: ; 3ee27
pop bc
pop af
ret
-; 3ee3b
-GiveExperiencePoints: ; 3ee3b
+GiveExperiencePoints:
; Give experience.
; Don't give experience if linked or in the Battle Tower.
ld a, [wLinkMode]
@@ -7240,7 +6992,7 @@ GiveExperiencePoints: ; 3ee3b
ld a, [wCurPartyMon]
ld c, a
ld b, CHECK_FLAG
- ld d, $0
+ ld d, FALSE
predef SmallFarFlagAction
ld a, c
and a
@@ -7254,7 +7006,7 @@ GiveExperiencePoints: ; 3ee3b
ld e, l
ld hl, wEnemyMonBaseStats - 1
push bc
- ld c, $5
+ ld c, NUM_EXP_STATS
.loop1
inc hl
ld a, [de]
@@ -7350,7 +7102,7 @@ GiveExperiencePoints: ; 3ee3b
ld a, [wCurPartyMon]
ld hl, wPartyMonNicknames
call GetNick
- ld hl, Text_PkmnGainedExpPoint
+ ld hl, Text_MonGainedExpPoint
call BattleTextBox
ld a, [wStringBuffer2 + 1]
ld [hQuotient + 2], a
@@ -7419,7 +7171,7 @@ GiveExperiencePoints: ; 3ee3b
.not_max_exp
xor a ; PARTYMON
ld [wMonType], a
- predef CopyPkmnToTempMon
+ predef CopyMonToTempMon
callfar CalcLevel
pop bc
ld hl, MON_LEVEL
@@ -7456,7 +7208,7 @@ GiveExperiencePoints: ; 3ee3b
add hl, bc
push bc
ld b, TRUE
- predef CalcPkmnStats
+ predef CalcMonStats
pop bc
pop de
ld hl, MON_MAXHP + 1
@@ -7532,15 +7284,15 @@ GiveExperiencePoints: ; 3ee3b
.skip_animation2
xor a ; PARTYMON
ld [wMonType], a
- predef CopyPkmnToTempMon
+ predef CopyMonToTempMon
hlcoord 9, 0
- ld b, $a
- ld c, $9
+ ld b, 10
+ ld c, 9
call TextBox
hlcoord 11, 1
ld bc, 4
predef PrintTempMonStats
- ld c, $1e
+ ld c, 30
call DelayFrames
call WaitPressAorB_BlinkCursor
call Call_LoadTempTileMapToTileMap
@@ -7590,7 +7342,6 @@ GiveExperiencePoints: ; 3ee3b
.done
jp ResetBattleParticipants
-; 3f0d4
.EvenlyDivideExpAmongParticipants:
; count number of battle participants
@@ -7625,9 +7376,8 @@ GiveExperiencePoints: ; 3ee3b
dec c
jr nz, .count_loop2
ret
-; 3f106
-BoostExp: ; 3f106
+BoostExp:
; Multiply experience by 1.5x
push bc
; load experience value
@@ -7646,9 +7396,8 @@ BoostExp: ; 3f106
ld [hProduct + 2], a
pop bc
ret
-; 3f11b
-Text_PkmnGainedExpPoint: ; 3f11b
+Text_MonGainedExpPoint:
text_jump Text_Gained
start_asm
ld hl, TextJump_StringBuffer2ExpPoints
@@ -7658,19 +7407,16 @@ Text_PkmnGainedExpPoint: ; 3f11b
ld hl, TextJump_ABoostedStringBuffer2ExpPoints
ret
-; 3f12c
-TextJump_ABoostedStringBuffer2ExpPoints: ; 3f12c
+TextJump_ABoostedStringBuffer2ExpPoints:
text_jump Text_ABoostedStringBuffer2ExpPoints
db "@"
-; 3f131
-TextJump_StringBuffer2ExpPoints: ; 3f131
+TextJump_StringBuffer2ExpPoints:
text_jump Text_StringBuffer2ExpPoints
db "@"
-; 3f136
-AnimateExpBar: ; 3f136
+AnimateExpBar:
push bc
ld hl, wCurPartyMon
@@ -7692,7 +7438,7 @@ AnimateExpBar: ; 3f136
ld [wd002], a
xor a ; PARTYMON
ld [wMonType], a
- predef CopyPkmnToTempMon
+ predef CopyMonToTempMon
ld a, [wTempMonLevel]
ld b, a
ld e, a
@@ -7856,23 +7602,23 @@ AnimateExpBar: ; 3f136
ld [hBGMapMode], a
ret
-SendOutPkmnText: ; 3f26d
+SendOutMonText:
ld a, [wLinkMode]
and a
jr z, .not_linked
- ld hl, JumpText_GoPkmn ; If we're in a LinkBattle print just "Go <PlayerMon>"
+ ld hl, JumpText_GoMon ; If we're in a LinkBattle print just "Go <PlayerMon>"
ld a, [wBattleHasJustStarted] ; unless this (unidentified) variable is set
and a
jr nz, .skip_to_textbox
.not_linked
-; Depending on the HP of the enemy Pkmn, the game prints a different text
+; Depending on the HP of the enemy mon, the game prints a different text
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
- ld hl, JumpText_GoPkmn
+ ld hl, JumpText_GoMon
jr z, .skip_to_textbox
; compute enemy helth remaining as a percentage
@@ -7901,62 +7647,56 @@ SendOutPkmnText: ; 3f26d
call Divide
ld a, [hQuotient + 2]
- ld hl, JumpText_GoPkmn
+ ld hl, JumpText_GoMon
cp 70
jr nc, .skip_to_textbox
- ld hl, JumpText_DoItPkmn
+ ld hl, JumpText_DoItMon
cp 40
jr nc, .skip_to_textbox
- ld hl, JumpText_GoForItPkmn
+ ld hl, JumpText_GoForItMon
cp 10
jr nc, .skip_to_textbox
- ld hl, JumpText_YourFoesWeakGetmPkmn
+ ld hl, JumpText_YourFoesWeakGetmMon
.skip_to_textbox
jp BattleTextBox
-; 3f2d1
-JumpText_GoPkmn: ; 3f2d1
- text_jump Text_GoPkmn
+JumpText_GoMon:
+ text_jump Text_GoMon
start_asm
jr Function_TextJump_BattleMonNick01
-; 3f2d6
-JumpText_DoItPkmn: ; 3f2d8
- text_jump Text_DoItPkmn
+JumpText_DoItMon:
+ text_jump Text_DoItMon
start_asm
jr Function_TextJump_BattleMonNick01
-; 3f2dd
-JumpText_GoForItPkmn: ; 3f2df
- text_jump Text_GoForItPkmn
+JumpText_GoForItMon:
+ text_jump Text_GoForItMon
start_asm
jr Function_TextJump_BattleMonNick01
-; 3f2e4
-JumpText_YourFoesWeakGetmPkmn: ; 3f2e6
- text_jump Text_YourFoesWeakGetmPkmn
+JumpText_YourFoesWeakGetmMon:
+ text_jump Text_YourFoesWeakGetmMon
start_asm
-Function_TextJump_BattleMonNick01: ; 3f2eb
+Function_TextJump_BattleMonNick01:
ld hl, TextJump_BattleMonNick01
ret
-; 3f2ef
-TextJump_BattleMonNick01: ; 3f2ef
+TextJump_BattleMonNick01:
text_jump Text_BattleMonNick01
db "@"
-; 3f2f4
-WithdrawPkmnText: ; 3f2f4
- ld hl, .WithdrawPkmnText
+WithdrawMonText:
+ ld hl, .WithdrawMonText
jp BattleTextBox
-.WithdrawPkmnText:
+.WithdrawMonText:
text_jump Text_BattleMonNickComma
start_asm
-; Print text to withdraw Pkmn
+; Print text to withdraw mon
; depending on HP the message is different
push de
push bc
@@ -8003,33 +7743,27 @@ WithdrawPkmnText: ; 3f2f4
ld hl, TextJump_GoodComeBack
ret
-; 3f348
-TextJump_ThatsEnoughComeBack: ; 3f348
+TextJump_ThatsEnoughComeBack:
text_jump Text_ThatsEnoughComeBack
db "@"
-; 3f34d
-TextJump_OKComeBack: ; 3f34d
+TextJump_OKComeBack:
text_jump Text_OKComeBack
db "@"
-; 3f352
-TextJump_GoodComeBack: ; 3f352
+TextJump_GoodComeBack:
text_jump Text_GoodComeBack
db "@"
-; 3f357
-Unreferenced_TextJump_ComeBack: ; 3f357
+Unreferenced_TextJump_ComeBack:
; this function doesn't seem to be used
ld hl, TextJump_ComeBack
ret
-; 3f35b
-TextJump_ComeBack: ; 3f35b
+TextJump_ComeBack:
text_jump Text_ComeBack
db "@"
-; 3f360
Unreferenced_HandleSafariAngerEatingStatus:
ld hl, wSafariMonEating
@@ -8037,7 +7771,7 @@ Unreferenced_HandleSafariAngerEatingStatus:
and a
jr z, .angry
dec [hl]
- ld hl, BattleText_WildPkmnIsEating
+ ld hl, BattleText_WildMonIsEating
jr .finish
.angry
@@ -8046,7 +7780,7 @@ Unreferenced_HandleSafariAngerEatingStatus:
and a
ret z
dec [hl]
- ld hl, BattleText_WildPkmnIsAngry
+ ld hl, BattleText_WildMonIsAngry
jr nz, .finish
push hl
ld a, [wEnemyMonSpecies]
@@ -8061,18 +7795,16 @@ Unreferenced_HandleSafariAngerEatingStatus:
call Call_LoadTempTileMapToTileMap
pop hl
jp StdBattleTextBox
-; 3f390
-FillInExpBar: ; 3f390
+FillInExpBar:
push hl
call CalcExpBar
pop hl
ld de, 7
add hl, de
jp PlaceExpBar
-; 3f39c
-CalcExpBar: ; 3f39c
+CalcExpBar:
; Calculate the percent exp between this level and the next
; Level in b
push de
@@ -8171,9 +7903,8 @@ CalcExpBar: ; 3f39c
sub b
ld b, a
ret
-; 3f41c
-PlaceExpBar: ; 3f41c
+PlaceExpBar:
ld c, $8 ; number of tiles
.loop1
ld a, b
@@ -8203,15 +7934,14 @@ PlaceExpBar: ; 3f41c
.finish
ret
-; 3f43d
-GetBattleMonBackpic: ; 3f43d
+GetBattleMonBackpic:
ld a, [wPlayerSubStatus4]
bit SUBSTATUS_SUBSTITUTE, a
ld hl, BattleAnimCmd_RaiseSub
jr nz, GetBattleMonBackpic_DoAnim ; substitute
-DropPlayerSub: ; 3f447
+DropPlayerSub:
ld a, [wPlayerMinimized]
and a
ld hl, BattleAnimCmd_MinimizeOpp
@@ -8227,9 +7957,8 @@ DropPlayerSub: ; 3f447
pop af
ld [wCurPartySpecies], a
ret
-; 3f46f
-GetBattleMonBackpic_DoAnim: ; 3f46f
+GetBattleMonBackpic_DoAnim:
ld a, [hBattleTurn]
push af
xor a
@@ -8239,15 +7968,14 @@ GetBattleMonBackpic_DoAnim: ; 3f46f
pop af
ld [hBattleTurn], a
ret
-; 3f47c
-GetEnemyMonFrontpic: ; 3f47c
+GetEnemyMonFrontpic:
ld a, [wEnemySubStatus4]
bit SUBSTATUS_SUBSTITUTE, a
ld hl, BattleAnimCmd_RaiseSub
jr nz, GetEnemyMonFrontpic_DoAnim
-DropEnemySub: ; 3f486
+DropEnemySub:
ld a, [wEnemyMinimized]
and a
ld hl, BattleAnimCmd_MinimizeOpp
@@ -8266,9 +7994,8 @@ DropEnemySub: ; 3f486
pop af
ld [wCurPartySpecies], a
ret
-; 3f4b4
-GetEnemyMonFrontpic_DoAnim: ; 3f4b4
+GetEnemyMonFrontpic_DoAnim:
ld a, [hBattleTurn]
push af
call SetEnemyTurn
@@ -8277,9 +8004,8 @@ GetEnemyMonFrontpic_DoAnim: ; 3f4b4
pop af
ld [hBattleTurn], a
ret
-; 3f4c1
-StartBattle: ; 3f4c1
+StartBattle:
; This check prevents you from entering a battle without any Pokemon.
; Those using walk-through-walls to bypass getting a Pokemon experience
; the effects of this check.
@@ -8296,14 +8022,12 @@ StartBattle: ; 3f4c1
ld [wTimeOfDayPal], a
scf
ret
-; 3f4d9
-Unreferenced_DoBattle: ; 3f4d9
+Unreferenced_DoBattle:
call DoBattle
ret
-; 3f4dd
-BattleIntro: ; 3f4dd
+BattleIntro:
farcall StubbedTrainerRankings_Battles ; mobile
call LoadTrainerOrWildMonPic
xor a
@@ -8342,9 +8066,8 @@ BattleIntro: ; 3f4dd
ld a, $1
ld [hBGMapMode], a
ret
-; 3f54e
-LoadTrainerOrWildMonPic: ; 3f54e
+LoadTrainerOrWildMonPic:
ld a, [wOtherTrainerClass]
and a
jr nz, .Trainer
@@ -8354,16 +8077,14 @@ LoadTrainerOrWildMonPic: ; 3f54e
.Trainer:
ld [wTempEnemyMonSpecies], a
ret
-; 3f55e
-InitEnemy: ; 3f55e
+InitEnemy:
ld a, [wOtherTrainerClass]
and a
jp nz, InitEnemyTrainer ; trainer
jp InitEnemyWildmon ; wild
-; 3f568
-BackUpBGMap2: ; 3f568
+BackUpBGMap2:
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
@@ -8385,9 +8106,8 @@ BackUpBGMap2: ; 3f568
pop af
ld [rSVBK], a
ret
-; 3f594
-InitEnemyTrainer: ; 3f594
+InitEnemyTrainer:
ld [wTrainerClass], a
farcall StubbedTrainerRankings_TrainerBattles
xor a
@@ -8441,9 +8161,8 @@ InitEnemyTrainer: ; 3f594
jr .partyloop
.done
ret
-; 3f607
-InitEnemyWildmon: ; 3f607
+InitEnemyWildmon:
ld a, WILD_BATTLE
ld [wBattleMode], a
farcall StubbedTrainerRankings_WildBattles
@@ -8476,9 +8195,8 @@ InitEnemyWildmon: ; 3f607
lb bc, 7, 7
predef PlaceGraphic
ret
-; 3f662
-Unreferenced_Function3f662: ; 3f662
+Unreferenced_Function3f662:
ld hl, wEnemyMonMoves
ld de, wListMoves_MoveIndicesBuffer
ld b, NUM_MOVES
@@ -8528,15 +8246,13 @@ Unreferenced_Function3f662: ; 3f662
dec b
jr nz, .clear
ret
-; 3f69e
-ExitBattle: ; 3f69e
+ExitBattle:
call .HandleEndOfBattle
call CleanUpBattleRAM
ret
-; 3f6a5
-.HandleEndOfBattle: ; 3f6a5
+.HandleEndOfBattle:
ld a, [wLinkMode]
and a
jr z, .not_linked
@@ -8556,9 +8272,8 @@ ExitBattle: ; 3f69e
predef EvolveAfterBattle
farcall GivePokerusAndConvertBerries
ret
-; 3f6d0
-CleanUpBattleRAM: ; 3f6d0
+CleanUpBattleRAM:
call BattleEnd_HandleRoamMons
xor a
ld [wLowHealthAlarm], a
@@ -8589,9 +8304,8 @@ CleanUpBattleRAM: ; 3f6d0
jr nz, .loop
call WaitSFX
ret
-; 3f71d
-CheckPayDay: ; 3f71d
+CheckPayDay:
ld hl, wPayDayMoney
ld a, [hli]
or [hl]
@@ -8625,9 +8339,8 @@ CheckPayDay: ; 3f71d
call ClearTileMap
call ClearBGPalettes
ret
-; 3f759
-ShowLinkBattleParticipantsAfterEnd: ; 3f759
+ShowLinkBattleParticipantsAfterEnd:
farcall StubbedTrainerRankings_LinkBattles
farcall BackupMobileEventIndex
ld a, [wCurOTMon]
@@ -8638,9 +8351,8 @@ ShowLinkBattleParticipantsAfterEnd: ; 3f759
call ClearTileMap
farcall _ShowLinkBattleParticipants
ret
-; 3f77c
-DisplayLinkBattleResult: ; 3f77c
+DisplayLinkBattleResult:
farcall CheckMobileBattleError
jp c, .Mobile_InvalidBattle
call IsMobileBattle2
@@ -8655,9 +8367,10 @@ DisplayLinkBattleResult: ; 3f77c
.proceed
ld a, [wBattleResult]
and $f
- cp $1
- jr c, .victory
- jr z, .loss
+ cp LOSE
+ jr c, .victory ; WIN
+ jr z, .loss ; LOSE
+ ; DRAW
farcall StubbedTrainerRankings_ColosseumDraws
ld de, .Draw
jr .store_result
@@ -8698,7 +8411,6 @@ DisplayLinkBattleResult: ; 3f77c
call DelayFrames
call ClearTileMap
ret
-; 3f7f7
.Win:
db "YOU WIN@"
@@ -8706,9 +8418,8 @@ DisplayLinkBattleResult: ; 3f77c
db "YOU LOSE@"
.Draw:
db " DRAW@"
-; 3f80f
-.Mobile_InvalidBattle: ; 3f80f
+.Mobile_InvalidBattle:
hlcoord 6, 8
ld de, .Invalid
call PlaceString
@@ -8716,19 +8427,16 @@ DisplayLinkBattleResult: ; 3f77c
call DelayFrames
call ClearTileMap
ret
-; 3f821
.Invalid:
db "INVALID BATTLE@"
-; 3f830
-IsMobileBattle2: ; 3f830
+IsMobileBattle2:
ld a, [wLinkMode]
cp LINK_MOBILE
ret
-; 3f836
-DisplayLinkRecord: ; 3f836
+_DisplayLinkRecord:
ld a, BANK(sLinkBattleStats)
call GetSRAMBank
@@ -8747,9 +8455,8 @@ DisplayLinkRecord: ; 3f836
call DelayFrames
call WaitPressAorB_BlinkCursor
ret
-; 3f85f
-ReadAndPrintLinkBattleRecord: ; 3f85f
+ReadAndPrintLinkBattleRecord:
call ClearTileMap
call ClearSprites
call .PrintBattleRecord
@@ -8866,30 +8573,27 @@ ReadAndPrintLinkBattleRecord: ; 3f85f
call PlaceString
scf
ret
-; 3f938
.Scores:
db " 0 0 0@"
-; 3f947
-.Format: ; 3f947
- db " --- <LNBRK>"
+.Format:
+ db " --- <LF>"
db " - - -@"
-.Record: ; 3f964
+.Record:
db "<PLAYER>'s RECORD@"
-.Result: ; 3f96e
+.Result:
db "RESULT WIN LOSE DRAW@"
-.Total: ; 3f983
+.Total:
db "TOTAL WIN LOSE DRAW@"
-; 3f998
-BattleEnd_HandleRoamMons: ; 3f998
+BattleEnd_HandleRoamMons:
ld a, [wBattleType]
cp BATTLETYPE_ROAMING
jr nz, .not_roaming
ld a, [wBattleResult]
and $f
- jr z, .caught_or_defeated_roam_mon
+ jr z, .caught_or_defeated_roam_mon ; WIN
call GetRoamMonHP
ld a, [wEnemyMonHP + 1]
ld [hl], a
@@ -8897,13 +8601,13 @@ BattleEnd_HandleRoamMons: ; 3f998
.caught_or_defeated_roam_mon
call GetRoamMonHP
- ld [hl], $0
+ ld [hl], 0
call GetRoamMonMapGroup
- ld [hl], $ff
+ ld [hl], GROUP_N_A
call GetRoamMonMapNumber
- ld [hl], $ff
+ ld [hl], MAP_N_A
call GetRoamMonSpecies
- ld [hl], $0
+ ld [hl], 0
ret
.not_roaming
@@ -8914,9 +8618,8 @@ BattleEnd_HandleRoamMons: ; 3f998
.update_roam_mons
callfar UpdateRoamMons
ret
-; 3f9d1
-GetRoamMonMapGroup: ; 3f9d1
+GetRoamMonMapGroup:
ld a, [wTempEnemyMonSpecies]
ld b, a
ld a, [wRoamMon1Species]
@@ -8929,9 +8632,8 @@ GetRoamMonMapGroup: ; 3f9d1
ret z
ld hl, wRoamMon3MapGroup
ret
-; 3f9e9
-GetRoamMonMapNumber: ; 3f9e9
+GetRoamMonMapNumber:
ld a, [wTempEnemyMonSpecies]
ld b, a
ld a, [wRoamMon1Species]
@@ -8944,9 +8646,8 @@ GetRoamMonMapNumber: ; 3f9e9
ret z
ld hl, wRoamMon3MapNumber
ret
-; 3fa01
-GetRoamMonHP: ; 3fa01
+GetRoamMonHP:
; output: hl = wRoamMonHP
ld a, [wTempEnemyMonSpecies]
ld b, a
@@ -8960,9 +8661,8 @@ GetRoamMonHP: ; 3fa01
ret z
ld hl, wRoamMon3HP
ret
-; 3fa19
-GetRoamMonDVs: ; 3fa19
+GetRoamMonDVs:
; output: hl = wRoamMonDVs
ld a, [wTempEnemyMonSpecies]
ld b, a
@@ -8976,9 +8676,8 @@ GetRoamMonDVs: ; 3fa19
ret z
ld hl, wRoamMon3DVs
ret
-; 3fa31
-GetRoamMonSpecies: ; 3fa31
+GetRoamMonSpecies:
ld a, [wTempEnemyMonSpecies]
ld hl, wRoamMon1Species
cp [hl]
@@ -8988,9 +8687,8 @@ GetRoamMonSpecies: ; 3fa31
ret z
ld hl, wRoamMon3Species
ret
-; 3fa42
-AddLastMobileBattleToLinkRecord: ; 3fa42
+AddLastMobileBattleToLinkRecord:
ld hl, wOTPlayerID
ld de, wStringBuffer1
ld bc, 2
@@ -9045,15 +8743,15 @@ AddLastMobileBattleToLinkRecord: ; 3fa42
call .StoreResult
call .FindOpponentAndAppendRecord
ret
-; 3faa0
-.StoreResult: ; 3faa0
+.StoreResult:
ld a, [wBattleResult]
and $f
- cp $1
+ cp LOSE
ld bc, sLinkBattleWins + 1 - sLinkBattleResults
- jr c, .okay
+ jr c, .okay ; WIN
ld bc, sLinkBattleLosses + 1 - sLinkBattleResults
- jr z, .okay
+ jr z, .okay ; LOSE
+ ; DRAW
ld bc, sLinkBattleDraws + 1 - sLinkBattleResults
.okay
add hl, bc
@@ -9064,9 +8762,8 @@ AddLastMobileBattleToLinkRecord: ; 3fa42
dec hl
inc [hl]
ret
-; 3fabe
-.CheckOverflow: ; 3fabe
+.CheckOverflow:
dec hl
ld a, [hl]
inc hl
@@ -9075,9 +8772,8 @@ AddLastMobileBattleToLinkRecord: ; 3fa42
ld a, [hl]
cp LOW(MAX_LINK_RECORD)
ret
-; 3fac8
-.FindOpponentAndAppendRecord: ; 3fac8
+.FindOpponentAndAppendRecord:
ld b, 5
ld hl, sLinkBattleRecord + 17
ld de, wd002
@@ -9169,9 +8865,8 @@ AddLastMobileBattleToLinkRecord: ; 3fa42
pop de
call CopyBytes
ret
-; 3fb54
-.LoadPointer: ; 3fb54
+.LoadPointer:
ld e, $0
ld a, [hld]
ld c, a
@@ -9196,9 +8891,8 @@ AddLastMobileBattleToLinkRecord: ; 3fa42
ret nc
inc e
ret
-; 3fb6c
-InitBattleDisplay: ; 3fb6c
+InitBattleDisplay:
call .InitBackPic
hlcoord 0, 12
ld b, 4
@@ -9241,9 +8935,8 @@ InitBattleDisplay: ; 3fb6c
xor a
ld [hSCX], a
ret
-; 3fbd6
-.BlankBGMap: ; 3fbd6
+.BlankBGMap:
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
@@ -9262,15 +8955,13 @@ InitBattleDisplay: ; 3fb6c
pop af
ld [rSVBK], a
ret
-; 3fbf8
-.InitBackPic: ; 3fbf8
+.InitBackPic:
call GetTrainerBackpic
call CopyBackpic
ret
-; 3fbff
-GetTrainerBackpic: ; 3fbff
+GetTrainerBackpic:
; Load the player character's backpic (6x6) into VRAM starting from vTiles2 tile $31.
; Special exception for Dude.
@@ -9282,10 +8973,10 @@ GetTrainerBackpic: ; 3fbff
; What gender are we?
ld a, [wPlayerSpriteSetupFlags]
- bit 2, a ; transformed to male
+ bit PLAYERSPRITESETUP_FEMALE_TO_MALE_F, a
jr nz, .Chris
ld a, [wPlayerGender]
- bit 0, a
+ bit PLAYERGENDER_FEMALE_F, a
jr z, .Chris
; It's a girl.
@@ -9302,9 +8993,8 @@ GetTrainerBackpic: ; 3fbff
ld c, 7 * 7
predef DecompressGet2bpp
ret
-; 3fc30
-CopyBackpic: ; 3fc30
+CopyBackpic:
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
@@ -9324,9 +9014,8 @@ CopyBackpic: ; 3fc30
lb bc, 6, 6
predef PlaceGraphic
ret
-; 3fc5b
-.LoadTrainerBackpicAsOAM: ; 3fc5b
+.LoadTrainerBackpicAsOAM:
ld hl, wVirtualOAMSprite00
xor a
ld [hMapObjectIndexBuffer], a
@@ -9360,9 +9049,8 @@ CopyBackpic: ; 3fc30
dec b
jr nz, .outer_loop
ret
-; 3fc8b
-BattleStartMessage: ; 3fc8b
+BattleStartMessage:
ld a, [wBattleMode]
dec a
jr z, .wild
@@ -9443,4 +9131,3 @@ BattleStartMessage: ; 3fc8b
farcall Mobile_PrintOpponentBattleMessage
ret
-; 3fd26
diff --git a/engine/battle/effect_commands.asm b/engine/battle/effect_commands.asm
index 48efba8fa..eb30af88b 100644
--- a/engine/battle/effect_commands.asm
+++ b/engine/battle/effect_commands.asm
@@ -1,4 +1,4 @@
-DoPlayerTurn: ; 34000
+DoPlayerTurn:
call SetPlayerTurn
ld a, [wBattlePlayerAction]
@@ -7,10 +7,7 @@ DoPlayerTurn: ; 34000
jr DoTurn
-; 3400a
-
-
-DoEnemyTurn: ; 3400a
+DoEnemyTurn:
call SetEnemyTurn
ld a, [wLinkMode]
@@ -24,10 +21,8 @@ DoEnemyTurn: ; 3400a
ret nc
; fallthrough
-; 3401d
-
-DoTurn: ; 3401d
+DoTurn:
; Read in and execute the user's move effects for this turn.
xor a
@@ -41,10 +36,8 @@ DoTurn: ; 3401d
ret nz
call UpdateMoveData
-; 3402c
-
-DoMove: ; 3402c
+DoMove:
; Get the user's move effect.
ld a, BATTLE_VARS_MOVE_EFFECT
call GetBattleVar
@@ -64,7 +57,7 @@ DoMove: ; 3402c
inc hl
ld [de], a
inc de
- cp -1
+ cp endmove_command
jr nz, .GetMoveEffect
; Start at the first command.
@@ -75,7 +68,6 @@ DoMove: ; 3402c
ld [wBattleScriptBufferAddress + 1], a
.ReadMoveEffectCommand:
-
; ld a, [wBattleScriptBufferAddress++]
ld a, [wBattleScriptBufferAddress]
ld l, a
@@ -115,11 +107,8 @@ DoMove: ; 3402c
.DoMoveEffectCommand:
jp hl
-; 34084
-
-
CheckTurn:
-BattleCommand_CheckTurn: ; 34084
+BattleCommand_CheckTurn:
; checkturn
; Repurposed as hardcoded turn handling. Useless as a command.
@@ -145,9 +134,7 @@ BattleCommand_CheckTurn: ; 34084
and a
jp nz, CheckEnemyTurn
-
CheckPlayerTurn:
-
ld hl, wPlayerSubStatus4
bit SUBSTATUS_RECHARGE, [hl]
jr z, .no_recharge
@@ -160,7 +147,6 @@ CheckPlayerTurn:
.no_recharge
-
ld hl, wBattleMonStatus
ld a, [hl]
and SLP
@@ -206,7 +192,6 @@ CheckPlayerTurn:
.not_asleep
-
ld hl, wBattleMonStatus
bit FRZ, [hl]
jr z, .not_frozen
@@ -226,7 +211,6 @@ CheckPlayerTurn:
.not_frozen
-
ld hl, wPlayerSubStatus3
bit SUBSTATUS_FLINCHED, [hl]
jr z, .not_flinched
@@ -240,7 +224,6 @@ CheckPlayerTurn:
.not_flinched
-
ld hl, wPlayerDisableCount
ld a, [hl]
and a
@@ -258,7 +241,6 @@ CheckPlayerTurn:
.not_disabled
-
ld a, [wPlayerSubStatus3]
add a
jr nc, .not_confused
@@ -297,7 +279,6 @@ CheckPlayerTurn:
.not_confused
-
ld a, [wPlayerSubStatus1]
add a ; bit SUBSTATUS_ATTRACT
jr nc, .not_infatuated
@@ -321,7 +302,6 @@ CheckPlayerTurn:
.not_infatuated
-
; We can't disable a move that doesn't exist.
ld a, [wDisabledMove]
and a
@@ -338,7 +318,6 @@ CheckPlayerTurn:
.no_disabled_move
-
ld hl, wBattleMonStatus
bit PAR, [hl]
ret z
@@ -353,10 +332,7 @@ CheckPlayerTurn:
call CantMove
jp EndTurn
-; 341f0
-
-
-CantMove: ; 341f0
+CantMove:
ld a, BATTLE_VARS_SUBSTATUS1
call GetBattleVarAddr
res SUBSTATUS_ROLLOUT, [hl]
@@ -364,7 +340,7 @@ CantMove: ; 341f0
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVarAddr
ld a, [hl]
- and $ff ^ (1<<SUBSTATUS_BIDE + 1<<SUBSTATUS_RAMPAGE + 1<<SUBSTATUS_CHARGED)
+ and $ff ^ (1 << SUBSTATUS_BIDE | 1 << SUBSTATUS_RAMPAGE | 1 << SUBSTATUS_CHARGED)
ld [hl], a
call ResetFuryCutterCount
@@ -382,21 +358,12 @@ CantMove: ; 341f0
res SUBSTATUS_FLYING, [hl]
jp AppearUserRaiseSub
-; 34216
-
-
-
-OpponentCantMove: ; 34216
+OpponentCantMove:
call BattleCommand_SwitchTurn
call CantMove
jp BattleCommand_SwitchTurn
-; 3421f
-
-
-
-CheckEnemyTurn: ; 3421f
-
+CheckEnemyTurn:
ld hl, wEnemySubStatus4
bit SUBSTATUS_RECHARGE, [hl]
jr z, .no_recharge
@@ -409,7 +376,6 @@ CheckEnemyTurn: ; 3421f
.no_recharge
-
ld hl, wEnemyMonStatus
ld a, [hl]
and SLP
@@ -453,7 +419,6 @@ CheckEnemyTurn: ; 3421f
.not_asleep
-
ld hl, wEnemyMonStatus
bit FRZ, [hl]
jr z, .not_frozen
@@ -472,7 +437,6 @@ CheckEnemyTurn: ; 3421f
.not_frozen
-
ld hl, wEnemySubStatus3
bit SUBSTATUS_FLINCHED, [hl]
jr z, .not_flinched
@@ -486,7 +450,6 @@ CheckEnemyTurn: ; 3421f
.not_flinched
-
ld hl, wEnemyDisableCount
ld a, [hl]
and a
@@ -505,7 +468,6 @@ CheckEnemyTurn: ; 3421f
.not_disabled
-
ld a, [wEnemySubStatus3]
add a ; bit SUBSTATUS_CONFUSED
jr nc, .not_confused
@@ -520,7 +482,6 @@ CheckEnemyTurn: ; 3421f
call StdBattleTextBox
jr .not_confused
-
.confused
ld hl, IsConfusedText
call StdBattleTextBox
@@ -532,7 +493,7 @@ CheckEnemyTurn: ; 3421f
; 50% chance of hitting itself
call BattleRandom
- cp 1 + 50 percent
+ cp 50 percent + 1
jr nc, .not_confused
; clear confusion-dependent substatus
@@ -556,15 +517,14 @@ CheckEnemyTurn: ; 3421f
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
call z, PlayFXAnimID
- ld c, $1
- call EnemyHurtItself
+ ld c, TRUE
+ call DoEnemyDamage
call BattleCommand_RaiseSub
call CantMove
jp EndTurn
.not_confused
-
ld a, [wEnemySubStatus1]
add a ; bit SUBSTATUS_ATTRACT
jr nc, .not_infatuated
@@ -578,7 +538,7 @@ CheckEnemyTurn: ; 3421f
; 50% chance of infatuation
call BattleRandom
- cp 1 + 50 percent
+ cp 50 percent + 1
jr c, .not_infatuated
ld hl, InfatuationText
@@ -588,7 +548,6 @@ CheckEnemyTurn: ; 3421f
.not_infatuated
-
; We can't disable a move that doesn't exist.
ld a, [wEnemyDisabledMove]
and a
@@ -606,7 +565,6 @@ CheckEnemyTurn: ; 3421f
.no_disabled_move
-
ld hl, wEnemyMonStatus
bit PAR, [hl]
ret z
@@ -621,19 +579,13 @@ CheckEnemyTurn: ; 3421f
call CantMove
; fallthrough
-; 34385
-
-EndTurn: ; 34385
+EndTurn:
ld a, $1
ld [wTurnEnded], a
jp ResetDamage
-; 3438d
-
-
-MoveDisabled: ; 3438d
-
+MoveDisabled:
; Make sure any charged moves fail
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVarAddr
@@ -647,11 +599,7 @@ MoveDisabled: ; 3438d
ld hl, DisabledMoveText
jp StdBattleTextBox
-; 343a5
-
-
-HitConfusion: ; 343a5
-
+HitConfusion:
ld hl, HurtItselfText
call StdBattleTextBox
@@ -676,14 +624,11 @@ HitConfusion: ; 343a5
call CallBattleCore
ld a, $1
ld [hBGMapMode], a
- ld c, $1
- call PlayerHurtItself
+ ld c, TRUE
+ call DoPlayerDamage
jp BattleCommand_RaiseSub
-; 343db
-
-
-BattleCommand_CheckObedience: ; 343db
+BattleCommand_CheckObedience:
; checkobedience
; Enemy can't disobey
@@ -725,7 +670,6 @@ BattleCommand_CheckObedience: ; 343db
cp [hl]
ret z
-
.obeylevel
; The maximum obedience level is constrained by owned badges:
ld hl, wJohtoBadges
@@ -753,7 +697,6 @@ BattleCommand_CheckObedience: ; 343db
; no badges
ld a, 10
-
.getlevel
; c = obedience level
; d = monster level
@@ -772,14 +715,12 @@ BattleCommand_CheckObedience: ; 343db
jr nc, .checklevel
ld b, $ff
-
.checklevel
; If the monster's level is lower than the obedience level, it will obey.
ld a, c
cp d
ret nc
-
; Random number from 0 to obedience level + monster level
.rand1
call BattleRandom
@@ -797,7 +738,6 @@ BattleCommand_CheckObedience: ; 343db
call IgnoreSleepOnly
ret c
-
; Another random number from 0 to obedience level + monster level
.rand2
call BattleRandom
@@ -808,7 +748,6 @@ BattleCommand_CheckObedience: ; 343db
cp c
jr c, .UseInstead
-
; No hope of using a move now.
; b = number of levels the monster is above the obedience level
@@ -831,7 +770,6 @@ BattleCommand_CheckObedience: ; 343db
call HitConfusion
jp .EndDisobedience
-
.Nap:
call BattleRandom
add a
@@ -844,7 +782,6 @@ BattleCommand_CheckObedience: ; 343db
ld hl, BeganToNapText
jr .Print
-
.DoNothing:
; 4 random choices
call BattleRandom
@@ -868,9 +805,7 @@ BattleCommand_CheckObedience: ; 343db
call StdBattleTextBox
jp .EndDisobedience
-
.UseInstead:
-
; Can't use another move if the monster only has one!
ld a, [wBattleMonMoves + 1]
and a
@@ -881,7 +816,6 @@ BattleCommand_CheckObedience: ; 343db
and a
jr nz, .DoNothing
-
ld hl, wBattleMonPP
ld de, wBattleMonMoves
ld b, 0
@@ -902,7 +836,6 @@ BattleCommand_CheckObedience: ; 343db
and a
jr nz, .GetTotalPP
-
.CheckMovePP:
ld hl, wBattleMonPP
ld a, [wCurMoveNum]
@@ -916,7 +849,6 @@ BattleCommand_CheckObedience: ; 343db
cp b
jr z, .DoNothing
-
; Make sure we can actually use the move once we get there.
ld a, 1
ld [wAlreadyDisobeyed], a
@@ -929,7 +861,6 @@ BattleCommand_CheckObedience: ; 343db
ld c, a
push af
-
.RandomMove:
call BattleRandom
maskbits NUM_MOVES
@@ -951,7 +882,6 @@ BattleCommand_CheckObedience: ; 343db
and PP_MASK
jr z, .RandomMove
-
; Use it.
ld a, [wCurMoveNum]
ld c, a
@@ -965,12 +895,10 @@ BattleCommand_CheckObedience: ; 343db
call UpdateMoveData
call DoMove
-
; Restore original move choice.
pop af
ld [wCurMoveNum], a
-
.EndDisobedience:
xor a
ld [wLastPlayerMove], a
@@ -984,11 +912,7 @@ BattleCommand_CheckObedience: ; 343db
jp EndMoveEffect
-; 3451f
-
-
-IgnoreSleepOnly: ; 3451f
-
+IgnoreSleepOnly:
ld a, BATTLE_VARS_MOVE_ANIM
call GetBattleVar
@@ -1015,19 +939,12 @@ IgnoreSleepOnly: ; 3451f
scf
ret
-; 34541
-
-
-BattleCommand_UsedMoveText: ; 34541
+BattleCommand_UsedMoveText:
; usedmovetext
farcall DisplayUsedMoveText
ret
-; 34548
-
-
-CheckUserIsCharging: ; 34548
-
+CheckUserIsCharging:
ld a, [hBattleTurn]
and a
ld a, [wPlayerCharging] ; player
@@ -1037,10 +954,7 @@ CheckUserIsCharging: ; 34548
and a
ret
-; 34555
-
-
-BattleCommand_DoTurn: ; 34555
+BattleCommand_DoTurn:
call CheckUserIsCharging
ret nz
@@ -1165,9 +1079,7 @@ BattleCommand_DoTurn: ; 34555
ld b, 1
ret
-; 34602
-
-.continuousmoves ; 34602
+.continuousmoves
db EFFECT_RAZOR_WIND
db EFFECT_SKY_ATTACK
db EFFECT_SKULL_BASH
@@ -1177,9 +1089,8 @@ BattleCommand_DoTurn: ; 34555
db EFFECT_BIDE
db EFFECT_RAMPAGE
db -1
-; 3460b
-CheckMimicUsed: ; 3460b
+CheckMimicUsed:
ld a, [hBattleTurn]
and a
ld a, [wCurMoveNum]
@@ -1209,10 +1120,7 @@ CheckMimicUsed: ; 3460b
and a
ret
-; 34631
-
-
-BattleCommand_Critical: ; 34631
+BattleCommand_Critical:
; critical
; Determine whether this attack's hit will be critical.
@@ -1302,52 +1210,13 @@ BattleCommand_Critical: ; 34631
ld [wCriticalHit], a
ret
-INCLUDE "data/battle/critical_hits.asm"
-; 346b2
-
+INCLUDE "data/moves/critical_hit_moves.asm"
-BattleCommand_TripleKick: ; 346b2
-; triplekick
+INCLUDE "data/battle/critical_hit_chances.asm"
- ld a, [wKickCounter]
- ld b, a
- inc b
- ld hl, wCurDamage + 1
- ld a, [hld]
- ld e, a
- ld a, [hli]
- ld d, a
-.next_kick
- dec b
- ret z
- ld a, [hl]
- add e
- ld [hld], a
- ld a, [hl]
- adc d
- ld [hli], a
-
-; No overflow.
- jr nc, .next_kick
- ld a, $ff
- ld [hld], a
- ld [hl], a
- ret
-
-; 346cd
-
-
-BattleCommand_KickCounter: ; 346cd
-; kickcounter
-
- ld hl, wKickCounter
- inc [hl]
- ret
+INCLUDE "engine/battle/move_effects/triple_kick.asm"
-; 346d2
-
-
-BattleCommand_Stab: ; 346d2
+BattleCommand_Stab:
; STAB = Same Type Attack Bonus
ld a, BATTLE_VARS_MOVE_ANIM
call GetBattleVar
@@ -1531,19 +1400,16 @@ BattleCommand_Stab: ; 346d2
ld [wTypeModifier], a
ret
-; 347c8
-
-
-BattleCheckTypeMatchup: ; 347c8
+BattleCheckTypeMatchup:
ld hl, wEnemyMonType1
ld a, [hBattleTurn]
and a
jr z, CheckTypeMatchup
ld hl, wBattleMonType1
-CheckTypeMatchup: ; 347d3
+CheckTypeMatchup:
; There is an incorrect assumption about this function made in the AI related code: when
-; the AI calls CheckTypeMatchup (not BattleCheckTypeMatchup), it assumes that placing
-; the offensive type in a will make this function do the right thing. Since a is overwritten,
+; the AI calls CheckTypeMatchup (not BattleCheckTypeMatchup), it assumes that placing the
+; offensive type in a will make this function do the right thing. Since a is overwritten,
; this assumption is incorrect. A simple fix would be to load the move type for the
; current move into a in BattleCheckTypeMatchup, before falling through, which is
; consistent with how the rest of the code assumes this code works like.
@@ -1613,10 +1479,7 @@ CheckTypeMatchup: ; 347d3
pop hl
ret
-; 34833
-
-
-BattleCommand_ResetTypeMatchup: ; 34833
+BattleCommand_ResetTypeMatchup:
; Reset the type matchup multiplier to 1.0, if the type matchup is not 0.
; If there is immunity in play, the move automatically misses.
call BattleCheckTypeMatchup
@@ -1635,13 +1498,11 @@ BattleCommand_ResetTypeMatchup: ; 34833
ld [wTypeMatchup], a
ret
-; 3484e
-
INCLUDE "engine/battle/ai/switch.asm"
-INCLUDE "data/battle/type_matchups.asm"
+INCLUDE "data/types/type_matchups.asm"
-BattleCommand_DamageVariation: ; 34cfd
+BattleCommand_DamageVariation:
; damagevariation
; Modify the damage spread between 85% and 100%.
@@ -1650,7 +1511,6 @@ BattleCommand_DamageVariation: ; 34cfd
; is not consistent. This makes the highest damage multipliers
; rarer than normal.
-
; No point in reducing 1 or 0 damage.
ld hl, wCurDamage
ld a, [hli]
@@ -1694,10 +1554,7 @@ BattleCommand_DamageVariation: ; 34cfd
ld [hl], a
ret
-; 34d32
-
-
-BattleCommand_CheckHit: ; 34d32
+BattleCommand_CheckHit:
; checkhit
call .DreamEater
@@ -1765,7 +1622,6 @@ BattleCommand_CheckHit: ; 34d32
.Hit:
ret
-
.Miss:
; Keep the damage value intact if we're using (Hi) Jump Kick.
ld a, BATTLE_VARS_MOVE_EFFECT
@@ -1779,7 +1635,6 @@ BattleCommand_CheckHit: ; 34d32
ld [wAttackMissed], a
ret
-
.DreamEater:
; Return z if we're trying to eat the dream of
; a monster that isn't sleeping.
@@ -1793,7 +1648,6 @@ BattleCommand_CheckHit: ; 34d32
and SLP
ret
-
.Protect:
; Return nz if the opponent is protected.
ld a, BATTLE_VARS_SUBSTATUS1_OPP
@@ -1815,7 +1669,6 @@ BattleCommand_CheckHit: ; 34d32
and a
ret
-
.LockOn:
; Return nz if we are locked-on and aren't trying to use Earthquake,
; Fissure or Magnitude on a monster that is flying.
@@ -1845,7 +1698,6 @@ BattleCommand_CheckHit: ; 34d32
and a
ret
-
.DrainSub:
; Return z if using an HP drain move on a substitute.
call CheckSubstituteOpp
@@ -1864,7 +1716,6 @@ BattleCommand_CheckHit: ; 34d32
and a
ret
-
.FlyDigMoves:
; Check for moves that can hit underground/flying opponents.
; Return z if the current move can hit the opponent.
@@ -1900,7 +1751,6 @@ BattleCommand_CheckHit: ; 34d32
cp MAGNITUDE
ret
-
.ThunderRain:
; Return z if the current move always hits in rain, and it is raining.
ld a, BATTLE_VARS_MOVE_EFFECT
@@ -1912,16 +1762,13 @@ BattleCommand_CheckHit: ; 34d32
cp WEATHER_RAIN
ret
-
.XAccuracy:
ld a, BATTLE_VARS_SUBSTATUS4
call GetBattleVar
bit SUBSTATUS_X_ACCURACY, a
ret
-
.StatModifiers:
-
ld a, [hBattleTurn]
and a
@@ -2013,10 +1860,8 @@ BattleCommand_CheckHit: ; 34d32
ret
INCLUDE "data/battle/accuracy_multipliers.asm"
-; 34ecc
-
-BattleCommand_EffectChance: ; 34ecc
+BattleCommand_EffectChance:
; effectchance
xor a
@@ -2043,10 +1888,7 @@ BattleCommand_EffectChance: ; 34ecc
and a
ret
-; 34eee
-
-
-BattleCommand_LowerSub: ; 34eee
+BattleCommand_LowerSub:
; lowersub
ld a, BATTLE_VARS_SUBSTATUS4
@@ -2114,19 +1956,13 @@ BattleCommand_LowerSub: ; 34eee
ld [wSomeoneIsRampaging], a
ret
-; 34f57
-
-
-BattleCommand_HitTarget: ; 34f57
-; hittarget
+BattleCommand_MoveAnim:
+; moveanim
call BattleCommand_LowerSub
- call BattleCommand_HitTargetNoSub
+ call BattleCommand_MoveAnimNoSub
jp BattleCommand_RaiseSub
-; 34f60
-
-
-BattleCommand_HitTargetNoSub: ; 34f60
+BattleCommand_MoveAnimNoSub:
ld a, [wAttackMissed]
and a
jp nz, BattleCommand_MoveDelay
@@ -2144,20 +1980,19 @@ BattleCommand_HitTargetNoSub: ; 34f60
ld a, BATTLE_VARS_MOVE_EFFECT
call GetBattleVar
cp EFFECT_MULTI_HIT
- jr z, .multihit
+ jr z, .alternate_anim
cp EFFECT_CONVERSION
- jr z, .conversion
+ jr z, .alternate_anim
cp EFFECT_DOUBLE_HIT
- jr z, .doublehit
+ jr z, .alternate_anim
cp EFFECT_POISON_MULTI_HIT
- jr z, .twineedle
+ jr z, .alternate_anim
cp EFFECT_TRIPLE_KICK
jr z, .triplekick
xor a
ld [wKickCounter], a
.triplekick
-
ld a, BATTLE_VARS_MOVE_ANIM
call GetBattleVar
ld e, a
@@ -2167,18 +2002,13 @@ BattleCommand_HitTargetNoSub: ; 34f60
ld a, BATTLE_VARS_MOVE_ANIM
call GetBattleVar
cp FLY
- jr z, .fly_dig
+ jr z, .clear_sprite
cp DIG
ret nz
-
-.fly_dig
-; clear sprite
+.clear_sprite
jp AppearUserLowerSub
-.multihit
-.conversion
-.doublehit
-.twineedle
+.alternate_anim
ld a, [wKickCounter]
and 1
xor 1
@@ -2196,10 +2026,7 @@ BattleCommand_HitTargetNoSub: ; 34f60
ld [wNumHits], a
jp PlayFXAnimID
-; 34fd1
-
-
-BattleCommand_StatUpAnim: ; 34fd1
+BattleCommand_StatUpAnim:
ld a, [wAttackMissed]
and a
jp nz, BattleCommand_MoveDelay
@@ -2207,10 +2034,7 @@ BattleCommand_StatUpAnim: ; 34fd1
xor a
jr BattleCommand_StatUpDownAnim
-; 34fdb
-
-
-BattleCommand_StatDownAnim: ; 34fdb
+BattleCommand_StatDownAnim:
ld a, [wAttackMissed]
and a
jp nz, BattleCommand_MoveDelay
@@ -2222,10 +2046,8 @@ BattleCommand_StatDownAnim: ; 34fdb
ld a, BATTLEANIM_WOBBLE
; fallthrough
-; 34feb
-
-BattleCommand_StatUpDownAnim: ; 34feb
+BattleCommand_StatUpDownAnim:
ld [wNumHits], a
xor a
ld [wKickCounter], a
@@ -2235,10 +2057,7 @@ BattleCommand_StatUpDownAnim: ; 34feb
ld d, 0
jp PlayFXAnimID
-; 34ffd
-
-
-BattleCommand_SwitchTurn: ; 34ffd
+BattleCommand_SwitchTurn:
; switchturn
ld a, [hBattleTurn]
@@ -2246,10 +2065,7 @@ BattleCommand_SwitchTurn: ; 34ffd
ld [hBattleTurn], a
ret
-; 35004
-
-
-BattleCommand_RaiseSub: ; 35004
+BattleCommand_RaiseSub:
; raisesub
ld a, BATTLE_VARS_SUBSTATUS4
@@ -2268,10 +2084,7 @@ BattleCommand_RaiseSub: ; 35004
ld a, SUBSTITUTE
jp LoadAnim
-; 35023
-
-
-BattleCommand_FailureText: ; 35023
+BattleCommand_FailureText:
; failuretext
; If the move missed or failed, load the appropriate
; text, and end the effects of multi-turn or multi-
@@ -2313,68 +2126,68 @@ BattleCommand_FailureText: ; 35023
call AppearUserRaiseSub
jp EndMoveEffect
-; 3505e
-
-
-BattleCommand_CheckFaint: ; 3505e
-; checkfaint
+BattleCommand_ApplyDamage:
+; applydamage
ld a, BATTLE_VARS_SUBSTATUS1_OPP
call GetBattleVar
bit SUBSTATUS_ENDURE, a
- jr z, .not_enduring
+ jr z, .focus_band
+
call BattleCommand_FalseSwipe
- ld b, $0
- jr nc, .okay
- ld b, $1
- jr .okay
+ ld b, 0
+ jr nc, .damage
+ ld b, 1
+ jr .damage
-.not_enduring
+.focus_band
call GetOpponentItem
ld a, b
cp HELD_FOCUS_BAND
- ld b, $0
- jr nz, .okay
+ ld b, 0
+ jr nz, .damage
+
call BattleRandom
cp c
- jr nc, .okay
+ jr nc, .damage
call BattleCommand_FalseSwipe
- ld b, $0
- jr nc, .okay
- ld b, $2
-.okay
+ ld b, 0
+ jr nc, .damage
+ ld b, 2
+
+.damage
push bc
- call .check_sub
- ld c, $0
+ call .update_damage_taken
+ ld c, FALSE
ld a, [hBattleTurn]
and a
jr nz, .damage_player
- call EnemyHurtItself
+ call DoEnemyDamage
jr .done_damage
.damage_player
- call PlayerHurtItself
+ call DoPlayerDamage
.done_damage
pop bc
ld a, b
and a
ret z
+
dec a
- jr nz, .not_enduring2
+ jr nz, .focus_band_text
ld hl, EnduredText
jp StdBattleTextBox
-.not_enduring2
+.focus_band_text
call GetOpponentItem
ld a, [hl]
ld [wNamedObjectIndexBuffer], a
call GetItemName
-
ld hl, HungOnText
jp StdBattleTextBox
-.check_sub
+.update_damage_taken
ld a, BATTLE_VARS_SUBSTATUS4_OPP
call GetBattleVar
bit SUBSTATUS_SUBSTITUTE, a
@@ -2383,10 +2196,10 @@ BattleCommand_CheckFaint: ; 3505e
ld de, wPlayerDamageTaken + 1
ld a, [hBattleTurn]
and a
- jr nz, .damage_taken
+ jr nz, .got_damage_taken
ld de, wEnemyDamageTaken + 1
-.damage_taken
+.got_damage_taken
ld a, [wCurDamage + 1]
ld b, a
ld a, [de]
@@ -2405,10 +2218,7 @@ BattleCommand_CheckFaint: ; 3505e
ld [de], a
ret
-; 350e4
-
-
-GetFailureResultText: ; 350e4
+GetFailureResultText:
ld hl, DoesntAffectText
ld de, DoesntAffectText
ld a, [wTypeModifier]
@@ -2443,10 +2253,10 @@ GetFailureResultText: ; 350e4
ld hl, wCurDamage
ld a, [hli]
ld b, [hl]
- rept 3
+rept 3
srl a
rr b
- endr
+endr
ld [hl], b
dec hl
ld [hli], a
@@ -2460,13 +2270,13 @@ GetFailureResultText: ; 350e4
ld a, $1
ld [wKickCounter], a
call LoadMoveAnim
- ld c, $1
+ ld c, TRUE
ld a, [hBattleTurn]
and a
- jp nz, EnemyHurtItself
- jp PlayerHurtItself
+ jp nz, DoEnemyDamage
+ jp DoPlayerDamage
-FailText_CheckOpponentProtect: ; 35157
+FailText_CheckOpponentProtect:
ld a, BATTLE_VARS_SUBSTATUS1_OPP
call GetBattleVar
bit SUBSTATUS_PROTECT, a
@@ -2476,10 +2286,7 @@ FailText_CheckOpponentProtect: ; 35157
.not_protected
jp StdBattleTextBox
-; 35165
-
-
-BattleCommanda5: ; 35165
+BattleCommand_BideFailText:
ld a, [wAttackMissed]
and a
ret z
@@ -2489,10 +2296,7 @@ BattleCommanda5: ; 35165
jp z, PrintDoesntAffect
jp PrintButItFailed
-; 35175
-
-
-BattleCommand_CriticalText: ; 35175
+BattleCommand_CriticalText:
; criticaltext
; Prints the message for critical hits or one-hit KOs.
@@ -2522,10 +2326,8 @@ BattleCommand_CriticalText: ; 35175
.texts
dw CriticalHitText
dw OneHitKOText
-; 35197
-
-BattleCommand_StartLoop: ; 35197
+BattleCommand_StartLoop:
; startloop
ld hl, wPlayerRolloutCount
@@ -2538,10 +2340,7 @@ BattleCommand_StartLoop: ; 35197
ld [hl], a
ret
-; 351a5
-
-
-BattleCommand_SuperEffectiveLoopText: ; 351a5
+BattleCommand_SuperEffectiveLoopText:
; supereffectivelooptext
ld a, BATTLE_VARS_SUBSTATUS3
@@ -2550,10 +2349,8 @@ BattleCommand_SuperEffectiveLoopText: ; 351a5
ret nz
; fallthrough
-; 351ad
-
-BattleCommand_SuperEffectiveText: ; 351ad
+BattleCommand_SuperEffectiveText:
; supereffectivetext
ld a, [wTypeModifier]
@@ -2566,10 +2363,7 @@ BattleCommand_SuperEffectiveText: ; 351ad
.print
jp StdBattleTextBox
-; 351c0
-
-
-BattleCommand_CheckDestinyBond: ; 351c0
+BattleCommand_CheckDestinyBond:
; checkdestinybond
; Faint the user if it fainted an opponent using Destiny Bond.
@@ -2656,10 +2450,7 @@ BattleCommand_CheckDestinyBond: ; 351c0
.finish
jp EndMoveEffect
-; 35250
-
-
-BattleCommand_BuildOpponentRage: ; 35250
+BattleCommand_BuildOpponentRage:
; buildopponentrage
jp .start
@@ -2690,10 +2481,7 @@ BattleCommand_BuildOpponentRage: ; 35250
call StdBattleTextBox
jp BattleCommand_SwitchTurn
-; 3527b
-
-
-BattleCommand_RageDamage: ; 3527b
+BattleCommand_RageDamage:
; ragedamage
ld a, [wCurDamage]
@@ -2713,7 +2501,7 @@ BattleCommand_RageDamage: ; 3527b
dec a
add hl, bc
jr nc, .rage_loop
- ld hl, -1
+ ld hl, $ffff
.done
ld a, h
ld [wCurDamage], a
@@ -2721,10 +2509,7 @@ BattleCommand_RageDamage: ; 3527b
ld [wCurDamage + 1], a
ret
-; 352a3
-
-
-EndMoveEffect: ; 352a3
+EndMoveEffect:
ld a, [wBattleScriptBufferAddress]
ld l, a
ld a, [wBattleScriptBufferAddress + 1]
@@ -2735,10 +2520,7 @@ EndMoveEffect: ; 352a3
ld [hl], a
ret
-; 352b1
-
-
-DittoMetalPowder: ; 352b1
+DittoMetalPowder:
ld a, MON_SPECIES
call BattlePartyAttr
ld a, [hBattleTurn]
@@ -2774,10 +2556,7 @@ DittoMetalPowder: ; 352b1
rr c
ret
-; 352dc
-
-
-BattleCommand_DamageStats: ; 352dc
+BattleCommand_DamageStats:
; damagestats
ld a, [hBattleTurn]
@@ -2785,10 +2564,8 @@ BattleCommand_DamageStats: ; 352dc
jp nz, EnemyAttackDamage
; fallthrough
-; 352e2
-
-PlayerAttackDamage: ; 352e2
+PlayerAttackDamage:
; Return move power d, player level e, enemy defense c and player attack b.
call ResetDamage
@@ -2870,10 +2647,7 @@ PlayerAttackDamage: ; 352e2
and a
ret
-; 3534d
-
-
-TruncateHL_BC: ; 3534d
+TruncateHL_BC:
.loop
; Truncate 16-bit values hl and bc to 8-bit values b and c respectively.
; b = hl, c = bc
@@ -2918,10 +2692,7 @@ TruncateHL_BC: ; 3534d
ld b, l
ret
-; 35378
-
-
-GetDamageStatsCritical: ; 35378
+GetDamageStatsCritical:
; Return carry if non-critical.
ld a, [wCriticalHit]
@@ -2930,10 +2701,8 @@ GetDamageStatsCritical: ; 35378
ret z
; fallthrough
-; 3537e
-
-GetDamageStats: ; 3537e
+GetDamageStats:
; Return the attacker's offensive stat and the defender's defensive
; stat based on whether the attacking type is physical or special.
@@ -2973,10 +2742,7 @@ GetDamageStats: ; 3537e
pop hl
ret
-; 353b5
-
-
-ThickClubBoost: ; 353b5
+ThickClubBoost:
; Return in hl the stat value at hl.
; If the attacking monster is Cubone or Marowak and
@@ -2991,10 +2757,7 @@ ThickClubBoost: ; 353b5
pop bc
ret
-; 353c3
-
-
-LightBallBoost: ; 353c3
+LightBallBoost:
; Return in hl the stat value at hl.
; If the attacking monster is Pikachu and it's
@@ -3009,10 +2772,7 @@ LightBallBoost: ; 353c3
pop bc
ret
-; 353d1
-
-
-SpeciesItemBoost: ; 353d1
+SpeciesItemBoost:
; Return in hl the stat value at hl.
; If the attacking monster is species b or c and
@@ -3052,10 +2812,7 @@ SpeciesItemBoost: ; 353d1
rl h
ret
-; 353f6
-
-
-EnemyAttackDamage: ; 353f6
+EnemyAttackDamage:
call ResetDamage
; No damage dealt with 0 power.
@@ -3133,231 +2890,9 @@ EnemyAttackDamage: ; 353f6
and a
ret
-; 35461
-
-
-BattleCommand_BeatUp: ; 35461
-; beatup
-
- call ResetDamage
- ld a, [hBattleTurn]
- and a
- jp nz, .enemy_beats_up
- ld a, [wPlayerSubStatus3]
- bit SUBSTATUS_IN_LOOP, a
- jr nz, .next_mon
- ld c, 20
- call DelayFrames
- xor a
- ld [wPlayerRolloutCount], a
- ld [wd002], a
- ld [wBeatUpHitAtLeastOnce], a
- jr .got_mon
-
-.next_mon
- ld a, [wPlayerRolloutCount]
- ld b, a
- ld a, [wPartyCount]
- sub b
- ld [wd002], a
-
-.got_mon
- ld a, [wd002]
- ld hl, wPartyMonNicknames
- call GetNick
- ld a, MON_HP
- call GetBeatupMonLocation
- ld a, [hli]
- or [hl]
- jp z, .beatup_fail ; fainted
- ld a, [wd002]
- ld c, a
- ld a, [wCurBattleMon]
- ; BUG: this can desynchronize link battles
- ; Change "cp [hl]" to "cp c" to fix
- cp [hl]
- ld hl, wBattleMonStatus
- jr z, .active_mon
- ld a, MON_STATUS
- call GetBeatupMonLocation
-.active_mon
- ld a, [hl]
- and a
- jp nz, .beatup_fail
-
- ld a, $1
- ld [wBeatUpHitAtLeastOnce], a
- ld hl, BeatUpAttackText
- call StdBattleTextBox
- ld a, [wEnemyMonSpecies]
- ld [wCurSpecies], a
- call GetBaseData
- ld a, [wBaseDefense]
- ld c, a
- push bc
- ld a, MON_SPECIES
- call GetBeatupMonLocation
- ld a, [hl]
- ld [wCurSpecies], a
- call GetBaseData
- ld a, [wBaseAttack]
- pop bc
- ld b, a
- push bc
- ld a, MON_LEVEL
- call GetBeatupMonLocation
- ld a, [hl]
- ld e, a
- pop bc
- ld a, [wPlayerMoveStructPower]
- ld d, a
- ret
-
-.enemy_beats_up
- ld a, [wEnemySubStatus3]
- bit SUBSTATUS_IN_LOOP, a
- jr nz, .not_first_enemy_beatup
-
- xor a
- ld [wEnemyRolloutCount], a
- ld [wd002], a
- ld [wBeatUpHitAtLeastOnce], a
- jr .enemy_continue
-
-.not_first_enemy_beatup
- ld a, [wEnemyRolloutCount]
- ld b, a
- ld a, [wOTPartyCount]
- sub b
- ld [wd002], a
-.enemy_continue
- ld a, [wBattleMode]
- dec a
- jr z, .wild
-
- ld a, [wLinkMode]
- and a
- jr nz, .link_or_tower
-
- ld a, [wInBattleTowerBattle]
- and a
- jr nz, .link_or_tower
-
- ld a, [wd002]
- ld c, a
- ld b, 0
- ld hl, wOTPartySpecies
- add hl, bc
- ld a, [hl]
- ld [wNamedObjectIndexBuffer], a
- call GetPokemonName
- jr .got_enemy_nick
-
-.link_or_tower
- ld a, [wd002]
- ld hl, wOTPartyMonNicknames
- ld bc, NAME_LENGTH
- call AddNTimes
- ld de, wStringBuffer1
- call CopyBytes
-.got_enemy_nick
- ld a, MON_HP
- call GetBeatupMonLocation
- ld a, [hli]
- or [hl]
- jp z, .beatup_fail
- ld a, [wd002]
- ld b, a
- ld a, [wCurOTMon]
- cp b
- ld hl, wEnemyMonStatus
- jr z, .active_enemy
-
- ld a, MON_STATUS
- call GetBeatupMonLocation
-.active_enemy
- ld a, [hl]
- and a
- jr nz, .beatup_fail
-
- ld a, $1
- ld [wBeatUpHitAtLeastOnce], a
- jr .finish_beatup
-
-.wild
- ld a, [wEnemyMonSpecies]
- ld [wNamedObjectIndexBuffer], a
- call GetPokemonName
- ld hl, BeatUpAttackText
- call StdBattleTextBox
- jp EnemyAttackDamage
-
-.finish_beatup
- ld hl, BeatUpAttackText
- call StdBattleTextBox
- ld a, [wBattleMonSpecies]
- ld [wCurSpecies], a
- call GetBaseData
- ld a, [wBaseDefense]
- ld c, a
- push bc
- ld a, MON_SPECIES
- call GetBeatupMonLocation
- ld a, [hl]
- ld [wCurSpecies], a
- call GetBaseData
- ld a, [wBaseAttack]
- pop bc
- ld b, a
- push bc
- ld a, MON_LEVEL
- call GetBeatupMonLocation
- ld a, [hl]
- ld e, a
- pop bc
- ld a, [wEnemyMoveStructPower]
- ld d, a
- ret
-
-; 355b0
+INCLUDE "engine/battle/move_effects/beat_up.asm"
-
-.beatup_fail ; 355b0
- ld b, buildopponentrage_command
- jp SkipToBattleCommand
-
-; 355b5
-
-
-BattleCommanda8: ; 355b5
- ld a, [wBeatUpHitAtLeastOnce]
- and a
- ret nz
-
- jp PrintButItFailed
-
-; 355bd
-
-
-GetBeatupMonLocation: ; 355bd
- push bc
- ld c, a
- ld b, 0
- ld a, [hBattleTurn]
- and a
- ld hl, wPartyMon1Species
- jr z, .got_species
- ld hl, wOTPartyMon1Species
-
-.got_species
- ld a, [wd002]
- add hl, bc
- call GetPartyLocation
- pop bc
- ret
-
-
-BattleCommand_ClearMissDamage: ; 355d5
+BattleCommand_ClearMissDamage:
; clearmissdamage
ld a, [wAttackMissed]
and a
@@ -3365,10 +2900,7 @@ BattleCommand_ClearMissDamage: ; 355d5
jp ResetDamage
-; 355dd
-
-
-HitSelfInConfusion: ; 355dd
+HitSelfInConfusion:
call ResetDamage
ld a, [hBattleTurn]
and a
@@ -3404,10 +2936,7 @@ HitSelfInConfusion: ; 355dd
ld e, a
ret
-; 35612
-
-
-BattleCommand_DamageCalc: ; 35612
+BattleCommand_DamageCalc:
; damagecalc
; Return a damage value for move power d, player level e, enemy defense c and player attack b.
@@ -3530,12 +3059,11 @@ BattleCommand_DamageCalc: ; 35612
ld [hDivisor], a
ld b, 4
call Divide
-.DoneItem:
+.DoneItem:
; Critical hits
call .CriticalMultiplier
-
; Update wCurDamage (capped at 997).
ld hl, wCurDamage
ld b, [hl]
@@ -3600,7 +3128,6 @@ BattleCommand_DamageCalc: ; 35612
ld a, LOW(MAX_STAT_VALUE - MIN_NEUTRAL_DAMAGE)
ld [hld], a
-
.dont_cap_3
; Minimum neutral damage is 2 (bringing the cap to 999).
inc hl
@@ -3615,7 +3142,6 @@ BattleCommand_DamageCalc: ; 35612
and a
ret
-
.CriticalMultiplier:
ld a, [wCriticalHit]
and a
@@ -3639,13 +3165,9 @@ BattleCommand_DamageCalc: ; 35612
ret
-; 35703
-
-
-INCLUDE "data/battle/type_boost_items.asm"
-
+INCLUDE "data/types/type_boost_items.asm"
-BattleCommand_ConstantDamage: ; 35726
+BattleCommand_ConstantDamage:
; constantdamage
ld hl, wBattleMonLevel
@@ -3691,7 +3213,7 @@ BattleCommand_ConstantDamage: ; 35726
cp b
jr nc, .psywave_loop
ld b, a
- ld a, $0
+ ld a, 0
jr .got_power
.super_fang
@@ -3712,9 +3234,9 @@ BattleCommand_ConstantDamage: ; 35726
and a
jr nz, .got_power
or b
- ld a, $0
+ ld a, 0
jr nz, .got_power
- ld b, $1
+ ld b, 1
jr .got_power
.got_power
@@ -3766,11 +3288,11 @@ BattleCommand_ConstantDamage: ; 35726
ld [hDividend + 2], a
.skip_to_divide
- ld b, $4
+ ld b, 4
call Divide
ld a, [hQuotient + 2]
ld b, a
- ld hl, .FlailPower
+ ld hl, FlailReversalPower
.reversal_loop
ld a, [hli]
@@ -3803,532 +3325,23 @@ BattleCommand_ConstantDamage: ; 35726
ld [hl], 1
ret
-.FlailPower:
- ; px, bp
- db 1, 200
- db 4, 150
- db 9, 100
- db 16, 80
- db 32, 40
- db 48, 20
-; 35813
-
-
-BattleCommand_Counter: ; 35813
-; counter
-
- ld a, 1
- ld [wAttackMissed], a
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- and a
- ret z
-
- ld b, a
- callfar GetMoveEffect
- ld a, b
- cp EFFECT_COUNTER
- ret z
-
- call BattleCommand_ResetTypeMatchup
- ld a, [wTypeMatchup]
- and a
- ret z
-
- call CheckOpponentWentFirst
- ret z
-
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- dec a
- ld de, wStringBuffer1
- call GetMoveData
-
- ld a, [wStringBuffer1 + MOVE_POWER]
- and a
- ret z
-
- ld a, [wStringBuffer1 + MOVE_TYPE]
- cp SPECIAL
- ret nc
-
- ld hl, wCurDamage
- ld a, [hli]
- or [hl]
- ret z
-
- ld a, [hl]
- add a
- ld [hld], a
- ld a, [hl]
- adc a
- ld [hl], a
- jr nc, .capped
- ld a, $ff
- ld [hli], a
- ld [hl], a
-.capped
-
- xor a
- ld [wAttackMissed], a
- ret
-
-; 35864
-
-
-BattleCommand_Encore: ; 35864
-; encore
-
- ld hl, wEnemyMonMoves
- ld de, wEnemyEncoreCount
- ld a, [hBattleTurn]
- and a
- jr z, .ok
- ld hl, wBattleMonMoves
- ld de, wPlayerEncoreCount
-.ok
- ld a, BATTLE_VARS_LAST_MOVE_OPP
- call GetBattleVar
- and a
- jp z, .failed
- cp STRUGGLE
- jp z, .failed
- cp ENCORE
- jp z, .failed
- cp MIRROR_MOVE
- jp z, .failed
- ld b, a
-
-.got_move
- ld a, [hli]
- cp b
- jr nz, .got_move
-
- ld bc, wBattleMonPP - wBattleMonMoves - 1
- add hl, bc
- ld a, [hl]
- and PP_MASK
- jp z, .failed
- ld a, [wAttackMissed]
- and a
- jp nz, .failed
- ld a, BATTLE_VARS_SUBSTATUS5_OPP
- call GetBattleVarAddr
- bit SUBSTATUS_ENCORED, [hl]
- jp nz, .failed
- set SUBSTATUS_ENCORED, [hl]
- call BattleRandom
- and $3
- inc a
- inc a
- inc a
- ld [de], a
- call CheckOpponentWentFirst
- jr nz, .finish_move
- ld a, [hBattleTurn]
- and a
- jr z, .force_last_enemy_move
-
- push hl
- ld a, [wLastPlayerMove]
- ld b, a
- ld c, 0
- ld hl, wBattleMonMoves
-.find_player_move
- ld a, [hli]
- cp b
- jr z, .got_player_move
- inc c
- ld a, c
- cp NUM_MOVES
- jr c, .find_player_move
- pop hl
- res SUBSTATUS_ENCORED, [hl]
- xor a
- ld [de], a
- jr .failed
+INCLUDE "data/moves/flail_reversal_power.asm"
-.got_player_move
- pop hl
- ld a, c
- ld [wCurMoveNum], a
- ld a, b
- ld [wCurPlayerMove], a
- dec a
- ld de, wPlayerMoveStruct
- call GetMoveData
- jr .finish_move
-
-.force_last_enemy_move
- push hl
- ld a, [wLastEnemyMove]
- ld b, a
- ld c, 0
- ld hl, wEnemyMonMoves
-.find_enemy_move
- ld a, [hli]
- cp b
- jr z, .got_enemy_move
- inc c
- ld a, c
- cp NUM_MOVES
- jr c, .find_enemy_move
- pop hl
- res SUBSTATUS_ENCORED, [hl]
- xor a
- ld [de], a
- jr .failed
-
-.got_enemy_move
- pop hl
- ld a, c
- ld [wCurEnemyMoveNum], a
- ld a, b
- ld [wCurEnemyMove], a
- dec a
- ld de, wEnemyMoveStruct
- call GetMoveData
-
-.finish_move
- call AnimateCurrentMove
- ld hl, GotAnEncoreText
- jp StdBattleTextBox
-
-.failed
- jp PrintDidntAffect2
-
-; 35926
-
-
-BattleCommand_PainSplit: ; 35926
-; painsplit
-
- ld a, [wAttackMissed]
- and a
- jp nz, .ButItFailed
- call CheckSubstituteOpp
- jp nz, .ButItFailed
- call AnimateCurrentMove
- ld hl, wBattleMonMaxHP + 1
- ld de, wEnemyMonMaxHP + 1
- call .PlayerShareHP
- ld a, $1
- ld [wWhichHPBar], a
- hlcoord 10, 9
- predef AnimateHPBar
- ld hl, wEnemyMonHP
- ld a, [hli]
- ld [wBuffer4], a
- ld a, [hli]
- ld [wBuffer3], a
- ld a, [hli]
- ld [wBuffer2], a
- ld a, [hl]
- ld [wBuffer1], a
- call .EnemyShareHP
- xor a
- ld [wWhichHPBar], a
- call ResetDamage
- hlcoord 2, 2
- predef AnimateHPBar
- farcall _UpdateBattleHUDs
+INCLUDE "engine/battle/move_effects/counter.asm"
- ld hl, SharedPainText
- jp StdBattleTextBox
+INCLUDE "engine/battle/move_effects/encore.asm"
-.PlayerShareHP:
- ld a, [hld]
- ld [wBuffer1], a
- ld a, [hld]
- ld [wBuffer2], a
- ld a, [hld]
- ld b, a
- ld [wBuffer3], a
- ld a, [hl]
- ld [wBuffer4], a
- dec de
- dec de
- ld a, [de]
- dec de
- add b
- ld [wCurDamage + 1], a
- ld b, [hl]
- ld a, [de]
- adc b
- srl a
- ld [wCurDamage], a
- ld a, [wCurDamage + 1]
- rr a
- ld [wCurDamage + 1], a
- inc hl
- inc hl
- inc hl
- inc de
- inc de
- inc de
+INCLUDE "engine/battle/move_effects/pain_split.asm"
-.EnemyShareHP: ; 359ac
- ld c, [hl]
- dec hl
- ld a, [wCurDamage + 1]
- sub c
- ld b, [hl]
- dec hl
- ld a, [wCurDamage]
- sbc b
- jr nc, .skip
+INCLUDE "engine/battle/move_effects/snore.asm"
- ld a, [wCurDamage]
- ld b, a
- ld a, [wCurDamage + 1]
- ld c, a
-.skip
- ld a, c
- ld [hld], a
- ld [wBuffer5], a
- ld a, b
- ld [hli], a
- ld [wBuffer6], a
- ret
+INCLUDE "engine/battle/move_effects/conversion2.asm"
-; 359cd
+INCLUDE "engine/battle/move_effects/lock_on.asm"
-.ButItFailed:
- jp PrintDidntAffect2
+INCLUDE "engine/battle/move_effects/sketch.asm"
-; 359d0
-
-
-BattleCommand_Snore: ; 359d0
-; snore
- ld a, BATTLE_VARS_STATUS
- call GetBattleVar
- and SLP
- ret nz
- call ResetDamage
- ld a, $1
- ld [wAttackMissed], a
- call FailSnore
- jp EndMoveEffect
-
-; 359e6
-
-
-BattleCommand_Conversion2: ; 359e6
-; conversion2
-
- ld a, [wAttackMissed]
- and a
- jr nz, .failed
- ld hl, wBattleMonType1
- ld a, [hBattleTurn]
- and a
- jr z, .got_type
- ld hl, wEnemyMonType1
-.got_type
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- and a
- jr z, .failed
- push hl
- dec a
- ld hl, Moves + MOVE_TYPE
- call GetMoveAttr
- ld d, a
- pop hl
- cp CURSE_T
- jr z, .failed
- call AnimateCurrentMove
- call BattleCommand_SwitchTurn
-
-.loop
- call BattleRandom
- and $1f
- cp UNUSED_TYPES
- jr c, .okay
- cp UNUSED_TYPES_END
- jr c, .loop
- cp TYPES_END
- jr nc, .loop
-.okay
- ld [hli], a
- ld [hld], a
- push hl
- ld a, BATTLE_VARS_MOVE_TYPE
- call GetBattleVarAddr
- push af
- push hl
- ld a, d
- ld [hl], a
- call BattleCheckTypeMatchup
- pop hl
- pop af
- ld [hl], a
- pop hl
- ld a, [wTypeMatchup]
- cp 10
- jr nc, .loop
- call BattleCommand_SwitchTurn
-
- ld a, [hl]
- ld [wNamedObjectIndexBuffer], a
- predef GetTypeName
- ld hl, TransformedTypeText
- jp StdBattleTextBox
-
-.failed
- jp FailConversion2
-
-; 35a53
-
-
-BattleCommand_LockOn: ; 35a53
-; lockon
-
- call CheckSubstituteOpp
- jr nz, .fail
-
- ld a, [wAttackMissed]
- and a
- jr nz, .fail
-
- ld a, BATTLE_VARS_SUBSTATUS5_OPP
- call GetBattleVarAddr
- set SUBSTATUS_LOCK_ON, [hl]
- call AnimateCurrentMove
-
- ld hl, TookAimText
- jp StdBattleTextBox
-
-.fail
- call AnimateFailedMove
- jp PrintDidntAffect
-
-; 35a74
-
-
-BattleCommand_Sketch: ; 35a74
-; sketch
-
- call ClearLastMove
-; Don't sketch during a link battle
- ld a, [wLinkMode]
- and a
- jr z, .not_linked
- call AnimateFailedMove
- jp PrintNothingHappened
-
-.not_linked
-; If the opponent has a substitute up, fail.
- call CheckSubstituteOpp
- jp nz, .fail
-; If the opponent is transformed, fail.
- ld a, BATTLE_VARS_SUBSTATUS5_OPP
- call GetBattleVarAddr
- bit SUBSTATUS_TRANSFORMED, [hl]
- jp nz, .fail
-; Get the user's moveset in its party struct.
-; This move replacement shall be permanent.
-; Pointer will be in de.
- ld a, MON_MOVES
- call UserPartyAttr
- ld d, h
- ld e, l
-; Get the battle move structs.
- ld hl, wBattleMonMoves
- ld a, [hBattleTurn]
- and a
- jr z, .get_last_move
- ld hl, wEnemyMonMoves
-.get_last_move
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- ld [wTypeMatchup], a
- ld b, a
-; Fail if move is invalid or is Struggle.
- and a
- jr z, .fail
- cp STRUGGLE
- jr z, .fail
-; Fail if user already knows that move
- ld c, NUM_MOVES
-.does_user_already_know_move
- ld a, [hli]
- cp b
- jr z, .fail
- dec c
- jr nz, .does_user_already_know_move
-; Find Sketch in the user's moveset.
-; Pointer in hl, and index in c.
- dec hl
- ld c, NUM_MOVES
-.find_sketch
- dec c
- ld a, [hld]
- cp SKETCH
- jr nz, .find_sketch
- inc hl
-; The Sketched move is loaded to that slot.
- ld a, b
- ld [hl], a
-; Copy the base PP from that move.
- push bc
- push hl
- dec a
- ld hl, Moves + MOVE_PP
- call GetMoveAttr
- pop hl
- ld bc, wBattleMonPP - wBattleMonMoves
- add hl, bc
- ld [hl], a
- pop bc
-
- ld a, [hBattleTurn]
- and a
- jr z, .user_trainer
- ld a, [wBattleMode]
- dec a
- jr nz, .user_trainer
-; wildmon
- ld a, [hl]
- push bc
- ld hl, wWildMonPP
- ld b, 0
- add hl, bc
- ld [hl], a
- ld hl, wWildMonMoves
- add hl, bc
- pop bc
- ld [hl], b
- jr .done_copy
-
-.user_trainer
- ld a, [hl]
- push af
- ld l, c
- ld h, 0
- add hl, de
- ld a, b
- ld [hl], a
- pop af
- ld de, MON_PP - MON_MOVES
- add hl, de
- ld [hl], a
-.done_copy
- call GetMoveName
- call AnimateCurrentMove
-
- ld hl, SketchedText
- jp StdBattleTextBox
-
-.fail
- call AnimateFailedMove
- jp PrintDidntAffect
-
-; 35b16
-
-
-BattleCommand_DefrostOpponent: ; 35b16
+BattleCommand_DefrostOpponent:
; defrostopponent
; Thaw the opponent if frozen, and
; raise the user's Attack one stage.
@@ -4354,344 +3367,17 @@ BattleCommand_DefrostOpponent: ; 35b16
ld [hl], a
ret
-; 35b33
-
-
-BattleCommand_SleepTalk: ; 35b33
-; sleeptalk
-
- call ClearLastMove
- ld a, [wAttackMissed]
- and a
- jr nz, .fail
- ld a, [hBattleTurn]
- and a
- ld hl, wBattleMonMoves + 1
- ld a, [wDisabledMove]
- ld d, a
- jr z, .got_moves
- ld hl, wEnemyMonMoves + 1
- ld a, [wEnemyDisabledMove]
- ld d, a
-.got_moves
- ld a, BATTLE_VARS_STATUS
- call GetBattleVar
- and SLP
- jr z, .fail
- ld a, [hl]
- and a
- jr z, .fail
- call .safely_check_has_usable_move
- jr c, .fail
- dec hl
-.sample_move
- push hl
- call BattleRandom
- maskbits NUM_MOVES
- ld c, a
- ld b, 0
- add hl, bc
- ld a, [hl]
- pop hl
- and a
- jr z, .sample_move
- ld e, a
- ld a, BATTLE_VARS_MOVE_ANIM
- call GetBattleVar
- cp e
- jr z, .sample_move
- ld a, e
- cp d
- jr z, .sample_move
- call .check_two_turn_move
- jr z, .sample_move
- ld a, BATTLE_VARS_MOVE
- call GetBattleVarAddr
- ld a, e
- ld [hl], a
- call CheckUserIsCharging
- jr nz, .charging
- ld a, [wKickCounter]
- push af
- call BattleCommand_LowerSub
- pop af
- ld [wKickCounter], a
-.charging
- call LoadMoveAnim
- call UpdateMoveData
- jp ResetTurn
-
-.fail
- call AnimateFailedMove
- jp TryPrintButItFailed
-
-.safely_check_has_usable_move
- push hl
- push de
- push bc
- call .check_has_usable_move
- pop bc
- pop de
- pop hl
- ret
-
-.check_has_usable_move
- ld a, [hBattleTurn]
- and a
- ld a, [wDisabledMove]
- jr z, .got_move_2
+INCLUDE "engine/battle/move_effects/sleep_talk.asm"
- ld a, [wEnemyDisabledMove]
-.got_move_2
- ld b, a
- ld a, BATTLE_VARS_MOVE
- call GetBattleVar
- ld c, a
- dec hl
- ld d, NUM_MOVES
-.loop2
- ld a, [hl]
- and a
- jr z, .carry
+INCLUDE "engine/battle/move_effects/destiny_bond.asm"
- cp c
- jr z, .nope
- cp b
- jr z, .nope
+INCLUDE "engine/battle/move_effects/spite.asm"
- call .check_two_turn_move
- jr nz, .no_carry
+INCLUDE "engine/battle/move_effects/false_swipe.asm"
-.nope
- inc hl
- dec d
- jr nz, .loop2
-
-.carry
- scf
- ret
-
-.no_carry
- and a
- ret
+INCLUDE "engine/battle/move_effects/heal_bell.asm"
-.check_two_turn_move
- push hl
- push de
- push bc
-
- ld b, a
- callfar GetMoveEffect
- ld a, b
-
- pop bc
- pop de
- pop hl
-
- cp EFFECT_SKULL_BASH
- ret z
- cp EFFECT_RAZOR_WIND
- ret z
- cp EFFECT_SKY_ATTACK
- ret z
- cp EFFECT_SOLARBEAM
- ret z
- cp EFFECT_FLY
- ret z
- cp EFFECT_BIDE
- ret
-
-; 35bff
-
-
-BattleCommand_DestinyBond: ; 35bff
-; destinybond
-
- ld a, BATTLE_VARS_SUBSTATUS5
- call GetBattleVarAddr
- set SUBSTATUS_DESTINY_BOND, [hl]
- call AnimateCurrentMove
- ld hl, DestinyBondEffectText
- jp StdBattleTextBox
-
-; 35c0f
-
-
-BattleCommand_Spite: ; 35c0f
-; spite
-
- ld a, [wAttackMissed]
- and a
- jp nz, .failed
- ld bc, PARTYMON_STRUCT_LENGTH ; ????
- ld hl, wEnemyMonMoves
- ld a, [hBattleTurn]
- and a
- jr z, .got_moves
- ld hl, wBattleMonMoves
-.got_moves
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- and a
- jr z, .failed
- cp STRUGGLE
- jr z, .failed
- ld b, a
- ld c, -1
-.loop
- inc c
- ld a, [hli]
- cp b
- jr nz, .loop
- ld [wTypeMatchup], a
- dec hl
- ld b, 0
- push bc
- ld c, wBattleMonPP - wBattleMonMoves
- add hl, bc
- pop bc
- ld a, [hl]
- and PP_MASK
- jr z, .failed
- push bc
- call GetMoveName
- ; lose 2-5 PP
- call BattleRandom
- and %11
- inc a
- inc a
- ld b, a
- ld a, [hl]
- and PP_MASK
- cp b
- jr nc, .deplete_pp
- ld b, a
-.deplete_pp
- ld a, [hl]
- sub b
- ld [hl], a
- push af
- ld a, MON_PP
- call OpponentPartyAttr
- ld d, b
- pop af
- pop bc
- add hl, bc
- ld e, a
- ld a, BATTLE_VARS_SUBSTATUS5_OPP
- call GetBattleVar
- bit SUBSTATUS_TRANSFORMED, a
- jr nz, .transformed
- ld a, [hBattleTurn]
- and a
- jr nz, .not_wildmon
- ld a, [wBattleMode]
- dec a
- jr nz, .not_wildmon
- ld hl, wWildMonPP
- add hl, bc
-.not_wildmon
- ld [hl], e
-.transformed
- push de
- call AnimateCurrentMove
- pop de
- ld a, d
- ld [wTypeMatchup], a
- ld hl, SpiteEffectText
- jp StdBattleTextBox
-
-.failed
- jp PrintDidntAffect2
-
-; 35c94
-
-
-BattleCommand_FalseSwipe: ; 35c94
-; falseswipe
-
- ld hl, wEnemyMonHP
- ld a, [hBattleTurn]
- and a
- jr z, .got_hp
- ld hl, wBattleMonHP
-.got_hp
- ld de, wCurDamage
- ld c, 2
- push hl
- push de
- call StringCmp
- pop de
- pop hl
- jr c, .done
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hl]
- dec a
- ld [de], a
- inc a
- jr nz, .okay
- dec de
- ld a, [de]
- dec a
- ld [de], a
-.okay
- ld a, [wCriticalHit]
- cp 2
- jr nz, .carry
- xor a
- ld [wCriticalHit], a
-.carry
- scf
- ret
-
-.done
- and a
- ret
-
-; 35cc9
-
-
-BattleCommand_HealBell: ; 35cc9
-; healbell
-
- ld a, BATTLE_VARS_SUBSTATUS1
- call GetBattleVarAddr
- res SUBSTATUS_NIGHTMARE, [hl]
- ld de, wPartyMon1Status
- ld a, [hBattleTurn]
- and a
- jr z, .got_status
- ld de, wOTPartyMon1Status
-.got_status
- ld a, BATTLE_VARS_STATUS
- call GetBattleVarAddr
- xor a
- ld [hl], a
- ld h, d
- ld l, e
- ld bc, PARTYMON_STRUCT_LENGTH
- ld d, PARTY_LENGTH
-.loop
- ld [hl], a
- add hl, bc
- dec d
- jr nz, .loop
- call AnimateCurrentMove
-
- ld hl, BellChimedText
- call StdBattleTextBox
-
- ld a, [hBattleTurn]
- and a
- jp z, CalcPlayerStats
- jp CalcEnemyStats
-
-; 35d00
-
-
-FarPlayBattleAnimation: ; 35d00
+FarPlayBattleAnimation:
; play animation de
ld a, BATTLE_VARS_SUBSTATUS3
@@ -4700,9 +3386,8 @@ FarPlayBattleAnimation: ; 35d00
ret nz
; fallthrough
-; 35d08
-PlayFXAnimID: ; 35d08
+PlayFXAnimID:
ld a, e
ld [wFXAnimID], a
ld a, d
@@ -4710,15 +3395,10 @@ PlayFXAnimID: ; 35d08
ld c, 3
call DelayFrames
-
callfar PlayBattleAnim
-
ret
-; 35d1c
-
-
-EnemyHurtItself: ; 35d1c
+DoEnemyDamage:
ld hl, wCurDamage
ld a, [hli]
ld b, a
@@ -4728,13 +3408,14 @@ EnemyHurtItself: ; 35d1c
ld a, c
and a
- jr nz, .mimic_sub_check
-
+ jr nz, .ignore_substitute
ld a, [wEnemySubStatus4]
bit SUBSTATUS_SUBSTITUTE, a
- jp nz, SelfInflictDamageToSubstitute
+ jp nz, DoSubstituteDamage
-.mimic_sub_check
+.ignore_substitute
+ ; Substract wCurDamage from wEnemyMonHP.
+ ; store original HP in little endian wBuffer3/4
ld a, [hld]
ld b, a
ld a, [wEnemyMonHP + 1]
@@ -4747,19 +3428,18 @@ EnemyHurtItself: ; 35d1c
ld [wBuffer4], a
sbc b
ld [wEnemyMonHP], a
- jr nc, .mimic_faint
+ jr nc, .no_underflow
ld a, [wBuffer4]
ld [hli], a
ld a, [wBuffer3]
ld [hl], a
-
xor a
ld hl, wEnemyMonHP
ld [hli], a
ld [hl], a
-.mimic_faint
+.no_underflow
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld [wBuffer2], a
@@ -4770,6 +3450,7 @@ EnemyHurtItself: ; 35d1c
ld [wBuffer6], a
ld a, [hl]
ld [wBuffer5], a
+
hlcoord 2, 2
xor a
ld [wWhichHPBar], a
@@ -4777,10 +3458,7 @@ EnemyHurtItself: ; 35d1c
.did_no_damage
jp RefreshBattleHuds
-; 35d7e
-
-
-PlayerHurtItself: ; 35d7e
+DoPlayerDamage:
ld hl, wCurDamage
ld a, [hli]
ld b, a
@@ -4790,12 +3468,15 @@ PlayerHurtItself: ; 35d7e
ld a, c
and a
- jr nz, .mimic_sub_check
-
+ jr nz, .ignore_substitute
ld a, [wPlayerSubStatus4]
bit SUBSTATUS_SUBSTITUTE, a
- jp nz, SelfInflictDamageToSubstitute
-.mimic_sub_check
+ jp nz, DoSubstituteDamage
+
+.ignore_substitute
+ ; Substract wCurDamage from wBattleMonHP.
+ ; store original HP in little endian wBuffer3/4
+ ; store new HP in little endian wBuffer5/6
ld a, [hld]
ld b, a
ld a, [wBattleMonHP + 1]
@@ -4809,14 +3490,13 @@ PlayerHurtItself: ; 35d7e
sbc b
ld [wBattleMonHP], a
ld [wBuffer6], a
- jr nc, .mimic_faint
+ jr nc, .no_underflow
ld a, [wBuffer4]
ld [hli], a
ld a, [wBuffer3]
ld [hl], a
xor a
-
ld hl, wBattleMonHP
ld [hli], a
ld [hl], a
@@ -4824,24 +3504,21 @@ PlayerHurtItself: ; 35d7e
ld [hli], a
ld [hl], a
-.mimic_faint
+.no_underflow
ld hl, wBattleMonMaxHP
ld a, [hli]
ld [wBuffer2], a
ld a, [hl]
ld [wBuffer1], a
+
hlcoord 10, 9
- ld a, $1
+ ld a, 1
ld [wWhichHPBar], a
predef AnimateHPBar
.did_no_damage
jp RefreshBattleHuds
-; 35de0
-
-
-SelfInflictDamageToSubstitute: ; 35de0
-
+DoSubstituteDamage:
ld hl, SubTookDamageText
call StdBattleTextBox
@@ -4898,11 +3575,7 @@ SelfInflictDamageToSubstitute: ; 35de0
.done
jp ResetDamage
-; 35e40
-
-
-UpdateMoveData: ; 35e40
-
+UpdateMoveData:
ld a, BATTLE_VARS_MOVE_ANIM
call GetBattleVarAddr
ld d, h
@@ -4918,10 +3591,7 @@ UpdateMoveData: ; 35e40
call GetMoveName
jp CopyName1
-; 35e5c
-
-
-BattleCommand_SleepTarget: ; 35e5c
+BattleCommand_SleepTarget:
; sleeptarget
call GetOpponentItem
@@ -4992,10 +3662,7 @@ BattleCommand_SleepTarget: ; 35e5c
pop hl
jp StdBattleTextBox
-; 35ece
-
-
-.CheckAIRandomFail: ; 35ece
+.CheckAIRandomFail:
; Enemy turn
ld a, [hBattleTurn]
and a
@@ -5023,10 +3690,7 @@ BattleCommand_SleepTarget: ; 35e5c
xor a
ret
-; 35eee
-
-
-BattleCommand_PoisonTarget: ; 35eee
+BattleCommand_PoisonTarget:
; poisontarget
call CheckSubstituteOpp
@@ -5061,10 +3725,7 @@ BattleCommand_PoisonTarget: ; 35eee
farcall UseHeldStatusHealingItem
ret
-; 35f2c
-
-
-BattleCommand_Poison: ; 35f2c
+BattleCommand_Poison:
; poison
ld hl, DoesntAffectText
@@ -5101,25 +3762,25 @@ BattleCommand_Poison: ; 35f2c
ld a, [hBattleTurn]
and a
- jr z, .mimic_random
+ jr z, .dont_sample_failure
ld a, [wLinkMode]
and a
- jr nz, .mimic_random
+ jr nz, .dont_sample_failure
ld a, [wInBattleTowerBattle]
and a
- jr nz, .mimic_random
+ jr nz, .dont_sample_failure
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_LOCK_ON, a
- jr nz, .mimic_random
+ jr nz, .dont_sample_failure
call BattleRandom
cp 25 percent + 1 ; 25% chance AI fails
jr c, .failed
-.mimic_random
+.dont_sample_failure
call CheckSubstituteOpp
jr nz, .failed
ld a, [wAttackMissed]
@@ -5152,18 +3813,12 @@ BattleCommand_Poison: ; 35f2c
pop hl
jp StdBattleTextBox
-; 35fc0
-
-
-.apply_poison ; 35fc0
+.apply_poison
call AnimateCurrentMove
call PoisonOpponent
jp RefreshBattleHuds
-; 35fc9
-
-
-.check_toxic ; 35fc9
+.check_toxic
ld a, BATTLE_VARS_SUBSTATUS5_OPP
call GetBattleVarAddr
ld a, [hBattleTurn]
@@ -5177,10 +3832,7 @@ BattleCommand_Poison: ; 35f2c
cp EFFECT_TOXIC
ret
-; 35fe1
-
-
-CheckIfTargetIsPoisonType: ; 35fe1
+CheckIfTargetIsPoisonType:
ld de, wEnemyMonType1
ld a, [hBattleTurn]
and a
@@ -5195,37 +3847,26 @@ CheckIfTargetIsPoisonType: ; 35fe1
cp POISON
ret
-; 35ff5
-
-
-PoisonOpponent: ; 35ff5
+PoisonOpponent:
ld a, BATTLE_VARS_STATUS_OPP
call GetBattleVarAddr
set PSN, [hl]
jp UpdateOpponentInParty
-; 35fff
-
-
-BattleCommand_DrainTarget: ; 35fff
+BattleCommand_DrainTarget:
; draintarget
call SapHealth
ld hl, SuckedHealthText
jp StdBattleTextBox
-; 36008
-
-
-BattleCommand_EatDream: ; 36008
+BattleCommand_EatDream:
; eatdream
call SapHealth
ld hl, DreamEatenText
jp StdBattleTextBox
-; 36011
-
-
-SapHealth: ; 36011
+SapHealth:
+ ; Divide damage by 2, store it in hDividend
ld hl, wCurDamage
ld a, [hli]
srl a
@@ -5235,10 +3876,11 @@ SapHealth: ; 36011
rr a
ld [hDividend + 1], a
or b
- jr nz, .ok1
- ld a, $1
+ jr nz, .at_least_one
+ ld a, 1
ld [hDividend + 1], a
-.ok1
+.at_least_one
+
ld hl, wBattleMonHP
ld de, wBattleMonMaxHP
ld a, [hBattleTurn]
@@ -5247,12 +3889,16 @@ SapHealth: ; 36011
ld hl, wEnemyMonHP
ld de, wEnemyMonMaxHP
.battlemonhp
+
+ ; Store current HP in little endian wBuffer3/4
ld bc, wBuffer4
ld a, [hli]
ld [bc], a
ld a, [hl]
dec bc
ld [bc], a
+
+ ; Store max HP in little endian wBuffer1/2
ld a, [de]
dec bc
ld [bc], a
@@ -5260,6 +3906,8 @@ SapHealth: ; 36011
ld a, [de]
dec bc
ld [bc], a
+
+ ; Add hDividend to current HP and copy it to little endian wBuffer5/6
ld a, [hDividend + 1]
ld b, [hl]
add b
@@ -5270,7 +3918,9 @@ SapHealth: ; 36011
adc b
ld [hli], a
ld [wBuffer6], a
- jr c, .okay2
+ jr c, .max_hp
+
+ ; Substract current HP from max HP (to see if we have more than max HP)
ld a, [hld]
ld b, a
ld a, [de]
@@ -5281,8 +3931,10 @@ SapHealth: ; 36011
ld a, [de]
inc de
sbc b
- jr nc, .okay3
-.okay2
+ jr nc, .finish
+
+.max_hp
+ ; Load max HP into current HP and copy it to little endian wBuffer5/6
ld a, [de]
ld [hld], a
ld [wBuffer5], a
@@ -5291,7 +3943,8 @@ SapHealth: ; 36011
ld [hli], a
ld [wBuffer6], a
inc de
-.okay3
+
+.finish
ld a, [hBattleTurn]
and a
hlcoord 10, 9
@@ -5305,10 +3958,7 @@ SapHealth: ; 36011
call RefreshBattleHuds
jp UpdateBattleMonInParty
-; 3608c
-
-
-BattleCommand_BurnTarget: ; 3608c
+BattleCommand_BurnTarget:
; burntarget
xor a
@@ -5349,10 +3999,7 @@ BattleCommand_BurnTarget: ; 3608c
farcall UseHeldStatusHealingItem
ret
-; 360dd
-
-
-Defrost: ; 360dd
+Defrost:
ld a, [hl]
and 1 << FRZ
ret z
@@ -5377,10 +4024,7 @@ Defrost: ; 360dd
ld hl, DefrostedOpponentText
jp StdBattleTextBox
-; 36102
-
-
-BattleCommand_FreezeTarget: ; 36102
+BattleCommand_FreezeTarget:
; freezetarget
xor a
@@ -5433,10 +4077,7 @@ BattleCommand_FreezeTarget: ; 36102
ld [hl], $1
ret
-; 36165
-
-
-BattleCommand_ParalyzeTarget: ; 36165
+BattleCommand_ParalyzeTarget:
; paralyzetarget
xor a
@@ -5472,80 +4113,77 @@ BattleCommand_ParalyzeTarget: ; 36165
ld hl, UseHeldStatusHealingItem
jp CallBattleCore
-; 361ac
-
-
-BattleCommand_AttackUp: ; 361ac
+BattleCommand_AttackUp:
; attackup
ld b, ATTACK
jr BattleCommand_StatUp
-BattleCommand_DefenseUp: ; 361b0
+BattleCommand_DefenseUp:
; defenseup
ld b, DEFENSE
jr BattleCommand_StatUp
-BattleCommand_SpeedUp: ; 361b4
+BattleCommand_SpeedUp:
; speedup
ld b, SPEED
jr BattleCommand_StatUp
-BattleCommand_SpecialAttackUp: ; 361b8
+BattleCommand_SpecialAttackUp:
; specialattackup
ld b, SP_ATTACK
jr BattleCommand_StatUp
-BattleCommand_SpecialDefenseUp: ; 361bc
+BattleCommand_SpecialDefenseUp:
; specialdefenseup
ld b, SP_DEFENSE
jr BattleCommand_StatUp
-BattleCommand_AccuracyUp: ; 361c0
+BattleCommand_AccuracyUp:
; accuracyup
ld b, ACCURACY
jr BattleCommand_StatUp
-BattleCommand_EvasionUp: ; 361c4
+BattleCommand_EvasionUp:
; evasionup
ld b, EVASION
jr BattleCommand_StatUp
-BattleCommand_AttackUp2: ; 361c8
+BattleCommand_AttackUp2:
; attackup2
ld b, $10 | ATTACK
jr BattleCommand_StatUp
-BattleCommand_DefenseUp2: ; 361cc
+BattleCommand_DefenseUp2:
; defenseup2
ld b, $10 | DEFENSE
jr BattleCommand_StatUp
-BattleCommand_SpeedUp2: ; 361d0
+BattleCommand_SpeedUp2:
; speedup2
ld b, $10 | SPEED
jr BattleCommand_StatUp
-BattleCommand_SpecialAttackUp2: ; 361d4
+BattleCommand_SpecialAttackUp2:
; specialattackup2
ld b, $10 | SP_ATTACK
jr BattleCommand_StatUp
-BattleCommand_SpecialDefenseUp2: ; 361d8
+BattleCommand_SpecialDefenseUp2:
; specialdefenseup2
ld b, $10 | SP_DEFENSE
jr BattleCommand_StatUp
-BattleCommand_AccuracyUp2: ; 361dc
+BattleCommand_AccuracyUp2:
; accuracyup2
ld b, $10 | ACCURACY
jr BattleCommand_StatUp
-BattleCommand_EvasionUp2: ; 361e0
+BattleCommand_EvasionUp2:
; evasionup2
ld b, $10 | EVASION
jr BattleCommand_StatUp
-BattleCommand_StatUp: ; 361e4
+BattleCommand_StatUp:
; statup
call CheckIfStatCanBeRaised
ld a, [wFailedMessage]
@@ -5553,10 +4191,7 @@ BattleCommand_StatUp: ; 361e4
ret nz
jp StatUpAnimation
-; 361ef
-
-
-CheckIfStatCanBeRaised: ; 361ef
+CheckIfStatCanBeRaised:
ld a, b
ld [wLoweredStat], a
ld hl, wPlayerStatLevels
@@ -5635,35 +4270,24 @@ CheckIfStatCanBeRaised: ; 361ef
ld [wFailedMessage], a
ret
-; 3626e
-
-
-.stats_already_max ; 3626e
+.stats_already_max
pop hl
dec [hl]
; fallthrough
-; 36270
-
-.cant_raise_stat ; 36270
+.cant_raise_stat
ld a, $2
ld [wFailedMessage], a
ld a, $1
ld [wAttackMissed], a
ret
-; 3627b
-
-
-.stat_raise_failed ; 3627b
+.stat_raise_failed
ld a, $1
ld [wFailedMessage], a
ret
-; 36281
-
-
-StatUpAnimation: ; 36281
+StatUpAnimation:
ld bc, wPlayerMinimized
ld hl, DropPlayerSub
ld a, [hBattleTurn]
@@ -5688,79 +4312,76 @@ StatUpAnimation: ; 36281
call WaitBGMap
jp BattleCommand_MoveDelay
-; 362ad
-
-
-BattleCommand_AttackDown: ; 362ad
+BattleCommand_AttackDown:
; attackdown
ld a, ATTACK
jr BattleCommand_StatDown
-BattleCommand_DefenseDown: ; 362b1
+BattleCommand_DefenseDown:
; defensedown
ld a, DEFENSE
jr BattleCommand_StatDown
-BattleCommand_SpeedDown: ; 362b5
+BattleCommand_SpeedDown:
; speeddown
ld a, SPEED
jr BattleCommand_StatDown
-BattleCommand_SpecialAttackDown: ; 362b9
+BattleCommand_SpecialAttackDown:
; specialattackdown
ld a, SP_ATTACK
jr BattleCommand_StatDown
-BattleCommand_SpecialDefenseDown: ; 362bd
+BattleCommand_SpecialDefenseDown:
; specialdefensedown
ld a, SP_DEFENSE
jr BattleCommand_StatDown
-BattleCommand_AccuracyDown: ; 362c1
+BattleCommand_AccuracyDown:
; accuracydown
ld a, ACCURACY
jr BattleCommand_StatDown
-BattleCommand_EvasionDown: ; 362c5
+BattleCommand_EvasionDown:
; evasiondown
ld a, EVASION
jr BattleCommand_StatDown
-BattleCommand_AttackDown2: ; 362c9
+BattleCommand_AttackDown2:
; attackdown2
ld a, $10 | ATTACK
jr BattleCommand_StatDown
-BattleCommand_DefenseDown2: ; 362cd
+BattleCommand_DefenseDown2:
; defensedown2
ld a, $10 | DEFENSE
jr BattleCommand_StatDown
-BattleCommand_SpeedDown2: ; 362d1
+BattleCommand_SpeedDown2:
; speeddown2
ld a, $10 | SPEED
jr BattleCommand_StatDown
-BattleCommand_SpecialAttackDown2: ; 362d5
+BattleCommand_SpecialAttackDown2:
; specialattackdown2
ld a, $10 | SP_ATTACK
jr BattleCommand_StatDown
-BattleCommand_SpecialDefenseDown2: ; 362d9
+BattleCommand_SpecialDefenseDown2:
; specialdefensedown2
ld a, $10 | SP_DEFENSE
jr BattleCommand_StatDown
-BattleCommand_AccuracyDown2: ; 362dd
+BattleCommand_AccuracyDown2:
; accuracydown2
ld a, $10 | ACCURACY
jr BattleCommand_StatDown
-BattleCommand_EvasionDown2: ; 362e1
+BattleCommand_EvasionDown2:
; evasiondown2
ld a, $10 | EVASION
-BattleCommand_StatDown: ; 362e3
+BattleCommand_StatDown:
; statdown
ld [wLoweredStat], a
@@ -5883,10 +4504,7 @@ BattleCommand_StatDown: ; 362e3
ld [wAttackMissed], a
ret
-; 36391
-
-
-CheckMist: ; 36391
+CheckMist:
ld a, BATTLE_VARS_MOVE_EFFECT
call GetBattleVar
cp EFFECT_ATTACK_DOWN
@@ -5911,10 +4529,7 @@ CheckMist: ; 36391
bit SUBSTATUS_MIST, a
ret
-; 363b8
-
-
-BattleCommand_StatUpMessage: ; 363b8
+BattleCommand_StatUpMessage:
ld a, [wFailedMessage]
and a
ret nz
@@ -5944,10 +4559,7 @@ BattleCommand_StatUpMessage: ; 363b8
text_jump UnknownText_0x1c0ce0
db "@"
-; 363e9
-
-
-BattleCommand_StatDownMessage: ; 363e9
+BattleCommand_StatDownMessage:
ld a, [wFailedMessage]
and a
ret nz
@@ -5976,10 +4588,7 @@ BattleCommand_StatDownMessage: ; 363e9
text_jump UnknownText_0x1c0d06
db "@"
-; 3641a
-
-
-TryLowerStat: ; 3641a
+TryLowerStat:
; Lower stat c from stat struct hl (buffer de).
push bc
@@ -6022,10 +4631,7 @@ TryLowerStat: ; 3641a
and a
ret
-; 3644c
-
-
-BattleCommand_StatUpFailText: ; 3644c
+BattleCommand_StatUpFailText:
; statupfailtext
ld a, [wFailedMessage]
and a
@@ -6043,10 +4649,7 @@ BattleCommand_StatUpFailText: ; 3644c
ld hl, WontRiseAnymoreText
jp StdBattleTextBox
-; 3646a
-
-
-BattleCommand_StatDownFailText: ; 3646a
+BattleCommand_StatDownFailText:
; statdownfailtext
ld a, [wFailedMessage]
and a
@@ -6067,10 +4670,7 @@ BattleCommand_StatDownFailText: ; 3646a
ld hl, WontDropAnymoreText
jp StdBattleTextBox
-; 3648f
-
-
-GetStatName: ; 3648f
+GetStatName:
ld hl, StatNames
ld c, "@"
.CheckName:
@@ -6089,11 +4689,9 @@ GetStatName: ; 3648f
INCLUDE "data/battle/stat_names.asm"
-
INCLUDE "data/battle/stat_multipliers.asm"
-
-BattleCommand_AllStatsUp: ; 36500
+BattleCommand_AllStatsUp:
; allstatsup
; Attack
@@ -6120,18 +4718,13 @@ BattleCommand_AllStatsUp: ; 36500
call ResetMiss
call BattleCommand_SpecialDefenseUp
jp BattleCommand_StatUpMessage
-; 3652d
-
-ResetMiss: ; 3652d
+ResetMiss:
xor a
ld [wAttackMissed], a
ret
-; 36532
-
-
-LowerStat: ; 36532
+LowerStat:
ld [wLoweredStat], a
ld hl, wPlayerStatLevels
@@ -6202,10 +4795,7 @@ LowerStat: ; 36532
ld [wFailedMessage], a
ret
-; 3658f
-
-
-BattleCommand_TriStatusChance: ; 3658f
+BattleCommand_TriStatusChance:
; tristatuschance
call BattleCommand_EffectChance
@@ -6225,20 +4815,15 @@ BattleCommand_TriStatusChance: ; 3658f
dw BattleCommand_ParalyzeTarget ; paralyze
dw BattleCommand_FreezeTarget ; freeze
dw BattleCommand_BurnTarget ; burn
-; 365a7
-
-BattleCommand_Curl: ; 365a7
+BattleCommand_Curl:
; curl
ld a, BATTLE_VARS_SUBSTATUS2
call GetBattleVarAddr
set SUBSTATUS_CURLED, [hl]
ret
-; 365af
-
-
-BattleCommand_RaiseSubNoAnim: ; 365af
+BattleCommand_RaiseSubNoAnim:
ld hl, GetBattleMonBackpic
ld a, [hBattleTurn]
and a
@@ -6250,10 +4835,7 @@ BattleCommand_RaiseSubNoAnim: ; 365af
call CallBattleCore
jp WaitBGMap
-; 365c3
-
-
-BattleCommand_LowerSubNoAnim: ; 365c3
+BattleCommand_LowerSubNoAnim:
ld hl, DropPlayerSub
ld a, [hBattleTurn]
and a
@@ -6265,10 +4847,7 @@ BattleCommand_LowerSubNoAnim: ; 365c3
call CallBattleCore
jp WaitBGMap
-; 365d7
-
-
-CalcPlayerStats: ; 365d7
+CalcPlayerStats:
ld hl, wPlayerAtkLevel
ld de, wPlayerStats
ld bc, wBattleMonAttack
@@ -6289,10 +4868,7 @@ CalcPlayerStats: ; 365d7
jp BattleCommand_SwitchTurn
-; 365fd
-
-
-CalcEnemyStats: ; 365fd
+CalcEnemyStats:
ld hl, wEnemyAtkLevel
ld de, wEnemyStats
ld bc, wEnemyMonAttack
@@ -6310,10 +4886,7 @@ CalcEnemyStats: ; 365fd
jp BattleCommand_SwitchTurn
-; 3661d
-
-
-CalcStats: ; 3661d
+CalcStats:
.loop
push af
ld a, [hli]
@@ -6382,117 +4955,9 @@ CalcStats: ; 3661d
ret
-; 36671
-
-
-BattleCommand_StoreEnergy: ; 36671
-; storeenergy
-
- ld a, BATTLE_VARS_SUBSTATUS3
- call GetBattleVar
- bit SUBSTATUS_BIDE, a
- ret z
-
- ld hl, wPlayerRolloutCount
- ld a, [hBattleTurn]
- and a
- jr z, .check_still_storing_energy
- ld hl, wEnemyRolloutCount
-.check_still_storing_energy
- dec [hl]
- jr nz, .still_storing
-
- ld a, BATTLE_VARS_SUBSTATUS3
- call GetBattleVarAddr
- res SUBSTATUS_BIDE, [hl]
+INCLUDE "engine/battle/move_effects/bide.asm"
- ld hl, UnleashedEnergyText
- call StdBattleTextBox
-
- ld a, BATTLE_VARS_MOVE_POWER
- call GetBattleVarAddr
- ld a, 1
- ld [hl], a
- ld hl, wPlayerDamageTaken + 1
- ld de, wPlayerCharging ; player
- ld a, [hBattleTurn]
- and a
- jr z, .player
- ld hl, wEnemyDamageTaken + 1
- ld de, wEnemyCharging ; enemy
-.player
- ld a, [hld]
- add a
- ld b, a
- ld [wCurDamage + 1], a
- ld a, [hl]
- rl a
- ld [wCurDamage], a
- jr nc, .not_maxed
- ld a, $ff
- ld [wCurDamage], a
- ld [wCurDamage + 1], a
-.not_maxed
- or b
- jr nz, .built_up_something
- ld a, 1
- ld [wAttackMissed], a
-.built_up_something
- xor a
- ld [hli], a
- ld [hl], a
- ld [de], a
-
- ld a, BATTLE_VARS_MOVE_ANIM
- call GetBattleVarAddr
- ld a, BIDE
- ld [hl], a
-
- ld b, unleashenergy_command
- jp SkipToBattleCommand
-
-.still_storing
- ld hl, StoringEnergyText
- call StdBattleTextBox
- jp EndMoveEffect
-
-; 366e5
-
-
-BattleCommand_UnleashEnergy: ; 366e5
-; unleashenergy
-
- ld de, wPlayerDamageTaken
- ld bc, wPlayerRolloutCount
- ld a, [hBattleTurn]
- and a
- jr z, .got_damage
- ld de, wEnemyDamageTaken
- ld bc, wEnemyRolloutCount
-.got_damage
- ld a, BATTLE_VARS_SUBSTATUS3
- call GetBattleVarAddr
- set SUBSTATUS_BIDE, [hl]
- xor a
- ld [de], a
- inc de
- ld [de], a
- ld [wPlayerMoveStructEffect], a
- ld [wEnemyMoveStructEffect], a
- call BattleRandom
- and 1
- inc a
- inc a
- ld [bc], a
- ld a, 1
- ld [wKickCounter], a
- call AnimateCurrentMove
- jp EndMoveEffect
-
-; 3671a
-
-
-BattleCommand_CheckRampage: ; 3671a
+BattleCommand_CheckRampage:
; checkrampage
ld de, wPlayerRolloutCount
@@ -6529,10 +4994,7 @@ BattleCommand_CheckRampage: ; 3671a
ld b, rampage_command
jp SkipToBattleCommand
-; 36751
-
-
-BattleCommand_Rampage: ; 36751
+BattleCommand_Rampage:
; rampage
; No rampage during Sleep Talk.
@@ -6559,113 +5021,16 @@ BattleCommand_Rampage: ; 36751
ld [wSomeoneIsRampaging], a
ret
-; 36778
-
-
-BattleCommand_Teleport: ; 36778
-; teleport
-
- ld a, [wBattleType]
- cp BATTLETYPE_SHINY
- jr z, .failed
- cp BATTLETYPE_TRAP
- jr z, .failed
- cp BATTLETYPE_CELEBI
- jr z, .failed
- cp BATTLETYPE_SUICUNE
- jr z, .failed
-
- ld a, BATTLE_VARS_SUBSTATUS5_OPP
- call GetBattleVar
- bit SUBSTATUS_CANT_RUN, a
- jr nz, .failed
-; Only need to check these next things if it's your turn
- ld a, [hBattleTurn]
- and a
- jr nz, .enemy_turn
-; Can't teleport from a trainer battle
- ld a, [wBattleMode]
- dec a
- jr nz, .failed
-; If your level is greater than the opponent's, you run without fail.
- ld a, [wCurPartyLevel]
- ld b, a
- ld a, [wBattleMonLevel]
- cp b
- jr nc, .run_away
-; Generate a number between 0 and (YourLevel + TheirLevel).
- add b
- ld c, a
- inc c
-.loop_player
- call BattleRandom
- cp c
- jr nc, .loop_player
-; If that number is greater than 4 times your level, run away.
- srl b
- srl b
- cp b
- jr nc, .run_away
-
-.failed
- call AnimateFailedMove
- jp PrintButItFailed
-
-.enemy_turn
- ld a, [wBattleMode]
- dec a
- jr nz, .failed
- ld a, [wBattleMonLevel]
- ld b, a
- ld a, [wCurPartyLevel]
- cp b
- jr nc, .run_away
- add b
- ld c, a
- inc c
-.loop_enemy
- call BattleRandom
- cp c
- jr nc, .loop_enemy
- srl b
- srl b
- cp b
- ; This does the wrong thing. What was
- ; probably intended was jr c, .failed
- ; The way this is made makes enemy use
- ; of Teleport always succeed if able
- jr nc, .run_away
-.run_away
- call UpdateBattleMonInParty
- xor a
- ld [wNumHits], a
- inc a
- ld [wForcedSwitch], a
- ld [wKickCounter], a
- call SetBattleDraw
- call BattleCommand_LowerSub
- call LoadMoveAnim
- ld c, 20
- call DelayFrames
- call SetBattleDraw
-
- ld hl, FledFromBattleText
- jp StdBattleTextBox
+INCLUDE "engine/battle/move_effects/teleport.asm"
-; 36804
-
-
-SetBattleDraw: ; 36804
+SetBattleDraw:
ld a, [wBattleResult]
- and $c0
- or $2
+ and BATTLERESULT_BITMASK
+ or DRAW
ld [wBattleResult], a
ret
-; 3680f
-
-
-BattleCommand_ForceSwitch: ; 3680f
+BattleCommand_ForceSwitch:
; forceswitch
ld a, [wBattleType]
@@ -6884,10 +5249,7 @@ BattleCommand_ForceSwitch: ; 3680f
.do_text
jp StdBattleTextBox
-; 36994
-
-
-CheckPlayerHasMonToSwitchTo: ; 36994
+CheckPlayerHasMonToSwitchTo:
ld a, [wPartyCount]
ld d, a
ld e, 0
@@ -6916,13 +5278,10 @@ CheckPlayerHasMonToSwitchTo: ; 36994
and a
ret
-; 369b6
-
-
-BattleCommand_EndLoop: ; 369b6
+BattleCommand_EndLoop:
; endloop
-; Loop back to the command before 'critical'.
+; Loop back to 'critical'.
ld de, wPlayerRolloutCount
ld bc, wPlayerDamageTaken
@@ -6985,7 +5344,7 @@ BattleCommand_EndLoop: ; 369b6
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVarAddr
res SUBSTATUS_IN_LOOP, [hl]
- call BattleCommanda8
+ call BattleCommand_BeatUpFailText
jp EndMoveEffect
.not_triple_kick
@@ -7037,7 +5396,6 @@ BattleCommand_EndLoop: ; 369b6
ld [bc], a
ret
-; Loop back to the command before 'critical'.
.loop_back_to_critical
ld a, [wBattleScriptBufferAddress + 1]
ld h, a
@@ -7054,10 +5412,7 @@ BattleCommand_EndLoop: ; 369b6
ld [wBattleScriptBufferAddress], a
ret
-; 36a82
-
-
-BattleCommand_FakeOut: ; 36a82
+BattleCommand_FakeOut:
ld a, [wAttackMissed]
and a
ret nz
@@ -7078,10 +5433,7 @@ BattleCommand_FakeOut: ; 36a82
ld [wAttackMissed], a
ret
-; 36aa0
-
-
-BattleCommand_FlinchTarget: ; 36aa0
+BattleCommand_FlinchTarget:
call CheckSubstituteOpp
ret nz
@@ -7098,19 +5450,14 @@ BattleCommand_FlinchTarget: ; 36aa0
ret nz
; fallthrough
-; 36ab5
-
-FlinchTarget: ; 36ab5
+FlinchTarget:
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVarAddr
set SUBSTATUS_FLINCHED, [hl]
jp EndRechargeOpp
-; 36abf
-
-
-CheckOpponentWentFirst: ; 36abf
+CheckOpponentWentFirst:
; Returns a=0, z if user went first
; Returns a=1, nz if opponent went first
push bc
@@ -7121,10 +5468,7 @@ CheckOpponentWentFirst: ; 36abf
pop bc
ret
-; 36ac9
-
-
-BattleCommand_HeldFlinch: ; 36ac9
+BattleCommand_HeldFlinch:
; kingsrock
ld a, [wAttackMissed]
@@ -7152,10 +5496,7 @@ BattleCommand_HeldFlinch: ; 36ac9
set SUBSTATUS_FLINCHED, [hl]
ret
-; 36af3
-
-
-BattleCommand_OHKO: ; 36af3
+BattleCommand_OHKO:
; ohko
call ResetDamage
@@ -7201,10 +5542,7 @@ BattleCommand_OHKO: ; 36af3
ld [wAttackMissed], a
ret
-; 36b3a
-
-
-BattleCommand_CheckCharge: ; 36b3a
+BattleCommand_CheckCharge:
; checkcharge
ld a, BATTLE_VARS_SUBSTATUS3
@@ -7217,10 +5555,7 @@ BattleCommand_CheckCharge: ; 36b3a
ld b, charge_command
jp SkipToBattleCommand
-; 36b4d
-
-
-BattleCommand_Charge: ; 36b4d
+BattleCommand_Charge:
; charge
call BattleCommand_ClearText
@@ -7301,7 +5636,7 @@ BattleCommand_Charge: ; 36b4d
jp EndMoveEffect
.UsedText:
- text_jump UnknownText_0x1c0d0e ; "[USER]"
+ text_jump UnknownText_0x1c0d0e ; "<USER>"
start_asm
ld a, BATTLE_VARS_MOVE_ANIM
call GetBattleVar
@@ -7360,17 +5695,12 @@ BattleCommand_Charge: ; 36b4d
; 'dug a hole!'
text_jump UnknownText_0x1c0d6c
db "@"
-; 36c2c
-
-BattleCommand3c: ; 36c2c
+BattleCommand3c:
; unused
ret
-; 36c2d
-
-
-BattleCommand_TrapTarget: ; 36c2d
+BattleCommand_TrapTarget:
; traptarget
ld a, [wAttackMissed]
@@ -7425,48 +5755,12 @@ BattleCommand_TrapTarget: ; 36c2d
dbw FIRE_SPIN, FireSpinTrapText ; 'was trapped!'
dbw CLAMP, ClampedByText ; 'was CLAMPED by'
dbw WHIRLPOOL, WhirlpoolTrapText ; 'was trapped!'
-; 36c7e
-
-
-BattleCommand_Mist: ; 36c7e
-; mist
-
- ld a, BATTLE_VARS_SUBSTATUS4
- call GetBattleVarAddr
- bit SUBSTATUS_MIST, [hl]
- jr nz, .already_mist
- set SUBSTATUS_MIST, [hl]
- call AnimateCurrentMove
- ld hl, MistText
- jp StdBattleTextBox
-
-.already_mist
- call AnimateFailedMove
- jp PrintButItFailed
-
-; 36c98
-
-
-BattleCommand_FocusEnergy: ; 36c98
-; focusenergy
-
- ld a, BATTLE_VARS_SUBSTATUS4
- call GetBattleVarAddr
- bit SUBSTATUS_FOCUS_ENERGY, [hl]
- jr nz, .already_pumped
- set SUBSTATUS_FOCUS_ENERGY, [hl]
- call AnimateCurrentMove
- ld hl, GettingPumpedText
- jp StdBattleTextBox
-.already_pumped
- call AnimateFailedMove
- jp PrintButItFailed
+INCLUDE "engine/battle/move_effects/mist.asm"
-; 36cb2
+INCLUDE "engine/battle/move_effects/focus_energy.asm"
-
-BattleCommand_Recoil: ; 36cb2
+BattleCommand_Recoil:
; recoil
ld hl, wBattleMonMaxHP
@@ -7530,10 +5824,7 @@ BattleCommand_Recoil: ; 36cb2
ld hl, RecoilText
jp StdBattleTextBox
-; 36d1d
-
-
-BattleCommand_ConfuseTarget: ; 36d1d
+BattleCommand_ConfuseTarget:
; confusetarget
call GetOpponentItem
@@ -7553,8 +5844,7 @@ BattleCommand_ConfuseTarget: ; 36d1d
ret nz
jr BattleCommand_FinishConfusingTarget
-
-BattleCommand_Confuse: ; 36d3b
+BattleCommand_Confuse:
; confuse
call GetOpponentItem
@@ -7583,7 +5873,7 @@ BattleCommand_Confuse: ; 36d3b
ld a, [wAttackMissed]
and a
jr nz, BattleCommand_Confuse_CheckSnore_Swagger_ConfuseHit
-BattleCommand_FinishConfusingTarget: ; 36d70
+BattleCommand_FinishConfusingTarget:
ld bc, wEnemyConfuseCount
ld a, [hBattleTurn]
and a
@@ -7626,9 +5916,7 @@ BattleCommand_FinishConfusingTarget: ; 36d70
ld hl, UseConfusionHealingItem
jp CallBattleCore
-; 36db6
-
-BattleCommand_Confuse_CheckSnore_Swagger_ConfuseHit: ; 36db6
+BattleCommand_Confuse_CheckSnore_Swagger_ConfuseHit:
ld a, BATTLE_VARS_MOVE_EFFECT
call GetBattleVar
cp EFFECT_CONFUSE_HIT
@@ -7639,10 +5927,7 @@ BattleCommand_Confuse_CheckSnore_Swagger_ConfuseHit: ; 36db6
ret z
jp PrintDidntAffect2
-; 36dc7
-
-
-BattleCommand_Paralyze: ; 36dc7
+BattleCommand_Paralyze:
; paralyze
ld a, BATTLE_VARS_STATUS_OPP
@@ -7681,7 +5966,7 @@ BattleCommand_Paralyze: ; 36dc7
jr nz, .dont_sample_failure
call BattleRandom
- cp 1 + 25 percent
+ cp 25 percent + 1 ; 25% chance AI fails
jr c, .failed
.dont_sample_failure
@@ -7722,10 +6007,7 @@ BattleCommand_Paralyze: ; 36dc7
call AnimateFailedMove
jp PrintDoesntAffect
-; 36e5b
-
-
-CheckMoveTypeMatchesTarget: ; 36e5b
+CheckMoveTypeMatchesTarget:
; Compare move type to opponent type.
; Return z if matching the opponent type,
; unless the move is Normal (Tri Attack).
@@ -7760,111 +6042,16 @@ CheckMoveTypeMatchesTarget: ; 36e5b
pop hl
ret
-; 36e7c
-
-
-BattleCommand_Substitute: ; 36e7c
-; substitute
-
- call BattleCommand_MoveDelay
- ld hl, wBattleMonMaxHP
- ld de, wPlayerSubstituteHP
- ld a, [hBattleTurn]
- and a
- jr z, .got_hp
- ld hl, wEnemyMonMaxHP
- ld de, wEnemySubstituteHP
-.got_hp
-
- ld a, BATTLE_VARS_SUBSTATUS4
- call GetBattleVar
- bit SUBSTATUS_SUBSTITUTE, a
- jr nz, .already_has_sub
-
- ld a, [hli]
- ld b, [hl]
- srl a
- rr b
- srl a
- rr b
- dec hl
- dec hl
- ld a, b
- ld [de], a
- ld a, [hld]
- sub b
- ld e, a
- ld a, [hl]
- sbc 0
- ld d, a
- jr c, .too_weak_to_sub
- ld a, d
- or e
- jr z, .too_weak_to_sub
- ld [hl], d
- inc hl
- ld [hl], e
-
- ld a, BATTLE_VARS_SUBSTATUS4
- call GetBattleVarAddr
- set SUBSTATUS_SUBSTITUTE, [hl]
-
- ld hl, wPlayerWrapCount
- ld de, wPlayerTrappingMove
- ld a, [hBattleTurn]
- and a
- jr z, .player
- ld hl, wEnemyWrapCount
- ld de, wEnemyTrappingMove
-.player
-
- xor a
- ld [hl], a
- ld [de], a
- call _CheckBattleScene
- jr c, .no_anim
-
- xor a
- ld [wNumHits], a
- ld [wFXAnimID + 1], a
- ld [wKickCounter], a
- ld a, SUBSTITUTE
- call LoadAnim
- jr .finish
-
-.no_anim
- call BattleCommand_RaiseSubNoAnim
-.finish
- ld hl, MadeSubstituteText
- call StdBattleTextBox
- jp RefreshBattleHuds
+INCLUDE "engine/battle/move_effects/substitute.asm"
-.already_has_sub
- call CheckUserIsCharging
- call nz, BattleCommand_RaiseSub
- ld hl, HasSubstituteText
- jr .jp_stdbattletextbox
-
-.too_weak_to_sub
- call CheckUserIsCharging
- call nz, BattleCommand_RaiseSub
- ld hl, TooWeakSubText
-.jp_stdbattletextbox
- jp StdBattleTextBox
-
-; 36f0b
-
-BattleCommand_RechargeNextTurn: ; 36f0b
+BattleCommand_RechargeNextTurn:
; rechargenextturn
ld a, BATTLE_VARS_SUBSTATUS4
call GetBattleVarAddr
set SUBSTATUS_RECHARGE, [hl]
ret
-; 36f13
-
-
-EndRechargeOpp: ; 36f13
+EndRechargeOpp:
push hl
ld a, BATTLE_VARS_SUBSTATUS4_OPP
call GetBattleVarAddr
@@ -7872,20 +6059,9 @@ EndRechargeOpp: ; 36f13
pop hl
ret
-; 36f1d
+INCLUDE "engine/battle/move_effects/rage.asm"
-
-BattleCommand_Rage: ; 36f1d
-; rage
- ld a, BATTLE_VARS_SUBSTATUS4
- call GetBattleVarAddr
- set SUBSTATUS_RAGE, [hl]
- ret
-
-; 36f25
-
-
-BattleCommand_DoubleFlyingDamage: ; 36f25
+BattleCommand_DoubleFlyingDamage:
; doubleflyingdamage
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVar
@@ -7893,10 +6069,7 @@ BattleCommand_DoubleFlyingDamage: ; 36f25
ret z
jr DoubleDamage
-; 36f2f
-
-
-BattleCommand_DoubleUndergroundDamage: ; 36f2f
+BattleCommand_DoubleUndergroundDamage:
; doubleundergrounddamage
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVar
@@ -7904,10 +6077,8 @@ BattleCommand_DoubleUndergroundDamage: ; 36f2f
ret z
; fallthrough
-; 36f37
-
-DoubleDamage: ; 36f37
+DoubleDamage:
ld hl, wCurDamage + 1
sla [hl]
dec hl
@@ -7920,322 +6091,19 @@ DoubleDamage: ; 36f37
.quit
ret
-; 36f46
+INCLUDE "engine/battle/move_effects/mimic.asm"
+INCLUDE "engine/battle/move_effects/leech_seed.asm"
-BattleCommand_Mimic: ; 36f46
-; mimic
+INCLUDE "engine/battle/move_effects/splash.asm"
- call ClearLastMove
- call BattleCommand_MoveDelay
- ld a, [wAttackMissed]
- and a
- jr nz, .fail
- ld hl, wBattleMonMoves
- ld a, [hBattleTurn]
- and a
- jr z, .player_turn
- ld hl, wEnemyMonMoves
-.player_turn
- call CheckHiddenOpponent
- jr nz, .fail
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- and a
- jr z, .fail
- cp STRUGGLE
- jr z, .fail
- ld b, a
- ld c, NUM_MOVES
-.check_already_knows_move
- ld a, [hli]
- cp b
- jr z, .fail
- dec c
- jr nz, .check_already_knows_move
- dec hl
-.find_mimic
- ld a, [hld]
- cp MIMIC
- jr nz, .find_mimic
- inc hl
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- ld [hl], a
- ld [wNamedObjectIndexBuffer], a
- ld bc, wBattleMonPP - wBattleMonMoves
- add hl, bc
- ld [hl], 5
- call GetMoveName
- call AnimateCurrentMove
- ld hl, LearnedMoveText
- jp StdBattleTextBox
-
-.fail
- jp FailMimic
+INCLUDE "engine/battle/move_effects/disable.asm"
-; 36f9d
+INCLUDE "engine/battle/move_effects/pay_day.asm"
+INCLUDE "engine/battle/move_effects/conversion.asm"
-BattleCommand_LeechSeed: ; 36f9d
-; leechseed
- ld a, [wAttackMissed]
- and a
- jr nz, .evaded
- call CheckSubstituteOpp
- jr nz, .evaded
-
- ld de, wEnemyMonType1
- ld a, [hBattleTurn]
- and a
- jr z, .ok
- ld de, wBattleMonType1
-.ok
-
- ld a, [de]
- cp GRASS
- jr z, .grass
- inc de
- ld a, [de]
- cp GRASS
- jr z, .grass
-
- ld a, BATTLE_VARS_SUBSTATUS4_OPP
- call GetBattleVarAddr
- bit SUBSTATUS_LEECH_SEED, [hl]
- jr nz, .evaded
- set SUBSTATUS_LEECH_SEED, [hl]
- call AnimateCurrentMove
- ld hl, WasSeededText
- jp StdBattleTextBox
-
-.grass
- call AnimateFailedMove
- jp PrintDoesntAffect
-
-.evaded
- call AnimateFailedMove
- ld hl, EvadedText
- jp StdBattleTextBox
-
-; 36fe1
-
-
-BattleCommand_Splash: ; 36fe1
- call AnimateCurrentMove
- farcall StubbedTrainerRankings_Splash
- jp PrintNothingHappened
-
-; 36fed
-
-
-BattleCommand_Disable: ; 36fed
-; disable
-
- ld a, [wAttackMissed]
- and a
- jr nz, .failed
-
- ld de, wEnemyDisableCount
- ld hl, wEnemyMonMoves
- ld a, [hBattleTurn]
- and a
- jr z, .got_moves
- ld de, wPlayerDisableCount
- ld hl, wBattleMonMoves
-.got_moves
-
- ld a, [de]
- and a
- jr nz, .failed
-
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- and a
- jr z, .failed
- cp STRUGGLE
- jr z, .failed
-
- ld b, a
- ld c, $ff
-.loop
- inc c
- ld a, [hli]
- cp b
- jr nz, .loop
-
- ld a, [hBattleTurn]
- and a
- ld hl, wEnemyMonPP
- jr z, .got_pp
- ld hl, wBattleMonPP
-.got_pp
- ld b, 0
- add hl, bc
- ld a, [hl]
- and a
- jr z, .failed
-.loop2
- call BattleRandom
- and 7
- jr z, .loop2
- inc a
- inc c
- swap c
- add c
- ld [de], a
- call AnimateCurrentMove
- ld hl, wDisabledMove
- ld a, [hBattleTurn]
- and a
- jr nz, .got_disabled_move_pointer
- inc hl
-.got_disabled_move_pointer
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- ld [hl], a
- ld [wNamedObjectIndexBuffer], a
- call GetMoveName
- ld hl, WasDisabledText
- jp StdBattleTextBox
-
-.failed
- jp FailDisable
-
-; 3705c
-
-
-BattleCommand_PayDay: ; 3705c
-; payday
-
- xor a
- ld hl, wStringBuffer1
- ld [hli], a
-
- ld a, [hBattleTurn]
- and a
- ld a, [wBattleMonLevel]
- jr z, .ok
- ld a, [wEnemyMonLevel]
-.ok
-
- add a
- ld hl, wPayDayMoney + 2
- add [hl]
- ld [hld], a
- jr nc, .done
- inc [hl]
- dec hl
- jr nz, .done
- inc [hl]
-.done
- ld hl, CoinsScatteredText
- jp StdBattleTextBox
-
-; 3707f
-
-
-BattleCommand_Conversion: ; 3707f
-; conversion
-
- ld hl, wBattleMonMoves
- ld de, wBattleMonType1
- ld a, [hBattleTurn]
- and a
- jr z, .got_moves
- ld hl, wEnemyMonMoves
- ld de, wEnemyMonType1
-.got_moves
- push de
- ld c, 0
- ld de, wStringBuffer1
-.loop
- push hl
- ld b, 0
- add hl, bc
- ld a, [hl]
- pop hl
- and a
- jr z, .okay
- push hl
- push bc
- dec a
- ld hl, Moves + MOVE_TYPE
- call GetMoveAttr
- ld [de], a
- inc de
- pop bc
- pop hl
- inc c
- ld a, c
- cp NUM_MOVES
- jr c, .loop
-.okay
- ld a, $ff
- ld [de], a
- inc de
- ld [de], a
- inc de
- ld [de], a
- pop de
- ld hl, wStringBuffer1
-.loop2
- ld a, [hl]
- cp -1
- jr z, .fail
- cp CURSE_T
- jr z, .next
- ld a, [de]
- cp [hl]
- jr z, .next
- inc de
- ld a, [de]
- dec de
- cp [hl]
- jr nz, .done
-.next
- inc hl
- jr .loop2
-
-.fail
- call AnimateFailedMove
- jp PrintButItFailed
-
-.done
-.loop3
- call BattleRandom
- maskbits NUM_MOVES
- ld c, a
- ld b, 0
- ld hl, wStringBuffer1
- add hl, bc
- ld a, [hl]
- cp -1
- jr z, .loop3
- cp CURSE_T
- jr z, .loop3
- ld a, [de]
- cp [hl]
- jr z, .loop3
- inc de
- ld a, [de]
- dec de
- cp [hl]
- jr z, .loop3
- ld a, [hl]
- ld [de], a
- inc de
- ld [de], a
- ld [wNamedObjectIndexBuffer], a
- farcall GetTypeName
- call AnimateCurrentMove
- ld hl, TransformedTypeText
- jp StdBattleTextBox
-
-; 3710e
-
-
-BattleCommand_ResetStats: ; 3710e
+BattleCommand_ResetStats:
; resetstats
ld a, 7 ; neutral
@@ -8268,10 +6136,7 @@ BattleCommand_ResetStats: ; 3710e
jr nz, .next
ret
-; 3713e
-
-
-BattleCommand_Heal: ; 3713e
+BattleCommand_Heal:
; heal
ld de, wBattleMonHP
@@ -8353,11 +6218,9 @@ BattleCommand_Heal: ; 3713e
ld hl, HPIsFullText
jp StdBattleTextBox
-; 371cd
+INCLUDE "engine/battle/move_effects/transform.asm"
-INCLUDE "engine/battle/effect_commands/transform.asm"
-
-BattleSideCopy: ; 372c6
+BattleSideCopy:
; Copy bc bytes from hl to de if it's the player's turn.
; Copy bc bytes from de to hl if it's the enemy's turn.
ld a, [hBattleTurn]
@@ -8372,17 +6235,11 @@ BattleSideCopy: ; 372c6
.copy
jp CopyBytes
-; 372d2
-
-
-BattleEffect_ButItFailed: ; 372d2
+BattleEffect_ButItFailed:
call AnimateFailedMove
jp PrintButItFailed
-; 372d8
-
-
-ClearLastMove: ; 372d8
+ClearLastMove:
ld a, BATTLE_VARS_LAST_COUNTER_MOVE
call GetBattleVarAddr
xor a
@@ -8394,10 +6251,7 @@ ClearLastMove: ; 372d8
ld [hl], a
ret
-; 372e7
-
-
-ResetActorDisable: ; 372e7
+ResetActorDisable:
ld a, [hBattleTurn]
and a
jr z, .player
@@ -8413,10 +6267,7 @@ ResetActorDisable: ; 372e7
ld [wDisabledMove], a
ret
-; 372fc
-
-
-BattleCommand_Screen: ; 372fc
+BattleCommand_Screen:
; screen
ld hl, wPlayerScreens
@@ -8461,133 +6312,66 @@ BattleCommand_Screen: ; 372fc
call AnimateFailedMove
jp PrintButItFailed
-; 3733d
-
-
-PrintDoesntAffect: ; 3733d
+PrintDoesntAffect:
; 'it doesn't affect'
ld hl, DoesntAffectText
jp StdBattleTextBox
-; 37343
-
-
-PrintNothingHappened: ; 37343
+PrintNothingHappened:
; 'but nothing happened!'
ld hl, NothingHappenedText
jp StdBattleTextBox
-; 37349
-
-
-TryPrintButItFailed: ; 37349
+TryPrintButItFailed:
ld a, [wAlreadyFailed]
and a
ret nz
; fallthrough
-; 3734e
-
-PrintButItFailed: ; 3734e
+PrintButItFailed:
; 'but it failed!'
ld hl, ButItFailedText
jp StdBattleTextBox
-; 37354
-
-
-FailSnore:
-FailDisable:
-FailConversion2:
-FailAttract:
-FailForesight:
-FailSpikes:
+FailMove:
call AnimateFailedMove
; fallthrough
-; 37357
-FailMimic: ; 37357
+FailMimic:
ld hl, ButItFailedText ; 'but it failed!'
ld de, ItFailedText ; 'it failed!'
jp FailText_CheckOpponentProtect
-; 37360
-
-
-PrintDidntAffect: ; 37360
+PrintDidntAffect:
; 'it didn't affect'
ld hl, DidntAffect1Text
jp StdBattleTextBox
-; 37366
-
-
-PrintDidntAffect2: ; 37366
+PrintDidntAffect2:
call AnimateFailedMove
ld hl, DidntAffect1Text ; 'it didn't affect'
ld de, DidntAffect2Text ; 'it didn't affect'
jp FailText_CheckOpponentProtect
-; 37372
-
-
-PrintParalyze: ; 37372
+PrintParalyze:
; 'paralyzed! maybe it can't attack!'
ld hl, ParalyzedText
jp StdBattleTextBox
-; 37378
-
-
-CheckSubstituteOpp: ; 37378
+CheckSubstituteOpp:
ld a, BATTLE_VARS_SUBSTATUS4_OPP
call GetBattleVar
bit SUBSTATUS_SUBSTITUTE, a
ret
-; 37380
-
-
-BattleCommand_Selfdestruct: ; 37380
- farcall StubbedTrainerRankings_Selfdestruct
- ld a, BATTLEANIM_PLAYER_DAMAGE
- ld [wNumHits], a
- ld c, 3
- call DelayFrames
- ld a, BATTLE_VARS_STATUS
- call GetBattleVarAddr
- xor a
- ld [hli], a
- inc hl
- ld [hli], a
- ld [hl], a
- ld a, $1
- ld [wKickCounter], a
- call BattleCommand_LowerSub
- call LoadMoveAnim
- ld a, BATTLE_VARS_SUBSTATUS4
- call GetBattleVarAddr
- res SUBSTATUS_LEECH_SEED, [hl]
- ld a, BATTLE_VARS_SUBSTATUS5_OPP
- call GetBattleVarAddr
- res SUBSTATUS_DESTINY_BOND, [hl]
- call _CheckBattleScene
- ret nc
- farcall DrawPlayerHUD
- farcall DrawEnemyHUD
- call WaitBGMap
- jp RefreshBattleHuds
-
-; 373c9
-
+INCLUDE "engine/battle/move_effects/selfdestruct.asm"
-INCLUDE "engine/battle/effect_commands/mirror_move.asm"
+INCLUDE "engine/battle/move_effects/mirror_move.asm"
-INCLUDE "engine/battle/effect_commands/metronome.asm"
+INCLUDE "engine/battle/move_effects/metronome.asm"
-
-CheckUserMove: ; 37462
+CheckUserMove:
; Return z if the user has move a.
ld b, a
ld de, wBattleMonMoves
@@ -8611,10 +6395,7 @@ CheckUserMove: ; 37462
and a
ret
-; 3747b
-
-
-ResetTurn: ; 3747b
+ResetTurn:
ld hl, wPlayerCharging
ld a, [hBattleTurn]
and a
@@ -8628,13 +6409,9 @@ ResetTurn: ; 3747b
call DoMove
jp EndMoveEffect
-; 37492
-
-
-INCLUDE "engine/battle/effect_commands/thief.asm"
+INCLUDE "engine/battle/move_effects/thief.asm"
-
-BattleCommand_ArenaTrap: ; 37517
+BattleCommand_ArenaTrap:
; arenatrap
; Doesn't work on an absent opponent.
@@ -8660,13 +6437,9 @@ BattleCommand_ArenaTrap: ; 37517
call AnimateFailedMove
jp PrintButItFailed
-; 37536
-
+INCLUDE "engine/battle/move_effects/nightmare.asm"
-INCLUDE "engine/battle/effect_commands/nightmare.asm"
-
-
-BattleCommand_Defrost: ; 37563
+BattleCommand_Defrost:
; defrost
; Thaw the user.
@@ -8697,188 +6470,39 @@ BattleCommand_Defrost: ; 37563
ld hl, WasDefrostedText
jp StdBattleTextBox
-; 37588
-
-
-INCLUDE "engine/battle/effect_commands/curse.asm"
+INCLUDE "engine/battle/move_effects/curse.asm"
-INCLUDE "engine/battle/effect_commands/protect.asm"
+INCLUDE "engine/battle/move_effects/protect.asm"
-INCLUDE "engine/battle/effect_commands/endure.asm"
+INCLUDE "engine/battle/move_effects/endure.asm"
-INCLUDE "engine/battle/effect_commands/spikes.asm"
+INCLUDE "engine/battle/move_effects/spikes.asm"
-INCLUDE "engine/battle/effect_commands/foresight.asm"
+INCLUDE "engine/battle/move_effects/foresight.asm"
-INCLUDE "engine/battle/effect_commands/perish_song.asm"
+INCLUDE "engine/battle/move_effects/perish_song.asm"
-INCLUDE "engine/battle/effect_commands/sandstorm.asm"
+INCLUDE "engine/battle/move_effects/sandstorm.asm"
-INCLUDE "engine/battle/effect_commands/rollout.asm"
+INCLUDE "engine/battle/move_effects/rollout.asm"
-
-BattleCommand5d: ; 37791
+BattleCommand5d:
; unused
ret
-; 37792
-
-
-BattleCommand_FuryCutter: ; 37792
-; furycutter
-
- ld hl, wPlayerFuryCutterCount
- ld a, [hBattleTurn]
- and a
- jr z, .go
- ld hl, wEnemyFuryCutterCount
-
-.go
- ld a, [wAttackMissed]
- and a
- jp nz, ResetFuryCutterCount
-
- inc [hl]
-
-; Damage capped at 5 turns' worth (16x).
- ld a, [hl]
- ld b, a
- cp 6
- jr c, .checkdouble
- ld b, 5
-
-.checkdouble
- dec b
- ret z
-
-; Double the damage
- ld hl, wCurDamage + 1
- sla [hl]
- dec hl
- rl [hl]
- jr nc, .checkdouble
-
-; No overflow
- ld a, $ff
- ld [hli], a
- ld [hl], a
- ret
-
-; 377be
-
-
-ResetFuryCutterCount: ; 377be
-
- push hl
-
- ld hl, wPlayerFuryCutterCount
- ld a, [hBattleTurn]
- and a
- jr z, .reset
- ld hl, wEnemyFuryCutterCount
-
-.reset
- xor a
- ld [hl], a
-
- pop hl
- ret
-
-; 377ce
-
-
-INCLUDE "engine/battle/effect_commands/attract.asm"
-
-BattleCommand_HappinessPower: ; 3784b
-; happinesspower
- push bc
- ld hl, wBattleMonHappiness
- ld a, [hBattleTurn]
- and a
- jr z, .ok
- ld hl, wEnemyMonHappiness
-.ok
- xor a
- ld [hMultiplicand + 0], a
- ld [hMultiplicand + 1], a
- ld a, [hl]
- ld [hMultiplicand + 2], a
- ld a, 10
- ld [hMultiplier], a
- call Multiply
- ld a, 25
- ld [hDivisor], a
- ld b, 4
- call Divide
- ld a, [hQuotient + 2]
- ld d, a
- pop bc
- ret
-
-; 37874
-
-
-INCLUDE "engine/battle/effect_commands/present.asm"
-
-BattleCommand_FrustrationPower: ; 3790e
-; frustrationpower
-
- push bc
- ld hl, wBattleMonHappiness
- ld a, [hBattleTurn]
- and a
- jr z, .got_happiness
- ld hl, wEnemyMonHappiness
-.got_happiness
- ld a, $ff
- sub [hl]
- ld [hMultiplicand + 2], a
- xor a
- ld [hMultiplicand + 0], a
- ld [hMultiplicand + 1], a
- ld a, 10
- ld [hMultiplier], a
- call Multiply
- ld a, 25
- ld [hDivisor], a
- ld b, 4
- call Divide
- ld a, [hQuotient + 2]
- ld d, a
- pop bc
- ret
-
-; 37939
-
+INCLUDE "engine/battle/move_effects/fury_cutter.asm"
-BattleCommand_Safeguard: ; 37939
-; safeguard
+INCLUDE "engine/battle/move_effects/attract.asm"
- ld hl, wPlayerScreens
- ld de, wPlayerSafeguardCount
- ld a, [hBattleTurn]
- and a
- jr z, .ok
- ld hl, wEnemyScreens
- ld de, wEnemySafeguardCount
-.ok
- bit SCREENS_SAFEGUARD, [hl]
- jr nz, .failed
- set SCREENS_SAFEGUARD, [hl]
- ld a, 5
- ld [de], a
- call AnimateCurrentMove
- ld hl, CoveredByVeilText
- jp StdBattleTextBox
+INCLUDE "engine/battle/move_effects/return.asm"
-.failed
- call AnimateFailedMove
- jp PrintButItFailed
+INCLUDE "engine/battle/move_effects/present.asm"
-; 37962
+INCLUDE "engine/battle/move_effects/frustration.asm"
+INCLUDE "engine/battle/move_effects/safeguard.asm"
-SafeCheckSafeguard: ; 37962
+SafeCheckSafeguard:
push hl
ld hl, wEnemyScreens
ld a, [hBattleTurn]
@@ -8891,10 +6515,7 @@ SafeCheckSafeguard: ; 37962
pop hl
ret
-; 37972
-
-
-BattleCommand_CheckSafeguard: ; 37972
+BattleCommand_CheckSafeguard:
; checksafeguard
ld hl, wEnemyScreens
ld a, [hBattleTurn]
@@ -8911,381 +6532,30 @@ BattleCommand_CheckSafeguard: ; 37972
call StdBattleTextBox
jp EndMoveEffect
-; 37991
-
-
-BattleCommand_GetMagnitude: ; 37991
-; getmagnitude
-
- push bc
- call BattleRandom
- ld b, a
- ld hl, .Magnitudes
-.loop
- ld a, [hli]
- cp b
- jr nc, .ok
- inc hl
- inc hl
- jr .loop
-
-.ok
- ld d, [hl]
- push de
- inc hl
- ld a, [hl]
- ld [wTypeMatchup], a
- call BattleCommand_MoveDelay
- ld hl, MagnitudeText
- call StdBattleTextBox
- pop de
- pop bc
- ret
-
-.Magnitudes:
- ; /255, BP, magnitude
- db 13, 10, 4
- db 38, 30, 5
- db 89, 50, 6
- db 166, 70, 7
- db 217, 90, 8
- db 242, 110, 9
- db 255, 150, 10
-; 379c9
-
-
-BattleCommand_BatonPass: ; 379c9
-; batonpass
-
- ld a, [hBattleTurn]
- and a
- jp nz, .Enemy
-
-
-; Need something to switch to
- call CheckAnyOtherAlivePartyMons
- jp z, FailedBatonPass
-
- call UpdateBattleMonInParty
- call AnimateCurrentMove
-
- ld c, 50
- call DelayFrames
-
-; Transition into switchmon menu
- call LoadStandardMenuDataHeader
- farcall SetUpBattlePartyMenu_NoLoop
-
- farcall ForcePickSwitchMonInBattle
-
-; Return to battle scene
- call ClearPalettes
- farcall _LoadBattleFontsHPBar
- call CloseWindow
- call ClearSprites
- hlcoord 1, 0
- lb bc, 4, 10
- call ClearBox
- ld b, SCGB_BATTLE_COLORS
- call GetSGBLayout
- call SetPalettes
- call BatonPass_LinkPlayerSwitch
-
-; Mobile link battles handle entrances differently
- farcall CheckMobileBattleError
- jp c, EndMoveEffect
-
- ld hl, PassedBattleMonEntrance
- call CallBattleCore
-
- call ResetBatonPassStatus
- ret
-
-
-.Enemy:
-
-; Wildmons don't have anything to switch to
- ld a, [wBattleMode]
- dec a ; WILDMON
- jp z, FailedBatonPass
-
- call CheckAnyOtherAliveEnemyMons
- jp z, FailedBatonPass
-
- call UpdateEnemyMonInParty
- call AnimateCurrentMove
- call BatonPass_LinkEnemySwitch
-
-; Mobile link battles handle entrances differently
- farcall CheckMobileBattleError
- jp c, EndMoveEffect
-
-; Passed enemy PartyMon entrance
- xor a
- ld [wEnemySwitchMonIndex], a
- ld hl, EnemySwitch_SetMode
- call CallBattleCore
- ld hl, ResetBattleParticipants
- call CallBattleCore
- ld a, 1
- ld [wTypeMatchup], a
- ld hl, ApplyStatLevelMultiplierOnAllStats
- call CallBattleCore
-
- ld hl, SpikesDamage
- call CallBattleCore
-
- jr ResetBatonPassStatus
-
-; 37a67
-
-
-BatonPass_LinkPlayerSwitch: ; 37a67
- ld a, [wLinkMode]
- and a
- ret z
-
- ld a, 1
- ld [wBattlePlayerAction], a
-
- call LoadStandardMenuDataHeader
- ld hl, LinkBattleSendReceiveAction
- call CallBattleCore
- call CloseWindow
-
- xor a
- ld [wBattlePlayerAction], a
- ret
-
-; 37a82
-
-
-BatonPass_LinkEnemySwitch: ; 37a82
- ld a, [wLinkMode]
- and a
- ret z
-
- call LoadStandardMenuDataHeader
- ld hl, LinkBattleSendReceiveAction
- call CallBattleCore
-
- ld a, [wOTPartyCount]
- add BATTLEACTION_SWITCH1
- ld b, a
- ld a, [wBattleAction]
- cp BATTLEACTION_SWITCH1
- jr c, .baton_pass
- cp b
- jr c, .switch
-
-.baton_pass
- ld a, [wCurOTMon]
- add BATTLEACTION_SWITCH1
- ld [wBattleAction], a
-.switch
- jp CloseWindow
-
-; 37aab
-
-
-FailedBatonPass: ; 37aab
- call AnimateFailedMove
- jp PrintButItFailed
-
-; 37ab1
-
-
-ResetBatonPassStatus: ; 37ab1
-; Reset status changes that aren't passed by Baton Pass.
-
- ; Nightmare isn't passed.
- ld a, BATTLE_VARS_STATUS
- call GetBattleVar
- and SLP
- jr nz, .ok
-
- ld a, BATTLE_VARS_SUBSTATUS1
- call GetBattleVarAddr
- res SUBSTATUS_NIGHTMARE, [hl]
-.ok
-
- ; Disable isn't passed.
- call ResetActorDisable
-
- ; Attraction isn't passed.
- ld hl, wPlayerSubStatus1
- res SUBSTATUS_IN_LOVE, [hl]
- ld hl, wEnemySubStatus1
- res SUBSTATUS_IN_LOVE, [hl]
- ld hl, wPlayerSubStatus5
-
- ld a, BATTLE_VARS_SUBSTATUS5
- call GetBattleVarAddr
- res SUBSTATUS_TRANSFORMED, [hl]
- res SUBSTATUS_ENCORED, [hl]
-
- ; New mon hasn't used a move yet.
- ld a, BATTLE_VARS_LAST_MOVE
- call GetBattleVarAddr
- ld [hl], 0
-
- xor a
- ld [wPlayerWrapCount], a
- ld [wEnemyWrapCount], a
- ret
-
-; 37ae9
+INCLUDE "engine/battle/move_effects/magnitude.asm"
+INCLUDE "engine/battle/move_effects/baton_pass.asm"
-CheckAnyOtherAlivePartyMons: ; 37ae9
- ld hl, wPartyMon1HP
- ld a, [wPartyCount]
- ld d, a
- ld a, [wCurBattleMon]
- ld e, a
- jr CheckAnyOtherAliveMons
+INCLUDE "engine/battle/move_effects/pursuit.asm"
-; 37af6
-
-
-CheckAnyOtherAliveEnemyMons: ; 37af6
- ld hl, wOTPartyMon1HP
- ld a, [wOTPartyCount]
- ld d, a
- ld a, [wCurOTMon]
- ld e, a
-
- ; fallthrough
-; 37b01
-
-CheckAnyOtherAliveMons: ; 37b01
-; Check for nonzero HP starting from partymon
-; HP at hl for d partymons, besides current mon e.
-
-; Return nz if any are alive.
-
- xor a
- ld b, a
- ld c, a
-.loop
- ld a, c
- cp d
- jr z, .done
- cp e
- jr z, .next
+INCLUDE "engine/battle/move_effects/rapid_spin.asm"
- ld a, [hli]
- or b
- ld b, a
- ld a, [hld]
- or b
- ld b, a
-
-.next
- push bc
- ld bc, PARTYMON_STRUCT_LENGTH
- add hl, bc
- pop bc
- inc c
- jr .loop
-
-.done
- ld a, b
- and a
- ret
-
-; 37b1d
-
-
-BattleCommand_Pursuit: ; 37b1d
-; pursuit
-; Double damage if the opponent is switching.
-
- ld hl, wEnemyIsSwitching
- ld a, [hBattleTurn]
- and a
- jr z, .ok
- ld hl, wPlayerIsSwitching
-.ok
- ld a, [hl]
- and a
- ret z
-
- ld hl, wCurDamage + 1
- sla [hl]
- dec hl
- rl [hl]
- ret nc
-
- ld a, $ff
- ld [hli], a
- ld [hl], a
- ret
-
-; 37b39
-
-
-BattleCommand_ClearHazards: ; 37b39
-; clearhazards
-
- ld a, BATTLE_VARS_SUBSTATUS4
- call GetBattleVarAddr
- bit SUBSTATUS_LEECH_SEED, [hl]
- jr z, .not_leeched
- res SUBSTATUS_LEECH_SEED, [hl]
- ld hl, ShedLeechSeedText
- call StdBattleTextBox
-.not_leeched
-
- ld hl, wPlayerScreens
- ld de, wPlayerWrapCount
- ld a, [hBattleTurn]
- and a
- jr z, .got_screens_wrap
- ld hl, wEnemyScreens
- ld de, wEnemyWrapCount
-.got_screens_wrap
- bit SCREENS_SPIKES, [hl]
- jr z, .no_spikes
- res SCREENS_SPIKES, [hl]
- ld hl, BlewSpikesText
- push de
- call StdBattleTextBox
- pop de
-.no_spikes
-
- ld a, [de]
- and a
- ret z
- xor a
- ld [de], a
- ld hl, ReleasedByText
- jp StdBattleTextBox
-
-; 37b74
-
-
-BattleCommand_HealMorn: ; 37b74
+BattleCommand_HealMorn:
; healmorn
ld b, MORN_F
jr BattleCommand_TimeBasedHealContinue
-; 37b78
-
-BattleCommand_HealDay: ; 37b78
+BattleCommand_HealDay:
; healday
ld b, DAY_F
jr BattleCommand_TimeBasedHealContinue
-; 37b7c
-
-BattleCommand_HealNite: ; 37b7c
+BattleCommand_HealNite:
; healnite
ld b, NITE_F
; fallthrough
-; 37b7e
-BattleCommand_TimeBasedHealContinue: ; 37b7e
+BattleCommand_TimeBasedHealContinue:
; Time- and weather-sensitive heal.
ld hl, wBattleMonMaxHP
@@ -9310,14 +6580,14 @@ BattleCommand_TimeBasedHealContinue: ; 37b7e
; Don't factor in time of day in link battles.
ld a, [wLinkMode]
and a
- jr nz, .checkWeather
+ jr nz, .Weather
ld a, [wTimeOfDay]
cp b
- jr z, .checkWeather
+ jr z, .Weather
dec c ; double
-.checkWeather:
+.Weather:
ld a, [wBattleWeather]
and a
jr z, .Heal
@@ -9366,202 +6636,20 @@ BattleCommand_TimeBasedHealContinue: ; 37b7e
dw GetQuarterMaxHP
dw GetHalfMaxHP
dw GetMaxHP
-; 37be8
-
-
-BattleCommand_HiddenPower: ; 37be8
-; hiddenpower
-
- ld a, [wAttackMissed]
- and a
- ret nz
- farcall HiddenPowerDamage
- ret
-
-; 37bf4
-
-
-BattleCommand_StartRain: ; 37bf4
-; startrain
- ld a, WEATHER_RAIN
- ld [wBattleWeather], a
- ld a, 5
- ld [wWeatherCount], a
- call AnimateCurrentMove
- ld hl, DownpourText
- jp StdBattleTextBox
-
-; 37c07
-
-
-BattleCommand_StartSun: ; 37c07
-; startsun
- ld a, WEATHER_SUN
- ld [wBattleWeather], a
- ld a, 5
- ld [wWeatherCount], a
- call AnimateCurrentMove
- ld hl, SunGotBrightText
- jp StdBattleTextBox
-
-; 37c1a
-
-
-BattleCommand_BellyDrum: ; 37c1a
-; bellydrum
-; This command is buggy because it raises the user's attack
-; before checking that it has enough HP to use the move.
-; Swap the order of these two blocks to fix.
- call BattleCommand_AttackUp2
- ld a, [wAttackMissed]
- and a
- jr nz, .failed
-
- callfar GetHalfMaxHP
- callfar CheckUserHasEnoughHP
- jr nc, .failed
-
- push bc
- call AnimateCurrentMove
- pop bc
- callfar SubtractHPFromUser
- call UpdateUserInParty
- ld a, 5
-
-.max_attack_loop
- push af
- call BattleCommand_AttackUp2
- pop af
- dec a
- jr nz, .max_attack_loop
- ld hl, BellyDrumText
- jp StdBattleTextBox
-
-.failed
- call AnimateFailedMove
- jp PrintButItFailed
+INCLUDE "engine/battle/move_effects/hidden_power.asm"
-; 37c55
+INCLUDE "engine/battle/move_effects/rain_dance.asm"
+INCLUDE "engine/battle/move_effects/sunny_day.asm"
-BattleCommand_PsychUp: ; 37c55
-; psychup
+INCLUDE "engine/battle/move_effects/belly_drum.asm"
- ld hl, wEnemyStatLevels
- ld de, wPlayerStatLevels
- ld a, [hBattleTurn]
- and a
- jr z, .pointers_correct
-; It's the enemy's turn, so swap the pointers.
- push hl
- ld h, d
- ld l, e
- pop de
-.pointers_correct
- push hl
- ld b, NUM_LEVEL_STATS
-; If any of the enemy's stats is modified from its base level,
-; the move succeeds. Otherwise, it fails.
-.loop
- ld a, [hli]
- cp BASE_STAT_LEVEL
- jr nz, .break
- dec b
- jr nz, .loop
- pop hl
- call AnimateFailedMove
- jp PrintButItFailed
-
-.break
- pop hl
- ld b, NUM_LEVEL_STATS
-.loop2
- ld a, [hli]
- ld [de], a
- inc de
- dec b
- jr nz, .loop2
- ld a, [hBattleTurn]
- and a
- jr nz, .calc_enemy_stats
- call CalcPlayerStats
- jr .merge
-
-.calc_enemy_stats
- call CalcEnemyStats
-.merge
- call AnimateCurrentMove
- ld hl, CopiedStatsText
- jp StdBattleTextBox
+INCLUDE "engine/battle/move_effects/psych_up.asm"
-; 37c95
+INCLUDE "engine/battle/move_effects/mirror_coat.asm"
-
-BattleCommand_MirrorCoat: ; 37c95
-; mirrorcoat
-
- ld a, 1
- ld [wAttackMissed], a
-
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- and a
- ret z
-
- ld b, a
- callfar GetMoveEffect
- ld a, b
- cp EFFECT_MIRROR_COAT
- ret z
-
- call BattleCommand_ResetTypeMatchup
- ld a, [wTypeMatchup]
- and a
- ret z
-
- call CheckOpponentWentFirst
- ret z
-
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
- call GetBattleVar
- dec a
- ld de, wStringBuffer1
- call GetMoveData
-
- ld a, [wStringBuffer1 + 2]
- and a
- ret z
-
- ld a, [wStringBuffer1 + 3]
- cp SPECIAL
- ret c
-
- ld hl, wCurDamage
- ld a, [hli]
- or [hl]
- ret z
-
- ld a, [hl]
- add a
- ld [hld], a
- ld a, [hl]
- adc a
- ld [hl], a
- jr nc, .capped
- ld a, $ff
- ld [hli], a
- ld [hl], a
-.capped
-
- xor a
- ld [wAttackMissed], a
- ret
-
-; 37ce6
-
-
-BattleCommand_DoubleMinimizeDamage: ; 37ce6
+BattleCommand_DoubleMinimizeDamage:
; doubleminimizedamage
ld hl, wEnemyMinimized
@@ -9583,10 +6671,7 @@ BattleCommand_DoubleMinimizeDamage: ; 37ce6
ld [hl], a
ret
-; 37d02
-
-
-BattleCommand_SkipSunCharge: ; 37d02
+BattleCommand_SkipSunCharge:
; mimicsuncharge
ld a, [wBattleWeather]
cp WEATHER_SUN
@@ -9594,129 +6679,18 @@ BattleCommand_SkipSunCharge: ; 37d02
ld b, charge_command
jp SkipToBattleCommand
-; 37d0d
+INCLUDE "engine/battle/move_effects/future_sight.asm"
+INCLUDE "engine/battle/move_effects/thunder.asm"
-BattleCommand_CheckFutureSight: ; 37d0d
-; checkfuturesight
-
- ld hl, wPlayerFutureSightCount
- ld de, wPlayerFutureSightDamage
- ld a, [hBattleTurn]
- and a
- jr z, .ok
- ld hl, wEnemyFutureSightCount
- ld de, wEnemyFutureSightDamage
-.ok
-
- ld a, [hl]
- and a
- ret z
- cp 1
- ret nz
-
- ld [hl], 0
- ld a, [de]
- inc de
- ld [wCurDamage], a
- ld a, [de]
- ld [wCurDamage + 1], a
- ld b, futuresight_command
- jp SkipToBattleCommand
-
-; 37d34
-
-BattleCommand_FutureSight: ; 37d34
-; futuresight
-
- call CheckUserIsCharging
- jr nz, .AlreadyChargingFutureSight
- ld a, BATTLE_VARS_MOVE_ANIM
- call GetBattleVar
- ld b, a
- ld a, BATTLE_VARS_LAST_COUNTER_MOVE
- call GetBattleVarAddr
- ld [hl], b
- ld a, BATTLE_VARS_LAST_MOVE
- call GetBattleVarAddr
- ld [hl], b
-.AlreadyChargingFutureSight:
- ld hl, wPlayerFutureSightCount
- ld a, [hBattleTurn]
- and a
- jr z, .GotFutureSightCount
- ld hl, wEnemyFutureSightCount
-.GotFutureSightCount:
- ld a, [hl]
- and a
- jr nz, .failed
- ld a, 4
- ld [hl], a
- call BattleCommand_LowerSub
- call BattleCommand_MoveDelay
- ld hl, ForesawAttackText
- call StdBattleTextBox
- call BattleCommand_RaiseSub
- ld de, wPlayerFutureSightDamage
- ld a, [hBattleTurn]
- and a
- jr z, .StoreDamage
- ld de, wEnemyFutureSightDamage
-.StoreDamage:
- ld hl, wCurDamage
- ld a, [hl]
- ld [de], a
- ld [hl], 0
- inc hl
- inc de
- ld a, [hl]
- ld [de], a
- ld [hl], 0
- jp EndMoveEffect
-
-.failed
- pop bc
- call ResetDamage
- call AnimateFailedMove
- call PrintButItFailed
- jp EndMoveEffect
-
-; 37d94
-
-
-BattleCommand_ThunderAccuracy: ; 37d94
-; thunderaccuracy
-
- ld a, BATTLE_VARS_MOVE_TYPE
- call GetBattleVarAddr
- inc hl
- ld a, [wBattleWeather]
- cp WEATHER_RAIN
- jr z, .rain
- cp WEATHER_SUN
- ret nz
- ld [hl], 50 percent + 1
- ret
-
-.rain
- ; Redundant with CheckHit guranteeing hit
- ld [hl], 100 percent
- ret
-
-; 37daa
-
-
-CheckHiddenOpponent: ; 37daa
+CheckHiddenOpponent:
; BUG: This routine should account for Lock-On and Mind Reader.
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVar
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
ret
-; 37db2
-
-
-GetUserItem: ; 37db2
+GetUserItem:
; Return the effect of the user's item in bc, and its id at hl.
ld hl, wBattleMonItem
ld a, [hBattleTurn]
@@ -9727,10 +6701,7 @@ GetUserItem: ; 37db2
ld b, [hl]
jp GetItemHeldEffect
-; 37dc1
-
-
-GetOpponentItem: ; 37dc1
+GetOpponentItem:
; Return the effect of the opponent's item in bc, and its id at hl.
ld hl, wEnemyMonItem
ld a, [hBattleTurn]
@@ -9741,10 +6712,7 @@ GetOpponentItem: ; 37dc1
ld b, [hl]
jp GetItemHeldEffect
-; 37dd0
-
-
-GetItemHeldEffect: ; 37dd0
+GetItemHeldEffect:
; Return the effect of item b in bc.
ld a, b
and a
@@ -9764,10 +6732,7 @@ GetItemHeldEffect: ; 37dd0
pop hl
ret
-; 37de9
-
-
-AnimateCurrentMoveEitherSide: ; 37de9
+AnimateCurrentMoveEitherSide:
push hl
push de
push bc
@@ -9783,10 +6748,7 @@ AnimateCurrentMoveEitherSide: ; 37de9
pop hl
ret
-; 37e01
-
-
-AnimateCurrentMove: ; 37e01
+AnimateCurrentMove:
push hl
push de
push bc
@@ -9802,10 +6764,7 @@ AnimateCurrentMove: ; 37e01
pop hl
ret
-; 37e19
-
-
-PlayDamageAnim: ; 37e19
+PlayDamageAnim:
xor a
ld [wFXAnimID + 1], a
@@ -9827,10 +6786,7 @@ PlayDamageAnim: ; 37e19
jp PlayUserBattleAnim
-; 37e36
-
-
-LoadMoveAnim: ; 37e36
+LoadMoveAnim:
xor a
ld [wNumHits], a
ld [wFXAnimID + 1], a
@@ -9841,18 +6797,13 @@ LoadMoveAnim: ; 37e36
ret z
; fallthrough
-; 37e44
-
-
-LoadAnim: ; 37e44
+LoadAnim:
ld [wFXAnimID], a
; fallthrough
-; 37e47
-
-PlayUserBattleAnim: ; 37e47
+PlayUserBattleAnim:
push hl
push de
push bc
@@ -9862,10 +6813,7 @@ PlayUserBattleAnim: ; 37e47
pop hl
ret
-; 37e54
-
-
-PlayOpponentBattleAnim: ; 37e54
+PlayOpponentBattleAnim:
ld a, e
ld [wFXAnimID], a
ld a, d
@@ -9886,35 +6834,23 @@ PlayOpponentBattleAnim: ; 37e54
pop hl
ret
-; 37e73
-
-
-CallBattleCore: ; 37e73
- ld a, BANK(BattleCore)
+CallBattleCore:
+ ld a, BANK("Battle Core")
rst FarCall
ret
-; 37e77
-
-
-AnimateFailedMove: ; 37e77
+AnimateFailedMove:
call BattleCommand_LowerSub
call BattleCommand_MoveDelay
jp BattleCommand_RaiseSub
-; 37e80
-
-
-BattleCommand_MoveDelay: ; 37e80
+BattleCommand_MoveDelay:
; movedelay
; Wait 40 frames.
ld c, 40
jp DelayFrames
-; 37e85
-
-
-BattleCommand_ClearText: ; 37e85
+BattleCommand_ClearText:
; cleartext
; Used in multi-hit moves.
@@ -9923,10 +6859,8 @@ BattleCommand_ClearText: ; 37e85
.text
db "@"
-; 37e8c
-
-SkipToBattleCommand: ; 37e8c
+SkipToBattleCommand:
; Skip over commands until reaching command b.
ld a, [wBattleScriptBufferAddress + 1]
ld h, a
@@ -9943,10 +6877,7 @@ SkipToBattleCommand: ; 37e8c
ld [wBattleScriptBufferAddress], a
ret
-; 37ea1
-
-
-GetMoveAttr: ; 37ea1
+GetMoveAttr:
; Assuming hl = Moves + x, return attribute x of move a.
push bc
ld bc, MOVE_LENGTH
@@ -9955,49 +6886,31 @@ GetMoveAttr: ; 37ea1
pop bc
ret
-; 37ead
-
-
-GetMoveData: ; 37ead
+GetMoveData:
; Copy move struct a to de.
ld hl, Moves
ld bc, MOVE_LENGTH
call AddNTimes
- ld a, Bank(Moves)
+ ld a, BANK(Moves)
jp FarCopyBytes
-; 37ebb
-
-
-GetMoveByte: ; 37ebb
+GetMoveByte:
ld a, BANK(Moves)
jp GetFarByte
-; 37ec0
-
-
-DisappearUser: ; 37ec0
+DisappearUser:
farcall _DisappearUser
ret
-; 37ec7
-
-
-AppearUserLowerSub: ; 37ec7
+AppearUserLowerSub:
farcall _AppearUserLowerSub
ret
-; 37ece
-
-
-AppearUserRaiseSub: ; 37ece
+AppearUserRaiseSub:
farcall _AppearUserRaiseSub
ret
-; 37ed5
-
-
-_CheckBattleScene: ; 37ed5
+_CheckBattleScene:
; Checks the options. Returns carry if battle animations are disabled.
push hl
push de
@@ -10007,5 +6920,3 @@ _CheckBattleScene: ; 37ed5
pop de
pop hl
ret
-
-; 37ee2
diff --git a/engine/battle/hidden_power.asm b/engine/battle/hidden_power.asm
index 9d9a8dc0e..537fe4354 100644
--- a/engine/battle/hidden_power.asm
+++ b/engine/battle/hidden_power.asm
@@ -1,4 +1,4 @@
-HiddenPowerDamage: ; fbced
+HiddenPowerDamage:
; Override Hidden Power's type and power based on the user's DVs.
ld hl, wBattleMonDVs
@@ -8,7 +8,6 @@ HiddenPowerDamage: ; fbced
ld hl, wEnemyMonDVs
.got_dvs
-
; Power:
; Take the top bit from each stat
@@ -62,7 +61,6 @@ HiddenPowerDamage: ; fbced
ld d, a
-
; Type:
; Def & 3
@@ -108,4 +106,3 @@ HiddenPowerDamage: ; fbced
pop af
ld d, a
ret
-; fbd54
diff --git a/engine/battle/link_result.asm b/engine/battle/link_result.asm
index 8f456da9b..0dd339fe4 100755..100644
--- a/engine/battle/link_result.asm
+++ b/engine/battle/link_result.asm
@@ -1,4 +1,4 @@
-DetermineLinkBattleResult: ; 2b930
+DetermineLinkBattleResult:
farcall UpdateEnemyMonInParty
ld hl, wPartyMon1HP
call .CountMonsRemaining
@@ -41,24 +41,24 @@ DetermineLinkBattleResult: ; 2b930
.victory
ld a, [wBattleResult]
and $f0
- ld [wBattleResult], a
+ ld [wBattleResult], a ; WIN
ret
.defeat
ld a, [wBattleResult]
and $f0
- add $1
+ add LOSE
ld [wBattleResult], a
ret
.drawn
ld a, [wBattleResult]
and $f0
- add $2
+ add DRAW
ld [wBattleResult], a
ret
-.CountMonsRemaining: ; 2b995
+.CountMonsRemaining:
ld c, 0
ld b, 3
ld de, PARTYMON_STRUCT_LENGTH - 1
@@ -74,7 +74,7 @@ DetermineLinkBattleResult: ; 2b930
jr nz, .loop
ret
-.CalcPercentHPRemaining: ; 2b9a6
+.CalcPercentHPRemaining:
ld de, 0
ld c, $3
.loop2
@@ -117,26 +117,26 @@ DetermineLinkBattleResult: ; 2b930
jr nz, .loop2
ret
-.BothSides_CheckNumberMonsAtFullHealth: ; 2b9e1
+.BothSides_CheckNumberMonsAtFullHealth:
ld hl, wPartyMon1HP
call .CheckFaintedOrFullHealth
jr nz, .finish ; we have a pokemon that's neither fainted nor at full health
ld hl, wOTPartyMon1HP
call .CheckFaintedOrFullHealth
- ld e, $1
+ ld e, $1 ; victory
ret
.finish
ld hl, wOTPartyMon1HP
call .CheckFaintedOrFullHealth
- ld e, $0
+ ld e, $0 ; drawn
ret nz ; we both have pokemon that are neither fainted nor at full health
- ld e, $2
- ld a, $1
+ ld e, $2 ; defeat
+ ld a, $1 ; not drawn
and a
ret
-.CheckFaintedOrFullHealth: ; 2ba01
+.CheckFaintedOrFullHealth:
ld d, 3
.loop3
ld a, [hli]
diff --git a/engine/battle/menu.asm b/engine/battle/menu.asm
index c97cd7854..147430030 100755..100644
--- a/engine/battle/menu.asm
+++ b/engine/battle/menu.asm
@@ -1,6 +1,6 @@
-LoadBattleMenu: ; 24ef2
- ld hl, BattleMenuDataHeader
- call LoadMenuDataHeader
+LoadBattleMenu:
+ ld hl, BattleMenuHeader
+ call LoadMenuHeader
ld a, [wBattleMenuCursorBuffer]
ld [wMenuCursorBuffer], a
call InterpretBattleMenu
@@ -8,21 +8,18 @@ LoadBattleMenu: ; 24ef2
ld [wBattleMenuCursorBuffer], a
call ExitMenu
ret
-; 24f0b
-SafariBattleMenu: ; 24f0b
+SafariBattleMenu:
; untranslated
- ld hl, MenuDataHeader_0x24f4e
- call LoadMenuDataHeader
+ ld hl, MenuHeader_0x24f4e
+ call LoadMenuHeader
jr Function24f19
-; 24f13
-ContestBattleMenu: ; 24f13
- ld hl, MenuDataHeader_0x24f89
- call LoadMenuDataHeader
-; 24f19
+ContestBattleMenu:
+ ld hl, MenuHeader_0x24f89
+ call LoadMenuHeader
-Function24f19: ; 24f19
+Function24f19:
ld a, [wBattleMenuCursorBuffer]
ld [wMenuCursorBuffer], a
call _2DMenu
@@ -30,86 +27,74 @@ Function24f19: ; 24f19
ld [wBattleMenuCursorBuffer], a
call ExitMenu
ret
-; 24f2c
-BattleMenuDataHeader: ; 24f2c
+BattleMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 8, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw MenuData_0x24f34
db 1 ; default option
-; 24f34
-MenuData_0x24f34: ; 0x24f34
+MenuData_0x24f34:
db STATICMENU_CURSOR | STATICMENU_DISABLE_B ; flags
dn 2, 2 ; rows, columns
db 6 ; spacing
dba Strings24f3d
dbw BANK(MenuData_0x24f34), 0
-; 0x24f3d
-Strings24f3d: ; 0x24f3d
+Strings24f3d:
db "FIGHT@"
db "<PKMN>@"
db "PACK@"
db "RUN@"
-; 24f4e
-MenuDataHeader_0x24f4e: ; 24f4e
+MenuHeader_0x24f4e:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw MenuData_0x24f56
db 1 ; default option
-; 24f56
-MenuData_0x24f56: ; 24f56
+MenuData_0x24f56:
db STATICMENU_CURSOR | STATICMENU_DISABLE_B ; flags
dn 2, 2 ; rows, columns
db 11 ; spacing
dba Strings24f5f
dba Function24f7c
-; 24f5f
-Strings24f5f: ; 24f5f
+Strings24f5f:
db "サファりボール×  @" ; "SAFARI BALL× @"
db "エサをなげる@" ; "THROW BAIT"
db "いしをなげる@" ; "THROW ROCK"
db "にげる@" ; "RUN"
-; 24f7c
-Function24f7c: ; 24f7c
+Function24f7c:
hlcoord 17, 13
ld de, wSafariBallsRemaining
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
ret
-; 24f89
-MenuDataHeader_0x24f89: ; 24f89
+MenuHeader_0x24f89:
db MENU_BACKUP_TILES ; flags
menu_coords 2, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw MenuData_0x24f91
db 1 ; default option
-; 24f91
-MenuData_0x24f91: ; 24f91
+MenuData_0x24f91:
db STATICMENU_CURSOR | STATICMENU_DISABLE_B ; flags
dn 2, 2 ; rows, columns
db 12 ; spacing
dba Strings24f9a
dba Function24fb2
-; 24f9a
-Strings24f9a: ; 24f9a
+Strings24f9a:
db "FIGHT@"
db "<PKMN>", "@"
db "PARKBALL× @"
db "RUN@"
-; 24fb2
-Function24fb2: ; 24fb2
+Function24fb2:
hlcoord 13, 16
ld de, wParkBallsRemaining
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
ret
-; 24fbf
diff --git a/engine/battle/misc.asm b/engine/battle/misc.asm
index b79c274b9..48062f643 100644
--- a/engine/battle/misc.asm
+++ b/engine/battle/misc.asm
@@ -1,4 +1,4 @@
-_DisappearUser: ; fbd54
+_DisappearUser:
xor a
ld [hBGMapMode], a
ld a, [hBattleTurn]
@@ -12,14 +12,14 @@ _DisappearUser: ; fbd54
call ClearBox
jr FinishAppearDisappearUser
-_AppearUserRaiseSub: ; fbd69 (3e:7d69)
+_AppearUserRaiseSub:
farcall BattleCommand_RaiseSubNoAnim
jr AppearUser
-_AppearUserLowerSub: ; fbd71 (3e:7d71)
+_AppearUserLowerSub:
farcall BattleCommand_LowerSubNoAnim
-AppearUser: ; fbd77 (3e:7d77)
+AppearUser:
xor a
ld [hBGMapMode], a
ld a, [hBattleTurn]
@@ -34,25 +34,23 @@ AppearUser: ; fbd77 (3e:7d77)
.okay
ld [hGraphicStartTile], a
predef PlaceGraphic
-FinishAppearDisappearUser: ; fbd91 (3e:7d91)
+FinishAppearDisappearUser:
ld a, $1
ld [hBGMapMode], a
ret
-GetEnemyFrontpicCoords: ; fbd96 (3e:7d96)
+GetEnemyFrontpicCoords:
hlcoord 12, 0
lb bc, 7, 7
ret
-GetPlayerBackpicCoords: ; fbd9d (3e:7d9d)
+GetPlayerBackpicCoords:
hlcoord 2, 6
lb bc, 6, 6
ret
-
-DoWeatherModifiers: ; fbda4
-
- ld de, .WeatherTypeModifiers
+DoWeatherModifiers:
+ ld de, WeatherTypeModifiers
ld a, [wBattleWeather]
ld b, a
ld a, [wd265] ; move type
@@ -76,9 +74,8 @@ DoWeatherModifiers: ; fbda4
inc de
jr .CheckWeatherType
-
.done_weather_types
- ld de, .WeatherMoveModifiers
+ ld de, WeatherMoveModifiers
ld a, BATTLE_VARS_MOVE_EFFECT
call GetBattleVar
@@ -145,20 +142,9 @@ DoWeatherModifiers: ; fbda4
.done
ret
-.WeatherTypeModifiers:
- db WEATHER_RAIN, WATER, MORE_EFFECTIVE
- db WEATHER_RAIN, FIRE, NOT_VERY_EFFECTIVE
- db WEATHER_SUN, FIRE, MORE_EFFECTIVE
- db WEATHER_SUN, WATER, NOT_VERY_EFFECTIVE
- db -1 ; end
-
-.WeatherMoveModifiers:
- db WEATHER_RAIN, EFFECT_SOLARBEAM, NOT_VERY_EFFECTIVE
- db -1 ; end
-; fbe24
-
+INCLUDE "data/battle/weather_modifiers.asm"
-DoBadgeTypeBoosts: ; fbe24
+DoBadgeTypeBoosts:
ld a, [wLinkMode]
and a
ret nz
@@ -174,7 +160,7 @@ DoBadgeTypeBoosts: ; fbe24
push de
push bc
- ld hl, .BadgeTypes
+ ld hl, BadgeTypeBoosts
ld a, [wKantoBadges]
ld b, a
@@ -235,25 +221,4 @@ DoBadgeTypeBoosts: ; fbe24
pop de
ret
-.BadgeTypes:
-; entries correspond to wJohtoBadges constants
- db FLYING ; ZEPHYRBADGE
- db BUG ; HIVEBADGE
- db NORMAL ; PLAINBADGE
- db GHOST ; FOGBADGE
- db STEEL ; MINERALBADGE
- db FIGHTING ; STORMBADGE
- db ICE ; GLACIERBADGE
- db DRAGON ; RISINGBADGE
- ; fallthrough
-; entries correspond to wKantoBadges constants
- db ROCK ; BOULDERBADGE
- db WATER ; CASCADEBADGE
- db ELECTRIC ; THUNDERBADGE
- db GRASS ; RAINBOWBADGE
- db POISON ; SOULBADGE
- db PSYCHIC ; MARSHBADGE
- db FIRE ; VOLCANOBADGE
- db GROUND ; EARTHBADGE
- db -1 ; end
-; fbe91
+INCLUDE "data/types/badge_type_boosts.asm"
diff --git a/engine/battle/effect_commands/attract.asm b/engine/battle/move_effects/attract.asm
index da6a9c0e9..bb7b4fce4 100755..100644
--- a/engine/battle/effect_commands/attract.asm
+++ b/engine/battle/move_effects/attract.asm
@@ -1,4 +1,4 @@
-BattleCommand_Attract: ; 377ce
+BattleCommand_Attract:
; attract
ld a, [wAttackMissed]
and a
@@ -20,11 +20,9 @@ BattleCommand_Attract: ; 377ce
jp StdBattleTextBox
.failed
- jp FailAttract
-; 377f5
+ jp FailMove
-
-CheckOppositeGender: ; 377f5
+CheckOppositeGender:
ld a, MON_SPECIES
call BattlePartyAttr
ld a, [hl]
@@ -76,4 +74,3 @@ CheckOppositeGender: ; 377f5
.genderless_samegender
scf
ret
-; 3784b
diff --git a/engine/battle/move_effects/baton_pass.asm b/engine/battle/move_effects/baton_pass.asm
new file mode 100644
index 000000000..5d9f19838
--- /dev/null
+++ b/engine/battle/move_effects/baton_pass.asm
@@ -0,0 +1,217 @@
+BattleCommand_BatonPass:
+; batonpass
+
+ ld a, [hBattleTurn]
+ and a
+ jp nz, .Enemy
+
+; Need something to switch to
+ call CheckAnyOtherAlivePartyMons
+ jp z, FailedBatonPass
+
+ call UpdateBattleMonInParty
+ call AnimateCurrentMove
+
+ ld c, 50
+ call DelayFrames
+
+; Transition into switchmon menu
+ call LoadStandardMenuHeader
+ farcall SetUpBattlePartyMenu_NoLoop
+
+ farcall ForcePickSwitchMonInBattle
+
+; Return to battle scene
+ call ClearPalettes
+ farcall _LoadBattleFontsHPBar
+ call CloseWindow
+ call ClearSprites
+ hlcoord 1, 0
+ lb bc, 4, 10
+ call ClearBox
+ ld b, SCGB_BATTLE_COLORS
+ call GetSGBLayout
+ call SetPalettes
+ call BatonPass_LinkPlayerSwitch
+
+; Mobile link battles handle entrances differently
+ farcall CheckMobileBattleError
+ jp c, EndMoveEffect
+
+ ld hl, PassedBattleMonEntrance
+ call CallBattleCore
+
+ call ResetBatonPassStatus
+ ret
+
+.Enemy:
+; Wildmons don't have anything to switch to
+ ld a, [wBattleMode]
+ dec a ; WILDMON
+ jp z, FailedBatonPass
+
+ call CheckAnyOtherAliveEnemyMons
+ jp z, FailedBatonPass
+
+ call UpdateEnemyMonInParty
+ call AnimateCurrentMove
+ call BatonPass_LinkEnemySwitch
+
+; Mobile link battles handle entrances differently
+ farcall CheckMobileBattleError
+ jp c, EndMoveEffect
+
+; Passed enemy PartyMon entrance
+ xor a
+ ld [wEnemySwitchMonIndex], a
+ ld hl, EnemySwitch_SetMode
+ call CallBattleCore
+ ld hl, ResetBattleParticipants
+ call CallBattleCore
+ ld a, 1
+ ld [wTypeMatchup], a
+ ld hl, ApplyStatLevelMultiplierOnAllStats
+ call CallBattleCore
+
+ ld hl, SpikesDamage
+ call CallBattleCore
+
+ jr ResetBatonPassStatus
+
+BatonPass_LinkPlayerSwitch:
+ ld a, [wLinkMode]
+ and a
+ ret z
+
+ ld a, 1
+ ld [wBattlePlayerAction], a
+
+ call LoadStandardMenuHeader
+ ld hl, LinkBattleSendReceiveAction
+ call CallBattleCore
+ call CloseWindow
+
+ xor a
+ ld [wBattlePlayerAction], a
+ ret
+
+BatonPass_LinkEnemySwitch:
+ ld a, [wLinkMode]
+ and a
+ ret z
+
+ call LoadStandardMenuHeader
+ ld hl, LinkBattleSendReceiveAction
+ call CallBattleCore
+
+ ld a, [wOTPartyCount]
+ add BATTLEACTION_SWITCH1
+ ld b, a
+ ld a, [wBattleAction]
+ cp BATTLEACTION_SWITCH1
+ jr c, .baton_pass
+ cp b
+ jr c, .switch
+
+.baton_pass
+ ld a, [wCurOTMon]
+ add BATTLEACTION_SWITCH1
+ ld [wBattleAction], a
+.switch
+ jp CloseWindow
+
+FailedBatonPass:
+ call AnimateFailedMove
+ jp PrintButItFailed
+
+ResetBatonPassStatus:
+; Reset status changes that aren't passed by Baton Pass.
+
+ ; Nightmare isn't passed.
+ ld a, BATTLE_VARS_STATUS
+ call GetBattleVar
+ and SLP
+ jr nz, .ok
+
+ ld a, BATTLE_VARS_SUBSTATUS1
+ call GetBattleVarAddr
+ res SUBSTATUS_NIGHTMARE, [hl]
+.ok
+
+ ; Disable isn't passed.
+ call ResetActorDisable
+
+ ; Attraction isn't passed.
+ ld hl, wPlayerSubStatus1
+ res SUBSTATUS_IN_LOVE, [hl]
+ ld hl, wEnemySubStatus1
+ res SUBSTATUS_IN_LOVE, [hl]
+ ld hl, wPlayerSubStatus5
+
+ ld a, BATTLE_VARS_SUBSTATUS5
+ call GetBattleVarAddr
+ res SUBSTATUS_TRANSFORMED, [hl]
+ res SUBSTATUS_ENCORED, [hl]
+
+ ; New mon hasn't used a move yet.
+ ld a, BATTLE_VARS_LAST_MOVE
+ call GetBattleVarAddr
+ ld [hl], 0
+
+ xor a
+ ld [wPlayerWrapCount], a
+ ld [wEnemyWrapCount], a
+ ret
+
+CheckAnyOtherAlivePartyMons:
+ ld hl, wPartyMon1HP
+ ld a, [wPartyCount]
+ ld d, a
+ ld a, [wCurBattleMon]
+ ld e, a
+ jr CheckAnyOtherAliveMons
+
+CheckAnyOtherAliveEnemyMons:
+ ld hl, wOTPartyMon1HP
+ ld a, [wOTPartyCount]
+ ld d, a
+ ld a, [wCurOTMon]
+ ld e, a
+
+ ; fallthrough
+
+CheckAnyOtherAliveMons:
+; Check for nonzero HP starting from partymon
+; HP at hl for d partymons, besides current mon e.
+
+; Return nz if any are alive.
+
+ xor a
+ ld b, a
+ ld c, a
+.loop
+ ld a, c
+ cp d
+ jr z, .done
+ cp e
+ jr z, .next
+
+ ld a, [hli]
+ or b
+ ld b, a
+ ld a, [hld]
+ or b
+ ld b, a
+
+.next
+ push bc
+ ld bc, PARTYMON_STRUCT_LENGTH
+ add hl, bc
+ pop bc
+ inc c
+ jr .loop
+
+.done
+ ld a, b
+ and a
+ ret
diff --git a/engine/battle/move_effects/beat_up.asm b/engine/battle/move_effects/beat_up.asm
new file mode 100644
index 000000000..673fc46c6
--- /dev/null
+++ b/engine/battle/move_effects/beat_up.asm
@@ -0,0 +1,224 @@
+BattleCommand_BeatUp:
+; beatup
+
+ call ResetDamage
+ ld a, [hBattleTurn]
+ and a
+ jp nz, .enemy_beats_up
+
+ ld a, [wPlayerSubStatus3]
+ bit SUBSTATUS_IN_LOOP, a
+ jr nz, .next_mon
+
+ ld c, 20
+ call DelayFrames
+ xor a
+ ld [wPlayerRolloutCount], a
+ ld [wd002], a
+ ld [wBeatUpHitAtLeastOnce], a
+ jr .got_mon
+
+.next_mon
+ ld a, [wPlayerRolloutCount]
+ ld b, a
+ ld a, [wPartyCount]
+ sub b
+ ld [wd002], a
+
+.got_mon
+ ld a, [wd002]
+ ld hl, wPartyMonNicknames
+ call GetNick
+ ld a, MON_HP
+ call GetBeatupMonLocation
+ ld a, [hli]
+ or [hl]
+ jp z, .beatup_fail ; fainted
+ ld a, [wd002]
+ ld c, a
+ ld a, [wCurBattleMon]
+ ; BUG: this can desynchronize link battles
+ ; Change "cp [hl]" to "cp c" to fix
+ cp [hl]
+ ld hl, wBattleMonStatus
+ jr z, .active_mon
+ ld a, MON_STATUS
+ call GetBeatupMonLocation
+.active_mon
+ ld a, [hl]
+ and a
+ jp nz, .beatup_fail
+
+ ld a, $1
+ ld [wBeatUpHitAtLeastOnce], a
+ ld hl, BeatUpAttackText
+ call StdBattleTextBox
+
+ ld a, [wEnemyMonSpecies]
+ ld [wCurSpecies], a
+ call GetBaseData
+ ld a, [wBaseDefense]
+ ld c, a
+
+ push bc
+ ld a, MON_SPECIES
+ call GetBeatupMonLocation
+ ld a, [hl]
+ ld [wCurSpecies], a
+ call GetBaseData
+ ld a, [wBaseAttack]
+ pop bc
+ ld b, a
+
+ push bc
+ ld a, MON_LEVEL
+ call GetBeatupMonLocation
+ ld a, [hl]
+ ld e, a
+ pop bc
+
+ ld a, [wPlayerMoveStructPower]
+ ld d, a
+ ret
+
+.enemy_beats_up
+ ld a, [wEnemySubStatus3]
+ bit SUBSTATUS_IN_LOOP, a
+ jr nz, .enemy_next_mon
+
+ xor a
+ ld [wEnemyRolloutCount], a
+ ld [wd002], a
+ ld [wBeatUpHitAtLeastOnce], a
+ jr .enemy_got_mon
+
+.enemy_next_mon
+ ld a, [wEnemyRolloutCount]
+ ld b, a
+ ld a, [wOTPartyCount]
+ sub b
+ ld [wd002], a
+
+.enemy_got_mon
+ ld a, [wBattleMode]
+ dec a
+ jr z, .wild
+
+ ld a, [wLinkMode]
+ and a
+ jr nz, .link_or_tower
+
+ ld a, [wInBattleTowerBattle]
+ and a
+ jr nz, .link_or_tower
+
+ ld a, [wd002]
+ ld c, a
+ ld b, 0
+ ld hl, wOTPartySpecies
+ add hl, bc
+ ld a, [hl]
+ ld [wNamedObjectIndexBuffer], a
+ call GetPokemonName
+ jr .got_enemy_nick
+
+.link_or_tower
+ ld a, [wd002]
+ ld hl, wOTPartyMonNicknames
+ ld bc, NAME_LENGTH
+ call AddNTimes
+ ld de, wStringBuffer1
+ call CopyBytes
+
+.got_enemy_nick
+ ld a, MON_HP
+ call GetBeatupMonLocation
+ ld a, [hli]
+ or [hl]
+ jp z, .beatup_fail
+
+ ld a, [wd002]
+ ld b, a
+ ld a, [wCurOTMon]
+ cp b
+ ld hl, wEnemyMonStatus
+ jr z, .active_enemy
+ ld a, MON_STATUS
+ call GetBeatupMonLocation
+.active_enemy
+ ld a, [hl]
+ and a
+ jr nz, .beatup_fail
+
+ ld a, $1
+ ld [wBeatUpHitAtLeastOnce], a
+ jr .finish_beatup
+
+.wild
+ ld a, [wEnemyMonSpecies]
+ ld [wNamedObjectIndexBuffer], a
+ call GetPokemonName
+ ld hl, BeatUpAttackText
+ call StdBattleTextBox
+ jp EnemyAttackDamage
+
+.finish_beatup
+ ld hl, BeatUpAttackText
+ call StdBattleTextBox
+
+ ld a, [wBattleMonSpecies]
+ ld [wCurSpecies], a
+ call GetBaseData
+ ld a, [wBaseDefense]
+ ld c, a
+
+ push bc
+ ld a, MON_SPECIES
+ call GetBeatupMonLocation
+ ld a, [hl]
+ ld [wCurSpecies], a
+ call GetBaseData
+ ld a, [wBaseAttack]
+ pop bc
+ ld b, a
+
+ push bc
+ ld a, MON_LEVEL
+ call GetBeatupMonLocation
+ ld a, [hl]
+ ld e, a
+ pop bc
+
+ ld a, [wEnemyMoveStructPower]
+ ld d, a
+ ret
+
+.beatup_fail
+ ld b, buildopponentrage_command
+ jp SkipToBattleCommand
+
+BattleCommand_BeatUpFailText:
+; beatupfailtext
+
+ ld a, [wBeatUpHitAtLeastOnce]
+ and a
+ ret nz
+
+ jp PrintButItFailed
+
+GetBeatupMonLocation:
+ push bc
+ ld c, a
+ ld b, 0
+ ld a, [hBattleTurn]
+ and a
+ ld hl, wPartyMon1Species
+ jr z, .got_species
+ ld hl, wOTPartyMon1Species
+
+.got_species
+ ld a, [wd002]
+ add hl, bc
+ call GetPartyLocation
+ pop bc
+ ret
diff --git a/engine/battle/move_effects/belly_drum.asm b/engine/battle/move_effects/belly_drum.asm
new file mode 100644
index 000000000..27ef1a542
--- /dev/null
+++ b/engine/battle/move_effects/belly_drum.asm
@@ -0,0 +1,34 @@
+BattleCommand_BellyDrum:
+; bellydrum
+; This command is buggy because it raises the user's attack
+; before checking that it has enough HP to use the move.
+; Swap the order of these two blocks to fix.
+ call BattleCommand_AttackUp2
+ ld a, [wAttackMissed]
+ and a
+ jr nz, .failed
+
+ callfar GetHalfMaxHP
+ callfar CheckUserHasEnoughHP
+ jr nc, .failed
+
+ push bc
+ call AnimateCurrentMove
+ pop bc
+ callfar SubtractHPFromUser
+ call UpdateUserInParty
+ ld a, 5
+
+.max_attack_loop
+ push af
+ call BattleCommand_AttackUp2
+ pop af
+ dec a
+ jr nz, .max_attack_loop
+
+ ld hl, BellyDrumText
+ jp StdBattleTextBox
+
+.failed
+ call AnimateFailedMove
+ jp PrintButItFailed
diff --git a/engine/battle/move_effects/bide.asm b/engine/battle/move_effects/bide.asm
new file mode 100644
index 000000000..871e0e7a8
--- /dev/null
+++ b/engine/battle/move_effects/bide.asm
@@ -0,0 +1,100 @@
+BattleCommand_StoreEnergy:
+; storeenergy
+
+ ld a, BATTLE_VARS_SUBSTATUS3
+ call GetBattleVar
+ bit SUBSTATUS_BIDE, a
+ ret z
+
+ ld hl, wPlayerRolloutCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .check_still_storing_energy
+ ld hl, wEnemyRolloutCount
+.check_still_storing_energy
+ dec [hl]
+ jr nz, .still_storing
+
+ ld a, BATTLE_VARS_SUBSTATUS3
+ call GetBattleVarAddr
+ res SUBSTATUS_BIDE, [hl]
+
+ ld hl, UnleashedEnergyText
+ call StdBattleTextBox
+
+ ld a, BATTLE_VARS_MOVE_POWER
+ call GetBattleVarAddr
+ ld a, 1
+ ld [hl], a
+ ld hl, wPlayerDamageTaken + 1
+ ld de, wPlayerCharging ; player
+ ld a, [hBattleTurn]
+ and a
+ jr z, .player
+ ld hl, wEnemyDamageTaken + 1
+ ld de, wEnemyCharging ; enemy
+.player
+ ld a, [hld]
+ add a
+ ld b, a
+ ld [wCurDamage + 1], a
+ ld a, [hl]
+ rl a
+ ld [wCurDamage], a
+ jr nc, .not_maxed
+ ld a, $ff
+ ld [wCurDamage], a
+ ld [wCurDamage + 1], a
+.not_maxed
+ or b
+ jr nz, .built_up_something
+ ld a, 1
+ ld [wAttackMissed], a
+.built_up_something
+ xor a
+ ld [hli], a
+ ld [hl], a
+ ld [de], a
+
+ ld a, BATTLE_VARS_MOVE_ANIM
+ call GetBattleVarAddr
+ ld a, BIDE
+ ld [hl], a
+
+ ld b, unleashenergy_command
+ jp SkipToBattleCommand
+
+.still_storing
+ ld hl, StoringEnergyText
+ call StdBattleTextBox
+ jp EndMoveEffect
+
+BattleCommand_UnleashEnergy:
+; unleashenergy
+
+ ld de, wPlayerDamageTaken
+ ld bc, wPlayerRolloutCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_damage
+ ld de, wEnemyDamageTaken
+ ld bc, wEnemyRolloutCount
+.got_damage
+ ld a, BATTLE_VARS_SUBSTATUS3
+ call GetBattleVarAddr
+ set SUBSTATUS_BIDE, [hl]
+ xor a
+ ld [de], a
+ inc de
+ ld [de], a
+ ld [wPlayerMoveStructEffect], a
+ ld [wEnemyMoveStructEffect], a
+ call BattleRandom
+ and 1
+ inc a
+ inc a
+ ld [bc], a
+ ld a, 1
+ ld [wKickCounter], a
+ call AnimateCurrentMove
+ jp EndMoveEffect
diff --git a/engine/battle/move_effects/conversion.asm b/engine/battle/move_effects/conversion.asm
new file mode 100644
index 000000000..f9307056c
--- /dev/null
+++ b/engine/battle/move_effects/conversion.asm
@@ -0,0 +1,96 @@
+BattleCommand_Conversion:
+; conversion
+
+ ld hl, wBattleMonMoves
+ ld de, wBattleMonType1
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_moves
+ ld hl, wEnemyMonMoves
+ ld de, wEnemyMonType1
+.got_moves
+ push de
+ ld c, 0
+ ld de, wStringBuffer1
+.loop
+ push hl
+ ld b, 0
+ add hl, bc
+ ld a, [hl]
+ pop hl
+ and a
+ jr z, .okay
+ push hl
+ push bc
+ dec a
+ ld hl, Moves + MOVE_TYPE
+ call GetMoveAttr
+ ld [de], a
+ inc de
+ pop bc
+ pop hl
+ inc c
+ ld a, c
+ cp NUM_MOVES
+ jr c, .loop
+.okay
+ ld a, $ff
+ ld [de], a
+ inc de
+ ld [de], a
+ inc de
+ ld [de], a
+ pop de
+ ld hl, wStringBuffer1
+.loop2
+ ld a, [hl]
+ cp -1
+ jr z, .fail
+ cp CURSE_T
+ jr z, .next
+ ld a, [de]
+ cp [hl]
+ jr z, .next
+ inc de
+ ld a, [de]
+ dec de
+ cp [hl]
+ jr nz, .done
+.next
+ inc hl
+ jr .loop2
+
+.fail
+ call AnimateFailedMove
+ jp PrintButItFailed
+
+.done
+.loop3
+ call BattleRandom
+ maskbits NUM_MOVES
+ ld c, a
+ ld b, 0
+ ld hl, wStringBuffer1
+ add hl, bc
+ ld a, [hl]
+ cp -1
+ jr z, .loop3
+ cp CURSE_T
+ jr z, .loop3
+ ld a, [de]
+ cp [hl]
+ jr z, .loop3
+ inc de
+ ld a, [de]
+ dec de
+ cp [hl]
+ jr z, .loop3
+ ld a, [hl]
+ ld [de], a
+ inc de
+ ld [de], a
+ ld [wNamedObjectIndexBuffer], a
+ farcall GetTypeName
+ call AnimateCurrentMove
+ ld hl, TransformedTypeText
+ jp StdBattleTextBox
diff --git a/engine/battle/move_effects/conversion2.asm b/engine/battle/move_effects/conversion2.asm
new file mode 100644
index 000000000..14a7e257a
--- /dev/null
+++ b/engine/battle/move_effects/conversion2.asm
@@ -0,0 +1,64 @@
+BattleCommand_Conversion2:
+; conversion2
+
+ ld a, [wAttackMissed]
+ and a
+ jr nz, .failed
+ ld hl, wBattleMonType1
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_type
+ ld hl, wEnemyMonType1
+.got_type
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ and a
+ jr z, .failed
+ push hl
+ dec a
+ ld hl, Moves + MOVE_TYPE
+ call GetMoveAttr
+ ld d, a
+ pop hl
+ cp CURSE_T
+ jr z, .failed
+ call AnimateCurrentMove
+ call BattleCommand_SwitchTurn
+
+.loop
+ call BattleRandom
+ maskbits NUM_TYPES
+ cp UNUSED_TYPES
+ jr c, .okay
+ cp UNUSED_TYPES_END
+ jr c, .loop
+ cp TYPES_END
+ jr nc, .loop
+.okay
+ ld [hli], a
+ ld [hld], a
+ push hl
+ ld a, BATTLE_VARS_MOVE_TYPE
+ call GetBattleVarAddr
+ push af
+ push hl
+ ld a, d
+ ld [hl], a
+ call BattleCheckTypeMatchup
+ pop hl
+ pop af
+ ld [hl], a
+ pop hl
+ ld a, [wTypeMatchup]
+ cp EFFECTIVE
+ jr nc, .loop
+ call BattleCommand_SwitchTurn
+
+ ld a, [hl]
+ ld [wNamedObjectIndexBuffer], a
+ predef GetTypeName
+ ld hl, TransformedTypeText
+ jp StdBattleTextBox
+
+.failed
+ jp FailMove
diff --git a/engine/battle/move_effects/counter.asm b/engine/battle/move_effects/counter.asm
new file mode 100644
index 000000000..031c399a6
--- /dev/null
+++ b/engine/battle/move_effects/counter.asm
@@ -0,0 +1,59 @@
+BattleCommand_Counter:
+; counter
+
+ ld a, 1
+ ld [wAttackMissed], a
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ and a
+ ret z
+
+ ld b, a
+ callfar GetMoveEffect
+ ld a, b
+ cp EFFECT_COUNTER
+ ret z
+
+ call BattleCommand_ResetTypeMatchup
+ ld a, [wTypeMatchup]
+ and a
+ ret z
+
+ call CheckOpponentWentFirst
+ ret z
+
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ dec a
+ ld de, wStringBuffer1
+ call GetMoveData
+
+ ld a, [wStringBuffer1 + MOVE_POWER]
+ and a
+ ret z
+
+ ld a, [wStringBuffer1 + MOVE_TYPE]
+ cp SPECIAL
+ ret nc
+
+ ; BUG: Move should fail with all non-damaging battle actions
+ ld hl, wCurDamage
+ ld a, [hli]
+ or [hl]
+ ret z
+
+ ld a, [hl]
+ add a
+ ld [hld], a
+ ld a, [hl]
+ adc a
+ ld [hl], a
+ jr nc, .capped
+ ld a, $ff
+ ld [hli], a
+ ld [hl], a
+.capped
+
+ xor a
+ ld [wAttackMissed], a
+ ret
diff --git a/engine/battle/effect_commands/curse.asm b/engine/battle/move_effects/curse.asm
index b11b9f3fb..4861e9a37 100644
--- a/engine/battle/effect_commands/curse.asm
+++ b/engine/battle/move_effects/curse.asm
@@ -1,4 +1,4 @@
-BattleCommand_Curse: ; 37588
+BattleCommand_Curse:
; curse
ld de, wBattleMonType1
@@ -21,7 +21,6 @@ BattleCommand_Curse: ; 37588
cp GHOST
jr z, .ghost
-
; If no stats can be increased, don't.
; Attack
@@ -54,7 +53,6 @@ BattleCommand_Curse: ; 37588
call BattleCommand_DefenseUp
jp BattleCommand_StatUpMessage
-
.ghost
; Cut HP in half and put a curse on the opponent.
@@ -84,7 +82,6 @@ BattleCommand_Curse: ; 37588
call AnimateFailedMove
jp PrintButItFailed
-
.cantraise
; Can't raise either stat.
@@ -94,4 +91,3 @@ BattleCommand_Curse: ; 37588
call AnimateFailedMove
ld hl, WontRiseAnymoreText
jp StdBattleTextBox
-; 37618
diff --git a/engine/battle/move_effects/destiny_bond.asm b/engine/battle/move_effects/destiny_bond.asm
new file mode 100644
index 000000000..55809d98a
--- /dev/null
+++ b/engine/battle/move_effects/destiny_bond.asm
@@ -0,0 +1,9 @@
+BattleCommand_DestinyBond:
+; destinybond
+
+ ld a, BATTLE_VARS_SUBSTATUS5
+ call GetBattleVarAddr
+ set SUBSTATUS_DESTINY_BOND, [hl]
+ call AnimateCurrentMove
+ ld hl, DestinyBondEffectText
+ jp StdBattleTextBox
diff --git a/engine/battle/move_effects/disable.asm b/engine/battle/move_effects/disable.asm
new file mode 100644
index 000000000..44017e30d
--- /dev/null
+++ b/engine/battle/move_effects/disable.asm
@@ -0,0 +1,72 @@
+BattleCommand_Disable:
+; disable
+
+ ld a, [wAttackMissed]
+ and a
+ jr nz, .failed
+
+ ld de, wEnemyDisableCount
+ ld hl, wEnemyMonMoves
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_moves
+ ld de, wPlayerDisableCount
+ ld hl, wBattleMonMoves
+.got_moves
+
+ ld a, [de]
+ and a
+ jr nz, .failed
+
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ and a
+ jr z, .failed
+ cp STRUGGLE
+ jr z, .failed
+
+ ld b, a
+ ld c, $ff
+.loop
+ inc c
+ ld a, [hli]
+ cp b
+ jr nz, .loop
+
+ ld a, [hBattleTurn]
+ and a
+ ld hl, wEnemyMonPP
+ jr z, .got_pp
+ ld hl, wBattleMonPP
+.got_pp
+ ld b, 0
+ add hl, bc
+ ld a, [hl]
+ and a
+ jr z, .failed
+.loop2
+ call BattleRandom
+ and 7
+ jr z, .loop2
+ inc a
+ inc c
+ swap c
+ add c
+ ld [de], a
+ call AnimateCurrentMove
+ ld hl, wDisabledMove
+ ld a, [hBattleTurn]
+ and a
+ jr nz, .got_disabled_move_pointer
+ inc hl
+.got_disabled_move_pointer
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ ld [hl], a
+ ld [wNamedObjectIndexBuffer], a
+ call GetMoveName
+ ld hl, WasDisabledText
+ jp StdBattleTextBox
+
+.failed
+ jp FailMove
diff --git a/engine/battle/move_effects/encore.asm b/engine/battle/move_effects/encore.asm
new file mode 100644
index 000000000..f436fd970
--- /dev/null
+++ b/engine/battle/move_effects/encore.asm
@@ -0,0 +1,120 @@
+BattleCommand_Encore:
+; encore
+
+ ld hl, wEnemyMonMoves
+ ld de, wEnemyEncoreCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .ok
+ ld hl, wBattleMonMoves
+ ld de, wPlayerEncoreCount
+.ok
+ ld a, BATTLE_VARS_LAST_MOVE_OPP
+ call GetBattleVar
+ and a
+ jp z, .failed
+ cp STRUGGLE
+ jp z, .failed
+ cp ENCORE
+ jp z, .failed
+ cp MIRROR_MOVE
+ jp z, .failed
+ ld b, a
+
+.got_move
+ ld a, [hli]
+ cp b
+ jr nz, .got_move
+
+ ld bc, wBattleMonPP - wBattleMonMoves - 1
+ add hl, bc
+ ld a, [hl]
+ and PP_MASK
+ jp z, .failed
+ ld a, [wAttackMissed]
+ and a
+ jp nz, .failed
+ ld a, BATTLE_VARS_SUBSTATUS5_OPP
+ call GetBattleVarAddr
+ bit SUBSTATUS_ENCORED, [hl]
+ jp nz, .failed
+ set SUBSTATUS_ENCORED, [hl]
+ call BattleRandom
+ and $3
+ inc a
+ inc a
+ inc a
+ ld [de], a
+ call CheckOpponentWentFirst
+ jr nz, .finish_move
+ ld a, [hBattleTurn]
+ and a
+ jr z, .force_last_enemy_move
+
+ push hl
+ ld a, [wLastPlayerMove]
+ ld b, a
+ ld c, 0
+ ld hl, wBattleMonMoves
+.find_player_move
+ ld a, [hli]
+ cp b
+ jr z, .got_player_move
+ inc c
+ ld a, c
+ cp NUM_MOVES
+ jr c, .find_player_move
+ pop hl
+ res SUBSTATUS_ENCORED, [hl]
+ xor a
+ ld [de], a
+ jr .failed
+
+.got_player_move
+ pop hl
+ ld a, c
+ ld [wCurMoveNum], a
+ ld a, b
+ ld [wCurPlayerMove], a
+ dec a
+ ld de, wPlayerMoveStruct
+ call GetMoveData
+ jr .finish_move
+
+.force_last_enemy_move
+ push hl
+ ld a, [wLastEnemyMove]
+ ld b, a
+ ld c, 0
+ ld hl, wEnemyMonMoves
+.find_enemy_move
+ ld a, [hli]
+ cp b
+ jr z, .got_enemy_move
+ inc c
+ ld a, c
+ cp NUM_MOVES
+ jr c, .find_enemy_move
+ pop hl
+ res SUBSTATUS_ENCORED, [hl]
+ xor a
+ ld [de], a
+ jr .failed
+
+.got_enemy_move
+ pop hl
+ ld a, c
+ ld [wCurEnemyMoveNum], a
+ ld a, b
+ ld [wCurEnemyMove], a
+ dec a
+ ld de, wEnemyMoveStruct
+ call GetMoveData
+
+.finish_move
+ call AnimateCurrentMove
+ ld hl, GotAnEncoreText
+ jp StdBattleTextBox
+
+.failed
+ jp PrintDidntAffect2
diff --git a/engine/battle/effect_commands/endure.asm b/engine/battle/move_effects/endure.asm
index ed4329ff5..f0555a737 100644
--- a/engine/battle/effect_commands/endure.asm
+++ b/engine/battle/move_effects/endure.asm
@@ -1,4 +1,4 @@
-BattleCommand_Endure: ; 3766f
+BattleCommand_Endure:
; endure
; Endure shares code with Protect. See protect.asm.
@@ -14,4 +14,3 @@ BattleCommand_Endure: ; 3766f
ld hl, BracedItselfText
jp StdBattleTextBox
-; 37683
diff --git a/engine/battle/move_effects/false_swipe.asm b/engine/battle/move_effects/false_swipe.asm
new file mode 100644
index 000000000..4f4eb329c
--- /dev/null
+++ b/engine/battle/move_effects/false_swipe.asm
@@ -0,0 +1,48 @@
+BattleCommand_FalseSwipe:
+; falseswipe
+
+; Makes sure wCurDamage < MonHP
+
+ ld hl, wEnemyMonHP
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_hp
+ ld hl, wBattleMonHP
+.got_hp
+ ld de, wCurDamage
+ ld c, 2
+ push hl
+ push de
+ call StringCmp
+ pop de
+ pop hl
+ jr c, .done
+
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ dec a
+ ld [de], a
+
+ inc a
+ jr nz, .okay
+ dec de
+ ld a, [de]
+ dec a
+ ld [de], a
+.okay
+
+ ld a, [wCriticalHit]
+ cp 2
+ jr nz, .carry
+ xor a
+ ld [wCriticalHit], a
+
+.carry
+ scf
+ ret
+
+.done
+ and a
+ ret
diff --git a/engine/battle/move_effects/focus_energy.asm b/engine/battle/move_effects/focus_energy.asm
new file mode 100644
index 000000000..ffdc7b136
--- /dev/null
+++ b/engine/battle/move_effects/focus_energy.asm
@@ -0,0 +1,15 @@
+BattleCommand_FocusEnergy:
+; focusenergy
+
+ ld a, BATTLE_VARS_SUBSTATUS4
+ call GetBattleVarAddr
+ bit SUBSTATUS_FOCUS_ENERGY, [hl]
+ jr nz, .already_pumped
+ set SUBSTATUS_FOCUS_ENERGY, [hl]
+ call AnimateCurrentMove
+ ld hl, GettingPumpedText
+ jp StdBattleTextBox
+
+.already_pumped
+ call AnimateFailedMove
+ jp PrintButItFailed
diff --git a/engine/battle/effect_commands/foresight.asm b/engine/battle/move_effects/foresight.asm
index 006e3b3d7..4235e0878 100644
--- a/engine/battle/effect_commands/foresight.asm
+++ b/engine/battle/move_effects/foresight.asm
@@ -1,4 +1,4 @@
-BattleCommand_Foresight: ; 376a0
+BattleCommand_Foresight:
; foresight
ld a, [wAttackMissed]
@@ -19,5 +19,4 @@ BattleCommand_Foresight: ; 376a0
jp StdBattleTextBox
.failed
- jp FailForesight
-; 376c2
+ jp FailMove
diff --git a/engine/battle/move_effects/frustration.asm b/engine/battle/move_effects/frustration.asm
new file mode 100644
index 000000000..3d395b510
--- /dev/null
+++ b/engine/battle/move_effects/frustration.asm
@@ -0,0 +1,27 @@
+BattleCommand_FrustrationPower:
+; frustrationpower
+
+ push bc
+ ld hl, wBattleMonHappiness
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_happiness
+ ld hl, wEnemyMonHappiness
+.got_happiness
+ ld a, $ff
+ sub [hl]
+ ld [hMultiplicand + 2], a
+ xor a
+ ld [hMultiplicand + 0], a
+ ld [hMultiplicand + 1], a
+ ld a, 10
+ ld [hMultiplier], a
+ call Multiply
+ ld a, 25
+ ld [hDivisor], a
+ ld b, 4
+ call Divide
+ ld a, [hQuotient + 2]
+ ld d, a
+ pop bc
+ ret
diff --git a/engine/battle/move_effects/fury_cutter.asm b/engine/battle/move_effects/fury_cutter.asm
new file mode 100644
index 000000000..6aa6b7838
--- /dev/null
+++ b/engine/battle/move_effects/fury_cutter.asm
@@ -0,0 +1,55 @@
+BattleCommand_FuryCutter:
+; furycutter
+
+ ld hl, wPlayerFuryCutterCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .go
+ ld hl, wEnemyFuryCutterCount
+
+.go
+ ld a, [wAttackMissed]
+ and a
+ jp nz, ResetFuryCutterCount
+
+ inc [hl]
+
+; Damage capped at 5 turns' worth (16x).
+ ld a, [hl]
+ ld b, a
+ cp 6
+ jr c, .checkdouble
+ ld b, 5
+
+.checkdouble
+ dec b
+ ret z
+
+; Double the damage
+ ld hl, wCurDamage + 1
+ sla [hl]
+ dec hl
+ rl [hl]
+ jr nc, .checkdouble
+
+; No overflow
+ ld a, $ff
+ ld [hli], a
+ ld [hl], a
+ ret
+
+ResetFuryCutterCount:
+ push hl
+
+ ld hl, wPlayerFuryCutterCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .reset
+ ld hl, wEnemyFuryCutterCount
+
+.reset
+ xor a
+ ld [hl], a
+
+ pop hl
+ ret
diff --git a/engine/battle/move_effects/future_sight.asm b/engine/battle/move_effects/future_sight.asm
new file mode 100644
index 000000000..c28841b35
--- /dev/null
+++ b/engine/battle/move_effects/future_sight.asm
@@ -0,0 +1,81 @@
+BattleCommand_CheckFutureSight:
+; checkfuturesight
+
+ ld hl, wPlayerFutureSightCount
+ ld de, wPlayerFutureSightDamage
+ ld a, [hBattleTurn]
+ and a
+ jr z, .ok
+ ld hl, wEnemyFutureSightCount
+ ld de, wEnemyFutureSightDamage
+.ok
+
+ ld a, [hl]
+ and a
+ ret z
+ cp 1
+ ret nz
+
+ ld [hl], 0
+ ld a, [de]
+ inc de
+ ld [wCurDamage], a
+ ld a, [de]
+ ld [wCurDamage + 1], a
+ ld b, futuresight_command
+ jp SkipToBattleCommand
+
+BattleCommand_FutureSight:
+; futuresight
+
+ call CheckUserIsCharging
+ jr nz, .AlreadyChargingFutureSight
+ ld a, BATTLE_VARS_MOVE_ANIM
+ call GetBattleVar
+ ld b, a
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE
+ call GetBattleVarAddr
+ ld [hl], b
+ ld a, BATTLE_VARS_LAST_MOVE
+ call GetBattleVarAddr
+ ld [hl], b
+.AlreadyChargingFutureSight:
+ ld hl, wPlayerFutureSightCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .GotFutureSightCount
+ ld hl, wEnemyFutureSightCount
+.GotFutureSightCount:
+ ld a, [hl]
+ and a
+ jr nz, .failed
+ ld a, 4
+ ld [hl], a
+ call BattleCommand_LowerSub
+ call BattleCommand_MoveDelay
+ ld hl, ForesawAttackText
+ call StdBattleTextBox
+ call BattleCommand_RaiseSub
+ ld de, wPlayerFutureSightDamage
+ ld a, [hBattleTurn]
+ and a
+ jr z, .StoreDamage
+ ld de, wEnemyFutureSightDamage
+.StoreDamage:
+ ld hl, wCurDamage
+ ld a, [hl]
+ ld [de], a
+ ld [hl], 0
+ inc hl
+ inc de
+ ld a, [hl]
+ ld [de], a
+ ld [hl], 0
+ jp EndMoveEffect
+
+.failed
+ pop bc
+ call ResetDamage
+ call AnimateFailedMove
+ call PrintButItFailed
+ jp EndMoveEffect
diff --git a/engine/battle/move_effects/heal_bell.asm b/engine/battle/move_effects/heal_bell.asm
new file mode 100644
index 000000000..2570a53ba
--- /dev/null
+++ b/engine/battle/move_effects/heal_bell.asm
@@ -0,0 +1,34 @@
+BattleCommand_HealBell:
+; healbell
+
+ ld a, BATTLE_VARS_SUBSTATUS1
+ call GetBattleVarAddr
+ res SUBSTATUS_NIGHTMARE, [hl]
+ ld de, wPartyMon1Status
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_status
+ ld de, wOTPartyMon1Status
+.got_status
+ ld a, BATTLE_VARS_STATUS
+ call GetBattleVarAddr
+ xor a
+ ld [hl], a
+ ld h, d
+ ld l, e
+ ld bc, PARTYMON_STRUCT_LENGTH
+ ld d, PARTY_LENGTH
+.loop
+ ld [hl], a
+ add hl, bc
+ dec d
+ jr nz, .loop
+ call AnimateCurrentMove
+
+ ld hl, BellChimedText
+ call StdBattleTextBox
+
+ ld a, [hBattleTurn]
+ and a
+ jp z, CalcPlayerStats
+ jp CalcEnemyStats
diff --git a/engine/battle/move_effects/hidden_power.asm b/engine/battle/move_effects/hidden_power.asm
new file mode 100644
index 000000000..3b40a6c31
--- /dev/null
+++ b/engine/battle/move_effects/hidden_power.asm
@@ -0,0 +1,8 @@
+BattleCommand_HiddenPower:
+; hiddenpower
+
+ ld a, [wAttackMissed]
+ and a
+ ret nz
+ farcall HiddenPowerDamage
+ ret
diff --git a/engine/battle/move_effects/leech_seed.asm b/engine/battle/move_effects/leech_seed.asm
new file mode 100644
index 000000000..5602e7f62
--- /dev/null
+++ b/engine/battle/move_effects/leech_seed.asm
@@ -0,0 +1,40 @@
+BattleCommand_LeechSeed:
+; leechseed
+ ld a, [wAttackMissed]
+ and a
+ jr nz, .evaded
+ call CheckSubstituteOpp
+ jr nz, .evaded
+
+ ld de, wEnemyMonType1
+ ld a, [hBattleTurn]
+ and a
+ jr z, .ok
+ ld de, wBattleMonType1
+.ok
+
+ ld a, [de]
+ cp GRASS
+ jr z, .grass
+ inc de
+ ld a, [de]
+ cp GRASS
+ jr z, .grass
+
+ ld a, BATTLE_VARS_SUBSTATUS4_OPP
+ call GetBattleVarAddr
+ bit SUBSTATUS_LEECH_SEED, [hl]
+ jr nz, .evaded
+ set SUBSTATUS_LEECH_SEED, [hl]
+ call AnimateCurrentMove
+ ld hl, WasSeededText
+ jp StdBattleTextBox
+
+.grass
+ call AnimateFailedMove
+ jp PrintDoesntAffect
+
+.evaded
+ call AnimateFailedMove
+ ld hl, EvadedText
+ jp StdBattleTextBox
diff --git a/engine/battle/move_effects/lock_on.asm b/engine/battle/move_effects/lock_on.asm
new file mode 100644
index 000000000..7dc4a013d
--- /dev/null
+++ b/engine/battle/move_effects/lock_on.asm
@@ -0,0 +1,21 @@
+BattleCommand_LockOn:
+; lockon
+
+ call CheckSubstituteOpp
+ jr nz, .fail
+
+ ld a, [wAttackMissed]
+ and a
+ jr nz, .fail
+
+ ld a, BATTLE_VARS_SUBSTATUS5_OPP
+ call GetBattleVarAddr
+ set SUBSTATUS_LOCK_ON, [hl]
+ call AnimateCurrentMove
+
+ ld hl, TookAimText
+ jp StdBattleTextBox
+
+.fail
+ call AnimateFailedMove
+ jp PrintDidntAffect
diff --git a/engine/battle/move_effects/magnitude.asm b/engine/battle/move_effects/magnitude.asm
new file mode 100644
index 000000000..4dcf919d7
--- /dev/null
+++ b/engine/battle/move_effects/magnitude.asm
@@ -0,0 +1,29 @@
+BattleCommand_GetMagnitude:
+; getmagnitude
+
+ push bc
+ call BattleRandom
+ ld b, a
+ ld hl, MagnitudePower
+.loop
+ ld a, [hli]
+ cp b
+ jr nc, .ok
+ inc hl
+ inc hl
+ jr .loop
+
+.ok
+ ld d, [hl]
+ push de
+ inc hl
+ ld a, [hl]
+ ld [wTypeMatchup], a
+ call BattleCommand_MoveDelay
+ ld hl, MagnitudeText
+ call StdBattleTextBox
+ pop de
+ pop bc
+ ret
+
+INCLUDE "data/moves/magnitude_power.asm"
diff --git a/engine/battle/effect_commands/metronome.asm b/engine/battle/move_effects/metronome.asm
index 1908df84d..25197d7cd 100644
--- a/engine/battle/effect_commands/metronome.asm
+++ b/engine/battle/move_effects/metronome.asm
@@ -1,4 +1,4 @@
-BattleCommand_Metronome: ; 37418
+BattleCommand_Metronome:
; metronome
call ClearLastMove
@@ -34,28 +34,10 @@ BattleCommand_Metronome: ; 37418
call CheckUserMove
jr z, .GetMove
-
ld a, BATTLE_VARS_MOVE
call GetBattleVarAddr
ld [hl], b
call UpdateMoveData
jp ResetTurn
-; 37454
-
-
-MetronomeExcepts: ; 37454
- db NO_MOVE
- db METRONOME
- db STRUGGLE
- db SKETCH
- db MIMIC
- db COUNTER
- db MIRROR_COAT
- db PROTECT
- db DETECT
- db ENDURE
- db DESTINY_BOND
- db SLEEP_TALK
- db THIEF
- db -1
-; 37462
+
+INCLUDE "data/moves/metronome_exception_moves.asm"
diff --git a/engine/battle/move_effects/mimic.asm b/engine/battle/move_effects/mimic.asm
new file mode 100644
index 000000000..b1c6608fa
--- /dev/null
+++ b/engine/battle/move_effects/mimic.asm
@@ -0,0 +1,50 @@
+BattleCommand_Mimic:
+; mimic
+
+ call ClearLastMove
+ call BattleCommand_MoveDelay
+ ld a, [wAttackMissed]
+ and a
+ jr nz, .fail
+ ld hl, wBattleMonMoves
+ ld a, [hBattleTurn]
+ and a
+ jr z, .player_turn
+ ld hl, wEnemyMonMoves
+.player_turn
+ call CheckHiddenOpponent
+ jr nz, .fail
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ and a
+ jr z, .fail
+ cp STRUGGLE
+ jr z, .fail
+ ld b, a
+ ld c, NUM_MOVES
+.check_already_knows_move
+ ld a, [hli]
+ cp b
+ jr z, .fail
+ dec c
+ jr nz, .check_already_knows_move
+ dec hl
+.find_mimic
+ ld a, [hld]
+ cp MIMIC
+ jr nz, .find_mimic
+ inc hl
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ ld [hl], a
+ ld [wNamedObjectIndexBuffer], a
+ ld bc, wBattleMonPP - wBattleMonMoves
+ add hl, bc
+ ld [hl], 5
+ call GetMoveName
+ call AnimateCurrentMove
+ ld hl, LearnedMoveText
+ jp StdBattleTextBox
+
+.fail
+ jp FailMimic
diff --git a/engine/battle/move_effects/mirror_coat.asm b/engine/battle/move_effects/mirror_coat.asm
new file mode 100644
index 000000000..fb3a30d58
--- /dev/null
+++ b/engine/battle/move_effects/mirror_coat.asm
@@ -0,0 +1,60 @@
+BattleCommand_MirrorCoat:
+; mirrorcoat
+
+ ld a, 1
+ ld [wAttackMissed], a
+
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ and a
+ ret z
+
+ ld b, a
+ callfar GetMoveEffect
+ ld a, b
+ cp EFFECT_MIRROR_COAT
+ ret z
+
+ call BattleCommand_ResetTypeMatchup
+ ld a, [wTypeMatchup]
+ and a
+ ret z
+
+ call CheckOpponentWentFirst
+ ret z
+
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ dec a
+ ld de, wStringBuffer1
+ call GetMoveData
+
+ ld a, [wStringBuffer1 + 2]
+ and a
+ ret z
+
+ ld a, [wStringBuffer1 + 3]
+ cp SPECIAL
+ ret c
+
+ ; BUG: Move should fail with all non-damaging battle actions
+ ld hl, wCurDamage
+ ld a, [hli]
+ or [hl]
+ ret z
+
+ ld a, [hl]
+ add a
+ ld [hld], a
+ ld a, [hl]
+ adc a
+ ld [hl], a
+ jr nc, .capped
+ ld a, $ff
+ ld [hli], a
+ ld [hl], a
+.capped
+
+ xor a
+ ld [wAttackMissed], a
+ ret
diff --git a/engine/battle/effect_commands/mirror_move.asm b/engine/battle/move_effects/mirror_move.asm
index c4f208d77..089403839 100644
--- a/engine/battle/effect_commands/mirror_move.asm
+++ b/engine/battle/move_effects/mirror_move.asm
@@ -1,4 +1,4 @@
-BattleCommand_MirrorMove: ; 373c9
+BattleCommand_MirrorMove:
; mirrormove
call ClearLastMove
@@ -49,4 +49,3 @@ BattleCommand_MirrorMove: ; 373c9
.done
call BattleCommand_MoveDelay
jp ResetTurn
-; 37418
diff --git a/engine/battle/move_effects/mist.asm b/engine/battle/move_effects/mist.asm
new file mode 100644
index 000000000..199a30045
--- /dev/null
+++ b/engine/battle/move_effects/mist.asm
@@ -0,0 +1,15 @@
+BattleCommand_Mist:
+; mist
+
+ ld a, BATTLE_VARS_SUBSTATUS4
+ call GetBattleVarAddr
+ bit SUBSTATUS_MIST, [hl]
+ jr nz, .already_mist
+ set SUBSTATUS_MIST, [hl]
+ call AnimateCurrentMove
+ ld hl, MistText
+ jp StdBattleTextBox
+
+.already_mist
+ call AnimateFailedMove
+ jp PrintButItFailed
diff --git a/engine/battle/effect_commands/nightmare.asm b/engine/battle/move_effects/nightmare.asm
index 788e3de41..dd85c722d 100644
--- a/engine/battle/effect_commands/nightmare.asm
+++ b/engine/battle/move_effects/nightmare.asm
@@ -1,4 +1,4 @@
-BattleCommand_Nightmare: ; 37536
+BattleCommand_Nightmare:
; nightmare
; Can't hit an absent opponent.
@@ -35,4 +35,3 @@ BattleCommand_Nightmare: ; 37536
.failed
call AnimateFailedMove
jp PrintButItFailed
-; 37563
diff --git a/engine/battle/move_effects/pain_split.asm b/engine/battle/move_effects/pain_split.asm
new file mode 100644
index 000000000..4e4380b23
--- /dev/null
+++ b/engine/battle/move_effects/pain_split.asm
@@ -0,0 +1,93 @@
+BattleCommand_PainSplit:
+; painsplit
+
+ ld a, [wAttackMissed]
+ and a
+ jp nz, .ButItFailed
+ call CheckSubstituteOpp
+ jp nz, .ButItFailed
+ call AnimateCurrentMove
+ ld hl, wBattleMonMaxHP + 1
+ ld de, wEnemyMonMaxHP + 1
+ call .PlayerShareHP
+ ld a, $1
+ ld [wWhichHPBar], a
+ hlcoord 10, 9
+ predef AnimateHPBar
+ ld hl, wEnemyMonHP
+ ld a, [hli]
+ ld [wBuffer4], a
+ ld a, [hli]
+ ld [wBuffer3], a
+ ld a, [hli]
+ ld [wBuffer2], a
+ ld a, [hl]
+ ld [wBuffer1], a
+ call .EnemyShareHP
+ xor a
+ ld [wWhichHPBar], a
+ call ResetDamage
+ hlcoord 2, 2
+ predef AnimateHPBar
+ farcall _UpdateBattleHUDs
+
+ ld hl, SharedPainText
+ jp StdBattleTextBox
+
+.PlayerShareHP:
+ ld a, [hld]
+ ld [wBuffer1], a
+ ld a, [hld]
+ ld [wBuffer2], a
+ ld a, [hld]
+ ld b, a
+ ld [wBuffer3], a
+ ld a, [hl]
+ ld [wBuffer4], a
+ dec de
+ dec de
+ ld a, [de]
+ dec de
+ add b
+ ld [wCurDamage + 1], a
+ ld b, [hl]
+ ld a, [de]
+ adc b
+ srl a
+ ld [wCurDamage], a
+ ld a, [wCurDamage + 1]
+ rr a
+ ld [wCurDamage + 1], a
+ inc hl
+ inc hl
+ inc hl
+ inc de
+ inc de
+ inc de
+
+.EnemyShareHP:
+ ld c, [hl]
+ dec hl
+ ld a, [wCurDamage + 1]
+ sub c
+ ld b, [hl]
+ dec hl
+ ld a, [wCurDamage]
+ sbc b
+ jr nc, .skip
+
+ ld a, [wCurDamage]
+ ld b, a
+ ld a, [wCurDamage + 1]
+ ld c, a
+.skip
+ ld a, c
+ ld [hld], a
+ ld [wBuffer5], a
+ ld a, b
+ ld [hli], a
+ ld [wBuffer6], a
+ ret
+
+.ButItFailed:
+ jp PrintDidntAffect2
diff --git a/engine/battle/move_effects/pay_day.asm b/engine/battle/move_effects/pay_day.asm
new file mode 100644
index 000000000..ba1dce884
--- /dev/null
+++ b/engine/battle/move_effects/pay_day.asm
@@ -0,0 +1,26 @@
+BattleCommand_PayDay:
+; payday
+
+ xor a
+ ld hl, wStringBuffer1
+ ld [hli], a
+
+ ld a, [hBattleTurn]
+ and a
+ ld a, [wBattleMonLevel]
+ jr z, .ok
+ ld a, [wEnemyMonLevel]
+.ok
+
+ add a
+ ld hl, wPayDayMoney + 2
+ add [hl]
+ ld [hld], a
+ jr nc, .done
+ inc [hl]
+ dec hl
+ jr nz, .done
+ inc [hl]
+.done
+ ld hl, CoinsScatteredText
+ jp StdBattleTextBox
diff --git a/engine/battle/effect_commands/perish_song.asm b/engine/battle/move_effects/perish_song.asm
index 8c88c8739..4df52cc1c 100644
--- a/engine/battle/effect_commands/perish_song.asm
+++ b/engine/battle/move_effects/perish_song.asm
@@ -1,7 +1,6 @@
-BattleCommand_PerishSong: ; 376c2
+BattleCommand_PerishSong:
; perishsong
-
ld hl, wPlayerSubStatus1
ld de, wEnemySubStatus1
bit SUBSTATUS_PERISH, [hl]
@@ -37,4 +36,3 @@ BattleCommand_PerishSong: ; 376c2
.failed
call AnimateFailedMove
jp PrintButItFailed
-; 376f8
diff --git a/engine/battle/effect_commands/present.asm b/engine/battle/move_effects/present.asm
index f0cf8006d..f0949558f 100755..100644
--- a/engine/battle/effect_commands/present.asm
+++ b/engine/battle/move_effects/present.asm
@@ -1,4 +1,4 @@
-BattleCommand_Present: ; 37874
+BattleCommand_Present:
; present
ld a, [wLinkMode]
@@ -27,17 +27,17 @@ BattleCommand_Present: ; 37874
push bc
call BattleRandom
ld b, a
- ld hl, .PresentPower
+ ld hl, PresentPower
ld c, 0
.next
ld a, [hli]
cp -1
- jr z, .heal_effect ; 378a4 $11
+ jr z, .heal_effect
cp b
- jr nc, .got_power ; 378a7 $4
+ jr nc, .got_power
inc c
inc hl
- jr .next ; 378ab $f4
+ jr .next
.got_power
ld a, c
@@ -49,19 +49,19 @@ BattleCommand_Present: ; 37874
.heal_effect
pop bc
- ld a, $3
+ ld a, 3
ld [wPresentPower], a
call AnimateCurrentMove
call BattleCommand_SwitchTurn
ld hl, AICheckPlayerMaxHP
ld a, [hBattleTurn]
and a
- jr z, .got_hp_fn_pointer ; 378c9 $3
+ jr z, .got_hp_fn_pointer
ld hl, AICheckEnemyMaxHP
.got_hp_fn_pointer
ld a, BANK(AICheckPlayerMaxHP)
rst FarCall
- jr c, .already_fully_healed ; 378d1 $20
+ jr c, .already_fully_healed
ld hl, GetQuarterMaxHP
call CallBattleCore
@@ -73,21 +73,16 @@ BattleCommand_Present: ; 37874
call StdBattleTextBox
call BattleCommand_SwitchTurn
call UpdateOpponentInParty
- jr .do_animation ; 378f1 $11
+ jr .do_animation
.already_fully_healed
call BattleCommand_SwitchTurn
call _CheckBattleScene
- jr nc, .do_animation ; 378f9 $9
+ jr nc, .do_animation
call AnimateFailedMove
ld hl, RefusedGiftText
call StdBattleTextBox
.do_animation
jp EndMoveEffect
-.PresentPower:
- db 40 percent, 40
- db 70 percent + 1, 80
- db 80 percent, 120
- db -1 ; end
-; 3790e
+INCLUDE "data/moves/present_power.asm"
diff --git a/engine/battle/effect_commands/protect.asm b/engine/battle/move_effects/protect.asm
index 6c65e0ed1..9025d2f4b 100644
--- a/engine/battle/effect_commands/protect.asm
+++ b/engine/battle/move_effects/protect.asm
@@ -1,4 +1,4 @@
-BattleCommand_Protect: ; 37618
+BattleCommand_Protect:
; protect
call ProtectChance
ret c
@@ -11,11 +11,8 @@ BattleCommand_Protect: ; 37618
ld hl, ProtectedItselfText
jp StdBattleTextBox
-; 3762c
-
-
-ProtectChance: ; 3762c
+ProtectChance:
ld de, wPlayerProtectCount
ld a, [hBattleTurn]
and a
@@ -69,7 +66,6 @@ ProtectChance: ; 3762c
and a
ret
-
.failed
xor a
ld [de], a
@@ -77,4 +73,3 @@ ProtectChance: ; 3762c
call PrintButItFailed
scf
ret
-; 3766f
diff --git a/engine/battle/move_effects/psych_up.asm b/engine/battle/move_effects/psych_up.asm
new file mode 100644
index 000000000..02fdef5d2
--- /dev/null
+++ b/engine/battle/move_effects/psych_up.asm
@@ -0,0 +1,49 @@
+BattleCommand_PsychUp:
+; psychup
+
+ ld hl, wEnemyStatLevels
+ ld de, wPlayerStatLevels
+ ld a, [hBattleTurn]
+ and a
+ jr z, .pointers_correct
+; It's the enemy's turn, so swap the pointers.
+ push hl
+ ld h, d
+ ld l, e
+ pop de
+.pointers_correct
+ push hl
+ ld b, NUM_LEVEL_STATS
+; If any of the enemy's stats is modified from its base level,
+; the move succeeds. Otherwise, it fails.
+.loop
+ ld a, [hli]
+ cp BASE_STAT_LEVEL
+ jr nz, .break
+ dec b
+ jr nz, .loop
+ pop hl
+ call AnimateFailedMove
+ jp PrintButItFailed
+
+.break
+ pop hl
+ ld b, NUM_LEVEL_STATS
+.loop2
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .loop2
+ ld a, [hBattleTurn]
+ and a
+ jr nz, .calc_enemy_stats
+ call CalcPlayerStats
+ jr .merge
+
+.calc_enemy_stats
+ call CalcEnemyStats
+.merge
+ call AnimateCurrentMove
+ ld hl, CopiedStatsText
+ jp StdBattleTextBox
diff --git a/engine/battle/move_effects/pursuit.asm b/engine/battle/move_effects/pursuit.asm
new file mode 100644
index 000000000..18c358144
--- /dev/null
+++ b/engine/battle/move_effects/pursuit.asm
@@ -0,0 +1,24 @@
+BattleCommand_Pursuit:
+; pursuit
+; Double damage if the opponent is switching.
+
+ ld hl, wEnemyIsSwitching
+ ld a, [hBattleTurn]
+ and a
+ jr z, .ok
+ ld hl, wPlayerIsSwitching
+.ok
+ ld a, [hl]
+ and a
+ ret z
+
+ ld hl, wCurDamage + 1
+ sla [hl]
+ dec hl
+ rl [hl]
+ ret nc
+
+ ld a, $ff
+ ld [hli], a
+ ld [hl], a
+ ret
diff --git a/engine/battle/move_effects/rage.asm b/engine/battle/move_effects/rage.asm
new file mode 100644
index 000000000..df206a6bf
--- /dev/null
+++ b/engine/battle/move_effects/rage.asm
@@ -0,0 +1,6 @@
+BattleCommand_Rage:
+; rage
+ ld a, BATTLE_VARS_SUBSTATUS4
+ call GetBattleVarAddr
+ set SUBSTATUS_RAGE, [hl]
+ ret
diff --git a/engine/battle/move_effects/rain_dance.asm b/engine/battle/move_effects/rain_dance.asm
new file mode 100644
index 000000000..e9ef5d123
--- /dev/null
+++ b/engine/battle/move_effects/rain_dance.asm
@@ -0,0 +1,9 @@
+BattleCommand_StartRain:
+; startrain
+ ld a, WEATHER_RAIN
+ ld [wBattleWeather], a
+ ld a, 5
+ ld [wWeatherCount], a
+ call AnimateCurrentMove
+ ld hl, DownpourText
+ jp StdBattleTextBox
diff --git a/engine/battle/move_effects/rapid_spin.asm b/engine/battle/move_effects/rapid_spin.asm
new file mode 100644
index 000000000..0dc8b7de2
--- /dev/null
+++ b/engine/battle/move_effects/rapid_spin.asm
@@ -0,0 +1,36 @@
+BattleCommand_ClearHazards:
+; clearhazards
+
+ ld a, BATTLE_VARS_SUBSTATUS4
+ call GetBattleVarAddr
+ bit SUBSTATUS_LEECH_SEED, [hl]
+ jr z, .not_leeched
+ res SUBSTATUS_LEECH_SEED, [hl]
+ ld hl, ShedLeechSeedText
+ call StdBattleTextBox
+.not_leeched
+
+ ld hl, wPlayerScreens
+ ld de, wPlayerWrapCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_screens_wrap
+ ld hl, wEnemyScreens
+ ld de, wEnemyWrapCount
+.got_screens_wrap
+ bit SCREENS_SPIKES, [hl]
+ jr z, .no_spikes
+ res SCREENS_SPIKES, [hl]
+ ld hl, BlewSpikesText
+ push de
+ call StdBattleTextBox
+ pop de
+.no_spikes
+
+ ld a, [de]
+ and a
+ ret z
+ xor a
+ ld [de], a
+ ld hl, ReleasedByText
+ jp StdBattleTextBox
diff --git a/engine/battle/move_effects/return.asm b/engine/battle/move_effects/return.asm
new file mode 100644
index 000000000..d3071d23a
--- /dev/null
+++ b/engine/battle/move_effects/return.asm
@@ -0,0 +1,25 @@
+BattleCommand_HappinessPower:
+; happinesspower
+ push bc
+ ld hl, wBattleMonHappiness
+ ld a, [hBattleTurn]
+ and a
+ jr z, .ok
+ ld hl, wEnemyMonHappiness
+.ok
+ xor a
+ ld [hMultiplicand + 0], a
+ ld [hMultiplicand + 1], a
+ ld a, [hl]
+ ld [hMultiplicand + 2], a
+ ld a, 10
+ ld [hMultiplier], a
+ call Multiply
+ ld a, 25
+ ld [hDivisor], a
+ ld b, 4
+ call Divide
+ ld a, [hQuotient + 2]
+ ld d, a
+ pop bc
+ ret
diff --git a/engine/battle/effect_commands/rollout.asm b/engine/battle/move_effects/rollout.asm
index f6966c48a..de4bfcaa6 100644
--- a/engine/battle/effect_commands/rollout.asm
+++ b/engine/battle/move_effects/rollout.asm
@@ -1,7 +1,6 @@
MAX_ROLLOUT_COUNT EQU 5
-
-BattleCommand_CheckCurl: ; 37718
+BattleCommand_CheckCurl:
; checkcurl
ld de, wPlayerRolloutCount
@@ -22,10 +21,8 @@ BattleCommand_CheckCurl: ; 37718
xor a
ld [de], a
ret
-; 37734
-
-BattleCommand_RolloutPower: ; 37734
+BattleCommand_RolloutPower:
; rolloutpower
ld a, BATTLE_VARS_STATUS
@@ -96,4 +93,3 @@ BattleCommand_RolloutPower: ; 37734
.done_damage
ret
-; 37791
diff --git a/engine/battle/move_effects/safeguard.asm b/engine/battle/move_effects/safeguard.asm
new file mode 100644
index 000000000..a926bdccc
--- /dev/null
+++ b/engine/battle/move_effects/safeguard.asm
@@ -0,0 +1,23 @@
+BattleCommand_Safeguard:
+; safeguard
+
+ ld hl, wPlayerScreens
+ ld de, wPlayerSafeguardCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .ok
+ ld hl, wEnemyScreens
+ ld de, wEnemySafeguardCount
+.ok
+ bit SCREENS_SAFEGUARD, [hl]
+ jr nz, .failed
+ set SCREENS_SAFEGUARD, [hl]
+ ld a, 5
+ ld [de], a
+ call AnimateCurrentMove
+ ld hl, CoveredByVeilText
+ jp StdBattleTextBox
+
+.failed
+ call AnimateFailedMove
+ jp PrintButItFailed
diff --git a/engine/battle/effect_commands/sandstorm.asm b/engine/battle/move_effects/sandstorm.asm
index 5aaa61deb..77d6e24b5 100644
--- a/engine/battle/effect_commands/sandstorm.asm
+++ b/engine/battle/move_effects/sandstorm.asm
@@ -1,4 +1,4 @@
-BattleCommand_StartSandstorm: ; 376f8
+BattleCommand_StartSandstorm:
; startsandstorm
ld a, [wBattleWeather]
@@ -16,4 +16,3 @@ BattleCommand_StartSandstorm: ; 376f8
.failed
call AnimateFailedMove
jp PrintButItFailed
-; 37718
diff --git a/engine/battle/move_effects/selfdestruct.asm b/engine/battle/move_effects/selfdestruct.asm
new file mode 100644
index 000000000..d6eeac484
--- /dev/null
+++ b/engine/battle/move_effects/selfdestruct.asm
@@ -0,0 +1,29 @@
+BattleCommand_Selfdestruct:
+ farcall StubbedTrainerRankings_Selfdestruct
+ ld a, BATTLEANIM_PLAYER_DAMAGE
+ ld [wNumHits], a
+ ld c, 3
+ call DelayFrames
+ ld a, BATTLE_VARS_STATUS
+ call GetBattleVarAddr
+ xor a
+ ld [hli], a
+ inc hl
+ ld [hli], a
+ ld [hl], a
+ ld a, $1
+ ld [wKickCounter], a
+ call BattleCommand_LowerSub
+ call LoadMoveAnim
+ ld a, BATTLE_VARS_SUBSTATUS4
+ call GetBattleVarAddr
+ res SUBSTATUS_LEECH_SEED, [hl]
+ ld a, BATTLE_VARS_SUBSTATUS5_OPP
+ call GetBattleVarAddr
+ res SUBSTATUS_DESTINY_BOND, [hl]
+ call _CheckBattleScene
+ ret nc
+ farcall DrawPlayerHUD
+ farcall DrawEnemyHUD
+ call WaitBGMap
+ jp RefreshBattleHuds
diff --git a/engine/battle/move_effects/sketch.asm b/engine/battle/move_effects/sketch.asm
new file mode 100644
index 000000000..4c15dbe02
--- /dev/null
+++ b/engine/battle/move_effects/sketch.asm
@@ -0,0 +1,117 @@
+BattleCommand_Sketch:
+; sketch
+
+ call ClearLastMove
+; Don't sketch during a link battle
+ ld a, [wLinkMode]
+ and a
+ jr z, .not_linked
+ call AnimateFailedMove
+ jp PrintNothingHappened
+
+.not_linked
+; If the opponent has a substitute up, fail.
+ call CheckSubstituteOpp
+ jp nz, .fail
+; If the opponent is transformed, fail.
+ ld a, BATTLE_VARS_SUBSTATUS5_OPP
+ call GetBattleVarAddr
+ bit SUBSTATUS_TRANSFORMED, [hl]
+ jp nz, .fail
+; Get the user's moveset in its party struct.
+; This move replacement shall be permanent.
+; Pointer will be in de.
+ ld a, MON_MOVES
+ call UserPartyAttr
+ ld d, h
+ ld e, l
+; Get the battle move structs.
+ ld hl, wBattleMonMoves
+ ld a, [hBattleTurn]
+ and a
+ jr z, .get_last_move
+ ld hl, wEnemyMonMoves
+.get_last_move
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ ld [wTypeMatchup], a
+ ld b, a
+; Fail if move is invalid or is Struggle.
+ and a
+ jr z, .fail
+ cp STRUGGLE
+ jr z, .fail
+; Fail if user already knows that move
+ ld c, NUM_MOVES
+.does_user_already_know_move
+ ld a, [hli]
+ cp b
+ jr z, .fail
+ dec c
+ jr nz, .does_user_already_know_move
+; Find Sketch in the user's moveset.
+; Pointer in hl, and index in c.
+ dec hl
+ ld c, NUM_MOVES
+.find_sketch
+ dec c
+ ld a, [hld]
+ cp SKETCH
+ jr nz, .find_sketch
+ inc hl
+; The Sketched move is loaded to that slot.
+ ld a, b
+ ld [hl], a
+; Copy the base PP from that move.
+ push bc
+ push hl
+ dec a
+ ld hl, Moves + MOVE_PP
+ call GetMoveAttr
+ pop hl
+ ld bc, wBattleMonPP - wBattleMonMoves
+ add hl, bc
+ ld [hl], a
+ pop bc
+
+ ld a, [hBattleTurn]
+ and a
+ jr z, .user_trainer
+ ld a, [wBattleMode]
+ dec a
+ jr nz, .user_trainer
+; wildmon
+ ld a, [hl]
+ push bc
+ ld hl, wWildMonPP
+ ld b, 0
+ add hl, bc
+ ld [hl], a
+ ld hl, wWildMonMoves
+ add hl, bc
+ pop bc
+ ld [hl], b
+ jr .done_copy
+
+.user_trainer
+ ld a, [hl]
+ push af
+ ld l, c
+ ld h, 0
+ add hl, de
+ ld a, b
+ ld [hl], a
+ pop af
+ ld de, MON_PP - MON_MOVES
+ add hl, de
+ ld [hl], a
+.done_copy
+ call GetMoveName
+ call AnimateCurrentMove
+
+ ld hl, SketchedText
+ jp StdBattleTextBox
+
+.fail
+ call AnimateFailedMove
+ jp PrintDidntAffect
diff --git a/engine/battle/move_effects/sleep_talk.asm b/engine/battle/move_effects/sleep_talk.asm
new file mode 100644
index 000000000..ae2d252b7
--- /dev/null
+++ b/engine/battle/move_effects/sleep_talk.asm
@@ -0,0 +1,143 @@
+BattleCommand_SleepTalk:
+; sleeptalk
+
+ call ClearLastMove
+ ld a, [wAttackMissed]
+ and a
+ jr nz, .fail
+ ld a, [hBattleTurn]
+ and a
+ ld hl, wBattleMonMoves + 1
+ ld a, [wDisabledMove]
+ ld d, a
+ jr z, .got_moves
+ ld hl, wEnemyMonMoves + 1
+ ld a, [wEnemyDisabledMove]
+ ld d, a
+.got_moves
+ ld a, BATTLE_VARS_STATUS
+ call GetBattleVar
+ and SLP
+ jr z, .fail
+ ld a, [hl]
+ and a
+ jr z, .fail
+ call .safely_check_has_usable_move
+ jr c, .fail
+ dec hl
+.sample_move
+ push hl
+ call BattleRandom
+ maskbits NUM_MOVES
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [hl]
+ pop hl
+ and a
+ jr z, .sample_move
+ ld e, a
+ ld a, BATTLE_VARS_MOVE_ANIM
+ call GetBattleVar
+ cp e
+ jr z, .sample_move
+ ld a, e
+ cp d
+ jr z, .sample_move
+ call .check_two_turn_move
+ jr z, .sample_move
+ ld a, BATTLE_VARS_MOVE
+ call GetBattleVarAddr
+ ld a, e
+ ld [hl], a
+ call CheckUserIsCharging
+ jr nz, .charging
+ ld a, [wKickCounter]
+ push af
+ call BattleCommand_LowerSub
+ pop af
+ ld [wKickCounter], a
+.charging
+ call LoadMoveAnim
+ call UpdateMoveData
+ jp ResetTurn
+
+.fail
+ call AnimateFailedMove
+ jp TryPrintButItFailed
+
+.safely_check_has_usable_move
+ push hl
+ push de
+ push bc
+ call .check_has_usable_move
+ pop bc
+ pop de
+ pop hl
+ ret
+
+.check_has_usable_move
+ ld a, [hBattleTurn]
+ and a
+ ld a, [wDisabledMove]
+ jr z, .got_move_2
+
+ ld a, [wEnemyDisabledMove]
+.got_move_2
+ ld b, a
+ ld a, BATTLE_VARS_MOVE
+ call GetBattleVar
+ ld c, a
+ dec hl
+ ld d, NUM_MOVES
+.loop2
+ ld a, [hl]
+ and a
+ jr z, .carry
+
+ cp c
+ jr z, .nope
+ cp b
+ jr z, .nope
+
+ call .check_two_turn_move
+ jr nz, .no_carry
+
+.nope
+ inc hl
+ dec d
+ jr nz, .loop2
+
+.carry
+ scf
+ ret
+
+.no_carry
+ and a
+ ret
+
+.check_two_turn_move
+ push hl
+ push de
+ push bc
+
+ ld b, a
+ callfar GetMoveEffect
+ ld a, b
+
+ pop bc
+ pop de
+ pop hl
+
+ cp EFFECT_SKULL_BASH
+ ret z
+ cp EFFECT_RAZOR_WIND
+ ret z
+ cp EFFECT_SKY_ATTACK
+ ret z
+ cp EFFECT_SOLARBEAM
+ ret z
+ cp EFFECT_FLY
+ ret z
+ cp EFFECT_BIDE
+ ret
diff --git a/engine/battle/move_effects/snore.asm b/engine/battle/move_effects/snore.asm
new file mode 100644
index 000000000..e2432c59f
--- /dev/null
+++ b/engine/battle/move_effects/snore.asm
@@ -0,0 +1,11 @@
+BattleCommand_Snore:
+; snore
+ ld a, BATTLE_VARS_STATUS
+ call GetBattleVar
+ and SLP
+ ret nz
+ call ResetDamage
+ ld a, $1
+ ld [wAttackMissed], a
+ call FailMove
+ jp EndMoveEffect
diff --git a/engine/battle/effect_commands/spikes.asm b/engine/battle/move_effects/spikes.asm
index a5e22a706..1eca7ae53 100644
--- a/engine/battle/effect_commands/spikes.asm
+++ b/engine/battle/move_effects/spikes.asm
@@ -1,4 +1,4 @@
-BattleCommand_Spikes: ; 37683
+BattleCommand_Spikes:
; spikes
ld hl, wEnemyScreens
@@ -23,5 +23,4 @@ BattleCommand_Spikes: ; 37683
jp StdBattleTextBox
.failed
- jp FailSpikes
-; 376a0
+ jp FailMove
diff --git a/engine/battle/move_effects/spite.asm b/engine/battle/move_effects/spite.asm
new file mode 100644
index 000000000..8aba187a4
--- /dev/null
+++ b/engine/battle/move_effects/spite.asm
@@ -0,0 +1,86 @@
+BattleCommand_Spite:
+; spite
+
+ ld a, [wAttackMissed]
+ and a
+ jp nz, .failed
+ ld bc, PARTYMON_STRUCT_LENGTH ; ????
+ ld hl, wEnemyMonMoves
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_moves
+ ld hl, wBattleMonMoves
+.got_moves
+ ld a, BATTLE_VARS_LAST_COUNTER_MOVE_OPP
+ call GetBattleVar
+ and a
+ jr z, .failed
+ cp STRUGGLE
+ jr z, .failed
+ ld b, a
+ ld c, -1
+.loop
+ inc c
+ ld a, [hli]
+ cp b
+ jr nz, .loop
+ ld [wTypeMatchup], a
+ dec hl
+ ld b, 0
+ push bc
+ ld c, wBattleMonPP - wBattleMonMoves
+ add hl, bc
+ pop bc
+ ld a, [hl]
+ and PP_MASK
+ jr z, .failed
+ push bc
+ call GetMoveName
+ ; lose 2-5 PP
+ call BattleRandom
+ and %11
+ inc a
+ inc a
+ ld b, a
+ ld a, [hl]
+ and PP_MASK
+ cp b
+ jr nc, .deplete_pp
+ ld b, a
+.deplete_pp
+ ld a, [hl]
+ sub b
+ ld [hl], a
+ push af
+ ld a, MON_PP
+ call OpponentPartyAttr
+ ld d, b
+ pop af
+ pop bc
+ add hl, bc
+ ld e, a
+ ld a, BATTLE_VARS_SUBSTATUS5_OPP
+ call GetBattleVar
+ bit SUBSTATUS_TRANSFORMED, a
+ jr nz, .transformed
+ ld a, [hBattleTurn]
+ and a
+ jr nz, .not_wildmon
+ ld a, [wBattleMode]
+ dec a
+ jr nz, .not_wildmon
+ ld hl, wWildMonPP
+ add hl, bc
+.not_wildmon
+ ld [hl], e
+.transformed
+ push de
+ call AnimateCurrentMove
+ pop de
+ ld a, d
+ ld [wTypeMatchup], a
+ ld hl, SpiteEffectText
+ jp StdBattleTextBox
+
+.failed
+ jp PrintDidntAffect2
diff --git a/engine/battle/move_effects/splash.asm b/engine/battle/move_effects/splash.asm
new file mode 100644
index 000000000..493ea8ca6
--- /dev/null
+++ b/engine/battle/move_effects/splash.asm
@@ -0,0 +1,4 @@
+BattleCommand_Splash:
+ call AnimateCurrentMove
+ farcall StubbedTrainerRankings_Splash
+ jp PrintNothingHappened
diff --git a/engine/battle/move_effects/substitute.asm b/engine/battle/move_effects/substitute.asm
new file mode 100644
index 000000000..8f14bc315
--- /dev/null
+++ b/engine/battle/move_effects/substitute.asm
@@ -0,0 +1,88 @@
+BattleCommand_Substitute:
+; substitute
+
+ call BattleCommand_MoveDelay
+ ld hl, wBattleMonMaxHP
+ ld de, wPlayerSubstituteHP
+ ld a, [hBattleTurn]
+ and a
+ jr z, .got_hp
+ ld hl, wEnemyMonMaxHP
+ ld de, wEnemySubstituteHP
+.got_hp
+
+ ld a, BATTLE_VARS_SUBSTATUS4
+ call GetBattleVar
+ bit SUBSTATUS_SUBSTITUTE, a
+ jr nz, .already_has_sub
+
+ ld a, [hli]
+ ld b, [hl]
+ srl a
+ rr b
+ srl a
+ rr b
+ dec hl
+ dec hl
+ ld a, b
+ ld [de], a
+ ld a, [hld]
+ sub b
+ ld e, a
+ ld a, [hl]
+ sbc 0
+ ld d, a
+ jr c, .too_weak_to_sub
+ ld a, d
+ or e
+ jr z, .too_weak_to_sub
+ ld [hl], d
+ inc hl
+ ld [hl], e
+
+ ld a, BATTLE_VARS_SUBSTATUS4
+ call GetBattleVarAddr
+ set SUBSTATUS_SUBSTITUTE, [hl]
+
+ ld hl, wPlayerWrapCount
+ ld de, wPlayerTrappingMove
+ ld a, [hBattleTurn]
+ and a
+ jr z, .player
+ ld hl, wEnemyWrapCount
+ ld de, wEnemyTrappingMove
+.player
+
+ xor a
+ ld [hl], a
+ ld [de], a
+ call _CheckBattleScene
+ jr c, .no_anim
+
+ xor a
+ ld [wNumHits], a
+ ld [wFXAnimID + 1], a
+ ld [wKickCounter], a
+ ld a, SUBSTITUTE
+ call LoadAnim
+ jr .finish
+
+.no_anim
+ call BattleCommand_RaiseSubNoAnim
+.finish
+ ld hl, MadeSubstituteText
+ call StdBattleTextBox
+ jp RefreshBattleHuds
+
+.already_has_sub
+ call CheckUserIsCharging
+ call nz, BattleCommand_RaiseSub
+ ld hl, HasSubstituteText
+ jr .jp_stdbattletextbox
+
+.too_weak_to_sub
+ call CheckUserIsCharging
+ call nz, BattleCommand_RaiseSub
+ ld hl, TooWeakSubText
+.jp_stdbattletextbox
+ jp StdBattleTextBox
diff --git a/engine/battle/move_effects/sunny_day.asm b/engine/battle/move_effects/sunny_day.asm
new file mode 100644
index 000000000..f5825930f
--- /dev/null
+++ b/engine/battle/move_effects/sunny_day.asm
@@ -0,0 +1,9 @@
+BattleCommand_StartSun:
+; startsun
+ ld a, WEATHER_SUN
+ ld [wBattleWeather], a
+ ld a, 5
+ ld [wWeatherCount], a
+ call AnimateCurrentMove
+ ld hl, SunGotBrightText
+ jp StdBattleTextBox
diff --git a/engine/battle/move_effects/teleport.asm b/engine/battle/move_effects/teleport.asm
new file mode 100644
index 000000000..1c67ef112
--- /dev/null
+++ b/engine/battle/move_effects/teleport.asm
@@ -0,0 +1,89 @@
+BattleCommand_Teleport:
+; teleport
+
+ ld a, [wBattleType]
+ cp BATTLETYPE_SHINY
+ jr z, .failed
+ cp BATTLETYPE_TRAP
+ jr z, .failed
+ cp BATTLETYPE_CELEBI
+ jr z, .failed
+ cp BATTLETYPE_SUICUNE
+ jr z, .failed
+
+ ld a, BATTLE_VARS_SUBSTATUS5_OPP
+ call GetBattleVar
+ bit SUBSTATUS_CANT_RUN, a
+ jr nz, .failed
+; Only need to check these next things if it's your turn
+ ld a, [hBattleTurn]
+ and a
+ jr nz, .enemy_turn
+; Can't teleport from a trainer battle
+ ld a, [wBattleMode]
+ dec a
+ jr nz, .failed
+; If your level is greater than the opponent's, you run without fail.
+ ld a, [wCurPartyLevel]
+ ld b, a
+ ld a, [wBattleMonLevel]
+ cp b
+ jr nc, .run_away
+; Generate a number between 0 and (YourLevel + TheirLevel).
+ add b
+ ld c, a
+ inc c
+.loop_player
+ call BattleRandom
+ cp c
+ jr nc, .loop_player
+; If that number is greater than 4 times your level, run away.
+ srl b
+ srl b
+ cp b
+ jr nc, .run_away
+
+.failed
+ call AnimateFailedMove
+ jp PrintButItFailed
+
+.enemy_turn
+ ld a, [wBattleMode]
+ dec a
+ jr nz, .failed
+ ld a, [wBattleMonLevel]
+ ld b, a
+ ld a, [wCurPartyLevel]
+ cp b
+ jr nc, .run_away
+ add b
+ ld c, a
+ inc c
+.loop_enemy
+ call BattleRandom
+ cp c
+ jr nc, .loop_enemy
+ srl b
+ srl b
+ cp b
+ ; This does the wrong thing. What was
+ ; probably intended was jr c, .failed
+ ; The way this is made makes enemy use
+ ; of Teleport always succeed if able
+ jr nc, .run_away
+.run_away
+ call UpdateBattleMonInParty
+ xor a
+ ld [wNumHits], a
+ inc a
+ ld [wForcedSwitch], a
+ ld [wKickCounter], a
+ call SetBattleDraw
+ call BattleCommand_LowerSub
+ call LoadMoveAnim
+ ld c, 20
+ call DelayFrames
+ call SetBattleDraw
+
+ ld hl, FledFromBattleText
+ jp StdBattleTextBox
diff --git a/engine/battle/effect_commands/thief.asm b/engine/battle/move_effects/thief.asm
index 5397c2bdf..64de1a4fe 100644
--- a/engine/battle/effect_commands/thief.asm
+++ b/engine/battle/move_effects/thief.asm
@@ -1,4 +1,4 @@
-BattleCommand_Thief: ; 37492
+BattleCommand_Thief:
; thief
ld a, [hBattleTurn]
@@ -50,7 +50,6 @@ BattleCommand_Thief: ; 37492
ld [de], a
jr .stole
-
.enemy
; The enemy can't already have an item.
@@ -91,13 +90,11 @@ BattleCommand_Thief: ; 37492
ld [hl], a
ld [de], a
-
.stole
call GetItemName
ld hl, StoleText
jp StdBattleTextBox
-
.playeritem
ld a, 1
call BattlePartyAttr
@@ -113,4 +110,3 @@ BattleCommand_Thief: ; 37492
ld e, l
ld hl, wEnemyMonItem
ret
-; 37517
diff --git a/engine/battle/move_effects/thunder.asm b/engine/battle/move_effects/thunder.asm
new file mode 100644
index 000000000..b2a643787
--- /dev/null
+++ b/engine/battle/move_effects/thunder.asm
@@ -0,0 +1,18 @@
+BattleCommand_ThunderAccuracy:
+; thunderaccuracy
+
+ ld a, BATTLE_VARS_MOVE_TYPE
+ call GetBattleVarAddr
+ inc hl
+ ld a, [wBattleWeather]
+ cp WEATHER_RAIN
+ jr z, .rain
+ cp WEATHER_SUN
+ ret nz
+ ld [hl], 50 percent + 1
+ ret
+
+.rain
+ ; Redundant with CheckHit guranteeing hit
+ ld [hl], 100 percent
+ ret
diff --git a/engine/battle/effect_commands/transform.asm b/engine/battle/move_effects/transform.asm
index 5ae7c1511..ef8071290 100755..100644
--- a/engine/battle/effect_commands/transform.asm
+++ b/engine/battle/move_effects/transform.asm
@@ -1,5 +1,5 @@
-BattleCommand_Transform: ; 371cd
+BattleCommand_Transform:
; transform
call ClearLastMove
@@ -137,5 +137,3 @@ BattleCommand_Transform: ; 371cd
call nz, LoadAnim
ld hl, TransformedText
jp StdBattleTextBox
-
-; 372c6
diff --git a/engine/battle/move_effects/triple_kick.asm b/engine/battle/move_effects/triple_kick.asm
new file mode 100644
index 000000000..e41044c9d
--- /dev/null
+++ b/engine/battle/move_effects/triple_kick.asm
@@ -0,0 +1,34 @@
+BattleCommand_TripleKick:
+; triplekick
+
+ ld a, [wKickCounter]
+ ld b, a
+ inc b
+ ld hl, wCurDamage + 1
+ ld a, [hld]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+.next_kick
+ dec b
+ ret z
+ ld a, [hl]
+ add e
+ ld [hld], a
+ ld a, [hl]
+ adc d
+ ld [hli], a
+
+; No overflow.
+ jr nc, .next_kick
+ ld a, $ff
+ ld [hld], a
+ ld [hl], a
+ ret
+
+BattleCommand_KickCounter:
+; kickcounter
+
+ ld hl, wKickCounter
+ inc [hl]
+ ret
diff --git a/engine/battle/read_trainer_attributes.asm b/engine/battle/read_trainer_attributes.asm
index 0b9507e0d..6db8f4204 100644
--- a/engine/battle/read_trainer_attributes.asm
+++ b/engine/battle/read_trainer_attributes.asm
@@ -1,4 +1,4 @@
-GetTrainerClassName: ; 3952d
+GetTrainerClassName:
ld hl, wRivalName
ld a, c
cp RIVAL1
@@ -19,7 +19,7 @@ GetTrainerClassName: ; 3952d
pop de
ret
-GetOTName: ; 39550
+GetOTName:
ld hl, wOTPlayerName
ld a, [wLinkMode]
and a
@@ -44,7 +44,7 @@ GetOTName: ; 39550
pop de
ret
-GetTrainerAttributes: ; 3957b
+GetTrainerAttributes:
ld a, [wTrainerClass]
ld c, a
call GetOTName
@@ -62,3 +62,5 @@ GetTrainerAttributes: ; 3957b
ld a, [hl]
ld [wEnemyTrainerBaseReward], a
ret
+
+INCLUDE "data/trainers/attributes.asm"
diff --git a/engine/battle/read_trainer_dvs.asm b/engine/battle/read_trainer_dvs.asm
index c021e8e8c..d35c9ea61 100644
--- a/engine/battle/read_trainer_dvs.asm
+++ b/engine/battle/read_trainer_dvs.asm
@@ -1,4 +1,4 @@
-GetTrainerDVs: ; 270c4
+GetTrainerDVs:
; Return the DVs of wOtherTrainerClass in bc
push hl
@@ -17,4 +17,5 @@ GetTrainerDVs: ; 270c4
pop hl
ret
-; 270d6
+
+INCLUDE "data/trainers/dvs.asm"
diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm
index 9f7a4a4a8..0a537b64e 100755..100644
--- a/engine/battle/read_trainer_party.asm
+++ b/engine/battle/read_trainer_party.asm
@@ -1,4 +1,4 @@
-ReadTrainerParty: ; 39771
+ReadTrainerParty:
ld a, [wInBattleTowerBattle]
bit 0, a
ret nz
@@ -44,7 +44,7 @@ ReadTrainerParty: ; 39771
jr z, .got_trainer
.loop
ld a, [hli]
- cp $ff
+ cp -1
jr nz, .loop
jr .skip_trainer
.got_trainer
@@ -79,16 +79,15 @@ ReadTrainerParty: ; 39771
call TrainerType2
call CloseSRAM
jr .done
-; 397e3
-TrainerTypes: ; 397e3
+TrainerTypes:
+; entries correspond to TRAINERTYPE_* constants
dw TrainerType1 ; level, species
dw TrainerType2 ; level, species, moves
dw TrainerType3 ; level, species, item
dw TrainerType4 ; level, species, item, moves
-; 397eb
-TrainerType1: ; 397eb
+TrainerType1:
; normal (level, species)
ld h, d
ld l, e
@@ -106,9 +105,8 @@ TrainerType1: ; 397eb
predef TryAddMonToParty
pop hl
jr .loop
-; 39806
-TrainerType2: ; 39806
+TrainerType2:
; moves
ld h, d
ld l, e
@@ -183,9 +181,8 @@ TrainerType2: ; 39806
pop hl
jr .loop
-; 39871
-TrainerType3: ; 39871
+TrainerType3:
; item
ld h, d
ld l, e
@@ -212,9 +209,8 @@ TrainerType3: ; 39871
ld a, [hli]
ld [de], a
jr .loop
-; 3989d (e:589d)
-TrainerType4: ; 3989d
+TrainerType4:
; item + moves
ld h, d
ld l, e
@@ -304,9 +300,8 @@ TrainerType4: ; 3989d
pop hl
jr .loop
-; 3991b
-ComputeTrainerReward: ; 3991b (e:591b)
+ComputeTrainerReward:
ld hl, hProduct
xor a
ld [hli], a
@@ -326,8 +321,7 @@ ComputeTrainerReward: ; 3991b (e:591b)
ld [hl], a
ret
-
-Battle_GetTrainerName:: ; 39939
+Battle_GetTrainerName::
ld a, [wInBattleTowerBattle]
bit 0, a
ld hl, wOTPlayerName
@@ -338,7 +332,7 @@ Battle_GetTrainerName:: ; 39939
ld a, [wOtherTrainerClass]
ld c, a
-GetTrainerName:: ; 3994c
+GetTrainerName::
ld a, c
cp CAL
jr nz, .not_cal2
@@ -378,20 +372,20 @@ GetTrainerName:: ; 3994c
jr nz, .skip
jr .loop
-CopyTrainerName: ; 39984
+CopyTrainerName:
ld de, wStringBuffer1
push de
ld bc, NAME_LENGTH
call CopyBytes
pop de
ret
-; 39990
-Function39990: ; 39990
+Function39990:
; This function is useless.
ld de, wStringBuffer1
push de
ld bc, NAME_LENGTH
pop de
ret
-; 39999
+
+INCLUDE "data/trainers/parties.asm"
diff --git a/engine/battle/returntobattle_useball.asm b/engine/battle/returntobattle_useball.asm
index b63881b2c..0aff780c9 100644
--- a/engine/battle/returntobattle_useball.asm
+++ b/engine/battle/returntobattle_useball.asm
@@ -1,4 +1,4 @@
-_ReturnToBattle_UseBall: ; 2715c
+_ReturnToBattle_UseBall:
call ClearBGPalettes
call ClearTileMap
ld a, [wBattleType]
@@ -14,6 +14,6 @@ _ReturnToBattle_UseBall: ; 2715c
farcall _LoadBattleFontsHPBar
call GetMemSGBLayout
call CloseWindow
- call LoadStandardMenuDataHeader
+ call LoadStandardMenuHeader
call WaitBGMap
jp SetPalettes
diff --git a/engine/battle/sliding_intro.asm b/engine/battle/sliding_intro.asm
index 667f18191..6b866c6d8 100755..100644
--- a/engine/battle/sliding_intro.asm
+++ b/engine/battle/sliding_intro.asm
@@ -1,4 +1,4 @@
-BattleIntroSlidingPics: ; 4e980
+BattleIntroSlidingPics:
ld a, [rSVBK]
push af
ld a, BANK(wLYOverrides)
@@ -12,9 +12,8 @@ BattleIntroSlidingPics: ; 4e980
pop af
ld [rSVBK], a
ret
-; 4e998
-.subfunction1 ; 4e998
+.subfunction1
call .subfunction4
ld a, $90
ld [hSCX], a
@@ -23,9 +22,8 @@ BattleIntroSlidingPics: ; 4e980
lb de, %11100100, %11100100
call DmgToCgbObjPals
ret
-; 4e9ab
-.subfunction2 ; 4e9ab
+.subfunction2
ld d, $90
ld e, $72
ld a, $48
@@ -57,9 +55,8 @@ BattleIntroSlidingPics: ; 4e980
dec a
jr nz, .loop1
ret
-; 4e9d6
-.subfunction3 ; 4e9d6
+.subfunction3
ld hl, wVirtualOAMSprite00XCoord
ld c, $12 ; 18
ld de, SPRITEOAMSTRUCT_LENGTH
@@ -70,17 +67,15 @@ BattleIntroSlidingPics: ; 4e980
dec c
jr nz, .loop3
ret
-; 4e9e5
-.subfunction4 ; 4e9e5
+.subfunction4
ld hl, wLYOverrides
ld a, $90
ld bc, SCREEN_HEIGHT_PX
call ByteFill
ret
-; 4e9f1
-.subfunction5 ; 4e9f1
+.subfunction5
ld hl, wLYOverrides
ld a, d
ld c, $3e ; 62
@@ -101,4 +96,3 @@ BattleIntroSlidingPics: ; 4e980
dec c
jr nz, .loop6
ret
-; 4ea0a
diff --git a/engine/battle/start_battle.asm b/engine/battle/start_battle.asm
index 84cd1e858..f5fc4a6b0 100644
--- a/engine/battle/start_battle.asm
+++ b/engine/battle/start_battle.asm
@@ -1,4 +1,4 @@
-ShowLinkBattleParticipants: ; 2ee18
+ShowLinkBattleParticipants:
; If we're not in a communications room,
; we don't need to be here.
ld a, [wLinkMode]
@@ -12,11 +12,11 @@ ShowLinkBattleParticipants: ; 2ee18
call ClearSprites
ret
-FindFirstAliveMonAndStartBattle: ; 2ee2f
+FindFirstAliveMonAndStartBattle:
xor a
ld [hMapAnims], a
call DelayFrame
- ld b, 6
+ ld b, PARTY_LENGTH
ld hl, wPartyMon1HP
ld de, PARTYMON_STRUCT_LENGTH - 1
@@ -46,7 +46,7 @@ FindFirstAliveMonAndStartBattle: ; 2ee2f
ld [hMapAnims], a
ret
-PlayBattleMusic: ; 2ee6c
+PlayBattleMusic:
push hl
push de
push bc
@@ -148,7 +148,7 @@ PlayBattleMusic: ; 2ee6c
pop hl
ret
-ClearBattleRAM: ; 2ef18
+ClearBattleRAM:
xor a
ld [wBattlePlayerAction], a
ld [wBattleResult], a
diff --git a/engine/battle/trainer_huds.asm b/engine/battle/trainer_huds.asm
index 0a18098ed..3930549b2 100755..100644
--- a/engine/battle/trainer_huds.asm
+++ b/engine/battle/trainer_huds.asm
@@ -1,4 +1,4 @@
-BattleStart_TrainerHuds: ; 2c000
+BattleStart_TrainerHuds:
ld a, $e4
ld [rOBP0], a
call LoadBallIconGFX
@@ -7,16 +7,14 @@ BattleStart_TrainerHuds: ; 2c000
dec a
ret z
jp ShowOTTrainerMonsRemaining
-; 2c012
-EnemySwitch_TrainerHud: ; 2c012
+EnemySwitch_TrainerHud:
ld a, $e4
ld [rOBP0], a
call LoadBallIconGFX
jp ShowOTTrainerMonsRemaining
-; 2c01c
-ShowPlayerMonsRemaining: ; 2c01c
+ShowPlayerMonsRemaining:
call DrawPlayerPartyIconHUDBorder
ld hl, wPartyMon1HP
ld de, wPartyCount
@@ -30,9 +28,8 @@ ShowPlayerMonsRemaining: ; 2c01c
ld [wPlaceBallsDirection], a
ld hl, wVirtualOAMSprite00
jp LoadTrainerHudOAM
-; 2c03a
-ShowOTTrainerMonsRemaining: ; 2c03a
+ShowOTTrainerMonsRemaining:
call DrawEnemyHUDBorder
ld hl, wOTPartyMon1HP
ld de, wOTPartyCount
@@ -46,9 +43,8 @@ ShowOTTrainerMonsRemaining: ; 2c03a
ld [wPlaceBallsDirection], a
ld hl, wVirtualOAMSprite00 + PARTY_LENGTH * SPRITEOAMSTRUCT_LENGTH
jp LoadTrainerHudOAM
-; 2c059
-StageBallTilesData: ; 2c059
+StageBallTilesData:
ld a, [de]
push af
ld de, wBuffer1
@@ -69,9 +65,8 @@ StageBallTilesData: ; 2c059
dec a
jr nz, .loop2
ret
-; 2c075
-.GetHUDTile: ; 2c075
+.GetHUDTile:
ld a, [hli]
and a
jr nz, .got_hp
@@ -102,9 +97,8 @@ StageBallTilesData: ; 2c059
ld bc, PARTYMON_STRUCT_LENGTH + MON_HP - MON_STATUS
add hl, bc
ret
-; 2c095
-DrawPlayerHUDBorder: ; 2c095
+DrawPlayerHUDBorder:
ld hl, .tiles
ld de, wTrainerHUDTiles
ld bc, 4
@@ -118,9 +112,8 @@ DrawPlayerHUDBorder: ; 2c095
db $77 ; bottom right
db $6f ; bottom left
db $76 ; bottom side
-; 2c0ad
-DrawPlayerPartyIconHUDBorder: ; 2c0ad
+DrawPlayerPartyIconHUDBorder:
ld hl, .tiles
ld de, wTrainerHUDTiles
ld bc, 4
@@ -134,9 +127,8 @@ DrawPlayerPartyIconHUDBorder: ; 2c0ad
db $5c ; bottom right
db $6f ; bottom left
db $76 ; bottom side
-; 2c0c5
-DrawEnemyHUDBorder: ; 2c0c5
+DrawEnemyHUDBorder:
ld hl, .tiles
ld de, wTrainerHUDTiles
ld bc, 4
@@ -160,9 +152,8 @@ DrawEnemyHUDBorder: ; 2c0c5
db $74 ; bottom left
db $78 ; bottom right
db $76 ; bottom side
-; 2c0f1
-PlaceHUDBorderTiles: ; 2c0f1
+PlaceHUDBorderTiles:
ld a, [wTrainerHUDTiles]
ld [hl], a
ld bc, SCREEN_WIDTH
@@ -180,9 +171,8 @@ PlaceHUDBorderTiles: ; 2c0f1
ld a, [wEndFlypoint]
ld [hl], a
ret
-; 2c10d
-LinkBattle_TrainerHuds: ; 2c10d
+LinkBattle_TrainerHuds:
call LoadBallIconGFX
ld hl, wPartyMon1HP
ld de, wPartyCount
@@ -205,9 +195,8 @@ LinkBattle_TrainerHuds: ; 2c10d
ld [hl], 13 * 8
ld hl, wVirtualOAMSprite00 + PARTY_LENGTH * SPRITEOAMSTRUCT_LENGTH
jp LoadTrainerHudOAM
-; 2c143
-LoadTrainerHudOAM: ; 2c143
+LoadTrainerHudOAM:
ld de, wBuffer1
ld c, PARTY_LENGTH
.loop
@@ -228,21 +217,18 @@ LoadTrainerHudOAM: ; 2c143
dec c
jr nz, .loop
ret
-; 2c165
-LoadBallIconGFX: ; 2c165
+LoadBallIconGFX:
ld de, .gfx
ld hl, vTiles0 tile $31
lb bc, BANK(LoadBallIconGFX), 4
call Get2bpp_2
ret
-; 2c172
-.gfx ; 2c172
+.gfx
INCBIN "gfx/battle/balls.2bpp"
-; 2c1b2
-_ShowLinkBattleParticipants: ; 2c1b2
+_ShowLinkBattleParticipants:
call ClearBGPalettes
call LoadFontsExtra
hlcoord 2, 3
@@ -266,4 +252,3 @@ _ShowLinkBattleParticipants: ; 2c1b2
ld a, $e4
ld [rOBP0], a
ret
-; 2c1ef
diff --git a/engine/battle/unreferenced_getgen1trainerclassname.asm b/engine/battle/unreferenced_getgen1trainerclassname.asm
new file mode 100644
index 000000000..045325234
--- /dev/null
+++ b/engine/battle/unreferenced_getgen1trainerclassname.asm
@@ -0,0 +1,21 @@
+Unreferenced_GetGen1TrainerClassName:
+ ld hl, Gen1TrainerClassNames
+ ld a, [wTrainerClass]
+ dec a
+ ld c, a
+ ld b, 0
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, wStringBuffer1
+.copy
+ ld a, [hli]
+ ld [de], a
+ inc de
+ cp "@"
+ jr nz, .copy
+ ret
+
+INCLUDE "data/text/unused_gen1_trainer_names.asm"
diff --git a/engine/battle/updatebattlehuds.asm b/engine/battle/update_battle_huds.asm
index 0c31f1c36..0c31f1c36 100644
--- a/engine/battle/updatebattlehuds.asm
+++ b/engine/battle/update_battle_huds.asm
diff --git a/engine/battle/used_move_text.asm b/engine/battle/used_move_text.asm
index bab0ea834..9307a1a1e 100755..100644
--- a/engine/battle/used_move_text.asm
+++ b/engine/battle/used_move_text.asm
@@ -1,11 +1,10 @@
-DisplayUsedMoveText: ; 105db0
+DisplayUsedMoveText:
; battle command 03
ld hl, UsedMoveText
call BattleTextBox
jp WaitBGMap
-; 105db9
-UsedMoveText: ; 105db9
+UsedMoveText:
; this is a stream of text and asm from 105db9 to 105ef6
text_jump _ActorNameText
start_asm
@@ -58,18 +57,16 @@ UsedMoveText: ; 105db9
ret c
ld hl, UsedMove1Text
ret
-; 105e04
-UsedMove1Text: ; 105e04
+UsedMove1Text:
text_jump _UsedMove1Text
start_asm
jr UsedMoveText_CheckObedience
-; 105e0b
-UsedMove2Text: ; 105e0b
+UsedMove2Text:
text_jump _UsedMove2Text
start_asm
-UsedMoveText_CheckObedience: ; 105e10
+UsedMoveText_CheckObedience:
; check obedience
ld a, [wAlreadyDisobeyed]
and a
@@ -77,7 +74,6 @@ UsedMoveText_CheckObedience: ; 105e10
; print "instead,"
ld hl, .UsedInsteadText
ret
-; 105e1a
.UsedInsteadText:
text_jump _UsedInsteadText
@@ -85,9 +81,8 @@ UsedMoveText_CheckObedience: ; 105e10
.GetMoveNameText:
ld hl, MoveNameText
ret
-; 105e23
-MoveNameText: ; 105e23
+MoveNameText:
text_jump _MoveNameText
start_asm
; get start address
@@ -111,39 +106,32 @@ MoveNameText: ; 105e23
ld h, [hl]
ld l, a
ret
-; 105e39
-.endusedmovetexts ; 105e39
+.endusedmovetexts
+; entries correspond to MoveGrammar sets
dw EndUsedMove1Text
dw EndUsedMove2Text
dw EndUsedMove3Text
dw EndUsedMove4Text
dw EndUsedMove5Text
-; 105e43
-EndUsedMove1Text: ; 105e43
+EndUsedMove1Text:
text_jump _EndUsedMove1Text
db "@"
-; 105e48
-EndUsedMove2Text: ; 105e48
+EndUsedMove2Text:
text_jump _EndUsedMove2Text
db "@"
-; 105e4d
-EndUsedMove3Text: ; 105e4d
+EndUsedMove3Text:
text_jump _EndUsedMove3Text
db "@"
-; 105e52
-EndUsedMove4Text: ; 105e52
+EndUsedMove4Text:
text_jump _EndUsedMove4Text
db "@"
-; 105e57
-EndUsedMove5Text: ; 105e57
+EndUsedMove5Text:
text_jump _EndUsedMove5Text
db "@"
-; 105e5c
-
-GetMoveGrammar: ; 105e5c
+GetMoveGrammar:
; store move grammar type in wd265
push bc
@@ -177,12 +165,10 @@ GetMoveGrammar: ; 105e5c
; we're done
pop bc
ret
-; 105e7a
INCLUDE "data/moves/grammar.asm"
-
-UpdateUsedMoves: ; 105ed0
+UpdateUsedMoves:
; append move a to wPlayerUsedMoves unless it has already been used
push bc
@@ -236,4 +222,3 @@ UpdateUsedMoves: ; 105ed0
; list updated
pop bc
ret
-; 105ef6