Cleanup helper files maths.dm, time.dm, type2type.dm, add macros for bit-manipulation

`maths.dm`:
	Rewrite `Gcd(x)` to remove recursive behaviour.
	Remove `RaiseToPower(x)` and its usage from `event_manager.dm`.
	Rename `Lerp()` to `Interpolate()`.
	Add `Square(x)`, which squares a number.
	Rearrange most of the functions in the file. (trigonometric functions together, etc.)

`type2type.dm`:
	Rewrite `num2hex()` and optimise `hex2num()` for superior clarity and a 100% speed improvement.
	Correct indenting, spaces, make switches more concise.

`time.dm`:
	Remove old, slanderous commented-out function `/proc/time_stamp()`

`lists.dm`:
	Add the macros, `BITTEST(bitfield,index)`, `BITSET(...)`, `BITRESET(...)`
	  and `BITFLIP(...)` for bit-manipulation and use them where 20+ files
	  do it manually, for arguments of reader clarity and standardness.
This commit is contained in:
Zulker Nayeen Nahiyan
2015-01-09 14:51:42 +06:00
parent fbffce744c
commit 6e550d7308
25 changed files with 371 additions and 405 deletions

View File

@@ -543,7 +543,7 @@ What a mess.*/
if ("Change Criminal Status") if ("Change Criminal Status")
if (active2) if (active2)
for(var/mob/living/carbon/human/H in player_list) for(var/mob/living/carbon/human/H in player_list)
H.hud_updateflag |= 1 << WANTED_HUD BITSET(H.hud_updateflag, WANTED_HUD)
switch(href_list["criminal2"]) switch(href_list["criminal2"])
if("none") if("none")
active2.fields["criminal"] = "None" active2.fields["criminal"] = "None"

View File

@@ -343,6 +343,12 @@ proc/listclearnulls(list/list)
return (result + L.Copy(Li, 0)) return (result + L.Copy(Li, 0))
return (result + R.Copy(Ri, 0)) return (result + R.Copy(Ri, 0))
// Macros to test for bits in a bitfield. Note, that this is for use with indexes, not bit-masks!
#define BITTEST(bitfield,index) ((bitfield) & (1 << (index)))
#define BITSET(bitfield,index) (bitfield) |= (1 << (index))
#define BITRESET(bitfield,index) (bitfield) &= ~(1 << (index))
#define BITFLIP(bitfield,index) (bitfield) ^= (1 << (index))
//Converts a bitfield to a list of numbers (or words if a wordlist is provided) //Converts a bitfield to a list of numbers (or words if a wordlist is provided)
/proc/bitfield2list(bitfield = 0, list/wordlist) /proc/bitfield2list(bitfield = 0, list/wordlist)
var/list/r = list() var/list/r = list()

View File

@@ -1,6 +1,7 @@
// 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/E = 2.71828183
var/const/Pi = 3.14159265
var/const/Sqrt2 = 1.41421356 var/const/Sqrt2 = 1.41421356
// List of square roots for the numbers 1-100. // List of square roots for the numbers 1-100.
@@ -9,115 +10,127 @@ var/list/sqrtTable = list(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10) 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10)
/proc/Atan2(x, y)
if(!x && !y) return 0
var/a = arccos(x / sqrt(x*x + y*y))
return y >= 0 ? a : -a
/proc/Ceiling(x)
return -round(-x)
/proc/Clamp(val, min, max) /proc/Clamp(val, min, max)
return max(min, min(val, max)) return max(min, min(val, max))
// cotangent
/proc/Cot(x)
return 1 / Tan(x)
// cosecant
/proc/Csc(x)
return 1 / sin(x)
/proc/Default(a, b)
return a ? a : b
/proc/Floor(x)
return round(x)
// Greatest Common Divisor - Euclid's algorithm
/proc/Gcd(a, b)
return b ? Gcd(b, a % b) : a
/proc/Inverse(x)
return 1 / x
/proc/IsAboutEqual(a, b, deviation = 0.1)
return abs(a - b) <= deviation
/proc/IsEven(x)
return x % 2 == 0
// Returns true if val is from min to max, inclusive.
/proc/IsInRange(val, min, max)
return min <= val && val <= max
/proc/IsInteger(x)
return Floor(x) == x
/proc/IsOdd(x)
return !IsEven(x)
/proc/IsMultiple(x, y)
return x % y == 0
// Least Common Multiple
/proc/Lcm(a, b)
return abs(a) / Gcd(a, b) * abs(b)
// Performs a linear interpolation between a and b.
// Note that amount=0 returns a, amount=1 returns b, and
// amount=0.5 returns the mean of a and b.
/proc/Lerp(a, b, amount = 0.5)
return a + (b - a) * amount
/proc/Mean(...)
var/values = 0
var/sum = 0
for(var/val in args)
values++
sum += val
return sum / values
// Returns the nth root of x.
/proc/Root(n, x)
return x ** (1 / n)
// secant
/proc/Sec(x)
return 1 / cos(x)
// 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/d = b*b - 4 * a * c
var/bottom = 2 * a
if(d < 0) return
var/root = sqrt(d)
. += (-b + root) / bottom
if(!d) return
. += (-b - root) / bottom
// tangent
/proc/Tan(x)
return sin(x) / cos(x)
/proc/ToDegrees(radians)
// 180 / Pi
return radians * 57.2957795
/proc/ToRadians(degrees)
// Pi / 180
return degrees * 0.0174532925
// min is inclusive, max is exclusive // min is inclusive, max is exclusive
/proc/Wrap(val, min, max) /proc/Wrap(val, min, max)
var/d = max - min var/d = max - min
var/t = Floor((val - min) / d) var/t = Floor((val - min) / d)
return val - (t * d) return val - (t * d)
proc/RaiseToPower(num, power) /proc/Default(a, b)
if(!power) return 1 return a ? a : b
return (power-- > 1 ? num * RaiseToPower(num, power) : num)
// 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)
return -round(-x)
// 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))

View File

@@ -11,20 +11,6 @@ proc/worldtime2text(time = world.time)
proc/time_stamp() proc/time_stamp()
return time2text(world.timeofday, "hh:mm:ss") return time2text(world.timeofday, "hh:mm:ss")
/* Preserving this so future generations can see how fucking retarded some people are
proc/time_stamp()
var/hh = text2num(time2text(world.timeofday, "hh")) // Set the hour
var/mm = text2num(time2text(world.timeofday, "mm")) // Set the minute
var/ss = text2num(time2text(world.timeofday, "ss")) // Set the second
var/ph
var/pm
var/ps
if(hh < 10) ph = "0"
if(mm < 10) pm = "0"
if(ss < 10) ps = "0"
return"[ph][hh]:[pm][mm]:[ps][ss]"
*/
/* Returns 1 if it is the selected month and day */ /* Returns 1 if it is the selected month and day */
proc/isDay(var/month, var/day) proc/isDay(var/month, var/day)
if(isnum(month) && isnum(day)) if(isnum(month) && isnum(day))

View File

@@ -9,81 +9,62 @@
* worldtime2text * worldtime2text
*/ */
//Returns an integer given a hex input // Returns an integer given a hexadecimal number string as input.
/proc/hex2num(hex) /proc/hex2num(hex)
if (!( istext(hex) )) if (!istext(hex))
return return
var/num = 0 var/num = 0
var/power = 0 var/power = 1
var/i = null var/i = length(hex)
i = length(hex)
while(i > 0) while (i)
var/char = copytext(hex, i, i + 1) var/char = text2ascii(hex, i)
switch(char) switch(char)
if("0") if(48) // 0 -- do nothing
//Apparently, switch works with empty statements, yay! If that doesn't work, blame me, though. -- Urist if(49 to 57) num += (char - 48) * power // 1-9
if("9", "8", "7", "6", "5", "4", "3", "2", "1") if(97, 65) num += power * 10 // A
num += text2num(char) * 16 ** power if(98, 66) num += power * 11 // B
if("a", "A") if(99, 67) num += power * 12 // C
num += 16 ** power * 10 if(100, 68) num += power * 13 // D
if("b", "B") if(101, 69) num += power * 14 // E
num += 16 ** power * 11 if(102, 70) num += power * 15 // F
if("c", "C")
num += 16 ** power * 12
if("d", "D")
num += 16 ** power * 13
if("e", "E")
num += 16 ** power * 14
if("f", "F")
num += 16 ** power * 15
else else
return return
power++ power *= 16
i-- i--
return num return num
// Returns the hex value of a number given a value assumed to be a base-ten value // Returns the hex value of a number given a value assumed to be a base-ten value
/proc/num2hex(num, placeholder) /proc/num2hex(num, digits)
if (digits == null)
digits = 2
if (placeholder == null) if (!isnum(num))
placeholder = 2
if (!( isnum(num) ))
return return
if (num == 0)
var/final = ""
for(var/i=1 to placeholder) final = "[final]0"
return final
var/hex = ""
var/i = 0
while(16 ** i < num)
i++
var/power = null
power = i - 1
while(power >= 0)
var/val = round(num / 16 ** power)
num -= val * 16 ** power
switch(val)
if(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0)
hex += text("[]", val)
if(10.0)
hex += "A"
if(11.0)
hex += "B"
if(12.0)
hex += "C"
if(13.0)
hex += "D"
if(14.0)
hex += "E"
if(15.0)
hex += "F"
else
power--
while(length(hex) < placeholder)
hex = text("0[]", hex)
return hex
// hex is our return value, to which each hex-digit of num is appended to.
var/hex = ""
var/power = -4
var/n = 1
// Figure out power. (power of 2)
while (n < num)
power += 4
n *= 16
// Note that we have to start appending to hex with the most-significant digits.
while (power >= 0)
var/m = (num >> power) & 15
hex += ascii2text(m + (m < 10 ? 48 : 87)) // Provided by the IconProcs library.
power -= 4
// Append zeroes to make sure that hex is atleast digits long.
var/left = length(hex) - digits
while (left-- > 0)
hex = text("0[]", hex)
return hex
// Concatenates a list of strings into a single string. A seperator may optionally be provided. // Concatenates a list of strings into a single string. A seperator may optionally be provided.
/proc/list2text(list/ls, sep) /proc/list2text(list/ls, sep)
@@ -135,7 +116,6 @@
#undef S16 #undef S16
#undef S4 #undef S4
#undef S1 #undef S1
else else
// Macros expand to long argument lists like so: ls[++i], ls[++i], ls[++i], etc... // Macros expand to long argument lists like so: ls[++i], ls[++i], ls[++i], etc...
#define S1 ls[++i] #define S1 ls[++i]
@@ -171,8 +151,7 @@
#undef S4 #undef S4
#undef S1 #undef S1
// Slower then list2text, but correctly processes associative lists.
//slower then list2text, but correctly processes associative lists.
proc/tg_list2text(list/list, glue=",") proc/tg_list2text(list/list, glue=",")
if (!istype(list) || !list.len) if (!istype(list) || !list.len)
return return
@@ -181,7 +160,6 @@ proc/tg_list2text(list/list, glue=",")
output += (i!=1? glue : null)+(!isnull(list["[list[i]]"])?"[list["[list[i]]"]]":"[list[i]]") output += (i!=1? glue : null)+(!isnull(list["[list[i]]"])?"[list["[list[i]]"]]":"[list[i]]")
return output return output
// Converts a string into a list by splitting the string at each delimiter found. (discarding the seperator) // Converts a string into a list by splitting the string at each delimiter found. (discarding the seperator)
/proc/text2list(text, delimiter="\n") /proc/text2list(text, delimiter="\n")
var/delim_len = length(delimiter) var/delim_len = length(delimiter)
@@ -218,9 +196,7 @@ proc/tg_list2text(list/list, glue=",")
/proc/file2list(filename, seperator="\n") /proc/file2list(filename, seperator="\n")
return text2list(return_file_text(filename),seperator) return text2list(return_file_text(filename),seperator)
// Turns a direction into text // Turns a direction into text
/proc/num2dir(direction) /proc/num2dir(direction)
switch (direction) switch (direction)
if (1.0) return NORTH if (1.0) return NORTH
@@ -230,55 +206,37 @@ proc/tg_list2text(list/list, glue=",")
else else
world.log << "UNKNOWN DIRECTION: [direction]" world.log << "UNKNOWN DIRECTION: [direction]"
// Turns a direction into text // Turns a direction into text
/proc/dir2text(direction) /proc/dir2text(direction)
switch (direction) switch (direction)
if(1.0) if (1.0) return "north"
return "north" if (2.0) return "south"
if(2.0) if (4.0) return "east"
return "south" if (8.0) return "west"
if(4.0) if (5.0) return "northeast"
return "east" if (6.0) return "southeast"
if(8.0) if (9.0) return "northwest"
return "west" if (10.0) return "southwest"
if(5.0)
return "northeast"
if(6.0)
return "southeast"
if(9.0)
return "northwest"
if(10.0)
return "southwest"
else else
return return
// Turns text into proper directions // Turns text into proper directions
/proc/text2dir(direction) /proc/text2dir(direction)
switch (uppertext(direction)) switch (uppertext(direction))
if("NORTH") if ("NORTH") return 1
return 1 if ("SOUTH") return 2
if("SOUTH") if ("EAST") return 4
return 2 if ("WEST") return 8
if("EAST") if ("NORTHEAST") return 5
return 4 if ("NORTHWEST") return 9
if("WEST") if ("SOUTHEAST") return 6
return 8 if ("SOUTHWEST") return 10
if("NORTHEAST")
return 5
if("NORTHWEST")
return 9
if("SOUTHEAST")
return 6
if("SOUTHWEST")
return 10
else else
return return
// Converts an angle (degrees) into an ss13 direction // Converts an angle (degrees) into an ss13 direction
/proc/angle2dir(var/degree) /proc/angle2dir(var/degree)
degree = ((degree+22.5)%365) degree = (degree + 22.5) % 365 // 22.5 = 45 / 2
if (degree < 45) return NORTH if (degree < 45) return NORTH
if (degree < 90) return NORTHEAST if (degree < 90) return NORTHEAST
if (degree < 135) return EAST if (degree < 135) return EAST
@@ -288,8 +246,7 @@ proc/tg_list2text(list/list, glue=",")
if (degree < 315) return WEST if (degree < 315) return WEST
return NORTH|WEST return NORTH|WEST
//returns the north-zero clockwise angle in degrees, given a direction // Returns the north-zero clockwise angle in degrees, given a direction
/proc/dir2angle(var/D) /proc/dir2angle(var/D)
switch (D) switch (D)
if (NORTH) return 0 if (NORTH) return 0
@@ -300,7 +257,8 @@ proc/tg_list2text(list/list, glue=",")
if (SOUTHEAST) return 135 if (SOUTHEAST) return 135
if (NORTHWEST) return 315 if (NORTHWEST) return 315
if (SOUTHWEST) return 225 if (SOUTHWEST) return 225
else return null else
return null
// Returns the angle in english // Returns the angle in english
/proc/angle2text(var/degree) /proc/angle2text(var/degree)

View File

@@ -500,7 +500,7 @@ datum/mind
else if(href_list["implant"]) else if(href_list["implant"])
var/mob/living/carbon/human/H = current var/mob/living/carbon/human/H = current
H.hud_updateflag |= (1 << IMPLOYAL_HUD) // updates that players HUD images so secHUD's pick up they are implanted or not. BITSET(H.hud_updateflag, IMPLOYAL_HUD) // updates that players HUD images so secHUD's pick up they are implanted or not.
switch(href_list["implant"]) switch(href_list["implant"])
if("remove") if("remove")
@@ -540,7 +540,7 @@ datum/mind
else if (href_list["revolution"]) else if (href_list["revolution"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD) BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["revolution"]) switch(href_list["revolution"])
if("clear") if("clear")
@@ -635,7 +635,7 @@ datum/mind
usr << "\red Reequipping revolutionary goes wrong!" usr << "\red Reequipping revolutionary goes wrong!"
else if (href_list["cult"]) else if (href_list["cult"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD) BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["cult"]) switch(href_list["cult"])
if("clear") if("clear")
if(src in ticker.mode.cult) if(src in ticker.mode.cult)
@@ -685,7 +685,7 @@ datum/mind
usr << "\red Spawning amulet failed!" usr << "\red Spawning amulet failed!"
else if (href_list["wizard"]) else if (href_list["wizard"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD) BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["wizard"]) switch(href_list["wizard"])
if("clear") if("clear")
@@ -715,7 +715,7 @@ datum/mind
usr << "\blue The objectives for wizard [key] have been generated. You can edit them and anounce manually." usr << "\blue The objectives for wizard [key] have been generated. You can edit them and anounce manually."
else if (href_list["changeling"]) else if (href_list["changeling"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD) BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["changeling"]) switch(href_list["changeling"])
if("clear") if("clear")
if(src in ticker.mode.changelings) if(src in ticker.mode.changelings)
@@ -751,7 +751,7 @@ datum/mind
else if (href_list["nuclear"]) else if (href_list["nuclear"])
var/mob/living/carbon/human/H = current var/mob/living/carbon/human/H = current
current.hud_updateflag |= (1 << SPECIALROLE_HUD) BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["nuclear"]) switch(href_list["nuclear"])
if("clear") if("clear")
@@ -805,7 +805,7 @@ datum/mind
usr << "\red No valid nuke found!" usr << "\red No valid nuke found!"
else if (href_list["traitor"]) else if (href_list["traitor"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD) BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["traitor"]) switch(href_list["traitor"])
if("clear") if("clear")
if(src in ticker.mode.traitors) if(src in ticker.mode.traitors)
@@ -888,7 +888,7 @@ datum/mind
current.radiation -= 50 current.radiation -= 50
else if (href_list["silicon"]) else if (href_list["silicon"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD) BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["silicon"]) switch(href_list["silicon"])
if("unmalf") if("unmalf")
if(src in ticker.mode.malf_ai) if(src in ticker.mode.malf_ai)

View File

@@ -134,7 +134,7 @@
newtraitor << "\red <B>No time like the present.</B> \black It's time to take matters into your own hands..." newtraitor << "\red <B>No time like the present.</B> \black It's time to take matters into your own hands..."
newtraitor << "<B>You are now a traitor.</B>" newtraitor << "<B>You are now a traitor.</B>"
newtraitor.mind.special_role = "traitor" newtraitor.mind.special_role = "traitor"
newtraitor.hud_updateflag |= 1 << SPECIALROLE_HUD BITSET(newtraitor.hud_updateflag, SPECIALROLE_HUD)
newtraitor << "<i>You have been selected this round as an antagonist!</i>" newtraitor << "<i>You have been selected this round as an antagonist!</i>"
show_objectives(newtraitor.mind) show_objectives(newtraitor.mind)

View File

@@ -205,7 +205,7 @@
if(rev_mind in revolutionaries) if(rev_mind in revolutionaries)
revolutionaries -= rev_mind revolutionaries -= rev_mind
rev_mind.special_role = null rev_mind.special_role = null
rev_mind.current.hud_updateflag |= 1 << SPECIALROLE_HUD BITSET(rev_mind.current.hud_updateflag, SPECIALROLE_HUD)
if(beingborged) if(beingborged)
rev_mind.current << "\red <FONT size = 3><B>The frame's firmware detects and deletes your neural reprogramming! You remember nothing from the moment you were flashed until now.</B></FONT>" rev_mind.current << "\red <FONT size = 3><B>The frame's firmware detects and deletes your neural reprogramming! You remember nothing from the moment you were flashed until now.</B></FONT>"

View File

@@ -109,7 +109,7 @@
rev_mind.special_role = "Revolutionary" rev_mind.special_role = "Revolutionary"
show_objectives(rev_mind) show_objectives(rev_mind)
update_rev_icons_added(rev_mind) update_rev_icons_added(rev_mind)
H.hud_updateflag |= 1 << SPECIALROLE_HUD BITSET(H.hud_updateflag, SPECIALROLE_HUD)
return 1 return 1
///////////////////////////// /////////////////////////////

View File

@@ -538,9 +538,9 @@ var/global/datum/controller/occupations/job_master
G.prescription = 1 G.prescription = 1
// H.update_icons() // H.update_icons()
H.hud_updateflag |= (1 << ID_HUD) BITSET(H.hud_updateflag, ID_HUD)
H.hud_updateflag |= (1 << IMPLOYAL_HUD) BITSET(H.hud_updateflag, IMPLOYAL_HUD)
H.hud_updateflag |= (1 << SPECIALROLE_HUD) BITSET(H.hud_updateflag, SPECIALROLE_HUD)
return H return H

View File

@@ -134,11 +134,11 @@
unload(0) unload(0)
switch(severity) switch(severity)
if(2) if(2)
wires &= ~(1 << rand(0,9)) BITRESET(wires, rand(0,9))
wires &= ~(1 << rand(0,9)) BITRESET(wires, rand(0,9))
wires &= ~(1 << rand(0,9)) BITRESET(wires, rand(0,9))
if(3) if(3)
wires &= ~(1 << rand(0,9)) BITRESET(wires, rand(0,9))
..() ..()
return return

View File

@@ -534,7 +534,7 @@ What a mess.*/
if ("Change Criminal Status") if ("Change Criminal Status")
if (active2) if (active2)
for(var/mob/living/carbon/human/H in player_list) for(var/mob/living/carbon/human/H in player_list)
H.hud_updateflag |= 1 << WANTED_HUD BITSET(H.hud_updateflag, WANTED_HUD)
switch(href_list["criminal2"]) switch(href_list["criminal2"])
if("none") if("none")
active2.fields["criminal"] = "None" active2.fields["criminal"] = "None"

View File

@@ -68,7 +68,7 @@ var/list/uristrune_cache = list()
var/icon/I = icon('icons/effects/uristrunes.dmi', "blank") var/icon/I = icon('icons/effects/uristrunes.dmi', "blank")
for(var/i = 0, i < 10, i++) for(var/i = 0, i < 10, i++)
if(symbol_bits & (1 << i)) if(BITTEST(symbol_bits, i))
I.Blend(icon('icons/effects/uristrunes.dmi', "rune-[1 << i]"), ICON_OVERLAY) I.Blend(icon('icons/effects/uristrunes.dmi', "rune-[1 << i]"), ICON_OVERLAY)

View File

@@ -47,7 +47,7 @@
affected.implants += src.imp affected.implants += src.imp
imp.part = affected imp.part = affected
H.hud_updateflag |= 1 << IMPLOYAL_HUD BITSET(H.hud_updateflag, IMPLOYAL_HUD)
src.imp = null src.imp = null
update() update()

View File

@@ -190,12 +190,12 @@
admin_log_and_message_admins("has [report_at_round_end ? "enabled" : "disabled"] the round end event report.") admin_log_and_message_admins("has [report_at_round_end ? "enabled" : "disabled"] the round end event report.")
else if(href_list["dec_timer"]) else if(href_list["dec_timer"])
var/datum/event_container/EC = locate(href_list["event"]) var/datum/event_container/EC = locate(href_list["event"])
var/decrease = (60 * RaiseToPower(10, text2num(href_list["dec_timer"]))) var/decrease = 60 * (10 ** text2num(href_list["dec_timer"]))
EC.next_event_time -= decrease EC.next_event_time -= decrease
admin_log_and_message_admins("decreased timer for [severity_to_string[EC.severity]] events by [decrease/600] minute(s).") admin_log_and_message_admins("decreased timer for [severity_to_string[EC.severity]] events by [decrease/600] minute(s).")
else if(href_list["inc_timer"]) else if(href_list["inc_timer"])
var/datum/event_container/EC = locate(href_list["event"]) var/datum/event_container/EC = locate(href_list["event"])
var/increase = (60 * RaiseToPower(10, text2num(href_list["inc_timer"]))) var/increase = 60 * (10 ** text2num(href_list["inc_timer"]))
EC.next_event_time += increase EC.next_event_time += increase
admin_log_and_message_admins("increased timer for [severity_to_string[EC.severity]] events by [increase/600] minute(s).") admin_log_and_message_admins("increased timer for [severity_to_string[EC.severity]] events by [increase/600] minute(s).")
else if(href_list["select_event"]) else if(href_list["select_event"])

View File

@@ -179,7 +179,7 @@ var/list/rune_animation = list(
var/icon/base = icon('icons/effects/uristrunes.dmi', "") var/icon/base = icon('icons/effects/uristrunes.dmi', "")
for(var/i = 0, i < 10, i++) for(var/i = 0, i < 10, i++)
if(rune_bits & (1 << i)) if(BITTEST(rune_bits, i))
base.Blend(icon('icons/effects/uristrunes.dmi', "rune-[1 << i]"), ICON_OVERLAY) base.Blend(icon('icons/effects/uristrunes.dmi', "rune-[1 << i]"), ICON_OVERLAY)
var/icon/result var/icon/result
@@ -217,7 +217,7 @@ var/list/rune_animation = list(
var/icon/I = icon('icons/effects/uristrunes.dmi', "blank") var/icon/I = icon('icons/effects/uristrunes.dmi', "blank")
for(var/i = 0, i < 10, i++) for(var/i = 0, i < 10, i++)
if(rune & (1 << i)) if(BITTEST(rune, i))
I.Blend(icon('icons/effects/uristrunes.dmi', "rune-[1 << i]"), ICON_OVERLAY) I.Blend(icon('icons/effects/uristrunes.dmi', "rune-[1 << i]"), ICON_OVERLAY)
var/obj/o = new(locate(x, y, z)) var/obj/o = new(locate(x, y, z))
@@ -229,7 +229,7 @@ var/list/rune_animation = list(
var/rune = rand(1, 1023) var/rune = rand(1, 1023)
for(var/i = 0, i < 10, i++) for(var/i = 0, i < 10, i++)
if(rune & (1 << i)) if(BITTEST(rune, i))
I.Blend(icon('icons/effects/uristrunes.dmi', "rune-[1 << i]"), ICON_OVERLAY) I.Blend(icon('icons/effects/uristrunes.dmi', "rune-[1 << i]"), ICON_OVERLAY)
var/obj/o = new(t) var/obj/o = new(t)

View File

@@ -28,8 +28,9 @@
if(stat == DEAD) return if(stat == DEAD) return
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
hud_updateflag |= 1 << STATUS_HUD BITSET(hud_updateflag, STATUS_HUD)
handle_hud_list() handle_hud_list()
//Handle species-specific deaths. //Handle species-specific deaths.

View File

@@ -412,7 +412,7 @@
modified = 1 modified = 1
spawn() spawn()
hud_updateflag |= 1 << WANTED_HUD BITSET(hud_updateflag, WANTED_HUD)
if(istype(usr,/mob/living/carbon/human)) if(istype(usr,/mob/living/carbon/human))
var/mob/living/carbon/human/U = usr var/mob/living/carbon/human/U = usr
U.handle_regular_hud_updates() U.handle_regular_hud_updates()

View File

@@ -87,7 +87,7 @@
take_overall_damage(amount, 0) take_overall_damage(amount, 0)
else else
heal_overall_damage(-amount, 0) heal_overall_damage(-amount, 0)
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
/mob/living/carbon/human/adjustFireLoss(var/amount) /mob/living/carbon/human/adjustFireLoss(var/amount)
if(species && species.burn_mod) if(species && species.burn_mod)
@@ -97,7 +97,7 @@
take_overall_damage(0, amount) take_overall_damage(0, amount)
else else
heal_overall_damage(0, -amount) heal_overall_damage(0, -amount)
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
/mob/living/carbon/human/proc/adjustBruteLossByPart(var/amount, var/organ_name, var/obj/damage_source = null) /mob/living/carbon/human/proc/adjustBruteLossByPart(var/amount, var/organ_name, var/obj/damage_source = null)
if(species && species.brute_mod) if(species && species.brute_mod)
@@ -112,7 +112,7 @@
//if you don't want to heal robot organs, they you will have to check that yourself before using this proc. //if you don't want to heal robot organs, they you will have to check that yourself before using this proc.
O.heal_damage(-amount, 0, internal=0, robo_repair=(O.status & ORGAN_ROBOT)) O.heal_damage(-amount, 0, internal=0, robo_repair=(O.status & ORGAN_ROBOT))
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
/mob/living/carbon/human/proc/adjustFireLossByPart(var/amount, var/organ_name, var/obj/damage_source = null) /mob/living/carbon/human/proc/adjustFireLossByPart(var/amount, var/organ_name, var/obj/damage_source = null)
if(species && species.burn_mod) if(species && species.burn_mod)
@@ -127,7 +127,7 @@
//if you don't want to heal robot organs, they you will have to check that yourself before using this proc. //if you don't want to heal robot organs, they you will have to check that yourself before using this proc.
O.heal_damage(0, -amount, internal=0, robo_repair=(O.status & ORGAN_ROBOT)) O.heal_damage(0, -amount, internal=0, robo_repair=(O.status & ORGAN_ROBOT))
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
/mob/living/carbon/human/Stun(amount) /mob/living/carbon/human/Stun(amount)
if(HULK in mutations) return if(HULK in mutations) return
@@ -185,7 +185,7 @@
if (O.status & ORGAN_MUTATED) if (O.status & ORGAN_MUTATED)
O.unmutate() O.unmutate()
src << "<span class = 'notice'>Your [O.display_name] is shaped normally again.</span>" src << "<span class = 'notice'>Your [O.display_name] is shaped normally again.</span>"
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
// Defined here solely to take species flags into account without having to recast at mob/living level. // Defined here solely to take species flags into account without having to recast at mob/living level.
/mob/living/carbon/human/getOxyLoss() /mob/living/carbon/human/getOxyLoss()
@@ -249,7 +249,7 @@
var/datum/organ/external/picked = pick(parts) var/datum/organ/external/picked = pick(parts)
if(picked.heal_damage(brute,burn)) if(picked.heal_damage(brute,burn))
UpdateDamageIcon() UpdateDamageIcon()
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
updatehealth() updatehealth()
@@ -265,7 +265,7 @@ In most cases it makes more sense to use apply_damage() instead! And make sure t
var/datum/organ/external/picked = pick(parts) var/datum/organ/external/picked = pick(parts)
if(picked.take_damage(brute,burn,sharp,edge)) if(picked.take_damage(brute,burn,sharp,edge))
UpdateDamageIcon() UpdateDamageIcon()
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
updatehealth() updatehealth()
speech_problem_flag = 1 speech_problem_flag = 1
@@ -288,7 +288,7 @@ In most cases it makes more sense to use apply_damage() instead! And make sure t
parts -= picked parts -= picked
updatehealth() updatehealth()
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
speech_problem_flag = 1 speech_problem_flag = 1
if(update) UpdateDamageIcon() if(update) UpdateDamageIcon()
@@ -309,7 +309,7 @@ In most cases it makes more sense to use apply_damage() instead! And make sure t
parts -= picked parts -= picked
updatehealth() updatehealth()
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
if(update) UpdateDamageIcon() if(update) UpdateDamageIcon()
@@ -336,7 +336,7 @@ This function restores all organs.
if(istype(E, /datum/organ/external)) if(istype(E, /datum/organ/external))
if (E.heal_damage(brute, burn)) if (E.heal_damage(brute, burn))
UpdateDamageIcon() UpdateDamageIcon()
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
else else
return 0 return 0
return return
@@ -393,5 +393,5 @@ This function restores all organs.
// Will set our damageoverlay icon to the next level, which will then be set back to the normal level the next mob.Life(). // Will set our damageoverlay icon to the next level, which will then be set back to the normal level the next mob.Life().
updatehealth() updatehealth()
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
return 1 return 1

View File

@@ -1608,8 +1608,7 @@
/mob/living/carbon/human/proc/handle_hud_list() /mob/living/carbon/human/proc/handle_hud_list()
if (BITTEST(hud_updateflag, HEALTH_HUD))
if(hud_updateflag & 1 << HEALTH_HUD)
var/image/holder = hud_list[HEALTH_HUD] var/image/holder = hud_list[HEALTH_HUD]
if(stat == 2) if(stat == 2)
holder.icon_state = "hudhealth-100" // X_X holder.icon_state = "hudhealth-100" // X_X
@@ -1618,7 +1617,7 @@
holder.icon_state = "hud[percentage_health]" holder.icon_state = "hud[percentage_health]"
hud_list[HEALTH_HUD] = holder hud_list[HEALTH_HUD] = holder
if(hud_updateflag & 1 << STATUS_HUD) if (BITTEST(hud_updateflag, STATUS_HUD))
var/foundVirus = 0 var/foundVirus = 0
for(var/datum/disease/D in viruses) for(var/datum/disease/D in viruses)
if(!D.hidden[SCANNER]) if(!D.hidden[SCANNER])
@@ -1655,7 +1654,7 @@
hud_list[STATUS_HUD] = holder hud_list[STATUS_HUD] = holder
hud_list[STATUS_HUD_OOC] = holder2 hud_list[STATUS_HUD_OOC] = holder2
if(hud_updateflag & 1 << ID_HUD) if (BITTEST(hud_updateflag, ID_HUD))
var/image/holder = hud_list[ID_HUD] var/image/holder = hud_list[ID_HUD]
if(wear_id) if(wear_id)
var/obj/item/weapon/card/id/I = wear_id.GetID() var/obj/item/weapon/card/id/I = wear_id.GetID()
@@ -1669,7 +1668,7 @@
hud_list[ID_HUD] = holder hud_list[ID_HUD] = holder
if(hud_updateflag & 1 << WANTED_HUD) if (BITTEST(hud_updateflag, WANTED_HUD))
var/image/holder = hud_list[WANTED_HUD] var/image/holder = hud_list[WANTED_HUD]
holder.icon_state = "hudblank" holder.icon_state = "hudblank"
var/perpname = name var/perpname = name
@@ -1695,7 +1694,10 @@
break break
hud_list[WANTED_HUD] = holder hud_list[WANTED_HUD] = holder
if(hud_updateflag & 1 << IMPLOYAL_HUD || hud_updateflag & 1 << IMPCHEM_HUD || hud_updateflag & 1 << IMPTRACK_HUD) if ( BITTEST(hud_updateflag, IMPLOYAL_HUD) \
|| BITTEST(hud_updateflag, IMPCHEM_HUD) \
|| BITTEST(hud_updateflag, IMPTRACK_HUD))
var/image/holder1 = hud_list[IMPTRACK_HUD] var/image/holder1 = hud_list[IMPTRACK_HUD]
var/image/holder2 = hud_list[IMPLOYAL_HUD] var/image/holder2 = hud_list[IMPLOYAL_HUD]
var/image/holder3 = hud_list[IMPCHEM_HUD] var/image/holder3 = hud_list[IMPCHEM_HUD]
@@ -1717,7 +1719,7 @@
hud_list[IMPLOYAL_HUD] = holder2 hud_list[IMPLOYAL_HUD] = holder2
hud_list[IMPCHEM_HUD] = holder3 hud_list[IMPCHEM_HUD] = holder3
if(hud_updateflag & 1 << SPECIALROLE_HUD) if (BITTEST(hud_updateflag, SPECIALROLE_HUD))
var/image/holder = hud_list[SPECIALROLE_HUD] var/image/holder = hud_list[SPECIALROLE_HUD]
holder.icon_state = "hudblank" holder.icon_state = "hudblank"
if(mind) if(mind)

View File

@@ -567,8 +567,8 @@ proc/get_damage_icon_part(damage_state, body_part)
else else
overlays_standing[ID_LAYER] = null overlays_standing[ID_LAYER] = null
hud_updateflag |= 1 << ID_HUD BITSET(hud_updateflag, ID_HUD)
hud_updateflag |= 1 << WANTED_HUD BITSET(hud_updateflag, WANTED_HUD)
if(update_icons) update_icons() if(update_icons) update_icons()

View File

@@ -279,8 +279,8 @@
if (C.legcuffed && !initial(C.legcuffed)) if (C.legcuffed && !initial(C.legcuffed))
C.drop_from_inventory(C.legcuffed) C.drop_from_inventory(C.legcuffed)
C.legcuffed = initial(C.legcuffed) C.legcuffed = initial(C.legcuffed)
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
hud_updateflag |= 1 << STATUS_HUD BITSET(hud_updateflag, STATUS_HUD)
/mob/living/proc/rejuvenate() /mob/living/proc/rejuvenate()
@@ -329,8 +329,8 @@
// make the icons look correct // make the icons look correct
regenerate_icons() regenerate_icons()
hud_updateflag |= 1 << HEALTH_HUD BITSET(hud_updateflag, HEALTH_HUD)
hud_updateflag |= 1 << STATUS_HUD BITSET(hud_updateflag, STATUS_HUD)
return return
/mob/living/proc/UpdateDamageIcon() /mob/living/proc/UpdateDamageIcon()

View File

@@ -190,7 +190,7 @@
"\blue You take [obj] out of incision on [target]'s [affected.display_name]s with \the [tool]." ) "\blue You take [obj] out of incision on [target]'s [affected.display_name]s with \the [tool]." )
affected.implants -= obj affected.implants -= obj
target.hud_updateflag |= 1 << IMPLOYAL_HUD BITSET(target.hud_updateflag, IMPLOYAL_HUD)
//Handle possessive brain borers. //Handle possessive brain borers.
if(istype(obj,/mob/living/simple_animal/borer)) if(istype(obj,/mob/living/simple_animal/borer))

View File

@@ -100,7 +100,7 @@
for(var/datum/disease2/effectholder/e in effects) for(var/datum/disease2/effectholder/e in effects)
e.effect.deactivate(mob) e.effect.deactivate(mob)
mob.virus2.Remove("[uniqueID]") mob.virus2.Remove("[uniqueID]")
mob.hud_updateflag |= 1 << STATUS_HUD BITSET(mob.hud_updateflag, STATUS_HUD)
/datum/disease2/disease/proc/minormutate() /datum/disease2/disease/proc/minormutate()
//uniqueID = rand(0,10000) //uniqueID = rand(0,10000)

View File

@@ -94,7 +94,7 @@ proc/airborne_can_reach(turf/source, turf/target)
D.minormutate() D.minormutate()
// log_debug("Adding virus") // log_debug("Adding virus")
M.virus2["[D.uniqueID]"] = D M.virus2["[D.uniqueID]"] = D
M.hud_updateflag |= 1 << STATUS_HUD BITSET(M.hud_updateflag, STATUS_HUD)
//Infects mob M with random lesser disease, if he doesn't have one //Infects mob M with random lesser disease, if he doesn't have one
/proc/infect_mob_random_lesser(var/mob/living/carbon/M) /proc/infect_mob_random_lesser(var/mob/living/carbon/M)
@@ -102,14 +102,14 @@ proc/airborne_can_reach(turf/source, turf/target)
D.makerandom() D.makerandom()
D.infectionchance = 1 D.infectionchance = 1
infect_virus2(M,D,1) infect_virus2(M,D,1)
M.hud_updateflag |= 1 << STATUS_HUD BITSET(M.hud_updateflag, STATUS_HUD)
//Infects mob M with random greated disease, if he doesn't have one //Infects mob M with random greated disease, if he doesn't have one
/proc/infect_mob_random_greater(var/mob/living/carbon/M) /proc/infect_mob_random_greater(var/mob/living/carbon/M)
var/datum/disease2/disease/D = new /datum/disease2/disease var/datum/disease2/disease/D = new /datum/disease2/disease
D.makerandom(1) D.makerandom(1)
infect_virus2(M,D,1) infect_virus2(M,D,1)
M.hud_updateflag |= 1 << STATUS_HUD BITSET(M.hud_updateflag, STATUS_HUD)
//Fancy prob() function. //Fancy prob() function.
/proc/dprob(var/p) /proc/dprob(var/p)