-------------------------------------------- EXTENSION FROM MOREBUNKERSILOMOD BY DERELKY - PERMISSION GIVEN --------------------------
-- (MoreBunkersilo Mod by derelky)
-- (Help to register new fillTypes by Wopster)
-- (Version 1.0 initial Release LS19)

local modDirectory = g_currentModDirectory

function addtoseasonseconomy(mission)
		if g_seasons == nil then
		else
			if g_seasons.economy.data.repricing.fillTypes.POTATOSORTED  == nil then
				g_seasons.economy.data.repricing.fillTypes.POTATOSORTED = {}
				for i,j in pairs(g_seasons.economy.data.repricing.fillTypes.POTATO) do
				g_seasons.economy.data.repricing.fillTypes.POTATOSORTED[i]=j
				end
			end
		end	
end

function overload(object, superFunc, ...)
    if not superFunc(object, ...) then
        return false
    end
	-- Add the new Filltype to the SellingStations
		local haspotato =false
		local haspotatosorted=false
				
		
		if object == nil then
		else
		haspotato =false
		haspotatosorted=false
			for i,filltype in pairs(object.acceptedFillTypes) do
					
			local fillname=g_fillTypeManager.indexToName[i]

			if fillname == "POTATO" then
				haspotato=true
							
			end
			if fillname == "POTATOSORTED" then
				haspotatosorted=true
							
			end
			
			end
			
			if haspotato and not haspotatosorted then
				--add haspotatosorted to the same SellingStation that accept POTATO
				local filltypen = g_fillTypeManager:getFillTypeIndexByName("POTATOSORTED")
				local price = g_fillTypeManager:getFillTypeByName("POTATOSORTED").pricePerLiter
				object:addAcceptedFillType(filltypen,price,true,false)
				object.priceMultipliers[ g_fillTypeManager:getFillTypeIndexByName("POTATOSORTED")]=object.priceMultipliers[ g_fillTypeManager:getFillTypeIndexByName("POTATO")]
				object:initPricingDynamics()
			end
			
		end
	return true
end

-- Hook here
Mission00.loadItemsFinished = Utils.prependedFunction(Mission00.loadItemsFinished, addtoseasonseconomy)
SellingStation.load = Utils.overwrittenFunction(SellingStation.load, overload)
