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 (active2)
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"])
if("none")
active2.fields["criminal"] = "None"

View File

@@ -343,6 +343,12 @@ proc/listclearnulls(list/list)
return (result + L.Copy(Li, 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)
/proc/bitfield2list(bitfield = 0, list/wordlist)
var/list/r = list()

View File

@@ -1,6 +1,7 @@
// Credits to Nickr5 for the useful procs I've taken from his library resource.
var/const/E = 2.71828183
var/const/Pi = 3.14159265
var/const/Sqrt2 = 1.41421356
// 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,
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)
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
/proc/Wrap(val, min, max)
var/d = max - min
var/t = Floor((val - min) / d)
return val - (t * d)
proc/RaiseToPower(num, power)
if(!power) return 1
return (power-- > 1 ? num * RaiseToPower(num, power) : num)
/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)
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()
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 */
proc/isDay(var/month, var/day)
if(isnum(month) && isnum(day))

View File

@@ -9,91 +9,72 @@
* worldtime2text
*/
//Returns an integer given a hex input
// Returns an integer given a hexadecimal number string as input.
/proc/hex2num(hex)
if (!( istext(hex) ))
if (!istext(hex))
return
var/num = 0
var/power = 0
var/i = null
i = length(hex)
while(i > 0)
var/char = copytext(hex, i, i + 1)
var/power = 1
var/i = length(hex)
while (i)
var/char = text2ascii(hex, i)
switch(char)
if("0")
//Apparently, switch works with empty statements, yay! If that doesn't work, blame me, though. -- Urist
if("9", "8", "7", "6", "5", "4", "3", "2", "1")
num += text2num(char) * 16 ** power
if("a", "A")
num += 16 ** power * 10
if("b", "B")
num += 16 ** power * 11
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
if(48) // 0 -- do nothing
if(49 to 57) num += (char - 48) * power // 1-9
if(97, 65) num += power * 10 // A
if(98, 66) num += power * 11 // B
if(99, 67) num += power * 12 // C
if(100, 68) num += power * 13 // D
if(101, 69) num += power * 14 // E
if(102, 70) num += power * 15 // F
else
return
power++
power *= 16
i--
return num
//Returns the hex value of a number given a value assumed to be a base-ten value
/proc/num2hex(num, placeholder)
// Returns the hex value of a number given a value assumed to be a base-ten value
/proc/num2hex(num, digits)
if (digits == null)
digits = 2
if (placeholder == null)
placeholder = 2
if (!( isnum(num) ))
if (!isnum(num))
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.
/proc/list2text(list/ls, sep)
if(ls.len <= 1) // Early-out code for empty or singleton lists.
if (ls.len <= 1) // Early-out code for empty or singleton lists.
return ls.len ? ls[1] : ""
var/l = ls.len // Made local for sanic speed.
var/i = 0 // Incremented every time a list index is accessed.
if(sep <> null)
if (sep <> null)
// Macros expand to long argument lists like so: sep, ls[++i], sep, ls[++i], sep, ls[++i], etc...
#define S1 sep, ls[++i]
#define S4 S1, S1, S1, S1
@@ -103,25 +84,25 @@
. = "[ls[++i]]" // Make sure the initial element is converted to text.
// Having the small concatenations come before the large ones boosted speed by an average of at least 5%.
if(l-1 & 0x01) // 'i' will always be 1 here.
if (l-1 & 0x01) // 'i' will always be 1 here.
. = text("[][][]", ., S1) // Append 1 element if the remaining elements are not a multiple of 2.
if(l-i & 0x02)
if (l-i & 0x02)
. = text("[][][][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4.
if(l-i & 0x04)
if (l-i & 0x04)
. = text("[][][][][][][][][]", ., S4) // And so on....
if(l-i & 0x08)
if (l-i & 0x08)
. = text("[][][][][][][][][][][][][][][][][]", ., S4, S4)
if(l-i & 0x10)
if (l-i & 0x10)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16)
if(l-i & 0x20)
if (l-i & 0x20)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
if(l-i & 0x40)
if (l-i & 0x40)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
while(l > i) // Chomp through the rest of the list, 128 elements at a time.
while (l > i) // Chomp through the rest of the list, 128 elements at a time.
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
@@ -135,7 +116,6 @@
#undef S16
#undef S4
#undef S1
else
// Macros expand to long argument lists like so: ls[++i], ls[++i], ls[++i], etc...
#define S1 ls[++i]
@@ -145,22 +125,22 @@
. = "[ls[++i]]" // Make sure the initial element is converted to text.
if(l-1 & 0x01) // 'i' will always be 1 here.
if (l-1 & 0x01) // 'i' will always be 1 here.
. += S1 // Append 1 element if the remaining elements are not a multiple of 2.
if(l-i & 0x02)
if (l-i & 0x02)
. = text("[][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4.
if(l-i & 0x04)
if (l-i & 0x04)
. = text("[][][][][]", ., S4) // And so on...
if(l-i & 0x08)
if (l-i & 0x08)
. = text("[][][][][][][][][]", ., S4, S4)
if(l-i & 0x10)
if (l-i & 0x10)
. = text("[][][][][][][][][][][][][][][][][]", ., S16)
if(l-i & 0x20)
if (l-i & 0x20)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
if(l-i & 0x40)
if (l-i & 0x40)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
while(l > i) // Chomp through the rest of the list, 128 elements at a time.
while (l > i) // Chomp through the rest of the list, 128 elements at a time.
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
@@ -171,21 +151,19 @@
#undef S4
#undef S1
//slower then list2text, but correctly processes associative lists.
// Slower then list2text, but correctly processes associative lists.
proc/tg_list2text(list/list, glue=",")
if(!istype(list) || !list.len)
if (!istype(list) || !list.len)
return
var/output
for(var/i=1 to list.len)
output += (i!=1? glue : null)+(!isnull(list["[list[i]]"])?"[list["[list[i]]"]]":"[list[i]]")
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")
var/delim_len = length(delimiter)
if(delim_len < 1) return list(text)
if (delim_len < 1) return list(text)
. = list()
var/last_found = 1
var/found
@@ -193,7 +171,7 @@ proc/tg_list2text(list/list, glue=",")
found = findtext(text, delimiter, last_found, 0)
. += copytext(text, last_found, found)
last_found = found + delim_len
while(found)
while (found)
/proc/text2numlist(text, delimiter="\n")
var/list/num_list = list()
@@ -201,10 +179,10 @@ proc/tg_list2text(list/list, glue=",")
num_list += text2num(x)
return num_list
//Case Sensitive!
// Case Sensitive!
/proc/text2listEx(text, delimiter="\n")
var/delim_len = length(delimiter)
if(delim_len < 1) return list(text)
if (delim_len < 1) return list(text)
. = list()
var/last_found = 1
var/found
@@ -212,130 +190,110 @@ proc/tg_list2text(list/list, glue=",")
found = findtextEx(text, delimiter, last_found, 0)
. += copytext(text, last_found, found)
last_found = found + delim_len
while(found)
while (found)
//Splits the text of a file at seperator and returns them in a list.
// Splits the text of a file at seperator and returns them in a list.
/proc/file2list(filename, seperator="\n")
return text2list(return_file_text(filename),seperator)
//Turns a direction into text
// Turns a direction into text
/proc/num2dir(direction)
switch(direction)
if(1.0) return NORTH
if(2.0) return SOUTH
if(4.0) return EAST
if(8.0) return WEST
switch (direction)
if (1.0) return NORTH
if (2.0) return SOUTH
if (4.0) return EAST
if (8.0) return WEST
else
world.log << "UNKNOWN DIRECTION: [direction]"
//Turns a direction into text
// Turns a direction into text
/proc/dir2text(direction)
switch(direction)
if(1.0)
return "north"
if(2.0)
return "south"
if(4.0)
return "east"
if(8.0)
return "west"
if(5.0)
return "northeast"
if(6.0)
return "southeast"
if(9.0)
return "northwest"
if(10.0)
return "southwest"
switch (direction)
if (1.0) return "north"
if (2.0) return "south"
if (4.0) return "east"
if (8.0) return "west"
if (5.0) return "northeast"
if (6.0) return "southeast"
if (9.0) return "northwest"
if (10.0) return "southwest"
else
return
//Turns text into proper directions
// Turns text into proper directions
/proc/text2dir(direction)
switch(uppertext(direction))
if("NORTH")
return 1
if("SOUTH")
return 2
if("EAST")
return 4
if("WEST")
return 8
if("NORTHEAST")
return 5
if("NORTHWEST")
return 9
if("SOUTHEAST")
return 6
if("SOUTHWEST")
return 10
switch (uppertext(direction))
if ("NORTH") return 1
if ("SOUTH") return 2
if ("EAST") return 4
if ("WEST") return 8
if ("NORTHEAST") return 5
if ("NORTHWEST") return 9
if ("SOUTHEAST") return 6
if ("SOUTHWEST") return 10
else
return
//Converts an angle (degrees) into an ss13 direction
// Converts an angle (degrees) into an ss13 direction
/proc/angle2dir(var/degree)
degree = ((degree+22.5)%365)
if(degree < 45) return NORTH
if(degree < 90) return NORTHEAST
if(degree < 135) return EAST
if(degree < 180) return SOUTHEAST
if(degree < 225) return SOUTH
if(degree < 270) return SOUTHWEST
if(degree < 315) return WEST
degree = (degree + 22.5) % 365 // 22.5 = 45 / 2
if (degree < 45) return NORTH
if (degree < 90) return NORTHEAST
if (degree < 135) return EAST
if (degree < 180) return SOUTHEAST
if (degree < 225) return SOUTH
if (degree < 270) return SOUTHWEST
if (degree < 315) return 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)
switch(D)
if(NORTH) return 0
if(SOUTH) return 180
if(EAST) return 90
if(WEST) return 270
if(NORTHEAST) return 45
if(SOUTHEAST) return 135
if(NORTHWEST) return 315
if(SOUTHWEST) return 225
else return null
switch (D)
if (NORTH) return 0
if (SOUTH) return 180
if (EAST) return 90
if (WEST) return 270
if (NORTHEAST) return 45
if (SOUTHEAST) return 135
if (NORTHWEST) return 315
if (SOUTHWEST) return 225
else
return null
//Returns the angle in english
// Returns the angle in english
/proc/angle2text(var/degree)
return dir2text(angle2dir(degree))
//Converts a blend_mode constant to one acceptable to icon.Blend()
// Converts a blend_mode constant to one acceptable to icon.Blend()
/proc/blendMode2iconMode(blend_mode)
switch(blend_mode)
if(BLEND_MULTIPLY) return ICON_MULTIPLY
if(BLEND_ADD) return ICON_ADD
if(BLEND_SUBTRACT) return ICON_SUBTRACT
switch (blend_mode)
if (BLEND_MULTIPLY) return ICON_MULTIPLY
if (BLEND_ADD) return ICON_ADD
if (BLEND_SUBTRACT) return ICON_SUBTRACT
else return ICON_OVERLAY
//Converts a rights bitfield into a string
// Converts a rights bitfield into a string
/proc/rights2text(rights,seperator="")
if(rights & R_BUILDMODE) . += "[seperator]+BUILDMODE"
if(rights & R_ADMIN) . += "[seperator]+ADMIN"
if(rights & R_BAN) . += "[seperator]+BAN"
if(rights & R_FUN) . += "[seperator]+FUN"
if(rights & R_SERVER) . += "[seperator]+SERVER"
if(rights & R_DEBUG) . += "[seperator]+DEBUG"
if(rights & R_POSSESS) . += "[seperator]+POSSESS"
if(rights & R_PERMISSIONS) . += "[seperator]+PERMISSIONS"
if(rights & R_STEALTH) . += "[seperator]+STEALTH"
if(rights & R_REJUVINATE) . += "[seperator]+REJUVINATE"
if(rights & R_VAREDIT) . += "[seperator]+VAREDIT"
if(rights & R_SOUNDS) . += "[seperator]+SOUND"
if(rights & R_SPAWN) . += "[seperator]+SPAWN"
if(rights & R_MOD) . += "[seperator]+MODERATOR"
if(rights & R_MENTOR) . += "[seperator]+MENTOR"
if (rights & R_BUILDMODE) . += "[seperator]+BUILDMODE"
if (rights & R_ADMIN) . += "[seperator]+ADMIN"
if (rights & R_BAN) . += "[seperator]+BAN"
if (rights & R_FUN) . += "[seperator]+FUN"
if (rights & R_SERVER) . += "[seperator]+SERVER"
if (rights & R_DEBUG) . += "[seperator]+DEBUG"
if (rights & R_POSSESS) . += "[seperator]+POSSESS"
if (rights & R_PERMISSIONS) . += "[seperator]+PERMISSIONS"
if (rights & R_STEALTH) . += "[seperator]+STEALTH"
if (rights & R_REJUVINATE) . += "[seperator]+REJUVINATE"
if (rights & R_VAREDIT) . += "[seperator]+VAREDIT"
if (rights & R_SOUNDS) . += "[seperator]+SOUND"
if (rights & R_SPAWN) . += "[seperator]+SPAWN"
if (rights & R_MOD) . += "[seperator]+MODERATOR"
if (rights & R_MENTOR) . += "[seperator]+MENTOR"
return .
/proc/ui_style2icon(ui_style)
switch(ui_style)
if("old") return 'icons/mob/screen1_old.dmi'
if("Orange") return 'icons/mob/screen1_Orange.dmi'
if("Midnight") return 'icons/mob/screen1_Midnight.dmi'
switch (ui_style)
if ("old") return 'icons/mob/screen1_old.dmi'
if ("Orange") return 'icons/mob/screen1_Orange.dmi'
if ("Midnight") return 'icons/mob/screen1_Midnight.dmi'
else return 'icons/mob/screen1_White.dmi'

View File

@@ -500,7 +500,7 @@ datum/mind
else if(href_list["implant"])
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"])
if("remove")
@@ -540,7 +540,7 @@ datum/mind
else if (href_list["revolution"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD)
BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["revolution"])
if("clear")
@@ -635,7 +635,7 @@ datum/mind
usr << "\red Reequipping revolutionary goes wrong!"
else if (href_list["cult"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD)
BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["cult"])
if("clear")
if(src in ticker.mode.cult)
@@ -685,7 +685,7 @@ datum/mind
usr << "\red Spawning amulet failed!"
else if (href_list["wizard"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD)
BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["wizard"])
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."
else if (href_list["changeling"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD)
BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["changeling"])
if("clear")
if(src in ticker.mode.changelings)
@@ -751,7 +751,7 @@ datum/mind
else if (href_list["nuclear"])
var/mob/living/carbon/human/H = current
current.hud_updateflag |= (1 << SPECIALROLE_HUD)
BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["nuclear"])
if("clear")
@@ -805,7 +805,7 @@ datum/mind
usr << "\red No valid nuke found!"
else if (href_list["traitor"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD)
BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["traitor"])
if("clear")
if(src in ticker.mode.traitors)
@@ -888,7 +888,7 @@ datum/mind
current.radiation -= 50
else if (href_list["silicon"])
current.hud_updateflag |= (1 << SPECIALROLE_HUD)
BITSET(current.hud_updateflag, SPECIALROLE_HUD)
switch(href_list["silicon"])
if("unmalf")
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 << "<B>You are now a traitor.</B>"
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>"
show_objectives(newtraitor.mind)

View File

@@ -205,7 +205,7 @@
if(rev_mind in revolutionaries)
revolutionaries -= rev_mind
rev_mind.special_role = null
rev_mind.current.hud_updateflag |= 1 << SPECIALROLE_HUD
BITSET(rev_mind.current.hud_updateflag, SPECIALROLE_HUD)
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>"

View File

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

View File

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

View File

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

View File

@@ -534,7 +534,7 @@ What a mess.*/
if ("Change Criminal Status")
if (active2)
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"])
if("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")
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)

View File

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

View File

@@ -190,12 +190,12 @@
admin_log_and_message_admins("has [report_at_round_end ? "enabled" : "disabled"] the round end event report.")
else if(href_list["dec_timer"])
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
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"])
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
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"])

View File

@@ -179,7 +179,7 @@ var/list/rune_animation = list(
var/icon/base = icon('icons/effects/uristrunes.dmi', "")
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)
var/icon/result
@@ -217,7 +217,7 @@ var/list/rune_animation = list(
var/icon/I = icon('icons/effects/uristrunes.dmi', "blank")
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)
var/obj/o = new(locate(x, y, z))
@@ -229,7 +229,7 @@ var/list/rune_animation = list(
var/rune = rand(1, 1023)
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)
var/obj/o = new(t)

View File

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

View File

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

View File

@@ -87,7 +87,7 @@
take_overall_damage(amount, 0)
else
heal_overall_damage(-amount, 0)
hud_updateflag |= 1 << HEALTH_HUD
BITSET(hud_updateflag, HEALTH_HUD)
/mob/living/carbon/human/adjustFireLoss(var/amount)
if(species && species.burn_mod)
@@ -97,7 +97,7 @@
take_overall_damage(0, amount)
else
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)
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.
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)
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.
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)
if(HULK in mutations) return
@@ -185,7 +185,7 @@
if (O.status & ORGAN_MUTATED)
O.unmutate()
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.
/mob/living/carbon/human/getOxyLoss()
@@ -249,7 +249,7 @@
var/datum/organ/external/picked = pick(parts)
if(picked.heal_damage(brute,burn))
UpdateDamageIcon()
hud_updateflag |= 1 << HEALTH_HUD
BITSET(hud_updateflag, HEALTH_HUD)
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)
if(picked.take_damage(brute,burn,sharp,edge))
UpdateDamageIcon()
hud_updateflag |= 1 << HEALTH_HUD
BITSET(hud_updateflag, HEALTH_HUD)
updatehealth()
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
updatehealth()
hud_updateflag |= 1 << HEALTH_HUD
BITSET(hud_updateflag, HEALTH_HUD)
speech_problem_flag = 1
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
updatehealth()
hud_updateflag |= 1 << HEALTH_HUD
BITSET(hud_updateflag, HEALTH_HUD)
if(update) UpdateDamageIcon()
@@ -336,7 +336,7 @@ This function restores all organs.
if(istype(E, /datum/organ/external))
if (E.heal_damage(brute, burn))
UpdateDamageIcon()
hud_updateflag |= 1 << HEALTH_HUD
BITSET(hud_updateflag, HEALTH_HUD)
else
return 0
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().
updatehealth()
hud_updateflag |= 1 << HEALTH_HUD
BITSET(hud_updateflag, HEALTH_HUD)
return 1

View File

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

View File

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

View File

@@ -279,8 +279,8 @@
if (C.legcuffed && !initial(C.legcuffed))
C.drop_from_inventory(C.legcuffed)
C.legcuffed = initial(C.legcuffed)
hud_updateflag |= 1 << HEALTH_HUD
hud_updateflag |= 1 << STATUS_HUD
BITSET(hud_updateflag, HEALTH_HUD)
BITSET(hud_updateflag, STATUS_HUD)
/mob/living/proc/rejuvenate()
@@ -329,8 +329,8 @@
// make the icons look correct
regenerate_icons()
hud_updateflag |= 1 << HEALTH_HUD
hud_updateflag |= 1 << STATUS_HUD
BITSET(hud_updateflag, HEALTH_HUD)
BITSET(hud_updateflag, STATUS_HUD)
return
/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]." )
affected.implants -= obj
target.hud_updateflag |= 1 << IMPLOYAL_HUD
BITSET(target.hud_updateflag, IMPLOYAL_HUD)
//Handle possessive brain borers.
if(istype(obj,/mob/living/simple_animal/borer))

View File

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

View File

@@ -94,7 +94,7 @@ proc/airborne_can_reach(turf/source, turf/target)
D.minormutate()
// log_debug("Adding virus")
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
/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.infectionchance = 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
/proc/infect_mob_random_greater(var/mob/living/carbon/M)
var/datum/disease2/disease/D = new /datum/disease2/disease
D.makerandom(1)
infect_virus2(M,D,1)
M.hud_updateflag |= 1 << STATUS_HUD
BITSET(M.hud_updateflag, STATUS_HUD)
//Fancy prob() function.
/proc/dprob(var/p)