Some API extension ideas

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

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

Re: Some API extension ideas

Post by Yexo »

Blustuff wrote:As stated in the wiki an AI should be parametrized to not compete with other players.
Please not that that wiki page is almost completely written by Bilbo. While I think the points on that page are valid, nobody will force you to implement any of them in case you don't agree. It are just some guidelines.
Shouldn't it be with other human players ? In this case, I didn't find API calls which can tell if a company is owned by a human player or by an AI. This would be another low priority request.
Noted, but I'm not sure we'll implemented it.
Blustuff
Engineer
Engineer
Posts: 112
Joined: 21 Aug 2008 09:37
Location: France

Re: Some API extension ideas

Post by Blustuff »

Yexo wrote:nobody will force you to implement any of them in case you don't agree
I don't feel like someone forces me to implement these guidelines ! But they sounds valid to me as well so I have thought about how to follow them.
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: Some API extension ideas

Post by Xander »

Although it's no biggy, getting the exact subsidy multiplier would be nice. At the moment all I can pull is the index value so "3" = "x4" and 0 = "x1.5".

Cheers :)
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
Dezmond_snz
Engineer
Engineer
Posts: 58
Joined: 19 Apr 2009 11:50

Re: Some API extension ideas

Post by Dezmond_snz »

My suggestions is simple, i hope...

Add enumeration like

Code: Select all

AIRoad::RoadDirection{
 ROADDIR_NW = 0x01,
 ROADDIR_NE = 0x02,
 ROADDIR_SW = 0x04,
 ROADDIR_SE = 0x08
}
And some functions to use with it:

Code: Select all

/* Returns direction or road tile or 0 if no road here. */
static RoadDirection AIRoad::GetRoadDirection(TileIndex tile);
/* Builds a road part in specified tile. */
static bool AIRoad::BuildRoad(TileIndex tile, RoadDirection dir);
/* Removes a road part in specified tile. */
static bool AIRoad::RemoveRoad(TileIndex tile, RoadDirection dir);
My AI want to build roads like this:
Great Henthill Transport, 1950-03-03.png
Great Henthill Transport, 1950-03-03.png (29.24 KiB) Viewed 4394 times
Thanks.
Russia
Chruker
Engineer
Engineer
Posts: 49
Joined: 01 Jun 2009 20:13

Re: Some API extension ideas

Post by Chruker »

Dezmond_snz wrote:My suggestions is simple, i hope...

Add enumeration like

Code: Select all

AIRoad::RoadDirection{
 ROADDIR_NW = 0x01,
 ROADDIR_NE = 0x02,
 ROADDIR_SW = 0x04,
 ROADDIR_SE = 0x08
}
And some functions to use with it:

Code: Select all

/* Returns direction or road tile or 0 if no road here. */
static RoadDirection AIRoad::GetRoadDirection(TileIndex tile);
/* Builds a road part in specified tile. */
static bool AIRoad::BuildRoad(TileIndex tile, RoadDirection dir);
/* Removes a road part in specified tile. */
static bool AIRoad::RemoveRoad(TileIndex tile, RoadDirection dir);
I also miss those.
Dezmond_snz
Engineer
Engineer
Posts: 58
Joined: 19 Apr 2009 11:50

Re: Some API extension ideas

Post by Dezmond_snz »

Also useful will be
AIEngine.GetRefitCost(EngineID engine, CargoID cargo);
Russia
Blustuff
Engineer
Engineer
Posts: 112
Joined: 21 Aug 2008 09:37
Location: France

Re: Some API extension ideas

Post by Blustuff »

Dezmond_snz wrote:Also useful will be
AIEngine.GetRefitCost(EngineID engine, CargoID cargo);
This is in my list of *::GetCost() on the second page : http://www.tt-forums.net/viewtopic.php? ... 20#p806073
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Some API extension ideas

Post by frosch »

AIEngine with refitting is troublesome for three reasons:

1. It is not visible to a human player.
2. It is currently not supported by newgrfs to return that information.

Though those two points are on my TODO list, there is a long way to go (at least with my stepsize :o ).

3. It adds a lot of complexity: Next request will be: Capacity after refit. Capacity after multiple refits (not all parts might be refittable to the same cargo). Weight after refit. Length after refit. Basically everything after refit...
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: Some API extension ideas

Post by Xander »

The refit cost itself might not be explicitly available but what's stopping the AI (or the API) doing the neccessary calculations? We can lift current value and subtract it from DesiredEngine.GetPrice to get total refit cost. You can do similar for the carriages.

So something like CompareEngine(sourceVehicle, desiredEngine, comparisonitem) which would return the difference. Maybe something for the Shared Library? :)
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Some API extension ideas

Post by Zutty »

frosch wrote:Capacity after refit.
I must admit complete ignorance as far as NewGRFs work. Is it not possible to get this as is appears in the UI...
refit.png
refit.png (17.6 KiB) Viewed 4250 times
Or is this done with strings?
PathZilla - A networking AI - Now with tram support.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Some API extension ideas

Post by Rubidium »

Zutty wrote:
frosch wrote:Capacity after refit.
I must admit complete ignorance as far as NewGRFs work. Is it not possible to get this as is appears in the UI...
You have a vehicle in that case, the case where frosch talks about is without having a vehicle.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Some API extension ideas

Post by Zutty »

Rubidium wrote:
Zutty wrote:
frosch wrote:Capacity after refit.
I must admit complete ignorance as far as NewGRFs work. Is it not possible to get this as is appears in the UI...
You have a vehicle in that case, the case where frosch talks about is without having a vehicle.
Oh I see.
PathZilla - A networking AI - Now with tram support.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Some API extension ideas

Post by frosch »

... and AIVehicle::GetRefitCapacity() is already present.

AIEngine::GetRefitCapacity/Cost would be more like showing those values in the purchase list e.g. after selecting a cargo in the cargo-filter-dropdown. But as I said: A lot articulated vehicle sets will fail to supply the correct values currently, as they already use quite some trickery to work around other problems :)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Dezmond_snz
Engineer
Engineer
Posts: 58
Joined: 19 Apr 2009 11:50

Re: Some API extension ideas

Post by Dezmond_snz »

Oh, no!
Sorry if there are already signed it, but somehow i can't find function to see if cargo accepted at specified station... :(

Code: Select all

static bool AIStation::IsCargoAccepted(StationID, CargoID);
Or may be make func to get list of cargos accepted:

Code: Select all

static ALCargoList AIStation::GetAcceptedCargos(StationID);
?
Russia
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Some API extension ideas

Post by fanioz »

But, we can get tilelist of station-id. And check their cargo acceptance. Isn't? :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Dezmond_snz
Engineer
Engineer
Posts: 58
Joined: 19 Apr 2009 11:50

Re: Some API extension ideas

Post by Dezmond_snz »

fanioz wrote:But, we can get tilelist of station-id. And check their cargo acceptance. Isn't? :D
Well. That's it. But sometimes this way shows that cargoX and cargoY are accepted by tile and in station info window i see cargoX isn't accepted when cargoY is... (firstly spotted this with FIRS r187)
Russia
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: Some API extension ideas

Post by Xander »

[offtopic]
fanioz wrote:... acceptance. Isn't? :D
I lol'd.

The word you were going for is, in fact, "acceptance, innit?". But, seriously, huge points from me for that. Great way to start my thursday :)
[/offtopic]
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Some API extension ideas

Post by Dustin »

Dezmond_snz wrote:Oh, no!
Sorry if there are already signed it, but somehow i can't find function to see if cargo accepted at specified station... :(

Code: Select all

static bool AIStation::IsCargoAccepted(StationID, CargoID);
Or may be make func to get list of cargos accepted:

Code: Select all

static ALCargoList AIStation::GetAcceptedCargos(StationID);
?

Code: Select all



function GetIndustryProducesAIList(industryIndex)
{

    local industryType = AIIndustry.GetIndustryType(industryIndex);
    local produces = AIIndustryType.GetProducedCargo(industryType);
    return produces;
}


function GetIndustryAcceptsAIList(industryIndex)
{
    local industryType = AIIndustry.GetIndustryType(industryIndex);
    local accepts = AIIndustryType.GetAcceptedCargo(industryType);
    return accepts;
}
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

Dustin wrote:

Code: Select all

function GetIndustryProducesAIList(industryIndex)

function GetIndustryAcceptsAIList(industryIndex)
Do not use those functions!

The api already has working versions for what you want to code: AICargoList_IndustryAccepting / AICargoList_IndustryProducing. Your version might work for the default industries, but it can (and will) break with newgrf industry sets.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Some API extension ideas

Post by Dustin »

Yexo wrote:
Dustin wrote:

Code: Select all

function GetIndustryProducesAIList(industryIndex)

function GetIndustryAcceptsAIList(industryIndex)
Do not use those functions!

The api already has working versions for what you want to code: AICargoList_IndustryAccepting / AICargoList_IndustryProducing. Your version might work for the default industries, but it can (and will) break with newgrf industry sets.

Really good to know. Thanks.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 34 guests