home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GameStar 2006 April
/
Gamestar_83_2006-04_dvd.iso
/
Dema
/
demowot_english.exe
/
Script
/
Source
/
IterateInOrder.sma
< prev
next >
Wrap
Text File
|
2005-03-11
|
961b
|
52 lines
#include "script.inc"
#define ARRAY_MAXLENGTH 50
stock ItFillArray( Selector[], DrID:Array[], MaxLength )
{
static StringArray[ARRAY_MAXLENGTH][STRID_MAX_LENGTH];
new DrID:Entity;
new Length = 0;
new Iterator:i = Iterate( Selector );
while( ItNext(i))
PutInArrayOrdered( ItEntity(i), Array, &Length );
ItStop(i);
}
stock PutInArrayOrdered( DrID:Entity, DrID:Array, &Length ) // Binaris kereses, majd beszuras
{
new LowerLimit = 0;
new UpperLimit = Length;
new i;
new CurrentName[STRID_MAX_LENGTH];
GetPropertyString( Entity, "StringID", STRID_MAX_LENGTH, CurrentName );
do {
i = ( UpperLimit + LowerLimit ) / 2;
if( CompareString( CurrentName, StringArray[i] ) >= 0 ) {
LowerLimit = i;
} else {
UpperLimit = i;
}
} while( ( abs( i - LowerLimit ) > 1 ) && ( abs( i - UpperLimit ) > 1 ) ); // Ha mar elertuk a hatart, abbahagyjuk
Array[i] =
Length++;
}