If you appreciate the work done within the wiki, please consider supporting The Cutting Room Floor on Patreon. Thanks for all your support!

LEGO City Undercover (Windows)

From The Cutting Room Floor
Jump to navigation Jump to search

Title Screen

LEGO City Undercover

Developer: TT Fusion
Publisher: Warner Bros. Interactive Entertainment
Platform: Windows
Released in US: April 4, 2017
Released in EU: April 7, 2017


GraphicsIcon.png This game has unused graphics.


SOMETIMES I SEE A TEXT BOX AND I JUST CAN'T HELP MYSSDFGFFDHFGDJGGFSHGDFH
This page sucks.
If you could make it suck less, that would be awesome.
Specifically: Needs a lot of organizing, and a ton of other stuff needs to be done.

A multiplatform and PC port of a previously Wii U-exclusive LEGO game, with all of the gameplay mechanics being redone to accommodate one screen.

Notable for not only being the first LEGO game to be released for the Nintendo Switch, but also the fact that all references to the Super Mario series were removed from the non-Nintendo versions.

Consoles

Various console images are present in the Windows release.

LEGO City Undercover BUTTONMASHBUTTONUP 360 DX11.TEX.png LEGO City Undercover BUTTONMASHBUTTONUP A DX11.TEX.png LEGO City Undercover BUTTONMASHBUTTONUPWIIU A DX11.TEX.png

LEGO City Undercover BUTTONMASHJUMP WIIU DX11.TEX.png LEGO City Undercover BUTTONMASHSPECIAL PC DX11.TEX.png LEGO City Undercover BUTTONMASHSPECIAL WIIU DX11.TEX.png LEGO City Undercover BUTTONPROMPT A DX11.TEX.png LEGO City Undercover BUTTONPROMPT B DX11.TEX.png LEGO City Undercover LEFTSTICK STICKTOP DX11.TEX.png LEGO City Undercover DRC BUTPROMPT LS DX11.TEX.png LEGO City Undercover DRC BUTPROMPT RS DX11.TEX.png

Editor Icons

Icons from a level editor, which includes functions from other Lego games.

LEGO City Undercover AI PROCESSOR ICON DX11.TEX.png LEGO City Undercover ATTRACTO ICON DX11.TEX.png LEGO City Undercover BLOWUP ICON DX11.TEX.png LEGO City Undercover BUILDIT ICON DX11.TEX.png LEGO City Undercover COLLAPSE ICON DX11.TEX.png LEGO City Undercover CONDITION ICON DX11.TEX.png LEGO City Undercover DEFAULT ICON DX11.TEX.png LEGO City Undercover DIG ICON DX11.TEX.png LEGO City Undercover FLOCK ICON DX11.TEX.png LEGO City Undercover FORCE ICON DX11.TEX.png LEGO City Undercover GRAPPLE ICON DX11.TEX.png LEGO City Undercover GUIDELINE ICON DX11.TEX.png LEGO City Undercover LEVER ICON DX11.TEX.png LEGO City Undercover MINICUT ICON DX11.TEX.png LEGO City Undercover NUSPECIAL ICON DX11.TEX.png LEGO City Undercover OBSTACLE ICON DX11.TEX.png LEGO City Undercover PANEL ICON DX11.TEX.png LEGO City Undercover PICKUP ICON DX11.TEX.png LEGO City Undercover PLUG ICON DX11.TEX.png LEGO City Undercover PROCESS ICON DX11.TEX.png LEGO City Undercover PUSH ICON DX11.TEX.png LEGO City Undercover RANDOM ICON DX11.TEX.png LEGO City Undercover SECURITY ICON DX11.TEX.png LEGO City Undercover SHARD ICON DX11.TEX.png LEGO City Undercover SIGNAL ICON DX11.TEX.png LEGO City Undercover SPINNER ICON DX11.TEX.png LEGO City Undercover TECHNO ICON DX11.TEX.png LEGO City Undercover TIGHTROPE ICON DX11.TEX.png LEGO City Undercover TIMER ICON DX11.TEX.png LEGO City Undercover TUBE ICON DX11.TEX.png LEGO City Undercover WHIPPER ICON DX11.TEX.png LEGO City Undercover ZIP ICON DX11.TEX.png


LEGO City Undercover JOB ICON DX11.TEX.png LEGO City Undercover OBJECTIVE ICON DX11.TEX.png LEGO City Undercover VERTS DX11.TEX.png


LEGO City Undercover FLAG DEACTWHENFINISHED DX11.TEX.png LEGO City Undercover FLAG FREEPLAY DX11.TEX.png LEGO City Undercover FLAG INVISATSTART DX11.TEX.png LEGO City Undercover FLAG INVISWHENFALSE DX11.TEX.png LEGO City Undercover FLAG INVISWHENFINISHED DX11.TEX.png LEGO City Undercover FLAG OUTPUTSONLY DX11.TEX.png LEGO City Undercover FLAG REVWHENFALSE DX11.TEX.png LEGO City Undercover FLAG STROYMODE DX11.TEX.png

Editor Map Zones

Used in the Editor when building the map, separating it into zones.

LEGO City Undercover 2DAIMAP DX11.TEX.png

LEGO City Undercover ZONEA DX11.TEX.png LEGO City Undercover ZONEB DX11.TEX.png LEGO City Undercover ZONEC DX11.TEX.png LEGO City Undercover ZONED DX11.TEX.png LEGO City Undercover ZONEE DX11.TEX.png LEGO City Undercover ZONEF DX11.TEX.png LEGO City Undercover ZONEG DX11.TEX.png LEGO City Undercover ZONEH DX11.TEX.png LEGO City Undercover ZONERECOVERY DX11.TEX.png

Placeholder Graphics

Some temporary images used as placeholders before real images are made.

LEGO City Undercover GOLDBRICKPLACEHOLDER DX11.TEX.png LEGO City Undercover GOLDPLATEPLACEHOLDER DX11.TEX.png LEGO City Undercover ICONGENERIC DX11.TEX.png LEGO City Undercover SC PLACEHOLDER DX11.TEX.png LEGO City Undercover TROPHYPLACEHOLDER DX11.TEX.png

LEGO City Undercover MAP DX11.TEX.png LEGO City Undercover MISSIONS DX11.TEX.png LEGO City Undercover STATS DX11.TEX.png LEGO City Undercover SHIELDUNLOCKICON DX11.TEX.png LEGO City Undercover STATICONREDBRICK DX11.TEX.png

Unused Map Icons

Icons that are supposed to appear on the map, but are for features that don't appear in the final game.

LEGO City Undercover ICON LEGO DX11.TEX.png LEGO City Undercover ICON NINTENDOCUBE DX11.TEX.png LEGO City Undercover ICON NINTENDOSTAR DX11.TEX.png

LEGO City Undercover BM TOWTRUCK DX11.TEX.png LEGO City Undercover HUDSAVINGSHIELD DX11.TEX.png LEGO City Undercover ICON REMOTECAR DX11.TEX.png LEGO City Undercover MAPICON POLICELIFT 01 DX11.TEX.png LEGO City Undercover MAPICON POLICELIFT 02 DX11.TEX.png LEGO City Undercover MAPICON POLICELIFT B DX11.TEX.png LEGO City Undercover MAPICONAERIAL DX11.TEX.png

Random Graphics

Some random images in the game archives, that aren't used in the game.

LEGO City Undercover ROPE1 DX11.TEX.png LEGO City Undercover ROPE2 DX11.TEX.png LEGO City Undercover ROPE3 DX11.TEX.png LEGO City Undercover ROPE5 DX11.TEX.png LEGO City Undercover ROPE7 DX11.TEX.png LEGO City Undercover COLOUR DUMMY RAINBOW DX11.TEX.png

LEGO City Undercover TT LOGO DX11.TEX.png LEGO City Undercover CHANDELIER BANK DX11.TEX.png LEGO City Undercover MAINFRAME EGGTIMER DX11.TEX.png LEGO City Undercover SECRETBASE PIPESHADOWS DX11.TEX.png LEGO City Undercover MAINFRAME DRC CHARIM DX11.TEX.png

LEGO City Undercover 1X1LEGOBRICKRED DX11.TEX.png LEGO City Undercover SMILEY DX11.TEX.png

Placeholder Graphics

Features that aren't in the final game.

There are many loading screens, but this isn't one that's used:

LEGO City Undercover INITIALLOADINGSCREEN DX11.TEX.png


A crash icon:

LEGO City Undercover MAINFRAME CRASHICONSMALL DX11.TEX.png


A "quarted" shield:

LEGO City Undercover SC QUARTEDSHIELD DX11.TEX.png


Balls that are called "novelty":

LEGO City Undercover NOVELTY BEACHBALL DX11.TEX.png LEGO City Undercover NOVELTY MAGMABALL DX11.TEX.png LEGO City Undercover NOVELTY ROCKBALL DX11.TEX.png LEGO City Undercover NOVELTY WHITEBALL DX11.TEX.png


Label for Prison Island, which is called Albatross Island in-game:

LEGO City Undercover TEXTMISSIONNAME DX11.TEX.png

Unused Text

Cut Side Missions

Under the SIDE_MISSIONS folder, there is a variety of missions that have code but do not appear in-game.
PARAMEDIC_MISSION.SF

//  PARAMEDIC PANIC!
//  This script runs in the background and waits for the player to enter the special Ambulance.
//  Once they're in it, it activates the first build-it, and sticks on the destination glow thing, sets the sat-nav up and gets boogeying.
//  Once the player arrives in the destination area it turns off the indicator and satnav and just waits for the build-it to be finished (via an AI message).
//  It will reenable the indicator and satnav for the current destination if the player strays out of a much larger area.
//  If the player stops before the parking area, then we should also switch off the parking indicator if they approach the buildit, otherwise it looks odd.
//  The mission will ONLY be abandoned if the player enters a non-ambulance. There's no time-out other than the one which the game itself handles. We'll need to get feedback from that, mind, so we can reset stuff.

HotSpot hMissionStart("");

Timer scripttimer(0);
Timer missionTimer(0);
Character cPlayer1("player1");
Character cPlayer2("player2");
Character cMissionPlayer;
Vehicle cAmbulance;
Character cPatient;

Locator lVehicleSpawn("");						// Mission vehicle spawn locator

Text tVehicleType("Ambulance");										// Mission vehicle type
	
// Decleration strings
Text tSatNavLocator("BM_Medic_SFR_01_Patient");										// Locator for satnav prefix
Text tHotSpot("BM_Medic_SFR_01_HS");					// Hotspot prefix
Text tGizmoBuildit("iMinifig_BusinessMan");										// Buildit name prefix
Text tScript("KillOffScreen");													// Script assigned to pedestrian
Text tType("NPC_BusinessMan");														// Type of character spawned


// Debug message strings
Text tReleaseScript("KillOffScreen");



Text tReturnState("");  // State the mission returns to



WorldLevel wlCity ("Lego_City");
WorldLevel wlMissionStart ("SF_Residential_0922");
WorldLevel wlPatient01 ("SF_Residential_0921");
WorldLevel wlPatient02 ("SF_Residential_0919");
WorldLevel wlPatient03 ("SF_Residential_1021");
WorldLevel wlPatient04 ("SF_Residential_0921");
WorldLevel wlPatient05 ("SF_Residential_0922");
WorldLevel wlCurrentTile("Lego_City");

Number nStage(1);
Number nMaxStage(2); // Number of patients to see
Number nMaxDistance(8); // Max distance allowed from patient is 8 units
Number nAbandonTime(20); // Abandon time of 15 seconds
Number nMaxTime(600); // Set time given for mission to be 10 minutes
Number nHeroMax(5000);
Number nBuilditAward(2500);

Number nAbortDistance(8);		// Distance from vehicle the mission will be aborted.
Number nReturnToPatientDistance(4); // Distance from patient when prompt is given.

// Number nMaxTime(6); // Set time given for mission to be 10 minutes
Global Locator gLocKillMoveTo(""); 

// Objective OBJ_Abort("Abort_Check");


// Setup the hotspot based on the nStage
Function ActivateHotspot( Number n )
{	
	HotSpot h(tHotSpot + n.ToText("int 2"));
	h.SetActive(true);
	h.ScriptResponse("ForceBreak");	
};

// Function to force the Ambulance to break whenever they enter a hotspot
Function ForceBreak( )
{
	cAmbulance.SetParked(true);
};

// Function to remove hotspot in case it wasn't triggered 
Function RemoveHotspot( Number n )
{	
	HotSpot h(tHotSpot + n.ToText("int 2"));
	h.SetActive(false);
};

// Function to govern tile loading
Function SetTile()
{
	if (nStage == 1)
	{
		wlCurrentTile = wlPatient01;
	}
	elseif (nStage == 2)
	{
		wlCurrentTile = wlPatient02;
	}
	elseif (nStage == 3)
	{
		wlCurrentTile = wlPatient03;
	}
	elseif (nStage == 4)
	{
		wlCurrentTile = wlPatient04;
	}
	elseif (nStage == 5)
	{
		wlCurrentTile = wlPatient05;
	};
};

/////////////////////////////////////////////////////////////////
// Level Load
/////////////////////////////////////////////////////////////////
Function LevelEnter (WorldLevel level)
{
	if (!cPlayer1)
	{
		cPlayer1 = "player1";
	};
		
	if (!cPlayer2)
	{
		cPlayer1 = "player2";
	};
};

/////////////////////////////////////////////////////////////////////////////////
////  SETUP STAGE
/////////////////////////////////////////////////////////////////////////////////


State Setup( )
{
	Conditions
	{
		if ( wlCity.IsLoaded() )
		{
			goto EnableHotspot();
		};
	};	
	Actions
	{
	};
};


State EnableHotspot()
{
	Conditions
	{
	};	
	Actions
	{
		hMissionStart = "BM_Medic_SFR_01_Start";

		lVehicleSpawn = "BM_Medic_SFR_01_SpawnAmbulance";						// Mission vehicle spawn locator
		// [NOTE: stuff done here must be un-done in Cleanup()]
		
		hMissionStart.SetHaloVisible(false);
		hMissionStart.SetIcon("Bonus");
		hMissionStart.SetActive(true);
		hMissionStart.NoCondition();
		goto WaitForReturnToTile();
	};
};


// Wait for the player to be in the tile
State WaitForReturnToTile()
{
	Conditions
	{
		if( wlMissionStart.IsLoaded() ) 
		{ 
			if ( cAmbulance ) 
			{ 
				if ( cPlayer1.GetVehicle() != cAmbulance )
				{
					cAmbulance.Destroy();	
					cAmbulance = "";						
				};
			};
			goto WaitForPlayerInVehicle(); 
		};
	};
	Actions
	{
		// OBJ_Abort.Release();
	};	
};


// Activate, then await the player to enter the taxi.
State WaitForPlayerInVehicle()
{
	Text tPrompt("MISSION_PARAMEDIC_CHARACTER_PROMPT");
	Bool bPrompt(false); // Number used for latching character prompt
	Bool bPromptSecondPlayer(false);
	Bool bNoTargetSet(false);
	Gizmo gCharacterPickup("c_ParamedicCharkit");
	Number nDistance(1.5);
	Conditions
	{
//		 Check to see if the player enters the mission's vehicle		
		if ( wlCity.IsLoaded() )
		{
			if ( cAmbulance )
			{
				if( cPlayer1.GetVehicle( ) == cAmbulance ) 
				{ 
					if (MissionFocus(cPlayer1))
					{
						cMissionPlayer = cPlayer1;
						goto GiveMissionPrompts(); 
					};
				};	
				
				if( cPlayer2.GetVehicle( ) == cAmbulance ) 
				{ 
					if (MissionFocus(cPlayer2))
					{
						cMissionPlayer = cPlayer2;
						goto GiveMissionPrompts(); 
					};
				};	
			};
			
			if( !wlMissionStart.IsLoaded()  ) { goto WaitForReturnToTile(); };
			
			if ( gCharacterPickup.GetOutput(0)  AND  !Mission_IsFlagSet(#characterUnlocked) )
			{
				Mission_SetFlag( #characterUnlocked, true );
				
				if ( cAmbulance )
				{
					if (cPlayer1.DistanceToXZ(cAmbulance) < nDistance)
					{
						UI_RemoveMissionHelpText(cPlayer1);					
					};
					
					if (cPlayer2.DistanceToXZ(cAmbulance) < nDistance)
					{
						UI_RemoveMissionHelpText(cPlayer2); 					
					};
				};
				
				cAmbulance.SetLocked(false);	//  RE-ENABLE ONCE SETTAGGABLE WORKS
				bNoTargetSet = false;

			};
			
			if ( cAmbulance  AND  !Mission_IsFlagSet(#characterUnlocked) ) //  checks to see if the taxi exists and the mission value has yet to be flagged as true.
			{
				if ( cPlayer1.DistanceToXZ(cAmbulance) < nDistance  AND  !bPrompt )
				{					
					UI_SetMissionHelpText(tPrompt, 6, cPlayer1 );
					bPrompt = true;		
				}
				elseif ( cPlayer1.DistanceToXZ(cAmbulance) > nDistance  AND  bPrompt )
				{					
					UI_RemoveMissionHelpText(cPlayer1); 
					bPrompt = false;
				};
				
				if ( cPlayer2.DistanceToXZ(cAmbulance) < nDistance  AND  !bPromptSecondPlayer )
				{
					bPromptSecondPlayer = true;
					UI_SetMissionHelpText(tPrompt, 6, cPlayer2 );
				}
				elseif ( cPlayer2.DistanceToXZ(cAmbulance) > nDistance  AND  bPromptSecondPlayer )
				{
					bPromptSecondPlayer = false;
					UI_RemoveMissionHelpText(cPlayer2);
				};					
			};			
			
		};
	};
	Actions	
	{	
		// OBJ_Abort.Prepare();
		UI_LoadMissionPrompt("Hud_Mission_Bonus_Ambulance"); 
		if ( !cAmbulance )
		{
			Number nDirection(0);
			nDirection = lVehicleSpawn.GetDirection();
			cAmbulance = CreateAIVehicle( tVehicleType, "Emergency", lVehicleSpawn, nDirection );
			wait(0);
			cAmbulance.SetParked(true);	
			Wait();
			if ( !Mission_IsFlagSet(#characterUnlocked) )
			{
				cAmbulance.SetLocked(true);  //  RE-ENABLE ONCE SETTAGGABLE WORKS
			};			
		};		

		
	};
};


// Checks to see if the player starts the mission or not - handles accepting the mission
State GiveMissionPrompts()
{
	Conditions
	{
//		 Gets out of the vehicle before pressing LB to initiate mission...
		if( cMissionPlayer.GetVehicle( ) != cAmbulance ) 
		{ 
			cAmbulance.SetParked(false);	
			UI_HideMissionPrompt();	
			MissionUnfocus();
			StreamedCharacterRelease("Mission_Paramedic");			
			goto WaitForPlayerInVehicle(); 
		};

		if( PlayerPressedButton(cMissionPlayer, "A") ) 
		{ 			
			if ( cPlayer1 == cMissionPlayer )
			{
				PlayerSetCharacter( 1, "Mission_Paramedic");
			}
			else
			{
				PlayerSetCharacter( 2, "Mission_Paramedic");
			};
			
			MissionActivate();  // START THE MISSION!			
		};
	};
	Actions
	{
		UI_ShowMissionPrompt("Hud_Mission_Bonus_Ambulance", "MISSION_INSTRUCTIONS_PARAMEDIC", "MISSION_PROMPT", "MISSION_TITLE_PARAMEDIC");	
		nStage = 1;
		StreamedCharacterPreLoad("Mission_Paramedic");
	};
};




/////////////////////////////////////////////////////////////////////////////////
////// CLEANUP
/////////////////////////////////////////////////////////////////////////////////

state Cleanup()
{
	Actions
	{
		if ( cAmbulance ) 
		{
			cAmbulance.Destroy();
			cAmbulance = "";
		};
		
		if ( wlCity.IsLoaded() )
		{
			Number n(1);
			Gizmo gBuildit(tGizmoBuildit + n.ToText("int 2") );
			// cleanup stuff...
			while ( nMaxStage >= n )
			{
				gBuildit = (tGizmoBuildit + n.ToText("int 2"));			
				gBuildit.SetVisible(false);
				gBuildit.SetActive(false);
				n = n + 1;
			};
		};
		
		if ( hMissionStart )
		{
			hMissionStart.SetActive(false);
		};
		// All tidy, let the game know...
		MissionCleanupEnd();
	};
};



/////////////////////////////////////////////////////////////////////////////////
//// Mission Loop
/////////////////////////////////////////////////////////////////////////////////


state Begin()
{
	Actions
	{
		// Remove the icon above the vehicle
		hMissionStart.Trigger();
		
		// Start the timer and setup the other hud elements
		UI_StartMission();
		missionTimer = 0;	
		UI_SetHUDTimer( nMaxTime, 1, missionTimer );
		UI_ShowHUDTimer(true);	
		UI_SetHeroBarMax(nHeroMax);	
		
		// Stream in patients for spawning immediately
		StreamedCharacterPreLoad( tType );
		
		// Set tile for the first stage
		SetTile();
		// OBJ_Abort.ScriptGoto("Begin");
		goto SetStage();
	};
};


State SetStage( )
{
	Locator lSatNav(tSatNavLocator + nStage.ToText("int 2"));
	Gizmo gBuildit(tGizmoBuildit + nStage.ToText("int 2") );
	
	Conditions
	{
		if ( cMissionPlayer.GetVehicle( ) != cAmbulance  )
		{
			UI_RemoveMissionHelpText(); 
			UI_RadioCall(false);
			goto ReturnToVehicle(); 	
		};
	};	
	Actions
	{
		tReturnState = "SetStage";
		// Ensure the player can drive to the next stage
		cAmbulance.SetParked(false);
		
		
		gBuildit.SetVisible(true);
		gBuildit.SetActive(true);
			
		
		ActivateHotspot( nStage );		
		SetSatNavDestination( lSatNav );
		
		Text t("MISSION_PARAMEDIC_PATIENT_");
		t = t + nStage.ToText("int 2");
		UI_RadioCall( true );		
		Wait(0.25);
		UI_SetMissionHelpText( t, 5 );
		tReturnState = "SpawnBuildit";
		Wait( 5.5 );
		UI_RadioCall( false );
		goto SpawnBuildit();
	};
};



State SpawnBuildit( )
{
	Gizmo gBuildit(tGizmoBuildit + nStage.ToText("int 2") );
	Bool bSpawnBuildit(true);
	Bool bPark(true);
	Bool bReachedPatient(false);
	
	Conditions
	{
		
		if ( cMissionPlayer.GetVehicle( ) != cAmbulance  AND  !bReachedPatient )
		{
			if ( cMissionPlayer.DistanceToXZ( gBuildit ) > nReturnToPatientDistance ) 
			{ 	
				goto ReturnToVehicle(); 
			}			
			else {  bReachedPatient = true; };		
		};
		
		if ( bReachedPatient )
		{
			if ( cMissionPlayer.DistanceToXZ( gBuildit ) > nReturnToPatientDistance ) { goto ReturnToPatient(); }
		};
		
		
		// Check to see if the pedestrian buildit has been completed and then go to the next stage to swap him out for an actual AI pedestrian
		if ( gBuildit.HasFinished() )  
		{
			gBuildit.SetVisible(false);	
			gBuildit.SetActive(false);	
			goto SpawnPedestrian();			
		};
		
		// If the player runs out of time, go to the out of time stage
		if ( missionTimer > nMaxTime ) { goto OutOfTime(); };
		
		
		// Check to see if the buildit needs spawning
		if ( bSpawnBuildit )
		{
			// If it does need spawning, check to see if the tile is loaded
			if ( wlCurrentTile.IsLoaded() )
			{
				bSpawnBuildit = false;
				gBuildit.SetActive(false);
				gBuildit.SetActive(true);
			};
		}
		else
		{
			// if it doesn't need spawning, check that the tile isn't loaded, and then if it isn't, make sure we know it needs building again.
			if ( !wlCurrentTile.IsLoaded() ) { bSpawnBuildit = true; };
		};
				
	};
};


// Spawn the pedestrian character 
State SpawnPedestrian( )
{
	Gizmo gBuildit(tGizmoBuildit + nStage.ToText("int 2") );
	Number n(1);

	Actions
	{
		//gLocKillMoveTo = "TaxiMissionCustomerEnd01_TEST";
		n = gBuildit.GetDirection();		
		cPatient = CreateAICharacter(tType, "Pedestrian", gBuildit, n);	
		cPatient.Release();

		Playergivestuds(nBuilditAward);
		Text t("MISSION_GRATITUDE_");
		n = RandomInt(1, 4);
		t = t + n.ToText("int 2");
		UI_SetMissionHelpText( t, 4 );
		
		// calls the remove hotspot function - do so before nStage is incremented to ensure the stage which has just been completed is removed and not the next one!
		RemoveHotspot( nStage );
		nStage = nStage + 1;
		
		tReturnState = "SetStage";
		
		// Check to see if you've completed the mission, otherwise carry on to the next state in the loop.
		if ( nStage > nMaxStage ) 
		{			
			goto MissionEnd();
		}
		else 
		{ 			
			goto ReturnToVehicle(); 
		};
	};
};

////////////////////////////////////////////////////////////////
// Abandon Mission
////////////////////////////////////////////////////////////////

State ReturnToPatient( )
{
	Number nPatientAbort(8);
	Gizmo gBuildit(tGizmoBuildit + nStage.ToText("int 2") );
	Text tAwayFromPatientPrompt("MISSION_PARAMEDIC_RETURN_TO_PAT");
	Text tAbandonedPatientPrompt("MISSION_PARAMEDIC_ABANDONED_PATIENT");
	Conditions 
	{
		if ( cMissionPlayer.GetVehicle() == cAmbulance  OR  cMissionPlayer.DistanceToXZ( gBuildit ) < nReturnToPatientDistance  )
		{
			UI_RemoveMissionMessage();					
			goto SpawnBuildit();		
		};
		
		if ( cMissionPlayer.DistanceToXZ( cAmbulance ) > nAbortDistance  AND  cMissionPlayer.DistanceToXZ( gBuildit ) > nPatientAbort )
		{
			UI_SetMissionMessage( tAbandonedPatientPrompt, 5 );
			MissionAbort();
		};
	};
	Actions
	{
		UI_SetMissionMessage( tAwayFromPatientPrompt );
	};
};


State ReturnToVehicle( )
{
	Text tOutOfVehiclePrompt("MISSION_PARAMEDIC_RETURN_TO_AMB");
	Text tAbandonedVehiclePrompt("MISSION_PARAMEDIC_ABANDONED");
	Conditions
	{
		if ( cMissionPlayer.GetVehicle() == cAmbulance )
		{
			UI_RemoveMissionMessage();
			
			if ( tReturnState == "SetStage" )
			{
				goto SetStage();
			}
			else {goto SpawnBuildit(); };
		};
		
		if ( cMissionPlayer.DistanceToXZ( cAmbulance ) > nAbortDistance )
		{
			UI_SetMissionMessage( tAbandonedVehiclePrompt, 5 );
			MissionAbort();
		};
	};
	Actions
	{
		UI_SetMissionMessage( tOutOfVehiclePrompt );
	};
};



// Mission ended due to player running out of time - Give out of time message and reset mission
State OutOfTime( ) 
{
	Conditions
	{
	};
	Actions
	{
		UI_EndMission("MISSION_FAIL_TIMEOUT", false);
		goto HandleFailScreen();
	};
};


State HandleFailScreen( )
{
	Timer time(0);
	Bool b(false);
	Conditions
	{
		if ( time > 0.1  AND  ( PlayerPressedButton(cMissionPlayer, "A")  OR  PlayerPressedButton("Y") ) AND !b )
		{
			UI_ResetMission();
			goto Reset();
		}
		else
		{
			if ( (b AND !cMissionPlayer.GetVehicle()) OR  PlayerPressedButton(cMissionPlayer, "A")  OR  PlayerPressedButton("Y") )
			{
				UI_ResetMission();
				goto Reset();
			};
		};
		
	};
	Actions
	{
		if ( cMissionPlayer.GetVehicle() ) 
		{
			b = true;
		};	
	};
};




// Player completed the mission
State MissionEnd( )
{
	Conditions
	{
		// if ( UI_IsEndMissionComplete() )
		//{
		//	goto Reset();
		//};		
	};
	Actions
	{
		cAmbulance.SetParked(true);
		// UI_EndMission("MISSION_COMPLETE", true);	
		goto Reset();
	};
};


// Reset all mission assets
State Reset( )
{
	Number n(1);
	Text t("");
	Gizmo gBuildit(tGizmoBuildit + n.ToText("int 2") );
	Conditions
	{
	};
	Actions
	{
		// REPLACE WITH BELOW WHILE LOOP WHEN gizmo.Reset() WORKS 
			
		
		while ( nMaxStage >= n )
		{
			gBuildit = (tGizmoBuildit + n.ToText("int 2"));
			gBuildit.SetVisible(false);
			gBuildit.SetActive(false);
			n = n + 1;
		};  
		UI_SetStatsStuds();		
		UI_StopHUDTimer();
		UI_ShowHUDTimer(false);	
		SetHotSpot();
		StreamedCharacterReleaseAll();
		cAmbulance.SetParked(false);	   
		cAmbulance.SetScript( tScript );
		cAmbulance = "";
		
		if ( nStage > nMaxStage )
		{
			nStage = 1;
			MissionComplete(); // NEEDS TO CHECK AGAINST MISSION COMPLETE STATUS AND FAIL / END MISSION IF MISSION FAILED / ABANDONED ONCE THAT STATE IS AVAILABLE
		}
		else
		{
			nStage = 1;
			MissionAbort(); 
		};
	};
};


TAXI_MISSION.SF

// This script is the Taxi Mission Handler - when you jump into a Taxi (at the moment a
// specific one, later on it should be any of them) it will spawn the first customer. That
// customer will then further the mission by getting picked up and dropped off.
// If the player gets out of the taxi they have 5 seconds to get back in it before the 
// script will abort, and any customer who is in the taxi will get out.
// We execute this ONCE only. Couples the Taxi up and then heads to WaitForTaxiMission

HotSpot hMissionStart("");
// Mission vehicle spawn locations
Locator lTaxiSpawn("");

// Characters used in the mission
Character cPlayer1("player1");
Character cPlayer2("player2");
Character cMissionPlayer("");
Vehicle cTaxi("");
Character cPassengerCurrent("");

Locator gLocMoveTo("");

// Vehicle setup strings
Text tVehicleType("Taxicab");
Text tCharType("");

// Declaration strings - used to declare area and locator vars in the mission loop as the mission stage progresses / iterates
Text tSpawnLocator("BM_Taxi_SFR_01_Customer");
//Text tPickupArea("TaxiMissionCustomerPickupArea"); // CANNOT SEE AREAS RELATING TO THESE IN THE LED. REMOVE IS UNNECESSARY
Text tPickupLocator("BM_Taxi_SFR_01_PU");
//Text tDropOffArea("TaxiMissionCustomerDropOffArea"); // CANNOT SEE AREAS RELATING TO THESE IN THE LED. REMOVE IS UNNECESSARY
Text tDropOffLocator("BM_Taxi_SFR_01_DO");

Text tPickupHotspot("HotSpot_SideMission_Taxi_Pickup_SFResidential_");
Text tDropOffHotspot("HotSpot_SideMission_Taxi_DropOff_SFResidential_");

// Response text based on player performance
Text tGood_01("MISSION_TAXI_CUSTOMER_RESPONSE_GOOD_01");
Text tNeutral_01("MISSION_TAXI_CUSTOMER_RESPONSE_FAIR_01");
Text tPoor_01("MISSION_TAXI_CUSTOMER_RESPONSE_POOR_01");

// Temporary text to differentiate between different taxi varients
Text tPrompt("MISSION_TAXI_PROMPT");

Number nStage(1);
Number nMaxStage(2); // Number of passengers / loops of pickups
Number nTimeLimit(600); // Seconds allowed for the mission to be completed within

// Definitions needed for new timer system and two tier stud awards
Number nStage01Timer(50);
Number nStage02Timer(70);
Number nStage03Timer(70);
Number nStage04Timer(70);
Number nStage05Timer(70);

Number nBonusThreshold(0);
Number nTimeMultiplier(500);
Number nTimeBonusMultiplier(1000);
Number nStudAward(0);
Number nHeroTarget(14000);
Number nPassengerSet(0);

Number nAbortDistance(1);

Timer scripttimer(0);
Timer missionTimer(0);

WorldLevel wlCity ("Lego_City");
WorldLevel wlMissionStart("SF_Residential_1122");
WorldLevel wlPassenger1("SF_Residential_0921");
WorldLevel wlPassenger2("SF_Residential_0919");
WorldLevel wlPassenger3("SF_Residential_0919");
WorldLevel wlPassenger4("SF_Residential_0919");
WorldLevel wlPassenger5("SF_Residential_0919");

WorldLevel wlCurrentPassenger("SF_Residential_0921");



/////////////////////////////////////////////////////////////////
// Level Load
/////////////////////////////////////////////////////////////////
Function LevelEnter (WorldLevel level)
{
	
	if ( level == wlCity )
	{
		if (!cPlayer1)
		{
			cPlayer1 = "player1";
		};
	};
};

/////////////////////////////////////////////////////////////////////////////////
////  SETUP STAGE
/////////////////////////////////////////////////////////////////////////////////

State Setup()
{
	Conditions
	{
		if ( wlCity.IsLoaded() )
		{
			goto EnableHotspot();
		};
	};	
	Actions
	{
	};
};


State EnableHotspot()
{
	Conditions
	{
	};
	
	Actions
	{
		hMissionStart = "BM_Taxi_SFR_01_TimeTrialStart";

		lTaxiSpawn = "BM_Taxi_SFR_01_TimeTrialSpawn";
		
		// setup stuff...
		// [NOTE: stuff done here must be un-done in Cleanup()]
		
		hMissionStart.SetHaloVisible(false);
		hMissionStart.SetIcon("Bonus"); 
		hMissionStart.SetActive(true);
		hMissionStart.NoCondition();
		goto WaitForReturnToTile();
	};
};




// Wait for the player to be in the tile
State WaitForReturnToTile()
{
	Conditions
	{
		if( wlMissionStart.IsLoaded() ) 
		{ 
			goto WaitForPlayerInTaxi(); 
		};
	};
	Actions
	{
		if ( cTaxi ) 
		{ 
			if ( cPlayer1.GetVehicle() != cTaxi  AND  cPlayer2.GetVehicle() != cTaxi ) 
			{	
				cTaxi.Deactivate();
				cTaxi = "";					
			};
		};	
	};	
};


// Activate, then await the player to enter the taxi.
State WaitForPlayerInTaxi()
{

	Number n(0);
	
	Conditions
	{
//		 Check to see if the player enters the mission's vehicle		
		if ( wlCity.IsLoaded() )
		{
			if ( cTaxi )
			{
				if( cPlayer1.GetVehicle( ) == cTaxi ) 
				{ 
					if (MissionFocus(cPlayer1))
					{
						UI_RemoveMissionHelpText(); 
						cMissionPlayer = cPlayer1;
						goto GiveMissionPrompts(); 
					};
				};
				
				if( cPlayer2.GetVehicle( ) == cTaxi ) 
				{ 
					if (MissionFocus(cPlayer2))
					{
						UI_RemoveMissionHelpText(); 
						cMissionPlayer = cPlayer2;
						goto GiveMissionPrompts(); 
					};
				};
			};
			
			if( !wlMissionStart.IsLoaded() ) 
			{
				goto WaitForReturnToTile(); 
			};
			
			if ( cTaxi )
			{
				if (cPlayer1.DistanceToXZ(cTaxi) < 1 AND n == 0)
				{
					n = 1;
					UI_SetMissionHelpText(tPrompt);
				};
				if (cPlayer1.DistanceToXZ(cTaxi) > 1 AND n == 1)
				{
					n = 0;
					UI_RemoveMissionHelpText(); 			
				};	
			};				
		};
	};
	Actions
	{
		Number nDirection(0);
		Number nDirectionSeat(0);
		if ( !cTaxi  ) 
		{
			nDirection = lTaxiSpawn.GetDirection();
			
			cTaxi = CreateAIVehicle( tVehicleType, "Taxi", lTaxiSpawn, nDirection );
			cTaxi.SetParked(true);
		};	
	};
};


// Checks to see if the player starts the mission or not - handles accepting the mission
State GiveMissionPrompts()
{
	// Number n(0);
	
	Conditions
	{
//		 Gets out of the vehicle before pressing LB to initiate mission...
		if( cMissionPlayer.GetVehicle( ) != cTaxi ) 
		{ 
			cTaxi.SetParked(false);
			UI_HideMissionPrompt();
			MissionUnfocus();
			goto WaitForPlayerInTaxi(); 
		};

		if( PlayerPressedButton(cMissionPlayer, "A") ) 
		{ 
			MissionActivate();
		};
	};
	Actions
	{
		UI_ShowMissionPrompt("Hud_Mission_Bonus_Taxi", "MISSION_INSTRUCTIONS_TAXI", "MISSION_PROMPT", "MISSION_TITLE_TAXI");		
	};
};




/////////////////////////////////////////////////////////////////////////////////
/////  Cleanup
/////////////////////////////////////////////////////////////////////////////////

State Cleanup()
{
	Actions
	{
		// cleanup stuff...
		if (wlCity.IsLoaded())
		{
			if ( cTaxi )
			{
				cTaxi.Deactivate();
				cTaxi = "";
			};
			
			if ( cPassengerCurrent )
			{
				cPassengerCurrent.SetScript("KillOffScreen");
				cPassengerCurrent = "";
			};

			if ( hMissionStart )
			{
				hMissionStart.SetActive(false);
			};
		};
		// All tidy, let the game know...
		MissionCleanupEnd();
	};
};



/////////////////////////////////////////////////////////////////////////////////
//// Mission Loop
/////////////////////////////////////////////////////////////////////////////////

Function ParkTaxi()
{
	cTaxi.SetParked(true);
};

Function ParkTaxiDropOff()
{
	cTaxi.SetParked(true);
	goto DropOffCustomer();
};

State Begin()
{
	Actions
	{
			UI_StartMission();
			hMissionStart.Trigger();
			cTaxi.SetParked(false);				
			UI_SetHeroBarMax(nHeroTarget);
			
			goto StageSetup();	
	};
};


// States below here comprise the mission loop

State StageSetup()
{
	HotSpot hPickup( tPickupHotspot + nStage.ToText("int 2") );
	Locator lPickUp( "" + tPickupLocator + nStage.ToText("int 2")  );	
	Conditions
	{
	};
	Actions
	{
		if (nStage == 1)
		{
			nTimeLimit = nStage01Timer;
			wlCurrentPassenger = wlPassenger1;
		}		
		elseif (nStage == 2)
		{
			nTimeLimit = nStage02Timer;
			wlCurrentPassenger = wlPassenger2;
		}
		elseif (nStage == 3)
		{
			nTimeLimit = nStage03Timer;
			wlCurrentPassenger = wlPassenger3;
		}
		elseif (nStage == 4)
		{
			nTimeLimit = nStage04Timer;
			wlCurrentPassenger = wlPassenger4;
		}
		elseif (nStage == 5)
		{
			nTimeLimit = nStage05Timer;
			wlCurrentPassenger = wlPassenger5;
		};
		
		
		hPickup.SetActive(true);
		hPickup.ScriptResponse("ParkTaxi");
		hPickup.SetIcon("Bonus"); 
		SetSatNavDestination( lPickUp );
		
		if ( nStage != 1 )
		{
			UI_SetMissionCounter( (nStage - 1), nMaxStage, false ) ;
			UI_ShowMissionCounter( true );
			Wait(1.5);
			UI_ShowMissionCounter( false );
		};		
		
		
		missionTimer = 0;
		UI_StopHUDTimer(); 
		UI_ShowHUDTimer(false);
		UI_SetHUDTimer( nTimeLimit, 1, missionTimer );
		UI_ShowHUDTimer(true);
		
		
		
		Text t("MISSION_TAXI_DIRECTIONS_PICKUP_");
		t = t + nStage.ToText("int 2");
		UI_RadioCall( true, 6 );
		Wait(0.25);
		UI_SetMissionHelpText( t, 5 );

		goto HeadToCustomer();
	};
};

State HeadToCustomer( )
{
	Conditions
	{
		if ( wlCurrentPassenger.IsLoaded() )
		{
			goto SpawnCustomer();
		};	
		
		if ( cTaxi.DistanceToXZ( cMissionPlayer ) > nAbortDistance )
		{
			goto HandleFailScreen();
		};
	};

	Actions
	{		
	};
};

// Spawn the customer
State SpawnCustomer( )
{
	Locator lSpawn( "" + tSpawnLocator + nStage.ToText("int 2") );
	Number 	n(0);
	Text 	tType01("BusinessManA");
	Text 	tType02("ConstructionWorker");
	Text 	tType03("MaleA");
	Text 	tType04("Nurse");
	Conditions
	{
	};
	Actions
	{
		
		if (nPassengerSet == 0)
		{
			n = RandomInt( 1, 4 );
			if ( n == 1 ) { tCharType = tType01; }
			elseif ( n == 2 ) { tCharType = tType02; }
			elseif ( n == 3 ) { tCharType = tType03; }
			elseif ( n == 4 ) { tCharType = tType04; }
			else { tCharType = tType01; };		
		
			Position pCabPos( cTaxi );
			//gLocMoveTo = pCabPos;
		
			tCharType = tType01;  // REMOVE WHEN ISSUE OF CHARACTERS GETTING INTO VEHICLES IS SORTED
			nPassengerSet = 1;
		};
		
		n = lSpawn.GetDirection();
		cPassengerCurrent = CreateAICharacter( tCharType, "Pedestrian",  lSpawn, n);
		cPassengerCurrent.SetZoneAbility( #RAISE, #A, #B );	
		
		goto CustomerFollowTaxi();
	};
};


State CustomerFollowTaxi( )
{
	Locator lSpawn( "" + tSpawnLocator + nStage.ToText("int 2") );
	Locator lMoveTo( "" );
	Number n(1);
	Number z(0);
	
	Conditions
	{

		if ( cPassengerCurrent.GetVehicle() != cTaxi  AND  cMissionPlayer.DistanceToXZ( lSpawn ) > 10 AND n == 0 ) 
		{ 
			cPassengerCurrent.MoveTo( lSpawn, 1 );
			n = 1;
		};
		
		if (n == 1 AND cPassengerCurrent.GetVehicle( ) != cTaxi AND cPassengerCurrent.DistanceToXZ( cMissionPlayer ) < 10)
		{
			// cPassengerCurrent.FollowCharacter( cTaxiSeat );		 // THIS HAS YET TO BE IMPLEMENTED BY CODE -- chrysp: this should be : cPassengerCurrent.EnterVehicle( cTaxi, "seatXYZ");
			n = 0;
		};
		
		if ( cPassengerCurrent.DistanceToXZ( cMissionPlayer ) < 3.5 )
		{
			z = cTaxi.GetSpeed();
			if( z <= 1)
			{
				//cPassengerCurrent.TakeOver( cTaxiSeat ); chrysp: this should be : cPassengerCurrent.EnterVehicle( cTaxi, "seatXYZ");
				goto HeadToDropOff();
			};
		};
		
		if ( !wlCurrentPassenger.IsLoaded() )
		{
			cPassengerCurrent.Kill();
			goto HeadToCustomer();
		};
		
		
		if ( cTaxi.DistanceToXZ( cMissionPlayer ) > nAbortDistance )
		{
			goto HandleFailScreen();
		};
	};
	Actions
	{
	//cPassengerCurrent.FollowCharacter( cTaxiSeat );		 // THIS HAS YET TO BE IMPLEMENTED BY CODE	
	};
};


State HeadToDropOff( )
{
	Locator lDropOff( "" + tDropOffLocator + nStage.ToText("int 2") );
	HotSpot hDropOff( tDropOffHotspot + nStage.ToText("int 2") );
	HotSpot hPickup( tPickupHotspot + nStage.ToText("int 2") );

	Conditions
	{
	`	if ( cTaxi.DistanceToXZ( cMissionPlayer ) > nAbortDistance )
		{
			goto HandleFailScreen();
		};
	};
	Actions
	{
		hPickup.SetActive(false);
		cTaxi.SetParked(false);
		Text t("MISSION_TAXI_DIRECTIONS_DROPOFF_");
		t = t + nStage.ToText("int 2");
		UI_SetMissionHelpText( t, 5 );
		
		hDropOff.SetActive(true);
		hDropOff.ScriptResponse("ParkTaxiDropOff");
		hDropOff.SetIcon("Bonus"); 
		SetSatNavDestination( lDropOff );
		//  REMOVE THIS ONCE WE CAN RELEASE CHARACTERS TO THE CITY AS AMBIENT CHARACTERS
	};
};


State DropOffCustomer( )
{
	Locator lDropOff( "" + tDropOffLocator + nStage.ToText("int 2") );
	Number n(0);
	HotSpot hDropOff( tDropOffHotspot + nStage.ToText("int 2") );
	Conditions
	{
		n = cTaxi.GetSpeed();
		If( n <= 1)
		{
			cPassengerCurrent.ExitVehicle(); //cPassengerCurrent.ReleaseTakeOver(0.5, 1); //chrysp: this should be   cPassengerCurrent.ExitVehicle();
			hDropOff.SetActive(false);
			goto Reward();
		};
		
		if ( cPassengerCurrent.GetVehicle() == cTaxi  AND  cMissionPlayer.DistanceToXZ( lDropOff ) > 20 ) 
		{
			goto HeadToDropOff();
		};
		
		if ( cTaxi.DistanceToXZ( cMissionPlayer ) > nAbortDistance )
		{
			goto HandleFailScreen();
		};
	};
	Actions
	{
		
	};
};


State Reward( )
{
	Conditions
	{
	};
	Actions
	{	
		// Award the player based on the time taken
		Number nTotal(0);
		nPassengerSet = 0;
		nBonusThreshold = nTimeLimit / 4;
		nStudAward = nTimeLimit - missionTimer;

		if (missionTimer < nTimeLimit)
		{
			if (nStudAward > nBonusThreshold)
			{
				nTotal = (nBonusThreshold * nTimeMultiplier);
				ntotal = ntotal + ((nStudAward - nBonusThreshold) * nTimeBonusMultiplier);
				Playergivestuds(nTotal);
			}
			else
			{
				nTotal = nStudAward * nTimeMultiplier;
				Playergivestuds(nTotal);
			};
		};
		goto PassengerResponse();
	};
};

State PassengerResponse( )
{
	Text t("");
	Conditions
	{
	};
	Actions
	{
		if ( MissionTimer >= nTimelimit )
		{
			t = tPoor_01; 
		}
		else
		{
			if (nStudAward > nBonusThreshold)
			{
				t = tGood_01; 
			}
			else
			{
				t = tNeutral_01;	
			};
		};	
		// Give customer dialogue feedback (temporary version)
		UI_SetMissionHelpText( t, 4 ); 
		
		cTaxi.SetParked(false);
		UI_StopHudTimer();	
		wait(1);
		goto NextStage();
	};
};

State NextStage( )
{
	Conditions
	{
	};
	Actions
	{	
		// Set up ready for next stage or complete the mission
		nStage = nStage + 1;
		cPassengerCurrent.SetScript( "KillOffScreen" );  //  REMOVE THIS ONCE WE CAN RELEASE CHARACTERS TO THE CITY AS AMBIENT CHARACTERS 
		if ( nStage > nMaxStage ) 
		{
			goto MissionEnd();
		}
		else
		{
			goto StageSetup();
		};
	};
};

State OutOfTime( ) 
{
	Conditions
	{
		
	};
	Actions
	{
		UI_EndMission("MISSION_FAIL_TIMEOUT", false);
		goto HandleFailScreen();
	};
};


State HandleFailScreen( )
{
	Timer time(0);
	Bool b(false);
	Conditions
	{
		if ( time > 0.1  AND  ( PlayerPressedButton(cMissionPlayer, "A")  OR  PlayerPressedButton("Y") ) AND !b )
		{
			UI_ResetMission();
			goto Reset();
		}
		else
		{
			if ( (b AND !cMissionPlayer.GetVehicle()) OR  PlayerPressedButton(cMissionPlayer, "A")  OR  PlayerPressedButton("Y") )
			{
				UI_ResetMission();
				goto Reset();
			};
		};
		
	};
	Actions
	{
		if ( cMissionPlayer.GetVehicle() ) 
		{
			b = true;
		};	
	};
};



State MissionEnd( )
{
	Conditions
	{
	};
	Actions
	{
		// UI_EndMission("MISSION_COMPLETE", true);
		goto Reset();
	};
};

State Reset( )
{
	Conditions
	{
	};
	Actions
	{
		UI_SetStatsStuds();
		SetSatNavDestination();
		SetHotSpot();
		UI_StopHUDTimer();
		UI_ShowHUDTimer(false);	
		cTaxi = "";
		if ( nStage > nMaxStage ) 
		{
			MissionComplete(); // NEEDS TO CHECK AGAINST MISSION COMPLETE STATUS AND FAIL / END MISSION IF MISSION FAILED / ABANDONED ONCE THAT STATE IS AVAILABLE
		}
		else
		{
			MissionAbort();
		};	
	};
};


UFO_MISSION.SF
A prototype of what the UFO Mission might've looked like.


HotSpot hMissionStart("");
Hotspot hCaptureArea("");

Character cPlayer1("player1");
Character cPlayer2("player2");
Character cMissionPlayer("");

Character cLiveStock01("");
Character cLiveStock02("");
Character cLiveStock03("");
Character cLiveStock04("");
Character cLiveStock05("");
Vehicle cUFO;

Locator lVehicleSpawn;
Locator lSpawnLiveStock01;
Locator lSpawnLiveStock02;
Locator lSpawnLiveStock03;
Locator lSpawnLiveStock04;
Locator lSpawnLiveStock05;


Area aTile01("");
Area aTile02("");

Area aTargetA("");
Area aTargetB("");
Area aUFO_OutOfBound("");
// Debug messages
Text tUI_StartMission("Press A to start the UFO abduction mission!");
Text tMissionDesc("Use the UFO to abduct and corral the livestock! Press A to start");
// Vehicle setup strings
Text tVehicleType("UFO");
// Declaration strings
Number nTimeLimit(600); // Seconds allowed for the mission to be completed within
Number nTargetsCaught(0);
Number nMaxTargets(5);

Number nHeroMax(10000);
Number nLiveStockAward(2000);

Timer scripttimer(0);
Timer missionTimer(0);

WorldLevel wlCity("Lego_City");
WorldLevel wlFarmLands("WI_Farmlands_0507");
WorldLevel wlFarmLands2("WI_Farmlands_0505");
WorldLevel wlFarmLands3("WI_Farmlands_0506");

Bool bLiveStockFree01(true);
Bool bLiveStockFree02(true);
Bool bLiveStockFree03(true);
Bool bLiveStockFree04(true);
Bool bLiveStockFree05(true);
Bool bCounterOn(false);
Number nLiveStockCaught01(0);
Number nLiveStockCaught02(0);
Number nLiveStockCaught03(0);
Number nLiveStockCaught04(0);
Number nLiveStockCaught05(0);	


/////////////////////////////////////////////////////////////////
// Level Load
/////////////////////////////////////////////////////////////////
Function LevelEnter (WorldLevel level)
{	
	cPlayer1 = "player1";
	cPlayer2 = "player2";
};

/////////////////////////////////////////////////////////////////////////////////
////  SETUP STAGE
/////////////////////////////////////////////////////////////////////////////////



State Setup( )
{
	Conditions
	{
		if ( wlCity.IsLoaded() )
		{
			goto EnableHotspot();
		};
	};	
	Actions
	{
	};
};


state EnableHotspot( )
{
	Conditions
	{
	};	
	Actions
	{			
		hMissionStart = "BM_UFO_FL_01_Start";
		hCaptureArea = "BM_UFO_FL_01_CaptureArea";
		
		lVehicleSpawn = "BM_UFO_FL_01_SpawnUFO";
		lSpawnLiveStock01 = "BM_UFO_FL_01_SpawnLiveStock01";
		lSpawnLiveStock02 = "BM_UFO_FL_01_SpawnLiveStock02";
		lSpawnLiveStock03 = "BM_UFO_FL_01_SpawnLiveStock03";
		lSpawnLiveStock04 = "BM_UFO_FL_01_SpawnLiveStock04";
		lSpawnLiveStock05 = "BM_UFO_FL_01_SpawnLiveStock05";


		aTile01 = "WI_Farmlands01";
		aTile02 = "WI_Farmlands02";
		aUFO_OutOfBound = "BM_UFO_FL_01_OutOfBounds";

		aTargetA = "BM_UFO_FL_01_LiveStockCylinder";
		aTargetB = "BM_UFO_FL_01_LiveStockCube";

		// setup stuff...
		// [NOTE: stuff done here must be un-done in Cleanup()]
		
		hMissionStart.SetHaloVisible(false);
		hMissionStart.SetIcon("Bonus");
		hMissionStart.SetActive(true);
		hMissionStart.NoCondition();		
		goto WaitForReturnToTile();
	};
};


// Wait for the player to be in the tile
State WaitForReturnToTile()
{
	Conditions
	{
		if ( wlCity.IsLoaded() )
		{
			if( wlFarmLands.IsLoaded() ) 
			{ 
				// PrintToScreen("DEBUG: WaitForReturnToTile");
							
				if ( cUFO ) 
				{ 
					if ( cMissionPlayer )
					{
						if (cMissionPlayer.GetVehicle() != cUFO)
						{
							cUFO.Destroy();
						};
					}
					else
					{
						cUFO.Destroy();
					};
				};

				cUFO = "";
				goto WaitForPlayerInVehicle(); 
			};
		};
	};
	Actions
	{
	};	
};


// Activate, then await the player to enter the taxi.
State WaitForPlayerInVehicle()
{
	
	Conditions
	{
		if ( wlCity.IsLoaded() )
		{
			//	Check to see if the player enters the mission's vehicle		
			if ( cUFO )
			{
				if ( cPlayer1 )
				{
					if( cPlayer1.GetVehicle() == cUFO ) 
					{ 
						if (MissionFocus(cPlayer1))
						{
							cMissionPlayer = cPlayer1;
							goto GiveMissionPrompts(); 
						};
					};
				}
				else
				{
					cPlayer1 = "player1";
				};
				
				
				if ( cPlayer2 )
				{
					if( cPlayer2.GetVehicle() == cUFO ) 
					{ 
						if (MissionFocus(cPlayer2))
						{
							cMissionPlayer = cPlayer2;
							goto GiveMissionPrompts(); 
						};
					};
				}
				else
				{
					cPlayer2 = "player2";
				};
			};
			
			if( !wlFarmLands.IsLoaded() ) { goto WaitForReturnToTile(); };
		};
	};
	Actions
	{
		UI_LoadMissionPrompt("Hud_Mission_Bonus_UFO"); 
		
		if ( !cUFO )
		{
			Number nDirection(0);
			nDirection = lVehicleSpawn.GetDirection();
			cUFO = CreateAIVehicle( tVehicleType, "Aircraft", lVehicleSpawn, nDirection );	
			wait(0);
			cUFO.SetParked(true);		
		};
	};
};


// Checks to see if the player starts the mission or not - handles accepting the mission
State GiveMissionPrompts()
{
	Number n(0);
	
	Conditions
	{
//		 Gets out of the vehicle before pressing LB to initiate mission...
		if( cMissionPlayer.GetVehicle() != cUFO ) 
		{ 
			cUFO.SetParked(false);
			UI_HideMissionPrompt();
			MissionUnfocus();
			goto WaitForPlayerInVehicle(); 
		};

		if( PlayerPressedButton(cMissionPlayer, "A") ) 
		{ 
			MissionActivate();  // START THE MISSION!						
		};
	};
	Actions
	{
		UI_ShowMissionPrompt("Hud_Mission_Bonus_UFO", "MISSION_INSTRUCTIONS_UFO", "MISSION_PROMPT", "MISSION_TITLE_UFO");	
	};
};

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////


state Cleanup()
{
	Actions
	{
		// cleanup stuff...
		if ( cLiveStock01 )
		{
			cLiveStock01.Kill();
			cLiveStock01 = "";
		};
		
		if ( cLiveStock02 )
		{
			cLiveStock02.Kill();
			cLiveStock02 = "";
		};
		
		if ( cLiveStock03 )
		{
			cLiveStock03.Kill();
			cLiveStock03 = "";
		};
		
		if ( cLiveStock04 )
		{
			cLiveStock04.Kill();
			cLiveStock04 = "";
		};
		
		if ( cLiveStock05 )		
		{
			cLiveStock05.Kill();
			cLiveStock05 = "";
		};
		
		if ( cUFO )
		{
			cUFO.Destroy();
			cUFO = "";
		};
		
		if  ( hMissionStart )
		{
			hMissionStart.SetActive(false);
		};
		if (hCaptureArea)
		{
			hCaptureArea.SetActive(false);
		};
		// All tidy, let the game know...
		MissionCleanupEnd();
	};
};


/////////////////////////////////////////////////////////////////////////////////
//// Mission Loop
/////////////////////////////////////////////////////////////////////////////////


state Begin()
{
	Actions
	{
		UI_StartMission();
		hMissionStart.Trigger();
		hCaptureArea.SetActive(true);
		hCaptureArea.NoCondition();
		cUFO.SetParked(false);
		cMissionPlayer.SetNoTagRelease(false);
		missionTimer = 0;
		UI_SetHUDTimer( nTimeLimit, 1, missionTimer );
		UI_ShowHUDTimer(true);
		goto AbductCheck();	
	};
};


State AbductCheck()
{
	Text tDebug("");
	Timer ResetCounterTime(0);

	Conditions
	{		
		if ( cLiveStock01 )
		{
			if ( bLiveStockFree01 ) 
			{
				if ( cLiveStock01.InArea( aTargetA )  AND  cLiveStock01.InArea( aTargetB ) ) 
				{
					nTargetsCaught = nTargetsCaught + 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree01 = false;
					if (nLiveStockCaught01 == 0)
					{
						nLiveStockCaught01 = 1;
						Playergivestuds(nLiveStockAward);
					};
				};
			}
			else
			{
				if ( !cLiveStock01.InArea( aTargetA )  OR  !cLiveStock01.InArea( aTargetB ) ) 
				{
					nTargetsCaught = nTargetsCaught - 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree01 = true;
				};
			};
		};
		
		
		if ( cLiveStock02 )
		{
			if ( bLiveStockFree02 ) 
			{
				if ( cLiveStock02.InArea( aTargetA )  AND  cLiveStock02.InArea( aTargetB ) ) 
				{
					nTargetsCaught = nTargetsCaught + 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree02 = false;
					if (nLiveStockCaught02 == 0)
					{
						nLiveStockCaught02 = 1;
						Playergivestuds(nLiveStockAward);
					};					
				};
			}
			else
			{
				if ( !cLiveStock02.InArea( aTargetA )  OR  !cLiveStock02.InArea( aTargetB ) )
				{
					nTargetsCaught = nTargetsCaught - 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree02 = true;
				};
			};
		};
		
		
		if ( cLiveStock03 )
		{
			if ( bLiveStockFree03 ) 
			{
				if ( cLiveStock03.InArea( aTargetA )  AND  cLiveStock03.InArea( aTargetB ) ) 
				{
					nTargetsCaught = nTargetsCaught + 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree03 = false;
					if (nLiveStockCaught03 == 0)
					{
						nLiveStockCaught03 = 1;
						Playergivestuds(nLiveStockAward);
					};								
				};
			}
			else
			{
				if ( !cLiveStock03.InArea( aTargetA )  OR  !cLiveStock03.InArea( aTargetB ) )
				{
					nTargetsCaught = nTargetsCaught - 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree03 = true;
				};
			};
		};
		
		
		if ( cLiveStock04 )
		{
			if ( bLiveStockFree04 ) 
			{
				if ( cLiveStock04.InArea( aTargetA )  AND  cLiveStock04.InArea( aTargetB ) ) 
				{
					nTargetsCaught = nTargetsCaught + 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree04 = false;
					if (nLiveStockCaught04 == 0)
					{
						nLiveStockCaught04 = 1;
						Playergivestuds(nLiveStockAward);
					};								
				};
			}
			else
			{
				if ( !cLiveStock04.InArea( aTargetA )  OR  !cLiveStock04.InArea( aTargetB ) ) 
				{
					nTargetsCaught = nTargetsCaught - 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree04 = true;
				};
			};
		};
		
		
		
		if ( cLiveStock05 )
		{
			if ( bLiveStockFree05 ) 
			{
				if ( cLiveStock05.InArea( aTargetA )  AND  cLiveStock05.InArea( aTargetB ) ) 
				{
					nTargetsCaught = nTargetsCaught + 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree05 = false;
					if (nLiveStockCaught05 == 0)
					{
						nLiveStockCaught05 = 1;
						Playergivestuds(nLiveStockAward);
					};								
				};
			}
			else
			{
				if ( !cLiveStock05.InArea( aTargetA )  OR  !cLiveStock05.InArea( aTargetB ) ) 
				{
					nTargetsCaught = nTargetsCaught - 1;
					UI_SetMissionCounter( nTargetsCaught, nMaxTargets, false, 1.5  );
					UI_ShowMissionCounter( true );
					ResetCounterTime = 0;			
					bCounterOn = true;
					bLiveStockFree05 = true;
				};
			};
		};
		
		
		if ( bCounterOn  AND  ResetCounterTime > 2.5 )
		{
			UI_ShowMissionCounter( false );
			bCounterOn = false;
		};
		
		if( nTargetsCaught >= nMaxTargets ) { goto FinishedMission(); };
		
		if( cMissionPlayer.GetVehicle() != cUFO OR !cMissionPlayer.InArea(aUFO_OutOfBound)) { goto AbandonedWaitForTimer(); };
		
		if( missionTimer > nTimeLimit ) { goto OutOfTime(); };		
	};
	Actions
	{
		Number nDirection(0);
		UI_SetHeroBarMax(nHeroMax);
		if (cLiveStock01 == "")
		{
			nDirection = lSpawnLiveStock01.GetDirection();	
			cLiveStock01 = CreateAICharacter( "BusinessMan", "Pedestrian", lSpawnLiveStock01, nDirection );
		};
		if (cLiveStock02 == "")
		{
			nDirection = lSpawnLiveStock02.GetDirection();
			cLiveStock02 = CreateAICharacter( "BusinessMan", "Pedestrian", lSpawnLiveStock02, nDirection );
		};
		if (cLiveStock03 == "")
		{		
			nDirection = lSpawnLiveStock03.GetDirection();
			cLiveStock03 = CreateAICharacter( "BusinessMan", "Pedestrian", lSpawnLiveStock03, nDirection );
		};
		if (cLiveStock04 == "")
		{		
			nDirection = lSpawnLiveStock04.GetDirection();
			cLiveStock04 = CreateAICharacter( "BusinessMan", "Pedestrian", lSpawnLiveStock04, nDirection );
		};
		if (cLiveStock05 == "")
		{		
			nDirection = lSpawnLiveStock05.GetDirection();
			cLiveStock05 = CreateAICharacter( "BusinessMan", "Pedestrian", lSpawnLiveStock05, nDirection );		
		};
	};
};


// ---------------- Out Of Time ---------------- ;
// Called if the timer reaches 0
State OutOfTime()
{
	Conditions
	{
	};
	Actions
	{
		cUFO.SetParked(true);
		cMissionPlayer.SetNoTagRelease(true);
		UI_StopHUDTimer();
		UI_ShowHUDTimer(false);
		UI_EndMission("MISSION_FAIL_TIMEOUT", false);
		goto HandleFailScreen();
	};
};


// Wait for the timer to get to 5 seconds...
State AbandonedWaitForTimer()
{
	Timer tAbandon(0);
	Conditions
	{
//		 If player gets back into the pizza bike, don't reinitialise the mission, just goes back to WaitForNextCheckpoint state.
		if( cMissionPlayer.GetVehicle() == cUFO AND cMissionPlayer.InArea(aUFO_OutOfBound) ) 
		{ 
			UI_RemoveMissionMessage();
			goto AbductCheck(); 
		};
//		 If the player enters any vehicle other than the race car, immediately abandon the mission.
		if( cMissionPlayer.GetVehicle()  AND  cMissionPlayer.GetVehicle() != cUFO ) 
		{ 
			UI_RemoveMissionMessage();
			goto Abandoned(); 
		};
		if( tAbandon > 7.5 ) 
		{ 
			UI_RemoveMissionMessage();
			goto Abandoned(); 
		};
		If (!wlFarmLands.IsLoaded() AND !wlFarmLands2.IsLoaded() AND !wlFarmLands3.IsLoaded())
		{
			goto Abandoned();
		};
	};
	Actions
	{
		UI_SetMissionMessage("MISSION_GENERIC_RETURN_TO_MISSION");
	};
};


// Player has officially abandoned the mission.
State Abandoned()
{
	Conditions
	{
	};
	Actions
	{
//		 Reset the mission and cleanup anything being used
		UI_StopHUDTimer();
		UI_ShowHUDTimer(false);
		cUFO.SetParked(true);		
		UI_EndMission("MISSION_GENERIC_ABANDONED", false);
		goto HandleFailScreen();
	};
};


State HandleFailScreen( )
{
	Timer time(0);
	Bool b(false);
	Conditions
	{
		if ( time > 0.1  AND  ( PlayerPressedButton(cMissionPlayer, "A")  OR  PlayerPressedButton("Y") ) AND !b )
		{
			UI_ResetMission();
			goto ResetMission();
		}
		else
		{
			if ( (b AND !cMissionPlayer.GetVehicle()) OR  PlayerPressedButton(cMissionPlayer, "A")  OR  PlayerPressedButton("Y") )
			{
				UI_ResetMission();
				goto ResetMission();
			};
		};
		
	};
	Actions
	{
		if ( cMissionPlayer.GetVehicle() ) 
		{
			b = true;
		};	
	};
};



// Handles Mission complete
State FinishedMission()
{
	Conditions
	{
	};
	Actions
	{		
		UI_StopHUDTimer();
		UI_ShowHUDTimer(false);	
		// UI_EndMission("MISSION_COMPLETE", true);
		goto ResetMission();
	};
};


// Reset everything in the mission so it's in a state to be restarted
State ResetMission()
{
	Conditions
	{
	};
	Actions
	{
		UI_SetStatsStuds();		
		hCaptureArea.SetActive(false);		
		Wait(2.5);
		FadeScreen(true);		
		Wait(1);
		cLiveStock01.Kill();
		cLiveStock02.Kill();
		cLiveStock03.Kill();
		cLiveStock04.Kill();
		cLiveStock05.Kill();		
		cUFO.SetParked(false);
		cUFO.SetLocked(false);
		cMissionPlayer.ReleaseTakeOver();
		// cUFO.Deactivate();
		// Number nDirection(0);
		// nDirection = lVehicleSpawn.GetDirection();
		// cUFO = CreateCharacter( tVehicleType, lVehicleSpawn, "default", nDirection );	
		
		Wait(2);
		FadeScreen(false);
		if ( nTargetsCaught >= nMaxTargets )
		{
			MissionComplete(); // NEEDS TO CHECK AGAINST MISSION COMPLETE STATUS AND FAIL / END MISSION IF MISSION FAILED / ABANDONED ONCE THAT STATE IS AVAILABLE
		}
		else
		{
			MissionAbort();
		};	
		// goto WaitForPlayerInVehicle();
	};
};