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
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- AIConveyorBelt
- AIDrivable
- AIFieldWorker
- AIImplement
- AIJobVehicle
- AIVehicle
- AIVehicleObstacle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- AutoLoader
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BigBag
- BunkerSiloCompacter
- BunkerSiloInteractor
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- CropSensor
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- ExtendedAIVehicle
- ExtendedCombine
- ExtendedMotorized
- ExtendedMower
- ExtendedSowingMachine
- ExtendedSprayer
- ExtendedWearable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- HeadlandAnimation
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- InlineWrapper
- JigglingParts
- Leveler
- LicensePlates
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- ManureSensor
- MixerWagon
- Motorized
- Mountable
- Mower
- Mulcher
- MultipleItemPurchase
- Pallet
- Pickup
- Pipe
- PlaceableAI
- PlaceableAnimatedObjects
- PlaceableBeehive
- PlaceableBeehivePalletSpa...
- PlaceableBunkerSilo
- PlaceableBuyingStation
- PlaceableCartridgePlayer
- PlaceableChargingStation
- PlaceableClearAreas
- PlaceableColorable
- PlaceableDeletedNodes
- PlaceableDoghouse
- PlaceableDynamicallyLoade...
- PlaceableFarmhouse
- PlaceableFence
- PlaceableFoliageAreas
- PlaceableGreenhouse
- PlaceableHighPressureWash...
- PlaceableHotspots
- PlaceableHusbandry
- PlaceableHusbandryAnimals
- PlaceableHusbandryFeeding...
- PlaceableHusbandryFence
- PlaceableHusbandryFood
- PlaceableHusbandryLiquidM...
- PlaceableHusbandryMilk
- PlaceableHusbandryPallets
- PlaceableHusbandryStraw
- PlaceableHusbandryWater
- PlaceableIncomePerHour
- PlaceableIndoorAreas
- PlaceableInfoTrigger
- PlaceableLeveling
- PlaceableLights
- PlaceableManureHeap
- PlaceablePlacement
- PlaceableProductionPoint
- PlaceableSellingStation
- PlaceableSilo
- PlaceableSiloExtension
- PlaceableSolarPanels
- PlaceableTipOcclusionArea...
- PlaceableTrainSystem
- PlaceableTriggerMarkers
- PlaceableVine
- PlaceableWardrobe
- PlaceableWeatherStation
- PlaceableWeighingStation
- PlaceableWindTurbine
- PlaceableWorkshop
- Plow
- PlowPacker
- PowerConsumer
- PowerTakeOffs
- PrecisionFarmingStatistic
- PushHandTool
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- RTKStation
- SaltSpreader
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SoilSampler
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StonePicker
- StrawBlower
- StumpCutter
- SupportVehicle
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TestAreas
- TipOccluder
- Trailer
- TreePlanter
- TreeSaplingPallet
- TreeSaw
- TurnOnVehicle
- VariableWorkWidth
- VehicleSettings
- VineCutter
- VineDetector
- VinePrepruner
- Washable
- WaterTrailer
- Wearable
- Weeder
- WeedSpotSpray
- Wheels
- WindBending
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- 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
PlaceableSiloExtension
DescriptionSpecialization for placeablesFunctions
- canBeSold
- getCanBePlacedAt
- getSpecValueVolume
- initSpecialization
- loadFromXMLFile
- loadSpecValueVolume
- onDelete
- onFinalizePlacement
- onLoad
- onReadStream
- onSell
- onWriteStream
- prerequisitesPresent
- registerEventListeners
- registerOverwrittenFunctions
- registerSavegameXMLPaths
- registerXMLPaths
- saveToXMLFile
- setOwnerFarmId
canBeSold
DescriptionDefinitioncanBeSold()Code
179 | function PlaceableSiloExtension:canBeSold(superFunc) |
180 | local spec = self.spec_siloExtension |
181 | |
182 | if spec.storage == nil then |
183 | return true, nil |
184 | end |
185 | |
186 | local warning = g_i18n:getText("info_siloExtensionNotEmpty") .. "\n" |
187 | local totalFillLevel = 0 |
188 | |
189 | spec.totalFillTypeSellPrice = 0 |
190 | |
191 | for fillTypeIndex, fillLevel in pairs(spec.storage.fillLevels) do |
192 | totalFillLevel = totalFillLevel + fillLevel |
193 | if fillLevel > 0 then |
194 | local lowestSellPrice = math.huge |
195 | |
196 | for _, unloadingStation in pairs(g_currentMission.storageSystem:getUnloadingStations()) do |
197 | if unloadingStation.owningPlaceable ~= nil |
198 | and unloadingStation.isSellingPoint |
199 | and unloadingStation.acceptedFillTypes[fillTypeIndex] then |
200 | local price = unloadingStation:getEffectiveFillTypePrice(fillTypeIndex) |
201 | |
202 | if price > 0 then |
203 | lowestSellPrice = math.min(lowestSellPrice, price) |
204 | end |
205 | end |
206 | end |
207 | |
208 | if lowestSellPrice == math.huge then |
209 | lowestSellPrice = 0.5 |
210 | end |
211 | |
212 | local price = fillLevel * lowestSellPrice * PlaceableSiloExtension.PRICE_SELL_FACTOR |
213 | local fillType = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex) |
214 | warning = string.format("%s%s (%d %s) - %s: %s\n", warning, fillType.title, g_i18n:getFluid(fillLevel), g_i18n:getText("unit_literShort"), g_i18n:getText("ui_sellValue"), g_i18n:formatMoney(price, 0, true, true)) |
215 | spec.totalFillTypeSellPrice = spec.totalFillTypeSellPrice + price |
216 | end |
217 | end |
218 | |
219 | if totalFillLevel > 0 then |
220 | return true, warning |
221 | end |
222 | |
223 | return true, nil |
224 | end |
getCanBePlacedAt
DescriptionDefinitiongetCanBePlacedAt()Code
152 | function PlaceableSiloExtension:getCanBePlacedAt(superFunc, x, y, z, farmId) |
153 | local canBePlaced, errorMessage = superFunc(self, x, y, z, farmId) |
154 | if not canBePlaced then |
155 | return false, errorMessage |
156 | end |
157 | |
158 | local spec = self.spec_siloExtension |
159 | if spec.storage == nil then |
160 | return false |
161 | end |
162 | |
163 | spec.lastFoundUnloadingStations = nil |
164 | spec.lastFoundLoadingStations = nil |
165 | |
166 | local storageSystem = g_currentMission.storageSystem |
167 | -- we also need to check farmId |
168 | spec.lastFoundUnloadingStations = storageSystem:getExtendableUnloadingStationsInRange(spec.storage, farmId, x, y, z) |
169 | spec.lastFoundLoadingStations = storageSystem:getExtendableLoadingStationsInRange(spec.storage, farmId, x, y, z) |
170 | if #spec.lastFoundUnloadingStations == 0 and #spec.lastFoundLoadingStations == 0 then |
171 | return false, spec.nearSiloWarning |
172 | end |
173 | |
174 | return true |
175 | end |
getSpecValueVolume
DescriptionDefinitiongetSpecValueVolume()Code
277 | function PlaceableSiloExtension.getSpecValueVolume(storeItem, realItem) |
278 | if storeItem.specs.siloExtensionVolume == nil then |
279 | return nil |
280 | end |
281 | |
282 | return g_i18n:formatVolume(storeItem.specs.siloExtensionVolume) |
283 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
63 | function PlaceableSiloExtension.initSpecialization() |
64 | g_storeManager:addSpecType("siloExtensionVolume", "shopListAttributeIconCapacity", PlaceableSiloExtension.loadSpecValueVolume, PlaceableSiloExtension.getSpecValueVolume, "placeable") |
65 | end |
loadFromXMLFile
DescriptionDefinitionloadFromXMLFile()Code
228 | function PlaceableSiloExtension:loadFromXMLFile(xmlFile, key) |
229 | local spec = self.spec_siloExtension |
230 | |
231 | if spec.storage ~= nil then |
232 | spec.storage:loadFromXMLFile(xmlFile, key) |
233 | end |
234 | end |
loadSpecValueVolume
DescriptionDefinitionloadSpecValueVolume()Code
271 | function PlaceableSiloExtension.loadSpecValueVolume(xmlFile, customEnvironment, baseDir) |
272 | return xmlFile:getValue("placeable.siloExtension.storage#capacity") |
273 | end |
onDelete
DescriptionDefinitiononDelete()Code
90 | function PlaceableSiloExtension:onDelete() |
91 | local spec = self.spec_siloExtension |
92 | |
93 | if spec.storage ~= nil then |
94 | local storageSystem = g_currentMission.storageSystem |
95 | if storageSystem:hasStorage(spec.storage) then |
96 | -- just remove storage from all registered unloading and loading stations |
97 | storageSystem:removeStorageFromUnloadingStations(spec.storage, spec.storage.unloadingStations) |
98 | storageSystem:removeStorageFromLoadingStations(spec.storage, spec.storage.loadingStations) |
99 | |
100 | storageSystem:removeStorage(spec.storage) |
101 | end |
102 | |
103 | spec.storage:delete() |
104 | end |
105 | end |
onFinalizePlacement
DescriptionDefinitiononFinalizePlacement()Code
109 | function PlaceableSiloExtension:onFinalizePlacement() |
110 | local spec = self.spec_siloExtension |
111 | if spec.storage ~= nil then |
112 | local storageSystem = g_currentMission.storageSystem |
113 | local ownerFarmId = self:getOwnerFarmId() |
114 | local lastFoundUnloadingStations = storageSystem:getExtendableUnloadingStationsInRange(spec.storage, ownerFarmId) |
115 | local lastFoundLoadingStations = storageSystem:getExtendableLoadingStationsInRange(spec.storage, ownerFarmId) |
116 | |
117 | spec.storage:setOwnerFarmId(self:getOwnerFarmId(), true) |
118 | storageSystem:addStorage(spec.storage) |
119 | spec.storage:register(true) |
120 | |
121 | storageSystem:addStorageToUnloadingStations(spec.storage, lastFoundUnloadingStations) |
122 | storageSystem:addStorageToLoadingStations(spec.storage, lastFoundLoadingStations) |
123 | end |
124 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
70 | function PlaceableSiloExtension:onLoad(savegame) |
71 | local spec = self.spec_siloExtension |
72 | local xmlFile = self.xmlFile |
73 | |
74 | local storageKey = "placeable.siloExtension.storage" |
75 | spec.foreignSilo = xmlFile:getValue(storageKey.."#foreignSilo", false) -- Shows as foreign silo in the menu |
76 | |
77 | if xmlFile:hasProperty(storageKey) then |
78 | spec.storage = Storage.new(self.isServer, self.isClient) |
79 | spec.storage:load(self.components, xmlFile, storageKey, self.i3dMappings) |
80 | spec.storage.foreignSilo = spec.foreignSilo |
81 | else |
82 | Logging.xmlWarning(xmlFile, "Missing 'storage' for siloExtension!") |
83 | end |
84 | |
85 | spec.nearSiloWarning = xmlFile:getValue("placeable.siloExtension#nearSiloWarning", "warning_siloExtensionNotNearSilo", self.customEnvironment) |
86 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
128 | function PlaceableSiloExtension:onReadStream(streamId, connection) |
129 | local spec = self.spec_siloExtension |
130 | |
131 | if spec.storage ~= nil then |
132 | local storageId = NetworkUtil.readNodeObjectId(streamId) |
133 | spec.storage:readStream(streamId, connection) |
134 | g_client:finishRegisterObject(spec.storage, storageId) |
135 | end |
136 | end |
onSell
DescriptionDefinitiononSell()Code
259 | function PlaceableSiloExtension:onSell() |
260 | local spec = self.spec_siloExtension |
261 | |
262 | if self.isServer then |
263 | if spec.totalFillTypeSellPrice > 0 then |
264 | g_currentMission:addMoney(spec.totalFillTypeSellPrice, self:getOwnerFarmId(), MoneyType.HARVEST_INCOME, true, true) |
265 | end |
266 | end |
267 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
140 | function PlaceableSiloExtension:onWriteStream(streamId, connection) |
141 | local spec = self.spec_siloExtension |
142 | |
143 | if spec.storage ~= nil then |
144 | NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(spec.storage)) |
145 | spec.storage:writeStream(streamId, connection) |
146 | g_server:registerObjectInStream(connection, spec.storage) |
147 | end |
148 | end |
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
19 | function PlaceableSiloExtension.prerequisitesPresent(specializations) |
20 | return true |
21 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
33 | function PlaceableSiloExtension.registerEventListeners(placeableType) |
34 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableSiloExtension) |
35 | SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableSiloExtension) |
36 | SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableSiloExtension) |
37 | SpecializationUtil.registerEventListener(placeableType, "onReadStream", PlaceableSiloExtension) |
38 | SpecializationUtil.registerEventListener(placeableType, "onWriteStream", PlaceableSiloExtension) |
39 | SpecializationUtil.registerEventListener(placeableType, "onSell", PlaceableSiloExtension) |
40 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
25 | function PlaceableSiloExtension.registerOverwrittenFunctions(placeableType) |
26 | SpecializationUtil.registerOverwrittenFunction(placeableType, "setOwnerFarmId", PlaceableSiloExtension.setOwnerFarmId) |
27 | SpecializationUtil.registerOverwrittenFunction(placeableType, "getCanBePlacedAt", PlaceableSiloExtension.getCanBePlacedAt) |
28 | SpecializationUtil.registerOverwrittenFunction(placeableType, "canBeSold", PlaceableSiloExtension.canBeSold) |
29 | end |
registerSavegameXMLPaths
DescriptionDefinitionregisterSavegameXMLPaths()Code
55 | function PlaceableSiloExtension.registerSavegameXMLPaths(schema, basePath) |
56 | schema:setXMLSpecializationType("SiloExtension") |
57 | Storage.registerSavegameXMLPaths(schema, basePath) |
58 | schema:setXMLSpecializationType() |
59 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
44 | function PlaceableSiloExtension.registerXMLPaths(schema, basePath) |
45 | schema:setXMLSpecializationType("SiloExtension") |
46 | schema:register(XMLValueType.BOOL, basePath .. ".siloExtension.storage#foreignSilo", "Shows as foreign silo in the menu", false) |
47 | schema:register(XMLValueType.L10N_STRING, basePath .. ".siloExtension#nearSiloWarning", "Warning that is shown if extension is not placed near another silo") |
48 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".siloExtension.storage#node", "Storage node") |
49 | Storage.registerXMLPaths(schema, basePath .. ".siloExtension.storage") |
50 | schema:setXMLSpecializationType() |
51 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
238 | function PlaceableSiloExtension:saveToXMLFile(xmlFile, key, usedModNames) |
239 | local spec = self.spec_siloExtension |
240 | if spec.storage ~= nil then |
241 | spec.storage:saveToXMLFile(xmlFile, key, usedModNames) |
242 | end |
243 | end |
setOwnerFarmId
DescriptionDefinitionsetOwnerFarmId()Code
247 | function PlaceableSiloExtension:setOwnerFarmId(superFunc, farmId, noEventSend) |
248 | local spec = self.spec_siloExtension |
249 | |
250 | superFunc(self, farmId, noEventSend) |
251 | |
252 | if self.isServer and spec.storage ~= nil then |
253 | spec.storage:setOwnerFarmId(farmId, true) |
254 | end |
255 | end |