Skip to content

Commit

Permalink
HQLessHumansLose Fixes
Browse files Browse the repository at this point in the history
- Pass result by reference to allow changes
- Correctly detect 2-team situation in HvHvA
  • Loading branch information
data-bomb committed Feb 16, 2024
1 parent 18536c7 commit 3c503dc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 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.8", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(HQlessHumansLose), "HQless Humans Lose", "1.2.9", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand Down Expand Up @@ -76,7 +76,7 @@ static void HandleTimerSendLostMessage(object? source, ElapsedEventArgs e)
lostMessageTimerExpired = true;
}

public static bool OneFactionEliminated()
public static bool OneFactionAlreadyEliminated()
{
int TeamsWithMajorStructures = 0;
for (int i = 0; i < Team.Teams.Count; i++)
Expand All @@ -89,13 +89,13 @@ public static bool OneFactionEliminated()
}
}

if (TeamsWithMajorStructures < 3)
if (TeamsWithMajorStructures < 2)
{
MelonLogger.Msg("OneFactionEliminated: true");
MelonLogger.Msg("OneFactionAlreadyEliminated: true");
return true;
}

MelonLogger.Msg("OneFactionEliminated: false");
MelonLogger.Msg("OneFactionAlreadyEliminated: false");
return false;
}

Expand All @@ -107,7 +107,7 @@ public static void EliminateTeam(Team team)
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())
if (versusMode == MP_Strategy.ETeamsVersus.HUMANS_VS_HUMANS_VS_ALIENS && !OneFactionAlreadyEliminated())
{
// destroy structures
for (int i = 0; i < team.Structures.Count; i++)
Expand Down Expand Up @@ -146,6 +146,8 @@ private static void DestroyAllUnits(Team team)
// introduce a delay so clients can see chat message after round ends
private static void DelayTeamLostMessage(Team team)
{
MelonLogger.Msg("Starting delay lost timer for team " + team.TeamName);

lostMessageTimerExpired = false;
losingTeam = team;

Expand Down Expand Up @@ -238,6 +240,8 @@ private static void Postfix(ConstructionSite __instance, bool __0)
return;
}

MelonLogger.Msg("Structure construction destroyed: " + __instance.name);

Team constructionSiteTeam = __instance.Team;
String rootStructureMatchText = GetRootStructurePrefix(constructionSiteTeam);
if (!__instance.ToString().Contains(rootStructureMatchText))
Expand Down Expand Up @@ -295,7 +299,7 @@ private static void Postfix(Team __instance)
#endif
private static class ApplyPatch_GetHasLost
{
private static void Postfix(StrategyTeamSetup __instance, bool __result)
private static void Postfix(StrategyTeamSetup __instance, ref bool __result)
{
// only spend the CPU if the team is about to lose
if (__result == true && GameMode.CurrentGameMode.GameOngoing)
Expand All @@ -316,7 +320,7 @@ private static void Postfix(StrategyTeamSetup __instance, bool __result)
#endif
private static class ApplyPatch_GetHasAnyMajorStructures
{
private static void Postfix(Team __instance, bool __result)
private static void Postfix(Team __instance, ref bool __result)
{
// only spend the CPU if the team is about to lose
if (__result == false && GameMode.CurrentGameMode.GameOngoing)
Expand Down Expand Up @@ -383,6 +387,8 @@ private static void Postfix(MP_Strategy __instance, Structure __0, EDamageType _
return;
}

MelonLogger.Msg("Structure destroyed: " + __0.name);

Team structureTeam = __0.Team;
if (structureTeam == null)
{
Expand Down

0 comments on commit 3c503dc

Please sign in to comment.