const_value SET 2
	const BATTLE_TOWER_BATTLE_ROOM_OPPONENT
	const BATTLE_TOWER_BATTLE_ROOM_RECEPTIONIST

BattleTowerBattleRoom_MapScriptHeader:
; triggers
	db 2
	maptrigger .Trigger0
	maptrigger .Trigger1

; callbacks
	db 1
	dbw MAPCALLBACK_NEWMAP, .Callback

.Trigger1
	priorityjump BattleTowerBattleRoom_Script
.Trigger0
	end

.Callback
	disappear BATTLE_TOWER_BATTLE_ROOM_OPPONENT
	return

BattleTowerBattleRoom_Script:
	dotrigger 0
	applymovement PLAYER, .movement_player_battle_position
	callasm BattleTower_LoadChallengeData
	iftrue .notFirstBattle
	; spriteface PLAYER, LEFT
	; applymovement BATTLE_TOWER_BATTLE_ROOM_RECEPTIONIST, .movement_nurse_walks_to_player
	; opentext
	; jump .backToNextBattleMenu
.loop
	callasm BattleTower_LoadCurrentTeam
	playsound SFX_ENTER_DOOR
	appear BATTLE_TOWER_BATTLE_ROOM_OPPONENT
	applymovement BATTLE_TOWER_BATTLE_ROOM_OPPONENT, .movement_opponent_walks_in
	opentext
	battletowertext 1
	closetext
	domaptrigger BATTLE_TOWER_ENTRANCE, 1
	setlasttalked $3
	callasm StartBattleTowerBattle
	reloadmap
	iftrue .exit_failure
	applymovement BATTLE_TOWER_BATTLE_ROOM_OPPONENT, .movement_opponent_walks_out
	playsound SFX_EXIT_BUILDING
	disappear BATTLE_TOWER_BATTLE_ROOM_OPPONENT
	callasm BattleTower_SaveChallengeData
	callasm BattleTower_CheckFought7Trainers
	iffalse .exit_victorious
	writebyte 0

.notFirstBattle
	spriteface PLAYER, LEFT
	applymovement BATTLE_TOWER_BATTLE_ROOM_RECEPTIONIST, .movement_nurse_walks_to_player
	opentext
	iftrue .backToNextBattleMenu
	writetext .heal_party_text
	special HealParty
	playwaitsfx SFX_HEAL_POKEMON
.backToNextBattleMenu
	writetext BattleTowerText_AskNextBattle
.loop_ask
	menuanonjumptable BattleTowerBeforeMatchMenuDataHeader
	dw .loop_ask
	dw .close_text
	dw .quicksave
	dw .close_text_exit_failure

.close_text
	closetext
	spriteface PLAYER, RIGHT
	applymovement BATTLE_TOWER_BATTLE_ROOM_RECEPTIONIST, .movement_nurse_walks_away
	jump .loop

.close_text_exit_failure
	writetext .ask_retire_text
	yesorno
	iffalse .backToNextBattleMenu
	closetext
.exit_failure
	domaptrigger BATTLE_TOWER_ENTRANCE, 4
	jump .return_to_entrance

.exit_victorious
	domaptrigger BATTLE_TOWER_ENTRANCE, 3
.return_to_entrance
	pause 20
	warpfacing UP, BATTLE_TOWER_ENTRANCE, 3, 5
	end

.quicksave
	writetext .ask_save_text
	yesorno
	iffalse .backToNextBattleMenu
	writetext .saving_text
	domaptrigger BATTLE_TOWER_ENTRANCE, 1
	writebyte 2
	scriptstartasm

.BattleTowerReset
	call SetBattleTowerChallengeState
	callba BattleTower_SaveChallengeData
	ld a, $3
	ld [wSpawnAfterChampion], a
	callba SaveGameData
	ld de, SFX_SAVE
	call PlaySFX
	ld c, 1
	call FadeToDarkestColor
	ld a, $1
	ld [hCGBPalUpdate], a
	call DelayFrame
	call WaitSFX
	jp Reset

.movement_player_battle_position
	step_up
	step_up
	step_up
	turn_head_right
	step_end

.movement_opponent_walks_in
	step_down
	step_down
	step_down
	step_down
	turn_head_left
	step_end

.movement_opponent_walks_out
	step_up
	step_up
	step_up
	step_up
	step_end

.movement_nurse_walks_to_player
	step_right
	step_end

.movement_nurse_walks_away
	step_left
	turn_head_right
	step_end

.heal_party_text
	db TX_COMPRESSED, $6e, $72, $a1, $f7, $b0, $81, $aa, $24, $f7
	db $af, $02, $0b, $4b, $80, $e5, $7c, $24
	db $f5, $34

.ask_save_text
	db TX_COMPRESSED, $6e, $16, $bb, $98, $08, $2d, $4e, $8d, $48, $e5
	db $85, $e4, $68, $31, $cd, $26, $62, $cd, $17
	db $4b, $4d

.ask_retire_text
	db TX_COMPRESSED, $e0, $0c, $04, $16, $a5, $43, $42, $65
	db $85, $e5, $9d, $8d, $67, $30, $58, $5f, $96, $91
	db $a1, $53, $29, $de, $f4, $c9, $c9, $d2
	db $d3, $40

.saving_text
	db TX_COMPRESSED, $51, $a0, $c3, $27, $3e, $f7
	db $a9, $a0

BattleTowerBeforeMatchMenuDataHeader:
	db $40 ; flags
	db 00, 00 ; start coords
	db 07, 11 ; end coords
	dw .menu_data
	db 1 ; default option

.menu_data ; 17d297
	db %10000001 ; flags
	db 3
	db "Continue@"
	db "Rest@"
	db "Retire@"

BattleTowerText_AskNextBattle:
	start_asm
	ld a, [rSVBK]
	push af
	wbk BANK(wBT_WinStreak)
	ld a, [wBT_WinStreak]
	ld h, a
	pop af
	ld [rSVBK], a
	ld a, h
	ld hl, .normal_opponent
	cp 20
	jr z, .tycoon
	cp 48
	ret nz
.tycoon
	ld hl, .tycoon_text
	ret

.normal_opponent
	db TX_COMPRESSED, $76, $20, $40, $48, $64, $b8, $40, $fa, $39, $80
	start_asm
	ld a, [rSVBK]
	push af
	wbk BANK(wBT_CurStreak)
	ld a, [wBT_CurStreak]
	add "1"
	ld [bc], a
	pop af
	ld [rSVBK], a
	call JoyTextDelay
	ld hl, .continue_text
	ret

.continue_text
	db TX_COMPRESSED
	db $78, $68, $8d, $08, $84, $3a, $76

	db $fc, $02, $b5, $9c, $04, $16, $a2, $cf, $72, $0a
	db $96, $9a

.tycoon_text
	db TX_COMPRESSED, $6d, $09, $39, $5e, $db, $5d, $db, $18, $48, $88, $12
	db $3d, $50, $c8, $41, $93, $99, $69, $69, $13, $0d, $5f

	db $10, $0e, $98, $0e, $53, $8d, $22, $e2, $b3, $32, $41, $90
	db $0b, $d8, $05, $6f, $9e, $65, $a7, $6e, $05, $a5

	db $80, $34, $59, $9b, $e7, $98, $50, $6a, $35
	db $bc, $50, $26, $42, $12, $44, $19, $a9, $22, $69
	db $15, $6b, $59, $19, $91, $93, $95, $0e, $d3, $01, $05, $af

	db $00, $ad, $67, $01, $05, $a8, $b3, $dc, $82, $96
	db $17, $b5, $96, $4c, $45, $cb, $49, $8d, $71, $94, $ef, $40
	db $aa, $e9, $93, $93, $a5
	db $a6, $80

BattleTowerBattleRoom_MapEventHeader::	db 0, 0

.Warps
	db 2
	warp_def 7, 3, 2, BATTLE_TOWER_HALLWAY
	warp_def 7, 4, 2, BATTLE_TOWER_HALLWAY

.CoordEvents
	db 0

.BGEvents
	db 0

.ObjectEvents
	db 2
	person_event SPRITE_YOUNGSTER, 0, 4, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, 0, PERSONTYPE_SCRIPT, 0, ObjectEvent, EVENT_BATTLE_TOWER_TRAINER
	person_event SPRITE_RECEPTIONIST, 4, 1, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, ObjectEvent, -1

