
RollerGrass = {}

function RollerGrass.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Roller, specializations);
end;

function RollerGrass:load(savegame)
    self.processRollerAreas = RollerGrass.processRollerGrassAreas;
	self.Visnode = Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.ToggleParts#node"));
end;

function RollerGrass:delete()
end;

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

function RollerGrass:keyEvent(unicode, sym, modifier, isDown)
end;

function RollerGrass:update(dt)
end;

function RollerGrass:updateTick(dt)
end;

function RollerGrass:draw()
end;

function RollerGrass:onAttach(attacherVehicle, jointDescIndex)
	if self.Visnode ~= nil then
		VisnodeValid = true;
	end;
local jointDesc = attacherVehicle.attacherJoints[jointDescIndex];
    if jointDesc.jointType == AttacherJoints.JOINTTYPE_IMPLEMENT then
        for _, tool in pairs(self.movingTools) do
            if tool.disableInTrailerMode then
                tool.isActive = true;
            end;
        end;
		if VisnodeValid then
			setVisibility(self.Visnode, true);
		end;
    else
        self:playAnimation("drawbarSetup", -1, nil, true);
        for _, tool in pairs(self.movingTools) do
            if tool.disableInTrailerMode then
                tool.isActive = false;
            end;
        end;
		if VisnodeValid then
			setVisibility(self.Visnode, false);
		end;
    end;
end;

function RollerGrass:onDetach()
	if self.Visnode ~= nil then
		setVisibility(self.Visnode, false);
	end;
end;

function RollerGrass:processRollerGrassAreas(workAreas)
    local numAreas = table.getn(workAreas);
    local areaSum = 0;
    for i=1, numAreas do
        local x = workAreas[i][1];
        local z = workAreas[i][2];
        local x1 = workAreas[i][3];
        local z1 = workAreas[i][4];
        local x2 = workAreas[i][5];
        local z2 = workAreas[i][6];
        -- Remove roller effect, so fields does not get destroyed
        --areaSum = areaSum + Utils.updateRollerArea(x, z, x1, z1, x2, z2)
        
        -- Cut grass
        Utils.cutFruitArea(FruitUtil.FRUITTYPE_GRASS, x, z, x1, z1, x2, z2, false, false, false)
        -- Now do the "spraying/weeding fertilization"
        Utils.updateWeederArea(x, z, x1, z1, x2, z2, g_currentMission.cultivatorValue, 1);
    end;
    return areaSum;
end;
