Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on May 23, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathstart_stop.lua
More file actions
Latest commit
192 lines (152 loc) · 6.01 KB
/
Copy pathstart_stop.lua
File metadata and controls
192 lines (152 loc) · 6.01 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
localcurFile='start_stop.lua';
-- starts driving the course only runs on the server!
functioncourseplay:start(self)
ifg_server==nilthen
return
end
ifnotCpManager.trafficCollisionIgnoreList[g_currentMission.terrainRootNode] then-- ???
CpManager.trafficCollisionIgnoreList[g_currentMission.terrainRootNode] =true;
end;
self.cp.numWayPoints=#self.Waypoints;
ifself.cp.numWaypoints<1then
return
end
--setEngineState needed or AIDriver handling this ??
courseplay:setEngineState(self, true);
self.cp.saveFuel=false
courseplay.alreadyPrinted= {}
self.cpTrafficCollisionIgnoreList= {}
courseplay:resetTools(self)
ifself.cp.waypointIndex<1then
courseplay:setWaypointIndex(self, 1);
end
-- show arrow
-- self.cp.distanceCheck = true
-- current position
localctx, cty, ctz=getWorldTranslation(self.cp.directionNode);
-- TODO: temporary bandaid here for the case when the legacy waypointIndex isn't set correctly
ifself.cp.waypointIndex>#self.Waypointsthen
courseplay.infoVehicle(self, 'Waypoint index %d reset to %d', self.cp.waypointIndex, #self.Waypoints)
self.cp.waypointIndex=#self.Waypoints
end
-- position of next waypoint
localcx, cz=self.Waypoints[self.cp.waypointIndex].cx, self.Waypoints[self.cp.waypointIndex].cz
-- distance (in any direction)
localdist=courseplay:distance(ctx, ctz, cx, cz)
localnumWaitPoints=0
localnumUnloadPoints=0
localnumCrossingPoints=0
self.cp.waitPoints= {};
self.cp.unloadPoints= {};
localmode=self.cp.settings.driverMode:get()
-- modes 4/6 without start and stop point, set them at start and end, for only-on-field-courses
if (mode==courseplay.MODE_SEED_FERTILIZEormode==courseplay.MODE_FIELDWORK) then
ifnumWaitPoints==0orself.cp.startWork==nilthen
self.cp.startWork=1;
end;
ifnumWaitPoints==0orself.cp.stopWork==nilthen
self.cp.stopWork=self.cp.numWaypoints;
end;
end;
self.cp.numWaitPoints=numWaitPoints;
self.cp.numUnloadPoints=numUnloadPoints;
self.cp.numCrossingPoints=numCrossingPoints;
courseplay:debug(string.format("%s: numWaitPoints=%d, waitPoints[1]=%s, numCrossingPoints=%d",
nameNum(self), self.cp.numWaitPoints, tostring(self.cp.waitPoints[1]), numCrossingPoints), courseplay.DBG_COURSES);
courseplay:updateAllTriggers();
---Do we need to set distanceCheck==true at the beginning of courseplay:start() and set now set it to false 50 lines later ??
-- self.cp.distanceCheck = false
self.cp.totalLength, self.cp.totalLengthOffset=courseplay:getTotalLengthOnWheels(self);
courseplay:validateCanSwitchMode(self);
-- and another ugly hack here as when settings.lua setAIDriver() is called the bale loader does not seem to be
-- attached and I don't have the motivation do dig through the legacy code to find out why
ifmode==courseplay.MODE_FIELDWORKthen
self.cp.driver:delete()
self.cp.driver=UnloadableFieldworkAIDriver.create(self)
elseifmode==courseplay.MODE_BUNKERSILO_COMPACTERthen
--- Not sure if this is needed, might have to check if the AIDriver gets reevaluated after an implement gets attached.
self.cp.driver:delete()
self.cp.driver=BunkerSiloAIDriver.create(self)
end
self.cp.driver:start(self.cp.settings.startingPoint)
end;
-- stops driving the course only runs on the server!
functioncourseplay:stop(self)
ifg_server==nilthen
return
end
-- Stop AI Driver
ifself.cp.driverthen
self.cp.driver:dismiss()
end
--is this one still used ??
ifg_currentMission.missionInfo.automaticMotorStartEnabledandself.cp.saveFuelandnotself.spec_motorized.isMotorStartedthen
courseplay:setEngineState(self, true);
self.cp.saveFuel=false;
end
ifself.cp.directionNodeToTurnNodeLength~=nilthen
self.cp.directionNodeToTurnNodeLength=nil
end
self.cp.settings.forcedToStop:set(false)
---Is this one still used as cp.isTurning isn't getting set to true ??
self.cp.isTurning=nil;
courseplay:clearTurnTargets(self);
self.cp.hasMachineToFill=false;
-- resetting variables
courseplay:resetTipTrigger(self);
ifself.cp.checkReverseValdityPrintedthen
self.cp.checkReverseValdityPrinted=false
end
self.cp.curSpeed=0;
self.cp.startWork=nil
self.cp.stopWork=nil
courseplay:setSlippingStage(self, 0);
courseplay:resetCustomTimer(self, 'slippingStage1');
courseplay:resetCustomTimer(self, 'slippingStage2');
self.cp.totalLength, self.cp.totalLengthOffset=0, 0;
self.cp.numWorkTools=0;
--validation: can switch mode?
courseplay:validateCanSwitchMode(self);
-- reactivate load/add/delete course buttons
--courseplay.buttons:setActiveEnabled(self, 'page2');
end
---TODO: move this to TrafficCollision.lua
functioncourseplay:findVehicleHeights(transformId, x, y, z, distance)
localstartHeight=math.max(self.sizeLength,5)
localheight=startHeight-distance
localvehicle=false
--print(string.format("found %s (%s)",tostring(getName(transformId)),tostring(transformId)))
-- if self.cp.aiTrafficCollisionTrigger == transformId then
ifself.aiTrafficCollisionTrigger==transformIdthen
ifself.cp.HeightsFoundColli<heightthen
self.cp.HeightsFoundColli=height
end
elseiftransformId==self.rootNodethen
vehicle=true
elseifgetParent(transformId) ==self.rootNodeandself.aiTrafficCollisionTrigger~=transformIdthen
vehicle=true
elseifself.cpTrafficCollisionIgnoreList[transformId] orself.cpTrafficCollisionIgnoreList[getParent(transformId)] then
vehicle=true
end
ifvehicleandself.cp.HeightsFound<heightthen
self.cp.HeightsFound=height
end
returntrue
end
functioncourseplay:safeSetWaypointIndex( vehicle, newIx )
fori=newIx, newIxdo
-- don't set it too close to a turn start,
ifvehicle.Waypoints[ i ] ~=nilandvehicle.Waypoints[ i ].turnStartthen
-- set it to after the turn
newIx=i+2
break
end
end
ifvehicle.cp.waypointIndex>vehicle.cp.numWaypointsthen
courseplay:setWaypointIndex(vehicle, 1);
else
courseplay:setWaypointIndex( vehicle, newIx );
end
end
-- do not remove this comment
-- vim: set noexpandtab: