-- Lampovo Project ^ω^ Average Enjoyer

local modDir = g_currentModDirectory
local modName = g_currentModName

FruitTypeManager.loadMapData = Utils.overwrittenFunction(FruitTypeManager.loadMapData, function (self, superFunc, xmlFileHandle, missionInfo, baseDirectory)
    superFunc(self, xmlFileHandle, missionInfo, baseDirectory)
    local xmlFile = loadXMLFile("mod_fruitTypes", modDir .. "xml/fruitTypes.xml")

    if xmlFile ~= nil then
        g_fruitTypeManager:loadFruitTypes(xmlFile, missionInfo, modDir, false)
        delete(xmlFile)
    end

    self:initializeFruitTypeConverters()

    return true
end)

FruitTypeManager.addFruitType = Utils.overwrittenFunction(FruitTypeManager.addFruitType, function (self, superFunc, fruitTypeDesc)
    superFunc(self, fruitTypeDesc)

    if fruitTypeDesc.name:lower() ~= "maize" then
        return
    end

    local maize = fruitTypeDesc

    if maize.hasWindrow then
        return
    end

    local windrowFillType = g_fillTypeManager:getFillTypeByName("maizestalks")
    if windrowFillType == nil then
        Logging.warning("Windrow FillType 'maizestalks' not found!")
        return
    end

    Logging.info("Configured windrow for fruit '%s' (cutFill '%s')", fruitTypeDesc.name, windrowFillType.name)

    maize.hasWindrow = true
    maize.windrowFillType = windrowFillType
    maize.windrowName = windrowFillType.name
    maize.windrowLiterPerSqm = 3.68

    self.windrowFillTypes[windrowFillType.index] = true
    self.fruitTypeIndexToWindrowFillTypeIndex[maize.index] = windrowFillType.index
    self.fillTypeIndexToFruitTypeIndex[windrowFillType.index] = maize.index
end)