コード例 #1
0
ファイル: aeroplane.py プロジェクト: quasipedia/atc-ng
 def update(self, pings):
     '''
     Update the plane status according to the elapsed time.
     Pings = number of radar pings from last update.
     '''
     burning_speed = 1 if self.pilot.status['haste'] == 'normal' else 2
     initial = self.position.copy()
     for i in range(pings):
         # Pilot's updates
         self.pilot.update()
     # Compute waiting time score if not airborne
     # FIXME: distinguish between just landed and waiting to takeoff
     if self.flags.on_ground:
         mult = pings * S.PING_IN_SECONDS
         self.aerospace.gamelogic.score_event(S.PLANE_WAITS_ONE_SECOND,
                                              multiplier=mult)
     # Decrease fuel amount if airborne
     elif self.fuel > 0:
         dist = U.ground_distance(initial, self.position)
         burnt = burning_speed * dist * self.fuel_efficiency
         self.fuel -= burnt
         self.aerospace.gamelogic.score_event(S.PLANE_BURNS_FUEL_UNIT,
                                              multiplier=burnt)
     # Check if a fuel emergency has to be triggered.
     # FIXME: this is goo reason to use objects intstead of IATA/NAME
     try:
         dest_point = self.aerospace.airports[self.destination].location
     except KeyError:
         tmp = self.aerospace.gates[self.destination].location
         dest_point = Vector3(tmp[0], tmp[1], self.altitude)
     dist = U.ground_distance(dest_point, self.position)
     self.fuel_delta = self.fuel - (2 * dist * self.fuel_efficiency)
     self.dist_to_target = dist
     if not self.flags.fuel_emergency and self.fuel_delta < 0:
         log.info('%s is declaring fuel emergency' % self.icao)
         msg = 'Pan-Pan, Pan-Pan, Pan-Pan... We are low on fuel, ' \
               'requesting priority landing!'
         self.pilot.say(msg, S.KO_COLOUR)
         self.aerospace.gamelogic.score_event(S.EMERGENCY_FUEL)
         self.flags.fuel_emergency = True
     # Fuel has ran out
     if self.fuel < 0:
         msg = 'Mayday! Mayday! Mayday! All engines have flamed out, we ' \
               'are going down!'
         self.pilot.say(msg, S.KO_COLOUR)
         log.info('%s has ran out of fuel' % self.icao)
         self.fuel = 0
         self.max_speed = self.min_speed * 2
         max_down = self.climb_rate_limits[0]
         self.climb_rate_limits = [max_down, max_down / 2.0]
     # Update sprite
     self.rect = U.sc(self.position.xy)
     self.trail.appendleft(U.sc(self.position.xy))
コード例 #2
0
ファイル: aerospace.py プロジェクト: quasipedia/atc-ng
 def __draw_radar_aid(self):
     '''
     Draw the radar aid.
     '''
     if not S.RADAR_AID:
         return
     centre = U.sc((S.RADAR_RANGE, S.RADAR_RANGE))
     # Find how many metres a step consist of, making sure the final value
     # is sensible (not 12735.5, for example...)
     sensibles = [n*1000 for n in (1, 5, 10, 20, 25, 50, 100)]
     attempts = [S.RADAR_RANGE * 2 / n for n in sensibles]
     closest = min(attempts, key = lambda x : abs(x-S.RADAR_AID_STEPS))
     metres_per_step = sensibles[attempts.index(closest)]
     if S.RADAR_AID == 'circles':
         step_range = range(metres_per_step, U.rint(S.RADAR_RANGE*2**0.5),
                            metres_per_step)
         for radius in step_range:
             pygame.draw.circle(self.surface, S.RADAR_AID_COLOUR, centre,
                                U.rint(radius/S.METRES_PER_PIXEL), 1)
     elif S.RADAR_AID in ('grid', 'crosses', 'dots'):
         # In the following line: since division is integer division, this
         # will ensure that on marking will pass from the radar position
         first = S.RADAR_RANGE - S.RADAR_RANGE/metres_per_step*metres_per_step
         step_range = range(first, S.RADAR_RANGE * 2 + metres_per_step,
                            metres_per_step)
         draw = lambda fm, to : pygame.draw.aaline(self.surface,
                                   S.RADAR_AID_COLOUR, U.sc(fm), U.sc(to))
         for step in step_range:
             if S.RADAR_AID == 'grid':
                 draw((step, 0), (step, S.RADAR_RANGE*2))
                 draw((0, step), (S.RADAR_RANGE*2, step))
             elif S.RADAR_AID in ('dots', 'crosses'):
                 for step2 in step_range:
                     if S.RADAR_AID == 'dots':
                         pygame.draw.circle(self.surface, S.RADAR_AID_COLOUR,
                                            U.sc((step, step2)), 2)
                     elif S.RADAR_AID == 'crosses':
                         x, y = step, step2
                         offset = U.rint(metres_per_step / 16.0)
                         draw((x-offset, y), (x+offset, y))
                         draw((x, y-offset), (x, y+offset))
     else:
             msg = 'Wrong value of `RADAR_AID` in config file!'
             raise BaseException(msg)
     S.RADAR_MARKING = metres_per_step
コード例 #3
0
ファイル: testutils.py プロジェクト: quasipedia/atc-ng
 def testSc(self):
     '''
     sc - transform coordinates from "world logic" to radar screen
     '''
     for i in range(100):
         x = randint(0, 2 * S.RADAR_RANGE)
         y = randint(0, 2 * S.RADAR_RANGE)
         x, y = U.sc((x,y))
         self.assertGreaterEqual(x, 0)
         self.assertLessEqual(x, S.RADAR_RECT.width)
         self.assertGreaterEqual(y, 0)
         self.assertLessEqual(y, S.RADAR_RECT.height)
コード例 #4
0
ファイル: waypoints.py プロジェクト: quasipedia/atc-ng
 def draw(self, surface):
     '''
     Blit self on radar surface.
     '''
     x, y = U.sc(self.location)
     # GATE
     # In order to facilitate blitting information on the orientation of the
     # gate, we create the image already rotated 90° clockwise by swapping
     # width and height...
     gate_width_px = U.rint(self.width / S.METRES_PER_PIXEL)
     gate_length_px = S.RADAR_RECT.h / 4
     aaf = 5  #anti-alias factor
     g_img = pygame.surface.Surface((gate_length_px*aaf,
                                     gate_width_px*aaf), SRCALPHA)
     # BOUNDARIES OF THE GATE
     pygame.draw.line(
          g_img, S.GRAY, (0, aaf), (gate_length_px*aaf, aaf), aaf)
     pygame.draw.line(
          g_img, S.GRAY, (0, gate_width_px*aaf-aaf),
          (gate_length_px*aaf, gate_width_px*aaf-aaf), aaf)
     # INFO ON ORIENTATION and FLIGHT LEVELS
     fl = lambda x : str(x/100).zfill(2)
     lines = ['H:' + str(self.heading).zfill(3),
              'B:' + fl(self.bottom),
              'T:' + fl(self.top)]
     fontobj = pygame.font.Font(S.MAIN_FONT, S.HUD_INFO_FONT_SIZE * aaf)
     label = U.render_lines(fontobj, lines, S.GRAY)
     label = label.subsurface(label.get_bounding_rect())
     w, h = label.get_size()
     ypsilon = U.rint(gate_width_px*aaf/2.0-h/2)
     g_img.blit(label, (0, ypsilon))
     g_img.blit(label, (gate_length_px*aaf-w, ypsilon))
     # tranformation and blitting
     rotang = 90 if 0<= self.heading < 180 else 270
     g_img = pygame.transform.rotate(g_img, rotang-self.heading)
     g_img = g_img.subsurface(g_img.get_bounding_rect()).copy()
     r = g_img.get_rect()
     g_img = pygame.transform.smoothscale(g_img, (U.rint(r.w*1.0/aaf),
                                                  U.rint(r.h*1.0/aaf)))
     g_rect = g_img.get_rect()
     surface.blit(g_img, (x-g_rect.centerx, y-g_rect.centery))
     # LABEL
     fontobj = pygame.font.Font(S.MAIN_FONT, S.HUD_INFO_FONT_SIZE)
     label = fontobj.render(self.name, True, S.RED)
     w, h = label.get_size()
     signed_offset = lambda n : cmp(1,n)*w
     x += (signed_offset(x) if self.side <=0 else 0) - w/2
     y += (signed_offset(y) if self.side >=0 else 0) - h/2
     surface.blit(label, (x,y))
コード例 #5
0
ファイル: waypoints.py プロジェクト: quasipedia/atc-ng
 def draw(self, surface):
     pos = U.sc(self.location)
     pygame.draw.circle(surface, S.GRAY, pos, 2)
     pygame.draw.circle(surface, S.GRAY, pos, 6, 1)
     fontobj = pygame.font.Font(S.MAIN_FONT, S.HUD_INFO_FONT_SIZE)
     label = fontobj.render(self.id, True, S.BLUE)
     label = label.subsurface(label.get_bounding_rect()).copy()
     w, h = label.get_size()
     x, y = pos
     # In order to keep the crammed central space free, beacons labels are
     # always placed towards the edges of the radar screen, if possible.
     offsets = [U.rint(6+w/3), -U.rint(6+w/3)-w]
     index = x < S.RADAR_RECT.w/2
     if not (0 < x+offsets[index] and x+offsets[index]+w < S.RADAR_RECT.w):
         index = not index
     surface.blit(label, (x+offsets[index], y-h/2))
コード例 #6
0
ファイル: aerospace.py プロジェクト: quasipedia/atc-ng
 def add_airport(self, a_port):
     '''
     Add an airport to the aerospace.
     '''
     self.__airports[a_port.iata] = a_port
     a_image = a_port.get_image(scale=1.0/S.METRES_PER_PIXEL,
                                with_labels=False)
     # Place airport on radar
     offset = Vector3(-a_image.get_width()/2, -a_image.get_height()/2).xy
     centre = U.sc(a_port.location.xy)
     pos = (centre[0]+offset[0], centre[1]+offset[1])
     self.surface.blit(a_image, pos)
     # Draw IATA name
     fontobj = pygame.font.Font(S.MAIN_FONT, S.HUD_INFO_FONT_SIZE)
     label = fontobj.render(a_port.iata, True, S.GREEN)
     pos = centre[0]-label.get_width()/2, centre[1]-label.get_height()/2
     self.surface.blit(label, pos)
コード例 #7
0
ファイル: aeroplane.py プロジェクト: quasipedia/atc-ng
 def __init__(self, aerospace, **kwargs):
     # Required parameters/properties
     self.aerospace = aerospace
     self.tcas = Tcas(self)
     for property in self.KNOWN_PROPERTIES:
         setattr(self, property, kwargs[property])
     # Initialisation of other properties
     self.entry_time = time()
     self.min_speed = self.landing_speed*1.5
     self.flags = Flags()
     if self.origin in aerospace.airports:
         self.flags.on_ground = True
     self.time_last_cmd = time()
     self.trail = deque(
            [U.sc(self.position.xy)] * S.TRAIL_LENGTH, S.TRAIL_LENGTH)
     self.colliding_planes = []
     self.__accelerometer = ' '
     self.__variometer = ' '
     self.pilot = pilot.pilot.Pilot(self)
     self.fuel_delta = self.fuel / 2
     self.dist_to_target = self.fuel / self.fuel_efficiency / 4
コード例 #8
0
ファイル: login.py プロジェクト: GuoJing/jguoer-web
 def POST(self):
     req = gd()
     authen = authen_user(req.name, req.pwd)
     if authen:
         sc('name', req.name)
     return js(dict(r=True, authen=authen))
コード例 #9
0
ファイル: login.py プロジェクト: GuoJing/jguoer-web
 def POST(self):
     req = gd()
     authen = authen_user(req.name, req.pwd)
     if authen:
         sc('name', req.name)
     return js(dict(r=True, authen=authen))
コード例 #10
0
ファイル: logout.py プロジェクト: GuoJing/jguoer-web
 def GET(self):
     name = gc('name')
     sc('name','',-2)
     return st("admin/login.mako", **locals())
コード例 #11
0
ファイル: logout.py プロジェクト: GuoJing/jguoer-web
 def GET(self):
     name = gc('name')
     sc('name', '', -2)
     return st("admin/login.mako", **locals())