Better Train Behavior

by Raidwas

Changes trains behavior so they will skip a station if the "wait until" condition is already met

Content
1 year, 8 months ago
1.1
1.38K
Trains

i Add settings for which condition types should be considered for skipping stations

2 years ago

In line 40, shouldnt it be "and train.manal_mode == false"?

2 years ago

Ah forget it I was wrong :D

2 years ago

But I have a suggestion: Could you implement a setting which ignores passed time or inactivity when checking for fulfilled? And maybe a setting, which only checks the circuit conditions (so the train is going to that station only when the circuit condition is not met, but if there other types such as item count can apply)? That would be nice for my usecase.

2 years ago

Hi Natha :)
first things first: thanks for looking through my and the original mods code :D
Now to your suggestions:
1) To be honest I'm not entirely sure what the current behavior is in regards to timers, with this mod I never use timers (not to say your use case isn't valid) ^^
I assume the train just always drives to the station regardless of other conditions if a timer is present in the conditions (and somehow relevant for the and/or structure)?
This I think should be easy to change

2) If I understand your proposal correctly you would like to have options to exclude certain condition types from the decision to skip a station?
So for example the settings would contain (among others) "ignore full cargo", "ignore empty cargo", "ignore circuit condition", etc. The default for all these options would be "false" -> this should match the current behavior if I'm not mistaken.

Concrete example:
We disable all other conditions except circuit conditions by checking all boxes except "ignore circuit condition".
Given a train with a schedule A -> B -> C -> D with the following conditions:
A) Full cargo
B) Some circuit condition which is currently fulfilled (meaning a vanilla train would start driving)
C) Full cargo
D) Empty cargo

Lets assume the train is currently at A and has a full cargo. With how the mod currently works the train would skip B because of the circuit condition, skip C because of the full cargo and thus drive to D.
With your suggestion and the settings outlined above he would still skip B (we did not check the box in the settings), but drive to C as we checked "ignore full cargo".
Did I understand that correct?

On second thought I think both your proposals would be covered by what I outlined in 2), is that right?

2 years ago

Edit: I changed the title as I don't think it qualifies as a bug anymore ;)

2 years ago

Yes you were right. My usecase was a train, which collects all 3 ingredients for a rocket part (fuel, control units, low density structure) in 1 wagon, so no empty/full inventory conditions. The fuel was loaded on a station which also had nuclear fuels, so I couldnt simply disable it if rocket fuel was below a certain amount. I wanted my train to only go to that station if rocket fuel > this certain amount to prevent station blocking. So I thought about setting a circuit condition with the amount of rocket fuel, and the train should skip it until the amount reaches this certain value (wait until circuit condition < amount), but when there the train should not go until all possible fuels are loaded (condition: item count). So check only the circuit conditions if a wait condition is fulfulled.

2 years ago

The thing is, having a setting (which is global for that game) is not that good because I also have other usecases where I need the funcionality as it is now. So maybe a checkbox in the train gui where I can do that setup is better. Since the game engine is a bit restricted in per-train skips it would be neccessary to rewrite the shedule management in a mod for overall functionality.

2 years ago

Thing is, making the option per game would be super simple.
In contrast modifying the train GUI - I'm not even sure if the modding api supports that? I have seen you also wrote some mods, if you know a method to hook into the train GUI to add some buttons, I might consider doing that.

Currently my feeling is that that would go beyond a "simple" mod like this one and would make using the mod much more complicated.

2 years ago

You can add a relative gui which is anchored to one of the ingame guis (player.gui.relative.left/right/top/bottom)...so when opening the train gui, your gui is always shown. you have to update your mod gui with the train-specific settings, and save them when the gui is closed (because the relative gui api doesnt care which train was opened). See cargo-ship mod for example (deep oil rig)

2 years ago

I do not think that I will implement such a functionality as I would like to keep this mod "simple" (as in a new player shouldn't have to figure out what a bunch of new buttons do).

I'm sorry that this mod apparently won't fit your use case, if your use case is complex you could always just go with LTN?

2 years ago

hey, quick question.
Would it still be possible to add a setting to ignore the timer or inactivity options?

2 years ago

Fortunately, I could use this feature though. My train schedules are pretty straightforward:
X Provider:
Cargo full ->
X Requester:
Cargo empty ->
Refuel Depot:
5s Inactivity.

Do note that Refuel Depot is from https://mods.factorio.com/mod/Train_Control_Signals so the train only goes there if it's low on fuel.

Expected behaviour for me would be that trains sit and wait at their Provider stops until a requester stop opens up, and occasionally go to the refuel depot when they need fuel.

What I'm observing is, trains become full, since no requester stop is open (I'm disabling stops so I can do multiple requester stops with priorities), they skip the requester stop and head to the refuel depot to refuel, but then refuse to go back to the Provider stop, therefore clogging up my depots for other trains (since their inventory is already full)

Would love to get this feature as a mod option at least, to ignore certain wait condition types (in my case, Cargo full) so trains play well and also support multiple requester provider/requester priority stops. What say?

2 years ago

Isn't that super easy to make in Vanilla?
Simply set a maximum number of trains at the providers and that should work. (so without this mod here)

2 years ago

My use case is when I have, say, multiple requesters with different priorities. So Provider > Requester P1 > Requester P0 > Refuel. In this case, I can easily do the whole schedule with limits, but after supplying the priority stop, the train would still route to the P0 stop and immediately move ahead as it has no cargo to give, which adds an unnecessary stop for the train to route to every cycle. I'm using the mod to only skip the second requester stop if it already has no cargo and go directly to refuel. Does this make sense?

2 years ago

ah... I must have misunderstood something... ^^

1 year, 9 months ago

Sorry for the late reply I didn't have a lot of time to play recently.

I personally use the following setup, maybe that would also work for you?

Provider P2:
- full cargo
Provider P1:
- full cargo
Depot:
- full cargo
- or 5s passed
Requester P2:
- empty cargo
Requester P1:
- empty cargo
Depot:
- empty cargo
- or 5s passed

This schedule makes it so that the train only drives to the Depot if it cannot directly drive to a Requester/Provider (whichever would be next).
Some considerations for this design though:
1) it removes unnecessary drives to depot, but trains still drive to it if no "useful" stop is available.
From your description I think this would be an anti-feature for you, as the trains still clog up the depots. I find this quite useful though, since if you have multiple trains for the same resource a single train does not clog up the provider (instead the trains clog up depots, but they are full)
2) either the provider or requester stations should supply fuel to prevent the train running out of it

One problem I see with your suggested design:
If the train would (for whatever reason) drive from the refuel Depot back to the provider with a full inventory, what exactly would stop the train from driving to the refuel Depot again?

1 year, 9 months ago

Um...
I kind of don't understand how this is supposed to work for you here.
Wouldn't the train definitely go to Provider P2 unless it's full, skipping Provider P1 every time? Because it only skips Provider P2 if it is already full. Which then leads again to the fact that he also skips Provider P1.
Why do you have Provider P1 then?
The same applies to Requester P1, since it definitely travels to Requester P2 unless it is already empty.

1 year, 9 months ago

Ah, I forgot to mention that I usually disable all providers/requester that are not able to fill/empty the train.

1 year, 9 months ago

Oh, ok... That makes a lot of sense ^^'

New response