ref: 0dc5ae04b82143b1cbff50a9d25ebe21326305ae
dir: /misc/battle_tower_5c.asm/
BattleTowerBattle: ; 170215 xor a ld [wcf63], a call _BattleTowerBattle ret ; 17021d EmptySpecial_17021d: ; 17021d ret ; 17021e Function17021e: ; 17021e xor a ld [wcf63], a ld [wcf64], a ld [wcf65], a ld [wcf66], a ret ; 17022c _BattleTowerBattle: ; 17022c .loop call .do_jumptable call DelayFrame ld a, [wcf63] cp $1 jr nz, .loop ret ; 17023a .do_jumptable: ; 17023a ld a, [wcf63] ld e, a ld d, 0 ld hl, .jumptable rept 2 add hl, de endr ld a, [hli] ld h, [hl] ld l, a jp [hl] ; 170249 .jumptable: ; 170249 dw RunBattleTowerTrainer dw SkipBattleTowerTrainer ; 17024d RunBattleTowerTrainer: ; 17024d ld a, [Options] push af ld hl, Options set BATTLE_SHIFT, [hl] ; SET MODE ld a, [InBattleTowerBattle] push af or $1 ld [InBattleTowerBattle], a xor a ld [wLinkMode], a callba Mobile_HealParty callba HealParty call ReadBTTrainerParty call Clears5_a89a predef StartBattle callba LoadPokemonData callba HealParty ld a, [wBattleResult] ld [ScriptVar], a and a jr nz, .lost ld a, BANK(sNrOfBeatenBattleTowerTrainers) call GetSRAMBank ld a, [sNrOfBeatenBattleTowerTrainers] ld [wNrOfBeatenBattleTowerTrainers], a ; wcf64 call CloseSRAM ld hl, StringBuffer3 ld a, [wNrOfBeatenBattleTowerTrainers] ; wcf64 add "1" ld [hli], a ld a, "@" ld [hl], a .lost pop af ld [InBattleTowerBattle], a pop af ld [Options], a ld a, $1 ld [wcf63], a ret ReadBTTrainerParty: ; 1702b7 ; Initialise the BattleTower-Trainer and his Pkmn call CopyBTTrainer_FromBT_OT_TowBT_OTTemp ; Check the nicknames for illegal characters, and replace bad nicknames ; with their species names. ld de, wBT_OTTempPkmn1Name ; $c643 ld c, PKMN_NAME_LENGTH callba CheckStringForErrors jr nc, .skip_mon_1 ld a, [wBT_OTTempPkmn1] ld [wNamedObjectIndexBuffer], a call GetPokemonName ld l, e ld h, d ld de, wBT_OTTempPkmn1Name ; $c643 ld bc, PKMN_NAME_LENGTH call CopyBytes .skip_mon_1 ld de, wBT_OTTempPkmn2Name ; $c67e ld c, PKMN_NAME_LENGTH callba CheckStringForErrors jr nc, .skip_mon_2 ld a, [wBT_OTTempPkmn2] ; [$c64e] ld [wNamedObjectIndexBuffer], a call GetPokemonName ld l, e ld h, d ld de, wBT_OTTempPkmn2Name ; $c67e ld bc, PKMN_NAME_LENGTH call CopyBytes .skip_mon_2 ld de, wBT_OTTempPkmn3Name ; $c686 + 51 = $c6b9 ld c, PKMN_NAME_LENGTH callba CheckStringForErrors jr nc, .skip_mon_3 ld a, [wBT_OTTempPkmn3] ; [$c689] ld [wNamedObjectIndexBuffer], a call GetPokemonName ld l, e ld h, d ld de, wBT_OTTempPkmn3Name ; $c686 + 51 = $c6b9 ld bc, PKMN_NAME_LENGTH call CopyBytes .skip_mon_3 ; Add the terminator character to each of these names ld a, "@" ld [wBT_OTTempPkmn1NameEnd - 1], a ; $c64d ld [wBT_OTTempPkmn2NameEnd - 1], a ; $c688 ld [wBT_OTTempPkmn3NameEnd - 1], a ; $c68a + 57 = $c6c3 ; Fix errors in the movesets call CheckBTMonMovesForErrors ; Repair the trainer name if needed, then copy it to OTPlayerName ld de, wBT_OTTempName ld c, NAME_LENGTH - 1 callba CheckStringForErrors jr nc, .trainer_name_okay ld hl, BT_ChrisName jr .done_trainer_name .trainer_name_okay ld hl, wBT_OTTempName ; 0xc608 .done_trainer_name ld de, OTPlayerName ld bc, NAME_LENGTH - 1 call CopyBytes ld a, "@" ld [de], a ld hl, wBT_OTTempTrainerClass ld a, [hli] ld [OtherTrainerClass], a ld a, OTPartyMonNicknames % $100 ld [BGMapBuffer], a ld a, OTPartyMonNicknames / $100 ld [BGMapBuffer + 1], a ; Copy Pkmn into Memory from the address in hl ld de, OTPartyMon1Species ld bc, OTPartyCount ld a, BATTLETOWER_NROFPKMNS ; Number of Pkmn the BattleTower-Trainer has ld [bc], a inc bc .otpartymon_loop push af ld a, [hl] ld [bc], a inc bc push bc ld bc, PARTYMON_STRUCT_LENGTH call CopyBytes push de ld a, [BGMapBuffer] ld e, a ld a, [BGMapBuffer + 1] ld d, a ld bc, PKMN_NAME_LENGTH call CopyBytes ld a, e ld [BGMapBuffer], a ld a, d ld [BGMapBuffer + 1], a pop de pop bc pop af dec a and a jr nz, .otpartymon_loop ld a, -1 ld [bc], a ret ; 170394 ValidateBTParty: ; 170394 ; Check for and fix errors in party data ld hl, wBT_OTTempPkmn1Species ld d, BATTLETOWER_NROFPKMNS .pkmn_loop push de push hl ld b, h ld c, l ld a, [hl] and a idx = $ff rept ($ff +- NUM_POKEMON) jr z, .invalid cp idx idx = idx +- 1 endr jr nz, .valid .invalid ld a, SMEARGLE ld [hl], a .valid ld [CurSpecies], a call GetBaseData ld a, $5 call GetSRAMBank ld a, [$b2fb] ; s5_b2fb ; max level? call CloseSRAM ld e, a ld hl, MON_LEVEL add hl, bc ld a, [hl] cp MIN_LEVEL ld a, MIN_LEVEL jr c, .load ld a, [hl] cp e jr c, .dont_load ld a, e .load ld [hl], a .dont_load ld [CurPartyLevel], a ld hl, MON_MOVES add hl, bc ld d, NUM_MOVES - 1 ld a, [hli] and a jr z, .not_move cp NUM_ATTACKS + 1 jr nc, .not_move jr .valid_move .not_move dec hl ld a, POUND ld [hli], a xor a rept 2 ld [hli], a endr ld [hl], a jr .done_moves .valid_move ld a, [hl] cp NUM_ATTACKS + 1 jr c, .next ld [hl], $0 .next inc hl dec d jr nz, .valid_move .done_moves ld hl, MON_MAXHP add hl, bc ld d, h ld e, l push hl push de ld hl, MON_EXP + 2 add hl, bc ld b, $1 predef CalcPkmnStats pop de pop hl rept 2 dec de endr ld a, [hli] ld [de], a inc de ld a, [hl] ld [de], a pop hl ld bc, PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH add hl, bc pop de dec d jp nz, .pkmn_loop ret ; 170426 BT_ChrisName: ; 170426 db "CHRIS@" ; 17042c