Station
A Station is a persistent structure in space owned by a faction. Stations contain modules (production, docks, defence, habitation), employ NPCs, trade wares, and serve as hubs for ship operations.
Subtypes: Shipyard, Wharf, Equipment Dock, Trade Station, Defence Station, Production Factory, Pirate Base, Player Headquarters.
Contains: Modules, Dockareas, Build plot.
Properties
Section titled “Properties”Most common accessors used by vanilla MD scripts and mods.
| Property | Type | Description |
|---|---|---|
.faction / .owner | faction | Current owning faction |
.trueowner | faction | True owner — differs from .faction during boarding/capture |
.knownname | string | Display name |
.sector | sector | Containing Sector |
.zone | zone | Containing Zone |
.modules | list | All Modules of this station |
.container | container | Aggregate inventory and value |
.container.value | int (Cr) | Total value of modules + drones |
.cargo | container | Cargo inventory |
.cargo.list | list | List of wares in cargo |
.buildplot | buildplot | Build plot info |
.buildplot.price | int (Cr) | Build plot price |
.dockingbays | list | Docking bays |
.crew | list | NPC crew |
.workforce | int | Current workforce |
.maxworkforce | int | Maximum workforce |
.controlpost.manager | npc | Station manager NPC |
.istradestation | bool | Is a trade station |
.isfactionheadquarters | bool | Is a faction HQ |
.isplannedshipyard | bool | Is a planned shipyard |
.isplannedwharf | bool | Is a planned wharf |
.isplanneddefencestation | bool | Is a planned defence |
.hasfixedconstruction | bool | Has fixed construction (cannot extend) |
.hasstagedconstruction | bool | Has staged construction (X4 9.0+) |
Actions
Section titled “Actions”Create a station
Section titled “Create a station”<create_station name="$myStation" macro="..." faction="..." object="$sector" position="[x, y, z]"/>Change owner
Section titled “Change owner”<set_owner object="$station" faction="faction.player"/>For ships, use md.LIB_Generic.TransferShipOwnership (handles fleet detachment). For stations, <set_owner> is typically sufficient — but verify subordinate ship behaviors with your specific scenario.
Destroy
Section titled “Destroy”<destroy_object object="$station"/>Find stations by faction
Section titled “Find stations by faction”<find_station_by_true_owner name="$stations" faction="faction.argon" space="player.galaxy"/>Filter for normal vs special stations
Section titled “Filter for normal vs special stations”<do_if value="not $station.isplanneddefencestation and not $station.isplannedshipyard and not $station.isplannedwharf and not $station.istradestation and not $station.isfactionheadquarters"> <!-- this is a normal production/storage station --></do_if>This is the filter used by the Buy and Sell Stations mod to identify stations the player can buy or sell.
Libraries
Section titled “Libraries”Vanilla helpers for working with stations. Source: md/lib_generic.xml.
| Library | Purpose | Source line |
|---|---|---|
md.LIB_Generic.FindNearestStationForFaction | Closest station of given faction | 1240 |
md.LIB_Generic.FindStationsForFactionByDistance | All stations sorted by distance | 1270 |
md.LIB_Generic.TransferStationOwnership | Transfer with cleanup | 1559 |
md.LIB_Generic.SetStationMinHull | Set hull floor | 2971 |
md.LIB_Generic.RequestObjectInvincibility | Mark indestructible | 3522 |
md.FinaliseStations.NewStation_GenerateFactory_Signal | Public API for finalizing a created station | finalisestations.xml:192 |
Events
Section titled “Events”Events that fire about stations.
| Event | When | Notes |
|---|---|---|
event_object_destroyed | Station destroyed | Filter by event.object.isclass.{class.station} |
event_object_changed_owner | Ownership changed | — |
event_object_attacked | Under attack | Fires from aiscript, not MD-side |
event_god_created_factory | Engine-side new station spawn | isgamestartgodentry=true/false distinguishes initial seed from runtime |
For galaxy-wide combat notifications, see Behavior → Order — aiscripts emit 'station_under_attack' signal to player.galaxy.
Common gotchas
Section titled “Common gotchas”- ⚠
<find_station>(without_by_true_owner) excludes player stations. Usefind_station_by_true_owneror merge results from both. - ⚠ Module recipes accessible via
$Mod.macro.ware.resources— not$Mod.products.list.{1}.resources(returns null silently). - ⚠ In X4 9.0,
<create_construction_sequence>errors on stations withhasstagedconstruction=true— guard with<do_if value="not $Station.hasstagedconstruction">. - ⚠
bare <set_player_target>for cross-cluster stations errors (not in player cluster). For galaxy-wide tracking use Guidance API.
Examples
Section titled “Examples”Example 1: Find the player’s nearest Argon trade station
Section titled “Example 1: Find the player’s nearest Argon trade station”<run_actions ref="md.LIB_Generic.FindNearestStationForFaction" result="$nearest"> <param name="Faction" value="faction.argon"/> <param name="Position" value="player.ship.position"/> <param name="Sector" value="player.ship.sector"/></run_actions>
<do_if value="@$nearest"> <set_value name="$is_trade" exact="$nearest.istradestation"/></do_if>Example 2: Listen for any station destruction in the galaxy
Section titled “Example 2: Listen for any station destruction in the galaxy”<cue name="WatchStationDestruction" instantiate="true"> <conditions> <event_object_destroyed/> <check_value value="event.object.isclass.{class.station}"/> </conditions> <actions> <write_to_logbook text="'Station destroyed: ' + event.object.knownname"/> </actions></cue>Example 3: Transfer ownership of a station with cleanup
Section titled “Example 3: Transfer ownership of a station with cleanup”<run_actions ref="md.LIB_Generic.TransferStationOwnership"> <param name="Station" value="$capturedStation"/> <param name="NewOwner" value="faction.player"/></run_actions>Architectural context
Section titled “Architectural context”For deeper understanding of station-related subsystems:
- How stations come into existence: Architectural overview Galaxy seeding (Tier 1) — covers
god.xml,FinaliseStationspipeline,factionlogic_stationsruntime spawner. - How factions decide when to build new stations: Architectural overview Faction economy —
EvaluateSectorShortageformula andRequest_Factoryaction. - Station construction rendering: Architectural overview Construction sequence —
<create_construction_sequence>and<apply_construction_sequence>.
Related
Section titled “Related”- Module — building block of a station.
- Shipyard — subtype, builds capital ships.
- Sector — container.
- Faction — owner.
- Ware — what stations trade and produce.