Skip to content

Commit

Permalink
Fixed loading mechanoids from saves. Removed mechanoid equipment
Browse files Browse the repository at this point in the history
category and random mechanoid from the available equipment panel when
Biotech is not enabled.
  • Loading branch information
edbmods committed May 9, 2024
1 parent 1809f51 commit 80bc2cd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
20 changes: 11 additions & 9 deletions Source/EquipmentDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 10 additions & 7 deletions Source/ManagerEquipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions Source/PanelEquipmentAvailable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,13 @@ protected void ApplyCurrentFilters() {

protected void PrepareThingCategoryFilterOptions() {
List<FloatMenuOption> options = new List<FloatMenuOption>();
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;
Expand Down
21 changes: 20 additions & 1 deletion Source/PresetLoaderV5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThingDef>.GetNamedSilentFail(e.def) : null;
if (thingDef == null) {
result.AddWarning(string.Format("Could not load thing definition for equipment \"{0}\"", e.def));
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Source/Version3/SaveRecordEquipmentV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SaveRecordEquipmentV3 : IExposable {
public string stuffDef;
public string quality;
public string gender;
public float? overseenChance;

public SaveRecordEquipmentV3() {
}
Expand All @@ -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() {
Expand All @@ -32,6 +34,7 @@ public void ExposeData() {
Scribe_Values.Look<string>(ref this.quality, "quality", null, false);
Scribe_Values.Look<string>(ref this.spawnType, "spawnType", null, false);
Scribe_Values.Look<int>(ref this.count, "count", 0, false);
Scribe_Values.Look<float?>(ref this.overseenChance, "overseenChance", null, false);
}
}
}
Expand Down

0 comments on commit 80bc2cd

Please sign in to comment.