please add method find_train_path()

Post your ideas and suggestions how to improve the game.
Post Reply
mrvn
Smart Inserter
Smart Inserter
Posts: 4105
Joined: Mon Sep 05, 2016 9:10 am
Contact:

please add method find_train_path()

Post by mrvn »

TL;DR
There is no easy way for mod that manage train schedules (e.g. Logistic Train Network) to check if a station is reachable for a train or which station of a set would be the best choice.
What ?

Code: Select all

find_train_path{from_entity=…, to_entities=…, train=…, bidirectional=…}

Find best train path.

Parameters
Table with the following fields:

    from_entity :: LuaEntity (optional), defaults to train location, Rail, TrainStop or Signal
    to_entities :: array of LuaEntity, Rail or TrainStop
    train :: LuaTrain (optional)
    from_direction :: LuaEntity or defines.rail_direction (optional)
                     - with rail default to directions allowed on the rail
                       entity given must be a rail connected to the from_entity rail and determines the direction
                     - with train defaults to directions the train can travel
                     - with train stop defaults in both directions
                       forward means the direction the train stop is facing
                     - with signal defaults to the direction of the signal, both if it has a signal on the opposite side
                       forward means the direction the signal is on, backward the opposite for paired signals
    to_direction :: defines.rail_direction or array of LuaEntity or defines.rail_direction or nil (optional)
                     - if array then entries match with to_entities
                     - with train stop as goal always use the direction the stop is facing
                     - with signal as goal defaults to the direction of the signal, both if it has a signal on the opposite side
                       forward means the direction the signal is on, backward the opposite for paired signals
                     - with rails defaults to directions allowed on the rail
                       entity given must be a rail connected to the goal rail and determines the direction

Return value
The LuaTrainPath the pathfinding setteled on as best.
I'm not sure if from_direction and to_direction can be specified for the games pathfinder like this. Also looks really complicated. Only include them if the existing pathfinder allows for it easily and it makes sense to you. I see the main use case as being train stop to train stop searches with and without train. In the later case from_direction=defines.rail_direction.forward would be an important feature to disable searching in both directions.
Why ?
Mods that mange train schedules automagically have no good way of judging costs between stations. The best that can be done is the manhatten distance, which is a really poor estimation of the cost of going form A to B by train. Luckily the game already has a highly optimized algorithm for trains to pick the best destination. All it needs is to make this accessible to mods.

With the new method the mod could build up a list of possible destinations and ask the game to pick the best. The result can then be used to build / update the schedule for the train.

The LuaRailPath would also tell if the train arrives in forward or backward direction. Something that is important when dealing with bidirectional trains that are not palindrom.

Post Reply

Return to “Ideas and Suggestions”

Who is online

Users browsing this forum: No registered users