Skip to content

Commit 2c2ce5d

Browse files
committed
AI now runs whan appropriate
1 parent acbad35 commit 2c2ce5d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Data/Base.rte/AI/NativeHumanAI.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function NativeHumanAI:Create(Owner)
1717
Members.fire = false;
1818
Members.groundContact = 5;
1919
Members.flying = false;
20+
Members.running = false;
2021

2122
Members.squadShoot = false;
2223
Members.useMedikit = false;
@@ -29,6 +30,9 @@ function NativeHumanAI:Create(Owner)
2930
Members.SquadShootTimer = Timer();
3031
Members.SquadShootDelay = math.random(50,100);
3132

33+
Members.RunStateTimer = Timer();
34+
Members.RunStateTimer:SetSimTimeLimitMS(math.random(2000,5000));
35+
3236
Members.AlarmTimer = Timer();
3337
Members.AlarmTimer:SetSimTimeLimitMS(400);
3438

@@ -336,6 +340,18 @@ function NativeHumanAI:Update(Owner)
336340
end
337341
end
338342

343+
local AlarmPoint = Owner:GetAlarmPoint();
344+
345+
-- If we currently have a target or are alerted, we walk. Otherwise we run
346+
-- We also have a small random chance to walk for a lil bit
347+
local wasAlarmed = AlarmPoint.Largest > 0;
348+
if wasAlarmed or self.RunStateTimer:IsPastSimTimeLimit() then
349+
self.running = self.Target == nil and not wasAlarmed and math.random() < 0.6;
350+
self.RunStateTimer:Reset();
351+
end
352+
353+
self.Ctrl:SetState(Controller.MOVE_FAST, self.running);
354+
339355
self.squadShoot = false;
340356
if Owner.MOMoveTarget then
341357
-- make the last waypoint marker stick to the MO we are following
@@ -547,7 +563,6 @@ function NativeHumanAI:Update(Owner)
547563
end
548564

549565
-- listen and react to AlarmEvents and AlarmPoints
550-
local AlarmPoint = Owner:GetAlarmPoint();
551566
if AlarmPoint.Largest > 0 then
552567
if not self.Target and not self.UnseenTarget then
553568
self.AlarmPos = Vector(AlarmPoint.X, AlarmPoint.Y);

0 commit comments

Comments
 (0)