Rivens Dynamic Train Weight


This mod makes train weight depend on cargo, realistically affects acceleration and braking.

Tweaks
6 months ago
1.1
344
Transportation Trains

i Delay recalculation until moving?

9 months ago

I love the idea of this mod, but I'm deterred by how it affects the interaction of pumps with fluid wagons, especially the deletion of circuit connections.

Would it be feasible to delay calculating weight and replacing wagon entities until the train is leaving the station?

9 months ago
(updated 9 months ago)

That would seem like the ideal solution, however, it means the train loses its target, it's "slot" in the train-limit logic in the target station, and loses its path. So... that's why we have this problem :')

Edit: This is because when changing a carriage, the game sees it as an entirely new train.

Lets say we have this train: LCCCC, and we want to turn it into LCXCC (X = heavier cargo-wagon)
I remove and spawn a new wagon at the same position, within 1 game tick. This is what the game sees:
- LCCCC (train 1)
- LC..CC (train 2: "LC", train 3: "CC")
- LCXCC (train 4: "LCXCC")

This is why the train-ID typically goes up by 3 when a carriage is changed.

9 months ago

I see!... I appreciate the explanation! I thank you for your patience, especially as it prompts more curiosity:

so, changing the train while it's still stopped works? is this because the new train is instantly stopped at that station, and can begin waiting for the same conditions to leave? (side question from this, does the weight change cause "time passed" conditions to start over?)

my understanding is that creating and canceling the trip to the next station is where a problem lies. my knowledge is limited, and my train schedules are perhaps too small in scale to be affected, but why exactly is it a problem if it targets a station, gives up its path, and then its heavier twin tries the same station name? if there's no room at the destination(s), wouldn't it be the most recent train to queue regardless?

if it must avoid that pattern, would it be possible to add a temporary stop at its current position, update the wagons there, then promptly target the next real station on the schedule? or would that just be venturing into a whole new world of broken side effects?

9 months ago
(updated 9 months ago)

This is my understanding of how train-station-limits work:
- each station has a list of 'approaching trains'.
- this list has a maximum length of N.
- when a train wants to go to a station, it tries to put itself in the list, if the list is already full, it fails.
- the train tries another startion with the same name, if such a station exists.
- if no station with non-full 'approaching trains' list exists, the train will have 'no destination'
- if a station with non-full 'approaching trains' list exists, the train will register itself to the list, and head to it.
- the moment the train starts moving (from the station it is currently at), it deregisters itself from the list of its current station
- this means that other trains get notified and will attempt to visit the current station

So... when happens when we swap out a cargo-wagon, thereby destroying a train, and creating a new one...
- upon detroying it, it will deregister itself from the 'approaching trains' list of its destination
- upon recreating it, it will try to find a new destination, based on the station-name (it may have forgotten its previous target station)

This all is not really a problem, when the train is standing still at a station, and it doesn't have a route yet.
However, when the train is moving, the train may lose its place in the list of its target, and find no alternative, forcing it to stop.
To add insult to injury, once the train is on its ways, even when it moved 1 pixel, it deregistered itself from the current station, meaning other trains will move to the station. If the current train has no destination anymore, it will be stuck where it is, while other trains will target the current station, breaking the 'train limit' mechanic.

9 months ago
(updated 9 months ago)

ah.. so the issue isn't really at the target station, it's that using "leaving the station" as the trigger tells searching trains there's a free space, while in truth there's a train still parked in it, unaccounted for

...with this, I have one last idea to run past you, if you'll permit, just in case there's any reasonable (& even possible) way you'd want to implement it:

  1. Train fulfills conditions to leave current station and leaves
  2. at the same moment, if current station has a train limit N, set it to N-1 (in some non-destructive sort of way that would remain true if the limit changes during this time (also this whole method falls apart if the Nth train is able to reserve its spot in the same tick)) ... so, now, if the 'approaching' list is full, the number of trains waiting at the current station is technically N-1, but practically N (as Train is still physically parked there), so that an Nth train won't find a spot there yet
  3. Train is given a temporary stop at its current position, before it's actually traveled any significant distance out of the station.
  4. Train reaches the temporary stop and waits the minimum time needed to swap weighted wagons
  5. Schedule advances to the actual next station, and it may or may not find a non-full destination
  6. Once it's successfully on its way and the temporary stop is cleared, cease subtracting from the station limit

...

even if this works, i just realized how high the chances are that the temporary stop will have unexpected interactions with pumps and inserters at that location.

...
y'know,

I'm beginning to suspect that slightly adjusting my use of circuits and not looking too closely at the pump animations will be a bit easier.

thinking about this sort of problem is kind of fun. thank you again!

9 months ago
(updated 9 months ago)

It may be an option to insert an artificial waiting-condition in the train-schedule for the current train stop... and use that to delay the departure, and change the wagon-weight, but I have, at the moment, no idea how i can (easily) check whether "all conditions except the artificial one" are met.

6 months ago

So as far as i can tell there's no way to change the properties (weight) of a wagon without just straight up deleting the old one and replacing it with a new one that's been modified? because this causes a number of interesting interactions.

if you have 2 trains queued up too close to eachother, then the train being loaded/offloaded hooks into the one directly behind it, merging them. overwriting the schedule of one of them and with certain wait conditions the train will end up never leaving either.
pumps become either glitchy or completely unresponsive.
wagons lose their filtered slots whenever they're regenerated.

6 months ago
(updated 6 months ago)

Earlier today I updated the homepage of the mod, that explains the known issue with pumps. In the previous version, I removed the pump and recreated it, which had the issue of the pump-contents (fluids) getting destroyed, and the pump-hose having to re-attach. In today's version, the pump is rotated twice (spread over 2 frames). This causes a graphical glitch, but the hose remains attached and the fluids are not lost anymore. In my testing today, I haven't seen it breaking the pump, yet.

Regarding the wagons of different trains merging -- I can see how that could happen, and I don't think there is a fix. Just put that rail-signal one notch further - in reality separate trains wouldn't be that close to eachother either :)

Regarding the filtered slots: that is was an oversight and I will add support for it Soon (tm).

6 months ago

thanks for the quick response and rapid fixes. i'll be sure to report any other weird behaviours or problems i encounter.

New response