[NOT fixed]-Train not moving, savegame and possible solution

Got a problem with OpenTTD? Find some help here.

Moderator: OpenTTD Developers

Post Reply
tecxx
Engineer
Engineer
Posts: 106
Joined: 23 Jun 2003 19:31
Location: Tirol/Austria
Contact:

[NOT fixed]-Train not moving, savegame and possible solution

Post by tecxx »

hey there,

i once reported that with realistic train acceleration turned on, a train might get stuck at a 45 degree section. i have debugged the code while having such a train on my map and found a possible solution.

here is the savegame:
http://rrs.at/ottd/frozentrain.sav

it contains only ONE train and no other vehicles, this makes it very easy to debug the code. it's the yellow company, just open the train list to jump to the problem. a screenshot is attached. the train is stuck in front of the turn, because the signal was red, when it turned back to green it tries to acellerate, but the routine calculates wrong.

here is why:

in file "train_cmd.c", line 243,

Code: Select all

		return (force - resistance) / (mass * 4);
the acceleration can be calculated to a zero. to be more precise, in my savegame the variables are
force: 360
resistance: 36
mass: 238

putting these values into the formula, the result is 0,3403....

however the function calculating the acceleration returns an int, so the value is cutted to a zero. the train will never start to move!

my "workaround" solution was

Code: Select all

		return max((force - resistance) / (mass * 4), 10);
to have at least an acceleration value of 10.

however, the person who was coding the "realistic train acceleration" thing might look deeper into the problem and find a better solution than this workaround.

bye!
Attachments
train stuck.JPG
train stuck.JPG (124.85 KiB) Viewed 2933 times
Last edited by tecxx on 10 Apr 2005 12:35, edited 1 time in total.
to everyone who's coding on openttd: YOU ROCK !!!
Panther
Engineer
Engineer
Posts: 22
Joined: 25 Mar 2005 09:30
Location: Hungary

Post by Panther »

I have a very similar problem. I use nightly 2034 with PBS patch, and somehow my SH-40 (BR87) engine does not want to leave the station despite it is fully loaded. And if i build additional stations - anywhere -, trains also does not leave that sations, too.

My savegame's place:
http://cfhay.inf.elte.hu/~panther/opent ... tation.sav
It's a 8x11 map...
I use hacked engines.h file:
http://cfhay.inf.elte.hu/~panther/opent ... /engines.h

EDIT: i tried with 2053, too, but i had the same error.


The other one:
If i buy 4 sh-40 to make a multi-head train, sometimes it's speed is only 1KPH when it leaves the station (and than turns 90 degrees)
tecxx
Engineer
Engineer
Posts: 106
Joined: 23 Jun 2003 19:31
Location: Tirol/Austria
Contact:

Post by tecxx »

as a sidenote, i've just updated to revision 2075, and this problem still exists.

@ devs what about just adding my small fix? it ensures a minimal accel value, that should be sufficient.
to everyone who's coding on openttd: YOU ROCK !!!
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

I think this is already fixed, no? I loaded the savegame and the train just started to move. I even tried reversing it, blocking the way so it really has to stop and let it loose again. Realistic acc on/off, NPF on/off.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
tecxx
Engineer
Engineer
Posts: 106
Joined: 23 Jun 2003 19:31
Location: Tirol/Austria
Contact:

Post by tecxx »

sorry this is definitely not fixed.

- i deleted the entire openttd-source directory from my computer
- checked out the source from the svn server, rev 2174
- did not apply any patch or other modification
- compiled using visual studio and "release" setting
- copied exe and lang files to my game directory
- started the exe, loaded the savegame
- train 81 not moving. started/stopped it - not moving.
realistic train acceleration is ON.

- opened train_cmd.c in visual studio editor. function "GetTrainAcceleration", line 234:
"return (force - resistance) / (mass * 4);"
... still the same, no changes since i posted this bug here.

so...
- compiled in visual studio with "debug" setting.
- started debug session in visual studio
- opened savegame
- breakpoint at line 234 in train_cmd.c
- variable values: force=360, resistance=36, mass=238.
- calculator, entered values in formula, result = 0.340336....
return casts this value to an INT, value is truncated to zero, train not accelerating.

conclusion: no change in the situation. bug NOT fixed.
to everyone who's coding on openttd: YOU ROCK !!!
MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Post by MeusH »

How about

Code: Select all

acc=(force - resistance) / (mass * 4);
if (acc<2)
{
acc=2;
}
return acc;
tecxx
Engineer
Engineer
Posts: 106
Joined: 23 Jun 2003 19:31
Location: Tirol/Austria
Contact:

Post by tecxx »

Code: Select all

return max((force - resistance) / (mass * 4), 2);
to everyone who's coding on openttd: YOU ROCK !!!
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

Bizarr..I tested it and I swear the train was moving through that signal. Tested it again with clean config (that might've been it) and it is stuck there like a stuffed pig.

I'll forward this to the realistic acceleration person, whoever that is at the moment. If no proper fix is coming, we'll just prolly add max(x, 2); or something similar there for 0.4.0. Thanks tecxx.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
tecxx
Engineer
Engineer
Posts: 106
Joined: 23 Jun 2003 19:31
Location: Tirol/Austria
Contact:

Post by tecxx »

you're welcome.

you just gotta love step-by-step debugging, don't you? :o)
to everyone who's coding on openttd: YOU ROCK !!!
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

:) I am not sure of the max(x,2) solution since I've had a word with Tron. It might be that the 2 might allow any train to go up any slope of any size. If this is the case, then some other, more rigorous fix/workaround is needed.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Post Reply

Return to “OpenTTD Problems”

Who is online

Users browsing this forum: No registered users and 8 guests