Skip to content

Commit

Permalink
modulo conversion for 515 (#6264)
Browse files Browse the repository at this point in the history
# About the pull request


![image](https://github.com/cmss13-devs/cmss13/assets/14267245/f04d12d5-ce42-493b-814a-a22a2e56fbd2)
https://www.byond.com/docs/ref/#/operator/%25%25

With the move to 515, removes this define in favor of `x %% y`:
`#define MODULUS(x, y) ( (x) - (y) * round((x) / (y)) )`
And this one in favor of `x %% 360`:
`#define SIMPLIFY_DEGREES(degrees) (MODULUS((degrees), 360))`

<!-- 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

Less bespoke code means less points of failure.
# Testing Photographs and Procedure
Boots without obvious issue.


# Changelog
No player-facing changes.
  • Loading branch information
Doubleumc authored May 13, 2024
1 parent 80a60e4 commit ac2a986
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
7 changes: 0 additions & 7 deletions code/__DEFINES/_math.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@
// round() acts like floor(x, 1) by default but can't handle other values
#define FLOOR(x, y) ( floor((x) / (y)) * (y) )

// Real modulus that handles decimals
#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))

// Same as above, exclusive.
#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.
#define SIMPLIFY_DEGREES(degrees) (MODULUS((degrees), 360))

/// Gets the sign of x, returns -1 if negative, 0 if 0, 1 if positive
#define SIGN(x) ( ((x) > 0) - ((x) < 0) )

Expand Down
6 changes: 3 additions & 3 deletions code/__HELPERS/_time.dm
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ GLOBAL_VAR_INIT(rollovercheck_last_timeofday, 0)
if(second < 60)
return "[second] second[(second != 1)? "s":""]"
var/minute = floor(second / 60)
second = FLOOR(MODULUS(second, 60), round_seconds_to)
second = FLOOR(second %% 60, round_seconds_to)
var/secondT
if(second)
secondT = " and [second] second[(second != 1)? "s":""]"
if(minute < 60)
return "[minute] minute[(minute != 1)? "s":""][secondT]"
var/hour = floor(minute / 60)
minute = MODULUS(minute, 60)
minute %%= 60
var/minuteT
if(minute)
minuteT = " and [minute] minute[(minute != 1)? "s":""]"
if(hour < 24)
return "[hour] hour[(hour != 1)? "s":""][minuteT][secondT]"
var/day = floor(hour / 24)
hour = MODULUS(hour, 24)
hour %%= 24
var/hourT
if(hour)
hourT = " and [hour] hour[(hour != 1)? "s":""]"
Expand Down
2 changes: 1 addition & 1 deletion code/modules/shuttle/docking.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
rotation = dir2angle(new_dock.dir)-dir2angle(dir)
if ((rotation % 90) != 0)
rotation += (rotation % 90) //diagonal rotations not allowed, round up
rotation = SIMPLIFY_DEGREES(rotation)
rotation %%= 360

if(!movement_direction)
movement_direction = turn(preferred_direction, 180)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/vehicles/hardpoints/hardpoint.dm
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@
if(muzzle_turf == target_turf)
return FALSE

var/angle_diff = SIMPLIFY_DEGREES(dir2angle(dir) - Get_Angle(muzzle_turf, target_turf))
var/angle_diff = (dir2angle(dir) - Get_Angle(muzzle_turf, target_turf)) %% 360
if(angle_diff < -180)
angle_diff += 360
else if(angle_diff > 180)
Expand Down

0 comments on commit ac2a986

Please sign in to comment.