Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified 1.5/Assemblies/FactionLoadout.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion 1.5/Source/ApparelGenPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void Postfix(Pawn pawn)
hairColors.Clear();
edits = 0;

foreach (PawnKindEdit edit in PawnKindEdit.GetEditsFor(pawn.kindDef))
foreach (PawnKindEdit edit in PawnKindEdit.GetEditsFor(pawn.kindDef, pawn.Faction?.def))
{
Accumulate(edit);
edits++;
Expand Down
2 changes: 1 addition & 1 deletion 1.5/Source/CloningUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static PawnKindDef Clone(PawnKindDef def)
if (def == null)
return null;

if (def is CreepJoinerFormKindDef)
if (def is CreepJoinerFormKindDef || def == PawnKindDefOf.WildMan)
return def;

PawnKindDef created = new PawnKindDef();
Expand Down
1 change: 1 addition & 0 deletions 1.5/Source/Dialog_FactionLoadout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@ public override void PostClose()
{
base.PostClose();
Find.WindowStack.WindowOfType<PresetUI>()?.Close();
ModCore.Settings.ExposeData();
}
}
1 change: 1 addition & 0 deletions 1.5/Source/FactionEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class FactionEdit : IExposable

public static PawnKindDef GetReplacementForPawnKind(FactionDef faction, PawnKindDef original)
{
if (original == PawnKindDefOf.WildMan) faction = Preset.SpecialWildManFaction;
factionSpecificPawnKindReplacements.TryGetValue((faction, original), out PawnKindDef replacement);
ModCore.Debug($"Found replacement for {original.defName} in {faction.defName}: {replacement?.defName ?? "<null>"}");
return replacement ?? original;
Expand Down
41 changes: 29 additions & 12 deletions 1.5/Source/FactionEditUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public override void DoWindowContents(Rect inRect)
"<color=yellow>EXPERIMENTAL! - This is a fake faction used for Creepjoiner editing, use at your own risk.</color>"
);
}
if (Current.Faction.DefName == Preset.SpecialWildManFactionDefName)
{
ui.Label(
"<color=yellow>EXPERIMENTAL! - This is a fake faction used for WildMan editing, use at your own risk.</color>"
);
}

// Disabled for now
// DrawMaterialFilter(ui);
Expand All @@ -119,22 +125,22 @@ public override void DoWindowContents(Rect inRect)
);
}

if (ModsConfig.BiotechActive)
if (ModsConfig.BiotechActive && Current.Faction.Def != Preset.SpecialWildManFaction)
{
ui.GapLine();
ui.Label("<b>Xenotype spawn rates:</b>");
var toDelete = new List<XenotypeDef>();
if (Current.xenotypeChances is null)
{
Current.xenotypeChances =
Current.Faction.Def?.xenotypeSet?.xenotypeChances?.ToDictionary(
Current.Faction?.Def?.xenotypeSet?.xenotypeChances?.ToDictionary(
x => x.xenotype,
x => x.chance
) ?? new Dictionary<XenotypeDef, float>();
if (!Current.xenotypeChances.ContainsKey(XenotypeDefOf.Baseliner))
Current.xenotypeChances.Add(
XenotypeDefOf.Baseliner,
Current.Faction.Def?.xenotypeSet?.BaselinerChance ?? 1f
Current.Faction?.Def?.xenotypeSet?.BaselinerChance ?? 1f
);
}

Expand Down Expand Up @@ -399,16 +405,25 @@ PawnGroupMaker maker in Current.Faction.Def.pawnGroupMakers
Current.Apply(clonedFac, false);
DestroyPawns();

Faction faction = new();
faction.def = clonedFac;
faction.loadID = -1;
faction.colorFromSpectrum = Rand.Range(0f, 1f);
faction.hidden = true;
faction.ideos = Find.FactionManager?.FirstFactionOfDef(Current.Faction.Def)?.ideos;
faction.Name = clonedFac.fixedName;
faction.TryMakeInitialRelationsWith(Faction.OfPlayer);
Faction faction = new()
{
def = clonedFac,
loadID = -1,
colorFromSpectrum = Rand.Range(0f, 1f),
hidden = true,
ideos = Find.FactionManager?.FirstFactionOfDef(Current.Faction.Def)?.ideos,
Name = clonedFac.fixedName,
relations = Find.FactionManager.AllFactionsVisible.Select(otherFaction => new FactionRelation()
{
other = otherFaction,
baseGoodwill = 0,
kind = FactionRelationKind.Neutral
}).ToList(),
temporary = true
};

ThingIDPatch.Active = _ThingIDPatch;
IdeoUtilityPatch.Active = true;

foreach (PawnKindDef item in FactionEdit.GetAllPawnKinds(clonedFac))
try
Expand All @@ -421,7 +436,8 @@ PawnGroupMaker maker in Current.Faction.Def.pawnGroupMakers
AllowDead = false,
CanGeneratePawnRelations = false,
RelationWithExtraPawnChanceFactor = 0,
ColonistRelationChanceFactor = 0
ColonistRelationChanceFactor = 0,
ForceNoIdeo = true
}
);
pawns.Add(pawn);
Expand All @@ -435,6 +451,7 @@ PawnGroupMaker maker in Current.Faction.Def.pawnGroupMakers
ThingIDPatch.Active = false;
FactionLeaderPatch.Active = false;
FactionUtilityPawnGenPatch.Active = false;
IdeoUtilityPatch.Active = false;
}

GUI.enabled = true;
Expand Down
26 changes: 26 additions & 0 deletions 1.5/Source/IdeoUtilityPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using HarmonyLib;
using RimWorld;

namespace FactionLoadout;

/**
* This method checks every faction's relation to our faction. If there are none it spams errors.
* So to avoid polluting main faction relations with our custom factions, we need to disable this method.
*/
[HarmonyPatch(typeof(IdeoUtility), nameof(IdeoUtility.IdeoChangeToWeight))]
public static class IdeoUtilityPatch
{
public static bool Active = false;

[HarmonyPriority(Priority.First)]
public static bool Prefix(ref float __result)
{
if (Active)
{
__result = 0;
return false;
}

return true;
}
}
12 changes: 10 additions & 2 deletions 1.5/Source/ModCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace FactionLoadout
public class ModCore : Mod
{
public Dialog_FactionLoadout settingsDialog = null;
public static MySettings Settings;
public Dialog_FactionLoadout SettingsDialog => settingsDialog ??= new Dialog_FactionLoadout();

public static void Debug(string msg)
Expand Down Expand Up @@ -38,7 +39,7 @@ public static void Error(string msg, Exception e = null)
public ModCore(ModContentPack content)
: base(content)
{
GetSettings<MySettings>();
Settings = GetSettings<MySettings>();
LongEventHandler.QueueLongEvent(
LoadLate,
"FactionLoadout_LoadingScreenText",
Expand Down Expand Up @@ -102,7 +103,14 @@ private void LoadLate()
harmony.Patch(
AccessTools.Method(typeof(ThingIDMaker), "GiveIDTo"),
prefix: new HarmonyMethod(
AccessTools.Method(typeof(ThingIDPatch), "Prefix"),
AccessTools.Method(typeof(ThingIDPatch), nameof(ThingIDPatch.Prefix)),
priority: Priority.First
)
);
harmony.Patch(
AccessTools.Method(typeof(IdeoUtility), nameof(IdeoUtility.IdeoChangeToWeight)),
prefix: new HarmonyMethod(
AccessTools.Method(typeof(IdeoUtilityPatch), nameof(IdeoUtilityPatch.Prefix)),
priority: Priority.First
)
);
Expand Down
4 changes: 2 additions & 2 deletions 1.5/Source/PawnGenPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class PawnGenPatchBodyTypeDef
public static void Postfix(ref BodyTypeDef __result, Pawn pawn)
{
PawnKindEdit
.GetEditsFor(pawn.kindDef)
.GetEditsFor(pawn.kindDef, pawn.Faction?.def)
.SelectMany(e => e.BodyTypes ?? [])
.TryRandomElement(out BodyTypeDef bodyTypeDef);
if (bodyTypeDef != null)
Expand Down Expand Up @@ -75,7 +75,7 @@ public static bool Prefix(Pawn pawn, ref PawnGenerationRequest request)
return true;
int? minAge = null;
int? maxAge = null;
foreach (PawnKindEdit pawnKindEdit in PawnKindEdit.GetEditsFor(pawn.kindDef))
foreach (PawnKindEdit pawnKindEdit in PawnKindEdit.GetEditsFor(pawn.kindDef, pawn.Faction?.def))
{
if (pawnKindEdit.MinGenerationAge != null && (!pawnKindEdit.IsGlobal || minAge == null))
minAge = pawnKindEdit.MinGenerationAge;
Expand Down
16 changes: 14 additions & 2 deletions 1.5/Source/PawnKindEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,27 @@ public static void SetActiveEdits(PawnKindDef pawnKindDef, List<PawnKindEdit> ed
public static PawnKindDef NormaliseDef(PawnKindDef def) =>
replacementToOriginal.TryGetValue(def, def);

public static IEnumerable<PawnKindEdit> GetEditsFor(PawnKindDef def)
public static IEnumerable<PawnKindEdit> GetEditsFor(PawnKindDef def, FactionDef factionDef)
{
if (def == null)
yield break;
factionDef = ForcedFactionForEditing(def, factionDef);

if (!activeEdits.TryGetValue(def, out List<PawnKindEdit> list))
yield break;
foreach (PawnKindEdit item in list)
yield return item;
if (factionDef == null || item.ParentEdit.Faction.Def == factionDef || FactionEdit.TryGetOriginal(factionDef.defName) == item.ParentEdit.Faction.Def)
yield return item;
}

public static FactionDef ForcedFactionForEditing(PawnKindDef def, FactionDef fallbackFactionDef)
{
if (def == null)
{
return fallbackFactionDef;
}

return def == PawnKindDefOf.WildMan ? Preset.SpecialWildManFaction : fallbackFactionDef;
}

private static void AddActiveEdit(PawnKindDef def, PawnKindEdit edit)
Expand Down
35 changes: 27 additions & 8 deletions 1.5/Source/Preset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public static void DeletePreset(Preset preset)
}

public static string SpecialCreepjoinerFactionDefName = "FactionLoadout_Special_CreepJoiner";
public static string SpecialWildManFactionDefName = "FactionLoadout_Special_WildMan";

public static FactionDef SpecialCreepjoinerFaction = new()
{
hidden = true,
Expand All @@ -66,19 +68,34 @@ public static void DeletePreset(Preset preset)
humanlikeFaction = true,
raidsForbidden = true,
requiredCountAtGameStart = 0,
pawnGroupMakers = [new PawnGroupMaker()
{
kindDef = PawnGroupKindDefOf.Combat,
options = DefDatabase<CreepJoinerFormKindDef>.AllDefsListForReading.Select(creepKind => new PawnGenOption()
pawnGroupMakers =
[
new PawnGroupMaker
{
kind = creepKind,
}).ToList(),
}]
kindDef = PawnGroupKindDefOf.Combat,
options = DefDatabase<CreepJoinerFormKindDef>.AllDefsListForReading.Select(creepKind => new PawnGenOption
{
kind = creepKind,
}).ToList(),
}
]
};

public static FactionDef SpecialWildManFaction = new()
{
hidden = true,
defName = SpecialWildManFactionDefName,
label = "Special WildMan",
description = "This is a special faction that is used to edit a faux WildMan faction.",
humanlikeFaction = true,
raidsForbidden = true,
requiredCountAtGameStart = 0,
basicMemberKind = PawnKindDefOf.WildMan
};

public string Name = "My preset";
public List<FactionEdit> factionChanges = new List<FactionEdit>();

public string GUID
{
get
Expand All @@ -98,6 +115,8 @@ public void ExposeData()
Scribe_Values.Look(ref guid, "guid");
if (DefDatabase<FactionDef>.GetNamed(SpecialCreepjoinerFactionDefName, false) == null)
DefDatabase<FactionDef>.Add(SpecialCreepjoinerFaction);
if (DefDatabase<FactionDef>.GetNamed(SpecialWildManFactionDefName, false) == null)
DefDatabase<FactionDef>.Add(SpecialWildManFaction);
Scribe_Collections.Look(ref factionChanges, "factionChanges", LookMode.Deep);
}

Expand Down Expand Up @@ -173,7 +192,7 @@ private void EnsureGUID()
guid = "";

var rand = new Random();
char[] digits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
for (int i = 0; i < 16; i++)
{
guid += digits[rand.Next(digits.Length)];
Expand Down
4 changes: 4 additions & 0 deletions 1.5/Source/PresetUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public override void DoWindowContents(Rect inRect)
{
raw.Add(Preset.SpecialCreepjoinerFaction);
}
if (!Current.HasEditFor(Preset.SpecialWildManFaction) && !raw.Any(f => f.defName == Preset.SpecialWildManFaction.defName))
{
raw.Add(Preset.SpecialWildManFaction);
}
List<MenuItemBase> items = CustomFloatMenu.MakeItems(
raw,
f => new MenuItemText(
Expand Down
2 changes: 1 addition & 1 deletion 1.5/Source/ThingIDPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class ThingIDPatch
public static bool Active = false;

[HarmonyPriority(Priority.First)]
static bool Prefix(Thing t)
public static bool Prefix(Thing t)
{
if (Active)
{
Expand Down
2 changes: 1 addition & 1 deletion 1.5/Source/WeaponGenPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void Postfix(Pawn pawn)
pool4.Clear();
edits = 0;

foreach (var edit in PawnKindEdit.GetEditsFor(pawn.kindDef))
foreach (var edit in PawnKindEdit.GetEditsFor(pawn.kindDef, pawn.Faction?.def))
{
Accumulate(edit);
edits++;
Expand Down
Binary file not shown.