-
-
Notifications
You must be signed in to change notification settings - Fork 874
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
Doc: [Script] Add a note about how wagon connectivity works for scripts #8002
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a note to IsValidVehicle
too
The edge case is only related to building vehicles, I'm not sure what note I could put on IsValidVehicle without being overly specific - it's not a valid vehicle because the vehicle doesn't exist any more. |
This rather looks like a bug that should be fixed, instead of being documented. The intention of the API is that OpenTTD should never attach wagons automatically, to make stuff easy/predictable for the AI. |
I'm tempted to agree, but writing a compatibility shim for that could be tricky... |
SimpleAI and WormAI make active use of this behaviour (same "railbuilder.nut" in both AIs). |
Looking at the available API functions, there's no way to find the vehicles in a particular depot - you'd need to iterate through all vehicles and check state (is in depot) & location. Would turn BuildVehicle into a very expensive function. Not actually sure what you'd do to check whether a vehicle is just an unattached wagon So yes, fixing this "bug" and adding a compatibility shim would be possible, but would really require adding a couple new API functions. Worth it? |
Sounds like a big API change, but big changes only work if someone uses them. |
I did some digging into this, and it seems that by design new wagons only connect to existing free wagons, not trains. The connecting to trains bit happens in the GUI window, which obviously scripts don't have.
I've convinced myself that this is sane behaviour, so just added a note to the BuildVehicle documentation. Also added a "test" of this in the regression test.
Closes #6515