mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-20 07:02:05 +00:00
Projectile hitscan effects moved to /effects/projectiles folder.
Most of projectile firing code and some of impact code refactored, and projectile hitscan effects refactored with ported TGcode (which is mostly TGcode I wrote anyways 😎)
Projectiles can now be fired at any angle, instead of just at the center of turfs!
Projectiles are now [in theory] 100% accurate down to 0.001 of a pixel.
138 lines
2.9 KiB
Plaintext
138 lines
2.9 KiB
Plaintext
// min is inclusive, max is exclusive
|
|
/proc/Wrap(val, min, max)
|
|
var/d = max - min
|
|
var/t = Floor((val - min) / d)
|
|
return val - (t * d)
|
|
|
|
/proc/Default(a, b)
|
|
return a ? a : b
|
|
|
|
// Trigonometric functions.
|
|
/proc/Tan(x)
|
|
return sin(x) / cos(x)
|
|
|
|
/proc/Csc(x)
|
|
return 1 / sin(x)
|
|
|
|
/proc/Sec(x)
|
|
return 1 / cos(x)
|
|
|
|
/proc/Cot(x)
|
|
return 1 / Tan(x)
|
|
|
|
/proc/Atan2(x, y)
|
|
if(!x && !y) return 0
|
|
var/a = arccos(x / sqrt(x*x + y*y))
|
|
return y >= 0 ? a : -a
|
|
|
|
/proc/Floor(x)
|
|
return round(x)
|
|
|
|
/proc/Ceiling(x, y=1)
|
|
return -round(-x / y) * y
|
|
|
|
/proc/Modulus(x, y)
|
|
return ( (x) - (y) * round((x) / (y)) )
|
|
|
|
// Greatest Common Divisor: Euclid's algorithm.
|
|
/proc/Gcd(a, b)
|
|
while (1)
|
|
if (!b) return a
|
|
a %= b
|
|
if (!a) return b
|
|
b %= a
|
|
|
|
// Least Common Multiple. The formula is a consequence of: a*b = LCM*GCD.
|
|
/proc/Lcm(a, b)
|
|
return abs(a) * abs(b) / Gcd(a, b)
|
|
|
|
// Useful in the cases when x is a large expression, e.g. x = 3a/2 + b^2 + Function(c)
|
|
/proc/Square(x)
|
|
return x*x
|
|
|
|
/proc/Inverse(x)
|
|
return 1 / x
|
|
|
|
// Condition checks.
|
|
/proc/IsAboutEqual(a, b, delta = 0.1)
|
|
return abs(a - b) <= delta
|
|
|
|
// Returns true if val is from min to max, inclusive.
|
|
/proc/IsInRange(val, min, max)
|
|
return (val >= min) && (val <= max)
|
|
|
|
/proc/IsInteger(x)
|
|
return Floor(x) == x
|
|
|
|
/proc/IsMultiple(x, y)
|
|
return x % y == 0
|
|
|
|
/proc/IsEven(x)
|
|
return !(x & 0x1)
|
|
|
|
/proc/IsOdd(x)
|
|
return (x & 0x1)
|
|
|
|
// Performs a linear interpolation between a and b.
|
|
// Note: weight=0 returns a, weight=1 returns b, and weight=0.5 returns the mean of a and b.
|
|
/proc/Interpolate(a, b, weight = 0.5)
|
|
return a + (b - a) * weight // Equivalent to: a*(1 - weight) + b*weight
|
|
|
|
/proc/Mean(...)
|
|
var/sum = 0
|
|
for(var/val in args)
|
|
sum += val
|
|
return sum / args.len
|
|
|
|
// Returns the nth root of x.
|
|
/proc/Root(n, x)
|
|
return x ** (1 / n)
|
|
|
|
// The quadratic formula. Returns a list with the solutions, or an empty list
|
|
// if they are imaginary.
|
|
/proc/SolveQuadratic(a, b, c)
|
|
ASSERT(a)
|
|
|
|
. = list()
|
|
var/discriminant = b*b - 4*a*c
|
|
var/bottom = 2*a
|
|
|
|
// Return if the roots are imaginary.
|
|
if(discriminant < 0)
|
|
return
|
|
|
|
var/root = sqrt(discriminant)
|
|
. += (-b + root) / bottom
|
|
|
|
// If discriminant == 0, there would be two roots at the same position.
|
|
if(discriminant != 0)
|
|
. += (-b - root) / bottom
|
|
|
|
/proc/ToDegrees(radians)
|
|
// 180 / Pi ~ 57.2957795
|
|
return radians * 57.2957795
|
|
|
|
/proc/ToRadians(degrees)
|
|
// Pi / 180 ~ 0.0174532925
|
|
return degrees * 0.0174532925
|
|
|
|
// Vector algebra.
|
|
/proc/squaredNorm(x, y)
|
|
return x*x + y*y
|
|
|
|
/proc/norm(x, y)
|
|
return sqrt(squaredNorm(x, y))
|
|
|
|
/proc/IsPowerOfTwo(var/val)
|
|
return (val & (val-1)) == 0
|
|
|
|
/proc/RoundUpToPowerOfTwo(var/val)
|
|
return 2 ** -round(-log(2,val))
|
|
|
|
//Returns the cube root of the input number
|
|
/proc/cubert(var/num, var/iterations = 10)
|
|
. = num
|
|
for (var/i = 0, i < iterations, i++)
|
|
. = (1/3) * (num/(.**2)+2*.)
|
|
|