void GetClosestObjActor()
{
int obj;
int act;
int dist;
// This code can't detect any actors farther away than 255 units
// (pixels in newer games, characters in older ones.) But this is
// perfectly OK, as it is exactly how the original behaved.
int closest_obj = 0xFF, closest_dist = 0xFF;
GetResult();
act = GetVarOrDirectWord(OpCodeParameter.Param1);
obj = Variables[VariableActorRangeMax.Value];
do
{
dist = GetObjActToObjActDist(act, obj);
if (dist < closest_dist)
{
closest_dist = dist;
closest_obj = obj;
}
} while (--obj >= Variables[VariableActorRangeMin.Value]);
SetResult(closest_obj);
}