Script v1.7.1.0
- AI
- Animals
- 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
- assignAnimTrackClip
- clearAnimTrackClip
- cloneAnimCharacterSet
- disableAnimTrack
- enableAnimTrack
- getAnimCharacterSet
- getAnimClipDuration
- getAnimClipIndex
- getAnimNumOfClips
- getAnimTrackAssignedClip
- getAnimTrackBlendWeight
- getAnimTrackTime
- isAnimTrackClipAssigned
- isAnimTrackEnabled
- setAnimTrackBlendWeight
- setAnimTrackLoopState
- setAnimTrackSpeedScale
- setAnimTrackTime
- 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
HusbandryModuleStraw
DescriptionThis class handles straw in husbandryParent
HusbandryModuleBaseFunctions
- addFillLevelFromTool
- delete
- getFilltypeInfos
- hasStraw
- initDataStructures
- load
- loadFromXMLFile
- new
- onIntervalUpdate
- readStream
- writeStream
addFillLevelFromTool
DescriptionDefinitionaddFillLevelFromTool()Code
151 | function HusbandryModuleStraw:addFillLevelFromTool(farmId, deltaFillLevel, fillType) |
152 | local changed = HusbandryModuleStraw:superClass().addFillLevelFromTool(self, farmId, deltaFillLevel, fillType) |
153 | |
154 | if deltaFillLevel > 0 and changed ~= 0 then |
155 | self.owner:updateGlobalProductionFactor() |
156 | end |
157 | |
158 | if changed > 0 and self.unloadPlace ~= nil then |
159 | if self.unloadPlace:getIsFillTypeSupported(fillType) then |
160 | self.unloadPlace:raiseActive() |
161 | self:updateFillPlane() |
162 | end |
163 | end |
164 | |
165 | return changed |
166 | end |
delete
DescriptionDeletes instanceDefinition
delete()Code
27 | function HusbandryModuleStraw: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
182 | function HusbandryModuleStraw:getFilltypeInfos() |
183 | local result = {} |
184 | |
185 | for filltypeIndex, val in pairs(self.fillLevels) do |
186 | local fillType = g_fillTypeManager:getFillTypeByIndex(filltypeIndex) |
187 | local capacity = self.unloadPlace.target:getCapacity() |
188 | local fillLevel = self.unloadPlace.target:getFillLevel(filltypeIndex) |
189 | |
190 | table.insert(result, {fillType=fillType, fillLevel=fillLevel, capacity=capacity}) |
191 | end |
192 | |
193 | return result |
194 | end |
hasStraw
DescriptionDefinitionhasStraw()Code
170 | function HusbandryModuleStraw:hasStraw() |
171 | local totalStraw = 0.0 |
172 | |
173 | for _, fillLevel in pairs(self.fillLevels) do |
174 | totalStraw = totalStraw + fillLevel |
175 | end |
176 | |
177 | return totalStraw > 0.0 |
178 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
40 | function HusbandryModuleStraw:initDataStructures() |
41 | HusbandryModuleStraw: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 HusbandryModuleStraw:load(xmlFile, configKey, rootNode, owner, baseDirectory) |
52 | if not HusbandryModuleStraw: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 strawNodeId = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#node")) |
61 | if strawNodeId ~= nil then |
62 | local unloadPlace = UnloadTrigger:new(self.owner.isServer, self.owner.isClient) |
63 | |
64 | if unloadPlace:load(strawNodeId, xmlFile, configKey, self) then |
65 | unloadPlace:register(true) |
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 HusbandryModuleStraw:loadFromXMLFile(xmlFile, key) |
91 | HusbandryModuleStraw:superClass().loadFromXMLFile(self, xmlFile, key) |
92 | |
93 | if self.fillPlane ~= nil then |
94 | self.fillPlane:setState(self:getFillProgress()) |
95 | end |
96 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
21 | function HusbandryModuleStraw:new(customMt) |
22 | return HusbandryModuleBase:new(customMt or HusbandryModuleStraw_mt) |
23 | end |
onIntervalUpdate
DescriptionUpdate straw usageDefinition
onIntervalUpdate(float dayToInterval)Arguments
float | dayToInterval |
131 | function HusbandryModuleStraw:onIntervalUpdate(dayToInterval) |
132 | HusbandryModuleStraw:superClass().onIntervalUpdate(self, dayToInterval) |
133 | |
134 | if self.singleAnimalUsagePerDay > 0.0 then |
135 | local totalNumAnimals = self.owner:getNumOfAnimals() |
136 | local strawNeeded = totalNumAnimals * self.singleAnimalUsagePerDay * dayToInterval |
137 | |
138 | if strawNeeded > 0.0 then |
139 | for fillTypeIndex, fillLevel in pairs(self.fillLevels) do |
140 | if fillLevel > 0.0 then |
141 | self:changeFillLevels(-math.min(strawNeeded, fillLevel), fillTypeIndex) |
142 | self:updateFillPlane() |
143 | end |
144 | end |
145 | end |
146 | end |
147 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
102 | function HusbandryModuleStraw:readStream(streamId, connection) |
103 | HusbandryModuleStraw:superClass().readStream(self, streamId, connection) |
104 | |
105 | if self.unloadPlace ~= nil then |
106 | local unloadPlaceId = NetworkUtil.readNodeObjectId(streamId) |
107 | self.unloadPlace:readStream(streamId, connection) |
108 | g_client:finishRegisterObject(self.unloadPlace, unloadPlaceId) |
109 | end |
110 | |
111 | self:updateFillPlane() |
112 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
118 | function HusbandryModuleStraw:writeStream(streamId, connection) |
119 | HusbandryModuleStraw:superClass().writeStream(self, streamId, connection) |
120 | |
121 | if self.unloadPlace ~= nil then |
122 | NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.unloadPlace)) |
123 | self.unloadPlace:writeStream(streamId, connection) |
124 | g_server:registerObjectInStream(connection, self.unloadPlace) |
125 | end |
126 | end |