//
//Scripting
//Map: Axis Lab
//Last edited by: Chris S.
//

game_manager
{
	spawn
	{
		// Set scenario information

		// "Allied forces are attempting to steal top secret lab documents from an under ground hidden Axis lab."

		// Set the respawn times

		wm_allied_respawntime		20
		wm_axis_respawntime		30

		wm_set_round_timelimit		20

		// Set the number of objectives for the map

		wm_number_of_objectives		8

		// Current main objectives for each team (0=Axis, 1=Allies)
		wm_set_main_objective		4	0
		wm_set_main_objective		4	1

		// objectives
		// 1:	Flag on the Hill Top
		// 2:	Sewers
		// 3:	Root Cellar
		// 4:	Elevator Generator
		// 5:	Documents Room doors
		// 6:	Picking up Axis Lab Documents
		// 7:	Drive away with the Lab Documents
		// 8:   Axis Command Post
		// 9:   Allied Command Post

		// Objective overview status indicators
		//wm_objective_status <objective> <team (0=Axis, 1=Allies)> <status (0=neutral 1=complete 2=failed)>
		wm_objective_status 1 1 0
		wm_objective_status 1 0 0
		wm_objective_status 2 1 0
		wm_objective_status 2 0 0
		wm_objective_status 3 1 0
		wm_objective_status 3 0 0
		wm_objective_status 4 1 0
		wm_objective_status 4 0 0
		wm_objective_status 5 1 0
		wm_objective_status 5 0 0
		wm_objective_status 6 1 0
		wm_objective_status 6 0 0
		wm_objective_status 7 1 0
		wm_objective_status 7 0 0
		wm_objective_status 8 1 0
		wm_objective_status 8 0 0

		// Set autospawn markers <team (0 = axis, 1 = allies)> <message key of marker>
		// Spawns on Axis Lab:
		// Allied Side
		// Hill Top

		wait 500

		setautospawn "Hill Top" 		0
		setautospawn "Allied Side"		1

		// Set Defending Team for SW Mode
		wm_set_defending_team	0

		// If the round timer expires, the Axis have won, so set the current winning team
		// Set the round winner:  0 == AXIS, 1 == ALLIED
		wm_setwinner 0

		wait 2000
		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hill_top_dont"
		wm_addteamvoiceannounce 0 "axis_entrances_defend"
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

		wm_addteamvoiceannounce 1 "allies_hill_top_go"
		wm_addteamvoiceannounce 1 "allies_entrances_destroy"
		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"

		wm_teamvoiceannounce 0 "axis_hill_top_dont"
		wm_teamvoiceannounce 0 "axis_entrances_defend"
		wm_teamvoiceannounce 0 "axis_hq_compost_construct"


		wm_teamvoiceannounce 1 "allies_hill_top_go"
		wm_teamvoiceannounce 1 "allies_entrances_destroy"
		wm_teamvoiceannounce 1 "allies_hq_compost_construct"
		// *---------------------------------------------------------------------------------*

	}

	trigger axis_object_stolen
	{
		// Change the objective state internally, so UI can update, etc.
		// Allied have stolen the documents (0 == AXIS, 1 == ALLIED)
		setstate docs_cm_marker invisible
		setstate docs_toi invisible

		wm_set_main_objective	6	0
		wm_set_main_objective	6	1

		wm_objective_status 5 0 2
		wm_objective_status 5 1 1
	}

	trigger axis_object_returned
	{
		// Change the objective state internally, so UI can update, etc.
		// Axis have returned the documents (0 == AXIS, 1 == ALLIED)
		setstate docs_cm_marker default
		setstate docs_toi default

		wm_set_main_objective	5	0
		wm_set_main_objective	5	1

		wm_objective_status 5 0 1
		wm_objective_status 5 1 2
	}

	trigger allied_spawn_truck
	{
		alertentity allied_truck // fix spawn points for begining
		wait 500
		alertentity allied_start
	}

	trigger allies_win
	{
		wm_setwinner	1
		wm_announce "Allied team escaped with the Secret Lab Documents!"

		wm_objective_status 6 0 2
		wm_objective_status 6 1 1

		wait 3000
		wm_endround
	}
}

//////////////
//Objectives//
//////////////

hill_flag //Flag on top of hill (Objective 1)
{
	spawn
	{
		// Accum #0 State of Hill Top flag: 0=axis 1=allied
		accum 0 bitreset 0
		wait 1000
		disablespeaker flag_sound
	}

	trigger axis_capture
	{
		// Axis takes control of Hill Top flag

		enablespeaker flag_sound

		accum 0 abort_if_not_bitset 0
		accum 0 bitreset 0

		setautospawn "Hill Top"		0
		setautospawn "Allied Side"	1

		alertentity hill_top_spawn

		wm_announce	"Axis reclaims the Hill Top!"

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hill_top_dont"

		wm_addteamvoiceannounce 1 "allies_hill_top_go"

		wm_teamvoiceannounce 0 "axis_hill_top_recaptured"

		wm_teamvoiceannounce 1 "allies_hill_top_reclaimed"
		// *---------------------------------------------------------------------------------*

	}

	trigger allied_capture
	{
		// Allied takes control of Hill Top flag
	
		enablespeaker flag_sound

		accum 0 abort_if_bitset 0
		accum 0 bitset 0

		setautospawn "Hill Top"		1
		setautospawn "Axis Bunker"	0
		alertentity hill_top_spawn // Targets team_WOLF_objective entity and changes who owns it on command map
		wm_announce	"Allies capture the Hill Top!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hill_top_captured"

		wm_teamvoiceannounce 1 "allies_hill_top_captured"

		wm_removeteamvoiceannounce 0 "axis_hill_top_dont"

		wm_removeteamvoiceannounce 1 "allies_hill_top_go"



		// *---------------------------------------------------------------------------------*

	}

	trigger force_allied
	{
		remove
		disablespeaker flag_sound

		accum 0 abort_if_bitset 0

		setautospawn "Hill Top"		1
		setautospawn "Axis Bunker"	0

		alertentity hill_top_spawn
		alertentity hill_top

		// *----------------------------------- vo ------------------------------------------*
		wm_removeteamvoiceannounce 0 "axis_hill_top_dont"
		wm_removeteamvoiceannounce 1 "allies_hill_top_go"
		// *---------------------------------------------------------------------------------*
	}
}

sewers
{
	spawn
	{
		wait 200

		constructible_class 3
	}

	death
	{
//		setstate sewers_toi invisible

		wm_announce "Allies have breached the Sewers"

		wm_objective_status 1 1 1
		wm_objective_status 1 0 2

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_objective_destroyed"
		wm_teamvoiceannounce 1 "allies_hq_objective_destroyed"

		wm_removeteamvoiceannounce 0 "axis_entrances_defend"
		wm_removeteamvoiceannounce 1 "allies_entrances_destroy"
		trigger war_room_door announce
		trigger elevator_generator announce
		// *---------------------------------------------------------------------------------*
	}
}

root_cellar
{
	spawn
	{
		wait 200

		constructible_class 3
	}

	death
	{
		trigger hill_flag force_allied // Switch hill top spawn to Allied ONLY

//		setstate root_cellar_toi invisible

		wm_announce "Allies have breached the Root Cellar and secured the Hill Top!"

		wm_objective_status 2 1 1
		wm_objective_status 2 0 2

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_objective_destroyed"
		wm_teamvoiceannounce 1 "allies_hq_objective_destroyed"

		wm_removeteamvoiceannounce 0 "axis_entrances_defend"
		wm_removeteamvoiceannounce 1 "allies_entrances_destroy"
		trigger war_room_door announce
		trigger elevator_generator announce
		// *---------------------------------------------------------------------------------*
	}
}

elevator_generator
{
	spawn
	{
		wait 1000
		trigger elevator_generator setup
		accum 0 bitreset 6
		constructible_class 2
	}

	trigger announce
	{
		accum 0 abort_if_bitset 6

		wm_addteamvoiceannounce 0 "axis_generator_defend"
		wm_addteamvoiceannounce 1 "allies_generator_destroy"
		wm_teamvoiceannounce 0 "axis_generator_defend"
		wm_teamvoiceannounce 1 "allies_generator_destroy"
	}

	trigger setup
	{
		setstate elevator_generator default

		setstate elevator_generator_materials invisible
		setstate elevator_generator_materials_clip invisible
		enablespeaker generator_sound
	}

	buildstart final
	{
		setstate elevator_generator underconstruction

		setstate elevator_generator_materials default
		setstate elevator_generator_materials_clip default
	}

	built final
	{
		setstate elevator_generator default

		setstate elevator_generator_materials invisible
		setstate elevator_generator_materials_clip invisible

		enablespeaker generator_sound
		accum 0 bitreset 6

		wm_announce "The Elevator Generator has been constructed."
		wm_objective_status 3 1 2
		wm_objective_status 3 0 1

		trigger elevator elevator_fixed

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_generator_constructed"
		wm_teamvoiceannounce 1 "allies_generator_destroy"

		wm_addteamvoiceannounce 0 "axis_generator_defend"
		wm_addteamvoiceannounce 1 "allies_generator_destroy"
		// *---------------------------------------------------------------------------------*
	}

	decayed final
	{
		setstate elevator_generator invisible

		setstate elevator_generator_materials default
		setstate elevator_generator_materials_clip default
	}

	death
	{
		setstate elevator_generator invisible

		setstate elevator_generator_materials default
		setstate elevator_generator_materials_clip default

		disablespeaker generator_sound
		accum 0 bitset 6

		wm_announce "The Elevator Generator has been destroyed."
		wm_objective_status 3 1 1
		wm_objective_status 3 0 2

		trigger elevator elevator_destroyed

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_generator_destroyed"
		wm_teamvoiceannounce 1 "allies_generator_destroyed"

		wm_removeteamvoiceannounce 0 "axis_generator_defend"
		wm_removeteamvoiceannounce 1 "allies_generator_destroy"
		// *---------------------------------------------------------------------------------*
	}
}

war_room_door
{
	spawn
	{
		wait 200
		accum 0 bitreset 5
		constructible_class 3
	}

	trigger announce
	{
		accum 0 abort_if_bitset 5

		wm_addteamvoiceannounce 0 "axis_main_entrance_stop"
		wm_addteamvoiceannounce 1 "allies_main_entrance_destroy"
		wm_teamvoiceannounce 0 "axis_main_entrance_stop"
		wm_teamvoiceannounce 1 "allies_main_entrance_destroy"
	}

	death
	{
//		trigger hill_flag force_allied // Switch hill top spawn to Allied ONLY

		accum 0 bitset 5

		wm_announce "Allies have breached the Document's Room Main Entrance"

		wm_objective_status 4 1 1
		wm_objective_status 4 0 2
		wm_set_main_objective	5 0
		wm_set_main_objective	5 1

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_main_entrance_destroyed"
		wm_teamvoiceannounce 1 "allies_main_entrance_destroyed"

		wm_removeteamvoiceannounce 0 "axis_main_entrance_stop"
		wm_removeteamvoiceannounce 1 "allies_main_entrance_destroy"
		// *---------------------------------------------------------------------------------*
	}
}

docs_holder
{
	death
	{
		trigger truck run_2
	}
}

// ================================================
// =============== COMMAND POSTS ==================
// ================================================

allied_radio_destroyed
{
	spawn
	{
		wait 400
		setstate allied_radio_destroyed invisible
		setstate allied_radio_destroyed_model invisible
	}

	trigger hide
	{
		setstate allied_radio_destroyed invisible
		setstate allied_radio_destroyed_model invisible
	}

	trigger show
	{
		accum 0 abort_if_not_bitset 1
		setstate allied_radio_destroyed default
		setstate allied_radio_destroyed_model default
	}

	trigger enable
	{
		accum 0 bitset 1
	}
}

allied_radio_closed
{
	trigger hide
	{
		setstate allied_radio_closed invisible
		setstate allied_radio_closed_model invisible
	}

	trigger show
	{
		accum 0 abort_if_bitset 1
		setstate allied_radio_closed default
		setstate allied_radio_closed_model default
	}

	trigger disable
	{
		accum 0 bitset 1
	}
}

allied_radio_built
{
	spawn
	{
		wait 1000

		constructible_class 2
		setstate allied_cabin_spawn invisible
		trigger allied_radio_built setup

		disablespeaker allied_compost_sound
	}

	trigger setup
	{
		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1
		sethqstatus 1 0
	}

	buildstart final
	{
		trigger allied_radio_built_model trans

		trigger allied_radio_destroyed hide
		trigger allied_radio_closed 	hide
	}

	built final
	{
		trigger allied_radio_built_model show

		trigger allied_radio_destroyed enable
		trigger allied_radio_closed 	disable

		trigger allied_radio_built_model enable_allied_features

		alertentity allied_cabin
		setstate allied_cabin_spawn default

		enablespeaker allied_compost_sound
	}

	decayed final
	{
		trigger allied_radio_built_model hide

		trigger allied_radio_destroyed show
		trigger allied_radio_closed 	show
	}

	death
	{
		trigger allied_radio_built_model hide

		trigger allied_radio_destroyed show

		trigger allied_radio_built_model disable_allied_features

		disablespeaker allied_compost_sound

		alertentity allied_cabin
		setstate allied_cabin_spawn invisible
	}
}

allied_radio_built_model
{
	spawn
	{
		wait 400
		setstate allied_radio_built_model invisible
	}

	trigger show
	{
		setstate allied_radio_built_model default
	}

	trigger hide
	{
		setstate allied_radio_built_model invisible
	}

	trigger trans
	{
		setstate allied_radio_built_model underconstruction
	}

	trigger enable_allied_features
	{
		setchargetimefactor 1 soldier 0.75
		setchargetimefactor 1 lieutenant 0.75
		setchargetimefactor 1 medic 0.75
		setchargetimefactor 1 engineer 0.75
		setchargetimefactor 1 covertops 0.75
		sethqstatus 1 1

		wm_announce	"Allied Command Post constructed. Charge speed increased!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_compost_constructed_allies"

		wm_teamvoiceannounce 1 "allies_hq_compost_constructed"

		wm_removeteamvoiceannounce 1 "allies_hq_compost_construct"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 8 1 1
		wm_objective_status 8 0 2

	}

	trigger disable_allied_features
	{
		// Some kind of UI pop-up to alert players
		wm_announce	"Axis team has destroyed the Allied Command Post!"

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 1 "allies_hqt_compost_construc"

		wm_teamvoiceannounce 1 "allies_hq_compost_damaged"
		// *----------------------------------- vo ------------------------------------------*

		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1
		sethqstatus 1 0

		wm_objective_status 8 1 0
		wm_objective_status 8 0 0
	}
}

axis_radio_destroyed
{
	spawn
	{
		wait 400
		setstate axis_radio_destroyed invisible
		setstate axis_radio_destroyed_model invisible
	}

	trigger hide
	{
		setstate axis_radio_destroyed invisible
		setstate axis_radio_destroyed_model invisible
	}

	trigger show
	{
		accum 0 abort_if_not_bitset 2
		setstate axis_radio_destroyed default
		setstate axis_radio_destroyed_model default
	}

	trigger enable
	{
		accum 0 bitset 2
	}
}

axis_radio_closed
{
	trigger hide
	{
		setstate axis_radio_closed invisible
		setstate axis_radio_closed_model invisible
	}

	trigger show
	{
		accum 0 abort_if_bitset 2
		setstate axis_radio_closed default
		setstate axis_radio_closed_model default
	}

	trigger disable
	{
		accum 0 bitset 2
	}
}

axis_radio_built
{
	spawn
	{
		wait 1000
		constructible_class 2
		trigger axis_radio_built setup

		disablespeaker axis_compost_sound
	}

	trigger setup
	{
		setchargetimefactor 0 soldier 1
		setchargetimefactor 0 lieutenant 1
		setchargetimefactor 0 medic 1
		setchargetimefactor 0 engineer 1
		setchargetimefactor 0 covertops 1
		sethqstatus 0 0
	}

	buildstart final
	{
		trigger axis_radio_built_model trans

		trigger axis_radio_destroyed hide
		trigger axis_radio_closed 	hide
	}

	built final
	{
		trigger axis_radio_built_model show

		trigger axis_radio_destroyed enable
		trigger axis_radio_closed 	disable

		trigger axis_radio_built_model enable_axis_features

		enablespeaker axis_compost_sound
	}

	decayed final
	{
		trigger axis_radio_built_model hide

		trigger axis_radio_destroyed show
		trigger axis_radio_closed 	show
	}

	death
	{
		trigger axis_radio_built_model hide

		trigger axis_radio_destroyed show

		trigger axis_radio_built_model disable_axis_features

		disablespeaker axis_compost_sound
	}
}

axis_radio_built_model
{
	spawn
	{
		wait 400
		setstate axis_radio_built_model invisible
	}

	trigger show
	{
		setstate axis_radio_built_model default
	}

	trigger hide
	{
		setstate axis_radio_built_model invisible
	}

	trigger trans
	{
		setstate axis_radio_built_model underconstruction
	}

	trigger enable_axis_features
	{
		setchargetimefactor 0 soldier 0.75
		setchargetimefactor 0 lieutenant 0.75
		setchargetimefactor 0 medic 0.75
		setchargetimefactor 0 engineer 0.75
		setchargetimefactor 0 covertops 0.75
		sethqstatus 0 1

		wm_announce	"Axis Command Post constructed. Charge speed increased!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_compost_constructed"

		wm_teamvoiceannounce 1 "allies_hq_compost_constructed_axis"

		wm_removeteamvoiceannounce 0 "axis_hq_compost_construct"
		// *----------------------------------- vo ------------------------------------------*

		wm_objective_status 7 1 2
		wm_objective_status 7 0 1

	}

	trigger disable_axis_features
	{
		// Some kind of UI pop-up to alert players
		wm_announce	"Allied team has destroyed the Axis Command Post!"

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

		wm_teamvoiceannounce 0 "axis_hq_compost_damaged"
		// *----------------------------------- vo ------------------------------------------*

		setchargetimefactor 0 soldier 1
		setchargetimefactor 0 lieutenant 1
		setchargetimefactor 0 medic 1
		setchargetimefactor 0 engineer 1
		setchargetimefactor 0 covertops 1
		sethqstatus 0 0

		wm_objective_status 7 1 0
		wm_objective_status 7 0 0
	}
}

// ===================================================
// ============== END COMMAND POSTS ==================
// ===================================================

axis_bunker_mg42_clip
{
	spawn
	{
		wait 200
		trigger axis_bunker_mg42_clip setup

		constructible_class 2
	}

	trigger setup
	{
		setstate axis_bunker_mg42 invisible
		setstate axis_bunker_mg42_sbags invisible

		setstate axis_bunker_mg42_materials default
		setstate axis_bunker_mg42_materials_clip default
//		setstate axis_bunker_mg42_flag default
	}

	buildstart final
	{
		setstate axis_bunker_mg42 underconstruction
		setstate axis_bunker_mg42_sbags underconstruction

		setstate axis_bunker_mg42_materials default
		setstate axis_bunker_mg42_materials_clip default
//		setstate axis_bunker_mg42_flag default
	}

	built final
	{
		setstate axis_bunker_mg42 default
		setstate axis_bunker_mg42_sbags default

		setstate axis_bunker_mg42_materials invisible
		setstate axis_bunker_mg42_materials_clip invisible
//		setstate axis_bunker_mg42_flag invisible

		wm_announce "The Axis Bunker MG Nest has been constructed."
	}

	decayed final
	{
		setstate axis_bunker_mg42 invisible
		setstate axis_bunker_mg42_sbags invisible

		setstate axis_bunker_mg42_materials default
		setstate axis_bunker_mg42_materials_clip default
//		setstate axis_bunker_mg42_flag default
	}

	death
	{
		setstate axis_bunker_mg42 invisible
		setstate axis_bunker_mg42_sbags invisible
		repairmg42 axis_bunker_mg42
		setstate axis_bunker_mg42_materials default
		setstate axis_bunker_mg42_materials_clip default
//		setstate axis_bunker_mg42_flag default

		wm_announce "The Axis Bunker MG Nest has been destroyed."
	}
}

allied_cabin_mg42_clip
{
	spawn
	{
		wait 200
		trigger allied_cabin_mg42_clip setup

		constructible_class 2
	}

	trigger setup
	{
		setstate allied_cabin_mg42 invisible

		setstate allied_cabin_mg42_materials default
		setstate allied_cabin_mg42_materials_clip default
	}

	buildstart final
	{
		setstate allied_cabin_mg42 underconstruction

		setstate allied_cabin_mg42_materials default
		setstate allied_cabin_mg42_materials_clip default
	}

	built final
	{
		setstate allied_cabin_mg42 default
		setstate allied_cabin_mg42_materials invisible
		setstate allied_cabin_mg42_materials_clip invisible

		wm_announce "The Allied Cabin MG Nest has been constructed."
	}

	decayed final
	{
		setstate allied_cabin_mg42 invisible
		setstate allied_cabin_mg42_materials default
		setstate allied_cabin_mg42_materials_clip default
	}

	death
	{
		setstate allied_cabin_mg42 invisible
		repairmg42 allied_cabin_mg42
		setstate allied_cabin_mg42_materials default
		setstate allied_cabin_mg42_materials_clip default

		wm_announce "The Allied Cabin MG Nest has been destroyed."
	}
}

//////////////////////////////////////////////////
// Functions for the elevator and elevator doors//
//////////////////////////////////////////////////


//Cabin Level Door

cabindoor1
{

	trigger cabindooropenclose
	{
		wait 1000

		//cabin door open
		trigger cabindoor1 cabindoor1open
		trigger cabindoor2 cabindoor2open
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 1000
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
		wait 3000

		//cabin door close
		trigger cabindoor1 cabindoor1close
		trigger cabindoor2 cabindoor2close

		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 1000
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger cabindooropen
	{
		//cabin door open
		trigger cabindoor1 cabindoor1open
		trigger cabindoor2 cabindoor2open
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
		wait 1000
	}

	trigger cabindoorclose
	{
		//cabin door close
		trigger cabindoor1 cabindoor1close
		trigger cabindoor2 cabindoor2close
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger cabindoor1open
	{
		gotomarker cabinopen 40
	}

	trigger cabindoor1close
	{
		gotomarker cabinclosed1 40
	}
}

cabindoor2
{
	trigger cabindoor2open
	{
		gotomarker cabinopen 20
	}

	trigger cabindoor2close
	{
		gotomarker cabinclosed2 20
	}
}

//Basement Level 1 Door

b1door1
{

	trigger b1dooropenclose
	{
		wait 1000

		//b1door open
		trigger b1door1 b1door1open
		trigger b1door2 b1door2open
		trigger b1door3 b1door3open
		trigger b1door4 b1door4open
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
		
		wait 3000

		//b1door close
		trigger b1door1 b1door1close
		trigger b1door2 b1door2close
		trigger b1door3 b1door3close
		trigger b1door4 b1door4close
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger b1dooropen
	{
		//b1door open
		trigger b1door1 b1door1open
		trigger b1door2 b1door2open
		trigger b1door3 b1door3open
		trigger b1door4 b1door4open
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
		wait 1000
	}

	trigger b1doorclose
	{
		//b1door close
		trigger b1door1 b1door1close
		trigger b1door2 b1door2close
		trigger b1door3 b1door3close
		trigger b1door4 b1door4close
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger b1door1open
	{
		gotomarker b1doorleft 20
	}

	trigger b1door1close
	{
		gotomarker b1door1 20
	}
}

b1door2
{
	trigger b1door2open
	{
		gotomarker b1doorleft 40
	}

	trigger b1door2close
	{
		gotomarker b1door2 40
	}
}

b1door3
{
	trigger b1door3open
	{
		gotomarker b1doorright 40
	}

	trigger b1door3close
	{
		gotomarker b1door3 40
	}
}

b1door4
{
	trigger b1door4open
	{
		gotomarker b1doorright 20
	}

	trigger b1door4close
	{
		gotomarker b1door4 20
	}
}

//Basement Level 2 Door

b2door1
{

	trigger b2dooropenclose
	{
		wait 1000

		//b2door open
		trigger b2door1 b2door1open
		trigger b2door2 b2door2open
		trigger b2door3 b2door3open
		trigger b2door4 b2door4open
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
		wait 3000

		//b2door close
		trigger b2door1 b2door1close
		trigger b2door2 b2door2close
		trigger b2door3 b2door3close
		trigger b2door4 b2door4close
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger b2dooropen
	{
		//b2door open
		trigger b2door1 b2door1open
		trigger b2door2 b2door2open
		trigger b2door3 b2door3open
		trigger b2door4 b2door4open
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
		wait 1000
	}

	trigger b2doorclose
	{
		//b2door close
		trigger b2door1 b2door1close
		trigger b2door2 b2door2close
		trigger b2door3 b2door3close
		trigger b2door4 b2door4close
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger b2door1open
	{
		gotomarker b2doorleft 20
	}

	trigger b2door1close
	{
		gotomarker b2door1 20
	}
}

b2door2
{
	trigger b2door2open
	{
		gotomarker b2doorleft 40
	}

	trigger b2door2close
	{
		gotomarker b2door2 40
	}
}

b2door3
{
	trigger b2door3open
	{
		gotomarker b2doorright 40
	}

	trigger b2door3close
	{
		gotomarker b2door3 40
	}
}

b2door4
{
	trigger b2door4open
	{
		gotomarker b2doorright 20
	}

	trigger b2door4close
	{
		gotomarker b2door4 20
	}
}

//Basement Level 3 Door

b3door1
{

	trigger b3dooropenclose
	{
		wait 1000

		//b3door open
		trigger b3door1 b3door1open
		trigger b3door2 b3door2open
		trigger b3door3 b3door3open
		trigger b3door4 b3door4open
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
		wait 3000

		//b3door close
		trigger b3door1 b3door1close
		trigger b3door2 b3door2close
		trigger b3door3 b3door3close
		trigger b3door4 b3door4close
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger b3dooropen
	{
		//b3door open
		trigger b3door1 b3door1open
		trigger b3door2 b3door2open
		trigger b3door3 b3door3open
		trigger b3door4 b3door4open
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
		wait 1000
	}

	trigger b3doorclose
	{
		//b3door close
		trigger b3door1 b3door1close
		trigger b3door2 b3door2close
		trigger b3door3 b3door3close
		trigger b3door4 b3door4close
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 742
		playsound sound/movers/doors/door3_loopo.wav looping
		wait 500
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger b3door1open
	{
		gotomarker b3doorleft 20
	}

	trigger b3door1close
	{
		gotomarker b3door1 20
	}
}

b3door2
{
	trigger b3door2open
	{
		gotomarker b3doorleft 40
	}

	trigger b3door2close
	{
		gotomarker b3door2 40
	}
}

b3door3
{
	trigger b3door3open
	{
		gotomarker b3doorright 40
	}

	trigger b3door3close
	{
		gotomarker b3door3 40
	}
}

b3door4
{
	trigger b3door4open
	{
		gotomarker b3doorright 20
	}

	trigger b3door4close
	{
		gotomarker b3door4 20
	}
}

// Elevator movements
elevator
{
	spawn
	{
		wait 500
		accum 1 set 0 // Which floors have called the elevator. (floor b1)
		accum 2 set 0 // Which floors have called the elevator. (floor b2)
		accum 3 set 0 // Which floors have called the elevator. (floor b3)
		accum 4 set 2 // Current floor the elevator moving to or is on.
		accum 5 set 0 // Is the elevator moving? Call Button lockout.

		wait 2000
		trigger b2door1 b2dooropen
	}

	trigger b1_call_button
	{
		accum 4 abort_if_equal 1
		accum 1 set 1

		accum 5 abort_if_equal 1

		trigger elevator call_button_check
	}

	trigger b2_call_button
	{
		accum 4 abort_if_equal 2
		accum 2 set 1

		accum 5 abort_if_equal 1

		trigger elevator call_button_check
	}

	trigger b3_call_button
	{
		accum 4 abort_if_equal 3
		accum 3 set 1

		accum 5 abort_if_equal 1

		trigger elevator call_button_check
	}

	trigger call_button_check
	{
		accum 5 abort_if_equal 1

		accum 3 trigger_if_equal 1 elevator goto_b3
		accum 3 abort_if_equal 1

		accum 2 trigger_if_equal 1 elevator goto_b2
		accum 2 abort_if_equal 1

		accum 1 trigger_if_equal 1 elevator goto_b1
	}

	trigger goto_cabin
	{

	}
	
	trigger goto_b1
	{
		accum 4 trigger_if_equal 0 elevator 1_to_b1
		accum 4 trigger_if_equal 2 elevator b2_to_b1
		accum 4 trigger_if_equal 3 elevator b3_to_b1
	}

	trigger goto_b2
	{
		accum 4 trigger_if_equal 0 elevator 1_to_b2
		accum 4 trigger_if_equal 1 elevator b1_to_b2
		accum 4 trigger_if_equal 3 elevator b3_to_b2
	}

	trigger goto_b3
	{
		accum 4 trigger_if_equal 0 elevator 1_to_b3
		accum 4 trigger_if_equal 1 elevator b1_to_b3
		accum 4 trigger_if_equal 2 elevator b2_to_b3
	}

	trigger 1_to_b1
	{
		//from floor 1 to b1
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 1
		trigger cabindoor1 cabindoorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floor1_bottom 40 wait
		gotomarker floorb1_top 90 wait
		gotomarker floorb1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b1door1 b1dooropen
		wait 2000
		accum 1 set 0
		setstate b1_button_up default
		setstate b1_button_down default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger 1_to_b2
	{
		//from floor 1 to b2
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 2
		trigger cabindoor1 cabindoorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floor1_bottom 40 wait
		gotomarker floorb2_top 90 wait
		gotomarker floorb2 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b2door1 b2dooropen
		wait 2000
		accum 2 set 0
		setstate b2_button_up default
		setstate b2_button_down default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger 1_to_b3
	{
		//from floor 1 to b3
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 3
		trigger cabindoor1 cabindoorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floor1_bottom 40 wait
		gotomarker floorb3_top 90 wait
		gotomarker floorb3 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b3door1 b3dooropen
		wait 2000
		accum 3 set 0
		setstate b3_button_up default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}
	
	trigger b1_to_1
	{
		//from floor b1 to 1
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 0
		trigger b1door1 b1doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping	
		gotomarker floorb1_top 40 wait
		gotomarker floor1_bottom 90 wait
		gotomarker floor1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger cabindoor1 cabindooropen
		wait 2000
		setstate cabin_button_down default
		wait 5000
		accum 5 set 0
		trigger elevator call_button_check
	}
	
	trigger b1_to_b2
	{
		//from floor b1 to b2
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 2
		trigger b1door1 b1doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb1_bottom 40 wait
		gotomarker floorb2_top 90 wait
		gotomarker floorb2 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b2door1 b2dooropen
		wait 2000
		accum 2 set 0
		setstate b2_button_up default
		setstate b2_button_down default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger b1_to_b3
	{
		//from floor b1 to b3
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 3
		trigger b1door1 b1doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb1_bottom 40 wait
		gotomarker floorb3_top 90 wait
		gotomarker floorb3 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b3door1 b3dooropen
		wait 2000
		accum 3 set 0
		setstate b3_button_up default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger b2_to_1
	{
		//from floor b2 to 1
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 100
		accum 4 set 0
		trigger b2door1 b2doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping
		gotomarker floorb2_top 40 wait
		gotomarker floor1_bottom 90 wait
		gotomarker floor1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger cabindoor1 cabindooropen
		wait 2000
		setstate cabin_button_down default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger b2_to_b1
	{
		//from floor b2 to b1
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 100
		accum 4 set 1
		trigger b2door1 b2doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping
		gotomarker floorb2_top 40 wait
		gotomarker floorb1_bottom 90 wait
		gotomarker floorb1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b1door1 b1dooropen
		wait 2000
		accum 1 set 0
		setstate b1_button_up default
		setstate b1_button_down default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger b2_to_b3
	{
		//from floor b2 to b3
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 3
		trigger b2door1 b2doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96	
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb2_bottom 40 wait
		gotomarker floorb3_top 90 wait
		gotomarker floorb3 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b3door1 b3dooropen
		wait 2000
		accum 3 set 0
		setstate b3_button_up default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}
	
	trigger b3_to_1
	{
		//from floor b3 to 1
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 0
		trigger b3door1 b3doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb3_top 40 wait
		gotomarker floor1_bottom 90 wait
		gotomarker floor1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger cabindoor1 cabindooropen
		wait 2000
		setstate cabin_button_down default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger b3_to_b1
	{
		//from floor b3 to b1
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 1
		trigger b3door1 b3doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb3_top 40 wait
		gotomarker floorb1_bottom 90 wait
		gotomarker floorb1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b1door1 b1dooropen
		wait 2000
		accum 1 set 0
		setstate b1_button_up default
		setstate b1_button_down default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger b3_to_b2
	{
		//from floor b3 to b2
		trigger cabin_button hide_all_buttons
		accum 5 set 1
		wait 50
		accum 4 set 2
		trigger b3door1 b3doorclose
		wait 1000
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 800
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb3_top 40 wait
		gotomarker floorb2_bottom 90 wait
		gotomarker floorb2 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b2door1 b2dooropen
		wait 2000
		accum 2 set 0
		setstate b2_button_up default
		setstate b2_button_down default
		wait 3000
		accum 5 set 0
		trigger elevator call_button_check
	}

	trigger cycle_elevator		
	{
		//from floor b2 to b1
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 1000
		playsound sound/movers/elevators/elev1_loop.wav looping
		gotomarker floorb2_top 40 wait
		gotomarker floorb1_bottom 90 wait
		gotomarker floorb1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b1door1 b1dooropenclose
		wait 8000

		//from floor b1 to 1
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 1000
		playsound sound/movers/elevators/elev1_loop.wav looping	
		gotomarker floorb1_top 40 wait
		gotomarker floor1_bottom 90 wait
		gotomarker floor1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger cabindoor1 cabindooropenclose
		wait 9000

		//from floor 1 to b1
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 1000
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floor1_bottom 40 wait
		gotomarker floorb1_top 90 wait
		gotomarker floorb1 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b1door1 b1dooropenclose
		wait 8000

		//from floor b1 to b2
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 1000
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb1_bottom 40 wait
		gotomarker floorb2_top 90 wait
		gotomarker floorb2 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b2door1 b2dooropenclose
		wait 8000

		//from floor b2 to b3
		playsound sound/movers/elevators/elev1_start.wav volume 96	
		wait 1000
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb2_bottom 40 wait
		gotomarker floorb3_top 90 wait
		gotomarker floorb3 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b3door1 b3dooropenclose
		wait 8000

		//from floor b3 to b2
		playsound sound/movers/elevators/elev1_start.wav volume 96
		wait 1000
		playsound sound/movers/elevators/elev1_loop.wav looping		
		gotomarker floorb3_top 40 wait
		gotomarker floorb2_bottom 90 wait
		gotomarker floorb2 40 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 96
		trigger b2door1 b2dooropenclose
		wait 8000

		trigger elevator start_elevator
	}

	trigger elevator_destroyed
	{
		accum 5 set 1
		setstate cabin_button_down invisible
		setstate b1_button_up invisible
		setstate b1_button_down invisible
		setstate b2_button_up invisible
		setstate b2_button_down invisible
		setstate b3_button_up invisible
		
		wait 300
		trigger cabindoor1 cabindooropen
		wait 350
		trigger b2door1 b2dooropen
		wait 200		
		trigger b1door1 b1dooropen
		wait 250
		trigger b3door1 b3dooropen
				
		stopsound
		playsound sound/movers/misc/garage_door_loop_01.wav looping volume 1000
		gotomarker bottom 600 wait
		stopsound
		playsound sound/movers/elevators/elev1_end.wav volume 400
	}

	trigger elevator_fixed
	{
		wait 300
		trigger cabindoor1 cabindoorclose
		wait 200
		trigger b2door1 b2doorclose
		wait 100
		trigger b1door1 b1doorclose
		wait 200

		setstate b3_button_up default
		accum 4 set 3
		accum 5 set 0
		accum 3 set 0
		accum 2 set 0
		accum 1 set 0
		
		gotomarker floorb3 10 wait
		playsound sound/movers/elevators/elev1_end.wav volume 96
	}

}

// Elevator Buttons (call, up, down)

cabin_button
{
	spawn
	{
		setstate cabin_button_down invisible
	}

	trigger hide_all_buttons
	{
		setstate cabin_button_down invisible
		setstate b1_button_up invisible
		setstate b1_button_down invisible
		setstate b2_button_up invisible
		setstate b2_button_down invisible
		setstate b3_button_up invisible
	}
	
	trigger down
	{
		togglespeaker cabin_button_sound
		trigger elevator 1_to_b1		
	}
}

b1_button
{
	spawn
	{
		setstate b1_button_down invisible
		setstate b1_button_up invisible
	}

	trigger call
	{
		togglespeaker b1_call_button_sound

		trigger elevator b1_call_button
	}

	trigger up
	{
		togglespeaker b1_button_sound
		trigger elevator b1_to_1
	}

	trigger down
	{
		togglespeaker b1_button_sound
		trigger elevator b1_to_b2
	}
}

b2_button
{
	spawn
	{
		setstate b2_button_down default
		setstate b2_button_up default
	}

	trigger call
	{
		togglespeaker b2_call_button_sound

		trigger elevator b2_call_button
	}

	trigger up
	{
		togglespeaker b2_button_sound
		trigger elevator b2_to_b1
	}

	trigger down
	{
		togglespeaker b2_button_sound
		trigger elevator b2_to_b3
	}
}

b3_button
{
	spawn
	{
		setstate b3_button_up invisible
	}

	trigger call
	{
		togglespeaker b3_call_button_sound

		trigger elevator b3_call_button
	}

	trigger up
	{
		togglespeaker b3_button_sound
		trigger elevator b3_to_b2
	}
}



// Script for the moving rock

rockbutton
{
	spawn
	{
		accum 0 bitreset 3
	}

	trigger rockopenclose
	{
		trigger rockbutton open
		trigger rockbutton close
	}

	trigger close
	{
		accum 0 abort_if_not_bitset 3
		gotomarker rock_button_out 5
		playsound sound/movers/switches/switch.wav volume 96
		wait 500
		accum 0 bitreset 3
		trigger rock rockclose
	}

	trigger open
	{
		accum 0 abort_if_bitset 3
		gotomarker rock_button_in 5
		playsound sound/movers/switches/switch.wav volume 96
		wait 500
		accum 0 bitset 3
		trigger rock rockopen
	}
}

rock
{
	trigger rockopen
	{
		playsound sound/movers/doors/door2_open.wav volume 96
		wait 540
		playsound sound/movers/doors/door2_loop.wav looping
		gotomarker rockopen 25 wait
		stopsound
		playsound sound/movers/doors/door2_locked.wav volume 96
		wait 5000
		trigger rockbutton rockopenclose
	}

	trigger rockclose
	{
		playsound sound/movers/doors/door2_open.wav volume 96
		wait 540
		playsound sound/movers/doors/door2_loop.wav looping
		gotomarker rockclose 25 wait
		stopsound
		playsound sound/movers/doors/door2_locked.wav volume 96	
	}
}


// Script for the book case

bookcasebutton
{
	spawn
	{
		accum 0 bitreset 4
	}

	trigger bookcaseopenclose
	{
		trigger bookcasebutton open
		trigger bookcasebutton close
	}

	trigger close
	{
		accum 0 abort_if_not_bitset 4
		accum 0 bitreset 4
		gotomarker bookcasebuttonup 15
		playsound sound/movers/switches/butn2.wav volume 96
		wait 250
		trigger bookcase bookcaseclose
	}

	trigger open
	{
		accum 0 abort_if_bitset 4
		accum 0 bitset 4
		gotomarker bookcasebuttondown 15
		playsound sound/movers/switches/butn2.wav volume 96
		wait 250
		trigger bookcase bookcaseopen
	}
}

bookcase
{
	trigger bookcaseopen
	{
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 300
		stopsound
		playsound sound/movers/doors/door3_loopo.wav looping
		gotomarker bookcaseopen 25 wait
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}

	trigger bookcaseclose
	{
		playsound sound/movers/doors/door3_open.wav volume 96
		wait 300
		stopsound
		playsound sound/movers/doors/door3_loopo.wav looping
		gotomarker bookcaseclose 25 wait
		stopsound
		playsound sound/movers/doors/door3_endo.wav volume 96
	}
}

// **********************************************
// ****************** TRUCK STUFF ***************
// **********************************************

truck_smoke
{
	spawn
	{
		wait 300
		attachtotag truck tag_wfront
		setstate truck_smoke invisible
	}
}

// sound "thread"
truck_engine
{
	spawn
	{
		wait 200
		attachtotag truck tag_wfront

		trigger truck_engine sound_idle
	}

	trigger start
	{
		trigger truck_engine sound_start
		wait 950
		trigger truck_engine sound_move
	}

	trigger stop
	{
		trigger truck_engine sound_stop
		wait 950
		trigger truck_engine sound_idle
	}

	// ========================================
	// sound events
	trigger sound_idle
	{
		playsound sound/vehicles/truck/truck_idle.wav looping
	}

	trigger sound_start
	{
		stopsound
		playsound sound/vehicles/truck/truck_revup.wav volume 96
	}

	trigger sound_move
	{
		playsound sound/vehicles/truck/truck_move.wav looping
	}

	trigger sound_stop
	{
		stopsound
		playsound sound/vehicles/truck/truck_revdown.wav volume 96
	}

	trigger sound_death
	{
		stopsound
		playsound sound/vehicles/truck/truck_stop.wav volume 96
	}

	// ========================================
	// ========================================
}

truck_build
{
	spawn
	{
		wait 100

		attachtotag truck tag_wback
	}
}

truck_construct
{
	spawn
	{
		constructible_class 2
		constructible_health 1050
		constructible_constructxpbonus 10
		constructible_destructxpbonus 10
	}

	built final
	{
		alertentity truck

		wm_announce "The Truck has been repaired!"
		wm_objective_status 6 1 1
		wm_objective_status 6 0 2
	}
}

truck
{
	spawn
	{
		faceangles 0 0 0 50
		//faceangles 0 90 0 50
		trigger truck run_1
	}

	// ========================================
	// wheeeeeeeeeeeeeeels. eeels. ls.
	trigger wheels_forward
	{
		trigger truck_bwheel2 forward
		trigger truck_fwheel forward
	}

	trigger wheels_backward
	{
		trigger truck_bwheel2 backward
		trigger truck_fwheel backward
	}

	trigger wheels_stop
	{
		trigger truck_bwheel2 stop
		trigger truck_fwheel stop
	}

	// ========================================
	// movement

	trigger run_1
	{
		followspline 0 tspln_1 125 wait length 304

		wait 1500
		trigger truck wheels_forward
		trigger truck_engine start

		followspline 0 tspln_2 125 wait length 304

		alertentity gater

		followspline 0 gate 125 wait length 304
		followspline 0 tspln_3 125 wait length 304
		followspline 0 tspln_4 125 wait length 304
		followspline 0 tspln_5 125 wait length 304
		followspline 0 tspln_6 125 wait length 304

		trigger game_manager allied_spawn_truck

		followspline 0 tspln_7 125 wait length 304
		followspline 0 tspln_8 125 wait length 304
		followspline 0 tspln_9 125 wait length 304
		followspline 0 tspln_10 125 wait length 304
		followspline 0 tspln_11 125 wait length 304

		trigger truck_engine stop
		trigger truck wheels_stop
	}

	trigger run_2
	{
		trigger game_manager allies_win
		trigger truck_engine start
		trigger truck wheels_forward

		followspline 0 tspln_12 125 wait length 304
		followspline 0 tspln_13 125 wait length 304
		followspline 0 tspln_14 125 wait length 304
		followspline 0 tspln_15 125 wait length 304
		followspline 0 tspln_16 125 wait length 304
		followspline 0 tspln_17 125 wait length 304
		followspline 0 tspln_18 125 wait length 304
	}

	// ========================================
	// death / rebirth

	rebirth
	{
		changemodel models/mapobjects/blitz_sd/blitzbody.md3

		setstate truck_smoke invisible

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_truck_repaired_allies"

		wm_teamvoiceannounce 1 "allies_hq_truck_repaired"
		// *---------------------------------------------------------------------------------*

		trigger truck_engine sound_idle

		setstate docs_holder default
	}

	death
	{
		wm_announce "The Truck has been damaged!"

		wm_objective_status 6 1 2
		wm_objective_status 6 0 1	
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_truck_damaged"

		wm_teamvoiceannounce 1 "allies_hq_truck_damaged_axis"
		// *---------------------------------------------------------------------------------*

		setstate truck_smoke default
		kill truck_construct

		trigger truck_engine sound_death

		changemodel models/mapobjects/blitz_sd/blitzbody_damaged.md3
		
		setstate docs_holder invisible

		resetscript
	}

	// ========================================
	// ========================================
}
	
truck_bwheel2
{
	spawn
	{
		wait 100

		attachtotag truck tag_wback
	}

	trigger forward
	{
		setrotation 130 0 0
	}

	trigger backward
	{
		setrotation -130 0 0
	}

	trigger stop
	{
		stoprotation
	}
}

truck_fwheel
{
	spawn
	{
		wait 100

		attachtotag truck tag_wfront
	}

	trigger forward
	{
		setrotation 130 0 0
	}

	trigger backward
	{
		setrotation -130 0 0
	}

	trigger stop
	{
		stoprotation
	}
}

truck_trigger
{
	spawn
	{
		wait 100

		attachtotag truck tag_wback
	}
}
