ref: b2dc57576d13ebf4dfa35b0132b003d2cfe4d39e
parent: c2efe700ac1c5cca88bac710b98388a99665741e
author: xCrystal <rgr.crystal@gmail.com>
date: Wed Apr 8 08:15:08 EDT 2015
Document move effects Document mist effect Document recoil effect Document heal effect Update conversion_effect.asm Update haze_effect.asm Update leech_seed_effect.asm Update pay_day_effect.asm Update reflect_light_screen_effect.asm Update substitute_effect.asm Update transform_effect.asm
--- a/engine/battle/moveEffects/conversion_effect.asm
+++ b/engine/battle/moveEffects/conversion_effect.asm
@@ -4,15 +4,16 @@
ld a, [H_WHOSETURN]
and a
ld a, [W_ENEMYBATTSTATUS1]
- jr z, .asm_139b8
+ jr z, .conversionEffect
push hl
ld h, d
ld l, e
pop de
ld a, [W_PLAYERBATTSTATUS1]
-.asm_139b8
+.conversionEffect
bit Invulnerable, a ; is mon immune to typical attacks (dig/fly)
jr nz, PrintButItFailedText
+; copy target's types to user
ld a, [hli]
ld [de], a
inc de
--- a/engine/battle/moveEffects/haze_effect.asm
+++ b/engine/battle/moveEffects/haze_effect.asm
@@ -1,9 +1,11 @@
HazeEffect_: ; 139da (4:79da)
ld a, $7
+; store 7 on every stat mod
ld hl, wPlayerMonAttackMod
call ResetStatMods
ld hl, wEnemyMonAttackMod
call ResetStatMods
+; copy unmodified stats to battle stats
ld hl, wPlayerMonUnmodifiedAttack
ld de, wBattleMonAttack
call ResetStats
@@ -14,19 +16,20 @@
ld de, wEnemySelectedMove
ld a, [H_WHOSETURN]
and a
- jr z, .asm_13a09
+ jr z, .cureStatuses
ld hl, wBattleMonStatus
- dec de
+ dec de ; wPlayerSelectedMove
-.asm_13a09
+.cureStatuses
ld a, [hl]
ld [hl], $0
- and $27
- jr z, .asm_13a13
+ and SLP | (1 << FRZ)
+ jr z, .cureVolatileStatuses
+; prevent the Pokemon from executing a move if it was asleep or frozen
ld a, $ff
ld [de], a
-.asm_13a13
+.cureVolatileStatuses
xor a
ld [W_PLAYERDISABLEDMOVE], a
ld [W_ENEMYDISABLEDMOVE], a
@@ -34,19 +37,21 @@
ld [hli], a
ld [hl], a
ld hl, W_PLAYERBATTSTATUS1
- call CureStatuses
+ call CureVolatileStatuses
ld hl, W_ENEMYBATTSTATUS1
- call CureStatuses
+ call CureVolatileStatuses
ld hl, PlayCurrentMoveAnimation
call CallBankF
ld hl, StatusChangesEliminatedText
jp PrintText
-CureStatuses: ; 13a37 (4:7a37)
+CureVolatileStatuses: ; 13a37 (4:7a37)
+; only cures statuses of the Pokemon not using Haze
res Confused, [hl]
inc hl ; BATTSTATUS2
ld a, [hl]
- and (1 << UsingRage) | (1 << NeedsToRecharge) | (1 << HasSubstituteUp) | (1 << 3) ; clear all but these from BATTSTATUS2
+ ; clear UsingXAccuracy, ProtectedByMist, GettingPumped, and Seeded statuses
+ and (1 << UsingRage) | (1 << NeedsToRecharge) | (1 << HasSubstituteUp) | (1 << 3)
ld [hli], a ; BATTSTATUS3
ld a, [hl]
and %11110000 | (1 << Transformed) ; clear Bad Poison, Reflect and Light Screen statuses
@@ -56,7 +61,7 @@
ResetStatMods: ; 13a43 (4:7a43)
ld b, $8
.loop
- ld [hli], a
+ ld [hli], a
dec b
jr nz, .loop
ret
--- a/engine/battle/moveEffects/heal_effect.asm
+++ b/engine/battle/moveEffects/heal_effect.asm
@@ -4,22 +4,23 @@
ld de, wBattleMonHP
ld hl, wBattleMonMaxHP
ld a, [W_PLAYERMOVENUM]
- jr z, .asm_3ba03
+ jr z, .healEffect
ld de, wEnemyMonHP
ld hl, wEnemyMonMaxHP
ld a, [W_ENEMYMOVENUM]
-.asm_3ba03
+.healEffect
ld b, a
ld a, [de]
- cp [hl]
+ cp [hl] ; most significant bytes comparison is ignored
+ ; causes the move to miss if max HP is 255 or 511 points higher than the current HP
inc de
inc hl
ld a, [de]
sbc [hl]
- jp z, .failed
+ jp z, .failed ; no effect if user's HP is already at its maximum
ld a, b
cp REST
- jr nz, .asm_3ba37
+ jr nz, .healHP
push hl
push de
push af
@@ -28,21 +29,21 @@
ld hl, wBattleMonStatus
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3ba25
+ jr z, .restEffect
ld hl, wEnemyMonStatus
-.asm_3ba25
+.restEffect
ld a, [hl]
and a
- ld [hl], 2 ; Number of turns from Rest
- ld hl, StartedSleepingEffect
- jr z, .asm_3ba31
- ld hl, FellAsleepBecameHealthyText
-.asm_3ba31
+ ld [hl], 2 ; clear status and set number of turns asleep to 2
+ ld hl, StartedSleepingEffect ; if mon didn't have an status
+ jr z, .printRestText
+ ld hl, FellAsleepBecameHealthyText ; if mon had an status
+.printRestText
call PrintText
pop af
pop de
pop hl
-.asm_3ba37
+.healHP
ld a, [hld]
ld [wHPBarMaxHP], a
ld c, a
@@ -49,10 +50,12 @@
ld a, [hl]
ld [wHPBarMaxHP+1], a
ld b, a
- jr z, .asm_3ba47
+ jr z, .gotHPAmountToHeal
+; Recover and Softboiled only heal for half the mon's max HP
srl b
rr c
-.asm_3ba47
+.gotHPAmountToHeal
+; update HP
ld a, [de]
ld [wHPBarOldHP], a
add c
@@ -72,7 +75,8 @@
dec hl
ld a, [de]
sbc [hl]
- jr c, .asm_3ba6f
+ jr c, .playAnim
+; copy max HP to current HP if an overflow ocurred
ld a, [hli]
ld [de], a
ld [wHPBarNewHP+1], a
@@ -80,7 +84,7 @@
ld a, [hl]
ld [de], a
ld [wHPBarNewHP], a
-.asm_3ba6f
+.playAnim
ld hl, PlayCurrentMoveAnimation
call BankswitchEtoF
ld a, [H_WHOSETURN]
@@ -87,10 +91,10 @@
and a
hlCoord 10, 9
ld a, $1
- jr z, .asm_3ba83
+ jr z, .updateHPBar
hlCoord 2, 2
xor a
-.asm_3ba83
+.updateHPBar
ld [wHPBarType], a
predef UpdateHPBar2
ld hl, DrawHUDsAndHPBars
--- a/engine/battle/moveEffects/leech_seed_effect.asm
+++ b/engine/battle/moveEffects/leech_seed_effect.asm
@@ -1,30 +1,31 @@
LeechSeedEffect_: ; 2bea9 (a:7ea9)
callab MoveHitTest
- ld a, [W_MOVEMISSED] ; W_MOVEMISSED
+ ld a, [W_MOVEMISSED]
and a
- jr nz, .asm_2bee7
- ld hl, W_ENEMYBATTSTATUS2 ; W_ENEMYBATTSTATUS2
- ld de, wEnemyMonType1 ; wcfea (aliases: wEnemyMonType)
- ld a, [H_WHOSETURN] ; $fff3
+ jr nz, .moveMissed
+ ld hl, W_ENEMYBATTSTATUS2
+ ld de, wEnemyMonType1
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_2bec8
- ld hl, W_PLAYERBATTSTATUS2 ; W_PLAYERBATTSTATUS2
- ld de, wBattleMonType1 ; wd019 (aliases: wBattleMonType)
-.asm_2bec8
+ jr z, .leechSeedEffect
+ ld hl, W_PLAYERBATTSTATUS2
+ ld de, wBattleMonType1
+.leechSeedEffect
+; miss if the target is grass-type or already seeded
ld a, [de]
cp GRASS
- jr z, .asm_2bee7
+ jr z, .moveMissed
inc de
ld a, [de]
cp GRASS
- jr z, .asm_2bee7
+ jr z, .moveMissed
bit Seeded, [hl]
- jr nz, .asm_2bee7
+ jr nz, .moveMissed
set Seeded, [hl]
callab PlayCurrentMoveAnimation
ld hl, WasSeededText ; $7ef2
jp PrintText
-.asm_2bee7
+.moveMissed
ld c, $32
call DelayFrames
ld hl, EvadedAttackText ; $7ef7
--- a/engine/battle/moveEffects/mist_effect.asm
+++ b/engine/battle/moveEffects/mist_effect.asm
@@ -1,17 +1,17 @@
MistEffect_: ; 33f2b (c:7f2b)
ld hl, W_PLAYERBATTSTATUS2
- ld a, [$fff3]
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_33f36
+ jr z, .mistEffect
ld hl, W_ENEMYBATTSTATUS2
-.asm_33f36
+.mistEffect
bit ProtectedByMist, [hl] ; is mon protected by mist?
- jr nz, .asm_33f4a
+ jr nz, .mistAlreadyInUse
set ProtectedByMist, [hl] ; mon is now protected by mist
callab PlayCurrentMoveAnimation
ld hl, ShroudedInMistText
jp PrintText
-.asm_33f4a
+.mistAlreadyInUse
ld hl, PrintButItFailedText_
ld b, BANK(PrintButItFailedText_)
jp Bankswitch
--- a/engine/battle/moveEffects/one_hit_ko_effect.asm
+++ b/engine/battle/moveEffects/one_hit_ko_effect.asm
@@ -7,12 +7,13 @@
ld [wCriticalHitOrOHKO], a
ld hl, wBattleMonSpeed + 1
ld de, wEnemyMonSpeed + 1
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_33f72
+ jr z, .compareSpeed
ld hl, wEnemyMonSpeed + 1
ld de, wBattleMonSpeed + 1
-.asm_33f72
+.compareSpeed
+; set damage to 65535 and OHKO flag is the user's current speed is higher than the target's
ld a, [de]
dec de
ld b, a
@@ -22,7 +23,7 @@
ld b, a
ld a, [hl]
sbc b
- jr c, .asm_33f8a
+ jr c, .userIsSlower
ld hl, W_DAMAGE
ld a, $ff
ld [hli], a
@@ -30,7 +31,8 @@
ld a, $2
ld [wCriticalHitOrOHKO], a
ret
-.asm_33f8a
+.userIsSlower
+; keep damage at 0 and set move missed flag if target's current speed is higher instead
ld a, $1
ld [W_MOVEMISSED], a
ret
--- a/engine/battle/moveEffects/pay_day_effect.asm
+++ b/engine/battle/moveEffects/pay_day_effect.asm
@@ -5,24 +5,26 @@
ld a, [H_WHOSETURN]
and a
ld a, [wBattleMonLevel]
- jr z, .asm_2fec8
+ jr z, .payDayEffect
ld a, [wEnemyMonLevel]
-.asm_2fec8
- add a
+.payDayEffect
+; level * 2
+ add a
ld [H_DIVIDEND + 3], a
xor a
ld [H_DIVIDEND], a
ld [H_DIVIDEND + 1], a
ld [H_DIVIDEND + 2], a
- ld a, $64
+; convert to BCD
+ ld a, 100
ld [H_DIVISOR], a
ld b, $4
call Divide
ld a, [H_QUOTIENT + 3]
- ld [hli], a
+ ld [hli], a
ld a, [H_REMAINDER]
ld [H_DIVIDEND + 3], a
- ld a, $a
+ ld a, 10
ld [H_DIVISOR], a
ld b, $4
call Divide
--- a/engine/battle/moveEffects/recoil_effect.asm
+++ b/engine/battle/moveEffects/recoil_effect.asm
@@ -3,10 +3,10 @@
and a
ld a, [W_PLAYERMOVENUM]
ld hl, wBattleMonMaxHP
- jr z, .asm_1393d
+ jr z, .recoilEffect
ld a, [W_ENEMYMOVENUM]
ld hl, wEnemyMonMaxHP
-.asm_1393d
+.recoilEffect
ld d, a
ld a, [W_DAMAGE]
ld b, a
@@ -15,22 +15,23 @@
srl b
rr c
ld a, d
- cp STRUGGLE
- jr z, .asm_13953
+ cp STRUGGLE ; struggle deals 50% recoil damage
+ jr z, .gotRecoilDamage
srl b
rr c
-.asm_13953
+.gotRecoilDamage
ld a, b
or c
- jr nz, .asm_13958
- inc c
-.asm_13958
+ jr nz, .updateHP
+ inc c ; minimum recoil damage is 1
+.updateHP
+; substract HP from user due to the recoil damage
ld a, [hli]
ld [wHPBarMaxHP+1], a
ld a, [hl]
ld [wHPBarMaxHP], a
push bc
- ld bc, $fff2
+ ld bc, wBattleMonHP - wBattleMonMaxHP
add hl, bc
pop bc
ld a, [hl]
@@ -43,22 +44,23 @@
sbc b
ld [hl], a
ld [wHPBarNewHP+1], a
- jr nc, .asm_13982
- xor a
+ jr nc, .getHPBarCoords
+; if recoil damage is higher than the Pokemon's HP, set its HP to 0
+ xor a
ld [hli], a
ld [hl], a
ld hl, wHPBarNewHP
ld [hli], a
ld [hl], a
-.asm_13982
+.getHPBarCoords
hlCoord 10, 9
ld a, [H_WHOSETURN]
and a
ld a, $1
- jr z, .asm_13990
+ jr z, .updateHPBar
hlCoord 2, 2
xor a
-.asm_13990
+.updateHPBar
ld [wHPBarType], a
predef UpdateHPBar2
ld hl, HitWithRecoilText
--- a/engine/battle/moveEffects/reflect_light_screen_effect.asm
+++ b/engine/battle/moveEffects/reflect_light_screen_effect.asm
@@ -3,10 +3,10 @@
ld de, W_PLAYERMOVEEFFECT
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3bba8
+ jr z, .reflectLightScreenEffect
ld hl, W_ENEMYBATTSTATUS3
ld de, W_ENEMYMOVEEFFECT
-.asm_3bba8
+.reflectLightScreenEffect
ld a, [de]
cp LIGHT_SCREEN_EFFECT
jr nz, .reflect
@@ -14,13 +14,13 @@
jr nz, .moveFailed
set HasLightScreenUp, [hl] ; mon is now protected by light screen
ld hl, LightScreenProtectedText
- jr .asm_3bbc1
+ jr .playAnim
.reflect
bit HasReflectUp, [hl] ; is mon already protected by reflect?
jr nz, .moveFailed
set HasReflectUp, [hl] ; mon is now protected by reflect
ld hl, ReflectGainedArmorText
-.asm_3bbc1
+.playAnim
push hl
ld hl, PlayCurrentMoveAnimation
call BankswitchEtoF
--- a/engine/battle/moveEffects/substitute_effect.asm
+++ b/engine/battle/moveEffects/substitute_effect.asm
@@ -11,46 +11,48 @@
ld de, wEnemySubstituteHP
ld bc, W_ENEMYBATTSTATUS2
.notEnemy
- ld a, [bc] ;load flags
- bit HasSubstituteUp, a ;user already has substitute?
- jr nz, .alreadyHasSubstitute ;skip this code if so
- ;user doesn't have a substitute [yet]
+ ld a, [bc]
+ bit HasSubstituteUp, a ; user already has substitute?
+ jr nz, .alreadyHasSubstitute
+; quarter health to remove from user
+; assumes max HP is 1023 or lower
push bc
- ld a, [hli] ;load max hp
+ ld a, [hli]
ld b, [hl]
- srl a ;max hp / 4, [quarter health to remove from user]
+ srl a
rr b
srl a
- rr b
+ rr b ; max hp / 4
push de
ld de, wBattleMonHP - wBattleMonMaxHP
- add hl, de ; point hl to current HP
+ add hl, de ; point hl to current HP low byte
pop de
- ld a, b
- ld [de], a ;save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has]
- ld a, [hld] ;load current hp
- sub b ;subtract [max hp / 4]
- ld d, a ;save low byte result in D
+ ld a, b
+ ld [de], a ; save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has]
+ ld a, [hld]
+; subtract [max hp / 4] to current HP
+ sub b
+ ld d, a
ld a, [hl]
- sbc a, 0 ;borrow from high byte if needed
+ sbc 0
pop bc
- jr c, .notEnoughHP ;underflow means user would be left with negative health
- ;bug: note since it only brances on carry, it will possibly leave user with 0HP
+ jr c, .notEnoughHP ; underflow means user would be left with negative health
+ ; bug: since it only brances on carry, it will possibly leave user with 0 HP
.userHasZeroOrMoreHP
- ldi [hl], a ;store high byte HP
- ld [hl], d ;store low byte HP
+ ldi [hl], a ; save resulting HP after substraction into current HP
+ ld [hl], d
ld h, b
ld l, c
- set HasSubstituteUp, [hl] ;set bit 4 of flags, user now has substitute
- ld a, [W_OPTIONS] ;load options
- bit 7, a ;battle animation is enabled?
- ld hl, PlayCurrentMoveAnimation ;animation enabled: 0F:7BA8
+ set HasSubstituteUp, [hl]
+ ld a, [W_OPTIONS]
+ bit 7, a ; battle animation is enabled?
+ ld hl, PlayCurrentMoveAnimation
ld b, BANK(PlayCurrentMoveAnimation)
jr z, .animationEnabled
- ld hl, AnimationSubstitute ;animation disabled: 1E:56E0
+ ld hl, AnimationSubstitute
ld b, BANK(AnimationSubstitute)
.animationEnabled
- call Bankswitch ;jump to routine depending on animation setting
+ call Bankswitch ; jump to routine depending on animation setting
ld hl, SubstituteText
call PrintText
ld hl, DrawHUDsAndHPBars
--- a/engine/battle/moveEffects/transform_effect.asm
+++ b/engine/battle/moveEffects/transform_effect.asm
@@ -5,13 +5,13 @@
ld a, [W_ENEMYBATTSTATUS1]
ld a, [H_WHOSETURN]
and a
- jr nz, .asm_3bad1
+ jr nz, .hitTest
ld hl, wEnemyMonSpecies
ld de, wBattleMonSpecies
ld bc, W_PLAYERBATTSTATUS3
ld [wPlayerMoveListIndex], a
ld a, [W_PLAYERBATTSTATUS1]
-.asm_3bad1
+.hitTest
bit Invulnerable, a ; is mon invulnerable to typical attacks? (fly/dig)
jp nz, .failed
push hl
@@ -20,10 +20,11 @@
ld hl, W_PLAYERBATTSTATUS2
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3bae4
+ jr z, .transformEffect
ld hl, W_ENEMYBATTSTATUS2
-.asm_3bae4
- bit HasSubstituteUp, [hl]
+.transformEffect
+; animation(s) played are different if target has Substitute up
+ bit HasSubstituteUp, [hl]
push af
ld hl, Func_79747
ld b, BANK(Func_79747)
@@ -32,10 +33,10 @@
add a
ld hl, PlayCurrentMoveAnimation
ld b, BANK(PlayCurrentMoveAnimation)
- jr nc, .asm_3baff
+ jr nc, .gotAnimToPlay
ld hl, AnimationTransformMon
ld b, BANK(AnimationTransformMon)
-.asm_3baff
+.gotAnimToPlay
call Bankswitch
ld hl, Func_79771
ld b, BANK(Func_79771)
@@ -43,15 +44,18 @@
call nz, Bankswitch
pop bc
ld a, [bc]
- set Transformed, a
+ set Transformed, a ; mon is now Transformed
ld [bc], a
pop de
pop hl
push hl
- ld a, [hl]
+; transform user into opposing Pokemon
+; species
+ ld a, [hl]
ld [de], a
+; type 1, type 2, catch rate, and moves
ld bc, $5
- add hl, bc
+ add hl, bc
inc de
inc de
inc de
@@ -62,7 +66,8 @@
call CopyData
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3bb32
+ jr z, .next
+; save enemy mon DVs in wcceb/wccec (enemy turn only)
ld a, [de]
ld [wcceb], a
inc de
@@ -69,7 +74,8 @@
ld a, [de]
ld [wccec], a
dec de
-.asm_3bb32
+.next
+; DVs
ld a, [hli]
ld [de], a
inc de
@@ -76,6 +82,7 @@
ld a, [hli]
ld [de], a
inc de
+; Attack, Defense, Speed, and Special stats
inc hl
inc hl
inc hl
@@ -84,26 +91,29 @@
inc de
ld bc, $8
call CopyData
- ld bc, $ffef
- add hl, bc
- ld b, $4
-.asm_3bb4a
+ ld bc, wBattleMonMoves - wBattleMonPP
+ add hl, bc ; ld hl, wBattleMonMoves
+ ld b, NUM_MOVES
+.copyPPLoop
+; 5 PP for all moves
ld a, [hli]
and a
- jr z, .asm_3bb57
+ jr z, .lessThanFourMoves
ld a, $5
ld [de], a
inc de
dec b
- jr nz, .asm_3bb4a
- jr .asm_3bb5d
-.asm_3bb57
+ jr nz, .copyPPLoop
+ jr .copyStats
+.lessThanFourMoves
+; 0 PP for blank moves
xor a
ld [de], a
inc de
dec b
- jr nz, .asm_3bb57
-.asm_3bb5d
+ jr nz, .lessThanFourMoves
+.copyStats
+; original (unmodified) stats and stat mods
pop hl
ld a, [hl]
ld [wd11e], a
@@ -110,10 +120,10 @@
call GetMonName
ld hl, wEnemyMonUnmodifiedAttack
ld de, wPlayerMonUnmodifiedAttack
- call .copyBasedOnTurn
+ call .copyBasedOnTurn ; original (unmodified) stats
ld hl, wEnemyMonStatMods
ld de, wPlayerMonStatMods
- call .copyBasedOnTurn
+ call .copyBasedOnTurn ; stat mods
ld hl, TransformedText
jp PrintText
@@ -120,12 +130,12 @@
.copyBasedOnTurn
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3bb86
+ jr z, .gotStatsOrModsToCopy
push hl
ld h, d
ld l, e
pop de
-.asm_3bb86
+.gotStatsOrModsToCopy
ld bc, $8
jp CopyData