view atc_maps.py @ 35:c0c52fb4a7fd

Moved most of single player game code into new class Game() This will simplify code management between single/multi-player game modes
author Josef "Jeff" Sipek <jeffpc@optonline.net>
date Thu, 18 Aug 2005 00:14:13 -0500
parents dde511571317
children 05245904f997
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")
	
	m = {	"centerx": float(s[0]),
		"centery": float(s[1]),
		"mperpix": float(s[2]),
		"towerx":  float(s[3]),
		"towery":  float(s[4])}
	
	return m

def get_navaids(file, m):
	fd = open(file, 'r')
	s = fd.read()
	fd.close()
	
	s = s.split("\n")
	
	NAVS = []
	
	for line in s:
		if (line.__len__() == 0):
			continue
		
		line = line.split(" ")
		
		nav = {	"xoff": float(line[0]),
			"yoff": float(line[1]),
			"freq": float(line[2]),
			"name": line[3],
			"type": line[4],
			"output": float(line[5])}
			
		NAVS.append(nav)
	
	m["navs"] = NAVS
	
	return m

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")
	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["navs"].__len__()) + " navaids)"
	
print "Added " + str(MAPS.__len__()) + " maps"