diff --git a/src/railnetwork/apis/railnetwork b/src/railnetwork/apis/railnetwork index af5c62c..0378f62 100644 --- a/src/railnetwork/apis/railnetwork +++ b/src/railnetwork/apis/railnetwork @@ -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 @@ -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 diff --git a/src/railrouter/startup b/src/railrouter/startup index 592d1f8..07dc5ea 100644 --- a/src/railrouter/startup +++ b/src/railrouter/startup @@ -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 diff --git a/src/railstation/.manifest b/src/railstation/.manifest index bb5b8d2..90d90d6 100644 --- a/src/railstation/.manifest +++ b/src/railstation/.manifest @@ -7,6 +7,7 @@ {name = "wire"}, {name = "minecartevents"}, {name = "input"}, + {name = "graph"}, {name = "railnetwork"}, {name = "autostartup"}, {name = "amber-autoupdater"} diff --git a/src/railstation/startup b/src/railstation/startup index 09faebc..6539ffc 100644 --- a/src/railstation/startup +++ b/src/railstation/startup @@ -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") @@ -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 @@ -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