diff --git a/Si_SurrenderCommand/Si_SurrenderCommand.cs b/Si_SurrenderCommand/Si_SurrenderCommand.cs index e1d66f0..a3630a7 100644 --- a/Si_SurrenderCommand/Si_SurrenderCommand.cs +++ b/Si_SurrenderCommand/Si_SurrenderCommand.cs @@ -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")] @@ -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(); @@ -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 sitesToDestroy = new List(); @@ -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); } @@ -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++) { @@ -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++) { @@ -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); } }