summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluckytyphlosion <alan.rj.huang@gmail.com>2015-12-31 15:04:19 -0500
committerluckytyphlosion <alan.rj.huang@gmail.com>2015-12-31 15:04:19 -0500
commitd3cd6e1e1a64a0093128918f9e02a79dc6d510cb (patch)
tree212ced67fff5042b40b2225d30087e41e83abf0a
parentf0915e2b664f3c045cdea710aeced219396db8bb (diff)
BankF documentation from HasMonFainted to Func_3d536
-rw-r--r--constants/misc_constants.asm9
-rw-r--r--constants/predef_constants.asm2
-rw-r--r--engine/bank3d/bank3d_battle.asm4
-rw-r--r--engine/bank3d/link_menu.asm2
-rw-r--r--engine/bank3f/main.asm1
-rwxr-xr-xengine/battle/animations.asm22
-rwxr-xr-xengine/battle/core.asm290
-rw-r--r--engine/battle/core_.asm1364
-rw-r--r--engine/battle/moveEffects/haze_effect.asm2
-rwxr-xr-xengine/hidden_object_functions17.asm10
-rwxr-xr-xengine/hidden_object_functions7.asm2
-rwxr-xr-xengine/items/items.asm6
-rwxr-xr-xengine/menu/main_menu.asm2
-rwxr-xr-xengine/oak_speech.asm2
-rwxr-xr-xengine/predefs.asm2
-rwxr-xr-xengine/trade.asm2
-rwxr-xr-xwram.asm4
-rwxr-xr-xyellow/main.asm10
18 files changed, 1599 insertions, 137 deletions
diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm
index 3f48b091..5bc12b88 100644
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -52,6 +52,14 @@ NPC_MOVEMENT_UP EQU $40
NPC_MOVEMENT_LEFT EQU $80
NPC_MOVEMENT_RIGHT EQU $C0
+; battle types
+const_value set $0
+ const NORMAL_BATTLE ; $0
+ const OLD_MAN_BATTLE ; $1
+ const SAFARI_BATTLE ; $2
+ const HURRY_RUN_AWAY_BATTLE ; $3
+ const STARTER_PIKACHU_BATTLE ; $4
+
; text box IDs
MESSAGE_BOX EQU $01
FIELD_MOVE_MON_MENU EQU $04
@@ -207,6 +215,7 @@ LINK_STATE_BATTLING EQU $04 ; in a link battle
LINK_STATE_RESET EQU $05 ; reset game (unused)
LINK_STATE_TRADING EQU $32 ; in a link trade
+; pikachu happiness modifiers
const_value set 1
const PIKAHAPPY_LEVELUP
const PIKAHAPPY_USEDITEM
diff --git a/constants/predef_constants.asm b/constants/predef_constants.asm
index c4d0c208..2f1834d5 100644
--- a/constants/predef_constants.asm
+++ b/constants/predef_constants.asm
@@ -5,7 +5,7 @@ const_value = 0
predef_const AnimateSendingOutMon
predef_const ScaleSpriteByTwo
predef_const LoadMonBackPic
- predef_const Func_79aba
+ predef_const CopyDownscaledMonTiles
predef_const LoadMissableObjects
predef_const HealParty
predef_const MoveAnimation; 08 play move animation
diff --git a/engine/bank3d/bank3d_battle.asm b/engine/bank3d/bank3d_battle.asm
index fde29f5d..b9713cec 100644
--- a/engine/bank3d/bank3d_battle.asm
+++ b/engine/bank3d/bank3d_battle.asm
@@ -206,7 +206,7 @@ Func_f61a6: ; f61a6 (3d:f61a6)
ld a, $1
ld [wNumMovesMinusOne], a
ld bc, $303
- predef Func_79aba
+ predef CopyDownscaledMonTiles
ld c, $4
call DelayFrames
ld bc, -41
@@ -214,7 +214,7 @@ Func_f61a6: ; f61a6 (3d:f61a6)
xor a
ld [wNumMovesMinusOne], a
ld bc, $505
- predef Func_79aba
+ predef CopyDownscaledMonTiles
ld c, $5
call DelayFrames
ld bc, -41
diff --git a/engine/bank3d/link_menu.asm b/engine/bank3d/link_menu.asm
index 9ae45eb6..a7b4ea9e 100644
--- a/engine/bank3d/link_menu.asm
+++ b/engine/bank3d/link_menu.asm
@@ -776,7 +776,7 @@ LinkMenu: ; f580c (3d:580c)
call DelayFrames
ld hl, wd732
res 1, [hl]
- ld a, [W_ANIMATIONID]
+ ld a, [wAnimationID]
ld [wDestinationMap], a
callab SpecialWarpIn
ld c, $14
diff --git a/engine/bank3f/main.asm b/engine/bank3f/main.asm
index 21566031..9552e07a 100644
--- a/engine/bank3f/main.asm
+++ b/engine/bank3f/main.asm
@@ -1548,6 +1548,7 @@ IsThisPartymonStarterPikachu_Box:: ; fce0d (3f:4e0d)
jr asm_fce21
IsThisPartymonStarterPikachu_Party:: ; fce18 (3f:4e18)
+IsThisPartymonStarterPikachu::
ld hl,wPartyMon1
ld bc,wPartyMon2 - wPartyMon1
ld de,wPartyMonOT
diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm
index f2b660f7..aa9a6c3b 100755
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -142,7 +142,7 @@ DrawFrameBlock: ; 78000 (1e:4000)
jr z,.advanceFrameBlockDestAddr ; skip cleaning OAM buffer
cp a,4
jr z,.done ; skip cleaning OAM buffer and don't advance the frame block destination address
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
cp a,GROWL
jr z,.resetFrameBlockDestAddr
call AnimationCleanOAM
@@ -165,7 +165,7 @@ PlayAnimation: ; 780f1 (1e:40f1)
xor a
ld [$FF8B],a ; it looks like nothing reads this
ld [W_SUBANIMTRANSFORM],a
- ld a,[W_ANIMATIONID] ; get animation number
+ ld a,[wAnimationID] ; get animation number
dec a
ld l,a
ld h,0
@@ -376,7 +376,7 @@ MoveAnimation: ; 78d5e (1e:4d5e)
push af
call WaitForSoundToFinish
call SetAnimationPalette
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
and a
jr z,.AnimationFinished
@@ -422,7 +422,7 @@ ShareMoveAnimations: ; 78da6 (1e:4da6)
; opponent’s turn
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
cp a,AMNESIA
ld b,CONF_ANIM
@@ -434,7 +434,7 @@ ShareMoveAnimations: ; 78da6 (1e:4da6)
.Replace
ld a,b
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
ret
PlayApplyingAttackAnimation: ; 78dbd (1e:4dbd)
@@ -521,7 +521,7 @@ SetAnimationPalette: ; 78e23 (1e:4e23)
ld a, $f0
ld [wAnimPalette], a
ld b, $e4
- ld a, [W_ANIMATIONID]
+ ld a, [wAnimationID]
cp TRADE_BALL_DROP_ANIM
jr c, .next
cp TRADE_BALL_POOF_ANIM + 1
@@ -626,7 +626,7 @@ DoSpecialEffectByAnimationId: ; 78ed7 (1e:4ed7)
push hl
push de
push bc
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
ld hl,AnimationIdSpecialEffects
ld de,3
call IsInArray
@@ -2346,7 +2346,7 @@ GetMoveSound: ; 7986f (1e:586f)
IsCryMove: ; 798ad (1e:58ad)
; set carry if the move animation involves playing a monster cry
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
cp a,GROWL
jr z,.CryMove
cp a,ROAR
@@ -2976,7 +2976,7 @@ TossBallAnimation: ; 79e16 (1e:5e16)
.done
ld a,b
.PlayNextAnimation
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
push bc
push hl
call PlayAnimation
@@ -2993,12 +2993,12 @@ TossBallAnimation: ; 79e16 (1e:5e16)
.BlockBall ; 5E55
ld a,TOSS_ANIM
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
call PlayAnimation
ld a,SFX_FAINT_THUD
call PlaySound
ld a,BLOCKBALL_ANIM
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
jp PlayAnimation
PlayApplyingAttackSound: ; 79e6a (1e:5e6a)
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index e33295dc..b6d6ace0 100755
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -424,7 +424,7 @@ MainInBattleLoop: ; 3c249 (f:4249)
jr nz, .selectEnemyMove
ld [wMoveMenuType], a
inc a
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
xor a
ld [wMenuItemToSwap], a
call MoveSelectionMenu
@@ -1611,18 +1611,20 @@ HasMonFainted: ; 3cafc (f:4afc)
xor a
ret
-NoWillText: ; 3cab4 (f:4ab4)
+NoWillText: ; 3cb19 (f:4b19)
TX_FAR _NoWillText
db "@"
; try to run from battle (hl = player speed, de = enemy speed)
; stores whether the attempt was successful in carry flag
-TryRunningFromBattle: ; 3cab9 (f:4ab9)
+TryRunningFromBattle: ; 3cb1e (f:4b1e)
call IsGhostBattle
jp z, .canEscape ; jump if it's a ghost battle
ld a, [wBattleType]
cp $2
jp z, .canEscape ; jump if it's a safari battle
+ cp $3
+ jp z, .canEscape ; hurry, get away?
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jp z, .canEscape
@@ -1734,20 +1736,20 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
scf ; set carry
ret
-CantEscapeText: ; 3cb97 (f:4b97)
+CantEscapeText: ; 3cc01 (f:4c01)
TX_FAR _CantEscapeText
db "@"
-NoRunningText: ; 3cb9c (f:4b9c)
+NoRunningText: ; 3cc06 (f:4c06)
TX_FAR _NoRunningText
db "@"
-GotAwayText: ; 3cba1 (f:4ba1)
+GotAwayText: ; 3cc0b (f:4c0b)
TX_FAR _GotAwayText
db "@"
; copies from party data to battle mon data when sending out a new player mon
-LoadBattleMonFromParty: ; 3cba6 (f:4ba6)
+LoadBattleMonFromParty: ; 3cc10 (f:4c10)
ld a, [wWhichPokemon]
ld bc, wPartyMon2 - wPartyMon1
ld hl, wPartyMon1Species
@@ -1791,7 +1793,7 @@ LoadBattleMonFromParty: ; 3cba6 (f:4ba6)
ret
; copies from enemy party data to current enemy mon data when sending out a new enemy mon
-LoadEnemyMonFromParty: ; 3cc13 (f:4c13)
+LoadEnemyMonFromParty: ; 3cc7d (f:4c7d)
ld a, [wWhichPokemon]
ld bc, wEnemyMon2 - wEnemyMon1
ld hl, wEnemyMons
@@ -1844,7 +1846,7 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13)
ld [wEnemyMonPartyPos], a
ret
-SendOutMon: ; 3cc91 (f:4c91)
+SendOutMon: ; 3ccfb (f:4cfb)
callab PrintSendOutMonMessage
ld hl, wEnemyMonHP
ld a, [hli]
@@ -1871,26 +1873,53 @@ SendOutMon: ; 3cc91 (f:4c91)
ld [hli], a
ld [hli], a
ld [hl], a
- ld [W_PLAYERDISABLEDMOVE], a
+ ld [wPlayerDisabledMove], a
ld [wPlayerDisabledMoveNumber], a
ld [wPlayerMonMinimized], a
ld b, SET_PAL_BATTLE
call RunPaletteCommand
ld hl, wEnemyBattleStatus1
res UsingTrappingMove, [hl]
+ callab IsThisPartymonStarterPikachu
+ jr c, .starterPikachu
ld a, $1
ld [H_WHOSETURN], a
ld a, POOF_ANIM
call PlayMoveAnimation
coord hl, 4, 11
predef AnimateSendingOutMon
+ jr .playRegularCry
+.playerPikachu
+ xor a
+ ld [H_WHOSETURN], a
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ callab Func_f429f
+ callab Func_fd0d0
+ ld e, $24
+ jr c, .asm_3cd81
+ ld e, $a
+.asm_3cd81
+ callab PlayPikachuSoundClip
+ jr .done
+.playRegularCry
ld a, [wcf91]
call PlayCry
+.done
call PrintEmptyString
jp SaveScreenTilesToBuffer1
; show 2 stages of the player mon getting smaller before disappearing
-AnimateRetreatingPlayerMon: ; 3ccfa (f:4cfa)
+AnimateRetreatingPlayerMon: ; 3cd97 (f:4d97)
+ ld a, [wWhichPokemon]
+ push af
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ callab IsThisPartymonStarterPikachu
+ pop bc
+ ld a, b
+ ld [wWhichPokemon], a
+ jr c, .starterPikachu
coord hl, 1, 5
lb bc, 7, 7
call ClearScreenArea
@@ -1914,13 +1943,20 @@ AnimateRetreatingPlayerMon: ; 3ccfa (f:4cfa)
call .clearScreenArea
ld a, $4c
Coorda 5, 11
+ jr .clearScreenArea
+.starterPikachu
+ xor a
+ ld [H_WHOSETURN], a
+ callab AnimationSlideMonOff
+ ret
.clearScreenArea
coord hl, 1, 5
lb bc, 7, 7
- jp ClearScreenArea
+ call ClearScreenArea ; jp
+ ret
; reads player's current mon's HP into wBattleMonHP
-ReadPlayerMonCurHPAndStatus: ; 3cd43 (f:4d43)
+ReadPlayerMonCurHPAndStatus: ; 3ce08 (f:4e08)
ld a, [wPlayerMonNumber]
ld hl, wPartyMon1HP
ld bc, wPartyMon2 - wPartyMon1
@@ -1931,11 +1967,11 @@ ReadPlayerMonCurHPAndStatus: ; 3cd43 (f:4d43)
ld bc, $4 ; 2 bytes HP, 1 byte unknown (unused?), 1 byte status
jp CopyData
-DrawHUDsAndHPBars: ; 3cd5a (f:4d5a)
+DrawHUDsAndHPBars: ; 3ce1f (f:4e1f)
call DrawPlayerHUDAndHPBar
jp DrawEnemyHUDAndHPBar
-DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60)
+DrawPlayerHUDAndHPBar: ; 3ce25 (f:4e25)
xor a
ld [H_AUTOBGTRANSFERENABLED], a
coord hl, 9, 7
@@ -1962,9 +1998,9 @@ DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60)
ld de, wLoadedMonStatus
call PrintStatusConditionNotFainted
pop hl
- jr nz, .asm_3cdae
+ jr nz, .doNotPrintLevel
call PrintLevel
-.asm_3cdae
+.doNotPrintLevel
ld a, [wLoadedMonSpecies]
ld [wcf91], a
coord hl, 10, 9
@@ -1976,14 +2012,14 @@ DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60)
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
- jr z, .asm_3cdd9
+ jr z, .fainted
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
-.asm_3cdd9
+ jr z, .setLowHealthAlarm
+.fainted
ld hl, wLowHealthAlarm
bit 7, [hl] ;low health alarm enabled?
ld [hl], $0
@@ -1991,12 +2027,12 @@ DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60)
xor a
ld [wChannelSoundIDs + CH4], a
ret
-.asm_3cde6
+.setLowHealthAlarm
ld hl, wLowHealthAlarm
set 7, [hl] ;enable low health alarm
ret
-DrawEnemyHUDAndHPBar: ; 3cdec (f:4dec)
+DrawEnemyHUDAndHPBar: ; 3ceb1 (f:4eb1)
xor a
ld [H_AUTOBGTRANSFERENABLED], a
coord hl, 0, 0
@@ -2086,7 +2122,7 @@ DrawEnemyHUDAndHPBar: ; 3cdec (f:4dec)
ld [H_AUTOBGTRANSFERENABLED], a
ld hl, wEnemyHPBarColor
-GetBattleHealthBarColor: ; 3ce90 (f:4e90)
+GetBattleHealthBarColor: ; 3cf55 (f:4f55)
ld b, [hl]
call GetHealthBarColor
ld a, [hl]
@@ -2100,7 +2136,7 @@ GetBattleHealthBarColor: ; 3ce90 (f:4e90)
; (i.e. for names longer than 4 letters)
; if the name is 3 or 4 letters long, it is printed 1 space more to the right than usual
; (i.e. for names longer than 4 letters)
-CenterMonName: ; 3ce9c (f:4e9c)
+CenterMonName: ; 3cf61 (f:4f61)
push de
inc hl
inc hl
@@ -2121,7 +2157,7 @@ CenterMonName: ; 3ce9c (f:4e9c)
pop de
ret
-DisplayBattleMenu: ; 3ceb3 (f:4eb3)
+DisplayBattleMenu: ; 3cf78 (f:4f78)
call LoadScreenTilesFromBuffer1 ; restore saved screen
ld a, [wBattleType]
and a
@@ -2139,36 +2175,49 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
ld [wTextBoxID], a
call DisplayTextBoxID
ld a, [wBattleType]
- dec a
- jp nz, .handleBattleMenuInput ; handle menu input if it's not the old man tutorial
-; the following happens for the old man tutorial
+ cp $1
+ jr z, .doSimulatedMenuInput ; simulate menu input if it's the old man or prof. oak pikachu battle
+ cp $4
+ jr z, .doSimulatedMenuInput
+ jp .handleBattleMenuInput
+; the following happens for the old man tutorial and prof. oak pikachu battle
+.doSimulatedMenuInput
ld hl, wPlayerName
ld de, wGrassRate
ld bc, NAME_LENGTH
call CopyData ; temporarily save the player name in unused space,
; which is supposed to get overwritten when entering a
- ; map with wild Pokémon. Due to an oversight, the data
+ ; map with wild Pokémon.
+ ; In Red/Blue, due to an oversight, the data
; may not get overwritten (cinnabar) and the infamous
- ; Missingno. glitch can show up.
+ ; Missingno. glitch can show up. However,
+ ; this has been fixed in yellow
ld hl, .oldManName
+ ld a, [wBattleType]
+ dec a
+ jr z, .useOldManName
+ ld hl, .profOakName
+.useOldManName
ld de, wPlayerName
ld bc, NAME_LENGTH
call CopyData
; the following simulates the keystrokes by drawing menus on screen
coord hl, 9, 14
ld [hl], "▶"
- ld c, 80
+ ld c, 20
call DelayFrames
ld [hl], " "
coord hl, 9, 16
ld [hl], "▶"
- ld c, 50
+ ld c, 14
call DelayFrames
ld [hl], $ec
ld a, $2 ; select the "ITEM" menu
jp .upperLeftMenuItemWasNotSelected
.oldManName
db "OLD MAN@"
+.profOakName
+ db "PROF.OAK@"
.handleBattleMenuInput
ld a, [wBattleAndStartSavedMenuItem]
ld [wCurrentMenuItem], a
@@ -2251,7 +2300,9 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
.AButtonPressed
call PlaceUnfilledArrowMenuCursor
ld a, [wBattleType]
- cp $2 ; is it a Safari battle?
+ cp HURRY_RUN_AWAY_BATTLE
+ jr z, .handleUnusedBattle
+ cp SAFARI_BATTLE ; is it a Safari battle?
ld a, [wCurrentMenuItem]
ld [wBattleAndStartSavedMenuItem], a
jr z, .handleMenuSelection
@@ -2282,12 +2333,23 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
.throwSafariBallWasSelected
ld a, SAFARI_BALL
ld [wcf91], a
- jr UseBagItem
+ jp UseBagItem
+.handleUnusedBattle
+ ld a, [wCurrentMenuItem]
+ cp $3
+ jp z, BattleMenu_RunWasSelected
+ ld hl, RunAwayText
+ call PrintText
+ jp DisplayBattleMenu
+RunAwayText: ; 3d0df (f:50df)
+ TX_FAR _RunAwayText
+ db "@"
+
.upperLeftMenuItemWasNotSelected ; a menu item other than the upper left item was selected
cp $2
jp nz, PartyMenuOrRockOrRun
-
+
; either the bag (normal battle) or bait (safari battle) was selected
ld a, [wLinkState]
cp LINK_STATE_BATTLING
@@ -2309,7 +2371,7 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
ld [wcf91], a
jr UseBagItem
-BagWasSelected:
+BagWasSelected: ; 3d10a (f:510a)
call LoadScreenTilesFromBuffer1
ld a, [wBattleType]
and a ; is it a normal battle?
@@ -2319,21 +2381,25 @@ BagWasSelected:
call DrawHUDsAndHPBars
.next
ld a, [wBattleType]
- dec a ; is it the old man tutorial?
- jr nz, DisplayPlayerBag ; no, it is a normal battle
- ld hl, OldManItemList
+ cp OLD_MAN_BATTLE ; is it the old man tutorial?
+ jr z, .simulatedInputBattle
+ cp STARTER_PIKACHU_BATTLE ; is it the prof oak battle with pikachu?
+ jr z, .simulatedInputBattle
+ jr DisplayPlayerBag
+.simulatedInputBattle
+ ld hl, SimulatedInputBattleItemList
ld a, l
ld [wListPointer], a
ld a, h
ld [wListPointer + 1], a
jr DisplayBagMenu
-OldManItemList:
- db 1 ; # items
- db POKE_BALL, 50
- db -1
+SimulatedInputBattleItemList: ; 3c130 (f:5130)
+ db 1 ; # of items
+ db POKE_BALL, 1
+ db $ff
-DisplayPlayerBag:
+DisplayPlayerBag: ; 3c134 (f:5134)
; get the pointer to player's bag when in a normal battle
ld hl, wNumBagItems
ld a, l
@@ -2341,7 +2407,7 @@ DisplayPlayerBag:
ld a, h
ld [wListPointer + 1], a
-DisplayBagMenu:
+DisplayBagMenu: ; 3c13f (f:513f)
xor a
ld [wPrintItemPrices], a
ld a, ITEMLISTMENU
@@ -2356,7 +2422,7 @@ DisplayBagMenu:
ld [wMenuItemToSwap], a
jp c, DisplayBattleMenu ; go back to battle menu if an item was not selected
-UseBagItem:
+UseBagItem: ; 3c162 (f:5162)
; either use an item from the bag or use a safari zone item
ld a, [wcf91]
ld [wd11e], a
@@ -2364,13 +2430,14 @@ UseBagItem:
call CopyStringToCF4B ; copy name
xor a
ld [wPseudoItemID], a
+ ld a, [wBattleType]
call UseItem
call LoadHudTilePatterns
call ClearSprites
xor a
ld [wCurrentMenuItem], a
ld a, [wBattleType]
- cp $2 ; is it a safari battle?
+ cp SAFARI_BATTLE ; is it a safari battle?
jr z, .checkIfMonCaptured
ld a, [wActionResultOrTookBattleTurn]
@@ -2392,7 +2459,7 @@ UseBagItem:
jr nz, .returnAfterCapturingMon
ld a, [wBattleType]
- cp $2 ; is it a safari battle?
+ cp SAFARI_BATTLE ; is it a safari battle?
jr z, .returnAfterUsingItem_NoCapture
; not a safari battle
call LoadScreenTilesFromBuffer1
@@ -2413,11 +2480,11 @@ UseBagItem:
scf ; set carry
ret
-ItemsCantBeUsedHereText:
+ItemsCantBeUsedHereText: ; 3d1c8 (f:51c8)
TX_FAR _ItemsCantBeUsedHereText
db "@"
-PartyMenuOrRockOrRun:
+PartyMenuOrRockOrRun: ; 3d1cd (f:51cd)
dec a ; was Run selected?
jp nz, BattleMenu_RunWasSelected
; party menu or rock was selected
@@ -2490,6 +2557,8 @@ PartyMenuOrRockOrRun:
predef StatusScreen
predef StatusScreen2
; now we need to reload the enemy mon pic
+ ld a, $1
+ ld [H_WHOSETURN], a
ld a, [wEnemyBattleStatus2]
bit HasSubstituteUp, a ; does the enemy mon have a substitute?
ld hl, AnimationSubstitute
@@ -2535,7 +2604,7 @@ PartyMenuOrRockOrRun:
call GBPalNormal
; fall through to SwitchPlayerMon
-SwitchPlayerMon: ; 3d1ba (f:51ba)
+SwitchPlayerMon: ; 3d2c1 (f:52c1)
callab RetreatMon
ld c, 50
call DelayFrames
@@ -2558,11 +2627,11 @@ SwitchPlayerMon: ; 3d1ba (f:51ba)
and a
ret
-AlreadyOutText: ; 3d1f5 (f:51f5)
+AlreadyOutText: ; 3d2fc (f:52fc)
TX_FAR _AlreadyOutText
db "@"
-BattleMenu_RunWasSelected: ; 3d1fa (f:51fa)
+BattleMenu_RunWasSelected: ; 3d301 (f:5301)
call LoadScreenTilesFromBuffer1
ld a, $3
ld [wCurrentMenuItem], a
@@ -2577,7 +2646,7 @@ BattleMenu_RunWasSelected: ; 3d1fa (f:51fa)
ret nz ; return if the player couldn't escape
jp DisplayBattleMenu
-MoveSelectionMenu: ; 3d219 (f:5219)
+MoveSelectionMenu: ; 3d320 (f:5320)
ld a, [wMoveMenuType]
dec a
jr z, .mimicmenu
@@ -2609,9 +2678,9 @@ MoveSelectionMenu: ; 3d219 (f:5219)
ld hl, wBattleMonMoves
call .loadmoves
coord hl, 4, 12
- ld b, $4
- ld c, $e
- di
+ lb bc, 4, 14
+ di ; out of pure coincidence, it is possible for vblank to occur between the di and ei
+ ; so it is necessary to put the di ei block to not cause tearing
call TextBoxBorder
coord hl, 4, 12
ld [hl], $7a
@@ -2627,8 +2696,7 @@ MoveSelectionMenu: ; 3d219 (f:5219)
ld hl, wEnemyMonMoves
call .loadmoves
coord hl, 0, 7
- ld b, $4
- ld c, $e
+ lb bc, 4, 14
call TextBoxBorder
coord hl, 2, 8
call .writemoves
@@ -2642,8 +2710,7 @@ MoveSelectionMenu: ; 3d219 (f:5219)
call AddNTimes
call .loadmoves
coord hl, 4, 7
- ld b, $4
- ld c, $e
+ lb bc, 4, 14
call TextBoxBorder
coord hl, 6, 8
call .writemoves
@@ -2657,8 +2724,6 @@ MoveSelectionMenu: ; 3d219 (f:5219)
ld a, [wMoveMenuType]
cp $1
jr z, .selectedmoveknown
- ld a, $1
- jr nc, .selectedmoveknown
ld a, [wPlayerMoveListIndex]
inc a
.selectedmoveknown
@@ -2695,7 +2760,7 @@ MoveSelectionMenu: ; 3d219 (f:5219)
ld [hl], a
; fallthrough
-SelectMenuItem: ; 3d2fe (f:52fe)
+SelectMenuItem: ; 3d3fe (f:53fe)
ld a, [wMoveMenuType]
and a
jr z, .battleselect
@@ -2725,9 +2790,9 @@ SelectMenuItem: ; 3d2fe (f:52fe)
ld hl, hFlags_0xFFFA
res 1, [hl]
bit 6, a
- jp nz, CursorUp ; up
+ jp nz, SelectMenuItem_CursorUp ; up
bit 7, a
- jp nz, CursorDown ; down
+ jp nz, SelectMenuItem_CursorDown ; down
bit 2, a
jp nz, SwapMovesInMenu ; select
bit 1, a ; B, but was it reset above?
@@ -2740,10 +2805,10 @@ SelectMenuItem: ; 3d2fe (f:52fe)
ld b, a
ld a, [wMoveMenuType]
dec a ; if not mimic
- jr nz, .nob
+ jr nz, .notB
pop af
ret
-.nob
+.notB
dec a
ld a, b
ld [wPlayerMoveListIndex], a
@@ -2760,8 +2825,8 @@ SelectMenuItem: ; 3d2fe (f:52fe)
add hl, bc
ld a, [hl]
and $3f
- jr z, .nopp
- ld a, [W_PLAYERDISABLEDMOVE]
+ jr z, .noPP
+ ld a, [wPlayerDisabledMove]
swap a
and $f
dec a
@@ -2783,25 +2848,25 @@ SelectMenuItem: ; 3d2fe (f:52fe)
.disabled
ld hl, MoveDisabledText
jr .print
-.nopp
+.noPP
ld hl, MoveNoPPText
.print
call PrintText
call LoadScreenTilesFromBuffer1
jp MoveSelectionMenu
-MoveNoPPText: ; 3d3ae (f:53ae)
+MoveNoPPText: ; 3d4ae (f:54ae)
TX_FAR _MoveNoPPText
db "@"
-MoveDisabledText: ; 3d3b3 (f:53b3)
+MoveDisabledText: ; 3d4b3 (f:54b3)
TX_FAR _MoveDisabledText
db "@"
-WhichTechniqueString: ; 3d3b8 (f:53b8)
+WhichTechniqueString: ; 3d4b8 (f:54b8)
db "WHICH TECHNIQUE?@"
-CursorUp: ; 3d3c9 (f:53c9)
+SelectMenuItem_CursorUp: ; 3d4c9 (f:54c9)
ld a, [wCurrentMenuItem]
and a
jp nz, SelectMenuItem
@@ -2811,7 +2876,7 @@ CursorUp: ; 3d3c9 (f:53c9)
ld [wCurrentMenuItem], a
jp SelectMenuItem
-CursorDown: ; 3d3dd (f:53dd)
+SelectMenuItem_CursorDown: ; 3d4dd (f:54dd)
ld a, [wCurrentMenuItem]
ld b, a
ld a, [wNumMovesMinusOne]
@@ -2824,11 +2889,60 @@ CursorDown: ; 3d3dd (f:53dd)
ld [wCurrentMenuItem], a
jp SelectMenuItem
-AnyMoveToSelect: ; 3d3f5 (f:53f5)
+Func_3d4f5: ; 3d4f5 (f:54f5)
+ bit 3, a
+ ld a, $0
+ jr nz, .asm_3d4fd
+ ld a, $1
+ ld [H_WHOSETURN], a
+.asm_3d4fd
+ call LoadScreenTilesFromBuffer1
+ call Func_3d536
+ ld a, [wTestBattlePlayerSelectedMove]
+ and a
+ jp z, MoveSelectionMenu
+ ld [wAnimationID], a
+ xor a
+ ld [wAnimationType], a
+ predef MoveAnimation
+ callab Func_78e98
+ jp MoveSelectionMenu
+
+Func_3d523: ; 3d523 (f:5523)
+ ld a, [wTestBattlePlayerSelectedMove]
+ dec a
+ jr asm_3d52d
+Func_3d529: ; 3d529 (f:5529)
+ ld a, [wTestBattlePlayerSelectedMove]
+ inc a
+asm_3d52d: ; 3d52d (f:552d)
+ ld [wTestBattlePlayerSelectedMove], a
+ call Func_3d536
+ jp MoveSelectionMenu
+
+Func_3d536: ; 3d536 (f:5536)
+ coord hl, 10, 9
+ lb bc, 2, 10
+ call TextBoxBorder
+ coord hl, 10, 17
+ ld de, wTestBattlePlayerSelectedMove
+ lb bc, LEADING_ZEROS | 1, 3
+ call PrintNumber
+ ld a, [wTestBattlePlayerSelectedMove]
+ and a
+ ret z
+ cp STRUGGLE
+ ret nc
+ ld [wd11e], a
+ call GetMoveName
+ coord hl, 13, 17
+ jp PlaceString
+
+AnyMoveToSelect: ; 3d55f (f:555f)
; return z and Struggle as the selected move if all moves have 0 PP and/or are disabled
ld a, STRUGGLE
ld [wPlayerSelectedMove], a
- ld a, [W_PLAYERDISABLEDMOVE]
+ ld a, [wPlayerDisabledMove]
and a
ld hl, wBattleMonPP
jr nz, .asm_3d40e
@@ -2880,7 +2994,7 @@ SwapMovesInMenu: ; 3d435 (f:5435)
ld hl, wBattleMonPP
call .swapBytes ; swap move PP
; update the index of the disabled move if necessary
- ld hl, W_PLAYERDISABLEDMOVE
+ ld hl, wPlayerDisabledMove
ld a, [hl]
swap a
and $f
@@ -2954,7 +3068,7 @@ PrintMenuItem: ; 3d4b6 (f:54b6)
ld b, $3
ld c, $9
call TextBoxBorder
- ld a, [W_PLAYERDISABLEDMOVE]
+ ld a, [wPlayerDisabledMove]
and a
jr z, .notDisabled
swap a
@@ -3486,7 +3600,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
jp .returnToHL
.AnyMoveDisabledCheck
- ld hl,W_PLAYERDISABLEDMOVE
+ ld hl,wPlayerDisabledMove
ld a,[hl]
and a
jr z,.ConfusedCheck
@@ -6424,7 +6538,7 @@ DoBattleTransitionAndInitBattleVariables: ; 3ec32 (f:6c32)
ld [hli], a
ld [hli], a
ld [hl], a
- ld [W_PLAYERDISABLEDMOVE], a
+ ld [wPlayerDisabledMove], a
ret
; swaps the level values of the BattleMon and EnemyMon structs
@@ -6865,7 +6979,7 @@ HandleExplodingAnimation: ; 3eed3 (f:6ed3)
ld [wAnimationType], a
PlayMoveAnimation: ; 3ef07 (f:6f07)
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
call Delay3
predef_jump MoveAnimation
@@ -8269,7 +8383,7 @@ DisableEffect: ; 3fa8a (f:7a8a)
ld a, [H_WHOSETURN]
and a
jr z, .disableEffect
- ld de, W_PLAYERDISABLEDMOVE
+ ld de, wPlayerDisabledMove
ld hl, wBattleMonMoves
.disableEffect
; no effect if target already has a move disabled
@@ -8323,7 +8437,7 @@ DisableEffect: ; 3fa8a (f:7a8a)
inc a ; 1-8 turns disabled
inc c ; move 1-4 will be disabled
swap c
- add c ; map disabled move to high nibble of wEnemyDisabledMove / W_PLAYERDISABLEDMOVE
+ add c ; map disabled move to high nibble of wEnemyDisabledMove / wPlayerDisabledMove
ld [de], a
call PlayCurrentMoveAnimation2
ld hl, wPlayerDisabledMoveNumber
@@ -8435,7 +8549,7 @@ PlayCurrentMoveAnimation2: ; 3fb89 (f:7b89)
PlayBattleAnimation2: ; 3fb96 (f:7b96)
; play animation ID at a and animation type 6 or 3
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
ld a, [H_WHOSETURN]
and a
ld a, $6
@@ -8461,10 +8575,10 @@ PlayCurrentMoveAnimation: ; 3fba8 (f:7ba8)
PlayBattleAnimation: ; 3fbb9 (f:7bb9)
; play animation ID at a and predefined animation type
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
PlayBattleAnimationGotID: ; 3fbbc (f:7bbc)
-; play animation at W_ANIMATIONID
+; play animation at wAnimationID
push hl
push de
push bc
diff --git a/engine/battle/core_.asm b/engine/battle/core_.asm
index 580d4c2e..fecfad07 100644
--- a/engine/battle/core_.asm
+++ b/engine/battle/core_.asm
@@ -425,7 +425,7 @@ MainInBattleLoop: ; 3c249 (f:4249)
jr nz, .selectEnemyMove
ld [wMoveMenuType], a
inc a
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
xor a
ld [wMenuItemToSwap], a
call MoveSelectionMenu
@@ -1596,32 +1596,1358 @@ AnyPartyAlive: ; 3cae8 (f:4ae8)
ld d, a
ret
+; tests if player mon has fainted
+; stores whether mon has fainted in Z flag
HasMonFainted: ; 3cafc (f:4afc)
- dr $3cafc,$3cb1e
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMon1HP
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld a, [hli]
+ or [hl]
+ ret nz
+ ld a, [wFirstMonsNotOutYet]
+ and a
+ jr nz, .done
+ ld hl, NoWillText
+ call PrintText
+.done
+ xor a
+ ret
+
+NoWillText: ; 3cb19 (f:4b19)
+ TX_FAR _NoWillText
+ db "@"
+
+; try to run from battle (hl = player speed, de = enemy speed)
+; stores whether the attempt was successful in carry flag
TryRunningFromBattle: ; 3cb1e (f:4b1e)
- dr $3cb1e,$3cc10
+ call IsGhostBattle
+ jp z, .canEscape ; jump if it's a ghost battle
+ ld a, [wBattleType]
+ cp $2
+ jp z, .canEscape ; jump if it's a safari battle
+ cp $3
+ jp z, .canEscape ; hurry, get away?
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ jp z, .canEscape
+ ld a, [wIsInBattle]
+ dec a
+ jr nz, .trainerBattle ; jump if it's a trainer battle
+ ld a, [wNumRunAttempts]
+ inc a
+ ld [wNumRunAttempts], a
+ ld a, [hli]
+ ld [H_MULTIPLICAND + 1], a
+ ld a, [hl]
+ ld [H_MULTIPLICAND + 2], a
+ ld a, [de]
+ ld [hEnemySpeed], a
+ inc de
+ ld a, [de]
+ ld [hEnemySpeed + 1], a
+ call LoadScreenTilesFromBuffer1
+ ld de, H_MULTIPLICAND + 1
+ ld hl, hEnemySpeed
+ ld c, 2
+ call StringCmp
+ jr nc, .canEscape ; jump if player speed greater than enemy speed
+ xor a
+ ld [H_MULTIPLICAND], a
+ ld a, 32
+ ld [H_MULTIPLIER], a
+ call Multiply ; multiply player speed by 32
+ ld a, [H_PRODUCT + 2]
+ ld [H_DIVIDEND], a
+ ld a, [H_PRODUCT + 3]
+ ld [H_DIVIDEND + 1], a
+ ld a, [hEnemySpeed]
+ ld b, a
+ ld a, [hEnemySpeed + 1]
+; divide enemy speed by 4
+ srl b
+ rr a
+ srl b
+ rr a
+ and a
+ jr z, .canEscape ; jump if enemy speed divided by 4, mod 256 is 0
+ ld [H_DIVISOR], a ; ((enemy speed / 4) % 256)
+ ld b, $2
+ call Divide ; divide (player speed * 32) by ((enemy speed / 4) % 256)
+ ld a, [H_QUOTIENT + 2]
+ and a ; is the quotient greater than 256?
+ jr nz, .canEscape ; if so, the player can escape
+ ld a, [wNumRunAttempts]
+ ld c, a
+; add 30 to the quotient for each run attempt
+.loop
+ dec c
+ jr z, .compareWithRandomValue
+ ld b, 30
+ ld a, [H_QUOTIENT + 3]
+ add b
+ ld [H_QUOTIENT + 3], a
+ jr c, .canEscape
+ jr .loop
+.compareWithRandomValue
+ call BattleRandom
+ ld b, a
+ ld a, [H_QUOTIENT + 3]
+ cp b
+ jr nc, .canEscape ; if the random value was less than or equal to the quotient
+ ; plus 30 times the number of attempts, the player can escape
+; can't escape
+ ld a, $1
+ ld [wActionResultOrTookBattleTurn], a ; you lose your turn when you can't escape
+ ld hl, CantEscapeText
+ jr .printCantEscapeOrNoRunningText
+.trainerBattle
+ ld hl, NoRunningText
+.printCantEscapeOrNoRunningText
+ call PrintText
+ ld a, 1
+ ld [wForcePlayerToChooseMon], a
+ call SaveScreenTilesToBuffer1
+ and a ; reset carry
+ ret
+.canEscape
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ ld a, $2
+ jr nz, .playSound
+; link battle
+ call SaveScreenTilesToBuffer1
+ xor a
+ ld [wActionResultOrTookBattleTurn], a
+ ld a, $f
+ ld [wPlayerMoveListIndex], a
+ call LinkBattleExchangeData
+ call LoadScreenTilesFromBuffer1
+ ld a, [wSerialExchangeNybbleReceiveData]
+ cp $f
+ ld a, $2
+ jr z, .playSound
+ dec a
+.playSound
+ ld [wBattleResult], a
+ ld a, SFX_RUN
+ call PlaySoundWaitForCurrent
+ ld hl, GotAwayText
+ call PrintText
+ call WaitForSoundToFinish
+ call SaveScreenTilesToBuffer1
+ scf ; set carry
+ ret
+
+CantEscapeText: ; 3cc01 (f:4c01)
+ TX_FAR _CantEscapeText
+ db "@"
+
+NoRunningText: ; 3cc06 (f:4c06)
+ TX_FAR _NoRunningText
+ db "@"
+
+GotAwayText: ; 3cc0b (f:4c0b)
+ TX_FAR _GotAwayText
+ db "@"
+
+; copies from party data to battle mon data when sending out a new player mon
LoadBattleMonFromParty: ; 3cc10 (f:4c10)
- dr $3cc10,$3ccfb
+ ld a, [wWhichPokemon]
+ ld bc, wPartyMon2 - wPartyMon1
+ ld hl, wPartyMon1Species
+ call AddNTimes
+ ld de, wBattleMonSpecies
+ ld bc, wBattleMonDVs - wBattleMonSpecies
+ call CopyData
+ ld bc, wPartyMon1DVs - wPartyMon1OTID
+ add hl, bc
+ ld de, wBattleMonDVs
+ ld bc, NUM_DVS
+ call CopyData
+ ld de, wBattleMonPP
+ ld bc, NUM_MOVES
+ call CopyData
+ ld de, wBattleMonLevel
+ ld bc, $b
+ call CopyData
+ ld a, [wBattleMonSpecies2]
+ ld [wd0b5], a
+ call GetMonHeader
+ ld hl, wPartyMonNicks
+ ld a, [wPlayerMonNumber]
+ call SkipFixedLengthTextEntries
+ ld de, wBattleMonNick
+ ld bc, NAME_LENGTH
+ call CopyData
+ ld hl, wBattleMonLevel
+ ld de, wPlayerMonUnmodifiedLevel ; block of memory used for unmodified stats
+ ld bc, 1 + NUM_STATS * 2
+ call CopyData
+ call ApplyBurnAndParalysisPenaltiesToPlayer
+ call ApplyBadgeStatBoosts
+ ld a, $7 ; default stat modifier
+ ld b, NUM_STAT_MODS
+ ld hl, wPlayerMonAttackMod
+.statModLoop
+ ld [hli], a
+ dec b
+ jr nz, .statModLoop
+ ret
+
+; copies from enemy party data to current enemy mon data when sending out a new enemy mon
+LoadEnemyMonFromParty: ; 3cc7d (f:4c7d)
+ ld a, [wWhichPokemon]
+ ld bc, wEnemyMon2 - wEnemyMon1
+ ld hl, wEnemyMons
+ call AddNTimes
+ ld de, wEnemyMonSpecies
+ ld bc, wEnemyMonDVs - wEnemyMonSpecies
+ call CopyData
+ ld bc, wEnemyMon1DVs - wEnemyMon1OTID
+ add hl, bc
+ ld de, wEnemyMonDVs
+ ld bc, NUM_DVS
+ call CopyData
+ ld de, wEnemyMonPP
+ ld bc, NUM_MOVES
+ call CopyData
+ ld de, wEnemyMonLevel
+ ld bc, $b
+ call CopyData
+ ld a, [wEnemyMonSpecies]
+ ld [wd0b5], a
+ call GetMonHeader
+ ld hl, wEnemyMonNicks
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+ ld de, wEnemyMonNick
+ ld bc, NAME_LENGTH
+ call CopyData
+ ld hl, wEnemyMonLevel
+ ld de, wEnemyMonUnmodifiedLevel ; block of memory used for unmodified stats
+ ld bc, 1 + NUM_STATS * 2
+ call CopyData
+ call ApplyBurnAndParalysisPenaltiesToEnemy
+ ld hl, wMonHBaseStats
+ ld de, wEnemyMonBaseStats
+ ld b, NUM_STATS
+.copyBaseStatsLoop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .copyBaseStatsLoop
+ ld a, $7 ; default stat modifier
+ ld b, NUM_STAT_MODS
+ ld hl, wEnemyMonStatMods
+.statModLoop
+ ld [hli], a
+ dec b
+ jr nz, .statModLoop
+ ld a, [wWhichPokemon]
+ ld [wEnemyMonPartyPos], a
+ ret
+
SendOutMon: ; 3ccfb (f:4cfb)
- dr $3ccfb,$3ce08
+ callab PrintSendOutMonMessage
+ ld hl, wEnemyMonHP
+ ld a, [hli]
+ or [hl] ; is enemy mon HP zero?
+ jp z, .skipDrawingEnemyHUDAndHPBar; if HP is zero, skip drawing the HUD and HP bar
+ call DrawEnemyHUDAndHPBar
+.skipDrawingEnemyHUDAndHPBar
+ call DrawPlayerHUDAndHPBar
+ predef LoadMonBackPic
+ xor a
+ ld [hStartTileID], a
+ ld hl, wBattleAndStartSavedMenuItem
+ ld [hli], a
+ ld [hl], a
+ ld [wBoostExpByExpAll], a
+ ld [wDamageMultipliers], a
+ ld [W_PLAYERMOVENUM], a
+ ld hl, wPlayerUsedMove
+ ld [hli], a
+ ld [hl], a
+ ld hl, wPlayerStatsToDouble
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ld [wPlayerDisabledMove], a
+ ld [wPlayerDisabledMoveNumber], a
+ ld [wPlayerMonMinimized], a
+ ld b, SET_PAL_BATTLE
+ call RunPaletteCommand
+ ld hl, wEnemyBattleStatus1
+ res UsingTrappingMove, [hl]
+ callab IsThisPartymonStarterPikachu
+ jr c, .starterPikachu
+ ld a, $1
+ ld [H_WHOSETURN], a
+ ld a, POOF_ANIM
+ call PlayMoveAnimation
+ coord hl, 4, 11
+ predef AnimateSendingOutMon
+ jr .playRegularCry
+.starterPikachu
+ xor a
+ ld [H_WHOSETURN], a
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ callab Func_f429f
+ callab Func_fd0d0
+ ld e, $24
+ jr c, .asm_3cd81
+ ld e, $a
+.asm_3cd81
+ callab PlayPikachuSoundClip
+ jr .done
+.playRegularCry
+ ld a, [wcf91]
+ call PlayCry
+.done
+ call PrintEmptyString
+ jp SaveScreenTilesToBuffer1
+
+; show 2 stages of the player mon getting smaller before disappearing
+AnimateRetreatingPlayerMon: ; 3cd97 (f:4d97)
+ ld a, [wWhichPokemon]
+ push af
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ callab IsThisPartymonStarterPikachu
+ pop bc
+ ld a, b
+ ld [wWhichPokemon], a
+ jr c, .starterPikachu
+ coord hl, 1, 5
+ lb bc, 7, 7
+ call ClearScreenArea
+ coord hl, 3, 7
+ lb bc, 5, 5
+ xor a
+ ld [wDownscaledMonSize], a
+ ld [hBaseTileID], a
+ predef CopyDownscaledMonTiles
+ ld c, 4
+ call DelayFrames
+ call .clearScreenArea
+ coord hl, 4, 9
+ lb bc, 3, 3
+ ld a, 1
+ ld [wDownscaledMonSize], a
+ xor a
+ ld [hBaseTileID], a
+ predef CopyDownscaledMonTiles
+ call Delay3
+ call .clearScreenArea
+ ld a, $4c
+ Coorda 5, 11
+ jr .clearScreenArea
+.starterPikachu
+ xor a
+ ld [H_WHOSETURN], a
+ callab AnimationSlideMonOff
+ ret
+.clearScreenArea
+ coord hl, 1, 5
+ lb bc, 7, 7
+ call ClearScreenArea ; jp
+ ret
+
+; reads player's current mon's HP into wBattleMonHP
ReadPlayerMonCurHPAndStatus: ; 3ce08 (f:4e08)
- dr $3ce08,$3ce1f
+ ld a, [wPlayerMonNumber]
+ ld hl, wPartyMon1HP
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld d, h
+ ld e, l
+ ld hl, wBattleMonHP
+ ld bc, $4 ; 2 bytes HP, 1 byte unknown (unused?), 1 byte status
+ jp CopyData
+
DrawHUDsAndHPBars: ; 3ce1f (f:4e1f)
- dr $3ce1f,$3ce25
+ call DrawPlayerHUDAndHPBar
+ jp DrawEnemyHUDAndHPBar
+
DrawPlayerHUDAndHPBar: ; 3ce25 (f:4e25)
- dr $3ce25,$3ceb1
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ coord hl, 9, 7
+ lb bc, 5, 11
+ call ClearScreenArea
+ callab PlacePlayerHUDTiles
+ coord hl, 18, 9
+ ld [hl], $73
+ ld de, wBattleMonNick
+ coord hl, 10, 7
+ call CenterMonName
+ call PlaceString
+ ld hl, wBattleMonSpecies
+ ld de, wLoadedMon
+ ld bc, $c
+ call CopyData
+ ld hl, wBattleMonLevel
+ ld de, wLoadedMonLevel
+ ld bc, $b
+ call CopyData
+ coord hl, 14, 8
+ push hl
+ inc hl
+ ld de, wLoadedMonStatus
+ call PrintStatusConditionNotFainted
+ pop hl
+ jr nz, .doNotPrintLevel
+ call PrintLevel
+.doNotPrintLevel
+ ld a, [wLoadedMonSpecies]
+ ld [wcf91], a
+ coord hl, 10, 9
+ predef DrawHP
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld hl, wPlayerHPBarColor
+ call GetBattleHealthBarColor
+ ld hl, wBattleMonHP
+ ld a, [hli]
+ or [hl]
+ jr z, .fainted
+ 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, .setLowHealthAlarm
+.fainted
+ ld hl, wLowHealthAlarm
+ bit 7, [hl] ;low health alarm enabled?
+ ld [hl], $0
+ ret z
+ xor a
+ ld [wChannelSoundIDs + CH4], a
+ ret
+.setLowHealthAlarm
+ ld hl, wLowHealthAlarm
+ set 7, [hl] ;enable low health alarm
+ ret
+
DrawEnemyHUDAndHPBar: ; 3ceb1 (f:4eb1)
- dr $3ceb1,$3cf55
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ coord hl, 0, 0
+ lb bc, 4, 12
+ call ClearScreenArea
+ callab PlaceEnemyHUDTiles
+ ld de, wEnemyMonNick
+ coord hl, 1, 0
+ call CenterMonName
+ call PlaceString
+ coord hl, 4, 1
+ push hl
+ inc hl
+ ld de, wEnemyMonStatus
+ call PrintStatusConditionNotFainted
+ pop hl
+ jr nz, .skipPrintLevel ; if the mon has a status condition, skip printing the level
+ ld a, [wEnemyMonLevel]
+ ld [wLoadedMonLevel], a
+ call PrintLevel
+.skipPrintLevel
+ ld hl, wEnemyMonHP
+ ld a, [hli]
+ ld [H_MULTIPLICAND + 1], a
+ ld a, [hld]
+ ld [H_MULTIPLICAND + 2], a
+ or [hl] ; is current HP zero?
+ jr nz, .hpNonzero
+; current HP is 0
+; set variables for DrawHPBar
+ ld c, a
+ ld e, a
+ ld d, $6
+ jp .drawHPBar
+.hpNonzero
+ xor a
+ ld [H_MULTIPLICAND], a
+ ld a, 48
+ ld [H_MULTIPLIER], a
+ call Multiply ; multiply current HP by 48
+ ld hl, wEnemyMonMaxHP
+ ld a, [hli]
+ ld b, a
+ ld a, [hl]
+ ld [H_DIVISOR], a
+ ld a, b
+ and a ; is max HP > 255?
+ jr z, .doDivide
+; if max HP > 255, scale both (current HP * 48) and max HP by dividing by 4 so that max HP fits in one byte
+; (it needs to be one byte so it can be used as the divisor for the Divide function)
+ ld a, [H_DIVISOR]
+ srl b
+ rr a
+ srl b
+ rr a
+ ld [H_DIVISOR], a
+ ld a, [H_PRODUCT + 2]
+ ld b, a
+ srl b
+ ld a, [H_PRODUCT + 3]
+ rr a
+ srl b
+ rr a
+ ld [H_PRODUCT + 3], a
+ ld a, b
+ ld [H_PRODUCT + 2], a
+.doDivide
+ ld a, [H_PRODUCT + 2]
+ ld [H_DIVIDEND], a
+ ld a, [H_PRODUCT + 3]
+ ld [H_DIVIDEND + 1], a
+ ld a, $2
+ ld b, a
+ call Divide ; divide (current HP * 48) by max HP
+ ld a, [H_QUOTIENT + 3]
+; set variables for DrawHPBar
+ ld e, a
+ ld a, $6
+ ld d, a
+ ld c, a
+.drawHPBar
+ xor a
+ ld [wHPBarType], a
+ coord hl, 2, 2
+ call DrawHPBar
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld hl, wEnemyHPBarColor
+
GetBattleHealthBarColor: ; 3cf55 (f:4f55)
- dr $3cf55,$3cf78
+ ld b, [hl]
+ call GetHealthBarColor
+ ld a, [hl]
+ cp b
+ ret z
+ ld b, SET_PAL_BATTLE
+ jp RunPaletteCommand
+
+; center's mon's name on the battle screen
+; if the name is 1 or 2 letters long, it is printed 2 spaces more to the right than usual
+; (i.e. for names longer than 4 letters)
+; if the name is 3 or 4 letters long, it is printed 1 space more to the right than usual
+; (i.e. for names longer than 4 letters)
+CenterMonName: ; 3cf61 (f:4f61)
+ push de
+ inc hl
+ inc hl
+ ld b, $2
+.loop
+ inc de
+ ld a, [de]
+ cp "@"
+ jr z, .done
+ inc de
+ ld a, [de]
+ cp "@"
+ jr z, .done
+ dec hl
+ dec b
+ jr nz, .loop
+.done
+ pop de
+ ret
+
DisplayBattleMenu: ; 3cf78 (f:4f78)
- dr $3cf78,$3d2c1
+ call LoadScreenTilesFromBuffer1 ; restore saved screen
+ ld a, [wBattleType]
+ and a
+ jr nz, .nonstandardbattle
+ call DrawHUDsAndHPBars
+ call PrintEmptyString
+ call SaveScreenTilesToBuffer1
+.nonstandardbattle
+ ld a, [wBattleType]
+ cp $2 ; safari
+ ld a, BATTLE_MENU_TEMPLATE
+ jr nz, .menuselected
+ ld a, SAFARI_BATTLE_MENU_TEMPLATE
+.menuselected
+ ld [wTextBoxID], a
+ call DisplayTextBoxID
+ ld a, [wBattleType]
+ cp $1
+ jr z, .doSimulatedMenuInput ; simulate menu input if it's the old man or prof. oak pikachu battle
+ cp $4
+ jr z, .doSimulatedMenuInput
+ jp .handleBattleMenuInput
+; the following happens for the old man tutorial and prof. oak pikachu battle
+.doSimulatedMenuInput
+ ld hl, wPlayerName
+ ld de, wGrassRate
+ ld bc, NAME_LENGTH
+ call CopyData ; temporarily save the player name in unused space,
+ ; which is supposed to get overwritten when entering a
+ ; map with wild Pokémon.
+ ; In Red/Blue, due to an oversight, the data
+ ; may not get overwritten (cinnabar) and the infamous
+ ; Missingno. glitch can show up. However,
+ ; this has been fixed in yellow
+ ld hl, .oldManName
+ ld a, [wBattleType]
+ dec a
+ jr z, .useOldManName
+ ld hl, .profOakName
+.useOldManName
+ ld de, wPlayerName
+ ld bc, NAME_LENGTH
+ call CopyData
+; the following simulates the keystrokes by drawing menus on screen
+ coord hl, 9, 14
+ ld [hl], "▶"
+ ld c, 20
+ call DelayFrames
+ ld [hl], " "
+ coord hl, 9, 16
+ ld [hl], "▶"
+ ld c, 20
+ call DelayFrames
+ ld [hl], $ec
+ ld a, $2 ; select the "ITEM" menu
+ jp .upperLeftMenuItemWasNotSelected
+.oldManName
+ db "OLD MAN@"
+.profOakName
+ db "PROF.OAK@"
+.handleBattleMenuInput
+ ld a, [wBattleAndStartSavedMenuItem]
+ ld [wCurrentMenuItem], a
+ ld [wLastMenuItem], a
+ sub 2 ; check if the cursor is in the left column
+ jr c, .leftColumn
+; cursor is in the right column
+ ld [wCurrentMenuItem], a
+ ld [wLastMenuItem], a
+ jr .rightColumn
+.leftColumn ; put cursor in left column of menu
+ ld a, [wBattleType]
+ cp $2
+ ld a, " "
+ jr z, .safariLeftColumn
+; put cursor in left column for normal battle menu (i.e. when it's not a Safari battle)
+ Coorda 15, 14 ; clear upper cursor position in right column
+ Coorda 15, 16 ; clear lower cursor position in right column
+ ld b, $9 ; top menu item X
+ jr .leftColumn_WaitForInput
+.safariLeftColumn
+ Coorda 13, 14
+ Coorda 13, 16
+ coord hl, 7, 14
+ ld de, wNumSafariBalls
+ lb bc, 1, 2
+ call PrintNumber
+ ld b, $1 ; top menu item X
+.leftColumn_WaitForInput
+ ld hl, wTopMenuItemY
+ ld a, $e
+ ld [hli], a ; wTopMenuItemY
+ ld a, b
+ ld [hli], a ; wTopMenuItemX
+ inc hl
+ inc hl
+ ld a, $1
+ ld [hli], a ; wMaxMenuItem
+ ld [hl], D_RIGHT | A_BUTTON ; wMenuWatchedKeys
+ call HandleMenuInput
+ bit 4, a ; check if right was pressed
+ jr nz, .rightColumn
+ jr .AButtonPressed ; the A button was pressed
+.rightColumn ; put cursor in right column of menu
+ ld a, [wBattleType]
+ cp $2
+ ld a, " "
+ jr z, .safariRightColumn
+; put cursor in right column for normal battle menu (i.e. when it's not a Safari battle)
+ Coorda 9, 14 ; clear upper cursor position in left column
+ Coorda 9, 16 ; clear lower cursor position in left column
+ ld b, $f ; top menu item X
+ jr .rightColumn_WaitForInput
+.safariRightColumn
+ Coorda 1, 14 ; clear upper cursor position in left column
+ Coorda 1, 16 ; clear lower cursor position in left column
+ coord hl, 7, 14
+ ld de, wNumSafariBalls
+ lb bc, 1, 2
+ call PrintNumber
+ ld b, $d ; top menu item X
+.rightColumn_WaitForInput
+ ld hl, wTopMenuItemY
+ ld a, $e
+ ld [hli], a ; wTopMenuItemY
+ ld a, b
+ ld [hli], a ; wTopMenuItemX
+ inc hl
+ inc hl
+ ld a, $1
+ ld [hli], a ; wMaxMenuItem
+ ld a, D_LEFT | A_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
+ call HandleMenuInput
+ bit 5, a ; check if left was pressed
+ jr nz, .leftColumn ; if left was pressed, jump
+ ld a, [wCurrentMenuItem]
+ add $2 ; if we're in the right column, the actual id is +2
+ ld [wCurrentMenuItem], a
+.AButtonPressed
+ call PlaceUnfilledArrowMenuCursor
+ ld a, [wBattleType]
+ cp HURRY_RUN_AWAY_BATTLE
+ jr z, .handleUnusedBattle
+ ld a, [wBattleType]
+ cp SAFARI_BATTLE ; is it a Safari battle?
+ ld a, [wCurrentMenuItem]
+ ld [wBattleAndStartSavedMenuItem], a
+ jr z, .handleMenuSelection
+; not Safari battle
+; swap the IDs of the item menu and party menu (this is probably because they swapped the positions
+; of these menu items in first generation English versions)
+ cp $1 ; was the item menu selected?
+ jr nz, .notItemMenu
+; item menu was selected
+ inc a ; increment a to 2
+ jr .handleMenuSelection
+.notItemMenu
+ cp $2 ; was the party menu selected?
+ jr nz, .handleMenuSelection
+; party menu selected
+ dec a ; decrement a to 1
+.handleMenuSelection
+ and a
+ jr nz, .upperLeftMenuItemWasNotSelected
+; the upper left menu item was selected
+ ld a, [wBattleType]
+ cp $2
+ jr z, .throwSafariBallWasSelected
+; the "FIGHT" menu was selected
+ xor a
+ ld [wNumRunAttempts], a
+ jp LoadScreenTilesFromBuffer1 ; restore saved screen and return
+.throwSafariBallWasSelected
+ ld a, SAFARI_BALL
+ ld [wcf91], a
+ jp UseBagItem
+.handleUnusedBattle
+ ld a, [wCurrentMenuItem]
+ cp $3
+ jp z, BattleMenu_RunWasSelected
+ ld hl, .RunAwayText
+ call PrintText
+ jp DisplayBattleMenu
+
+.RunAwayText ; 3d0df (f:50df)
+ TX_FAR _RunAwayText
+ db "@"
+
+.upperLeftMenuItemWasNotSelected ; a menu item other than the upper left item was selected
+ cp $2
+ jp nz, PartyMenuOrRockOrRun
+
+; either the bag (normal battle) or bait (safari battle) was selected
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ jr nz, .notLinkBattle
+
+; can't use items in link battles
+ ld hl, ItemsCantBeUsedHereText
+ call PrintText
+ jp DisplayBattleMenu
+
+.notLinkBattle
+ call SaveScreenTilesToBuffer2
+ ld a, [wBattleType]
+ cp $2 ; is it a safari battle?
+ jr nz, BagWasSelected
+
+; bait was selected
+ ld a, SAFARI_BAIT
+ ld [wcf91], a
+ jr UseBagItem
+
+BagWasSelected: ; 3d10a (f:510a)
+ call LoadScreenTilesFromBuffer1
+ ld a, [wBattleType]
+ and a ; is it a normal battle?
+ jr nz, .next
+
+; normal battle
+ call DrawHUDsAndHPBars
+.next
+ ld a, [wBattleType]
+ cp OLD_MAN_BATTLE ; is it the old man tutorial?
+ jr z, .simulatedInputBattle
+ cp STARTER_PIKACHU_BATTLE ; is it the prof oak battle with pikachu?
+ jr z, .simulatedInputBattle
+ jr DisplayPlayerBag
+.simulatedInputBattle
+ ld hl, SimulatedInputBattleItemList
+ ld a, l
+ ld [wListPointer], a
+ ld a, h
+ ld [wListPointer + 1], a
+ jr DisplayBagMenu
+
+SimulatedInputBattleItemList: ; 3c130 (f:5130)
+ db 1 ; # of items
+ db POKE_BALL, 1
+ db $ff
+
+DisplayPlayerBag: ; 3c134 (f:5134)
+ ; get the pointer to player's bag when in a normal battle
+ ld hl, wNumBagItems
+ ld a, l
+ ld [wListPointer], a
+ ld a, h
+ ld [wListPointer + 1], a
+
+DisplayBagMenu: ; 3c13f (f:513f)
+ xor a
+ ld [wPrintItemPrices], a
+ ld a, ITEMLISTMENU
+ ld [wListMenuID], a
+ ld a, [wBagSavedMenuItem]
+ ld [wCurrentMenuItem], a
+ call DisplayListMenuID
+ ld a, [wCurrentMenuItem]
+ ld [wBagSavedMenuItem], a
+ ld a, $0
+ ld [wMenuWatchMovingOutOfBounds], a
+ ld [wMenuItemToSwap], a
+ jp c, DisplayBattleMenu ; go back to battle menu if an item was not selected
+
+UseBagItem: ; 3c162 (f:5162)
+ ; either use an item from the bag or use a safari zone item
+ ld a, [wcf91]
+ ld [wd11e], a
+ call GetItemName
+ call CopyStringToCF4B ; copy name
+ xor a
+ ld [wPseudoItemID], a
+ call UseItem
+ call LoadHudTilePatterns
+ call ClearSprites
+ xor a
+ ld [wCurrentMenuItem], a
+ ld a, [wBattleType]
+ cp SAFARI_BATTLE ; is it a safari battle?
+ jr z, .checkIfMonCaptured
+
+ ld a, [wActionResultOrTookBattleTurn]
+ and a ; was the item used successfully?
+ jp z, BagWasSelected ; if not, go back to the bag menu
+
+ ld a, [wPlayerBattleStatus1]
+ bit UsingTrappingMove, a ; is the player using a multi-turn move like wrap?
+ jr z, .checkIfMonCaptured
+ ld hl, wPlayerNumAttacksLeft
+ dec [hl]
+ jr nz, .checkIfMonCaptured
+ ld hl, wPlayerBattleStatus1
+ res UsingTrappingMove, [hl] ; not using multi-turn move any more
+
+.checkIfMonCaptured
+ ld a, [wCapturedMonSpecies]
+ and a ; was the enemy mon captured with a ball?
+ jr nz, .returnAfterCapturingMon
+
+ ld a, [wBattleType]
+ cp SAFARI_BATTLE ; is it a safari battle?
+ jr z, .returnAfterUsingItem_NoCapture
+; not a safari battle
+ call LoadScreenTilesFromBuffer1
+ call DrawHUDsAndHPBars
+ call Delay3
+.returnAfterUsingItem_NoCapture
+
+ call GBPalNormal
+ and a ; reset carry
+ ret
+
+.returnAfterCapturingMon
+ call GBPalNormal
+ xor a
+ ld [wCapturedMonSpecies], a
+ ld a, $2
+ ld [wBattleResult], a
+ scf ; set carry
+ ret
+
+ItemsCantBeUsedHereText: ; 3d1c8 (f:51c8)
+ TX_FAR _ItemsCantBeUsedHereText
+ db "@"
+
+PartyMenuOrRockOrRun: ; 3d1cd (f:51cd)
+ dec a ; was Run selected?
+ jp nz, BattleMenu_RunWasSelected
+; party menu or rock was selected
+ call SaveScreenTilesToBuffer2
+ ld a, [wBattleType]
+ cp $2 ; is it a safari battle?
+ jr nz, .partyMenuWasSelected
+; safari battle
+ ld a, SAFARI_ROCK
+ ld [wcf91], a
+ jp UseBagItem
+.partyMenuWasSelected
+ call LoadScreenTilesFromBuffer1
+ xor a ; NORMAL_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
+ ld [wMenuItemToSwap], a
+ call DisplayPartyMenu
+.checkIfPartyMonWasSelected
+ jp nc, .partyMonWasSelected ; if a party mon was selected, jump, else we quit the party menu
+.quitPartyMenu
+ call ClearSprites
+ call GBPalWhiteOut
+ call LoadHudTilePatterns
+ call LoadScreenTilesFromBuffer2
+ call RunDefaultPaletteCommand
+ call GBPalNormal
+ jp DisplayBattleMenu
+.partyMonDeselected
+ coord hl, 11, 11
+ ld bc, 6 * SCREEN_WIDTH + 9
+ ld a, " "
+ call FillMemory
+ xor a ; NORMAL_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
+ call GoBackToPartyMenu
+ jr .checkIfPartyMonWasSelected
+.partyMonWasSelected
+ ld a, SWITCH_STATS_CANCEL_MENU_TEMPLATE
+ ld [wTextBoxID], a
+ call DisplayTextBoxID
+ ld hl, wTopMenuItemY
+ ld a, $c
+ ld [hli], a ; wTopMenuItemY
+ ld [hli], a ; wTopMenuItemX
+ xor a
+ ld [hli], a ; wCurrentMenuItem
+ inc hl
+ ld a, $2
+ ld [hli], a ; wMaxMenuItem
+ ld a, B_BUTTON | A_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
+ xor a
+ ld [hl], a ; wLastMenuItem
+ call HandleMenuInput
+ bit 1, a ; was A pressed?
+ jr nz, .partyMonDeselected ; if B was pressed, jump
+; A was pressed
+ call PlaceUnfilledArrowMenuCursor
+ ld a, [wCurrentMenuItem]
+ cp $2 ; was Cancel selected?
+ jr z, .quitPartyMenu ; if so, quit the party menu entirely
+ and a ; was Switch selected?
+ jr z, .switchMon ; if so, jump
+; Stats was selected
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
+ ld hl, wPartyMon1
+ call ClearSprites
+; display the two status screens
+ predef StatusScreen
+ predef StatusScreen2
+; now we need to reload the enemy mon pic
+ ld a, $1
+ ld [H_WHOSETURN], a
+ ld a, [wEnemyBattleStatus2]
+ bit HasSubstituteUp, a ; does the enemy mon have a substitute?
+ ld hl, AnimationSubstitute
+ jr nz, .doEnemyMonAnimation
+; enemy mon doesn't have substitute
+ ld a, [wEnemyMonMinimized]
+ and a ; has the enemy mon used Minimise?
+ ld hl, AnimationMinimizeMon
+ jr nz, .doEnemyMonAnimation
+; enemy mon is not minimised
+ ld a, [wEnemyMonSpecies]
+ ld [wcf91], a
+ ld [wd0b5], a
+ call GetMonHeader
+ ld de, vFrontPic
+ call LoadMonFrontSprite
+ jr .enemyMonPicReloaded
+.doEnemyMonAnimation
+ ld b, BANK(AnimationSubstitute) ; BANK(AnimationMinimizeMon)
+ call Bankswitch
+.enemyMonPicReloaded ; enemy mon pic has been reloaded, so return to the party menu
+ jp .partyMenuWasSelected
+.switchMon
+ ld a, [wPlayerMonNumber]
+ ld d, a
+ ld a, [wWhichPokemon]
+ cp d ; check if the mon to switch to is already out
+ jr nz, .notAlreadyOut
+; mon is already out
+ ld hl, AlreadyOutText
+ call PrintText
+ jp .partyMonDeselected
+.notAlreadyOut
+ call HasMonFainted
+ jp z, .partyMonDeselected ; can't switch to fainted mon
+ ld a, $1
+ ld [wActionResultOrTookBattleTurn], a
+ call GBPalWhiteOut
+ call ClearSprites
+ call LoadHudTilePatterns
+ call LoadScreenTilesFromBuffer1
+ call RunDefaultPaletteCommand
+ call GBPalNormal
+; fall through to SwitchPlayerMon
+
SwitchPlayerMon: ; 3d2c1 (f:52c1)
- dr $3d2c1,$3d2fc
+ callab RetreatMon
+ ld c, 50
+ call DelayFrames
+ call AnimateRetreatingPlayerMon
+ ld a, [wWhichPokemon]
+ ld [wPlayerMonNumber], a
+ ld c, a
+ ld b, FLAG_SET
+ push bc
+ ld hl, wPartyGainExpFlags
+ predef FlagActionPredef
+ pop bc
+ ld hl, wPartyFoughtCurrentEnemyFlags
+ predef FlagActionPredef
+ call LoadBattleMonFromParty
+ call SendOutMon
+ call SaveScreenTilesToBuffer1
+ ld a, $2
+ ld [wCurrentMenuItem], a
+ and a
+ ret
+
AlreadyOutText: ; 3d2fc (f:52fc)
- dr $3d2fc,$3d320
+ TX_FAR _AlreadyOutText
+ db "@"
+
+BattleMenu_RunWasSelected: ; 3d301 (f:5301)
+ call LoadScreenTilesFromBuffer1
+ ld a, $3
+ ld [wCurrentMenuItem], a
+ ld hl, wBattleMonSpeed
+ ld de, wEnemyMonSpeed
+ call TryRunningFromBattle
+ ld a, 0
+ ld [wForcePlayerToChooseMon], a
+ ret c
+ ld a, [wActionResultOrTookBattleTurn]
+ and a
+ ret nz ; return if the player couldn't escape
+ jp DisplayBattleMenu
+
MoveSelectionMenu: ; 3d320 (f:5320)
- dr $3d320,$3d6d6
+ ld a, [wMoveMenuType]
+ dec a
+ jr z, .mimicmenu
+ dec a
+ jr z, .relearnmenu
+ jr .regularmenu
+
+.loadmoves
+ ld de, wMoves
+ ld bc, NUM_MOVES
+ call CopyData
+ callab FormatMovesString
+ ret
+
+.writemoves
+ ld de, wMovesString
+ ld a, [hFlags_0xFFFA]
+ set 2, a
+ ld [hFlags_0xFFFA], a
+ call PlaceString
+ ld a, [hFlags_0xFFFA]
+ res 2, a
+ ld [hFlags_0xFFFA], a
+ ret
+
+.regularmenu
+ call AnyMoveToSelect
+ ret z
+ ld hl, wBattleMonMoves
+ call .loadmoves
+ coord hl, 4, 12
+ lb bc, 4, 14
+ di ; out of pure coincidence, it is possible for vblank to occur between the di and ei
+ ; so it is necessary to put the di ei block to not cause tearing
+ call TextBoxBorder
+ coord hl, 4, 12
+ ld [hl], $7a
+ coord hl, 10, 12
+ ld [hl], $7e
+ ei
+ coord hl, 6, 13
+ call .writemoves
+ ld b, $5
+ ld a, $c
+ jr .menuset
+.mimicmenu
+ ld hl, wEnemyMonMoves
+ call .loadmoves
+ coord hl, 0, 7
+ lb bc, 4, 14
+ call TextBoxBorder
+ coord hl, 2, 8
+ call .writemoves
+ ld b, $1
+ ld a, $7
+ jr .menuset
+.relearnmenu
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMon1Moves
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ call .loadmoves
+ coord hl, 4, 7
+ lb bc, 4, 14
+ call TextBoxBorder
+ coord hl, 6, 8
+ call .writemoves
+ ld b, $5
+ ld a, $7
+.menuset
+ ld hl, wTopMenuItemY
+ ld [hli], a ; wTopMenuItemY
+ ld a, b
+ ld [hli], a ; wTopMenuItemX
+ ld a, [wMoveMenuType]
+ cp $1
+ jr z, .selectedmoveknown
+ ld a, [wPlayerMoveListIndex]
+ inc a
+.selectedmoveknown
+ ld [hli], a ; wCurrentMenuItem
+ inc hl ; wTileBehindCursor untouched
+ ld a, [wNumMovesMinusOne]
+ inc a
+ inc a
+ ld [hli], a ; wMaxMenuItem
+ ld a, [wMoveMenuType]
+ dec a
+ ld b, D_UP | D_DOWN | A_BUTTON
+ jr z, .matchedkeyspicked
+ dec a
+ ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON
+ jr z, .matchedkeyspicked
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ jr z, .matchedkeyspicked
+ ld a, [wFlags_D733]
+ bit BIT_TEST_BATTLE, a
+ ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON | SELECT
+ jr z, .matchedkeyspicked
+ ld b, $ff
+.matchedkeyspicked
+ ld a, b
+ ld [hli], a ; wMenuWatchedKeys
+ ld a, [wMoveMenuType]
+ cp $1
+ jr z, .movelistindex1
+ ld a, [wPlayerMoveListIndex]
+ inc a
+.movelistindex1
+ ld [hl], a
+; fallthrough
+
+SelectMenuItem: ; 3d3fe (f:53fe)
+ ld a, [wMoveMenuType]
+ and a
+ jr z, .battleselect
+ dec a
+ jr nz, .select
+ coord hl, 1, 14
+ ld de, WhichTechniqueString
+ call PlaceString
+ jr .select
+.battleselect
+ ld a, [wFlags_D733]
+ bit BIT_TEST_BATTLE, a
+ jr nz, .select
+ call PrintMenuItem
+ ld a, [wMenuItemToSwap]
+ and a
+ jr z, .select
+ coord hl, 5, 13
+ dec a
+ ld bc, SCREEN_WIDTH
+ call AddNTimes
+ ld [hl], $ec
+.select
+ ld hl, hFlags_0xFFFA
+ set 1, [hl]
+ call HandleMenuInput
+ ld hl, hFlags_0xFFFA
+ res 1, [hl]
+ bit 6, a
+ jp nz, SelectMenuItem_CursorUp ; up
+ bit 7, a
+ jp nz, SelectMenuItem_CursorDown ; down
+ bit 2, a
+ jp nz, SwapMovesInMenu ; select
+ bit 1, a ; B, but was it reset above?
+ push af
+ xor a
+ ld [wMenuItemToSwap], a
+ ld a, [wCurrentMenuItem]
+ dec a
+ ld [wCurrentMenuItem], a
+ ld b, a
+ ld a, [wMoveMenuType]
+ dec a ; if not mimic
+ jr nz, .notB
+ pop af
+ ret
+.notB
+ dec a
+ ld a, b
+ ld [wPlayerMoveListIndex], a
+ jr nz, .moveselected
+ pop af
+ ret
+.moveselected
+ pop af
+ ret nz
+ ld hl, wBattleMonPP
+ ld a, [wCurrentMenuItem]
+ ld c, a
+ ld b, $0
+ add hl, bc
+ ld a, [hl]
+ and $3f
+ jr z, .noPP
+ ld a, [wPlayerDisabledMove]
+ swap a
+ and $f
+ dec a
+ cp c
+ jr z, .disabled
+ ld a, [wPlayerBattleStatus3]
+ bit 3, a ; transformed
+ jr nz, .dummy ; game freak derp
+.dummy
+ ld a, [wCurrentMenuItem]
+ ld hl, wBattleMonMoves
+ ld c, a
+ ld b, $0
+ add hl, bc
+ ld a, [hl]
+ ld [wPlayerSelectedMove], a
+ xor a
+ ret
+.disabled
+ ld hl, MoveDisabledText
+ jr .print
+.noPP
+ ld hl, MoveNoPPText
+.print
+ call PrintText
+ call LoadScreenTilesFromBuffer1
+ jp MoveSelectionMenu
+
+MoveNoPPText: ; 3d4ae (f:54ae)
+ TX_FAR _MoveNoPPText
+ db "@"
+
+MoveDisabledText: ; 3d4b3 (f:54b3)
+ TX_FAR _MoveDisabledText
+ db "@"
+
+WhichTechniqueString: ; 3d4b8 (f:54b8)
+ db "WHICH TECHNIQUE?@"
+
+SelectMenuItem_CursorUp: ; 3d4c9 (f:54c9)
+ ld a, [wCurrentMenuItem]
+ and a
+ jp nz, SelectMenuItem
+ call EraseMenuCursor
+ ld a, [wNumMovesMinusOne]
+ inc a
+ ld [wCurrentMenuItem], a
+ jp SelectMenuItem
+
+SelectMenuItem_CursorDown: ; 3d4dd (f:54dd)
+ ld a, [wCurrentMenuItem]
+ ld b, a
+ ld a, [wNumMovesMinusOne]
+ inc a
+ inc a
+ cp b
+ jp nz, SelectMenuItem
+ call EraseMenuCursor
+ ld a, $1
+ ld [wCurrentMenuItem], a
+ jp SelectMenuItem
+
+Func_3d4f5: ; 3d4f5 (f:54f5)
+ bit 3, a
+ ld a, $0
+ jr nz, .asm_3d4fd
+ ld a, $1
+.asm_3d4fd
+ ld [H_WHOSETURN], a
+ call LoadScreenTilesFromBuffer1
+ call Func_3d536
+ ld a, [wTestBattlePlayerSelectedMove]
+ and a
+ jp z, MoveSelectionMenu
+ ld [wAnimationID], a
+ xor a
+ ld [wAnimationType], a
+ predef MoveAnimation
+ callab Func_78e98
+ jp MoveSelectionMenu
+
+Func_3d523: ; 3d523 (f:5523)
+ ld a, [wTestBattlePlayerSelectedMove]
+ dec a
+ jr asm_3d52d
+Func_3d529: ; 3d529 (f:5529)
+ ld a, [wTestBattlePlayerSelectedMove]
+ inc a
+asm_3d52d: ; 3d52d (f:552d)
+ ld [wTestBattlePlayerSelectedMove], a
+ call Func_3d536
+ jp MoveSelectionMenu
+
+Func_3d536: ; 3d536 (f:5536)
+ coord hl, 10, 16
+ lb bc, 2, 10
+ call ClearScreenArea
+ coord hl, 10, 17
+ ld de, wTestBattlePlayerSelectedMove
+ lb bc, LEADING_ZEROES | 1, 3
+ call PrintNumber
+ ld a, [wTestBattlePlayerSelectedMove]
+ and a
+ ret z
+ cp STRUGGLE
+ ret nc
+ ld [wd11e], a
+ call GetMoveName
+ coord hl, 13, 17
+ jp PlaceString
+
+AnyMoveToSelect: ; 3d55f (f:555f)
+ dr $3d55f,$3d5a0
+SwapMovesInMenu: ; 3d5a0 (f:55a0)
+ dr $3d5a0,$3d629
+PrintMenuItem: ; 3d629 (f:5629)
+ dr $3d629,$3d6d6
SelectEnemyMove: ; 3d6d6 (f:56d6)
dr $3d6d6,$3d777
LinkBattleExchangeData: ; 3d777 (f:5777)
@@ -1690,9 +3016,15 @@ DoBattleTransitionAndInitBattleVariables: ; 3edb8 (f:6db8)
LoadPlayerBackPic: ; 3ee18 (f:6e18)
dr $3ee18,$3ee9e
ScrollTrainerPicAfterBattle: ; 3ee9e (f:6e9e)
- dr $3ee9e,$3eeb3
+ dr $3ee9e,$3eea6
+ApplyBurnAndParalysisPenaltiesToPlayer: ; 3eea6 (f:6ea6)
+ dr $3eea6,$3eeaa
+ApplyBurnAndParalysisPenaltiesToEnemy: ; 3eeaa (f:6eaa)
+ dr $3eeaa,$3eeb3
QuarterSpeedDueToParalysis: ; 3eeb3 (f:6eb3)
- dr $3eeb3,$3efe4
+ dr $3eeb3,$3efa5
+ApplyBadgeStatBoosts: ; 3efa5 (f:6fa5)
+ dr $3efa5,$3efe4
LoadHudAndHpBarAndStatusTilePatterns: ; 3efe4 (f:6fe4)
dr $3efe4,$3efe7
LoadHudTilePatterns: ; 3efe7 (f:6fe7)
diff --git a/engine/battle/moveEffects/haze_effect.asm b/engine/battle/moveEffects/haze_effect.asm
index e7e7a68a..eec68182 100644
--- a/engine/battle/moveEffects/haze_effect.asm
+++ b/engine/battle/moveEffects/haze_effect.asm
@@ -31,7 +31,7 @@ HazeEffect_: ; 139a4 (4:79a4)
.cureVolatileStatuses
xor a
- ld [W_PLAYERDISABLEDMOVE], a
+ ld [wPlayerDisabledMove], a
ld [wEnemyDisabledMove], a
ld hl, wPlayerDisabledMoveNumber
ld [hli], a
diff --git a/engine/hidden_object_functions17.asm b/engine/hidden_object_functions17.asm
index 77f3eeb9..90b26578 100755
--- a/engine/hidden_object_functions17.asm
+++ b/engine/hidden_object_functions17.asm
@@ -95,7 +95,7 @@ LinkCableHelp: ; 5dc29 (17:5c29)
ld hl, LinkCableHelpText1
call PrintText
xor a
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld a, A_BUTTON | B_BUTTON
@@ -179,7 +179,7 @@ ViridianSchoolBlackboard: ; 5dced (17:5ced)
ld hl, ViridianSchoolBlackboardText1
call PrintText
xor a
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld a, D_LEFT | D_RIGHT | A_BUTTON | B_BUTTON
@@ -217,7 +217,7 @@ ViridianSchoolBlackboard: ; 5dced (17:5ced)
ld a, $6
ld [wTopMenuItemX], a
ld a, $3
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
jr .blackboardLoop
.didNotPressRight
bit 5, a ; pressed left
@@ -230,12 +230,12 @@ ViridianSchoolBlackboard: ; 5dced (17:5ced)
ld a, $1
ld [wTopMenuItemX], a
xor a
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
jr .blackboardLoop
.didNotPressLeftOrRight
ld a, [wCurrentMenuItem]
ld b, a
- ld a, [W_ANIMATIONID]
+ ld a, [wAnimationID]
add b
cp $5 ; cursor is pointing to "QUIT"
jr z, .exitBlackboard
diff --git a/engine/hidden_object_functions7.asm b/engine/hidden_object_functions7.asm
index b61dc68a..33ad1c9b 100755
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -391,7 +391,7 @@ BillsHousePokemonList: ; 1ec05 (7:6c05)
ld hl, BillsHousePokemonListText1
call PrintText
xor a
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld a, A_BUTTON | B_BUTTON
diff --git a/engine/items/items.asm b/engine/items/items.asm
index bda01e27..e0cccf01 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -332,7 +332,7 @@ ItemUseBall: ; d3ad (3:53ad)
ld c,20
call DelayFrames
ld a,TOSS_ANIM
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
xor a
ld [H_WHOSETURN],a
ld [wAnimationType],a
@@ -1441,7 +1441,7 @@ ItemUseRock: ; dd87 (3:5d87)
ld de,wSafariBaitFactor ; bait factor
BaitRockCommon: ; dd9f (3:5d9f)
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
xor a
ld [wAnimationType],a
ld [H_WHOSETURN],a
@@ -2446,7 +2446,7 @@ ThrowBallAtTrainerMon: ; e4ca (3:64ca)
call LoadScreenTilesFromBuffer1 ; restore saved screen
call Delay3
ld a,TOSS_ANIM
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
predef MoveAnimation ; do animation
ld hl,ThrowBallAtTrainerMonText1
call PrintText
diff --git a/engine/menu/main_menu.asm b/engine/menu/main_menu.asm
index 9a7b8de7..48346a02 100755
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -20,7 +20,7 @@ MainMenu: ; 5ba6 (1:5ba6)
ld [hli],a
ld [hli],a
ld [hl],a
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
ld hl,wd72e
res 6,[hl]
call ClearScreen
diff --git a/engine/oak_speech.asm b/engine/oak_speech.asm
index 045bbb68..5cbfbee1 100755
--- a/engine/oak_speech.asm
+++ b/engine/oak_speech.asm
@@ -56,7 +56,7 @@ OakSpeech: ; 5e85 (1:5e85)
ld a,1
ld [wItemQuantity],a
call AddItemToInventory ; give one potion
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
ld [wDestinationMap],a
call SpecialWarpIn
xor a
diff --git a/engine/predefs.asm b/engine/predefs.asm
index d4e3511c..fa6e29df 100755
--- a/engine/predefs.asm
+++ b/engine/predefs.asm
@@ -58,7 +58,7 @@ PredefPointers:: ; f681d (3d:681d)
;add_predef Func_3f073
;add_predef ScaleSpriteByTwo
;add_predef LoadMonBackPic
- ;add_predef Func_79aba
+ ;add_predef CopyDownscaledMonTiles
;add_predef LoadMissableObjects
;add_predef HealParty
;add_predef MoveAnimation; 08 play move animation
diff --git a/engine/trade.asm b/engine/trade.asm
index bef9a540..fd5eb1d1 100755
--- a/engine/trade.asm
+++ b/engine/trade.asm
@@ -851,7 +851,7 @@ TradeforText: ; 41986 (10:5986)
db "@"
Trade_ShowAnimation: ; 4198b (10:598b)
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
xor a
ld [wAnimationType], a
predef_jump MoveAnimation
diff --git a/wram.asm b/wram.asm
index 89edd69e..9bac935b 100755
--- a/wram.asm
+++ b/wram.asm
@@ -1700,7 +1700,7 @@ W_PLAYERCONFUSEDCOUNTER:: ; d06b
wPlayerToxicCounter:: ; d06c
ds 1
-W_PLAYERDISABLEDMOVE:: ; d06d
+wPlayerDisabledMove:: ; d06d
; high nibble: which move is disabled (1-4)
; low nibble: disable turns left
ds 1
@@ -1749,7 +1749,7 @@ wObjectToShow:: ; d07a
ds 1
-W_ANIMATIONID:: ; d07c
+wAnimationID:: ; d07c
; ID number of the current battle animation
ds 1
diff --git a/yellow/main.asm b/yellow/main.asm
index 3671df39..39f39df5 100755
--- a/yellow/main.asm
+++ b/yellow/main.asm
@@ -4207,9 +4207,15 @@ SECTION "bank1E",ROMX,BANK[$1E]
AnimationTileset2: ; 78757 (1e:4757)
dr $78757,$78c17
SlotMachineTiles2: ; 78c17 (1e:4c17)
- dr $78c17,$79353
+ dr $78c17,$78e98
+Func_78e98: ; 78e98 (1e:4e98)
+ dr $78e98,$79349
+AnimationSlideMonOff: ; 79349 (1e:5349)
+ dr $79349,$79353
AnimationSlideEnemyMonOff: ; 79353 (1e:5353)
- dr $79353,$797af
+ dr $79353,$7966e
+AnimationMinimizeMon: ; 7966e (1e:566e)
+ dr $7966e,$797af
AnimationSubstitute: ; 797af (1e:57af)
dr $797af,$79816
HideSubstituteShowMonAnim: ; 79816 (1e:5816)