Where is the file with the behaviour for the train waiting conditions defined?

Place to get help with not working mods / modding interface.
Johannes_00
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Jul 16, 2022 8:21 am
Contact:

Where is the file with the behaviour for the train waiting conditions defined?

Post by Johannes_00 »

Hello, i want to make a little mod which adds waiting conditions for the trains.
However, i just can't find the file that defines for which type of waiting condition it does what.
Shouldn't there be a file like control.lua which defines the behaviour for the trains and other entities?
robot256
Smart Inserter
Smart Inserter
Posts: 1248
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Where is the file with the behaviour for the train waiting conditions defined?

Post by robot256 »

99.9% of the Factorio application is written in C++ and compiled into a binary executable before distribution. The only reason mods can execute Lua code is because the C++ source includes a sandboxed Lua interpreter and API functions that allow Lua to trigger certain changes in the C++ game state. This is the reason, for example, that a crash in Lua code does not crash Factorio to the desktop: the Lua code is a "guest" training on top of the C++ application.

Train scheduling and pathfinding is all executed directly within the C++ game. The API allows mods to alter train schedules at any time using the available schedule record and condition types. More complex behavior can be achieved by having the mod modify a train's schedule at specific times, based on other information the mod collects. A few schedule record types are available to mods which the player cannot access: Temporary station records and permanent rail-coordinate records.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
robot256
Smart Inserter
Smart Inserter
Posts: 1248
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Where is the file with the behaviour for the train waiting conditions defined?

Post by robot256 »

Johannes_00 wrote: Sat Jul 16, 2022 8:42 am Hello, i want to make a little mod which adds waiting conditions for the trains.
However, i just can't find the file that defines for which type of waiting condition it does what.
Shouldn't there be a file like control.lua which defines the behaviour for the trains and other entities?
I might have misread your question. To expand on my previous answer, to find what API features are available for mod Lua code to use, look in the Lua API documentation: https://lua-api.factorio.com/latest/index.html

The schedule of a Train can be read or written using LuaTrain::schedule. To write the schedule, you must create the full schedule as a Lua Table according to the TrainSchedule format, which includes an array of TrainScheduleRecord tables, which each include an array of WaitCondition tables, which can each be set to one of the listed types.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2767
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Where is the file with the behaviour for the train waiting conditions defined?

Post by FuryoftheStars »

robot256 wrote: Sat Jul 16, 2022 12:17 pm
Johannes_00 wrote: Sat Jul 16, 2022 8:42 am Hello, i want to make a little mod which adds waiting conditions for the trains.
However, i just can't find the file that defines for which type of waiting condition it does what.
Shouldn't there be a file like control.lua which defines the behaviour for the trains and other entities?
I might have misread your question.
I was reading it the same way you initially did. It sounds like they want to create new wait conditions and define their behavior, which, of course, can’t be done as that’s all engine side.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
Johannes_00
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Jul 16, 2022 8:21 am
Contact:

Re: Where is the file with the behaviour for the train waiting conditions defined?

Post by Johannes_00 »

robot256 wrote: Sat Jul 16, 2022 12:17 pm
Johannes_00 wrote: Sat Jul 16, 2022 8:42 am Hello, i want to make a little mod which adds waiting conditions for the trains.
However, i just can't find the file that defines for which type of waiting condition it does what.
Shouldn't there be a file like control.lua which defines the behaviour for the trains and other entities?
I might have misread your question. To expand on my previous answer, to find what API features are available for mod Lua code to use, look in the Lua API documentation: https://lua-api.factorio.com/latest/index.html

The schedule of a Train can be read or written using LuaTrain::schedule. To write the schedule, you must create the full schedule as a Lua Table according to the TrainSchedule format, which includes an array of TrainScheduleRecord tables, which each include an array of WaitCondition tables, which can each be set to one of the listed types.
You actually didn't misread the question. My intention was, as FuryoftheStars said, to add new types of waiting conditions like "full_cargo_wagons" and then extend this new case with the appropriate behaviour where its initially defined.
robot256
Smart Inserter
Smart Inserter
Posts: 1248
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Where is the file with the behaviour for the train waiting conditions defined?

Post by robot256 »

Johannes_00 wrote: Sat Jul 16, 2022 3:30 pm You actually didn't misread the question. My intention was, as FuryoftheStars said, to add new types of waiting conditions like "full_cargo_wagons" and then extend this new case with the appropriate behaviour where its initially defined.
I have used the Inventory Sensor mod in the past to read the contents of each individual wagon, calculate what I need, and send it to a circuit schedule condition.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Post Reply

Return to “Modding help”