Skip to content

Commit

Permalink
fix and clean code
Browse files Browse the repository at this point in the history
+Fix issue with Choose New Wanderers Dialog
+Change default algorithm to use normal
  • Loading branch information
mastertea committed Mar 25, 2024
1 parent 067d85b commit a6d6d96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
5 changes: 4 additions & 1 deletion Source/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public static void InjectCustomUI()
if (ModsConfig.BiotechActive)
rerollLabelRect.y += 60;

if (RandomSettings.PawnFilter == null)
RandomSettings.Init();

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

var tmpSave = GUI.color;
Expand Down Expand Up @@ -337,7 +340,7 @@ public static void GoToConfigPawnPage()
var page = new Page_RandomEditor();
Find.WindowStack.Add(page);
});
}, "wait", true, null, false);
}, null, true, null, false);


}
Expand Down
2 changes: 1 addition & 1 deletion Source/PawnFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static RerollAlgorithmOptions DefaultRerollAlgorithm
get {
if (ModsConfig.IsActive("erdelf.HumanoidAlienRaces"))
return RerollAlgorithmOptions.Normal;
return RerollAlgorithmOptions.Fast;
return RerollAlgorithmOptions.Normal;
}
}

Expand Down
25 changes: 9 additions & 16 deletions Source/RandomSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using Verse.AI;

namespace RandomPlus
{
public class RandomSettings
{
static FieldInfo curPawnFieldInfo;
static MethodInfo randomAgeMethodInfo;
static MethodInfo randomTraitMethodInfo;
static MethodInfo randomSkillMethodInfo;
static MethodInfo randomHealthMethodInfo;
static MethodInfo randomBodyTypeMethodInfo;
static MethodInfo randomGeneMethodInfo;

static PropertyInfo startingAndOptionalPawnsPropertyInfo;

public static int MinSkillRange;

public static int randomRerollCounter = 0;
Expand All @@ -40,9 +42,6 @@ public static void Init()
{
pawnFilter = new PawnFilter();

curPawnFieldInfo = typeof(Page_ConfigureStartingPawns)
.GetField("curPawn", BindingFlags.NonPublic | BindingFlags.Instance);

randomAgeMethodInfo = typeof(PawnGenerator)
.GetMethod("GenerateRandomAge", BindingFlags.NonPublic | BindingFlags.Static);

Expand All @@ -60,6 +59,9 @@ public static void Init()

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

startingAndOptionalPawnsPropertyInfo = typeof(StartingPawnUtility)
.GetProperty("StartingAndOptionalPawns", BindingFlags.NonPublic | BindingFlags.Static);
}

public static void ResetRerollCounter()
Expand All @@ -69,9 +71,6 @@ public static void ResetRerollCounter()

public static void Reroll(int pawnIndex)
{
PropertyInfo startingAndOptionalPawnsPropertyInfo = typeof(StartingPawnUtility)
.GetProperty("StartingAndOptionalPawns", BindingFlags.NonPublic | BindingFlags.Static);

List<Pawn> pawnList = (List<Pawn>)startingAndOptionalPawnsPropertyInfo.GetValue(null);
Pawn pawn = pawnList[pawnIndex];

Expand All @@ -83,7 +82,8 @@ public static void Reroll(int pawnIndex)
if (CheckPawnIsSatisfied(pawn))
return;

if (PawnFilter.RerollAlgorithm == PawnFilter.RerollAlgorithmOptions.Normal)
if (PawnFilter.RerollAlgorithm == PawnFilter.RerollAlgorithmOptions.Normal ||
Find.WindowStack.currentlyDrawnWindow is Dialog_ChooseNewWanderers)
{
while (true)
{
Expand Down Expand Up @@ -180,6 +180,7 @@ public static void Reroll(int pawnIndex)
pawn = StartingPawnUtility.RandomizeInPlace(pawn);

//Log.Error("Error while generating pawn. Rethrowing. Exception: \n" + (object)ex);
//return;
//throw;
}

Expand All @@ -192,25 +193,18 @@ public static bool CheckPawnIsSatisfied(Pawn pawn)
{
return true;
}
//Log.Warning("a1");
if (!CheckGenderIsSatisfied(pawn))
return false;
//Log.Warning("a2");
if (!CheckSkillsIsSatisfied(pawn))
return false;
//Log.Warning("a3");
if (!CheckTraitsIsSatisfied(pawn))
return false;
//Log.Warning("a4");
if (!CheckHealthIsSatisfied(pawn))
return false;
//Log.Warning("a5");
if (!CheckWorkIsSatisfied(pawn))
return false;
//Log.Warning("a6");
if (!CheckAgeIsSatisfied(pawn))
return false;
//Log.Warning("a7");
return true;
}

Expand Down Expand Up @@ -246,7 +240,6 @@ public static bool CheckSkillsIsSatisfied(Pawn pawn)
var skillRecord = skillList.FirstOrDefault(i => i.def == skillFilter.SkillDef);
if (skillRecord != null)
{
//Log.Error(skillRecord.Level + ":" + skillFilter.MinValue);
if (skillRecord.passion < skillFilter.Passion ||
skillRecord.Level < skillFilter.MinValue)
{
Expand Down

0 comments on commit a6d6d96

Please sign in to comment.