MinchinWeb's MetaLibrary  v.9 Library functions of OpenTTD AI writers.
_MinchinWeb_Lakes_ Class Reference

Lakes. More...

Public Member Functions

function InitializePath (sources, goals)

function FindPath (iterations)

Seeds a point into Lakes. More...

function GetPathLength ()
Get the minimum distance between the source and destination tiles. More...

function Preseed ()
Adds 'starter' tile groups across the map. More...

Private Member Functions

constructor ()

Seeds the grid points to Lakes. More...

function _AllGroups (StartGroupArray)
Given a starting group, return all groups attached to it. More...

Processes NextTiles neighbours. More...

Private Attributes

_heap_class = import("queue.fibonacci_heap", "", 3)

_map = null
AIList that tells which group each tile belongs in. More...

_connections = null
Array that shows the connections to each tile group. More...

_areas = null
Array of the defined tile groups. More...

_open_neighbours = null
Array of tiles that are open from each tile group. More...

_group_tiles = null
Array of AIList's of the tiles that are in each group. More...

_AGroup = null
array of groups containing source tiles More...

_BGroup = null
array of groups containing goal tiles More...

_A = null
array of source tiles More...

_B = null
array of goal tiles More...

_running = null
is Lakes currently running? More...

Detailed Description

Lakes.

Version
v.3 (2012-03-05)
Since
MetaLibrary v.7

Lakes is a replacement for WaterBody Check (_MinchinWeb_WBC_). Lakes serves to determine if two water tiles are connected by water (i.e. if a ship could sail between them). It trades memory usage for speed by caching results. Like WaterBody Check, it will keep trying to find a connections until there is no possible connection left.

Approximate program flow:

Depends On:
_MinchinWeb_DLS_
Depends On:
Fibonacci Heap v.3
_MinchinWeb_ShipPathfinder_
_MinchinWeb_WBC_
Note
Although _map and _group_tiles keep the same information (which tiles are in which group), there are independently created and maintained. If for some reason they become de-synced, Lakes will not work as expected. However, the previous approach of effectively creating _group_tiles from _map on the fly twice a loop was deemed too time demanding.

Definition at line 97 of file Lakes.nut.

Member Function Documentation

private

Seeds the grid points to Lakes.

Called by the class initialization function.

PreSeed()

Definition at line 388 of file Lakes.nut.

private

Processes NextTiles neighbours.

Parameters
 NextTile Tile we consider the neighbours of
Returns
[null] if no neighbours are added.
An array of the neighbours added otherwise.

Definition at line 502 of file Lakes.nut.

 function _MinchinWeb_Lakes_::_AllGroups ( StartGroupArray )
private

Given a starting group, return all groups attached to it.

Parameters
 StartGroupArray assumed to be an array
Returns
An array listing all the attached tile groups

Definition at line 466 of file Lakes.nut.

Seeds a point into Lakes.

Parameters
 myTileID Assumed to be a tile index.
Returns
Area the tile is in. -1 if the tile is on land.

Definition at line 397 of file Lakes.nut.

 _MinchinWeb_Lakes_::constructor ( )
inlineprivate

Definition at line 138 of file Lakes.nut.

 function _MinchinWeb_Lakes_::FindPath ( iterations )

Try to find if the source and goal tiles are within the same waterbody.

Parameters
 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.
Returns
'true' if within the same waterbody, or 'false' if the amount of iterations was reached, or 'null' if no path was found. You can call this function over and over as long as it returns false, which is an indication it is not yet done looking for a route.

Definition at line 233 of file Lakes.nut.

 function _MinchinWeb_Lakes_::GetPathLength ( )

Get the minimum distance between the source and destination tiles.

Note
Distance is calculated as Manhattan Distance

Definition at line 379 of file Lakes.nut.

 function _MinchinWeb_Lakes_::InitializePath ( sources , goals )
inline

Initialize a path search between sources and goals.

Parameters
 sources The source tiles. Assumed to be an array. goals The target tiles. Assumed to be an array.

Definition at line 155 of file Lakes.nut.

 function _MinchinWeb_Lakes_::Preseed ( )
inline

Adds 'starter' tile groups across the map.

This inserts any tile that is water that falls on an 8x8 grid. This is not required to be run before using the class.

Definition at line 229 of file Lakes.nut.

Member Data Documentation

 _MinchinWeb_Lakes_::_A = null
private

array of source tiles

Definition at line 133 of file Lakes.nut.

 _MinchinWeb_Lakes_::_AGroup = null
private

array of groups containing source tiles

Definition at line 131 of file Lakes.nut.

 _MinchinWeb_Lakes_::_areas = null
private

Array of the defined tile groups.

index is TileGroup.

Definition at line 117 of file Lakes.nut.

 _MinchinWeb_Lakes_::_B = null
private

array of goal tiles

Definition at line 134 of file Lakes.nut.

 _MinchinWeb_Lakes_::_BGroup = null
private

array of groups containing goal tiles

Definition at line 132 of file Lakes.nut.

 _MinchinWeb_Lakes_::_connections = null
private

Array that shows the connections to each tile group.

index is TileGroup.

Definition at line 111 of file Lakes.nut.

 _MinchinWeb_Lakes_::_group_tiles = null
private

Array of AIList's of the tiles that are in each group.

index is TileGroup

Note
Does not contain land tiles (i.e. group -1)

Definition at line 130 of file Lakes.nut.

 _MinchinWeb_Lakes_::_heap_class = import("queue.fibonacci_heap", "", 3)
private

Definition at line 98 of file Lakes.nut.

 _MinchinWeb_Lakes_::_map = null
private

AIList that tells which group each tile belongs in.

item is TileIndex, value is Group. value == -2 means the value remains unset, value == -1 means the tile is land.

Definition at line 105 of file Lakes.nut.

 _MinchinWeb_Lakes_::_open_neighbours = null
private

Array of tiles that are open from each tile group.

index is TileGroup; form is [Edge_Tile, Past_Edge_Tile]

Definition at line 123 of file Lakes.nut.

 _MinchinWeb_Lakes_::_running = null
private

is Lakes currently running?

Definition at line 136 of file Lakes.nut.

The documentation for this class was generated from the following file: