From 80bc2cdfca1372c907ff598f1a64ad6df8a32606 Mon Sep 17 00:00:00 2001 From: edbmods Date: Wed, 8 May 2024 20:52:14 -0700 Subject: [PATCH] Fixed loading mechanoids from saves. Removed mechanoid equipment category and random mechanoid from the available equipment panel when Biotech is not enabled. --- Source/EquipmentDatabase.cs | 20 +++++++++++--------- Source/ManagerEquipment.cs | 17 ++++++++++------- Source/PanelEquipmentAvailable.cs | 12 +++++++----- Source/PresetLoaderV5.cs | 21 ++++++++++++++++++++- Source/Version3/SaveRecordEquipmentV3.cs | 3 +++ 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/Source/EquipmentDatabase.cs b/Source/EquipmentDatabase.cs index ca2f670..833978a 100644 --- a/Source/EquipmentDatabase.cs +++ b/Source/EquipmentDatabase.cs @@ -354,15 +354,17 @@ protected void AddRandomAnimalToEquipmentOptions() { EquipmentOptions.Add(RandomAnimalEquipmentOption); } protected void AddRandomMechToEquipmentOptions() { - RandomMechEquipmentOption = new EquipmentOption() { - ThingDef = null, - DefaultSpawnType = EquipmentSpawnType.Mech, - Materials = null, - SupportsQuality = false, - RandomMech = true, - EquipmentType = TypeMech - }; - EquipmentOptions.Add(RandomMechEquipmentOption); + if (ModsConfig.BiotechActive) { + RandomMechEquipmentOption = new EquipmentOption() { + ThingDef = null, + DefaultSpawnType = EquipmentSpawnType.Mech, + Materials = null, + SupportsQuality = false, + RandomMech = true, + EquipmentType = TypeMech + }; + EquipmentOptions.Add(RandomMechEquipmentOption); + } } protected bool AddStyleToEquipmentOptions(StyleCategoryDef def) { diff --git a/Source/ManagerEquipment.cs b/Source/ManagerEquipment.cs index aaf0f1f..8f9a360 100644 --- a/Source/ManagerEquipment.cs +++ b/Source/ManagerEquipment.cs @@ -140,13 +140,16 @@ public void InitializeStateFromScenarioAndStartingPawns() { } } else { - AddEquipment(new CustomizedEquipment() { - EquipmentOption = EquipmentDatabase.RandomMechEquipmentOption, - Count = 1, - SpawnType = EquipmentSpawnType.Mech, - OverseenChance = overseenChance - }); - State.ReplacedScenarioParts.Add(part); + var option = EquipmentDatabase.RandomMechEquipmentOption; + if (option != null) { + AddEquipment(new CustomizedEquipment() { + EquipmentOption = EquipmentDatabase.RandomMechEquipmentOption, + Count = 1, + SpawnType = EquipmentSpawnType.Mech, + OverseenChance = overseenChance + }); + State.ReplacedScenarioParts.Add(part); + } } } } diff --git a/Source/PanelEquipmentAvailable.cs b/Source/PanelEquipmentAvailable.cs index e068a59..719edbb 100644 --- a/Source/PanelEquipmentAvailable.cs +++ b/Source/PanelEquipmentAvailable.cs @@ -180,11 +180,13 @@ protected void ApplyCurrentFilters() { protected void PrepareThingCategoryFilterOptions() { List options = new List(); - options.Add(new FloatMenuOption("EdB.PC.Equipment.AvailableEquipment.MechCategoryLabel".Translate(), () => { - FilterThingCategory = null; - FilterMechs = true; - ApplyCurrentFilters(); - }, MenuOptionPriority.Default, null, null, 0, null, null)); + if (ModsConfig.BiotechActive) { + options.Add(new FloatMenuOption("EdB.PC.Equipment.AvailableEquipment.MechCategoryLabel".Translate(), () => { + FilterThingCategory = null; + FilterMechs = true; + ApplyCurrentFilters(); + }, MenuOptionPriority.Default, null, null, 0, null, null)); + } foreach (var thingCategory in ProviderEquipment.EquipmentDatabase.ThingCategories) { if (thingCategory.defName == "Root") { continue; diff --git a/Source/PresetLoaderV5.cs b/Source/PresetLoaderV5.cs index e9caf62..c1bceaa 100644 --- a/Source/PresetLoaderV5.cs +++ b/Source/PresetLoaderV5.cs @@ -58,6 +58,20 @@ protected void LoadEquipment(SaveRecordPresetV5 preset, PresetLoaderResult resul }); continue; } + else if (e.def == null && e.spawnType == "Mech") { + var option = EquipmentDatabase.RandomMechEquipmentOption; + if (option != null) { + customizedEquipment.Add(new CustomizedEquipment() { + EquipmentOption = EquipmentDatabase.RandomMechEquipmentOption, + Count = e.count, + OverseenChance = e.overseenChance ?? 1.0f + }); + } + else { + result.AddWarning("Could not load equipment option for random mech because Biotech is not enabled"); + } + continue; + } ThingDef thingDef = e?.def != null ? DefDatabase.GetNamedSilentFail(e.def) : null; if (thingDef == null) { result.AddWarning(string.Format("Could not load thing definition for equipment \"{0}\"", e.def)); @@ -87,12 +101,17 @@ protected void LoadEquipment(SaveRecordPresetV5 preset, PresetLoaderResult resul catch { spawnType = EquipmentDatabase.DefaultSpawnTypeForThingDef(thingDef); } + float? overseenChance = null; + if (spawnType == EquipmentSpawnType.Mech) { + overseenChance = e.overseenChance ?? 1.0f; + } customizedEquipment.Add(new CustomizedEquipment() { EquipmentOption = equipmentOption, StuffDef = stuffDef, Quality = quality, SpawnType = spawnType, - Count = e.count + Count = e.count, + OverseenChance = overseenChance, }); } customizations.Equipment = customizedEquipment; diff --git a/Source/Version3/SaveRecordEquipmentV3.cs b/Source/Version3/SaveRecordEquipmentV3.cs index e261ed9..3486ccd 100644 --- a/Source/Version3/SaveRecordEquipmentV3.cs +++ b/Source/Version3/SaveRecordEquipmentV3.cs @@ -12,6 +12,7 @@ public class SaveRecordEquipmentV3 : IExposable { public string stuffDef; public string quality; public string gender; + public float? overseenChance; public SaveRecordEquipmentV3() { } @@ -23,6 +24,7 @@ public SaveRecordEquipmentV3(CustomizedEquipment equipment) { gender = equipment.Gender.HasValue ? equipment.Gender.ToString() : null; quality = equipment.Quality.HasValue ? equipment.Quality.Value.ToString() : null; spawnType = equipment.SpawnType.HasValue ? equipment.SpawnType.Value.ToString() : null; + overseenChance = equipment.SpawnType == EquipmentSpawnType.Mech ? (equipment.OverseenChance ?? 1.0f) : (float?)null; } public void ExposeData() { @@ -32,6 +34,7 @@ public void ExposeData() { Scribe_Values.Look(ref this.quality, "quality", null, false); Scribe_Values.Look(ref this.spawnType, "spawnType", null, false); Scribe_Values.Look(ref this.count, "count", 0, false); + Scribe_Values.Look(ref this.overseenChance, "overseenChance", null, false); } } }