@@ -31,7 +31,7 @@ function CrabBehaviors.LookForTargets(AI, Owner)
3131 FoundMO = ToACRocket (FoundMO );
3232 elseif FoundMO .ClassName == " ACDropShip" then
3333 FoundMO = ToACDropShip (FoundMO );
34- elseif FoundMO .ClassName == " ADoor" and FoundMO .Team ~= Activity .NOTEAM and Owner .AIMode ~= Actor .AIMODE_SENTRY and ToADoor (FoundMO ).Door and ToADoor (FoundMO ).Door :IsAttached () and HumanBehaviors .GetProjectileData (Owner ).pen * 0.9 > ToADoor (FoundMO ).Door .Material .StructuralIntegrity then
34+ elseif FoundMO .ClassName == " ADoor" and FoundMO .Team ~= Activity .NOTEAM and Owner .AIMode ~= Actor .AIMODE_SENTRY and ToADoor (FoundMO ).Door and ToADoor (FoundMO ).Door :IsAttached () and SharedBehaviors .GetProjectileData (Owner ).pen * 0.9 > ToADoor (FoundMO ).Door .Material .StructuralIntegrity then
3535 FoundMO = ToADoor (FoundMO );
3636 elseif FoundMO .ClassName == " Actor" then
3737 FoundMO = ToActor (FoundMO );
@@ -42,7 +42,7 @@ function CrabBehaviors.LookForTargets(AI, Owner)
4242 if FoundMO then
4343 if AI .Target then
4444 -- check if this MO should be targeted instead
45- if HumanBehaviors .CalculateThreatLevel (FoundMO , Owner ) > HumanBehaviors .CalculateThreatLevel (AI .Target , Owner ) + 0.2 then
45+ if SharedBehaviors .CalculateThreatLevel (FoundMO , Owner ) > SharedBehaviors .CalculateThreatLevel (AI .Target , Owner ) + 0.2 then
4646 AI .OldTargetPos = Vector (AI .Target .Pos .X , AI .Target .Pos .Y );
4747 AI .Target = FoundMO ;
4848 AI .TargetOffset = SceneMan :ShortestDistance (AI .Target .Pos , HitPoint , false ); -- this is the distance vector from the target center to the point we hit with our ray
@@ -257,182 +257,6 @@ function CrabBehaviors.Sentry(AI, Owner, Abort)
257257 return true ;
258258end
259259
260- -- move to the next waypoint
261- function CrabBehaviors .GoToWpt (AI , Owner , Abort )
262- if not Owner .MOMoveTarget then
263- if SceneMan :ShortestDistance (Owner :GetLastAIWaypoint (), Owner .Pos , false ).Largest < Owner .Height * 0.15 then
264- Owner :ClearAIWaypoints ();
265- Owner :ClearMovePath ();
266-
267- if Owner .AIMode == Actor .AIMODE_GOTO then
268- AI .SentryFacing = Owner .HFlipped ; -- guard this direction
269- AI .SentryPos = Vector (Owner .Pos .X , Owner .Pos .Y ); -- guard this point
270- Owner .AIMode = Actor .AIMODE_SENTRY ;
271- end
272-
273- AI :CreateSentryBehavior (Owner );
274-
275- return true ;
276- end
277- end
278-
279- local UpdatePathTimer = Timer ();
280- UpdatePathTimer :SetSimTimeLimitMS (5000 );
281-
282- local StuckTimer = Timer ();
283- StuckTimer :SetSimTimeLimitMS (2000 );
284-
285- local WptList , Waypoint , Dist , CurrDist ;
286-
287- while true do
288- while AI .Target and Owner .FirearmIsReady do -- don't move around if we have something to shoot at
289- local _ai , _ownr , _abrt = coroutine.yield (); -- wait until next frame
290- if _abrt then return true end
291- end
292-
293- if Owner .Vel :MagnitudeIsGreaterThan (2 ) then
294- StuckTimer :Reset ();
295- end
296-
297- if Owner .MOMoveTarget then -- make the last waypoint marker stick to the MO we are following
298- if MovableMan :ValidMO (Owner .MOMoveTarget ) then
299- Owner :RemoveMovePathEnd ();
300- Owner :AddToMovePathEnd (Owner .MOMoveTarget .Pos );
301- else
302- Owner .MOMoveTarget = nil ;
303- end
304- end
305-
306- if UpdatePathTimer :IsPastSimTimeLimit () then
307- UpdatePathTimer :Reset ();
308- AI .deviceState = AHuman .STILL ;
309- AI .lateralMoveState = Actor .LAT_STILL ;
310- Waypoint = nil ;
311- WptList = nil ;
312- elseif StuckTimer :IsPastSimTimeLimit () then -- dislodge
313- StuckTimer :Reset ();
314- if AI .lateralMoveState == Actor .LAT_LEFT then
315- AI .lateralMoveState = Actor .LAT_RIGHT ;
316- elseif AI .lateralMoveState == Actor .LAT_LEFT then
317- AI .lateralMoveState = Actor .LAT_LEFT ;
318- else
319- AI .lateralMoveState = math.random (Actor .LAT_LEFT , Actor .LAT_RIGHT );
320- end
321- elseif WptList then -- we have a list of waypoints, folow it
322- if not WptList [1 ] and not Waypoint then -- arrived
323- if Owner .MOMoveTarget then -- following actor
324- if MovableMan :ValidMO (Owner .MOMoveTarget ) then
325- local Trace = SceneMan :ShortestDistance (Owner .Pos , Owner .MOMoveTarget .Pos , false );
326- -- stop here if the MOMoveTarget is close and in LOS
327- if Trace .Largest < Owner .Height * 0.5 + Owner .MOMoveTarget .Radius and SceneMan :CastStrengthRay (Owner .Pos , Trace , 5 , Vector (), 4 , rte .grassID , true ) then
328- while true do
329- AI .lateralMoveState = Actor .LAT_STILL ;
330- local _ai , _ownr , _abrt = coroutine.yield (); -- wait until next frame
331- if _abrt then return true end
332-
333- if Owner .MOMoveTarget and MovableMan :ValidMO (Owner .MOMoveTarget ) then
334- Trace = SceneMan :ShortestDistance (Owner .Pos , Owner .MOMoveTarget .Pos , false );
335- if Trace .Largest > Owner .Height * 0.7 + Owner .MOMoveTarget .Radius then
336- Waypoint = {Pos = Owner .MOMoveTarget .Pos };
337- break ;
338- end
339- end
340- end
341- else
342- WptList = nil ; -- update the path
343- break ;
344- end
345- end
346- else -- moving towards a scene point
347- if SceneMan :ShortestDistance (Owner :GetLastAIWaypoint (), Owner .Pos , false ).Largest < Owner .Height * 0.4 then
348- if Owner .AIMode == Actor .AIMODE_GOTO then
349- AI .SentryFacing = Owner .HFlipped ; -- guard this direction
350- AI .SentryPos = Vector (Owner .Pos .X , Owner .Pos .Y ); -- guard this point
351- AI :CreateSentryBehavior (Owner );
352- end
353-
354- Owner :ClearAIWaypoints ();
355- Owner :ClearMovePath ();
356-
357- break ;
358- end
359- end
360- else
361- if not Waypoint then -- get the next waypoint in the list
362- UpdatePathTimer :Reset ();
363- Waypoint = table.remove (WptList , 1 );
364- if WptList [1 ] then
365- Owner :RemoveMovePathBeginning ();
366- elseif not Owner .MOMoveTarget and SceneMan :ShortestDistance (Owner .Pos , Waypoint .Pos , false ):MagnitudeIsLessThan (Owner .MoveProximityLimit ) then -- the last waypoint
367- Owner :ClearMovePath ();
368- WptList = nil ;
369- Waypoint = nil ;
370- end
371- end
372-
373- if Waypoint then
374- CurrDist = SceneMan :ShortestDistance (Owner .Pos , Waypoint .Pos , false );
375- if CurrDist .X < - 3 then
376- AI .lateralMoveState = Actor .LAT_LEFT ;
377- elseif CurrDist .X > 3 then
378- AI .lateralMoveState = Actor .LAT_RIGHT ;
379- end
380-
381- if CurrDist :MagnitudeIsLessThan (Owner .MoveProximityLimit ) then
382- Waypoint = nil ;
383- end
384- end
385- end
386- else -- no waypoint list, create one
387- local TmpList = {};
388- table.insert (TmpList , {Pos = Owner .Pos });
389-
390- Owner :UpdateMovePath ();
391-
392- -- wait until movepath is updated
393- while Owner .IsWaitingOnNewMovePath do
394- local _ai , _ownr , _abrt = coroutine.yield ();
395- if _abrt then return true end
396- end
397-
398- Owner :DrawWaypoints (true );
399-
400- for WptPos in Owner .MovePath do -- skip any waypoint too close to the previous one
401- if SceneMan :ShortestDistance (TmpList [# TmpList ].Pos , WptPos , false ):MagnitudeIsGreaterThan (10 ) then
402- table.insert (TmpList , {Pos = WptPos });
403- end
404- end
405-
406- if # TmpList < 3 then
407- Dist = nil ;
408- if TmpList [2 ] then
409- Dist = SceneMan :ShortestDistance (TmpList [2 ].Pos , Owner .Pos , false );
410- end
411-
412- -- already at the target
413- if not Dist or Dist :MagnitudeIsLessThan (25 ) then
414- Owner :ClearMovePath ();
415- break ;
416- end
417- end
418-
419- WptList = TmpList ;
420-
421- -- create the move path seen on the screen
422- Owner :ClearMovePath ();
423- for _ , Wpt in pairs (TmpList ) do
424- Owner :AddToMovePathEnd (Wpt .Pos );
425- end
426- end
427-
428- local _ai , _ownr , _abrt = coroutine.yield (); -- wait until next frame
429- if _abrt then return true end
430- end
431-
432- return true ;
433- end
434-
435-
436260-- open fire on the selected target
437261function CrabBehaviors .ShootTarget (AI , Owner , Abort )
438262 if not MovableMan :ValidMO (AI .Target ) then
0 commit comments