Mercurial > atc
annotate 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 |
rev | line source |
---|---|
10
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
1 #/* |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
2 # * ATC - Air Traffic Controller simulation game |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
3 # * |
11
300ba3412449
Fixed velocity calc formulas
Jeff Sipek <jeffpc@jeff.(none)>
parents:
10
diff
changeset
|
4 # * Copyright (C) 2005 Josef "Jeff" Sipek <jeffpc@optonline.net> |
10
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
5 # * |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
6 # * This program is free software; you can redistribute it and/or modify |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
7 # * it under the terms of the GNU General Public License as published by |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
8 # * the Free Software Foundation; either version 2 of the License, or |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
9 # * (at your option) any later version. |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
10 # * |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
11 # * This program is distributed in the hope that it will be useful, |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
12 # * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
13 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
14 # * GNU General Public License for more details. |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
15 # * |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
16 # * You should have received a copy of the GNU General Public License |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
17 # * along with this program; if not, write to the Free Software |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
18 # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
19 # * |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
20 # * @(#) %M% %I% %E% %U% |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
21 # */ |
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
22 |
23
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
23 import os |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
24 import sys |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
25 import atc_config |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
26 |
10
7bb4cd2fa1bc
Changed window size from 800x600 to 1024x768
Jeff Sipek <jeffpc@jeff.(none)>
parents:
diff
changeset
|
27 # all measurements in meters/sec or meters |
23
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
28 plane_SPECS = [] |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
29 |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
30 plane_dir = os.listdir(atc_config.plane_spec_dir) |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
31 |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
32 for f in plane_dir: |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
33 plane = {"fullname": str(None), |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
34 "name": str(None), |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
35 "heavy": False, |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
36 "jet": False, |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
37 "stall_speed": 0.0, |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
38 "climb_normal": 0.0, |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
39 "max_altitude": 0.0} |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
40 |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
41 fd = open(atc_config.plane_spec_dir + "/" + f, 'r') |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
42 s = fd.read() |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
43 fd.close() |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
44 |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
45 s = s.split("\n") |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
46 for line in s: |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
47 if (line.__len__()==0): |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
48 continue |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
49 |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
50 cmd = line[:line.find(' ')-1] |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
51 param = line[line.find(' ')+1:] |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
52 |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
53 if cmd=="FullName": |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
54 plane["fullname"] = param |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
55 elif cmd=="Name": |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
56 plane["name"] = param |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
57 elif cmd=="Heavy": |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
58 if (param.upper() == "YES"): |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
59 plane["heavy"] = True |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
60 else: |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
61 plane["heavy"] = False |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
62 elif cmd=="Jet": |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
63 if (param.upper() == "YES"): |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
64 plane["jet"] = True |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
65 else: |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
66 plane["jet"] = False |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
67 elif cmd=="StallSpeed": |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
68 plane["stall_speed"] = float(param) |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
69 elif cmd=="ClimbNormal": |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
70 plane["climb_normal"] = float(param) |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
71 elif cmd=="MaxAltitude": |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
72 plane["max_altitude"] = float(param) |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
73 else: |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
74 print "Error parsing " + f + ": Unknown statement" |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
75 sys.exit(1) |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
76 |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
77 plane_SPECS.append(plane) |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
78 print "Parsed and added " + plane["fullname"] + " aka. " + plane["name"] |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
79 |
b2ed1770081f
Load the plane specs at start up from files
Jeff <jeffpc@batlh.(none)>
parents:
13
diff
changeset
|
80 print "Added " + str(plane_SPECS.__len__()) + " plane types" |