--[[
==============================================================================
MGS Monitor Framework
==============================================================================

Author: MyGameSteam
Version: 1.0.0.0
Game: Farming Simulator 25
Date: June 27th 2026

Description:
A generic monitor framework for Farming Simulator 25 that exposes live
implement information through custom dashboard value types.

The system recursively scans attached implements and provides data for
in-cab terminals and displays, allowing multiple monitor layouts and
brands to share a common backend.

Implemented Features:
- Generic fill channel system
- Dynamic fill level monitoring
- Capacity detection
- Fill percentage calculation
- Low level warning system
- Application rate detection
- Remaining area calculation
- Recursive implement scanning
- Implement detection
- Working width detection
- Speed limit detection
- Live implement mass calculation
- Implement operating states
- Dashboard integration

Supported Monitor Layouts:
- Quartz Terminal
- Novag Virtual Terminal

Example Dashboard Values:
- mgsMonitor.seeds.fillLevel
- mgsMonitor.seeds.fillLevelPct
- mgsMonitor.seeds.applicationRate
- mgsMonitor.seeds.remainingArea
- mgsMonitor.fertilizer.fillLevel
- mgsMonitor.fertilizer.applicationRate
- mgsMonitor.fertilizer.remainingArea
- mgsMonitor.implement.mass
- mgsMonitor.implement.workingWidth
- mgsMonitor.implement.speedLimit

Architecture:
Implement -> MGS Monitor -> Dashboard System -> Terminal Display

Copyright (c) MyGameSteam
All rights reserved.

==============================================================================
]]
MGSMonitor={};MGSMonitor.DEFAULT_CHANNELS={{name="main",fillTypes="SEEDS FERTILIZER LIQUIDFERTILIZER HERBICIDE",warningPct=402 -(232 + 160) ,applicationRateType="auto"},{name="seeds",fillTypes="SEEDS",warningPct=1028 -(697 + 321) ,applicationRateType="sowing"},{name="fertilizer",fillTypes="FERTILIZER LIQUIDFERTILIZER",warningPct=21 -11 ,applicationRateType="sprayer"}};MGSMonitor.CHANNEL_VALUE_NAMES={"fillLevelPct","fillLevel","capacity","fillLevelWarning","hasFillType","fillTypeIndex","status","applicationRateAvailable","applicationRate","remainingArea"};MGSMonitor.IMPLEMENT_VALUE_NAMES={"attachedCount","hasAttachedImplement","hasFillUnit","workingWidth","speedLimit","mass","isTurnedOn","isOperating","isWorkAreaActive"};MGSMonitor.prerequisitesPresent=function(v72) return SpecializationUtil.hasSpecialization(Dashboard,v72);end;MGSMonitor.initSpecialization=function() local v73=Vehicle.xmlSchema;v73:setXMLSpecializationType("MGSMonitor");v73:register(XMLValueType.INT,"vehicle.mgsMonitor#updateInterval","Update interval in ms",743 -493 );v73:register(XMLValueType.STRING,"vehicle.mgsMonitor.fillChannels.fillChannel(?)#name","Channel name");v73:register(XMLValueType.STRING,"vehicle.mgsMonitor.fillChannels.fillChannel(?)#fillTypes","Fill types");v73:register(XMLValueType.FLOAT,"vehicle.mgsMonitor.fillChannels.fillChannel(?)#warningPct","Low fill warning percentage",448 -(262 + 176) );v73:register(XMLValueType.STRING,"vehicle.mgsMonitor.fillChannels.fillChannel(?)#applicationRateType","Application rate resolver type","auto");local v74={};for v234,v235 in ipairs(MGSMonitor.DEFAULT_CHANNELS) do for v256,v257 in ipairs(MGSMonitor.CHANNEL_VALUE_NAMES) do table.insert(v74,"mgsMonitor."   .. v235.name   .. "."   .. v257 );end end for v236,v237 in ipairs(MGSMonitor.IMPLEMENT_VALUE_NAMES) do table.insert(v74,"mgsMonitor.implement."   .. v237 );end Dashboard.registerDashboardXMLPaths(v73,"vehicle.mgsMonitor.dashboards",v74);v73:setXMLSpecializationType();end;MGSMonitor.registerFunctions=function(v75) local v76={"mgsMonitorGetData","mgsMonitorGetChannelValue","mgsMonitorGetImplementValue","mgsMonitorLoadChannels","mgsMonitorCreateChannel","mgsMonitorUpdateData","mgsMonitorResetChannels","mgsMonitorResetImplement","mgsMonitorFinalizeChannels","mgsMonitorScanVehicleRecursive","mgsMonitorReadFillUnit","mgsMonitorFillUnitMatchesChannel","mgsMonitorGetFillUnitCapacity","mgsMonitorReadImplementState","mgsMonitorGetWorkingWidth","mgsMonitorGetSpeedLimit","mgsMonitorGetVehicleMass","mgsMonitorUpdateApplicationRates","mgsMonitorGetApplicationRate","mgsMonitorGetSowingApplicationRate","mgsMonitorGetSprayerApplicationRate","mgsMonitorGetFillTypeMassPerLiter","mgsMonitorGetMainFillLevelPct","mgsMonitorGetMainFillLevel","mgsMonitorGetMainCapacity","mgsMonitorGetMainFillLevelWarning","mgsMonitorGetMainHasFillType","mgsMonitorGetMainFillTypeIndex","mgsMonitorGetMainStatus","mgsMonitorGetMainApplicationRateAvailable","mgsMonitorGetMainApplicationRate","mgsMonitorGetMainRemainingArea","mgsMonitorGetSeedsFillLevelPct","mgsMonitorGetSeedsFillLevel","mgsMonitorGetSeedsCapacity","mgsMonitorGetSeedsFillLevelWarning","mgsMonitorGetSeedsHasFillType","mgsMonitorGetSeedsFillTypeIndex","mgsMonitorGetSeedsStatus","mgsMonitorGetSeedsApplicationRateAvailable","mgsMonitorGetSeedsApplicationRate","mgsMonitorGetSeedsRemainingArea","mgsMonitorGetFertilizerFillLevelPct","mgsMonitorGetFertilizerFillLevel","mgsMonitorGetFertilizerCapacity","mgsMonitorGetFertilizerFillLevelWarning","mgsMonitorGetFertilizerHasFillType","mgsMonitorGetFertilizerFillTypeIndex","mgsMonitorGetFertilizerStatus","mgsMonitorGetFertilizerApplicationRateAvailable","mgsMonitorGetFertilizerApplicationRate","mgsMonitorGetFertilizerRemainingArea","mgsMonitorGetImplementAttachedCount","mgsMonitorGetImplementHasAttachedImplement","mgsMonitorGetImplementHasFillUnit","mgsMonitorGetImplementWorkingWidth","mgsMonitorGetImplementSpeedLimit","mgsMonitorGetImplementMass","mgsMonitorGetImplementIsTurnedOn","mgsMonitorGetImplementIsOperating","mgsMonitorGetImplementIsWorkAreaActive"};for v238,v239 in ipairs(v76) do SpecializationUtil.registerFunction(v75,v239,MGSMonitor[v239]);end end;MGSMonitor.registerEventListeners=function(v77) local v78=0 -0 ;while true do if (v78==(0 -0)) then SpecializationUtil.registerEventListener(v77,"onLoad",MGSMonitor);SpecializationUtil.registerEventListener(v77,"onPreInitComponentPlacement",MGSMonitor);v78=868 -(550 + 317) ;end if (v78==1) then SpecializationUtil.registerEventListener(v77,"onRegisterDashboardValueTypes",MGSMonitor);SpecializationUtil.registerEventListener(v77,"onUpdate",MGSMonitor);break;end end end;MGSMonitor.mgsMonitorGetData=function(v79) local v80=0 -0 ;while true do if (v80==(48 -(25 + 23))) then if (v79.mgsMonitor==nil) then v79.mgsMonitor={};end return v79.mgsMonitor;end end end;MGSMonitor.onLoad=function(v81,v82) local v83=0 -0 ;local v84;while true do if (v83==(8 -5)) then v81:mgsMonitorLoadChannels();v81:mgsMonitorUpdateData();break;end if (v83==(287 -(134 + 151))) then v84.channelOrder={};v84.implement={};v83=1668 -(970 + 695) ;end if (v83==(1 -0)) then v84.updateTimer=0 -0 ;v84.channels={};v83=99 -(11 + 86) ;end if (v83==(1990 -(582 + 1408))) then v84=v81:mgsMonitorGetData();v84.updateInterval=v81.xmlFile:getValue("vehicle.mgsMonitor#updateInterval",867 -617 );v83=1 -0 ;end end end;MGSMonitor.mgsMonitorCreateChannel=function(v85,v86,v87,v88,v89) local v90={name=v86,fillTypesRaw=v87,warningPct=v88 or (37 -27) ,applicationRateType=v89 or "auto" ,fillTypeIndexes={},fillLevel=0 -0 ,capacity=0,fillLevelPct=1824 -(1195 + 629) ,fillLevelWarning=0 -0 ,hasFillType=241 -(187 + 54) ,fillTypeIndex=780 -(162 + 618) ,status=0 + 0 ,applicationRateAvailable=0,applicationRate=0 + 0 ,remainingArea=0 -0 };for v240 in string.gmatch(v87 or "" ,"%S+") do local v241=1061 -(810 + 251) ;local v242;while true do if (v241==(0 + 0)) then v242=g_fillTypeManager:getFillTypeIndexByName(string.upper(v240));if (v242~=nil) then table.insert(v90.fillTypeIndexes,v242);end break;end end end return v90;end;MGSMonitor.mgsMonitorLoadChannels=function(v91) local v92=0 + 0 ;local v93;local v94;local v95;while true do if (v92==2) then if  not v95 then for v332,v333 in ipairs(MGSMonitor.DEFAULT_CHANNELS) do v93.channels[v333.name]=v91:mgsMonitorCreateChannel(v333.name,v333.fillTypes,v333.warningPct,v333.applicationRateType);table.insert(v93.channelOrder,v333.name);end end break;end if (v92==(0 -0)) then v93=v91:mgsMonitorGetData();v94="vehicle.mgsMonitor.fillChannels.fillChannel";v92=534 -(43 + 490) ;end if (v92==(1 + 0)) then v95=false;v91.xmlFile:iterate(v94,function(v282,v283) local v284=1636 -(1373 + 263) ;local v285;local v286;local v287;local v288;while true do if (v284==(861 -(240 + 619))) then if ((v285~=nil) and (v286~=nil)) then v93.channels[v285]=v91:mgsMonitorCreateChannel(v285,v286,v287,v288);table.insert(v93.channelOrder,v285);v95=true;end break;end if (v284==(1001 -(451 + 549))) then v287=v91.xmlFile:getValue(v283   .. "#warningPct" ,15 -5 );v288=v91.xmlFile:getValue(v283   .. "#applicationRateType" ,"auto");v284=1 + 1 ;end if (v284==(1744 -(1344 + 400))) then v285=v91.xmlFile:getValue(v283   .. "#name" );v286=v91.xmlFile:getValue(v283   .. "#fillTypes" );v284=1;end end end);v92=407 -(255 + 150) ;end end end;MGSMonitor.onRegisterDashboardValueTypes=function(v96) local function v97(v243,v244) local v245=0 + 0 ;local v246;while true do if (v245==(0 + 0)) then v246=DashboardValueType.new("mgsMonitor",v243);v246:setValue(v96,v244);v245=1 -0 ;end if (v245==(1 -0)) then v246:setPollUpdate(false);v96:registerDashboardValueType(v246);break;end end end v97("main.fillLevelPct","mgsMonitorGetMainFillLevelPct");v97("main.fillLevel","mgsMonitorGetMainFillLevel");v97("main.capacity","mgsMonitorGetMainCapacity");v97("main.fillLevelWarning","mgsMonitorGetMainFillLevelWarning");v97("main.hasFillType","mgsMonitorGetMainHasFillType");v97("main.fillTypeIndex","mgsMonitorGetMainFillTypeIndex");v97("main.status","mgsMonitorGetMainStatus");v97("main.applicationRateAvailable","mgsMonitorGetMainApplicationRateAvailable");v97("main.applicationRate","mgsMonitorGetMainApplicationRate");v97("main.remainingArea","mgsMonitorGetMainRemainingArea");v97("seeds.fillLevelPct","mgsMonitorGetSeedsFillLevelPct");v97("seeds.fillLevel","mgsMonitorGetSeedsFillLevel");v97("seeds.capacity","mgsMonitorGetSeedsCapacity");v97("seeds.fillLevelWarning","mgsMonitorGetSeedsFillLevelWarning");v97("seeds.hasFillType","mgsMonitorGetSeedsHasFillType");v97("seeds.fillTypeIndex","mgsMonitorGetSeedsFillTypeIndex");v97("seeds.status","mgsMonitorGetSeedsStatus");v97("seeds.applicationRateAvailable","mgsMonitorGetSeedsApplicationRateAvailable");v97("seeds.applicationRate","mgsMonitorGetSeedsApplicationRate");v97("seeds.remainingArea","mgsMonitorGetSeedsRemainingArea");v97("fertilizer.fillLevelPct","mgsMonitorGetFertilizerFillLevelPct");v97("fertilizer.fillLevel","mgsMonitorGetFertilizerFillLevel");v97("fertilizer.capacity","mgsMonitorGetFertilizerCapacity");v97("fertilizer.fillLevelWarning","mgsMonitorGetFertilizerFillLevelWarning");v97("fertilizer.hasFillType","mgsMonitorGetFertilizerHasFillType");v97("fertilizer.fillTypeIndex","mgsMonitorGetFertilizerFillTypeIndex");v97("fertilizer.status","mgsMonitorGetFertilizerStatus");v97("fertilizer.applicationRateAvailable","mgsMonitorGetFertilizerApplicationRateAvailable");v97("fertilizer.applicationRate","mgsMonitorGetFertilizerApplicationRate");v97("fertilizer.remainingArea","mgsMonitorGetFertilizerRemainingArea");v97("implement.attachedCount","mgsMonitorGetImplementAttachedCount");v97("implement.hasAttachedImplement","mgsMonitorGetImplementHasAttachedImplement");v97("implement.hasFillUnit","mgsMonitorGetImplementHasFillUnit");v97("implement.workingWidth","mgsMonitorGetImplementWorkingWidth");v97("implement.speedLimit","mgsMonitorGetImplementSpeedLimit");v97("implement.mass","mgsMonitorGetImplementMass");v97("implement.isTurnedOn","mgsMonitorGetImplementIsTurnedOn");v97("implement.isOperating","mgsMonitorGetImplementIsOperating");v97("implement.isWorkAreaActive","mgsMonitorGetImplementIsWorkAreaActive");end;MGSMonitor.onPreInitComponentPlacement=function(v98,v99) if (v98.isClient and v98.xmlFile:hasProperty("vehicle.mgsMonitor.dashboards")) then v98:loadDashboardsFromXML(v98.xmlFile,"vehicle.mgsMonitor.dashboards");end end;MGSMonitor.onUpdate=function(v100,v101,v102,v103,v104) local v105=1384 -(746 + 638) ;local v106;while true do if (v105==(1 + 0)) then if (v106.updateTimer>=(v106.updateInterval or 250)) then local v298=0 -0 ;while true do if (v298==(342 -(218 + 123))) then if (v100.updateDashboardValueType~=nil) then local v387=1581 -(1535 + 46) ;while true do if (v387==(0 + 0)) then for v407,v408 in ipairs(v106.channelOrder) do for v412,v413 in ipairs(MGSMonitor.CHANNEL_VALUE_NAMES) do v100:updateDashboardValueType("mgsMonitor."   .. v408   .. "."   .. v413 );end end for v409,v410 in ipairs(MGSMonitor.IMPLEMENT_VALUE_NAMES) do v100:updateDashboardValueType("mgsMonitor.implement."   .. v410 );end break;end end end break;end if (v298==(0 + 0)) then v106.updateTimer=0 + 0 ;v100:mgsMonitorUpdateData();v298=1;end end end break;end if (v105==(560 -(306 + 254))) then v106=v100:mgsMonitorGetData();v106.updateTimer=(v106.updateTimer or (0 + 0)) + v101 ;v105=1 -0 ;end end end;MGSMonitor.mgsMonitorUpdateData=function(v107) v107:mgsMonitorResetChannels();v107:mgsMonitorResetImplement();v107:mgsMonitorScanVehicleRecursive(v107,1467 -(899 + 568) );v107:mgsMonitorFinalizeChannels();end;MGSMonitor.mgsMonitorResetChannels=function(v108) local v109=0 + 0 ;local v110;while true do if (v109==(338 -(118 + 220))) then v110=v108:mgsMonitorGetData();for v289,v290 in pairs(v110.channels) do local v291=0;while true do if (v291==(1 + 0)) then v290.fillLevelPct=0 -0 ;v290.fillLevelWarning=603 -(268 + 335) ;v291=292 -(60 + 230) ;end if (v291==(572 -(426 + 146))) then v290.fillLevel=0 -0 ;v290.capacity=0 + 0 ;v291=1494 -(711 + 782) ;end if (v291==(1460 -(282 + 1174))) then v290.applicationRate=0;v290.remainingArea=811 -(569 + 242) ;break;end if ((8 -5)==v291) then v290.status=0 -0 ;v290.applicationRateAvailable=469 -(270 + 199) ;v291=1 + 3 ;end if (v291==(1821 -(580 + 1239))) then v290.hasFillType=0;v290.fillTypeIndex=0 -0 ;v291=3 + 0 ;end end end break;end end end;MGSMonitor.mgsMonitorResetImplement=function(v111) local v112=v111:mgsMonitorGetData();v112.implement.attachedCount=0;v112.implement.hasAttachedImplement=0 + 0 ;v112.implement.hasFillUnit=1024 -(706 + 318) ;v112.implement.workingWidth=0;v112.implement.speedLimit=0 -0 ;v112.implement.mass=1251 -(721 + 530) ;v112.implement.isTurnedOn=1271 -(945 + 326) ;v112.implement.isOperating=0 -0 ;v112.implement.isWorkAreaActive=1167 -(645 + 522) ;end;MGSMonitor.mgsMonitorFinalizeChannels=function(v122) local v123=v122:mgsMonitorGetData();for v247,v248 in pairs(v123.channels) do local v249=0 + 0 ;while true do if (v249==(701 -(271 + 429))) then if ((v248.applicationRateAvailable==(1 + 0)) and (v248.applicationRate>(0 + 0)) and (v248.fillLevel>(1500 -(1408 + 92)))) then local v335=1086 -(461 + 625) ;local v336;while true do if (v335==0) then v336=string.lower(v248.applicationRateType or "auto" );if (v336=="sowing") then local v396=0 -0 ;local v397;while true do if (v396==(1288 -(993 + 295))) then v397=1 + 0 ;if (v248.fillTypeIndex~=(1171 -(418 + 753))) then local v417=0 + 0 ;local v418;while true do if (0==v417) then v418=v122:mgsMonitorGetFillTypeMassPerLiter(v248.fillTypeIndex);if (v418>(0 + 0)) then local v419=0 + 0 ;while true do if ((0 + 0)==v419) then v397=v418;if (v397<(529.1 -(406 + 123))) then v397=v397 * (2769 -(1749 + 20)) ;end break;end end end break;end end end v396=1 + 0 ;end if (v396==(1323 -(1249 + 73))) then v248.remainingArea=(v248.fillLevel * v397)/v248.applicationRate ;break;end end else v248.remainingArea=v248.fillLevel/v248.applicationRate ;end break;end end else v248.remainingArea=0 -0 ;end break;end if (v249==(0 + 0)) then if (v248.capacity>(1145 -(466 + 679))) then v248.fillLevelPct=(v248.fillLevel/v248.capacity) * (240 -140) ;else v248.fillLevelPct=0 + 0 ;end if (v248.hasFillType==(0 -0)) then local v340=1900 -(106 + 1794) ;while true do if (0==v340) then v248.status=0 + 0 ;v248.fillLevelWarning=0 -0 ;break;end end elseif (v248.capacity<=(0 + 0)) then local v373=0;while true do if (v373==(470 -(381 + 89))) then v248.status=1;v248.fillLevelWarning=0 -0 ;break;end end elseif (v248.fillLevel<=(0 + 0)) then local v388=0;while true do if ((0 -0)==v388) then v248.status=116 -(4 + 110) ;v248.fillLevelWarning=585 -(57 + 527) ;break;end end else local v389=1427 -(41 + 1386) ;while true do if (v389==(103 -(17 + 86))) then v248.status=3 + 0 ;v248.fillLevelWarning=((v248.fillLevelPct<=(v248.warningPct or 10)) and (1 -0)) or (0 + 0) ;break;end end end v249=1 + 0 ;end end end end;MGSMonitor.mgsMonitorScanVehicleRecursive=function(v124,v125,v126) local v127=0 + 0 ;local v128;while true do if (v127==(0 -0)) then if ((v125==nil) or (v126>(57 -37))) then return;end v128=v124:mgsMonitorGetData();v127=1;end if (v127==(627 -(512 + 114))) then if (v126>(166 -(122 + 44))) then v128.implement.attachedCount=v128.implement.attachedCount + (1 -0) ;v128.implement.hasAttachedImplement=3 -2 ;v124:mgsMonitorReadImplementState(v125);v124:mgsMonitorUpdateApplicationRates(v125);if ((v125.spec_fillUnit~=nil) and (v125.spec_fillUnit.fillUnits~=nil)) then v128.implement.hasFillUnit=1 -0 ;for v374,v375 in pairs(v125.spec_fillUnit.fillUnits) do v124:mgsMonitorReadFillUnit(v125,v374);end end end if (v125.getAttachedImplements~=nil) then local v301=v125:getAttachedImplements();if (v301~=nil) then for v376,v377 in ipairs(v301) do if (v377.object~=nil) then v124:mgsMonitorScanVehicleRecursive(v377.object,v126 + 1 + 0 );end end end end break;end end end;MGSMonitor.mgsMonitorReadFillUnit=function(v129,v130,v131) local v132=v129:mgsMonitorGetData();if (v130.getFillUnitFillLevel==nil) then return;end local v133=nil;if ((v130.spec_fillUnit~=nil) and (v130.spec_fillUnit.fillUnits~=nil)) then v133=v130.spec_fillUnit.fillUnits[v131];end local v134=v130:getFillUnitFillLevel(v131) or (0 + 0) ;local v135=v129:mgsMonitorGetFillUnitCapacity(v130,v131);local v136=0 + 0 ;if (v130.getFillUnitFillType~=nil) then v136=v130:getFillUnitFillType(v131) or (0 + 0) ;end if (v135<=(0 -0)) then return;end for v250,v251 in pairs(v132.channels) do if v129:mgsMonitorFillUnitMatchesChannel(v130,v131,v133,v136,v251) then v251.hasFillType=66 -(30 + 35) ;v251.fillLevel=v251.fillLevel + v134 ;v251.capacity=v251.capacity + v135 ;if (v136~=(0 + 0)) then v251.fillTypeIndex=v136;elseif (v251.fillTypeIndexes[1]~=nil) then v251.fillTypeIndex=v251.fillTypeIndexes[1];end end end end;MGSMonitor.mgsMonitorFillUnitMatchesChannel=function(v137,v138,v139,v140,v141,v142) local v143=1994 -(109 + 1885) ;while true do if (v143==(1469 -(1269 + 200))) then for v292,v293 in ipairs(v142.fillTypeIndexes) do if ((v141~=(1257 -(1043 + 214))) and (v141==v293)) then return true;end if (v140~=nil) then if ((v140.supportedFillTypes~=nil) and (v140.supportedFillTypes[v293]~=nil)) then return true;end if (v140.fillTypes~=nil) then local v378=815 -(98 + 717) ;while true do if (v378==(0 -0)) then if (v140.fillTypes[v293]~=nil) then return true;end for v401,v402 in pairs(v140.fillTypes) do if (v402==v293) then return true;end end break;end end end end if (v138.getFillUnitSupportsFillType~=nil) then local v341=1212 -(323 + 889) ;local v342;local v343;while true do if (v341==(0 -0)) then v342,v343=pcall(v138.getFillUnitSupportsFillType,v138,v139,v293);if (v342 and v343) then return true;end break;end end end end return false;end end end;MGSMonitor.mgsMonitorGetFillUnitCapacity=function(v144,v145,v146) local v147=0 -0 ;if ((v145.spec_fillUnit~=nil) and (v145.spec_fillUnit.fillUnits~=nil) and (v145.spec_fillUnit.fillUnits[v146]~=nil)) then local v259=v145.spec_fillUnit.fillUnits[v146];v147=v259.capacity or v259.defaultCapacity or v259.maxCapacity or (0 -0) ;end if ((v147<=(0 + 0)) and (v145.getFillUnitCapacity~=nil)) then local v260,v261=pcall(v145.getFillUnitCapacity,v145,v146);if (v260 and (type(v261)=="number")) then v147=v261;end end return v147 or (580 -(361 + 219)) ;end;MGSMonitor.mgsMonitorReadImplementState=function(v148,v149) local v150=320 -(53 + 267) ;local v151;local v152;local v153;local v154;while true do if (v150==(1 + 0)) then v153=v148:mgsMonitorGetWorkingWidth(v149);if (v153>v152.workingWidth) then v152.workingWidth=v153;end v150=1 + 1 ;end if (v150==(413 -(15 + 398))) then v151=v148:mgsMonitorGetData();v152=v151.implement;v150=983 -(18 + 964) ;end if (v150==(14 -10)) then if (v149.getIsOperating~=nil) then local v304=0;local v305;local v306;while true do if (v304==(0 -0)) then v305,v306=pcall(v149.getIsOperating,v149);if (v305 and v306) then v152.isOperating=1 + 0 ;end break;end end end if ((v149.getIsWorkAreaActive~=nil) and (v149.spec_workArea~=nil) and (v149.spec_workArea.workAreas~=nil)) then for v344,v345 in pairs(v149.spec_workArea.workAreas) do local v346,v347=pcall(v149.getIsWorkAreaActive,v149,v345);if (v346 and v347) then v152.isWorkAreaActive=1 + 0 ;break;end end end break;end if (v150==(2 + 0)) then v154=v148:mgsMonitorGetSpeedLimit(v149);if (v154>v152.speedLimit) then v152.speedLimit=v154;end v150=3;end if (v150==3) then v152.mass=v152.mass + v148:mgsMonitorGetVehicleMass(v149) ;if (v149.getIsTurnedOn~=nil) then local v308=0;local v309;local v310;while true do if (v308==(850 -(20 + 830))) then v309,v310=pcall(v149.getIsTurnedOn,v149);if (v309 and v310) then v152.isTurnedOn=1 + 0 ;end break;end end end v150=130 -(116 + 10) ;end end end;MGSMonitor.mgsMonitorGetWorkingWidth=function(v155,v156) local v157=0 + 0 ;while true do if (v157==(0 + 0)) then if (v156==nil) then return 738 -(542 + 196) ;end if (v156.xmlFile~=nil) then local v311=0 -0 ;local v312;while true do if (v311==0) then v312=v156.xmlFile:getValue("vehicle.storeData.specs.workingWidth",0 + 0 );if ((v312~=nil) and (v312>(0 + 0))) then return v312;end break;end end end v157=1 + 0 ;end if (v157==(1 + 0)) then if (v156.getAIWorkAreaWidth~=nil) then local v313,v314=pcall(v156.getAIWorkAreaWidth,v156);if (v313 and (type(v314)=="number") and (v314>(326 -(192 + 134)))) then return v314;end end if (v156.getAIMarkers~=nil) then local v315,v316,v317=pcall(v156.getAIMarkers,v156);if (v315 and (v316~=nil) and (v317~=nil) and (v316~=0) and (v317~=(1276 -(316 + 960)))) then local v365,v366,v367=getWorldTranslation(v316);local v368,v369,v370=getWorldTranslation(v317);if ((v365~=nil) and (v368~=nil)) then local v384=v365-v368 ;local v385=v366-v369 ;local v386=v367-v370 ;return math.sqrt((v384 * v384) + (v385 * v385) + (v386 * v386) );end end end v157=2;end if (v157==(4 -2)) then return 0 -0 ;end end end;MGSMonitor.mgsMonitorGetSpeedLimit=function(v158,v159) if (v159==nil) then return 1551 -(1126 + 425) ;end if (v159.xmlFile~=nil) then local v262=405 -(118 + 287) ;local v263;while true do if (v262==0) then v263=v159.xmlFile:getValue("vehicle.base.speedLimit#value",0);if ((v263~=nil) and (v263>(0 -0))) then return v263;end break;end end end if (v159.getSpeedLimit~=nil) then local v264=1121 -(118 + 1003) ;local v265;local v266;while true do if (v264==(0 -0)) then v265,v266=pcall(v159.getSpeedLimit,v159);if (v265 and (type(v266)=="number") and (v266>(377 -(142 + 235)))) then return v266;end break;end end end return 0;end;MGSMonitor.mgsMonitorGetVehicleMass=function(v160,v161) local v162=0 -0 ;local v163;while true do if ((1 + 0)==v162) then for v294,v295 in pairs(v161.components) do if ((v295.node~=nil) and (v295.node~=0)) then local v348,v349=pcall(getMass,v295.node);if (v348 and (type(v349)=="number")) then v163=v163 + (v349 * (1977 -(553 + 424))) ;end end end return v163;end if (v162==(0 -0)) then if ((v161==nil) or (v161.components==nil)) then return 325 -(45 + 280) ;end v163=0 + 0 ;v162=1 + 0 ;end end end;MGSMonitor.mgsMonitorUpdateApplicationRates=function(v164,v165) local v166=v164:mgsMonitorGetData();for v252,v253 in pairs(v166.channels) do local v254,v255=v164:mgsMonitorGetApplicationRate(v165,v253);if (v254 and (v255>(0 + 0))) then local v281=0 + 0 ;while true do if (v281==(0 + 0)) then v253.applicationRateAvailable=1 + 0 ;v253.applicationRate=v255;break;end end end end end;MGSMonitor.mgsMonitorGetApplicationRate=function(v167,v168,v169) local v170=1911 -(340 + 1571) ;local v171;while true do if (v170==(2 -1)) then if ((v171=="none") or (v171=="false") or (v171=="disabled")) then return false,0 -0 ;end if (v171=="sowing") then return v167:mgsMonitorGetSowingApplicationRate(v168);end v170=4 -2 ;end if (v170==(0 + 0)) then if ((v168==nil) or (v169==nil)) then return false,1948 -(1096 + 852) ;end v171=string.lower(v169.applicationRateType or "auto" );v170=1 + 0 ;end if (v170==(2 -0)) then if (v171=="sprayer") then return v167:mgsMonitorGetSprayerApplicationRate(v168);end if (v171=="auto") then local v318=0 + 0 ;local v319;local v320;while true do if (v318==(0 -0)) then v319,v320=v167:mgsMonitorGetSowingApplicationRate(v168);if (v319 and (v320>(753 -(239 + 514)))) then return true,v320;end v318=1 + 0 ;end if ((96 -(51 + 44))==v318) then v319,v320=v167:mgsMonitorGetSprayerApplicationRate(v168);if (v319 and (v320>(0 + 0))) then return true,v320;end break;end end end v170=1332 -(797 + 532) ;end if (3==v170) then return false,0 + 0 ;end end end;MGSMonitor.mgsMonitorGetSowingApplicationRate=function(v172,v173) if ((v173==nil) or (v173.spec_sowingMachine==nil)) then return false,0 + 0 ;end local v174=v173.spec_sowingMachine;local v175=nil;if ((v174.workAreaParameters~=nil) and (v174.workAreaParameters.seedsFruitType~=nil)) then v175=v174.workAreaParameters.seedsFruitType;elseif ((v174.seeds~=nil) and (v174.currentSeed~=nil)) then v175=v174.seeds[v174.currentSeed];end if (v175~=nil) then local v268=0 + 0 ;local v269;while true do if (v268==(0 + 0)) then v269=g_fruitTypeManager:getFruitTypeByIndex(v175);if ((v269~=nil) and (v269.seedUsagePerSqm~=nil)) then local v371=v174.seedUsageScale or (2 -1) ;return true,v269.seedUsagePerSqm * (23512 -13512) * v371 ;end break;end end end return false,0;end;MGSMonitor.mgsMonitorGetSprayerApplicationRate=function(v176,v177) local v178=1202 -(373 + 829) ;local v179;while true do if (v178==(733 -(476 + 255))) then if ((v179==nil) or (v179==(1269 -(231 + 1038))) or (v179==FillType.UNKNOWN)) then return false,0 + 0 ;end if (v177.getSprayerUsage~=nil) then local v321=0;local v322;local v323;local v324;while true do if (v321==(1130 -(369 + 761))) then v322=579 + 421 ;v323,v324=pcall(v177.getSprayerUsage,v177,v179,v322);v321=1 -0 ;end if ((1 -0)==v321) then if (v323 and (type(v324)=="number") and (v324>(238 -(64 + 174)))) then local v392=0 -0 ;local v393;local v394;while true do if (v392==(2 -1)) then if ((v393>(0 -0)) and (v394>(0 + 0))) then local v414=0 -0 ;local v415;local v416;while true do if ((337 -(144 + 192))==v414) then if (v416>0) then return true,v324/v416 ;end break;end if (v414==(216 -(42 + 174))) then v415=v394/(3.6 + 0) ;v416=(v415 * v393)/(8284 + 1716) ;v414=3 -2 ;end end end break;end if (v392==(0 + 0)) then v393=v176:mgsMonitorGetWorkingWidth(v177);v394=v176:mgsMonitorGetSpeedLimit(v177);v392=1505 -(363 + 1141) ;end end end break;end end end v178=1583 -(1183 + 397) ;end if (v178==(2 -1)) then if ((v177.getSprayerFillUnitIndex~=nil) and (v177.getFillUnitFillType~=nil)) then local v325,v326=pcall(v177.getSprayerFillUnitIndex,v177);if (v325 and (v326~=nil)) then v179=v177:getFillUnitFillType(v326) or (0 + 0) ;end end if (v179==(0 + 0)) then local v327=1975 -(1913 + 62) ;local v328;while true do if (v327==(0 + 0)) then v328=v177.spec_sprayer;if ((v328.workAreaParameters~=nil) and (v328.workAreaParameters.sprayFillType~=nil)) then v179=v328.workAreaParameters.sprayFillType;end break;end end end v178=5 -3 ;end if (v178==(1933 -(565 + 1368))) then if ((v177==nil) or (v177.spec_sprayer==nil)) then return false,523 -(423 + 100) ;end v179=0 -0 ;v178=1662 -(1477 + 184) ;end if (v178==(3 -0)) then return false,0;end end end;MGSMonitor.mgsMonitorGetFillTypeMassPerLiter=function(v180,v181) local v182=0 + 0 ;local v183;while true do if (v182==(2 + 0)) then return 771 -(326 + 445) ;end if (v182==(857 -(564 + 292))) then if (v183~=nil) then local v329=0 -0 ;while true do if (v329==(0 -0)) then if ((type(v183.massPerLiter)=="number") and (v183.massPerLiter>(304 -(244 + 60)))) then return v183.massPerLiter;end if ((type(v183.massPerUnit)=="number") and (v183.massPerUnit>(0 + 0))) then return v183.massPerUnit;end break;end end end if (g_fillTypeManager.getMassPerLiter~=nil) then local v330,v331=pcall(g_fillTypeManager.getMassPerLiter,g_fillTypeManager,v181);if (v330 and (type(v331)=="number") and (v331>(476 -(41 + 435)))) then return v331;end end v182=1003 -(938 + 63) ;end if (v182==(0 + 0)) then if ((v181==nil) or (v181==(881 -(614 + 267)))) then return 0;end v183=g_fillTypeManager:getFillTypeByIndex(v181);v182=1126 -(936 + 189) ;end end end;MGSMonitor.mgsMonitorGetChannelValue=function(v184,v185,v186) local v187=0 + 0 ;local v188;local v189;while true do if (v187==(1614 -(1565 + 48))) then if (v189==nil) then return 0 + 0 ;end return v189[v186] or (1138 -(782 + 356)) ;end if (v187==(267 -(176 + 91))) then v188=v184:mgsMonitorGetData();v189=((v188.channels~=nil) and v188.channels[v185]) or nil ;v187=2 -1 ;end end end;MGSMonitor.mgsMonitorGetImplementValue=function(v190,v191) local v192=0 -0 ;local v193;local v194;while true do if (v192==(1093 -(975 + 117))) then return v194[v191] or (1875 -(157 + 1718)) ;end if (v192==(0 -0)) then v193=v190:mgsMonitorGetData();v194=v193.implement or {} ;v192=1 + 0 ;end end end;MGSMonitor.mgsMonitorGetMainFillLevelPct=function(v195) return v195:mgsMonitorGetChannelValue("main","fillLevelPct");end;MGSMonitor.mgsMonitorGetMainFillLevel=function(v196) return v196:mgsMonitorGetChannelValue("main","fillLevel");end;MGSMonitor.mgsMonitorGetMainCapacity=function(v197) return v197:mgsMonitorGetChannelValue("main","capacity");end;MGSMonitor.mgsMonitorGetMainFillLevelWarning=function(v198) return v198:mgsMonitorGetChannelValue("main","fillLevelWarning");end;MGSMonitor.mgsMonitorGetMainHasFillType=function(v199) return v199:mgsMonitorGetChannelValue("main","hasFillType");end;MGSMonitor.mgsMonitorGetMainFillTypeIndex=function(v200) return v200:mgsMonitorGetChannelValue("main","fillTypeIndex");end;MGSMonitor.mgsMonitorGetMainStatus=function(v201) return v201:mgsMonitorGetChannelValue("main","status");end;MGSMonitor.mgsMonitorGetMainApplicationRateAvailable=function(v202) return v202:mgsMonitorGetChannelValue("main","applicationRateAvailable");end;MGSMonitor.mgsMonitorGetMainApplicationRate=function(v203) return v203:mgsMonitorGetChannelValue("main","applicationRate");end;MGSMonitor.mgsMonitorGetMainRemainingArea=function(v204) return v204:mgsMonitorGetChannelValue("main","remainingArea");end;MGSMonitor.mgsMonitorGetSeedsFillLevelPct=function(v205) return v205:mgsMonitorGetChannelValue("seeds","fillLevelPct");end;MGSMonitor.mgsMonitorGetSeedsFillLevel=function(v206) return v206:mgsMonitorGetChannelValue("seeds","fillLevel");end;MGSMonitor.mgsMonitorGetSeedsCapacity=function(v207) return v207:mgsMonitorGetChannelValue("seeds","capacity");end;MGSMonitor.mgsMonitorGetSeedsFillLevelWarning=function(v208) return v208:mgsMonitorGetChannelValue("seeds","fillLevelWarning");end;MGSMonitor.mgsMonitorGetSeedsHasFillType=function(v209) return v209:mgsMonitorGetChannelValue("seeds","hasFillType");end;MGSMonitor.mgsMonitorGetSeedsFillTypeIndex=function(v210) return v210:mgsMonitorGetChannelValue("seeds","fillTypeIndex");end;MGSMonitor.mgsMonitorGetSeedsStatus=function(v211) return v211:mgsMonitorGetChannelValue("seeds","status");end;MGSMonitor.mgsMonitorGetSeedsApplicationRateAvailable=function(v212) return v212:mgsMonitorGetChannelValue("seeds","applicationRateAvailable");end;MGSMonitor.mgsMonitorGetSeedsApplicationRate=function(v213) return v213:mgsMonitorGetChannelValue("seeds","applicationRate");end;MGSMonitor.mgsMonitorGetSeedsRemainingArea=function(v214) return v214:mgsMonitorGetChannelValue("seeds","remainingArea");end;MGSMonitor.mgsMonitorGetFertilizerFillLevelPct=function(v215) return v215:mgsMonitorGetChannelValue("fertilizer","fillLevelPct");end;MGSMonitor.mgsMonitorGetFertilizerFillLevel=function(v216) return v216:mgsMonitorGetChannelValue("fertilizer","fillLevel");end;MGSMonitor.mgsMonitorGetFertilizerCapacity=function(v217) return v217:mgsMonitorGetChannelValue("fertilizer","capacity");end;MGSMonitor.mgsMonitorGetFertilizerFillLevelWarning=function(v218) return v218:mgsMonitorGetChannelValue("fertilizer","fillLevelWarning");end;MGSMonitor.mgsMonitorGetFertilizerHasFillType=function(v219) return v219:mgsMonitorGetChannelValue("fertilizer","hasFillType");end;MGSMonitor.mgsMonitorGetFertilizerFillTypeIndex=function(v220) return v220:mgsMonitorGetChannelValue("fertilizer","fillTypeIndex");end;MGSMonitor.mgsMonitorGetFertilizerStatus=function(v221) return v221:mgsMonitorGetChannelValue("fertilizer","status");end;MGSMonitor.mgsMonitorGetFertilizerApplicationRateAvailable=function(v222) return v222:mgsMonitorGetChannelValue("fertilizer","applicationRateAvailable");end;MGSMonitor.mgsMonitorGetFertilizerApplicationRate=function(v223) return v223:mgsMonitorGetChannelValue("fertilizer","applicationRate");end;MGSMonitor.mgsMonitorGetFertilizerRemainingArea=function(v224) return v224:mgsMonitorGetChannelValue("fertilizer","remainingArea");end;MGSMonitor.mgsMonitorGetImplementAttachedCount=function(v225) return v225:mgsMonitorGetImplementValue("attachedCount");end;MGSMonitor.mgsMonitorGetImplementHasAttachedImplement=function(v226) return v226:mgsMonitorGetImplementValue("hasAttachedImplement");end;MGSMonitor.mgsMonitorGetImplementHasFillUnit=function(v227) return v227:mgsMonitorGetImplementValue("hasFillUnit");end;MGSMonitor.mgsMonitorGetImplementWorkingWidth=function(v228) return v228:mgsMonitorGetImplementValue("workingWidth");end;MGSMonitor.mgsMonitorGetImplementSpeedLimit=function(v229) return v229:mgsMonitorGetImplementValue("speedLimit");end;MGSMonitor.mgsMonitorGetImplementIsTurnedOn=function(v230) return v230:mgsMonitorGetImplementValue("isTurnedOn");end;MGSMonitor.mgsMonitorGetImplementMass=function(v231) return v231:mgsMonitorGetImplementValue("mass");end;MGSMonitor.mgsMonitorGetImplementIsOperating=function(v232) return v232:mgsMonitorGetImplementValue("isOperating");end;MGSMonitor.mgsMonitorGetImplementIsWorkAreaActive=function(v233) return v233:mgsMonitorGetImplementValue("isWorkAreaActive");end;