//Mitchell Down Scripting
//Map: mitchelldown
//Original Map and Script by: Chris Witherell 08/25/02
//ET Version Script by CptnTriscuit 1/07

game_manager
{
	spawn
	{
		wm_allied_respawntime		20
		wm_axis_respawntime		30
		wm_set_round_timelimit		20
		wm_number_of_objectives		8
		wm_set_defending_team	0
		wm_setwinner 0

		//setautospawn "Axis Base" 0
		//setautospawn "Allied Spawn" 1

		// Primary:
		// 1: Steal the Littleboy Bomb
		// 2: Secure the Littleboy Bomb
		// 3: The South Door
		// 4: The North Door
		// 5: Allied command post
		// 6: Axis command post
		// 7: Sewer Grate
		// 8: Gate Flag

		wm_objective_status 1 0 0 // <objective team status>
		wm_objective_status 1 1 0 // status: 0 = default
		wm_objective_status 2 0 0 //		 1 = succeeded
		wm_objective_status 2 1 0 //		 2 = failed
		wm_objective_status 3 0 0
		wm_objective_status 3 1 0
		wm_objective_status 4 0 0
		wm_objective_status 4 1 0
		wm_objective_status 5 0 0
		wm_objective_status 5 1 0
		wm_objective_status 6 0 0
		wm_objective_status 6 1 0
		wm_objective_status 6 0 0
		wm_objective_status 6 1 0
		wm_objective_status 6 0 0
		wm_objective_status 6 1 0

		wm_set_main_objective		1	0
		wm_set_main_objective		1	1

	}


	trigger allies_win
	{
		wm_setwinner 1
		wm_announce	"The Allies have Escaped with the Little Boy Bomb!"
		wait 2000
		wm_endround
	}

	trigger allies_cap_gate
	{
		setautospawn	"Axis Base" 0
		wm_axis_respawntime		40
		setstate axis_gate invisible

	}

	trigger axis_cap_gate
	{
		setautospawn	"Axis Gate" 0
		wm_axis_respawntime		30
		setstate axis_gate default
	}
}

//======================================================================
//=============| South Factory Door |===================================
//======================================================================

factorydoor_south
{
	spawn
	{
		wait 200
		constructible_class 3			// Dynamite only
		trigger factorydoor_south_debris hide
	}

	death
	{
		trigger factorydoor_south_debris unhide
		wm_announce	"Allied forces have destroyed the South Factory Doors!"
		setstate factorydoor_south_toi invisible

		wm_objective_status 3 0 2
		wm_objective_status 3 1 1
	}
}

factorydoor_south_debris
{
	spawn
	{
		wait 200
	}

	trigger hide
	{
		setstate factorydoor_south_debris invisible
	}

	trigger unhide
	{
		setstate factorydoor_south_debris default
	}
}

//======================================================================
//=============| North Factory Door |===================================
//======================================================================

factorydoor_north
{
	spawn
	{
		wait 200
		constructible_class 3			// Dynamite only
		trigger factorydoor_north_debris hide
	}

	death
	{
		trigger factorydoor_north_catwalk hide
		trigger factorydoor_north_debris unhide
		wm_announce	"Allied forces have destroyed the North Factory Doors!"
		setstate factorydoor_north_toi invisible

		wm_objective_status 4 0 2
		wm_objective_status 4 1 1
	}
}

factorydoor_north_debris
{
	spawn
	{
		wait 200
	}

	trigger hide
	{
		setstate factorydoor_north_debris invisible
	}

	trigger unhide
	{
		setstate factorydoor_north_debris default
	}
}

factorydoor_north_catwalk
{
	spawn
	{
		wait 200
	}

	trigger hide
	{
		setstate factorydoor_north_catwalk invisible
	}

	trigger unhide
	{
		setstate factorydoor_north_catwalk default
	}
}

//======================================================================
//=============| Sewer Grate |==========================================
//======================================================================

sewerGrate
{
	spawn
	{
		wait 200
		constructible_class 3			// Dynamite only
	}

	death
	{
		wm_announce	"Allied forces have destroyed the Sewer Grate!"
		setstate sewerGrate_toi invisible

		wm_objective_status 7 0 2
		wm_objective_status 7 1 1
	}
}

//======================================================================
//=============| The Little Boy Bomb |==================================
//======================================================================

little_boy
{
	spawn
	{
		wait 200
	}

	trigger stolen
	{
		wm_announce	"The Allies have Stolen the Little Boy Bomb!"
		trigger little_boy_toi hide

		wm_objective_status 1 0 2
		wm_objective_status 1 1 1
	}

	trigger secured
	{
		wm_announce	"The Allies have Secured the Little Boy Bomb!"

		wm_objective_status 2 0 2
		wm_objective_status 2 1 1
	}

	trigger returned
	{
		wm_announce	"The Axis have Returned the Little Boy Bomb!"
		trigger little_boy_toi unhide

		wm_objective_status 1 0 0
		wm_objective_status 1 1 0
	}
}

little_boy_captured
{
	spawn
	{
		wait 200
		trigger self hide
	}

	trigger hide
	{
		setstate little_boy_captured invisible
	}

	trigger unhide
	{
		setstate little_boy_captured default
	}
}

little_boy_red
{
	spawn
	{
		wait 200
	}

	trigger hide
	{
		setstate little_boy_red invisible
	}

	trigger unhide
	{
		setstate little_boy_red default
	}
}

little_boy_capzone
{
	spawn
	{
		wait 200
	}

	death
	{
		trigger little_boy_captured unhide
		trigger little_boy_red hide
		wm_announce "The Allies have Secured the Little Boy Bomb!"
		trigger game_manager allies_win
	}
}

//======================================================================
//=============| The Church Machine Gun |===============================
//======================================================================

churchmg
{
	spawn
	{
		wait 400
		trigger churchmg setup

		constructible_class 2
	}

	trigger setup
	{
		setstate churchmg_mg invisible
		setstate churchmg_sandbags invisible
		setstate churchmg_materials default
		setstate churchmg_clip default
		setstate churchmg_flag default
	}

	buildstart final
	{
		trigger churchmg_warning unhide
		setstate churchmg_materials default
		setstate churchmg_clip default
		setstate churchmg_flag default
	}

	built final
	{
		trigger churchmg_warning hide
		setstate churchmg_mg default
		setstate churchmg_sandbags default
		setstate churchmg_materials invisible
		setstate churchmg_clip invisible
		setstate churchmg_flag invisible

		wm_announce	"The Church MG has been constructed!"
	}

	decayed final
	{
		trigger churchmg_warning hide
		setstate churchmg_materials default
		setstate churchmg_clip default
		setstate churchmg_flag default
	}

	death
	{
		setstate churchmg_mg invisible
		setstate churchmg_sandbags invisible
		setstate churchmg_materials default
		setstate churchmg_clip default
		setstate churchmg_flag default

		wm_announce	"The Church MG has been destroyed!"
	}

	trigger remove
	{
		setstate churchmg_materials invisible
		setstate churchmg_clip invisible
		setstate churchmg_flag invisible
		setstate churchmg_clip invisible

		remove
	}
}

churchmg_warning
{
	spawn
	{
		wait 200
		setstate churchmg_warning invisible
	}

	trigger hide
	{
		setstate churchmg_warning invisible
	}

	trigger unhide
	{
		setstate churchmg_warning default
	}
}

//======================================================================
//=============| Windmill |=============================================
//======================================================================

windmill
{
	spawn
	{
		wait 200
		trigger windmill rotateloop
	}
	trigger rotateloop
	{
		faceangles 0 2 2 5000
		faceangles 0 0 0 5000
		faceangles 0 -2 -2 5000
		faceangles 0 0 0 5000
		trigger windmill rotateloop
	}
}

//======================================================================
//=============| Allied CP (Lifted from Simland) |======================
//======================================================================


allied_cp_open
{
	spawn
	{
		wait 100
		accum 0 set 0			// 0=CP Closed, 1=CP Damaged
		constructible_class 2			// Dyno+Satchel

		trigger self disable_cp_features		// Default charge bar times
		setstate allied_cp_damaged invisible	// Hide damaged CP clipbrush+model
		setstate allied_cp_damaged_model invisible
	}

	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
	{
		setstate allied_cp_closed invisible		// Hide closed CP clipbrush+model
		setstate allied_cp_closed_model invisible
		setstate allied_cp_damaged invisible	// Hide damaged CP clipbrush+model
		setstate allied_cp_damaged_model invisible
	}

	built final
	{
		accum 0 set 1			// Only show the damaged CP model
		trigger self enable_cp_features		// Increase charge bar times

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

		wm_objective_status 5 0 2
		wm_objective_status 5 1 1

	}

	decayed final
	{
		setstate allied_cp_open_model invisible	// Hide Open CP model
		trigger self show_damaged_cabinet	// Show previous cabinet state
		trigger self show_closed_cabinet
	}

	death
	{
		trigger self show_damaged_cabinet	// Show damaged CP model
		trigger self disable_cp_features		// Default charge bar times

		wm_announce "Axis team has destroyed the Allied Command Post!"

		wm_objective_status 5 0 0
		wm_objective_status 5 1 0
	}

	trigger show_closed_cabinet
	{
		accum 0 abort_if_equal 1		// Closed cabinet active yet?
		setstate allied_cp_closed default
		setstate allied_cp_closed_model default
	}

	trigger show_damaged_cabinet
	{
		accum 0 abort_if_equal 0		// Damaged cabinet active yet?
		setstate allied_cp_damaged default
		setstate allied_cp_damaged_model default
	}
}

//======================================================================
//=============| Axis CP (Lifted from Simland) |========================
//======================================================================

axis_cp_open
{
	spawn
	{
		wait 100
		accum 0 set 0			// 0=CP Closed, 1=CP Damaged
		constructible_class 2			// Dyno+Satchel

		trigger self disable_cp_features		// Default charge bar times
		setstate axis_cp_damaged invisible	// Hide damaged CP clipbrush+model
		setstate axis_cp_damaged_model invisible
	}

	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.85
		setchargetimefactor 0 lieutenant 0.85
		setchargetimefactor 0 medic 0.85
		setchargetimefactor 0 engineer 0.85
		setchargetimefactor 0 covertops 0.85

		sethqstatus 0 1			// Landmines team warning message
		enablespeaker axis_cp_sound		// Enable morse code sound
	}

	buildstart final
	{
		setstate axis_cp_closed invisible		// Hide closed CP clipbrush+model
		setstate axis_cp_closed_model invisible
		setstate axis_cp_damaged invisible	// Hide damaged CP clipbrush+model
		setstate axis_cp_damaged_model invisible
	}

	built final
	{
		accum 0 set 1			// Only show the damaged CP model
		trigger self enable_cp_features		// Increase charge bar times

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

		wm_objective_status 6 0 1
		wm_objective_status 6 1 2
	}

	decayed final
	{
		setstate axis_cp_open_model invisible	// Hide Open CP model
		trigger self show_damaged_cabinet	// Show previous cabinet state
		trigger self show_closed_cabinet
	}

	death
	{
		trigger self show_damaged_cabinet	// Show damaged CP model
		trigger self disable_cp_features		// Default charge bar times

		wm_announce "Allied team has destroyed the Axis Command Post!"

		wm_objective_status 6 0 0
		wm_objective_status 6 1 0
	}

	trigger show_closed_cabinet
	{
		accum 0 abort_if_equal 1		// Closed cabinet active yet?
		setstate axis_cp_closed default
		setstate axis_cp_closed_model default
	}

	trigger show_damaged_cabinet
	{
		accum 0 abort_if_equal 0		// Damaged cabinet active yet?
		setstate axis_cp_damaged default
		setstate axis_cp_damaged_model default
	}
}

//========================================================================
//================| The Master Lock Control |=============================
//========================================================================

master_lock_fiu
{
	spawn
	{
		wait 200
	}

	activate allies
	{
		trigger master_lock_on hide
		trigger master_lock_off unhide
		trigger teamdoora_locked hide
		trigger teamdoora_unlocked unhide
		wm_announce "Axis-Only Doors have been Unlocked!"
	}

	activate axis
	{
		trigger master_lock_on unhide
		trigger master_lock_off hide
		trigger teamdoora_locked unhide
		trigger teamdoora_unlocked hide
		wm_announce "Axis-Only Doors have been Locked!"
	}

}

master_lock_off
{
	spawn
	{
		wait 200
		trigger self hide
	}

	trigger hide
	{
		setstate master_lock_off invisible
	}

	trigger unhide
	{
		setstate master_lock_off default
	}
}

master_lock_on
{
	spawn
	{
		wait 200
	}

	trigger hide
	{
		setstate master_lock_on invisible
	}

	trigger unhide
	{
		setstate master_lock_on default
	}
}

teamdoora_locked
{
	spawn
	{
		wait 200
	}

	trigger hide
	{
		setstate teamdoora_locked invisible
	}

	trigger unhide
	{
		setstate teamdoora_locked default
	}

}

teamdoora_unlocked
{
	spawn
	{
		wait 200
		setstate teamdoora_unlocked invisible
	}

	trigger hide
	{
		setstate teamdoora_unlocked invisible
	}

	trigger unhide
	{
		setstate teamdoora_unlocked default
	}
}

//========================================================================
//================| The Gate Flag |=======================================
//========================================================================

axis_gate_flag
{
	spawn
	{
		wait 200
		setstate axis_gate invisible
	}

	trigger allied_capture
	{
		wm_announce "The Allies have Captured the Gate Flag!"
		trigger axis_gate_wobj hide
		trigger game_manager allies_cap_gate
	}

	trigger axis_capture
	{
		wm_announce "The Axis have Captured the Gate Flag!"
		trigger axis_gate_wobj unhide
		trigger game_manager axis_cap_gate
	}

}

axis_gate_wobj
{
	spawn
	{
		wait 200
		trigger self hide
	}

	trigger hide
	{
		setstate axis_gate_wobj invisible
		setstate axis_gate invisible
	}

	trigger unhide
	{
		setstate axis_gate_wobj default
		setstate axis_gate default
	}
}

axis_base_wobj
{
	spawn
	{
		wait 200
	}

	trigger hide
	{
		setstate axis_base_wobj invisible
		setstate axis_base invisible
	}

	trigger unhide
	{
		setstate axis_base_wobj default
		setstate axis_base default
	}
}

allied_spawn_wobj
{
	spawn
	{
		wait 200
	}

	trigger hide
	{
		setstate allied_spawn_wobj invisible
		setstate allied_spawn invisible
	}

	trigger unhide
	{
		setstate allied_spawn_wobj default
		setstate allied_spawn default
	}
}