Hi there, I've been creating a mod for automatic vehicle management on lines called "LineManager", GitHub link: https://github.com/TommyC81/TPF2-LineManager.
One item that is critical for this mod is of course the removal and addition of vehicles. Removal is easy using:
However, for adding vehicles, you need to specify a depot. To find a depot I've made use of the following workaround, effectively (temporarily) sending an existing vehicle to depot to see if it can find one then cancel the depot call, but use the found depot_id. Like so:
for _, vehicle_id in pairs(lineVehicles) do
api.cmd.sendCommand(api.cmd.make.sendToDepot(vehicle_id, false))
vehicleToDuplicate = api.engine.getComponent(vehicle_id, api.type.ComponentType.TRANSPORT_VEHICLE)
if vehicleToDuplicate.state == api.type.enum.TransportVehicleState.GOING_TO_DEPOT then
depot_id = vehicleToDuplicate.depot
stop_id = vehicleToDuplicate.stopIndex
local lineCommand = api.cmd.make.setLine(vehicle_id, line_id, stop_id)
api.cmd.sendCommand(lineCommand)
break
end
end
Alles anzeigen
This unfortunately empties the vehicle sent to the depot, which is less than ideal.
Is there a better/sensible way to find a suitable (and accessible) depot for a specific line?
I've looked at the pathfinding functions (https://transportfever2.com/wi…util.pathfinding.findPath), and believe the answer might exist in that functionality. However, this is currently beyond my knowledge and skill to implement (in particular as the associated documentation is virtually non-existent).
Any suggestions or advice is appreciated, many thanks in advance!