Some API extension ideas
Moderator: OpenTTD Developers
Re: Some API extension ideas
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?
Re: Some API extension ideas
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.
In any case: what this means is that these changes will be in the 1.2 release.
- MinchinWeb
- Traffic Manager
- Posts: 225
- Joined: 01 Feb 2011 12:41
- Contact:
Re: Some API extension ideas
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
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Re: Some API extension ideas
I use HTTrack website copier. Wheather or not this is the direction you are going I have no ideaMinchinWeb 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.
Re: Some API extension ideas
I also (have used) the same software
A suggestion!
bool AIController::IsGoalScriptLoaded()
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
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
Re: Some API extension ideas
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():
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().
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():
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().
Re: Some API extension ideas
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
should fix your issue, but it need a newer API, i'm not sure what version is need
Re: Some API extension ideas
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
AIAI - AI for OpenTTD
Re: Some API extension ideas
If it is just about that, have a look at the AIInfrastructure class.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.
-- Michael Lutz
Re: Some API extension ideas
Thanks, I missed this addition!Michi_cc wrote:If it is just about that, have a look at the AIInfrastructure class.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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Some API extension ideas
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
AIAI - AI for OpenTTD
Re: Some API extension ideas
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.
Re: Some API extension ideas
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.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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Some API extension ideas
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".
Re: Some API extension ideas
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.
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.
Re: Some API extension ideas
This should already work.Aphid wrote:Allow GSSign to place a sign even if no valid company mode is active (just like a server can).
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)
Junctioneer (a traffic intersection simulator)
- MinchinWeb
- Traffic Manager
- Posts: 225
- Joined: 01 Feb 2011 12:41
- Contact:
Re: Some API extension ideas
Code: Select all
GSGameSettings.IsDisabledVehicleType()
Update:
As well
Code: Select all
local MyIndustries = GSList();
MyIndustries.AddItem(oilrig1);
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
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Re: Some API extension ideas
I'm not sure about that. I don't think they should be, so this function should not be required for GS at all.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 aware of any differences between GSList() and AIList(), but I'll look into it.As wellcomplains that there is an invalid number of parameters. Having an implied Value of 0 (if none is specified) would match the AIList behaviour.Code: Select all
local MyIndustries = GSList(); MyIndustries.AddItem(oilrig1);
- MinchinWeb
- Traffic Manager
- Posts: 225
- Joined: 01 Feb 2011 12:41
- Contact:
Re: Some API extension ideas
Thanks!Yexo wrote:...I'm not aware of any differences between GSList() and AIList(), but I'll look into it.
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
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
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Re: Some API extension ideas
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.
Who is online
Users browsing this forum: No registered users and 43 guests