AIRail::BuildNewGRFRailStation

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

Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

AIRail::BuildNewGRFRailStation

Post by Kogut »

Why that:

Code: Select all

	local hangar = AIAirport.GetHangarOfAirport(tile_1);

	if (!AIEngine.IsValidEngine(engine)) {
		AILog.Error("Couldn't find a suitable engine");
		return false;
	}
	
	AILog.Error("aircraft " + AIError.GetLastErrorString());
	local vehicle = AIVehicle.BuildVehicle(hangar, engine);
	AILog.Error("aircraft " + AIError.GetLastErrorString());
	if (!AIVehicle.IsValidVehicle(vehicle)) {
		AILog.Error("Couldn't build the aircraft " + AIError.GetLastErrorString());
		AISign.BuildSign(hangar, "HERE "+AIDate.GetCurrentDate());
		return false;
	}
Result in?
What may be cause of UNKNOW error?
Engine is correct, depot place is correct, money is sufficient...
Attachments
Przechwytywanie.PNG
Przechwytywanie.PNG (40.93 KiB) Viewed 4372 times
Last edited by Kogut on 04 Jul 2010 10:04, edited 29 times in total.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Aircraft problem

Post by Yexo »

There are several causes that can result in ERR_UNKOWN, but in the end for all of them the AI has made a wrong choice. (trying to build a non-aircraft at an airport, trying to build on a non-hangar tile, building planes on a heliport, etc.) If you upload an AI that reproduces the problem I'll take a look at it.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Aircraft problem

Post by Kogut »

Standard settings, seed 1, problem before 15 January, openttd 1.0.0-RC1.
Attachments
main.nut
(8.56 KiB) Downloaded 100 times
info.nut
(619 Bytes) Downloaded 89 times
here.sav
(96.22 KiB) Downloaded 94 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Morloth
Transport Coordinator
Transport Coordinator
Posts: 378
Joined: 07 Feb 2008 14:06
Location: Glasgow

Re: Aircraft problem

Post by Morloth »

Hey Kogut,

I just tried out your version and if I add the following rule to the FindAircaft method the code to this:

Code: Select all

function KWAI::FindAircraft(airport_type, passenger_cargo_id) {
   ...
   assert(engine_list.Count() > 0);
   return engine_list.Begin();
}
I get an assertion error. What you want to do, is not only check for AIEngine.GetCargoType(engineID) == passenger_cargo_id, but also for: AIEngine.CanRefitCargo(engineID, passenger_cargo_id) and make sure you don't return an empty list.

That should fix your problem, good luck with your AI! :)
Bram
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Aircraft problem

Post by Kogut »

Thanks!
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Aircraft problem

Post by Kogut »

Morloth wrote:What you want to do, is not only check for AIEngine.GetCargoType(engineID) == passenger_cargo_id, but also for: AIEngine.CanRefitCargo(engineID, passenger_cargo_id) and make sure you don't return an empty list.
How to do it using valuators?

How to replace "AIEngine.GetCargoType" in

Code: Select all

engine_list.Valuate(AIEngine.GetCargoType);
with CanRefitCargo(EngineID engine_id, CargoID cargo_id)?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Aircraft problems [new problem]

Post by Zuu »

Kogut wrote:How to replace "AIEngine.GetCargoType" in
Code:
engine_list.Valuate(AIEngine.GetCargoType);


with CanRefitCargo(EngineID engine_id, CargoID cargo_id)?
engine_list.Valuate(AIEngine.CanRefitCargo, cargo_id);

The first parameter to a valuator function will always be taken from the list to valuate, the next parameters you send to the valuators as argument to the Valuate function.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Aircraft problems [solved, thanks!]

Post by Kogut »

Thanks!

New problem: I have:

tileindex pozycja;
industrID industry_list

And I want valuate industry_list according to distance from tile pozycja.
So I want to valuate with AITile.GetDistanceManhattanToTile(AIIndustry.GetLocation( <HERE ENTRY FROM INDUSTRY LIST> ), pozycja);

How to do it?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: New valuator problem

Post by Zuu »

For that you need to write your own function that take am industry id and return the distance using the code you wrote. Pass this function to the valuate function.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: New valuator problem

Post by Zutty »

That is a good way of doing it, however in this particular case AIIndustry has a handy dandy function to do this for you...

Code: Select all

industry_list.Valuate(AIIndustry.GetDistanceManhattanToTile, pozycja);
PathZilla - A networking AI - Now with tram support.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: New valuator problem [solved, thanks]

Post by Kogut »

Thanks!

Now I have problems with cargo catchment. In noai api there is function

Code: Select all

AIStation::GetCoverageRadius(AIStation::StationType station_type)  	
As argument it need station type. Unfortunatelly it is broken confused me, because various airports have various coverage (see picture, straight part of roar/canal/rail is size of catchment), and I need fuction that can tell me is (constructed) airport in one of loading tiles of industry.

http://noai.openttd.org/api/trunk/class ... d96eba1275

EDIT: I have workaround, but that function is broken may confuse sb.
Attachments
Przechwytywanie.PNG
Last edited by Kogut on 02 Mar 2010 07:05, edited 2 times in total.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Catchment problem

Post by Yexo »

For airports you can use AIAirport::GetAirportCoverageRadius
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: New valuator problem [solved, thanks]

Post by PikkaBird »

Kogut wrote:As argument it need station type. Unfortunatelly it is broken,
EDIT: I have workaround, but that function is broken.
I realise English isn't your first language Kogut, but be careful telling devs that functions are "broken" when it's more likely you're just not using them correctly. ;) It's a little bit rude...
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Catchment problem

Post by Kogut »

I changed to sth else, and I have next problem: is it possible to get refit cost of vehicle?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Refit cost problem

Post by Zuu »

If you have the vehicle in a depot then you can use AITestMode and AIAccounting mode togeather to get the price of a refit without actually executing it. If you want information about a vehicle before it is built then it is not a vehicle, but an engine. Engine information you get by using AIEngine. Have a look there if refit cost can be obtained. If not, that is probably because of a limitation with respect to how the NewGRF system was designed.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Road pathfinder, sloped bridge problem

Post by Kogut »

Is it counted as sloped tile?
Attachments
Przechwytywanie.PNG
Przechwytywanie.PNG (4.71 KiB) Viewed 3996 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Road pathfinder, sloped bridge problem

Post by fanioz »

It should only flat (grass) tiles there. Look here
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Sleep problem

Post by Kogut »

Thanks!

Why it is impossible to execute Sleep command in non static function outside start function? Is it possible to remove that limitation?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Sleep problem

Post by Yexo »

Kogut wrote:Why it is impossible to execute Sleep command in non static function outside start function?
That is possible.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Sleep problem

Post by Kogut »

So why it happened?
Attachments
Przechwytywanie.PNG
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 8 guests