SuperLib: Helper, Direction, Tile, ... libraries
Moderator: OpenTTD Developers
Re: SuperLib: Helper, Direction, Tile, ... libraries
Thanks, I didn't knew that.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Hello Zuu, My AI was crashed at : (\superlib-5\money.nut - 152)
function _SuperLib_Money::GetCompanyProfitLastYear()
{
.....
}
function _SuperLib_Money::GetCompanyProfitLastYear()
{
.....
}
- Attachments
-
- SuperLib.PNG (30.47 KiB) Viewed 7255 times
Re: SuperLib: Helper, Direction, Tile, ... libraries
Thanks for your report. I would hope that the API had this value in it (eg that my suggestion to the API thread would be implemented), but otherwise I'll have to use the base value of about 500 and add inflation if that is enabled. Still it's a bug in the library that I did release it before sorting out this constant.
Thanks for your report.
Thanks for your report.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
I can't find it in the last few pages of the API extension ideas topic. Could you please point out where the request is (so I don't miss similar things) or make a new post in the API extension ideas topic?Zuu wrote:Thanks for your report. I would hope that the API had this value in it (eg that my suggestion to the API thread would be implemented), but otherwise I'll have to use the base value of about 500 and add inflation if that is enabled. Still it's a bug in the library that I did release it before sorting out this constant.
Thanks for your report.
Re: SuperLib: Helper, Direction, Tile, ... libraries
Its in my post from 20 feb 2010 at page 7 in the api suggestion forum.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Update - Version 7
- Bug fix: Use AILog.Warning for Log.Warning calls.
- Change: Include date in log prints
- Bug fix: Fixed two fatal bugs in Airport sub library
- Attachments
-
- SuperLib-v7.tar
- (130 KiB) Downloaded 261 times
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: SuperLib: Helper, Direction, Tile, ... libraries
Thanks for your Library Zuu - it makes my life way nicer.
I have a bug report: If I cheat to switch companies to my AI and then cheat to add £10,000,000, the MaxPayback function (in the Money sublibrary) stops working. My loan amount doesn't go up, but the loan doesn't disappear either.
To replicate, load up WmDOT, and in the AI Options set 'OpDOT' to 'no go' and the 'Debug Level' to '3' or better. Cheat to the money...
I have a bug report: If I cheat to switch companies to my AI and then cheat to add £10,000,000, the MaxPayback function (in the Money sublibrary) stops working. My loan amount doesn't go up, but the loan doesn't disappear either.
To replicate, load up WmDOT, and in the AI Options set 'OpDOT' to 'no go' and the 'Debug Level' to '3' or better. Cheat to the money...
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: SuperLib: Helper, Direction, Tile, ... libraries
Thanks for your report,
Here is a fixed money.nut, I've verified it using a test AI that do nothing more than calling MakeMaxPayback.
Verification AI "PayBack":
I will make a version 8 of the library soon (today or within a few days).
Here is a fixed money.nut, I've verified it using a test AI that do nothing more than calling MakeMaxPayback.
Verification AI "PayBack":
Code: Select all
function PayBack::Start()
{
while(true)
{
AIController.Sleep(1);
Money.MakeMaximumPayback();
}
}
- Attachments
-
- money.nut
- (6.44 KiB) Downloaded 217 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Update - version 8
Fixes the problem in the Money sub library reported above.
Fixes the problem in the Money sub library reported above.
- Attachments
-
- SuperLib-v8.tar
- (130 KiB) Downloaded 248 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Update - SuperLib 9
Includes my pathfinder wrapper (SuperLib.RoadPathFinder) + road building code (SuperLib.RoadBuilder).
Includes my pathfinder wrapper (SuperLib.RoadPathFinder) + road building code (SuperLib.RoadBuilder).
- Attachments
-
- SuperLib-v9.tar
- (170 KiB) Downloaded 239 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Update - SuperLib 10
Important: moved functions
The following two static functions has moved to a new Road class.
RoadBuilder::ConvertRailCrossingToBridge(rail_tile, prev_tile)
RoadBuilder::RemoveRoadUpToRoadCrossing(start_tile)
Other changes
Important: moved functions
The following two static functions has moved to a new Road class.
RoadBuilder::ConvertRailCrossingToBridge(rail_tile, prev_tile)
RoadBuilder::RemoveRoadUpToRoadCrossing(start_tile)
Other changes
- A new class Road with functions for building road stations for towns/industries
- New functions in Airport for handling of air services
- Yexo's Valuate and CallFunction functions from AdmiralAI (version 22) has been added to SuperLib. The reason for this is that they are needed by a function in Airport. What differs Yexo's Valuate squirrel function from the one in the API is that it accepts valuator functions that execute DoCommands.
- A few additional functions here and there
- Attachments
-
- SuperLib-v10.tar
- (230 KiB) Downloaded 265 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Version 11
* Airport Upgrading
* Improved handling of when the distant join station setting is off
Version 12
* Read use_rvs, use_planes, use_trains and use_ships settings. Report zero vehicle limit if corresponding vehicle type setting is defined by the AI and is equal to 0.
* Function to get a string explaining which setting a user need to enable in order to enable a given vehicle type. (will require updates whenever the English "translation" changes and is incompatible with users running OpenTTD in a language different from English)
If anyone needs other setting names than "use_rvs", "use_planes", etc. a system that allows defining those names is possible. However, unless someone actually needs it, I will probably not implement it. (for inspiration see eg. the Log system which allow to offer your own function for deciding which log messages that should be hidden or not if you don't want to use the default one.)
Download
Visit bananas: http://bananas.openttd.org/en/ai/
* Airport Upgrading
* Improved handling of when the distant join station setting is off
Version 12
* Read use_rvs, use_planes, use_trains and use_ships settings. Report zero vehicle limit if corresponding vehicle type setting is defined by the AI and is equal to 0.
* Function to get a string explaining which setting a user need to enable in order to enable a given vehicle type. (will require updates whenever the English "translation" changes and is incompatible with users running OpenTTD in a language different from English)
If anyone needs other setting names than "use_rvs", "use_planes", etc. a system that allows defining those names is possible. However, unless someone actually needs it, I will probably not implement it. (for inspiration see eg. the Log system which allow to offer your own function for deciding which log messages that should be hidden or not if you don't want to use the default one.)
Download
Visit bananas: http://bananas.openttd.org/en/ai/
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Version 13
- Fixes a fatal error that has existed in the library for a while. In order to trigger it one had to call the function to build a bus stop/truck stop/depot next to road from a scope where "this" would not point to a sub class of AIController. These conditions are as far as I remember never met in CluelessPlus, so the error didn't appear there.
- Fix: Don't require 8 in production when building road stops. Only acceptance need >= 8. For production there is no such limit in OpenTTD.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Is it planned to include useful function but unused in PAXlink/Clueless code? I think that it may be interesting to move certain functions from AIAI to this library.
Inflate function may be used for example in function _SuperLib_Road::ConvertRailCrossingToBridge
Code: Select all
// This function comes from SimpleaAI, version 6, written by Brumi
/**
* Calculates the percentage of inflation since the start of the game.
* @return The percentage by which prices have risen since the start of the game.
* It is 100 if there is no inflation, 200 if prices have doubled, etc.
*/
static function GetInflationRate();
// This function comes from AIAI, version 51, written by Kogut
/**
* Adjusts any given amount of money for inflation
*/
static function Inflate(money);
// This function comes from AIAI, version 51, written by Kogut
/**
* Wastes money (may be used to ensure bankruptcy)
*/
static function BurnMoney();
function GetInflationRate()
{
return (100 * AICompany.GetMaxLoanAmount() / AIGameSettings.GetValue("difficulty.max_loan"));
}
function Inflate(money)
{
return money*GetInflationRate()/100;
}
function BurnMoney()
{
local empty_tile=null;
for(local i = 0; i<1000; i++)
{
empty_tile = RandomTile();
if(AITile.IsBuildable(empty_tile))
{
while(true)
{
AITile.PlantTree(empty_tile);
AITile.DemolishTile(empty_tile);
}
if(!AITile.IsBuildable(empty_tile))continue;
break;
}
}
}
Code: Select all
/* Now we know it is possible to bridge/tunnel the rail from tile_before to tile_after */
// Make sure we can afford the construction
AICompany.SetLoanAmount(AICompany.GetMaxLoanAmount());
if (AICompany.GetBankBalance(AICompany.COMPANY_SELF) < 20000) //<--Here
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SuperLib: Helper, Direction, Tile, ... libraries
I haven't exactly planned to do so, but if you or others offer code that seems resonable to include, I'm not against including it.
Actually, I think it is very nice of you that you offer some code back that can be used to improve SuperLib even more.
Actually, I think it is very nice of you that you offer some code back that can be used to improve SuperLib even more.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Hello,
It appears that when you use the Road.BuildMagicDTRSInTown function and set the stop_length argument to a value greater than 2, the depot_tile return value is a tile off. The picture included on this post illustrates the problem
If you cant read past my bad photoshopping skills, SuperLib returned the depot tile as 1002,972, while the depot was actually at 1003,972. I have no idea if the problem is related to the way the station is facing or not, or if your Tile.GetTileString function incorrect, but somthing is wrong. Yes, the station in the background is the station in question.
It appears that when you use the Road.BuildMagicDTRSInTown function and set the stop_length argument to a value greater than 2, the depot_tile return value is a tile off. The picture included on this post illustrates the problem
If you cant read past my bad photoshopping skills, SuperLib returned the depot tile as 1002,972, while the depot was actually at 1003,972. I have no idea if the problem is related to the way the station is facing or not, or if your Tile.GetTileString function incorrect, but somthing is wrong. Yes, the station in the background is the station in question.
Re: SuperLib: Helper, Direction, Tile, ... libraries
Thanks 11Runner for your report. Actually, I think it will return a wrong depot tile for any stop_length other than 2. I've fixed the problem in the code respority and it will be included in the next release, which I think will happen when I've also added the code that Kogut posted.
Kogut: Is it intended that your BurnMoney function never will return? You have a while(true) loop in there which has no way of breaking out of the loop. You've also missed the RandomTile function, but no problem, its fairly simple and I've added a SuperLib::Tile::GetRandomTile function that I use for your BurnMoney function.
Kogut: Is it intended that your BurnMoney function never will return? You have a while(true) loop in there which has no way of breaking out of the loop. You've also missed the RandomTile function, but no problem, its fairly simple and I've added a SuperLib::Tile::GetRandomTile function that I use for your BurnMoney function.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SuperLib: Helper, Direction, Tile, ... libraries
Zuu wrote:Is it intended that your BurnMoney function never will return?

Code: Select all
function BurnMoney()
{
local empty_tile=null;
for(local i = 0; i<1000; i++)
{
empty_tile = RandomTile();
if(AITile.IsBuildable(empty_tile))
{
while(true)
{
if(!AITile.DemolishTile(empty_tile)) break;
}
if(!AITile.IsBuildable(empty_tile))continue;
break;
}
}
}
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SuperLib: Helper, Direction, Tile, ... libraries
I found a bug: function _SuperLib_Tile::GetBridgeAboveStart is using this for:
Unfortunately, result from GetAdjacentTileInDirection is using value from GetTileInDirection, this function is using value from GetTileRelative. Value returned by GetTileRelative is clamped to mapsize, therefore AIMap.IsValidTile(curr_tile); is not working (curr_tile is always valid). I think that it can be replaced by
to achieve intended result.
Code: Select all
for (local curr_tile = _SuperLib_Direction.GetAdjacentTileInDirection(tile, bridge_search_direction);
AIMap.IsValidTile(curr_tile);
curr_tile = _SuperLib_Direction.GetAdjacentTileInDirection(curr_tile, bridge_search_direction))
Code: Select all
for (local curr_tile = _SuperLib_Direction.GetAdjacentTileInDirection(tile, bridge_search_direction);
true;
curr_tile = _SuperLib_Direction.GetAdjacentTileInDirection(curr_tile, bridge_search_direction))
...
if(curr_tile == _SuperLib_Direction.GetAdjacentTileInDirection(curr_tile, bridge_search_direction)) break;
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SuperLib: Helper, Direction, Tile, ... libraries
To my understanding, this loop will never stop for as long as empty_tile is empty. Thus the function will typically not return until the AI has really gone bankrupt. For the purpose of ensuring bankruptcy its probably fine, it's just not documented. So unless someone corrects me, I will add to the docs of this function that it will most likely not return.Kogut wrote:Code: Select all
while(true) { if(!AITile.DemolishTile(empty_tile)) break; }
Thanks for your other bug report, I'll include that fix.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Who is online
Users browsing this forum: No registered users and 11 guests