pokered/engine/battle/read_trainer_party.asm

167 lines
3.6 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
ReadTrainer:
2015-04-01 15:27:51 +00:00
; don't change any moves in a link battle
ld a, [wLinkState]
2015-04-01 15:27:51 +00:00
and a
ret nz
; set [wEnemyPartyCount] to 0, [wEnemyPartySpecies] to FF
2015-04-01 15:27:51 +00:00
; XXX first is total enemy pokemon?
; XXX second is species of first pokemon?
ld hl, wEnemyPartyCount
2015-04-01 15:27:51 +00:00
xor a
ld [hli], a
2015-04-01 15:27:51 +00:00
dec a
ld [hl], a
2015-04-01 15:27:51 +00:00
; get the pointer to trainer data for this class
ld a, [wCurOpponent]
2020-11-05 21:55:39 +00:00
sub OPP_ID_OFFSET + 1 ; convert value from pokemon to trainer
add a
ld hl, TrainerDataPointers
ld c, a
ld b, 0
add hl, bc ; hl points to trainer class
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wTrainerNo]
ld b, a
2015-04-01 15:27:51 +00:00
; At this point b contains the trainer number,
; and hl points to the trainer class.
; Our next task is to iterate through the trainers,
; decrementing b each time, until we get to the right one.
.outer
dec b
jr z, .IterateTrainer
2015-04-01 15:27:51 +00:00
.inner
ld a, [hli]
2015-04-01 15:27:51 +00:00
and a
jr nz, .inner
2015-04-01 15:27:51 +00:00
jr .outer
; if the first byte of trainer data is FF,
; - each pokemon has a specific level
; (as opposed to the whole team being of the same level)
2015-08-31 02:38:41 +00:00
; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
2015-04-01 15:27:51 +00:00
; else the first byte is the level of every pokemon on the team
.IterateTrainer
ld a, [hli]
2015-04-01 15:27:51 +00:00
cp $FF ; is the trainer special?
jr z, .SpecialTrainer ; if so, check for special moves
ld [wCurEnemyLVL], a
2015-04-01 15:27:51 +00:00
.LoopTrainerData
ld a, [hli]
2015-04-01 15:27:51 +00:00
and a ; have we reached the end of the trainer data?
jr z, .FinishUp
ld [wcf91], a ; write species somewhere (XXX why?)
ld a, ENEMY_PARTY_DATA
ld [wMonDataLocation], a
2015-04-01 15:27:51 +00:00
push hl
call AddPartyMon
pop hl
jr .LoopTrainerData
.SpecialTrainer
; if this code is being run:
; - each pokemon has a specific level
; (as opposed to the whole team being of the same level)
2015-08-31 02:38:41 +00:00
; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
ld a, [hli]
2015-04-01 15:27:51 +00:00
and a ; have we reached the end of the trainer data?
jr z, .AddLoneMove
ld [wCurEnemyLVL], a
ld a, [hli]
ld [wcf91], a
ld a, ENEMY_PARTY_DATA
ld [wMonDataLocation], a
2015-04-01 15:27:51 +00:00
push hl
call AddPartyMon
pop hl
jr .SpecialTrainer
.AddLoneMove
2020-11-05 21:55:39 +00:00
; does the trainer have a single monster with a different move?
ld a, [wLoneAttackNo] ; Brock is 01, Misty is 02, Erika is 04, etc
2015-04-01 15:27:51 +00:00
and a
jr z, .AddTeamMove
2015-04-01 15:27:51 +00:00
dec a
add a
ld c, a
ld b, 0
ld hl, LoneMoves
add hl, bc
ld a, [hli]
ld d, [hl]
ld hl, wEnemyMon1Moves + 2
ld bc, wEnemyMon2 - wEnemyMon1
2015-04-01 15:27:51 +00:00
call AddNTimes
ld [hl], d
2015-04-01 15:27:51 +00:00
jr .FinishUp
.AddTeamMove
; check if our trainer's team has special moves
; get trainer class number
ld a, [wCurOpponent]
sub OPP_ID_OFFSET
ld b, a
ld hl, TeamMoves
2015-04-01 15:27:51 +00:00
; iterate through entries in TeamMoves, checking each for our trainer class
.IterateTeamMoves
ld a, [hli]
2015-04-01 15:27:51 +00:00
cp b
jr z, .GiveTeamMoves ; is there a match?
2015-04-01 15:27:51 +00:00
inc hl ; if not, go to the next entry
inc a
jr nz, .IterateTeamMoves
2015-04-01 15:27:51 +00:00
; no matches found. is this trainer champion rival?
ld a, b
2020-07-17 17:27:27 +00:00
cp RIVAL3
jr z, .ChampionRival
2015-04-01 15:27:51 +00:00
jr .FinishUp ; nope
.GiveTeamMoves
ld a, [hl]
ld [wEnemyMon5Moves + 2], a
2015-04-01 15:27:51 +00:00
jr .FinishUp
.ChampionRival ; give moves to his team
; pidgeot
ld a, SKY_ATTACK
ld [wEnemyMon1Moves + 2], a
2015-04-01 15:27:51 +00:00
; starter
ld a, [wRivalStarter]
2015-04-01 15:27:51 +00:00
cp STARTER3
ld b, MEGA_DRAIN
jr z, .GiveStarterMove
2015-04-01 15:27:51 +00:00
cp STARTER1
ld b, FIRE_BLAST
jr z, .GiveStarterMove
ld b, BLIZZARD ; must be squirtle
2015-04-01 15:27:51 +00:00
.GiveStarterMove
ld a, b
ld [wEnemyMon6Moves + 2], a
2015-04-09 11:05:57 +00:00
.FinishUp
; clear wAmountMoneyWon addresses
2015-06-11 22:41:33 +00:00
xor a
ld de, wAmountMoneyWon
ld [de], a
2015-04-01 15:27:51 +00:00
inc de
ld [de], a
2015-04-01 15:27:51 +00:00
inc de
ld [de], a
ld a, [wCurEnemyLVL]
ld b, a
2015-04-01 15:27:51 +00:00
.LastLoop
2015-04-09 11:05:57 +00:00
; update wAmountMoneyWon addresses (money to win) based on enemy's level
ld hl, wTrainerBaseMoney + 1
ld c, 2 ; wAmountMoneyWon is a 3-byte number
2015-04-01 15:27:51 +00:00
push bc
predef AddBCDPredef
pop bc
inc de
inc de
dec b
jr nz, .LastLoop ; repeat wCurEnemyLVL times
2015-06-02 03:15:02 +00:00
ret