2018-06-24 07:09:41 -07:00
|
|
|
Function_LoadOpponentTrainerAndPokemons:
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rSVBK]
|
2017-12-26 19:57:19 -08:00
|
|
|
push af
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, BANK(wBT_OTTrainer)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2017-12-26 19:57:19 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
; Fill wBT_OTTrainer with zeros
|
2017-12-26 19:57:19 -08:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wBT_OTTrainer
|
2019-01-02 16:04:50 -08:00
|
|
|
ld bc, BATTLE_TOWER_STRUCT_LENGTH
|
2017-12-26 19:57:19 -08:00
|
|
|
call ByteFill
|
|
|
|
|
|
|
|
; Write $ff into the Item-Slots
|
|
|
|
ld a, $ff
|
2018-02-22 08:13:29 -08:00
|
|
|
ld [wBT_OTMon1Item], a
|
|
|
|
ld [wBT_OTMon2Item], a
|
|
|
|
ld [wBT_OTMon3Item], a
|
2017-12-26 19:57:19 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
; Set wBT_OTTrainer as start address to write the following data to
|
|
|
|
ld de, wBT_OTTrainer
|
2017-12-26 19:57:19 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hRandomAdd]
|
2017-12-26 19:57:19 -08:00
|
|
|
ld b, a
|
|
|
|
.resample ; loop to find a random trainer
|
|
|
|
call Random
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hRandomAdd]
|
2017-12-26 19:57:19 -08:00
|
|
|
add b
|
|
|
|
ld b, a ; b contains the nr of the trainer
|
2018-01-09 14:26:40 -08:00
|
|
|
if DEF(_CRYSTAL11)
|
2018-01-16 14:27:50 -08:00
|
|
|
maskbits BATTLETOWER_NUM_UNIQUE_TRAINERS
|
2018-01-09 23:55:44 -08:00
|
|
|
cp BATTLETOWER_NUM_UNIQUE_TRAINERS
|
2017-12-28 18:22:35 -08:00
|
|
|
else
|
2018-01-10 10:59:07 -08:00
|
|
|
; Crystal 1.0 used the wrong constant here, so only the first 21
|
2018-01-09 23:55:44 -08:00
|
|
|
; trainers in BattleTowerTrainers can be sampled.
|
2018-02-22 08:13:29 -08:00
|
|
|
maskbits BATTLETOWER_NUM_UNIQUE_MON
|
|
|
|
cp BATTLETOWER_NUM_UNIQUE_MON
|
2017-12-28 18:22:35 -08:00
|
|
|
endc
|
2017-12-26 19:57:19 -08:00
|
|
|
jr nc, .resample
|
|
|
|
ld b, a
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2017-12-26 19:57:19 -08:00
|
|
|
ld a, BANK(sBTTrainers)
|
|
|
|
call GetSRAMBank
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2018-01-20 09:25:55 -08:00
|
|
|
ld c, BATTLETOWER_STREAK_LENGTH
|
2017-12-26 19:57:19 -08:00
|
|
|
ld hl, sBTTrainers
|
|
|
|
.next_trainer
|
|
|
|
ld a, [hli]
|
|
|
|
cp b
|
|
|
|
jr z, .resample
|
|
|
|
dec c
|
|
|
|
jr nz, .next_trainer ; c <= 7 initialise all 7 trainers?
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2017-12-26 19:57:19 -08:00
|
|
|
ld hl, sBTTrainers
|
|
|
|
ld a, [sNrOfBeatenBattleTowerTrainers]
|
|
|
|
ld c, a
|
2015-10-16 10:35:43 -07:00
|
|
|
ld a, b
|
2017-12-26 19:57:19 -08:00
|
|
|
ld b, 0
|
|
|
|
add hl, bc
|
|
|
|
ld [hl], a
|
|
|
|
|
|
|
|
call CloseSRAM
|
|
|
|
|
|
|
|
push af
|
|
|
|
; Copy name (10 bytes) and class (1 byte) of trainer
|
|
|
|
ld hl, BattleTowerTrainers
|
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call AddNTimes
|
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
|
|
|
|
2018-02-22 08:13:29 -08:00
|
|
|
call Function_LoadRandomBattleTowerMon
|
2017-12-26 19:57:19 -08:00
|
|
|
pop af
|
|
|
|
|
|
|
|
ld hl, BattleTowerTrainerData
|
|
|
|
ld bc, BATTLETOWER_TRAINERDATALENGTH
|
|
|
|
call AddNTimes
|
|
|
|
ld bc, BATTLETOWER_TRAINERDATALENGTH
|
|
|
|
.copy_bt_trainer_data_loop
|
|
|
|
ld a, BANK(BattleTowerTrainerData)
|
|
|
|
call GetFarByte
|
|
|
|
ld [de], a
|
|
|
|
inc hl
|
2015-10-16 10:35:43 -07:00
|
|
|
inc de
|
2017-12-26 19:57:19 -08:00
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
|
|
|
jr nz, .copy_bt_trainer_data_loop
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2017-12-26 19:57:19 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2015-10-16 10:35:43 -07:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Function_LoadRandomBattleTowerMon:
|
2018-01-20 09:25:55 -08:00
|
|
|
ld c, BATTLETOWER_PARTY_LENGTH
|
2017-12-26 19:57:19 -08:00
|
|
|
.loop
|
2015-10-16 10:35:43 -07:00
|
|
|
push bc
|
2018-02-22 08:13:29 -08:00
|
|
|
ld a, BANK(sBTMonPrevTrainer1)
|
2017-12-26 19:57:19 -08:00
|
|
|
call GetSRAMBank
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2018-02-22 08:13:29 -08:00
|
|
|
.FindARandomBattleTowerMon:
|
|
|
|
; From Which LevelGroup are the mon loaded
|
2017-12-26 19:57:19 -08:00
|
|
|
; a = 1..10
|
2018-01-02 21:19:54 -08:00
|
|
|
ld a, [wBTChoiceOfLvlGroup]
|
2017-12-26 19:57:19 -08:00
|
|
|
dec a
|
|
|
|
ld hl, BattleTowerMons
|
2019-01-02 16:04:50 -08:00
|
|
|
ld bc, BATTLETOWER_NUM_UNIQUE_MON * NICKNAMED_MON_STRUCT_LENGTH
|
2017-12-26 19:57:19 -08:00
|
|
|
call AddNTimes
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hRandomAdd]
|
2017-12-26 19:57:19 -08:00
|
|
|
ld b, a
|
|
|
|
.resample
|
|
|
|
call Random
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hRandomAdd]
|
2017-12-26 19:57:19 -08:00
|
|
|
add b
|
|
|
|
ld b, a
|
2018-02-22 08:13:29 -08:00
|
|
|
maskbits BATTLETOWER_NUM_UNIQUE_MON
|
|
|
|
cp BATTLETOWER_NUM_UNIQUE_MON
|
2017-12-26 19:57:19 -08:00
|
|
|
jr nc, .resample
|
2018-02-22 08:13:29 -08:00
|
|
|
; in register 'a' is the chosen mon of the LevelGroup
|
2017-12-26 19:57:19 -08:00
|
|
|
|
2018-02-22 08:13:29 -08:00
|
|
|
; Check if mon was already loaded before
|
2017-12-26 19:57:19 -08:00
|
|
|
; Check current and the 2 previous teams
|
|
|
|
; includes check if item is double at the current team
|
2019-01-02 16:04:50 -08:00
|
|
|
ld bc, NICKNAMED_MON_STRUCT_LENGTH
|
2017-12-26 19:57:19 -08:00
|
|
|
call AddNTimes
|
2015-10-16 10:35:43 -07:00
|
|
|
ld a, [hli]
|
2017-12-26 19:57:19 -08:00
|
|
|
ld b, a
|
|
|
|
ld a, [hld]
|
2015-10-16 10:35:43 -07:00
|
|
|
ld c, a
|
2018-02-22 08:13:29 -08:00
|
|
|
ld a, [wBT_OTMon1]
|
2015-10-16 10:35:43 -07:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [wBT_OTMon1Item]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp c
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [wBT_OTMon2]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [wBT_OTMon2Item]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp c
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [wBT_OTMon3]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [wBT_OTMon3Item]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp c
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [sBTMonPrevTrainer1]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [sBTMonPrevTrainer2]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [sBTMonPrevTrainer3]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [sBTMonPrevPrevTrainer1]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [sBTMonPrevPrevTrainer2]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
|
|
|
ld a, [sBTMonPrevPrevTrainer3]
|
2017-12-26 19:57:19 -08:00
|
|
|
cp b
|
2018-02-22 08:13:29 -08:00
|
|
|
jr z, .FindARandomBattleTowerMon
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2019-01-02 16:04:50 -08:00
|
|
|
ld bc, NICKNAMED_MON_STRUCT_LENGTH
|
2017-12-26 19:57:19 -08:00
|
|
|
call CopyBytes
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2017-12-26 19:57:19 -08:00
|
|
|
ld a, [wNamedObjectIndexBuffer]
|
|
|
|
push af
|
2015-10-16 10:35:43 -07:00
|
|
|
push de
|
2019-01-02 16:04:50 -08:00
|
|
|
ld hl, -NICKNAMED_MON_STRUCT_LENGTH
|
2017-12-26 19:57:19 -08:00
|
|
|
add hl, de
|
2015-10-16 10:35:43 -07:00
|
|
|
ld a, [hl]
|
2017-12-26 19:57:19 -08:00
|
|
|
ld [wNamedObjectIndexBuffer], a
|
2015-11-04 08:19:58 -08:00
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
2015-10-16 10:35:43 -07:00
|
|
|
add hl, bc
|
2017-12-26 19:57:19 -08:00
|
|
|
push hl
|
|
|
|
call GetPokemonName
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
pop de
|
2018-01-20 09:25:55 -08:00
|
|
|
ld bc, MON_NAME_LENGTH
|
2017-12-26 19:57:19 -08:00
|
|
|
call CopyBytes
|
2015-10-16 10:35:43 -07:00
|
|
|
|
2017-12-26 19:57:19 -08:00
|
|
|
pop de
|
|
|
|
pop af
|
|
|
|
ld [wNamedObjectIndexBuffer], a
|
2015-10-16 10:35:43 -07:00
|
|
|
pop bc
|
|
|
|
dec c
|
2017-12-26 19:57:19 -08:00
|
|
|
jp nz, .loop
|
|
|
|
|
2018-02-22 08:13:29 -08:00
|
|
|
ld a, [sBTMonPrevTrainer1]
|
|
|
|
ld [sBTMonPrevPrevTrainer1], a
|
|
|
|
ld a, [sBTMonPrevTrainer2]
|
|
|
|
ld [sBTMonPrevPrevTrainer2], a
|
|
|
|
ld a, [sBTMonPrevTrainer3]
|
|
|
|
ld [sBTMonPrevPrevTrainer3], a
|
|
|
|
ld a, [wBT_OTMon1]
|
|
|
|
ld [sBTMonPrevTrainer1], a
|
|
|
|
ld a, [wBT_OTMon2]
|
|
|
|
ld [sBTMonPrevTrainer2], a
|
|
|
|
ld a, [wBT_OTMon3]
|
|
|
|
ld [sBTMonPrevTrainer3], a
|
2017-12-26 19:57:19 -08:00
|
|
|
call CloseSRAM
|
|
|
|
ret
|
|
|
|
|
2018-01-09 13:55:11 -08:00
|
|
|
INCLUDE "data/battle_tower/classes.asm"
|
|
|
|
|
2018-01-06 15:53:30 -08:00
|
|
|
INCLUDE "data/battle_tower/parties.asm"
|