Route

Overview

Represents a supply route from a Laboratory to a destination Region. Handles money gain, excess-production conversion (money/control/loyalty depending on mode & personality), maintenance, save/load of the node path, and toggling of the visual connection usage state. Also spawns a moving plane path along the first connection via UIPathPlaneSpawner. fileciteturn13file1

Serialized Atoms & Events

  • FloatVariable moneyPerUnit, currentMoney
  • FloatVariable controlGainPerStar, loyalty
  • BoolVariable controlToLoyaltyMode
  • IntVariable selectedPersonality, routeCount
  • FloatVariable routeMaintenanceCost
  • VoidEvent monthlyTick (registers ApplyMaintenanceCost) fileciteturn13file1

Other References

  • UIPathPlaneSpawner planeSpawner — animates a plane between start/end anchors. fileciteturn13file1

Runtime State & Properties

  • Region Destination { get; } — last node’s Region.
  • List<Node> NodeList { get; } — ordered node path.
  • List<NodeConnectionUI> Connections { get; }
  • int NodesTraversedConnections.Count
  • bool Paused — pausing the route’s logic & visuals; setter calls OnPauseChanged().
  • bool OriginLabPaused — if the lab is paused, this also pauses route visuals. fileciteturn13file1

Initialization

public void Init(List<Node> nodes)
  • Stores nodes and resolves Destination (last node’s Region).
  • Maps nodes → Connections = NodeMap.GetRouteConnections(nodes) and calls IncreaseActiveUsage() on each to light them up.
  • Configures the planeSpawner start/end anchors from the first/last node visualAnchor, reparents it under the first connection, and activates it.
  • Increments routeCount and registers to monthlyTick. fileciteturn13file1

Sending Production

public void SendProduction(float production)

Skips when Paused. Otherwise:

  • Earns money up to demand: currentMoney += min(production, Destination.LocalDemand) * moneyPerUnit.
  • For excess over demand:
    • If controlToLoyaltyMode == false:
      • Mobster → adds 50% of excess as extra money.
      • Subterfuge → increases Destination.Control by excess * controlGainPerStar (clamped to 1).
    • Else → increases Loyalty by the same factor (clamped to 1).
  • Marks Destination.Presence = true and accumulates Destination.SupplyPerTick += production. fileciteturn13file1

Maintenance

ApplyMaintenanceCost() subtracts routeMaintenanceCost on each monthly tick. fileciteturn13file1

Pause/Resume Visuals

OnPauseChanged() flips each connection’s usage counters so UI reflects inactive vs active state. Lab-level pauses set OriginLabPaused = true, which also enforces inactive visuals. fileciteturn13file1

Destruction

On OnDestroy():

  • Decreases the appropriate usage counter on every connection (active vs inactive depending on current paused state).
  • routeCount--, destroys planeSpawner, and unregisters from monthlyTick. fileciteturn13file1

Save / Load (IRuntimeSaveable)

  • OnSave(StringWriter): 1) Writes a standard header (PrefabType="Route", RegionId = parent lab name).
    2) Writes each node’s GameObject name on its own line.
  • OnLoad(StringReader): 1) Reads header and reparents this route under the Laboratory belonging to the saved Region.
    2) Looks up nodes by name, rebuilds the list, and calls Init(loadedNodes).
    3) Registers the route back into the lab via Laboratory.AddRoute(this). fileciteturn13file1

Integration Tips

  • To pause a route due to lab state, set route.OriginLabPaused = true instead of Paused to keep logic clear.
  • NodesTraversed can be used to compute building/refund costs based on distance. fileciteturn13file1