Skip to content

Commit

Permalink
Defines parentheses (#5654)
Browse files Browse the repository at this point in the history
# About the pull request

Following on the heels of
#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.

<!-- Remove this text and explain what the purpose of your PR is.

Mention if you have tested your changes. If you changed a map, make sure
you used the mapmerge tool.
If this is an Issue Correction, you can type "Fixes Issue #169420" to
link the PR to the corresponding Issue number #169420.

Remember: something that is self-evident to you might not be to others.
Explain your rationale fully, even if you feel it goes without saying.
-->

# 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.
  • Loading branch information
Doubleumc committed Feb 5, 2024
1 parent 19cf7a5 commit 4c29353
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions code/__DEFINES/__game.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions code/__DEFINES/_math.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) )
2 changes: 1 addition & 1 deletion code/__DEFINES/xeno.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 12 additions & 12 deletions code/__HELPERS/#maths.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,44 @@ 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))

// 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
Expand Down
14 changes: 7 additions & 7 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand All @@ -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 ) | \
Expand Down
6 changes: 3 additions & 3 deletions code/_macros.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)]"

Expand Down

0 comments on commit 4c29353

Please sign in to comment.