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
UnloadingStation
DescriptionA unloading station defines a spot where fillTypes can be unloaded. Requires unloadTrigger to define the exact positionsParent
ObjectFunctions
- addFillLevelFromTool
- addTargetStorage
- delete
- getCapacity
- getFillLevel
- getFreeCapacity
- getIsFillAllowedFromFarm
- getIsFillTypeAllowed
- getIsFillTypeSupported
- getIsToolTypeAllowed
- hasFarmAccessToStorage
- load
- new
- readStream
- removeTargetStorage
- writeStream
addFillLevelFromTool
DescriptionDefinitionaddFillLevelFromTool()Code
237 | function UnloadingStation:addFillLevelFromTool(farmId, deltaFillLevel, fillType, fillInfo, toolType) |
238 | assert(deltaFillLevel >= 0) |
239 | |
240 | |
241 | local movedFillLevel = 0 |
242 | |
243 | if self:getIsFillTypeAllowed(fillType) and self:getIsToolTypeAllowed(toolType) then |
244 | for _, targetStorage in pairs(self.targetStorages) do |
245 | if self:hasFarmAccessToStorage(farmId, targetStorage) then |
246 | if targetStorage:getFreeCapacity(fillType) > 0 then |
247 | local oldFillLevel = targetStorage:getFillLevel(fillType) |
248 | targetStorage:setFillLevel(oldFillLevel + deltaFillLevel, fillType) |
249 | local newFillLevel = targetStorage:getFillLevel(fillType) |
250 | |
251 | movedFillLevel = movedFillLevel + (newFillLevel - oldFillLevel) |
252 | end |
253 | |
254 | if movedFillLevel >= deltaFillLevel - 0.001 then |
255 | movedFillLevel = deltaFillLevel |
256 | break |
257 | end |
258 | end |
259 | end |
260 | end |
261 | |
262 | return movedFillLevel |
263 | end |
addTargetStorage
DescriptionDefinitionaddTargetStorage()Code
139 | function UnloadingStation:addTargetStorage(storage) |
140 | if storage ~= nil then |
141 | if storage.getIsFillTypeSupported ~= nil and storage.setFillLevel ~= nil and storage.getFillLevel ~= nil then |
142 | self.targetStorages[storage] = storage |
143 | storage:addUnloadingStation(self) |
144 | return true |
145 | else |
146 | print("Error: UnloadingStation '"..tostring(self.stationName).."' can't add storage, because it is not a valid storage object!") |
147 | end |
148 | end |
149 | end |
delete
DescriptionDefinitiondelete()Code
85 | function UnloadingStation:delete() |
86 | if self.mapHotspot ~= nil then |
87 | g_currentMission:removeMapHotspot(self.mapHotspot) |
88 | self.mapHotspot:delete() |
89 | end |
90 | |
91 | if self.unloadTriggers ~= nil then |
92 | for _,unloadTrigger in pairs(self.unloadTriggers) do |
93 | unloadTrigger:delete() |
94 | end |
95 | end |
96 | |
97 | UnloadingStation:superClass().delete(self) |
98 | end |
getCapacity
DescriptionDefinitiongetCapacity()Code
203 | function UnloadingStation:getCapacity(fillTypeIndex, farmId) |
204 | local capacity = 0 |
205 | |
206 | for _,targetStorage in pairs(self.targetStorages) do |
207 | if self:hasFarmAccessToStorage(farmId, targetStorage) then |
208 | capacity = capacity + targetStorage:getCapacity(fillTypeIndex) |
209 | end |
210 | end |
211 | |
212 | return capacity |
213 | end |
getFillLevel
DescriptionDefinitiongetFillLevel()Code
217 | function UnloadingStation:getFillLevel(fillTypeIndex, farmId) |
218 | local fillLevel = 0 |
219 | |
220 | for _,targetStorage in pairs(self.targetStorages) do |
221 | if self:hasFarmAccessToStorage(farmId, targetStorage) then |
222 | fillLevel = fillLevel + targetStorage:getFillLevel(fillTypeIndex) |
223 | end |
224 | end |
225 | |
226 | return fillLevel |
227 | end |
getFreeCapacity
DescriptionDefinitiongetFreeCapacity()Code
188 | function UnloadingStation:getFreeCapacity(fillTypeIndex, farmId) |
189 | local freeCapacity = 0 |
190 | |
191 | for _,targetStorage in pairs(self.targetStorages) do |
192 | -- Allow a nil farmId for generic checks. Without this. getIsFillTypeAllowed will also need farmId |
193 | if farmId == nil or self:hasFarmAccessToStorage(farmId, targetStorage) then |
194 | freeCapacity = freeCapacity + targetStorage:getFreeCapacity(fillTypeIndex) |
195 | end |
196 | end |
197 | |
198 | return freeCapacity |
199 | end |
getIsFillAllowedFromFarm
DescriptionDefinitiongetIsFillAllowedFromFarm()Code
267 | function UnloadingStation:getIsFillAllowedFromFarm(farmId) |
268 | for _, targetStorage in pairs(self.targetStorages) do |
269 | if self:hasFarmAccessToStorage(farmId, targetStorage) then |
270 | return true |
271 | end |
272 | end |
273 | |
274 | return false |
275 | end |
getIsFillTypeAllowed
DescriptionDefinitiongetIsFillTypeAllowed()Code
176 | function UnloadingStation:getIsFillTypeAllowed(fillTypeIndex, farmId) |
177 | for _,targetStorage in pairs(self.targetStorages) do |
178 | if targetStorage:getIsFillTypeSupported(fillTypeIndex, self) then |
179 | return true |
180 | end |
181 | end |
182 | |
183 | return false |
184 | end |
getIsFillTypeSupported
DescriptionDefinitiongetIsFillTypeSupported()Code
164 | function UnloadingStation:getIsFillTypeSupported(fillTypeIndex) |
165 | for _, targetStorage in pairs(self.targetStorages) do |
166 | if targetStorage:getIsFillTypeSupported(fillTypeIndex, self) then |
167 | return true |
168 | end |
169 | end |
170 | |
171 | return false |
172 | end |
getIsToolTypeAllowed
DescriptionDefinitiongetIsToolTypeAllowed()Code
231 | function UnloadingStation:getIsToolTypeAllowed(toolType) |
232 | return true |
233 | end |
hasFarmAccessToStorage
DescriptionDefinitionhasFarmAccessToStorage()Code
279 | function UnloadingStation:hasFarmAccessToStorage(farmId, storage) |
280 | if self.hasStoragePerFarm then |
281 | return farmId == storage:getOwnerFarmId() |
282 | else |
283 | return g_currentMission.accessHandler:canFarmAccess(farmId, storage) |
284 | end |
285 | end |
load
DescriptionDefinitionload()Code
25 | function UnloadingStation:load(id, xmlFile, key, customEnv) |
26 | self.rootNode = id |
27 | self.rootNodeName = getName(self.rootNode) |
28 | |
29 | self.appearsOnPDA = Utils.getNoNil(getXMLBool(xmlFile, key.."#appearsOnPDA"), false) |
30 | local rawName = Utils.getNoNil(getXMLString(xmlFile, key.."#stationName"), "UnloadingStation") |
31 | self.stationName = g_i18n:convertText(rawName, customEnv) -- returns input if it cannot be resolved |
32 | self.storageRadius = Utils.getNoNil(getXMLFloat(xmlFile, key.."#storageRadius"), 50) |
33 | |
34 | self.targetStorages = {} |
35 | self.unloadTriggers = {} |
36 | |
37 | local i = 0 |
38 | while true do |
39 | local unloadTriggerKey = string.format("%s.unloadTrigger(%d)", key, i) |
40 | if not hasXMLProperty(xmlFile, unloadTriggerKey) then |
41 | break |
42 | end |
43 | |
44 | local unloadTrigger = UnloadTrigger:new(self.isServer, self.isClient) |
45 | if unloadTrigger:load(self.rootNode, xmlFile, unloadTriggerKey, self) then |
46 | unloadTrigger:setTarget(self) |
47 | unloadTrigger:register(true) |
48 | table.insert(self.unloadTriggers, unloadTrigger) |
49 | else |
50 | unloadTrigger:delete() |
51 | end |
52 | |
53 | i = i + 1 |
54 | end |
55 | |
56 | if self.appearsOnPDA then |
57 | local mapPosition = self.rootNode |
58 | local mapPositionIndex = getUserAttribute(self.rootNode, "mapPositionIndex") |
59 | if mapPositionIndex ~= nil then |
60 | mapPosition = I3DUtil.indexToObject(self.rootNode, mapPositionIndex) |
61 | if mapPosition == nil then |
62 | mapPosition = self.rootNode |
63 | end |
64 | end |
65 | |
66 | self.mapHotspot = MapHotspot:new("loadingStation", MapHotspot.CATEGORY_TRIGGER) |
67 | self.mapHotspot:setText(self.stationName) |
68 | self.mapHotspot:setTextOptions(nil, nil, nil, {0.9559, 0.5647, 0.0423, 1}) |
69 | self.mapHotspot:setBorderedImage(nil, getNormalizedUVs(MapHotspot.UV.SELLING_POINT), {0.9559, 0.5647, 0.0423, 1}) |
70 | |
71 | local x, _, z = getWorldTranslation(mapPosition) |
72 | self.mapHotspot:setWorldPosition(x, z) |
73 | |
74 | local hotspotTextOffset = Utils.getNoNil(getXMLString(xmlFile, key .. "#hotspotTextOffset"), "0px 0px") |
75 | self.mapHotspot:setRawTextOffset(hotspotTextOffset) |
76 | |
77 | g_currentMission:addMapHotspot(self.mapHotspot) |
78 | end |
79 | |
80 | return true |
81 | end |
new
DescriptionDefinitionnew()Code
18 | function UnloadingStation:new(isServer, isClient, customMt) |
19 | local self = Object:new(isServer, isClient, customMt or UnloadingStation_mt) |
20 | return self |
21 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
104 | function UnloadingStation:readStream(streamId, connection) |
105 | UnloadingStation:superClass().readStream(self, streamId, connection) |
106 | if connection:getIsServer() then |
107 | for _, unloadTrigger in ipairs(self.unloadTriggers) do |
108 | local unloadTriggerId = NetworkUtil.readNodeObjectId(streamId) |
109 | unloadTrigger:readStream(streamId, connection) |
110 | g_client:finishRegisterObject(unloadTrigger, unloadTriggerId) |
111 | end |
112 | end |
113 | end |
removeTargetStorage
DescriptionDefinitionremoveTargetStorage()Code
153 | function UnloadingStation:removeTargetStorage(storage) |
154 | if storage ~= nil then |
155 | if storage.getIsFillTypeSupported ~= nil and storage.setFillLevel ~= nil and storage.getFillLevel ~= nil then |
156 | storage:removeUnloadingStation(self) |
157 | self.targetStorages[storage] = nil |
158 | end |
159 | end |
160 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
119 | function UnloadingStation:writeStream(streamId, connection) |
120 | UnloadingStation:superClass().writeStream(self, streamId, connection) |
121 | if not connection:getIsServer() then |
122 | for _, unloadTrigger in ipairs(self.unloadTriggers) do |
123 | NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(unloadTrigger)) |
124 | unloadTrigger:writeStream(streamId, connection) |
125 | g_server:registerObjectInStream(connection, unloadTrigger) |
126 | end |
127 | end |
128 | end |