// we add it to the bottom, then bubble it up void InsertIntoArray( UnitInfo[] closestunits, UnitInfo newunit, int numexistingunits ) { if( numexistingunits < closestunits.GetUpperBound(0) + 1 ) { closestunits[ numexistingunits ] = newunit; numexistingunits++; } else { closestunits[ numexistingunits - 1 ] = newunit; } // bubble new unit up for( int i = numexistingunits - 2; i >= 0; i-- ) { if( closestunits[ i ].squareddistance > closestunits[ i + 1 ].squareddistance ) { UnitInfo swap = closestunits[ i ]; closestunits[ i ] = closestunits[ i + 1 ]; closestunits[ i + 1 ] = swap; } } // debug; // logfile.WriteLine( "AttackPackCoordinator.InsertIntoArray"); // for( int i = 0; i < numexistingunits; i++ ) // { // logfile.WriteLine(i + ": " + closestunits[ i ].squareddistance ); // } }