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
HusbandryModuleBase
DescriptionThis class handles modules in husbandryFunctions
- addFillLevelFromTool
- addFillLevelToFillableObject
- changeFillLevels
- createModule
- delete
- finalizePlacement
- getAllFillLevels
- getCapacity
- getFillLevel
- getFillProgress
- getFreeCapacity
- getHasSpaceForUnloading
- getIsFillAllowedToFarm
- getIsFillTypeAllowed
- getIsNodeUsed
- getIsToolTypeAllowed
- getProvidedFillTypes
- getTotalFillLevel
- hasModule
- initDataStructures
- load
- loadFromXMLFile
- new
- onIntervalUpdate
- onSell
- readStream
- readUpdateStream
- registerModule
- setCapacity
- setFillLevel
- setSingleAnimalUsagePerDay
- writeStream
- writeUpdateStream
addFillLevelFromTool
DescriptionCalled to change the amount of a specific fillTypeDefinition
addFillLevelFromTool(float deltaFillLevel, integer fillTypeIndex)Arguments
float | deltaFillLevel | amount to change |
integer | fillTypeIndex | index of the fillType |
float | delta | of amount changed |
275 | function HusbandryModuleBase:addFillLevelFromTool(farmId, deltaFillLevel, fillTypeIndex) |
276 | if not self:getHasSpaceForUnloading() then |
277 | return 0 |
278 | end |
279 | |
280 | local changed = 0 |
281 | changed = self:changeFillLevels(deltaFillLevel, fillTypeIndex) |
282 | return changed |
283 | end |
addFillLevelToFillableObject
DescriptionIncrease fill level of a fillable objectDefinition
addFillLevelToFillableObject(table fillableObject, integer fillTypeIndex, integer fillDelta, table fillInfo, toolType)Arguments
table | fillableObject | fillable enity |
integer | fillTypeIndex | fill type id |
integer | fillDelta | amount to fill |
table | fillInfo | fill information structure |
toolType |
float | actual | delta filled |
397 | function HusbandryModuleBase:addFillLevelToFillableObject(fillableObject, fillUnitIndex, fillTypeIndex, fillDelta, fillInfo, toolType) |
398 | if fillableObject == nil or fillableObject == 0 or fillableObject == self then |
399 | return 0.0 |
400 | end |
401 | |
402 | local oldFillLevel = self:getFillLevel(fillTypeIndex) |
403 | fillDelta = math.min(fillDelta, oldFillLevel) |
404 | |
405 | local actualDelta = fillableObject:addFillUnitFillLevel(self.owner:getOwnerFarmId(), fillUnitIndex, fillDelta, fillTypeIndex, ToolType.UNDEFINED, fillInfo) |
406 | self:changeFillLevels(-actualDelta, fillTypeIndex) |
407 | |
408 | return actualDelta |
409 | end |
changeFillLevels
DescriptionChange amount of fillTypeDefinition
changeFillLevels(float amount, integer index)Arguments
float | amount | to change the fill type |
integer | index | of the fillType |
float | amount | effectively changed |
251 | function HusbandryModuleBase:changeFillLevels(fillDelta, fillTypeIndex) |
252 | local delta = 0.0 |
253 | if self.fillLevels[fillTypeIndex] ~= nil then |
254 | local oldFillLevel = self.fillLevels[fillTypeIndex] |
255 | local newFillLevel = oldFillLevel + fillDelta |
256 | newFillLevel = math.max(newFillLevel, 0.0) |
257 | delta = newFillLevel - oldFillLevel |
258 | |
259 | local oldTotalFillLevel = self:getTotalFillLevel() |
260 | local capacity = self:getCapacity() |
261 | local newTotalFillLevel = oldTotalFillLevel + delta |
262 | newTotalFillLevel = MathUtil.clamp(newTotalFillLevel, 0.0, capacity) |
263 | delta = newTotalFillLevel - oldTotalFillLevel |
264 | |
265 | self:setFillLevel(fillTypeIndex, newTotalFillLevel) |
266 | end |
267 | return delta |
268 | end |
createModule
DescriptionHusbandry module factory methodDefinition
createModule(table spec)Arguments
table | spec | Specialization reference |
table | module | instance or nil of no module has been registered |
444 | function HusbandryModuleBase.createModule(moduleName) |
445 | local moduleType = registry[moduleName] |
446 | local moduleInstance = nil |
447 | if moduleType ~= nil then |
448 | moduleInstance = moduleType.new() |
449 | end |
450 | return moduleInstance |
451 | end |
delete
DescriptionDeletes instanceDefinition
delete()Code
40 | function HusbandryModuleBase:delete() |
41 | self.owner = nil |
42 | end |
finalizePlacement
DescriptionCalled when husbandry is placedDefinition
finalizePlacement()Return Values
bool | true | if successful |
61 | function HusbandryModuleBase:finalizePlacement() |
62 | return true |
63 | end |
getAllFillLevels
DescriptionDefinitiongetAllFillLevels()Code
379 | function HusbandryModuleBase:getAllFillLevels() |
380 | local fillLevels = {} |
381 | local capacity = self:getCapacity() |
382 | |
383 | for fillTypeIndex, fillLevel in pairs(self.fillLevels) do |
384 | fillLevels[fillTypeIndex] = fillLevel |
385 | end |
386 | return fillLevels, capacity |
387 | end |
getCapacity
DescriptionGets a fill capacityDefinition
getCapacity(integer index)Arguments
integer | index | of a fill type |
float | returns | the capacity of a fillType |
347 | function HusbandryModuleBase:getCapacity() |
348 | return self.fillCapacity |
349 | end |
getFillLevel
DescriptionGets a fill levelDefinition
getFillLevel(integer index)Arguments
integer | index | of a fill type |
float | returns | the fillLevel of a fillType |
289 | function HusbandryModuleBase:getFillLevel(fillTypeIndex) |
290 | return Utils.getNoNil(self.fillLevels[fillTypeIndex], 0.0) |
291 | end |
getFillProgress
DescriptionGets a fill progressDefinition
getFillProgress(integer index)Arguments
integer | index | of a fill type |
float | returns | a progress of the fillType between 0 and 1. Default is 0. |
355 | function HusbandryModuleBase:getFillProgress() |
356 | local capacity = self:getCapacity() |
357 | if capacity > 0.0 then |
358 | local progress = self:getTotalFillLevel() / capacity |
359 | progress = MathUtil.clamp(progress, 0.0, 1.0) |
360 | return progress |
361 | end |
362 | return 0.0 |
363 | end |
getFreeCapacity
DescriptionSets a capacityDefinition
getFreeCapacity()Code
332 | function HusbandryModuleBase:getFreeCapacity(fillTypeIndex) |
333 | return self:getCapacity() - self:getFillLevel(fillTypeIndex) |
334 | end |
getHasSpaceForUnloading
DescriptionChecks if there is enough space to unload a fillTypeDefinition
getHasSpaceForUnloading(integer index)Arguments
integer | index | of the fillType |
242 | function HusbandryModuleBase:getHasSpaceForUnloading() |
243 | return self:getTotalFillLevel() <= self:getCapacity() |
244 | end |
getIsFillAllowedToFarm
DescriptionDefinitiongetIsFillAllowedToFarm(integer farmId)Arguments
integer | farmId |
bool |
415 | function HusbandryModuleBase:getIsFillAllowedToFarm(farmId) |
416 | return g_currentMission.accessHandler:canFarmAccess(farmId, self.owner) |
417 | end |
getIsFillTypeAllowed
DescriptionCheck if fillType is allowedDefinition
getIsFillTypeAllowed(integer fillTypeIndex)Arguments
integer | fillTypeIndex | index of the fillType to check |
222 | function HusbandryModuleBase:getIsFillTypeAllowed(fillTypeIndex) |
223 | for fTypeIndex, state in pairs(self.providedFillTypes) do |
224 | if fTypeIndex == fillTypeIndex and state then |
225 | return true |
226 | end |
227 | end |
228 | |
229 | return false |
230 | end |
getIsNodeUsed
DescriptionDefinitiongetIsNodeUsed()Code
373 | function HusbandryModuleBase:getIsNodeUsed(node) |
374 | return false |
375 | end |
getIsToolTypeAllowed
DescriptionChecks if a tool type is allowed. (empty method)Definition
getIsToolTypeAllowed(integer toolType)Arguments
integer | toolType |
235 | function HusbandryModuleBase:getIsToolTypeAllowed(toolType) |
236 | return true |
237 | end |
getProvidedFillTypes
DescriptionDefinitiongetProvidedFillTypes()Code
367 | function HusbandryModuleBase:getProvidedFillTypes() |
368 | return self.providedFillTypes |
369 | end |
getTotalFillLevel
DescriptionGets total fill levelDefinition
getTotalFillLevel()Return Values
float | returns | the fillLevel of all fillType |
312 | function HusbandryModuleBase:getTotalFillLevel() |
313 | local totalFillLevel = 0.0 |
314 | |
315 | for _, fillLevel in pairs(self.fillLevels) do |
316 | totalFillLevel = totalFillLevel + fillLevel |
317 | end |
318 | |
319 | return totalFillLevel |
320 | end |
hasModule
DescriptionCheck if there is a module for a given specialization.Definition
hasModule()Code
455 | function HusbandryModuleBase.hasModule(moduleName) |
456 | return registry[moduleName] ~= nil |
457 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
31 | function HusbandryModuleBase:initDataStructures() |
32 | self.fillLevels = {} |
33 | self.fillCapacity = 0.0 |
34 | self.providedFillTypes = {} |
35 | self.singleAnimalUsagePerDay = 0.0 |
36 | end |
load
DescriptionLoads data from xml. Checking methods from husbandry used by modules are available.Definition
load(table xmlFile, string xmlKey, table rootNode, table owner)Arguments
table | xmlFile | handle |
string | xmlKey | from which to read the configuration |
table | rootNode | of the husbandry |
table | owner | the husbandry |
boolean | true | if loading was successful else false |
51 | function HusbandryModuleBase:load(xmlFile, configKey, rootNode, owner, baseDirectory) |
52 | self.owner = owner |
53 | self.baseDirectory = baseDirectory |
54 | |
55 | return true |
56 | 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 |
169 | function HusbandryModuleBase:loadFromXMLFile(xmlFile, key) |
170 | self.fillCapacity = Utils.getNoNil(getXMLFloat(xmlFile, key.."#fillCapacity"), self.fillCapacity) |
171 | |
172 | local i = 0 |
173 | while true do |
174 | local fillLevelKey = key .. string.format(".fillLevel(%d)", i) |
175 | |
176 | if not hasXMLProperty(xmlFile, fillLevelKey) then |
177 | break |
178 | end |
179 | |
180 | local fillTypeName = getXMLString(xmlFile, fillLevelKey .. "#fillType") |
181 | local fillLevel = getXMLFloat(xmlFile, fillLevelKey .. "#fillLevel") |
182 | if fillTypeName ~= nil and fillLevel ~= nil then |
183 | local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeName) |
184 | |
185 | if fillTypeIndex ~= nil then |
186 | self:setFillLevel(fillTypeIndex, fillLevel) |
187 | self.providedFillTypes[fillTypeIndex] = true |
188 | end |
189 | end |
190 | i = i + 1 |
191 | end |
192 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
17 | function HusbandryModuleBase:new(customMt) |
18 | if customMt == nil then |
19 | customMt = HusbandryModuleBase_mt |
20 | end |
21 | |
22 | local self = {} |
23 | setmetatable(self, customMt) |
24 | self:initDataStructures() |
25 | self.owner = nil |
26 | return self |
27 | end |
onIntervalUpdate
DescriptionUpdates module when a timed interval has passedDefinition
onIntervalUpdate(float dayToInterval)Arguments
float | dayToInterval |
78 | function HusbandryModuleBase:onIntervalUpdate(dayToInterval) |
79 | end |
onSell
DescriptionCalled when husbandry is placedDefinition
onSell()Return Values
bool | true | if successful |
68 | function HusbandryModuleBase:onSell() |
69 | self.fillLevels = {} |
70 | self.fillCapacity = 0.0 |
71 | self.providedFillTypes = {} |
72 | self.singleAnimalUsagePerDay = 0.0 |
73 | end |
readStream
DescriptionReads network streamDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | network stream identification |
table | connection | connection information |
101 | function HusbandryModuleBase:readStream(streamId, connection) |
102 | local nbFillLevel = streamReadUInt8(streamId) |
103 | |
104 | for i=1, nbFillLevel do |
105 | local fillTypeIndex = streamReadUInt8(streamId) |
106 | local fillLevel = streamReadFloat32(streamId) |
107 | self:setFillLevel(fillTypeIndex, fillLevel) |
108 | end |
109 | 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 |
133 | function HusbandryModuleBase:readUpdateStream(streamId, timestamp, connection) |
134 | local nbFillLevel = streamReadUInt8(streamId) |
135 | |
136 | for i=1, nbFillLevel do |
137 | local fillTypeIndex = streamReadUInt8(streamId) |
138 | local fillLevel = streamReadFloat32(streamId) |
139 | self:setFillLevel(fillTypeIndex, fillLevel) |
140 | end |
141 | end |
registerModule
DescriptionRegister a HUD extension for a specialization.Definition
registerModule(string moduleName, table moduleType)Arguments
string | moduleName | module name |
table | moduleType | module class type table corresponding to the given module |
436 | function HusbandryModuleBase.registerModule(moduleName, moduleType) |
437 | registry[moduleName] = moduleType |
438 | end |
setCapacity
DescriptionSets a capacityDefinition
setCapacity(float newCapacity)Arguments
float | newCapacity |
325 | function HusbandryModuleBase:setCapacity(newCapacity) |
326 | self.fillCapacity = newCapacity |
327 | self:onFillProgressChanged() |
328 | end |
setFillLevel
DescriptionSet fill level of storageDefinition
setFillLevel(float fillLevel, integer fillType)Arguments
float | fillLevel | new fill level |
integer | fillType | fill type |
297 | function HusbandryModuleBase:setFillLevel(fillTypeIndex, fillLevel) |
298 | if self.fillLevels[fillTypeIndex] ~= fillLevel then |
299 | self.fillLevels[fillTypeIndex] = fillLevel |
300 | |
301 | self:onFillProgressChanged() |
302 | |
303 | if self.owner.isServer then |
304 | self.owner:raiseDirtyFlags(self.owner.husbandryDirtyFlag) |
305 | end |
306 | end |
307 | end |
setSingleAnimalUsagePerDay
DescriptionDefinitionsetSingleAnimalUsagePerDay()Arguments
Warning: Undefined array key "className" in /usr/www/users/giantw/gdn.giants-software.com/documentation_scripting_fs19.php on line 189 |
339 | function HusbandryModuleBase:setSingleAnimalUsagePerDay(usagePerDay) |
340 | self.singleAnimalUsagePerDay = usagePerDay |
341 | end |
writeStream
DescriptionWrites network streamDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | network stream identification |
table | connection | connection information |
115 | function HusbandryModuleBase:writeStream(streamId, connection) |
116 | local nbFillLevel = 0 |
117 | for fillTypeIndex, fillLevel in pairs(self.fillLevels) do |
118 | nbFillLevel = nbFillLevel + 1 |
119 | end |
120 | |
121 | streamWriteUInt8(streamId, nbFillLevel) |
122 | for fillTypeIndex, fillLevel in pairs(self.fillLevels) do |
123 | streamWriteUInt8(streamId, fillTypeIndex) |
124 | streamWriteFloat32(streamId, fillLevel) |
125 | end |
126 | 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 |
148 | function HusbandryModuleBase:writeUpdateStream(streamId, connection, dirtyMask) |
149 | local nbFillLevel = 0 |
150 | for fillTypeIndex, fillLevel in pairs(self.fillLevels) do |
151 | nbFillLevel = nbFillLevel + 1 |
152 | end |
153 | |
154 | streamWriteUInt8(streamId, nbFillLevel) |
155 | for fillTypeIndex, fillLevel in pairs(self.fillLevels) do |
156 | streamWriteUInt8(streamId, fillTypeIndex) |
157 | streamWriteFloat32(streamId, fillLevel) |
158 | end |
159 | end |