Exemplo n.º 1
0
 def new_departure_DEP(self, goal_point):
     acft_type = choice(
         self.parkable_aircraft_types if self.parkable_aircraft_types != []
         else self.playable_aircraft_types)
     rwy = rnd_rwy([
         rwy
         for rwy in env.airport_data.allRunways() if rwy.use_for_departures
     ], lambda rwy: rwy.acceptsAcftType(acft_type))
     if rwy == None:
         return None
     thr = rwy.threshold()
     hdg = rwy.orientation()
     pos = thr.moved(hdg, settings.solo_TWR_range_dist)
     try:  # Check for separation
         horiz_dist = [
             pos.distanceTo(acft.params.position)
             for acft in self.controlled_traffic if acft.isOutboundGoal()
         ]
         if time_to_fly(min(horiz_dist),
                        cruise_speed(acft_type)) < TTF_separation:
             return None
     except ValueError:
         pass  # No departures in the sky yet
     alt = GS_alt(env.elevation(thr), rwy.param_FPA, pos.distanceTo(thr))
     ias = restrict_speed_under_ceiling(cruise_speed(acft_type), alt,
                                        StdPressureAlt.fromFL(100))
     params = SoloParams(Status(Status.AIRBORNE), pos, alt, hdg, ias)
     params.XPDR_code = env.nextSquawkCodeAssignment(XPDR_range_IFR_DEP)
     acft = self.mkAiAcft(acft_type, params, (goal_point, None))
     acft.instructions.append(
         Instruction(Instruction.VECTOR_ALT,
                     arg=settings.solo_initial_climb_reading))
     return acft
Exemplo n.º 2
0
	def updateButtons(self):
		cs = self.createCallsign_edit.text()
		t = self.createAircraftType_edit.getAircraftType()
		ok = cs != ''
		ok &= all(cs != acft.identifier for acft in settings.session_manager.getAircraft())
		ok &= cs not in env.ATCs.knownATCs()
		ok &= t in known_aircraft_types() and cruise_speed(t) != None
		self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(ok)
 def updateEET(self):
     if self.EETfromSpeed_radioButton.isChecked():
         self.EET_info.setText(
             TTF_str(self.route_length, Speed(self.speed_edit.value())))
     elif self.EETfromACFT_radioButton.isChecked():
         crspd = cruise_speed(self.acftType_select.getAircraftType())
         if crspd == None:
             self.EET_info.setText('(unknown ACFT cruise speed)')
         else:
             try:
                 self.EET_info.setText(TTF_str(self.route_length, crspd))
             except ValueError:
                 self.EET_info.setText('(speed too low)')
Exemplo n.º 4
0
 def spawnNewUncontrolledAircraft(self):
     rndpos = env.radarPos().moved(Heading(randint(1, 360), True),
                                   uniform(10, .8 * settings.radar_range))
     rndalt = StdPressureAlt(randint(1, 10) * 1000)
     if self.airbornePositionFullySeparated(rndpos, rndalt):
         acft_type = choice(self.uncontrolled_aircraft_types)
         params = SoloParams(Status(Status.AIRBORNE), rndpos, rndalt,
                             Heading(randint(1, 360), True),
                             cruise_speed(acft_type))
         params.XPDR_code = settings.uncontrolled_VFR_XPDR_code
         new_acft = self.mkAiAcft(acft_type, params, goal=None)
         if new_acft != None:
             self.uncontrolled_traffic.append(new_acft)
Exemplo n.º 5
0
 def __init__(self, gui):
     SessionManager.__init__(self, gui)
     self.session_type = SessionType.SOLO
     self.session_ticker = Ticker(self.tickSessionOnce, parent=gui)
     self.weather_ticker = Ticker(self.setNewWeather, parent=gui)
     self.spawn_timer = QTimer(gui)
     self.spawn_timer.setSingleShot(True)
     self.voice_instruction_recogniser = None
     self.speech_synthesiser = None
     self.msg_is_from_session_manager = False  # set to True before sending to avoid chat msg being rejected
     if speech_recognition_available:
         try:
             self.voice_instruction_recogniser = InstructionRecogniser(gui)
         except RuntimeError as err:
             settings.solo_voice_instructions = False
             QMessageBox.critical(self.gui, 'Sphinx error', \
              'Error setting up the speech recogniser (check log): %s\nVoice instructions disabled.' % err)
     if speech_synthesis_available:
         try:
             self.speech_synthesiser = SpeechSynthesiser(gui)
         except Exception as err:
             settings.solo_voice_readback = False
             QMessageBox.critical(self.gui, 'Pyttsx error', \
              'Error setting up the speech synthesiser: %s\nPilot read-back disabled.' % err)
     self.controlled_traffic = []
     self.uncontrolled_traffic = []
     self.current_local_weather = None
     self.simulation_paused_at = None  # start time if session is paused; None otherwise
     self.spawn_timer.timeout.connect(
         lambda: self.spawnNewControlledAircraft(isSessionStart=False))
     self.playable_aircraft_types = settings.solo_aircraft_types[:]
     self.uncontrolled_aircraft_types = [
         t for t in known_aircraft_types() if cruise_speed(t) != None
     ]
     pop_all(self.playable_aircraft_types,
             lambda t: t not in known_aircraft_types())
     pop_all(self.playable_aircraft_types,
             lambda t: cruise_speed(t) == None)
Exemplo n.º 6
0
 def new_arrival_TWR(self):
     acft_type = choice(
         self.parkable_aircraft_types if self.parkable_aircraft_types != []
         else self.playable_aircraft_types)
     ils = random() >= settings.solo_ILSvsVisual_balance
     rwy_ok = lambda rwy: rwy.acceptsAcftType(acft_type) and (not ils or rwy
                                                              .hasILS())
     rwy = rnd_rwy([
         rwy
         for rwy in env.airport_data.allRunways() if rwy.use_for_arrivals
     ], rwy_ok)
     if rwy == None:
         return None
     dthr = rwy.threshold(dthr=True)
     try:
         furthest = max([
             dthr.distanceTo(acft.params.position)
             for acft in self.controlled_traffic if acft.isInboundGoal()
         ])
         dist = max(
             furthest + uniform(1, 2) *
             distance_flown(TTF_separation, cruise_speed(acft_type)),
             settings.solo_TWR_range_dist)
     except ValueError:
         dist = settings.solo_TWR_range_dist / 2
     if dist > min(settings.solo_TWR_range_dist * 1.5,
                   settings.radar_range - 10):
         return None  # to protect from creating aircraft out of radar range
     status = Status(Status.LANDING, arg=rwy.name) if ils else Status(
         Status.AIRBORNE)
     hdg = rwy.appCourse()
     alt = GS_alt(env.elevation(dthr), rwy.param_FPA,
                  max(2, dist if ils else dist - 2))
     params = SoloParams(status,
                         env.radarPos().moved(hdg.opposite(), dist), alt,
                         hdg, touch_down_speed(acft_type))
     params.XPDR_code = env.nextSquawkCodeAssignment(XPDR_range_IFR_ARR)
     acft = self.mkAiAcft(acft_type, params, ils)
     acft.instructions.append(
         Instruction(Instruction.EXPECT_RWY, arg=rwy.name))
     if ils:
         acft.instructions.append(Instruction(Instruction.CLEARED_APP))
     return acft
Exemplo n.º 7
0
	def acftInitParams(self):
		if self.ground_status_radioButton.isChecked():
			status = Status(Status.TAXIING)
		elif self.ready_status_radioButton.isChecked():
			status = Status(Status.READY, arg=self.depRWY_select.currentText())
		else: # airborne status radio button must be ticked
			status = Status(Status.AIRBORNE)
		pos = self.spawn_coords
		hdg = self.spawn_hdg
		if self.airborne_status_radioButton.isChecked():
			ias = cruise_speed(self.createAircraftType_edit.getAircraftType())
			alt = StdPressureAlt.fromFL(self.airborneFL_edit.value())
		else: # on ground
			ias = Speed(0)
			alt = env.groundStdPressureAlt(pos)
			if self.parked_tickBox.isChecked() and self.closest_PKG != None:
				pkinf = env.airport_data.ground_net.parkingPosInfo(self.closest_PKG)
				pos = pkinf[0]
				hdg = pkinf[1]
		return SoloParams(status, pos, alt, hdg, ias)
Exemplo n.º 8
0
	def __init__(self, spawn_coords, spawn_hdg, parent=None):
		QDialog.__init__(self, parent)
		self.setupUi(self)
		self.createCallsign_edit.setClearButtonEnabled(True)
		self.installEventFilter(RadioKeyEventFilter(self))
		self.createAircraftType_edit.setAircraftFilter(lambda t: cruise_speed(t) != None)
		self.airline_codes = known_airline_codes()
		self.createAircraftType_edit.setEditText(CreateTrafficDialog.last_known_acft_type_used)
		self.startFrozen_tickBox.setChecked(CreateTrafficDialog.last_start_frozen)
		self.createStripLink_tickBox.setChecked(CreateTrafficDialog.last_strip_link)
		self.suggestCallsign()
		if env.airport_data == None:
			self.allow_taxi = False
			self.closest_PKG = None
			self.nearby_THRs = []
		else:
			self.allow_taxi = env.airport_data.ground_net.closestNode(spawn_coords, maxdist=max_spawn_GND_dist) != None
			self.closest_PKG = env.airport_data.ground_net.closestParkingPosition(spawn_coords, maxdist=max_spawn_PKG_dist)
			self.nearby_THRs = [r.name for r in env.airport_data.allRunways() if r.threshold().distanceTo(spawn_coords) <= max_spawn_THR_dist]
		self.closestParkingPosition_info.setText(some(self.closest_PKG, ''))
		self.depRWY_select.addItems(sorted(self.nearby_THRs))
		self.spawn_coords = spawn_coords
		self.spawn_hdg = spawn_hdg
		self.updateButtons()
		if self.allow_taxi:
			self.ground_status_radioButton.toggled.connect(self.toggleGroundStatus)
			self.ground_status_radioButton.setChecked(True)
			if self.closest_PKG != None:
				self.parked_tickBox.setChecked(True)
		else:
			self.ground_status_radioButton.setEnabled(False)
			self.toggleGroundStatus(False)
		self.depRWY_select.setEnabled(False)
		if self.nearby_THRs == []:
			self.ready_status_radioButton.setEnabled(False)
		elif self.closest_PKG == None:
			self.ready_status_radioButton.setChecked(True)
		self.accepted.connect(self.rememberOptions)
		self.createAircraftType_edit.editTextChanged.connect(self.updateButtons)
		self.createAircraftType_edit.editTextChanged.connect(self.suggestCallsign)
		self.createCallsign_edit.textChanged.connect(self.updateButtons)
Exemplo n.º 9
0
 def new_arrival_APP(self, entry_point):
     type_choice = self.parkable_aircraft_types if self.parkable_aircraft_types != [] else self.playable_aircraft_types
     # must be landable too
     rwy_choice = [
         rwy for rwy in env.airport_data.allRunways()
         if rwy.use_for_arrivals
     ]
     if rwy_choice == []:
         rwy_choice = env.airport_data.allRunways()
     pop_all(
         type_choice,
         lambda t: all(not rwy.acceptsAcftType(t) for rwy in rwy_choice))
     if type_choice == []:
         return None
     acft_type = choice(type_choice)
     ils = any(rwy.hasILS() for rwy in
               rwy_choice) and random() >= settings.solo_ILSvsVisual_balance
     if entry_point == None:
         hdg = Heading(randint(1, 360), True)
         pos = env.radarPos().moved(
             hdg.opposite(),
             uniform(.33 * settings.radar_range,
                     .75 * settings.radar_range))
     else:
         pos = entry_point.coordinates
         hdg = pos.headingTo(env.radarPos())
     alt = StdPressureAlt.fromFL(
         10 * randint(settings.solo_APP_ceiling_FL_min // 10,
                      settings.solo_APP_ceiling_FL_max // 10))
     if not self.airbornePositionFullySeparated(pos, alt):
         return None
     ias = restrict_speed_under_ceiling(
         cruise_speed(acft_type), alt,
         StdPressureAlt.fromFL(150))  # 5000-ft anticipation
     params = SoloParams(Status(Status.AIRBORNE), pos, alt, hdg, ias)
     params.XPDR_code = env.nextSquawkCodeAssignment(XPDR_range_IFR_ARR)
     return self.mkAiAcft(acft_type, params, ils)
Exemplo n.º 10
0
    def generateAircraftAndStrip(self):
        start_angle = uniform(0, 360)
        start_pos = env.radarPos().moved(Heading(start_angle, True),
                                         settings.solo_CTR_range_dist)
        end_pos = env.radarPos().moved(
            Heading(start_angle + 90 + uniform(1, 179), True),
            settings.solo_CTR_range_dist)
        transit_hdg = start_pos.headingTo(end_pos)
        dep_ad = world_navpoint_db.findClosest(env.radarPos().moved(transit_hdg.opposite(), \
          uniform(1.2 * settings.map_range, 5000)), types=[Navpoint.AD])
        dest_ad = world_navpoint_db.findClosest(env.radarPos().moved(transit_hdg, \
          uniform(1.2 * settings.map_range, 5000)), types=[Navpoint.AD])
        if env.pointOnMap(dep_ad.coordinates) or env.pointOnMap(
                dest_ad.coordinates):
            return None, None

        candidate_midpoints = [p for code in settings.solo_CTR_routing_points \
          for p in env.navpoints.findAll(code, types=[Navpoint.NDB, Navpoint.VOR, Navpoint.FIX]) \
          if start_pos.distanceTo(p.coordinates) < start_pos.distanceTo(end_pos)]
        midpoint = None if candidate_midpoints == [] else choice(
            candidate_midpoints)

        FLd10 = randint(settings.solo_CTR_floor_FL // 10,
                        settings.solo_CTR_ceiling_FL // 10)
        if settings.solo_CTR_semi_circular_rule == SemiCircRule.E_W and (FLd10 % 2 == 0) != (transit_hdg.magneticAngle() >= 180) \
         or settings.solo_CTR_semi_circular_rule == SemiCircRule.N_S and (FLd10 % 2 == 1) != (90 <= transit_hdg.magneticAngle() < 270):
            FLd10 += 1
            if 10 * FLd10 > settings.solo_CTR_ceiling_FL:
                return None, None
        p_alt = StdPressureAlt.fromFL(10 * FLd10)
        if not self.airbornePositionFullySeparated(start_pos, p_alt):
            return None, None
        acft_type = choice(self.playable_aircraft_types)
        hdg = start_pos.headingTo(some(midpoint, dest_ad).coordinates)
        params = SoloParams(Status(Status.AIRBORNE), start_pos, p_alt, hdg,
                            cruise_speed(acft_type))
        params.XPDR_code = env.nextSquawkCodeAssignment(XPDR_range_IFR_transit)
        new_acft = self.mkAiAcft(acft_type, params, dest_ad)
        dist_key = lambda atc: env.ATCs.getATC(atc).position.distanceTo(
            start_pos)
        received_from = min(env.ATCs.knownATCs(), key=dist_key)

        strip = Strip()
        strip.writeDetail(FPL.CALLSIGN, new_acft.identifier)
        strip.writeDetail(FPL.ACFT_TYPE, new_acft.aircraft_type)
        strip.writeDetail(FPL.WTC, wake_turb_cat(new_acft.aircraft_type))
        strip.writeDetail(FPL.FLIGHT_RULES, 'IFR')
        strip.writeDetail(FPL.ICAO_DEP, dep_ad.code)
        strip.writeDetail(FPL.ICAO_ARR, dest_ad.code)
        strip.writeDetail(FPL.CRUISE_ALT,
                          env.readStdAlt(new_acft.params.altitude))
        strip.writeDetail(assigned_altitude_detail,
                          strip.lookup(FPL.CRUISE_ALT))
        strip.writeDetail(assigned_SQ_detail, new_acft.params.XPDR_code)
        strip.writeDetail(received_from_detail, received_from)
        if midpoint != None:
            strip.insertRouteWaypoint(midpoint)

        new_acft.instructions.append(
            Instruction(Instruction.FOLLOW_ROUTE,
                        arg=strip.lookup(parsed_route_detail).dup()))
        return new_acft, strip