Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- AIParameter
- AIParameterFillType
- AIParameterGroup
- AIParameterLoadingStation
- AIParameterLooping
- AIParameterPosition
- AIParameterPositionAngle
- AIParameterUnloadingStati...
- AIParameterVehicle
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
AIParameterLoadingStation
ParentAIParameterFunctions
- getLoadingStation
- getString
- loadFromXMLFile
- new
- onPlaceableLoaded
- readStream
- saveToXMLFile
- setLoadingStation
- setLoadingStationFromSavegameId
- setNextItem
- setPreviousItem
- setValidLoadingStations
- validate
- writeStream
getLoadingStation
DescriptionDefinitiongetLoadingStation()Code
100 | function AIParameterLoadingStation:getLoadingStation() |
101 | local loadingStation = NetworkUtil.getObject(self.loadingStationId) |
102 | if loadingStation ~= nil and loadingStation.owningPlaceable ~= nil and loadingStation.owningPlaceable:getIsSynchronized() then |
103 | return loadingStation |
104 | end |
105 | |
106 | return nil |
107 | end |
getString
DescriptionDefinitiongetString()Code
111 | function AIParameterLoadingStation:getString() |
112 | local loadingStation = NetworkUtil.getObject(self.loadingStationId) |
113 | if loadingStation ~= nil then |
114 | return loadingStation:getName() |
115 | end |
116 | |
117 | return "" |
118 | end |
loadFromXMLFile
DescriptionDefinitionloadFromXMLFile()Code
45 | function AIParameterLoadingStation:loadFromXMLFile(xmlFile, key) |
46 | local loadingStationSavegameId = xmlFile:getInt(key .. "#stationId") |
47 | local stationIndex = xmlFile:getInt(key .. "#stationIndex") |
48 | |
49 | if loadingStationSavegameId ~= nil and stationIndex ~= nil then |
50 | if not self:setLoadingStationFromSavegameId(loadingStationSavegameId, stationIndex) then |
51 | g_messageCenter:subscribeOneshot(MessageType.LOADED_ALL_SAVEGAME_PLACEABLES, self.onPlaceableLoaded, self, {loadingStationSavegameId, stationIndex}) |
52 | end |
53 | end |
54 | end |
new
DescriptionDefinitionnew()Code
16 | function AIParameterLoadingStation.new(customMt) |
17 | local self = AIParameter.new(customMt or AIParameterLoadingStation_mt) |
18 | |
19 | self.type = AIParameterType.LOADING_STATION |
20 | |
21 | self.loadingStationId = nil |
22 | self.loadingStationIds = {} |
23 | |
24 | return self |
25 | end |
onPlaceableLoaded
DescriptionDefinitiononPlaceableLoaded()Code
58 | function AIParameterLoadingStation:onPlaceableLoaded(args) |
59 | self:setLoadingStationFromSavegameId(args[1], args[2]) |
60 | end |
readStream
DescriptionDefinitionreadStream()Code
78 | function AIParameterLoadingStation:readStream(streamId, connection) |
79 | if streamReadBool(streamId) then |
80 | self.loadingStationId = NetworkUtil.readNodeObjectId(streamId) |
81 | end |
82 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
29 | function AIParameterLoadingStation:saveToXMLFile(xmlFile, key, usedModNames) |
30 | local loadingStation = self:getLoadingStation() |
31 | if loadingStation ~= nil then |
32 | local owningPlaceable = loadingStation.owningPlaceable |
33 | if owningPlaceable ~= nil and owningPlaceable.currentSavegameId ~= nil then |
34 | local index = g_currentMission.storageSystem:getPlaceableLoadingStationIndex(owningPlaceable, loadingStation) |
35 | if index ~= nil then |
36 | xmlFile:setInt(key .. "#stationId", owningPlaceable.currentSavegameId) |
37 | xmlFile:setInt(key .. "#stationIndex", index) |
38 | end |
39 | end |
40 | end |
41 | end |
setLoadingStation
DescriptionDefinitionsetLoadingStation()Code
94 | function AIParameterLoadingStation:setLoadingStation(loadingStation) |
95 | self.loadingStationId = NetworkUtil.getObjectId(loadingStation) |
96 | end |
setLoadingStationFromSavegameId
DescriptionDefinitionsetLoadingStationFromSavegameId()Code
64 | function AIParameterLoadingStation:setLoadingStationFromSavegameId(savegameId, index) |
65 | local placeable = g_currentMission.placeableSystem:getPlaceableBySavegameId(savegameId) |
66 | if placeable ~= nil then |
67 | local loadingStation = g_currentMission.storageSystem:getPlaceableLoadingStation(placeable, index) |
68 | self:setLoadingStation(loadingStation) |
69 | |
70 | return true |
71 | end |
72 | |
73 | return false |
74 | end |
setNextItem
DescriptionDefinitionsetNextItem()Code
141 | function AIParameterLoadingStation:setNextItem() |
142 | local nextIndex = 0 |
143 | for k, loadingStationId in ipairs(self.loadingStationIds) do |
144 | if loadingStationId == self.loadingStationId then |
145 | nextIndex = k + 1 |
146 | end |
147 | end |
148 | |
149 | if nextIndex > #self.loadingStationIds then |
150 | nextIndex = 1 |
151 | end |
152 | |
153 | self.loadingStationId = self.loadingStationIds[nextIndex] |
154 | end |
setPreviousItem
DescriptionDefinitionsetPreviousItem()Code
158 | function AIParameterLoadingStation:setPreviousItem() |
159 | local previousIndex = 0 |
160 | for k, loadingStationId in ipairs(self.loadingStationIds) do |
161 | if loadingStationId == self.loadingStationId then |
162 | previousIndex = k - 1 |
163 | end |
164 | end |
165 | |
166 | if previousIndex < 1 then |
167 | previousIndex = #self.loadingStationIds |
168 | end |
169 | |
170 | self.loadingStationId = self.loadingStationIds[previousIndex] |
171 | end |
setValidLoadingStations
DescriptionDefinitionsetValidLoadingStations()Code
122 | function AIParameterLoadingStation:setValidLoadingStations(loadingStationIds) |
123 | self.loadingStationIds = {} |
124 | local nextLoadingStationId |
125 | |
126 | for _, loadingStation in ipairs(loadingStationIds) do |
127 | local id = NetworkUtil.getObjectId(loadingStation) |
128 | if id ~= nil then |
129 | if id == self.loadingStationId then |
130 | nextLoadingStationId = id |
131 | end |
132 | table.insert(self.loadingStationIds, id) |
133 | end |
134 | end |
135 | |
136 | self.loadingStationId = nextLoadingStationId or self.loadingStationIds[1] |
137 | end |
validate
DescriptionDefinitionvalidate()Code
175 | function AIParameterLoadingStation:validate(fillTypeIndex, farmId) |
176 | if self.loadingStationId == nil then |
177 | return false, g_i18n:getText("ai_validationErrorNoLoadingStation") |
178 | end |
179 | |
180 | local loadingStation = self:getLoadingStation() |
181 | if loadingStation == nil then |
182 | return false, g_i18n:getText("ai_validationErrorLoadingStationDoesNotExistAnymore") |
183 | end |
184 | |
185 | if fillTypeIndex ~= nil then |
186 | if not loadingStation:getIsFillTypeAISupported(fillTypeIndex) then |
187 | return false, g_i18n:getText("ai_validationErrorFillTypeNotSupportedByLoadingStation") |
188 | elseif loadingStation:getFillLevel(fillTypeIndex, farmId) <= 0 then |
189 | return false, g_i18n:getText("ai_validationErrorLoadingStationIsEmpty") |
190 | end |
191 | end |
192 | |
193 | return true, nil |
194 | end |
writeStream
DescriptionDefinitionwriteStream()Code
86 | function AIParameterLoadingStation:writeStream(streamId, connection) |
87 | if streamWriteBool(streamId, self.loadingStationId ~= nil) then |
88 | NetworkUtil.writeNodeObjectId(streamId, self.loadingStationId) |
89 | end |
90 | end |