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

Extra functions. More...

Public Member Functions

function MinDistance (TileID, TargetArray)
 Get the minimum distance between TileID and any of the tiles in TargetArray. More...
 

Static Public Member Functions

function SignLocation (text)
 Get the location of a sign. More...
 
function MidPoint (TileA, TileB)
 Find the tile halfway between two other tiles. More...
 
function Perpendicular (SlopeIn)
 Get the perpendicular slope. More...
 
function Slope (TileA, TileB)
 Get the slope between two tiles. More...
 
function Within (Bound1, Bound2, Value)
 Does Value fall between the bounds? More...
 
function WithinFloat (Bound1, Bound2, Value)
 Does Value fall between the bounds? More...
 
function MinAbsFloat (Value1, Value2)
 Takes the absolute value of both numbers and then returns the smaller of the two. More...
 
function MaxAbsFloat (Value1, Value2)
 Takes the absolute value of both numbers and then returns the larger of the two. More...
 
function AbsFloat (Value)
 Returns the absolute value of a given number. More...
 
function Sign (Value)
 Returns the sign of a given number. More...
 
function MinFloat (Value1, Value2)
 Returns the smaller of the two numbers. More...
 
function MaxFloat (Value1, Value2)
 Returns the larger of the two numbers. More...
 
function MinAbsFloatKeepSign (Value1, Value2)
 Takes the absolute value of both numbers and then returns the number with the lesser of the two, sign intact. More...
 
function MaxAbsFloatKeepSign (Value1, Value2)
 Takes the absolute value of both numbers and then returns the number with the greater of the two, sign intact. More...
 
function NextCardinalTile (StartTile, TowardsTile)
 The tile that is neighbouring StartTile that is closest to TowardsTile More...
 
function GetOpenTTDRevision ()
 Returns the revision number of the current build of OpenTTD. More...
 

Private Member Functions

 constructor ()
 

Private Attributes

 _infinity = null
 pointer to _MinchinWeb_C_::Infinity() More...
 

Detailed Description

Extra functions.

Version
v.5 (2012-07-01)
Author
W. Minchin (MinchinWeb)
Since
MetaLibrary v.1

These are 'random' functions that didn't seem to fit well elsewhere. Many of them are math helper functions. Many others are helpful in dealing geometry.

Definition at line 34 of file Extras.nut.

Member Function Documentation

function _MinchinWeb_Extras_::AbsFloat ( Value  )
static

Returns the absolute value of a given number.

Returns
the absolute value of a given number (this will always be positive) (this will typically be a floating point number).

Definition at line 296 of file Extras.nut.

_MinchinWeb_Extras_::constructor ( )
inlineprivate

Definition at line 37 of file Extras.nut.

function _MinchinWeb_Extras_::GetOpenTTDRevision ( )
static

Returns the revision number of the current build of OpenTTD.

See also
See AILib.Common for more details on what is contained in the full returned version number.
Note
I determine this at the beginning of my AI's run so that when I get bug reports, I know what version of OpenTTD was being run.
This might also be useful if you want to turn on or off certain features, depending on if they are in the user's version of OpenTTD.

Definition at line 367 of file Extras.nut.

function _MinchinWeb_Extras_::MaxAbsFloat ( Value1  ,
Value2   
)
static

Takes the absolute value of both numbers and then returns the larger of the two.

Returns
the magnitude of the value farther to zero (this will always be positive).
See also
MinAbsFloat()
MaxAbsFloatKeepSign()

Definition at line 286 of file Extras.nut.

function _MinchinWeb_Extras_::MaxAbsFloatKeepSign ( Value1  ,
Value2   
)
static

Takes the absolute value of both numbers and then returns the number with the greater of the two, sign intact.

See also
MinAbsFloatKeepSign()
MaxAbsFloat()

Definition at line 341 of file Extras.nut.

function _MinchinWeb_Extras_::MaxFloat ( Value1  ,
Value2   
)
static

Returns the larger of the two numbers.

Returns
The larger of the two numbers, as a floating point number.
See also
MinFloat()

Definition at line 321 of file Extras.nut.

function _MinchinWeb_Extras_::MidPoint ( TileA  ,
TileB   
)
static

Find the tile halfway between two other tiles.

Parameters
TileAone 'end' tile
TileBthe other 'end' tile
Returns
the TileID of the tile halfway between TileA and TileB

Definition at line 223 of file Extras.nut.

function _MinchinWeb_Extras_::MinAbsFloat ( Value1  ,
Value2   
)
static

Takes the absolute value of both numbers and then returns the smaller of the two.

Returns
the magnitude of the value closer to zero (this will always be positive).
See also
MinAbsFloatKeepSign()
MaxAbsFloat()

Definition at line 276 of file Extras.nut.

function _MinchinWeb_Extras_::MinAbsFloatKeepSign ( Value1  ,
Value2   
)
static

Takes the absolute value of both numbers and then returns the number with the lesser of the two, sign intact.

See also
MaxAbsFloatKeepSign()
MinAbsFloat()

Definition at line 329 of file Extras.nut.

function _MinchinWeb_Extras_::MinDistance ( TileID  ,
TargetArray   
)

Get the minimum distance between TileID and any of the tiles in TargetArray.

Note
This is designed such that it can be run as a validator on an AIList of tiles
Parameters
TileIDTile we measure distance from
TargetArrayAn array to tiles that we want to measure distance to. This can also be an AIList where the items are tiles.
Returns
the minimum distance between TileID and any of the TargetArray
Note
Distances is measured using Manhattan Distance
Distances to invalid tiles is reported as -1; therefore invalid tiles are always 'closer' that valid tiles.
Todo:
Remove invalid tiles from the TargetArray

Definition at line 373 of file Extras.nut.

function _MinchinWeb_Extras_::MinFloat ( Value1  ,
Value2   
)
static

Returns the smaller of the two numbers.

Returns
The smaller of the two numbers, as a floating point number.
See also
MaxFloat()

Definition at line 313 of file Extras.nut.

function _MinchinWeb_Extras_::NextCardinalTile ( StartTile  ,
TowardsTile   
)
static

The tile that is neighbouring StartTile that is closest to TowardsTile

Given a StartTile and a TowardsTile, will give the tile immediately next (Manhattan Distance == 1) to StartTile that is closest to TowardsTile.

Returns
a neighbouring tile to StartTile

Definition at line 353 of file Extras.nut.

function _MinchinWeb_Extras_::Perpendicular ( SlopeIn  )
static

Get the perpendicular slope.

Parameters
SlopeInoriginal slope
Returns
slope perpendicular to SlopeIn (as a floating point number)
Note
Perpendicular slopes are inverses of each other.
See also
Slope()
_MinchinWeb_C_.Infinity()

Definition at line 232 of file Extras.nut.

function _MinchinWeb_Extras_::Sign ( Value  )
static

Returns the sign of a given number.

Returns
+1 if the Value >= 0, -1 Value < 0

Definition at line 305 of file Extras.nut.

function _MinchinWeb_Extras_::SignLocation ( text  )
static

Get the location of a sign.

Parameters
textmessage to search for
Returns
TileID of the first instance where the sign matches the given text.
null if no matching sign can be found.

Definition at line 212 of file Extras.nut.

function _MinchinWeb_Extras_::Slope ( TileA  ,
TileB   
)
static

Get the slope between two tiles.

Parameters
TileAfirst 'end' tile
TileBtile at the other 'end'
Returns
Slope between the two tiles (typically as a floating point number.
If the slope is vertical, "Infinity (`Constants.Infinity()`)" is returned.
If the slope is flat (i.e. 0), 1/Infinity is returned.
See also
_MinchinWeb_C_.Infinity()

Definition at line 241 of file Extras.nut.

function _MinchinWeb_Extras_::Within ( Bound1  ,
Bound2  ,
Value   
)
static

Does Value fall between the bounds?

Parameters
Bound1one limit
Bound2another limit
Valuethe value being tested
Returns
True is Value falls between the bounds, False otherwise.
Note
This is helpful in that there is no requirement that Bound1 be larger than Bound2 or vis-versa.
See also
WithinFloat()

Definition at line 258 of file Extras.nut.

function _MinchinWeb_Extras_::WithinFloat ( Bound1  ,
Bound2  ,
Value   
)
static

Does Value fall between the bounds?

Parameters
Bound1one limit
Bound2another limit
Valuethe value being tested
Returns
True is Value falls between the bounds, False otherwise.
Note
This is helpful in that there is no requirement that Bound1 be larger than Bound2 or vis-versa.
This version explicitly converts all three parameters to floating point numbers before comparing them.
See also
Within()

Definition at line 266 of file Extras.nut.

Member Data Documentation

_MinchinWeb_Extras_::_infinity = null
private

pointer to _MinchinWeb_C_::Infinity()

Definition at line 35 of file Extras.nut.


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