Skip to content

Commit

Permalink
Americanize Contests System (#814)
Browse files Browse the repository at this point in the history
# Description

I have updated the Contests System to make it safe to use by Americans.
This is accomplished by adding very helpful warning labels, as well as
restricting the Range of all its functions so that they cannot return
either a negative number, or a zero. Therefore, all Contests are now
perfectly safe to divide by.

# Changelog

:cl:
- tweak: ContestsSystem(Mass Contest, Stamina Contest, Health Contest,
Mind Contest, Mood Contest, and Every Contest) have all been updated to
be safe to divide by, since it is no longer possible for them to ever
return 0. Instead they will just return
0.0000000000000000000000000000000000000000000001401298, so if you divide
by an unclamped contest, I hope you like your function randomly
returning the 32bit integer limit.
- add: Warning labels have been added to all Contests to make them
comply with the demands of the American consumer market.
  • Loading branch information
VMSolidus authored Sep 9, 2024
1 parent aec137a commit 058650e
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 38 deletions.
21 changes: 21 additions & 0 deletions Content.Shared/Contests/ContestsSystem.Utilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Content.Shared.CCVar;

namespace Content.Shared.Contests;
public sealed partial class ContestsSystem
{
/// <summary>
/// Clamp a contest to a Range of [Epsilon, 32bit integer limit]. This exists to make sure contests are always "Safe" to divide by.
/// </summary>
private float ContestClamp(float input)
{
return Math.Clamp(input, float.Epsilon, float.MaxValue);
}

/// <summary>
/// Shorthand for checking if clamp overrides are allowed, and the bypass is used by a contest.
/// </summary>
private bool ContestClampOverride(bool bypassClamp)
{
return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp;
}
}
Loading

0 comments on commit 058650e

Please sign in to comment.