Sending vehicles to depot

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
marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Sending vehicles to depot

Post by marco.r »

Greetings,

what are the reasons that may cause a call to AIVehicle.SendVehicleToDepot ?
All I get is a ERR_UNKNOWN when I use AIError.GetLastError.

Moreover, is there a way to know that a given vehicle is already going to a depot,
so that I can avoid to undo the action by mistake ?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Sending vehicles to depot

Post by Yexo »

The only reasons I can find for getting ERR_UNKNOWN is calling the function on a vehicle that has 1) crashed or 2) is already stopped inside a depot.

You can check if a vehicle is going to a depot by testing AIRoad.IsRoadDepotTile(AIOrder.GetOrderDestination(vehicle_id, AIOrder.ORDER_CURRENT));. Subsitute AIRoad.ISRoadDepotTile with the appropriate function for the vehicle type you're using.
marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: Sending vehicles to depot

Post by marco.r »

Hi Yexo, thanks for answering.

Even after adding a check to see if the truck is alread in the depot, I still get ERR_UNKNOWN errors...
If I keep trying to do the command, something like

Code: Select all

while( !AIVehicle.SendVehicleToDepot(vehicle) )  ;
(Yuck :D), eventually the command will succeed, but taking quite a while,
so instead I get the same result by removing existing orders and adding one to go to
a depot. Seems a more reliable way... at least for now.
Thanks also for the other suggestion (but with the way I handle it now, it shouldn't be necessary)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Sending vehicles to depot

Post by Zuu »

The command will fail (not sure about exactly which error message) for road vehicles when they are in certain states in road stations. Just telling a vehicle to go to depot will also not make it stop loading in some (all?) conditions. Therefore, I use the approach to unshare orders, remove all orders and then add a goto depot order. In some cases it is also a good idea to tell road vehicles to turn around if they are stuck in a queue.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests