Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- AnimalHusbandry
- BeehivePlaceable
- BgaPlaceable
- BunkerSiloPlaceable
- BuyingStationPlaceable
- Doghouse
- FarmhousePlaceable
- GreenhousePlaceable
- HeatingPlantPlaceable
- HusbandryModuleWater
- Placeable
- SellingStationPlaceable
- SiloExtensionPlaceable
- SiloPlaceable
- SolarCollectorPlaceable
- WindTurbinePlaceable
- WoodSellStationPlaceable
- 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
HusbandryModuleWater
DescriptionThis class handles water in husbandryParent
HusbandryModuleBaseFunctions
- addFillLevelFromTool
- delete
- getFilltypeInfos
- hasWater
- initDataStructures
- load
- loadFromXMLFile
- new
- onIntervalUpdate
- readStream
- writeStream
addFillLevelFromTool
DescriptionDefinitionaddFillLevelFromTool()Code
146 | function HusbandryModuleWater:addFillLevelFromTool(farmId, deltaFillLevel, fillType) |
147 | local changed = HusbandryModuleWater:superClass().addFillLevelFromTool(self, farmId, deltaFillLevel, fillType) |
148 | |
149 | if deltaFillLevel > 0 and changed ~= 0 then |
150 | self.owner:updateGlobalProductionFactor() |
151 | end |
152 | |
153 | if changed > 0 and self.unloadPlace ~= nil then |
154 | if self.unloadPlace:getIsFillTypeSupported(fillType) then |
155 | self.unloadPlace:raiseActive() |
156 | self:updateFillPlane() |
157 | end |
158 | end |
159 | |
160 | return changed |
161 | end |
delete
DescriptionDeletes instanceDefinition
delete()Code
27 | function HusbandryModuleWater:delete() |
28 | if self.unloadPlace ~= nil then |
29 | self.unloadPlace:delete() |
30 | self.unloadPlace = nil |
31 | end |
32 | if self.fillPlane ~= nil then |
33 | self.fillPlane:delete() |
34 | self.fillPlane = nil |
35 | end |
36 | end |
getFilltypeInfos
DescriptionDefinitiongetFilltypeInfos()Code
176 | function HusbandryModuleWater:getFilltypeInfos() |
177 | local result = {} |
178 | |
179 | for filltypeIndex, val in pairs(self.fillLevels) do |
180 | local fillType = g_fillTypeManager:getFillTypeByIndex(filltypeIndex) |
181 | local capacity = self.unloadPlace.target:getCapacity() |
182 | local fillLevel = self.unloadPlace.target:getFillLevel(filltypeIndex) |
183 | |
184 | table.insert(result, {fillType=fillType, fillLevel=fillLevel, capacity=capacity}) |
185 | end |
186 | return result |
187 | end |
hasWater
DescriptionGet a water multiplierDefinition
hasWater(float between)Arguments
float | between | 0 and 1 |
166 | function HusbandryModuleWater:hasWater() |
167 | local totalWater = 0.0 |
168 | for _, fillLevel in pairs(self.fillLevels) do |
169 | totalWater = totalWater + fillLevel |
170 | end |
171 | return totalWater > 0.0 |
172 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
40 | function HusbandryModuleWater:initDataStructures() |
41 | HusbandryModuleWater:superClass().initDataStructures(self) |
42 | self.unloadPlace = nil |
43 | 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 |
51 | function HusbandryModuleWater:load(xmlFile, configKey, rootNode, owner, baseDirectory) |
52 | if not HusbandryModuleWater:superClass().load(self, xmlFile, configKey, rootNode, owner, baseDirectory) then |
53 | return false |
54 | end |
55 | |
56 | if not hasXMLProperty(xmlFile, configKey) then |
57 | return false |
58 | end |
59 | |
60 | local waterNodeId = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#node")) |
61 | if waterNodeId ~= nil then |
62 | local unloadPlace = UnloadTrigger:new(self.owner.isServer, self.owner.isClient) |
63 | if unloadPlace:load(waterNodeId, xmlFile, configKey, self) then |
64 | unloadPlace:register(true) |
65 | |
66 | self.unloadPlace = unloadPlace |
67 | self.fillPlane = FillPlane:new() |
68 | self.fillPlane:load(rootNode, xmlFile, configKey..".fillPlane") |
69 | |
70 | for fillTypeIndex, state in pairs(unloadPlace.fillTypes) do |
71 | self.fillLevels[fillTypeIndex] = 0.0 |
72 | self.providedFillTypes[fillTypeIndex] = state |
73 | end |
74 | self:setCapacity(0.0) |
75 | |
76 | return true |
77 | else |
78 | unloadPlace:delete() |
79 | return false |
80 | end |
81 | end |
82 | |
83 | return false |
84 | 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 |
90 | function HusbandryModuleWater:loadFromXMLFile(xmlFile, key) |
91 | HusbandryModuleWater:superClass().loadFromXMLFile(self, xmlFile, key) |
92 | self:updateFillPlane() |
93 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
21 | function HusbandryModuleWater:new(customMt) |
22 | return HusbandryModuleBase:new(customMt or HusbandryModuleWater_mt) |
23 | end |
onIntervalUpdate
DescriptionUpdate water usageDefinition
onIntervalUpdate(float dayToInterval)Arguments
float | dayToInterval |
126 | function HusbandryModuleWater:onIntervalUpdate(dayToInterval) |
127 | HusbandryModuleWater:superClass().onIntervalUpdate(self, dayToInterval) |
128 | |
129 | if self.singleAnimalUsagePerDay > 0.0 then |
130 | local totalNumAnimals = self.owner:getNumOfAnimals() |
131 | local waterNeeded = totalNumAnimals * self.singleAnimalUsagePerDay * dayToInterval |
132 | |
133 | if waterNeeded > 0.0 then |
134 | for fillTypeIndex, fillLevel in pairs(self.fillLevels) do |
135 | if fillLevel > 0.0 then |
136 | self:changeFillLevels(-math.min(waterNeeded, fillLevel), fillTypeIndex) |
137 | self:updateFillPlane() |
138 | end |
139 | end |
140 | end |
141 | end |
142 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
99 | function HusbandryModuleWater:readStream(streamId, connection) |
100 | HusbandryModuleWater:superClass().readStream(self, streamId, connection) |
101 | |
102 | if self.unloadPlace ~= nil then |
103 | local unloadPlaceId = NetworkUtil.readNodeObjectId(streamId) |
104 | self.unloadPlace:readStream(streamId, connection) |
105 | g_client:finishRegisterObject(self.unloadPlace, unloadPlaceId) |
106 | end |
107 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
113 | function HusbandryModuleWater:writeStream(streamId, connection) |
114 | HusbandryModuleWater:superClass().writeStream(self, streamId, connection) |
115 | |
116 | if self.unloadPlace ~= nil then |
117 | NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.unloadPlace)) |
118 | self.unloadPlace:writeStream(streamId, connection) |
119 | g_server:registerObjectInStream(connection, self.unloadPlace) |
120 | end |
121 | end |