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

Doc: [Script] Add a note about how wagon connectivity works for scripts #8002

Merged
merged 1 commit into from Feb 19, 2020

Conversation

LordAro
Copy link
Member

@LordAro LordAro commented Feb 15, 2020

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

Copy link
Contributor

@glx22 glx22 left a comment

Maybe add a note to IsValidVehicle too

@LordAro
Copy link
Member Author

@LordAro LordAro commented Feb 15, 2020

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.

@frosch123
Copy link
Member

@frosch123 frosch123 commented Feb 15, 2020

This rather looks like a bug that should be fixed, instead of being documented.
In the API "VehicleId" refers to a wagon chain, i.e. always to the first vehicle in a chain.
BuildVehicle should always create a new chain.
If it does not do that for wagons, it's a bug.

The intention of the API is that OpenTTD should never attach wagons automatically, to make stuff easy/predictable for the AI.

@LordAro
Copy link
Member Author

@LordAro LordAro commented Feb 15, 2020

I'm tempted to agree, but writing a compatibility shim for that could be tricky...

@frosch123
Copy link
Member

@frosch123 frosch123 commented Feb 16, 2020

SimpleAI and WormAI make active use of this behaviour (same "railbuilder.nut" in both AIs).
They build N pax wagons, N mail wagons, remember only the first ID, refit the chains and then attach the chains to the engine.
It also does some magic shuffling, if it turns out that pax and mail wagons are the same wagons.

@LordAro
Copy link
Member Author

@LordAro LordAro commented Feb 16, 2020

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?

@frosch123
Copy link
Member

@frosch123 frosch123 commented Feb 16, 2020

Sounds like a big API change, but big changes only work if someone uses them.
So documenting this is the best option until there is actual demand by AI authors for a better API. But it seems they were happy working around the weirdness.

@LordAro LordAro added the backport requested label Feb 16, 2020
@nielsmh nielsmh merged commit 5c19668 into master Feb 19, 2020
8 checks passed
@LordAro LordAro deleted the improve-buildveh-doc branch Feb 23, 2020
@LordAro LordAro added backported and removed backport requested labels Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants