Skip to content

Commit

Permalink
now always using interruptmanager for assembly popups, fixed drive tr…
Browse files Browse the repository at this point in the history
…ains showing up as salvage, fixed min mechparts setting not being used
  • Loading branch information
mcb5637 committed Jun 27, 2020
1 parent 846ed1c commit 77d0f98
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions BTSimpleMechAssembly/SimpleMechAssembly_Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static bool Prefix(SimGameState __instance, string id)
MechDef d = __instance.DataManager.MechDefs.Get(id);
int p = SimpleMechAssembly_Main.GetNumPartsForAssembly(__instance, d);
if (p >= __instance.Constants.Story.DefaultMechPartMax)
SimpleMechAssembly_Main.QueryMechAssemblyPopup(__instance, d, null);
//SimpleMechAssembly_Main.QueryMechAssemblyPopup(__instance, d, null);
__instance.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_AssembleMechEntry(__instance, d, null), true);
}

return false; // completely replace
Expand Down Expand Up @@ -90,8 +91,8 @@ public static bool Prefix(MechBayChassisInfoWidget __instance, ChassisDef ___sel
.AddFader(new UIColorRef?(LazySingletonBehavior<UIManager>.Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
return false;
}
SimpleMechAssembly_Main.QueryMechAssemblyPopup(___mechBay.Sim, d, ___mechBay);
//___mechBay.Sim.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_AssembleMechEntry(___mechBay.Sim, d, ___mechBay), true);
//SimpleMechAssembly_Main.QueryMechAssemblyPopup(___mechBay.Sim, d, ___mechBay);
___mechBay.Sim.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_AssembleMechEntry(___mechBay.Sim, d, ___mechBay), true);
return false;
}
if (___selectedChassis.MechPartCount < ___selectedChassis.MechPartMax)
Expand Down
1 change: 1 addition & 0 deletions BTSimpleMechAssembly/SimpleMechAssembly_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class SimpleMechAssembly_Settings
public int StructurePointBasedSalvageMaxPartsFromMech = 3;
public int StructurePointBasedSalvageMinPartsFromMech = 1;
public bool StructurePointBasedSalvageVanillaComponents = false;
public string[] StructurePointBasedSalvageSalvageBlacklist = new string[] { };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static bool Prefix(Contract __instance, List<UnitResult> enemyMechs, List
log.Log($"generating salvage for vehicle {d.Chassis.Description.Name}");
foreach (VehicleComponentRef r in d.Inventory)
{
log.Log(string.Format("added salvage {0} from nondestroyed loc", r.Def.Description.Id));
log.Log(string.Format("added salvage {0}", r.Def.Description.Id));
AddUpgradeToSalvage(__instance, r.Def, s, ___finalPotentialSalvage);
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ private static void GenerateSalvageForMech(Contract __instance, UnitResult u, Si
}
float left = currstruct / maxstruct;
int maxparts = Math.Min(s.Constants.Story.DefaultMechPartMax, SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageMaxPartsFromMech);
int minparts = 1;
int minparts = SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageMinPartsFromMech;
float parts = left * maxparts;
log.Log(string.Format("calculated parts {0}, ct is {1} of total points", parts, u.mech.GetChassisLocationDef(ChassisLocations.CenterTorso).InternalStructure * SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageHighPriorityFactor / maxstruct));
float fract = parts - (float) Math.Floor(parts);
Expand Down Expand Up @@ -153,12 +153,22 @@ private static void GenerateSalvageForMech(Contract __instance, UnitResult u, Si

private static void AddMechPartSalvage(Contract __instance, MechDef d, SimGameState s, int num, List<SalvageDef> sal)
{
if (SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageSalvageBlacklist.Contains(d.Description.Id))
{
SimpleMechAssembly_Main.Log.LogError("skipping, cause its blacklisted by mod.json");
return;
}
object[] arg = new object[] { s.Constants, d, num, sal };
Traverse.Create(__instance).Method("CreateAndAddMechPart", arg).GetValue(arg);
}

private static void AddUpgradeToSalvage(Contract __instance, MechComponentDef d, SimGameState s, List<SalvageDef> sal)
{
if (SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageSalvageBlacklist.Contains(d.Description.Id))
{
SimpleMechAssembly_Main.Log.LogError("skipping, cause its blacklisted by mod.json");
return;
}
if (SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageVanillaComponents)
{
object[] args = new object[] { sal, d, ComponentDamageLevel.Functional, false, s.Constants, s.NetworkRandom, true };
Expand Down
3 changes: 2 additions & 1 deletion BTSimpleMechAssembly/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"StructurePointBasedSalvageMaxPartsFromMech": 3,
"StructurePointBasedSalvageMinPartsFromMech": 1,
/*activate to salvage + parts*/
"StructurePointBasedSalvageVanillaComponents": false
"StructurePointBasedSalvageVanillaComponents": false,
"StructurePointBasedSalvageSalvageBlacklist": [ "Gear_General_Robinson_TG120_Drive_Train", "Gear_Cockpit_Tacticon_B2000_Battle_Computer" ]
}
}

0 comments on commit 77d0f98

Please sign in to comment.