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
PlaceableHusbandryStraw
DescriptionSpecialization for placeablesFunctions
- getConditionInfos
- onDelete
- onFinalizePlacement
- onHusbandryAnimalsUpdate
- onHusbandryFillLevelChanged
- onLoad
- onPostFinalizePlacement
- onReadStream
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- registerXMLPaths
- updateInfo
- updateOutput
- updateProduction
- updateStrawPlane
getConditionInfos
DescriptionDefinitiongetConditionInfos()Code
217 | function PlaceableHusbandryStraw:getConditionInfos(superFunc) |
218 | local infos = superFunc(self) |
219 | local spec = self.spec_husbandryStraw |
220 | |
221 | local info = {} |
222 | local fillType = g_fillTypeManager:getFillTypeByIndex(spec.inputFillType) |
223 | info.title = fillType.title |
224 | info.value = self:getHusbandryFillLevel(spec.inputFillType) |
225 | local capacity = self:getHusbandryCapacity(spec.inputFillType) |
226 | local ratio = 0 |
227 | if capacity > 0 then |
228 | ratio = info.value / capacity |
229 | end |
230 | info.ratio = MathUtil.clamp(ratio, 0, 1) |
231 | info.invertedBar = false |
232 | |
233 | table.insert(infos, info) |
234 | |
235 | return infos |
236 | end |
onDelete
DescriptionDefinitiononDelete()Code
90 | function PlaceableHusbandryStraw:onDelete() |
91 | local spec = self.spec_husbandryStraw |
92 | if spec.strawPlane ~= nil then |
93 | spec.strawPlane:delete() |
94 | spec.strawPlane = nil |
95 | end |
96 | end |
onFinalizePlacement
DescriptionDefinitiononFinalizePlacement()Code
100 | function PlaceableHusbandryStraw:onFinalizePlacement() |
101 | local spec = self.spec_husbandryStraw |
102 | if not self:getHusbandryIsFillTypeSupported(spec.inputFillType) then |
103 | Logging.warning("Missing filltype 'straw' in husbandry storage!") |
104 | end |
105 | if self.isManureActive and not self:getHusbandryIsFillTypeSupported(spec.outputFillType) then |
106 | Logging.warning("Missing filltype 'manure' in husbandry storage!") |
107 | end |
108 | end |
onHusbandryAnimalsUpdate
DescriptionDefinitiononHusbandryAnimalsUpdate()Code
178 | function PlaceableHusbandryStraw:onHusbandryAnimalsUpdate(clusters) |
179 | local spec = self.spec_husbandryStraw |
180 | spec.inputLitersPerHour = 0 |
181 | spec.outputLitersPerHour = 0 |
182 | for _, cluster in ipairs(clusters) do |
183 | local subType = g_currentMission.animalSystem:getSubTypeByIndex(cluster.subTypeIndex) |
184 | if subType ~= nil then |
185 | local straw = subType.input.straw |
186 | if straw ~= nil then |
187 | local age = cluster:getAge() |
188 | local litersPerAnimal = straw:get(age) |
189 | local litersPerDay = litersPerAnimal * cluster:getNumAnimals() |
190 | |
191 | spec.inputLitersPerHour = spec.inputLitersPerHour + (litersPerDay / 24) |
192 | end |
193 | |
194 | local manure = subType.output.manure |
195 | if manure ~= nil then |
196 | local age = cluster:getAge() |
197 | local litersPerAnimal = manure:get(age) |
198 | local litersPerDay = litersPerAnimal * cluster:getNumAnimals() |
199 | |
200 | spec.outputLitersPerHour = spec.outputLitersPerHour + (litersPerDay / 24) |
201 | end |
202 | end |
203 | end |
204 | end |
onHusbandryFillLevelChanged
DescriptionDefinitiononHusbandryFillLevelChanged()Code
208 | function PlaceableHusbandryStraw:onHusbandryFillLevelChanged(fillTypeIndex, delta) |
209 | local spec = self.spec_husbandryStraw |
210 | if fillTypeIndex == spec.inputFillType then |
211 | self:updateStrawPlane() |
212 | end |
213 | end |
onLoad
DescriptionDefinitiononLoad()Code
62 | function PlaceableHusbandryStraw:onLoad(savegame) |
63 | local spec = self.spec_husbandryStraw |
64 | |
65 | spec.manureFactor = self.xmlFile:getValue("placeable.husbandry.straw.manure#factor", 1) |
66 | spec.isManureActive = self.xmlFile:getValue("placeable.husbandry.straw.manure#active", true) |
67 | |
68 | spec.strawPlane = FillPlane.new() |
69 | if spec.strawPlane:load(self.components, self.xmlFile, "placeable.husbandry.straw.strawPlane", self.i3dMappings) then |
70 | spec.strawPlane:setState(0) |
71 | else |
72 | spec.strawPlane:delete() |
73 | spec.strawPlane = nil |
74 | end |
75 | spec.inputFillType = FillType.STRAW |
76 | spec.outputFillType = FillType.MANURE |
77 | spec.inputLitersPerHour = 0 |
78 | spec.outputLitersPerHour = 0 |
79 | spec.info = {title=g_i18n:getText("fillType_straw"), text=""} |
80 | end |
onPostFinalizePlacement
DescriptionDefinitiononPostFinalizePlacement()Code
84 | function PlaceableHusbandryStraw:onPostFinalizePlacement() |
85 | self:updateStrawPlane() |
86 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
112 | function PlaceableHusbandryStraw:onReadStream(streamId, connection) |
113 | self:updateStrawPlane() |
114 | 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 |
18 | function PlaceableHusbandryStraw.prerequisitesPresent(specializations) |
19 | return true |
20 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
39 | function PlaceableHusbandryStraw.registerEventListeners(placeableType) |
40 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableHusbandryStraw) |
41 | SpecializationUtil.registerEventListener(placeableType, "onPostFinalizePlacement", PlaceableHusbandryStraw) |
42 | SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableHusbandryStraw) |
43 | SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableHusbandryStraw) |
44 | SpecializationUtil.registerEventListener(placeableType, "onReadStream", PlaceableHusbandryStraw) |
45 | SpecializationUtil.registerEventListener(placeableType, "onHusbandryAnimalsUpdate", PlaceableHusbandryStraw) |
46 | SpecializationUtil.registerEventListener(placeableType, "onHusbandryFillLevelChanged", PlaceableHusbandryStraw) |
47 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
24 | function PlaceableHusbandryStraw.registerFunctions(placeableType) |
25 | SpecializationUtil.registerFunction(placeableType, "updateStrawPlane", PlaceableHusbandryStraw.updateStrawPlane) |
26 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
30 | function PlaceableHusbandryStraw.registerOverwrittenFunctions(placeableType) |
31 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateOutput", PlaceableHusbandryStraw.updateOutput) |
32 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateProduction", PlaceableHusbandryStraw.updateProduction) |
33 | SpecializationUtil.registerOverwrittenFunction(placeableType, "getConditionInfos", PlaceableHusbandryStraw.getConditionInfos) |
34 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableHusbandryStraw.updateInfo) |
35 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
51 | function PlaceableHusbandryStraw.registerXMLPaths(schema, basePath) |
52 | schema:setXMLSpecializationType("Husbandry") |
53 | basePath = basePath .. ".husbandry.straw" |
54 | FillPlane.registerXMLPaths(schema, basePath .. ".strawPlane") |
55 | schema:register(XMLValueType.FLOAT, basePath .. ".manure#factor", "Factor to transform straw to manure", 1) |
56 | schema:register(XMLValueType.BOOL, basePath .. ".manure#active", "Enable manure production", true) |
57 | schema:setXMLSpecializationType() |
58 | end |
updateInfo
DescriptionDefinitionupdateInfo()Code
240 | function PlaceableHusbandryStraw:updateInfo(superFunc, infoTable) |
241 | superFunc(self, infoTable) |
242 | local spec = self.spec_husbandryStraw |
243 | |
244 | local fillLevel = self:getHusbandryFillLevel(spec.inputFillType) |
245 | spec.info.text = string.format("%d l", fillLevel) |
246 | table.insert(infoTable, spec.info) |
247 | end |
updateOutput
DescriptionDefinitionupdateOutput()Code
134 | function PlaceableHusbandryStraw:updateOutput(superFunc, foodFactor, productionFactor, globalProductionFactor) |
135 | if self.isServer then |
136 | local spec = self.spec_husbandryStraw |
137 | |
138 | if spec.inputLitersPerHour > 0 then |
139 | local amount = spec.inputLitersPerHour * g_currentMission.environment.timeAdjustment |
140 | local delta = amount - self:removeHusbandryFillLevel(self:getOwnerFarmId(), amount, spec.inputFillType) |
141 | if spec.outputLitersPerHour > 0 and delta > 0 then |
142 | local liters = foodFactor * spec.outputLitersPerHour * (delta/amount) * g_currentMission.environment.timeAdjustment -- outputLitersPerHour increases with number of animals |
143 | if liters > 0 then |
144 | self:addHusbandryFillLevelFromTool(self:getOwnerFarmId(), liters, spec.outputFillType, nil, nil, nil) |
145 | end |
146 | end |
147 | |
148 | self:updateStrawPlane() |
149 | end |
150 | end |
151 | |
152 | superFunc(self, foodFactor, productionFactor, globalProductionFactor) |
153 | end |
updateProduction
DescriptionDefinitionupdateProduction()Code
157 | function PlaceableHusbandryStraw:updateProduction(superFunc, foodFactor) |
158 | local factor = superFunc(self, foodFactor) |
159 | |
160 | if self.isServer then |
161 | local spec = self.spec_husbandryStraw |
162 | local fillLevel = self:getHusbandryFillLevel(spec.inputFillType) |
163 | if fillLevel > 0 then |
164 | local freeCapacity = self:getHusbandryFreeCapacity(spec.outputFillType) |
165 | if freeCapacity <= 0 then |
166 | factor = factor * 0.75 |
167 | end |
168 | else |
169 | factor = factor * 0.9 |
170 | end |
171 | end |
172 | |
173 | return factor |
174 | end |
updateStrawPlane
DescriptionDefinitionupdateStrawPlane()Code
118 | function PlaceableHusbandryStraw:updateStrawPlane() |
119 | local spec = self.spec_husbandryStraw |
120 | if spec.strawPlane ~= nil then |
121 | local capacity = self:getHusbandryCapacity(spec.inputFillType, nil) |
122 | local fillLevel = self:getHusbandryFillLevel(spec.inputFillType, nil) |
123 | local factor = 0 |
124 | if capacity > 0 then |
125 | factor = fillLevel / capacity |
126 | end |
127 | |
128 | spec.strawPlane:setState(factor) |
129 | end |
130 | end |