summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluckytyphlosion <alan.rj.huang@gmail.com>2015-12-29 14:53:57 -0500
committerluckytyphlosion <alan.rj.huang@gmail.com>2015-12-29 14:53:57 -0500
commitf0915e2b664f3c045cdea710aeced219396db8bb (patch)
tree791dd3a4cc749f482593f2bd3746f904304430d0
parent47979336e29d7e22d524e35ddc50576874ead009 (diff)
More BankF documentation
Also introduce bit direction constants and setpal macros
-rw-r--r--constants/misc_constants.asm12
-rw-r--r--constants/predef_constants.asm2
-rw-r--r--engine/bank3d/main.asm4
-rw-r--r--engine/bank3f/main.asm12
-rwxr-xr-xengine/battle/core.asm131
-rw-r--r--engine/battle/core_.asm1064
-rwxr-xr-xengine/evos_moves.asm2
-rwxr-xr-xengine/hall_of_fame.asm2
-rwxr-xr-xengine/items/items.asm4
-rw-r--r--engine/menu/bills_pc.asm8
-rwxr-xr-xengine/menu/party_menu.asm2
-rwxr-xr-xengine/menu/status_screen.asm4
-rwxr-xr-xengine/overworld/npc_movement.asm2
-rwxr-xr-xengine/overworld/player_animations.asm2
-rwxr-xr-xengine/overworld/pokecenter.asm8
-rw-r--r--home.asm12
-rw-r--r--home/overworld.asm8
-rw-r--r--macros.asm16
-rwxr-xr-xmain.asm4
-rwxr-xr-xscripts/halloffameroom.asm2
-rwxr-xr-xscripts/oakslab.asm2
-rwxr-xr-xscripts/seafoamislands4.asm4
-rwxr-xr-xscripts/seafoamislands5.asm2
-rwxr-xr-xwram.asm6
-rwxr-xr-xyellow/main.asm8
25 files changed, 1205 insertions, 118 deletions
diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm
index 527152fe..3f48b091 100644
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -26,6 +26,16 @@ D_LEFT EQU %00100000
D_UP EQU %01000000
D_DOWN EQU %10000000
+const_value set 0
+ const BIT_A_BUTTON
+ const BIT_B_BUTTON
+ const BIT_SELECT
+ const BIT_START
+ const BIT_D_RIGHT
+ const BIT_D_LEFT
+ const BIT_D_UP
+ const BIT_D_DOWN
+
SCREEN_WIDTH EQU 20
SCREEN_HEIGHT EQU 18
@@ -207,5 +217,5 @@ const_value set 1
const PIKAHAPPY_DEPOSITED
const PIKAHAPPY_FAINTED
const PIKAHAPPY_PSNFNT
- const PIKAHAPPY_10
+ const PIKAHAPPY_CARELESSTRAINER
const PIKAHAPPY_TRADE
diff --git a/constants/predef_constants.asm b/constants/predef_constants.asm
index 34b751e4..c4d0c208 100644
--- a/constants/predef_constants.asm
+++ b/constants/predef_constants.asm
@@ -2,7 +2,7 @@ const_value = 0
predef_const DrawPlayerHUDAndHPBar
predef_const CopyUncompressedPicToTilemap
- predef_const Func_3f073
+ predef_const AnimateSendingOutMon
predef_const ScaleSpriteByTwo
predef_const LoadMonBackPic
predef_const Func_79aba
diff --git a/engine/bank3d/main.asm b/engine/bank3d/main.asm
index 0c4c3544..cc78a114 100644
--- a/engine/bank3d/main.asm
+++ b/engine/bank3d/main.asm
@@ -60,14 +60,14 @@ ModifyPikachuHappiness:: ; f430a (3d:430a)
cp PIKAHAPPY_WALKING
jr z, .checkanywhereinparty
push de
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
pop de
ret nc
jr .proceed
.checkanywhereinparty
push de
- callab IsPikachuInOurParty
+ callab IsStarterPikachuInOurParty
pop de
ret nc
diff --git a/engine/bank3f/main.asm b/engine/bank3f/main.asm
index c0ff4b21..21566031 100644
--- a/engine/bank3f/main.asm
+++ b/engine/bank3f/main.asm
@@ -10,7 +10,7 @@ Func_fc4dd:: ; fc4dd (3f:44dd)
ld a,[wd430]
bit 7,a
jr nz,.asm_fc4f8
- call IsPikachuInOurParty
+ call IsStarterPikachuInOurParty
jr nc,.asm_fc4f8
ld a,[wWalkBikeSurfState]
and a
@@ -1477,7 +1477,7 @@ Func_fcdad: ; fcdad (3f:4dad)
pop bc
ret
-IsPikachuInOurParty:: ; fcdb8 (3f:4db8)
+IsStarterPikachuInOurParty:: ; fcdb8 (3f:4db8)
ld hl,wPartySpecies
ld de,wPartyMon1OTID
ld bc,wPartyMonOT
@@ -1541,13 +1541,13 @@ IsPikachuInOurParty:: ; fcdb8 (3f:4db8)
and a
ret
-Func_fce0d:: ; fce0d (3f:4e0d)
+IsThisPartymonStarterPikachu_Box:: ; fce0d (3f:4e0d)
ld hl,wBoxMon1
ld bc,wBoxMon2 - wBoxMon1
ld de,wBoxMonOT
jr asm_fce21
-IsThisPartymonOurPikachu:: ; fce18 (3f:4e18)
+IsThisPartymonStarterPikachu_Party:: ; fce18 (3f:4e18)
ld hl,wPartyMon1
ld bc,wPartyMon2 - wPartyMon1
ld de,wPartyMonOT
@@ -1590,7 +1590,7 @@ asm_fce21: ; fce21 (3f:4e21)
Func_fce5a:: ; fce5a (3f:4e5a)
push de
- call IsPikachuInOurParty
+ call IsStarterPikachuInOurParty
pop de
ret nc
ld a,d
@@ -1619,7 +1619,7 @@ Func_fce73:: ; fce73 (3f:4e73)
cp $ff
jr z,.asm_fcea9
push hl
- call IsThisPartymonOurPikachu
+ call IsThisPartymonStarterPikachu_Party
pop hl
jr nc,.asm_fce9e
ld a,[wWhichPokemon]
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index e6c5b3c1..e33295dc 100755
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -565,7 +565,7 @@ MainInBattleLoop: ; 3c249 (f:4249)
call CheckNumAttacksLeft
jp MainInBattleLoop
-HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd)
+HandlePoisonBurnLeechSeed: ; 3c3d3 (f:43d3)
ld hl, wBattleMonHP
ld de, wBattleMonStatus
ld a, [H_WHOSETURN]
@@ -629,15 +629,15 @@ HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd)
xor a
ret
-HurtByPoisonText: ; 3c42e (f:442e)
+HurtByPoisonText: ; 3c444 (f:4444)
TX_FAR _HurtByPoisonText
db "@"
-HurtByBurnText: ; 3c433 (f:4433)
+HurtByBurnText: ; 3c449 (f:4449)
TX_FAR _HurtByBurnText
db "@"
-HurtByLeechSeedText: ; 3c438 (f:4438)
+HurtByLeechSeedText: ; 3c44e (f:444e)
TX_FAR _HurtByLeechSeedText
db "@"
@@ -668,12 +668,12 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d)
inc c ; damage is at least 1
.nonZeroDamage
ld hl, wPlayerBattleStatus3
- ld de, W_PLAYERTOXICCOUNTER
+ ld de, wPlayerToxicCounter
ld a, [H_WHOSETURN]
and a
jr z, .playersTurn
ld hl, wEnemyBattleStatus3
- ld de, W_ENEMYTOXICCOUNTER
+ ld de, wEnemyToxicCounter
.playersTurn
bit BadlyPoisoned, [hl]
jr z, .noToxic
@@ -713,7 +713,7 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d)
; adds bc to enemy HP
; bc isn't updated if HP substracted was capped to prevent overkill
-HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3)
+HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4b9 (f:44b9)
push hl
ld hl, wEnemyMonMaxHP
ld a, [H_WHOSETURN]
@@ -763,7 +763,7 @@ HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3)
pop hl
ret
-UpdateCurMonHPBar: ; 3c4f6 (f:44f6)
+UpdateCurMonHPBar: ; 3c50c (f:450c)
coord hl, 10, 9 ; tile pointer to player HP bar
ld a, [H_WHOSETURN]
and a
@@ -778,7 +778,7 @@ UpdateCurMonHPBar: ; 3c4f6 (f:44f6)
pop bc
ret
-CheckNumAttacksLeft: ; 3c50f (f:450f)
+CheckNumAttacksLeft: ; 3c525 (f:4525)
ld a, [wPlayerNumAttacksLeft]
and a
jr nz, .checkEnemy
@@ -794,7 +794,7 @@ CheckNumAttacksLeft: ; 3c50f (f:450f)
res UsingTrappingMove, [hl] ; enemy not using multi-turn attack like wrap any more
ret
-HandleEnemyMonFainted: ; 3c525 (f:4525)
+HandleEnemyMonFainted: ; 3c53b (f:453b)
xor a
ld [wInHandlePlayerMonFainted], a
call FaintEnemyPokemon
@@ -827,7 +827,7 @@ HandleEnemyMonFainted: ; 3c525 (f:4525)
ld [wActionResultOrTookBattleTurn], a
jp MainInBattleLoop
-FaintEnemyPokemon: ; 0x3c567
+FaintEnemyPokemon: ; 3c57d (f:457d)
call ReadPlayerMonCurHPAndStatus
ld a, [wIsInBattle]
dec a
@@ -892,6 +892,8 @@ FaintEnemyPokemon: ; 0x3c567
ld a, MUSIC_DEFEATED_WILD_MON
call PlayBattleVictoryMusic
.sfxplayed
+; bug: win sfx is played for wild battles before checking for player mon HP
+; this can lead to odd scenarios where both player and enemy faint, as the win sfx plays yet the player never won the battle
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
@@ -953,11 +955,11 @@ FaintEnemyPokemon: ; 0x3c567
ld [wPartyGainExpFlags], a
jpab GainExperience
-EnemyMonFaintedText: ; 0x3c63e
+EnemyMonFaintedText: ; 3c654 (f:4654)
TX_FAR _EnemyMonFaintedText
db "@"
-EndLowHealthAlarm: ; 3c643 (f:4643)
+EndLowHealthAlarm: ; 3c659 (f:4659)
; 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
@@ -967,7 +969,7 @@ EndLowHealthAlarm: ; 3c643 (f:4643)
ld [wLowHealthAlarmDisabled], a ; prevent it from reactivating
ret
-AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f)
+AnyEnemyPokemonAliveCheck: ; 3c665 (f:4665)
ld a, [wEnemyPartyCount]
ld b, a
xor a
@@ -985,10 +987,15 @@ AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f)
ret
; stores whether enemy ran in Z flag
-ReplaceFaintedEnemyMon: ; 3c664 (f:4664)
+ReplaceFaintedEnemyMon: ; 3c67a (f:467a)
ld hl, wEnemyHPBarColor
ld e, $30
call GetBattleHealthBarColor
+ setpal SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE
+ ld [rOBP0], a
+ ld [rOBP1], a
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
callab DrawEnemyPokeballs
ld a, [wLinkState]
cp LINK_STATE_BATTLING
@@ -1008,7 +1015,7 @@ ReplaceFaintedEnemyMon: ; 3c664 (f:4664)
inc a ; reset Z flag
ret
-TrainerBattleVictory: ; 3c696 (f:4696)
+TrainerBattleVictory: ; 3c6b8 (f:46b8)
call EndLowHealthAlarm
ld b, MUSIC_DEFEATED_GYM_LEADER
ld a, [wGymLeaderNo]
@@ -1020,7 +1027,7 @@ TrainerBattleVictory: ; 3c696 (f:4696)
cp SONY3 ; final battle against rival
jr nz, .notrival
ld b, MUSIC_DEFEATED_GYM_LEADER
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
set 1, [hl]
.notrival
ld a, [wLinkState]
@@ -1044,25 +1051,23 @@ TrainerBattleVictory: ; 3c696 (f:4696)
ld c, $3
predef_jump AddBCDPredef
-MoneyForWinningText: ; 3c6e4 (f:46e4)
+MoneyForWinningText: ; 3c706 (f:4706)
TX_FAR _MoneyForWinningText
db "@"
-TrainerDefeatedText: ; 3c6e9 (f:46e9)
+TrainerDefeatedText: ; 3c70b (f:470b)
TX_FAR _TrainerDefeatedText
db "@"
-PlayBattleVictoryMusic: ; 3c6ee (f:46ee)
+PlayBattleVictoryMusic: ; 3c710 (f:4710)
push af
- ld a, $ff
- ld [wNewSoundID], a
- call PlaySoundWaitForCurrent
+ call StopAllMusic
ld c, BANK(Music_DefeatedTrainer)
pop af
call PlayMusic
jp Delay3
-HandlePlayerMonFainted: ; 3c700 (f:4700)
+HandlePlayerMonFainted: ; 3c71d (f:471d)
ld a, 1
ld [wInHandlePlayerMonFainted], a
call RemoveFaintedPlayerMon
@@ -1096,7 +1101,7 @@ HandlePlayerMonFainted: ; 3c700 (f:4700)
jp MainInBattleLoop
; resets flags, slides mon's pic down, plays cry, and prints fainted message
-RemoveFaintedPlayerMon: ; 3c741 (f:4741)
+RemoveFaintedPlayerMon: ; 3c75e (f:475e)
ld a, [wPlayerMonNumber]
ld c, a
ld hl, wPartyGainExpFlags
@@ -1134,18 +1139,42 @@ RemoveFaintedPlayerMon: ; 3c741 (f:4741)
and a ; was this called by HandleEnemyMonFainted?
ret z ; if so, return
+ ld a, [wPlayerMonIndex]
+ ld [wWhichPokemon], a
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .notPlayerPikachu
+ ld e, $3
+ callab PlayPikachuSoundClip
+ jr .printText
+.notPlayerPikachu
ld a, [wBattleMonSpecies]
call PlayCry
+.printText
ld hl, PlayerMonFaintedText
- jp PrintText
-
-PlayerMonFaintedText: ; 3c796 (f:4796)
+ call PrintText
+ ld a, [wPlayerMonIndex]
+ ld [wWhichPokemon], a
+ ld a, [wBattleMonLevel]
+ ld b, a
+ ld a, [wEnemyMonLevel]
+ sub b ; enemylevel - playerlevel
+ ; are we stronger than the opposing pokemon?
+ jr c, .carelessTrainer ; if so, punish the player for being careless, as they had a level advantage
+ cp 30 ; is the enemy 30 levels greater than us?
+ jr nc, .carelessTrainer ; if so, punish the player for being careless, as they shouldn't be fighting a very high leveled trainer with such a level difference
+ callabd_ModifyPikachuHappiness PIKAHAPPY_FAINTED
+ ret
+.carelessTrainer
+ calladb_ModifyPikachuHappiness PIKAHAPPY_CARELESSTRAINER
+ ret
+
+PlayerMonFaintedText: ; 3c7fa (f:47fa)
TX_FAR _PlayerMonFaintedText
db "@"
; asks if you want to use next mon
; stores whether you ran in C flag
-DoUseNextMonDialogue: ; 3c79b (f:479b)
+DoUseNextMonDialogue: ; 3c7ff (f:47ff)
call PrintEmptyString
call SaveScreenTilesToBuffer1
ld a, [wIsInBattle]
@@ -1173,13 +1202,13 @@ DoUseNextMonDialogue: ; 3c79b (f:479b)
ld de, wEnemyMonSpeed
jp TryRunningFromBattle
-UseNextMonText: ; 3c7d3 (f:47d3)
+UseNextMonText: ; 3c837 (f:4837)
TX_FAR _UseNextMonText
db "@"
; choose next player mon to send out
; stores whether enemy mon has no HP left in Z flag
-ChooseNextMon: ; 3c7d8 (f:47d8)
+ChooseNextMon: ; 3c83c (f:483c)
ld a, BATTLE_PARTY_MENU
ld [wPartyMenuTypeOrMessageID], a
call DisplayPartyMenu
@@ -1225,7 +1254,7 @@ ChooseNextMon: ; 3c7d8 (f:47d8)
; called when player is out of usable mons.
; prints approriate lose message, sets carry flag if player blacked out (special case for initial rival fight)
-HandlePlayerBlackOut: ; 3c837 (f:4837)
+HandlePlayerBlackOut: ; 3c89c (f:489c)
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr z, .notSony1Battle
@@ -1260,21 +1289,21 @@ HandlePlayerBlackOut: ; 3c837 (f:4837)
scf
ret
-Sony1WinText: ; 3c884 (f:4884)
+Sony1WinText: ; 3c8e9 (f:48e9)
TX_FAR _Sony1WinText
db "@"
-PlayerBlackedOutText2: ; 3c889 (f:4889)
+PlayerBlackedOutText2: ; 3c8ee (f:48ee)
TX_FAR _PlayerBlackedOutText2
db "@"
-LinkBattleLostText: ; 3c88e (f:488e)
+LinkBattleLostText: ; 3c8f3 (f:48f3)
TX_FAR _LinkBattleLostText
db "@"
; slides pic of fainted mon downwards until it disappears
; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing
-SlideDownFaintedMonPic: ; 3c893 (f:4893)
+SlideDownFaintedMonPic: ; 3c8f8 (f:48f8)
ld a, [wd730]
push af
set 6, a
@@ -1293,7 +1322,7 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893)
call CopyData
pop de
pop hl
- ld bc, -20
+ ld bc, -SCREEN_WIDTH
add hl, bc
push hl
ld h, d
@@ -1305,7 +1334,7 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893)
pop bc
dec b
jr nz, .rowLoop
- ld bc, 20
+ ld bc, SCREEN_WIDTH
add hl, bc
ld de, SevenSpacesText
call PlaceString
@@ -1320,14 +1349,14 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893)
ld [wd730], a
ret
-SevenSpacesText: ; 3c8d7 (f:48d7)
+SevenSpacesText: ; 3c93c (f:493c)
db " @"
; slides the player or enemy trainer off screen
; a is the number of tiles to slide it horizontally (always 9 for the player trainer or 8 for the enemy trainer)
; if a is 8, the slide is to the right, else it is to the left
; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing
-SlideTrainerPicOffScreen: ; 3c8df (f:48df)
+SlideTrainerPicOffScreen: ; 3c944 (f:4944)
ld [hSlideAmount], a
ld c, a
.slideStepLoop ; each iteration, the trainer pic is slid one tile left/right
@@ -1368,7 +1397,7 @@ SlideTrainerPicOffScreen: ; 3c8df (f:48df)
ret
; send out a trainer's mon
-EnemySendOut: ; 3c90e (f:490e)
+EnemySendOut: ; 3c973 (f:4973)
ld hl,wPartyGainExpFlags
xor a
ld [hl],a
@@ -1384,7 +1413,7 @@ EnemySendOut: ; 3c90e (f:490e)
predef FlagActionPredef
; don't change wPartyGainExpFlags or wPartyFoughtCurrentEnemyFlags
-EnemySendOutFirstMon: ; 3c92a (f:492a)
+EnemySendOutFirstMon: ; 3c98f (f:498f)
xor a
ld hl,wEnemyStatsToDouble ; clear enemy statuses
ld [hli],a
@@ -1537,17 +1566,17 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
call SaveScreenTilesToBuffer1
jp SwitchPlayerMon
-TrainerAboutToUseText: ; 3ca79 (f:4a79)
+TrainerAboutToUseText: ; 3cade (f:4ade)
TX_FAR _TrainerAboutToUseText
db "@"
-TrainerSentOutText: ; 3ca7e (f:4a7e)
+TrainerSentOutText: ; 3cae3 (f:4ae3)
TX_FAR _TrainerSentOutText
db "@"
; tests if the player has any pokemon that are not fainted
; sets d = 0 if all fainted, d != 0 if some mons are still alive
-AnyPartyAlive: ; 3ca83 (f:4a83)
+AnyPartyAlive: ; 3cae8 (f:4ae8)
ld a, [wPartyCount]
ld e, a
xor a
@@ -1565,7 +1594,7 @@ AnyPartyAlive: ; 3ca83 (f:4a83)
; tests if player mon has fainted
; stores whether mon has fainted in Z flag
-HasMonFainted: ; 3ca97 (f:4a97)
+HasMonFainted: ; 3cafc (f:4afc)
ld a, [wWhichPokemon]
ld hl, wPartyMon1HP
ld bc, wPartyMon2 - wPartyMon1
@@ -2649,7 +2678,7 @@ MoveSelectionMenu: ; 3d219 (f:5219)
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr z, .matchedkeyspicked
- ld a, [W_FLAGS_D733]
+ ld a, [wFlags_D733]
bit BIT_TEST_BATTLE, a
ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON | SELECT
jr z, .matchedkeyspicked
@@ -2677,7 +2706,7 @@ SelectMenuItem: ; 3d2fe (f:52fe)
call PlaceString
jr .select
.battleselect
- ld a, [W_FLAGS_D733]
+ ld a, [wFlags_D733]
bit BIT_TEST_BATTLE, a
jr nz, .select
call PrintMenuItem
@@ -6181,7 +6210,7 @@ GetCurrentMove: ; 3eabe (f:6abe)
jr .selected
.player
ld de, W_PLAYERMOVENUM
- ld a, [W_FLAGS_D733]
+ ld a, [wFlags_D733]
bit BIT_TEST_BATTLE, a
ld a, [wTestBattlePlayerSelectedMove]
jr nz, .selected
@@ -7061,11 +7090,11 @@ PoisonEffect: ; 3f24f (f:724f)
ld b, ANIM_C7
ld hl, wPlayerBattleStatus3
ld a, [de]
- ld de, W_PLAYERTOXICCOUNTER
+ ld de, wPlayerToxicCounter
jr nz, .ok
ld b, ANIM_A9
ld hl, wEnemyBattleStatus3
- ld de, W_ENEMYTOXICCOUNTER
+ ld de, wEnemyToxicCounter
.ok
cp TOXIC
jr nz, .normalPoison ; done if move is not Toxic
diff --git a/engine/battle/core_.asm b/engine/battle/core_.asm
index 45f231df..580d4c2e 100644
--- a/engine/battle/core_.asm
+++ b/engine/battle/core_.asm
@@ -567,25 +567,1039 @@ MainInBattleLoop: ; 3c249 (f:4249)
jp MainInBattleLoop
HandlePoisonBurnLeechSeed: ; 3c3d3 (f:43d3)
- dr $3c3d3,$3c525
+ ld hl, wBattleMonHP
+ ld de, wBattleMonStatus
+ ld a, [H_WHOSETURN]
+ and a
+ jr z, .playersTurn
+ ld hl, wEnemyMonHP
+ ld de, wEnemyMonStatus
+.playersTurn
+ ld a, [de]
+ and (1 << BRN) | (1 << PSN)
+ jr z, .notBurnedOrPoisoned
+ push hl
+ ld hl, HurtByPoisonText
+ ld a, [de]
+ and 1 << BRN
+ jr z, .poisoned
+ ld hl, HurtByBurnText
+.poisoned
+ call PrintText
+ xor a
+ ld [wAnimationType], a
+ ld a,BURN_PSN_ANIM
+ call PlayMoveAnimation ; play burn/poison animation
+ pop hl
+ call HandlePoisonBurnLeechSeed_DecreaseOwnHP
+.notBurnedOrPoisoned
+ ld de, wPlayerBattleStatus2
+ ld a, [H_WHOSETURN]
+ and a
+ jr z, .playersTurn2
+ ld de, wEnemyBattleStatus2
+.playersTurn2
+ ld a, [de]
+ add a
+ jr nc, .notLeechSeeded
+ push hl
+ ld a, [H_WHOSETURN]
+ push af
+ xor $1
+ ld [H_WHOSETURN], a
+ xor a
+ ld [wAnimationType], a
+ ld a,ABSORB
+ call PlayMoveAnimation ; play leech seed animation (from opposing mon)
+ pop af
+ ld [H_WHOSETURN], a
+ pop hl
+ call HandlePoisonBurnLeechSeed_DecreaseOwnHP
+ call HandlePoisonBurnLeechSeed_IncreaseEnemyHP
+ push hl
+ ld hl, HurtByLeechSeedText
+ call PrintText
+ pop hl
+.notLeechSeeded
+ ld a, [hli]
+ or [hl]
+ ret nz ; test if fainted
+ call DrawHUDsAndHPBars
+ ld c, 20
+ call DelayFrames
+ xor a
+ ret
+
+HurtByPoisonText: ; 3c444 (f:4444)
+ TX_FAR _HurtByPoisonText
+ db "@"
+
+HurtByBurnText: ; 3c449 (f:4449)
+ TX_FAR _HurtByBurnText
+ db "@"
+
+HurtByLeechSeedText: ; 3c44e (f:444e)
+ TX_FAR _HurtByLeechSeedText
+ db "@"
+
+; decreases the mon's current HP by 1/16 of the Max HP (multiplied by number of toxic ticks if active)
+; note that the toxic ticks are considered even if the damage is not poison (hence the Leech Seed glitch)
+; hl: HP pointer
+; bc (out): total damage
+HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d)
+ push hl
+ push hl
+ ld bc, $e ; skip to max HP
+ add hl, bc
+ ld a, [hli] ; load max HP
+ ld [wHPBarMaxHP+1], a
+ ld b, a
+ ld a, [hl]
+ ld [wHPBarMaxHP], a
+ ld c, a
+ srl b
+ rr c
+ srl b
+ rr c
+ srl c
+ srl c ; c = max HP/16 (assumption: HP < 1024)
+ ld a, c
+ and a
+ jr nz, .nonZeroDamage
+ inc c ; damage is at least 1
+.nonZeroDamage
+ ld hl, wPlayerBattleStatus3
+ ld de, wPlayerToxicCounter
+ ld a, [H_WHOSETURN]
+ and a
+ jr z, .playersTurn
+ ld hl, wEnemyBattleStatus3
+ ld de, wEnemyToxicCounter
+.playersTurn
+ bit BadlyPoisoned, [hl]
+ jr z, .noToxic
+ ld a, [de] ; increment toxic counter
+ inc a
+ ld [de], a
+ ld hl, $0000
+.toxicTicksLoop
+ add hl, bc
+ dec a
+ jr nz, .toxicTicksLoop
+ ld b, h ; bc = damage * toxic counter
+ ld c, l
+.noToxic
+ pop hl
+ inc hl
+ ld a, [hl] ; subtract total damage from current HP
+ ld [wHPBarOldHP], a
+ sub c
+ ld [hld], a
+ ld [wHPBarNewHP], a
+ ld a, [hl]
+ ld [wHPBarOldHP+1], a
+ sbc b
+ ld [hl], a
+ ld [wHPBarNewHP+1], a
+ jr nc, .noOverkill
+ xor a ; overkill: zero HP
+ ld [hli], a
+ ld [hl], a
+ ld [wHPBarNewHP], a
+ ld [wHPBarNewHP+1], a
+.noOverkill
+ call UpdateCurMonHPBar
+ pop hl
+ ret
+
+; adds bc to enemy HP
+; bc isn't updated if HP substracted was capped to prevent overkill
+HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4b9 (f:44b9)
+ push hl
+ ld hl, wEnemyMonMaxHP
+ ld a, [H_WHOSETURN]
+ and a
+ jr z, .playersTurn
+ ld hl, wBattleMonMaxHP
+.playersTurn
+ ld a, [hli]
+ ld [wHPBarMaxHP+1], a
+ ld a, [hl]
+ ld [wHPBarMaxHP], a
+ ld de, wBattleMonHP - wBattleMonMaxHP
+ add hl, de ; skip back from max hp to current hp
+ ld a, [hl]
+ ld [wHPBarOldHP], a ; add bc to current HP
+ add c
+ ld [hld], a
+ ld [wHPBarNewHP], a
+ ld a, [hl]
+ ld [wHPBarOldHP+1], a
+ adc b
+ ld [hli], a
+ ld [wHPBarNewHP+1], a
+ ld a, [wHPBarMaxHP]
+ ld c, a
+ ld a, [hld]
+ sub c
+ ld a, [wHPBarMaxHP+1]
+ ld b, a
+ ld a, [hl]
+ sbc b
+ jr c, .noOverfullHeal
+ ld a, b ; overfull heal, set HP to max HP
+ ld [hli], a
+ ld [wHPBarNewHP+1], a
+ ld a, c
+ ld [hl], a
+ ld [wHPBarNewHP], a
+.noOverfullHeal
+ ld a, [H_WHOSETURN]
+ xor $1
+ ld [H_WHOSETURN], a
+ call UpdateCurMonHPBar
+ ld a, [H_WHOSETURN]
+ xor $1
+ ld [H_WHOSETURN], a
+ pop hl
+ ret
+
+UpdateCurMonHPBar: ; 3c50c (f:450c)
+ coord hl, 10, 9 ; tile pointer to player HP bar
+ ld a, [H_WHOSETURN]
+ and a
+ ld a, $1
+ jr z, .playersTurn
+ coord hl, 2, 2 ; tile pointer to enemy HP bar
+ xor a
+.playersTurn
+ push bc
+ ld [wHPBarType], a
+ predef UpdateHPBar2
+ pop bc
+ ret
+
CheckNumAttacksLeft: ; 3c525 (f:4525)
- dr $3c525,$3c53b
+ ld a, [wPlayerNumAttacksLeft]
+ and a
+ jr nz, .checkEnemy
+; player has 0 attacks left
+ ld hl, wPlayerBattleStatus1
+ res UsingTrappingMove, [hl] ; player not using multi-turn attack like wrap any more
+.checkEnemy
+ ld a, [wEnemyNumAttacksLeft]
+ and a
+ ret nz
+; enemy has 0 attacks left
+ ld hl, wEnemyBattleStatus1
+ res UsingTrappingMove, [hl] ; enemy not using multi-turn attack like wrap any more
+ ret
+
HandleEnemyMonFainted: ; 3c53b (f:453b)
- dr $3c53b,$3c71d
+ xor a
+ ld [wInHandlePlayerMonFainted], a
+ call FaintEnemyPokemon
+ call AnyPartyAlive
+ ld a, d
+ and a
+ jp z, HandlePlayerBlackOut ; if no party mons are alive, the player blacks out
+ ld hl, wBattleMonHP
+ ld a, [hli]
+ or [hl] ; is battle mon HP zero?
+ call nz, DrawPlayerHUDAndHPBar ; if battle mon HP is not zero, draw player HD and HP bar
+ ld a, [wIsInBattle]
+ dec a
+ ret z ; return if it's a wild battle
+ call AnyEnemyPokemonAliveCheck
+ jp z, TrainerBattleVictory
+ ld hl, wBattleMonHP
+ ld a, [hli]
+ or [hl] ; does battle mon have 0 HP?
+ jr nz, .skipReplacingBattleMon ; if not, skip replacing battle mon
+ call DoUseNextMonDialogue ; this call is useless in a trainer battle. it shouldn't be here
+ ret c
+ call ChooseNextMon
+.skipReplacingBattleMon
+ ld a, $1
+ ld [wActionResultOrTookBattleTurn], a
+ call ReplaceFaintedEnemyMon
+ jp z, EnemyRan
+ xor a
+ ld [wActionResultOrTookBattleTurn], a
+ jp MainInBattleLoop
+
+FaintEnemyPokemon: ; 3c57d (f:457d)
+ call ReadPlayerMonCurHPAndStatus
+ ld a, [wIsInBattle]
+ dec a
+ jr z, .wild
+ ld a, [wEnemyMonPartyPos]
+ ld hl, wEnemyMon1HP
+ ld bc, wEnemyMon2 - wEnemyMon1
+ call AddNTimes
+ xor a
+ ld [hli], a
+ ld [hl], a
+.wild
+ ld hl, wPlayerBattleStatus1
+ res AttackingMultipleTimes, [hl]
+; Bug. This only zeroes the high byte of the player's accumulated damage,
+; setting the accumulated damage to itself mod 256 instead of 0 as was probably
+; intended. That alone is problematic, but this mistake has another more severe
+; effect. This function's counterpart for when the player mon faints,
+; RemoveFaintedPlayerMon, zeroes both the high byte and the low byte. In a link
+; battle, the other player's Game Boy will call that function in response to
+; the enemy mon (the player mon from the other side's perspective) fainting,
+; and the states of the two Game Boys will go out of sync unless the damage
+; was congruent to 0 modulo 256.
+ xor a
+ ld [wPlayerBideAccumulatedDamage], a
+ ld hl, wEnemyStatsToDouble ; clear enemy statuses
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ld [wEnemyDisabledMove], a
+ ld [wEnemyDisabledMoveNumber], a
+ ld [wEnemyMonMinimized], a
+ ld hl, wPlayerUsedMove
+ ld [hli], a
+ ld [hl], a
+ coord hl, 12, 5
+ coord de, 12, 6
+ call SlideDownFaintedMonPic
+ coord hl, 0, 0
+ lb bc, 4, 11
+ call ClearScreenArea
+ ld a, [wIsInBattle]
+ dec a
+ jr z, .wild_win
+ xor a
+ ld [wFrequencyModifier], a
+ ld [wTempoModifier], a
+ ld a, SFX_FAINT_FALL
+ call PlaySoundWaitForCurrent
+.sfxwait
+ ld a, [wChannelSoundIDs + CH4]
+ cp SFX_FAINT_FALL
+ jr z, .sfxwait
+ ld a, SFX_FAINT_THUD
+ call PlaySound
+ call WaitForSoundToFinish
+ jr .sfxplayed
+.wild_win
+ call EndLowHealthAlarm
+ ld a, MUSIC_DEFEATED_WILD_MON
+ call PlayBattleVictoryMusic
+.sfxplayed
+; bug: win sfx is played for wild battles before checking for player mon HP
+; this can lead to odd scenarios where both player and enemy faint, as the win sfx plays yet the player never won the battle
+ ld hl, wBattleMonHP
+ ld a, [hli]
+ or [hl]
+ 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
+ ld a, d
+ and a
+ ret z
+ ld hl, EnemyMonFaintedText
+ call PrintText
+ call PrintEmptyString
+ call SaveScreenTilesToBuffer1
+ xor a
+ ld [wBattleResult], a
+ ld b, EXP_ALL
+ call IsItemInBag
+ push af
+ jr z, .giveExpToMonsThatFought ; if no exp all, then jump
+
+; the player has exp all
+; first, we halve the values that determine exp gain
+; the enemy mon base stats are added to stat exp, so they are halved
+; the base exp (which determines normal exp) is also halved
+ ld hl, wEnemyMonBaseStats
+ ld b, $7
+.halveExpDataLoop
+ srl [hl]
+ inc hl
+ dec b
+ jr nz, .halveExpDataLoop
+
+; give exp (divided evenly) to the mons that actually fought in battle against the enemy mon that has fainted
+; if exp all is in the bag, this will be only be half of the stat exp and normal exp, due to the above loop
+.giveExpToMonsThatFought
+ xor a
+ ld [wBoostExpByExpAll], a
+ callab GainExperience
+ pop af
+ ret z ; return if no exp all
+
+; the player has exp all
+; now, set the gain exp flag for every party member
+; half of the total stat exp and normal exp will divided evenly amongst every party member
+ ld a, $1
+ ld [wBoostExpByExpAll], a
+ ld a, [wPartyCount]
+ ld b, 0
+.gainExpFlagsLoop
+ scf
+ rl b
+ dec a
+ jr nz, .gainExpFlagsLoop
+ ld a, b
+ ld [wPartyGainExpFlags], a
+ jpab GainExperience
+
+EnemyMonFaintedText: ; 3c654 (f:4654)
+ TX_FAR _EnemyMonFaintedText
+ db "@"
+
+EndLowHealthAlarm: ; 3c659 (f:4659)
+; 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 ; turn off low health alarm
+ ld [wChannelSoundIDs + CH4], a
+ inc a
+ ld [wLowHealthAlarmDisabled], a ; prevent it from reactivating
+ ret
+
+AnyEnemyPokemonAliveCheck: ; 3c665 (f:4665)
+ ld a, [wEnemyPartyCount]
+ ld b, a
+ xor a
+ ld hl, wEnemyMon1HP
+ ld de, wEnemyMon2 - wEnemyMon1
+.nextPokemon
+ or [hl]
+ inc hl
+ or [hl]
+ dec hl
+ add hl, de
+ dec b
+ jr nz, .nextPokemon
+ and a
+ ret
+
+; stores whether enemy ran in Z flag
+ReplaceFaintedEnemyMon: ; 3c67a (f:467a)
+ ld hl, wEnemyHPBarColor
+ ld e, $30
+ call GetBattleHealthBarColor
+ setpal SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE
+ ld [rOBP0], a
+ ld [rOBP1], a
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ callab DrawEnemyPokeballs
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ jr nz, .notLinkBattle
+; link battle
+ call LinkBattleExchangeData
+ ld a, [wSerialExchangeNybbleReceiveData]
+ cp $f
+ ret z
+ call LoadScreenTilesFromBuffer1
+.notLinkBattle
+ call EnemySendOut
+ xor a
+ ld [wEnemyMoveNum], a
+ ld [wActionResultOrTookBattleTurn], a
+ ld [wAILayer2Encouragement], a
+ inc a ; reset Z flag
+ ret
+
+TrainerBattleVictory: ; 3c6b8 (f:46b8)
+ call EndLowHealthAlarm
+ ld b, MUSIC_DEFEATED_GYM_LEADER
+ ld a, [wGymLeaderNo]
+ and a
+ jr nz, .gymleader
+ ld b, MUSIC_DEFEATED_TRAINER
+.gymleader
+ ld a, [wTrainerClass]
+ cp SONY3 ; final battle against rival
+ jr nz, .notrival
+ ld b, MUSIC_DEFEATED_GYM_LEADER
+ ld hl, wFlags_D733
+ set 1, [hl]
+.notrival
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ ld a, b
+ call nz, PlayBattleVictoryMusic
+ ld hl, TrainerDefeatedText
+ call PrintText
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ ret z
+ call ScrollTrainerPicAfterBattle
+ ld c, 40
+ call DelayFrames
+ call PrintEndBattleText
+; win money
+ ld hl, MoneyForWinningText
+ call PrintText
+ ld de, wPlayerMoney + 2
+ ld hl, wAmountMoneyWon + 2
+ ld c, $3
+ predef_jump AddBCDPredef
+
+MoneyForWinningText: ; 3c706 (f:4706)
+ TX_FAR _MoneyForWinningText
+ db "@"
+
+TrainerDefeatedText: ; 3c70b (f:470b)
+ TX_FAR _TrainerDefeatedText
+ db "@"
+
+PlayBattleVictoryMusic: ; 3c710 (f:4710)
+ push af
+ call StopAllMusic
+ ld c, BANK(Music_DefeatedTrainer)
+ pop af
+ call PlayMusic
+ jp Delay3
+
HandlePlayerMonFainted: ; 3c71d (f:471d)
- dr $3c71d,$3c89c
+ ld a, 1
+ ld [wInHandlePlayerMonFainted], a
+ call RemoveFaintedPlayerMon
+ call AnyPartyAlive ; test if any more mons are alive
+ ld a, d
+ and a
+ jp z, HandlePlayerBlackOut
+ ld hl, wEnemyMonHP
+ ld a, [hli]
+ or [hl] ; is enemy mon's HP 0?
+ jr nz, .doUseNextMonDialogue ; if not, jump
+; the enemy mon has 0 HP
+ call FaintEnemyPokemon
+ ld a, [wIsInBattle]
+ dec a
+ ret z ; if wild encounter, battle is over
+ call AnyEnemyPokemonAliveCheck
+ jp z, TrainerBattleVictory
+.doUseNextMonDialogue
+ call DoUseNextMonDialogue
+ ret c ; return if the player ran from battle
+ call ChooseNextMon
+ jp nz, MainInBattleLoop ; if the enemy mon has more than 0 HP, go back to battle loop
+; the enemy mon has 0 HP
+ ld a, $1
+ ld [wActionResultOrTookBattleTurn], a
+ call ReplaceFaintedEnemyMon
+ jp z, EnemyRan ; if enemy ran from battle rather than sending out another mon, jump
+ xor a
+ ld [wActionResultOrTookBattleTurn], a
+ jp MainInBattleLoop
+
+; resets flags, slides mon's pic down, plays cry, and prints fainted message
+RemoveFaintedPlayerMon: ; 3c75e (f:475e)
+ ld a, [wPlayerMonNumber]
+ ld c, a
+ ld hl, wPartyGainExpFlags
+ ld b, FLAG_RESET
+ predef FlagActionPredef ; clear gain exp flag for fainted mon
+ ld hl, wEnemyBattleStatus1
+ res 2, [hl] ; reset "attacking multiple times" flag
+ ld a, [wLowHealthAlarm]
+ bit 7, a ; skip sound flag (red bar (?))
+ jr z, .skipWaitForSound
+ ld a, $ff
+ ld [wLowHealthAlarm], a ;disable low health alarm
+ call WaitForSoundToFinish
+ xor a
+.skipWaitForSound
+; a is 0, so this zeroes the enemy's accumulated damage.
+ ld hl, wEnemyBideAccumulatedDamage
+ ld [hli], a
+ ld [hl], a
+ ld [wBattleMonStatus], a
+ call ReadPlayerMonCurHPAndStatus
+ coord hl, 9, 7
+ lb bc, 5, 11
+ call ClearScreenArea
+ coord hl, 1, 10
+ coord de, 1, 11
+ call SlideDownFaintedMonPic
+ ld a, $1
+ ld [wBattleResult], a
+
+; 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, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .notPlayerPikachu
+ ld e, $3
+ callab PlayPikachuSoundClip
+ jr .printText
+.notPlayerPikachu
+ ld a, [wBattleMonSpecies]
+ call PlayCry
+.printText
+ ld hl, PlayerMonFaintedText
+ call PrintText
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ ld a, [wBattleMonLevel]
+ ld b, a
+ ld a, [wEnemyMonLevel]
+ sub b ; enemylevel - playerlevel
+ ; are we stronger than the opposing pokemon?
+ jr c, .regularFaint ; if so, deduct happiness regularly
+
+ cp 30 ; is the enemy 30 levels greater than us?
+ jr nc, .carelessTrainer ; if so, punish the player for being careless, as they shouldn't be fighting a very high leveled trainer with such a level difference
+.regularFaint
+ callabd_ModifyPikachuHappiness PIKAHAPPY_FAINTED
+ ret
+.carelessTrainer
+ callabd_ModifyPikachuHappiness PIKAHAPPY_CARELESSTRAINER
+ ret
+
+PlayerMonFaintedText: ; 3c7fa (f:47fa)
+ TX_FAR _PlayerMonFaintedText
+ db "@"
+
+; asks if you want to use next mon
+; stores whether you ran in C flag
+DoUseNextMonDialogue: ; 3c7ff (f:47ff)
+ call PrintEmptyString
+ call SaveScreenTilesToBuffer1
+ ld a, [wIsInBattle]
+ and a
+ dec a
+ ret nz ; return if it's a trainer battle
+ ld hl, UseNextMonText
+ call PrintText
+.displayYesNoBox
+ coord hl, 13, 9
+ lb bc, 10, 14
+ ld a, TWO_OPTION_MENU
+ ld [wTextBoxID], a
+ call DisplayTextBoxID
+ ld a, [wMenuExitMethod]
+ cp CHOSE_SECOND_ITEM ; did the player choose NO?
+ jr z, .tryRunning ; if the player chose NO, try running
+ and a ; reset carry
+ ret
+.tryRunning
+ ld a, [wCurrentMenuItem]
+ and a
+ jr z, .displayYesNoBox ; xxx when does this happen?
+ ld hl, wPartyMon1Speed
+ ld de, wEnemyMonSpeed
+ jp TryRunningFromBattle
+
+UseNextMonText: ; 3c837 (f:4837)
+ TX_FAR _UseNextMonText
+ db "@"
+
+; choose next player mon to send out
+; stores whether enemy mon has no HP left in Z flag
+ChooseNextMon: ; 3c83c (f:483c)
+ ld a, BATTLE_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
+ call DisplayPartyMenu
+.checkIfMonChosen
+ jr nc, .monChosen
+.goBackToPartyMenu
+ call GoBackToPartyMenu
+ jr .checkIfMonChosen
+.monChosen
+ call HasMonFainted
+ jr z, .goBackToPartyMenu ; if mon fainted, you have to choose another
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ jr nz, .notLinkBattle
+ ld a, $1
+ ld [wActionResultOrTookBattleTurn], a
+ call LinkBattleExchangeData
+.notLinkBattle
+ xor a
+ ld [wActionResultOrTookBattleTurn], a
+ call ClearSprites
+ ld a, [wWhichPokemon]
+ ld [wPlayerMonNumber], a
+ ld c, a
+ ld hl, wPartyGainExpFlags
+ ld b, FLAG_SET
+ push bc
+ predef FlagActionPredef
+ pop bc
+ ld hl, wPartyFoughtCurrentEnemyFlags
+ predef FlagActionPredef
+ call LoadBattleMonFromParty
+ call GBPalWhiteOut
+ call LoadHudTilePatterns
+ call LoadScreenTilesFromBuffer1
+ call RunDefaultPaletteCommand
+ call GBPalNormal
+ call SendOutMon
+ ld hl, wEnemyMonHP
+ ld a, [hli]
+ or [hl]
+ ret
+
+; called when player is out of usable mons.
+; prints approriate lose message, sets carry flag if player blacked out (special case for initial rival fight)
HandlePlayerBlackOut: ; 3c89c (f:489c)
- dr $3c89c,$3c944
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ jr z, .notSony1Battle
+ ld a, [wCurOpponent]
+ cp OPP_SONY1
+ jr nz, .notSony1Battle
+ coord hl, 0, 0 ; sony 1 battle
+ lb bc, 8, 21
+ call ClearScreenArea
+ call ScrollTrainerPicAfterBattle
+ ld c, 40
+ call DelayFrames
+ ld hl, Sony1WinText
+ call PrintText
+ ld a, [wCurMap]
+ cp OAKS_LAB
+ ret z ; starter battle in oak's lab: don't black out
+.notSony1Battle
+ ld b, SET_PAL_BATTLE_BLACK
+ call RunPaletteCommand
+ ld hl, PlayerBlackedOutText2
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ jr nz, .noLinkBattle
+ ld hl, LinkBattleLostText
+.noLinkBattle
+ call PrintText
+ ld a, [wd732]
+ res 5, a
+ ld [wd732], a
+ call ClearScreen
+ scf
+ ret
+
+Sony1WinText: ; 3c8e9 (f:48e9)
+ TX_FAR _Sony1WinText
+ db "@"
+
+PlayerBlackedOutText2: ; 3c8ee (f:48ee)
+ TX_FAR _PlayerBlackedOutText2
+ db "@"
+
+LinkBattleLostText: ; 3c8f3 (f:48f3)
+ TX_FAR _LinkBattleLostText
+ db "@"
+
+; slides pic of fainted mon downwards until it disappears
+; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing
+SlideDownFaintedMonPic: ; 3c8f8 (f:48f8)
+ ld a, [wd730]
+ push af
+ set 6, a
+ ld [wd730], a
+ ld b, 7 ; number of times to slide
+.slideStepLoop ; each iteration, the mon is slid down one row
+ push bc
+ push de
+ push hl
+ ld b, 6 ; number of rows
+.rowLoop
+ push bc
+ push hl
+ push de
+ ld bc, $7
+ call CopyData
+ pop de
+ pop hl
+ ld bc, -SCREEN_WIDTH
+ add hl, bc
+ push hl
+ ld h, d
+ ld l, e
+ add hl, bc
+ ld d, h
+ ld e, l
+ pop hl
+ pop bc
+ dec b
+ jr nz, .rowLoop
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ ld de, SevenSpacesText
+ call PlaceString
+ ld c, 2
+ call DelayFrames
+ pop hl
+ pop de
+ pop bc
+ dec b
+ jr nz, .slideStepLoop
+ pop af
+ ld [wd730], a
+ ret
+
+SevenSpacesText: ; 3c93c (f:493c)
+ db " @"
+
+; slides the player or enemy trainer off screen
+; a is the number of tiles to slide it horizontally (always 9 for the player trainer or 8 for the enemy trainer)
+; if a is 8, the slide is to the right, else it is to the left
+; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing
SlideTrainerPicOffScreen: ; 3c944 (f:4944)
- dr $3c944,$3c973
+ ld [hSlideAmount], a
+ ld c, a
+.slideStepLoop ; each iteration, the trainer pic is slid one tile left/right
+ push bc
+ push hl
+ ld b, 7 ; number of rows
+.rowLoop
+ push hl
+ ld a, [hSlideAmount]
+ ld c, a
+.columnLoop
+ ld a, [hSlideAmount]
+ cp 8
+ jr z, .slideRight
+.slideLeft ; slide player sprite off screen
+ ld a, [hld]
+ ld [hli], a
+ inc hl
+ jr .nextColumn
+.slideRight ; slide enemy trainer sprite off screen
+ ld a, [hli]
+ ld [hld], a
+ dec hl
+.nextColumn
+ dec c
+ jr nz, .columnLoop
+ pop hl
+ ld de, 20
+ add hl, de
+ dec b
+ jr nz, .rowLoop
+ ld c, 2
+ call DelayFrames
+ pop hl
+ pop bc
+ dec c
+ jr nz, .slideStepLoop
+ ret
+
+; send out a trainer's mon
EnemySendOut: ; 3c973 (f:4973)
- dr $3c973,$3c98f
+ ld hl,wPartyGainExpFlags
+ xor a
+ ld [hl],a
+ ld a,[wPlayerMonNumber]
+ ld c,a
+ ld b,FLAG_SET
+ push bc
+ predef FlagActionPredef
+ ld hl,wPartyFoughtCurrentEnemyFlags
+ xor a
+ ld [hl],a
+ pop bc
+ predef FlagActionPredef
+
+; don't change wPartyGainExpFlags or wPartyFoughtCurrentEnemyFlags
EnemySendOutFirstMon: ; 3c98f (f:498f)
- dr $3c98f,$3cae8
+ xor a
+ ld hl,wEnemyStatsToDouble ; clear enemy statuses
+ ld [hli],a
+ ld [hli],a
+ ld [hli],a
+ ld [hli],a
+ ld [hl],a
+ ld [wEnemyDisabledMove],a
+ ld [wEnemyDisabledMoveNumber],a
+ ld [wEnemyMonMinimized],a
+ ld hl,wPlayerUsedMove
+ ld [hli],a
+ ld [hl],a
+ dec a
+ ld [wAICount],a
+ ld hl,wPlayerBattleStatus1
+ res 5,[hl]
+ coord hl, 18, 0
+ ld a,8
+ call SlideTrainerPicOffScreen
+ call PrintEmptyString
+ call SaveScreenTilesToBuffer1
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
+ jr nz,.next
+ ld a,[wSerialExchangeNybbleReceiveData]
+ sub 4
+ ld [wWhichPokemon],a
+ jr .next3
+.next
+ ld b,$FF
+.next2
+ inc b
+ ld a,[wEnemyMonPartyPos]
+ cp b
+ jr z,.next2
+ ld hl,wEnemyMon1
+ ld a,b
+ ld [wWhichPokemon],a
+ push bc
+ ld bc,wEnemyMon2 - wEnemyMon1
+ call AddNTimes
+ pop bc
+ inc hl
+ ld a,[hli]
+ ld c,a
+ ld a,[hl]
+ or c
+ jr z,.next2
+.next3
+ ld a,[wWhichPokemon]
+ ld hl,wEnemyMon1Level
+ ld bc,wEnemyMon2 - wEnemyMon1
+ call AddNTimes
+ ld a,[hl]
+ ld [wCurEnemyLVL],a
+ ld a,[wWhichPokemon]
+ inc a
+ ld hl,wEnemyPartyCount
+ ld c,a
+ ld b,0
+ add hl,bc
+ ld a,[hl]
+ ld [wEnemyMonSpecies2],a
+ ld [wcf91],a
+ call LoadEnemyMonData
+ ld hl,wEnemyMonHP
+ ld a,[hli]
+ ld [wLastSwitchInEnemyMonHP],a
+ ld a,[hl]
+ ld [wLastSwitchInEnemyMonHP + 1],a
+ ld a,1
+ ld [wCurrentMenuItem],a
+ ld a,[wFirstMonsNotOutYet]
+ dec a
+ jr z,.next4
+ ld a,[wPartyCount]
+ dec a
+ jr z,.next4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
+ jr z,.next4
+ ld a,[wOptions]
+ bit 6,a
+ jr nz,.next4
+ ld hl, TrainerAboutToUseText
+ call PrintText
+ coord hl, 0, 7
+ lb bc, 8, 1
+ ld a,TWO_OPTION_MENU
+ ld [wTextBoxID],a
+ call DisplayTextBoxID
+ ld a,[wCurrentMenuItem]
+ and a
+ jr nz,.next4
+ ld a,BATTLE_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
+ call DisplayPartyMenu
+.next9
+ ld a,1
+ ld [wCurrentMenuItem],a
+ jr c,.next7
+ ld hl,wPlayerMonNumber
+ ld a,[wWhichPokemon]
+ cp [hl]
+ jr nz,.next6
+ ld hl,AlreadyOutText
+ call PrintText
+.next8
+ call GoBackToPartyMenu
+ jr .next9
+.next6
+ call HasMonFainted
+ jr z,.next8
+ xor a
+ ld [wCurrentMenuItem],a
+.next7
+ call GBPalWhiteOut
+ call LoadHudTilePatterns
+ call LoadScreenTilesFromBuffer1
+.next4
+ call ClearSprites
+ coord hl, 0, 0
+ lb bc, 4, 11
+ call ClearScreenArea
+ ld b, SET_PAL_BATTLE
+ call RunPaletteCommand
+ call GBPalNormal
+ ld hl,TrainerSentOutText
+ call PrintText
+ ld a,[wEnemyMonSpecies2]
+ ld [wcf91],a
+ ld [wd0b5],a
+ call GetMonHeader
+ ld de,vFrontPic
+ call LoadMonFrontSprite
+ ld a,-$31
+ ld [hStartTileID],a
+ coord hl, 15, 6
+ predef AnimateSendingOutMon
+ ld a,[wEnemyMonSpecies2]
+ call PlayCry
+ call DrawEnemyHUDAndHPBar
+ ld a,[wCurrentMenuItem]
+ and a
+ ret nz
+ xor a
+ ld [wPartyGainExpFlags],a
+ ld [wPartyFoughtCurrentEnemyFlags],a
+ call SaveScreenTilesToBuffer1
+ jp SwitchPlayerMon
+
+TrainerAboutToUseText: ; 3cade (f:4ade)
+ TX_FAR _TrainerAboutToUseText
+ db "@"
+
+TrainerSentOutText: ; 3cae3 (f:4ae3)
+ TX_FAR _TrainerSentOutText
+ db "@"
+
+; tests if the player has any pokemon that are not fainted
+; sets d = 0 if all fainted, d != 0 if some mons are still alive
AnyPartyAlive: ; 3cae8 (f:4ae8)
- dr $3cae8,$3cafc
+ ld a, [wPartyCount]
+ ld e, a
+ xor a
+ ld hl, wPartyMon1HP
+ ld bc, wPartyMon2 - wPartyMon1 - 1
+.partyMonsLoop
+ or [hl]
+ inc hl
+ or [hl]
+ add hl, bc
+ dec e
+ jr nz, .partyMonsLoop
+ ld d, a
+ ret
+
HasMonFainted: ; 3cafc (f:4afc)
- dr $3cafc,$3cc10
+ dr $3cafc,$3cb1e
+TryRunningFromBattle: ; 3cb1e (f:4b1e)
+ dr $3cb1e,$3cc10
LoadBattleMonFromParty: ; 3cc10 (f:4c10)
dr $3cc10,$3ccfb
SendOutMon: ; 3ccfb (f:4cfb)
@@ -593,15 +1607,25 @@ SendOutMon: ; 3ccfb (f:4cfb)
ReadPlayerMonCurHPAndStatus: ; 3ce08 (f:4e08)
dr $3ce08,$3ce1f
DrawHUDsAndHPBars: ; 3ce1f (f:4e1f)
- dr $3ce1f,$3ceb1
+ dr $3ce1f,$3ce25
+DrawPlayerHUDAndHPBar: ; 3ce25 (f:4e25)
+ dr $3ce25,$3ceb1
DrawEnemyHUDAndHPBar: ; 3ceb1 (f:4eb1)
- dr $3ceb1,$3cf78
+ dr $3ceb1,$3cf55
+GetBattleHealthBarColor: ; 3cf55 (f:4f55)
+ dr $3cf55,$3cf78
DisplayBattleMenu: ; 3cf78 (f:4f78)
- dr $3cf78,$3d320
+ dr $3cf78,$3d2c1
+SwitchPlayerMon: ; 3d2c1 (f:52c1)
+ dr $3d2c1,$3d2fc
+AlreadyOutText: ; 3d2fc (f:52fc)
+ dr $3d2fc,$3d320
MoveSelectionMenu: ; 3d320 (f:5320)
dr $3d320,$3d6d6
SelectEnemyMove: ; 3d6d6 (f:56d6)
- dr $3d6d6,$3d7d0
+ dr $3d6d6,$3d777
+LinkBattleExchangeData: ; 3d777 (f:5777)
+ dr $3d777,$3d7d0
ExecutePlayerMove: ; 3d7d0 (f:57d0)
dr $3d7d0,$3d9ac
IsGhostBattle: ; 3d9ac (f:59ac)
@@ -664,15 +1688,21 @@ LoadEnemyMonData: ; 3ec87 (f:6c87)
DoBattleTransitionAndInitBattleVariables: ; 3edb8 (f:6db8)
dr $3edb8,$3ee18
LoadPlayerBackPic: ; 3ee18 (f:6e18)
- dr $3ee18,$3eeb3
+ dr $3ee18,$3ee9e
+ScrollTrainerPicAfterBattle: ; 3ee9e (f:6e9e)
+ dr $3ee9e,$3eeb3
QuarterSpeedDueToParalysis: ; 3eeb3 (f:6eb3)
dr $3eeb3,$3efe4
LoadHudAndHpBarAndStatusTilePatterns: ; 3efe4 (f:6fe4)
dr $3efe4,$3efe7
LoadHudTilePatterns: ; 3efe7 (f:6fe7)
- dr $3efe7,$3f027
+ dr $3efe7,$3f020
+PrintEmptyString: ; 3f020 (f:7020)
+ dr $3f020,$3f027
BattleRandom: ; 3f027 (f:7027)
- dr $3f027,$3f3de
+ dr $3f027,$3f093
+PlayMoveAnimation: ; 3f093 (f:7093)
+ dr $3f093,$3f3de
StatModifierUpEffect: ; 3f3de (f:73de)
dr $3f3de,$3fb2e
PrintButItFailedText_: ; 3fb2e (f:7b2e)
diff --git a/engine/evos_moves.asm b/engine/evos_moves.asm
index e66cacd3..2e0c3cc9 100755
--- a/engine/evos_moves.asm
+++ b/engine/evos_moves.asm
@@ -365,7 +365,7 @@ LearnMoveFromLevelUp: ; 3b00c (e:700c)
ld a, b
and a
jr z, .done
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc, .done
ld a, [wMoveNum]
cp THUNDERBOLT
diff --git a/engine/hall_of_fame.asm b/engine/hall_of_fame.asm
index 485ab182..762850f3 100755
--- a/engine/hall_of_fame.asm
+++ b/engine/hall_of_fame.asm
@@ -156,7 +156,7 @@ HoFDisplayAndRecordMonInfo: ; 7030e (1c:430e)
call HoFDisplayMonInfo
ld a, [wHoFPartyMonIndex]
ld [wWhichPokemon], a
- callab IsThisPartymonOurPikachu ; 3f:4e18
+ callab IsThisPartymonStarterPikachu_Party ; 3f:4e18
jr nc, .asm_70336
ld e, $22
callab PlayPikachuSoundClip
diff --git a/engine/items/items.asm b/engine/items/items.asm
index 4ff01eff..bda01e27 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -673,7 +673,7 @@ ItemUseEvoStone: ; d7d0 (3:57d0)
ld [wcf91],a
call Func_d85d
jr nc, .noEffect
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc, .notPlayerPikachu
ld e, $1b
callab PlayPikachuSoundClip
@@ -2373,7 +2373,7 @@ ItemUseTMHM: ; e374 (3:6374)
ld a,d
ld [wWhichPokemon],a
callabd_ModifyPikachuHappiness PIKAHAPPY_USEDTMHM
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc,.notTeachingThunderboltOrThunderToPikachu
ld a,[wcf91]
cp a,TM_24 ; are we teaching thunderbolt to the player pikachu?
diff --git a/engine/menu/bills_pc.asm b/engine/menu/bills_pc.asm
index 347ec5df..ce9ca5a8 100644
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -225,7 +225,7 @@ BillsPCDeposit: ; 2156d (8:556d)
ld hl, wPartyCount
call DisplayMonListMenu
jp c, BillsPCMenu
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc, .asm_215ad
call Func_154a
jr z, .asm_215ad
@@ -235,7 +235,7 @@ BillsPCDeposit: ; 2156d (8:556d)
.asm_215ad
call DisplayDepositWithdrawMenu
jp nc, BillsPCMenu
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc, .asm_215c9
ld e, $1b
callab PlayPikachuSoundClip
@@ -298,7 +298,7 @@ BillsPCWithdraw: ; 21613 (8:5613)
ld a, [wWhichPokemon]
ld hl, wBoxMonNicks
call GetPartyMonName
- callab Func_fce0d
+ callab IsThisPartymonStarterPikachu_Box
jr nc, .asm_21660
ld e, $22
callab PlayPikachuSoundClip
@@ -329,7 +329,7 @@ BillsPCRelease: ; 21690 (8:5690)
ld hl, wNumInBox
call DisplayMonListMenu
jp c, BillsPCMenu
- callab Func_fce0d
+ callab IsThisPartymonStarterPikachu_Box
jr c, .asm_216cb
ld hl, OnceReleasedText
call PrintText
diff --git a/engine/menu/party_menu.asm b/engine/menu/party_menu.asm
index d65123d7..3ec0029e 100755
--- a/engine/menu/party_menu.asm
+++ b/engine/menu/party_menu.asm
@@ -51,7 +51,7 @@ RedrawPartyMenu_: ; 11886 (4:5886)
call PlaceString ; print the pokemon's name
ld a,[hPartyMonIndex]
ld [wWhichPokemon],a
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc, .regularMon
call Func_154a
jr z, .regularMon
diff --git a/engine/menu/status_screen.asm b/engine/menu/status_screen.asm
index e91d3b31..719cacd1 100755
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -175,11 +175,11 @@ StatusScreen: ; 114cc (4:54cc)
jr z, .playRegularCry
cp BOX_DATA
jr z, .checkBoxData
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc, .playRegularCry
jr .playPikachuSoundClip
.checkBoxData
- callab Func_fce0d
+ callab IsThisPartymonStarterPikachu_Box
jr nc, .playRegularCry
.playPikachuSoundClip
ld e, 16
diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm
index a609fb60..719c8835 100755
--- a/engine/overworld/npc_movement.asm
+++ b/engine/overworld/npc_movement.asm
@@ -79,7 +79,7 @@ PalletMovementScript_OakMoveLeft: ; 1a44c (6:644c)
ld a, $3
ld [wNPCMovementScriptFunctionNum], a
.done
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
set 1, [hl]
ld a, $fc
ld [wJoyIgnore], a
diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm
index ff579a04..d883f0e3 100755
--- a/engine/overworld/player_animations.asm
+++ b/engine/overworld/player_animations.asm
@@ -5,7 +5,7 @@ EnterMapAnim: ; 70567 (1c:4567)
call Delay3
push hl
call GBFadeInFromWhite
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
bit 7, [hl] ; used fly out of battle?
res 7, [hl]
jr nz, .flyAnimation
diff --git a/engine/overworld/pokecenter.asm b/engine/overworld/pokecenter.asm
index 9cedd99d..779d852c 100755
--- a/engine/overworld/pokecenter.asm
+++ b/engine/overworld/pokecenter.asm
@@ -25,7 +25,7 @@ DisplayPokemonCenterDialogue_: ; 6d97 (1:6d97)
and a
jp nz, .declinedHealing ; if the player chose No
call SetLastBlackoutMap
- callab IsPikachuInOurParty
+ callab IsStarterPikachuInOurParty
jr nc, .notHealingPlayerPikachu
call Func_154a
jr nz, .notHealingPlayerPikachu
@@ -41,7 +41,7 @@ DisplayPokemonCenterDialogue_: ; 6d97 (1:6d97)
call Func_154a
jr nz, .playerPikachuNotOnScreen
call Func_152d
- callab IsPikachuInOurParty
+ callab IsStarterPikachuInOurParty
call c, Func_6eaa
.playerPikachuNotOnScreen
lb bc, 1, 8
@@ -60,7 +60,7 @@ DisplayPokemonCenterDialogue_: ; 6d97 (1:6d97)
call PlaySound
call Func_154a
jr nz, .doNotReturnPikachu
- callab IsPikachuInOurParty
+ callab IsStarterPikachuInOurParty
call c, Func_6eaa
ld a, $5
ld [wd431], a
@@ -70,7 +70,7 @@ DisplayPokemonCenterDialogue_: ; 6d97 (1:6d97)
call Func_6ebb
ld hl, PokemonFightingFitText
call PrintText
- callab IsPikachuInOurParty
+ callab IsStarterPikachuInOurParty
jr nc, .notInParty
lb bc, 15, 0
call Func_6ebb
diff --git a/home.asm b/home.asm
index 7bcb7676..68342640 100644
--- a/home.asm
+++ b/home.asm
@@ -475,7 +475,7 @@ HandlePartyMenuInput:: ; 1226 (0:1226)
jr nz,.asm_1258
ld a,[wCurrentMenuItem]
ld [wWhichPokemon],a
- callab IsThisPartymonOurPikachu ; 3f:4e18
+ callab IsThisPartymonStarterPikachu_Party ; 3f:4e18
jr nc,.asm_1258
call Func_154a
jr nz,.asm_128f
@@ -2476,7 +2476,7 @@ ExecuteCurMapScriptInTable:: ; 30fc (0:30fc)
pop hl
pop af
push hl
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
bit 4, [hl]
res 4, [hl]
jr z, .useProvidedIndex ; test if map script index was overridden manually
@@ -2574,7 +2574,7 @@ TalkToTrainer:: ; 3168 (0:3168)
call ReadTrainerHeaderInfo ; read end battle text
pop de
call SaveEndBattleTextPointers
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
set 4, [hl] ; activate map script index override (index is set below)
ld hl, wFlags_0xcd60
bit 0, [hl] ; test if player is already engaging the trainer (because the trainer saw the player)
@@ -2596,7 +2596,7 @@ CheckFightingMapTrainers:: ; 31b5 (0:31b5)
ld [wTrainerHeaderFlagBit], a
ret
.trainerEngaging
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
set 3, [hl]
ld [wEmotionBubbleSpriteIndex], a
xor a ; EXCLAMATION_BUBBLE
@@ -2958,7 +2958,7 @@ IsItemInBag:: ; 3422 (0:3422)
IsSurfingPikachuInParty:: ; 342a (0:342a)
; set bit 6 of wd472 if true
-; also calls Func_3467, which is a bankswitch to IsPikachuInOurParty
+; also calls Func_3467, which is a bankswitch to IsStarterPikachuInOurParty
ld a,[wd472]
and $3f
ld [wd472],a
@@ -3001,7 +3001,7 @@ IsSurfingPikachuInParty:: ; 342a (0:342a)
Func_3467:: ; 3467 (0:3467)
push hl
push bc
- callab IsPikachuInOurParty
+ callab IsStarterPikachuInOurParty
pop bc
pop hl
ret nc
diff --git a/home/overworld.asm b/home/overworld.asm
index f08ef86a..d9949d5c 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -267,7 +267,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
.battleOccurred
ld hl,wd72d
res 6,[hl]
- ld hl,W_FLAGS_D733
+ ld hl,wFlags_D733
res 3,[hl]
ld hl,wd126
set 5,[hl]
@@ -390,7 +390,7 @@ CheckWarpsNoCollisionLoop:: ; 04d5 (0:04d5)
pop hl
jr nc,CheckWarpsNoCollisionRetry2
; if the extra check passed
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 2,a
jr nz,WarpFound1
push de
@@ -1603,7 +1603,7 @@ JoypadOverworld:: ; 0c51 (0:0c51)
ret
ForceBikeDown:: ; 0c65 (0:0c65)
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 3,a ; check if a trainer wants a challenge
ret nz
ld a,[wCurMap]
@@ -1989,7 +1989,7 @@ LoadMapData:: ; 1241 (0:1241)
ld a,[wd732]
and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
jr nz,.restoreRomBank
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 1,a
jr nz,.restoreRomBank
call Func_21e3 ; music related
diff --git a/macros.asm b/macros.asm
index 895048a6..d71fc5a8 100644
--- a/macros.asm
+++ b/macros.asm
@@ -17,6 +17,22 @@ lb: MACRO ; r, hi, lo
ld \1, (\2) << 8 + ((\3) & $ff)
ENDM
+SHADE_BLACK EQU %11
+SHADE_DARK EQU %10
+SHADE_LIGHT EQU %01
+SHADE_WHITE EQU %00
+
+setpal: MACRO
+ ld a, \1 << 6 | \2 << 4 | \3 << 2 | \4
+ENDM
+
+setpalBGP: MACRO
+ setpal SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE
+ENDM
+
+setpalOBP: MACRO
+ setpal SHADE_BLACK, SHADE_DARK, SHADE_WHITE, SHADE_WHITE
+ENDM
; Constant enumeration is useful for monsters, items, moves, etc.
const_def: MACRO
diff --git a/main.asm b/main.asm
index e36f755f..13ee5769 100755
--- a/main.asm
+++ b/main.asm
@@ -499,7 +499,7 @@ TestBattle:
ld a, %10000000 ; EARTHBADGE
ld [wObtainedBadges], a
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
set 0, [hl]
; Reset the party.
@@ -2534,7 +2534,7 @@ ApplyOutOfBattlePoisonDamage: ; c3de (3:43de)
ld a, $d0
ld [hSpriteIndexOrTextID], a
call DisplayTextID
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc, .curMonNotPlayerPikachu
ld e, $3
callab PlayPikachuSoundClip
diff --git a/scripts/halloffameroom.asm b/scripts/halloffameroom.asm
index 1da6d3f5..466ce77d 100755
--- a/scripts/halloffameroom.asm
+++ b/scripts/halloffameroom.asm
@@ -28,7 +28,7 @@ HallofFameRoomScript2: ; 5a4bb (16:64bb)
predef HallOfFamePC
pop af
ld [wLetterPrintingDelayFlags], a
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
res 1, [hl]
inc hl
set 0, [hl]
diff --git a/scripts/oakslab.asm b/scripts/oakslab.asm
index be254970..40ecd1f9 100755
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -116,7 +116,7 @@ OaksLabScript4: ; 1cbd2 (7:4bd2)
ld [hSpriteFacingDirection], a
call SetSpriteFacingDirectionAndDelay
call UpdateSprites
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
res 1, [hl]
call PlayDefaultMusic
diff --git a/scripts/seafoamislands4.asm b/scripts/seafoamislands4.asm
index 90d282cf..e3234b0a 100755
--- a/scripts/seafoamislands4.asm
+++ b/scripts/seafoamislands4.asm
@@ -70,7 +70,7 @@ SeafoamIslands4Script0: ; 46603 (11:6603)
dec a
ld [wSimulatedJoypadStatesIndex], a
call StartSimulatingJoypadStates
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
set 2, [hl]
ld a, $1
ld [wSeafoamIslands4CurScript], a
@@ -112,7 +112,7 @@ SeafoamIslands4Script2: ; 46644 (11:6644)
ld [wSpriteStateData2 + $06], a
ld hl, wd730
set 7, [hl]
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
set 2, [hl]
ld a, $3
.asm_4667b
diff --git a/scripts/seafoamislands5.asm b/scripts/seafoamislands5.asm
index 17ea82cb..98c27666 100755
--- a/scripts/seafoamislands5.asm
+++ b/scripts/seafoamislands5.asm
@@ -46,7 +46,7 @@ SeafoamIslands5Script0: ; 467c7 (11:67c7)
ld a, D_UP
ld [wSimulatedJoypadStatesEnd], a
call StartSimulatingJoypadStates
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
res 2, [hl]
ld a, $1
ld [wSeafoamIslands5CurScript], a
diff --git a/wram.asm b/wram.asm
index 97e7f35a..89edd69e 100755
--- a/wram.asm
+++ b/wram.asm
@@ -1698,7 +1698,7 @@ wPlayerNumAttacksLeft::
W_PLAYERCONFUSEDCOUNTER:: ; d06b
ds 1
-W_PLAYERTOXICCOUNTER:: ; d06c
+wPlayerToxicCounter:: ; d06c
ds 1
W_PLAYERDISABLEDMOVE:: ; d06d
; high nibble: which move is disabled (1-4)
@@ -1714,7 +1714,7 @@ wEnemyNumAttacksLeft:: ; d06f
W_ENEMYCONFUSEDCOUNTER:: ; d070
ds 1
-W_ENEMYTOXICCOUNTER:: ; d071
+wEnemyToxicCounter:: ; d071
ds 1
wEnemyDisabledMove:: ; d072
; high nibble: which move is disabled (1-4)
@@ -3017,7 +3017,7 @@ wd732:: ; d732
; bit 6: map destination is [wLastBlackoutMap] (usually the last used pokemon center, but could be the player's house)
ds 1
-W_FLAGS_D733:: ; d733
+wFlags_D733:: ; d733
; bit 0: running a test battle
; bit 4: use variable [W_CURMAPSCRIPT] instead of the provided index for next frame's map script (used to start battle when talking to trainers)
; bit 7: used fly out of battle
diff --git a/yellow/main.asm b/yellow/main.asm
index ba1ccd6b..3671df39 100755
--- a/yellow/main.asm
+++ b/yellow/main.asm
@@ -1755,7 +1755,7 @@ ApplyOutOfBattlePoisonDamage: ; c3de (3:43de)
ld a, $d0
ld [hSpriteIndexOrTextID], a
call DisplayTextID
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
jr nc, .curMonNotPlayerPikachu
ld e, $3
callab PlayPikachuSoundClip
@@ -3870,7 +3870,7 @@ INCLUDE "engine/battle/display_effectiveness.asm"
INCLUDE "engine/items/tmhm.asm"
Func_2fd6a: ; 2fd6a (b:7d6a)
- callab IsThisPartymonOurPikachu
+ callab IsThisPartymonStarterPikachu_Party
ret nc
ld a, $3
ld [wd431], a
@@ -4113,7 +4113,9 @@ CeladonPrizeMenu: ; 5267d (14:667d)
SECTION "bank15",ROMX,BANK[$15]
- dr $54000,$56745
+ dr $54000,$5525f
+GainExperience: ; 5525f (15:525f)
+ dr $5525f,$56745
_GetSpritePosition1: ; 56745 (15:6745)
dr $56745,$56765
_GetSpritePosition2: ; 56765 (15:6765)