feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using RimWorld;
|
|
|
|
|
using Verse;
|
|
|
|
|
|
|
|
|
|
namespace BlaxCastes
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The ready-made Colonist, Slave and Prisoner castes, wired to the join rows.
|
|
|
|
|
/// - Colonist: the database's current default apparel, food, drug and reading policy (which already
|
|
|
|
|
/// carry the ideo drug rule and any earlier "Make default"). Medical care unmanaged.
|
|
|
|
|
/// - Slave (Ideology only): the Slave outfit, Simple food, No drugs. Reading stays unmanaged, because
|
|
|
|
|
/// slave children need books to learn; medical care stays unmanaged, so the game's default care for
|
2026-11-29 16:07:51 +00:00
|
|
|
/// slaves stays in charge. Seeded without Ideology, a save gets it on its first load with Ideology.
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// - Prisoner: Simple food.
|
|
|
|
|
/// Policies are found by their translated starting labels, No drugs by its source def. A miss leaves
|
2026-11-29 16:07:51 +00:00
|
|
|
/// the slot unmanaged; Castes never creates vanilla policies itself, with one exception: the Slave
|
|
|
|
|
/// caste a save gets on its first load with Ideology also gets the Slave outfit when the save has none
|
|
|
|
|
/// (AddSlaveCasteIfOwed).
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// Rows: bought as colonist and new colonist use Default caste (Colonist); bought as slave and new
|
|
|
|
|
/// slave use Slave; new prisoner uses Prisoner.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class StarterCastes
|
|
|
|
|
{
|
|
|
|
|
public const string NoDrugsSourceDef = "NoDrugs";
|
|
|
|
|
|
|
|
|
|
private static bool SettingOn => BlaxCastesMod.Settings == null || BlaxCastesMod.Settings.seedStarterCastes;
|
|
|
|
|
|
|
|
|
|
public static string ColonistLabel => "BlaxCastes_StarterColonist".Translate();
|
|
|
|
|
public static string SlaveLabel => "BlaxCastes_StarterSlave".Translate();
|
|
|
|
|
public static string PrisonerLabel => "BlaxCastes_StarterPrisoner".Translate();
|
|
|
|
|
|
|
|
|
|
// ---- policy lookups ------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
public static ApparelPolicy SlaveOutfit() => Current.Game?.outfitDatabase?.AllOutfits?.FirstOrDefault(o => o != null && o.label == (string)"OutfitSlave".Translate());
|
|
|
|
|
|
|
|
|
|
public static FoodPolicy SimpleFood() => Current.Game?.foodRestrictionDatabase?.AllFoodRestrictions?.FirstOrDefault(f => f != null && f.label == (string)"FoodRestrictionSimple".Translate());
|
|
|
|
|
|
|
|
|
|
public static DrugPolicy NoDrugs() => Current.Game?.drugPolicyDatabase?.AllPolicies?.FirstOrDefault(d => d?.sourceDef != null && d.sourceDef.defName == NoDrugsSourceDef);
|
|
|
|
|
|
|
|
|
|
/// <summary>True for the game's Slave outfit (by its starting label), which has no cold protection.</summary>
|
|
|
|
|
public static bool IsSlaveOutfit(Policy policy) => policy is ApparelPolicy a && a.label == (string)"OutfitSlave".Translate();
|
|
|
|
|
|
|
|
|
|
/// <summary>Ideology is active and the game has no Slave outfit (renamed or deleted): the manager offers to create one.</summary>
|
|
|
|
|
public static bool CanCreateSlaveOutfit => ModsConfig.IdeologyActive && Current.Game?.outfitDatabase != null && SlaveOutfit() == null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The manager's "Create Slave outfit" button: a new apparel policy named like the game's starting
|
|
|
|
|
/// Slave outfit that allows the apparel the game tags for slaves, the way a new game sets it up.
|
2026-11-29 16:07:51 +00:00
|
|
|
/// On the player's click, and for the Slave caste a save is owed (AddSlaveCasteIfOwed); other seeding
|
|
|
|
|
/// never creates policies. Returns the existing outfit if there is one, or null without Ideology.
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public static ApparelPolicy CreateSlaveOutfit()
|
|
|
|
|
{
|
|
|
|
|
if (!ModsConfig.IdeologyActive)
|
|
|
|
|
return null;
|
|
|
|
|
ApparelPolicy existing = SlaveOutfit();
|
|
|
|
|
OutfitDatabase db = Current.Game?.outfitDatabase;
|
|
|
|
|
if (existing != null || db == null)
|
|
|
|
|
return existing;
|
|
|
|
|
ApparelPolicy policy = db.MakeNewOutfit();
|
|
|
|
|
policy.label = "OutfitSlave".Translate();
|
|
|
|
|
policy.filter.SetDisallowAll();
|
|
|
|
|
if (SpecialThingFilterDefOf.AllowDeadmansApparel != null)
|
|
|
|
|
policy.filter.SetAllow(SpecialThingFilterDefOf.AllowDeadmansApparel, allow: false);
|
|
|
|
|
foreach (ThingDef def in DefDatabase<ThingDef>.AllDefs)
|
|
|
|
|
{
|
|
|
|
|
if (def.apparel?.defaultOutfitTags != null && def.apparel.defaultOutfitTags.Contains("Slave"))
|
|
|
|
|
policy.filter.SetAllow(def, allow: true);
|
|
|
|
|
}
|
|
|
|
|
return policy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- seeding -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A new game: adds the starter castes and wires the rows, unless the setting is off or the
|
|
|
|
|
/// component already has castes. Returns true if it seeded.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool SeedNewGame(GameComponent_BlaxCastes comp)
|
|
|
|
|
{
|
|
|
|
|
if (comp == null || !SettingOn || comp.StarterCastesSeeded)
|
|
|
|
|
return false;
|
|
|
|
|
if (comp.Castes.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
comp.MarkStarterCastesSeeded();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Seed(comp);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A loaded save: adds the starter castes once per save, only if the save has no castes. A save
|
|
|
|
|
/// that already has castes is marked, so deleting them later does not bring the starters back.
|
|
|
|
|
/// Nobody is moved. Returns true if it seeded.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool SeedOnLoad(GameComponent_BlaxCastes comp) => SeedNewGame(comp);
|
|
|
|
|
|
|
|
|
|
/// <summary>Creates the castes in the component and wires the rows. Writes the component directly, so it works on any component.</summary>
|
|
|
|
|
internal static void Seed(GameComponent_BlaxCastes comp)
|
|
|
|
|
{
|
|
|
|
|
Game game = Current.Game;
|
|
|
|
|
Caste colonist = NewCaste(comp, ColonistLabel);
|
|
|
|
|
SetIfFound(colonist, CasteSlot.Apparel, game?.outfitDatabase?.DefaultOutfit());
|
|
|
|
|
SetIfFound(colonist, CasteSlot.Food, game?.foodRestrictionDatabase?.DefaultFoodRestriction());
|
|
|
|
|
SetIfFound(colonist, CasteSlot.Drug, game?.drugPolicyDatabase?.DefaultDrugPolicy());
|
|
|
|
|
SetIfFound(colonist, CasteSlot.Reading, game?.readingPolicyDatabase?.DefaultReadingPolicy());
|
|
|
|
|
|
2026-11-29 16:07:51 +00:00
|
|
|
Caste slave = ModsConfig.IdeologyActive ? NewSlaveCaste(comp) : null;
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
|
|
|
|
|
Caste prisoner = NewCaste(comp, PrisonerLabel);
|
|
|
|
|
SetIfFound(prisoner, CasteSlot.Food, SimpleFood());
|
|
|
|
|
|
|
|
|
|
comp.SetDefaultRaw(colonist);
|
|
|
|
|
comp.SetRowRaw(JoinReason.BoughtColonist, JoinRowMode.DefaultCaste, null);
|
|
|
|
|
comp.SetRowRaw(JoinReason.NewColonist, JoinRowMode.DefaultCaste, null);
|
|
|
|
|
if (slave != null)
|
|
|
|
|
{
|
|
|
|
|
comp.SetRowRaw(JoinReason.BoughtSlave, JoinRowMode.SpecificCaste, slave);
|
|
|
|
|
comp.SetRowRaw(JoinReason.NewSlave, JoinRowMode.SpecificCaste, slave);
|
|
|
|
|
}
|
|
|
|
|
comp.SetRowRaw(JoinReason.NewPrisoner, JoinRowMode.SpecificCaste, prisoner);
|
|
|
|
|
comp.MarkStarterCastesSeeded();
|
2026-11-29 16:07:51 +00:00
|
|
|
// Without Ideology the Slave caste is owed: the first load with Ideology adds it (AddSlaveCasteIfOwed).
|
|
|
|
|
comp.SetSlaveCasteOwed(slave == null);
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
|
|
|
|
|
List<string> missing = new List<string>();
|
|
|
|
|
if (slave != null)
|
2026-11-29 16:07:51 +00:00
|
|
|
missing.AddRange(MissingSlaveSlots(slave));
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
if (!prisoner.IsManaged(CasteSlot.Food)) missing.Add(PrisonerLabel + ": " + CasteUtility.SlotLabel(CasteSlot.Food));
|
|
|
|
|
if (missing.Count > 0)
|
|
|
|
|
Log.Message("[Blax Castes] Starter castes added; policies not found (renamed or removed), left unmanaged: " + string.Join(", ", missing));
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-29 16:07:51 +00:00
|
|
|
/// <summary>The Slave caste: the Slave outfit, Simple food, No drugs, each where the game has it.</summary>
|
|
|
|
|
private static Caste NewSlaveCaste(GameComponent_BlaxCastes comp)
|
|
|
|
|
{
|
|
|
|
|
Caste slave = NewCaste(comp, SlaveLabel);
|
|
|
|
|
SetIfFound(slave, CasteSlot.Apparel, SlaveOutfit());
|
|
|
|
|
SetIfFound(slave, CasteSlot.Food, SimpleFood());
|
|
|
|
|
SetIfFound(slave, CasteSlot.Drug, NoDrugs());
|
|
|
|
|
return slave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<string> MissingSlaveSlots(Caste slave)
|
|
|
|
|
{
|
|
|
|
|
foreach (CasteSlot slot in new[] { CasteSlot.Apparel, CasteSlot.Food, CasteSlot.Drug })
|
|
|
|
|
{
|
|
|
|
|
if (!slave.IsManaged(slot))
|
|
|
|
|
yield return SlaveLabel + ": " + CasteUtility.SlotLabel(slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A save whose starter castes were added without Ideology, loaded with Ideology: adds the Slave caste
|
|
|
|
|
/// once, like a new game would have it, and picks it in the bought-as-slave and new-slave rows that are
|
|
|
|
|
/// still at No caste. The game makes its Slave outfit only in a new game with Ideology
|
|
|
|
|
/// (OutfitDatabase.GenerateStartingOutfits) and loads the saved outfit list over it, so such a save
|
|
|
|
|
/// usually has none: the new caste then gets one made like the game's (CreateSlaveOutfit), the one
|
|
|
|
|
/// policy Castes creates without a click. A caste already named Slave is used as it is instead of a
|
|
|
|
|
/// second one, and when both slave rows already pick a caste nothing is added. Nobody moves. Does
|
|
|
|
|
/// nothing while seedStarterCastes is off (the caste stays owed). Returns the caste the rows now pick, or null.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Caste AddSlaveCasteIfOwed(GameComponent_BlaxCastes comp)
|
|
|
|
|
{
|
|
|
|
|
if (comp == null || !comp.SlaveCasteOwed || !ModsConfig.IdeologyActive || !SettingOn)
|
|
|
|
|
return null;
|
|
|
|
|
comp.SetSlaveCasteOwed(false);
|
|
|
|
|
List<string> openRows = new[] { JoinReason.BoughtSlave, JoinReason.NewSlave }
|
|
|
|
|
.Where(r => comp.GetRow(r).mode == JoinRowMode.NoCaste).ToList();
|
|
|
|
|
if (openRows.Count == 0)
|
|
|
|
|
return null;
|
|
|
|
|
Caste slave = comp.Castes.FirstOrDefault(c => c != null && c.label == SlaveLabel);
|
|
|
|
|
if (slave == null)
|
|
|
|
|
{
|
|
|
|
|
if (SlaveOutfit() == null)
|
|
|
|
|
CreateSlaveOutfit();
|
|
|
|
|
slave = NewSlaveCaste(comp);
|
|
|
|
|
List<string> missing = MissingSlaveSlots(slave).ToList();
|
|
|
|
|
if (missing.Count > 0)
|
|
|
|
|
Log.Message("[Blax Castes] Slave caste added; policies not found (renamed or removed), left unmanaged: " + string.Join(", ", missing));
|
|
|
|
|
}
|
|
|
|
|
foreach (string row in openRows)
|
|
|
|
|
comp.SetRowRaw(row, JoinRowMode.SpecificCaste, slave);
|
|
|
|
|
return slave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The one message for a save that just got the Slave caste (AddSlaveCasteIfOwed).</summary>
|
|
|
|
|
public static void ShowSlaveCasteAddedMessage(Caste slave)
|
|
|
|
|
{
|
|
|
|
|
string text = "BlaxCastes_StarterSlaveAddedMessage".Translate(slave.label.Named("CASTE"));
|
|
|
|
|
LongEventHandler.ExecuteWhenFinished(() => Messages.Message(text, MessageTypeDefOf.NeutralEvent));
|
|
|
|
|
}
|
|
|
|
|
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
private static Caste NewCaste(GameComponent_BlaxCastes comp, string label)
|
|
|
|
|
{
|
|
|
|
|
var caste = new Caste(comp.TakeNextId(), label);
|
|
|
|
|
comp.AddCaste(caste);
|
|
|
|
|
return caste;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>No members exist yet, so the raw write needs no member sync.</summary>
|
|
|
|
|
private static void SetIfFound(Caste caste, CasteSlot slot, Policy policy)
|
|
|
|
|
{
|
|
|
|
|
if (policy != null && CasteUtility.PolicyExists(policy))
|
|
|
|
|
caste.SetSlotRaw(slot, policy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The one message for a save that just got the starter castes.</summary>
|
|
|
|
|
public static void ShowSeededMessage(GameComponent_BlaxCastes comp)
|
|
|
|
|
{
|
|
|
|
|
string text = SeededMessageText(comp);
|
|
|
|
|
LongEventHandler.ExecuteWhenFinished(() => Messages.Message(text, MessageTypeDefOf.NeutralEvent));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-11-29 12:09:10 +00:00
|
|
|
/// The seeding message. It points to Assign > Manage castes, or, while the Caste column is not in the
|
|
|
|
|
/// Assign tab (so that button is not there), to the mod settings, which open the same window. The
|
|
|
|
|
/// column is there as the game started (CasteColumns.Shown), whatever the setting says until a restart.
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public static string SeededMessageText(GameComponent_BlaxCastes comp)
|
|
|
|
|
{
|
|
|
|
|
string names = comp.Castes.Select(c => c.label).ToCommaList(useAnd: true);
|
2026-11-29 12:09:10 +00:00
|
|
|
string key = CasteColumns.Shown ? "BlaxCastes_StarterSeededMessage" : "BlaxCastes_StarterSeededMessageNoColumn";
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
return key.Translate(names.Named("CASTES"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|