NoAI Branch - An AI Framework

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

Locked
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: NoAI Branch - An AI Framework

Post by svetovoi »

Kilinich wrote: How can I get list of industries which accepts particular cargo?
You can check each industry with function like this one:

Code: Select all

function IsIndustryAcceptingParticularCargo(industry_id, cargo_id)
{
         local r = AIStation.GetCoverageRadius(AIStation.STATION_TRUCK_STOP);
         if(!AIIndustry.IsValidIndustry(industry_id))
                  return false;
         if(!AICargo.IsValidCargo(cargo_id))
                  return false;
         if(AITile.GetCargoAcceptance(AIIndustry.GetLocation(industry_id), cargo_id, 1, 1, r)>=8)
                  return true;
         return false;
}
And add to you own list if it returns true.
I think it's also possible to wtrite AIIndustryList valuator.
Kilinich wrote: I think we need some more:

new AIEngine class with functions like this:
char * GetEngineName (EngineID engine_id)
cargo_id GetEngineCargo (EngineID engine_id)
uint32 GetEngineCapacity (EngineID engine_id)
uint32 GetEngineReliability (EngineID engine_id)
uint32 GetEngineMaxSpeed (EngineID engine_id)
bool IsValidEngine (EngineID engine_id)
I wrote some (Get Cargo, Capacity, Speed) :D but have some problems with SVN :( (my linux machine will never has internet access, unfortunately I do not know how to make SVN work without it :oops: ) and so can not provide patch with theese functions :(
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Kilinich wrote:I think we need some more:

new AIEngine class with functions like this:
char * GetEngineName (EngineID engine_id)
cargo_id GetEngineCargo (EngineID engine_id)
uint32 GetEngineCapacity (EngineID engine_id)
uint32 GetEngineReliability (EngineID engine_id)
uint32 GetEngineMaxSpeed (EngineID engine_id)
bool IsValidEngine (EngineID engine_id)

add to AIIndustry class:
bool IsAcceptingCargo (IndustryID industru_id, CargoID cargo_id)

new valuator:
AIIndustryListAccept (CargoID cargo_id)
I believe they are all done now ;) The only thing remaining is a List(valuator) for the AIEngine things. Have fun with it ;)

[Edit]
The lists are done now too ;)
The only thing necessary for the triumph of evil is for good men to do nothing.
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

@TrueLight:
Could you please update the doxygen documentation? It's a bit exhausting to examine the new functions from the sourcecode :wink:
As you may presently yourself be fully made aware of, my grammar sucks
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

TrueLight wrote:
Kilinich wrote:I think we need some more:
Most of those functions are already handled via AIVehicle::FindBestVehicle. IsValidEngine is already in AIVehicle. Nevertheless, I see no problem in adding some more functions, and list-valuators, to allow easy finding the best engine.
bugs:
-----
AIIndustry.GetProdution() returns invalid data (production from 1st day of month i think).

need functions:
---------------
Current date !!!
Engine info - speed, capacity, reliability
Vehicle info - current speed, current state (loading/unloading, runing/stoped, broken)
Industries, that accept cargo (got workaround via AITile.GetCargoAcceptance)
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

ac84 wrote:
Kilinich wrote: How can I get list of industries which accepts particular cargo?
You can check each industry with function like this one:

Code: Select all

function IsIndustryAcceptingParticularCargo(industry_id, cargo_id)
{
         local r = AIStation.GetCoverageRadius(AIStation.STATION_TRUCK_STOP);
         if(!AIIndustry.IsValidIndustry(industry_id))
                  return false;
         if(!AICargo.IsValidCargo(cargo_id))
                  return false;
         if(AITile.GetCargoAcceptance(AIIndustry.GetLocation(industry_id), cargo_id, 1, 1, r)>=8)
                  return true;
         return false;
}
no need to use AIStation:

Code: Select all

      local list = AIIndustryList();
      for (local industry=list.Begin(); list.HasNext(); industry=list.Next()) {
        list.SetValue(industry,AITile.GetCargoAcceptance(Industries.GetLocation(industry),i,1,1,1));
      }
      list.KeepAboveValue(0);
but it return fake acceptance of mail/passangers if city is near
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Kilinich wrote: need functions:
---------------
Current date !!!
Engine info - speed, capacity, reliability
Vehicle info - current speed, current state (loading/unloading, runing/stoped, broken)
Industries, that accept cargo (got workaround via AITile.GetCargoAcceptance)
You really should read-up with the whole topic before replying.............

Anyway:

Current-date: how is this ever useful?
Engine-info: done
Vehicle-info: how is this useful?
Industries: done
The only thing necessary for the triumph of evil is for good men to do nothing.
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

TrueLight wrote: I believe they are all done now ;) The only thing remaining is a List(valuator) for the AIEngine things. Have fun with it ;)
The lists are done now too ;)
Thanks, i'll continue to dig it.
Is r11289-noai win32 binary with that changes?
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Kilinich wrote:
TrueLight wrote: I believe they are all done now ;) The only thing remaining is a List(valuator) for the AIEngine things. Have fun with it ;)
The lists are done now too ;)
Thanks, i'll continue to dig it.
Is r11289-noai win32 binary with that changes?
Sadly enough, it isn't. Tonight at 18:00 (2 hours before the trunk nightly) there will be a new binary available, which does include the latest changes.
The only thing necessary for the triumph of evil is for good men to do nothing.
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

You really should read-up with the whole topic before replying.............
Sure, i have some problem with inet, so i post message with big lag, sorry.
Current-date: how is this ever useful?
Engine-info: done
Vehicle-info: how is this useful?
Industries: done
If i don't know current date - why i need any "profit this year" function - it's useless.
Plus i want some real-time events in my script like annual review etc.
Vehicle info like current speed/state and location need for locate traffic jam.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Kilinich wrote: If i don't know current date - why i need any "profit this year" function - it's useless.
Plus i want some real-time events in my script like annual review etc.
Vehicle info like current speed/state and location need for locate traffic jam.
Hmm, good point about the first one yes. About the annual review, it might be better to do it once in the N ticks. This simply because AIs can run on different speeds. One that is running faster should, in my opinion, check things sooner than one that is running more slow. And I will add the last one to the TODO list too. Tnx for the feedback :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Nickman
Engineer
Engineer
Posts: 66
Joined: 27 Jun 2006 23:07

Re: NoAI Branch - An AI Framework

Post by Nickman »

Nice to see the NoAI branch alive again ;).
I havn't finished my AI because of lack of time but it sure was fun working with it ;).

Keep it up ;).
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: NoAI Branch - An AI Framework

Post by svetovoi »

Maybe AICargo should contain cargo enumeration... I mean CT_PASSENGERS, CT_MAIL, ..., etc
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: NoAI Branch - An AI Framework

Post by Rubidium »

What enumeration would tourists get, or potash, or clay, or ...? It's totally useless when used with NewGRFs.
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

TrueLight wrote: Hmm, good point about the first one yes. About the annual review, it might be better to do it once in the N ticks. This simply because AIs can run on different speeds. One that is running faster should, in my opinion, check things sooner than one that is running more slow. And I will add the last one to the TODO list too. Tnx for the feedback :)
Nono, once it N ticks means nothing - i want to alalyse period of operation and get some statistic to dig. By game design statistic is annual and it's easy to use it.
Another way current_date may come handy - calculate route-average speed of vehicle (or time to travel between stations) and recalculate optimal count of trucks on route.

p.s. And it simply better for people - know what time it is =)
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

Did anyone here try to create road pathfinder based on wave algorithm?
It seems like best solution for TTD world.
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: NoAI Branch - An AI Framework

Post by svetovoi »

Rubidium wrote:It's totally useless
Well, maybe :(
I mean when building a road station, AI need to "know" it's type (bus or truck)
As I understand it can be "known" by to ways:
  • 1.Always build one type of stations (not very interesting)
    2.Check what type of cargo it's going to transport
Not a big problem to use zero, but it's one more "magic number"
Also why not make NUM_CARGO accessible through AICargo? Very useful to organize loops.
About non passengers think you are right.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: NoAI Branch - An AI Framework

Post by Rubidium »

Ok, you've got no idea what I meant:
with NewGRFs you can define your own cargos/override the current cargos.

This means that I can override CT_PASSENGER to be potash and override CT_COAL to be passengers. Knowing that I said that the enum would be totally useless. I did not say that getting some information about the cargo would be useless. Adding a constant about the maximum number of loadable cargos is probably usefull. Then you can just use the current API to get information about the cargo; it has a function which tells you whether it's freight or not and you can get it's so-called cargo-label, which should be a unique 4-letter name for each cargo.
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: NoAI Branch - An AI Framework

Post by svetovoi »

Understand now. Thank you for explaining.
Leviath.NL
Traffic Manager
Traffic Manager
Posts: 152
Joined: 28 Jan 2006 15:00

Re: NoAI Branch - An AI Framework

Post by Leviath.NL »

I just had an funny idea, is it possible to make an AI that slowly connects all the towns of the map to each other? It does not build any vehicles and shouldn't be seen as an competitor.
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

If I remember right someone developed a pathfinder for road vehicles. This could be used to plan the path between two cities. Also I programmed a squirrel class that calculates a maximum Hamilton Circle. It would be easy to change it to calculate a minimum circle.
The only problem would be that the AI wouldn't have any income.
Of course you could cheat but at the moment you cannot automate this.
As you may presently yourself be fully made aware of, my grammar sucks
Locked

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests