Skip to content

Commit

Permalink
Release 1.0.6.2
Browse files Browse the repository at this point in the history
Some code cleaning.
  • Loading branch information
Stephan-S committed Oct 7, 2019
1 parent b092966 commit 43ed2e1
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 722 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.6.1</version>
<version>1.0.6.2</version>
<multiplayer supported="true"/>
<iconFilename>store.dds</iconFilename>
<extraSourceFiles>
Expand Down
29 changes: 2 additions & 27 deletions FS19_AutoDrive/scripts/AutoDrive.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AutoDrive = {};
AutoDrive.Version = "1.0.6.1";
AutoDrive.Version = "1.0.6.2";
AutoDrive.config_changed = false;

AutoDrive.directory = g_currentModDirectory;
Expand Down Expand Up @@ -289,9 +289,6 @@ function init(self)
self.ad.nToolTipWait = 300;
self.ad.nToolTipTimer = 6000;
self.ad.sToolTip = "";

self.ad.destinationPrintTimer = 0;
self.ad.lastPrintedModeTimer = 0;

self.ad.choosingDestination = false;
self.ad.chosenDestination = "";
Expand Down Expand Up @@ -473,14 +470,6 @@ function AutoDrive:onUpdate(dt)
AutoDrive:handleCombineHarvester(self, dt)
end;

if self.ad.destinationPrintTimer > 0 then
self.ad.destinationPrintTimer = self.ad.destinationPrintTimer - dt;
end;

if self.ad.lastPrintedModeTimer > 0 then
self.ad.lastPrintedModeTimer = self.ad.lastPrintedModeTimer - dt;
end;

local driverWages = AutoDrive:getSetting("driverWages");
local spec = self.spec_aiVehicle
if self.isServer and spec ~= nil then
Expand Down Expand Up @@ -562,21 +551,7 @@ function AutoDrive:onDrawControlledVehicle(vehicle)
if AutoDrive.Hud.showHud == true then
AutoDrive.Hud:drawHud(vehicle);
end;
end;

-- local worldX,worldY,worldZ = getWorldTranslation( vehicle.components[1].node );
-- local rx,ry,rz = localDirectionToWorld(vehicle.components[1].node, 0,0,1);
-- local vehicleVector = {x= rx ,z= rz};
-- local ahead = {x=worldX + 20*rx, y=worldY+5, z=worldZ + 20*rz};
-- local current = {x=worldX, y=worldY+5, z=worldZ };

-- local vehicleNormalVector = {x= -vehicleVector.z ,z= vehicleVector.x};
-- local right = {x=worldX + 20*vehicleNormalVector.x, y=worldY+5, z=worldZ + 20*vehicleNormalVector.z};

-- AutoDrive:drawLine(ahead, current, 0, 1, 0, 1);
-- AutoDrive:drawLine(right, current, 0, 0, 1, 1);
--print("TurnRadius: " .. AIVehicleUtil.getAttachedImplementsMaxTurnRadius(vehicle));

end;
end;

function AutoDrive:onDrawCreationMode(vehicle)
Expand Down
2 changes: 0 additions & 2 deletions FS19_AutoDrive/scripts/AutoDriveDriveFuncs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ function AutoDrive:checkActiveAttributesSet(vehicle)

if vehicle.ad.isActive == false then
if vehicle.currentHelper == nil then
--vehicle.spec_aiVehicle.isActive = false;

if vehicle.steeringEnabled == false then
vehicle.steeringEnabled = true;
end
Expand Down
93 changes: 3 additions & 90 deletions FS19_AutoDrive/scripts/AutoDriveFunc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,34 +322,17 @@ end

function AutoDrive:detectTraffic(vehicle)
local x,y,z = getWorldTranslation( vehicle.components[1].node );
--create bounding box to check for vehicle
local rx,ry,rz = localDirectionToWorld(vehicle.components[1].node, math.sin(vehicle.rotatedTime),0,math.cos(vehicle.rotatedTime));
local vehicleVector = {x=rx ,z= rz};
local width = vehicle.sizeWidth;
local length = vehicle.sizeLength;
local ortho = { x=-vehicleVector.z, z=vehicleVector.x };
local lookAheadDistance = math.min(vehicle.lastSpeedReal*3600/40, 1) * 10 + 2;

local approachingLastWayPoints = false;
if vehicle.ad.wayPoints ~= nil and vehicle.ad.wayPoints[vehicle.ad.currentWayPoint] ~= nil and vehicle.ad.wayPoints[vehicle.ad.currentWayPoint+2] == nil then
width = width * 2 / 3;
approachingLastWayPoints = true;
end;

local boundingBox = {};
boundingBox[1] ={ x = x + (width/2) * ortho.x,
y = y+2,
z = z + (width/2) * ortho.z};
boundingBox[2] ={ x = x - (width/2) * ortho.x,
y = y+2,
z = z - (width/2) * ortho.z};
boundingBox[3] ={ x = x - (width/2) * ortho.x + (length/2 + lookAheadDistance) * vehicleVector.x,
y = y+2,
z = z - (width/2) * ortho.z + (length/2 + lookAheadDistance) * vehicleVector.z };
boundingBox[4] ={ x = x + (width/2) * ortho.x + (length/2 + lookAheadDistance) * vehicleVector.x,
y = y+2,
z = z + (width/2) * ortho.z + (length/2 + lookAheadDistance) * vehicleVector.z};

if AutoDrive:getSetting("enableTrafficDetection") == true then --GC have now updated their triggers. so remove this: and (getDistanceToTargetPosition(vehicle) > 15 and getDistanceToUnloadPosition(vehicle) > 15)
local box = {};
box.center = {};
Expand All @@ -375,8 +358,7 @@ function AutoDrive:detectTraffic(vehicle)

local boxCenter = { x = x + (((length/2 + box.size[3] + 1) * vehicleVector.x)),
y = y+heightOffset,
z = z + (((length/2 + box.size[3] + 1) * vehicleVector.z)) };

z = z + (((length/2 + box.size[3] + 1) * vehicleVector.z)) };

boxCenter.y = math.max(getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, boxCenter.x, 1, boxCenter.z), y) + 2.2;
local rx,ry,rz = getWorldRotation(vehicle.components[1].node)
Expand All @@ -393,77 +375,8 @@ function AutoDrive:detectTraffic(vehicle)
end;
end;

--AutoDrive:drawLine(boundingBox[1], boundingBox[2], 0, 0, 0, 1);
--AutoDrive:drawLine(boundingBox[2], boundingBox[3], 0, 0, 0, 1);
--AutoDrive:drawLine(boundingBox[3], boundingBox[4], 0, 0, 0, 1);
--AutoDrive:drawLine(boundingBox[4], boundingBox[1], 0, 0, 0, 1);

for _,other in pairs(g_currentMission.vehicles) do
if other ~= vehicle then --and other ~= vehicle.ad.currentCombine
local isAttachedToMe = AutoDrive:checkIsConnected(vehicle, other);
local isAttachedToMyCombine = AutoDrive:checkIsConnected(vehicle.ad.currentCombine, other) and (vehicle.ad.combineState == AutoDrive.DRIVE_TO_COMBINE or vehicle.ad.combineState == AutoDrive.PREDRIVE_COMBINE); --

if isAttachedToMe == false and other.components ~= nil and isAttachedToMyCombine == false then
if other.sizeWidth == nil then
--print("vehicle " .. other.configFileName .. " has no width");
else
if other.sizeLength == nil then
--print("vehicle " .. other.configFileName .. " has no length");
else
if other.rootNode == nil then
--print("vehicle " .. other.configFileName .. " has no root node");
else

local otherWidth = other.sizeWidth;
local otherLength = other.sizeLength;
local otherPos = {};
otherPos.x,otherPos.y,otherPos.z = getWorldTranslation( other.components[1].node );

local distance = AutoDrive:getDistance(x,z,otherPos.x,otherPos.z);
if distance < 100 then
local rx,ry,rz = localDirectionToWorld(other.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 = y;
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 = y,
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 = y,
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 = y,
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 = y,
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)))};


--AutoDrive:drawLine(otherBoundingBox[1], otherBoundingBox[2], 0, 0, 1, 1);
--AutoDrive:drawLine(otherBoundingBox[2], otherBoundingBox[3], 0, 0, 1, 1);
--AutoDrive:drawLine(otherBoundingBox[3], otherBoundingBox[4], 0, 0, 1, 1);
--AutoDrive:drawLine(otherBoundingBox[4], otherBoundingBox[1], 0, 0, 1, 1);

if AutoDrive:BoxesIntersect(boundingBox, otherBoundingBox) == true then
return true;
end;
end;
end;
end;
end;
end;
end;
if AutoDrive:checkForVehicleCollision(vehicle, {}, true) then
return true;
end;

return false;
Expand Down
9 changes: 5 additions & 4 deletions FS19_AutoDrive/scripts/AutoDriveHud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ end;
function AutoDriveHud:createMapHotspot(vehicle)
if vehicle.ad.isActive and vehicle.ad.mapHotSpot == nil then
local hotspotX, _, hotspotZ = getWorldTranslation(vehicle.rootNode)
local _, textSize = getNormalizedScreenValues(0, 9)
local _, textOffsetY = getNormalizedScreenValues(0, 24)
local width, height = getNormalizedScreenValues(18, 18)
local _, textSize = getNormalizedScreenValues(0, 6) --Textsize local _, textSize = getNormalizedScreenValues(0, 9)
local _, textOffsetY = getNormalizedScreenValues(0, 10) --Distance to icon -- local _, textOffsetY = getNormalizedScreenValues(0, 24)
local width, height = getNormalizedScreenValues(10, 10) --Triggersize -- local width, height = getNormalizedScreenValues(18, 18)
vehicle.ad.mapHotspot = MapHotspot:new("adDriver", MapHotspot.CATEGORY_AI)
vehicle.ad.mapHotspot:setSize(width, height)
vehicle.ad.mapHotspot:setLinkedNode(vehicle.components[1].node)
Expand All @@ -374,9 +374,10 @@ function AutoDriveHud:createMapHotspot(vehicle)
end;
vehicle.ad.mapHotspot:setImage(nil, getNormalizedUVs(MapHotspot.UV.HELPER), {0.052, 0.1248, 0.672, 1})
vehicle.ad.mapHotspot:setBackgroundImage(nil, getNormalizedUVs(MapHotspot.UV.HELPER))
vehicle.ad.mapHotspot:setIconScale(0.7)
vehicle.ad.mapHotspot:setIconScale(0.4) --Iconsize vehicle.ad.mapHotspot:setIconScale(0.7)
vehicle.ad.mapHotspot:setTextOptions(textSize, nil, textOffsetY, {1, 1, 1, 1}, Overlay.ALIGN_VERTICAL_MIDDLE)
vehicle.ad.mapHotspot:setColor({0.0, 0.569, 0.835, 1});

g_currentMission:addMapHotspot(vehicle.ad.mapHotspot)
end;
end
Expand Down
Loading

0 comments on commit 43ed2e1

Please sign in to comment.