Please do not question the mathematics library in progress that I will release soon, and please do not skid it.
// Fur die unbedarft
Function int tan(int ang)
{
return sin(ang)/cos(ang);
}
Function int atandeg(int x, int y)
{
return atan(x,y,0);
}
Function int atanbyt(int x, int y)
{
return atan(x,y,1);
}
Function int atanrad(int x, int y)
{
return atan(x,y,2);
}
int cordictable[20] = { 4096.0, 2418.00999158469876409, 1277.610072102819028345, 648.5348214467058403058, 325.5259022219811071486, 162.9216411416866640464, 81.48070037832356419276, 40.74283652988500860877, 20.37172910021182123791, 10.18590340584852022845, 5.092956559933773885388, 2.546478887094378914628, 1.273239519438166664869, 0.6366197692054567556005, 0.3183098857885250954529, 0.1591549430424871386755, 0.07957747153977164324517, 0.03978873577220183086223, 0.01989436788639041658611, 0.00994718394323139593743 };
// Calculation function for arctangent
Function int atan(int x, int y, int selector)
{
if(abs(x) < 65536)
{
x = toFixed(x);
}
if(abs(y) < 65536)
{
y = toFixed(y);
}
If(y==0)
{
If(x >= 0)
{
return 0;
} Else {
If(selector == 0)
return 180.0;
If(selector == 1)
return 128;
return 3.14159;
}
}
int t = 0;
int beta = 0; // Beta will temporarily be an octant, but then will be an angle
If(y < 0)
{
x = -x;
y = -y;
beta += 4;
}
If(x <= 0)
{
t = x;
x = y;
y = -t;
beta += 2;
}
If(x <= y)
{
t = y-x;
x = x+y;
y = t; // Don't you just love how the number of angles in a circle is arbitrary?
beta += 1; // It makes things so much easier!
} // Know what I mean?
print(d: beta);
beta = beta * 4096; // << 'cause I sure as hell do.
int dbeta = 0;
For(int j = 1; j < 20; j++)
{
If(y > 0)
{
t = x + (y >> j);
y = y - (x >> j);
x = t;
dbeta += cordictable[j-1];
}
If (y < 0){
t = x - (y >> j);
y = y + (x >> j);
x = t;
dbeta -= cordictable[j-1];
}
If (y == 0)
break;
}
int finalangle = toFixed(beta) + dbeta;
print(f: finalangle);
If(selector == 0) // Atan Degrees
{
return (finalangle)/16384 * 180;
}
If(selector == 1) // Atan Byte-angle
{
return (finalangle)/16384 * 128;
}
return FixedMul(finalangle/16384, 3.14159); // Atan radians
}
Function int round(int fixed)
{
return (fixed + 0.5) >> 16;
}
Function int floor(int fixed)
{
return fixed & 0xFFFF0000;
}
Function int ceil(int fixed)
{
return floor(fixed) + 1;
}
Function int toFixed(int i)
{
return i << 16;
}
Function int adeltdeg(int ang1, int ang2)
{
int a = ang1 - ang2;
a = mod(a + 180, 360) - 180;
return a;
}
Function int adeltbyt(int ang1, int ang2)
{
int a = ang1 - ang2;
a = mod(a + 128, 256);
return a;
}
Function int adeltrad(int ang1, int ang2)
{
int a = ang1 - ang2;
a = mod(a + 3.14159, 6.28318) - 3.14159;
return a;
}
Function int fadeltdeg(int ang1, int ang2)
{
int a = ang1 - ang2;
a = mod(a + 180.0, 360.0) - 180.0;
return a;
}
Function int mod(int operand, int modulo) // Woo, recursing!
{
If(operand > modulo)
{
return mod(operand - modulo, modulo);
}
If(operand < -modulo)
{
return mod(operand + modulo, modulo);
}
return operand;
}
script 13337 (void)
{
int O = ActivatorTID();
int x = GetActorX(O);
int y = GetActorY(O);
int z = GetActorZ(O);
int yaw = GetActorAngle(O); // What the fuck were you smoking to use the proper term for Pitch but not Yaw, Doom Sourceporters?
int pitch = GetActorPitch(O);
For(int i = 1000; i < ServerMAX+1000; i++)
{
If(i != O)
{
int tx = GetActorX(i);
int ty = GetActorY(i);
int tz = GetActorZ(i);
int deltx = tx - x;
int delty = ty - y;
int deltz = tz - z;
If(FixedMul(deltx, deltx) + FixedMul(delty,delty) + FixedMul(deltz,deltz) < 65536.0 || true)
{
int yaw2 = atandeg(deltx,delty); // Always passes negatives? ************
int deltyaw = fadeltdeg(yaw, yaw2);
If((abs(deltyaw) < 8.0 || abs(mod(deltyaw - 180.0,180.0)) < 8.0) && false)
{
int hdist = xyDistance(deltx,delty);
int pitch2 = atandeg(hdist,deltz) - 180.0;
int deltpitch = pitch2 - pitch;
print(f: deltpitch);
If(abs(deltpitch < 8.0))
{
int forceyaw = 0;
int forcepitch = 0;
If(fadeltdeg(yaw, yaw2) != deltyaw)
{
forceyaw = mod(yaw2 + 180.0, 360.0);
forcepitch = -pitch2;
} Else {
forceyaw = yaw2;
forcepitch = pitch2;
}
ThrustThing(forceyaw >> 8, 20*cos(forcepitch), 1, i);
ThrustThingZ(i, 20*sin(forcepitch), 0, 1);
}
}
}
}
}
}
Can anyone tell me why the first call to atan() in script 13337 always passes negatives?