MinchinWeb's MetaLibrary
v.9
Library functions of OpenTTD AI writers.
|
A Road Pathfinder (and extras) More...
Classes | |
class | Cost |
class | Info |
Public Member Functions | |
function | InitializePath (sources, goals) |
Initialize a path search between sources and goals. More... | |
function | FindPath (iterations) |
Try to find the path as indicated with InitializePath with the lowest cost. More... | |
function | PresetOriginal () |
The settings in the original (v3) pathfinder by NoAI Team. More... | |
function | PresetPerfectPath () |
Good preset for reusing existing roads. More... | |
function | PresetQuickAndDirty () |
Quick but messy preset. More... | |
function | PresetCheckExisting () |
Preset that only uses existing roads. More... | |
function | PresetStreetcar () |
Reserved. More... | |
function | GetBuildCost () |
Cost to build found path. More... | |
function | BuildPath () |
Build the found path. More... | |
function | LoadPath () |
Load an existing path. More... | |
function | GetPath () |
Export the found path. More... | |
function | GetPathLength () |
Get the length of the found path. More... | |
function | InitializePathOnTowns () |
Initializes the pathfinder using two towns. More... | |
function | PathToTilePairs () |
Get the found path as tile pairs. More... | |
function | PathToTiles () |
Get a list of all the tiles in the path. More... | |
function | TilePairsToBuild () |
Tiles in the path that need to be built. More... | |
Private Member Functions | |
constructor () | |
function | _GetBridgeNumSlopes (end_a, end_b) |
function | _Cost (self, path, new_tile, new_direction) |
function | _Estimate (self, cur_tile, cur_direction, goal_tiles) |
function | _Neighbours (self, path, cur_node) |
function | _CheckDirection (self, tile, existing_direction, new_direction) |
function | _GetDirection (from, to, is_bridge) |
function | _GetTunnelsBridges (last_node, cur_node, bridge_dir) |
function | _IsSlopedRoad (start, middle, end) |
function | _CheckTunnelBridge (current_tile, new_tile) |
Private Attributes | |
_aystar_class = import("graph.aystar", "", 6) | |
_max_cost = null | |
The maximum cost for a route. More... | |
_cost_tile = null | |
The cost for a single tile. More... | |
_cost_no_existing_road = null | |
The cost that is added to _cost_tile if no road exists yet. More... | |
_cost_turn = null | |
The cost that is added to _cost_tile if the direction changes. More... | |
_cost_slope = null | |
The extra cost if a road tile is sloped. More... | |
_cost_bridge_per_tile = null | |
The cost per tile of a new bridge, this is added to _cost_tile . More... | |
_cost_tunnel_per_tile = null | |
The cost per tile of a new tunnel, this is added to _cost_tile . More... | |
_cost_coast = null | |
The extra cost for a coast tile. More... | |
_cost_level_crossing = null | |
the extra cost for rail/road level crossings. More... | |
_cost_drivethru_station = null | |
The extra cost for drive-thru road stations. More... | |
_pathfinder = null | |
A reference to the used AyStar object. More... | |
_max_bridge_length = null | |
The maximum length of a bridge that will be build. More... | |
_max_tunnel_length = null | |
The maximum length of a tunnel that will be build. More... | |
_cost_only_existing_roads = null | |
Choose whether to only search through existing connected roads. More... | |
_distance_penalty = null | |
Penalty to use to speed up pathfinder, 1 is no penalty. More... | |
_road_type = null | |
cost = null | |
Used to change the costs. More... | |
_mypath = null | |
Used to store the path after it's been found for Building functions. More... | |
_running = null | |
info = null | |
A Road Pathfinder (and extras)
This road pathfinder tries to find a buildable / existing route for road vehicles. You can changes the costs below using for example roadpf.cost.turn = 30
. Note that it's not allowed to change the cost between consecutive calls to FindPath. You can change the cost before the first call to FindPath and after FindPath has returned an actual route. To use only existing roads, set roadpf.cost.only_existing_road = True
.
The pathfinder has been extended to provide 'presets' for configuration, store the found path, and build the found path.
upgrade slow bridges along path
convert existing level crossings (road/rail) to road bridge
do something about one-way roads - build a pair? route around?
Add example usage code.
if(AIRoad.AreRoadTilesConnected(new_tile, prev_tile) && !AIRoad.AreRoadTilesConnected(prev_tile, new_tile))
Definition at line 83 of file Pathfinder.Road.nut.
|
private |
Definition at line 517 of file Pathfinder.Road.nut.
|
private |
Definition at line 601 of file Pathfinder.Road.nut.
|
private |
Definition at line 360 of file Pathfinder.Road.nut.
|
private |
Definition at line 432 of file Pathfinder.Road.nut.
|
private |
Definition at line 340 of file Pathfinder.Road.nut.
|
private |
Definition at line 521 of file Pathfinder.Road.nut.
|
private |
Get a list of all bridges and tunnels that can be build from the current tile. Bridges will only be build starting on non-flat tiles for performance reasons. Tunnels will only be build if no terraforming is needed on both ends.
Definition at line 546 of file Pathfinder.Road.nut.
|
private |
Definition at line 573 of file Pathfinder.Road.nut.
|
private |
Definition at line 442 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::BuildPath | ( | ) |
|
inlineprivate |
Definition at line 107 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::FindPath | ( | iterations | ) |
Try to find the path as indicated with InitializePath with the lowest cost.
iterations | After how many iterations it should abort for a moment. This value should either be -1 for infinite, or > 0. Any other value aborts immediately and will never find a path. |
Definition at line 332 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::GetBuildCost | ( | ) |
Cost to build found path.
Turns to 'test mode,' builds the route provided, and returns the cost.
False
if the test build fails somewhere Definition at line 747 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::GetPath | ( | ) |
Export the found path.
Definition at line 918 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::GetPathLength | ( | ) |
Get the length of the found path.
Runs over the path to determine its length.
Definition at line 927 of file Pathfinder.Road.nut.
|
inline |
Initialize a path search between sources and goals.
sources | The source tiles. |
goals | The target tiles. |
Definition at line 140 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::InitializePathOnTowns | ( | ) |
Initializes the pathfinder using two towns.
Definition at line 941 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::LoadPath | ( | ) |
Load an existing path.
'Loads' a path to allow GetBuildCost(), BuildPath() and GetPathLength() to be used.
Definition at line 908 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::PathToTilePairs | ( | ) |
Get the found path as tile pairs.
Definition at line 949 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::PathToTiles | ( | ) |
Get a list of all the tiles in the path.
Definition at line 975 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::PresetCheckExisting | ( | ) |
Preset that only uses existing roads.
Based on PerfectPath, but uses only existing roads. Useful for checking if there an existing route and how long it is.
Definition at line 721 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::PresetOriginal | ( | ) |
The settings in the original (v3) pathfinder by NoAI Team.
function _MinchinWeb_RoadPathfinder_::PresetPerfectPath | ( | ) |
Good preset for reusing existing roads.
My slightly updated version of PresetOriginal().
Definition at line 677 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::PresetQuickAndDirty | ( | ) |
Quick but messy preset.
Runs in as little as 5% of the time of PresetPerfectPath(), but builds odd bridges and loops.
Definition at line 698 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::PresetStreetcar | ( | ) |
Reserved.
Reserved preset for future use for intraurban tram lines.
Definition at line 742 of file Pathfinder.Road.nut.
function _MinchinWeb_RoadPathfinder_::TilePairsToBuild | ( | ) |
Tiles in the path that need to be built.
Similar to PathToTilePairs(), but only returns those pairs where there isn't a current road connection.
Definition at line 997 of file Pathfinder.Road.nut.
|
private |
Definition at line 84 of file Pathfinder.Road.nut.
|
private |
The cost per tile of a new bridge, this is added to _cost_tile
.
Definition at line 90 of file Pathfinder.Road.nut.
|
private |
The extra cost for a coast tile.
Definition at line 92 of file Pathfinder.Road.nut.
|
private |
The extra cost for drive-thru road stations.
Definition at line 94 of file Pathfinder.Road.nut.
|
private |
the extra cost for rail/road level crossings.
Definition at line 93 of file Pathfinder.Road.nut.
|
private |
The cost that is added to _cost_tile
if no road exists yet.
Definition at line 87 of file Pathfinder.Road.nut.
|
private |
Choose whether to only search through existing connected roads.
Definition at line 98 of file Pathfinder.Road.nut.
|
private |
The extra cost if a road tile is sloped.
Definition at line 89 of file Pathfinder.Road.nut.
|
private |
The cost for a single tile.
Definition at line 86 of file Pathfinder.Road.nut.
|
private |
The cost per tile of a new tunnel, this is added to _cost_tile
.
Definition at line 91 of file Pathfinder.Road.nut.
|
private |
The cost that is added to _cost_tile
if the direction changes.
Definition at line 88 of file Pathfinder.Road.nut.
|
private |
Penalty to use to speed up pathfinder, 1 is no penalty.
Definition at line 99 of file Pathfinder.Road.nut.
|
private |
The maximum length of a bridge that will be build.
Definition at line 96 of file Pathfinder.Road.nut.
|
private |
The maximum cost for a route.
Definition at line 85 of file Pathfinder.Road.nut.
|
private |
The maximum length of a tunnel that will be build.
Definition at line 97 of file Pathfinder.Road.nut.
|
private |
Used to store the path after it's been found for Building functions.
Definition at line 102 of file Pathfinder.Road.nut.
|
private |
A reference to the used AyStar object.
Definition at line 95 of file Pathfinder.Road.nut.
|
private |
Definition at line 100 of file Pathfinder.Road.nut.
|
private |
Definition at line 103 of file Pathfinder.Road.nut.
|
private |
Used to change the costs.
Definition at line 101 of file Pathfinder.Road.nut.
|
private |
Definition at line 104 of file Pathfinder.Road.nut.