Traffic World

pkg/traffic/world is the traffic engine of the airport map as a package. It runs scheduled traffic around the focus airports with its ATC: spawning and pushback, taxi, runways and their clearances, landing sequences, separation and conflicts, approaches and VFR circuits, enroute traffic, emergencies, crews, ground services and jetways, and the phrases per position. The airport map is a front end over it: its page and its voice. For a map of all the traffic pages, start at the Traffic Overview.

The package uses only the standard library and this module. It talks to the simulator on Windows; elsewhere it runs as a director (decisions only) or offline on a loopback client (Offline).

Running it

On its own connection (the airport map does this; it reconnects when the simulator goes away):

w := world.New(world.Options{LogDir: ".", Airways: graph})
go w.Run(ctx)

On a host’s connection: the host feeds every message of its connection and runs the World on its client. Feed copies the message and never blocks; with its queue (Options.QueueSize, default DefaultQueueSize 4096 messages) full, a message is dropped and counted in Snapshot().Dropped.

w := world.New(world.Options{OnTransmission: say})
mgr.OnMessage(func(m engine.Message) { w.Feed(m) })
go w.RunOn(ctx, client) // all its SimConnect calls happen here; again on the next connection

In a test, with no simulator: worldtest.Start runs a World on a loopback client (worldtest.Loopback: objects created get IDs, positions written are kept, data requests are answered from them, models listed) with SimlessAI, an airport loaded from offline data (a simconnect-data checkout, <dir>/<ICAO>/layout.json, …), every transmission recorded and a scriptable user aircraft. With Manual: true it runs on a traffic.ManualClock (traffic.SetTimeSource, process-wide until Close): time moves only in h.Advance(d) and h.Until(max, cond), frame by frame (FrameRate, 10 is plenty), each frame taken by the World before the next, about 100 times faster than the simulator; without it the wall clock runs and Advance waits. Airports with no offline data wait for the loader’s timeout (26 s of the clock in use) before giving up.

h, err := worldtest.Start(worldtest.Options{DataDir: "../simconnect-data", ICAO: "LKPR", Manual: true, FrameRate: 10})
defer h.Close()
h.World.SetSchedule(world.ScheduleSettings{Enabled: true, Airports: []string{"LKPR"}})
h.Until(10*time.Minute, func() bool { return h.Said("", "request clearance") }) // simulated minutes, a second or two
h.SetUser(func(o *worldtest.Object) { o.Lat, o.Lon, o.OnGround = 50.1, 14.26, true })
v, ok := h.Aircraft("CSA1922") // its ControlView

Options and hooks

Option What
LogDir where the traffic log goes (traffic-*.log); "" none
Airways an airway graph for flight plans; the airways around every airport loaded are read from the sim and added
AirwaysMaxAge how long an airport’s airways read from the sim are kept in DataDir/airways before they are read again (default DefaultAirwaysMaxAge, 7 days)
Airspace the control zone class for VFR rules (default D)
DataDir de-icing pads (deicing.json), review overlays and the airways read from the sim
DumpDir write each fetched airport’s raw facility records
IDBase moves the library helpers it creates off their default IDs (see SimConnect IDs)
QueueSize how many fed messages wait for the World (default 4096)
Output where the console lines go (nil: stdout); a host speaking a protocol on stdout gives stderr or io.Discard
Scenes a directory of camera scenes; "" the built-in ones
Schedule the schedule’s timing (ScheduleTiming, see below)
Overflights the overflights’ distance tiers (OverflightTiers{MaterialiseNM, DematerialiseNM, MaxVirtual}): far from the viewer they are flown as virtual tracks with no simulator object (Distance tiers); zero is off
OnTransmission every transmission once logged: the host says it with its own voice
OnChange a part of the picture changed (control, radio): fetch it again
OnCom1 the user aircraft’s COM1 frequency, each second
OnTune the COM1 tuner of each connection (nil once it ends)
SceneFrequency the frequency a camera scene’s radio is on

A transmission (traffic.Transmission) has everything a voice needs: the text, the intent and its parameters, the call sign, whether a pilot or which position says it, the airport and the frequency.

What a host sees and asks

  • Snapshot(): our aircraft (ControlView: state, its simulator object (objectId, the id /api/traffic and the actuator’s poses use; omitted until the object exists), ATC position and frequency, altitude as the simulator reports it (altFt), routes still to fly, the clearances available now) with their ground vehicles (VehicleView: tug or fuel truck, its sim object id, model, state, position and the way still ahead), whether the traffic runs, and how many fed messages were dropped. Virtual lists the overflights flown as virtual tracks with the distance tiers on (Traffic with virtual true; Distance tiers). A vehicle’s state is what it says of itself (traffic.VehicleState: waiting, inbound, attached, fuelling, outbound, removed).

  • Do(method, path, body) and Get(path, &v): the HTTP API in process, the same calls a remote client makes. For example, Get("/api/airportinfo?icao=LKPR", &v) gives the runways in use, the ATIS (letter and text: the World owns it), the ILS and the weather. /api/sequence?icao= gives the landing sequences, /api/stands?icao= the stands, and POST /api/schedule {"enabled":true,"icao":"LKPR","density":1} starts the schedule. POST /api/control/{id}/{action} gives a clearance. GET /api/traffic lists every aircraft the sim reports around the user aircraft (Traffic; ours flown by MSFS AI carry route, the way they still fly). Virtual overflights (distance tiers) are listed too, marked "virtual": true.

  • Stop bars (#1532): the engine owns the clearances, so each ControlView says where the aircraft is held and what it is cleared past. holdAt is the runway holding point it holds at, or stops at next on its route; clearedPast lists the holding points ahead that its clearances take it past (a crossing, a line-up or take-off, the exit it vacates by), each until it has passed it. Every point is a HoldPoint: node (the taxi graph node, the taxi point’s index, as Graph.HoldShortNodes and Layout.HoldShortPoints give), position, runway it protects and ils. GET /api/holds?icao=LKPR lists every holding point of the airport as a HoldBar with released (bar off) and by, the call signs cleared past it; the rest are protected (bar on). The view changes, and the control push fires, when a bar should switch.

  • POST /api/control spawns one of ours. A departure sent without a stand whose every fitting stand is on the way in of a backtracking arrival that has landed is put off, not placed where that arrival would come by it (#1641): the answer is 202 Accepted with a DeferredReply ({"deferred": true, "tail": ..., "reason": ...}), and the departure is spawned, without another call, once a stand out of that way is free (looked at every 10 s).

  • Typed actions over the same API: SetSchedule(ScheduleSettings{Enabled, ICAO, Airports, Density, IFR, VFR, Generator, Others}), AddFlights(flights), Clear(id, action) and Approach(icao, callsign, action).

  • Phrase(id, action) (GET /api/control/{id}/{action}/phrase) is what Clear would say, without giving it, for a “you say” button. It returns ClearancePhrase:

    • Controller: the transmission, with the same intent, params and phraseology (runway, taxi route, wind, the traffic to line up behind, FAA wording at US airports);
    • Readback: the crew’s readback, or nil when there is none.

    A clearance given with Clear is said on the radio as the automatic controllers’ are, readback included (GET /api/radio).

  • An arrival’s ControlView.Sequence is its place in its airport’s landing sequence: number, leader, spacing, minimum. It is the same entry /api/sequence gives.

  • PlaceUser(icao, stand) (POST /api/user/place) puts the user aircraft on a stand, where and as an aircraft parks there: a scenario’s start. It refuses while the aircraft flies, moves (over 1 kt) or runs an engine, and when one of ours holds the stand or an aircraft is in the way; each refusal is its own error (ErrUserAirborne, ErrUserMoving, ErrUserEngines, ErrStandOccupied).

  • Register(mux): serve that API on the host’s own server (the airport map does).

Flights at a chosen time

A host can time traffic around its own flight: an arrival a few minutes before the player’s ETA, a departure just after the player’s off-block.

  • SetSchedule(ScheduleSettings{Enabled: true, Airports: []string{"LKPR"}, Generator: &off}) runs the scheduled airports with no generated timetable: only the flights added.
  • AddFlights([]traffic.Flight{...}) (POST /api/flights) adds flights. Each needs a call sign, an origin and destination (one of them a scheduled airport), the STD and STA in traffic time (GET /api/schedule’s now), and an airline or type (default A320). The manager spawns them as it spawns the timetable’s: a departure on its stand DepartureLead before its STD, an arrival ArrivalLead before its STA to fly the STAR and approach.
  • An arrival added later than ArrivalLead minus ArrivalLate before its STA (15 min with the defaults) is refused with 422, not cancelled later. GET /api/flights lists the manager’s flights with their status.
  • Options.Schedule (ScheduleTiming) sets the horizon, the leads and the late limits; zero values keep the defaults (2 h; 10, 25 and 8 min; 15 and 10 min).

Real-world traffic

With real-world traffic on, the World flies the aircraft that a feed such as ADS-B observes, instead of the generated timetable. Each aircraft gets everything the World’s own traffic gets: stand services, push, taxi, ATC and radio.

  • SetRealTraffic(true, "LKPR") (POST /api/realtraffic {"on":true,"icao":"LKPR"}) turns the generator off and sets the managed airport. Generated flights not yet in the simulator go at once, and those flying finish their flight. false brings the generator back. GET /api/realtraffic says whether it is on, with the managed airports.
  • Observe([]traffic.Observed) (POST /api/realflights) takes a feed’s snapshot. A sighting is an id (the ICAO 24-bit address), callsign, registration, type, lat/lon, altFt, groundKts, trackDeg, vsFpm, onGround and seenAt, plus optional kind, origin, destination, departAt and route (or routeText, the filed route such as “DCT VLM UL86 KEPAD”, expanded over the airways known: unknown tokens such as a SID name are passed over and logged).
    • It returns one ObserveResult per sighting, with the status added, updated, retimed, turnaround or ignored (with a reason).
    • The aircraft flies under its call sign, else its registration, else its ID.
    • An unknown origin or destination stays "" and is shown as unknown, never guessed.
  • Drop(id) (DELETE /api/realflights/{id}) ends an aircraft the feed no longer sees. One not spawned yet, waiting on its stand or parked goes at once. One in progress plays out first: an arrival lands and parks, then goes; a departure leaves. Nothing is ever taken off the final.

The kind, when not given, comes from traffic.ClassifyObserved:

Kind When (no kind given) What the World does
parked On the ground within 3 NM of the airport, still It goes on the free stand within 80 m of where it is seen (else a stand by its type) and waits, with no push and no call to delivery, until a departure is seen for its ID. That departure re-times its push (traffic.TaxiController.SetPushbackAt), and only then does the aircraft call delivery.
departure On the ground at the airport, moving It goes on a stand the same way and pushes at departAt or now. With no destination it flies a SID of the runway and leaves the area. Given a route, it flies its planned SID and then the route, from its first point past the SID, at the route’s levels or the planned cruise level.
arrival Airborne within 150 NM, heading for the airport (within 60°), not climbing away Its sighting is projected to now along its track (at most 10 min). It appears there, flown by MSFS AI, and joins a STAR of the runway in use at the point that gives the shortest way in, up to the initial approach fix. Given a route (points lat, lon, optional altFt: a recorded or planned track), it flies the route and joins the STAR where the route passes within 5 NM of one of its points, again the shortest way in; a route that meets no STAR is left for the direct join. Approach takes it over at that point, as it takes over an en-route arrival. It is never held back by the landing flow (it is already in the air) and never cancelled by time.
overflight Anything else airborne Within 100 NM of the centre of the area, it appears where it is now (projected as an arrival is), flown by MSFS AI across the area along its route to the first point out of it, else straight on along its track, and goes once out.

A sighting is ignored when it is on the ground away from the airport, climbing out (over 500 fpm within 30 NM), or a ground station or vehicle (type TWR, GND, GRND, SVC, VEH). The projection uses its vertical rate for at most a minute.

Each ID is one aircraft and is never spawned twice. Once the World flies an ID, later sightings don’t move it; they only refresh its registration, origin and destination.

Each kind of flight shows as real:

  • ControlView has real, observedId and registration.
  • The manager’s flights carry their observed sighting.

A parked aircraft keeps the call sign it was spawned with when its departure is seen under another.

TCAS

Each of the World’s airborne aircraft carries TCAS II. It watches every aircraft within 12 NM: the World’s own, the user’s and other traffic. When the test is met it gives a traffic advisory (TA) or a resolution advisory (RA): traffic.Evaluate, then traffic.SelectRA.

The thresholds come from the FAA’s Introduction to TCAS II Version 7.1 (2011), Table 2:

Own altitude SL TA tau (s) RA tau (s) TA DMOD (NM) RA DMOD (NM) TA ZTHR (ft) RA ZTHR (ft) ALIM (ft)
< 1000 ft AGL 2 20 — 0.30 — 850 — —
1000–2350 ft AGL 3 25 15 0.33 0.20 850 600 300
2350–5000 ft 4 30 20 0.48 0.35 850 600 300
5000–10000 ft 5 40 25 0.75 0.55 850 600 350
10000–20000 ft 6 45 30 1.00 0.80 850 600 400
20000–42000 ft 7 48 35 1.30 1.10 850 700 600
> 42000 ft 7 48 35 1.30 1.10 1200 800 700

How an advisory is decided and flown:

  • Advisory: given when both the range test and the vertical test pass. The range test is the range tau, modified towards DMOD at slow closure. The vertical test is the vertical tau, or within ZTHR.
  • Inhibits: no RA below 1000 ft AGL, no descend RA below 1100 ft AGL, nothing on the ground.
  • Sense: the non-crossing sense when it gives ALIM at the closest point, otherwise the one that gives the most separation. The pilot is modelled as responding in 5 s at 0.25 g to 1500 fpm.
  • Strength: the least disruptive RA. Monitor Vertical Speed when the current rate already gives ALIM; Level Off when stopping the climb or descent does; otherwise Climb or Descend, crossing when it passes through the intruder’s level.
  • Coordination: between two of the World’s aircraft the second takes the opposite sense to the first.

The crew flies the RA after 5 s:

  • Level off: holds its level.
  • Climb or descend: goes 1000 ft from where the RA began, as a level on its route. An arrival on its injected final takes a climb RA as a go-around.

The crew reports on its frequency: “(station), (callsign), TCAS RA”, then “clear of conflict, returning to (assigned clearance)”: the level or approach it was last cleared to, “returning to flight level 100” (Doc 4444 12.3.1.2 r, t; CAP 413 5.32, 5.33). The controller answers each “roger” (12.3.1.2 s, u). At an FAA airport it is “returning to assigned altitude” (JO 7110.65 2-1-28, its examples). Approach gives the aircraft no instruction until then, and the conflict resolver leaves it alone. En route the same: the conflict watch and its safety net don’t steer it, and the player’s instruction is refused as approach’s is (“flying a TCAS RA: no instruction until clear of conflict”).

Until clear of conflict also:

  • an en route arrival isn’t paced behind its leader, told to resume own navigation or handed to approach (handed over once clear);
  • a departure gets no climb, restriction or direct from departure radar (the climb comes once clear, a crew’s request for a direct is “unable”), and the player’s climb, heading or speed is refused the same way;
  • assist suggests nothing to it;
  • an instruction given just before the RA is refused if it hasn’t reached the simulator when the RA is flown;
  • an arrival isn’t levelled for a conflict, nor sped, slowed, vectored, held, shortcut or diverted by its sequence, and one below it in a hold leaves only once it can step down;
  • a call decided before the crew reported the RA is said once clear;
  • an arrival handed from the en-route list to its arrival controller stays ours for TCAS in between, its RA flown once the controller has it.

On the map and over the API:

  • ControlView.tcas holds the advisory (TA/RA), the intruder, the aural (Table 4, Version 7.1) and the sense. The map shows a TA in amber and an RA in red with ↑ or ↓.
  • GET /api/tcas returns the counts and the last 200 events (TA, RA, clear).

Traffic along the user’s route

In cruise, the World can keep a few airliners around the host’s flight. SetCorridor(CorridorSettings{...}) (POST /api/corridor) takes the user’s route ahead (two or more points, in its direction), its cruise level and speed, and how many of each kind (default one):

  • same: ahead on the route, 25 to 45 NM, going the same way 2000 ft above or below.
  • opposite: 70 to 100 NM ahead, coming the other way 1000 ft above or below.
  • crossing: across the route 45 to 70 NM ahead, at 60 to 120 degrees, 1000 or 2000 ft above or below.

They are airlines of the schedule, with a jet that cruises at that level, created airborne and flown by MSFS AI (traffic.CorridorRoute, the en-route machinery). Each is kept at least 15 s from the last; none appears on top of other traffic. One more than DespawnNM (default 80) from the user aircraft and moving away is taken out and replaced. GET /api/corridor shows the settings and the aircraft; "enabled": false takes them all out. The user aircraft’s position comes from the World’s feed.

Traffic over the airport

With the schedule on, the World flies the traffic a real airport sees overhead: overflights crossing the 100 NM around the picture’s centre (Overflights). Each is created airborne as a NonATC aircraft on a waypoint chain of ours (MSFS 2024 ignores the en-route spawn phase), its level planned clear of everyone’s planned ways before it appears; with the distance tiers far ones are virtual tracks with no simulator object. ScheduleSettings.OverflightTraffic (the same fields in POST /api/schedule) turns on each piece; each is off when not given, and the traffic is then as before:

Field What
overflightFlows the overflights by the area’s streams and volume from the flows table, else the generic fallback (Streams and volume per area, #1483)
overflightRoutes across by the airspace’s route structure: direct in free route airspace (through its entry and exit points when the table lists them), along the airways elsewhere, each at a strategic offset of 0, 1 or 2 NM right of its route (Route structure, #1484)
transits the neighbouring airports’ departures and arrivals crossing the area on their climb or descent (Transits, #1485)
crossingKeepClear overflights and transits keep clear of the terminal airspace: above each layer inside its outline, or round it (Keeping clear of the terminal airspace, #1486)
overflightRadio, centreCallsPerMinute overflights and transits talk to the centre station holding them: check-in, hand-off, on the tuned frequency only, at most centreCallsPerMinute transmissions a minute (default 6) (Overflights on the centre frequency, #1487)

GET /api/schedule shows what is set, with overflightArea and overflightPeakPerHour while the flows are on, and transitFlights, the transits’ call signs.

Overflights on the centre frequency

With overflightRadio, the overflights and transits are worked by the centre station whose sector holds them: traffic.PickStation over the first focus airport’s stations at the center position, or over another focus airport’s where a player staffs its centre there (#1684). That is the scenery’s centre frequency, or a local station set with PUT /api/stations?icao= (an area polygon makes a sector). Without a centre station that has a frequency they say nothing.

  • Check-in: entering the area, the crew calls the station with its level: “Praha Radar, CSA123, flight level 370”. A climbing or descending transit says “passing flight level 183, climbing flight level 240”.
  • Hand-off: leaving its sector, the station hands it to the next sector’s station (“contact ”); the crew reads back and checks in there. Leaving the area, it is handed to the next unit, not named. Virtual tracks talk as the aircraft do.
  • Frequency load: only on the frequency the user’s COM1 is on (with no user aircraft, all). A centre frequency gets at most centreCallsPerMinute transmissions a minute, readbacks counted; a call over the cap waits. With room for a hand-off and its readback only, the crew answers it at once and right (ParamNoSlip): a “say again”, a corrected readback or a missed call would go past the cap.
  • Staffed: a centre station staffed by a player (StaffedStation, position center or the station’s name) is theirs. The crews still check in; the AI hands nobody off (unless autoHandoff). The player instructs an overflight or transit of ours (an arrival before its STAR is approach’s, see Staffed stations) with World.InstructEnroute(EnrouteInstruction{Callsign, AltFt | Heading+HeadingDeg | Kts | Direct | Fix, By}) or POST /api/enroute/instruct. It is said on the station’s frequency, read back, and flown from where the aircraft is now: through its waypoint chain (SetRoute), or its virtual track restarted at its pose (no jump). A level or speed holds for the rest of its way; a heading is flown for 15 minutes, then back onto its way. Refused (403) when the station working it is not the player’s, 404 for no such aircraft, 409 while its crew flies a TCAS RA. The conflict watch leaves such an aircraft to the player as it does an arrival or departure, by the station’s mode: an alert with a suggestion (assist), nothing (silent), or the resolution once the player is too late (safety net); it does not clear it on or restore an old route over the player’s clearance. The crew still flies a TCAS RA.

Beside the host’s own ATC

The World never controls nor calls the user aircraft. A host whose own ATC works the player tells the World what it does:

  • Heard(t): the host’s ATC said t on t.Frequency at t.Airport. The World’s traffic waits for the frequency instead of talking over it.
  • ClearPlayer(world.PlayerClearance{ICAO, Runway, Phase}) (POST /api/player), where the phase is pushback, taxi, holding_short, lineup, takeoff, landing or vacated. Pushing back, ours on stands near it wait to push; holding short, it takes its place in the departure queue. While the player lines up, takes off or lands on a runway, none of the World’s traffic is cleared onto it (line up, take-off, landing, crossing). Landing, the player is in that runway’s landing sequence (as Callsign, else “Player”), so the traffic fits around it; Snapshot().Player is its place (number, the call sign and type it follows, the spacing and both distances to go). vacated ends it.
  • PlayerRunway(world.PlayerQuery{ICAO, Runway, Phase, Callsign, Model}) asks before clearing the player onto a runway (lineup, takeoff, landing): the World’s tower decides on a copy of that runway’s state as it does for its own traffic, so nothing changes by asking. RunwayAnswer.Free means clear it now; otherwise Say is what to tell it instead (“line up and wait”, “hold position”, “continue approach”, “go around”), Behind a conditional line-up’s traffic (“the departing Airbus A320”), Traffic the reason as said to a pilot (“traffic on the runway”, “traffic on a 3 mile final”, “landing traffic”, “departing traffic”), Number its place in the departure queue, Why the World’s own reason with call signs, AskAgainIn when to ask again. Clear the player with ClearPlayer right after a free answer; report holding_short when it reaches the holding point, so it holds its place in the queue and ours wait their turn behind it.
  • One World per simulator: each World runs its own schedule from the same seeded timetable. Running two at once on one simulator (the airport map, the MyCrew app, the MCP server) spawns the same flights twice, with duplicate call signs. Run one, or link the others to it (director/actuator).
  • Stopping: when RunOn’s context ends, the World removes its aircraft, their vehicles and its en-route flights from the simulator (a host restarting its traffic on the same connection found them frozen); Options.KeepOnStop keeps them. Options.Cache shares an airport.Cache with the host, so one airport is loaded once. Console lines, errors included, go to Options.Output.
  • Over HTTP: POST /api/player/runway (a PlayerQuery → RunwayAnswer), GET /api/player/traffic?callsign=&icao= (→ []PlayerTrafficInfo) and GET /api/player/circuit?icao=&runway=&lat=&lon= (→ {config, leg}), for a host linked to a director.
  • The player and the World’s runways and ground, coordinated (the player’s ATC does not know the World’s traffic):
    • Seen, not only cleared: the user aircraft on a runway (any speed) or lined up close in on a final (within 4 NM, below 2500 ft AGL) counts for the World’s tower whether or not its ATC said so, on that runway and on every runway crossing it. A clearance onto one runway also keeps ours off the runways crossing it.
    • Crossing: PlayerCrossing (crossing) while it crosses a runway taxiing; PlayerRunway answers a crossing too (“hold short”, “cross behind” the landing traffic).
    • Stale clearances expire: line-up/take-off once it is airborne off the runway (or after 10 min), landing once it is on the ground off the runway (20 min), crossing once it has been on the runway and is off it (3 min), any other after 30 min. Sending vacated is still right.
    • Ground: each second the World reports where the user aircraft goes: moving, its way ahead along its heading (20 s at its speed, at least 60 m); cleared to push or moving backwards, the push corridor behind it. Ours and the service vehicles give way to that, not only to its body.
    • Stand: PlayerClearance.Stand (a label) holds that stand for it: none of ours is given it, and an arrival of ours that has not landed yet and holds it is moved to another (one already taxiing in or parked keeps it, logged).
    • Air: a pair with the user aircraft is the tower’s only below 1000 ft at the airport (UserTowerBelowFt, was 2500 ft for all): above that ours get resolutions against it. World.PlayerTraffic(callsign, icao) is the World’s traffic its ATC tells it of: ours airborne within 6 NM and 2000 ft, not moving apart, nearest first, each with the clock, distance, direction, type and level and the transmission’s text.

The runway in use

The World keeps one nav.RunwaySelector per airport (Keeping the runway in use). An airport’s preferential runways come first: at LKPR 24 stays in use, even with another end having more headwind, until it is out of its wind limits (gusts included). Another end is chosen only when it is better for nav.RunwayChangeAfter (10 min), or at once when the one in use is out of its limits.

A change is planned, not sudden. A change that is due waits for a gap in the traffic, at most nav.RunwayChangeMaxWait (15 min): no more than two arrivals (runwayChangeKeepArrivals) within 10 NM on the final, and none of them still being vectored. Then the new runway is prepared for everyone at once, while the last ones finish on the old one:

  • departures holding short, lining up, lined up or rolling, and those taxiing within 500 m of their runway (finishTaxiM), take off there;
  • the two arrivals nearest the old threshold within 15 NM (runwayChangeKeepNM) land there;
  • every other departure is re-cleared to the new runway: a SID named after the same fix and a new taxi route from where it is;
  • every other arrival not yet on the final gets the new runway’s STAR from the same entry fix and its approach, sequenced afresh. It joins at the entry fix while that is ahead of it, never sent back out against the arrivals coming in on the same STAR; one out of position near the field is vectored in behind the new flow;
  • arrivals to the new end are planned to land only after the departures still going from its other end have gone, plus a margin. Departures still at the old end’s holding point once that deadline has passed are re-cleared to the new runway.

A supervisor’s choice. UseRunway(icao, end) (POST /api/runway-use {"icao": "LKPR", "runway": "24"}) makes a runway end the one in use for departures and arrivals, whatever the wind; "" gives it back to the wind. It changes as any runway change does, planned, at the next gap. A scenario’s runway action with use does the same.

Held for a while. HoldRunway(icao, runway, held) stops all clearances on a runway for a few minutes without changing the runway in use: no line-up, take-off or landing (ours on a short final go around), as when closed, but no runway change follows. It is meant for a short stop, such as the rescue vehicles on the runway after an emergency landing (Emergencies & Scenarios). A scenario’s runway action with kind hold sets it.

Runway closures

CloseRunway(icao, runway, closed) closes a runway (works, a NOTAM; by name “06/24” or an end “24”) or opens it again; ClosedRunways(icao) lists them, the held ones included (GET /api/closures?icao=, POST /api/closures {icao, runway, closed}). A closed runway is never chosen for departures or arrivals (nav.RunwayLimits.Closed): the runway in use changes at once, also from one held through a wind shift, and the traffic on it changes runway as with a wind change; the ATIS and the player’s runway (DepartureRunway, the runways in use) follow. With every runway of an airport closed, no new flight starts there until one opens (a schedule attempt fails “all runways closed” and is tried again). On a closed runway the tower clears no line-up, take-off or landing, and ours on a final within 4 NM go around; crossing it stays allowed. With every runway closed, our arrivals in the air are told “all runways at LKPR are closed, expect holding” and hold at their STAR’s fix. A runway open again, the sequence releases them as from any hold. Held 20 minutes, each is cleared to the nearest other airport 30 NM or more away (“LKPR remains closed, cleared to LKKV, proceed direct”), sent direct toward it, and removed once 25 NM from the airport.

Emergencies, scenarios and staffed stations

  • Emergencies: Priority(tail, on) and PriorityFor(tail, kind) give an aircraft priority (the user aircraft with tail ""), and POST /api/emergency has one of ours declare one. See Emergencies & Scenarios.
  • Scenarios: StartScenario(sc, hooks) plays a scripted situation around the traffic. See Emergencies & Scenarios.
  • Staffed stations: SetStaffed(list) hands chosen ATC stations to a human controller. See ATC Game & Staffed Stations. With approach staffed, the player may give an arrival still en route, before its STAR entry, a speed, a heading or a level (POST /api/approach/{icao}/{callsign}/{speed|heading|descend}); it flies them on its en-route waypoints and is handed over at the entry as before.

Stands and stand rules

Our aircraft stop on a stand where its circle and parking point say. On some big stands a smaller aircraft would stop too far forward, so a stand rule moves the stop for one stand: traffic.StandRuleItem with Stand (“LKPR B14”), ForwardM along the stand’s line (negative: back), RightM across it, and MaxSpanM, the largest wingspan it applies to (0: any). The library ships a few (traffic.standRules: at LKPR B14 and C22 narrowbodies stop 9 m back from the widebody stop), and a local file in DataDir/stand-rules.json goes over them per stand. World.StandRules() (GET /api/stands/rules) lists the rules in use; World.SetStandRule(rule) (POST /api/stands/rules) sets a local one, and a rule with nothing to move ({"stand": "LKPR B14"}) takes a shipped one back. Aircraft already placed keep their place; the next on the stand stops by the rule. At a jetway gate with jetways on, the move along the line is not applied (Jetways).

Planning a flight and the ATIS

  • PlanFlight(ctx, PlanRequest{Departure, Arrival, Type, ...}) plans an IFR flight the way the World plans its own traffic’s (nav.Plan): both airports loaded from the simulator (waiting at most 30 s), their SIDs, STARs and approaches, and the airways the World knows between them (direct where it knows none). The player’s choices are optional: SID, STAR, Approach and their transitions, CruiseFL and Route (an ICAO item 15 over the World’s airways); what is not followed is said in the plan’s notes. The plan’s PLN gives a .pln file for the simulator. Do not call it from a Do function or the World’s hooks: it waits on the connection loop.
  • ATISText(icao) is an airport’s current ATIS as written, and ATISOn(freq) the ATIS broadcast on a frequency now (its airport and text). GET /api/radio/atis?icao= gives the letter, the text, its spoken form and the frequency, for a voice to loop.

Offline: an airport without the simulator

The World can run with no simulator behind it (Vector, the ATC game, runs it in WebAssembly on a loopback client):

  • Writing the data. With Options.AirportDumpDir set, the World writes everything the simulator gives about each airport it loads into <dir>/<ICAO>/: layout.json (the raw facility records), procedures.json (SIDs, STARs and approaches), airways.json and ils.json, and the worldwide airport list as airports.json. (Options.DumpDir writes only the raw facility records, <ICAO>.json.)
  • Serving it back. LoadAirportDir(dir) serves an airport from such a directory instead of the simulator (each file optional), with its weather.json (a WeatherFile: wind, gusts, visibility, ceiling, temperature, QNH and precipitation for a representative day, written by hand) as the World’s weather. LoadAirportsFile(path, kinds...) serves the worldwide airport list, used for diversions and en-route traffic; with kinds (traffic.AirportKindTowered, AirportKindIFR, AirportKindAirfield, AirportKindShort, AirportKindWater, AirportKindNoRunway, as simconnect-data’s airports.json marks each airport in kind) it holds only those. AirportRef.SelfAnnounce (a CTAF, UNICOM or MULTICOM) and GroundLayout (taxi paths and parking; nil not told) carry the list’s flags. AirportDataDir(root, ref) is where an airport’s data is in simconnect-data: <root>/<ICAO> for a towered airport with an ICAO code, <root>/fields/<kind>/<ident> for the rest. LoadFile(path) and LoadProceduresFile(path) serve a single raw layout dump and a procedures dump.
  • Weather. SetWeather(wx) sets the weather the World uses (wind, QNH, the ATIS, the runway in use) over the simulator’s; nil gives it back to the simulator. Without any, the World has no wind, QNH or ATIS, and chooses runways without wind.
  • Flying without MSFS AI. Options.SimlessAI flies in the core what MSFS AI would fly (arrivals down their STAR and approach, departures on their SID, en-route traffic). Never set it with the simulator. worldtest.Start (above) uses all of this.

Ground services

Each airport has a fleet of service vehicles. The defaults are sized by its stands:

Vehicle Default size Model (GSX first, then MSFS’s own) Where it parks When it comes
Pushback tug 1 per 10 stands, at least 2 GSX tug Nose gear Before the push
Fuel truck 1 per 15 stands, at least 1 GSX fuel truck or hydrant dispenser Right wing While the departure waits
Boarding stairs 1 per 10 stands, at least 2 FSDT_Staircase_*, else ASO_Boarding_Stairs Front left door, square to the fuselage: the model’s own door where known (its flight_model.cfg, read from the installed packages on Windows or given with World.SetModelDoors), else an estimate from the wheelbase; backs straight out Remote stands only (no jetway)
GPU 1 per 10 stands, at least 2 FSDT_GPU_TLD_406 or FSDT_GPU_Hobart_4400, else Car Ground Power Unit Forward right of the nose gear Remote stands only
Passenger buses 2 per set of stairs FSDT_Cobus_3000 (ICAO regions E, L, K, C) or FSDT_neoplan_bus (O, Z, V, W, U), else Bus Apron 02 15 m left of the axis, outside the stairs, facing the tail: the first 4 m behind the front door, the second 20 m ahead of it Remote stands, with the stairs only
  • Passenger buses: one for an aircraft under 30 m of span, two from an A320 or 737 up.
    • Boarding: in the last 15 minutes before the stairs leave, a minute after the stairs came; the second once the first is at its spot. They leave a minute before the stairs.
    • Deboarding: on a turnaround, buses come a minute after the stairs, stay 5 minutes and drive home. The boarding bus on the same spot comes only once that one is home.
    • The way: in from the nose side, out turning round away from the aircraft. A way that would cross the aircraft, or pass within 15 m of its nose or tail, goes round it.
    • Not yet: an arrival that parks without a turnaround gets no buses. GSX serves only the user’s aircraft, so our buses never meet its own.
  • Follow-me car: GSX only, FSDT_FollowMe_Hilux or FSDT_FollowMe_class_B (MSFS 2024 has none of its own). One per 30 stands, at least one.
    • Which arrivals: airliners landing injected and bound for a remote stand.
    • Meeting: sent once the aircraft is down, it starts from the vehicle road nearest its meeting point (cars wait near the exits) and drives to 100 m past the vacate stop on the aircraft’s taxi path, where it waits.
    • Leading: it drives ahead along the aircraft’s path, about 105 m ahead; the aircraft never comes within 45 m, and stops when the car does. A re-route moves the car onto the new path.
    • Leaving: 120 m before the stand it pulls aside, away from the stand, and drives home round the aircraft; the parked aircraft’s frames drive it until it is home.
    • No car: none free, a short taxi-in, or a car that has not come within 4 minutes: the aircraft taxis in on its own.
  • Overrides: airport.Limits sets Tugs, FuelTrucks, Stairs, GPUs, Buses and FollowMe per airport, and a local override file wins per value.
  • Taking and giving back: a departure takes each vehicle from the fleet before it is sent, and gives it back once the vehicle has driven off, or when the flight ends or is cancelled.
  • When none is free:
    • The push waits for a tug.
    • Fuelling, stairs and the GPU are left out once it is too late for them. Stairs and the GPU leave 2 minutes before the tug comes, and the push waits for them to clear.
  • Log: the traffic log gives each airport’s fleet sizes, and logs a departure waiting for one (“waits for a tug at LKPR: all 8 busy”).
  • Library: traffic.VehicleFleet and traffic.ServiceFleet; TaxiRequest.Stairs, TaxiRequest.GPU, TaxiRequest.Buses and TaxiRequest.Deboard (traffic.SimObjectBus, BusSpot, BusesFor); ArrivalRequest.FollowMe with ArrivalWithServices (traffic.SimObjectFollowMe).
  • Control API: pushInMin gives a manual departure a push time, so its stand services have a window.

SimConnect IDs

The World uses these definition, request and event IDs on the connection; a host keeps its own clear of them. A host that uses the same library helpers on its connection moves the World’s off their defaults with Options.IDBase: airport loader at IDBase/+100, procedure loader +200/+300, nav loader +400/+500, airport list +600, injector +700/+800/+900, airway crawl +1000/+1010, enroute creations +1100–+2099. In each controller block of 10 request IDs the last six are its two buses, GPU, stairs, fuel truck and tug (an arrival’s follow-me car takes the tug’s); a deboarding bus and the boarding bus after it share one.

IDs What
2000–2021 user aircraft (2017: placing it on a stand), traffic scan, model and vehicle lists, sim events, camera state
7100–7999 library defaults: airport loader 7100/7200, taxi 7300/7400, arrivals 7500/7600, injector 7700–7999
8200–8999 stand allocators 8200/8300 (+4 per airport), procedures 8400/8500, airway crawl 8600/8610–8625, nav loader 8700/8800, airport list 8900
10010–10011 weather at the user aircraft
20000–21279, 30000–31279 the controllers’ ID blocks (128 × 10)
41000–41999 enroute traffic (IDBase +1100–+2099 when set)

Split: a director anywhere, an actuator beside the simulator

The World can run in two parts. The actuator runs beside Microsoft Flight Simulator. It keeps the SimConnect connection, each aircraft’s controller and their injection at frame rate. The director takes every decision (schedule, ATC, sequencing, separation, conflicts) and needs no simulator, so it can run on Linux. Decisions cross the network about once a second; injection never does.

traffic-actuator -listen :7710 -token s3cret                      # on the simulator's PC (Windows)
traffic-director -actuator simpc:7710 -token s3cret -addr :8080 \
                 -web cmd/airport-map/web -airways airways.json   # anywhere; the map's page on :8080

The link is JSON lines over TCP, and the director opens it with the token. If the director goes away, the actuator keeps flying, and the next director to connect takes over. In a program, world.ServeActuator(ctx, w, addr, token) and world.DialDirector(ctx, w, addr, token) do the same. world.Loopback(ctx, actuator, director) links the two parts in one process (the airport map’s -split) to check the split against the World in one piece.

An actuator flies its director’s traffic only (#1284): while it is linked, its own schedule, corridors and real-world traffic spawn nothing, and a scenario’s cast is refused with world.ErrActuator. Schedule settings made meanwhile stay, and apply once the link ends.

The actuator sends the departures’ tugs and fuel trucks (with their routes) for the director’s map each second. It also sends each controller’s state each second, and the director answers its plain reads (state, route, plan, hold) from that; a command to a controller drops its snapshot, and reads with arguments are still a call across the network.

ScheduleSettings.OffsetMin ("offsetMin") flies the airline timetable of that many minutes later now: 600 puts a morning wave into an evening. VFR flights keep the daylight of now.

Multiplayer: local first, one director for several sims

In multiplayer each player’s sim is an actuator; the director (on a server) decides for all of them. Motion stays local: every aircraft and vehicle is moved and injected by the actuator on the player’s PC at the sim’s frame rate. Only decisions cross the network.

  • On the player’s PC, with the host’s own connection: w.LinkDirector(ctx, "director:7710", token) before RunOn. It dials out (no way in needed), dials again 5 s after the director is lost, and keeps the link across sim reconnects (RunOn restarted per connection). Snapshot().Link is “dialling”, “attached” or “gone”. DialActuator does the same with a connection of its own (traffic-actuator -director).
  • On the server: ListenDirector(ctx, w, ":7710", token) (traffic-director -listen :7710). Its HTTP API wants a token on a public server: -api-token to control the traffic, -view-token to read it (“auto”: a random one, printed), sent as Authorization: Bearer <token>; the server itself always has access. The first actuator to dial in is the primary: its replies, events and feed drive the director. Later ones follow: they get the same commands, so each sim creates and moves the same traffic; what they send back is dropped. A follower joining late flies the flights started after it itself. The flights already going on when it joined are puppets there: the primary records each, five samples a second (flight.Recorder), and the director relays them to the followers that joined after that flight began. Each of those creates the aircraft and flies it as recorded (flight.Ghost: position, attitude, gear, flaps, spoilers, lights, engines), one second behind the newest sample so it is always between two. The puppet goes when its flight ends on the primary. A model a follower does not have is not created there. Not checked with two sims yet. When the primary is gone the director starts again with the next one.
  • Radio: every transmission is relayed to the actuators and reaches their host’s OnTransmission, so each player’s voice speaks it locally.
  • What the host does on the director, not locally: in multiplayer the schedule, flights, corridor and player clearances (SetSchedule, AddFlights, SetCorridor, ClearPlayer) go to the director’s HTTP API. The actuator’s own Snapshot().Aircraft is empty: the aircraft are listed by the director (GET /api/control).
  • Session tokens and TLS: on a public server the link carries a player’s position and the credential that drives their sim, so it runs over TLS with per-player session tokens. Server: ListenDirectorWith(ctx, w, ":7710", world.LinkOptions{Verify: world.NewJWKS(jwksURL, iss, aud).LinkVerify, TLS: serverTLS}) (traffic-director -listen :7710 -jwks <url> -tls-cert <pem> -tls-key <pem>, optional -jwks-iss/-jwks-aud). Each greeting’s token is verified against the keys published at the JWKS address (RS256/384/512, PS256, ES256/384, EdDSA; exp and nbf with a minute of leeway); the link closes when the token expires. The same tokens open the HTTP API (-jwks-api control|view|none, default control). Player: w.LinkDirectorWith(ctx, "director:7710", world.LinkOptions{TokenFunc: session, TLS: &tls.Config{}}) (an empty config verifies the director with the system roots). TokenFunc is called for every greeting, so a link closed on expiry comes back with a fresh token on its own. traffic-actuator -director host:7710 -tls (-tls-ca for a private CA). The token forms stay for a trusted network.

Holding the traffic for a replay

A replay shows the traffic recorded with the flight (flight.GhostFleet), so the World’s live traffic must not be there at the same time. World.Hold(true) (POST /api/hold {"on": true}) stops the schedule and removes every aircraft of ours from the simulator, marking each flight done; flights not yet in the simulator stay in the timetable. World.Hold(false) gives the schedule back as it was (on or off), and it fills the scene from its timetable as at any start. The aircraft removed are not brought back where they were: a replay can last any time, and their flights have moved on meanwhile. It returns HoldResult{Held, Removed}. Letting go when not held does nothing; holding again removes whatever came in meanwhile.

While held, nothing brings traffic in (#1283): a schedule set (SetSchedule, or the settings replayed on a new connection) or real-world traffic switched on is remembered for when the hold ends, not started; corridors spawn nothing; a scenario’s cast is refused with ErrHeld. The hold is the World’s, so a new connection keeps it. Aircraft spawned by hand (POST /api/control) are the host’s choice and still come in.

Real start: one snapshot placed at the start

World.Seed(observed, at) (POST /api/seed) places the traffic of one real-world snapshot when a flight loads: the same traffic.Observed records as the live feed, taken at at (zero: now). Each aircraft becomes a flight of ours from then on, with its real callsign and airline, under our ATC, sequencing and give-way. No feed follows it, and the schedule fills in afterwards.

  • Parked at an airport of ours: placed on the stand it is at (else one for its type). It departs after a turnaround (40 min, two minutes apart down the list) to its real destination, else on a SID out of the area.
  • Airborne inbound: joins the arrival sequence from where it is, as a live real arrival does.
  • Airborne outbound or overflying: crosses the area along its route (or its filed routeText), else straight on along its track.
  • Moving on the ground (taxiing): not placed yet, and said why.

The nearest to an airport of ours come first, up to the room the schedule’s MaxAircraft leaves. It returns SeedResult{Placed, Skipped, Results}, one ObserveResult per aircraft (added, or ignored with the reason), and logs each. The flights are marked seeded in ControlView (not real), so the map can tell them apart from live real traffic.

Ground vehicles on and off

The World’s ground vehicles can be switched off by kind: tugs, fuel trucks, stairs, GPUs, buses and follow-me cars (traffic.VehicleTug … VehicleFollowMe; all on by default). World.SetGroundVehicles(map[kind]bool) (POST /api/vehicles {"tug": false}) changes them at any time, World.GroundVehicles() (GET /api/vehicles) says which are on, and Options.GroundVehicles sets them from the start. A kind off means none of it is created from then on, and nobody waits for one:

  • Tugs off: departures push back on their own along the planned push.
  • Fuel trucks, stairs, GPUs, buses off: the turnaround runs without them.
  • Follow-me cars off: arrivals go to their stand without one.

Vehicles already at work finish their job and are not replaced. In a director and actuator pair the director decides, so its switches count.

The vehicles talk on the radio: “Ruzyne Ground, Tug 1, request proceed via G”. A vehicle calls when it is within 250 m of the taxiway or runway (traffic.VehicleAskAheadM), about 30 s at road speed: the answer comes before it gets there, so it drives on without stopping, and it does not call as it sets off. A tug’s time to reach the nose allows 45 s more for each such call on its way (VehicleGateAllowance). World.SetVehicleRadio(false) (POST /api/vehicles/radio {"on": false}) keeps them quiet: a taxiway is theirs without a call, and a runway crossing still waits for the tower in its turn, only nothing is said. World.VehicleRadio() (GET /api/vehicles/radio) says which.

Departure queue

Departures stay on their stands while the queue ahead of them is full, as departure management does: the queue at the runway stays short, and the arrivals are not spaced for a long one (traffic.CheckDepartureQueue). Two queues are counted apart:

  • Taxiing out: up to 6 departures between their stands and the runway, from the push to the line at the runway (DefaultMaxDepartureQueue).
  • At the runway: departures in its line (within 400 m of it), holding short, lining up or rolling. Each runway has its own queue: 3 for each entrance at its end, at least 4 (DefaultMaxRunwayQueue, ManagerOptions.RunwayQueue). LKPR 24 has two entrances, A and Z, so 6; EDDM’s runways have three each, so 9.

An entrance at the runway’s end has a holding point of its own and lies within 120 m of the nearest one (airport.EndEntrances, EndEntranceSpanMeters), which is itself within 300 m of the threshold (FullLengthMeters, measured on 262 runway ends at 40 large airports). LKPR 24’s A and Z both join the runway 201 m in. Intersections further in (LKPR 24: B, E) are not entrances; departures for them are planned as before.

The first entrance at the end (airport.EndEntrances order: nearest the threshold, then by name; LKPR 24: A) is the main one: every full-length departure goes there until its line is full (3 heading for it). Only then do the others (LKPR 24: Z) take departures, and a departure takes the entrance with the shorter line: each departure already heading for a holding point counts as 250 m more taxi there (airport.RouteOptions.HoldShortQueue). The radio still says only “runway 24”.

Model providers. Our traffic’s models come from providers, each on or off: a title’s package names it (FSLTL, AIG, GSX, MyCrew, else the package’s creator; traffic.modelProviders holds the patterns), and a title the simulator lists on no package on disk is MSFS’s own. By default our aircraft are the game’s own: MSFS on; FSLTL, AIG, MyCrew and any other maker’s aircraft off; the ground vehicles’ providers (GSX) on. A table item’s on changes a default. A flyable title (FlyByWire, Fenix: isUserSelectable = 1) is used only when its provider has nothing else and is switched on, so a maker’s FSLTL-format traffic package is not taken for its flyable liveries. World.ModelProviders() (GET /api/models/providers) lists them per kind with their title counts, World.SetModelProviders(map[provider]bool) (POST /api/models/providers) switches them and keeps the switches in DataDir/model-providers.json (the GSX way: what is there wins, per provider); Options.ModelProviders gives a host’s own defaults under that file (the airport map and worldtest switch FSLTL on). A provider off is passed over for the next choice; where nothing else is there, any is taken (flyable titles last) and the traffic log says so.

Reserved airlines. traffic.ReservedAirlines are our own: WTD (“WANTED”) and MCR (“MyCrew”), occasionally scheduled from LKPR. Their codes are in no list of airline codes we know, and they are kept over every table: the shipped telephony and airlines, the MyCrew API’s set, a local override and a schedule config’s airlines. They fly their own traffic models only (their liveries, never a flyable one), switched on or not; without them installed, their flights are left out.

Models never used. Some simulator models do not work as traffic: one that does not show attached, one that looks wrong. The table traffic.modelRules lists them by title (traffic.ModelRuleItem: title, kind, never, reason); our traffic passes them over for the next choice: the next aircraft title (ModelsFor), the next bigger tug (TugTitleFor), the next stairs, GPU, bus or follow-me car. Shipped: the small Mototok robot tug (it does not show attached; light aircraft get the towbarless Mototok) and MSFS’s GPU van. Local rules go over them per model in DataDir/model-rules.json ({"title": …, "never": false} takes a shipped one back): World.SetModelRule (POST /api/models/rules) sets one, World.ModelRules() (GET /api/models/rules) lists those in use, and the map’s aircraft card has “Never use” beside its model and each of its vehicles. Models already in use keep going.