Skip to content

Commit

Permalink
Merge pull request #261 from edbmods/develop
Browse files Browse the repository at this point in the history
Merge additional 1.0.12 fixes into master
  • Loading branch information
edbmods authored Jul 18, 2019
2 parents 9f774f9 + b2fd70e commit 4965676
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.cs text eol=lf
*.dll binary
*.png binary

22 changes: 8 additions & 14 deletions Source/EquipmentDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected bool AddThingToEquipmentLists(ThingDef def) {
}
catch (Exception e) {
Log.Warning("Prepare Carefully failed to process thing definition while building equipment lists: " + def.defName);
Log.Message(" Exception: " + e.Message);
Log.Message(" Exception: " + e);
}
return false;
}
Expand Down Expand Up @@ -242,16 +242,12 @@ public EquipmentType ClassifyThingDef(ThingDef def) {
if (def.IsFrame) {
return TypeDiscard;
}
if (def.weaponTags != null && def.weaponTags.Count > 0) {
if (def.IsWeapon) {
return TypeWeapons;
}
if (def.weaponTags != null && def.weaponTags.Count > 0 && def.IsWeapon) {
return TypeWeapons;
}

if (def.IsApparel) {
if (!def.destroyOnDrop) {
return TypeApparel;
}
if (def.IsApparel && !def.destroyOnDrop) {
return TypeApparel;
}

if (def.defName.StartsWith("MechSerum")) {
Expand All @@ -278,7 +274,7 @@ public EquipmentType ClassifyThingDef(ThingDef def) {
return TypeMedical;
}
if (def.ingestible != null) {
if (thingCategoryMeatRaw != null && def.thingCategories.Contains(thingCategoryMeatRaw)) {
if (thingCategoryMeatRaw != null && def.thingCategories != null && def.thingCategories.Contains(thingCategoryMeatRaw)) {
return TypeFood;
}
if (def.ingestible.drugCategory == DrugCategory.Medical) {
Expand All @@ -297,10 +293,8 @@ public EquipmentType ClassifyThingDef(ThingDef def) {
return TypeMedical;
}

if (def.building != null) {
if (def.Minifiable) {
return TypeBuildings;
}
if (def.building != null && def.Minifiable) {
return TypeBuildings;
}

if (def.race != null && def.race.Animal == true) {
Expand Down
21 changes: 20 additions & 1 deletion Source/PrepareCarefully.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,27 @@ public void ClearPawns() {
pawns.Clear();
}
public void AddPawn(CustomPawn customPawn) {
PreloadPawnEquipment(customPawn.Pawn);
pawns.Add(customPawn);
}
protected void PreloadPawnEquipment(Pawn pawn) {
if (pawn.equipment != null) {
foreach (var e in pawn.equipment.AllEquipmentListForReading) {
if (e.Stuff != null) {
equipmentDatabase.PreloadDefinition(e.Stuff);
}
equipmentDatabase.PreloadDefinition(e.def);
}
}
if (pawn.apparel != null) {
foreach (var e in pawn.apparel.WornApparel) {
if (e.Stuff != null) {
equipmentDatabase.PreloadDefinition(e.Stuff);
}
equipmentDatabase.PreloadDefinition(e.def);
}
}
}
public void RemovePawn(CustomPawn customPawn) {
pawns.Remove(customPawn);
}
Expand Down Expand Up @@ -513,7 +532,7 @@ public void InitializePawns() {
Pawn originalPawn = Verse.Find.GameInitData.startingAndOptionalPawns[i];
CustomPawn customPawn = originalPawnToCustomPawnMap[originalPawn];
customPawn.Type = i < startingPawnCount ? CustomPawnType.Colonist : CustomPawnType.World;
this.pawns.Add(customPawn);
this.AddPawn(customPawn);
}
}

Expand Down
3 changes: 0 additions & 3 deletions Source/ProviderAgeLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public class ProviderAgeLimits {

public int MinAgeForPawn(Pawn pawn) {
if (!minAgeLookup.TryGetValue(pawn.def, out int age)) {
foreach (var p in pawn.def.race.ageGenerationCurve) {
Log.Message(" age generation: " + p.x + ", " + p.y);
}
CurvePoint point = pawn.def.race.ageGenerationCurve.First();
age = (int)point.x;
minAgeLookup.Add(pawn.def, age);
Expand Down
26 changes: 20 additions & 6 deletions Source/Randomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,39 @@

namespace EdB.PrepareCarefully {
public class Randomizer {
public static readonly int MaxAttempts = 10;
private System.Random random = new System.Random();
public System.Random Random {
get {
return random;
}
}

protected Pawn AttemptToGeneratePawn(PawnGenerationRequest request) {
Exception lastException = null;
for (int i = 0; i < MaxAttempts; i++) {
try {
return PawnGenerator.GeneratePawn(request);
}
catch (Exception e) {
lastException = e;
}
}
throw lastException;
}

public Pawn GenerateColonist() {
Pawn result = PawnGenerator.GeneratePawn(new PawnGenerationRequestWrapper() {
}.Request);
Pawn result = AttemptToGeneratePawn(new PawnGenerationRequestWrapper() { }.Request);
return result;
}

public Pawn GeneratePawn(PawnGenerationRequest request) {
Pawn result = PawnGenerator.GeneratePawn(request);
Pawn result = AttemptToGeneratePawn(request);
return result;
}

public Pawn GenerateKindOfColonist(PawnKindDef kindDef) {
Pawn result = PawnGenerator.GeneratePawn(new PawnGenerationRequestWrapper() {
Pawn result = AttemptToGeneratePawn(new PawnGenerationRequestWrapper() {
KindDef = kindDef
}.Request);
return result;
Expand All @@ -42,7 +56,7 @@ public Pawn GenerateKindOfPawn(PawnKindDef kindDef) {
Faction = faction,
KindDef = kindDef
}.Request;
Pawn result = PawnGenerator.GeneratePawn(req);
Pawn result = AttemptToGeneratePawn(req);
return result;
}

Expand All @@ -57,7 +71,7 @@ public Pawn GenerateKindAndGenderOfPawn(PawnKindDef kindDef, Gender gender) {
KindDef = kindDef,
FixedGender = gender
}.Request;
Pawn result = PawnGenerator.GeneratePawn(req);
Pawn result = AttemptToGeneratePawn(req);
return result;
}

Expand Down

0 comments on commit 4965676

Please sign in to comment.