pokecrystal-board/engine/battle/core.asm

9401 lines
146 KiB
NASM
Raw Normal View History

; Core components of the battle engine.
BattleCore:
DoBattle: ; 3c000
xor a
2015-11-07 18:04:54 -08:00
ld [wBattleParticipantsNotFainted], a
2016-01-12 09:46:18 -08:00
ld [wBattleParticipantsIncludingFainted], a
ld [wBattlePlayerAction], a
2018-01-23 14:39:09 -08:00
ld [wBattleEnded], a
inc a
2016-08-07 15:14:20 -07:00
ld [wBattleHasJustStarted], a
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1HP
2015-11-06 06:04:27 -08:00
ld bc, PARTYMON_STRUCT_LENGTH - 1
ld d, BATTLEACTION_SWITCH1 - 1
.loop
inc d
ld a, [hli]
or [hl]
2015-11-06 06:04:27 -08:00
jr nz, .alive
add hl, bc
2015-11-06 06:04:27 -08:00
jr .loop
2015-11-06 06:04:27 -08:00
.alive
ld a, d
ld [wBattleAction], a
ld a, [wLinkMode]
and a
2015-11-06 06:04:27 -08:00
jr z, .not_linked
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
2015-11-06 06:04:27 -08:00
jr z, .player_2
2015-11-06 06:04:27 -08:00
.not_linked
ld a, [wBattleMode]
dec a
2015-11-06 06:04:27 -08:00
jr z, .wild
xor a
2015-11-08 16:09:36 -08:00
ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
2015-11-07 18:04:54 -08:00
call EnemySwitch
2015-11-06 06:04:27 -08:00
.wild
ld c, 40
call DelayFrames
2015-11-06 06:04:27 -08:00
.player_2
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
call CheckPlayerPartyForFitMon
ld a, d
and a
jp z, LostBattle
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
2015-09-09 16:27:07 -07:00
cp BATTLETYPE_DEBUG
2015-11-06 06:04:27 -08:00
jp z, .tutorial_debug
cp BATTLETYPE_TUTORIAL
2015-11-06 06:04:27 -08:00
jp z, .tutorial_debug
xor a
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
2015-11-06 06:04:27 -08:00
.loop2
2016-03-01 19:31:21 -08:00
call CheckIfCurPartyMonIsFitToFight
2015-11-06 06:04:27 -08:00
jr nz, .alive2
2018-01-23 14:39:09 -08:00
ld hl, wCurPartyMon
inc [hl]
2015-11-06 06:04:27 -08:00
jr .loop2
2015-11-06 06:04:27 -08:00
.alive2
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wLastPlayerMon], a
ld a, [wCurPartyMon]
ld [wCurBattleMon], a
inc a
2018-01-23 14:39:09 -08:00
ld hl, wPartySpecies - 1
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wCurPartySpecies], a
ld [wTempBattleMonSpecies], a
hlcoord 1, 5
ld a, 9
call SlideBattlePicOut
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-11-07 18:04:54 -08:00
call ResetBattleParticipants
2015-11-06 13:42:38 -08:00
call InitBattleMon
call ResetPlayerStatLevels
call SendOutMonText
call NewBattleMonStatus
call BreakAttraction
2015-11-07 06:48:32 -08:00
call SendOutPlayerMon
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
call SetPlayerTurn
call SpikesDamage
ld a, [wLinkMode]
and a
2015-11-06 06:04:27 -08:00
jr z, .not_linked_2
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
2015-11-06 06:04:27 -08:00
jr nz, .not_linked_2
xor a
2015-11-08 16:09:36 -08:00
ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
2015-11-07 18:04:54 -08:00
call EnemySwitch
call SetEnemyTurn
call SpikesDamage
2015-11-06 06:04:27 -08:00
.not_linked_2
jp BattleTurn
2015-11-06 06:04:27 -08:00
.tutorial_debug
jp BattleMenu
; 3c0e5
WildFled_EnemyFled_LinkBattleCanceled: ; 3c0e5
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
and BATTLERESULT_BITMASK
add DRAW
2015-10-24 07:34:19 -07:00
ld [wBattleResult], a
ld a, [wLinkMode]
and a
2015-08-24 16:56:30 -07:00
ld hl, BattleText_WildFled
jr z, .print_text
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
and BATTLERESULT_BITMASK
ld [wBattleResult], a ; WIN
2015-08-24 16:56:30 -07:00
ld hl, BattleText_EnemyFled
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
jr nc, .print_text
ld hl, wcd2a
bit 4, [hl]
jr nz, .skip_text
2015-08-24 16:56:30 -07:00
ld hl, BattleText_LinkErrorBattleCanceled
.print_text
call StdBattleTextBox
.skip_text
2015-10-19 13:49:29 -07:00
call StopDangerSound
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
jr c, .skip_sfx
ld de, SFX_RUN
call PlaySFX
.skip_sfx
call SetPlayerTurn
ld a, 1
2018-01-23 14:39:09 -08:00
ld [wBattleEnded], a
ret
; 3c12f
BattleTurn: ; 3c12f
.loop
call Stubbed_Function3c1bf
2015-11-08 10:27:26 -08:00
call CheckContestBattleOver
jp c, .quit
xor a
ld [wPlayerIsSwitching], a
ld [wEnemyIsSwitching], a
2016-08-07 15:14:20 -07:00
ld [wBattleHasJustStarted], a
ld [wPlayerJustGotFrozen], a
ld [wEnemyJustGotFrozen], a
2018-01-23 14:39:09 -08:00
ld [wCurDamage], a
ld [wCurDamage + 1], a
2015-11-08 16:09:36 -08:00
call HandleBerserkGene
call UpdateBattleMonInParty
2017-12-24 09:47:30 -08:00
farcall AIChooseMove
call IsMobileBattle
jr nz, .not_disconnected
2017-12-24 09:47:30 -08:00
farcall Function100da5
farcall StartMobileInactivityTimer
farcall Function100dd8
jp c, .quit
.not_disconnected
2015-11-08 16:09:36 -08:00
call CheckPlayerLockedIn
2015-11-08 10:27:26 -08:00
jr c, .skip_iteration
.loop1
call BattleMenu
jr c, .quit
2018-01-23 14:39:09 -08:00
ld a, [wBattleEnded]
and a
jr nz, .quit
2015-11-08 16:09:36 -08:00
ld a, [wForcedSwitch] ; roared/whirlwinded/teleported
and a
jr nz, .quit
2015-11-08 10:27:26 -08:00
.skip_iteration
2015-11-08 16:09:36 -08:00
call ParsePlayerAction
2015-11-08 10:27:26 -08:00
jr nz, .loop1
2015-11-08 16:09:36 -08:00
call EnemyTriesToFlee
jr c, .quit
2015-11-06 06:04:27 -08:00
call DetermineMoveOrder
2015-11-08 10:27:26 -08:00
jr c, .false
2015-11-08 16:09:36 -08:00
call Battle_EnemyFirst
2015-11-08 10:27:26 -08:00
jr .proceed
.false
2015-11-08 16:09:36 -08:00
call Battle_PlayerFirst
2015-11-08 10:27:26 -08:00
.proceed
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
jr c, .quit
2015-11-08 16:09:36 -08:00
ld a, [wForcedSwitch]
and a
jr nz, .quit
2018-01-23 14:39:09 -08:00
ld a, [wBattleEnded]
and a
jr nz, .quit
2015-11-08 10:27:26 -08:00
call HandleBetweenTurnEffects
2018-01-23 14:39:09 -08:00
ld a, [wBattleEnded]
and a
jr nz, .quit
jp .loop
.quit
ret
; 3c1bf
Stubbed_Function3c1bf:
ret
ld a, 5 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
2018-01-08 19:48:58 -08:00
ld hl, $a89b ; address of MBC30 bank
inc [hl]
2015-11-08 10:27:26 -08:00
jr nz, .finish
dec hl
inc [hl]
2015-11-08 10:27:26 -08:00
jr nz, .finish
dec [hl]
inc hl
dec [hl]
2015-11-08 10:27:26 -08:00
.finish
call CloseSRAM
ret
; 3c1d6
2015-11-08 10:27:26 -08:00
HandleBetweenTurnEffects: ; 3c1d6
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-10-19 13:49:29 -07:00
jr z, .CheckEnemyFirst
call CheckFaint_PlayerThenEnemy
ret c
2015-11-08 10:27:26 -08:00
call HandleFutureSight
2015-10-19 13:49:29 -07:00
call CheckFaint_PlayerThenEnemy
ret c
call HandleWeather
2015-10-19 13:49:29 -07:00
call CheckFaint_PlayerThenEnemy
ret c
2015-11-08 10:27:26 -08:00
call HandleWrap
2015-10-19 13:49:29 -07:00
call CheckFaint_PlayerThenEnemy
ret c
2015-11-08 10:27:26 -08:00
call HandlePerishSong
2015-10-19 13:49:29 -07:00
call CheckFaint_PlayerThenEnemy
ret c
2015-10-19 13:49:29 -07:00
jr .NoMoreFaintingConditions
.CheckEnemyFirst:
2015-10-19 13:49:29 -07:00
call CheckFaint_EnemyThenPlayer
ret c
2015-11-08 10:27:26 -08:00
call HandleFutureSight
2015-10-19 13:49:29 -07:00
call CheckFaint_EnemyThenPlayer
ret c
call HandleWeather
2015-10-19 13:49:29 -07:00
call CheckFaint_EnemyThenPlayer
ret c
2015-11-08 10:27:26 -08:00
call HandleWrap
2015-10-19 13:49:29 -07:00
call CheckFaint_EnemyThenPlayer
ret c
2015-11-08 10:27:26 -08:00
call HandlePerishSong
2015-10-19 13:49:29 -07:00
call CheckFaint_EnemyThenPlayer
ret c
.NoMoreFaintingConditions:
2015-11-08 10:27:26 -08:00
call HandleLeftovers
call HandleMysteryberry
2018-04-05 02:41:06 -07:00
call HandleDefrost
call HandleSafeguard
call HandleScreens
2015-11-08 10:27:26 -08:00
call HandleStatBoostingHeldItems
call HandleHealingItems
call UpdateBattleMonInParty
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-11-23 13:04:53 -08:00
jp HandleEncore
; 3c23c
2015-10-19 13:49:29 -07:00
CheckFaint_PlayerThenEnemy: ; 3c23c
call HasPlayerFainted
2015-10-19 13:49:29 -07:00
jr nz, .PlayerNotFainted
call HandlePlayerMonFaint
2018-01-23 14:39:09 -08:00
ld a, [wBattleEnded]
and a
2015-10-19 13:49:29 -07:00
jr nz, .BattleIsOver
.PlayerNotFainted:
call HasEnemyFainted
2015-10-19 13:49:29 -07:00
jr nz, .BattleContinues
call HandleEnemyMonFaint
2018-01-23 14:39:09 -08:00
ld a, [wBattleEnded]
and a
2015-10-19 13:49:29 -07:00
jr nz, .BattleIsOver
.BattleContinues:
and a
ret
.BattleIsOver:
scf
ret
; 3c25c
2015-10-19 13:49:29 -07:00
CheckFaint_EnemyThenPlayer: ; 3c25c
call HasEnemyFainted
2015-10-19 13:49:29 -07:00
jr nz, .EnemyNotFainted
call HandleEnemyMonFaint
2018-01-23 14:39:09 -08:00
ld a, [wBattleEnded]
and a
2015-10-19 13:49:29 -07:00
jr nz, .BattleIsOver
.EnemyNotFainted:
call HasPlayerFainted
2015-10-19 13:49:29 -07:00
jr nz, .BattleContinues
call HandlePlayerMonFaint
2018-01-23 14:39:09 -08:00
ld a, [wBattleEnded]
and a
2015-10-19 13:49:29 -07:00
jr nz, .BattleIsOver
.BattleContinues:
and a
ret
.BattleIsOver:
scf
ret
; 3c27c
2015-11-08 16:09:36 -08:00
HandleBerserkGene: ; 3c27c
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .reverse
call .player
jr .enemy
.reverse
call .enemy
; jr .player
.player
call SetPlayerTurn
2018-01-23 14:39:09 -08:00
ld de, wPartyMon1Item
ld a, [wCurBattleMon]
ld b, a
jr .go
.enemy
call SetEnemyTurn
2018-01-23 14:39:09 -08:00
ld de, wOTPartyMon1Item
ld a, [wCurOTMon]
ld b, a
; jr .go
.go
push de
push bc
2017-12-24 09:47:30 -08:00
callfar GetUserItem
ld a, [hl]
ld [wd265], a
sub BERSERK_GENE
pop bc
pop de
ret nz
ld [hl], a
ld h, d
ld l, e
ld a, b
call GetPartyLocation
xor a
ld [hl], a
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVarAddr
push af
set SUBSTATUS_CONFUSED, [hl]
ld a, BATTLE_VARS_MOVE_ANIM
call GetBattleVarAddr
push hl
push af
xor a
ld [hl], a
2018-01-23 14:39:09 -08:00
ld [wAttackMissed], a
ld [wEffectFailed], a
2017-12-24 09:47:30 -08:00
farcall BattleCommand_AttackUp2
pop af
pop hl
ld [hl], a
call GetItemName
2015-09-09 16:27:07 -07:00
ld hl, BattleText_UsersStringBuffer1Activated
call StdBattleTextBox
2017-12-24 09:47:30 -08:00
callfar BattleCommand_StatUpMessage
pop af
bit SUBSTATUS_CONFUSED, a
ret nz
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
ld de, ANIM_CONFUSED
2015-11-07 18:04:54 -08:00
call Call_PlayBattleAnim_OnlyIfVisible
call SwitchTurnCore
2014-01-05 04:28:55 -08:00
ld hl, BecameConfusedText
jp StdBattleTextBox
; 3c300
2015-11-08 16:09:36 -08:00
EnemyTriesToFlee: ; 3c300
ld a, [wLinkMode]
and a
2015-11-06 06:04:27 -08:00
jr z, .not_linked
ld a, [wBattleAction]
2015-11-06 06:04:27 -08:00
cp BATTLEACTION_FORFEIT
jr z, .forfeit
2015-11-06 06:04:27 -08:00
.not_linked
and a
ret
2015-11-06 06:04:27 -08:00
.forfeit
call WildFled_EnemyFled_LinkBattleCanceled
scf
ret
; 3c314
2015-11-06 06:04:27 -08:00
DetermineMoveOrder: ; 3c314
ld a, [wLinkMode]
and a
2015-11-06 06:04:27 -08:00
jr z, .use_move
ld a, [wBattleAction]
2015-11-06 06:04:27 -08:00
cp BATTLEACTION_E
jr z, .use_move
cp BATTLEACTION_D
jr z, .use_move
sub BATTLEACTION_SWITCH1
jr c, .use_move
ld a, [wBattlePlayerAction]
cp $2
2015-11-05 16:13:09 -08:00
jr nz, .switch
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
2015-11-06 06:04:27 -08:00
jr z, .player_2
2015-11-05 16:13:09 -08:00
call BattleRandom
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
2015-11-06 06:04:27 -08:00
jp c, .player_first
jp .enemy_first
2015-11-06 06:04:27 -08:00
.player_2
call BattleRandom
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
2015-11-06 06:04:27 -08:00
jp c, .enemy_first
jp .player_first
2015-11-05 16:13:09 -08:00
.switch
2017-12-24 09:47:30 -08:00
callfar AI_Switch
call SetEnemyTurn
call SpikesDamage
2015-11-06 06:04:27 -08:00
jp .enemy_first
2015-11-06 06:04:27 -08:00
.use_move
ld a, [wBattlePlayerAction]
and a
2015-11-06 06:04:27 -08:00
jp nz, .player_first
2013-12-30 20:32:37 -08:00
call CompareMovePriority
2015-11-06 06:04:27 -08:00
jr z, .equal_priority
jp c, .player_first ; player goes first
jp .enemy_first
2015-11-06 06:04:27 -08:00
.equal_priority
call SetPlayerTurn
2017-12-24 09:47:30 -08:00
callfar GetUserItem
push bc
2017-12-24 09:47:30 -08:00
callfar GetOpponentItem
pop de
ld a, d
cp HELD_QUICK_CLAW
2015-11-06 06:04:27 -08:00
jr nz, .player_no_quick_claw
ld a, b
cp HELD_QUICK_CLAW
2015-11-06 06:04:27 -08:00
jr z, .both_have_quick_claw
call BattleRandom
cp e
2015-11-06 06:04:27 -08:00
jr nc, .speed_check
jp .player_first
2015-11-06 06:04:27 -08:00
.player_no_quick_claw
ld a, b
cp HELD_QUICK_CLAW
2015-11-06 06:04:27 -08:00
jr nz, .speed_check
call BattleRandom
cp c
2015-11-06 06:04:27 -08:00
jr nc, .speed_check
jp .enemy_first
2015-11-06 06:04:27 -08:00
.both_have_quick_claw
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
2015-11-06 06:04:27 -08:00
jr z, .player_2b
call BattleRandom
cp c
2015-11-06 06:04:27 -08:00
jp c, .enemy_first
call BattleRandom
cp e
2015-11-06 06:04:27 -08:00
jp c, .player_first
jr .speed_check
2015-11-06 06:04:27 -08:00
.player_2b
call BattleRandom
cp e
2015-11-06 06:04:27 -08:00
jp c, .player_first
call BattleRandom
cp c
2015-11-06 06:04:27 -08:00
jp c, .enemy_first
jr .speed_check
2015-11-06 06:04:27 -08:00
.speed_check
2018-01-23 14:39:09 -08:00
ld de, wBattleMonSpeed
ld hl, wEnemyMonSpeed
2015-11-06 06:04:27 -08:00
ld c, 2
call StringCmp
2015-11-06 06:04:27 -08:00
jr z, .speed_tie
jp nc, .player_first
jp .enemy_first
2015-11-06 06:04:27 -08:00
.speed_tie
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
2015-11-06 06:04:27 -08:00
jr z, .player_2c
call BattleRandom
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
2015-11-06 06:04:27 -08:00
jp c, .player_first
jp .enemy_first
2015-11-06 06:04:27 -08:00
.player_2c
call BattleRandom
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
2015-11-06 06:04:27 -08:00
jp c, .enemy_first
.player_first
scf
ret
; 3c3f3
.enemy_first ; 3c3f3
and a
ret
; 3c3f5
2015-11-08 10:27:26 -08:00
CheckContestBattleOver: ; 3c3f5
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_CONTEST
2015-11-08 10:27:26 -08:00
jr nz, .contest_not_over
ld a, [wParkBallsRemaining]
and a
2015-11-08 10:27:26 -08:00
jr nz, .contest_not_over
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
and BATTLERESULT_BITMASK
add DRAW
2015-10-24 07:34:19 -07:00
ld [wBattleResult], a
scf
ret
2015-11-08 10:27:26 -08:00
.contest_not_over
and a
ret
; 3c410
2015-11-08 16:09:36 -08:00
CheckPlayerLockedIn: ; 3c410
2018-01-23 14:39:09 -08:00
ld a, [wPlayerSubStatus4]
and 1 << SUBSTATUS_RECHARGE
jp nz, .quit
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus3
res SUBSTATUS_FLINCHED, [hl]
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus3
res SUBSTATUS_FLINCHED, [hl]
ld a, [hl]
and 1 << SUBSTATUS_CHARGED | 1 << SUBSTATUS_RAMPAGE
jp nz, .quit
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus1
bit SUBSTATUS_ROLLOUT, [hl]
jp nz, .quit
and a
ret
.quit
scf
ret
; 3c434
2015-11-08 16:09:36 -08:00
ParsePlayerAction: ; 3c434
call CheckPlayerLockedIn
jp c, .locked_in
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus5
bit SUBSTATUS_ENCORED, [hl]
2015-11-08 16:09:36 -08:00
jr z, .not_encored
2018-01-23 14:39:09 -08:00
ld a, [wLastPlayerMove]
ld [wCurPlayerMove], a
2015-11-08 16:09:36 -08:00
jr .encored
2015-11-08 16:09:36 -08:00
.not_encored
ld a, [wBattlePlayerAction]
cp $2
2015-11-08 16:09:36 -08:00
jr z, .reset_rage
and a
2015-11-08 16:09:36 -08:00
jr nz, .reset_bide
2018-01-23 14:39:09 -08:00
ld a, [wPlayerSubStatus3]
and 1 << SUBSTATUS_BIDE
2015-11-08 16:09:36 -08:00
jr nz, .locked_in
xor a
2015-11-23 13:04:53 -08:00
ld [wMoveSelectionMenuType], a
inc a ; POUND
2018-01-23 14:39:09 -08:00
ld [wFXAnimID], a
2015-10-10 04:45:39 -07:00
call MoveSelectionScreen
push af
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
call UpdateBattleHuds
2018-01-23 14:39:09 -08:00
ld a, [wCurPlayerMove]
cp STRUGGLE
2015-11-08 16:09:36 -08:00
jr z, .struggle
call PlayClickSFX
2015-11-08 16:09:36 -08:00
.struggle
ld a, $1
ld [hBGMapMode], a
pop af
ret nz
2015-11-08 16:09:36 -08:00
.encored
call SetPlayerTurn
2017-12-24 09:47:30 -08:00
callfar UpdateMoveData
xor a
2015-11-07 18:04:54 -08:00
ld [wPlayerCharging], a
ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_FURY_CUTTER
2015-11-08 16:09:36 -08:00
jr z, .continue_fury_cutter
xor a
2018-01-23 14:39:09 -08:00
ld [wPlayerFuryCutterCount], a
2015-11-08 16:09:36 -08:00
.continue_fury_cutter
ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_RAGE
2015-11-08 16:09:36 -08:00
jr z, .continue_rage
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus4
res SUBSTATUS_RAGE, [hl]
xor a
2015-11-05 16:13:09 -08:00
ld [wPlayerRageCounter], a
2015-11-08 16:09:36 -08:00
.continue_rage
ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_PROTECT
2015-11-08 16:09:36 -08:00
jr z, .continue_protect
cp EFFECT_ENDURE
2015-11-08 16:09:36 -08:00
jr z, .continue_protect
xor a
2018-01-23 14:39:09 -08:00
ld [wPlayerProtectCount], a
2015-11-08 16:09:36 -08:00
jr .continue_protect
2015-11-08 16:09:36 -08:00
.reset_bide
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus3
res SUBSTATUS_BIDE, [hl]
2015-11-08 16:09:36 -08:00
.locked_in
xor a
2018-01-23 14:39:09 -08:00
ld [wPlayerFuryCutterCount], a
ld [wPlayerProtectCount], a
2015-11-05 16:13:09 -08:00
ld [wPlayerRageCounter], a
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus4
res SUBSTATUS_RAGE, [hl]
2015-11-08 16:09:36 -08:00
.continue_protect
call ParseEnemyAction
xor a
ret
2015-11-08 16:09:36 -08:00
.reset_rage
xor a
2018-01-23 14:39:09 -08:00
ld [wPlayerFuryCutterCount], a
ld [wPlayerProtectCount], a
2015-11-05 16:13:09 -08:00
ld [wPlayerRageCounter], a
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus4
res SUBSTATUS_RAGE, [hl]
xor a
ret
; 3c4df
2015-11-23 13:04:53 -08:00
HandleEncore: ; 3c4df
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-23 13:04:53 -08:00
jr z, .player_1
call .do_player
jr .do_enemy
2015-11-23 13:04:53 -08:00
.player_1
call .do_enemy
.do_player
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus5
bit SUBSTATUS_ENCORED, [hl]
ret z
2018-01-23 14:39:09 -08:00
ld a, [wPlayerEncoreCount]
dec a
2018-01-23 14:39:09 -08:00
ld [wPlayerEncoreCount], a
2015-11-23 13:04:53 -08:00
jr z, .end_player_encore
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonPP
ld a, [wCurMoveNum]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
2018-01-11 09:00:01 -08:00
and PP_MASK
ret nz
2015-11-23 13:04:53 -08:00
.end_player_encore
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus5
res SUBSTATUS_ENCORED, [hl]
call SetEnemyTurn
2015-09-09 16:27:07 -07:00
ld hl, BattleText_TargetsEncoreEnded
jp StdBattleTextBox
2015-11-23 13:04:53 -08:00
.do_enemy
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus5
bit SUBSTATUS_ENCORED, [hl]
ret z
2018-01-23 14:39:09 -08:00
ld a, [wEnemyEncoreCount]
dec a
2018-01-23 14:39:09 -08:00
ld [wEnemyEncoreCount], a
2015-11-23 13:04:53 -08:00
jr z, .end_enemy_encore
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonPP
ld a, [wCurEnemyMoveNum]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
2018-01-11 09:00:01 -08:00
and PP_MASK
ret nz
2015-11-23 13:04:53 -08:00
.end_enemy_encore
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus5
res SUBSTATUS_ENCORED, [hl]
call SetPlayerTurn
2015-09-09 16:27:07 -07:00
ld hl, BattleText_TargetsEncoreEnded
jp StdBattleTextBox
; 3c543
2015-11-07 18:04:54 -08:00
TryEnemyFlee: ; 3c543
ld a, [wBattleMode]
dec a
jr nz, .Stay
2018-01-23 14:39:09 -08:00
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_CANT_RUN, a
jr nz, .Stay
2015-11-08 10:27:26 -08:00
ld a, [wEnemyWrapCount]
and a
jr nz, .Stay
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonStatus]
and 1 << FRZ | SLP
jr nz, .Stay
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld de, 1
2013-12-24 14:19:39 -08:00
ld hl, AlwaysFleeMons
call IsInArray
jr c, .Flee
call BattleRandom
ld b, a
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
jr nc, .Stay
push bc
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld de, 1
2013-12-24 14:19:39 -08:00
ld hl, OftenFleeMons
call IsInArray
pop bc
jr c, .Flee
ld a, b
2018-02-04 18:21:34 -08:00
cp 10 percent + 1
jr nc, .Stay
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld de, 1
2013-12-24 14:19:39 -08:00
ld hl, SometimesFleeMons
call IsInArray
jr c, .Flee
.Stay:
and a
ret
.Flee:
scf
ret
; 3c59a
INCLUDE "data/wild/flee_mons.asm"
2013-12-30 20:32:37 -08:00
CompareMovePriority: ; 3c5b4
; Compare the priority of the player and enemy's moves.
; Return carry if the player goes first, or z if they match.
2018-01-23 14:39:09 -08:00
ld a, [wCurPlayerMove]
call GetMovePriority
ld b, a
push bc
2018-01-23 14:39:09 -08:00
ld a, [wCurEnemyMove]
call GetMovePriority
pop bc
cp b
ret
; 3c5c5
GetMovePriority: ; 3c5c5
2013-12-30 20:32:37 -08:00
; Return the priority (0-3) of move a.
ld b, a
2013-12-30 20:32:37 -08:00
; Vital Throw goes last.
cp VITAL_THROW
ld a, 0
ret z
2013-12-30 20:32:37 -08:00
call GetMoveEffect
ld hl, MoveEffectPriorities
.loop
ld a, [hli]
cp b
2013-12-30 20:32:37 -08:00
jr z, .done
inc hl
2013-12-30 20:32:37 -08:00
cp -1
jr nz, .loop
2013-12-30 20:32:37 -08:00
2018-01-09 12:39:48 -08:00
ld a, BASE_PRIORITY
ret
2013-12-30 20:32:37 -08:00
.done
ld a, [hl]
ret
; 3c5df
INCLUDE "data/moves/effects_priorities.asm"
2013-12-30 20:32:37 -08:00
GetMoveEffect: ; 3c5ec
ld a, b
dec a
2013-12-30 20:22:27 -08:00
ld hl, Moves + MOVE_EFFECT
ld bc, MOVE_LENGTH
call AddNTimes
2013-12-30 20:22:27 -08:00
ld a, BANK(Moves)
call GetFarByte
ld b, a
ret
; 3c5fe
2015-11-08 16:09:36 -08:00
Battle_EnemyFirst: ; 3c5fe
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-11-07 18:04:54 -08:00
call TryEnemyFlee
jp c, WildFled_EnemyFled_LinkBattleCanceled
call SetEnemyTurn
ld a, $1
2015-11-08 16:09:36 -08:00
ld [wEnemyGoesFirst], a
2017-12-24 09:47:30 -08:00
callfar AI_SwitchOrTryItem
2015-11-07 18:04:54 -08:00
jr c, .switch_item
call EnemyTurn_EndOpponentProtectEndureDestinyBond
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
ret c
2015-11-08 16:09:36 -08:00
ld a, [wForcedSwitch]
and a
ret nz
call HasPlayerFainted
2015-10-19 13:49:29 -07:00
jp z, HandlePlayerMonFaint
call HasEnemyFainted
2015-10-19 13:49:29 -07:00
jp z, HandleEnemyMonFaint
2015-11-07 18:04:54 -08:00
.switch_item
call SetEnemyTurn
call ResidualDamage
2015-10-19 13:49:29 -07:00
jp z, HandleEnemyMonFaint
call RefreshBattleHuds
2015-11-07 18:04:54 -08:00
call PlayerTurn_EndOpponentProtectEndureDestinyBond
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
ret c
2015-11-08 16:09:36 -08:00
ld a, [wForcedSwitch]
and a
ret nz
call HasEnemyFainted
2015-10-19 13:49:29 -07:00
jp z, HandleEnemyMonFaint
call HasPlayerFainted
2015-10-19 13:49:29 -07:00
jp z, HandlePlayerMonFaint
call SetPlayerTurn
call ResidualDamage
2015-10-19 13:49:29 -07:00
jp z, HandlePlayerMonFaint
call RefreshBattleHuds
xor a
ld [wBattlePlayerAction], a
ret
; 3c664
2015-11-08 16:09:36 -08:00
Battle_PlayerFirst: ; 3c664
xor a
2015-11-08 16:09:36 -08:00
ld [wEnemyGoesFirst], a
call SetEnemyTurn
2017-12-24 09:47:30 -08:00
callfar AI_SwitchOrTryItem
push af
2015-11-07 18:04:54 -08:00
call PlayerTurn_EndOpponentProtectEndureDestinyBond
pop bc
2015-11-08 16:09:36 -08:00
ld a, [wForcedSwitch]
and a
ret nz
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
ret c
call HasEnemyFainted
2015-10-19 13:49:29 -07:00
jp z, HandleEnemyMonFaint
call HasPlayerFainted
2015-10-19 13:49:29 -07:00
jp z, HandlePlayerMonFaint
push bc
call SetPlayerTurn
call ResidualDamage
pop bc
2015-10-19 13:49:29 -07:00
jp z, HandlePlayerMonFaint
push bc
call RefreshBattleHuds
pop af
2015-11-07 18:04:54 -08:00
jr c, .switched_or_used_item
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-11-07 18:04:54 -08:00
call TryEnemyFlee
jp c, WildFled_EnemyFled_LinkBattleCanceled
2015-11-07 18:04:54 -08:00
call EnemyTurn_EndOpponentProtectEndureDestinyBond
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
ret c
2015-11-08 16:09:36 -08:00
ld a, [wForcedSwitch]
and a
ret nz
call HasPlayerFainted
2015-10-19 13:49:29 -07:00
jp z, HandlePlayerMonFaint
call HasEnemyFainted
2015-10-19 13:49:29 -07:00
jp z, HandleEnemyMonFaint
2015-11-07 18:04:54 -08:00
.switched_or_used_item
call SetEnemyTurn
call ResidualDamage
2015-10-19 13:49:29 -07:00
jp z, HandleEnemyMonFaint
call RefreshBattleHuds
xor a
ld [wBattlePlayerAction], a
ret
; 3c6cf
2015-11-07 18:04:54 -08:00
PlayerTurn_EndOpponentProtectEndureDestinyBond: ; 3c6cf
call SetPlayerTurn
2015-11-07 18:04:54 -08:00
call EndUserDestinyBond
2017-12-24 09:47:30 -08:00
callfar DoPlayerTurn
2015-11-07 18:04:54 -08:00
jp EndOpponentProtectEndureDestinyBond
; 3c6de
2015-11-07 18:04:54 -08:00
EnemyTurn_EndOpponentProtectEndureDestinyBond: ; 3c6de
call SetEnemyTurn
2015-11-07 18:04:54 -08:00
call EndUserDestinyBond
2017-12-24 09:47:30 -08:00
callfar DoEnemyTurn
2015-11-07 18:04:54 -08:00
jp EndOpponentProtectEndureDestinyBond
; 3c6ed
2015-11-07 18:04:54 -08:00
EndOpponentProtectEndureDestinyBond: ; 3c6ed
ld a, BATTLE_VARS_SUBSTATUS1_OPP
call GetBattleVarAddr
res SUBSTATUS_PROTECT, [hl]
res SUBSTATUS_ENDURE, [hl]
ld a, BATTLE_VARS_SUBSTATUS5_OPP
call GetBattleVarAddr
res SUBSTATUS_DESTINY_BOND, [hl]
ret
; 3c6fe
2015-11-07 18:04:54 -08:00
EndUserDestinyBond: ; 3c6fe
ld a, BATTLE_VARS_SUBSTATUS5
call GetBattleVarAddr
res SUBSTATUS_DESTINY_BOND, [hl]
ret
; 3c706
HasUserFainted: ; 3c706
ld a, [hBattleTurn]
and a
jr z, HasPlayerFainted
HasEnemyFainted: ; 3c70b
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
2015-09-09 16:27:07 -07:00
jr CheckIfHPIsZero
HasPlayerFainted: ; 3c710
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
2015-09-09 16:27:07 -07:00
CheckIfHPIsZero: ; 3c713
ld a, [hli]
or [hl]
ret
; 3c716
ResidualDamage: ; 3c716
; Return z if the user fainted before
; or as a result of residual damage.
; For Sandstorm damage, see HandleWeather.
call HasUserFainted
ret z
ld a, BATTLE_VARS_STATUS
call GetBattleVar
and 1 << PSN | 1 << BRN
jr z, .did_psn_brn
ld hl, HurtByPoisonText
ld de, ANIM_PSN
and 1 << BRN
jr z, .got_anim
ld hl, HurtByBurnText
ld de, ANIM_BRN
.got_anim
push de
call StdBattleTextBox
pop de
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
2015-11-07 18:04:54 -08:00
call Call_PlayBattleAnim_OnlyIfVisible
call GetEighthMaxHP
2018-01-23 14:39:09 -08:00
ld de, wPlayerToxicCount
ld a, [hBattleTurn]
and a
2015-11-07 18:04:54 -08:00
jr z, .check_toxic
2018-01-23 14:39:09 -08:00
ld de, wEnemyToxicCount
2015-11-07 18:04:54 -08:00
.check_toxic
ld a, BATTLE_VARS_SUBSTATUS5
call GetBattleVar
bit SUBSTATUS_TOXIC, a
jr z, .did_toxic
call GetSixteenthMaxHP
ld a, [de]
inc a
ld [de], a
ld hl, 0
.add
add hl, bc
dec a
jr nz, .add
ld b, h
ld c, l
.did_toxic
2015-11-06 17:55:16 -08:00
call SubtractHPFromUser
.did_psn_brn
call HasUserFainted
jp z, .fainted
ld a, BATTLE_VARS_SUBSTATUS4
call GetBattleVarAddr
bit SUBSTATUS_LEECH_SEED, [hl]
2015-11-07 18:04:54 -08:00
jr z, .not_seeded
call SwitchTurnCore
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
ld de, ANIM_SAP
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVar
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
2015-11-07 18:04:54 -08:00
call z, Call_PlayBattleAnim_OnlyIfVisible
call SwitchTurnCore
call GetEighthMaxHP
2015-11-06 17:55:16 -08:00
call SubtractHPFromUser
ld a, $1
ld [hBGMapMode], a
2015-11-06 19:36:06 -08:00
call RestoreHP
ld hl, LeechSeedSapsText
call StdBattleTextBox
2015-11-07 18:04:54 -08:00
.not_seeded
call HasUserFainted
jr z, .fainted
ld a, BATTLE_VARS_SUBSTATUS1
call GetBattleVarAddr
bit SUBSTATUS_NIGHTMARE, [hl]
2015-11-07 18:04:54 -08:00
jr z, .not_nightmare
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
ld de, ANIM_IN_NIGHTMARE
2015-11-07 18:04:54 -08:00
call Call_PlayBattleAnim_OnlyIfVisible
call GetQuarterMaxHP
2015-11-06 17:55:16 -08:00
call SubtractHPFromUser
ld hl, HasANightmareText
call StdBattleTextBox
2015-11-07 18:04:54 -08:00
.not_nightmare
call HasUserFainted
jr z, .fainted
ld a, BATTLE_VARS_SUBSTATUS1
call GetBattleVarAddr
bit SUBSTATUS_CURSE, [hl]
2015-11-07 18:04:54 -08:00
jr z, .not_cursed
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
ld de, ANIM_IN_NIGHTMARE
2015-11-07 18:04:54 -08:00
call Call_PlayBattleAnim_OnlyIfVisible
call GetQuarterMaxHP
2015-11-06 17:55:16 -08:00
call SubtractHPFromUser
ld hl, HurtByCurseText
call StdBattleTextBox
2015-11-07 18:04:54 -08:00
.not_cursed
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hBattleTurn]
and a
2015-11-07 18:04:54 -08:00
jr z, .check_fainted
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
2015-11-07 18:04:54 -08:00
.check_fainted
ld a, [hli]
or [hl]
ret nz
.fainted
call RefreshBattleHuds
ld c, 20
call DelayFrames
xor a
ret
; 3c801
2015-11-08 10:27:26 -08:00
HandlePerishSong: ; 3c801
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-08 10:27:26 -08:00
jr z, .EnemyFirst
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
jp .do_it
.EnemyFirst:
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
.do_it
2018-01-23 14:39:09 -08:00
ld hl, wPlayerPerishCount
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr z, .got_count
2018-01-23 14:39:09 -08:00
ld hl, wEnemyPerishCount
2015-11-08 10:27:26 -08:00
.got_count
ld a, BATTLE_VARS_SUBSTATUS1
call GetBattleVar
bit SUBSTATUS_PERISH, a
ret z
dec [hl]
ld a, [hl]
ld [wd265], a
push af
ld hl, PerishCountText
call StdBattleTextBox
pop af
ret nz
ld a, BATTLE_VARS_SUBSTATUS1
call GetBattleVarAddr
res SUBSTATUS_PERISH, [hl]
ld a, [hBattleTurn]
and a
2016-01-17 21:39:01 -08:00
jr nz, .kill_enemy
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
xor a
ld [hli], a
ld [hl], a
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1HP
ld a, [wCurBattleMon]
call GetPartyLocation
xor a
ld [hli], a
ld [hl], a
ret
2016-01-17 21:39:01 -08:00
.kill_enemy
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
xor a
ld [hli], a
ld [hl], a
ld a, [wBattleMode]
dec a
ret z
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1HP
ld a, [wCurOTMon]
call GetPartyLocation
xor a
ld [hli], a
ld [hl], a
ret
; 3c874
2015-11-08 10:27:26 -08:00
HandleWrap: ; 3c874
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-08 10:27:26 -08:00
jr z, .EnemyFirst
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
jp .do_it
.EnemyFirst:
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
.do_it
ld hl, wPlayerWrapCount
ld de, wPlayerTrappingMove
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr z, .got_addrs
ld hl, wEnemyWrapCount
ld de, wEnemyTrappingMove
2015-11-08 10:27:26 -08:00
.got_addrs
ld a, [hl]
and a
ret z
2015-11-08 10:27:26 -08:00
ld a, BATTLE_VARS_SUBSTATUS4
call GetBattleVar
bit SUBSTATUS_SUBSTITUTE, a
ret nz
2015-11-08 10:27:26 -08:00
ld a, [de]
ld [wd265], a
2018-01-23 14:39:09 -08:00
ld [wFXAnimID], a
call GetMoveName
dec [hl]
2015-11-08 10:27:26 -08:00
jr z, .release_from_bounds
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVar
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
2015-11-08 10:27:26 -08:00
jr nz, .skip_anim
call SwitchTurnCore
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
2018-01-23 14:39:09 -08:00
ld [wFXAnimID + 1], a
predef PlayBattleAnim
call SwitchTurnCore
2015-11-08 10:27:26 -08:00
.skip_anim
call GetSixteenthMaxHP
2015-11-06 17:55:16 -08:00
call SubtractHPFromUser
2015-09-09 16:27:07 -07:00
ld hl, BattleText_UsersHurtByStringBuffer1
2016-01-17 21:39:01 -08:00
jr .print_text
2015-11-08 10:27:26 -08:00
.release_from_bounds
2015-09-09 16:27:07 -07:00
ld hl, BattleText_UserWasReleasedFromStringBuffer1
2016-01-17 21:39:01 -08:00
.print_text
jp StdBattleTextBox
; 3c8e4
SwitchTurnCore: ; 3c8e4
ld a, [hBattleTurn]
xor 1
ld [hBattleTurn], a
ret
; 3c8eb
2015-11-08 10:27:26 -08:00
HandleLeftovers: ; 3c8eb
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-08 10:27:26 -08:00
jr z, .DoEnemyFirst
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
jp .do_it
.DoEnemyFirst:
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
.do_it
2017-12-24 09:47:30 -08:00
callfar GetUserItem
ld a, [hl]
ld [wd265], a
call GetItemName
ld a, b
cp HELD_LEFTOVERS
ret nz
2015-11-08 10:27:26 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr z, .got_hp
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
2015-11-08 10:27:26 -08:00
.got_hp
; Don't restore if we're already at max HP
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
ld a, [hli]
cp b
2015-11-08 10:27:26 -08:00
jr nz, .restore
ld a, [hl]
cp c
ret z
2015-11-08 10:27:26 -08:00
.restore
call GetSixteenthMaxHP
call SwitchTurnCore
2015-11-06 19:36:06 -08:00
call RestoreHP
2016-01-17 21:39:01 -08:00
ld hl, BattleText_TargetRecoveredWithItem
jp StdBattleTextBox
; 3c93c
2015-11-08 10:27:26 -08:00
HandleMysteryberry: ; 3c93c
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-08 10:27:26 -08:00
jr z, .DoEnemyFirst
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
jp .do_it
.DoEnemyFirst:
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
.do_it
2017-12-24 09:47:30 -08:00
callfar GetUserItem
ld a, b
cp HELD_RESTORE_PP
2015-11-08 10:27:26 -08:00
jr nz, .quit
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1PP
ld a, [wCurBattleMon]
call GetPartyLocation
ld d, h
ld e, l
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1Moves
ld a, [wCurBattleMon]
call GetPartyLocation
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr z, .wild
2015-11-29 18:34:59 -08:00
ld de, wWildMonPP
ld hl, wWildMonMoves
ld a, [wBattleMode]
dec a
2015-11-08 10:27:26 -08:00
jr z, .wild
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1PP
ld a, [wCurOTMon]
call GetPartyLocation
ld d, h
ld e, l
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1Moves
ld a, [wCurOTMon]
call GetPartyLocation
2015-11-08 10:27:26 -08:00
.wild
ld c, $0
2015-11-08 10:27:26 -08:00
.loop
ld a, [hl]
and a
2015-11-08 10:27:26 -08:00
jr z, .quit
ld a, [de]
2018-01-11 09:00:01 -08:00
and PP_MASK
2015-11-08 10:27:26 -08:00
jr z, .restore
inc hl
inc de
inc c
ld a, c
cp NUM_MOVES
2015-11-08 10:27:26 -08:00
jr nz, .loop
2015-11-08 10:27:26 -08:00
.quit
ret
2015-11-08 10:27:26 -08:00
.restore
; lousy hack
ld a, [hl]
cp SKETCH
ld b, 1
2015-11-08 10:27:26 -08:00
jr z, .sketch
ld b, 5
2015-11-08 10:27:26 -08:00
.sketch
ld a, [de]
add b
ld [de], a
push bc
push bc
ld a, [hl]
ld [wd265], a
2018-01-23 14:39:09 -08:00
ld de, wBattleMonMoves - 1
ld hl, wBattleMonPP
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr z, .player_pp
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonMoves - 1
ld hl, wEnemyMonPP
2015-11-08 10:27:26 -08:00
.player_pp
inc de
pop bc
ld b, 0
add hl, bc
push hl
ld h, d
ld l, e
add hl, bc
pop de
pop bc
ld a, [wd265]
cp [hl]
2015-11-08 10:27:26 -08:00
jr nz, .skip_checks
ld a, [hBattleTurn]
and a
2018-01-23 14:39:09 -08:00
ld a, [wPlayerSubStatus5]
2015-11-08 10:27:26 -08:00
jr z, .check_transform
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus5]
2015-11-08 10:27:26 -08:00
.check_transform
bit SUBSTATUS_TRANSFORMED, a
2015-11-08 10:27:26 -08:00
jr nz, .skip_checks
ld a, [de]
add b
ld [de], a
2015-11-08 10:27:26 -08:00
.skip_checks
2017-12-24 09:47:30 -08:00
callfar GetUserItem
ld a, [hl]
ld [wd265], a
xor a
ld [hl], a
2015-11-08 10:27:26 -08:00
call GetPartymonItem
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr z, .consume_item
ld a, [wBattleMode]
dec a
2015-11-08 10:27:26 -08:00
jr z, .skip_consumption
call GetOTPartymonItem
2015-11-08 10:27:26 -08:00
.consume_item
xor a
ld [hl], a
2015-11-08 10:27:26 -08:00
.skip_consumption
call GetItemName
call SwitchTurnCore
2015-11-06 19:36:06 -08:00
call ItemRecoveryAnim
call SwitchTurnCore
ld hl, BattleText_UserRecoveredPPUsing
jp StdBattleTextBox
; 3ca26
2015-11-08 10:27:26 -08:00
HandleFutureSight: ; 3ca26
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-08 10:27:26 -08:00
jr z, .enemy_first
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
jp .do_it
2015-11-08 10:27:26 -08:00
.enemy_first
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
call .do_it
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
.do_it
ld hl, wPlayerFutureSightCount
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr z, .okay
ld hl, wEnemyFutureSightCount
2015-11-08 10:27:26 -08:00
.okay
ld a, [hl]
and a
ret z
dec a
ld [hl], a
cp $1
ret nz
2016-01-17 21:39:01 -08:00
ld hl, BattleText_TargetWasHitByFutureSight
call StdBattleTextBox
ld a, BATTLE_VARS_MOVE
call GetBattleVarAddr
push af
ld a, FUTURE_SIGHT
ld [hl], a
2017-12-24 09:47:30 -08:00
callfar UpdateMoveData
xor a
2018-01-23 14:39:09 -08:00
ld [wAttackMissed], a
ld [wAlreadyDisobeyed], a
2018-03-09 13:09:03 -08:00
ld a, EFFECTIVE
2018-01-23 14:39:09 -08:00
ld [wTypeModifier], a
2017-12-24 09:47:30 -08:00
callfar DoMove
xor a
2018-01-23 14:39:09 -08:00
ld [wCurDamage], a
ld [wCurDamage + 1], a
ld a, BATTLE_VARS_MOVE
call GetBattleVarAddr
pop af
ld [hl], a
call UpdateBattleMonInParty
jp UpdateEnemyMonInParty
; 3ca8f
2018-04-05 02:41:06 -07:00
HandleDefrost: ; 3ca8f
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .enemy_first
call .do_player_turn
jr .do_enemy_turn
.enemy_first
call .do_enemy_turn
.do_player_turn
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonStatus]
bit FRZ, a
ret z
ld a, [wPlayerJustGotFrozen]
and a
ret nz
call BattleRandom
cp 10 percent
ret nc
xor a
2018-01-23 14:39:09 -08:00
ld [wBattleMonStatus], a
ld a, [wCurBattleMon]
ld hl, wPartyMon1Status
call GetPartyLocation
ld [hl], 0
call UpdateBattleHuds
call SetEnemyTurn
2014-01-05 04:28:55 -08:00
ld hl, DefrostedOpponentText
jp StdBattleTextBox
.do_enemy_turn
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonStatus]
bit FRZ, a
ret z
ld a, [wEnemyJustGotFrozen]
and a
ret nz
call BattleRandom
cp 10 percent
ret nc
xor a
2018-01-23 14:39:09 -08:00
ld [wEnemyMonStatus], a
ld a, [wBattleMode]
dec a
2016-01-17 21:39:01 -08:00
jr z, .wild
2018-01-23 14:39:09 -08:00
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Status
call GetPartyLocation
ld [hl], 0
2016-01-17 21:39:01 -08:00
.wild
call UpdateBattleHuds
call SetPlayerTurn
2014-01-05 04:28:55 -08:00
ld hl, DefrostedOpponentText
jp StdBattleTextBox
; 3cafb
HandleSafeguard: ; 3cafb
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2016-01-17 21:39:01 -08:00
jr z, .player1
call .CheckPlayer
jr .CheckEnemy
2016-01-17 21:39:01 -08:00
.player1
call .CheckEnemy
.CheckPlayer:
2018-01-23 14:39:09 -08:00
ld a, [wPlayerScreens]
bit SCREENS_SAFEGUARD, a
ret z
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSafeguardCount
dec [hl]
ret nz
res SCREENS_SAFEGUARD, a
2018-01-23 14:39:09 -08:00
ld [wPlayerScreens], a
xor a
2016-01-17 21:39:01 -08:00
jr .print
.CheckEnemy:
2018-01-23 14:39:09 -08:00
ld a, [wEnemyScreens]
bit SCREENS_SAFEGUARD, a
ret z
2018-01-23 14:39:09 -08:00
ld hl, wEnemySafeguardCount
dec [hl]
ret nz
res SCREENS_SAFEGUARD, a
2018-01-23 14:39:09 -08:00
ld [wEnemyScreens], a
ld a, $1
2016-01-17 21:39:01 -08:00
.print
ld [hBattleTurn], a
ld hl, BattleText_SafeguardFaded
jp StdBattleTextBox
HandleScreens: ; 3cb36
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .Both
call .CheckPlayer
jr .CheckEnemy
.Both:
call .CheckEnemy
.CheckPlayer:
call SetPlayerTurn
ld de, .Your
call .Copy
2018-01-23 14:39:09 -08:00
ld hl, wPlayerScreens
ld de, wPlayerLightScreenCount
2016-01-17 21:39:01 -08:00
jr .TickScreens
.CheckEnemy:
call SetEnemyTurn
ld de, .Enemy
call .Copy
2018-01-23 14:39:09 -08:00
ld hl, wEnemyScreens
ld de, wEnemyLightScreenCount
.TickScreens:
bit SCREENS_LIGHT_SCREEN, [hl]
2016-01-17 21:39:01 -08:00
call nz, .LightScreenTick
bit SCREENS_REFLECT, [hl]
2016-01-17 21:39:01 -08:00
call nz, .ReflectTick
ret
.Copy:
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
jp CopyName2
; 3cb75
.Your:
db "Your@"
.Enemy:
db "Enemy@"
; 3cb80
2016-01-17 21:39:01 -08:00
.LightScreenTick: ; 3cb80
ld a, [de]
dec a
ld [de], a
ret nz
res SCREENS_LIGHT_SCREEN, [hl]
push hl
push de
ld hl, BattleText_MonsLightScreenFell
call StdBattleTextBox
pop de
pop hl
ret
; 3cb91
2016-01-17 21:39:01 -08:00
.ReflectTick: ; 3cb91
inc de
ld a, [de]
dec a
ld [de], a
ret nz
res SCREENS_REFLECT, [hl]
ld hl, BattleText_MonsReflectFaded
jp StdBattleTextBox
; 3cb9e
HandleWeather: ; 3cb9e
ld a, [wBattleWeather]
cp WEATHER_NONE
ret z
2018-01-23 14:39:09 -08:00
ld hl, wWeatherCount
dec [hl]
jr z, .ended
ld hl, .WeatherMessages
call .PrintWeatherMessage
ld a, [wBattleWeather]
cp WEATHER_SANDSTORM
ret nz
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .enemy_first
.player_first
call SetPlayerTurn
call .SandstormDamage
call SetEnemyTurn
jr .SandstormDamage
.enemy_first
call SetEnemyTurn
call .SandstormDamage
call SetPlayerTurn
.SandstormDamage:
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVar
bit SUBSTATUS_UNDERGROUND, a
ret nz
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonType1
ld a, [hBattleTurn]
and a
jr z, .ok
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonType1
.ok
ld a, [hli]
cp ROCK
ret z
cp GROUND
ret z
cp STEEL
ret z
ld a, [hl]
cp ROCK
ret z
cp GROUND
ret z
cp STEEL
ret z
call SwitchTurnCore
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
ld de, ANIM_IN_SANDSTORM
2015-09-09 16:27:07 -07:00
call Call_PlayBattleAnim
call SwitchTurnCore
call GetEighthMaxHP
2015-11-06 17:55:16 -08:00
call SubtractHPFromUser
ld hl, SandstormHitsText
jp StdBattleTextBox
.ended
ld hl, .WeatherEndedMessages
call .PrintWeatherMessage
xor a
ld [wBattleWeather], a
ret
.PrintWeatherMessage:
ld a, [wBattleWeather]
dec a
ld c, a
ld b, 0
add hl, bc
2015-12-26 18:59:03 -08:00
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp StdBattleTextBox
; 3cc2d
.WeatherMessages:
2018-01-25 18:34:42 -08:00
; entries correspond to WEATHER_* constants
dw BattleText_RainContinuesToFall
dw BattleText_TheSunlightIsStrong
dw BattleText_TheSandstormRages
2018-01-25 18:34:42 -08:00
.WeatherEndedMessages:
2018-01-25 18:34:42 -08:00
; entries correspond to WEATHER_* constants
dw BattleText_TheRainStopped
dw BattleText_TheSunlightFaded
dw BattleText_TheSandstormSubsided
; 3cc39
2015-11-06 17:55:16 -08:00
SubtractHPFromTarget: ; 3cc39
call SubtractHP
jp UpdateHPBar
; 3cc3f
2015-11-06 17:55:16 -08:00
SubtractHPFromUser: ; 3cc3f
; Subtract HP from mon
2015-11-06 17:55:16 -08:00
call SubtractHP
jp UpdateHPBarBattleHuds
; 3cc45
2015-11-06 17:55:16 -08:00
SubtractHP: ; 3cc45
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hBattleTurn]
and a
jr z, .ok
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
.ok
inc hl
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBuffer3], a
sub c
ld [hld], a
2018-01-23 14:39:09 -08:00
ld [wBuffer5], a
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBuffer4], a
sbc b
ld [hl], a
2018-01-23 14:39:09 -08:00
ld [wBuffer6], a
ret nc
2015-09-09 16:27:07 -07:00
2018-01-23 14:39:09 -08:00
ld a, [wBuffer3]
ld c, a
2018-01-23 14:39:09 -08:00
ld a, [wBuffer4]
ld b, a
xor a
ld [hli], a
ld [hl], a
2018-01-23 14:39:09 -08:00
ld [wBuffer5], a
ld [wBuffer6], a
ret
; 3cc76
GetSixteenthMaxHP: ; 3cc76
call GetQuarterMaxHP
; quarter result
srl c
srl c
; round up
ld a, c
and a
jr nz, .ok
inc c
.ok
ret
; 3cc83
GetEighthMaxHP: ; 3cc83
; output: bc
call GetQuarterMaxHP
; assumes nothing can have 1024 or more hp
; halve result
srl c
; round up
ld a, c
and a
jr nz, .end
inc c
.end
ret
; 3cc8e
GetQuarterMaxHP: ; 3cc8e
; output: bc
call GetMaxHP
; quarter result
srl b
rr c
srl b
rr c
; assumes nothing can have 1024 or more hp
; round up
ld a, c
and a
jr nz, .end
inc c
.end
ret
; 3cc9f
GetHalfMaxHP: ; 3cc9f
; output: bc
call GetMaxHP
; halve result
srl b
rr c
; floor = 1
ld a, c
or b
jr nz, .end
inc c
.end
ret
; 3ccac
GetMaxHP: ; 3ccac
2018-01-23 14:39:09 -08:00
; output: bc, wBuffer1-2
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonMaxHP
ld a, [hBattleTurn]
and a
jr z, .ok
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMaxHP
.ok
ld a, [hli]
2018-01-23 14:39:09 -08:00
ld [wBuffer2], a
ld b, a
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBuffer1], a
ld c, a
ret
; 3ccc2
2018-01-02 07:04:21 -08:00
Unreferenced_GetHalfHP: ; 3ccc2
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hBattleTurn]
and a
jr z, .ok
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
.ok
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
srl b
rr c
ld a, [hli]
2018-01-23 14:39:09 -08:00
ld [wBuffer2], a
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBuffer1], a
ret
; 3ccde
2015-11-09 13:41:09 -08:00
CheckUserHasEnoughHP: ; 3ccde
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP + 1
ld a, [hBattleTurn]
and a
jr z, .ok
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP + 1
.ok
ld a, c
sub [hl]
dec hl
ld a, b
sbc [hl]
ret
; 3ccef
2015-11-06 19:36:06 -08:00
RestoreHP ; 3ccef
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMaxHP
ld a, [hBattleTurn]
and a
jr z, .ok
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonMaxHP
.ok
ld a, [hli]
2018-01-23 14:39:09 -08:00
ld [wBuffer2], a
ld a, [hld]
2018-01-23 14:39:09 -08:00
ld [wBuffer1], a
dec hl
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBuffer3], a
add c
ld [hld], a
2018-01-23 14:39:09 -08:00
ld [wBuffer5], a
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBuffer4], a
adc b
ld [hli], a
2018-01-23 14:39:09 -08:00
ld [wBuffer6], a
2018-01-23 14:39:09 -08:00
ld a, [wBuffer1]
ld c, a
ld a, [hld]
sub c
2018-01-23 14:39:09 -08:00
ld a, [wBuffer2]
ld b, a
ld a, [hl]
sbc b
jr c, .asm_3cd2d
ld a, b
ld [hli], a
2018-01-23 14:39:09 -08:00
ld [wBuffer6], a
ld a, c
ld [hl], a
2018-01-23 14:39:09 -08:00
ld [wBuffer5], a
.asm_3cd2d
call SwitchTurnCore
call UpdateHPBarBattleHuds
jp SwitchTurnCore
; 3cd36
UpdateHPBarBattleHuds: ; 3cd36
call UpdateHPBar
jp UpdateBattleHuds
; 3cd3c
UpdateHPBar: ; 3cd3c
hlcoord 10, 9
ld a, [hBattleTurn]
and a
ld a, 1
jr z, .ok
hlcoord 2, 2
xor a
.ok
push bc
ld [wWhichHPBar], a
predef AnimateHPBar
pop bc
ret
; 3cd55
2015-10-19 13:49:29 -07:00
HandleEnemyMonFaint: ; 3cd55
call FaintEnemyPokemon
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
2015-10-19 13:49:29 -07:00
call z, FaintYourPokemon
xor a
2016-01-12 09:46:18 -08:00
ld [wWhichMonFaintedFirst], a
call UpdateBattleStateAndExperienceAfterEnemyFaint
call CheckPlayerPartyForFitMon
ld a, d
and a
jp z, LostBattle
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
call nz, UpdatePlayerHUD
ld a, $1
ld [hBGMapMode], a
ld c, 60
call DelayFrames
ld a, [wBattleMode]
dec a
2015-10-19 13:49:29 -07:00
jr nz, .trainer
ld a, 1
2018-01-23 14:39:09 -08:00
ld [wBattleEnded], a
ret
2015-10-19 13:49:29 -07:00
.trainer
call CheckEnemyTrainerDefeated
jp z, WinTrainerBattle
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
2015-11-10 16:51:13 -08:00
jr nz, .player_mon_not_fainted
2015-11-07 18:04:54 -08:00
call AskUseNextPokemon
jr nc, .dont_flee
ld a, 1
2018-01-23 14:39:09 -08:00
ld [wBattleEnded], a
ret
2015-11-07 18:04:54 -08:00
.dont_flee
2015-11-10 16:51:13 -08:00
call ForcePlayerMonChoice
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
jp c, WildFled_EnemyFled_LinkBattleCanceled
ld a, $1
ld [wBattlePlayerAction], a
2016-01-12 21:39:41 -08:00
call HandleEnemySwitch
jp z, WildFled_EnemyFled_LinkBattleCanceled
2015-11-23 13:04:53 -08:00
jr DoubleSwitch
2015-11-10 16:51:13 -08:00
.player_mon_not_fainted
ld a, $1
ld [wBattlePlayerAction], a
2016-01-12 21:39:41 -08:00
call HandleEnemySwitch
jp z, WildFled_EnemyFled_LinkBattleCanceled
xor a
ld [wBattlePlayerAction], a
ret
2013-12-31 01:09:00 -08:00
; 3cdca
2015-11-23 13:04:53 -08:00
DoubleSwitch: ; 3cdca
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-10 16:51:13 -08:00
jr z, .player_1
call ClearSprites
hlcoord 1, 0
lb bc, 4, 10
call ClearBox
2015-11-10 16:51:13 -08:00
call PlayerPartyMonEntrance
ld a, $1
call EnemyPartyMonEntrance
2015-11-10 16:51:13 -08:00
jr .done
2015-11-10 16:51:13 -08:00
.player_1
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
push af
ld a, $1
call EnemyPartyMonEntrance
call ClearSprites
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
pop af
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
2015-11-10 16:51:13 -08:00
call PlayerPartyMonEntrance
2015-11-10 16:51:13 -08:00
.done
xor a
ld [wBattlePlayerAction], a
ret
; 3ce01
2016-01-12 09:46:18 -08:00
UpdateBattleStateAndExperienceAfterEnemyFaint: ; 3ce01
call UpdateBattleMonInParty
ld a, [wBattleMode]
dec a
2015-11-10 16:51:13 -08:00
jr z, .wild
2018-01-23 14:39:09 -08:00
ld a, [wCurOTMon]
ld hl, wOTPartyMon1HP
call GetPartyLocation
xor a
ld [hli], a
ld [hl], a
2015-11-10 16:51:13 -08:00
.wild
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus3
res SUBSTATUS_IN_LOOP, [hl]
xor a
2018-01-23 14:39:09 -08:00
ld hl, wEnemyDamageTaken
ld [hli], a
ld [hl], a
call NewEnemyMonStatus
call BreakAttraction
ld a, [wBattleMode]
dec a
2015-11-10 16:51:13 -08:00
jr z, .wild2
jr .trainer
2015-11-10 16:51:13 -08:00
.wild2
2015-10-19 13:49:29 -07:00
call StopDangerSound
ld a, $1
ld [wBattleLowHealthAlarm], a
2015-11-10 16:51:13 -08:00
.trainer
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
2015-11-10 16:51:13 -08:00
jr nz, .player_mon_did_not_faint
2016-01-12 09:46:18 -08:00
ld a, [wWhichMonFaintedFirst]
and a
2015-11-10 16:51:13 -08:00
jr nz, .player_mon_did_not_faint
call PlayerMonFaintHappinessMod
2015-11-10 16:51:13 -08:00
.player_mon_did_not_faint
call CheckPlayerPartyForFitMon
ld a, d
and a
ret z
ld a, [wBattleMode]
dec a
2015-09-09 16:27:07 -07:00
call z, PlayVictoryMusic
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
and BATTLERESULT_BITMASK
ld [wBattleResult], a ; WIN
2016-01-12 09:46:18 -08:00
call IsAnyMonHoldingExpShare
2015-11-10 16:51:13 -08:00
jr z, .skip_exp
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonBaseStats
ld b, wEnemyMonEnd - wEnemyMonBaseStats
2015-11-10 16:51:13 -08:00
.loop
srl [hl]
inc hl
dec b
2015-11-10 16:51:13 -08:00
jr nz, .loop
2015-11-10 16:51:13 -08:00
.skip_exp
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonBaseStats
2016-01-12 09:46:18 -08:00
ld de, wBackupEnemyMonBaseStats
2018-01-23 14:39:09 -08:00
ld bc, wEnemyMonEnd - wEnemyMonBaseStats
call CopyBytes
xor a
2016-01-12 09:46:18 -08:00
ld [wGivingExperienceToExpShareHolders], a
2015-09-09 16:27:07 -07:00
call GiveExperiencePoints
2016-01-12 09:46:18 -08:00
call IsAnyMonHoldingExpShare
ret z
2015-11-07 18:04:54 -08:00
ld a, [wBattleParticipantsNotFainted]
push af
ld a, d
2015-11-07 18:04:54 -08:00
ld [wBattleParticipantsNotFainted], a
2016-01-12 09:46:18 -08:00
ld hl, wBackupEnemyMonBaseStats
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonBaseStats
ld bc, wEnemyMonEnd - wEnemyMonBaseStats
call CopyBytes
ld a, $1
2016-01-12 09:46:18 -08:00
ld [wGivingExperienceToExpShareHolders], a
2015-09-09 16:27:07 -07:00
call GiveExperiencePoints
pop af
2015-11-07 18:04:54 -08:00
ld [wBattleParticipantsNotFainted], a
ret
; 3ceaa
2016-01-12 09:46:18 -08:00
IsAnyMonHoldingExpShare: ; 3ceaa
2018-01-23 14:39:09 -08:00
ld a, [wPartyCount]
ld b, a
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1
ld c, 1
ld d, 0
2015-11-07 18:04:54 -08:00
.loop
push hl
push bc
ld bc, MON_HP
add hl, bc
ld a, [hli]
or [hl]
pop bc
pop hl
2015-11-07 18:04:54 -08:00
jr z, .next
push hl
push bc
ld bc, MON_ITEM
add hl, bc
pop bc
ld a, [hl]
pop hl
cp EXP_SHARE
2015-11-07 18:04:54 -08:00
jr nz, .next
ld a, d
or c
ld d, a
2015-11-07 18:04:54 -08:00
.next
sla c
push de
ld de, PARTYMON_STRUCT_LENGTH
add hl, de
pop de
dec b
2015-11-07 18:04:54 -08:00
jr nz, .loop
ld a, d
ld e, 0
ld b, PARTY_LENGTH
2015-11-07 18:04:54 -08:00
.loop2
srl a
2015-11-07 18:04:54 -08:00
jr nc, .okay
inc e
2015-11-07 18:04:54 -08:00
.okay
dec b
2015-11-07 18:04:54 -08:00
jr nz, .loop2
ld a, e
and a
ret
; 3ceec
2015-10-19 13:49:29 -07:00
StopDangerSound: ; 3ceec
xor a
ld [wLowHealthAlarm], a
ret
; 3cef1
2015-10-19 13:49:29 -07:00
FaintYourPokemon: ; 3cef1
call StopDangerSound
call WaitSFX
ld a, $f0
2018-01-23 14:39:09 -08:00
ld [wCryTracks], a
ld a, [wBattleMonSpecies]
2014-07-18 10:25:03 -07:00
call PlayStereoCry
2015-10-19 13:49:29 -07:00
call PlayerMonFaintedAnimation
hlcoord 9, 7
lb bc, 5, 11
call ClearBox
ld hl, BattleText_MonFainted
jp StdBattleTextBox
; 3cf14
2015-10-19 13:49:29 -07:00
FaintEnemyPokemon: ; 3cf14
call WaitSFX
ld de, SFX_KINESIS
call PlaySFX
2015-10-19 13:49:29 -07:00
call EnemyMonFaintedAnimation
ld de, SFX_FAINT
call PlaySFX
hlcoord 1, 0
lb bc, 4, 10
call ClearBox
ld hl, BattleText_EnemyMonFainted
jp StdBattleTextBox
; 3cf35
2015-10-19 13:49:29 -07:00
CheckEnemyTrainerDefeated: ; 3cf35
2018-01-23 14:39:09 -08:00
ld a, [wOTPartyCount]
ld b, a
xor a
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1HP
ld de, PARTYMON_STRUCT_LENGTH
2015-10-19 13:49:29 -07:00
.loop
or [hl]
inc hl
or [hl]
dec hl
add hl, de
dec b
2015-10-19 13:49:29 -07:00
jr nz, .loop
and a
ret
; 3cf4a
2016-01-12 21:39:41 -08:00
HandleEnemySwitch: ; 3cf4a
2018-01-23 14:39:09 -08:00
ld hl, wEnemyHPPal
ld e, HP_BAR_LENGTH_PX
2015-11-23 13:04:53 -08:00
call UpdateHPPal
call WaitBGMap
2017-12-24 09:47:30 -08:00
farcall EnemySwitch_TrainerHud
ld a, [wLinkMode]
and a
2015-11-06 06:04:27 -08:00
jr z, .not_linked
2015-09-09 16:27:07 -07:00
2015-11-23 13:04:53 -08:00
call LinkBattleSendReceiveAction
ld a, [wBattleAction]
2015-11-06 06:04:27 -08:00
cp BATTLEACTION_FORFEIT
ret z
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
2015-11-06 06:04:27 -08:00
.not_linked
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
ld a, $0
jr nz, EnemyPartyMonEntrance
inc a
ret
2013-12-31 01:09:00 -08:00
; 3cf78
EnemyPartyMonEntrance: ; 3cf78
push af
xor a
2015-11-08 16:09:36 -08:00
ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
pop af
and a
2016-01-12 21:39:41 -08:00
jr nz, .set
2015-11-07 18:04:54 -08:00
call EnemySwitch
2016-01-12 21:39:41 -08:00
jr .done_switch
2016-01-12 21:39:41 -08:00
.set
2015-11-07 18:04:54 -08:00
call EnemySwitch_SetMode
2016-01-12 21:39:41 -08:00
.done_switch
2015-11-07 18:04:54 -08:00
call ResetBattleParticipants
call SetEnemyTurn
call SpikesDamage
xor a
ld [wEnemyMoveStruct + MOVE_ANIM], a
ld [wBattlePlayerAction], a
inc a
ret
; 3cfa4
2015-10-19 13:49:29 -07:00
WinTrainerBattle: ; 3cfa4
2015-09-09 16:27:07 -07:00
; Player won the battle
2015-10-19 13:49:29 -07:00
call StopDangerSound
ld a, $1
ld [wBattleLowHealthAlarm], a
2018-01-23 14:39:09 -08:00
ld [wBattleEnded], a
ld a, [wLinkMode]
and a
ld a, b
2015-09-09 16:27:07 -07:00
call z, PlayVictoryMusic
2017-12-24 09:47:30 -08:00
callfar Battle_GetTrainerName
ld hl, BattleText_EnemyWasDefeated
call StdBattleTextBox
2015-09-09 16:27:07 -07:00
call IsMobileBattle
2015-11-03 19:35:36 -08:00
jr z, .mobile
ld a, [wLinkMode]
and a
ret nz
2018-01-23 14:39:09 -08:00
ld a, [wInBattleTowerBattle]
bit 0, a
2015-11-03 19:35:36 -08:00
jr nz, .battle_tower
call BattleWinSlideInEnemyTrainerFrontpic
ld c, 40
call DelayFrames
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_CANLOSE
2015-11-03 19:35:36 -08:00
jr nz, .skip_heal
predef HealParty
2015-11-03 19:35:36 -08:00
.skip_heal
ld a, [wMonStatusFlags]
bit 0, a
2015-11-04 12:35:29 -08:00
jr nz, .skip_win_loss_text
call PrintWinLossText
2015-11-04 12:35:29 -08:00
.skip_win_loss_text
2016-03-01 19:31:21 -08:00
jp .GiveMoney
2015-11-03 19:35:36 -08:00
.mobile
call BattleWinSlideInEnemyTrainerFrontpic
ld c, 40
call DelayFrames
ld c, $4 ; win
2017-12-24 09:47:30 -08:00
farcall Mobile_PrintOpponentBattleMessage
ret
2015-11-03 19:35:36 -08:00
.battle_tower
call BattleWinSlideInEnemyTrainerFrontpic
ld c, 40
call DelayFrames
call EmptyBattleTextBox
ld c, BATTLETOWERTEXT_LOSS_TEXT
2017-12-24 09:47:30 -08:00
farcall BattleTowerText
call WaitPressAorB_BlinkCursor
ld hl, wPayDayMoney
ld a, [hli]
or [hl]
inc hl
or [hl]
ret nz
call ClearTileMap
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
ret
.GiveMoney:
2015-11-22 21:21:21 -08:00
ld a, [wAmuletCoin]
and a
2015-11-22 21:21:21 -08:00
call nz, .DoubleReward
call .CheckMaxedOutMomMoney
push af
2018-01-22 10:57:44 -08:00
ld a, FALSE
2015-11-22 21:21:21 -08:00
jr nc, .okay
ld a, [wMomSavingMoney]
2018-01-22 10:57:44 -08:00
and MOM_SAVING_MONEY_MASK
cp (1 << MOM_SAVING_SOME_MONEY_F) | (1 << MOM_SAVING_HALF_MONEY_F)
2015-11-22 21:21:21 -08:00
jr nz, .okay
2018-01-22 10:57:44 -08:00
inc a ; TRUE
2015-11-22 21:21:21 -08:00
.okay
ld b, a
2018-01-22 10:57:44 -08:00
ld c, 4
2015-11-22 21:21:21 -08:00
.loop
ld a, b
and a
2015-11-22 21:21:21 -08:00
jr z, .loop2
2018-01-22 10:57:44 -08:00
call .AddMoneyToMom
dec c
dec b
2015-11-22 21:21:21 -08:00
jr .loop
2015-11-22 21:21:21 -08:00
.loop2
ld a, c
and a
2015-11-22 21:21:21 -08:00
jr z, .done
call .AddMoneyToWallet
dec c
2015-11-22 21:21:21 -08:00
jr .loop2
2015-11-22 21:21:21 -08:00
.done
call .DoubleReward
call .DoubleReward
pop af
2015-06-11 09:57:45 -07:00
jr nc, .KeepItAll
ld a, [wMomSavingMoney]
2018-01-22 10:57:44 -08:00
and MOM_SAVING_MONEY_MASK
2015-06-11 09:57:45 -07:00
jr z, .KeepItAll
2015-11-22 21:21:21 -08:00
ld hl, .SentToMomTexts
dec a
ld c, a
ld b, 0
add hl, bc
2015-12-26 18:59:03 -08:00
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp StdBattleTextBox
.KeepItAll:
2015-06-11 09:57:45 -07:00
ld hl, GotMoneyForWinningText
jp StdBattleTextBox
; 3d081
2018-01-22 10:57:44 -08:00
.AddMoneyToMom: ; 3d081
push bc
2015-11-22 21:21:21 -08:00
ld hl, wBattleReward + 2
ld de, wMomsMoney + 2
2015-11-22 21:21:21 -08:00
call AddBattleMoneyToAccount
pop bc
ret
; 3d08d
2015-11-22 21:21:21 -08:00
.AddMoneyToWallet: ; 3d08d
push bc
2015-11-22 21:21:21 -08:00
ld hl, wBattleReward + 2
2018-01-23 14:39:09 -08:00
ld de, wMoney + 2
2015-11-22 21:21:21 -08:00
call AddBattleMoneyToAccount
pop bc
ret
; 3d099
2015-11-22 21:21:21 -08:00
.DoubleReward: ; 3d099
ld hl, wBattleReward + 2
sla [hl]
dec hl
rl [hl]
dec hl
rl [hl]
ret nc
ld a, $ff
ld [hli], a
2015-12-26 18:59:03 -08:00
ld [hli], a
ld [hl], a
ret
; 3d0ab
2015-11-22 21:21:21 -08:00
.SentToMomTexts: ; 3d0ab
2018-01-25 18:34:42 -08:00
; entries correspond to MOM_SAVING_* constants
dw SentSomeToMomText
dw SentHalfToMomText
dw SentAllToMomText
; 3d0b1
2015-11-22 21:21:21 -08:00
.CheckMaxedOutMomMoney: ; 3d0b1
ld hl, wMomsMoney + 2
ld a, [hld]
cp LOW(MAX_MONEY)
ld a, [hld]
sbc HIGH(MAX_MONEY) ; mid
ld a, [hl]
sbc HIGH(MAX_MONEY >> 8)
ret
; 3d0be
2015-11-22 21:21:21 -08:00
AddBattleMoneyToAccount: ; 3d0be
2018-01-22 10:57:44 -08:00
ld c, 3
and a
push de
push hl
push bc
ld b, h
ld c, l
farcall StubbedTrainerRankings_AddToBattlePayouts
pop bc
pop hl
2015-11-22 21:21:21 -08:00
.loop
ld a, [de]
adc [hl]
ld [de], a
dec de
dec hl
dec c
2015-11-22 21:21:21 -08:00
jr nz, .loop
pop hl
ld a, [hld]
cp LOW(MAX_MONEY)
ld a, [hld]
sbc HIGH(MAX_MONEY) ; mid
ld a, [hl]
sbc HIGH(MAX_MONEY >> 8)
ret c
ld [hl], HIGH(MAX_MONEY >> 8)
inc hl
ld [hl], HIGH(MAX_MONEY) ; mid
inc hl
ld [hl], LOW(MAX_MONEY)
ret
; 3d0ea
2015-09-09 16:27:07 -07:00
PlayVictoryMusic: ; 3d0ea
push de
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld de, MUSIC_WILD_VICTORY
ld a, [wBattleMode]
dec a
2015-11-07 18:04:54 -08:00
jr nz, .trainer_victory
push de
2016-01-12 09:46:18 -08:00
call IsAnyMonHoldingExpShare
pop de
2015-11-07 18:04:54 -08:00
jr nz, .play_music
ld hl, wPayDayMoney
ld a, [hli]
or [hl]
2015-11-07 18:04:54 -08:00
jr nz, .play_music
ld a, [wBattleParticipantsNotFainted]
and a
2015-11-07 18:04:54 -08:00
jr z, .lost
jr .play_music
2015-11-07 18:04:54 -08:00
.trainer_victory
ld de, MUSIC_GYM_VICTORY
call IsGymLeader
2015-11-07 18:04:54 -08:00
jr c, .play_music
ld de, MUSIC_TRAINER_VICTORY
2015-11-07 18:04:54 -08:00
.play_music
call PlayMusic
2015-11-07 18:04:54 -08:00
.lost
pop de
ret
; 3d123
IsKantoGymLeader: ; 0x3d123
ld hl, KantoGymLeaders
jr IsGymLeaderCommon
IsGymLeader: ; 0x3d128
ld hl, GymLeaders
IsGymLeaderCommon:
push de
2018-01-23 14:39:09 -08:00
ld a, [wOtherTrainerClass]
2018-01-22 10:57:44 -08:00
ld de, 1
call IsInArray
pop de
ret
; 0x3d137
INCLUDE "data/trainers/leaders.asm"
2015-10-19 13:49:29 -07:00
HandlePlayerMonFaint: ; 3d14e
call FaintYourPokemon
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
2015-10-19 13:49:29 -07:00
call z, FaintEnemyPokemon
ld a, $1
2016-01-12 09:46:18 -08:00
ld [wWhichMonFaintedFirst], a
2015-11-10 16:51:13 -08:00
call PlayerMonFaintHappinessMod
call CheckPlayerPartyForFitMon
ld a, d
and a
jp z, LostBattle
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
2015-10-19 13:49:29 -07:00
jr nz, .notfainted
2016-01-12 09:46:18 -08:00
call UpdateBattleStateAndExperienceAfterEnemyFaint
ld a, [wBattleMode]
dec a
2015-10-19 13:49:29 -07:00
jr nz, .trainer
ld a, $1
2018-01-23 14:39:09 -08:00
ld [wBattleEnded], a
ret
2015-10-19 13:49:29 -07:00
.trainer
call CheckEnemyTrainerDefeated
jp z, WinTrainerBattle
2015-10-19 13:49:29 -07:00
.notfainted
2015-11-07 18:04:54 -08:00
call AskUseNextPokemon
2015-11-10 16:51:13 -08:00
jr nc, .switch
ld a, $1
2018-01-23 14:39:09 -08:00
ld [wBattleEnded], a
ret
2015-11-10 16:51:13 -08:00
.switch
call ForcePlayerMonChoice
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
jp c, WildFled_EnemyFled_LinkBattleCanceled
ld a, c
and a
ret nz
ld a, $1
ld [wBattlePlayerAction], a
2016-01-12 21:39:41 -08:00
call HandleEnemySwitch
jp z, WildFled_EnemyFled_LinkBattleCanceled
2015-11-23 13:04:53 -08:00
jp DoubleSwitch
; 3d1aa
2015-11-10 16:51:13 -08:00
PlayerMonFaintHappinessMod: ; 3d1aa
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld c, a
2015-11-07 18:04:54 -08:00
ld hl, wBattleParticipantsNotFainted
2015-11-22 21:21:21 -08:00
ld b, RESET_FLAG
predef SmallFarFlagAction
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus3
res SUBSTATUS_IN_LOOP, [hl]
xor a
ld [wLowHealthAlarm], a
2018-01-23 14:39:09 -08:00
ld hl, wPlayerDamageTaken
ld [hli], a
ld [hl], a
2018-01-23 14:39:09 -08:00
ld [wBattleMonStatus], a
call UpdateBattleMonInParty
2015-10-12 09:33:24 -07:00
ld c, HAPPINESS_FAINTED
; If TheirLevel > (YourLevel + 30), use a different parameter
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonLevel]
2015-10-12 09:33:24 -07:00
add 30
ld b, a
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonLevel]
cp b
2015-11-10 16:51:13 -08:00
jr c, .got_param
2015-10-12 09:33:24 -07:00
ld c, HAPPINESS_BEATENBYSTRONGFOE
2015-11-10 16:51:13 -08:00
.got_param
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wCurPartyMon], a
2017-12-24 09:47:30 -08:00
callfar ChangeHappiness
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
and BATTLERESULT_BITMASK
add LOSE
2015-10-24 07:34:19 -07:00
ld [wBattleResult], a
2016-01-12 09:46:18 -08:00
ld a, [wWhichMonFaintedFirst]
and a
ret z
2015-11-10 16:51:13 -08:00
ret ; ??????????
; 3d1f8
2015-11-07 18:04:54 -08:00
AskUseNextPokemon: ; 3d1f8
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-11-07 18:04:54 -08:00
; We don't need to be here if we're in a Trainer battle,
; as that decision is made for us.
ld a, [wBattleMode]
and a
dec a
ret nz
2015-11-07 18:04:54 -08:00
ld hl, BattleText_UseNextMon
call StdBattleTextBox
2015-11-07 18:04:54 -08:00
.loop
lb bc, 1, 7
call PlaceYesNoBox
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2015-11-07 18:04:54 -08:00
jr c, .pressed_b
and a
ret
2015-11-07 18:04:54 -08:00
.pressed_b
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2015-11-07 18:04:54 -08:00
cp $1 ; YES
jr z, .loop
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1Speed
ld de, wEnemyMonSpeed
2015-09-09 16:27:07 -07:00
jp TryToRunAwayFromBattle
; 3d227
2015-11-10 16:51:13 -08:00
ForcePlayerMonChoice: ; 3d227
call EmptyBattleTextBox
call LoadStandardMenuHeader
call SetUpBattlePartyMenu_NoLoop
call ForcePickPartyMonInBattle
ld a, [wLinkMode]
and a
2015-11-07 18:04:54 -08:00
jr z, .skip_link
ld a, $1
ld [wBattlePlayerAction], a
2015-11-23 13:04:53 -08:00
call LinkBattleSendReceiveAction
2015-11-07 18:04:54 -08:00
.skip_link
xor a
ld [wBattlePlayerAction], a
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
2015-11-10 16:51:13 -08:00
jr c, .enemy_fainted_mobile_error
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
2015-11-10 16:51:13 -08:00
jr nz, .send_out_pokemon
2015-11-10 16:51:13 -08:00
.enemy_fainted_mobile_error
call ClearSprites
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
2015-11-10 16:51:13 -08:00
call _LoadHPBar
call ExitMenu
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
call WaitBGMap
2015-11-20 12:15:32 -08:00
call GetMemSGBLayout
2015-09-09 16:27:07 -07:00
call SetPalettes
xor a
ld c, a
ret
2015-11-10 16:51:13 -08:00
.send_out_pokemon
call ClearSprites
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wLastPlayerMon], a
ld a, [wCurPartyMon]
ld [wCurBattleMon], a
2015-11-07 18:04:54 -08:00
call AddBattleParticipant
2015-11-06 13:42:38 -08:00
call InitBattleMon
call ResetPlayerStatLevels
call ClearPalettes
call DelayFrame
2015-11-10 16:51:13 -08:00
call _LoadHPBar
call CloseWindow
2015-11-20 12:15:32 -08:00
call GetMemSGBLayout
2015-09-09 16:27:07 -07:00
call SetPalettes
call SendOutMonText
call NewBattleMonStatus
call BreakAttraction
2015-11-07 06:48:32 -08:00
call SendOutPlayerMon
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
call SetPlayerTurn
call SpikesDamage
ld a, $1
and a
ld c, a
ret
; 3d2b3
2015-11-10 16:51:13 -08:00
PlayerPartyMonEntrance: ; 3d2b3
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wLastPlayerMon], a
ld a, [wCurPartyMon]
ld [wCurBattleMon], a
2015-11-07 18:04:54 -08:00
call AddBattleParticipant
2015-11-06 13:42:38 -08:00
call InitBattleMon
call ResetPlayerStatLevels
call SendOutMonText
call NewBattleMonStatus
call BreakAttraction
2015-11-07 06:48:32 -08:00
call SendOutPlayerMon
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
call SetPlayerTurn
jp SpikesDamage
; 3d2e0
2015-11-08 16:09:36 -08:00
CheckMobileBattleError: ; 3d2e0
ld a, [wLinkMode]
cp LINK_MOBILE
2015-11-07 18:04:54 -08:00
jr nz, .not_mobile ; It's not a mobile battle
ld a, [wcd2b]
and a
2015-11-07 18:04:54 -08:00
jr z, .not_mobile
; We have a mobile battle and something else happened
scf
ret
2015-11-07 18:04:54 -08:00
.not_mobile
xor a
ret
; 3d2f1
IsMobileBattle: ; 3d2f1
ld a, [wLinkMode]
cp LINK_MOBILE
ret
; 3d2f7
SetUpBattlePartyMenu_NoLoop: ; 3d2f7
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
SetUpBattlePartyMenu: ; switch to fullscreen menu?
2017-12-24 09:47:30 -08:00
farcall LoadPartyMenuGFX
farcall InitPartyMenuWithCancel
farcall InitPartyMenuBGPal7
farcall InitPartyMenuGFX
ret
; 3d313
2016-01-12 21:39:41 -08:00
JumpToPartyMenuAndPrintText: ; 3d313
2017-12-24 09:47:30 -08:00
farcall WritePartyMenuTilemap
farcall PrintPartyMenuText
call WaitBGMap
2015-09-09 16:27:07 -07:00
call SetPalettes
call DelayFrame
ret
; 3d329
2016-01-12 21:39:41 -08:00
SelectBattleMon: ; 3d329
call IsMobileBattle
jr z, .mobile
2017-12-24 09:47:30 -08:00
farcall PartyMenuSelect
ret
.mobile
2017-12-24 09:47:30 -08:00
farcall Mobile_PartyMenuSelect
ret
; 3d33c
PickPartyMonInBattle: ; 3d33c
.loop
ld a, PARTYMENUACTION_SWITCH ; Which PKMN?
2018-01-23 14:39:09 -08:00
ld [wPartyMenuActionText], a
2016-01-12 21:39:41 -08:00
call JumpToPartyMenuAndPrintText
call SelectBattleMon
ret c
2016-03-01 19:31:21 -08:00
call CheckIfCurPartyMonIsFitToFight
jr z, .loop
xor a
ret
; 3d34f
SwitchMonAlreadyOut: ; 3d34f
2018-01-23 14:39:09 -08:00
ld hl, wCurBattleMon
ld a, [wCurPartyMon]
cp [hl]
jr nz, .notout
ld hl, BattleText_MonIsAlreadyOut
call StdBattleTextBox
scf
ret
.notout
xor a
ret
; 3d362
ForcePickPartyMonInBattle: ; 3d362
; Can't back out.
.pick
call PickPartyMonInBattle
ret nc
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
ret c
ld de, SFX_WRONG
call PlaySFX
call WaitSFX
jr .pick
; 3d375
PickSwitchMonInBattle: ; 3d375
.pick
call PickPartyMonInBattle
ret c
call SwitchMonAlreadyOut
jr c, .pick
xor a
ret
; 3d380
ForcePickSwitchMonInBattle: ; 3d380
; Can't back out.
.pick
call ForcePickPartyMonInBattle
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
ret c
call SwitchMonAlreadyOut
jr c, .pick
xor a
ret
; 3d38e
LostBattle: ; 3d38e
ld a, 1
2018-01-23 14:39:09 -08:00
ld [wBattleEnded], a
2018-01-23 14:39:09 -08:00
ld a, [wInBattleTowerBattle]
bit 0, a
2015-11-03 19:35:36 -08:00
jr nz, .battle_tower
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_CANLOSE
2015-11-03 19:35:36 -08:00
jr nz, .not_canlose
; Remove the enemy from the screen.
hlcoord 0, 0
2015-10-19 13:49:29 -07:00
lb bc, 8, 21
call ClearBox
call BattleWinSlideInEnemyTrainerFrontpic
ld c, 40
call DelayFrames
ld a, [wMonStatusFlags]
bit 0, a
2015-11-04 12:35:29 -08:00
jr nz, .skip_win_loss_text
call PrintWinLossText
.skip_win_loss_text
ret
2015-11-03 19:35:36 -08:00
.battle_tower
; Remove the enemy from the screen.
hlcoord 0, 0
2015-10-19 13:49:29 -07:00
lb bc, 8, 21
call ClearBox
call BattleWinSlideInEnemyTrainerFrontpic
ld c, 40
call DelayFrames
call EmptyBattleTextBox
ld c, BATTLETOWERTEXT_WIN_TEXT
2017-12-24 09:47:30 -08:00
farcall BattleTowerText
call WaitPressAorB_BlinkCursor
call ClearTileMap
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
ret
2015-11-03 19:35:36 -08:00
.not_canlose
ld a, [wLinkMode]
and a
jr nz, .LostLinkBattle
; Greyscale
2015-12-28 07:57:04 -08:00
ld b, SCGB_BATTLE_GRAYSCALE
call GetSGBLayout
2015-09-09 16:27:07 -07:00
call SetPalettes
jr .end
.LostLinkBattle:
call UpdateEnemyMonInParty
2015-10-19 13:49:29 -07:00
call CheckEnemyTrainerDefeated
2015-11-03 19:35:36 -08:00
jr nz, .not_tied
ld hl, TiedAgainstText
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
and BATTLERESULT_BITMASK
add DRAW
2015-10-24 07:34:19 -07:00
ld [wBattleResult], a
jr .text
2015-11-03 19:35:36 -08:00
.not_tied
ld hl, LostAgainstText
call IsMobileBattle
2015-11-03 19:35:36 -08:00
jr z, .mobile
.text
call StdBattleTextBox
.end
scf
ret
2015-11-03 19:35:36 -08:00
.mobile
; Remove the enemy from the screen.
hlcoord 0, 0
2015-10-19 13:49:29 -07:00
lb bc, 8, 21
call ClearBox
call BattleWinSlideInEnemyTrainerFrontpic
ld c, 40
call DelayFrames
ld c, $3 ; lost
2017-12-24 09:47:30 -08:00
farcall Mobile_PrintOpponentBattleMessage
scf
ret
; 3d432
2015-10-19 13:49:29 -07:00
EnemyMonFaintedAnimation: ; 3d432
hlcoord 12, 5
decoord 12, 6
2015-10-19 13:49:29 -07:00
jp MonFaintedAnimation
; 3d43b
2015-10-19 13:49:29 -07:00
PlayerMonFaintedAnimation: ; 3d43b
hlcoord 1, 10
decoord 1, 11
2015-10-19 13:49:29 -07:00
jp MonFaintedAnimation
; 3d444
2015-10-19 13:49:29 -07:00
MonFaintedAnimation: ; 3d444
ld a, [wcfbe]
push af
set 6, a
ld [wcfbe], a
2015-10-19 13:49:29 -07:00
ld b, 7
.OuterLoop:
push bc
push de
push hl
2015-10-19 13:49:29 -07:00
ld b, 6
.InnerLoop:
push bc
push hl
push de
2015-10-19 13:49:29 -07:00
ld bc, 7
call CopyBytes
pop de
pop hl
2015-10-19 13:49:29 -07:00
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
2015-10-19 13:49:29 -07:00
jr nz, .InnerLoop
ld bc, 20
add hl, bc
ld de, .Spaces
call PlaceString
ld c, 2
call DelayFrames
pop hl
pop de
pop bc
dec b
2015-10-19 13:49:29 -07:00
jr nz, .OuterLoop
pop af
ld [wcfbe], a
ret
; 3d488
.Spaces:
db " @"
; 3d490
SlideBattlePicOut: ; 3d490
2015-11-02 08:15:32 -08:00
ld [hMapObjectIndexBuffer], a
ld c, a
.loop
push bc
push hl
ld b, $7
.loop2
push hl
call .DoFrame
pop hl
ld de, SCREEN_WIDTH
add hl, de
dec b
jr nz, .loop2
ld c, 2
call DelayFrames
pop hl
pop bc
dec c
jr nz, .loop
ret
; 3d4ae
.DoFrame: ; 3d4ae
2015-11-02 08:15:32 -08:00
ld a, [hMapObjectIndexBuffer]
ld c, a
cp $8
jr nz, .back
.forward
ld a, [hli]
ld [hld], a
dec hl
dec c
jr nz, .forward
ret
.back
ld a, [hld]
ld [hli], a
inc hl
dec c
jr nz, .back
ret
; 3d4c3
2015-11-10 16:51:13 -08:00
ForceEnemySwitch: ; 3d4c3
call ResetEnemyBattleVars
2015-11-08 16:09:36 -08:00
ld a, [wEnemySwitchMonIndex]
dec a
ld b, a
call LoadEnemyMonToSwitchTo
2015-11-10 16:51:13 -08:00
call ClearEnemyMonBox
call NewEnemyMonStatus
call ResetEnemyStatLevels
call Function_SetEnemyMonAndSendOutAnimation
call BreakAttraction
2015-11-07 18:04:54 -08:00
call ResetBattleParticipants
ret
; 3d4e1
2015-11-07 18:04:54 -08:00
EnemySwitch: ; 3d4e1
2015-11-10 16:51:13 -08:00
call CheckWhetherToAskSwitch
2015-11-07 18:04:54 -08:00
jr nc, EnemySwitch_SetMode
; Shift Mode
call ResetEnemyBattleVars
2015-11-10 16:51:13 -08:00
call CheckWhetherSwitchmonIsPredetermined
2015-11-07 18:04:54 -08:00
jr c, .skip
call FindMonInOTPartyToSwitchIntoBattle
2015-11-07 18:04:54 -08:00
.skip
; 'b' contains the PartyNr of the mon the AI will switch to
call LoadEnemyMonToSwitchTo
2015-11-07 18:04:54 -08:00
call OfferSwitch
push af
2015-11-10 16:51:13 -08:00
call ClearEnemyMonBox
2015-08-23 06:09:56 -07:00
call Function_BattleTextEnemySentOut
call Function_SetEnemyMonAndSendOutAnimation
pop af
ret c
2015-11-07 18:04:54 -08:00
; If we're here, then we're switching too
xor a
2015-11-07 18:04:54 -08:00
ld [wBattleParticipantsNotFainted], a
2016-01-12 09:46:18 -08:00
ld [wBattleParticipantsIncludingFainted], a
ld [wBattlePlayerAction], a
inc a
ld [wEnemyIsSwitching], a
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-11-07 18:04:54 -08:00
jp PlayerSwitch
2013-12-31 01:09:00 -08:00
; 3d517
2015-11-07 18:04:54 -08:00
EnemySwitch_SetMode: ; 3d517
call ResetEnemyBattleVars
2015-11-10 16:51:13 -08:00
call CheckWhetherSwitchmonIsPredetermined
2015-11-07 18:04:54 -08:00
jr c, .skip
call FindMonInOTPartyToSwitchIntoBattle
2015-11-07 18:04:54 -08:00
.skip
; 'b' contains the PartyNr of the mon the AI will switch to
call LoadEnemyMonToSwitchTo
ld a, 1
ld [wEnemyIsSwitching], a
2015-11-10 16:51:13 -08:00
call ClearEnemyMonBox
2015-08-23 06:09:56 -07:00
call Function_BattleTextEnemySentOut
jp Function_SetEnemyMonAndSendOutAnimation
; 3d533
2015-11-10 16:51:13 -08:00
CheckWhetherSwitchmonIsPredetermined: ; 3d533
; returns carry if: ???
ld a, [wLinkMode]
and a
2015-11-06 06:04:27 -08:00
jr z, .not_linked
ld a, [wBattleAction]
2015-11-06 06:04:27 -08:00
sub BATTLEACTION_SWITCH1
ld b, a
2015-11-06 06:04:27 -08:00
jr .return_carry
2015-11-06 06:04:27 -08:00
.not_linked
2015-11-08 16:09:36 -08:00
ld a, [wEnemySwitchMonIndex]
and a
2016-08-07 15:14:20 -07:00
jr z, .check_wBattleHasJustStarted
dec a
ld b, a
2015-11-06 06:04:27 -08:00
jr .return_carry
2016-08-07 15:14:20 -07:00
.check_wBattleHasJustStarted
ld a, [wBattleHasJustStarted]
and a
ld b, $0
2015-11-06 06:04:27 -08:00
jr nz, .return_carry
and a
ret
2015-11-06 06:04:27 -08:00
.return_carry
scf
ret
; 3d557
ResetEnemyBattleVars: ; 3d557
; and draw empty TextBox
xor a
2018-01-23 14:39:09 -08:00
ld [wLastPlayerCounterMove], a
ld [wLastEnemyCounterMove], a
ld [wLastEnemyMove], a
ld [wCurEnemyMove], a
dec a
2016-01-12 09:46:18 -08:00
ld [wEnemyItemState], a
xor a
2015-11-08 10:27:26 -08:00
ld [wPlayerWrapCount], a
hlcoord 18, 0
ld a, 8
call SlideBattlePicOut
call EmptyBattleTextBox
jp LoadStandardMenuHeader
; 3d57a
2015-11-07 18:04:54 -08:00
ResetBattleParticipants: ; 3d57a
xor a
2015-11-07 18:04:54 -08:00
ld [wBattleParticipantsNotFainted], a
2016-01-12 09:46:18 -08:00
ld [wBattleParticipantsIncludingFainted], a
2015-11-07 18:04:54 -08:00
AddBattleParticipant: ; 3d581
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld c, a
2015-11-07 18:04:54 -08:00
ld hl, wBattleParticipantsNotFainted
ld b, SET_FLAG
push bc
predef SmallFarFlagAction
pop bc
2016-01-12 09:46:18 -08:00
ld hl, wBattleParticipantsIncludingFainted
predef_jump SmallFarFlagAction
; 3d599
FindMonInOTPartyToSwitchIntoBattle: ; 3d599
2018-02-25 16:50:48 -08:00
ld b, -1
ld a, $1
2018-01-23 14:39:09 -08:00
ld [wBuffer1], a
ld [wBuffer2], a
2016-01-12 21:39:41 -08:00
.loop
2018-01-23 14:39:09 -08:00
ld hl, wBuffer1
sla [hl]
inc hl
sla [hl]
inc b
2018-01-23 14:39:09 -08:00
ld a, [wOTPartyCount]
cp b
2016-01-12 21:39:41 -08:00
jp z, ScoreMonTypeMatchups
2018-01-23 14:39:09 -08:00
ld a, [wCurOTMon]
cp b
2016-01-12 21:39:41 -08:00
jr z, .discourage
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1HP
push bc
ld a, b
call GetPartyLocation
ld a, [hli]
ld c, a
ld a, [hl]
or c
pop bc
2016-01-12 21:39:41 -08:00
jr z, .discourage
call LookUpTheEffectivenessOfEveryMove
call IsThePlayerMonTypesEffectiveAgainstOTMon
2016-01-12 21:39:41 -08:00
jr .loop
2016-01-12 21:39:41 -08:00
.discourage
2018-01-23 14:39:09 -08:00
ld hl, wBuffer2
set 0, [hl]
2016-01-12 21:39:41 -08:00
jr .loop
; 3d5d7
LookUpTheEffectivenessOfEveryMove: ; 3d5d7
push bc
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1Moves
ld a, b
call GetPartyLocation
pop bc
ld e, NUM_MOVES + 1
.loop
dec e
jr z, .done
ld a, [hli]
and a
jr z, .done
push hl
push de
push bc
dec a
ld hl, Moves
ld bc, MOVE_LENGTH
call AddNTimes
ld de, wEnemyMoveStruct
2013-12-30 20:22:27 -08:00
ld a, BANK(Moves)
call FarCopyBytes
call SetEnemyTurn
2017-12-24 09:47:30 -08:00
callfar BattleCheckTypeMatchup
pop bc
pop de
pop hl
ld a, [wd265] ; Get The Effectiveness Modifier
cp 10 + 1 ; 1.0 + 0.1
jr c, .loop
2018-01-23 14:39:09 -08:00
ld hl, wBuffer1
set 0, [hl]
ret
.done
ret
; 3d618
IsThePlayerMonTypesEffectiveAgainstOTMon: ; 3d618
; Calculates the effectiveness of the types of the PlayerMon
; against the OTMon
push bc
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyCount
ld a, b
inc a
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
dec a
ld hl, BaseData + BASE_TYPES
ld bc, BASE_DATA_SIZE
call AddNTimes
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonType
ld bc, BASE_CATCH_RATE - BASE_TYPES
2014-01-05 04:28:55 -08:00
ld a, BANK(BaseData)
call FarCopyBytes
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonType1]
ld [wPlayerMoveStruct + MOVE_TYPE], a
call SetPlayerTurn
2017-12-24 09:47:30 -08:00
callfar BattleCheckTypeMatchup
ld a, [wd265]
cp 10 + 1 ; 1.0 + 0.1
2016-01-12 21:39:41 -08:00
jr nc, .super_effective
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonType2]
ld [wPlayerMoveStruct + MOVE_TYPE], a
2017-12-24 09:47:30 -08:00
callfar BattleCheckTypeMatchup
ld a, [wd265]
cp 10 + 1 ; 1.0 + 0.1
2016-01-12 21:39:41 -08:00
jr nc, .super_effective
pop bc
ret
2016-01-12 21:39:41 -08:00
.super_effective
pop bc
2018-01-23 14:39:09 -08:00
ld hl, wBuffer1
bit 0, [hl]
2016-01-12 21:39:41 -08:00
jr nz, .reset
inc hl
set 0, [hl]
ret
2016-01-12 21:39:41 -08:00
.reset
res 0, [hl]
ret
; 3d672
2016-01-12 21:39:41 -08:00
ScoreMonTypeMatchups: ; 3d672
.loop1
2018-01-23 14:39:09 -08:00
ld hl, wBuffer1
sla [hl]
inc hl
sla [hl]
2016-01-12 21:39:41 -08:00
jr nc, .loop1
2018-01-23 14:39:09 -08:00
ld a, [wOTPartyCount]
ld b, a
ld c, [hl]
2016-01-12 21:39:41 -08:00
.loop2
sla c
2016-01-12 21:39:41 -08:00
jr nc, .okay
dec b
2016-01-12 21:39:41 -08:00
jr z, .loop5
jr .loop2
2016-01-12 21:39:41 -08:00
.okay
2018-01-23 14:39:09 -08:00
ld a, [wBuffer1]
and a
2016-01-12 21:39:41 -08:00
jr z, .okay2
2018-02-25 16:50:48 -08:00
ld b, -1
ld c, a
2016-01-12 21:39:41 -08:00
.loop3
inc b
sla c
2016-01-12 21:39:41 -08:00
jr nc, .loop3
jr .quit
2016-01-12 21:39:41 -08:00
.okay2
2018-02-25 16:50:48 -08:00
ld b, -1
2018-01-23 14:39:09 -08:00
ld a, [wBuffer2]
ld c, a
2016-01-12 21:39:41 -08:00
.loop4
inc b
sla c
2016-01-12 21:39:41 -08:00
jr c, .loop4
jr .quit
2016-01-12 21:39:41 -08:00
.loop5
2018-01-23 14:39:09 -08:00
ld a, [wOTPartyCount]
ld b, a
call BattleRandom
and $7
cp b
2016-01-12 21:39:41 -08:00
jr nc, .loop5
ld b, a
2018-01-23 14:39:09 -08:00
ld a, [wCurOTMon]
cp b
2016-01-12 21:39:41 -08:00
jr z, .loop5
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1HP
push bc
ld a, b
call GetPartyLocation
pop bc
ld a, [hli]
ld c, a
ld a, [hl]
or c
2016-01-12 21:39:41 -08:00
jr z, .loop5
2016-01-12 21:39:41 -08:00
.quit
ret
; 3d6ca
LoadEnemyMonToSwitchTo: ; 3d6ca
; 'b' contains the PartyNr of the mon the AI will switch to
ld a, b
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
ld hl, wOTPartyMon1Level
call GetPartyLocation
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
ld a, [wCurPartyMon]
inc a
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyCount
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wTempEnemyMonSpecies], a
ld [wCurPartySpecies], a
call LoadEnemyMon
2015-09-09 16:27:07 -07:00
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
2014-03-05 02:42:09 -08:00
cp UNOWN
2015-11-09 20:55:39 -08:00
jr nz, .skip_unown
2015-11-29 18:34:59 -08:00
ld a, [wFirstUnownSeen]
and a
2015-11-09 20:55:39 -08:00
jr nz, .skip_unown
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonDVs
predef GetUnownLetter
2018-01-23 14:39:09 -08:00
ld a, [wUnownLetter]
2015-11-29 18:34:59 -08:00
ld [wFirstUnownSeen], a
2015-11-09 20:55:39 -08:00
.skip_unown
2015-09-09 16:27:07 -07:00
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
ld [wEnemyHPAtTimeOfPlayerSwitch], a
ld a, [hl]
ld [wEnemyHPAtTimeOfPlayerSwitch + 1], a
ret
; 3d714
2015-11-10 16:51:13 -08:00
CheckWhetherToAskSwitch: ; 3d714
2016-08-07 15:14:20 -07:00
ld a, [wBattleHasJustStarted]
dec a
2015-11-10 16:51:13 -08:00
jp z, .return_nc
2018-01-23 14:39:09 -08:00
ld a, [wPartyCount]
dec a
2015-11-10 16:51:13 -08:00
jp z, .return_nc
ld a, [wLinkMode]
and a
2015-11-10 16:51:13 -08:00
jp nz, .return_nc
2018-01-23 14:39:09 -08:00
ld a, [wOptions]
bit BATTLE_SHIFT, a
2015-11-10 16:51:13 -08:00
jr nz, .return_nc
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
push af
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wCurPartyMon], a
2017-12-24 09:47:30 -08:00
farcall CheckCurPartyMonFainted
pop bc
ld a, b
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
2015-11-10 16:51:13 -08:00
jr c, .return_nc
scf
ret
2015-11-10 16:51:13 -08:00
.return_nc
and a
ret
; 3d74b
2015-11-07 18:04:54 -08:00
OfferSwitch: ; 3d74b
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
push af
2017-12-24 09:47:30 -08:00
callfar Battle_GetTrainerName
ld hl, BattleText_EnemyIsAboutToUseWillPlayerChangeMon
call StdBattleTextBox
lb bc, 1, 7
call PlaceYesNoBox
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
dec a
2015-11-07 18:04:54 -08:00
jr nz, .said_no
call SetUpBattlePartyMenu_NoLoop
call PickSwitchMonInBattle
2015-11-07 18:04:54 -08:00
jr c, .canceled_switch
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wLastPlayerMon], a
ld a, [wCurPartyMon]
ld [wCurBattleMon], a
call ClearPalettes
call DelayFrame
2015-11-10 16:51:13 -08:00
call _LoadHPBar
pop af
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
xor a
2018-01-23 14:39:09 -08:00
ld [wCurEnemyMove], a
ld [wCurPlayerMove], a
and a
ret
2015-11-07 18:04:54 -08:00
.canceled_switch
call ClearPalettes
call DelayFrame
2015-11-10 16:51:13 -08:00
call _LoadHPBar
2015-11-07 18:04:54 -08:00
.said_no
pop af
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
scf
ret
; 3d7a0
2015-11-10 16:51:13 -08:00
ClearEnemyMonBox: ; 3d7a0
xor a
ld [hBGMapMode], a
call ExitMenu
call ClearSprites
hlcoord 1, 0
lb bc, 4, 10
call ClearBox
call WaitBGMap
2015-11-09 13:41:09 -08:00
jp FinishBattleAnim
; 3d7b8
2015-08-23 06:09:56 -07:00
Function_BattleTextEnemySentOut: ; 3d7b8
2017-12-24 09:47:30 -08:00
callfar Battle_GetTrainerName
2015-08-23 06:09:56 -07:00
ld hl, BattleText_EnemySentOut
call StdBattleTextBox
jp WaitBGMap
; 3d7c7
Function_SetEnemyMonAndSendOutAnimation: ; 3d7c7
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld [wCurPartySpecies], a
ld [wCurSpecies], a
call GetBaseData
ld a, OTPARTYMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
predef CopyMonToTempMon
call GetEnemyMonFrontpic
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
2015-12-23 17:46:23 -08:00
ld [wBattleAnimParam], a
call SetEnemyTurn
ld de, ANIM_SEND_OUT_MON
2015-09-09 16:27:07 -07:00
call Call_PlayBattleAnim
2015-11-06 13:42:38 -08:00
call BattleCheckEnemyShininess
2015-11-07 06:48:32 -08:00
jr nc, .not_shiny
ld a, 1 ; shiny anim
2015-12-23 17:46:23 -08:00
ld [wBattleAnimParam], a
ld de, ANIM_SEND_OUT_MON
2015-09-09 16:27:07 -07:00
call Call_PlayBattleAnim
2015-11-07 06:48:32 -08:00
.not_shiny
2018-01-23 14:39:09 -08:00
ld bc, wTempMonSpecies
2017-12-24 09:47:30 -08:00
farcall CheckFaintedFrzSlp
2015-11-07 06:48:32 -08:00
jr c, .skip_cry
2017-12-24 09:47:30 -08:00
farcall CheckBattleScene
2015-11-07 06:48:32 -08:00
jr c, .cry_no_anim
hlcoord 12, 0
ld d, $0
2015-11-07 06:48:32 -08:00
ld e, ANIM_MON_SLOW
predef AnimateFrontpic
2015-11-07 06:48:32 -08:00
jr .skip_cry
2015-11-07 06:48:32 -08:00
.cry_no_anim
ld a, $f
2018-01-23 14:39:09 -08:00
ld [wCryTracks], a
ld a, [wTempEnemyMonSpecies]
2014-07-18 10:25:03 -07:00
call PlayStereoCry
2015-11-07 06:48:32 -08:00
.skip_cry
call UpdateEnemyHUD
ld a, $1
ld [hBGMapMode], a
ret
; 3d834
NewEnemyMonStatus: ; 3d834
xor a
2018-01-23 14:39:09 -08:00
ld [wLastPlayerCounterMove], a
ld [wLastEnemyCounterMove], a
ld [wLastEnemyMove], a
ld hl, wEnemySubStatus1
2015-07-20 19:18:18 -07:00
rept 4
ld [hli], a
2015-07-20 19:18:18 -07:00
endr
ld [hl], a
2018-01-23 14:39:09 -08:00
ld [wEnemyDisableCount], a
ld [wEnemyFuryCutterCount], a
ld [wEnemyProtectCount], a
2015-11-05 16:13:09 -08:00
ld [wEnemyRageCounter], a
2018-01-23 14:39:09 -08:00
ld [wEnemyDisabledMove], a
ld [wEnemyMinimized], a
2015-11-08 10:27:26 -08:00
ld [wPlayerWrapCount], a
ld [wEnemyWrapCount], a
2018-01-23 14:39:09 -08:00
ld [wEnemyTurnsTaken], a
ld hl, wPlayerSubStatus5
res SUBSTATUS_CANT_RUN, [hl]
ret
; 3d867
ResetEnemyStatLevels: ; 3d867
2015-11-06 17:55:16 -08:00
ld a, BASE_STAT_LEVEL
ld b, NUM_LEVEL_STATS
2018-01-23 14:39:09 -08:00
ld hl, wEnemyStatLevels
.loop
ld [hli], a
dec b
jr nz, .loop
ret
; 3d873
CheckPlayerPartyForFitMon: ; 3d873
; Has the player any mon in his Party that can fight?
2018-01-23 14:39:09 -08:00
ld a, [wPartyCount]
ld e, a
xor a
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1HP
ld bc, wPartyMon2 - (wPartyMon1 + 1)
2016-03-01 19:31:21 -08:00
.loop
or [hl]
inc hl
or [hl]
add hl, bc
dec e
2016-03-01 19:31:21 -08:00
jr nz, .loop
ld d, a
ret
; 3d887
2016-03-01 19:31:21 -08:00
CheckIfCurPartyMonIsFitToFight: ; 3d887
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld hl, wPartyMon1HP
call GetPartyLocation
ld a, [hli]
or [hl]
ret nz
2016-08-07 15:14:20 -07:00
ld a, [wBattleHasJustStarted]
and a
2016-03-01 19:31:21 -08:00
jr nz, .finish_fail
2018-01-23 14:39:09 -08:00
ld hl, wPartySpecies
ld a, [wCurPartyMon]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
cp EGG
ld hl, BattleText_AnEGGCantBattle
2016-03-01 19:31:21 -08:00
jr z, .print_textbox
ld hl, BattleText_TheresNoWillToBattle
2016-03-01 19:31:21 -08:00
.print_textbox
call StdBattleTextBox
2016-03-01 19:31:21 -08:00
.finish_fail
xor a
ret
; 3d8b3
2015-09-09 16:27:07 -07:00
TryToRunAwayFromBattle: ; 3d8b3
; Run away from battle, with or without item
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
2015-09-09 16:27:07 -07:00
cp BATTLETYPE_DEBUG
2015-11-06 06:04:27 -08:00
jp z, .can_escape
cp BATTLETYPE_CONTEST
2015-11-06 06:04:27 -08:00
jp z, .can_escape
cp BATTLETYPE_TRAP
2015-11-06 06:04:27 -08:00
jp z, .cant_escape
cp BATTLETYPE_CELEBI
2015-11-06 06:04:27 -08:00
jp z, .cant_escape
cp BATTLETYPE_SHINY
2015-11-06 06:04:27 -08:00
jp z, .cant_escape
cp BATTLETYPE_SUICUNE
2015-11-06 06:04:27 -08:00
jp z, .cant_escape
ld a, [wLinkMode]
and a
2015-11-06 06:04:27 -08:00
jp nz, .can_escape
ld a, [wBattleMode]
dec a
2015-11-06 06:04:27 -08:00
jp nz, .cant_run_from_trainer
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus5]
bit SUBSTATUS_CANT_RUN, a
2015-11-06 06:04:27 -08:00
jp nz, .cant_escape
2015-11-08 10:27:26 -08:00
ld a, [wPlayerWrapCount]
and a
2015-11-06 06:04:27 -08:00
jp nz, .cant_escape
push hl
push de
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonItem]
ld [wd265], a
ld b, a
2017-12-24 09:47:30 -08:00
callfar GetItemHeldEffect
ld a, b
cp HELD_ESCAPE
pop de
pop hl
2015-11-06 06:04:27 -08:00
jr nz, .no_flee_item
call SetPlayerTurn
call GetItemName
2015-09-09 16:27:07 -07:00
ld hl, BattleText_UserFledUsingAStringBuffer1
call StdBattleTextBox
2015-11-06 06:04:27 -08:00
jp .can_escape
2015-11-06 06:04:27 -08:00
.no_flee_item
2015-11-23 13:04:53 -08:00
ld a, [wNumFleeAttempts]
inc a
2015-11-23 13:04:53 -08:00
ld [wNumFleeAttempts], a
ld a, [hli]
ld [hStringCmpString2 + 0], a
ld a, [hl]
ld [hStringCmpString2 + 1], a
ld a, [de]
inc de
ld [hStringCmpString1 + 0], a
ld a, [de]
ld [hStringCmpString1 + 1], a
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
ld de, hStringCmpString2
ld hl, hStringCmpString1
ld c, $2
call StringCmp
2015-11-06 06:04:27 -08:00
jr nc, .can_escape
xor a
ld [hMultiplicand], a
ld a, $20
ld [hMultiplier], a
call Multiply
ld a, [hProduct + 2]
ld [hDividend + 0], a
ld a, [hProduct + 3]
ld [hDividend + 1], a
2015-11-06 06:04:27 -08:00
ld a, [hStringCmpString1 + 0]
ld b, a
2015-11-06 06:04:27 -08:00
ld a, [hStringCmpString1 + 1]
srl b
rr a
srl b
rr a
and a
2015-11-06 06:04:27 -08:00
jr z, .can_escape
ld [hDivisor], a
2016-01-17 21:39:01 -08:00
ld b, 2
call Divide
ld a, [hQuotient + 1]
and a
2015-11-06 06:04:27 -08:00
jr nz, .can_escape
2015-11-23 13:04:53 -08:00
ld a, [wNumFleeAttempts]
ld c, a
2015-11-06 06:04:27 -08:00
.loop
dec c
2015-11-06 06:04:27 -08:00
jr z, .cant_escape_2
2015-11-23 13:04:53 -08:00
ld b, 30
ld a, [hQuotient + 2]
add b
2015-11-06 06:04:27 -08:00
ld [hQuotient + 2], a
jr c, .can_escape
jr .loop
2015-11-06 06:04:27 -08:00
.cant_escape_2
call BattleRandom
ld b, a
2015-11-06 06:04:27 -08:00
ld a, [hQuotient + 2]
cp b
2015-11-06 06:04:27 -08:00
jr nc, .can_escape
ld a, $1
ld [wBattlePlayerAction], a
ld hl, BattleText_CantEscape2
2015-11-06 06:04:27 -08:00
jr .print_inescapable_text
2015-11-06 06:04:27 -08:00
.cant_escape
ld hl, BattleText_CantEscape
2015-11-06 06:04:27 -08:00
jr .print_inescapable_text
2015-11-06 06:04:27 -08:00
.cant_run_from_trainer
ld hl, BattleText_TheresNoEscapeFromTrainerBattle
2015-11-06 06:04:27 -08:00
.print_inescapable_text
call StdBattleTextBox
ld a, $1
2015-11-23 13:04:53 -08:00
ld [wFailedToFlee], a
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
and a
ret
2015-11-06 06:04:27 -08:00
.can_escape
ld a, [wLinkMode]
and a
2015-11-06 06:04:27 -08:00
ld a, DRAW
jr z, .fled
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
xor a
ld [wBattlePlayerAction], a
ld a, $f
2018-01-23 14:39:09 -08:00
ld [wCurMoveNum], a
xor a
2018-01-23 14:39:09 -08:00
ld [wCurPlayerMove], a
2015-11-23 13:04:53 -08:00
call LinkBattleSendReceiveAction
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
jr c, .mobile
; Got away safely
ld a, [wBattleAction]
2015-11-06 06:04:27 -08:00
cp BATTLEACTION_FORFEIT
ld a, DRAW
jr z, .fled
2018-04-05 08:44:02 -07:00
dec a ; LOSE
2015-11-06 06:04:27 -08:00
.fled
ld b, a
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
and BATTLERESULT_BITMASK
add b
2015-10-24 07:34:19 -07:00
ld [wBattleResult], a
2015-10-19 13:49:29 -07:00
call StopDangerSound
push de
ld de, SFX_RUN
call WaitPlaySFX
pop de
call WaitSFX
ld hl, BattleText_GotAwaySafely
call StdBattleTextBox
call WaitSFX
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
scf
ret
2015-11-08 16:09:36 -08:00
.mobile
2015-10-19 13:49:29 -07:00
call StopDangerSound
ld hl, wcd2a
bit 4, [hl]
2015-11-08 16:09:36 -08:00
jr nz, .skip_link_error
2015-08-24 16:56:30 -07:00
ld hl, BattleText_LinkErrorBattleCanceled
call StdBattleTextBox
2015-11-08 16:09:36 -08:00
.skip_link_error
call WaitSFX
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
scf
ret
; 3da0d
2015-11-06 13:42:38 -08:00
InitBattleMon: ; 3da0d
ld a, MON_SPECIES
call GetPartyParamLocation
2018-01-23 14:39:09 -08:00
ld de, wBattleMonSpecies
2015-11-06 06:04:27 -08:00
ld bc, MON_ID
call CopyBytes
ld bc, MON_DVS - MON_ID
add hl, bc
2018-01-23 14:39:09 -08:00
ld de, wBattleMonDVs
ld bc, MON_PKRUS - MON_DVS
call CopyBytes
inc hl
inc hl
inc hl
2018-01-23 14:39:09 -08:00
ld de, wBattleMonLevel
ld bc, PARTYMON_STRUCT_LENGTH - MON_LEVEL
call CopyBytes
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonSpecies]
ld [wTempBattleMonSpecies], a
ld [wCurPartySpecies], a
ld [wCurSpecies], a
call GetBaseData
2018-01-23 14:39:09 -08:00
ld a, [wBaseType1]
ld [wBattleMonType1], a
ld a, [wBaseType2]
ld [wBattleMonType2], a
ld hl, wPartyMonNicknames
ld a, [wCurBattleMon]
call SkipNames
2018-01-23 14:39:09 -08:00
ld de, wBattleMonNick
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
call CopyBytes
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonAttack
ld de, wPlayerStats
ld bc, PARTYMON_STRUCT_LENGTH - MON_ATK
call CopyBytes
2015-11-07 18:04:54 -08:00
call ApplyStatusEffectOnPlayerStats
call BadgeStatBoosts
ret
; 3da74
2015-11-06 13:42:38 -08:00
BattleCheckPlayerShininess: ; 3da74
call GetPartyMonDVs
jr BattleCheckShininess
2015-11-06 13:42:38 -08:00
BattleCheckEnemyShininess: ; 3da79
call GetEnemyMonDVs
2015-11-06 13:42:38 -08:00
BattleCheckShininess: ; 3da7c
ld b, h
ld c, l
2017-12-24 09:47:30 -08:00
callfar CheckShininess
ret
; 3da85
2015-11-06 13:42:38 -08:00
GetPartyMonDVs: ; 3da85
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonDVs
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TRANSFORMED, a
ret z
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1DVs
ld a, [wCurBattleMon]
jp GetPartyLocation
; 3da97
2015-11-06 13:42:38 -08:00
GetEnemyMonDVs: ; 3da97
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonDVs
ld a, [wEnemySubStatus5]
bit SUBSTATUS_TRANSFORMED, a
ret z
2016-01-10 14:44:09 -08:00
ld hl, wEnemyBackupDVs
ld a, [wBattleMode]
dec a
ret z
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1DVs
ld a, [wCurOTMon]
jp GetPartyLocation
; 3dab1
ResetPlayerStatLevels: ; 3dab1
2015-11-06 17:55:16 -08:00
ld a, BASE_STAT_LEVEL
ld b, NUM_LEVEL_STATS
2018-01-23 14:39:09 -08:00
ld hl, wPlayerStatLevels
.loop
ld [hli], a
dec b
jr nz, .loop
ret
; 3dabd
2016-01-12 21:39:41 -08:00
InitEnemyMon: ; 3dabd
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld hl, wOTPartyMon1Species
call GetPartyLocation
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonSpecies
2015-11-06 06:04:27 -08:00
ld bc, MON_ID
call CopyBytes
ld bc, MON_DVS - MON_ID
add hl, bc
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonDVs
ld bc, MON_PKRUS - MON_DVS
call CopyBytes
inc hl
inc hl
inc hl
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonLevel
ld bc, PARTYMON_STRUCT_LENGTH - MON_LEVEL
call CopyBytes
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonSpecies]
ld [wCurSpecies], a
call GetBaseData
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMonNicknames
ld a, [wCurPartyMon]
call SkipNames
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonNick
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
call CopyBytes
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonAttack
ld de, wEnemyStats
ld bc, PARTYMON_STRUCT_LENGTH - MON_ATK
call CopyBytes
2015-11-07 18:04:54 -08:00
call ApplyStatusEffectOnEnemyStats
2018-01-23 14:39:09 -08:00
ld hl, wBaseType1
ld de, wEnemyMonType1
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
2018-01-23 14:39:09 -08:00
ld hl, wBaseStats
ld de, wEnemyMonBaseStats
ld b, 5
2016-01-12 21:39:41 -08:00
.loop
ld a, [hli]
ld [de], a
inc de
dec b
2016-01-12 21:39:41 -08:00
jr nz, .loop
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld [wCurOTMon], a
ret
; 3db32
2015-11-07 06:48:32 -08:00
SwitchPlayerMon: ; 3db32
call ClearSprites
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wLastPlayerMon], a
ld a, [wCurPartyMon]
ld [wCurBattleMon], a
2015-11-07 18:04:54 -08:00
call AddBattleParticipant
2015-11-06 13:42:38 -08:00
call InitBattleMon
call ResetPlayerStatLevels
call NewBattleMonStatus
call BreakAttraction
2015-11-07 06:48:32 -08:00
call SendOutPlayerMon
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
ret
; 3db5f
2015-11-07 06:48:32 -08:00
SendOutPlayerMon: ; 3db5f
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonDVs
predef GetUnownLetter
hlcoord 1, 5
ld b, 7
ld c, 8
call ClearBox
call WaitBGMap
xor a
ld [hBGMapMode], a
call GetBattleMonBackpic
xor a
2016-01-12 09:46:18 -08:00
ld [hGraphicStartTile], a
2017-12-09 16:41:03 -08:00
ld [wBattleMenuCursorBuffer], a
2018-01-23 14:39:09 -08:00
ld [wCurMoveNum], a
ld [wTypeModifier], a
ld [wPlayerMoveStruct + MOVE_ANIM], a
2018-01-23 14:39:09 -08:00
ld [wLastPlayerCounterMove], a
ld [wLastEnemyCounterMove], a
ld [wLastPlayerMove], a
call CheckAmuletCoin
2015-11-09 13:41:09 -08:00
call FinishBattleAnim
xor a
2015-11-08 10:27:26 -08:00
ld [wEnemyWrapCount], a
call SetPlayerTurn
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
2015-12-23 17:46:23 -08:00
ld [wBattleAnimParam], a
ld de, ANIM_SEND_OUT_MON
2015-09-09 16:27:07 -07:00
call Call_PlayBattleAnim
2015-11-06 13:42:38 -08:00
call BattleCheckPlayerShininess
2015-11-07 06:48:32 -08:00
jr nc, .not_shiny
2015-12-23 17:46:23 -08:00
ld a, 1
ld [wBattleAnimParam], a
ld de, ANIM_SEND_OUT_MON
2015-09-09 16:27:07 -07:00
call Call_PlayBattleAnim
2015-11-07 06:48:32 -08:00
.not_shiny
ld a, MON_SPECIES
call GetPartyParamLocation
ld b, h
ld c, l
2017-12-24 09:47:30 -08:00
farcall CheckFaintedFrzSlp
2015-11-07 06:48:32 -08:00
jr c, .statused
ld a, $f0
2018-01-23 14:39:09 -08:00
ld [wCryTracks], a
ld a, [wCurPartySpecies]
2014-07-18 10:25:03 -07:00
call PlayStereoCry
2015-11-07 06:48:32 -08:00
.statused
call UpdatePlayerHUD
ld a, $1
ld [hBGMapMode], a
ret
; 3dbde
NewBattleMonStatus: ; 3dbde
xor a
2018-01-23 14:39:09 -08:00
ld [wLastPlayerCounterMove], a
ld [wLastEnemyCounterMove], a
ld [wLastPlayerMove], a
ld hl, wPlayerSubStatus1
2015-07-20 19:18:18 -07:00
rept 4
ld [hli], a
2015-07-20 19:18:18 -07:00
endr
ld [hl], a
2018-01-23 14:39:09 -08:00
ld hl, wPlayerUsedMoves
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
2018-01-23 14:39:09 -08:00
ld [wPlayerDisableCount], a
ld [wPlayerFuryCutterCount], a
ld [wPlayerProtectCount], a
2015-11-05 16:13:09 -08:00
ld [wPlayerRageCounter], a
2018-01-23 14:39:09 -08:00
ld [wDisabledMove], a
ld [wPlayerMinimized], a
2015-11-08 10:27:26 -08:00
ld [wEnemyWrapCount], a
ld [wPlayerWrapCount], a
2018-01-23 14:39:09 -08:00
ld [wPlayerTurnsTaken], a
ld hl, wEnemySubStatus5
res SUBSTATUS_CANT_RUN, [hl]
ret
; 3dc18
BreakAttraction: ; 3dc18
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus1
res SUBSTATUS_IN_LOVE, [hl]
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus1
res SUBSTATUS_IN_LOVE, [hl]
ret
; 3dc23
SpikesDamage: ; 3dc23
2018-01-23 14:39:09 -08:00
ld hl, wPlayerScreens
ld de, wBattleMonType
ld bc, UpdatePlayerHUD
ld a, [hBattleTurn]
and a
jr z, .ok
2018-01-23 14:39:09 -08:00
ld hl, wEnemyScreens
ld de, wEnemyMonType
ld bc, UpdateEnemyHUD
.ok
bit SCREENS_SPIKES, [hl]
ret z
; Flying-types aren't affected by Spikes.
ld a, [de]
cp FLYING
ret z
inc de
ld a, [de]
cp FLYING
ret z
push bc
2015-09-09 16:27:07 -07:00
ld hl, BattleText_UserHurtBySpikes ; "hurt by SPIKES!"
call StdBattleTextBox
call GetEighthMaxHP
2015-11-06 17:55:16 -08:00
call SubtractHPFromTarget
pop hl
call .hl
jp WaitBGMap
.hl
jp hl
; 3dc5b
2015-11-05 16:13:09 -08:00
PursuitSwitch: ; 3dc5b
ld a, BATTLE_VARS_MOVE
call GetBattleVar
ld b, a
2013-12-30 20:32:37 -08:00
call GetMoveEffect
ld a, b
cp EFFECT_PURSUIT
2015-11-05 16:13:09 -08:00
jr nz, .done
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
push af
ld hl, DoPlayerTurn
ld a, [hBattleTurn]
and a
2015-11-05 16:13:09 -08:00
jr z, .do_turn
ld hl, DoEnemyTurn
2018-01-23 14:39:09 -08:00
ld a, [wLastPlayerMon]
ld [wCurBattleMon], a
2015-11-05 16:13:09 -08:00
.do_turn
ld a, BANK(DoPlayerTurn)
rst FarCall
ld a, BATTLE_VARS_MOVE
call GetBattleVarAddr
ld a, $ff
ld [hl], a
pop af
2018-01-23 14:39:09 -08:00
ld [wCurBattleMon], a
ld a, [hBattleTurn]
and a
2015-11-05 16:13:09 -08:00
jr z, .check_enemy_fainted
2018-01-23 14:39:09 -08:00
ld a, [wLastPlayerMon]
2015-07-20 22:52:46 -07:00
call UpdateBattleMon
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
2015-11-05 16:13:09 -08:00
jr nz, .done
ld a, $f0
2018-01-23 14:39:09 -08:00
ld [wCryTracks], a
ld a, [wBattleMonSpecies]
2014-07-18 10:25:03 -07:00
call PlayStereoCry
2018-01-23 14:39:09 -08:00
ld a, [wLastPlayerMon]
ld c, a
2015-11-07 18:04:54 -08:00
ld hl, wBattleParticipantsNotFainted
ld b, RESET_FLAG
predef SmallFarFlagAction
2015-10-19 13:49:29 -07:00
call PlayerMonFaintedAnimation
ld hl, BattleText_MonFainted
2015-11-05 16:13:09 -08:00
jr .done_fainted
2015-11-05 16:13:09 -08:00
.check_enemy_fainted
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
2015-11-05 16:13:09 -08:00
jr nz, .done
ld de, SFX_KINESIS
call PlaySFX
call WaitSFX
ld de, SFX_FAINT
call PlaySFX
call WaitSFX
2015-10-19 13:49:29 -07:00
call EnemyMonFaintedAnimation
ld hl, BattleText_EnemyMonFainted
2015-11-05 16:13:09 -08:00
.done_fainted
call StdBattleTextBox
scf
ret
2015-11-05 16:13:09 -08:00
.done
and a
ret
; 3dce6
2016-01-12 21:39:41 -08:00
RecallPlayerMon: ; 3dce6
ld a, [hBattleTurn]
push af
xor a
ld [hBattleTurn], a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
ld de, ANIM_RETURN_MON
2015-09-09 16:27:07 -07:00
call Call_PlayBattleAnim
pop af
ld [hBattleTurn], a
ret
; 3dcf9
2015-11-08 10:27:26 -08:00
HandleHealingItems: ; 3dcf9
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-06 06:04:27 -08:00
jr z, .player_1
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
call HandleHPHealingItem
2015-11-06 19:36:06 -08:00
call UseHeldStatusHealingItem
call UseConfusionHealingItem
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
call HandleHPHealingItem
2015-11-06 19:36:06 -08:00
call UseHeldStatusHealingItem
jp UseConfusionHealingItem
2015-11-06 06:04:27 -08:00
.player_1
call SetEnemyTurn
2015-11-08 10:27:26 -08:00
call HandleHPHealingItem
2015-11-06 19:36:06 -08:00
call UseHeldStatusHealingItem
call UseConfusionHealingItem
call SetPlayerTurn
2015-11-08 10:27:26 -08:00
call HandleHPHealingItem
2015-11-06 19:36:06 -08:00
call UseHeldStatusHealingItem
jp UseConfusionHealingItem
; 3dd2f
2015-11-08 10:27:26 -08:00
HandleHPHealingItem: ; 3dd2f
2017-12-24 09:47:30 -08:00
callfar GetOpponentItem
ld a, b
cp HELD_BERRY
ret nz
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonHP + 1
ld hl, wEnemyMonMaxHP
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr z, .go
2018-01-23 14:39:09 -08:00
ld de, wBattleMonHP + 1
ld hl, wBattleMonMaxHP
2015-11-08 10:27:26 -08:00
.go
2016-03-01 19:31:21 -08:00
; If, and only if, Pokemon's HP is less than half max, use the item.
; Store current HP in Buffer 3/4
push bc
ld a, [de]
2018-01-23 14:39:09 -08:00
ld [wBuffer3], a
add a
ld c, a
dec de
ld a, [de]
inc de
2018-01-23 14:39:09 -08:00
ld [wBuffer4], a
adc a
ld b, a
ld a, b
cp [hl]
ld a, c
pop bc
2015-11-08 10:27:26 -08:00
jr z, .equal
jr c, .less
ret
2015-11-08 10:27:26 -08:00
.equal
inc hl
cp [hl]
dec hl
ret nc
2015-11-08 10:27:26 -08:00
.less
2015-11-06 19:36:06 -08:00
call ItemRecoveryAnim
2018-01-23 14:39:09 -08:00
; store max HP in wBuffer1/2
ld a, [hli]
2018-01-23 14:39:09 -08:00
ld [wBuffer2], a
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBuffer1], a
ld a, [de]
add c
2018-01-23 14:39:09 -08:00
ld [wBuffer5], a
ld c, a
dec de
ld a, [de]
2018-02-04 10:16:40 -08:00
adc 0
2018-01-23 14:39:09 -08:00
ld [wBuffer6], a
ld b, a
ld a, [hld]
cp c
ld a, [hl]
sbc b
2015-11-08 10:27:26 -08:00
jr nc, .okay
ld a, [hli]
2018-01-23 14:39:09 -08:00
ld [wBuffer6], a
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBuffer5], a
2015-11-08 10:27:26 -08:00
.okay
2018-01-23 14:39:09 -08:00
ld a, [wBuffer6]
ld [de], a
inc de
2018-01-23 14:39:09 -08:00
ld a, [wBuffer5]
ld [de], a
ld a, [hBattleTurn]
ld [wWhichHPBar], a
and a
hlcoord 2, 2
2015-11-08 10:27:26 -08:00
jr z, .got_hp_bar_coords
hlcoord 10, 9
2015-11-08 10:27:26 -08:00
.got_hp_bar_coords
ld [wWhichHPBar], a
predef AnimateHPBar
2015-11-06 19:36:06 -08:00
UseOpponentItem:
call RefreshBattleHuds
2017-12-24 09:47:30 -08:00
callfar GetOpponentItem
ld a, [hl]
ld [wNamedObjectIndexBuffer], a
call GetItemName
2017-12-24 09:47:30 -08:00
callfar ConsumeHeldItem
ld hl, RecoveredUsingText
jp StdBattleTextBox
; 3ddc8
2015-11-06 19:36:06 -08:00
ItemRecoveryAnim: ; 3ddc8
push hl
push de
push bc
call EmptyBattleTextBox
ld a, RECOVER
2018-01-23 14:39:09 -08:00
ld [wFXAnimID], a
call SwitchTurnCore
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
2018-01-23 14:39:09 -08:00
ld [wFXAnimID + 1], a
predef PlayBattleAnim
call SwitchTurnCore
pop bc
pop de
pop hl
ret
; 3dde9
2015-11-06 19:36:06 -08:00
UseHeldStatusHealingItem: ; 3dde9
2017-12-24 09:47:30 -08:00
callfar GetOpponentItem
2018-01-25 18:34:42 -08:00
ld hl, HeldStatusHealingEffects
2015-11-06 19:36:06 -08:00
.loop
ld a, [hli]
cp $ff
ret z
inc hl
cp b
2015-11-06 19:36:06 -08:00
jr nz, .loop
dec hl
ld b, [hl]
ld a, BATTLE_VARS_STATUS_OPP
call GetBattleVarAddr
and b
ret z
xor a
ld [hl], a
push bc
call UpdateOpponentInParty
pop bc
ld a, BATTLE_VARS_SUBSTATUS5_OPP
call GetBattleVarAddr
and [hl]
res SUBSTATUS_TOXIC, [hl]
ld a, BATTLE_VARS_SUBSTATUS1_OPP
call GetBattleVarAddr
and [hl]
res SUBSTATUS_NIGHTMARE, [hl]
ld a, b
2015-11-08 10:27:26 -08:00
cp ALL_STATUS
2015-11-06 19:36:06 -08:00
jr nz, .skip_confuse
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVarAddr
res SUBSTATUS_CONFUSED, [hl]
2015-11-06 19:36:06 -08:00
.skip_confuse
2015-11-06 17:55:16 -08:00
ld hl, CalcEnemyStats
ld a, [hBattleTurn]
and a
2015-11-06 19:36:06 -08:00
jr z, .got_pointer
2015-11-06 17:55:16 -08:00
ld hl, CalcPlayerStats
2015-11-06 19:36:06 -08:00
.got_pointer
call SwitchTurnCore
2015-11-06 17:55:16 -08:00
ld a, BANK(CalcEnemyStats)
rst FarCall
call SwitchTurnCore
2015-11-06 19:36:06 -08:00
call ItemRecoveryAnim
call UseOpponentItem
ld a, $1
and a
ret
; 3de44
2018-01-25 18:34:42 -08:00
INCLUDE "data/battle/held_heal_status.asm"
UseConfusionHealingItem: ; 3de51
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVar
bit SUBSTATUS_CONFUSED, a
ret z
2017-12-24 09:47:30 -08:00
callfar GetOpponentItem
ld a, b
cp HELD_HEAL_CONFUSION
2015-11-08 10:27:26 -08:00
jr z, .heal_status
cp HELD_HEAL_STATUS
ret nz
2015-11-08 10:27:26 -08:00
.heal_status
ld a, [hl]
ld [wd265], a
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call GetBattleVarAddr
res SUBSTATUS_CONFUSED, [hl]
call GetItemName
2015-11-06 19:36:06 -08:00
call ItemRecoveryAnim
ld hl, BattleText_ItemHealedConfusion
call StdBattleTextBox
ld a, [hBattleTurn]
and a
2015-11-08 10:27:26 -08:00
jr nz, .do_partymon
call GetOTPartymonItem
xor a
ld [bc], a
ld a, [wBattleMode]
dec a
ret z
ld [hl], $0
ret
2015-11-08 10:27:26 -08:00
.do_partymon
call GetPartymonItem
xor a
ld [bc], a
ld [hl], a
ret
; 3de97
2015-11-08 10:27:26 -08:00
HandleStatBoostingHeldItems: ; 3de97
; The effects handled here are not used in-game.
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-06 06:04:27 -08:00
jr z, .player_1
2015-11-08 10:27:26 -08:00
call .DoPlayer
jp .DoEnemy
.player_1
call .DoEnemy
jp .DoPlayer
; 3dea9
.DoPlayer: ; 3dea9
2015-11-08 10:27:26 -08:00
call GetPartymonItem
ld a, $0
2015-11-08 10:27:26 -08:00
jp .HandleItem
; 3deb1
.DoEnemy: ; 3deb1
2015-11-08 10:27:26 -08:00
call GetOTPartymonItem
ld a, $1
2015-11-08 10:27:26 -08:00
.HandleItem: ; 3deb6
ld [hBattleTurn], a
ld d, h
ld e, l
push de
push bc
ld a, [bc]
ld b, a
2017-12-24 09:47:30 -08:00
callfar GetItemHeldEffect
2018-01-25 18:34:42 -08:00
ld hl, HeldStatUpItems
2015-11-08 10:27:26 -08:00
.loop
ld a, [hli]
2018-01-25 18:34:42 -08:00
cp -1
2015-11-08 10:27:26 -08:00
jr z, .finish
inc hl
2015-12-26 18:59:03 -08:00
inc hl
cp b
2015-11-08 10:27:26 -08:00
jr nz, .loop
pop bc
ld a, [bc]
ld [wd265], a
push bc
dec hl
2015-12-26 18:59:03 -08:00
dec hl
ld a, [hli]
ld h, [hl]
ld l, a
ld a, BANK(BattleCommand_AttackUp)
rst FarCall
pop bc
pop de
2018-01-23 14:39:09 -08:00
ld a, [wFailedMessage]
and a
ret nz
xor a
ld [bc], a
ld [de], a
call GetItemName
2015-09-09 16:27:07 -07:00
ld hl, BattleText_UsersStringBuffer1Activated
call StdBattleTextBox
2017-12-24 09:47:30 -08:00
callfar BattleCommand_StatUpMessage
ret
2015-11-08 10:27:26 -08:00
.finish
pop bc
pop de
ret
; 3defc
2018-01-25 18:34:42 -08:00
INCLUDE "data/battle/held_stat_up.asm"
2015-11-08 10:27:26 -08:00
GetPartymonItem: ; 3df12
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1Item
ld a, [wCurBattleMon]
call GetPartyLocation
2018-01-23 14:39:09 -08:00
ld bc, wBattleMonItem
ret
; 3df1f
2015-11-08 10:27:26 -08:00
GetOTPartymonItem: ; 3df1f
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1Item
ld a, [wCurOTMon]
call GetPartyLocation
2018-01-23 14:39:09 -08:00
ld bc, wEnemyMonItem
ret
; 3df2c
2015-11-08 10:27:26 -08:00
UpdateBattleHUDs: ; 3df2c
push hl
push de
push bc
call DrawPlayerHUD
2018-01-23 14:39:09 -08:00
ld hl, wPlayerHPPal
call SetHPPal
call CheckDanger
call DrawEnemyHUD
2018-01-23 14:39:09 -08:00
ld hl, wEnemyHPPal
call SetHPPal
pop bc
pop de
pop hl
ret
; 3df48
UpdatePlayerHUD:: ; 3df48
push hl
push de
push bc
call DrawPlayerHUD
call UpdatePlayerHPPal
call CheckDanger
pop bc
pop de
pop hl
ret
; 3df58
DrawPlayerHUD: ; 3df58
xor a
ld [hBGMapMode], a
; Clear the area
hlcoord 9, 7
lb bc, 5, 11
call ClearBox
2017-12-24 09:47:30 -08:00
farcall DrawPlayerHUDBorder
hlcoord 18, 9
ld [hl], $73 ; vertical bar
call PrintPlayerHUD
; HP bar
hlcoord 10, 9
ld b, 1
xor a ; PARTYMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
predef DrawPlayerHP
; Exp bar
push de
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld hl, wPartyMon1Exp + 2
call GetPartyLocation
ld d, h
ld e, l
hlcoord 10, 11
2018-01-23 14:39:09 -08:00
ld a, [wTempMonLevel]
ld b, a
call FillInExpBar
pop de
ret
; 3df98
UpdatePlayerHPPal: ; 3df98
2018-01-23 14:39:09 -08:00
ld hl, wPlayerHPPal
2015-11-23 13:04:53 -08:00
jp UpdateHPPal
; 3df9e
CheckDanger: ; 3df9e
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
jr z, .no_danger
ld a, [wBattleLowHealthAlarm]
and a
jr nz, .done
2018-01-23 14:39:09 -08:00
ld a, [wPlayerHPPal]
cp HP_RED
jr z, .danger
.no_danger
ld hl, wLowHealthAlarm
res DANGER_ON_F, [hl]
jr .done
.danger
ld hl, wLowHealthAlarm
set DANGER_ON_F, [hl]
.done
ret
; 3dfbf
PrintPlayerHUD: ; 3dfbf
2018-01-23 14:39:09 -08:00
ld de, wBattleMonNick
hlcoord 10, 7
2015-11-23 13:04:53 -08:00
call ret_3e138
call PlaceString
push bc
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld hl, wPartyMon1DVs
call GetPartyLocation
2018-01-23 14:39:09 -08:00
ld de, wTempMonDVs
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonLevel
ld de, wTempMonLevel
2018-01-09 12:39:48 -08:00
ld bc, $11
call CopyBytes
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld hl, wPartyMon1Species
call GetPartyLocation
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wCurPartySpecies], a
ld [wCurSpecies], a
call GetBaseData
pop hl
dec hl
2016-05-11 14:16:03 -07:00
ld a, TEMPMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
callfar GetGender
ld a, " "
2016-01-17 21:39:01 -08:00
jr c, .got_gender_char
ld a, "♂"
2016-01-17 21:39:01 -08:00
jr nz, .got_gender_char
ld a, "♀"
2016-01-17 21:39:01 -08:00
.got_gender_char
hlcoord 17, 8
ld [hl], a
hlcoord 14, 8
2016-01-17 21:39:01 -08:00
push af ; back up gender
push hl
2018-01-23 14:39:09 -08:00
ld de, wBattleMonStatus
predef PlaceNonFaintStatus
pop hl
pop bc
ret nz
ld a, b
cp " "
2016-01-17 21:39:01 -08:00
jr nz, .copy_level ; male or female
dec hl ; genderless
2016-01-17 21:39:01 -08:00
.copy_level
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonLevel]
ld [wTempMonLevel], a
jp PrintLevel
; 3e036
UpdateEnemyHUD:: ; 3e036
push hl
push de
push bc
call DrawEnemyHUD
call UpdateEnemyHPPal
pop bc
pop de
pop hl
ret
; 3e043
DrawEnemyHUD: ; 3e043
xor a
ld [hBGMapMode], a
hlcoord 1, 0
lb bc, 4, 11
call ClearBox
2017-12-24 09:47:30 -08:00
farcall DrawEnemyHUDBorder
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld [wCurSpecies], a
ld [wCurPartySpecies], a
call GetBaseData
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonNick
hlcoord 1, 0
2015-11-23 13:04:53 -08:00
call ret_3e138
call PlaceString
ld h, b
ld l, c
dec hl
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonDVs
ld de, wTempMonDVs
ld a, [wEnemySubStatus5]
bit SUBSTATUS_TRANSFORMED, a
jr z, .ok
2016-01-10 14:44:09 -08:00
ld hl, wEnemyBackupDVs
.ok
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
2016-05-11 14:16:03 -07:00
ld a, TEMPMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
callfar GetGender
ld a, " "
2015-11-23 13:04:53 -08:00
jr c, .got_gender
ld a, "♂"
2015-11-23 13:04:53 -08:00
jr nz, .got_gender
ld a, "♀"
2015-11-23 13:04:53 -08:00
.got_gender
hlcoord 9, 1
ld [hl], a
hlcoord 6, 1
push af
push hl
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonStatus
predef PlaceNonFaintStatus
pop hl
pop bc
2015-11-23 13:04:53 -08:00
jr nz, .skip_level
ld a, b
cp " "
2015-11-23 13:04:53 -08:00
jr nz, .print_level
dec hl
2015-11-23 13:04:53 -08:00
.print_level
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonLevel]
ld [wTempMonLevel], a
call PrintLevel
2015-11-23 13:04:53 -08:00
.skip_level
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
ld [hMultiplicand + 1], a
ld a, [hld]
ld [hMultiplicand + 2], a
or [hl]
2015-11-23 13:04:53 -08:00
jr nz, .not_fainted
ld c, a
ld e, a
ld d, HP_BAR_LENGTH
2015-11-23 13:04:53 -08:00
jp .draw_bar
2015-11-23 13:04:53 -08:00
.not_fainted
xor a
ld [hMultiplicand], a
ld a, HP_BAR_LENGTH_PX
ld [hMultiplier], a
call Multiply
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld b, a
ld a, [hl]
ld [hMultiplier], a
ld a, b
and a
2015-11-23 13:04:53 -08:00
jr z, .less_than_256_max
ld a, [hMultiplier]
srl b
rr a
srl b
rr a
ld [hDivisor], a
ld a, [hProduct + 2]
ld b, a
srl b
ld a, [hProduct + 3]
rr a
srl b
rr a
ld [hProduct + 3], a
ld a, b
ld [hProduct + 2], a
2015-11-23 13:04:53 -08:00
.less_than_256_max
ld a, [hProduct + 2]
ld [hDividend + 0], a
ld a, [hProduct + 3]
ld [hDividend + 1], a
2015-11-23 13:04:53 -08:00
ld a, 2
ld b, a
call Divide
ld a, [hQuotient + 2]
ld e, a
ld a, HP_BAR_LENGTH
ld d, a
ld c, a
2015-11-23 13:04:53 -08:00
.draw_bar
xor a
ld [wWhichHPBar], a
hlcoord 2, 2
ld b, 0
2015-11-08 07:59:28 -08:00
call DrawBattleHPBar
ret
; 3e127
UpdateEnemyHPPal: ; 3e127
2018-01-23 14:39:09 -08:00
ld hl, wEnemyHPPal
2015-11-23 13:04:53 -08:00
call UpdateHPPal
ret
; 3e12e
2015-11-23 13:04:53 -08:00
UpdateHPPal: ; 3e12e
ld b, [hl]
call SetHPPal
ld a, [hl]
cp b
ret z
2015-11-09 13:41:09 -08:00
jp FinishBattleAnim
; 3e138
2015-11-23 13:04:53 -08:00
ret_3e138: ; 3e138
ret
; 3e139
BattleMenu: ; 3e139
xor a
ld [hBGMapMode], a
2015-09-09 16:27:07 -07:00
call LoadTempTileMapToTileMap
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
2015-09-09 16:27:07 -07:00
cp BATTLETYPE_DEBUG
jr z, .ok
cp BATTLETYPE_TUTORIAL
jr z, .ok
call EmptyBattleTextBox
call UpdateBattleHuds
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
.ok
.loop
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_CONTEST
jr nz, .not_contest
2017-12-24 09:47:30 -08:00
farcall ContestBattleMenu
jr .next
.not_contest
; Auto input: choose "ITEM"
2018-01-23 14:39:09 -08:00
ld a, [wInputType]
or a
jr z, .skip_dude_pack_select
2017-12-24 09:47:30 -08:00
farcall _DudeAutoInput_DownA
.skip_dude_pack_select
call LoadBattleMenu2
ret c
.next
ld a, $1
ld [hBGMapMode], a
2017-12-09 16:41:03 -08:00
ld a, [wBattleMenuCursorBuffer]
cp $1
jp z, BattleMenu_Fight
cp $3
jp z, BattleMenu_Pack
cp $2
jp z, BattleMenu_PKMN
cp $4
jp z, BattleMenu_Run
jr .loop
; 3e192
BattleMenu_Fight: ; 3e192
xor a
2015-11-23 13:04:53 -08:00
ld [wNumFleeAttempts], a
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
and a
ret
; 3e19b
LoadBattleMenu2: ; 3e19b
call IsMobileBattle
jr z, .mobile
2017-12-24 09:47:30 -08:00
farcall LoadBattleMenu
and a
ret
.mobile
2017-12-24 09:47:30 -08:00
farcall Function100b12
ld a, [wcd2b]
and a
ret z
ld hl, wcd2a
bit 4, [hl]
jr nz, .error
2015-08-24 16:56:30 -07:00
ld hl, BattleText_LinkErrorBattleCanceled
call StdBattleTextBox
ld c, 60
call DelayFrames
.error
scf
ret
; 3e1c7
BattleMenu_Pack: ; 3e1c7
ld a, [wLinkMode]
and a
jp nz, .ItemsCantBeUsed
2018-01-23 14:39:09 -08:00
ld a, [wInBattleTowerBattle]
and a
jp nz, .ItemsCantBeUsed
call LoadStandardMenuHeader
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_TUTORIAL
jr z, .tutorial
cp BATTLETYPE_CONTEST
jr z, .contest
2017-12-24 09:47:30 -08:00
farcall BattlePack
ld a, [wBattlePlayerAction]
and a
jr z, .didnt_use_item
jr .got_item
.tutorial
2017-12-24 09:47:30 -08:00
farcall TutorialPack
ld a, POKE_BALL
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
call DoItemEffect
jr .got_item
.contest
ld a, PARK_BALL
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
call DoItemEffect
.got_item
call .UseItem
ret
.didnt_use_item
call ClearPalettes
call DelayFrame
2015-11-10 16:51:13 -08:00
call _LoadBattleFontsHPBar
call GetBattleMonBackpic
call GetEnemyMonFrontpic
call ExitMenu
call WaitBGMap
2015-11-09 13:41:09 -08:00
call FinishBattleAnim
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
jp BattleMenu
; 3e22b
.ItemsCantBeUsed: ; 3e22b
2015-09-09 16:27:07 -07:00
ld hl, BattleText_ItemsCantBeUsedHere
call StdBattleTextBox
jp BattleMenu
; 3e234
.UseItem: ; 3e234
2015-12-07 08:28:58 -08:00
ld a, [wWildMon]
and a
jr nz, .run
2017-12-24 09:47:30 -08:00
callfar CheckItemPocket
2015-10-24 07:34:19 -07:00
ld a, [wItemAttributeParamBuffer]
cp BALL
jr z, .ball
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
.ball
xor a
ld [hBGMapMode], a
2015-11-10 16:51:13 -08:00
call _LoadBattleFontsHPBar
call ClearSprites
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_TUTORIAL
jr z, .tutorial2
call GetBattleMonBackpic
.tutorial2
call GetEnemyMonFrontpic
ld a, $1
2015-12-15 15:59:49 -08:00
ld [wMenuCursorY], a
call ExitMenu
2015-11-08 10:27:26 -08:00
call UpdateBattleHUDs
call WaitBGMap
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
call ClearWindowData
2015-11-09 13:41:09 -08:00
call FinishBattleAnim
and a
ret
.run
xor a
2015-12-07 08:28:58 -08:00
ld [wWildMon], a
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
and BATTLERESULT_BITMASK
ld [wBattleResult], a ; WIN
call ClearWindowData
2015-09-09 16:27:07 -07:00
call SetPalettes
scf
ret
; 3e28d
BattleMenu_PKMN: ; 3e28d
call LoadStandardMenuHeader
2016-01-12 21:39:41 -08:00
BattleMenuPKMN_ReturnFromStats:
call ExitMenu
call LoadStandardMenuHeader
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
BattleMenuPKMN_Loop:
call SetUpBattlePartyMenu
xor a
2018-01-23 14:39:09 -08:00
ld [wPartyMenuActionText], a
2016-01-12 21:39:41 -08:00
call JumpToPartyMenuAndPrintText
call SelectBattleMon
jr c, .Cancel
.loop
2017-12-24 09:47:30 -08:00
farcall FreezeMonIcons
call .GetMenu
jr c, .PressedB
2015-12-17 19:31:16 -08:00
call PlaceHollowCursor
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
cp $1 ; SWITCH
jp z, TryPlayerSwitch
cp $2 ; STATS
jr z, .Stats
cp $3 ; CANCEL
jr z, .Cancel
jr .loop
.PressedB:
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
jr c, .Cancel
jr BattleMenuPKMN_Loop
.Stats:
2015-12-23 06:12:29 -08:00
call Battle_StatsScreen
2015-11-08 16:09:36 -08:00
call CheckMobileBattleError
jr c, .Cancel
2016-01-12 21:39:41 -08:00
jp BattleMenuPKMN_ReturnFromStats
.Cancel:
call ClearSprites
call ClearPalettes
call DelayFrame
2015-11-10 16:51:13 -08:00
call _LoadHPBar
call CloseWindow
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-11-20 12:15:32 -08:00
call GetMemSGBLayout
2015-09-09 16:27:07 -07:00
call SetPalettes
jp BattleMenu
; 3e2f5
.GetMenu: ; 3e2f5
call IsMobileBattle
jr z, .mobile
2017-12-24 09:47:30 -08:00
farcall BattleMonMenu
ret
.mobile
2017-12-24 09:47:30 -08:00
farcall MobileBattleMonMenu
ret
; 3e308
2015-12-23 06:12:29 -08:00
Battle_StatsScreen: ; 3e308
call DisableLCD
2016-06-07 05:08:51 -07:00
2017-12-28 04:32:33 -08:00
ld hl, vTiles2 tile $31
ld de, vTiles0
2016-06-07 05:08:51 -07:00
ld bc, $11 tiles
call CopyBytes
2016-06-07 05:08:51 -07:00
2017-12-28 04:32:33 -08:00
ld hl, vTiles2
ld de, vTiles0 tile $11
ld bc, $31 tiles
call CopyBytes
2016-06-07 05:08:51 -07:00
call EnableLCD
2016-06-07 05:08:51 -07:00
call ClearSprites
call LowVolume
xor a ; PARTYMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
2017-12-24 09:47:30 -08:00
farcall BattleStatsScreenInit
call MaxVolume
2016-06-07 05:08:51 -07:00
call DisableLCD
2016-06-07 05:08:51 -07:00
2017-12-28 04:32:33 -08:00
ld hl, vTiles0
ld de, vTiles2 tile $31
ld bc, $11 tiles
call CopyBytes
2016-06-07 05:08:51 -07:00
2017-12-28 04:32:33 -08:00
ld hl, vTiles0 tile $11
ld de, vTiles2
ld bc, $31 tiles
call CopyBytes
2016-06-07 05:08:51 -07:00
call EnableLCD
ret
; 3e358
TryPlayerSwitch: ; 3e358
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
cp d
jr nz, .check_trapped
ld hl, BattleText_MonIsAlreadyOut
call StdBattleTextBox
jp BattleMenuPKMN_Loop
.check_trapped
2015-11-08 10:27:26 -08:00
ld a, [wPlayerWrapCount]
and a
jr nz, .trapped
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus5]
bit SUBSTATUS_CANT_RUN, a
jr z, .try_switch
.trapped
ld hl, BattleText_MonCantBeRecalled
call StdBattleTextBox
jp BattleMenuPKMN_Loop
.try_switch
2016-03-01 19:31:21 -08:00
call CheckIfCurPartyMonIsFitToFight
jp z, BattleMenuPKMN_Loop
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wLastPlayerMon], a
ld a, $2
ld [wBattlePlayerAction], a
call ClearPalettes
call DelayFrame
call ClearSprites
2015-11-10 16:51:13 -08:00
call _LoadHPBar
call CloseWindow
2015-11-20 12:15:32 -08:00
call GetMemSGBLayout
2015-09-09 16:27:07 -07:00
call SetPalettes
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld [wCurBattleMon], a
2015-11-07 18:04:54 -08:00
PlayerSwitch: ; 3e3ad
ld a, 1
ld [wPlayerIsSwitching], a
ld a, [wLinkMode]
and a
2015-11-07 18:04:54 -08:00
jr z, .not_linked
call LoadStandardMenuHeader
2015-11-23 13:04:53 -08:00
call LinkBattleSendReceiveAction
call CloseWindow
2015-11-07 18:04:54 -08:00
.not_linked
2015-11-08 16:09:36 -08:00
call ParseEnemyAction
ld a, [wLinkMode]
and a
2015-11-07 18:04:54 -08:00
jr nz, .linked
2015-11-06 06:04:27 -08:00
.switch
call BattleMonEntrance
and a
ret
2015-11-07 18:04:54 -08:00
.linked
ld a, [wBattleAction]
2015-11-06 06:04:27 -08:00
cp BATTLEACTION_E
jp z, .switch
cp BATTLEACTION_D
jp z, .switch
cp BATTLEACTION_SWITCH1
jp c, .switch
cp BATTLEACTION_FORFEIT
jr nz, .dont_run
call WildFled_EnemyFled_LinkBattleCanceled
ret
2015-11-06 06:04:27 -08:00
.dont_run
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
2015-11-06 06:04:27 -08:00
jr z, .player_1
call BattleMonEntrance
2015-11-06 06:04:27 -08:00
call EnemyMonEntrance
and a
ret
2015-11-06 06:04:27 -08:00
.player_1
call EnemyMonEntrance
call BattleMonEntrance
and a
ret
; 3e3ff
2015-11-06 06:04:27 -08:00
EnemyMonEntrance: ; 3e3ff
2017-12-24 09:47:30 -08:00
callfar AI_Switch
call SetEnemyTurn
jp SpikesDamage
; 3e40b
BattleMonEntrance: ; 3e40b
call WithdrawMonText
ld c, 50
call DelayFrames
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus4
res SUBSTATUS_RAGE, [hl]
call SetEnemyTurn
2015-11-05 16:13:09 -08:00
call PursuitSwitch
jr c, .ok
2016-01-12 21:39:41 -08:00
call RecallPlayerMon
.ok
hlcoord 9, 7
lb bc, 5, 11
call ClearBox
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wCurPartyMon], a
2015-11-07 18:04:54 -08:00
call AddBattleParticipant
2015-11-06 13:42:38 -08:00
call InitBattleMon
call ResetPlayerStatLevels
call SendOutMonText
call NewBattleMonStatus
call BreakAttraction
2015-11-07 06:48:32 -08:00
call SendOutPlayerMon
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
call SetPlayerTurn
call SpikesDamage
ld a, $2
2015-12-15 15:59:49 -08:00
ld [wMenuCursorY], a
ret
; 3e459
PassedBattleMonEntrance: ; 3e459
ld c, 50
call DelayFrames
hlcoord 9, 7
lb bc, 5, 11
call ClearBox
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld [wCurBattleMon], a
2015-11-07 18:04:54 -08:00
call AddBattleParticipant
2015-11-06 13:42:38 -08:00
call InitBattleMon
xor a
ld [wd265], a
2015-09-09 16:27:07 -07:00
call ApplyStatLevelMultiplierOnAllStats
2015-11-07 06:48:32 -08:00
call SendOutPlayerMon
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
call SetPlayerTurn
jp SpikesDamage
; 3e489
BattleMenu_Run: ; 3e489
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
ld a, $3
2015-12-15 15:59:49 -08:00
ld [wMenuCursorY], a
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonSpeed
ld de, wEnemyMonSpeed
2015-09-09 16:27:07 -07:00
call TryToRunAwayFromBattle
ld a, $0
2015-11-23 13:04:53 -08:00
ld [wFailedToFlee], a
ret c
ld a, [wBattlePlayerAction]
and a
ret nz
jp BattleMenu
; 3e4a8
CheckAmuletCoin: ; 3e4a8
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonItem]
ld b, a
2017-12-24 09:47:30 -08:00
callfar GetItemHeldEffect
ld a, b
cp HELD_AMULET_COIN
ret nz
ld a, 1
2015-11-22 21:21:21 -08:00
ld [wAmuletCoin], a
ret
; 3e4bc
2015-10-10 04:45:39 -07:00
MoveSelectionScreen: ; 3e4bc
call IsMobileBattle
2015-11-23 13:04:53 -08:00
jr nz, .not_mobile
2017-12-24 09:47:30 -08:00
farcall MobileMoveSelectionScreen
ret
2015-11-23 13:04:53 -08:00
.not_mobile
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMoves
2015-11-23 13:04:53 -08:00
ld a, [wMoveSelectionMenuType]
dec a
2015-11-23 13:04:53 -08:00
jr z, .got_menu_type
dec a
2015-11-23 13:04:53 -08:00
jr z, .ether_elixer_menu
call CheckPlayerHasUsableMoves
ret z ; use Struggle
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonMoves
2015-11-23 13:04:53 -08:00
jr .got_menu_type
2015-11-23 13:04:53 -08:00
.ether_elixer_menu
ld a, MON_MOVES
call GetPartyParamLocation
2015-11-23 13:04:53 -08:00
.got_menu_type
2015-10-17 14:18:52 -07:00
ld de, wListMoves_MoveIndicesBuffer
ld bc, NUM_MOVES
call CopyBytes
xor a
ld [hBGMapMode], a
hlcoord 4, 17 - NUM_MOVES - 1
ld b, 4
ld c, 14
2015-11-23 13:04:53 -08:00
ld a, [wMoveSelectionMenuType]
cp $2
2015-11-23 13:04:53 -08:00
jr nz, .got_dims
hlcoord 4, 17 - NUM_MOVES - 1 - 4
ld b, 4
ld c, 14
2015-11-23 13:04:53 -08:00
.got_dims
call TextBox
hlcoord 6, 17 - NUM_MOVES
2015-11-23 13:04:53 -08:00
ld a, [wMoveSelectionMenuType]
cp $2
2015-11-23 13:04:53 -08:00
jr nz, .got_start_coord
hlcoord 6, 17 - NUM_MOVES - 4
2015-11-23 13:04:53 -08:00
.got_start_coord
ld a, SCREEN_WIDTH
2018-01-23 14:39:09 -08:00
ld [wBuffer1], a
predef ListMoves
ld b, 5
2015-11-23 13:04:53 -08:00
ld a, [wMoveSelectionMenuType]
cp $2
ld a, 17 - NUM_MOVES
2015-11-23 13:04:53 -08:00
jr nz, .got_default_coord
ld b, 5
ld a, 17 - NUM_MOVES - 4
2015-11-23 13:04:53 -08:00
.got_default_coord
ld [w2DMenuCursorInitY], a
ld a, b
ld [w2DMenuCursorInitX], a
2015-11-23 13:04:53 -08:00
ld a, [wMoveSelectionMenuType]
cp $1
2015-11-23 13:04:53 -08:00
jr z, .skip_inc
2018-01-23 14:39:09 -08:00
ld a, [wCurMoveNum]
inc a
2015-11-23 13:04:53 -08:00
.skip_inc
2015-12-15 15:59:49 -08:00
ld [wMenuCursorY], a
ld a, $1
2015-12-15 15:59:49 -08:00
ld [wMenuCursorX], a
2015-12-04 05:46:11 -08:00
ld a, [wNumMoves]
inc a
ld [w2DMenuNumRows], a
ld a, $1
ld [w2DMenuNumCols], a
ld c, $2c
2015-11-23 13:04:53 -08:00
ld a, [wMoveSelectionMenuType]
dec a
2016-03-01 19:31:21 -08:00
ld b, D_DOWN | D_UP | A_BUTTON
2015-11-23 13:04:53 -08:00
jr z, .okay
dec a
2016-03-01 19:31:21 -08:00
ld b, D_DOWN | D_UP | A_BUTTON | B_BUTTON
2015-11-23 13:04:53 -08:00
jr z, .okay
ld a, [wLinkMode]
and a
2015-11-23 13:04:53 -08:00
jr nz, .okay
2016-03-01 19:31:21 -08:00
ld b, D_DOWN | D_UP | A_BUTTON | B_BUTTON | SELECT
2015-11-23 13:04:53 -08:00
.okay
ld a, b
ld [wMenuJoypadFilter], a
ld a, c
ld [w2DMenuFlags1], a
xor a
ld [w2DMenuFlags2], a
ld a, $10
2015-12-21 11:10:16 -08:00
ld [w2DMenuCursorOffsets], a
2015-11-23 13:04:53 -08:00
.menu_loop
ld a, [wMoveSelectionMenuType]
and a
2015-11-23 13:04:53 -08:00
jr z, .battle_player_moves
dec a
2015-11-23 13:04:53 -08:00
jr nz, .interpret_joypad
hlcoord 11, 14
ld de, .string_3e61c
call PlaceString
2015-11-23 13:04:53 -08:00
jr .interpret_joypad
2015-11-23 13:04:53 -08:00
.battle_player_moves
call MoveInfoBox
2015-11-23 13:04:53 -08:00
ld a, [wMoveSwapBuffer]
and a
2015-11-23 13:04:53 -08:00
jr z, .interpret_joypad
hlcoord 5, 13
ld bc, SCREEN_WIDTH
dec a
call AddNTimes
ld [hl], "▷"
2015-11-23 13:04:53 -08:00
.interpret_joypad
ld a, $1
ld [hBGMapMode], a
2015-12-15 15:59:49 -08:00
call ScrollingMenuJoypad
2015-11-23 13:04:53 -08:00
bit D_UP_F, a
jp nz, .pressed_up
bit D_DOWN_F, a
jp nz, .pressed_down
bit SELECT_F, a
jp nz, .pressed_select
bit B_BUTTON_F, a
2016-03-01 19:31:21 -08:00
; A button
push af
xor a
2015-11-23 13:04:53 -08:00
ld [wMoveSwapBuffer], a
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
dec a
2015-12-15 15:59:49 -08:00
ld [wMenuCursorY], a
ld b, a
2015-11-23 13:04:53 -08:00
ld a, [wMoveSelectionMenuType]
dec a
2015-11-23 13:04:53 -08:00
jr nz, .not_enemy_moves_process_b
pop af
ret
2015-11-23 13:04:53 -08:00
.not_enemy_moves_process_b
dec a
ld a, b
2018-01-23 14:39:09 -08:00
ld [wCurMoveNum], a
2015-11-23 13:04:53 -08:00
jr nz, .use_move
pop af
ret
2015-11-23 13:04:53 -08:00
.use_move
pop af
ret nz
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonPP
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
2018-01-11 09:00:01 -08:00
and PP_MASK
2015-11-23 13:04:53 -08:00
jr z, .no_pp_left
2018-01-23 14:39:09 -08:00
ld a, [wPlayerDisableCount]
swap a
and $f
dec a
cp c
2015-11-23 13:04:53 -08:00
jr z, .move_disabled
2016-01-12 09:46:18 -08:00
ld a, [wUnusedPlayerLockedMove]
and a
2015-11-23 13:04:53 -08:00
jr nz, .skip2
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonMoves
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
2015-11-23 13:04:53 -08:00
.skip2
2018-01-23 14:39:09 -08:00
ld [wCurPlayerMove], a
xor a
ret
2015-11-23 13:04:53 -08:00
.move_disabled
2015-09-09 16:27:07 -07:00
ld hl, BattleText_TheMoveIsDisabled
2015-11-23 13:04:53 -08:00
jr .place_textbox_start_over
2015-11-23 13:04:53 -08:00
.no_pp_left
2015-09-09 16:27:07 -07:00
ld hl, BattleText_TheresNoPPLeftForThisMove
2015-11-23 13:04:53 -08:00
.place_textbox_start_over
call StdBattleTextBox
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
2015-10-10 04:45:39 -07:00
jp MoveSelectionScreen
; 3e61c
.string_3e61c ; 3e61c
db "@"
; 3e61d
2015-11-23 13:04:53 -08:00
.pressed_up
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
and a
2015-11-23 13:04:53 -08:00
jp nz, .menu_loop
2015-12-04 05:46:11 -08:00
ld a, [wNumMoves]
inc a
2015-12-15 15:59:49 -08:00
ld [wMenuCursorY], a
2015-11-23 13:04:53 -08:00
jp .menu_loop
; 3e62e
2015-11-23 13:04:53 -08:00
.pressed_down ; 3e62e
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
ld b, a
2015-12-04 05:46:11 -08:00
ld a, [wNumMoves]
inc a
2015-12-26 18:59:03 -08:00
inc a
cp b
2015-11-23 13:04:53 -08:00
jp nz, .menu_loop
ld a, $1
2015-12-15 15:59:49 -08:00
ld [wMenuCursorY], a
2015-11-23 13:04:53 -08:00
jp .menu_loop
; 3e643
2015-11-23 13:04:53 -08:00
.pressed_select ; 3e643
ld a, [wMoveSwapBuffer]
and a
2015-11-23 13:04:53 -08:00
jr z, .start_swap
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonMoves
2015-11-23 13:04:53 -08:00
call .swap_bytes
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonPP
2015-11-23 13:04:53 -08:00
call .swap_bytes
2018-01-23 14:39:09 -08:00
ld hl, wPlayerDisableCount
ld a, [hl]
swap a
and $f
ld b, a
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
cp b
2015-11-23 13:04:53 -08:00
jr nz, .not_swapping_disabled_move
ld a, [hl]
and $f
ld b, a
2015-11-23 13:04:53 -08:00
ld a, [wMoveSwapBuffer]
swap a
add b
ld [hl], a
2015-11-23 13:04:53 -08:00
jr .swap_moves_in_party_struct
2015-11-23 13:04:53 -08:00
.not_swapping_disabled_move
ld a, [wMoveSwapBuffer]
cp b
2015-11-23 13:04:53 -08:00
jr nz, .swap_moves_in_party_struct
ld a, [hl]
and $f
ld b, a
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
swap a
add b
ld [hl], a
2015-11-23 13:04:53 -08:00
.swap_moves_in_party_struct
; Fixes the COOLTRAINER glitch
2018-01-23 14:39:09 -08:00
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TRANSFORMED, a
2015-11-23 13:04:53 -08:00
jr nz, .transformed
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1Moves
ld a, [wCurBattleMon]
call GetPartyLocation
push hl
2015-11-23 13:04:53 -08:00
call .swap_bytes
pop hl
ld bc, MON_PP - MON_MOVES
add hl, bc
2015-11-23 13:04:53 -08:00
call .swap_bytes
2015-11-23 13:04:53 -08:00
.transformed
xor a
2015-11-23 13:04:53 -08:00
ld [wMoveSwapBuffer], a
2015-10-10 04:45:39 -07:00
jp MoveSelectionScreen
2015-11-23 13:04:53 -08:00
.swap_bytes
push hl
2015-11-23 13:04:53 -08:00
ld a, [wMoveSwapBuffer]
dec a
ld c, a
ld b, 0
add hl, bc
ld d, h
ld e, l
pop hl
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
dec a
ld c, a
ld b, 0
add hl, bc
ld a, [de]
ld b, [hl]
ld [hl], a
ld a, b
ld [de], a
ret
2015-11-23 13:04:53 -08:00
.start_swap
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2015-11-23 13:04:53 -08:00
ld [wMoveSwapBuffer], a
2015-10-10 04:45:39 -07:00
jp MoveSelectionScreen
; 3e6c8
MoveInfoBox: ; 3e6c8
xor a
ld [hBGMapMode], a
hlcoord 0, 8
ld b, 3
ld c, 9
call TextBox
call MobileTextBorder
2018-01-23 14:39:09 -08:00
ld a, [wPlayerDisableCount]
and a
2015-11-23 13:04:53 -08:00
jr z, .not_disabled
swap a
and $f
ld b, a
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
cp b
2015-11-23 13:04:53 -08:00
jr nz, .not_disabled
hlcoord 1, 10
ld de, .Disabled
call PlaceString
jr .done
2015-11-23 13:04:53 -08:00
.not_disabled
2015-12-15 15:59:49 -08:00
ld hl, wMenuCursorY
dec [hl]
call SetPlayerTurn
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonMoves
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wCurPlayerMove], a
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld [wCurPartyMon], a
ld a, WILDMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
2017-12-24 09:47:30 -08:00
callfar GetMaxPPOfMove
2015-12-15 15:59:49 -08:00
ld hl, wMenuCursorY
ld c, [hl]
inc [hl]
ld b, 0
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonPP
add hl, bc
ld a, [hl]
2018-01-11 09:00:01 -08:00
and PP_MASK
2018-01-23 14:39:09 -08:00
ld [wStringBuffer1], a
2015-11-23 13:04:53 -08:00
call .PrintPP
hlcoord 1, 9
ld de, .Type
call PlaceString
hlcoord 7, 11
ld [hl], "/"
2017-12-24 09:47:30 -08:00
callfar UpdateMoveData
ld a, [wPlayerMoveStruct + MOVE_ANIM]
ld b, a
hlcoord 2, 10
predef PrintMoveType
.done
ret
; 3e74f
.Disabled:
db "Disabled!@"
.Type:
db "TYPE/@"
; 3e75f
2015-11-23 13:04:53 -08:00
.PrintPP: ; 3e75f
hlcoord 5, 11
ld a, [wLinkMode] ; What's the point of this check?
cp LINK_MOBILE
jr c, .ok
hlcoord 5, 11
.ok
push hl
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
lb bc, 1, 2
call PrintNum
pop hl
inc hl
2015-12-26 18:59:03 -08:00
inc hl
ld [hl], "/"
inc hl
ld de, wNamedObjectIndexBuffer
lb bc, 1, 2
call PrintNum
ret
; 3e786
2015-11-23 13:04:53 -08:00
CheckPlayerHasUsableMoves: ; 3e786
ld a, STRUGGLE
2018-01-23 14:39:09 -08:00
ld [wCurPlayerMove], a
ld a, [wPlayerDisableCount]
and a
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonPP
2015-11-23 13:04:53 -08:00
jr nz, .disabled
ld a, [hli]
or [hl]
inc hl
or [hl]
inc hl
or [hl]
2018-01-11 09:00:01 -08:00
and PP_MASK
ret nz
2015-11-23 13:04:53 -08:00
jr .force_struggle
2015-11-23 13:04:53 -08:00
.disabled
swap a
and $f
ld b, a
2017-12-12 19:58:20 -08:00
ld d, NUM_MOVES + 1
xor a
2015-11-23 13:04:53 -08:00
.loop
dec d
2015-11-23 13:04:53 -08:00
jr z, .done
ld c, [hl]
inc hl
dec b
2015-11-23 13:04:53 -08:00
jr z, .loop
or c
2015-11-23 13:04:53 -08:00
jr .loop
2015-11-23 13:04:53 -08:00
.done
2017-12-12 19:58:20 -08:00
; Bug: this will result in a move with PP Up confusing the game.
2018-01-11 09:00:01 -08:00
and a ; should be "and PP_MASK"
ret nz
2015-11-23 13:04:53 -08:00
.force_struggle
ld hl, BattleText_MonHasNoMovesLeft
call StdBattleTextBox
ld c, 60
call DelayFrames
xor a
ret
; 3e7c1
2015-11-08 16:09:36 -08:00
ParseEnemyAction: ; 3e7c1
ld a, [wEnemyIsSwitching]
and a
ret nz
ld a, [wLinkMode]
and a
2015-11-07 18:04:54 -08:00
jr z, .not_linked
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
ld a, [wBattlePlayerAction]
and a
2015-11-23 13:04:53 -08:00
call z, LinkBattleSendReceiveAction
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
ld a, [wBattleAction]
2015-11-06 06:04:27 -08:00
cp BATTLEACTION_E
2015-11-07 18:04:54 -08:00
jp z, .struggle
2015-11-06 06:04:27 -08:00
cp BATTLEACTION_D
2015-11-07 18:04:54 -08:00
jp z, .battle_action_d
2015-11-06 06:04:27 -08:00
cp BATTLEACTION_SWITCH1
2015-09-09 16:27:07 -07:00
jp nc, ResetVarsForSubstatusRage
2018-01-23 14:39:09 -08:00
ld [wCurEnemyMoveNum], a
ld c, a
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus1]
bit SUBSTATUS_ROLLOUT, a
2015-11-07 18:04:54 -08:00
jp nz, .skip_load
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus3]
and 1 << SUBSTATUS_CHARGED | 1 << SUBSTATUS_RAMPAGE | 1 << SUBSTATUS_BIDE
2015-11-07 18:04:54 -08:00
jp nz, .skip_load
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus5
bit SUBSTATUS_ENCORED, [hl]
2018-01-23 14:39:09 -08:00
ld a, [wLastEnemyMove]
2015-11-07 18:04:54 -08:00
jp nz, .finish
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMoves
ld b, 0
add hl, bc
ld a, [hl]
2015-11-07 18:04:54 -08:00
jp .finish
2015-11-07 18:04:54 -08:00
.not_linked
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus5
bit SUBSTATUS_ENCORED, [hl]
2015-11-07 18:04:54 -08:00
jr z, .skip_encore
2018-01-23 14:39:09 -08:00
ld a, [wLastEnemyMove]
2015-11-07 18:04:54 -08:00
jp .finish
2015-11-07 18:04:54 -08:00
.skip_encore
2016-03-01 19:31:21 -08:00
call CheckEnemyLockedIn
2015-09-09 16:27:07 -07:00
jp nz, ResetVarsForSubstatusRage
2015-11-07 18:04:54 -08:00
jr .continue
2015-11-07 18:04:54 -08:00
.battle_action_d
ld a, $ff
2015-11-07 18:04:54 -08:00
jr .finish
2015-11-07 18:04:54 -08:00
.continue
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMoves
ld de, wEnemyMonPP
ld b, NUM_MOVES
2015-11-07 18:04:54 -08:00
.loop
ld a, [hl]
and a
2015-11-07 18:04:54 -08:00
jp z, .struggle
2018-01-23 14:39:09 -08:00
ld a, [wEnemyDisabledMove]
cp [hl]
2015-11-07 18:04:54 -08:00
jr z, .disabled
ld a, [de]
2018-01-11 09:00:01 -08:00
and PP_MASK
2015-11-07 18:04:54 -08:00
jr nz, .enough_pp
2015-11-07 18:04:54 -08:00
.disabled
inc hl
inc de
dec b
2015-11-07 18:04:54 -08:00
jr nz, .loop
jr .struggle
2015-11-07 18:04:54 -08:00
.enough_pp
ld a, [wBattleMode]
dec a
2015-11-07 18:04:54 -08:00
jr nz, .skip_load
; wild
.loop2
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMoves
call BattleRandom
2018-01-16 14:27:50 -08:00
maskbits NUM_MOVES
ld c, a
ld b, 0
add hl, bc
2018-01-23 14:39:09 -08:00
ld a, [wEnemyDisableCount]
swap a
and $f
dec a
cp c
2015-11-07 18:04:54 -08:00
jr z, .loop2
ld a, [hl]
and a
2015-11-07 18:04:54 -08:00
jr z, .loop2
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonPP
add hl, bc
ld b, a
ld a, [hl]
2018-01-11 09:00:01 -08:00
and PP_MASK
2015-11-07 18:04:54 -08:00
jr z, .loop2
ld a, c
2018-01-23 14:39:09 -08:00
ld [wCurEnemyMoveNum], a
ld a, b
2015-11-07 18:04:54 -08:00
.finish
2018-01-23 14:39:09 -08:00
ld [wCurEnemyMove], a
2015-11-07 18:04:54 -08:00
.skip_load
call SetEnemyTurn
2017-12-24 09:47:30 -08:00
callfar UpdateMoveData
2016-03-01 19:31:21 -08:00
call CheckEnemyLockedIn
2015-11-06 17:55:16 -08:00
jr nz, .raging
xor a
2015-11-07 18:04:54 -08:00
ld [wEnemyCharging], a
2015-11-06 17:55:16 -08:00
.raging
ld a, [wEnemyMoveStruct + MOVE_EFFECT]
cp EFFECT_FURY_CUTTER
2015-11-06 17:55:16 -08:00
jr z, .fury_cutter
xor a
2018-01-23 14:39:09 -08:00
ld [wEnemyFuryCutterCount], a
2015-11-06 17:55:16 -08:00
.fury_cutter
ld a, [wEnemyMoveStruct + MOVE_EFFECT]
cp EFFECT_RAGE
2015-11-07 18:04:54 -08:00
jr z, .no_rage
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus4
res SUBSTATUS_RAGE, [hl]
xor a
2015-11-05 16:13:09 -08:00
ld [wEnemyRageCounter], a
2015-11-07 18:04:54 -08:00
.no_rage
ld a, [wEnemyMoveStruct + MOVE_EFFECT]
cp EFFECT_PROTECT
ret z
cp EFFECT_ENDURE
ret z
xor a
2018-01-23 14:39:09 -08:00
ld [wEnemyProtectCount], a
ret
2015-11-07 18:04:54 -08:00
.struggle
ld a, STRUGGLE
2015-11-07 18:04:54 -08:00
jr .finish
; 3e8c1
2015-09-09 16:27:07 -07:00
ResetVarsForSubstatusRage: ; 3e8c1
xor a
2018-01-23 14:39:09 -08:00
ld [wEnemyFuryCutterCount], a
ld [wEnemyProtectCount], a
2015-11-05 16:13:09 -08:00
ld [wEnemyRageCounter], a
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus4
res SUBSTATUS_RAGE, [hl]
ret
; 3e8d1
2016-03-01 19:31:21 -08:00
CheckEnemyLockedIn: ; 3e8d1
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus4]
and 1 << SUBSTATUS_RECHARGE
ret nz
2015-09-09 16:27:07 -07:00
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus3
ld a, [hl]
and 1 << SUBSTATUS_CHARGED | 1 << SUBSTATUS_RAMPAGE | 1 << SUBSTATUS_BIDE
ret nz
2015-09-09 16:27:07 -07:00
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus1
bit SUBSTATUS_ROLLOUT, [hl]
ret
; 3e8e4
2015-11-23 13:04:53 -08:00
LinkBattleSendReceiveAction: ; 3e8e4
2017-12-24 09:47:30 -08:00
farcall _LinkBattleSendReceiveAction
ret
; 3e8eb
LoadEnemyMon: ; 3e8eb
; Initialize enemy monster parameters
2018-01-23 14:39:09 -08:00
; To do this we pull the species from wTempEnemyMonSpecies
; Notes:
; BattleRandom is used to ensure sync between Game Boys
; Clear the whole enemy mon struct (wEnemyMon)
xor a
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonSpecies
ld bc, wEnemyMonEnd - wEnemyMon
call ByteFill
; We don't need to be here if we're in a link battle
ld a, [wLinkMode]
and a
2016-01-12 21:39:41 -08:00
jp nz, InitEnemyMon
2015-09-04 13:30:40 -07:00
; and also not in a BattleTower-Battle
2018-01-23 14:39:09 -08:00
ld a, [wInBattleTowerBattle] ; ????
bit 0, a
2016-01-12 21:39:41 -08:00
jp nz, InitEnemyMon
; Make sure everything knows what species we're working with
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld [wEnemyMonSpecies], a
ld [wCurSpecies], a
ld [wCurPartySpecies], a
; Grab the BaseData for this species
call GetBaseData
; Let's get the item:
; Is the item predetermined?
ld a, [wBattleMode]
dec a
jr z, .WildItem
; If we're in a trainer battle, the item is in the party struct
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld hl, wOTPartyMon1Item
call GetPartyLocation ; bc = PartyMon[wCurPartyMon] - wPartyMons
ld a, [hl]
jr .UpdateItem
.WildItem:
; In a wild battle, we pull from the item slots in BaseData
; Force Item1
; Used for Ho-Oh, Lugia and Snorlax encounters
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_FORCEITEM
2018-01-23 14:39:09 -08:00
ld a, [wBaseItems]
jr z, .UpdateItem
; Failing that, it's all up to chance
; Effective chances:
; 75% None
; 23% Item1
; 2% Item2
; 25% chance of getting an item
call BattleRandom
2018-02-04 18:21:34 -08:00
cp 75 percent + 1
ld a, NO_ITEM
jr c, .UpdateItem
; From there, an 8% chance for Item2
call BattleRandom
cp 8 percent ; 8% of 25% = 2% Item2
2018-01-23 14:39:09 -08:00
ld a, [wBaseItems]
jr nc, .UpdateItem
2018-01-23 14:39:09 -08:00
ld a, [wBaseItems+1]
.UpdateItem:
2018-01-23 14:39:09 -08:00
ld [wEnemyMonItem], a
; Initialize DVs
; If we're in a trainer battle, DVs are predetermined
ld a, [wBattleMode]
and a
jr z, .InitDVs
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus5]
bit SUBSTATUS_TRANSFORMED, a
jr z, .InitDVs
; Unknown
2016-01-10 14:44:09 -08:00
ld hl, wEnemyBackupDVs
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonDVs
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
jp .Happiness
.InitDVs:
; Trainer DVs
; All trainers have preset DVs, determined by class
; See GetTrainerDVs for more on that
2017-12-24 09:47:30 -08:00
farcall GetTrainerDVs
; These are the DVs we'll use if we're actually in a trainer battle
ld a, [wBattleMode]
dec a
jr nz, .UpdateDVs
; Wild DVs
; Here's where the fun starts
; Roaming monsters (Entei, Raikou) work differently
; They have their own structs, which are shorter than normal
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_ROAMING
jr nz, .NotRoaming
; Grab HP
call GetRoamMonHP
ld a, [hl]
; Check if the HP has been initialized
and a
; We'll do something with the result in a minute
push af
; Grab DVs
call GetRoamMonDVs
inc hl
ld a, [hld]
ld c, a
ld b, [hl]
; Get back the result of our check
pop af
; If the RoamMon struct has already been initialized, we're done
jr nz, .UpdateDVs
; If it hasn't, we need to initialize the DVs
; (HP is initialized at the end of the battle)
call GetRoamMonDVs
inc hl
call BattleRandom
ld [hld], a
ld c, a
call BattleRandom
ld [hl], a
ld b, a
; We're done with DVs
jr .UpdateDVs
.NotRoaming:
2018-01-23 14:39:09 -08:00
; Register a contains wBattleType
; Forced shiny battle type
; Used by Red Gyarados at Lake of Rage
cp BATTLETYPE_SHINY
jr nz, .GenerateDVs
ld b, ATKDEFDV_SHINY ; $ea
ld c, SPDSPCDV_SHINY ; $aa
jr .UpdateDVs
.GenerateDVs:
; Generate new random DVs
call BattleRandom
ld b, a
call BattleRandom
ld c, a
.UpdateDVs:
; Input DVs in register bc
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonDVs
ld a, b
ld [hli], a
ld [hl], c
; We've still got more to do if we're dealing with a wild monster
ld a, [wBattleMode]
dec a
jr nz, .Happiness
; Species-specfic:
; Unown
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
cp UNOWN
jr nz, .Magikarp
; Get letter based on DVs
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonDVs
predef GetUnownLetter
; Can't use any letters that haven't been unlocked
; If combined with forced shiny battletype, causes an infinite loop
call CheckUnownLetter
jr c, .GenerateDVs ; try again
.Magikarp:
; These filters are untranslated.
2017-12-28 07:42:57 -08:00
; They expect at wMagikarpLength a 2-byte value in mm,
; but the value is in feet and inches (one byte each).
2017-12-28 07:42:57 -08:00
; The first filter is supposed to make very large Magikarp even rarer,
2018-01-02 08:50:08 -08:00
; by targeting those 1600 mm (= 5'3") or larger.
; After the conversion to feet, it is unable to target any,
2018-01-02 08:50:08 -08:00
; since the largest possible Magikarp is 5'3", and $0503 = 1283 mm.
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
cp MAGIKARP
jr nz, .Happiness
; Get Magikarp's length
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonDVs
ld bc, wPlayerID
2017-12-24 09:47:30 -08:00
callfar CalcMagikarpLength
2018-01-02 08:53:06 -08:00
; No reason to keep going if length > 1536 mm (i.e. if HIGH(length) > 6 feet)
2017-12-09 16:41:03 -08:00
ld a, [wMagikarpLength]
2018-01-02 08:50:08 -08:00
cp HIGH(1536) ; should be "cp 5", since 1536 mm = 5'0", but HIGH(1536) = 6
jr nz, .CheckMagikarpArea
; 5% chance of skipping both size checks
call Random
cp 5 percent
jr c, .CheckMagikarpArea
2018-01-02 08:53:06 -08:00
; Try again if length >= 1616 mm (i.e. if LOW(length) >= 3 inches)
2017-12-09 16:41:03 -08:00
ld a, [wMagikarpLength + 1]
2018-01-02 08:50:08 -08:00
cp LOW(1616) ; should be "cp 3", since 1616 mm = 5'3", but LOW(1616) = 80
jr nc, .GenerateDVs
; 20% chance of skipping this check
call Random
cp 20 percent - 1
jr c, .CheckMagikarpArea
2018-01-02 08:53:06 -08:00
; Try again if length >= 1600 mm (i.e. if LOW(length) >= 2 inches)
2017-12-09 16:41:03 -08:00
ld a, [wMagikarpLength + 1]
2018-01-02 08:50:08 -08:00
cp LOW(1600) ; should be "cp 2", since 1600 mm = 5'2", but LOW(1600) = 64
jr nc, .GenerateDVs
.CheckMagikarpArea:
2018-01-02 08:50:08 -08:00
; The "jr z" checks are supposed to be "jr nz".
; Instead, all maps in GROUP_LAKE_OF_RAGE (Mahogany area)
; and Routes 20 and 44 are treated as Lake of Rage.
; This also means Lake of Rage Magikarp can be smaller than ones
2018-01-02 08:50:08 -08:00
; caught elsewhere rather than the other way around.
2018-01-02 08:50:08 -08:00
; Intended behavior enforces a minimum size at Lake of Rage.
; The real behavior prevents a minimum size in the Lake of Rage area.
2017-12-28 07:42:57 -08:00
2018-01-02 08:50:08 -08:00
; Moreover, due to the check not being translated to feet+inches, all Magikarp
; smaller than 4'0" may be caught by the filter, a lot more than intended.
2018-01-23 14:39:09 -08:00
ld a, [wMapGroup]
cp GROUP_LAKE_OF_RAGE
jr z, .Happiness
2018-01-23 14:39:09 -08:00
ld a, [wMapNumber]
cp MAP_LAKE_OF_RAGE
jr z, .Happiness
; 40% chance of not flooring
call Random
cp 40 percent - 2
jr c, .Happiness
2018-01-02 08:53:06 -08:00
; Try again if length < 1024 mm (i.e. if HIGH(length) < 3 feet)
2017-12-09 16:41:03 -08:00
ld a, [wMagikarpLength]
2018-01-02 08:50:08 -08:00
cp HIGH(1024) ; should be "cp 3", since 1024 mm = 3'4", but HIGH(1024) = 4
jr c, .GenerateDVs ; try again
; Finally done with DVs
.Happiness:
; Set happiness
ld a, BASE_HAPPINESS
2018-01-23 14:39:09 -08:00
ld [wEnemyMonHappiness], a
; Set level
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyLevel]
ld [wEnemyMonLevel], a
; Fill stats
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonMaxHP
2015-12-21 11:10:16 -08:00
ld b, FALSE
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonDVs - (MON_DVS - MON_STAT_EXP + 1) ; wLinkBattleRNs + 7 ; ?
predef CalcMonStats
; If we're in a trainer battle,
; get the rest of the parameters from the party struct
ld a, [wBattleMode]
cp TRAINER_BATTLE
jr z, .OpponentParty
; If we're in a wild battle, check wild-specific stuff
and a
jr z, .TreeMon
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus5]
bit SUBSTATUS_TRANSFORMED, a
jp nz, .Moves
.TreeMon:
; If we're headbutting trees, some monsters enter battle asleep
call CheckSleepingTreeMon
ld a, TREEMON_SLEEP_TURNS
jr c, .UpdateStatus
; Otherwise, no status
xor a
.UpdateStatus:
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonStatus
ld [hli], a
; Unused byte
xor a
ld [hli], a
2015-11-23 13:04:53 -08:00
; Full HP..
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonMaxHP]
ld [hli], a
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonMaxHP + 1]
ld [hl], a
2015-11-23 13:04:53 -08:00
; ..unless it's a RoamMon
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_ROAMING
jr nz, .Moves
; Grab HP
call GetRoamMonHP
ld a, [hl]
; Check if it's been initialized again
and a
jr z, .InitRoamHP
; Update from the struct if it has
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wEnemyMonHP + 1], a
jr .Moves
.InitRoamHP:
; HP only uses the lo byte in the RoamMon struct since
; Raikou/Entei/Suicune will have < 256 hp at level 40
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonHP + 1]
ld [hl], a
jr .Moves
.OpponentParty:
; Get HP from the party struct
2018-01-23 14:39:09 -08:00
ld hl, (wOTPartyMon1HP + 1)
ld a, [wCurPartyMon]
call GetPartyLocation
ld a, [hld]
2018-01-23 14:39:09 -08:00
ld [wEnemyMonHP + 1], a
ld a, [hld]
2018-01-23 14:39:09 -08:00
ld [wEnemyMonHP], a
; Make sure everything knows which monster the opponent is using
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld [wCurOTMon], a
; Get status from the party struct
dec hl
ld a, [hl] ; OTPartyMonStatus
2018-01-23 14:39:09 -08:00
ld [wEnemyMonStatus], a
.Moves:
2018-01-23 14:39:09 -08:00
ld hl, wBaseType1
ld de, wEnemyMonType1
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
; Get moves
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonMoves
; Are we in a trainer battle?
ld a, [wBattleMode]
cp TRAINER_BATTLE
jr nz, .WildMoves
; Then copy moves from the party struct
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1Moves
ld a, [wCurPartyMon]
call GetPartyLocation
ld bc, NUM_MOVES
call CopyBytes
jr .PP
.WildMoves:
2018-01-23 14:39:09 -08:00
; Clear wEnemyMonMoves
xor a
ld h, d
ld l, e
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
; Make sure the predef knows this isn't a partymon
2017-12-09 16:41:03 -08:00
ld [wEvolutionOldSpecies], a
; Fill moves based on level
predef FillMoves
.PP:
; Trainer battle?
ld a, [wBattleMode]
cp TRAINER_BATTLE
jr z, .TrainerPP
; Fill wild PP
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMoves
ld de, wEnemyMonPP
predef FillPP
jr .Finish
.TrainerPP:
; Copy PP from the party struct
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1PP
ld a, [wCurPartyMon]
call GetPartyLocation
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonPP
ld bc, NUM_MOVES
call CopyBytes
.Finish:
2015-11-23 13:04:53 -08:00
; Only the first five base stats are copied..
2018-01-23 14:39:09 -08:00
ld hl, wBaseStats
ld de, wEnemyMonBaseStats
ld b, wBaseSpecialDefense - wBaseStats
.loop
ld a, [hli]
ld [de], a
inc de
dec b
jr nz, .loop
2018-01-23 14:39:09 -08:00
ld a, [wBaseCatchRate]
ld [de], a
inc de
2018-01-23 14:39:09 -08:00
ld a, [wBaseExp]
ld [de], a
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld [wd265], a
call GetPokemonName
; Did we catch it?
ld a, [wBattleMode]
and a
ret z
; Update enemy nick
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
ld de, wEnemyMonNick
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
call CopyBytes
2015-11-29 18:34:59 -08:00
; Saw this mon
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
dec a
ld c, a
2015-11-22 21:21:21 -08:00
ld b, SET_FLAG
2018-01-23 14:39:09 -08:00
ld hl, wPokedexSeen
predef SmallFarFlagAction
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonStats
ld de, wEnemyStats
ld bc, wEnemyMonStatsEnd - wEnemyMonStats
call CopyBytes
ret
; 3eb38
CheckSleepingTreeMon: ; 3eb38
; Return carry if species is in the list
; for the current time of day
; Don't do anything if this isn't a tree encounter
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_TREE
jr nz, .NotSleeping
; Get list for the time of day
ld hl, AsleepTreeMonsMorn
2018-01-23 14:39:09 -08:00
ld a, [wTimeOfDay]
cp DAY_F
jr c, .Check
ld hl, AsleepTreeMonsDay
jr z, .Check
ld hl, AsleepTreeMonsNite
.Check:
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld de, 1 ; length of species id
call IsInArray
; If it's a match, the opponent is asleep
ret c
.NotSleeping:
and a
ret
INCLUDE "data/wild/treemons_asleep.asm"
CheckUnownLetter: ; 3eb75
; Return carry if the Unown letter hasn't been unlocked yet
ld a, [wUnlockedUnowns]
ld c, a
ld de, 0
.loop
; Don't check this set unless it's been unlocked
srl c
jr nc, .next
; Is our letter in the set?
ld hl, UnlockedUnownLetterSets
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
push de
2018-01-23 14:39:09 -08:00
ld a, [wUnownLetter]
ld de, 1
push bc
call IsInArray
pop bc
pop de
jr c, .match
.next
; Make sure we haven't gone past the end of the table
inc e
2015-12-26 18:59:03 -08:00
inc e
ld a, e
cp UnlockedUnownLetterSets.End - UnlockedUnownLetterSets
jr c, .loop
; Hasn't been unlocked, or the letter is invalid
scf
ret
.match
; Valid letter
and a
ret
INCLUDE "data/wild/unlocked_unowns.asm"
2018-01-02 07:04:21 -08:00
Unreferenced_SwapBattlerLevels: ; 3ebc7
push bc
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonLevel]
ld b, a
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonLevel]
ld [wBattleMonLevel], a
ld a, b
2018-01-23 14:39:09 -08:00
ld [wEnemyMonLevel], a
pop bc
ret
; 3ebd8
BattleWinSlideInEnemyTrainerFrontpic: ; 3ebd8
xor a
2018-01-23 14:39:09 -08:00
ld [wTempEnemyMonSpecies], a
2015-11-09 13:41:09 -08:00
call FinishBattleAnim
2018-01-23 14:39:09 -08:00
ld a, [wOtherTrainerClass]
ld [wTrainerClass], a
2017-12-28 04:32:33 -08:00
ld de, vTiles2
callfar GetTrainerPic
hlcoord 19, 0
ld c, 0
2015-10-19 13:49:29 -07:00
.outer_loop
inc c
ld a, c
cp 7
ret z
xor a
ld [hBGMapMode], a
ld [hBGMapThird], a
ld d, $0
push bc
push hl
2015-10-19 13:49:29 -07:00
.inner_loop
call .CopyColumn
inc hl
ld a, 7
add d
ld d, a
dec c
2015-10-19 13:49:29 -07:00
jr nz, .inner_loop
ld a, $1
ld [hBGMapMode], a
ld c, 4
call DelayFrames
pop hl
pop bc
dec hl
2015-10-19 13:49:29 -07:00
jr .outer_loop
; 3ec1a
.CopyColumn: ; 3ec1a
push hl
push de
push bc
ld e, 7
2015-10-19 13:49:29 -07:00
.loop
ld [hl], d
2015-10-19 13:49:29 -07:00
ld bc, SCREEN_WIDTH
add hl, bc
inc d
dec e
2015-10-19 13:49:29 -07:00
jr nz, .loop
pop bc
pop de
pop hl
ret
; 3ec2c
2015-11-07 18:04:54 -08:00
ApplyStatusEffectOnPlayerStats: ; 3ec2c
ld a, 1
2015-11-07 18:04:54 -08:00
jr ApplyStatusEffectOnStats
; 3ec30
2015-11-07 18:04:54 -08:00
ApplyStatusEffectOnEnemyStats: ; 3ec30
xor a
; 3ec31
2015-11-07 18:04:54 -08:00
ApplyStatusEffectOnStats: ; 3ec31
ld [hBattleTurn], a
2015-11-06 17:55:16 -08:00
call ApplyPrzEffectOnSpeed
jp ApplyBrnEffectOnAttack
; 3ec39
2015-11-06 17:55:16 -08:00
ApplyPrzEffectOnSpeed: ; 3ec39
ld a, [hBattleTurn]
and a
2015-11-07 18:04:54 -08:00
jr z, .enemy
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonStatus]
and 1 << PAR
ret z
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonSpeed + 1
ld a, [hld]
ld b, a
ld a, [hl]
srl a
rr b
srl a
rr b
ld [hli], a
or b
2015-11-07 18:04:54 -08:00
jr nz, .player_ok
ld b, $1 ; min speed
2015-11-07 18:04:54 -08:00
.player_ok
ld [hl], b
ret
2015-11-07 18:04:54 -08:00
.enemy
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonStatus]
and 1 << PAR
ret z
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonSpeed + 1
ld a, [hld]
ld b, a
ld a, [hl]
srl a
rr b
srl a
rr b
ld [hli], a
or b
2015-11-07 18:04:54 -08:00
jr nz, .enemy_ok
ld b, $1 ; min speed
2015-11-07 18:04:54 -08:00
.enemy_ok
ld [hl], b
ret
; 3ec76
2015-11-06 17:55:16 -08:00
ApplyBrnEffectOnAttack: ; 3ec76
ld a, [hBattleTurn]
and a
2015-11-07 18:04:54 -08:00
jr z, .enemy
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonStatus]
and 1 << BRN
ret z
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonAttack + 1
ld a, [hld]
ld b, a
ld a, [hl]
srl a
rr b
ld [hli], a
or b
2015-11-07 18:04:54 -08:00
jr nz, .player_ok
ld b, $1 ; min attack
2015-11-07 18:04:54 -08:00
.player_ok
ld [hl], b
ret
2015-11-07 18:04:54 -08:00
.enemy
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonStatus]
and 1 << BRN
ret z
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonAttack + 1
ld a, [hld]
ld b, a
ld a, [hl]
srl a
rr b
ld [hli], a
or b
2015-11-07 18:04:54 -08:00
jr nz, .enemy_ok
ld b, $1 ; min attack
2015-11-07 18:04:54 -08:00
.enemy_ok
ld [hl], b
ret
; 3ecab
2015-09-09 16:27:07 -07:00
ApplyStatLevelMultiplierOnAllStats: ; 3ecab
; Apply StatLevelMultipliers on all 5 Stats
ld c, 0
2015-11-07 18:04:54 -08:00
.stat_loop
2015-09-09 16:27:07 -07:00
call ApplyStatLevelMultiplier
inc c
ld a, c
cp 5
2015-11-07 18:04:54 -08:00
jr nz, .stat_loop
ret
; 3ecb7
2015-09-09 16:27:07 -07:00
ApplyStatLevelMultiplier: ; 3ecb7
push bc
push bc
ld a, [wd265]
and a
ld a, c
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonAttack
ld de, wPlayerStats
ld bc, wPlayerAtkLevel
2015-11-07 18:04:54 -08:00
jr z, .got_pointers
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonAttack
ld de, wEnemyStats
ld bc, wEnemyAtkLevel
2015-11-07 18:04:54 -08:00
.got_pointers
add c
ld c, a
2015-11-07 18:04:54 -08:00
jr nc, .okay
inc b
2015-11-07 18:04:54 -08:00
.okay
ld a, [bc]
pop bc
ld b, a
push bc
sla c
ld b, 0
add hl, bc
ld a, c
add e
ld e, a
2015-11-07 18:04:54 -08:00
jr nc, .okay2
inc d
2015-11-07 18:04:54 -08:00
.okay2
pop bc
push hl
2018-01-25 18:34:42 -08:00
ld hl, StatLevelMultipliers_Applied
dec b
sla b
ld c, b
ld b, 0
add hl, bc
xor a
ld [hMultiplicand + 0], a
ld a, [de]
ld [hMultiplicand + 1], a
inc de
ld a, [de]
ld [hMultiplicand + 2], a
ld a, [hli]
ld [hMultiplier], a
call Multiply
ld a, [hl]
ld [hDivisor], a
ld b, $4
call Divide
pop hl
; Cap at 999.
ld a, [hQuotient + 2]
sub LOW(MAX_STAT_VALUE)
ld a, [hQuotient + 1]
sbc HIGH(MAX_STAT_VALUE)
2015-11-07 18:04:54 -08:00
jp c, .okay3
ld a, HIGH(MAX_STAT_VALUE)
2015-11-07 18:04:54 -08:00
ld [hQuotient + 1], a
ld a, LOW(MAX_STAT_VALUE)
2015-11-07 18:04:54 -08:00
ld [hQuotient + 2], a
2015-11-07 18:04:54 -08:00
.okay3
ld a, [hQuotient + 1]
ld [hli], a
ld b, a
2015-11-07 18:04:54 -08:00
ld a, [hQuotient + 2]
ld [hl], a
or b
2015-11-07 18:04:54 -08:00
jr nz, .okay4
inc [hl]
2015-11-07 18:04:54 -08:00
.okay4
pop bc
ret
; 3ed2b
2018-01-25 18:34:42 -08:00
INCLUDE "data/battle/stat_multipliers_2.asm"
BadgeStatBoosts: ; 3ed45
; Raise the stats of the battle mon in wBattleMon
; depending on which badges have been obtained.
; Every other badge boosts a stat, starting from the first.
; ZephyrBadge: Attack
; PlainBadge: Speed
; MineralBadge: Defense
; GlacierBadge: Special Attack
; RisingBadge: Special Defense
; The boosted stats are in order, except PlainBadge and MineralBadge's boosts are swapped.
ld a, [wLinkMode]
and a
ret nz
2018-01-23 14:39:09 -08:00
ld a, [wInBattleTowerBattle]
and a
ret nz
ld a, [wJohtoBadges]
; Swap badges 3 (PlainBadge) and 5 (MineralBadge).
ld d, a
2015-11-07 18:04:54 -08:00
and (1 << PLAINBADGE)
add a
2015-12-26 18:59:03 -08:00
add a
ld b, a
ld a, d
2015-11-07 18:04:54 -08:00
and (1 << MINERALBADGE)
rrca
rrca
ld c, a
ld a, d
2015-11-07 18:04:54 -08:00
and ((1 << ZEPHYRBADGE) | (1 << HIVEBADGE) | (1 << FOGBADGE) | (1 << STORMBADGE) | (1 << GLACIERBADGE) | (1 << RISINGBADGE))
or b
or c
ld b, a
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonAttack
ld c, 4
.CheckBadge:
ld a, b
srl b
call c, BoostStat
inc hl
2015-12-26 18:59:03 -08:00
inc hl
; Check every other badge.
srl b
dec c
jr nz, .CheckBadge
; And the last one (RisingBadge) too.
srl a
call c, BoostStat
ret
; 3ed7c
BoostStat: ; 3ed7c
; Raise stat at hl by 1/8.
ld a, [hli]
ld d, a
ld e, [hl]
srl d
rr e
srl d
rr e
srl d
rr e
ld a, [hl]
add e
ld [hld], a
ld a, [hl]
adc d
ld [hli], a
; Cap at 999.
ld a, [hld]
sub LOW(MAX_STAT_VALUE)
ld a, [hl]
sbc HIGH(MAX_STAT_VALUE)
ret c
ld a, HIGH(MAX_STAT_VALUE)
ld [hli], a
ld a, LOW(MAX_STAT_VALUE)
ld [hld], a
ret
; 3ed9f
2015-11-10 16:51:13 -08:00
_LoadBattleFontsHPBar: ; 3ed9f
2017-12-24 09:47:30 -08:00
callfar LoadBattleFontsHPBar
ret
; 3eda6
2015-11-10 16:51:13 -08:00
_LoadHPBar: ; 3eda6
2017-12-24 09:47:30 -08:00
callfar LoadHPBar
ret
; 3edad
2018-01-02 07:04:21 -08:00
Unreferenced_LoadHPExpBarGFX:
2015-11-04 12:35:29 -08:00
ld de, EnemyHPBarBorderGFX
2017-12-28 04:32:33 -08:00
ld hl, vTiles2 tile $6c
2015-11-04 12:35:29 -08:00
lb bc, BANK(EnemyHPBarBorderGFX), 4
call Get1bpp
2015-11-04 12:35:29 -08:00
ld de, HPExpBarBorderGFX
2017-12-28 04:32:33 -08:00
ld hl, vTiles2 tile $73
2015-11-04 12:35:29 -08:00
lb bc, BANK(HPExpBarBorderGFX), 6
call Get1bpp
2015-11-04 11:02:11 -08:00
ld de, ExpBarGFX
2017-12-28 04:32:33 -08:00
ld hl, vTiles2 tile $55
2015-11-04 11:02:11 -08:00
lb bc, BANK(ExpBarGFX), 8
jp Get2bpp
; 3edd1
EmptyBattleTextBox: ; 3edd1
ld hl, .empty
jp BattleTextBox
.empty
db "@"
; 3edd8
_BattleRandom:: ; 3edd8
; If the normal RNG is used in a link battle it'll desync.
; To circumvent this a shared PRNG is used instead.
; But if we're in a non-link battle we're safe to use it
ld a, [wLinkMode]
and a
jp z, Random
; The PRNG operates in streams of 10 values.
; Which value are we trying to pull?
push hl
push bc
2018-01-23 14:39:09 -08:00
ld a, [wLinkBattleRNCount]
ld c, a
ld b, 0
2018-01-23 14:39:09 -08:00
ld hl, wLinkBattleRNs
add hl, bc
inc a
2018-01-23 14:39:09 -08:00
ld [wLinkBattleRNCount], a
; If we haven't hit the end yet, we're good
cp 10 - 1 ; Exclude last value. See the closing comment
ld a, [hl]
pop bc
pop hl
ret c
; If we have, we have to generate new pseudorandom data
; Instead of having multiple PRNGs, ten seeds are used
push hl
push bc
push af
; Reset count to 0
xor a
2018-01-23 14:39:09 -08:00
ld [wLinkBattleRNCount], a
ld hl, wLinkBattleRNs
ld b, 10 ; number of seeds
; Generate next number in the sequence for each seed
; a[n+1] = (a[n] * 5 + 1) % 256
.loop
; get last #
ld a, [hl]
; a * 5 + 1
ld c, a
add a
2015-12-26 18:59:03 -08:00
add a
add c
inc a
; update #
ld [hli], a
dec b
jr nz, .loop
; This has the side effect of pulling the last value first,
; then wrapping around. As a result, when we check to see if
; we've reached the end, we check the one before it.
pop af
pop bc
pop hl
ret
; 3ee0f
2015-11-07 18:04:54 -08:00
Call_PlayBattleAnim_OnlyIfVisible: ; 3ee0f
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVar
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
ret nz
; 3ee17
2015-09-09 16:27:07 -07:00
Call_PlayBattleAnim: ; 3ee17
ld a, e
2018-01-23 14:39:09 -08:00
ld [wFXAnimID], a
ld a, d
2018-01-23 14:39:09 -08:00
ld [wFXAnimID + 1], a
call WaitBGMap
predef_jump PlayBattleAnim
; 3ee27
2015-11-09 13:41:09 -08:00
FinishBattleAnim: ; 3ee27
push af
push bc
push de
push hl
2015-12-28 07:57:04 -08:00
ld b, SCGB_BATTLE_COLORS
call GetSGBLayout
2015-09-09 16:27:07 -07:00
call SetPalettes
call DelayFrame
pop hl
pop de
pop bc
pop af
ret
; 3ee3b
2015-09-09 16:27:07 -07:00
GiveExperiencePoints: ; 3ee3b
2014-06-03 14:07:10 -07:00
; Give experience.
2015-11-11 11:12:46 -08:00
; Don't give experience if linked or in the Battle Tower.
ld a, [wLinkMode]
and a
ret nz
2015-08-24 16:56:30 -07:00
2018-01-23 14:39:09 -08:00
ld a, [wInBattleTowerBattle]
bit 0, a
ret nz
2015-08-24 16:56:30 -07:00
2016-01-12 09:46:18 -08:00
call .EvenlyDivideExpAmongParticipants
xor a
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
ld bc, wPartyMon1Species
2015-11-07 18:04:54 -08:00
.loop
ld hl, MON_HP
add hl, bc
ld a, [hli]
or [hl]
2015-11-07 18:04:54 -08:00
jp z, .skip_stats ; fainted
push bc
2015-11-07 18:04:54 -08:00
ld hl, wBattleParticipantsNotFainted
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld c, a
2015-11-07 18:04:54 -08:00
ld b, CHECK_FLAG
ld d, $0
predef SmallFarFlagAction
ld a, c
and a
pop bc
2015-11-07 18:04:54 -08:00
jp z, .skip_stats
2016-01-12 09:46:18 -08:00
; give stat exp
2015-11-07 18:04:54 -08:00
ld hl, MON_STAT_EXP + 1
add hl, bc
ld d, h
ld e, l
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonBaseStats - 1
push bc
ld c, $5
2015-11-07 18:04:54 -08:00
.loop1
inc hl
ld a, [de]
add [hl]
ld [de], a
2015-11-07 18:04:54 -08:00
jr nc, .okay1
dec de
ld a, [de]
inc a
2015-11-07 18:04:54 -08:00
jr z, .next
ld [de], a
inc de
2015-11-07 18:04:54 -08:00
.okay1
push hl
push bc
ld a, MON_PKRUS
call GetPartyParamLocation
ld a, [hl]
and a
pop bc
pop hl
2015-11-07 18:04:54 -08:00
jr z, .skip
ld a, [de]
add [hl]
ld [de], a
2015-11-07 18:04:54 -08:00
jr nc, .skip
dec de
ld a, [de]
inc a
2015-11-07 18:04:54 -08:00
jr z, .next
ld [de], a
inc de
2015-11-07 18:04:54 -08:00
jr .skip
2015-11-07 18:04:54 -08:00
.next
ld a, $ff
ld [de], a
inc de
ld [de], a
2015-11-07 18:04:54 -08:00
.skip
inc de
2015-12-26 18:59:03 -08:00
inc de
dec c
2015-11-07 18:04:54 -08:00
jr nz, .loop1
xor a
ld [hMultiplicand + 0], a
ld [hMultiplicand + 1], a
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonBaseExp]
ld [hMultiplicand + 2], a
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonLevel]
ld [hMultiplier], a
call Multiply
2015-11-07 18:04:54 -08:00
ld a, 7
ld [hDivisor], a
2015-11-07 18:04:54 -08:00
ld b, 4
call Divide
2016-01-12 09:46:18 -08:00
; Boost Experience for traded Pokemon
pop bc
2015-11-07 18:04:54 -08:00
ld hl, MON_ID
add hl, bc
2018-01-23 14:39:09 -08:00
ld a, [wPlayerID]
cp [hl]
2015-11-07 18:04:54 -08:00
jr nz, .boosted
inc hl
2018-01-23 14:39:09 -08:00
ld a, [wPlayerID + 1]
cp [hl]
ld a, $0
2015-11-07 18:04:54 -08:00
jr z, .no_boost
2015-11-07 18:04:54 -08:00
.boosted
2015-11-11 11:12:46 -08:00
call BoostExp
ld a, $1
2015-11-07 18:04:54 -08:00
.no_boost
2016-01-12 09:46:18 -08:00
; Boost experience for a Trainer Battle
2018-01-23 14:39:09 -08:00
ld [wStringBuffer2 + 2], a
ld a, [wBattleMode]
dec a
2015-11-11 11:12:46 -08:00
call nz, BoostExp
2016-01-12 09:46:18 -08:00
; Boost experience for Lucky Egg
push bc
ld a, MON_ITEM
call GetPartyParamLocation
ld a, [hl]
2014-06-03 14:07:10 -07:00
cp LUCKY_EGG
2015-11-11 11:12:46 -08:00
call z, BoostExp
2015-11-07 18:04:54 -08:00
ld a, [hQuotient + 2]
2018-01-23 14:39:09 -08:00
ld [wStringBuffer2 + 1], a
2015-11-07 18:04:54 -08:00
ld a, [hQuotient + 1]
2018-01-23 14:39:09 -08:00
ld [wStringBuffer2], a
ld a, [wCurPartyMon]
ld hl, wPartyMonNicknames
call GetNick
ld hl, Text_MonGainedExpPoint
call BattleTextBox
2018-01-23 14:39:09 -08:00
ld a, [wStringBuffer2 + 1]
2015-11-07 18:04:54 -08:00
ld [hQuotient + 2], a
2018-01-23 14:39:09 -08:00
ld a, [wStringBuffer2]
2015-11-07 18:04:54 -08:00
ld [hQuotient + 1], a
pop bc
2016-01-12 09:46:18 -08:00
call AnimateExpBar
push bc
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
pop bc
2015-12-21 11:10:16 -08:00
ld hl, MON_STAT_EXP - 1
add hl, bc
ld d, [hl]
2015-11-07 18:04:54 -08:00
ld a, [hQuotient + 2]
add d
ld [hld], a
ld d, [hl]
2015-11-07 18:04:54 -08:00
ld a, [hQuotient + 1]
adc d
ld [hl], a
2015-11-07 18:04:54 -08:00
jr nc, .skip2
dec hl
inc [hl]
2015-11-07 18:04:54 -08:00
jr nz, .skip2
ld a, $ff
ld [hli], a
2015-12-26 18:59:03 -08:00
ld [hli], a
ld [hl], a
2015-11-07 18:04:54 -08:00
.skip2
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
ld e, a
ld d, $0
2018-01-23 14:39:09 -08:00
ld hl, wPartySpecies
add hl, de
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wCurSpecies], a
call GetBaseData
push bc
2014-06-03 14:07:10 -07:00
ld d, MAX_LEVEL
2017-12-24 09:47:30 -08:00
callfar CalcExpAtLevel
pop bc
2015-12-21 11:10:16 -08:00
ld hl, MON_STAT_EXP - 1
add hl, bc
push bc
2015-11-07 18:04:54 -08:00
ld a, [hQuotient]
ld b, a
2015-11-07 18:04:54 -08:00
ld a, [hQuotient + 1]
ld c, a
2015-11-07 18:04:54 -08:00
ld a, [hQuotient + 2]
ld d, a
ld a, [hld]
sub d
ld a, [hld]
sbc c
ld a, [hl]
sbc b
jr c, .not_max_exp
ld a, b
ld [hli], a
ld a, c
ld [hli], a
ld a, d
ld [hld], a
.not_max_exp
xor a ; PARTYMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
predef CopyMonToTempMon
2017-12-24 09:47:30 -08:00
callfar CalcLevel
pop bc
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
2014-06-03 14:07:10 -07:00
cp MAX_LEVEL
2015-11-07 18:04:54 -08:00
jp nc, .skip_stats
cp d
2015-11-07 18:04:54 -08:00
jp z, .skip_stats
; <NICKNAME> grew to level ##!
ld [wTempLevel], a
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyLevel]
push af
ld a, d
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
ld [hl], a
ld hl, MON_SPECIES
add hl, bc
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wCurSpecies], a
ld [wd265], a
call GetBaseData
2015-11-07 18:04:54 -08:00
ld hl, MON_MAXHP + 1
add hl, bc
ld a, [hld]
ld e, a
ld d, [hl]
push de
2015-11-07 18:04:54 -08:00
ld hl, MON_MAXHP
add hl, bc
ld d, h
ld e, l
2015-12-21 11:10:16 -08:00
ld hl, MON_STAT_EXP - 1
add hl, bc
push bc
2015-12-21 11:10:16 -08:00
ld b, TRUE
predef CalcMonStats
pop bc
pop de
2015-11-07 18:04:54 -08:00
ld hl, MON_MAXHP + 1
add hl, bc
ld a, [hld]
sub e
ld e, a
ld a, [hl]
sbc d
ld d, a
dec hl
ld a, [hl]
add e
ld [hld], a
ld a, [hl]
adc d
ld [hl], a
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
cp d
2015-11-07 18:04:54 -08:00
jr nz, .skip_animation
2018-01-23 14:39:09 -08:00
ld de, wBattleMonHP
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
2018-01-23 14:39:09 -08:00
ld de, wBattleMonMaxHP
push bc
2015-11-07 18:04:54 -08:00
ld bc, PARTYMON_STRUCT_LENGTH - MON_MAXHP
call CopyBytes
pop bc
2015-11-07 18:04:54 -08:00
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wBattleMonLevel], a
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TRANSFORMED, a
2015-11-07 18:04:54 -08:00
jr nz, .transformed
ld hl, MON_ATK
add hl, bc
2018-01-23 14:39:09 -08:00
ld de, wPlayerStats
2015-11-07 18:04:54 -08:00
ld bc, PARTYMON_STRUCT_LENGTH - MON_ATK
call CopyBytes
2015-11-07 18:04:54 -08:00
.transformed
xor a
ld [wd265], a
2015-09-09 16:27:07 -07:00
call ApplyStatLevelMultiplierOnAllStats
2017-12-24 09:47:30 -08:00
callfar ApplyStatusEffectOnPlayerStats
callfar BadgeStatBoosts
callfar UpdatePlayerHUD
call EmptyBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
ld a, $1
ld [hBGMapMode], a
2015-11-07 18:04:54 -08:00
.skip_animation
2017-12-24 09:47:30 -08:00
farcall LevelUpHappinessMod
2018-01-23 14:39:09 -08:00
ld a, [wCurBattleMon]
ld b, a
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
cp b
2015-11-07 18:04:54 -08:00
jr z, .skip_animation2
ld de, SFX_HIT_END_OF_EXP_BAR
call PlaySFX
call WaitSFX
2015-09-09 16:27:07 -07:00
ld hl, BattleText_StringBuffer1GrewToLevel
call StdBattleTextBox
2015-09-09 16:27:07 -07:00
call LoadTileMapToTempTileMap
2015-11-07 18:04:54 -08:00
.skip_animation2
xor a ; PARTYMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
predef CopyMonToTempMon
hlcoord 9, 0
ld b, $a
ld c, $9
call TextBox
hlcoord 11, 1
ld bc, 4
predef PrintTempMonStats
ld c, $1e
call DelayFrames
call WaitPressAorB_BlinkCursor
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
xor a ; PARTYMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
ld a, [wCurSpecies]
ld [wd265], a
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyLevel]
push af
ld c, a
ld a, [wTempLevel]
ld b, a
2015-11-07 18:04:54 -08:00
.level_loop
inc b
ld a, b
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
push bc
predef LearnLevelMoves
pop bc
ld a, b
cp c
2015-11-07 18:04:54 -08:00
jr nz, .level_loop
pop af
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
ld hl, wEvolvableFlags
ld a, [wCurPartyMon]
ld c, a
2015-11-22 21:21:21 -08:00
ld b, SET_FLAG
predef SmallFarFlagAction
pop af
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
2015-11-07 18:04:54 -08:00
.skip_stats
2018-01-23 14:39:09 -08:00
ld a, [wPartyCount]
ld b, a
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
inc a
cp b
2015-11-07 18:04:54 -08:00
jr z, .done
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
ld a, MON_SPECIES
call GetPartyParamLocation
ld b, h
ld c, l
2015-11-07 18:04:54 -08:00
jp .loop
2015-11-07 18:04:54 -08:00
.done
jp ResetBattleParticipants
; 3f0d4
.EvenlyDivideExpAmongParticipants:
; count number of battle participants
2015-11-07 18:04:54 -08:00
ld a, [wBattleParticipantsNotFainted]
ld b, a
ld c, PARTY_LENGTH
ld d, 0
2016-01-12 09:46:18 -08:00
.count_loop
xor a
srl b
adc d
ld d, a
dec c
2016-01-12 09:46:18 -08:00
jr nz, .count_loop
cp 2
ret c
ld [wd265], a
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonBaseStats
ld c, wEnemyMonEnd - wEnemyMonBaseStats
2016-01-12 09:46:18 -08:00
.count_loop2
xor a
2015-09-09 16:27:07 -07:00
ld [hDividend + 0], a
ld a, [hl]
2015-09-09 16:27:07 -07:00
ld [hDividend + 1], a
ld a, [wd265]
2015-09-09 16:27:07 -07:00
ld [hDivisor], a
ld b, 2
call Divide
2015-09-09 16:27:07 -07:00
ld a, [hQuotient + 2]
ld [hli], a
dec c
2016-01-12 09:46:18 -08:00
jr nz, .count_loop2
ret
; 3f106
2015-11-11 11:12:46 -08:00
BoostExp: ; 3f106
; Multiply experience by 1.5x
push bc
2015-11-11 11:12:46 -08:00
; load experience value
ld a, [hProduct + 2]
ld b, a
ld a, [hProduct + 3]
ld c, a
2015-11-11 11:12:46 -08:00
; halve it
srl b
rr c
2015-11-11 11:12:46 -08:00
; add it back to the whole exp value
add c
ld [hProduct + 3], a
ld a, [hProduct + 2]
adc b
ld [hProduct + 2], a
pop bc
ret
; 3f11b
Text_MonGainedExpPoint: ; 3f11b
2015-09-09 16:27:07 -07:00
text_jump Text_Gained
start_asm
2015-09-09 16:27:07 -07:00
ld hl, TextJump_StringBuffer2ExpPoints
2018-01-23 14:39:09 -08:00
ld a, [wStringBuffer2 + 2] ; IsTradedMon
and a
ret z
2015-09-09 16:27:07 -07:00
ld hl, TextJump_ABoostedStringBuffer2ExpPoints
ret
; 3f12c
2015-09-09 16:27:07 -07:00
TextJump_ABoostedStringBuffer2ExpPoints: ; 3f12c
text_jump Text_ABoostedStringBuffer2ExpPoints
db "@"
; 3f131
2015-09-09 16:27:07 -07:00
TextJump_StringBuffer2ExpPoints: ; 3f131
text_jump Text_StringBuffer2ExpPoints
db "@"
; 3f136
2016-01-12 09:46:18 -08:00
AnimateExpBar: ; 3f136
push bc
2018-01-23 14:39:09 -08:00
ld hl, wCurPartyMon
ld a, [wCurBattleMon]
cp [hl]
2015-11-10 16:51:13 -08:00
jp nz, .finish
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonLevel]
cp MAX_LEVEL
2015-11-10 16:51:13 -08:00
jp nc, .finish
ld a, [hProduct + 3]
ld [wd004], a
push af
ld a, [hProduct + 2]
ld [wd003], a
push af
xor a
2015-11-10 16:51:13 -08:00
ld [wd002], a
xor a ; PARTYMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
predef CopyMonToTempMon
2018-01-23 14:39:09 -08:00
ld a, [wTempMonLevel]
ld b, a
ld e, a
push de
2018-01-23 14:39:09 -08:00
ld de, wTempMonExp + 2
call CalcExpBar
push bc
2018-01-23 14:39:09 -08:00
ld hl, wTempMonExp + 2
ld a, [wd004]
add [hl]
ld [hld], a
ld a, [wd003]
adc [hl]
ld [hld], a
2016-01-12 09:46:18 -08:00
jr nc, .NoOverflow
inc [hl]
2016-01-12 09:46:18 -08:00
jr nz, .NoOverflow
ld a, $ff
ld [hli], a
2015-12-26 18:59:03 -08:00
ld [hli], a
ld [hl], a
.NoOverflow:
2014-06-03 14:07:10 -07:00
ld d, MAX_LEVEL
2017-12-24 09:47:30 -08:00
callfar CalcExpAtLevel
ld a, [hProduct + 1]
ld b, a
ld a, [hProduct + 2]
ld c, a
ld a, [hProduct + 3]
ld d, a
2018-01-23 14:39:09 -08:00
ld hl, wTempMonExp + 2
ld a, [hld]
sub d
ld a, [hld]
sbc c
ld a, [hl]
sbc b
2016-01-12 09:46:18 -08:00
jr c, .AlreadyAtMaxExp
ld a, b
ld [hli], a
ld a, c
ld [hli], a
ld a, d
ld [hld], a
.AlreadyAtMaxExp:
2017-12-24 09:47:30 -08:00
callfar CalcLevel
ld a, d
pop bc
pop de
ld d, a
cp e
2016-01-12 09:46:18 -08:00
jr nc, .LoopLevels
ld a, e
ld d, a
.LoopLevels:
ld a, e
2014-03-05 02:42:09 -08:00
cp MAX_LEVEL
2016-01-12 09:46:18 -08:00
jr nc, .FinishExpBar
cp d
2016-01-12 09:46:18 -08:00
jr z, .FinishExpBar
inc a
2018-01-23 14:39:09 -08:00
ld [wTempMonLevel], a
ld [wCurPartyLevel], a
ld [wBattleMonLevel], a
push de
2016-01-12 09:46:18 -08:00
call .PlayExpBarSound
ld c, $40
2016-01-12 09:46:18 -08:00
call .LoopBarAnimation
call PrintPlayerHUD
2018-01-23 14:39:09 -08:00
ld hl, wBattleMonNick
ld de, wStringBuffer1
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
call CopyBytes
2016-01-12 09:46:18 -08:00
call TerminateExpBarSound
ld de, SFX_HIT_END_OF_EXP_BAR
call PlaySFX
2017-12-24 09:47:30 -08:00
farcall AnimateEndOfExpBar
call WaitSFX
2015-09-09 16:27:07 -07:00
ld hl, BattleText_StringBuffer1GrewToLevel
call StdBattleTextBox
pop de
inc e
ld b, $0
2016-01-12 09:46:18 -08:00
jr .LoopLevels
.FinishExpBar:
push bc
ld b, d
2018-01-23 14:39:09 -08:00
ld de, wTempMonExp + 2
call CalcExpBar
ld a, b
pop bc
ld c, a
2016-01-12 09:46:18 -08:00
call .PlayExpBarSound
call .LoopBarAnimation
call TerminateExpBarSound
pop af
ld [hProduct + 2], a
pop af
ld [hProduct + 3], a
2015-11-10 16:51:13 -08:00
.finish
pop bc
ret
.PlayExpBarSound:
push bc
call WaitSFX
ld de, SFX_EXP_BAR
call PlaySFX
ld c, 10
call DelayFrames
pop bc
ret
.LoopBarAnimation:
2016-01-12 09:46:18 -08:00
ld d, 3
dec b
2016-01-12 09:46:18 -08:00
.anim_loop
inc b
push bc
push de
hlcoord 17, 11
call PlaceExpBar
pop de
ld a, $1
ld [hBGMapMode], a
ld c, d
call DelayFrames
xor a
ld [hBGMapMode], a
pop bc
ld a, c
cp b
2016-01-12 09:46:18 -08:00
jr z, .end_animation
inc b
push bc
push de
hlcoord 17, 11
call PlaceExpBar
pop de
ld a, $1
ld [hBGMapMode], a
ld c, d
call DelayFrames
xor a
ld [hBGMapMode], a
dec d
2016-01-12 09:46:18 -08:00
jr nz, .min_number_of_frames
ld d, 1
.min_number_of_frames
pop bc
ld a, c
cp b
2016-01-12 09:46:18 -08:00
jr nz, .anim_loop
.end_animation
ld a, $1
ld [hBGMapMode], a
ret
SendOutMonText: ; 3f26d
ld a, [wLinkMode]
and a
jr z, .not_linked
ld hl, JumpText_GoMon ; If we're in a LinkBattle print just "Go <PlayerMon>"
2016-08-07 15:14:20 -07:00
ld a, [wBattleHasJustStarted] ; unless this (unidentified) variable is set
and a
jr nz, .skip_to_textbox
.not_linked
; Depending on the HP of the enemy mon, the game prints a different text
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
ld hl, JumpText_GoMon
jr z, .skip_to_textbox
; compute enemy helth remaining as a percentage
xor a
ld [hMultiplicand + 0], a
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP
ld a, [hli]
ld [wEnemyHPAtTimeOfPlayerSwitch], a
ld [hMultiplicand + 1], a
ld a, [hl]
ld [wEnemyHPAtTimeOfPlayerSwitch + 1], a
ld [hMultiplicand + 2], a
ld a, 25
ld [hMultiplier], a
call Multiply
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld b, [hl]
srl a
rr b
srl a
rr b
ld a, b
ld b, 4
ld [hDivisor], a
call Divide
ld a, [hQuotient + 2]
ld hl, JumpText_GoMon
cp 70
jr nc, .skip_to_textbox
ld hl, JumpText_DoItMon
cp 40
jr nc, .skip_to_textbox
ld hl, JumpText_GoForItMon
cp 10
jr nc, .skip_to_textbox
ld hl, JumpText_YourFoesWeakGetmMon
.skip_to_textbox
jp BattleTextBox
; 3f2d1
JumpText_GoMon: ; 3f2d1
text_jump Text_GoMon
start_asm
jr Function_TextJump_BattleMonNick01
; 3f2d6
JumpText_DoItMon: ; 3f2d8
text_jump Text_DoItMon
start_asm
jr Function_TextJump_BattleMonNick01
; 3f2dd
JumpText_GoForItMon: ; 3f2df
text_jump Text_GoForItMon
start_asm
jr Function_TextJump_BattleMonNick01
; 3f2e4
JumpText_YourFoesWeakGetmMon: ; 3f2e6
text_jump Text_YourFoesWeakGetmMon
start_asm
Function_TextJump_BattleMonNick01: ; 3f2eb
ld hl, TextJump_BattleMonNick01
ret
; 3f2ef
TextJump_BattleMonNick01: ; 3f2ef
text_jump Text_BattleMonNick01
db "@"
; 3f2f4
WithdrawMonText: ; 3f2f4
ld hl, .WithdrawMonText
jp BattleTextBox
.WithdrawMonText:
2015-09-09 16:27:07 -07:00
text_jump Text_BattleMonNickComma
start_asm
; Print text to withdraw mon
2015-09-09 16:27:07 -07:00
; depending on HP the message is different
push de
push bc
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP + 1
ld de, wEnemyHPAtTimeOfPlayerSwitch + 1
ld b, [hl]
dec hl
ld a, [de]
sub b
ld [hMultiplicand + 2], a
dec de
ld b, [hl]
ld a, [de]
sbc b
ld [hMultiplicand + 1], a
ld a, 25
ld [hMultiplier], a
call Multiply
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld b, [hl]
srl a
rr b
srl a
rr b
ld a, b
ld b, 4
ld [hDivisor], a
call Divide
pop bc
pop de
ld a, [hQuotient + 2]
2015-09-09 16:27:07 -07:00
ld hl, TextJump_ThatsEnoughComeBack
and a
ret z
2015-09-09 16:27:07 -07:00
ld hl, TextJump_ComeBack
cp 30
ret c
2015-09-09 16:27:07 -07:00
ld hl, TextJump_OKComeBack
cp 70
ret c
2015-09-09 16:27:07 -07:00
ld hl, TextJump_GoodComeBack
ret
; 3f348
2015-09-09 16:27:07 -07:00
TextJump_ThatsEnoughComeBack: ; 3f348
text_jump Text_ThatsEnoughComeBack
db "@"
; 3f34d
2015-09-09 16:27:07 -07:00
TextJump_OKComeBack: ; 3f34d
text_jump Text_OKComeBack
db "@"
; 3f352
2015-09-09 16:27:07 -07:00
TextJump_GoodComeBack: ; 3f352
text_jump Text_GoodComeBack
db "@"
; 3f357
Unreferenced_TextJump_ComeBack: ; 3f357
2015-09-09 16:27:07 -07:00
; this function doesn't seem to be used
ld hl, TextJump_ComeBack
ret
; 3f35b
2015-09-09 16:27:07 -07:00
TextJump_ComeBack: ; 3f35b
text_jump Text_ComeBack
db "@"
; 3f360
2018-01-02 07:04:21 -08:00
Unreferenced_HandleSafariAngerEatingStatus:
ld hl, wSafariMonEating
ld a, [hl]
and a
jr z, .angry
dec [hl]
ld hl, BattleText_WildMonIsEating
jr .finish
.angry
dec hl ; wSafariMonAngerCount
ld a, [hl]
and a
ret z
dec [hl]
ld hl, BattleText_WildMonIsAngry
jr nz, .finish
push hl
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonSpecies]
ld [wCurSpecies], a
call GetBaseData
2018-01-23 14:39:09 -08:00
ld a, [wBaseCatchRate]
ld [wEnemyMonCatchRate], a
pop hl
.finish
push hl
2015-09-09 16:27:07 -07:00
call Call_LoadTempTileMapToTileMap
pop hl
jp StdBattleTextBox
; 3f390
FillInExpBar: ; 3f390
push hl
call CalcExpBar
pop hl
ld de, 7
add hl, de
jp PlaceExpBar
; 3f39c
CalcExpBar: ; 3f39c
; Calculate the percent exp between this level and the next
; Level in b
push de
ld d, b
push de
2017-12-24 09:47:30 -08:00
callfar CalcExpAtLevel
pop de
; exp at current level gets pushed to the stack
ld hl, hMultiplicand
ld a, [hli]
push af
ld a, [hli]
push af
ld a, [hl]
push af
; next level
inc d
2017-12-24 09:47:30 -08:00
callfar CalcExpAtLevel
; back up the next level exp, and subtract the two levels
ld hl, hMultiplicand + 2
ld a, [hl]
ld [hMathBuffer + 2], a
pop bc
sub b
ld [hld], a
ld a, [hl]
ld [hMathBuffer + 1], a
pop bc
sbc b
ld [hld], a
ld a, [hl]
ld [hMathBuffer], a
pop bc
sbc b
ld [hl], a
pop de
ld hl, hMultiplicand + 1
ld a, [hli]
push af
ld a, [hl]
push af
; get the amount of exp remaining to the next level
ld a, [de]
dec de
ld c, a
ld a, [hMathBuffer + 2]
sub c
ld [hld], a
ld a, [de]
dec de
ld b, a
ld a, [hMathBuffer + 1]
sbc b
ld [hld], a
ld a, [de]
ld c, a
ld a, [hMathBuffer]
sbc c
ld [hld], a
xor a
ld [hl], a
; multiply by 64
ld a, $40
ld [hMultiplier], a
call Multiply
pop af
ld c, a
pop af
ld b, a
.loop
ld a, b
and a
jr z, .done
srl b
rr c
ld hl, hProduct
srl [hl]
inc hl
rr [hl]
inc hl
rr [hl]
inc hl
rr [hl]
jr .loop
.done
ld a, c
ld [hDivisor], a
ld b, 4
call Divide
ld a, [hQuotient + 2]
ld b, a
ld a, $40
sub b
ld b, a
ret
; 3f41c
PlaceExpBar: ; 3f41c
ld c, $8 ; number of tiles
.loop1
ld a, b
sub $8
jr c, .next
ld b, a
ld a, $6a ; full bar
ld [hld], a
dec c
jr z, .finish
jr .loop1
.next
add $8
jr z, .loop2
add $54 ; tile to the left of small exp bar tile
jr .skip
.loop2
ld a, $62 ; empty bar
.skip
ld [hld], a
ld a, $62 ; empty bar
dec c
jr nz, .loop2
.finish
ret
; 3f43d
GetBattleMonBackpic: ; 3f43d
2018-01-23 14:39:09 -08:00
ld a, [wPlayerSubStatus4]
bit SUBSTATUS_SUBSTITUTE, a
ld hl, BattleAnimCmd_RaiseSub
jr nz, GetBattleMonBackpic_DoAnim ; substitute
2015-12-23 17:46:23 -08:00
DropPlayerSub: ; 3f447
ld a, [wPlayerMinimized]
and a
ld hl, BattleAnimCmd_MinimizeOpp
jr nz, GetBattleMonBackpic_DoAnim
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
push af
2018-01-23 14:39:09 -08:00
ld a, [wBattleMonSpecies]
ld [wCurPartySpecies], a
ld hl, wBattleMonDVs
predef GetUnownLetter
2017-12-28 04:32:33 -08:00
ld de, vTiles2 tile $31
predef GetMonBackpic
pop af
2018-01-23 14:39:09 -08:00
ld [wCurPartySpecies], a
ret
2013-12-31 01:09:00 -08:00
; 3f46f
GetBattleMonBackpic_DoAnim: ; 3f46f
ld a, [hBattleTurn]
push af
xor a
ld [hBattleTurn], a
ld a, BANK(BattleAnimCommands)
rst FarCall
pop af
ld [hBattleTurn], a
ret
; 3f47c
GetEnemyMonFrontpic: ; 3f47c
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus4]
bit SUBSTATUS_SUBSTITUTE, a
ld hl, BattleAnimCmd_RaiseSub
jr nz, GetEnemyMonFrontpic_DoAnim
2015-12-23 17:46:23 -08:00
DropEnemySub: ; 3f486
ld a, [wEnemyMinimized]
and a
ld hl, BattleAnimCmd_MinimizeOpp
jr nz, GetEnemyMonFrontpic_DoAnim
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
push af
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonSpecies]
ld [wCurSpecies], a
ld [wCurPartySpecies], a
call GetBaseData
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonDVs
predef GetUnownLetter
2017-12-28 04:32:33 -08:00
ld de, vTiles2
predef GetAnimatedFrontpic
pop af
2018-01-23 14:39:09 -08:00
ld [wCurPartySpecies], a
ret
2013-12-31 01:09:00 -08:00
; 3f4b4
GetEnemyMonFrontpic_DoAnim: ; 3f4b4
ld a, [hBattleTurn]
push af
call SetEnemyTurn
ld a, BANK(BattleAnimCommands)
rst FarCall
pop af
ld [hBattleTurn], a
ret
; 3f4c1
StartBattle: ; 3f4c1
2015-10-24 07:34:19 -07:00
; This check prevents you from entering a battle without any Pokemon.
; Those using walk-through-walls to bypass getting a Pokemon experience
; the effects of this check.
2018-01-23 14:39:09 -08:00
ld a, [wPartyCount]
and a
ret z
2015-10-24 07:34:19 -07:00
2018-01-23 14:39:09 -08:00
ld a, [wTimeOfDayPal]
push af
call BattleIntro
call DoBattle
call ExitBattle
pop af
2018-01-23 14:39:09 -08:00
ld [wTimeOfDayPal], a
scf
ret
; 3f4d9
2018-01-02 07:04:21 -08:00
Unreferenced_DoBattle: ; 3f4d9
call DoBattle
ret
; 3f4dd
BattleIntro: ; 3f4dd
farcall StubbedTrainerRankings_Battles ; mobile
2015-10-24 07:34:19 -07:00
call LoadTrainerOrWildMonPic
xor a
2018-01-23 14:39:09 -08:00
ld [wTempBattleMonSpecies], a
2017-12-09 16:41:03 -08:00
ld [wBattleMenuCursorBuffer], a
xor a
2015-11-05 11:06:03 -08:00
ld [hMapAnims], a
2017-12-24 09:47:30 -08:00
farcall PlayBattleMusic
farcall ShowLinkBattleParticipants
farcall FindFirstAliveMonAndStartBattle
2015-10-24 07:34:19 -07:00
call DisableSpriteUpdates
2017-12-24 09:47:30 -08:00
farcall ClearBattleRAM
2015-11-06 13:42:38 -08:00
call InitEnemy
2017-12-28 04:32:33 -08:00
call BackUpBGMap2
2015-12-28 07:57:04 -08:00
ld b, SCGB_BATTLE_GRAYSCALE
call GetSGBLayout
ld hl, rLCDC
2017-12-29 09:53:21 -08:00
res rLCDC_WINDOW_TILEMAP, [hl] ; select 9800-9BFF
call InitBattleDisplay
call BattleStartMessage
ld hl, rLCDC
2017-12-29 09:53:21 -08:00
set rLCDC_WINDOW_TILEMAP, [hl] ; select 9C00-9FFF
xor a
ld [hBGMapMode], a
call EmptyBattleTextBox
hlcoord 9, 7
2015-11-05 16:13:09 -08:00
lb bc, 5, 11
call ClearBox
hlcoord 1, 0
2015-11-05 16:13:09 -08:00
lb bc, 4, 10
call ClearBox
call ClearSprites
ld a, [wBattleMode]
2015-11-29 18:34:59 -08:00
cp WILD_BATTLE
call z, UpdateEnemyHUD
ld a, $1
ld [hBGMapMode], a
ret
; 3f54e
2015-10-24 07:34:19 -07:00
LoadTrainerOrWildMonPic: ; 3f54e
2018-01-23 14:39:09 -08:00
ld a, [wOtherTrainerClass]
and a
2015-10-24 07:34:19 -07:00
jr nz, .Trainer
2018-01-23 14:39:09 -08:00
ld a, [wTempWildMonSpecies]
ld [wCurPartySpecies], a
.Trainer:
2018-01-23 14:39:09 -08:00
ld [wTempEnemyMonSpecies], a
ret
; 3f55e
2015-11-06 13:42:38 -08:00
InitEnemy: ; 3f55e
2018-01-23 14:39:09 -08:00
ld a, [wOtherTrainerClass]
and a
2015-11-06 13:42:38 -08:00
jp nz, InitEnemyTrainer ; trainer
jp InitEnemyWildmon ; wild
; 3f568
2017-12-28 04:32:33 -08:00
BackUpBGMap2: ; 3f568
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ld [rSVBK], a
ld hl, wDecompressScratch
2017-12-28 04:32:33 -08:00
ld bc, $40 tiles ; vBGMap3 - vBGMap2
ld a, $2
call ByteFill
ld a, [rVBK]
push af
ld a, $1
ld [rVBK], a
ld de, wDecompressScratch
2017-12-28 04:32:33 -08:00
hlbgcoord 0, 0 ; vBGMap2
lb bc, BANK(BackUpBGMap2), $40
call Request2bpp
pop af
ld [rVBK], a
pop af
ld [rSVBK], a
ret
; 3f594
2015-11-06 13:42:38 -08:00
InitEnemyTrainer: ; 3f594
2018-01-23 14:39:09 -08:00
ld [wTrainerClass], a
farcall StubbedTrainerRankings_TrainerBattles
xor a
2018-01-23 14:39:09 -08:00
ld [wTempEnemyMonSpecies], a
2017-12-24 09:47:30 -08:00
callfar GetTrainerAttributes
callfar ReadTrainerParty
2018-01-18 09:03:58 -08:00
; RIVAL1's first mon has no held item
2018-01-23 14:39:09 -08:00
ld a, [wTrainerClass]
cp RIVAL1
jr nz, .ok
xor a
2018-01-23 14:39:09 -08:00
ld [wOTPartyMon1Item], a
.ok
2017-12-28 04:32:33 -08:00
ld de, vTiles2
callfar GetTrainerPic
xor a
2016-01-12 09:46:18 -08:00
ld [hGraphicStartTile], a
dec a
2016-01-12 09:46:18 -08:00
ld [wEnemyItemState], a
hlcoord 12, 0
lb bc, 7, 7
predef PlaceGraphic
ld a, -1
2018-01-23 14:39:09 -08:00
ld [wCurOTMon], a
ld a, TRAINER_BATTLE
ld [wBattleMode], a
call IsGymLeader
2015-10-12 09:33:24 -07:00
jr nc, .done
xor a
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
ld a, [wPartyCount]
ld b, a
2015-10-12 09:33:24 -07:00
.partyloop
push bc
ld a, MON_HP
call GetPartyParamLocation
ld a, [hli]
or [hl]
2015-10-12 09:33:24 -07:00
jr z, .skipfaintedmon
ld c, HAPPINESS_GYMBATTLE
2017-12-24 09:47:30 -08:00
callfar ChangeHappiness
2015-10-12 09:33:24 -07:00
.skipfaintedmon
pop bc
dec b
2015-10-12 09:33:24 -07:00
jr z, .done
2018-01-23 14:39:09 -08:00
ld hl, wCurPartyMon
inc [hl]
2015-10-12 09:33:24 -07:00
jr .partyloop
.done
ret
; 3f607
2015-11-06 13:42:38 -08:00
InitEnemyWildmon: ; 3f607
2015-11-29 18:34:59 -08:00
ld a, WILD_BATTLE
ld [wBattleMode], a
farcall StubbedTrainerRankings_WildBattles
call LoadEnemyMon
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMoves
2015-11-29 18:34:59 -08:00
ld de, wWildMonMoves
ld bc, NUM_MOVES
call CopyBytes
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonPP
2015-11-29 18:34:59 -08:00
ld de, wWildMonPP
ld bc, NUM_MOVES
call CopyBytes
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonDVs
predef GetUnownLetter
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
cp UNOWN
2015-11-09 20:55:39 -08:00
jr nz, .skip_unown
2015-11-29 18:34:59 -08:00
ld a, [wFirstUnownSeen]
and a
2015-11-09 20:55:39 -08:00
jr nz, .skip_unown
2018-01-23 14:39:09 -08:00
ld a, [wUnownLetter]
2015-11-29 18:34:59 -08:00
ld [wFirstUnownSeen], a
2015-11-09 20:55:39 -08:00
.skip_unown
2017-12-28 04:32:33 -08:00
ld de, vTiles2
predef GetAnimatedFrontpic
xor a
2018-01-23 14:39:09 -08:00
ld [wTrainerClass], a
2016-01-12 09:46:18 -08:00
ld [hGraphicStartTile], a
hlcoord 12, 0
lb bc, 7, 7
predef PlaceGraphic
ret
; 3f662
Unreferenced_Function3f662: ; 3f662
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMoves
2015-10-17 14:18:52 -07:00
ld de, wListMoves_MoveIndicesBuffer
ld b, NUM_MOVES
2014-01-05 04:28:55 -08:00
.loop
ld a, [de]
inc de
ld [hli], a
and a
2014-01-05 04:28:55 -08:00
jr z, .clearpp
push bc
push hl
2014-01-05 04:28:55 -08:00
push hl
dec a
2014-01-05 04:28:55 -08:00
ld hl, Moves + MOVE_PP
ld bc, MOVE_LENGTH
call AddNTimes
2014-01-05 04:28:55 -08:00
ld a, BANK(Moves)
call GetFarByte
pop hl
2014-01-05 04:28:55 -08:00
2018-01-23 14:39:09 -08:00
ld bc, wEnemyMonPP - (wEnemyMonMoves + 1)
add hl, bc
ld [hl], a
2014-01-05 04:28:55 -08:00
pop hl
pop bc
2014-01-05 04:28:55 -08:00
dec b
2014-01-05 04:28:55 -08:00
jr nz, .loop
ret
2014-01-05 04:28:55 -08:00
.clear
xor a
ld [hli], a
2014-01-05 04:28:55 -08:00
.clearpp
push bc
push hl
2018-01-23 14:39:09 -08:00
ld bc, wEnemyMonPP - (wEnemyMonMoves + 1)
add hl, bc
xor a
ld [hl], a
pop hl
pop bc
dec b
2014-01-05 04:28:55 -08:00
jr nz, .clear
ret
; 3f69e
ExitBattle: ; 3f69e
call .HandleEndOfBattle
call CleanUpBattleRAM
ret
; 3f6a5
.HandleEndOfBattle: ; 3f6a5
ld a, [wLinkMode]
and a
2015-10-24 07:34:19 -07:00
jr z, .not_linked
call ShowLinkBattleParticipantsAfterEnd
ld c, 150
call DelayFrames
call DisplayLinkBattleResult
ret
2015-10-24 07:34:19 -07:00
.not_linked
ld a, [wBattleResult]
and $f
ret nz
call CheckPayDay
xor a
ld [wForceEvolution], a
predef EvolveAfterBattle
2017-12-24 09:47:30 -08:00
farcall GivePokerusAndConvertBerries
ret
; 3f6d0
CleanUpBattleRAM: ; 3f6d0
call BattleEnd_HandleRoamMons
xor a
ld [wLowHealthAlarm], a
ld [wBattleMode], a
2018-01-23 14:39:09 -08:00
ld [wBattleType], a
ld [wAttackMissed], a
ld [wTempWildMonSpecies], a
ld [wOtherTrainerClass], a
2015-11-23 13:04:53 -08:00
ld [wFailedToFlee], a
ld [wNumFleeAttempts], a
2015-11-08 16:09:36 -08:00
ld [wForcedSwitch], a
2015-12-23 11:00:29 -08:00
ld [wPartyMenuCursor], a
2015-10-24 16:49:19 -07:00
ld [wKeyItemsPocketCursor], a
ld [wItemsPocketCursor], a
2017-12-09 16:41:03 -08:00
ld [wBattleMenuCursorBuffer], a
2018-01-23 14:39:09 -08:00
ld [wCurMoveNum], a
2015-10-24 16:49:19 -07:00
ld [wBallsPocketCursor], a
2015-11-23 13:04:53 -08:00
ld [wLastPocket], a
ld [wMenuScrollPosition], a
ld [wKeyItemsPocketScrollPosition], a
ld [wItemsPocketScrollPosition], a
ld [wBallsPocketScrollPosition], a
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus1
ld b, wEnemyFuryCutterCount - wPlayerSubStatus1
.loop
ld [hli], a
dec b
jr nz, .loop
call WaitSFX
ret
; 3f71d
CheckPayDay: ; 3f71d
ld hl, wPayDayMoney
ld a, [hli]
or [hl]
inc hl
or [hl]
ret z
2015-11-22 21:21:21 -08:00
ld a, [wAmuletCoin]
and a
jr z, .okay
ld hl, wPayDayMoney + 2
sla [hl]
dec hl
rl [hl]
dec hl
rl [hl]
jr nc, .okay
ld a, $ff
ld [hli], a
2015-12-26 18:59:03 -08:00
ld [hli], a
ld [hl], a
.okay
ld hl, wPayDayMoney + 2
2018-01-23 14:39:09 -08:00
ld de, wMoney + 2
2015-11-22 21:21:21 -08:00
call AddBattleMoneyToAccount
2015-12-18 17:07:09 -08:00
ld hl, BattleText_PlayerPickedUpPayDayMoney
call StdBattleTextBox
2018-01-23 14:39:09 -08:00
ld a, [wInBattleTowerBattle]
bit 0, a
ret z
call ClearTileMap
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
ret
; 3f759
ShowLinkBattleParticipantsAfterEnd: ; 3f759
farcall StubbedTrainerRankings_LinkBattles
2017-12-24 09:47:30 -08:00
farcall BackupMobileEventIndex
2018-01-23 14:39:09 -08:00
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Status
call GetPartyLocation
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonStatus]
ld [hl], a
call ClearTileMap
2017-12-24 09:47:30 -08:00
farcall _ShowLinkBattleParticipants
ret
; 3f77c
DisplayLinkBattleResult: ; 3f77c
2017-12-24 09:47:30 -08:00
farcall CheckMobileBattleError
jp c, .Mobile_InvalidBattle
call IsMobileBattle2
jr nz, .proceed
ld hl, wcd2a
bit 4, [hl]
jr z, .proceed
2017-12-24 09:47:30 -08:00
farcall DetermineLinkBattleResult
.proceed
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
and $f
2018-04-05 08:44:02 -07:00
cp LOSE
jr c, .victory ; WIN
jr z, .loss ; LOSE
; DRAW
farcall StubbedTrainerRankings_ColosseumDraws
ld de, .Draw
jr .store_result
.victory
farcall StubbedTrainerRankings_ColosseumWins
ld de, .Win
jr .store_result
.loss
farcall StubbedTrainerRankings_ColosseumLosses
ld de, .Lose
jr .store_result
.store_result
hlcoord 6, 8
call PlaceString
2017-12-24 09:47:30 -08:00
farcall BackupMobileEventIndex
ld c, 200
call DelayFrames
2015-10-04 11:14:51 -07:00
ld a, BANK(sLinkBattleStats)
call GetSRAMBank
2016-01-12 21:39:41 -08:00
call AddLastMobileBattleToLinkRecord
call ReadAndPrintLinkBattleRecord
call CloseSRAM
call IsMobileBattle2
jr z, .mobile
call WaitPressAorB_BlinkCursor
call ClearTileMap
ret
.mobile
ld c, 200
call DelayFrames
call ClearTileMap
ret
; 3f7f7
.Win:
db "YOU WIN@"
.Lose:
db "YOU LOSE@"
.Draw:
db " DRAW@"
; 3f80f
.Mobile_InvalidBattle: ; 3f80f
hlcoord 6, 8
ld de, .Invalid
call PlaceString
ld c, 200
call DelayFrames
call ClearTileMap
ret
; 3f821
.Invalid:
db "INVALID BATTLE@"
; 3f830
IsMobileBattle2: ; 3f830
ld a, [wLinkMode]
cp LINK_MOBILE
ret
; 3f836
_DisplayLinkRecord: ; 3f836
2015-08-19 21:21:38 -07:00
ld a, BANK(sLinkBattleStats)
call GetSRAMBank
2016-01-12 21:39:41 -08:00
call ReadAndPrintLinkBattleRecord
call CloseSRAM
2018-01-23 14:39:09 -08:00
hlcoord 0, 0, wAttrMap
xor a
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call ByteFill
2015-12-11 13:59:40 -08:00
call WaitBGMap2
2016-06-06 15:23:00 -07:00
ld b, SCGB_DIPLOMA
call GetSGBLayout
2015-09-09 16:27:07 -07:00
call SetPalettes
2016-01-12 21:39:41 -08:00
ld c, 8
call DelayFrames
call WaitPressAorB_BlinkCursor
ret
; 3f85f
2016-01-12 21:39:41 -08:00
ReadAndPrintLinkBattleRecord: ; 3f85f
call ClearTileMap
call ClearSprites
2016-01-12 21:39:41 -08:00
call .PrintBattleRecord
hlcoord 0, 8
2016-01-12 21:39:41 -08:00
ld b, 5
ld de, sLinkBattleRecord + 2
.loop
push bc
push hl
push de
ld a, [de]
and a
2016-01-12 21:39:41 -08:00
jr z, .PrintFormatString
2015-10-16 10:35:43 -07:00
ld a, [wSavedAtLeastOnce]
and a
2016-01-12 21:39:41 -08:00
jr z, .PrintFormatString
push hl
push hl
ld h, d
ld l, e
2015-11-10 16:51:13 -08:00
ld de, wd002
2016-01-12 21:39:41 -08:00
ld bc, 10
call CopyBytes
2016-01-12 21:39:41 -08:00
ld a, "@"
ld [de], a
inc de
2016-01-12 21:39:41 -08:00
ld bc, 6
call CopyBytes
2015-11-10 16:51:13 -08:00
ld de, wd002
pop hl
call PlaceString
pop hl
2016-01-12 21:39:41 -08:00
ld de, 26
add hl, de
push hl
ld de, wd00d
lb bc, 2, 4
call PrintNum
pop hl
2016-01-12 21:39:41 -08:00
ld de, 5
add hl, de
push hl
ld de, wd00f
lb bc, 2, 4
call PrintNum
pop hl
2016-01-12 21:39:41 -08:00
ld de, 5
add hl, de
ld de, wd011
lb bc, 2, 4
call PrintNum
2016-01-12 21:39:41 -08:00
jr .next
.PrintFormatString:
ld de, .Format
call PlaceString
2016-01-12 21:39:41 -08:00
.next
pop hl
2016-01-12 21:39:41 -08:00
ld bc, 18
add hl, bc
ld d, h
ld e, l
pop hl
2016-01-12 21:39:41 -08:00
ld bc, 2 * SCREEN_WIDTH
add hl, bc
pop bc
dec b
2016-01-12 21:39:41 -08:00
jr nz, .loop
ret
.PrintBattleRecord:
hlcoord 1, 0
ld de, .Record
call PlaceString
hlcoord 0, 6
ld de, .Result
call PlaceString
hlcoord 0, 2
ld de, .Total
call PlaceString
hlcoord 6, 4
2015-08-19 21:21:38 -07:00
ld de, sLinkBattleWins
2016-01-12 21:39:41 -08:00
call .PrintZerosIfNoSaveFileExists
jr c, .quit
lb bc, 2, 4
call PrintNum
hlcoord 11, 4
2015-08-19 21:21:38 -07:00
ld de, sLinkBattleLosses
2016-01-12 21:39:41 -08:00
call .PrintZerosIfNoSaveFileExists
lb bc, 2, 4
call PrintNum
hlcoord 16, 4
2015-08-19 21:21:38 -07:00
ld de, sLinkBattleDraws
2016-01-12 21:39:41 -08:00
call .PrintZerosIfNoSaveFileExists
lb bc, 2, 4
call PrintNum
2016-01-12 21:39:41 -08:00
.quit
ret
.PrintZerosIfNoSaveFileExists:
2015-10-16 10:35:43 -07:00
ld a, [wSavedAtLeastOnce]
and a
ret nz
ld de, .Scores
call PlaceString
scf
ret
; 3f938
.Scores:
db " 0 0 0@"
; 3f947
.Format: ; 3f947
2016-01-12 21:39:41 -08:00
db " --- <LNBRK>"
db " - - -@"
.Record: ; 3f964
2015-10-16 10:35:43 -07:00
db "<PLAYER>'s RECORD@"
.Result: ; 3f96e
db "RESULT WIN LOSE DRAW@"
.Total: ; 3f983
db "TOTAL WIN LOSE DRAW@"
; 3f998
BattleEnd_HandleRoamMons: ; 3f998
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_ROAMING
jr nz, .not_roaming
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
and $f
2018-04-05 08:44:02 -07:00
jr z, .caught_or_defeated_roam_mon ; WIN
call GetRoamMonHP
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonHP + 1]
ld [hl], a
jr .update_roam_mons
.caught_or_defeated_roam_mon
call GetRoamMonHP
2018-02-25 16:50:48 -08:00
ld [hl], 0
call GetRoamMonMapGroup
2018-02-25 16:50:48 -08:00
ld [hl], GROUP_N_A
call GetRoamMonMapNumber
2018-02-25 16:50:48 -08:00
ld [hl], MAP_N_A
call GetRoamMonSpecies
2018-02-25 16:50:48 -08:00
ld [hl], 0
ret
.not_roaming
call BattleRandom
and $f
ret nz
.update_roam_mons
2017-12-24 09:47:30 -08:00
callfar UpdateRoamMons
ret
; 3f9d1
GetRoamMonMapGroup: ; 3f9d1
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld b, a
ld a, [wRoamMon1Species]
cp b
ld hl, wRoamMon1MapGroup
ret z
ld a, [wRoamMon2Species]
cp b
ld hl, wRoamMon2MapGroup
ret z
ld hl, wRoamMon3MapGroup
ret
; 3f9e9
GetRoamMonMapNumber: ; 3f9e9
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld b, a
ld a, [wRoamMon1Species]
cp b
ld hl, wRoamMon1MapNumber
ret z
ld a, [wRoamMon2Species]
cp b
ld hl, wRoamMon2MapNumber
ret z
ld hl, wRoamMon3MapNumber
ret
; 3fa01
GetRoamMonHP: ; 3fa01
; output: hl = wRoamMonHP
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld b, a
ld a, [wRoamMon1Species]
cp b
ld hl, wRoamMon1HP
ret z
ld a, [wRoamMon2Species]
cp b
ld hl, wRoamMon2HP
ret z
ld hl, wRoamMon3HP
ret
; 3fa19
GetRoamMonDVs: ; 3fa19
; output: hl = wRoamMonDVs
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld b, a
ld a, [wRoamMon1Species]
cp b
ld hl, wRoamMon1DVs
ret z
ld a, [wRoamMon2Species]
cp b
ld hl, wRoamMon2DVs
ret z
ld hl, wRoamMon3DVs
ret
; 3fa31
GetRoamMonSpecies: ; 3fa31
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
ld hl, wRoamMon1Species
cp [hl]
ret z
ld hl, wRoamMon2Species
cp [hl]
ret z
ld hl, wRoamMon3Species
ret
; 3fa42
2016-01-12 21:39:41 -08:00
AddLastMobileBattleToLinkRecord: ; 3fa42
2018-01-23 14:39:09 -08:00
ld hl, wOTPlayerID
ld de, wStringBuffer1
ld bc, 2
call CopyBytes
2018-01-23 14:39:09 -08:00
ld hl, wOTPlayerName
2016-01-12 21:39:41 -08:00
ld bc, NAME_LENGTH - 1
call CopyBytes
2016-01-12 21:39:41 -08:00
ld hl, sLinkBattleResults
call .StoreResult
ld hl, sLinkBattleRecord
ld d, 5
.loop
push hl
inc hl
2015-12-26 18:59:03 -08:00
inc hl
ld a, [hl]
dec hl
2015-12-26 18:59:03 -08:00
dec hl
and a
jr z, .copy
push de
ld bc, 12
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
call CompareLong
pop de
pop hl
jr c, .done
ld bc, 18
add hl, bc
dec d
jr nz, .loop
ld bc, -18
add hl, bc
push hl
.copy
ld d, h
ld e, l
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
ld bc, 12
call CopyBytes
ld b, 6
xor a
.loop2
ld [de], a
inc de
dec b
jr nz, .loop2
pop hl
.done
2016-01-12 21:39:41 -08:00
call .StoreResult
call .FindOpponentAndAppendRecord
ret
; 3faa0
2016-01-12 21:39:41 -08:00
.StoreResult: ; 3faa0
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
and $f
2018-04-05 08:44:02 -07:00
cp LOSE
2016-01-12 21:39:41 -08:00
ld bc, sLinkBattleWins + 1 - sLinkBattleResults
2018-04-05 08:44:02 -07:00
jr c, .okay ; WIN
2016-01-12 21:39:41 -08:00
ld bc, sLinkBattleLosses + 1 - sLinkBattleResults
2018-04-05 08:44:02 -07:00
jr z, .okay ; LOSE
; DRAW
2016-01-12 21:39:41 -08:00
ld bc, sLinkBattleDraws + 1 - sLinkBattleResults
.okay
add hl, bc
2016-01-12 21:39:41 -08:00
call .CheckOverflow
ret nc
inc [hl]
ret nz
dec hl
inc [hl]
ret
; 3fabe
2016-01-12 21:39:41 -08:00
.CheckOverflow: ; 3fabe
dec hl
ld a, [hl]
inc hl
cp HIGH(MAX_LINK_RECORD)
ret c
ld a, [hl]
cp LOW(MAX_LINK_RECORD)
ret
; 3fac8
2016-01-12 21:39:41 -08:00
.FindOpponentAndAppendRecord: ; 3fac8
ld b, 5
ld hl, sLinkBattleRecord + 17
2015-11-10 16:51:13 -08:00
ld de, wd002
2016-01-12 21:39:41 -08:00
.loop3
push bc
push de
push hl
2016-01-12 21:39:41 -08:00
call .LoadPointer
pop hl
ld a, e
pop de
ld [de], a
inc de
ld a, b
ld [de], a
inc de
ld a, c
ld [de], a
inc de
ld bc, 18
add hl, bc
pop bc
dec b
2016-01-12 21:39:41 -08:00
jr nz, .loop3
ld b, $0
ld c, $1
2016-01-12 21:39:41 -08:00
.loop4
ld a, b
add b
2015-12-26 18:59:03 -08:00
add b
ld e, a
ld d, $0
2015-11-10 16:51:13 -08:00
ld hl, wd002
add hl, de
push hl
ld a, c
add c
2015-12-26 18:59:03 -08:00
add c
ld e, a
ld d, $0
2015-11-10 16:51:13 -08:00
ld hl, wd002
add hl, de
ld d, h
ld e, l
pop hl
push bc
2016-01-12 21:39:41 -08:00
ld c, 3
call StringCmp
pop bc
jr z, .equal
2016-01-12 21:39:41 -08:00
jr nc, .done2
.equal
inc c
ld a, c
cp $5
2016-01-12 21:39:41 -08:00
jr nz, .loop4
inc b
ld c, b
inc c
ld a, b
cp $4
2016-01-12 21:39:41 -08:00
jr nz, .loop4
ret
2016-01-12 21:39:41 -08:00
.done2
push bc
ld a, b
ld bc, 18
2016-01-12 21:39:41 -08:00
ld hl, sLinkBattleRecord
call AddNTimes
push hl
2015-11-10 16:51:13 -08:00
ld de, wd002
ld bc, 18
call CopyBytes
pop hl
pop bc
push hl
ld a, c
ld bc, 18
2016-01-12 21:39:41 -08:00
ld hl, sLinkBattleRecord
call AddNTimes
pop de
push hl
ld bc, 18
call CopyBytes
2015-11-10 16:51:13 -08:00
ld hl, wd002
ld bc, 18
pop de
call CopyBytes
ret
; 3fb54
2016-01-12 21:39:41 -08:00
.LoadPointer: ; 3fb54
ld e, $0
ld a, [hld]
ld c, a
ld a, [hld]
ld b, a
ld a, [hld]
add c
ld c, a
ld a, [hld]
adc b
ld b, a
2016-01-12 21:39:41 -08:00
jr nc, .okay2
inc e
2016-01-12 21:39:41 -08:00
.okay2
ld a, [hld]
add c
ld c, a
ld a, [hl]
adc b
ld b, a
ret nc
inc e
ret
; 3fb6c
InitBattleDisplay: ; 3fb6c
call .InitBackPic
hlcoord 0, 12
2015-11-06 13:42:38 -08:00
ld b, 4
ld c, 18
call TextBox
2017-12-24 09:47:30 -08:00
farcall MobileTextBorder
hlcoord 1, 5
lb bc, 3, 7
call ClearBox
2015-11-04 13:14:27 -08:00
call LoadStandardFont
2015-11-10 16:51:13 -08:00
call _LoadBattleFontsHPBar
call .BlankBGMap
xor a
2015-11-05 11:06:03 -08:00
ld [hMapAnims], a
ld [hSCY], a
ld a, $90
ld [hWY], a
ld [rWY], a
call WaitBGMap
xor a
ld [hBGMapMode], a
2017-12-24 09:47:30 -08:00
farcall BattleIntroSlidingPics
ld a, $1
ld [hBGMapMode], a
ld a, $31
2016-01-12 09:46:18 -08:00
ld [hGraphicStartTile], a
hlcoord 2, 6
2015-11-06 13:42:38 -08:00
lb bc, 6, 6
predef PlaceGraphic
xor a
ld [hWY], a
ld [rWY], a
call WaitBGMap
call HideSprites
2015-12-28 07:57:04 -08:00
ld b, SCGB_BATTLE_COLORS
call GetSGBLayout
2015-09-09 16:27:07 -07:00
call SetPalettes
ld a, $90
ld [hWY], a
xor a
ld [hSCX], a
ret
; 3fbd6
.BlankBGMap: ; 3fbd6
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ld [rSVBK], a
ld hl, wDecompressScratch
2016-05-04 19:34:09 -07:00
ld bc, wScratchAttrMap - wDecompressScratch
ld a, " "
call ByteFill
ld de, wDecompressScratch
2015-11-20 08:47:52 -08:00
hlbgcoord 0, 0
lb bc, BANK(.BlankBGMap), $40
call Request2bpp
pop af
ld [rSVBK], a
ret
; 3fbf8
.InitBackPic: ; 3fbf8
2015-11-06 13:42:38 -08:00
call GetTrainerBackpic
call CopyBackpic
ret
; 3fbff
2015-11-06 13:42:38 -08:00
GetTrainerBackpic: ; 3fbff
2017-12-28 04:32:33 -08:00
; Load the player character's backpic (6x6) into VRAM starting from vTiles2 tile $31.
; Special exception for Dude.
ld b, BANK(DudeBackpic)
ld hl, DudeBackpic
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_TUTORIAL
jr z, .Decompress
; What gender are we?
2015-10-24 07:34:19 -07:00
ld a, [wPlayerSpriteSetupFlags]
2018-01-22 11:34:55 -08:00
bit PLAYERSPRITESETUP_FEMALE_TO_MALE_F, a
jr nz, .Chris
ld a, [wPlayerGender]
2018-01-22 11:34:55 -08:00
bit PLAYERGENDER_FEMALE_F, a
jr z, .Chris
; It's a girl.
2017-12-24 09:47:30 -08:00
farcall GetKrisBackpic
ret
.Chris:
; It's a boy.
ld b, BANK(ChrisBackpic)
ld hl, ChrisBackpic
.Decompress:
2017-12-28 04:32:33 -08:00
ld de, vTiles2 tile $31
ld c, 7 * 7
predef DecompressGet2bpp
ret
; 3fc30
2015-11-06 13:42:38 -08:00
CopyBackpic: ; 3fc30
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ld [rSVBK], a
2017-12-28 04:32:33 -08:00
ld hl, vTiles0
ld de, vTiles2 tile $31
ld a, [hROMBank]
ld b, a
ld c, $31
call Get2bpp
pop af
ld [rSVBK], a
2016-01-12 21:39:41 -08:00
call .LoadTrainerBackpicAsOAM
ld a, $31
2016-01-12 09:46:18 -08:00
ld [hGraphicStartTile], a
hlcoord 2, 6
2015-11-06 13:42:38 -08:00
lb bc, 6, 6
predef PlaceGraphic
ret
; 3fc5b
2016-01-12 21:39:41 -08:00
.LoadTrainerBackpicAsOAM: ; 3fc5b
2018-01-30 11:52:46 -08:00
ld hl, wVirtualOAMSprite00
xor a
2015-11-02 08:15:32 -08:00
ld [hMapObjectIndexBuffer], a
2018-01-10 10:47:57 -08:00
ld b, 6
ld e, (SCREEN_WIDTH + 1) * TILE_WIDTH
2015-11-06 13:42:38 -08:00
.outer_loop
2018-01-10 10:47:57 -08:00
ld c, 3
ld d, 8 * TILE_WIDTH
2015-11-06 13:42:38 -08:00
.inner_loop
2018-01-10 10:47:57 -08:00
ld [hl], d ; y
inc hl
2018-01-10 10:47:57 -08:00
ld [hl], e ; x
inc hl
2015-11-02 08:15:32 -08:00
ld a, [hMapObjectIndexBuffer]
2018-01-10 10:47:57 -08:00
ld [hli], a ; tile id
inc a
2015-11-02 08:15:32 -08:00
ld [hMapObjectIndexBuffer], a
2018-01-10 10:47:57 -08:00
ld a, PAL_BATTLE_OB_PLAYER
ld [hli], a ; attributes
ld a, d
2018-01-10 10:47:57 -08:00
add 1 * TILE_WIDTH
ld d, a
dec c
2015-11-06 13:42:38 -08:00
jr nz, .inner_loop
2015-11-02 08:15:32 -08:00
ld a, [hMapObjectIndexBuffer]
add $3
2015-11-02 08:15:32 -08:00
ld [hMapObjectIndexBuffer], a
ld a, e
2018-01-10 10:47:57 -08:00
add 1 * TILE_WIDTH
ld e, a
dec b
2015-11-06 13:42:38 -08:00
jr nz, .outer_loop
ret
; 3fc8b
BattleStartMessage: ; 3fc8b
ld a, [wBattleMode]
dec a
2015-11-06 13:42:38 -08:00
jr z, .wild
ld de, SFX_SHINE
call PlaySFX
call WaitSFX
ld c, 20
call DelayFrames
2017-12-24 09:47:30 -08:00
farcall Battle_GetTrainerName
ld hl, WantsToBattleText
2015-11-06 13:42:38 -08:00
jr .PlaceBattleStartText
2015-11-06 13:42:38 -08:00
.wild
call BattleCheckEnemyShininess
jr nc, .not_shiny
xor a
2015-12-23 11:00:29 -08:00
ld [wNumHits], a
ld a, 1
ld [hBattleTurn], a
ld a, 1
2015-12-23 17:46:23 -08:00
ld [wBattleAnimParam], a
ld de, ANIM_SEND_OUT_MON
2015-09-09 16:27:07 -07:00
call Call_PlayBattleAnim
2015-11-06 13:42:38 -08:00
.not_shiny
2017-12-24 09:47:30 -08:00
farcall CheckSleepingTreeMon
2015-11-06 13:42:38 -08:00
jr c, .skip_cry
2017-12-24 09:47:30 -08:00
farcall CheckBattleScene
2015-11-07 06:48:32 -08:00
jr c, .cry_no_anim
hlcoord 12, 0
ld d, $0
2015-11-07 06:48:32 -08:00
ld e, ANIM_MON_NORMAL
predef AnimateFrontpic
2015-12-13 11:15:16 -08:00
jr .skip_cry ; cry is played during the animation
2015-11-07 06:48:32 -08:00
.cry_no_anim
ld a, $0f
2018-01-23 14:39:09 -08:00
ld [wCryTracks], a
ld a, [wTempEnemyMonSpecies]
2014-07-18 10:25:03 -07:00
call PlayStereoCry
2015-11-06 13:42:38 -08:00
.skip_cry
2018-01-23 14:39:09 -08:00
ld a, [wBattleType]
cp BATTLETYPE_FISH
2015-11-06 13:42:38 -08:00
jr nz, .NotFishing
farcall StubbedTrainerRankings_HookedEncounters
ld hl, HookedPokemonAttackedText
2015-11-06 13:42:38 -08:00
jr .PlaceBattleStartText
.NotFishing:
ld hl, PokemonFellFromTreeText
cp BATTLETYPE_TREE
2015-11-06 13:42:38 -08:00
jr z, .PlaceBattleStartText
ld hl, WildCelebiAppearedText
cp BATTLETYPE_CELEBI
2015-11-06 13:42:38 -08:00
jr z, .PlaceBattleStartText
ld hl, WildPokemonAppearedText
.PlaceBattleStartText:
push hl
2017-12-24 09:47:30 -08:00
farcall BattleStart_TrainerHuds
pop hl
call StdBattleTextBox
call IsMobileBattle2
ret nz
ld c, $2 ; start
2017-12-24 09:47:30 -08:00
farcall Mobile_PrintOpponentBattleMessage
ret
; 3fd26