Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- path = path or Path("Follow")
- local tries = 0
- local viable = path:Compute(self, pos, function( area, fromArea, ladder, elevator, length )
- if tries > 20000 then
- return -1
- end
- tries = tries + 1
- if ( !IsValid( fromArea ) ) then
- // first area in path, no cost
- return 0
- else
- if not self:CanFitInArea(area) then
- return -1
- end
- if ( !self.loco:IsAreaTraversable( area ) ) then
- // our locomotor says we can't move here
- return -1
- end
- // compute distance traveled along path so far
- local dist = 0
- if ( IsValid( ladder ) ) then
- dist = ladder:GetLength()
- elseif ( length > 0 ) then
- // optimization to avoid recomputing length
- dist = length
- else
- dist = ( area:GetCenter() - fromArea:GetCenter() ):GetLength()
- end
- local cost = dist + fromArea:GetCostSoFar()
- // check height change
- local deltaZ = fromArea:ComputeAdjacentConnectionHeightChange( area )
- if ( deltaZ >= self.loco:GetStepHeight() ) then
- if ( deltaZ >= self.loco:GetMaxJumpHeight() ) then
- // too high to reach
- return -1
- end
- // jumping is slower than flat ground
- local jumpPenalty = 5
- cost = cost + jumpPenalty * dist
- elseif ( deltaZ < -self.loco:GetDeathDropHeight() ) then
- // too far to drop
- return -1
- end
- return cost
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement