2026-11-29 18:27:08 +00:00
|
|
|
using System;
|
|
|
|
|
using Verse;
|
|
|
|
|
|
|
|
|
|
namespace BlaxZones
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// All Blax state of one map (design: "Zone store, safe to remove from a save"): our zones while
|
|
|
|
|
/// saving and loading, and every cache. No Blax zone or field ever enters a vanilla save list.
|
|
|
|
|
/// ZoneManager stays the only zone registry while the game runs; this component keeps no zone list.
|
|
|
|
|
///
|
|
|
|
|
/// Zones' own code never creates this component: vanilla's Map.FillComponents adds it. Every
|
|
|
|
|
/// patch reads it with Of(map) and routes to vanilla on null.
|
|
|
|
|
///
|
|
|
|
|
/// The class is split by owner. This file (integrator) wires the MapComponent overrides to the
|
|
|
|
|
/// package parts:
|
|
|
|
|
/// - MapComponent_BlaxZones.Store.cs (Store): ExposeStore, the loaded-zone list, RegisterLoadedZones.
|
|
|
|
|
/// - MapComponent_BlaxZones.Rules.cs (Rules): reach cache per district, unusable cells per zone,
|
|
|
|
|
/// the red overlay, the inspect line.
|
|
|
|
|
/// - MapComponent_BlaxZones.Router.cs (Router): cell order per zone.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MapComponent_BlaxZones : MapComponent
|
|
|
|
|
{
|
|
|
|
|
public MapComponent_BlaxZones(Map map) : base(map)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The map's component, or null (no map, or Zones was removed from this game).</summary>
|
|
|
|
|
public static MapComponent_BlaxZones Of(Map map) => map?.GetComponent<MapComponent_BlaxZones>();
|
|
|
|
|
|
|
|
|
|
public override void ExposeData()
|
|
|
|
|
{
|
|
|
|
|
base.ExposeData();
|
|
|
|
|
ExposeStore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void FinalizeInit()
|
|
|
|
|
{
|
|
|
|
|
base.FinalizeInit();
|
|
|
|
|
ZonesLog.ResetOnce();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ClearRouterCaches();
|
|
|
|
|
ClearRuleCaches();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ZonesLog.Once("Map init", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void MapComponentTick()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
TickRules();
|
2026-11-30 21:33:40 +00:00
|
|
|
TradeShipsDropSpotHint.Check(map);
|
2026-11-29 18:27:08 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ZonesLog.Once("Map tick", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void MapComponentUpdate()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
UpdateOverlay();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ZonesLog.Once("Zone overlay", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Drops caches only. Never deletes or deregisters zones of the removed map; vanilla doesn't either.</summary>
|
|
|
|
|
public override void MapRemoved()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ClearRouterCaches();
|
|
|
|
|
ClearRuleCaches();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ZonesLog.Once("Map removal", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Called by Zone_Delivery.AddCell and RemoveCell.</summary>
|
|
|
|
|
public void Notify_ZoneCellsChanged(Zone_Delivery zone)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DropRouterCaches(zone);
|
|
|
|
|
DropRuleCaches(zone);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ZonesLog.Once("Zone cell change", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Called by Zone_Delivery.PostDeregister: the zone left ZoneManager, drop everything keyed by it.</summary>
|
|
|
|
|
public void Notify_ZoneRemoved(Zone_Delivery zone)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DropRouterCaches(zone);
|
|
|
|
|
DropRuleCaches(zone);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ZonesLog.Once("Zone removal", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|