Skip to content

Commit

Permalink
Merge pull request #91 from B3none/force-even-teams-config
Browse files Browse the repository at this point in the history
Force even teams config
  • Loading branch information
B3none authored Mar 24, 2024
2 parents 03515df + 0584f70 commit 8b10c5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion RetakesPlugin/Modules/Configs/RetakesConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class RetakesConfigData
{
public static int CurrentVersion = 6;
public static int CurrentVersion = 7;

public int Version { get; set; } = CurrentVersion;
public int MaxPlayers { get; set; } = 9;
Expand All @@ -17,4 +17,5 @@ public class RetakesConfigData
public bool IsAutoPlantEnabled { get; set; } = true;
public string QueuePriorityFlag { get; set; } = "@css/vip";
public bool IsDebugMode { get; set; } = false;
public bool ShouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 { get; set; } = true;
}
16 changes: 11 additions & 5 deletions RetakesPlugin/Modules/Managers/QueueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,29 @@ public class QueueManager
private readonly int _maxRetakesPlayers;
private readonly float _terroristRatio;
private readonly string _queuePriorityFlag;
private readonly bool _shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10;

public HashSet<CCSPlayerController> QueuePlayers = new();
public HashSet<CCSPlayerController> ActivePlayers = new();

public QueueManager(Translator translator, int? retakesMaxPlayers, float? retakesTerroristRatio,
string? queuePriorityFlag)
{
public QueueManager(
Translator translator,
int? retakesMaxPlayers,
float? retakesTerroristRatio,
string? queuePriorityFlag,
bool? shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10
) {
_translator = translator;
_maxRetakesPlayers = retakesMaxPlayers ?? 9;
_terroristRatio = retakesTerroristRatio ?? 0.45f;
_queuePriorityFlag = queuePriorityFlag ?? "@css/vip";
_shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 = shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 ?? true;
}

public int GetTargetNumTerrorists()
{
// TODO: Add a config option for this logic
var ratio = (ActivePlayers.Count > 9 ? 0.5 : _terroristRatio) * ActivePlayers.Count;
var shouldForceEvenTeams = _shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 && ActivePlayers.Count % 10 == 0;
var ratio = (shouldForceEvenTeams ? 0.5 : _terroristRatio) * ActivePlayers.Count;
var numTerrorists = (int)Math.Round(ratio);

// Ensure at least one terrorist if the calculated number is zero
Expand Down
5 changes: 3 additions & 2 deletions RetakesPlugin/RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace RetakesPlugin;
[MinimumApiVersion(180)]
public class RetakesPlugin : BasePlugin
{
private const string Version = "1.4.1";
private const string Version = "1.4.2";

#region Plugin info
public override string ModuleName => "Retakes Plugin";
Expand Down Expand Up @@ -480,7 +480,8 @@ private void OnMapStart(string mapName)
_translator,
_retakesConfig?.RetakesConfigData?.MaxPlayers,
_retakesConfig?.RetakesConfigData?.TerroristRatio,
_retakesConfig?.RetakesConfigData?.QueuePriorityFlag
_retakesConfig?.RetakesConfigData?.QueuePriorityFlag,
_retakesConfig?.RetakesConfigData?.ShouldForceEvenTeamsWhenPlayerCountIsMultipleOf10
),
_retakesConfig?.RetakesConfigData?.RoundsToScramble,
_retakesConfig?.RetakesConfigData?.IsScrambleEnabled
Expand Down

0 comments on commit 8b10c5d

Please sign in to comment.