forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_stop.lua
637 lines (553 loc) · 23.1 KB
/
start_stop.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
local curFile = 'start_stop.lua';
-- starts driving the course
function courseplay:start(self)
if g_server == nil then
return
end
self.cp.TrafficBrake = false
self.cp.inTraffic = false
if not CpManager.trafficCollisionIgnoreList[g_currentMission.terrainRootNode] then -- ???
CpManager.trafficCollisionIgnoreList[g_currentMission.terrainRootNode] = true;
end;
-- TODO: move this to TrafficCollision.lua
if self:getAINeedsTrafficCollisionBox() then
local collisionRoot = g_i3DManager:loadSharedI3DFile(AIVehicle.TRAFFIC_COLLISION_BOX_FILENAME, self.baseDirectory, false, true, false)
if collisionRoot ~= nil and collisionRoot ~= 0 then
local collision = getChildAt(collisionRoot, 0)
link(getRootNode(), collision)
self.spec_aiVehicle.aiTrafficCollision = collision
delete(collisionRoot)
end
end
self.cp.numWayPoints = #self.Waypoints;
--self:setCpVar('numWaypoints', #self.Waypoints,courseplay.isClient);
if self.cp.numWaypoints < 1 then
return
end
courseplay:setEngineState(self, true);
self.cp.saveFuel = false
courseplay.alreadyPrinted = {}
self.cpTrafficCollisionIgnoreList = {}
self.cp.collidingVehicleId = nil
self.cp.collidingObjects = {
all = {};
};
courseplay:debug(string.format("%s: Start/Stop: deleting \"self.cp.collidingVehicleId\"", nameNum(self)), 3);
self:setIsCourseplayDriving(false);
courseplay:setIsRecording(self, false);
courseplay:setRecordingIsPaused(self, false);
self.cp.calculatedCourseToCombine = false
courseplay:resetTools(self)
if self.cp.waypointIndex < 1 then
courseplay:setWaypointIndex(self, 1);
end
-- add do working players if not already added
if self.cp.coursePlayerNum == nil then
self.cp.coursePlayerNum = CpManager:addToTotalCoursePlayers(self)
end;
-- show arrow
self:setCpVar('distanceCheck',true,courseplay.isClient);
-- current position
local ctx, cty, ctz = getWorldTranslation(self.cp.directionNode);
-- TODO: temporary bandaid here for the case when the legacy waypointIndex isn't set correctly
if self.cp.waypointIndex > #self.Waypoints then
courseplay.infoVehicle(self, 'Waypoint index %d reset to %d', self.cp.waypointIndex, #self.Waypoints)
self.cp.waypointIndex = #self.Waypoints
end
-- position of next waypoint
local cx, cz = self.Waypoints[self.cp.waypointIndex].cx, self.Waypoints[self.cp.waypointIndex].cz
-- distance (in any direction)
local dist = courseplay:distance(ctx, ctz, cx, cz)
local setLaneNumber = false;
local isFrontAttached = false;
local isReversePossible = true;
local tailerCount = 0;
for k,workTool in pairs(self.cp.workTools) do --TODO temporary solution (better would be Tool:getIsAnimationPlaying(animationName))
if courseplay:isFolding(workTool) then
if self.setLowered ~= nil then
workTool:setLowered(true)
elseif self.setFoldState ~= nil then
self:setFoldState(-1, true)
end
end;
--DrivingLine spec: set lane numbers
if self.cp.mode == 4 and not setLaneNumber and workTool.cp.hasSpecializationDrivingLine and not workTool.manualDrivingLine then
setLaneNumber = true;
end;
if self.cp.mode == 10 then
local x,y,z = getWorldTranslation(workTool.rootNode)
local _,_,tz = worldToLocal(self.cp.directionNode,x,y,z)
if tz > 0 then
isFrontAttached = true
end
end
if workTool.cp.hasSpecializationTrailer then
tailerCount = tailerCount + 1
if tailerCount > 1 then
isReversePossible = false
end
end
-- TODO: this must be moved to the AIDriver somewhere, has nothing to do here...
if workTool.spec_sprayer ~= nil and self.cp.hasFertilizerSowingMachine then
workTool.fertilizerEnabled = self.cp.settings.sowingMachineFertilizerEnabled:is(true)
end
if workTool.cp.isSugarCaneAugerWagon then
isReversePossible = false
end
end;
self.cp.isReversePossible = isReversePossible
self.cp.mode10.levelerIsFrontAttached = isFrontAttached
local numWaitPoints = 0
local numUnloadPoints = 0
local numCrossingPoints = 0
self.cp.waitPoints = {};
self.cp.unloadPoints = {};
self.cp.workDistance = 0
self.cp.mediumWpDistance = 0
self.cp.mode10.alphaList = {}
-- modes 4/6 without start and stop point, set them at start and end, for only-on-field-courses
if (self.cp.mode == 4 or self.cp.mode == 6) then
if numWaitPoints == 0 or self.cp.startWork == nil then
self.cp.startWork = 1;
end;
if numWaitPoints == 0 or self.cp.stopWork == nil then
self.cp.stopWork = self.cp.numWaypoints;
end;
end;
self.cp.numWaitPoints = numWaitPoints;
self.cp.numUnloadPoints = numUnloadPoints;
self.cp.numCrossingPoints = numCrossingPoints;
courseplay:debug(string.format("%s: numWaitPoints=%d, waitPoints[1]=%s, numCrossingPoints=%d", nameNum(self), self.cp.numWaitPoints, tostring(self.cp.waitPoints[1]), numCrossingPoints), 12);
-- set waitTime to 0 if necessary
if not courseplay:getCanHaveWaitTime(self) and self.cp.waitTime > 0 then
courseplay:changeWaitTime(self, -self.cp.waitTime);
end;
if self.cp.waypointIndex > 2 and self.cp.mode ~= 4 and self.cp.mode ~= 6 and self.cp.mode ~= 8 then
courseplay:setDriveUnloadNow(self, true);
elseif self.cp.mode == 4 or self.cp.mode == 6 then
courseplay:setDriveUnloadNow(self, false);
self.cp.hasUnloadingRefillingCourse = self.cp.numWaypoints > self.cp.stopWork + 7;
self.cp.hasTransferCourse = self.cp.startWork > 5
if self.Waypoints[self.cp.stopWork].cx == self.Waypoints[self.cp.startWork].cx
and self.Waypoints[self.cp.stopWork].cz == self.Waypoints[self.cp.startWork].cz then -- TODO: VERY unsafe, there could be LUA float problems (e.g. 7 + 8 = 15.000000001)
self.cp.finishWork = self.cp.stopWork-5
else
self.cp.finishWork = self.cp.stopWork
end
-- NOTE: if we want to start the course but catch one of the last 5 points ("returnToStartPoint"), make sure we get wp 2
if self.cp.settings.startingPoint:is(StartingPointSetting.START_AT_NEAREST_POINT) and self.cp.finishWork ~= self.cp.stopWork and self.cp.waypointIndex > self.cp.finishWork and self.cp.waypointIndex <= self.cp.stopWork then
courseplay:setWaypointIndex(self, 2);
end
courseplay:debug(string.format("%s: numWaypoints=%d, stopWork=%d, finishWork=%d, hasUnloadingRefillingCourse=%s,hasTransferCourse=%s, waypointIndex=%d", nameNum(self), self.cp.numWaypoints, self.cp.stopWork, self.cp.finishWork, tostring(self.cp.hasUnloadingRefillingCourse),tostring(self.cp.hasTransferCourse), self.cp.waypointIndex), 12);
elseif self.cp.mode == 8 then
courseplay:setDriveUnloadNow(self, false);
end
if self.cp.settings.startingPoint:is(StartingPointSetting.START_AT_FIRST_POINT) then
if self.cp.mode == 2 or self.cp.mode == 3 then
-- TODO: really? 3?
courseplay:setWaypointIndex(self, 3);
courseplay:setDriveUnloadNow(self, true);
else
courseplay:setWaypointIndex(self, 1);
end
end;
courseplay:updateAllTriggers();
self.cp.aiLightsTypesMaskBackup = self.spec_lights.aiLightsTypesMask
self.cp.cruiseControlSpeedBackup = self:getCruiseControlSpeed();
--check Crab Steering mode and set it to default
if self.crabSteering and (self.crabSteering.state ~= self.crabSteering.aiSteeringModeIndex or self.cp.useCrabSteeringMode ~= nil) then
local crabSteeringMode = self.cp.useCrabSteeringMode or self.crabSteering.aiSteeringModeIndex;
self:setCrabSteering(crabSteeringMode);
end
-- ok i am near the waypoint, let's go
self.cp.savedCheckSpeedLimit = self.checkSpeedLimit;
self.checkSpeedLimit = false
self.cp.runOnceStartCourse = true;
self:setIsCourseplayDriving(true);
courseplay:setIsRecording(self, false);
self:setCpVar('distanceCheck',false,courseplay.isClient);
self.cp.totalLength, self.cp.totalLengthOffset = courseplay:getTotalLengthOnWheels(self);
courseplay:validateCanSwitchMode(self);
-- Disable crop destruction if 4Real Module 01 - Crop Destruction mod is installed
if self.cropDestruction then
courseplay:disableCropDestruction(self);
end;
local ret_removeLegacyCollisionTriggers = false -- TODO could be used for further processing / error handling / information to the user
ret_removeLegacyCollisionTriggers = courseplay:removeLegacyCollisionTriggers(self)
-- and another ugly hack here as when settings.lua setAIDriver() is called the bale loader does not seem to be
-- attached and I don't have the motivation do dig through the legacy code to find out why
if self.cp.mode == courseplay.MODE_FIELDWORK then
self.cp.driver:delete()
self.cp.driver = UnloadableFieldworkAIDriver.create(self)
end
StartStopEvent:sendStartEvent(self)
self.cp.driver:start(self.cp.settings.startingPoint)
end;
function courseplay:getCanUseCpMode(vehicle)
-- check engine running state
if not courseplay:getIsEngineReady(vehicle) then
return false;
end;
local mode = vehicle.cp.mode;
if (mode == 7 and not vehicle.cp.isCombine and not vehicle.cp.isChopper and not vehicle.cp.isHarvesterSteerable)
or ((mode == 1 or mode == 2 or mode == 3 or mode == 4 or mode == 8 or mode == 9) and (vehicle.cp.isCombine or vehicle.cp.isChopper or vehicle.cp.isHarvesterSteerable))
or ((mode ~= 5) and (vehicle.cp.isWoodHarvester or vehicle.cp.isWoodForwarder)) then
courseplay:setInfoText(vehicle, 'COURSEPLAY_MODE_NOT_SUPPORTED_FOR_VEHICLETYPE');
print('Not Supported Vehicle Type')
return false;
end;
if mode ~= 5 and mode ~= 7 and not vehicle.cp.workToolAttached then
if mode == 4 or mode == 6 then
courseplay:setInfoText(vehicle, 'COURSEPLAY_WRONG_TOOL');
elseif mode == 9 then
courseplay:setInfoText(vehicle, 'COURSEPLAY_SHOVEL_NOT_FOUND');
elseif mode == 10 then
courseplay:setInfoText(vehicle, 'COURSEPLAY_MODE10_NOBLADE');
else
courseplay:setInfoText(vehicle, 'COURSEPLAY_WRONG_TRAILER');
end;
return false;
end;
if mode == 10 and vehicle.cp.mode10.levelerIsFrontAttached then
courseplay:setInfoText(vehicle, 'COURSEPLAY_MODE10_NOFRONTBLADE');
return false;
end
local minWait, maxWait, minUnload, maxUnload;
if (mode == 1 and vehicle.cp.hasAugerWagon) or mode == 3 or mode == 8 or mode == 10 then
minWait, maxWait = 1, 1;
if vehicle.cp.hasWaterTrailer then
maxWait = 10
end
if vehicle.cp.numWaitPoints < minWait then
courseplay:setInfoText(vehicle, string.format("COURSEPLAY_WAITING_POINTS_TOO_FEW;%d",minWait));
return false;
elseif vehicle.cp.numWaitPoints > maxWait then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_WAITING_POINTS_TOO_MANY;%d',maxWait));
return false;
end;
if mode == 3 then
maxUnload = 0
if vehicle.cp.workTools[1] == nil or vehicle.cp.workTools[1].cp == nil or not vehicle.cp.workTools[1].cp.isAugerWagon then
courseplay:setInfoText(vehicle, 'COURSEPLAY_WRONG_TRAILER');
return false;
elseif vehicle.cp.numUnloadPoints > maxUnload then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_UNLOADING_POINTS_TOO_MANY;%d',maxUnload));
return false;
end;
elseif mode == 8 then
if vehicle.cp.workTools[1] == nil then
courseplay:setInfoText(vehicle, 'COURSEPLAY_WRONG_TRAILER');
return false;
end;
end;
elseif mode == 7 then
-- DELETE ME MODE 7 Crap
minWait, maxWait = 1, 1;
if vehicle.cp.numUnloadPoints == 0 and vehicle.cp.numWaitPoints < minWait then
courseplay:setInfoText(vehicle, string.format("COURSEPLAY_WAITING_POINTS_TOO_FEW;%d",minWait));
return false;
elseif vehicle.cp.numWaitPoints > maxWait then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_WAITING_POINTS_TOO_MANY;%d',maxWait));
return false;
end;
minUnload, maxUnload = 2, 2;
if vehicle.cp.numWaitPoints == 0 and vehicle.cp.numUnloadPoints < minUnload then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_UNLOADING_POINTS_TOO_FEW;%d',minUnload));
return false;
elseif vehicle.cp.numUnloadPoints > maxUnload then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_UNLOADING_POINTS_TOO_MANY;%d',maxUnload));
return false;
end;
elseif mode == 4 or mode == 6 then
if vehicle.cp.startWork == nil or vehicle.cp.stopWork == nil then
courseplay:setInfoText(vehicle, 'COURSEPLAY_NO_WORK_AREA');
return false;
end;
if mode == 6 then
maxUnload = 0;
if vehicle.cp.hasBaleLoader then
minWait, maxWait = 2, 3;
if vehicle.cp.numWaitPoints < minWait then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_WAITING_POINTS_TOO_FEW;%d',minWait));
return false;
elseif vehicle.cp.numWaitPoints > maxWait then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_WAITING_POINTS_TOO_MANY;%d',maxWait));
return false;
end; --TODO: Remove when tippers are supported with 2 unload points
elseif (vehicle.cp.isCombine or vehicle.cp.isHarvesterSteerable or vehicle.cp.hasHarvesterAttachable) and not vehicle.cp.hasSpecialChopper then
maxUnload = 2;
else
maxUnload = 1;
end;
if vehicle.cp.numUnloadPoints > maxUnload then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_UNLOADING_POINTS_TOO_MANY;%d',maxUnload));
return false;
end;
end;
elseif mode == 9 then
minWait, maxWait = 3, 3;
if vehicle.cp.numWaitPoints < minWait then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_WAITING_POINTS_TOO_FEW;%d',minWait));
return false;
elseif vehicle.cp.numWaitPoints > maxWait then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_WAITING_POINTS_TOO_MANY;%d',maxWait));
return false;
elseif vehicle.cp.shovelStatePositions == nil or vehicle.cp.shovelStatePositions[2] == nil or vehicle.cp.shovelStatePositions[3] == nil or vehicle.cp.shovelStatePositions[4] == nil or vehicle.cp.shovelStatePositions[5] == nil then
courseplay:setInfoText(vehicle, 'COURSEPLAY_SHOVEL_POSITIONS_MISSING');
return false;
elseif vehicle.cp.shovelFillStartPoint == nil or vehicle.cp.shovelFillEndPoint == nil or vehicle.cp.shovelEmptyPoint == nil then
courseplay:setInfoText(vehicle, 'COURSEPLAY_NO_VALID_COURSE');
return false;
end;
end;
return true;
end;
-- stops driving the course
function courseplay:stop(self)
if g_server == nil then
return
end
-- Stop AI Driver
if self.cp.driver then
self.cp.driver:dismiss()
end
local ret2_removeLegacyCollisionTriggers = false -- TODO could be used for further processing / error handling / information to the user
ret_removeLegacyCollisionTriggers = courseplay:removeLegacyCollisionTriggers(self)
-- TODO: move this to TrafficCollision.lua
if self:getAINeedsTrafficCollisionBox() then
setTranslation(self.spec_aiVehicle.aiTrafficCollision, 0, -1000, 0)
self.spec_aiVehicle.aiTrafficCollisionRemoveDelay = 200
end
if g_currentMission.missionInfo.automaticMotorStartEnabled and self.cp.saveFuel and not self.spec_motorized.isMotorStarted then
courseplay:setEngineState(self, true);
self.cp.saveFuel = false;
end
if courseplay:getCustomTimerExists(self,'fuelSaveTimer') then
--print("reset existing timer")
courseplay:resetCustomTimer(self,'fuelSaveTimer',true)
end
--stop special tools
for _, tool in pairs (self.cp.workTools) do
-- vehicle, workTool, unfold, lower, turnOn, allowedToDrive, cover, unload, ridgeMarker,forceSpeedLimit)
courseplay:handleSpecialTools(self, tool, false, false, false, false, false, nil,nil,0);
if tool.cp.originalCapacities then
for index,fillUnit in pairs(tool:getFillUnits()) do
fillUnit.capacity = tool.cp.originalCapacities[index]
end
tool.cp.originalCapacities = nil
end
if tool.fertilizerEnabled ~= nil then
tool.fertilizerEnabled = nil
end
end
if self.cp.directionNodeToTurnNodeLength ~= nil then
self.cp.directionNodeToTurnNodeLength = nil
end
self.cp.lastInfoText = nil
--mode10 restore original compactingScales
if self.cp.mode10.OrigCompactScale ~= nil then
self.bunkerSiloCompactingScale = self.cp.mode10.OrigCompactScale
self.cp.mode10.OrigCompactScale = nil
end
-- Enable crop destruction if 4Real Module 01 - Crop Destruction mod is installed
if self.cropDestruction then
courseplay:enableCropDestruction(self);
end;
-- MR and Real Fill Type Mass mod combatiablity
if self.cp.useProgessiveBraking then
self.cp.mrAccelrator = nil
end
if self.cp.hasDriveControl then
local changed = false;
if self.cp.driveControl.hasFourWD and self.driveControl.fourWDandDifferentials.fourWheel ~= self.cp.driveControl.fourWDBackup then
self.driveControl.fourWDandDifferentials.fourWheel = self.cp.driveControl.fourWDBackup;
self.driveControl.fourWDandDifferentials.diffLockFront = false;
self.driveControl.fourWDandDifferentials.diffLockBack = false;
changed = true;
end;
if changed and driveControlInputEvent ~= nil then
driveControlInputEvent.sendEvent(self);
end;
end;
if self.cp.cruiseControlSpeedBackup then
self.spec_drivable.cruiseControl.speed = self.cp.cruiseControlSpeedBackup; -- NOTE JT: no need to use setter or event function - Drivable's update() checks for changes in the var and calls the event itself
self.cp.cruiseControlSpeedBackup = nil;
end;
self.spec_lights.aiLightsTypesMask = self.cp.aiLightsTypesMaskBackup
if self.cp.takeOverSteering then
self.cp.takeOverSteering = false
end
courseplay:removeFromVehicleLocalIgnoreList(vehicle, self.cp.activeCombine)
courseplay:removeFromVehicleLocalIgnoreList(vehicle, self.cp.lastActiveCombine)
self.cp.BunkerSiloMap = nil
self.cp.mode9TargetSilo = nil
self.cp.mode10.lowestAlpha = 99
self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF)
self.spec_drivable.cruiseControl.minSpeed = 1
self.cp.forcedToStop = false
self.cp.waitingForTrailerToUnload = false
courseplay:setIsRecording(self, false);
courseplay:setRecordingIsPaused(self, false);
self.cp.isTurning = nil;
courseplay:clearTurnTargets(self);
self.cp.aiTurnNoBackward = false
self.cp.noStopOnEdge = false
self.cp.fillTrigger = nil;
self.cp.factoryScriptTrigger = nil;
self.cp.tipperLoadMode = 0;
self.cp.hasMachineToFill = false;
self.cp.unloadOrder = false
self.cp.isUnloadingStopped = false
self.cp.foundColli = {}
self.cp.TrafficBrake = false
self.cp.inTraffic = false
self.cp.collidingVehicleId = nil
self.cp.collidingObjects = {
all = {};
};
self.cp.bypassWaypointsSet = false
-- deactivate beacon and hazard lights
if self.beaconLightsActive then
self:setBeaconLightsVisibility(false);
end;
if self.spec_lights.turnLightState and self.spec_lights.turnLightState ~= Lights.TURNLIGHT_OFF then
self:setTurnLightState(Lights.TURNLIGHT_OFF);
end;
-- resetting variables
--self.cp.ColliHeightSet = nil
self.cp.tempCollis = {}
self.checkSpeedLimit = self.cp.savedCheckSpeedLimit;
courseplay:resetTipTrigger(self);
self:setIsCourseplayDriving(false);
self:setCpVar('canDrive',true,courseplay.isClient)
self:setCpVar('distanceCheck',false,courseplay.isClient);
if self.cp.checkReverseValdityPrinted then
self.cp.checkReverseValdityPrinted = false
end
self.cp.lastMode8UnloadTriggerId = nil
self.cp.curSpeed = 0;
self.spec_motorized.motor.maxRpmOverride = nil;
self.cp.heapStart = nil
self.cp.heapStop = nil
self.cp.startWork = nil
self.cp.stopWork = nil
self.cp.hasFinishedWork = nil
self.cp.turnTimeRecorded = nil;
self.cp.hasUnloadingRefillingCourse = false;
self.cp.hasTransferCourse = false
courseplay:setStopAtEnd(self, false);
self.cp.stopAtEndMode1 = false;
self.cp.isTipping = false;
self.cp.isUnloaded = false;
self.cp.prevFillLevelPct = nil;
self.cp.isInRepairTrigger = nil;
self.cp.curMapWeightStation = nil;
courseplay:setSlippingStage(self, 0);
courseplay:resetCustomTimer(self, 'slippingStage1');
courseplay:resetCustomTimer(self, 'slippingStage2');
courseplay:resetCustomTimer(self, 'foldBaleLoader', true);
self.cp.hasBaleLoader = false;
self.cp.hasPlow = false;
self.cp.rotateablePlow = nil;
self.cp.hasSowingMachine = false;
self.cp.hasSprayer = false;
if self.cp.manualWorkWidth ~= nil then
courseplay:changeWorkWidth(self, nil, self.cp.manualWorkWidth, true)
if self.cp.hud.currentPage == courseplay.hud.PAGE_COURSE_GENERATION then
courseplay.hud:setReloadPageOrder(self, self.cp.hud.currentPage, true);
end
end
self.cp.totalLength, self.cp.totalLengthOffset = 0, 0;
self.cp.numWorkTools = 0;
self.cp.movingToolsPrimary, self.cp.movingToolsSecondary = nil, nil;
self.cp.attachedFrontLoader = nil
courseplay:deleteFixedWorldPosition(self);
--remove any local and global info texts
if g_server ~= nil then
courseplay:setInfoText(self, nil);
for refIdx,_ in pairs(CpManager.globalInfoText.msgReference) do
if self.cp.activeGlobalInfoTexts[refIdx] ~= nil then
CpManager:setGlobalInfoText(self, refIdx, true);
end;
end;
end
--validation: can switch mode?
courseplay:validateCanSwitchMode(self);
StartStopEvent:sendStopEvent(self)
-- reactivate load/add/delete course buttons
--courseplay.buttons:setActiveEnabled(self, 'page2');
end
function courseplay:findVehicleHeights(transformId, x, y, z, distance)
local startHeight = math.max(self.sizeLength,5)
local height = startHeight - distance
local vehicle = false
--print(string.format("found %s (%s)",tostring(getName(transformId)),tostring(transformId)))
-- if self.cp.aiTrafficCollisionTrigger == transformId then
if self.aiTrafficCollisionTrigger == transformId then
if self.cp.HeightsFoundColli < height then
self.cp.HeightsFoundColli = height
end
elseif transformId == self.rootNode then
vehicle = true
elseif getParent(transformId) == self.rootNode and self.aiTrafficCollisionTrigger ~= transformId then
vehicle = true
elseif self.cpTrafficCollisionIgnoreList[transformId] or self.cpTrafficCollisionIgnoreList[getParent(transformId)] then
vehicle = true
end
if vehicle and self.cp.HeightsFound < height then
self.cp.HeightsFound = height
end
return true
end
function courseplay:checkSaveFuel(vehicle,allowedToDrive)
if (not vehicle.cp.saveFuelOptionActive)
or (vehicle.cp.mode == courseplay.MODE_COMBI and vehicle.cp.activeCombine ~= nil)
or (vehicle.cp.mode == courseplay.MODE_FIELDWORK and ((vehicle.courseplayers ~= nil and #vehicle.courseplayers > 0) or vehicle.cp.convoyActive))
or ((vehicle.cp.mode == courseplay.MODE_FIELD_SUPPLY or vehicle.cp.mode == courseplay.MODE_OVERLOADER) and vehicle.Waypoints[vehicle.cp.previousWaypointIndex].wait)
then
if vehicle.cp.saveFuel then
vehicle.cp.saveFuel = false
end
courseplay:resetCustomTimer(vehicle,'fuelSaveTimer',true)
return
end
if allowedToDrive then
if courseplay:getCustomTimerExists(vehicle,'fuelSaveTimer') then
--print("reset existing timer")
courseplay:resetCustomTimer(vehicle,'fuelSaveTimer',true)
end
if vehicle.cp.saveFuel then
--print("reset saveFuel")
vehicle.cp.saveFuel = false
end
else
-- set fuel save timer
if not vehicle.cp.saveFuel then
if courseplay:timerIsThrough(vehicle,'fuelSaveTimer',false) then
--print(" timer is throught and not nil")
--print("set saveFuel")
vehicle.cp.saveFuel = true
elseif courseplay:timerIsThrough(vehicle,'fuelSaveTimer') then
--print(" set timer ")
courseplay:setCustomTimer(vehicle,'fuelSaveTimer',30)
end
end
end
end
function courseplay:safeSetWaypointIndex( vehicle, newIx )
for i = newIx, newIx do
-- don't set it too close to a turn start,
if vehicle.Waypoints[ i ] ~= nil and vehicle.Waypoints[ i ].turnStart then
-- set it to after the turn
newIx = i + 2
break
end
end
if vehicle.cp.waypointIndex > vehicle.cp.numWaypoints then
courseplay:setWaypointIndex(vehicle, 1);
else
courseplay:setWaypointIndex( vehicle, newIx );
end
end
-- do not remove this comment
-- vim: set noexpandtab: