Patch: Multiengine Normalization

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Patch: Multiengine Normalization

Post by kaan »

This patch makes locomotives on trains with more than one locomotive act like any locomotive would when it comes to ageing, servicing and breakdowns.
The effect of a breakdown has been altered however.
When the first engine of a train breaks down everything stops like it has been all along. When an engine that isn't the first on a train breaks down it will subtract its horsepower from the front engine for the duration of the breakdown.
This means that a train with multiple engines where one (or more) of the secondary engines is broken down - is carrying a lot of dead weight, but not stopping.
As a nice little bonus: Any engine that need to go to depot for servicing will cause the entire train to go to depot.

The train cargo panel has been modified to show details about each engine.
Screenshot
Screenshot
details.png (13.87 KiB) Viewed 11317 times
Version 5 is attached. The only change is a bugfix.
Attachments
MultiengineNormalization_V5_SVN13130.diff
(8.54 KiB) Downloaded 267 times
Last edited by kaan on 17 May 2008 00:01, edited 4 times in total.

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
User avatar
Maedhros
OpenTTD Developer
OpenTTD Developer
Posts: 603
Joined: 30 Mar 2006 18:24
Location: Durham, UK

Post by Maedhros »

Ooh, pretty nice. One thing you have to watch out for though is that if one of the secondary engines get old, you'll start getting news messages about "Train 0", which isn't desperately helpful. Another point is that checking for IsTrainEngine(v) || IsFrontEngine(v) is redundant since the front engine is also a train engine. :)
No-one's more important than the earthworm.
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

Maedhros wrote:Ooh, pretty nice. One thing you have to watch out for though is that if one of the secondary engines get old, you'll start getting news messages about "Train 0", which isn't desperately helpful. Another point is that checking for IsTrainEngine(v) || IsFrontEngine(v) is redundant since the front engine is also a train engine. :)
Good point :)
Any directions of where to look for the "getting old" code?
The second bit ... erhm ... thats just me not cleaning the code properly :oops:

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

Ok, here is version 2 with handling of old engines and new strings :)
Last edited by kaan on 16 May 2008 23:43, edited 1 time in total.

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
User avatar
Zojj
Engineer
Engineer
Posts: 97
Joined: 27 Apr 2007 17:58
Location: Vegas baby
Contact:

Post by Zojj »

This is a cool patch. I think a few of people were asking for it.

Some other ideas
Make broken engines spew out smoke so you can see if they are not operational.
Make the broken down engines stay broken down until the whole train completely breaks down or enters a depot.
Only stop the train if ALL the engines are broken down. It would be fun to see a 4 engine train with 3 broken engines. =)
Fix this mess:

Code: Select all

	r = Random();

	/* increase chance of failure */
	chance = v->breakdown_chance + 1;
	if (CHANCE16I(1,25,r)) chance += 25;
	v->breakdown_chance = min(255, chance);

	/* calculate reliability value to use in comparison */
	rel = v->reliability;
	if (v->type == VEH_SHIP) rel += 0x6666;

	/* disabled breakdowns? */
	if (_opt.diff.vehicle_breakdowns < 1) return;

	/* reduced breakdowns? */
	if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666;

	/* check if to break down */
	if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) {
		v->breakdown_ctr    = GB(r, 16, 6) + 0x3F;
		v->breakdown_delay  = GB(r, 24, 7) + 0x80;
		v->breakdown_chance = 0;
	}
Replace it with cleaner code, maybe the breakdown chance can increase based on how much effort the trains are using. An engine pulling 2 cars would break down less than an engine pulling 10 cars.

Those are just ideas; it is your patch. =)
I'm on the Zoloft to keep me from killing yall

My patches: Better graphs - Train acceleration - Crash rates
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

interesting patch... I see that somebody beat me to writing it (not the worst problem you can have).

You could clean up the getting old string by making a static const string array. This can save you from making dublicated code.

I wonder about how to handle breakdowns though. Should the front always stpo the train and never any of the rear ones? If anything, I would say that there should be a risk that any broken engine will stop the train. One could also argue that the train can continue with the front engine broken. The front should have a greater risk of having to stop the train because it contains more complex stuff that's needed to control the other engines.
Also engines should not be able to magically fix themselves. They would need to stop in order to be fixed, but this can save you from stopping in junctions and then stop at stations where they can be overtaken if needed. The counter for the breakdown should then count while the train loads and unloads.

Also how should the load affect the risk of breakdown? There is a certain risk when the front engine pulls a lot (it's overloaded), but shouldn't it be divided with the number of engines to even out the load? and what if the engines aren't equally strong?

And what about the display of the breakdown counter?
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

Zojj wrote:This is a cool patch. I think a few of people were asking for it.
I'm glad you like it :)
Zojj wrote:Some other ideas
Make broken engines spew out smoke so you can see if they are not operational.
Well, the problem is that when you activate the black smoke it just stay where the engine broke instead of following the train. Looks kind of strange with the tracks smoking like that :P
Zojj wrote:Make the broken down engines stay broken down until the whole train completely breaks down or enters a depot.
That is one way to do it, but as it is now then trains get repaired on track all the time and changing that would be adding micromanagement.
Zojj wrote:Only stop the train if ALL the engines are broken down. It would be fun to see a 4 engine train with 3 broken engines. =)
This is the next thing I am looking into but don't expect too much. As of now secondary engines don't have a speed or is even started when the train starts. Lots of things might go wrong when I activate that ;)
Zojj wrote:Fix this mess:
[snip]
Replace it with cleaner code, maybe the breakdown chance can increase based on how much effort the trains are using. An engine pulling 2 cars would break down less than an engine pulling 10 cars.
I would love to, but this is my first patch so I think I'm just going to take it easy :D
Zojj wrote:Those are just ideas; it is your patch. =)
I welcome your feedback :)

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
knedle
Traffic Manager
Traffic Manager
Posts: 158
Joined: 13 Apr 2007 17:07

Post by knedle »

You could turn on and off smoke every second this way smoke would follow broken engine. ;)
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

Bjarni wrote:interesting patch... I see that somebody beat me to writing it (not the worst problem you can have).
I'm glad you are now free to do something else with your time :)
Bjarni wrote:You could clean up the getting old string by making a static const string array. This can save you from making dublicated code.
Please give an example as how to do this. I really can't imagine what you mean.
Bjarni wrote:I wonder about how to handle breakdowns though. Should the front always stpo the train and never any of the rear ones? If anything, I would say that there should be a risk that any broken engine will stop the train. One could also argue that the train can continue with the front engine broken. The front should have a greater risk of having to stop the train because it contains more complex stuff that's needed to control the other engines.
Also engines should not be able to magically fix themselves. They would need to stop in order to be fixed, but this can save you from stopping in junctions and then stop at stations where they can be overtaken if needed. The counter for the breakdown should then count while the train loads and unloads.
These are all good ideas.
On the other hand you could argue that the current system is close enough to the real thing. As it is then about 1/n of the breakdowns stops the train (where n is the number of engines and assuming the engines are of the same type). For gameplay purposes this would mean that on a 3 engine train most breakdown would not stop the train, but many would. How does that sound for realism? :P
For most players that don't know the underlying mechanics, this would be enough to make it "realistic" and fun. On the other hand the players that knows more wouldn't be tempted to make every train a 4 engine monster to keep it from ever stopping. This might be the best way to keep "realism" in there somewhere because you would mostly use multi engine trains on routes with many wagons and/or hills and mountains.
Bjarni wrote:Also how should the load affect the risk of breakdown? There is a certain risk when the front engine pulls a lot (it's overloaded), but shouldn't it be divided with the number of engines to even out the load? and what if the engines aren't equally strong?
I really like that idea, you should rewrite the breakdown code ;)
Bjarni wrote:And what about the display of the breakdown counter?
As it is now the breakdowns are counted for each engine and i think it should remain so. It would be a good idea to show this on the detailed info on the train (you know the place where you can see all the wagons too).

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

knedle wrote:You could turn on and off smoke every second this way smoke would follow broken engine. ;)
that would be really ugly code. It would be better to make the smoke follow the engine. Also it's an open question which of those two solutions that would be easiest to code.
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

Bjarni wrote:
knedle wrote:You could turn on and off smoke every second this way smoke would follow broken engine. ;)
that would be really ugly code. It would be better to make the smoke follow the engine. Also it's an open question which of those two solutions that would be easiest to code.
I really don't think its necessary with black smoke on secondary engines, not every fault is a fire :P

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

kaan wrote:I really don't think its necessary with black smoke on secondary engines, not every fault is a fire :P
Actually black smoke mean "this can't be fixed right away and can't be fixed at location". It's a clear sign of a breakdown though, but if anybody has a better idea, we will listen :wink:
User avatar
Zojj
Engineer
Engineer
Posts: 97
Joined: 27 Apr 2007 17:58
Location: Vegas baby
Contact:

Post by Zojj »

kaan wrote:
Zojj wrote: Make the broken down engines stay broken down until the whole train completely breaks down or enters a depot.
That is one way to do it, but as it is now then trains get repaired on track all the time and changing that would be adding micromanagement.
I didn't state that very well. Right now you have it so the broken engine repairs itself while the train is still moving.

A broken-down engine shouldn't be able to be fixed until the train comes to a stop. When the 2nd or 3rd engine is "broken down", it can still be pulled by the 1st engine. There would be no extra management involved, just a little more smoke. =)
I'm on the Zoloft to keep me from killing yall

My patches: Better graphs - Train acceleration - Crash rates
User avatar
WWTBAM
Moderator
Moderator
Posts: 3689
Joined: 02 Apr 2005 07:01
Location: Sydney NSW Antipodea
Contact:

Post by WWTBAM »

Zojj wrote:
kaan wrote:
Zojj wrote: Make the broken down engines stay broken down until the whole train completely breaks down or enters a depot.
That is one way to do it, but as it is now then trains get repaired on track all the time and changing that would be adding micromanagement.
I didn't state that very well. Right now you have it so the broken engine repairs itself while the train is still moving.

A broken-down engine shouldn't be able to be fixed until the train comes to a stop. When the 2nd or 3rd engine is "broken down", it can still be pulled by the 1st engine. There would be no extra management involved, just a little more smoke. =)
I geese you could have a random chance that it could be fixed in motion or vice versa.
Formerly known as r0b0t_b0y2003, robotboy, roboboy and beclawat. The best place to get the most recent nightly builds of TTDPatch is: http://roboboy.users.tt-forums.net/TTDPatch/nightlies/
knedle
Traffic Manager
Traffic Manager
Posts: 158
Joined: 13 Apr 2007 17:07

Post by knedle »

Then make it possible to repair/service trains when they stop at station.
Minor repairs are always done like that.
User avatar
Villem
Tycoon
Tycoon
Posts: 3310
Joined: 28 Aug 2003 09:38

Post by Villem »

Why not also fix the counter wich induces breakdowns? I had many trains wich had just come out of depot, breakdown with 80% or more reliabilaty..(heck, once even 96% reliabilaty broke down after coming out of depot, then broke down again when it reached 92% at a station).
User avatar
Zojj
Engineer
Engineer
Posts: 97
Joined: 27 Apr 2007 17:58
Location: Vegas baby
Contact:

Post by Zojj »

the devs have a complete rewrite of breakdowns planned according to this post. See 9.2
I'm on the Zoloft to keep me from killing yall

My patches: Better graphs - Train acceleration - Crash rates
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

Zojj wrote:the devs have a complete rewrite of breakdowns planned according to this post. See 9.2
That's nice to know, thanks for the link :)

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
kul
Engineer
Engineer
Posts: 21
Joined: 30 Jun 2005 19:22

Post by kul »

kaan wrote:Well, the problem is that when you activate the black smoke it just stay where the engine broke instead of following the train. Looks kind of strange with the tracks smoking like that :P
Steam engines do "smoke", and move, maybe you could use that? or at least a small alternation of that?
User avatar
ostlandr
Chairman
Chairman
Posts: 882
Joined: 12 May 2007 01:09
Location: Northeastern USA

Post by ostlandr »

Bjarni wrote: (snip)

I wonder about how to handle breakdowns though. Should the front always stpo the train and never any of the rear ones? If anything, I would say that there should be a risk that any broken engine will stop the train. One could also argue that the train can continue with the front engine broken. The front should have a greater risk of having to stop the train because it contains more complex stuff that's needed to control the other engines.
Actually, with multiple units, the lead unit breaking down won't necessarily stop the whole consist. Of course, if it's a running gear issue. . .
Currently, when the train is at less than full load, some crews will shut down the prime mover in the lead unit, to give themselves a quieter ride.
Also how should the load affect the risk of breakdown? There is a certain risk when the front engine pulls a lot (it's overloaded), but shouldn't it be divided with the number of engines to even out the load? and what if the engines aren't equally strong?
That is something I would love to see. Lightly loaded trains operating at slow speeds almost never breaking down, and overloaded trains on steep grades or running at high speeds breaking down more often. Different horsepower (KW) engines together shouldn't affect the game, as each should be working at an equal share of it's maximum effort. US locomotives have eight "notches" or power settings. On a level track, the driver of the lead units might radio back to the driver of the helper units "put it in run 1 and relax for a while." As the grade increases, he will say "give me run 4" and his own locomotives are likewise in run 4. Soon it's "Give me run 6" as the train's speed drops. If you're a lucky spectator, the call will be "Give me all you've got" and all four locomotives on the head end and the pair of helpers will be screaming in notch eight, nearly twenty thousand turbocharged horsepower making the small pebbles dance on the ground at your feet. . .

<< stops, catches breath, has a cigarette :wink: >>
Who is John Galt?
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Semrush [Bot] and 22 guests