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

Commit 9ce9afc

Browse files
committed
Fixed dday initial human actor spawning when there are a large number of units
1 parent 6808d9e commit 9ce9afc

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Data/Missions.rte/Activities/DecisionDay.lua

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -528,24 +528,23 @@ function DecisionDay:SetupStorageCrateInventories()
528528
end
529529

530530
function DecisionDay:DoInitialHumanSpawns()
531-
local nextActorPos = Vector(self.initialHumanSpawnArea.FirstBox.Corner.X, self.initialHumanSpawnArea.Center.Y);
531+
local firstActorPos = Vector(self.initialHumanSpawnArea.FirstBox.Corner.X, self.initialHumanSpawnArea.Center.Y);
532532
local initialActorFunds = 1300 / self.difficultyRatio;
533-
local spawnedActorNumber = 0;
533+
local spawnedActors = {};
534534
while initialActorFunds > 0 do
535-
spawnedActorNumber = spawnedActorNumber + 1;
536-
local actor = self:SpawnInfantry(self.humanTeam, spawnedActorNumber < 3 and "CQB" or "Heavy", nextActorPos, Actor.AIMODE_SENTRY, true);
537-
actor.Pos = SceneMan:MovePointToGround(actor.Pos, actor.Radius, 5);
535+
local actor = self:SpawnInfantry(self.humanTeam, #spawnedActors < 3 and "CQB" or "Heavy", firstActorPos, Actor.AIMODE_SENTRY, true);
536+
spawnedActors[#spawnedActors + 1] = actor;
538537
actor.PlayerControllable = true;
539-
if spawnedActorNumber < 3 then
538+
if #spawnedActors < 3 then
540539
actor:AddInventoryItem(RandomTDExplosive("Tools - Breaching", self.humanTeamTech));
541540
elseif math.random() < 0.65 then
542541
actor:AddInventoryItem(RandomTDExplosive("Bombs - Grenades", self.humanTeamTech));
543542
end
544543
initialActorFunds = initialActorFunds - actor:GetTotalValue(self.humanTeamTech, 1);
545-
nextActorPos = nextActorPos + Vector(30, 0);
546544
end
547545
for _, player in pairs(self.humanPlayers) do
548546
local brain = PresetMan:GetLoadout("Infantry Brain", self.humanTeamTech, false);
547+
spawnedActors[#spawnedActors + 1] = brain;
549548
if brain then
550549
brain:RemoveInventoryItem("Constructor");
551550
else
@@ -554,14 +553,20 @@ function DecisionDay:DoInitialHumanSpawns()
554553
brain:AddInventoryItem(RandomHDFirearm("Weapons - Light", self.humanTeamTech));
555554
brain:AddInventoryItem(RandomHDFirearm("Weapons - Secondary", self.humanTeamTech));
556555
end
557-
brain.Pos = nextActorPos;
556+
brain.Pos = firstActorPos;
558557
brain.Team = self.humanTeam;
559-
nextActorPos = nextActorPos + Vector(30, 0);
560558
brain.AIMode = Actor.AIMODE_SENTRY;
561559
MovableMan:AddActor(brain);
562560
self:SetPlayerBrain(brain, player);
563561
self:SetObservationTarget(brain.Pos, player);
564562
end
563+
564+
local actorXOffset = math.min(30, 275 / #spawnedActors);
565+
for index, actor in ipairs(spawnedActors) do
566+
actor.Pos.X = actor.Pos.X + (actorXOffset * (index - 1));
567+
actor.Pos.Y = 0;
568+
actor.Pos = SceneMan:MovePointToGround(actor.Pos, actor.Radius, 5);
569+
end
565570
end
566571

567572
function DecisionDay:SpawnAreaDefinedAIDefenders()

0 commit comments

Comments
 (0)