Mercurial > atc
diff atcgame/maps.py @ 47:d2efdc4ff196
Initial reorganization of the code
author | Josef "Jeff" Sipek <jeffpc@josefsipek.net> |
---|---|
date | Fri, 01 Jun 2007 02:32:48 -0400 |
parents | |
children | 955cd24d7a05 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/atcgame/maps.py Fri Jun 01 02:32:48 2007 -0400 @@ -0,0 +1,107 @@ +#/* +# * ATC - Air Traffic Controller simulation game +# * +# * Copyright (C) 2004-2007 Josef "Jeff" Sipek <jeffpc@josefsipek.net> +# * +# * This program is free software; you can redistribute it and/or modify +# * it under the terms of the GNU General Public License version 2 as +# * published by the Free Software Foundation. +# * +# * This program is distributed in the hope that it will be useful, +# * but WITHOUT ANY WARRANTY; without even the implied warranty of +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# * GNU General Public License for more details. +# */ + +import os +import sys + +import config +import beacon + +def get_map_info(file): + fd = open(file, 'r') + s = fd.read() + fd.close() + + s = s.split("\n") + + return Map( float(s[0]), # centerx + float(s[1]), # centery + float(s[2]), # mperpix + float(s[3]), # atcx + float(s[4])) # atcy + +def get_navaids(file, m): + fd = open(file, 'r') + s = fd.read() + fd.close() + + s = s.split("\n") + + for line in s: + if (line.__len__() == 0): + continue + + line = line.split(" ") + + m.ninfo.append({ + "xoff": float(line[0]), + "yoff": float(line[1]), + "freq": float(line[2]), + "name": line[3], + "type": line[4], + "output": float(line[5])}) + +class Map: + def __init__(self, centerx, centery, mperpix, atcx, atcy): + self.centerx = centerx + self.centery = centery + self.mperpix = mperpix + self.atcx = atcx + self.atcy = atcy + + self.ninfo = [] + self.navs = [] + + self.image = "" + + def bootstrap(self): + for nav in self.ninfo: + if nav["type"] == "VOR": + self.navs.append(beacon.VOR_Beacon(nav["name"], nav["freq"], (nav["xoff"], nav["yoff"]))) + elif nav["type"] == "ILS": + pass # FIXME: ILS beacons are little complicated + + def cleanup(self): + while self.navs.__len__(): + self.navs.pop() + +MAPS = [] + +maps_dir = os.listdir(config.maps_dir) + +for map_dir in maps_dir: + files = os.listdir(config.maps_dir + "/" + map_dir) + + if (files.count("map.info") == 0): + print "Missing " + config.maps_dir + "/" + map_dir + "/map.info" + sys.exit(1) + + if (files.count("map.png") == 0): + print "Missing " + config.maps_dir + "/" + map_dir + "/map.png" + sys.exit(1) + + if (files.count("navaid.info") == 0): + print "Missing " + config.maps_dir + "/" + map_dir + "/navaid.info" + sys.exit(1) + + map_info = get_map_info(config.maps_dir + "/" + map_dir + "/map.info") + get_navaids(config.maps_dir + "/" + map_dir + "/navaid.info", map_info) + + map_info.image = config.maps_dir + "/" + map_dir + "/map.png" + + MAPS.append(map_info) + print "Parsed and added '" + map_dir + "' map (" + str(map_info.ninfo.__len__()) + " navaids)" + +print "Added " + str(MAPS.__len__()) + " maps"