forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_stop.lua
864 lines (764 loc) · 30.6 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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
local curFile = 'start_stop.lua';
-- starts driving the course
function courseplay:start(self)
self.currentHelper = HelperUtil.getRandomHelper()
self.isHired = true;
self.isHirableBlocked = true;
self.cp.savedLightsMask = self.aiLightsTypesMask;
self.aiLightsTypesMask = nil;
self.cp.forceIsActiveBackup = self.forceIsActive;
self.forceIsActive = true;
self.cp.stopMotorOnLeaveBackup = self.stopMotorOnLeave;
self.stopMotorOnLeave = false;
self.steeringEnabled = false;
self.disableCharacterOnLeave = false;
if self.vehicleCharacter ~= nil then
self.vehicleCharacter:delete();
self.vehicleCharacter:loadCharacter(self.currentHelper.xmlFilename, getUserRandomizedMpColor(self.currentHelper.name))
if self.isEntered then
self.vehicleCharacter:setCharacterVisibility(false)
end
end
-- Start the reset character timer.
courseplay:setCustomTimer(self, "resetCharacter", 300);
if courseplay.isClient then
return
end
self.cp.numWaypoints= #self.Waypoints
if self.cp.numWaypoints < 1 then
return
end
courseplay:setEngineState(self, true);
self.cp.saveFuel = false
--print(tableShow(self.attachedImplements[1],"self.attachedImplements",nil,nil,4))
--local id = self.attachedImplements[1].object.unloadTrigger.triggerId
--courseplay:findInTables(g_currentMission ,"g_currentMission", id)
if self.cp.orgRpm == nil then
self.cp.orgRpm = {}
self.cp.orgRpm[1] = self.motor.maxRpm
self.cp.orgRpm[2] = self.motor.maxRpm
self.cp.orgRpm[3] = self.motor.maxRpm
end
self.CPnumCollidingVehicles = 0;
self.cp.collidingVehicleId = nil
courseplay:debug(string.format("%s: Start/Stop: deleting \"self.cp.collidingVehicleId\"", nameNum(self)), 3);
--self.numToolsCollidingVehicles = {};
self:setIsCourseplayDriving(false);
courseplay:setIsRecording(self, false);
courseplay:setRecordingIsPaused(self, false);
self.cp.calculatedCourseToCombine = false
self.cp.backMarkerOffset = nil
self.cp.aiFrontMarker = nil
courseplay:resetTools(self)
if self.attachedCutters ~= nil then
for cutter, implement in pairs(self.attachedCutters) do
--remove cutter atTrafficCollisionTrigger in case of having changed or removed it while not in CP
if self.cp.trafficCollisionTriggers[0] ~= nil then
removeTrigger(self.cp.trafficCollisionTriggers[0])
self.cp.trafficCollisionTriggerToTriggerIndex[self.cp.trafficCollisionTriggers[0]] = nil
end
--set cutter aiTrafficCollisionTrigger to cp.aiTrafficCollisionTrigger's list
if cutter.aiTrafficCollisionTrigger ~= nil then
if cutter.cpTrafficCollisionTrigger == nil then
cutter.cpTrafficCollisionTrigger = clone(cutter.aiTrafficCollisionTrigger, true);
self.cp.trafficCollisionTriggers[0] = cutter.cpTrafficCollisionTrigger
else
self.cp.trafficCollisionTriggers[0] = cutter.cpTrafficCollisionTrigger
end
addTrigger(self.cp.trafficCollisionTriggers[0], 'cpOnTrafficCollisionTrigger', self);
self.cp.trafficCollisionTriggerToTriggerIndex[self.cp.trafficCollisionTriggers[0]] = 0
self.cp.collidingObjects[0] = {};
courseplay:debug(string.format("%s: Start/Stop: cutter.aiTrafficCollisionTrigger present -> adding %s to self.cp.trafficCollisionTriggers[0]",nameNum(self),tostring(self.cp.trafficCollisionTriggers[0])),3)
--self.cp.numCollidingObjects[0] = 0;
else
courseplay:debug(string.format('## Courseplay: %s: aiTrafficCollisionTrigger in cutter missing. Traffic collision prevention will not work!', nameNum(self)),3);
end
end
end
-- adapt collis height to vehicles height , its a runonce
if self.cp.ColliHeightSet == nil and self.cp.numTrafficCollisionTriggers > 0 then
local height = 0;
local step = (self.sizeLength/2)+1 ;
local stepBehind, stepFront = step, step;
if self.attachedImplements ~= nil then
for index, implement in pairs(self.attachedImplements) do
local tool = implement.object
local x,y,z = getWorldTranslation(tool.rootNode);
local _,_,nz = worldToLocal(self.cp.DirectionNode, x, y, z);
if nz > 0 then
stepFront = stepFront + (tool.sizeLength)+2
else
stepBehind = stepBehind + (tool.sizeLength)+2
end
end
end
local distance = self.sizeLength;
local nx, ny, nz = localDirectionToWorld(self.rootNode, 0, -1, 0);
self.cp.HeightsFound = 0;
self.cp.HeightsFoundColli = 0;
for i=-stepBehind,stepFront,0.5 do
local x,y,z = localToWorld(self.rootNode, 0, distance, i);
raycastAll(x, y, z, nx, ny, nz, "findVehicleHeights", distance, self);
--print("drive raycast "..tostring(i).." end");
--drawDebugLine(x, y, z, 1, 0, 0, x+(nx*distance), y+(ny*distance), z+(nz*distance), 1, 0, 0);
end
local difference = self.cp.HeightsFound - self.cp.HeightsFoundColli;
local trigger = self.cp.trafficCollisionTriggers[1];
local Tx,Ty,Tz = getTranslation(trigger,self.rootNode);
setTranslation(trigger, Tx,Ty+difference,Tz);
self.cp.ColliHeightSet = true;
end
--calculate workwidth for combines in mode7
if self.cp.mode == 7 then
courseplay:calculateWorkWidth(self)
end
-- set default modeState if not in mode 2 or 3
if self.cp.mode ~= 2 and self.cp.mode ~= 3 then
courseplay:setModeState(self, 0);
end;
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;
--add to activeCoursePlayers
CpManager:addToActiveCoursePlayers(self);
self.cp.turnTimer = 8000
-- show arrow
self:setCpVar('distanceCheck',true,courseplay.isClient);
-- current position
local ctx, cty, ctz = getWorldTranslation(self.cp.DirectionNode);
-- position of next waypoint
local cx, cz = self.Waypoints[self.cp.waypointIndex].cx, self.Waypoints[self.cp.waypointIndex].cz
-- distance
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.aiLower ~= nil then
workTool:aiLower(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
end;
self.cp.isReversePossible = isReversePossible
self.cp.mode10.levelerIsFrontAttached = isFrontAttached
local mapIconPath = Utils.getFilename('img/mapWaypoint.png', courseplay.path);
local mapIconHeight = 2 / 1080;
local mapIconWidth = mapIconHeight / g_screenAspectRatio;
local numWaitPoints = 0
local numUnloadPoints = 0
local numCrossingPoints = 0
self.cp.waitPoints = {};
self.cp.unloadPoints = {};
self.cp.shovelFillStartPoint = nil
self.cp.shovelFillEndPoint = nil
self.cp.shovelEmptyPoint = nil
self.cp.mode9SavedLastFillLevel = 0;
self.cp.workDistance = 0
self.cp.mediumWpDistance = 0
self.cp.mode10.alphaList = {}
local nearestpoint = dist
local recordNumber = 0
local curLaneNumber = 1;
local hasReversing = false;
local lookForNearestWaypoint = self.cp.startAtPoint == courseplay.START_AT_NEAREST_POINT and (self.cp.modeState == 0 or self.cp.modeState == 99); --or self.cp.modeState == 1
for i,wp in pairs(self.Waypoints) do
local cx, cz = wp.cx, wp.cz;
if lookForNearestWaypoint then
dist = courseplay:distance(ctx, ctz, cx, cz)
if dist <= nearestpoint then
nearestpoint = dist
recordNumber = i
end;
end;
if wp.wait then
numWaitPoints = numWaitPoints + 1;
self.cp.waitPoints[numWaitPoints] = i;
end;
if wp.unload then
numUnloadPoints = numUnloadPoints + 1;
self.cp.unloadPoints[numUnloadPoints] = i;
end;
if wp.crossing then
numCrossingPoints = numCrossingPoints + 1;
self.cp.crossingPoints[numCrossingPoints] = i;
end;
-- has reversing part
if self.cp.mode ~= 9 and wp.rev then
hasReversing = true;
end;
-- specific Workzone
if self.cp.mode == 4 or self.cp.mode == 6 then
if numWaitPoints == 1 and (self.cp.startWork == nil or self.cp.startWork == 0) then
self.cp.startWork = i
end
if numWaitPoints > 1 and (self.cp.stopWork == nil or self.cp.stopWork == 0) then
self.cp.stopWork = i
end
if self.cp.startWork and not self.cp.stopWork then
if i > 1 then
local dist = courseplay:distance(cx, cz, self.Waypoints[i-1].cx, self.Waypoints[i-1].cz)
self.cp.workDistance = self.cp.workDistance + dist
self.cp.mediumWpDistance = self.cp.workDistance/i
end
end
if numUnloadPoints == 1 and (self.cp.heapStart == nil or self.cp.heapStart == 0) then
self.cp.heapStart = i
self.cp.makeHeaps = false
end
if numUnloadPoints > 1 and (self.cp.heapStop == nil or self.cp.heapStop == 0) then
self.cp.heapStop = i
self.cp.makeHeaps = true
end
elseif self.cp.mode == 7 then--combineUnloadMode
if numUnloadPoints == 1 and (self.cp.heapStart == nil or self.cp.heapStart == 0) then
self.cp.heapStart = i
self.cp.makeHeaps = false
end
if numUnloadPoints > 1 and (self.cp.heapStop == nil or self.cp.heapStop == 0) then
self.cp.heapStop = i
self.cp.makeHeaps = true
end
--unloading point for transporter
elseif self.cp.mode == 8 then
--
--work points for shovel
elseif self.cp.mode == 9 then
if numWaitPoints == 1 and self.cp.shovelFillStartPoint == nil then
self.cp.shovelFillStartPoint = i;
end;
if numWaitPoints == 2 and self.cp.shovelFillEndPoint == nil then
self.cp.shovelFillEndPoint = i;
end;
if numWaitPoints == 3 and self.cp.shovelEmptyPoint == nil then
self.cp.shovelEmptyPoint = i;
end;
end;
-- laneNumber (for seeders)
if setLaneNumber and wp.generated ~= nil and wp.generated == true then
if wp.turnEnd ~= nil and wp.turnEnd == true then
curLaneNumber = curLaneNumber + 1;
courseplay:debug(string.format('%s: waypoint %d: turnEnd=true -> new curLaneNumber=%d', nameNum(self), i, curLaneNumber), 12);
end;
wp.laneNum = curLaneNumber;
end;
end; -- END for wp in self.Waypoints
-- 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 lookForNearestWaypoint then
local changed = false
for i=recordNumber,recordNumber+3 do
if self.Waypoints[i]~= nil and self.Waypoints[i].turnStart then
courseplay:setWaypointIndex(self, i + 2);
changed = true
break
end
end
if changed == false then
courseplay:setWaypointIndex(self, recordNumber);
end
if self.cp.waypointIndex > self.cp.numWaypoints then
courseplay:setWaypointIndex(self, 1);
end
end --END if modeState == 0
if self.cp.waypointIndex > 2 and self.cp.mode ~= 4 and self.cp.mode ~= 6 and self.cp.mode ~= 8 then
courseplay:setIsLoaded(self, true);
elseif self.cp.mode == 4 or self.cp.mode == 6 then
courseplay:setIsLoaded(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.startAtPoint == courseplay.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:setIsLoaded(self, false);
end
if self.cp.mode == 9 then
courseplay:setWaypointIndex(self, 1);
self.cp.shovelState = 1;
for i,_ in pairs(self.attachedImplements) do
local object = self.attachedImplements[i].object
if object.ignoreVehicleDirectionOnLoad ~= nil then
object.ignoreVehicleDirectionOnLoad = true
end
if object.attachedImplements ~= nil then
for k,_ in pairs(object.attachedImplements) do
if object.attachedImplements[k].object.ignoreVehicleDirectionOnLoad ~= nil then
object.attachedImplements[k].object.ignoreVehicleDirectionOnLoad = true
end
end
end
end
elseif self.cp.startAtPoint == courseplay.START_AT_FIRST_POINT then
if self.cp.mode == 2 or self.cp.mode == 3 then
courseplay:setWaypointIndex(self, 3);
courseplay:setIsLoaded(self, true);
else
courseplay:setWaypointIndex(self, 1);
end
end;
courseplay:updateAllTriggers();
self.cp.cruiseControlSpeedBackup = self.cruiseControl.speed;
if self.cp.hasDriveControl then
local changed = false;
if self.cp.driveControl.hasFourWD then
self.cp.driveControl.fourWDBackup = self.driveControl.fourWDandDifferentials.fourWheel;
if self.cp.driveControl.alwaysUseFourWD and not self.driveControl.fourWDandDifferentials.fourWheel then
self.driveControl.fourWDandDifferentials.fourWheel = true;
changed = true;
end;
end;
if self.cp.driveControl.hasHandbrake then
if self.driveControl.handBrake.isActive == true then
self.driveControl.handBrake.isActive = false;
changed = true;
end;
end;
if self.cp.driveControl.hasShuttleMode and self.driveControl.shuttle.isActive then
if self.driveControl.shuttle.direction < 1.0 then
self.driveControl.shuttle.direction = 1.0;
changed = true;
end;
end;
if changed and driveControlInputEvent ~= nil then
driveControlInputEvent.sendEvent(self);
end;
end;
--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);
-- deactivate load/add/delete course buttons
courseplay.buttons:setActiveEnabled(self, 'page2');
-- add ingameMap icon
if CpManager.ingameMapIconActive then
courseplay:createMapHotspot(self);
end;
-- Disable crop destruction if 4Real Module 01 - Crop Destruction mod is installed
if self.cropDestruction then
courseplay:disableCropDestruction(self);
end;
--More Realistlitic Mod. Temp fix until we can fix the breaking problem.
if self.mrUseMrTransmission ~= nil then
self.mrUseMrTransmission = false
end
--print("startStop "..debug.getinfo(1).currentline)
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');
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 == 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
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;
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
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
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;
end;
if vehicle.cp.isCombine or vehicle.cp.isHarvesterSteerable then
maxUnload = 2;
if vehicle.cp.numUnloadPoints > maxUnload then
courseplay:setInfoText(vehicle, string.format('COURSEPLAY_UNLOADING_POINTS_TOO_MANY;%d',maxUnload));
return false;
end;
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)
self.isHired = false;
self.isHirableBlocked = false;
self.aiLightsTypesMask = self.cp.savedLightsMask;
self.forceIsActive = self.cp.forceIsActiveBackup;
self.stopMotorOnLeave = self.cp.stopMotorOnLeaveBackup;
self.steeringEnabled = true;
self.disableCharacterOnLeave = true;
if g_currentMission.missionInfo.automaticMotorStartEnabled and self.cp.saveFuel and not self.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
if self.cp.runReset == true then
self.cp.runCounter = 0;
self.cp.runReset = false;
courseplay:changeRunCounter(self, false)
end;
-- Reset the reset character timer.
courseplay:resetCustomTimer(self, "resetCharacter", true);
if self.vehicleCharacter ~= nil then
self.vehicleCharacter:delete();
end
if self.isEntered or self.isControlled then
if self.vehicleCharacter ~= nil then
----------------------------------
--- Fix Missing playerIndex and playerColorIndex that some times happens for unknow reasons
local playerIndex = Utils.getNoNil(self.playerIndex, g_currentMission.missionInfo.playerIndex);
local playerColorIndex = Utils.getNoNil(self.playerColorIndex, g_currentMission.missionInfo.playerColorIndex);
--- End Fix
----------------------------------
self.vehicleCharacter:loadCharacter(PlayerUtil.playerIndexToDesc[playerIndex].xmlFilename, playerColorIndex)
self.vehicleCharacter:setCharacterVisibility(not self.isEntered)
end
end;
self.currentHelper = nil
--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.fillUnits) do
fillUnit.capacity = tool.cp.originalCapacities[index]
end
tool.cp.originalCapacities = nil
end
end
self.cp.lastInfoText = nil
if courseplay.isClient then
return
end
-- Enable crop destruction if 4Real Module 01 - Crop Destruction mod is installed
if self.cropDestruction then
courseplay:enableCropDestruction(self);
end;
--More Realistlitic Mod. Temp fix until we can fix the breaking problem.
if self.mrUseMrTransmission ~= nil then
self.mrUseMrTransmission = true;
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.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;
if self.cp.takeOverSteering then
self.cp.takeOverSteering = false
end
courseplay:releaseCombineStop(self)
self.cp.BunkerSiloMap = nil
self.cp.mode9TargetSilo = nil
self.cp.mode10.lowestAlpha = 99
self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF)
self.cruiseControl.minSpeed = 1
self.cp.forcedToStop = false
self.cp.waitingForTrailerToUnload = false
courseplay:setIsRecording(self, false);
courseplay:setRecordingIsPaused(self, false);
if self.cp.modeState > 4 then
courseplay:setModeState(self, 1);
end
self.cp.isTurning = nil;
courseplay:clearTurnTargets(self);
self.cp.backMarkerOffset = nil
self.cp.aiFrontMarker = nil
self.cp.aiTurnNoBackward = false
self.cp.noStopOnEdge = false
self.cp.fillTrigger = nil;
self.cp.tipperLoadMode = 0;
self.cp.hasMachineToFill = false;
self.cp.unloadOrder = false
self.cp.isUnloadingStopped = false
self.cpTrafficCollisionIgnoreList = {}
self.cp.foundColli = {}
self.cp.inTraffic = false
self.cp.bypassWaypointsSet = false
-- deactivate beacon and hazard lights
if self.beaconLightsActive then
self:setBeaconLightsVisibility(false);
end;
if self.turnLightState and self.turnLightState ~= Lights.TURNLIGHT_OFF then
self:setTurnLightState(Lights.TURNLIGHT_OFF);
end;
--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,60,false,false,true);
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);
self.cp.mode7GoBackBeforeUnloading = false
if self.cp.checkReverseValdityPrinted then
self.cp.checkReverseValdityPrinted = false
end
self.cp.lastMode8UnloadTriggerId = nil
self.cp.curSpeed = 0;
self.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.hasPlough = false;
self.cp.hasRotateablePlough = false;
self.cp.hasSowingMachine = false;
self.cp.hasSprayer = false;
if self.cp.tempToolOffsetX ~= nil then
courseplay:changeToolOffsetX(self, nil, self.cp.tempToolOffsetX, true);
self.cp.tempToolOffsetX = nil
end;
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
-- remove ingame map hotspot
if CpManager.ingameMapIconActive then
courseplay:deleteMapHotspot(self);
end;
--remove from activeCoursePlayers
CpManager:removeFromActiveCoursePlayers(self);
--validation: can switch mode?
courseplay:validateCanSwitchMode(self);
-- reactivate load/add/delete course buttons
courseplay.buttons:setActiveEnabled(self, 'page2');
end
function courseplay:findVehicleHeights(transformId, x, y, z, distance)
local height = self.sizeLength - distance
local vehicle = false
--print(string.format("found %s (%s)",tostring(getName(transformId)),tostring(transformId)))
if self.cp.trafficCollisionTriggerToTriggerIndex[transformId] ~= nil 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.mode == courseplay.MODE_LIQUIDMANURE_TRANSPORT 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