-- author: DD ModPassion
-- date: 14.04.2021
-- copyright (C): DD ModPassion, All Rights Reserved
-- version: farming simulator 19
ExtendedWorkMode = {} local modName = g_currentModName function ExtendedWorkMode.prerequisitesPresent(specializations) return true end function ExtendedWorkMode.registerEventListeners(vehicleType) SpecializationUtil.registerEventListener(vehicleType, "onLoad", ExtendedWorkMode) SpecializationUtil.registerEventListener(vehicleType, "onUpdate", ExtendedWorkMode) end function ExtendedWorkMode:onLoad(savegame) self.spec_extendedWorkMode = self[string.format("spec_%s.extendedWorkMode", modName)] local spec = self.spec_extendedWorkMode spec.workAreaWidth = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.workAreas.workArea(3).area#widthNode"), self.i3dMappings) spec.workAreaHeight = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.workAreas.workArea(3).area#heightNode"), self.i3dMappings) end function ExtendedWorkMode:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) local spec = self.spec_extendedWorkMode if spec.workAreaWidth ~= nil and spec.workAreaHeight ~= nil then local rx, ry, rz = getWorldTranslation(spec.workAreaWidth) local lx, ly, lz = getWorldTranslation(spec.workAreaHeight) local workingWidth = MathUtil.round(MathUtil.vector3Length(rx-lx, ry-ly, rz-lz)) if workingWidth ~= self.spec_sprayer.usageScale.workingWidth and workingWidth > 0 then self.spec_sprayer.usageScale.workingWidth = workingWidth end if  self.isClient and isSelected and self:getIsActive() then local spec = self.spec_workMode local mode = spec.workModes[spec.state] g_currentMission:addExtraPrintText(string.format(g_i18n:getText("action_workModeSelected"), mode.name)) end end end function ExtendedWorkMode:updateDebugValues(values) local spec = self.spec_extendedWorkMode if  spec.workAreaWidth ~= nil and spec.workAreaHeight ~= nil then table.insert(values, {name="Sprayer.usageScale.workingWidth", value=string.format("%.4f", self.spec_sprayer.usageScale.workingWidth)}) end end