-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathispfix.py
118 lines (110 loc) · 3.63 KB
/
ispfix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# vim:ts=4:et
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
from cfgnode import *
from kspdata import *
from pprint import *
import sys
import os
def uses_intakeair(engine):
propellants = engine.GetNodes("PROPELLANT")
for p in propellants:
if p.GetValue("name") == "IntakeAir":
return True
return False
def engine_modules(node):
modules = node.GetNodes("MODULE")
em = []
for m in modules:
if m.GetValue("name") not in "ModuleEnginesFX":
continue
if uses_intakeair(m):
continue
em.append (m)
return em
engine_blacklist = {
"ionEngine", #no change
"radialEngineMini",
"nuclearEngine",
"sepMotor1", #improved in 1.0
"microEngine",
"solidBooster_sm", #new engine
}
engine_isp = {}
def collect_isps(path):
if path[-4:].lower() != ".cfg":
return
text = open(path, "rt").read()
try:
cfg = ConfigNode.load(text)
except ConfigNodeError as e:
#print(path+e.message)
return
lineoffs = 0
for n in cfg.nodes:
name, node, line = n
if name != "PART":
continue
mass = node.GetValue("mass");
engines = engine_modules (node)
if not engines:
continue
for e in engines:
atmCrv = e.GetNode ("atmosphereCurve")
keys = atmCrv.GetValues("key")
isp = keys[0].split(" ")[1]
engine_isp[node.GetValue("name")] = isp
def find_engines(path):
if path[-4:].lower() != ".cfg":
return
text = open(path, "rt").read()
try:
cfg = ConfigNode.load(text)
except ConfigNodeError as e:
#print(path+e.message)
return
lineoffs = 0
for n in cfg.nodes:
name, node, line = n
if name != "PART":
continue
mass = node.GetValue("mass");
engines = engine_modules (node)
if not engines:
continue
pname = node.GetValue("name")
if pname in engine_blacklist:
continue
print("@PART[%s] {" % pname)
for e in engines:
print("\t@MODULE[%s]:HAS[!PROPELLANT[IntakeAir]] {" % e.GetValue("name"))
atmCrv = e.GetNode ("atmosphereCurve")
keys = atmCrv.GetValues("key")
visp = keys[0].split(" ")[1]
aisp = keys[1].split(" ")[1]
aisp = float(aisp)*float(engine_isp[pname])/float(visp)
print("\t\t@atmosphereCurve:HAS[#key[0?%s]] {" % visp)
print("\t\t\t@key,0 = 0 %s" % engine_isp[pname])
print("\t\t\t@key,1 = 1 %g" % aisp)
print("\t\t}")
print("\t}")
print("}")
recurse_tree("/home/bill/ksp/KSP_linux-0.90/GameData/Squad", collect_isps)
recurse_tree("/home/bill/ksp/KSP_linux-0.90/GameData/NASAmission", collect_isps)
recurse_tree("/home/bill/ksp/KSP_linux/GameData/Squad", find_engines)