Skip to content

Add: conditional order to test if a train is driving backwards#15484

Merged
PeterN merged 1 commit intoOpenTTD:masterfrom
PeterN:conditional-driving-backwards
Apr 16, 2026
Merged

Add: conditional order to test if a train is driving backwards#15484
PeterN merged 1 commit intoOpenTTD:masterfrom
PeterN:conditional-driving-backwards

Conversation

@PeterN
Copy link
Copy Markdown
Member

@PeterN PeterN commented Apr 15, 2026

Motivation / Problem

Trains can now drive backwards. #15391 adds the possibility for any train to drive backwards at a reduced speed.

Description

This PR adds a conditional order condition to test if a train is driving backwards. This allows it to be routed differently depending on whether it is driving forwards or backwards.

image

Limitations

Due to how orders are evaluated at stations, the current driving direction is tested rather than the driving direction after starting to move, so the flag may be "outdated" when testing at stations. It's still usable but can be fiddly.

(It also kinda depends on #15391 to be more useful)

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 touches english.txt or translations? Check the guidelines
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@PeterN PeterN force-pushed the conditional-driving-backwards branch from bc5cf8b to 20c238b Compare April 15, 2026 20:00
Comment thread src/order_type.h Outdated
@PeterN PeterN force-pushed the conditional-driving-backwards branch from 20c238b to a444374 Compare April 15, 2026 23:14
@zephyris
Copy link
Copy Markdown
Contributor

Might be wrong, haven't had a chance to test, but wouldn't "arrived at last stop backwards" be more accurate? Or something like that? I can see the wording is tricky, seems like a fiddly behaviour.

@PeterN
Copy link
Copy Markdown
Member Author

PeterN commented Apr 16, 2026

Might be wrong, haven't had a chance to test, but wouldn't "arrived at last stop backwards" be more accurate? Or something like that? I can see the wording is tricky, seems like a fiddly behaviour.

Sort of. The order before the conditional doesn't have to be the "last stop", e.g. a waypoint of go via order.

@PeterN PeterN merged commit d15f105 into OpenTTD:master Apr 16, 2026
18 checks passed
@PeterN PeterN deleted the conditional-driving-backwards branch April 16, 2026 20:00
@reldred
Copy link
Copy Markdown

reldred commented Apr 17, 2026

Might be a bug in JGRPP's cherrypick of this, but this doesn't seem to take into account a train driving backwards with a cab on the rear? Perhaps two conditions would be better, driving backwards, and driving backwards without a cab? Maybe make it instead of a straight boolean add 'true with a cab, false with a cab' to the criteria. The former with two different conditions is how JGR's programmable signals/routing restrictions works.

Purpose of this would be a shared orders list that starts off with steamers without driving cabs that gets locos with driving cabs added to it afterwards.

Also, for other spectators I've found this approach works well to get around needing the train to get underway before the conditional works:
image

Otherwise, great addition!

@PeterN
Copy link
Copy Markdown
Member Author

PeterN commented Apr 17, 2026

Alright, any way to reduce the length of this updated string?

"Driving backwards at reduced speed"

Maybe "Driving backwards slowly" but it feels wrong.

@reldred
Copy link
Copy Markdown

reldred commented Apr 17, 2026

I wonder, maybe just make it so that the driving backwards check only matches true if there's no cab and leave the strings alone entirely? Only reason I can really think of to use this condition is if the reversing is going to incur a penalty to begin with.

@PeterN
Copy link
Copy Markdown
Member Author

PeterN commented Apr 17, 2026

Yes, that is what I'm doing, I'm just quibbling (by myself) about the wording of the text :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants