Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
PlaceableBeehive
DescriptionSpecialization for placeablesFunctions
- getBeehiveInfluenceFactor
- getHoneyAmountToSpawn
- onDelete
- onFinalizePlacement
- onLoad
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- registerXMLPaths
- updateBeehiveState
- updateInfo
getBeehiveInfluenceFactor
DescriptionReturns factor (0..1) on the impact of the beehive for given world location wx wz factor is linear based on beehive action radiusDefinition
getBeehiveInfluenceFactor()Code
117 | function 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 |
126 | end |
getHoneyAmountToSpawn
DescriptionDefinitiongetHoneyAmountToSpawn()Code
152 | function 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 |
161 | end |
onDelete
DescriptionDefinitiononDelete()Code
95 | function 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) |
101 | end |
onFinalizePlacement
DescriptionDefinitiononFinalizePlacement()Code
105 | function 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() |
112 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
60 | function 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 |
91 | end |
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
18 | function PlaceableBeehive.prerequisitesPresent(specializations) |
19 | return true |
20 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
38 | function PlaceableBeehive.registerEventListeners(placeableType) |
39 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableBeehive) |
40 | SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableBeehive) |
41 | SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableBeehive) |
42 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
24 | function PlaceableBeehive.registerFunctions(placeableType) |
25 | SpecializationUtil.registerFunction(placeableType, "getBeehiveInfluenceFactor", PlaceableBeehive.getBeehiveInfluenceFactor) |
26 | SpecializationUtil.registerFunction(placeableType, "updateBeehiveState", PlaceableBeehive.updateBeehiveState) |
27 | SpecializationUtil.registerFunction(placeableType, "getHoneyAmountToSpawn", PlaceableBeehive.getHoneyAmountToSpawn) |
28 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
32 | function PlaceableBeehive.registerOverwrittenFunctions(placeableType) |
33 | SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableBeehive.updateInfo) |
34 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
46 | function 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() |
55 | end |
updateBeehiveState
DescriptionDefinitionupdateBeehiveState()Code
130 | function 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 |
148 | end |
updateInfo
DescriptionDefinitionupdateInfo()Code
165 | function 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 |
180 | end |