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

Line Walker. More...

Public Member Functions

function Start (Tile)
 Sets the starting tile for LineWalker. More...
 
function End (Tile)
 Sets the ending tile for LineWalker. More...
 
function Slope (Slope, ThirdQuadrant=false)
 Sets the slope for LineWalker. More...
 
function Reset ()
 Resets the variables for the LineWalker. More...
 
function Restart ()
 Moves the LineWalker to the original starting position. More...
 
function Walk ()
 'Walks' the LineWalker one tile at a tile More...
 
function IsEnd ()
 Returns True if we are at the edge of the bounding box defined by the Starting and Ending point. More...
 
function GetStart ()
 Returns the tile the LineWalker is starting on. More...
 
function GetEnd ()
 Returns the tile the LineWalker is ending on. More...
 

Private Member Functions

 constructor ()
 

Private Attributes

 _start = null
 start tile More...
 
 _end = null
 end tile More...
 
 _slope = null
 line slope More...
 
 _startx = null
 x value of start tile More...
 
 _starty = null
 y value of start tile More...
 
 _endx = null
 x value of end tile More...
 
 _endy = null
 y value of end tile More...
 
 _past_end = null
 
 _x = null
 x value of current tile More...
 
 _y = null
 y value of current tile More...
 
 _dirx = null
 
 _current_tile = null
 current tile More...
 

Detailed Description

Line Walker.

Version
v.1 (2012-01-28)
Author
W. Minchin (MinchinWeb)
Since
MetaLibrary v.4

The LineWalker class allows you to define a starting and endpoint, and then 'walk' all the tiles between the two. Alternately, you can give a starting point and a slope. It was originally part of my Ship Pathfinder, also part of Minchinweb's MetaLibrary.

Note
Plane geometry does funky things when you don't have an infinity, or by extension, zero (the inverse of infinity) for slopes. To get around the fact integer conversions drop everything past the decimal point (effectively rounding down), slopes are set so that there is a slight inflection point at the 'origin' so that as you move out from the start point, so stay slightly above the 'unchanging' index...
LineWalker is designed to be a persistent class.
See also
_MinchinWeb_SW_

Definition at line 53 of file Line.Walker.nut.

Member Function Documentation

_MinchinWeb_LW_::constructor ( )
inlineprivate

Definition at line 67 of file Line.Walker.nut.

function _MinchinWeb_LW_::End ( Tile  )

Sets the ending tile for LineWalker.

Note
If the slope is also directly set, the start and end tiles define a bounding box. Otherwise, the slope is calculated between the start and end tiles.
See also
Start()
Slope()
GetEnd()

Definition at line 187 of file Line.Walker.nut.

function _MinchinWeb_LW_::GetEnd ( )
inline

Returns the tile the LineWalker is ending on.

Returns
The tile the LineWalker is ending on
See also
End()
IsEnd()

Definition at line 142 of file Line.Walker.nut.

function _MinchinWeb_LW_::GetStart ( )
inline

Returns the tile the LineWalker is starting on.

Returns
The tile the LineWalker is starting on
See also
Start()

Definition at line 135 of file Line.Walker.nut.

function _MinchinWeb_LW_::IsEnd ( )
inline

Returns True if we are at the edge of the bounding box defined by the Starting and Ending point.

Returns
True if we are at the edge of the bounding box defined by the Starting and Ending point
See also
End()
GetEnd()

Definition at line 129 of file Line.Walker.nut.

function _MinchinWeb_LW_::Reset ( )

Resets the variables for the LineWalker.

See also
Restart()

Definition at line 260 of file Line.Walker.nut.

function _MinchinWeb_LW_::Restart ( )

Moves the LineWalker to the original starting position.

See also
Reset()

Definition at line 275 of file Line.Walker.nut.

function _MinchinWeb_LW_::Slope ( Slope  ,
ThirdQuadrant  = false 
)

Sets the slope for LineWalker.

Note
Assumes that the slope is in the first or second quadrant unless ThirdQuadrant == true
Todo:
Add a picture of the four Cartesian quadrants

Definition at line 220 of file Line.Walker.nut.

function _MinchinWeb_LW_::Start ( Tile  )

Sets the starting tile for LineWalker.

See also
End()
Slope()
Restart()
Reset()
GetStart()

Definition at line 148 of file Line.Walker.nut.

function _MinchinWeb_LW_::Walk ( )

'Walks' the LineWalker one tile at a tile

Returns
the tile that the LineWalker is now "standing on"
Note
This is where (most) of the action is!
Before calling this function, you need to set the Start() and at least one of End() or Slope().

Definition at line 284 of file Line.Walker.nut.

Member Data Documentation

_MinchinWeb_LW_::_current_tile = null
private

current tile

Definition at line 65 of file Line.Walker.nut.

_MinchinWeb_LW_::_dirx = null
private

Definition at line 64 of file Line.Walker.nut.

_MinchinWeb_LW_::_end = null
private

end tile

Definition at line 55 of file Line.Walker.nut.

_MinchinWeb_LW_::_endx = null
private

x value of end tile

Definition at line 59 of file Line.Walker.nut.

_MinchinWeb_LW_::_endy = null
private

y value of end tile

Definition at line 60 of file Line.Walker.nut.

_MinchinWeb_LW_::_past_end = null
private

Definition at line 61 of file Line.Walker.nut.

_MinchinWeb_LW_::_slope = null
private

line slope

Definition at line 56 of file Line.Walker.nut.

_MinchinWeb_LW_::_start = null
private

start tile

Definition at line 54 of file Line.Walker.nut.

_MinchinWeb_LW_::_startx = null
private

x value of start tile

Definition at line 57 of file Line.Walker.nut.

_MinchinWeb_LW_::_starty = null
private

y value of start tile

Definition at line 58 of file Line.Walker.nut.

_MinchinWeb_LW_::_x = null
private

x value of current tile

Definition at line 62 of file Line.Walker.nut.

_MinchinWeb_LW_::_y = null
private

y value of current tile

Definition at line 63 of file Line.Walker.nut.


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