pokecrystal/engine/events/battle_tower/load_trainer.asm

213 lines
4.2 KiB
NASM
Raw Normal View History

2018-06-24 14:09:41 +00:00
Function_LoadOpponentTrainerAndPokemons:
ld a, [rSVBK]
push af
2018-01-23 22:39:09 +00:00
ld a, BANK(wBT_OTTrainer)
ld [rSVBK], a
2018-01-23 22:39:09 +00:00
; Fill wBT_OTTrainer with zeros
xor a
2018-01-23 22:39:09 +00:00
ld hl, wBT_OTTrainer
ld bc, wBT_OTTrainerEnd - wBT_OTTrainer
call ByteFill
; Write $ff into the Item-Slots
ld a, $ff
ld [wBT_OTMon1Item], a
ld [wBT_OTMon2Item], a
ld [wBT_OTMon3Item], a
2018-01-23 22:39:09 +00:00
; Set wBT_OTTrainer as start address to write the following data to
ld de, wBT_OTTrainer
ld a, [hRandomAdd]
ld b, a
.resample ; loop to find a random trainer
call Random
ld a, [hRandomAdd]
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
cp BATTLETOWER_NUM_UNIQUE_TRAINERS
else
2018-01-10 18:59:07 +00:00
; Crystal 1.0 used the wrong constant here, so only the first 21
; trainers in BattleTowerTrainers can be sampled.
maskbits BATTLETOWER_NUM_UNIQUE_MON
cp BATTLETOWER_NUM_UNIQUE_MON
endc
jr nc, .resample
ld b, a
2015-10-16 17:35:43 +00:00
ld a, BANK(sBTTrainers)
call GetSRAMBank
2015-10-16 17:35:43 +00:00
2018-01-20 17:25:55 +00:00
ld c, BATTLETOWER_STREAK_LENGTH
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
ld hl, sBTTrainers
ld a, [sNrOfBeatenBattleTowerTrainers]
ld c, a
2015-10-16 17:35:43 +00:00
ld a, b
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
call Function_LoadRandomBattleTowerMon
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
dec bc
ld a, b
or c
jr nz, .copy_bt_trainer_data_loop
2015-10-16 17:35:43 +00:00
pop af
ld [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
.loop
2015-10-16 17:35:43 +00:00
push bc
ld a, BANK(sBTMonPrevTrainer1)
call GetSRAMBank
2015-10-16 17:35:43 +00:00
.FindARandomBattleTowerMon:
; From Which LevelGroup are the mon loaded
; a = 1..10
ld a, [wBTChoiceOfLvlGroup]
dec a
ld hl, BattleTowerMons
ld bc, BattleTowerMons2 - BattleTowerMons1 ; size of one level group
call AddNTimes
2015-10-16 17:35:43 +00:00
ld a, [hRandomAdd]
ld b, a
.resample
call Random
ld a, [hRandomAdd]
add b
ld b, a
maskbits BATTLETOWER_NUM_UNIQUE_MON
cp BATTLETOWER_NUM_UNIQUE_MON
jr nc, .resample
; in register 'a' is the chosen mon of the LevelGroup
; Check if mon was already loaded before
; Check current and the 2 previous teams
; includes check if item is double at the current team
2018-01-20 17:25:55 +00:00
ld bc, PARTYMON_STRUCT_LENGTH + MON_NAME_LENGTH
call AddNTimes
2015-10-16 17:35:43 +00:00
ld a, [hli]
ld b, a
ld a, [hld]
2015-10-16 17:35:43 +00:00
ld c, a
ld a, [wBT_OTMon1]
2015-10-16 17:35:43 +00:00
cp b
jr z, .FindARandomBattleTowerMon
ld a, [wBT_OTMon1Item]
cp c
jr z, .FindARandomBattleTowerMon
ld a, [wBT_OTMon2]
cp b
jr z, .FindARandomBattleTowerMon
ld a, [wBT_OTMon2Item]
cp c
jr z, .FindARandomBattleTowerMon
ld a, [wBT_OTMon3]
cp b
jr z, .FindARandomBattleTowerMon
ld a, [wBT_OTMon3Item]
cp c
jr z, .FindARandomBattleTowerMon
ld a, [sBTMonPrevTrainer1]
cp b
jr z, .FindARandomBattleTowerMon
ld a, [sBTMonPrevTrainer2]
cp b
jr z, .FindARandomBattleTowerMon
ld a, [sBTMonPrevTrainer3]
cp b
jr z, .FindARandomBattleTowerMon
ld a, [sBTMonPrevPrevTrainer1]
cp b
jr z, .FindARandomBattleTowerMon
ld a, [sBTMonPrevPrevTrainer2]
cp b
jr z, .FindARandomBattleTowerMon
ld a, [sBTMonPrevPrevTrainer3]
cp b
jr z, .FindARandomBattleTowerMon
2015-10-16 17:35:43 +00:00
2018-01-20 17:25:55 +00:00
ld bc, PARTYMON_STRUCT_LENGTH + MON_NAME_LENGTH
call CopyBytes
2015-10-16 17:35:43 +00:00
ld a, [wNamedObjectIndexBuffer]
push af
2015-10-16 17:35:43 +00:00
push de
2018-01-20 17:25:55 +00:00
ld hl, - (PARTYMON_STRUCT_LENGTH + MON_NAME_LENGTH)
add hl, de
2015-10-16 17:35:43 +00:00
ld a, [hl]
ld [wNamedObjectIndexBuffer], a
ld bc, PARTYMON_STRUCT_LENGTH
2015-10-16 17:35:43 +00:00
add hl, bc
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
call CopyBytes
2015-10-16 17:35:43 +00:00
pop de
pop af
ld [wNamedObjectIndexBuffer], a
2015-10-16 17:35:43 +00:00
pop bc
dec c
jp nz, .loop
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
call CloseSRAM
ret
2018-01-09 21:55:11 +00:00
INCLUDE "data/battle_tower/classes.asm"
INCLUDE "data/battle_tower/parties.asm"