Skip to content

Commit

Permalink
Merge pull request #347 from edbmods/bug-fixes-1.5.8
Browse files Browse the repository at this point in the history
Bug fixes 1.5.8
  • Loading branch information
edbmods authored May 9, 2024
2 parents ae2e68e + 59b5672 commit 1809f51
Show file tree
Hide file tree
Showing 41 changed files with 1,053 additions and 644 deletions.
1 change: 1 addition & 0 deletions EdBPrepareCarefully.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="Source\AgeModifier.cs" />
<Compile Include="Source\AlienRace.cs" />
<Compile Include="Source\AlienRaceBodyAddon.cs" />
<Compile Include="Source\ImplantOption.cs" />
<Compile Include="Source\PawnLoaderV3.cs" />
<Compile Include="Source\PawnSaver.cs" />
<Compile Include="Source\CostCalculator.cs" />
Expand Down
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.7")]
[assembly: AssemblyFileVersion("1.5.8")]
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.7]
[Version 1.5.8]
</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.7</version>
<version>1.5.8</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
14 changes: 14 additions & 0 deletions Resources/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
_____________________________________________________________________________

Version 1.5.8
_____________________________________________________________________________

- Added support for Mechanitor implants in the Health panel's Implants and
Bionics dialog
- Added Mechanoid options to the Equipment Tab
- Bug fixes:
- Fixed issue where sibling relationships were sometimes lost when loading
from a preset
- Fixed issue where non-parent/child relationships between starting pawns
and hidden/world pawns were removed when initializing the game

_____________________________________________________________________________

Version 1.5.7
Expand Down
20 changes: 20 additions & 0 deletions Resources/Common/Languages/English/Keyed/EdBPrepareCarefully.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- CHANGE NOTES -->

<!-- v1.5.8 -->
<!-- ADDED: EdB.PC.Dialog.Implant.InstallImplantLabel -->
<!-- ADDED: EdB.PC.Dialog.Implant.LevelLabel -->
<!-- ADDED: EdB.PC.Dialog.Implant.RequiredImplantMessage -->
<!-- ADDED: EdB.PC.Equipment.AvailableEquipment.MechCategoryLabel -->
<!-- ADDED: EdB.PC.Equipment.AvailableEquipment.RandomMechLabel -->
<!-- ADDED: EdB.PC.Equipment.AvailableEquipment.OverseenChanceLabel -->
<!-- ADDED: EdB.PC.Equipment.SelectedEquipment.OverseenChanceLabel -->
<!-- ADDED: EdB.PC.Equipment.SelectedEquipment.SpawnType.Mech -->
<!-- ADDED: EdB.PC.Equipment.Type.Mechs -->

<!-- v1.5.3 -->
<!-- ADDED: EdB.PC.Panel.Apparel.ApparelLocked -->
<!-- ADDED: EdB.PC.Equipment.AvailableEquipment.DefaultStyleOption -->
Expand Down Expand Up @@ -208,6 +219,9 @@
<EdB.PC.Dialog.Implant.Button.Confirm>Apply</EdB.PC.Dialog.Implant.Button.Confirm>
<EdB.PC.Dialog.Implant.Conflict>This implant cannot be installed because it conflicts with the following:\n\n- {0}, {1}</EdB.PC.Dialog.Implant.Conflict>
<EdB.PC.Dialog.Implant.Header>Select Implants and Bionics</EdB.PC.Dialog.Implant.Header>
<EdB.PC.Dialog.Implant.InstallImplantLabel>Implant {0}</EdB.PC.Dialog.Implant.InstallImplantLabel>
<EdB.PC.Dialog.Implant.RequiredImplantMessage>This implant must be added because it is required by one of the other implants that you selected</EdB.PC.Dialog.Implant.RequiredImplantMessage>
<EdB.PC.Dialog.Implant.LevelLabel>{0}:</EdB.PC.Dialog.Implant.LevelLabel>

<EdB.PC.Dialog.Injury.Header>Select a condition</EdB.PC.Dialog.Injury.Header>
<EdB.PC.Dialog.Injury.Error.Required>You must select a condition</EdB.PC.Dialog.Injury.Error.Required>
Expand Down Expand Up @@ -262,17 +276,20 @@
<EdB.PC.Equipment.Type.Apparel>Apparel</EdB.PC.Equipment.Type.Apparel>
<EdB.PC.Equipment.Type.Buildings>Furniture</EdB.PC.Equipment.Type.Buildings>
<EdB.PC.Equipment.Type.Food>Food</EdB.PC.Equipment.Type.Food>
<EdB.PC.Equipment.Type.Mechs>Mechanoids</EdB.PC.Equipment.Type.Mechs>
<EdB.PC.Equipment.Type.Medical>Medical</EdB.PC.Equipment.Type.Medical>
<EdB.PC.Equipment.Type.Resources>Resources</EdB.PC.Equipment.Type.Resources>
<EdB.PC.Equipment.Type.Weapons>Weapons</EdB.PC.Equipment.Type.Weapons>
<EdB.PC.Equipment.LoadingProgress.Initializing>Initializing...</EdB.PC.Equipment.LoadingProgress.Initializing>
<EdB.PC.Equipment.LoadingProgress.StuffDefs>Processing materials...</EdB.PC.Equipment.LoadingProgress.StuffDefs>
<EdB.PC.Equipment.LoadingProgress.ThingDefs>Processing items...</EdB.PC.Equipment.LoadingProgress.ThingDefs>
<EdB.PC.Equipment.LoadingProgress.Finished>Finished</EdB.PC.Equipment.LoadingProgress.Finished>
<EdB.PC.Equipment.SelectedEquipment.OverseenChanceLabel>{0}: {1}%</EdB.PC.Equipment.SelectedEquipment.OverseenChanceLabel>
<EdB.PC.Equipment.SelectedEquipment.SpawnType.SpawnsWith>Start With</EdB.PC.Equipment.SelectedEquipment.SpawnType.SpawnsWith>
<EdB.PC.Equipment.SelectedEquipment.SpawnType.SpawnsNear>Start Near</EdB.PC.Equipment.SelectedEquipment.SpawnType.SpawnsNear>
<EdB.PC.Equipment.SelectedEquipment.SpawnType.Possession>Possessions - {0}</EdB.PC.Equipment.SelectedEquipment.SpawnType.Possession>
<EdB.PC.Equipment.SelectedEquipment.SpawnType.Animal>Animals</EdB.PC.Equipment.SelectedEquipment.SpawnType.Animal>
<EdB.PC.Equipment.SelectedEquipment.SpawnType.Mech>Mechanoids</EdB.PC.Equipment.SelectedEquipment.SpawnType.Mech>
<EdB.PC.Equipment.AvailableEquipment.AllCategoriesOption>All Categories</EdB.PC.Equipment.AvailableEquipment.AllCategoriesOption>
<EdB.PC.Equipment.AvailableEquipment.AllModsOption>All Mods</EdB.PC.Equipment.AvailableEquipment.AllModsOption>
<EdB.PC.Equipment.AvailableEquipment.CostLabelAndValue>Cost: {0}</EdB.PC.Equipment.AvailableEquipment.CostLabelAndValue>
Expand All @@ -281,8 +298,11 @@
<EdB.PC.Equipment.AvailableEquipment.GenderLabel>Gender:</EdB.PC.Equipment.AvailableEquipment.GenderLabel>
<EdB.PC.Equipment.AvailableEquipment.HitPointsLabel>Hit Points:</EdB.PC.Equipment.AvailableEquipment.HitPointsLabel>
<EdB.PC.Equipment.AvailableEquipment.MaterialLabel>Material:</EdB.PC.Equipment.AvailableEquipment.MaterialLabel>
<EdB.PC.Equipment.AvailableEquipment.MechCategoryLabel>Mechanoids</EdB.PC.Equipment.AvailableEquipment.MechCategoryLabel>
<EdB.PC.Equipment.AvailableEquipment.QualityLabel>Quality:</EdB.PC.Equipment.AvailableEquipment.QualityLabel>
<EdB.PC.Equipment.AvailableEquipment.OverseenChanceLabel>{0}:</EdB.PC.Equipment.AvailableEquipment.OverseenChanceLabel>
<EdB.PC.Equipment.AvailableEquipment.RandomAnimalLabel>Random Pet</EdB.PC.Equipment.AvailableEquipment.RandomAnimalLabel>
<EdB.PC.Equipment.AvailableEquipment.RandomMechLabel>Random Mechanoid</EdB.PC.Equipment.AvailableEquipment.RandomMechLabel>
<EdB.PC.Equipment.AvailableEquipment.SpawnTypeLabel>Spawn Type:</EdB.PC.Equipment.AvailableEquipment.SpawnTypeLabel>
<EdB.PC.Equipment.AvailableEquipment.StyleLabel>Style:</EdB.PC.Equipment.AvailableEquipment.StyleLabel>

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 60 additions & 16 deletions Source/ControllerPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ public void PreparePawns() {
Find.GameInitData.startingPossessions.Remove(key);
}
// Destroy any starting pawn that are not in our customized pawn list
Logger.Debug("Destroy any pawn that is not in our carefully prepared pawn list:");
foreach (var pawn in Find.GameInitData.startingAndOptionalPawns) {
if (!State.Customizations.AllPawns.Select(p => p.Pawn).Contains(pawn)) {
Logger.Debug("Destroyed starting pawn: " + pawn.LabelCap);
Logger.Debug(" Destroyed starting pawn: " + pawn.LabelShort);
ManagerPawns.DestroyPawn(pawn);
}
else {
Logger.Debug("Kept starting pawn: " + pawn.LabelCap);
Logger.Debug(" Kept starting pawn: " + pawn.LabelShort);
}
}
Find.GameInitData.startingPawnCount = State.Customizations.ColonyPawns.Count;
Expand Down Expand Up @@ -189,10 +190,7 @@ public void PrepareEquipment() {

// Add scenario parts for all of our customized equipment selections
foreach (var equipment in State.Customizations.Equipment) {
ScenPart part = CreateScenarioPartForCustomizedEquipment(equipment);
if (part != null) {
scenarioPartsToUse.Add(part);
}
scenarioPartsToUse.AddRange(CreateScenarioPartForCustomizedEquipment(equipment).Where(p => p != null));
}

ReflectionUtil.SetFieldValue(Find.Scenario, "parts", scenarioPartsToUse);
Expand All @@ -207,23 +205,26 @@ public bool ShouldReplaceScenarioPart(ScenPart part) {
return false;
}

public ScenPart CreateScenarioPartForCustomizedEquipment(CustomizedEquipment equipment) {
Logger.Debug(string.Format("AddScenarioPartForCustomizedEquipment({0}), Animal = {1}", equipment.EquipmentOption?.ThingDef?.defName, equipment.Animal));
public IEnumerable<ScenPart> CreateScenarioPartForCustomizedEquipment(CustomizedEquipment equipment) {
Logger.Debug(string.Format("AddScenarioPartForCustomizedEquipment({0}), Animal = {1}, Mech = {2}", equipment.EquipmentOption?.ThingDef?.defName, equipment.Animal, equipment.Mech));
if (equipment.Animal) {
return CreateStartingAnimalScenarioPart(equipment);
return new List<ScenPart>() { CreateStartingAnimalScenarioPart(equipment) };
}
else if (equipment.Mech) {
return CreateStartingMechScenarioParts(equipment);
}
var spawnType = equipment.SpawnType;
if (equipment.EquipmentOption.RestrictedSpawnType && equipment.EquipmentOption.DefaultSpawnType != spawnType) {
spawnType = equipment.EquipmentOption.DefaultSpawnType;
}
if (spawnType == EquipmentSpawnType.SpawnsWith) {
return CreateStartsWithScenarioPart(equipment);
return new List<ScenPart>() { CreateStartsWithScenarioPart(equipment) };
}
else if (spawnType == EquipmentSpawnType.SpawnsNear) {
return CreateScatterThingsNearScenarioPart(equipment);
return new List<ScenPart>() { CreateScatterThingsNearScenarioPart(equipment) };
}
else {
return null;
return Enumerable.Empty<ScenPart>();
}
}

Expand Down Expand Up @@ -260,6 +261,49 @@ public ScenPart CreateStartingAnimalScenarioPart(CustomizedEquipment equipment)
return CreateStartingAnimalWithRandomGenderScenarioPart(equipment);
}
}
public IEnumerable<ScenPart> CreateStartingMechScenarioParts(CustomizedEquipment equipment) {
if (equipment.EquipmentOption.RandomMech) {
return CreateRandomStartingMechScenarioParts(equipment);
}
else {
return CreateDefinedStartingMechScenarioParts(equipment);
}
}
public IEnumerable<ScenPart> CreateDefinedStartingMechScenarioParts(CustomizedEquipment equipment) {
ScenPartDef scenPartDef = DefDatabase<ScenPartDef>.GetNamedSilentFail("StartingMech");
if (scenPartDef == null) {
Logger.Warning("Could not find definition for starting mech scenario part. Cannot add scenario part");
yield break;
}
PawnKindDef pawnKindDef = FindPawnKindDefForRace(equipment);
if (pawnKindDef == null) {
Logger.Warning(string.Format("Could not spawn selected mech ({0}). Could not find matching pawn kind", equipment.EquipmentOption?.ThingDef?.defName));
yield break;
}
for (int i = 0; i < equipment.Count; i++) {
var part = new ScenPart_StartingMech() {
def = scenPartDef
};
part.SetPrivateField("mechKind", pawnKindDef);
part.SetPrivateField("overseenByPlayerPawnChance", equipment.OverseenChance);
yield return part;
}
}
public IEnumerable<ScenPart> CreateRandomStartingMechScenarioParts(CustomizedEquipment equipment) {
ScenPartDef scenPartDef = DefDatabase<ScenPartDef>.GetNamedSilentFail("StartingMech");
if (scenPartDef == null) {
Logger.Warning("Could not find definition for starting mech scenario part. Cannot add scenario part");
yield break;
}
for (int i = 0; i < equipment.Count; i++) {
var part = new ScenPart_StartingMech() {
def = scenPartDef
};
part.SetPrivateField("overseenByPlayerPawnChance", equipment.OverseenChance);
yield return part;
}
}

public ScenPart CreateRandomStartingAnimalScenarioPart(CustomizedEquipment equipment) {
ScenPartDef scenPartDef = DefDatabase<ScenPartDef>.GetNamedSilentFail("StartingAnimal");
if (scenPartDef == null) {
Expand All @@ -278,7 +322,7 @@ public ScenPart CreateStartingAnimalWithRandomGenderScenarioPart(CustomizedEquip
Logger.Warning("Could not find definition for starting animal scenario part. Cannot add scenario part");
return null;
}
PawnKindDef pawnKindDef = FindPawnKindDefForAnimal(equipment);
PawnKindDef pawnKindDef = FindPawnKindDefForRace(equipment);
if (pawnKindDef == null) {
Logger.Warning(string.Format("Could not spawn selected animal ({0}). Could not find matching pawn kind", equipment.EquipmentOption?.ThingDef?.defName));
return null;
Expand All @@ -291,7 +335,7 @@ public ScenPart CreateStartingAnimalWithRandomGenderScenarioPart(CustomizedEquip
return part;
}
public ScenPart CreateStartingAnimalWithSpecificGenderScenarioPart(CustomizedEquipment equipment) {
PawnKindDef pawnKindDef = FindPawnKindDefForAnimal(equipment);
PawnKindDef pawnKindDef = FindPawnKindDefForRace(equipment);
if (pawnKindDef == null) {
Logger.Warning(string.Format("Could not spawn selected animal ({0}). Could not find matching pawn kind", equipment.EquipmentOption?.ThingDef?.defName));
return null;
Expand All @@ -303,8 +347,8 @@ public ScenPart CreateStartingAnimalWithSpecificGenderScenarioPart(CustomizedEqu
};
return part;
}
public PawnKindDef FindPawnKindDefForAnimal(CustomizedEquipment equipment) {
return (from td in DefDatabase<PawnKindDef>.AllDefs where td.race == equipment.EquipmentOption.ThingDef select td).FirstOrDefault();
public PawnKindDef FindPawnKindDefForRace(CustomizedEquipment equipment) {
return DefDatabase<PawnKindDef>.AllDefs.Where(k => k.race == equipment.EquipmentOption.ThingDef).FirstOrDefault();
}

public void MarkCostsForRecalculation() {
Expand Down
5 changes: 1 addition & 4 deletions Source/ControllerTabViewPawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,8 @@ public void AddInjury(Injury injury) {
public void AddImplant(Implant implant) {
PawnManager.AddPawnImplant(ViewState?.CurrentPawn, implant);
}
public void RemoveHediff(Hediff hediff) {
PawnManager.RemovePawnHediff(ViewState?.CurrentPawn, hediff);
}
public void RemoveHediffs(IEnumerable<Hediff> hediffs) {
PawnManager.RemovePawnHediffs(ViewState?.CurrentPawn, hediffs);
PawnManager.RemoveHediffs(ViewState?.CurrentPawn, hediffs);
}

public void RandomizeAppearance() {
Expand Down
19 changes: 19 additions & 0 deletions Source/CostCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class CostCalculator {
protected HashSet<string> cheapApparel = new HashSet<string>();
public StatWorker MarketValueStatWorker { get; set; }
public float CostForRandomAnimal { get; set; } = 250f;
public float CostForRandomMech { get; set; } = 1200f;


public CostCalculator() {
Expand Down Expand Up @@ -174,6 +175,21 @@ public PawnCostDetailsRefactored CalculatePawnCost(CustomizedPawn pawn) {
//Logger.Debug(string.Format("Market value for pawn apparel; pawn = {0}, apparel = {1}, cost = {2}", pawn.Pawn.LabelShortCap, apparel.def.defName, c));
}

// Implants that have a ThingDef associated with them (like a Mechlink) need to include the
// cost of that ThingDef
foreach (Implant implant in pawn.Customizations.Implants) {
if (implant.HediffDef == null) {
continue;
}
if (implant.Option?.ThingDef != null) {
int count = 1;
if (implant.Option.MaxSeverity > 0) {
count = (int)implant.Severity;
}
cost.bionics += MarketValueStatWorker.GetValue(StatRequest.For(implant.Option.ThingDef, null)) * count;
}
}

// Calculate cost for any materials needed for implants.
OptionsHealth healthOptions = ProviderHealthOptions.GetOptions(pawn);
foreach (Implant option in pawn.Customizations.Implants) {
Expand Down Expand Up @@ -228,6 +244,9 @@ public double CalculateEquipmentCost(CustomizedEquipment equipment) {
else if (equipment.EquipmentOption.RandomAnimal) {
return CostForRandomAnimal * equipment.Count;
}
else if (equipment.EquipmentOption.RandomMech) {
return CostForRandomMech * equipment.Count;
}
else {
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions Source/CustomizationsPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ public class CustomizationsPawn {
public List<Injury> Injuries { get; set; } = new List<Injury>();
public List<Implant> Implants { get; set; } = new List<Implant>();

public List<CustomizedHediff> BodyParts = new List<CustomizedHediff>();

// Titles
public List<CustomizationTitle> Titles { get; set; } = new List<CustomizationTitle>();

Expand Down
12 changes: 10 additions & 2 deletions Source/CustomizedEquipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ public class CustomizedEquipment {
public EquipmentSpawnType? SpawnType { get; set; }
public int Count { get; set; }
public Gender? Gender { get; set; }
public float? OverseenChance { get; set; }

public bool Animal {
get {
return EquipmentOption.RandomAnimal || (EquipmentOption.ThingDef?.race?.Animal ?? false);
}
}

public bool Mech {
get {
return EquipmentOption.RandomMech || (EquipmentOption.ThingDef?.race?.IsMechanoid ?? false);
}
}
public CustomizedEquipment CreateCopy() {
return new CustomizedEquipment() {
EquipmentOption = this.EquipmentOption,
Expand All @@ -27,6 +32,7 @@ public CustomizedEquipment CreateCopy() {
Count = this.Count,
SpawnType = this.SpawnType,
Gender = this.Gender,
OverseenChance = this.OverseenChance,
};
}

Expand All @@ -36,7 +42,8 @@ public override bool Equals(object obj) {
EqualityComparer<ThingDef>.Default.Equals(StuffDef, equipment.StuffDef) &&
Quality == equipment.Quality &&
SpawnType == equipment.SpawnType &&
Gender == equipment.Gender;
Gender == equipment.Gender &&
OverseenChance == equipment.OverseenChance;
}

public override int GetHashCode() {
Expand All @@ -46,6 +53,7 @@ public override int GetHashCode() {
hashCode = hashCode * -1521134295 + Quality.GetHashCode();
hashCode = hashCode * -1521134295 + SpawnType.GetHashCode();
hashCode = hashCode * -1521134295 + Gender.GetHashCode();
hashCode = hashCode * -1521134295 + OverseenChance.GetHashCode();
return hashCode;
}
}
Expand Down
Loading

0 comments on commit 1809f51

Please sign in to comment.