Skip to content

Commit 8b091bf

Browse files
authored
Merge pull request #708 from Courseplay/nexat
fix: Nexat reversing
2 parents 4c2c6db + c69491e commit 8b091bf

4 files changed

Lines changed: 26 additions & 31 deletions

File tree

scripts/ai/PurePursuitController.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ end
169169
-- remain in initializing mode if the waypoint is too far back from the controlled node, and just
170170
-- reverse forever
171171
function PurePursuitController:initializeForReversing(ix)
172-
local reverserNode = self:getReverserNode()
172+
local reverserNode, debugText = self:getReverserNode(false)
173173
if reverserNode then
174-
self:debug('Reverser node found, initializing with it')
174+
self:debug('Reverser node %s found, initializing with it', debugText)
175175
-- don't use ix as it is, instead, find the waypoint closest to the reverser node
176176
local dPrev, d = math.huge, self.course:getWaypoint(ix):getDistanceFromNode(reverserNode)
177177
while d < dPrev and self.course:isReverseAt(ix) and ix < self.course:getNumberOfWaypoints() do
@@ -253,11 +253,11 @@ function PurePursuitController:getLastPassedWaypointIx()
253253
end
254254

255255
---@return number, string node that would be used for reversing, debug text explaining what node it is
256-
function PurePursuitController:getReverserNode()
256+
function PurePursuitController:getReverserNode(suppressLog)
257257
if not self.reversingImplement then
258-
self.reversingImplement = AIUtil.getFirstReversingImplementWithWheels(self.vehicle, true)
258+
self.reversingImplement = AIUtil.getFirstReversingImplementWithWheels(self.vehicle, suppressLog)
259259
end
260-
return AIUtil.getReverserNode(self.vehicle, self.reversingImplement, true)
260+
return AIUtil.getReverserNode(self.vehicle, self.reversingImplement, suppressLog)
261261
end
262262

263263
--- When reversing, use the towed implement's node as a reference
@@ -266,7 +266,7 @@ function PurePursuitController:switchControlledNode()
266266
local debugText = 'AIDirectionNode'
267267
local reverserNode
268268
if self:isReversing() then
269-
reverserNode, debugText = self:getReverserNode()
269+
reverserNode, debugText = self:getReverserNode(true)
270270
if reverserNode then
271271
self:setControlledNode(reverserNode)
272272
else

scripts/ai/util/AIUtil.lua

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,16 @@ function AIUtil.getTractorRadiusFromImplementRadius(r, towBarLength)
202202
return rTractor
203203
end
204204

205-
function AIUtil.getArticulatedAxisVehicleReverserNode(vehicle)
206-
local reverserNode, debugText
207-
-- articulated axis vehicles have a special reverser node
208-
-- and yes, Giants has a typo in there...
209-
if vehicle.spec_articulatedAxis.aiRevereserNode ~= nil then
210-
reverserNode = vehicle.spec_articulatedAxis.aiRevereserNode
211-
debugText = 'vehicle articulated axis reverese'
212-
elseif vehicle.spec_articulatedAxis.aiReverserNode ~= nil then
213-
reverserNode = vehicle.spec_articulatedAxis.aiReverserNode
214-
debugText = 'vehicle articulated axis reverse'
215-
end
216-
return reverserNode, debugText
217-
end
218-
219205
-- Find the node to use by the PPC when driving in reverse
220206
function AIUtil.getReverserNode(vehicle, reversingImplement, suppressLog)
221207
local reverserNode, debugText
222208
-- if there's a reverser node on the tool, use that
223-
reverserNode, debugText = AIVehicleUtil.getAIToolReverserDirectionNode(vehicle), 'AIToolReverserDirectionNode'
209+
reverserNode, debugText = AIVehicleUtil.getAIToolReverserDirectionNode(vehicle), 'AIVehicleUtil.AIToolReverserDirectionNode()'
210+
if not reverserNode then
211+
-- the vehicle may also have a tool reverser node, likely for the Nexat, this is the order Giants checks it
212+
-- in their driver.
213+
reverserNode, debugText = vehicle:getAIToolReverserDirectionNode(), 'vehicle:AIToolReverserDirectionNode()'
214+
end
224215
if not reverserNode then
225216
reversingImplement = reversingImplement and reversingImplement or AIUtil.getFirstReversingImplementWithWheels(vehicle, suppressLog)
226217
if reversingImplement and reversingImplement.steeringAxleNode then
@@ -230,9 +221,6 @@ function AIUtil.getReverserNode(vehicle, reversingImplement, suppressLog)
230221
if not reverserNode and vehicle.getAIReverserNode then
231222
reverserNode, debugText = vehicle:getAIReverserNode(), 'AIReverserNode'
232223
end
233-
if not reverserNode and vehicle.spec_articulatedAxis ~= nil then
234-
reverserNode, debugText = AIUtil.getArticulatedAxisVehicleReverserNode(vehicle)
235-
end
236224
return reverserNode, debugText
237225
end
238226

@@ -764,7 +752,7 @@ end
764752
--- FS22_UniversalAutoload from Loki79uk: https://github.com/loki79uk/FS22_UniversalAutoload
765753
function AIUtil.hasValidUniversalTrailerAttached(vehicle)
766754
local implements, found = AIUtil.getAllChildVehiclesWithSpecialization(vehicle, nil, "spec_universalAutoload")
767-
if not found then
755+
if not found then
768756
return false
769757
end
770758
local spec = implements[1].spec_universalAutoload

scripts/dev/ConsoleCommands.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CpConsoleCommands.commands = {
66
{ 'cpAddMoney', 'adds money', 'addMoney' },
77
{ 'cpRestartSaveGame', 'Load and start a savegame', 'restartSaveGame' },
88
{ 'cpReturnToSaveGameSelect', 'Returns to the menu', 'returnToSaveGameSelect' },
9-
{ 'print', 'Print a variable', 'printVariable' },
9+
{ 'print', 'Print a variable ($vehicle is replaced with CpUtil.getCurrentVehicle())', 'printVariable' },
1010
{ 'printGlobalCpVariable', 'Print a global cp variable', 'printGlobalCpVariable' },
1111
{ 'printVehicleVariable', 'Print CpUtil.getCurrentVehicle().variable', 'printVehicleVariable' },
1212
{ 'printImplementVariable', 'printImplementVariable <implement index> <variable>', 'printImplementVariable' },
@@ -97,6 +97,7 @@ end
9797
---@param printToXML number should the variable be printed to an xml file ? (optional)
9898
---@param printToSeparateXmlFiles number should the variable be printed to an xml file named after the variable ? (optional)
9999
function CpConsoleCommands:printVariable(variableName, maxDepth, printToXML, printToSeparateXmlFiles)
100+
variableName = variableName:gsub('$vehicle', 'CpUtil.getCurrentVehicle()')
100101
if printToXML and tonumber(printToXML) and tonumber(printToXML)>0 then
101102
CpUtil.printVariableToXML(variableName, maxDepth, printToSeparateXmlFiles)
102103
return

scripts/dev/DevHelper.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,22 @@ function DevHelper:showAIMarkers()
313313
end
314314
local reverseNode = self.vehicle:getAIReverserNode()
315315
if reverseNode then
316-
CpUtil.drawDebugNode(reverseNode, false , 4.5, "AiReverseNode")
316+
CpUtil.drawDebugNode(reverseNode, false , 4.2, "AiReverseNode")
317317
end
318318
local steeringNode = self.vehicle:getAISteeringNode()
319319
if steeringNode then
320-
CpUtil.drawDebugNode(steeringNode, false , 5, "AiSteeringNode")
320+
CpUtil.drawDebugNode(steeringNode, false , 4.4, "AiSteeringNode")
321321
end
322-
local articulatedAxisReverseNode = AIUtil.getArticulatedAxisVehicleReverserNode(self.vehicle)
323-
if articulatedAxisReverseNode then
324-
CpUtil.drawDebugNode(articulatedAxisReverseNode, false , 5.5, "AiArticulatedAxisReverseNode")
322+
323+
local reverserNode = AIVehicleUtil.getAIToolReverserDirectionNode(self.vehicle)
324+
if reverserNode then
325+
CpUtil.drawDebugNode(reverserNode, false , 4.8, "AIVehicleUtil.AIToolReverserDirectionNode()")
326+
end
327+
reverserNode = self.vehicle:getAIToolReverserDirectionNode()
328+
if reverserNode then
329+
CpUtil.drawDebugNode(reverserNode, false , 5.0, 'vehicle:AIToolReverserDirectionNode()')
325330
end
331+
326332
end
327333

328334
function DevHelper:togglePpcControlledNode()

0 commit comments

Comments
 (0)