Skip to content

Commit

Permalink
Destroy Structures/Units for Eliminated Team
Browse files Browse the repository at this point in the history
- Brings back HQLessHumansLose mod to default mod package
- Counts under construction Nest/HQ as a major structure and prevents a loss under these conditions
- Forces all structures & units to perish when a faction is eliminated
  • Loading branch information
data-bomb committed Feb 15, 2024
1 parent 1102995 commit 13b3d2f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cicd-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 57 additions & 24 deletions Si_HQlessHumansLose/Si_HQlessHumansLose.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 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")]

Expand Down Expand Up @@ -102,6 +102,8 @@ public static void EliminateTeam(Team team)
MP_Strategy strategyInstance = GameObject.FindObjectOfType<MP_Strategy>();
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())
{
Expand All @@ -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
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 13b3d2f

Please sign in to comment.