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
- AIConveyorBelt
- AIDrivable
- AIFieldWorker
- AIImplement
- AIJobVehicle
- AIVehicle
- AIVehicleObstacle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- AutoLoader
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BigBag
- BunkerSiloCompacter
- BunkerSiloInteractor
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- CropSensor
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- ExtendedAIVehicle
- ExtendedCombine
- ExtendedMotorized
- ExtendedMower
- ExtendedSowingMachine
- ExtendedSprayer
- ExtendedWearable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- HeadlandAnimation
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- InlineWrapper
- JigglingParts
- Leveler
- LicensePlates
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- ManureSensor
- MixerWagon
- Motorized
- Mountable
- Mower
- Mulcher
- MultipleItemPurchase
- Pallet
- Pickup
- Pipe
- PlaceableAI
- PlaceableAnimatedObjects
- PlaceableBeehive
- PlaceableBeehivePalletSpa...
- PlaceableBunkerSilo
- PlaceableBuyingStation
- PlaceableCartridgePlayer
- PlaceableChargingStation
- PlaceableClearAreas
- PlaceableColorable
- PlaceableDeletedNodes
- PlaceableDoghouse
- PlaceableDynamicallyLoade...
- PlaceableFarmhouse
- PlaceableFence
- PlaceableFoliageAreas
- PlaceableGreenhouse
- PlaceableHighPressureWash...
- PlaceableHotspots
- PlaceableHusbandry
- PlaceableHusbandryAnimals
- PlaceableHusbandryFeeding...
- PlaceableHusbandryFence
- PlaceableHusbandryFood
- PlaceableHusbandryLiquidM...
- PlaceableHusbandryMilk
- PlaceableHusbandryPallets
- PlaceableHusbandryStraw
- PlaceableHusbandryWater
- PlaceableIncomePerHour
- PlaceableIndoorAreas
- PlaceableInfoTrigger
- PlaceableLeveling
- PlaceableLights
- PlaceableManureHeap
- PlaceablePlacement
- PlaceableProductionPoint
- PlaceableSellingStation
- PlaceableSilo
- PlaceableSiloExtension
- PlaceableSolarPanels
- PlaceableTipOcclusionArea...
- PlaceableTrainSystem
- PlaceableTriggerMarkers
- PlaceableVine
- PlaceableWardrobe
- PlaceableWeatherStation
- PlaceableWeighingStation
- PlaceableWindTurbine
- PlaceableWorkshop
- Plow
- PlowPacker
- PowerConsumer
- PowerTakeOffs
- PrecisionFarmingStatistic
- PushHandTool
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- RTKStation
- SaltSpreader
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SoilSampler
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StonePicker
- StrawBlower
- StumpCutter
- SupportVehicle
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TestAreas
- TipOccluder
- Trailer
- TreePlanter
- TreeSaplingPallet
- TreeSaw
- TurnOnVehicle
- VariableWorkWidth
- VehicleSettings
- VineCutter
- VineDetector
- VinePrepruner
- Washable
- WaterTrailer
- Wearable
- Weeder
- WeedSpotSpray
- Wheels
- WindBending
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- 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
SplineVehicle
DescriptionSpecialization for vehicles driving on a spline only (e.g. train)Functions
- alignToSplineTime
- getAreSurfaceSoundsActive
- getCurrentSplinePosition
- getCurrentSurfaceSound
- getFrontToBackDistance
- getIsDischargeNodeActive
- getLastSpeed
- getSplinePositionAndTimeFromDistance
- getSplineTimeFromDistance
- initSpecialization
- loadDischargeNode
- onLoad
- onUpdate
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- setTrainSystem
alignToSplineTime
DescriptionDefinitionalignToSplineTime()Code
165 | function SplineVehicle:alignToSplineTime(spline, yOffset, tFront) |
166 | if self.trainSystem == nil then |
167 | return |
168 | end |
169 | |
170 | local spec = self.spec_splineVehicle |
171 | |
172 | local maxDiff = math.max(self.trainSystem:getLengthSplineTime(), 0.25) |
173 | |
174 | local delta = tFront - spec.splinePosition |
175 | if math.abs(delta) > maxDiff then |
176 | if delta > 0 then |
177 | delta = delta - 1 |
178 | else |
179 | delta = delta + 1 |
180 | end |
181 | end |
182 | |
183 | self.movingDirection = 1 |
184 | if delta < 0 then |
185 | self.movingDirection = -1 |
186 | end |
187 | |
188 | local p1x,p1y,p1z,t = self:getSplinePositionAndTimeFromDistance(tFront, spec.rootNodeToFrontDistance, -1.2*spec.rootNodeToFrontSplineTime) |
189 | |
190 | local wp1x,wp1y,wp1z = localToWorld(getParent(spline), p1x,p1y,p1z) |
191 | |
192 | local p2x,p2y,p2z, t2 = self:getSplinePositionAndTimeFromDistance(t, spec.dollyToDollyDistance, -1.2*spec.dollyToDollySplineTime) |
193 | |
194 | local wp2x,wp2y,wp2z = localToWorld(getParent(spline), p2x,p2y,p2z) |
195 | |
196 | setDirection(self.rootNode, wp1x-wp2x,wp1y-wp2y,wp1z-wp2z, 0,1,0) |
197 | local qx, qy, qz, qw = getWorldQuaternion(self.rootNode) |
198 | |
199 | setWorldTranslation(self.rootNode, wp1x, wp1y+yOffset, wp1z) |
200 | local networkInterpolators = self.components[1].networkInterpolators |
201 | networkInterpolators.quaternion:setQuaternion(qx, qy, qz, qw) |
202 | networkInterpolators.position:setPosition(wp1x, wp1y+yOffset, wp1z) |
203 | |
204 | if spec.alignDollys then |
205 | local d1x,d1y,d1z = getSplineDirection(spline, t) |
206 | local d2x,d2y,d2z = getSplineDirection(spline, t2) |
207 | |
208 | d1x,d1y,d1z = localDirectionToLocal(spline, getParent(spec.dolly1Node), d1x,d1y,d1z) |
209 | d2x,d2y,d2z = localDirectionToLocal(spline, getParent(spec.dolly2Node), d2x,d2y,d2z) |
210 | |
211 | setDirection(spec.dolly1Node, d1x,d1y,d1z, 0,1,0) |
212 | setDirection(spec.dolly2Node, d2x,d2y,d2z, 0,1,0) |
213 | end |
214 | |
215 | local interpDt = g_physicsDt |
216 | if g_server == nil then |
217 | -- on clients, we interpolate the vehicles with g_physicsDtUnclamped, thus we need to use the same for camera interpolation |
218 | interpDt = g_physicsDtUnclamped |
219 | end |
220 | |
221 | spec.splinePositionSpeedReal = delta * spec.trainSystem:getSplineLength() * (1000 / interpDt) |
222 | if self.isServer then |
223 | spec.splinePositionSpeed = spec.splinePositionSpeedReal |
224 | end |
225 | |
226 | spec.splinePosition = tFront |
227 | |
228 | if spec.firstUpdate then |
229 | spec.splinePositionSpeedReal = 0 |
230 | spec.splinePositionSpeed = 0 |
231 | spec.firstUpdate = false |
232 | end |
233 | |
234 | -- return spline time for backNode |
235 | local tBack = self:getSplineTimeFromDistance(tFront, spec.frontToBackDistance, -1.2*spec.frontToBackSplineTime) |
236 | return tBack |
237 | end |
getAreSurfaceSoundsActive
DescriptionDefinitiongetAreSurfaceSoundsActive()Code
253 | function SplineVehicle:getAreSurfaceSoundsActive(superFunc) |
254 | local rootVehicle = self.rootVehicle |
255 | if rootVehicle ~= nil then |
256 | return rootVehicle:getAreSurfaceSoundsActive() |
257 | end |
258 | |
259 | return true |
260 | end |
getCurrentSplinePosition
DescriptionDefinitiongetCurrentSplinePosition()Code
117 | function SplineVehicle:getCurrentSplinePosition() |
118 | return self.spec_splineVehicle.splinePosition |
119 | end |
getCurrentSurfaceSound
DescriptionDefinitiongetCurrentSurfaceSound()Code
247 | function SplineVehicle:getCurrentSurfaceSound() |
248 | return self.spec_wheels.surfaceNameToSound["railroad"] |
249 | end |
getFrontToBackDistance
DescriptionDefinitiongetFrontToBackDistance()Code
123 | function SplineVehicle:getFrontToBackDistance() |
124 | return self.spec_splineVehicle.frontToBackDistance |
125 | end |
getIsDischargeNodeActive
DescriptionDefinitiongetIsDischargeNodeActive()Code
276 | function SplineVehicle:getIsDischargeNodeActive(superFunc, dischargeNode) |
277 | if dischargeNode.needsIsEntered then |
278 | local rootVehicle = self:getRootVehicle() |
279 | if rootVehicle ~= nil and rootVehicle.getIsControlled ~= nil and not rootVehicle:getIsControlled() then |
280 | return false |
281 | end |
282 | end |
283 | |
284 | return superFunc(self, dischargeNode) |
285 | end |
getLastSpeed
DescriptionDefinitiongetLastSpeed()Code
241 | function SplineVehicle:getLastSpeed(superFunc, useAttacherVehicleSpeed) |
242 | return math.abs(self.spec_splineVehicle.splinePositionSpeed * 3.6) |
243 | end |
getSplinePositionAndTimeFromDistance
DescriptionDefinitiongetSplinePositionAndTimeFromDistance()Code
152 | function SplineVehicle:getSplinePositionAndTimeFromDistance(t, distance, stepSize) |
153 | |
154 | if self.trainSystem == nil then |
155 | return |
156 | end |
157 | |
158 | local positiveTimeOffset = stepSize >= 0 |
159 | local x,y,z, t2 = getSplinePositionWithDistance(self.trainSystem:getSpline(), t, distance, positiveTimeOffset, 0.01) |
160 | return x,y,z, SplineUtil.getValidSplineTime(t2) |
161 | end |
getSplineTimeFromDistance
DescriptionDefinitiongetSplineTimeFromDistance()Code
140 | function SplineVehicle:getSplineTimeFromDistance(t, distance, stepSize) |
141 | if self.trainSystem == nil then |
142 | return |
143 | end |
144 | |
145 | local positiveTimeOffset = stepSize >= 0 |
146 | local _,_,_, t2 = getSplinePositionWithDistance(self.trainSystem:getSpline(), t, distance, positiveTimeOffset, 0.01) |
147 | return SplineUtil.getValidSplineTime(t2) |
148 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
23 | function SplineVehicle.initSpecialization() |
24 | local schema = Vehicle.xmlSchema |
25 | schema:setXMLSpecializationType("SplineVehicle") |
26 | |
27 | schema:register(XMLValueType.NODE_INDEX, "vehicle.splineVehicle.dollies#frontNode", "Front node") |
28 | schema:register(XMLValueType.NODE_INDEX, "vehicle.splineVehicle.dollies#backNode", "Back node") |
29 | |
30 | schema:register(XMLValueType.NODE_INDEX, "vehicle.splineVehicle.dollies#dolly1Node", "Front dolly node") |
31 | schema:register(XMLValueType.NODE_INDEX, "vehicle.splineVehicle.dollies#dolly2Node", "Back dolly node") |
32 | |
33 | schema:register(XMLValueType.BOOL, "vehicle.splineVehicle.dollies#alignDollys", "Align dollies", true) |
34 | |
35 | schema:register(XMLValueType.BOOL, Dischargeable.DISCHARGE_NODE_XML_PATH .. "#needsIsEntered", "Vehicle needs to be entered to do raycasting", true) |
36 | schema:register(XMLValueType.BOOL, Dischargeable.DISCHARGE_NODE_CONFIG_XML_PATH .. "#needsIsEntered", "Vehicle needs to be entered to do raycasting", true) |
37 | |
38 | schema:setXMLSpecializationType() |
39 | end |
loadDischargeNode
DescriptionDefinitionloadDischargeNode()Code
264 | function SplineVehicle:loadDischargeNode(superFunc, xmlFile, key, entry) |
265 | if not superFunc(self, xmlFile, key, entry) then |
266 | return false |
267 | end |
268 | |
269 | entry.needsIsEntered = xmlFile:getValue(key.."#needsIsEntered", true) |
270 | |
271 | return true |
272 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
73 | function SplineVehicle:onLoad(savegame) |
74 | local spec = self.spec_splineVehicle |
75 | |
76 | spec.frontNode = self.xmlFile:getValue("vehicle.splineVehicle.dollies#frontNode", nil, self.components, self.i3dMappings) |
77 | spec.backNode = self.xmlFile:getValue("vehicle.splineVehicle.dollies#backNode", nil, self.components, self.i3dMappings) |
78 | |
79 | spec.frontToBackDistance = calcDistanceFrom(spec.frontNode, spec.backNode) |
80 | |
81 | spec.dolly1Node = self.xmlFile:getValue("vehicle.splineVehicle.dollies#dolly1Node", nil, self.components, self.i3dMappings) |
82 | spec.dolly2Node = self.xmlFile:getValue("vehicle.splineVehicle.dollies#dolly2Node", nil, self.components, self.i3dMappings) |
83 | |
84 | spec.dollyToDollyDistance = calcDistanceFrom(spec.dolly1Node, spec.dolly2Node) |
85 | |
86 | spec.rootNodeToBackDistance = calcDistanceFrom(spec.backNode, self.rootNode) |
87 | spec.rootNodeToFrontDistance = calcDistanceFrom(spec.frontNode, self.rootNode) |
88 | |
89 | spec.alignDollys = self.xmlFile:getValue("vehicle.splineVehicle.dollies#alignDollys", true) |
90 | spec.splinePosition = 0 |
91 | spec.lastSplinePosition = 0 |
92 | spec.currentSplinePosition = 0 |
93 | |
94 | spec.splinePositionSpeed = 0 |
95 | spec.splinePositionSpeedReal = 0 |
96 | |
97 | spec.splineSpeed = 0 |
98 | |
99 | spec.firstUpdate = true |
100 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
129 | function SplineVehicle:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
130 | if self.isClient then |
131 | local spec = self.spec_splineVehicle |
132 | if spec.trainSystem ~= nil then |
133 | spec.splinePositionSpeed = spec.splinePositionSpeed * 0.975 + spec.splinePositionSpeedReal * 0.025 |
134 | end |
135 | end |
136 | 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 |
17 | function SplineVehicle.prerequisitesPresent(specializations) |
18 | return true |
19 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
64 | function SplineVehicle.registerEventListeners(vehicleType) |
65 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", SplineVehicle) |
66 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", SplineVehicle) |
67 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
43 | function SplineVehicle.registerFunctions(vehicleType) |
44 | SpecializationUtil.registerFunction(vehicleType, "getFrontToBackDistance", SplineVehicle.getFrontToBackDistance) |
45 | SpecializationUtil.registerFunction(vehicleType, "getSplineTimeFromDistance", SplineVehicle.getSplineTimeFromDistance) |
46 | SpecializationUtil.registerFunction(vehicleType, "getSplinePositionAndTimeFromDistance", SplineVehicle.getSplinePositionAndTimeFromDistance) |
47 | SpecializationUtil.registerFunction(vehicleType, "alignToSplineTime", SplineVehicle.alignToSplineTime) |
48 | SpecializationUtil.registerFunction(vehicleType, "getCurrentSplinePosition", SplineVehicle.getCurrentSplinePosition) |
49 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
53 | function SplineVehicle.registerOverwrittenFunctions(vehicleType) |
54 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getLastSpeed", SplineVehicle.getLastSpeed) |
55 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "setTrainSystem", SplineVehicle.setTrainSystem) |
56 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCurrentSurfaceSound", SplineVehicle.getCurrentSurfaceSound) |
57 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAreSurfaceSoundsActive", SplineVehicle.getAreSurfaceSoundsActive) |
58 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsDischargeNodeActive", SplineVehicle.getIsDischargeNodeActive) |
59 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadDischargeNode", SplineVehicle.loadDischargeNode) |
60 | end |
setTrainSystem
DescriptionDefinitionsetTrainSystem()Code
104 | function SplineVehicle:setTrainSystem(superFunc, trainSystem) |
105 | superFunc(self, trainSystem) |
106 | |
107 | local spec = self.spec_splineVehicle |
108 | spec.splineLength = trainSystem:getSplineLength() |
109 | spec.frontToBackSplineTime = spec.frontToBackDistance / spec.splineLength |
110 | spec.dollyToDollySplineTime = spec.dollyToDollyDistance / spec.splineLength |
111 | spec.rootNodeToBackSplineTime = spec.rootNodeToBackDistance / spec.splineLength |
112 | spec.rootNodeToFrontSplineTime = spec.rootNodeToFrontDistance / spec.splineLength |
113 | end |