Trouble finding a valid cart with ECS

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
Maninthebox
Engineer
Engineer
Posts: 113
Joined: 08 Aug 2008 11:35
Contact:

Trouble finding a valid cart with ECS

Post by Maninthebox »

I'm currently running all sorts of test with the new OtviAI with train support. I've enabled only the ECS newgrfs and noticed at some point a very peculiar train on my tracks. It was a steam loc followed by 3 kirby paul tanks. As it turns out, these are the best you can get to haul wood products... So the question is: am I making a mistake in my cart selection function? Is there no cart available for wood products without adding another newgrf (starting 1970 or so, the AI can't find any cart)?

Code: Select all

 287     function getCart(cargoID, railType) {                                                                                                
 288         local cart_list = AIEngineList(AIVehicle.VT_RAIL);                                                                               
 289         cart_list.Valuate(AIEngine.CanRefitCargo, cargoID);                                                                              
 290         cart_list.KeepValue(1);                                                                                                          
 291                                                                                                                                          
 292         cart_list.Valuate(AIEngine.IsWagon);                                                                                             
 293         cart_list.KeepValue(1);                                                                                                          
 294                                                                                                                                          
 295         cart_list.Valuate(AIEngine.CanRunOnRail, railType);                                                                              
 296         cart_list.KeepValue(1);                                                                                                          
 297                                                                                                                                          
 298         cart_list.Valuate(AIEngine.GetCapacity)                                                                                          
 299         cart_list.KeepTop(1);                                                                                                            
 300                                                                                                                                          
 301         local cart = cart_list.Begin();                                                                                                  
 302         Debug("Picked cart for cargo " + AICargo.GetCargoLabel(cargoID) + ": " + AIEngine.GetName(cart));                                
 303                                                                                                                                          
 304         return cart;                                                                                                                     
 305     } 
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Trouble finding a valid cart with ECS

Post by Yexo »

Correct, if you use an industry newgrf you generally have to use a vehicle newgrf too to be able to transport the new cargoes.
Maninthebox
Engineer
Engineer
Posts: 113
Joined: 08 Aug 2008 11:35
Contact:

Re: Trouble finding a valid cart with ECS

Post by Maninthebox »

I suspected as much, but: will adding a 'wood products' cart newgrf fix the problem of finding the kirby paul tank? Because the listed code can only result in wagons that can be refitted to some cargo type. If I don't have the appropriate newgrf installed, I should just get null (like I do in later years) not a steam loc right? A kirby paul is neither a wagon, nor refitable to any type of cargo as far as I can see...
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Trouble finding a valid cart with ECS

Post by Yexo »

You should check for cart_list.IsEmpty() before calling cart_list.Begin(). Begin returns 0 in case the list is empty, and the kirby paul tank is the engine with id 0. So you don't find any engine, but because you don't check that condition your code things you find the kirby paul tank. In later years you probably get null because the kirby paul tank is not valid anymore.
Maninthebox
Engineer
Engineer
Posts: 113
Joined: 08 Aug 2008 11:35
Contact:

Re: Trouble finding a valid cart with ECS

Post by Maninthebox »

Ahhh... that explains... let me check my other list uses for the same bug :P Thanks for the explanation!
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests