Page 7 of 16

Re: Some API extension ideas

Posted: 24 Dec 2009 15:34
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

Re: Some API extension ideas

Posted: 28 Dec 2009 14:55
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.

Re: Some API extension ideas

Posted: 29 Jan 2010 21:50
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)

Re: Some API extension ideas

Posted: 30 Jan 2010 01:13
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.

Re: Some API extension ideas

Posted: 30 Jan 2010 08:23
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

Re: Some API extension ideas

Posted: 31 Jan 2010 15:11
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?

Re: Some API extension ideas

Posted: 31 Jan 2010 15:17
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.

Re: Some API extension ideas

Posted: 31 Jan 2010 19:33
by Timmaexx
lol, i thought the command 'print' sends the log to my epson sx100 :mrgreen:

Re: Some API extension ideas

Posted: 01 Feb 2010 01:17
by Zutty
We could do this ourselves if we were still allowed to call getroottable(). Why was that taken away?

Re: Some API extension ideas

Posted: 02 Feb 2010 12:58
by Blustuff
Yexo wrote:Just giving a status update:
Excellent !

Re: Some API extension ideas

Posted: 20 Feb 2010 14:27
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)

Re: Some API extension ideas

Posted: 20 Feb 2010 15:25
by Blustuff
Yexo, did you look for a solution about vehicles which can handle several cargos at the same time ?

Re: Some API extension ideas

Posted: 07 Mar 2010 22:40
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.

Re: Some API extension ideas

Posted: 13 Mar 2010 07:31
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)

Re: Some API extension ideas

Posted: 13 Mar 2010 07:52
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

Re: Some API extension ideas

Posted: 13 Mar 2010 08:30
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.

Re: Some API extension ideas

Posted: 13 Mar 2010 08:38
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.

Re: Some API extension ideas

Posted: 13 Mar 2010 08:47
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.

Re: Some API extension ideas

Posted: 13 Mar 2010 10:29
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.

Re: Some API extension ideas

Posted: 14 Mar 2010 22:02
by Kogut
Something more important:
There is already AIIndustry.GetStockpiledCargo() but for ECS it is useless without AIIndustry.GetMaxStockpileSize().