BattleArcadeLobby_MapScriptHeader:

;trigger count
	db 0
;callback count
	db 0

BattleArcadeLobbyInstructionsNPC:
	jumptextfaceplayer BattleArcadeLobbyInstructionsNPC_Text

BattleArcadeLobbyBattleNPC:
	opentext
	special PlaceMoneyTopRight
	writetext BattleArcadeLobbyBattleNPC_Text_Enter
	loadmenudata BattleArcadeLobby_EnterMenu
	verticalmenu
	closewindow
	anonjumptable
	dw .come_back_later
	dw .enter
	dw .instructions
	dw .come_back_later
.instructions
	writetext BattleArcadeLobbyBattleNPC_Text_Instructions
	waitbutton
	writetext BattleArcadeLobbyBattleNPC_Text_EnterInsist
	yesorno
	sif false
.come_back_later
		jumptext BattleArcadeLobby_Text_ComeBackLater
.enter
	checkcode VAR_PARTYCOUNT
	sif <, 3
		jumptext BattleArcadeLobby_Text_RequireThreePokemon
	callasm BattleArcadeLobby_LegalityCheck
	sif <, 3
		jumptext BattleArcadeLobby_Text_NotLevelForty
	checkmoney 0, 500
	sif =, 2
		jumptext BattleArcadeLobby_Text_NeedMoreMoney
	takemoney 0, 500
	waitsfx ;wait for the text's "click" sound to end
	special PlaceMoneyTopRight
	playwaitsfx SFX_TRANSACTION
.selection_loop
	writetext BattleArcadeLobby_Text_SelectParty
	waitbutton
	callasm BattleArcadeLobby_LegalityCheck
	callasm ChooseThreePartyMonsForBattle
	sif false, then
		writetext BattleArcadeLobby_Text_CancelChallenge
		yesorno
		iffalse .selection_loop
		givemoney 0, 500
		jumptext BattleArcadeLobby_Text_Refund
	sendif
	writetext BattleArcadeLobby_Text_EnterToBegin
	waitbutton
	closetext
	applymovement PLAYER, .entrance_movement
	special ClearBGPalettes
	warpsound
	waitsfx
	warp BATTLE_ARCADE_BATTLEROOM, 4, 7
	applymovement PLAYER, .approach_machine
	farscall MainArcadeScript
	applymovement PLAYER, .leave_machine
	warpsound
	waitsfx
	warp BATTLE_ARCADE_LOBBY, 5, 0
	applymovement PLAYER, .exit_movement
	spriteface PLAYER, UP
	jumptext BattleArcadeLobby_Text_ThanksForPlaying
.entrance_movement
	step_right
	step_right
	step_right
	step_up
	step_up
	step_up
	remove_person
	step_end
.exit_movement
	step_down
	step_down
	step_down
	step_left
	step_left
	step_left
	step_end
.approach_machine
	step_left
	step_left
	step_up
	step_up
	step_up
	step_left
	step_end
.leave_machine
	step_right
	step_down
	step_down
	step_down
	step_right
	step_right
	turn_head_down
	remove_person
	step_end

BattleArcadeLobby_EnterMenu:
	db $40 ;flags (?)
	db 4, 4 ;start coordinates (y, x)
	db 11, 19 ;end coordinates (y, x) -- final y - initial y = 2 * items + 1, final x - initial x = longest item + 3
	dw .options
	db 1 ;default option
.options
	db $a0 ;flags 2.0 (??)
	db 3 ;option count
	db "Enter arcade@"
	db "Instructions@"
	db "Cancel@"

BattleArcadeLobbyRedeemNPC:
	opentext
	pokemart 6, 0
	closetext
	end

BattleArcadeLobby_Door:
	jumptext BattleArcadeLobby_Text_Door

BattleArcadeLobby_HighScoreDisplay:
	jumptext BattleArcadeLobby_Text_HighScores

BattleArcadeLobbyInstructionsNPC_Text:
	db TX_COMPRESSED, $29, $27, $15, $ed, $df, $4d, $10, $10, $5a
	db $78, $c8, $c8, $5a, $25, $9a, $e6, $ac
	db $d5, $32, $17, $c4, $74, $ec, $fa
	db $09, $52, $f4, $99, $0b, $e3, $13, $67, $9e

	db $20, $0a, $49, $c7, $c2, $b3, $98, $0f, $94, $da
	db $1e, $04, $16, $a5, $43, $24, $19, $26
	db $aa, $58, $6a, $fc, $b4, $9c, $7c, $2b
	db $35, $55, $ad, $9d, $c9, $c2, $86, $ca, $91, $da
	db $15, $02, $0b, $53, $93, $bf

	db $00, $72, $85, $a8, $ce, $92, $1d, $3a, $ca, $74, $9c
	db $9b, $d6, $93, $7e, $60, $15, $c4, $05, $f3
	db $54, $c8, $43, $d8, $8b, $6b, $0c, $38
	db $d3, $40

BattleArcadeLobbyRedeemNPC_Text_Redeem:
	db TX_COMPRESSED, $6e, $7d, $64, $2f, $9f

	db $10, $0d, $ce, $33, $a4, $8b, $3c, $99, $bf, $01, $05, $a5
	db $bd, $5a, $d9, $dc, $9c, $28, $6c, $a9, $1d
	db $a1, $56, $01, $5c, $10, $b1, $89, $b3, $44, $49, $ac, $f8

	db $d3, $40

BattleArcadeLobbyBattleNPC_Text_Enter:
	db TX_COMPRESSED, $6e, $7d, $64, $2f, $9c, $b0, $cb, $49
	db $bc, $25, $b7, $7d, $39, $5a, $d9, $dc, $9f

	db $10, $0e, $ae, $32, $14, $5a, $20, $9a, $d7, $05, $b1, $60, $58
	db $78, $41, $ae, $5a, $c1, $7a, $37, $0b, $5d
	db $ca, $a0, $41, $6a, $74, $6a, $47, $2c
	db $2a, $8c, $96, $6b, $a5
	db $a6, $80

BattleArcadeLobbyBattleNPC_Text_Instructions:
	db TX_COMPRESSED, $72, $85, $a9, $50, $fb, $d9, $86, $b2, $73
	db $5e, $41, $ac, $66, $88, $1c, $22, $f4, $99, $0b

	db $e0, $04, $6a, $ec, $66, $88, $d1, $2c, $7d, $80, $82, $d2
	db $de, $11, $ab, $b0, $53, $0d, $19, $2d, $13, $49
	db $95, $40, $82, $d4, $67, $49, $4c, $8c, $84, $96, $32, $34, $7e

	db $00, $e5, $0b, $4b, $9c, $3c, $32, $a1, $f7, $b1, $59
	db $bc, $b3, $45, $85, $67, $98, $ac, $ee, $a3, $32

	db $00, $57, $b7, $7d, $34, $7e, $2b, $6a, $e0, $20, $b4
	db $b7, $84, $6a, $ec, $14, $a8, $7d, $ec, $20, $6e, $2b
	db $35, $41, $b4, $9a, $ea, $1a, $0e, $24, $f7, $a7, $9f

	db $00, $29, $27, $04, $6a, $ec, $66, $89, $50, $fb
	db $d7, $95, $9c, $e4, $c8, $6b, $db, $3c

	db $80, $5e, $93, $21, $7f, $a0, $a6, $dc, $b4
	db $9b, $c8, $bd, $5d, $c0, $e1, $0c, $18, $d6

	db $08, $02, $bd, $bb, $e9, $fe, $69, $33, $2d, $26
	db $09, $ea, $87, $de, $c4, $74, $35, $74, $14, $58, $d0

	db $60, $06, $49, $91, $e1, $80, $d9, $6b, $b6, $0a, $6a
	db $1e, $04, $16, $a0, $85, $87, $95, $9a, $11

	db $e0, $15, $dc, $b4, $9c, $32, $66, $07
	db $07, $8c, $18, $d6, $0a, $2c, $2d, $13, $3f, $80, $82, $d2

	db $c0, $08, $35, $e0, $15, $bf, $a4, $64, $e0
	db $c8, $f2, $bd, $bb, $e9, $ca, $87, $de, $c5

	db $66, $01, $0c, $85, $67, $9f, $cd, $26, $60, $20
	db $b4, $f5, $43, $ef, $62, $cd, $93, $18, $31, $cd

	db $00, $46, $9f, $56, $6b, $81, $c2, $08, $08, $c9, $68
	db $79, $5e, $a0, $f3, $02, $48, $3b, $f4, $29

	db $26, $03, $5f, $0b, $44, $b8, $1c, $20, $80, $8c, $96
	db $87, $81, $05, $a8, $b3, $64, $c6, $0c, $70, $c1, $8d, $60

	db $80, $2c, $2d, $13, $32, $a1, $f7, $b1, $59
	db $bc, $fb, $5d, $b1, $88, $e8, $cf, $31, $58, $29, $69

	db $30, $0b, $0b, $44, $cc, $23, $4f, $ab, $35, $fe, $20
	db $2f, $6c, $e8, $49, $c9, $ae, $22, $d6, $7a

	db $a4, $02, $a1, $f7, $b0, $10, $cf, $b9, $8f, $b4, $ca
	db $5e, $48, $f9, $49, $ae, $21, $90, $ac, $d1

	db $e0, $0d, $d2, $64, $80, $82, $d4, $c0, $64, $1a
	db $12, $f0, $20, $b4, $b8, $af, $6e, $fa, $68

	db $f8, $00, $41, $69, $72, $c3, $7b, $d8, $86, $42, $b3
	db $7a, $a1, $f7, $b1, $59, $c4, $24, $35, $13

	db $e0, $34, $99, $80, $82, $d4, $a8, $7d
	db $eb, $cb, $36, $4c, $60, $c7, $02, $43

	db $01, $5a, $d9, $dc, $9c, $28, $6c, $a9, $1d, $cc, $02
	db $b7, $8c, $18, $d6, $0a, $0b, $21, $60, $58, $82, $02, $32, $5a

	db $3c, $01, $ca, $16, $a3, $3a, $48, $74, $eb, $29, $d2, $72
	db $6f, $5a, $42, $83, $96, $36, $54, $8e, $d1, $02

	db $40, $16, $93, $8c, $85, $a2, $59, $ae, $04
	db $8f, $5a, $4e, $2c, $7c, $a6, $e6, $01
	db $5a, $a0, $6d, $58, $c2, $d2, $20, $85, $8c, $4d, $9a

	db $3d, $4d

BattleArcadeLobbyBattleNPC_Text_EnterInsist:
	db TX_COMPRESSED, $50, $1f, $cc, $86, $02, $0b, $52, $ad, $25, $cb
	db $0b, $c6, $4b, $35, $d2, $c7, $57, $19, $0a, $2d
	db $0a, $84, $d6, $b8, $2d, $8b, $02, $c4, $10, $6b, $96, $b0, $5e
	db $a6, $80

BattleArcadeLobby_Text_ComeBackLater:
	db TX_COMPRESSED, $76, $26, $25, $a4, $c9, $f8, $c8, $5f
	db $37, $95, $eb, $2a, $51, $01, $7c, $e0, $6d, $26
	db $b5, $56, $37, $cf
	db $8d, $34

BattleArcadeLobby_Text_RequireThreePokemon:
	db TX_COMPRESSED, $72, $85, $a8, $fb, $48, $b8, $9d, $06
	db $37, $b6, $e7, $4f, $51, $72, $d2, $b3

	db $30, $00, $e5, $7c, $24, $83, $24, $04, $16
	db $96, $f5, $9e, $bf, $2c, $30, $c9, $66, $bf

	db $00, $72, $85, $a8, $ce, $92, $34, $83, $96, $93
	db $79, $90, $be, $21, $ab, $35, $c2, $1e, $ad, $58

	db $20, $16, $18, $15, $f3, $a4, $18, $9b, $38, $08, $2d
	db $2d, $eb, $3d, $7f
	db $d4, $d0

BattleArcadeLobby_Text_NeedMorePoints:
	db TX_COMPRESSED, $72, $85, $a9, $90, $92, $99, $13, $a0
	db $c6, $f1, $90, $2d, $72, $99, $63, $65, $48, $ed, $1e
	db $a6, $80

BattleArcadeLobby_Text_NotLevelForty:
	db TX_COMPRESSED, $50, $15, $ac, $17, $e0, $20, $b4
	db $b7, $81, $ca, $f8, $49, $1f, $69, $17, $15

	db $98, $0d, $b9, $d3, $d4, $5c, $e9, $83, $1f, $65, $3f, $16
	db $1e, $b0, $c1, $1a, $bb, $1b, $23, $11, $b6, $7e

	db $00, $e5, $0b, $51, $9d, $24, $69, $07, $2d
	db $26, $f3, $21, $7c, $43, $56, $6b, $84, $3d, $5a, $b0

	db $40, $2c, $30, $2b, $e7, $48, $31, $36, $70, $10, $5a
	db $5b, $d6, $7a, $ff
	db $a9, $a0

BattleArcadeLobby_Text_SelectParty:
	db TX_COMPRESSED, $e1, $e9, $ea, $0e, $20, $fa, $6c, $dc, $b4
	db $9b, $c0, $e5, $7c, $24, $80, $82, $d4, $ab, $49
	db $6a, $ac, $31, $5e, $dd, $f4, $e5, $43, $b4
	db $fa, $9a

BattleArcadeLobby_Text_EnterToBegin:
	db TX_COMPRESSED, $6e, $12, $64, $d7, $83, $5d

	db $e2, $03, $87, $a7, $a8, $38, $64, $b3, $5c, $b4
	db $9b, $da, $b6, $77, $27, $16, $10, $bf, $2c

	db $20, $15, $9f, $23, $24, $04, $16
	db $96, $f2, $bd, $bb, $e9, $a3
	db $8d, $34

BattleArcadeLobby_Text_AlreadyHaveItem:
	db TX_COMPRESSED, $72, $85, $a9, $bd, $59, $ee, $41, $44, $e8, $31
	db $bd, $69, $1a, $20, $ec, $df
	db $f5, $34

BattleArcadeLobby_Text_NeedMoreMoney:
	db TX_COMPRESSED, $50, $15, $ac, $17, $e0, $20, $b5, $32, $12, $53
	db $1e, $4e, $83, $1c, $32, $05, $ae, $53, $1f, $09, $0c
	db $12, $ab, $0c, $32, $59, $af
	db $d4, $d0

BattleArcadeLobby_Text_ThanksForPlaying:
	db TX_COMPRESSED, $29, $3a, $45, $24, $4c, $02
	db $b7, $84, $77, $41, $0c, $9c, $fe, $32, $17
	db $cd, $56, $f3, $a3, $27
	db $1a, $68

BattleArcadeLobby_Text_CancelChallenge:
	db TX_COMPRESSED, $ad, $67, $01, $05, $a8, $86, $96, $70, $10, $5a
	db $7a, $ad, $25, $cb, $0c, $e9, $e8, $31, $d2
	db $d3, $40

BattleArcadeLobby_Text_Refund:
	db TX_COMPRESSED, $72, $85, $a5, $c1, $35, $ae, $0b, $62, $c0, $b1, $2a, $1f, $7b, $08, $1a
	db $9e, $56, $71, $67, $83, $44, $c9, $e7

	db $c0, $1b, $9c, $48, $44, $1c, $04, $16, $a1, $92, $cd
	db $6f, $5a, $4e, $32, $9d, $ef, $4c, $9c, $9c, $21, $d3
	db $b6, $aa, $c6, $f9, $fa, $36, $85, $f3, $9b, $ce, $8c, $9c
	db $69, $a0

BattleArcadeLobby_Text_Door:
	db TX_COMPRESSED, $75, $70, $68, $9d, $0b, $2a, $47, $9e
	db $2f, $57, $10, $3e, $49, $02, $48, $3b, $88, $d0, $48

	db $f8, $01, $2a, $ca, $2b, $1c, $5d, $2b, $72, $36, $d7, $c0, $2e
	db $7b, $87, $1e, $b7, $28, $b9, $c8, $a2, $3b, $07, $e3, $b9
	db $69, $a0

BattleArcadeLobby_Text_HighScores:
	start_asm
	push bc
	ld hl, wBattleArcadeMaxScore
	ld a, [hli]
	ld b, a
	ld a, [hli]
	ld c, a
	ld a, [hli]
	ld d, a
	ld a, [hli]
	ld e, a
	push hl
	ld hl, wStringBuffer1
	ld a, $8a
	ld [hDigitsFlags], a
	predef PrintBigNumber
	ld bc, 0
	pop hl
	ld a, [hli]
	ld d, a
	ld e, [hl]
	ld a, 3
	ld [hDigitsFlags], a
	ld hl, wStringBuffer3
	predef PrintBigNumber
	ld a, "@"
	ld [wStringBuffer1 + 10], a
	ld [wStringBuffer3 + 3], a
	pop bc
	ld hl, .text
	ret
.text
	db TX_COMPRESSED, $6d, $69, $6b, $32, $5c, $ad, $6c, $ee
	db $4d, $e4, $8f, $94, $c4, $32, $15, $9a, $1c

	db $40, $28, $64, $2b, $37, $18, $0e
	db $43, $ce, $40, $b4, $4c, $a2, $54, $12, $38, $c9, $29
	db $e5, $4d

BattleArcadeLobby_LegalityCheck:
	ld hl, wPartyCount
	ld a, [hli]
	ld c, a
	ld d, a
	ld b, 0
.loop_species
	sla b
	ld a, [hli]
	and a
	jr z, .checked_species
	inc a
	jr z, .checked_species
	cp EGG + 1 ; a has been incremented
	jr z, .checked_species
	set 0, b
.checked_species
	dec c
	jr nz, .loop_species
	ld c, d
	push bc
	ld b, 0
	ld de, wPartyMon2 - wPartyMon1
	ld hl, PartyMon1Level
.loop_level
	sla b
	ld a, [hl]
	add hl, de
	cp 40
	jr c, .checked_level
	set 0, b
.checked_level
	dec c
	jr nz, .loop_level
	ld a, b
	pop bc
	and b
	ld b, 0
	ld d, b
.loop_bits
	rrca
	jr nc, .no_increment
	inc d
.no_increment
	rl b
	dec c
	jr nz, .loop_bits
	ld a, d
	ld [hScriptVar], a
	ld a, b
	ld [wBattleTowerLegalPokemonFlags], a
	ret

BattleArcadeLobby_MapEventHeader:: db 0, 0

.Warps: db 2
	warp_def 9, 5, 1, ROUTE_86
	warp_def 9, 6, 1, ROUTE_86

.CoordEvents: db 0

.BGEvents: db 2
	signpost 0, 5, SIGNPOST_READ, BattleArcadeLobby_Door
	signpost 2, 4, SIGNPOST_READ, BattleArcadeLobby_HighScoreDisplay

.ObjectEvents: db 3
	person_event SPRITE_LASS, 5, 6, SPRITEMOVEDATA_WANDER, 0, 0, -1, -1, PAL_OW_RED, 0, 0, BattleArcadeLobbyInstructionsNPC, -1
	person_event SPRITE_RECEPTIONIST, 1, 9, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_PURPLE, 0, 0, BattleArcadeLobbyRedeemNPC, -1
	person_event SPRITE_RECEPTIONIST, 1, 2, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_YELLOW, 0, 0, BattleArcadeLobbyBattleNPC, -1

