Patch: Improved acceleration for road vehicles [In trunk]

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

Post Reply
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Patch: Improved acceleration for road vehicles [In trunk]

Post by Terkhen »

My goal with this patch is to make road vehicles more diverse in their features, as right now different road vehicle models behave too similarly: all road vehicles perform equally when crossing rough terrain (besides differences caused by speed).


Present features:
  • Show weight and power in the engine preview window (only if the setting is active).
  • Show weight, weight including cargo, power and tractive effort in the build vehicle window (only if the setting is active).
  • Allow to sort road vehicles by power in the build vehicle window (it is not disabled when settings change, though).
  • Standard vehicles have air drag values set correctly.
  • Show weight, power and tractive effort in the vehicle details window (only if the setting is active).
  • Force a lower limit of 1 km/h in vehicle's speed.
  • Allow to select the steepness of slopes for road vehicles.
  • Acceleration working and changed correctly for road vehicles.
  • Standard trains work with the air drag value defined at the documentation (based on their speed) instead of a hardcoded one.

NewGRF features:

Unless otherwise noted, all implemented features follow the New Graphics specifications.

Road vehicles:
  • Property 0x13 (Power): Power is in units of 10 hp. Only the power of the first part is taken into account for articulated road vehicles.
  • Property 0x14 (Weight): Weight is in units of 1/4 tonnes. Only the weight of the first part is taken into account for articulated road vehicles.
  • Property 0x18 (Tractive effort): For a value of 0xFF, the tractive effort is equal to the vehicle weight, for 0x80, it is half, and so on. Since only the first part of an articulated road vehicle can have power and tractive effort, it is only useful at the first part. When a NewGRF vehicle has no tractive effort or it is set to zero, it uses the standard value instead (0x4C = 76).
  • Property 0x19 (Air drag): Air drag in arbitrary units. 0x01 means no air drag. 0xFF means full air drag and 0x00 means standard air drag (calculated with the vehicle's max speed looking on this table). Only the air drag from the first part of a vehicle is used.
  • Callback 36 support for power (Action 0 property 0x13) and air drag (Action 0 property 0x19). These callbacks are checked whenever the vehicle is bought, serviced, visits a station or after loading a savegame (UNTESTED).
  • Callback 36 support for weight (Action 0 property 0x14) and tractive effort (Action 0 property 0x18). In addition to the above conditions, these callbacks are also checked when the cargo changes (UNTESTED).
Trains:
  • Property 0x1F (Tractive effort): When a NewGRF vehicle has no tractive effort or it is set to zero, it uses the standard value instead (0x4C = 76) (missing in trunk).
  • Property 0x20 (Air drag): Air drag in arbitrary units. 0x01 means no air drag. 0xFF means full air drag and 0x00 means standard air drag (calculated with the vehicle's max speed looking on this table). Only the air drag from the first part of a vehicle is used. (UNTESTED)

List of things to do: (Comments needed!)
  • Possible crash caused by NewGRF cargos.
  • The game asserts if there's a NewGRF road vehicle with a weight of zero.
  • Remove "Sort by engine" for road vehicles when improved acceleration is off.
  • Missing a check for reversing in slopes. It seems as it is not needed, though.
  • Right now, road vehicles don't use the freight multiplier.
  • Should trains use "Improved" instead of Realistic?.
  • Implement IsMaglev function for road vehicles.

Notes about the code:
  • The unified acceleration code needs an in-depth review.
  • Vehicle flags related to acceleration (_GOINGUP, _GOINGUP, etcetera) are not unified.

Since the Improved acceleration for road vehicles is just a patch, there is currently not much GRF sets that have ALL of their road vehicles working correctly. I know that some articulated vehicles in HEQS have this problem when loaded in slopes, and in eGRTVS there is also some vehicles that will not move at all. To my knowledge only standard vehicles and the Hover Bus are fully supported.
Attachments
version_history_rv_acceleration.txt
(5.5 KiB) Downloaded 109 times
improved_acceleration_rv_v16-r18778.diff
(93.66 KiB) Downloaded 128 times
Last edited by Terkhen on 06 Mar 2010 13:10, edited 53 times in total.
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: Patch: Realistic acceleration for road vehicles [v1-r17152]

Post by Hirundo »

Yet Another Great Patch By Terkhen? It sure looks nice and I hope it could be included in trunk at some point. It's very nice to see patches like this that add a new dimension to the game, in this case to road vehicles. Some months and hundreds of trunk revisions ago, I have been working on a patch like this. (See below) It was never finished though, mainly due to lack of time and motivation on my part.

Regarding your "missing features", I have the following comments:

I'd leave the freight multiplier out for now. It seems to be intended to simulate long freight trains, but this doesn't really apply to road vehicles. A separate setting could do, but I that could always be done later with little effort. For now I'd keep things small and simple for easier reviewing.

In my personal opinion, using magic numbers is fine in this case as long as you document them properly. Trying to use real world values only complicates matters and would probably not give a desirable result.

In curves, TTDPatch limits the speed to 75% of the maximum. This is quite easy to do using v->direction and I think it works quite well.

I'd recommend testing your patch with various newgrfs and also with the default vehicles, and don't forget to test with fully loaded (=very heavy!) vehicles.

Warning: the following patch contains bugs and is not finished.

I have attached the old unfinished patch I wrote. Perhaps it can be of some use to you. Feel free to use it for any purpose, it's GPL for a reason. Be warned, though, that it is neither bug-free nor finished.
Attachments
rvphysics.diff
(33.26 KiB) Downloaded 144 times
Create your own NewGRF? Check out this tutorial!
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Realistic acceleration for road vehicles [v1-r17152]

Post by Terkhen »

Wow, thanks!. I gave a quick look to your patch. For starters I discovered that I am calculating weights wrong (right shift instead of left shift among other mistakes... :oops:). I knew I had a calculation error somewhere, but not that it was so big. There's also some features that I haven't implemented (like sorting road vehicles by power) that will be included in v2.

I agree about leaving the freight multiplier out: it is simple enough to add if it is needed. I like that solution for curves: it is a big penalty but not a complete stop as it is right now. After polishing the patch I will need to do tests of all normal and extreme cases to make sure that everything is okay.

I will check your patch more exhaustively soon, but first I'll fix the huge mess with weights. Expect v2 really soon!
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Patch: Realistic acceleration for road vehicles [v1-r17152]

Post by andythenorth »

Hi Terkhen,

Really nice to see a patch for this.

1. If you need testing, I'd like to help. I've never compiled with a patch, but I think I can find the instructions for compiling on Mac and figure it out. Maybe not tonight, but I'll try and get to it...

2. A few HEQS vehicles have power / weight set, not all. I set a couple of those for Hirundo when he was writing a patch. I can do more and release a new version.

3. Hertojgan was working on vehicle physics patches a year or more ago. He just pm'ed me this weekend to say he might be interested in helping anyone who worked on a new patch. I'll forward you the PM.

cheers,

Andy
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by Terkhen »

New version released. Finally it seems that I had no serious errors while determining weight. The new version consists mostly of features from Hirundo's patch that mine was missing.

v2-r17157: Road vehicles don't use the freight multiplier anymore. Updating road vehicle weight when transfering cargo while autoreplacing articulated vehicles was missing (Hirundo). Allow to sort road vehicles by power in the build vehicle window (Hirundo). Show weight including cargo, as OpenTTD does with wagons (Hirundo). Road vehicle speed is limited to 75% when changing direction and to 50% when reversing (Hirundo).

andythenorth: I will be glad to have your help for testing. Unfortunately I have no way of compiling binaries for mac, but compiling a binary with a single patch is not very complicated in linux so I hope that you don't have serious problems. I am not 100% sure I implemented the articulated vehicle part of the patch correctly, so testing if there's some strange behaviour with them would be really helpful.

I have used only a few HEQS vehicles while testing (mostly the Kilimanjaro Unitised Mining Truck). There's some vehicles that have a weight of 6t and power of 200 HP that seem to be the not set ones. Here's a screenshot that shows how the build vehicle window for HEQS vehicles looks with the patch:
Kilimanjaro.png
Kilimanjaro.png (27.89 KiB) Viewed 7620 times
I knew about Hertojgan's patch, and I was planning to review it once I had basic functionality working and tested. Having the advice and reviews of someone that already worked on a similar patch would be really valuable for this patch's development.

Edit: Minor update to correct a bug when showing weight with cargo for articulated vehicles.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by andythenorth »

Terkhen wrote:andythenorth: I will be glad to have your help for testing. Unfortunately I have no way of compiling binaries for mac, but compiling a binary with a single patch is not very complicated in linux so I hope that you don't have serious problems.
I am learning how to patch and compile. I did get a successful compile run but it didn't seem to introduce realistic acceleration...

EDIT: found the road vehicle acceleration switch in Advanced Settings. Testing now...
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by andythenorth »

Hi Terkhen,

I've done some testing. I think there may be a problem with articulated vehicles. However there is definitely a problem with the vehicle weights I have set (or not set) in HEQS. So I'm going to update those and report back....

Code: Select all

Veh 1:  400hp   50t (100t)  148kn
Veh 2:  400hp   90t (50t)    148kn  (articulated)
Veh 3:  650hp   43t (103t)  127kn
Veh 4:  650hp   31t (31t)    92kn    (articulated)
 
Interesting. 
A: there is a problem with the unladen weights I have set for some vehicles
B: This patch might be dealing with articulated RVs incorrectly?  (As mentioned in a post above)
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by Terkhen »

Mmm... the weight including cargo (between parentheses) should be correct with the mini update I did a few hours ago. The bug was that cargo weight was zero for articulated vehicles and as a result they would appear as what you posted for vehicle 4: 31t (31t). That bug is corrected now. What I don't understand is the values shown for vehicle 2. The patched version displays less weight including cargo than without?. Anyways I checked HEQS vehicles for year 2000 with the corrected version and I did not found any "weight including cargo" value that was smaller than the weight value.

Edit: I am currently reworking the acceleration function, to be both faster and more understandable. It will probably change vehicle behaviour.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by andythenorth »

Hi Terkhen,

Is RV prop 18 supported (coefficient of tractive effort)?

I am trying varying values of it and get the same TE displayed in the vehicle purchase window.

EDIT: my mistake. Making changes to the wrong vehicle :oops:

cheers,

Andy
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by Terkhen »

Yes, it is supported. Check the attached example GRF for an example (it is included with the windows binary too). The only difference between the "Standard" and the "TE+" buses is that the Standard has a tractive effort of 0x4C and the TE+ has a tractive effort of 0x98. It is entirely possible that the patch does not reload these values correctly after the GRF has been altered in the same game.

Edit: Okay ;)
Attachments
RARV_Test.grf
(446 Bytes) Downloaded 127 times
RARV_Test.nfo
(1.56 KiB) Downloaded 124 times
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by andythenorth »

Hi Terkhen,

I've done some more testing, and I've been refining prop 13 / 14 / 18 values for HEQS dump trucks / mining trucks.

New HEQS is attached here.
heqs.grf
(484.71 KiB) Downloaded 131 times
It's interesting how this performs. Over a grade of approx 7 tiles:
The Camelback Mountain truck has 930hp and capacity of 240t. TE coefficient is 0.125. Speed flaps betwen 10-13mph. Max TE is reported as 355KN.
The Rockchuck Peak truck has 930hp and capacity of 95t. TE coefficient is default (0.3?). Speed flaps between 13-18mph. Max TE is reported as 454KN.
This seems counter-intuitive, the larger truck ought to go quite a bit more slowly than the smaller truck all things considered?

The Camelback truck is also misreporting weight. Unladen weight should be 44t + 33t +33t (two trailers). Gross laden weight should be 350t. It reports 44t unladen, 284t laden. I guess these issues may be connected.

Nice to see this working though :)

cheers,

Andy
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by Roujin »

First of all, nice to see you working on this :) I'm looking forward to seeing some fast RVs not slowing to a crawl on each curve/hill ;)
Terkhen wrote:[...] or the Hover Bus (it can't reach its top speed with the current constants, though).
Hmm, what do you mean with "constants" here? Some constants in your code, or the values (TE, air drag) defined by the grf? Obviously I set those to nonsense values when I created the grf, because they didn't matter in OpenTTD (I didn't exactly bother to install TTDPatch and check there).
I'll be gladly accepting any proposals what to set those values to and upload a new version of the hover bus.


edit: looking at my nfo, I only set power and weight (to nonsense values):

Code: Select all

// Power in 10hp: nonsense value
      13 FF
// Weight in 1/4 tons: nonsense value
      14 50
... and left tractive effort and air drag to whatever is there by default.
edit2: according to the specs, defaults for those two are "0.30 times weight" for TE, and I think 8 for air drag.

Also it says there that if a vehicle doesn't reach its intended max speed air drag should be set to one or two higher than the default... hmm.

Anyway, I think I'll wait until you've tweaked your constants to something you're happy with, before tweaking the grf.
Last edited by Roujin on 12 Aug 2009 16:38, edited 3 times in total.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by Terkhen »

andythenorth: Then I am probably calculating weights for articulated vehicles wrong in some parts of the code. Once I manage to get the function that calculates acceleration working well, I'll correct that bug.

Roujin: I meant the constants of my code for things like rolling friction and air drag, that limit the maximum speed for vehicles (I know something similar happens with trains, but the limit is higher). In v2 the hover bus had a speed limit of 342 km/h. Right now I am reworking the function that contains all of these constants to get more logical results, and I expect it to reach even higher speeds once I get all formulas reworked. Anyways it will be still far from its limit. I am thinking about giving support to the NewGRF air drag property to allow reducing these limits on a per vehicle basis, but what the hover bus would really need to perform as intended is some way of setting the rolling friction to zero, as maglev trains do in trunk. Maximum acceleration depends on power, but it is limited by the vehicle's tractive effort and weight. Increasing tractive effort and weight (not much weight as it also determines rolling friction) would allow it to reach higher speeds, no matter how I end implementing the GetRoadVehAcceleration function.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by andythenorth »

Terkhen wrote:andythenorth: Then I am probably calculating weights for articulated vehicles wrong in some parts of the code. Once I manage to get the function that calculates acceleration working well, I'll correct that bug.
Well it looks pretty good already. It doesn't need to be ultra-realistic, just good for gameplay. Or so I think anyway :)

I am not sure how to best make use of TE. An articulated vehicle with several trailers may have a large overall consist weight, but most of that weight will be dead trailing weight, not useful weight on the drive wheel(s). Some HEQS vehicles now have unfeasibly high TE when loaded :shock:

On the other hand, for an articulated vehicle, the weight of the first trailer should increase TE as part of that weight would be applied to the drive wheel(s) (on a typical truck or tractor). I thought I could use TE co-efficient to fake these effects, but I'm not sure so far.

Looking forward to more on this. :)
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by SirkoZ »

I have tested v1 yesterday with build r17156 and no new .grf and it made vehicles really struggle with gaining speed and inclines, even unloaded, then I saw that horsepower is really low, only 120 hp for second gen. bus (Leyland) and 220 hp for second gen. lorry (88km/h). I suggest you look at TTDPatch and their default values for hp/other new properties as it's had realistic road acceleration for ages now. Other than that - I like the patch.
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by Terkhen »

andythenorth: I share that opinion. Actually, I checked that thread while documenting myself before starting this patch and it encouraged me to actually start coding. But since I am also trying to make it as similar as possible as train realistic acceleration (probably the code of both accelerations should be unified at some points), I am following existing documentation. I am still making it more simpler than the current implementation of realistic acceleration for trains, though.

Checking the problem you mention I discovered that I am not calculating tractive effort for articulated vehicles correctly... I was considering the weight of all parts of the vehicle when calculating tractive effort, when only the weight of powered parts of the vehicle should be taken into account. I will correct it for the next release. The values actually shown by the GUI seem to work as intended, but I will check that part of the code too.

SirkoZ: I checked TTDPatch's road vehicle power code before starting this project. I suck badly with assembler code but I was able to check that OpenTTD trunk already has the same default values for these new properties set at the engine table code (even if they are not used). My acceleration code is to blame for that strange behaviour, not the standard values. I hope everything will run more smoothly with v3.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by andythenorth »

I may be mistaken, but I'm not sure that the patch calculates power for articulated vehicles correctly. It seems to only use the hp of the lead vehicle - at least for display in the purchase window.

I had an example earlier (articulated tractor) where the hp was split between front / rear. I recoded it to put the hp on the front vehicle to get correct display, however I'll change that later and post a grf. I'm cooking dinner right now though :)
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by Terkhen »

The patch has a lot of holes at articulated vehicles :D

Checking only the first vehicle for power was a wrong assumption on my part. It will be corrected for v3 too.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by andythenorth »

Terkhen wrote:Checking only the first vehicle for power was a wrong assumption on my part. It will be corrected for v3 too.
Attached HEQS grf...the Red Peak articulated crawler has the hp / weight split between each part.
Front: 230 hp, 13t
Rear: 220 hp, 13t
Co-efficient of traction is 9A (0.6) on those btw.
heqs.grf
(484.74 KiB) Downloaded 130 times
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: Patch: Realistic acceleration for road vehicles [v2-r17157]

Post by SirkoZ »

Terkhen wrote:SirkoZ: I checked TTDPatch's road vehicle power code before starting this project. I suck badly with assembler code but I was able to check that OpenTTD trunk already has the same default values for these new properties set at the engine table code (even if they are not used). My acceleration code is to blame for that strange behaviour, not the standard values. I hope everything will run more smoothly with v3.
I see - well you could just load up TTDPatch and skipped to year 2050 with "enginespersist = 1" to check those properties quickly. :)
Thanks for the update, I'm looking forward to v3.
thumbsup.gif
thumbsup.gif (226 Bytes) Viewed 7046 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 51 guests