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

Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: Some API extension ideas

Post by Attila7 »

Perhaps we could have the routine return the refit capacity for road vehicles, ships and planes, but not trains. These are the vehicle types that need this most and for these types the return values should be accurate, no?
Attila
"Artificial intelligence is no match for natural stupidity."
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: Some API extension ideas

Post by Attila7 »

I just got to the point in my AI where it started to transport goods to a town. At some point a message popped up that said the station no longer accepts goods and my trucks would run around without unloading.

It would be very useful to get an Event for this that the AI can detect.
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 »

are you ever going to release this AI of yours? it sounds really good :wink:
</offtopic>
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 »

I don't know. The problem with the notification about station's acceptance changes is that industries with stockpiling trigger them every few days. I.e. when stockpile is filled and somewhat emptied again.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: Some API extension ideas

Post by Attila7 »

So, how do you propose to handle the detection of the situation?
Attila
"Artificial intelligence is no match for natural stupidity."
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: Some API extension ideas

Post by svetovoi »

You may just check AITile.GetCargoAcceptance(..., cargo_id, ...) for station tiles from time to time, and when it is < 8 for all tiles => station do not accept cargo_id anymore.
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: Some API extension ideas

Post by Attila7 »

I realize that, but what would take the game engine running in C++ a few instructions to do (as it is already doing the work of detection and popping up the message), the AI will have to also do - on every station/cargo combination. This will surely use more resources than just checking the event queue.
Attila
"Artificial intelligence is no match for natural stupidity."
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 »

If it was possible to get these value...
Attachments
Unnamed, 5th Oct 1998.png
Unnamed, 5th Oct 1998.png (38.43 KiB) Viewed 6837 times
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
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 »

just a thought and entirely non-essential, perhaps make AIDate.GetMonth() and AIDate.GetDayOfMonth() always return 2 digits, eg: 01, 02 ...10...31 etc
just a thought to make my debug output look neater :D

------Others-not-yet-talked-about-------
Lord Aro wrote:Request: GetNextNearestTown()

for finding the nearest town to town_a (or whatever)
Lord Aro wrote: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)
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 »

Lord Aro wrote:just a thought and entirely non-essential, perhaps make AIDate.GetMonth() and AIDate.GetDayOfMonth() always return 2 digits, eg: 01, 02 ...10...31 etc
just a thought to make my debug output look neater :D
GetMonth() and GetDayOfMonth() return integers, not strings.
Lord Aro wrote:Request: GetNextNearestTown()
There already is AITile::GetClosestTown
Lord Aro wrote: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)
I see no reason to implement this.
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:
Lord Aro wrote:just a thought and entirely non-essential, perhaps make AIDate.GetMonth() and AIDate.GetDayOfMonth() always return 2 digits, eg: 01, 02 ...10...31 etc
just a thought to make my debug output look neater :D
GetMonth() and GetDayOfMonth() return integers, not strings.
damn
Yexo wrote:
Lord Aro wrote:Request: GetNextNearestTown()
There already is AITile::GetClosestTown
but in the circumstances described (vaguely) above, that would just return town_a
Yexo wrote:
Lord Aro wrote: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)
I see no reason to implement this.
oh go on... you know you want to... :lol: why not? it would be a better version than AIController.GetVersion() (if you ask me, but i concentrate on the aesthetics of the debug output too much)

more:
AICompany.[Get/Set]CompanyColour();
AICompany.IsSecondCompanyColourUsed();
AICompany.[Get/Set]SecondCompanyColour();

AICompany.[Get/Set]PresidentFace(*company-id*, *newgrf-style-input*); (if you get what i mean, like what is stored in openttd.cfg)

Like i said, i concentrate to the looks of my AI far too much... :lol:
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
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 »

Lord Aro wrote:
Yexo wrote:
Lord Aro wrote: just a thought and entirely non-essential, perhaps make AIDate.GetMonth() and AIDate.GetDayOfMonth() always return 2 digits, eg: 01, 02 ...10...31 etc
just a thought to make my debug output look neater :D
GetMonth() and GetDayOfMonth() return integers, not strings.
damn
Hey.. you could use AILibrary - String that handle Date function.

->

Code: Select all

import("AILib.String",  1, "CLString");
CLString.Date(date, date_format, separator) ;

/*
    Convert date to it string representation

    Parameters:

        date
            Date integer to convert
        date_format
             One of DateStr Format  :
                  DateYMD  = Year - Month - Day
                  DateMDY  = Month - Day - Year
                  DateDMY  = Day - Month Year
       separator
              separator for each section. eg, 12.10.12 or 31/12/10
    Returns:
        string of date 
*/
Want to take only a part ?
use CLString.Split to split the date based on separator.
look more : here
Correct me If I am wrong - PM me if my English was bad :D

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

Re: Some API extension ideas

Post by Brumi »

I think if there are notifications for new industries being founded, there should be some AIEventTownFounded as well. And I think this should be available as a news item for players as well...

EDIT: Sorry for being a bit off-topic, I don't want to open a new topic for this: What is the difference between AIAbstractList::SetValue() and AIList::ChangeItem(), apart from the return value?
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 »

Brumi wrote:EDIT: Sorry for being a bit off-topic, I don't want to open a new topic for this: What is the difference between AIAbstractList::SetValue() and AIList::ChangeItem(), apart from the return value?
Well, I don't think there would be a different, since AIList::ChangeItem() call AIAbstractList::SetValue() in it implementation, except that AIList::ChangeItem() doesn't return the return value

Code: Select all

void AIList::ChangeItem(int32 item, int32 value)
{
   this->SetValue(item, value);
}
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

What about GetRailTypeName(RailType rail_type)?
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 »

And bool AIInfo::UseAsReplacementAI (like bool AIInfo::UseAsRandomAI ) - to fix problems like this: http://www.tt-forums.net/viewtopic.php?p=913027#p913027
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Hephi
Engineer
Engineer
Posts: 72
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: Some API extension ideas

Post by Hephi »

Not really an extension but a very small change to the api doc

for AIEngine.GetWeight()
Get the weight of an engine.


Is this always unloaded or does it change when the load of the wagon changes?
I know it returns the empty weight when going over the engine_list and that is what counts for me
but the API doc doesn't elaborate on this.


edit:
removed another question
Last edited by Hephi on 28 Nov 2010 20:31, edited 2 times in total.
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

The argument is an EngineID, which cannot refer to a specific vehicle, only to a vehicle type (=engine type). As such it's always the empty weight.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

I lost track in this topic. It would be very much appreciated if someone could make a list of suggestions that haven't been rejected yet so I can take a look at them and implement some.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

GetRailTypeName(RailType rail_type)

TownEffectCargoDeliveredToCity(AICargo::TownEffect, town_id) //water, food available for player and tracked by openttd so it can be: WaterCargoDeliveredToCity, FoodCargoDeliveredToCity

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

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests