This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 525
/
start_stop.lua
192 lines (152 loc) · 6.01 KB
/
start_stop.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
local curFile = 'start_stop.lua';
-- starts driving the course only runs on the server!
function courseplay:start(self)
if g_server == nil then
return
end
if not CpManager.trafficCollisionIgnoreList[g_currentMission.terrainRootNode] then -- ???
CpManager.trafficCollisionIgnoreList[g_currentMission.terrainRootNode] = true;
end;
self.cp.numWayPoints = #self.Waypoints;
if self.cp.numWaypoints < 1 then
return
end
--setEngineState needed or AIDriver handling this ??
courseplay:setEngineState(self, true);
self.cp.saveFuel = false
courseplay.alreadyPrinted = {}
self.cpTrafficCollisionIgnoreList = {}
courseplay:resetTools(self)
if self.cp.waypointIndex < 1 then
courseplay:setWaypointIndex(self, 1);
end
-- show arrow
-- self.cp.distanceCheck = true
-- current position
local ctx, cty, ctz = getWorldTranslation(self.cp.directionNode);
-- TODO: temporary bandaid here for the case when the legacy waypointIndex isn't set correctly
if self.cp.waypointIndex > #self.Waypoints then
courseplay.infoVehicle(self, 'Waypoint index %d reset to %d', self.cp.waypointIndex, #self.Waypoints)
self.cp.waypointIndex = #self.Waypoints
end
-- position of next waypoint
local cx, cz = self.Waypoints[self.cp.waypointIndex].cx, self.Waypoints[self.cp.waypointIndex].cz
-- distance (in any direction)
local dist = courseplay:distance(ctx, ctz, cx, cz)
local numWaitPoints = 0
local numUnloadPoints = 0
local numCrossingPoints = 0
self.cp.waitPoints = {};
self.cp.unloadPoints = {};
local mode = 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_FERTILIZE or mode == courseplay.MODE_FIELDWORK) then
if numWaitPoints == 0 or self.cp.startWork == nil then
self.cp.startWork = 1;
end;
if numWaitPoints == 0 or self.cp.stopWork == nil then
self.cp.stopWork = self.cp.numWaypoints;
end;
end;
self.cp.numWaitPoints = numWaitPoints;
self.cp.numUnloadPoints = numUnloadPoints;
self.cp.numCrossingPoints = numCrossingPoints;
courseplay:debug(string.format("%s: numWaitPoints=%d, waitPoints[1]=%s, numCrossingPoints=%d",
nameNum(self), self.cp.numWaitPoints, tostring(self.cp.waitPoints[1]), numCrossingPoints), 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
if mode == courseplay.MODE_FIELDWORK then
self.cp.driver:delete()
self.cp.driver = UnloadableFieldworkAIDriver.create(self)
elseif mode == courseplay.MODE_BUNKERSILO_COMPACTER then
--- 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!
function courseplay:stop(self)
if g_server == nil then
return
end
-- Stop AI Driver
if self.cp.driver then
self.cp.driver:dismiss()
end
--is this one still used ??
if g_currentMission.missionInfo.automaticMotorStartEnabled and self.cp.saveFuel and not self.spec_motorized.isMotorStarted then
courseplay:setEngineState(self, true);
self.cp.saveFuel = false;
end
if self.cp.directionNodeToTurnNodeLength ~= nil then
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);
if self.cp.checkReverseValdityPrinted then
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
function courseplay:findVehicleHeights(transformId, x, y, z, distance)
local startHeight = math.max(self.sizeLength,5)
local height = startHeight - distance
local vehicle = false
--print(string.format("found %s (%s)",tostring(getName(transformId)),tostring(transformId)))
-- if self.cp.aiTrafficCollisionTrigger == transformId then
if self.aiTrafficCollisionTrigger == transformId then
if self.cp.HeightsFoundColli < height then
self.cp.HeightsFoundColli = height
end
elseif transformId == self.rootNode then
vehicle = true
elseif getParent(transformId) == self.rootNode and self.aiTrafficCollisionTrigger ~= transformId then
vehicle = true
elseif self.cpTrafficCollisionIgnoreList[transformId] or self.cpTrafficCollisionIgnoreList[getParent(transformId)] then
vehicle = true
end
if vehicle and self.cp.HeightsFound < height then
self.cp.HeightsFound = height
end
return true
end
function courseplay:safeSetWaypointIndex( vehicle, newIx )
for i = newIx, newIx do
-- don't set it too close to a turn start,
if vehicle.Waypoints[ i ] ~= nil and vehicle.Waypoints[ i ].turnStart then
-- set it to after the turn
newIx = i + 2
break
end
end
if vehicle.cp.waypointIndex > vehicle.cp.numWaypoints then
courseplay:setWaypointIndex(vehicle, 1);
else
courseplay:setWaypointIndex( vehicle, newIx );
end
end
-- do not remove this comment
-- vim: set noexpandtab: