[DIY] GetDistance(tid)

Moderator: GZDoom Developers

GetDistance(tid)

Postby Cutmanmike » Fri Mar 11, 2005 7:00 am

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
Cutmanmike
Is it hot in here or is it just ZScript
 
Joined: 06 Oct 2003
Location: United Kingdom
Discord: https://discord.gg/Whts7Bj
Operating System: Windows Vista/7/2008 64-bit

Postby Graf Zahl » Fri Mar 11, 2005 8:14 am

Code: Select allExpand view

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: GetDistance(tid)

Postby Agent ME » Fri Mar 11, 2005 5:26 pm

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
Agent ME
Title Not Found
 
Joined: 22 Mar 2004
Location: California, USA
Discord: Macil#5633
Twitch ID: macil_tech
Github ID: Macil

Postby Graf Zahl » Fri Mar 11, 2005 5:32 pm

Look at my code. One is the activator, the other the specified tid.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Postby Agent ME » Fri Mar 11, 2005 5:58 pm

Oh, I see. I never looked at it closely enough.
User avatar
Agent ME
Title Not Found
 
Joined: 22 Mar 2004
Location: California, USA
Discord: Macil#5633
Twitch ID: macil_tech
Github ID: Macil


Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests