Skip to content

Commit

Permalink
Fixed to 1.4 v0
Browse files Browse the repository at this point in the history
+Fixed label alignment with biotech enabled
+Fixed fast algorithm with genes giving hediffs.
+Fixed issue with HAR mod compatibility
  • Loading branch information
mastertea committed Oct 22, 2022
1 parent 33c3d61 commit edcc024
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Source/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public static void InjectCustomUI()
Rect rerollLabelRect = new Rect(640f, 4f, 200f, 30f);
if (ModsConfig.IdeologyActive)
rerollLabelRect.y += 40;
if (ModsConfig.BiotechActive)
rerollLabelRect.y += 60;

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

Expand Down
6 changes: 6 additions & 0 deletions Source/Page_RandomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public override void PreOpen()
public override void DoWindowContents(Rect inRect)
{
this.DrawPageTitle(inRect);

if (Prefs.DevMode && Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.UpArrow)
{
GenCommandLine.Restart();
}

//Rect mainRect = base.GetMainRect(inRect, 30f, false);

panelSkills.Draw();
Expand Down
20 changes: 14 additions & 6 deletions Source/PanelOthers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ protected override void DrawPanelContent()
private readonly static Action<Enum> rerollAlgorithmCallback = (Enum val) => RandomSettings.PawnFilter.RerollAlgorithm = (PawnFilter.RerollAlgorithmOptions)val;
public void drawRerollAlgorithm(Rect rect)
{
drawButton(rect, PawnFilter.RerollAlgorithmOptionValues[(int)RandomSettings.PawnFilter.RerollAlgorithm], typeof(PawnFilter.RerollAlgorithmOptions), PawnFilter.RerollAlgorithmOptionValues, rerollAlgorithmCallback);
drawButton(
rect,
PawnFilter.RerollAlgorithmOptionValues[(int)RandomSettings.PawnFilter.RerollAlgorithm],
typeof(PawnFilter.RerollAlgorithmOptions),
PawnFilter.RerollAlgorithmOptionValues,
rerollAlgorithmCallback);
}

private readonly static Action<Enum> rerollLimitCallback = (Enum val) => RandomSettings.PawnFilter.RerollLimit = (int)(PawnFilter.RerollLimitOptions)val;
Expand Down Expand Up @@ -140,11 +145,14 @@ public void drawButton(Rect rect, string label, Type enumOptionType, string[] di
for (int i=0; i < enumOptions.Length; i++)
{
var option = enumOptions[i];
var displayedName = (translate) ? displayedNameArray[i].Translate().CapitalizeFirst().ToString() : displayedNameArray[i].CapitalizeFirst();
var menuOption = new FloatMenuOption(displayedName, () => {
callback?.Invoke(option);
});
options.Add(menuOption);
if (displayedNameArray.Length > i)
{
var displayedName = (translate) ? displayedNameArray[i].Translate().CapitalizeFirst().ToString() : displayedNameArray[i].CapitalizeFirst();
var menuOption = new FloatMenuOption(displayedName, () => {
callback?.Invoke(option);
});
options.Add(menuOption);
}
}
Find.WindowStack.Add(new FloatMenu(options));
}
Expand Down
9 changes: 8 additions & 1 deletion Source/PawnFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ public static string[] RerollAlgorithmOptionValues {
return _RerollAlgorithmOptionValues;
}
}
public static readonly RerollAlgorithmOptions DefaultRerollAlgorithm = RerollAlgorithmOptions.Fast;
public static RerollAlgorithmOptions DefaultRerollAlgorithm
{
get {
if (ModsConfig.IsActive("erdelf.HumanoidAlienRaces"))
return RerollAlgorithmOptions.Normal;
return RerollAlgorithmOptions.Fast;
}
}

public enum RerollLimitOptions { N100 = 100, N250 = 250, N500 = 500, N1000 = 1000, N2500 = 2500, N5000 = 5000, N10000 = 10000, N50000 = 50000 }
public readonly static string[] RerollLimitOptionValues = new string[] { "100", "250", "500", "1000", "2500", "5000", "10000", "50000" };
Expand Down
81 changes: 66 additions & 15 deletions Source/RandomSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class RandomSettings
static MethodInfo randomSkillMethodInfo;
static MethodInfo randomHealthMethodInfo;
static MethodInfo randomBodyTypeMethodInfo;
static MethodInfo randomGeneMethodInfo;

public static int MinSkillRange;

Expand Down Expand Up @@ -56,6 +57,9 @@ public static void Init()

randomBodyTypeMethodInfo = typeof(PawnGenerator)
.GetMethod("GenerateBodyType", BindingFlags.NonPublic | BindingFlags.Static);

randomGeneMethodInfo = typeof(PawnGenerator)
.GetMethod("GenerateGenes", BindingFlags.NonPublic | BindingFlags.Static);
}

public static void ResetRerollCounter()
Expand All @@ -71,13 +75,27 @@ public static bool Reroll(Pawn pawn)
return CheckPawnIsSatisfied(pawn);
}

PawnGenerationRequest request = new PawnGenerationRequest(
Faction.OfPlayer.def.basicMemberKind,
Faction.OfPlayer,
PawnGenerationContext.PlayerStarter,
forceGenerateNewPawn: true,
mustBeCapableOfViolence: TutorSystem.TutorialMode,
colonistRelationChanceFactor: 20f);
//PawnGenerationRequest request = new PawnGenerationRequest(
// Faction.OfPlayer.def.basicMemberKind,
// Faction.OfPlayer,
// PawnGenerationContext.PlayerStarter,

// forceGenerateNewPawn: true,
// mustBeCapableOfViolence: TutorSystem.TutorialMode,
// colonistRelationChanceFactor: 20f);

//PawnGenerationRequest request = new PawnGenerationRequest(
// Find.GameInitData.startingPawnKind ?? Faction.OfPlayer.def.basicMemberKind,
// Faction.OfPlayer,
// PawnGenerationContext.PlayerStarter,
// forceGenerateNewPawn: true,
// mustBeCapableOfViolence: TutorSystem.TutorialMode,
// colonistRelationChanceFactor: 20f, allowPregnant: true,
// forcedXenotype: (ModsConfig.BiotechActive ? XenotypeDefOf.Baseliner : null),
// excludeBiologicalAgeRange: (ModsConfig.BiotechActive ? new FloatRange(12.1f, 13f) : new FloatRange?()));

int index = StartingPawnUtility.PawnIndex(pawn);
PawnGenerationRequest request = StartingPawnUtility.GetGenerationRequest(index);

if (!CheckGenderIsSatisfied(pawn))
{
Expand All @@ -89,6 +107,8 @@ public static bool Reroll(Pawn pawn)
{
randomRerollCounter++;

PawnGenerator.RedressPawn(pawn, request);

pawn.ageTracker = new Pawn_AgeTracker(pawn);
randomAgeMethodInfo.Invoke(null, new object[] { pawn, request });
if (!CheckAgeIsSatisfied(pawn))
Expand Down Expand Up @@ -130,10 +150,17 @@ public static bool Reroll(Pawn pawn)
continue;

// Handle custom scenario
Find.Scenario.Notify_PawnGenerated(pawn, request.Context, true);
if (!CheckPawnIsSatisfied(pawn))
continue;
//Find.Scenario.Notify_PawnGenerated(pawn, request.Context, true);
//if (!CheckPawnIsSatisfied(pawn))
// continue;

// Generate Misc
if (ModsConfig.BiotechActive && pawn.genes != null)
{
pawn.genes.Reset();
XenotypeDef xenotype = ModsConfig.BiotechActive ? PawnGenerator.GetXenotypeForGeneratedPawn(request) : null;
randomGeneMethodInfo.Invoke(null, new object[] { pawn, xenotype, request });
}
randomBodyTypeMethodInfo.Invoke(null, new object[] { pawn, request });
GeneratePawnStyle(pawn);

Expand Down Expand Up @@ -316,31 +343,55 @@ public static bool CheckTraitsIsSatisfied(Pawn pawn)
return true;
}

private static bool IsGeneAffectedHealth(Hediff hediff)
{
if (!ModsConfig.BiotechActive)
return false;

if (hediff is Hediff_ChemicalDependency chemicalDependency && chemicalDependency.LinkedGene != null)
return true;

return false;
}

public static bool CheckHealthIsSatisfied(Pawn pawn)
{

// handle health options
switch (pawnFilter.FilterHealthCondition)
{
case PawnFilter.HealthOptions.AllowAll:
break;
case PawnFilter.HealthOptions.OnlyStartCondition:
var foundNotStartCondition = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff.def.defName != "CryptosleepSickness" && hediff.def.defName != "Malnutrition");
var foundNotStartCondition =
pawn.health.hediffSet.hediffs
.FirstOrDefault((hediff) => hediff.def.defName != "CryptosleepSickness" && hediff.def.defName != "Malnutrition" && !IsGeneAffectedHealth(hediff));
if (foundNotStartCondition != null)
return false;
break;
case PawnFilter.HealthOptions.NoPain:
var foundPain = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff.PainOffset > 0f);
var foundPain = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff.PainOffset > 0f && !IsGeneAffectedHealth(hediff));
if (foundPain != null)
return false;
break;
case PawnFilter.HealthOptions.NoAddiction:
var foundAddiction = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff is Hediff_Addiction);
var foundAddiction = pawn.health.hediffSet.hediffs.FirstOrDefault((hediff) => hediff is Hediff_Addiction && !IsGeneAffectedHealth(hediff));
if (foundAddiction != null)
return false;
break;
case PawnFilter.HealthOptions.AllowNone:
if (pawn.health.hediffSet.hediffs.Count > 0)
return false;
if (ModsConfig.BiotechActive)
{
if (pawn.health.hediffSet.hediffs.Where(i => !IsGeneAffectedHealth(i)).Count() > 0)
return false;
}
else
{
if (pawn.health.hediffSet.hediffs.Count > 0)
return false;
}


break;
// case PawnFilter.HealthOptions.OnlyPositiveImplants:
// var hediffs = pawn.health.hediffSet.hediffs;
Expand Down

0 comments on commit edcc024

Please sign in to comment.