Skip to content

Commit

Permalink
Use Total Resources Gathered as Team Score
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
data-bomb committed May 3, 2024
1 parent fbc8c8f commit b5315aa
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions Si_Logging/Si_Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand All @@ -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!;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -791,7 +819,6 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0, Team __
}
}


// 061. Team Objectives/Actions - Research Tier
public static Dictionary<string, int> currTiers = new Dictionary<string, int>();
public static int getHighestTechTier(Team team)
Expand All @@ -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<string, int> tiers)
public static void initializeRound(ref Dictionary<string, int> 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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit b5315aa

Please sign in to comment.