using System.Text; using RimWorld; using UnityEngine; using Verse; namespace BlaxZones { /// /// A delivery zone: a landing pad for drop pods (design: "Delivery zone"). Saved inside /// MapComponent_BlaxZones, never in ZoneManager (design: "Zone store, safe to remove from a save"). /// /// This file holds the data model, saving and the cache notifications (integrator). The tab and /// copy/paste gizmos are in Zone_Delivery.Tab.cs (package Tab), the expand designator in /// Zone_Delivery.Designators.cs (package Designators). /// public partial class Zone_Delivery : Zone { /// Amber at the vanilla zone opacity (ZoneColorUtility.ZoneOpacity, 0.09). public static readonly Color ZoneColor = new Color(1f, 0.70f, 0.10f, 0.09f); /// The designator icon tint (defaultIconColor), amber at full opacity. public static readonly Color IconColor = new Color(1f, 0.70f, 0.10f, 1f); /// What may land here. Always a child of DeliveryFilters.Parent. public ThingFilter filter; /// Higher priority zones are tried first; ties go to the lower zone ID. public StoragePriority priority = StoragePriority.Normal; /// Orbital trade purchases, sale silver and ZonesApi callers (Blax Slaves payouts) may land here. public bool acceptOrbital = true; /// Item rewards from quests may land here (1.1). public bool acceptRewards = true; /// Goods bought from trader caravans and Hospitality guests may appear here (1.1). public bool acceptCaravan = true; /// Trader caravans and tribute collectors camp next to this zone. public bool campHere; protected override Color NextZoneColor => ZoneColor; /// The map, or null while the zone is loaded but not yet registered (zoneManager unset). public Map MapOrNull => zoneManager?.map; public Zone_Delivery() { } public Zone_Delivery(ZoneManager zoneManager) : base("BlaxZones_DeliveryZone".Translate(), zoneManager) { filter = DeliveryFilters.NewDefaultFilter(); } public override void ExposeData() { base.ExposeData(); Scribe_Deep.Look(ref filter, "filter"); Scribe_Values.Look(ref priority, "priority", StoragePriority.Normal); Scribe_Values.Look(ref acceptOrbital, "acceptOrbital", true); Scribe_Values.Look(ref acceptRewards, "acceptRewards", true); Scribe_Values.Look(ref acceptCaravan, "acceptCaravan", true); Scribe_Values.Look(ref campHere, "campHere", false); if (Scribe.mode == LoadSaveMode.PostLoadInit) { filter ??= DeliveryFilters.NewDefaultFilter(); if (priority == StoragePriority.Unstored) priority = StoragePriority.Normal; } } /// Whether this zone takes deliveries from the source (its checkbox). public bool AcceptsSource(DeliverySource source) { switch (source) { case DeliverySource.Orbital: return acceptOrbital; case DeliverySource.Rewards: return acceptRewards; case DeliverySource.Caravan: return acceptCaravan; default: return false; } } /// The zone's own filter plus the never-routed refusals. Not the cell rules. public bool Accepts(Thing thing) { if (DeliveryFilters.NeverRouted(thing)) return false; return filter == null || filter.Allows(thing); } /// Copies the player's choices (filter, priority, sources, camp) from another zone. Never the cells. public void CopySettingsFrom(Zone_Delivery other) { if (other == null || other == this) return; filter ??= new ThingFilter(); if (other.filter != null) filter.CopyAllowancesFrom(other.filter); priority = other.priority; acceptOrbital = other.acceptOrbital; acceptRewards = other.acceptRewards; acceptCaravan = other.acceptCaravan; campHere = other.campHere; } public override void AddCell(IntVec3 c) { base.AddCell(c); MapComponent_BlaxZones.Of(MapOrNull)?.Notify_ZoneCellsChanged(this); } public override void RemoveCell(IntVec3 c) { Map map = MapOrNull; base.RemoveCell(c); MapComponent_BlaxZones.Of(map)?.Notify_ZoneCellsChanged(this); } public override void PostDeregister() { Map map = MapOrNull; base.PostDeregister(); MapComponent_BlaxZones.Of(map)?.Notify_ZoneRemoved(this); } public override string GetInspectString() { var sb = new StringBuilder(base.GetInspectString() ?? ""); try { MapComponent_BlaxZones comp = MapComponent_BlaxZones.Of(MapOrNull); string rules = comp?.InspectLineFor(this); if (!rules.NullOrEmpty()) { if (sb.Length > 0) sb.AppendLine(); sb.Append(rules); } } catch (System.Exception e) { ZonesLog.Once("Delivery zone inspect string", e); } return sb.ToString(); } } }