PrisonB1F_MapScriptHeader;trigger count
	db 0
 ;callback count
	db 1
	dbw MAPCALLBACK_TILES, .unlock_opened_doors

.unlock_opened_doors
	copy wCageKeyDoorsArrayBank
	dba PrisonB1FChangeBlockArray
	db (PrisonB1FChangeBlockArrayEnd - PrisonB1FChangeBlockArray) / 5
	endcopy
	farjump UpdateCageKeyDoorsScript

PrisonB1FChangeBlockArray:
	eventflagchangeblock EVENT_PRISON_B1F_DOOR_1, 2, 6, $18
PrisonB1FChangeBlockArrayEntrySizeEnd:
	eventflagchangeblock EVENT_PRISON_B1F_DOOR_2, 14, 6, $18
	eventflagchangeblock EVENT_PRISON_B1F_DOOR_3, 24, 6, $18
	eventflagchangeblock EVENT_PRISON_B1F_DOOR_4, 2, 20, $18
	eventflagchangeblock EVENT_PRISON_B1F_DOOR_5, 14, 20, $18
	eventflagchangeblock EVENT_PRISON_B1F_DOOR_6, 24, 20, $18
	eventflagchangeblock EVENT_PRISON_B1F_DOOR_7, 14, 16, $18
PrisonB1FChangeBlockArrayEnd:

PrisonB1FPasswordDoor:
	dw EVENT_PRISON_B1F_PASSWORD_DOOR
	opentext
	checkevent EVENT_PRISON_B1F_KNOW_PASSWORD
	sif false
		jumptext .door_needs_password_text
	setevent EVENT_PRISON_B1F_PASSWORD_DOOR
	writetext .door_password_text
	playsound SFX_ENTER_DOOR
	setevent EVENT_PRISON_B1F_DOOR_7
	closetext
	farscall UpdateCageKeyDoorsScript
	refreshscreen 0
	reloadmappart
	end

.door_needs_password_text
	db TX_COMPRESSED, $29, $27, $32, $10, $ae, $0d
	db $0f, $74, $2c, $a9, $1e

	db $7c, $01, $d5, $ce, $84, $2a, $48, $9d, $1a, $91, $c1
	db $db, $c4, $33, $ca, $26, $c1, $1a, $84, $54, $15
	db $e5, $55, $86, $34, $4e, $85, $95, $2f
	db $53, $40

.door_password_text
	db TX_COMPRESSED, $a7, $8e, $19, $2c, $d6, $79
	db $7a, $d2, $70, $46, $a1, $15, $05, $79

	db $f0, $01, $35, $8b, $37, $1f, $3c, $f4, $15, $38, $7d, $e8, $2e, $22, $6b, $17

	db $00, $52, $4e, $64, $21, $5c, $08, $83, $21, $e7
	db $8d, $3c, $40

PrisonB1FRival:
	trainer EVENT_PRISON_B1F_TRAINER_1, RIVAL1, RIVAL1_4, .before_battle_text, .battle_won_text, $0000, .Script

.Script
	faceplayer
	opentext
	checkevent EVENT_DEFEATED_RIVAL_IN_PRISON
	sif true
		jumptext .after_giving_HM_text
	writetext .after_winning_text
	waitbutton
	givetm 100 + RECEIVED_TM
	opentext
	writetext .got_HM_text
	setevent EVENT_DEFEATED_RIVAL_IN_PRISON
	endtext

.before_battle_text
	db TX_COMPRESSED, $50, $18, $08, $2d, $17, $1c, $e8, $42, $a4, $32
	db $72, $f6, $01, $5c, $d9, $56, $82, $81, $6a, $e0, $70
	db $54, $93, $59, $cd, $44, $a8, $fb, $da

	db $50, $05, $24, $68, $82, $16, $34, $04, $90, $68, $8f, $e8
	db $17, $89, $bc, $9e, $62, $b0, $51, $01, $7c, $e7, $74, $4d, $82

	db $00, $ad, $a4, $0c, $86, $84, $3f, $a4, $fc, $d2
	db $65, $ee, $5a, $d5, $e4, $f3, $15, $82, $98, $6d
	db $fd, $53, $48, $3e, $9a, $11, $06, $fa, $b3, $64, $7d, $34

	db $78, $03, $a9, $56, $a2, $6a, $d6, $68, $b3
	db $cb, $d8, $05, $71, $f0, $51, $5e, $dd, $f4, $64
	db $e4, $06, $93, $31, $3a, $bc, $cb, $5e, $8c, $83, $27
	db $2f, $3e, $76, $90, $e5, $1f, $8a, $da, $ba, $78

	db $00, $34, $4c, $02, $bb, $68, $9b, $67, $d0, $53, $00
	db $ad, $eb, $48, $d1, $2a, $0a, $fb, $99, $83, $5d

	db $e8, $00, $e1, $2a, $3d, $52, $e8, $c9, $ca, $3f, $1d, $16
	db $3d, $61, $0c, $10, $1a, $8d, $78, $35, $d9, $61

	db $00, $ac, $e7, $42, $ca, $91, $e6, $54, $3b, $48
	db $c8, $f5, $a4, $d0, $72, $ad, $ef, $51, $03
	db $82, $a6, $56, $d3, $ea, $fa, $32, $73, $19, $37, $cc, $97

	db $e0, $0e, $a2, $bd, $bb, $e9, $c0, $72, $be, $12
	db $3d, $69, $39, $56, $82, $96, $93, $41
	db $80, $65, $67, $b6, $d2, $cd, $11, $3a, $0c
	db $6f, $2b, $33, $24, $56, $b3, $cc, $b0, $c5, $67

	db $e0, $0e, $50, $b5, $2d, $23, $22, $94, $b4, $9a
	db $0d, $eb, $19, $01, $46, $56, $76, $32, $22, $27, $41
	db $8c, $06, $4c, $18, $fa, $11, $07, $99, $69, $31
	db $ad, $ed, $56, $3e, $8e, $c1, $4b

	db $08, $05, $6b, $3d, $b4, $9c, $c0, $6b, $3f
	db $bd, $69, $58, $6a, $8a, $c2, $d7, $72, $6b, $47

	db $c0, $69, $33, $11, $d1, $b2, $72, $d2, $63
	db $5b, $c6, $43, $7c, $66, $89, $61, $8a, $f6, $ef
	db $a6, $aa, $9c, $69, $17, $30, $0a, $e2, $04, $05, $77

	db $4a, $01, $de, $11, $90, $b4, $b4, $1c, $20, $6f

	db $88, $07, $51, $5e, $dd, $f4, $e5, $a4, $d0
	db $6f, $32, $b3, $db, $69, $66, $89, $69, $39, $56, $82
	db $01, $69, $30, $45, $c7, $1f, $3d, $25, $cb
	db $0b, $ca, $f6, $ef, $a6, $e3, $16, $d5, $a7, $a6, $84

	db $78, $03, $a2, $45, $7b, $77, $d3, $fc, $b4
	db $9b, $c1, $27, $41, $4b, $5b, $47, $2a, $d0, $52
	db $c2, $03, $59, $48, $cc, $18, $e6, $ab, $40, $7a, $d5
	db $9b, $c2, $03, $51, $ae, $0d, $10, $e9, $d1, $1d, $08, $ec
	db $08, $01, $93, $99, $69, $39, $51, $ea, $91, $0d, $08
	db $78, $38, $4b, $49, $c3, $21, $be, $0a, $54, $91, $f4
	db $c0, $3f, $a3, $25, $e8, $c8, $32, $73, $19, $0b, $e0
	db $5e, $11, $d3, $b3, $8c, $84, $96, $b0, $f6, $07
	db $05, $56, $93, $86, $4b, $1a, $ce, $60, $33, $ee

	db $7c, $01, $b4, $2f, $9f, $e3, $e0, $a2, $5a, $7d, $5f
	db $4d, $e2, $97, $a3, $21, $af, $f3, $49, $99, $d3, $bc
	db $4a, $b2, $18, $af, $6e, $fa, $7c, $63, $1d, $4e
	db $fa, $9a

.battle_won_text
	db TX_COMPRESSED, $74, $f8, $80, $a1, $03, $57, $d3
	db $e3, $4d

.after_winning_text
	db TX_COMPRESSED, $72, $85, $a8, $a4, $40, $d5, $f8, $ea, $60, $67
	db $d7, $90, $15, $ac, $14, $c0, $2b, $80, $82, $d7

	db $80, $39, $42, $d1, $71, $c2, $18, $31, $ae, $72, $11, $93
	db $97, $ac, $30, $e9, $d1, $06, $b1, $99, $19, $39
	db $a0, $01, $ca, $f8, $49, $15, $ed, $df
	db $4d, $ee, $8d, $48, $e3, $a9, $90, $c5, $66, $32
	db $72, $a9, $16, $d3, $2a, $50, $64, $89, $35, $9f

	db $80, $15, $aa, $47, $2d, $23, $44, $62, $2b
	db $ea, $68

.got_HM_text
	db TX_COMPRESSED, $29, $3b, $78, $a5, $49, $db, $8e, $8b
	db $1e, $69, $03, $27, $32, $c3, $0d, $0c, $e8, $83

	db $f0, $07, $45, $90, $81, $b9, $67, $de, $8c, $9c
	db $bc, $08, $2d, $44, $86, $a9, $61, $8d, $20
	db $c0, $0e, $e5, $86, $1a, $19, $d1, $07, $f8, $08, $2d
	db $3d, $c8, $6e, $f6, $60, $3e, $5a, $59, $cb, $4e
	db $da, $a0, $b5, $70, $10, $5a, $5a, $0f, $b8
	db $7a, $9a

.after_giving_HM_text
	db TX_COMPRESSED, $29, $27, $08, $74, $ed, $cb, $1b, $e7, $2a
	db $37, $9f, $33, $bf, $c7, $50, $42, $c2, $f8, $d0, $7e

	db $00, $52, $76, $e2, $bd, $bb, $e9, $ca, $87, $de
	db $bc, $64, $cc, $b4, $9c, $ab, $41, $47
	db $4a, $b2, $68, $1a, $cf
	db $d4, $d0

PrisonB1FMetagross:
	faceplayer
	setevent EVENT_PRISON_B1F_NPC_1
	cry METAGROSS
	waitsfx
	setlasttalked 255
	writecode VAR_BATTLETYPE, BATTLETYPE_NORMAL
	loadwildmon METAGROSS, 50
	startbattle
	reloadmapafterbattle
	disappear 3
	end

PrisonB1FFambaco:
	faceplayer
	setevent EVENT_PRISON_B1F_NPC_2
	clearevent EVENT_FAMBACO
	cry FAMBACO
	waitsfx
	applymovement 4, .step_aside
	spriteface 0, 3
	applymovement 4, .leave
	disappear 4
	end

.step_aside
	fast_jump_step_right
	step_end

.leave
	fast_slide_step_right
	fast_slide_step_right
	fast_slide_step_up
	fast_slide_step_up
	fast_slide_step_up
	fast_slide_step_up
	fast_slide_step_up
	step_end

PrisonB1Makuhita:
	cry HARIYAMA
	waitsfx
	setlasttalked 255
	writecode VAR_BATTLETYPE, BATTLETYPE_NORMAL
	loadwildmon HARIYAMA, 45
	startbattle
	reloadmapafterbattle
	end

PrisonB1FNPC3:
	faceplayer
	setevent EVENT_PRISON_B1F_NPC_3
	scall PrisonB1Makuhita
	disappear 5
	end

PrisonB1FNPC4:
	faceplayer
	setevent EVENT_PRISON_B1F_NPC_4
	scall PrisonB1Makuhita
	disappear 6
	end

PrisonB1FNPC5:
	faceplayer
	setevent EVENT_PRISON_B1F_NPC_5
	cry MACHOKE
	waitsfx
	setlasttalked 255
	writecode VAR_BATTLETYPE, BATTLETYPE_NORMAL
	loadwildmon MACHOKE, 45
	startbattle
	reloadmapafterbattle
	disappear 7
	end

PrisonB1FNPC6:
	faceplayer
	setevent EVENT_PRISON_B1F_NPC_6
	cry BRONZONG
	waitsfx
	setlasttalked 255
	writecode VAR_BATTLETYPE, BATTLETYPE_NORMAL
	loadwildmon BRONZONG, 50
	startbattle
	reloadmapafterbattle
	disappear 8
	end

PrisonB1F_MapEventHeader ;filler
	db 0, 0

;warps
	db 1
	warp_def $e, $f, 7, PRISON_F1

	;xy triggers
	db 0

	;signposts
	db 7
	signpost 7, 3, SIGNPOST_JUMPSTDNOSFX, cagekeydoor, 0
	signpost 7, 15, SIGNPOST_JUMPSTDNOSFX, cagekeydoor, 1
	signpost 7, 25, SIGNPOST_JUMPSTDNOSFX, cagekeydoor, 2
	signpost 21, 3, SIGNPOST_JUMPSTDNOSFX, cagekeydoor, 3
	signpost 21, 15, SIGNPOST_JUMPSTDNOSFX, cagekeydoor, 4
	signpost 21, 25, SIGNPOST_JUMPSTDNOSFX, cagekeydoor, 5
	signpost 17, 15, signpost_reset SIGNPOST_READ, PrisonB1FPasswordDoor

	;people-events
	db 7
	person_event SPRITE_SILVER, 18, 2, SPRITEMOVEDATA_STANDING_UP, 0, 0, -1, -1, 0, PERSONTYPE_TRAINER, 0, PrisonB1FRival, EVENT_PRISON_B1F_TRAINER_1
	person_event SPRITE_METAGROSS, 24, 26, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, PrisonB1FMetagross, EVENT_PRISON_B1F_NPC_1
	person_event SPRITE_FAMBACO, 22, 11, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_SCRIPT, 0, PrisonB1FFambaco, EVENT_PRISON_B1F_NPC_2
	person_event SPRITE_HARIYAMA, 24, 3, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_BROWN, PERSONTYPE_SCRIPT, 0, PrisonB1FNPC3, EVENT_PRISON_B1F_NPC_3
	person_event SPRITE_HARIYAMA, 4, 26, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_BROWN, PERSONTYPE_SCRIPT, 0, PrisonB1FNPC4, EVENT_PRISON_B1F_NPC_4
	person_event SPRITE_MACHOKE, 4, 14, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, PrisonB1FNPC5, EVENT_PRISON_B1F_NPC_5
	person_event SPRITE_BRONZONG, 4, 3, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, PrisonB1FNPC6, EVENT_PRISON_B1F_NPC_6

