Advertisement
Guest User

Untitled

a guest
May 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1.     path = path or Path("Follow")
  2.     local tries = 0
  3.     local viable = path:Compute(self, pos, function( area, fromArea, ladder, elevator, length )
  4.         if tries > 20000 then
  5.             return -1
  6.         end
  7.         tries = tries + 1
  8.         if ( !IsValid( fromArea ) ) then
  9.             // first area in path, no cost
  10.             return 0
  11.         else
  12.  
  13.             if not self:CanFitInArea(area) then
  14.                 return -1
  15.             end
  16.  
  17.             if ( !self.loco:IsAreaTraversable( area ) ) then
  18.                 // our locomotor says we can't move here
  19.                 return -1
  20.             end
  21.  
  22.             // compute distance traveled along path so far
  23.             local dist = 0
  24.  
  25.             if ( IsValid( ladder ) ) then
  26.                 dist = ladder:GetLength()
  27.             elseif ( length > 0 ) then
  28.                 // optimization to avoid recomputing length
  29.                 dist = length
  30.             else
  31.                 dist = ( area:GetCenter() - fromArea:GetCenter() ):GetLength()
  32.             end
  33.  
  34.             local cost = dist + fromArea:GetCostSoFar()
  35.  
  36.             // check height change
  37.             local deltaZ = fromArea:ComputeAdjacentConnectionHeightChange( area )
  38.             if ( deltaZ >= self.loco:GetStepHeight() ) then
  39.                 if ( deltaZ >= self.loco:GetMaxJumpHeight() ) then
  40.                     // too high to reach
  41.                     return -1
  42.                 end
  43.  
  44.                 // jumping is slower than flat ground
  45.                 local jumpPenalty = 5
  46.                 cost = cost + jumpPenalty * dist
  47.             elseif ( deltaZ < -self.loco:GetDeathDropHeight() ) then
  48.                 // too far to drop
  49.                 return -1
  50.             end
  51.             return cost
  52.         end
  53.     end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement