Guest
Public paste!

Untitled

By: a guest | Apr 28th, 2010 | Syntax: None | Size: 0.64 KB | Hits: 61 | Expires: Never
Copy text to clipboard
  1.  
  2. unit getSecondClosestUnit(unit u)
  3. {
  4.         unit closest;
  5.         unit secondClosest;
  6.  
  7.         unitgroup g = /* code to get unit group that covers all units across the map here */;
  8.         UnitGroupLoopBegin(g);
  9.         while( !UnitGroupLoopDone() )
  10.         {
  11.                 if( !closest || DistanceToUnit(u, closest) > DistanceToUnit(u, UnitGroupLoopCurrent()) )
  12.                 {
  13.                         closest = UnitGroupLoopCurrent();
  14.                         UnitGroupLoopStep();
  15.                         continue;
  16.                 }
  17.  
  18.                 if( !secondClosest || DistanceToUnit(u, secondClosest) > DistanceToUnit(u, UnitGroupLoopCurrent()) )
  19.                 {
  20.                         secondClosest = UnitGroupLoopCurrent();
  21.                         UnitGroupLoopStep();
  22.                         continue;
  23.                 }
  24.         }
  25.         UnitGroupLoopEnd();
  26.  
  27.         return secondClosest;
  28. }