133 lines
4.4 KiB
C#
133 lines
4.4 KiB
C#
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace BlaxCastes
|
|
{
|
|
/// <summary>The five policy slots a caste can manage in 1.0.</summary>
|
|
public enum CasteSlot
|
|
{
|
|
Apparel,
|
|
Food,
|
|
Drug,
|
|
Reading,
|
|
MedCare,
|
|
}
|
|
|
|
/// <summary>
|
|
/// A bundle of policies. Ids, load IDs, rename and duplicate work the vanilla Policy way. A null
|
|
/// policy slot, or medCare -1, means the caste leaves that slot alone.
|
|
/// Read the slots freely; change them only through CasteManager.SetSlot, which keeps members in sync.
|
|
/// </summary>
|
|
public class Caste : Policy
|
|
{
|
|
public const int Unmanaged = -1;
|
|
|
|
private ApparelPolicy apparelPolicy;
|
|
private FoodPolicy foodPolicy;
|
|
private DrugPolicy drugPolicy;
|
|
private ReadingPolicy readingPolicy;
|
|
private int medCare = Unmanaged;
|
|
|
|
protected override string LoadKey => "BlaxCaste";
|
|
|
|
public Caste()
|
|
{
|
|
}
|
|
|
|
public Caste(int id, string label) : base(id, label)
|
|
{
|
|
}
|
|
|
|
public ApparelPolicy ApparelPolicy => apparelPolicy;
|
|
public FoodPolicy FoodPolicy => foodPolicy;
|
|
public DrugPolicy DrugPolicy => drugPolicy;
|
|
public ReadingPolicy ReadingPolicy => readingPolicy;
|
|
|
|
/// <summary>-1 (Unmanaged), otherwise a MedicalCareCategory.</summary>
|
|
public int MedCare => medCare;
|
|
|
|
public MedicalCareCategory? MedCareCategory => medCare < 0 ? (MedicalCareCategory?)null : (MedicalCareCategory)medCare;
|
|
|
|
/// <summary>The slot's value: a Policy, a boxed int for MedCare (-1 = unmanaged), or null.</summary>
|
|
public object GetSlot(CasteSlot slot)
|
|
{
|
|
switch (slot)
|
|
{
|
|
case CasteSlot.Apparel: return apparelPolicy;
|
|
case CasteSlot.Food: return foodPolicy;
|
|
case CasteSlot.Drug: return drugPolicy;
|
|
case CasteSlot.Reading: return readingPolicy;
|
|
case CasteSlot.MedCare: return medCare;
|
|
default: return null;
|
|
}
|
|
}
|
|
|
|
public bool IsManaged(CasteSlot slot)
|
|
{
|
|
if (slot == CasteSlot.MedCare)
|
|
return medCare >= 0;
|
|
return GetSlot(slot) != null;
|
|
}
|
|
|
|
public bool AnyManaged()
|
|
{
|
|
foreach (CasteSlot slot in CasteUtility.AllSlots)
|
|
{
|
|
if (IsManaged(slot))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>Raw write without member sync. Only CasteManager calls this.</summary>
|
|
internal void SetSlotRaw(CasteSlot slot, object value)
|
|
{
|
|
switch (slot)
|
|
{
|
|
case CasteSlot.Apparel:
|
|
apparelPolicy = value as ApparelPolicy;
|
|
break;
|
|
case CasteSlot.Food:
|
|
foodPolicy = value as FoodPolicy;
|
|
break;
|
|
case CasteSlot.Drug:
|
|
drugPolicy = value as DrugPolicy;
|
|
break;
|
|
case CasteSlot.Reading:
|
|
readingPolicy = value as ReadingPolicy;
|
|
break;
|
|
case CasteSlot.MedCare:
|
|
medCare = CasteUtility.ToMedCare(value);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>Copies every slot, not the id or the label (vanilla duplicate keeps the new policy's label).</summary>
|
|
public override void CopyFrom(Policy other)
|
|
{
|
|
if (other is Caste caste)
|
|
{
|
|
apparelPolicy = caste.apparelPolicy;
|
|
foodPolicy = caste.foodPolicy;
|
|
drugPolicy = caste.drugPolicy;
|
|
readingPolicy = caste.readingPolicy;
|
|
medCare = caste.medCare;
|
|
}
|
|
}
|
|
|
|
public override void ExposeData()
|
|
{
|
|
base.ExposeData();
|
|
Scribe_References.Look(ref apparelPolicy, "apparelPolicy");
|
|
Scribe_References.Look(ref foodPolicy, "foodPolicy");
|
|
Scribe_References.Look(ref drugPolicy, "drugPolicy");
|
|
Scribe_References.Look(ref readingPolicy, "readingPolicy");
|
|
Scribe_Values.Look(ref medCare, "medCare", Unmanaged);
|
|
if (Scribe.mode == LoadSaveMode.PostLoadInit)
|
|
medCare = CasteUtility.ToMedCare(medCare);
|
|
}
|
|
|
|
public override string ToString() => "Caste(" + id + ", " + label + ")";
|
|
}
|
|
}
|