Faction economy
How do NPC factions grow their economies during gameplay? Argon doesnβt just stand still β they expand when shortages appear, build new factories, and request more freighters. This is driven by factionlogic_economy.xml β ~4100 lines of MD running per-faction tick logic.
This overview explains the shortage β evaluation β corrective action loop that makes NPC economies dynamic.
The loop
Section titled βThe loopββββββββββββββββββββββββββββββββββββββββββββββ Per-faction tick (every N minutes) ββ β EvaluateShortages βββββββββββββββββββ¬ββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββ EvaluateShortages ββ - Iterate faction sectors ββ - Read demand vs supply per ware ββ - Compute shortage scores βββββββββββββββββββ¬ββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββ Per-sector evaluation ββ β EvaluateSectorShortage ββ - Which wares are short? ββ - Which station type can fix? βββββββββββββββββββ¬ββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββ Pick corrective action ββ (one of N Request_X cues) βββββββββββββββββββ¬ββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββ Request_X runs ββ - Find suitable site ββ - Issue build / spawn / etc. ββ - Wait for outcome βββββββββββββββββββ¬ββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββ Outcome handler ββ - Built / disregarded / destroyed ββ - Update faction state βββββββββββββββββββββββββββββββββββββββββββββEvaluateShortages β the trigger
Section titled βEvaluateShortages β the triggerβThe top-level cue EvaluateShortages runs per-faction on a heartbeat. It walks the factionβs sectors, reading ware demand and supply data, and identifies sectors where supply lags demand.
For each affected sector, it dispatches to EvaluateSectorShortage which determines:
- Which wares are short
- Which station-type (production factory, shipyard, defence station) can address the shortage
- Whether the faction has resources / budget to act
Corrective actions (the Request_X cues)
Section titled βCorrective actions (the Request_X cues)βWhen a shortage is identified, vanilla picks one of several Request_X actions:
| Action cue | What it does |
|---|---|
Request_Production_Module | Add a production module to an existing factory |
Request_Freighter | Spawn a new transport ship to cover supply |
Request_Commandeerable_Freighter | Spawn a freighter that the player can capture (balance lever) |
| (and others) | New station construction, defence reinforcement, etc. |
Each Request_X is a substantial sub-cue with _Disregarded, _Destroyed, _Started, _Built, _Spawned, _Not_Requested sub-handlers. The state machine tracks:
- Disregard (faction decided not to act after all)
- Destruction (the requested asset was destroyed before completion)
- Successful build / spawn
The verbose _Disregarded handling reflects that NPC economy decisions are tentative β many factors can cancel a planned build (faction goes hostile, budget changes, sector ownership flips).
Per-sector heuristics
Section titled βPer-sector heuristicsβEvaluateSectorShortage reads several signals:
| Signal | Source | Indicates |
|---|---|---|
Container.cargo.{ware}.target - .amount | Per-station target deficit | How much is missing |
iswaitingforresources on production modules | Build module state | Supply chain stalled |
iswaitingforstorage on production modules | Build module state | Output backed up |
Sector.yieldrating.{ware} | Sector data | Mining capacity |
The heuristic isnβt pure shortage β it combines stalled state, deficit, and capability (does the sector have resources for the missing ware).
Why this matters for modders
Section titled βWhy this matters for moddersβDonβt break this loop
Section titled βDonβt break this loopβCustom mods that touch production modules (paused state, custom cargo) can confuse the shortage evaluator. Vanillaβs EvaluateSectorShortage reads iswaitingforresources and iswaitingforstorage directly β pause your custom modules with <set_production_paused> rather than alternative mechanisms.
Faction expansion adds to constructionplans
Section titled βFaction expansion adds to constructionplansβWhen Request_Production_Module decides to build, it ultimately calls into the Construction sequence pipeline. Custom plans in constructionplans.xml are eligible β your modβs plans are real options for NPC factions.
NPC factions ignore non-vanilla wares by default
Section titled βNPC factions ignore non-vanilla wares by defaultβIf your mod adds new wares, NPC factions donβt know to demand them. To integrate:
- Add wares to faction-relevant production chains
- Update
factionlogicdata so faction recognises ware demand - Or accept that only player stations produce/consume new wares
Performance impact
Section titled βPerformance impactβEvaluateShortages runs per-faction per-tick across all sectors. Mods that add many factions or many sectors can multiply this cost. The vanilla tick interval is tuned for ~10 factions; adding more without adjusting the interval impacts CPU.
Vanilla file structure
Section titled βVanilla file structureβfactionlogic_economy.xml (4103 lines) organises like:
factionlogic_economy.xmlβββ Manage_Stations (top-level state machine)β βββ EvaluateShortages (heartbeat)β β βββ EvaluateSectorShortage (per-sector)β βββ Request_Production_Moduleβ β βββ Request_Production_Module_Generate_Sequenceβ β βββ Request_Production_Module_Sequence_Generatedβ β βββ Request_Production_Module_Disregardedβ β βββ Request_Production_Module_Startedβ β βββ Request_Production_Module_Evaluate_Buildβ βββ Request_Freighterβ β βββ Request_Freighter_Spawnedβ β βββ Request_Freighter_Disregardedβ β βββ Request_Freighter_Destroyedβ β βββ Request_Freighter_Builtβ β βββ Request_Freighter_Not_Requestedβ βββ Request_Commandeerable_Freighter (similar)βββ (additional cues for support / cleanup)The Disregard / Destroyed / Built handler pattern is consistent across all Request_X actions. Custom mods extending this should follow the same shape.
Cross-references
Section titled βCross-referencesβ- Production module β what the loop manages
- Storage module β
iswaitingforstoragesignal source - Production factory β the station type
- Build module β what builds new modules
- Faction β owner of the economy
- Sector β
yieldratingdata source - constructionplans.xml β modder-extensible build catalogue
Related architectural overviews
Section titled βRelated architectural overviewsβ- Galaxy seeding β initial state before this loop runs
- Construction sequence β what
Request_Production_Modulecalls into - Faction goals β the layer ABOVE economy (which decides hold / invade / patrol)
- Trade routing β separate but related ware-distribution system