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