-
Notifications
You must be signed in to change notification settings - Fork 4
/
partcost.py
167 lines (161 loc) · 6.24 KB
/
partcost.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# 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
markup = {
"tank": 1.2,
"welded tank": 1.4,
"structural": 1.1,
"workshop": 25,
"pad": 2.5,
"smelter": 20,
"science": 44,
"auger": 1.5,
"detector": 12.8,
}
part_type={
"TAL.Large.HalfSpherical.Tank.Fuel":"tank",
"TAL.Large.HalfSpherical.Tank.V2.Fuel":"tank",
"TAL.Large.Spherical.Tank.Fuel":"tank",
"TAL.Large.Spherical.Tank.V2.Fuel":"tank",
"TAL.Medium.HalfSpherical.Tank.Fuel":"tank",
"TAL.Medium.HalfSpherical.Tank.V2.Fuel":"tank",
"TAL.Medium.Spherical.Tank.Fuel":"tank",
"TAL.Medium.Spherical.Tank.V2.Fuel":"tank",
"TAL.Small.HalfSpherical.Tank.Fuel":"tank",
"TAL.Small.HalfSpherical.Tank.V2.Fuel":"tank",
"TAL.Small.Spherical.Tank.Fuel":"tank",
"TAL.Small.Spherical.Tank.V2.Fuel":"tank",
"TAL.Toroidal.Tank.Large.Fuel":"tank",
"TAL.Toroidal.Tank.Medium.Fuel":"tank",
"TAL.Toroidal.Tank.Small.Fuel":"tank",
"TAL.XLarge.Toroidal.Tank.Fuel":"tank",
"TAL_Toroidal_Tank_Hub_Large":"tank",
"TAL_Toroidal_Tank_Hub_Medium":"tank",
"TAL_Toroidal_Tank_Hub_Small":"tank",
"TAL_Toroidal_Tank_Hub_XLarge":"tank",
"TAL.Radial.Experiment.Storage.Container":"science",
"TAL.Cubic.Truss.Mini.0.5m":"structural",
"TAL.Cubic.Truss.Mini.1.5m":"structural",
"TAL.Cubic.Truss.Mini.5m":"structural",
"TAL.Cubic.Truss.Mini.1m":"structural",
"TAL.Cubic.Truss.Mini.2.5m":"structural",
"TAL.Cubic.Truss.Mini.Adapter.Large":"structural",
"TAL.Cubic.Truss.Mini.Adapter.Long":"structural",
"TAL.Cubic.Truss.Mini.Adapter.Short":"structural",
"TAL.Cubic.Truss.Mini.Half":"structural",
"TAL.Cubic.Truss.Mini.Hub":"structural",
"TAL.Cubic.Truss.10m":"structural",
"TAL.Cubic.Truss.1m":"structural",
"TAL.Cubic.Truss.2m":"structural",
"TAL.Cubic.Truss.3m":"structural",
"TAL.Cubic.Truss.5m":"structural",
"TAL.Cubic.Truss.Adapter.Large":"structural",
"TAL.Cubic.Truss.Adapter.Long":"structural",
"TAL.Cubic.Truss.Adapter.Short":"structural",
"TAL.Cubic.Truss.Half":"structural",
"TAL.Cubic.Truss.Hub":"structural",
"TAL.Extended.Radial.Mount.Large":"structural",
"TAL.Extended.Radial.Mount.Medium":"structural",
"TAL.Extended.Radial.Mount.Small":"structural",
"TAL.Flush.Radial.Mount.Large":"structural",
"TAL.Flush.Radial.Mount.Medium":"structural",
"TAL.Flush.Radial.Mount.Small":"structural",
"Auger":"auger",
"SmallAuger":"auger",
"TinyAuger":"auger",
"HexCanMetalHuge":"tank",
"HexCanMetalLarge":"tank",
"HexCanMetal":"tank",
"HexCanMetalSmall":"tank",
"HexCanOreHuge":"tank",
"HexCanOreLarge":"tank",
"HexCanOre":"tank",
"HexCanOreSmall":"tank",
"HexCanRocketPartsHuge":"tank",
"HexCanRocketPartsLarge":"tank",
"HexCanRocketParts":"tank",
"HexCanRocketPartsSmall":"tank",
"RocketpartsHuge7x":"welded tank",
"RocketpartsLarge7x":"welded tank",
"Rocketparts7x":"welded tank",
"RocketpartsSmall7x":"welded tank",
"Magnetometer":"detector",
"OMD":"detector",
"ExOrbitalDock":"pad",
"ExSurveyStake":"structural",
"ExMallet":"structural",
"ExWorkshop":"workshop",
"ELTankLargeMTL":"tank",
"ELTankLargeORE":"tank",
"ELTankLargeRP":"tank",
"ELTankMedMTL":"tank",
"ELTankMedORE":"tank",
"ELTankMedRP":"tank",
"ELTankSmlMTL":"tank",
"ELTankSmlORE":"tank",
"ELTankSmlRP":"tank",
"exLaunchPad":"workshop",
"exLaunchPad2":"workshop",
"RocketBuilder":"workshop",
"exRunway":"pad",
"Smelter":"smelter",
"SmallSmelter":"smelter",
"TinySmelter":"smelter",
"adapter3m1m7":"structural",
}
def find_parts(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
pname = node.GetValue("name").strip()
mass = node.GetValue("mass").strip()
cost = node.GetValue("cost").strip()
costLine = node.GetValueLine("cost")
ecost = node.GetValue("entryCost").strip()
newcost = float(mass) * markup[part_type[pname]] * rp_cost
rescost = get_resource_cost(node.GetNodes("RESOURCE"))
#rescost = 0
c = float(cost)
m = float(mass)
#print ("%s c %s m %s c/m %f e %s n %g r %g n + r %g (c-r)/m %g %g" % (pname, cost, mass, c / m, ecost, newcost, rescost, newcost + rescost, (c - rescost) / m, (c - rescost) / m / rp_cost))
#print (r"sed -i -e '%ds/\<cost\>\s*=\s*%s\>/cost = %g\r\n\tTechRequired = specializedConstruction\r\n\tentryCost = 2000/' '%s'" % (costLine + lineoffs, cost, newcost + rescost, path))
if cost != ("%g" % (newcost + rescost)):
print (r"sed -i -e '%ds/\<cost\>\s*=\s*%s\>.*/cost = %g/' '%s'" % (costLine + lineoffs, cost, newcost + rescost, path))
#lineoffs += 2
recurse_tree("/home/bill/ksp/KSP_linux/GameData", find_resources)
pprint(resources)
rp_cost = float(resources["RocketParts"].GetValue("unitCost")) / float(resources["RocketParts"].GetValue("density"))
recurse_tree("/home/bill/ksp/KSP_linux/GameData/TalisarParts", find_parts)
recurse_tree("/home/bill/ksp/src/Extraplanetary-Launchpads/GameData/ExtraplanetaryLaunchpads", find_parts)
recurse_tree("/home/bill/ksp/KSP_linux/GameData/mystuff", find_parts)