Skip to content

Commit

Permalink
#16: Output route information before departure.
Browse files Browse the repository at this point in the history
  • Loading branch information
danports committed May 18, 2020
1 parent dad98e7 commit 589b89c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/railnetwork/apis/railnetwork
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ function RailNetwork:findRoute(trip)
local distance = edge.distance or 1
if edge.tags and trip.tags then
for tag, weight in pairs(edge.tags) do
if trip.tags[tag] then
if trip.tags[tag] == true then
distance = distance * weight
else
elseif trip.tags[tag] == false then
return math.huge
end
end
Expand All @@ -194,11 +194,11 @@ function RailNetwork:findRoute(trip)
end
if not locationsMatch(trip.origin, originNode) then
-- Add an edge for the segment between the origin and the first location in the network.
table.insert(path, 1, {destination = formatLocation(originNode)})
table.insert(path, 1, {edge = {destination = formatLocation(originNode)}, weight = 1})
end
if not locationsMatch(trip.destination, destinationNode) then
-- Add an edge for the segment between the last location in the network and the final destination.
table.insert(path, {destination = formatLocation(trip.destination)})
table.insert(path, {edge = {destination = formatLocation(trip.destination)}, weight = 1})
end
return path
end
Expand Down
2 changes: 1 addition & 1 deletion src/railrouter/startup
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function minecartDetected(detection)
return
end

local switchState = edge.switchState or false
local switchState = edge.edge.switchState or false
log.info(string.format("Setting switch %i to %s", detection.switchId, tostring(switchState)))
net.sendMessage(switch.computerId, "setSwitch", {state = switchState})
end
Expand Down
1 change: 1 addition & 0 deletions src/railstation/.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{name = "wire"},
{name = "minecartevents"},
{name = "input"},
{name = "graph"},
{name = "railnetwork"},
{name = "autostartup"},
{name = "amber-autoupdater"}
Expand Down
8 changes: 6 additions & 2 deletions src/railstation/startup
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ os.loadAPI("apis/serializer")
os.loadAPI("apis/wire")
os.loadAPI("apis/minecartevents")
os.loadAPI("apis/input")
os.loadAPI("apis/graph")
os.loadAPI("apis/railnetwork")
os.loadAPI("apis/autostartup")
os.loadAPI("apis/autoupdater")
Expand Down Expand Up @@ -58,8 +59,10 @@ function selectDepartureRoute(trip)
table.insert(routeOptions, tags)
end
if #routeOptions == 1 then
print(string.format("Only one route to %s; preparing departure: %s",
railnetwork.formatLocation(trip.destination), formatRouteTags(routeOptions[1])))
local key, route = next(trip.routes)
print(string.format("Only one route to %s (%s); preparing departure: %s",
railnetwork.formatLocation(trip.destination), formatRouteTags(routeOptions[1]),
graph.formatPath(railnetwork.formatLocation(trip.origin), route)))
trip.routes = nil
handleDeparture(trip)
return
Expand All @@ -74,6 +77,7 @@ function selectDepartureRoute(trip)
end
trip.routes = nil
trip.tags = selected[1]
print(string.format("Preparing departure: %s", graph.formatPath(railnetwork.formatLocation(trip.origin), trip.routes[selected])))
handleDeparture(trip)
end

Expand Down

0 comments on commit 589b89c

Please sign in to comment.