feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Verse;
|
|
|
|
|
|
|
|
|
|
namespace BlaxCastes
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Where a join happens, as a stack of scopes. A hook pushes a scope in a prefix and pops it in a
|
|
|
|
|
/// Harmony finalizer, so an exception inside the scope never leaves the stack dirty. When a pawn's
|
|
|
|
|
/// status changes, the innermost scope that covers the pawn names the join reason; without one,
|
|
|
|
|
/// the reason is the status fallback, resolved from the final status when the join is applied.
|
|
|
|
|
/// Only touched from the main thread.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class JoinScopes
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Pawn.PreTraded while the player buys. Resolves to bought as slave or bought as colonist.</summary>
|
|
|
|
|
public const string Bought = "bought";
|
|
|
|
|
|
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>
|
|
|
|
|
/// Pawn.PreTraded while the player sells. Status changes inside it queue nothing (selling a slave
|
|
|
|
|
/// briefly frees it before the faction changes); the sale itself writes the former-caste record.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const string Sold = "sold";
|
|
|
|
|
|
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
|
|
|
private struct Scope
|
|
|
|
|
{
|
|
|
|
|
public string reason;
|
|
|
|
|
public Pawn pawn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly List<Scope> stack = new List<Scope>();
|
|
|
|
|
|
|
|
|
|
/// <summary>Open scopes. 0 outside every hooked call.</summary>
|
|
|
|
|
public static int Depth => stack.Count;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens a scope. With a pawn it covers only that pawn, without one it covers every pawn.
|
|
|
|
|
/// Returns the token Pop needs.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int Push(string reason, Pawn pawn = null)
|
|
|
|
|
{
|
|
|
|
|
stack.Add(new Scope { reason = reason, pawn = pawn });
|
|
|
|
|
return stack.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Closes the scope the token came from and any scope opened inside it that was not closed.
|
|
|
|
|
/// Token 0 (nothing was pushed) does nothing.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void Pop(int token)
|
|
|
|
|
{
|
|
|
|
|
if (token <= 0 || token > stack.Count)
|
|
|
|
|
return;
|
|
|
|
|
stack.RemoveRange(token - 1, stack.Count - token + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The reason of the innermost scope that covers the pawn, or null.</summary>
|
|
|
|
|
public static string ReasonFor(Pawn pawn)
|
|
|
|
|
{
|
|
|
|
|
for (int i = stack.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (stack[i].pawn == null || stack[i].pawn == pawn)
|
|
|
|
|
return stack[i].reason;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|