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?
Where is the file with the behaviour for the train waiting conditions defined?
-
- 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?
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.
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.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Where is the file with the behaviour for the train waiting conditions defined?
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.htmlJohannes_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?
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.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
-
- 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?
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.robot256 wrote: Sat Jul 16, 2022 12:17 pmI might have misread your question.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?
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
-
- 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?
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 wrote: Sat Jul 16, 2022 12:17 pmI 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.htmlJohannes_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?
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.
Re: Where is the file with the behaviour for the train waiting conditions 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.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.
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.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.