Skip to content

Commit

Permalink
Merge pull request #292 from edbmods/version-1.1.9
Browse files Browse the repository at this point in the history
Version 1.1.9
  • Loading branch information
edbmods authored Mar 19, 2020
2 parents 62fd74f + bf4fb46 commit 3cf33c7
Show file tree
Hide file tree
Showing 52 changed files with 541 additions and 459 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.1.8")]
[assembly: AssemblyFileVersion("1.1.9")]
2 changes: 1 addition & 1 deletion Resources/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

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.1.8]
[Version 1.1.9]
</description>
</ModMetaData>
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>EdBPrepareCarefully</identifier>
<version>1.1.8</version>
<version>1.1.9</version>
<loadAfter>
<li>Core</li>
<li>HugsLib</li>
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.1.9
_____________________________________________________________________________

- Better error handling in various panels.
- Fixed Backstory and Trait panel tooltip display so that tagged strings
are properly highlighted.
- Support for more injuries and health conditions.
- Added a tooltip description when choosing injuries and health conditions.
- Apparel/faction-related bug fix when loading presets.
- Performance improvements when initializing the equipment panel.

_____________________________________________________________________________

Version 1.1.8
Expand Down
2 changes: 1 addition & 1 deletion Source/AgeInjuryUtility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using RimWorld;
using RimWorld;
using RimWorld.Planet;
using System;
using System.Collections;
Expand Down
3 changes: 1 addition & 2 deletions Source/AnimalDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ protected AnimalRecord CreateAnimalRecord(ThingDef def, Gender gender) {
}
}
catch (Exception e) {
Log.Warning("Prepare Carefully failed to create a pawn for animal database record: " + def.defName);
Log.Message(" Exception message: " + e);
Logger.Warning("Failed to create a pawn for animal database record: " + def.defName, e);
return null;
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion Source/ColonistFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static string SavedColonistsFolderPath {
return Reflection.GenFilePaths.FolderUnderSaveData("PrepareCarefully");
}
catch (Exception e) {
Log.Error("Failed to get colonist save directory");
Logger.Error("Failed to get colonist save directory");
throw e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ColonistLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static CustomPawn LoadFromFile(PrepareCarefully loadout, string name) {
Scribe_Values.Look<string>(ref version, "version", "unknown", false);
}
catch (Exception e) {
Log.Error("Failed to load preset file");
Logger.Error("Failed to load preset file");
throw e;
}
finally {
Expand Down
2 changes: 1 addition & 1 deletion Source/ColonistSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void SaveToFile(CustomPawn customPawn, string colonistName) {
Scribe_Deep.Look<SaveRecordPawnV5>(ref pawn, "pawn");
}
catch (Exception e) {
Log.Error("Failed to save preset file");
Logger.Error("Failed to save preset file");
throw e;
}
finally {
Expand Down
10 changes: 5 additions & 5 deletions Source/Controller.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using RimWorld;
using RimWorld;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void StartGame() {

public void LoadPreset(string name) {
if (string.IsNullOrEmpty(name)) {
Log.Warning("Trying to load a preset without a name");
Logger.Warning("Trying to load a preset without a name");
return;
}
bool result = PresetLoader.LoadFromFile(PrepareCarefully.Instance, name);
Expand All @@ -96,7 +96,7 @@ public void LoadPreset(string name) {
public void SavePreset(string name) {
PrepareCarefully.Instance.Filename = name;
if (string.IsNullOrEmpty(name)) {
Log.Warning("Trying to save a preset without a name");
Logger.Warning("Trying to save a preset without a name");
return;
}
PresetSaver.SaveToFile(PrepareCarefully.Instance, PrepareCarefully.Instance.Filename);
Expand Down Expand Up @@ -183,7 +183,7 @@ protected void AddPawnToWorld(CustomPawn pawn) {
pawn.Pawn.SetFaction(pawn.Faction.Faction, null);
}
catch (Exception) {
Log.Warning("Prepare Carefully failed to add a world pawn to the expected faction");
Logger.Warning("Failed to add a world pawn to the expected faction");
}
}
// If they are assigned to a random faction of a specific def, choose the random faction and assign it.
Expand All @@ -193,7 +193,7 @@ protected void AddPawnToWorld(CustomPawn pawn) {
pawn.Pawn.SetFaction(pawn.Faction.Faction, null);
}
catch (Exception) {
Log.Warning("Prepare Carefully failed to add a world pawn to the expected faction");
Logger.Warning("Failed to add a world pawn to the expected faction");
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions Source/ControllerPawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void DeletePawn(CustomPawn pawn) {
}
public void LoadCharacter(string name) {
if (string.IsNullOrEmpty(name)) {
Log.Warning("Trying to load a character without a name");
Logger.Warning("Trying to load a character without a name");
return;
}
CustomPawn pawn = ColonistLoader.LoadFromFile(PrepareCarefully.Instance, name);
Expand All @@ -284,7 +284,7 @@ public void LoadCharacter(string name) {
}
public void SaveCharacter(CustomPawn pawn, string filename) {
if (string.IsNullOrEmpty(filename)) {
Log.Warning("Trying to save a character without a name");
Logger.Warning("Trying to save a character without a name");
return;
}
ColonistSaver.SaveToFile(pawn, filename);
Expand Down Expand Up @@ -317,9 +317,7 @@ public void AddFactionPawn(PawnKindDef kindDef, bool startingPawn) {
}
}
catch (Exception e) {
Log.Warning("Failed to create faction pawn of kind " + kindDef.defName);
Log.Message(e.Message);
Log.Message(e.StackTrace);
Logger.Warning("Failed to create faction pawn of kind " + kindDef.defName, e);
if (pawn != null) {
pawn.Destroy();
}
Expand Down
78 changes: 21 additions & 57 deletions Source/CostCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void ComputeTotal() {
public class CostCalculator {
protected HashSet<string> freeApparel = new HashSet<string>();
protected HashSet<string> cheapApparel = new HashSet<string>();
StatWorker statWorker = null;

public CostCalculator() {
cheapApparel.Add("Apparel_Pants");
Expand Down Expand Up @@ -194,7 +195,7 @@ public void CalculatePawnCost(ColonistCostDetails cost, CustomPawn pawn) {
// Check if there are any ancestor parts that override the selection.
UniqueBodyPart uniquePart = healthOptions.FindBodyPartsForRecord(option.BodyPartRecord);
if (uniquePart == null) {
Log.Warning("Prepare Carefully could not find body part record when computing the cost of an implant: " + option.BodyPartRecord.def.defName);
Logger.Warning("Could not find body part record when computing the cost of an implant: " + option.BodyPartRecord.def.defName);
continue;
}
if (pawn.AtLeastOneImplantedPart(uniquePart.Ancestors.Select((UniqueBodyPart p) => { return p.Record; }))) {
Expand Down Expand Up @@ -247,84 +248,47 @@ public double CalculateEquipmentCost(EquipmentSelection equipment) {
}
}

/*
public double CalculateAnimalCost(SelectedAnimal animal) {
AnimalRecord record = PrepareCarefully.Instance.AnimalDatabase.FindAnimal(animal.Key);
if (record != null) {
return (double)animal.Count * record.Cost;
}
else {
return 0;
public double GetAnimalCost(Thing thing) {
if (statWorker == null) {
StatDef marketValueStatDef = StatDefOf.MarketValue;
statWorker = marketValueStatDef.Worker;
}
float value = statWorker.GetValue(StatRequest.For(thing));
return value;
}
*/

public double GetBaseThingCost(ThingDef def, ThingDef stuffDef) {
if (def == null) {
Log.Warning("Prepare Carefully is trying to calculate the cost of a null ThingDef");
return 0;
double value = 0;
if (stuffDef != null) {
value = StatWorker_MarketValue.CalculatedBaseMarketValue(def, stuffDef);
}
if (def.BaseMarketValue > 0) {
if (stuffDef == null) {
return def.BaseMarketValue;
}
else {
// EVERY RELEASE:
// Should look at ThingMaker.MakeThing() to decide which validations we need to do
// before calling that method. That method doesn't do null checks everywhere, so we
// may need to do those validations ourselves to avoid null pointer exceptions.
// Should re-evaluate for each new release.
if (def.thingClass == null) {
Log.Warning("Prepare Carefully trying to calculate the cost of a ThingDef with null thingClass: " + def.defName);
return 0;
}
if (def.MadeFromStuff && stuffDef == null) {
Log.Warning("Prepare Carefully trying to calculate the cost of a \"made-from-stuff\" ThingDef without specifying any stuff: " + def.defName);
return 0;
}

try {
// TODO: Creating an instance of a thing may not be the best way to calculate
// its market value. It may be considered a relatively expensive operation,
// especially when a lot of mods are enabled. There may be a lower-level set of
// methods in the vanilla codebase that could be called. Should investigate.
Thing thing = ThingMaker.MakeThing(def, stuffDef);
if (thing == null) {
Log.Warning("Prepare Carefully failed when calling MakeThing(" + def.defName + ", ...) to calculate a ThingDef's market value");
return 0;
}
return thing.MarketValue;
}
catch (Exception e) {
Log.Warning("Prepare Carefully failed to calculate the cost of a ThingDef (" + def.defName + "): ");
Log.Warning(e.ToString());
return 0;
}
}
if (value == 0) {
value = def.BaseMarketValue;
}
else {
return 0;
if (value > 100) {
value = Math.Round(value / 5.0) * 5.0;
}
value = Math.Round(value, 2);
return value;
}

public double CalculateStackCost(ThingDef def, ThingDef stuffDef, double baseCost) {
double cost = baseCost;

if (def.MadeFromStuff) {
if (def.IsApparel) {
cost = cost * 1;
cost *= 1;
}
else {
cost = cost * 0.5;
cost *= 0.5;
}
}

if (def.IsRangedWeapon) {
cost = cost * 2;
cost *= 2;
}

//cost = cost * 1.25;
cost = Math.Round(cost, 1);
cost = Math.Round(cost, 2);

return cost;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/CustomHeadType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected static string GetHeadLabel(string path) {
return values[values.Count() - 2] + ", " + values[values.Count() - 1];
}
catch (Exception) {
Logger.Warning("Prepare Carefully could not determine head type label from graphics path: " + path);
Logger.Warning("Could not determine head type label from graphics path: " + path);
return "EdB.PC.Common.Default".Translate();
}
}
Expand Down
11 changes: 6 additions & 5 deletions Source/CustomPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ public void InitializeInjuriesAndImplantsFromPawn(Pawn pawn) {
injuries.Add(injury);
}
else {
//Logger.Debug("Looking for implant recipes for part {" + hediff.Part?.def + "}");
RecipeDef implantRecipe = healthOptions.ImplantRecipes.Where((RecipeDef def) => {
return (def.addsHediff != null && def.addsHediff == hediff.def && def.appliedOnFixedBodyParts.Contains(hediff.Part.def));
return (def.addsHediff != null && def.addsHediff == hediff.def && def.appliedOnFixedBodyParts.Contains(hediff.Part?.def));
}).RandomElementWithFallback(null);
if (implantRecipe != null) {
Implant implant = new Implant();
Expand All @@ -281,7 +282,7 @@ public void InitializeInjuriesAndImplantsFromPawn(Pawn pawn) {
implants.Add(implant);
}
else if (hediff.def.defName != "MissingBodyPart") {
Log.Warning("Prepare Carefully could not add a hediff to the pawn: " + hediff.def.defName + ", " + (hediff.Part != null ? hediff.Part.def.defName : "no part"));
Logger.Warning("Could not add hediff {" + hediff.def.defName + "} to the pawn because no recipe adds it to the body part {" + (hediff.Part?.def?.defName ?? "WholeBody") + "}");
}
}
}
Expand All @@ -301,7 +302,7 @@ public void InitializeInjuriesAndImplantsFromPawn(Pawn pawn) {
protected void InitializeSkillLevelsAndPassions() {

if (pawn.skills == null) {
Log.Warning("Prepare Carefully could not initialize skills for the pawn. No pawn skill tracker for " + pawn.def.defName + ", " + pawn.kindDef.defName);
Logger.Warning("Could not initialize skills for the pawn. No pawn skill tracker for " + pawn.def.defName + ", " + pawn.kindDef.defName);
}

// Save the original passions and set the current values to the same.
Expand Down Expand Up @@ -1298,7 +1299,7 @@ protected void ResetCachedHead() {
// gender, swapping to the correct head type if necessary.
CustomHeadType filteredHeadType = PrepareCarefully.Instance.Providers.HeadTypes.FindHeadTypeForGender(pawn.def, headType, Gender);
if (filteredHeadType == null) {
Log.Warning("No filtered head type found"); //TODO
Logger.Warning("No filtered head type found"); //TODO
}
SetHeadGraphicPathOnPawn(pawn, filteredHeadType.GraphicPath);
}
Expand Down Expand Up @@ -1467,7 +1468,7 @@ public void AddImplant(Implant implant) {
InitializeInjuriesAndImplantsFromPawn(this.pawn);
}
else {
Log.Warning("Discarding implant because of missing body part: " + implant.BodyPartRecord.def.defName);
Logger.Warning("Discarding implant because of missing body part: " + implant.BodyPartRecord.def.defName);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Source/DialogManageImplants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using RimWorld;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -215,9 +215,9 @@ protected void ResetDisabledState() {
validImplants.Add(implant);
}

//Log.Warning("Valid implants");
//Logger.Debug("Valid implants");
//foreach (var i in validImplants) {
// Log.Message(" " + i.recipe.LabelCap + ", " + i.PartName + (i.ReplacesPart ? ", replaces part" : ""));
// Logger.Debug(" " + i.recipe.LabelCap + ", " + i.PartName + (i.ReplacesPart ? ", replaces part" : ""));
//}

// Iterate each each body part option for each recipe to determine if that body part is missing,
Expand Down
Loading

0 comments on commit 3cf33c7

Please sign in to comment.