diff --git a/PythonPlugins/PI_XSayATC.py b/PythonPlugins/PI_XSayATC.py index 15f69c8..300790e 100644 --- a/PythonPlugins/PI_XSayATC.py +++ b/PythonPlugins/PI_XSayATC.py @@ -1441,18 +1441,43 @@ class XSayATC: if close: return "nearby traffic within 5 nm (issue traffic advisory)" - # 3) Pas zajety — jesli pilot wybral pas i ktos na nim jest (start/ladowanie). + # 3) Pas zajety — tylko gdy pilot jest BLISKO lotniska (< 15 nm). + # Inaczej po odlocie ATC gadalby o pasie oddalonego lotniska w petli. if self.selected_runway and self._runway_icao: - occ = self._runway_occupants(self._runway_icao, self.selected_runway) - if occ: - desc = ", ".join( - f"{o['phase_name']} (key 0x{o['key']:X})" if isinstance(o.get('key'), int) else o['phase_name'] - for o in occ - ) - return f"runway {self.selected_runway} occupied: {desc}" + runway = self._find_runway(self._runway_icao, self.selected_runway) + if runway: + plat, plon = self._pilot_latlon() + if plat is not None: + mid_lat = (runway["lat1"] + runway["lat2"]) / 2.0 + mid_lon = (runway["lon1"] + runway["lon2"]) / 2.0 + if self._dist_nm(plat, plon, mid_lat, mid_lon) < 15.0: + occ = self._runway_occupants(self._runway_icao, self.selected_runway) + if occ: + desc = ", ".join( + f"{o['phase_name']} (key 0x{o['key']:X})" if isinstance(o.get('key'), int) else o['phase_name'] + for o in occ + ) + return f"runway {self.selected_runway} occupied: {desc}" return None + def _pilot_latlon(self): + """Zwraca (lat, lon) pilota lub (None, None).""" + lat = self._get_dataref("sim/flightmodel/position/latitude", is_float=True) + lon = self._get_dataref("sim/flightmodel/position/longitude", is_float=True) + return lat, lon + + def _dist_nm(self, lat1, lon1, lat2, lon2): + """Odleglosc (nm) miedzy dwoma punktami (haversine).""" + import math + R = 3440.065 # promien Ziemi w milach morskich + p1 = math.radians(lat1) + p2 = math.radians(lat2) + dp = math.radians(lat2 - lat1) + dl = math.radians(lon2 - lon1) + a = math.sin(dp / 2) ** 2 + math.cos(p1) * math.cos(p2) * math.sin(dl / 2) ** 2 + return 2 * R * math.asin(math.sqrt(a)) + def _read_int_array(self, ref, count): """Czyta tablice int z datarefu (indeksowaną slotem).""" if ref is None: