pokered/engine/evos_moves.asm

501 lines
9.3 KiB
NASM
Raw Normal View History

2014-08-09 05:39:13 +00:00
; try to evolve the mon in [wWhichPokemon]
TryEvolvingMon: ; 3ad0e (e:6d0e)
ld hl, wccd3
2014-05-22 22:13:20 +00:00
xor a
ld [hl], a
2014-08-09 05:39:13 +00:00
ld a, [wWhichPokemon]
2014-05-22 22:13:20 +00:00
ld c, a
ld b, $1
2014-08-09 05:39:13 +00:00
call Evolution_FlagAction
2014-05-22 22:13:20 +00:00
2014-08-09 05:39:13 +00:00
; this is only called after battle
; it is supposed to do level up evolutions, though there is a bug that allows item evolutions to occur
EvolutionAfterBattle: ; 3ad1c (e:6d1c)
2014-05-22 22:13:20 +00:00
ld a, [$ffd7]
push af
xor a
ld [wd121], a
2014-05-22 22:13:20 +00:00
dec a
2014-08-09 05:39:13 +00:00
ld [wWhichPokemon], a
2014-05-22 22:13:20 +00:00
push hl
push bc
push de
2014-08-09 05:39:13 +00:00
ld hl, wPartyCount
2014-05-22 22:13:20 +00:00
push hl
2014-08-09 05:39:13 +00:00
Evolution_PartyMonLoop: ; loop over party mons
ld hl, wWhichPokemon
2014-05-22 22:13:20 +00:00
inc [hl]
pop hl
inc hl
ld a, [hl]
2014-08-09 05:39:13 +00:00
cp $ff ; have we reached the end of the party?
jp z, .done
ld [wHPBarMaxHP], a
2014-05-22 22:13:20 +00:00
push hl
2014-08-09 05:39:13 +00:00
ld a, [wWhichPokemon]
2014-05-22 22:13:20 +00:00
ld c, a
ld hl, wccd3
2014-05-22 22:13:20 +00:00
ld b, $2
2014-08-09 05:39:13 +00:00
call Evolution_FlagAction
2014-05-22 22:13:20 +00:00
ld a, c
2014-08-09 05:39:13 +00:00
and a ; is the mon's bit set?
jp z, Evolution_PartyMonLoop ; if not, go to the next mon
ld a, [wHPBarMaxHP]
2014-05-22 22:13:20 +00:00
dec a
2014-08-09 05:39:13 +00:00
ld b, 0
2014-05-22 22:13:20 +00:00
ld hl, EvosMovesPointerTable
add a
rl b
ld c, a
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
push hl
ld a, [wcf91]
2014-05-22 22:13:20 +00:00
push af
xor a
ld [wcc49], a
2014-05-22 22:13:20 +00:00
call LoadMonData
pop af
ld [wcf91], a
2014-05-22 22:13:20 +00:00
pop hl
2014-08-09 05:39:13 +00:00
.evoEntryLoop ; loop over evolution entries
2014-05-22 22:13:20 +00:00
ld a, [hli]
2014-08-09 05:39:13 +00:00
and a ; have we reached the end of the evolution data?
jr z, Evolution_PartyMonLoop
ld b, a ; evolution type
cp EV_TRADE
jr z, .checkTradeEvo
; not trade evolution
ld a, [W_ISLINKBATTLE]
cp $32 ; in a trade?
jr z, Evolution_PartyMonLoop ; if so, go the next mon
2014-05-22 22:13:20 +00:00
ld a, b
2014-08-09 05:39:13 +00:00
cp EV_ITEM
jr z, .checkItemEvo
ld a, [wccd4]
2014-05-22 22:13:20 +00:00
and a
2014-08-09 05:39:13 +00:00
jr nz, Evolution_PartyMonLoop
2014-05-22 22:13:20 +00:00
ld a, b
2014-08-09 05:39:13 +00:00
cp EV_LEVEL
jr z, .checkLevel
.checkTradeEvo
ld a, [W_ISLINKBATTLE]
cp $32 ; in a trade?
jp nz, .nextEvoEntry1 ; if not, go to the next evolution entry
ld a, [hli] ; level requirement
2014-05-22 22:13:20 +00:00
ld b, a
ld a, [wcfb9]
2014-08-09 05:39:13 +00:00
cp b ; is the mon's level greater than the evolution requirement?
jp c, Evolution_PartyMonLoop ; if so, go the next mon
2014-05-22 22:13:20 +00:00
jr .asm_3adb6
2014-08-09 05:39:13 +00:00
.checkItemEvo
2014-05-22 22:13:20 +00:00
ld a, [hli]
2014-08-09 05:39:13 +00:00
ld b, a ; evolution item
ld a, [wcf91] ; this is supposed to be the last item used, but it is also used to hold species numbers
cp b ; was the evolution item in this entry used?
jp nz, .nextEvoEntry1 ; if not, go to the next evolution entry
.checkLevel
ld a, [hli] ; level requirement
2014-05-22 22:13:20 +00:00
ld b, a
ld a, [wcfb9]
2014-08-09 05:39:13 +00:00
cp b ; is the mon's level greater than the evolution requirement?
jp c, .nextEvoEntry2 ; if so, go the next evolution entry
2014-05-22 22:13:20 +00:00
.asm_3adb6
2014-08-09 05:39:13 +00:00
ld [W_CURENEMYLVL], a
2014-05-22 22:13:20 +00:00
ld a, $1
ld [wd121], a
2014-05-22 22:13:20 +00:00
push hl
ld a, [hl]
ld [wHPBarMaxHP + 1], a
2014-08-09 05:39:13 +00:00
ld a, [wWhichPokemon]
ld hl, wPartyMonNicks
2014-05-22 22:13:20 +00:00
call GetPartyMonName
call CopyStringToCF4B
ld hl, IsEvolvingText
call PrintText
ld c, $32
call DelayFrames
xor a
2014-08-09 05:39:13 +00:00
ld [H_AUTOBGTRANSFERENABLED], a
2014-05-22 22:13:20 +00:00
ld hl, wTileMap
ld bc, $c14
call ClearScreenArea
ld a, $1
2014-08-09 05:39:13 +00:00
ld [H_AUTOBGTRANSFERENABLED], a
2014-05-22 22:13:20 +00:00
ld a, $ff
ld [wcfcb], a
2014-05-23 22:34:35 +00:00
call ClearSprites
2014-05-22 22:13:20 +00:00
callab Func_7bde9
2014-08-09 05:39:13 +00:00
jp c, CancelledEvolution
2014-05-22 22:13:20 +00:00
ld hl, EvolvedText
call PrintText
pop hl
ld a, [hl]
ld [wd0b5], a
ld [wcf98], a
ld [wHPBarMaxHP + 1], a
2014-05-22 22:13:20 +00:00
ld a, MONSTER_NAME
ld [W_LISTTYPE], a
ld a, $e
ld [wPredefBank], a
2014-05-22 22:13:20 +00:00
call GetName
push hl
ld hl, IntoText
call Func_3c59
ld a, (SFX_02_3b - SFX_Headers_02) / 3
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
ld c, $28
call DelayFrames
call ClearScreen
2014-08-09 05:39:13 +00:00
call RenameEvolvedMon
ld a, [wd11e]
2014-05-22 22:13:20 +00:00
push af
ld a, [wd0b5]
ld [wd11e], a
predef IndexToPokedex
ld a, [wd11e]
2014-05-22 22:13:20 +00:00
dec a
ld hl, BaseStats
2014-05-22 22:13:20 +00:00
ld bc, $1c
call AddNTimes
ld de, W_MONHEADER
call CopyData
ld a, [wd0b5]
ld [W_MONHDEXNUM], a
2014-05-22 22:13:20 +00:00
pop af
ld [wd11e], a
ld hl, wcfa8
ld de, wcfba
2014-05-22 22:13:20 +00:00
ld b, $1
call CalcStats
2014-08-09 05:39:13 +00:00
ld a, [wWhichPokemon]
ld hl, wPartyMon1
ld bc, wPartyMon2 - wPartyMon1
2014-05-22 22:13:20 +00:00
call AddNTimes
ld e, l
ld d, h
push hl
push bc
2014-08-09 05:39:13 +00:00
ld bc, wPartyMon1MaxHP - wPartyMon1
2014-05-22 22:13:20 +00:00
add hl, bc
ld a, [hli]
ld b, a
ld c, [hl]
ld hl, wcfbb
2014-05-22 22:13:20 +00:00
ld a, [hld]
sub c
ld c, a
ld a, [hl]
sbc b
ld b, a
ld hl, wcf9a
2014-05-22 22:13:20 +00:00
ld a, [hl]
add c
ld [hld], a
ld a, [hl]
adc b
ld [hl], a
dec hl
pop bc
call CopyData
ld a, [wd0b5]
ld [wd11e], a
2014-05-22 22:13:20 +00:00
xor a
ld [wcc49], a
2014-08-09 05:39:13 +00:00
call LearnMoveFromLevelUp
2014-05-22 22:13:20 +00:00
pop hl
predef SetPartyMonTypes
2014-08-09 05:39:13 +00:00
ld a, [W_ISINBATTLE]
2014-05-22 22:13:20 +00:00
and a
2014-08-09 05:39:13 +00:00
call z, Evolution_ReloadTilesetTilePatterns
predef IndexToPokedex
ld a, [wd11e]
2014-05-22 22:13:20 +00:00
dec a
ld c, a
ld b, $1
2014-08-09 05:39:13 +00:00
ld hl, wPokedexOwned
2014-05-22 22:13:20 +00:00
push bc
2014-08-09 05:39:13 +00:00
call Evolution_FlagAction
2014-05-22 22:13:20 +00:00
pop bc
2014-08-09 05:39:13 +00:00
ld hl, wPokedexSeen
call Evolution_FlagAction
2014-05-22 22:13:20 +00:00
pop de
pop hl
ld a, [wcf98]
2014-05-22 22:13:20 +00:00
ld [hl], a
push hl
ld l, e
ld h, d
2014-08-09 05:39:13 +00:00
jr .nextEvoEntry2
2014-05-22 22:13:20 +00:00
2014-08-09 05:39:13 +00:00
.nextEvoEntry1
2014-05-22 22:13:20 +00:00
inc hl
2014-08-09 05:39:13 +00:00
.nextEvoEntry2
2014-05-22 22:13:20 +00:00
inc hl
2014-08-09 05:39:13 +00:00
jp .evoEntryLoop
2014-05-22 22:13:20 +00:00
2014-08-09 05:39:13 +00:00
.done
2014-05-22 22:13:20 +00:00
pop de
pop bc
pop hl
pop af
ld [$ffd7], a
2014-08-09 05:39:13 +00:00
ld a, [W_ISLINKBATTLE]
2014-05-22 22:13:20 +00:00
cp $32
ret z
2014-08-09 05:39:13 +00:00
ld a, [W_ISINBATTLE]
2014-05-22 22:13:20 +00:00
and a
ret nz
ld a, [wd121]
2014-05-22 22:13:20 +00:00
and a
call nz, Func_2307
ret
2014-08-09 05:39:13 +00:00
; checks if the evolved mon's name is different from the standard name (i.e. it has a nickname)
; if so, rename it to is evolved form's standard name
RenameEvolvedMon: ; 3aef7 (e:6ef7)
ld a, [wd0b5]
2014-05-22 22:13:20 +00:00
push af
ld a, [W_MONHDEXNUM]
ld [wd0b5], a
2014-05-22 22:13:20 +00:00
call GetName
pop af
ld [wd0b5], a
ld hl, wcd6d
ld de, wcf4b
2014-08-09 05:39:13 +00:00
.compareNamesLoop
2014-05-22 22:13:20 +00:00
ld a, [de]
inc de
cp [hl]
inc hl
ret nz
cp $50
2014-08-09 05:39:13 +00:00
jr nz, .compareNamesLoop
ld a, [wWhichPokemon]
2014-05-22 22:13:20 +00:00
ld bc, $b
2014-08-09 05:39:13 +00:00
ld hl, wPartyMonNicks
2014-05-22 22:13:20 +00:00
call AddNTimes
push hl
call GetName
ld hl, wcd6d
2014-05-22 22:13:20 +00:00
pop de
jp CopyData
2014-08-09 05:39:13 +00:00
CancelledEvolution: ; 3af2e (e:6f2e)
2014-05-22 22:13:20 +00:00
ld hl, StoppedEvolvingText
call PrintText
call ClearScreen
pop hl
2014-08-09 05:39:13 +00:00
call Evolution_ReloadTilesetTilePatterns
jp Evolution_PartyMonLoop
2014-05-22 22:13:20 +00:00
EvolvedText: ; 3af3e (e:6f3e)
TX_FAR _EvolvedText
db "@"
IntoText: ; 3af43 (e:6f43)
TX_FAR _IntoText
db "@"
StoppedEvolvingText: ; 3af48 (e:6f48)
TX_FAR _StoppedEvolvingText
db "@"
IsEvolvingText: ; 3af4d (e:6f4d)
TX_FAR _IsEvolvingText
db "@"
2014-08-09 05:39:13 +00:00
Evolution_ReloadTilesetTilePatterns: ; 3af52 (e:6f52)
ld a, [W_ISLINKBATTLE] ; W_ISLINKBATTLE
2014-08-09 05:39:13 +00:00
cp $32 ; in a trade?
ret z ; if so, return
2014-05-22 22:13:20 +00:00
jp ReloadTilesetTilePatterns
2014-08-09 05:39:13 +00:00
LearnMoveFromLevelUp: ; 3af5b (e:6f5b)
2014-05-22 22:13:20 +00:00
ld hl, EvosMovesPointerTable
2014-08-09 05:39:13 +00:00
ld a, [wd11e] ; species
ld [wcf91], a
2014-05-22 22:13:20 +00:00
dec a
2014-08-09 05:39:13 +00:00
ld bc, 0
2014-05-22 22:13:20 +00:00
ld hl, EvosMovesPointerTable
add a
rl b
ld c, a
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
2014-08-09 05:39:13 +00:00
.skipEvolutionDataLoop ; loop to skip past the evolution data, which comes before the move data
2014-05-22 22:13:20 +00:00
ld a, [hli]
2014-08-09 05:39:13 +00:00
and a ; have we reached the end of the evolution data?
jr nz, .skipEvolutionDataLoop ; if not, jump back up
.learnSetLoop ; loop over the learn set until we reach a move that is learnt at the current level or the end of the list
2014-05-22 22:13:20 +00:00
ld a, [hli]
2014-08-09 05:39:13 +00:00
and a ; have we reached the end of the learn set?
jr z, .done ; if we've reached the end of the learn set, jump
ld b, a ; level the move is learnt at
ld a, [W_CURENEMYLVL]
cp b ; is the move learnt at the mon's current level?
ld a, [hli] ; move ID
jr nz, .learnSetLoop
ld d, a ; ID of move to learn
ld a, [wcc49]
2014-05-22 22:13:20 +00:00
and a
2014-08-09 05:39:13 +00:00
jr nz, .next
; if [wcc49] is 0, get the address of the mon's current moves
; there is no reason to make this conditional because the code wouldn't work properly without doing this
; every call to this function sets [wcc49] to 0
ld hl, wPartyMon1Moves
ld a, [wWhichPokemon]
ld bc, wPartyMon2 - wPartyMon1
2014-05-22 22:13:20 +00:00
call AddNTimes
2014-08-09 05:39:13 +00:00
.next
2014-05-22 22:13:20 +00:00
ld b, $4
2014-08-09 05:39:13 +00:00
.checkCurrentMovesLoop ; check if the move to learn is already known
2014-05-22 22:13:20 +00:00
ld a, [hli]
cp d
2014-08-09 05:39:13 +00:00
jr z, .done ; if already known, jump
2014-05-22 22:13:20 +00:00
dec b
2014-08-09 05:39:13 +00:00
jr nz, .checkCurrentMovesLoop
2014-05-22 22:13:20 +00:00
ld a, d
ld [wd0e0], a
ld [wd11e], a
2014-05-22 22:13:20 +00:00
call GetMoveName
call CopyStringToCF4B
predef LearnMove
2014-08-09 05:39:13 +00:00
.done
ld a, [wcf91]
ld [wd11e], a
2014-05-22 22:13:20 +00:00
ret
; writes the moves a mon has at level [W_CURENEMYLVL] to [de]
; move slots are being filled up sequentially and shifted if all slots are full
; [wHPBarMaxHP]: (?)
2014-05-22 22:13:20 +00:00
WriteMonMoves: ; 3afb8 (e:6fb8)
call GetPredefRegisters
2014-05-22 22:13:20 +00:00
push hl
push de
push bc
ld hl, EvosMovesPointerTable
ld b, $0
ld a, [wcf91] ; cur mon ID
2014-05-22 22:13:20 +00:00
dec a
add a
rl b
ld c, a
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
.skipEvoEntriesLoop
ld a, [hli]
and a
jr nz, .skipEvoEntriesLoop
jr .firstMove
.nextMove
pop de
.nextMove2
inc hl
.firstMove
ld a, [hli] ; read level of next move in learnset
and a
jp z, .done ; end of list
ld b, a
ld a, [W_CURENEMYLVL] ; W_CURENEMYLVL
2014-05-22 22:13:20 +00:00
cp b
jp c, .done ; mon level < move level (assumption: learnset is sorted by level)
ld a, [wHPBarMaxHP]
2014-05-22 22:13:20 +00:00
and a
jr z, .skipMinLevelCheck
ld a, [wWhichTrade] ; wWhichTrade (min move level)
2014-05-22 22:13:20 +00:00
cp b
jr nc, .nextMove2 ; min level >= move level
.skipMinLevelCheck
push de
ld c, $4
.moveAlreadyLearnedCheckLoop
ld a, [de]
inc de
cp [hl]
jr z, .nextMove
dec c
jr nz, .moveAlreadyLearnedCheckLoop
pop de
push de
ld c, $4
.findEmptySlotLoop
ld a, [de]
and a
jr z, .writeMoveToSlot2
inc de
dec c
jr nz, .findEmptySlotLoop
pop de ; no empty move slots found
push de
push hl
ld h, d
ld l, e
call WriteMonMoves_ShiftMoveData ; shift all moves one up (deleting move 1)
ld a, [wHPBarMaxHP]
2014-05-22 22:13:20 +00:00
and a
jr z, .writeMoveToSlot
push de
ld bc, $12
add hl, bc
ld d, h
ld e, l
call WriteMonMoves_ShiftMoveData ; shift all move PP data one up
pop de
.writeMoveToSlot
pop hl
.writeMoveToSlot2
ld a, [hl]
ld [de], a
ld a, [wHPBarMaxHP]
2014-05-22 22:13:20 +00:00
and a
jr z, .nextMove
push hl ; write move PP value
ld a, [hl]
ld hl, $15
add hl, de
push hl
dec a
ld hl, Moves
ld bc, $6
call AddNTimes
ld de, wHPBarMaxHP
2014-05-22 22:13:20 +00:00
ld a, BANK(Moves)
call FarCopyData
ld a, [wHPBarNewHP + 1]
2014-05-22 22:13:20 +00:00
pop hl
ld [hl], a
pop hl
jr .nextMove
.done
pop bc
pop de
pop hl
ret
; shifts all move data one up (freeing 4th move slot)
WriteMonMoves_ShiftMoveData: ; 3b04e (e:704e)
ld c, $3
.asm_3b050
inc de
ld a, [de]
ld [hli], a
dec c
jr nz, .asm_3b050
ret
2014-08-09 05:39:13 +00:00
Evolution_FlagAction: ; 3b057 (e:7057)
predef_jump FlagActionPredef
2014-05-22 22:13:20 +00:00
INCLUDE "data/evos_moves.asm"