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
PlaceableHotspots
DescriptionSpecialization for placeablesFunctions
- getHotspot
- onDelete
- onLoad
- onOwnerChanged
- onPostFinalizePlacement
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerXMLPaths
getHotspot
DescriptionDefinitiongetHotspot()Code
145 | function PlaceableHotspots:getHotspot(index) |
146 | local spec = self.spec_hotspots |
147 | return spec.mapHotspots[index or 1] |
148 | end |
onDelete
DescriptionDefinitiononDelete()Code
106 | function PlaceableHotspots:onDelete() |
107 | local spec = self.spec_hotspots |
108 | |
109 | g_messageCenter:unsubscribeAll(self) |
110 | if spec.mapHotspots ~= nil then |
111 | for _, hotspot in ipairs(spec.mapHotspots) do |
112 | g_currentMission:removeMapHotspot(hotspot) |
113 | hotspot:delete() |
114 | end |
115 | end |
116 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
53 | function PlaceableHotspots:onLoad(savegame) |
54 | local spec = self.spec_hotspots |
55 | |
56 | spec.mapHotspots = {} |
57 | self.xmlFile:iterate("placeable.hotspots.hotspot", function(_, key) |
58 | local hotspot = PlaceableHotspot.new() |
59 | hotspot:setPlaceable(self) |
60 | |
61 | local hotspotTypeName = self.xmlFile:getValue(key .. "#type", "UNLOADING") |
62 | local hotspotType = PlaceableHotspot.getTypeByName(hotspotTypeName) |
63 | if hotspotType == nil then |
64 | Logging.xmlWarning(self.xmlFile, "Unknown placeable hotspot type '%s'. Falling back to type 'UNLOADING'\nAvailable types: %s", hotspotTypeName, table.concatKeys(PlaceableHotspot.TYPE, " ")) |
65 | hotspotType = PlaceableHotspot.TYPE.UNLOADING |
66 | end |
67 | hotspot:setPlaceableType(hotspotType) |
68 | |
69 | local linkNode = self.xmlFile:getValue(key .. "#linkNode", nil, self.components, self.i3dMappings) or self.rootNode |
70 | if linkNode ~= nil then |
71 | local x, _, z = getWorldTranslation(linkNode) |
72 | hotspot:setWorldPosition(x, z) |
73 | end |
74 | |
75 | local teleportNode = self.xmlFile:getValue(key .. "#teleportNode", nil, self.components, self.i3dMappings) |
76 | if teleportNode ~= nil then |
77 | local x, y, z = getWorldTranslation(teleportNode) |
78 | hotspot:setTeleportWorldPosition(x, y, z) |
79 | end |
80 | |
81 | local worldPositionX, worldPositionZ = self.xmlFile:getValue(key .. "#worldPosition", nil) |
82 | if worldPositionX ~= nil then |
83 | hotspot:setWorldPosition(worldPositionX, worldPositionZ) |
84 | end |
85 | |
86 | local teleportX, teleportY, teleportZ = self.xmlFile:getValue(key .. "#teleportWorldPosition", nil) |
87 | if teleportX ~= nil then |
88 | if g_currentMission ~= nil then |
89 | teleportY = math.max(teleportY, getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, teleportX, 0, teleportZ)) |
90 | end |
91 | hotspot:setTeleportWorldPosition(teleportX, teleportY, teleportZ) |
92 | end |
93 | |
94 | local text = self.xmlFile:getValue(key.."#text", nil) |
95 | if text ~= nil then |
96 | text = g_i18n:convertText(text, self.customEnvironment) |
97 | hotspot:setName(text) |
98 | end |
99 | |
100 | table.insert(spec.mapHotspots, hotspot) |
101 | end) |
102 | end |
onOwnerChanged
DescriptionDefinitiononOwnerChanged()Code
133 | function PlaceableHotspots:onOwnerChanged() |
134 | local spec = self.spec_hotspots |
135 | if spec.mapHotspots ~= nil then |
136 | for _, hotspot in ipairs(spec.mapHotspots) do |
137 | hotspot:setOwnerFarmId(self.ownerFarmId) |
138 | hotspot:setVisible(self.ownerFarmId ~= AccessHandler.NOBODY) |
139 | end |
140 | end |
141 | end |
onPostFinalizePlacement
DescriptionDefinitiononPostFinalizePlacement()Code
120 | function PlaceableHotspots:onPostFinalizePlacement() |
121 | local spec = self.spec_hotspots |
122 | |
123 | -- Add now so that the hotspot does not show up during placement |
124 | for _, hotspot in ipairs(spec.mapHotspots) do |
125 | hotspot:setOwnerFarmId(self.ownerFarmId) |
126 | hotspot:setVisible(self.ownerFarmId ~= AccessHandler.NOBODY) |
127 | g_currentMission:addMapHotspot(hotspot) |
128 | end |
129 | 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 PlaceableHotspots.prerequisitesPresent(specializations) |
19 | return true |
20 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
30 | function PlaceableHotspots.registerEventListeners(placeableType) |
31 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableHotspots) |
32 | SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableHotspots) |
33 | SpecializationUtil.registerEventListener(placeableType, "onPostFinalizePlacement", PlaceableHotspots) |
34 | SpecializationUtil.registerEventListener(placeableType, "onOwnerChanged", PlaceableHotspots) |
35 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
24 | function PlaceableHotspots.registerFunctions(placeableType) |
25 | SpecializationUtil.registerFunction(placeableType, "getHotspot", PlaceableHotspots.getHotspot) |
26 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
39 | function PlaceableHotspots.registerXMLPaths(schema, basePath) |
40 | schema:setXMLSpecializationType("Hotspots") |
41 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".hotspots.hotspot(?)#linkNode", "Node where hotspot is linked to") |
42 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".hotspots.hotspot(?)#teleportNode", "Node where player is teleported to. Teleporting is only available if this is set") |
43 | schema:register(XMLValueType.STRING, basePath .. ".hotspots.hotspot(?)#type", "Placeable hotspot type") |
44 | schema:register(XMLValueType.VECTOR_2, basePath .. ".hotspots.hotspot(?)#worldPosition", "Placeable world position") |
45 | schema:register(XMLValueType.VECTOR_3, basePath .. ".hotspots.hotspot(?)#teleportWorldPosition", "Placeable teleport world position") |
46 | schema:register(XMLValueType.STRING, basePath .. ".hotspots.hotspot(?)#text", "Placeable hotspot text") |
47 | schema:setXMLSpecializationType() |
48 | end |