Script v1.7.1.0
- AI
- Animals
- AnimalFoodManager
- AnimalHusbandryNoMorePall...
- AnimalManager
- AnimalNameManager
- CrowsWildlife
- Dog
- Horse
- HusbandryModuleBase
- HusbandryModuleFood
- HusbandryModuleFoodSpilla...
- HusbandryModuleLiquidManu...
- HusbandryModuleManure
- HusbandryModuleMilk
- HusbandryModulePallets
- HusbandryModuleStraw
- LightWildlife
- RideableAnimal
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
HusbandryModuleManure
DescriptionThis class handles water in husbandryParent
HusbandryModuleBaseXML Configuration Parameters
placeable.husbandry.manureHeapArea#index | manure heap node index |
Functions
- delete
- getFilltypeInfos
- getManureLevel
- initDataStructures
- load
- loadFromXMLFile
- new
- onIntervalUpdate
- removeManure
- updateManure
delete
DescriptionDeletes instanceDefinition
delete()Code
32 | function HusbandryModuleManure:delete() |
33 | -- unregistration in mission |
34 | g_currentMission:removeManureHeap(self) |
35 | |
36 | g_densityMapHeightManager:removeFixedFillTypesArea(self.manureArea) |
37 | end |
getFilltypeInfos
DescriptionDefinitiongetFilltypeInfos()Code
240 | function HusbandryModuleManure:getFilltypeInfos() |
241 | local result = {} |
242 | local fillType = g_fillTypeManager:getFillTypeByIndex(self.fillTypeIndex) |
243 | local capacity = self:getCapacity() |
244 | local fillLevel = self:getFillLevel(self.fillTypeIndex) |
245 | |
246 | table.insert(result, {fillType=fillType, fillLevel=fillLevel, capacity=capacity}) |
247 | return result |
248 | end |
getManureLevel
DescriptionGet manure level from manure areaDefinition
getManureLevel()Return Values
float | manure | fill level |
189 | function HusbandryModuleManure:getManureLevel() |
190 | local xs, _, zs = getWorldTranslation(self.manureArea.start) |
191 | local xw, _, zw = getWorldTranslation(self.manureArea.width) |
192 | local xh, _, zh = getWorldTranslation(self.manureArea.height) |
193 | local fillLevel = DensityMapHeightUtil.getFillLevelAtArea(self.fillTypeIndex, xs, zs, xw, zw, xh, zh) |
194 | |
195 | return fillLevel |
196 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
41 | function HusbandryModuleManure:initDataStructures() |
42 | HusbandryModuleManure:superClass().initDataStructures(self) |
43 | |
44 | self.manureArea = nil |
45 | self.splittedManureAreas = nil |
46 | self.fillTypeIndex = 0 |
47 | self.manureToDrop = 0 |
48 | self.manureToRemove = 0 |
49 | self.lineOffsetManure = 0 |
50 | self.manureHeapName = "" |
51 | end |
load
DescriptionLoads data from xmlDefinition
load(table xmlFile, string xmlKey, table rootNode)Arguments
table | xmlFile | handle |
string | xmlKey | from which to read the configuration |
table | rootNode | of the husbandry |
boolean | true | if loading was successful else false |
59 | function HusbandryModuleManure:load(xmlFile, configKey, rootNode, owner, baseDirectory) |
60 | local result = HusbandryModuleManure:superClass().load(self, xmlFile, configKey, rootNode, owner, baseDirectory) |
61 | |
62 | if result ~= true then |
63 | return false |
64 | end |
65 | if not hasXMLProperty(xmlFile, configKey) then |
66 | return false |
67 | end |
68 | |
69 | local manureAreaNodeStart = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#startNode")) |
70 | local manureAreaNodeWidth = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#widthNode")) |
71 | local manureAreaNodeHeight = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#heightNode")) |
72 | |
73 | local fillType = getXMLString(xmlFile, configKey .. "#fillType") |
74 | if manureAreaNodeStart ~= nil and manureAreaNodeWidth ~= nil and manureAreaNodeHeight ~= nil and fillType ~= nil then |
75 | self.fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillType) |
76 | self.manureArea = {start=manureAreaNodeStart, width=manureAreaNodeWidth, height=manureAreaNodeHeight} |
77 | |
78 | self.splittedManureAreas = DensityMapHeightUtil.getAreaPartitions(manureAreaNodeStart, manureAreaNodeWidth, manureAreaNodeHeight) |
79 | |
80 | local fillTypes = {} |
81 | fillTypes[self.fillTypeIndex] = true |
82 | g_densityMapHeightManager:setFixedFillTypesArea(self.manureArea, fillTypes) |
83 | |
84 | self.fillLevels[self.fillTypeIndex] = self:getManureLevel() |
85 | else |
86 | result = false |
87 | end |
88 | |
89 | return result |
90 | end |
loadFromXMLFile
DescriptionLoads information from attributes and node. Retrives from xml file information.Definition
loadFromXMLFile(table xmlFile, string key)Arguments
table | xmlFile | XML file handler |
string | key | XML base key |
149 | function HusbandryModuleManure:loadFromXMLFile(xmlFile, key) |
150 | HusbandryModuleManure:superClass().loadFromXMLFile(self, xmlFile, key) |
151 | |
152 | self.manureToDrop = Utils.getNoNil(getXMLFloat(xmlFile, key.."#manureToDrop"), self.manureToDrop) |
153 | self.manureToRemove = Utils.getNoNil(getXMLFloat(xmlFile, key.."#manureToRemove"), self.manureToRemove) |
154 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
22 | function HusbandryModuleManure:new(customMt) |
23 | if customMt == nil then |
24 | customMt = HusbandryModuleManure_mt |
25 | end |
26 | local self = HusbandryModuleBase:new(customMt) |
27 | return self |
28 | end |
onIntervalUpdate
DescriptionUpdate water usageDefinition
onIntervalUpdate(float dayToInterval)Arguments
float | dayToInterval |
112 | function HusbandryModuleManure:onIntervalUpdate(dayToInterval) |
113 | HusbandryModuleManure:superClass().onIntervalUpdate(self, dayToInterval) |
114 | |
115 | if self.singleAnimalUsagePerDay > 0 then |
116 | local hasStraw = self.owner:hasStraw() |
117 | |
118 | if hasStraw then |
119 | local minValidLiterValue = g_densityMapHeightManager:getMinValidLiterValue(self.fillTypeIndex) |
120 | |
121 | local fillLevel = self:getFillLevel(self.fillTypeIndex) |
122 | if (fillLevel + self.manureToDrop > self:getCapacity()) then |
123 | -- cap to capacity |
124 | self.manureToDrop = math.max(self:getCapacity() - fillLevel, minValidLiterValue) |
125 | end |
126 | |
127 | if self.manureToDrop >= minValidLiterValue then |
128 | local maxManureToDrop = math.min(self.manureToDrop, 200.0 * minValidLiterValue) |
129 | local dropped = self:updateManure(maxManureToDrop) |
130 | |
131 | self.manureToDrop = self.manureToDrop - dropped |
132 | end |
133 | |
134 | local totalNumAnimals = self.owner:getNumOfAnimals() |
135 | local newManure = totalNumAnimals * self.singleAnimalUsagePerDay * dayToInterval |
136 | |
137 | self.manureToDrop = self.manureToDrop + newManure |
138 | |
139 | local manureLevel = self:getManureLevel() |
140 | self:setFillLevel(self.fillTypeIndex, manureLevel + self.manureToDrop) |
141 | end |
142 | end |
143 | end |
removeManure
DescriptionRemove amount of manure; called by Sprayer specializationDefinition
removeManure(float delta)Arguments
float | delta | amount to remove |
float | manure | used |
202 | function HusbandryModuleManure:removeManure(delta) |
203 | local used = 0 |
204 | |
205 | if self.manureToDrop >= delta then |
206 | self.manureToDrop = self.manureToDrop - delta |
207 | used = delta |
208 | else |
209 | self.manureToDrop = self.manureToDrop - delta |
210 | delta = math.abs(self.manureToDrop) |
211 | self.manureToDrop = 0 |
212 | self.manureToRemove = self.manureToRemove + delta |
213 | |
214 | local manureLevel = self:getManureLevel() |
215 | self:setFillLevel(self.fillTypeIndex, manureLevel + self.manureToDrop) |
216 | |
217 | if self.manureToRemove < manureLevel then |
218 | used = delta |
219 | if self.manureToRemove > g_densityMapHeightManager:getMinValidLiterValue(self.fillTypeIndex) then |
220 | for _, area in ipairs(self.splittedManureAreas) do |
221 | local lsx, lsy, lsz, lex, ley, lez, radius = DensityMapHeightUtil.getLineByArea(area.start, area.width, area.height, true) |
222 | |
223 | local dropped, lineOffset = DensityMapHeightUtil.tipToGroundAroundLine(nil, -self.manureToRemove, self.fillTypeIndex, lsx, lsy, lsz, lex, ley, lez, radius, radius, area.lineOffset, false, nil) |
224 | area.lineOffset = lineOffset |
225 | |
226 | self.manureToRemove = math.max(self.manureToRemove + dropped, 0) |
227 | if self.manureToRemove <= 0 then |
228 | break |
229 | end |
230 | end |
231 | end |
232 | end |
233 | end |
234 | |
235 | return used |
236 | end |
updateManure
DescriptionUpdate manure mechanicsDefinition
updateManure(float manureIncrease)Arguments
float | manureIncrease |
float | manure | dropped |
167 | function HusbandryModuleManure:updateManure(manureIncrease) |
168 | local manureDropped = 0 |
169 | |
170 | if manureIncrease > g_densityMapHeightManager:getMinValidLiterValue(self.fillTypeIndex) then |
171 | for _, area in ipairs(self.splittedManureAreas) do |
172 | local lsx, lsy, lsz, lex, ley, lez, radius = DensityMapHeightUtil.getLineByArea(area.start, area.width, area.height, false) |
173 | local dropped, lineOffset = DensityMapHeightUtil.tipToGroundAroundLine(nil, manureIncrease, self.fillTypeIndex, lsx, lsy, lsz, lex, ley, lez, radius, radius, area.lineOffset, false, nil) |
174 | area.lineOffset = lineOffset |
175 | manureDropped = manureDropped + dropped |
176 | manureIncrease = manureIncrease - dropped |
177 | if manureIncrease <= 0 then |
178 | break |
179 | end |
180 | end |
181 | end |
182 | |
183 | return manureDropped |
184 | end |