Page 1 of 1

Railway and Rail Segment controls

Posted: Sat Jun 10, 2017 11:47 pm
by FrodoOf9Fingers
Factorio trains are one of the best parts of the game (IMHO). Let modders contribute more! It would be awesome to expose more of the pathing algorithm used by trains.

Specifically, I would love to be able to:

-Combine two rail dead ends together logically (IE, for pathing algorithms) (including which path to take and when to slow down). The actual movement of the train between the two dead ends would be handled by the modder OR automatically taken care of via teleportation.
-Manipulate the weight of a piece of rail (or rail segment) for the purpose of pathing algorithms (including which path to take and when to slow down).
-Get a list of every rail segment on a layer(?)

- An api for rail segments might look like:
- A list of pointers to the straight rail and curved rail entities included in the segment.
- A list of pointers to the rail signals marking the beginning(s) and end(s) of the segment (Perhaps two lists: one for start, one for end)
- A list of pointers to bordering rail segments
- The total weight of the segment (not including modifiers from red signals etc...)

-An api for straight/curved rail might look like:
- A pointer to the rail before
- A pointer to the rail after
- A list of pointers to rails that cross this piece of rail
- The train stop attached to this piece of rail
- List of rail signals attached to this piece of rail
- length
- Pathfinding weight multiplier

It would be especially awesome if all of this could be done in such a way as to be independent of the layer(?) that the entities are on.

The general end goal I'm personally trying to reach is creating an underground tunnel mod, similar to an underground belt but for trains. Potential would also include being able to create preferred lanes of traffic for trains (by reducing/increasing the pathing weight of rail/rail segments). It would also allow for trains to traverse across multiple layers, in case anyone wanted to make a mod involving underground mines and wanted to allow trains to go up and down to different levels of a mine. I'm sure there's other good use cases of such interfaces.

Re: Railway and Rail Segment controls

Posted: Mon Jul 01, 2019 9:27 pm
by alercah
Controlling rail segments is one thing, but in order to have crossing rails, you'd also need some mechanism to control collision on the trains so that they don't crash into each other. The engine currently doesn't have any facility (that I can see) that allows this, unfortunately.

Re: Railway and Rail Segment controls

Posted: Mon Jul 01, 2019 10:27 pm
by Rseding91
I don't realistically see this ever happening. If the base game doesn't allow things like tunnels then it's never going to work in mods. Additionally the entire mod API is checked to prevent mods from crashing the game and everything you just described sounds like map corruption and crash central.

Re: Railway and Rail Segment controls

Posted: Tue Jul 02, 2019 6:36 am
by Godmave
I would be happy with at least this: viewtopic.php?f=28&t=67199
Then I could (slowly) piece together the best path myself :p

The "Combine two rail dead ends" is the only one that I would say might break stuff. The rest looks possible to implement without breaking the base game (or even is already implemented).

Some things seem already possible to me, at least on a train "on path" you get access to it's path:
https://lua-api.factorio.com/latest/Lua ... Path.rails

Just give the path the "cost" attribute, and we would be able to puzzle together the total cost of virtual paths (through tunnels and stuff)

"A list of pointers to the rail signals marking the beginning(s) and end(s) of the segment (Perhaps two lists: one for start, one for end)"
https://lua-api.factorio.com/latest/Lua ... ent_entity and other *segment* methods
and "An api for straight/curved rail might look like", etc:
https://lua-api.factorio.com/latest/Lua ... ected_rail