AIEngineList, IsValidEngine and Maglev in the year 1950

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
deepblue2k8
Engineer
Engineer
Posts: 44
Joined: 06 Sep 2008 12:41
Location: Hamburg, Germany

AIEngineList, IsValidEngine and Maglev in the year 1950

Post by deepblue2k8 »

static bool AIEngine::IsValidEngine

Code: Select all

local enginelist = AIEngineList(AIVehicle.VT_RAIL);
local engine;
		
enginelist.Valuate(AIEngine.IsWagon);
enginelist.KeepValue(1);
enginelist.Valuate(AIEngine.IsValidEngine);
enginelist.KeepValue(1);
I have another problem regarding the AIEngineList:
With the standard train set this code snippet still gives me the cargo wagons for coal, goods etc. for the all four railtypes (Maglev, Monorail, Electrified,...) even though I cant build them in the year 1950... I thought that the future rail wagons shouldn't survive a valuate with IsValidEngine (which "Checks whether the given engine type is valid and buildable by you.") ?

Thanks
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIEngineList, IsValidEngine and Maglev in the year 1950

Post by Yexo »

I'm not able to test it now, but your code looks correct and should do what you describe. The code

Code: Select all

enginelist.Valuate(AIEngine.IsValidEngine);
enginelist.KeepValue(1);
isn't needed because AIEngineList will only contains valid engines.
deepblue2k8
Engineer
Engineer
Posts: 44
Joined: 06 Sep 2008 12:41
Location: Hamburg, Germany

Re: AIEngineList, IsValidEngine and Maglev in the year 1950

Post by deepblue2k8 »

Is it possible that in the original train set the wagons have no valid design date but only the engines?

As a workaround I could check if there are engines available for the railtype of each wagon.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIEngineList, IsValidEngine and Maglev in the year 1950

Post by Yexo »

All wagons from the original vehicles are available from 1925 indeed. But I think it would be better for the API to not expose those wagons as valid until at least one engines is available because the railtype isn't valid until that time.
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: AIEngineList, IsValidEngine and Maglev in the year 1950

Post by Xander »

As a fix, for now at least, you could do a final validation against AIEnginge.CanRunOnRail

disclaimer: I haven't tested this myself owing to not being at a PC with OTTD on it
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
deepblue2k8
Engineer
Engineer
Posts: 44
Joined: 06 Sep 2008 12:41
Location: Hamburg, Germany

Re: AIEngineList, IsValidEngine and Maglev in the year 1950

Post by deepblue2k8 »

My goal was to first check for a wagon for my cargo to transport and choosing the railtype according to the wagon. I want to do it that way in order to prevent my AI using MonoRail with 2cc Train Set and then realising there is no freight wagon for that railtype :)

So CanRunOnRail isnt useful for me in that case.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIEngineList, IsValidEngine and Maglev in the year 1950

Post by Yexo »

I solved that problem by selecting the best engine / wagon combination for every railtype and then comparing those. Railtypes without an engine or wagon are left out, so it'll never chose a railtype that it can't use.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AIEngineList, IsValidEngine and Maglev in the year 1950

Post by fanioz »

deepblue2k8 wrote:My goal was to first check for a wagon for my cargo to transport and choosing the railtype according to the wagon. I want to do it that way in order to prevent my AI using MonoRail with 2cc Train Set and then realising there is no freight wagon for that railtype :)

So CanRunOnRail isnt useful for me in that case.
How with these ?

Code: Select all

local c = AIEngineList(AIVehicle.VT_RAIL);
c.Valuate(AIEngine.IsWagon);
c.KeepValue(1);
foreach (i, v in c) {
	if (!AIRail.IsRailTypeAvailable(AIEngine.GetRailType(i))) continue;
	AILog.Info("Name " + AIEngine.GetName(i));
       //do other
}
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
deepblue2k8
Engineer
Engineer
Posts: 44
Joined: 06 Sep 2008 12:41
Location: Hamburg, Germany

Re: AIEngineList, IsValidEngine and Maglev in the year 1950

Post by deepblue2k8 »

Thank you fanioz. That looks good :)
And thanks to everyone else for their ideas :)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 6 guests