//
// The following consists of small parts of script written by me, Charming_Fox (A noob to ET Mapping), and many bits of copied
// code from other folks hard work, to those people i am eternally endebted. Thank you.

game_manager
{
	spawn 
   	{
		remapshaderflush
		
		// Game rules
		wm_axis_respawntime	20
		wm_allied_respawntime	15
		wm_number_of_objectives	4
		wm_set_round_timelimit	20

		// Objectives
		//1 Blow up TANK1
		//2 Blow up TANK2
		//3 Hold Forward Spawn
		//4 Build Command Post

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


		//Accum values
		accum 1 set 0 //Overall Allied status
		accum 2 set 2 //set 2 = null value

		// Stopwatch mode defending team (0=Axis, 1=Allies)
		wm_set_defending_team	0

		// Winner on expiration of round timer (0=Axis, 1=Allies, -1=no winner at expiration)
		wm_setwinner	0 //Assumes allies defending

		wait 2000

		setautospawn	"Old City"	1 //Uses name from description field of team_WOLF_objective
		setautospawn	"Old City"	0

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 1 "battery_allies_ramp_construct"
		wm_teamvoiceannounce 1 "allies_hq_compost_construct"

		wm_teamvoiceannounce 0 "battery_axis_ramp_stop"
		wm_teamvoiceannounce 0 "axis_hq_compost_construct"

		wm_addteamvoiceannounce 1 "battery_allies_ramp_construct"
		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"

		wm_teamvoiceannounce 0 "oasis_axis_city_defend"
		wm_addteamvoiceannounce 0 "oasis_axis_city_defend"

		wm_teamvoiceannounce 1 "oasis_allies_city_capture"
		wm_addteamvoiceannounce 1 "oasis_allies_city_capture"

		wm_addteamvoiceannounce 0 "battery_axis_ramp_stop"
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

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

   	}

	
//Objective Flags

	trigger objectivecounter  //Destruction of Allied Doors
           	 {
                        	//Set to objective accum to 1 so we know that the objective has been completed
                        	accum 1 inc 1

                        	//Call function called checkgame in game_manager to check if the round has been won
                        	trigger game_manager checkgame
           	}

	trigger checkgame // checks to see if win requirements have been met
            	{
                        	accum 1 abort_if_not_equal 2
                        	wm_setwinner 1
		wait 1500
                        	wm_endround
           	}


	trigger forwardflagblue
	{
		// Change the objective state internally, so UI can update, etc.
		// Allied takes control of forward flag

		// Some kind of UI pop-up to alert players
		wm_announce	"Allies capture the forward spawn!"

		wm_objective_status	3 1 1
		wm_objective_status	3 0 2

	}

	trigger forwardflagred
	{
		// Change the objective state internally, so UI can update, etc.
		// Axis takes control of forward flag

		// Some kind of UI pop-up to alert players
		wm_announce	"Axis capture the forward spawn!"


		wm_objective_status	3 1 2
		wm_objective_status	3 0 1

	}
} 

//End of Game_manager section

oldcityflag
{
	spawn
	{
		accum 0 set 0	// Who has the flag: 0-Axis, 1-Allied
	}

	trigger axis_capture	// Flag has been touched by an Axis player
	{
		accum 0 abort_if_equal 0 // do Axis own flag?

		accum 0 set 0 // Axis own the pole
		wm_announce	"Axis reclaim the Old City!"

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "oasis_axis_city_defend"

		wm_addteamvoiceannounce 1 "oasis_allies_city_capture"

		wm_teamvoiceannounce 0 "oasis_axis_city_captured"

		wm_teamvoiceannounce 1 "oasis_allies_city_lost"

		wm_removeteamvoiceannounce 0 "oasis_axis_wall_defend"

		wm_removeteamvoiceannounce 1 "oasis_allies_wall_destroy"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 		4 0 1
		wm_objective_status 		4 1 2

		alertentity old_city_wobj
	}

	trigger allied_capture	// Flag has been 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 capture the Old City!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "oasis_axis_city_lost"

		wm_teamvoiceannounce 1 "oasis_allies_city_captured"

		wm_removeteamvoiceannounce 0 "oasis_axis_city_defend"

		wm_removeteamvoiceannounce 1 "oasis_allies_city_capture"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 		4 0 2
		wm_objective_status 		4 1 1

		alertentity old_city_wobj
	}

	trigger check_obj
	{
		accum 0 abort_if_equal 1 // Do Allied own the flag?

		wm_objective_status 		4 0 2
		wm_objective_status 		4 1 1

	}

	trigger force_allied
	{
		accum 0 abort_if_equal 1 // Do Allied own the flag?

		alertentity old_city_wobj
		alertentity oldcityspawns
	}

	trigger kill
	{
		remove
	}
}

oldcitywall //Broken section of Old City wall
{
	spawn
	{
		wait 200

		constructible_class 3
	}

	death
	{
		trigger oldcityflag force_allied // Switch forward spawn to Allied ONLY

		trigger oldcityflag check_obj

		trigger oldcityflag kill

		wm_announce "Allies have breached the Hotel Doors and secured the Old City"

		wm_teamvoiceannounce 1 "charming_allies_east_tanks_destroy"
		wm_teamvoiceannounce 1 "charming_allies_west_tanks_destroy"

		wm_removeteamvoiceannounce 0 "oasis_axis_city_defend"
		wm_removeteamvoiceannounce 1 "oasis_allies_city_capture"

		wm_teamvoiceannounce 0 "charming_axis_east_tanks_defend"
		wm_teamvoiceannounce 0 "charming_axis_west_tanks_defend"

		wm_objective_status 		3 0 2
		wm_objective_status 		3 1 1

		wm_set_main_objective	1 0
		wm_set_main_objective	1 1
	}
}

// CONSTRUCTIBLE OBJECTIVES ================================================
//Axis constructible

	axisconstruct_script
	{ 
		spawn 
		{ 
			wait 200 
			constructible_class 2 
			trigger self startup 
		} 
	
		buildstart final 
		{ 
		} 

		built final 
		{ 
			setstate axisconstruct_target default 
			setstate axisconstruct_materials invisible 
			wm_announce "The Axis wall has been constructed" 
		} 

		decayed final 
		{ 
			trigger self startup 
		} 

		death 
		{ 
			trigger self startup 
			wm_announce "The Axis wall has been breached" 
			setstate axisconstruct_materials default
		} 

		trigger startup 
		{ 
			setstate axisconstruct_target invisible
			setstate axisconstruct_materials default 
		} 
	}

//allied constructible

	alliedconstruct_script
	{ 
		spawn 
		{ 
			wait 200 
			constructible_class 2 
			trigger self startup 
		} 
	
		buildstart final 
		{ 
		} 

		built final 
		{ 
			setstate alliedconstruct_target default
			setstate alliedconstruct_materials invisible 
			wm_announce "The Allies have built an Assault Ramp!" 

		wm_teamvoiceannounce 0 "battery_axis_ramp_constructed"
		wm_teamvoiceannounce 1 "battery_allies_ramp_constructed"
		wm_removeteamvoiceannounce 0 "battery_axis_ramp_stop"
		wm_removeteamvoiceannounce 1 "battery_allies_ramp_construct"

			wm_teamvoiceannounce 1 "charming_allies_west_tanks_destroy"
			wm_teamvoiceannounce 0 "charming_axis_west_tanks_defend"

			wm_removeteamvoiceannounce 1 "charming_allies_west_tanks_destroy"
			wm_removeteamvoiceannounce 0 "charming_axis_west_tanks_defend"

			wm_teamvoiceannounce 1 "charming_allies_east_tanks_destroy"
			wm_teamvoiceannounce 0 "charming_axis_east_tanks_defend"

			wm_removeteamvoiceannounce 1 "charming_allies_east_tanks_destroy"
			wm_removeteamvoiceannounce 0 "charming_axis_east_tanks_defend"

		} 

		decayed final 
		{ 
			trigger self startup 
		} 

		death 
		{ 
			trigger self startup 
			wm_announce "The Axis have destroyed the Allied assault ramp!" 

			setstate alliedconstruct_materials default

		wm_addteamvoiceannounce 0 "battery_axis_ramp_stop"

		wm_addteamvoiceannounce 1 "battery_allies_ramp_construct"

		wm_teamvoiceannounce 0 "battery_axis_ramp_destroyed"

		wm_teamvoiceannounce 1 "battery_allies_ramp_destroyed"

		} 

		trigger startup 
		{ 
			setstate alliedconstruct_target invisible
			setstate alliedconstruct_materials default 
		} 
	}

// DESTRUCTIBLE OBJECTIVES ================================================

//North Door
	northdoor_script
	{
		spawn 
		{
			wait 200
			constructible_class 3 
		}

		death 
		{
			wm_announce "Allies have destroyed the Sout-West Panzer!"

			wm_teamvoiceannounce 1 "charming_allies_west_tanks_destroyed"
			wm_teamvoiceannounce 0 "charming_axis_west_tanks_destroyed"

			wm_removeteamvoiceannounce 0 "charming_allies_west_tanks_destroyed"
			wm_removeteamvoiceannounce 1 "charming_axis_west_tanks_destroyed"

			wm_objective_status 2 0 1
			wm_objective_status 2 1 2

	                        	trigger game_manager objectivecounter
		}
	}

//South Door
	southdoor_script
	{
		spawn 
		{
			wait 200
			constructible_class 3 
		}

		death 
		{
			wm_announce "Allies have destroyed the South-East Panzers!"

			wm_teamvoiceannounce 1 "charming_allies_east_tanks_destroyed"
			wm_teamvoiceannounce 0 "charming_axis_east_tanks_destroyed"

			wm_removeteamvoiceannounce 1 "charming_allies_east_tanks_destroyed"
			wm_removeteamvoiceannounce 0 "charming_axis_east_tanks_destroyed"

			wm_objective_status 1 0 1
			wm_objective_status 1 1 2

	                        	trigger game_manager objectivecounter
		}
	}

// NEUTRAL COMMAND POST ================================================
// FROM Goldrush Thx SD!!! prefab by seven 2003 

allied_compost_built
{
	spawn
	{
		wait 400
		trigger allied_compost_built setup

		constructible_class 2
	}

	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
	{
		setstate allied_compost_built_model underconstruction
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible
	}

	built final
	{
		setstate allied_compost_built_model default
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible

		trigger allied_compost_built_model enable_allied_features

		enablespeaker allies_compost_sound
	}

	decayed final
	{
		setstate allied_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default
	}

	death
	{
		setstate allied_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default

		trigger allied_compost_built_model disable_allied_features

		disablespeaker allies_compost_sound
	}
}

allied_compost_built_model
{
	spawn
	{
		wait 400
		setstate allied_compost_built_model invisible
	}

	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 4 0 2
		wm_objective_status 4 1 1
	}

	trigger disable_allied_features
	{
		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1
		sethqstatus 1 0

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

		wm_objective_status 4 0 0
		wm_objective_status 4 1 0
	}
}

axis_compost_built
{
	spawn
	{
		wait 400
		trigger axis_compost_built setup

		constructible_class 2
	}

	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
	{
		setstate axis_compost_built_model underconstruction
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible
	}

	built final
	{
		setstate axis_compost_built_model default
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible

		trigger axis_compost_built_model enable_axis_features

		enablespeaker axis_compost_sound
	}

	decayed final
	{
		setstate axis_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default
	}

	death
	{
		setstate axis_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default

		trigger axis_compost_built_model disable_axis_features

		disablespeaker axis_compost_sound
	}
}

axis_compost_built_model
{
	spawn
	{
		wait 400
		setstate axis_compost_built_model invisible
	}

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

		wm_objective_status 4 0 1
		wm_objective_status 4 1 2
	}

	trigger disable_axis_features
	{
		setchargetimefactor 0 soldier 1
		setchargetimefactor 0 lieutenant 1
		setchargetimefactor 0 medic 1
		setchargetimefactor 0 engineer 1
		setchargetimefactor 0 covertops 1
		sethqstatus 0 0

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

		wm_objective_status 4 0 0
		wm_objective_status 4 1 0
	}
}

//Constructable MG positions

//Allied MG

alliedmg_script 
{ 
	spawn 
	{ 
      		wait 200 
      		constructible_class 2 
      		trigger self startup 
   	} 

   	buildstart final 
   	{ 
   	} 

   	built final 
   	{ 
      		setstate alliedmg_extra default 
      		setstate alliedmg_mg42  default 
      		setstate alliedmg_materials invisible 

      		wm_announce   "Allied MG nest constructed!" 
   	} 

   	decayed final 
   	{ 
      		trigger self startup 
   	} 

   	death 
   	{ 
      		trigger self startup 

      		wm_announce   "Axis team has destroyed the Allied MG nest!" 
	} 

	trigger startup 
   	{ 
		setstate alliedmg_extra invisible 
		setstate alliedmg_mg42  invisible 
		setstate alliedmg_materials default 
      		repairmg42 construction_mg42 
   	} 
} 

//Axis MG

axismg_script 
{ 
	spawn 
	{ 
      		wait 200 
      		constructible_class 2 
      		trigger self startup 
   	} 

   	buildstart final 
   	{ 
   	} 

   	built final 
   	{ 
      		setstate axismg_extra default 
      		setstate axismg_mg42  default 
      		setstate axismg_materials invisible 

      		wm_announce   "Axis MG nest constructed!" 
   	} 

   	decayed final 
   	{ 
      		trigger self startup 
   	} 

   	death 
   	{ 
      		trigger self startup 

      		wm_announce   "Allied team has destroyed the Axis MG nest!" 
	} 

	trigger startup 
   	{ 
		setstate axismg_extra invisible 
		setstate axismg_mg42  invisible 
		setstate axismg_materials default 
      		repairmg42 construction_mg42 
   	} 
} 
