Skip to content

Commit

Permalink
Fix for Surrender Disrupting Game/AI
Browse files Browse the repository at this point in the history
- Previously the !surrender command would destroy all construction sites, structures, and units, which could cause significant disruption when a team had a lot of destroyed objects on a 50+ player server
- The new method only destroys critical objects (e.g., HQ, Queen, Nest, etc.)
  • Loading branch information
data-bomb committed Sep 8, 2024
1 parent 6c6a989 commit 2c89690
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions Si_SurrenderCommand/Si_SurrenderCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You should have received a copy of the GNU General Public License
using UnityEngine;
using System.Collections.Generic;

[assembly: MelonInfo(typeof(SurrenderCommand), "Surrender Command", "1.4.1", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(SurrenderCommand), "Surrender Command", "1.5.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand Down Expand Up @@ -191,13 +191,13 @@ public static void Surrender(Team team, Player player)
HelperMethods.ReplyToCommand_Player(player, "used !surrender to end");

// find all construction sites we should destroy form the team that's surrendering
RemoveConstructionSites(team);
RemoveConstructionSites(team, true);

// destroy all structures on team that's surrendering
RemoveStructures(team);
// destroy only critical structures on team that's surrendering
RemoveStructures(team, true);

// and destroy all units (especially the queen)
RemoveUnits(team);
// and destroy only critical units (e.g., the queen)
RemoveUnits(team, true);

// clear all people who voted for a surrender
ClearSurrenderVotes();
Expand All @@ -219,7 +219,7 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0)
}
}

public static void RemoveConstructionSites(Team team)
public static void RemoveConstructionSites(Team team, bool criticalOnly)
{
List<ConstructionSite> sitesToDestroy = new List<ConstructionSite>();

Expand All @@ -235,6 +235,13 @@ public static void RemoveConstructionSites(Team team)
continue;
}

if (criticalOnly && constructionSite.ObjectInfo && !constructionSite.ObjectInfo.Critical)
{
continue;
}

MelonLogger.Msg("Found critical construction site: " + constructionSite.ToString());

sitesToDestroy.Add(constructionSite);
}

Expand All @@ -244,7 +251,7 @@ public static void RemoveConstructionSites(Team team)
}
}

public static void RemoveStructures(Team team)
public static void RemoveStructures(Team team, bool criticalOnly)
{
for (int i = 0; i < team.Structures.Count; i++)
{
Expand All @@ -254,11 +261,22 @@ public static void RemoveStructures(Team team)
continue;
}

if (team.Structures[i].IsDestroyed)
{
continue;
}

if (criticalOnly && team.Structures[i].ObjectInfo && !team.Structures[i].ObjectInfo.Critical)
{
continue;
}

MelonLogger.Msg("Found critical structure: " + team.Structures[i].ToString());
team.Structures[i].DamageManager.SetHealth01(0.0f);
}
}

public static void RemoveUnits(Team team)
public static void RemoveUnits(Team team, bool criticalOnly)
{
for (int i = 0; i < team.Units.Count; i++)
{
Expand All @@ -273,6 +291,13 @@ public static void RemoveUnits(Team team)
continue;
}

if (criticalOnly && team.Units[i].ObjectInfo && !team.Units[i].ObjectInfo.Critical)
{
continue;
}

MelonLogger.Msg("Found critical unit: " + team.Units[i].ToString());

team.Units[i].DamageManager.SetHealth01(0.0f);
}
}
Expand Down

0 comments on commit 2c89690

Please sign in to comment.