-- Replaces bales generated by balers/baleWrappers with bales that have less tendency to roll when dropped

stableBales = {}
stableBales.modDir = g_currentModDirectory

function stableBales:loadMap(name)
	local baleType = g_baleTypeManager.baleTypes
	local bale = g_baleTypeManager.nameToIndex
	baleType[bale.DRYGRASS_WINDROW_112_130].filename = "$"..stableBales.modDir.."bales/roundbaleHay_w120_d180.i3d"
	baleType[bale.GRASS_WINDROW_112_130].filename = "$"..stableBales.modDir.."bales/roundbaleGrass_w120_d180.i3d"
	baleType[bale.STRAW_112_130].filename = "$"..stableBales.modDir.."bales/roundbaleStraw_w120_d180.i3d"
	baleType[bale.SILAGE_112_130].filename = "$"..stableBales.modDir.."objects/roundbaleSilage_w120_d180.i3d"
end

function stableBales:deleteMap()
end

function stableBales:mouseEvent(posX, posY, isDown, isUp, button)
end

function stableBales:keyEvent(unicode, sym, modifier, isDown)
end

function stableBales:update(dt) 
end

function stableBales:draw()
end

addModEventListener(stableBales)

BaleWrapper.stableBalesLoad = function(self, savegame)
    for _, fillType in pairs(self.spec_baleWrapper.roundBaleWrapper.allowedBaleTypes) do
        for _, bale in pairs(fillType) do
			if string.match(bale.wrapperBaleFilename, "roundbaleSilage_w112_d130.i3d") then
                bale.wrapperBaleFilename = stableBales.modDir.."objects/roundbaleSilage_w112_d130.i3d"
            end
        end
	end
end
BaleWrapper.onLoad = Utils.appendedFunction(BaleWrapper.onLoad, BaleWrapper.stableBalesLoad)