From b5315aa789a87ae5ee8eb35e362abe41b22336f7 Mon Sep 17 00:00:00 2001 From: data-bomb Date: Fri, 3 May 2024 16:16:14 -0700 Subject: [PATCH] Use Total Resources Gathered as Team Score - Switches the round_end team score from the current resources the team has to the total number of resources gathered over the course of the entire round (addresses #13) --- Si_Logging/Si_Logging.cs | 47 ++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/Si_Logging/Si_Logging.cs b/Si_Logging/Si_Logging.cs index f9b58d7..87c8c6c 100644 --- a/Si_Logging/Si_Logging.cs +++ b/Si_Logging/Si_Logging.cs @@ -42,7 +42,7 @@ You should have received a copy of the GNU General Public License using System.Diagnostics; using System.IO; -[assembly: MelonInfo(typeof(HL_Logging), "Half-Life Logger", "1.2.4", "databomb&zawedcvg", "https://github.com/data-bomb/Silica")] +[assembly: MelonInfo(typeof(HL_Logging), "Half-Life Logger", "1.2.5", "databomb&zawedcvg", "https://github.com/data-bomb/Silica")] [assembly: MelonGame("Bohemia Interactive", "Silica")] [assembly: MelonOptionalDependencies("Admin Mod")] @@ -52,6 +52,7 @@ namespace Si_Logging public class HL_Logging : MelonMod { const int MaxTeams = 3; + static int[] teamResourcesCollected = new int[Team.NumTeams]; static Player?[]? lastCommander; static MelonPreferences_Category _modCategory = null!; @@ -688,6 +689,34 @@ public static void Postfix(MP_Strategy __instance, Structure __0, EDamageType __ // TODO: 060. Player Objectives/Actions // Ideas: Enter/exit vehicle. Take control of bug. + // Round-End Scoring based on Resources Collected + + [HarmonyPatch(typeof(Team), nameof(Team.StoreResource))] + private static class ApplyPatchStoreResource + { + public static void Postfix(Team __instance, int __result, int __0) + { + try + { + if (__instance == null) + { + return; + } + + if (__0 <= 0) + { + return; + } + + teamResourcesCollected[__instance.Index] += __0; + } + catch (Exception error) + { + HelperMethods.PrintError(error, "Failed to run StoreResource"); + } + } + } + // 061. Team Objectives/Actions - Victory // 062. World Objectives/Actions - Round_Win // 065. Round-End Team Score Report @@ -735,9 +764,8 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0, Team __ { continue; } - - // TODO: Investigate what else to use for team score. Add up all player scores? For now resources is used but it's not using Total acculumated resources so need to find something else. - string TeamLogLine = "Team \"" + thisTeam.TeamShortName + "\" scored \"" + thisTeam.TotalResources.ToString() + "\" with \"" + thisTeam.GetNumPlayers().ToString() + "\" players"; + + string TeamLogLine = "Team \"" + thisTeam.TeamShortName + "\" scored \"" + teamResourcesCollected[thisTeam.Index].ToString() + "\" with \"" + thisTeam.GetNumPlayers().ToString() + "\" players"; PrintLogLine(TeamLogLine); } @@ -791,7 +819,6 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0, Team __ } } - // 061. Team Objectives/Actions - Research Tier public static Dictionary currTiers = new Dictionary(); public static int getHighestTechTier(Team team) @@ -801,20 +828,19 @@ public static int getHighestTechTier(Team team) int count = team.GetTechnologyTierStructureCount(i); if (count > 0) { return i; } } - return 0; + return 0; } - public static void initializeTiers(ref Dictionary tiers) + public static void initializeRound(ref Dictionary tiers) { for (int i = 0; i < Team.NumTeams; i++) { tiers[Team.Teams[i].name] = 0; + teamResourcesCollected[i] = 0; } - } - #if NET6_0 [HarmonyPatch(typeof(BarksHandler), nameof(BarksHandler.OnConstructionCompleted))] #else @@ -848,7 +874,6 @@ public static void LogTierChange(Team team, int tier) { string LogLine = "Team \"" + team.TeamShortName + "\" triggered \"technology_change\" (tier \"" + tier.ToString() + "\")"; PrintLogLine(LogLine); - } // 062. World Objectives/Actions - Round_Start @@ -864,7 +889,7 @@ public static void Prefix(MusicJukeboxHandler __instance, GameMode __0) string RoundStartLogLine = "World triggered \"Round_Start\" (gametype \"" + versusMode.ToString() + "\")"; PrintLogLine(RoundStartLogLine); - initializeTiers(ref currTiers); + initializeRound(ref currTiers); firedRoundEndOnce = false; }