Skip to content

Commit

Permalink
Merge pull request #352 from edbmods/fixes-and-changes-1.5.11
Browse files Browse the repository at this point in the history
Fixes and changes 1.5.11
  • Loading branch information
edbmods authored May 11, 2024
2 parents b5bbbc8 + e9df773 commit 8c53174
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
[assembly: AssemblyVersion("1.1.1")]

// Increment for each new release
[assembly: AssemblyFileVersion("1.5.10")]
[assembly: AssemblyFileVersion("1.5.11")]
2 changes: 1 addition & 1 deletion Resources/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

If you get a set of starting colonists that you like, save them as a preset so that you can start your game the same way next time.

[Version 1.5.10]
[Version 1.5.11]
</description>
<loadAfter>
<li>net.pardeike.rimworld.mod.harmony</li>
Expand Down
2 changes: 1 addition & 1 deletion Resources/About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>EdB.PrepareCarefully</identifier>
<version>1.5.10</version>
<version>1.5.11</version>
<showCrossPromotions>false</showCrossPromotions>
<manifestUri>https://github.com/edbmods/EdBPrepareCarefully/raw/master/Resources/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/edbmods/EdBPrepareCarefully/releases/latest</downloadUri>
Expand Down
13 changes: 13 additions & 0 deletions Resources/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
_____________________________________________________________________________

Version 1.5.11
_____________________________________________________________________________

- Added some missing implants (tentacles, etc.)
- Bug fixes:
- Pawns can no longer add implants that are mutant-specific or restricted
if their mutant type does not match
- Fixed some errors when trying to open the Bionics and Implants dialog
when using some mods
- Removed the implant level slider when the implant only has one level

_____________________________________________________________________________

Version 1.5.10
Expand Down
79 changes: 44 additions & 35 deletions Source/DialogManageImplants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ protected void ResetDisabledState() {
if (part == null) {
continue;
}
// If there's already an implant on that body part record, skip it. Otherwise add it
// to the list of first pass valid implants
if (firstPassReplacedParts.ContainsKey(part.Record)) {
continue;
}
firstPassValidImplants.Add(implant);
// Also keep track of whether we've replaced a body part with an implant
if (implant.ReplacesPart) {
firstPassReplacedParts.Add(implant.BodyPartRecord, implant);
}
Expand All @@ -224,6 +227,7 @@ protected void ResetDisabledState() {
// that don't replace parts but whose target part has been removed.
Dictionary<BodyPartRecord, Implant> secondPassReplacedParts = new Dictionary<BodyPartRecord, Implant>();
List<Implant> secondPassValidImplants = new List<Implant>();
// Iterate all of the implants that we marked as valid in the first pass
foreach (var implant in firstPassValidImplants) {
UniqueBodyPart part = health.FindBodyPartsForRecord(implant.BodyPartRecord);
if (part == null) {
Expand Down Expand Up @@ -260,19 +264,19 @@ protected void ResetDisabledState() {
validImplants.Add(implant);
}

//Logger.Debug("Valid implants");
//foreach (var i in validImplants) {
// Logger.Debug(" " + i.recipe.LabelCap + ", " + i.PartName + (i.ReplacesPart ? ", replaces part" : ""));
//}
Logger.Debug("Valid implants:");
foreach (var i in validImplants) {
Logger.Debug(" " + i.Label + ", " + i.BodyPartRecord?.def?.defName + (i.ReplacesPart ? ", replaces part" : ""));
}

// Iterate each body part option for each recipe to determine if that body part is missing,
// Iterate each body part option for each option to determine if that body part is missing,
// based on the whether or not it or one of its ancestors has been replaced. Only evaluate each
// body part once. The result will be used to determine if recipes and part options should be
// body part once. The result will be used to determine if options and part options should be
// disabled.
HashSet<BodyPartRecord> evaluatedParts = new HashSet<BodyPartRecord>();
Dictionary<BodyPartRecord, Implant> blockedParts = new Dictionary<BodyPartRecord, Implant>();
foreach (var recipe in options) {
foreach (var part in recipe.Parts) {
foreach (var option in options) {
foreach (var part in option.Parts) {
if (evaluatedParts.Contains(part.Part)) {
continue;
}
Expand All @@ -290,7 +294,7 @@ protected void ResetDisabledState() {
}
}

// Go through each recipe and recipe part, marking the parts as disabled if
// Go through each option and option part, marking the parts as disabled if
// they are missing and marking the recipes as disabled if all of its parts
// are disabled.
foreach (var option in options) {
Expand Down Expand Up @@ -318,19 +322,19 @@ protected void ResetDisabledState() {
}
}

// Evaluate each recipe's selected state.
foreach (var recipe in options) {
recipe.PartiallySelected = false;
if (recipe.Selected) {
// Evaluate each option's selected state.
foreach (var option in options) {
option.PartiallySelected = false;
if (option.Selected) {
int selectedCount = 0;
foreach (var part in recipe.Parts) {
foreach (var part in option.Parts) {
if (part.Selected && !part.Disabled) {
selectedCount++;
break;
}
}
if (selectedCount == 0) {
recipe.PartiallySelected = true;
option.PartiallySelected = true;
}
}
}
Expand All @@ -340,8 +344,8 @@ protected void ResetDisabledState() {

protected void ResetCachedBlockedSelectionAlert() {
bool showAlert = false;
foreach (var recipe in options) {
foreach (var part in recipe.Parts) {
foreach (var option in options) {
foreach (var part in option.Parts) {
if (part.Disabled && part.Implant != null) {
showAlert = true;
break;
Expand All @@ -356,17 +360,19 @@ protected void ResetCachedBlockedSelectionAlert() {
return;
}
List<Implant> blockedSelections = new List<Implant>();
foreach (var recipe in options) {
int partCount = recipe.Parts.Count;
foreach (var part in recipe.Parts) {
if (part.Disabled && part.Implant != null) {
blockedSelections.Add(part.Implant);
foreach (var option in options) {
int partCount = option.Parts?.Count ?? 0;
if (option.Parts != null) {
foreach (var part in option.Parts) {
if (part.Disabled && part.Implant != null) {
blockedSelections.Add(part.Implant);
}
}
}
}
string listItems = "";
foreach (var item in blockedSelections) {
listItems += "\n" + "EdB.PC.Dialog.Implant.Alert.Item".Translate(item.Recipe.LabelCap, item.BodyPartRecord.def.label);
listItems += "\n" + "EdB.PC.Dialog.Implant.Alert.Item".Translate(item.Label, item.BodyPartRecord?.def?.label);
}
cachedBlockedSelectionAlert = "EdB.PC.Dialog.Implant.Alert".Translate(listItems);
}
Expand Down Expand Up @@ -439,6 +445,9 @@ public void SelectOption(DialogOption option) {
return;
}
option.Selected = true;
if (option.ImplantOption?.MaxSeverity == 1) {
UpdateSeverity(option, 1);
}
if (option.Parts.Count == 1) {
if (!option.Parts[0].Selected) {
option.Parts[0].Selected = true;
Expand Down Expand Up @@ -474,21 +483,21 @@ public void AddMissingDependencies() {
}

public bool NeedsDependencies(ref HashSet<DialogOption> missingDependencies) {
Logger.Debug("NeedsDependencies()");
//Logger.Debug("NeedsDependencies()");
if (missingDependencies == null) {
missingDependencies = new HashSet<DialogOption>();
}
HashSet<HediffDef> selected = new HashSet<HediffDef>(implantList.Select(i => i.Option.HediffDef));
Logger.Debug(" Selected implants: " + string.Join(", ", selected.Select(d => d.defName)));
HashSet<HediffDef> selected = new HashSet<HediffDef>(implantList.Select(i => i.Option?.HediffDef).Where(h => h != null));
//Logger.Debug(" Selected implants: " + string.Join(", ", selected.Select(d => d.defName)));
foreach (var implant in implantList) {
if (implant.Option.Dependency != null && !selected.Contains(implant.Option.Dependency)) {
if (implant.Option?.Dependency != null && !selected.Contains(implant.Option.Dependency)) {
var optionToAdd = FindDialogOptionForHediff(implant.Option.Dependency);
if (optionToAdd != null) {
missingDependencies.Add(optionToAdd);
}
}
}
Logger.Debug(" Needs dependencies: " + string.Join(", ", missingDependencies.Select(o => o.ImplantOption.HediffDef.defName)));
//Logger.Debug(" Needs dependencies: " + string.Join(", ", missingDependencies.Select(o => o.ImplantOption?.HediffDef?.defName)));
return missingDependencies.Count > 0;
}

Expand Down Expand Up @@ -517,7 +526,7 @@ public bool HasUnneededDependencies(ref HashSet<DialogOption> unneededDependenci
unneededDependencies.Add(option);
}
}
Logger.Debug("Unneeded dependencies: " + string.Join(", ", unneededDependencies.Select(o => o.ImplantOption?.HediffDef?.defName ?? "null")));
//Logger.Debug("Unneeded dependencies: " + string.Join(", ", unneededDependencies.Select(o => o.ImplantOption?.HediffDef?.defName ?? "null")));

return unneededDependencies.Count > 0;
}
Expand All @@ -531,7 +540,7 @@ public void DeselectOption(DialogOption option) {
option.Selected = false;
option.SelectedDependency = false;
if (option.Parts != null) {
Logger.Debug(" option.Parts = " + string.Join(", ", option.Parts.Select(p => p.UniquePart.Record.def.defName)));
//Logger.Debug(" option.Parts = " + string.Join(", ", option.Parts.Select(p => p.UniquePart.Record.def.defName)));
}
foreach (var part in option.Parts) {
if (part.Selected) {
Expand All @@ -550,10 +559,10 @@ public void UpdateSeverity(DialogOption option, float severity) {
Implant implant = implantList.FirstOrDefault(i => i.Option == option.ImplantOption);
if (implant != null) {
implant.Severity = option.Severity;
Logger.Debug("Updated implant severity");
//Logger.Debug("Updated implant severity");
}
else {
Logger.Debug("Didn't find implant to update");
//Logger.Debug("Didn't find implant to update");
}
}
protected void AddImplant(DialogOption option, ImplantBodyPart part) {
Expand Down Expand Up @@ -716,7 +725,7 @@ protected void Resize() {
if (option.Selected || option.SelectedDependency) {
float inset = 32;
float cursor = labelRect.yMax;
if (option.ImplantOption.MaxSeverity > 0) {
if (option.ImplantOption.MaxSeverity > 1) {
float rowWidth = rect.width - inset * 2;
float sliderWidth = rowWidth - LevelLabelSize.x - LevelValueSize.x - 12;
float sliderHeight = 12;
Expand Down Expand Up @@ -769,7 +778,7 @@ protected void Resize() {
ClickPartAction(option, part);
}
if (part.BlockingImplant != null) {
TooltipHandler.TipRegion(labelRect, "EdB.PC.Dialog.Implant.Conflict".Translate(part.BlockingImplant.Recipe.LabelCap, part.BlockingImplant.BodyPartRecord.Label));
TooltipHandler.TipRegion(labelRect, "EdB.PC.Dialog.Implant.Conflict".Translate(part.BlockingImplant.Label, part.BlockingImplant.BodyPartRecord.Label));
}
}
cursor += labelRect.height;
Expand All @@ -783,7 +792,7 @@ protected void Resize() {
if (option.Selected && option.Parts.Count > 1) {
height += LineHeight * option.Parts.Count;
}
if (option.Selected && option.ImplantOption.MaxSeverity > 0) {
if (option.Selected && option.ImplantOption.MaxSeverity > 1) {
height += LineHeight;
}
return height;
Expand Down
1 change: 1 addition & 0 deletions Source/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static void Postfix() {
// After we've initialized the new game, swap in the original scenario parts so that the game save
// doesn't include any Prepare Carefully-specific scene parts.
Mod.Instance.RestoreScenarioParts();
Mod.ClearInstance();
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions Source/Implant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
namespace EdB.PrepareCarefully {
public class Implant : CustomizedHediff {

public string label = "";

public Implant() {
}

Expand All @@ -26,7 +24,12 @@ public Implant(BodyPartRecord bodyPartRecord, RecipeDef recipe) {

public string Label {
get {
return Recipe?.addsHediff?.LabelCap ?? "";
if (Recipe != null) {
return Recipe?.addsHediff?.LabelCap ?? "";
}
else {
return "EdB.PC.Dialog.Implant.InstallImplantLabel".Translate(Option?.HediffDef?.label);
}
}
}

Expand All @@ -37,6 +40,9 @@ public bool ReplacesPart {
|| typeof(Hediff_MissingPart).IsAssignableFrom(Recipe.addsHediff.hediffClass))) {
return true;
}
else if (Option?.HediffDef?.organicAddedBodypart ?? false) {
return true;
}
return false;
}
}
Expand Down
12 changes: 7 additions & 5 deletions Source/MapperPawnToCustomizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@ public void MapInjuriesAndImplants(Pawn pawn, CustomizationsPawn customizations)
else {
//Logger.Debug("Did not find injury option for {" + hediff.def.defName + "} for part {" + hediff.Part?.LabelCap + "}");
ImplantOption implantOption = healthOptions.FindImplantOptionsThatAddHediff(hediff).RandomElementWithFallback(null);
if (implantOption != null) {
HediffDef hediffDef = hediff?.def;
BodyPartRecord bodyPartRecord = hediff.Part;
if (hediffDef != null) {
var implant = new Implant() {
Option = implantOption,
Recipe = implantOption.RecipeDef,
BodyPartRecord = hediff.Part,
Recipe = implantOption?.RecipeDef,
BodyPartRecord = bodyPartRecord,
Hediff = hediff,
HediffDef = hediff?.def,
HediffDef = hediffDef,
};
if (hediff is Hediff_Level level) {
//Logger.Debug("Mapping implant " + implantOption.HediffDef.defName + " with severity " + level.level);
Expand All @@ -279,7 +281,7 @@ public void MapInjuriesAndImplants(Pawn pawn, CustomizationsPawn customizations)
implants.Add(implant);
}
else {
Logger.Warning("Could not add hediff {" + hediff.def.defName + "} to the pawn because found no matching implant option for the body part {" + (hediff.Part?.def?.defName ?? "WholeBody") + "}");
Logger.Debug("Could not find implant option for hediff {" + hediff.def?.defName + "} and body part {" + (hediff.Part?.def?.defName ?? "WholeBody") + "}");
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion Source/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace EdB.PrepareCarefully {
public class Mod {
public static readonly Version MinimumGameVersion = new Version(1, 3, 3102);
public static readonly Version MinimumGameVersion = new Version(1, 5, 0);
private static Mod instance = new Mod();
public static Mod Instance {
get {
Expand All @@ -19,6 +19,9 @@ public static Mod Instance {
}
}

public static void ClearInstance() {
instance = null;
}
public ModState State { get; set; }

public void Clear() {
Expand Down
13 changes: 3 additions & 10 deletions Source/OptionsHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ public UniqueBodyPart FindBodyPartsForRecord(BodyPartRecord record) {
return null;
}
}
public List<UniqueBodyPart> FindBodyPartsForDef(BodyPartDef def) {
public IEnumerable<UniqueBodyPart> FindBodyPartsForDef(BodyPartDef def) {
if (bodyPartDefLookup.TryGetValue(def, out List<UniqueBodyPart> result)) {
return result;
}
else {
return null;
return Enumerable.Empty<UniqueBodyPart>();
}
}
public IEnumerable<RecipeDef> FindImplantRecipesThatAddHediff(Hediff hediff) {
Expand Down Expand Up @@ -261,13 +261,6 @@ public void AddImplantRecipe(RecipeDef recipe, List<UniqueBodyPart> parts) {
public void AddImplantOption(ImplantOption option) {
ImplantOptions.Add(option);
}
public void AddImplantHediffDef(HediffDef hediffDef, BodyPartRecord bodyPartRecord = null) {
ImplantOptions.Add(new ImplantOption() {
RecipeDef = null,
HediffDef = hediffDef,
BodyPartRecord = bodyPartRecord,
});
}

public IEnumerable<UniqueBodyPart> FindBodyPartsForImplantRecipe(RecipeDef recipeDef) {
if (recipeDef == null) {
Expand Down Expand Up @@ -329,7 +322,7 @@ public IEnumerable<BodyPartRecord> BodyPartsForInjury(InjuryOption option) {
else {
List<BodyPartRecord> records = new List<BodyPartRecord>();
foreach (var part in option.ValidParts) {
records.AddRange(FindBodyPartsForDef(part).ConvertAll(p => p.Record));
records.AddRange(FindBodyPartsForDef(part).Select(p => p.Record));
}
return records;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/PawnCustomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public void ApplyInjuryAndImplantCustomizationsToPawn(Pawn pawn, CustomizationsP
ApplyImplantToPawn(pawn, implant);
}
catch (Exception e) {
Logger.Warning("Failed to add implant {" + implant.label + "} to part {" + implant.BodyPartRecord?.def?.defName + "}", e);
Logger.Warning("Failed to add implant {" + implant.Label + "} to part {" + implant.BodyPartRecord?.def?.defName + "}", e);
implantsToRemove.Add(implant);
}
}
Expand Down
Loading

0 comments on commit 8c53174

Please sign in to comment.