GetDistance(tid)

Moderator: GZDoom Developers

Post Reply
User avatar
Cutmanmike
Posts: 11335
Joined: Mon Oct 06, 2003 3:41 pm
Operating System Version (Optional): Windows 10
Location: United Kingdom
Contact:

GetDistance(tid)

Post by Cutmanmike »

Since you can do this in ACS anyway (with a bit more hassle) why not have this? A little low priority but there you go
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Post by Graf Zahl »

Code: Select all


function int abs(int x)
{
  if (x>=0) return x;
  return -x;
}

function int min(int x, int y)
{
    if (x<y) return x;
    else return y;
}

function int AproxDistance(int dx, int dy)
{
	int dx = abs(dx);
	int dy = abs(dy);
	return dx+dy-(min(dx,dy)>>1);
}

function void GetDistance(int tid)
{
    int x=abs(GetActorX(tid)-GetActorX(activatortid()));
    int y=abs(GetActorY(tid)-GetActorY(activatortid()));
    int z=abs(GetActorZ(tid)-GetActorZ(activatortid()));

    return AproxDistance(AproxDistance(x,y), z);
}

It used the same precision Doom is using internally for distance calculations as a fixed point value.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: GetDistance(tid)

Post by Macil »

cutmanmike wrote:Since you can do this in ACS anyway (with a bit more hassle) why not have this? A little low priority but there you go
What would it do? And don't you need two things to be able to tell the distance between them?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Post by Graf Zahl »

Look at my code. One is the activator, the other the specified tid.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Post by Macil »

Oh, I see. I never looked at it closely enough.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”