EagulouGymB1F_MapScriptHeader;trigger count
	db 0
 ;callback count
	db 1
	dbw MAPCALLBACK_TILES, .prison_doors

.prison_doors
	copy wCageKeyDoorsArrayBank
	dba EagulouGymB1FChangeBlockArray
	db (EagulouGymB1FChangeBlockArrayEnd - EagulouGymB1FChangeBlockArray) / 5
	endcopy
	farjump UpdateCageKeyDoorsScript
	
EagulouGymB1FChangeBlockArray:
	eventflagchangeblock EVENT_EAGULOU_DOOR_1, 4, 4, $57
EagulouGymB1FChangeBlockArrayEntrySizeEnd:
	eventflagchangeblock EVENT_EAGULOU_DOOR_2, 16, 4, $57
	eventflagchangeblock EVENT_EAGULOU_DOOR_3, 4, 14, $57
	eventflagchangeblock EVENT_EAGULOU_DOOR_4, 16, 14, $57
EagulouGymB1FChangeBlockArrayEnd:

EagulouGymB1F_CageKey:
	db CAGE_KEY, 1

EagulouGymB1FGuide:
	db TX_COMPRESSED, $29, $23, $44, $1a, $20, $85, $9d, $d8
	db $27, $9f, $69, $94, $cd, $24, $3a, $76, $cc, $88, $18
	db $48, $00, $38, $45, $1b, $4e, $8f, $05, $ef
	db $26, $f3, $a4, $77, $49, $9f

	db $00, $29, $26, $0a, $72, $1b, $88, $0c, $c0, $7d, $e9
	db $e5, $e6, $84, $4b, $4e, $dc, $b4, $98, $29, $51
	db $80, $c9, $b2, $3c, $9e, $65, $86, $5e, $a9
	db $1b, $cc, $ea, $ce, $07, $08, $80, $be, $70, $38
	db $2a, $b4, $98, $d7, $19, $58, $df, $19, $37, $a8
	db $f5, $34

EagulouGymB1FDoor1:
	dw EVENT_EAGULOU_DOOR_1
	writebyte 0
	jump EagulouGymB1FDoor

EagulouGymB1FDoor2:
	dw EVENT_EAGULOU_DOOR_2
	writebyte 1
	jump EagulouGymB1FDoor

EagulouGymB1FDoor4:
	dw EVENT_EAGULOU_DOOR_4
	writebyte 3
	; fallthrough
EagulouGymB1FDoor:
	pushvar
	loadarray .EagulouGymB1FTrainerEventsArray
	readarrayhalfword 0
	checkevent -1
	sif false
		jumptext .keys_wont_work_text
	popvar
	jumpstd cagekeydoor

.EagulouGymB1FTrainerEventsArray:
	dw EVENT_EAGULOU_GYM_B1F_TRAINER_1
.EagulouGymB1FTrainerEventsArrayEntrySizeEnd:
	dw EVENT_EAGULOU_GYM_B1F_TRAINER_3
	dw 0
	dw EVENT_EAGULOU_GYM_B1F_TRAINER_2

.keys_wont_work_text:
	db TX_COMPRESSED, $07, $84, $87, $03, $84, $04, $16, $97, $14, $8c, $12
	db $1e, $a8, $7d, $ec, $a8, $2b, $52, $81
	db $22, $ab, $48, $d1, $32, $10, $af
	db $d4, $d0

EagulouGymB1F_Trainer_1:
	trainer EVENT_EAGULOU_GYM_B1F_TRAINER_1, GRUNTM, 1, .before_battle_text, .battle_won_text, $0000, .script

.script
	opentext
	checkevent EVENT_EAGULOU_JAIL_GOT_NPC_KEY_1
	sif true
		jumptext .after_key_text
	writetext .give_key_text
	verbosegiveitem CAGE_KEY, 1
	sif false, then
		waitbutton
		jumptext EagulouGymB1F_Text_NoSpace
	sendif
	setevent EVENT_EAGULOU_JAIL_GOT_NPC_KEY_1
	closetext
	end

.before_battle_text
	db TX_COMPRESSED, $29, $27, $10, $20, $6b, $1d, $c0, $e1, $0a, $3d
	db $7d, $e7, $20, $59, $52, $3b, $88, $4e, $f7, $b3, $a3, $06
	db $35, $41, $27
	db $1a, $68

.battle_won_text
	db TX_COMPRESSED, $76, $d3, $29, $fc, $c0, $64, $32, $f8, $e9, $c3
	db $d7, $af, $54, $8e, $6c, $56, $b3, $d5, $2f
	db $53, $40

.give_key_text
	db TX_COMPRESSED, $75, $84, $04, $16, $a5, $5a, $4b, $9a, $42, $04
	db $13, $d6, $9d, $b8, $23, $6d, $27, $63
	db $64, $07, $0e, $f4, $ee, $ce, $70, $ed, $ac, $3d, $e9, $af
	db $ef, $5a, $4c, $92, $f5, $48, $e5, $a4, $68
	db $54, $a4, $60
	db $bd, $4f, $10

.after_key_text
	db TX_COMPRESSED, $74, $59, $30, $0a, $cc, $18, $d7, $3a, $10, $5b
	db $d7, $ac, $31, $84, $30, $83, $69, $08, $3f

	db $00, $62, $6e, $1e, $c5, $9d, $b4, $b2, $40, $90
	db $de, $ce, $82, $9a, $4c, $c5, $9b, $44, $1d
	db $9a, $a2, $8f, $5f, $8e, $40, $b2, $a4, $77
	db $c6, $9a

EagulouGymB1F_Trainer_2:
	trainer EVENT_EAGULOU_GYM_B1F_TRAINER_2, SAILOR, 3, .before_battle_text, .battle_won_text, $0000, .script

.script
	opentext
	checkevent EVENT_EAGULOU_JAIL_GOT_NPC_KEY_2
	sif true
		jumptext .after_key_text
	writetext .give_key_text
	verbosegiveitem CAGE_KEY, 1
	sif false, then
		waitbutton
		jumptext EagulouGymB1F_Text_NoSpace
	sendif
	setevent EVENT_EAGULOU_JAIL_GOT_NPC_KEY_2
	closetext
	end

.before_battle_text
	db TX_COMPRESSED, $6d, $d2, $53, $22, $be, $eb, $e7, $36, $72, $d0
	db $27, $b0, $0a, $e5, $ac, $10, $c9, $cc, $b0
	db $80, $48, $e9, $cd, $65, $4a, $6c, $42, $46, $22, $60, $d7
	db $7a, $f0, $70, $8b, $d5, $9c, $07, $2b, $e1, $27
	db $a9, $a0

.battle_won_text
	db TX_COMPRESSED, $61, $34, $68, $44, $75, $39, $0d, $de
	db $bc, $83, $58, $31, $c7, $c1, $4b, $1b, $e7
	db $ea, $68

.give_key_text
	db TX_COMPRESSED, $6e, $7d, $ef, $e2, $4d, $67, $8a, $5a
	db $4d, $e5, $23, $05, $2c, $32, $d2, $71, $c8, $16, $54, $8e
	db $d5, $33, $bc, $9f
	db $a9, $e2

.after_key_text
	db TX_COMPRESSED, $74, $e1, $ec, $56, $71, $06, $4b, $32, $32, $79
	db $7a, $c3, $3a, $3c, $0e, $0f, $08, $ea, $3f, $aa
	db $46, $ab, $62, $da, $24, $c0, $2b, $83, $be
	db $34, $d0

EagulouGymB1F_Trainer_3:
	trainer EVENT_EAGULOU_GYM_B1F_TRAINER_3, PATROLLER, 20, .before_battle_text, .battle_won_text, $0000, .script
.script
	opentext
	checkevent EVENT_EAGULOU_JAIL_GOT_NPC_KEY_3
	sif true
		jumptext .after_key_text
	writetext .give_key_text
	verbosegiveitem CAGE_KEY, 1
	sif false, then
		waitbutton
		jumptext EagulouGymB1F_Text_NoSpace
	sendif
	setevent EVENT_EAGULOU_JAIL_GOT_NPC_KEY_3
	closetext
	end

.before_battle_text
	db TX_COMPRESSED, $29, $23, $44, $a7, $34, $7d, $83, $44, $40
	db $5e, $1b, $2a, $40, $b8

	db $80, $75, $14, $88, $1a, $bf, $1d, $38, $7b, $16, $78, $34, $83
	db $7a, $c3, $0f, $6e, $69, $33, $2d, $26
	db $45, $56, $93, $04, $e1, $ec, $e9, $dc, $7c, $e7, $21
	db $e3, $4d

.battle_won_text
	db TX_COMPRESSED, $6d, $0b, $e7, $02, $4f, $c2, $06, $a2, $f8, $f8
	db $27, $95, $84, $16, $0b, $19, $93, $32, $a1, $f7
	db $a0, $08, $1b, $8a, $ce, $27, $44, $08, $05, $2c
	db $2f, $24, $f5, $73, $55, $85, $ab, $96, $91, $a3
	db $8d, $34

.give_key_text
	db TX_COMPRESSED, $61, $06, $2b, $0d, $a4, $d7, $2d
	db $26, $f5, $5a, $bc, $99, $3f, $1d, $16, $4b, $1a, $cf
	db $2a, $83, $84, $04, $16
	db $bd, $4f, $10

.after_key_text
	db TX_COMPRESSED, $6d, $d2, $40, $41, $6a, $20, $87, $aa, $51, $f3
	db $78, $64, $88, $0b, $e7, $19, $68, $43, $3a, $a4, $68, $a5
	db $a6, $80

EagulouGymB1FLeader:
	faceplayer
	opentext
	checkflag ENGINE_STARBADGE
	sif true
		jumptext .already_battled_text
	writetext .before_battle_text
	winlosstext .battle_won_text, 0
	setlasttalked 255
	writecode VAR_BATTLETYPE, BATTLETYPE_NORMAL
	loadtrainer SILVER, 1
	startbattle
	reloadmapafterbattle
	playmapmusic
	opentext
	writetext .received_badge_text
	playwaitsfx SFX_TCG2_DIDDLY_5
	setflag ENGINE_STARBADGE
	playmusic MUSIC_GYM
	writetext .after_badge_text
	givetm 8 + RECEIVED_TM
	jumptext .after_TM_text

.already_battled_text
	db TX_COMPRESSED, $07, $98, $31, $ae, $60, $15, $f2, $77, $2d
	db $26, $f2, $04, $1b, $23, $de, $c5, $61, $26, $60, $20
	db $b4, $01, $21, $ee, $65, $43, $b4, $c0, $41, $69
	db $6f, $03, $95, $f0, $93
	db $d4, $d0

.before_battle_text
	db TX_COMPRESSED, $a7, $80, $54, $14, $26, $be, $78
	db $9e, $50, $3e, $83, $1a

	db $fc, $01, $d1, $64, $b4, $9c, $6f, $ab, $c9, $92, $69
	db $32, $f3, $08, $13, $f3, $1c, $f7, $26, $b8, $1c
	db $15, $0b, $b7, $96, $ba, $16

	db $bc, $01, $d4, $69, $07, $99, $61, $8a, $cf, $a3, $30, $63
	db $7a, $d3, $b7, $13, $a0, $c3, $27, $31, $16, $b0, $93
	db $90, $00, $e5, $7c, $24, $95, $6a, $25, $a4
	db $de, $56, $1b, $b0, $bf, $3a, $32, $1f

	db $10, $00, $e5, $7c, $24, $8f, $e8, $28, $ac
	db $de, $64, $24, $40, $f2, $6b, $3c, $ca, $8f, $54
	db $be, $01, $5b, $57, $2d, $27, $15, $84, $99
	db $79, $59, $dd, $46, $64, $9b, $0a, $5e, $8c, $86
	db $b0, $1a, $4c, $cd, $80, $e5, $7c, $24
	db $79, $3a, $88, $d1, $3a, $37, $c7, $67
	db $95, $42, $03, $66, $4b, $1e, $f7

	db $88, $01, $23, $82, $36, $c6, $64, $bf, $cd, $26
	db $5e, $04, $16, $97, $01, $ca, $f8, $49, $2a, $1f
	db $7a, $01, $59, $b2, $17, $ce, $02, $0b, $4b
	db $7b, $95, $9e, $d9, $a2, $e6, $f7, $a3, $34, $71

	db $01, $4f, $1f

	db $10, $0e, $a3, $29, $de, $f4, $c9, $c9, $c0, $41, $6b
	db $8d, $3c, $40

.battle_won_text
	db TX_COMPRESSED, $a7, $80, $a4, $ed, $e2
	db $78, $6f, $88, $59, $a1, $03, $06, $3f

	db $00, $72, $85, $a8, $84, $ea, $ce, $6c, $45, $ac, $24
	db $e5, $e5, $61, $26, $65, $43, $b4, $c0, $41, $69
	db $6a, $ac, $f5, $fe
	db $34, $d0

.received_badge_text
	db TX_COMPRESSED, $a7, $8e, $2c, $d9, $31, $83, $1e
	db $5e, $51, $7a, $b8, $25, $b9, $e4, $f8
	db $d3, $40

.after_badge_text
	db TX_COMPRESSED, $a7, $81, $d4, $b4, $8c, $8a, $50, $10, $5a, $2e
	db $37, $aa, $0a, $ed, $20, $a0, $70, $96, $91, $a3

	db $c0, $1d, $43, $d5, $90, $f3, $2d, $23
	db $43, $c8, $30, $63, $5e, $f6, $02, $3d, $5a, $26, $f2
	db $10, $18, $2c, $2f, $c5, $02, $16, $16, $ae, $14, $1a, $8d, $78
	db $9e, $a8, $68, $38, $2e, $ee, $4d, $7e

	db $00, $ea, $34, $4c, $9a, $d1, $61, $0e, $62, $46
	db $87, $b7, $20, $c3, $64, $e2, $0c, $18, $d7, $bd
	db $54, $08, $f5, $68, $9d, $db, $35, $b8
	db $80, $07, $2b, $e1, $24, $d5, $9c, $20
	db $6d, $eb, $08, $7a, $88, $1c, $25, $5a, $bf
	db $53, $c4

.after_TM_text
	db TX_COMPRESSED, $a7, $80, $a4, $8d, $10, $a1, $58, $34
	db $3c, $ce, $f7, $a7, $98, $a7, $dd, $42

	db $7c, $01, $d5, $e2, $84, $0d, $cd, $82, $02, $21, $ae, $ea
	db $de, $28, $57, $f1, $5b, $57, $07, $72, $a1, $f7
	db $a0, $3a, $3e, $53, $71, $a1, $13, $3a, $b5
	db $27, $84, $77, $59, $34, $41, $3c, $e8, $6a, $35
	db $80, $b4, $9c, $d6, $59, $69, $7a, $c8, $28, $1c
	db $1e, $b4, $9c, $c0, $27, $32, $d2, $c6, $4e
	db $55, $2b, $db, $be, $9a
	db $3d, $4d

EagulouGymB1F_Text_NoSpace:
	db TX_COMPRESSED, $53, $59, $9c, $68, $44, $40, $5f
	db $37, $90, $23, $59, $3f, $ca, $87, $de, $c0, $5b, $4b
	db $c6, $9a

EagulouGymB1F_MapEventHeader::	db 0, 0

.Warps
	db 1
	warp_def $10, $11, 2, EAGULOU_GYM_F1

.CoordEvents
	db 0

.BGEvents
	db 4
	signpost 4, 4, signpost_reset SIGNPOST_READ, EagulouGymB1FDoor1
	signpost 4, 16, signpost_reset SIGNPOST_READ, EagulouGymB1FDoor2
	signpost 14, 4, SIGNPOST_JUMPSTDNOSFX, cagekeydoor, 2
	signpost 14, 16, signpost_reset SIGNPOST_READ, EagulouGymB1FDoor4

.ObjectEvents
	db 6
	person_event SPRITE_ROCKET, 12, 15, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_TRAINER, 0, EagulouGymB1F_Trainer_1, -1
	person_event SPRITE_SILVER, 2, 15, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_SCRIPT, 0, EagulouGymB1FLeader, -1
	person_event SPRITE_SAILOR, 12, 4, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_BLUE, PERSONTYPE_TRAINER, 0, EagulouGymB1F_Trainer_2, -1
	person_event SPRITE_PALETTE_PATROLLER, 2, 4, SPRITEMOVEDATA_00, 0, 0, -1, -1, 8 + PAL_OW_PURPLE, PERSONTYPE_TRAINER, 0, EagulouGymB1F_Trainer_3, -1
	person_event SPRITE_OFFICER, 8, 10, SPRITEMOVEDATA_WANDER, 1, 1, -1, -1, PAL_OW_BROWN, PERSONTYPE_TEXTFP, 0, EagulouGymB1FGuide, -1
	person_event SPRITE_POKE_BALL, 6, 8, SPRITEMOVEDATA_ITEM_TREE, 0, 0, -1, -1, PAL_OW_PURPLE, PERSONTYPE_ITEMBALL, 0, EagulouGymB1F_CageKey, EVENT_EAGULOU_GYM_B1F_ITEM_1

