Clean up procs.

This commit is contained in:
ESwordTheCat
2014-06-10 02:48:56 -08:00
parent c84f3ce50f
commit 08835d434e
4 changed files with 76 additions and 64 deletions

View File

@@ -13,15 +13,11 @@
var/atom/A = O
for (var/i = 0, ++i <= 20)
for (var/i = 0, ++i <= 16)
if (isarea(A))
return A
switch (istype(A))
if (1)
A = A.loc
if (0)
return
/proc/get_area_master(const/O)
var/area/A = get_area(O)
@@ -59,19 +55,6 @@
return 0
return 1
//Magic constants obtained by using linear regression on right-angled triangles of sides 0<x<1, 0<y<1
//They should approximate pythagoras theorem well enough for our needs.
#define k1 0.934
#define k2 0.427
/proc/cheap_hypotenuse(Ax,Ay,Bx,By) // T is just the second atom to check distance to center with
var/dx = abs(Ax - Bx) //sides of right-angled triangle
var/dy = abs(Ay - By)
if(dx>=dy) return (k1*dx) + (k2*dy) //No sqrt or powers :)
else return (k2*dx) + (k1*dy)
#undef k1
#undef k2
/proc/circlerange(center=usr,radius=3)
var/turf/centerturf = get_turf(center)

View File

@@ -1,4 +1,6 @@
// Credits to Nickr5 for the useful procs I've taken from his library resource.
/**
* Credits to Nickr5 for the useful procs I've taken from his library resource.
*/
var/const/E = 2.71828183
var/const/Sqrt2 = 1.41421356
@@ -85,12 +87,16 @@ var/list/sqrtTable = list(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
return sum / values
// Returns the nth root of x.
/proc/Root(n, x)
/*
* Returns the nth root of x.
*/
/proc/Root(const/n, const/x)
return x ** (1 / n)
// secant
/proc/Sec(x)
/*
* Secant.
*/
/proc/Sec(const/x)
return 1 / cos(x)
// The quadratic formula. Returns a list with the solutions, or an empty list
@@ -106,15 +112,17 @@ var/list/sqrtTable = list(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
if(!d) return
. += (-b - root) / bottom
// tangent
/proc/Tan(x)
/*
* Tangent.
*/
/proc/Tan(const/x)
return sin(x) / cos(x)
/proc/ToDegrees(radians)
/proc/ToDegrees(const/radians)
// 180 / Pi
return radians * 57.2957795
/proc/ToRadians(degrees)
/proc/ToRadians(const/degrees)
// Pi / 180
return degrees * 0.0174532925
@@ -123,3 +131,32 @@ var/list/sqrtTable = list(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
var/d = max - min
var/t = Floor((val - min) / d)
return val - (t * d)
/*
* A very crude linear approximatiaon of pythagoras theorem.
*/
/proc/cheap_pythag(const/Ax, const/Ay)
var/dx = abs(Ax)
var/dy = abs(Ay)
if (dx >= dy)
return dx + (0.5 * dy) // The longest side add half the shortest side approximates the hypotenuse.
else
return dy + (0.5 * dx)
/*
* Magic constants obtained by using linear regression on right-angled triangles of sides 0<x<1, 0<y<1
* They should approximate pythagoras theorem well enough for our needs.
*/
#define k1 0.934
#define k2 0.427
/proc/cheap_hypotenuse(const/Ax, const/Ay, const/Bx, const/By)
var/dx = abs(Ax - Bx) // Sides of right-angled triangle.
var/dy = abs(Ay - By)
if (dx >= dy)
return (k1*dx) + (k2*dy) // No sqrt or powers :).
else
return (k2*dx) + (k1*dy)
#undef k1
#undef k2

View File

@@ -1252,15 +1252,11 @@ proc/get_mob_with_client_list()
var/atom/A = O
for (var/i = 0, ++i <= 20)
for (var/i = 0, ++i <= 16)
if (isturf(A))
return A
switch (istype(A))
if (1)
A = A.loc
if (0)
return
/proc/get(atom/loc, type)
while(loc)

View File

@@ -1,13 +1,8 @@
//TODO: Flash range does nothing currently
//A very crude linear approximatiaon of pythagoras theorem.
/proc/cheap_pythag(var/dx, var/dy)
dx = abs(dx); dy = abs(dy);
if(dx>=dy) return dx + (0.5*dy) //The longest side add half the shortest side approximates the hypotenuse
else return dy + (0.5*dx)
proc/trange(var/Dist=0,var/turf/Center=null)//alternative to range (ONLY processes turfs and thus less intensive)
if(Center==null) return
/proc/trange(var/Dist = 0, var/turf/Center = null)//alternative to range (ONLY processes turfs and thus less intensive)
if (isnull(Center))
return
//var/x1=((Center.x-Dist)<1 ? 1 : Center.x-Dist)
//var/y1=((Center.y-Dist)<1 ? 1 : Center.y-Dist)
@@ -16,10 +11,11 @@ proc/trange(var/Dist=0,var/turf/Center=null)//alternative to range (ONLY process
var/turf/x1y1 = locate(((Center.x-Dist)<1 ? 1 : Center.x-Dist),((Center.y-Dist)<1 ? 1 : Center.y-Dist),Center.z)
var/turf/x2y2 = locate(((Center.x+Dist)>world.maxx ? world.maxx : Center.x+Dist),((Center.y+Dist)>world.maxy ? world.maxy : Center.y+Dist),Center.z)
return block(x1y1,x2y2)
return block(x1y1, x2y2)
proc/explosion(turf/epicenter, devastation_range, heavy_impact_range, light_impact_range, flash_range, adminlog = 1, squelch = 0)
/proc/explosion(turf/epicenter, const/devastation_range, const/heavy_impact_range, const/light_impact_range, const/flash_range, adminlog = 1, squelch = 0)
src = null //so we don't abort once src is deleted
spawn(0)
if(config.use_recursive_explosions)
var/power = devastation_range * 2 + heavy_impact_range + light_impact_range //The ranges add up, ie light 14 includes both heavy 7 and devestation 3. So this calculation means devestation counts for 4, heavy for 2 and light for 1 power, giving us a cap of 27 power.
@@ -42,11 +38,10 @@ proc/explosion(turf/epicenter, devastation_range, heavy_impact_range, light_impa
// Calculate far explosion sound range. Only allow the sound effect for heavy/devastating explosions.
// 3/7/14 will calculate to 80 + 35
var/far_dist = 0
far_dist += heavy_impact_range * 5
far_dist += devastation_range * 20
var/far_dist = (devastation_range * 20) + (heavy_impact_range * 5)
var/frequency = get_rand_frequency()
for(var/mob/M in player_list)
for (var/mob/M in player_list)
// Double check for client
if(M && M.client)
var/turf/M_turf = get_turf(M)
@@ -88,21 +83,22 @@ proc/explosion(turf/epicenter, devastation_range, heavy_impact_range, light_impa
var/y0 = epicenter.y
var/z0 = epicenter.z
for(var/turf/T in trange(max_range, epicenter))
var/dist = cheap_pythag(T.x - x0,T.y - y0)
for (var/turf/T in trange(max_range, epicenter))
var/dist = cheap_pythag(T.x - x0, T.y - y0)
if(dist < devastation_range) dist = 1
else if(dist < heavy_impact_range) dist = 2
else if(dist < light_impact_range) dist = 3
else continue
if (dist < devastation_range)
dist = 1
else if (dist < heavy_impact_range)
dist = 2
else if (dist < light_impact_range)
dist = 3
else
continue
for (var/atom/A in T.contents)
A.ex_act(dist)
if(T)
//spawn(dist) No need for this anymore with the new garbage man
T.ex_act(dist)
for(var/atom_movable in T.contents) //bypass type checking since only atom/movable can be contained by turfs anyway
var/atom/movable/AM = atom_movable
//spawn(dist) No need for this anymore with the new garbage man
if(AM) AM.ex_act(dist)
var/took = (world.timeofday-start)/10
//You need to press the DebugGame verb to see these now....they were getting annoying and we've collected a fair bit of data. Just -test- changes to explosion code using this please so we can compare