How to break a wagon chain into two parts?

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

How to break a wagon chain into two parts?

Post by Brumi »

Currently I'm working on SimpleAI to add support for NUTS. The problem there is that the same wagon can be used for carrying passengers and mail. My AI usually adds one mail wagon to the end of passenger trains, but as the mail and passenger wagons are of the same type, they get attached to the same wagon chain as I'm building them. I need to have the mail wagon in a separate chain to refit it, but AIVehicle.MoveWagon(firstwagon, 1, -1, 0) (assuming that the mail wagon is the second one) does nothing to the wagon chain, although it returns true. Note that I'm trying to move a wagon away from a chain which has no locomotive yet.
So, am I overlooking something, is it a bug in the API, or I need to do some workaround?
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: How to break a wagon chain into two parts?

Post by krinn »

there's no "virtual" vehicle and we have no function to get a wagon except inside a vehicle, as such, any wagon move out of a vehicle not into another vehicle is lost as soon as its var holding its id is lost. LOL yeah, dead wagons stay in depot and you then cannot delete the depot :)

you need to workaround that, refit it once built, or delete the wagon to build and refit a new one.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: How to break a wagon chain into two parts?

Post by Brumi »

My problem is not that I have dead wagons. When building a passenger train, I build the locomotive first, then a passenger wagon (called 'firstwagon'), and then the mail wagon (called 'mailwagon'). After this, I usually have 3 separate chains. But in the case of NUTS, the passenger wagon and the mail wagon are the same, so I have 2 chains instead of 3, and I cannot refit the mail wagon without moving it away from the passenger wagon first. I tried to do this using the command I described in my first post, but that does nothing, although the documentation says that -1 creates a new chain. I have the ID of that wagon, so it wouldn't be dead.
So most probably I need an ugly workaround for this :(
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: How to break a wagon chain into two parts?

Post by krinn »

Well, i'm not sure if this has ever work. The code show it use ::INVALID_VEHICLE when using -1
Anyway even if this work, moving it to some unknow vehicle won't help. To work as it should this function should return the new vehicleID where the cart were attach to.
Because even having the ID of the wagon you would be able to refit it, but still in a unknow vehicle or refit at depot, but it will remain "dead". As if you wish move that wagon again, you will need to give it not the ID of the wagon, but the ID of the vehicle that now have the wagon :)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests