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

Feature: [NewGRF] Maximum curve speed modifier for rail vehicles #9346

wants to merge 2 commits into
base: master
Choose a base branch


Copy link

@vituscze vituscze commented Jun 9, 2021

Motivation / Problem

Prior to 0f91cb0, rail type's curve_speed essentially worked as a vehicle property. A rail vehicle could set its curve speed advantage to an arbitrary value by choosing the proper "home" rail type and the advantage would apply when traveling on compatible rail types.

Currently, the only way a rail vehicle can control its curve speed bonus is via the tilt property, which is a flat 20% bonus. There are no other ways in which the original behavior can be recovered. NUTS (and possibly other NewGRFs) relied on that behavior quite heavily.


This PR fixes the stated problem by introducing a new rail vehicle property: curve_speed_mod (0x2E). A 16 bit signed fixed-point binary number with 8 fractional bits, ranging from -128 to 127.996. 0 represents no bonus (default behavior), positive numbers increase maximum curve speed, negative numbers decrease. As an example, the value 1.0 (0x0100) would double the vehicle's speed in curves.

The way this property works is analogous to tilt. Each part of the consist has its own curve_speed_mod and the curve speed advantage of the entire consist is given by its weakest link.

Moreover, NewGRFs can also affect curve_speed_mod via callback 0x36. The resulting 15 bits represent values from -64 to 63.996. To support negative modifiers, GetEngineProperty and GetVehicleProperty now optionally allow negative numbers (existing uses are unaffected).

This change also expands the possible design space compared to the original behavior: NewGRFs can provide powerful trains that travel slowly in curves; wagons that, when refitted to fragile cargo, must travel slowly in curves; and so on.

NML support: OpenTTD/nml#222


No known limitations.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
Copy link
Contributor Author

@vituscze vituscze commented Jun 9, 2021

Together with @V453000, we've also prepared a modified version of NUTS and a savegame that showcases positive and negative curve speed modifiers as well as curve speed mod callbacks.


Copy link

@andythenorth andythenorth commented Jun 9, 2021

Copy link

@V453000 V453000 commented Jun 10, 2021

I went a bit further and replaced all TRAIN_FLAG_TILT with increased curve_speed_mod. This is so much cleaner and I can't wait when I get the courage to finetune the values further.

Not sure if it's helpful at all (probably not), but I'll provide it here too.



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

Successfully merging this pull request may close these issues.

None yet

3 participants