function point_direction_vec(pointA,pointB)
 --Returns the direction from Vector A to Vector B.
 return math.atan2(pointA.Y - pointB.Y,pointA.X - pointB.X);
end
function Speak(person,text,length)
 --Set the text.
 ActivityMan:GetActivity():ResetMessageTimer(Activity.PLAYER_1);
 FrameMan:ClearScreenText(Activity.PLAYER_1);
 FrameMan:SetScreenText(string.upper(person.PresetName) .. ": " .. text, Activity.PLAYER_1, 0, length, false); 
 --Add the marker.
 local marker = CreateAEmitter("Prison Escape Ep2.rte/Speech Marks");
 marker.Mass = person.ID;
 marker.Lifetime = length;
 MovableMan:AddParticle(marker);
end
function PrisonEscapeMission2:StartActivity()
 --Create an invisible brain.
 self.brain = CreateActor("Base.rte/Brain Case");
 self.brain.Team = Activity.TEAM_1;
 self.brain.Pos = Vector(600,550);
 self.brain.Scale = 0;
 self.brain.GetsHitByMOs = false;
 self.brain.HitsMOs = false;
 MovableMan:AddActor(self.brain);
 self:SetPlayerBrain(self.brain,Activity.PLAYER_1);
 self:SwitchToActor(self.brain,Activity.PLAYER_1,-1); 
 --Actors to spawn.
 local guard1 = CreateAHuman("Base.rte/Robot 2");
 guard1.Pos = Vector(1430,360);
 guard1.Team = Activity.TEAM_2;
 MovableMan:AddActor(guard1);
 guard1:SetControllerMode(Controller.CIM_NETWORK,-1);
 guard1.HFlipped = true; 
 local guard2 = CreateAHuman("Base.rte/Robot 2");
 guard2.Pos = Vector(1440,456);
 guard2.Team = Activity.TEAM_2;
 MovableMan:AddActor(guard2);
 guard2:SetControllerMode(Controller.CIM_NETWORK,-1);
 guard2.HFlipped = true; 
 local guard3 = CreateAHuman("Base.rte/Robot 2");
 guard3.Pos = Vector(1260,626);
 guard3.Team = Activity.TEAM_2;
 MovableMan:AddActor(guard3);
 guard3:SetControllerMode(Controller.CIM_NETWORK,-1);
 guard3.HFlipped = true; 
 self.soldier1 = CreateAHuman("Prison Escape Ep2.rte/Soldier Light");
 self.soldier1.Pos = Vector(2220,456);
 self.soldier1.Team = Activity.TEAM_2;
 self.soldier1.HFlipped = true;
 self.soldier1:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Pistol"));
 MovableMan:AddActor(self.soldier1);
 self.soldier1.AIMode = Actor.AIMODE_SENTRY; 
 local soldier2 = CreateAHuman("Prison Escape Ep2.rte/Soldier Light");
 soldier2.Pos = Vector(2029,648);
 soldier2.Team = Activity.TEAM_2;
 soldier2.HFlipped = false;
 soldier2:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Compact Assault Rifle"));
 MovableMan:AddActor(soldier2);
 soldier2.AIMode = Actor.AIMODE_SENTRY; 
 self.soldier3 = CreateAHuman("Prison Escape Ep2.rte/Soldier Light");
 self.soldier3.Pos = Vector(2895,384);
 self.soldier3.Team = Activity.TEAM_2;
 self.soldier3.HFlipped = true;
 self.soldier3:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Shotgun"));
 MovableMan:AddActor(self.soldier3);
 self.soldier3.AIMode = Actor.AIMODE_SENTRY; 
 self.soldier4 = CreateAHuman("Prison Escape Ep2.rte/Soldier Heavy");
 self.soldier4.Pos = Vector(3324,408);
 self.soldier4.Team = Activity.TEAM_2;
 self.soldier4.HFlipped = true;
 self.soldier4:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Compact Assault Rifle"));
 MovableMan:AddActor(self.soldier4);
 self.soldier4.AIMode = Actor.AIMODE_SENTRY; 
 self.soldier5 = CreateAHuman("Prison Escape Ep2.rte/Soldier Heavy");
 self.soldier5.Pos = Vector(3420,408);
 self.soldier5.Team = Activity.TEAM_2;
 self.soldier5.HFlipped = true;
 self.soldier5:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Compact Assault Rifle"));
 MovableMan:AddActor(self.soldier5);
 self.soldier5.AIMode = Actor.AIMODE_SENTRY; 
 --Blocks player's exit through first opening.
 self.shield1 = CreateMOSRotating("Prison Escape Ep2.rte/Force Field V");
 self.shield1.Pos = Vector(1932,420);
 MovableMan:AddParticle(self.shield1); 
 --Blocks player from exiting during first battle.
 self.shield2 = CreateMOSRotating("Prison Escape Ep2.rte/Force Field H");
 self.shield2.Pos = Vector(2190,504);
 self.shield2.HFlipped = true;
 MovableMan:AddParticle(self.shield2); 
 self.shield3 = CreateMOSRotating("Prison Escape Ep2.rte/Force Field H");
 self.shield3.Pos = Vector(2190,552);
 self.shield3.HFlipped = true;
 MovableMan:AddParticle(self.shield3); 
 --Blocks player's exit through second opening.
 self.shield4 = CreateMOSRotating("Prison Escape Ep2.rte/Force Field V");
 self.shield4.Pos = Vector(2796,324);
 MovableMan:AddParticle(self.shield4); 
 --Blocks player's entrance into the enemy spawn room.
 self.shield5 = CreateMOSRotating("Prison Escape Ep2.rte/Force Field H Ballistic");
 self.shield5.Pos = Vector(3618,600);
 MovableMan:AddParticle(self.shield5); 
 --The enemy brain.
 self.enemyBrain = CreateActor("Prison Escape Ep2.rte/Richard Borno");
 self.enemyBrain.Pos = Vector(3372,368);
 self.enemyBrain.Team = Activity.TEAM_2;
 self.enemyBrain.GetsHitByMOs = false;
 MovableMan:AddActor(self.enemyBrain); 
 --The escape rocket.
 self.rocket = CreateAEmitter("Prison Escape Ep2.rte/Escape Rocket");
 self.rocket.Pos = Vector(3852,499);
 self.rocket.PinStrength = 99999;
 MovableMan:AddParticle(self.rocket); 
 --A floating health symbol implying that there's an actor next to the ship.
 self.symbol = CreateActor("Base.rte/Brain Case");
 self.symbol.RotAngle = 0;
 self.symbol.HFlipped = true;
 self.symbol.Scale = 0;
 self.symbol.Team = Activity.TEAM_1;
 self.symbol.Pos = Vector(3876,520);
 self.symbol.PresetName = "Fiona";
 MovableMan:AddActor(self.symbol); 
 --Something for enemies to aim at on the ship.
 self.aimer = CreateActor("Base.rte/Brain Case");
 self.aimer.Scale = 0;
 self.aimer.Team = Activity.TEAM_1;
 self.aimer.Pos = Vector(3852,460);
 MovableMan:AddActor(self.aimer); 
 --The cloning tube.
 self.cloneTube = CreateAEmitter("Prison Escape Ep2.rte/Clone Generator");
 self.cloneTube.Pos = Vector(3372,528);
 self.cloneTube:EnableEmission(false);
 self.cloneTube.Team = Activity.TEAM_2;
 MovableMan:AddParticle(self.cloneTube); 
 --The gun maker.
 self.gunMaker = CreateAEmitter("Prison Escape Ep2.rte/Gun Maker");
 self.gunMaker.Pos = Vector(3470,492);
 self.gunMaker:EnableEmission(false);
 self.gunMaker.Team = Activity.TEAM_2;
 MovableMan:AddParticle(self.gunMaker); 
 --The shield maker.
 self.shieldMaker = CreateAEmitter("Prison Escape Ep2.rte/Shield Maker");
 self.shieldMaker.Pos = Vector(3566,492);
 self.shieldMaker:EnableEmission(false);
 self.shieldMaker.Team = Activity.TEAM_2;
 MovableMan:AddParticle(self.shieldMaker); 
 --The enemy spawn room
 self.spawnRoom = SceneMan.Scene:GetArea("Enemy Spawn Room"); 
 --Timer to count events.
 self.eventTimer = Timer(); 
 --How fast the ship falls.
 self.shipFallSpeed = 40; 
 --Where the ship actually landed.
 self.landingSpot = Vector(); 
 --The player's last position.
 self.playerPos = Vector(); 
 --How often ending clones should shoot.
 self.shootTime = 500;
 self.shootTimer = Timer(); 
 --Whether the player was HFlipped.
 self.playerHFlip = false; 
 --Where the player was aiming.
 self.playerAim = 0;
 --Which of the endings the player got.
 self.endMsg = 0; 
 --Give the player no funds.
 self:SetTeamFunds(0,Activity.TEAM_1); 
 if checkpoint == nil then
  --The current event stage.
  self.eventStage = 0;
  --Items the player has.
  hasDeagle = true;
  hasPstl = false;
  hasCAR = false;
  hasAR = false;
  hasShotgun = false;
  hasShield = false;  
  --How many times the player has respawned.
  respawns = 0;  
  --What the camera should be focusing on.
  self.target = self.brain;  
  --What AIMode the target should be in.
  self.targetMode = Controller.CIM_NETWORK;  
  --Don't play music yet.
  AudioMan:StopMusic();
 else
  --The current event stage.
  self.eventStage = 64;
  --Set the actor's position.
  self.playerPos = Vector(3350,415);  
  --What AIMode the target should be in.
  self.targetMode = Controller.CIM_PLAYER;  
  --Spawn Fiona.
  self.partner = CreateAHuman("Prison Escape Ep2.rte/Fiona");
  self.partner:SetControllerMode(Controller.CIM_NETWORK,-1);
  self.partner.Pos = SceneMan:MovePointToGround(Vector(50,0),0,0);
  self.partner.Team = Activity.TEAM_1;
  self.partner:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Amazon Pistol"));
  self.partner:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Amazon Pistol (Offhand)"));
  MovableMan:AddActor(self.partner);  
  --Report the amount of respawns.
  self:ReportDeath(Activity.TEAM_1,respawns + 1);  
  --Play music.
  AudioMan:ClearMusicQueue();
  AudioMan:PlayMusic("Prison Escape Ep2.rte/Sound/Music/Plucked_From_Space.ogg", -1, -1);  
  self.startup = true;
 end
end
function PrisonEscapeMission2:UpdateActivity()
 if self.startup and self.eventTimer:IsPastSimMS(100) then
  --Kill all enemies.
  for actor in MovableMan.Actors do
   if actor.Team == Activity.TEAM_2 then
    if actor.PresetName == "Richard Borno" then
     actor.ToDelete = true;
    else
     actor.Health = 0;
    end
   end
  end  
  self.startup = false;
 end
 --Keep the brain's health invisible.
 self.brain.Team = -1;
 if self:ActivityOver() == false then
  --Stay controlling the target.
  if MovableMan:IsActor(self.target) then
   if self:GetControlledActor(Activity.TEAM_1) == nil then
    self:SwitchToActor(self.target,Activity.PLAYER_1,Activity.TEAM_1);
   else
    --If the target isn't already controlled, switch to it.
    local other = self:GetControlledActor(Activity.PLAYER_1);
    if self.target.ID ~= other.ID then
     self:SwitchToActor(self.target,Activity.PLAYER_1,Activity.TEAM_1);     
     --Set the target's controller mode.
     if self.targetMode == Controller.CIM_NETWORK then
      self.target:SetControllerMode(Controller.CIM_NETWORK,-1);
     else
      self.target:SetControllerMode(Controller.CIM_PLAYER,Activity.PLAYER_1);
     end     
     --Set the last actor back to the right mode.
     other:SetControllerMode(Controller.CIM_NETWORK,-1);
    end
   end
  end 
  --Respawn the player if they died.
  local playerAlive = true;
  if MovableMan:IsActor(self.playerActor) == false then
   playerAlive = false;
  elseif self.playerActor.Health <= 0 then
   self.playerActor.ToDelete = true;
   playerAlive = false;
  else
   --Keep the player in the right mode.
   if self.playerActor:IsPlayerControlled() == false then
    --Set the target's controller mode.
    if self.targetMode == Controller.CIM_NETWORK then
     self.playerActor:SetControllerMode(Controller.CIM_NETWORK,-1);
    else
     self.playerActor:SetControllerMode(Controller.CIM_PLAYER,Activity.PLAYER_1);
    end
   end  
   --Update the player's position.
   self.playerPos.X = self.playerActor.Pos.X;
   self.playerPos.Y = self.playerActor.Pos.Y;
   self:SetObservationTarget(self.playerPos,Activity.PLAYER_1);   
   --Update the player's aim.
   self.playerAim = self.playerActor:GetAimAngle(false);
   self.playerHFlip = self.playerActor.HFlipped;   
   --Update the player's inventory.
   if self.playerActor:HasObject("Pistol") then
    hasPistol = true;
   end
   if self.playerActor:HasObject("Compact Assault Rifle") then
    hasCAR = true;
   end
   if self.playerActor:HasObject("Assault Rifle") then
    hasAR = true;
   end
   if self.playerActor:HasObject("Shotgun") then
    hasShotgun = true;
   end
   if self.playerActor:HasObject("Riot Shield") then
    hasShield = true;
   end   
   --Keep the player inside the level.
   if self.playerActor.Pos.X < 0 then
    self.playerActor.Pos.X = 0;
    self.playerActor.Vel.X = 0;
   end   
   if self.playerActor.Pos.X > SceneMan.SceneWidth then
    self.playerActor.Pos.X = SceneMan.SceneWidth;
    self.playerActor.Vel.X = 0;
   end
  end  
  --Check that the actor isn't inside of a rocket.
  if MovableMan:IsActor(self.escapeRocket) then
   if self.escapeRocket:HasObject("Dafred") then
    playerAlive = true;
   end
  end  
  if playerAlive == false and self.eventStage >= 6 then 
   respawns = respawns + 1;
   self.playerActor = CreateAHuman("Prison Escape Ep2.rte/Dafred");
   self.playerActor.Pos = self.playerPos;
   self.playerActor.HFlipped = self.playerHFlip;
   self.playerActor:SetAimAngle(self.playerAim);
   self.playerActor.Team = Activity.TEAM_1;   
   --Give the player their items back.
   self.playerActor:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Desert Eagle"));   
   if hasPistol then
    self.playerActor:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Pistol"));
   end
   if hasCAR then
    self.playerActor:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Compact Assault Rifle"));
   end
   if hasAR then
    self.playerActor:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Assault Rifle"));
   end
   if hasShotgun then
    self.playerActor:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Shotgun"));
   end
   if hasShield then
    self.playerActor:AddInventoryItem(CreateHeldDevice("Base.rte/Riot Shield"));
   end
   MovableMan:AddActor(self.playerActor);
   self:SwitchToActor(self.playerActor,Activity.PLAYER_1,Activity.TEAM_1);   
   self.target = self.playerActor;
  end
  --After a few seconds, send the dropship hurtling in.
  if self.eventTimer:IsPastSimMS(2500) and self.eventStage == 0 then
   self.ship = CreateMOSRotating("Prison Escape Ep2.rte/Ruined Ship");
   self.ship.Pos = Vector(0,0);
   self.ship.RotAngle = math.pi * 1.25;
   MovableMan:AddParticle(self.ship);   
   self.eventStage = 1;
  end  
  --Make the dropship land in the desired spot.
  if MovableMan:IsParticle(self.ship) then
   if self.ship:GetAltitude(0,0) > 50 then
    self.ship.Vel = SceneMan:ShortestDistance(self.ship.Pos,Vector(600,550),false);
    self.ship.Vel = (self.ship.Vel / self.ship.Vel.Largest) * self.shipFallSpeed;
   elseif self.ship.Vel.Magnitude < 15 and self.ship.Vel.Magnitude > -15 and self.eventStage == 1 then
    --Pin the ship in place and make a crashing sound.
    self.ship.PinStrength = 99999;
    self.ship.Vel = Vector(0,0);
    self.ship.RotAngle = 3.36;
    local sound = CreateAEmitter("Prison Escape Ep2.rte/Crash Sound Emitter");
    sound.Pos = self.ship.Pos;
    MovableMan:AddParticle(sound);    
    --Store where the ship landed.
    self.landingSpot = self.ship.Pos;    
    --Play music.
    AudioMan:ClearMusicQueue();
    AudioMan:PlayMusic("Prison Escape Ep2.rte/Sound/Music/What_It_Feels_Like.ogg", -1, -1);    
    self.eventStage = 2;
   end   
   --Keep the dropship in place.
   if self.eventStage >= 2 then
    self.ship.Pos = self.landingSpot;
   end  
   --3 door hits.
   if self.eventTimer:IsPastSimMS(5000) and self.eventStage == 2 then
    local sound = CreateAEmitter("Prison Escape Ep2.rte/Hit Sound 1 Emitter");
    sound.Pos = self.ship.Pos;
    MovableMan:AddParticle(sound);    
    self.eventStage = 3;
   end   
   if self.eventTimer:IsPastSimMS(6400) and self.eventStage == 3 then
    local sound = CreateAEmitter("Prison Escape Ep2.rte/Hit Sound 2 Emitter");
    sound.Pos = self.ship.Pos;
    MovableMan:AddParticle(sound);    
    self.eventStage = 4;
   end   
   if self.eventTimer:IsPastSimMS(8000) and self.eventStage == 4 then
    local sound = CreateAEmitter("Prison Escape Ep2.rte/Hit Sound 3 Emitter");
    sound.Pos = self.ship.Pos;
    MovableMan:AddParticle(sound);
    --Break off the door.
    local doorPos = Vector();
    local doorAng = 0;    
    for i=1,MovableMan:GetMOIDCount()-1 do
     local mo = MovableMan:GetMOFromID(i);
     if mo.RootID == self.ship.ID and mo.PresetName == "Ruined Ship Door" then
      doorPos = mo.Pos;
      doorAng = mo.RotAngle;
      ToAttachable(mo):Detach();
     end
    end    
    local door = CreateAttachable("Prison Escape Ep2.rte/Ruined Ship Door");
    door.Pos = doorPos;
    door.RotAngle = doorAng;
    door.Vel = Vector(-5,2);
    door.AngularVel = 3;
    door.GetsHitByMOs = false;
    MovableMan:AddParticle(door);    
    self.ship.GetsHitByMOs = false;    
    self.eventStage = 5;
   end   
   --Spawn the player from inside the ship.
   if self.eventTimer:IsPastSimMS(8300) and self.eventStage == 5 then
    self.playerActor = CreateAHuman("Prison Escape Ep2.rte/Dafred");
    self.playerActor.Pos = self.ship.Pos + Vector(-25,-10);
    self.playerActor.Vel = Vector(-11,-10);
    self.playerActor.HFlipped = true;
    self.playerActor.Team = Activity.TEAM_1;
    self.playerActor.AIMode = Actor.AIMODE_SENTRY;
    MovableMan:AddActor(self.playerActor);
    self.playerActor:SetControllerMode(Controller.CIM_NETWORK,-1);    
    --Move the camera over.
    self.brain.Pos = self.brain.Pos + Vector(-200,0);    
    self.eventStage = 6;
   end   
   --Spawn Fiona.
   if self.eventTimer:IsPastSimMS(9400) and self.eventStage == 6 then
    self.partner = CreateAHuman("Prison Escape Ep2.rte/Fiona");
    self.partner.Pos = self.ship.Pos + Vector(-25,-10);
    self.partner.Vel = Vector(-10,-10);
    self.partner.HFlipped = true;
    self.partner.Team = Activity.TEAM_1;
    self.partner.AIMode = Actor.AIMODE_SENTRY;
    MovableMan:AddActor(self.partner);
    self.partner:SetControllerMode(Controller.CIM_NETWORK,-1);    
    self.eventStage = 7;
   end   
   --Make Fiona and Dafred not collide.
   if self.eventStage == 7 then
    local partsFound = false;
    for i=1,MovableMan:GetMOIDCount()-1 do
     local mo = MovableMan:GetMOFromID(i);
     if mo.RootID == self.partner.ID then
      partsFound = true;
      mo:SetWhichMOToNotHit(self.playerActor,-1);
     elseif mo.RootID == self.playerActor.ID then
      mo:SetWhichMOToNotHit(self.partner,-1);
     end
    end    
    if partsFound then
     self.eventStage = 8;
    end
   end   
   --Spawn Brutus.
   if self.eventTimer:IsPastSimMS(10100) and self.eventStage == 8 then
    self.survivor = CreateAHuman("Ronin.rte/Brutus");
    self.survivor.Pos = self.ship.Pos + Vector(-25,-10);
    self.survivor.Vel = Vector(-9,-10);
    self.survivor.HFlipped = true;
    self.survivor.Team = Activity.TEAM_1;
    self.survivor.AIMode = Actor.AIMODE_SENTRY;
    MovableMan:AddActor(self.survivor);
    self.survivor:SetControllerMode(Controller.CIM_NETWORK,-1);    
    self.eventStage = 9;
   end   
   --Explode the ship.
   if self.eventTimer:IsPastSimMS(11600) and self.eventStage == 9 then
    --Create the explosives.
    for i=1,5 do
     local bomb = CreateTDExplosive("Pineapple Grenade");
     bomb.Pos = self.ship.Pos + Vector(-25,-10);
     bomb.Vel = Vector(0,0);
     MovableMan:AddParticle(bomb);
     bomb:GibThis();
    end    
    --Make everyone look.
    for actor in MovableMan.Actors do
     if actor.ClassName == "AHuman" and actor.Team == Activity.TEAM_1 then
      actor.HFlipped = false;
      actor:SetAimAngle(math.pi / 5);
      actor.Pos.Y = SceneMan:MovePointToGround(actor.Pos,0,0).Y - 10;
     end
    end    
    self.eventStage = 10;
   end
  end
  --If Fiona is dead, fail.
  if self.eventStage >= 7 and self.eventStage <= 71 and MovableMan:IsActor(self.partner) == false then
   local inShip = false;
   if MovableMan:IsActor(self.escapeRocket) then
    if self.escapeRocket:HasObject("Fiona") then
     inShip = true;
    end
   end   
   if inShip == false then
    self.endMsg = 2;   
    self.WinnerTeam = Activity.TEAM_2;
    ActivityMan:EndActivity();
   end
  end
  --If the escape rocket has been destroyed, fail.
  if self.eventStage <= 70 and MovableMan:IsParticle(self.rocket) == false then
   self.symbol.ToDelete = true;
   self.aimer.ToDelete = true;   
   self:SetObservationTarget(Vector(3852,499),Activity.PLAYER_1);   
   self.partner.Pos = Vector(3880,534);
   self.partner.Health = 0;   
   self.endMsg = 3;   
   self.WinnerTeam = Activity.TEAM_2;
   ActivityMan:EndActivity();
  end
  if self.eventTimer:IsPastSimMS(12000) and self.eventStage == 10 then
   --Speech.
   Speak(self.partner,"Oh god, there were still people in there!",2500);
   self.eventStage = 11;
  end
  if self.eventTimer:IsPastSimMS(15000) and self.eventStage == 11 then
   --Speech.
   Speak(self.partner,"...I guess we'll have to go on without them.",2500);   
   --Let the ship settle.
   self.ship.PinStrength = 0;
   self.ship.ToSettle = true;   
   --Turn everyone to look at Fiona.
   self.survivor.HFlipped = true;
   self.survivor:SetAimAngle(-math.pi / 

;
   self.playerActor:SetAimAngle(math.pi / 6);
   self.eventStage = 12;
  end
  if self.eventTimer:IsPastSimMS(16000) and self.eventStage == 12 then
   self.pda = CreateHDFirearm("Prison Escape Ep2.rte/PDA");   
   --Take Fiona's PDA out.
   self.partner:AddInventoryItem(self.pda);
   self.partner:SetAimAngle(0);   
   self.eventStage = 13;
  end  
  if self.eventTimer:IsPastSimMS(18000) and self.eventStage == 13 then
   --Speech.
   Speak(self.partner,"According to my PDA, we're right in front of a Coalition outpost.",2500);
   self.eventStage = 14;
  end  
  if self.eventTimer:IsPastSimMS(21000) and self.eventStage == 14 then
   --Speech.
   Speak(self.partner,"I think they're the ones who shot us down.  There has to be a rocket or something in there that we can escape with.",5000);
   self.eventStage = 15;
  end  
  if self.eventTimer:IsPastSimMS(26250) and self.eventStage == 15 then
   --Speech.
   Speak(self.survivor,"So you're telling me that we need to break into their base?",3000);
   self.eventStage = 16;
  end  
  if self.eventTimer:IsPastSimMS(29500) and self.eventStage == 16 then
   --Speech.
   Speak(self.partner,"Basically.",1500);
   self.eventStage = 17;
  end  
  if self.eventTimer:IsPastSimMS(31250) and self.eventStage == 17 then
   --Speech.
   Speak(self.survivor,"The three of us against their entire barracks?",2500);
   self.eventStage = 18;
  end  
  if self.eventTimer:IsPastSimMS(34000) and self.eventStage == 18 then
   --Speech.
   Speak(self.partner,"Well...  Yeah.",1500);   
   --Remove the PDA.
   self.pda.ToDelete = true;
   self.partner:SetAimAngle(math.pi / 

;
   self.eventStage = 19;
  end  
  if self.eventTimer:IsPastSimMS(35750) and self.eventStage == 19 then
   --Speech.
   Speak(self.survivor,"No turning back, nobody to save us, and a good chance that at least one of us will die?",4000);
   self.eventStage = 20;
  end  
  if self.eventTimer:IsPastSimMS(40000) and self.eventStage == 20 then
   --Speech.
   Speak(self.partner,"Look, if you've got a better plan, then-",1000);
   self.eventStage = 21;
  end  
  if self.eventTimer:IsPastSimMS(41100) and self.eventStage == 21 then
   --Speech.
   Speak(self.survivor,"AWESOME!  I'm going in.",2000);
   self.survivor:SetAimAngle(0);
   self.sGun = CreateHDFirearm("Prison Escape Ep2.rte/YAK47");
   self.survivor:AddInventoryItem(self.sGun);
   self.eventStage = 22;
  end  
  if self.eventStage >= 22 and self.eventStage < 26 then
   if self.survivor.Pos.X < 800 then
    self.survivor:GetController():SetState(Controller.MOVE_RIGHT,true);
    if self.survivor.Pos.X > 450 and self.survivor.Pos.X < 600 then
     self.survivor:GetController():SetState(Controller.BODY_JUMP,true);
    end    
    if self.survivor.Vel.Magnitude < 0.5 and self.survivor.Vel.Magnitude > -0.5 then
     self.survivor.Pos.Y = self.survivor.Pos.Y - 1;
    end
   else
    self.survivor.HFlipped = true;
    self.survivor.Pos.X = 800;
    self.survivor.Vel.X = 0;
   end
  end  
  if self.eventTimer:IsPastSimMS(43250) and self.eventStage == 22 then
   --Speech.
   Speak(self.partner,"Brutus, wait!",2000);
   self.eventStage = 23;
  end  
  if self.eventTimer:IsPastSimMS(45500) and self.eventStage == 23 then
   --Speech.
   Speak(self.partner,"What an idiot.  We should probably follow him before he gets himself killed.",3000);
   self.partner.HFlipped = true;
   self.partner:SetAimAngle(-math.pi / 

;
   self.eventStage = 24;
  end  
  if self.eventTimer:IsPastSimMS(48750) and self.eventStage == 24 then
   --Speech.
   Speak(self.partner,"Brutus, slow down!",2000);
   self.partner:SetAimAngle(0);
   self:SwitchToActor(self.playerActor,Activity.PLAYER_1,Activity.TEAM_1);   
   self.target = self.playerActor;
   self.targetMode = Controller.CIM_PLAYER;
   self.eventStage = 25;
  end  
  if self.eventStage == 25 then
   if self.playerActor.Pos.X > 575 then
    self.playerActor.Pos.X = 575;
    self.playerActor.Vel.X = 0;
   end   
   if self.partner.Pos.X > 450 and self.partner.Pos.X < 525 then
    self.partner:GetController():SetState(Controller.BODY_JUMP,true);
   end  
   if self.partner.Pos.X < 650 then
    self.partner:GetController():SetState(Controller.MOVE_RIGHT,true);
   end   
   if self.partner.Vel.Magnitude < 0.5 and self.partner.Vel.Magnitude > -0.5 then
    self.partner.Pos.Y = self.partner.Pos.Y - 1;
   end
   --Once everyone is in place...
   if self.partner.Pos.X > 625 and self.survivor.Pos.X > 775 and self.playerActor.Pos.X > 560 and self.eventStage == 25 then
    --Stop controlling the player for a moment.
    self.playerActor:SetControllerMode(Controller.CIM_NETWORK,-1);
    self.targetMode = Controller.CIM_NETWORK;
    self.playerActor.Vel.X = 0;   
    --Speech.
    Speak(self.partner,"Brutus, wait for us!  You can't possibly take them all down by yourself!",3000);
    self.partner:SetAimAngle(math.pi / 

;   
    --Make Brutus look at Fiona.
    self.survivor:SetAimAngle(-math.pi / 

;
    self.survivor.HFlipped = true;
    self.survivor.Pos.Y = SceneMan:MovePointToGround(self.survivor.Pos,0,0).Y - 10;   
    --Restart the timer's counting again.
    self.eventTimer:Reset();   
    self.eventStage = 26;
   end
  end  
  if self.eventStage == 25 or self.eventStage == 26 then
   if self.partner.Pos.X > 650 then
    self.partner.Vel.X = 0;
    self.partner.Pos.X = 650;
   end
  end  
  if self.eventStage >= 26 and self.eventStage <= 31 then
   --Turn the player to face them.
   self.playerActor.HFlipped = false;
  end  
  if self.eventTimer:IsPastSimMS(3250) and self.eventStage == 26 then
   Speak(self.survivor,"Pff, you guys are too slow.  Besides, this'll be a piece of cake.",3000);   
   self.eventStage = 27;
  end  
  if self.eventTimer:IsPastSimMS(6500) and self.eventStage == 27 then
   Speak(self.survivor,"Watch and learn, you wuss.  I'll walk all ov-",1000);   
   self.survivor.HFlipped = false;
   self.survivor:SetAimAngle(0);   
   self.eventStage = 28;
  end  
  if self.eventTimer:IsPastSimMS(7500) and self.eventStage == 28 then
   --Fire a shot to kill Brutus.
   self.killRifle = CreateHDFirearm("Prison Escape Ep2.rte/Hyper-Accurate HSR");
   self.killRifle.HFlipped = true;
   self.killRifle.Pos = self.survivor.Pos + Vector(500,-16);
   self.killRifle.PinStrength = 10000;
   MovableMan:AddItem(self.killRifle);
   self.killRifle:Activate();   
   self.eventStage = 29;
  end  
  if self.eventStage == 29 and MovableMan:IsActor(self.survivor) then
   --Keep Brutus from flying back.
   self.survivor.Vel = Vector(0,0);
  end  
  if MovableMan:IsActor(self.survivor) == false and self.eventStage == 29 then
   Speak(self.partner,"WOAH!  Get down!",1250);   
   --Don't count this death.
   self:ReportDeath(Activity.TEAM_1,-1);   
   --Remove the gun.
   self.killRifle.ToDelete = true;   
   --If Brutus' gun is still around, make sure it isn't any longer.
   if MovableMan:IsDevice(self.sGun) then
    self.sGun.ToSettle = true;
   end   
   --Let Brutus die.
   self.survivor.PinStrength = 0;   
   self.eventTimer:Reset();   
   self.eventStage = 30;
  end  
  if self.eventStage == 30 then
   self.partner:GetController():SetState(Controller.BODY_CROUCH,true);
   self.partner:GetController():SetState(Controller.MOVE_RIGHT,true);   
   self.playerActor:GetController():SetState(Controller.BODY_CROUCH,true);
   self.playerActor:GetController():SetState(Controller.MOVE_RIGHT,true);
  end
  if self.eventTimer:IsPastSimMS(1510) and self.eventStage == 30 then
   Speak(self.partner,"I knew it.  Guard robots.  Dammit, Brutus, we needed you...",4000);
   self.partner.Pos.Y = SceneMan:MovePointToGround(self.partner.Pos,0,0).Y - 10;
   self.partner:GetController():SetState(Controller.MOVE_RIGHT,true);
   self.playerActor:GetController():SetState(Controller.MOVE_RIGHT,true);   
   self.eventStage = 31;
  end
  if self.eventTimer:IsPastSimMS(6000) and self.eventStage == 31 then
   Speak(self.partner,"I wonder what kind of network connection they're on.  Let's see...",4000);   
   --Take Fiona's PDA out.
   self.pda = CreateHDFirearm("Prison Escape Ep2.rte/PDA");
   self.partner:AddInventoryItem(self.pda);
   self.partner:SetAimAngle(0);   
   self.eventStage = 32;
  end
  if self.eventTimer:IsPastSimMS(10250) and self.eventStage == 32 then
   Speak(self.partner,"...You're kidding me.  Their password is \"password\".  Their firmware is out of date, too.",4000);   
   self.eventStage = 33;
  end  
  if self.eventTimer:IsPastSimMS(16000) and self.eventStage == 33 then
   --Kill the robots.
   for actor in MovableMan.Actors do
    if actor.PresetName == "Robot 2" then
     actor.Health = 0;
     actor.Vel = Vector(math.random() * 2 - 1,math.random() * 2 - 1);       
     --Don't count this death.
     self:ReportDeath(Activity.TEAM_1,-1);
    end
   end   
   --Open the door.
   for actor in MovableMan.Actors do
    if actor.ClassName == "ADoor" and actor.Pos.X < 1850 then
     actor.Team = Activity.TEAM_1;
    end
   end   
   Speak(self.partner,"Okay, their front guard robots are disabled.  The rest of their security is out of range.",4000);   
   self.eventStage = 34;
  end  
  if self.eventTimer:IsPastSimMS(20250) and self.eventStage == 34 then
   Speak(self.partner,"Let's get going.  They'll be after us in no time now that their front entrance is wide open.",4000);   
   --Look at Dafred.
   self.partner.HFlipped = true;   
   --Put away the pda.
   self.pda.ToDelete = true;   
   --Give Fiona her weapons.
   self.pistolA = CreateHDFirearm("Prison Escape Ep2.rte/Amazon Pistol (Offhand)");
   self.partner:AddInventoryItem(self.pistolA);   
   --Give the player a weapon.
   self.playerActor:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Desert Eagle"));   
   --Switch control to Dafred again.
   self:SwitchToActor(self.playerActor,Activity.PLAYER_1,Activity.TEAM_1);
   self.targetMode = Controller.CIM_PLAYER;   
   self.eventStage = 35;
  end  
  if self.eventTimer:IsPastSimMS(20500) and self.eventStage == 35 then
   --Equip Fiona's second pistol.
   self.partner.HFlipped = true;
   self.pistolB = CreateHDFirearm("Prison Escape Ep2.rte/Amazon Pistol");
   self.partner:AddInventoryItem(self.pistolB);
   self.partner:GetController():SetState(Controller.WEAPON_CHANGE_PREV,true);
   self.partner:SetAimAngle(-0.1);   
   self.eventStage = 36;
  end  
  if self.eventTimer:IsPastSimMS(22000) and self.eventStage == 36 then
   if self.partner.Pos.X < 1734 then
    self.partner:GetController():SetState(Controller.MOVE_RIGHT,true);
   else
    self.partner.HFlipped = true;
   end
   if (self.partner.Pos.X > 750 and self.partner.Pos.X < 775) or (self.partner.Pos.X > 1450 and self.partner.Pos.X < 1500) then
    self.partner:GetController():SetState(Controller.BODY_JUMP,true);
   end   
   if self.partner.Vel.Magnitude < 0.5 and self.partner.Vel.Magnitude > -0.5 then
    self.partner.Pos.Y = self.partner.Pos.Y - 1;
   end   
   if self.playerActor.Pos.X > 1680 then
    self.playerActor.Vel.X = 0;
    self.playerActor.Pos.X = 1680;
   end   
   if self.playerActor.Pos.Y < 310 and self.playerActor.Pos.X > 1412 then
    self.playerActor.Pos.X = 1412;
    self.playerActor.Vel.X = 0;
   end  
   if self.partner.Pos.X > 1734 and self.playerActor.Pos.X > 1640 then
    --Stop controlling the player.
    self.playerActor:SetControllerMode(Controller.CIM_NETWORK,-1);
    self.targetMode = Controller.CIM_NETWORK;    
    --Speech
    Speak(self.partner,"I'm going to see what's behind this door.  Cover me.",4000);
    self.partner.HFlipped = true;
    self.playerActor.HFlipped = false;
    self.playerActor:SetAimAngle(0);    
    self.eventTimer:Reset();    
    self.eventStage = 37;
   end
  end  
  if self.eventStage == 37 and self.eventTimer:IsPastSimMS(4000) then
   self.partner:GetController():SetState(Controller.MOVE_RIGHT,true);
   if self.partner.Vel.Magnitude < 0.5 and self.partner.Vel.Magnitude > -0.5 then
    self.partner.Pos.Y = self.partner.Pos.Y - 1;
   end   
   if self.partner.Pos.X > 1875 then
    --Close the doors again.
    for actor in MovableMan.Actors do
     if actor.ClassName == "ADoor" and actor.Pos.X > 1750 and actor.Pos.X < 1850 then
      actor.Team = Activity.TEAM_2;
     end
    end    
    self.eventTimer:Reset();    
    self.eventStage = 38;
   end
  end  
  if self.eventStage == 38 and self.eventTimer:IsPastSimMS(1000) then
   self.partner.HFlipped = true;
   Speak(self.partner,"Unless you just shut that door, I'd say that they know we're here now.",4000);   
   self.eventStage = 39;
  end  
  if self.eventStage == 39 and self.eventTimer:IsPastSimMS(5250) then
   self.partner.HFlipped = true;
   Speak(self.partner,"I guess I won't be coming back out that way.  You check the other path, I'll take this portal.",4000);   
   self.eventStage = 40;
  end  
  if self.eventStage == 40 and self.eventTimer:IsPastSimMS(9500) then
   self.partner.HFlipped = true;
   Speak(self.partner,"Good luck.  Let's make sure the others' deaths weren't in vain.",4000);   
   self.eventStage = 41;
  end  
  if self.eventStage == 41 and self.eventTimer:IsPastSimMS(13750) then
   self.partner:GetController():SetState(Controller.MOVE_RIGHT,true);
   if self.partner.Vel.Magnitude < 0.5 and self.partner.Vel.Magnitude > -0.5 then
    self.partner.Pos.Y = self.partner.Pos.Y - 1;
   end   
   if self.partner.Pos.X > 2200 then
    --Switch control to Dafred again.
    self:SwitchToActor(self.playerActor,Activity.PLAYER_1,Activity.TEAM_1);
    self.targetMode = Controller.CIM_PLAYER;    
    --Play music.
    AudioMan:ClearMusicQueue();
    AudioMan:PlayMusic("Prison Escape Ep2.rte/Sound/Music/Mind_Stalker.ogg", -1, -1);    
    self.eventStage = 42;
   end
  end  
  if self.eventStage >= 42 then
   --Disable the teleporter.
   cantele[1]:Reset();
  end  
  if self.eventStage == 42 and MovableMan:IsActor(self.soldier1) == false then
   --Spawn the dropship with troops in it.
   self.enemyDropShip = CreateACDropShip("Prison Escape Ep2.rte/Drop Ship MK1 Slowspawn");
   self.enemyDropShip.Pos = Vector(1740,0);
   self.enemyDropShip:SetControllerMode(Controller.CIM_NETWORK,-1);
   self.enemyDropShip.Team = Activity.TEAM_2;
   self.attacker1 = CreateAHuman("Prison Escape Ep2.rte/Soldier Light");
   self.attacker1:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Pistol"));
   self.attacker1.Team = Activity.TEAM_2;
   self.attacker1:SetControllerMode(Controller.CIM_NETWORK,-1);
   self.attacker1.AIMode = Actor.AIMODE_GOTO;
   self.attacker1:AddAISceneWaypoint(Vector(2144,550));
   self.enemyDropShip:AddInventoryItem(self.attacker1);
   self.attacker2 = CreateAHuman("Prison Escape Ep2.rte/Soldier Light");
   self.attacker2:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Pistol"));
   self.attacker2.Team = Activity.TEAM_2;
   self.attacker2:AddInventoryItem(CreateHeldDevice("Prison Escape Ep2.rte/Riot Shield"));
   self.attacker2:SetControllerMode(Controller.CIM_NETWORK,-1);
   self.attacker2.AIMode = Actor.AIMODE_GOTO;
   self.attacker2:AddAISceneWaypoint(Vector(2144,550));
   self.enemyDropShip:AddInventoryItem(self.attacker2);   
   self.attacker3 = CreateAHuman("Prison Escape Ep2.rte/Soldier Heavy");
   self.attacker3:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Compact Assault Rifle"));
   self.attacker3.Team = Activity.TEAM_2;
   self.attacker3:SetControllerMode(Controller.CIM_NETWORK,-1);
   self.attacker3.AIMode = Actor.AIMODE_GOTO;
   self.attacker3:AddAISceneWaypoint(Vector(2144,550));
   self.enemyDropShip:AddInventoryItem(self.attacker3);   
   MovableMan:AddActor(self.enemyDropShip);   
   self.eventStage = 43;
  end  
  if self.eventStage == 43 or self.eventStage == 44 then
   self.enemyDropShip.Pos.X = 1740;
  end  
  --Lower the dropship.
  if self.eventStage == 43 then
   self.enemyDropShip:GetController():SetState(Controller.MOVE_DOWN,true);   
   if self.enemyDropShip.Pos.Y > 150 then
    self.enemyDropShip:GetController():SetState(Controller.PRESS_FACEBUTTON,true);
    self.enemyDropShip:GetController():SetState(Controller.MOVE_DOWN,false);    
    self.eventStage = 44;
   end
  end  
  --Let the actors come out.
  if self.eventStage == 44 then
   if self.enemyDropShip.Pos.Y > 200 then
    self.enemyDropShip:GetController():SetState(Controller.MOVE_UP,true);
   end   
   if MovableMan:IsActor(self.attacker1) and MovableMan:IsActor(self.attacker2) and MovableMan:IsActor(self.attacker3) then
    self.enemyDropShip:GetController():SetState(Controller.PRESS_FACEBUTTON,true);
    self.eventStage = 45;
   end
  end  
  --Make the actors move.
  if self.eventStage == 44 or self.eventStage == 45 then
   if MovableMan:IsActor(self.attacker1) then
    if self.attacker1:GetController().InputMode == Controller.CIM_NETWORK then
     self.attacker1:GetController():SetState(Controller.MOVE_RIGHT,true);
     if self.attacker1.Pos.X > 1968 then
      self.attacker1:SetControllerMode(Controller.CIM_AI,-1);
     end    
    end
   end   
   if MovableMan:IsActor(self.attacker2) then
    if self.attacker2:GetController().InputMode == Controller.CIM_NETWORK then
     self.attacker2:GetController():SetState(Controller.MOVE_RIGHT,true);
     if self.attacker2.Pos.X > 1968 then
      self.attacker2:SetControllerMode(Controller.CIM_AI,-1);
     end    
    end
   end   
   if MovableMan:IsActor(self.attacker3) then
    if self.attacker3:GetController().InputMode == Controller.CIM_NETWORK then
     self.attacker3:GetController():SetState(Controller.MOVE_RIGHT,true);
     if self.attacker3.Pos.X > 1968 then
      self.attacker3:SetControllerMode(Controller.CIM_AI,-1);
     end    
    end
   end
  end   
  --Take off again.
  if self.eventStage == 45 then 
   if MovableMan:IsActor(self.enemyDropShip) then
    self.enemyDropShip:GetController():SetState(Controller.MOVE_UP,true);
   end  
   --If the player has killed all the enemies, let the shields down.
   if (MovableMan:IsActor(self.attacker1) == false or self.attacker1.PresetName == "Dafred") and (MovableMan:IsActor(self.attacker2) == false or self.attacker2.PresetName == "Dafred") and (MovableMan:IsActor(self.attacker3) == false or self.attacker1.PresetName == "Dafred") then
    self.shield2.ToDelete = true;
    self.shield3.ToDelete = true;    
    self.eventStage = 46;
   end
  end  
  if self.eventStage == 46 and (MovableMan:IsActor(self.soldier3) == false or self.soldier3.PresetName == "Dafred") then
   self.dropCrate = CreateACRocket("Dummy.rte/Drop Crate");
   self.dropCrate.Pos = Vector(2796,0);
   self.dropCrate.Team = Activity.TEAM_2;   
   local attacker4 = CreateAHuman("Prison Escape Ep2.rte/Soldier Light");
   attacker4.Team = Activity.TEAM_2;
   attacker4.AIMode = Actor.AIMODE_PATROL;
   attacker4:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Pistol"));
   self.dropCrate:AddInventoryItem(attacker4);   
   local attacker5 = CreateAHuman("Prison Escape Ep2.rte/Soldier Light");
   attacker5.Team = Activity.TEAM_2;
   attacker5.AIMode = Actor.AIMODE_PATROL;
   attacker5:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Pistol"));
   self.dropCrate:AddInventoryItem(attacker5);   
   local attacker6 = CreateAHuman("Prison Escape Ep2.rte/Soldier Light");
   attacker6.Team = Activity.TEAM_2;
   attacker6.AIMode = Actor.AIMODE_PATROL;
   attacker6:AddInventoryItem(CreateHDFirearm("Prison Escape Ep2.rte/Pistol"));
   self.dropCrate:AddInventoryItem(attacker6);   
   MovableMan:AddActor(self.dropCrate);   
   self.eventStage = 47;
  end  
  if MovableMan:IsActor(self.dropCrate) then
   self.dropCrate.RotAngle = math.pi;
  end  
  if self.eventStage == 47 then
   --Keep the crate moving down.
   self.dropCrate.Vel.Y = 15;  
   --Break the doors off.
   if self.dropCrate.Pos.Y > 240 then
    for actor in MovableMan.Actors do
     if actor.PresetName == "Door Rotate Short" and actor.Pos.X > 2711 and actor.Pos.X < 2855 then
      actor:GibThis();      
      --Don't count this death.
      self:ReportDeath(Activity.TEAM_2,-1);
      self.eventStage = 48;
     end
    end
   end
  end  
  if self.eventStage == 48 then
   --If the player has killed all the guards and is in the room...
   if (MovableMan:IsActor(self.soldier4) == false or self.soldier4.PresetName == "Dafred") and (MovableMan:IsActor(self.soldier5) == false or self.soldier5.PresetName == "Dafred") then
    if self.playerActor.Pos.X > 3318 then
     --Lose control momentarily.
     self.playerActor:SetControllerMode(Controller.CIM_NETWORK,-1);
     self.targetMode = Controller.CIM_NETWORK;
     self.playerActor.HFlipped = false;
     self.playerActor:SetAimAngle(math.pi - point_direction_vec(self.playerActor.Pos,self.enemyBrain.Pos));
     self.enemyBrain.GetsHitByMOs = true;     
     Speak(self.enemyBrain,"Don't even think about it.  That would be a very bad move.",4000);     
     --Stop music.
     AudioMan:ClearMusicQueue();
     AudioMan:StopMusic();
     self.eventTimer:Reset();
     self.eventStage = 49;
    end
   end
  end  
  if self.eventStage == 49 and self.eventTimer:IsPastSimMS(4250) then
   Speak(self.enemyBrain,"Let's put it this way - if you kill me, the whole Coalition army will be after you.",5000);
   self.eventStage = 50;
  end  
  if self.eventStage == 50 and self.eventTimer:IsPastSimMS(10250) then
   Speak(self.enemyBrain,"You're already on their wanted list.  Don't make it any worse for yourself.",5000);   
   self.eventStage = 51;
  end  
  if self.eventStage == 51 and self.eventTimer:IsPastSimMS(15500) then
   Speak(self.enemyBrain,"Now, put down the gun.",2000);   
   self.eventStage = 52;
  end  
  if self.eventStage == 52 and self.eventTimer:IsPastSimMS(19750) then
   self.disarmed = CreateHeldDevice("Disarmed");
   self.playerActor:AddInventoryItem(self.disarmed);
   self.playerActor:GetController():SetState(Controller.WEAPON_CHANGE_PREV,true);   
   self.eventStage = 53;
  end  
  if self.eventStage == 53 and self.eventTimer:IsPastSimMS(20000) then
   Speak(self.enemyBrain,"Good.  Now, I happen to know that you have a friend with you.  She's in the next room over.",5000);   
   self.eventStage = 54;
  end  
  if self.eventStage == 54 and self.eventTimer:IsPastSimMS(25250) then
   Speak(self.enemyBrain,"After the stunt she pulled off, helping you escape from the prison,",4000);   
   self.eventStage = 55;
  end  
  if self.eventStage == 55 and self.eventTimer:IsPastSimMS(29500) then
   Speak(self.enemyBrain,"she has quite a bounty on her head.  So, I'll make you a deal.",4000);   
   self.eventStage = 56;
  end  
  if self.eventStage == 56 and self.eventTimer:IsPastSimMS(34750) then
   Speak(self.enemyBrain,"Leave her with my guards, and I'll let you go, scot-free.  Nobody will know you were here.",5000);   
   self.eventStage = 57;
  end  
  if self.eventStage == 57 and self.eventTimer:IsPastSimMS(40000) then
   Speak(self.enemyBrain,"She won't even know you left her.  I'll let you right out with that rocket.",5000);   
   self.eventStage = 58;
  end  
  if self.eventStage == 58 and self.eventTimer:IsPastSimMS(45250) then
   self.disarmed.ToDelete = true;   
   self.eventStage = 59;
  end
  if self.eventStage == 59 and self.eventTimer:IsPastSimMS(45500) then
   self.newDeagle = CreateHDFirearm("Prison Escape Ep2.rte/Desert Eagle");
   self.playerActor:AddInventoryItem(self.newDeagle);
   self.playerActor:GetController():SetState(Controller.WEAPON_CHANGE_PREV,true);
   self.playerActor:SetAimAngle(math.pi - point_direction_vec(self.playerActor.Pos,self.enemyBrain.Pos));   
   self.eventStage = 60;
  end  
  if self.eventStage == 60 and self.eventTimer:IsPastSimMS(45750) then
   self.playerActor:GetController():SetState(Controller.WEAPON_FIRE,true);   
   --Play music.
   AudioMan:ClearMusicQueue();
   AudioMan:PlayMusic("Prison Escape Ep2.rte/Sound/Music/Plucked_From_Space.ogg", -1, -1);   
   self.eventStage = 61;
  end  
  if self.eventStage == 61 and self.eventTimer:IsPastSimMS(46000) then
   Speak(self.enemyBrain,"AUGH, MY BRAIN!  You'll pay for that!",1500);   
   self.eventStage = 62;
  end  
  if self.eventStage == 62 and self.eventTimer:IsPastSimMS(48000) then
   self.enemyBrain.Pos.Y = self.enemyBrain.Pos.Y - 0.5;
   if self.enemyBrain.Pos.Y < 288 then
    self.ePos = Vector(self.enemyBrain.Pos.X,self.enemyBrain.Pos.Y);
    self.enemyBrain.ToDelete = true;    
    --Don't count this death.
    self:ReportDeath(Activity.TEAM_2,-1);    
    --Make the brain into a rocket.
    self.enemyBrain = CreateACRocket("Prison Escape Ep2.rte/Brain Rocket");
    self.enemyBrain.Pos = self.ePos;
    self.enemyBrain.Team = Activity.TEAM_2;
    self.enemyBrain.PinStrength = 9999;
    MovableMan:AddActor(self.enemyBrain);
    self.enemyBrain:EraseFromTerrain();    
    self.eventStage = 63;
   end
  end  
  if self.eventStage == 63 then
   if MovableMan:IsActor(self.enemyBrain) then
    self.enemyBrain.Pos.X = self.ePos.X;
    self.enemyBrain.RotAngle = 0;
    if self.enemyBrain.Pos.Y > 240 then
     self.enemyBrain.Pos.Y = self.enemyBrain.Pos.Y - 0.5;
    else
     self.enemyBrain.PinStrength = 0;
     self.enemyBrain:GetController():SetState(Controller.MOVE_UP,true);
    end
   else
    self.eventStage = 64;
    self:SwitchToActor(self.playerActor,Activity.PLAYER_1,Activity.TEAM_1);
    self.targetMode = Controller.CIM_PLAYER;
    self.newDeagle.ToDelete = true;
    self.playerActor:GetController():SetState(Controller.WEAPON_CHANGE_PREV,true);
   end
  end  
  if self.eventStage == 64 then
   if self.playerActor.Pos.X > 3760 then
    Speak(self.symbol,"Dafred!  Thank goodness you're still alive. We have a bit of a problem.",4000);    
    checkpoint = true;    
    self.eventStage = 65;
    self.eventTimer:Reset();
   end
  end  
  if self.eventStage == 65 and self.eventTimer:IsPastSimMS(4250) then
   Speak(self.symbol,"That room over there is their cloning station.  I heard it starting up a few minutes back.",4000);   
   self.eventStage = 66;
  end  
  if self.eventStage == 66 and self.eventTimer:IsPastSimMS(8500) then
   Speak(self.symbol,"Our escape rocket here has a busted thruster.  I can fix it, but I need time.",4000);   
   self.eventStage = 67;
  end  
  if self.eventStage == 67 and self.eventTimer:IsPastSimMS(12750) then
   Speak(self.symbol,"You look like you're in rough shape, but if you can hold them off for just a moment,",4000);   
   self.eventStage = 68;
  end  
  if self.eventStage == 68 and self.eventTimer:IsPastSimMS(17000) then
   Speak(self.symbol,"I can get this thing in working condition and we can get the hell out of here.",4000);   
   --Turn on the emitters.
   self.cloneTube:EnableEmission(true);
   self.gunMaker:EnableEmission(true);
   self.shieldMaker:EnableEmission(true);   
   self.eventStage = 69;
  end
  if self.eventStage == 69 and self.eventTimer:IsPastSimMS(21250) then
   Speak(self.symbol,"Crap, here they come!  Get ready!",4000);
   self.rocket:EnableEmission(true);   
   --Play music.
   AudioMan:ClearMusicQueue();
   AudioMan:PlayMusic("Prison Escape Ep2.rte/Sound/Music/HyperReactive.ogg", -1, -1);   
   --Start the timer.
   self.escapeTimer = Timer();   
   self.eventStage = 70;
  end  
  if self.eventStage >= 70 and self.eventStage < 72 then
   --Control new clones.
   for actor in MovableMan.Actors do
    if actor.Team == Activity.TEAM_2 then
     --Make them exit the room.
     if self.spawnRoom:IsInside(actor.Pos) then
      actor:SetControllerMode(Controller.CIM_NETWORK,-1);
      actor:GetController():SetState(Controller.MOVE_RIGHT,true);
      actor:GetController():SetState(Controller.WEAPON_PICKUP,true);      
      --If the actor hasn't equipped its pistol, do so.
      if actor:Inventory() ~= nil then
       if actor:Inventory().PresetName == "Pistol" then
        actor:GetController():SetState(Controller.WEAPON_CHANGE_PREV,true);
       end
      end
     elseif actor.Pos.X < 3750 and actor.Pos.Y > 500 and actor:GetController().InputMode == Controller.CIM_NETWORK then
      --Make them continue to walk forward and aim at the rocket.
      if MovableMan:IsParticle(self.rocket) then
       actor:SetAimAngle(math.pi - point_direction_vec(actor.Pos,self.rocket.Pos));
      end
      actor:GetController():SetState(Controller.MOVE_RIGHT,true);      
      --Fire periodically.
      if self.shootTimer:IsPastSimMS(self.shootTime + 100) then
       self.shootTimer:Reset();
      elseif self.shootTimer:IsPastSimMS(self.shootTime) then
       actor:GetController():SetState(Controller.WEAPON_FIRE,true);
      else
       actor:GetController():SetState(Controller.WEAPON_FIRE,false);
      end
     else
      --Turn AI on again.
      actor:SetControllerMode(Controller.CIM_AI,-1);      
      --Keep them down.
      if actor.Pos.Y < 575 then
       actor.Pos.Y = 575;
       actor.Vel.Y = 0;
      end
     end
    end
   end   
   --Display the time.
   if self.eventTimer:IsPastSimMS(21000) then
    FrameMan:SetScreenText(math.floor(self.escapeTimer:LeftTillSimMS(34000) / 1000) .. " SECONDS LEFT!", Activity.PLAYER_1, 0, 1, false);
   end
  end  
  if self.eventStage == 70 and self.escapeTimer:IsPastSimMS(34000) then
   --Activate the rocket.
   self.rocket.ToDelete = true;
   self.escapeRocket = CreateACRocket("Base.rte/Rocket MK2");
   self.escapeRocket.PinStrength = 99999;
   self.escapeRocket.Pos = Vector(3854,506);
   self.escapeRocket.Team = Activity.TEAM_1;
   self.escapeRocket.GetsHitByMOs = false;
   self.escapeRocket:SetControllerMode(Controller.CIM_NETWORK,-1);
   self.escapeRocket.RotAngle = 0;
   MovableMan:AddActor(self.escapeRocket);
   self.escapeRocket:GetController():SetState(Controller.PRESS_FACEBUTTON,true);   
   --Add Fiona back.
   self.partner.Pos = self.symbol.Pos + Vector(20,10);
   self.partner.HFlipped = true;
   self.symbol.ToDelete = true;
   self.aimer.ToDelete = true;   
   Speak(self.partner,"Okay, it's all patched up!  Get in, quick!",1500);   
   self.eventStage = 71;   
   self.eventTimer:Reset();
  end  
  if self.eventStage == 71 then
   self.escapeRocket.RotAngle = 0;
   if self.eventTimer:IsPastSimMS(1500) then 
    if MovableMan:IsActor(self.partner) then
     self.partner:GetController():SetState(Controller.BODY_JUMP,true);     
     if self.partner.Pos.X < 3850 then
      self.partner.Pos.X = 3850;
      self.partner.Vel.X = 0;
     end
    end
   end
   if self.escapeRocket:HasObject("Dafred") and self.escapeRocket:HasObject("Fiona") then
    self.escapeRocket.PinStrength = 0;    
    self.eventStage = 72;
   end
  end  
  if self.eventStage == 72 then
   if MovableMan:IsActor(self.escapeRocket) then
    self.escapeRocket:GetController():SetState(Controller.MOVE_UP,true);
    self.target = self.escapeRocket;
    self.targetMode = Controller.CIM_NETWORK;
    self.escapeRocket.Pos.X = 3852;
    self.escapeRocket.RotAngle = 0;
   end
  end
 end 
 --Objective markers.
 self:ClearObjectivePoints(); 
 if self.eventStage == 25 then
  self:AddObjectivePoint("Follow Brutus!",self.survivor.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
 end 
 if self.eventStage == 36 and MovableMan:IsActor(self.partner) then
  self:AddObjectivePoint("Follow Fiona!",self.partner.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
 end 
 if self.eventStage == 42 then
  if self.playerActor.Pos.X < 1980 then
   self:AddObjectivePoint("Continue ahead!",Vector(2122,560),Activity.TEAM_1,GameActivity.ARROWDOWN);
  elseif MovableMan:IsActor(self.soldier1) then
   self:AddObjectivePoint("Kill!",self.soldier1.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
  end
 end 
 if self.eventStage == 45 then
  if MovableMan:IsActor(self.attacker1) and self.attacker1.PresetName ~= "Dafred" then
   self:AddObjectivePoint("Kill!",self.attacker1.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
  end
  if MovableMan:IsActor(self.attacker2) and self.attacker2.PresetName ~= "Dafred" then
   self:AddObjectivePoint("Kill!",self.attacker2.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
  end
  if MovableMan:IsActor(self.attacker3) and self.attacker3.PresetName ~= "Dafred" then
   self:AddObjectivePoint("Kill!",self.attacker3.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
  end
 end 
 if self.eventStage == 46 then
  if self.playerActor.Pos.X < 2600 then
   self:AddObjectivePoint("Continue ahead!",Vector(2800,565),Activity.TEAM_1,GameActivity.ARROWDOWN);
  else
   self:AddObjectivePoint("Kill!",self.soldier3.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
  end
 end
 if self.eventStage == 48 then
  if self.playerActor.Pos.X < 3125 then
   self:AddObjectivePoint("Go for the brain!",self.enemyBrain.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
  else
   local soldiers = false;   
   if MovableMan:IsActor(self.soldier4) and self.soldier4.PresetName ~= "Dafred" then
    self:AddObjectivePoint("Kill!",self.soldier4.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
    soldiers = true;
   end
   if MovableMan:IsActor(self.soldier5) and self.soldier5.PresetName ~= "Dafred" then
    self:AddObjectivePoint("Kill!",self.soldier5.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
    soldiers = true;
   end   
   if soldiers == false then
    self:AddObjectivePoint("Walk up to the brain!",self.enemyBrain.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
   end
  end
 end 
 if self.eventStage == 64 and MovableMan:IsActor(self.symbol) then
  self:AddObjectivePoint("Get to Fiona!",self.symbol.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
 end 
 if self.eventStage == 70 and MovableMan:IsActor(self.aimer) then
  self:AddObjectivePoint("Protect!",self.aimer.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
 end 
 if self.eventStage == 71 then
  self:AddObjectivePoint("Get in!",self.escapeRocket.AboveHUDPos + Vector(0,-8),Activity.TEAM_1,GameActivity.ARROWDOWN);
 end 
 self:YSortObjectivePoints();
end
function PrisonEscapeMission2:PauseActivity()
end
function PrisonEscapeMission2:EndActivity()
 --If the player won the level...
 if self.endMsg == 1 then
  self:ResetMessageTimer(Activity.PLAYER_1);
  FrameMan:ClearScreenText(Activity.PLAYER_1);
  FrameMan:SetScreenText("FIONA: Nice work!  That was a close call.  I'm plotting a course back to the base.", Activity.PLAYER_1, 0, 5000, false);
  checkpoint = nil;
 elseif self.endMsg == 2 then
  self:ResetMessageTimer(Activity.PLAYER_1);
  FrameMan:ClearScreenText(Activity.PLAYER_1);
  FrameMan:SetScreenText("Fiona is dead.  You have no pilot to escape with.  Mission failed.", Activity.PLAYER_1, 0, 5000, false);
 elseif self.endMsg == 3 then
  self:ResetMessageTimer(Activity.PLAYER_1);
  FrameMan:ClearScreenText(Activity.PLAYER_1);
  FrameMan:SetScreenText("Your escape ship is destroyed - you have no way of leaving the base.  Mission failed.", Activity.PLAYER_1, 0, 5000, false);
 end
end
function PrisonEscapeMission2:CraftEnteredOrbit()
 --If the end stage has been reached...
 if self.eventStage == 72 then
  if self.OrbitedCraft:HasObject("Dafred") and self.OrbitedCraft:HasObject("Fiona") then
   --Win!
   self.endMsg = 1;   
   self.WinnerTeam = Activity.TEAM_1;
   ActivityMan:EndActivity();   
   self.brain.Pos = Vector(3852,0);
  end
    end
end