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
HusbandryModuleFoodSpillage
DescriptionThis class handles water in husbandryParent
HusbandryModuleBaseFunctions
- delete
- getFoodSpillageLevel
- getSpillageFactor
- initDataStructures
- load
- loadFromXMLFile
- new
- onIntervalUpdate
- readStream
- readUpdateStream
- updateFoodSpillage
- writeStream
- writeUpdateStream
delete
DescriptionDeletes instanceDefinition
delete()Code
28 | function HusbandryModuleFoodSpillage:delete() |
29 | end |
getFoodSpillageLevel
DescriptionGet spillage levelDefinition
getFoodSpillageLevel()Return Values
float | spillage | total |
234 | function HusbandryModuleFoodSpillage:getFoodSpillageLevel() |
235 | local totalLevel = 0 |
236 | for _, spillageArea in ipairs(self.spillageAreas) do |
237 | local xs,_,zs = getWorldTranslation(spillageArea.start) |
238 | local xw,_,zw = getWorldTranslation(spillageArea.width) |
239 | local xh,_,zh = getWorldTranslation(spillageArea.height) |
240 | local fillLevel = DensityMapHeightUtil.getFillLevelAtArea(self.spillageFillType, xs, zs, xw, zw, xh, zh) |
241 | totalLevel = totalLevel + fillLevel |
242 | end |
243 | return totalLevel |
244 | end |
getSpillageFactor
DescriptionDefinitiongetSpillageFactor()Code
249 | function HusbandryModuleFoodSpillage:getSpillageFactor() |
250 | if self.hasCleanliness then |
251 | return self.cleanlinessFactor |
252 | end |
253 | |
254 | return nil |
255 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
33 | function HusbandryModuleFoodSpillage:initDataStructures() |
34 | HusbandryModuleFoodSpillage:superClass().initDataStructures(self) |
35 | |
36 | self.spillageAreas = {} |
37 | self.foodToDrop = 0 |
38 | self.spillageFillType = FillType.UNKNOWN |
39 | self.lineOffset = 0 |
40 | self.cleanlinessFactor = 0.0 |
41 | self.hasCleanliness = false |
42 | 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 |
50 | function HusbandryModuleFoodSpillage:load(xmlFile, configKey, rootNode, owner, baseDirectory) |
51 | if not HusbandryModuleFoodSpillage:superClass().load(self, xmlFile, configKey, rootNode, owner, baseDirectory) then |
52 | return false |
53 | end |
54 | |
55 | if not hasXMLProperty(xmlFile, configKey) then |
56 | return false |
57 | end |
58 | |
59 | local i = 0 |
60 | while true do |
61 | local areaKey = string.format("%s.area(%d)", configKey, i) |
62 | if not hasXMLProperty(xmlFile, areaKey) then |
63 | break |
64 | end |
65 | local start = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, areaKey .. "#startNode")) |
66 | local width = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, areaKey .. "#widthNode")) |
67 | local height = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, areaKey .. "#heightNode")) |
68 | |
69 | if start ~= nil and width ~= nil and height ~= nil then |
70 | table.insert(self.spillageAreas, {start = start, width = width, height = height}) |
71 | end |
72 | i = i + 1 |
73 | end |
74 | |
75 | local spillageFillType = getXMLString(xmlFile, configKey .. "#fillType") |
76 | if spillageFillType ~= nil then |
77 | local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(spillageFillType) |
78 | if fillTypeIndex ~= nil then |
79 | self.spillageFillType = fillTypeIndex |
80 | end |
81 | end |
82 | |
83 | self.hasCleanliness = true |
84 | |
85 | return self.spillageFillType ~= nil and #self.spillageAreas > 0 |
86 | 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 |
182 | function HusbandryModuleFoodSpillage:loadFromXMLFile(xmlFile, key) |
183 | HusbandryModuleFoodSpillage:superClass().loadFromXMLFile(self, xmlFile, key) |
184 | |
185 | if self.hasCleanliness then |
186 | self.cleanlinessFactor = Utils.getNoNil(getXMLFloat(xmlFile, key.."#cleanlinessFactor"), self.cleanlinessFactor) |
187 | self.foodToDrop = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foodToDrop"), self.foodToDrop) |
188 | end |
189 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
21 | function HusbandryModuleFoodSpillage:new(customMt) |
22 | local self = HusbandryModuleBase:new(customMt or HusbandryModuleFoodSpillage_mt) |
23 | return self |
24 | end |
onIntervalUpdate
DescriptionUpdate water usageDefinition
onIntervalUpdate(float dayToInterval)Arguments
float | dayToInterval |
144 | function HusbandryModuleFoodSpillage:onIntervalUpdate(dayToInterval) |
145 | HusbandryModuleFoodSpillage:superClass().onIntervalUpdate(self, dayToInterval) |
146 | self:updateCleanlinessFactor(dayToInterval) |
147 | end |
readStream
DescriptionReads network streamDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | network stream identification |
table | connection | connection information |
93 | function HusbandryModuleFoodSpillage:readStream(streamId, connection) |
94 | HusbandryModuleFoodSpillage:superClass().readStream(self, streamId, connection) |
95 | |
96 | if self.hasCleanliness then |
97 | self.cleanlinessFactor = streamReadUInt8(streamId) / 255 |
98 | end |
99 | end |
readUpdateStream
DescriptionRead updates from network streamDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | network stream identification |
integer | timestamp | |
table | connection | connection information |
119 | function HusbandryModuleFoodSpillage:readUpdateStream(streamId, timestamp, connection) |
120 | HusbandryModuleFoodSpillage:superClass().readUpdateStream(self, streamId, timestamp, connection) |
121 | |
122 | if self.hasCleanliness then |
123 | self.cleanlinessFactor = streamReadUInt8(streamId) / 255 |
124 | end |
125 | end |
updateFoodSpillage
DescriptionUpdate spillage mechanics.Definition
updateFoodSpillage(float spillageDelta)Arguments
float | spillageDelta | amount of food to increase |
float | food | dropped |
204 | function HusbandryModuleFoodSpillage:updateFoodSpillage(spillageDelta) |
205 | local foodDropped = 0 |
206 | |
207 | if self.hasCleanliness and self.cleanlinessFactor > 0 and spillageDelta > g_densityMapHeightManager:getMinValidLiterValue(self.spillageFillType) then |
208 | local i = math.random(1, #self.spillageAreas) |
209 | local spillageArea = self.spillageAreas[i] |
210 | local xs,_,zs = getWorldTranslation(spillageArea.start) |
211 | local xw,_,zw = getWorldTranslation(spillageArea.width) |
212 | local xh,_,zh = getWorldTranslation(spillageArea.height) |
213 | local ux, uz = xw - xs, zw - zs |
214 | local vx, vz = xh - xs, zh - zs |
215 | local vLength = MathUtil.vector2Length(vx,vz) |
216 | local sx = xs + (math.random() * ux) + (math.random() * vx) |
217 | local sz = zs + (math.random() * uz) + (math.random() * vz) |
218 | local ex = xs + (math.random() * ux) + (math.random() * vx) |
219 | local ez = zs + (math.random() * uz) + (math.random() * vz) |
220 | local sy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, sx, 0.0, sz) |
221 | local ey = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, ex, 0.0, ez) |
222 | local dropped, lineOffset = DensityMapHeightUtil.tipToGroundAroundLine(nil, spillageDelta, self.spillageFillType, sx,sy,sz, ex,ey,ez, 0, vLength, self.lineOffset, false, nil) |
223 | |
224 | foodDropped = dropped |
225 | self.lineOffset = lineOffset |
226 | end |
227 | |
228 | return foodDropped |
229 | end |
writeStream
DescriptionWrites network streamDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | network stream identification |
table | connection | connection information |
105 | function HusbandryModuleFoodSpillage:writeStream(streamId, connection) |
106 | HusbandryModuleFoodSpillage:superClass().writeStream(self, streamId, connection) |
107 | |
108 | if self.hasCleanliness then |
109 | local cleanliness = math.floor(self.cleanlinessFactor * 255 + 0.5) |
110 | streamWriteUInt8(streamId, cleanliness) |
111 | end |
112 | end |
writeUpdateStream
DescriptionWrite updates from network streamDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | network stream identification |
table | connection | connection information |
integer | dirtyMask | is used to check if we need to update |
132 | function HusbandryModuleFoodSpillage:writeUpdateStream(streamId, connection, dirtyMask) |
133 | HusbandryModuleFoodSpillage:superClass().writeUpdateStream(self, streamId, connection, dirtyMask) |
134 | |
135 | if self.hasCleanliness then |
136 | local cleanliness = math.floor(self.cleanlinessFactor * 255 + 0.5) |
137 | streamWriteUInt8(streamId, cleanliness) |
138 | end |
139 | end |