local c={}local X={}local o={}local K={}for V,R in pairs(_Tune.Ratios)do local g={}local l={}local H={}local t={}for c=0,math.ceil((_Tune.Redline+100)/100),1 do local X={}local o={}local K={}local R={}if c~=0 then if _Tune.Engine then X.Horsepower,X.Torque=GetNCurve(c*100,V-2)if _TCount~=0 then K.Horsepower,K.Torque=GetTCurve(c*100,V-2)else K.Horsepower,K.Torque=0,0 end if _SCount~=0 then R.Horsepower,R.Torque=GetSCurve(c*100,V-2)else R.Horsepower,R.Torque=0,0 end else X.Horsepower,X.Torque=0,0 K.Horsepower,K.Torque=0,0 R.Horsepower,R.Torque=0,0 end if _Tune.Electric then o.Horsepower,o.Torque=GetECurve(c*100,V-2)else o.Horsepower,o.Torque=0,0 end else X.Horsepower,X.Torque=0,0 o.Horsepower,o.Torque=0,0 K.Horsepower,K.Torque=0,0 R.Horsepower,R.Torque=0,0 end if _Tune.Engine then nhp,ntq=GetNCurve((c+1)*100,V-2)if _TCount~=0 then thp,ttq=GetTCurve((c+1)*100,V-2)else thp,ttq=0,0 end if _SCount~=0 then shp,stq=GetSCurve((c+1)*100,V-2)else shp,stq=0,0 end else nhp,ntq=0,0 thp,ttq=0,0 shp,stq=0,0 end if _Tune.Electric then ehp,etq=GetECurve((c+1)*100,V-2)else ehp,etq=0,0 end X.HpSlope,X.TqSlope=nhp-X.Horsepower,ntq-X.Torque o.HpSlope,o.TqSlope=ehp-o.Horsepower,etq-o.Torque K.HpSlope,K.TqSlope=thp-K.Horsepower,ttq-K.Torque R.HpSlope,R.TqSlope=shp-R.Horsepower,stq-R.Torque g[c]=X l[c]=o H[c]=K t[c]=R end table.insert(c,g)table.insert(X,l)table.insert(o,H)table.insert(K,t)end
--Output Cache
local NCache = {}
local ECache = {}
local TCache = {}
local SCache = {}

for gear, ratio in pairs(_Tune.Ratios) do
	local nhpPlot = {}
	local ehpPlot = {}
	local thpPlot = {}
	local shpPlot = {}
	for rpm = 0, math.ceil((_Tune.Redline + 100) / 100) do
		local ntqPlot = {}
		local etqPlot = {}
		local ttqPlot = {}
		local stqPlot = {}
		if rpm ~= 0 then
			if _Tune.Engine then
				ntqPlot.Horsepower, ntqPlot.Torque = GetNCurve(rpm * 100, gear - 2)
				if _TCount ~= 0 then
					ttqPlot.Horsepower, ttqPlot.Torque = GetTCurve(rpm * 100, gear - 2)
				else
					ttqPlot.Horsepower, ttqPlot.Torque = 0, 0
				end
				if _SCount ~= 0 then
					stqPlot.Horsepower, stqPlot.Torque = GetSCurve(rpm * 100, gear - 2)
				else
					stqPlot.Horsepower, stqPlot.Torque = 0, 0
				end
			else
				ntqPlot.Horsepower, ntqPlot.Torque = 0, 0
				ttqPlot.Horsepower, ttqPlot.Torque = 0, 0
				stqPlot.Horsepower, stqPlot.Torque = 0, 0
			end
			if _Tune.Electric then
				etqPlot.Horsepower, etqPlot.Torque = GetECurve(rpm * 100, gear - 2)
			else
				etqPlot.Horsepower, etqPlot.Torque = 0, 0
			end
		else
			ntqPlot.Horsepower, ntqPlot.Torque = 0, 0
			etqPlot.Horsepower, etqPlot.Torque = 0, 0
			ttqPlot.Horsepower, ttqPlot.Torque = 0, 0
			stqPlot.Horsepower, stqPlot.Torque = 0, 0
		end
		if _Tune.Engine then
			nhp, ntq = GetNCurve((rpm + 1) * 100, gear - 2)
			if _TCount ~= 0 then
				thp, ttq = GetTCurve((rpm + 1) * 100, gear - 2)
			else
				thp, ttq = 0, 0
			end
			if _SCount ~= 0 then
				shp, stq = GetSCurve((rpm + 1) * 100, gear - 2)
			else
				shp, stq = 0, 0
			end
		else
			nhp, ntq = 0, 0
			thp, ttq = 0, 0
			shp, stq = 0, 0
		end
		if _Tune.Electric then
			ehp, etq = GetECurve((rpm + 1) * 100, gear - 2)
		else
			ehp, etq = 0, 0
		end
		ntqPlot.HpSlope, ntqPlot.TqSlope = (nhp - ntqPlot.Horsepower), (ntq - ntqPlot.Torque)
		etqPlot.HpSlope, etqPlot.TqSlope = (ehp - etqPlot.Horsepower), (etq - etqPlot.Torque)
		ttqPlot.HpSlope, ttqPlot.TqSlope = (thp - ttqPlot.Horsepower), (ttq - ttqPlot.Torque)
		stqPlot.HpSlope, stqPlot.TqSlope = (shp - stqPlot.Horsepower), (stq - stqPlot.Torque)
		nhpPlot[rpm] = ntqPlot
		ehpPlot[rpm] = etqPlot
		thpPlot[rpm] = ttqPlot
		shpPlot[rpm] = stqPlot
	end
	table.insert(NCache, nhpPlot)
	table.insert(ECache, ehpPlot)
	table.insert(TCache, thpPlot)
	table.insert(SCache, shpPlot)
end
