76 lines
3.4 KiB
C#
76 lines
3.4 KiB
C#
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace BlaxZones
|
|
{
|
|
/// <summary>
|
|
/// Package Rewards. Trade Ships Drop Spot (Workshop 1969732297, package id smashphil.dropspot) moves
|
|
/// both orbital drops and quest rewards to its marker. With 1.1 Zones covers both, so a one-time
|
|
/// message says the player can unsubscribe (design: 1.1 "Quest rewards land in the zone", Unsubscribe
|
|
/// hint). Detected by its marker def, read from github.com/SmashPhil/TradeShips-Drop-Spot,
|
|
/// Defs/DropSpotIndicator.xml (checked 2026-11-30): ThingDef "DropSpotTradeShip". The mod isn't installed
|
|
/// on the test machine; tests simulate the def through Compat.SimulatedActive.
|
|
/// </summary>
|
|
public static partial class Compat
|
|
{
|
|
/// <summary>Trade Ships Drop Spot's marker ThingDef.</summary>
|
|
public const string TradeShipsDropSpotDef = "DropSpotTradeShip";
|
|
|
|
/// <summary>Defs never change after startup, so the lookup runs once.</summary>
|
|
private static bool? tradeShipsDropSpotDefLoaded;
|
|
|
|
/// <summary>The marker def exists (the mod is active), or a test simulates it.</summary>
|
|
public static bool TradeShipsDropSpotActive
|
|
{
|
|
get
|
|
{
|
|
if (SimulatedActive.Count > 0 && SimulatedActive.Contains(TradeShipsDropSpotDef))
|
|
return true;
|
|
tradeShipsDropSpotDefLoaded ??= DefDatabase<ThingDef>.GetNamedSilentFail(TradeShipsDropSpotDef) != null;
|
|
return tradeShipsDropSpotDefLoaded.Value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The unsubscribe hint for Trade Ships Drop Spot: shown once, ever, on a map tick once the map has a
|
|
/// delivery zone, while "Route orbital trade" and "Route quest rewards" are both on. Before the
|
|
/// player makes a delivery zone Zones routes nothing, so the advice would be wrong. "Shown" is kept
|
|
/// in the mod settings file (BlaxZonesSettings.tradeShipsHintShown), so nothing enters a save and the
|
|
/// hint doesn't come back on the next load or game.
|
|
/// </summary>
|
|
public static class TradeShipsDropSpotHint
|
|
{
|
|
/// <summary>The mod is active and Zones routes everything it would place.</summary>
|
|
public static bool Applies =>
|
|
BlaxZonesMod.S.routeOrbital && BlaxZonesMod.S.routeRewards && Compat.TradeShipsDropSpotActive;
|
|
|
|
/// <summary>The hint text, also logged.</summary>
|
|
public static string Text => "BlaxZones_TradeShipsDropSpotHint".Translate();
|
|
|
|
/// <summary>Called on every map tick. After the hint was shown it costs one bool read.</summary>
|
|
public static void Check(Map map)
|
|
{
|
|
if (BlaxZonesMod.S.tradeShipsHintShown || !Applies || !DeliveryRouter.HasDeliveryZone(map))
|
|
return;
|
|
Show();
|
|
}
|
|
|
|
/// <summary>Shows the message, logs it and remembers it in the mod settings.</summary>
|
|
private static void Show()
|
|
{
|
|
BlaxZonesMod.S.tradeShipsHintShown = true;
|
|
BlaxZonesMod.SaveSettings();
|
|
string text = Text;
|
|
Messages.Message(text, MessageTypeDefOf.NeutralEvent, historical: true);
|
|
Log.Message("[Blax Zones] " + text);
|
|
}
|
|
|
|
/// <summary>Forgets that the hint was shown, so the next check may show it again. Tests only.</summary>
|
|
public static void Reset()
|
|
{
|
|
BlaxZonesMod.S.tradeShipsHintShown = false;
|
|
}
|
|
}
|
|
}
|