Skip to content

Commit 436c9d1

Browse files
committed
Merge branch 'development' into multithreading-ai
2 parents 3917113 + bcbe1f7 commit 436c9d1

File tree

129 files changed

+2347
-2985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+2347
-2985
lines changed

Data/Base.rte/AI/CrabBehaviors.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ function CrabBehaviors.ShootArea(AI, Owner, Abort)
616616

617617
-- check if we can fire at the AimPoint
618618
local Trace = SceneMan:ShortestDistance(Owner.EyePos, AimPoint, false);
619-
local rayLenght = SceneMan:CastObstacleRay(Owner.EyePos, Trace, Vector(), Vector(), rte.NoMOID, Owner.IgnoresWhichTeam, rte.grassID, 11);
620-
if Trace.Magnitude * 0.67 < rayLenght then
619+
local rayLength = SceneMan:CastObstacleRay(Owner.EyePos, Trace, Vector(), Vector(), rte.NoMOID, Owner.IgnoresWhichTeam, rte.grassID, 11);
620+
if Trace:MagnitudeIsLessThan(rayLength * 1.5) then
621621
break; -- the AimPoint is close enough to the target, start shooting
622622
end
623623

Data/Base.rte/AI/HumanBehaviors.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,10 @@ end
235235

236236
function HumanBehaviors.GetGrenadeAngle(AimPoint, TargetVel, StartPos, muzVel)
237237
local Dist = SceneMan:ShortestDistance(StartPos, AimPoint, false);
238-
local range = Dist.Magnitude;
239238

240239
-- compensate for gravity if the point we are trying to hit is more than 2m away
241-
if range > 40 then
242-
local timeToTarget = range / muzVel;
240+
if Dist:MagnitudeIsGreaterThan(40) then
241+
local timeToTarget = Dist.Magnitude / muzVel;
243242

244243
-- lead the target if target speed and projectile TTT is above the threshold
245244
if (timeToTarget * TargetVel.Magnitude) > 0.5 then
@@ -1464,8 +1463,7 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
14641463
local RandomWpt = WptList[test];
14651464
if RandomWpt then
14661465
Dist = SceneMan:ShortestDistance(Owner.Pos, RandomWpt.Pos, false);
1467-
local mag = Dist.Magnitude;
1468-
if mag < 50 and mag < SceneMan:ShortestDistance(Owner.Pos, Waypoint.Pos, false).Magnitude/3 then
1466+
if Dist:MagnitudeIsLessThan(50) and Dist:MagnitudeIsLessThan(SceneMan:ShortestDistance(Owner.Pos, Waypoint.Pos, false).Magnitude * 0.33) then
14691467
-- this waypoint is closer, check LOS
14701468
if -1 == SceneMan:CastObstacleRay(Owner.Pos, Dist, Vector(), Vector(), Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 4) then
14711469
Waypoint = RandomWpt; -- go here instead
@@ -2997,8 +2995,8 @@ function HumanBehaviors.ShootArea(AI, Owner, Abort)
29972995

29982996
-- check if we can fire at the AimPoint
29992997
local Trace = SceneMan:ShortestDistance(Owner.EyePos, AimPoint, false);
3000-
local rayLenght = SceneMan:CastObstacleRay(Owner.EyePos, Trace, Vector(), Vector(), rte.NoMOID, Owner.IgnoresWhichTeam, rte.grassID, 11);
3001-
if Trace.Magnitude * 0.67 < rayLenght then
2998+
local rayLength = SceneMan:CastObstacleRay(Owner.EyePos, Trace, Vector(), Vector(), rte.NoMOID, Owner.IgnoresWhichTeam, rte.grassID, 11);
2999+
if Trace:MagnitudeIsLessThan(rayLength * 1.5) then
30023000
break; -- the AimPoint is close enough to the target, start shooting
30033001
end
30043002

Data/Base.rte/AI/NativeDropShipAI.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ function NativeDropShipAI:Update(Owner)
165165
self.Waypoint.Y = -500; -- Go to orbit
166166
end
167167
else
168-
local dist = SceneMan:ShortestDistance(Owner.Pos, self.Waypoint, false).Magnitude;
169-
if dist < Owner.Radius and math.abs(change) < 3 and math.abs(Owner.Vel.X) < 4 then -- If we passed the hover check, check if we can start unloading
168+
local dist = SceneMan:ShortestDistance(Owner.Pos, self.Waypoint, false);
169+
if dist:MagnitudeIsLessThan(Owner.Radius) and math.abs(change) < 3 and math.abs(Owner.Vel.X) < 4 then -- If we passed the hover check, check if we can start unloading
170170
local WptL = SceneMan:MovePointToGround(Owner.Pos+Vector(-Owner.Radius, -Owner.Radius), self.hoverAlt, 12);
171171
local WptC = SceneMan:MovePointToGround(Owner.Pos+Vector(0, -Owner.Radius), self.hoverAlt, 12);
172172
local WptR = SceneMan:MovePointToGround(Owner.Pos+Vector(Owner.Radius, -Owner.Radius), self.hoverAlt, 12);
173173
self.Waypoint = Vector(Owner.Pos.X, math.min(WptL.Y, WptC.Y, WptR.Y));
174174

175-
dist = SceneMan:ShortestDistance(Owner.Pos, self.Waypoint, false).Magnitude;
176-
if dist < Owner.Diameter then
175+
dist = SceneMan:ShortestDistance(Owner.Pos, self.Waypoint, false);
176+
if dist:MagnitudeIsLessThan(Owner.Diameter) then
177177
-- We are close enough to our waypoint
178178
if Owner.AIMode == Actor.AIMODE_STAY then
179179
self.DeliveryState = ACraft.STANDBY;

Data/Base.rte/AI/RocketAI.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,8 @@ function UpdateAI(self)
140140
self.LZpos = SceneMan:MovePointToGround(self.Pos, self.groundDist, 6);
141141
end
142142

143-
if self.AIMode ~= Actor.AIMODE_STAY then
144-
local dist = SceneMan:ShortestDistance(self.Pos, self.LZpos, false).Magnitude;
145-
if dist < 25 then -- If we passed the check, start unloading
146-
self.DeliveryState = ACraft.UNLOAD;
147-
end
143+
if self.AIMode ~= Actor.AIMODE_STAY and SceneMan:ShortestDistance(self.Pos, self.LZpos, false):MagnitudeIsLessThan(25) then
144+
self.DeliveryState = ACraft.UNLOAD;
148145
end
149146
end
150147
elseif self.DeliveryState == ACraft.UNLOAD then

Data/Base.rte/Activities.ini

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ AddActivity = GAScripted
4747
Description = Build a bunker and defend it against increasingly longer waves of AI-controlled enemies, with time to repair in between! Adjust the Difficulty to change wave difficulty.
4848
SceneName = Ketanot Hills
4949
ScriptPath = Base.rte/Activities/WaveDefense.lua
50-
TeamOfPlayer1 = 0
51-
TeamOfPlayer2 = 0
52-
TeamOfPlayer3 = 0
53-
TeamOfPlayer4 = 0
54-
CPUTeam = 1
50+
TeamOfPlayer1 = 1
51+
TeamOfPlayer2 = 1
52+
TeamOfPlayer3 = 1
53+
TeamOfPlayer4 = 1
54+
CPUTeam = 0
5555
MinTeamsRequired = 2
5656
DefaultGoldCakeDifficulty = 6000
5757
DefaultGoldEasyDifficulty = 5000
@@ -60,9 +60,11 @@ AddActivity = GAScripted
6060
DefaultGoldNutsDifficulty = 2000
6161
DefaultGoldMaxDifficulty = 1000
6262
LuaClassName = WaveDefense
63+
Team1Name = Attackers
64+
Team2Name = Defenders
6365
DefaultRequireClearPathToOrbit = 1
6466
DeployUnitsSwitchEnabled = 1
65-
DefaultDeployUnits = 0
67+
DefaultDeployUnits = 1
6668
6769
6870
AddActivity = GAScripted
@@ -208,6 +210,7 @@ AddActivity = GAScripted
208210
DeployUnitsSwitchEnabled = 1
209211
ScriptPath = Base.rte/Activities/Test.lua
210212
LuaClassName = Test
213+
DefaultDeployUnits = 0
211214
212215
213216
/*

Data/Base.rte/Activities/BunkerBreach.lua

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ function BunkerBreach:SetupDefenderBrains()
7777

7878
-- Add defender brains, either using the Brain area or picking randomly from those created by deployments.
7979
if SceneMan.Scene:HasArea("Brain") then
80-
for actor in MovableMan.Actors do
81-
if actor.Team == self.defenderTeam and actor:IsInGroup("Brains") then
80+
for actor in MovableMan.AddedActors do
81+
if actor:IsInGroup("Brains") then
8282
actor.ToDelete = true;
8383
end
8484
end
@@ -141,35 +141,52 @@ function BunkerBreach:SetupDefenderActors()
141141
local techID = PresetMan:GetModuleID(self:GetTeamTech(self.defenderTeam));
142142
local crabToHumanSpawnRatio = self:GetCrabToHumanSpawnRatio(techID);
143143

144-
for _, loadoutName in pairs({"Light", "Heavy", "Sniper", "Engineer", "Mecha", "Turret"}) do
144+
local loadoutNames = {"Light", "Heavy", "Sniper", "Engineer", "Mecha", "Turret"};
145+
146+
local hasSpawnAreas = false;
147+
for _, loadoutName in pairs(loadoutNames) do
145148
if SceneMan.Scene:HasArea(loadoutName .. " Defenders") then
146-
local defenderArea = SceneMan.Scene:GetOptionalArea(loadoutName .. " Defenders");
147-
if defenderArea ~= nil then
148-
for defenderBox in defenderArea.Boxes do
149-
local guard;
150-
if loadoutName == "Mecha" or loadoutName == "Turret" then
151-
guard = crabToHumanSpawnRatio > 0 and self:CreateCrab(techID, loadoutName == "Turret") or self:CreateInfantry(techID, "Heavy");
152-
else
153-
guard = self:CreateInfantry(techID, loadoutName);
154-
end
155-
if guard then
156-
guard.Pos = defenderBox.Center;
157-
guard.Team = self.defenderTeam;
158-
guard.AIMode = Actor.AIMODE_SENTRY;
159-
if loadoutName == "Engineer" then
160-
guard.AIMode = Actor.AIMODE_GOLDDIG;
149+
hasSpawnAreas = true;
150+
end
151+
end
152+
153+
for actor in MovableMan.AddedActors do
154+
if not actor:IsInGroup("Brains") and not actor:IsInGroup("Bunker Systems - Automovers") then
155+
if hasSpawnAreas then
156+
actor.ToDelete = true;
157+
elseif actor.Team ~= self.defenderTeam then
158+
MovableMan:ChangeActorTeam(actor, self.defenderTeam);
159+
end
160+
end
161+
end
162+
163+
if hasSpawnAreas then
164+
for _, loadoutName in pairs({"Light", "Heavy", "Sniper", "Engineer", "Mecha", "Turret"}) do
165+
if SceneMan.Scene:HasArea(loadoutName .. " Defenders") then
166+
hasSpawnAreas = true;
167+
local defenderArea = SceneMan.Scene:GetOptionalArea(loadoutName .. " Defenders");
168+
if defenderArea ~= nil then
169+
for defenderBox in defenderArea.Boxes do
170+
local guard;
171+
if loadoutName == "Mecha" or loadoutName == "Turret" then
172+
guard = crabToHumanSpawnRatio > 0 and self:CreateCrab(techID, loadoutName == "Turret") or self:CreateInfantry(techID, "Heavy");
173+
else
174+
guard = self:CreateInfantry(techID, loadoutName);
175+
end
176+
if guard then
177+
guard.Pos = defenderBox.Center;
178+
guard.Team = self.defenderTeam;
179+
guard.AIMode = Actor.AIMODE_SENTRY;
180+
if loadoutName == "Engineer" then
181+
guard.AIMode = Actor.AIMODE_GOLDDIG;
182+
end
183+
MovableMan:AddActor(guard);
161184
end
162-
MovableMan:AddActor(guard);
163185
end
164186
end
165187
end
166188
end
167189
end
168-
for actor in MovableMan.AddedActors do
169-
if actor.Team ~= self.defenderTeam and not actor:IsInGroup("Brains") and not actor:IsInGroup("Bunker Systems - Automovers") then
170-
MovableMan:ChangeActorTeam(actor, self.defenderTeam);
171-
end
172-
end
173190
end
174191

175192
function BunkerBreach:SetupFogOfWar()
@@ -241,12 +258,12 @@ function BunkerBreach:StartActivity(isNewGame)
241258

242259
self:SetupAIVariables();
243260

244-
self:SetupHumanAttackerBrains();
245-
246261
self:SetupDefenderBrains();
247262

248263
self:SetupDefenderActors();
249264

265+
self:SetupHumanAttackerBrains();
266+
250267
self:SetupFogOfWar();
251268
else
252269
self:ResumeLoadedGame();

Data/Base.rte/Activities/SkirmishDefense.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ function SkirmishDefense:StartNewGame(aiTeams)
110110
soleHumanTeam = soleHumanTeam == -1 and team or false;
111111
end
112112
end
113-
-- If there's only one Human team, set all existing doors to that team
113+
-- If there's only one Human team, set all existing doors and actors to that team
114114
if soleHumanTeam ~= false and soleHumanTeam >= 0 then
115115
for actor in MovableMan.AddedActors do
116-
if actor.Team ~= soleHumanTeam and actor.ClassName == "ADoor" then
116+
if actor.Team ~= soleHumanTeam then
117117
MovableMan:ChangeActorTeam(actor, soleHumanTeam);
118118
end
119119
end

Data/Base.rte/Activities/WaveDefense.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525

2626
function WaveDefense:StartActivity(isNewGame)
2727
-- Get player team
28-
self.playerTeam = Activity.TEAM_1;
28+
self.playerTeam = Activity.TEAM_2;
2929
for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
3030
if self:PlayerActive(player) and self:PlayerHuman(player) then
3131
self.playerTeam = self:GetTeamOfPlayer(player);
@@ -108,6 +108,14 @@ function WaveDefense:StartNewGame()
108108
end
109109

110110
self:CheckBrains();
111+
112+
for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
113+
if self:PlayerActive(player) and self:PlayerHuman(player) then
114+
if self:GetPlayerBrain(player) then
115+
self:SwitchToActor(self:GetPlayerBrain(player), player, self:GetTeamOfPlayer(player));
116+
end
117+
end
118+
end
111119
end
112120

113121
function WaveDefense:ResumeLoadedGame()
@@ -259,6 +267,14 @@ function WaveDefense:UpdateActivity()
259267
end
260268
end
261269

270+
-- Reveal the main bunker area for the defender.
271+
local mainBunkerArea = SceneMan.Scene:GetOptionalArea("Main Bunker");
272+
if mainBunkerArea ~= nil then
273+
for mainBunkerBox in mainBunkerArea.Boxes do
274+
SceneMan:RevealUnseenBox(mainBunkerBox.Corner.X, mainBunkerBox.Corner.Y, mainBunkerBox.Width, mainBunkerBox.Height, self.playerTeam);
275+
end
276+
end
277+
262278
for Act in MovableMan.AddedActors do
263279
if Act.ClassName ~= "ADoor" then
264280
for ang = 0, math.pi*2, 0.15 do

Data/Base.rte/Actors/Brains/Brainbot/Brainbot.ini

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -742,66 +742,7 @@ AddActor = AHuman
742742
FastTravelSpeed = 4.5
743743
PushForce = 6000
744744
ClimbLimbPath = LimbPath
745-
PresetName = Brainbot Climb Path
746-
StartOffset = Vector
747-
X = 0
748-
Y = -14
749-
StartSegCount = 13
750-
AddSegment = Vector
751-
X = 4
752-
Y = 4
753-
AddSegment = Vector
754-
X = 1
755-
Y = 2
756-
AddSegment = Vector
757-
X = 1
758-
Y = 2
759-
AddSegment = Vector
760-
X = 1
761-
Y = 1
762-
AddSegment = Vector
763-
X = 1
764-
Y = 1
765-
AddSegment = Vector
766-
X = 1
767-
Y = 1
768-
AddSegment = Vector
769-
X = 1
770-
Y = 1
771-
AddSegment = Vector
772-
X = 1
773-
Y = 1
774-
AddSegment = Vector
775-
X = 1
776-
Y = 1
777-
AddSegment = Vector
778-
X = 1
779-
Y = 1
780-
AddSegment = Vector
781-
X = 1
782-
Y = 1
783-
AddSegment = Vector
784-
X = 1
785-
Y = 1
786-
AddSegment = Vector
787-
X = 0
788-
Y = 1
789-
AddSegment = Vector
790-
X = 0
791-
Y = 3
792-
AddSegment = Vector
793-
X = -2
794-
Y = 5
795-
AddSegment = Vector
796-
X = -4
797-
Y = 5
798-
AddSegment = Vector
799-
X = -6
800-
Y = 5
801-
SlowTravelSpeed = 1.5
802-
NormalTravelSpeed = 1.5
803-
FastTravelSpeed = 4.5
804-
PushForce = 7000
745+
CopyOf = Human Climb Path
805746
JumpLimbPath = LimbPath
806747
PresetName = Brainbot Jump Path
807748
StartOffset = Vector

Data/Base.rte/Actors/Mecha/Medic/Medic.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function Update(self)
4545
for _, healTarget in pairs(self.healTargets) do
4646
if healTarget and IsActor(healTarget) and (healTarget.Health < healTarget.MaxHealth or healTarget.WoundCount > 0) and healTarget.Vel.Largest < 10 then
4747
local trace = SceneMan:ShortestDistance(self.Pos, healTarget.Pos, false);
48-
if (trace.Magnitude - healTarget.Radius) < healRange and SceneMan:CastObstacleRay(self.Pos, trace, Vector(), Vector(), parent.ID, parent.IgnoresWhichTeam, rte.grassID, 5) < 0 then
48+
if trace:MagnitudeIsLessThan(healRange + healTarget.Radius) and SceneMan:CastObstacleRay(self.Pos, trace, Vector(), Vector(), parent.ID, parent.IgnoresWhichTeam, rte.grassID, 5) < 0 then
4949
healTarget.Health = math.min(healTarget.Health + self.healStrength, healTarget.MaxHealth);
5050
if self.crossTimer:IsPastSimTimeLimit() then
5151
local cross = CreateMOSParticle("Particle Heal Effect", "Base.rte");
@@ -65,7 +65,7 @@ function Update(self)
6565
for actor in MovableMan.Actors do
6666
if actor.Team == parent.Team and actor.ID ~= parent.ID and (actor.Health < actor.MaxHealth or actor.WoundCount > 0) and actor.Vel.Largest < 5 then
6767
local trace = SceneMan:ShortestDistance(self.Pos, actor.Pos, false);
68-
if (trace.Magnitude - actor.Radius) < (healRange * 0.9) then
68+
if trace:MagnitudeIsLessThan(healRange * 0.9 + actor.Radius) then
6969
if SceneMan:CastObstacleRay(self.Pos, trace, Vector(), Vector(), parent.ID, parent.IgnoresWhichTeam, rte.airID, 3) < 0 then
7070
table.insert(self.healTargets, actor);
7171
end

0 commit comments

Comments
 (0)