Skip to content

Commit

Permalink
Merge branch 'dev_RC' into dev_axel32019
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel32019 committed Jan 1, 2025
2 parents 8357da4 + e8611d3 commit 0112f84
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 48 deletions.
1 change: 1 addition & 0 deletions scripts/Hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ function AutoDriveHud:drawHud(vehicle)
self.lastUIScale = uiScale

if self.hudElements ~= nil then
new2DLayer()
for _, element in ipairs(self.hudElements) do -- `ipairs` is important, as we want "index-value pairs", not "key-value pairs". https://stackoverflow.com/a/55109411
element:onDraw(vehicle, uiScale)
end
Expand Down
13 changes: 6 additions & 7 deletions scripts/Hud/PullDownList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function ADPullDownList:onDraw(vehicle, uiScale)

renderText(posX, posY, adFontSize, text)
else
drawFilledRect(self.position.x, self.expandedBottom, self.size.width, self.expandedSize.height, 0, 0, 0, 0.9)
self.ovTop:render()
self.ovStretch:render()
self.ovBottom:render()
Expand Down Expand Up @@ -764,15 +765,13 @@ function ADPullDownList:expand(vehicle)
self.expandedSize.height = math.min(itemCount + ADPullDownList.MIN_SHOWN, ADPullDownList.MAX_SHOWN) * AutoDrive.Hud.listItemHeight + self.size.height / 2

if self.direction == ADPullDownList.EXPANDED_UP then
self.ovTop = Overlay.new(self.imageBGTop, self.position.x, self.position.y + self.expandedSize.height - self.size.height / 2, self.size.width, self.size.height / 2)
self.ovStretch = Overlay.new(self.imageBGStretch, self.position.x, self.position.y + (self.size.height / 2), self.size.width, self.expandedSize.height - self.size.height)
self.ovBottom = Overlay.new(self.imageBGBottom, self.position.x, self.position.y, self.size.width, self.size.height / 2)
self.expandedBottom = self.position.y
else
self.ovTop = Overlay.new(self.imageBGTop, self.position.x, self.position.y + self.size.height / 2, self.size.width, self.size.height / 2)
self.ovStretch = Overlay.new(self.imageBGStretch, self.position.x, self.position.y + (self.size.height / 2) * 3 - self.expandedSize.height, self.size.width, self.expandedSize.height - self.size.height)
self.ovBottom = Overlay.new(self.imageBGBottom, self.position.x, self.position.y - self.expandedSize.height + self.size.height, self.size.width, self.size.height / 2)
self.expandedBottom = self.position.y - self.expandedSize.height + self.size.height
end

self.ovTop = Overlay.new(self.imageBGTop, self.position.x, self.expandedBottom + self.expandedSize.height - self.size.height / 2, self.size.width, self.size.height / 2)
self.ovStretch = Overlay.new(self.imageBGStretch, self.position.x, self.expandedBottom + self.size.height / 2, self.size.width, self.expandedSize.height - self.size.height)
self.ovBottom = Overlay.new(self.imageBGBottom, self.position.x, self.expandedBottom, self.size.width, self.size.height / 2)
self:setSelected(vehicle)
end
end
Expand Down
61 changes: 40 additions & 21 deletions scripts/Modules/DrivePathModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ function ADDrivePathModule:update(dt)
self:checkIfStuck(dt)

if self:isCloseToWaypoint() then
local reverseStart, _ = self:checkForReverseSection()
if reverseStart then
self.isReversing = not self.isReversing
local isReverse, _, _ = self:checkForReverseSection()
if isReverse and not self.isReversing then
self.isReversing = true
self.vehicle.ad.specialDrivingModule:reset()
self.vehicle.ad.specialDrivingModule.currentWayPointIndex = self:getCurrentWayPointIndex() + 1
else
Expand Down Expand Up @@ -211,27 +211,35 @@ function ADDrivePathModule:isCloseToWaypoint()
end

local maxSkipWayPoints = 1
local wp_ahead = self:getNextWayPoint()
local wp_current = self:getCurrentWayPoint()
local isReverseStart = wp_ahead ~= nil and wp_ahead.incoming ~= nil and (not table.contains(wp_ahead.incoming, wp_current.id))
if isReverseStart then
maxSkipWayPoints = 0
end

AutoDrive.debugPrint(self.vehicle, AutoDrive.DC_PATHINFO, "ADDrivePathModule:isCloseToWaypoint - start, wpIdx=%d, isReverseStart=%s", self:getCurrentWayPointIndex(), tostring(isReverseStart))

for i = 0, maxSkipWayPoints do
if self.wayPoints[self:getCurrentWayPointIndex() + i] ~= nil then
local distanceToCurrentWp = MathUtil.vector2Length(x - self.wayPoints[self:getCurrentWayPointIndex() + i].x, z - self.wayPoints[self:getCurrentWayPointIndex() + i].z)
if distanceToCurrentWp < self.min_distance then --and i == 0
AutoDrive.debugPrint(self.vehicle, AutoDrive.DC_PATHINFO, "ADDrivePathModule:isCloseToWaypoint(%d/%d) - true distanceToCurrentWp=%f min_distance=%f", i+1, maxSkipWayPoints+1, distanceToCurrentWp, self.min_distance)
return true
end
-- Check if the angle between vehicle and current wp and current wp to next wp is over 90° - then we should already make the switch
if i == 1 then
local wp_ahead = self:getNextWayPoint()
local wp_current = self:getCurrentWayPoint()

if i == 1 and not isReverseStart then
local angle = AutoDrive.angleBetween({x = wp_ahead.x - wp_current.x, z = wp_ahead.z - wp_current.z}, {x = wp_current.x - x, z = wp_current.z - z})
angle = math.abs(angle)

local isReverseStart = wp_ahead.incoming ~= nil and (not table.contains(wp_ahead.incoming, wp_current.id))
if angle >= 135 and not isReverseStart then
if angle >= 135 then
AutoDrive.debugPrint(self.vehicle, AutoDrive.DC_PATHINFO, "ADDrivePathModule:isCloseToWaypoint(%d/%d) - true angle=%f", i+1, maxSkipWayPoints+1, angle)
return true
end
end
end
end
AutoDrive.debugPrint(self.vehicle, AutoDrive.DC_PATHINFO, "ADDrivePathModule:isCloseToWaypoint - false")
return false
end

Expand Down Expand Up @@ -633,9 +641,9 @@ function ADDrivePathModule:switchToNextWayPoint()
self:setCurrentWayPointIndex(self:getNextWayPointIndex())
self.minDistanceToNextWp = math.huge

local _, reverseEnd = self:checkForReverseSection()
if reverseEnd and self.isReversing then
self.isReversing = false --not self.isReversing
local isReverse, _, _ = self:checkForReverseSection()
if not isReverse and self.isReversing then
self.isReversing = false
self.vehicle.ad.specialDrivingModule:reset()
self.vehicle.ad.specialDrivingModule.currentWayPointIndex = self:getCurrentWayPointIndex()
end
Expand Down Expand Up @@ -767,25 +775,36 @@ function ADDrivePathModule:handleBeingStuck()
end

function ADDrivePathModule:checkForReverseSection()
local reverseStart = false
local reverseEnd = false
local isReverseSectionStart = false
local isReverseSectionEnd = false
local isReverseSection = false

if self.wayPoints ~= nil and #self.wayPoints > self:getCurrentWayPointIndex() + 1 and self:getCurrentWayPointIndex() > 1 then
local wp_ahead = self.wayPoints[self:getCurrentWayPointIndex() + 1]
local wp_current = self.wayPoints[self:getCurrentWayPointIndex() - 0]
local wp_ref = self.wayPoints[self:getCurrentWayPointIndex() - 1]
local isReverseStart = (wp_ahead.incoming ~= nil and (not table.contains(wp_ahead.incoming, wp_current.id))) or (wp_ahead.isReverse ~= nil and wp_ahead.isReverse == true)
local isReverseEnd = wp_ahead.incoming ~= nil and wp_current.incoming ~= nil and table.contains(wp_ahead.incoming, wp_current.id) and not table.contains(wp_current.incoming, wp_ref.id)
local refIsReverse = wp_current.incoming ~= nil and not table.contains(wp_current.incoming, wp_ref.id)
local currentIsReverse = wp_ahead.incoming ~= nil and not table.contains(wp_ahead.incoming, wp_current.id)
local isReverse = currentIsReverse or (wp_ahead.isReverse ~= nil and wp_ahead.isReverse == true)
local isReverseStart = not refIsReverse and currentIsReverse
local isReverseEnd = refIsReverse and not currentIsReverse

local angle = AutoDrive.angleBetween({x = wp_ahead.x - wp_current.x, z = wp_ahead.z - wp_current.z}, {x = wp_current.x - wp_ref.x, z = wp_current.z - wp_ref.z})

angle = math.abs(angle)
if (angle > 100 and isReverseStart) or (wp_ahead.isReverse ~= nil and wp_ahead.isReverse == true) then
reverseStart = true
if (angle > 100 and isReverseStart) or Utils.getNoNil(wp_ahead.isReverse, false) then
isReverseSectionStart = true
end
if (angle > 100 and isReverseEnd) or (wp_ahead.isForward ~= nil and wp_ahead.isForward == true) then
reverseEnd = true
if (angle > 100 and isReverseEnd) or Utils.getNoNil(wp_ahead.isForward, false) then
isReverseSectionEnd = true
end
if isReverse or Utils.getNoNil(wp_ahead.isReverse, false) then
isReverseSection = true
end
AutoDrive.debugPrint(self.vehicle, AutoDrive.DC_PATHINFO, "ADDrivePathModule:checkForReverseSection - wpIdx=%d, angle=%f, refIsReverse=%s, currentIsReverse=%s, isReverse=%s, isReverseStart=%s, isReverseEnd=%s", self:getCurrentWayPointIndex(), angle, tostring(refIsReverse), tostring(currentIsReverse), tostring(isReverse), tostring(isReverseStart), tostring(isReverseEnd))
else
isReverseSection = self.isReversing -- preserve setting for first/last waypoint
end

return reverseStart, reverseEnd
return isReverseSection, isReverseSectionStart, isReverseSectionEnd
end
2 changes: 1 addition & 1 deletion scripts/Modules/SpecialDrivingModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function ADSpecialDrivingModule:checkWayPointReached()
local minDistance = 9
local storedIndex = self.vehicle.ad.drivePathModule.currentWayPoint
self.vehicle.ad.drivePathModule.currentWayPoint = self.vehicle.ad.drivePathModule.currentWayPoint + 1
local reverseStart, reverseEnd = self.vehicle.ad.drivePathModule:checkForReverseSection()
local _, _, reverseEnd = self.vehicle.ad.drivePathModule:checkForReverseSection()
self.vehicle.ad.drivePathModule.currentWayPoint = storedIndex
if self.reverseSolo then
minDistance = AutoDrive.defineMinDistanceByVehicleType(self.vehicle)
Expand Down
13 changes: 3 additions & 10 deletions scripts/Modules/StateModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ function ADStateModule:reset()

self.startHelper = false

if self.vehicle.getLastJob then
self.usedHelper = ADStateModule.HELPER_AI
elseif self.vehicle.cpStartStopDriver then
if self.vehicle.cpStartStopDriver then
self.usedHelper = ADStateModule.HELPER_CP
elseif self.vehicle.acParameters then
self.usedHelper = ADStateModule.HELPER_AIVE
elseif self.vehicle.getLastJob then
self.usedHelper = ADStateModule.HELPER_AI
else
self.usedHelper = ADStateModule.HELPER_NONE
end
Expand Down Expand Up @@ -172,12 +172,6 @@ function ADStateModule:readFromXMLFile(xmlFile, key)
self.bunkerUnloadType = bunkerUnloadType
end

local usedHelper = xmlFile:getValue(key .. "#usedHelper")
if usedHelper ~= nil and self:isHelperTypeValid(usedHelper) then
self.usedHelper = usedHelper
end


-- local automaticUnloadTarget = xmlFile:getValue(key .. "#automaticUnloadTarget")
-- if automaticUnloadTarget ~= nil then
-- self.automaticUnloadTarget = automaticUnloadTarget
Expand Down Expand Up @@ -206,7 +200,6 @@ function ADStateModule:saveToXMLFile(xmlFile, key)
xmlFile:setValue(key .. "#driverName", self.driverName)
xmlFile:setValue(key .. "#lastActive", self.active)
xmlFile:setValue(key .. "#AIVElastActive", false)
xmlFile:setValue(key .. "#usedHelper", self.usedHelper)
xmlFile:setValue(key .. "#bunkerUnloadType", self.bunkerUnloadType)
-- xmlFile:setValue(key .. "#automaticUnloadTarget", self.automaticUnloadTarget)
-- xmlFile:setValue(key .. "#automaticPickupTarget", self.automaticPickupTarget)
Expand Down
3 changes: 0 additions & 3 deletions scripts/Sensors/CollSensorSplit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,11 @@ function ADCollSensorSplit:collisionTestCallback(transformId)
if collisionObject ~= self and collisionObject ~= self.vehicle and not AutoDrive:checkIsConnected(self.vehicle:getRootVehicle(), collisionObject) then
if unloadDriver == nil or (collisionObject ~= unloadDriver and (not AutoDrive:checkIsConnected(unloadDriver:getRootVehicle(), collisionObject))) then
self.newHit = true
-- return true
end
end
else
self.newHit = true
-- return true
end
-- return false
end

function ADCollSensorSplit:buildBoxShape(x, y, z, width, height, length, vecZ, vecX)
Expand Down
5 changes: 4 additions & 1 deletion scripts/Specialization.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ function AutoDrive.initSpecialization()
schemaSavegame:register(XMLValueType.STRING, "vehicles.vehicle(?).AutoDrive#driverName", "driverName")
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?).AutoDrive#lastActive", "lastActive")
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?).AutoDrive#AIVElastActive", "AIVElastActive")
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).AutoDrive#usedHelper", "usedHelper")
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).AutoDrive#parkDestination", "parkDestination")
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).AutoDrive#bunkerUnloadType", "bunkerUnloadType")
if AutoDrive.automaticUnloadTarget then
Expand Down Expand Up @@ -755,6 +754,10 @@ function AutoDrive:onEnterVehicle(isControlling)
end

function AutoDrive:onLeaveVehicle(wasEntered)
AutoDrive.debugPrint(self, AutoDrive.DC_VEHICLEINFO, "AutoDrive:onLeaveVehicle wasEntered: %s", tostring(wasEntered))
if not wasEntered then
return
end
if not AutoDrive.getSetting("RecordWhileNotInVehicle") then
if self.ad ~= nil and self.ad.stateModule ~= nil then
self.ad.stateModule:disableCreationMode()
Expand Down
2 changes: 0 additions & 2 deletions scripts/Utils/CollisionDetectionUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,8 @@ function ADDimensionSensor:getRealVehicleDimensions_Callback(transformId)
local collisionObject = g_currentMission.nodeToObject[transformId]
if collisionObject ~= nil and collisionObject == self.vehicle then
self.selfHits = self.selfHits + 1
return true
end
end
return false
end

function AutoDrive.getVehicleDimensions(vehicle, force)
Expand Down
5 changes: 2 additions & 3 deletions scripts/Utils/UtilFuncs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,16 @@ string.randomCharset = {
--- Calculates a much better result of world height by using a raycast.
--- The original function `getTerrainHeightAtWorldPos` returns wrong results if, for example, the terrain underneath a road has gaps.
--- As the raycast uses a callback function, this function must be splitted in two parts.
--- We're using collision mask of 12 (bit 3&4) - see: ADCollSensor.mask_static_world*
--- see: https://gdn.giants-software.com/thread.php?categoryId=3&threadId=8381
--- @param x number X Coordinate
--- @param z number Z Coordinate
--- @return number Height of the terrain
function AutoDrive:getTerrainHeightAtWorldPos(x, z, startingHeight)
self.raycastHeight = nil
local collisionMask = CollisionFlag.DEFAULT + CollisionFlag.ROAD + CollisionFlag.TERRAIN
-- get a starting height with the basic function
local startHeight = startingHeight or getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 1, z)
-- do a raycast from a bit above y
raycastClosest(x, startHeight + 3, z, 0, -1, 0, 5, "getTerrainHeightAtWorldPos_Callback", self, 12)
raycastClosest(x, startHeight + 3, z, 0, -1, 0, 5, "getTerrainHeightAtWorldPos_Callback", self, collisionMask)
return self.raycastHeight or startHeight
end

Expand Down

0 comments on commit 0112f84

Please sign in to comment.