shithub: pokered

Download patch

ref: 599a6aeaaf81e7174577c782f3b3ba113a4a4c39
parent: f6d618090aa689540056a13fb74125d83879347f
author: YamaArashi <shadow962@live.com>
date: Thu Aug 13 20:36:06 EDT 2015

named battle and learn move variables

--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -788,7 +788,7 @@
 
 HandleEnemyMonFainted: ; 3c525 (f:4525)
 	xor a
-	ld [wccf0], a
+	ld [wInHandlePlayerMonFainted], a
 	call FaintEnemyPokemon
 	call AnyPartyAlive
 	ld a, d
@@ -888,9 +888,9 @@
 	ld a, [hli]
 	or [hl]
 	jr nz, .playermonnotfaint
-	ld a, [wccf0]
-	and a
-	jr nz, .playermonnotfaint
+	ld a, [wInHandlePlayerMonFainted]
+	and a ; was this called by HandlePlayerMonFainted?
+	jr nz, .playermonnotfaint ; if so, don't call RemoveFaintedPlayerMon twice
 	call RemoveFaintedPlayerMon
 .playermonnotfaint
 	call AnyPartyAlive
@@ -950,11 +950,13 @@
 	db "@"
 
 EndLowHealthAlarm: ; 3c643 (f:4643)
+; This function is called when the player has the won the battle. It turns off
+; the low health alarm and prevents it from reactivating until the next battle.
 	xor a
-	ld [wLowHealthAlarm], a ;disable low health alarm
+	ld [wLowHealthAlarm], a ; turn off low health alarm
 	ld [wChannelSoundIDs + CH4], a
 	inc a
-	ld [wccf6], a
+	ld [wLowHealthAlarmDisabled], a ; prevent it from reactivating
 	ret
 
 AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f)
@@ -1053,8 +1055,8 @@
 	jp Delay3
 
 HandlePlayerMonFainted: ; 3c700 (f:4700)
-	ld a, $1
-	ld [wccf0], a
+	ld a, 1
+	ld [wInHandlePlayerMonFainted], a
 	call RemoveFaintedPlayerMon
 	call AnyPartyAlive     ; test if any more mons are alive
 	ld a, d
@@ -1115,9 +1117,15 @@
 	call SlideDownFaintedMonPic
 	ld a, $1
 	ld [wBattleResult], a
-	ld a, [wccf0]
-	and a
-	ret z
+
+; When the player mon and enemy mon faint at the same time and the fact that the
+; enemy mon has fainted is detected first (e.g. when the player mon knocks out
+; the enemy mon using a move with recoil and faints due to the recoil), don't
+; play the player mon's cry or show the "[player mon] fainted!" message.
+	ld a, [wInHandlePlayerMonFainted]
+	and a ; was this called by HandleEnemyMonFainted?
+	ret z ; if so, return
+
 	ld a, [wBattleMonSpecies]
 	call PlayCry
 	ld hl, PlayerMonFaintedText
@@ -1932,9 +1940,9 @@
 	ld a, [hli]
 	or [hl]
 	jr z, .asm_3cdd9
-	ld a, [wccf6]
-	and a
-	ret nz
+	ld a, [wLowHealthAlarmDisabled]
+	and a ; has the alarm been disabled because the player has already won?
+	ret nz ; if so, return
 	ld a, [wPlayerHPBarColor]
 	cp HP_BAR_RED
 	jr z, .asm_3cde6
@@ -6201,7 +6209,7 @@
 	call GetMonHeader
 	ld a, [W_ENEMYBATTSTATUS3]
 	bit Transformed, a ; is enemy mon transformed?
-	ld hl, wcceb ; copied DVs from when it used Transform
+	ld hl, wTransformedEnemyMonOriginalDVs ; original DVs before transforming
 	ld a, [hli]
 	ld b, [hl]
 	jr nz, .storeDVs
@@ -6879,7 +6887,7 @@
 	ld [wEnemyMonPartyPos], a
 	ld a, $2
 	ld [W_ISINBATTLE], a
-	jp InitBattle_Common
+	jp _InitBattleCommon
 
 InitWildBattle: ; 3ef8b (f:6f8b)
 	ld a, $1
@@ -6931,7 +6939,7 @@
 	predef CopyUncompressedPicToTilemap
 
 ; common code that executes after init battle code specific to trainer or wild battles
-InitBattle_Common: ; 3efeb (f:6feb)
+_InitBattleCommon: ; 3efeb (f:6feb)
 	ld b, SET_PAL_BATTLE_BLACK
 	call RunPaletteCommand
 	call SlidePlayerAndEnemySilhouettesOnScreen
--- a/engine/battle/moveEffects/transform_effect.asm
+++ b/engine/battle/moveEffects/transform_effect.asm
@@ -67,12 +67,12 @@
 	ld a, [H_WHOSETURN]
 	and a
 	jr z, .next
-; save enemy mon DVs in wcceb/wccec (enemy turn only)
+; save enemy mon DVs at wTransformedEnemyMonOriginalDVs
 	ld a, [de]
-	ld [wcceb], a
+	ld [wTransformedEnemyMonOriginalDVs], a
 	inc de
 	ld a, [de]
-	ld [wccec], a
+	ld [wTransformedEnemyMonOriginalDVs + 1], a
 	dec de
 .next
 ; DVs
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -364,7 +364,7 @@
 	jr .next16
 .next15
 	set Transformed,[hl]
-	ld hl,wcceb
+	ld hl,wTransformedEnemyMonOriginalDVs
 	ld a,[wEnemyMonDVs]
 	ld [hli],a
 	ld a,[wEnemyMonDVs + 1]
@@ -2105,9 +2105,9 @@
 	push af
 .chooseMon
 	ld hl,wcf4b
-	ld de,wd036
+	ld de,wTempMoveNameBuffer
 	ld bc,14
-	call CopyData
+	call CopyData ; save the move name because DisplayPartyMenu will overwrite it
 	ld a,$ff
 	ld [wUpdateSpritesEnabled],a
 	ld a,TMHM_PARTY_MENU
@@ -2114,7 +2114,7 @@
 	ld [wPartyMenuTypeOrMessageID],a
 	call DisplayPartyMenu
 	push af
-	ld hl,wd036
+	ld hl,wTempMoveNameBuffer
 	ld de,wcf4b
 	ld bc,14
 	call CopyData
--- a/engine/learn_move.asm
+++ b/engine/learn_move.asm
@@ -4,7 +4,7 @@
 	ld hl, wPartyMonNicks
 	call GetPartyMonName
 	ld hl, wcd6d
-	ld de, wd036
+	ld de, wLearnMoveMonName
 	ld bc, NAME_LENGTH
 	call CopyData
 
@@ -16,13 +16,13 @@
 	ld d, h
 	ld e, l
 	ld b, NUM_MOVES
-.asm_6e6b
+.findEmptyMoveSlotLoop
 	ld a, [hl]
 	and a
-	jr z, .asm_6e8b
+	jr z, .next
 	inc hl
 	dec b
-	jr nz, .asm_6e6b
+	jr nz, .findEmptyMoveSlotLoop
 	push de
 	call TryingToLearn
 	pop de
@@ -35,7 +35,7 @@
 	call PrintText
 	pop de
 	pop hl
-.asm_6e8b
+.next
 	ld a, [wMoveNum]
 	ld [hl], a
 	ld bc, wPartyMon1PP - wPartyMon1Moves
@@ -86,13 +86,13 @@
 	jp nz, DontAbandonLearning
 	ld hl, DidNotLearnText
 	call PrintText
-	ld b, $0
+	ld b, 0
 	ret
 
 PrintLearnedMove: ; 6efe (1:6efe)
 	ld hl, LearnedMove1Text
 	call PrintText
-	ld b, $1
+	ld b, 1
 	ret
 
 TryingToLearn: ; 6f07 (1:6f07)
@@ -108,7 +108,7 @@
 	ld a, [wCurrentMenuItem]
 	rra
 	ret c
-	ld bc, - NUM_MOVES
+	ld bc, -NUM_MOVES
 	add hl, bc
 	push hl
 	ld de, wMoves
@@ -121,8 +121,8 @@
 	ld hl, WhichMoveToForgetText
 	call PrintText
 	coord hl, 4, 7
-	ld b, $4
-	ld c, $e
+	ld b, 4
+	ld c, 14
 	call TextBoxBorder
 	coord hl, 6, 8
 	ld de, wMovesString
@@ -160,7 +160,7 @@
 	push hl
 	ld a, [wCurrentMenuItem]
 	ld c, a
-	ld b, $0
+	ld b, 0
 	add hl, bc
 	ld a, [hl]
 	push af
--- a/text.asm
+++ b/text.asm
@@ -2686,7 +2686,7 @@
 	done
 
 _LearnedMove1Text:: ; a273b (28:673b)
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	text " learned"
 	line "@"
 	TX_RAM wcf4b
@@ -2705,7 +2705,7 @@
 	done
 
 _DidNotLearnText:: ; a278a (28:678a)
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	db $0
 	line "did not learn"
 	cont "@"
@@ -2714,7 +2714,7 @@
 	prompt
 
 _TryingToLearnText:: ; a27a4 (28:67a4)
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	text " is"
 	line "trying to learn"
 	cont "@"
@@ -2722,7 +2722,7 @@
 	text "!"
 
 	para "But, @"
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	db $0
 	line "can't learn more"
 	cont "than 4 moves!"
@@ -2743,7 +2743,7 @@
 _ForgotAndText:: ; a2830 (28:6830)
 	db $0
 	para "@"
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	text " forgot"
 	line "@"
 	TX_RAM wcd6d
--- a/wram.asm
+++ b/wram.asm
@@ -622,8 +622,8 @@
 
 	ds 1
 
-wcceb:: ds 1 ; used to save the dvs of a mon when it uses transform
-wccec:: ds 1 ; also used with above case
+wTransformedEnemyMonOriginalDVs:: ; cceb
+	ds 2
 
 wMonIsDisobedient:: ds 1 ; cced
 
@@ -630,7 +630,10 @@
 wPlayerDisabledMoveNumber:: ds 1 ; ccee
 wEnemyDisabledMoveNumber:: ds 1 ; ccef
 
-wccf0:: ds 1 ; used as a check if a mon fainted
+wInHandlePlayerMonFainted:: ; ccf0
+; When running in the scope of HandlePlayerMonFainted, it equals 1.
+; When running in the scope of HandleEnemyMonFainted, it equals 0.
+	ds 1
 
 wPlayerUsedMove:: ds 1 ; ccf1
 wEnemyUsedMove:: ds 1 ; ccf2
@@ -643,9 +646,14 @@
 ; flags that indicate which party members have fought the current enemy mon
 	flag_array 6
 
-wccf6:: ds 1 ; used in some hp bar thing
-wPlayerMonMinimized:: ds 1 ; ccf7
+wLowHealthAlarmDisabled:: ; ccf6
+; Whether the low health alarm has been disabled due to the player winning the
+; battle.
+	ds 1
 
+wPlayerMonMinimized:: ; ccf7
+	ds 1
+
 	ds 13
 
 wLuckySlotHiddenObjectIndex:: ; cd05
@@ -1556,7 +1564,12 @@
 wTrainerPicPointer:: ; d033
 	ds 2
 	ds 1
-wd036:: ds 16 ; used as a temporary buffer to print "XXX learned YYY"
+
+wTempMoveNameBuffer:: ; d036
+
+wLearnMoveMonName:: ; d036
+; The name of the mon that is learning a move.
+	ds 16
 
 wTrainerBaseMoney:: ; d046
 ; 2-byte BCD number