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
PlaceableHusbandryWater
DescriptionSpecialization for placeablesFunctions
- getConditionInfos
- onDelete
- onFinalizePlacement
- onHusbandryAnimalsCreated
- onHusbandryAnimalsUpdate
- onHusbandryFillLevelChanged
- onLoad
- onPostFinalizePlacement
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- registerXMLPaths
- updateFeeding
- updateInfo
- updateWaterPlane
getConditionInfos
DescriptionDefinitiongetConditionInfos()Code
206 | function PlaceableHusbandryWater:getConditionInfos(superFunc) |
207 | local infos = superFunc(self) |
208 | local spec = self.spec_husbandryWater |
209 | |
210 | if not spec.automaticWaterSupply then |
211 | local info = {} |
212 | local fillType = g_fillTypeManager:getFillTypeByIndex(spec.fillType) |
213 | info.title = fillType.title |
214 | info.value = self:getHusbandryFillLevel(spec.fillType) |
215 | local capacity = self:getHusbandryCapacity(spec.fillType) |
216 | local ratio = 0 |
217 | if capacity > 0 then |
218 | ratio = info.value / capacity |
219 | end |
220 | info.ratio = MathUtil.clamp(ratio, 0, 1) |
221 | info.invertedBar = false |
222 | |
223 | table.insert(infos, info) |
224 | end |
225 | |
226 | return infos |
227 | end |
onDelete
DescriptionDefinitiononDelete()Code
94 | function PlaceableHusbandryWater:onDelete() |
95 | local spec = self.spec_husbandryWater |
96 | if spec.waterPlane ~= nil then |
97 | spec.waterPlane:delete() |
98 | spec.waterPlane = nil |
99 | end |
100 | end |
onFinalizePlacement
DescriptionDefinitiononFinalizePlacement()Code
104 | function PlaceableHusbandryWater:onFinalizePlacement() |
105 | local spec = self.spec_husbandryWater |
106 | |
107 | if not spec.automaticWaterSupply then |
108 | if not self:getHusbandryIsFillTypeSupported(spec.fillType) then |
109 | Logging.warning("Missing filltype 'water' in husbandry storage! Changing to automatic water supply") |
110 | spec.automaticWaterSupply = true |
111 | end |
112 | end |
113 | end |
onHusbandryAnimalsCreated
DescriptionDefinitiononHusbandryAnimalsCreated()Code
164 | function PlaceableHusbandryWater:onHusbandryAnimalsCreated(husbandry) |
165 | if husbandry ~= nil then |
166 | local spec = self.spec_husbandryWater |
167 | spec.husbandry = husbandry |
168 | for _, waterPlace in ipairs(spec.waterPlaces) do |
169 | waterPlace.place = addFeedingPlace(husbandry, waterPlace.node, 0.0, AnimalHusbandryFeedingType.WATER) |
170 | end |
171 | end |
172 | end |
onHusbandryAnimalsUpdate
DescriptionDefinitiononHusbandryAnimalsUpdate()Code
176 | function PlaceableHusbandryWater:onHusbandryAnimalsUpdate(clusters) |
177 | local spec = self.spec_husbandryWater |
178 | |
179 | spec.litersPerHour = 0 |
180 | for _, cluster in ipairs(clusters) do |
181 | local subType = g_currentMission.animalSystem:getSubTypeByIndex(cluster.subTypeIndex) |
182 | if subType ~= nil then |
183 | local water = subType.input.water |
184 | if water ~= nil then |
185 | local age = cluster:getAge() |
186 | local litersPerAnimal = water:get(age) |
187 | local litersPerDay = litersPerAnimal * cluster:getNumAnimals() |
188 | |
189 | spec.litersPerHour = spec.litersPerHour + (litersPerDay / 24) |
190 | end |
191 | end |
192 | end |
193 | end |
onHusbandryFillLevelChanged
DescriptionDefinitiononHusbandryFillLevelChanged()Code
197 | function PlaceableHusbandryWater:onHusbandryFillLevelChanged(fillTypeIndex, delta) |
198 | local spec = self.spec_husbandryWater |
199 | if fillTypeIndex == spec.fillType then |
200 | self:updateWaterPlane() |
201 | end |
202 | end |
onLoad
DescriptionDefinitiononLoad()Code
61 | function PlaceableHusbandryWater:onLoad(savegame) |
62 | local spec = self.spec_husbandryWater |
63 | |
64 | spec.husbandry = nil |
65 | spec.litersPerHour = 0 |
66 | spec.automaticWaterSupply = false |
67 | spec.fillType = FillType.WATER |
68 | spec.waterPlaces = {} |
69 | spec.info = {title=g_i18n:getText("fillType_water"), text=""} |
70 | spec.automaticWaterSupply = self.xmlFile:getValue("placeable.husbandry.water#automaticWaterSupply", spec.automaticWaterSupply) |
71 | |
72 | spec.waterPlane = FillPlane.new() |
73 | if spec.waterPlane:load(self.components, self.xmlFile, "placeable.husbandry.water.waterPlane", self.i3dMappings) then |
74 | spec.waterPlane:setState(spec.automaticWaterSupply and 1 or 0) |
75 | else |
76 | spec.waterPlane:delete() |
77 | spec.waterPlane = nil |
78 | end |
79 | |
80 | self.xmlFile:iterate("placeable.husbandry.water.waterPlaces.waterPlace", function(_, key) |
81 | local node = self.xmlFile:getValue(key .. "#node", nil, self.components, self.i3dMappings) |
82 | table.insert(spec.waterPlaces, {node=node, place=nil}) |
83 | end) |
84 | end |
onPostFinalizePlacement
DescriptionDefinitiononPostFinalizePlacement()Code
88 | function PlaceableHusbandryWater:onPostFinalizePlacement() |
89 | self:updateWaterPlane() |
90 | 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 PlaceableHusbandryWater.prerequisitesPresent(specializations) |
19 | return true |
20 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
38 | function PlaceableHusbandryWater.registerEventListeners(placeableType) |
39 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableHusbandryWater) |
40 | SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableHusbandryWater) |
41 | SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableHusbandryWater) |
42 | SpecializationUtil.registerEventListener(placeableType, "onPostFinalizePlacement", PlaceableHusbandryWater) |
43 | SpecializationUtil.registerEventListener(placeableType, "onHusbandryAnimalsUpdate", PlaceableHusbandryWater) |
44 | SpecializationUtil.registerEventListener(placeableType, "onHusbandryAnimalsCreated", PlaceableHusbandryWater) |
45 | SpecializationUtil.registerEventListener(placeableType, "onHusbandryFillLevelChanged", PlaceableHusbandryWater) |
46 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
24 | function PlaceableHusbandryWater.registerFunctions(placeableType) |
25 | SpecializationUtil.registerFunction(placeableType, "updateWaterPlane", PlaceableHusbandryWater.updateWaterPlane) |
26 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
30 | function PlaceableHusbandryWater.registerOverwrittenFunctions(placeableType) |
31 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateFeeding", PlaceableHusbandryWater.updateFeeding) |
32 | SpecializationUtil.registerOverwrittenFunction(placeableType, "getConditionInfos", PlaceableHusbandryWater.getConditionInfos) |
33 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableHusbandryWater.updateInfo) |
34 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
50 | function PlaceableHusbandryWater.registerXMLPaths(schema, basePath) |
51 | schema:setXMLSpecializationType("Husbandry") |
52 | basePath = basePath .. ".husbandry.water" |
53 | schema:register(XMLValueType.BOOL, basePath .. "#automaticWaterSupply", "If husbandry has a automatic water supply", false) |
54 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".waterPlaces.waterPlace(?)#node", "Water place") |
55 | FillPlane.registerXMLPaths(schema, basePath .. ".waterPlane") |
56 | schema:setXMLSpecializationType() |
57 | end |
updateFeeding
DescriptionDefinitionupdateFeeding()Code
141 | function PlaceableHusbandryWater:updateFeeding(superFunc) |
142 | local factor = superFunc(self) |
143 | local spec = self.spec_husbandryWater |
144 | |
145 | if self.isServer and spec.litersPerHour > 0 then |
146 | local delta = spec.litersPerHour * g_currentMission.environment.timeAdjustment |
147 | |
148 | if spec.automaticWaterSupply then |
149 | local fillType = g_fillTypeManager:getFillTypeByIndex(spec.fillType) |
150 | local price = delta * fillType.pricePerLiter |
151 | g_currentMission:addMoney(-price, self:getOwnerFarmId(), MoneyType.PURCHASE_WATER, false, false) |
152 | else |
153 | local remainingLiters = self:removeHusbandryFillLevel(nil, delta, spec.fillType) |
154 | local usedDelta = (delta - remainingLiters) |
155 | factor = factor * MathUtil.clamp(usedDelta / delta, 0, 1) |
156 | end |
157 | end |
158 | |
159 | return factor |
160 | end |
updateInfo
DescriptionDefinitionupdateInfo()Code
231 | function PlaceableHusbandryWater:updateInfo(superFunc, infoTable) |
232 | superFunc(self, infoTable) |
233 | local spec = self.spec_husbandryWater |
234 | if not spec.automaticWaterSupply then |
235 | local fillLevel = self:getHusbandryFillLevel(spec.fillType) |
236 | spec.info.text = string.format("%d l", fillLevel) |
237 | table.insert(infoTable, spec.info) |
238 | end |
239 | end |
updateWaterPlane
DescriptionDefinitionupdateWaterPlane()Code
117 | function PlaceableHusbandryWater:updateWaterPlane() |
118 | local spec = self.spec_husbandryWater |
119 | local fillLevel = self:getHusbandryFillLevel(spec.fillType, nil) |
120 | |
121 | if spec.waterPlane ~= nil then |
122 | local capacity = self:getHusbandryCapacity(spec.fillType, nil) |
123 | local factor = 0 |
124 | if capacity > 0 then |
125 | factor = fillLevel / capacity |
126 | end |
127 | spec.waterPlane:setState(factor) |
128 | end |
129 | |
130 | if spec.husbandry ~= nil then |
131 | for _, waterPlace in pairs(spec.waterPlaces) do |
132 | if waterPlace.place ~= nil then |
133 | updateFeedingPlace(spec.husbandry, waterPlace.place, fillLevel) |
134 | end |
135 | end |
136 | end |
137 | end |