From 4c293532d20ccfe5d5771ad9dffd915b7ebdd254 Mon Sep 17 00:00:00 2001 From: Doubleumc Date: Mon, 5 Feb 2024 04:33:13 -0500 Subject: [PATCH] Defines parentheses (#5654) # About the pull request Following on the heels of https://github.com/cmss13-devs/cmss13/pull/5637 adds parentheses around the arguments of several other global defines, to ensure the order of operations resolves as intended. While some of these aren't strictly necessary due to operator precedence better safe than sorry. # Explain why it's good for the game Pre-empts possible issues in the future. # Testing Photographs and Procedure Boots without obvious issue. # Changelog No player-facing changes. --- code/__DEFINES/__game.dm | 4 ++-- code/__DEFINES/_math.dm | 6 +++--- code/__DEFINES/xeno.dm | 2 +- code/__HELPERS/#maths.dm | 24 ++++++++++++------------ code/__HELPERS/unsorted.dm | 14 +++++++------- code/_macros.dm | 6 +++--- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/code/__DEFINES/__game.dm b/code/__DEFINES/__game.dm index ead4c9665c7c..dfa335375b67 100644 --- a/code/__DEFINES/__game.dm +++ b/code/__DEFINES/__game.dm @@ -283,7 +283,7 @@ block( \ // Helpers /// Only use the CEILING_PROTECTION_TIER_X defines for `protection_level` -#define CEILING_IS_PROTECTED(ceiling, protection_level) (ceiling >= protection_level) +#define CEILING_IS_PROTECTED(ceiling, protection_level) ((ceiling) >= (protection_level)) // Default font settings #define FONT_SIZE "5pt" @@ -536,7 +536,7 @@ block( \ /// `amount` - The number to get per time /// `time` - The time period in which to gain this amount /// To be used with delta_time. Multiplied by 10 to convert from deciseconds to seconds -#define AMOUNT_PER_TIME(amount, time) ((amount / (time))*10) +#define AMOUNT_PER_TIME(amount, time) (((amount) / (time))*10) // Local message mode. Used to decide wheter message should be dispatched on the radio. #define MESSAGE_MODE_LOCAL 1 diff --git a/code/__DEFINES/_math.dm b/code/__DEFINES/_math.dm index 138adeeda451..f0281f51cedb 100644 --- a/code/__DEFINES/_math.dm +++ b/code/__DEFINES/_math.dm @@ -21,10 +21,10 @@ #define MODULUS(x, y) ( (x) - (y) * round((x) / (y)) ) // Returns true if val is from min to max, inclusive. -#define ISINRANGE(val, min, max) (min <= val && val <= max) +#define ISINRANGE(val, min, max) ((min) <= (val) && (val) <= (max)) // Same as above, exclusive. -#define ISINRANGE_EX(val, min, max) (min < val && val < max) +#define ISINRANGE_EX(val, min, max) ((min) < (val) && (val) < (max)) // Will filter out extra rotations and negative rotations // E.g: 540 becomes 180. -180 becomes 180. @@ -34,4 +34,4 @@ #define SIGN(x) ( ((x) > 0) - ((x) < 0) ) /// 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. -#define LERP(a, b, amount) ( amount ? ((a) + ((b) - (a)) * (amount)) : a ) +#define LERP(a, b, amount) ( (amount) ? ((a) + ((b) - (a)) * (amount)) : (a) ) diff --git a/code/__DEFINES/xeno.dm b/code/__DEFINES/xeno.dm index e3a35d0c4744..2761bc12acf0 100644 --- a/code/__DEFINES/xeno.dm +++ b/code/__DEFINES/xeno.dm @@ -660,7 +660,7 @@ // PARAMETERS: // source_hive integer the hive to check the alliance of // target_hive integer the target hive to see if the source_hive is allied to it. -#define HIVE_ALLIED_TO_HIVE(source_hive, target_hive) (source_hive == target_hive || GLOB.hive_datum[source_hive]?.faction_is_ally(GLOB.hive_datum[target_hive]?.internal_faction)) +#define HIVE_ALLIED_TO_HIVE(source_hive, target_hive) ((source_hive) == (target_hive) || GLOB.hive_datum[source_hive]?.faction_is_ally(GLOB.hive_datum[target_hive]?.internal_faction)) #define QUEEN_SPAWN_TIMEOUT (2 MINUTES) diff --git a/code/__HELPERS/#maths.dm b/code/__HELPERS/#maths.dm index 825090bc4f3b..f8a9292d3806 100644 --- a/code/__HELPERS/#maths.dm +++ b/code/__HELPERS/#maths.dm @@ -9,7 +9,7 @@ GLOBAL_LIST_INIT(sqrtTable, list(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, // MATH DEFINES #define Ceiling(x) (-round(-(x))) -#define CLAMP01(x) (clamp(x, 0, 1)) +#define CLAMP01(x) (clamp((x), 0, 1)) // cotangent #define Cot(x) (1 / tan(x)) @@ -17,36 +17,36 @@ GLOBAL_LIST_INIT(sqrtTable, list(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, // cosecant #define Csc(x) (1 / sin(x)) -#define Default(a, b) (a ? a : b) +#define Default(a, b) ((a) ? (a) : (b)) #define Floor(x) (round(x)) // Greatest Common Divisor - Euclid's algorithm -#define Gcd(a, b) (b ? Gcd(b, a % b) : a) +#define Gcd(a, b) ((b) ? Gcd((b), (a) % (b)) : (a)) -#define Inverse(x) (1 / x) -#define IsEven(x) (x % 2 == 0) +#define Inverse(x) (1 / (x)) +#define IsEven(x) ((x) % 2 == 0) -#define IsInteger(x) (Floor(x) == x) +#define IsInteger(x) (Floor(x) == (x)) #define IsOdd(x) (!IsEven(x)) -#define IsMultiple(x, y) (x % y == 0) +#define IsMultiple(x, y) ((x) % (y) == 0) // Least Common Multiple -#define Lcm(a, b) (abs(a) / Gcd(a, b) * abs(b)) +#define Lcm(a, b) (abs(a) / Gcd((a), (b)) * abs(b)) // Returns the nth root of x. -#define NRoot(n, x) (x ** (1 / n)) +#define NRoot(n, x) ((x) ** (1 / (n))) // secant #define Sec(x) (1 / cos(x)) // 57.2957795 = 180 / Pi -#define ToDegrees(radians) (radians * 57.2957795) +#define ToDegrees(radians) ((radians) * 57.2957795) // 0.0174532925 = Pi / 180 -#define ToRadians(degrees) (degrees * 0.0174532925) +#define ToRadians(degrees) ((degrees) * 0.0174532925) // min is inclusive, max is exclusive -#define WRAP(val, min, max) clamp(( min == max ? min : (val) - (round(((val) - (min))/((max) - (min))) * ((max) - (min))) ),min,max) +#define WRAP(val, min, max) clamp(( (min) == (max) ? (min) : (val) - (round(((val) - (min))/((max) - (min))) * ((max) - (min))) ),(min),(max)) // MATH PROCS diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 7324c4a9634e..2fd7ea8919df 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -21,23 +21,23 @@ #define between(low, middle, high) (max(min(middle, high), low)) //Offuscate x for coord system -#define obfuscate_x(x) (x + GLOB.obfs_x) +#define obfuscate_x(x) ((x) + GLOB.obfs_x) //Offuscate y for coord system -#define obfuscate_y(y) (y + GLOB.obfs_y) +#define obfuscate_y(y) ((y) + GLOB.obfs_y) //Deoffuscate x for coord system -#define deobfuscate_x(x) (x - GLOB.obfs_x) +#define deobfuscate_x(x) ((x) - GLOB.obfs_x) //Deoffuscate y for coord system -#define deobfuscate_y(y) (y - GLOB.obfs_y) +#define deobfuscate_y(y) ((y) - GLOB.obfs_y) #define can_xeno_build(T) (!T.density && !(locate(/obj/structure/fence) in T) && !(locate(/obj/structure/tunnel) in T) && (locate(/obj/effect/alien/weeds) in T)) // For the purpose of a skillcheck, not having a skillset counts as being skilled in everything (!user.skills check) // Note that is_skilled() checks if the skillset contains the skill internally, so a has_skill check is unnecessary -#define skillcheck(user, skill, req_level) ((!user.skills || user.skills.is_skilled(skill, req_level))) -#define skillcheckexplicit(user, skill, req_level) ((!user.skills || user.skills.is_skilled(skill, req_level, TRUE))) +#define skillcheck(user, skill, req_level) ((!user.skills || user.skills.is_skilled((skill), (req_level)))) +#define skillcheckexplicit(user, skill, req_level) ((!user.skills || user.skills.is_skilled((skill), (req_level), TRUE))) // Ensure the frequency is within bounds of what it should be sending/receiving at // Sets f within bounds via `clamp(round(f), 1441, 1489)` @@ -48,7 +48,7 @@ ) //Turns 1479 into 147.9 -#define format_frequency(f) "[round(f / 10)].[f % 10]" +#define format_frequency(f) "[round((f) / 10)].[(f) % 10]" #define reverse_direction(direction) ( \ ( dir & (NORTH|SOUTH) ? ~dir & (NORTH|SOUTH) : 0 ) | \ diff --git a/code/_macros.dm b/code/_macros.dm index e8a97cbada83..ec4f559f0bfc 100644 --- a/code/_macros.dm +++ b/code/_macros.dm @@ -78,14 +78,14 @@ // Spawns multiple objects of the same type #define cast_new(type, num, args...) if((num) == 1) { new type(args) } else { for(var/i=0;i<(num),i++) { new type(args) } } -#define FLAGS_EQUALS(flag, flags) ((flag & (flags)) == (flags)) +#define FLAGS_EQUALS(flag, flags) (((flag) & (flags)) == (flags)) #define IS_DIAGONAL_DIR(dir) (dir & ~(NORTH|SOUTH)) // Inverse direction, taking into account UP|DOWN if necessary. -#define REVERSE_DIR(dir) ( ((dir & 85) << 1) | ((dir & 170) >> 1) ) +#define REVERSE_DIR(dir) ( (((dir) & 85) << 1) | (((dir) & 170) >> 1) ) -#define POSITIVE(val) max(val, 0) +#define POSITIVE(val) max((val), 0) #define GENERATE_DEBUG_ID "[rand(0, 9)][rand(0, 9)][rand(0, 9)][rand(0, 9)][pick(alphabet_lowercase)][pick(alphabet_lowercase)][pick(alphabet_lowercase)][pick(alphabet_lowercase)]"