Skip to content

Commit

Permalink
Merge pull request #762 from Stephan-S/dev-iwan
Browse files Browse the repository at this point in the history
AutoDrive 2.0.0.9
  • Loading branch information
Iwan1803 authored Dec 4, 2022
2 parents 91c9490 + 40707c6 commit 16a890b
Show file tree
Hide file tree
Showing 58 changed files with 1,116 additions and 289 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# FS22_AutoDrive
FS22 version of the AutoDrive mod

### Latest Release: 2.0.0.7
### Latest Release: 2.0.0.9
![GitHub all releases](https://img.shields.io/github/downloads/Stephan-S/FS22_AutoDrive/total?label=Downloads&style=plastic)
[Latest Release](https://github.com/Stephan-S/FS22_AutoDrive/releases/latest)
Direct Download: https://github.com/Stephan-S/FS22_AutoDrive/releases/download/2.0.0.7/FS22_AutoDrive.zip
Direct Download: https://github.com/Stephan-S/FS22_AutoDrive/releases/download/2.0.0.9/FS22_AutoDrive.zip

## Discord Server:
For help & support, feel free to join us on Discord:
Expand All @@ -16,10 +16,10 @@ For now, there is no general link for the team, so each contributer can post his
But remember, this is absolutely not required. We value any issues and feature requests the same!
And to all who do donate: Thank you very much :-)

#### Stephan (Founder & Modder):
#### Stephan (Founder):
https://www.paypal.me/StephanSchlosser

#### Axel (Co-Modder)
#### Axel (Modder)

#### Iwan1803 (Community Manager, Supporter & Tester):
https://www.tipeeestream.com/iwan1803/tip
Expand Down
10 changes: 9 additions & 1 deletion gui/debugSettingsPage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,20 @@
<!-- <GuiElement type="text" profile="autoDriveDebugSettingsCheckboxToggleText" text="gui_ad_debugChannelBGA" onCreate="onCreateAutoDriveText11" /> -->
<!-- </GuiElement> -->
<!-- </GuiElement> -->
<GuiElement type="listItem" profile="autoDriveDebugSettingsCheckbox" onCreate="onCreateCheckbox" onCreateArgs="2048">
<GuiElement type="toggleButton" profile="autoDriveDebugSettingsCheckboxToggle" onClick="onClickToggle">
<GuiElement type="button" profile="autoDriveDebugSettingsCheckboxToggleTick" />
<GuiElement type="button" profile="autoDriveDebugSettingsCheckboxToggleUntick" />
<GuiElement type="bitmap" profile="autoDriveDebugSettingsCheckboxToggleIcon3" imageUVs="480px 100px 48px 40px" />
<GuiElement type="text" profile="autoDriveDebugSettingsCheckboxToggleText" text="gui_ad_debugChannelTrains" onCreate="onCreateAutoDriveText12" />
</GuiElement>
</GuiElement>
<GuiElement type="listItem" profile="autoDriveDebugSettingsCheckbox" onCreate="onCreateCheckbox" onCreateArgs="65535">
<GuiElement type="toggleButton" profile="autoDriveDebugSettingsCheckboxToggle" onClick="onClickToggle">
<GuiElement type="button" profile="autoDriveDebugSettingsCheckboxToggleTick" />
<GuiElement type="button" profile="autoDriveDebugSettingsCheckboxToggleUntick" />
<GuiElement type="bitmap" profile="autoDriveDebugSettingsCheckboxToggleIcon" imageUVs="0px 128px 128px 128px" />
<GuiElement type="text" profile="autoDriveDebugSettingsCheckboxToggleText" text="gui_ad_debugChannelAll" onCreate="onCreateAutoDriveText12" />
<GuiElement type="text" profile="autoDriveDebugSettingsCheckboxToggleText" text="gui_ad_debugChannelAll" onCreate="onCreateAutoDriveText13" />
</GuiElement>
</GuiElement>
</GuiElement>
Expand Down
8 changes: 8 additions & 0 deletions gui/guiProfiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@
<Profile name="autoDriveDebugSettingsCheckboxToggleUntick" extends="ingameMenuMPActionsListPermissionCheckboxUntick">
</Profile>

<!-- new used -->
<Profile name="autoDriveDebugSettingsCheckboxToggleIcon3" extends="baseReference" with="lightFrame">
<Value name="size" value="48px 48px" />
<Value name="position" value="48px 0px" />
<Value name="imageFilename" value="g_baseUIFilename" />
<Value name="frameThickness" value="0 0 1dp 0" />
</Profile>

<!-- new used -->
<Profile name="autoDriveDebugSettingsCheckboxToggleIcon2" extends="baseReference" with="lightFrame">
<Value name="size" value="48px 48px" />
Expand Down
8 changes: 8 additions & 0 deletions gui/userSettingsPage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
<GuiElement type="bitmap" profile="multiTextOptionSettingsBg" />
<GuiElement type="bitmap" profile="baseReference" position="730px 0px" size="50px 50px"/>
</GuiElement>
<GuiElement type="multiTextOption" profile="multiTextOptionSettings" onCreate="onCreateAutoDriveSetting" onClick="onOptionChange" name="scaleLines" toolTipElementId="ingameMenuHelpBoxText">
<GuiElement type="button" profile="multiTextOptionSettingsLeft" />
<GuiElement type="button" profile="multiTextOptionSettingsRight" />
<GuiElement type="text" profile="multiTextOptionSettingsText" />
<GuiElement type="text" profile="multiTextOptionSettingsTitle" position="27px 0px" />
<GuiElement type="bitmap" profile="multiTextOptionSettingsBg" />
<GuiElement type="bitmap" profile="baseReference" position="730px 0px" size="50px 50px"/>
</GuiElement>
</GuiElement>
</GuiElement>

Expand Down
4 changes: 2 additions & 2 deletions modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="62">
<modDesc descVersion="72">
<author>AutoDrive Team</author>
<title>
<en>AutoDrive</en>
Expand Down Expand Up @@ -32,7 +32,7 @@ Différents modes d'utilisation ont été ajoutés depuis les premières version
<![CDATA[Этот мод может быть использован для создания сети маршрутов для транспортных средств для автономного вождения. После настройки вы можете указать трактору, стоящему где-угодно рядом с сетью, проехать в любую точку, например, в магазин, поле №1 или в точку продажи.]]>
</ru>
</description>
<version>2.0.0.7</version>
<version>2.0.0.9</version>
<multiplayer supported="true" />
<iconFilename>icon.dds</iconFilename>
<extraSourceFiles>
Expand Down
5 changes: 3 additions & 2 deletions register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ source(Utils.getFilename("scripts/Modules/TrailerModule.lua", g_currentModDirect
source(Utils.getFilename("scripts/Modules/PathFinderModule.lua", g_currentModDirectory))
source(Utils.getFilename("scripts/Modules/StateModule.lua", g_currentModDirectory))
source(Utils.getFilename("scripts/Modules/RecordingModule.lua", g_currentModDirectory))
source(Utils.getFilename("scripts/Modules/TrainModule.lua", g_currentModDirectory))

source(Utils.getFilename("scripts/Modes/AbstractMode.lua", g_currentModDirectory))
source(Utils.getFilename("scripts/Modes/DriveToMode.lua", g_currentModDirectory))
Expand Down Expand Up @@ -165,7 +166,7 @@ function AutoDriveRegister.register()
end

for vehicleType, typeDef in pairs(g_vehicleTypeManager.types) do
if typeDef ~= nil and vehicleType ~= "locomotive" and vehicleType ~= "horse" and (not typeDef.hasADSpec == true) then
if typeDef ~= nil and vehicleType ~= "horse" and (not typeDef.hasADSpec == true) then
if AutoDrive.prerequisitesPresent(typeDef.specializations) then
--Logging.info('[AD] Attached to vehicleType "%s"', vehicleType)
if typeDef.specializationsByName[AutoDrive.ADSpecName] == nil then
Expand Down Expand Up @@ -193,7 +194,7 @@ function AutoDriveRegister.registerVehicleData()
end

for vehicleType, typeDef in pairs(g_vehicleTypeManager.types) do
if typeDef ~= nil and vehicleType ~= "locomotive" and vehicleType ~= "horse" and (not typeDef.hasADVDSpec == true) then
if typeDef ~= nil and vehicleType ~= "horse" and (not typeDef.hasADVDSpec == true) then
if AutoDriveVehicleData.prerequisitesPresent(typeDef.specializations) then
if typeDef.specializationsByName[AutoDrive.ADVDSpecName] == nil then
g_vehicleTypeManager:addSpecialization(vehicleType, AutoDrive.ADVDSpecName)
Expand Down
4 changes: 3 additions & 1 deletion scripts/AutoDrive.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AutoDrive = {}
AutoDrive.version = "2.0.0.7"
AutoDrive.version = "2.0.0.9"

AutoDrive.directory = g_currentModDirectory

Expand All @@ -16,6 +16,7 @@ AutoDrive.experimentalFeatures.colorAssignmentMode = false
AutoDrive.experimentalFeatures.UTurn = true
AutoDrive.experimentalFeatures.FoldImplements = true
AutoDrive.experimentalFeatures.RefuelOnlyAtValidStations = true
AutoDrive.experimentalFeatures.RecordWhileNotInVehicle = false

AutoDrive.dynamicChaseDistance = true
AutoDrive.smootherDriving = true
Expand Down Expand Up @@ -50,6 +51,7 @@ AutoDrive.DC_EXTERNALINTERFACEINFO = 128
AutoDrive.DC_RENDERINFO = 256
AutoDrive.DC_ROADNETWORKINFO = 512
AutoDrive.DC_BGA_MODE = 1024
AutoDrive.DC_TRAINS = 2048
AutoDrive.DC_ALL = 65535

AutoDrive.currentDebugChannelMask = AutoDrive.DC_NONE
Expand Down
11 changes: 7 additions & 4 deletions scripts/Events/InputEvent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,38 @@ function AutoDriveInputEventEvent.emptyNew()
return self
end

function AutoDriveInputEventEvent.new(vehicle, inputId)
function AutoDriveInputEventEvent.new(vehicle, inputId, farmId)
local self = AutoDriveInputEventEvent.emptyNew()
self.vehicle = vehicle
self.inputId = inputId
self.farmId = farmId
return self
end

function AutoDriveInputEventEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.vehicle))
streamWriteUInt8(streamId, self.inputId)
streamWriteUInt8(streamId, self.farmId)
end

function AutoDriveInputEventEvent:readStream(streamId, connection)
self.vehicle = NetworkUtil.getObject(NetworkUtil.readNodeObjectId(streamId))
self.inputId = streamReadUInt8(streamId)
self.farmId = streamReadUInt8(streamId)
self:run(connection)
end

function AutoDriveInputEventEvent:run(connection)
if g_server ~= nil then
local input = ADInputManager.idsToInputs[self.inputId]
--print(string.format("onInputCall [%s] %s", self.inputId, input))
ADInputManager:onInputCall(self.vehicle, input, false)
ADInputManager:onInputCall(self.vehicle, input, self.farmId, false)
end
end

function AutoDriveInputEventEvent.sendEvent(vehicle, inputId)
function AutoDriveInputEventEvent.sendEvent(vehicle, inputId, farmId)
if g_client ~= nil then
-- Client have to send to server
g_client:getServerConnection():sendEvent(AutoDriveInputEventEvent.new(vehicle, inputId))
g_client:getServerConnection():sendEvent(AutoDriveInputEventEvent.new(vehicle, inputId, farmId))
end
end
16 changes: 15 additions & 1 deletion scripts/ExternalInterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,25 @@ end

function AutoDrive:onCpEmpty()
AutoDrive.debugPrint(self, AutoDrive.DC_EXTERNALINTERFACEINFO, "AutoDrive:onCpEmpty start...")
local rootVehicle = self.getRootVehicle and self:getRootVehicle()
if rootVehicle then
if rootVehicle.ad == nil then
rootVehicle.ad = {}
end
rootVehicle.ad.isCpEmpty = true
end
AutoDrive:handleCPFieldWorker(self)
end

function AutoDrive:onCpFull()
AutoDrive.debugPrint(self, AutoDrive.DC_EXTERNALINTERFACEINFO, "AutoDrive:onCpFull start...")
local rootVehicle = self.getRootVehicle and self:getRootVehicle()
if rootVehicle then
if rootVehicle.ad == nil then
rootVehicle.ad = {}
end
rootVehicle.ad.isCpFull = true
end
AutoDrive:handleCPFieldWorker(self)
end

Expand Down Expand Up @@ -736,7 +750,7 @@ function AutoDrive:getALObjectFillLevels(object) -- used by getIsFillUnitEmpty,
fillFreeCapacity = object:getFillUnitFreeCapacity()
AutoDrive.debugPrint(object, AutoDrive.DC_EXTERNALINTERFACEINFO, "AutoDrive:getALObjectFillLevels fillCapacity %s fillLevel %s fillFreeCapacity %s", tostring(fillCapacity), tostring(fillLevel), tostring(fillFreeCapacity))
end
local filledToUnload = AutoDrive.isUnloadFillLevelReached(rootVehicle, fillFreeCapacity, fillCapacity)
local filledToUnload = AutoDrive.isUnloadFillLevelReached(rootVehicle, fillLevel, fillFreeCapacity, fillCapacity)
return fillLevel, fillCapacity, filledToUnload, fillFreeCapacity
end

Expand Down
19 changes: 19 additions & 0 deletions scripts/Gui/DebugSettingsPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,24 @@ function ADDebugSettingsPage:onCreateAutoDriveText12(box)
end
end

function ADDebugSettingsPage:onCreateAutoDriveText13(box)
if self.storedKey13 == nil then
self.storedKey13 = box.text
end
if self.storedKey13 ~= nil then

local hasText = self.storedKey13 ~= nil and self.storedKey13 ~= ""
if hasText then
local text = self.storedKey13
if text:sub(1,6) == "$l10n_" then
text = text:sub(7)
end
text = g_i18n:getText(text)
box:setTextInternal(text, false, true)
end
end
end

function ADDebugSettingsPage:copyAttributes(src)
ADDebugSettingsPage:superClass().copyAttributes(self, src)
self.storedHeaderKey = src.storedHeaderKey
Expand All @@ -326,4 +344,5 @@ function ADDebugSettingsPage:copyAttributes(src)
self.storedKey10 = src.storedKey10
self.storedKey11 = src.storedKey11
self.storedKey12 = src.storedKey12
self.storedKey13 = src.storedKey13
end
4 changes: 2 additions & 2 deletions scripts/Hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ function AutoDriveHud:createHudAt(hudX, hudY)
self.gapWidth, self.gapHeight = getNormalizedScreenValues(uiScale * gapSize, uiScale * gapSize)
self.iconWidth, self.iconHeight = getNormalizedScreenValues(uiScale * iconSize, uiScale * iconSize)
self.listItemWidth, self.listItemHeight = getNormalizedScreenValues(uiScale * listItemSize, uiScale * listItemSize)
self.posX = math.clamp(0, hudX, 1 - self.width)
self.posY = math.clamp(2 * self.gapHeight, hudY, 1 - (self.height + 3 * self.gapHeight + self.headerHeight))

self.posX = MathUtil.clamp(hudX, 0, 1 - self.width)
self.posY = MathUtil.clamp(hudY, 2 * self.gapHeight, 1 - (self.height + 3 * self.gapHeight + self.headerHeight))

AutoDrive.HudX = self.posX
AutoDrive.HudY = self.posY
Expand Down
2 changes: 0 additions & 2 deletions scripts/Hud/HudButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ function ADHudButton:act(vehicle, posX, posY, isDown, isUp, button)
end

if button == 1 and isUp and not AutoDrive.leftLSHIFTmodifierKeyPressed then
local storedVehicle = nil
ADInputManager:onInputCall(vehicle, self.primaryAction)
SpecializationUtil.raiseEvent(vehicle, "onUpdate", 16, false, false, false)
return true
elseif (button == 3 or button == 2) and isUp and not AutoDrive.leftLSHIFTmodifierKeyPressed then
ADInputManager:onInputCall(vehicle, self.secondaryAction)
Expand Down
5 changes: 3 additions & 2 deletions scripts/Hud/PullDownList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,9 @@ function ADPullDownList:getNewState_FillType(vehicle)
-- AutoDrive.debugMsg(vehicle, "ADPullDownList:getNewState_FillType 2 self.text %s", tostring(self.text))
end
else
if vehicle.ad.stateModule:getFillType() ~= g_fillTypeManager:getFillTypeIndexByName('UNKNOWN') then
self.text = g_fillTypeManager:getFillTypeByIndex(vehicle.ad.stateModule:getFillType()).title
local fillType = g_fillTypeManager:getFillTypeByIndex(vehicle.ad.stateModule:getFillType())
if fillType and vehicle.ad.stateModule:getFillType() ~= g_fillTypeManager:getFillTypeIndexByName('UNKNOWN') then
self.text = fillType.title
else
self.text = ""
end
Expand Down
8 changes: 7 additions & 1 deletion scripts/Manager/DrawingManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ function ADDrawingManager:drawLine(id, task)

setTranslation(id, task.sx, task.sy + self.yOffset, task.sz)

setScale(id, 1, 1, distToNextPoint)
local scaleLines = AutoDrive.getSetting("scaleLines") or 1
setScale(id, scaleLines, scaleLines, distToNextPoint)

-- Set the direction of the line
setRotation(id, rotX, rotY, 0)
Expand Down Expand Up @@ -386,6 +387,9 @@ function ADDrawingManager:drawArrow(id, task)

setTranslation(id, x, y + self.yOffset, z)

local scaleLines = AutoDrive.getSetting("scaleLines") or 1
setScale(id, scaleLines, scaleLines, scaleLines)

-- Set the direction of the arrow
setRotation(id, rotX, rotY, 0)

Expand All @@ -409,6 +413,8 @@ end

function ADDrawingManager:drawCross(id, task)
setTranslation(id, task.x, task.y + self.yOffset, task.z)
local scaleLines = AutoDrive.getSetting("scaleLines") or 1
setScale(id, scaleLines, scaleLines, scaleLines)
setVisibility(id, true)
end

Expand Down
26 changes: 23 additions & 3 deletions scripts/Manager/GraphManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,12 @@ function ADGraphManager:recordWayPoint(x, y, z, connectPrevious, dual, isReverse
end
end

-- play sound only on client with enabled editor mode
-- play sound only on client with enabled editor mode or RecordWhileNotInVehicle
if g_client ~= nil then
local vehicle = g_currentMission.controlledVehicle
if vehicle ~= nil and vehicle.ad ~= nil and AutoDrive.isInExtendedEditorMode() then
AutoDrive.playSample(AutoDrive.recordWaypointSample, 0.25)
local forced = AutoDrive.experimentalFeatures.RecordWhileNotInVehicle
if (vehicle ~= nil and vehicle.ad ~= nil and AutoDrive.isInExtendedEditorMode()) or forced then
AutoDrive.playSample(AutoDrive.recordWaypointSample, 0.25, forced)
end
end

Expand Down Expand Up @@ -1534,6 +1535,25 @@ function ADGraphManager:deleteWayPointsInSection(vehicle)
for i = 2, #vehicle.ad.sectionWayPoints - 1 do
table.insert(pointsToDelete, vehicle.ad.sectionWayPoints[i])
end

-- delete last wayPoint if not connected to a junction
local lastWayPointID = vehicle.ad.sectionWayPoints[#vehicle.ad.sectionWayPoints]
local lastWayPoint = self:getWayPointById(lastWayPointID)
local connectedIds = {}
for _, incomingId in pairs(lastWayPoint.incoming) do
if not table.contains(connectedIds, incomingId) then
table.insert(connectedIds, incomingId)
end
end
for _, outId in pairs(lastWayPoint.out) do
if not table.contains(connectedIds, outId) then
table.insert(connectedIds, outId)
end
end
if #connectedIds == 1 then
table.insert(pointsToDelete, lastWayPointID)
end

-- sort the wayPoints to delete in descant order to ensure correct linkage deletion
local sort_func = function(a, b)
return a > b
Expand Down
Loading

0 comments on commit 16a890b

Please sign in to comment.