shithub: pokecrystal

Download patch

ref: e9494770894c0504a21e1e130ef51f1d97accaf8
parent: 1dc88cb5854a15337997c6236aed01021a9d46f7
author: Idain <luiscarlosholguinperez@outlook.com>
date: Mon Jan 24 16:48:21 EST 2022

Document Return/Frustration bug and its fix (#872)

Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com>

--- a/docs/bugs_and_glitches.md
+++ b/docs/bugs_and_glitches.md
@@ -34,6 +34,7 @@
   - [Beat Up may fail to raise Substitute](#beat-up-may-fail-to-raise-substitute)
   - [Beat Up may trigger King's Rock even if it failed](#beat-up-may-trigger-kings-rock-even-if-it-failed)
   - [Present damage is incorrect in link battles](#present-damage-is-incorrect-in-link-battles)
+  - [Return and Frustration deal no damage when the user's happiness is low or high, respectively](#return-and-frustration-deal-no-damage-when-the-users-happiness-is-low-or-high-respectively)
   - [Dragon Scale, not Dragon Fang, boosts Dragon-type moves](#dragon-scale-not-dragon-fang-boosts-dragon-type-moves)
   - [Switching out or switching against a Pokémon with max HP below 4 freezes the game](#switching-out-or-switching-against-a-pokémon-with-max-HP-below-4-freezes-the-game)
   - [Moves that do damage and increase your stats do not increase stats after a KO](#moves-that-do-damage-and-increase-your-stats-do-not-increase-stats-after-a-ko)
@@ -697,6 +698,53 @@
  	pop de
  	pop bc
 -.colosseum_skippop
+```
+
+
+## Return and Frustration deal no damage when the user's happiness is low or high, respectively
+
+This happens because the user's happiness (or 255 − happiness for Frustration) is multiplied by 10 and divided by 25, which rounds down to zero when the happiness is 0–2 (or 253–255 for Frustration).
+
+**Fix:**
+
+Edit [engine/battle/move_effects/return.asm](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/return.asm):
+
+```diff
+ BattleCommand_HappinessPower:
+ 	...
+ 	call Multiply
+ 	ld a, 25
+ 	ldh [hDivisor], a
+ 	ld b, 4
+ 	call Divide
+ 	ldh a, [hQuotient + 3]
++	and a
++	jr nz, .done
++	inc a
++.done
+ 	ld d, a
+ 	pop bc
+ 	ret
+```
+
+And edit [engine/battle/move_effects/frustration.asm](https://github.com/pret/pokecrystal/blob/master/engine/battle/move_effects/frustration.asm):
+
+```diff
+ BattleCommand_FrustrationPower:
+ 	...
+ 	call Multiply
+ 	ld a, 25
+ 	ldh [hDivisor], a
+ 	ld b, 4
+ 	call Divide
+ 	ldh a, [hQuotient + 3]
++	and a
++	jr nz, .done
++	inc a
++.done
+ 	ld d, a
+ 	pop bc
+ 	ret
 ```
 
 
--- a/engine/battle/move_effects/frustration.asm
+++ b/engine/battle/move_effects/frustration.asm
@@ -1,13 +1,12 @@
 BattleCommand_FrustrationPower:
 ; frustrationpower
-
 	push bc
 	ld hl, wBattleMonHappiness
 	ldh a, [hBattleTurn]
 	and a
-	jr z, .got_happiness
+	jr z, .ok
 	ld hl, wEnemyMonHappiness
-.got_happiness
+.ok
 	ld a, $ff
 	sub [hl]
 	ldh [hMultiplicand + 2], a