Traffic Manager
traffic.TrafficManager runs the schedule of the managed airports. It decides what happens when. A Spawner does it in the simulator: it knows the stands, models, runways and controllers, and it reports back.
cfg := traffic.DefaultScheduleConfig()
mgr := traffic.NewTrafficManager(spawner, traffic.ManagerOptions{
Source: func(from, to time.Time, airports []string) []traffic.Flight {
return traffic.Schedule(cfg, traffic.ScheduleOptions{Focus: airports, Seed: seed ^ uint64(from.Unix()/3600)}, from, to)
},
Picture: picture, // the TrafficPicture: other traffic is respected
MaxAircraft: 12,
OnEvent: func(e traffic.ManagerEvent) { log.Println(e.Kind, e.Flight.Callsign, e.Reason) },
}, "LKPR")
for now := range time.Tick(time.Second) {
mgr.Tick(now)
}
What it does
| When | What |
|---|---|
STD − DepartureLead (10 min) |
A departure is spawned on a stand and boards; it pushes at its STD (TaxiRequest.PushbackAt). |
STA − ArrivalLead (25 min) |
An arrival is spawned at its STAR entry and flies the STAR and approach, lands and taxis to a stand. |
STA − VFRLead (8 min) |
A VFR arrival (Flight.Rules) appears near the airport to join the circuit (VFR traffic). |
| Arrival parked | If the arrival pairs with a later departure of the same airline and type from that airport (MinTurn 40 min – MaxTurn 3 h after the STA), that departure adopts the aircraft on its stand (turnaround). Otherwise the aircraft is removed after RemoveParkedAfter. |
| Departure airborne | Flies on along its plan and is removed once it leaves the area (see Leaving), at the latest RemoveDepartedAfter (30 min) after it leaves the controllers. |
| Too late | A departure is cancelled 15 min (DepartureLate) after its STD without an aircraft. An arrival is cancelled 10 min (ArrivalLate) after it should have appeared. A departure waits as long as its inbound aircraft is still on its way. |
Overnight
With Night (the World gives it from the schedule’s waves: an hour with at most a tenth of the peak’s movements is night, 23–04 local by default), the airport keeps aircraft overnight (#1294):
- From
Horizonbefore the night, the Source is also asked for the morning wave after it (MorningWave, 2 h from the first busy hour). - An arrival whose next turn (
MinTurnafter its STA) falls in the night pairs with a morning-wave departure of its airline and type: it stays on its stand overnight and leaves in the morning. - In the night, the morning wave’s other departures are spawned at once, parked on their stands (
ManagedFlight.NightStop), up toNightStopsan airport (default halfMaxPerAirport, negative none), earliest first. Each stays quiet and calls deliveryDepartureLeadbefore its STD, as any other departure does; its boarding counts from its STD forCheckStuck. - Both take remote stands first and leave the jetways to the day’s turnarounds (#1298): an airliner stand without a jetway, then a GA or cargo one, a jetway’s last (
StandRequirements.Overnight). Which stands have a jetway comes from the simulator’s jetway list (Bridged,jetway.Helpers.Jetways). Most airports type every airliner stand GATE, jetway or not, so without the list (jetways off) the stand is chosen as for any other flight.
The World’s settings for all of this are in Changing the timing.
The limits are MaxAircraft in total (default 24) and MaxPerAirport (default 16). Spawns are spaced: arrivals ArrivalSpacing (3 min) apart, departures DepartureSpacing (1 min). The Source is asked Horizon (2 h) ahead, an hour at a time. Flights already too late when they are added are left out, so a schedule started mid-day does not show the morning as cancelled. A failed spawn is tried again after RetryAfter (30 s), up to MaxAttempts (3); one unanswered for SpawnTimeout (2 min) counts as failed. Done and cancelled flights stay on the boards for Keep (1 h).
Add(flights) adds flights beside the Source’s (flights at chosen times); a flight already known by kind and call sign keeps its state. SetAirports, SetEnabled and SetLimits change the managed airports, spawning and the limits while it runs; SetStartStands and SetNightStops a session’s StartStands and NightStops (0 the options’ again, negative none; SetTiming leaves them); Replan asks the Source again for the hours ahead.
Changing the timing
World.SetScheduleTuning (POST /api/schedule/tuning) changes the scheduled traffic’s timing (#1303). What is set is saved in DataDir/schedule-tuning.json and wins per value over the default; what is left out stays the default. Each call replaces the whole override, and an empty one takes everything back. GET /api/schedule/tuning gives local (the override) and effective (every value in use).
| Value | Default | Triggers |
|---|---|---|
waves |
24 values, 0–1 | Movements by local hour against the peak |
nightWave |
0.1 | An hour at or below it is night: 23–04 local, morning at 05:00 |
morningWaveMin |
120 | The wave after the night that night stops and overnight arrivals leave in |
nightStops |
0: half MaxPerAirport |
Departures parked per airport; negative none |
minTurnMin, maxTurnMin |
40, 180 | An arrival’s turnaround after its STA; a negative minTurnMin never. A longer stay counts as overnight |
horizonMin |
120 | How far ahead the timetable is planned; a night is prepared from this long before it |
departureLeadMin |
10 | A departure appears, or a night stop calls delivery, this long before its STD |
arrivalLeadMin, vfrLeadMin |
25, 8 | An arrival appears this long before its STA |
departureLateMin, arrivalLateMin |
15, 10 | A flight not started this long after that is cancelled |
overnightRemote |
true | Aircraft parked overnight take stands without a jetway first |
selfAnnounce |
true | Our crews announce themselves at a field without a tower; false keeps its tower and ground on the common frequency |
cargoShare |
1 | Scales the cargo airlines’ weight, 0–10; 0 none |
Values the triggers cannot work with are refused with every problem named, and nothing changes: a wave outside 0–1, minTurnMin after maxTurnMin, a lead beyond the horizon. A file with such values is left out whole at the start, with a warning. A change applies from then on and to the hours ahead, asked again; flights already paired or parked stay as they are. TrafficManager.SetTiming is the manager’s own side (ManagerTiming, ManagerOptions.Timing).
The Spawner
type Spawner interface {
Spawn(f ManagedFlight) // must not block: report with Update, Describe, Failed
Remove(f ManagedFlight)
}
Update(callsign, status, now)reports progress: boarding, taxiing, departing, departed, approaching, landed or parked.Describe(callsign, model, stand, runway)records what the Spawner chose, for the boards.Failed(callsign, err, now)handles a failed spawn. It is tried again afterRetryAfter, up toMaxAttempts, and the Spawner takes another model or stand on each attempt (f.Attempts). An aircraft that was already flying is cancelled and removed.ErrSpawnBlockedmeans the place was taken: another aircraft is at the STAR entry, or no stand is free. The spawn waits and is tried again without counting an attempt.- A Spawner that is also a
Holder(Hold(f, on)) can keep a boarding departure on its stand. The map usesTaxiController.HoldPushback.
ModelsFor(models, airline, name, type, max) ranks the simulator’s aircraft titles for a flight:
- The type in the airline’s livery (
FSLTL_FAIB_B738_TVS-Smartwings,FSLTL A20N DLH Lufthansa). - Another type of the same size in the airline’s livery, same maker first.
- The type in any livery.
Within each of the first two, titles with the airline’s ICAO code come before those that only carry its name, which may be a sister airline’s (“TVP-Smartwings Poland” for Smartwings, TVS). Stubs, VIP, business-jet and military versions are left out. A cargo airline (Airline.Cargo) flies freighters only (FSLTL_B77LF_FDX: a designator with an F, or CARGO or FREIGHTER in the title); every other airline never gets one.
ModelsForFlight(models, airline, name, type, callsign, max) ranks the same way, but takes the equally good best titles in turn by call sign. Each flight always gets the same one, and a fleet with several liveries or versions installed shows them all instead of one aircraft. The map spawns with it.
Situation checks
Each Tick the manager looks at each airport the way the people there would. It predicts what is coming and adjusts. The controllers already do this up close (give way, queue behind, hold for traffic behind the stand); the checks cover the wider picture. A check is a function func(Situation) []Advice. ManagerOptions.Checks defaults to DefaultChecks():
| Check | Sees | Advises |
|---|---|---|
CheckLandingFlow(gap, queue) |
The predicted landing of every arrival: ours, and other traffic arriving (ETA from distance and speed). | Delay a scheduled arrival that would land less than gap (3 min) behind the one before. One gap is doubled while queue (2) or more departures wait, and the weather on final (ManagerOptions.Conditions) stretches every gap: twice in low visibility, a third more on a contaminated runway (Weather on final). Estimate its ETA. |
CheckGroundCongestion(max) |
Aircraft taxiing: our departures and arrivals, and other traffic. | Hold boarding departures on their stands while max (4) or more taxi: a ground stop. |
CheckTurnaround(minGround) |
A turnaround’s inbound aircraft: parked, or predicted to land. | Estimate the departure late when fewer than minGround (25 min) remain on the stand. |
CheckStuck(after) |
How long a flight stays in one status. | Remove an aircraft that stopped making progress (e.g. taxiing 30 min). |
The advice actions are:
AdviceDelaydelays a spawn.AdviceHoldholds a departure on its stand while it is advised; the hold is released on the first Tick that no check advises it.AdviceEstimatesetsEstimated, shown on the boards withNote.AdviceRemoveremoves the aircraft.
Write your own checks and add them with append(traffic.DefaultChecks(), myCheck).
Other traffic
ManagerOptions.Picture gives the manager the traffic picture. Aircraft that are not ours count as other traffic: MSFS AI, other add-ons and the user. The manager can treat it two ways:
OtherRespect(the default): other traffic fills the taxiways, takes landing slots and, through the Spawner, blocks spawn points.Situation.Otherslists it for your own checks, andOthers(icao)lists it for the app.OtherIgnore: the manager plans as if it were not there.
Switch between them with SetOthers.
Enroute traffic and overflights
Traffic flies between airports, not only at one.
- Enroute arrivals: an arrival appears
EnrouteLead(20 min) before it would appear at its STAR entry. It shows up en route on its flight plan, at the point the plan puts it now, at the planned level. MSFS AI flies it to the entry, where the Spawner hands it over to the arrival controller (statusenroute, thenapproaching). If the enroute spawn fails, the arrival appears at its STAR entry instead, with no attempt lost. A negativeEnrouteLeadturns enroute arrivals off. - Overflights:
ManagerOptions.Overflightsgives flights between airports outside the area whose route crosses it.traffic.Overflights(cfg, OverflightOptions{Centre, RadiusNM, PerHour, Density, Seed, Exclude}, from, to)generates them: airports outside the area, an airline serving both ends, a type that fits, andEnter/Exitwhen the flight crosses into and out of the area. Each appears atEnter, where its flight is by then, up toMaxOverflights(20) at once, on top ofMaxAircraft(overflights do not take the airports’ room;SetMaxOverflightschanges it). The World generatesoverflightsPerHour(default 10) in the peak hour at density 1, scaled by the density, and both are set withPOST /api/schedule. - Departures fly on after their SID along their plan, and stay ours.
- Leaving: an airborne aircraft of ours (departed, en route, overflying) is removed once the picture has not seen it for
LeftAfter(1 min), i.e. it left the area.RemoveDepartedAfter(30 min) and an overflight’sExitare the fallbacks.
Attach(callsign, objectID) tells the manager which aircraft flies a flight, so that it can follow it in the picture.
On the map an enroute arrival keeps its distance to the one ahead of it in the landing sequence (pkg/traffic/world/enroute_pace.go). Every 10 s, once it is within 10 NM of its leader and faster, its route ahead is flown no faster than the leader’s ground speed (at least 210 kt). It gets its planned speeds back once the gap has opened past 14 NM. A change under 10 kt is not made.
Appearing airborne
traffic.EnrouteStart(route []RoutePoint) turns the rest of a flight (points with altitude and speed, EnrouteSpeedKts) into two things:
- where the aircraft appears: at the first point, heading for the second, at its altitude and speed;
- the waypoint chain it flies from there.
Create the aircraft with Fleet.RequestNonATC at that position, then ReleaseControl and SetWaypoints once it exists. nav.FlightPlan.PositionAt(distNM) gives the point, planned altitude and track along a plan.
A flight plan cannot start an aircraft mid-route in MSFS 2024. AICreateEnrouteATCAircraft puts it on the ground at the plan’s departure airport whatever the phase. It also refuses a plan whose departure airport the simulator has not loaded.
Real-world flights
A flight with Observed set is a real aircraft a feed sees (manager_observed.go; the World drives it, see Traffic World). It is added with Add like any flight and handled differently:
- it is not spaced from other spawns, never cancelled as too late, and a real arrival is never delayed by a check (it is in the air already);
- it turns around only as the feed says:
Turn(arrival, departure)makes the departure adopt the arrival’s aircraft once it has parked; Observe(kind, callsign, sighting, origin, destination)takes a later sighting: all of it before the spawn, only the registration, origin and destination after;Retime(callsign, std)moves a departure’s STD while it is still on its stand;Drop(kind, callsign, now)ends it: not spawned, boarding or parked, it goes now; in progress it plays out (an arrival lands and parks, then goes; a departure leaves).
Flight(kind, callsign) returns one managed flight. AddOverflight(flight) adds a real overflight (with Enter and Exit), flown from its sighting across the area.
Replaying a recorded day
A scheduled flight can carry its recorded way, Flight.Path: points with lat, lon, altFt and the time at it was there. The flights are scheduled as usual (Add, with their STD, STA, or Enter/Exit), and the World flies each along its path:
- an arrival or an overflight appears, when its en-route stage starts, where its path has it at that moment on the simulator’s clock (between the timed points either side, at the speed of that leg), and flies the rest. An arrival flies on to where the path meets a STAR of the runway in use; an overflight flies across the area;
- a departure flies its SID, then its path;
- an untimed path starts at its first point, flown at 420 kt.
Lifecycle events
Every step is an event, for the app’s own state machine: logs, boards, sounds, or rules of its own.
ManagerOptions.OnEventis called with each event, in order, outside the manager’s lock, so it may call the manager.Events()is a channel of 256 events; events are dropped when it is full.
| Kind | When |
|---|---|
added, turnaround |
A flight entered the schedule, or an arrival and a departure became one aircraft. |
status |
Any status change (Previous → Flight.Status), including spawning, cancelled and done. |
retry, blocked |
A spawn failed and will be tried again, or found its place taken. |
delayed, estimated |
A check moved a spawn, or changed an estimate. |
held, released |
A ground-stop hold started or ended. |
removed |
The aircraft left the simulator. |
enabled, disabled |
Spawning was switched on or off. |
Boards
Board(icao) returns an airport’s departures and arrivals by time. Each ManagedFlight carries its status, Estimated, Note (held, landing flow, late inbound), TurnFrom/TurnTo, the model, stand and runway, and Err when it was cancelled.
On the airport map
The Schedule section has Scheduled traffic: ▶ Start / ■ Stop, density and max aircraft, the airports whose timetables run (the loaded one by default; others are loaded on start), and the Departures, Arrivals and Overflights boards, with a board per managed airport.
The spawner for scheduled flights (enroute arrivals and overflights appear airborne, see above; their labels show call sign, flight level and destination, and Overflights is a third board):
- picks a model in the airline’s livery (
ModelsFor); - plans the flight to or from the other end (SID, airways, level), or falls back to the runway’s SID or STAR;
- uses the runway in use, a free stand, the airport’s service vehicles (tug, fuel truck, stairs, GPU: Ground services) and automatic de-icing.
Other traffic is a layer in the Map section (Other traffic), drawn in blue. It is off by default and listed apart from ours. There you can set whether the schedule respects or ignores it, and ✕ removes one of those aircraft from the simulator.
The API:
GET /api/schedulereturns the settings and every flight.POST /api/scheduletakes{"enabled", "airports": ["LKPR", "LKTB"] (or "icao"), "density", "maxAircraft", "seed", "ifr", "vfr", "generator", "offsetMin", "others": "respect"|"ignore", "startStands", "nightStops"}(world.ScheduleSettings).startStandsandnightStopssize, for this session, the departures put on their stands per airport when its traffic begins and those parked there through the night (#1677): absent keeps what is set, 0 the default again (halfmaxAircraft;nightStopsthe tuning’s), negative none. A session’snightStopswins over the tuning’s.GET /api/schedulegives them back when set.GET /api/flightslists the manager’s flights;POST /api/flightsadds flights (Traffic World).GET /api/boards?icao=returns an airport’s departures and arrivals.POST /api/world/remove {"objectId"}removes an aircraft that is not ours.