LUADOC - Farming Simulator 19

UnloadFeedingTrough

Parent
UnloadTrigger
Functions

addFillUnitFillLevel

Description
Changes fill levels from a tool
Definition
addFillUnitFillLevel(float deltaFillLevel, integer fillType, table fillInfo, integer toolType)
Arguments
floatdeltaFillLevel
integerfillType
tablefillInfo
integertoolType
Return Values
floatreturnsthe change delta
Code
102function UnloadFeedingTrough:addFillUnitFillLevel(farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData)
103 local foodMixture = g_animalFoodManager:getFoodMixtureByFillType(fillTypeIndex)
104 local delta = 0
105 if foodMixture ~= nil then
106 for _, ingredient in ipairs(foodMixture.ingredients) do
107 local ingredientFillType = ingredient.fillTypes[1]
108 local ingredientFillLevel = fillLevelDelta * ingredient.weight
109 delta = delta + UnloadFeedingTrough:superClass().addFillUnitFillLevel(self, farmId, fillUnitIndex, ingredientFillLevel, ingredientFillType, toolType, fillPositionData)
110 end
111 else
112 delta = UnloadFeedingTrough:superClass().addFillUnitFillLevel(self, farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData)
113 end
114
115 self:updateAnimalPlaces(delta)
116 return delta
117end

initFillTypesFromFoodGroups

Description
Setup fillTypes from animal food groups
Definition
initFillTypesFromFoodGroups(table foodGroups)
Arguments
tablefoodGroups
Code
82function UnloadFeedingTrough:initFillTypesFromFoodGroups(foodGroups)
83 self.fillTypes = {}
84 for _, foodGroup in pairs(foodGroups) do
85 for _, fillTypeIndex in pairs(foodGroup.fillTypes) do
86 self.fillTypes[fillTypeIndex] = true
87 end
88 end
89end

load

Description
Loads elements of the class
Definition
load(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Return Values
boolreturntrue if successful
Code
40function UnloadFeedingTrough:load(rootNode, xmlFile, xmlNode, target)
41 local returnValue = UnloadFeedingTrough:superClass().load(self, rootNode, xmlFile, xmlNode, target)
42
43 if returnValue then
44 self:loadAnimalPlaces(rootNode, xmlFile, xmlNode)
45 end
46 return returnValue
47end

loadAnimalPlaces

Description
Loads animal places
Definition
loadAnimalPlaces(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
54function UnloadFeedingTrough:loadAnimalPlaces(rootNode, xmlFile, xmlNode)
55 -- print(string.format("-- [UnloadFeedingTrough:loadAnimalPlaces] rootNode(%s) xmlFile(%s) xmlNode(%s)", tostring(rootNode), tostring(xmlFile), tostring(xmlNode)))
56 local animalPlacesNode = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "animalPlacesNode", getXMLString, rootNode)
57 if animalPlacesNode ~= nil then
58 local animalPlaces = I3DUtil.indexToObject(rootNode, animalPlacesNode)
59 -- print(string.format("-- [UnloadFeedingTrough:loadAnimalPlaces] animalPlacesNode(%s) animalPlaces(%s)", tostring(animalPlacesNode), tostring(animalPlaces)))
60 if animalPlaces ~= nil and self.target~= nil and self.target.husbandryId ~= nil then
61 for i = 1, getNumOfChildren(animalPlaces) do
62 local animalPlaceId = getChildAt(animalPlaces, i - 1)
63 local animalPlace = addFeedingPlace(self.target.husbandryId, animalPlaceId, 0.0)
64 table.insert(self.animalPlaces, animalPlace)
65 end
66 end
67 end
68end

loadFillTypes

Description
Overriding Unload Trigger method with empty method. The animal husbandry module is taking care of setting up the filltypes
Definition
loadFillTypes(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
75function UnloadFeedingTrough:loadFillTypes(rootNode, xmlFile, xmlNode)
76end

new

Description
Creates a new instance of the class
Definition
new(bool isServer, bool isClient, table customMt)
Arguments
boolisServertrue if we are server
boolisClienttrue if we are client
tablecustomMtmeta table
Return Values
tableselfreturns the instance
Code
25function UnloadFeedingTrough:new(isServer, isClient, customMt)
26 local self = UnloadTrigger:new(isServer, isClient, customMt or UnloadFeedingTrough_mt)
27
28 self.animalPlaces = {}
29 self.notAllowedWarningText = string.format(g_i18n:getText("warning_inAdvanceFeedingLimitReached"), HusbandryModuleAnimal.TROUGH_CAPACITY)
30
31 return self
32end

updateAnimalPlaces

Description
Changes animal places visuals
Definition
updateAnimalPlaces()
Code
121function UnloadFeedingTrough:updateAnimalPlaces(delta)
122 if delta ~= nil and delta > 0 then
123 for _, animalPlace in pairs(self.animalPlaces) do
124 updateFeedingPlace(self.target.husbandryId, animalPlace, delta)
125 end
126 end
127end