From e1da37e03303b1a6dd6531d8a044339f337731a1 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Wed, 4 Apr 2018 22:35:47 +0200 Subject: Comment SapHealth Also fixed some Beat Up inconsistencies to make it more readable. --- engine/battle/effect_commands.asm | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'engine/battle/effect_commands.asm') diff --git a/engine/battle/effect_commands.asm b/engine/battle/effect_commands.asm index 376624e44..9e304df72 100644 --- a/engine/battle/effect_commands.asm +++ b/engine/battle/effect_commands.asm @@ -4136,6 +4136,7 @@ BattleCommand_EatDream: ; 36008 SapHealth: ; 36011 + ; Divide damage by 2, store it in hDividend ld hl, wCurDamage ld a, [hli] srl a @@ -4145,10 +4146,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] @@ -4157,12 +4159,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 @@ -4170,6 +4176,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 @@ -4180,7 +4188,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] @@ -4191,8 +4201,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 @@ -4201,7 +4213,8 @@ SapHealth: ; 36011 ld [hli], a ld [wBuffer6], a inc de -.okay3 + +.finish ld a, [hBattleTurn] and a hlcoord 10, 9 -- cgit v1.2.3 From 682ca7e93c635b21b7ac3db709ba6296c53fa080 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Thu, 29 Mar 2018 10:57:55 +0200 Subject: Label bidefailtext This "unknown" battle command is actually used to give the proper fail message to bide. --- engine/battle/effect_commands.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engine/battle/effect_commands.asm') diff --git a/engine/battle/effect_commands.asm b/engine/battle/effect_commands.asm index 9e304df72..9433c33b4 100644 --- a/engine/battle/effect_commands.asm +++ b/engine/battle/effect_commands.asm @@ -2437,7 +2437,7 @@ FailText_CheckOpponentProtect: ; 35157 ; 35165 -BattleCommanda5: ; 35165 +BattleCommand_BideFailText: ; 35165 ld a, [wAttackMissed] and a ret z -- cgit v1.2.3 From c1e3d17769aa3088556dcd1142944541f7f6fd0e Mon Sep 17 00:00:00 2001 From: mid-kid Date: Tue, 3 Apr 2018 01:05:44 +0200 Subject: `endloop` loops back to critical itself The comments seemed to specify that `endloop` loops back to the command before `critical` and executes that, which simply isn't true. It loops back to `critical` itself, and executes `critical`, before continuing on with the remaining commands. --- engine/battle/effect_commands.asm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engine/battle/effect_commands.asm') diff --git a/engine/battle/effect_commands.asm b/engine/battle/effect_commands.asm index 9433c33b4..16b3cea9a 100644 --- a/engine/battle/effect_commands.asm +++ b/engine/battle/effect_commands.asm @@ -5651,7 +5651,7 @@ CheckPlayerHasMonToSwitchTo: ; 36994 BattleCommand_EndLoop: ; 369b6 ; endloop -; Loop back to the command before 'critical'. +; Loop back to 'critical'. ld de, wPlayerRolloutCount ld bc, wPlayerDamageTaken @@ -5766,7 +5766,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 -- cgit v1.2.3 From 800f9489145dc7c82edb3fa86fc24a5ff7411533 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Tue, 3 Apr 2018 12:00:24 +0200 Subject: Label BattleCommand_BeatUpFailText --- engine/battle/effect_commands.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engine/battle/effect_commands.asm') diff --git a/engine/battle/effect_commands.asm b/engine/battle/effect_commands.asm index 16b3cea9a..b9a7382c0 100644 --- a/engine/battle/effect_commands.asm +++ b/engine/battle/effect_commands.asm @@ -5714,7 +5714,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 -- cgit v1.2.3 From d4025863cf56466b79827bace6d6b3e48ffd05e9 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Wed, 4 Apr 2018 23:27:40 +0200 Subject: Rename some battle commands `hittarget` was misleading, as it doesn't actually "hit" the target, it only plays the animation. As such, I've renamed it to `moveanim`. `checkfaint` has nothing to do with checking if the user or target has fainted, instead, it applies wCurDamage onto the target's HP, hitting the substitute if applicable. I've renamed the command to `applydamage` and all of its subfunctions accordingly. --- engine/battle/effect_commands.asm | 118 ++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 57 deletions(-) (limited to 'engine/battle/effect_commands.asm') diff --git a/engine/battle/effect_commands.asm b/engine/battle/effect_commands.asm index b9a7382c0..ea6c22dda 100644 --- a/engine/battle/effect_commands.asm +++ b/engine/battle/effect_commands.asm @@ -556,8 +556,8 @@ 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 @@ -676,8 +676,8 @@ HitConfusion: ; 343a5 call CallBattleCore ld a, $1 ld [hBGMapMode], a - ld c, $1 - call PlayerHurtItself + ld c, TRUE + call DoPlayerDamage jp BattleCommand_RaiseSub ; 343db @@ -2081,16 +2081,16 @@ BattleCommand_LowerSub: ; 34eee ; 34f57 -BattleCommand_HitTarget: ; 34f57 -; hittarget +BattleCommand_MoveAnim: ; 34f57 +; moveanim call BattleCommand_LowerSub - call BattleCommand_HitTargetNoSub + call BattleCommand_MoveAnimNoSub jp BattleCommand_RaiseSub ; 34f60 -BattleCommand_HitTargetNoSub: ; 34f60 +BattleCommand_MoveAnimNoSub: ; 34f60 ld a, [wAttackMissed] and a jp nz, BattleCommand_MoveDelay @@ -2274,65 +2274,68 @@ BattleCommand_FailureText: ; 35023 ; 3505e -BattleCommand_CheckFaint: ; 3505e -; checkfaint +BattleCommand_ApplyDamage: ; 3505e +; 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 @@ -2341,10 +2344,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] @@ -2418,11 +2421,11 @@ 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 ld a, BATTLE_VARS_SUBSTATUS1_OPP @@ -3620,15 +3623,13 @@ PlayFXAnimID: ; 35d08 ld c, 3 call DelayFrames - callfar PlayBattleAnim - ret ; 35d1c -EnemyHurtItself: ; 35d1c +DoEnemyDamage: ; 35d1c ld hl, wCurDamage ld a, [hli] ld b, a @@ -3638,13 +3639,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] @@ -3657,19 +3659,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 @@ -3680,6 +3681,7 @@ EnemyHurtItself: ; 35d1c ld [wBuffer6], a ld a, [hl] ld [wBuffer5], a + hlcoord 2, 2 xor a ld [wWhichHPBar], a @@ -3690,7 +3692,7 @@ EnemyHurtItself: ; 35d1c ; 35d7e -PlayerHurtItself: ; 35d7e +DoPlayerDamage: ; 35d7e ld hl, wCurDamage ld a, [hli] ld b, a @@ -3700,12 +3702,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] @@ -3719,14 +3724,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 @@ -3734,14 +3738,15 @@ 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 @@ -3750,8 +3755,7 @@ PlayerHurtItself: ; 35d7e ; 35de0 -SelfInflictDamageToSubstitute: ; 35de0 - +DoSubstituteDamage: ; 35de0 ld hl, SubTookDamageText call StdBattleTextBox -- cgit v1.2.3