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. fileciteturn13file1
Serialized Atoms & Events
- FloatVariable
moneyPerUnit,currentMoney - FloatVariable
controlGainPerStar,loyalty - BoolVariable
controlToLoyaltyMode - IntVariable
selectedPersonality,routeCount - FloatVariable
routeMaintenanceCost - VoidEvent
monthlyTick(registersApplyMaintenanceCost) fileciteturn13file1
Other References
- UIPathPlaneSpawner
planeSpawner— animates a plane between start/end anchors. fileciteturn13file1
Runtime State & Properties
Region Destination { get; }— last node’s Region.List<Node> NodeList { get; }— ordered node path.List<NodeConnectionUI> Connections { get; }int NodesTraversed—Connections.Countbool Paused— pausing the route’s logic & visuals; setter callsOnPauseChanged().bool OriginLabPaused— if the lab is paused, this also pauses route visuals. fileciteturn13file1
Initialization
public void Init(List<Node> nodes)
- Stores nodes and resolves
Destination(last node’sRegion). - Maps nodes →
Connections = NodeMap.GetRouteConnections(nodes)and callsIncreaseActiveUsage()on each to light them up. - Configures the
planeSpawnerstart/end anchors from the first/last nodevisualAnchor, reparents it under the first connection, and activates it. - Increments
routeCountand registers tomonthlyTick. fileciteturn13file1
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.Controlbyexcess * controlGainPerStar(clamped to 1).
- Else → increases Loyalty by the same factor (clamped to 1).
- If
- Marks
Destination.Presence = trueand accumulatesDestination.SupplyPerTick += production. fileciteturn13file1
Maintenance
ApplyMaintenanceCost() subtracts routeMaintenanceCost on each monthly tick. fileciteturn13file1
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. fileciteturn13file1
Destruction
On OnDestroy():
- Decreases the appropriate usage counter on every connection (active vs inactive depending on current paused state).
routeCount--, destroysplaneSpawner, and unregisters frommonthlyTick. fileciteturn13file1
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 callsInit(loadedNodes).
3) Registers the route back into the lab viaLaboratory.AddRoute(this). fileciteturn13file1
Integration Tips
- To pause a route due to lab state, set
route.OriginLabPaused = trueinstead ofPausedto keep logic clear. NodesTraversedcan be used to compute building/refund costs based on distance. fileciteturn13file1