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
	givetm HM_STRENGTH + RECEIVED_TM
	setevent EVENT_DEFEATED_RIVAL_IN_PRISON
	jumptext .got_HM_text

.before_battle_text
	db TX_COMPRESSED, $50, $1f, $c0, $41, $68, $b8, $e7, $42, $15, $21, $93
	db $97, $b0, $0a, $e6, $ca, $b4, $14, $0b, $57, $03
	db $82, $a4, $9a, $ce, $6a, $25, $47, $de, $d2

	db $80, $29, $23, $44, $10, $b1, $a0, $24, $83, $44, $7f, $40
	db $bc, $4d, $e4, $f3, $15, $82, $88, $0b, $e7, $3b, $a2, $6c
	db $10, $05, $6d, $20, $64, $34, $21, $fd, $27, $e6, $93
	db $2f, $72, $d6, $af, $27, $98, $ac, $14, $c3, $6f
	db $ea, $9a, $41, $f4, $d0, $88, $37, $d5, $9b, $23, $e9, $a3

	db $c0, $1d, $4a, $b5, $13, $56, $b3, $45, $9e
	db $5e, $c0, $2b, $8f, $82, $8a, $f6, $ef, $a3, $27
	db $20, $34, $99, $89, $d5, $e6, $5a, $f4, $64, $19, $39
	db $79, $f3, $b4, $87, $28, $fc, $56, $d5, $d3
	db $c0, $01, $a2, $60, $15, $db, $44, $db, $3e, $82, $98, $05
	db $6f, $5a, $46, $89, $50, $57, $dc, $cc, $1a, $ef
	db $40, $07, $09, $51, $ea, $97, $46, $4e, $51, $f8, $e8
	db $b1, $eb, $08, $60, $80, $d4, $6b, $c1, $ae, $cb
	db $08, $05, $67, $3a, $16, $54, $8f, $32, $a1, $da, $46
	db $47, $ad, $26, $83, $95, $6f, $7a, $88, $1c
	db $15, $32, $b6, $9f, $57, $d1, $93, $98, $c9, $be, $64, $bf

	db $00, $75, $15, $ed, $df, $4e, $03, $95, $f0
	db $91, $eb, $49, $ca, $b4, $14, $b4, $9a
	db $0c, $03, $2b, $3d, $b6, $96, $68, $89, $d0, $63
	db $79, $59, $99, $22, $b5, $9e, $65, $86, $2b, $3f

	db $00, $72, $85, $a9, $69, $19, $14, $a5, $a4, $d0
	db $6f, $58, $c8, $0a, $32, $b3, $b1, $91, $11, $3a, $0c
	db $60, $32, $60, $c7, $d0, $88, $3c, $cb, $49, $8d
	db $6f, $6a, $b1, $f4, $76, $0a, $58
	db $40, $2b, $59, $ed, $a4, $e6, $03, $59
	db $fd, $eb, $4a, $c3, $54, $56, $16, $bb, $93, $5a
	db $3e, $03, $49, $98, $8e, $8d, $93, $96, $93, $1a
	db $de, $32, $1b, $e3, $34, $4b, $0c, $57, $b7, $7d
	db $35, $54, $e3, $48, $b9, $80, $57, $10, $20, $2b, $ba

	db $50, $0e, $f0, $8c, $85, $a5, $a0, $e1, $03, $7c

	db $40, $3a, $8a, $f6, $ef, $a7, $2d, $26, $83
	db $79, $95, $9e, $db, $4b, $34, $4b, $49, $ca, $b4
	db $10, $0b, $49, $82, $2e, $38, $f9, $e9, $2e, $58
	db $5e, $57, $b7, $7d, $37, $18, $b6, $ad, $3d, $34, $23

	db $c0, $1d, $12, $2b, $db, $be, $9f, $e5, $a4
	db $de, $09, $3a, $0a, $5a, $da, $39, $56, $82, $96
	db $10, $1a, $ca, $46, $60, $c7, $35, $5a, $03, $d6, $ac
	db $de, $10, $1a, $8d, $70, $68, $87, $4e, $88, $e8, $47, $60
	db $40, $0c, $9c, $cb, $49, $ca, $8f, $54, $88, $68
	db $43, $c1, $c2, $5a, $4e, $19, $0d, $f0, $52, $a4, $8f
	db $a6, $01, $fd, $19, $2f, $46, $41, $93, $98, $c8, $5f
	db $02, $f0, $8e, $9d, $9c, $64, $24, $b5, $87, $b0, $38
	db $2a, $b4, $9c, $32, $58, $d6, $73, $01, $9f, $73

	db $e0, $0d, $a1, $7c, $ff, $1f, $05, $12, $d3, $ea, $fa
	db $6f, $14, $bd, $19, $0d, $7f, $9a, $4c, $ce, $9d, $e2
	db $55, $90, $c5, $7b, $77, $d3, $e3, $18, $ea, $77
	db $d4, $d0

.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, $78, $80

.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, $06, $5f, $01, $05
	db $a7, $b9, $0d, $de, $cc, $07, $cb, $4b, $39, $69, $db
	db $54, $16, $ae, $02, $0b, $4b, $41, $f7, $0f
	db $53, $40

.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
	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
	applymovement 4, .step_aside
	spriteface PLAYER, RIGHT
	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

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

PrisonB1FHariyama1:
	faceplayer
	setevent EVENT_PRISON_B1F_NPC_3
	scall PrisonB1FHariyama
	disappear 5
	end

PrisonB1FHariyama2:
	faceplayer
	setevent EVENT_PRISON_B1F_NPC_4
	scall PrisonB1FHariyama
	disappear 6
	end

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

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

PrisonB1F_MapEventHeader:: db 0, 0

.Warps
	db 1
	warp_def $e, $f, 7, PRISON_F1

.CoordEvents
	db 0

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

.ObjectEvents
	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, PrisonB1FHariyama1, EVENT_PRISON_B1F_NPC_3
	person_event SPRITE_HARIYAMA, 4, 26, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_BROWN, PERSONTYPE_SCRIPT, 0, PrisonB1FHariyama2, EVENT_PRISON_B1F_NPC_4
	person_event SPRITE_MACHOKE, 4, 14, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, PrisonB1FMachoke, EVENT_PRISON_B1F_NPC_5
	person_event SPRITE_BRONZONG, 4, 3, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, PrisonB1FBronzong, EVENT_PRISON_B1F_NPC_6

