LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableIncomePerHour

Description
Specialization for placeables
Functions

getIncomePerHourFactor

Description
Definition
getIncomePerHourFactor()
Code
89function PlaceableIncomePerHour:getIncomePerHourFactor()
90 return 1
91end

getNeedHourChanged

Description
Definition
getNeedHourChanged()
Code
68function PlaceableIncomePerHour:getNeedHourChanged(superFunc)
69 return true
70end

getSpecValueIncomePerHour

Description
Returns value of income per hour
Definition
getSpecValueIncomePerHour(table storeItem, table realItem)
Arguments
tablestoreItemstore item
tablerealItemreal item
Return Values
integerincomePerHourincome per hour
Code
113function PlaceableIncomePerHour.getSpecValueIncomePerHour(storeItem, realItem)
114 if storeItem.specs.incomePerHour == nil then
115 return nil
116 end
117
118 local perMonth = storeItem.specs.incomePerHour * 24-- 24 hours in an un-adjusted month
119 return string.format("%s / %s", g_i18n:formatMoney(perMonth), g_i18n:getText("ui_month"))
120end

initSpecialization

Description
Definition
initSpecialization()
Code
51function PlaceableIncomePerHour.initSpecialization()
52 g_storeManager:addSpecType("incomePerHour", "shopListAttributeIconIncomePerHour", PlaceableIncomePerHour.loadSpecValueIncomePerHour, PlaceableIncomePerHour.getSpecValueIncomePerHour, "placeable")
53end

loadSpecValueIncomePerHour

Description
Loads capacity spec value
Definition
loadSpecValueIncomePerHour(integer xmlFile, string customEnvironment)
Arguments
integerxmlFileid of xml object
stringcustomEnvironmentcustom environment
Return Values
tablecapacityAndUnitcapacity and unit
Code
98function PlaceableIncomePerHour.loadSpecValueIncomePerHour(xmlFile, customEnvironment, baseDir)
99 if not xmlFile:hasProperty("placeable.incomePerHour") then
100 return nil
101 end
102
103 local incomePerHour = xmlFile:getValue("placeable.incomePerHour", 0)
104
105 return incomePerHour
106end

onHourChanged

Description
Called if hour changed
Definition
onHourChanged()
Code
74function PlaceableIncomePerHour:onHourChanged()
75 if self.isServer then
76 local ownerFarmId = self:getOwnerFarmId()
77 if ownerFarmId ~= FarmlandManager.NO_OWNER_FARM_ID then
78 local spec = self.spec_incomePerHour
79 local incomePerHour = spec.incomePerHour * self:getIncomePerHourFactor() * g_currentMission.environment.timeAdjustment
80 if incomePerHour ~= 0 then
81 g_currentMission:addMoney(incomePerHour, ownerFarmId, MoneyType.PROPERTY_INCOME, true)
82 end
83 end
84 end
85end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
58function PlaceableIncomePerHour:onLoad(savegame)
59 local spec = self.spec_incomePerHour
60 local xmlFile = self.xmlFile
61
62 spec.incomePerHour = xmlFile:getValue("placeable.incomePerHour", 0)
63 spec.incomePerHourFactor = 1
64end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
18function PlaceableIncomePerHour.prerequisitesPresent(specializations)
19 return true
20end

registerEventListeners

Description
Definition
registerEventListeners()
Code
36function PlaceableIncomePerHour.registerEventListeners(placeableType)
37 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableIncomePerHour)
38 SpecializationUtil.registerEventListener(placeableType, "onHourChanged", PlaceableIncomePerHour)
39end

registerFunctions

Description
Definition
registerFunctions()
Code
24function PlaceableIncomePerHour.registerFunctions(placeableType)
25 SpecializationUtil.registerFunction(placeableType, "getIncomePerHourFactor", PlaceableIncomePerHour.getIncomePerHourFactor)
26end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
30function PlaceableIncomePerHour.registerOverwrittenFunctions(placeableType)
31 SpecializationUtil.registerOverwrittenFunction(placeableType, "getNeedHourChanged", PlaceableIncomePerHour.getNeedHourChanged)
32end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
43function PlaceableIncomePerHour.registerXMLPaths(schema, basePath)
44 schema:setXMLSpecializationType("IncomePerHour")
45 schema:register(XMLValueType.FLOAT, basePath .. ".incomePerHour", "Income per hour")
46 schema:setXMLSpecializationType()
47end