Skip to content

Commit

Permalink
Release 1.0.4.2
Browse files Browse the repository at this point in the history
New interface function for use with Courseplay.
  • Loading branch information
Stephan-S committed Aug 12, 2019
1 parent f2cdde6 commit c593c14
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FS19_AutoDrive/modDesc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Créer, ajouter, modifier, supprimer vos routes ou points de destination à l'ai
]]>
</ru>
</description>
<version>1.0.4.1</version>
<version>1.0.4.2</version>
<multiplayer supported="true"/>
<iconFilename>store.dds</iconFilename>
<extraSourceFiles>
Expand Down
2 changes: 1 addition & 1 deletion FS19_AutoDrive/scripts/AutoDrive.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AutoDrive = {};
AutoDrive.Version = "1.0.4.1";
AutoDrive.Version = "1.0.4.2";
AutoDrive.config_changed = false;

AutoDrive.directory = g_currentModDirectory;
Expand Down
54 changes: 50 additions & 4 deletions FS19_AutoDrive/scripts/AutoDriveExternalInterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,48 @@ function AutoDrive:GetPath(startX, startZ, startYRot, destinationID, options)
return AutoDrive:FastShortestPath(AutoDrive.mapWayPoints,bestPoint,markerName, destinationID);
end;

function AutoDrive:GetPathVia(startX, startZ, startYRot, viaID, destinationID, options)
if startX == nil or startZ == nil or startYRot == nil or destinationID == nil or AutoDrive.mapMarker[destinationID] == nil or viaID == nil or AutoDrive.mapMarker[viaID] == nil then
return;
end;

local markerName = AutoDrive.mapMarker[viaID].name;
local startPoint = {x=startX, z=startZ};
local minDistance = 1;
local maxDistance = 20;
if options ~= nil and options.minDistance ~= nil then
minDistance = options.minDistance;
end;
if options ~= nil and options.maxDistance ~= nil then
maxDistance = options.maxDistance;
end;
local directionVec = {x = math.cos(startYRot), z = math.sin(startYRot)};
local bestPoint = AutoDrive:findMatchingWayPoint(startPoint, directionVec, minDistance, maxDistance);

if bestPoint == -1 then
bestPoint = AutoDrive:GetClosestPointToLocation(startX, startZ, minDistance, maxDistance);
if bestPoint == -1 then
return;
end;
end;

local toViaID = AutoDrive:FastShortestPath(AutoDrive.mapWayPoints,bestPoint,markerName, viaID);

if toViaID == nil or ADTableLength(toViaID) < 1 then
return;
end;

local fromViaID = AutoDrive:FastShortestPath(AutoDrive.mapWayPoints,toViaID[ADTableLength(toViaID)], AutoDrive.mapMarker[destinationID].name, destinationID);

for i, wayPoint in pairs(fromViaID) do
if i > 1 then
table.insert(toViaID, wayPoint);
end;
end;

return toViaID;
end;

function AutoDrive:GetAvailableDestinations()
local destinations = {};
for markerID, marker in pairs(AutoDrive.mapMarker) do
Expand Down Expand Up @@ -89,11 +131,15 @@ end;

--These are just here for example purposes on how to use the interface to start an AD driver and receive a callback when it's finished

addConsoleCommand('adStartDriving', 'Start current course and callback', 'adStartDriving', AutoDrive);
addConsoleCommand('adGetPath', 'Start current course and callback', 'adGetPath', AutoDrive);

function AutoDrive:adGetPath()
local veh = g_currentMission.controlledVehicle;
local x1,y1,z1 = getWorldTranslation(veh.components[1].node);
local rx,ry,rz = localDirectionToWorld(veh.components[1].node, 0,0,1);
local vehicleVector = {x= math.sin(rx) ,z= math.sin(rz) };

function AutoDrive:adStartDriving()
--print("AutoDrive:adStartDriving called")
AutoDrive:StartDriving(g_currentMission.controlledVehicle, g_currentMission.controlledVehicle.ad.mapMarkerSelected, g_currentMission.controlledVehicle.ad.mapMarkerSelected_Unload, AutoDrive, AutoDrive.isFinished, g_currentMission.controlledVehicle);
veh.ad.testVar = AutoDrive:GetPathVia(x1, z1, rz, g_currentMission.controlledVehicle.ad.mapMarkerSelected, g_currentMission.controlledVehicle.ad.mapMarkerSelected_Unload);
end;

function AutoDrive:isFinished(vehicle)
Expand Down
2 changes: 1 addition & 1 deletion FS19_AutoDrive/scripts/AutoDrivePathFinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function AutoDrivePathFinder:init(driver, startX, startZ, targetX, targetZ, targ
driver.ad.pf.fallBackMode = false;
driver.ad.pf.combine = combine;
driver.ad.pf.fruitToCheck = driver.ad.combineFruitToCheck;
if driver.ad.combineFruitToCheck == nil then
if driver.ad.combineFruitToCheck == nil and driver.ad.pf.combine ~= nil then
driver.ad.pf.fruitToCheck = 1;
end;
driver.ad.pf.fieldArea = driver.ad.combineFieldArea;
Expand Down
Binary file added releases/1.0.4.2/FS19_AutoDrive.zip
Binary file not shown.

0 comments on commit c593c14

Please sign in to comment.