----------------------------------------------------------------------------------------- -- Start Activity ----------------------------------------------------------------------------------------- function BodyMovin:StartActivity() print("START! -- BodyMovin:StartActivity()!"); self.FightStage = { BEGINFIGHT = 0, ROOMCLEAR = 1, FIGHTSTAGECOUNT = 2 }; self.CrateTimer = Timer(); self.HackTimer = Timer(); self.SpawnTimer = Timer(); self.ScreenChange = false; self.roomArea = SceneMan.Scene:GetArea("Room"); self.rocketArea = SceneMan.Scene:GetArea("Rocket"); self.surpriseArea = SceneMan.Scene:GetArea("surprise"); self.dreadArea = SceneMan.Scene:GetArea("dreadnoughts"); self.compuArea = SceneMan.Scene:GetArea("putor"); self.prisonArea = SceneMan.Scene:GetArea("prison"); self.MOIDLimit = 220; gateonepassed = 0; gatetwopassed = 0; gatethreepassed = 0; self.brainInHangar = false; self.rocketspawned = false; self.roomclear = false; self.CurrentFightStage = self.FightStage.BEGINFIGHT; self.braindead = {}; self.AssignedBrains = {}; self.CPUBrain = nil; self.WeaponListC = {"Assault Rifle", "Auto Shotgun", "Mauler Shotgun"}; self.WeaponList = {"Blaster", "Dummy.rte/Sniper Rifle", "Dummy.rte/Grenade Launcher"}; self.LandingList = {"Landing 2", "Landing 3", "Landing 4", "Landing 5"}; -------------------------- -- Set up teams -- Team 2 is always CPU self.CPUTeam = Activity.TEAM_2; self.PlayerTeam = Activity.TEAM_1; self.RogueTeam = -1; ActivityMan:GetActivity():SetTeamFunds(-10000,0) ActivityMan:GetActivity():SetTeamFunds(-10000,1) if self.Difficulty <= GameActivity.CAKEDIFFICULTY then self.BaseSpawnTime = 10000; elseif self.Difficulty <= GameActivity.EASYDIFFICULTY then self.BaseSpawnTime = 8000; elseif self.Difficulty <= GameActivity.MEDIUMDIFFICULTY then self.BaseSpawnTime = 6000; elseif self.Difficulty <= GameActivity.HARDDIFFICULTY then self.BaseSpawnTime = 4000; elseif self.Difficulty <= GameActivity.NUTSDIFFICULTY then self.BaseSpawnTime = 3500; elseif self.Difficulty <= GameActivity.MAXDIFFICULTY then self.BaseSpawnTime = 3000; end -- for team = 0, self.TeamCount - 1 do -- end -- Set up AI modes for the Actors that have been added to the scene by the scene definition for actor in MovableMan.AddedActors do if actor.Team == self.CPUTeam and actor.PresetName == "Dummy" then actor:SetControllerMode(Controller.CIM_AI, -1); actor.AIMode = Actor.AIMODE_BRAINHUNT; actor:AddInventoryItem(CreateHDFirearm(self.WeaponList[math.random(#self.WeaponList)])); actor:AddInventoryItem(CreateTDExplosive("Impulse Grenade")); end if actor.Team == self.PlayerTeam and actor.PresetName == "Soldier Light" then actor:AddInventoryItem(CreateHDFirearm(self.WeaponListC[math.random(#self.WeaponListC)])); end if actor.Team == self.PlayerTeam and actor.PresetName == "Soldier Heavy" and not self.prisonArea:IsInside(actor.Pos) then actor:AddInventoryItem(CreateHDFirearm(self.WeaponListC[math.random(#self.WeaponListC)])); end if actor.Team == self.CPUTeam and actor.PresetName == "Dreadnought" then actor:SetControllerMode(Controller.CIM_AI, -1); actor.AIMode = Actor.AIMODE_SENTRY; end end end ----------------------------------------------------------------------------------------- -- Pause Activity ----------------------------------------------------------------------------------------- function BodyMovin:PauseActivity(pause) print("PAUSE! -- BodyMovin:PauseActivity()!"); end ----------------------------------------------------------------------------------------- -- End Activity ----------------------------------------------------------------------------------------- function BodyMovin:EndActivity() print("END! -- BodyMovin:EndActivity()!"); end ----------------------------------------------------------------------------------------- -- Update Activity ----------------------------------------------------------------------------------------- function BodyMovin:UpdateActivity() -- Clear all objective markers, they get re-added each frame self:ClearObjectivePoints(); -- Keep spawning dummies self:EnemySpawn(); if self.roomclear and self.brainInHangar and not self.rocketspawned then self:SpawnRocket(); end if gatethreepassed == 0 and not (self.ActivityState == Activity.OVER) then self:SecurityShutdown(); end if gateonepassed == 0 then self:Surprise(); end if gatetwopassed == 0 then self:Surprise2(); end -- Check for defeat conditions self:BrainCheck(); -- Sort the objective points self:YSortObjectivePoints(); end ----------------------------------------------------------------------------------------- -- Brain selection and gameover conditions check ----------------------------------------------------------------------------------------- function BodyMovin:BrainCheck() -- Iterate through player 1 for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do if self:PlayerActive(Activity.PLAYER_1) and self:PlayerHuman(Activity.PLAYER_1) then -- The current player's team local team = self:GetTeamOfPlayer(player); -- Make sure the game is not already ending if not (self.ActivityState == Activity.OVER) then -- Check if any player's brain is dead local brain = self:GetPlayerBrain(Activity.PLAYER_1); if not brain or not MovableMan:IsActor(brain) or not brain:HasObjectInGroup("Brains") then self:SetPlayerBrain(nil, Activity.PLAYER_1); -- Try to find a new unasigned brain this player can use instead, or if his old brain entered a craft local newBrain = MovableMan:GetUnassignedBrain(team); -- Found new brain actor, assign it and keep on truckin' if newBrain then self:SetPlayerBrain(newBrain, Activity.PLAYER_1); self:SwitchToActor(newBrain, Activity.PLAYER_1, team); else FrameMan:SetScreenText("Your brain has been lost!", player, 333, -1, false); -- Now see if all brains of self player's team are dead, and if so, end the game if not MovableMan:GetClosestBrainActor(team) then self.WinnerTeam = self:OtherTeam(team); ActivityMan:EndActivity(); print("END! -- BodyMovin:EndActivity()!"); end self:ResetMessageTimer(Activity.PLAYER_1); end else -- Update the observation target to the brain, so that if/when it dies, the view flies to it in observation mode self:SetObservationTarget(self:GetPlayerBrain(Activity.PLAYER_1).Pos, Activity.PLAYER_1) end -- Game over, show the appropriate messages until a certain time elseif not self.GameOverTimer:IsPastSimMS(self.GameOverPeriod) then -- TODO: make more appropriate messages here for run out of funds endings if team == self.WinnerTeam then FrameMan:SetScreenText("Well done, you made it!", Activity.PLAYER_1, 0, -1, false); else FrameMan:SetScreenText("Your brain has been lost!", Activity.PLAYER_1, 0, -1, false); end end end end end -------------------------------------------- -- Dummy Spawning & Objectives -------------------------------------------- function BodyMovin:EnemySpawn() if self.SpawnTimer:IsPastSimMS(self.BaseSpawnTime) and MovableMan:GetMOIDCount() <= self.MOIDLimit then local rocket = CreateACRocket("Drop Crate"); local dummy = CreateAHuman("Dummy"); local gun = CreateHDFirearm(self.WeaponList[math.random(#self.WeaponList)]); dummy:AddInventoryItem(gun); if math.random() < 0.6 then dummy:AddInventoryItem(CreateTDExplosive("Impulse Grenade")); end rocket:AddInventoryItem(dummy); -- See if there is a designated LZ Area for attackers, and only land over it local attackLZ = SceneMan.Scene:GetArea(self.LandingList[math.random(#self.LandingList)]); if attackLZ then rocket.Pos = Vector(attackLZ:GetRandomPoint().X, 0); rocket.Team = self.CPUTeam; rocket:SetControllerMode(Controller.CIM_AI, -1); -- Let the spawn into the world, passing ownership MovableMan:AddActor(rocket); -- Wait another period for next spawn self.SpawnTimer:Reset(); end end local liveenemies = 0; local brainsinhangar = 0; local rocketsspawned = 0; for actor in MovableMan.Actors do if actor.PresetName == "Rocket MK1" then self.rocketspawned = true; rocketsspawned = rocketsspawned + 1; if actor:HasObject("Brain Robot") then self:AddObjectivePoint("Launch into orbit!", actor.AboveHUDPos + Vector(0, -32), Activity.TEAM_1, GameActivity.ARROWUP); else self:AddObjectivePoint("Get In!", actor.AboveHUDPos + Vector(0, -32), Activity.TEAM_1, GameActivity.ARROWDOWN); end elseif actor.PresetName == ("Brain Robot") then self:AddObjectivePoint("Protect!", actor.AboveHUDPos, Activity.TEAM_1, GameActivity.ARROWDOWN); end if self.CrateTimer:IsPastSimMS(20000) and actor.PresetName == ("Drop Crate") then actor:GibThis(); self.CrateTimer:Reset(); end if self.rocketArea:IsInside(actor.Pos) and actor.PresetName == "Brain Robot" then self.brainInHangar = true; brainsinhangar = brainsinhangar + 1; end if actor.Team == self.CPUTeam and self.roomArea:IsInside(actor.Pos) and self.brainInHangar then self.roomclear = false; liveenemies = liveenemies + 1; self:AddObjectivePoint("Destroy!", actor.AboveHUDPos, Activity.TEAM_1, GameActivity.ARROWDOWN); end end if liveenemies == 0 then self.roomclear = true; end if brainsinhangar == 0 then self.brainInHangar = false; end if rocketsspawned == 0 then self.rocketspawned = false; end end -------------------------------------------- -- Shutdown Security -------------------------------------------- function BodyMovin:SecurityShutdown() local gatethreepass = false; for actor in MovableMan.Actors do if self.compuArea:IsInside(actor.Pos) and actor.PresetName == "Brain Robot" then gatethreepass = true; end end if self.CurrentFightStage == self.FightStage.BEGINFIGHT and not gatethreepass then self:AddObjectivePoint("Security Override", Vector(2952, 996), Activity.TEAM_1, GameActivity.ARROWDOWN); end if gatethreepass == true then if self.HackTimer:LeftTillSimMS(60000) > 0 then self:AddObjectivePoint("Loading... " .. math.ceil(self.HackTimer:LeftTillSimMS(60000)/1000) .. " seconds left.", Vector(2952, 996), Activity.TEAM_1, GameActivity.ARROWDOWN); end if -self.HackTimer:LeftTillSimMS(0) > 60000 then which = math.random(); if which < 0.6 then for actor in MovableMan.Actors do if actor.ClassName == "ADoor" then actor.Team = Activity.TEAM_1; self:ResetMessageTimer(Activity.PLAYER_1); -- Display the text of the current step FrameMan:ClearScreenText(Activity.PLAYER_1); FrameMan:SetScreenText("Success! Security systems online!", Activity.PLAYER_1, 500, 8000, true); end end elseif which > 0.6 then for actor in MovableMan.Actors do if actor.ClassName == "ADoor" then actor:GibThis(); self:ResetMessageTimer(Activity.PLAYER_1); -- Display the text of the current step FrameMan:ClearScreenText(Activity.PLAYER_1); FrameMan:SetScreenText("Error! Critical failure!", Activity.PLAYER_1, 500, 8000, true); end end end gatethreepassed = 1; end else self.HackTimer:Reset(); end end -------------------------------- -- Surprise -------------------------------- function BodyMovin:Surprise() local gateonepass = false; for actor in MovableMan.Actors do if self.dreadArea:IsInside(actor.Pos) and actor.Team == Activity.TEAM_1 then gateonepass = true; end end if gateonepass == true then local dummy = CreateAHuman("Dummy"); local dummytwo = CreateAHuman("Dummy"); dummy:AddInventoryItem(CreateHDFirearm("Dummy.rte/Sniper Rifle")); dummy.Pos = Vector(86.8672, 908.664); dummy.Team = self.CPUTeam; dummy:SetControllerMode(Controller.CIM_AI, -1); dummy.AIMode = Actor.AIMODE_SENTRY; dummytwo:AddInventoryItem(CreateHDFirearm("Dummy.rte/Sniper Rifle")); dummytwo.Pos = Vector(84.7969, 980.992); dummytwo.Team = self.CPUTeam; dummytwo:SetControllerMode(Controller.CIM_AI, -1); dummytwo.AIMode = Actor.AIMODE_SENTRY; MovableMan:AddActor(dummy); MovableMan:AddActor(dummytwo); local rocket = CreateACRocket("Drop Crate"); local dread = CreateACrab("Dreadnought"); rocket:AddInventoryItem(dread); -- See if there is a designated LZ Area for attackers, and only land over it local attackLZ = SceneMan.Scene:GetArea("Landing 1"); if attackLZ then rocket.Pos = Vector(attackLZ:GetRandomPoint().X, 744); rocket.Team = self.CPUTeam; rocket:SetControllerMode(Controller.CIM_AI, -1); --Let the spawn into the world, passing ownership MovableMan:AddActor(rocket); gateonepassed = 1; end end end ---------------------------- -- Surprise 2 ---------------------------- function BodyMovin:Surprise2() local gatetwopass = false; for actor in MovableMan.Actors do if self.surpriseArea:IsInside(actor.Pos) and actor.PresetName == "Brain Robot" then gatetwopass = true; end end if gatetwopass == true then local rocket = CreateACRocket("Drop Crate"); local dummy = CreateACrab("Dreadnought"); rocket:AddInventoryItem(dummy); -- See if there is a designated LZ Area for attackers, and only land over it local attackLZ = SceneMan.Scene:GetArea("Landing 1"); if attackLZ then rocket.Pos = Vector(228, 744); rocket.Team = self.CPUTeam; rocket:SetControllerMode(Controller.CIM_AI, -1); --Let the spawn into the world, passing ownership MovableMan:AddActor(rocket); gatetwopassed = 1; end end self:AddObjectivePoint("Evacuate!", Vector(324, 1044), Activity.TEAM_1, GameActivity.ARROWDOWN); end ----------------------------- ---- Evac ------------------------------ function BodyMovin:SpawnRocket() local rocket = CreateACRocket("Rocket MK1"); -- See if there is a designated LZ Area for rescuers, and only land over it local attackLZ = SceneMan.Scene:GetArea("Landing 1"); if attackLZ then rocket.AIMODE = Actor.AIMODE_STAY; rocket.Pos = Vector(attackLZ:GetRandomPoint().X, 0); rocket.Team = Activity.TEAM_1; -- Let the spawn into the world, passing ownership MovableMan:AddActor(rocket); -- Take over control of screen messages self:ResetMessageTimer(Activity.PLAYER_1); -- Display the text of the current step FrameMan:ClearScreenText(Activity.PLAYER_1); FrameMan:SetScreenText("Rescue vessel incoming!", Activity.PLAYER_1, 500, 8000, true); -- Advance the stage end end ----------------------------------------------------------------------------------------- -- Craft Entered Orbit ----------------------------------------------------------------------------------------- function BodyMovin:CraftEnteredOrbit() -- This is set to the ACraft that just entered orbit if self.OrbitedCraft:HasObject("Brain Robot") then -- WINRAR! self.WinnerTeam = Activity.TEAM_1; ActivityMan:EndActivity(); end end