LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableBeehive

Description
Specialization for placeables
Functions

getBeehiveInfluenceFactor

Description
Returns factor (0..1) on the impact of the beehive for given world location wx wz factor is linear based on beehive action radius
Definition
getBeehiveInfluenceFactor()
Code
117function PlaceableBeehive:getBeehiveInfluenceFactor(wx, wz)
118 local spec = self.spec_beehive
119
120 local distanceToPointSquared = MathUtil.getPointPointDistanceSquared(spec.wx, spec.wz, wx, wz)
121 if distanceToPointSquared <= spec.actionRadiusSquared then
122 return 1 - (distanceToPointSquared * 0.85 / spec.actionRadiusSquared) -- reduce actual distance to increase returned factor
123 end
124
125 return 0
126end

getHoneyAmountToSpawn

Description
Definition
getHoneyAmountToSpawn()
Code
152function PlaceableBeehive:getHoneyAmountToSpawn()
153 local spec = self.spec_beehive
154 if spec.isProductionActive then
155 local hours = math.min(math.abs(((spec.environment.dayTime - spec.lastDayTimeHoneySpawned) / 1000 / 60 / 60)), 1) -- max should be one hour since since it called at least each hour
156 local amount = spec.honeyPerHour * hours * g_currentMission.environment.timeAdjustment
157 spec.lastDayTimeHoneySpawned = spec.environment.dayTime
158 return amount
159 end
160 return 0
161end

onDelete

Description
Definition
onDelete()
Code
95function PlaceableBeehive:onDelete()
96 local spec = self.spec_beehive
97 g_effectManager:deleteEffects(spec.effects)
98 g_soundManager:deleteSamples(spec.samples)
99
100 g_currentMission.beehiveSystem:removeBeehive(self)
101end

onFinalizePlacement

Description
Definition
onFinalizePlacement()
Code
105function PlaceableBeehive:onFinalizePlacement()
106 local spec = self.spec_beehive
107
108 spec.lastDayTimeHoneySpawned = spec.environment.dayTime
109 g_currentMission.beehiveSystem:addBeehive(self)
110
111 self:updateBeehiveState()
112end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
60function PlaceableBeehive:onLoad(savegame)
61 local spec = self.spec_beehive
62 local xmlFile = self.xmlFile
63
64 spec.environment = g_currentMission.environment
65
66 spec.isFxActive = false
67 spec.isProductionActive = false
68 spec.actionRadius = xmlFile:getFloat("placeable.beehive#actionRadius", 25)
69 spec.honeyPerHour = xmlFile:getFloat("placeable.beehive#litersHoneyPerDay", 10) / 24
70
71 -- info hud
72 spec.infoTableRange = {title=g_i18n:getText("infohud_range"), text=g_i18n:formatNumber(spec.actionRadius, 0) .. "m"}
73 spec.infoTableNoSpawnerA = {title=g_i18n:getText("infohud_beehive_noPalletLocationA"), accentuate=true}
74 spec.infoTableNoSpawnerB = {title=g_i18n:getText("infohud_beehive_noPalletLocationB"), accentuate=true}
75 spec.honeyAtPalletLocation = {title="", text=g_i18n:getText("infohud_beehive_honeyAtPalletLocation")}
76
77 -- store this information on load for more performant access during runtime
78 spec.actionRadiusSquared = spec.actionRadius^2
79 local wx, _, wz = getWorldTranslation(self.rootNode)
80 spec.wx, spec.wz = wx, wz
81
82 if self.isClient then
83 spec.effects = g_effectManager:loadEffect(xmlFile, "placeable.beehive.effects", self.components, self, self.i3dMappings)
84 g_effectManager:setFillType(spec.effects, FillType.UNKNOWN)
85
86 spec.samples = {}
87 spec.samples.idle = g_soundManager:loadSampleFromXML(xmlFile, "placeable.beehive.sounds", "idle", self.baseDirectory, self.components, 1, AudioGroup.ENVIRONMENT, self.i3dMappings, nil)
88 end
89
90 spec.lastDayTimeHoneySpawned = -1
91end

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 PlaceableBeehive.prerequisitesPresent(specializations)
19 return true
20end

registerEventListeners

Description
Definition
registerEventListeners()
Code
38function PlaceableBeehive.registerEventListeners(placeableType)
39 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableBeehive)
40 SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableBeehive)
41 SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableBeehive)
42end

registerFunctions

Description
Definition
registerFunctions()
Code
24function PlaceableBeehive.registerFunctions(placeableType)
25 SpecializationUtil.registerFunction(placeableType, "getBeehiveInfluenceFactor", PlaceableBeehive.getBeehiveInfluenceFactor)
26 SpecializationUtil.registerFunction(placeableType, "updateBeehiveState", PlaceableBeehive.updateBeehiveState)
27 SpecializationUtil.registerFunction(placeableType, "getHoneyAmountToSpawn", PlaceableBeehive.getHoneyAmountToSpawn)
28end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
32function PlaceableBeehive.registerOverwrittenFunctions(placeableType)
33 SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableBeehive.updateInfo)
34end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
46function PlaceableBeehive.registerXMLPaths(schema, basePath)
47 schema:setXMLSpecializationType("Beehive")
48
49 schema:register(XMLValueType.FLOAT, basePath .. ".beehive#actionRadius", "Bees action radius")
50 schema:register(XMLValueType.FLOAT, basePath .. ".beehive#litersHoneyPerDay", "Beehive honey production per active day")
51
52 EffectManager.registerEffectXMLPaths(schema, basePath .. ".beehive.effects")
53 SoundManager.registerSampleXMLPaths(schema, basePath .. ".beehive.sounds", "idle")
54 schema:setXMLSpecializationType()
55end

updateBeehiveState

Description
Definition
updateBeehiveState()
Code
130function PlaceableBeehive:updateBeehiveState()
131 local spec = self.spec_beehive
132 local beehiveSystem = g_currentMission.beehiveSystem
133 spec.isProductionActive = beehiveSystem.isProductionActive
134
135 if spec.isFxActive ~= beehiveSystem.isFxActive then
136 spec.isFxActive = beehiveSystem.isFxActive
137
138 if self.isClient then
139 if beehiveSystem.isFxActive then
140 g_effectManager:startEffects(spec.effects)
141 g_soundManager:playSample(spec.samples.idle, 0)
142 else
143 g_effectManager:stopEffects(spec.effects)
144 g_soundManager:stopSample(spec.samples.idle)
145 end
146 end
147 end
148end

updateInfo

Description
Definition
updateInfo()
Code
165function PlaceableBeehive:updateInfo(superFunc, infoTable)
166 local spec = self.spec_beehive
167 table.insert(infoTable, spec.infoTableRange)
168
169 local owner = self:getOwnerFarmId()
170 if owner == g_currentMission:getFarmId() then
171 local spawner = g_currentMission.beehiveSystem:getFarmBeehivePalletSpawner(owner)
172 if spawner == nil then
173 table.insert(infoTable, spec.infoTableNoSpawnerA)
174 table.insert(infoTable, spec.infoTableNoSpawnerB)
175 else
176 table.insert(infoTable, spec.honeyAtPalletLocation)
177 --TODO: spawner is full warning
178 end
179 end
180end