Skip to content

Commit

Permalink
Diff MP fixes
Browse files Browse the repository at this point in the history
- Should fix #273
- Removed invalid event calls
  • Loading branch information
schwiti6190 committed Jan 8, 2025
1 parent 629a044 commit efc91db
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion scripts/ai/jobs/CpAIJob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function CpAIJob:readStream(streamId, connection)

self.currentTaskIndex = streamReadUInt8(streamId)
if self.cpJobParameters then
self.cpJobParameters:validateSettings()
self.cpJobParameters:validateSettings(true)
self.cpJobParameters:readStream(streamId, connection)
end
if streamReadBool(streamId) then
Expand Down
4 changes: 2 additions & 2 deletions scripts/ai/jobs/CpJobParameters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ function CpJobParameters.registerXmlSchema(schema, baseKey)
CpSettingsUtil.registerXmlSchema(schema, baseKey .. CpJobParameters.xmlKey.."(?)")
end

function CpJobParameters:validateSettings()
function CpJobParameters:validateSettings(includeDisabledValues)
for i, setting in ipairs(self.settings) do
setting:refresh()
setting:refresh(includeDisabledValues)
end
end

Expand Down
5 changes: 3 additions & 2 deletions scripts/ai/parameters/AIParameterSettingList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ function AIParameterSettingList:isValueDisabled(value)
end

--- Excludes deactivated values from the current values and texts tables.
function AIParameterSettingList:refresh()
---@param includeDisabledValues boolean|nil
function AIParameterSettingList:refresh(includeDisabledValues)
if self.data.generateValuesFunction then
local lastValue = self.values[self.current]
local newValue
Expand All @@ -211,7 +212,7 @@ function AIParameterSettingList:refresh()
self.values = {}
self.texts = {}
for ix, v in ipairs(self.data.values) do
if not self:isValueDisabled(v) then
if includeDisabledValues or not self:isValueDisabled(v) then
table.insert(self.values, v)
table.insert(self.texts, self.data.texts[ix])
end
Expand Down
6 changes: 3 additions & 3 deletions scripts/specializations/CpCourseGeneratorSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ function CpCourseGeneratorSettings:setAutomaticWorkWidthAndOffset()
local spec = self.spec_cpCourseGeneratorSettings
local width, offset, _, _ = WorkWidthUtil.getAutomaticWorkWidthAndOffset(self)
spec.workWidth:refresh()
spec.workWidth:setFloatValue(width)
self:getCpSettings().toolOffsetX:setFloatValue(offset)
spec.workWidth:setFloatValue(width, nil, true)
self:getCpSettings().toolOffsetX:setFloatValue(offset, nil, true)
end

function CpCourseGeneratorSettings:setDefaultTurningRadius()
local spec = self.spec_cpCourseGeneratorSettings
spec.turningRadius:setFloatValue(AIUtil.getTurningRadius(self))
spec.turningRadius:setFloatValue(AIUtil.getTurningRadius(self), nil, true)
end

--- Loads the generic settings setup from an xmlFile.
Expand Down
26 changes: 14 additions & 12 deletions scripts/specializations/CpVehicleSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function CpVehicleSettings:onStateChange(state, data)
local spec = self.spec_cpVehicleSettings
if state == VehicleStateChange.FILLTYPE_CHANGE and self:getIsSynchronized() then
local _, hasSprayer = AIUtil.getAllChildVehiclesWithSpecialization(self, Sprayer, nil)
if hasSprayer then
if self.isServer and hasSprayer then
local width, offset = WorkWidthUtil.getAutomaticWorkWidthAndOffset(self, nil, nil)
local oldWidth = self:getCourseGeneratorSettings().workWidth:getValue()
if not MathUtil.equalEpsilon(width, oldWidth, 1) then
Expand Down Expand Up @@ -167,8 +167,8 @@ function CpVehicleSettings:setAutomaticWorkWidthAndOffset(ignoreObject)
local spec = self.spec_cpVehicleSettings
local width, offset = WorkWidthUtil.getAutomaticWorkWidthAndOffset(self, nil, ignoreObject)
self:getCourseGeneratorSettings().workWidth:refresh()
self:getCourseGeneratorSettings().workWidth:setFloatValue(width)
spec.toolOffsetX:setFloatValue(offset)
self:getCourseGeneratorSettings().workWidth:setFloatValue(width, nil, true)
spec.toolOffsetX:setFloatValue(offset, nil, true)
end

function CpVehicleSettings:onReadStream(streamId, connection)
Expand Down Expand Up @@ -290,7 +290,7 @@ end
---@param vehicleConfigurationName string name of the setting in the vehicle configuration XML
function CpVehicleSettings:setFromVehicleConfiguration(object, setting, vehicleConfigurationName)
local value = g_vehicleConfigurations:get(object, vehicleConfigurationName)
if value then
if self.isServer and value then
CpUtil.debugVehicle(CpDebug.DBG_IMPLEMENTS, self, '%s: setting configured %s to %s',
CpUtil.getName(object), vehicleConfigurationName, tostring(value))
if type(value) == 'number' then
Expand All @@ -309,7 +309,7 @@ end
---@param defaultValue any default value to reset the setting to
function CpVehicleSettings:resetToDefault(object, setting, vehicleConfigurationName, defaultValue)
local value = g_vehicleConfigurations:get(object, vehicleConfigurationName)
if value then
if self.isServer and value then
CpUtil.debugVehicle(CpDebug.DBG_IMPLEMENTS, self, '%s: resetting to default %s to %s',
CpUtil.getName(object), vehicleConfigurationName, tostring(defaultValue))
if type(defaultValue) == 'number' then
Expand Down Expand Up @@ -408,26 +408,28 @@ end
function CpVehicleSettings:setAutomaticBunkerSiloWorkWidth(ignoreObject)
local spec = self.spec_cpVehicleSettings
local width = WorkWidthUtil.getAutomaticWorkWidthAndOffset(self, nil, ignoreObject)
spec.bunkerSiloWorkWidth:setFloatValue(width)
spec.bunkerSiloWorkWidth:setFloatValue(width, nil, true)
end

function CpVehicleSettings:isBaleCollectorOffsetVisible()
return self:getCanStartCpBaleFinder()
end

function CpVehicleSettings:setAutomaticBaleCollectorOffset()
local spec = self.spec_cpVehicleSettings
local halfVehicleWidth = AIUtil.getWidth(self) / 2
local configValue = g_vehicleConfigurations:getRecursively(self, "baleCollectorOffset")
local offset = configValue ~= nil and configValue or halfVehicleWidth + 0.2
spec.baleCollectorOffset:setFloatValue(offset)
if self.isServer then
local spec = self.spec_cpVehicleSettings
local halfVehicleWidth = AIUtil.getWidth(self) / 2
local configValue = g_vehicleConfigurations:getRecursively(self, "baleCollectorOffset")
local offset = configValue ~= nil and configValue or halfVehicleWidth + 0.2
spec.baleCollectorOffset:setFloatValue(offset)
end
end

--- If the vehicle has a pipe, instantiate a pipe controller to measure the pipe offsets. This is better
--- done here and not when the vehicle starts as measuring is a hack and may mess up the vehicle states.
function CpVehicleSettings:setPipeOffset()
local pipeObject = AIUtil.getImplementOrVehicleWithSpecialization(self, Pipe)
if pipeObject then
if self.isServer and pipeObject then
local spec = self.spec_cpVehicleSettings
-- ask the pipe controller to get the offsets
local pipeController = PipeController(self, pipeObject, true)
Expand Down

0 comments on commit efc91db

Please sign in to comment.