PhloxLab1F_MapScriptHeader;trigger count
	db 0
 ;callback count
	db 1

	dbw MAPCALLBACK_TILES, PhloxLabF1Tiles

PhloxLabF1_Item:
	db MAX_REVIVE, 1

PhloxLabF1RefreshMap:
	changemap BANK(PhloxLab1F_BlockData), PhloxLab1F_BlockData

; fallthrough	
PhloxLabF1Tiles:
	checkevent EVENT_PHLOX_LAB_RED_ON
	sif false, then
		changeblock 12, 18, $3a
		changeblock 2, 2, $3a
		changeblock 8, 16, $57
		changeblock 8, 18, $3b
	sendif

	checkevent EVENT_PHLOX_LAB_BLUE_ON
	sif false, then
		changeblock 20, 18, $3a
		changeblock 20, 2, $3a
		changeblock 20, 4, $3f
		changeblock 22, 4, $41
	sendif

	checkevent EVENT_PHLOX_LAB_GREEN_ON
	sif false, then
		changeblock 6, 18, $3a
		changeblock 4, 22, $3a
		changeblock 8, 4, $3b
		changeblock 6, 4, $3f
	sendif

	checkevent EVENT_PHLOX_LAB_YELLOW_ON
	sif false, then
		changeblock 16, 2, $3a
		changeblock 8, 6, $3a
	sendif

	checkevent EVENT_PHLOX_LAB_BROWN_ON
	sif true
		return
	changeblock 16, 22, $3a
	changeblock 12, 2, $3a
	return

PhloxLab1FRedWarp1:
	switch 0

PhloxLab1FRedWarp2:
	switch 1

PhloxLab1FBlueWarp1:
	switch 2

PhloxLab1FBlueWarp2:
	switch 3

PhloxLab1FGreenWarp1:
	switch 4

PhloxLab1FGreenWarp2:
	switch 5

PhloxLab1FYellowWarp1:
	switch 6

PhloxLab1FYellowWarp2:
	switch 7

PhloxLab1FBrownWarp1:
	switch 8

PhloxLab1FBrownWarp2:
	writebyte 9
	sendif
	playsound SFX_WARP_TO
	applymovement 0, PhloxLabWarpFrom
	special FadeOutPalettes
	loadarray PhloxLabWarpCoordsArray
	cmdwitharrayargs .CustomWarpEnd - .CustomWarp
.CustomWarp:
	db warp_command, %110
	map PHLOX_LAB_1F
	db 0, 1
.CustomWarpEnd:
	playsound SFX_WARP_FROM
	applymovement 0, PhloxLabWarpTo
	end

PhloxLabWarpCoordsArray:
	db 03, 02
PhloxLabWarpCoordsArrayEntrySizeEnd:
	db 13, 18
	db 21, 02
	db 21, 18
	db 05, 22
	db 07, 18
	db 17, 02
	db 09, 06
	db 17, 22
	db 13, 02

PhloxLabWarpFrom:
	teleport_from
	step_end

PhloxLabWarpTo:
	teleport_to
	step_end

PhloxLabRedSwitch:
	switch 0

PhloxLabBlueSwitch:
	switch 1

PhloxLabGreenSwitch:
	switch 2

PhloxLabYellowSwitch:
	switch 3

PhloxLabBrownSwitch:
	writebyte 4

; toggle switch
	sendif
	loadarray PhloxLabSwitchArray
	readarrayhalfword 0
	checkevent -1
	sif false, then
		setevent -1
	selse
		clearevent -1
	sendif

	scall PhloxLabF1RefreshMap
	waitsfx
	playwaitsfx SFX_TWO_PC_BEEPS
	readarrayhalfword 2
	jumptext -1

PhloxLabSwitchArray:
	dw EVENT_PHLOX_LAB_RED_ON, PhloxLabRedSwitchText
PhloxLabSwitchArrayEntrySizeEnd:
	dw EVENT_PHLOX_LAB_BLUE_ON, PhloxLabBlueSwitchText
	dw EVENT_PHLOX_LAB_GREEN_ON, PhloxLabGreenSwitchText
	dw EVENT_PHLOX_LAB_YELLOW_ON, PhloxLabYellowSwitchText
	dw EVENT_PHLOX_LAB_BROWN_ON, PhloxLabBrownSwitchText

PhloxLabF1_YellowPalette:
	trainer EVENT_PHLOX_LAB_F1_YELLOW_PALETTE, PATROLLER, 17, PhloxLabF1_YellowPalette_Text, PhloxLabF1_YellowPalette_Lose_Text, $0000, .Script

.Script
	end_if_just_battled
	jumptext PhloxLabF1_YellowPalette_Script_Text

PhloxLabF1_Trainer_1:
	trainer EVENT_PHLOX_LAB_F1_TRAINER_1, SCIENTIST, 4, PhloxLabF1_Trainer_1_Text, PhloxLabF1_Trainer_1_Lose_Text, $0000, .Script

.Script
	end_if_just_battled
	jumptext PhloxLabF1_Trainer_1_Script_Text

PhloxLabF1_Trainer_2:
	trainer EVENT_PHLOX_LAB_F1_TRAINER_2, SCIENTIST, 5, PhloxLabF1_Trainer_2_Text, PhloxLabF1_Trainer_2_Lose_Text, $0000, .Script

.Script
	end_if_just_battled
	jumptext PhloxLabF1_Trainer_2_Script_Text

PhloxLabF1_Trainer_3:
	trainer EVENT_PHLOX_LAB_F1_TRAINER_3, SCIENTIST, 6, PhloxLabF1_Trainer_3_Text, PhloxLabF1_Trainer_3_Lose_Text, $0000, .Script

.Script
	end_if_just_battled
	jumptext PhloxLabF1_Trainer_3_Script_Text

PhloxLabF1_Trainer_4:
	trainer EVENT_PHLOX_LAB_F1_TRAINER_4, SCIENTIST, 7, PhloxLabF1_Trainer_4_Text, PhloxLabF1_Trainer_4_Lose_Text, $0000, .Script

.Script
	end_if_just_battled
	jumptext PhloxLabF1_Trainer_4_Script_Text

PhloxLabF1_Trainer_1_Text:
	db TX_COMPRESSED, $13, $48, $08, $f5, $68, $81, $c2, $3e, $79, $1b, $3b
	db $d7, $84, $f0, $1c, $af, $84, $93, $49, $b6, $17, $c1
	db $2a, $45, $b5, $90, $52, $a1, $f7, $b3, $91, $83, $1c, $7c
	db $d5, $5a, $4e, $34, $20, $41, $ae, $27, $49, $98, $32
	db $2a, $b4, $8d, $11, $5e, $dd, $f4, $f8
	db $d3, $40

PhloxLabF1_Trainer_1_Lose_Text:
	db TX_COMPRESSED, $a7, $80, $4d, $20, $23, $d5, $a2, $55, $a8, $b3, $cd, $3c
	db $14, $d0

PhloxLabF1_Trainer_1_Script_Text:
	db TX_COMPRESSED, $13, $2d, $67, $91, $93, $98, $ac, $14, $b4, $9c, $ab, $41
	db $3c, $08, $2d, $4c, $07, $ca, $6f, $f0, $10, $5a

	db $00, $fb, $48, $b8, $ac, $e6, $cb, $5b
	db $46, $f0, $39, $5f, $09, $20, $85, $87, $23, $e4, $17
	db $a9, $a0

PhloxLabF1_Trainer_2_Text:
	db TX_COMPRESSED, $a7, $80, $11, $a2
	db $96, $9a

PhloxLabF1_Trainer_2_Lose_Text:
	db TX_COMPRESSED, $29, $26, $0a, $64, $24, $a6, $41, $1a, $0a, $3e
	db $6f, $19, $02, $d7, $29, $96, $18, $ce, $ac, $e0, $f0
	db $54, $ea, $74, $28, $b9, $61, $80, $82, $d7
	db $a9, $a0

PhloxLabF1_Trainer_2_Script_Text:
	db TX_COMPRESSED, $75, $10, $90, $b5, $dc, $c6, $42, $44, $0f, $26
	db $b7, $b6, $33, $ab, $33, $5c, $65, $3a, $4e, $4f
	db $d4, $d0

PhloxLabF1_Trainer_3_Text:
	db TX_COMPRESSED, $75, $29, $c6, $91, $71, $03, $e4, $87, $98, $d0
	db $87, $b0, $0a, $e5, $a4, $e7, $26, $43, $58, $5a
	db $42, $a4, $9e, $f6, $d2, $ce, $ac, $e0, $8e, $e9

	db $3c, $00, $a4, $9a, $cf, $14, $20, $65, $5a, $0a, $3a, $2c
	db $7b, $a7, $76, $32, $73, $01, $05, $a9, $7a, $a4
	db $6a, $b2, $1a, $89, $2d, $23, $44, $64, $2f, $88, $d2, $02
	db $f5, $34

PhloxLabF1_Trainer_3_Lose_Text:
	db TX_COMPRESSED, $76, $99, $51, $f7, $bf, $9c, $b4, $68, $44
	db $74, $f1, $0c, $f3, $2c, $33, $01, $f4, $e6, $01
	db $5a, $a6, $88, $6f, $88, $e8, $41, $3e, $64, $b8, $40, $d5
	db $ea, $68

PhloxLabF1_Trainer_3_Script_Text:
	db TX_COMPRESSED, $75, $84, $04, $16, $a5, $46, $b3, $8f, $85
	db $66, $f3, $21, $22, $07, $93, $5e, $d9, $fe, $02, $0b

	db $40, $2a, $0b, $5d, $c9, $29, $92, $9c, $31, $01, $5e, $46, $26
	db $cd, $e0, $b4, $b8, $6f, $88, $e8, $41, $3e, $64, $bf
	db $53, $40

PhloxLabF1_Trainer_4_Text:
	db TX_COMPRESSED, $29, $26, $b3, $83, $44, $40, $63, $ed, $32
	db $97, $96, $68, $3d, $5b, $29, $88, $b1, $f7
	db $aa, $ba, $78, $5c, $b0, $c5, $67, $32, $12, $1f

	db $10, $0e, $a5, $43, $ef, $62, $2c, $22, $20, $20, $b5
	db $c6, $9a

PhloxLabF1_Trainer_4_Lose_Text:
	db TX_COMPRESSED, $75, $1f, $69, $17, $04, $2c, $d0, $6b, $06
	db $37, $9f, $05, $30, $19, $32, $32, $72, $89, $80
	db $56, $ab, $bb, $66, $b8, $21, $a5, $7d, $1a, $12, $32, $73
	db $ea, $68

PhloxLabF1_Trainer_4_Script_Text:
	db TX_COMPRESSED, $74, $59, $39, $08, $c9, $cc, $b0, $c7, $f5, $48
	db $de, $b4, $8d, $11, $90, $be, $23, $48, $0a, $3f, $a4
	db $04, $a9, $f1, $f7, $a3, $09, $11, $f8, $80, $be, $79, $d0, $5e

	db $00, $52, $4c, $92, $d2, $60, $9c, $3d, $89, $d0, $63
	db $7a, $c3, $15, $b4, $f8, $88, $d0, $88, $f8
	db $25, $4f, $9e, $a3, $a0, $a2, $37, $ba, $b0, $5e
	db $a6, $80

PhloxLabF1_YellowPalette_Text:
	db TX_COMPRESSED, $e1, $de, $9d, $d9, $c7, $21, $e6, $55, $a8, $9a
	db $47, $b6, $ac, $1a, $ec, $e9, $ee, $4d, $72, $d3

	db $b6, $00, $86, $0c, $6b, $9a, $20, $42, $cd, $91, $ed, $9e
	db $5e, $7c, $14, $c3, $50, $91, $84, $91, $16, $0b, $a7

	db $e0, $05, $27, $6f, $14, $a9, $20, $a2, $4e, $55, $a8
	db $78, $f5, $03, $e8, $28, $d0, $84, $5e, $f2, $79, $8a, $c1
	db $2a, $d8, $a4, $3c, $ce, $8d, $48, $e0, $20, $b5
	db $ea, $68

PhloxLabF1_YellowPalette_Lose_Text:
	db TX_COMPRESSED, $07, $87, $8c, $29, $27, $2c, $d6, $b1, $ab, $e9
	db $bd, $d1, $f2, $9b, $19, $39, $8b, $68, $64, $3c, $c7, $c1
	db $2a, $42, $43, $73, $6e, $5a, $46, $8e
	db $34, $d0

PhloxLabF1_YellowPalette_Script_Text:
	db TX_COMPRESSED, $53, $0a, $f9, $3b, $96, $91, $a2, $08, $ee, $b2, $7c

	db $40, $0a, $e8, $25, $67, $1d, $38, $7b, $39, $0c, $0b
	db $56, $f5, $86, $09, $8d, $e8, $51

	db $e0, $0e, $8b, $22, $1a, $59, $c4, $05, $f3, $09
	db $0d, $e0, $b5, $72, $d2, $6b, $39, $50, $fb

	db $d0, $1a, $20, $42, $cd, $91, $ed, $9c, $7c
	db $13, $c8, $b0, $5d, $39, $a4, $cc, $53, $c7, $ad, $c8, $2e
	db $e3, $4d

PhloxLabRedSwitchText:
	db TX_COMPRESSED, $e1, $59, $a1, $07, $99, $69, $38, $e4, $3c
	db $bc, $a2, $a1, $db, $29
	db $e3, $4d

PhloxLabBlueSwitchText:
	db TX_COMPRESSED, $e1, $59, $a1, $07, $99, $69, $38, $25, $d6
	db $8d, $e5, $15, $0e, $d9, $4f
	db $1a, $68

PhloxLabGreenSwitchText:
	db TX_COMPRESSED, $e1, $59, $a1, $07, $99, $69, $38, $c2, $59, $99
	db $1e, $51, $50, $ed, $94, $f1
	db $a6, $80

PhloxLabYellowSwitchText:
	db TX_COMPRESSED, $e1, $59, $a1, $07, $99, $69, $38, $e5, $3e, $f4, $35
	db $3c, $a2, $a1, $db, $29
	db $e3, $4d

PhloxLabBrownSwitchText:
	db TX_COMPRESSED, $e1, $59, $a1, $07, $99, $69, $38, $24, $b0, $d4
	db $47, $94, $54, $3b, $65, $3c
	db $69, $a0

PhloxLab1F_MapEventHeader:: db 0, 0

.Warps: db 3
	warp_def 23, 14, 3, PHLOX_TOWN
	warp_def 23, 15, 3, PHLOX_TOWN
	warp_def 7, 18, 1, PHLOX_LAB_2F

.CoordEvents: db 10
	xy_trigger 0, 18, 13, $0, PhloxLab1FRedWarp1, EVENT_PHLOX_LAB_RED_ON
	xy_trigger 0, 02, 03, $0, PhloxLab1FRedWarp2, EVENT_PHLOX_LAB_RED_ON
	xy_trigger 0, 18, 21, $0, PhloxLab1FBlueWarp1, EVENT_PHLOX_LAB_BLUE_ON
	xy_trigger 0, 02, 21, $0, PhloxLab1FBlueWarp2, EVENT_PHLOX_LAB_BLUE_ON
	xy_trigger 0, 18, 07, $0, PhloxLab1FGreenWarp1, EVENT_PHLOX_LAB_GREEN_ON
	xy_trigger 0, 22, 05, $0, PhloxLab1FGreenWarp2, EVENT_PHLOX_LAB_GREEN_ON
	xy_trigger 0, 06, 09, $0, PhloxLab1FYellowWarp1, EVENT_PHLOX_LAB_YELLOW_ON
	xy_trigger 0, 02, 17, $0, PhloxLab1FYellowWarp2, EVENT_PHLOX_LAB_YELLOW_ON
	xy_trigger 0, 02, 13, $0, PhloxLab1FBrownWarp1, EVENT_PHLOX_LAB_BROWN_ON
	xy_trigger 0, 22, 17, $0, PhloxLab1FBrownWarp2, EVENT_PHLOX_LAB_BROWN_ON

.BGEvents: db 5
	signpost 16, 16, SIGNPOST_UP, PhloxLabRedSwitch
	signpost 0, 4, SIGNPOST_UP, PhloxLabBlueSwitch
	signpost 0, 16, SIGNPOST_UP, PhloxLabGreenSwitch
	signpost 16, 2, SIGNPOST_UP, PhloxLabYellowSwitch
	signpost 0, 12, SIGNPOST_UP, PhloxLabBrownSwitch

.ObjectEvents: db 6
	person_event SPRITE_SCIENTIST, 20, 3, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, PAL_OW_BLUE, 2, 3, PhloxLabF1_Trainer_1, EVENT_PHLOX_LAB_CEO
	person_event SPRITE_SCIENTIST, 3, 4, SPRITEMOVEDATA_STANDING_UP, 0, 0, -1, -1, PAL_OW_BLUE, 2, 3, PhloxLabF1_Trainer_2, EVENT_PHLOX_LAB_CEO
	person_event SPRITE_SCIENTIST, 11, 19, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_OW_BLUE, 2, 3, PhloxLabF1_Trainer_3, EVENT_PHLOX_LAB_CEO
	person_event SPRITE_SCIENTIST, 9, 6, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_OW_BLUE, 2, 3, PhloxLabF1_Trainer_4, EVENT_PHLOX_LAB_CEO
	person_event SPRITE_PALETTE_PATROLLER, 9, 10, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_OW_YELLOW, 2, 3, PhloxLabF1_YellowPalette, EVENT_PHLOX_LAB_CEO
	person_event SPRITE_POKE_BALL, 7, 14, SPRITEMOVEDATA_ITEM_TREE, 0, 0, -1, -1, PAL_OW_YELLOW, 3, TM_METRONOME, 0, EVENT_PHLOX_F1_TM51
	person_event SPRITE_POKE_BALL, 8, 4, SPRITEMOVEDATA_ITEM_TREE, 0, 0, -1, -1, PAL_OW_RED, 1, 0, PhloxLabF1_Item, EVENT_PHLOX_ITEM

