SuperLib: Helper, Direction, Tile, ... libraries
Moderator: OpenTTD Developers
Re: SuperLib: Helper, Direction, Tile, ... libraries
Bug:
When my AI calls Road.ConvertRailCrossingToBridge in SuperLib v19 with the situation illustrated in the picture, the function continuously generates an invalid tile direction to Direction.GetTileInDirection (as illustrated in the picture)
If my bug report is not correct, could you tell me what I am doing wrong?
When my AI calls Road.ConvertRailCrossingToBridge in SuperLib v19 with the situation illustrated in the picture, the function continuously generates an invalid tile direction to Direction.GetTileInDirection (as illustrated in the picture)
If my bug report is not correct, could you tell me what I am doing wrong?
Re: SuperLib: Helper, Direction, Tile, ... libraries
My guess is that something is going wrong when it is deciding the "tile_after" and "tile_before". As you can see in your debug output it wrongly thinks that the level crossing is not flat. Thus it could be that either the "before" or "after" tile is a invalid index.
I wonder, could you place two signs one at the rail_tile and another at the prev_tile? (arguments to the function). Also if you have a test case (AI + savegame) that can reproduce this, that would help, but just providing those signs and show me the code that calls ConvertRailCrossingToBridge would help.
Mind that my function doesn't validate that the input is sane.
Edit: just to be clear:
rail_tile = the rail/road crossing
prev_tile = either of the two road tiles next to the rail/road crossing. If there are several adjacent rail crossings, you do not need to iterate to find a tile that has no rail - this is done by the function.
I wonder, could you place two signs one at the rail_tile and another at the prev_tile? (arguments to the function). Also if you have a test case (AI + savegame) that can reproduce this, that would help, but just providing those signs and show me the code that calls ConvertRailCrossingToBridge would help.
Mind that my function doesn't validate that the input is sane.
Edit: just to be clear:
rail_tile = the rail/road crossing
prev_tile = either of the two road tiles next to the rail/road crossing. If there are several adjacent rail crossings, you do not need to iterate to find a tile that has no rail - this is done by the function.
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
I was looking at your RoadPathfinder, looking for a few ideas to improve or supplement my own. A couple of questions:
For what it's worth, aircraft is both the singular and the plural form of the word...
Thanks again for the library!
EDIT: Another question: I noticed that you talk in the comments about avoiding building a parallel route to an existing route - is this done by testing for parallel route, or simply by reducing the cost of a path that uses existing (already built) roads?
- - (line 209 for "roadbuilder.nut") I see you replace rail/road level crossings with a road bridge, but if I understand your code, the pathfinder has to first build the level crossing to then convert it to a bridge. Is this right? In that case, have you done anything to be able to cross diagonal railway tracks?
- how do you get over rivers? I'm using (a slightly modified version of) the NoAI Team's pathfinder which only tries to build bridges starting from a sloped tile; thus, it usually can't get over rivers (both sides are usually flat).
Code: Select all
static function GetAircraftsInHangar(station_id);
Thanks again for the library!
EDIT: Another question: I noticed that you talk in the comments about avoiding building a parallel route to an existing route - is this done by testing for parallel route, or simply by reducing the cost of a path that uses existing (already built) roads?
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
Take a look on line 205. Line 209 is only executed if the road already have road. That happen when the pathfinder has found a path that uses existing road. In that case the pathfinder can suggest to use a path that has railroad crossing. What line 209 does is to detect this and see if the ownership of the road as well as the local landscape situation allows to replace the level crossing with a bridge.MinchinWeb wrote:I was looking at your RoadPathfinder, looking for a few ideas to improve or supplement my own. A couple of questions:
- (line 209 for "roadbuilder.nut") I see you replace rail/road level crossings with a road bridge, but if I understand your code, the pathfinder has to first build the level crossing to then convert it to a bridge. Is this right?
So no, if the path finder is suggesting to build a completely new road past a railway, it will bridge it from start and not first build a rail crossing. The code responsible for finding such paths is the custom _Neighbours function in roadpathfinder.nut. RoadBuilder then detects that there is a gap in the found path and sees if it should use a bridge or a tunnel depending on the situation.
From what I can see the pathfinder should find paths across diagonal rails: (around line 99 in roadpathfinder.nut)
Code: Select all
while(AITile.HasTransportType(i_tile, AITile.TRANSPORT_RAIL) || AITile.IsWaterTile(i_tile)) // try to bridge over rail or flat water (rivers/canals)
{
i_tile += offset;
bridge_length++;
}
Avoiding parallel routes is done by pathfinder penalties. In addition to the modified costs there is also a custom _Cost function that adds a few extra penalties but none of these are for parallel roads.EDIT: Another question: I noticed that you talk in the comments about avoiding building a parallel route to an existing route - is this done by testing for parallel route, or simply by reducing the cost of a path that uses existing (already built) roads?
Regarding Aircraft(s), thanks for the notification.
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 21 (yes I screw up version 20 )
Changes:
Known bug/issue:
The comments does still use "aircrafts" instead of "aircraft" for the functions that got corrected spelling.
Manual download
Changes:
- Fix: Aircrafts => Aircraft. Wrapper functions for the old name exist so no backward compatibility should be broken (thanks MinchinWeb)
- Fix: Tile => _SuperLib_Tile (reported by trotter94)
- Change: As per request, make SetSign return the sign id (it was previously not returning anything)
- Change: Allow more sub libraries to be translated to NoGo (some functions doesn't really make sense for NoGo, but I'm not the one to decide what you want to use. Some will only work with company mode for a player. Use your common sense to judge what will work and what will not.)
- Feature: A generic Tile.CanWalkToTile(...) that takes a function that decides which tiles that can be walked.
Known bug/issue:
The comments does still use "aircrafts" instead of "aircraft" for the functions that got corrected spelling.
Manual download
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
roadpathfinder.nut:219 calls _SuperLib__SuperLib_Log.Info() which doesn't exist. I think you meant _SuperLib_Log.Info().
Code: Select all
if(num_iterations_to_run <= 0)
{
// No path found (within time)
_SuperLib__SuperLib_Log.Info("SuperLib: Finding path took to long -> abort", _SuperLib_Log.LVL_SUB_DECISIONS);
this.find_path_error_code = _SuperLib_RoadPathFinder.PATH_FIND_FAILED_TIME_OUT;
return null;
}
Re: SuperLib: Helper, Direction, Tile, ... libraries
Thank you, I'll fix it for next release (which will also contain some rail functions from krinn)
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 22
Version 22 adds not a too short list of new functions including two new sub libraries - DataStore and Rail.
DataStore offers the code from CluelessPlus that is used to store data in station and vehicle names. It is generic enough that you can store data in any object that have <API>.SetName(id, name) and <API>.GetName(id). See datastore.nut for more info.
Rail contains two functions contributed by krinn to check if two tiles are connected by rail.
Manual Download - visit Bananas website
AI Libraries
GS Libraries
Don't forget to get the dependencies too if you don't have them already.
Version 22 adds not a too short list of new functions including two new sub libraries - DataStore and Rail.
DataStore offers the code from CluelessPlus that is used to store data in station and vehicle names. It is generic enough that you can store data in any object that have <API>.SetName(id, name) and <API>.GetName(id). See datastore.nut for more info.
Rail contains two functions contributed by krinn to check if two tiles are connected by rail.
- Document: If no cargo is passed to BuildAirportInTown, the airport will end up far away
- Add: Initial support for building airports for industries (no landscaping support yet)
- Add: Functions for storing data in vehicles/stations (or any object type which has APIClass.GetName/SetName). Also added ability to encode integers to 84-base strings or any other base you want.
- Add: Functions to find char or string in a string, searching from the back
- Add: Tile.IsDepotTile(tile, vehicle_type)
- Add: Vehicle.SendVehicleToDepotForSelling and Vehicle.SellVehiclesInDepot for sending vehicles to depot for selling and for selling vehicles waiting in depot.
- Add: Sign.GetSign that does the same checks as HasSign, but does actually return the sign ID
- Add: Rail library. It mainly features Rail.AreRailTilesConnected by krinn
- Fix: If pathfinding takes longer time than the time-limit a crash was triggered (Core Xii)
Manual Download - visit Bananas website
AI Libraries
GS Libraries
Don't forget to get the dependencies too if you don't have them already.
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
Another one; relevant bits focused.
Re: SuperLib: Helper, Direction, Tile, ... libraries
Thank you. That constant is a placeholder that I have not been able to replace as at that time (and probably still) there is no way for AI/GS to get hold of that cost. Accidentally this code has been included in SuperLib without doing an educated guess on what the station maintenance cost is.
As long as there isn't a base cost mod active and the user don't change the interest rate during the game, it is probably possible to compute the cost. However, as I sad there are several pre conditions that the user will not be aware that he/she breaks and then wonder why the AI/GS is "broken".
As long as there isn't a base cost mod active and the user don't change the interest rate during the game, it is probably possible to compute the cost. However, as I sad there are several pre conditions that the user will not be aware that he/she breaks and then wonder why the AI/GS is "broken".
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 guess you could say this is a feature request you will want to add
In SynTrans v10, I found some code in Michel's ChooChoo which I imlpemented as a Road pathfinder in my AI.
Overall, you simply override the _Estimate() function in the pathfinder.road library, and multiply the return value by a number (usually between 1 and 2) to speed up pathfinding. The difference is very noticeable. When the multiplier is 2.0, pathfinding only takes a few days, whereas pathfinding could take much longer when not multiplied.
So I guess, my feature request is to provide such an option to speed up the road pathfinder .
In SynTrans v10, I found some code in Michel's ChooChoo which I imlpemented as a Road pathfinder in my AI.
Overall, you simply override the _Estimate() function in the pathfinder.road library, and multiply the return value by a number (usually between 1 and 2) to speed up pathfinding. The difference is very noticeable. When the multiplier is 2.0, pathfinding only takes a few days, whereas pathfinding could take much longer when not multiplied.
So I guess, my feature request is to provide such an option to speed up the road pathfinder .
Re: SuperLib: Helper, Direction, Tile, ... libraries
Update - Version 23
Changelog
AI Library and GS Library section of bananas
Changelog
- Fix: Airport.BuildAirportInTown was broken
- Feature: Make it possible to set a multiplier for the _Estimate return value of the road pathfinder
- Documment that Money.GetCompanyProfitLastYear doesn't work
AI Library and GS Library section of bananas
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 24
Changelog
AI Library and GS Library section of bananas
Changelog
- Add: Money::ExecuteWithLoan - executes an action, but if it fails due to being out of money, it takes more loan and execute it again.
- Feature: The RoadBuilder takes more loan if it runs out of money
AI Library and GS Library section of bananas
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 need some help with this, where do I install this?
Also, the SVN version does not work, it says it is a invalid path.
Thanks in advance.
EDIT: Okay I think I found out, I think it goes into the AI folder.
Also, the SVN version does not work, it says it is a invalid path.
Thanks in advance.
EDIT: Okay I think I found out, I think it goes into the AI folder.
You just lost The Game.
Re: SuperLib: Helper, Direction, Tile, ... libraries
My development SuperLib install goes into C:\Users\Leif\Documents\OpenTTD\Installations\Last Nightly\ai\library\SuperLib_svn
If I would be okay with it being available for all installations and not only my "Last Nightly" install, I would put it in:
C:\Users\Leif\Documents\OpenTTD\ai\library\SuperLib_svn
(actually, you probably should use _hg rather than _svn as it is actually checked in in a hg repository. My "_svn" is just staying around since when I had it in a svn repository)
Depending on your operating system, the paths might be different for you. Checkout readme.txt of OpenTTD, section 4.2.
If I would be okay with it being available for all installations and not only my "Last Nightly" install, I would put it in:
C:\Users\Leif\Documents\OpenTTD\ai\library\SuperLib_svn
(actually, you probably should use _hg rather than _svn as it is actually checked in in a hg repository. My "_svn" is just staying around since when I had it in a svn repository)
Depending on your operating system, the paths might be different for you. Checkout readme.txt of OpenTTD, section 4.2.
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 found it on the in-game addon thing majig thankfully, thanks for the help! Also I use Windows 7 and Windows XP on my netbook.Zuu wrote:My development SuperLib install goes into C:\Users\Leif\Documents\OpenTTD\Installations\Last Nightly\ai\library\SuperLib_svn
If I would be okay with it being available for all installations and not only my "Last Nightly" install, I would put it in:
C:\Users\Leif\Documents\OpenTTD\ai\library\SuperLib_svn
(actually, you probably should use _hg rather than _svn as it is actually checked in in a hg repository. My "_svn" is just staying around since when I had it in a svn repository)
Depending on your operating system, the paths might be different for you. Checkout readme.txt of OpenTTD, section 4.2.
You just lost The Game.
Re: SuperLib: Helper, Direction, Tile, ... libraries
Is there a particular reason why SuperLib for NoGo v24 does not have a Road sub-library?
Re: SuperLib: Helper, Direction, Tile, ... libraries
Because the road pathfinder lib have not been ported to NoGo.
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 have made my own port of the road pathfinder library if you are interested.Zuu wrote:Because the road pathfinder lib have not been ported to NoGo.
Re: SuperLib: Helper, Direction, Tile, ... libraries
Version 24
It appears that I have forgotten to announce version 24 that was released 2012-08-19. That update included some exciting news:
It appears that I have forgotten to announce version 24 that was released 2012-08-19. That update included some exciting news:
- Add: HasSignAt(tile) and GetSignAt(tile)
- Change: Use Pathfinder.Road 4
- Add: AreDistantRoadTilesConnected that use a special version of the A* RPF that only consider existing roads as neighbours. Note that it is not perfect. Under some cases it fail to report connected tiles if the detour is too long.
- Feature: Road, RoadBuilder and RoadPathfinder are now supported for NoGo
- Add: IsStation, GetMaxCoverageRadius, GetAcceptanceCoverageTiles, GetSupplyCoverageTiles, ISCargoAccepted, IsCargoAcceptedByIndustry, IsCargoSUpplide, IsCargoSuppliedByIndustry
Last edited by Zuu on 29 Sep 2012 18:55, edited 1 time in total.
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 3 guests