Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. -- Get travel time between two nodes in seconds
  3. --------------------------------------------------------------------------------
  4. function Metrostroi.GetTravelTime(src,dest)
  5.     -- Determine direction of travel
  6.     --assert(src.path == dest.path)
  7.     local direction = src.x < dest.x
  8.  
  9.     -- Accumulate travel time
  10.     local travel_time = 0
  11.     local travel_dist = 0
  12.     local travel_speed = 20
  13.     local iter = 0
  14.     function scan(node,path)
  15.         local oldx
  16.         local oldars
  17.         while (node) and (node ~= dest) do
  18.             local ars_speed
  19.             local ars_joint = Metrostroi.GetARSJoint(node,node.x+0.01,path or true)
  20.             if ars_joint then
  21.                 --[[if oldx and oldx ~= ars_joint.TrackPosition.x then
  22.                     print(Format("\t\t\t%.2f:\t%s->%s",(ars_joint.TrackPosition.x - oldx)/18.8,oldars.Name,ars_joint.Name))
  23.                 end
  24.                 oldx = ars_joint.TrackPosition.x
  25.                 oldars = ars_joint]]
  26.                 --print(ars_joint.Name)
  27.                 local ARSLimit = ars_joint:GetMaxARS()
  28.                 --print(ARSLimit)
  29.                 if ARSLimit >= 4  then
  30.                     ars_speed = ARSLimit*10
  31.                 end
  32.                 --print(ars_speed)
  33.             end
  34.             if ars_speed then travel_speed = ars_speed end
  35.             --print(Format("[%03d] %.2f m   V = %02d km/h",node.id,node.length,ars_speed or 0))
  36.  
  37.             -- Assume 70% of travel speed
  38.             local speed = travel_speed * 0.82
  39.  
  40.             -- Add to travel time
  41.             travel_dist = travel_dist + node.length
  42.             travel_time = travel_time + (node.length / (speed/3.6))
  43.             node = node.next
  44.             if not node then break end
  45.             if src.path == dest.path and node.branches and node.branches[1][2].path == src.path then scan(node,src.x > node.branches[1][2].x) end
  46.             if src.path == dest.path and node.branches and  node.branches[2] and node.branches[2][2].path == src.path then scan(node,src.x > node.branches[1][1].x) end
  47.             assert(iter < 10000, "OH SHI~")
  48.             iter = iter + 1
  49.         end
  50.     end
  51.     scan(src)
  52.  
  53.     return travel_time,travel_dist
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement