Mission = {
};


function Mission:OnInit()
	-- you may want to load a string-table etc. here...
	-- System:SetConsoleImage("levels/M08/loadingm08.jpg",0);
end

function Mission:OnUpdate()
	local i;
	local bFinished=1;
	for i,objective in Mission do
		if (type(objective)~="function") then
			if (objective==0) then 
				bFinished=0;				
			else
			end
		end	
	end
	if (bFinished==1) then	
		self.Finish();
	end
end


function Mission:Finish()
	-- go to next mission...
end

function Mission:Event_SetRockets()
	local AIVehicle=System:GetEntityByName("Val4WD");
	if(AIVehicle)then
		AIVehicle.ammoRL = 6;
		AIVehicle.Ammo["VehicleRocket"] = AIVehicle.ammoRL;
	end
end


function Mission:SetValerieLeadCount( count ) 
	local val = System:GetEntityByName("Valerie");
	if (val) then
		System:LogToConsole("found Val");		
		val.Properties.LEADING_COUNT = count;
	end
end


function Mission:Event_JumpLeadTo_1ONE()
   Mission:SetValerieLeadCount( 1 );
end

function Mission:Event_JumpLeadTo_2TWO()
   Mission:SetValerieLeadCount( 2 );
end

function Mission:Event_JumpLeadTo_3THREE()
   Mission:SetValerieLeadCount( 3 );
end

function Mission:Event_JumpLeadTo_4FOUR()
   Mission:SetValerieLeadCount( 4 );
end

function Mission:Event_JumpLeadTo_5FIVE()
   Mission:SetValerieLeadCount( 5 );
end

function Mission:Event_JumpLeadTo_6SIX()
   Mission:SetValerieLeadCount( 6 );
end

function Mission:Event_JumpLeadTo_7SEVEN()
   Mission:SetValerieLeadCount( 7 );
end



function Mission:Event_MissionFinished()
   _localplayer.cnt:SavePlayerElements();
   Game:SendMessage('StartLevelFade Factory');
end

function Mission:Event_OutsideMap()
--System:Log("setting timetodie to 1");
	_localplayer.timetodie=1;	
	_localplayer:SetTimer(100);
end

function Mission:Event_ValerieDiesMissionFailed()	

	if (god) then
		god=nil;
	end	
	local ent = System:GetEntityByName("Valerie");	
	local pos=new(ent:GetPos());
	local ang=new(ent:GetAngles());
	_localplayer:SetPos(pos);
	_localplayer:SetAngles(ang);
	_localplayer.timetodie=1;	
	
end

-- InGameEvents


function Mission:Event_CollapsingGuardTower()
  Movie:PlaySequence('CollapsingGuardTower')
end

function Mission:Event_AlarmLight()
  Movie:PlaySequence('AlarmLight')
end

function Mission:Event_MoveplayerControlCenter()
	System:LogToConsole("Event_MoveplayerControlCenter");
	local CutsceneVal=System:GetEntityByName("Valerie_ControlCenterCutscene");
	local AIValerie=System:GetEntityByName("Valerie");
	if((CutsceneVal)and(AIValerie))then
		AIValerie:SetPos(new(CutsceneVal:GetPos()));
		AIValerie:SetAngles(new(CutsceneVal:GetAngles()));
	end
	local CutsceneJack=System:GetEntityByName("Jack_ControlCenterCutscene");
	if((CutsceneJack)and(_localplayer))then
		_localplayer:SetAngles(new(CutsceneJack:GetAngles()));
		_localplayer:SetPos(new(CutsceneJack:GetPos()));
	end	
end

function Mission:Event_MoveplayerHackingComputer()
	System:LogToConsole("Event_MoveplayerHackingComputer");
	local CutsceneVal=System:GetEntityByName("Valerie_HackingComputerCutscene");
	local AIValerie=System:GetEntityByName("Valerie");
	if((CutsceneVal)and(AIValerie))then
		AIValerie:SetPos(new(CutsceneVal:GetPos()));
		AIValerie:SetAngles(new(CutsceneVal:GetAngles()));
	end
	local CutsceneJack=System:GetEntityByName("Jack_HackingComputerCutscene");
	if((CutsceneJack)and(_localplayer))then
		_localplayer:SetAngles(new(CutsceneJack:GetAngles()));
		_localplayer:SetPos(new(CutsceneJack:GetPos()));
	end	
end

function Mission:Event_MoveplayerOutpostCoords()
	System:LogToConsole("Event_MoveplayerOutpostCoords");
	local CutsceneVal=System:GetEntityByName("Valerie_OutpostCoordsCutscene");
	local AIValerie=System:GetEntityByName("Valerie");
	if((CutsceneVal)and(AIValerie))then
		AIValerie:SetPos(new(CutsceneVal:GetPos()));
		AIValerie:SetAngles(new(CutsceneVal:GetAngles()));
	end
	local CutsceneJack=System:GetEntityByName("Jack_OutpostCoordsCutscene");
	if((CutsceneJack)and(_localplayer))then
		_localplayer:SetAngles(new(CutsceneJack:GetAngles()));
		_localplayer:SetPos(new(CutsceneJack:GetPos()));
	end	
end

function Mission:Event_MoveplayerStart()
	System:LogToConsole("Event_MoveplayerStart");
	local CutsceneVal=System:GetEntityByName("Valerie_StartCutscene");
	local AIValerie=System:GetEntityByName("Valerie");
	if((CutsceneVal)and(AIValerie))then
		AIValerie:SetPos(CutsceneVal:GetPos());
		AIValerie:SetAngles(CutsceneVal:GetAngles());
	end
end

function Mission:Event_Move4WDRide()
	local Dummy4WD=System:GetEntityByName("AB01_GI05_4WD_Dummy");
	local AI4WD=System:GetEntityByName("AB01_GI05_4WD");
	if((Dummy4WD)and(AI4WD))then
		AI4WD:SetPos(Dummy4WD:GetPos());
		AI4WD:SetAngles(Dummy4WD:GetAngles());
	end
end

function Mission:Event_Move4WDVal()

	if (Mission.AlreadyMoved==nil) then
		Mission.Event_Move4WDVal_ALWAYS();
		Mission.AlreadyMoved = 1;
	end
end

function Mission:Event_Move4WDVal_ALWAYS()
	local Dummy4WD=System:GetEntityByName("Val4WD_Dummy");
	local AI4WD=System:GetEntityByName("Val4WD");
	if((Dummy4WD)and(AI4WD))then
		AI4WD:SetPos(Dummy4WD:GetPos());
		AI4WD:SetAngles(Dummy4WD:GetAngles());
	end
end


function Mission:Event_SetPlayerHealth()
	_localplayer.cnt.health=255	
end
-- InGameMessage

function Mission:Event_M1AMessage()
	Hud:FlashObjectives({},"");
	Hud:SetRadarObjective("nil");	
--	Hud:AddMessage('Objective: Steal a car out of this camp!',10);
--	Hud:AddMessage('Objective: Get to the mercenary base!',10);
--	Hud:AddMessage('Hint: Avoid that they call reinforcement!',10);
	Hud:AddMessage(Localize("NewObjectives"),10);
	Hud:PushObjective({},Localize("StealACarOutOfTh"));
	Hud:PushObjective({},Localize("GetToTheMercenar"));
	Hud:SetRadarObjective("MissionObjective_1");
end

function Mission:Event_M1BMessage()
	Hud:AddMessage(Localize("NewObjectives"),10);
	Hud:CompleteObjective(Localize("StealACarOutOfTh"));
	Hud:SetRadarObjective("MissionObjective_2");
end

function Mission:Event_M1CMessage()
	-- Hud:AddMessage(Localize("ValerieIsGoingTo"),5);
	-- Hud:AddMessage(Localize("PleaseWaitUntilS"),5);
end

function Mission:Event_M1Message()
	-- Hud:AddMessage(Localize("CompletedGetToTh"),5);
	-- Hud:AddMessage('Objective: Get into the base and find a computer terminal',10);
	Hud:CompleteObjective(Localize("GetToTheMercenar"));
	Hud:AddMessage(Localize("NewObjective"),10);
	Hud:PushObjective({},Localize("GetIntoTheBaseAn"));
	Hud:SetRadarObjective("MissionObjective_3");
end

function Mission:Event_M2Message()
	-- Hud:AddMessage('Jack: Here is a terminal. Check this out!',10);
	-- Hud:AddMessage('Val: Wait there. I am coming!',10);
	Hud:SetRadarObjective("MissionObjective_4");
end

function Mission:Event_M3Message()
--	Hud:AddMessage('Val: Okay, Lets see!',10);
--	Hud:AddMessage('Val: I got the code for a door. Follow me now!',10);
	Hud:AddMessage(Localize("NewObjective"),10);
	Hud:CompleteObjective(Localize("GetIntoTheBaseAn"));
	Hud:PushObjective({},Localize("FollowValDoNotLo"));
	Hud:SetRadarObjective("MissionObjective_5");
end

function Mission:Event_M4Message()
--	Hud:AddMessage('Val: Okay, open!',10);
--	Hud:AddMessage('Val: Stay with me!',10);
	Hud:CompleteObjective(Localize("FindAWayInsideTh")); 
	Hud:SetRadarObjective("MissionObjective_5");
end


function Mission:Event_M5Message()
--	Hud:AddMessage('Val: Allright. Should be unlocked now!',10);
end

function Mission:Event_M6Message()
--	Hud:AddMessage('Val: The back door. Clever! It is unlocked!',10);
end

function Mission:Event_M7Message()
--	Hud:AddMessage('Val. Okay, the door is open!',10);
end

function Mission:Event_M8Message()
	-- Hud:AddMessage('Val: Allright. I will stay here and try to find the code for the next gate.',10);
	-- Hud:AddMessage('Val: You should enter the headqaurter and get the bomb access codes.',10);
	-- Hud:AddMessage('Val: I will unlock the doors for the headquarter! Good luck!',10);
	Hud:FlashObjectives({},"");
	Hud:AddMessage(Localize("NewObjective"),10);
	Hud:PushObjective({},Localize("GetTheBombAcessC"))
	Hud:SetRadarObjective("MissionObjective_6");
end

function Mission:Event_M9Message()
	-- Hud:AddMessage('Jack: I got the codes. How about you?',10);
	-- Hud:AddMessage('Valerie: Almost done. Come back to me.',10);
	Hud:CompleteObjective(Localize("GetTheBombAcessC")); 
	Hud:AddMessage(Localize("NewObjective"),10);
	Hud:PushObjective({},Localize("GoBackToTheContr"))
	Hud:SetRadarObjective("MissionObjective_5");
end

function Mission:Event_M10Message()
--	Hud:AddMessage('Valerie: I got it. Follow me again!',10);
	Hud:CompleteObjective(Localize("GoBackToTheContr")); 
	Hud:AddMessage(Localize("NewObjective"),10);
	Hud:PushObjective({},Localize("EscortVal"))
	Hud:SetRadarObjective("MissionObjective_7");
end

function Mission:Event_M11Message()
--	Hud:AddMessage('Okay, now we have to get inside the armoury and take the bomb!',10);
--	Hud:AddMessage('You are leading!',10);
	Hud:CompleteObjective(Localize("EscortVal")); 
	Hud:AddMessage(Localize("NewObjective"),10);
	Hud:PushObjective({},Localize("EnterArmoury"));
	Hud:SetRadarObjective("MissionObjective_8");
end

function Mission:Event_M11BMessage()
--	Hud:AddMessage('Val: Okay, we are in the armory now!',10);
--	Hud:AddMessage('Val: Lets find the bomb!',10);
	Hud:CompleteObjective(Localize("EnterArmoury")); 
	Hud:PushObjective({},Localize("GetTheBomb"))
end

function Mission:Event_M14Message()
--	Hud:AddMessage('Jack: Got it. Lets go!',10);
--	Hud:AddMessage('Val: Get in the car!',10);
	Hud:CompleteObjective(Localize("GetTheBomb")); 
end







