summaryrefslogtreecommitdiff
path: root/battle/core.asm
diff options
context:
space:
mode:
Diffstat (limited to 'battle/core.asm')
-rw-r--r--battle/core.asm488
1 files changed, 243 insertions, 245 deletions
diff --git a/battle/core.asm b/battle/core.asm
index 9a464023b..7e6eea9c6 100644
--- a/battle/core.asm
+++ b/battle/core.asm
@@ -3,7 +3,7 @@ BattleCore:
DoBattle: ; 3c000
xor a
ld [wBattleParticipantsNotFainted], a
- ld [wc6fc], a
+ ld [wBattleParticipantsIncludingFainted], a
ld [wPlayerAction], a
ld [BattleEnded], a
inc a
@@ -1248,7 +1248,7 @@ HandlePerishSong: ; 3c801
res SUBSTATUS_PERISH, [hl]
ld a, [hBattleTurn]
and a
- jr nz, .asm_3c85c
+ jr nz, .kill_enemy
ld hl, BattleMonHP
xor a
ld [hli], a
@@ -1261,7 +1261,7 @@ HandlePerishSong: ; 3c801
ld [hl], a
ret
-.asm_3c85c
+.kill_enemy
ld hl, EnemyMonHP
xor a
ld [hli], a
@@ -1334,12 +1334,12 @@ HandleWrap: ; 3c874
call GetSixteenthMaxHP
call SubtractHPFromUser
ld hl, BattleText_UsersHurtByStringBuffer1
- jr .asm_3c8e1
+ jr .print_text
.release_from_bounds
ld hl, BattleText_UserWasReleasedFromStringBuffer1
-.asm_3c8e1
+.print_text
jp StdBattleTextBox
; 3c8e4
@@ -1396,7 +1396,7 @@ HandleLeftovers: ; 3c8eb
call GetSixteenthMaxHP
call SwitchTurnCore
call RestoreHP
- ld hl, BattleText_0x80880
+ ld hl, BattleText_TargetRecoveredWithItem
jp StdBattleTextBox
; 3c93c
@@ -1569,7 +1569,7 @@ HandleFutureSight: ; 3ca26
cp $1
ret nz
- ld hl, BattleText_0x808b6
+ ld hl, BattleText_TargetWasHitByFutureSight
call StdBattleTextBox
ld a, BATTLE_VARS_MOVE
@@ -1645,12 +1645,12 @@ HanleDefrost: ; 3ca8f
ld a, [wBattleMode]
dec a
- jr z, .asm_3caef
+ jr z, .wild
ld a, [CurOTMon]
ld hl, OTPartyMon1Status
call GetPartyLocation
ld [hl], 0
-.asm_3caef
+.wild
call UpdateBattleHuds
call SetPlayerTurn
@@ -1661,13 +1661,13 @@ HanleDefrost: ; 3ca8f
HandleSafeguard: ; 3cafb
ld a, [hLinkPlayerNumber]
cp $1
- jr z, .asm_3cb06
- call .asm_3cb09
- jr .asm_3cb1c
+ jr z, .player1
+ call .CheckPlayer
+ jr .CheckEnemy
-.asm_3cb06
- call .asm_3cb1c
-.asm_3cb09
+.player1
+ call .CheckEnemy
+.CheckPlayer
ld a, [PlayerScreens]
bit SCREENS_SAFEGUARD, a
ret z
@@ -1677,9 +1677,9 @@ HandleSafeguard: ; 3cafb
res SCREENS_SAFEGUARD, a
ld [PlayerScreens], a
xor a
- jr .asm_3cb2e
+ jr .print
-.asm_3cb1c
+.CheckEnemy
ld a, [EnemyScreens]
bit SCREENS_SAFEGUARD, a
ret z
@@ -1690,7 +1690,7 @@ HandleSafeguard: ; 3cafb
ld [EnemyScreens], a
ld a, $1
-.asm_3cb2e
+.print
ld [hBattleTurn], a
ld hl, BattleText_SafeguardFaded
jp StdBattleTextBox
@@ -1712,7 +1712,7 @@ HandleScreens: ; 3cb36
call .Copy
ld hl, PlayerScreens
ld de, PlayerLightScreenCount
- jr .FadeScreens
+ jr .TickScreens
.CheckEnemy
call SetEnemyTurn
@@ -1721,11 +1721,11 @@ HandleScreens: ; 3cb36
ld hl, EnemyScreens
ld de, EnemyLightScreenCount
-.FadeScreens
+.TickScreens
bit SCREENS_LIGHT_SCREEN, [hl]
- call nz, FadeLightScreen
+ call nz, .LightScreenTick
bit SCREENS_REFLECT, [hl]
- call nz, FadeReflect
+ call nz, .ReflectTick
ret
.Copy
@@ -1740,7 +1740,7 @@ HandleScreens: ; 3cb36
; 3cb80
-FadeLightScreen: ; 3cb80
+.LightScreenTick: ; 3cb80
ld a, [de]
dec a
ld [de], a
@@ -1748,21 +1748,21 @@ FadeLightScreen: ; 3cb80
res SCREENS_LIGHT_SCREEN, [hl]
push hl
push de
- ld hl, BattleText_PkmnnLightScreenFell
+ ld hl, BattleText_PkmnLightScreenFell
call StdBattleTextBox
pop de
pop hl
ret
; 3cb91
-FadeReflect: ; 3cb91
+.ReflectTick: ; 3cb91
inc de
ld a, [de]
dec a
ld [de], a
ret nz
res SCREENS_REFLECT, [hl]
- ld hl, BattleText_0x80905
+ ld hl, BattleText_PkmnReflectFaded
jp StdBattleTextBox
; 3cb9e
@@ -2110,8 +2110,8 @@ HandleEnemyMonFaint: ; 3cd55
or [hl]
call z, FaintYourPokemon
xor a
- ld [wc6f7], a
- call Function3ce01
+ ld [wWhichMonFaintedFirst], a
+ call UpdateBattleStateAndExperienceAfterEnemyFaint
call CheckPlayerPartyForFitPkmn
ld a, d
and a
@@ -2158,14 +2158,14 @@ HandleEnemyMonFaint: ; 3cd55
ld a, $1
ld [wPlayerAction], a
- call Function3cf4a
+ call HandleEnemySwitch
jp z, WildFled_EnemyFled_LinkBattleCanceled
jr DoubleSwitch
.player_mon_not_fainted
ld a, $1
ld [wPlayerAction], a
- call Function3cf4a
+ call HandleEnemySwitch
jp z, WildFled_EnemyFled_LinkBattleCanceled
xor a
ld [wPlayerAction], a
@@ -2202,7 +2202,7 @@ DoubleSwitch: ; 3cdca
ret
; 3ce01
-Function3ce01: ; 3ce01
+UpdateBattleStateAndExperienceAfterEnemyFaint: ; 3ce01
call UpdateBattleMonInParty
ld a, [wBattleMode]
dec a
@@ -2231,14 +2231,14 @@ Function3ce01: ; 3ce01
.wild2
call StopDangerSound
ld a, $1
- ld [wc6fd], a
+ ld [wDanger], a
.trainer
ld hl, BattleMonHP
ld a, [hli]
or [hl]
jr nz, .player_mon_did_not_faint
- ld a, [wc6f7]
+ ld a, [wWhichMonFaintedFirst]
and a
jr nz, .player_mon_did_not_faint
call PlayerMonFaintHappinessMod
@@ -2256,10 +2256,10 @@ Function3ce01: ; 3ce01
ld a, [wBattleResult]
and $c0
ld [wBattleResult], a
- call DoOthersShareExperience
+ call IsAnyMonHoldingExpShare
jr z, .skip_exp
ld hl, EnemyMonBaseStats
- ld b, $7
+ ld b, EnemyMonEnd - EnemyMonBaseStats
.loop
srl [hl]
inc hl
@@ -2268,32 +2268,32 @@ Function3ce01: ; 3ce01
.skip_exp
ld hl, EnemyMonBaseStats
- ld de, wc720
+ ld de, wBackupEnemyMonBaseStats
ld bc, EnemyMonEnd - EnemyMonBaseStats
call CopyBytes
xor a
- ld [wc71f], a
+ ld [wGivingExperienceToExpShareHolders], a
call GiveExperiencePoints
- call DoOthersShareExperience
+ call IsAnyMonHoldingExpShare
ret z
ld a, [wBattleParticipantsNotFainted]
push af
ld a, d
ld [wBattleParticipantsNotFainted], a
- ld hl, wc720
+ ld hl, wBackupEnemyMonBaseStats
ld de, EnemyMonBaseStats
ld bc, EnemyMonEnd - EnemyMonBaseStats
call CopyBytes
ld a, $1
- ld [wc71f], a
+ ld [wGivingExperienceToExpShareHolders], a
call GiveExperiencePoints
pop af
ld [wBattleParticipantsNotFainted], a
ret
; 3ceaa
-DoOthersShareExperience: ; 3ceaa
+IsAnyMonHoldingExpShare: ; 3ceaa
ld a, [PartyCount]
ld b, a
ld hl, PartyMon1
@@ -2406,7 +2406,7 @@ CheckEnemyTrainerDefeated: ; 3cf35
ret
; 3cf4a
-Function3cf4a: ; 3cf4a
+HandleEnemySwitch: ; 3cf4a
ld hl, EnemyHPPal
ld e, HP_BAR_LENGTH_PX
call UpdateHPPal
@@ -2442,15 +2442,13 @@ EnemyPartyMonEntrance: ; 3cf78
call BreakAttraction
pop af
and a
- jr nz, .asm_3cf8f
-
+ jr nz, .set
call EnemySwitch
- jr .asm_3cf92
+ jr .done_switch
-.asm_3cf8f
+.set
call EnemySwitch_SetMode
-
-.asm_3cf92
+.done_switch
call ResetBattleParticipants
call SetEnemyTurn
call SpikesDamage
@@ -2465,7 +2463,7 @@ WinTrainerBattle: ; 3cfa4
; Player won the battle
call StopDangerSound
ld a, $1
- ld [wc6fd], a
+ ld [wDanger], a
ld [BattleEnded], a
ld a, [wLinkMode]
and a
@@ -2499,7 +2497,7 @@ WinTrainerBattle: ; 3cfa4
call PrintWinLossText
.skip_win_loss_text
- jp Function3d02b
+ jp HandleBattleReward
.mobile
call BattleWinSlideInEnemyTrainerFrontpic
@@ -2528,7 +2526,7 @@ WinTrainerBattle: ; 3cfa4
ret
; 3d02b
-Function3d02b: ; 3d02b
+HandleBattleReward: ; 3d02b
ld a, [wAmuletCoin]
and a
call nz, .DoubleReward
@@ -2682,7 +2680,7 @@ PlayVictoryMusic: ; 3d0ea
dec a
jr nz, .trainer_victory
push de
- call DoOthersShareExperience
+ call IsAnyMonHoldingExpShare
pop de
jr nz, .play_music
ld hl, wPayDayMoney
@@ -2771,7 +2769,7 @@ HandlePlayerMonFaint: ; 3d14e
or [hl]
call z, FaintEnemyPokemon
ld a, $1
- ld [wc6f7], a
+ ld [wWhichMonFaintedFirst], a
call PlayerMonFaintHappinessMod
call CheckPlayerPartyForFitPkmn
ld a, d
@@ -2781,7 +2779,7 @@ HandlePlayerMonFaint: ; 3d14e
ld a, [hli]
or [hl]
jr nz, .notfainted
- call Function3ce01
+ call UpdateBattleStateAndExperienceAfterEnemyFaint
ld a, [wBattleMode]
dec a
jr nz, .trainer
@@ -2809,7 +2807,7 @@ HandlePlayerMonFaint: ; 3d14e
ret nz
ld a, $1
ld [wPlayerAction], a
- call Function3cf4a
+ call HandleEnemySwitch
jp z, WildFled_EnemyFled_LinkBattleCanceled
jp DoubleSwitch
; 3d1aa
@@ -2847,7 +2845,7 @@ PlayerMonFaintHappinessMod: ; 3d1aa
and %11000000
add $1
ld [wBattleResult], a
- ld a, [wc6f7]
+ ld a, [wWhichMonFaintedFirst]
and a
ret z
ret ; ??????????
@@ -2999,7 +2997,7 @@ SetUpBattlePartyMenu: ; switch to fullscreen menu?
ret
; 3d313
-Function3d313: ; 3d313
+JumpToPartyMenuAndPrintText: ; 3d313
callba WritePartyMenuTilemap
callba PrintPartyMenuText
call WaitBGMap
@@ -3008,14 +3006,14 @@ Function3d313: ; 3d313
ret
; 3d329
-Function3d329: ; 3d329
+SelectBattleMon: ; 3d329
call IsMobileBattle
jr z, .mobile
callba PartyMenuSelect
ret
.mobile
- callba Function100cb5
+ callba Mobile_PartyMenuSelect
ret
; 3d33c
@@ -3023,8 +3021,8 @@ PickPartyMonInBattle: ; 3d33c
.loop
ld a, $2 ; Which PKMN?
ld [PartyMenuActionText], a
- call Function3d313
- call Function3d329
+ call JumpToPartyMenuAndPrintText
+ call SelectBattleMon
ret c
call CheckIfPartyHasPkmnToBattleWith
jr z, .loop
@@ -3338,7 +3336,7 @@ EnemySwitch: ; 3d4e1
; If we're here, then we're switching too
xor a
ld [wBattleParticipantsNotFainted], a
- ld [wc6fc], a
+ ld [wBattleParticipantsIncludingFainted], a
ld [wPlayerAction], a
inc a
ld [wEnemyIsSwitching], a
@@ -3403,7 +3401,7 @@ ResetEnemyBattleVars: ; 3d557
ld [LastEnemyMove], a
ld [CurEnemyMove], a
dec a
- ld [wc6e6], a
+ ld [wEnemyItemState], a
xor a
ld [wPlayerWrapCount], a
hlcoord 18, 0
@@ -3416,7 +3414,7 @@ ResetEnemyBattleVars: ; 3d557
ResetBattleParticipants: ; 3d57a
xor a
ld [wBattleParticipantsNotFainted], a
- ld [wc6fc], a
+ ld [wBattleParticipantsIncludingFainted], a
AddBattleParticipant: ; 3d581
ld a, [CurBattleMon]
ld c, a
@@ -3425,7 +3423,7 @@ AddBattleParticipant: ; 3d581
push bc
predef FlagPredef
pop bc
- ld hl, wc6fc
+ ld hl, wBattleParticipantsIncludingFainted
predef_jump FlagPredef
; 3d599
@@ -3434,7 +3432,7 @@ FindPkmnInOTPartyToSwitchIntoBattle: ; 3d599
ld a, $1
ld [Buffer1], a
ld [Buffer2], a
-.asm_3d5a3
+.loop
ld hl, Buffer1
sla [hl]
inc hl
@@ -3442,10 +3440,10 @@ FindPkmnInOTPartyToSwitchIntoBattle: ; 3d599
inc b
ld a, [OTPartyCount]
cp b
- jp z, Function3d672
+ jp z, ScoreMonTypeMatchups
ld a, [CurOTMon]
cp b
- jr z, .asm_3d5d0
+ jr z, .discourage
ld hl, OTPartyMon1HP
push bc
ld a, b
@@ -3455,15 +3453,15 @@ FindPkmnInOTPartyToSwitchIntoBattle: ; 3d599
ld a, [hl]
or c
pop bc
- jr z, .asm_3d5d0
+ jr z, .discourage
call LookUpTheEffectivenessOfEveryMove
call IsThePlayerPkmnTypesEffectiveAgainstOTPkmn
- jr .asm_3d5a3
+ jr .loop
-.asm_3d5d0
+.discourage
ld hl, Buffer2
set 0, [hl]
- jr .asm_3d5a3
+ jr .loop
; 3d5d7
LookUpTheEffectivenessOfEveryMove: ; 3d5d7
@@ -3517,7 +3515,7 @@ IsThePlayerPkmnTypesEffectiveAgainstOTPkmn: ; 3d618
ld a, [hl]
dec a
ld hl, BaseData + 7 ; type
- ld bc, $20
+ ld bc, BaseData1 - BaseData0
call AddNTimes
ld de, EnemyMonType
ld bc, 2
@@ -3529,80 +3527,80 @@ IsThePlayerPkmnTypesEffectiveAgainstOTPkmn: ; 3d618
callab BattleCheckTypeMatchup
ld a, [wd265]
cp 10 + 1 ; 1.0 + 0.1
- jr nc, .asm_3d663
+ jr nc, .super_effective
ld a, [BattleMonType2]
ld [wPlayerMoveStruct + MOVE_TYPE], a
callab BattleCheckTypeMatchup
ld a, [wd265]
cp 10 + 1 ; 1.0 + 0.1
- jr nc, .asm_3d663
+ jr nc, .super_effective
pop bc
ret
-.asm_3d663
+.super_effective
pop bc
ld hl, Buffer1
bit 0, [hl]
- jr nz, .asm_3d66f
+ jr nz, .reset
inc hl
set 0, [hl]
ret
-.asm_3d66f
+.reset
res 0, [hl]
ret
; 3d672
-Function3d672: ; 3d672
-.asm_3d672
+ScoreMonTypeMatchups: ; 3d672
+.loop1
ld hl, Buffer1
sla [hl]
inc hl
sla [hl]
- jr nc, .asm_3d672
+ jr nc, .loop1
ld a, [OTPartyCount]
ld b, a
ld c, [hl]
-.asm_3d681
+.loop2
sla c
- jr nc, .asm_3d68a
+ jr nc, .okay
dec b
- jr z, .asm_3d6a7
- jr .asm_3d681
+ jr z, .loop5
+ jr .loop2
-.asm_3d68a
+.okay
ld a, [Buffer1]
and a
- jr z, .asm_3d69a
+ jr z, .okay2
ld b, $ff
ld c, a
-.asm_3d693
+.loop3
inc b
sla c
- jr nc, .asm_3d693
- jr .asm_3d6c9
+ jr nc, .loop3
+ jr .quit
-.asm_3d69a
+.okay2
ld b, $ff
ld a, [Buffer2]
ld c, a
-.asm_3d6a0
+.loop4
inc b
sla c
- jr c, .asm_3d6a0
- jr .asm_3d6c9
+ jr c, .loop4
+ jr .quit
-.asm_3d6a7
+.loop5
ld a, [OTPartyCount]
ld b, a
call BattleRandom
and $7
cp b
- jr nc, .asm_3d6a7
+ jr nc, .loop5
ld b, a
ld a, [CurOTMon]
cp b
- jr z, .asm_3d6a7
+ jr z, .loop5
ld hl, OTPartyMon1HP
push bc
ld a, b
@@ -3612,9 +3610,9 @@ Function3d672: ; 3d672
ld c, a
ld a, [hl]
or c
- jr z, .asm_3d6a7
+ jr z, .loop5
-.asm_3d6c9
+.quit
ret
; 3d6ca
@@ -3971,7 +3969,7 @@ TryToRunAwayFromBattle: ; 3d8b3
and a
jr z, .can_escape
ld [hDivisor], a
- ld b, $2
+ ld b, 2
call Divide
ld a, [hQuotient + 1]
and a
@@ -4142,7 +4140,7 @@ GetEnemyMonDVs: ; 3da97
ld a, [EnemySubStatus5]
bit SUBSTATUS_TRANSFORMED, a
ret z
- ld hl, wc6f2
+ ld hl, wEnemyBackupDVs
ld a, [wBattleMode]
dec a
ret z
@@ -4163,7 +4161,7 @@ ResetPlayerStatLevels: ; 3dab1
; 3dabd
-Function3dabd: ; 3dabd
+InitEnemyMon: ; 3dabd
ld a, [CurPartyMon]
ld hl, OTPartyMon1Species
call GetPartyLocation
@@ -4205,12 +4203,12 @@ endr
ld hl, BaseStats
ld de, EnemyMonBaseStats
ld b, 5
-.asm_3db25
+.loop
ld a, [hli]
ld [de], a
inc de
dec b
- jr nz, .asm_3db25
+ jr nz, .loop
ld a, [CurPartyMon]
ld [CurOTMon], a
ret
@@ -4250,7 +4248,7 @@ SendOutPlayerMon: ; 3db5f
ld [hBGMapMode], a
call GetMonBackpic
xor a
- ld [hFillBox], a
+ ld [hGraphicStartTile], a
ld [wd0d2], a
ld [CurMoveNum], a
ld [TypeModifier], a
@@ -4418,7 +4416,7 @@ PursuitSwitch: ; 3dc5b
ld [CryTracks], a
ld a, [BattleMonSpecies]
call PlayStereoCry
- ld a, [wc71a]
+ ld a, [LastPlayerMon]
ld c, a
ld hl, wBattleParticipantsNotFainted
ld b, RESET_FLAG
@@ -4452,7 +4450,7 @@ PursuitSwitch: ; 3dc5b
ret
; 3dce6
-Function3dce6: ; 3dce6
+RecallPlayerMon: ; 3dce6
ld a, [hBattleTurn]
push af
xor a
@@ -4887,7 +4885,7 @@ CheckDanger: ; 3df9e
ld a, [hli]
or [hl]
jr z, .no_danger
- ld a, [wc6fd]
+ ld a, [wDanger]
and a
jr nz, .done
ld a, [PlayerHPPal]
@@ -4943,16 +4941,16 @@ PrintPlayerHUD: ; 3dfbf
ld [MonType], a
callab GetGender
ld a, " "
- jr c, .asm_3e013
+ jr c, .got_gender_char
ld a, "♂"
- jr nz, .asm_3e013
+ jr nz, .got_gender_char
ld a, "♀"
-.asm_3e013
+.got_gender_char
hlcoord 17, 8
ld [hl], a
hlcoord 14, 8
- push af
+ push af ; back up gender
push hl
ld de, BattleMonStatus
predef PlaceNonFaintStatus
@@ -4961,10 +4959,10 @@ PrintPlayerHUD: ; 3dfbf
ret nz
ld a, b
cp " "
- jr nz, .asm_3e02d
- dec hl
+ jr nz, .copy_level ; male or female
+ dec hl ; genderless
-.asm_3e02d
+.copy_level
ld a, [BattleMonLevel]
ld [TempMonLevel], a
jp PrintLevel
@@ -5009,7 +5007,7 @@ DrawEnemyHUD: ; 3e043
ld a, [EnemySubStatus5]
bit SUBSTATUS_TRANSFORMED, a
jr z, .ok
- ld hl, wc6f2
+ ld hl, wEnemyBackupDVs
.ok
ld a, [hli]
ld [de], a
@@ -5322,7 +5320,7 @@ BattleMenu_Pack: ; 3e1c7
BattleMenu_PKMN: ; 3e28d
call LoadStandardMenuDataHeader
-Function3e290:
+BattleMenuPKMN_ReturnFromStats:
call ExitMenu
call LoadStandardMenuDataHeader
call ClearBGPalettes
@@ -5330,8 +5328,8 @@ BattleMenuPKMN_Loop:
call SetUpBattlePartyMenu
xor a
ld [PartyMenuActionText], a
- call Function3d313
- call Function3d329
+ call JumpToPartyMenuAndPrintText
+ call SelectBattleMon
jr c, .Cancel
.loop
callba FreezeMonIcons
@@ -5356,7 +5354,7 @@ BattleMenuPKMN_Loop:
call Battle_StatsScreen
call CheckMobileBattleError
jr c, .Cancel
- jp Function3e290
+ jp BattleMenuPKMN_ReturnFromStats
.Cancel
call ClearSprites
@@ -5519,7 +5517,7 @@ BattleMonEntrance: ; 3e40b
call SetEnemyTurn
call PursuitSwitch
jr c, .ok
- call Function3dce6
+ call RecallPlayerMon
.ok
hlcoord 9, 7
@@ -5771,7 +5769,7 @@ MoveSelectionScreen: ; 3e4bc
dec a
cp c
jr z, .move_disabled
- ld a, [wc6e1]
+ ld a, [wUnusedPlayerLockedMove]
and a
jr nz, .skip2
ld a, [wMenuCursorY]
@@ -6258,12 +6256,12 @@ LoadEnemyMon: ; 3e8eb
; We don't need to be here if we're in a link battle
ld a, [wLinkMode]
and a
- jp nz, Function3dabd
+ jp nz, InitEnemyMon
; and also not in a BattleTower-Battle
ld a, [InBattleTowerBattle] ; ????
bit 0, a
- jp nz, Function3dabd
+ jp nz, InitEnemyMon
; Make sure everything knows what species we're working with
ld a, [TempEnemyMonSpecies]
@@ -6336,7 +6334,7 @@ LoadEnemyMon: ; 3e8eb
jr z, .InitDVs
; Unknown
- ld hl, wc6f2
+ ld hl, wEnemyBackupDVs
ld de, EnemyMonDVs
ld a, [hli]
ld [de], a
@@ -6848,7 +6846,8 @@ CheckUnownLetter: ; 3eb75
; 3ebc7
-Function3ebc7: ; 3ebc7
+SwapBattlerLevels: ; 3ebc7
+; unreferenced
push bc
ld a, [BattleMonLevel]
ld b, a
@@ -7383,7 +7382,7 @@ GiveExperiencePoints: ; 3ee3b
bit 0, a
ret nz
- call Function3f0d4
+ call .EvenlyDivideExpAmongParticipants
xor a
ld [CurPartyMon], a
ld bc, PartyMon1Species
@@ -7407,6 +7406,7 @@ GiveExperiencePoints: ; 3ee3b
pop bc
jp z, .skip_stats
+; give stat exp
ld hl, MON_STAT_EXP + 1
add hl, bc
ld d, h
@@ -7472,6 +7472,7 @@ GiveExperiencePoints: ; 3ee3b
ld [hDivisor], a
ld b, 4
call Divide
+; Boost Experience for traded Pokemon
pop bc
ld hl, MON_ID
add hl, bc
@@ -7489,10 +7490,12 @@ GiveExperiencePoints: ; 3ee3b
ld a, $1
.no_boost
+; Boost experience for a Trainer Battle
ld [StringBuffer2 + 2], a
ld a, [wBattleMode]
dec a
call nz, BoostExp
+; Boost experience for Lucky Egg
push bc
ld a, MON_ITEM
call GetPartyParamLocation
@@ -7513,7 +7516,7 @@ GiveExperiencePoints: ; 3ee3b
ld a, [StringBuffer2]
ld [hQuotient + 1], a
pop bc
- call Function3f136
+ call AnimateExpBar
push bc
call LoadTileMapToTempTileMap
pop bc
@@ -7748,26 +7751,26 @@ GiveExperiencePoints: ; 3ee3b
jp ResetBattleParticipants
; 3f0d4
-Function3f0d4: ; 3f0d4
+.EvenlyDivideExpAmongParticipants
; count number of battle participants
ld a, [wBattleParticipantsNotFainted]
ld b, a
ld c, PARTY_LENGTH
ld d, 0
-.loop
+.count_loop
xor a
srl b
adc d
ld d, a
dec c
- jr nz, .loop
+ jr nz, .count_loop
cp 2
ret c
ld [wd265], a
ld hl, EnemyMonBaseStats
ld c, EnemyMonEnd - EnemyMonBaseStats
-.loop2
+.count_loop2
xor a
ld [hDividend + 0], a
ld a, [hl]
@@ -7779,7 +7782,7 @@ Function3f0d4: ; 3f0d4
ld a, [hQuotient + 2]
ld [hli], a
dec c
- jr nz, .loop2
+ jr nz, .count_loop2
ret
; 3f106
@@ -7827,7 +7830,7 @@ TextJump_StringBuffer2ExpPoints: ; 3f131
; 3f136
-Function3f136: ; 3f136
+AnimateExpBar: ; 3f136
push bc
ld hl, CurPartyMon
@@ -7864,15 +7867,15 @@ Function3f136: ; 3f136
ld a, [wd003]
adc [hl]
ld [hld], a
- jr nc, .asm_3f186
+ jr nc, .NoOverflow
inc [hl]
- jr nz, .asm_3f186
+ jr nz, .NoOverflow
ld a, $ff
ld [hli], a
ld [hli], a
ld [hl], a
-.asm_3f186
+.NoOverflow
ld d, MAX_LEVEL
callab CalcExpAtLevel
ld a, [hProduct + 1]
@@ -7888,7 +7891,7 @@ Function3f136: ; 3f136
sbc c
ld a, [hl]
sbc b
- jr c, .asm_3f1a8
+ jr c, .AlreadyAtMaxExp
ld a, b
ld [hli], a
ld a, c
@@ -7896,37 +7899,37 @@ Function3f136: ; 3f136
ld a, d
ld [hld], a
-.asm_3f1a8
+.AlreadyAtMaxExp
callab CalcLevel
ld a, d
pop bc
pop de
ld d, a
cp e
- jr nc, .asm_3f1b7
+ jr nc, .LoopLevels
ld a, e
ld d, a
-.asm_3f1b7
+.LoopLevels
ld a, e
cp MAX_LEVEL
- jr nc, .asm_3f1ff
+ jr nc, .FinishExpBar
cp d
- jr z, .asm_3f1ff
+ jr z, .FinishExpBar
inc a
ld [TempMonLevel], a
ld [CurPartyLevel], a
ld [BattleMonLevel], a
push de
- call Function3f21b
+ call .PlayExpBarSound
ld c, $40
- call Function3f22c
+ call .LoopBarAnimation
call PrintPlayerHUD
ld hl, BattleMonNick
ld de, StringBuffer1
ld bc, PKMN_NAME_LENGTH
call CopyBytes
- call Function3dfe
+ call TerminateExpBarSound
ld de, SFX_HIT_END_OF_EXP_BAR
call PlaySFX
callba AnimateEndOfExpBar
@@ -7936,9 +7939,9 @@ Function3f136: ; 3f136
pop de
inc e
ld b, $0
- jr .asm_3f1b7
+ jr .LoopLevels
-.asm_3f1ff
+.FinishExpBar
push bc
ld b, d
ld de, TempMonExp + 2
@@ -7946,9 +7949,9 @@ Function3f136: ; 3f136
ld a, b
pop bc
ld c, a
- call Function3f21b
- call Function3f22c
- call Function3dfe
+ call .PlayExpBarSound
+ call .LoopBarAnimation
+ call TerminateExpBarSound
pop af
ld [hProduct + 2], a
pop af
@@ -7957,9 +7960,8 @@ Function3f136: ; 3f136
.finish
pop bc
ret
-; 3f21b
-Function3f21b: ; 3f21b
+.PlayExpBarSound
push bc
call WaitSFX
ld de, SFX_EXP_BAR
@@ -7968,12 +7970,11 @@ Function3f21b: ; 3f21b
call DelayFrames
pop bc
ret
-; 3f22c
-Function3f22c: ; 3f22c
- ld d, $3
+.LoopBarAnimation
+ ld d, 3
dec b
-.asm_3f22f
+.anim_loop
inc b
push bc
push de
@@ -7989,7 +7990,7 @@ Function3f22c: ; 3f22c
pop bc
ld a, c
cp b
- jr z, .asm_3f268
+ jr z, .end_animation
inc b
push bc
push de
@@ -8003,16 +8004,14 @@ Function3f22c: ; 3f22c
xor a
ld [hBGMapMode], a
dec d
- jr nz, .asm_3f263
- ld d, $1
-
-.asm_3f263
+ jr nz, .min_number_of_frames
+ ld d, 1
+.min_number_of_frames
pop bc
ld a, c
cp b
- jr nz, .asm_3f22f
-
-.asm_3f268
+ jr nz, .anim_loop
+.end_animation
ld a, $1
ld [hBGMapMode], a
ret
@@ -8184,7 +8183,7 @@ TextJump_GoodComeBack: ; 3f352
db "@"
; 3f357
-Function_TextJump_ComeBack: ; 3f357
+UnusedFunction_TextJump_ComeBack: ; 3f357
; this function doesn't seem to be used
ld hl, TextJump_ComeBack
ret
@@ -8575,12 +8574,12 @@ InitEnemyTrainer: ; 3f594
ld de, VTiles2
callab GetTrainerPic
xor a
- ld [hFillBox], a
+ ld [hGraphicStartTile], a
dec a
- ld [wc6e6], a
+ ld [wEnemyItemState], a
hlcoord 12, 0
lb bc, 7, 7
- predef FillBox
+ predef PlaceGraphic
ld a, -1
ld [CurOTMon], a
ld a, TRAINER_BATTLE
@@ -8640,14 +8639,15 @@ InitEnemyWildmon: ; 3f607
predef FrontpicPredef
xor a
ld [TrainerClass], a
- ld [hFillBox], a
+ ld [hGraphicStartTile], a
hlcoord 12, 0
lb bc, 7, 7
- predef FillBox
+ predef PlaceGraphic
ret
; 3f662
Function3f662: ; 3f662
+; XXX
ld hl, EnemyMonMoves
ld de, wListMoves_MoveIndicesBuffer
ld b, NUM_MOVES
@@ -8852,8 +8852,8 @@ DetermineMobileBattleResult: ; 3f77c
ld a, BANK(sLinkBattleStats)
call GetSRAMBank
- call Function3fa42
- call Function3f85f
+ call AddLastMobileBattleToLinkRecord
+ call ReadAndPrintLinkBattleRecord
call CloseSRAM
@@ -8905,7 +8905,7 @@ DisplayLinkRecord: ; 3f836
ld a, BANK(sLinkBattleStats)
call GetSRAMBank
- call Function3f85f
+ call ReadAndPrintLinkBattleRecord
call CloseSRAM
hlcoord 0, 0, AttrMap
@@ -8916,86 +8916,85 @@ DisplayLinkRecord: ; 3f836
ld b, SCGB_08
call GetSGBLayout
call SetPalettes
- ld c, $8
+ ld c, 8
call DelayFrames
call WaitPressAorB_BlinkCursor
ret
; 3f85f
-Function3f85f: ; 3f85f
+ReadAndPrintLinkBattleRecord: ; 3f85f
call ClearTileMap
call ClearSprites
- call .asm_3f8e0
+ call .PrintBattleRecord
hlcoord 0, 8
- ld b, $5
- ld de, sLinkBattleStats + $8
-.asm_3f870
+ ld b, 5
+ ld de, sLinkBattleRecord + 2
+.loop
push bc
push hl
push de
ld a, [de]
and a
- jr z, .asm_3f8c9
+ jr z, .PrintFormatString
ld a, [wSavedAtLeastOnce]
and a
- jr z, .asm_3f8c9
+ jr z, .PrintFormatString
push hl
push hl
ld h, d
ld l, e
ld de, wd002
- ld bc, $000a
+ ld bc, 10
call CopyBytes
- ld a, $50
+ ld a, "@"
ld [de], a
inc de
- ld bc, $0006
+ ld bc, 6
call CopyBytes
ld de, wd002
pop hl
call PlaceString
pop hl
- ld de, $001a
+ ld de, 26
add hl, de
push hl
ld de, wd00d
lb bc, 2, 4
call PrintNum
pop hl
- ld de, $0005
+ ld de, 5
add hl, de
push hl
ld de, wd00f
lb bc, 2, 4
call PrintNum
pop hl
- ld de, $0005
+ ld de, 5
add hl, de
ld de, wd011
lb bc, 2, 4
call PrintNum
- jr .asm_3f8cf
+ jr .next
-.asm_3f8c9
+.PrintFormatString
ld de, .Format
call PlaceString
-
-.asm_3f8cf
+.next
pop hl
- ld bc, $0012
+ ld bc, 18
add hl, bc
ld d, h
ld e, l
pop hl
- ld bc, $0028
+ ld bc, 2 * SCREEN_WIDTH
add hl, bc
pop bc
dec b
- jr nz, .asm_3f870
+ jr nz, .loop
ret
-.asm_3f8e0
+.PrintBattleRecord
hlcoord 1, 0
ld de, .Record
call PlaceString
@@ -9010,30 +9009,30 @@ Function3f85f: ; 3f85f
hlcoord 6, 4
ld de, sLinkBattleWins
- call .asm_3f92b
- jr c, .asm_3f92a
+ call .PrintZerosIfNoSaveFileExists
+ jr c, .quit
lb bc, 2, 4
call PrintNum
hlcoord 11, 4
ld de, sLinkBattleLosses
- call .asm_3f92b
+ call .PrintZerosIfNoSaveFileExists
lb bc, 2, 4
call PrintNum
hlcoord 16, 4
ld de, sLinkBattleDraws
- call .asm_3f92b
+ call .PrintZerosIfNoSaveFileExists
lb bc, 2, 4
call PrintNum
-.asm_3f92a
+.quit
ret
-.asm_3f92b
+.PrintZerosIfNoSaveFileExists
ld a, [wSavedAtLeastOnce]
and a
ret nz
@@ -9048,7 +9047,8 @@ Function3f85f: ; 3f85f
; 3f947
.Format ; 3f947
- db " --- <LNBRK> - - -@"
+ db " --- <LNBRK>"
+ db " - - -@"
.Record ; 3f964
db "<PLAYER>'s RECORD@"
.Result ; 3f96e
@@ -9166,17 +9166,17 @@ GetRoamMonSpecies: ; 3fa31
; 3fa42
-Function3fa42: ; 3fa42
+AddLastMobileBattleToLinkRecord: ; 3fa42
ld hl, OTPlayerID
ld de, StringBuffer1
ld bc, 2
call CopyBytes
ld hl, OTPlayerName
- ld bc, 10
+ ld bc, NAME_LENGTH - 1
call CopyBytes
- ld hl, s1_b254
- call Function3faa0
- ld hl, s1_b266
+ ld hl, sLinkBattleResults
+ call .StoreResult
+ ld hl, sLinkBattleRecord
ld d, 5
.loop
push hl
@@ -9218,24 +9218,22 @@ Function3fa42: ; 3fa42
pop hl
.done
- call Function3faa0
- call Function3fac8
+ call .StoreResult
+ call .FindOpponentAndAppendRecord
ret
; 3faa0
-
-Function3faa0: ; 3faa0
+.StoreResult: ; 3faa0
ld a, [wBattleResult]
and $f
cp $1
- ld bc, 13
+ ld bc, sLinkBattleWins + 1 - sLinkBattleResults
jr c, .okay
- ld bc, 15
+ ld bc, sLinkBattleLosses + 1 - sLinkBattleResults
jr z, .okay
- ld bc, 17
-
+ ld bc, sLinkBattleDraws + 1 - sLinkBattleResults
.okay
add hl, bc
- call Function3fabe
+ call .CheckOverflow
ret nc
inc [hl]
ret nz
@@ -9244,26 +9242,26 @@ Function3faa0: ; 3faa0
ret
; 3fabe
-Function3fabe: ; 3fabe
+.CheckOverflow: ; 3fabe
dec hl
ld a, [hl]
inc hl
- cp $27
+ cp 9999 / $100
ret c
ld a, [hl]
- cp $f
+ cp 9999 % $100
ret
; 3fac8
-Function3fac8: ; 3fac8
- ld b, $5
- ld hl, s1_b277
+.FindOpponentAndAppendRecord: ; 3fac8
+ ld b, 5
+ ld hl, sLinkBattleRecord + 17
ld de, wd002
-.loop
+.loop3
push bc
push de
push hl
- call Function3fb54
+ call .LoadPointer
pop hl
ld a, e
pop de
@@ -9279,10 +9277,10 @@ Function3fac8: ; 3fac8
add hl, bc
pop bc
dec b
- jr nz, .loop
+ jr nz, .loop3
ld b, $0
ld c, $1
-.loop2
+.loop4
ld a, b
add b
add b
@@ -9302,30 +9300,30 @@ Function3fac8: ; 3fac8
ld e, l
pop hl
push bc
- ld c, $3
+ ld c, 3
call StringCmp
pop bc
jr z, .equal
- jr nc, .done
+ jr nc, .done2
.equal
inc c
ld a, c
cp $5
- jr nz, .loop2
+ jr nz, .loop4
inc b
ld c, b
inc c
ld a, b
cp $4
- jr nz, .loop2
+ jr nz, .loop4
ret
-.done
+.done2
push bc
ld a, b
ld bc, 18
- ld hl, s1_b266
+ ld hl, sLinkBattleRecord
call AddNTimes
push hl
ld de, wd002
@@ -9336,7 +9334,7 @@ Function3fac8: ; 3fac8
push hl
ld a, c
ld bc, 18
- ld hl, s1_b266
+ ld hl, sLinkBattleRecord
call AddNTimes
pop de
push hl
@@ -9349,7 +9347,7 @@ Function3fac8: ; 3fac8
ret
; 3fb54
-Function3fb54: ; 3fb54
+.LoadPointer: ; 3fb54
ld e, $0
ld a, [hld]
ld c, a
@@ -9361,10 +9359,10 @@ Function3fb54: ; 3fb54
ld a, [hld]
adc b
ld b, a
- jr nc, .okay
+ jr nc, .okay2
inc e
-.okay
+.okay2
ld a, [hld]
add c
ld c, a
@@ -9402,10 +9400,10 @@ InitBattleDisplay: ; 3fb6c
ld a, $1
ld [hBGMapMode], a
ld a, $31
- ld [hFillBox], a
+ ld [hGraphicStartTile], a
hlcoord 2, 6
lb bc, 6, 6
- predef FillBox
+ predef PlaceGraphic
xor a
ld [hWY], a
ld [rWY], a
@@ -9497,24 +9495,24 @@ CopyBackpic: ; 3fc30
call Get2bpp
pop af
ld [rSVBK], a
- call Function3fc5b
+ call .LoadTrainerBackpicAsOAM
ld a, $31
- ld [hFillBox], a
+ ld [hGraphicStartTile], a
hlcoord 2, 6
lb bc, 6, 6
- predef FillBox
+ predef PlaceGraphic
ret
; 3fc5b
-Function3fc5b: ; 3fc5b
+.LoadTrainerBackpicAsOAM: ; 3fc5b
ld hl, Sprites
xor a
ld [hMapObjectIndexBuffer], a
ld b, $6
- ld e, $a8
+ ld e, 21 * 8
.outer_loop
ld c, $3
- ld d, $40
+ ld d, 8 * 8
.inner_loop
ld [hl], d
inc hl