using System; using RimWorld; using Verse; namespace BlaxLaws { /// /// Laws works with any DLC combination, core only included (design: "DLC support"). This class names /// where a def comes from, says what a missing catalogue entry needs, and guards every read of DLC-only /// pawn state behind ModsConfig.<DLC>Active. ModLister.Check<DLC> is an install check, not an /// active check, and is never used. /// public static class DlcSupport { public const string CoreName = "Core"; public const string CorePackageId = "ludeon.rimworld"; private const string OfficialPrefix = "ludeon.rimworld."; /// The official DLCs by name, in release order. public static readonly string[] DlcNames = { "Royalty", "Ideology", "Biotech", "Anomaly", "Odyssey" }; // ---- where a def comes from --------------------------------------------------------- /// "Core", the DLC's name ("Ideology") or the mod's name, as the catalogue shows it. public static string SourceName(ModContentPack mod) { if (mod == null || mod.IsCoreMod) return CoreName; if (IsDlcPackageId(mod.PackageId)) return DlcName(mod.PackageId); return mod.Name.NullOrEmpty() ? mod.PackageIdPlayerFacing : mod.Name; } /// The package id a catalogue entry saves with a row, lower case. Core for a def without a mod. public static string SourcePackageId(ModContentPack mod) => mod?.PackageId ?? CorePackageId; /// True for "ludeon.rimworld.royalty" and the other official DLCs, false for Core and mods. public static bool IsDlcPackageId(string packageId) => !packageId.NullOrEmpty() && packageId.ToLowerInvariant().StartsWith(OfficialPrefix); /// "ludeon.rimworld.royalty" to "Royalty". public static string DlcName(string packageId) { if (packageId.NullOrEmpty()) return packageId; string id = packageId.ToLowerInvariant(); return (id.StartsWith(OfficialPrefix) ? id.Substring(OfficialPrefix.Length) : id).CapitalizeFirst(); } /// /// The official DLC a saved row's source names, by package id or by name ("Ideology"), or null for /// Core and mods. /// public static string DlcOf(string savedMod, string savedPackageId) { if (IsDlcPackageId(savedPackageId)) return DlcName(savedPackageId); foreach (string dlc in DlcNames) { if (string.Equals(dlc, savedMod, StringComparison.OrdinalIgnoreCase)) return dlc; } return null; } /// Whether the official DLC of this name is active. False for an unknown name. public static bool IsDlcActive(string dlcName) { switch (dlcName?.ToLowerInvariant()) { case "royalty": return ModsConfig.RoyaltyActive; case "ideology": return ModsConfig.IdeologyActive; case "biotech": return ModsConfig.BiotechActive; case "anomaly": return ModsConfig.AnomalyActive; case "odyssey": return ModsConfig.OdysseyActive; default: return false; } } /// "Needs Ideology". public static string NeedsText(string dlcName) => "BlaxLaws_NeedsDlc".Translate(dlcName); /// /// What a row whose entry is missing shows: "Needs <DLC>" for a DLC source, else /// "Missing: <mod>" (design: "A missing entry from a DLC shows Needs <DLC>"). /// public static string MissingText(string savedMod, string savedPackageId) { string dlc = DlcOf(savedMod, savedPackageId); if (dlc != null) return NeedsText(dlc); string mod = !savedMod.NullOrEmpty() ? savedMod : !savedPackageId.NullOrEmpty() ? savedPackageId : CoreName; return "BlaxLaws_MissingMod".Translate(mod); } // ---- DLC-only pawn state, always behind the active check ------------------------------ /// A slave (Ideology). public static bool IsSlave(Pawn p) => ModsConfig.IdeologyActive && p != null && p.IsSlave; /// A child, never beaten (Biotech). public static bool IsChild(Pawn p) => ModsConfig.BiotechActive && p != null && p.DevelopmentalStage.Child(); /// Holds an ideoligion role, which an arrest takes (Ideology; Precept_Role.cs:582-585). public static bool HoldsRole(Pawn p) => ModsConfig.IdeologyActive && p?.Ideo != null && p.Ideo.GetRole(p) != null; /// A mechanitor that controls mechs, which an arrest shuts down (Biotech; Pawn_GuestTracker.cs:536-539). public static bool IsMechanitorWithMechs(Pawn p) => ModsConfig.BiotechActive && p?.mechanitor != null && MechanitorUtility.IsMechanitor(p) && p.mechanitor.ControlledPawns.Count > 0; /// /// Laws doesn't jail this pawn on its own while "Release gives back what jail took" isn't built or is /// off: the case waits with "Arrest now" (design: "Jail for N days", hold). /// public static bool HeldForArrestNow(Pawn p) => HoldsRole(p) || IsMechanitorWithMechs(p); } }