88#include < variant>
99
1010bool ProcedureAssigner::should_process (const EuroScopePlugIn::CFlightPlan& flight_plan,
11- bool ignore_already_assigned) const
11+ bool ignore_already_assigned) const
1212{
1313 if (flight_plan.GetClearenceFlag ())
1414 return false ; // No reason to change it from under the ATCO
1515
1616 const auto adep = std::string (flight_plan.GetFlightPlanData ().GetOrigin ());
17- if (std::find (std::begin (airports), std::end (airports), adep) ==
18- std::end (airports))
17+ if (ranges::find (airports, adep) == std::end (airports))
1918 return false ; // Not an airport we handle
2019
2120 if (!flight_plan.IsValid () || !flight_plan.GetCorrelatedRadarTarget ().IsValid ())
@@ -51,10 +50,10 @@ bool ProcedureAssigner::should_process(const EuroScopePlugIn::CFlightPlan& fligh
5150}
5251
5352std::optional<std::string> ProcedureAssigner::get_runway (const EuroScopePlugIn::CFlightPlan& flight_plan,
54- const std::string& sid_fix) const
53+ const std::string& sid_fix) const
5554{
5655 const std::string origin = flight_plan.GetFlightPlanData ().GetOrigin ();
57- if (departure_runways->find (origin) == departure_runways-> end ( ))
56+ if (! departure_runways->contains (origin))
5857 {
5958 return {};
6059 }
@@ -69,8 +68,8 @@ std::optional<std::string> ProcedureAssigner::get_runway(const EuroScopePlugIn::
6968 if (origin == " EBLG" )
7069 {
7170 // For EBLG, we never assign 22R/04L by default
72- const bool has_04R = std ::binary_search (origin_runways. begin (), origin_runways. end () , std::string (" 04R" ));
73- const bool has_22L = std ::binary_search (origin_runways. begin (), origin_runways. end () , std::string (" 22L" ));
71+ const bool has_04R = ranges ::binary_search (origin_runways, std::string (" 04R" ));
72+ const bool has_22L = ranges ::binary_search (origin_runways, std::string (" 22L" ));
7473
7574 if (has_04R)
7675 return " 04R" ;
@@ -83,11 +82,11 @@ std::optional<std::string> ProcedureAssigner::get_runway(const EuroScopePlugIn::
8382
8483 // Should only get here at EBBR
8584 const bool has_25R = std::binary_search (std::begin (origin_runways), std::end (origin_runways),
86- std::string (" 25R" ));
85+ std::string (" 25R" ));
8786 const bool has_19 = std::binary_search (std::begin (origin_runways), std::end (origin_runways),
88- std::string (" 19" ));
87+ std::string (" 19" ));
8988 const bool has_07R = std::binary_search (std::begin (origin_runways), std::end (origin_runways),
90- std::string (" 07R" ));
89+ std::string (" 07R" ));
9190 const char wtc = flight_plan.GetFlightPlanData ().GetAircraftWtc ();
9291
9392 if (has_25R && has_19)
@@ -113,12 +112,13 @@ std::optional<std::string> ProcedureAssigner::get_runway(const EuroScopePlugIn::
113112ProcedureAssigner::ProcedureAssigner (std::function<void (const std::string&)> printer)
114113{
115114 departure_runways = new std::map<std::string, std::vector<std::string>>();
115+ arrival_runways = new std::map<std::string, std::vector<std::string>>();
116116 debug_printer = std::move (printer);
117117}
118118
119119// TODO: a lot of the data in this loop should really be cached between planes in one iteration...
120120std::optional<SidEntry> ProcedureAssigner::process_flight_plan (const EuroScopePlugIn::CFlightPlan& flight_plan,
121- bool force)
121+ bool force)
122122{
123123 const std::string callsign = flight_plan.GetCallsign ();
124124
@@ -210,9 +210,10 @@ size_t ProcedureAssigner::setup_lara(bool always) const
210210 lara_path += " \\ TopSky\\ TopSkyAreasManualAct.txt" ;
211211 std::ifstream ifs (lara_path);
212212 const std::string allocation_file ((std::istreambuf_iterator<char >(ifs)),
213- (std::istreambuf_iterator<char >()));
213+ (std::istreambuf_iterator<char >()));
214214 return lara_parser.parse_string (allocation_file);
215- } catch (exception &e)
215+ }
216+ catch (exception& e)
216217 {
217218 const auto msg = " Could not parse LARA, areas may be inaccurate: " + std::string (e.what ());
218219 debug_printer (msg);
@@ -231,14 +232,16 @@ void ProcedureAssigner::on_disconnect(const EuroScopePlugIn::CFlightPlan& flight
231232 cache.erase (found);
232233}
233234
234- void ProcedureAssigner::set_departure_runways (
235- const std::map<std::string, std::vector<std::string>>& active_departure_runways)
235+ void ProcedureAssigner::set_runways (
236+ const std::map<std::string, std::vector<std::string>>* active_departure_runways, const std::map<std::string, std::
237+ vector<std::string>>*active_arrival_runways)
236238{
237- (*departure_runways) = active_departure_runways;
239+ departure_runways = active_departure_runways;
240+ arrival_runways = active_arrival_runways;
238241 airports.erase (airports.begin (), airports.end ());
239242
240243
241- for (const auto & [fst, snd] : active_departure_runways)
244+ for (const auto & [fst, snd] : * active_departure_runways)
242245 {
243246 airports.insert (fst);
244247 }
@@ -247,12 +250,12 @@ void ProcedureAssigner::set_departure_runways(
247250}
248251
249252std::optional<SidEntry> ProcedureAssigner::suggest (const EuroScopePlugIn::CFlightPlan& flight_plan,
250- bool ignore_already_assigned)
253+ bool ignore_already_assigned)
251254{
252255 const std::string callsign = flight_plan.GetCallsign ();
253256
254257 // See if we have it cached
255- if (cache.find (callsign) != cache. end ( ))
258+ if (cache.contains (callsign))
256259 {
257260 return cache.at (callsign);
258261 }
@@ -264,7 +267,7 @@ std::optional<SidEntry> ProcedureAssigner::suggest(const EuroScopePlugIn::CFligh
264267
265268 typedef boost::split_iterator<std::string::const_iterator> SplitIter;
266269 for (SplitIter i = boost::make_split_iterator (route_text, boost::token_finder (boost::is_space ()));
267- i != SplitIter (); ++i)
270+ i != SplitIter (); ++i)
268271 {
269272 auto route_element = boost::copy_range<std::string>(*i);
270273 for (auto & fix : sid_fixes)
@@ -303,14 +306,16 @@ std::optional<SidEntry> ProcedureAssigner::suggest(const EuroScopePlugIn::CFligh
303306 // Get a tm struct for now in UTC
304307 tm now;
305308 gmtime_s (&now, &raw_time);
309+ const auto chrono_now = std::chrono::system_clock::now ();
306310
307311 const auto areas = lara_parser.get_active (now);
308312
309- auto entry = sid_allocation.find (flight_plan_data.GetOrigin (),
310- sid_fix,
311- flight_plan_data.GetDestination (),
312- flight_plan_data.GetEngineNumber (),
313- runway, now, areas);
313+ const std::string adep = flight_plan_data.GetOrigin ();
314+ auto entry = sid_allocation.find (adep,
315+ sid_fix,
316+ flight_plan_data.GetDestination (),
317+ flight_plan_data.GetEngineNumber (),
318+ runway, chrono_now, areas, arrival_runways->at (adep));
314319 cache.insert_or_assign (callsign, entry);
315320 return entry;
316321}
0 commit comments