Skip to content

Commit edcc024

Browse files
committed
Fixed to 1.4 v0
+Fixed label alignment with biotech enabled +Fixed fast algorithm with genes giving hediffs. +Fixed issue with HAR mod compatibility
1 parent 33c3d61 commit edcc024

5 files changed

Lines changed: 96 additions & 22 deletions

File tree

Source/HarmonyPatches.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public static void InjectCustomUI()
206206
Rect rerollLabelRect = new Rect(640f, 4f, 200f, 30f);
207207
if (ModsConfig.IdeologyActive)
208208
rerollLabelRect.y += 40;
209+
if (ModsConfig.BiotechActive)
210+
rerollLabelRect.y += 60;
209211

210212
string labelText = "RandomPlus.RerollLabel".Translate() + RandomSettings.RandomRerollCounter() + "/" + RandomSettings.PawnFilter.RerollLimit;
211213

Source/Page_RandomEditor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public override void PreOpen()
6060
public override void DoWindowContents(Rect inRect)
6161
{
6262
this.DrawPageTitle(inRect);
63+
64+
if (Prefs.DevMode && Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.UpArrow)
65+
{
66+
GenCommandLine.Restart();
67+
}
68+
6369
//Rect mainRect = base.GetMainRect(inRect, 30f, false);
6470

6571
panelSkills.Draw();

Source/PanelOthers.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ protected override void DrawPanelContent()
102102
private readonly static Action<Enum> rerollAlgorithmCallback = (Enum val) => RandomSettings.PawnFilter.RerollAlgorithm = (PawnFilter.RerollAlgorithmOptions)val;
103103
public void drawRerollAlgorithm(Rect rect)
104104
{
105-
drawButton(rect, PawnFilter.RerollAlgorithmOptionValues[(int)RandomSettings.PawnFilter.RerollAlgorithm], typeof(PawnFilter.RerollAlgorithmOptions), PawnFilter.RerollAlgorithmOptionValues, rerollAlgorithmCallback);
105+
drawButton(
106+
rect,
107+
PawnFilter.RerollAlgorithmOptionValues[(int)RandomSettings.PawnFilter.RerollAlgorithm],
108+
typeof(PawnFilter.RerollAlgorithmOptions),
109+
PawnFilter.RerollAlgorithmOptionValues,
110+
rerollAlgorithmCallback);
106111
}
107112

108113
private readonly static Action<Enum> rerollLimitCallback = (Enum val) => RandomSettings.PawnFilter.RerollLimit = (int)(PawnFilter.RerollLimitOptions)val;
@@ -140,11 +145,14 @@ public void drawButton(Rect rect, string label, Type enumOptionType, string[] di
140145
for (int i=0; i < enumOptions.Length; i++)
141146
{
142147
var option = enumOptions[i];
143-
var displayedName = (translate) ? displayedNameArray[i].Translate().CapitalizeFirst().ToString() : displayedNameArray[i].CapitalizeFirst();
144-
var menuOption = new FloatMenuOption(displayedName, () => {
145-
callback?.Invoke(option);
146-
});
147-
options.Add(menuOption);
148+
if (displayedNameArray.Length > i)
149+
{
150+
var displayedName = (translate) ? displayedNameArray[i].Translate().CapitalizeFirst().ToString() : displayedNameArray[i].CapitalizeFirst();
151+
var menuOption = new FloatMenuOption(displayedName, () => {
152+
callback?.Invoke(option);
153+
});
154+
options.Add(menuOption);
155+
}
148156
}
149157
Find.WindowStack.Add(new FloatMenu(options));
150158
}

Source/PawnFilter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ public static string[] RerollAlgorithmOptionValues {
3131
return _RerollAlgorithmOptionValues;
3232
}
3333
}
34-
public static readonly RerollAlgorithmOptions DefaultRerollAlgorithm = RerollAlgorithmOptions.Fast;
34+
public static RerollAlgorithmOptions DefaultRerollAlgorithm
35+
{
36+
get {
37+
if (ModsConfig.IsActive("erdelf.HumanoidAlienRaces"))
38+
return RerollAlgorithmOptions.Normal;
39+
return RerollAlgorithmOptions.Fast;
40+
}
41+
}
3542

3643
public enum RerollLimitOptions { N100 = 100, N250 = 250, N500 = 500, N1000 = 1000, N2500 = 2500, N5000 = 5000, N10000 = 10000, N50000 = 50000 }
3744
public readonly static string[] RerollLimitOptionValues = new string[] { "100", "250", "500", "1000", "2500", "5000", "10000", "50000" };

Source/RandomSettings.cs

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class RandomSettings
1616
static MethodInfo randomSkillMethodInfo;
1717
static MethodInfo randomHealthMethodInfo;
1818
static MethodInfo randomBodyTypeMethodInfo;
19+
static MethodInfo randomGeneMethodInfo;
1920

2021
public static int MinSkillRange;
2122

@@ -56,6 +57,9 @@ public static void Init()
5657

5758
randomBodyTypeMethodInfo = typeof(PawnGenerator)
5859
.GetMethod("GenerateBodyType", BindingFlags.NonPublic | BindingFlags.Static);
60+
61+
randomGeneMethodInfo = typeof(PawnGenerator)
62+
.GetMethod("GenerateGenes", BindingFlags.NonPublic | BindingFlags.Static);
5963
}
6064

6165
public static void ResetRerollCounter()
@@ -71,13 +75,27 @@ public static bool Reroll(Pawn pawn)
7175
return CheckPawnIsSatisfied(pawn);
7276
}
7377

74-
PawnGenerationRequest request = new PawnGenerationRequest(
75-
Faction.OfPlayer.def.basicMemberKind,
76-
Faction.OfPlayer,
77-
PawnGenerationContext.PlayerStarter,
78-
forceGenerateNewPawn: true,
79-
mustBeCapableOfViolence: TutorSystem.TutorialMode,
80-
colonistRelationChanceFactor: 20f);
78+
//PawnGenerationRequest request = new PawnGenerationRequest(
79+
// Faction.OfPlayer.def.basicMemberKind,
80+
// Faction.OfPlayer,
81+
// PawnGenerationContext.PlayerStarter,
82+
83+
// forceGenerateNewPawn: true,
84+
// mustBeCapableOfViolence: TutorSystem.TutorialMode,
85+
// colonistRelationChanceFactor: 20f);
86+
87+
//PawnGenerationRequest request = new PawnGenerationRequest(
88+
// Find.GameInitData.startingPawnKind ?? Faction.OfPlayer.def.basicMemberKind,
89+
// Faction.OfPlayer,
90+
// PawnGenerationContext.PlayerStarter,
91+
// forceGenerateNewPawn: true,
92+
// mustBeCapableOfViolence: TutorSystem.TutorialMode,
93+
// colonistRelationChanceFactor: 20f, allowPregnant: true,
94+
// forcedXenotype: (ModsConfig.BiotechActive ? XenotypeDefOf.Baseliner : null),
95+
// excludeBiologicalAgeRange: (ModsConfig.BiotechActive ? new FloatRange(12.1f, 13f) : new FloatRange?()));
96+
97+
int index = StartingPawnUtility.PawnIndex(pawn);
98+
PawnGenerationRequest request = StartingPawnUtility.GetGenerationRequest(index);
8199

82100
if (!CheckGenderIsSatisfied(pawn))
83101
{
@@ -89,6 +107,8 @@ public static bool Reroll(Pawn pawn)
89107
{
90108
randomRerollCounter++;
91109

110+
PawnGenerator.RedressPawn(pawn, request);
111+
92112
pawn.ageTracker = new Pawn_AgeTracker(pawn);
93113
randomAgeMethodInfo.Invoke(null, new object[] { pawn, request });
94114
if (!CheckAgeIsSatisfied(pawn))
@@ -130,10 +150,17 @@ public static bool Reroll(Pawn pawn)
130150
continue;
131151

132152
// Handle custom scenario
133-
Find.Scenario.Notify_PawnGenerated(pawn, request.Context, true);
134-
if (!CheckPawnIsSatisfied(pawn))
135-
continue;
153+
//Find.Scenario.Notify_PawnGenerated(pawn, request.Context, true);
154+
//if (!CheckPawnIsSatisfied(pawn))
155+
// continue;
156+
136157
// Generate Misc
158+
if (ModsConfig.BiotechActive && pawn.genes != null)
159+
{
160+
pawn.genes.Reset();
161+
XenotypeDef xenotype = ModsConfig.BiotechActive ? PawnGenerator.GetXenotypeForGeneratedPawn(request) : null;
162+
randomGeneMethodInfo.Invoke(null, new object[] { pawn, xenotype, request });
163+
}
137164
randomBodyTypeMethodInfo.Invoke(null, new object[] { pawn, request });
138165
GeneratePawnStyle(pawn);
139166

@@ -316,31 +343,55 @@ public static bool CheckTraitsIsSatisfied(Pawn pawn)
316343
return true;
317344
}
318345

346+
private static bool IsGeneAffectedHealth(Hediff hediff)
347+
{
348+
if (!ModsConfig.BiotechActive)
349+
return false;
350+
351+
if (hediff is Hediff_ChemicalDependency chemicalDependency && chemicalDependency.LinkedGene != null)
352+
return true;
353+
354+
return false;
355+
}
356+
319357
public static bool CheckHealthIsSatisfied(Pawn pawn)
320358
{
359+
321360
// handle health options
322361
switch (pawnFilter.FilterHealthCondition)
323362
{
324363
case PawnFilter.HealthOptions.AllowAll:
325364
break;
326365
case PawnFilter.HealthOptions.OnlyStartCondition:
327-
var foundNotStartCondition = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff.def.defName != "CryptosleepSickness" && hediff.def.defName != "Malnutrition");
366+
var foundNotStartCondition =
367+
pawn.health.hediffSet.hediffs
368+
.FirstOrDefault((hediff) => hediff.def.defName != "CryptosleepSickness" && hediff.def.defName != "Malnutrition" && !IsGeneAffectedHealth(hediff));
328369
if (foundNotStartCondition != null)
329370
return false;
330371
break;
331372
case PawnFilter.HealthOptions.NoPain:
332-
var foundPain = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff.PainOffset > 0f);
373+
var foundPain = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff.PainOffset > 0f && !IsGeneAffectedHealth(hediff));
333374
if (foundPain != null)
334375
return false;
335376
break;
336377
case PawnFilter.HealthOptions.NoAddiction:
337-
var foundAddiction = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff is Hediff_Addiction);
378+
var foundAddiction = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff is Hediff_Addiction && !IsGeneAffectedHealth(hediff));
338379
if (foundAddiction != null)
339380
return false;
340381
break;
341382
case PawnFilter.HealthOptions.AllowNone:
342-
if (pawn.health.hediffSet.hediffs.Count > 0)
343-
return false;
383+
if (ModsConfig.BiotechActive)
384+
{
385+
if (pawn.health.hediffSet.hediffs.Where(i => !IsGeneAffectedHealth(i)).Count() > 0)
386+
return false;
387+
}
388+
else
389+
{
390+
if (pawn.health.hediffSet.hediffs.Count > 0)
391+
return false;
392+
}
393+
394+
344395
break;
345396
// case PawnFilter.HealthOptions.OnlyPositiveImplants:
346397
// var hediffs = pawn.health.hediffSet.hediffs;

0 commit comments

Comments
 (0)