Some API extension ideas
Moderator: OpenTTD Developers
- MinchinWeb
- Traffic Manager
- Posts: 225
- Joined: 01 Feb 2011 12:41
- Contact:
Re: Some API extension ideas
Well it seems that Zuu has figured out a way to tell an AI to build the ship, so the pressing need is gone.
I still like the idea of including Order commands. As it sits right now, a GameScript and build the station and depot, run the pathfinder, build a ship, start a ship moving, it just can't tell it where to go...
I still like the idea of including Order commands. As it sits right now, a GameScript and build the station and depot, run the pathfinder, build a ship, start a ship moving, it just can't tell it where to go...
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
- MinchinWeb
- Traffic Manager
- Posts: 225
- Joined: 01 Feb 2011 12:41
- Contact:
Re: Some API extension ideas
Is it possible to just make one tile a one-way road? It seems that to build one-way road, you need to supply two tiles and it you can't turn the first tile into a one-way road, neither is converted to be a one-way road.
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Re: Some API extension ideas
AIStation::GetMonthlyCargoSupply(StationID station_id, CargoID cargo_id) - to access new information available to players (via station window, after selecting ratings)
AIStation::HasCargoAcceptance(StationID station_id, CargoID cargo_id) - to access information available to players since forever (via station window, after selecting ratings)
Both are missing and I just wanted to use it.
AIStation::HasCargoAcceptance(StationID station_id, CargoID cargo_id) - to access information available to players since forever (via station window, after selecting ratings)
Both are missing and I just wanted to use it.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Some API extension ideas
Using AICargoList.StationAccepting I think that you can create a Squirrel wrapper for the requested method.Kogut wrote:AIStation::HasCargoAcceptance(StationID station_id, CargoID cargo_id) - to access information available to players since forever (via station window, after selecting ratings)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Some API extension ideas
Thanks, I missed this list!Zuu wrote:Using AICargoList.StationAccepting I think that you can create a Squirrel wrapper for the requested method.Kogut wrote:AIStation::HasCargoAcceptance(StationID station_id, CargoID cargo_id) - to access information available to players since forever (via station window, after selecting ratings)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Some API extension ideas
And for this functionnality, AIStation.HasRating == HasCargoAcceptance in newer API.Kogut wrote:Thanks, I missed this list!Zuu wrote:Using AICargoList.StationAccepting I think that you can create a Squirrel wrapper for the requested method.Kogut wrote:AIStation::HasCargoAcceptance(StationID station_id, CargoID cargo_id) - to access information available to players since forever (via station window, after selecting ratings)
edit: the function is HasRating is Changelog, but the real one is there http://noai.openttd.org/docs/trunk/clas ... 2d4b3a545e
Re: Some API extension ideas
It would be useful to have AIEngine::GetCargoLoadingSpeed(engine_id, cargo_id).
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Some API extension ideas
That's at least numerically not available to the user either. Granted, some NewGRFs give a hint on the order of speed in the extra text (and possibly it could be done so w/o the extra text even), thus it is IMHO a valid request.Kogut wrote:It would be useful to have AIEngine::GetCargoLoadingSpeed(engine_id, cargo_id).
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: Some API extension ideas
It is a change, not expansion but I think it fits here.
This is one of the most confusing things:
Is it applied to the single airport or is it about two groups (whatever large planes can safely fly)?
It seems that it is about single airports - so why city airport is named large? And is it possible to order this in the same way as it is in interface (it is enough to change position of commuter airport)?
This is one of the most confusing things:
Code: Select all
enum AIAirport::AirportType
The types of airports available in the game.
Enumerator:
AT_SMALL The small airport.
AT_LARGE The large airport.
AT_METROPOLITAN The metropolitan airport.
AT_INTERNATIONAL The international airport.
AT_COMMUTER The commuter airport.
AT_INTERCON The intercontinental airport.
AT_HELIPORT The heliport.
AT_HELISTATION The helistation.
AT_HELIDEPOT The helidepot.
AT_INVALID Invalid airport.
Code: Select all
AT_SMALL The small airport.
AT_LARGE The large airport.
It seems that it is about single airports - so why city airport is named large? And is it possible to order this in the same way as it is in interface (it is enough to change position of commuter airport)?
Code: Select all
enum AIAirport::AirportType
The types of airports available in the game.
Enumerator:
AT_SMALL The small airport.
AT_COMMUTER The commuter airport.
AT_LARGE The large airport.
AT_METROPOLITAN The metropolitan airport.
AT_INTERNATIONAL The international airport.
AT_INTERCON The intercontinental airport.
AT_HELIPORT The heliport.
AT_HELISTATION The helistation.
AT_HELIDEPOT The helidepot.
AT_INVALID Invalid airport.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Some API extension ideas
Historical reasons; in the beginning there was a heliport, and a small and large airport.Kogut wrote:It seems that it is about single airports - so why city airport is named large?
No. That would change the API (read: old saved data from AIs) and break in case NewGRFs were to provide airports. I think there should be a CanLandAtStation(AirportType, PlaneType) function, which should return false for PT_BIG_PLANE at "small" airports (those where big planes crash more often). Though this slight misleading name should then be documented: "Big planes can land at all airports where small planes can land, but for certain airports the chance of crashing the big plane is significantly increased. Thus this function return false to try to prevent causing unneeded plane crashes"Kogut wrote:And is it possible to order this in the same way as it is in interface (it is enough to change position of commuter airport)?
Re: Some API extension ideas
CanSafelyUseStation?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Some API extension ideas
As long as airporttype are enum, nothing is critically need, except for an AI dev that have never played openttd. It "may" disturb an AI if a newGRF change a big airport to a small one (never saw that yet).
So, i would say an "AIAirport.GetAirportTypeList" should goes first. Until this exist, it means the list as an enum because wrote in stone rock, and so are the airport properties.
As this is suggestion, i would prefer getting the numerical value of current rating in town instead of "poor...". This will allow us to know before doing an action the cost to the town rating http://wiki.openttd.org/Game_mechanics# ... ity_rating
like removing a tree (cost 35) may put you from mediocre (200) down to mediocre (165) or from mediocre (10) down to poor (-25)
So, i would say an "AIAirport.GetAirportTypeList" should goes first. Until this exist, it means the list as an enum because wrote in stone rock, and so are the airport properties.
As this is suggestion, i would prefer getting the numerical value of current rating in town instead of "poor...". This will allow us to know before doing an action the cost to the town rating http://wiki.openttd.org/Game_mechanics# ... ity_rating
like removing a tree (cost 35) may put you from mediocre (200) down to mediocre (165) or from mediocre (10) down to poor (-25)
Re: Some API extension ideas
This one is completely hidden from player, so it may be intentionally obscured information.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Some API extension ideas
You may want to look for my AI airport API extension patch queue. I dont remember if it is just a forum thread or an fs task. It does split Airport and AirportType apart an address small/large planes etc in preparation for NewGRF airports. I remember that I had it difficult to implement a method to get number of aircraft in holding.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Some API extension ideas
Since the inclusion of cargo distribution in trunk an AI should have a way to determine where the cargo wants to go. As far as I can see that's not available in AIStation.
Re: Some API extension ideas
GSTile::GetClosestIndustry()
Return the ID of the industry.
Otherwise, are there any functions or existing libraries that can do this? I had a look around but could find nothing (or nothing simple). I did find what I think are these same functions in the OpenTTD source docs so maybe its simple to implement?
I'm trying to use these features in a GS that builds industries based on some limitations, like max per town, or min distance from town/other industry
While I'm at it what would also be great is to get a grid of the town size, say:
GSTown::GetTownSize()
Returning a grid of the min and max x and y coords of town buildings.
Both these would be great for NoAI also, like for trains pathfinding.
Return the ID of the industry.
Otherwise, are there any functions or existing libraries that can do this? I had a look around but could find nothing (or nothing simple). I did find what I think are these same functions in the OpenTTD source docs so maybe its simple to implement?
I'm trying to use these features in a GS that builds industries based on some limitations, like max per town, or min distance from town/other industry

While I'm at it what would also be great is to get a grid of the town size, say:
GSTown::GetTownSize()
Returning a grid of the min and max x and y coords of town buildings.
Both these would be great for NoAI also, like for trains pathfinding.
Re: Some API extension ideas
Code: Select all
GetClosestIndustry(Tile) {
local indu = AIIndustryList();
indu.Valuate(AIIndustry.GetDistanceManhattanToTile, Tile);
indu.Sort(AIList.SORT_BY_VALUE, AIList.SORT_ASCENDING);
return indu.Begin(); }
Re: Some API extension ideas
Ahh of course, didn't understand the Valuate function so well so guess I overlooked it...Thanks! That flicked another lightbulb for me and the API
Also I did now find a .GetTownTiles() function in Superlib, but it uses an estimate:
Maybe a loop function for each house might be too slow...

Also I did now find a .GetTownTiles() function in Superlib, but it uses an estimate:
Code: Select all
local radius = 20 + _SuperLib_Helper.Max(0, GSTown.GetPopulation(town_id) / 1000);
Maybe a loop function for each house might be too slow...
Re: Some API extension ideas
Hi,
finding house tiles is tricky.
I wrote a function for you which returns all tiles which produce mail. In a game without newGRFs this are only house tiles. But don't use this function to often because it is really very slow.
To get the max./ min. X and Y coordinate of a town you can do this for example:
finding house tiles is tricky.
I wrote a function for you which returns all tiles which produce mail. In a game without newGRFs this are only house tiles. But don't use this function to often because it is really very slow.
Code: Select all
function HouseList(town){
local mailID=2;//CargoId for mail
local tiles=AITileList();
if (!AITown.IsValidTown(town))return tiles;
local location=AITown.GetLocation(town);
local townX=AIMap.GetTileX(location);
local townY=AIMap.GetTileY(location);
local maxSize=25+(AITown.GetHouseCount(town)/20).tointeger();//to limit the tiles we need to check
local from=AIMap.GetTileIndex(((townX<=maxSize)?1:townX-maxSize),((townY<=maxSize)?1:townY-maxSize));
local to=AIMap.GetTileIndex(((townX+maxSize>=AIMap.GetMapSizeX()-2)?AIMap.GetMapSizeX()-2:townX+maxSize),((townY+maxSize>=AIMap.GetMapSizeY()-2)?AIMap.GetMapSizeY()-2:townY+maxSize));
tiles.AddRectangle(from,to);
tiles.Valuate(AITile.GetClosestTown);
tiles.KeepValue(town);
tiles.Valuate(AITile.GetCargoProduction,mailID,1,1,0);
tiles.RemoveValue(0);
return tiles;
}
To get the max./ min. X and Y coordinate of a town you can do this for example:
Code: Select all
local houseList=AIList();
houseList.AddList(HouseList(town));
local xmax=-1;
local xmin=-1;
local ymax=-1;
local ymin=-1;
if(!houseList.IsEmpty()){
houseList.Valuate(AIMap.GetTileX);
houseList.Sort(AIAbstractList.SORT_BY_VALUE, false);
xmax=houseList.Begin();
houseList.Sort(AIAbstractList.SORT_BY_VALUE, true);
xmin=houseList.Begin();
houseList.Valuate(AIMap.GetTileY);
houseList.Sort(AIAbstractList.SORT_BY_VALUE, false);
ymax=houseList.Begin();
houseList.Sort(AIAbstractList.SORT_BY_VALUE, true);
ymin=houseList.Begin();
}
Re: Some API extension ideas
Many thanks for the code
I've been using your great RoadrunnerAI as a reference to see how some squirrel things work, not many comments though
My current shot at this function uses the minchin.metalib spiral walker to start at town centre, then loop for 0 to AITown.GetHouseCount(Town), putting every tile with AITile.GetTownAuthority(Town) into a list. I got stuck though at sorting the lists...also not sure if AITile.GetTownAuthority(Tile) is only true for town buildings of if I need to skip for AITile.IsRoad(Tile). I am trying to keep NewGrf ability as I use TTRS and a few others.
I think this would be a quick and solid approach if there was AITile.IsHouse or AITile.IsIndustry in a similar function for industries.
But thanks again, I will give it a try


My current shot at this function uses the minchin.metalib spiral walker to start at town centre, then loop for 0 to AITown.GetHouseCount(Town), putting every tile with AITile.GetTownAuthority(Town) into a list. I got stuck though at sorting the lists...also not sure if AITile.GetTownAuthority(Tile) is only true for town buildings of if I need to skip for AITile.IsRoad(Tile). I am trying to keep NewGrf ability as I use TTRS and a few others.
I think this would be a quick and solid approach if there was AITile.IsHouse or AITile.IsIndustry in a similar function for industries.
But thanks again, I will give it a try

Who is online
Users browsing this forum: No registered users and 26 guests