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
PlaceableHusbandryMilk
DescriptionSpecialization for placeablesFunctions
- getConditionInfos
- onDelete
- onFinalizePlacement
- onHusbandryAnimalsUpdate
- onLoad
- onMilkingRobotLoaded
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- registerXMLPaths
- updateInfo
- updateOutput
- updateProduction
getConditionInfos
DescriptionDefinitiongetConditionInfos()Code
194 | function PlaceableHusbandryMilk:getConditionInfos(superFunc) |
195 | local spec = self.spec_husbandryMilk |
196 | local infos = superFunc(self) |
197 | |
198 | local info = {} |
199 | local fillType = g_fillTypeManager:getFillTypeByIndex(spec.fillType) |
200 | info.title = fillType.title |
201 | info.value = self:getHusbandryFillLevel(spec.fillType) |
202 | local capacity = self:getHusbandryCapacity(spec.fillType) |
203 | local ratio = 0 |
204 | if capacity > 0 then |
205 | ratio = info.value / capacity |
206 | end |
207 | info.ratio = MathUtil.clamp(ratio, 0, 1) |
208 | info.invertedBar = true |
209 | |
210 | table.insert(infos, info) |
211 | |
212 | return infos |
213 | end |
onDelete
DescriptionDefinitiononDelete()Code
112 | function PlaceableHusbandryMilk:onDelete() |
113 | local spec = self.spec_husbandryMilk |
114 | if spec.milkingRobots ~= nil then |
115 | for _, robot in ipairs(spec.milkingRobots) do |
116 | robot:delete() |
117 | end |
118 | spec.milkingRobots = {} |
119 | end |
120 | end |
onFinalizePlacement
DescriptionDefinitiononFinalizePlacement()Code
124 | function PlaceableHusbandryMilk:onFinalizePlacement() |
125 | local spec = self.spec_husbandryMilk |
126 | if not self:getHusbandryIsFillTypeSupported(spec.fillType) then |
127 | Logging.warning("Missing filltype 'milk' in husbandry storage!") |
128 | end |
129 | |
130 | for _, robot in ipairs(spec.milkingRobots) do |
131 | robot:finalizePlacement() |
132 | end |
133 | end |
onHusbandryAnimalsUpdate
DescriptionDefinitiononHusbandryAnimalsUpdate()Code
163 | function PlaceableHusbandryMilk:onHusbandryAnimalsUpdate(clusters) |
164 | local spec = self.spec_husbandryMilk |
165 | spec.litersPerHour = 0 |
166 | for _, cluster in ipairs(clusters) do |
167 | local subType = g_currentMission.animalSystem:getSubTypeByIndex(cluster.subTypeIndex) |
168 | if subType ~= nil then |
169 | local milk = subType.output.milk |
170 | if milk ~= nil then |
171 | local age = cluster:getAge() |
172 | local litersPerAnimals = milk:get(age) |
173 | local litersPerDay = litersPerAnimals * cluster:getNumAnimals() |
174 | |
175 | spec.litersPerHour = spec.litersPerHour + (litersPerDay / 24) |
176 | end |
177 | end |
178 | end |
179 | end |
onLoad
DescriptionDefinitiononLoad()Code
63 | function PlaceableHusbandryMilk:onLoad(savegame) |
64 | local spec = self.spec_husbandryMilk |
65 | |
66 | spec.litersPerHour = 0 |
67 | spec.fillType = FillType.MILK |
68 | spec.info = {title=g_i18n:getText("fillType_milk"), text=""} |
69 | spec.milkingRobots = {} |
70 | spec.husbandry = nil |
71 | |
72 | self.xmlFile:iterate("placeable.husbandry.milk.milkingRobots.milkingRobot", function(_, key) |
73 | local filename = Utils.getFilename(self.xmlFile:getValue(key .. "#filename", nil), self.baseDirectory) |
74 | if filename == nil then |
75 | Logging.xmlWarning(self.xmlFile, "Milkingrobot filename missing for '%s'", key) |
76 | return |
77 | end |
78 | |
79 | local className = self.xmlFile:getValue(key .. "#class", "") |
80 | local class = ClassUtil.getClassObject(className) |
81 | if class == nil then |
82 | Logging.xmlWarning(self.xmlFile, "Milkingrobot class '%s' not defined for '%s'", className, key) |
83 | return |
84 | end |
85 | |
86 | local linkNode = self.xmlFile:getValue(key .. "#linkNode", nil, self.components, self.i3dMappings) |
87 | if linkNode == nil then |
88 | Logging.xmlWarning(self.xmlFile, "Milkingrobot linkNode not defined for '%s'", key) |
89 | return |
90 | end |
91 | |
92 | local args = {} |
93 | args.loadingTask = self:createLoadingTask(self) |
94 | local robot = class.new(self, self.baseDirectory) |
95 | if robot:load(linkNode, filename, self.onMilkingRobotLoaded, self, args) then |
96 | table.insert(spec.milkingRobots, robot) |
97 | else |
98 | self:finishLoadingTask(args.loadingTask) |
99 | robot:delete() |
100 | end |
101 | end) |
102 | end |
onMilkingRobotLoaded
DescriptionDefinitiononMilkingRobotLoaded()Code
106 | function PlaceableHusbandryMilk:onMilkingRobotLoaded(robot, args) |
107 | self:finishLoadingTask(args.loadingTask) |
108 | 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 |
22 | function PlaceableHusbandryMilk.prerequisitesPresent(specializations) |
23 | return SpecializationUtil.hasSpecialization(PlaceableHusbandry, specializations) |
24 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
43 | function PlaceableHusbandryMilk.registerEventListeners(placeableType) |
44 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableHusbandryMilk) |
45 | SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableHusbandryMilk) |
46 | SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableHusbandryMilk) |
47 | SpecializationUtil.registerEventListener(placeableType, "onHusbandryAnimalsUpdate", PlaceableHusbandryMilk) |
48 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
28 | function PlaceableHusbandryMilk.registerFunctions(placeableType) |
29 | SpecializationUtil.registerFunction(placeableType, "onMilkingRobotLoaded", PlaceableHusbandryMilk.onMilkingRobotLoaded) |
30 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
34 | function PlaceableHusbandryMilk.registerOverwrittenFunctions(placeableType) |
35 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateOutput", PlaceableHusbandryMilk.updateOutput) |
36 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateProduction", PlaceableHusbandryMilk.updateProduction) |
37 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableHusbandryMilk.updateInfo) |
38 | SpecializationUtil.registerOverwrittenFunction(placeableType, "getConditionInfos", PlaceableHusbandryMilk.getConditionInfos) |
39 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
52 | function PlaceableHusbandryMilk.registerXMLPaths(schema, basePath) |
53 | schema:setXMLSpecializationType("Husbandry") |
54 | basePath = basePath .. ".husbandry.milk" |
55 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".milkingRobots.milkingRobot(?)#linkNode", "Milkingrobot link node") |
56 | schema:register(XMLValueType.STRING, basePath .. ".milkingRobots.milkingRobot(?)#class", "Milkingrobot class name") |
57 | schema:register(XMLValueType.STRING, basePath .. ".milkingRobots.milkingRobot(?)#filename", "Milkingrobot config file") |
58 | schema:setXMLSpecializationType() |
59 | end |
updateInfo
DescriptionDefinitionupdateInfo()Code
183 | function PlaceableHusbandryMilk:updateInfo(superFunc, infoTable) |
184 | local spec = self.spec_husbandryMilk |
185 | superFunc(self, infoTable) |
186 | |
187 | local fillLevel = self:getHusbandryFillLevel(spec.fillType) |
188 | spec.info.text = string.format("%d l", fillLevel) |
189 | table.insert(infoTable, spec.info) |
190 | end |
updateOutput
DescriptionDefinitionupdateOutput()Code
137 | function PlaceableHusbandryMilk:updateOutput(superFunc, foodFactor, productionFactor, globalProductionFactor) |
138 | local spec = self.spec_husbandryMilk |
139 | if self.isServer and spec.litersPerHour > 0 then |
140 | local liters = productionFactor * globalProductionFactor * spec.litersPerHour * g_currentMission.environment.timeAdjustment |
141 | self:addHusbandryFillLevelFromTool(self:getOwnerFarmId(), liters, spec.fillType, nil, nil, nil) |
142 | end |
143 | |
144 | superFunc(self, foodFactor, productionFactor, globalProductionFactor) |
145 | end |
updateProduction
DescriptionDefinitionupdateProduction()Code
149 | function PlaceableHusbandryMilk:updateProduction(superFunc, foodFactor) |
150 | local spec = self.spec_husbandryMilk |
151 | local factor = superFunc(self, foodFactor) |
152 | |
153 | local freeCapacity = self:getHusbandryFreeCapacity(spec.fillType) |
154 | if freeCapacity <= 0 then |
155 | factor = 0 |
156 | end |
157 | |
158 | return factor |
159 | end |