# HG changeset patch # User Jeff Sipek # Date 1120807571 14400 # Node ID 300ba3412449febc757649d0d7d132862bd68129 # Parent 7bb4cd2fa1bc545b31979bcf63303a7abc888fa9 Fixed velocity calc formulas Moved (0,0) to the center of the screen, x goes right, y goes up Added HEAD command (change heading) Colon separates Flight Number and command, both ':' and ';' produce it Copyright notice update as needed (2005) committer: Jeff Sipek 1120793171 -0400 diff -r 7bb4cd2fa1bc -r 300ba3412449 atc.py --- a/atc.py Fri Jul 08 01:37:01 2005 -0400 +++ b/atc.py Fri Jul 08 03:26:11 2005 -0400 @@ -3,7 +3,7 @@ #/* # * ATC - Air Traffic Controller simulation game # * -# * Copyright (C) 2004 Josef "Jeff" Sipek +# * Copyright (C) 2004, 2005 Josef "Jeff" Sipek # * # * This program is free software; you can redistribute it and/or modify # * it under the terms of the GNU General Public License as published by diff -r 7bb4cd2fa1bc -r 300ba3412449 atc_plane.py --- a/atc_plane.py Fri Jul 08 01:37:01 2005 -0400 +++ b/atc_plane.py Fri Jul 08 03:26:11 2005 -0400 @@ -1,7 +1,7 @@ #/* # * ATC - Air Traffic Controller simulation game # * -# * Copyright (C) 2004 Josef "Jeff" Sipek +# * Copyright (C) 2004, 2005 Josef "Jeff" Sipek # * # * This program is free software; you can redistribute it and/or modify # * it under the terms of the GNU General Public License as published by @@ -108,8 +108,8 @@ return if ijk == None: - self.vel["i"] = self.vel["speed"]*cos(self.vel["climb"]/self.vel["speed"]) - self.vel["j"] = self.vel["speed"]*cos(self.vel["heading"]) + self.vel["i"] = sin(self.vel["heading"]) * sqrt(self.vel["speed"]**2 - self.vel["climb"]**2) + self.vel["j"] = cos(self.vel["heading"]) * sqrt(self.vel["speed"]**2 - self.vel["climb"]**2) self.vel["k"] = self.vel["climb"] else: self.vel["heading"] = self.calc_head() @@ -135,8 +135,8 @@ self.complete_vel(ijk=1) - if (self.pos["X"] < 0) or (self.pos["Y"] < 0): # FIXME: max values - self.status = plane_RANGE + #if (self.pos["X"] < 0) or (self.pos["Y"] < 0): # FIXME: max values + # self.status = plane_RANGE if (self.pos["Z"] < 0): self.vel["i"] = self.vel["j"] = self.vel["k"] = 0 @@ -145,7 +145,7 @@ if (self.vel["speed"]0) and (-self.vel["j"]>0): # east and north - return pi/2 - head - if (self.vel["i"]<0) and (-self.vel["j"]>0): # west and north - return head + 3*pi/2 - if (self.vel["i"]>0) and (-self.vel["j"]<0): # east and south - return head + pi/2 - if (self.vel["i"]==0) and (-self.vel["j"]>0): # north - return head - return head + pi # west and south / south + return head - def calc_geo(self, xy): + def calc_geo(self, xy, prefix): """ Return a geographic coodrinate-formated xy """ df = m2pix(pix2geo(xy)) + minus = prefix[0] + if df<0: + df *= -1 + minus = prefix[1] d = floor(df) mf = (df-d) * 60.0 m = floor(mf) s = (mf-m) * 60.0 - return "%dd %02dm %02ds" % (int(d), int(m), int(s)) + return "%s %dd %02dm %02ds" % (minus, int(d), int(m), int(s)) def process(self,cmd): """ Process a user command """ @@ -196,13 +192,22 @@ self.complete_vel(ijk=1) if (parts[0] == "HEAD"): - print "Changing heading to " + parts[1] - self.targetHead = int(parts[1]) + self.vel["heading"] = int(parts[1]) + while(True): + if self.vel["heading"]>=360: + self.vel["heading"] -= 360 + elif self.vel["heading"]<0: + self.vel["heading"] += 360 + else: + break + print "Changing heading to " + str(self.vel["heading"]) + self.vel["heading"] *= pi/180.0 + self.complete_vel(hac=1) def display(self,screen): """ Put everything onto the screen """ - screen.blit(self.image, (int(m2pix(self.pos["X"])), int(m2pix(self.pos["Y"])))) + screen.blit(self.image, (int(1024/2+m2pix(self.pos["X"])), int(768/2-m2pix(self.pos["Y"])))) # Plane info font = pygame.font.Font(None, 16) @@ -211,16 +216,16 @@ if (self.status == plane_CRASHED) or (self.status == plane_DEAD): color = atc_colors.planeinfo_crashed - x = int(m2pix(self.pos["X"])) + 10 - y = int(m2pix(self.pos["Y"])) - 5 + x = int(1024/2+m2pix(self.pos["X"])) + 10 + y = int(768/2-m2pix(self.pos["Y"])) - 5 # FIXME: display geographic coordinates with NSWE appended/prepended strings = ( self.flightno, self.callsign + " " + str(self.status), "Alt: " + str(int(self.pos["Z"])), - "Lat: " + self.calc_geo(self.pos["X"]), - "Long: " + self.calc_geo(self.pos["Y"]), - "Head: " + str(int(atc_utils.todeg(self.calc_head()))), + "Lat: " + self.calc_geo(self.pos["Y"],"NS"), + "Long: " + self.calc_geo(self.pos["X"],"EW"), + "Head: " + str(int(atc_utils.todeg(self.vel["heading"]))), "AS: " + str(int(self.vel["speed"]*3.6))) for stri in strings: diff -r 7bb4cd2fa1bc -r 300ba3412449 atc_plane_specs.py --- a/atc_plane_specs.py Fri Jul 08 01:37:01 2005 -0400 +++ b/atc_plane_specs.py Fri Jul 08 03:26:11 2005 -0400 @@ -1,7 +1,7 @@ #/* # * ATC - Air Traffic Controller simulation game # * -# * Copyright (C) 2004 Josef "Jeff" Sipek +# * Copyright (C) 2005 Josef "Jeff" Sipek # * # * This program is free software; you can redistribute it and/or modify # * it under the terms of the GNU General Public License as published by diff -r 7bb4cd2fa1bc -r 300ba3412449 atc_single.py --- a/atc_single.py Fri Jul 08 01:37:01 2005 -0400 +++ b/atc_single.py Fri Jul 08 03:26:11 2005 -0400 @@ -1,7 +1,7 @@ #/* # * ATC - Air Traffic Controller simulation game # * -# * Copyright (C) 2004 Josef "Jeff" Sipek +# * Copyright (C) 2004, 2005 Josef "Jeff" Sipek # * # * This program is free software; you can redistribute it and/or modify # * it under the terms of the GNU General Public License as published by @@ -142,7 +142,10 @@ cmd += '8' if (event.key == pygame.K_9) or (event.key == pygame.K_KP9): cmd += '9' - + + if (event.key == pygame.K_COLON) or (event.key == pygame.K_SEMICOLON): + cmd += ': ' + if event.key == pygame.K_SPACE: cmd += " " @@ -181,24 +184,12 @@ pygame.display.flip() -def is_cmd(cmd): - if cmd=="ALT": - return True - return False - def cmd_plane(cmd): - parts = cmd.split(' ') - ret = "" - for par in parts: - if is_cmd(par): - break; - ret += par + " " - return ret[:-1] + return cmd.split(': ')[0] def cmd_cmd(cmd): - p = cmd_plane(cmd) - - return cmd[p.__len__()+1:] + # FIXME: what if no split happens? + return cmd.split(': ')[1] if (__name__ == '__main__'): print "Don't do it!"