forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrive.lua
More file actions
1363 lines (1243 loc) · 50.6 KB
/
drive.lua
File metadata and controls
1363 lines (1243 loc) · 50.6 KB
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
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- drives recored course
function courseplay:drive(self, dt)
if not courseplay:getCanUseAiMode(self) then
return;
end;
local refSpeed = 0
local cx,cy,cz = 0,0,0
-- may i drive or should i hold position for some reason?
local allowedToDrive = true
-- combine self unloading
if self.cp.mode == 7 then
if self.isAIThreshing then
if (self.grainTankFillLevel * 100 / self.grainTankCapacity) >= self.cp.driveOnAtFillLevel then
self.maxnumber = table.getn(self.Waypoints)
cx7, cz7 = self.Waypoints[self.maxnumber].cx, self.Waypoints[self.maxnumber].cz
local lx7, lz7 = AIVehicleUtil.getDriveDirection(self.rootNode, cx7, cty7, cz7);
local fx,fy,fz = localToWorld(self.rootNode, 0, 0, -3*self.cp.turnRadius)
local x7,y7,z7 = localToWorld(self.rootNode, 0, 0, -15)
self.cp.mode7tx7 = x7
self.cp.mode7ty7 = y7
self.cp.mode7tz7 = z7
if courseplay:is_field(fx, fz) or self.grainTankFillLevel >= self.grainTankCapacity*0.99 then
self.lastaiThreshingDirectionX = self.aiThreshingDirectionX
self.lastaiThreshingDirectionZ = self.aiThreshingDirectionZ
self:stopAIThreshing()
self.cp.shortestDistToWp = nil
self.cp.nextTargets = {}
if lx7 < 0 then
courseplay:debug(nameNum(self) .. ": approach from right", 11);
self.cp.curTarget.x, self.cp.curTarget.y, self.cp.curTarget.z = localToWorld(self.rootNode, -(0.34*3*self.cp.turnRadius) , 0, -3*self.cp.turnRadius);
courseplay:addNewTarget(self, (0.34*2*self.cp.turnRadius) , 0);
courseplay:addNewTarget(self, 0 , 3);
else
courseplay:debug(nameNum(self) .. ": approach from left", 11);
self.cp.curTarget.x, self.cp.curTarget.y, self.cp.curTarget.z = localToWorld(self.rootNode, (0.34*3*self.cp.turnRadius) , 0, -3*self.cp.turnRadius);
courseplay:addNewTarget(self, -(0.34*2*self.cp.turnRadius) , 0);
courseplay:addNewTarget(self, 0 ,3);
end
self.cp.mode7Unloading = true
self.cp.mode7GoBackBeforeUnloading = true
courseplay:start(self)
self.cp.speeds.sl = 3
refSpeed = self.cp.speeds.field
else
return
end
else
return
end
elseif self.cp.mode7Unloading then
self.cp.speeds.sl = 3
refSpeed = self.cp.speeds.field
if self.cp.mode7GoBackBeforeUnloading then
local dist = courseplay:distance_to_point(self, self.cp.mode7tx7,self.cp.mode7ty7,self.cp.mode7tz7)
if dist < 1 then
self.cp.mode7GoBackBeforeUnloading = false
self.recordnumber = 2
end
end
else
allowedToDrive = false
courseplay:setGlobalInfoText(self, 'WORK_END');
end
if self.cp.modeState == 5 then
local targets = #(self.cp.nextTargets)
local aligned = false
local ctx7, cty7, ctz7 = getWorldTranslation(self.rootNode);
self.cp.infoText = string.format(courseplay:loc("CPDriveToWP"), self.cp.curTarget.x, self.cp.curTarget.z)
cx = self.cp.curTarget.x
cy = self.cp.curTarget.y
cz = self.cp.curTarget.z
if courseplay.debugChannels[11] then
drawDebugLine(cx, cty7+3, cz, 1, 0, 0, ctx7, cty7+3, ctz7, 1, 0, 0);
end;
self.cp.speeds.sl = 3
refSpeed = self.cp.speeds.field
distance_to_wp = courseplay:distance_to_point(self, cx, y, cz)
local distToChange = 4
if self.cp.shortestDistToWp == nil or self.cp.shortestDistToWp > distance_to_wp then
self.cp.shortestDistToWp = distance_to_wp
end
if distance_to_wp > self.cp.shortestDistToWp and distance_to_wp < 6 then
distToChange = distance_to_wp + 1
end
if targets == 2 then
self.cp.curTargetMode7 = self.cp.nextTargets[2];
elseif targets == 1 then
if math.abs(self.lastaiThreshingDirectionZ) > 0.1 then
if math.abs(self.cp.curTargetMode7.x-ctx7)< 3 then
aligned = true
courseplay:debug(nameNum(self) .. ": aligned", 11);
end
else
if math.abs(self.cp.curTargetMode7.z-ctz7)< 3 then
aligned = true
courseplay:debug(nameNum(self) .. ": aligned", 11);
end
end
elseif targets == 0 then
if distance_to_wp < 25 then
self.cp.speeds.sl = 3
refSpeed = self.cp.speeds.turn
end
if distance_to_wp < 15 then
self:setIsThreshing(true)
end
if math.abs(self.lastaiThreshingDirectionX) > 0.1 then
if math.abs(self.cp.curTargetMode7.x-ctx7)< 5 then
aligned = true
courseplay:debug(nameNum(self) .. ": aligned", 11);
end
else
if math.abs(self.cp.curTargetMode7.z-ctz7)< 5 then
aligned = true
courseplay:debug(nameNum(self) .. ": aligned", 11);
end
end
end
if distance_to_wp < distToChange or aligned then
self.cp.shortestDistToWp = nil
if targets > 0 then
courseplay:setCurrentTargetFromList(self, 1);
self.recordnumber = 2
else
self.cp.modeState = 0
if self.lastaiThreshingDirectionX ~= nil then
self.aiThreshingDirectionX = self.lastaiThreshingDirectionX
self.aiThreshingDirectionZ = self.lastaiThreshingDirectionZ
courseplay:debug(nameNum(self) .. ": restored self.aiThreshingDirection", 11);
end
self:startAIThreshing(true)
self.cp.mode7Unloading = false
courseplay:debug(nameNum(self) .. ": start AITreshing", 11);
courseplay:debug(nameNum(self) .. ": fault: "..tostring(math.ceil(math.abs(ctx7-self.cp.curTargetMode7.x)*100)).." cm X "..tostring(math.ceil(math.abs(ctz7-self.cp.curTargetMode7.z)*100)).." cm Z", 11);
end
end
end
end
-- unregister at combine, if there is one
if self.cp.isLoaded == true and self.cp.positionWithCombine ~= nil then
courseplay:unregister_at_combine(self, self.cp.activeCombine)
end
-- switch lights on!
if not self.isControlled then
-- we want to hear our courseplayers
setVisibility(self.aiMotorSound, true)
if courseplay.lightsNeeded then
self:setLightsVisibility(true);
else
self:setLightsVisibility(false);
end;
end;
-- current position
local ctx, cty, ctz = getWorldTranslation(self.rootNode);
-- coordinates of next waypoint
--if self.recordnumber > self.maxnumber then
-- this should never happen
-- self.recordnumber = self.maxnumber
-- end
if self.recordnumber > 1 then
self.cp.last_recordnumber = self.recordnumber - 1
else
self.cp.last_recordnumber = 1
end
if self.recordnumber > self.maxnumber then
courseplay:debug(string.format("drive %i: %s: self.recordnumber (%s) > self.maxnumber (%s)", debug.getinfo(1).currentline, self.name, tostring(self.recordnumber), tostring(self.maxnumber)), 12); --this should never happen
self.recordnumber = self.maxnumber
end
if self.cp.mode ~= 7 then
cx, cz = self.Waypoints[self.recordnumber].cx, self.Waypoints[self.recordnumber].cz
elseif self.cp.mode == 7 and self.cp.modeState ~=5 then
if not self.cp.mode7GoBackBeforeUnloading then
cx, cz = self.Waypoints[self.recordnumber].cx, self.Waypoints[self.recordnumber].cz
else
cx,cz = self.cp.mode7tx7, self.cp.mode7tz7
end
end
if courseplay.debugChannels[12] and self.cp.isTurning == nil then
drawDebugPoint(cx, cty+3, cz, 1, 0 , 1, 1);
end;
--HORIZONTAL/VERTICAL OFFSET
local offsetValid = self.cp.totalOffsetX ~= nil and self.cp.toolOffsetZ ~= nil and (self.cp.totalOffsetX ~= 0 or self.cp.toolOffsetZ ~= 0);
if offsetValid then
if self.cp.mode == 3 then
if self.cp.laneOffset ~= 0 then
courseplay:changeLaneOffset(self, nil, 0);
end;
offsetValid = self.recordnumber > 2 and self.recordnumber > self.cp.waitPoints[1] - 6 and self.recordnumber <= self.cp.waitPoints[1] + 3;
elseif self.cp.mode == 4 or self.cp.mode == 6 then
offsetValid = self.recordnumber > self.cp.startWork and self.recordnumber < self.cp.stopWork and self.recordnumber > 1; --TODO: recordnumber incl startWork/stopWork?
elseif self.cp.mode == 7 then
if self.cp.laneOffset ~= 0 then
courseplay:changeLaneOffset(self, nil, 0);
end;
offsetValid = self.recordnumber > 3 and self.recordnumber > self.cp.waitPoints[1] - 6 and self.recordnumber <= self.cp.waitPoints[1] + 3 and not self.cp.mode7GoBackBeforeUnloading;
elseif self.cp.mode == 8 then
if self.cp.laneOffset ~= 0 then
courseplay:changeLaneOffset(self, nil, 0);
end;
offsetValid = self.recordnumber > self.cp.waitPoints[1] - 6 and self.recordnumber <= self.cp.waitPoints[1] + 3;
else
offsetValid = false;
end;
end;
if offsetValid then
--courseplay:debug(string.format('%s: waypoint before offset: cx=%.2f, cz=%.2f', nameNum(self), cx, cz), 2);
local vcx, vcz;
if self.recordnumber == 1 then
vcx = self.Waypoints[2].cx - cx;
vcz = self.Waypoints[2].cz - cz;
else
if self.Waypoints[self.cp.last_recordnumber].rev then
vcx = self.Waypoints[self.cp.last_recordnumber].cx - cx;
vcz = self.Waypoints[self.cp.last_recordnumber].cz - cz;
else
vcx = cx - self.Waypoints[self.cp.last_recordnumber].cx;
vcz = cz - self.Waypoints[self.cp.last_recordnumber].cz;
end;
end;
local vl = Utils.vector2Length(vcx, vcz); -- length of vector
if vl ~= nil and vl > 0.01 then -- if not too short: normalize and add offsets
vcx = vcx / vl;
vcz = vcz / vl;
cx = cx - vcz * self.cp.totalOffsetX + vcx * self.cp.toolOffsetZ;
cz = cz + vcx * self.cp.totalOffsetX + vcz * self.cp.toolOffsetZ;
end;
--courseplay:debug(string.format('%s: waypoint after offset [%.1fm]: cx=%.2f, cz=%.2f', nameNum(self), self.cp.totalOffsetX, cx, cz), 2);
end;
if courseplay.debugChannels[12] and self.cp.isTurning == nil then
drawDebugPoint(cx, cty+3, cz, 0, 1 , 1, 1);
end;
self.dist = courseplay:distance(cx, cz, ctx, ctz)
--courseplay:debug(string.format("Tx: %f2 Tz: %f2 WPcx: %f2 WPcz: %f2 dist: %f2 ", ctx, ctz, cx, cz, self.dist ), 2)
local fwd = nil
local distToChange = nil
local lx, lz = AIVehicleUtil.getDriveDirection(self.cp.DirectionNode, cx, cty, cz);
-- what about our tippers?
self.cp.tipperFillLevel, self.cp.tipperCapacity = self:getAttachedTrailersFillLevelAndCapacity()
local fill_level = nil
if self.cp.tipperFillLevel ~= nil then
fill_level = self.cp.tipperFillLevel * 100 / self.cp.tipperCapacity
end
if self.cp.mode == 4 or self.cp.mode == 6 then
if self.Waypoints[self.recordnumber].turn ~= nil then
self.cp.isTurning = self.Waypoints[self.recordnumber].turn
end
if self.cp.abortWork ~= nil and fill_level == 0 then
self.cp.isTurning = nil
end
--RESET OFFSET TOGGLES
if not self.cp.isTurning then
if self.cp.symmetricLaneChange and not self.cp.switchLaneOffset then
self.cp.switchLaneOffset = true;
courseplay:debug(string.format("%s: isTurning=false, switchLaneOffset=false -> set switchLaneOffset to true", nameNum(self)), 12);
end;
if self.cp.hasPlough and not self.cp.switchToolOffset then
self.cp.switchToolOffset = true;
courseplay:debug(string.format("%s: isTurning=false, switchToolOffset=false -> set switchToolOffset to true", nameNum(self)), 12);
end;
end;
end;
if self.cp.mode == 4 or self.cp.mode == 8 then
self.implementIsFull = (fill_level ~= nil and fill_level == 100);
end;
-- in a traffic yam?
-- coordinates of coli
--local tx, ty, tz = getWorldTranslation(self.aiTrafficCollisionTrigger)
local tx, ty, tz = localToWorld(self.cp.DirectionNode,0,1,3)
-- direction of tractor
local nx, ny, nz = localDirectionToWorld(self.cp.DirectionNode, lx, 0, lz)
-- RulModiä
if self.cp.beaconLightsMode == 1 then --on streets only
local combineNeedsBeacon = self.cp.isCombine and (self.grainTankFillLevel / self.grainTankCapacity) > 0.8;
if (self.cp.speeds.sl == 3 and not self.beaconLightsActive)
or (self.cp.speeds.sl ~= 3 and self.beaconLightsActive and not combineNeedsBeacon)
or (self.cp.mode == 6 and combineNeedsBeacon and not self.beaconLightsActive)
or (self.cp.mode == 7 and self.isAIThreshing == self.beaconLightsActive) then
self:setBeaconLightsVisibility(not self.beaconLightsActive);
end;
elseif self.cp.beaconLightsMode == 2 then --always
if not self.beaconLightsActive then
self:setBeaconLightsVisibility(true);
end;
elseif self.cp.beaconLightsMode == 3 then --never
if self.beaconLightsActive then
self:setBeaconLightsVisibility(false);
end;
end;
-- the tipper that is currently loaded/unloaded
local activeTipper = nil
local isBypassing = false
--### WAITING POINTS - START
if self.Waypoints[self.cp.last_recordnumber].wait and self.wait then
if self.waitTimer == nil and self.cp.waitTime > 0 then
self.waitTimer = self.timer + self.cp.waitTime * 1000
end
if self.cp.mode == 3 and self.cp.tipperAttached then
courseplay:handleMode3(self, fill_level, allowedToDrive, dt);
elseif self.cp.mode == 4 then
local drive_on = false
if self.cp.last_recordnumber == self.cp.startWork and fill_level ~= 0 then
self.wait = false
elseif self.cp.last_recordnumber == self.cp.stopWork and self.cp.abortWork ~= nil then
self.wait = false
else
local isInWorkArea = self.recordnumber > self.cp.startWork and self.recordnumber <= self.cp.stopWork;
if self.cp.tipperAttached and self.cp.startWork ~= nil and self.cp.stopWork ~= nil and self.tippers ~= nil and not isInWorkArea then
allowedToDrive,lx,lz = courseplay:refillSprayer(self, fill_level, self.cp.refillUntilPct, allowedToDrive, lx, lz, dt);
end;
if courseplay:timerIsThrough(self, "fillLevelChange") or self.cp.prevFillLevel == nil then
if self.cp.prevFillLevel ~= nil and fill_level == self.cp.prevFillLevel and fill_level > self.cp.refillUntilPct then
drive_on = true
end
self.cp.prevFillLevel = fill_level
courseplay:setCustomTimer(self, "fillLevelChange", 7);
end
if fill_level == 100 or drive_on then
self.wait = false
end
self.cp.infoText = string.format(courseplay:loc("CPloading"), self.cp.tipperFillLevel, self.cp.tipperCapacity)
end
elseif self.cp.mode == 6 then
if self.cp.last_recordnumber == self.cp.startWork then
self.wait = false
elseif self.cp.last_recordnumber == self.cp.stopWork and self.cp.abortWork ~= nil then
self.wait = false
elseif self.cp.last_recordnumber ~= self.cp.startWork and self.cp.last_recordnumber ~= self.cp.stopWork then
courseplay:setGlobalInfoText(self, 'UNLOADING_BALE');
if fill_level == 0 or drive_on then
self.wait = false
end;
end;
elseif self.cp.mode == 7 then
if self.cp.last_recordnumber == self.cp.startWork then
if self.grainTankFillLevel > 0 then
self:setPipeState(2)
courseplay:setGlobalInfoText(self, 'OVERLOADING_POINT');
else
self.wait = false
self.cp.isUnloaded = true
end
end
elseif self.cp.mode == 8 then
courseplay:setGlobalInfoText(self, 'OVERLOADING_POINT');
if self.cp.tipperAttached then
-- drive on if fill_level doesn't change and fill level is < 100-self.cp.followAtFillLevel
courseplay:handle_mode8(self)
local drive_on = false
if courseplay:timerIsThrough(self, "fillLevelChange") or self.cp.prevFillLevel == nil then
if self.cp.prevFillLevel ~= nil and fill_level == self.cp.prevFillLevel and fill_level < self.cp.followAtFillLevel then
drive_on = true
end
self.cp.prevFillLevel = fill_level
courseplay:setCustomTimer(self, "fillLevelChange", 7);
end
if fill_level == 0 or drive_on then
self.wait = false
self.cp.prevFillLevel = nil
self.cp.isUnloaded = true
end
end
elseif self.cp.mode == 9 then
self.wait = false;
else
courseplay:setGlobalInfoText(self, 'WAIT_POINT');
end
-- wait untli a specific time
if self.waitTimer and self.timer > self.waitTimer then
self.waitTimer = nil
self.wait = false
end
allowedToDrive = false
--### WAITING POINTS - END
else -- ende wartepunkt
-- abfahrer-mode
if (self.cp.mode == 1 or (self.cp.mode == 2 and self.cp.isLoaded)) and self.cp.tipperFillLevel ~= nil and self.cp.tipRefOffset ~= nil and self.cp.tipperAttached then
if self.cp.currentTipTrigger == nil and self.cp.tipperFillLevel > 0 then
-- is there a tipTrigger within 10 meters?
courseplay:debug(nameNum(self) .. ": call 1st raycast", 1);
local num = raycastAll(tx, ty, tz, nx, ny, nz, "findTipTriggerCallback", 10, self)
if num > 0 then
courseplay:debug(string.format("%s: drive(%d): 1st raycast end", nameNum(self), debug.getinfo(1).currentline), 1);
end;
if courseplay.debugChannels[1] then
drawDebugLine(tx, ty, tz, 1, 0, 0, tx+(nx*10), ty+(ny*10), tz+(nz*10), 1, 0, 0);
end;
if self.cp.tipRefOffset ~= 0 then
if self.cp.currentTipTrigger == nil then
local x1,y1,z1 = localToWorld(self.aiTrafficCollisionTrigger,self.cp.tipRefOffset,0,0)
courseplay:debug(nameNum(self) .. ": call 2nd raycast", 1);
num = raycastAll(x1,y1,z1, nx, ny, nz, "findTipTriggerCallback", 10, self)
if num > 0 then
courseplay:debug(string.format("%s: drive(%d): 2nd raycast end", nameNum(self), debug.getinfo(1).currentline), 1);
end;
if courseplay.debugChannels[1] then
drawDebugLine(x1,y1,z1, 1, 0, 0, x1+(nx*10), y1+(ny*10), z1+(nz*10), 1, 0, 0);
end;
end
if self.cp.currentTipTrigger == nil then
local x1,y1,z1 = localToWorld(self.aiTrafficCollisionTrigger,-self.cp.tipRefOffset,0,0)
courseplay:debug(nameNum(self) .. ": call 3rd raycast", 1);
num = raycastAll(x1,y1,z1, nx, ny, nz, "findTipTriggerCallback", 10, self)
if num > 0 then
courseplay:debug(string.format("%s: drive(%d): 3rd raycast end", nameNum(self), debug.getinfo(1).currentline), 1);
end;
if courseplay.debugChannels[1] then
drawDebugLine(x1,y1,z1, 1, 0, 0, x1+(nx*10), y1+(ny*10), z1+(nz*10), 1, 0, 0);
end;
end
end
end;
-- handle mode
allowedToDrive = courseplay:handle_mode1(self);
end;
-- combi-mode
if (((self.cp.mode == 2 or self.cp.mode == 3) and self.recordnumber < 2) or self.cp.activeCombine) and self.cp.tipperAttached then
self.cp.inTraffic = false
courseplay:handle_mode2(self, dt);
return;
elseif (self.cp.mode == 2 or self.cp.mode == 3) and self.recordnumber < 3 then
isBypassing = true
lx, lz = courseplay:isTheWayToTargetFree(self,lx, lz)
elseif self.cp.mode == 6 and self.cp.hasBaleLoader and (self.recordnumber == self.cp.stopWork - 4 or (self.cp.abortWork ~= nil and self.recordnumber == self.cp.abortWork ))then
isBypassing = true
lx, lz = courseplay:isTheWayToTargetFree(self,lx, lz)
elseif self.cp.mode ~= 7 then
self.cp.modeState = 0
end;
if self.cp.mode == 3 and self.cp.tipperAttached and self.recordnumber >= 2 and self.cp.modeState == 0 then
courseplay:handleMode3(self, fill_level, allowedToDrive, dt);
end;
-- Fertilice loading --only for one Implement !
if self.cp.mode == 4 then
if self.cp.tipperAttached and self.cp.startWork ~= nil and self.cp.stopWork ~= nil then
local isInWorkArea = self.recordnumber > self.cp.startWork and self.recordnumber <= self.cp.stopWork;
if self.tippers ~= nil and not isInWorkArea then
allowedToDrive,lx,lz = courseplay:refillSprayer(self, fill_level, self.cp.refillUntilPct, allowedToDrive, lx, lz, dt);
end
end;
end
if self.cp.mode == 7 then
if self.recordnumber == self.maxnumber then
if self.cp.curTarget.x ~= nil then
self.cp.modeState = 5
self.recordnumber = 2
courseplay:debug(nameNum(self) .. ": " .. tostring(debug.getinfo(1).currentline) .. ": modeState = 5", 11);
else
allowedToDrive = false
--TODO local text no aithreshing
end
end
local pipeState = self:getCombineTrailerInRangePipeState();
if pipeState > 0 then
self:setPipeState(pipeState);
else
self:setPipeState(1);
end;
end;
--REFILL LIQUID MANURE TRANSPORT
if self.cp.mode == 8 then
raycastAll(tx, ty, tz, nx, ny, nz, "findTipTriggerCallback", 10, self)
if self.cp.tipperAttached then
if self.tippers ~= nil then
allowedToDrive,lx,lz = courseplay:refillSprayer(self, fill_level, self.cp.refillUntilPct, allowedToDrive, lx, lz, dt);
end;
end;
end;
--VEHICLE DAMAGE
if self.damageLevel then
if self.damageLevel >= 90 and not self.isInRepairTrigger then
allowedToDrive = courseplay:brakeToStop(self);
courseplay:setGlobalInfoText(self, 'DAMAGE_MUST');
elseif self.damageLevel >= 50 and not self.isInRepairTrigger then
courseplay:setGlobalInfoText(self, 'DAMAGE_SHOULD');
end;
if self.damageLevel > 70 then
raycastAll(tx, ty, tz, nx, ny, nz, "findTipTriggerCallback", 10, self);
if self.cp.fillTrigger ~= nil then
if courseplay.triggers.all[self.cp.fillTrigger].isDamageModTrigger then
--print("slow down , its a garage")
self.cp.isInFilltrigger = true
end
end
if self.isInRepairTrigger then
self.cp.isInRepairTrigger = true
end;
elseif self.damageLevel == 0 then
self.cp.isInRepairTrigger = false
end;
if self.cp.isInRepairTrigger then
allowedToDrive = false;
self.cp.fillTrigger = nil;
courseplay:setGlobalInfoText(self, 'DAMAGE_IS');
end;
end;
--FUEL LEVEL + REFILLING
if self.fuelCapacity > 0 then
local currentFuelPercentage = (self.fuelFillLevel / self.fuelCapacity + 0.0001) * 100;
if currentFuelPercentage < 5 then
allowedToDrive = false;
courseplay:setGlobalInfoText(self, 'FUEL_MUST');
elseif currentFuelPercentage < 20 and not self.isFuelFilling then
raycastAll(tx, ty, tz, nx, ny, nz, "findTipTriggerCallback", 10, self)
if self.cp.fillTrigger ~= nil then
local trigger = courseplay.triggers.all[self.cp.fillTrigger]
if trigger.isGasStationTrigger then
--print("slow down , its a gasstation")
self.cp.isInFilltrigger = true
end
end
courseplay:setGlobalInfoText(self, 'FUEL_SHOULD');
if self.fuelFillTriggers[1] then
allowedToDrive = courseplay:brakeToStop(self);
self:setIsFuelFilling(true, self.fuelFillTriggers[1].isEnabled, false);
end
elseif self.isFuelFilling and currentFuelPercentage < 99.9 then
allowedToDrive = courseplay:brakeToStop(self);
courseplay:setGlobalInfoText(self, 'FUEL_IS');
end;
if self.fuelFillTriggers[1] then
courseplay:debug(nameNum(self) .. ": resetting \"self.cp.fillTrigger\"",1)
self.cp.fillTrigger = nil
end
end;
--WATER WARNING
if self.showWaterWarning then
allowedToDrive = false
courseplay:setGlobalInfoText(self, 'WATER');
end
if self.cp.stopAtEnd and (self.recordnumber == self.maxnumber or self.cp.currentTipTrigger ~= nil) then
allowedToDrive = false
courseplay:setGlobalInfoText(self, 'END_POINT');
end
end
-- ai_mode 4 = fertilize
local workArea = false
local workSpeed = 0;
local isFinishingWork = false
if self.cp.mode == 4 and self.cp.tipperAttached and self.cp.startWork ~= nil and self.cp.stopWork ~= nil then
allowedToDrive, workArea, workSpeed ,isFinishingWork = courseplay:handle_mode4(self, allowedToDrive, workSpeed, fill_level)
end
-- Mode 6 Fieldwork for balers and foragewagon
if (self.cp.mode == 6 or self.cp.mode == 4) and self.cp.startWork ~= nil and self.cp.stopWork ~= nil then
if self.cp.mode == 6 then
allowedToDrive, workArea, workSpeed, activeTipper ,isFinishingWork = courseplay:handle_mode6(self, allowedToDrive, workSpeed, fill_level, lx , lz )
end
if not workArea and self.cp.tipperFillLevel ~= nil and ((self.grainTankCapacity == nil and self.cp.tipRefOffset ~= nil) or self.cp.hasMachinetoFill) then
if self.cp.currentTipTrigger == nil and self.cp.fillTrigger == nil then
-- is there a tipTrigger within 10 meters?
courseplay:debug(nameNum(self) .. ": call 1st raycast", 1);
local num = raycastAll(tx, ty, tz, nx, ny, nz, "findTipTriggerCallback", 10, self)
if num > 0 then
courseplay:debug(string.format("%s: drive(%d): 1st raycast end", nameNum(self), debug.getinfo(1).currentline), 1);
end;
if courseplay.debugChannels[1] then
drawDebugLine(tx, ty, tz, 1, 0, 0, tx+(nx*10), ty+(ny*10), tz+(nz*10), 1, 0, 0);
end;
if self.cp.tipRefOffset ~= 0 then
if self.cp.currentTipTrigger == nil then
local x1,y1,z1 = localToWorld(self.aiTrafficCollisionTrigger,self.cp.tipRefOffset,0,0)
courseplay:debug(nameNum(self) .. ": call 2nd raycast", 1);
num = raycastAll(x1,y1,z1, nx, ny, nz, "findTipTriggerCallback", 10, self)
if num > 0 then
courseplay:debug(string.format("%s: drive(%d): 2nd raycast end", nameNum(self), debug.getinfo(1).currentline), 1);
end;
if courseplay.debugChannels[1] then
drawDebugLine(x1,y1,z1, 1, 0, 0, x1+(nx*10), y1+(ny*10), z1+(nz*10), 1, 0, 0);
end;
end
if self.cp.currentTipTrigger == nil then
local x1,y1,z1 = localToWorld(self.aiTrafficCollisionTrigger,-self.cp.tipRefOffset,0,0)
courseplay:debug(nameNum(self) .. ": call 3rd raycast", 1);
num = raycastAll(x1,y1,z1, nx, ny, nz, "findTipTriggerCallback", 10, self)
if num > 0 then
courseplay:debug(string.format("%s: drive(%d): 3rd raycast end", nameNum(self), debug.getinfo(1).currentline), 1);
end;
if courseplay.debugChannels[1] then
drawDebugLine(x1,y1,z1, 1, 0, 0, x1+(nx*10), y1+(ny*10), z1+(nz*10), 1, 0, 0);
end;
end
end
end;
end;
end
if self.cp.mode == 9 then
allowedToDrive = courseplay:handle_mode9(self, fill_level, allowedToDrive, dt);
end;
self.cp.inTraffic = false
local dx,_,dz = localDirectionToWorld(self.cp.DirectionNode, 0, 0, 1);
local length = Utils.vector2Length(dx,dz);
if self.cp.turnStage == 0 then
self.aiTractorDirectionX = dx/length;
self.aiTractorDirectionZ = dz/length;
end
--Open/close cover
if self.cp.tipperHasCover and self.cp.automaticCoverHandling and (self.cp.mode == 1 or self.cp.mode == 2 or self.cp.mode == 5 or self.cp.mode == 6) then
local showCover = false;
if self.cp.mode ~= 6 then
local minCoverWaypoint = 3;
if self.cp.mode == 1 then
minCoverWaypoint = 4;
end;
if self.recordnumber >= minCoverWaypoint and self.recordnumber < self.maxnumber and self.cp.currentTipTrigger == nil then
showCover = true;
elseif (self.recordnumber == nil or (self.recordnumber ~= nil and (self.recordnumber == 1 or self.recordnumber == self.maxnumber))) or self.cp.currentTipTrigger ~= nil then
showCover = false;
end;
else
showCover = not workArea and self.cp.currentTipTrigger == nil;
end;
courseplay:openCloseCover(self, dt, showCover, self.cp.currentTipTrigger ~= nil);
end;
allowedToDrive = courseplay:checkTraffic(self, true, allowedToDrive)
if self.cp.waitForTurnTime > self.timer then
allowedToDrive = courseplay:brakeToStop(self)
end
local WpUnload = false
if self.cp.shovelEmptyPoint ~= nil and self.recordnumber >=3 then
WpUnload = self.recordnumber == self.cp.shovelEmptyPoint
end
if WpUnload then
local i = self.cp.shovelEmptyPoint
local x,y,z = getWorldTranslation(self.rootNode)
local _,_,ez = worldToLocal(self.rootNode, self.Waypoints[i].cx , y , self.Waypoints[i].cz)
if ez < 0 then
allowedToDrive = false
end
end
local WpLoadEnd = false
if self.cp.shovelFillEndPoint ~= nil and self.recordnumber >=3 then
WpLoadEnd = self.recordnumber == self.cp.shovelFillEndPoint
end
if WpLoadEnd then
local i = self.cp.shovelFillEndPoint
local x,y,z = getWorldTranslation(self.rootNode)
local _,_,ez = worldToLocal(self.rootNode, self.Waypoints[i].cx , y , self.Waypoints[i].cz)
if ez < 0.2 then
if fill_level == 0 then
allowedToDrive = false
courseplay:setGlobalInfoText(self, 'WORK_END');
else
self.cp.isLoaded = true;
self.recordnumber = i + 2
end
end
end
-- stop or hold position
if not allowedToDrive then
self.cp.TrafficBrake = false
self.cp.isTrafficBraking = false
if self.isRealistic then
courseplay:driveInMRDirection(self, 0,1,true,dt,false)
return
else
AIVehicleUtil.driveInDirection(self, dt, 30, 0, 0, 28, false, moveForwards, 0, 1)
if g_server ~= nil then
AIVehicleUtil.driveInDirection(self, dt, self.cp.steeringAngle, 0.5, 0.5, 28, false, moveForwards, 0, 1)
end
return;
end
-- unload active tipper if given
end
if self.cp.isTurning ~= nil then
courseplay:turn(self, dt);
self.cp.TrafficBrake = false
return
end
--SPEED SETTING
local isAtEnd = self.recordnumber > self.maxnumber - 3;
local isAtStart = self.recordnumber < 3;
if ((self.cp.mode == 1 or self.cp.mode == 5 or self.cp.mode == 7 or self.cp.mode == 8) and (isAtStart or isAtEnd)) or
((self.cp.mode == 2 or self.cp.mode == 3) and isAtEnd) or
(self.cp.mode == 9 and self.recordnumber > self.cp.waitPoints[1] and self.recordnumber <= self.cp.waitPoints[2]) or
(not workArea and self.wait and ((isAtEnd and self.Waypoints[self.recordnumber].wait) or courseplay:waypointsHaveAttr(self, self.recordnumber, 0, 2, "wait", true, false))) or
(isAtEnd and self.Waypoints[self.recordnumber].rev) or
(workSpeed ~= nil and workSpeed == 0.5)
then
self.cp.speeds.sl = 1;
refSpeed = self.cp.speeds.turn;
elseif ((self.cp.mode == 2 or self.cp.mode == 3) and isAtStart) or (workSpeed ~= nil and workSpeed == 1) then
self.cp.speeds.sl = 2;
refSpeed = self.cp.speeds.field;
else
self.cp.speeds.sl = 3;
refSpeed = self.cp.speeds.max;
if self.cp.speeds.useRecordingSpeed and self.Waypoints[self.recordnumber].speed ~= nil then
refSpeed = Utils.clamp(refSpeed, 3/3600, self.Waypoints[self.recordnumber].speed);
end;
end;
if self.cp.collidingVehicleId ~= nil then
refSpeed = courseplay:regulateTrafficSpeed(self, refSpeed, allowedToDrive);
end
local real_speed = self.lastSpeedReal;
local maxRpm = self.motor.maxRpm[self.cp.speeds.sl];
--bunkerSilo speed by Thomas Gärtner
if self.cp.currentTipTrigger ~= nil then
if self.cp.currentTipTrigger.bunkerSilo ~= nil then
refSpeed = Utils.getNoNil(self.cp.speeds.unload, 3/3600);
else
refSpeed = self.cp.speeds.turn
end
elseif self.cp.isInFilltrigger then
if self.lastSpeedReal > self.cp.speeds.turn then
courseplay:brakeToStop(self)
else
refSpeed = self.cp.speeds.turn
end
self.cp.isInFilltrigger = false
else
if self.runonce ~= nil then
self.runonce = nil;
end
end
--checking ESLimiter version
if self.ESLimiter ~= nil and self.ESLimiter.maxRPM[5] == nil then
self.cp.infoText = courseplay:loc("CPWrongESLversion")
end
-- where to drive?
if courseplay:isWheelloader(self) then
local lx2 ,lz2 = AIVehicleUtil.getDriveDirection(self.rootNode, cx, cty, cz);
if math.abs(self.steeringLastRotation) < 0.5 then
lx = lx2
lz = lz2
end
end
--finishing field work
if isFinishingWork then
lx=0
lz=1
end
--reverse
if self.Waypoints[self.recordnumber].rev then
lx,lz,fwd = courseplay:goReverse(self,lx,lz)
refSpeed = Utils.getNoNil(self.cp.speeds.unload, 3/3600)
else
fwd = true
end
if self.cp.TrafficBrake then
if self.isRealistic then
AIVehicleUtil.mrDriveInDirection(self, dt, 1, false, true, 0, 1, self.cp.speeds.sl, true, true)
self.cp.TrafficBrake = false
self.cp.isTrafficBraking = false
self.cp.TrafficHasStopped = false
return
else
fwd = false
lx = 0
lz = 1
end
end
self.cp.TrafficBrake = false
self.cp.isTrafficBraking = false
self.cp.TrafficHasStopped = false
if self.cp.mode7GoBackBeforeUnloading then
fwd = false
lz = lz * -1
lx = lx * -1
end
-- Speed Control
if self.cp.maxFieldSpeed ~= 0 then
refSpeed = math.min(self.cp.maxFieldSpeed, refSpeed);
end
if self.isRealistic then
courseplay:setMRSpeed(self, refSpeed, self.cp.speeds.sl, allowedToDrive, workArea);
else
courseplay:setSpeed(self, refSpeed, self.cp.speeds.sl)
end
-- go, go, go!
if self.recordnumber == 1 or self.recordnumber == self.maxnumber - 1 or self.Waypoints[self.recordnumber].turn then
distToChange = 0.5
elseif self.recordnumber + 1 <= self.maxnumber then
local beforeReverse = (self.Waypoints[self.recordnumber + 1].rev and (self.Waypoints[self.recordnumber].rev == false))
local afterReverse = (not self.Waypoints[self.recordnumber + 1].rev and self.Waypoints[self.cp.last_recordnumber].rev)
if (self.Waypoints[self.recordnumber].wait or beforeReverse) and self.Waypoints[self.recordnumber].rev == false then -- or afterReverse or self.recordnumber == 1
distToChange = 1
elseif (self.Waypoints[self.recordnumber].rev and self.Waypoints[self.recordnumber].wait) or afterReverse then
distToChange = 2
elseif self.Waypoints[self.recordnumber].rev then
distToChange = 2; --1
elseif self.cp.mode == 4 or self.cp.mode == 6 or self.cp.mode == 7 then
distToChange = 5;
elseif self.cp.mode == 9 then
distToChange = 4;
else
distToChange = 2.85; --orig: 5
end;
else
distToChange = 2.85; --orig: 5
end
if self.cp.isKasi ~= nil then
distToChange = distToChange * self.cp.isKasi
end
-- record shortest distance to the next waypoint
if self.cp.shortestDistToWp == nil or self.cp.shortestDistToWp > self.dist then
self.cp.shortestDistToWp = self.dist
end
if beforeReverse then
self.cp.shortestDistToWp = nil
end
if self.invertedDrivingDirection then
lx = -lx
lz = -lz
end
-- if distance grows i must be circling
if self.dist > self.cp.shortestDistToWp and self.recordnumber > 3 and self.dist < 15 and self.Waypoints[self.recordnumber].rev ~= true then
distToChange = self.dist + 1
end
if self.dist > distToChange or WpUnload or WpLoadEnd or isFinishingWork then
if g_server ~= nil then
if self.isRealistic then
courseplay:driveInMRDirection(self, lx,lz,fwd, dt,allowedToDrive);
else
AIVehicleUtil.driveInDirection(self, dt, self.cp.steeringAngle, 0.5, 0.5, 8, true, fwd, lx, lz, self.cp.speeds.sl, 0.5);
end
if not isBypassing then
courseplay:setTrafficCollision(self, lx, lz, workArea)
end
end
else
-- reset distance to waypoint
self.cp.shortestDistToWp = nil
if self.recordnumber < self.maxnumber then -- = New
if not self.wait then
self.wait = true
end
if self.cp.mode == 7 and self.cp.modeState == 5 then
else
self.recordnumber = self.recordnumber + 1
end
-- ignore reverse Waypoints for mode 6
local in_work_area = false
if self.cp.startWork ~= nil and self.cp.stopWork ~= nil and self.recordnumber >= self.cp.startWork and self.recordnumber <= self.cp.stopWork then
in_work_area = true
end
while self.cp.mode == 6 and self.recordnumber < self.maxnumber and in_work_area and self.Waypoints[self.recordnumber].rev do
self.recordnumber = self.recordnumber + 1
end
else -- reset some variables
if (self.cp.mode == 4 or self.cp.mode == 6) and not self.cp.hasUnloadingRefillingCourse then
else
self.recordnumber = 1
end
self.cp.isUnloaded = false
self.cp.stopAtEnd = false
self.cp.isLoaded = false
self.cp.isRecording = false
self.cp.canDrive = true
end
end
end
function courseplay:setTrafficCollision(self, lx, lz, workArea) --!!!
--local goForRaycast = self.cp.mode == 1 or (self.cp.mode == 3 and self.recordnumber > 3) or self.cp.mode == 5 or self.cp.mode == 8 or ((self.cp.mode == 4 or self.cp.mode == 6) and self.recordnumber > self.cp.stopWork) or (self.cp.mode == 2 and self.recordnumber > 3)
--print("lx: "..tostring(lx).." distance: "..tostring(distance))
local maxlx = 0.5; --math.sin(maxAngle); --sin30° old was : 0.7071067 sin 45°
local colDirX = lx;
local colDirZ = lz;
if colDirX > maxlx then
colDirX = maxlx;
elseif colDirX < -maxlx then
colDirX = -maxlx;
end;
if colDirZ < -0.4 then
colDirZ = 0.4;
end;
--courseplay:debug(string.format("colDirX: %f colDirZ %f ",colDirX,colDirZ ), 3)
if self.cp.trafficCollisionTriggers[1] ~= nil then
AIVehicleUtil.setCollisionDirection(self.cp.DirectionNode, self.cp.trafficCollisionTriggers[1], colDirX, colDirZ);
local recordNumber = self.recordnumber
if self.cp.collidingVehicleId == nil then
for i=2,self.cp.numTrafficCollisionTriggers do
if workArea or recordNumber + i > self.maxnumber or recordNumber < 2 then
AIVehicleUtil.setCollisionDirection(self.cp.trafficCollisionTriggers[i-1], self.cp.trafficCollisionTriggers[i], 0, -1);
else
local nodeX,nodeY,nodeZ = getWorldTranslation(self.cp.trafficCollisionTriggers[i]);
local nodeDirX,nodeDirY,nodeDirZ,distance = courseplay:get3dDirection(nodeX,nodeY,nodeZ, self.Waypoints[recordNumber+i].cx,nodeY,self.Waypoints[recordNumber+i].cz);
if distance < 5.5 and recordNumber + i +1 <= self.maxnumber then
nodeDirX,nodeDirY,nodeDirZ,distance = courseplay:get3dDirection(nodeX,nodeY,nodeZ, self.Waypoints[recordNumber+i+1].cx,nodeY,self.Waypoints[recordNumber+i+1].cz);
end;
nodeDirX,nodeDirY,nodeDirZ = worldDirectionToLocal(self.cp.trafficCollisionTriggers[i-1], nodeDirX,nodeDirY,nodeDirZ);
AIVehicleUtil.setCollisionDirection(self.cp.trafficCollisionTriggers[i-1], self.cp.trafficCollisionTriggers[i], nodeDirX, nodeDirZ);
end;
end
end
end;
end;
function courseplay:checkTraffic(self, display_warnings, allowedToDrive)
local ahead = false
local collisionVehicle = g_currentMission.nodeToVehicle[self.cp.collidingVehicleId]
--courseplay:debug(tableShow(self, nameNum(self), 4), 4)
--if self.CPnumCollidingVehicles ~= nil and self.CPnumCollidingVehicles > 0 then
if collisionVehicle ~= nil and not (self.cp.mode == 9 and collisionVehicle.allowFillFromAir) then
local vx, vy, vz = getWorldTranslation(self.cp.collidingVehicleId)
local tx, ty, tz = worldToLocal(self.aiTrafficCollisionTrigger, vx, vy, vz)
local xvx, xvy, xvz = getWorldTranslation(self.aiTrafficCollisionTrigger)
local x, y, z = getWorldTranslation(self.cp.DirectionNode)
local x1, y1, z1 = 0,0,0
local halfLength = Utils.getNoNil(collisionVehicle.sizeLength,5)/2
x1,z1 = AIVehicleUtil.getDriveDirection(self.cp.collidingVehicleId, x, y, z);
if z1 > -0.9 then -- tractor in front of vehicle face2face or beside < 4 o'clock
ahead = true
end
if math.abs(tx) > 5 and collisionVehicle.rootNode ~= nil and not self.cp.collidingObjects.all[self.cp.collidingVehicleId] then
courseplay:debug(nameNum(self)..": checkTraffic: deleteCollisionVehicle",3)
courseplay:deleteCollisionVehicle(self)
return allowedToDrive
end
if collisionVehicle.lastSpeedReal == nil or collisionVehicle.lastSpeedReal*3600 < 5 or ahead then
--courseplay:debug(nameNum(self)..": checkTraffic: distance: "..tostring(tz-halfLength),3)
if tz <= 2 + halfLength then
allowedToDrive = false;
self.cp.inTraffic = true
--courseplay:debug(nameNum(self)..": checkTraffic: Stop",3)
elseif self.lastSpeedReal*3600 > 10 then
--courseplay:debug(nameNum(self)..": checkTraffic: brake",3)
allowedToDrive = courseplay:brakeToStop(self)
else
--courseplay:debug(nameNum(self)..": checkTraffic: do nothing - go, but set \"self.cp.isTrafficBraking\"",3)
self.cp.isTrafficBraking = true
end
end
end