diff --git a/.github/workflows/cicd-push.yml b/.github/workflows/cicd-push.yml index 1afc9c3..809c406 100644 --- a/.github/workflows/cicd-push.yml +++ b/.github/workflows/cicd-push.yml @@ -212,8 +212,8 @@ jobs: mv release/dedi/Mods/Si_FriendlyFireLimits.dll release/dedi/Mods/disabled mv release/listen/Mods/Si_FriendlyFireLimits.dll release/listen/Mods/disabled # HQ was re-dfined as the default loss condition with a game update - mv release/dedi/Mods/Si_HQlessHumansLose.dll release/dedi/Mods/disabled - mv release/listen/Mods/Si_HQlessHumansLose.dll release/listen/Mods/disabled + #mv release/dedi/Mods/Si_HQlessHumansLose.dll release/dedi/Mods/disabled + #mv release/listen/Mods/Si_HQlessHumansLose.dll release/listen/Mods/disabled # There are still too many game bugs for mapcycle to be on by default mv release/dedi/Mods/Si_Mapcycle.dll release/dedi/Mods/disabled mv release/listen/Mods/Si_Mapcycle.dll release/listen/Mods/disabled diff --git a/Si_HQlessHumansLose/Si_HQlessHumansLose.cs b/Si_HQlessHumansLose/Si_HQlessHumansLose.cs index 4d92e23..9805e2e 100644 --- a/Si_HQlessHumansLose/Si_HQlessHumansLose.cs +++ b/Si_HQlessHumansLose/Si_HQlessHumansLose.cs @@ -34,7 +34,7 @@ You should have received a copy of the GNU General Public License using System; using SilicaAdminMod; -[assembly: MelonInfo(typeof(HQlessHumansLose), "[Si] HQless Humans Lose", "1.2.5", "databomb", "https://github.com/data-bomb/Silica")] +[assembly: MelonInfo(typeof(HQlessHumansLose), "[Si] HQless Humans Lose", "1.2.6", "databomb", "https://github.com/data-bomb/Silica")] [assembly: MelonGame("Bohemia Interactive", "Silica")] [assembly: MelonOptionalDependencies("Admin Mod")] @@ -102,6 +102,8 @@ public static void EliminateTeam(Team team) MP_Strategy strategyInstance = GameObject.FindObjectOfType(); MP_Strategy.ETeamsVersus versusMode = strategyInstance.TeamsVersus; + MelonLogger.Msg("Eliminating team " + team.TeamName + " on versus mode " + versusMode.ToString()); + // are there still two remaining factions after this one is eliminated? if (versusMode == MP_Strategy.ETeamsVersus.HUMANS_VS_HUMANS_VS_ALIENS && !OneFactionEliminated()) { @@ -118,10 +120,7 @@ public static void EliminateTeam(Team team) } // destroy units (otherwise AI will roam around doing odd things) - for (int i = 0; i < team.Units.Count; i++) - { - team.Units[i].DamageManager.SetHealth01(0.0f); - } + DestroyAllUnits(team); } else { @@ -131,6 +130,14 @@ public static void EliminateTeam(Team team) DelayTeamLostMessage(team); } + private static void DestroyAllUnits(Team team) + { + for (int i = 0; i < team.Units.Count; i++) + { + team.Units[i].DamageManager.SetHealth01(0.0f); + } + } + // introduce a delay so clients can see chat message after round ends private static void DelayTeamLostMessage(Team team) { @@ -253,6 +260,50 @@ private static void Postfix(ConstructionSite __instance, bool __0) } } + // don't let the structure count reach 0 if HQ/Nest is under construction + #if NET6_0 + [HarmonyPatch(typeof(Team), nameof(Team.UpdateMajorStructuresCount))] + #else + [HarmonyPatch(typeof(Team), "UpdateMajorStructuresCount")] + #endif + private static class ApplyPatch_UpdateMajorStructuresCount + { + private static void Postfix(Team __instance) + { + // only spend the CPU if the team is about to lose + if (__instance.NumMajorStructures == 0 && GameMode.CurrentGameMode.GameOngoing) + { + if (HasRootStructureUnderConstruction(__instance)) + { + MelonLogger.Msg("Found Major Structure under Construction. Adjusting count."); + __instance.NumMajorStructures = 1; + } + } + } + } + + // don't count it as a loss if HQ/Nest is under construction + #if NET6_0 + [HarmonyPatch(typeof(StrategyTeamSetup), nameof(StrategyTeamSetup.GetHasLost))] + #else + [HarmonyPatch(typeof(StrategyTeamSetup), "GetHasLost")] + #endif + private static class ApplyPatch_GetHasLost + { + private static void Postfix(StrategyTeamSetup __instance, bool __result) + { + // only spend the CPU if the team is about to lose + if (__result == true && GameMode.CurrentGameMode.GameOngoing) + { + if (HasRootStructureUnderConstruction(__instance.Team)) + { + MelonLogger.Msg("Found Major Structure under Construction. Preventing loss."); + __result = false; + } + } + } + } + #if NET6_0 [HarmonyPatch(typeof(ConstructionSite), nameof(ConstructionSite.Update))] #else @@ -343,25 +394,7 @@ private static void Postfix(MP_Strategy __instance, Structure __0, EDamageType _ } // no HQ/nests left or being constructed - // end the round if it's humans - // Alien team index = 0 - if (structureTeam.Index != 0) - { - EliminateTeam(structureTeam); - } - // otherwise, send a chat right away - else - { - if (destroyerOfWorlds == null) - { - TeamLostMessage(structureTeam); - } - else - { - TeamLostByPlayerMessage(structureTeam, destroyerOfWorlds); - } - } - + EliminateTeam(structureTeam); } catch (Exception error) {