-- dlc06.lua
-- SR2 mission script

--[[ *** NOTES ***

	TODO: 
	* Pirate ship canons. (DONE)
	* Peewee taunt (DONE)
	* Add gyrocopter to first section. (DONE)
	* "Now things are getting interesting" -> mime car (DONE)
	* Disable action nodes on rooftop (DONE)
	* Eric use Binocular state(DONE)

	* Determine why ninjas were invisible in co-op. (DONE?)
	* Eric damages -> fail (NIXED)
	* More multi-target events. (NIXED)
	* Lower ped density between mime car and rooftop? (NIXED)
	* Satchel-charge mimes. (NIXED)
	* Readd Limo with new path. (NIXED)

	* New target ideas:
		* Psychic - always the first target.
		* Rapper
		* SuicideJumper
		* Someone hanging from the helicopter
		* Gyrocopter. (DONE)
		* Pirate target. (DONE)
		* Mime car. (DONE)
		* Juggler (DONE)
		* TaiChier (DONE)
		* Ninja's with smoke grenades... appears next to player after first time he's hit. (DONE)

	* Anim info for other nodes:
		Juggler: (DONE)
			State = Juggle
			Actions = NA
		Rapper
			State = Rap Stand
			Actions = Rap A, Rap B, Rap C
			Male Civilian
			special - rap battle
		TaiChier (DONE)
			State = TaiChiStand
			spcial - yoga
		SuicideJumper
			Suicide Stand
			Suicide Jump
		BinocularLooker
			Lookout Stand

	* Required animations
		--State = WaterCan Stand (pml1_wtrcan_sd.animx)
		--Actions = WaterCan Water Plants (pml1_wtrcan_waterplnts.animx)
		--State = Yoga Sit (pml1_yog_st_strtl.animx)
		--State = Guitar Stand (pml1_gp_sd.animx)
		--State = stand
		--Actions = powerup food (pml1_bs_sd_eating.animx)
		--State = Flyer Stand (pml1_flyers_sd.animx)
		--Actions = Flyer Passout A, Flyer Passout B (pml1_flyers_sd_psot_a.animx, pml1_flyers_sd_psot_b.animx)
		--State = Sketchpad Sit (pml1_spad_st.animx)
		--State = GroundReading Sit (pml1_grnd_st_rdbk.animx)
		--State = FireBreather Stand (pml1_firbrthr_sd.animx)
		--Actions = FireBreather Breathe Fire", "FireBreather Flip Fire (pml1_firbrthr_brthfire.animx, pml1_firbrthr_flpfire.)
		--State = Doorman stand (pml1_drman_sd.animx)
		--Actions = Doorman Greet (pml1_drman_sd_greet.animx)
		--State = stand, Smoking, stand (ykza_smkin_sd.animx - preloaded)
		--Actions = talk long, talk no, talk yes, talk short 
		-- (pml1_bs_sd_talk_lng.animx, pml1_bs_sd_talk_no.animx, pml1_bs_sd_talk_yes.animx, pml1_bs_sd_talk_shrt.animx - all preloaded)
		--State = Tourist Stand (pml1_tr_sd.animx)
		--Actions = Tourist Take Picture (pml1_tr_sd_pix.animx)
		--State = Fishing Stand (pml1_fishn_sd.animx)
		--Actions = Fishing Cast, Fishing Reel (pml1_fishn_cast.animx, pml1_fishn_reel.animx)

]]

MISSION_NAME						= "dlc06"


-- Target enumerations have to be listed before debug variables so that they are defined
-- when DEBUG_SECOND_FLOOR_TARGETS or DEBUG_ROOFTOP_TARGETS is set.
	TARGET_WATERER			= 1
	TARGET_YOGA				= 2
	TARGET_GUITAR			= 3
	TARGET_FOOD_EATER		= 4
	TARGET_FLYER			= 5
	TARGET_SKETCHER		= 6
	TARGET_READER			= 7
	TARGET_MIME				= 8
	TARGET_DOORMAN			= 9
	TARGET_JUGGLER			= 10
	TARGET_TOURIST			= 11
	TARGET_FISHERMAN		= 12
	TARGET_RUNNER			= 13
	TARGET_BOAT				= 14
	TARGET_CYCLE			= 15
	TARGET_CONVERTIBLE	= 16
	TARGET_PEEWEE			= 17
	TARGET_LIMO				= 18
	TARGET_JOGGERS			= 19
	TARGET_HELI				= 20
	TARGET_JETSKI			= 21
	TARGET_HOTDOG			= 22
	TARGET_TAICHIER		= 23
	TARGET_NINJA			= 24
	TARGET_GYRO				= 25

-- DEBUG VARIABLES --
	DO_NOT_RANDOMIZE_TARGETS		= false  -- this prevents the targets being randomized to go through them in the order in which they are listed below

	DEBUG_FLAG_SKIP_INTRO_CONVO	= false
	DEBUG_SKIP_STAIRS					= false
	-- If true, players start on the 2nd floor

	DEBUG_FLAG_SKIP_SECOND_FLOOR	= false -- If true, the player starts on the roof

	DEBUG_FLAG_DO_ALL_TARGETS		= false -- If true, do all targets one at a time

	DEBUG_SECOND_FLOOR_TARGETS		= {} -- {TARGET_CONVERTIBLE}
	DEBUG_ROOFTOP_TARGETS			= {} -- {TARGET_JOGGERS}

	DEBUG_FLAG_ONE_AT_A_TIME		= false

	DEBUG_TEST_SHIP_CANONS			= false
	DEBUG_TEST_NINJAS					= false

-----------------------------------------------------------------------------------
--																											--
-- Global constants (All caps == GLOBAL CONSTANT)											--
--																											--
-----------------------------------------------------------------------------------

--	(In general, global constants shouldn't be modified in running code, except for maybe in the setup function )

	-- Co-op mission?
		IN_COOP	= false

	-- Characters --

		CHAR_ERIC							= "dlc06_$Eric"
		LIMO_DRIVER							= "dlc06_$limo_driver"
		HELI_PILOT							= "dlc06_$heli_pilot"
		ULTOR_BEAR_CREW01					= { "dlc06_$c000", "dlc06_$c001", "dlc06_$c002", "dlc06_$c003" }
		ULTOR_BEAR_CREW02					= { "dlc06_$c004", "dlc06_$c005", "dlc06_$c006", "dlc06_$c007" }
		CHAR_MIME_CAR_DRIVER			= "dlc06_$c023"

		-- Targets
		CHAR_TARGET_RUNNER				= "dlc06_$target_runner"
		CHAR_TARGET_BOAT					= "dlc06_$target_boat"
		CHAR_TARGET_LIMO					= "dlc06_$target_limo"
		CHAR_TARGET_HELI					= "dlc06_$target_heli"
		CHAR_TARGET_JETSKI				= "dlc06_$target_jetski"
		CHAR_TARGET_HOTDOG				= "dlc06_$target_hotdog"
		CHAR_TARGET_CYCLE01				= "dlc06_$target_cycle01"
		CHAR_TARGET_CYCLE02				= "dlc06_$target_cycle02"
		CHAR_TARGET_CONVERTIBLE01		= "dlc06_$c008"
		CHAR_TARGET_CONVERTIBLE02		= "dlc06_$c009"
		CHAR_TARGET_CONVERTIBLE03		= "dlc06_$c010"
		CHAR_TARGET_PEEWEE				= "dlc06_$target_peewee"
		CHAR_TARGET_NINJA					= "dlc06_$target_ninja"
		CHAR_TARGET_GYRO					= "dlc06_$target_gyro"

		-- All of the extra ninjas
		CHAR_TARGET_OTHER_NINJAS		= 
		{
			"dlc06_$c024", "dlc06_$c025", "dlc06_$c026", "dlc06_$c027",
			"dlc06_$c028", "dlc06_$c029", "dlc06_$c030", "dlc06_$c031",
			"dlc06_$c032", "dlc06_$c033", "dlc06_$c034", "dlc06_$c035",
			"dlc06_$c036", "dlc06_$c037", "dlc06_$c038",
		}


	-- Checkpoints --
		CHECKPOINT_START					= MISSION_START_CHECKPOINT		-- defined in ug_lib.lua
		CHECKPOINT_ROOFTOP				= "dlc06_checkpoint_rooftop" 

	-- Conversations -- 

		MISSION_START_CONVERSATION =
		{
			-- Alright, I'm in the lighthouse.
			{ "GRYPHON_DLC0203_PHONE_1", nil, 0.0 },
			-- How's the view?
			{ "PLAYER_DLC0203_GRYPHONE1_1", LOCAL_PLAYER, 0.0 },
			-- Adequate. Dex's people are all over. I'll identify as many as I can so you can work your� magic... from that building.
			{ "GRYPHON_DLC0203_PHONE_2", nil, 0.0 },
			-- Wouldn't it be easier to just walk up to these assholes?
			{ "PLAYER_DLC0203_GRYPHONE1_2", LOCAL_PLAYER, 0.0 },
			-- If you want to go on a suicide run, be my guest. But if they spot you  we're both dead.
			{ "GRYPHON_DLC0203_PHONE_3", nil, 0.0 },
			-- If you say so.
			{ "PLAYER_DLC0203_GRYPHONE1_3", LOCAL_PLAYER, 0.0 },
		}

		-- Looks like we got Dex's attention then.
		-- BMPLAYER_DLC0203_GRYPHONE2_1

	-- Cutscenes --
		CUTSCENE_IN							= "DLC06-01"
		CUTSCENE_OUT						= "DLC06-02"

	-- Groups --
		GROUP_START							= "dlc06_$group_start"
		GROUP_RUNNER						= "dlc06_$group_runner"
		GROUP_BOAT							= "dlc06_$group_boat"
		GROUP_LIMO							= "dlc06_$group_limo"
		GROUP_JOGGERS						= "dlc06_$group_joggers"
		GROUP_HELI							= "dlc06_$group_heli"
		GROUP_JETSKI						= "dlc06_$group_jetski"
		GROUP_CYCLE							= "dlc06_$group_cycle"
		GROUP_ULTOR_ATTACK				= "dlc06_$group_ultor_attack"
		GROUP_HOTDOG						= "dlc06_$group_hotdog"
		GROUP_CONVERTIBLE					= "dlc06_$group_convertable"
		GROUP_POLICE						= "dlc06_$group_police"
		GROUP_PEEWEE						= "dlc06_$group_peewee"
		GROUP_MIME_CAR						= "dlc06_$Gclown_car"
		GROUP_NINJA							= "dlc06_$Gninja"
		GROUP_GYRO							= "dlc06_$group_gyro"

	-- Movers --
		POLICE_DOOR01						= "dlc06_$police_door01"
		POLICE_DOOR02						= "dlc06_$police_door02"
		MM_HOTEL_DOOR_1					= "dlc06_MMhotel_door_1"
		MM_HOTEL_DOOR_2					= "dlc06_MMhotel_door_2"
		MM_HOTEL_DOOR_3					= "dlc06_MMhotel_door_3"
		MM_HOTEL_DOOR_4					= "dlc06_MMhotel_door_4"
		MM_OFFICE_DOOR_1					= "dlc06_MMoffice_door_ground"
		MM_OFFICE_DOOR_2					= "dlc06_MMoffice_door_second"

	-- Navpoints --
		NAVP_LOCAL_START					= "dlc06_$nav_local_start"
		NAVP_REMOTE_START					= "dlc06_$nav_remote_start"
		NAVP_LOCAL_START2					= "dlc06_$nav_local_start2"
		NAVP_REMOTE_START2				= "dlc06_$nav_remote_start2"
		NAVP_LOCAL_START3					= "dlc06_$nav_local_start3"
		NAVP_REMOTE_START3				= "dlc06_$nav_remote_start3"
		RUNNER_FLEEPOINT					= "dlc06_$nav_runner_fleepoint"
		NAV_ERIC_LEAVE01					= "dlc06_$n125"
		NAV_ERIC_LEAVE02					= "dlc06_$n126"

		NAV_POLICE01						= "dlc06_$n156"
		NAV_POLICE02						= "dlc06_$n157"
		NAV_POLICE03						= "dlc06_$n207"

		NAVP_UFO_BOOM						= {"dlc06_$n229", "dlc06_$n230", "dlc06_$n231", "dlc06_$n232"}

		NAVP_FLEE_SET_1					= {"dlc06_$nav_fleepoint01", "dlc06_$nav_fleepoint02", "dlc06_$nav_fleepoint03", "dlc06_$nav_fleepoint04"}
		NAVP_FLEE_SET_2					= {"dlc06_$nav_fleepoint05", "dlc06_$nav_fleepoint06", "dlc06_$nav_fleepoint07", "dlc06_$nav_fleepoint08"}

		--NAVP_MIME_STAGING_DRIVER		= {"dlc06_$n281", "dlc06_$n282"}
		NAVP_MIME_STAGING_LEFT			= {"dlc06_$n281", "dlc06_$n282", "dlc06_$n283", "dlc06_$n284"}
		--NAVP_MIME_STAGING_PASSENGER	= {"dlc06_$n279", "dlc06_$n280"}
		NAVP_MIME_STAGING_RIGHT		= {"dlc06_$n277", "dlc06_$n278", "dlc06_$n279", "dlc06_$n280"}

		NAVP_MIME_THROW				= 
		{
			"dlc06_$n297", "dlc06_$n298", "dlc06_$n299", "dlc06_$n300", "dlc06_$n301", "dlc06_$n302", "dlc06_$n303", "dlc06_$n304"
		}

		NAVP_NINJA_ROOFTOP_ATTACK	= 
		{
			"dlc06_$n312", "dlc06_$n313", "dlc06_$n314", 
			"dlc06_$n315", "dlc06_$n316", "dlc06_$n317", 
			"dlc06_$n318", "dlc06_$n319", "dlc06_$n320", 
			"dlc06_$n321", "dlc06_$n322", "dlc06_$n323",
			"dlc06_$n324", "dlc06_$n325", "dlc06_$n326",
			"dlc06_$n327", "dlc06_$n373",
		}

		-- Canon shots sometimes hit the patio
		NAVP_CANON_PATIO = 
		{
			"dlc06_$n329", "dlc06_$n330", "dlc06_$n331"
		}

	-- Paths --
		PATH_BOAT_1							= "dlc06_$path_target_boat_1"
		PATH_BOAT_TURN						= "dlc06_$path_target_boat_turn"
		PATH_BOAT_2							= "dlc06_$path_target_boat_2"
		PATH_LIMO1							= "dlc06_$path_limo1"
		PATH_LIMO2							= "dlc06_$path_limo2"
		PATH_JOGGERS						= "dlc06_$path_joggers"
		PATH_HELI1							= "dlc06_$path_heli1"
		PATH_HELI2							= "dlc06_$path_heli2"
		PATH_HELI3							= "dlc06_$path_heli3"
		PATH_GYRO1							= "dlc06_$path_gyro1"
		PATH_GYRO2							= "dlc06_$path_gyro2"
		PATH_GYRO3							= "dlc06_$path_gyro3"
		PATH_CYCLE							= "dlc06_$path_cycle"
		PATH_JETSKI_1						= "dlc06_$path_jetski_1"
		PATH_JETSKI_TURN					= "dlc06_$path_jetski_turn"
		PATH_JETSKI_2						= "dlc06_$path_jetski_2"
		PATH_ULTOR_ATTACK					= "dlc06_$path_ultor_attack"
		PATH_ULTOR_ATTACK02				= "dlc06_$path_ultor_attack02"
		PATH_ULTOR_FOOT_ATTACK			= "dlc06_$path_ultor_foot_attack"
		PATH_ULTOR_FOOT_ATTACK2			= "dlc06_$path_ultor_foot_attack2"
		PATH_ERIC							= "dlc06_$path_eric"
		PATH_HOTDOG							= "dlc06_$path_hotdog"
		PATH_CONVERTIBLE					= "dlc06_$path_convertible"
		PATH_SWAT01							= "dlc06_$path_swat01"
		PATH_POLICE01						= "dlc06_$path_police01"
		PATH_POLICE02						= "dlc06_$path_police02"
		PATH_ERIC_TO_CAR					= "dlc06_$path_eric_to_car"
		PATH_MIME_CAR						= "dlc06_$path_clown_car"
		PATH_NINJA_ROOF_1					= "dlc06_$path_ninja_roof_1"
		PATH_NINJA_ROOF_2					= "dlc06_$path_ninja_roof_2"

		-- The start of the peewee path (replace PATH_PEEWEE_1 on the first pass)
		PATH_PEEWEE_0						= "dlc06_$path_peewee_0"

		-- The four half-loops of the peewee path, in-order
		PATH_PEEWEE_1						= "dlc06_$path_peewee_1" 
		PATH_PEEWEE_2						= "dlc06_$path_peewee_2"
		PATH_PEEWEE_3						= "dlc06_$path_peewee_3"
		PATH_PEEWEE_4						= "dlc06_$path_peewee_4"

		-- The escale route after completing the figure-8.
		PATH_PEWEE_ESCAPE					= "dlc06_$path_peewee_5"

		PATH_CONVERTIBLE_NAVP			= 
		{
			"dlc06_$n172", "dlc06_$n173", "dlc06_$n174", "dlc06_$n175", "dlc06_$n176",
			"dlc06_$n177", "dlc06_$n178", "dlc06_$n179", "dlc06_$n180", "dlc06_$n181",
			"dlc06_$n182", "dlc06_$n183", "dlc06_$n184"
		}

		PATH_CYCLE_NAVP					=
		{
			"dlc06_$n061", "dlc06_$n062", "dlc06_$n063", "dlc06_$n064", "dlc06_$n065",
			"dlc06_$n066", "dlc06_$n067", "dlc06_$n068", "dlc06_$n069", "dlc06_$n070",
			"dlc06_$n071"
		}

		PATH_MIME_NAVP					= 
		{
			"dlc06_$n271", "dlc06_$n285", "dlc06_$n292", "dlc06_$n272", "dlc06_$n293",
			"dlc06_$n273", "dlc06_$n294", "dlc06_$n295", "dlc06_$n274", "dlc06_$n296", 
			"dlc06_$n275", "dlc06_$n276"
		}

	-- Personas --

	-- Text --
		TEXT_FAIL_ERIC_KILLED			= "MSN_DLC06_FAIL_ERIC_KILLED"
		TEXT_FAIL_ERIC_VEHICLE_DESTROYED	= "MSN_DLC06_FAIL_ERIC_VEHICLE_DESTROYED" -- (LOCALIZE ME)
		TEXT_FAIL_TARGET_ESCAPED		= "MSN_DLC06_FAIL_TARGET_ESCAPED"
		TEXT_FAIL_LEFT_ROOFTOPS			= "MSN_DLC06_FAIL_LEFT_ROOF"
		TEXT_FAIL_LEFT_OFFICE			= "MSN_DLC06_FAIL_LEFT_OFFICE"
		TEXT_TARGET01						= "MSN_DLC06_TARGET1"
		TEXT_TARGET02						= "MSN_DLC06_TARGET2"
		TEXT_TARGET03						= "MSN_DLC06_TARGET3"
		TEXT_TARGET04						= "MSN_DLC06_TARGET4"
		TEXT_TARGET05						= "MSN_DLC06_TARGET5"
		TEXT_TARGET06						= "MSN_DLC06_TARGET6"
		TEXT_TARGET07						= "MSN_DLC06_TARGET7"
		TEXT_TARGET08						= "MSN_DLC06_TARGET8"
		TEXT_TARGET09						= "MSN_DLC06_TARGET9"
		TEXT_TARGET10						= "MSN_DLC06_TARGET10"
		TEXT_TARGET11						= "MSN_DLC06_TARGET11"
		TEXT_TARGET12						= "MSN_DLC06_TARGET12"
		TEXT_TARGET_JOGGERS				= "MSN_DLC06_TARGET_JOGGERS"
		TEXT_TARGET_RUNNER				= "MSN_DLC06_TARGET_RUNNER"
		TEXT_TARGET_LIMO					= "MSN_DLC06_TARGET_LIMO"
		TEXT_TARGET_BOAT					= "MSN_DLC06_TARGET_BOAT"
		TEXT_TARGET_PEEWEE				= "MSN_DLC06_TARGET_PEEWEE"
		TEXT_TARGET_HELI					= "MSN_DLC06_TARGET_HELI" 
		TEXT_TARGET_GYRO					= "MSN_DLC06_TARGET_HELI" 
		TEXT_TARGET_CYCLE					= "MSN_DLC06_TARGET_CYCLE"
		TEXT_TARGET_JETSKI				= "MSN_DLC06_TARGET_JETSKI"
		TEXT_TARGET_HOTDOG				= "MSN_DLC06_TARGET_HOTDOG"
		TEXT_TARGET_CONVERTIBLE			= "MSN_DLC06_TARGET_CONVERTABLE"
		TEXT_HELP_GO_TO_OFFICE			= "MSN_DLC06_GO_TO_OFFICE"
		TEXT_HELP_GO_TO_ROOF				= "MSN_DLC06_GO_TO_ROOF"
		TEXT_MEET_ERIC						= "MSN_DLC06_MEET_ERIC"
		TEXT_HELP_ULTOR_COMING			= "MSN_DLC06_HELP_ULTOR_COMING"		
		TEXT_KILL_EM_AS_I_CALL_EM		= "MSN_DLC06_KILL_EM_AS_I_CALL_EM"	
		TEXT_REQUIRED_AREA_EXITED		= "MSN_DLC06_REQUIRED_AREA_EXITED"			-- (LOCALIZE ME)
		TEXT_WAIT_FOR_PARTNER			= "MSN_TSS01_TOO_FAR_APART" -- Stay together. This portion needs to be done cooperatively

		TEXT_WAIT_FOR_ERIC				= "MSN_DLC06_WAIT_FOR_ERIC" -- "Wait for Eric to arrive"

		TEXT_MIME_CAR_DEFEND				= "MSN_DLC06_MIME_CAR_DEFEND" -- "Defend yourself from the angry mimes"
		TEXT_MIME_CAR_DESTROY			= "MSN_DLC06_MIME_CAR_DESTROY" -- "Destroy the mime car"

	-- Unlocalized text
		TEXT_TARGET_TAICHI				= "MSN_DLC06_TARGET_TAICHI" -- Kill the Taichier
		TEXT_TARGET_NINJA					= "MSN_DLC06_TARGET_NINJA" -- Shoot the ninja on the roof.

	-- Triggers --
		TRIGGER_GO1							= "dlc06_$trig_go1"
		TRIGGER_GO2							= "dlc06_$trig_go2"
		TRIGGER_SECOND_FLOOR_ARRIVAL  = "dlc06_$Tsecond_floor_arrival"
		TRIGGER_SECOND_FLOOR_AREA		= "dlc06_$trig_first_snipe"

		TRIGGER_GO3							= "dlc06_$trig_go3"
		TRIGGER_GO4							= "dlc06_$trig_go4"
		TRIGGER_GO5							= "dlc06_$trig_go5"
		TRIGGER_ROOFTOP_ARRIVAL			= "dlc06_$Trooftop_arrival"
		TRIGGER_ROOFTOP_AREA				= "dlc06_$trig_second_snipe"

		TRIGGER_ULTOR_REACH_ERIC		= "dlc06_$trig_ultor_reach_eric"

		TRIGGERS_UFO_BOOM					= {"dlc06_$t000", "dlc06_$t001", "dlc06_$t002", "dlc06_$t003"}

		TRIGGER_NINJA_FELL				= "dlc06_$Tninja_death"

		TRIGGER_MEET_ERIC					= "dlc06_$t004"

	-- Vehicles --
		VEH_BOAT					= "dlc06_$v000"
		VEH_LIMO					= "dlc06_$veh_limo"
		VEH_HELI					= "dlc06_$veh_heli"
		VEH_JETSKI				= "dlc06_$veh_jetski"
		VEH_CYCLE				= "dlc06_$veh_cycle"
		VEH_ULTOR_BEAR01		= "dlc06_$v001"
		VEH_ULTOR_BEAR02		= "dlc06_$v002"
		VEH_ERICS_DEF_RIDE	= "dlc06_$v003"
		VEH_CONVERTIBLE		= "dlc06_$veh_convertible"
		VEH_POLICE01			= "dlc06_$police_police01"
		VEH_POLICE02			= "dlc06_$police_police02"
		VEH_SWAT					= "dlc06_$police_swat01"
		VEH_PEEWEE				= "dlc06_$target_peewee_peewee"
		VEH_MIME_CAR			= "dlc06_$v004"
		VEH_GYRO					= "dlc06_$v005"

	-- Miscellaneous --

		-- Eric's audio lines that are played over the speakers 
		-- Note: This data structure isn't used in code, it is just here as a reference.
		ERIC_SPEAKER_LINES = 
		{

			-- Played when player(s) need to move from the 2nd floor to the roof
			"GRYPHON_DLC0203_PLAYERMOVE", -- People are starting to scatter. Get on the roof for a better vantage point.

			-- Played before the players are prompted to meet Eric.
			"GRYPHON_DLC0203_FINISHED", -- That's was unpleasant� Dex will have gotten the message by now.  We're finished here.  Meet me near the boardwalk.

			-- Played when the Ultor attack is initiated
			"GRYPHON_DLC0203_MASAKOATK_1", -- I've been spotted. The Masako team is coming for me.

			-- Played when the first Ultor bear arrives
			"GRYPHON_DLC0203_MASAKOATK_2", -- Just don't forget that I can't help you if I'm dead.

			-- TARGET_HELI
				"GRYPHON_DLC0203_SHOOTPERSON_1", -- Over there. One of Dex's accountants.

			-- TARGET_WATERER
				"GRYPHON_DLC0203_SHOOTPERSON_2", -- Now there's someone who needs a harsh lesson on the realities of life.

			-- TARGET_GUITAR
				"GRYPHON_DLC0203_SHOOTPERSON_3", -- How bout that one? Yeah... I think I've seen them around Dex's office.

			-- TARGET_FLYER
				"GRYPHON_DLC0203_SHOOTPERSON_5", -- I'm sure they've done something wrong in their miserable life�

			-- TARGET_CONVERTIBLE
				"GRYPHON_DLC0203_SHOOTPERSON_7", -- I don't suppose Dex's chauffeur would interest you�?

			-- TARGET_SKETCHER
				"GRYPHON_DLC0203_SHOOTPERSON_8", -- You won't get an easier shot than this.

			-- TARGET_JUGGLER
				"GRYPHON_DLC0203_SHOOTPERSON_9", -- Dex treats his masseuse like family� How unfortunate for them.

			-- TARGET_TOURIST
				"GRYPHON_DLC0203_SHOOTPERSON_10", -- You know what needs to be done with that one.

			-- TARGET_MIME
				"GRYPHON_DLC0203_SHOOTMIME_1", -- (sigh) Sutton the Mime� Please put everyone out of their misery�
				"GRYPHON_DLC0203_SHOOTMIME_2", -- I'd like to see that prick do the "invisible box" routine after this�
				"GRYPHON_DLC0203_SHOOTMIME_3", -- Kill the mime.  You don't really need a reason, do you?
			
			-- TARGET_CYCLE
				"GRYPHON_DLC0203_SHOOTMOTO_1", -- Masako trainer on that motorcycle. Take them out.
				"GRYPHON_DLC0203_SHOOTMOTO_2", -- People never understand just how dangerous motorcycles can be�

			-- TARGET_PEEWEE
				"GRYPHON_DLC0203_SHOOTMOTO_3", -- That is most certainly Dex's stylist.  Someone should have worn a helmet�

			-- TARGET_YOGA
				"GRYPHON_DLC0203_SHOOTYOGA_1", -- Someone is in need of a little enlightenment it seems.	
				"GRYPHON_DLC0203_SHOOTYOGA_2", -- Feel free to put Dex's florist "at one with the universe."

			-- TARGET_READER
				"GRYPHON_DLC0203_SHOOTYOGA_3", -- That's actually not anyone connected to Dex� I'm just repulsed by their face.

			-- TARGET_RUNNER
				"GRYPHON_DLC0203_SHOOTRUNNER_2", -- By all means, work your magic on that one.
				"GRYPHON_DLC0203_SHOOTRUNNER_3", -- Well, they didn't even say goodbye.

			-- TARGET_FISHERMAN
				"GRYPHON_DLC0203_SHOOTFISHERMAN_1", -- They're about to get the catch of the day�
				"GRYPHON_DLC0203_SHOOTFISHERMAN_2", -- Someone's about to sleep with the fishes� (cough) It sounded better in my head�
				"GRYPHON_DLC0203_SHOOTFISHERMAN_3", -- The only thing that person should catch is a bullet�

			-- TARGET_FOOD_EATER
				"GRYPHON_DLC0203_SHOOTEATERS_1", -- Look at these people stuffing their faces� Disgusting.
				"GRYPHON_DLC0203_SHOOTEATERS_2", -- Dex's dry cleaner is busy eating� You should have a clear shot.
				"GRYPHON_DLC0203_SHOOTEATERS_3", -- Hmm� Dex's personal food tester.  A little lead poisoning should suffice.

			-- TARGET_BOAT
				"GRYPHON_DLC0203_SHOOTBOATERS_1", -- See that boat out there?  It's carrying Dex's stock broker.
				"GRYPHON_DLC0203_SHOOTBOATERS_2", -- I hope you're not planning on letting that boat escape�
				"GRYPHON_DLC0203_SHOOTBOATERS_3", -- Dex loaned out that boat. A pity the captain won't go down with the ship.

			-- TARGET_JETSKI
				"GRYPHON_DLC0203_SHOOTJETSKI_1", -- Clearly that person doesn't understand how dangerous those contraptions can be�
				"GRYPHON_DLC0203_SHOOTJETSKI_2", -- Out on the water� Quick.
				"GRYPHON_DLC0203_SHOOTJETSKI_3", -- Torbit from marketing is trying to escape by sea. Put a stop to it.

			-- TARGET_LIMO
				"GRYPHON_DLC0203_SHOOTEXEC_1", -- Over by the limo. It's one of Dex's assistants�
				"GRYPHON_DLC0203_SHOOTEXEC_2", -- Hmm, only a decoy for one of the Ultor VPs� but don't let that stop you if you're so inclined.

			-- TARGET_HOTDOG
				"GRYPHON_DLC0203_SHOOTHOTDOG_1", -- Ugh� It's Lowery from accounting. Do us all a favor, please?
				"GRYPHON_DLC0203_SHOOTHOTDOG_3", -- Dex forces that fool to peddle month old hotdogs in our cafeteria� Please put an end to the problem.

			-- TARGET_JOGGERS
				"GRYPHON_DLC0203_PICNICRACE", -- The 3rd annual Executive Pirate Bay Run is about to begin.  Here's your chance to knock a few rungs off the corporate ladder.

			-- (TARGET_TAICHIER )
				"GRYPHON_DLC0203_SHOOTPERSON_4", -- Someone's personal shopper is in for a surprise�

			-- TARGET_NINJA
				"GRYPHON_DLC0203_SHOOTHOTDOG_2", -- That imbecile insists on wearing that outfit to the office� I never want to see it again.

			-- TARGET_GYRO
				"GRYPHON_DLC0203_SHOOTYOGA_3", -- That's actually not anyone connected to Dex� I'm just repulsed by their face.

			-- (USED DURING MIME ATTACK)
				"GRYPHON_DLC0203_SHOOTRUNNER_1", -- Now things are getting interesting�

			-- (Not being played currently)
				"GRYPHON_DLC0203_SHOOTEXEC_3", -- They claim those limos are bulletproof� Care to test that theory?

			-- (Not being played currently)
				"GRYPHON_DLC0203_3RDLOC", -- The crowds are moving away from the building� You'll need to find another location.

			-- (Not being played currently)
				"GRYPHON_DLC0203_SHOOTPERSON_6", -- Just shoot them already.

			-- (Not be played, was TARGET_LIMO )
				"GRYPHON_DLC0203_SHOOTEXEC_1", -- Over by the limo. It's one of Dex's assistants�
				"GRYPHON_DLC0203_SHOOTEXEC_2", -- Hmm, only a decoy for one of the Ultor VPs� but don't let that stop you if you're so inclined.

		}

		-- Easy 2nd floor targets
		TARGET_LIST_SECOND_FLOOR_EASY = 
		{
			TARGET_WATERER, TARGET_YOGA, TARGET_GUITAR, TARGET_FOOD_EATER, TARGET_MIME, TARGET_TAICHIER,
		}

		-- Hard 2nd floor targets
		TARGET_LIST_SECOND_FLOOR_HARD = 
		{
			TARGET_RUNNER, TARGET_CYCLE, TARGET_CONVERTIBLE, TARGET_GYRO, -- Limo
		}

		-- Easy rooftop targets
		TARGET_LIST_ROOFTOP_EASY = 
		{
			TARGET_JUGGLER, TARGET_TOURIST, TARGET_FISHERMAN, TARGET_FLYER,  TARGET_SKETCHER,
		} -- Eater, flyer... adjust text.

		-- Hard rooftop targets
		TARGET_LIST_ROOFTOP_HARD = 
		{
			TARGET_PEEWEE, TARGET_JOGGERS, TARGET_HELI, TARGET_JETSKI, TARGET_HOTDOG, TARGET_BOAT,
		}		

		-- NOT IN USE
		-- TARGET_DOORMAN
		-- TARGET_READER
		-- TARGET_LIMO


		-- Targets
		TARGET_INFOS = 
		{
			[TARGET_WATERER] = 
			{
				["targets"]			= {"dlc06_$target01"},
				["group"]			= "dlc06_$group_target_one",
				["fleepoints"]		= NAVP_FLEE_SET_1,
				["text"]				= TEXT_TARGET01,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTPERSON", {2}},
				["state"]			= "WaterCan Stand",
				["action_set"]		= {"WaterCan Water Plants"},
				["action_navp"]	= {"dlc06_$Nwaterer_action_1", "dlc06_$Nwaterer_action_2"},
				["spawn_navp"]		= {"dlc06_$nav_runner_fleepoint", "dlc06_$Nwaterer_spawn_2"}

			},
			[TARGET_YOGA] = 
			{
				["targets"]			= {"dlc06_$target02"},
				["group"]			= "dlc06_$group_target02",
				["fleepoints"]		= NAVP_FLEE_SET_1,
				["text"]				= TEXT_TARGET02,
				["function_name"]	= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTYOGA", {1,2}},
				["state"]			= "Yoga Sit",
				["action_navp"]	= {"dlc06_$Nyoga_action_1", "dlc06_$Nyoga_action_2", "dlc06_$Nyoga_action_3"},
				["spawn_navp"]		= {"dlc06_$Nyoga_spawn_1", "dlc06_$Nyoga_spawn_2"}
			},
			[TARGET_GUITAR] = 
			{
				["targets"]			= {"dlc06_$target03"},
				["group"]			= "dlc06_$group_target03",
				["fleepoints"]		= NAVP_FLEE_SET_1,
				["text"]				= TEXT_TARGET03,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTPERSON", {3}},
				["state"]			=	"Guitar Stand",
				["action_navp"]	= {"dlc06_$Nguitar_action_1", "dlc06_$Nguitar_action_2", "dlc06_$Nguitar_action_3"},
				["spawn_navp"]		= {"dlc06_$Nguitar_spawn_1", "dlc06_$Nguitar_spawn_2"}
			},
			[TARGET_FOOD_EATER] = 
			{
				["targets"]			= {"dlc06_$target04"},
				["group"]			= "dlc06_$group_target04",
				["fleepoints"]		= NAVP_FLEE_SET_1,
				["text"]				= TEXT_TARGET04,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTEATERS", {1, 2, 3}},
				["state"]			= "stand",
				["action_set"]		= {"powerup food"},
				["action_navp"]	= {"dlc06_$Neater_action_1", "dlc06_$Neater_action_2", "dlc06_$Neater_action_3"},
				["spawn_navp"]		= {"dlc06_$Neater_spawn_1", "dlc06_$Neater_spawn_2"}
			},
			[TARGET_FLYER] = 
			{
				["targets"]			= {"dlc06_$target05"},
				["group"]			= "dlc06_$group_target05",
				["fleepoints"]		= NAVP_FLEE_SET_2,
				["text"]				= TEXT_TARGET05,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTPERSON", {5}},
				["state"]			= "Flyer Stand",
				["action_set"]		= {"Flyer Passout A", "Flyer Passout B"},
				["action_navp"]	= {"dlc06_$Nflyer_action_1", "dlc06_$Nflyer_action_2", "dlc06_$Nflyer_action_3"},
				["spawn_navp"]		= {"dlc06_$Nflyer_spawn_1", "dlc06_$Nflyer_spawn_2"}
			},
			[TARGET_SKETCHER] = 
			{
				["targets"]			= {"dlc06_$target06"},
				["group"]			= "dlc06_$group_target06",
				["fleepoints"]		= NAVP_FLEE_SET_2,
				["text"]				= TEXT_TARGET06,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTPERSON", {8}},
				["state"]			= "Sketchpad Sit",
				["action_navp"]	= {"dlc06_$Nsketcher_action_1", "dlc06_$Nsketcher_action_2", "dlc06_$Nsketcher_action_3"},
				["spawn_navp"]		= {"dlc06_$Nsketcher_spawn_1", "dlc06_$Nsketcher_spawn_2"},
				["flee_delay"]		= 15,
			},
			[TARGET_READER] = 
			{
				["targets"]			= {"dlc06_$target07"},
				["group"]			= "dlc06_$group_target07",
				["fleepoints"]		= "dlc06_$nav_fleepoint05",
				["text"]				= TEXT_TARGET07,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTYOGA", {3}},
				["state"]			= "GroundReading Sit",
			},
			[TARGET_MIME] = 
			{
				["targets"]			= {"dlc06_$target08"},
				["group"]			= "dlc06_$group_target08",
				["fleepoints"]		= NAVP_FLEE_SET_1,
				["text"]				= TEXT_TARGET08,
				["function_name"]		= {"dlc06_eliminate_action_node_target","dlc06_target_mime"},
				["audio"]			=  {"SHOOTMIME", {1, 2, 3}},
				["state"]			= "FireBreather Stand",
				["action_set"]		= {"FireBreather Breathe Fire", "FireBreather Flip Fire"},
				["action_navp"]	= {"dlc06_$Nmime_action_1", "dlc06_$Nmime_action_2", "dlc06_$Nmime_action_3"},
				["spawn_navp"]		= {"dlc06_$Nmime_spawn_1", "dlc06_$Nmime_spawn_2"}
			},
			[TARGET_DOORMAN] = 
			{
				["targets"]			= {"dlc06_$target09"},
				["group"]			= "dlc06_$group_target09",
				["fleepoints"]		= "dlc06_$nav_fleepoint05",
				["text"]				= TEXT_TARGET09,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTPERSON", {4}},
				["state"]			= "",
				["action_set"]		= {}
			},
			[TARGET_JUGGLER] = 
			{
				["targets"]			= {"dlc06_$target10"},
				["group"]			= "dlc06_$group_target10",
				["fleepoints"]		= NAVP_FLEE_SET_2,
				["text"]				= TEXT_TARGET10,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTPERSON", {9}},
				["state"]			= "Juggle",
				["action_navp"]	= {"dlc06_$Nidle_action_1", "dlc06_$Nidle_action_2", "dlc06_$Nidle_action_3"},
				["spawn_navp"]		= {"dlc06_$Nidle_spawn_1", "dlc06_$Nidle_spawn_2", "dlc06_$Nidle_spawn_3"},
				["flee_delay"]		= 15,
			},
			[TARGET_TOURIST] = 
			{
				["targets"]			= {"dlc06_$target11"},
				["group"]			= "dlc06_$group_target11",
				["fleepoints"]		= NAVP_FLEE_SET_2,
				["text"]				= TEXT_TARGET11,
				["function_name"]		= {"dlc06_eliminate_action_node_target","dlc06_target_tourist"},
				["audio"]			=  {"SHOOTPERSON", {10}},
				["state"]			= "Tourist Stand",
				["action_set"]		= {"Tourist Take Picture"},
				["action_navp"]	= {"dlc06_$Ntourist_action_1", "dlc06_$Ntourist_action_2"},
				["spawn_navp"]		= {"dlc06_$Ntourist_spawn_3"},
--				["action_navp"]	= {"dlc06_$Ntourist_action_1", "dlc06_$Ntourist_action_2", "dlc06_$Ntourist_action_3", "dlc06_$Ntourist_action_4"},
--				["spawn_navp"]		= {"dlc06_$Ntourist_spawn_1", "dlc06_$Ntourist_spawn_2"}
				["invulnerable"]	= true,
			},
			[TARGET_FISHERMAN] = 
			{
				["targets"]			= {"dlc06_$target12"},
				["group"]			= "dlc06_$group_target12",
				["fleepoints"]		= NAVP_FLEE_SET_2,
				["text"]				= TEXT_TARGET12,
				["function_name"]		= "dlc06_eliminate_action_node_target",
				["audio"]			=  {"SHOOTFISHERMAN", {1, 2, 3}},
				["state"]			= "Fishing Stand",
				["action_set"]		= {"Fishing Cast", "Fishing Reel"},
				["action_navp"]	= {"dlc06_$Nfisherman_action_1", "dlc06_$Nfisherman_action_2", "dlc06_$Nfisherman_action_3"},
				["spawn_navp"]		= {"dlc06_$Nfisherman_spawn_1", "dlc06_$Nfisherman_spawn_2"}
			},
			[TARGET_RUNNER] = 
			{
				["targets"]			= {CHAR_TARGET_RUNNER},
				["group"]			= GROUP_RUNNER,
				["function_name"]		= "dlc06_target_runner",
				["audio"]			=  {"SHOOTRUNNER", {2, 3}}
			},
			[TARGET_BOAT] = 
			{
				["targets"]			= {CHAR_TARGET_BOAT},
				["group"]			= GROUP_BOAT,
				["function_name"]		= "dlc06_target_boat",
				["audio"]			=  {"SHOOTBOATERS", {1, 2, 3}}
			},
			[TARGET_CYCLE] = 
			{
				["targets"]			= {CHAR_TARGET_CYCLE01, CHAR_TARGET_CYCLE02},
				["group"]			= GROUP_CYCLE,
				["function_name"]		= "dlc06_target_cycle",
				["audio"]			= {"SHOOTMOTO", {1, 2, 3}}
			},
			[TARGET_CONVERTIBLE] = 
			{
				["targets"]			= {CHAR_TARGET_CONVERTIBLE01, CHAR_TARGET_CONVERTIBLE02, CHAR_TARGET_CONVERTIBLE03},
				["group"]			= GROUP_CONVERTIBLE,
				["function_name"]		= "dlc06_target_convertible",
				["audio"]			= {"SHOOTPERSON", {7}}
			},
			[TARGET_PEEWEE] = 
			{
				["targets"]			= {CHAR_TARGET_PEEWEE},
				["group"]			= GROUP_PEEWEE,
				["function_name"]		= "dlc06_target_peewee",
				["audio"]			= {"SHOOTMOTO", {1, 2, 3}}
			},
			[TARGET_LIMO] = 
			{
				["targets"]			= {CHAR_TARGET_LIMO},
				["group"]			= GROUP_LIMO,
				["function_name"]		= "dlc06_target_limo",
				["audio"]			=  {"SHOOTEXEC", {1, 2}}
			},
			[TARGET_JOGGERS] = 
			{
				["targets"]			= { "dlc06_$jogger01", "dlc06_$jogger02", "dlc06_$jogger03" },
				["group"]			= GROUP_JOGGERS,
				["function_name"]		= "dlc06_target_joggers",
				["audio"]			=  {"PICNICRACE"}
			},
			[TARGET_HELI] = 
			{
				["targets"]			= {CHAR_TARGET_HELI},
				["group"]			= GROUP_HELI,
				["function_name"]		= "dlc06_target_heli",
				["audio"]			=  {"SHOOTPERSON", {1}}

			},
			[TARGET_JETSKI] = 
			{
				["targets"]			= {CHAR_TARGET_JETSKI},
				["group"]			= GROUP_JETSKI,
				["function_name"]		= "dlc06_target_jetski",
				["audio"]			=  {"SHOOTJETSKI", {1, 2, 3}}
			},
			[TARGET_HOTDOG] = 
			{
				["targets"]			= {CHAR_TARGET_HOTDOG},
				["group"]			= GROUP_HOTDOG,
				["function_name"]		= "dlc06_target_hotdog",
				["audio"]			=  {"SHOOTHOTDOG", {1, 3}}
			},
			[TARGET_TAICHIER] = 
			{
				["targets"]			= {"dlc06_$target_taichier"},
				["group"]			= "dlc06_$Gtai_chi",
				["fleepoints"]		= NAVP_FLEE_SET_1,
				["text"]				= TEXT_TARGET_TAICHI,
				["function_name"]		= {"dlc06_eliminate_action_node_target"},
				["audio"]			=  {"SHOOTPERSON", {4}},
				["state"]			= "TaiChi Stand",
				["action_navp"]	= {"dlc06_$Ntaichi_action_1", "dlc06_$Ntaichi_action_2", "dlc06_$Ntaichi_action_3"},
				["spawn_navp"]		= {"dlc06_$nav_fleepoint03", "dlc06_$nav_fleepoint01", "dlc06_$Nwaterer_spawn_1"}
			},
			[TARGET_NINJA] = 
			{
				["targets"]			= {CHAR_TARGET_NINJA},
				["extra_targets"] = CHAR_TARGET_OTHER_NINJAS,
				["group"]			= GROUP_NINJA,
				["function_name"]	= "dlc06_target_ninja",
				["audio"]			=  {"SHOOTHOTDOG", {2}},
				["invulnerable"]	= true,
				["hidden"]			= true,
			},
			[TARGET_GYRO] = 
			{
				["targets"]			= {CHAR_TARGET_GYRO},
				["group"]			= GROUP_GYRO,
				["function_name"]		= "dlc06_target_gyro",
				["audio"]			=  {"SHOOTYOGA", {3}},
			},
		}

		

		POLICE_CREW01						= { "dlc06_$c017", "dlc06_$c018", "dlc06_$c019" }
		POLICE_CREW02						= { "dlc06_$c020", "dlc06_$c021", "dlc06_$c022" }
		SWAT_CREW01							= { "dlc06_$c011", "dlc06_$c012", "dlc06_$c013" , "dlc06_$c014", "dlc06_$c015", "dlc06_$c016" }

		SNIPER_RIFLE						= "mcmanus2010"
		FLEE_DISTANCE						= 5
		BOAT_SPEED							= 16
		BOAT_SPEED_TURN					= 7
		LIMO_SPEED							= 25
		HELI_SPEED							= 12
		JETSKI_SPEED						= 25
		JETSKI_SPEED_TURN					= 15
		CYCLE_SPEED							= 23
		CYCLE_SPEED_COOP					= 35
		CONVERTIBLE_SPEED					= 20
		CONVERTIBLE_SPEED_COOP			= 30
		LEFT_OFFICE_FAIL_TIME_S			= 15
		LEFT_ROOFTOP_FAIL_TIME_S		= 25

		-- Time at which the mission takes place
		TIME_OF_DAY_HOUR					= 12;
		TIME_OF_DAY_MINUTE				= 30;

		-- Weather stage for the mission
		WEATHER_STAGE						= 0;

		-- Max number of npc corpses
		NPC_MAX_CORPSES_OVERRIDE = 15

		-- Max number of ninjas that we can spawn in single player (Only 16 ninjas exist)
		MAX_NINJAS_SP = 8

		-- Max number of ninjas that we can spawn in co-op. (Only 16 ninjas exist)
		MAX_NINJAS_COOP = 16

		PLAYER_SYNC	=
		{
			[LOCAL_PLAYER]								= SYNC_LOCAL,
			[REMOTE_PLAYER]							= SYNC_REMOTE,
		}

		OTHER_PLAYER =
		{
			[LOCAL_PLAYER]								= REMOTE_PLAYER,
			[REMOTE_PLAYER]							= LOCAL_PLAYER,
		}

		PLAYER_TIMER_INDEX	=
		{
			[LOCAL_PLAYER]								= 0,
			[REMOTE_PLAYER]							= 1,
		}

	-- THE MIMES !!!!
	MIME_GROUPS = 
	{
		["dlc06_$Cclown_1"] = "dlc06_$Gclown_1",
		["dlc06_$Cclown_2"] = "dlc06_$Gclown_2",
		["dlc06_$Cclown_3"] = "dlc06_$Gclown_3",
		["dlc06_$Cclown_4"] = "dlc06_$Gclown_4",
		["dlc06_$Cclown_5"] = "dlc06_$Gclown_5",
		["dlc06_$Cclown_6"] = "dlc06_$Gclown_6",
		["dlc06_$Cclown_7"] = "dlc06_$Gclown_7",
		["dlc06_$Cclown_8"] = "dlc06_$Gclown_8",
		["dlc06_$Cclown_9"] = "dlc06_$Gclown_9",
		["dlc06_$Cclown_10"] = "dlc06_$Gclown_10",
		["dlc06_$Cclown_11"] = "dlc06_$Gclown_11",
		["dlc06_$Cclown_12"] = "dlc06_$Gclown_12",
	}

-- Ignore This Stuff --
GROUP_MYSTERY						= "dlc06_$group_mystery"
V_UFO									= "dlc06_$v_ufo"
C_ALIEN								= "dlc06_$c_alien"
MYSTERY_PATH						= "dlc06_$path_ufo"
MYSTERY_PATH_REVERSE				= "dlc06_$path_ufo_reverse"

-----------------------------------------------------------------------------------
--																											--
-- Global variables (First lett in caps == GLOBAL VARIABLE)								--
--																											--
-----------------------------------------------------------------------------------

	-- Door status
		Door01_open							= false
		Door02_open							= false

	-- Threads --
		Thread_eric_binoculars			= INVALID_THREAD_HANDLE
		Thread_eric_audio					= INVALID_THREAD_HANDLE
		Thread_keep_players_in_trigger= INVALID_THREAD_HANDLE
		Thread_ninja_prowl				= INVALID_THREAD_HANDLE
		
		Fake_action_node_threads		= {}

	-- Effects handles --
		Effect_handles						= {}		

	-- Number of ultor attackers killed
		Ultor_attackers_killed			= 0

	-- Have the players been given temporary weapons?
		Temp_weapons_given				= false

	-- Eliminated targets
		Target_eliminated				= {}

	-- Targets which shouldn't be marked
		Unmarked_targets				= {}

	-- A queue of target events that the players will progress through
		Target_event_queue				= {}

	-- The list of active target event threads
		Active_target_event_threads		= {}

	-- Are the targets in position for the event to begin?
		Target_event_participants_ready	= {}

	-- Are the players in the correct positions?
		Player_in_required_position		= {[LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false}

	-- The node at which the action node target is performing its actions
		Target_action_node = {}

	-- The max number of ninjas that can be spawned
		Max_ninjas = 8

	-- Initially we use the large kill arrow.
		Dlc06_npc_kill_icon = INGAME_EFFECT_VEHICLE_KILL

-----------------------------------------------------------------------------------
--																											--
-- The main function/thread. Called when the mission starts.							--
--																											--
-----------------------------------------------------------------------------------

-- dlc06_checkpoint: The checkpoint that we're restarting from.
-- is_restart: Was this mission restarted?
-- 
function dlc06_start(dlc06_checkpoint, is_restart)

	-- Fade out to begin the mission.
	mission_start_fade_out()

	if ( (DEBUG_TEST_SHIP_CANONS or DEBUG_FLAG_SKIP_SECOND_FLOOR or DEBUG_TEST_NINJAS) and (dlc06_checkpoint == CHECKPOINT_START) ) then
		dlc06_checkpoint = CHECKPOINT_ROOFTOP
		teleport_coop(NAVP_LOCAL_START3, NAVP_REMOTE_START3)
	end

	-- When starting from the beginning, we may need to play the intro cutscene.
	dlc06_handle_cutscene(dlc06_checkpoint, is_restart)

	-- Initialize the current checkpoint
	dlc06_initialize(dlc06_checkpoint)

	if (dlc06_checkpoint == CHECKPOINT_START) then

		if (not DEBUG_SKIP_STAIRS) then

			-- Start creating the Ufo's group
			group_create_hidden(GROUP_MYSTERY)

			-- Play the intro conversation
			if ( (not DEBUG_FLAG_SKIP_INTRO_CONVO) and (not is_restart) ) then
				dlc06_play_forced_incoming_call(MISSION_START_CONVERSATION)
			end

			-- Setup the rpg-guy when the breadcrumb trigger is hit
			dlc06_set_breadcrumb_functions({[TRIGGER_GO2] = "dlc06_mystery"})

			-- Unlock ground floor office door
			door_lock(MM_OFFICE_DOOR_1,false)

			-- Lead the players into the second floor of the sniping building
			dlc06_send_to_location(	{	TRIGGER_GO1,
												TRIGGER_GO2,
												TRIGGER_SECOND_FLOOR_ARRIVAL,
											},
											INGAME_EFFECT_LOCATION,
											{	TEXT_HELP_GO_TO_OFFICE,
											},
											true,
											true
										)

		else

			-- Unlock ground and open floor office door
			door_lock(MM_OFFICE_DOOR_1,false)		
			door_open(MM_OFFICE_DOOR_1, false)

		end

		-- The player has entered the first location for the first time, so anything we need to set up happens here	
		dlc06_give_sniper_rifles()

		-- Keep both players in this location for now
		dlc06_keep_players_in_trigger(TRIGGER_SECOND_FLOOR_AREA, LEFT_OFFICE_FAIL_TIME_S, "dlc06_failure_left_office")

		-- Tell the players to eliminate all of the targets as Eric calls them out:
		mission_help_table(TEXT_KILL_EM_AS_I_CALL_EM)
		delay(5.0)

		if (DEBUG_FLAG_DO_ALL_TARGETS) then

			for i,target in pairs(TARGET_LIST_SECOND_FLOOR_EASY) do
				dlc06_add_target(target)
			end
			for i,target in pairs(TARGET_LIST_SECOND_FLOOR_HARD) do
				dlc06_add_target(target)
			end

		elseif (sizeof_table(DEBUG_SECOND_FLOOR_TARGETS) ~= 0) then

			for i,target in pairs(DEBUG_SECOND_FLOOR_TARGETS) do
				dlc06_add_target(target)
			end

		else

			-- Kill two easy targets on the first floor
			dlc06_add_target(TARGET_LIST_SECOND_FLOOR_EASY[1])
			dlc06_add_target(TARGET_LIST_SECOND_FLOOR_EASY[2])

			-- Then the first hard target
			dlc06_add_target(TARGET_LIST_SECOND_FLOOR_HARD[1])

			-- Then another easy target. Make sure that the mime is always spawned.
			if ( (TARGET_LIST_SECOND_FLOOR_EASY[1] ~= TARGET_MIME) and (TARGET_LIST_SECOND_FLOOR_EASY[2] ~= TARGET_MIME) ) then
				dlc06_add_target(TARGET_MIME)
			else
				dlc06_add_target(TARGET_LIST_SECOND_FLOOR_EASY[3])
			end

			-- And finally, 2 more hard targets. 
			dlc06_add_target(TARGET_LIST_SECOND_FLOOR_HARD[2])
			dlc06_add_target(TARGET_LIST_SECOND_FLOOR_HARD[3])
		
		end

		-- Wait current target events to be completed
		dlc06_wait_for_target_event_completion()

		-- Do the mime car
		dlc06_mime_car()

		-- Let the players leave the second floor
		dlc06_release_players_from_required_trigger(TRIGGER_SECOND_FLOOR_AREA)

		-- Eric tells the players to head to the roof
		dlc06_play_eric_line_over_speaker("PLAYERMOVE")

		-- Unlock second floor office door
		door_lock(MM_OFFICE_DOOR_2,false)

		-- Lead the players into the second floor of the sniping building
		dlc06_send_to_location(	{	TRIGGER_GO3,
											TRIGGER_GO4,
											TRIGGER_GO5,
											TRIGGER_ROOFTOP_ARRIVAL,
										},
										INGAME_EFFECT_LOCATION,
										{	TEXT_HELP_GO_TO_ROOF
										},
										true, 
										true
									)

		-- Set the rooftop checkpoint
		mission_set_checkpoint(CHECKPOINT_ROOFTOP, true)
		dlc06_checkpoint = CHECKPOINT_ROOFTOP
	
		-- Release the mimes
		dlc06_release_mimes()

	end

	if (dlc06_checkpoint == CHECKPOINT_ROOFTOP) then

		if (DEBUG_TEST_SHIP_CANONS) then
			dlc06_test_ship_canons()
		end

		-- Tell the players to eliminate all of the targets as Eric calls them out:
		mission_help_table(TEXT_KILL_EM_AS_I_CALL_EM)
		delay(5.0)

		-- Keep both players in this location for now
		dlc06_keep_players_in_trigger(TRIGGER_ROOFTOP_AREA, LEFT_ROOFTOP_FAIL_TIME_S, "dlc06_failure_left_rooftop")

		if (DEBUG_FLAG_DO_ALL_TARGETS) then

			for i,target in pairs(TARGET_LIST_ROOFTOP_EASY) do
				dlc06_add_target(target)
			end
			for i,target in pairs(TARGET_LIST_ROOFTOP_HARD) do
				dlc06_add_target(target)
			end

		elseif (sizeof_table(DEBUG_ROOFTOP_TARGETS) ~= 0) then

			for i,target in pairs(DEBUG_ROOFTOP_TARGETS) do
				dlc06_add_target(target)
			end

		elseif (not DEBUG_TEST_NINJAS) then

			-- Kill two easy rooftop target
			dlc06_add_target(TARGET_LIST_ROOFTOP_EASY[1])
			dlc06_add_target(TARGET_LIST_ROOFTOP_EASY[2])

			-- A hard rooftop target
			dlc06_add_target(TARGET_LIST_ROOFTOP_HARD[1])

			-- A final easy rooftop target
			if ( (TARGET_LIST_ROOFTOP_EASY[1] ~= TARGET_TOURIST) and (TARGET_LIST_ROOFTOP_EASY[2] ~= TARGET_TOURIST) ) then
				dlc06_add_target(TARGET_TOURIST)
			else
				dlc06_add_target(TARGET_LIST_ROOFTOP_EASY[3])
			end

			-- Three more hard rooftop targets
			dlc06_add_target(TARGET_LIST_ROOFTOP_HARD[2])
			dlc06_add_target(TARGET_LIST_ROOFTOP_HARD[3])
			dlc06_add_target(TARGET_LIST_ROOFTOP_HARD[4])

		end

		-- Wait current target events to be completed
		dlc06_wait_for_target_event_completion()

		-- Disable chainsaw usage.
		chainsaw_disable()

		-- Allow more corpses
		npc_max_corpses_override(NPC_MAX_CORPSES_OVERRIDE)

		-- Add the ninja
		dlc06_add_target(TARGET_NINJA)

		-- Wait current ninja events to be completed
		dlc06_wait_for_target_event_completion()

		-- Reenable chainsaw usage
		chainsaw_enable()

		-- Reset the max npc corpse override
		npc_max_corpses_reset()

		-- Let cops take up resource slots again
	   character_slots_cap_for_team( "police", 2 )

		-- Use large kill arrows again.
		Dlc06_npc_kill_icon = INGAME_EFFECT_VEHICLE_KILL

		-- Eric warn's the player that the Ultor are after him.
		dlc06_play_eric_line_over_speaker("MASAKOATK_1")

		-- Eric goes inside
		thread_new("dlc06_send_eric_inside")

		-- Have the Ultor attack
		dlc06_launch_ultor_attack()

		-- Wait for Eric to show up.
		dlc06_send_eric_down()

	end

end

-----------------------------------------------------------------------------------
--																											--
-- Cutscene routines.																				--
--																											--
-----------------------------------------------------------------------------------

-- Play the opening cutscene, or, in the case of a restart, handle skipping of the cutscene.
function dlc06_handle_cutscene(checkpoint, is_restart)

	local local_start_navp = NAVP_LOCAL_START
	local remote_start_navp = NAVP_REMOTE_START

	if (DEBUG_SKIP_STAIRS) then

		local_start_navp = NAVP_LOCAL_START2
		remote_start_navp = NAVP_REMOTE_START2

	end

	-- The cutscene is only played at the mission start.
	if (checkpoint == CHECKPOINT_START) then

		-- Determine which groups to load at mission start.
		local start_groups = {GROUP_START}

		-- Load the groups/teleport manually for a restart. Otherwise use the cutscene system.
		if (is_restart) then

			-- Load starting groups
			for i,group in pairs(start_groups) do
				group_create(group, true)
			end

			-- Teleport players to the start location
			teleport_coop(local_start_navp, remote_start_navp)

		else

			-- Play the intro cutscene then show the start groups.
			cutscene_play(CUTSCENE_IN, start_groups, {local_start_navp, remote_start_navp}, false)
			for i,group in pairs(start_groups) do
				group_show(group)
			end

		end

	end

end

-----------------------------------------------------------------------------------
--																											--
-- Initialization routines																			--
--																											--
-----------------------------------------------------------------------------------

-- Initialize the mission for restart from a specific checkpoint
function dlc06_initialize(dlc06_checkpoint)

	-- Do initialization common to all checkpoints
	dlc06_initialize_common_pre()

	-- Do initialization specific to this checkpoint
	dlc06_initialize_checkpoint(dlc06_checkpoint)

	-- Do initialization common to all checkpoints
	dlc06_initialize_common_post()

	-- Fade-in for mission start
	mission_start_fade_in()

end

-- Initialization code shared by all checkpoints.
function dlc06_initialize_common_pre()

	-- Get Your Fur On.
	set_mission_author("Bryan Dillow, Phillip Alexander")

	-- Adjust police notoriety spawning
	notoriety_set_max( "Police", 3 )
	set_cops_shooting_from_vehicles( true )

	-- Eliminate Ronin notoriety
	notoriety_set_max( "Ronin", 0 )

	-- Determine if this is a co-op mission
	if coop_is_active() then
		IN_COOP = true
	end

	--Dismiss the player's party
	party_dismiss_all()
	party_set_recruitable(false)

	-- Set time of day to early afternoon
	set_time_of_day(TIME_OF_DAY_HOUR,TIME_OF_DAY_MINUTE)

	-- Make it nice outside!
	set_weather(WEATHER_STAGE,true)

	-- Restrict action node spawning
	action_nodes_restrict_spawning(true)

	-- Cap ronin slots
   character_slots_cap_for_team( "ronin", 0 )
   character_slots_cap_for_team( "police", 0 )
	character_slots_cap_for_team( "Playas", 0 )

	-- Disable the branded shop
	shop_enable( "MAR Branded", false )

	-- Kill the shop owner
	local clerk = "shops_sr2_city_$MAR_branded_clerk"
	if ( character_exists(clerk) and (not character_is_dead(clerk)) ) then
		character_kill(clerk)
	end

end

-- Initialization code specific to the checkpoint.
function dlc06_initialize_checkpoint(checkpoint)

	-- Handle starting from the beginning
	if (checkpoint ~= CHECKPOINT_START) then

		group_create(GROUP_START, true)

		-- Players should already have sniper rifles at this point.
		dlc06_give_sniper_rifles()

	else
		-- Lock and close the office doors
		door_close(MM_OFFICE_DOOR_1)
		door_lock(MM_OFFICE_DOOR_1,true)
		door_close(MM_OFFICE_DOOR_2)
		door_lock(MM_OFFICE_DOOR_2,true)

		-- Open the hotel doors
		thread_new("dlc06_keep_doors_open")
		--[[
		mesh_mover_hide(MM_HOTEL_DOOR_1)
		mesh_mover_hide(MM_HOTEL_DOOR_2)
		door_open(MM_HOTEL_DOOR_1, false)
		door_open(MM_HOTEL_DOOR_2, true)
		mesh_mover_reset_to_action_end(MM_HOTEL_DOOR_1, "start1")
		mesh_mover_reset_to_action_end(MM_HOTEL_DOOR_2, "end1")
		]]
	end

	-- Shuffle the order in which targets appear
	if (not DO_NOT_RANDOMIZE_TARGETS) then
		dlc06_shuffle_table( TARGET_LIST_SECOND_FLOOR_EASY	)
		dlc06_shuffle_table( TARGET_LIST_SECOND_FLOOR_HARD	)
		dlc06_shuffle_table( TARGET_LIST_ROOFTOP_EASY	)
		dlc06_shuffle_table( TARGET_LIST_ROOFTOP_HARD	)
	end

end

-- Doors usually close on chunk load/reload... this keeps them open.
function dlc06_keep_doors_open()

	while (true) do
		door_open(MM_HOTEL_DOOR_1, false)
		door_open(MM_HOTEL_DOOR_2, true)
		door_open(MM_HOTEL_DOOR_3, false)
		door_open(MM_HOTEL_DOOR_4, true)
		mesh_mover_reset_to_action_end(MM_HOTEL_DOOR_1, "start1")
		mesh_mover_reset_to_action_end(MM_HOTEL_DOOR_2, "start2")		
		mesh_mover_reset_to_action_end(MM_HOTEL_DOOR_3, "start1")
		mesh_mover_reset_to_action_end(MM_HOTEL_DOOR_4, "start2")		
		thread_yield()
	end
end

-- Initialization code shared by all checkpoints.
function dlc06_initialize_common_post()

	-- Don't let Eric's car be damaged
	dlc06_set_vehicle_invulnerable(VEH_ERICS_DEF_RIDE, true)

	-- Make sure that it doesn't chase/flee
	vehicle_disable_flee( VEH_ERICS_DEF_RIDE, true ) 
	vehicle_disable_chase( VEH_ERICS_DEF_RIDE, true ) 
	set_unjackable_flag(VEH_ERICS_DEF_RIDE, true)
	vehicle_set_untowable(VEH_ERICS_DEF_RIDE, true)
	vehicle_suppress_flipping(VEH_ERICS_DEF_RIDE, true)
	vehicle_infinite_mass(VEH_ERICS_DEF_RIDE, true)

	-- Add callbacks to Eric and his ride
	on_death( "dlc06_failure_eric_killed", CHAR_ERIC )
	on_vehicle_destroyed( "dlc06_failure_eric_vehicle_destroyed", VEH_ERICS_DEF_RIDE)

	-- Eric is a lover, not a fighter
	npc_combat_enable(CHAR_ERIC, false)

	-- He can't be recruited
	set_unrecruitable_flag( CHAR_ERIC, true )


	-- Start the target elimination thread
	thread_new( "dlc06_target_elimination")

	-- Eric looks through binoculars
	Thread_eric_binoculars = thread_new("dlc06_eric_use_binoculars")

end

function dlc06_eric_use_binoculars()

	local anim_state = "Clipboard Stand"
	local anim_action = "Clipboard Lean In"

	while(true) do

		if (not check_animation_state(CHAR_ERIC, anim_state)) then
			set_animation_state(CHAR_ERIC, anim_state)
		end
		thread_yield()

		action_play(CHAR_ERIC, anim_action, "", true, 1.0, true)

		delay(rand_int(5,8))

	end
end

----------------------------------------
-- Target Acquisition and Liquidation --
----------------------------------------

-- The main target elimination thread
function dlc06_target_elimination()

	-- Max number of target events that can be active at any point
	local max_active_target_events = 2
	if (IN_COOP) then
		max_active_target_events = 3
	end

	if (DEBUG_FLAG_ONE_AT_A_TIME) then
		max_active_target_events = 1
	end

	-- Activate new target 
	while (true) do

		-- Was a target just killed?
		local target_just_killed = false

		-- Remove inactive events from the active list					
		for target_event, thread_handle in pairs(Active_target_event_threads) do
			if (thread_check_done(thread_handle)) then
				Active_target_event_threads[target_event] = nil
				target_just_killed = true
			end
		end

		-- See if we can start a new target event
		local space_available = (sizeof_table(Active_target_event_threads) < max_active_target_events)
		local next_target_event = Target_event_queue[1] 
		if ( space_available and next_target_event) then

			-- A target was just killed. Wait a bit before activating the new target. If we don't do this, then Eric
			-- will call out a new target immediately. This makes the mission feel less organic.
			if (target_just_killed) then
				delay(rand_float(2.5,4))
			end

			-- Start the new target event
			Active_target_event_threads[next_target_event] = thread_new("dlc06_do_target_event",next_target_event)

			-- Adjust queue positions
			local num_targets_queued = sizeof_table(Target_event_queue)
			for i = 1, num_targets_queued - 1, 1 do
				Target_event_queue[i] = Target_event_queue[i + 1]
			end
			Target_event_queue[num_targets_queued] = nil

			-- Wait several seconds before initiating another target event
			delay(5.0)
			
		end

		-- No hangs
		thread_yield()

	end

end

-- Wait for target event completion
function dlc06_wait_for_target_event_completion()

	-- Wait until the event queue is empty and there are not active events
	while ( (Target_event_queue[1] ~= nil) or (sizeof_table(Active_target_event_threads) > 0) ) do
		thread_yield()
	end

end

-- Add a target to the target queue
function dlc06_add_target(target_index)

	if (target_index == nil) then
		return
	end

	local next_target_index = sizeof_table(Target_event_queue)	+ 1

	Target_event_queue[next_target_index] = target_index

end

-- The main thread for a target event
function dlc06_do_target_event(target_index)

	-- Mark the participants as not ready
	Target_event_participants_ready[target_index] = false

	-- Convenience variable
	local target_info = TARGET_INFOS[target_index]

	-- Create the group
	if ( target_info.hidden ) then
		group_create_hidden( target_info.group, true )
	else
		group_create( target_info.group, true )
	end
	
	-- Delay so that the group has time to load on the client
	delay(0.5)

	-- Make the targets invulnerable until they're in position
	for i, npc in pairs(target_info.targets) do
		turn_invulnerable(npc)
		npc_combat_enable(npc, false)
		set_cant_flee_flag(npc, true)
	end

	-- Create the thread(s) for this target
	if (type(target_info.function_name) == "table") then
		for i, name in pairs(target_info.function_name) do
			thread_new(name, target_index)
		end
	else
		thread_new(target_info.function_name, target_index)
	end

	-- For now we're only worrying about setting up action node positions
	local is_action_node_target = false
	if ( type(target_info.function_name) == "table") then
		for i, name in pairs(target_info.function_name) do
			if ( name == "dlc06_eliminate_action_node_target" ) then
				is_action_node_target = true
			end
		end
	else
		if ( target_info.function_name  == "dlc06_eliminate_action_node_target" ) then
			is_action_node_target = true
		end
	end
	if ( not is_action_node_target ) then
		Target_event_participants_ready[target_index] = true
	end

	-- Wait until the participants are ready
	while (not Target_event_participants_ready[target_index]) do
		thread_yield()
	end

	-- Start playing Eric's line for this person
	local line_suffix = target_info.audio[1]
	local variant_pool = target_info.audio[2]
	if (variant_pool) then
		local num_variants = sizeof_table(variant_pool)
		local line_variant = variant_pool[rand_int(1, num_variants )]
		line_suffix = line_suffix .. "_" .. line_variant
	end
	dlc06_play_eric_line_over_speaker(line_suffix)

	-- Setup the targets
	if (target_info.extra_targets) then
		for i, npc in pairs(target_info.extra_targets) do
			Target_eliminated[npc] = false
			on_death( "dlc06_target_killed", npc )
		end
	end

	for i, npc in pairs(target_info.targets) do
		Target_eliminated[npc] = false

		-- Make the target vulnerable
		if (not target_info.invulnerable) then
			turn_vulnerable(npc)
		end
		
		-- Allow action node targets to flee now
		if ( target_info.function_name  == "dlc06_eliminate_action_node_target" ) then
			if ( target_info.flee_delay ) then
				thread_new("dlc06_delayed_allow_flee", npc, target_info.flee_delay)				
			else
				set_cant_flee_flag(npc, false)
			end
		end

		-- Always add kill arrows. Only add minimap icons if the player is in position. (If out of position, icons
		-- will be added when the players get in position).
		ingame_effect_add_npc(npc, Dlc06_npc_kill_icon, SYNC_LOCAL)
		if (Player_in_required_position[LOCAL_PLAYER]) then
			minimap_icon_add_npc(npc, MINIMAP_ICON_KILL, "", SYNC_LOCAL)
		end
		if ( IN_COOP ) then
			ingame_effect_add_npc(npc, Dlc06_npc_kill_icon, SYNC_REMOTE)
			if (Player_in_required_position[REMOTE_PLAYER]) then
				minimap_icon_add_npc(npc, MINIMAP_ICON_KILL, "", SYNC_REMOTE)
			end

		end
		on_death( "dlc06_target_killed", npc )

		npc_combat_enable(npc, false)
	end

	-- Wait for enemies to be eliminated
	local all_targets_eliminated = false
	while (not all_targets_eliminated) do
		all_targets_eliminated = true
		for i,npc in pairs(target_info.targets) do
			if (not Target_eliminated[npc]) then
				all_targets_eliminated = false
			end
		end
		if ( target_info.extra_targets ) then
			for i,npc in pairs(target_info.extra_targets) do
				if (not Target_eliminated[npc]) then
					all_targets_eliminated = false
				end
			end			
		end
		thread_yield()
	end

	-- Give markers time to go away.
	delay(0.5)

	-- Release then destroy the current target's group
	release_to_world( target_info.group )
	delay(0.5) 
	group_destroy( target_info.group )

end

function dlc06_delayed_allow_flee(npc, delay_s)

	delay(delay_s)
	if ( character_exists(npc) and (not character_is_dead(npc)) ) then
		set_cant_flee_flag(npc, false)
	end

end

-----------------------------------------
-- Common code for action node targets --
-----------------------------------------

function dlc06_eliminate_action_node_target( target_event )

	-- Get the info for this target
	local target_info = TARGET_INFOS[target_event]

	-- The target npc (convenience variable)
	local target_npc = target_info.targets[1]

	-- Get the best (action_navp,spawn_navp) combo 
	local action_navp, spawn_navp = dlc06_select_navp(target_info.action_navp, target_info.spawn_navp)

	-- Remember the action node for later processing (currently used for the mime)
	Target_action_node[target_event] = action_navp

	-- Teleport the character to the action node if we can
	if ( spawn_navp == nil ) then
		teleport( target_npc, action_navp)		

		-- Make sure that the character has moved before we add markers
		delay(0.25)
		
	-- Otherwise, have the npc move to the action node
	else
		teleport( target_npc, spawn_navp)	
		move_to_safe( target_npc, action_navp, 1, true, false ) 
	end

	-- The participants are now ready
	Target_event_participants_ready[target_event] = true

	-- Determine when the npc should flee and have them run to the correct navpoint.
	if (target_event ~= TARGET_TOURIST) then
		thread_new( "dlc06_target_flee_handling", target_npc, action_navp, target_info.fleepoints )
	end

	-- Tell the player(s) what to do
	mission_help_table_nag( target_info.text ) 
		
	Fake_action_node_threads[target_npc] = thread_new("dlc06_fake_action_node", target_npc, target_info.fleepoints, target_info.state, target_info.action_set)
end

-- Determine the best (action_navpoint, spawn_navpoint) combo for an action node target
--
-- returns (action_navpoint, nil) if the target can be teleported directly to the action navpoint
-- returns (action_navpoint, spawn_navpoint) otherwise.
function dlc06_select_navp(action_navp_set, spawn_navp_set)

	-- Get the nearest action navp to another navp
	local function get_nearest_action_navp(navp)

		local nearest_dist = 10000
		local nearest_navp

		-- Loop over all action navpoints
		for i,action_navp in pairs(action_navp_set) do
			local current_dist = get_dist(navp,action_navp)
			if ( current_dist < nearest_dist ) then
				nearest_dist = current_dist
				nearest_navp = action_navp
			end						
		end

		-- Return the nearest action navpoint
		return nearest_navp

	end

	-- See if there is an out-of-site action node that we can use:
	for i,navp in pairs(action_navp_set) do
		if ( not dlc06_navpoint_in_fov(navp, 5.0) ) then
			return navp, nil
		end
	end

	-- All action navpoints are in view of a player, use the best spawn navp
	local furthest_dist = 0
	local furthest_spawn_navp = spawn_navp_set[1]

	for i,navp in pairs(spawn_navp_set) do

		-- If the sapwn navpoint is out of sight, return it
		if ( not dlc06_navpoint_in_fov(navp, 5.0) ) then
			return get_nearest_action_navp(navp), navp
		end

		-- Otherwise, track the furthest navpoint from any players
		local current_dist = get_dist_closest_player_to_object(navp)
		if ( current_dist > furthest_dist ) then
			furthest_spawn_navp = navp
			furthest_dist = current_dist
		end

	end

	-- No action navpoints or spawn navpoints were out of sight, return the furthest spawn navpoint
	return get_nearest_action_navp(furthest_spawn_navp), furthest_spawn_navp

end

function dlc06_target_flee_handling( target, nodename, fleepoints )

   -- As a way of detecting if a target has decided they need to flee
	-- I constantly check if they move beyond a distance from their assigned
	-- Action Node.   If they have exceeded that distance, I assume they're 
	-- fleeing and tell them to flee to a specific navpoint.   On arriving at  
	-- that Navpoint they are assumed to have successfully escaped. Npcs can only
	-- be damaged by the player, so npcs w/ less than max health can also be told
	-- to flee.

	local function should_flee()

		if (not character_exists(target) or character_is_dead(target)) then
			return true
		end

		if get_dist( nodename, target ) > FLEE_DISTANCE then
			return true
		end

		if ( get_current_hit_points(target) < get_max_hit_points(target) ) then
			return true
		end

		return false
		
	end

	while (not should_flee()) do
		delay(0.25)
	end

	if (not character_exists(target) or character_is_dead(target)) then
		return
	end

	-- Determine the best navpoint to flee to
	local best_navpoint = fleepoints[1]
	local best_weight = -1000

	for i, navp in pairs(fleepoints) do
		
		-- Navpoints far from players are good
		local current_weight = min(get_dist_closest_player_to_object(navp),50)

		-- Navpoints close to the fleeing npc are good
		current_weight = current_weight - get_dist(navp, target)

		-- Is the current navpoint an improvement?
		if (current_weight > best_weight) then
			best_weight = current_weight
			best_navpoint = navp
		end

	end

	-- Kill the fake action node thread.
	thread_kill(Fake_action_node_threads[target])

	local dist, closest_player = get_dist_closest_player_to_object(target)

	if (not character_exists(target) or character_is_dead(target)) then
		return
	end

	flee_to_navpoint( target, best_navpoint, closest_player, true ) 

	-- Because flee_to_navpoint isn't blocking, we need to go into a hold here until the character reaches the goal.
	local runner_got_away = false
	repeat

		if (not character_exists(target) or character_is_dead(target)) then
			return
		end

		if get_dist( target, best_navpoint ) < 3 then
			runner_got_away = true
		end
		delay(0.25)
	until runner_got_away

	dlc06_failure_target_escaped()
end

------------------------------------------------
-- Specialized code for action-node targets	 --
------------------------------------------------

function dlc06_target_mime()

	local mime_info = TARGET_INFOS[TARGET_MIME]
	local mime = mime_info.targets[1]

	-- Wait for the mime group to be loaded
	while (not group_is_loaded(mime_info.group)) do
		thread_yield()
	end

	-- Has the mime been shot?
	local function	mime_shot()

		-- Mime has been shot if he is dead or his hit points are less than max
		if (character_is_dead(mime)) then
			return true
		elseif (get_current_hit_points(mime) ~=  get_max_hit_points(mime)) then
			return true
		end

		return false

	end

	-- Wait fo rthe mime to be shot
	while (character_exists(mime) and (not mime_shot()) ) do
		thread_yield()
	end

	-- If the mime was shot near his action node, then BOOM!
	if (character_exists(mime) and get_dist(mime, Target_action_node[TARGET_MIME])) then
		explosion_create("Gas Exp Medium", Target_action_node[TARGET_MIME], "", true)	
	end

end

-- The tourist (Pirate)
function dlc06_target_tourist()

	local tourist = TARGET_INFOS[TARGET_TOURIST].targets[1]

	set_max_hit_points(tourist, 2000)  -- Sniper does 2500 per shot.

	on_take_damage("dlc06_tourist_take_damage", tourist)

end

-- When a ninja takes damage, it vanishes. After a short pause, 2 more ninjas appear in its place.
function dlc06_tourist_take_damage(tourist, attacker)

	-- Only take damage from players
	if ( (attacker ~= LOCAL_PLAYER) and (attacker ~= REMOTE_PLAYER) ) then
		return
	end

	-- If the target isn't at their action node, wait
	if (not Target_event_participants_ready[TARGET_TOURIST] ) then
		return
	end

	-- Don't take pictures
	if (not Fake_action_node_threads[tourist]) then
		return
	end

	thread_kill(Fake_action_node_threads[tourist])

	-- Don't do this again
	on_take_damage("", tourist)

	-- Turn to the players
	turn_to_nav(tourist, NAVP_CANON_PATIO[1])

	-- Play an audio line
	audio_play_persona_line( tourist, "threat - damage received (melee)", 3)

	-- Start the pirate ship attack
	dlc06_pirate_ship(tourist)

end

function dlc06_pirate_ship(pirate)

	local pirate_shoot_at_navp = "dlc06_$n365"

	-- Equip the magnum
	dlc06_equip_mime_common(pirate, "magnum")
	npc_unholster_best_weapon(pirate)

	local voice_situations = 
	{
		"threat - knocked down NPC/PC",
		"drunk - attack",
		"observe - human shield",
		"drunk - hit by car",
	}

	local first_pass = true
	while ( character_exists(pirate) and (not character_is_dead(pirate)) ) do

		-- Turn toward the players
		turn_to_nav(pirate, NAVP_CANON_PATIO[1])

		-- Play an audio line
		audio_play_persona_line( pirate, voice_situations[rand_int(1, sizeof_table(voice_situations))], 3)

		-- Fire once at the navp
		npc_combat_enable(pirate)
		character_set_combat_ready(pirate, true, 60 * 1000)

		npc_aim_at_point(pirate, pirate_shoot_at_navp)
		delay(1.0)
		force_fire(pirate, pirate_shoot_at_navp, true)

		npc_combat_enable(pirate, false)


		-- Delay a second
		delay(0.5)

		-- Fire the canons
		thread_new("dlc06_fire_canon")
		delay(rand_float(0.2,0.4))
		thread_new("dlc06_fire_canon")
		delay(rand_float(0.2,0.4))
		thread_new("dlc06_fire_canon")

		 -- Let the dust clear
		 delay(3.5)

		-- Take damage
		if (first_pass) then
			turn_vulnerable(pirate)
			first_pass = false
		end

	end

end

Canons_fired = false
function dlc06_fire_canon()

	local canon_navp_list = 
	{	"dlc06_$n328", "dlc06_$n366", "dlc06_$n367", "dlc06_$n368",
		"dlc06_$n369", "dlc06_$n370", "dlc06_$n371", "dlc06_$n372"	
	}

	local effect_list = 
	{ 

		"rpg_a_ignite", -- Quick fire donut
		"flamethrower", -- Initial flame?
		"fire_put_out", -- 
	}
			
	local detonation_navp = ""

	if (not Canons_fired) then
		Canons_fired = true
		detonation_navp = NAVP_CANON_PATIO[rand_int(1, sizeof_table(NAVP_CANON_PATIO))]
	else
		detonation_navp = NAVP_NINJA_ROOFTOP_ATTACK[rand_int(1, sizeof_table(NAVP_NINJA_ROOFTOP_ATTACK))]
	end

	local canon_navp = canon_navp_list[rand_int(1, sizeof_table(canon_navp_list))]

	effect_play( "muzz_minigun", canon_navp )
	delay(0.1)
	for i, effect in pairs(effect_list) do
		effect_play( effect, canon_navp )
	end
	audio_play_for_navpoint("SFX_RPG_EXP", canon_navp, "Foley")

	delay(0.3)
	explosion_create("grenade", detonation_navp, "", true)	

end
------------------------------------------------
-- Common code for land-based vehicle targets --
------------------------------------------------

-- Common code for handling a vehicle w/ multiple occupants
function dlc06_vehicle_target_common(occupant_list, vehicle, speed_override, speed_override_coop, text, path_navp_list)

	-- Setup the occupants
	for i,npc in pairs(occupant_list) do

		-- Place the character in the vehicle
		vehicle_enter_teleport(npc, vehicle, i - 1)

		-- Watch for passenger escape
		thread_new( "dlc06_vehicle_target_escape_watch", occupant_list, path_navp_list[sizeof_table(path_navp_list)] )

		-- Only take damage from the players
		turn_invulnerable(npc, true)

	end

	-- Only let the vehicle take damage from the players
	turn_invulnerable(vehicle, true)

	-- Make it unjackable
	set_unjackable_flag(vehicle, true)

	-- Don't let it flee or chase
	vehicle_disable_chase(vehicle, true)
	vehicle_disable_flee(vehicle, true)
	vehicle_set_script_hard_goto(vehicle, true)

	-- Handle damage to vehicle or characters
	thread_new( "dlc06_handle_vehicle_target_vehicle_damage", occupant_list, vehicle, path_navp_list)

	-- Wait for the group to be unhidden
	while( vehicle_hidden(vehicle) ) do
		thread_yield()
	end

	-- Override the vehicle's speed
	local speed = speed_override
	if (IN_COOP) then
		speed = speed_override_coop
	end
	vehicle_speed_override( vehicle, speed )

	-- Display the target help message
	mission_help_table_nag( text )

	-- Have the vehicle pathfind
	vehicle_pathfind_to( vehicle, path_navp_list, true, true)

end

-- Watch for vehicle targets escaping
function dlc06_vehicle_target_escape_watch( occupant_list, end_navp ) 

	-- Are all occupants dead
	local all_occupants_dead = false

	-- Continuously check for escape
	while ( not all_occupants_dead ) do

		for i, npc in pairs(occupant_list) do

			all_occupants_dead = true

			if ( character_exists(npc) and (not character_is_dead(npc)) ) then

				all_occupants_dead = false

				-- Trigger failure if an npc reaches the end of the path
				if ( get_dist (end_navp, npc) < 6 ) then
					dlc06_failure_target_escaped()
					return
				end

			end

		end

		thread_yield()

	end

end



-- Watch for damage to the vehicle or its occupants
function dlc06_handle_vehicle_target_vehicle_damage( occupant_list, vehicle, path_navp_list ) 

	-- Makes all living occupants exit the vehicle
	local function exit_vehicle()

		-- Get the set of living occupants
		local living_occupants = {}
		for i,npc in pairs(occupant_list) do
			if ( character_exists(npc) and (not character_is_dead(npc)) ) then
				living_occupants[npc] = npc
			end
		end

		-- Have all living occupants initiate exiting, keep track of npcs which are exiting
		local exiting_occupants = {}
		for i,npc in pairs(living_occupants) do
			-- Name, teleport, unenterable, dive
			if (vehicle_exit_do(npc, false, false, (vehicle ~= VEH_CYCLE) )) then
				exiting_occupants[npc] = npc
				while (not(vehicle_exit_check_done(npc))) do
					thread_yield()
				end
			end			
		end

	end

	-- Should the npcs flee/exit the vehicle?
	local should_flee_vehicle = false
	local should_exit_vehicle = false

	-- Wait until the occupants should flee the vehicle
	while ( not should_flee_vehicle ) do

		-- Flee if the vehicle is destroyed (I'm not sure if this will always kill the npcs)
		if ( not vehicle_exists(vehicle) or vehicle_is_destroyed(vehicle) ) then
			should_flee_vehicle = true
		
		-- Else, exit the vehicle and flee if the vehicle is smoking
		elseif ( vehicle_get_smoke_and_fire_state(vehicle) ) then
			should_exit_vehicle = true
			should_flee_vehicle = true

		-- Else, exit the vehicle and flee if an npc is dead or damaged
		else
			
			for i,npc in pairs(occupant_list) do

				if ( (not character_exists(npc)) or character_is_dead(npc) or (get_current_hit_points(npc) ~= get_max_hit_points(npc)) ) then
					should_exit_vehicle = true
					should_flee_vehicle = true	
				end

			end

		end

		-- Check for damage to the vehicle
		thread_yield()

	end

	-- Have the passengers exit the vehicle
	if (should_exit_vehicle) then
		exit_vehicle()
	end

	-- Have the passengers flee 
	for i,npc in pairs(occupant_list) do
		
		thread_new("dlc06_vehicle_occupant_flee", npc, path_navp_list)

	end

end

-- Have a vehicle occupant flee to the nearest end of the vehicle's path
function dlc06_vehicle_occupant_flee( npc, path_navp_list )
	
	if ( character_exists( npc ) and (not character_is_dead(npc) ) ) then

		-- Wait for the npc to finish exiting
		while ( character_exists(npc) and (not character_is_dead(npc)) and (not vehicle_exit_check_done(npc)) ) do
			thread_yield()
		end

		-- Convenience variables
		local start_navp = path_navp_list[1]
		local end_navp = path_navp_list[sizeof_table(path_navp_list)]

		-- Determine the nearest navpoint along the vehicles's path:
		local shortest_dist = 10000
		local nearest_navp = start_navp
		local nearest_index = 1
		for i = 1, sizeof_table(path_navp_list), 1 do
			local current_dist = get_dist(npc, path_navp_list[i])			
			if ( (current_dist < shortest_dist) ) then
				shortest_dist = current_dist
				nearest_navp = path_navp_list[i]
				nearest_index = i
			end
		end	

		-- If the npc is closer to the start of the path than the end, have them flee towards the starting point
		local reverse_path = false
		if (get_dist(nearest_navp, end_navp) > get_dist (nearest_navp, start_navp)) then
			reverse_path = true
		end

		-- Determine the path to flee along
		local index_increment = 1
		local final_index = sizeof_table(path_navp_list)
		if (reverse_path) then
			index_increment = -1
			final_index = 1
		end

		-- Flee to the next node along the path. Otherwise, the target may have to double back.
		-- 
		-- In the example below, assume that we've decided to have the npc escape forward along the path.
		-- We'd want them to skip N3 and travel to N4 and then N5.
		--
		-- N1...................N2............N3...NPC.........N4..............N5
		-- 
		if (nearest_index ~= final_index) then
			nearest_index = nearest_index + index_increment
		end

		-- Flee along the path
		for i = nearest_index, final_index, index_increment do

			-- Flee to the current node
			local dist, closest_player = get_dist_closest_player_to_object(npc)			
			flee_to_navpoint( npc, path_navp_list[i], closest_player, true )

			-- Wait until the npc gets close to the current node
			local move_on = false
			while (not move_on) do

				-- Make sure that the character is still around
				if ( character_is_dead(npc) or (not character_exists(npc)) ) then
					return
				end

				-- Determine if the character is close enough to the current target node to move on to the next
				if ( get_dist(npc, path_navp_list[i]) < 4 ) then
					move_on = true
				end

				thread_yield()
			end
		end
		
		-- If the script has gotten this far, then the passenger has followed the entire path, make sure that 
		-- the mission fails.
		dlc06_failure_target_escaped()

	end

end

-----------------------------------------------
-- Target is killed - Set up the Next Target --
-----------------------------------------------

function dlc06_target_killed( target )

	local function remove_markers()
		ingame_effect_remove_npc(target, SYNC_LOCAL)
		minimap_icon_remove_npc(target, SYNC_LOCAL)
		if (IN_COOP) then
			ingame_effect_remove_npc(target, SYNC_REMOTE)
			minimap_icon_remove_npc(target, SYNC_REMOTE)
		end
	end

	-- This is excessive, but I'm going to remove markers twice because of a problem where 
	-- the icons on ninjas would occasionally persist for a long interval.
	remove_markers()
	remove_markers()

	Target_eliminated[target] = true

end

--------------------------
-- Special Case Targets --
--------------------------

-- THE RUNNING MAN -------------------------------------------------------------------------------------

function dlc06_target_runner()
	-- This one is a guy panicking that makes a run for it from the beginning.
	-- Just let him go, if he gets to his destination then fail the destination.

	-- When the target was told to flee into the building directly from his starting location, he would
	-- often get on the door frame. Now I have him flee to the entry way and then pathfind into the building.

	-- Flee to the hotel doors
	local dist, closest_player = get_dist_closest_player_to_object(CHAR_TARGET_RUNNER)
	flee_to_navpoint( CHAR_TARGET_RUNNER, "dlc06_$t005", closest_player, true ) 

	-- Setup a trigger outside of the hotel near the doors
	trigger_enable( "dlc06_$t005", true )
	on_trigger( "dlc06_runner_reached_doors", "dlc06_$t005" )

	-- Helptext prompt
	delay(1)
	mission_help_table_nag( TEXT_TARGET_RUNNER )

end

-- Called when the runner arrives outside the hotel doors
function dlc06_runner_reached_doors(triggerer, trigger)

	if (triggerer ~= CHAR_TARGET_RUNNER) then
		return
	end

	-- Only do this once
	trigger_enable(trigger, false)
	on_trigger("", trigger)

	-- Run into the hotel
	npc_go_idle(CHAR_TARGET_RUNNER)
	set_cant_flee_flag(CHAR_TARGET_RUNNER, true)
	move_to_safe( CHAR_TARGET_RUNNER, RUNNER_FLEEPOINT, 2, true, false)

	-- Handle the pathfind completing
	if ( character_exists(CHAR_TARGET_RUNNER) and (not character_is_dead(CHAR_TARGET_RUNNER)) ) then

		-- If the character is near the fleepoint, fail the mission
		if (get_dist(CHAR_TARGET_RUNNER, RUNNER_FLEEPOINT) < 1) then

			dlc06_failure_target_escaped()

			-- Don't run back outside.	
			npc_leash_to_nav( CHAR_TARGET_RUNNER, RUNNER_FLEEPOINT, 0.5 )
			npc_leash_set_unbreakable( CHAR_TARGET_RUNNER, true )

		-- Character is alive, but not near the fleepoint. I'm not sure how this would happen, but let's
		-- just kill him to prevent a possible mission hang.
		else
			character_kill(CHAR_TARGET_RUNNER)			
		end
					
	end

end

-- DAS BOOT --------------------------------------------------------------------------------------------

function dlc06_target_boat()

	-- This one is a guy in a boat
	vehicle_enter_teleport( CHAR_TARGET_BOAT, VEH_BOAT, 0 )

	-- If the boat is destroyed, kill the target
	on_vehicle_destroyed("dlc06_kill_boat_target", VEH_HELI)

	vehicle_speed_override( VEH_BOAT, BOAT_SPEED )
	vehicle_suppress_npc_exit(VEH_BOAT, true)
	set_unjackable_flag(VEH_BOAT, true)
	delay(1)
	mission_help_table_nag( TEXT_TARGET_BOAT )
	vehicle_pathfind_to( VEH_BOAT, PATH_BOAT_1, true, false)

	vehicle_speed_override( VEH_BOAT, BOAT_SPEED_TURN )
	vehicle_pathfind_to( VEH_BOAT, PATH_BOAT_TURN, true, false)

	vehicle_speed_override( VEH_BOAT, BOAT_SPEED )
	vehicle_pathfind_to( VEH_BOAT, PATH_BOAT_2, true, true)

	local boat_got_away = false
	repeat
		if get_dist( "dlc06_$n253", CHAR_TARGET_BOAT ) < 6 then
			boat_got_away = true
		end
		delay(0.25)
	until boat_got_away
	
	dlc06_failure_target_escaped()
end

function dlc06_kill_boat_target()

	if( character_exists(CHAR_TARGET_BOAT) and (not character_is_dead(CHAR_TARGET_BOAT)) ) then
		character_kill(CHAR_TARGET_BOAT)
	end

end


-- HOT DOG ---------------------------------------------------------------------------------------------

function dlc06_target_hotdog()
	-- a hot dog mascot guy
	mission_help_table_nag( TEXT_TARGET_HOTDOG )
	move_to_safe( CHAR_TARGET_HOTDOG, PATH_HOTDOG, 1, true, false ) 
	local hotdog_got_away = false
	repeat
		if get_dist( "dlc06_$n270", CHAR_TARGET_HOTDOG ) < 3 then
			hotdog_got_away = true
		end
		delay(0.25)
	until hotdog_got_away
	
	dlc06_failure_target_escaped()
end

-- NINJA!!!!! ------------------------------------------------------------------------------------------

function dlc06_target_ninja()

	-- Determine the max number of ninjas that we can spawn
	Max_ninjas = MAX_NINJAS_SP
	if ( IN_COOP ) then
		Max_ninjas = MAX_NINJAS_COOP
	end

	-- Place the extra ninjas in the do-not mark list
	for i = 1, Max_ninjas - 1, 1 do
		Unmarked_targets[CHAR_TARGET_OTHER_NINJAS[i]] = true
	end

	dlc06_mark_extra_ninjas_eliminated()
	
	mission_help_table_nag( TEXT_TARGET_NINJA )

	-- The ninja can't be harmed for now
	on_take_damage("dlc06_ninja_take_damage", CHAR_TARGET_NINJA)
	dlc06_setup_ninja_common(CHAR_TARGET_NINJA)

	-- The ninja crawls around the roof of the building
	--crouch_start(CHAR_TARGET_NINJA, true)
	thread_new("dlc06_ninja_crouch")
	
	Thread_ninja_prowl = thread_new("dlc06_ninja_prowl_rooftop")

	-- Enable the ninja death trigger which handles ninjas falling from the roof
	on_trigger( "dlc06_ninja_fell", TRIGGER_NINJA_FELL )
	trigger_enable(TRIGGER_NINJA_FELL, true)

end

function dlc06_mark_extra_ninjas_eliminated()

	delay(1.0)

	for i = Max_ninjas, sizeof_table(CHAR_TARGET_OTHER_NINJAS), 1 do
		Target_eliminated[CHAR_TARGET_OTHER_NINJAS[i]] = true
	end

end

function dlc06_ninja_prowl_rooftop()

	character_show(CHAR_TARGET_NINJA)

	--  speed, retry_on_failure, move_and_fire
	move_to_safe( CHAR_TARGET_NINJA, PATH_NINJA_ROOF_1, 1, true, false)

	-- Ninja looks around a bit
	delay(1.5)

	--  speed, retry_on_failure, move_and_fire
	move_to_safe( CHAR_TARGET_NINJA, PATH_NINJA_ROOF_2, 1, true, false)

	-- Ninja looks around a bit
	delay(1.5)

	-- Ninja returns to his spawn location
	move_to_safe( CHAR_TARGET_NINJA, CHAR_TARGET_NINJA, 1, true, false)

	dlc06_failure_target_escaped()

end

function dlc06_ninja_crouch()
	delay(0.5)
	crouch_start(CHAR_TARGET_NINJA, true)
end

-- The set of ninjas which are attacking
Attacking_ninjas = 
{
	[1] = CHAR_TARGET_NINJA,
}

-- When a ninja takes damage, it vanishes. After a short pause, 2 more ninjas appear in its place.
function dlc06_ninja_take_damage(ninja, attacker, damage_percent)

	-- Only take damage from players
	if ( (attacker ~= LOCAL_PLAYER) and (attacker ~= REMOTE_PLAYER) ) then
		return
	end

	-- If max number of ninjas have been spawned, just let the ninja take damage normally
	if ( sizeof_table(Attacking_ninjas) >= Max_ninjas ) then
	
		local old_hit_points = get_current_hit_points(ninja)
		local new_hit_points = damage_percent * get_max_hit_points(ninja)
		set_current_hit_points(ninja, new_hit_points)
		return

	else

		-- Attack again.
		dlc06_ninja_respawn_with_friend(ninja)
	
	end

end

-- Called when a ninja falls from the rooftop
function dlc06_ninja_fell(triggerer)

	-- Only react if the triggerer is a ninja
	local is_ninja = false
	if ( triggerer == CHAR_TARGET_NINJA ) then
		is_ninja = true
	end
	for i,ninja in pairs(CHAR_TARGET_OTHER_NINJAS) do
		if ( triggerer == ninja ) then
			is_ninja = true
		end
	end

	if (not is_ninja) then
		return
	end

	-- Let the ninja die if all ninjas are spawned
	if ( sizeof_table(Attacking_ninjas) >= Max_ninjas ) then
		set_current_hit_points(triggerer,  0)

	-- Otherwise, respawn him on the roof with a friend.
	else
		dlc06_ninja_respawn_with_friend(triggerer)
	end
	
end

function dlc06_ninja_respawn_with_friend(ninja)

	-- Remove the on_death callback
	on_take_damage("", ninja)

	-- Add the next ninja to the battle
	local num_ninjas = sizeof_table(Attacking_ninjas)
	local next_ninja = CHAR_TARGET_OTHER_NINJAS[ num_ninjas]
	Attacking_ninjas[num_ninjas + 1] = next_ninja
	dlc06_setup_ninja_common(next_ninja)

	-- Kill the movement thread
	thread_kill(Thread_ninja_prowl)
	npc_go_idle(ninja)

	-- Make the ninja do something
	action_play( ninja, "crouch to crouch ready", "", true, 0.9, true)

	-- Create a smoke effect followed by a flash bang explosion
	dlc06_play_ninja_smoke_effect(ninja)
	delay(1.0)
	dlc06_play_ninja_flash_effect(ninja)

	-- Ninja becomes unmarked and vanishes
	dlc06_ninja_hide(ninja)

	-- Start the ninja attack!
	dlc06_ninja_attack(ninja, next_ninja)

end

Ninja_spawn_navp_in_use = {}

function dlc06_ninja_attack(ninja_one, ninja_two)

	-- Use the normal kill arrow for ninjas on the rooftop
	Dlc06_npc_kill_icon = INGAME_EFFECT_KILL


	-- Get the best rooftop spawn location for the ninja
	local function get_spawn_navp()
		-- Increase the min distance from players at which npcs are allowed to spawn as the number of ninjas
		-- increases.
		local distance_divisor = 4
		if (IN_COOP) then
			distance_divisor = 6
		end
		local min_dist = 2.5 + sizeof_table(Attacking_ninjas)/distance_divisor
		local shortest_dist = 2000
		local nearest_player = LOCAL_PLAYER
		local nearest_navp = NAVP_NINJA_ROOFTOP_ATTACK[1]
		for i, current_navp in pairs(NAVP_NINJA_ROOFTOP_ATTACK) do
			local current_dist, current_player = get_dist_closest_player_to_object(current_navp)
			-- Don't have ninjas appear too close to the player. We don't want them to group up and spawn on top of each other.
			if ( (current_dist < shortest_dist) and (current_dist > min_dist) and (not Ninja_spawn_navp_in_use[current_navp])) then
				shortest_dist = current_dist
				nearest_player = current_player
				nearest_navp = current_navp
			end
		end
		return nearest_navp
	end

	-- Wait a bit
	delay(rand_float(3, 5))

	-- Wait for at least one of the players to be up on the rooftop
	while ( (not Player_in_required_position[LOCAL_PLAYER]) and ((not IN_COOP) or (not Player_in_required_position[REMOTE_PLAYER])) ) do
		thread_yield()
	end

	-- Teleport the ninjas into position
	local spawn_navp = get_spawn_navp()
	teleport(ninja_one, spawn_navp)
	teleport(ninja_two, spawn_navp)

	-- Claim this navp
	Ninja_spawn_navp_in_use[spawn_navp] = true

	thread_yield()

	-- Readd ninja damage callbacks
	on_take_damage("dlc06_ninja_take_damage", ninja_one)
	on_take_damage("dlc06_ninja_take_damage", ninja_two)

	-- Do ninja effects
	dlc06_play_ninja_smoke_effect(ninja_one)
	delay(1.0)

	-- Ninja one attacks!
	dlc06_play_ninja_flash_effect(ninja_one)
	dlc06_ninja_show(ninja_one)
	crouch_stop(ninja_one)
	npc_combat_enable(ninja_one, true)
	attack(ninja_one)

	delay(rand_float(0.25, 0.6))

	-- Ninja two attacks!
	dlc06_play_ninja_flash_effect(ninja_two)
	dlc06_ninja_show(ninja_two)
	crouch_stop(ninja_two)
	npc_combat_enable(ninja_two, true)
	attack(ninja_two)

	-- Release the navp after a few seconds
	delay(4)
	Ninja_spawn_navp_in_use[spawn_navp] = false


end

function dlc06_play_ninja_smoke_effect(ninja)

	-- Limit the number of effects. Otherwise the smoke will fill up the screen.
	local max_ninja_effects = 5

	-- If we've already got the max # effects, kill off the oldest
	if (sizeof_table(Effect_handles) == max_ninja_effects) then
		effect_stop(Effect_handles[1])

		for i=2, max_ninja_effects, 1 do
			Effect_handles[i-1] = Effect_handles[i]
		end

		Effect_handles[max_ninja_effects] = nil
	end

	-- Only store the smoke effect. The flash bang is fast enough that I'm not worried about it.
	local handle = effect_play_for_object("smoke_grenade", ninja, false, SYNC_ALL, false)
	Effect_handles[sizeof_table(Effect_handles) + 1] = handle

end

function dlc06_play_ninja_flash_effect(ninja)
	effect_play_for_object("flash_bang", ninja, false, SYNC_ALL, false)
end

-- Hide a ninja
function dlc06_ninja_hide(ninja)

	-- Ninja becomes unmarked and vanishes
	Unmarked_targets[ninja] = true

	-- Hide the ninja
	ingame_effect_remove_npc(ninja, SYNC_LOCAL)
	minimap_icon_remove_npc(ninja, SYNC_LOCAL)
	character_hide(ninja)
	if (IN_COOP) then
		ingame_effect_remove_npc(ninja, SYNC_REMOTE)
		minimap_icon_remove_npc(ninja, SYNC_REMOTE)
	end

end

-- Show a ninja
function dlc06_ninja_show(ninja)

	-- Have the ninja reappear
	character_show(ninja)

	-- Mark the ninja. Always add kill arrows, only add icons for players in the required area.
	Unmarked_targets[ninja] = false
	ingame_effect_add_npc(ninja, Dlc06_npc_kill_icon, SYNC_LOCAL)
	if ( Player_in_required_position[LOCAL_PLAYER] ) then
		minimap_icon_add_npc(ninja, MINIMAP_ICON_KILL, "", SYNC_LOCAL)
	end
	if (IN_COOP) then
		ingame_effect_add_npc(ninja, Dlc06_npc_kill_icon, SYNC_REMOTE)
		if ( Player_in_required_position[REMOTE_PLAYER] ) then
			minimap_icon_add_npc(ninja, MINIMAP_ICON_KILL, "", SYNC_REMOTE)
		end
	end

end

-- Commone code for setting up the ninja on the rooftop or a ninja for an 
-- attack.
function dlc06_setup_ninja_common(ninja)
	
	-- Ninja damage is handled in script
	turn_invulnerable(ninja)

	character_prevent_explosion_fling(ninja, true)
	character_allow_ragdoll(ninja, false)

	-- have about 50% of the ninjas use melee attacks. the rest get swords
	inv_item_remove_all(ninja)
	if (rand_int(1,2) == 1) then
		inv_item_add("samurai_sword", 1, ninja)
	end

end

-- DRIVING MISS DAISY ----------------------------------------------------------------------------------

function dlc06_target_limo()
	-- This guy is waiting for his limo to arrive.
	vehicle_enter_teleport( LIMO_DRIVER, VEH_LIMO, 0 )
	delay(1)
	mission_help_table_nag( TEXT_TARGET_LIMO )
	vehicle_speed_override( VEH_LIMO, LIMO_SPEED )
	vehicle_pathfind_to( VEH_LIMO, PATH_LIMO1, true, true)
	vehicle_enter( CHAR_TARGET_LIMO, VEH_LIMO, 2 )
	vehicle_pathfind_to( VEH_LIMO, PATH_LIMO2, true, true)
	local limo_got_away = false
	repeat
		if get_dist( "dlc06_$n024", CHAR_TARGET_LIMO ) < 6 then
			limo_got_away = true
		end
		delay(0.25)
	until limo_got_away
	
	dlc06_failure_target_escaped()
end

-- CHARIOTS OF FIRE ------------------------------------------------------------------------------------

function dlc06_target_joggers()
	-- A trio of runners are moving across the area, get them before they reach the end
	for i, jogger in pairs(TARGET_INFOS[TARGET_JOGGERS].targets) do
		thread_new( "dlc06_target_jogger_jogging", jogger )
	end
	delay(1)
	mission_help_table_nag( TEXT_TARGET_JOGGERS )
end

function dlc06_target_jogger_jogging( jogger )

	-- Send the joggers on their way.
	move_to_safe( jogger, PATH_JOGGERS, 2, true, false ) 

	-- if the jogger completes the move_to then the sniper has failed.
	local jogger_got_away = false
	repeat
		if get_dist( "dlc06_$n245", jogger ) < 3 then
			jogger_got_away = true
		end
		delay(0.25)
	until jogger_got_away
	dlc06_failure_target_escaped()
end

-- CON AIR ---------------------------------------------------------------------------------------------

function dlc06_target_heli()
	-- the target is inside a helicopter flying over the Marina
	vehicle_enter_teleport( HELI_PILOT, VEH_HELI, 0 )
	vehicle_enter_teleport( CHAR_TARGET_HELI, VEH_HELI, 1 )

	-- If the heli is destroyed, kill the target
	on_vehicle_destroyed("dlc06_kill_heli_target", VEH_HELI)

	-- vehicle_speed_override( VEH_HELI, HELI_SPEED )
	delay(1)
	mission_help_table_nag( TEXT_TARGET_HELI )
	helicopter_fly_to_direct( VEH_HELI, HELI_SPEED, PATH_HELI1 )
	delay(5)
	helicopter_fly_to_direct( VEH_HELI, HELI_SPEED, PATH_HELI2 )
	delay(5)
	helicopter_fly_to_direct( VEH_HELI, HELI_SPEED, PATH_HELI3 )
	local heli_got_away = false
	repeat
		if get_dist( "dlc06_$n060", CHAR_TARGET_HELI ) < 10 then
			heli_got_away = true
		end
		delay(0.25)
	until heli_got_away
	
	dlc06_failure_target_escaped()
end

function dlc06_kill_heli_target()

	if( character_exists(CHAR_TARGET_HELI) and (not character_is_dead(CHAR_TARGET_HELI)) ) then
		character_kill(CHAR_TARGET_HELI)
	end

end

-- CON AIR ---------------------------------------------------------------------------------------------

function dlc06_target_gyro()

	-- Callbacks are skipped when a heli pilot dies in an explosion
	thread_new("dlc06_watch_for_gyro_pilot_death")

	-- the target is flying around inside a gyrocopter
	vehicle_enter_teleport( CHAR_TARGET_GYRO, VEH_GYRO, 0 )
	vehicle_enter_teleport( CHAR_TARGET_GYRO, VEH_GYRO, 1 )

	-- If the heli is destroyed, kill the target
	on_vehicle_destroyed("dlc06_kill_gyro_target", VEH_GYRO)

	-- vehicle_speed_override( VEH_HELI, HELI_SPEED )
	delay(1)
	mission_help_table_nag( TEXT_TARGET_GYRO )
	helicopter_fly_to_direct( VEH_GYRO, 20, PATH_GYRO1 )
	helicopter_fly_to_direct( VEH_GYRO, 30, PATH_GYRO2 )
	delay(3)
	helicopter_fly_to_direct( VEH_GYRO, 15, PATH_GYRO3 )
	local gyro_got_away = false
	repeat
		if get_dist( "dlc06_$n358", CHAR_TARGET_GYRO ) < 10 then
			gyro_got_away = true
		end
		delay(0.25)
	until gyro_got_away
	
	dlc06_failure_target_escaped()
end

function dlc06_kill_gyro_target()

	if( character_exists(CHAR_TARGET_GYRO) and (not character_is_dead(CHAR_TARGET_GYRO)) ) then
		character_kill(CHAR_TARGET_GYRO)
	end

end

function dlc06_watch_for_gyro_pilot_death()

	while( character_exists(CHAR_TARGET_GYRO) and (not character_is_dead(CHAR_TARGET_GYRO)) ) do
		thread_yield()
	end

	 dlc06_target_killed( CHAR_TARGET_GYRO )

end

-- WATERWORLD ------------------------------------------------------------------------------------------

function dlc06_target_jetski()

	-- This one is a guy in a jetski
	vehicle_enter_teleport( CHAR_TARGET_JETSKI, VEH_JETSKI, 0 )

	-- Kill the target if the jetski is destroyed
	on_vehicle_destroyed("dlc06_kill_jetski_target", VEH_JETSKI)

	vehicle_speed_override( VEH_JETSKI, JETSKI_SPEED )
	vehicle_suppress_npc_exit(VEH_JETSKI, true)
	set_unjackable_flag(VEH_JETSKI, true)
	delay(1)
	mission_help_table_nag( TEXT_TARGET_JETSKI )
	vehicle_pathfind_to( VEH_JETSKI, PATH_JETSKI_1, true, false)

	vehicle_speed_override( VEH_JETSKI, JETSKI_SPEED_TURN )
	vehicle_pathfind_to( VEH_JETSKI, PATH_JETSKI_TURN, true, false)

	vehicle_speed_override( VEH_JETSKI, JETSKI_SPEED )
	vehicle_pathfind_to( VEH_JETSKI, PATH_JETSKI_2, true, true)

	local jetski_got_away = false
	repeat
		if get_dist( "dlc06_$n090", CHAR_TARGET_JETSKI ) < 6 then
			jetski_got_away = true
		end
		delay(0.25)
	until jetski_got_away
	
	dlc06_failure_target_escaped()
end

function dlc06_kill_jetski_target()

	if( character_exists(CHAR_TARGET_JETSKI) and (not character_is_dead(CHAR_TARGET_JETSKI)) ) then
		character_kill(CHAR_TARGET_JETSKI)
	end

end

-- GHOST RIDER -----------------------------------------------------------------------------------------

function dlc06_target_cycle()

	local occupant_list = { CHAR_TARGET_CYCLE01, CHAR_TARGET_CYCLE02 }

	dlc06_vehicle_target_common( occupant_list, VEH_CYCLE, CYCLE_SPEED, CYCLE_SPEED_COOP, TEXT_TARGET_CYCLE, PATH_CYCLE_NAVP )

end

-- WHITE LINE FEVER ------------------------------------------------------------------------------------

function dlc06_target_convertible()

	local occupant_list = { CHAR_TARGET_CONVERTIBLE01, CHAR_TARGET_CONVERTIBLE02, CHAR_TARGET_CONVERTIBLE03 }

	dlc06_vehicle_target_common( occupant_list, VEH_CONVERTIBLE, CONVERTIBLE_SPEED, CONVERTIBLE_SPEED_COOP, TEXT_TARGET_CONVERTIBLE, PATH_CONVERTIBLE_NAVP )

end


-- PEEWEES BIG ADVENTURE -------------------------------------------------------------------------------

function dlc06_target_peewee()

	-- Kill the target if the Peewee is destroyed
	on_vehicle_destroyed("dlc06_kill_peewee_target", VEH_PEEWEE)

	-- This one is a barbershop guy on a peewee
	-- (try 3 times. If he still isn't in the peeweee, we're gonna have to let him die)
	local in_vehicle = vehicle_enter_teleport( CHAR_TARGET_PEEWEE, VEH_PEEWEE, 0 )
	if (not in_vehicle) then
		delay(0.5)
		in_vehicle = vehicle_enter_teleport( CHAR_TARGET_PEEWEE, VEH_PEEWEE, 0 )
	end
	if (not in_vehicle) then
		delay(0.5)
		in_vehicle = vehicle_enter_teleport( CHAR_TARGET_PEEWEE, VEH_PEEWEE, 0 )
	end
	if (not in_vehicle) then
		vehicle_detonate(VEH_PEEWEE)
		return
	end

	delay(0.5)

	-- Setup the vehicle
	vehicle_suppress_npc_exit(VEH_PEEWEE, true)
	set_unjackable_flag(VEH_PEEWEE, true)
	vehicle_set_untowable(VEH_PEEWEE, true)
	vehicle_disable_chase(VEH_PEEWEE, true)
	vehicle_set_allow_ram_ped(VEH_PEEWEE,true)
	vehicle_disable_flee(VEH_PEEWEE, true)

	-- Start messing w/ the peewee's speed
	local peewee_speed_thread = thread_new("dlc06_regulate_peewee_speed")
	mission_help_table_nag( TEXT_TARGET_PEEWEE )

	-- Do the figure 8, then a single loop, then another figure 8
	local looping_path = 
	{	PATH_PEEWEE_0, PATH_PEEWEE_2, PATH_PEEWEE_3, PATH_PEEWEE_4,
		PATH_PEEWEE_1, PATH_PEEWEE_4,
		PATH_PEEWEE_1, PATH_PEEWEE_2, PATH_PEEWEE_3, PATH_PEEWEE_4,
	}
	for i = 1, sizeof_table(looping_path), 1 do
		vehicle_pathfind_to( VEH_PEEWEE, looping_path[i], true, false)
	end

	-- Have the peewee escape
	vehicle_pathfind_to( VEH_PEEWEE, PATH_PEWEE_ESCAPE, true, true)
	vehicle_suppress_npc_exit(VEH_PEEWEE, false)
	npc_combat_enable(CHAR_TARGET_PEEWEE, false)

	-- Kill the peeweee speed thread
	thread_kill(peewee_speed_thread)

	-- The peewee rider runs back out and taunts the player.
	vehicle_exit( CHAR_TARGET_PEEWEE )

	--  speed, retry_on_failure, move_and_fire
	move_to_safe( CHAR_TARGET_PEEWEE, {"dlc06_$n363", "dlc06_$n364" }, 3, true, false)

	-- Turn toward the players
	if (character_exists(CHAR_TARGET_PEEWEE) and (not character_is_dead(CHAR_TARGET_PEEWEE))) then
		turn_to_orient(CHAR_TARGET_PEEWEE, "dlc06_$n364")
	end

	-- TAUNT!!!!!
	if (character_exists(CHAR_TARGET_PEEWEE) and (not character_is_dead(CHAR_TARGET_PEEWEE))) then
		local taunt_action_list = {"Insult A", "Insult B", "Insult C", "Insult D"}
		audio_play_persona_line( CHAR_TARGET_PEEWEE, "threat - melee attack missed", 3)
		action_play(CHAR_TARGET_PEEWEE, taunt_action_list[rand_int(1, sizeof_table(taunt_action_list))], nil, true, 0.95, true)
	end

	-- Run away
	if (character_exists(CHAR_TARGET_PEEWEE) and (not character_is_dead(CHAR_TARGET_PEEWEE))) then
		move_to_safe( CHAR_TARGET_PEEWEE, {"dlc06_$n363", "dlc06_$n228" }, 3, true, false)
	end

	-- EPIC FAIL!!!!
	if (character_exists(CHAR_TARGET_PEEWEE) and (not character_is_dead(CHAR_TARGET_PEEWEE))) then
		dlc06_failure_target_escaped()
	end

end

function dlc06_kill_peewee_target()

	if( character_exists(CHAR_TARGET_PEEWEE) and (not character_is_dead(CHAR_TARGET_PEEWEE)) ) then
		character_kill(CHAR_TARGET_PEEWEE)
	end

end


-- Continuously adjust the peewee's speed
function dlc06_regulate_peewee_speed()

	while(true) do

		thread_yield()

		local peewee_speeds = {5, 13, 13, 18, 18, 23, 23, 27}
		local old_speed = -1
	
		if ( vehicle_exists( VEH_PEEWEE ) and (not vehicle_is_destroyed( VEH_PEEWEE )) ) then

			-- Get a new speed for the peewee.
			local new_speed = peewee_speeds[rand_int(1,sizeof_table(peewee_speeds))] --(MIN_PEEWEE_SPEED, MAX_PEEWEE_SPEED)

			-- Make sure that the speed has changed
			while (new_speed == old_speed) do
				new_speed = peewee_speeds[rand_int(1,sizeof_table(peewee_speeds))]
				thread_yield()
			end

			-- Change the speed, then wait a bit
			vehicle_speed_override( VEH_PEEWEE, new_speed)
			old_speed = new_speed
			delay(rand_float(0.5,1.0))

		end

	end

end

-------------------------------------
-- The Mime car		              --
-------------------------------------

	-- List of mimes that can be spawned
		Available_mimes = {}

	-- List of mimes occupying specific staging areas.
		Staging_area_occupants = {}

	-- List of mimes charging the office area.
		Mimes_attacking_office = {}

	-- Current mime difficulty level
		Mime_current_difficulty = 1

	-- The max difficulty level
		Mime_max_difficulty = 1

	-- The number of living mimes
		Num_living_mimes = 0

	-- List of mimes throwing grenades
		Mimes_throwing = {}

	-- Is the mime car marked?
		Mime_car_marked = false

	-- Mime difficulty levels (6... last 2 for co-op only)
		Mime_difficulty_levels = 
		{
			[1] = 
			{
				["melee"] = "crowbar",
				["pistol"] = "beretta",
				["smg"] = "tec9",
				["thrown"] = "molotov",
				["office_pistol_chance"] = .15,
				["outside_smg_chance"] = .1,
				["max_mimes"] = 7,
				["max_office_mimes"] = 20,
				["duration_s"] = 20,
				["throws_per_minute"] = 10,
			},
			[2] = 
			{
				["melee"] = "knife",
				["pistol"] = "beretta",
				["smg"] = "tec9",
				["thrown"] = "molotov",
				["office_pistol_chance"] = .30,
				["outside_smg_chance"] = .3,
				["max_mimes"] = 9,
				["max_office_mimes"] = 3,
				["duration_s"] = 30,
				["throws_per_minute"] = 12,
			},
			[3] = 
			{
				["melee"] = "baseball_bat",
				["pistol"] = "glock",
				["smg"] = "tec9",
				["thrown"] = "pipe_bomb",
				["office_pistol_chance"] = .30,
				["outside_smg_chance"] = .5,
				["max_mimes"] = 11,
				["max_office_mimes"] = 4,
				["duration_s"] = 30,
				["throws_per_minute"] = 15,
			},
			[4] = 
			{
				["melee"] = "machete",
				["pistol"] = "magnum",
				["smg"] = "SKR-9",
				["thrown"] = "pipe_bomb",
				["office_pistol_chance"] = .45,
				["outside_smg_chance"] = .4,
				["max_mimes"] = 12,
				["max_office_mimes"] = 4,
				["duration_s"] = 40,
				["throws_per_minute"] = 20,
			},
			[5] = 
			{
				["melee"] = "samurai_sword",
				["pistol"] = "magnum",
				["smg"] = "SKR-9",
				["thrown"] = "grenade",
				["office_pistol_chance"] = .45,
				["outside_smg_chance"] = .6,
				["max_mimes"] = 12,
				["max_office_mimes"] = 4,
				["duration_s"] = 5,
				["throws_per_minute"] = 24,
			},
			[6] = 
			{
				["melee"] = "sledgehammer",
				["pistol"] = "desert eagle",
				["smg"] = "SKR-9",
				["thrown"] = "grenade",
				["office_pistol_chance"] = .60,
				["outside_smg_chance"] = .8,
				["max_mimes"] = 12,
				["max_office_mimes"] = 4,
				["duration_s"] = 5,
				["throws_per_minute"] = 30,
			},

		}

-- Test the mime attack
function dlc06_mime_car()

	-- Create the mime car group
	group_create(GROUP_MIME_CAR, true)

	-- Allow more corpses
	npc_max_corpses_override(NPC_MAX_CORPSES_OVERRIDE)

	-- Setup the mime car
	vehicle_disable_chase(VEH_MIME_CAR, true)
	vehicle_disable_flee(VEH_MIME_CAR, true)
	set_unjackable_flag(VEH_MIME_CAR, true)
	vehicle_prevent_explosion_fling(VEH_MIME_CAR, true)
	vehicle_infinite_mass(VEH_MIME_CAR, true)
	vehicle_ignore_repulsors(VEH_MIME_CAR, true)
	vehicle_set_allow_ram_ped(VEH_MIME_CAR,true)
	vehicle_set_script_hard_goto(VEH_MIME_CAR, true)

	-- Initially, the mime car has tons of hp and is invulnerable
	turn_invulnerable(VEH_MIME_CAR)
	set_max_hit_points(VEH_MIME_CAR, 250000)  -- Sniper does 2500 per shot.

	-- Place the driver in the seat
	vehicle_enter_teleport( CHAR_MIME_CAR_DRIVER, VEH_MIME_CAR, 0 )
	turn_invulnerable(CHAR_MIME_CAR_DRIVER)
	thread_yield()

	-- Setup his weapons
	inv_item_remove_all(CHAR_MIME_CAR_DRIVER)

	-- Drive to the top of the ramp
	vehicle_pathfind_to( VEH_MIME_CAR, PATH_MIME_CAR, true, true)

	-- Make the car vulnerable to player damage
	turn_invulnerable(VEH_MIME_CAR, true)

	-- Have the driver exit
	thread_new("dlc06_boss_mime")

	-- Add all mimes to the available list
	for mime, group in pairs(MIME_GROUPS) do
		Available_mimes[mime] = true	
	end

	-- Gryphon has a line here
	dlc06_play_eric_line_over_speaker("SHOOTRUNNER_1")

	-- Warn the players about the mimes
	mission_help_table(TEXT_MIME_CAR_DEFEND)

	-- Start spawning
	--thread_new("dlc06_spawn_mimes", 0, NAVP_MIME_STAGING_DRIVER)
	--thread_new("dlc06_spawn_mimes", 1, NAVP_MIME_STAGING_PASSENGER)
	thread_new("dlc06_spawn_mimes", 2, NAVP_MIME_STAGING_LEFT)
	thread_new("dlc06_spawn_mimes", 3, NAVP_MIME_STAGING_RIGHT)

	-- Some mimes attack the office
	thread_new("dlc06_mimes_attack_office")

	-- Sometimes mimes throw items
	thread_new("dlc06_mimes_throw")

	-- Set the max mime difficulty
	Mime_max_difficulty = sizeof_table(Mime_difficulty_levels)
	if (not IN_COOP) then
		Mime_max_difficulty = Mime_max_difficulty - 2
	end

	-- Slowly increase the difficulty
	thread_new("dlc06_control_mime_car_difficulty")

	-- Wait for the players to reach max difficulty or destroy the car
	while ( (Mime_current_difficulty ~= Mime_max_difficulty) and (not dlc06_mime_car_eliminated()) ) do
		thread_yield()
	end

	-- Tell the players to destroy the mime car if they haven't already
	if ( not dlc06_mime_car_eliminated() ) then
	
		-- Always add kill arrows. Only add minimap icons if the player is in position. (If out of position, icons
		-- will be added when the players get in position).
		ingame_effect_add_vehicle(VEH_MIME_CAR, INGAME_EFFECT_VEHICLE_KILL, SYNC_LOCAL)
		if (Player_in_required_position[LOCAL_PLAYER]) then
			minimap_icon_add_vehicle( VEH_MIME_CAR, MINIMAP_ICON_KILL, "", SYNC_LOCAL)
		end
		if ( IN_COOP ) then
			ingame_effect_add_vehicle(VEH_MIME_CAR, INGAME_EFFECT_VEHICLE_KILL, SYNC_REMOTE)
			if (Player_in_required_position[REMOTE_PLAYER]) then
				minimap_icon_add_vehicle( VEH_MIME_CAR, MINIMAP_ICON_KILL, "", SYNC_REMOTE)
			end

		end

		-- The mime car should be marked
		Mime_car_marked = true

		-- Tell the players to destroy the mime car
		mission_help_table(TEXT_MIME_CAR_DESTROY)

		-- Make sure that the vehicle's hit points are reasonable (sniper rifle does 2500 per shot)
		local max_hp = 15000 -- 6 shots
		if (IN_COOP) then
			max_hp = 30000 -- 12 shots
		end
		if (get_current_hit_points(VEH_MIME_CAR) > max_hp) then
			set_max_hit_points(VEH_MIME_CAR, max_hp, true)
		end

	end

	-- Wait for destruction of the mime car.
	while (not dlc06_mime_car_eliminated() ) do
		thread_yield()
	end

	-- Remove the mime car marker
	marker_remove_vehicle(VEH_MIME_CAR)
	Mime_car_marked = false

	-- Reset the max npc corpse override
	npc_max_corpses_reset()

end

function dlc06_release_mimes()

	release_to_world(GROUP_MIME_CAR)
	for mime, group in pairs(MIME_GROUPS) do
		release_to_world(group)		
	end

	delay(0.5)

	group_destroy(GROUP_MIME_CAR)
	for mime, group in pairs(MIME_GROUPS) do
		group_destroy(group)		
	end

	Num_living_mimes = 0

end

function dlc06_control_mime_car_difficulty()

	while (Mime_current_difficulty ~= Mime_max_difficulty) do
		
		delay(Mime_difficulty_levels[Mime_current_difficulty].duration_s)
		Mime_current_difficulty = Mime_current_difficulty + 1
	
	end

end

-- The boss mime
function dlc06_boss_mime()

	-- make the boss vulnerable to players only
	turn_invulnerable(CHAR_MIME_CAR_DRIVER, true)

	-- Boss mime exits, keep the car unjackable
	vehicle_exit(CHAR_MIME_CAR_DRIVER, true )

	-- Equip the boss mime
	dlc06_equip_mime_for_staging(CHAR_MIME_CAR_DRIVER)

	attack(CHAR_MIME_CAR_DRIVER)

end

-- Spawn mimes. 
--
-- The mimes begin in the limo, then pathfind to staging navpoints from which they'll attack the 
-- players.
--
-- seat: Seat of the limo from which to spawn.
-- staging_navp: Set of navpoints at which to stage the mimes before sending them into the office.
function dlc06_spawn_mimes(seat, staging_navp)

	-- Get an available (unspawned) mime
	local function get_available_mime()

		-- Make sure that we don't spawn too many mimes
		if (Num_living_mimes >= Mime_difficulty_levels[Mime_current_difficulty].max_mimes) then
			return nil
		end

		-- Return the first available mime
		for mime, available in pairs(Available_mimes) do
			if (available) then
				return mime
			end
		end

		-- No mimes available. Teardrop.
		return nil

	end

	-- Get an available staging navp
	local function get_staging_navp()

		-- Return the first unoccupied navpoint from the set
		for i, navp in pairs(staging_navp) do
	
			if (not Staging_area_occupants[navp]) then

				-- Exchange this navp with another to shuffle things up a bit for the next pass
				local j = rand_int(1, sizeof_table(staging_navp))
				staging_navp[i], staging_navp[j] = staging_navp[j], staging_navp[i]

				return navp
			end
		
		end

		-- All navpoints occupied, return nil
		return nil

	end

	-- Continously spawn mimes from this seat
	while( not dlc06_mime_car_eliminated() ) do

		-- If the mime car is on fire, don't spawn any more mimes
		local smoke, fire = vehicle_get_smoke_and_fire_state(VEH_MIME_CAR)
		if (fire) then
			return
		end

		-- Get an available mime and staging navpoint
		local mime = get_available_mime()
		local navp = get_staging_navp()

		-- If both are available, spawn the dude
		if ( (mime ~= nil) and (navp ~= nil) ) then

			-- This mime is no longer available
			Available_mimes[mime] = false

			Num_living_mimes = Num_living_mimes + 1

			-- Create the mime
			group_create_hidden(MIME_GROUPS[mime], true)

			-- Delay so that the group has time to load on the client
			delay(0.5)

			-- Only take damage from the player
			turn_invulnerable(mime, true)

			-- Don't attack until the staging point has been reached
			npc_combat_enable(mime, false)

			-- Setup his weapons
			dlc06_equip_mime_for_staging(mime)

			-- Add the on_death callback
			on_death("dlc06_mime_killed", mime)

			-- Place the mime in the seat
			if (dlc06_mime_car_eliminated()) then
				return
			end

			-- Teleport into the vehicle
			local vehicle_entered = vehicle_enter_teleport( mime, VEH_MIME_CAR, seat )
			thread_yield()

			-- The mime didn't show up for some reason... kill him off.
			if (not vehicle_entered) then

				group_destroy(MIME_GROUPS[mime])

				thread_yield()

				Available_mimes[mime] = true
				Num_living_mimes = Num_living_mimes - 1
				on_death("", mime)

			else
				-- Show the mime
				group_show(MIME_GROUPS[mime])			
				delay(0.2)

				-- Exit the vehicle (don't teleport, keep unenterable, don't dive)
				vehicle_exit_do(mime, false, true, false)
				local exit_wait_s = 0.0
				local max_wait_s = 3.0
				while ( (not vehicle_exit_check_done(mime)) and (exit_wait_s < max_wait_s) ) do
					exit_wait_s = exit_wait_s + 0.2
					delay(0.2)
				end

				-- Couldn't enter the vehicle for some reason. Abort.
				if ( exit_wait_s >= max_wait_s ) then
					group_destroy(MIME_GROUPS[mime])

					thread_yield()

					Available_mimes[mime] = true
					Num_living_mimes = Num_living_mimes - 1
					on_death("", mime)
				end

			end

			-- Make sure that the character still exists before moving on.
			if ( character_exists(mime) and (not character_is_dead(mime)) ) then

				-- Move to the staging navpoint (run, retry on failure, shoot while running)
				move_to_safe( mime, navp, 2, false, false )

				-- Make sure that the character still exists
				if ( character_exists(mime) and (not character_is_dead(mime)) ) then

					-- Leash to the navp
					npc_leash_to_nav(mime, navp, 1 )
					npc_leash_set_unbreakable( mime, true )

					-- Attack the player
					npc_combat_enable(mime, true)
					attack(mime)
					
					Staging_area_occupants[navp] = mime

					-- Wait a little bit
					delay(rand_float(0.5,1.5))

				end

			end

		end

		thread_yield()

	end
	
end

-- Some mimes attack the office
function dlc06_mimes_attack_office()

	-- Can another mime join the office attack?
	local function can_attack_office() 

		-- Office attackers are drawn from the pool of mimes in the staging area
		if ( sizeof_table(Staging_area_occupants) == 0 ) then
			return false
		end

		-- Let all mimes attack the office as soon as their car is eliminated
		if (dlc06_mime_car_eliminated()) then
			return true
		end

		-- Get the default max # of attackers
		local max_attackers = Mime_difficulty_levels[Mime_current_difficulty].max_office_mimes

		-- If either or both players are out of the required area, increase the amount of mimes that can rush
		-- the office.
		local alpha = 0

		-- All players out of co-op area, let 50% of mimes normally kept in the staging area attack the office
		if ( ((not IN_COOP) or (not Player_in_required_position[REMOTE_PLAYER])) and (not Player_in_required_position[LOCAL_PLAYER]) ) then
			alpha = 0.5

		-- If only one player is out of the required area, 25%
		elseif ( (not Player_in_required_position[REMOTE_PLAYER]) or (not Player_in_required_position[LOCAL_PLAYER]) ) then
			alpha = 0.25
		end
		max_attackers = max_attackers + alpha * (Mime_difficulty_levels[Mime_current_difficulty].max_mimes - max_attackers)

		if (sizeof_table(Mimes_attacking_office) >= max_attackers) then
			return false
		end

		return true

	end

	-- Have more mimes join the attack whenever possible
	while ( true ) do

		-- Wait until a mime is available
		while( not can_attack_office() ) do
			thread_yield()
		end

		-- Get the set of all spawning navp at which a mime is available
		local available_navp = {}
		local num_mimes = 0
		for navp, mime in pairs(Staging_area_occupants) do

			-- Is there an attacker at this staging point who isn't throwing?
			if ( (mime ~= nil) and character_exists(mime) and (not character_is_dead(mime)) and (not Mimes_throwing[mime]) ) then

				num_mimes = num_mimes + 1
				available_navp[num_mimes] = navp

			end

		end

		-- Try to have a mime attack.
		if (num_mimes > 0) then
			local navp = available_navp[rand_int(1, num_mimes)]
			local mime = Staging_area_occupants[navp]
			Staging_area_occupants[navp] = nil
			Mimes_attacking_office[mime] = thread_new("dlc06_mime_attack_office", mime)
		end

		thread_yield()

		-- Let the thread die if the mime car is eliminated and all mimes are dead.
		if (Num_living_mimes == 0 and dlc06_mime_car_eliminated()) then
			return
		end

	end

end

function dlc06_mime_car_eliminated()

	return (vehicle_is_destroyed(VEH_MIME_CAR) or (not vehicle_exists(VEH_MIME_CAR)))

end

function dlc06_mime_attack_office(mime)

	-- Equip the mime for attacking the office
	dlc06_equip_mime_for_office( mime )

	-- Move into the office (run, retry on failure, shoot while running)
	npc_leash_remove( mime )

	-- Head up to the office, stop and attack any player that gets too close
	for i = 1, sizeof_table(PATH_MIME_NAVP), 1 do

		-- Move along the path. run, retry on fail, shoot while moving
		move_to_safe( mime, PATH_MIME_NAVP[i], 2, true, false )

		-- Make sure that the mime still exists
		if ( character_exists(mime) and (not character_is_dead(mime)) ) then
			if (get_dist_closest_player_to_object(mime) < 5) then
				attack(mime)
				return
			end
		else
			return
		end
	end

	-- Mime has reached the end of the path. Attack!
	attack(mime)

end

-- Mimes occasionally throw items at the players
function dlc06_mimes_throw()

	-- Get a mime to have throw
	local function get_thrower()

		local mimes = {}
		local i = 0
		for navp, mime in pairs(Staging_area_occupants) do
			i = i + 1
			mimes[i] = mime
		end

		if (i == 0) then
			return nil
		else
			return mimes[rand_int(1,i)]
		end

	end

	while(not dlc06_mime_car_eliminated()) do

		-- Find a mime to have throw
		local mime = get_thrower()

		-- Have the mime throw something
		if (mime) then
			Mimes_throwing[mime] = thread_new("dlc06_mime_throw",mime)
		end

		-- Determine how long to wait between throws:
		local delay_between_throws = 60 / Mime_difficulty_levels[Mime_current_difficulty].throws_per_minute 

		delay(delay_between_throws)

	end

end

-- Have a mime throw something at the players
function dlc06_mime_throw(mime)

	local target_noise = 0.2
	local speed_noise = 0.15
	local angle_noise = 0.15

	local target = ""
	local dist = 1000
	local message = ""

	if(rand_int(1,2) == 1) then
		-- Sometimes pick a target near the player
		for i,navpoint in pairs(NAVP_MIME_THROW) do
			local cur_dist = get_dist_closest_player_to_object(navpoint)
			cur_dist = cur_dist * rand_float(1.0 - target_noise, 1.0 + target_noise)
			if (cur_dist < dist) then
				dist = cur_dist
				target = navpoint
			end
		end
	else
		-- Othertimes, a random target is selected
		target = NAVP_MIME_THROW[rand_int(1,sizeof_table(NAVP_MIME_THROW))]
	end
	dist = get_dist(target,mime)

	local angle = 22 * rand_float(1.0 - angle_noise, 1.0 + angle_noise)
	local speed = dist

	local  alpha = (dist - 7 / 9)

	speed = 7 + alpha * 4.5

	speed = speed  * rand_float(1.0 - speed_noise, 1.0 + speed_noise)
	
	-- Equip the item:
	dlc06_equip_mime_for_throw(mime)

	force_throw(mime, target, angle, speed)
	
	if ( character_exists(mime) and (not character_is_dead(mime)) ) then
			-- Reequip the proper item
			dlc06_equip_mime_for_staging(mime)
	end

	Mimes_throwing[mime] = nil

end

function dlc06_mime_killed(mime)
	
	-- Make this mime available again
	release_to_world(MIME_GROUPS[mime])
	Available_mimes[mime] = true
	Num_living_mimes = Num_living_mimes - 1

	-- If the mime occupied a staging area, mark that area as free
	for navp, occupant in pairs(Staging_area_occupants) do
		if (occupant == mime) then
			Staging_area_occupants[navp] = nil
			break
		end
	end

	-- If the mime is attacking the office, remove him from that set
	if (Mimes_attacking_office[mime]) then
		thread_kill(Mimes_attacking_office[mime])
		Mimes_attacking_office[mime] = nil
	end

	-- If the mime is throwing, remove him from that set
	if (Mimes_throwing[mime]) then
		thread_kill(Mimes_throwing[mime])
		Mimes_throwing[mime] = nil
	end

end

function dlc06_equip_mime_for_staging(mime)

	-- Convenience variable
	local difficulty_info =  Mime_difficulty_levels[Mime_current_difficulty]

	-- Determine what type of weapon to equip
	local roll = rand_float(0,1)
	local weapon = difficulty_info.pistol
	if (roll < difficulty_info.outside_smg_chance) then
		weapon = difficulty_info.smg
	end

	-- Add the weapon
	dlc06_equip_mime_common(mime, weapon)

end

function dlc06_equip_mime_for_office(mime)

	-- Convenience variable
	local difficulty_info =  Mime_difficulty_levels[Mime_current_difficulty]

	-- Determine what type of weapon to equip
	local roll = rand_float(0,1)
	local weapon = difficulty_info.melee
	if (roll < difficulty_info.office_pistol_chance) then
		weapon = difficulty_info.pistol
	end

	-- Add the weapon
	dlc06_equip_mime_common(mime, weapon)

end

function dlc06_equip_mime_for_throw(mime)

	-- Convenience variable
	local weapon = Mime_difficulty_levels[Mime_current_difficulty].thrown

	-- Add the weapon
	dlc06_equip_mime_common(mime, weapon)
	inv_item_equip(weapon, mime)

end

function dlc06_equip_mime_common(mime, weapon)

	-- Setup his weapons
	inv_item_remove_all(mime)
	inv_item_add(weapon, 1, mime)

end

-------------------------------
--     The Masako Show Up    --
-------------------------------

function dlc06_launch_ultor_attack()
	group_create( GROUP_ULTOR_ATTACK )
	for i, npc in pairs(ULTOR_BEAR_CREW01) do
		on_death( "dlc06_ultor_attacker_killed", npc )
		marker_add_npc( npc, MINIMAP_ICON_KILL, Dlc06_npc_kill_icon, SYNC_ALL)
		vehicle_enter_teleport( npc, VEH_ULTOR_BEAR01, ( i - 1 ) )
	end
	for i, npc in pairs(ULTOR_BEAR_CREW02) do
		marker_add_npc( npc, MINIMAP_ICON_KILL, Dlc06_npc_kill_icon, SYNC_ALL)
		on_death( "dlc06_ultor_attacker_killed", npc )
		vehicle_enter_teleport( npc, VEH_ULTOR_BEAR02, ( i - 1 ) )
	end
	mission_help_table( TEXT_HELP_ULTOR_COMING )
	thread_new( "dlc06_ultor_bear_pathfind01" ) 
	delay(4)
	thread_new( "dlc06_ultor_bear_pathfind02" )
	trigger_enable( TRIGGER_ULTOR_REACH_ERIC, true )
	on_trigger( "dlc06_ultor_reach_eric", TRIGGER_ULTOR_REACH_ERIC )

	local total_num_ultor = sizeof_table(ULTOR_BEAR_CREW01) + sizeof_table(ULTOR_BEAR_CREW02)


	-- Block until a single attacker remains, then launch the police response
	while (Ultor_attackers_killed < total_num_ultor - 1) do
		thread_yield()
	end
	thread_new( "dlc06_launch_police_response" )

	-- Block until all Ultor attackers have been killed
	while (Ultor_attackers_killed < total_num_ultor) do
		thread_yield()
	end
end

function dlc06_ultor_bear_pathfind01()
	vehicle_pathfind_to( VEH_ULTOR_BEAR01, PATH_ULTOR_ATTACK, true, true)
	for i, npc in pairs(ULTOR_BEAR_CREW01) do
		thread_new( "dlc06_ultor_run_up1", npc ) 
	end

	-- Eric reminds the player to keep him alive
	dlc06_play_eric_line_over_speaker("MASAKOATK_2")

end

function dlc06_ultor_bear_pathfind02()
	vehicle_pathfind_to( VEH_ULTOR_BEAR02, PATH_ULTOR_ATTACK02, true, true)
	for i, npc in pairs(ULTOR_BEAR_CREW02) do
		thread_new( "dlc06_ultor_run_up2", npc )
	end
end

function dlc06_ultor_run_up1( dude )
	vehicle_exit( dude )
	npc_unholster_best_weapon( dude )
	move_to_safe( dude, PATH_ULTOR_FOOT_ATTACK, 2, true, true )
end

function dlc06_ultor_run_up2( dude )
	vehicle_exit( dude )
	npc_unholster_best_weapon( dude )
	move_to_safe( dude, PATH_ULTOR_FOOT_ATTACK2, 2, true, true )
end

function dlc06_ultor_attacker_killed( ultor )
	Ultor_attackers_killed = Ultor_attackers_killed + 1
	marker_remove_npc( ultor, SYNC_ALL )
end

function dlc06_ultor_reach_eric( activator )
	-- we need to see if any of the ultor attackers have reached the Lighthouse.
	for i, npc in pairs(ULTOR_BEAR_CREW01) do
		if ( activator == npc ) then
			dlc06_failure_eric_killed()
		end
	end
	for i, npc in pairs(ULTOR_BEAR_CREW02) do
		if ( activator == npc ) then
			dlc06_failure_eric_killed()
		end
	end
end

--------------------------------------
-- Race For Your Life Charlie Brown --
--------------------------------------

-- Send Eric inside the lighthouse
function dlc06_send_eric_inside()
	
	-- Make eric stop using the binoculars
	thread_kill(Thread_eric_binoculars)
	thread_yield()
	clear_animation_state(CHAR_ERIC)

	move_to_safe( CHAR_ERIC, NAV_ERIC_LEAVE01, 2, true, false ) 
end

-- Send Eric from the lighthouse to the boardwalk
function dlc06_send_eric_down()

	-- Eric tells the players to meet him:
	dlc06_play_eric_line_over_speaker("FINISHED")

	-- Let the players leave the rooftop
	dlc06_release_players_from_required_trigger(TRIGGER_ROOFTOP_AREA)

	-- Tell the players to meet Eric
	mission_help_table( TEXT_MEET_ERIC )

	-- Activate the meet-Eric Trigger
	on_trigger("dlc06_meet_eric_trigger", TRIGGER_MEET_ERIC)
	trigger_enable(TRIGGER_MEET_ERIC, true)
	marker_add_trigger( TRIGGER_MEET_ERIC, MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL )

	-- Teleport eric outside
	teleport( CHAR_ERIC, NAV_ERIC_LEAVE02 )

	-- Eric runs to his vehicle
	move_to_safe( CHAR_ERIC, PATH_ERIC_TO_CAR, 2, true, false)

	-- Eric enters the vehicle
	set_unjackable_flag(VEH_ERICS_DEF_RIDE, false)
	delay(0.25)

		-- Try to enter normally twice. If that fails, just teleport in
		if (not vehicle_enter( CHAR_ERIC, VEH_ERICS_DEF_RIDE, 0 ) ) 
			then
			delay(0.5)
			if (not vehicle_enter( CHAR_ERIC, VEH_ERICS_DEF_RIDE, 0 ) ) then
				delay(0.25)
				vehicle_enter_teleport( CHAR_ERIC, VEH_ERICS_DEF_RIDE, 0 )
			end
		end
	delay(0.25)
	set_unjackable_flag(VEH_ERICS_DEF_RIDE, true)

	-- Let Eric's ride be vulnerable again
	dlc06_set_vehicle_invulnerable(VEH_ERICS_DEF_RIDE, false)

	-- Eric drives down to meet the player
	vehicle_pathfind_to( VEH_ERICS_DEF_RIDE, PATH_ERIC, true, true)

end


Meet_eric_triggered = false
function dlc06_meet_eric_trigger(triggerer, trigger)

	if (Meet_eric_triggered) then
		return
	else
		Meet_eric_triggered = true
	end

	local function mission_won()

		if (get_dist(CHAR_ERIC,trigger) > 5) then
			return false
		end

		if (get_dist_closest_player_to_object(trigger) > 5) then
			return false
		end

		return true

	end

	-- Wait for Eric and at least one player to be near the trigger
	if (not mission_won()) then
		mission_help_table(TEXT_WAIT_FOR_ERIC)

		while (not mission_won()) do
			thread_yield()
		end
	end

	-- Winner, winner, chicken dinner!
	marker_remove_trigger(trigger)
	mission_end_success( MISSION_NAME, CUTSCENE_OUT )	
end

function dlc06_launch_police_response()

	group_create( GROUP_POLICE, true )

	vehicle_enter_group_teleport(POLICE_CREW01, VEH_POLICE01)
	vehicle_enter_group_teleport(POLICE_CREW02, VEH_POLICE02)
	vehicle_enter_group_teleport(SWAT_CREW01, VEH_SWAT)

	thread_new( "dlc06_police01_drive" )
	thread_new( "dlc06_police02_drive" )
	thread_new( "dlc06_swat01_drive" )
end

function dlc06_police01_drive()
	vehicle_pathfind_to( VEH_POLICE01, PATH_POLICE01, true, true)
	for i, npc in pairs(POLICE_CREW01) do
		thread_new( "dlc06_check_door01", npc )
	end
end

function dlc06_police02_drive()
	vehicle_pathfind_to( VEH_POLICE02, PATH_POLICE02, true, true)
	for i, npc in pairs(POLICE_CREW02) do
		thread_new( "dlc06_check_door01", npc )
	end
end

function dlc06_swat01_drive()
	vehicle_pathfind_to( VEH_SWAT, PATH_SWAT01, true, true)
	for i, npc in pairs(SWAT_CREW01) do
		thread_new( "dlc06_check_door01", npc )		
	end
end

function dlc06_check_door01 ( copper )
	vehicle_exit( copper )
	move_to_safe( copper, NAV_POLICE01, 2, true, true)
	while ( not Door01_open ) do
		if get_dist( copper, NAV_POLICE01 ) < 2 then
			door_open( POLICE_DOOR01 )
			Door01_open = true
		end
		thread_yield()
	end 
	move_to_safe( copper, NAV_POLICE02, 2, true, true)
	while ( not Door02_open ) do
		if get_dist( copper, NAV_POLICE02 ) < 2 then
			door_open( POLICE_DOOR02 )
			Door02_open = true
		end
		thread_yield()
	end
	move_to_safe( copper, NAV_POLICE03, 2, true, true)
	attack_closest_player( copper, false )
end

------------------------
-- Cleanup Stuff Here --
------------------------

function dlc06_cleanup()

	-- Reenable chainsaw usage
	chainsaw_enable()

	-- Release Ronin spawning restrictions
	character_slots_clear_caps()

	-- Unrestrict action node spawning
	action_nodes_restrict_spawning(false)

	-- Remove effects
	for i, handle in pairs(Effect_handles) do
		effect_stop(handle)
	end

	-- Reset the max npc corpse override
	npc_max_corpses_reset()

	-- Let the weather do as it likes
	set_weather(-1,false)

	-- reset doors
	door_lock(MM_OFFICE_DOOR_1,false)
	door_lock(MM_OFFICE_DOOR_2,false)

	--Reenable recruiting
	party_set_recruitable(true)

	-- Cleanup mission here
	--teleport_coop( NAVP_LOCAL_START, NAVP_REMOTE_START )
	notoriety_force_no_spawn( "Police", false )
	notoriety_reset( "Police" )
	notoriety_reset( "Ronin" )
	set_cops_shooting_from_vehicles( false )

	-- Take back the temporary weapons
	if (Temp_weapons_given) then
		inv_weapon_remove_temporary( LOCAL_PLAYER, SNIPER_RIFLE )
		if ( coop_is_active() ) then
			inv_weapon_remove_temporary( REMOTE_PLAYER, SNIPER_RIFLE ) 
		end
	end

	-- Turn off timers
	hud_timer_stop(PLAYER_TIMER_INDEX[LOCAL_PLAYER])
	hud_timer_stop(PLAYER_TIMER_INDEX[REMOTE_PLAYER])

	-- Remove vehicle markers
	marker_remove_vehicle(VEH_MIME_CAR)

	-- Reenable the branded shop
	shop_enable( "MAR Branded", true )

end


function dlc06_success()
end

-----------------------------------------------------------------------------------
--																											--
-- Functions used to send players to a specific locations, possibly using			--
-- breadcrumbs.																						--
--																											--
-----------------------------------------------------------------------------------

-- Global variables utilized by the send_to_location functions
Dlc06_location_reached				= false
Dlc06_current_trigger				= 1
Dlc06_breadcrumb_triggers			= {}
Dlc06_breadcrumb_helptext			= {}
Dlc06_breadcrumb_effect				= ""
Dlc06_breadcrumb_functions			= {}
Dlc06_breadcrumb_trigger_checks	= {}
Dlc06_no_gps							= false
Dlc06_wait_for_partner				= false

function dlc06_send_to_location(trigger, effect, helptext, no_gps, wait_for_partner)

	Dlc06_location_reached = false
	Dlc06_breadcrumb_effect = false
	if (effect) then
		Dlc06_breadcrumb_effect = effect
	end
	Dlc06_current_trigger = 1
	Dlc06_breadcrumb_triggers = {}
	Dlc06_breadcrumb_helptext = {}
	Dlc06_no_gps = no_gps
	Dlc06_wait_for_partner = wait_for_partner


	-- Place triggers into a global table variable
	if ((type(trigger) == "table")) then
		Dlc06_breadcrumb_triggers = trigger
	else
		Dlc06_breadcrumb_triggers[1] = trigger
	end

	-- Same for helptext
	if ((type(helptext) == "table")) then
		Dlc06_breadcrumb_helptext = helptext
	else
		Dlc06_breadcrumb_helptext[1] = helptext
	end

	-- Same for whether we should use breadcrumbs at the tr

	-- Add callbacks for all triggers, special callback for final trigger
	local num_breadcrumbs = sizeof_table(Dlc06_breadcrumb_triggers)
	for i,breadcrumb in pairs(Dlc06_breadcrumb_triggers) do
		trigger_enable(breadcrumb,true)
		if (i == num_breadcrumbs) then
			on_trigger("dlc06_toggle_location_reached",breadcrumb)
			trigger_set_delay_between_activations(breadcrumb, 0)
		else
			on_trigger("dlc06_breadcrumb_reached", breadcrumb)
		end
	end

	if (effect) then
		marker_add_trigger(Dlc06_breadcrumb_triggers[Dlc06_current_trigger], MINIMAP_ICON_LOCATION, effect, SYNC_ALL)
		if (not Dlc06_no_gps) then
			mission_waypoint_add( Dlc06_breadcrumb_triggers[Dlc06_current_trigger], SYNC_ALL )
		end
	end

	-- Display helptext
	if (Dlc06_breadcrumb_helptext[1]) then
		mission_help_table(Dlc06_breadcrumb_helptext[1])
	end

	-- Wait for player to arrive at the location
	while (not Dlc06_location_reached) do
		thread_yield()
	end

	Dlc06_location_reached = false
end

function dlc06_set_breadcrumb_functions(function_list)

	Dlc06_breadcrumb_functions = function_list

end

-- Assigns trigger checks.  The list should have the trigger name as the key and a function func( triggerer, trigger ) that
-- returns true if the trigger can be activated as the value.  Or, if trigger_checks is just one function, then it will be
-- used for all the triggers
--
function dlc06_set_breadcrumb_trigger_checks( trigger_check )

	if type( trigger_check ) == "table" then
		Dlc06_breadcrumb_trigger_checks = trigger_check
	else
		Dlc06_breadcrumb_trigger_checks.all_triggers = trigger_check
	end

end

function dlc06_breadcrumb_reached(triggerer, trigger)

	-- Check whether we can trigger this
	local trigger_check = Dlc06_breadcrumb_trigger_checks[trigger] or Dlc06_breadcrumb_trigger_checks.all_triggers

	if trigger_check and not trigger_check( triggerer, trigger ) then
		return
	end

 	-- Disable all breadcrumbs up to and including the one that we just hit
	for i = Dlc06_current_trigger, sizeof_table(Dlc06_breadcrumb_triggers) do

		-- Convenience variable for the breadcrumb trigger that we're currently dealing with
		local breadcrumb = Dlc06_breadcrumb_triggers[i]

		-- Disable the breadcrumb trigger
		trigger_enable(breadcrumb, false)
		on_trigger("", breadcrumb)
		marker_remove_trigger(breadcrumb, SYNC_ALL)

		-- Increment the current trigger
		Dlc06_current_trigger = i+1

		-- If the breadcrumb has an associated function, call it in a new thread
		if (Dlc06_breadcrumb_functions[breadcrumb]) then
			thread_new(Dlc06_breadcrumb_functions[breadcrumb])
		end

		-- If the current trigger is the activated trigger, then break
		if(Dlc06_breadcrumb_triggers[i] == trigger) then
			break
		end

	end

	-- Display helptext for the just-hit trigger.
	if (Dlc06_breadcrumb_helptext[trigger]) then
		mission_help_table(Dlc06_breadcrumb_helptext[trigger])
	end

	mission_waypoint_remove()

	-- Add an effect to the next trigger
	if (Dlc06_breadcrumb_effect) then
		marker_add_trigger(Dlc06_breadcrumb_triggers[Dlc06_current_trigger], MINIMAP_ICON_LOCATION, Dlc06_breadcrumb_effect, SYNC_ALL)
		if (not Dlc06_no_gps) then
			mission_waypoint_add( Dlc06_breadcrumb_triggers[Dlc06_current_trigger], SYNC_ALL )
		end
	end
end

function dlc06_toggle_location_reached(triggerer, trigger)

	-- Check whether we can trigger this
	local trigger_check = Dlc06_breadcrumb_trigger_checks[trigger] or Dlc06_breadcrumb_trigger_checks.all_triggers

	if trigger_check and not trigger_check( triggerer, trigger ) then
		return
	end

	-- Maybe wait for a partner
	if ( IN_COOP and Dlc06_wait_for_partner and (get_dist(trigger, OTHER_PLAYER[triggerer]) > 5) ) then
		mission_help_table_nag(TEXT_WAIT_FOR_PARTNER)
		return 
	end

	-- disable all breadcrumb triggers
	for i = Dlc06_current_trigger, sizeof_table(Dlc06_breadcrumb_triggers) do
		local breadcrumb = Dlc06_breadcrumb_triggers[i]
		trigger_enable(breadcrumb, false)
		on_trigger("", breadcrumb)
		marker_remove_trigger(breadcrumb, SYNC_ALL)

		-- Call any remaining breadcrumb functions
		if (Dlc06_breadcrumb_functions[breadcrumb]) then
			thread_new(Dlc06_breadcrumb_functions[breadcrumb])
		end

	end

	Dlc06_location_reached = true

	-- Reset the breadcrumb function list
	Dlc06_breadcrumb_functions = {}

	-- Reset the breadcrumb trigger check list
	Dlc06_breadcrumb_trigger_checks = {}

	mission_waypoint_remove()

end

-----------------------------------------------------------------------------------
--																											--
-- Functions used to keep players in a specific trigger.									--
--																											--
-----------------------------------------------------------------------------------

-- Keep the players in the specified trigger. Assumes that the players begin in that
-- trigger.
function dlc06_keep_players_in_trigger(trigger, absent_fail_time_s, fail_function_name)
	Thread_keep_players_in_trigger = thread_new("dlc06_keep_players_in_trigger_helper", trigger, absent_fail_time_s, fail_function_name)
end


-- Keep the players in the specified trigger. Assumes that the players begin in that
-- trigger.
function dlc06_keep_players_in_trigger_helper(trigger, absent_fail_time_s, fail_function_name)

	-- Add trigger callback functions
	on_trigger("dlc06_required_area_entered", trigger)
	on_trigger_exit("dlc06_required_area_exited", trigger)

	-- Enable the trigger
	trigger_enable(trigger, true)
	trigger_set_delay_between_activations(trigger, 0)

	-- Assume that players begin in the trigger
	Player_in_required_position[LOCAL_PLAYER] = true
	Player_in_required_position[REMOTE_PLAYER] = true

	-- Were the players in position
	local player_was_in_required_position = {[LOCAL_PLAYER] = true, [REMOTE_PLAYER] = true}

	-- Update player prompts
	local function update_prompts(player)

		-- Convenience variable
		local sync = PLAYER_SYNC[player]

		-- Handle a player entering the required area
		if ( Player_in_required_position[player] and (not player_was_in_required_position[player]) ) then
			marker_remove_trigger(trigger, sync)
			hud_timer_stop(PLAYER_TIMER_INDEX[player])

			-- Add target minimap icons when the player enters the area
			dlc06_enable_target_kill_icons(sync, true)

		end

		-- Handle a player leaving the required area
		if ( (not Player_in_required_position[player]) and player_was_in_required_position[player] ) then
			marker_add_trigger( trigger, MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, sync )
			mission_help_table_nag(TEXT_REQUIRED_AREA_EXITED, "", "", sync)

			-- Start the failure timer (index, time_ms, expire callback, enable sound, sync type)
			hud_timer_set(PLAYER_TIMER_INDEX[player], absent_fail_time_s * 1000, fail_function_name, true, sync)

			-- Remove target minimap icons while the player is out of the area
			dlc06_enable_target_kill_icons(sync, false)

		end

		player_was_in_required_position[player] = Player_in_required_position[player]

	end

	while (true) do
		update_prompts(LOCAL_PLAYER)
		if (IN_COOP) then
			update_prompts(REMOTE_PLAYER)
		end

		thread_yield()
	end

end

-- Release players from a required trigger
function dlc06_release_players_from_required_trigger(trigger)

	-- Kill the thread that is keeping the players in the trigger
	if ( not thread_check_done(Thread_keep_players_in_trigger) ) then
		thread_kill(Thread_keep_players_in_trigger)
	end

	-- Remove trigger callback functions
	on_trigger("", trigger)
	on_trigger_exit("", trigger)

	-- Disable the trigger
	trigger_enable(trigger, false)

	-- Stop the hud timers
	hud_timer_stop(PLAYER_TIMER_INDEX[LOCAL_PLAYER])
	hud_timer_stop(PLAYER_TIMER_INDEX[REMOTE_PLAYER])

	-- Remove the trigger's marker
	marker_remove_trigger(trigger)

	-- Reenable target minimap icons if needed
	if (not Player_in_required_position[LOCAL_PLAYER]) then

		-- Add target minimap icons when the player enters the area
		dlc06_enable_target_kill_icons(PLAYER_SYNC[LOCAL_PLAYER], true)

	end

	if ( IN_COOP and (not Player_in_required_position[REMOTE_PLAYER]) ) then

		-- Add target minimap icons when the player enters the area
		dlc06_enable_target_kill_icons(PLAYER_SYNC[REMOTE_PLAYER], true)

	end


end

-- Remove or add npc target minimap kill icons
function dlc06_enable_target_kill_icons(sync, enable)

	if ( not dlc06_mime_car_eliminated() and Mime_car_marked ) then
	
		if (enable) then
			minimap_icon_add_vehicle(VEH_MIME_CAR, MINIMAP_ICON_KILL, "", sync)
		else
			minimap_icon_remove_vehicle(VEH_MIME_CAR, sync)
		end
			
	end

	for npc, eliminated in pairs(Target_eliminated) do
		if ( not eliminated and (not Unmarked_targets[npc] ) ) then

			if (enable) then
				minimap_icon_add_npc(npc, MINIMAP_ICON_KILL, "", sync)
			else
				minimap_icon_remove_npc(npc, sync)
			end
		end
	end		

end

-- Called when a player enters a required area
function dlc06_required_area_entered( triggerer )
	Player_in_required_position[triggerer] = true
end

-- Called when a player exits a required area
function dlc06_required_area_exited( triggerer )
	Player_in_required_position[triggerer] = false
end

-----------------------
-- Failure Functions --
-----------------------

function dlc06_failure_target_escaped()
	mission_end_failure( "dlc06" , TEXT_FAIL_TARGET_ESCAPED )
end

function dlc06_failure_eric_killed()
	mission_end_failure( "dlc06" , TEXT_FAIL_ERIC_KILLED )
end

function dlc06_failure_eric_vehicle_destroyed()
	mission_end_failure( "dlc06", TEXT_FAIL_ERIC_VEHICLE_DESTROYED )
end

function dlc06_failure_left_rooftop()
	mission_end_failure( "dlc06" , TEXT_FAIL_LEFT_ROOFTOPS)
end

function dlc06_failure_left_office()
	mission_end_failure( "dlc06" , TEXT_FAIL_LEFT_OFFICE)
end

-----------------------------------------------------------------------------------
--																											--
-- Utility functions																					--
--																											--
-----------------------------------------------------------------------------------

-- Give the players their temporary sniper rifles
function dlc06_give_sniper_rifles()

	-- Only give temp weapons once.
	if (Temp_weapons_given) then
		return
	end

	inv_weapon_add_temporary( LOCAL_PLAYER, SNIPER_RIFLE, 1, true, true )
	if ( coop_is_active() ) then
		inv_weapon_add_temporary( REMOTE_PLAYER, SNIPER_RIFLE, 1, true, true ) 
	end
   inv_item_equip( SNIPER_RIFLE, LOCAL_PLAYER )
   if ( coop_is_active() ) then
      inv_item_equip( SNIPER_RIFLE, REMOTE_PLAYER )
   end

	Temp_weapons_given = true

end

-- Shuffle the entries in a table
-- 
-- table: The table whose entries we want shuffled.
--
function dlc06_shuffle_table( table )

   -- Get the number of entries in the table
   local table_size = sizeof_table(table)

   -- Loop over all elements in the table
   for index = 1, table_size, 1 do
      
      -- Randomly select another entry in the table
      local other_index = rand_int(1, table_size)

      -- Swap the current entry with the other entry
      if ( index ~= other_index ) then
         table[index], table[other_index] = table[other_index], table[index]
      end
   end

end

function dlc06_play_eric_line_over_speaker(line_suffix)

	-- Wait until previous lines have finished playing
	while (not thread_check_done(Thread_eric_audio)) do 
		thread_yield()
	end

	-- Start playing the new line
	Thread_eric_audio = thread_new("dlc06_play_eric_line_helper", line_suffix)

end

function dlc06_play_eric_line_helper(line_suffix)
	
	audio_play_for_character("GRYPHON_DLC0203_" .. line_suffix, LOCAL_PLAYER, "voice", false, true, nil, nil, true)	

	-- Make sure that there is a reasonable gap between the audio.
	delay(2.0)
end

function dlc06_play_forced_incoming_call(conversation)

	-- Have the phone ring
	audio_play(CELLPHONE_INCOMING, "foley", true)

	-- Answer the phone
	if (not character_is_ready_to_speak(LOCAL_PLAYER)) then
		return
	end
   cellphone_animate_start_do()
   delay(0.5)

	-- Play the conversation
	if (not character_is_ready_to_speak(LOCAL_PLAYER)) then
		cellphone_animate_stop_do()
		return
	end
	audio_play_conversation(conversation, INCOMING_CALL)

	-- Put up the phone
	cellphone_animate_stop_do()

end

-- Is a sphere centered on a navpoint in any player's fov?
--
function dlc06_navpoint_in_fov(navpoint, radius)

	-- The players can't see the navpoint if the game is mostly faded out.
	if ( fade_get_percent() > 0.9 ) then
		return false
	end

	local navpoint_in_local_fov = navpoint_in_player_fov(navpoint, LOCAL_PLAYER, radius)
	local navpoint_in_remote_fov = false
	if (IN_COOP) then
		navpoint_in_remote_fov = navpoint_in_player_fov(navpoint, REMOTE_PLAYER, radius)
	end

	return (navpoint_in_local_fov or navpoint_in_remote_fov)

end


-- Enable or disable invulnerability for a vehicle. Also makes the vehicle ignore explosions.
-- 
function dlc06_set_vehicle_invulnerable(vehicle, flag)

	local explosion_multiplier = 1.0

	if (flag) then
		explosion_multiplier = 0.0
		turn_invulnerable(vehicle, false)
	end

	vehicle_prevent_explosion_fling(vehicle, flag) 

	vehicle_set_explosion_damage_multiplier(vehicle, explosion_multiplier) 
end

----------------------------------
-- Test Functions					  --
----------------------------------

function dlc06_fake_action_node(npc, flee_navp, animation_state, action_set)

	-- Start the firebreathing state
	npc_combat_enable(npc, false)

	-- Only take damage from the players
	turn_invulnerable(npc, true)

	-- Start the animation state
	if (animation_state) then
	   set_animation_state(npc, animation_state)
	end

	-- Should we continue w/ the actions node animations?
	local function should_continue_processing()
		return ( character_exists(npc) and (not character_is_dead(npc)) and (get_current_hit_points(npc) == get_max_hit_points(npc)) )
	end

	-- Play an action every once in a while if any are available
	while( should_continue_processing() ) do

		if (action_set) then

			-- Select a random action from the set
			local actions = action_set[rand_int(1, sizeof_table(action_set))]

			-- Some actions must be performed in order
			if (type(actions) == "table") then
				for i = 1, sizeof_table(actions), 1 do
					if (should_continue_processing) then
						action_play( npc, actions[i], "", true, 0.7, true)
					end
				end
			else
				action_play( npc, actions, "", true, 0.9, true)
			end

		end

		-- Wait a bit before doing any other actions
		delay(rand_int (2, 5))

		thread_yield()

	end

end

function dlc06_test_ship_canons()

	local effect_list = 
	{ 

		"rpg_a_ignite", -- Quick fire donut
		"flamethrower", -- Initial flame?
		"fire_put_out", -- 
	}

	delay(5)

	while( true ) do

		thread_yield()
			
		effect_play( "muzz_minigun", "dlc06_$n328" )
		delay(0.1)
		for i, effect in pairs(effect_list) do
			effect_play( effect, "dlc06_$n328" )
		end
		audio_play_for_navpoint("SFX_PIPEBOMB_EXP", "dlc06_$n328", "Foley")

		delay(5.0)

	end

end

function dlc06_test_mime()

	local mime = "dlc06_$target08"
	local group = "dlc06_$group_target08"
	local navp = "dlc06_$n229"

	local action_set = {"FireBreather Breathe Fire", "FireBreather Flip Fire"}

	group_create(group, true)
	teleport(mime, navp)

	-- Start the firebreathing state
	npc_combat_enable(mime, false)

	-- Only take damage from the players
	turn_invulnerable(mime, true)

	-- Start the animation state
   set_animation_state(mime, "FireBreather Stand")

	-- Play an action every once in a while
	while( character_exists(mime) and (not character_is_dead(mime)) and (get_current_hit_points(mime) == get_max_hit_points(mime)) ) do

		action_play( mime, action_set[rand_int(1, sizeof_table(action_set))], "", true, 0.9, true)

		delay(rand_int (2, 5))

		thread_yield()

	end

	if ( character_exists(mime) and (not character_is_dead(mime)) ) then
		local dist, closest_player = get_dist_closest_player_to_object(mime)
		flee_to_navpoint( mime, "dlc06_$nav_fleepoint01", closest_player, true ) 	
	end

end

----------------------------------
-- Ignore Everything Below Here --
----------------------------------
function dlc06_mystery()

	delay(1.0)

	for i, trigger in pairs(TRIGGERS_UFO_BOOM) do
		on_trigger("dlc06_ufo_boom", trigger)
		trigger_enable(trigger, true)
	end

	local start_node = ""
	local path = MYSTERY_PATH

	if ( group_is_loaded(GROUP_MYSTERY) and (not dlc06_navpoint_in_fov("dlc06_$n161")) ) then
		start_node = "dlc06_$n161"
	elseif ( group_is_loaded(GROUP_MYSTERY) and (not dlc06_navpoint_in_fov("dlc06_$n233")) ) then
		start_node = "dlc06_$n233"
		path = MYSTERY_PATH_REVERSE
	end

	if (start_node ~= "") then
		vehicle_enter_teleport( C_ALIEN, V_UFO, 0 )
		turn_invulnerable(C_ALIEN)
		turn_invulnerable(V_UFO)
		teleport_vehicle( V_UFO, start_node )
		group_show(GROUP_MYSTERY)
		helicopter_fly_to_direct( V_UFO, 40, path )
	end
		group_destroy( GROUP_MYSTERY )

end

function dlc06_ufo_boom(triggerer, trigger)

	-- Only care if the triggerer is the alien
	if (triggerer == C_ALIEN) then

		-- Only let the trigger be hit once
		on_trigger("", trigger)
		trigger_enable(trigger, false)

		-- Delay slightly so that the explosion trails the UFO. Otherwise the UFO is hard to see in release.
		delay(0.2)

		-- Create an explosion at the corresponding navpoint
		for i,trig in pairs(TRIGGERS_UFO_BOOM) do
				if (trig == trigger) then
					explosion_create("Gas Exp Medium", NAVP_UFO_BOOM[i], "", true)	
				end
		end
	end

end