LUADOC - Farming Simulator 19

AnimalHusbandry

Description
Animal husbandry class
Parent
Placeable
XML Configuration Parameters
placeable.husbandry.animal#typetype of animal
placeable.husbandry.animal#initialCountinitial number of animals to spawn
placeable.husbandry.navmesh#indexnavmesh node index
placeable.husbandry.liquidManureTrigger#indexliquid manure trigger node index
placeable.husbandry.fillLevelListeners#indexnode index where the fill level listeners are located
placeable.husbandry.placementRaycast#distancedistance for the placement raycast

Functions

addRideable

Description
Definition
addRideable()
Code
814function AnimalHusbandry:addRideable(visualId, player)
815 local animalsModule = self:getModuleByName("animals")
816
817 if animalsModule ~= nil then
818 animalsModule:addRideable(visualId, player)
819 end
820end

addSingleAnimal

Description
Registers the husbandry to the mission game.
Definition
addSingleAnimal()
Code
776function AnimalHusbandry:addSingleAnimal(animal)
777 local animalsModule = self:getModuleByName("animals")
778
779 if animalsModule ~= nil then
780 animalsModule:addSingleAnimal(animal)
781 end
782end

canBuy

Description
Returns true if we can place a building
Definition
canBuy()
Return Values
bool
Code
154function AnimalHusbandry:canBuy()
155 local canBuy = AnimalHusbandry:superClass().canBuy(self)
156 return canBuy and self:canAddMoreHusbandriesToGame(), g_i18n:getText("warning_tooManyHusbandries")
157end

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
418function AnimalHusbandry:collectPickObjects(node, target)
419 -- do not add node if used by module (e.g. a food trigger already added this node)
420 for _, moduleInstance in pairs(self.modulesById) do
421 if moduleInstance:getIsNodeUsed(node) then
422 return
423 end
424 end
425
426 AnimalHusbandry:superClass().collectPickObjects(self, node, target)
427end

delete

Description
Deletes instance
Definition
delete()
Code
206function AnimalHusbandry:delete()
207 g_currentMission:removeOnCreateLoadedObjectToSave(self)
208 self:unregisterHusbandryToMission()
209
210 for _, moduleInstance in pairs(self.modulesById) do
211 moduleInstance:delete()
212 end
213
214 if self.isServer then
215 if self.palletSpawnerTriggerId ~= nil then
216 removeTrigger(self.palletSpawnerTriggerId)
217 end
218 end
219
220 AnimalHusbandry:superClass().delete(self)
221end

finalizePlacement

Description
Called when player places the husbandry.
Definition
finalizePlacement()
Return Values
boolreturnstrue if initialization is fine
Code
172function AnimalHusbandry:finalizePlacement()
173 AnimalHusbandry:superClass().finalizePlacement(self)
174
175 local success = self:modulesFinalizePlacement() and self:registerHusbandryToMission()
176 if not success then
177 return false
178 end
179
180 if self.isServer then
181 g_currentMission.environment:addMinuteChangeListener(self)
182 g_currentMission.environment:addHourChangeListener(self)
183 g_currentMission.environment:addDayChangeListener(self)
184 end
185 return true
186end

getAnimalName

Description
Retrieves animal name
Definition
getAnimalName()
Code
933function AnimalHusbandry:getAnimalName(visualId)
934 local animalsModule = self:getModuleByName("animals")
935
936 if animalsModule ~= nil then
937 return animalsModule:getAnimalName(visualId)
938 end
939 return ""
940end

getAnimals

Description
Registers the husbandry to the mission game.
Definition
getAnimals()
Code
719function AnimalHusbandry:getAnimals()
720 local animalsModule = self:getModuleByName("animals")
721
722 if animalsModule ~= nil then
723 return animalsModule:getAnimals()
724 end
725end

getAnimalSubTypeCount

Description
Registers the husbandry to the mission game.
Definition
getAnimalSubTypeCount()
Code
707function AnimalHusbandry:getAnimalSubTypeCount()
708 local count = 0
709 local animalsModule = self:getModuleByName("animals")
710
711 if animalsModule ~= nil then
712 count = animalsModule.numSubTypes
713 end
714 return count
715end

getAnimalType

Description
Definition
getAnimalType()
Return Values
stringreturnanimal type. nil if not available
Code
480function AnimalHusbandry:getAnimalType()
481 local animalsModule = self:getModuleByName("animals")
482
483 if animalsModule ~= nil then
484 return animalsModule:getAnimalType()
485 end
486
487 return nil
488end

getCanBePlacedAt

Description
Returns true if we can place a building
Definition
getCanBePlacedAt()
Return Values
bool
Code
146function AnimalHusbandry:getCanBePlacedAt(x, y, z, distance)
147 local canBePlaced = AnimalHusbandry:superClass().getCanBePlacedAt(self, x, y, z, distance)
148 return canBePlaced and self:canAddMoreHusbandriesToGame()
149end

getConsumedFood

Description
Returns the amount of food consumed
Definition
getConsumedFood()
Return Values
tableofcosumed food (result[fillTypeIndex]=amount)
Code
493function AnimalHusbandry:getConsumedFood()
494 local foodModule = self:getModuleByName("food")
495
496 if foodModule ~= nil then
497 return foodModule:getConsumedFood()
498 end
499 return nil
500end

getFilltype

Description
Definition
getFilltype()
Code
889function AnimalHusbandry:getFilltype(subTypeId)
890 local animalsModule = self:getModuleByName("animals")
891
892 if animalsModule ~= nil then
893 local fillType = animalsModule:getFillType(subTypeId)
894 return fillType
895 end
896 return nil
897end

getFluidStatsText

Description
Format text to display fill level
Definition
getFluidStatsText(float fillLevel, bool alwaysExact)
Arguments
floatfillLevel
boolalwaysExactif true will change text accordingly
Return Values
stringfilllevel
Code
406function AnimalHusbandry:getFluidStatsText(fillLevel, alwaysExact)
407 fillLevel = Utils.getNoNil(fillLevel,0)
408 if self.isServer or alwaysExact or fillLevel == 0 then
409 return string.format("%1.0f", math.floor(g_i18n:getFluid(fillLevel)))
410 else
411 return string.format("~%1.0f", math.floor(g_i18n:getFluid(fillLevel)))
412 end
413end

getFoodFilltypeInfo

Description
Definition
getFoodFilltypeInfo()
Code
537function AnimalHusbandry:getFoodFilltypeInfo()
538 local foodModule = self:getModuleByName("food")
539
540 if foodModule ~= nil then
541 return foodModule:getFilltypeInfos()
542 end
543 return AnimalHusbandry.NO_FILLTYPE_INFOS
544end

getFoodProductionFactor

Description
Definition
getFoodProductionFactor()
Code
504function AnimalHusbandry:getFoodProductionFactor()
505 local foodModule = self:getModuleByName("food")
506
507 if foodModule ~= nil then
508 return foodModule:getFoodFactor()
509 end
510 return 0.0
511end

getFoodSpillageFactor

Description
Definition
getFoodSpillageFactor()
Code
632function AnimalHusbandry:getFoodSpillageFactor()
633 local foodSpillageModule = self:getModuleByName("foodSpillage")
634
635 if foodSpillageModule ~= nil then
636 return foodSpillageModule:getSpillageFactor()
637 end
638
639 return nil
640end

getGlobalDirtFactor

Description
Definition
getGlobalDirtFactor()
Return Values
floatdirtyfactor [0-1]
Code
902function AnimalHusbandry:getGlobalDirtFactor()
903 local animalsModule = self:getModuleByName("animals")
904 if animalsModule ~= nil then
905 return animalsModule:getDirtFactor()
906 end
907
908 return 0
909end

getGlobalProductionFactor

Description
Definition
getGlobalProductionFactor()
Code
883function AnimalHusbandry:getGlobalProductionFactor()
884 return self.globalProductionFactor
885end

getLiquidManureFilltypeInfo

Description
Definition
getLiquidManureFilltypeInfo()
Code
581function AnimalHusbandry:getLiquidManureFilltypeInfo()
582 local liquidManureModule = self:getModuleByName("liquidManure")
583
584 if liquidManureModule ~= nil then
585 return liquidManureModule:getFilltypeInfos()
586 end
587 return AnimalHusbandry.NO_FILLTYPE_INFOS
588end

getManureFilltypeInfo

Description
Definition
getManureFilltypeInfo()
Code
592function AnimalHusbandry:getManureFilltypeInfo()
593 local manureModule = self:getModuleByName("manure")
594
595 if manureModule ~= nil then
596 return manureModule:getFilltypeInfos()
597 end
598 return AnimalHusbandry.NO_FILLTYPE_INFOS
599end

getMilkFilltypeInfo

Description
Definition
getMilkFilltypeInfo()
Code
644function AnimalHusbandry:getMilkFilltypeInfo()
645 local milkModule = self:getModuleByName("milk")
646
647 if milkModule ~= nil then
648 return milkModule:getFilltypeInfos()
649 end
650 return AnimalHusbandry.NO_FILLTYPE_INFOS
651end

getMinutesUntilNextAnimal

Description
Definition
getMinutesUntilNextAnimal()
Code
955function AnimalHusbandry:getMinutesUntilNextAnimal(fillTypeIndex)
956 local animalsModule = self:getModuleByName("animals")
957
958 if animalsModule ~= nil then
959 return animalsModule:getMinutesUntilNextAnimal(fillTypeIndex)
960 end
961 return nil
962end

getModuleById

Description
Definition
getModuleById()
Code
435function AnimalHusbandry:getModuleById(moduleId)
436 local moduleinstance = self.modulesById[moduleId]
437
438 return moduleinstance
439end

getModuleByName

Description
Definition
getModuleByName()
Code
443function AnimalHusbandry:getModuleByName(moduleName)
444 if HusbandryModuleBase.hasModule(moduleName) then
445 return self.modulesByName[moduleName]
446 end
447 g_logManager:warning("Animal module '%s' is not registered!", tostring(moduleName))
448 return nil
449end

getNumOfAnimals

Description
Definition
getNumOfAnimals()
Return Values
integertotalanimals. Default is zero
Code
468function AnimalHusbandry:getNumOfAnimals()
469 local animalsModule = self:getModuleByName("animals")
470
471 if animalsModule ~= nil then
472 return animalsModule:getNumOfAnimals()
473 end
474 return 0
475end

getPalletsFilltypeInfo

Description
Definition
getPalletsFilltypeInfo()
Code
570function AnimalHusbandry:getPalletsFilltypeInfo()
571 local palletsModule = self:getModuleByName("pallets")
572
573 if palletsModule ~= nil then
574 return palletsModule:getFilltypeInfos()
575 end
576 return AnimalHusbandry.NO_FILLTYPE_INFOS
577end

getProductionFilltypeInfo

Description
Get production fill type information for this husbandry. This will return fill type information in an array per fill type with tables in the form of {fillType=fillType, fillLevel=fillLevel, capacity=capacity}. The output order is set to manure first, liquid manure (slurry) second and the main husbandry product (e.g. milk, egg pallets) third.
Definition
getProductionFilltypeInfo()
Return Values
tableProductionfill type information as {i={j={fillType=fillType, fillLevel=fillLevel, capacity=capacity}}}
Code
606function AnimalHusbandry:getProductionFilltypeInfo()
607 local manureProduction = self:getManureFilltypeInfo()
608 local liquidManureProduction = self:getLiquidManureFilltypeInfo()
609 local milkProduction = self:getMilkFilltypeInfo()
610 local palletsProduction = self:getPalletsFilltypeInfo()
611
612 local result = {}
613 if manureProduction ~= AnimalHusbandry.NO_FILLTYPE_INFOS then
614 table.insert(result, manureProduction)
615 end
616
617 if liquidManureProduction ~= AnimalHusbandry.NO_FILLTYPE_INFOS then
618 table.insert(result, liquidManureProduction)
619 end
620
621 if milkProduction ~= AnimalHusbandry.NO_FILLTYPE_INFOS then
622 table.insert(result, milkProduction)
623 elseif palletsProduction ~= AnimalHusbandry.NO_FILLTYPE_INFOS then
624 table.insert(result, palletsProduction)
625 end
626
627 return result
628end

getReproductionTimePerDay

Description
Definition
getReproductionTimePerDay()
Code
944function AnimalHusbandry:getReproductionTimePerDay(fillTypeIndex)
945 local animalsModule = self:getModuleByName("animals")
946 if animalsModule ~= nil then
947 return animalsModule:getReproductionTimePerDay(fillTypeIndex)
948 end
949
950 return 0
951end

getStrawFilltypeInfo

Description
Definition
getStrawFilltypeInfo()
Code
559function AnimalHusbandry:getStrawFilltypeInfo()
560 local strawModule = self:getModuleByName("straw")
561
562 if strawModule ~= nil then
563 return strawModule:getFilltypeInfos()
564 end
565 return AnimalHusbandry.NO_FILLTYPE_INFOS
566end

getTypedAnimals

Description
Registers the husbandry to the mission game.
Definition
getTypedAnimals()
Code
729function AnimalHusbandry:getTypedAnimals()
730 local animalsModule = self:getModuleByName("animals")
731
732 if animalsModule ~= nil then
733 return animalsModule:getTypedAnimals()
734 end
735end

getWaterFilltypeInfo

Description
Definition
getWaterFilltypeInfo()
Code
548function AnimalHusbandry:getWaterFilltypeInfo()
549 local waterModule = self:getModuleByName("water")
550
551 if waterModule ~= nil then
552 return waterModule:getFilltypeInfos()
553 end
554 return AnimalHusbandry.NO_FILLTYPE_INFOS
555end

hasStraw

Description
Definition
hasStraw()
Code
515function AnimalHusbandry:hasStraw()
516 local strawModule = self:getModuleByName("straw")
517
518 if strawModule ~= nil then
519 return strawModule:hasStraw()
520 end
521 return true
522end

hasWater

Description
Definition
hasWater()
Code
526function AnimalHusbandry:hasWater()
527 local waterModule = self:getModuleByName("water")
528
529 if waterModule ~= nil then
530 return waterModule:hasWater()
531 end
532 return true
533end

isRideableInOnHusbandryGround

Description
Definition
isRideableInOnHusbandryGround()
Code
835function AnimalHusbandry:isRideableInOnHusbandryGround(visualId)
836 local animalsModule = self:getModuleByName("animals")
837
838 if animalsModule ~= nil then
839 return animalsModule:isRideableInOnHusbandryGround(visualId)
840 end
841 return false
842end

isSimilarHusbandryRegistered

Description
Returns true if a husbandry with same animal type exists for the current farmId
Definition
isSimilarHusbandryRegistered()
Return Values
bool
Code
656function AnimalHusbandry:isSimilarHusbandryRegistered()
657 local animalsModule = self:getModuleByName("animals")
658
659 if animalsModule ~= nil then
660 local animalType = animalsModule:getAnimalType()
661 if animalType ~= nil then
662 for _, husbandry in pairs(g_currentMission.husbandries) do
663 if animalType == husbandry:getAnimalType() and husbandry:getOwnerFarmId() == self:getOwnerFarmId() then
664 return true
665 end
666 end
667 end
668 end
669 return false
670end

load

Description
Loads information from xml file and registers the instance to the current Mission
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, initRandom)
Arguments
stringxmlFilenameXML filename
floatxworld x position
floatyworld y position
floatzworld z position
floatrxx rotation in rad
floatryy rotation in rad
floatrzz rotation in rad
initRandom
Return Values
boolreturnstrue if loading is fine
Code
74function AnimalHusbandry:load(xmlFilename, x, y, z, rx, ry, rz, initRandom)
75 if not AnimalHusbandry:superClass().load(self, xmlFilename, x, y, z, rx, ry, rz, initRandom) then
76 return false
77 end
78
79 local success = self:loadModules(xmlFilename)
80
81 if success then
82 local xmlFile = loadXMLFile("AnimalHusbandryXML", xmlFilename)
83 local key = string.format("placeable.husbandry")
84 self.saveId = Utils.getNoNil(getXMLString(xmlFile, key .. "#saveId"), "Animals_" .. self:getAnimalType())
85 self.hasStatistics = Utils.getNoNil(getXMLBool(xmlFile, key .. "#hasStatistics"), false)
86 delete(xmlFile)
87 end
88
89 return success
90end

loadFromXMLFile

Description
Loads information from attributes and node. Retrives from xml file information from: initial amount of animals. manure, pallet, fill level, cleanliness.
Definition
loadFromXMLFile(table xmlFile, string key)
Arguments
tablexmlFileXML file handler
stringkeyXML base key
Code
227function AnimalHusbandry:loadFromXMLFile(xmlFile, key)
228 AnimalHusbandry:superClass().loadFromXMLFile(self, xmlFile, key, nil)
229
230 self.globalProductionFactor = getXMLFloat(xmlFile, key.."#globalProductionFactor") or self.globalProductionFactor
231
232 local i = 0
233 while true do
234 local moduleKey = string.format("%s.module(%d)", key, i)
235 local moduleNameKey = string.format("%s#name", moduleKey)
236 if not hasXMLProperty(xmlFile, moduleNameKey) then
237 break
238 end
239 local moduleName = getXMLString(xmlFile, moduleNameKey)
240 local moduleInstance = self:getModuleByName(moduleName)
241
242 if moduleInstance ~= nil then
243 moduleInstance:loadFromXMLFile(xmlFile, moduleKey)
244 end
245 i = i + 1
246 end
247 return true
248end

loadModules

Description
Loads all modules declared in xml file
Definition
loadModules(table xmlFile)
Arguments
tablexmlFilehandle to the xml config file
Code
95function AnimalHusbandry:loadModules(xmlFilename)
96 local xmlFile = loadXMLFile("TempXML", xmlFilename)
97 local key = string.format("placeable.husbandry")
98 local i = 0
99
100 if xmlFile == 0 then
101 return false
102 end
103 while true do
104 local moduleNameKey = string.format("%s.modules.module(%d)#name", key, i)
105 if not hasXMLProperty(xmlFile, moduleNameKey) then
106 break
107 end
108 local moduleName = getXMLString(xmlFile, moduleNameKey)
109 local newModule = HusbandryModuleBase.createModule(moduleName)
110
111 if newModule ~= nil then
112 local moduleConfigKey = string.format("%s.modules.module(%d).config", key, i)
113 local success = newModule:load(xmlFile, moduleConfigKey, self.nodeId, self, self.baseDirectory)
114
115 if not success then
116 return false
117 end
118
119 self.modulesByName[moduleName] = newModule
120 newModule.moduleName = moduleName
121
122 table.insert(self.modulesById, newModule)
123 end
124 i = i + 1
125 end
126 delete(xmlFile)
127 return true
128end

minuteChanged

Description
Called by the environment when an hour has changed. Updates: egg production, straw usage, food usage, production, animal reproduction, dirt, water usage, manure and pallet
Definition
minuteChanged()
Code
353function AnimalHusbandry:minuteChanged(minute)
354 if minute % 15 == 0 then
355 for _, moduleInstance in pairs(self.modulesById) do
356 moduleInstance:onQuarterHourChanged()
357 end
358
359 if self:getNumOfAnimals() > 0 then
360 if self.isServer then
361 local dayInterval = 1 / (24 * 4)
362
363 self:onIntervalModulesUpdate(dayInterval)
364 self:updateGlobalProductionFactor()
365 self:raiseDirtyFlags(self.husbandryDirtyFlag)
366 end
367 end
368 end
369end

modulesFinalizePlacement

Description
Definition
modulesFinalizePlacement()
Return Values
boolreturnstrue if module init after placement is fine
Code
133function AnimalHusbandry:modulesFinalizePlacement()
134 for _, moduleInstance in pairs(self.modulesById) do
135 local success = moduleInstance:finalizePlacement()
136 if success ~= true then
137 return false
138 end
139 end
140 return true
141end

new

Description
Creating instance and initializing member variables
Definition
new(boolean isServer, boolean isClient, table mt)
Arguments
booleanisServeris server
booleanisClientis client
tablemtcustom meta table
Return Values
tableinstanceInstance of object
Code
40function AnimalHusbandry:new(isServer, isClient, mt)
41 if mt == nil then
42 mt = AnimalHusbandry_mt
43 end
44 local self = Placeable:new(isServer, isClient, mt)
45
46 self.useMultiRootNode = true
47 self.modulesByName = {}
48 self.modulesById = {}
49 -- husbandry information
50 self.updateMinutes = 0
51 self.saveId = ""
52 self.hasStatistics = false
53 self.husbandryDirtyFlag = self:getNextDirtyFlag()
54
55 -- productivity
56 self.globalProductionFactor = 0.0
57
58 registerObjectClassName(self, "AnimalHusbandry")
59
60 return self
61end

onIntervalModulesUpdate

Description
Update method for modules called when an interval has passed
Definition
onIntervalModulesUpdate(float dayInterval)
Arguments
floatdayInterval
Code
345function AnimalHusbandry:onIntervalModulesUpdate(dayInterval)
346 for _, moduleInstance in pairs(self.modulesById) do
347 moduleInstance:onIntervalUpdate(dayInterval)
348 end
349end

onSell

Description
Called on sell
Definition
onSell()
Code
190function AnimalHusbandry:onSell()
191 AnimalHusbandry:superClass().onSell(self)
192
193 for i = #self.modulesById, 1, -1 do
194 self.modulesById[i]:onSell()
195 end
196
197 if self.isServer then
198 g_currentMission.environment:removeMinuteChangeListener(self)
199 g_currentMission.environment:removeHourChangeListener(self)
200 g_currentMission.environment:removeDayChangeListener(self)
201 end
202end

readStream

Description
Reads network stream
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
Code
270function AnimalHusbandry:readStream(streamId, connection)
271 AnimalHusbandry:superClass().readStream(self, streamId, connection)
272
273 if connection:getIsServer() then
274 for _, moduleInstance in ipairs(self.modulesById) do
275 moduleInstance:readStream(streamId, connection)
276 end
277 end
278end

readUpdateStream

Description
Read updates from network stream
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdnetwork stream identification
integertimestamp
tableconnectionconnection information
Code
298function AnimalHusbandry:readUpdateStream(streamId, timestamp, connection)
299 AnimalHusbandry:superClass().readUpdateStream(self, streamId, timestamp, connection)
300
301 if connection:getIsServer() then
302 if streamReadBool(streamId) then
303 for _, moduleInstance in ipairs(self.modulesById) do
304 moduleInstance:readUpdateStream(streamId, timestamp, connection)
305 end
306 self.globalProductionFactor = streamReadFloat32(streamId)
307 end
308 end
309end

registerHusbandryToMission

Description
Registers the husbandry to the mission game.
Definition
registerHusbandryToMission()
Return Values
booltrueif registration went well
Code
679function AnimalHusbandry:registerHusbandryToMission()
680 local animalsModule = self:getModuleByName("animals")
681 if animalsModule ~= nil then
682 local husbandryId = animalsModule.husbandryId
683 g_currentMission:registerHusbandry(husbandryId, self)
684 return true
685 end
686 return false
687end

removeAnimals

Description
Registers the husbandry to the mission game.
Definition
removeAnimals()
Code
794function AnimalHusbandry:removeAnimals(animals)
795 local animalsModule = self:getModuleByName("animals")
796
797 if animalsModule ~= nil then
798 animalsModule:removeAnimals(animals)
799 end
800end

removeRideable

Description
Definition
removeRideable()
Code
824function AnimalHusbandry:removeRideable(visualId)
825 local animalsModule = self:getModuleByName("animals")
826
827 if animalsModule ~= nil then
828 animalsModule:removeRideable(visualId)
829 animalsModule:updateVisualDirt()
830 end
831end

removeSingleAnimal

Description
Registers the husbandry to the mission game.
Definition
removeSingleAnimal()
Code
804function AnimalHusbandry:removeSingleAnimal(animal)
805 local animalsModule = self:getModuleByName("animals")
806
807 if animalsModule ~= nil then
808 animalsModule:removeSingleAnimal(animal)
809 end
810end

renameAnimal

Description
Rename a visible animal identified by subtype and animal ID.
Definition
renameAnimal()
Code
923function AnimalHusbandry:renameAnimal(animalId, name, noEventSend)
924 local animalsModule = self:getModuleByName("animals")
925
926 if animalsModule ~= nil then
927 animalsModule:renameAnimal(animalId, name, noEventSend)
928 end
929end

setAnimalDirt

Description
Sets the dirt scale of an animal
Definition
setAnimalDirt()
Code
913function AnimalHusbandry:setAnimalDirt(animalId, dirtScale)
914 local animalsModule = self:getModuleByName("animals")
915
916 if animalsModule ~= nil then
917 animalsModule:setAnimalDirt(animalId, dirtScale)
918 end
919end

setModuleParameters

Description
Initializes capacity and daily usage parameters for the specified module. Called by the animal module
Definition
setModuleParameters(string moduleName, float capacity, float usagePerDay)
Arguments
stringmoduleName
floatcapacity
floatusagePerDay
Code
456function AnimalHusbandry:setModuleParameters(moduleName, capacity, usagePerDay)
457 local moduleInstance = self:getModuleByName(moduleName)
458
459 if moduleInstance ~= nil then
460 moduleInstance:setCapacity(capacity)
461 moduleInstance:setSingleAnimalUsagePerDay(usagePerDay)
462 end
463end

unregisterHusbandryToMission

Description
Registers the husbandry to the mission game.
Definition
unregisterHusbandryToMission()
Return Values
booltrueif registration went well
Code
692function AnimalHusbandry:unregisterHusbandryToMission()
693 local animalsModule = self:getModuleByName("animals")
694
695 if animalsModule ~= nil then
696 local husbandryId = animalsModule.husbandryId
697 if husbandryId ~= nil then
698 g_currentMission:unregisterHusbandry(husbandryId)
699 return true
700 end
701 end
702 return false
703end

updateGlobalProductionFactor

Description
Definition
updateGlobalProductionFactor()
Code
385function AnimalHusbandry:updateGlobalProductionFactor()
386 self.globalProductionFactor = 0.0
387 if self:hasWater() then
388 local foodFactor = self:getFoodProductionFactor()
389 -- animals need at least food and water to be productive!
390 if foodFactor > 0 then
391 if self:hasStraw() then
392 self.globalProductionFactor = 0.1
393 end
394 local foodSpillageFactor = self:getFoodSpillageFactor() or 1.0
395 self.globalProductionFactor = self.globalProductionFactor + (foodSpillageFactor * 0.1) + (foodFactor * 0.8)
396 end
397 -- test: self.globalProductionFactor = 1.0
398 end
399end

writeStream

Description
Writes network stream
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
Code
284function AnimalHusbandry:writeStream(streamId, connection)
285 AnimalHusbandry:superClass().writeStream(self, streamId, connection)
286 if not connection:getIsServer() then
287 for _, moduleInstance in ipairs(self.modulesById) do
288 moduleInstance:writeStream(streamId, connection)
289 end
290 end
291end

writeUpdateStream

Description
Write updates from network stream
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
integerdirtyMaskis used to check if we need to update
Code
316function AnimalHusbandry:writeUpdateStream(streamId, connection, dirtyMask)
317 AnimalHusbandry:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
318 if not connection:getIsServer() then
319 local isDirty = bitAND(dirtyMask, self.husbandryDirtyFlag) ~= 0
320 if streamWriteBool(streamId, isDirty) then
321 for _, moduleInstance in ipairs(self.modulesById) do
322 moduleInstance:writeUpdateStream(streamId, connection, dirtyMask)
323 end
324 streamWriteFloat32(streamId, self.globalProductionFactor)
325 end
326 end
327end