Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 40f3fc1

Browse files
committed
Fix lua formatting style and add semicolons ":D" (also make OMA spawn enemies less frequently, damn)
1 parent 7e7c84d commit 40f3fc1

File tree

1 file changed

+94
-99
lines changed

1 file changed

+94
-99
lines changed

Base.rte/Activities/OneManArmy.lua

Lines changed: 94 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ dofile("Base.rte/Constants.lua")
33
function OneManArmy:StartActivity()
44

55
self.BuyMenuEnabled = false;
6-
-- Brain strength multiplier
7-
self.multiplier = math.ceil(11 - (self.Difficulty * 0.1)); -- Med = 6, Max = 11, Min = 1
6+
--Brain strength multiplier
7+
self.multiplier = math.ceil(11 - (self.Difficulty * 0.1)); --Med = 6, Max = 11, Min = 1
88

99
local primaryGroup = "Weapons - Heavy";
1010
local secondaryGroup = "Weapons - Light";
11-
-- Tertiary weapon is always a grenade
11+
--Tertiary weapon is always a grenade
1212
local actorGroup = "Actors - Heavy";
13-
-- Default actors if no tech is chosen
13+
--Default actors if no tech is chosen
1414
local defaultActor = ("Soldier Heavy");
1515
local defaultPrimary = ("Coalition/Assault Rifle");
1616
local defaultSecondary = ("Coalition/Auto Pistol");
@@ -55,30 +55,30 @@ function OneManArmy:StartActivity()
5555
secondaryGroup = "Weapons - Secondary";
5656
actorGroup = "Actors - Light";
5757
end
58-
-- Destroy all doors for this Activity
58+
--Destroy all doors for this Activity - the enemy is not equipped to deal with them
5959
MovableMan:OpenAllDoors(true, -1);
6060
for actor in MovableMan.AddedActors do
6161
if actor.ClassName == "ADoor" then
6262
actor.ToSettle = true;
6363
actor:GibThis();
6464
end
6565
end
66-
-- Check if we already have a brain assigned
66+
--Check if we already have a brain assigned
6767
for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
6868
if self:PlayerActive(player) and self:PlayerHuman(player) then
6969
if not self:GetPlayerBrain(player) then
7070
local team = self:GetTeamOfPlayer(player);
7171
local foundBrain = MovableMan:GetUnassignedBrain(team);
72-
-- If we can't find an unassigned brain in the scene to give the player, create one
72+
--If we can't find an unassigned brain in the scene to give the player, create one
7373
if not foundBrain then
7474
local tech = PresetMan:GetModuleID(self:GetTeamTech(team));
7575
foundBrain = CreateAHuman(defaultActor);
76-
-- If a faction was chosen, pick the first item from faction listing
76+
--If a faction was chosen, pick the first item from faction listing
7777
if tech ~= -1 then
7878
local module = PresetMan:GetDataModule(tech);
7979
local primaryWeapon, secondaryWeapon, throwable, actor;
8080
for entity in module.Presets do
81-
local picked; -- Prevent duplicates
81+
local picked; --Prevent duplicates
8282
if not primaryWeapon and entity.ClassName == "HDFirearm" then
8383
if ToMOSRotating(entity):HasObjectInGroup(primaryGroup) then
8484
primaryWeapon = CreateHDFirearm(entity:GetModuleAndPresetName());
@@ -115,7 +115,7 @@ function OneManArmy:StartActivity()
115115
foundBrain:AddInventoryItem(weapons[i]);
116116
end
117117
end
118-
else -- If no tech selected, use default items
118+
else --If no tech selected, use default items
119119
local weapons = {defaultPrimary, defaultSecondary};
120120
for i = 1, #weapons do
121121
local item = CreateHDFirearm(weapons[i]);
@@ -130,13 +130,13 @@ function OneManArmy:StartActivity()
130130
foundBrain:AddInventoryItem(item);
131131
end
132132
end
133-
-- Reinforce the brain actor
133+
--Reinforce the brain actor
134134
local parts = {foundBrain, foundBrain.Head, foundBrain.FGArm, foundBrain.BGArm, foundBrain.FGLeg, foundBrain.BGLeg};
135135
for i = 1, #parts do
136136
local part = parts[i];
137137
if part then
138138
part.GibWoundLimit = math.ceil(part.GibWoundLimit * self.multiplier);
139-
part.DamageMultiplier = part.DamageMultiplier / self.multiplier;
139+
part.DamageMultiplier = part.DamageMultiplier/self.multiplier;
140140
if IsAttachable(part) then
141141
ToAttachable(part).JointStrength = ToAttachable(part).JointStrength * self.multiplier;
142142
else
@@ -153,61 +153,61 @@ function OneManArmy:StartActivity()
153153
if medikit then
154154
foundBrain:AddInventoryItem(medikit);
155155
end
156-
-- Reinforce FGArm so that we don't lose it
157-
-- No FGArm = no weapons = no gameplay
156+
--Reinforce FGArm so that we don't lose it
157+
--No FGArm = no weapons = no gameplay
158158
foundBrain.FGArm.GibWoundLimit = 999999;
159159
foundBrain.FGArm.JointStrength = 999999;
160160

161161
foundBrain.Pos = SceneMan:MovePointToGround(Vector(math.random(0, SceneMan.SceneWidth), 0), 0, 0) + Vector(0, -foundBrain.Radius);
162-
foundBrain.Team = self:GetTeamOfPlayer(player)
163-
MovableMan:AddActor(foundBrain)
164-
-- Set the found brain to be the selected actor at start
165-
self:SetPlayerBrain(foundBrain, player)
166-
self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player))
167-
self:SetLandingZone(self:GetPlayerBrain(player).Pos, player)
168-
-- Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
169-
self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player)
162+
foundBrain.Team = self:GetTeamOfPlayer(player);
163+
MovableMan:AddActor(foundBrain);
164+
--Set the found brain to be the selected actor at start
165+
self:SetPlayerBrain(foundBrain, player);
166+
self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player));
167+
self:SetLandingZone(self:GetPlayerBrain(player).Pos, player);
168+
--Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
169+
self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player);
170170
else
171-
-- Set the found brain to be the selected actor at start
172-
self:SetPlayerBrain(foundBrain, player)
173-
self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player))
174-
self:SetLandingZone(self:GetPlayerBrain(player).Pos, player)
175-
-- Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
176-
self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player)
171+
--Set the found brain to be the selected actor at start
172+
self:SetPlayerBrain(foundBrain, player);
173+
self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player));
174+
self:SetLandingZone(self:GetPlayerBrain(player).Pos, player);
175+
--Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
176+
self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player);
177177
end
178178
end
179179
end
180180
end
181181

182-
-- Select a tech for the CPU player
182+
--Select a tech for the CPU player
183183
self.CPUTechName = self:GetTeamTech(self.CPUTeam);
184184
self.ESpawnTimer = Timer();
185-
self.LZ = SceneMan.Scene:GetArea("LZ Team 1")
186-
self.EnemyLZ = SceneMan.Scene:GetArea("LZ All")
187-
self.SurvivalTimer = Timer()
185+
self.LZ = SceneMan.Scene:GetArea("LZ Team 1");
186+
self.EnemyLZ = SceneMan.Scene:GetArea("LZ All");
187+
self.SurvivalTimer = Timer();
188188

189-
self.StartTimer = Timer()
190-
ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_1)
191-
ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_2)
192-
ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_3)
193-
ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_4)
189+
self.StartTimer = Timer();
190+
ActivityMan:GetActivity():SetTeamFunds(0, Activity.TEAM_1);
191+
ActivityMan:GetActivity():SetTeamFunds(0, Activity.TEAM_2);
192+
ActivityMan:GetActivity():SetTeamFunds(0, Activity.TEAM_3);
193+
ActivityMan:GetActivity():SetTeamFunds(0, Activity.TEAM_4);
194194

195-
-- CPU Funds are unlimited
195+
--CPU Funds are "unlimited"
196196
self:SetTeamFunds(1000000, self.CPUTeam);
197197

198-
self.TimeLeft = 500
198+
self.TimeLeft = 500;
199199
end
200200

201201

202202
function OneManArmy:EndActivity()
203-
-- Play sad music if no humans are left
203+
--Play sad music if no humans are left
204204
if self:HumanBrainCount() == 0 then
205205
AudioMan:ClearMusicQueue();
206206
AudioMan:PlayMusic("Base.rte/Music/dBSoundworks/udiedfinal.ogg", 2, -1.0);
207207
AudioMan:QueueSilence(10);
208208
AudioMan:QueueMusicStream("Base.rte/Music/dBSoundworks/ccambient4.ogg");
209209
else
210-
-- But if humans are left, then play happy music!
210+
--But if humans are left, play happy music!
211211
AudioMan:ClearMusicQueue();
212212
AudioMan:PlayMusic("Base.rte/Music/dBSoundworks/uwinfinal.ogg", 2, -1.0);
213213
AudioMan:QueueSilence(10);
@@ -218,62 +218,59 @@ end
218218

219219
function OneManArmy:UpdateActivity()
220220
if self.ActivityState ~= Activity.OVER then
221-
ActivityMan:GetActivity():SetTeamFunds(0,0)
221+
ActivityMan:GetActivity():SetTeamFunds(0, 0)
222222
for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
223223
if self:PlayerActive(player) and self:PlayerHuman(player) then
224-
--Display messages.
224+
--Display messages
225225
if self.StartTimer:IsPastSimMS(3000) then
226-
FrameMan:SetScreenText(math.floor(self.SurvivalTimer:LeftTillSimMS(self.TimeLimit) / 1000) .. " seconds left", player, 0, 1000, false)
226+
FrameMan:SetScreenText(math.floor(self.SurvivalTimer:LeftTillSimMS(self.TimeLimit) * 0.001) .. " seconds left", player, 0, 1000, false)
227227
else
228228
FrameMan:SetScreenText("Survive for " .. self.timeDisplay .. "!", player, 333, 5000, true)
229229
end
230-
231-
-- The current player's team
232-
local team = self:GetTeamOfPlayer(player)
233-
-- Check if any player's brain is dead
230+
231+
local team = self:GetTeamOfPlayer(player);
232+
--Check if any player's brain is dead
234233
if not MovableMan:IsActor(self:GetPlayerBrain(player)) then
235-
self:SetPlayerBrain(nil, player)
236-
self:ResetMessageTimer(player)
237-
FrameMan:ClearScreenText(player)
238-
FrameMan:SetScreenText("Your brain has been destroyed!", player, 333, -1, false)
239-
-- Now see if all brains of self player's team are dead, and if so, end the game
234+
self:SetPlayerBrain(nil, player);
235+
self:ResetMessageTimer(player);
236+
FrameMan:ClearScreenText(player);
237+
FrameMan:SetScreenText("Your brain has been destroyed!", player, 333, -1, false);
238+
--Now see if all brains of self player's team are dead, and if so, end the game
240239
if not MovableMan:GetFirstBrainActor(team) then
241-
self.WinnerTeam = self:OtherTeam(team)
242-
ActivityMan:EndActivity()
240+
self.WinnerTeam = self:OtherTeam(team);
241+
ActivityMan:EndActivity();
243242
end
244-
else
245-
self.HuntPlayer = player
246243
end
247244

248-
--Check if the player has won.
245+
--Check if the player has won
249246
if self.SurvivalTimer:IsPastSimMS(self.TimeLimit) then
250-
self:ResetMessageTimer(player)
251-
FrameMan:ClearScreenText(player)
252-
FrameMan:SetScreenText("You survived!", player, 333, -1, false)
247+
self:ResetMessageTimer(player);
248+
FrameMan:ClearScreenText(player);
249+
FrameMan:SetScreenText("You survived!", player, 333, -1, false);
253250

254-
self.WinnerTeam = player
251+
self.WinnerTeam = player;
255252

256-
--Kill all enemies.
253+
--Kill all enemies
257254
for actor in MovableMan.Actors do
258255
if actor.Team ~= self.WinnerTeam then
259-
actor.Health = 0
256+
actor.Health = 0;
260257
end
261258
end
262259

263-
ActivityMan:EndActivity()
260+
ActivityMan:EndActivity();
264261
end
265262
end
266263
end
267-
268-
--Spawn the AI.
269-
if self.CPUTeam ~= Activity.NOTEAM and self.ESpawnTimer:LeftTillSimMS(self.TimeLeft) <= 0 and MovableMan:GetTeamMOIDCount(self.CPUTeam) <= rte.AIMOIDMax * 3 / self:GetActiveCPUTeamCount() then
270-
local ship, actorsInCargo
264+
local enemyMOIDCount = MovableMan:GetTeamMOIDCount(self.CPUTeam);
265+
--Spawn the AI
266+
if self.CPUTeam ~= Activity.NOTEAM and self.ESpawnTimer:LeftTillSimMS(self.TimeLeft) <= 0 and enemyMOIDCount < rte.AIMOIDMax then
267+
local ship, actorsInCargo;
271268

272269
if math.random() < 0.5 then
273-
-- Set up the ship to deliver this stuff
270+
--Set up the ship to deliver this stuff
274271
ship = RandomACDropShip("Any", self.CPUTechName);
275-
-- If we can't afford this dropship, then try a rocket instead
276-
if ship:GetTotalValue(0,3) > self:GetTeamFunds(self.CPUTeam) then
272+
--If we can't afford this dropship, then try a rocket instead
273+
if ship:GetTotalValue(0, 3) > self:GetTeamFunds(self.CPUTeam) then
277274
DeleteEntity(ship);
278275
ship = RandomACRocket("Any", self.CPUTechName);
279276
end
@@ -285,44 +282,44 @@ function OneManArmy:UpdateActivity()
285282

286283
ship.Team = self.CPUTeam;
287284

288-
-- The max allowed weight of this craft plus cargo
289-
local craftMaxMass = ship.MaxMass
285+
--The max allowed weight of this craft plus cargo
286+
local craftMaxMass = ship.MaxMass;
290287
if craftMaxMass < 0 then
291-
craftMaxMass = math.huge
288+
craftMaxMass = math.huge;
292289
elseif craftMaxMass < 1 then
293-
craftMaxMass = ship.Mass + 400 -- MaxMass not defined
290+
craftMaxMass = ship.Mass + 400; --MaxMass not defined
294291
end
295292

296-
-- Set the ship up with a cargo of a few armed and equipped actors
293+
--Set the ship up with a cargo of a few armed and equipped actors
297294
for i = 1, actorsInCargo do
298-
-- Get any Actor from the CPU's native tech
295+
--Get any Actor from the CPU's native tech
299296
local passenger = nil;
300297
if math.random() >= self:GetCrabToHumanSpawnRatio(PresetMan:GetModuleID(self.CPUTechName)) then
301298
passenger = RandomAHuman("Any", self.CPUTechName);
302299
else
303300
passenger = RandomACrab("Any", self.CPUTechName);
304301
end
305-
-- Equip it with tools and guns if it's a humanoid
302+
--Equip it with tools and guns if it's a humanoid
306303
if IsAHuman(passenger) then
307304
passenger:AddInventoryItem(RandomHDFirearm("Weapons - Light", self.CPUTechName));
308305
passenger:AddInventoryItem(RandomHDFirearm("Weapons - Secondary", self.CPUTechName));
309306
if math.random() < 0.5 then
310307
passenger:AddInventoryItem(RandomHDFirearm("Tools - Diggers", self.CPUTechName));
311308
end
312309
end
313-
-- Set AI mode and team so it knows who and what to fight for!
310+
--Set AI mode and team so it knows who and what to fight for!
314311
passenger.AIMode = Actor.AIMODE_BRAINHUNT;
315312
passenger.Team = self.CPUTeam;
316313

317-
-- Check that we can afford to buy and to carry the weight of this passenger
318-
if (ship:GetTotalValue(0,3) + passenger:GetTotalValue(0,3)) <= self:GetTeamFunds(self.CPUTeam) and (ship.Mass + passenger.Mass) <= craftMaxMass then
319-
-- Yes we can; so add it to the cargo hold
314+
--Check that we can afford to buy and to carry the weight of this passenger
315+
if (ship:GetTotalValue(0, 3) + passenger:GetTotalValue(0, 3)) <= self:GetTeamFunds(self.CPUTeam) and (ship.Mass + passenger.Mass) <= craftMaxMass then
316+
--Yes we can; so add it to the cargo hold
320317
ship:AddInventoryItem(passenger);
321318
passenger = nil;
322319
else
323-
-- Nope; just delete the nixed passenger and stop adding new ones
324-
-- This doesn't need to be explicitly deleted here, teh garbage collection would do it eventually..
325-
-- but since we're so sure we don't need it, might as well go ahead and do it here right away
320+
--Nope; just delete the nixed passenger and stop adding new ones
321+
--This doesn't need to be explicitly deleted here, the garbage collection would do it eventually,
322+
--but since we're so sure we don't need it, might as well go ahead and do it right away
326323
DeleteEntity(passenger);
327324
passenger = nil;
328325

@@ -336,47 +333,45 @@ function OneManArmy:UpdateActivity()
336333
end
337334

338335
if ship then
339-
-- Set the spawn point of the ship from orbit
336+
--Set the spawn point of the ship from orbit
340337
if self.playertally == 1 then
341338
for i = 1, #self.playerlist do
342339
if self.playerlist[i] == true then
343-
local sceneChunk = SceneMan.SceneWidth / 3;
344-
local checkPos = self:GetPlayerBrain(i - 1).Pos.X + (SceneMan.SceneWidth/2) + ( (sceneChunk/2) - (math.random()*sceneChunk) );
340+
local sceneChunk = SceneMan.SceneWidth * 0.3;
341+
local checkPos = self:GetPlayerBrain(i - 1).Pos.X + (SceneMan.SceneWidth * 0.5) + ((sceneChunk * 0.5) - (math.random() * sceneChunk));
345342
if checkPos > SceneMan.SceneWidth then
346343
checkPos = checkPos - SceneMan.SceneWidth;
347344
elseif checkPos < 0 then
348345
checkPos = SceneMan.SceneWidth + checkPos;
349346
end
350-
ship.Pos = Vector(checkPos,-50);
347+
ship.Pos = Vector(checkPos, -50);
351348
break;
352349
end
353350
end
354351
else
355352
if SceneMan.SceneWrapsX then
356353
ship.Pos = Vector(math.random() * SceneMan.SceneWidth, -50);
357354
else
358-
ship.Pos = Vector(RangeRand(100, SceneMan.SceneWidth-100), -50);
355+
ship.Pos = Vector(RangeRand(100, SceneMan.SceneWidth - 100), -50);
359356
end
360357
end
361358

362-
-- Double-check if the computer can afford this ship and cargo, then subtract the total value from the team's funds
363-
local shipValue = ship:GetTotalValue(0,3);
359+
--Double-check if the computer can afford this ship and cargo, then subtract the total value from the team's funds
360+
local shipValue = ship:GetTotalValue(0, 3);
364361
if shipValue <= self:GetTeamFunds(self.CPUTeam) then
365-
-- Subtract the total value of the ship+cargo from the CPU team's funds
362+
--Subtract the total value of the ship+cargo from the CPU team's funds
366363
self:ChangeTeamFunds(-shipValue, self.CPUTeam);
367-
-- Spawn the ship onto the scene
364+
--Spawn the ship onto the scene
368365
MovableMan:AddActor(ship);
369366
else
370-
-- The ship and its contents is deleted if it can't be afforded
371-
-- This doesn't need to be explicitly deleted here, teh garbage collection would do it eventually..
372-
-- but since we're so sure we don't need it, might as well go ahead and do it here right away
367+
--The ship and its contents is deleted if it can't be afforded
373368
DeleteEntity(ship);
374369
ship = nil;
375370
end
376371
end
377372

378373
self.ESpawnTimer:Reset();
379-
self.TimeLeft = (self.BaseSpawnTime + math.random(self.BaseSpawnTime) * rte.SpawnIntervalScale);
374+
self.TimeLeft = (self.BaseSpawnTime * (1 + enemyMOIDCount * 0.1) + math.random(self.BaseSpawnTime)) * rte.SpawnIntervalScale;
380375
end
381376
end
382377
end

0 commit comments

Comments
 (0)