Skip to content

Commit

Permalink
Release 1.0.2.5
Browse files Browse the repository at this point in the history
Added setting to select if the field courses should be smoothed.
Limited speed on field to 28 km/h
Made sure that the 'exitField' strategies only apply when going to unload and not when parking
  • Loading branch information
Stephan-S committed May 30, 2019
1 parent 0109d91 commit e87f5ee
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 112 deletions.
4 changes: 4 additions & 0 deletions FS19_AutoDrive/gui/settingsGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,8 @@ end;

function adSettingsGui:onCreateAutoDriveSettingDriverWages(element)
self:onCreateAutoDriveSetting(element, "driverWages");
end;

function adSettingsGui:onCreateAutoDriveSettingSmoothField(element)
self:onCreateAutoDriveSetting(element, "smoothField");
end;
7 changes: 7 additions & 0 deletions FS19_AutoDrive/gui/settingsGui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
<GuiElement type="text" profile="multiTextOptionSettingsTitle" text="driverWages" />
<GuiElement type="bitmap" profile="multiTextOptionSettingsBg" />
</GuiElement>
<GuiElement type="multiTextOption" profile="multiTextOptionSettings" onCreate="onCreateAutoDriveSettingSmoothField" toolTipElementId="ingameMenuHelpBoxText" toolTipText="$l10n_gui_ad_smoothField_tooltip">
<GuiElement type="button" profile="multiTextOptionSettingsLeft" />
<GuiElement type="button" profile="multiTextOptionSettingsRight" />
<GuiElement type="text" profile="multiTextOptionSettingsText" />
<GuiElement type="text" profile="multiTextOptionSettingsTitle" text="smoothField" />
<GuiElement type="bitmap" profile="multiTextOptionSettingsBg" />
</GuiElement>
</GuiElement>

<GuiElement type="bitmap" profile="ingameMenuHelpRowBg" position="80px 50px" id="ingameMenuHelpBox" visible="true">
Expand Down
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.2.4</version>
<version>1.0.2.5</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.2.4";
AutoDrive.Version = "1.0.2.5";
AutoDrive.config_changed = false;

AutoDrive.directory = g_currentModDirectory;
Expand Down
2 changes: 1 addition & 1 deletion FS19_AutoDrive/scripts/AutoDriveCombineMode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function AutoDrive:handleReachedWayPointCombine(vehicle)
vehicle.ad.initialized = false;
vehicle.ad.wayPoints = {};
vehicle.ad.isPaused = true;
elseif vehicle.ad.combineState == AutoDrive.DRIVE_TO_PARK_POS then
elseif vehicle.ad.combineState == AutoDrive.DRIVE_TO_PARK_POS then
AutoDrive.waitingUnloadDrivers[vehicle] = vehicle;
vehicle.ad.combineState = AutoDrive.WAIT_FOR_COMBINE;
--vehicle.ad.initialized = false;
Expand Down
27 changes: 22 additions & 5 deletions FS19_AutoDrive/scripts/AutoDriveDriveFuncs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,18 @@ end;

function AutoDrive:checkForDeadLock(vehicle, dt)
if vehicle.ad.isActive == true and vehicle.isServer and vehicle.ad.isStopping == false then
vehicle.ad.timeTillDeadLock = vehicle.ad.timeTillDeadLock - dt;
if vehicle.ad.timeTillDeadLock < 0 and vehicle.ad.timeTillDeadLock ~= -1 then
--print("Deadlock reached due to timer");
vehicle.ad.inDeadLock = true;
end;
local x,y,z = getWorldTranslation( vehicle.components[1].node );
if (AutoDrive:getDistance(x,z, vehicle.ad.targetX, vehicle.ad.targetZ) < 15) then
vehicle.ad.timeTillDeadLock = vehicle.ad.timeTillDeadLock - dt;
if vehicle.ad.timeTillDeadLock < 0 and vehicle.ad.timeTillDeadLock ~= -1 then
--print("Deadlock reached due to timer");
vehicle.ad.inDeadLock = true;
end;
else
vehicle.ad.inDeadLock = false;
vehicle.ad.timeTillDeadLock = 15000;
vehicle.ad.inDeadLockRepairCounter = 4;
end;
else
vehicle.ad.inDeadLock = false;
vehicle.ad.timeTillDeadLock = 15000;
Expand Down Expand Up @@ -367,6 +374,16 @@ function AutoDrive:driveToNextWayPoint(vehicle, dt)
end;
end;
end;

if vehicle.ad.mode == AutoDrive.MODE_UNLOAD
and
( vehicle.ad.combineState == AutoDrive.DRIVE_TO_COMBINE
or vehicle.ad.combineState == AutoDrive.DRIVE_TO_PARK_POS
or vehicle.ad.combineState == AutoDrive.DRIVE_TO_START_POS ) then

vehicle.ad.speedOverride = math.min(28, vehicle.ad.speedOverride);
end;

end;

local finalSpeed = vehicle.ad.speedOverride;
Expand Down
167 changes: 164 additions & 3 deletions FS19_AutoDrive/scripts/AutoDrivePathFinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ function AutoDrivePathFinder:startPathPlanningToStartPosition(driver, combine)
local targetVector = {};

local exitStrategy = AutoDrive:getSetting("exitField");
if exitStrategy == 1 then
if exitStrategy == 1 and driver.ad.combineState ~= AutoDrive.DRIVE_TO_PARK_POS then
local waypointsToUnload = AutoDrive:FastShortestPath(AutoDrive.mapWayPoints, AutoDrive.mapMarker[driver.ad.mapMarkerSelected].id, AutoDrive.mapMarker[driver.ad.mapMarkerSelected_Unload].name, AutoDrive.mapMarker[driver.ad.mapMarkerSelected_Unload].id);
if waypointsToUnload ~= nil and waypointsToUnload[6] ~= nil then
preTargetPoint = AutoDrive.mapWayPoints[waypointsToUnload[5].id];
targetPoint = AutoDrive.mapWayPoints[waypointsToUnload[6].id];
end;
elseif exitStrategy == 2 then
elseif exitStrategy == 2 and driver.ad.combineState ~= AutoDrive.DRIVE_TO_PARK_POS then
local closest = AutoDrive:findClosestWayPoint(driver);
local waypointsToUnload = AutoDrive:FastShortestPath(AutoDrive.mapWayPoints, closest, AutoDrive.mapMarker[driver.ad.mapMarkerSelected_Unload].name, AutoDrive.mapMarker[driver.ad.mapMarkerSelected_Unload].id);
if waypointsToUnload ~= nil and waypointsToUnload[2] ~= nil then
Expand Down Expand Up @@ -528,7 +528,10 @@ function AutoDrivePathFinder:createWayPoints(pf)
--print("Found path!");
--DebugUtil.printTableRecursively(pf.wayPoints, ":::",0,1);

AutoDrivePathFinder:smoothResultingPPPath(pf);
AutoDrivePathFinder:smoothResultingPPPath(pf);
if AutoDrive:getSetting("smoothField") == true then
AutoDrivePathFinder:smoothResultingPPPath_Refined(pf);
end;
end;

function AutoDrivePathFinder:smoothResultingPPPath(pf)
Expand Down Expand Up @@ -563,6 +566,164 @@ function AutoDrivePathFinder:smoothResultingPPPath(pf)
pf.wayPoints = filteredWPs;
end;

function AutoDrivePathFinder:smoothResultingPPPath_Refined(pf)
if pf.fruitToCheck == nil then
return;
end;

local index = 1;
local filteredIndex = 1;
local filteredWPs = {};

--add first few without filtering
while index < ADTableLength(pf.wayPoints) and index < 3 do
filteredWPs[filteredIndex] = pf.wayPoints[index];
filteredIndex = filteredIndex + 1;
index = index + 1;
end;

while index < ADTableLength(pf.wayPoints) - 6 do
local node = pf.wayPoints[index];
local worldPos = pf.wayPoints[index];

filteredWPs[filteredIndex] = node;
filteredIndex = filteredIndex + 1;

local foundCollision = false;
local lookAheadIndex = 1;
while foundCollision == false and ((index+lookAheadIndex) < (ADTableLength(pf.wayPoints) - 6)) do
local nodeAhead = pf.wayPoints[index+lookAheadIndex];
local nodeTwoAhead = pf.wayPoints[index+lookAheadIndex+1];

local angle = AutoDrive:angleBetween( {x= nodeAhead.x - node.x, z = nodeAhead.z - node.z },
{x= nodeTwoAhead.x- nodeAhead.x, z = nodeTwoAhead.z - nodeAhead.z } )
angle = math.abs(angle);

local hasCollision = false;
if angle > 60 then
hasCollision = true;
end;

local vectorX = nodeAhead.x - node.x;
local vectorZ = nodeAhead.z - node.z;
local angleRad = math.atan2(vectorZ, vectorX);
angleRad = normalizeAngle(angleRad);
local sideLength = 3;
local length = math.sqrt(math.pow(vectorX, 2) + math.pow(vectorZ, 2));

local leftAngle = normalizeAngle(angleRad + math.rad(-90));
local rightAngle = normalizeAngle(angleRad + math.rad(90));

local cornerX = node.x + math.cos(leftAngle) * sideLength;
local cornerZ = node.z + math.sin(leftAngle) * sideLength;

local corner2X = nodeAhead.x + math.cos(leftAngle) * sideLength;
local corner2Z = nodeAhead.z + math.sin(leftAngle) * sideLength;

local corner3X = node.x + math.cos(rightAngle) * sideLength;
local corner3Z = node.z + math.sin(rightAngle) * sideLength;

local corner4X = nodeAhead.x + math.cos(rightAngle) * sideLength;
local corner4Z = nodeAhead.z + math.sin(rightAngle) * sideLength;

local y = worldPos.y;
local shapes = overlapBox(worldPos.x,y,worldPos.z, 0,angleRad,0, AutoDrive.PP_CELL_X,5,length, "collisionTestCallbackIgnore", nil, AIVehicleUtil.COLLISION_MASK, true, true, true)
hasCollision = hasCollision or (shapes > 0);
shapes = overlapBox(worldPos.x,y,worldPos.z, 0,angleRad,0, AutoDrive.PP_CELL_X,5,length, "collisionTestCallbackIgnore", nil, Player.COLLISIONMASK_TRIGGER, true, true, true)
hasCollision = hasCollision or (shapes > 0);

if (index > 1) then
local worldPosPrevious = pf.wayPoints[index-1]
local length = MathUtil.vector3Length(worldPos.x-worldPosPrevious.x, worldPos.y-worldPosPrevious.y, worldPos.z-worldPosPrevious.z)
local angleBetween = math.atan(math.abs(worldPos.y-worldPosPrevious.y)/length)

if angleBetween > AITurnStrategy.SLOPE_DETECTION_THRESHOLD then
hasCollision = true;
end
end;

local fruitValue, _, _, _ = FSDensityMapUtil.getFruitArea(pf.fruitToCheck, cornerX, cornerZ, corner2X, corner2Z, corner3X, corner3Z, nil, false);
if pf.fruitToCheck == 9 then
fruitValue, _, _, _ = FSDensityMapUtil.getFruitArea(pf.fruitToCheck, cornerX, cornerZ, corner2X, corner2Z, corner3X, corner3Z, true, true);
end;
hasCollision = hasCollision or (fruitValue > (0.3 * pf.fieldArea));
hasCollision = hasCollision or AutoDrivePathFinder:checkForCombineCollision(pf, cornerX, cornerZ, corner2X, corner2Z, corner3X, corner3Z, corner4X, corner4Z);

foundCollision = hasCollision;

lookAheadIndex = lookAheadIndex + 1;
end;

index = index + math.max(1,(lookAheadIndex-2));
end;

--add remaining points without filtering
while index <= ADTableLength(pf.wayPoints) do
local node = pf.wayPoints[index];
filteredWPs[filteredIndex] = node;
filteredIndex = filteredIndex + 1;
index = index + 1;
end;

pf.wayPoints = filteredWPs;
end;

function AutoDrivePathFinder:checkForCombineCollision(pf, cornerX, cornerZ, corner2X, corner2Z, corner3X, corner3Z, corner4X, corner4Z)
local boundingBox = {};
boundingBox[1] ={ x = cornerX,
y = 0,
z = cornerZ; };
boundingBox[2] ={ x = corner2X,
y = 0,
z = corner2Z; };
boundingBox[3] ={ x = corner3X,
y = 0,
z = corner3Z; };
boundingBox[4] ={ x = corner4X,
y = 0,
z = corner4Z; };

if pf.combine ~= nil and pf.combine.components ~= nil and pf.combine.sizeWidth ~= nil and pf.combine.sizeLength ~= nil and pf.combine.rootNode ~= nil then
local otherWidth = pf.combine.sizeWidth;
local otherLength = pf.combine.sizeLength;
local otherPos = {};
otherPos.x,otherPos.y,otherPos.z = getWorldTranslation( pf.combine.components[1].node );

local rx,ry,rz = localDirectionToWorld(pf.combine.components[1].node, 0, 0, 1);

local otherVectorToWp = {};
otherVectorToWp.x = rx;
otherVectorToWp.z = rz;

local otherPos2 = {};
otherPos2.x = otherPos.x + (otherLength/2) * (otherVectorToWp.x/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z)));
otherPos2.y = 0;
otherPos2.z = otherPos.z + (otherLength/2) * (otherVectorToWp.z/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z)));
local otherOrtho = { x=-otherVectorToWp.z, z=otherVectorToWp.x };

local otherBoundingBox = {};
otherBoundingBox[1] ={ x = otherPos.x + (otherWidth/2) * ( otherOrtho.x / (math.abs(otherOrtho.x)+math.abs(otherOrtho.z))) + (otherLength/2) * (otherVectorToWp.x/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z))),
y = 0,
z = otherPos.z + (otherWidth/2) * ( otherOrtho.z / (math.abs(otherOrtho.x)+math.abs(otherOrtho.z))) + (otherLength/2) * (otherVectorToWp.z/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z)))};

otherBoundingBox[2] ={ x = otherPos.x - (otherWidth/2) * ( otherOrtho.x / (math.abs(otherOrtho.x)+math.abs(otherOrtho.z))) + (otherLength/2) * (otherVectorToWp.x/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z))),
y = 0,
z = otherPos.z - (otherWidth/2) * ( otherOrtho.z / (math.abs(otherOrtho.x)+math.abs(otherOrtho.z))) + (otherLength/2) * (otherVectorToWp.z/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z)))};
otherBoundingBox[3] ={ x = otherPos.x - (otherWidth/2) * ( otherOrtho.x / (math.abs(otherOrtho.x)+math.abs(otherOrtho.z))) - (otherLength/2) * (otherVectorToWp.x/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z))),
y = 0,
z = otherPos.z - (otherWidth/2) * ( otherOrtho.z / (math.abs(otherOrtho.x)+math.abs(otherOrtho.z))) - (otherLength/2) * (otherVectorToWp.z/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z)))};

otherBoundingBox[4] ={ x = otherPos.x + (otherWidth/2) * ( otherOrtho.x / (math.abs(otherOrtho.x)+math.abs(otherOrtho.z))) - (otherLength/2) * (otherVectorToWp.x/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z))),
y = 0,
z = otherPos.z + (otherWidth/2) * ( otherOrtho.z / (math.abs(otherOrtho.x)+math.abs(otherOrtho.z))) - (otherLength/2) * (otherVectorToWp.z/(math.abs(otherVectorToWp.x)+math.abs(otherVectorToWp.z)))};

if AutoDrive:BoxesIntersect(boundingBox, otherBoundingBox) == true then
return true;
end;
end;
return false;
end;

function AutoDrivePathFinder:onFieldDataUpdateFinished(pf, fielddata, cell)
local totalFruitPixels = 0;
if fielddata ~= nil then
Expand Down
10 changes: 10 additions & 0 deletions FS19_AutoDrive/scripts/AutoDriveSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ AutoDrive.settings.driverWages = {
translate= false
};

AutoDrive.settings.smoothField = {
values= {false, true},
texts= {"gui_ad_no", "gui_ad_yes"},
default= 2,
current= 2,
text= "gui_ad_smoothField",
tooltip= "gui_ad_smoothField_tooltip",
translate= true
};

function AutoDrive:getSetting(settingName)
if AutoDrive.settings[settingName] ~= nil then
local setting = AutoDrive.settings[settingName]
Expand Down
2 changes: 2 additions & 0 deletions FS19_AutoDrive/translations/translation_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@
<text name="gui_ad_showHelp_tooltip" text="Tastenbelegung im F1 Hilfsfenster anzeigen" />
<text name="gui_ad_driverWages" text="Fahrer Lohn" />
<text name="gui_ad_driverWages_tooltip" text="Mit diesem Faktor werden die Lohnkosten der Fahrer multipliziert" />
<text name="gui_ad_smoothField" text="Feldstrecken glätten" />
<text name="gui_ad_smoothField_tooltip" text="Strecken zu/vom Drescher werden geglättet - Experimental" />
</texts>
</l10n>
2 changes: 2 additions & 0 deletions FS19_AutoDrive/translations/translation_en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@
<text name="gui_ad_showHelp_tooltip" text="Display keybinding in F1 window" />
<text name="gui_ad_driverWages" text="Driver wages" />
<text name="gui_ad_driverWages_tooltip" text="Driver wages will be multiplied with this value" />
<text name="gui_ad_smoothField" text="Smoother field driving" />
<text name="gui_ad_smoothField_tooltip" text="Generated field courses to and from combine will be smoothed (experimental)" />
</texts>
</l10n>
12 changes: 4 additions & 8 deletions FS19_AutoDrive/translations/translation_fr.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<l10n>
<translationContributors>Anonymous</translationContributors>
<translationContributors>Anonymous-any</translationContributors>
<texts>
<text name="UNKNOWN" text="Inconnu" />
<text name="input_ADToggleHud" text="AD: Montrer/cacher HUD" />
Expand Down Expand Up @@ -78,15 +78,11 @@
<text name="gui_ad_findDriver" text="Trouver un chauffeur" />
<text name="gui_ad_findDriver_tooltip" text="Recherche du chauffeur le plus proche (Ignore la destination)" />
<text name="gui_ad_gui_scale" text="Taille du HUD AutoDrive" />
<text name="gui_ad_gui_scale_tooltip" text="Définit (par défaut) le paramètre de l'échelle de l'interface graphique utilisé en jeu" />
<text name="gui_ad_gui_scale_tooltip" text="Définit (par défaut) le paramètre de l'échelle de l'interface graphique utilisé en jeu" />
<text name="gui_ad_exitField" text="Sortie de champ" />
<text name="gui_ad_exitField_tooltip" text="Stratégie de sortie au champ après le déchargement - Commencer, peu après le point de départ, le point le plus proche" />
<text name="gui_ad_default" text="Par défaut" />
<text name="gui_ad_after_start" text="Derrière le départ" />
<text name="gui_ad_closest" text="Le plus proche" />
<text name="gui_ad_showHelp" text="Afficher l'aide" />
<text name="gui_ad_showHelp_tooltip" text="Afficher l'affectation des touches dans la fenêtre d'aide F1" />
<text name="gui_ad_driverWages" text="Salaire du chauffeur" />
<text name="gui_ad_driverWages_tooltip" text="Avec cette option, les coûts salariaux du conducteur sont multipliés" />
<text name="gui_ad_after_start" text="Après le départ" />
<text name="gui_ad_closest" text="Le plus proche" />
</texts>
</l10n>
6 changes: 1 addition & 5 deletions FS19_AutoDrive/translations/translation_ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@
<text name="gui_ad_exitField_tooltip" text="Способ выезда с поля при разгрузке" />
<text name="gui_ad_default" text="Обычный" />
<text name="gui_ad_after_start" text="За стартом" />
<text name="gui_ad_closest" text="Ближайшая точка" />
<text name="gui_ad_showHelp" text="Отображать подсказки" />
<text name="gui_ad_showHelp_tooltip" text="Отображать сочетания клавиш в окне подсказок по F1" />
<text name="gui_ad_driverWages" text="Зарплата водителя" />
<text name="gui_ad_driverWages_tooltip" text="Заработная плата водителя будет умножена на указанное значение" />
<text name="gui_ad_closest" text="Ближайшая точка" />
</texts>
</l10n>
File renamed without changes.
File renamed without changes.
78 changes: 78 additions & 0 deletions courses/Ravenport/AutoDrive_Ravenport_config.xml

Large diffs are not rendered by default.

Loading

0 comments on commit e87f5ee

Please sign in to comment.