--
-- Diese Scriptpfade können nach belieben geändert werden
-- Die Scripte sollten dort dann natürlich auch vorhanden sein!
--
SpecializationUtil.registerSpecialization("weightStationVehicle", "weightStationVehicle", g_currentModDirectory .. "map/script/weightStationVehicle.lua");
SpecializationUtil.registerSpecialization("weightFix", "weightFix", g_currentModDirectory .. "map/script/weightStationVehicle.lua");

addToVehicle = {};
addToVehicle.modDir = g_currentModDirectory;

function addToVehicle:loadMap(name)
	if self.firstRun == nil then
		-- Gewichtsfaktor der Früchte
		-- Jede Frucht hat ihr eigenes spezifisches Gewicht, Früchte die noch nicht in der Liste stehen haben
		-- einen Standardwert. Der fruitWeightFactor gibt die Wirkung dieser Gewichte auf befüllbare Geräte an.
		-- Der von mir bisher am höchsten getestete Wert ist 3.75, da schafft ein Fendt 939 gerademal nen HKD302
		-- ohne Frontgewicht zu ziehen und der HKD302 schleift fast auf Bodennähe.
		-- Gebäuchliche Werte belaufen sich von 1.33 bis 2.205, einfach nach eigenem Gutdünken einstellen
		-- aber die Test's ruhig mit 2 vollen Hängern (BBE 900 mit Aufsatz am besten mit Weizen beladen) ausprobieren
		--
		g_currentMission.fruitWeightFactor = 1.52;
		--

		self.firstRun = false;
		for k, v in pairs(VehicleTypeUtil.vehicleTypes) do
			if v ~= nil and SpecializationUtil.hasSpecialization(FuelTrailer, v.specializations) and not SpecializationUtil.hasSpecialization(Trailer, v.specializations) then
				table.insert(v.specializations, SpecializationUtil.getSpecialization("trailer"));
			end;
			if v ~= nil and SpecializationUtil.hasSpecialization(WaterTrailer, v.specializations) and not SpecializationUtil.hasSpecialization(Trailer, v.specializations) then
				table.insert(v.specializations, SpecializationUtil.getSpecialization("trailer"));
			end;
			if v ~= nil and not SpecializationUtil.hasSpecialization(TrafficVehicle, v.specializations) then
				for i = 1, table.maxn(v.specializations) do
				  local vs = v.specializations[i];
				  if vs ~= nil then
					if vs == SpecializationUtil.getSpecialization("motorized") then
						local allowInsertion = true;
						local v_name_string = v.name;
						local point_location = string.find(v_name_string, ".", nil, true);
						if point_location ~= nil then
							local _name = string.sub(v_name_string, 1, point_location-1);
							if rawget(SpecializationUtil.specializations, string.format("%s.weightStationVehicle", _name)) ~= nil then
								allowInsertion = false;
							end;
						end;
						if allowInsertion then
							table.insert(v.specializations, SpecializationUtil.getSpecialization("weightStationVehicle"));
							vs.Wage_hud = Overlay:new("Wage_hud", (addToVehicle.modDir.."map/models/objects/Waage_24/WageFrame.dds"), 0.75, 0.3, 0.25, 0.55); -- Dies ist der Standardablagepfad für die beiden Overlays, er kann nach belieben angepasst werden
						end;
					end;
					if vs == SpecializationUtil.getSpecialization("fillable") then
						local allowInsertion2 = true;
						local v_name_string = v.name;
						local point_location = string.find(v_name_string, ".", nil, true);
						if point_location ~= nil then
							local _name = string.sub(v_name_string, 1, point_location-1);
							if rawget(SpecializationUtil.specializations, string.format("%s.weightFix", _name)) ~= nil then
								allowInsertion2 = false;
							end;
						end;
						if allowInsertion2 then
							table.insert(v.specializations, SpecializationUtil.getSpecialization("weightFix"));
						end;
					end; 
				  end;
				end;
			end;	
		end;
		-- Waagennamen
		local i = 1;
		while true do
			local txt = string.format("SCALENAME_%d", i);
			if not g_i18n:hasText(txt) then
				break;
			end;
			g_i18n.globalI18N.texts[txt] = g_i18n:getText(txt);
			i = i + 1;
		end;

		-- Waagentexte
		g_i18n.globalI18N.texts["wage_ready"] = g_i18n:getText("wage_ready");
		g_i18n.globalI18N.texts["wage_warn2"] = g_i18n:getText("wage_warn2");
		g_i18n.globalI18N.texts["wage_warn1"] = g_i18n:getText("wage_warn1");
		g_i18n.globalI18N.texts["wage_helper"] = g_i18n:getText("wage_helper");
		g_i18n.globalI18N.texts["wage_string1"] = g_i18n:getText("wage_string1");
		g_i18n.globalI18N.texts["wage_string2"] = g_i18n:getText("wage_string2");
		g_i18n.globalI18N.texts["wage_string3"] = g_i18n:getText("wage_string3");
		g_i18n.globalI18N.texts["wage_string4"] = g_i18n:getText("wage_string4");
		g_i18n.globalI18N.texts["wage_string5"] = g_i18n:getText("wage_string5");
		g_i18n.globalI18N.texts["MAPWEIGHTSTATION_SHOWOVERVIEW"] = g_i18n:getText("MAPWEIGHTSTATION_SHOWOVERVIEW");
		g_i18n.globalI18N.texts["MAPWEIGHTSTATION_RESET"] = g_i18n:getText("MAPWEIGHTSTATION_RESET");
		g_i18n.globalI18N.texts["MAPWEIGHTSTATION_SHOW"] = g_i18n:getText("MAPWEIGHTSTATION_SHOW");
		g_i18n.globalI18N.texts["PricePerTon"] = g_i18n:getText("PricePerTon");
	end;
end;
function addToVehicle:deleteMap()
end;
function addToVehicle:keyEvent(unicode, sym, modifier, isDown)
end;
function addToVehicle:mouseEvent(posX, posY, isDown, isUp, button)
end;
function addToVehicle:update(dt)
end;
function addToVehicle:draw()
end; 

addModEventListener(addToVehicle);
