game_manager
{

    spawn
    {
     
	wm_allied_respawntime 15
        wm_axis_respawntime 15
	wm_set_round_timelimit 30   
     	wm_number_of_objectives 7
	
	wait 500
	
	accum 1 set 0
	accum 2 set 0

	setstate forward_wobj invisible

	setautospawn "forward flag" 	0
	setautospawn "forward flag" 	1

	wait 2000
	// *----------------------------------- vo ------------------------------------------*
		
		wm_teamvoiceannounce 0 "sod2_axis_tank_steal"
		wm_teamvoiceannounce 0 "axis_hq_compost_construct"
		wm_teamvoiceannounce 0 "sod2_axis_city_capture"           		
		wm_teamvoiceannounce 1 "allies_hq_compost_construct" 
		wm_teamvoiceannounce 1 "sod2_allies_city_capture"
		wm_teamvoiceannounce 1 "sod2_allies_tankbar_construct"
				
		wm_addteamvoiceannounce 0 "sod2_axis_tank_steal"
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"
		wm_addteamvoiceannounce 0 "sod2_axis_city_capture"
		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"
		wm_addteamvoiceannounce 1 "sod2_allies_city_capture"
		wm_addteamvoiceannounce 1 "sod2_allies_tankbar_construct"
		              
	// *---------------------------------------------------------------------------------*


	// Objectives
	// 1: Repair the tank!
	// 2: Construct the command post!
	// 3: Blowup the bankdoor!
	// 4: Steal Duke's knife The Spear of Destiny!
	// 5: Secure the Spear of Destiny!
	// 6: Construct the Tank barrier!
	// 7: Take control of the city!

	//wm_set_main_objective 1	0
	//wm_set_main_objective 1	1

	wm_objective_status 1 0 0
	wm_objective_status 2 0 0
	wm_objective_status 3 0 0
	wm_objective_status 4 0 0
	wm_objective_status 5 0 0
	wm_objective_status 6 1 0
	wm_objective_status 7 0 0
	
	// Stopwatch mode defending team (0=Axis, 1=Allies)
	wm_set_defending_team 1

	//Winner on expirtion of round time (o=axis, 1=allies)
	wm_setwinner 1
	}
	
	trigger axis_win
	{
		wm_setwinner 0
		wm_announce "The Axis forces have secured the Spear of Destiny!"
		wm_objective_status 5 0 2
		wm_objective_status 5 0 1
		
		wait 1500
		wm_endround
	}
	
    trigger endgame
    {
        wait 1500        
        wm_endround        
    }
}


//FLAG STUFF
// *********************************************
goldbar_holder
{
	death
	{
	trigger gold_trans_1 hide
	trigger gold_full_1 show
	wait 1500

	wm_setwinner 0
	wm_announce "The Axis forces have secured the Spear of Destiny!"
	// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "sod2_axis_end"
                wm_teamvoiceannounce 1 "sod2_allies_end"

		wm_addteamvoiceannounce 0 "sod2_axis_end"
		wm_addteamvoiceannounce 1 "sod2_allies_end"
	// *----------------------------------- vo ------------------------------------------*	
	
	wm_objective_status 5 0 2

	wait 1500
	wm_endround
	}
}

//GOLD STUFF
//*********************************************
gold_crate1
{
	spawn
	{

}

	trigger stolen
	{
	wm_announce "Axis team have stolen the Spear of Destiny!"

	}

	trigger secured
	{
	wm_announce "Axis team has secured the Spear of Destiny!"

	//u can add sounds here

	}

	trigger returned
	{

	wm_announce "Allied team has returned the Spear of Destiny!"
	}
}

gold_trans_1
{
	spawn
	{
	wait 500

	}

	trigger hide // should be triggered when u secure the obj
	{
	setstate gold_trans_1 invisible //cannot see it now
	}
}

gold_full_1
{
	spawn
	{
	wait 500

	setstate gold_full_1 invisible
	}

	trigger show
	{
	setstate gold_full_1 default
	}
}


//bankwall stuff
// =================================================
axis_destructible
{
	spawn
	{
		wait 300
		constructible_class 3 // 2=satchel  3=dyna
	}

	death
	{
		wm_announce "The Axis have destroyed the bank side wall!"
	// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "sod2_axis_wall_breached"
                wm_teamvoiceannounce 1 "sod2_allies_wall_breached"

		wm_addteamvoiceannounce 0 "sod2_axis_wall_breached"
		wm_addteamvoiceannounce 1 "sod2_allies_wall_breached"
	// *----------------------------------- vo ------------------------------------------*
		alertentity axis_destructible_bits
		trigger axis_destructible_toi remove
	}
}

axis_destructible_toi
{
	trigger remove
	{
		remove
	}
}


//forward spawn stuff
// =================================================
forward_flag   
{ 
	spawn 
	{

	accum 0 set 0 // Who owns flag: 0-Axis, 1-Allied, 2-Nobody

	}

	trigger axis_capture // Touched by an Axis player

	{

	accum 0 abort_if_equal 0 // do Axis own flag?

	accum 0 trigger_if_equal 1 forward_flag axis_reclaim // Reclaimed from Allies

	accum 0 set 0 // Axis own the flag

	wm_announce "Axis have captured the Forward Flag!"
	
	// *----------------------------------- vo ------------------------------------------*
		wm_removeteamvoiceannounce 0 "sod2_axis_capture_city"
		wm_teamvoiceannounce 0 "sod2_axis_captured_city"

		wm_addteamvoiceannounce 1 "sod2_allies_capture_city"
		wm_teamvoiceannounce 1 "sod2_allies_axis_capture_city"
	// *---------------------------------------------------------------------------------*
	
	
	setstate forward_wobj default

	}

	trigger axis_reclaim

	{

	alertentity forward_wobj // Switch command map marker

	}

	trigger allied_capture // Touched by an allied player

	{

	accum 0 abort_if_equal 1 // do Allies own flag?

	accum 0 set 1 // Allied own the flag

	wm_announce "Allies have captured the Forward Flag!"

	// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "sod2_axis_capture_city"
		wm_teamvoiceannounce 0 "sod2_axis_capture_city"

		wm_removeteamvoiceannounce 1 "sod2_allies_capture_city"
		wm_teamvoiceannounce 1 "sod2_allies_captured_city"
	// *---------------------------------------------------------------------------------*
	
	setstate forward_wobj default

	alertentity forward_wobj // Switch command map marker

	} 
  
} 


//CP stuff
// ================================================
neutral_cp_toi
{
	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 speaker_allied_cp		// 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 speaker_allied_cp		// 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 speaker_axis_cp		// 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 speaker_axis_cp		// 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 ------------------------------------------*
	}
}

//barrier stuff
// ================================================
barrier1
{
	spawn
	{
		wait 400
		trigger barrier1 setup

		constructible_class 3
	}

	trigger setup
	{
		setstate barrier1_materials default
		setstate barrier1_materials_clip default
		setstate barrier1_flag default

		globalaccum 0 bitreset 0

	}

	built final
	{
		setstate barrier1_materials invisible
		setstate barrier1_materials_clip invisible
		setstate barrier1_flag invisible

		wm_announce "The Tank Barrier has been constructed."
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "sod2_axis_tankbar_constructed"
		wm_teamvoiceannounce 1 "sod2_allies_tankbar_constructed"

		wm_removeteamvoiceannounce 0 "sod2_allies_tankbar_construct"
		wm_removeteamvoiceannounce 1 "sod2_axis_tankbar_construct"
                // *---------------------------------------------------------------------------------*
		

		globalaccum 0 bitset 0

		}

	decayed final
	{
		setstate barrier1_materials default
		setstate barrier1_materials_clip default
		setstate barrier1_flag default
	}

	death
	{
		trigger self setup

		wm_announce "The Tank Barrier has been destroyed."
		// *----------------------------------- vo ------------------------------------------*
                wm_addteamvoiceannounce 0 "sod2_allies_tankbar_construct"

		wm_teamvoiceannounce 0 "sod2_axis_tankbar_destroyed"

		wm_teamvoiceannounce 1 "sod2_allies_tankbar_destroyed"
		// *---------------------------------------------------------------------------------*
		
	}

	trigger remove
	{
		setstate barrier1_toi invisible
		setstate barrier1_materials invisible
		setstate barrier1_materials_clip invisible
		setstate barrier1_flag invisible

		wm_removeteamvoiceannounce 0 "sod2_axis_tankbar_destroyed"
		wm_removeteamvoiceannounce 1 "sod2_allies_tankbar_construct"

		remove
	}
}

//tank stuff
// ================================================
tank
{
// accum 0, track state
// accum 1
//  - bit 0: barrier1 state		( 0 = not built,	1 = built		)
//  - bit 1: barrier2 state		( 0 = not built,	1 = built		)
//  - bit 2: spline status 		( 0 = not moving, 	1 = moving 		)
//  - bit 3: stuck check flag 	( 0 = not stuck, 	1 = stuck 		)
//  - bit 4: flag for message	( 0 = dont display, 1= display		)
//  - bit 5: blank
//  - bit 6: temp register 		(XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)
//  - bit 7: death status 		( 0 = alive, 		1 = dead		)
//  - bit 8: player check 		( 0 = players, 		1 = no players	)
//  - bit 9: visible state		( 0 = alive, 		1 = dead		)
// accum 2, blank
// accum 3, current movement loop position
// accum 4, stop counter
// accum 5, lockout ref counter
// accum 6, blank
// accum 7, blank
	spawn
	{
		wait 400
		followspline 1 spln0 50000 length 32 wait
		followspline 1 spln0 50000 length 32 wait

		trigger tank sound_idle
		trigger tank tracks_stop
	}

	death
	{
		accum 1 bitset 7
	}

	rebirth
	{
		accum 1 bitreset 9 // we're visibly alive
		accum 1 bitreset 7 // we're alive again

		trigger self script_lockout

		changemodel models/mapobjects/tanks_sd/jagdpanther_africa_tracks.md3

		setstate tank_smoke invisible

		// *----------------------------------- vo ------------------------------------------*
		
                wm_teamvoiceannounce 0 "sod2_axis_tank_repaired"

		wm_teamvoiceannounce 1 "sod2_allies_tank_repaired"
		
		// *---------------------------------------------------------------------------------*


		trigger tank_sound rebirth
		wait 500

		trigger self script_lockout_stop
	}

	trigger barrier_built
	{
		accum 1 bitset 1
	}

	trigger barrier_destroyed
	{
		accum 1 bitreset 1
	}

	trigger deathcheck
	{
		accum 1 abort_if_not_bitset 7	// abort if tank not damaged
		accum 1 abort_if_bitset 9	// abort if tank already visibly dead
		accum 1 abort_if_bitset 2	// abort if we are following a spline
		accum 5 abort_if_not_equal 0	// abort if we are in a script lockout

		accum 1 bitset 9				// we're now visibly dead

		trigger self deathcheck_message
		accum 1 bitset 4

		changemodel models/mapobjects/tanks_sd/jagdpanther_africa_tracks2.md3

		setstate tank_smoke default

		kill tank_construct

		trigger self sound_death
		trigger self tracks_stop

		trigger self script_lockout

		trigger self tracks_stop
		startanimation 45 10 15 nolerp norandom
		wait 666
		startanimation 0 1 15 nolerp norandom

		trigger self script_lockout_stop

		resetscript
	}

	trigger deathcheck_message
	{
		accum 1 abort_if_not_bitset 4

		wm_announce "The tank has been damaged!"

		// *----------------------------------- vo ------------------------------------------*
		
		wm_teamvoiceannounce 0 "sod2_axis_tank_damaged"

		wm_teamvoiceannounce 1 "sod2_allies_tank_damaged"
		
		// *--------------------------------------------------------------------------------*
		
	}

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

	trigger dispatch
	{
		accum 3 trigger_if_equal 0 tank run_0
		accum 3 trigger_if_equal 1 tank run_1
		accum 3 trigger_if_equal 2 tank run_2
		accum 3 trigger_if_equal 3 tank run_3
		accum 3 trigger_if_equal 4 tank run_4
		accum 3 trigger_if_equal 5 tank run_5
		accum 3 trigger_if_equal 6 tank run_6
		accum 3 trigger_if_equal 7 tank run_7
		accum 3 trigger_if_equal 8 tank run_8
		accum 3 trigger_if_equal 9 tank run_9
		accum 3 trigger_if_equal 10 tank run_10
		accum 3 trigger_if_equal 11 tank run_11
		accum 3 trigger_if_equal 12 tank run_12
		accum 3 trigger_if_equal 13 tank run_13
		accum 3 trigger_if_equal 14 tank run_14
		accum 3 trigger_if_equal 15 tank run_15
		accum 3 trigger_if_equal 16 tank run_16
		accum 3 trigger_if_equal 17 tank run_17
		accum 3 trigger_if_equal 18 tank run_18
		accum 3 trigger_if_equal 19 tank run_19
		accum 3 trigger_if_equal 20 tank run_20
		accum 3 trigger_if_equal 21 tank run_21
						
	}

	trigger move
	{
		trigger self move_check
		wait 500
		trigger self move
	}

	trigger move_check
	{
		trigger self stuck_check
		accum 1 abort_if_bitset 3

		trigger self dispatch
	}

	trigger run_continue
	{
		accum 3 inc 1

		trigger self deathcheck
		trigger self stopcheck
		trigger self move
	}

	trigger run_0
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln0 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_1
	{
		trigger self tracks_forward

		//wm_objective_status 1 0 1
		//wm_objective_status 1 1 2
		//wm_set_main_objective		2	0
		//wm_set_main_objective		2	1
		wm_announce	"Axis have stolen the tank!!!"		

		accum 1 bitset 2
		followspline 0 spln1 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_2
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln2 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_3
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln3 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_4
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln4 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_5
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln5 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_6
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln6 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_7
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln7 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_8
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln8 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}
	
	trigger run_9
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln9 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_10
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln10 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_11
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln11 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_12
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln12 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_13
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln13 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_14
	{
		trigger self tracks_forward
		accum 1 bitset 2

	//	=======================
		trigger barrier1 remove
	//	=======================

		followspline 0 spln14 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_15
	{
		trigger self tracks_forward
		accum 1 bitset 2

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "sod2_axis_tankbar_past"

		wm_teamvoiceannounce 1 "sod2_allies_tankbar_past"
                wm_removeteamvoiceannounce 1 "sod2_allies_tankbar_construct"
		// *---------------------------------------------------------------------------------*

		followspline 0 spln15 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_16
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln16 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}
	
	trigger run_17
	{
		trigger self tracks_forward
		accum 1 bitset 2

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "sod2_axis_tank_bridge"

		wm_teamvoiceannounce 1 "sod2_allies_tank_bridge"
		// *---------------------------------------------------------------------------------*

		followspline 0 spln17 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_18
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln18 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_19
	{
		trigger self tracks_forward
		accum 1 bitset 2
		wm_announce	"^6Warning: ^3Enemy Tank approching the bank"
		followspline 0 spln19 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_20
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln20 32 wait
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_21
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln21 32 wait
		accum 1 bitreset 2
		
		trigger self script_lockout

		accum 3 inc 1

		trigger tank_sound stop
		trigger self tracks_stop		
		startanimation 5 10 15 nolerp norandom	// stopping
		wait 666
		startanimation 0 1 15 nolerp norandom	// stopped

		wait 900

		trigger tank_turret turn
	}

	// =========================
	// script lockouts

	trigger script_lockout
	{
		accum 5 inc 1
	}

	trigger script_lockout_stop
	{
		accum 5 inc -1
	}

	trigger sound_idle
	{
		stopsound
		playsound sound/vehicles/tank/tank_idle.wav looping volume 512
	}

	trigger sound_start
	{
		stopsound
		playsound sound/vehicles/tank/tank_revup.wav volume 196
	}

	trigger sound_move
	{
		stopsound
		playsound sound/vehicles/tank/tank_move.wav looping volume 512
	}

	trigger sound_stop
	{
		stopsound
		playsound sound/vehicles/tank/tank_revdown.wav volume 196
	}

	trigger sound_death
	{
		stopsound
		playsound sound/vehicles/tank/tank_stop.wav volume 256
	}

	trigger sound_rebirth
	{
		stopsound
		playsound sound/vehicles/tank/tank_start.wav volume 196
	}

	// ================================
	// stop check
	trigger stopcheck
	{
		trigger self stopcheck_setup
		accum 1 abort_if_not_bitset 6

		trigger self script_lockout

		trigger tank_sound 	stop
		trigger self 		tracks_stop
		startanimation 45 	10 	15 nolerp norandom
		wait 666
		startanimation 0 	1 	15 nolerp norandom
		wait 900

		trigger self script_lockout_stop
		resetscript
	}

	trigger stopcheck_setup
	{
		accum 1 bitset 6				// stop if we're stuck/no-one's pushing :)

		accum 1 abort_if_bitset 8		// no one in the trigger, abort

		trigger self stuck_check		// call the stop check function
		accum 1 abort_if_bitset 3		// we're stuck so break out

		accum 1 bitreset 6			// we're free to move
	}

	// ======================================
	// stuck checking

	trigger stuck_check
	{
		accum 1 bitreset 3

		trigger self stuck_check_barrier
		trigger self stuck_check_scriptlockout
		trigger self stuck_check_finished
	}

	trigger stuck_check_finished
	{
	//	The check should be the final spln nbr + 1
		accum 3 abort_if_less_than 22
		accum 1 bitset 3
	}

	trigger stuck_check_scriptlockout
	{
		accum 5 abort_if_equal 0
		accum 1 bitset 3
	}

	trigger stuck_check_barrier
	{
		accum 3 abort_if_not_equal 14
		globalaccum 0 abort_if_not_bitset 0	// abort if barrier not built
		accum 1 bitset 3
	}

	trigger tank_disable
	{
		accum 4 inc 1				// up the stop counter
		accum 4 abort_if_less_than 4

		accum 1 bitset 8				// set stop check

		trigger self deathcheck
	}

	trigger tank_enable
	{
		trigger self stuck_check
		accum 1 abort_if_bitset 3 	// stuck check

		accum 4 set 0			// reset stop counter
		accum 1 bitreset 8		// reset stop check

		accum 1 abort_if_bitset 2 	// already following spline
		accum 5 abort_if_not_equal 0	// are we not in a script lockout?

		accum 1 abort_if_bitset 7 	// death check

		trigger self script_lockout

		trigger tank_sound start

		startanimation 55 10 15 nolerp norandom
		wait 666
		startanimation 5 40 15 nolerp norandom
		wait 500
		trigger self tracks_forward

		trigger self script_lockout_stop

		trigger self move
	}

	trigger tracks_forward
	{
		accum 0 abort_if_equal 1
		accum 0 set 1

		remapshader models/mapobjects/tanks_sd/jag_tracks_left 	models/mapobjects/tanks_sd/jag_tracks_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_tracks_right models/mapobjects/tanks_sd/jag_tracks_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_wheels_left 	models/mapobjects/tanks_sd/jag_wheels_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_wheels_right models/mapobjects/tanks_sd/jag_wheels_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_cogs_left 	models/mapobjects/tanks_sd/jag_cogs_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_cogs_right 	models/mapobjects/tanks_sd/jag_cogs_alt_forward

		remapshaderflush
	}

	trigger tracks_stop
	{
		accum 0 abort_if_equal 0
		accum 0 set 0

		remapshader models/mapobjects/tanks_sd/jag_tracks_left 	models/mapobjects/tanks_sd/jag_tracks_left
		remapshader models/mapobjects/tanks_sd/jag_tracks_right models/mapobjects/tanks_sd/jag_tracks_right
		remapshader models/mapobjects/tanks_sd/jag_wheels_left 	models/mapobjects/tanks_sd/jag_wheels_left
		remapshader models/mapobjects/tanks_sd/jag_wheels_right models/mapobjects/tanks_sd/jag_wheels_right
		remapshader models/mapobjects/tanks_sd/jag_cogs_left 	models/mapobjects/tanks_sd/jag_cogs_left
		remapshader models/mapobjects/tanks_sd/jag_cogs_right 	models/mapobjects/tanks_sd/jag_cogs_right

		remapshaderflush
	}

	trigger tracks_turn_left
	{
		accum 0 abort_if_equal 2
		accum 0 set 2

		remapshader models/mapobjects/tanks_sd/jag_tracks_left 	models/mapobjects/tanks_sd/jag_tracks_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_tracks_right models/mapobjects/tanks_sd/jag_tracks_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_wheels_left 	models/mapobjects/tanks_sd/jag_wheels_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_wheels_right models/mapobjects/tanks_sd/jag_wheels_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_cogs_left 	models/mapobjects/tanks_sd/jag_cogs_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_cogs_right 	models/mapobjects/tanks_sd/jag_cogs_alt_forward

		remapshaderflush
	}

	trigger tracks_turn_right
	{
		accum 0 abort_if_equal 3
		accum 0 set 3

		remapshader models/mapobjects/tanks_sd/jag_tracks_left 	models/mapobjects/tanks_sd/jag_tracks_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_tracks_right models/mapobjects/tanks_sd/jag_tracks_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_wheels_left 	models/mapobjects/tanks_sd/jag_wheels_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_wheels_right models/mapobjects/tanks_sd/jag_wheels_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_cogs_left 	models/mapobjects/tanks_sd/jag_cogs_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_cogs_right 	models/mapobjects/tanks_sd/jag_cogs_alt_backward

		remapshaderflush
	}

	trigger startfire
	{
		startanimation 67 8 10 nolerp norandom noloop
	}

	trigger stopfire
	{
		startanimation 0 1 15 nolerp norandom
	}
}

tank_build
{
	spawn
	{
		wait 500
		attachtotag tank_shell tag_turret
	}
}

tank_construct
{
	spawn
	{
		wait 1000

		kill tank

		constructible_class 2
		constructible_health 1200
		constructible_constructxpbonus 10
		constructible_destructxpbonus 10
	}

	built final
	{
		alertentity tank
		wm_announce "The tank has been repaired!"
	}
}

tank_disabler
{
	trigger run
	{
		trigger tank tank_disable
	}
}

tank_enabler
{
	trigger run
	{
		trigger tank tank_enable
	}
}

tank_fire_sound
{
	trigger run
	{
		setposition tank
		alertentity tank_fire_sound
	}
}

tank_gunsmoke
{
	spawn
	{
		wait 300
 		attachtotag tank_turret tag_flash
		setstate tank_gunsmoke invisible
	}
}

tank_shell
{
	spawn
	{
		wait 400
		attachtotag tank tag_tank
	}
}

tank_smoke
{
	spawn
	{
		wait 300
		attachtotag tank_shell tag_smoke
		setstate tank_smoke invisible
	}
}

tank_sound
{
	trigger start
	{
		trigger tank sound_start
		wait 3400
		trigger tank sound_move
	}

	trigger stop
	{
		trigger tank sound_stop
		wait 1400
		trigger tank sound_idle
	}

	trigger rebirth
	{
		trigger tank sound_rebirth
		wait 1400
		trigger tank sound_idle
	}
}

tank_trigger
{
	spawn
	{
		wait 500
		attachtotag tank_shell tag_turret
	}
}

tank_turret
{
	spawn
	{
		wait 500

		attachtotag tank_shell tag_turret
	}

	trigger turn
	{
		wait 1000

		playsound sound/vehicles/tank/turret_spin.wav looping
		faceangles 0 -340 0 3000
		stopsound
		playsound sound/vehicles/tank/turret_end.wav

		wait 500

		trigger tank startfire
		playsound sound/vehicles/tank/tank_fire.wav
		trigger boomtrigger boom_all		// triggers the hurts around bank explosions (each has its own wait for timing)
		trigger tank_flash run
	}

	trigger blow_doors
	{
		setstate tank_flash invisible

		wait 200
		trigger tank stopfire

		alertentity bank_door1
		setstate doorframe invisible
		setstate doorframe_damaged default

		wm_announce "Axis team has destroyed the Bank Doors!"
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "sod2_axis_attack"
                wm_teamvoiceannounce 1 "sod2_allies_fallback"

		wm_addteamvoiceannounce 0 "sod2_axis_attack"
		wm_addteamvoiceannounce 1 "sod2_allies_fallback"
		// *----------------------------------- vo ------------------------------------------*	

		//wm_objective_status 3 0 2
		//wm_objective_status 3 1 1

		//wm_set_main_objective		4	0
		//wm_set_main_objective		4	1

		wait 100
		
		playsound sound/vehicles/tank/turret_spin.wav looping
		faceangles 0 0 0 3000
		stopsound
		playsound sound/vehicles/tank/turret_end.wav
		trigger tank sound_death
		trigger tank script_lockout_stop
	}
}

tank_flash
{
	spawn
	{
		setstate tank_flash invisible
	}

	trigger run
	{
		setstate tank_flash default
 		attachtotag tank_turret tag_flash
		faceangles 0 90 0 50

		wait 50

		trigger tank_turret blow_doors
	}
}

// *******************************
//BANK EXPLOSION
doorframe
{
	spawn
	{
		setstate doorframe_damaged invisible
	}
}


// these cause timed damage from the tank barrel to the bank explosion
boomtrigger
{
	trigger boom_all		// this is called from the tank to trigger all hurts
	{
		trigger hurt_barrelblast1 boom
		trigger hurt_barrelblast2 boom
		trigger hurt_barrelblast3 boom
		trigger hurt_bankblast boom
		wait 450
		setstate bankdoors_toi invisible
		setstate bankdoors_cm_marker invisible
	}
}


hurt_barrelblast1
{
	spawn
	{
		wait 200
		setstate hurt_barrelblast1 invisible
	}

	trigger boom
	{
		setstate hurt_barrelblast1 default
		wait 100
		remove
	}
}

hurt_barrelblast2
{
	spawn
	{
		wait 200
		setstate hurt_barrelblast2 invisible
	}

	trigger boom
	{
		wait 165
		setstate hurt_barrelblast2 default
		wait 100
		remove
	}
}

hurt_barrelblast3
{
	spawn
	{
		wait 200
		setstate hurt_barrelblast3 invisible
	}

	trigger boom
	{
		wait 325
		setstate hurt_barrelblast3 default
		wait 100
		remove
	}
}

hurt_bankblast
{
	spawn
	{
		wait 200
		setstate hurt_bankblast invisible

		setstate hurt_barrelblast2 invisible
		setstate hurt_barrelblast3 invisible
	}

	trigger boom
	{
		wait 400
		setstate hurt_bankblast default
		wait 100
		remove
	}
}

//door stuff
// *******************************

door_control
{

    spawn
    {
        accum 1 set 1 //set accum 1 to 1 so it's initial state is closed.
        wait 200 //wait for things to spawn.
    }

    trigger toggle
    {
        accum 1 abort_if_equal 2 //abort this function if accum is 2. Moving = 2.
        trigger door_control open //trigger the open function of the routine.
        wait 50 
        trigger door_control close //trigger the close function of the routine.
    }

    trigger open
    {
        accum 1 abort_if_not_equal 1 //abort this function if accum is not 1. Closed = 1.
        accum 1 set 2 //set accum 1 to 2. Moving = 2.
        trigger door_1 open //trigger door_1 open so the door will move.
        wait 14000 //wait 4 seconds so door finishes it's path.
        accum 1 set 0 //set accum 1 to 0. Open = 0.
    }

    trigger close 
    { 
        accum 1 abort_if_not_equal 0 //abort this function if accum is not 0. Open = 0.
        accum 1 set 2 //set accum 1 to 2. Moving = 2.
        trigger door_1 close //trigger door_1 close so the door will move.
        wait 14000 //wait 4 seconds so door finishes it's path
        accum 1 set 1 //set accum 1 to 1. Closed = 1. 
    } 
}

door_1
{
        spawn
        {
        wait 200
        }

        trigger open
        {
        gotomarker door_1_open 8 wait
        }

        trigger close
        {
        gotomarker door_1_close 8 wait
        }
}

door_control_2
{

    spawn
    {
        accum 1 set 1 //set accum 1 to 1 so it's initial state is closed.
        wait 200 //wait for things to spawn.
    }

    trigger toggle
    {
        accum 1 abort_if_equal 2 //abort this function if accum is 2. Moving = 2.
        trigger door_control_2 open //trigger the open function of the routine.
        wait 50 
        trigger door_control_2 close //trigger the close function of the routine.
    }

    trigger open
    {
        accum 1 abort_if_not_equal 1 //abort this function if accum is not 1. Closed = 1.
        accum 1 set 2 //set accum 1 to 2. Moving = 2.
        trigger door_2 open //trigger door_2 open so the door will move.
        wait 14000 //wait 4 seconds so door finishes it's path.
        accum 1 set 0 //set accum 1 to 0. Open = 0.
    }

    trigger close 
    { 
        accum 1 abort_if_not_equal 0 //abort this function if accum is not 0. Open = 0.
        accum 1 set 2 //set accum 1 to 2. Moving = 2.
        trigger door_2 close //trigger door_2 close so the door will move.
        wait 14000 //wait 4 seconds so door finishes it's path
        accum 1 set 1 //set accum 1 to 1. Closed = 1. 
    } 
}

door_2
{
        spawn
        {
        wait 200
        }

        trigger open
        {
        gotomarker door_2_open 8 wait
        }

        trigger close
        {
        gotomarker door_2_close 8 wait
        }
}

door_control_3
{

    spawn
    {
        accum 1 set 1 //set accum 1 to 1 so it's initial state is closed.
        wait 200 //wait for things to spawn.
    }

    trigger toggle
    {
        accum 1 abort_if_equal 2 //abort this function if accum is 2. Moving = 2.
        trigger door_control_3 open //trigger the open function of the routine.
        wait 50 
        trigger door_control_3 close //trigger the close function of the routine.
    }

    trigger open
    {
        accum 1 abort_if_not_equal 1 //abort this function if accum is not 1. Closed = 1.
        accum 1 set 2 //set accum 1 to 2. Moving = 2.
        trigger door_3 open //trigger door_2 open so the door will move.
        wait 14000 //wait 4 seconds so door finishes it's path.
        accum 1 set 0 //set accum 1 to 0. Open = 0.
    }

    trigger close 
    { 
        accum 1 abort_if_not_equal 0 //abort this function if accum is not 0. Open = 0.
        accum 1 set 2 //set accum 1 to 2. Moving = 2.
        trigger door_3 close //trigger door_3 close so the door will move.
        wait 14000 //wait 4 seconds so door finishes it's path
        accum 1 set 1 //set accum 1 to 1. Closed = 1. 
    } 
}

door_3
{
        spawn
        {
        wait 200
        }

        trigger open
        {
        gotomarker door_3_open 8 wait
        }

        trigger close
        {
        gotomarker door_3_close 8 wait
        }
}