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
HusbandryModuleMilk
DescriptionThis class handles milk in husbandryParent
HusbandryModuleBaseFunctions
delete
DescriptionDeletes instanceDefinition
delete()Code
31 | function HusbandryModuleMilk:delete() |
32 | HusbandryModuleMilk:superClass().delete(self) |
33 | if self.loadPlace ~= nil then |
34 | self.loadPlace:delete() |
35 | self.loadPlace = nil |
36 | end |
37 | end |
getFilltypeInfos
DescriptionDefinitiongetFilltypeInfos()Code
132 | function HusbandryModuleMilk:getFilltypeInfos() |
133 | local result = {} |
134 | |
135 | for fillTypeIndex, _ in pairs(self.loadPlace.fillTypes) do |
136 | local fillType = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex) |
137 | local capacity = self:getCapacity() |
138 | local fillLevel = self:getFillLevel(fillTypeIndex) |
139 | |
140 | table.insert(result, {fillType=fillType, fillLevel=fillLevel, capacity=capacity}) |
141 | end |
142 | return result |
143 | 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 |
45 | function HusbandryModuleMilk:load(xmlFile, configKey, rootNode, owner, baseDirectory) |
46 | local result = HusbandryModuleMilk:superClass().load(self, xmlFile, configKey, rootNode, owner, baseDirectory) |
47 | |
48 | if result ~= true then |
49 | return false |
50 | end |
51 | if not hasXMLProperty(xmlFile, configKey) then |
52 | return false |
53 | end |
54 | |
55 | local milkTankNodeId = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#node")) |
56 | if milkTankNodeId ~= nil then |
57 | local loadPlace = LoadTrigger:new(self.owner.isServer, self.owner.isClient) |
58 | self.stationName = self.owner:getName() -- used in the silo dialog |
59 | |
60 | if loadPlace:load(milkTankNodeId, xmlFile, configKey) then |
61 | loadPlace:setSource(self) |
62 | loadPlace:register(true) |
63 | |
64 | self.loadPlace = loadPlace |
65 | |
66 | for fillTypeIndex, state in pairs(loadPlace.fillTypes) do |
67 | self.fillLevels[fillTypeIndex] = 0.0 |
68 | self.providedFillTypes[fillTypeIndex] = state |
69 | end |
70 | self:setCapacity(0.0) |
71 | |
72 | return true |
73 | else |
74 | loadPlace:delete() |
75 | end |
76 | end |
77 | return false |
78 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
21 | function HusbandryModuleMilk:new(customMt) |
22 | if customMt == nil then |
23 | customMt = HusbandryModuleMilk_mt |
24 | end |
25 | local self = HusbandryModuleBase:new(customMt) |
26 | return self |
27 | end |
onIntervalUpdate
DescriptionUpdate milk usageDefinition
onIntervalUpdate(float dayToInterval)Arguments
float | dayToInterval |
111 | function HusbandryModuleMilk:onIntervalUpdate(dayToInterval) |
112 | HusbandryModuleMilk:superClass().onIntervalUpdate(self, dayToInterval) |
113 | |
114 | if self.singleAnimalUsagePerDay > 0.0 then |
115 | local hasWater = self.owner:hasWater() |
116 | |
117 | if hasWater then |
118 | local totalNumAnimals = self.owner:getNumOfAnimals() |
119 | local newMilk = self.owner:getGlobalProductionFactor() * totalNumAnimals * self.singleAnimalUsagePerDay * dayToInterval |
120 | |
121 | if newMilk > 0 then |
122 | for fillTypeIndex, state in pairs(self.loadPlace.fillTypes) do |
123 | self:changeFillLevels(newMilk, fillTypeIndex) |
124 | end |
125 | end |
126 | end |
127 | end |
128 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
84 | function HusbandryModuleMilk:readStream(streamId, connection) |
85 | HusbandryModuleMilk:superClass().readStream(self, streamId, connection) |
86 | |
87 | if self.loadPlace ~= nil then |
88 | local loadPlaceId = NetworkUtil.readNodeObjectId(streamId) |
89 | self.loadPlace:readStream(streamId, connection) |
90 | g_client:finishRegisterObject(self.loadPlace, loadPlaceId) |
91 | end |
92 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
98 | function HusbandryModuleMilk:writeStream(streamId, connection) |
99 | HusbandryModuleMilk:superClass().writeStream(self, streamId, connection) |
100 | |
101 | if self.loadPlace ~= nil then |
102 | NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.loadPlace)) |
103 | self.loadPlace:writeStream(streamId, connection) |
104 | g_server:registerObjectInStream(connection, self.loadPlace) |
105 | end |
106 | end |