Skip to content

Commit

Permalink
Merge pull request #365 from CWolfs/develop
Browse files Browse the repository at this point in the history
v1.0.5
  • Loading branch information
CWolfs authored Jun 2, 2020
2 parents bff2491 + 35d49a1 commit 547f63b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Mission Control",
"Enabled": true,
"Version": "1.0.4",
"Version": "1.0.5",
"Description": "A HBS BattleTech mod that adds custom contract types and varies the encounter specifics such as encounter boundary size, spawn locations, lance numbers and objectives",
"Author": "CWolf",
"Contact": "cwolfs@gmail.com",
Expand Down
4 changes: 2 additions & 2 deletions src/Core/EncounterLogic/LanceLogic/LanceLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public MLanceOverride SelectAppropriateLanceOverride(string teamType) {
FactionDef faction = MissionControl.Instance.GetFactionFromTeamType(teamType);
string factionName = (faction == null) ? "UNKNOWN" : faction.Name;
int factionRep = (MissionControl.Instance.IsSkirmish()) ? 0 : UnityGameInstance.Instance.Game.Simulation.GetRawReputation(faction.FactionValue);
int mrbRating = UnityGameInstance.Instance.Game.Simulation.GetRawReputation(FactionEnumeration.GetMercenaryReviewBoardFactionValue());
int mrbLevel = UnityGameInstance.Instance.Game.Simulation.GetCurrentMRBLevel();
int mrbRating = (MissionControl.Instance.IsSkirmish()) ? 0 : UnityGameInstance.Instance.Game.Simulation.GetRawReputation(FactionEnumeration.GetMercenaryReviewBoardFactionValue());
int mrbLevel = (MissionControl.Instance.IsSkirmish()) ? 0 : UnityGameInstance.Instance.Game.Simulation.GetCurrentMRBLevel();
bool useElites = MissionControl.Instance.ShouldUseElites(faction, teamType);
Config.Lance activeAdditionalLance = Main.Settings.ActiveAdditionalLances.GetActiveAdditionalLanceByTeamType(teamType);
List<string> lancePoolKeys = Main.Settings.ActiveAdditionalLances.GetLancePoolKeys(teamType, biome, contractType, factionName, factionRep, mrbLevel, mrbRating);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System.Linq;
using System.Collections.Generic;
using System.Reflection;

namespace MissionControl.Patches {
[HarmonyPatch(typeof(SimGameState), "FilterActiveMaps")]
Expand Down Expand Up @@ -44,8 +45,12 @@ private static void FixActiveMapWeights(WeightedList<MapAndEncounters> activeMap
}

private static void FilterOnMapsWithEncountersWithValidContractRequirements(SimGameState simGameState, WeightedList<MapAndEncounters> activeMaps, List<Contract> currentContracts) {
List<int> indexesToRemove = new List<int>();
List<MapAndEncounters> mapsToRemove = new List<MapAndEncounters>();

StarSystem system = MissionControl.Instance.System;
var validParticipants = AccessTools.Method(typeof(SimGameState), "GetValidParticipants").Invoke(simGameState, new object[] { system });
MethodInfo GetValidFactionMethod = AccessTools.Method(typeof(SimGameState), "GetValidFaction");
MethodInfo DoesContractMeetRequirementsMethod = AccessTools.Method(typeof(SimGameState), "DoesContractMeetRequirements");

for (int i = 0; i < activeMaps.Count; i++) {
MapAndEncounters level = activeMaps[i];
Expand All @@ -58,11 +63,23 @@ private static void FilterOnMapsWithEncountersWithValidContractRequirements(SimG
if (MissionControl.Instance.PotentialContracts.ContainsKey(contractTypeId)) {
// If the contract overrides in the potential contracts by ContractTypeID has a `DoesContractMeetRequirements` sucess, mark remove = false
List<ContractOverride> contractOverrides = MissionControl.Instance.PotentialContracts[contractTypeId];
foreach (ContractOverride contractOverride in contractOverrides) {
bool doesContractMeetReqs = (bool)AccessTools.Method(typeof(SimGameState), "DoesContractMeetRequirements").Invoke(simGameState, new object[] { system, level, contractOverride });
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] '{contractTypeId}' - contractOverrides count is: {contractOverrides.Count}");
for (int j = contractOverrides.Count; j > 0; j--) {
ContractOverride contractOverride = contractOverrides[j - 1];
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] '{contractTypeId}' - contractOverride is: {contractOverride.ID}");
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] '{contractTypeId}' - validParticipants is: {validParticipants}");
bool doesContractHaveValidFactions = (bool)GetValidFactionMethod.Invoke(simGameState, new object[] { system, validParticipants, contractOverride.requirementList, null });
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] '{contractTypeId}' - Contract '{contractOverride.ID}' has valid fations?: {doesContractHaveValidFactions}");
if (!doesContractHaveValidFactions) {
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] '{contractTypeId}' - Removing Contract '{contractOverride.ID}' from potential list");
contractOverrides.RemoveAt(j - 1);
continue;
}

bool doesContractMeetReqs = (bool)DoesContractMeetRequirementsMethod.Invoke(simGameState, new object[] { system, level, contractOverride });
if (doesContractMeetReqs) {
// At least one contract override meets the requirements to prevent the infinite spinner so ignore this logic now and continue to the next map/encounter combo
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] Level '{level.Map.MapName}.{encounterLayerMDD.Name}' has at least one valid contract override");
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] '{contractTypeId}' - Level '{level.Map.MapName}.{encounterLayerMDD.Name}' has at least one valid contract override");
removeMap = false;
break;
}
Expand All @@ -71,19 +88,31 @@ private static void FilterOnMapsWithEncountersWithValidContractRequirements(SimG
}

if (removeMap) {
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] Level '{level.Map.MapName}' had no encounters with anyvalid contract overrides. Removing map.");
indexesToRemove.Add(i);
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] Level '{level.Map.MapName}' had no encounters with any valid contract overrides. Removing map.");
mapsToRemove.Add(level);
}
}

// Remove maps that have no valid contracts due to failing requirements
foreach (int indexToRemove in indexesToRemove) {
activeMaps.RemoveAt(indexToRemove);
foreach (MapAndEncounters level in mapsToRemove) {
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] Attempting to remove Level '{level.Map.MapName}'");
activeMaps.Remove(level);
}

// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] There are '{activeMaps.Count}' active maps/encounter combos to use. These are:");
/*
for (int k = 0; k < activeMaps.Count; k++) {
MapAndEncounters level = activeMaps[k];
Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] - '{level.Map.MapName}' with '{level.Encounters.Length}' encounters");
foreach (EncounterLayer_MDD encounterLayerMDD in level.Encounters) {
Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] - Encounter '{encounterLayerMDD.Name}'");
}
}
*/

// If there are no more active maps, reset the biomes/maps list
if (activeMaps.Count <= 0) {
// Main.LogDebug($"[FilterOnMapsWithEncountersWithValidContractRequirements] No valid map/encounter combinations. Clearing map discard pile.");
Main.Logger.LogWarning($"[FilterOnMapsWithEncountersWithValidContractRequirements] No valid map/encounter combinations. Clearing map discard pile. WARNING: MapEncounters unfiltered by MC being used. Potential for infinite loading issue. If you see this from an infinite load freeze - inform CWolf from Mission Control");
List<string> mapDiscardPile = (List<string>)AccessTools.Field(typeof(SimGameState), "mapDiscardPile").GetValue(simGameState);
mapDiscardPile.Clear();

Expand Down

0 comments on commit 547f63b

Please sign in to comment.