Skip to main content
Skip to main content

AIParameterLoadingStation

AIParameterLoadingStation

Parent

AIParameter

Functions

getLoadingStation

Description

Definition

getLoadingStation()

Code

function AIParameterLoadingStation:getLoadingStation()
local loadingStation = NetworkUtil.getObject( self.loadingStationId)
if loadingStation ~ = nil and loadingStation.owningPlaceable ~ = nil and loadingStation.owningPlaceable:getIsSynchronized() then
return loadingStation
end

return nil
end

getString

Description

Definition

getString()

Code

function AIParameterLoadingStation:getString()
local loadingStation = NetworkUtil.getObject( self.loadingStationId)
if loadingStation ~ = nil then
return loadingStation:getName()
end

return ""
end

loadFromXMLFile

Description

Definition

loadFromXMLFile()

Arguments

anyxmlFile
anykey

Code

function AIParameterLoadingStation:loadFromXMLFile(xmlFile, key)
local loadingStationUniqueId = xmlFile:getString(key .. "#stationUniqueId" )
local stationIndex = xmlFile:getInt(key .. "#stationIndex" )

if loadingStationUniqueId ~ = nil and stationIndex ~ = nil then
if not self:setLoadingStationFromUniqueId(loadingStationUniqueId, stationIndex) then
g_messageCenter:subscribeOneshot(MessageType.LOADED_ALL_SAVEGAME_PLACEABLES, self.onPlaceableLoaded, self , { loadingStationUniqueId, stationIndex } )
end
end
end

new

Description

Definition

new()

Arguments

anycustomMt

Code

function AIParameterLoadingStation.new(customMt)
local self = AIParameter.new(customMt or AIParameterLoadingStation _mt)

self.type = AIParameterType.LOADING_STATION

self.loadingStationId = nil
self.loadingStationIds = { }

return self
end

onPlaceableLoaded

Description

Definition

onPlaceableLoaded()

Arguments

anyargs

Code

function AIParameterLoadingStation:onPlaceableLoaded(args)
self:setLoadingStationFromUniqueId(args[ 1 ], args[ 2 ])
end

readStream

Description

Definition

readStream()

Arguments

anystreamId
anyconnection

Code

function AIParameterLoadingStation:readStream(streamId, connection)
if streamReadBool(streamId) then
self.loadingStationId = NetworkUtil.readNodeObjectId(streamId)
end
end

saveToXMLFile

Description

Definition

saveToXMLFile()

Arguments

anyxmlFile
anykey
anyusedModNames

Code

function AIParameterLoadingStation:saveToXMLFile(xmlFile, key, usedModNames)
local loadingStation = self:getLoadingStation()
if loadingStation ~ = nil then
local owningPlaceable = loadingStation.owningPlaceable
if owningPlaceable ~ = nil then
local uniqueId = owningPlaceable:getUniqueId()
if uniqueId ~ = nil then
local index = g_currentMission.storageSystem:getPlaceableLoadingStationIndex(owningPlaceable, loadingStation)
if index ~ = nil then
xmlFile:setString(key .. "#stationUniqueId" , uniqueId)
xmlFile:setInt(key .. "#stationIndex" , index)
end
end
end
end
end

setLoadingStation

Description

Definition

setLoadingStation()

Arguments

anyloadingStation

Code

function AIParameterLoadingStation:setLoadingStation(loadingStation)
self.loadingStationId = NetworkUtil.getObjectId(loadingStation)
end

setLoadingStationFromUniqueId

Description

Definition

setLoadingStationFromUniqueId()

Arguments

anyuniqueId
anyindex

Code

function AIParameterLoadingStation:setLoadingStationFromUniqueId(uniqueId, index)
local placeable = g_currentMission.placeableSystem:getPlaceableByUniqueId(uniqueId)
if placeable ~ = nil then
local loadingStation = g_currentMission.storageSystem:getPlaceableLoadingStation(placeable, index)
self:setLoadingStation(loadingStation)

return true
end

return false
end

setNextItem

Description

Definition

setNextItem()

Code

function AIParameterLoadingStation:setNextItem()
local nextIndex = 0
for k, loadingStationId in ipairs( self.loadingStationIds) do
if loadingStationId = = self.loadingStationId then
nextIndex = k + 1
end
end

if nextIndex > # self.loadingStationIds then
nextIndex = 1
end

self.loadingStationId = self.loadingStationIds[nextIndex]
end

setPreviousItem

Description

Definition

setPreviousItem()

Code

function AIParameterLoadingStation:setPreviousItem()
local previousIndex = 0
for k, loadingStationId in ipairs( self.loadingStationIds) do
if loadingStationId = = self.loadingStationId then
previousIndex = k - 1
end
end

if previousIndex < 1 then
previousIndex = # self.loadingStationIds
end

self.loadingStationId = self.loadingStationIds[previousIndex]
end

setValidLoadingStations

Description

Definition

setValidLoadingStations()

Arguments

anyloadingStationIds

Code

function AIParameterLoadingStation:setValidLoadingStations(loadingStationIds)
self.loadingStationIds = { }
local nextLoadingStationId

for _, loadingStation in ipairs(loadingStationIds) do
local id = NetworkUtil.getObjectId(loadingStation)
if id ~ = nil then
if id = = self.loadingStationId then
nextLoadingStationId = id
end
table.insert( self.loadingStationIds, id)
end
end

self.loadingStationId = nextLoadingStationId or self.loadingStationIds[ 1 ]
end

validate

Description

Definition

validate()

Arguments

anyfillTypeIndex
anyfarmId

Code

function AIParameterLoadingStation:validate(fillTypeIndex, farmId)
if self.loadingStationId = = nil then
return false , g_i18n:getText( "ai_validationErrorNoLoadingStation" )
end

local loadingStation = self:getLoadingStation()
if loadingStation = = nil then
return false , g_i18n:getText( "ai_validationErrorLoadingStationDoesNotExistAnymore" )
end

if fillTypeIndex ~ = nil then
if not loadingStation:getIsFillTypeAISupported(fillTypeIndex) then
return false , g_i18n:getText( "ai_validationErrorFillTypeNotSupportedByLoadingStation" )
elseif loadingStation:getFillLevel(fillTypeIndex, farmId) < = 0 then
return false , g_i18n:getText( "ai_validationErrorLoadingStationIsEmpty" )
end
end

return true , nil
end

writeStream

Description

Definition

writeStream()

Arguments

anystreamId
anyconnection

Code

function AIParameterLoadingStation:writeStream(streamId, connection)
if streamWriteBool(streamId, self.loadingStationId ~ = nil ) then
NetworkUtil.writeNodeObjectId(streamId, self.loadingStationId)
end
end