forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode3.lua
122 lines (103 loc) · 6.09 KB
/
mode3.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
function courseplay:handleMode3(vehicle, fill_level, allowedToDrive, dt)
courseplay:debug(string.format("handleMode3(vehicle, fill_level=%s, allowedToDrive=%s, dt)", tostring(fill_level), tostring(allowedToDrive)), 15);
local workTool = vehicle.tippers[vehicle.currentTrailerToFill] or vehicle.tippers[1];
local backPointsUnfoldPipe = 8; --[[workTool.cp.backPointsUnfoldPipe or 8;]] --NOTE: backPointsUnfoldPipe must not be 0!
local forwardPointsFoldPipe = workTool.cp.forwardPointsFoldPipe or 2;
workTool.cp.isUnloading = workTool.fillLevel < workTool.cp.lastFillLevel;
if workTool.cp.isAugerWagon then
if vehicle.wait and vehicle.cp.last_recordnumber >= math.max(vehicle.cp.waitPoints[1] - backPointsUnfoldPipe, 2) and vehicle.cp.last_recordnumber < vehicle.cp.waitPoints[1] and not workTool.cp.isUnloading then
courseplay:handleAugerWagon(vehicle, workTool, true, false, "unfold"); --unfold=true, unload=false
end;
if vehicle.wait and vehicle.cp.last_recordnumber == vehicle.cp.waitPoints[1] then
courseplay:setGlobalInfoText(vehicle, courseplay:get_locale(vehicle, "CPReachedOverloadPoint"));
local driveOn = false
if fill_level > 0 then
courseplay:handleAugerWagon(vehicle, workTool, true, true, "unload"); --unfold=true, unload=true
end;
if vehicle.last_fill_level ~= nil then
if fill_level > 0 and workTool.cp.isUnloading then
courseplay:setCustomTimer(vehicle, "fillLevelChange", 7);
elseif fill_level == vehicle.last_fill_level and fill_level < vehicle.required_fill_level_for_follow and courseplay:timerIsThrough(vehicle, "fillLevelChange", false) then
driveOn = true; -- drive on if fill_level doesn't change for 7 seconds and fill level is < required_fill_level_for_follow
end;
end;
vehicle.last_fill_level = fill_level;
if (fill_level == 0 or driveOn) and not workTool.cp.isUnloading then
courseplay:handleAugerWagon(vehicle, workTool, true, false, "stopUnload"); --unfold=true, unload=false
vehicle.wait = false;
vehicle.last_fill_level = nil;
vehicle.unloaded = true;
end;
end;
if (not vehicle.wait or vehicle.unloaded) and vehicle.cp.last_recordnumber >= math.min(vehicle.cp.waitPoints[1] + forwardPointsFoldPipe, vehicle.maxnumber - 1) then
courseplay:handleAugerWagon(vehicle, workTool, false, false, "fold"); --unfold=false, unload=false
end;
end;
workTool.cp.lastFillLevel = workTool.fillLevel;
end;
function courseplay:handleAugerWagon(vehicle, workTool, unfold, unload, orderName)
courseplay:debug(string.format("\thandleAugerWagon(vehicle, %s, unfold=%s, unload=%s, orderName=%s)", nameNum(workTool), tostring(unfold), tostring(unload), tostring(orderName)), 15);
--Taarup Shuttle
if workTool.cp.isTaarupShuttle then
if unfold and workTool.animationParts[1].clipStartTime then
workTool:setAnimationTime(1, workTool.animationParts[1].animDuration, false);
elseif not unfold and workTool.animationParts[1].clipEndTime then
workTool:setAnimationTime(1, workTool.animationParts[1].offSet, false);
end;
if (unload and workTool.unloadingState ~= 1) or (not unload and workTool.unloadingState ~= 0) then
workTool:setUnloadingState(unload);
end;
--Overcharge / AgrolinerTUW20 / Hawe SUW 5000
elseif workTool.cp.hasSpecializationOvercharge or workTool.cp.hasSpecializationAgrolinerTUW20 or workTool.cp.isHaweSUW5000 then
if unfold and not workTool.pipe.out then
workTool:setAnimationTime(1, workTool.animationParts[1].animDuration, false);
elseif not unfold and workTool.pipe.out then
workTool:setAnimationTime(1, workTool.animationParts[1].offSet, false);
end;
if unload and not workTool.isUnloading and workTool.trailerFoundId ~= 0 then
workTool:setUnloadingState(true);
if workTool.cp.isHaweSUW5000 then
workTool.isDrumActivated = workTool.isUnloading;
end;
elseif not unload and workTool.isUnloading then
workTool:setUnloadingState(false);
if workTool.cp.isHaweSUW5000 then
workTool.isDrumActivated = workTool.isUnloading;
end;
end;
--Brent Avalanche
elseif workTool.cp.isBrentAvalanche then
-- n/a in FS13
--Overloader spec
elseif workTool.cp.hasSpecializationOverloaderV2 then
if (unfold and workTool.cpAI ~= "out") or (not unfold and workTool.cpAI ~= "in") then
if unfold then
workTool.cpAI = "out";
else
workTool.cpAI = "in";
end;
if workTool.pipeLight ~= nil and g_currentMission.environment.needsLights or (g_currentMission.environment.lastRainScale > 0.1 and g_currentMission.environment.timeSinceLastRain < 30) then
setVisibility(workTool.pipeLight, unfold);
end;
end;
if (unload and workTool.trailerToOverload ~= nil and not workTool.isCharging) or (not unload and workTool.isCharging) then
workTool.isCharging = unload;
end;
--AugerWagon spec
elseif workTool.cp.hasSpecializationAugerWagon and workTool.foldAnimTime ~= nil and workTool.turnOnFoldDirection ~= nil then
local pipeIsFolding = workTool.foldAnimTime > workTool.cp.lastFoldAnimTime;
local pipeIsUnfolding = workTool.foldAnimTime < workTool.cp.lastFoldAnimTime;
local pipeIsFolded = workTool.foldAnimTime == 1;
local pipeIsUnfolded = workTool.foldAnimTime == 0;
courseplay:debug(string.format("\t\t%s: foldAnimTime=%s, lastFoldAnimTime=%s", nameNum(workTool), tostring(workTool.foldAnimTime), tostring(workTool.cp.lastFoldAnimTime)), 15);
courseplay:debug(string.format("\t\t%s: pipeIsFolding=%s, pipeIsUnfolding=%s, pipeIsFolded=%s, pipeIsUnfolded=%s", nameNum(workTool), tostring(pipeIsFolding), tostring(pipeIsUnfolding), tostring(pipeIsFolded), tostring(pipeIsUnfolded)), 15);
if unfold and not pipeIsUnfolded and not pipeIsUnfolding then
workTool:setFoldDirection(workTool.turnOnFoldDirection); -- -1
courseplay:debug(string.format("\t\t\t%s: setFoldDirection(%s) (unfold)", nameNum(workTool), tostring(workTool.turnOnFoldDirection)), 15);
elseif not unfold and not pipeIsFolded and not pipeIsFolding then
workTool:setFoldDirection(workTool.turnOnFoldDirection * -1); -- 1
courseplay:debug(string.format("\t\t\t%s: setFoldDirection(%s) (fold)", nameNum(workTool), tostring(workTool.turnOnFoldDirection * -1)), 15);
end;
workTool.cp.lastFoldAnimTime = workTool.foldAnimTime;
end;
end;