From b0b21a6f7ee3752711da5b550d74cb5ea9cf1fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=A4rtner?= Date: Tue, 5 Feb 2019 18:21:58 +0100 Subject: [PATCH] 06.01.00042:handle single covers --- drive.lua | 55 +++++++++++++++++++++++++++++++++++-------------- modDesc.xml | 2 +- start_stop.lua | 2 +- toolManager.lua | 2 +- triggers.lua | 4 +++- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/drive.lua b/drive.lua index 6008421ab..66dea72a3 100644 --- a/drive.lua +++ b/drive.lua @@ -667,7 +667,7 @@ function courseplay:drive(self, dt) showCover = not workArea and self.cp.currentTipTrigger == nil; end; - courseplay:openCloseCover(self, showCover, self.cp.currentTipTrigger ~= nil); + courseplay:openCloseCover(self, showCover); elseif self.cp.tipperHasCover then courseplay:openCloseCover(self, false); end; @@ -1248,23 +1248,48 @@ function courseplay:getSpeedWithLimiter(vehicle, refSpeed) return refSpeed, speedLimitActivated; end -function courseplay:openCloseCover(vehicle, showCover, isAtTipTrigger, stopOrder) +function courseplay:openCloseCover(vehicle, showCover, fillTrigger) for i,twc in pairs(vehicle.cp.tippersWithCovers) do local tIdx, coverType, showCoverWhenTipping, coverItems = twc.tipperIndex, twc.coverType, twc.showCoverWhenTipping, twc.coverItems; local tipper = vehicle.cp.workTools[tIdx]; -- default Giants trailers if coverType == 'defaultGiants' then - local isSprayer, isSowingMachine = courseplay:isSprayer(tipper), courseplay:isSowingMachine(tipper); - --[[if (vehicle.cp.mode == 4 and tipper.fillTriggers and tipper.fillTriggers[1] ~= nil) - or (vehicle.cp.mode == 1 and tipper.fillTriggers and tipper.fillTriggers[1] ~= nil) - or (stopOrder and (isSprayer or isSowingMachine)) then - return - end]] - local newState = showCover and 0 or 1 - if tipper.spec_cover.state ~= newState then - tipper:setCoverState(newState); - end; - + if not showCover then + if courseplay:isSprayer(tipper) or courseplay:isSowingMachine(tipper) and fillTrigger then + local fillUnits = tipper:getFillUnits() + for i=1,#fillUnits do + if courseplay:fillTypesMatch(vehicle, fillTrigger, tipper, i) then + if tipper.spec_cover.state ~= i then + tipper:setCoverState(i,true); + end + end + end + else + local newState = 1 + if tipper.spec_cover.state ~= newState and tipper:getIsNextCoverStateAllowed(newState) then + tipper:setCoverState(newState,true); + end + end + else --showCover + local newState = 0 + if tipper.spec_cover.state ~= newState then + if tipper:getIsNextCoverStateAllowed(newState) then + tipper:setCoverState(newState,true); + else + for i=tipper.spec_cover.state,#tipper.spec_cover.covers do + if tipper:getIsNextCoverStateAllowed(i+1)then + tipper:setCoverState(i+1,true); + end + if tipper:getIsNextCoverStateAllowed(newState) then + tipper:setCoverState(newState,true); + break + end + end + end; + end + end + + -- Example: for mods trailer that don't use the default cover specialization else--if coverType == 'CoverVehicle' then @@ -1472,7 +1497,7 @@ function courseplay:isInUnloadArea(vehicle, wpBefore, wpAfter, fromWP, unloadInd return false; end; -function courseplay:handleMapWeightStation(vehicle, allowedToDrive) +--[[function courseplay:handleMapWeightStation(vehicle, allowedToDrive) local station, name, x, y, z, vehToCenterX, vehToCenterZ; local isInFrontOfStation = vehicle.cp.fillTrigger ~= nil; @@ -1590,7 +1615,7 @@ function courseplay:handleMapWeightStation(vehicle, allowedToDrive) courseplay:debug(('%s: handleMapWeightStation() **END** -> station=%s, isInFrontOfStation=%s, isInStation=%s, vehToCenterZ=%s'):format(nameNum(vehicle), tostring(name), tostring(isInFrontOfStation), tostring(vehicle.cp.curMapWeightStation ~= nil), tostring(vehToCenterZ)), 20); return allowedToDrive; -end; +end;]] function courseplay:setReverseBackDistance(vehicle, metersBack) if not vehicle or not metersBack then return; end; diff --git a/modDesc.xml b/modDesc.xml index d35a7e4e1..79cee9222 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -1,6 +1,6 @@ - 6.01.00041 + 6.01.00042 <br>CoursePlay SIX</br> diff --git a/start_stop.lua b/start_stop.lua index 15e1f6932..36a5fdc90 100644 --- a/start_stop.lua +++ b/start_stop.lua @@ -814,7 +814,7 @@ function courseplay:stop(self) --open all covers if self.cp.workToolAttached and self.cp.tipperHasCover and self.cp.mode == 1 or self.cp.mode == 2 or self.cp.mode == 5 or self.cp.mode == 6 then - courseplay:openCloseCover(self,false,false,true); + courseplay:openCloseCover(self,not courseplay.SHOW_COVERS); end; -- resetting variables diff --git a/toolManager.lua b/toolManager.lua index beb5e8be7..17d021905 100644 --- a/toolManager.lua +++ b/toolManager.lua @@ -1305,7 +1305,7 @@ function courseplay:refillWorkTools(vehicle, driveOnAtPercent, allowedToDrive, l local trigger = courseplay.triggers.fillTriggers[vehicle.cp.fillTrigger] if trigger ~= nil and courseplay:fillTypesMatch(vehicle, trigger, workTool) then courseplay:setInfoText(vehicle, string.format("COURSEPLAY_LOADING_AMOUNT;%d;%d",courseplay.utils:roundToLowerInterval(vehicle.cp.totalFillLevel, 100),vehicle.cp.totalCapacity)); - courseplay:openCloseCover(vehicle, not courseplay.SHOW_COVERS) + courseplay:openCloseCover(vehicle, not courseplay.SHOW_COVERS,trigger) allowedToDrive, isFilling = courseplay:fillOnTrigger(vehicle, workTool,vehicle.cp.fillTrigger) else courseplay:resetFillTrigger(vehicle) diff --git a/triggers.lua b/triggers.lua index 87b90bef2..400733718 100644 --- a/triggers.lua +++ b/triggers.lua @@ -199,7 +199,9 @@ function courseplay:findSpecialTriggerCallback(transformId, x, y, z, distance) --print("findSpecialTriggerCallback found "..tostring(transformId).." "..getName(transformId)) if courseplay.triggers.fillTriggers[transformId] then --print(transformId.." is in fillTrigers") - self.cp.fillTrigger = transformId; + if self.cp.fillTrigger == nil then + self.cp.fillTrigger = transformId; + end courseplay:setCustomTimer(self, 'triggerFailBackup', 10); return false; end