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 »

That is documented already on the AI changelog page for quite some time:
http://noai.openttd.org/docs/trunk/ai__changelog_8hpp.html wrote:1.1.0

API removals:
* HasNext for all lists.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: Some API extension ideas

Post by Michiel »

Is the 0.7.5 API compatibility being phased out? Guess I'll bite the bullet and update to 1.0 for the next release.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Some API extension ideas

Post by Lord Aro »

Yexo wrote:That is documented already on the AI changelog page for quite some time:
http://noai.openttd.org/docs/trunk/ai__changelog_8hpp.html wrote:1.1.0

API removals:
* HasNext for all lists.
and the point i was asking was that it didn't work back then... :rolleyes:
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

Michiel wrote:Is the 0.7.5 API compatibility being phased out? Guess I'll bite the bullet and update to 1.0 for the next release.
Eventually it'll be, but if it's not too much work we'll try and keep it working for some time.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

Kogut wrote:- AIVehicle.GetWeight(vehicle_id)
and AIEngine.GetWeightOfFullyLoaded(engine_id)
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: Some API extension ideas

Post by Kogut »

There is

Code: Select all

AIMap::DistanceMax  	( TileIndex tile_from, TileIndex tile_to)
But there is not:

Code: Select all

AIMap::DistanceMin  	( TileIndex tile_from, TileIndex tile_to)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Steffl
Engineer
Engineer
Posts: 103
Joined: 23 Feb 2010 15:44

Re: Some API extension ideas

Post by Steffl »

I have a question to the problem with HasNext() <> IsEnd():

Does the following code work right with all versions? It's using IsEnd() when the version is 1.1 or higher.

function hasnext(list) {
if (::major>1||(::major>0&&::minor>0))return !list.IsEnd();
return list.HasNext();
}

I want to call it with hasnext(list) instead of list.hasnext(). Maybe some experts have better solutions for this, but it is ok when it work as it should.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

Just make sure your info.nut GetAPIVersion returns "1.0" and always use HasNext(). That is by far the easiest solution. Otherwise your code looks ok.
Steffl
Engineer
Engineer
Posts: 103
Joined: 23 Feb 2010 15:44

Re: Some API extension ideas

Post by Steffl »

Thanks for your answer Yexo.
I don't really understand what you mean when you say that I should always use HasNext() when GetAPIVersion returns 1.0.

I think this is the same as it was before. The problem is that GetAPIVersion not returns 1.0 in the newer OpenTTD versions and what you have to do then. I think you always have to decide between HasNext() and IsEnd() if you want to keep compatibility to all OpenTTD versions.
But when you say my code looks ok, I think I let it, as it is.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Some API extension ideas

Post by planetmaker »

Steffl wrote:Thanks for your answer Yexo.
I don't really understand what you mean when you say that I should always use HasNext() when GetAPIVersion returns 1.0.

I think this is the same as it was before. The problem is that GetAPIVersion not returns 1.0 in the newer OpenTTD versions and what you have to do then. I think you always have to decide between HasNext() and IsEnd() if you want to keep compatibility to all OpenTTD versions.
But when you say my code looks ok, I think I let it, as it is.
You don't really have to support the 0.7 API anymore. The VAST majority of players uses 1.0.0 or better meanwhile.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Some API extension ideas

Post by Rubidium »

Steffl wrote:I don't really understand what you mean when you say that I should always use HasNext() when GetAPIVersion returns 1.0.
When you return 1.0 for GetAPIVersion HasNext will work, however if you do so in a recent trunk version then IsEnd will work as well. This means that under trunk while returning 1.0 for GetAPIVersion you can technically use both, however when the AI is ran under 1.0 it will not be having IsEnd and as such not work.
So, when you return 1.0 for GetAPIVersion you must not use IsEnd and always use HasNext, which is what Yexo wanted to get across.
Steffl
Engineer
Engineer
Posts: 103
Joined: 23 Feb 2010 15:44

Re: Some API extension ideas

Post by Steffl »

Ahhh, sorry I think it's my fault that we talked in different directions. :-)
I don't have described what I mean with ::major and ::minor.
They are the major and minor version number from AIController.GetVersion(), not from AIInfo.GetAPIVersion ().

My question is:
If OpenTTD version is 1.1 our higher, you have always to use IsEnd(), on older versions you can/have to use HasNext()? Like I did in the code below.
Thanks for your help.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

In 1.1 API HasNext is removed. Fortunatelly special script transform HasNext function in 1.0 API AIs to IsEnd.
In other words:
1.1 API, 1.1 API declared: IsEnd()
1.1 API, 1.0 API declared: HasNext() (I see that it is NOT working)
1.0 API (or lower): HasNext ()
======
Yet Another Request: AIRail.GetRailwayTypeName(railway_type)
======
@Yexo (and maybe others?) Thanks for developing NoAI API!
======
Kogut wrote:I tried to use AIRail::BuildNewGRFRailStation ( http://noai.openttd.org/api/0.7.3/class ... 2262c8b42f ).

But I see:
IndustryType source_industry,
IndustryType goal_industry
What with industry to town / town to town routes?
frosch wrote:Towns are 0xFF.
Seems like there is no enumeration for that :)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Some API extension ideas

Post by Lord Aro »

Request:
AIController::GetWindowDisplayVersion()
or something similar or, modify the existing AIController::GetVersion()
to display whatever is displayed in the toolbar at the top of the screen (see pic)
Attachments
untitled.gif
untitled.gif (5.54 KiB) Viewed 5781 times
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Some API extension ideas

Post by frosch »

Kogut wrote:I tried to use AIRail::BuildNewGRFRailStation ( http://noai.openttd.org/api/0.7.3/class ... 2262c8b42f ).

But I see:
IndustryType source_industry,
IndustryType goal_industry
What with industry to town / town to town routes?
frosch wrote:Towns are 0xFF.
Seems like there is no enumeration for that :)
r20108 adds AIIndustryType::INDUSTRYTYPE_TOWN and AIIndustryType::INDUSTRYTYPE_UNKNOWN which can be passed to AIRail::BuildNewGRFRailStation for towns resp. if there is no specific industrytype (e.g. multiple industries).

Also note that the API now checks the passed industrytype for validity (previously it just passed the stuff on to the grf). So check your AIs whether they still work :)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

Great!
Yet Another Request: AIRail.GetRailwayTypeName(railway_type)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: Some API extension ideas

Post by Attila7 »

Can we get a function that returns the station id or the station tile of the cargo origin?
Something like TileIndex AIVehicle.GetCargoOrigin(VehicleID,CargoID)

We have this information displayed for buses carrying passengers. I want to know if my fleet of buses on their way to a station have enough capacity to take the cargo. The problem is when vehicles are already at the station, I can't tell if the load they are carrying is to be unloaded or picked up already.

Alternately, a function that returns the state of a vehicle in more detail may be of use:

ie: Instead of just being at a station, break it down to Loading/Unloading
Attila
"Artificial intelligence is no match for natural stupidity."
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Some API extension ideas

Post by Lord Aro »

Request: GetNextNearestTown()

for finding the nearest town to town_a (or whatever)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: Some API extension ideas

Post by Attila7 »

Is there a reason why we have AIVehicle.GetRefitCapacity, but we don't have AIEngine.GetRefitCapacity?

I want to make a decision about which engine to buy, but can't tell how much cargo I will be able to carry without actually buying the vehicle.
Attila
"Artificial intelligence is no match for natural stupidity."
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Some API extension ideas

Post by Rubidium »

Attila7 wrote:Is there a reason why we have AIVehicle.GetRefitCapacity, but we don't have AIEngine.GetRefitCapacity?
Yes... OpenTTD has no way of knowing the refit capacity of an "engine" as it can only execute the refit callback on actual vehicles. As such OpenTTD would need to build the vehicle before it can test it... but wait... there is more... the (refit) capacity of a part of a vehicle (wagon, engine) can depend on other parts within the same consist and that effectively makes AIEngine.GetRefitCapacity useless as you won't be getting the right numbers.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 29 guests