view atc_maps.py @ 42:05245904f997

Slight change in map specs Map parsing is more OOP-ish
author Josef "Jeff" Sipek <jeffpc@optonline.net>
date Fri, 19 Aug 2005 19:09:27 -0500
parents dde511571317
children 1757b7e8d09f
line wrap: on
line source

#/*
# * ATC - Air Traffic Controller simulation game
# *
# * Copyright (C) 2005 Josef "Jeff" Sipek <jeffpc@optonline.net>
# *
# * 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
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * 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.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# *
# * @(#) %M% %I% %E% %U%
# */

import os
import sys
import atc_config

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	= ""

MAPS	= []

maps_dir = os.listdir(atc_config.maps_dir)

for map_dir in maps_dir:
	files = os.listdir(atc_config.maps_dir + "/" + map_dir)
	
	if (files.count("map.info") == 0):
		print "Missing " + atc_config.maps_dir + "/" + map_dir + "/map.info"
		sys.exit(1)
	
	if (files.count("map.png") == 0):
		print "Missing " + atc_config.maps_dir + "/" + map_dir + "/map.png"
		sys.exit(1)
	
	if (files.count("navaid.info") == 0):
		print "Missing " + atc_config.maps_dir + "/" + map_dir + "/navaid.info"
		sys.exit(1)
	
	map_info = get_map_info(atc_config.maps_dir + "/" + map_dir + "/map.info")
	get_navaids(atc_config.maps_dir + "/" + map_dir + "/navaid.info", map_info)
	
	map_info.image = atc_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"