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

Commit 0d86c07

Browse files
committed
Bunker Breach fixes; AI will now respond better to difficulty changes
1 parent b2b7ca7 commit 0d86c07

File tree

1 file changed

+45
-52
lines changed

1 file changed

+45
-52
lines changed

Base.rte/Activities/BunkerBreach.lua

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function BunkerBreach:StartActivity()
5151
self.checkTimer:SetRealTimeLimitMS(1000);
5252
self.CPUSpawnTimer = Timer();
5353
self.CPUSpawnDelay = (40000 - self.difficultyRatio * 20000) * rte.SpawnIntervalScale;
54+
self.CPUSearchRadius = math.sqrt(SceneMan.SceneWidth^2 + SceneMan.SceneHeight^2) * 0.5 * self.difficultyRatio;
5455

5556
--Set all actors in the scene to the defending team
5657
for actor in MovableMan.AddedActors do
@@ -68,8 +69,8 @@ function BunkerBreach:StartActivity()
6869
end
6970

7071
--CPU team setup
71-
if self.CPUTeam ~= -1 then
72-
self:SetTeamFunds(5000 * (0.5 + math.floor(self.difficultyRatio * 10)/10), self.CPUTeam);
72+
if self.CPUTeam ~= Activity.NOTEAM then
73+
self:SetTeamFunds(4000 + 8000 * math.floor(self.difficultyRatio * 5)/5, self.CPUTeam);
7374
if (self.CPUTeam ~= self.defenderTeam) then
7475
self.CPUSpawnDelay = self.CPUSpawnDelay * 0.5;
7576
end
@@ -195,8 +196,6 @@ function BunkerBreach:StartActivity()
195196
end
196197
end
197198
end
198-
self.enemyForcesCount = 0;
199-
self.enemyDiggersCount = 0;
200199
end
201200

202201

@@ -314,62 +313,54 @@ function BunkerBreach:UpdateActivity()
314313
if self.CPUSpawnTimer:IsPastSimMS(self.CPUSpawnDelay) then
315314
self.CPUSpawnTimer:Reset();
316315

317-
local unitRatio = enemyCount/math.max(allyCount, 1);
316+
local enemyUnitRatio = enemyCount/math.max(allyCount, 1);
318317
--Send CPU to dig for gold if funds are low and a digger hasn't recently been sent
319318
self.sendGoldDiggers = not self.sendGoldDiggers and diggerCount < 3 and (funds < 500 or math.random() < 0.1);
320319

321320
if self.CPUTeam == self.attackerTeam then
322321
if self.sendGoldDiggers then
323-
self:CreateDrop(self.CPUTeam, "Engineer");
324-
elseif unitRatio < 1.75 then
325-
self:CreateDrop(self.CPUTeam);
326-
self.CPUSpawnDelay = (30000 - self.difficultyRatio * 15000 + unitRatio * 5000) * rte.SpawnIntervalScale;
322+
self:CreateDrop(self.CPUTeam, "Engineer", Actor.AIMODE_GOLDDIG);
323+
elseif enemyUnitRatio < 1.75 then
324+
self:CreateDrop(self.CPUTeam, "Any", Actor.AIMODE_BRAINHUNT);
325+
self.CPUSpawnDelay = (30000 - self.difficultyRatio * 15000 + enemyUnitRatio * 5000) * rte.SpawnIntervalScale;
327326
else
328327
self.CPUSpawnDelay = self.CPUSpawnDelay * 0.9;
329328
end
330329
elseif self.CPUTeam == self.defenderTeam then
331330

332331
local dist = Vector();
333-
local searchRadius = (SceneMan.SceneWidth + SceneMan.SceneHeight) * 0.2;
334-
local targetActor = MovableMan:GetClosestEnemyActor(self.CPUTeam, Vector(self.defenderBrain.Pos.X, SceneMan.SceneHeight * 0.5), searchRadius, dist);
332+
local targetActor = MovableMan:GetClosestEnemyActor(self.CPUTeam, Vector(self.defenderBrain.Pos.X, SceneMan.SceneHeight * 0.5), self.CPUSearchRadius, dist);
335333
if targetActor then
336-
if SceneMan:IsUnseen(targetActor.Pos.X, targetActor.Pos.Y, self.CPUTeam) then
337-
self.attackPos = targetActor.Pos;
334+
self.chokePoint = targetActor.Pos;
335+
local closestGuard = MovableMan:GetClosestTeamActor(self.CPUTeam, Activity.PLAYER_NONE, targetActor.Pos, self.CPUSearchRadius - dist.Magnitude, Vector(), self.defenderBrain);
336+
if closestGuard and closestGuard.AIMODE == Actor.AIMODE_PATROL then
337+
--Send a nearby alerted guard after the intruder
338+
closestGuard.AIMode = Actor.AIMODE_GOTO;
339+
closestGuard:AddAIMOWaypoint(targetActor);
340+
self.chokePoint = nil;
341+
--A guard has been sent, the next unit should spawn faster
342+
self.CPUSpawnDelay = self.CPUSpawnDelay * 0.8;
338343
else
339-
local closestGuard = MovableMan:GetClosestTeamActor(self.CPUTeam, Activity.PLAYER_NONE, targetActor.Pos, searchRadius - dist.Magnitude, Vector(), self.defenderBrain);
340-
if closestGuard and closestGuard.AIMODE ~= Actor.AIMODE_GOTO then
341-
--Send a nearby alerted guard after the intruder
342-
closestGuard.AIMode = Actor.AIMODE_GOTO;
343-
closestGuard:AddAIMOWaypoint(targetActor);
344-
self.attackPos = nil;
345-
--A guard has been sent, the next unit should spawn faster
346-
self.CPUSpawnDelay = self.CPUSpawnDelay * 0.8;
347-
else
348-
self:CreateDrop(self.CPUTeam);
349-
self.CPUSpawnDelay = (30000 - self.difficultyRatio * 15000 + unitRatio * 5000) * rte.SpawnIntervalScale;
350-
if math.random() < 0.5 then
351-
--Change target for the next attack
352-
self.attackPos = nil;
353-
end
344+
self:CreateDrop(self.CPUTeam, "Any", Actor.AIMODE_GOTO);
345+
self.CPUSpawnDelay = (30000 - self.difficultyRatio * 15000 + enemyUnitRatio * 5000) * rte.SpawnIntervalScale;
346+
if math.random() < 0.5 then
347+
--Change target for the next attack
348+
self.chokePoint = nil;
354349
end
355350
end
356351
else
357-
self.attackPos = nil;
358-
359-
if unitRatio < 1.25 then
360-
if self.sendGoldDiggers then
361-
self:CreateDrop(self.CPUTeam, "Engineer");
362-
else
363-
self:CreateDrop(self.CPUTeam);
364-
end
365-
self.CPUSpawnDelay = (40000 - self.difficultyRatio * 20000 + unitRatio * 7500) * rte.SpawnIntervalScale;
352+
self.chokePoint = nil;
353+
354+
if self.sendGoldDiggers then
355+
self:CreateDrop(self.CPUTeam, "Engineer", Actor.AIMODE_GOLDDIG);
366356
else
367-
self.CPUSpawnDelay = self.CPUSpawnDelay * 0.9;
357+
self:CreateDrop(self.CPUTeam, "Any", enemyUnitRatio < RangeRand(1.5, 0.5) and Actor.AIMODE_BRAINHUNT or Actor.AIMODE_PATROL);
368358
end
359+
self.CPUSpawnDelay = (40000 - self.difficultyRatio * 20000 + enemyUnitRatio * 7500) * rte.SpawnIntervalScale;
369360
end
370361
end
371362
end
372-
elseif enemyCount < 1 then
363+
elseif enemyCount < 0.5 then
373364
for actor in MovableMan.Actors do
374365
if actor.Team ~= self.playerTeam then
375366
actor.Status = Actor.INACTIVE;
@@ -384,10 +375,13 @@ function BunkerBreach:UpdateActivity()
384375
end
385376

386377

387-
function BunkerBreach:CreateDrop(team, loadout)
378+
function BunkerBreach:CreateDrop(team, loadout, aiMode)
388379
local tech = self:GetTeamTech(team);
389380
local crabRatio = self:GetCrabToHumanSpawnRatio(PresetMan:GetModuleID(tech));
390381

382+
if loadout == "Any" then
383+
loadout = nil;
384+
end
391385
local craft = RandomACDropShip("Craft", tech);
392386
if not craft or craft.MaxInventoryMass <= 0 then
393387
--MaxMass not defined, spawn a default craft
@@ -420,6 +414,16 @@ function BunkerBreach:CreateDrop(team, loadout)
420414
end
421415

422416
if passenger then
417+
if aiMode then
418+
passenger.AIMode = aiMode;
419+
if aiMode == Actor.AIMODE_GOTO then
420+
if self.chokePoint then
421+
passenger:AddAISceneWaypoint(self.chokePoint);
422+
else
423+
passenger.AIMode = Actor.AIMODE_BRAINHUNT;
424+
end
425+
end
426+
end
423427
craft:AddInventoryItem(passenger);
424428
end
425429
end
@@ -517,18 +521,7 @@ function BunkerBreach:CreateInfantry(team, loadout)
517521
end
518522
end
519523
end
520-
if loadout == "Engineer" and self.sendGoldDiggers then
521-
actor.AIMode = Actor.AIMODE_GOLDDIG;
522-
elseif self.attackPos then
523-
actor.AIMode = Actor.AIMODE_GOTO;
524-
actor:AddAISceneWaypoint(self.attackPos);
525-
elseif team == self.attackerTeam then
526-
actor.AIMode = Actor.AIMODE_BRAINHUNT;
527-
elseif loadout == "CQB" then
528-
actor.AIMode = Actor.AIMODE_PATROL;
529-
else
530-
actor.AIMode = Actor.AIMODE_SENTRY;
531-
end
524+
actor.AIMode = Actor.AIMODE_SENTRY;
532525
actor.Team = team;
533526
return actor;
534527
end

0 commit comments

Comments
 (0)