view atc_plane_specs.py @ 23:b2ed1770081f

Load the plane specs at start up from files committer: Jeff <jeffpc@batlh.(none)> 1121707415 -0400
author Jeff <jeffpc@batlh.(none)>
date Mon, 18 Jul 2005 17:23:35 -0400
parents 4a95c5552d3b
children c93c3c910c85
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

# all measurements in meters/sec or meters
plane_SPECS	= []

plane_dir = os.listdir(atc_config.plane_spec_dir)

for f in plane_dir:
	plane = {"fullname": str(None),
		 "name": str(None),
		 "heavy": False,
		 "jet": False,
		 "stall_speed": 0.0,
		 "climb_normal": 0.0,
		 "max_altitude": 0.0}
	
	fd = open(atc_config.plane_spec_dir + "/" + f, 'r')
	s = fd.read()
	fd.close()
	
	s = s.split("\n")
	for line in s:
		if (line.__len__()==0):
			continue
		
		cmd = line[:line.find(' ')-1]
		param = line[line.find(' ')+1:]
		
		if	cmd=="FullName":
			plane["fullname"] = param
		elif	cmd=="Name":
			plane["name"] = param
		elif	cmd=="Heavy":
			if (param.upper() == "YES"):
				plane["heavy"] = True
			else:
				plane["heavy"] = False
		elif	cmd=="Jet":
			if (param.upper() == "YES"):
				plane["jet"] = True
			else:
				plane["jet"] = False
		elif	cmd=="StallSpeed":
			plane["stall_speed"] = float(param)
		elif	cmd=="ClimbNormal":
			plane["climb_normal"] = float(param)
		elif	cmd=="MaxAltitude":
			plane["max_altitude"] = float(param)
		else:
			print "Error parsing " + f + ": Unknown statement"
			sys.exit(1)
	
	plane_SPECS.append(plane)
	print "Parsed and added " + plane["fullname"] + " aka. " + plane["name"]

print "Added " + str(plane_SPECS.__len__()) + " plane types"