game_manager
{
	spawn
	{
		wait 250

		// Game rules
		wm_axis_respawntime	20
		wm_allied_respawntime	20
		wm_number_of_objectives 7
		wm_set_round_timelimit	30
		
		// Stopwatch mode defending team (0=Axis, 1=Allies)
		//wm_set_defending_team	1

		// Winner on expiration of round timer (0=Axis, 1=Allies)
		wm_setwinner	-1
		
		wm_set_main_objective 1 0
		wm_set_main_objective 1 1
		
		// obj's
		wm_teamvoiceannounce 1 "allies_hq_compost_construct"
		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"
		wm_teamvoiceannounce 0 "axis_hq_compost_construct"
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

		
		// 0 null, 1 suc 2 fail
		// ref team val
		
		wm_objective_status 1 0 0
		wm_objective_status 1 1 0

		// controls the map start / who wins the fwd spawn //
		globalaccum 0 set 0

		wait 150
	 }

	 trigger axis_att
	 {
	 	wm_setwinner 1
	 }

	 trigger axis_def
	 {
	 	wm_setwinner 0
	 }

	 trigger win_axis
	 {
	 	wm_setwinner 0
		wait 2400
		wm_endround
		wait 6000
	 }

	 trigger win_allied
	 {
	 	wm_setwinner 1
		wait 2400
		wm_endround
		wait 6000
	 }
}

// Trap 1 START
sand_trap_target
{
	trigger
	{
		trigger sand_trap_door door_close
	}
}

sand_trap_door
{
	spawn
	{
		wait 250
		// start off up
		trigger self door_open
	}

	trigger door_close
	{
		accum 1 abort_if_equal 1
		accum 1 set 1
		
		setstate sand_trap_flow default
		gotomarker sand_door_down 100 wait
		trigger sand_trap_flow do_drown
	}

	trigger door_open
	{
		accum 1 set 0
		setstate sand_trap_flow invisible
		gotomarker sand_door_up 100 wait
	}
}

sand_trap_flow
{
	spawn
	{
		wait 250
	}

	trigger do_drown
	{
		gotomarker sand_trap_up 50 wait
		wait 23500
		trigger self undo_drown
	}

	trigger undo_drown
	{
		gotomarker sand_trap_down 50 wait
		trigger sand_trap_door door_open
	}
}

// Trap 1 STOP

// Entrance START

axis_att
{
	spawn
	{
		wait 150
		constructible_class 3
	}

	death
	{
		// print out //
		wm_announce "The Axis Tomb entrance has been blown!"
	}
}

allied_att
{
	spawn
	{
		wait 150
		constructible_class 3
	}

	death
	{
		// print out //
		wm_announce "The Allies Tomb entrance has been blown!"
	}
}

// Entrance STOP

// ramp trap start //

ramp_trap
{
	trigger put_up
	{
		setrotation 0 0 60
		wait 1000
		stoprotation
	}

	trigger put_down
	{
		setrotation 0 0 -60
		wait 1000
		stoprotation
	}
}

ramp_trap_sw
{
	trigger put_up
	{
		gotomarker ramp_trap_up 10 wait
	}

	trigger put_down
	{
		gotomarker ramp_trap_down 10 wait
	}
}

ramp_trap_script
{
	activate allies
	{
		trigger self logic
	}

	activate axis
	{
		trigger self logic
	}

	trigger logic
	{
		// can only be called every 45 secs //
		trigger ramp_trap_sw put_up
		trigger ramp_trap put_down

		wait 2000

		trigger ramp_trap_sw put_down
		trigger ramp_trap put_up
	}
}

// ramp trap stop //

// ramp start

axis_ramp
{
	spawn
	{
		wait 150
		constructible_class 2
		constructible_constructxpbonus 12
		constructible_destructxpbonus 12
		setstate ramp_construct default
		setstate ramp_clip default
		setstate ramp_flag default
	}

	built final
	{
		setstate ramp_construct invisible
		setstate ramp_clip invisible
		setstate ramp_flag invisible
	}

	decayed final
	{
		setstate ramp_construct default
		setstate ramp_clip default
		setstate ramp_flag default
	}

	death
	{
		wm_announce "Ramp destroyed!"
		setstate ramp_construct default
		setstate ramp_clip default
		setstate ramp_flag default
	}

	trigger r_die
	{
		kill axis_ramp_toi
		remove
	}
}

allied_ramp
{
	spawn
	{
		wait 150
		constructible_class 2
		constructible_constructxpbonus 12
		constructible_destructxpbonus 12
		setstate ramp_construct default
		setstate ramp_clip default
		setstate ramp_flag default
	}

	built final
	{
		setstate ramp_construct invisible
		setstate ramp_clip invisible
		setstate ramp_flag invisible
	}

	decayed final
	{
		setstate ramp_construct default
		setstate ramp_clip default
		setstate ramp_flag default
	}

	death
	{
		wm_announce "Ramp destroyed!"
		setstate ramp_construct default
		setstate ramp_clip default
		setstate ramp_flag default
	}

	trigger r_die
	{
		kill allied_ramp_toi
		remove
	}
}

// ramp stop

// Tomb door START
tomb_door
{
	spawn
	{
		wait 250
		constructible_class 3
	}

	death
	{
		// print out //
		wm_announce "The Tomb door has been blown!"
	}
}


// in door START
srt_indoor
{
	spawn
	{
		wait 250
		constructible_class 3
	}

	death
	{
		// change limbo info //
		wm_objective_status 2 0 1
		wm_objective_status 2 1 2

		// print out //
		wm_announce "The Internal door has been blown!"
	}
	
}
// in door STOP

// tunnel door START
srt_tundoor
{
	spawn
	{
		wait 250
		constructible_class 3
	}

	death
	{
		// change limbo info //
		wm_objective_status 3 0 1
		wm_objective_status 4 1 2

		// print out //
		wm_announce "The tunnel door has been blown!"
	}
	
}

// tunnel door STOP


// Ball START

ball
{
	spawn
	{
		wait 250
		accum 2 set 0
		setposition ball_start
	}

	trigger do_run
	{
		accum 2 abort_if_equal 1
		accum 2 set 1

		gotomarker ball_point1 300 wait
		gotomarker ball_point2 350 wait
		gotomarker ball_point3 400 wait
		gotomarker ball_stop 550 wait
		wait 10000
		setposition ball_start
		accum 2 set 0
	}
}

ball_script
{
	spawn
	{
		wait 250
		accum 2 set 0
	}
	
	trigger
	{
		accum 2 abort_if_equal 1
		accum 2 set 1

		trigger ball do_run

		accum 2 set 0
	}
}

// Ball STOP

// Init Spawn START

init_ctf_spwn
{
	spawn
	{
		wait 250
		
		// nobody owns the spawn initially //
		accum 1 set 0
	}
	
	trigger allied_capture
	{
		// can't capture it if axis already own it //
		accum 3 abort_if_equal 2

		// now they own it - stfu axis! //
		accum 3 set 1
		
		// tell the world about this //
		wm_announce	"Allies take the Forward spawn!"

		// switch allies to active and axis to inactive //
		alertentity init_ctf_blob
		setautospawn "Attacking spawn" 1

		// move axis to def.
		alertentity def_spawn_axis

		// stop old spawn
		alertentity init_axis_spwn

		// state of play
		trigger game_manager axis_def

		// remove the allied build obj
		trigger slide_door_allied r_die
		trigger tomb_door_allied r_die
		trigger dyno_slide_allied r_die

		trigger axis_ramp r_die

		// remove me
		setstate init_ctf_spwn invisible
		setstate axis_ctf_obj default
		alertentity axis_ctf_obj

		kill post_spawn
		remove
	}
	
	trigger axis_capture
	{
		// can't capture it if allies already own it //
		accum 3 abort_if_equal 1

		// now they own it - weak allies! //
		accum 3 set 2
		
		// tell the world about this //
		wm_announce	"Axis capture the Forward spawn!"

		// switch allies to inactive and axis to active //
		alertentity init_ctf_blob
		setautospawn "Attacking spawn" 0

		// move allies to def
		alertentity def_spawn_allied

		// stop old spawn
		alertentity init_allies_spwn

		// state of play
		trigger game_manager axis_att

		// remove the allied build obj/destroy
		trigger slide_door_axis r_die
		trigger tomb_door_axis r_die
		trigger dyno_slide_axis r_die


		trigger allied_ramp r_die
		
		// remove me
		setstate init_ctf_spwn invisible
		setstate allied_ctf_obj default
		alertentity allied_ctf_obj

		kill post_spawn
		remove
	}
	
}

// Init Spawn STOP

// Allied Bridge START

allied_bridge_sw_script
{
	spawn
	{
		wait 250
		accum 1 set 1
		
		trigger allied_bridge put_up
		trigger allied_bridge_sw put_up
	}
	
	activate allies
	{
		trigger self eval
	}

	activate axis
	{
		trigger self eval
	}

	trigger eval
	{
		accum 1 trigger_if_equal 0 allied_bridge_sw_script eval_t
		accum 1 trigger_if_equal 1 allied_bridge_sw_script eval_f
		
		// if at 0|1 then eval_x not called so abrt
		accum 1 abort_if_equal 0
		accum 1 abort_if_equal 1

		// eval_x inc'ed this value to prevent loop so dec it
		accum 1 set 1
	}

	trigger eval_t
	{
		accum 1 set 2
		trigger allied_bridge put_up
		trigger allied_bridge_sw put_up
	}

	trigger eval_f
	{
		accum 1 set 0
		trigger allied_bridge put_down
		trigger allied_bridge_sw put_down
	}
}

allied_bridge
{
	trigger put_up
	{
		setrotation 60 0 0
		wait 1000
		stoprotation
	}

	trigger put_down
	{
		setrotation -60 0 0
		wait 1000
		stoprotation
	}
}

allied_bridge_sw
{
	trigger put_up
	{
		gotomarker allied_bridge_sw_top 10 wait
	}

	trigger put_down
	{
		gotomarker allied_bridge_sw_bot 10 wait
	}
}

// Allied Bridge STOP



// Axis Bridge START

axis_bridge_sw_script
{
	spawn
	{
		wait 250
		accum 1 set 1
		
		trigger axis_bridge put_up
		trigger axis_bridge_sw put_up
	}
	
	activate allies
	{
		trigger self eval
	}

	activate axis
	{
		trigger self eval
	}

	trigger eval
	{
		accum 1 trigger_if_equal 0 axis_bridge_sw_script eval_t
		accum 1 trigger_if_equal 1 axis_bridge_sw_script eval_f
		
		// if at 0|1 then eval_x not called so abrt
		accum 1 abort_if_equal 0
		accum 1 abort_if_equal 1

		// eval_x inc'ed this value to prevent loop so dec it
		accum 1 set 1
	}

	trigger eval_t
	{
		accum 1 set 2
		trigger axis_bridge put_up
		trigger axis_bridge_sw put_up
	}

	trigger eval_f
	{
		accum 1 set 0
		trigger axis_bridge put_down
		trigger axis_bridge_sw put_down
	}
}

axis_bridge
{
	trigger put_up
	{
		setrotation 60 0 0
		wait 1000
		stoprotation
	}

	trigger put_down
	{
		setrotation -60 0 0
		wait 1000
		stoprotation
	}
}

axis_bridge_sw
{
	trigger put_up
	{
		gotomarker axis_bridge_sw_top 10 wait
	}

	trigger put_down
	{
		gotomarker axis_bridge_sw_bot 10 wait
	}
}

// Axis Bridge STOP

// Blade Right START

blade_right_script
{
	spawn
	{
		wait 250
		accum 1 set 0
	}
	
	trigger
	{
		accum 1 abort_if_equal 1
		accum 1 set 1
		
		trigger blade_right out
		wait 500
		trigger blade_right in

		accum 1 set 0
	}
}

blade_right
{
	spawn
	{
		wait 250
		trigger self in
	}
	
	trigger out
	{
		gotomarker blade_right_out 250 wait
	}

	trigger in
	{
		gotomarker blade_right_in 125 wait
	}
}

// Blade Right STOP

// Blade Left START

blade_left_script
{
	spawn
	{
		wait 250
		accum 1 set 0
	}
	
	trigger
	{
		accum 1 abort_if_equal 1
		accum 1 set 1
		
		trigger blade_left out
		wait 500
		trigger blade_left in

		accum 1 set 0
	}
}

blade_left
{
	spawn
	{
		wait 250
		trigger self in
	}
	
	trigger out
	{
		gotomarker blade_left_out 250 wait
	}

	trigger in
	{
		gotomarker blade_left_in 125 wait
	}
}

// Blade Left STOP


// Main obj axis START

axis_ctf_obj_fin
{
	death
	{
		trigger game_manager win_allied
	}
}

// Main obj axis STOP

// Main obj allied START

allied_ctf_obj_fin
{
	death
	{
		trigger game_manager win_axis
	}
}

// Main obj allied STOP


// Tomb door START

tomb_door_allied
{
	spawn
	{
		wait 150
		setstate tomb_door_allied invisible
	}

	trigger r_die
	{
		setstate tomb_door_axis default
		remove
	}
}

tomb_door_axis
{
	spawn
	{
		wait 150
		setstate tomb_door_axis invisible
	}

	trigger r_die
	{
		setstate tomb_door_allied default
		remove
	}
}

// Tomb door STOP



// dyno_slide START
dyno_slide
{
	spawn
	{                                      	
		wait 250
		constructible_class 3
	}

	death
	{
		// print out //
		wm_announce "The Light shaft has been blown through!"
	}
}

dyno_slide_axis
{
	spawn
	{
		wait 150
		setstate dyno_slide_axis invisible
	}

	trigger r_die
	{
		setstate dyno_slide_allied default
		remove
	}
}

dyno_slide_allied
{
	spawn
	{
		wait 150
		setstate dyno_slide_allied invisible
	}

	trigger r_die
	{
		setstate dyno_slide_axis default
		remove
	}
}

// dyno_slide STOP


// Slide door START

slide_door_axis
{
	spawn
	{
		wait 150
		constructible_class 2
		constructible_constructxpbonus 12
		constructible_destructxpbonus 12
		setstate slide_door_crates default
		setstate slide_door_crates_clip default
		setstate slide_door_flag default
		setstate slide_door_dyno_axis default
	}

	built final
	{
		setstate slide_door_crates invisible
		setstate slide_door_crates_clip invisible
		setstate slide_door_flag invisible
		setstate slide_door_dyno_axis invisible
	}

	decayed final
	{
		setstate slide_door_crates default
		setstate slide_door_crates_clip default
		setstate slide_door_flag default
		setstate slide_door_dyno_axis default
	}

	death
	{
		wm_announce "The door to the slide has been destroyed!"
		setstate slide_door_crates default
		setstate slide_door_crates_clip default
		setstate slide_door_flag default
		setstate slide_door_dyno_axis default
	}

	trigger r_die
	{
		trigger slide_door_dyno_axis r_die
		remove
	}
}

slide_door_dyno_axis
{
	spawn
	{
		wait 150
	}

	trigger r_die
	{
		remove
	}
}

slide_door_allied
{
	spawn
	{
		wait 150
		constructible_class 2
		constructible_constructxpbonus 12
		constructible_destructxpbonus 12
		setstate slide_door_crates default
		setstate slide_door_crates_clip default
		setstate slide_door_flag default
		setstate slide_door_dyno_allied default
	}

	built final
	{
		setstate slide_door_crates invisible
		setstate slide_door_crates_clip invisible
		setstate slide_door_flag invisible
		setstate slide_door_dyno invisible
	}

	decayed final
	{
		setstate slide_door_crates default
		setstate slide_door_crates_clip default
		setstate slide_door_flag default
		setstate slide_door_dyno_allied default
	}

	death
	{
		wm_announce "The door to the slide has been destroyed!"
		setstate slide_door_crates default
		setstate slide_door_crates_clip default
		setstate slide_door_flag default
		setstate slide_door_dyno_allied default
	}

	trigger r_die
	{
		trigger slide_door_dyno_allied r_die
		remove
	}
}

slide_door_dyno_allied
{
	spawn
	{
		wait 150
	}

	trigger r_die
	{
		remove
	}
}

// Slide door STOP

// CP crap C&P FTW.

cp_door
{
	spawn
	{
		wait 250
		trigger self up
	}

	trigger up
	{
		gotomarker cp_door_up 50 wait
	}
	
	trigger mv_down_e
	{
		trigger self mv_down
	}

	trigger mv_down
	{
		gotomarker cp_door_down 50 wait
	}
}

cp_ceiling
{
	spawn
	{
		wait 250
		trigger self up
	}
	
	trigger mv_down
	{
		gotomarker cp_mid 70 wait
	}

	trigger mv_down_e
	{
		trigger self mv_down
	}
	
	trigger up
	{
		gotomarker cp_top 70 wait
	}
}

cp_spikes
{
	spawn
	{
		wait 250
		trigger self up
	}
	
	trigger mv_down
	{
		gotomarker cp_mid 500 wait
	}

	trigger up
	{
		gotomarker cp_top 500 wait
	}

	trigger mv_down_e
	{
		trigger self mv_down
	}

	trigger extend
	{
		gotomarker cp_bot 50 wait
	}

	trigger retract
	{
		gotomarker cp_mid 50 wait
	}
}

cp_door_trip
{
	spawn
	{
		wait 250
		accum 1 set 0
	}
	
	trigger
	{
		accum 1 abort_if_equal 1
		accum 1 set 1

		// crush
		trigger cp_door mv_down
		wait 2000
		trigger cp_ceiling mv_down
		wait 7500
		trigger cp_spikes mv_down
		wait 4000

		// let's kill them!
		alertentity cp_hurt
		trigger cp_spikes extend
		wait 4000
		trigger cp_spikes retract
		wait 3000
		alertentity cp_hurt

		// clean up
		trigger cp_spikes up
		trigger cp_ceiling up
		wait 3000
		trigger cp_door up

		accum 1 set 0
	}
}

// ================================================
neutral_cp_toi
{
	spawn
	{
		wait 250
		accum 1 set 0
	}
	
	trigger show_neutral_cabinet			// Show Neutral Closed CP
	{
		setstate neutral_cp_closed default
		setstate neutral_cp_closed_model default
	}

	trigger hide_neutral_cabinet			// Hide Neutral Closed CP
	{
		setstate neutral_cp_closed invisible
		setstate neutral_cp_closed_model invisible
	}

}

// ================================================
allied_cp_open
{
	spawn
	{
		wait 100
		constructible_class 2			// Dyno+Satchel

		trigger self disable_cp_features		// Default charge bar times
	}

	trigger disable_cp_features
	{
		setstate allied_cp_open_model invisible	// Hide Open CP model

		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1

		sethqstatus 1 0			// Landmines team warning message
		disablespeaker allied_cp_sound		// Disable morse code sound
	}

	trigger enable_cp_features
	{
		setstate allied_cp_open_model default	// Show open CP model

		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			// Landmines team warning message
		enablespeaker allied_cp_sound		// Enable morse code sound
	}

	buildstart final
	{
		trigger neutral_cp_toi hide_neutral_cabinet	// Hide Neutral CP model+clip brush
	}

	built final
	{
		trigger self enable_cp_features		// Increase charge bar times

		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"
		// *----------------------------------- vo ------------------------------------------*
	}

	decayed final
	{
		setstate allied_cp_open_model invisible	// Hide Open CP model
		trigger neutral_cp_toi show_neutral_cabinet	// Show Neutral CP model+clip brush
	}

	death
	{
		trigger neutral_cp_toi show_neutral_cabinet	// Show Neutral CP model+clip brush
		trigger self disable_cp_features		// Default charge bar times

		wm_announce "Axis team has destroyed the Allied Command Post!"
		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"
		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"
		wm_teamvoiceannounce 0 "axis_hq_compost_construct"
		wm_teamvoiceannounce 1 "allies_hq_compost_damaged"
		// *----------------------------------- vo ------------------------------------------*
	}
}

// ================================================
axis_cp_open
{
	spawn
	{
		wait 100
		constructible_class 2			// Dyno+Satchel

		trigger self disable_cp_features		// Default charge bar times
	}

	trigger disable_cp_features
	{
		setstate axis_cp_open_model invisible	// Hide Open CP model

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

		sethqstatus 0 0			// Landmines team warning message
		disablespeaker axis_cp_sound		// Disable morse code sound
	}

	trigger enable_cp_features
	{
		setstate axis_cp_open_model default	// Show open CP model

		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			// Landmines team warning message
		enablespeaker axis_cp_sound		// Enable morse code sound
	}

	buildstart final
	{
		trigger neutral_cp_toi hide_neutral_cabinet	// Hide Neutral CP model+clip brush
	}

	built final
	{
		trigger self enable_cp_features		// Increase charge bar times

		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 ------------------------------------------*
	}

	decayed final
	{
		setstate axis_cp_open_model invisible	// Hide Open CP model
		trigger neutral_cp_toi show_neutral_cabinet	// Show Neutral CP model+clip brush
	}

	death
	{
		trigger neutral_cp_toi show_neutral_cabinet	// Show Neutral CP model+clip brush
		trigger self disable_cp_features		// Default charge bar times

		wm_announce "Allied team has destroyed the Axis Command Post!"
		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"
		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"
		wm_teamvoiceannounce 0 "axis_hq_compost_damaged"
		wm_teamvoiceannounce 1 "allies_hq_compost_construct"
		// *----------------------------------- vo ------------------------------------------*
	}
}
