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

Merged
merged 2 commits into from Aug 15, 2021

Conversation

vituscze
Copy link
Contributor

@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.

Description

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

Limitations

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')

@vituscze
Copy link
Contributor Author

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.

savegame: curve_test.zip
NewGRF: https://dev.openttdcoop.org/attachments/download/9875/nuts-curve_speed_mod.grf

@andythenorth
Copy link
Contributor

Curve speed -99% https://en.wikipedia.org/wiki/4-14-4

@V453000
Copy link

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.

NewGRF: https://dev.openttdcoop.org/attachments/download/9876/nuts-curve_speed_mod.grf

V453000/NUTS@1b6e15c

@TrueBrain TrueBrain added this to the 1.12 milestone Aug 14, 2021
@michicc michicc added the needs review: NewGRF Review requested from a NewGRF expert label Aug 14, 2021
@michicc
Copy link
Member

michicc commented Aug 14, 2021

Makes sense to me and the code looks clean, but I might miss some intimate NewGRF knowledge to notice any problems.

Copy link
Member

@TrueBrain TrueBrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think every dev by now has said: yeah, this looks fine, just the NewGRF part I don't know about :D So maybe we should just bite the bullet and go for it .. if these three gentlemen in this thread can't figure out a way to extend the NewGRF specs nicely, who can! :D

Guess the most work is making sure https://wiki.openttd.org/en/Development/NewGRF/Specification%20Status is updated properly, which is mainly to track if we truly updated everything involved here.

@michicc michicc merged commit 2183fd4 into OpenTTD:master Aug 15, 2021
@michicc
Copy link
Member

michicc commented Aug 15, 2021

Spec state page updated, will write NFO wiki part.

@vituscze vituscze deleted the newgrf-curve-speed branch August 15, 2021 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review: NewGRF Review requested from a NewGRF expert
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants