This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode3.lua
253 lines (224 loc) · 11.9 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
function courseplay:handleMode3(vehicle, allowedToDrive, dt)
courseplay:debug(string.format("handleMode3(vehicle, allowedToDrive=%s, dt)",tostring(allowedToDrive)), 15);
local workTool = vehicle.cp.workTools[vehicle.cp.currentTrailerToFill] or vehicle.cp.workTools[1];
local backPointsUnfoldPipe = 8; --[[workTool.cp.backPointsUnfoldPipe or 8;]] --NOTE: backPointsUnfoldPipe must not be 0!
local forwardPointsFoldPipe = workTool.cp.forwardPointsFoldPipe or 2;
local fillLevelPct = workTool.cp.fillLevelPercent
workTool.cp.isUnloading = workTool.cp.fillLevel < workTool.cp.lastFillLevel or workTool.cp.isSugarCaneUnloading;
if workTool.cp.isAugerWagon then
if vehicle.cp.wait and vehicle.cp.previousWaypointIndex >= math.max(vehicle.cp.waitPoints[1] - backPointsUnfoldPipe, 2) and vehicle.cp.previousWaypointIndex < vehicle.cp.waitPoints[1] and not workTool.cp.isUnloading then
courseplay:handleAugerWagon(vehicle, workTool, true, false, "unfold",dt); --unfold=true, unload=false
end;
if vehicle.cp.wait and vehicle.cp.previousWaypointIndex == vehicle.cp.waitPoints[1] then
CpManager:setGlobalInfoText(vehicle, 'OVERLOADING_POINT');
local driveOn = false
if fillLevelPct > 0 then
courseplay:handleAugerWagon(vehicle, workTool, true, true, "unload",dt); --unfold=true, unload=true
elseif workTool.cp.isSugarCaneUnloading then -- used for sugarCane overloader to fold completely before driving on
courseplay:handleAugerWagon(vehicle, workTool, true, false, "unload",dt); --unfold=true, unload=false
end;
if vehicle.cp.prevFillLevelPct ~= nil then
if fillLevelPct > 0 and workTool.cp.isUnloading then
courseplay:setCustomTimer(vehicle, "fillLevelChange", 10);
elseif fillLevelPct == vehicle.cp.prevFillLevelPct and fillLevelPct < vehicle.cp.followAtFillLevel and courseplay:timerIsThrough(vehicle, "fillLevelChange", false) then
driveOn = true; -- drive on if fillLevelPct doesn't change for 10 seconds and fill level is < required_fillLevelPct_for_follow
courseplay:debug(' no fillLevel change for 10 seconds -> driveOn', 15);
end;
end;
vehicle.cp.prevFillLevelPct = fillLevelPct;
if (fillLevelPct == 0 or driveOn) and not workTool.cp.isUnloading then
courseplay:handleAugerWagon(vehicle, workTool, true, false, "stopUnload",dt); --unfold=true, unload=false
courseplay:cancelWait(vehicle);
end;
end;
if courseplay.debugChannels[15] then
courseplay:checkAndPrintChange(vehicle, vehicle.cp.waitPoints[1], "firstWaitPoint");
courseplay:checkAndPrintChange(vehicle, vehicle.cp.numWaypoints, "numWaypoints");
courseplay:checkAndPrintChange(vehicle, backPointsUnfoldPipe, "backPointsUnfoldPipe");
courseplay:checkAndPrintChange(vehicle, forwardPointsFoldPipe, "forwardPointsFoldPipe");
courseplay:checkAndPrintChange(vehicle, vehicle.cp.previousWaypointIndex, "previousWaypointIndex");
courseplay:checkAndPrintChange(vehicle, vehicle.cp.isUnloaded, "isUnloaded");
courseplay:checkAndPrintChange(vehicle, vehicle.cp.wait, "wait");
print("-------------------------");
end;
if vehicle.cp.previousWaypointIndex < math.max(vehicle.cp.waitPoints[1] - backPointsUnfoldPipe, 2) then -- is before unfold pipe point
courseplay:handleAugerWagon(vehicle, workTool, false, false, "foldBefore",dt); --unfold=false, unload=false
elseif (not vehicle.cp.wait or vehicle.cp.isUnloaded) and vehicle.cp.previousWaypointIndex >= math.min(vehicle.cp.waitPoints[1] + forwardPointsFoldPipe, vehicle.cp.numWaypoints - 1) then -- is past fold pipe point
courseplay:handleAugerWagon(vehicle, workTool, false, false, "foldAfter",dt); --unfold=false, unload=false
courseplay:resetCustomTimer(vehicle, "fillLevelChange", true)
vehicle.cp.prevFillLevelPct = nil;
elseif workTool.cp.isUnloading and not vehicle.cp.wait then
courseplay:handleAugerWagon(vehicle, workTool, true, false, "forceStopUnload",dt); --unfold=true, unload=false
end;
end;
workTool.cp.lastFillLevel = workTool.cp.fillLevel;
end;
function courseplay:handleAugerWagon(vehicle, workTool, unfold, unload, orderName,dt)
courseplay:debug(string.format("\thandleAugerWagon(vehicle, %s, unfold=%s, unload=%s, orderName=%s)", nameNum(workTool), tostring(unfold), tostring(unload), tostring(orderName)), 15);
local pipeOrderExists = unfold ~= nil;
local unloadOrderExists = unload ~= nil;
if workTool.cp.isSugarCaneAugerWagon then
local movingTools = workTool.movingTools
if unload then
workTool.cp.isSugarCaneUnloading = true
local targetPositions = { rot = { [1] = 0},
trans = { [1] = movingTools[1].transMax }
}
if courseplay:checkAndSetMovingToolsPosition(vehicle, movingTools, nil, targetPositions, dt ,1) then
local targetPositions = { rot = { [1] = movingTools[2].rotMin},
trans = { [1] = 0 }
}
courseplay:checkAndSetMovingToolsPosition(vehicle, movingTools, nil, targetPositions, dt ,2)
end
else
local targetPositions = { rot = { [1] = movingTools[2].rotMax},
trans = { [1] = 0 }
}
if courseplay:checkAndSetMovingToolsPosition(vehicle, movingTools, nil, targetPositions, dt ,2) then
local targetPositions = { rot = { [1] = 0},
trans = { [1] = movingTools[1].transMin }
}
if courseplay:checkAndSetMovingToolsPosition(vehicle, movingTools, nil, targetPositions, dt ,1) then
workTool.cp.isSugarCaneUnloading = nil
end
end
end
--Taarup Shuttle
elseif workTool.cp.isTaarupShuttle then
if pipeOrderExists 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;
end;
if unloadOrderExists then
if (unload and workTool.unloadingState ~= 1) or (not unload and workTool.unloadingState ~= 0) then
workTool:setUnloadingState(unload);
end;
end;
--Overcharge / AgrolinerTUW20 / Hawe SUW
elseif workTool.cp.hasSpecializationOvercharge or workTool.cp.hasSpecializationAgrolinerTUW20 or workTool.cp.hasSpecializationHaweSUW then
if pipeOrderExists and workTool.pipe.out ~= nil then
if unfold and not workTool.pipe.out then
workTool:setAnimationTime(1, workTool.animationParts[1].animDuration, false);
if workTool.cp.hasPipeLight and workTool.cp.pipeLight.a ~= CpManager.lightsNeeded then
workTool:setState("work:1", CpManager.lightsNeeded);
end;
elseif not unfold and workTool.pipe.out then
workTool:setAnimationTime(1, workTool.animationParts[1].offSet, false);
if workTool.cp.hasPipeLight and workTool.cp.pipeLight.a then
workTool:setState("work:1", false);
end;
end;
end;
if unload and not workTool.isUnloading and (workTool.trailerFoundId ~= 0 or workTool.trailerFound ~= nil) then
workTool:setUnloadingState(true);
if workTool.isDrumActivated ~= nil then
workTool.isDrumActivated = workTool.isUnloading;
end;
elseif not unload and workTool.isUnloading then
workTool:setUnloadingState(false);
if workTool.isDrumActivated ~= nil then
workTool.isDrumActivated = workTool.isUnloading;
end;
end;
--Ropa Big Bear / 'bigBear' spec
elseif workTool.cp.hasSpecializationBigBear then
if pipeOrderExists then
if unfold and not workTool.activeWorkMode then
if not workTool.workMode then
courseplay:debug('\t\tunfold=true, activeWorkMode=false, workMode=false -> set workMode to true', 15);
workTool.workMode = true;
workTool.bigBearNeedEvent = true;
else
courseplay:debug('\t\tunfold=true, activeWorkMode=false, workMode=true -> set activeWorkMode to true', 15);
workTool.activeWorkMode = true;
workTool.bigBearNeedEvent = true;
end;
elseif not unfold then
if workTool.activeWorkMode then
courseplay:debug('\t\tunfold=false, activeWorkMode=true -> set activeWorkMode to false', 15);
workTool.activeWorkMode = false;
workTool.bigBearNeedEvent = true;
end;
end;
end;
if unload and workTool.allowOverload and not workTool.isUnloading and workTool.trailerRaycastFound then
courseplay:debug('\t\tunload=true, allowOverload=true, isUnloading=false, trailerRaycastFound=true -> set isUnloading to true', 15);
workTool.isUnloading = true;
workTool.bigBearNeedEvent = true;
elseif workTool.isUnloading and (not unload or not workTool.trailerRaycastFound or not workTool.allowOverload) then
courseplay:debug(string.format('\t\tunload=%s, isUnloading=true, allowOverload=%s, trailerRaycastFound=%s -> set isUnloading to false', tostring(unload), tostring(workTool.allowOverload), tostring(workTool.trailerRaycastFound)), 15);
workTool.isUnloading = false;
workTool.bigBearNeedEvent = true;
end;
--Brent Avalanche
elseif workTool.cp.isBrentAvalanche then
-- n/a in FS13
--Overloader spec
elseif workTool.cp.hasSpecializationOverloaderV2 then
if pipeOrderExists then
if (unfold and workTool.cpAI ~= "out") or (not unfold and workTool.cpAI ~= "in") then
local newPipeState = unfold and 'out' or 'in';
courseplay:debug(string.format('\t\tunfold=%s, workTool.cpAI=%s -> set workTool.cpAI to %s', tostring(unfold), tostring(workTool.cpAI), newPipeState), 15);
workTool.cpAI = newPipeState;
if workTool.pipeLight ~= nil and getVisibility(workTool.pipeLight) ~= (unfold and CpManager.lightsNeeded) then
if workTool.togglePipeLight then
workTool:togglePipeLight(unfold and CpManager.lightsNeeded);
else
setVisibility(workTool.pipeLight, unfold and CpManager.lightsNeeded);
end;
end;
end;
end;
local hasTrailer = workTool.trailerToOverload ~= nil;
local trailerIsFull = hasTrailer and workTool.trailerToOverload.fillLevel and workTool.trailerToOverload.capacity and workTool.trailerToOverload.fillLevel >= workTool.trailerToOverload.capacity;
if (unload and hasTrailer and not trailerIsFull and not workTool.isCharging) or (not unload and workTool.isCharging) then
workTool.isCharging = unload;
courseplay:debug(string.format('\t\tset workTool.isCharging to %s', tostring(unload)), 15);
end;
--AugerWagon spec
elseif workTool.typeName == 'augerWagon' or workTool.cp.isAugerWagon then
if pipeOrderExists then
local pipeIsFolding = workTool.pipeCurrentState == 0;
local pipeIsFolded = workTool.pipeCurrentState == 1
local pipeIsUnfolded = workTool.pipeCurrentState == 2;
courseplay:debug(string.format("\t\tpipeIsFolding=%s, pipeIsFolded=%s, pipeIsUnfolded=%s", tostring(pipeIsFolding), tostring(pipeIsFolded), tostring(pipeIsUnfolded)), 15);
if unfold and not pipeIsFolding and pipeIsFolded then
workTool:setPipeState(2);
courseplay:debug("\t\t\tsetPipeState(2) (unfold)", 15);
elseif not unfold and not pipeIsFolding and pipeIsUnfolded then
workTool:setPipeState(1);
courseplay:debug("\t\t\tsetPipeState(1) (fold)", 15);
end;
if unfold and pipeIsUnfolded and vehicle.cp.pipePositions then
courseplay:checkAndSetMovingToolsPosition(vehicle, workTool.movingTools, nil, vehicle.cp.pipePositions, dt , vehicle.cp.pipeIndex ) ;
end
workTool.cp.lastFoldAnimTime = workTool.foldAnimTime;
end;
end;
end;
function courseplay:getPipesRotation(vehicle)
vehicle.cp.pipeWorkToolIndex = nil
for i,implement in pairs(vehicle.attachedImplements) do
local workTool = implement.object;
vehicle.cp.pipeIndex = nil
vehicle.cp.pipePositions = nil
if workTool.movingTools and workTool.pipeCurrentState and workTool.pipeCurrentState == 2 then
for index,tool in pairs(workTool.movingTools) do
if tool.axis and tool.axis == "AXIS_PIPE" then
vehicle.cp.pipeIndex = index --index of movingTools
vehicle.cp.pipeWorkToolIndex = i --index of attachedImplements
end
end
end
if vehicle.cp.pipeIndex ~= nil then
local rotation, translation = courseplay:getCurrentMovingToolsPosition(self, workTool.movingTools, nil, vehicle.cp.pipeIndex)
vehicle.cp.pipePositions = {
rot = rotation ;
trans = translation;
}
end
end
end