mw-modpack/scripts/fier/ug2-tires.py

243 lines
6.1 KiB
Python

#!/usr/bin/env python3
import sys
import os
oldexcepthook = sys.excepthook
def newexcepthook(type,value,traceback):
oldexcepthook(type,value,traceback)
input("Press ENTER to quit.")
sys.excepthook = newexcepthook
p = os.path.join
pUp = os.path.dirname
s = False
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
s = os.path.realpath(sys.executable)
else:
s = os.path.realpath(__file__)
sp = pUp(s)
os.chdir(sp)
nfsmsScript = s.replace(".py",".nfsms")
properties = """\
update_field tires replaceme DYNAMIC_GRIP Front 1.6
update_field tires replaceme DYNAMIC_GRIP Rear 1.6
update_field tires replaceme GRIP_SCALE Front 1
update_field tires replaceme GRIP_SCALE Rear 1
update_field tires replaceme STATIC_GRIP Front 2.2
update_field tires replaceme STATIC_GRIP Rear 2.2
update_field tires replaceme STEERING 0.4
update_field tires replaceme YAW_CONTROL[0] 1
update_field tires replaceme YAW_CONTROL[1] 1
update_field tires replaceme YAW_CONTROL[2] 1
update_field tires replaceme YAW_CONTROL[3] 1
update_field tires replaceme YAW_SPEED 0.7
update_field tires replaceme_top DYNAMIC_GRIP Front 1.6
update_field tires replaceme_top DYNAMIC_GRIP Rear 1.6
update_field tires replaceme_top GRIP_SCALE Front 1.6
update_field tires replaceme_top GRIP_SCALE Rear 1.8
update_field tires replaceme_top STATIC_GRIP Front 2.2
update_field tires replaceme_top STATIC_GRIP Rear 2.2
update_field tires replaceme_top STEERING 0.4
update_field tires replaceme_top YAW_CONTROL[0] 10
update_field tires replaceme_top YAW_CONTROL[1] 10
update_field tires replaceme_top YAW_CONTROL[2] 10
update_field tires replaceme_top YAW_CONTROL[3] 10
update_field tires replaceme_top YAW_SPEED 0.65
update_field pvehicle replaceme TENSOR_SCALE Y 2.2
update_field rigidbodyspecs racers DRAG_ANGULAR Y -100
update_field rigidbodyspecs racers GROUND_MOMENT_SCALE Y 2
\
"""
carlist = ["911gt2","911turbo","997s","a3","a4","bmwm3gtr","bmwm3gtre46","camaro","carreragt","caymans","clio","clk500","cobaltss","corvette","corvettec6r","cts","db9","eclipsegt","elise","fordgt","gallardo","gti","gto","imprezawrx","is300","lancerevo8","monaro","murcielago","mustanggt","punto","rx7","rx8","sl500","sl65","slr","supra","tt","viper"]
carlistNoTop = ["911gt2","bmwm3gtr","bmwm3gtre46","camaro","corvettec6r","rx8speedt","sl65"]
topBias = {
"911gt2": 0.8,
"911turbo": 0.6,
"997s": 0.6,
"a3": 0.2,
"a4": 0.2,
"bmwm3gtr": 1.0,
"bmwm3gtre46": 0.4,
"camaro": 0.0,
"carreragt": 0.9,
"caymans": 0.6,
"clio": 0.2,
"clk500": 0.2,
"cobaltss": 0.1,
"corvette": 0.4,
"corvettec6r": 1.0,
"cts": 0.1,
"db9": 0.7,
"eclipsegt": 0.4,
"elise": 0.6,
"fordgt": 0.6,
"gallardo": 0.6,
"gti": 0.2,
"gto": 0.1,
"imprezawrx": 0.4,
"is300": 0.0,
"lancerevo8": 0.5,
"monaro": 0.1,
"murcielago": 0.3,
"mustanggt": 0.1,
"punto": 0.2,
"rx7": 0.3,
"rx8": 0.2,
"sl500": 0.5,
"sl65": 0.4,
"slr": 0.6,
"supra": 0.3,
"tt": 0.3,
"viper": 0.4
}
nfsmsMods = {}
nfsmsModsTop = {}
for car in carlist:
nfsmsMods[car] = {}
nfsmsMods[car]["tires"] = {}
# Grip scale
nfsmsMods["elise"]["tires"]["GRIP_SCALE Front"] = 0.4
nfsmsMods["elise"]["tires"]["GRIP_SCALE Rear"] = 0.4
parsedVlt = []
for line in properties.split("\n"):
line = line.strip(" \t\r")
arg = ""
args = []
for c in line:
if c == "#": break
if c in [" ","\t"]:
if arg != "":
args.append(arg)
arg = ""
continue
arg = arg + c
if arg != "":
args.append(arg)
arg = ""
if len(args) > 0:
parsedVlt.append(args)
def findLine(linef,ls):
linef = linef.copy()
linef.pop(-1)
linef.pop(2)
linefLength = len(linef)
for line in reversed(ls):
length = len(line) - 2
if length != linefLength: continue
lineo = line
line = line.copy()
line.pop(-1)
line.pop(2)
index = 0
success = True
while index < length:
if linef[index] != line[index]:
success = False
break
index += 1
if success == False: continue
return lineo
return False
def lineToPropPair(line):
line = line.copy()
cat = line[1]
line.pop(0)
line.pop(0)
line.pop(0)
line.pop(-1)
line = " ".join(line)
return [cat,line]
def getNfsmsMod(car,line,isTop = False):
prop = lineToPropPair(line)
if isTop:
if car in nfsmsModsTop:
if prop[0] in nfsmsModsTop[car]:
if prop[1] in nfsmsModsTop[car][prop[0]]:
return nfsmsModsTop[car][prop[0]][prop[1]]
if car in nfsmsMods:
if prop[0] in nfsmsMods[car]:
if prop[1] in nfsmsMods[car][prop[0]]:
return nfsmsMods[car][prop[0]][prop[1]]
return False
nfsmsMisc = []
nfsmsCars = {}
for car in carlist:
for line in parsedVlt:
line = line.copy()
isCarLine = False
isTopLine = False
if "replaceme" in line:
isCarLine = True
if "replaceme_top" in line:
isCarLine = True
isTopLine = True
if isCarLine == False:
nfsmsMisc.append(line)
continue
if not car in nfsmsCars:
nfsmsCars[car] = [[],[]]
if not isTopLine:
nfsmsCars[car][0].append(line)
else:
nfsmsCars[car][1].append(line)
for car in nfsmsCars:
for line in nfsmsCars[car][0]:
if line[0] != "update_field": continue
mult = getNfsmsMod(car,line)
if mult == False: continue
line[-1] = str(float(line[-1]) * mult)
for line in nfsmsCars[car][1]:
if line[0] != "update_field": continue
mult = getNfsmsMod(car,line,True)
if mult == False: continue
line[-1] = str(float(line[-1]) * mult)
for car in nfsmsCars:
if not (car in topBias): continue
for line in nfsmsCars[car][0]:
if line[0] != "update_field": continue
if line[1] in ["ecar","pvehicle"]: continue
topLine = findLine(line,nfsmsCars[car][1])
if topLine == False:
print("Warning, no top line found: " +(" ".join(line)))
continue
topLine = topLine.copy()
topLine[-1] = float(topLine[-1])
line[-1] = float(line[-1])
line[-1] = str(line[-1] + ((topLine[-1] - line[-1])*topBias[car]))
file = open(nfsmsScript,"w")
for car in nfsmsCars:
for line in nfsmsCars[car][0]:
if line[2] == "replaceme": line[2] = car
file.write(" ".join(line) + "\n")
if car in carlistNoTop: continue
for line in nfsmsCars[car][1]:
if line[2] == "replaceme_top": line[2] = car + "_top"
file.write(" ".join(line) + "\n")
for line in nfsmsMisc:
file.write(" ".join(line) + "\n")
file.close()