forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.lua
More file actions
1315 lines (1142 loc) · 48.7 KB
/
settings.lua
File metadata and controls
1315 lines (1142 loc) · 48.7 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
function courseplay:openCloseHud(self, open)
courseplay:setMouseCursor(self, open);
self.cp.hud.show = open;
--set ESLimiter
if self.cp.hud.ESLimiterOrigPosY == nil and open and self.ESLimiter ~= nil and self.ESLimiter.xPos ~= nil and self.ESLimiter.yPos ~= nil and self.ESLimiter.overlay ~= nil and self.ESLimiter.overlayBg ~= nil and self.ESLimiter.overlayBar ~= nil then
if self.ESLimiter.xPos > courseplay.hud.visibleArea.x1 and self.ESLimiter.xPos < courseplay.hud.visibleArea.x2 and self.ESLimiter.yPos > courseplay.hud.visibleArea.y1 and self.ESLimiter.yPos < courseplay.hud.visibleArea.y2 then
self.cp.hud.ESLimiterOrigPosY = {
self.ESLimiter.yPos,
self.ESLimiter.overlay.y,
self.ESLimiter.overlayBg.y,
self.ESLimiter.overlayBar.y
};
end;
end;
--toggle ESLimiter
if self.cp.hud.ESLimiterOrigPosY ~= nil then
if open then
self.ESLimiter.yPos = -1;
self.ESLimiter.overlay:setPosition(self.ESLimiter.overlay.x, -1);
self.ESLimiter.overlayBg:setPosition(self.ESLimiter.overlayBg.x, -1);
self.ESLimiter.overlayBar:setPosition(self.ESLimiter.overlayBar.x, -1);
else
self.ESLimiter.yPos = self.cp.hud.ESLimiterOrigPosY[1];
self.ESLimiter.overlay:setPosition(self.ESLimiter.overlay.x, self.cp.hud.ESLimiterOrigPosY[2]);
self.ESLimiter.overlayBg:setPosition(self.ESLimiter.overlayBg.x, self.cp.hud.ESLimiterOrigPosY[3]);
self.ESLimiter.overlayBar:setPosition(self.ESLimiter.overlayBar.x, self.cp.hud.ESLimiterOrigPosY[4]);
end;
end;
--set ThreshingCounter
local isManualThreshingCounter = self.sessionHectars ~= nil and self.tcOverlay ~= nil and self.tcX ~= nil and self.tcY ~= nil;
local isGlobalThreshingCounter = self.ThreshingCounter ~= nil and self.tcOverlay ~= nil and self.xPos ~= nil and self.yPos ~= nil;
if self.cp.hud.ThreshingCounterOrigPosY == nil and open and (isManualThreshingCounter or isGlobalThreshingCounter) then
local x, y = nil, nil;
if isManualThreshingCounter then
x, y = self.tcX, self.tcY;
elseif isGlobalThreshingCounter then
x, y = self.xPos, self.yPos;
end;
if x and y and x > courseplay.hud.visibleArea.x1 and x < courseplay.hud.visibleArea.x2 and y > courseplay.hud.visibleArea.y1 and y < courseplay.hud.visibleArea.y2 then
self.cp.hud.ThreshingCounterOrigPosY = {
y,
self.tcOverlay.y,
};
end;
end;
--toggle ThreshingCounter
if self.cp.hud.ThreshingCounterOrigPosY ~= nil then
if isManualThreshingCounter then
if open then
self.tcY = -1;
self.tcOverlay:setPosition(self.tcOverlay.x, -1);
else
self.tcY = self.cp.hud.ThreshingCounterOrigPosY[1];
self.tcOverlay:setPosition(self.tcOverlay.x, self.cp.hud.ThreshingCounterOrigPosY[2]);
end;
elseif isGlobalThreshingCounter then
if open then
self.yPos = -1;
self.tcOverlay:setPosition(self.tcOverlay.x, -1);
else
self.yPos = self.cp.hud.ThreshingCounterOrigPosY[1];
self.tcOverlay:setPosition(self.tcOverlay.x, self.cp.hud.ThreshingCounterOrigPosY[2]);
end;
end;
end;
--set Odometer
if self.cp.hud.OdometerOrigPosY == nil and open and self.Odometer ~= nil and self.Odometer.HUD ~= nil and self.Odometer.posX ~= nil and self.Odometer.posY ~= nil then
if self.Odometer.posX > courseplay.hud.visibleArea.x1 and self.Odometer.posX < courseplay.hud.visibleArea.x2 and self.Odometer.posY > courseplay.hud.visibleArea.y1 and self.Odometer.posY < courseplay.hud.visibleArea.y2 then
--if courseplay:numberInSpan(self.Odometer.posX, courseplay.hud.visibleArea.x1, courseplay.hud.visibleArea.x2) and courseplay:numberInSpan(self.Odometer.posY, courseplay.hud.visibleArea.y1, courseplay.hud.visibleArea.y2) then
self.cp.hud.OdometerOrigPosY = {
self.Odometer.posY,
self.Odometer.HUD.y,
};
end;
end;
--toggle Odometer
if self.cp.hud.OdometerOrigPosY ~= nil then
if open then
self.Odometer.posY = -1;
self.Odometer.HUD:setPosition(self.Odometer.HUD.x, -1);
else
self.Odometer.posY = self.cp.hud.OdometerOrigPosY[1];
self.Odometer.HUD:setPosition(self.Odometer.HUD.x, self.cp.hud.OdometerOrigPosY[2]);
end;
end;
--set 4WD/Allrad
if self.cp.hud.AllradOrigPosY == nil and open and self.AllradV4Active ~= nil and self.hudAllradONOverlay ~= nil and self.hudAllradOFFOverlay ~= nil and self.hudAllradPosX ~= nil and self.hudAllradPosY ~= nil then
if self.hudAllradPosX > courseplay.hud.visibleArea.x1 and self.hudAllradPosX < courseplay.hud.visibleArea.x2 and self.hudAllradPosY > courseplay.hud.visibleArea.y1 and self.hudAllradPosY < courseplay.hud.visibleArea.y2 then
self.cp.hud.AllradOrigPosY = {
self.hudAllradPosY,
self.hudAllradONOverlay.y,
self.hudAllradOFFOverlay.y,
};
end;
end;
--toggle 4WD/Allrad
if self.cp.hud.AllradOrigPosY ~= nil then
if open then
self.hudAllradPosY = -1;
self.hudAllradONOverlay:setPosition(self.hudAllradONOverlay.x, -1);
self.hudAllradOFFOverlay:setPosition(self.hudAllradOFFOverlay.x, -1);
else
self.hudAllradPosY = self.cp.hud.AllradOrigPosY[1];
self.hudAllradONOverlay:setPosition(self.hudAllradONOverlay.x, self.cp.hud.AllradOrigPosY[2]);
self.hudAllradOFFOverlay:setPosition(self.hudAllradOFFOverlay.x, self.cp.hud.AllradOrigPosY[3]);
end;
end;
end;
function courseplay:setAiMode(vehicle, modeNum)
vehicle.cp.mode = modeNum;
courseplay:buttonsActiveEnabled(vehicle, "all");
end;
function courseplay:call_player(combine)
combine.wants_courseplayer = not combine.wants_courseplayer;
end;
function courseplay:start_stop_player(combine)
local tractor = combine.courseplayers[1];
tractor.cp.forcedToStop = not tractor.cp.forcedToStop;
end;
function courseplay:driveOn(vehicle, cancelStopAtEnd)
if vehicle.wait then
vehicle.wait = false;
end;
if vehicle.cp.mode == 3 then
vehicle.cp.isUnloaded = true;
end;
if cancelStopAtEnd then
courseplay:setStopAtEnd(vehicle, false);
end;
end;
function courseplay:setStopAtEnd(vehicle, bool)
vehicle.cp.stopAtEnd = bool;
end;
function courseplay:setIsLoaded(vehicle, bool)
vehicle.cp.isLoaded = bool;
end;
function courseplay:send_player_home(combine)
local tractor = combine.courseplayers[1];
tractor.cp.isLoaded = true;
end
function courseplay:switch_player_side(combine)
if combine.grainTankCapacity == 0 then
local tractor = combine.courseplayers[1];
if tractor == nil then
return;
end;
tractor.cp.modeState = 10;
if combine.cp.forcedSide == nil then
combine.cp.forcedSide = "left";
elseif combine.cp.forcedSide == "left" then
combine.cp.forcedSide = "right";
else
combine.cp.forcedSide = nil;
end;
end;
end;
function courseplay:setHudPage(vehicle, pageNum)
if vehicle.cp.mode == nil then
vehicle.cp.hud.currentPage = pageNum;
elseif courseplay.hud.pagesPerMode[vehicle.cp.mode] ~= nil and courseplay.hud.pagesPerMode[vehicle.cp.mode][pageNum+1] then
if pageNum == 0 then
if vehicle.cp.minHudPage == 0 or vehicle.cp.isCombine or vehicle.cp.isChopper or vehicle.cp.isHarvesterSteerable or vehicle.cp.isSugarBeetLoader then
vehicle.cp.hud.currentPage = pageNum;
end;
else
vehicle.cp.hud.currentPage = pageNum;
end;
end;
courseplay.hud:setReloadPageOrder(vehicle, vehicle.cp.hud.currentPage, true);
courseplay:buttonsActiveEnabled(vehicle, "all");
end;
function courseplay:switch_hud_page(vehicle, changeBy)
newPage = courseplay:minMaxPage(vehicle, vehicle.cp.hud.currentPage + changeBy);
if vehicle.cp.mode == nil then
vehicle.cp.hud.currentPage = newPage;
elseif courseplay.hud.pagesPerMode[vehicle.cp.mode] ~= nil then
while courseplay.hud.pagesPerMode[vehicle.cp.mode][newPage+1] == false do
newPage = courseplay:minMaxPage(vehicle, newPage + changeBy);
end;
vehicle.cp.hud.currentPage = newPage;
end;
courseplay.hud:setReloadPageOrder(vehicle, vehicle.cp.hud.currentPage, true);
courseplay:buttonsActiveEnabled(vehicle, "all");
end;
function courseplay:minMaxPage(vehicle, pageNum)
if pageNum < vehicle.cp.minHudPage then
pageNum = courseplay.hud.numPages;
elseif pageNum > courseplay.hud.numPages then
pageNum = vehicle.cp.minHudPage;
end;
return pageNum;
end;
function courseplay:buttonsActiveEnabled(self, section)
if section == nil or section == "all" or section == "pageNav" then
for _,button in pairs(self.cp.buttons.global) do
if button.function_to_call == "setHudPage" then
local pageNum = button.parameter;
button.isActive = pageNum == self.cp.hud.currentPage;
if self.cp.mode == nil then
button.isDisabled = false;
elseif courseplay.hud.pagesPerMode[self.cp.mode] ~= nil and courseplay.hud.pagesPerMode[self.cp.mode][pageNum+1] then
if pageNum == 0 then
button.isDisabled = not (self.cp.minHudPage == 0 or self.cp.isCombine or self.cp.isChopper or self.cp.isHarvesterSteerable or self.cp.isSugarBeetLoader);
else
button.isDisabled = false;
end;
else
button.isDisabled = true;
end;
button.canBeClicked = not button.isDisabled and not button.isActive;
end;
end;
end;
if self.cp.hud.currentPage == 1 and (section == nil or section == "all" or section == "quickModes" or section == "recording" or section == "customFieldShow") then
for _,button in pairs(self.cp.buttons["1"]) do
local fn = button.function_to_call;
if fn == "setAiMode" then
button.isActive = self.cp.mode == button.parameter;
button.isDisabled = button.parameter == 7 and not self.cp.isCombine and not self.cp.isChopper and not self.cp.isHarvesterSteerable;
button.canBeClicked = not button.isDisabled and not button.isActive;
elseif fn == "toggleCustomFieldEdgePathShow" then
button.isActive = self.cp.fieldEdge.customField.show;
elseif fn == 'stop_record' then
button.isDisabled = self.cp.recordingIsPaused or self.cp.isRecordingTurnManeuver;
button.canBeClicked = not button.isDisabled;
elseif fn == 'setRecordingPause' then
button.isActive = self.cp.recordingIsPaused;
button.isDisabled = self.cp.HUDrecordnumber < 4 or self.cp.isRecordingTurnManeuver;
button.canBeClicked = not button.isDisabled;
elseif fn == 'delete_waypoint' then
-- NOTE: during recording pause, HUDrecordnumber = recordnumber + 1, that's why <= 5 is used
button.isDisabled = not self.cp.recordingIsPaused or self.cp.HUDrecordnumber <= 5;
button.canBeClicked = not button.isDisabled;
elseif fn == 'set_waitpoint' or fn == 'set_crossing' then
button.isDisabled = self.cp.recordingIsPaused or self.cp.isRecordingTurnManeuver;
button.canBeClicked = not button.isDisabled;
elseif fn == 'setRecordingTurnManeuver' then --isToggleButton
button.isActive = self.cp.isRecordingTurnManeuver;
button.isDisabled = self.cp.recordingIsPaused or self.cp.drivingDirReverse;
button.canBeClicked = not button.isDisabled;
elseif fn == 'change_DriveDirection' then --isToggleButton
button.isActive = self.cp.drivingDirReverse;
button.isDisabled = self.cp.recordingIsPaused or self.cp.isRecordingTurnManeuver;
button.canBeClicked = not button.isDisabled;
end;
end;
elseif self.cp.hud.currentPage == 2 and section == 'page2' then
local enable, hide = true, false
local n_courses = #(self.cp.hud.courses)
local nofolders = nil == next(g_currentMission.cp_folders);
local offset = courseplay.hud.offset --0.006 (button width)
local row
for _, button in pairs(self.cp.buttons['-2']) do
row = button.row
enable = true
hide = false
if row > n_courses then
hide = true
else
if button.function_to_call == "expandFolder" then
if self.cp.hud.courses[row].type == 'course' then
hide = true
else
-- position the expandFolder buttons
courseplay.button.setOffset(button, self.cp.hud.courses[row].level * offset, 0)
if self.cp.hud.courses[row].id == 0 then
hide = true --hide for level 0 "folder"
else
-- check if plus or minus should show up
if self.cp.folder_settings[self.cp.hud.courses[row].id].showChildren then
courseplay.button.setOverlay(button,2)
else
courseplay.button.setOverlay(button,1)
end
if g_currentMission.cp_sorted.info[ self.cp.hud.courses[row].uid ].lastChild == 0 then
enable = false -- button has no children
end
end
end
else
if self.cp.hud.courses[row].type == 'folder' and (button.function_to_call == "load_sorted_course" or button.function_to_call == "add_sorted_course") then
hide = true
elseif self.cp.hud.choose_parent ~= true then
if button.function_to_call == 'delete_sorted_item' and self.cp.hud.courses[row].type == 'folder' and g_currentMission.cp_sorted.info[ self.cp.hud.courses[row].uid ].lastChild ~= 0 then
enable = false
elseif button.function_to_call == 'link_parent' then
courseplay.button.setOverlay(button, 1);
if nofolders then
enable = false;
end;
end
else
if button.function_to_call ~= 'link_parent' then
enable = false
else
courseplay.button.setOverlay(button, 2);
end
end
end
end
button.isDisabled = (not enable) or hide
button.isHidden = hide
end -- for buttons
courseplay.settings.validateCourseListArrows(self)
elseif self.cp.hud.currentPage == 6 and (section == nil or section == "all" or section == "debug") then
for _,button in pairs(self.cp.buttons["6"]) do
if button.function_to_call == "toggleDebugChannel" then
button.isDisabled = button.parameter > courseplay.numDebugChannels;
button.isActive = courseplay.debugChannels[button.parameter] == true;
button.canBeClicked = not button.isDisabled;
end;
end;
elseif self.cp.hud.currentPage == 8 and (section == nil or section == "all" or section == "selectedFieldShow") then
for _,button in pairs(self.cp.buttons["8"]) do
if button.function_to_call == "toggleSelectedFieldEdgePathShow" then
button.isActive = self.cp.fieldEdge.selectedField.show;
break;
end;
end;
elseif self.cp.hud.currentPage == 9 and (section == nil or section == "all" or section == "shovel") then
for _,button in pairs(self.cp.buttons["9"]) do
if button.function_to_call == "saveShovelStatus" then --isToggleButton
button.isActive = self.cp.shovelStateRot[tostring(button.parameter)] ~= nil;
button.canBeClicked = true;
end;
end;
end;
end;
function courseplay:change_combine_offset(vehicle, changeBy)
local previousOffset = vehicle.cp.combineOffset;
vehicle.cp.combineOffsetAutoMode = false;
vehicle.cp.combineOffset = courseplay:round(vehicle.cp.combineOffset, 1) + changeBy;
if math.abs(vehicle.cp.combineOffset) < 0.1 then
vehicle.cp.combineOffset = 0.0;
vehicle.cp.combineOffsetAutoMode = true;
end;
courseplay:debug(nameNum(vehicle) .. ": manual combine_offset change: prev " .. previousOffset .. " // new " .. vehicle.cp.combineOffset .. " // auto = " .. tostring(vehicle.cp.combineOffsetAutoMode), 4);
end
function courseplay:change_tipper_offset(vehicle, changeBy)
vehicle.cp.tipperOffset = courseplay:round(vehicle.cp.tipperOffset, 1) + changeBy;
if math.abs(vehicle.cp.tipperOffset) < 0.1 then
vehicle.cp.tipperOffset = 0;
end;
end
function courseplay:changeLaneOffset(vehicle, changeBy, force)
vehicle.cp.laneOffset = force or (vehicle.cp.laneOffset + changeBy);
if math.abs(vehicle.cp.laneOffset) < 0.1 then
vehicle.cp.laneOffset = 0;
end;
vehicle.cp.totalOffsetX = vehicle.cp.laneOffset + vehicle.cp.toolOffsetX;
end;
function courseplay:changeToolOffsetX(vehicle, changeBy, force, noDraw)
vehicle.cp.toolOffsetX = force or (vehicle.cp.toolOffsetX + changeBy);
if math.abs(vehicle.cp.toolOffsetX) < 0.1 then
vehicle.cp.toolOffsetX = 0;
end;
vehicle.cp.totalOffsetX = vehicle.cp.laneOffset + vehicle.cp.toolOffsetX;
if noDraw == nil then noDraw = false; end;
if not noDraw and vehicle.cp.mode ~= 3 and vehicle.cp.mode ~= 7 then
courseplay:calculateWorkWidthDisplayPoints(vehicle);
vehicle.cp.workWidthChanged = vehicle.timer + 2000;
end
end;
function courseplay:changeToolOffsetZ(vehicle, changeBy, force)
vehicle.cp.toolOffsetZ = force or (vehicle.cp.toolOffsetZ + changeBy);
if math.abs(vehicle.cp.toolOffsetZ) < 0.1 then
vehicle.cp.toolOffsetZ = 0;
end;
end;
function courseplay:changeWorkWidth(vehicle, changeBy)
if vehicle.cp.workWidth + changeBy > 10 then
if math.abs(changeBy) == 0.1 then
changeBy = 0.5 * Utils.sign(changeBy);
elseif math.abs(changeBy) == 0.5 then
changeBy = 2 * Utils.sign(changeBy);
end;
end;
vehicle.cp.workWidth = math.max(vehicle.cp.workWidth + changeBy, 0.1);
courseplay:calculateWorkWidthDisplayPoints(vehicle);
vehicle.cp.workWidthChanged = vehicle.timer + 2000;
end;
function courseplay:calculateWorkWidthDisplayPoints(vehicle)
--calculate points for display
local x, y, z = getWorldTranslation(vehicle.rootNode)
local left = (vehicle.cp.workWidth * 0.5) + (vehicle.cp.toolOffsetX or 0);
local right = (vehicle.cp.workWidth * -0.5) + (vehicle.cp.toolOffsetX or 0);
local pointLx, pointLy, pointLz = localToWorld(vehicle.rootNode, left, 1, -6);
local pointRx, pointRy, pointRz = localToWorld(vehicle.rootNode, right, 1, -6);
vehicle.cp.workWidthDisplayPoints = {
left = { x = pointLx; y = pointLy, z = pointLz; };
right = { x = pointRx; y = pointRy, z = pointRz; };
};
end;
function courseplay:change_WaypointMode(self, changeBy)
self.cp.visualWaypointsMode = courseplay:varLoop(self.cp.visualWaypointsMode, changeBy, 4, 1);
courseplay:setSignsVisibility(self);
end
function courseplay:change_required_fill_level_for_drive_on(self, change_by)
self.cp.driveOnAtFillLevel = Utils.clamp(self.cp.driveOnAtFillLevel + change_by, 0, 100);
end
function courseplay:change_required_fill_level(self, change_by)
self.cp.followAtFillLevel = Utils.clamp(self.cp.followAtFillLevel + change_by, 0, 100);
end
function courseplay:changeTurnRadius(vehicle, changeBy)
vehicle.cp.turnRadius = vehicle.cp.turnRadius + changeBy;
vehicle.cp.turnRadiusAutoMode = false;
if vehicle.cp.turnRadius < 0.5 then
vehicle.cp.turnRadius = 0;
end;
if vehicle.cp.turnRadius <= 0 then
vehicle.cp.turnRadiusAutoMode = true;
vehicle.cp.turnRadius = vehicle.cp.turnRadiusAuto
end;
end
function courseplay:change_turn_speed(self, change_by)
local speed = self.cp.speeds.turn * 3600;
speed = Utils.clamp(speed + change_by, 5, 60);
self.cp.speeds.turn = speed / 3600;
end
function courseplay:changeWaitTime(vehicle, changeBy)
vehicle.cp.waitTime = math.max(0, vehicle.cp.waitTime + changeBy);
end
function courseplay:change_field_speed(self, change_by)
local speed = self.cp.speeds.field * 3600;
speed = Utils.clamp(speed + change_by, 5, 60);
self.cp.speeds.field = speed / 3600;
end
function courseplay:change_max_speed(self, change_by)
if not self.cp.speeds.useRecordingSpeed then
local speed = self.cp.speeds.max * 3600;
speed = Utils.clamp(speed + change_by, 5, 60);
self.cp.speeds.max = speed / 3600;
end;
end
function courseplay:change_unload_speed(self, change_by)
local speed = self.cp.speeds.unload * 3600;
speed = Utils.clamp(speed + change_by, 3, 60);
self.cp.speeds.unload = speed / 3600;
end
function courseplay:change_use_speed(self)
self.cp.speeds.useRecordingSpeed = not self.cp.speeds.useRecordingSpeed
end
function courseplay:changeBeaconLightsMode(vehicle, changeBy)
vehicle.cp.beaconLightsMode = vehicle.cp.beaconLightsMode + changeBy;
if vehicle.cp.beaconLightsMode == 4 then
vehicle.cp.beaconLightsMode = 1;
end;
end;
function courseplay:toggleOpenHudWithMouse(vehicle)
vehicle.cp.hud.openWithMouse = not vehicle.cp.hud.openWithMouse;
end;
function courseplay:toggleRealisticDriving(vehicle)
vehicle.cp.realisticDriving = not vehicle.cp.realisticDriving;
end;
function courseplay:switchSearchCombineMode(vehicle)
vehicle.cp.searchCombineAutomatically = not vehicle.cp.searchCombineAutomatically;
end;
function courseplay:setSearchCombineOnField(vehicle, changeDir)
if courseplay.fields.numAvailableFields == 0 or not vehicle.cp.searchCombineAutomatically then return; end;
local newFieldNum = vehicle.cp.searchCombineOnField + changeDir;
if newFieldNum == 0 then
vehicle.cp.searchCombineOnField = newFieldNum;
return;
end;
while courseplay.fields.fieldData[newFieldNum] == nil do
if newFieldNum == 0 then
vehicle.cp.searchCombineOnField = newFieldNum;
return;
end;
newFieldNum = Utils.clamp(newFieldNum + changeDir, 0, courseplay.fields.numAvailableFields);
end;
vehicle.cp.searchCombineOnField = newFieldNum;
end;
function courseplay:selectAssignedCombine(vehicle, changeBy)
local combines = courseplay:find_combines(vehicle);
vehicle.cp.selectedCombineNumber = Utils.clamp(vehicle.cp.selectedCombineNumber + changeBy, 0, #combines);
if vehicle.cp.selectedCombineNumber == 0 then
vehicle.cp.savedCombine = nil;
else
vehicle.cp.savedCombine = combines[vehicle.cp.selectedCombineNumber];
end;
courseplay:removeActiveCombineFromTractor(vehicle);
end;
function courseplay:removeActiveCombineFromTractor(vehicle)
if vehicle.cp.activeCombine ~= nil then
courseplay:unregister_at_combine(vehicle, vehicle.cp.activeCombine);
end;
vehicle.cp.lastActiveCombine = nil;
end;
function courseplay:switchDriverCopy(self, change_by)
local drivers = courseplay:findDrivers(self);
if drivers ~= nil then
local selectedDriverNumber = self.cp.selectedDriverNumber + change_by;
self.cp.selectedDriverNumber = Utils.clamp(selectedDriverNumber, 0, #(drivers));
if self.cp.selectedDriverNumber == 0 then
self.cp.copyCourseFromDriver = nil;
self.cp.hasFoundCopyDriver = false;
else
self.cp.copyCourseFromDriver = drivers[self.cp.selectedDriverNumber];
self.cp.hasFoundCopyDriver = true;
end;
else
self.cp.copyCourseFromDriver = nil;
self.cp.selectedDriverNumber = 0;
self.cp.hasFoundCopyDriver = false;
end;
end;
function courseplay:findDrivers(self)
local foundDrivers = {}; -- resetting all drivers
for k, vehicle in pairs(g_currentMission.steerables) do
if vehicle.Waypoints ~= nil then
if vehicle.rootNode ~= self.rootNode and #(vehicle.Waypoints) > 0 then
table.insert(foundDrivers, vehicle);
end;
end;
end;
return foundDrivers;
end;
function courseplay:copyCourse(self)
if self.cp.hasFoundCopyDriver ~= nil and self.cp.copyCourseFromDriver ~= nil then
local src = self.cp.copyCourseFromDriver;
self.Waypoints = src.Waypoints;
self.cp.currentCourseName = src.cp.currentCourseName;
self.cp.loadedCourses = src.cp.loadedCourses;
self.cp.numCourses = src.cp.numCourses;
self.recordnumber = 1;
self.maxnumber = table.getn(self.Waypoints);
self.cp.isRecording = false;
self.cp.recordingIsPaused = false;
self.drive = false;
self.cp.distanceCheck = false;
self.cp.canDrive = true;
self.cp.abortWork = nil;
self.target_x, self.target_y, self.target_z = nil, nil, nil;
if self.cp.activeCombine ~= nil then
courseplay:unregister_at_combine(self, self.cp.activeCombine);
end
self.cp.modeState = 1;
self.cp.recordingTimer = 1;
courseplay:updateWaypointSigns(self, "current");
--reset variables
self.cp.selectedDriverNumber = 0;
self.cp.hasFoundCopyDriver = false;
self.cp.copyCourseFromDriver = nil;
courseplay:validateCanSwitchMode(self);
end;
end;
function courseplay.settings.add_folder_settings(folder)
folder.showChildren = false
folder.skipMe = false
end
function courseplay.settings.add_folder(input1, input2)
-- function might be called like add_folder(vehicle, id) or like add_folder(id)
local vehicle, id
if input2 ~= nil then
vehicle = input1
id = input2
else
vehicle = false
id = input1
end
if vehicle == false then
-- no vehicle given -> add folder to all vehicles
for k,v in pairs(g_currentMission.steerables) do
if v.cp ~= nil then -- alternative way to check if SpecializationUtil.hasSpecialization(courseplay, v.specializations)
v.cp.folder_settings[id] = {}
courseplay.settings.add_folder_settings(v.cp.folder_settings[id])
end
end
else
-- vehicle given -> add folder to that vehicle
vehicle.cp.folder_settings[id] = {}
courseplay.settings.add_folder_settings(vehicle.cp.folder_settings[id])
end
end
function courseplay.settings.update_folders(vehicle)
local old_settings
if vehicle == nil then
-- no vehicle given -> update all folders in all vehicles
for k,v in pairs(g_currentMission.steerables) do
if v.cp ~= nil then -- alternative way to check if SpecializationUtil.hasSpecialization(courseplay, v.specializations)
old_settings = v.cp.folder_settings
v.cp.folder_settings = {}
for _,f in pairs(g_currentMission.cp_folders) do
if old_settings[f.id] ~= nil then
v.cp.folder_settings[f.id] = old_settings[f.id]
else
v.cp.folder_settings[f.id] = {}
courseplay.settings.add_folder_settings(v.cp.folder_settings[f.id])
end
end
old_settings = nil
end
end
else
-- vehicle given -> update all folders in that vehicle
old_settings = vehicle.cp.folder_settings
vehicle.cp.folder_settings = {}
for _,f in pairs(g_currentMission.cp_folders) do
if old_settings[f.id] ~= nil then
vehicle.cp.folder_settings[f.id] = old_settings[f.id]
else
vehicle.cp.folder_settings[f.id] = {}
courseplay.settings.add_folder_settings(vehicle.cp.folder_settings[f.id])
end
end
end
old_settings = nil
end
function courseplay.settings.setReloadCourseItems(vehicle)
if vehicle ~= nil then
vehicle.cp.reloadCourseItems = true
courseplay.hud:setReloadPageOrder(vehicle, 2, true);
else
for k,v in pairs(g_currentMission.steerables) do
if v.cp ~= nil then -- alternative way to check if SpecializationUtil.hasSpecialization(courseplay, v.specializations)
v.cp.reloadCourseItems = true
courseplay.hud:setReloadPageOrder(v, 2, true);
end
end
end
end
function courseplay.settings.toggleFilter(vehicle, enable)
if enable and not vehicle.cp.hud.filterEnabled then
vehicle.cp.sorted = vehicle.cp.filtered;
vehicle.cp.hud.filterEnabled = true;
elseif not enable and vehicle.cp.hud.filterEnabled then
vehicle.cp.filtered = vehicle.cp.sorted;
vehicle.cp.sorted = g_currentMission.cp_sorted;
vehicle.cp.hud.filterEnabled = false;
end;
end;
function courseplay.hud.setCourses(self, start_index)
start_index = start_index or 1
if start_index < 1 then
start_index = 1
elseif start_index > #self.cp.sorted.item then
start_index = #self.cp.sorted.item
end
-- delete content of hud.courses
self.cp.hud.courses = {}
local index = start_index
local hudLines = courseplay.hud.numLines
local i = 1
if index == 1 and self.cp.hud.showZeroLevelFolder then
table.insert(self.cp.hud.courses, { id=0, uid=0, name='Level 0', displayname='Level 0', parent=0, type='folder', level=0})
i = 2 -- = i+1
end
-- is start_index even showed?
index = courseplay.courses.getMeOrBestFit(self, index)
if index ~= 0 then
-- insert first entry
table.insert(self.cp.hud.courses, self.cp.sorted.item[index])
i = i+1
-- now search for the next entries
while i <= hudLines do
index = courseplay.courses.getNextCourse(self,index)
if index == 0 then
-- no next item found: fill table with previous items and abort the loop
if start_index > 1 then
-- shift up
courseplay:shiftHudCourses(self, -(hudLines - i + 1))
end
i = hudLines+1 -- abort the loop
else
table.insert(self.cp.hud.courses, self.cp.sorted.item[index])
i = i + 1
end
end --while
end -- i<3
courseplay.hud:setReloadPageOrder(self, 2, true);
end
function courseplay.hud.reloadCourses(vehicle)
local index = 1
local i = 1
if vehicle ~= nil then
while i <= #vehicle.cp.hud.courses and vehicle.cp.sorted.info[ vehicle.cp.hud.courses[i].uid ] == nil do
i = i + 1
end
if i <= #vehicle.cp.hud.courses then
index = vehicle.cp.sorted.info[ vehicle.cp.hud.courses[i].uid ].sorted_index
end
courseplay.hud.setCourses(vehicle, index)
else
for k,v in pairs(g_currentMission.steerables) do
if v.cp ~= nil then -- alternative way to check if SpecializationUtil.hasSpecialization(courseplay, v.specializations)
i = 1
-- course/folder in the hud might have been deleted -> info no longer available
while i <= #v.cp.hud.courses and v.cp.sorted.info[ v.cp.hud.courses[i].uid ] == nil do
i = i + 1
end
if i > #v.cp.hud.courses then
index = 1
else
index = v.cp.sorted.info[ v.cp.hud.courses[i].uid ].sorted_index
end
courseplay.hud.setCourses(v,index)
end
end
end
end
function courseplay:shiftHudCourses(vehicle, change_by)
local hudLines = courseplay.hud.numLines
local index = hudLines
while change_by > 0 do
-- get the index of the last showed item
index = vehicle.cp.sorted.info[vehicle.cp.hud.courses[#(vehicle.cp.hud.courses)].uid].sorted_index
-- search for the next item
index = courseplay.courses.getNextCourse(vehicle,index)
if index == 0 then
-- there is no next item: abort
change_by = 0
else
if #(vehicle.cp.hud.courses) == hudLines then
-- remove first entry...
table.remove(vehicle.cp.hud.courses, 1)
end
-- ... and add one at the end
table.insert(vehicle.cp.hud.courses, vehicle.cp.sorted.item[index])
change_by = change_by - 1
end
end
while change_by < 0 do
-- get the index of the first showed item
index = vehicle.cp.sorted.info[vehicle.cp.hud.courses[1].uid].sorted_index
-- search reverse for the next item
index = courseplay.courses.getNextCourse(vehicle, index, true)
if index == 0 then
-- there is no next item: abort
change_by = 0
-- show LevelZeroFolder?
if vehicle.cp.hud.showZeroLevelFolder then
if #(vehicle.cp.hud.courses) >= hudLines then
-- remove last entry...
table.remove(vehicle.cp.hud.courses)
end
table.insert(vehicle.cp.hud.courses, 1, { id=0, uid=0, name='Level 0', displayname='Level 0', parent=0, type='folder', level=0})
end
else
if #(vehicle.cp.hud.courses) >= hudLines then
-- remove last entry...
table.remove(vehicle.cp.hud.courses)
end
-- ... and add one at the beginning:
table.insert(vehicle.cp.hud.courses, 1, vehicle.cp.sorted.item[index])
change_by = change_by + 1
end
end
courseplay.hud:setReloadPageOrder(vehicle, 2, true);
end
--Update all vehicles' course list arrow displays
function courseplay.settings.validateCourseListArrows(vehicle)
local n_courses = #(vehicle.cp.sorted.item)
local n_hudcourses, prev, next
if vehicle then
-- update vehicle only
prev = true
next = true
n_hudcourses = #(vehicle.cp.hud.courses)
if not (n_hudcourses > 0) then
prev = false
next = false
else
-- update prev
if vehicle.cp.hud.showZeroLevelFolder then
if vehicle.cp.hud.courses[1].uid == 0 then
prev = false
end
elseif vehicle.cp.sorted.info[ vehicle.cp.hud.courses[1].uid ].sorted_index == 1 then
prev = false
end
-- update next
if n_hudcourses < courseplay.hud.numLines then
next = false
elseif vehicle.cp.hud.showZeroLevelFolder and vehicle.cp.hud.courses[n_hudcourses].uid == 0 then
next = false
elseif 0 == courseplay.courses.getNextCourse(vehicle, vehicle.cp.sorted.info[ vehicle.cp.hud.courses[n_hudcourses].uid ].sorted_index) then
next = false
end
end
vehicle.cp.hud.courseListPrev = prev
vehicle.cp.hud.courseListNext = next
else
-- update all vehicles
for k,v in pairs(g_currentMission.steerables) do
if v.cp ~= nil then -- alternative way to check if SpecializationUtil.hasSpecialization(courseplay, v.specializations)
prev = true
next = true
n_hudcourses = #(v.cp.hud.courses)
if not (n_hudcourses > 0) then
prev = false
next = false
else
-- update prev
if v.cp.hud.showZeroLevelFolder then
if v.cp.hud.courses[1].uid == 0 then
prev = false
end
elseif v.cp.sorted.info[v.cp.hud.courses[1].uid].sorted_index == 1 then
prev = false
end
-- update next
if n_hudcourses < coursplay.hud.numLines then
next = false
elseif 0 == courseplay.courses.getNextCourse(v, v.cp.sorted.info[v.cp.hud.courses[n_hudcourses].uid].sorted_index) then
next = false
end
end
v.cp.hud.courseListPrev = prev
v.cp.hud.courseListNext = next
end -- if hasSpecialization
end -- in pairs(steerables)
end -- if vehicle
end;
function courseplay:expandFolder(vehicle, index)
-- expand/reduce a folder in the hud
if vehicle.cp.hud.courses[index].type == 'folder' then
local f = vehicle.cp.folder_settings[ vehicle.cp.hud.courses[index].id ]
f.showChildren = not f.showChildren
if f.showChildren then
-- from not showing to showing -> put it on top to see as much of the content as possible
courseplay.hud.setCourses(vehicle, vehicle.cp.sorted.info[vehicle.cp.hud.courses[index].uid].sorted_index)
else
-- from showing to not showing -> stay where it was
courseplay.hud.reloadCourses(vehicle)
end
end
end
function courseplay:change_num_ai_helpers(self, change_by)
local num_helpers = g_currentMission.maxNumHirables
num_helpers = num_helpers + change_by
if num_helpers < 1 then
num_helpers = 1
end
g_currentMission.maxNumHirables = num_helpers
end
function courseplay:change_DebugLevel(self, change_by)
courseplay.debugLevel = courseplay.debugLevel + change_by;
if courseplay.debugLevel > 4 then
courseplay.debugLevel = 0;
end;
end;
function courseplay:toggleDebugChannel(self, channel)
if courseplay.debugChannels[channel] ~= nil then
courseplay.debugChannels[channel] = not courseplay.debugChannels[channel];
courseplay:buttonsActiveEnabled(self, "debug");
end;
end;
--Course generation
function courseplay:switchStartingCorner(self)
self.cp.startingCorner = self.cp.startingCorner + 1;
if self.cp.startingCorner > 4 then
self.cp.startingCorner = 1;
end;
self.cp.hasStartingCorner = true;
self.cp.hasStartingDirection = false;
self.cp.startingDirection = 0;
courseplay:validateCourseGenerationData(self);
end;
function courseplay:switchStartingDirection(self)
-- corners: 1 = SW, 2 = NW, 3 = NE, 4 = SE
-- directions: 1 = North, 2 = East, 3 = South, 4 = West
local validDirections = {};
if self.cp.hasStartingCorner then
if self.cp.startingCorner == 1 then --SW
validDirections[1] = 1; --N
validDirections[2] = 2; --E
elseif self.cp.startingCorner == 2 then --NW
validDirections[1] = 2; --E
validDirections[2] = 3; --S
elseif self.cp.startingCorner == 3 then --NE
validDirections[1] = 3; --S
validDirections[2] = 4; --W
elseif self.cp.startingCorner == 4 then --SE