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

Post Reply
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 »

I would like to request (again).
AIVehicle::
-GetRailType
-GetPlaneType
Reason: can't getting these through AIEngine, when the engine is no longer buildable.
:D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Some API extension ideas

Post by Zuu »

fanioz wrote:I would like to request (again).
AIVehicle::
-GetRailType
-GetPlaneType
Reason: can't getting these through AIEngine, when the engine is no longer buildable.
:D
I need that as well (plane type). I'm not sure if there are more things that are only available in the engine that you would want to check after the engine has disappeared. Maybe it is a better solution to make all engines valid always (or at least after they are no longer buildable) and then have a separate check function for if the engine can be built or not.

It would be very nice if we could get away with this message from the API doc
API doc wrote:AIGameSettings::IsValid and AIGameSettings::GetValue are functions that rely on the settings as OpenTTD stores them in savegame and openttd.cfg. No guarantees can be given on the long term validity, consistency and stability of the names, values and value ranges. Using these settings can be dangerous and could cause issues in future versions. To make sure that a setting still exists in the current version you have to run AIGameSettings::IsValid before accessing it.
Some kind of promised compatibility layer would be awesome. This would mean that you can more extensively check for settings without the fear of them changing in future.

I would be happy to see the possibility to supply vehicle types to eg. AIVehicleList_Station to have that filtered already. If that is added it should probably also be added to the other AIVehicleList_*. I notice that there is no AIVehicleList_Waypoint while there is a AIWaypointList_Vehicle (corresponding to the AIStationList_Vehicle).

I would love to see (but I think these things do not need to make any particular stable version since it is enough to have them on the version used by AI-developers):
  • Make some AI settings configurable in-game (eg. place debug signs) - faster than having to traverse a long list of signs for "enable_signs" every time you want to place/update a sign
  • In the AI Debug window, add a text box where you can input a break string. Each AILog message is matched against this break string and if there is a match, the game pauses. (just simply check if the typed string is a sub string of the log string)
I might myself put aside some time on these two last things. Especially the later one which seams not to hard to do.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

Just giving a status update:
Yexo wrote:[*]AIVehicle::ChangeServicingInterval
Needs some more fundamental changes to the servicing system, will probably have to wait until after 1.0
[*]Check vehicles/stations belonging to other companies (FS#2776) - not planned for 0.8
=> not planned for 1.0
[*]Load latest version of AI that can load the data, don't load exact same version first. (FS#3232)
Implemented
[*]Keep is-random-ai flag when an AI is started, so don't start the same AI every time for a random slot. (FS#3095)
Implemented
[*]AIGameSettings::GetBaseCost(price_index) with a list of valid price indexes.
Work in progress, expect this soon
fanioz wrote:request for AIEventVehicleHasVoidOrder.
Still thinking about this one.
fanioz wrote:I would like to request (again).
AIVehicle::
-GetRailType
-GetPlaneType
Reason: can't getting these through AIEngine, when the engine is no longer buildable.
Not implemented, but the AIEngine functions now work even if the engine is no longer buildable
Zuu wrote:I would be happy to see the possibility to supply vehicle types to eg. AIVehicleList_Station to have that filtered already. If that is added it should probably also be added to the other AIVehicleList_*. I notice that there is no AIVehicleList_Waypoint while there is a AIWaypointList_Vehicle (corresponding to the AIStationList_Vehicle).
AIVehicleList_Station also works for waypoints (in 1.0, not in 0.7).
[*] Make some AI settings configurable in-game (eg. place debug signs) - faster than having to traverse a long list of signs for "enable_signs" every time you want to place/update a sign
Implemented
[*] In the AI Debug window, add a text box where you can input a break string. Each AILog message is matched against this break string and if there is a match, the game pauses. (just simply check if the typed string is a sub string of the log string)
Patch by Zuu on flyspray.


To summarize:
Some function to query the cost of building various things will be added before 1.0 (edit: done in r18955)
Todo:
  • Break AI on specific string (patch done by Zuu)
  • ChangeServicingInterval (probably won't make 1.0)
  • Check vehicles/stations belonging to other companies (probably won't make 1.0)
  • AIEventVehicleHasVoidOrder (not sure if this is really needed)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Some API extension ideas

Post by Zuu »

Regarding my patch:

IIRC it works okay if you don't mind it finish the current tick before breaking the AI and pausing the game. So to be useful for debugging code you need to put a Sleep call after the print-statement that you are looking for. That means that you need to modify the AI source code in order to make good use of this patch.

To avoid bug reports and confusion I think it would be worth to invest a few hours to see how hard it would be to make it break the AI after the AILog call and then OpenTTD would continue to run to the end of the tick and will then pause. If it is very hard, then it might not just be worth it, but I think I/we should at least take a look.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
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 »

Yexo wrote:
fanioz wrote:request for AIEventVehicleHasVoidOrder.
Still thinking about this one.
........
AIEventVehicleHasVoidOrder (not sure if this is really needed)
Yup, this would be only an equal notifier for AI that human player had.
an AI writer could just check whether a destination order for each vehicles are still valid, instead of waiting an event triggered. So you're right.

However, thanks for another feature introduced. Great :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: Some API extension ideas

Post by Brumi »

I'd like to request a console command for printing the current variables of an AI, either to the console or the AI debug window. Or a command like 'crash_ai' to crash an AI manually :mrgreen: (those red lines in the AI debug window can be really useful). It could be useful if an AI gets into an infinte loop.
What do you think?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Some API extension ideas

Post by Zuu »

I think it is a good idea. I have though about it myself but haven't got around to ask for it or trying to implement it.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Timmaexx
Transport Coordinator
Transport Coordinator
Posts: 301
Joined: 03 Jan 2009 17:55

Re: Some API extension ideas

Post by Timmaexx »

lol, i thought the command 'print' sends the log to my epson sx100 :mrgreen:
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Some API extension ideas

Post by Zutty »

We could do this ourselves if we were still allowed to call getroottable(). Why was that taken away?
PathZilla - A networking AI - Now with tram support.
Blustuff
Engineer
Engineer
Posts: 112
Joined: 21 Aug 2008 09:37
Location: France

Re: Some API extension ideas

Post by Blustuff »

Yexo wrote:Just giving a status update:
Excellent !
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Some API extension ideas

Post by Zuu »

I know this is very late and may possible not be for 1.0 but later.

1) Get the annually maintenance cost of having transport mode at a station.
2) Get the build cost of stations/depots/waypoints
[edit]3) Get figures from the economy window for estimating how quick the company will earn X amount of money[/edit]

1. IIRC in 1950 you pay about 500 pounds a year for each transport mode available at a station. This I guess change by inflation and the base value could possible change in future and/or the way inflation works so it would be nice to have a function to access this cost.

2. Since there has been added functions to get the price of building road without having some flat land to test on perhaps functions for getting the building cost of stations road/rail/air etc. could be added as well?

[edit]3. When choosing if an AI should wait for money to buy something expansive it will help to know the maintenance cost and vehicle income. For vehicles an AI could obtain this by summing up the stats for each vehicle, but not for stations as station maintenance costs are not available to the AI unless the suggestion above is implemented.[/edit]


(I'm doing some work to get PAXLink to do some cost/benefit analysis of actions before spending all money on the first action and maybe even learning to save money for higher revenue investments)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Blustuff
Engineer
Engineer
Posts: 112
Joined: 21 Aug 2008 09:37
Location: France

Re: Some API extension ideas

Post by Blustuff »

Yexo, did you look for a solution about vehicles which can handle several cargos at the same time ?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Some API extension ideas

Post by Zuu »

  • AICompany.IsTownOwner(company_id) - So that you can determine if something is owned by a company or a town.
  • Either AIRoad.CanRemoveRoad[Full]Completely or make AIRoad.RemoveRoad[Full] return false unless the entire length of road can be removed. As a player you can see if a vehicle is in the way, but for AIs you would have to loop through all your vehicles and check if they match the list of tiles that will have the road removed. And even then, you can only check your own vehicles, not vehicles owned by other companies.
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: Some API extension ideas

Post by Kogut »

AIIndustry.IsStrangeIndustry(industry_type_id)
- is it industry interacting in weird way with environment - for example: tropical lumber mill
- that exclude stocpiling

- AIIndustry.WhatCargoIsNeededToProceedBeforeThatCargo(industry_type_id, cargo_id) (return - cargo list)
- for example ECS machine works require steel to proceed glass
- tourist centre require tourists to proceed goods

-AIIndustry.IsIndustrySuppliedWithCargo(industry_id, cargo_id)
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: Some API extension ideas

Post by Yexo »

Kogut wrote:AIIndustry.IsStrangeIndustry(industry_type_id)
- is it industry interacting in weird way with environment - for example: tropical lumber mill
- that exclude stocpiling
Openttd doesn't have that information for industries defined by newgrfs.
- AIIndustry.WhatCargoIsNeededToProceedBeforeThatCargo(industry_type_id, cargo_id) (return - cargo list)
- for example ECS machine works require steel to proceed glass
- tourist centre require tourists to proceed goods
Openttd doesn't have that information for industries defined by newgrfs.
-AIIndustry.IsIndustrySuppliedWithCargo(industry_id, cargo_id)
Is this information in any way available to human players? Other then by looking at their competitors vehicles? If not, then it's a duplicate of FS#2776
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

1) And it is impossible/very hard to do to "ask" newgrf about industry properties? And return it through noai api?
2) So is it possible to check for added newgrf?
Possible use - use ony PAX cargo when somebody added ECS vectors.
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: Some API extension ideas

Post by Yexo »

Kogut wrote:1) And it is impossible/very hard to do to "ask" newgrf about industry properties? And return it through noai api?
That is possible, but only if a newgrf supported that. Currently there is no way for a newgrf to provide that information, it'd need an extension of specs, and even then it wouldn't be complete in all cases.
2) So is it possible to check for added newgrf?
Then your AI wouldn't work if an updated grf had another grfid. This has been suggested and denied before.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

Is it possible to examine callbacks for "strange features"? //It may be very stupid question, I even don't know how callbacks work in openttd.
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 »

Another idea:
there is BuildNewGRFRailStation
is it possible to have BuildNewGRFTileWithWaitingCargo
or even BuildNewGRFTileWithBuilding?

use: extending station coverage using rail station in looking-like-no-cheat-and-stupid-exploit way.
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 »

Something more important:
There is already AIIndustry.GetStockpiledCargo() but for ECS it is useless without AIIndustry.GetMaxStockpileSize().
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: No registered users and 4 guests