comparison 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
comparison
equal deleted inserted replaced
46:ca661c5a267b 47:d2efdc4ff196
1 #/*
2 # * ATC - Air Traffic Controller simulation game
3 # *
4 # * Copyright (C) 2004-2007 Josef "Jeff" Sipek <jeffpc@josefsipek.net>
5 # *
6 # * This program is free software; you can redistribute it and/or modify
7 # * it under the terms of the GNU General Public License version 2 as
8 # * published by the Free Software Foundation.
9 # *
10 # * This program is distributed in the hope that it will be useful,
11 # * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # * GNU General Public License for more details.
14 # */
15
16 import os
17 import sys
18
19 import config
20 import beacon
21
22 def get_map_info(file):
23 fd = open(file, 'r')
24 s = fd.read()
25 fd.close()
26
27 s = s.split("\n")
28
29 return Map( float(s[0]), # centerx
30 float(s[1]), # centery
31 float(s[2]), # mperpix
32 float(s[3]), # atcx
33 float(s[4])) # atcy
34
35 def get_navaids(file, m):
36 fd = open(file, 'r')
37 s = fd.read()
38 fd.close()
39
40 s = s.split("\n")
41
42 for line in s:
43 if (line.__len__() == 0):
44 continue
45
46 line = line.split(" ")
47
48 m.ninfo.append({
49 "xoff": float(line[0]),
50 "yoff": float(line[1]),
51 "freq": float(line[2]),
52 "name": line[3],
53 "type": line[4],
54 "output": float(line[5])})
55
56 class Map:
57 def __init__(self, centerx, centery, mperpix, atcx, atcy):
58 self.centerx = centerx
59 self.centery = centery
60 self.mperpix = mperpix
61 self.atcx = atcx
62 self.atcy = atcy
63
64 self.ninfo = []
65 self.navs = []
66
67 self.image = ""
68
69 def bootstrap(self):
70 for nav in self.ninfo:
71 if nav["type"] == "VOR":
72 self.navs.append(beacon.VOR_Beacon(nav["name"], nav["freq"], (nav["xoff"], nav["yoff"])))
73 elif nav["type"] == "ILS":
74 pass # FIXME: ILS beacons are little complicated
75
76 def cleanup(self):
77 while self.navs.__len__():
78 self.navs.pop()
79
80 MAPS = []
81
82 maps_dir = os.listdir(config.maps_dir)
83
84 for map_dir in maps_dir:
85 files = os.listdir(config.maps_dir + "/" + map_dir)
86
87 if (files.count("map.info") == 0):
88 print "Missing " + config.maps_dir + "/" + map_dir + "/map.info"
89 sys.exit(1)
90
91 if (files.count("map.png") == 0):
92 print "Missing " + config.maps_dir + "/" + map_dir + "/map.png"
93 sys.exit(1)
94
95 if (files.count("navaid.info") == 0):
96 print "Missing " + config.maps_dir + "/" + map_dir + "/navaid.info"
97 sys.exit(1)
98
99 map_info = get_map_info(config.maps_dir + "/" + map_dir + "/map.info")
100 get_navaids(config.maps_dir + "/" + map_dir + "/navaid.info", map_info)
101
102 map_info.image = config.maps_dir + "/" + map_dir + "/map.png"
103
104 MAPS.append(map_info)
105 print "Parsed and added '" + map_dir + "' map (" + str(map_info.ninfo.__len__()) + " navaids)"
106
107 print "Added " + str(MAPS.__len__()) + " maps"