shithub: pokecrystal

Download patch

ref: 80a3f7e1baea5a17ba039bdfe62d848f73288119
parent: 72f3234e036a6fbff598858f2b8713268cf9fca0
author: Nescientist <86188284+Nescientist@users.noreply.github.com>
date: Sun Jun 20 12:56:11 EDT 2021

Fixing comments in BattleCommand_Teleport


--- a/docs/bugs_and_glitches.md
+++ b/docs/bugs_and_glitches.md
@@ -1250,11 +1250,13 @@
  	call BattleRandom
  	cp c
  	jr nc, .loop_enemy
+ 	; b = player level / 4
  	srl b
  	srl b
- 	cp b
--	; This should be jr c, .failed
+-	; This should be "jr c, .failed"
 -	; As written, it makes enemy use of Teleport always succeed if able
++	; If the random number >= player level / 4, Teleport will succeed
+ 	cp b
 -	jr nc, .run_away
 +	jr c, .failed
 ```
--- a/engine/battle/move_effects/teleport.asm
+++ b/engine/battle/move_effects/teleport.asm
@@ -15,31 +15,34 @@
 	call GetBattleVar
 	bit SUBSTATUS_CANT_RUN, a
 	jr nz, .failed
-; Only need to check these next things if it's your turn
 	ldh a, [hBattleTurn]
 	and a
 	jr nz, .enemy_turn
-; Can't teleport from a trainer battle
+
+	; 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.
+	; b = player level
 	ld a, [wCurPartyLevel]
 	ld b, a
+	; If player level >= enemy level, Teleport will succeed
 	ld a, [wBattleMonLevel]
 	cp b
 	jr nc, .run_away
-; Generate a number between 0 and (YourLevel + TheirLevel).
+	; c = player level + enemy level + 1
 	add b
 	ld c, a
 	inc c
+	; Generate a number less than c
 .loop_player
 	call BattleRandom
 	cp c
 	jr nc, .loop_player
-; If that number is greater than 4 times your level, run away.
+	; b = enemy level / 4
 	srl b
 	srl b
+	; If the random number >= enemy level / 4, Teleport will succeed
 	cp b
 	jr nc, .run_away
 
@@ -48,27 +51,34 @@
 	jp PrintButItFailed
 
 .enemy_turn
+	; Can't teleport from a trainer battle
 	ld a, [wBattleMode]
 	dec a
 	jr nz, .failed
+	; b = enemy level
 	ld a, [wBattleMonLevel]
 	ld b, a
+	; If enemy level >= player level, Teleport will succeed
 	ld a, [wCurPartyLevel]
 	cp b
 	jr nc, .run_away
+	; c = enemy level + player level + 1
 	add b
 	ld c, a
 	inc c
+	; Generate a number less than c
 .loop_enemy
 	call BattleRandom
 	cp c
 	jr nc, .loop_enemy
+	; b = player level / 4
 	srl b
 	srl b
-	cp b
-	; This should be jr c, .failed
+	; This should be "jr c, .failed"
 	; As written, it makes enemy use of Teleport always succeed if able
+	cp b
 	jr nc, .run_away
+
 .run_away
 	call UpdateBattleMonInParty
 	xor a