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.6/Assemblies/FactionLoadout.dll
Binary file not shown.
28 changes: 28 additions & 0 deletions 1.6/Source/FactionEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public class FactionEdit : IExposable
{
private static readonly Dictionary<string, FactionDef> originalFactionDefs = new();
private static Dictionary<(FactionDef, PawnKindDef), PawnKindDef> factionSpecificPawnKindReplacements = new();

/// <summary>FactionDef defName → the FactionEdit applied to it by the active preset(s). Rebuilt on preset apply.</summary>
public static readonly Dictionary<string, FactionEdit> ActiveFactionEdits = new();

/// <summary>Returns the active <see cref="FactionEdit"/> for a runtime faction's def, or null.</summary>
public static FactionEdit GetActiveEditFor(FactionDef def) =>
def == null ? null
: ActiveFactionEdits.TryGetValue(def.defName, out FactionEdit edit) ? edit
: null;

public bool Active = true;
public ThingFilter ApparelStuffFilter;
public TechLevel? TechLevel = null;
Expand All @@ -24,6 +34,17 @@ public class FactionEdit : IExposable
private Dictionary<string, string> preservedFactionModuleXml;

public DefRef<FactionDef> Faction = new();

/// <summary>
/// Portable forced PRIMARY ideology reference for this faction (a <c>.rid</c> filename or an
/// <see cref="IdeoPresetDef"/> defName; null = don't force). Each real faction instance
/// realises this once per save via <see cref="ForcedIdeoGameComponent"/> and has it set as its
/// primary ideology, so the ideology listing matches what pawns actually believe. Pawnkind
/// edits referencing the same source+key resolve to the same realised instance.
/// </summary>
public string ForcedPrimaryIdeoKey = null;
public ForcedIdeoSource ForcedPrimaryIdeoSourceKind = ForcedIdeoSource.SavedFile;

public List<PawnKindEdit> KindEdits = [];
public List<PawnGroupMakerEdit> PawnGroupMakerEdits = null;
public Dictionary<string, float> xenotypeChances = [];
Expand All @@ -45,6 +66,8 @@ public void ExposeData()
Scribe_Deep.Look(ref ApparelStuffFilter, "apparelStuffFilter");
Scribe_Deep.Look(ref Faction, "faction");
Scribe_Values.Look(ref TechLevel, "techLevel");
Scribe_Values.Look(ref ForcedPrimaryIdeoKey, "forcedPrimaryIdeoKey");
Scribe_Values.Look(ref ForcedPrimaryIdeoSourceKind, "forcedPrimaryIdeoSourceKind", ForcedIdeoSource.SavedFile);
Scribe_Collections.Look(ref KindEdits, "kindEdits", LookMode.Deep);
Scribe_Collections.Look(ref xenotypeChances, "xenotypeChances", LookMode.Value, LookMode.Value);
if (Scribe.mode == LoadSaveMode.Saving)
Expand All @@ -56,6 +79,7 @@ public void ExposeData()
if (Scribe.mode != LoadSaveMode.PostLoadInit)
return;

xenotypeChances ??= [];
MaterializeXenotypeChances();
if (!(xenotypeChances.NullOrEmpty() && xenotypeChancesByDef.NullOrEmpty()))
OverrideFactionXenotypes = true;
Expand Down Expand Up @@ -268,6 +292,7 @@ public static void ClearState()
{
originalFactionDefs.Clear();
factionSpecificPawnKindReplacements.Clear();
ActiveFactionEdits.Clear();
}

public static FactionDef TryGetOriginal(string factionDefName)
Expand Down Expand Up @@ -371,6 +396,7 @@ public void Apply(FactionDef def, bool updateDefDatabase = true)
// def.apparelStuffFilter = ApparelStuffFilter;

def = EnsureOriginal(def);
ActiveFactionEdits[def.defName] = this;

// Apply group edits before discovering pawnkinds so that newly added
// pawnkinds are visible to the rest of the Apply() pipeline.
Expand Down Expand Up @@ -464,6 +490,8 @@ private void ReplaceKind(FactionDef faction, PawnKindDef original, PawnKindDef r
public void CopyFrom(FactionEdit source)
{
TechLevel = source.TechLevel;
ForcedPrimaryIdeoKey = source.ForcedPrimaryIdeoKey;
ForcedPrimaryIdeoSourceKind = source.ForcedPrimaryIdeoSourceKind;
OverrideFactionXenotypes = source.OverrideFactionXenotypes;
xenotypeChances = source.xenotypeChances != null ? new Dictionary<string, float>(source.xenotypeChances) : [];
xenotypeChancesByDef = source.xenotypeChancesByDef != null ? new Dictionary<XenotypeDef, float>(source.xenotypeChancesByDef) : [];
Expand Down
32 changes: 32 additions & 0 deletions 1.6/Source/FactionEditUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,38 @@ public override void DoWindowContents(Rect inRect)
);
}

// Because this is faction level and these aren't real factions skip
if (
ModsConfig.IdeologyActive
&& Current.Faction is { IsMissing: false }
&& Current.Faction?.Def != Preset.SpecialWildManFaction
&& Current.Faction?.Def != Preset.SpecialCreepjoinerFaction
&& Current.Faction?.Def != Preset.SpecialFactionlessPawnsFaction
)
{
inner.GapLine();
string primaryLabel =
ForcedIdeoRefUI.DisabledByClassicMode ? "FactionLoadout_General_IdeoClassicDisabled".Translate().ToString()
: string.IsNullOrEmpty(Current.ForcedPrimaryIdeoKey) ? "FactionLoadout_Faction_PrimaryIdeoNotOverridden".Translate().ToString()
: ForcedIdeoRefUI.DisplayName(Current.ForcedPrimaryIdeoSourceKind, Current.ForcedPrimaryIdeoKey);
if (
inner.ButtonTextLabeled("FactionLoadout_Faction_PrimaryIdeo".Translate(), primaryLabel, tooltip: "FactionLoadout_Faction_PrimaryIdeoTooltip".Translate())
&& !ForcedIdeoRefUI.DisabledByClassicMode
)
{
ForcedIdeoRefUI.OpenPicker(
includeFactionPrimary: false,
(source, key) =>
{
Current.ForcedPrimaryIdeoSourceKind = source;
Current.ForcedPrimaryIdeoKey = key;
},
onClear: () => Current.ForcedPrimaryIdeoKey = null,
clearLabel: "FactionLoadout_Faction_PrimaryIdeoNotOverridden".Translate().ToString()
);
}
}

if (
ModsConfig.BiotechActive
&& Current.Faction is { IsMissing: false }
Expand Down
Loading