Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- AnimatedMapObject
- AnimatedObject
- AnimatedObjectEvent
- Bale
- Basketball
- Bga
- BgaSellStation
- BunkerSilo
- BuyingStation
- DigitalDisplay
- DogBall
- HelpIcons
- LoadingStation
- NightIllumination
- Nightlight2
- NightlightFlicker
- PhysicsObject
- Rotator
- SellingStation
- SimParticleSystem
- Storage
- StorageSystem
- SunAdmirer
- TourIcons
- UnloadingStation
- VehicleSellingPoint
- WildlifeSpawner
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
LoadingStation
DescriptionA loading station defines a spot where fillTypes can be loaded. Requires loadTrigger to define the exact positionsParent
ObjectFunctions
- addFillLevelToFillableObject
- addSourceStorage
- delete
- getAllFillLevels
- getIsFillAllowedToFarm
- getProvidedFillTypes
- getSourceStorages
- hasFarmAccessToStorage
- load
- new
- readStream
- removeSourceStorage
- updateProvidedFillTyes
- writeStream
addFillLevelToFillableObject
DescriptionDefinitionaddFillLevelToFillableObject()Code
210 | function LoadingStation:addFillLevelToFillableObject(fillableObject, fillUnitIndex, fillTypeIndex, fillDelta, fillInfo, toolType) |
211 | if fillableObject == nil or fillTypeIndex == FillType.UNKNOWN or fillDelta == 0 or toolType == nil then |
212 | return 0 |
213 | end |
214 | |
215 | local farmId = fillableObject:getOwnerFarmId() |
216 | if fillableObject:isa(Vehicle) then |
217 | farmId = fillableObject:getActiveFarm() |
218 | end |
219 | |
220 | local availableFillLevel = 0 |
221 | for _, sourceStorage in pairs(self.sourceStorages) do |
222 | if self:hasFarmAccessToStorage(farmId, sourceStorage) then |
223 | availableFillLevel = availableFillLevel + Utils.getNoNil(sourceStorage:getFillLevel(fillTypeIndex), 0) |
224 | end |
225 | end |
226 | fillDelta = math.min(fillDelta, availableFillLevel) |
227 | |
228 | if fillDelta == 0 then |
229 | return 0 |
230 | end |
231 | |
232 | local usedFillLevel = fillableObject:addFillUnitFillLevel(farmId, fillUnitIndex, fillDelta, fillTypeIndex, toolType, fillInfo) |
233 | local appliedFillLevel = usedFillLevel |
234 | |
235 | for _, sourceStorage in pairs(self.sourceStorages) do |
236 | if self:hasFarmAccessToStorage(farmId, sourceStorage) then |
237 | local oldFillLevel = sourceStorage:getFillLevel(fillTypeIndex) |
238 | if oldFillLevel > 0 then |
239 | sourceStorage:setFillLevel(oldFillLevel - usedFillLevel, fillTypeIndex) |
240 | end |
241 | local newFillLevel = sourceStorage:getFillLevel(fillTypeIndex) |
242 | |
243 | usedFillLevel = usedFillLevel - (oldFillLevel - newFillLevel) |
244 | |
245 | if usedFillLevel < 0.0001 then |
246 | usedFillLevel = 0 |
247 | break |
248 | end |
249 | end |
250 | end |
251 | |
252 | fillDelta = appliedFillLevel - usedFillLevel |
253 | |
254 | return fillDelta |
255 | end |
addSourceStorage
DescriptionDefinitionaddSourceStorage()Code
146 | function LoadingStation:addSourceStorage(storage) |
147 | if storage ~= nil then |
148 | if storage.getIsFillTypeSupported ~= nil and storage.setFillLevel ~= nil and storage.getFillLevel ~= nil and storage.getSupportedFillTypes ~= nil then |
149 | self.sourceStorages[storage] = storage |
150 | storage:addLoadingStation(self) |
151 | self:updateProvidedFillTyes() |
152 | return true |
153 | else |
154 | print("Error: LoadingStation '"..tostring(self.stationName).."' can't add storage, because it is not a valid storage object!") |
155 | end |
156 | end |
157 | end |
delete
DescriptionDefinitiondelete()Code
92 | function LoadingStation:delete() |
93 | if self.mapHotspot ~= nil then |
94 | g_currentMission:removeMapHotspot(self.mapHotspot) |
95 | self.mapHotspot:delete() |
96 | end |
97 | |
98 | if self.loadTriggers ~= nil then |
99 | for _,loadTrigger in ipairs(self.loadTriggers) do |
100 | loadTrigger:delete() |
101 | end |
102 | end |
103 | |
104 | LoadingStation:superClass().delete(self) |
105 | end |
getAllFillLevels
DescriptionDefinitiongetAllFillLevels()Code
191 | function LoadingStation:getAllFillLevels(farmId) |
192 | local fillLevels = {} |
193 | local capacity = 0 |
194 | |
195 | for _, sourceStorage in pairs(self.sourceStorages) do |
196 | if self:hasFarmAccessToStorage(farmId, sourceStorage) then |
197 | for fillType, fillLevel in pairs(sourceStorage.fillLevels) do |
198 | fillLevels[fillType] = Utils.getNoNil(fillLevels[fillType], 0) + fillLevel |
199 | end |
200 | |
201 | capacity = capacity + sourceStorage:getCapacity() |
202 | end |
203 | end |
204 | |
205 | return fillLevels, capacity |
206 | end |
getIsFillAllowedToFarm
DescriptionGet whether the given farm is allowed to fill objects from this loading station.Definition
getIsFillAllowedToFarm()Code
265 | function LoadingStation:getIsFillAllowedToFarm(farmId) |
266 | for _, sourceStorage in pairs(self.sourceStorages) do |
267 | if self:hasFarmAccessToStorage(farmId, sourceStorage) then |
268 | return true |
269 | end |
270 | end |
271 | |
272 | return false |
273 | end |
getProvidedFillTypes
DescriptionDefinitiongetProvidedFillTypes()Code
185 | function LoadingStation:getProvidedFillTypes() |
186 | return self.providedFillTypes |
187 | end |
getSourceStorages
DescriptionDefinitiongetSourceStorages()Code
259 | function LoadingStation:getSourceStorages() |
260 | return self.sourceStorages |
261 | end |
hasFarmAccessToStorage
DescriptionDefinitionhasFarmAccessToStorage()Code
277 | function LoadingStation:hasFarmAccessToStorage(farmId, storage) |
278 | if self.hasStoragePerFarm then |
279 | return farmId == storage:getOwnerFarmId() |
280 | else |
281 | return g_currentMission.accessHandler:canFarmAccess(farmId, storage) |
282 | end |
283 | end |
load
DescriptionDefinitionload()Code
24 | function LoadingStation:load(id, xmlFile, key, customEnv) |
25 | self.rootNode = id |
26 | self.rootNodeName = getName(self.rootNode) |
27 | |
28 | self.appearsOnPDA = Utils.getNoNil(getXMLBool(xmlFile, key.."#appearsOnPDA"), false) |
29 | local rawName = Utils.getNoNil(getXMLString(xmlFile, key.."#stationName"), "LoadingStation") |
30 | self.stationName = g_i18n:convertText(rawName, customEnv) -- returns input if it cannot be resolved |
31 | self.storageRadius = Utils.getNoNil(getXMLFloat(xmlFile, key.."#storageRadius"), 50) |
32 | |
33 | self.sourceStorages = {} |
34 | self.loadTriggers = {} |
35 | |
36 | local i = 0 |
37 | while true do |
38 | local loadTriggerKey = string.format("%s.loadTrigger(%d)", key, i) |
39 | if not hasXMLProperty(xmlFile, loadTriggerKey) then |
40 | break |
41 | end |
42 | |
43 | local loadTrigger = LoadTrigger:new(self.isServer, self.isClient) |
44 | if loadTrigger:load(self.rootNode, xmlFile, loadTriggerKey) then |
45 | loadTrigger:setSource(self) |
46 | loadTrigger:register(true) |
47 | table.insert(self.loadTriggers, loadTrigger) |
48 | else |
49 | loadTrigger:delete() |
50 | end |
51 | |
52 | i = i + 1 |
53 | end |
54 | |
55 | if self.appearsOnPDA then |
56 | local mapPosition = self.rootNode |
57 | local mapPositionIndex = getUserAttribute(self.rootNode, "mapPositionIndex") |
58 | if mapPositionIndex ~= nil then |
59 | mapPosition = I3DUtil.indexToObject(self.rootNode, mapPositionIndex) |
60 | if mapPosition == nil then |
61 | mapPosition = self.rootNode |
62 | end |
63 | end |
64 | |
65 | self.mapHotspot = MapHotspot:new("loadingStation", MapHotspot.CATEGORY_TRIGGER) |
66 | |
67 | local showText = Utils.getNoNil(getXMLBool(xmlFile, key.."#showHotspotText"), true) |
68 | self.mapHotspot:setText(self.stationName, not showText) |
69 | |
70 | local imageName = getXMLString(xmlFile, key.."#hotspotImageName") |
71 | local imageUVs = MapHotspot.UV.SELLING_POINT |
72 | if imageName ~= nil and MapHotspot.UV[imageName] ~= nil then |
73 | imageUVs = MapHotspot.UV[imageName] |
74 | end |
75 | |
76 | self.mapHotspot:setBorderedImage(nil, getNormalizedUVs(imageUVs)) |
77 | |
78 | local x, _, z = getWorldTranslation(mapPosition) |
79 | self.mapHotspot:setWorldPosition(x, z) |
80 | |
81 | local hotspotTextOffset = Utils.getNoNil(getXMLString(xmlFile, key .. "#hotspotTextOffset"), "0px 0px") |
82 | self.mapHotspot:setRawTextOffset(hotspotTextOffset) |
83 | |
84 | g_currentMission:addMapHotspot(self.mapHotspot) |
85 | end |
86 | |
87 | return true |
88 | end |
new
DescriptionDefinitionnew()Code
18 | function LoadingStation:new(isServer, isClient, customMt) |
19 | return Object:new(isServer, isClient, customMt or LoadingStation_mt) |
20 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
111 | function LoadingStation:readStream(streamId, connection) |
112 | LoadingStation:superClass().readStream(self, streamId, connection) |
113 | if connection:getIsServer() then |
114 | for _, loadTrigger in ipairs(self.loadTriggers) do |
115 | local loadTriggerId = NetworkUtil.readNodeObjectId(streamId) |
116 | loadTrigger:readStream(streamId, connection) |
117 | g_client:finishRegisterObject(loadTrigger, loadTriggerId) |
118 | end |
119 | end |
120 | end |
removeSourceStorage
DescriptionDefinitionremoveSourceStorage()Code
161 | function LoadingStation:removeSourceStorage(storage) |
162 | if storage ~= nil then |
163 | if storage.getIsFillTypeSupported ~= nil and storage.setFillLevel ~= nil and storage.getFillLevel ~= nil then |
164 | storage:removeLoadingStation(self) |
165 | self.sourceStorages[storage] = nil |
166 | self:updateProvidedFillTyes() |
167 | end |
168 | end |
169 | end |
updateProvidedFillTyes
DescriptionDefinitionupdateProvidedFillTyes()Code
173 | function LoadingStation:updateProvidedFillTyes() |
174 | self.providedFillTypes = {} |
175 | for _,sourceStorage in pairs(self.sourceStorages) do |
176 | local sourceFillTypes = sourceStorage:getSupportedFillTypes() |
177 | for fillType,_ in pairs(sourceFillTypes) do |
178 | self.providedFillTypes[fillType] = true |
179 | end |
180 | end |
181 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
126 | function LoadingStation:writeStream(streamId, connection) |
127 | LoadingStation:superClass().writeStream(self, streamId, connection) |
128 | if not connection:getIsServer() then |
129 | for _, loadTrigger in ipairs(self.loadTriggers) do |
130 | NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(loadTrigger)) |
131 | loadTrigger:writeStream(streamId, connection) |
132 | g_server:registerObjectInStream(connection, loadTrigger) |
133 | end |
134 | end |
135 | end |