using System.Collections.Generic;
using Verse;
namespace BlaxCastes
{
///
/// A pawn's place in the caste system. Caste null means "casteless by choice": the player (or a
/// deleted caste) took the pawn out, and later safety nets leave it alone. A pawn with no record at
/// all never had a caste.
///
public class CasteMembership : IExposable
{
public Caste caste;
/// True when a join row set it, false when the player did.
public bool auto;
public string reason;
public int tick;
public CasteMembership()
{
}
public CasteMembership(Caste caste, bool auto, string reason, int tick)
{
this.caste = caste;
this.auto = auto;
this.reason = reason;
this.tick = tick;
}
public bool Casteless => caste == null;
public void ExposeData()
{
Scribe_References.Look(ref caste, "caste");
Scribe_Values.Look(ref auto, "auto");
Scribe_Values.Look(ref reason, "reason");
Scribe_Values.Look(ref tick, "tick");
}
}
public enum JoinRowMode
{
NoCaste,
DefaultCaste,
SpecificCaste,
}
/// What a way of joining does: no caste, the default caste, or one specific caste.
public class JoinRow : IExposable
{
public string reason;
public JoinRowMode mode = JoinRowMode.NoCaste;
/// Only used with SpecificCaste.
public Caste caste;
public JoinRow()
{
}
public JoinRow(string reason)
{
this.reason = reason;
}
public void ExposeData()
{
Scribe_Values.Look(ref reason, "reason");
Scribe_Values.Look(ref mode, "mode", JoinRowMode.NoCaste);
Scribe_References.Look(ref caste, "caste");
}
}
/// A join waiting for the next tick. Filled and applied by JoinDefaults.
public class QueuedJoin : IExposable
{
public Pawn pawn;
public string reason;
public int tick;
///
/// The pawn's membership when the join was last queued (not saved). A different membership at
/// apply time means the player picked a caste after the join was queued, even within one tick.
/// After a load, the ticks decide instead.
///
public CasteMembership seen;
public bool seenKnown;
public QueuedJoin()
{
}
public QueuedJoin(Pawn pawn, string reason, int tick)
{
this.pawn = pawn;
this.reason = reason;
this.tick = tick;
}
public void ExposeData()
{
Scribe_References.Look(ref pawn, "pawn");
Scribe_Values.Look(ref reason, "reason");
Scribe_Values.Look(ref tick, "tick");
}
}
///
/// The caste a pawn had when it left the player side, was sold or became a prisoner, or "No caste"
/// when it was casteless by choice. Keyed by ThingID in GameComponent_BlaxCastes, so a discarded pawn
/// leaves no unresolved reference. The caste and the policies are stored by id for the same reason.
/// If the pawn comes back within formerCasteDays with the same status (colonist or slave), it gets
/// that caste (or No caste) back instead of its join row's, and its own settings from when it left
/// (JoinDefaults.Restore): the slots it followed get the caste's current value, the ones it had
/// changed by hand get that value back.
///
public class FormerCaste : IExposable
{
public int casteId = Caste.Unmanaged;
/// The pawn was casteless by choice; casteId is unused.
public bool casteless;
/// Colonist or Slave: the status the pawn had in that caste.
public JoinSide side;
/// The membership's auto flag, restored with the caste.
public bool auto;
public int tick;
// The pawn's own settings just before it left; -1 or null where it had none.
public int apparelId = Caste.Unmanaged;
public int foodId = Caste.Unmanaged;
public int drugId = Caste.Unmanaged;
public int readingId = Caste.Unmanaged;
public int medCare = Caste.Unmanaged;
public int loadoutId = Caste.Unmanaged;
public List schedule;
/// Every work type's priority, as the game read it.
public Dictionary work;
/// The caste's managed slots where the pawn had the caste's value when it left.
public List followed = new List();
/// The work types the caste decides where the pawn had the caste's value when it left.
public List followedWork = new List();
public FormerCaste()
{
}
public FormerCaste(int casteId, JoinSide side, bool auto, int tick)
{
this.casteId = casteId;
this.side = side;
this.auto = auto;
this.tick = tick;
}
/// The pawn followed the caste's value for this slot when it left.
public bool Followed(CasteSlot slot) => followed != null && followed.Contains(slot);
public bool FollowedWork(string defName) => followedWork != null && followedWork.Contains(defName);
public void ExposeData()
{
Scribe_Values.Look(ref casteId, "casteId", Caste.Unmanaged);
Scribe_Values.Look(ref casteless, "casteless");
Scribe_Values.Look(ref side, "side", JoinSide.None);
Scribe_Values.Look(ref auto, "auto");
Scribe_Values.Look(ref tick, "tick");
Scribe_Values.Look(ref apparelId, "apparelId", Caste.Unmanaged);
Scribe_Values.Look(ref foodId, "foodId", Caste.Unmanaged);
Scribe_Values.Look(ref drugId, "drugId", Caste.Unmanaged);
Scribe_Values.Look(ref readingId, "readingId", Caste.Unmanaged);
Scribe_Values.Look(ref medCare, "medCare", Caste.Unmanaged);
Scribe_Values.Look(ref loadoutId, "loadoutId", Caste.Unmanaged);
Scribe_Collections.Look(ref schedule, "schedule", LookMode.Value);
Scribe_Collections.Look(ref work, "work", LookMode.Value, LookMode.Value);
Scribe_Collections.Look(ref followed, "followed", LookMode.Value);
Scribe_Collections.Look(ref followedWork, "followedWork", LookMode.Value);
if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
followed ??= new List();
followedWork ??= new List();
}
}
public override string ToString() =>
"FormerCaste(" + (casteless ? "no caste" : casteId.ToString()) + ", " + side + ", tick " + tick + ")";
}
/// Reason strings stored in memberships, join rows and the join queue.
public static class JoinReason
{
// The five join rows in 1.0.
public const string BoughtSlave = "boughtSlave";
public const string BoughtColonist = "boughtColonist";
public const string NewColonist = "newColonist";
public const string NewSlave = "newSlave";
public const string NewPrisoner = "newPrisoner";
// Reasons that are not join rows.
public const string Manual = "manual";
public const string CasteDeleted = "casteDeleted";
/// A returning pawn got back the caste it had before it left (FormerCaste).
public const string PreviousCaste = "previousCaste";
/// The join rows in display order.
public static readonly string[] Rows = { BoughtSlave, BoughtColonist, NewColonist, NewSlave, NewPrisoner };
public static bool IsRow(string reason)
{
for (int i = 0; i < Rows.Length; i++)
{
if (Rows[i] == reason)
return true;
}
return false;
}
}
}