forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.lua
1517 lines (1331 loc) · 62.1 KB
/
base.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
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
local floor = math.floor;
function courseplay.prerequisitesPresent(specializations)
return true;
end
--[[
function courseplay:preLoad(xmlFile)
end;
]]
function courseplay:load(savegame)
local xmlFile = self.xmlFile;
self.setCourseplayFunc = courseplay.setCourseplayFunc;
self.getIsCourseplayDriving = courseplay.getIsCourseplayDriving;
self.setIsCourseplayDriving = courseplay.setIsCourseplayDriving;
self.setCpVar = courseplay.setCpVar;
--SEARCH AND SET self.name IF NOT EXISTING
if self.name == nil then
self.name = courseplay:getObjectName(self, xmlFile);
end;
if self.cp == nil then self.cp = {}; end;
self.hasCourseplaySpec = true;
self.cp.varMemory = {};
-- XML FILE NAME VARIABLE
if self.cp.xmlFileName == nil then
self.cp.xmlFileName = courseplay.utils:getFileNameFromPath(self.configFileName);
end;
courseplay:setNameVariable(self);
self.cp.isCombine = courseplay:isCombine(self);
self.cp.isChopper = courseplay:isChopper(self);
self.cp.isHarvesterSteerable = courseplay:isHarvesterSteerable(self);
self.cp.isSugarBeetLoader = courseplay:isSpecialCombine(self, "sugarBeetLoader");
if self.cp.isCombine then
self.cp.mode7Unloading = false
self.cp.mode7makeHeaps = false
self.cp.driverPriorityUseFillLevel = false;
end
self.cp.stopWhenUnloading = false;
-- GIANT DLC
self.cp.haveInversedRidgeMarkerState = nil; --bool
--turn maneuver
self.cp.waitForTurnTime = 0.00 --float
self.cp.turnStage = 0 --int
self.cp.aiTurnNoBackward = false --bool
self.cp.canBeReversed = nil --bool
self.cp.backMarkerOffset = nil --float
self.cp.aiFrontMarker = nil --float
self.cp.turnTimer = 8000 --int
self.cp.noStopOnEdge = false --bool
self.cp.noStopOnTurn = false --bool
self.cp.combineOffsetAutoMode = true
self.cp.isDriving = false;
self.cp.runOnceStartCourse = false;
self.cp.stopAtEnd = false;
self.cp.stopAtEndMode1 = false;
self.cp.calculatedCourseToCombine = false
self.cp.waypointIndex = 1;
self.cp.previousWaypointIndex = 1;
self.cp.recordingTimer = 1
self.timer = 0.00
self.cp.timers = {};
self.cp.driveSlowTimer = 0;
self.cp.positionWithCombine = nil;
-- RECORDING
self.cp.isRecording = false;
self.cp.recordingIsPaused = false;
self.cp.isRecordingTurnManeuver = false;
self.cp.drivingDirReverse = false;
self.cp.waitPoints = {};
self.cp.numWaitPoints = 0;
self.cp.waitTime = 0;
self.cp.crossingPoints = {};
self.cp.numCrossingPoints = 0;
self.cp.visualWaypointsStartEnd = true;
self.cp.visualWaypointsAll = false;
self.cp.visualWaypointsCrossing = false;
self.cp.warningLightsMode = 1;
self.cp.hasHazardLights = self.turnSignalState ~= nil and self.setTurnSignalState ~= nil;
-- saves the shortest distance to the next waypoint (for recocnizing circling)
self.cp.shortestDistToWp = nil
self.Waypoints = {}
self.cp.isEntered = false
self.cp.remoteIsEntered = false
self.cp.canDrive = false --can drive course (has >4 waypoints, is not recording)
self.cp.coursePlayerNum = nil;
self.cp.infoText = nil; -- info text in tractor
self.cp.toolTip = nil;
-- global info text - also displayed when not in vehicle
self.cp.hasSetGlobalInfoTextThisLoop = {};
self.cp.activeGlobalInfoTexts = {};
self.cp.numActiveGlobalInfoTexts = 0;
-- CP mode
self.cp.mode = 5;
courseplay:setNextPrevModeVars(self);
self.cp.modeState = 0
self.cp.mode2nextState = nil;
self.cp.startWork = nil
self.cp.stopWork = nil
self.cp.abortWork = nil
self.cp.abortWorkExtraMoveBack = 0;
self.cp.hasUnloadingRefillingCourse = false;
self.cp.hasTransferCourse = false
self.cp.wait = true;
self.cp.waitTimer = nil;
self.cp.realisticDriving = true;
self.cp.canSwitchMode = false;
self.cp.siloSelectedFillType = FillUtil.FILLTYPE_UNKNOWN;
self.cp.siloSelectedEasyFillType = 1;
self.cp.turnOnField = true;
self.cp.slippingStage = 0;
self.cp.isTipping = false;
self.cp.hasPlough = false;
self.cp.hasRotateablePlough = false;
self.cp.startAtPoint = courseplay.START_AT_NEAREST_POINT;
-- ai mode 9: shovel
self.cp.shovelEmptyPoint = nil;
self.cp.shovelFillStartPoint = nil;
self.cp.shovelFillEndPoint = nil;
self.cp.shovelState = 1;
self.cp.shovel = {};
self.cp.shovelStopAndGo = false;
self.cp.shovelLastFillLevel = nil;
self.cp.shovelStatePositions = {};
self.cp.hasShovelStatePositions = {};
self.cp.manualShovelPositionOrder = nil;
for i=2,5 do
self.cp.hasShovelStatePositions[i] = false;
end;
-- Visual i3D waypoint signs
self.cp.signs = {
crossing = {};
current = {};
};
courseplay.signs:updateWaypointSigns(self);
self.cp.numCourses = 1;
self.cp.numWaypoints = 0;
self.cp.currentCourseName = nil;
self.cp.currentCourseId = 0;
self.cp.lastMergedWP = 0;
self.cp.loadedCourses = {}
-- forced waypoints
self.cp.curTarget = {};
self.cp.curTargetMode7 = {};
self.cp.nextTargets = {};
self.cp.turnTargets = {};
self.cp.curTurnIndex = 1;
-- speed limits
self.cp.speeds = {
useRecordingSpeed = true;
reverse = 6;
turn = 10;
field = 24;
street = self.cruiseControl.maxSpeed or 50;
crawl = 3;
discharge = 8;
minReverse = 3;
minTurn = 3;
minField = 3;
minStreet = 3;
max = self.cruiseControl.maxSpeed or 60;
};
self.cp.tooIsDirty = false
self.cp.orgRpm = nil;
-- data basis for the Course list
self.cp.reloadCourseItems = true
self.cp.sorted = {item={}, info={}}
self.cp.folder_settings = {}
courseplay.settings.update_folders(self)
--aiTrafficCollisionTrigger
if self.aiTrafficCollisionTrigger == nil then
local index = getXMLString(xmlFile, "vehicle.aiTrafficCollisionTrigger#index");
if index then
local triggerObject = Utils.indexToObject(self.components, index);
if triggerObject then
self.aiTrafficCollisionTrigger = triggerObject;
end;
end;
else
CpManager.trafficCollisionIgnoreList[self.aiTrafficCollisionTrigger] = true; --add AI traffic collision trigger to global ignore list
end;
if self.aiTrafficCollisionTrigger == nil and getNumOfChildren(self.rootNode) > 0 then
if getChild(self.rootNode, "trafficCollisionTrigger") ~= 0 then
self.aiTrafficCollisionTrigger = getChild(self.rootNode, "trafficCollisionTrigger");
else
for i=0,getNumOfChildren(self.rootNode)-1 do
local child = getChildAt(self.rootNode, i);
if getChild(child, "trafficCollisionTrigger") ~= 0 then
self.aiTrafficCollisionTrigger = getChild(child, "trafficCollisionTrigger");
break;
end;
end;
end;
end;
if self.aiTrafficCollisionTrigger == nil then
print(string.format('## Courseplay: %s: aiTrafficCollisionTrigger missing. Traffic collision prevention will not work!', nameNum(self)));
end;
-- DIRECTION NODE SETUP
local DirectionNode;
if self.aiVehicleDirectionNode ~= nil then
if self.cp.componentNumAsDirectionNode then
DirectionNode = self.components[self.cp.componentNumAsDirectionNode].node;
else
DirectionNode = self.aiVehicleDirectionNode;
end;
else
if courseplay:isWheelloader(self)then
if self.cp.hasSpecializationArticulatedAxis then
local nodeIndex = Utils.getNoNil(self.cp.componentNumAsDirectionNode, 2)
if self.components[nodeIndex] ~= nil then
DirectionNode = self.components[nodeIndex].node;
end
end;
end
if DirectionNode == nil then
DirectionNode = self.rootNode;
end
end;
if self.cp.directionNodeZOffset and self.cp.directionNodeZOffset ~= 0 then
self.cp.oldDirectionNode = DirectionNode; -- Only used for debugging.
DirectionNode = courseplay:createNewLinkedNode(self, "realDirectionNode", DirectionNode);
setTranslation(DirectionNode, 0, 0, self.cp.directionNodeZOffset);
end;
self.cp.DirectionNode = DirectionNode;
-- TRIGGERS
self.findTipTriggerCallback = courseplay.findTipTriggerCallback;
self.findSpecialTriggerCallback = courseplay.findSpecialTriggerCallback;
self.cp.hasRunRaycastThisLoop = {};
self.findTrafficCollisionCallback = courseplay.findTrafficCollisionCallback;
self.findBlockingObjectCallbackLeft = courseplay.findBlockingObjectCallbackLeft;
self.findBlockingObjectCallbackRight = courseplay.findBlockingObjectCallbackRight;
self.findVehicleHeights = courseplay.findVehicleHeights;
-- traffic collision
self.cpOnTrafficCollisionTrigger = courseplay.cpOnTrafficCollisionTrigger;
self.cp.steeringAngle = Utils.getNoNil(math.deg(self.maxRotation), 30);
if self.cp.steeringAngleCorrection then
self.cp.steeringAngle = Utils.getNoNil(self.cp.steeringAngleCorrection, self.cp.steeringAngle);
elseif self.cp.steeringAngleMultiplier then
self.cp.steeringAngle = self.cp.steeringAngle * self.cp.steeringAngleMultiplier;
end;
self.cp.tempCollis = {}
self.CPnumCollidingVehicles = 0;
self.cpTrafficCollisionIgnoreList = {};
self.cp.TrafficBrake = false
self.cp.inTraffic = false
if self.trafficCollisionIgnoreList == nil then
self.trafficCollisionIgnoreList = {}
end
if self.numCollidingVehicles == nil then
self.numCollidingVehicles = {};
end
self.cp.numTrafficCollisionTriggers = 0;
self.cp.trafficCollisionTriggers = {};
self.cp.trafficCollisionTriggerToTriggerIndex = {};
self.cp.collidingObjects = {
all = {};
};
self.cp.numCollidingObjects = {
all = 0;
};
if self.aiTrafficCollisionTrigger ~= nil then
self.cp.numTrafficCollisionTriggers = 4;
for i=1,self.cp.numTrafficCollisionTriggers do
local newTrigger = clone(self.aiTrafficCollisionTrigger, true);
self.cp.trafficCollisionTriggers[i] = newTrigger
if i > 1 then
unlink(newTrigger);
link(self.cp.trafficCollisionTriggers[i-1], newTrigger);
setTranslation(newTrigger, 0,0,5);
end;
addTrigger(newTrigger, 'cpOnTrafficCollisionTrigger', self);
self.cp.trafficCollisionTriggerToTriggerIndex[newTrigger] = i;
CpManager.trafficCollisionIgnoreList[newTrigger] = true; --add all traffic collision triggers to global ignore list
self.cp.collidingObjects[i] = {};
self.cp.numCollidingObjects[i] = 0;
end;
end;
if not CpManager.trafficCollisionIgnoreList[g_currentMission.terrainRootNode] then
CpManager.trafficCollisionIgnoreList[g_currentMission.terrainRootNode] = true;
end;
courseplay:askForSpecialSettings(self,self)
courseplay:setOwnFillLevelsAndCapacities(self)
-- workTools
self.cp.workTools = {};
self.cp.numWorkTools = 0;
self.cp.workToolAttached = false;
self.cp.currentTrailerToFill = nil;
self.cp.trailerFillDistance = nil;
self.cp.isUnloaded = false;
self.cp.isLoaded = false;
self.cp.totalFillLevel = nil;
self.cp.totalCapacity = nil;
self.cp.totalFillLevelPercent = 0;
self.cp.prevFillLevelPct = nil;
self.cp.tipRefOffset = 0;
self.cp.isReverseBGATipping = nil; -- Used for reverse BGA tipping
self.cp.isBGATipping = false; -- Used for BGA tipping
self.cp.BGASectionInverted = false; -- Used for BGA tipping
self.cp.inversedRearTipNode = nil; -- Used for BGA tipping
self.cp.tipperHasCover = false;
self.cp.tippersWithCovers = {};
self.cp.automaticCoverHandling = true;
-- combines
self.cp.reachableCombines = {};
self.cp.activeCombine = nil;
self.cp.offset = nil --self = combine [flt]
self.cp.combineOffset = 0.0
self.cp.tipperOffset = 0.0
self.cp.forcedSide = nil
self.cp.forcedToStop = false
self.cp.allowFollowing = false
self.cp.followAtFillLevel = 50
self.cp.driveOnAtFillLevel = 90
self.cp.refillUntilPct = 100;
self.cp.vehicleTurnRadius = courseplay:getVehicleTurnRadius(self);
self.cp.turnDiameter = self.cp.vehicleTurnRadius * 2;
self.cp.turnDiameterAuto = self.cp.vehicleTurnRadius * 2;
self.cp.turnDiameterAutoMode = true;
--Offset
self.cp.laneOffset = 0;
self.cp.toolOffsetX = 0;
self.cp.toolOffsetZ = 0;
self.cp.totalOffsetX = 0;
self.cp.symmetricLaneChange = false;
self.cp.switchLaneOffset = false;
self.cp.switchToolOffset = false;
self.cp.workWidth = 3
self.cp.searchCombineAutomatically = true;
self.cp.savedCombine = nil
self.cp.selectedCombineNumber = 0
self.cp.searchCombineOnField = 0;
--Copy course
self.cp.hasFoundCopyDriver = false;
self.cp.copyCourseFromDriver = nil;
self.cp.selectedDriverNumber = 0;
--Course generation
self.cp.startingCorner = 0;
self.cp.hasStartingCorner = false;
self.cp.startingDirection = 0;
self.cp.hasStartingDirection = false;
self.cp.returnToFirstPoint = false;
self.cp.hasGeneratedCourse = false;
self.cp.hasValidCourseGenerationData = false;
self.cp.ridgeMarkersAutomatic = true;
self.cp.headland = {
maxNumLanes = 6;
numLanes = 0;
userDirClockwise = true;
orderBefore = true;
tg = createTransformGroup('cpPointOrig_' .. tostring(self.rootNode));
rectWidthRatio = 1.25;
noGoWidthRatio = 0.975;
minPointDistance = 0.5;
maxPointDistance = 7.25;
};
link(getRootNode(), self.cp.headland.tg);
if CpManager.isDeveloper then
self.cp.headland.maxNumLanes = 50;
end;
self.cp.fieldEdge = {
selectedField = {
fieldNum = 0;
numPoints = 0;
buttonsCreated = false;
};
customField = {
points = nil;
numPoints = 0;
isCreated = false;
show = false;
fieldNum = 0;
selectedFieldNumExists = false;
};
};
-- WOOD CUTTING: increase max cut length
if CpManager.isDeveloper then
self.cutLengthMax = 15;
self.cutLengthStep = 1;
end;
self.cp.mouseCursorActive = false;
-- 2D course
self.cp.drawCourseMode = courseplay.COURSE_2D_DISPLAY_OFF;
-- 2D pda map background -- TODO: MP?
if g_currentMission.ingameMap and g_currentMission.ingameMap.mapOverlay and g_currentMission.ingameMap.mapOverlay.filename then
self.cp.course2dPdaMapOverlay = Overlay:new('cpPdaMap', g_currentMission.ingameMap.mapOverlay.filename, 0, 0, 1, 1);
self.cp.course2dPdaMapOverlay:setColor(1, 1, 1, CpManager.course2dPdaMapOpacity);
end;
-- HUD
courseplay.hud:setupVehicleHud(self);
courseplay:validateCanSwitchMode(self);
courseplay.buttons:setActiveEnabled(self, 'all');
end;
function courseplay:postLoad(savegame)
if savegame ~= nil and savegame.key ~= nil and not savegame.resetVehicles then
courseplay.loadVehicleCPSettings(self, savegame.xmlFile, savegame.key, savegame.resetVehicles)
end
-- Drive Control (upsidedown)
if self.driveControl ~= nil and g_currentMission.driveControl ~= nil then
self.cp.hasDriveControl = true;
self.cp.driveControl = {
hasFourWD = g_currentMission.driveControl.useModules.fourWDandDifferentials and not self.driveControl.fourWDandDifferentials.isSurpressed;
hasHandbrake = g_currentMission.driveControl.useModules.handBrake;
hasManualMotorStart = g_currentMission.driveControl.useModules.manMotorStart;
hasMotorKeepTurnedOn = g_currentMission.driveControl.useModules.manMotorKeepTurnedOn;
hasShuttleMode = g_currentMission.driveControl.useModules.shuttle;
alwaysUseFourWD = false;
};
-- add "always use 4WD" button
if self.cp.driveControl.hasFourWD then
courseplay.button:new(self, 7, nil, 'toggleAlwaysUseFourWD', nil, courseplay.hud.col1posX, courseplay.hud.linesPosY[5], courseplay.hud.contentMaxWidth, 0.015, 5, nil, true);
end;
end;
end;
function courseplay:onLeave()
if self.cp.mouseCursorActive then
courseplay:setMouseCursor(self, false);
end
--hide visual i3D waypoint signs when not in vehicle
courseplay.signs:setSignsVisibility(self, true);
end
function courseplay:onEnter()
if self.cp.mouseCursorActive then
courseplay:setMouseCursor(self, true);
end;
if self:getIsCourseplayDriving() and self.steeringEnabled then
self.steeringEnabled = false;
end;
--show visual i3D waypoint signs only when in vehicle
courseplay.signs:setSignsVisibility(self);
end
function courseplay:draw()
local isDriving = self:getIsCourseplayDriving();
--WORKWIDTH DISPLAY
if self.cp.mode ~= 7 and self.cp.timers.showWorkWidth and self.cp.timers.showWorkWidth > 0 then
if courseplay:timerIsThrough(self, 'showWorkWidth') then -- stop showing, reset timer
courseplay:resetCustomTimer(self, 'showWorkWidth');
else -- timer running, show
courseplay:showWorkWidth(self);
end;
end;
--DEBUG Speed Setting
if courseplay.debugChannels[21] then
renderText(0.2, 0.105, 0.02, string.format("mode%d rn: %d",self.cp.mode,self.cp.waypointIndex));
renderText(0.2, 0.075, 0.02, self.cp.speedDebugLine);
if self.cp.speedDebugStreet then
local mode = "max"
local speed = self.cp.speeds.street
if self.cp.speeds.useRecordingSpeed then
mode = "wpt"
if self.Waypoints and self.Waypoints[self.cp.waypointIndex] and self.Waypoints[self.cp.waypointIndex].speed then
speed = self.Waypoints[self.cp.waypointIndex].speed
else
speed = "no speed"
end
end
renderText(0.2, 0.045, 0.02, string.format("mode[%s] speed: %s",mode,tostring(speed)));
end
if (self.cp.mode == 2 or self.cp.mode ==3) and self.cp.activeCombine ~= nil then
local combine = self.cp.activeCombine
renderText(0.2,0.255,0.02,string.format("combine.lastSpeedReal: %.6f ",combine.lastSpeedReal*3600))
renderText(0.2,0.225,0.02,"combine.turnStage: "..combine.turnStage)
renderText(0.2,0.195,0.02,"combine.cp.turnStage: "..combine.cp.turnStage)
renderText(0.2,0.165,0.02,"combine.acTurnStage: "..combine.acTurnStage)
renderText(0.2,0.135,0.02,"combineIsTurning: "..tostring(self.cp.mode2DebugTurning ))
end
end
if courseplay.debugChannels[10] and self.cp.BunkerSiloMap ~= nil and self.cp.actualTarget ~= nil then
local fillUnit = self.cp.BunkerSiloMap[self.cp.actualTarget.line][self.cp.actualTarget.column]
--print(string.format("fillUnit %s; self.cp.actualTarget.line %s; self.cp.actualTarget.column %s",tostring(fillUnit),tostring(self.cp.actualTarget.line),tostring(self.cp.actualTarget.column)))
local sx,sz = fillUnit.sx,fillUnit.sz
local wx,wz = fillUnit.wx,fillUnit.wz
local hx,hz = fillUnit.hx +(fillUnit.wx-fillUnit.sx) ,fillUnit.hz +(fillUnit.wz-fillUnit.sz)
local y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, sx, 1, sz)+0.5;
drawDebugLine(sx, y, sz, 1, 0, 0, wx, y, wz, 1, 0, 0);
drawDebugLine(wx, y, wz, 1, 0, 0, hx, y, hz, 1, 0, 0);
drawDebugLine(fillUnit.hx, y, fillUnit.hz, 1, 0, 0, sx, y, sz, 1, 0, 0);
drawDebugPoint(fillUnit.cx, y, fillUnit.cz, 1, 1 , 1, 1);
renderText(0.2,0.225,0.02,"unit.fillLevel: "..tostring(fillUnit.fillLevel))
if self.cp.mode9SavedLastFillLevel ~= nil then
renderText(0.2,0.195,0.02,"SavedLastFillLevel: "..tostring(self.cp.mode9SavedLastFillLevel))
renderText(0.2,0.165,0.02,"triesTheSameFillUnit: "..tostring(self.cp.mode9triesTheSameFillUnit))
end
end
--DEBUG SHOW DIRECTIONNODE
if courseplay.debugChannels[12] then
-- For debugging when setting the directionNodeZOffset. (Visual points shown for old node)
-- In specialTools.lua -> courseplay:setNameVariable(workTool), add the value "workTool.cp.showDirectionNode = true;" to the specific vehicle, while testing.
if self.cp.oldDirectionNode and self.cp.showDirectionNode then
local ox,oy,oz = getWorldTranslation(self.cp.oldDirectionNode);
drawDebugPoint(ox, oy+4, oz, 0.9098, 0.6902 , 0.2706, 1);
end;
local nx,ny,nz = getWorldTranslation(self.cp.DirectionNode);
drawDebugPoint(nx, ny+4, nz, 0.6196, 0.3490 , 0, 1);
end;
-- HELP BUTTON TEXTS
if self:getIsActive() and self.isEntered and g_currentMission.showHelpText then
local modifierPressed = InputBinding.isPressed(InputBinding.COURSEPLAY_MODIFIER);
if (self.cp.canDrive or not self.cp.hud.openWithMouse) and not modifierPressed then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_FUNCTIONS'), InputBinding.COURSEPLAY_MODIFIER);
end;
if self.cp.hud.show then
if self.cp.mouseCursorActive then
g_currentMission:addHelpTextFunction(CpManager.drawMouseButtonHelp, self, CpManager.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_HIDE'));
else
g_currentMission:addHelpTextFunction(CpManager.drawMouseButtonHelp, self, CpManager.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_SHOW'));
end;
end;
if self.cp.hud.openWithMouse then
if not self.cp.hud.show then
g_currentMission:addHelpTextFunction(CpManager.drawMouseButtonHelp, self, CpManager.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_HUD_OPEN'));
end;
else
if modifierPressed then
if not self.cp.hud.show then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_HUD_OPEN'), InputBinding.COURSEPLAY_HUD);
else
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_HUD_CLOSE'), InputBinding.COURSEPLAY_HUD);
end;
end;
end;
if modifierPressed then
if self.cp.canDrive then
if isDriving then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_STOP_COURSE'), InputBinding.COURSEPLAY_START_STOP);
if self.cp.HUD1wait then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_CONTINUE'), InputBinding.COURSEPLAY_CANCELWAIT);
end;
if self.cp.HUD1noWaitforFill then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_DRIVE_NOW'), InputBinding.COURSEPLAY_DRIVENOW);
end;
else
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_START_COURSE'), InputBinding.COURSEPLAY_START_STOP);
end;
else
if not self.cp.isRecording and not self.cp.recordingIsPaused and self.cp.numWaypoints == 0 then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_RECORDING_START'), InputBinding.COURSEPLAY_START_STOP);
elseif self.cp.isRecording and not self.cp.recordingIsPaused and not self.cp.isRecordingTurnManeuver then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_RECORDING_STOP'), InputBinding.COURSEPLAY_START_STOP);
end;
end;
if self.cp.canSwitchMode then
if self.cp.nextMode then
g_currentMission:addHelpButtonText(courseplay:loc('input_COURSEPLAY_NEXTMODE'), InputBinding.COURSEPLAY_NEXTMODE);
end;
if self.cp.prevMode then
g_currentMission:addHelpButtonText(courseplay:loc('input_COURSEPLAY_PREVMODE'), InputBinding.COURSEPLAY_PREVMODE);
end;
end;
end;
end;
if self:getIsActive() then
if self.cp.hud.show then
courseplay.hud:setContent(self);
courseplay.hud:renderHud(self);
if self.cp.distanceCheck and (isDriving or (not self.cp.canDrive and not self.cp.isRecording and not self.cp.recordingIsPaused)) then -- turn off findFirstWaypoint when driving or no course loaded
courseplay:toggleFindFirstWaypoint(self);
end;
if self.cp.mouseCursorActive then
InputBinding.setShowMouseCursor(self.cp.mouseCursorActive);
end;
end;
if self.cp.distanceCheck and self.cp.numWaypoints > 1 then
courseplay:distanceCheck(self);
end;
if self.isEntered and self.cp.toolTip ~= nil then
courseplay:renderToolTip(self);
end;
end;
--RENDER
courseplay:renderInfoText(self);
if self.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_2DONLY or self.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_BOTH then
courseplay:drawCourse2D(self, false);
end;
end; --END draw()
function courseplay:showWorkWidth(vehicle)
local offsX, offsZ = vehicle.cp.toolOffsetX or 0, vehicle.cp.toolOffsetZ or 0;
local left = (vehicle.cp.workWidth * 0.5) + offsX;
local right = (vehicle.cp.workWidth * -0.5) + offsX;
if vehicle.cp.DirectionNode and vehicle.cp.backMarkerOffset and vehicle.cp.aiFrontMarker then
local p1x, p1y, p1z = localToWorld(vehicle.cp.DirectionNode, left, 1.6, vehicle.cp.backMarkerOffset - offsZ);
local p2x, p2y, p2z = localToWorld(vehicle.cp.DirectionNode, right, 1.6, vehicle.cp.backMarkerOffset - offsZ);
local p3x, p3y, p3z = localToWorld(vehicle.cp.DirectionNode, right, 1.6, vehicle.cp.aiFrontMarker - offsZ);
local p4x, p4y, p4z = localToWorld(vehicle.cp.DirectionNode, left, 1.6, vehicle.cp.aiFrontMarker - offsZ);
drawDebugPoint(p1x, p1y, p1z, 1, 1, 0, 1);
drawDebugPoint(p2x, p2y, p2z, 1, 1, 0, 1);
drawDebugPoint(p3x, p3y, p3z, 1, 1, 0, 1);
drawDebugPoint(p4x, p4y, p4z, 1, 1, 0, 1);
drawDebugLine(p1x, p1y, p1z, 1, 0, 0, p2x, p2y, p2z, 1, 0, 0);
drawDebugLine(p2x, p2y, p2z, 1, 0, 0, p3x, p3y, p3z, 1, 0, 0);
drawDebugLine(p3x, p3y, p3z, 1, 0, 0, p4x, p4y, p4z, 1, 0, 0);
drawDebugLine(p4x, p4y, p4z, 1, 0, 0, p1x, p1y, p1z, 1, 0, 0);
else
local lX, lY, lZ = localToWorld(vehicle.rootNode, left, 1.6, -6 - offsZ);
local rX, rY, rZ = localToWorld(vehicle.rootNode, right, 1.6, -6 - offsZ);
drawDebugPoint(lX, lY, lZ, 1, 1, 0, 1);
drawDebugPoint(rX, rY, rZ, 1, 1, 0, 1);
drawDebugLine(lX, lY, lZ, 1, 0, 0, rX, rY, rZ, 1, 0, 0);
end;
end;
function courseplay:drawWaypointsLines(vehicle)
if not CpManager.isDeveloper or not vehicle.isControlled or vehicle ~= g_currentMission.controlledVehicle then return; end;
local height = 2.5;
local r,g,b,a;
for i,wp in pairs(vehicle.Waypoints) do
if wp.cy == nil or wp.cy == 0 then
wp.cy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, wp.cx, 1, wp.cz);
end;
local np = vehicle.Waypoints[i+1];
if np and (np.cy == nil or np.cy == 0) then
np.cy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, np.cx, 1, np.cz);
end;
if i == 1 or wp.turnStart then
r,g,b,a = 0, 1, 0, 1;
elseif i == vehicle.cp.numWaypoints or wp.turnEnd then
r,g,b,a = 1, 0, 0, 1;
elseif i == vehicle.cp.waypointIndex then
r,g,b,a = 0.9, 0, 0.6, 1;
else
r,g,b,a = 1, 1, 0, 1;
end;
drawDebugPoint(wp.cx, wp.cy + height, wp.cz, r,g,b,a);
if i < vehicle.cp.numWaypoints then
if i + 1 == vehicle.cp.waypointIndex then
drawDebugLine(wp.cx, wp.cy + height, wp.cz, 0.9, 0, 0.6, np.cx, np.cy + height, np.cz, 1, 0.4, 0.05);
else
drawDebugLine(wp.cx, wp.cy + height, wp.cz, 0, 1, 1, np.cx, np.cy + height, np.cz, 0, 1, 1);
end;
end;
end;
end;
function courseplay:update(dt)
-- KEYBOARD EVENTS
if self:getIsActive() and self.isEntered and InputBinding.isPressed(InputBinding.COURSEPLAY_MODIFIER) then
if InputBinding.hasEvent(InputBinding.COURSEPLAY_START_STOP) then
if self.cp.canDrive then
if self.cp.isDriving then
self:setCourseplayFunc('stop', nil, false, 1);
else
self:setCourseplayFunc('start', nil, false, 1);
end;
else
if not self.cp.isRecording and not self.cp.recordingIsPaused and self.cp.numWaypoints == 0 then
self:setCourseplayFunc('start_record', nil, false, 1);
elseif self.cp.isRecording and not self.cp.recordingIsPaused and not self.cp.isRecordingTurnManeuver then
self:setCourseplayFunc('stop_record', nil, false, 1);
end;
end;
elseif InputBinding.hasEvent(InputBinding.COURSEPLAY_CANCELWAIT) and self.cp.HUD1wait and self.cp.canDrive and self.cp.isDriving then
self:setCourseplayFunc('cancelWait', true, false, 1);
elseif InputBinding.hasEvent(InputBinding.COURSEPLAY_DRIVENOW) and self.cp.HUD1noWaitforFill and self.cp.canDrive and self.cp.isDriving then
self:setCourseplayFunc('setIsLoaded', true, false, 1);
elseif self.cp.canSwitchMode and self.cp.nextMode and InputBinding.hasEvent(InputBinding.COURSEPLAY_NEXTMODE) then
self:setCourseplayFunc('setCpMode', self.cp.nextMode, false, 1);
elseif self.cp.canSwitchMode and self.cp.prevMode and InputBinding.hasEvent(InputBinding.COURSEPLAY_PREVMODE) then
self:setCourseplayFunc('setCpMode', self.cp.prevMode, false, 1);
end;
if not self.cp.openHudWithMouse and InputBinding.hasEvent(InputBinding.COURSEPLAY_HUD) then
self:setCourseplayFunc('openCloseHud', not self.cp.hud.show, true);
end;
end; -- self:getIsActive() and self.isEntered and modifierPressed
if not self.cp.remoteIsEntered then
if self.cp.isEntered ~= self.isEntered then
CourseplayEvent.sendEvent(self, "self.cp.remoteIsEntered",self.isEntered)
end
self:setCpVar('isEntered',self.isEntered)
end
if not courseplay.isClient then -- and self.cp.infoText ~= nil then --(self.cp.isDriving or self.cp.isRecording or self.cp.recordingIsPaused) then
if self.cp.infoText == nil and not self.cp.infoTextNilSent then
CourseplayEvent.sendEvent(self, "self.cp.infoText",nil)
self.cp.infoTextNilSent = true
elseif self.cp.infoText ~= nil then
self.cp.infoText = nil
end
end;
if CpManager.isDeveloper and (self.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_DBGONLY or self.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_BOTH) then
courseplay:drawWaypointsLines(self);
end;
-- we are in record mode
if self.cp.isRecording then
courseplay:record(self);
end;
-- we are in drive mode and single player /MP server
if self.cp.isDriving and g_server ~= nil then
for refIdx,_ in pairs(CpManager.globalInfoText.msgReference) do
self.cp.hasSetGlobalInfoTextThisLoop[refIdx] = false;
end;
courseplay:drive(self, dt);
for refIdx,_ in pairs(self.cp.activeGlobalInfoTexts) do
if not self.cp.hasSetGlobalInfoTextThisLoop[refIdx] then
CpManager:setGlobalInfoText(self, refIdx, true); --force remove
end;
end;
end
if self.cp.onSaveClick and not self.cp.doNotOnSaveClick then
inputCourseNameDialogue:onSaveClick()
self.cp.onSaveClick = false
self.cp.doNotOnSaveClick = false
end
if self.cp.onMpSetCourses then
courseplay.courses:reloadVehicleCourses(self)
self.cp.onMpSetCourses = nil
end
if not courseplay.isClient then
if self.cp.isDriving then
local showDriveOnButton = false;
if self.cp.mode == courseplay.MODE_FIELDWORK then
if self.cp.wait and (self.cp.waypointIndex == self.cp.stopWork or self.cp.previousWaypointIndex == self.cp.stopWork) and self.cp.abortWork == nil and not self.cp.isLoaded and not isFinishingWork and self.cp.hasUnloadingRefillingCourse then
showDriveOnButton = true;
end;
else
if (self.cp.wait and (self.Waypoints[self.cp.waypointIndex].wait or self.Waypoints[self.cp.previousWaypointIndex].wait)) or (self.cp.stopAtEnd and (self.cp.waypointIndex == self.cp.numWaypoints or self.cp.currentTipTrigger ~= nil)) then
showDriveOnButton = true;
end;
end;
self:setCpVar('HUD1wait', showDriveOnButton,courseplay.isClient);
self:setCpVar('HUD1noWaitforFill', not self.cp.isLoaded and self.cp.mode ~= 5,courseplay.isClient);
--[[ TODO (Jakob):
* rename to "HUD1waitForFill"
* should only be applicable in following situations:
** mode 1: waypoint 1 (being filled)
** mode 2: waiting for fill/unloading combine
** mode 3: unloading at wait point 3
** mode 4: refilling in trigger/at wait point 3
** mode 6: on field
** mode 7: ai threshing / unloading at wait point
]]
end;
if self.cp.hud.currentPage == 0 then
local combine = self;
if self.cp.attachedCombine then
combine = self.cp.attachedCombine;
end;
if combine.courseplayers == nil then
self:setCpVar('HUD0noCourseplayer', true,courseplay.isClient);
combine.courseplayers = {};
else
self:setCpVar('HUD0noCourseplayer', #combine.courseplayers == 0,courseplay.isClient);
end
self:setCpVar('HUD0wantsCourseplayer', combine.cp.wantsCourseplayer,courseplay.isClient);
self:setCpVar('HUD0combineForcedSide', combine.cp.forcedSide,courseplay.isClient);
self:setCpVar('HUD0isManual', not self.cp.isDriving and not combine.aiIsStarted,courseplay.isClient);
self:setCpVar('HUD0turnStage', self.cp.turnStage,courseplay.isClient);
local tractor = combine.courseplayers[1]
if tractor ~= nil then
self:setCpVar('HUD0tractorForcedToStop', tractor.cp.forcedToStop,courseplay.isClient);
self:setCpVar('HUD0tractorName', tostring(tractor.name),courseplay.isClient);
self:setCpVar('HUD0tractor', true,courseplay.isClient);
else
self:setCpVar('HUD0tractorForcedToStop', nil,courseplay.isClient);
self:setCpVar('HUD0tractorName', nil,courseplay.isClient);
self:setCpVar('HUD0tractor', false,courseplay.isClient);
end;
elseif self.cp.hud.currentPage == 1 then
if self:getIsActive() and not self.cp.canDrive and self.cp.fieldEdge.customField.show and self.cp.fieldEdge.customField.points ~= nil then
courseplay:showFieldEdgePath(self, "customField");
end;
elseif self.cp.hud.currentPage == 4 then
self:setCpVar('HUD4hasActiveCombine', self.cp.activeCombine ~= nil,courseplay.isClient);
if self.cp.HUD4hasActiveCombine == true then
self:setCpVar('HUD4combineName', self.cp.activeCombine.name,courseplay.isClient);
end
self:setCpVar('HUD4savedCombine', self.cp.savedCombine ~= nil and self.cp.savedCombine.rootNode ~= nil,courseplay.isClient);
if self.cp.savedCombine ~= nil then
self:setCpVar('HUD4savedCombineName', self.cp.savedCombine.name,courseplay.isClient);
end
elseif self.cp.hud.currentPage == 8 then
if self:getIsActive() and self.cp.fieldEdge.selectedField.show and self.cp.fieldEdge.selectedField.fieldNum > 0 and self == g_currentMission.controlledVehicle then
courseplay:showFieldEdgePath(self, "selectedField");
end;
end;
end;
--[[if g_server ~= nil and g_currentMission.missionDynamicInfo.isMultiplayer then
for k,v in pairs(courseplay.checkValues) do
self.cp[v .. "Memory"] = courseplay:checkForChangeAndBroadcast(self, "self.cp." .. v , self.cp[v], self.cp[v .. "Memory"]);
end;
end;]]
if self.cp.collidingVehicleId ~= nil and g_currentMission.nodeToVehicle[self.cp.collidingVehicleId] ~= nil and g_currentMission.nodeToVehicle[self.cp.collidingVehicleId].isCpPathvehicle then
courseplay:setPathVehiclesSpeed(self,dt)
end
-- MODE 9: move shovel to positions (manually)
if self.cp.mode == courseplay.MODE_SHOVEL_FILL_AND_EMPTY and self.cp.manualShovelPositionOrder ~= nil and self.cp.movingToolsPrimary then
if courseplay:checkAndSetMovingToolsPosition(self, self.cp.movingToolsPrimary, self.cp.movingToolsSecondary, self.cp.shovelStatePositions[ self.cp.manualShovelPositionOrder ], dt) or courseplay:timerIsThrough(self, 'manualShovelPositionOrder') then
courseplay:resetManualShovelPositionOrder(self);
end;
end;
-- MODE 3: move pipe to positions (manually)
if self.cp.mode == courseplay.MODE_OVERLOADER and self.cp.manualPipePositionOrder ~= nil and self.cp.pipeWorkToolIndex then
local workTool = self.attachedImplements[self.cp.pipeWorkToolIndex].object
if courseplay:checkAndSetMovingToolsPosition(self, workTool.movingTools, nil, self.cp.pipePositions, dt , self.cp.pipeIndex ) or courseplay:timerIsThrough(self, 'manualPipePositionOrder') then
courseplay:resetManualPipePositionOrder(self);
end;
end;
end; --END update()
--[[
function courseplay:postUpdate(dt)
end;
]]
function courseplay:updateTick(dt)
if not self.cp.fieldEdge.selectedField.buttonsCreated and courseplay.fields.numAvailableFields > 0 then
courseplay:createFieldEdgeButtons(self);
end;
--attached or detached implement?
if self.cp.tooIsDirty then
self.cpTrafficCollisionIgnoreList = {}
courseplay:resetTools(self)
end
self.timer = self.timer + dt;
end
--[[
function courseplay:postUpdateTick(dt)
end;
]]
function courseplay:preDelete()
if self.cp ~= nil and self.cp.numActiveGlobalInfoTexts ~= 0 then
for refIdx,_ in pairs(CpManager.globalInfoText.msgReference) do
if self.cp.activeGlobalInfoTexts[refIdx] ~= nil then
CpManager:setGlobalInfoText(self, refIdx, true);
-- print(('%s: preDelete(): self.cp.activeGlobalInfoTexts[%s]=%s'):format(nameNum(self), tostring(refIdx), tostring(self.cp.activeGlobalInfoTexts[refIdx])));
end;
self.cp.hasSetGlobalInfoTextThisLoop[refIdx] = false;
end;
end;
end;
function courseplay:delete()
if self.aiTrafficCollisionTrigger ~= nil then
removeTrigger(self.aiTrafficCollisionTrigger);
end;
for i,trigger in pairs(self.cp.trafficCollisionTriggers) do
removeTrigger(trigger);
end;
if self.cp ~= nil then
if self.cp.headland and self.cp.headland.tg then
unlink(self.cp.headland.tg);
delete(self.cp.headland.tg);
self.cp.headland.tg = nil;
end;
if self.cp.hud.bg ~= nil then
self.cp.hud.bg:delete();
end;
if self.cp.hud.bgWithModeButtons ~= nil then
self.cp.hud.bgWithModeButtons:delete();
end;
if self.cp.hud.suc ~= nil then
self.cp.hud.suc:delete();
end;
if self.cp.directionArrowOverlay ~= nil then
self.cp.directionArrowOverlay:delete();
end;
if self.cp.buttons ~= nil then
courseplay.buttons:deleteButtonOverlays(self);
end;
if self.cp.signs ~= nil then
for _,section in pairs(self.cp.signs) do
for k,signData in pairs(section) do
courseplay.signs:deleteSign(signData.sign);
end;
end;
self.cp.signs = nil;
end;
if self.cp.course2dPdaMapOverlay then
self.cp.course2dPdaMapOverlay:delete();
end;
end;
end;
function courseplay:setInfoText(vehicle, text)
if not vehicle.cp.isEntered then
return
end
if vehicle.cp.infoText ~= text and text ~= nil and vehicle.cp.lastInfoText ~= text then