Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back engines stopping on curve get disconnected #3

Open
ChuckSavage opened this issue Mar 30, 2018 · 24 comments
Open

Back engines stopping on curve get disconnected #3

ChuckSavage opened this issue Mar 30, 2018 · 24 comments

Comments

@ChuckSavage
Copy link
Contributor

Hey, thanks for this great mod.

I've had a lot of trouble with trains losing an engine off the back end if the engine is on a curve when the train comes to a stop.

I run 242 trains, and where I notice the biggest problem is the train stopping at a signal, and the back end of the train is on a curve. The end locomotive becomes disconnected.

I'm running v0.0.3

@NoxyNixie
Copy link
Owner

Interesting. This may actually be a bug in Factorio it self and something I might not be able to fix in the mod. I'll have a look at this when I get back from vacation.

@NoxyNixie NoxyNixie changed the title [0.0.3] Back engines stopping on curve get disconnected Back engines stopping on curve get disconnected Mar 30, 2018
@ChuckSavage
Copy link
Contributor Author

ChuckSavage commented Mar 30, 2018

So, I created a demo map for this. Set the train to run to 2n, and when it comes to a stop at that station, the back engine will disconnect as it spins around. The first half of the train is left on manual and the 2nd single engine will be on automatic, but "no path"ing.

In my game where I noticed this behavior, sometimes the first (bigger part of the) train will keep going. It isn't guaranteed to stop there, but the flipped (dropped off) engine so far as I've noticed always remains where it was dropped.

Attached files: save game and mods
traindisconnects2.zip
mods.zip

edit: I'm using the latest factorio alpha 16.36

@NoxyNixie
Copy link
Owner

Yeah my guess is that it fails to reconnect the locomotive to the rest of the train even though it just disconnected from it so in theory it should still be in range to reconnect but somehow the curve messes with this.

Before I went on vacation I was investigating a different way to do the rotations which could fix all the bugs that are open right now. I'm hoping to be able to make it more reliable and smoother but as mentioned I'll have a look at it when I get back from vacation.

@ChuckSavage
Copy link
Contributor Author

You know the expression, "I can't wait..." Well, I do hope your solution works.

In the game, I can use G to connect manually from the locomotive that is disconnected, so you'd think it would work in code. Though, since I don't really "know" that what I'm seeing is what is translated to in game, I thought I'd try in the rotate to connect both ways, but it doesn't work as I tried. So I commented it out. By someone (you) that knows what they're doing, it might make sense, or your solution when you get it working.

	if front then 
		loco.connect_rolling_stock(defines.rail_direction.back) 
		--defines.rail_direction.back.connect_rolling_stock(loco)
	end
        if back then 
		loco.connect_rolling_stock(defines.rail_direction.front) 
		--defines.rail_direction.front.connect_rolling_stock(loco)
	end

@ChuckSavage
Copy link
Contributor Author

When you started this mod, did you "suggest a new feature" for the API on factorio forums for allowing rotating an engine even while connected? If not, it might be worth doing so. I'll give it a +1.

@NoxyNixie
Copy link
Owner

I may be a step beyond requesting API features since I can implement them myself in Factorio in the form of a pull request directly. I just haven't had the time these past weeks.

@ChuckSavage
Copy link
Contributor Author

ChuckSavage commented Apr 6, 2018

Any word on this? I love the mod, but I'm going to disable it. My train network keeps breaking because of this bug, as trains get stuck. I've 180ish trains, and it gets messy.

@NoxyNixie
Copy link
Owner

The word is that so far just rotating rolling stock in factorio's source code is ... complex and I've yet to get something working correctly without crashing 😛

If I can't get something working there soonish I'll probably look at seeing if I can reproduce your specific issue and try to find a work-around there.

@NoxyNixie
Copy link
Owner

NoxyNixie commented Apr 6, 2018

Could you test this in version 0.0.5 and reopen if it still is not working correctly?

@ChuckSavage
Copy link
Contributor Author

I'll give this a go right away.

Tested on the test map I'd made, and it worked.
Loading it back into my big game. We'll see how it goes.

@ChuckSavage
Copy link
Contributor Author

ChuckSavage commented Apr 7, 2018

Sorry to say, not all is well. Within minutes, my personal maintenance train lost its caboose (its a 2 locomotive train) when it came to a stop.

See the Screenshot, there's no connecting green line.

Another screenshot, in map mode you can see the end engines have become disconnected.

It won't let me re-open this issue.

@NoxyNixie
Copy link
Owner

Can you manually reconnect those without moving the locomotives from the moment they disconnected?

@NoxyNixie NoxyNixie reopened this Apr 7, 2018
@ChuckSavage
Copy link
Contributor Author

ChuckSavage commented Apr 7, 2018

I could with my 2 locomotives.

Working my way towards that accident, and saw another train disconnected. From the locomotives, I couldn't, but from the train wagon I could, and they were fairly far apart. screenshot

Same with that train. Mouse over locomotives, "No rolling stock found." Mouse over cargo wagon, "Rolling stock connected."

If you can get/keep the handle to the vehicle(s) the locomotive is connected to before disconnecting it for rotation, that might help. It's in that array you're looping over isn't it? Nevermind, that's train.locomotives, ...

edit: Okay found LuaTrain. It appears the array of all vehicles in the train is train.carriages.

If you can differentiate between a cargo/fluid wagon and a locomotive, you could call an unrotate method. Assuming loco is carriages[i], then call unrotate(carriages[i-1],loco,carriages[i+1]) How sensitive is lua to index being out of array boundary?

@NoxyNixie
Copy link
Owner

Hm if you can't reconnect them manually then that is the issue. I'll think about if and how to do it from the connected rolling stock and if that would even be a good idea to do.

I'm curious if you are able to make a reproducible world where this happens reliably (since I can't seem to make that specific thing happen on my worlds).

@ChuckSavage
Copy link
Contributor Author

ChuckSavage commented Apr 7, 2018

Okay, managed to create a demo map that loses the end locomotive reliably. It's the bottom right L shaped track. Every time the train goes from 1 > 2, it loses the engine as it accelerates away from 2.
1_test loosing caboose.zip.

Just so you're not confused about which train track it is, it's this one.

PS, this isn't the exact same issue I had in last comment, as the front train was left in manual_mode and the lost locomotives were in automatic, such that the front train didn't race off without its engines. In this demo, it does. But, I've had this behavior before in 0.0.3, so it's not new.

@NoxyNixie
Copy link
Owner

Hm. Looks like pretty much all cases that I've seen with separating trains is when they are accelerating and being rotated while on an intersection.

I've not fixed the actual bug but I did add settings so you can increase how often the mod checks trains. By default I set it to 8 which means it now checks every 8th tick which is faster than what it was before (15). With this adjusted speed it "fixes" the map you made but I'm sure it does not fix all situations.

What you could try is see if faster rates fix your big maps. The lower the number the faster the updates are but it'll cost a little extra on performance (not sure how much since I don't really have a large map with loads of trains to test on yet).

This is released now in 0.0.6.

@ChuckSavage
Copy link
Contributor Author

Okay, I'll give it a shot. I've also been playing around with this, and have succeed as well. Before the call to disconnect, I copy train.carriages to a global variable, then when try reconnecting I iterate over the carriages and attempt to connect in each direction.

loco.connect_rolling_stock(defines.rail_direction.back) 
loco.connect_rolling_stock(defines.rail_direction.front) 

for _,car in pairs(global.carriages) do
	if car.unit_number ~= loco.unit_number then -- if we're not the locomotive we're connecting
		car.connect_rolling_stock(defines.rail_direction.back)
		--if loco.train.id == car.train.id then return end -- we're connected
		car.connect_rolling_stock(defines.rail_direction.front)
		--if loco.train.id == car.train.id then return end -- we're connected
	end
end

Add in the if (ids match) returns and it no longer works, which doesn't make sense to me.

@ChuckSavage
Copy link
Contributor Author

You're welcome to load my game. The files for the mods I use and map are located on this factorio forums bug post

@ChuckSavage
Copy link
Contributor Author

Okay, trains still become disconnected at 8, so I've changed it to 2. This is without my change, just the 0.0.6 version. Even at 2, the mod is only consuming 0.4 game cycles, so it isn't horrible.

Before I changed the setting, here is the current map with the disconnected train at the "_W1 1 W" train stop intersection. That's straight west from where you spawn in. You can use the train parked at Dune2 to get there. Before you go, there is an armory of equipment at the ARMOR location pinned to the map if you want equipment. This map was originally a multiplayer game I'd hosted.

@NoxyNixie
Copy link
Owner

Train ids change completely each time you connect or disconnect a rolling stock. This is why your train ID's are increasing over time with my mod enabled. The reference to car and its id are likely still the old references before the reconnecting.

I also wanted to avoid doing something like you are doing since it adds a lot of extra references and additional fuss around something that I think is either a factorio bug or something else which I'd rather pin down correctly before creating all kinds of work arounds.

I'd like to know if your big map with lots of trains works properly if you increase (and to what value) how often the mod checks trains.

I have a suspicion that at some value no issues will occur at all. I can't test this myself as I don't have a train network like yours with as many trains (My trains will never stop on junctions for instance).

@NoxyNixie
Copy link
Owner

Is 2 the highest value you can use to run your train network reliably or can you go higher?

I'll look at your saves tomorrow perhaps and see if I can find some way to improve things.

@ChuckSavage
Copy link
Contributor Author

ChuckSavage commented Apr 8, 2018

Which is better a lower number or higher? I was thinking lower is better. I'm about to switch to 1 from 2, the minimum it can be, since I think I'm still getting disconnects with 2.

PS I'm with you on a better method than this. No work around is better than an actual fix.

@NoxyNixie
Copy link
Owner

Well the term "better" is subjective here. The higher the number is the less UPS the script will eat but if it can't work properly at all without being 1 then the UPS hit is still "better" than it failing. I'm just curious if setting it to 1 actually fixes it or if it still can bug out at 1.

If it still can bug out at 1 than the current path of "fixing" is just a failure and I should be looking at a different method.

@ChuckSavage
Copy link
Contributor Author

ChuckSavage commented Apr 8, 2018

I was waiting to reply until I heard if 1 was better. No it didn't fix it and I disabled the mod with the new setting. Thanks for putting that in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants