pokecrystal/engine/battle/start_battle.asm

200 lines
3.1 KiB
NASM
Raw Normal View History

2018-06-24 14:09:41 +00:00
ShowLinkBattleParticipants:
; If we're not in a communications room,
; we don't need to be here.
ld a, [wLinkMode]
and a
ret z
2017-12-24 17:47:30 +00:00
farcall _ShowLinkBattleParticipants
ld c, 150
call DelayFrames
call ClearTilemap
call ClearSprites
ret
2018-06-24 14:09:41 +00:00
FindFirstAliveMonAndStartBattle:
xor a
ldh [hMapAnims], a
call DelayFrame
2018-07-04 06:42:11 +00:00
ld b, PARTY_LENGTH
2018-01-23 22:39:09 +00:00
ld hl, wPartyMon1HP
ld de, PARTYMON_STRUCT_LENGTH - 1
.loop
ld a, [hli]
or [hl]
jr nz, .okay
add hl, de
dec b
jr nz, .loop
.okay
ld de, MON_LEVEL - MON_HP
add hl, de
ld a, [hl]
2018-01-23 22:39:09 +00:00
ld [wBattleMonLevel], a
predef DoBattleTransition
2017-12-24 17:47:30 +00:00
farcall _LoadBattleFontsHPBar
ld a, 1
ldh [hBGMapMode], a
call ClearSprites
call ClearTilemap
xor a
ldh [hBGMapMode], a
ldh [hWY], a
ldh [rWY], a
ldh [hMapAnims], a
ret
2018-06-24 14:09:41 +00:00
PlayBattleMusic:
push hl
push de
push bc
xor a
2018-01-23 22:39:09 +00:00
ld [wMusicFade], a
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
call MaxVolume
2018-01-23 22:39:09 +00:00
ld a, [wBattleType]
cp BATTLETYPE_SUICUNE
ld de, MUSIC_SUICUNE_BATTLE
jp z, .done
cp BATTLETYPE_ROAMING
jp z, .done
; Are we fighting a trainer?
2018-01-23 22:39:09 +00:00
ld a, [wOtherTrainerClass]
and a
jr nz, .trainermusic
2017-12-24 17:47:30 +00:00
farcall RegionCheck
ld a, e
and a
jr nz, .kantowild
ld de, MUSIC_JOHTO_WILD_BATTLE
2018-01-23 22:39:09 +00:00
ld a, [wTimeOfDay]
cp NITE_F
jr nz, .done
ld de, MUSIC_JOHTO_WILD_BATTLE_NIGHT
jr .done
.kantowild
ld de, MUSIC_KANTO_WILD_BATTLE
jr .done
.trainermusic
ld de, MUSIC_CHAMPION_BATTLE
cp CHAMPION
jr z, .done
cp RED
jr z, .done
; They should have included EXECUTIVEM, EXECUTIVEF, and SCIENTIST too...
ld de, MUSIC_ROCKET_BATTLE
cp GRUNTM
jr z, .done
cp GRUNTF
jr z, .done
ld de, MUSIC_KANTO_GYM_LEADER_BATTLE
2017-12-24 17:47:30 +00:00
farcall IsKantoGymLeader
jr c, .done
; IsGymLeader also counts CHAMPION, RED, and the Kanto gym leaders
; but they have been taken care of before this
ld de, MUSIC_JOHTO_GYM_LEADER_BATTLE
farcall IsGymLeader
jr c, .done
ld de, MUSIC_RIVAL_BATTLE
2018-01-23 22:39:09 +00:00
ld a, [wOtherTrainerClass]
cp RIVAL1
jr z, .done
cp RIVAL2
jr nz, .othertrainer
2018-01-23 22:39:09 +00:00
ld a, [wOtherTrainerID]
cp RIVAL2_2_CHIKORITA ; Rival in Indigo Plateau
jr c, .done
ld de, MUSIC_CHAMPION_BATTLE
jr .done
.othertrainer
ld a, [wLinkMode]
and a
jr nz, .johtotrainer
2017-12-24 17:47:30 +00:00
farcall RegionCheck
ld a, e
and a
jr nz, .kantotrainer
.johtotrainer
ld de, MUSIC_JOHTO_TRAINER_BATTLE
jr .done
.kantotrainer
ld de, MUSIC_KANTO_TRAINER_BATTLE
.done
call PlayMusic
pop bc
pop de
pop hl
ret
2018-06-24 14:09:41 +00:00
ClearBattleRAM:
xor a
ld [wBattlePlayerAction], a
ld [wBattleResult], a
ld hl, wPartyMenuCursor
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld [wMenuScrollPosition], a
2018-01-23 22:39:09 +00:00
ld [wCriticalHit], a
ld [wBattleMonSpecies], a
ld [wBattleParticipantsNotFainted], a
2018-01-23 22:39:09 +00:00
ld [wCurBattleMon], a
ld [wForcedSwitch], a
2018-01-23 22:39:09 +00:00
ld [wTimeOfDayPal], a
ld [wPlayerTurnsTaken], a
ld [wEnemyTurnsTaken], a
ld [wEvolvableFlags], a
2018-01-23 22:39:09 +00:00
ld hl, wPlayerHPPal
ld [hli], a
ld [hl], a
2018-01-23 22:39:09 +00:00
ld hl, wBattleMonDVs
ld [hli], a
ld [hl], a
2018-01-23 22:39:09 +00:00
ld hl, wEnemyMonDVs
ld [hli], a
ld [hl], a
; Clear the entire BattleMons area
ld hl, wBattle
ld bc, wBattleEnd - wBattle
xor a
call ByteFill
2017-12-24 17:47:30 +00:00
callfar ResetEnemyStatLevels
call ClearWindowData
ld hl, hBGMapAddress
2017-12-28 12:32:33 +00:00
xor a ; LOW(vBGMap0)
ld [hli], a
2017-12-28 12:32:33 +00:00
ld [hl], HIGH(vBGMap0)
ret