Script v1.4.4.0
- Handtools
- Events
- Objects
- Placeables
- Triggers
- Utils
- Vehicles
- Specializations
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BuiltInCutterTrailer
- BunkerSiloCompacter
- Combine
- ConveyorBelt
- Cover
- CrabSteering
- Crawler
- Cultivator
- Cutter
- Cylindered
- Drivable
- DynamicMountAttacher
- Fillable
- FillActivatable
- FillVolume
- Foldable
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- FuelTrailer
- Honk
- HookLiftContainer
- HookLiftTrailer
- Leveler
- Lights
- LivestockTrailer
- ManureBarrel
- ManureSpreader
- MixerWagon
- Motorized
- Mountable
- Mower
- NonTabbable
- Overloading
- Pickup
- Pipe
- Plough
- PowerConsumer
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- RidgeMarker
- Roller
- Ropes
- RotorSpreader
- SemiTrailerFront
- Shovel
- SowingMachine
- SpeedRotatingParts
- Sprayer
- Steerable
- StrawBlower
- StumpCutter
- Tedder
- TensionBelts
- Trailer
- TreePlanter
- TreePlanterActivatable
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Weeder
- WheelRotations
- Windrower
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkParticles
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
AttacherJointControl
DescriptionSpecialization to control the attacherJoint heightFunctions
- prerequisitesPresent
- preLoad
- load
- loadInputAttacherJoint
- readStream
- writeStream
- readUpdateStream
- writeUpdateStream
- update
- onAttach
- onDetach
- updateAttacherJoint
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 AttacherJointControl.prerequisitesPresent(specializations) |
18 | return SpecializationUtil.hasSpecialization(Attachable, specializations); |
19 | end; |
preLoad
DescriptionCalled before loadingDefinition
preLoad(table savegame)Arguments
table | savegame | savegame |
24 | function AttacherJointControl:preLoad(savegame) |
25 | self.loadInputAttacherJoint = Utils.overwrittenFunction(self.loadInputAttacherJoint, AttacherJointControl.loadInputAttacherJoint); |
26 | end; |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
31 | function AttacherJointControl:load(savegame) |
32 | |
33 | self.updateAttacherJoint = AttacherJointControl.updateAttacherJoint; |
34 | |
35 | self.attacherJointControl = {}; |
36 | |
37 | local uiScale = g_gameSettings:getValue("uiScale") |
38 | |
39 | self.attacherJointControl.controls = {}; |
40 | for i=1,2 do |
41 | local key = string.format("vehicle.attacherJointControl.control%d", i); |
42 | if not hasXMLProperty(self.xmlFile, key) then |
43 | break; |
44 | end |
45 | local control = {}; |
46 | |
47 | control.controlAxis = getXMLString(self.xmlFile, key .. "#controlAxis"); |
48 | |
49 | if control.controlAxis ~= nil then |
50 | control.controlActionIndex = InputBinding[control.controlAxis]; |
51 | if control.controlActionIndex ~= nil then |
52 | self:addConflictCheckedInput(control.controlActionIndex); |
53 | end |
54 | end |
55 | |
56 | control.invertControlAxis = Utils.getNoNil( getXMLString(self.xmlFile, key .. "#invertControlAxis"), false ); |
57 | control.mouseSpeedFactor = Utils.getNoNil( getXMLFloat(self.xmlFile, key .. "#mouseSpeedFactor"), 1.0 ); |
58 | |
59 | control.iconFilename = getXMLString(self.xmlFile, key .. "#controlAxisIcon"); |
60 | if control.iconFilename ~= nil then |
61 | local iconFilename = Utils.getFilename(control.iconFilename, self.baseDirectory); |
62 | local iconWidth, iconHeight = getNormalizedScreenValues(40*uiScale, 40*uiScale); |
63 | control.controlAxisIcon = Overlay:new("axisIcon", iconFilename, 0, 0, iconWidth, iconHeight); |
64 | control.controlAxisIcon:setAlignment(Overlay.ALIGN_VERTICAL_MIDDLE, Overlay.ALIGN_HORIZONTAL_LEFT); |
65 | end |
66 | |
67 | control.moveAlpha = 0; |
68 | control.moveAlphaSend = 0; |
69 | |
70 | table.insert(self.attacherJointControl.controls, control); |
71 | end |
72 | |
73 | self.lastDirtyTime = -10000; |
74 | |
75 | self.attacherJointControl.dirtyFlag = self:getNextDirtyFlag(); |
76 | |
77 | end; |
loadInputAttacherJoint
DescriptionCalled on loadingDefinition
loadInputAttacherJoint(table savegame)Arguments
table | savegame | savegame |
82 | function AttacherJointControl:loadInputAttacherJoint(superFunc, xmlFile, key, inputAttacherJoint, i) |
83 | if superFunc ~= nil then |
84 | if not superFunc(self, xmlFile, key, inputAttacherJoint, i) then |
85 | return false; |
86 | end |
87 | end; |
88 | |
89 | inputAttacherJoint.isControllable = Utils.getNoNil(getXMLBool(xmlFile, key .. "#isControllable"), false); |
90 | |
91 | return true; |
92 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
101 | function AttacherJointControl:readStream(streamId, connection) |
102 | if connection:getIsServer() then |
103 | if streamReadBool(streamId) then |
104 | local moveAlpha = {}; |
105 | for i=1,2 do |
106 | moveAlpha[i] = streamReadFloat32(streamId); |
107 | end |
108 | self:updateAttacherJoint(moveAlpha[1], moveAlpha[2]); |
109 | end |
110 | end |
111 | end; |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
117 | function AttacherJointControl:writeStream(streamId, connection) |
118 | if not connection:getIsServer() then |
119 | if streamWriteBool(streamId, self.attacherJointControl.jointDesc ~= nil) then |
120 | for i=1,2 do |
121 | streamWriteFloat32(streamId, self.attacherJointControl.controls[i].moveAlpha); |
122 | end |
123 | end |
124 | end |
125 | end; |
readUpdateStream
DescriptionCalled on on updateDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
132 | function AttacherJointControl:readUpdateStream(streamId, timestamp, connection) |
133 | if streamReadBool(streamId) then |
134 | local moveAlpha = {}; |
135 | for i=1,2 do |
136 | moveAlpha[i] = streamReadFloat32(streamId); |
137 | end |
138 | self:updateAttacherJoint(moveAlpha[1], moveAlpha[2]); |
139 | end |
140 | end |
writeUpdateStream
DescriptionCalled on on updateDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
147 | function AttacherJointControl:writeUpdateStream(streamId, connection, dirtyMask) |
148 | if streamWriteBool( streamId, bitAND(dirtyMask, self.attacherJointControl.dirtyFlag) ~= 0 and (connection:getIsServer() or connection ~= self:getOwner()) ) then |
149 | for i=1,2 do |
150 | streamWriteFloat32(streamId, self.attacherJointControl.controls[i].moveAlpha); |
151 | end |
152 | end |
153 | end |
update
DescriptionCalled on updateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
164 | function AttacherJointControl:update(dt) |
165 | |
166 | if self.attacherJointControl ~= nil and self.attacherJointControl.controls ~= nil and self.attacherJointControl.jointDesc ~= nil then |
167 | |
168 | if self.isClient and self:getIsActiveForInput(false) and not self:hasInputConflictWithSelection() and self.attacherJoint.isControllable then |
169 | |
170 | for i=1,2 do |
171 | local control = self.attacherJointControl.controls[i]; |
172 | |
173 | if control.controlActionIndex ~= nil then |
174 | if control.controlAxisIcon ~= nil then |
175 | g_currentMission:addHelpAxis(control.controlActionIndex, control.controlAxisIcon) |
176 | end |
177 | |
178 | local move, axisType = InputBinding.getInputAxis(control.controlActionIndex); |
179 | if control.invertControlAxis then |
180 | move = -move; |
181 | end |
182 | if axisType == InputBinding.INPUTTYPE_MOUSE_AXIS then |
183 | move = move * control.mouseSpeedFactor; |
184 | else |
185 | move = move * g_gameSettings:getValue("vehicleArmSensitivity") |
186 | end |
187 | |
188 | local isAxisZero = InputBinding.isAxisZero(move); |
189 | |
190 | if not isAxisZero then |
191 | local jointDesc = self.attacherJointControl.jointDesc; |
192 | |
193 | local moveAlpha = control.moveAlpha + (0.001 * dt * move); |
194 | control.moveAlpha = Utils.clamp(moveAlpha, jointDesc.upperAlpha, jointDesc.lowerAlpha); |
195 | end |
196 | end |
197 | end |
198 | |
199 | local isDirty = false; |
200 | for i=1,2 do |
201 | local control = self.attacherJointControl.controls[i]; |
202 | if control.moveAlphaSend ~= control.moveAlpha then |
203 | control.moveAlphaSend = control.moveAlpha; |
204 | isDirty = true; |
205 | end |
206 | end |
207 | if isDirty then |
208 | self:raiseDirtyFlags(self.attacherJointControl.dirtyFlag); |
209 | self:updateAttacherJoint(self.attacherJointControl.controls[1].moveAlpha, self.attacherJointControl.controls[2].moveAlpha); |
210 | self.lastDirtyTime = g_currentMission.time; |
211 | end |
212 | |
213 | if self:getIsActiveForSound() and self.attacherVehicle ~= nil and self.attacherVehicle.sampleHydraulic ~= nil and self.attacherVehicle.sampleHydraulic.sample ~= nil then |
214 | if math.abs(self.lastDirtyTime - g_currentMission.time) <= 125 then |
215 | if self.startedSample == nil then |
216 | SoundUtil.playSample(self.attacherVehicle.sampleHydraulic, 0, 0, nil); |
217 | self.attacherVehicle.sampleHydraulic.isPlaying = false; |
218 | self.startedSample = self.attacherVehicle.sampleHydraulic; |
219 | end |
220 | elseif self.startedSample ~= nil then |
221 | SoundUtil.stopSample(self.startedSample, true); |
222 | self.startedSample = nil; |
223 | end |
224 | end |
225 | |
226 | end |
227 | end; |
228 | end; |
onAttach
DescriptionCalled if vehicle gets attachedDefinition
onAttach(table attacherVehicle, integer jointDescIndex)Arguments
table | attacherVehicle | attacher vehicle |
integer | jointDescIndex | index of attacher joint it gets attached to |
240 | function AttacherJointControl:onAttach(attacherVehicle, jointDescIndex) |
241 | if attacherVehicle.attacherJoints[jointDescIndex] ~= nil then |
242 | for i=1,2 do |
243 | local control = self.attacherJointControl.controls[i]; |
244 | if control.controlActionIndex ~= nil then |
245 | if not self.attacherJoint.isControllable then |
246 | self:removeConflictCheckedInput(control.controlActionIndex); |
247 | else |
248 | self:addConflictCheckedInput(control.controlActionIndex); |
249 | end; |
250 | end |
251 | end |
252 | end |
253 | local jointDesc = attacherVehicle.attacherJoints[jointDescIndex] |
254 | jointDesc.allowsLoweringBackup = jointDesc.allowsLowering; |
255 | jointDesc.allowsLowering = false; |
256 | |
257 | self.attacherJointControl.jointDesc = jointDesc; |
258 | |
259 | --jnself.applyInitialRotation = true; |
260 | self.attacherJointControl.controls[1].moveAlpha = 0.5; |
261 | self.attacherJointControl.controls[2].moveAlpha = 0.5; |
262 | end |
onDetach
DescriptionCalled if vehicle gets detachedDefinition
onDetach(table attacherVehicle, integer jointDescIndex)Arguments
table | attacherVehicle | attacher vehicle |
integer | jointDescIndex | index of attacher joint it was attached to |
268 | function AttacherJointControl:onDetach(attacherVehicle, jointDescIndex) |
269 | self.attacherJointControl.jointDesc.allowsLowering = self.attacherJointControl.jointDesc.allowsLoweringBackup; |
270 | self.attacherJointControl.jointDesc = nil; |
271 | end |
updateAttacherJoint
DescriptionUpdates attacher joint move alpha and update joint frameDefinition
updateAttacherJoint(float moveAlpha1, float moveAlpha2)Arguments
float | moveAlpha1 | move alpha of rotation node 1 |
float | moveAlpha2 | move alpha of rotation node 2 |
277 | function AttacherJointControl:updateAttacherJoint(moveAlpha1, moveAlpha2) |
278 | local jointDesc = self.attacherJointControl.jointDesc; |
279 | |
280 | self.attacherJointControl.controls[1].moveAlpha = moveAlpha1; |
281 | self.attacherJointControl.controls[2].moveAlpha = moveAlpha2; |
282 | self.attacherJointControl.controls[1].moveAlphaSend = moveAlpha1; |
283 | self.attacherJointControl.controls[2].moveAlphaSend = moveAlpha2; |
284 | |
285 | if jointDesc ~= nil then |
286 | if jointDesc.rotationNode ~= nil then |
287 | setRotation(jointDesc.rotationNode, Utils.vector3ArrayLerp(jointDesc.upperRotation, jointDesc.lowerRotation, moveAlpha1)); |
288 | end |
289 | if jointDesc.rotationNode2 ~= nil then |
290 | setRotation(jointDesc.rotationNode2, Utils.vector3ArrayLerp(jointDesc.upperRotation2, jointDesc.lowerRotation2, moveAlpha2)); |
291 | end |
292 | self.attacherVehicle:updateAttacherJointRotation(jointDesc, self); |
293 | |
294 | if self.isServer and jointDesc.jointIndex ~= 0 then |
295 | setJointFrame(jointDesc.jointIndex, 0, jointDesc.jointTransform) |
296 | end |
297 | end |
298 | end |