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
AnimalHusbandry
DescriptionAnimal husbandry classParent
PlaceableXML Configuration Parameters
placeable.husbandry.animal#type | type of animal |
placeable.husbandry.animal#initialCount | initial number of animals to spawn |
placeable.husbandry.navmesh#index | navmesh node index |
placeable.husbandry.liquidManureTrigger#index | liquid manure trigger node index |
placeable.husbandry.fillLevelListeners#index | node index where the fill level listeners are located |
placeable.husbandry.placementRaycast#distance | distance for the placement raycast |
Functions
- addRideable
- addSingleAnimal
- canBuy
- collectPickObjects
- delete
- finalizePlacement
- getAnimalName
- getAnimals
- getAnimalSubTypeCount
- getAnimalType
- getCanBePlacedAt
- getConsumedFood
- getFilltype
- getFluidStatsText
- getFoodFilltypeInfo
- getFoodProductionFactor
- getFoodSpillageFactor
- getGlobalDirtFactor
- getGlobalProductionFactor
- getLiquidManureFilltypeInfo
- getManureFilltypeInfo
- getMilkFilltypeInfo
- getMinutesUntilNextAnimal
- getModuleById
- getModuleByName
- getNumOfAnimals
- getPalletsFilltypeInfo
- getProductionFilltypeInfo
- getReproductionTimePerDay
- getStrawFilltypeInfo
- getTypedAnimals
- getWaterFilltypeInfo
- hasStraw
- hasWater
- isRideableInOnHusbandryGround
- isSimilarHusbandryRegistered
- load
- loadFromXMLFile
- loadModules
- minuteChanged
- modulesFinalizePlacement
- new
- onIntervalModulesUpdate
- onSell
- readStream
- readUpdateStream
- registerHusbandryToMission
- removeAnimals
- removeRideable
- removeSingleAnimal
- renameAnimal
- setAnimalDirt
- setModuleParameters
- unregisterHusbandryToMission
- updateGlobalProductionFactor
- writeStream
- writeUpdateStream
addRideable
DescriptionDefinitionaddRideable()Code
814 | function AnimalHusbandry:addRideable(visualId, player) |
815 | local animalsModule = self:getModuleByName("animals") |
816 | |
817 | if animalsModule ~= nil then |
818 | animalsModule:addRideable(visualId, player) |
819 | end |
820 | end |
addSingleAnimal
DescriptionRegisters the husbandry to the mission game.Definition
addSingleAnimal()Code
776 | function AnimalHusbandry:addSingleAnimal(animal) |
777 | local animalsModule = self:getModuleByName("animals") |
778 | |
779 | if animalsModule ~= nil then |
780 | animalsModule:addSingleAnimal(animal) |
781 | end |
782 | end |
canBuy
DescriptionReturns true if we can place a buildingDefinition
canBuy()Return Values
bool |
154 | function AnimalHusbandry:canBuy() |
155 | local canBuy = AnimalHusbandry:superClass().canBuy(self) |
156 | return canBuy and self:canAddMoreHusbandriesToGame(), g_i18n:getText("warning_tooManyHusbandries") |
157 | end |
collectPickObjects
DescriptionCollect pick objectsDefinition
collectPickObjects(integer node)Arguments
integer | node | node id |
418 | function 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) |
427 | end |
delete
DescriptionDeletes instanceDefinition
delete()Code
206 | function 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) |
221 | end |
finalizePlacement
DescriptionCalled when player places the husbandry.Definition
finalizePlacement()Return Values
bool | returns | true if initialization is fine |
172 | function 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 |
186 | end |
getAnimalName
DescriptionRetrieves animal nameDefinition
getAnimalName()Code
933 | function AnimalHusbandry:getAnimalName(visualId) |
934 | local animalsModule = self:getModuleByName("animals") |
935 | |
936 | if animalsModule ~= nil then |
937 | return animalsModule:getAnimalName(visualId) |
938 | end |
939 | return "" |
940 | end |
getAnimals
DescriptionRegisters the husbandry to the mission game.Definition
getAnimals()Code
719 | function AnimalHusbandry:getAnimals() |
720 | local animalsModule = self:getModuleByName("animals") |
721 | |
722 | if animalsModule ~= nil then |
723 | return animalsModule:getAnimals() |
724 | end |
725 | end |
getAnimalSubTypeCount
DescriptionRegisters the husbandry to the mission game.Definition
getAnimalSubTypeCount()Code
707 | function 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 |
715 | end |
getAnimalType
DescriptionDefinitiongetAnimalType()Return Values
string | return | animal type. nil if not available |
480 | function AnimalHusbandry:getAnimalType() |
481 | local animalsModule = self:getModuleByName("animals") |
482 | |
483 | if animalsModule ~= nil then |
484 | return animalsModule:getAnimalType() |
485 | end |
486 | |
487 | return nil |
488 | end |
getCanBePlacedAt
DescriptionReturns true if we can place a buildingDefinition
getCanBePlacedAt()Return Values
bool |
146 | function AnimalHusbandry:getCanBePlacedAt(x, y, z, distance) |
147 | local canBePlaced = AnimalHusbandry:superClass().getCanBePlacedAt(self, x, y, z, distance) |
148 | return canBePlaced and self:canAddMoreHusbandriesToGame() |
149 | end |
getConsumedFood
DescriptionReturns the amount of food consumedDefinition
getConsumedFood()Return Values
table | of | cosumed food (result[fillTypeIndex]=amount) |
493 | function AnimalHusbandry:getConsumedFood() |
494 | local foodModule = self:getModuleByName("food") |
495 | |
496 | if foodModule ~= nil then |
497 | return foodModule:getConsumedFood() |
498 | end |
499 | return nil |
500 | end |
getFilltype
DescriptionDefinitiongetFilltype()Code
889 | function 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 |
897 | end |
getFluidStatsText
DescriptionFormat text to display fill levelDefinition
getFluidStatsText(float fillLevel, bool alwaysExact)Arguments
float | fillLevel | |
bool | alwaysExact | if true will change text accordingly |
string | fill | level |
406 | function 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 |
413 | end |
getFoodFilltypeInfo
DescriptionDefinitiongetFoodFilltypeInfo()Code
537 | function 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 |
544 | end |
getFoodProductionFactor
DescriptionDefinitiongetFoodProductionFactor()Code
504 | function AnimalHusbandry:getFoodProductionFactor() |
505 | local foodModule = self:getModuleByName("food") |
506 | |
507 | if foodModule ~= nil then |
508 | return foodModule:getFoodFactor() |
509 | end |
510 | return 0.0 |
511 | end |
getFoodSpillageFactor
DescriptionDefinitiongetFoodSpillageFactor()Code
632 | function AnimalHusbandry:getFoodSpillageFactor() |
633 | local foodSpillageModule = self:getModuleByName("foodSpillage") |
634 | |
635 | if foodSpillageModule ~= nil then |
636 | return foodSpillageModule:getSpillageFactor() |
637 | end |
638 | |
639 | return nil |
640 | end |
getGlobalDirtFactor
DescriptionDefinitiongetGlobalDirtFactor()Return Values
float | dirty | factor [0-1] |
902 | function AnimalHusbandry:getGlobalDirtFactor() |
903 | local animalsModule = self:getModuleByName("animals") |
904 | if animalsModule ~= nil then |
905 | return animalsModule:getDirtFactor() |
906 | end |
907 | |
908 | return 0 |
909 | end |
getGlobalProductionFactor
DescriptionDefinitiongetGlobalProductionFactor()Code
883 | function AnimalHusbandry:getGlobalProductionFactor() |
884 | return self.globalProductionFactor |
885 | end |
getLiquidManureFilltypeInfo
DescriptionDefinitiongetLiquidManureFilltypeInfo()Code
581 | function 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 |
588 | end |
getManureFilltypeInfo
DescriptionDefinitiongetManureFilltypeInfo()Code
592 | function 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 |
599 | end |
getMilkFilltypeInfo
DescriptionDefinitiongetMilkFilltypeInfo()Code
644 | function 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 |
651 | end |
getMinutesUntilNextAnimal
DescriptionDefinitiongetMinutesUntilNextAnimal()Code
955 | function 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 |
962 | end |
getModuleById
DescriptionDefinitiongetModuleById()Code
435 | function AnimalHusbandry:getModuleById(moduleId) |
436 | local moduleinstance = self.modulesById[moduleId] |
437 | |
438 | return moduleinstance |
439 | end |
getModuleByName
DescriptionDefinitiongetModuleByName()Code
443 | function 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 |
449 | end |
getNumOfAnimals
DescriptionDefinitiongetNumOfAnimals()Return Values
integer | total | animals. Default is zero |
468 | function AnimalHusbandry:getNumOfAnimals() |
469 | local animalsModule = self:getModuleByName("animals") |
470 | |
471 | if animalsModule ~= nil then |
472 | return animalsModule:getNumOfAnimals() |
473 | end |
474 | return 0 |
475 | end |
getPalletsFilltypeInfo
DescriptionDefinitiongetPalletsFilltypeInfo()Code
570 | function 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 |
577 | end |
getProductionFilltypeInfo
DescriptionGet 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
table | Production | fill type information as {i={j={fillType=fillType, fillLevel=fillLevel, capacity=capacity}}} |
606 | function 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 |
628 | end |
getReproductionTimePerDay
DescriptionDefinitiongetReproductionTimePerDay()Code
944 | function 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 |
951 | end |
getStrawFilltypeInfo
DescriptionDefinitiongetStrawFilltypeInfo()Code
559 | function 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 |
566 | end |
getTypedAnimals
DescriptionRegisters the husbandry to the mission game.Definition
getTypedAnimals()Code
729 | function AnimalHusbandry:getTypedAnimals() |
730 | local animalsModule = self:getModuleByName("animals") |
731 | |
732 | if animalsModule ~= nil then |
733 | return animalsModule:getTypedAnimals() |
734 | end |
735 | end |
getWaterFilltypeInfo
DescriptionDefinitiongetWaterFilltypeInfo()Code
548 | function 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 |
555 | end |
hasStraw
DescriptionDefinitionhasStraw()Code
515 | function AnimalHusbandry:hasStraw() |
516 | local strawModule = self:getModuleByName("straw") |
517 | |
518 | if strawModule ~= nil then |
519 | return strawModule:hasStraw() |
520 | end |
521 | return true |
522 | end |
hasWater
DescriptionDefinitionhasWater()Code
526 | function AnimalHusbandry:hasWater() |
527 | local waterModule = self:getModuleByName("water") |
528 | |
529 | if waterModule ~= nil then |
530 | return waterModule:hasWater() |
531 | end |
532 | return true |
533 | end |
isRideableInOnHusbandryGround
DescriptionDefinitionisRideableInOnHusbandryGround()Code
835 | function 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 |
842 | end |
isSimilarHusbandryRegistered
DescriptionReturns true if a husbandry with same animal type exists for the current farmIdDefinition
isSimilarHusbandryRegistered()Return Values
bool |
656 | function 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 |
670 | end |
load
DescriptionLoads information from xml file and registers the instance to the current MissionDefinition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, initRandom)Arguments
string | xmlFilename | XML filename |
float | x | world x position |
float | y | world y position |
float | z | world z position |
float | rx | x rotation in rad |
float | ry | y rotation in rad |
float | rz | z rotation in rad |
initRandom |
bool | returns | true if loading is fine |
74 | function 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 |
90 | end |
loadFromXMLFile
DescriptionLoads 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
table | xmlFile | XML file handler |
string | key | XML base key |
227 | function 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 |
248 | end |
loadModules
DescriptionLoads all modules declared in xml fileDefinition
loadModules(table xmlFile)Arguments
table | xmlFile | handle to the xml config file |
95 | function 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 |
128 | end |
minuteChanged
DescriptionCalled by the environment when an hour has changed. Updates: egg production, straw usage, food usage, production, animal reproduction, dirt, water usage, manure and palletDefinition
minuteChanged()Code
353 | function 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 |
369 | end |
modulesFinalizePlacement
DescriptionDefinitionmodulesFinalizePlacement()Return Values
bool | returns | true if module init after placement is fine |
133 | function 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 |
141 | end |
new
DescriptionCreating instance and initializing member variablesDefinition
new(boolean isServer, boolean isClient, table mt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | mt | custom meta table |
table | instance | Instance of object |
40 | function 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 |
61 | end |
onIntervalModulesUpdate
DescriptionUpdate method for modules called when an interval has passedDefinition
onIntervalModulesUpdate(float dayInterval)Arguments
float | dayInterval |
345 | function AnimalHusbandry:onIntervalModulesUpdate(dayInterval) |
346 | for _, moduleInstance in pairs(self.modulesById) do |
347 | moduleInstance:onIntervalUpdate(dayInterval) |
348 | end |
349 | end |
onSell
DescriptionCalled on sellDefinition
onSell()Code
190 | function 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 |
202 | end |
readStream
DescriptionReads network streamDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | network stream identification |
table | connection | connection information |
270 | function 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 |
278 | 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 |
298 | function 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 |
309 | end |
registerHusbandryToMission
DescriptionRegisters the husbandry to the mission game.Definition
registerHusbandryToMission()Return Values
bool | true | if registration went well |
679 | function 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 |
687 | end |
removeAnimals
DescriptionRegisters the husbandry to the mission game.Definition
removeAnimals()Code
794 | function AnimalHusbandry:removeAnimals(animals) |
795 | local animalsModule = self:getModuleByName("animals") |
796 | |
797 | if animalsModule ~= nil then |
798 | animalsModule:removeAnimals(animals) |
799 | end |
800 | end |
removeRideable
DescriptionDefinitionremoveRideable()Code
824 | function AnimalHusbandry:removeRideable(visualId) |
825 | local animalsModule = self:getModuleByName("animals") |
826 | |
827 | if animalsModule ~= nil then |
828 | animalsModule:removeRideable(visualId) |
829 | animalsModule:updateVisualDirt() |
830 | end |
831 | end |
removeSingleAnimal
DescriptionRegisters the husbandry to the mission game.Definition
removeSingleAnimal()Code
804 | function AnimalHusbandry:removeSingleAnimal(animal) |
805 | local animalsModule = self:getModuleByName("animals") |
806 | |
807 | if animalsModule ~= nil then |
808 | animalsModule:removeSingleAnimal(animal) |
809 | end |
810 | end |
renameAnimal
DescriptionRename a visible animal identified by subtype and animal ID.Definition
renameAnimal()Code
923 | function 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 |
929 | end |
setAnimalDirt
DescriptionSets the dirt scale of an animalDefinition
setAnimalDirt()Code
913 | function AnimalHusbandry:setAnimalDirt(animalId, dirtScale) |
914 | local animalsModule = self:getModuleByName("animals") |
915 | |
916 | if animalsModule ~= nil then |
917 | animalsModule:setAnimalDirt(animalId, dirtScale) |
918 | end |
919 | end |
setModuleParameters
DescriptionInitializes capacity and daily usage parameters for the specified module. Called by the animal moduleDefinition
setModuleParameters(string moduleName, float capacity, float usagePerDay)Arguments
string | moduleName | |
float | capacity | |
float | usagePerDay |
456 | function 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 |
463 | end |
unregisterHusbandryToMission
DescriptionRegisters the husbandry to the mission game.Definition
unregisterHusbandryToMission()Return Values
bool | true | if registration went well |
692 | function 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 |
703 | end |
updateGlobalProductionFactor
DescriptionDefinitionupdateGlobalProductionFactor()Code
385 | function 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 |
399 | end |
writeStream
DescriptionWrites network streamDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | network stream identification |
table | connection | connection information |
284 | function 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 |
291 | 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 |
316 | function 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 |
327 | end |