AITileList_IndustryAccepting gives too much tiles

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
Gastje33
Engineer
Engineer
Posts: 22
Joined: 05 Aug 2004 14:06
Location: Netherlands

AITileList_IndustryAccepting gives too much tiles

Post by Gastje33 »

First, it is cool to see NoAI is included into 0.7.0. :D When I saw it, I decided to play around with it again. Now I have a fairly working AI building lorry routes between industries. So far I have had one problem with the API. Sometimes a station doesn't accept the cargo even if the industry is within its radius. Which you can see in the following screenshot:
Station not accepting.png
Station not accepting.png (286.15 KiB) Viewed 2982 times
If one uses AITileList_IndustryAccepting to get the tiles where one can build a station, it also returns the beforementioned wrong tiles. The bay in the screenshot is built by my AI with the following code (parts are cut out, it checks if it can build there, but stays within the accTiles list):

Code: Select all

local accTiles = AITileList_IndustryAccepting(pair.AcceptingIndustry, AIStation.GetCoverageRadius(AIStation.STATION_TRUCK_STOP));
local accTile = accTiles.Begin();
AIRoad.BuildRoadStation(accTile, accTile + 1, AIRoad.ROADVEHTYPE_TRUCK, AIStation.STATION_NEW)
I've did some searching, but couldn't find anything on the forum and the bugtracker about this. So my question is: am I doing something wrong, or OpenTTD?

Of course I use the latest nightly (r16189). My operating system is Windows 7 (build 7000), but that is rather irrelavant, I think...
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: AITileList_IndustryAccepting gives too much tiles

Post by GeekToo »

The api is correct, but the industry won't accept until you actually provide it with transportation, just like for a normal player
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: AITileList_IndustryAccepting gives too much tiles

Post by planetmaker »

The simple answer is: industries are generally such (even in original TTD afaik) that not every tile of them accepts cargo. Only some of them accept cargo and you need to have those within your station coverage. It's the same for human players.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: AITileList_IndustryAccepting gives too much tiles

Post by TrueBrain »

What are you two babbling about?
GeekToo wrote:The api is correct, but the industry won't accept until you actually provide it with transportation, just like for a normal player
False; Acceptance is a calculation which has nothing to do with true delivery. Mind you that his shot clearly shows what happens when a human tries to build a station, and where it shows what cargo is accepted. Of course the NoAI API should match that result. Clearly it doesn't. What you refer to is production.

planetmaker wrote:The simple answer is: industries are generally such (even in original TTD afaik) that not every tile of them accepts cargo. Only some of them accept cargo and you need to have those within your station coverage. It's the same for human players.
Although this is very true, the API should either return this value, or should not add the tile until the cargo is completely accepted. To give a bit more detail: each tile can accept a value of a cargo. If this value is above 8, the cargo is accepted. Below that value, it is not. As far as I was aware, but I have to add my knowledge is very old on this subject, this function should only return those tiles which really accept the cargo. I wouldn't know if they don't do that any more (by recent changes), never did, or there is some other catch to this .. either way, I am sure someone with a bit more in-depth up-to-date knowledge will help you out soon :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: AITileList_IndustryAccepting gives too much tiles

Post by GeekToo »

TrueBrain wrote:What are you two babbling about?
False; Acceptance is a calculation which has nothing to do with true delivery. Mind you that his shot clearly shows what happens when a human tries to build a station, and where it shows what cargo is accepted. Of course the NoAI API should match that result. Clearly it doesn't. What you refer to is production.
Sorry for the confusion; as usual, TrueBrain is completely right, I was referring to production, my bad.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: AITileList_IndustryAccepting gives too much tiles

Post by frosch »

This is going to be a bit delayed. As we need yexo for that :)

AITileList_IndustryAccepting is a bit unclear about whether it shall return the tiles which accept at least one cargo, or which accept all cargos of the industry. Maybe some list of tiles that accept a certain cargo is also useful.

For now it looks like that class is only used by Admiral and by NoCAB.
Admiral seems to filter the list afterwards for tiles that accept a certain cargo, using

Code: Select all

list.Valuate(AITile.GetCargoAcceptance, ...)
list.KeepAboveValue(7);
What NoCAB does, I do not understand :)

Edit: Btw. maybe the filting is already powerful enough, so the function might also stay as it is, and just the documentation needs fixing.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Gastje33
Engineer
Engineer
Posts: 22
Joined: 05 Aug 2004 14:06
Location: Netherlands

Re: AITileList_IndustryAccepting gives too much tiles

Post by Gastje33 »

TrueBrain wrote: [...]
Although this is very true, the API should either return this value, or should not add the tile until the cargo is completely accepted. To give a bit more detail: each tile can accept a value of a cargo. If this value is above 8, the cargo is accepted. Below that value, it is not. As far as I was aware, but I have to add my knowledge is very old on this subject, this function should only return those tiles which really accept the cargo. I wouldn't know if they don't do that any more (by recent changes), never did, or there is some other catch to this .. either way, I am sure someone with a bit more in-depth up-to-date knowledge will help you out soon :)
The docs say this about the list:
Detailed Description
Creates a list of tiles that will accept cargo for the given industry.
So at least one of the two is wrong (the docs or the code). :P It seems that the API only checks if the industry tiles are within its radius. Only two tiles of the power station actually accept the coal, the other tiles don't accept anything.

Edit:
frosch wrote: [...]
For now it looks like that class is only used by Admiral and by NoCAB.
Admiral seems to filter the list afterwards for tiles that accept a certain cargo, using

Code: Select all

list.Valuate(AITile.GetCargoAcceptance, ...)
list.KeepAboveValue(7);
[...]
Thank you! I haven't yet thought of that. :D I used a smaller radius, but that is a very dirty fix.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AITileList_IndustryAccepting gives too much tiles

Post by Yexo »

frosch wrote:This is going to be a bit delayed. As we need yexo for that :)

AITileList_IndustryAccepting is a bit unclear about whether it shall return the tiles which accept at least one cargo, or which accept all cargos of the industry. Maybe some list of tiles that accept a certain cargo is also useful.

For now it looks like that class is only used by Admiral and by NoCAB.
Admiral seems to filter the list afterwards for tiles that accept a certain cargo, using

Code: Select all

list.Valuate(AITile.GetCargoAcceptance, ...)
list.KeepAboveValue(7);
What NoCAB does, I do not understand :)

Edit: Btw. maybe the filting is already powerful enough, so the function might also stay as it is, and just the documentation needs fixing.
That filtering can be build in the api, but then it's possible the an industry accepts a certain cargo, but that there is no tile that accepts that cargo (think an industry that accepts 1/8 passengers on only one tile). My suggestion is to just fix the documentation. If anyone can come up with a nice description for the current behavior please post it.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: AITileList_IndustryAccepting gives too much tiles

Post by TrueBrain »

Yexo wrote:That filtering can be build in the api, but then it's possible the an industry accepts a certain cargo, but that there is no tile that accepts that cargo (think an industry that accepts 1/8 passengers on only one tile). My suggestion is to just fix the documentation. If anyone can come up with a nice description for the current behavior please post it.
Well, if there is only one tile with 1/8th of passengers, the tile is not of any interest to you anyway .. so I would suggest to fix the code to match what the documentation says. Or maybe remove it and add a new list where you can do the same, only per cargo (so instead of any cargo, just one cargo). Either way, I don't think this function is any useful in its current state (and I thought we already fixed it long ago that it only returns cargo which are truly accepted .. but okay ;)).
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: AITileList_IndustryAccepting gives too much tiles

Post by Bilbo »

That tile could be of interest if you got remaining 7/8 of passengers from nearby town...

By the way, if the AI have planned station from several components (some rail + perhaps few bus stops/airport), you can easily compute the covered area and therefore the coverage rectangle. So, is there a way that when given a coverage rectangle to tell you what cargoes will end up bewing produced and accepted? (before actually building the station)

Humans can do that by picking rail station building and then dragging it over target area, seeing what would be accepted and produced.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AITileList_IndustryAccepting gives too much tiles

Post by fanioz »

Just want to share :D
First time I used this function ( AITileList_IndustryAccepting and AITileList_IndustryProducing ) I only guess what it does. I think this function usage is to return an area of tiles around of industry counted from outer side, since not every industry have a same dimension (X/Y). Therefore it use radius, that is number of tiles from each side of industry. About a production/acceptance there are function AITile.GetProduction and AITile.GetAcceptance to actually check. And some time value below 8 is still acceptable.

And agree with Bilbo, human can easily use the station icon (before actually build it) to check every cargo would produce and accept around catchment area.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 18 guests