Difference between revisions of "GetDistanceInTiles"

From UODemo Wiki
Jump to: navigation, search
(decompilation fix)
Line 3: Line 3:
 
This function will calculate the absolute value of the difference between A and B (for both x and y) and the highest value of the two is returned. The Z value is ignored when calculating the difference.
 
This function will calculate the absolute value of the difference between A and B (for both x and y) and the highest value of the two is returned. The Z value is ignored when calculating the difference.
 
Pseudo-code (using signed integers):<pre>
 
Pseudo-code (using signed integers):<pre>
integer DistanceInTiles(location A, location B)
+
integer getDistanceInTiles(location A, location B)
 
{
 
{
 
   // NOTE TO SELF: I should clear this up when I'm not so sleepy
 
   // NOTE TO SELF: I should clear this up when I'm not so sleepy

Revision as of 22:41, 14 April 2010

integer getDistanceInTiles(location A, location B);

This function will calculate the absolute value of the difference between A and B (for both x and y) and the highest value of the two is returned. The Z value is ignored when calculating the difference.

Pseudo-code (using signed integers):
integer getDistanceInTiles(location A, location B)
{
  // NOTE TO SELF: I should clear this up when I'm not so sleepy
  tmpx = A.x >= 5120 ? 1 : 0;
  tmpy = B.x >= 5120 ? 1 : 0;
  if(tmpx ^ tmpy != 0)
    return 9999;

  Xdiff = A.x - B.x;
  ydiff = A.y - B.y;
  
  if(xdiff < 0)
    xdiff = -xdiff;
  if(ydiff < 0)
    ydiff = -ydiff;

  if(A.x < 5120)
  {
    if(5120 - xdiff > xdiff)
      xdiff = 5120 - xdiff;
    if(4096 - ydiff > ydiff)
      ydiff = 4096 - ydiff;
  }

  if(xdiff > ydiff)
    retval = xdiff;
  else
    retval = ydiff;

  return retval;
}

Return to the Command List.