MinchinWeb's MetaLibrary v.11
Library functions for OpenTTD AI (and GS) writers.
Loading...
Searching...
No Matches
_MinchinWeb_Extras_ Class Reference

Extra functions. More...

Classes

class  Info

Public Member Functions

function MinDistance (TileID, TargetArray)
 Get the minimum distance between TileID and any of the tiles in TargetArray.
function MultiMax (i1, i2)
function MultiMax (i1, i2, i3)
function MultiMax (i1, i2, i3, i4)

Static Public Member Functions

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

Private Member Functions

 constructor ()

Private Attributes

 _infinity = null
 pointer to _MinchinWeb_C_::Infinity()

Detailed Description

Extra functions.

Version
v.7 (2025-07-14)
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

◆ AbsFloat()

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 321 of file Extras.nut.

◆ constructor()

_MinchinWeb_Extras_::constructor ( )
inlineprivate

Definition at line 37 of file Extras.nut.

◆ GetOpenTTDRevision()

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 391 of file Extras.nut.

◆ MaxAbsFloat()

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 311 of file Extras.nut.

◆ MaxAbsFloatKeepSign()

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 365 of file Extras.nut.

◆ MaxFloat()

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 345 of file Extras.nut.

◆ MidPoint()

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 249 of file Extras.nut.

◆ MinAbsFloat()

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 301 of file Extras.nut.

◆ MinAbsFloatKeepSign()

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 353 of file Extras.nut.

◆ MinDistance()

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 397 of file Extras.nut.

◆ MinFloat()

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 337 of file Extras.nut.

◆ MultiMax() [1/4]

function _MinchinWeb_Extras_::MultiMax ( i1 )
static

Get the maximum when provided with more than two inputs (up to four)

Parameters
i1...input values
Returns
the maximum value

Definition at line 406 of file Extras.nut.

◆ MultiMax() [2/4]

function _MinchinWeb_Extras_::MultiMax ( i1 ,
i2  )

Definition at line 409 of file Extras.nut.

◆ MultiMax() [3/4]

function _MinchinWeb_Extras_::MultiMax ( i1 ,
i2 ,
i3  )

Definition at line 412 of file Extras.nut.

◆ MultiMax() [4/4]

function _MinchinWeb_Extras_::MultiMax ( i1 ,
i2 ,
i3 ,
i4  )

Definition at line 415 of file Extras.nut.

◆ NextCardinalTile()

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 377 of file Extras.nut.

◆ Perpendicular()

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 258 of file Extras.nut.

◆ Sign()

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 329 of file Extras.nut.

◆ SignLocation()

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 238 of file Extras.nut.

◆ Slope()

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 267 of file Extras.nut.

◆ Within()

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 284 of file Extras.nut.

◆ WithinFloat()

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 291 of file Extras.nut.

Member Data Documentation

◆ _infinity

_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: