LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableHusbandryLiquidManure

Description
Specialization for placeables
Functions

getConditionInfos

Description
Definition
getConditionInfos()
Code
122function PlaceableHusbandryLiquidManure:getConditionInfos(superFunc)
123 local infos = superFunc(self)
124 local spec = self.spec_husbandryLiquidManure
125
126 local info = {}
127 local fillType = g_fillTypeManager:getFillTypeByIndex(spec.fillType)
128 info.title = fillType.title
129 info.value = self:getHusbandryFillLevel(spec.fillType)
130 local capacity = self:getHusbandryCapacity(spec.fillType)
131 local ratio = 0
132 if capacity > 0 then
133 ratio = info.value / capacity
134 end
135 info.ratio = MathUtil.clamp(ratio, 0, 1)
136 info.invertedBar = true
137
138 table.insert(infos, info)
139
140 return infos
141end

onFinalizePlacement

Description
Definition
onFinalizePlacement()
Code
61function PlaceableHusbandryLiquidManure:onFinalizePlacement()
62 local spec = self.spec_husbandryLiquidManure
63 if not self:getHusbandryIsFillTypeSupported(spec.fillType) then
64 Logging.warning("Missing filltype 'liquidManure' in husbandry storage!")
65 end
66end

onHusbandryAnimalsUpdate

Description
Definition
onHusbandryAnimalsUpdate()
Code
101function PlaceableHusbandryLiquidManure:onHusbandryAnimalsUpdate(clusters)
102 local spec = self.spec_husbandryLiquidManure
103
104 spec.litersPerHour = 0
105 for _, cluster in ipairs(clusters) do
106 local subType = g_currentMission.animalSystem:getSubTypeByIndex(cluster.subTypeIndex)
107 if subType ~= nil then
108 local liquidManure = subType.output.liquidManure
109 if liquidManure ~= nil then
110 local age = cluster:getAge()
111 local litersPerAnimal = liquidManure:get(age)
112 local litersPerDay = litersPerAnimal * cluster:getNumAnimals()
113
114 spec.litersPerHour = spec.litersPerHour + (litersPerDay / 24)
115 end
116 end
117 end
118end

onLoad

Description
Definition
onLoad()
Code
51function PlaceableHusbandryLiquidManure:onLoad(savegame)
52 local spec = self.spec_husbandryLiquidManure
53
54 spec.litersPerHour = 0
55 spec.fillType = FillType.LIQUIDMANURE
56 spec.info = {title=g_i18n:getText("fillType_liquidManure"), text=""}
57end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
18function PlaceableHusbandryLiquidManure.prerequisitesPresent(specializations)
19 return true
20end

registerEventListeners

Description
Definition
registerEventListeners()
Code
33function PlaceableHusbandryLiquidManure.registerEventListeners(placeableType)
34 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableHusbandryLiquidManure)
35 SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableHusbandryLiquidManure)
36 SpecializationUtil.registerEventListener(placeableType, "onHusbandryAnimalsUpdate", PlaceableHusbandryLiquidManure)
37end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
24function PlaceableHusbandryLiquidManure.registerOverwrittenFunctions(placeableType)
25 SpecializationUtil.registerOverwrittenFunction(placeableType, "updateOutput", PlaceableHusbandryLiquidManure.updateOutput)
26 SpecializationUtil.registerOverwrittenFunction(placeableType, "updateProduction", PlaceableHusbandryLiquidManure.updateProduction)
27 SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableHusbandryLiquidManure.updateInfo)
28 SpecializationUtil.registerOverwrittenFunction(placeableType, "getConditionInfos", PlaceableHusbandryLiquidManure.getConditionInfos)
29end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
41function PlaceableHusbandryLiquidManure.registerXMLPaths(schema, basePath)
42 schema:setXMLSpecializationType("Husbandry")
43 basePath = basePath .. ".husbandry.liquidManure"
44 schema:register(XMLValueType.FLOAT, basePath .. ".manure#factor", "Factor to transform straw to manure", 1)
45 schema:register(XMLValueType.BOOL, basePath .. ".manure#active", "Enable manure production", true)
46 schema:setXMLSpecializationType()
47end

updateInfo

Description
Definition
updateInfo()
Code
145function PlaceableHusbandryLiquidManure:updateInfo(superFunc, infoTable)
146 superFunc(self, infoTable)
147 local spec = self.spec_husbandryLiquidManure
148
149 local fillLevel = self:getHusbandryFillLevel(spec.fillType)
150 spec.info.text = string.format("%d l", fillLevel)
151 table.insert(infoTable, spec.info)
152end

updateOutput

Description
Definition
updateOutput()
Code
70function PlaceableHusbandryLiquidManure:updateOutput(superFunc, foodFactor, productionFactor, globalProductionFactor)
71 if self.isServer then
72 local spec = self.spec_husbandryLiquidManure
73
74 if spec.litersPerHour > 0 then
75 local liters = foodFactor * spec.litersPerHour * g_currentMission.environment.timeAdjustment
76 self:addHusbandryFillLevelFromTool(self:getOwnerFarmId(), liters, spec.fillType, nil, nil, nil)
77 end
78 end
79
80 superFunc(self, foodFactor, productionFactor, globalProductionFactor)
81end

updateProduction

Description
Definition
updateProduction()
Code
85function PlaceableHusbandryLiquidManure:updateProduction(superFunc, foodFactor)
86 local factor = superFunc(self, foodFactor)
87
88 if self.isServer then
89 local spec = self.spec_husbandryLiquidManure
90 local freeCapacity = self:getHusbandryFreeCapacity(spec.fillType)
91 if freeCapacity <= 0 then
92 factor = factor * 0.75
93 end
94 end
95
96 return factor
97end