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

Array. More...

Static Public Member Functions

function Create1D (length)
 Creates a one dimensional (1-D) array. More...
 
function Create2D (length, width)
 Creates a two dimensional (2-D) array. More...
 
function Create3D (length, width, height)
 Creates a three dimensional (3-D) array. More...
 
function ToString1D (InArray, DisplayLength=true, replaceNull=false)
 Converts a one dimensional array to a nice string format. More...
 
function ToString2D (InArray, DisplayLength=true)
 Converts a one dimensional array to a nice string format. More...
 
function ContainedIn1D (InArray, SearchValue)
 Searches an array for a given value. More...
 
function ContainedIn2D (InArray, SearchValue)
 Searches a (two dimensional) array for a given value. More...
 
function ContainedIn3D (InArray, SearchValue)
 Searches a (three dimensional) array for a given value. More...
 
function ContainedIn1DIn2D (InArray2D, SearchArray1D)
 Searches a two dimensional array for a given one dimensional array. More...
 
function Find1D (InArray, SearchValue)
 Searches an array for a given value. More...
 
function Find2D (InArray, SearchValue)
 Searches an array for a given value. More...
 
function Find3D (InArray, SearchValue)
 Searches an array for a given value. More...
 
function RemoveValueAt (InArray, Index)
 Removes an element from the array. More...
 
function InsertValueAt (InArray, Index, Value)
 Adds an element from the array. More...
 
function ToStringTiles1D (InArrayOfTiles, ArrayLength=false)
 Converts a one dimensional array of tiles to a nice string format. More...
 
function ToStringTiles2D (InArrayOfTiles, ArrayLength=false)
 Converts a one dimensional array of tiles to a nice string format. More...
 
function FindPairs (InArray2D, SearchValue1, SearchValue2)
 Searches an array for a given pair of values. More...
 
function ContainedInPairs (InArray2D, SearchValue1, SearchValue2)
 Searches an array for a given pair of values. More...
 
function Compare1D (InArray1D, TestArray1D)
 Compares the two arrays item for item. More...
 
function Append (Array1, Array2)
 Appends one array to another. More...
 
function RemoveDuplicates (Array)
 Removes duplicates from an array. More...
 
function ToAIList (Array)
 Turns an Array in an AIList. More...
 

Private Attributes

 main = null
 

Detailed Description

Array.

Version
v.5 (2014-02-28)
Author
W. Minchin (MinchinWeb)
Since
MetaLibrary v.6

This is a collection of functions to make working with Arrays easier.

Note
While Arrays are powerful, also consider using AIList's.

Definition at line 30 of file Array.nut.

Member Function Documentation

function _MinchinWeb_Array_::Append ( Array1  ,
Array2   
)
static

Appends one array to another.

Parameters
Array1the first array
Array2the second array
Returns
An array that the items has Array2 appended to the end of the items of Array1
Note
Consider using Squirrel's built-in function: MyArray.append(Item) to append individual items to an array

Definition at line 672 of file Array.nut.

function _MinchinWeb_Array_::Compare1D ( InArray1D  ,
TestArray1D   
)
static

Compares the two arrays item for item.

Returns true if every item pair matches.

Parameters
InArray1Done dimensional (1-D) array, that is considered 'known'
TestArray1Done dimensional (1-D) array, that is considered 'unknown'
Returns
true if the InArray1D and TestArray1D equal each other for the comparison of each pair of elements. false otherwise.
Note
I wrote this because I don't trust InArray == TestArray to work this way...

Definition at line 659 of file Array.nut.

function _MinchinWeb_Array_::ContainedIn1D ( InArray  ,
SearchValue   
)
static

Searches an array for a given value.

Parameters
InArrayarray to search (assumed to be one dimensional (1-D))
SearchValuewhat is searched for
Returns
true if found at least once, false if not. null if InArray is null.
See also
ContainedIn1DIn2D()
ContainedIn2D()
ContainedIn3D()
Find1D()
Todo:
Add error check that an array is provided

Definition at line 434 of file Array.nut.

function _MinchinWeb_Array_::ContainedIn1DIn2D ( InArray2D  ,
SearchArray1D   
)
static

Searches a two dimensional array for a given one dimensional array.

Parameters
InArrayarray to search (assumed to be two dimensional (2-D))
SearchValuearray to search for (assumed to be one dimensional (1-D))
Returns
true if found at least once, false if not. null if InArray is null.
See also
ContainedIn1D()
Todo:
Add error check that arrays are provided

Definition at line 478 of file Array.nut.

function _MinchinWeb_Array_::ContainedIn2D ( InArray  ,
SearchValue   
)
static

Searches a (two dimensional) array for a given value.

Parameters
InArrayarray to search (assumed to be two dimensional (2-D))
SearchValuewhat is searched for
Returns
true if found at least once, false if not. null if InArray is null.
Note
using this to see if an given array is an element of the parent array does not seem to be returning expected results. Use ContainedInPairs() instead.
See also
ContainedInPairs()
ContainedIn1DIn2D()
ContainedIn1D()
ContainedIn3D()
Find2D()
Todo:
Add error check that an array is provided

Definition at line 447 of file Array.nut.

function _MinchinWeb_Array_::ContainedIn3D ( InArray  ,
SearchValue   
)
static

Searches a (three dimensional) array for a given value.

Parameters
InArrayarray to search (assumed to be three dimensional (3-D))
SearchValuewhat is searched for
Returns
true if found at least once, false if not. null if InArray is null.
See also
Find3D()
Todo:
Add error check that an array is provided

Definition at line 462 of file Array.nut.

function _MinchinWeb_Array_::ContainedInPairs ( InArray2D  ,
SearchValue1  ,
SearchValue2   
)
static

Searches an array for a given pair of values.

The idea is to provide an array of arrays of pairs (e.g. tile x and tile y, starting and ending points, etc.), and find out if SearchValue1 and SearchValue2 are among the pairs. The order that SearchValue1 and SearchValue2 are in is not considered.

Parameters
InArray2Dtwo dimensional (2-D) array
SearchValue1value to search for
SearchValue2value to search for
Returns
true if the search values are found at least once, false otherwise. null if InArray2D is null.
See also
FindInPairs()
Todo:
Add error check that a 2D array is provided

Definition at line 634 of file Array.nut.

function _MinchinWeb_Array_::Create1D ( length  )
inlinestatic

Creates a one dimensional (1-D) array.

Parameters
lengththe desired length of the array
Returns
empty array of the given size
See also
Create2D()
Create3D()

Definition at line 41 of file Array.nut.

function _MinchinWeb_Array_::Create2D ( length  ,
width   
)
static

Creates a two dimensional (2-D) array.

Parameters
lengththe desired length of the array (in the first dimension)
widththe desired length of the array (in the second dimension)
Returns
empty array of the given size (in two dimensions)
See also
Create1D()
Create3D()

Definition at line 360 of file Array.nut.

function _MinchinWeb_Array_::Create3D ( length  ,
width  ,
height   
)
static

Creates a three dimensional (3-D) array.

Parameters
lengththe desired length of the array (in the first dimension)
widththe desired length of the array (in the second dimension)
heightthe desired length of the array (in the third dimension)
Returns
empty array of the given size (in three dimensions)
See also
Create1D()
Create2D()

Definition at line 369 of file Array.nut.

function _MinchinWeb_Array_::Find1D ( InArray  ,
SearchValue   
)
static

Searches an array for a given value.

Parameters
InArrayarray to search (assumed to be two dimensional (2-D))
SearchArrayarray to search for (assumed to be one dimensional (1-D))
Returns
array index of the first time SearchValue is found (as an integer), false if not. null if InArray is null.
See also
ContainedIn1D()
Find2D()
Find3D()
FindPairs()
Note
using this to see if an given array is an element of the parent array does not seem to be returning expected results. Use FindPairs() instead.
Todo:
Add error check that an array is provided

Definition at line 491 of file Array.nut.

function _MinchinWeb_Array_::Find2D ( InArray  ,
SearchValue   
)
static

Searches an array for a given value.

Parameters
InArrayarray to search (assumed to be two dimensional (2-D))
SearchValuewhat is searched for
Returns
array index of the first time SearchValue is found (as an two dimensional array, of the from [i, j]), false if not. null if InArray is null.
See also
ContainedIn2D()
Find1D()
Find3D()
Todo:
Add error check that an array is provided

Definition at line 504 of file Array.nut.

function _MinchinWeb_Array_::Find3D ( InArray  ,
SearchValue   
)
static

Searches an array for a given value.

Parameters
InArrayarray to search (assumed to be three dimensional (3-D))
SearchValuewhat is searched for
Returns
array index of the first time SearchValue is found (as an three dimensional array, of the from [i, j, k]), false if not. null if InArray is null.
See also
ContainedIn3D()
Find1D()
Find2D()
Todo:
Add error check that an array is provided

Definition at line 519 of file Array.nut.

function _MinchinWeb_Array_::FindPairs ( InArray2D  ,
SearchValue1  ,
SearchValue2   
)
static

Searches an array for a given pair of values.

The idea is to provide an array of arrays of pairs (e.g. tile x and tile y, starting and ending points, etc.), and find out if SearchValue1 and SearchValue2 are among the pairs. The order that SearchValue1 and SearchValue2 is not considered.

Parameters
InArray2Dtwo dimensional (2-D) array
SearchValue1values to search for
SearchValue2values to search for
Returns
index (as an integer) of the array matching the search values. null if InArray2D is null.
See also
ContainedInPairs()
Todo:
Add error check that a 2D array is provided

Definition at line 609 of file Array.nut.

function _MinchinWeb_Array_::InsertValueAt ( InArray  ,
Index  ,
Value   
)
static

Adds an element from the array.

Adds Value to the InArray at the given Index. The rest of the array is shifted one place to the right. The returned array is thus one longer than InArray.

Parameters
InArraythe array to add the element to
Indexthe index of where to add Value at
Valuethe element to add
Returns
InArray, now with the element Value at Index, the elements beyond it shifted to the right.
Todo:

Add error check that an array is provided

Add error check that Index is reasonable

Definition at line 549 of file Array.nut.

function _MinchinWeb_Array_::RemoveDuplicates ( Array  )
static

Removes duplicates from an array.

The item is maintain at its first location and removed at all subsequent locations.

Parameters
Arrayarray to remove duplicates from
Returns
An array minus the duplicate items.
Todo:
Add error check that an array is provided.

Definition at line 684 of file Array.nut.

function _MinchinWeb_Array_::RemoveValueAt ( InArray  ,
Index   
)
static

Removes an element from the array.

Removes the value at the index, and shifts the rest of the array to the left. The returned array is thus one shorter than the supplied array.

Parameters
InArraythe array to remove the element from
Indexthe index of the element to remove
Returns
InArray sans the element at Index, the elements beyond it are shifted to the left.
Todo:
Add error check that an array is provided

Definition at line 535 of file Array.nut.

function _MinchinWeb_Array_::ToAIList ( Array  )
static

Turns an Array in an AIList.

Returns
An AIList with the contents of the Array
Todo:
Add error check that an array is provided.

Definition at line 697 of file Array.nut.

function _MinchinWeb_Array_::ToString1D ( InArray  ,
DisplayLength  = true,
replaceNull  = false 
)
static

Converts a one dimensional array to a nice string format.

This function was created to aid in the output of arrays to the AI debug screen.

Parameters
InArrayone dimensional (1-D) array
DisplayLengthwhether to prefix the output with the length of the array
replaceNullwhether the replace null values with '-'
Returns
string version of array. e.g. The array is 3 long. 3 4 5.
null if InArray is null.
See also
ToString2D()
ToStringTiles1D()
Todo:
Add error check that an array is provided

Definition at line 382 of file Array.nut.

function _MinchinWeb_Array_::ToString2D ( InArray  ,
DisplayLength  = true 
)
static

Converts a one dimensional array to a nice string format.

This function was created to aid in the output of arrays to the AI debug screen.

Parameters
InArraytwo dimensional (2-D) array
DisplayLengthwhether to prefix the output with the length of the array
Returns
string version of array. e.g. The array is 2 long. 3 4 / 5 6.
null if InArray is null.
See also
ToString1D()
ToStringTiles2D()
Todo:
Add error check that a 2D array is provided

Definition at line 404 of file Array.nut.

function _MinchinWeb_Array_::ToStringTiles1D ( InArrayOfTiles  ,
ArrayLength  = false 
)
static

Converts a one dimensional array of tiles to a nice string format.

This function was created to aid in the output of arrays of tiles to the AI debug screen.

Parameters
InArrayOfTilesone dimensional (1-D) array of Tiles
ArrayLength(true or false) whether to print the prefix noting the length of the array. Default is false.
Returns
string version of array. e.g. The array is 3 long. 12,45 62,52 59,10.
null if InArrayOfTiles is null.
See also
ToString1D()
ToStringTiles2D()
Todo:

Add error check that an array is provided

Add a better error message if you try and feed it not a 1-D array

Definition at line 563 of file Array.nut.

function _MinchinWeb_Array_::ToStringTiles2D ( InArrayOfTiles  ,
ArrayLength  = false 
)
static

Converts a one dimensional array of tiles to a nice string format.

This function was created to aid in the output of arrays of tiles to the AI debug screen.

Parameters
InArrayOfTilestwo dimensional (2-D) array of Tiles
ArrayLength(true or false) whether to print the prefix noting the length of the array. Default is false.
Returns
string version of array. e.g. The array is 2 long. 12,45 62,52 / 59,10 5,37.
null if InArrayOfTiles is null.
See also
ToString2D()
ToStringTiles1D()
Todo:

Add error check that an array is provided

Add a better error message if you try and feed it not a 2-D array

Definition at line 579 of file Array.nut.

Member Data Documentation

_MinchinWeb_Array_::main = null
private

Definition at line 31 of file Array.nut.


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