Skip to content

Commit

Permalink
06.01.00042:handle single covers
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGaertner committed Feb 5, 2019
1 parent fbcb184 commit b0b21a6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
55 changes: 40 additions & 15 deletions drive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="40">
<version>6.01.00041</version>
<version>6.01.00042</version>
<author><![CDATA[Courseplay.devTeam]]></author>
<title>
<br>CoursePlay SIX</br>
Expand Down
2 changes: 1 addition & 1 deletion start_stop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion toolManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion triggers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0b21a6

Please sign in to comment.