Skip to content

Commit

Permalink
Allow enemy trainer party date in arbitrary banks
Browse files Browse the repository at this point in the history
  • Loading branch information
roukaour committed Apr 27, 2017
1 parent 55daa2e commit 056e7d8
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 158 deletions.
16 changes: 10 additions & 6 deletions engine/wildmons.asm
Expand Up @@ -1011,17 +1011,21 @@ RandomPhoneMon: ; 2a567
dec a
ld c, a
ld b, 0
rept 2
rept 3
add hl, bc
endr
ld a, BANK(TrainerGroups)
call GetFarByte
inc hl
ld [TrainerGroupBank], a
ld a, BANK(TrainerGroups)
call GetFarHalfword

.skip_trainer
dec e
jr z, .skipped
.skip
ld a, BANK(Trainers)
ld a, [TrainerGroupBank]
call GetFarByte
inc hl
cp -1
Expand All @@ -1030,13 +1034,13 @@ endr
.skipped

.skip_name
ld a, BANK(Trainers)
ld a, [TrainerGroupBank]
call GetFarByte
inc hl
cp "@"
jr nz, .skip_name

ld a, BANK(Trainers)
ld a, [TrainerGroupBank]
call GetFarByte
inc hl

Expand Down Expand Up @@ -1082,7 +1086,7 @@ endr
.count_mon
inc e
add hl, bc
ld a, BANK(Trainers)
ld a, [TrainerGroupBank]
call GetFarByte
cp -1
jr nz, .count_mon
Expand All @@ -1103,7 +1107,7 @@ endr
.got_mon

inc hl ; species
ld a, BANK(Trainers)
ld a, [TrainerGroupBank]
call GetFarByte
ld [wNamedObjectIndexBuffer], a
call GetPokemonName
Expand Down
2 changes: 1 addition & 1 deletion main.asm
Expand Up @@ -1912,7 +1912,7 @@ endr

INCLUDE "trainers/attributes.asm"

SECTION "Enemy Trainer Parties", ROMX[$4000], BANK[$E]
SECTION "Enemy Trainer Pointers", ROMX[$4000], BANK[$E]

INCLUDE "trainers/read_party.asm"

Expand Down
49 changes: 31 additions & 18 deletions trainers/read_party.asm
Expand Up @@ -20,19 +20,19 @@ ReadTrainerParty: ; 39771

call FindTrainerData

ld a, [hli]
call GetNextTrainerDataByte
ld [OtherTrainerType], a

.loop2
; level
ld a, [hli]
call GetNextTrainerDataByte
cp $ff
ret z

ld [CurPartyLevel], a

; species
ld a, [hli]
call GetNextTrainerDataByte
ld [CurPartySpecies], a

ld a, OTPARTYMON
Expand All @@ -57,7 +57,7 @@ ReadTrainerParty: ; 39771
ld e, l
pop hl

ld a, [hli]
call GetNextTrainerDataByte
ld [de], a

.not_item
Expand All @@ -77,21 +77,21 @@ ReadTrainerParty: ; 39771
pop hl

; when reading DVs, $00 means $ff, since $ff is the end-of-trainer marker
ld a, [hli]
call GetNextTrainerDataByte
and a
jr nz, .dv1_ok
ld a, $ff
.dv1_ok
ld [de], a
inc de
ld a, [hli]
call GetNextTrainerDataByte
and a
jr nz, .dv2_ok
ld a, $ff
.dv2_ok
ld [de], a
inc de
ld a, [hli]
call GetNextTrainerDataByte
and a
jr nz, .dv3_ok
ld a, $ff
Expand All @@ -116,10 +116,10 @@ ReadTrainerParty: ; 39771
ld e, l
pop hl

ld a, [hli]
call GetNextTrainerDataByte
ld [de], a
inc de
ld a, [hli]
call GetNextTrainerDataByte
ld [de], a

; TODO: regenerate stats (after TryAddMonToParty) with new nature (will fix #133)
Expand All @@ -133,7 +133,7 @@ ReadTrainerParty: ; 39771
push de
ld de, StringBuffer2
.copy
ld a, [hli]
call GetNextTrainerDataByte
ld [de], a
inc de
cp "@"
Expand Down Expand Up @@ -170,7 +170,7 @@ ReadTrainerParty: ; 39771

ld b, NUM_MOVES
.copy_moves
ld a, [hli]
call GetNextTrainerDataByte
ld [de], a
inc de
dec b
Expand Down Expand Up @@ -227,6 +227,8 @@ Battle_GetTrainerName:: ; 39939
ld a, [InBattleTowerBattle]
bit 0, a
ld hl, OTPlayerName
ld a, BANK(Battle_GetTrainerName) ; make FarCopyBytes act like CopyBytes
ld [TrainerGroupBank], a
jp nz, CopyTrainerName

ld a, [OtherTrainerID]
Expand All @@ -239,9 +241,11 @@ GetTrainerName:: ; 3994c
push bc
ld b, 0
ld hl, TrainerGroups
rept 2
rept 3
add hl, bc
endr
ld a, [hli]
ld [TrainerGroupBank], a
ld a, [hli]
ld h, [hl]
ld l, a
Expand All @@ -252,7 +256,7 @@ endr
jr z, CopyTrainerName

.skip
ld a, [hli]
call GetNextTrainerDataByte
cp $ff
jr nz, .skip
jr .loop
Expand All @@ -261,7 +265,8 @@ CopyTrainerName: ; 39984
ld de, StringBuffer1
push de
ld bc, NAME_LENGTH
call CopyBytes
ld a, [TrainerGroupBank]
call FarCopyBytes
pop de
ret
; 39990
Expand All @@ -281,7 +286,7 @@ SetTrainerBattleLevel:
call FindTrainerData

inc hl
ld a, [hl]
call GetNextTrainerDataByte
ld [CurPartyLevel], a
ret

Expand All @@ -291,9 +296,11 @@ FindTrainerData:
ld c, a
ld b, 0
ld hl, TrainerGroups
rept 2
rept 3
add hl, bc
endr
ld a, [hli]
ld [TrainerGroupBank], a
ld a, [hli]
ld h, [hl]
ld l, a
Expand All @@ -304,14 +311,20 @@ endr
dec b
jr z, .got_trainer
.loop1
ld a, [hli]
call GetNextTrainerDataByte
cp $ff
jr nz, .loop1
jr .skip_trainer
.got_trainer

.skip_name
ld a, [hli]
call GetNextTrainerDataByte
cp "@"
jr nz, .skip_name
ret

GetNextTrainerDataByte:
ld a, [TrainerGroupBank]
call GetFarByte
inc hl
ret

0 comments on commit 056e7d8

Please sign in to comment.