Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
GroundReference
DescriptionSpecialization for determining if nodes are within a given distance threshold to the terrain/gorund.Functions
- getGroundReferenceNodeFromIndex
- getIsGroundReferenceNodeActive
- getIsSpeedRotatingPartActive
- getPowerMultiplier
- loadGroundReferenceNode
- loadSpeedRotatingPartFromXML
- onLoad
- onReadUpdateStream
- onUpdateTick
- onWriteUpdateStream
- prerequisitesPresent
- registerEventListeners
- registerEvents
- registerFunctions
- registerOverwrittenFunctions
- updateGroundReferenceNode
getGroundReferenceNodeFromIndex
DescriptionDefinitiongetGroundReferenceNodeFromIndex()Code
168 | function GroundReference:getGroundReferenceNodeFromIndex(refNodeIndex) |
169 | local spec = self.spec_groundReference |
170 | return spec.groundReferenceNodes[refNodeIndex] |
171 | end |
getIsGroundReferenceNodeActive
DescriptionDefinitiongetIsGroundReferenceNodeActive()Code
175 | function GroundReference:getIsGroundReferenceNodeActive(groundReferenceNode) |
176 | return groundReferenceNode.isActive |
177 | end |
getIsSpeedRotatingPartActive
DescriptionDefinitiongetIsSpeedRotatingPartActive()Code
227 | function GroundReference:getIsSpeedRotatingPartActive(superFunc, speedRotatingPart) |
228 | if speedRotatingPart.groundReferenceNodeIndex ~= nil then |
229 | local spec = self.spec_groundReference |
230 | |
231 | if spec.groundReferenceNodes[speedRotatingPart.groundReferenceNodeIndex] ~= nil then |
232 | if not spec.groundReferenceNodes[speedRotatingPart.groundReferenceNodeIndex].isActive then |
233 | return false |
234 | end |
235 | else |
236 | g_logManager:xmlWarning(self.configFileName, "Unknown ground reference node index '%d' for speed rotating part '%s'! Indices start with 1!", speedRotatingPart.groundReferenceNodeIndex, getName(speedRotatingPart.repr or speedRotatingPart.shaderNode)) |
237 | speedRotatingPart.groundReferenceNodeIndex = nil |
238 | end |
239 | end |
240 | |
241 | return superFunc(self, speedRotatingPart) |
242 | end |
getPowerMultiplier
DescriptionDefinitiongetPowerMultiplier()Code
181 | function GroundReference:getPowerMultiplier(superFunc) |
182 | local powerMultiplier = superFunc(self) |
183 | |
184 | local spec = self.spec_groundReference |
185 | if #(spec.groundReferenceNodes) > 0 then |
186 | local factor = 0 |
187 | if spec.hasForceFactors then |
188 | for _, refNode in ipairs(spec.groundReferenceNodes) do |
189 | if refNode.isActive then |
190 | factor = factor + refNode.forceFactor |
191 | end |
192 | end |
193 | else |
194 | for _, refNode in ipairs(spec.groundReferenceNodes) do |
195 | if refNode.isActive then |
196 | factor = refNode.chargeValue |
197 | end |
198 | end |
199 | end |
200 | |
201 | powerMultiplier = powerMultiplier * factor |
202 | end |
203 | return powerMultiplier |
204 | end |
loadGroundReferenceNode
DescriptionDefinitionloadGroundReferenceNode()Code
127 | function GroundReference:loadGroundReferenceNode(xmlFile, baseName, entry) |
128 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, baseName .. "#index", baseName .. "#node") --FS17 to FS19 |
129 | local spec = self.spec_groundReference |
130 | |
131 | local node = I3DUtil.indexToObject(self.components, getXMLString(xmlFile, baseName .. "#node"), self.i3dMappings) |
132 | if node ~= nil then |
133 | entry.node = node |
134 | entry.threshold = Utils.getNoNil(getXMLFloat(xmlFile, baseName .. "#threshold"), 0) |
135 | entry.chargeValue = Utils.getNoNil(getXMLFloat(xmlFile, baseName .. "#chargeValue"), 1) |
136 | entry.forceFactor = getXMLFloat(xmlFile, baseName .. "#forceFactor") |
137 | if entry.forceFactor ~= nil then |
138 | spec.hasForceFactors = true |
139 | end |
140 | entry.forceFactor = entry.forceFactor or 1 |
141 | entry.maxActivationDepth = Utils.getNoNil(getXMLFloat(xmlFile, baseName .. "#maxActivationDepth"), 10) -- maximum depth below the terrain -> prevents display in 3d shop |
142 | entry.isActive = false |
143 | return true |
144 | end |
145 | return false |
146 | end |
loadSpeedRotatingPartFromXML
DescriptionDefinitionloadSpeedRotatingPartFromXML()Code
209 | function GroundReference:loadSpeedRotatingPartFromXML(superFunc, speedRotatingPart, xmlFile, key) |
210 | if not superFunc(self, speedRotatingPart, xmlFile, key) then |
211 | return false |
212 | end |
213 | |
214 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, key.."#refNodeIndex", key.."#groundReferenceNodeIndex") -- FS17 to FS19 |
215 | |
216 | speedRotatingPart.groundReferenceNodeIndex = getXMLInt(xmlFile, key.."#groundReferenceNodeIndex") |
217 | |
218 | if speedRotatingPart.groundReferenceNodeIndex ~= nil and speedRotatingPart.groundReferenceNodeIndex == 0 then |
219 | g_logManager:xmlWarning(self.configFileName, "Unknown ground reference node index '%d' in '%s'! Indices start with 1!", speedRotatingPart.groundReferenceNodeIndex, key) |
220 | end |
221 | |
222 | return true |
223 | end |
onLoad
DescriptionDefinitiononLoad()Code
52 | function GroundReference:onLoad(savegame) |
53 | local spec = self.spec_groundReference |
54 | |
55 | spec.hasForceFactors = false |
56 | spec.groundReferenceNodes = {} |
57 | local i = 0 |
58 | while true do |
59 | local baseName = string.format("vehicle.groundReferenceNodes.groundReferenceNode(%d)", i) |
60 | if not hasXMLProperty(self.xmlFile, baseName) then |
61 | break |
62 | end |
63 | local entry = {} |
64 | if self:loadGroundReferenceNode(self.xmlFile, baseName, entry) then |
65 | table.insert(spec.groundReferenceNodes, entry) |
66 | end |
67 | i = i + 1 |
68 | end |
69 | |
70 | -- normalize chargeValues |
71 | -- deprecated: to be removed in FS21 |
72 | local totalCharge = 0 |
73 | for _, refNode in pairs(spec.groundReferenceNodes) do |
74 | totalCharge = totalCharge + refNode.chargeValue |
75 | end |
76 | if totalCharge > 0 then |
77 | for _, refNode in pairs(spec.groundReferenceNodes) do |
78 | refNode.chargeValue = refNode.chargeValue / totalCharge |
79 | end |
80 | end |
81 | |
82 | -- normalize forceFactors |
83 | local forceFactorSum = 0 |
84 | for _, refNode in pairs(spec.groundReferenceNodes) do |
85 | forceFactorSum = forceFactorSum + refNode.forceFactor |
86 | end |
87 | if forceFactorSum > 0 then |
88 | for _, refNode in pairs(spec.groundReferenceNodes) do |
89 | refNode.forceFactor = refNode.forceFactor / forceFactorSum |
90 | end |
91 | end |
92 | end |
onReadUpdateStream
DescriptionDefinitiononReadUpdateStream()Code
96 | function GroundReference:onReadUpdateStream(streamId, timestamp, connection) |
97 | local spec = self.spec_groundReference |
98 | if connection:getIsServer() then |
99 | for _,groundReferenceNode in ipairs(spec.groundReferenceNodes) do |
100 | groundReferenceNode.isActive = streamReadBool(streamId) |
101 | end |
102 | end |
103 | end |
onUpdateTick
DescriptionDefinitiononUpdateTick()Code
118 | function GroundReference:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
119 | local spec = self.spec_groundReference |
120 | for _,groundReferenceNode in ipairs(spec.groundReferenceNodes) do |
121 | self:updateGroundReferenceNode(groundReferenceNode) |
122 | end |
123 | end |
onWriteUpdateStream
DescriptionDefinitiononWriteUpdateStream()Code
107 | function GroundReference:onWriteUpdateStream(streamId, connection, dirtyMask) |
108 | local spec = self.spec_groundReference |
109 | if not connection:getIsServer() then |
110 | for _,groundReferenceNode in ipairs(spec.groundReferenceNodes) do |
111 | streamWriteBool(streamId, groundReferenceNode.isActive) |
112 | end |
113 | end |
114 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
15 | function GroundReference.prerequisitesPresent(specializations) |
16 | return true |
17 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
43 | function GroundReference.registerEventListeners(vehicleType) |
44 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", GroundReference) |
45 | SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", GroundReference) |
46 | SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", GroundReference) |
47 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", GroundReference) |
48 | end |
registerEvents
DescriptionDefinitionregisterEvents()Code
21 | function GroundReference.registerEvents(vehicleType) |
22 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
26 | function GroundReference.registerFunctions(vehicleType) |
27 | SpecializationUtil.registerFunction(vehicleType, "loadGroundReferenceNode", GroundReference.loadGroundReferenceNode) |
28 | SpecializationUtil.registerFunction(vehicleType, "updateGroundReferenceNode", GroundReference.updateGroundReferenceNode) |
29 | SpecializationUtil.registerFunction(vehicleType, "getGroundReferenceNodeFromIndex", GroundReference.getGroundReferenceNodeFromIndex) |
30 | SpecializationUtil.registerFunction(vehicleType, "getIsGroundReferenceNodeActive", GroundReference.getIsGroundReferenceNodeActive) |
31 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
35 | function GroundReference.registerOverwrittenFunctions(vehicleType) |
36 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getPowerMultiplier", GroundReference.getPowerMultiplier) |
37 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSpeedRotatingPartFromXML", GroundReference.loadSpeedRotatingPartFromXML) |
38 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSpeedRotatingPartActive", GroundReference.getIsSpeedRotatingPartActive) |
39 | end |
updateGroundReferenceNode
DescriptionDefinitionupdateGroundReferenceNode()Code
150 | function GroundReference:updateGroundReferenceNode(groundReferenceNode) |
151 | if self.isServer then |
152 | local x,y,z = getWorldTranslation(groundReferenceNode.node) |
153 | local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x,y,z) |
154 | |
155 | local terrainDiff = (terrainHeight + groundReferenceNode.threshold) - y |
156 | local terrainActiv = terrainDiff > 0 and terrainDiff < groundReferenceNode.maxActivationDepth |
157 | |
158 | local densityHeight, _ = DensityMapHeightUtil.getHeightAtWorldPos(x,y,z) |
159 | local densityDiff = (densityHeight + groundReferenceNode.threshold) - y |
160 | local densityActiv = densityDiff > 0 and densityDiff < groundReferenceNode.maxActivationDepth |
161 | |
162 | groundReferenceNode.isActive = terrainActiv or densityActiv |
163 | end |
164 | end |