--[[
FlieglTransportPackUtil

Utility for my Fliegl Transportpack

Author:		Ifko[nator]
Datum:		01.06.2020
Version:	v1.0

History:	v1.0 @ 01.06.2020 - initial implementation in FS 19
]]

FlieglTransportPackUtil = {};
FlieglTransportPackUtil.currentModName = g_currentModName;

FlieglTransportPackUtil.supportetDriveSymbolNames = {
	"HANDBRAKE",
	"CONTROL_LAMP_AFTER_STARTING",
	"TIPPING_ACTIVE_TRUCK",
	"ABS_TRUCK",
	"ABS_TRAILER",
	"TIPPING_ACTIVE_TRAILER_1",
	"TIPPING_ACTIVE_TRAILER_2",
	"WEARED_OUT_BRAKES",
	"WARNING_BRAKE_COMPRESSOR_FILL_LEVEL_TO_LOW",
	"WARNING_WORKSHOP_1",
	"WARNING_WORKSHOP_2",
	"WARNING_WORKSHOP_3",
	"STOP_IMMINENTLY",
	"MOTOR_NEED_MAINTRACE",
	"LOW_OIL_PRESSURE",
	"OIL_FILL_LEVEL_TO_LOW",
	"LOW_FUEL_FILL_LEVEL_LEVEL"
};

function FlieglTransportPackUtil.getDebugPriority(xmlFile, path)
	return Utils.getNoNil(getXMLInt(xmlFile, path), 0);
end;

function FlieglTransportPackUtil.getSpecByName(self, specName, currentModName)
    local spec = self["spec_" .. Utils.getNoNil(currentModName, FlieglTransportPackUtil.currentModName) .. "." .. specName];

	if spec ~= nil then
        return spec;
    end;

    return self["spec_" .. specName];
end;

function FlieglTransportPackUtil.printError(errorMessage, isWarning, isInfo, luaName)
	local prefix = "::ERROR:: ";
	
	if isWarning then
		prefix = "::WARNING:: ";
	elseif isInfo then
		prefix = "::INFO:: ";
	end;
	
	print(prefix .. "from the " .. luaName .. ".lua: " .. tostring(errorMessage));
end;

function FlieglTransportPackUtil.printDebug(debugMessage, priority, addString, luaName)
	if priority >= 1 then
		local prefix = "";
		
		if addString then
			prefix = "::DEBUG:: from the " .. luaName .. ".lua: ";
		end;
		
		--print(prefix .. tostring(debugMessage));
	end;
end;

function FlieglTransportPackUtil.getIsSupportetValue(supportetValues, supportetValue)
	for supportetValueNumber = 1, #supportetValues do
		if supportetValues[supportetValueNumber] == supportetValue then 
			return true;
		end;
	end;
	
	return false;
end;

function FlieglTransportPackUtil.getSupportetValues(supportetValues)
	local supportetValuesString = "";

	for supportetValueNumber, supportetValue in pairs(supportetValues) do
		if supportetValuesString ~= "" then 
			if supportetValueNumber < #supportetValues then
				supportetValue = "', '" .. supportetValue;
			else
				supportetValue = "' or '" .. supportetValue;
			end;
		end;
		
		supportetValuesString = supportetValuesString .. supportetValue;
	end;
	
	return supportetValuesString;
end;

function FlieglTransportPackUtil.getFillLevel(fillUnits)
	local fillLevel = 0;

	for _, fillUnit in pairs(fillUnits) do
		if fillUnit.showOnHud then
			fillLevel = fillLevel + fillUnit.fillLevel;
		end;
	end;

	return fillLevel;
end;

function FlieglTransportPackUtil.getCapacity(fillUnits)
	local capacity = 0;

	for _, fillUnit in pairs(fillUnits) do
		if fillUnit.showOnHud then
			capacity = capacity + fillUnit.capacity;
		end;
	end;

	return capacity;
end;

function FlieglTransportPackUtil.renderText(posX, posY, textSize, string, priority)
	if priority >= 1 then
		renderText(posX, posY, getCorrectTextSize(textSize), tostring(string));
	end;
end;