Skip to content

Commit

Permalink
Version 2 [r206 January 12, 2012]
Browse files Browse the repository at this point in the history
as tagged in SVN on Google Code
  • Loading branch information
MinchinWeb committed Nov 6, 2012
1 parent 93539ad commit 808b0c3
Show file tree
Hide file tree
Showing 12 changed files with 2,295 additions and 194 deletions.
93 changes: 69 additions & 24 deletions Arrays.nut
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Array SubLibrary, v.2 r.119 [2011-04-28],
* part of Minchinweb's MetaLibrary v1, r119, [2011-04-28],
* originally part of WmDOT v.5 r.53d [2011-04-09]
* and WmArray library v.1 r.1 [2011-02-13].
* Copyright © 2011 by W. Minchin. For more info,
/* Array SubLibrary, v.3 r.189 [2012-01-05],
* part of Minchinweb's MetaLibrary v2,
* originally part of WmDOT v.5 r.53d [2011-04-09]
* and WmArray library v.1 r.1 [2011-02-13].
* Copyright © 2011-12 by W. Minchin. For more info,
* please visit http://openttd-noai-wmdot.googlecode.com/
*/

Expand All @@ -15,26 +15,31 @@
* .ContainedIn1D(InArray, SearchValue)
* .ContainedIn2D(InArray, SearchValue)
* .ContainedIn3D(InArray, SearchValue)
* .ContainedIn1DIn2D(InArray2D, SearchArray1D)
* .Find1D(InArray, SearchValue)
* .Find2D(InArray, SearchValue)
* .Find3D(InArray, SearchValue)
* .RemoveValueAt(InArray, Index)
* .InsertValueAt(InArray, Index, Value)
* .ToStringTiles1D(InArrayOfTiles)
* .ToStringTiles1D(InArrayOfTiles, ArrayLength = false)
* .FindPairs(InArray2D, SearchValue1, SearchValue2)
* .ContainedInPairs(InArray2D, SearchValue1, SearchValue2)
* .Compare1D(InArray1D, TestArray1D)
*/

class _MetaLib_Array_ {
// To-DO
// - add safety if an array is not provided

class _MinchinWeb_Array_ {
main = null;
}

function _MetaLib_Array_::Create1D(length)
function _MinchinWeb_Array_::Create1D(length)
{
return array[length];
}

function _MetaLib_Array_::Create2D(length, width)
function _MinchinWeb_Array_::Create2D(length, width)
{
local ReturnArray = [length];
local tempArray = [width];
Expand All @@ -45,7 +50,7 @@ function _MetaLib_Array_::Create2D(length, width)
return ReturnArray;
}

function _MetaLib_Array_::Create3D(length, width, height)
function _MinchinWeb_Array_::Create3D(length, width, height)
{
local ReturnArray = [length];
local tempArray = [width];
Expand All @@ -62,7 +67,7 @@ function _MetaLib_Array_::Create3D(length, width, height)
return ReturnArray;
}

function _MetaLib_Array_::ToString1D(InArray)
function _MinchinWeb_Array_::ToString1D(InArray)
{
// Add error check that an array is provided

Expand All @@ -80,7 +85,7 @@ function _MetaLib_Array_::ToString1D(InArray)
}
}

function _MetaLib_Array_::ToString2D(InArray)
function _MinchinWeb_Array_::ToString2D(InArray)
{
// Add error check that a 2D array is provided

Expand All @@ -106,7 +111,7 @@ function _MetaLib_Array_::ToString2D(InArray)
}
}

function _MetaLib_Array_::ContainedIn1D(InArray, SearchValue)
function _MinchinWeb_Array_::ContainedIn1D(InArray, SearchValue)
{
// Searches the array for the given value. Returns 'TRUE' if found and
// 'FALSE' if not.
Expand All @@ -124,7 +129,7 @@ function _MetaLib_Array_::ContainedIn1D(InArray, SearchValue)
}
}

function _MetaLib_Array_::ContainedIn2D(InArray, SearchValue)
function _MinchinWeb_Array_::ContainedIn2D(InArray, SearchValue)
{
// Searches the array for the given value. Returns 'TRUE' if found and
// 'FALSE' if not.
Expand All @@ -147,7 +152,7 @@ function _MetaLib_Array_::ContainedIn2D(InArray, SearchValue)
}
}

function _MetaLib_Array_::ContainedIn3D(InArray, SearchValue)
function _MinchinWeb_Array_::ContainedIn3D(InArray, SearchValue)
{
// Searches the array for the given value. Returns 'TRUE' if found and
// 'FALSE' if not.
Expand All @@ -168,7 +173,25 @@ function _MetaLib_Array_::ContainedIn3D(InArray, SearchValue)
}
}

function _MetaLib_Array_::Find1D(InArray, SearchValue)
function _MinchinWeb_Array_::ContainedIn1DIn2D(InArray2D, SearchArray1D)
{
// Searches the array for the given array. Returns 'TRUE' if found and
// 'FALSE' if not.
// Accepts 2D Arrays for InArray and 1D Array for SearchArray

if (InArray2D == null) {
return null;
} else {
for (local i = 0; i < InArray2D.len(); i++ ) {
if (_MinchinWeb_Array_.Compare1D(InArray2D[i], SearchArray1D) == true) {
return true;
}
}
return false;
}
}

function _MinchinWeb_Array_::Find1D(InArray, SearchValue)
{
// Searches the array for the given value. Returns the index of the value if
// found and 'FALSE' if not. Will only return the index of the
Expand All @@ -190,7 +213,7 @@ function _MetaLib_Array_::Find1D(InArray, SearchValue)
}
}

function _MetaLib_Array_::Find2D(InArray, SearchValue)
function _MinchinWeb_Array_::Find2D(InArray, SearchValue)
{
// Searches the array for the given value. Returns a 2-item array with the
// indexes if found and 'FALSE' if not. Will only return the index of the
Expand All @@ -211,7 +234,7 @@ function _MetaLib_Array_::Find2D(InArray, SearchValue)
}
}

function _MetaLib_Array_::Find3D(InArray, SearchValue)
function _MinchinWeb_Array_::Find3D(InArray, SearchValue)
{
// Searches the array for the given value. Returns a 3-item array with the
// indexes if found and 'FALSE' if not. Will only return the index of the
Expand All @@ -233,7 +256,7 @@ function _MetaLib_Array_::Find3D(InArray, SearchValue)
}
}

function _MetaLib_Array_::RemoveValueAt(InArray, Index)
function _MinchinWeb_Array_::RemoveValueAt(InArray, Index)
{
// Removes the value at the index, and shifts the rest of the array to the
// left. The returned array is thus 1 shorter than the supplied array.
Expand All @@ -250,7 +273,7 @@ function _MetaLib_Array_::RemoveValueAt(InArray, Index)
return Return;
}

function _MetaLib_Array_::InsertValueAt(InArray, Index, Value)
function _MinchinWeb_Array_::InsertValueAt(InArray, Index, Value)
{
// Adds 'Value' to the 'InArray' at the given 'Index'. The rest of the array
// is shift one place to the right. The returned array is thus 1 longer
Expand All @@ -268,7 +291,7 @@ function _MetaLib_Array_::InsertValueAt(InArray, Index, Value)
return Return;
}

function _MetaLib_Array_::ToStringTiles1D(InArrayOfTiles)
function _MinchinWeb_Array_::ToStringTiles1D(InArrayOfTiles, ArrayLength = false)
{
// Add error check that an array is provided

Expand All @@ -282,11 +305,15 @@ function _MetaLib_Array_::ToStringTiles1D(InArrayOfTiles)
Temp = Temp + " " + AIMap.GetTileX(InArrayOfTiles[i]) + "," + AIMap.GetTileY(InArrayOfTiles[i]);
i++;
}
return ("The array is " + Length + " long. " + Temp + " ");
if (ArrayLength == true) {
return ("The array is " + Length + " long. " + Temp + " ");
} else {
return Temp;
}
}
}

function _MetaLib_Array_::FindPairs(InArray2D, SearchValue1, SearchValue2)
function _MinchinWeb_Array_::FindPairs(InArray2D, SearchValue1, SearchValue2)
{
// Searches the array for the given pair of value. Returns a the index
// if found and 'FALSE' if not. Will only return the index of the
Expand Down Expand Up @@ -319,7 +346,7 @@ function _MetaLib_Array_::FindPairs(InArray2D, SearchValue1, SearchValue2)
}
}

function _MetaLib_Array_::ContainedInPairs(InArray2D, SearchValue1, SearchValue2)
function _MinchinWeb_Array_::ContainedInPairs(InArray2D, SearchValue1, SearchValue2)
{
// Searches the array for the given pair of value. Returns a the index
// if found and 'FALSE' if not. Will only return the index of the
Expand Down Expand Up @@ -350,4 +377,22 @@ function _MetaLib_Array_::ContainedInPairs(InArray2D, SearchValue1, SearchValue2
}
return false;
}
}

function _MinchinWeb_Array_::Compare1D(InArray1D, TestArray1D)
{
// Compares the two arrays item for item. Returns true if every item pair
// matches.
// I wrote this because I don't trust (InArray == TestArray) to work this
// way...
if (InArray1D.len() != TestArray1D.len() ) {
return false;
}
for (local i = 0; i < InArray1D.len(); i++) {
if (InArray1D[i] != TestArray1D[i]) {
return false;
}
}

return true;
}
Loading

0 comments on commit 808b0c3

Please sign in to comment.