require "ATA2TuningTable"
require "SVUC_TuningTable"

local function copy(obj, seen)
	if type(obj) ~= 'table' then return obj end
	if seen and seen[obj] then return seen[obj] end
	local s = seen or {}
	local res = setmetatable({}, getmetatable(obj))
	s[obj] = res
	for k, v in pairs(obj) do res[copy(k, s)] = copy(v, s) end
	return res
end

local function SVU_TuningTable()
	if not getActivatedMods():contains("SCKCO") and not getActivatedMods():contains("VVSR_Continued") then
		local TemplateTuningTable = SVUC_TemplateVehicle()
		local NewCarTuningTable = {}

		-- Specify each vehicle script here.
		-- Entries
		NewCarTuningTable["fhqPorsche918"] = {
			addPartsFromVehicleScript = "",
			parts = {}
		}
		
		NewCarTuningTable["fhqPorsche918Sil"] = {
			addPartsFromVehicleScript = "",
			parts = {}
		}
		
		NewCarTuningTable["fhqPorsche918Livery"] = {
			addPartsFromVehicleScript = "",
			parts = {}
		}
		
		NewCarTuningTable["fhqPorsche918WeissachLivery"] = {
			addPartsFromVehicleScript = "",
			parts = {}
		}
		
		NewCarTuningTable["fhqPorsche918Livery2"] = {
			addPartsFromVehicleScript = "",
			parts = {}
		}
		
		NewCarTuningTable["fhqPorsche918WeissachLivery2"] = {
			addPartsFromVehicleScript = "",
			parts = {}
		}
		
		NewCarTuningTable["fhqPorsche918Offroad"] = {
			addPartsFromVehicleScript = "",
			parts = {}
		}

		-- Things are done much cleaner this time around.
		-- Simply follow the format below to assign parts to your vehicles.
		-- Parts HAVE to be defined in the vehicle armor script!

		-- 918
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionWindowFrontLeft"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWindowFrontLeft"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionWindowFrontRight"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWindowFrontRight"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionWindshield"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWindshield"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionWindshieldRear"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWindshieldRear"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2Bullbar"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2Bullbar"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionTrunk"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionTrunk"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionHood"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionHood"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionDoorFrontLeft"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionDoorFrontLeft"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionDoorFrontRight"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionDoorFrontRight"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2InteractiveTrunkRoofRack"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2InteractiveTrunkRoofRack"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2RoofLightFront"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2RoofLightFront"])
		NewCarTuningTable["fhqPorsche918"].parts["ATA2ProtectionWheels"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWheels"])
		
		-- 918 Offroad
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionWindowFrontLeft"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWindowFrontLeft"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionWindowFrontRight"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWindowFrontRight"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionWindshield"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWindshield"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionWindshieldRear"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWindshieldRear"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2Bullbar"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2Bullbar"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionTrunk"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionTrunk"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionHood"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionHood"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionDoorFrontLeft"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionDoorFrontLeft"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionDoorFrontRight"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionDoorFrontRight"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2InteractiveTrunkRoofRack"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2InteractiveTrunkRoofRack"])
		NewCarTuningTable["fhqPorsche918Offroad"].parts["ATA2ProtectionWheels"] = copy(TemplateTuningTable["TemplateVehicle"].parts["ATA2ProtectionWheels"])
		
		NewCarTuningTable["fhqPorsche918Sil"] = NewCarTuningTable["fhqPorsche918"]
		NewCarTuningTable["fhqPorsche918Livery"] = NewCarTuningTable["fhqPorsche918"]
		NewCarTuningTable["fhqPorsche918WeissachLivery"] = NewCarTuningTable["fhqPorsche918"]
		NewCarTuningTable["fhqPorsche918Livery2"] = NewCarTuningTable["fhqPorsche918"]
		NewCarTuningTable["fhqPorsche918WeissachLivery2"] = NewCarTuningTable["fhqPorsche918"]
		
		-- Specify your recipe from the magazine script here.
		local carRecipe = "Advanced Mechanics"

		-- Here you assign your recipe to your vehicle.
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionWindowFrontLeft")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionWindowFrontRight")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionWindshield")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionWindshieldRear")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionTrunk")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionDoorFrontLeft")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionDoorFrontRight")

		-- Here's a few doozies. Make sure to note what function they use!
		SVUC_setVehicleRecipesArmorHood(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionHood")
		SVUC_setVehicleRecipesBullbars(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2Bullbar")
		SVUC_setVehicleRecipesWheels(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2ProtectionWheels")
		SVUC_setVehicleRecipesMods(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2InteractiveTrunkRoofRack")
		SVUC_setVehicleRecipesMods(NewCarTuningTable, carRecipe, "fhqPorsche918", "ATA2RoofLightFront")
		
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionWindowFrontLeft")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionWindowFrontRight")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionWindshield")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionWindshieldRear")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionTrunk")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionDoorFrontLeft")
		SVUC_setVehicleRecipesArmor(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionDoorFrontRight")
		
		SVUC_setVehicleRecipesArmorHood(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionHood")
		SVUC_setVehicleRecipesBullbars(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2Bullbar")
		SVUC_setVehicleRecipesWheels(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2ProtectionWheels")
		SVUC_setVehicleRecipesMods(NewCarTuningTable, carRecipe, "fhqPorsche918Offroad", "ATA2InteractiveTrunkRoofRack")

		ATA2Tuning_AddNewCars(NewCarTuningTable)
	end
end
Events.OnInitGlobalModData.Add(SVU_TuningTable)
