BattleArcadeLobby_MapScriptHeader:

;trigger count
	db 0
;callback count
	db 0

BattleArcadeLobbyBattleNPC:
	opentext
	special PlaceMoneyTopRight
	writetext .enter_text
	menuanonjumptable .menu
	dw .come_back_later
	dw .enter
	dw .instructions
	dw .come_back_later

.instructions
	writetext .instructions_text
	yesorno
	sif false
.come_back_later
		jumptext .come_back_later_text
.enter
	checkcode VAR_PARTYCOUNT
	sif <, 3
		jumptext .three_pokemon_text
	callasm BattleArcadeLobby_LegalityCheck
	sif <, 3
		jumptext .level_forty_text
	checkmoney 0, 500
	sif =, 2
		jumptext .not_enough_money_text
	takemoney 0, 500
	waitsfx ;wait for the text's "click" sound to end
	special PlaceMoneyTopRight
	playwaitsfx SFX_TRANSACTION

.selection_loop
	writetext .select_party_text
	callasm BattleArcadeLobby_LegalityCheck
	callasm ChooseThreePartyMonsForBattle
	sif false, then
		writetext .cancel_challenge_text
		yesorno
		iffalse .selection_loop
		givemoney 0, 500
		jumptext .refund_text
	sendif
	writetext .enter_to_begin_text
	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 .thanks_for_playing_text

.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

.menu
	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 .menu_options
	db 1 ;default option
.menu_options
	db $a0 ;flags 2.0 (??)
	db 3 ;option count
	db "Enter arcade@"
	db "Instructions@"
	db "Cancel@"

.enter_text
	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

	db $78, $03, $70, $b5, $dc, $c0, $41, $6a, $74, $6a
	db $46, $f5, $86, $19, $2c, $d7
	db $4b, $4d

.instructions_text
	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, $15, $ed, $df, $4d, $11, $a2, $58
	db $fa, $f0, $20, $b4, $b8, $23, $57, $60, $a0
	db $d0, $ab, $27, $81, $ed, $9e

	db $7c, $01, $ca, $16, $97, $01, $ca, $f8, $49, $8a, $70, $f0
	db $bd, $50, $fb, $d8, $ac, $e2, $cd, $16, $15, $9e
	db $40, $2b, $3b, $a8, $cc, $91, $5e, $dd, $f4, $d1
	db $f7, $b4, $99, $96, $93, $1a, $e2, $2f, $6d, $a4
	db $00, $64, $24, $c8, $ec, $61, $22, $25, $43, $ef, $62, $b3
	db $79, $27, $bd, $3c, $97, $c4, $86, $a3, $06, $35
	db $fd, $55, $a4, $c6, $b8, $c7, $86, $54, $12, $53, $22, $b3

	db $f0, $02, $92, $71, $5e, $dd, $f4, $d1, $2a, $1f
	db $7a, $f2, $3a, $1a, $ba, $0a, $2c, $68, $38, $32
	db $00, $c8, $f0, $c0, $6c, $b5, $db, $05, $35
	db $0f, $02, $0b, $50, $42, $c3, $ca, $cd, $08

	db $f0, $0a, $ee, $5a, $4e, $19, $33, $03
	db $83, $c6, $0c, $6b, $05, $16, $16, $89, $9f, $c0, $41
	db $68, $05, $43, $ef, $62, $cd, $93, $18, $31, $cd
	db $78, $8d, $3e, $ac, $d7, $03, $84, $10, $11, $92
	db $d0, $01, $5e, $a0, $f3, $02, $48, $08, $2d
	db $2d, $e1, $06, $bc, $02, $b7, $f4, $8c, $9f

	db $80, $14, $93, $9a, $f8, $5a, $25, $c0
	db $e0, $f0, $80, $8c, $96, $88, $08, $2d
	db $00, $59, $b2, $63, $06, $39, $50, $fb, $d8, $ac
	db $de, $7d, $ae, $d8, $c4, $74, $67, $98, $ac, $14, $b4
	db $98, $05, $85, $a2, $66, $11, $a7, $d5, $9a, $ff, $10
	db $17, $ad, $60, $a5, $86, $72, $77, $36, $74, $24
	db $e5, $55, $43, $24, $45, $ac, $f5, $4b

	db $88, $0a, $ee, $5a, $4e, $19, $33, $f8, $08, $2d
	db $2d, $eb, $0d, $ef, $62, $19, $0a, $ce, $54, $3e
	db $f4, $02, $b3, $88, $48, $6a, $24, $d2, $66, $02, $0b
	db $4f, $54, $3e, $f6, $2c, $d9, $31, $83, $1c, $d2
	db $00, $ad, $6c, $ee, $4e, $14, $36, $54, $8e, $e6, $01
	db $5b, $c6, $0c, $6b, $05, $05, $90, $b0, $2c, $41, $01, $19, $2d, $1e

	db $00, $e5, $0b, $51, $9d, $24, $3a, $75, $94, $e9, $39
	db $37, $ad, $21, $41, $cb, $1b, $2a, $47, $68, $81
	db $20, $0b, $49, $c6, $42, $d1, $2c, $d7, $02
	db $47, $ad, $27, $16, $3e, $53, $73, $00
	db $ad, $50, $36, $ac, $61, $69, $10, $42, $c6, $26, $cd, $1e
	
	db $00, $a0, $3f, $99, $0c, $04, $16, $a5, $5a, $4b, $96
	db $17, $8c, $96, $6b, $a5, $8e, $ae, $32, $14, $5a
	db $15, $09, $ad, $70, $5b, $16, $05, $88, $20, $d7, $2d, $60
	db $bd, $4d

.come_back_later_text
	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

.three_pokemon_text
	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

.level_forty_text
	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

.not_enough_money_text
	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

.select_party_text
	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, $9e, $20

.cancel_challenge_text
	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

.refund_text
	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

.enter_to_begin_text
	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, $3c, $40

.thanks_for_playing_text
	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

BattleArcadeLobbyInstructionsNPC:
	db TX_COMPRESSED, $29, $27, $15, $ed, $df, $4d, $10, $10, $5a
	db $78, $c8, $c8, $5a, $25, $9a, $e6, $ac
	db $c0, $32, $17, $c4, $74, $ec, $fa
	db $09, $e5, $e9, $32, $17, $c6, $26, $cf, $3c

	db $40, $14, $93, $8f, $85, $67, $30, $1f, $29, $b4
	db $3c, $08, $2d, $4a, $86, $48, $32, $4d
	db $00, $b0, $d5, $f9, $69, $38, $f8, $56
	db $6f, $56, $b6, $77, $27, $0a, $1b, $2a, $47, $68
	db $54, $08, $2d, $4e, $4e

	db $fc, $01, $ca, $16, $a3, $3a, $48, $74, $eb, $29, $d2, $72
	db $6f, $5a, $4d, $f9, $80, $57, $10, $17
	db $cd, $53, $21, $0f, $62, $2d, $ac, $30
	db $e3, $4d

BattleArcadeLobby_Door:
	db TX_COMPRESSED, $75, $78, $a7, $42, $ca, $91, $e7
	db $8b, $d5, $c4, $0f, $92, $40, $92, $0e, $e2, $34, $12

	db $3e, $00, $4a, $b2, $8a, $c7, $17, $4a, $dc, $8d, $b5, $f0, $0b
	db $9e, $e1, $c7, $ad, $ca, $2e, $72, $28, $8e, $c1, $f8, $ee
	db $5a, $68

BattleArcadeLobby_HighScoreDisplay:
	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, wPartyMon1Level
.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_TEXT, BattleArcadeLobby_Door
	signpost 2, 4, SIGNPOST_TEXT, BattleArcadeLobby_HighScoreDisplay

.ObjectEvents
	db 3
	person_event SPRITE_LASS, 5, 6, SPRITEMOVEDATA_WANDER, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_TEXTFP, 0, BattleArcadeLobbyInstructionsNPC, -1
	person_event SPRITE_RECEPTIONIST, 1, 9, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_PURPLE, PERSONTYPE_MART, 0, MART_BATTLEARCADE, 0, -1
	person_event SPRITE_RECEPTIONIST, 1, 2, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_YELLOW, PERSONTYPE_SCRIPT, 0, BattleArcadeLobbyBattleNPC, -1

