Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static void Start(string[] args)
if (args.Length < 2)
{
MyAPIGateway.Utilities.ShowMessage("SUGMA",
$"Unrecognized gamemode \"null\". Available gamemodes:{SUGMA_SessionComponent.ListGamemodes()}");
$"Unrecognized gamemode \"null\". Available gamemodes:");
SUGMA_SessionComponent.ListGamemodes();
return;
}

Expand All @@ -33,7 +34,8 @@ public static void Start(string[] args)
if (!SUGMA_SessionComponent.I.StartGamemode(args[1].ToLower(), startArgs, true))
{
MyAPIGateway.Utilities.ShowMessage("SUGMA",
$"Unrecognized gamemode \"{args[1].ToLower()}\". Available gamemodes:{SUGMA_SessionComponent.ListGamemodes()}");
$"Unrecognized gamemode \"{args[1].ToLower()}\". Available gamemodes:");
SUGMA_SessionComponent.ListGamemodes();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal class DominationHud_Window : WindowBase
private readonly TexturedBox[] _captureIndicators;

private readonly DominationGamemode _gamemode;
private readonly elmHud_Window _windowBase;
private readonly ElmHud_Window _windowBase;

public DominationHud_Window(HudParentBase parent, DominationGamemode gamemode) : base(parent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private void RemoveBlockers(float maxDistanceFromCenter)

public override void StartRound(string[] arguments = null)
{
_winningFaction = null;
PointTracker = new PointTracker(3, 0);
SUGMA_SessionComponent.I.UnregisterComponent("ELMPointTracker");
if (!MyAPIGateway.Utilities.IsDedicated)
Expand Down Expand Up @@ -222,7 +223,6 @@ public override void StopRound()
ShareTrackApi.UnregisterOnTrack(OnGridTrackChanged);

base.StopRound();
_winningFaction = null;
TrackedFactions.Clear();
PointTracker = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class EliminationHud : ComponentBase
private int _closeTime = -1;
private readonly EliminationGamemode _gamemode;

public elmHud_Window Window;
public ElmHud_Window Window;

public EliminationHud(EliminationGamemode gamemode)
{
Expand All @@ -28,7 +28,7 @@ public override void Init(string id)
if (!RichHudClient.Registered)
throw new Exception("RichHudAPI was not initialized in time!");

Window = new elmHud_Window(HudMain.HighDpiRoot, _gamemode);
Window = new ElmHud_Window(HudMain.HighDpiRoot, _gamemode);
}

public override void Close()
Expand All @@ -52,7 +52,7 @@ public void MatchEnded(IMyFaction winner)
}
}

internal class elmHud_Window : HudElementBase
internal class ElmHud_Window : HudElementBase
{
private readonly EliminationGamemode _gamemode;

Expand All @@ -63,7 +63,7 @@ internal class elmHud_Window : HudElementBase
internal LabelBox _winnerLabel;
public EliminationHud_TeamBanner[] Banners;

public elmHud_Window(HudParentBase parent, EliminationGamemode gamemode) : base(parent)
public ElmHud_Window(HudParentBase parent, EliminationGamemode gamemode) : base(parent)
{
_gamemode = gamemode;
_timer = gamemode._matchTimer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Sandbox.ModAPI;
using SC.SUGMA.GameModes.Elimination;
using SC.SUGMA.GameState;
Expand Down Expand Up @@ -49,6 +50,16 @@ public override void StartRound(string[] arguments = null)
if (TrackedFactions.Count <= 1)
return;

foreach (var faction in TrackedFactions.Keys.ToArray())
TrackedFactions[faction] = 0;

foreach (var grid in ShareTrackApi.GetTrackedGrids())
{
var faction = grid.GetFaction();
if (TrackedFactions.ContainsKey(faction))
TrackedFactions[faction]++;
}

ActivationTimeCounter = ActivationTime;
ControlPoint = null;

Expand All @@ -58,7 +69,8 @@ public override void StartRound(string[] arguments = null)

public override void StopRound()
{
_winningFaction = ControlPoint?._zoneOwner;
if (ControlPoint != null)
_winningFaction = ControlPoint._zoneOwner;
base.StopRound();

SUGMA_SessionComponent.I.GetComponent<KOTHHud>("KOTHHud")?.MatchEnded(_winningFaction);
Expand All @@ -81,6 +93,9 @@ internal override void DisplayWinMessage()

public override void UpdateActive()
{
foreach (var faction in TrackedFactions)
MyAPIGateway.Utilities.ShowNotification($"{faction.Key.Tag}: {faction.Value}", 1000/60);

if (ActivationTimeCounter > 0)
{
if (_matchTimer.Ticks % 60 == 0)
Expand All @@ -103,5 +118,49 @@ public override void UpdateActive()
StopRound();
}
}

internal override void OnGridTrackChanged(IMyCubeGrid grid, bool isTracked)
{
if (!isTracked)
OnAliveChanged(grid, false);
}

internal override void OnAliveChanged(IMyCubeGrid grid, bool isAlive)
{
var gridFaction = PlayerTracker.I.GetGridFaction(grid);
if (gridFaction == null || !TrackedFactions.ContainsKey(gridFaction))
return;
if (!isAlive)
{
TrackedFactions[gridFaction]--;
if (TrackedFactions[gridFaction] <= 0)
{
IMyFaction winningFaction = null;
foreach (var factionKvp in TrackedFactions)
{
if (factionKvp.Value <= 0)
continue;
if (winningFaction != null)
{
winningFaction = null;
break;
}
winningFaction = factionKvp.Key;
}

if (winningFaction != null)
{
if (ControlPoint != null)
ControlPoint._zoneOwner = winningFaction;
_winningFaction = winningFaction;
StopRound();
}
}
}
else
{
TrackedFactions[gridFaction]++;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal class KOTHHud_Window : WindowBase
new Material(MyStringId.GetOrCompute("SugmaCircle"), new Vector2(32, 32));

private readonly KOTHGamemode _gamemode;
private readonly elmHud_Window _windowBase;
private readonly ElmHud_Window _windowBase;

private TexturedBox _captureIndicator;

Expand Down Expand Up @@ -130,7 +130,6 @@ public void Update()

public void MatchEnded(IMyFaction winner)
{
Log.Info("KOTHHud.cs:133 MatchEnded (" + winner?.Name + ")");
_captureIndicator.Visible = false;
_captureLabel.Visible = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
using SC.SUGMA.HeartNetworking.Custom;
using SC.SUGMA.Utilities;
using VRage.Game.Components;
using VRage.Scripting;
using Sandbox.Game;
using VRageMath;

namespace SC.SUGMA
{
Expand Down Expand Up @@ -102,7 +105,7 @@ public bool StartGamemode(string id, string[] arguments, bool notifyNetwork = fa
CurrentGamemode = (GamemodeBase)_components[id];
CurrentGamemode.StartRound(arguments);

if (!CurrentGamemode.IsStarted)
if (!(CurrentGamemode?.IsStarted ?? false))
{
CurrentGamemode = null;
return false;
Expand Down Expand Up @@ -134,18 +137,15 @@ public bool StopGamemode(bool notifyNetwork = false)
return true;
}

public static string ListGamemodes()
public static void ListGamemodes()
{
var availableGamemodes = new StringBuilder();

foreach (var gamemode in I.GetGamemodes())
{
var gamemodeObject = I.GetComponent<GamemodeBase>(gamemode);
availableGamemodes.Append(
$"\n- {gamemode} ({gamemodeObject.ReadableName})\n * {gamemodeObject.ArgumentParser.HelpText.Replace("\n", "\n * ")}");
MyVisualScriptLogicProvider.SendChatMessageColored($"\n- {gamemodeObject.ArgumentParser.HelpText.Replace("\n", "\n- ")}", Color.Green, $"{gamemode} ({gamemodeObject.ReadableName})");
}

return availableGamemodes.ToString();
}

#region Base Methods
Expand Down