// slighty modified script/bsp to allow
// the counteragent icons to dissapear/reappear when taken/returned.
// permission granted by CptnTriscuit ( original map/script maker )
// changes made by rayban. ( comments added to show where )
game_manager
{
	spawn
	{
		wm_axis_respawntime	30
		wm_allied_respawntime	20
		wm_number_of_objectives 7
		wm_set_round_timelimit	30

		wm_set_main_objective	1	0
		wm_set_main_objective	1	1

		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 	4 0 0

		// Winner on expiration of round timer (0=Axis, 1=Allies)
		wm_setwinner	0

		wait 200
		setautospawn "Forward Spawn"	0	// Set Axis to forward spawn
	}

	trigger allies_win
	{
		wm_setwinner 1
		wait 3000
		wm_endround
	}
}

// ============================================================================
// Forward Spawn point - Initially owned by Axis
//
// ============================================================================
forwardspawn1_flag
{
	spawn
	{
		accum 0 set 0			// Who owns flag: 0-Axis, 1-Allied
	}

	trigger axis_capture				// Touched by an Axis player
	{
		accum 0 abort_if_equal 0 		// do Axis own flag?

		accum 0 set 0 			// Axis own the flag
		wm_announce "Axis reclaim the Forward Spawn!"

		alertentity forwardspawn1_wobj		// Switch command map marker
		setautospawn "Forward Spawn"	0	// Set Axis to forward spawn
	}

	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 capture the Forward Spawn!"

		alertentity forwardspawn1_wobj		// Switch command map marker
		setautospawn "Forward Spawn"	1	// Set Allies to forward spawn
	}

	trigger force_allied
	{
		accum 0 abort_if_equal 1 		// Do Allies own the flag?
		alertentity forwardspawn1_wobj		// Switch command map marker
		alertentity forwardspawn1_spawns		// Switch all spawnpoints
		setautospawn "Forward Spawn"	1	// Set Allies to forward spawn
	}
	trigger kill
	{
		remove				// Remove self (flag model)
	}
}




//===============================================================
//==================|    The Warehouse Wall |====================
//===============================================================

wall_explosive
{
	spawn
	{
		wait 200					// Wait for all entities to spawn
		constructible_class 3			// Dynamite only
	}

	death
	{
		trigger wall_debris unhide
		wm_announce "The Allies have breached the Warehouse Wall!"
		trigger forwardspawn1_flag force_allied 	// Switch forward spawn to Allied ONLY
		trigger forwardspawn1_flag kill		// Remove entities
		setstate forwardspawn1_base invisible	// Remove base of flag
	}
}

wall_debris
{
	spawn
	{
		wait 200
		trigger self hide
	}

	trigger hide
	{
		setstate wall_debris invisible
	}

	trigger unhide
	{
		setstate wall_debris default
	}
}

//===============================================================
//==================|    The Valve    |==========================
//===============================================================

valve_mover
{
	spawn
	{
		wait 200
	}

	trigger turn
	{
		faceangles 0 525 0 5000
	}

}

valve_fiu
{
	spawn
	{
		wait 200
		accum 0 set 0
	}

	activate allies
	{
		accum 0 abort_if_equal 1
		trigger valve_mover turn
		trigger pit_water drain
		wm_announce "The Allied Team has Drained the Western Chemical Pit"
		accum 0 set 1
	}

	activate axis
	{
		wait 1000
	}
}

pit_water
{
	spawn
	{
		wait 200
		setstate pit_water_hurt default
	}

	trigger drain
	{
		setstate pit_water_hurt invisible
		gotomarker pit_water_down 80 wait
		setstate pit_water invisible
	}
}

pit_water_hurt
{
	spawn
	{
		wait 200
	}
}

//===============================================================
//==================|    Chemical Counteragent |=================
//===============================================================

counteragenta
{
	spawn
	{
		wait 200
	}

	trigger stolen
	{
		//alertentity counteragenta_sm		// *** commented out
		setstate counteragenta_cm invisible		// *** added - rayban
	}

	trigger secured
	{
	}

	trigger returned
	{
		//alertentity counteragenta_sm		// *** commented out
		setstate counteragenta_cm default		// *** added - rayban
	}
}

counteragenta_toi
{
	spawn
	{
		wait 200
	}

}

counteragentb
{
	spawn
	{
		wait 200
	}

	trigger stolen
	{
		setstate counteragentb_cm invisible		// *** added - rayban
	}

	trigger secured
	{
	}

	trigger returned
	{
		setstate counteragentb_cm default		// *** added - rayban
	}
}

counteragentb_toi
{
	spawn
	{
		wait 200
	}

}

counteragentc
{
	spawn
	{
		wait 200
	}

	trigger stolen
	{
		setstate counteragentc_cm invisible		// *** added - rayban
	}

	trigger secured
	{
	}

	trigger returned
	{
		setstate counteragentc_cm default		// *** added - rayban
	}
}

counteragentc_toi
{
	spawn
	{
		wait 200
	}

}

counteragent_capzone
{
	spawn
	{
		wait 200
		accum 0 set 0 //the number of counteragents returned
		setstate spawn_axis_dam invisible
		setstate axis_dam_wobj invisible
		setstate counteragenta_capped invisible
		setstate counteragentb_capped invisible
		setstate counteragentc_capped invisible
		setstate counteragenta_uncapped default
		setstate counteragentb_uncapped default
		setstate counteragentc_uncapped default

	}

	death
	{
		trigger toxic_speaker sound
		setstate counteragent_capzone invisible
		accum 0 inc 1
		wait 200
		accum 0 trigger_if_equal 1 counteragent_capzone counteragentone
		accum 0 trigger_if_equal 2 counteragent_capzone counteragenttwo
		accum 0 trigger_if_equal 3 counteragent_capzone counteragentthree
	}

	trigger counteragentone
	{
		setstate counteragenta_capped default
		setstate counteragenta_uncapped invisible
		wm_announce "The Allied Team has captured the first container of counter-agent!"
		wait 1000
		wm_announce "Two containers remain!"
		wait 1000
		setstate counteragent_capzone default
		wm_set_round_timelimit	35
		wm_announce "Round Time increased by 5 minutes!"

	}

	trigger counteragenttwo
	{
		setstate counteragentb_capped default
		setstate counteragentb_uncapped invisible
		wm_announce "The Allied Team has captured the second container of counter-agent!"
		wait 1000
		wm_announce "Only one container remains!"
		wait 1000
		setstate counteragent_capzone default
		wm_set_round_timelimit	40
		wm_announce "Round Time increased by 5 minutes!"
	}

	trigger counteragentthree
	{
		setstate counteragentc_capped default
		setstate counteragentc_uncapped invisible
		wm_announce "The Allied Team has captured the final container of counter-agent!"
		wait 1000
		trigger main_controls activate_controls
		wm_announce "Get to the Central Circulation Control Room!"
		wait 1000
		setstate spawn_axis_dam default
		setstate axis_dam_wobj default
		setautospawn "Dam Spawn"	0	// Set Axis to forward spawn
		wm_set_round_timelimit	45
		wm_announce "Round Time increased by 5 minutes!"

	}
}

toxic_speaker
{
	spawn
	{
		wait 200
	}

	trigger sound
	{
		playsound "sound/cptnt_bastogne/s_query.wav"
	}
}

main_controls
{
	spawn
	{
		wait 200
		setstate main_controls invisible
	}

	activate allies
	{
		wm_announce "The Allied Team has Circulated the Counter-Agent!"
		wait 500
		wm_announce "The Axis Chemical Supply has been Destroyed!"
		trigger game_manager allies_win
	}

	trigger activate_controls
	{
		setstate main_controls default
	}
}

gamblor_fiu
{
	spawn
	{
		wait 200
		accum 0 set 0
	}

	activate allies
	{
		setstate gamblor_hurt default
		wait 200
		setstate gamblor_hurt invisible
		trigger self gamble
	}

	activate axis
	{
		setstate gamblor_hurt default
		wait 200
		setstate gamblor_hurt invisible
		trigger self gamble
	}

	trigger gamble
	{
		accum 0 random 8
		wait 100
		accum 0 trigger_if_equal 0 gamblor_fiu reward_0
		accum 0 trigger_if_equal 1 gamblor_fiu reward_1
		accum 0 trigger_if_equal 2 gamblor_fiu reward_2
		accum 0 trigger_if_equal 3 gamblor_fiu reward_3
		accum 0 trigger_if_equal 4 gamblor_fiu reward_4
		accum 0 trigger_if_equal 5 gamblor_fiu reward_5
		accum 0 trigger_if_equal 6 gamblor_fiu reward_6
		accum 0 trigger_if_equal 7 gamblor_fiu reward_7
	}

	trigger reward_0
	{
		wait 5000
	}

	trigger reward_1
	{
		alertentity gamblor_rocket_relay
		wait 100
		alertentity gamblor_rocket_relay
	}

	trigger reward_2
	{
		alertentity gamblor_healthpack_relay
		wait 100
		alertentity gamblor_healthpack_relay
	}

	trigger reward_3
	{
		setstate gamblor_ammo default
		wait 1000
		setstate gamblor_ammo invisible
	}

	trigger reward_4
	{
		alertentity gamblor_rocket_relay
		wait 100
		alertentity gamblor_rocket_relay
	}

	trigger reward_5
	{
		alertentity gamblor_healthpack_relay
		wait 100
		alertentity gamblor_healthpack_relay
		wait 100
		alertentity gamblor_healthpack_relay
		wait 100
		alertentity gamblor_healthpack_relay
		wait 100
		alertentity gamblor_healthpack_relay
	}

	trigger reward_6
	{
		setstate gamblor_ammo default
		wait 3000
		setstate gamblor_ammo invisible
	}

	trigger reward_0
	{
		wait 5000
	}
}

gamblor_hurt
{
	spawn
	{
		wait 200
		setstate gamblor_hurt invisible
	}
}

gamblor_ammo
{
	spawn
	{
		wait 200
		setstate gamblor_ammo invisible
	}
}

//================================
table
{
	spawn
	{
		wait 200
	}

	trigger tipover
	{
		setrotation	-180 0 0
		wait 500
		setrotation	0 0 0
		playsound "sound/maps/expl_small.wav"
	}
}

tabletip
{
	spawn
	{
	}

	trigger tip
	{
		trigger table tipover
	}
}
//================================

cargo_rail
{
	spawn
	{
		wait 200
		trigger self move_loop
	}

	trigger move_loop
	{
		wait random 6000 10000
		playsound "sound/movers/misc/gate1.wav" wait
		playsound "sound/movers/misc/gate2.wav" looping
		gotomarker rail_pos2 60 wait
		gotomarker rail_pos3 160 wait
		gotomarker rail_pos4 60 wait
		stopsound
		playsound "sound/movers/misc/gate3.wav" looping

		wait random 6000 10000
		playsound "sound/movers/misc/gate1.wav" wait
		playsound "sound/movers/misc/gate2.wav" looping
		gotomarker rail_pos3 60 wait
		gotomarker rail_pos2 160 wait
		gotomarker rail_pos1 60 wait
		stopsound
		playsound "sound/movers/misc/gate3.wav" looping

		trigger self move_loop
	}
}

cp_allied_final
{
	spawn
	{
		wait 200
		constructible_class 2

		setstate cp_allied_stage1 invisible
		setstate cp_allied_stage2 invisible
		setstate cp_allied_final invisible

		wm_announce "Allies Charge 1.0!"
		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1

		setstate allied_wobj_cp invisible
		setstate spawn_allied_cp invisible
	}

	trigger hide
	{
		setstate cp_allied_materials invisible
		setstate cp_allied_toi invisible
		setstate cp_allied_clip invisible
	}

	trigger unhide
	{
		setstate cp_allied_materials default
		setstate cp_allied_toi default
		setstate cp_allied_clip default
	}

	//============================================
	// CP Stage 1 - Basic Command Post
	//============================================
    	buildstart stage1
    	{
	}

	built stage1
	{
		wm_announce "The Allies have constructed a Command Post!"
		wm_announce "Allies Charge 0.80!"
		setchargetimefactor 1 soldier 0.80
		setchargetimefactor 1 lieutenant 0.80
		setchargetimefactor 1 medic 0.80
		setchargetimefactor 1 engineer 0.80
		setchargetimefactor 1 covertops 0.80
		sethqstatus 1 1
	}

	decayed stage1
	{
	}

	death
	{
		wm_announce "The Axis have disabled the Allied Command Post!"
		wm_announce "Allies Charge 1.0!"
		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1
		sethqstatus 1 0
	}

	//============================================
	// PC Stage 2 - Enhanced Command Post
	//============================================
    	buildstart stage2
    	{
	}

	built stage2
	{
		wm_announce "The Allies have upgraded their Command Post!"
		wm_announce "Allies Charge 0.60!"
		setchargetimefactor 1 soldier 0.60
		setchargetimefactor 1 lieutenant 0.60
		setchargetimefactor 1 medic 0.60
		setchargetimefactor 1 engineer 0.60
		setchargetimefactor 1 covertops 0.60
	}

	decayed stage1
	{
	}

	death
	{
		wm_announce "The Axis have damaged the Allied Command Post!"
		wm_announce "Allies Charge 0.80!"
		setchargetimefactor 1 soldier 0.80
		setchargetimefactor 1 lieutenant 0.80
		setchargetimefactor 1 medic 0.80
		setchargetimefactor 1 engineer 0.80
		setchargetimefactor 1 covertops 0.80
	}

	//============================================
	// CP Stage 3 (FINAL)- Forward Spawn
	//============================================
	buildstart final
	{
	}

	built final
	{
		wm_announce "The Allies have constructed a Forward Spawn!"
		setstate allied_wobj_cp default
		setstate spawn_allied_cp default
		setstate cp_allied_boxmodel invisible
		setstate cp_allied_clip invisible
	}

	decayed final
	{
	}

	destroyed final
	{
		wm_announce "The Axis have disabled the Allies Forward Spawn!"
		setstate allied_wobj_cp invisible
		setstate spawn_allied_cp invisible
		setstate cp_allied_boxmodel default
		setstate cp_allied_clip default

	}
}

//====================================================
//   The Team-Only Chests
//====================================================

ammobox1_Allied_box
{
	spawn
	{
		wait 200
	}

	trigger open
	{
		setstate ammobox1_Allied_giveammo default
		wait 1000
		setstate ammobox1_Allied_giveammo invisible
	}
}

ammobox1_Allied_giveammo
{
	spawn
	{
		wait 200
		setstate ammobox1_Allied_giveammo invisible
	}
}

ammobox2_Allied_box
{
	spawn
	{
		wait 200
	}

	trigger open
	{
		setstate ammobox2_Allied_giveammo default
		wait 1000
		setstate ammobox2_Allied_giveammo invisible
	}
}

ammobox2_Allied_giveammo
{
	spawn
	{
		wait 200
		setstate ammobox2_Allied_giveammo invisible
	}
}

healthbox1_Allied_box
{
	spawn
	{
		wait 200
	}

	trigger open
	{
		setstate healthbox1_Allied_giveammo default
		wait 1000
		setstate healthbox1_Allied_giveammo invisible
	}

}


healthbox1_Allied_giveammo
{
	spawn
	{
		wait 200
		setstate healthbox1_Allied_giveammo invisible
	}

}

healthbox3_Allied_box
{
	spawn
	{
		wait 200
	}

	trigger open
	{
		setstate healthbox3_Allied_giveammo default
		wait 1000
		setstate healthbox3_Allied_giveammo invisible
	}

}


healthbox3_Allied_giveammo
{
	spawn
	{
		wait 200
		setstate healthbox3_Allied_giveammo invisible
	}

}
