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

Lowkee33
Engineer
Engineer
Posts: 20
Joined: 25 Nov 2011 20:49

Re: Some API extension ideas

Post by Lowkee33 »

It appears I do not have r23453, which brings up some noobie questions. What is r23453? I have 1.1.4. Should I be using trunk?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

See http://wiki.openttd.org/FAQ_OpenTTD_versions#Trunk. As for which version you should use; if you develop your AI for 1.1, keep using 1.1.4. If you develop your AI for 1.2 only, you can use trunk. Be advised however that the API for 1.2 is not stable until the first beta is released.

In any case: what this means is that these changes will be in the 1.2 release.
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: Some API extension ideas

Post by MinchinWeb »

Is it possible to download the documentation for the NoAI API? It used to be included when you downloaded the documentation for the whole of OpenTTD (at least as of v1.0.5), but is not longer included in the current nightlies.
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
11Runner
Engineer
Engineer
Posts: 92
Joined: 01 Sep 2011 19:23
Location: Oregon, USA

Re: Some API extension ideas

Post by 11Runner »

MinchinWeb wrote:Is it possible to download the documentation for the NoAI API? It used to be included when you downloaded the documentation for the whole of OpenTTD (at least as of v1.0.5), but is not longer included in the current nightlies.
I use HTTrack website copier. Wheather or not this is the direction you are going I have no idea
Image

SynTrans - A Synaptic Networking 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 »

I also (have used) the same software


A suggestion!

bool AIController::IsGoalScriptLoaded()
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
Core Xii
Traffic Manager
Traffic Manager
Posts: 228
Joined: 08 Apr 2008 09:47
Location: Finland

Re: Some API extension ideas

Post by Core Xii »

static int32 AITown::GetHouseTiles (TownID town_id)

Currently I have to work very hard to figure out where all the houses in a town are. This would greatly simplify that.

Some of the tiles with houses on them are reportedly not within town influence according to AITile::IsWithinTownInfluence():

Image

My AI explores all tiles within town influence and checks if they produce passenger cargo, and if so, mark as a house. It misses around 0-7 houses per town, checked against AITown::GetHouseCount().
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Some API extension ideas

Post by krinn »

http://noai.openttd.org/docs/trunk/clas ... bbb0c56b3b

should fix your issue, but it need a newer API, i'm not sure what version is need
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

It would be very useful to have access to financial report, for example - in games with enabled infrastructure costs mature company of AIAI regularly gets bankrupt as it gets hit by high fees. With access to detailed financial report AI would be able to keep required higher amount of money, enough to pay for infrastructure upkeep.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: Some API extension ideas

Post by Michi_cc »

Kogut wrote:With access to detailed financial report AI would be able to keep required higher amount of money, enough to pay for infrastructure upkeep.
If it is just about that, have a look at the AIInfrastructure class.
-- Michael Lutz
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

Michi_cc wrote:
Kogut wrote:With access to detailed financial report AI would be able to keep required higher amount of money, enough to pay for infrastructure upkeep.
If it is just about that, have a look at the AIInfrastructure class.
Thanks, I missed this addition!
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 »

IsTestModeEnabled() - there is no proper way to check this (example of a tricky one, resulting in certain side effects:)

Code: Select all

function IsTestModeEnabled()
{
local gender = AICompany.GetPresidentGender(AICompany.COMPANY_SELF);
local other_gender = AICompany.GENDER_MALE 
if(gender == other_gender) other_gender = AICompany.GENDER_FEMALE 
AICompany.SetPresidentGender(other_gender)
if(gender == AICompany.GetPresidentGender(AICompany.COMPANY_SELF)) return true;
return false;
}

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 »

Why exactly do you need that? It's not something that can be influenced externally, so you could as well just pass a state variable around in your AI.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some API extension ideas

Post by Kogut »

Yexo wrote:Why exactly do you need that? It's not something that can be influenced externally, so you could as well just pass a state variable around in your AI.
It would be hard to do, as "The original mode is stored and recovered from when ever the instance is destroyed." and I need this only when mode is/may be wrong - my variable may be influenced by the very bug that I try to remove.
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 »

Again, when do you need this? You can nest two AITestMode objects within eachother without any problems, so I don't see how the mode "might be wrong".
Aphid
Traffic Manager
Traffic Manager
Posts: 168
Joined: 16 Dec 2011 17:08

Re: Some API extension ideas

Post by Aphid »

GSCompany::GiveMoney (money amt, CompanyID id)

Give the amount specified to the company specified.

bool GSCompany::TakeMoney(money amt, CompanyID id, bool afford = false)

Take the specified amount of money from the specified company. If the 'afford' is true it will only succeed if the company can afford the payment (and return false otherwise).

GSTown::AllowConstructionRights(CompanyID cid, TownID tid)
GSTown::DisAllowConstructionRights(CompanyID cid, TownID tid)

(Dis)Allow a company to build in a town's local authority area. An equivalent function could also use a TileArea.

bool GSTown::RemoveHouse(TownID tid, int stage = 0)

Try to remove a house in the n'th stage area of the town (e.g. stage=1 would mean a small house, stage=5 a building from the town centre). Returns true if it succeeds. If stage = 0 it will remove any house. If a valid GSCompanyMode is active the company will pay for the removal (and it will fail if the authority will not allow it).

OR:

bool GSTile::IsHouse(tileindex X)

returns true iff there is a house on the tile.
Note: the former function can be written in script if the later is implemented.

Allow GSSign to place a sign even if no valid company mode is active (just like a server can).
EDIT: In the current release this works fine.

class GSChat.

GSChat::GetMessage(string &target, companyID &id)

gets and receives the last chat message as a string, as well as the company that typed it, placed in the arguments.

GSChat::PostMessage(string message)
GSChat::PostMessage(GSText message)

Accepts either a string or GSText object. Displays a text message to the user like a chat message. In GSCompanyMode the message will be from the specific company.

GSEventChatMessage

Event that happens whenever anything other than the script itself writes a line to chat.
Has a member function GetMessage (which does the same GSChat::GetMessage does).

bool GSTown::FoundTown(TileIndex X, int city = 0)

Uses a trool argument. If city = 1, the town founded is always a city. city = 2 it is never a city. City = 0 --> it's a city with probability as defined in the advanced settings, otherwise a normal town. Returns true if it succeeds. If a valid CompanyMode is active the company pays the costs.
Note: I am unsure whether this should succeed if founding towns is disabled via advanced settings.

GSTown::SetRating(CompanyID cid,TownID tid, int rating )

Set the rating of the company specified to the amount specified.
Range of the int: -1000 - 1000

int GSTown::GetExactRating(CompanyID cid, TownID tid)
Get the exact rating value of a specified company as an integer.

GSTown::AllowAction(CompanyID cid, TownID tid, TownAction act)
GSTown::ForbidAction (CompanyID cid, TownID tid, TownAction act)
forbid/allow the specified company from doing an action in a town.
Note: the company will still need the required funds. If an action is set to forbid the company can never do it.

Edit::

bool GSTile::ClearTile(TileIndex X, bool magic = false)

Tries to clear all stuff on a tile. If magic is true it acts as the magic bulldozer from the cheats menu (no deletion of vehicles only). Otherwise it acts like clearing a tile with standard limitations (no deletion of industries, radio towers, lighthouses, vehicles). Returns true on success.

Note: Of course, only the Chat and IsHouse function (sets) would be candidates for having AI versions of them.
Last edited by Aphid on 24 Oct 2012 14:14, edited 1 time in total.
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 »

Aphid wrote:Allow GSSign to place a sign even if no valid company mode is active (just like a server can).
This should already work.

You could have a look at TransportGoals, it put a sign on top of your HQ with your current score.

If you cannot get it to work, please post a minimal GS that reproduce your problem at http://bugs.openttd.org
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: Some API extension ideas

Post by MinchinWeb »

Code: Select all

GSGameSettings.IsDisabledVehicleType()
come back with an error ('the index 'IsDisabledVehicleType' does not exist'). If a GS is building for an AI (or human player), if a vehicle type is disabled, is the Game Script bound by that? It probably should be. And there probably should be a way to check if vehicle types are disabled.

Update:
As well

Code: Select all

local MyIndustries = GSList();
MyIndustries.AddItem(oilrig1);
complains that there is an invalid number of parameters. Having an implied Value of 0 (if none is specified) would match the AIList behaviour.
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

MinchinWeb wrote:If a GS is building for an AI (or human player), if a vehicle type is disabled, is the Game Script bound by that? It probably should be. And there probably should be a way to check if vehicle types are disabled.
I'm not sure about that. I don't think they should be, so this function should not be required for GS at all.
As well

Code: Select all

local MyIndustries = GSList();
MyIndustries.AddItem(oilrig1);
complains that there is an invalid number of parameters. Having an implied Value of 0 (if none is specified) would match the AIList behaviour.
I'm not aware of any differences between GSList() and AIList(), but I'll look into it.
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: Some API extension ideas

Post by MinchinWeb »

Yexo wrote:...I'm not aware of any differences between GSList() and AIList(), but I'll look into it.
Thanks!

I was looking at GSOrders and it seems that most of the functions to actually give a vehicle orders are missing (compare with AIOrders). Would it be possible to implement these?

I'm working on the Tutorial GameScript and trying to allow the game script to build the ship chapter is the player decides to skip it. In particular, the functions I think I need (or rather, would very much like) are:
  • GSOrder.AppendOrder()
  • GSOrder.OF_FULL_LOAD
  • GSOrder.OF_NONE
Thanks again!
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Some API extension ideas

Post by Yexo »

MinchinWeb wrote:I was looking at GSOrders and it seems that most of the functions to actually give a vehicle orders are missing (compare with AIOrders). Would it be possible to implement these?
Leaving out those functions was a conscious decision since a GS is meant to do "global" or "goal" things and not order-related actions like an AI. The problem now is that a "Tutorial" GS doesn't really fit in the same category of scripts as other GS. We'll have to come up with a satisfactory solution for this. One possible solution we've discussed in the past is to make yet another category of scripts for tutorial. These scripts would have unrestricted access to all api functions. Since they are only for tutorials they would be limited to single-player games and as such could maybe even get some more advanced control over the GUI. Please not that this is all speculation at this point as there hasn't been any plans for this.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 43 guests