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

Commit 5b91a31

Browse files
committed
Replace even more magnitude checks with new functions
1 parent a4c3a0f commit 5b91a31

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

Data/Base.rte/AI/CrabBehaviors.lua

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

610610
-- check if we can fire at the AimPoint
611611
local Trace = SceneMan:ShortestDistance(Owner.EyePos, AimPoint, false);
612-
local rayLenght = SceneMan:CastObstacleRay(Owner.EyePos, Trace, Vector(), Vector(), rte.NoMOID, Owner.IgnoresWhichTeam, rte.grassID, 11);
613-
if Trace.Magnitude * 0.67 < rayLenght then
612+
local rayLength = SceneMan:CastObstacleRay(Owner.EyePos, Trace, Vector(), Vector(), rte.NoMOID, Owner.IgnoresWhichTeam, rte.grassID, 11);
613+
if Trace:MagnitudeIsLessThan(rayLength * 1.5) then
614614
break; -- the AimPoint is close enough to the target, start shooting
615615
end
616616

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
@@ -1452,8 +1451,7 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
14521451
local RandomWpt = WptList[test];
14531452
if RandomWpt then
14541453
Dist = SceneMan:ShortestDistance(Owner.Pos, RandomWpt.Pos, false);
1455-
local mag = Dist.Magnitude;
1456-
if mag < 50 and mag < SceneMan:ShortestDistance(Owner.Pos, Waypoint.Pos, false).Magnitude/3 then
1454+
if Dist:MagnitudeIsLessThan(50) and Dist:MagnitudeIsLessThan(SceneMan:ShortestDistance(Owner.Pos, Waypoint.Pos, false).Magnitude * 0.33) then
14571455
-- this waypoint is closer, check LOS
14581456
if -1 == SceneMan:CastObstacleRay(Owner.Pos, Dist, Vector(), Vector(), Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 4) then
14591457
Waypoint = RandomWpt; -- go here instead
@@ -2993,8 +2991,8 @@ function HumanBehaviors.ShootArea(AI, Owner, Abort)
29932991

29942992
-- check if we can fire at the AimPoint
29952993
local Trace = SceneMan:ShortestDistance(Owner.EyePos, AimPoint, false);
2996-
local rayLenght = SceneMan:CastObstacleRay(Owner.EyePos, Trace, Vector(), Vector(), rte.NoMOID, Owner.IgnoresWhichTeam, rte.grassID, 11);
2997-
if Trace.Magnitude * 0.67 < rayLenght then
2994+
local rayLength = SceneMan:CastObstacleRay(Owner.EyePos, Trace, Vector(), Vector(), rte.NoMOID, Owner.IgnoresWhichTeam, rte.grassID, 11);
2995+
if Trace:MagnitudeIsLessThan(rayLength * 1.5) then
29982996
break; -- the AimPoint is close enough to the target, start shooting
29992997
end
30002998

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/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)