Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- AIConveyorBelt
- AIImplement
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BunkerSiloCompacter
- BunkerSiloInteractor
- BuyableBale
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- JigglingParts
- Leveler
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- MixerWagon
- Motorized
- Mountable
- Mower
- Pickup
- Pipe
- Plow
- PowerConsumer
- PowerTakeOffs
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StrawBlower
- StumpCutter
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TipOccluder
- Trailer
- TreePlanter
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Wearable
- Weeder
- Wheels
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- 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
BaleGrab
DescriptionSpecialization for a balegrab tool adding soft attaching of balesFunctions
- addDynamicMountedObject
- addNodeObjectMapping
- baleGrabTriggerCallback
- isComponentJointOutsideLimit
- onDelete
- onLoad
- onUpdateTick
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- removeDynamicMountedObject
- removeNodeObjectMapping
addDynamicMountedObject
DescriptionAdd dynamic mount objectDefinition
addDynamicMountedObject(table object)Arguments
table | object | object |
138 | function BaleGrab:addDynamicMountedObject(object) |
139 | local spec = self.spec_baleGrab |
140 | spec.dynamicMountedObjects[object] = object |
141 | end |
addNodeObjectMapping
DescriptionDefinitionaddNodeObjectMapping()Code
214 | function BaleGrab:addNodeObjectMapping(superFunc, list) |
215 | superFunc(self, list) |
216 | |
217 | local spec = self.spec_baleGrab |
218 | if spec.dynamicMountAttacherTrigger ~= nil and spec.dynamicMountAttacherTrigger.triggerNode ~= nil then |
219 | list[spec.dynamicMountAttacherTrigger.triggerNode] = self |
220 | end |
221 | end |
baleGrabTriggerCallback
DescriptionTrigger callbackDefinition
baleGrabTriggerCallback(integer triggerId, integer otherActorId, boolean onEnter, boolean onLeave, boolean onStay, integer otherShapeId)Arguments
integer | triggerId | id of trigger |
integer | otherActorId | id of other actor |
boolean | onEnter | on enter |
boolean | onLeave | on leave |
boolean | onStay | on stay |
integer | otherShapeId | id of other shape |
163 | function BaleGrab:baleGrabTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
164 | local spec = self.spec_baleGrab |
165 | if onEnter then |
166 | local object = g_currentMission:getNodeObject(otherActorId) |
167 | if object == nil then |
168 | object = g_currentMission.nodeToObject[otherActorId] |
169 | end |
170 | if object ~= nil and object ~= self and object.getSupportsMountDynamic ~= nil and object:getSupportsMountDynamic() then |
171 | spec.pendingDynamicMountObjects[object] = Utils.getNoNil(spec.pendingDynamicMountObjects[object], 0) + 1 |
172 | end |
173 | elseif onLeave then |
174 | local object = g_currentMission:getNodeObject(otherActorId) |
175 | if object == nil then |
176 | object = g_currentMission.nodeToObject[otherActorId] |
177 | end |
178 | if object ~= nil then |
179 | if spec.pendingDynamicMountObjects[object] ~= nil then |
180 | local count = spec.pendingDynamicMountObjects[object]-1 |
181 | if count == 0 then |
182 | spec.pendingDynamicMountObjects[object] = nil |
183 | |
184 | if spec.dynamicMountedObjects[object] ~= nil then |
185 | self:removeDynamicMountedObject(object, false) |
186 | object:unmountDynamic() |
187 | end |
188 | else |
189 | spec.pendingDynamicMountObjects[object] = count |
190 | end |
191 | end |
192 | end |
193 | end |
194 | end |
isComponentJointOutsideLimit
DescriptionReturns if component joint is outside the rotation limitDefinition
isComponentJointOutsideLimit(integer componentJoint, float maxRot, float cosMaxRot)Arguments
integer | componentJoint | index of component joint |
float | maxRot | max rotation |
float | cosMaxRot | cos max rotation |
boolean | isOutside | is outside the rotation limit |
202 | function BaleGrab:isComponentJointOutsideLimit(componentJoint, maxRot, cosMaxRot) |
203 | local x,_,z = localDirectionToLocal(self.components[componentJoint.componentIndices[2]].node, componentJoint.jointNode, 0,0,1) |
204 | if (x >= 0) == (maxRot >= 0) then |
205 | if z <= cosMaxRot*math.sqrt(x*x + z*z) then |
206 | return true |
207 | end |
208 | end |
209 | return false |
210 | end |
onDelete
DescriptionCalled on deletingDefinition
onDelete()Code
87 | function BaleGrab:onDelete() |
88 | local spec = self.spec_baleGrab |
89 | if self.isServer then |
90 | for object,_ in pairs(spec.dynamicMountedObjects) do |
91 | object:unmountDynamic() |
92 | end |
93 | end |
94 | if spec.dynamicMountAttacherTrigger ~= nil then |
95 | removeTrigger(spec.dynamicMountAttacherTrigger.triggerNode) |
96 | end |
97 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
46 | function BaleGrab:onLoad(savegame) |
47 | local spec = self.spec_baleGrab |
48 | |
49 | if self.isServer then |
50 | local attacherTriggerTriggerNode = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.baleGrab#triggerNode"), self.i3dMappings) |
51 | local attacherTriggerRootNode = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.baleGrab#rootNode"), self.i3dMappings) |
52 | local attacherTriggerJointNode = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.baleGrab#jointNode"), self.i3dMappings) |
53 | local attacherJointTypeString = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.baleGrab#jointType"), "TYPE_AUTO_ATTACH_XYZ") |
54 | local attacherJointType = DynamicMountUtil.TYPE_AUTO_ATTACH_XYZ |
55 | if DynamicMountUtil[attacherJointTypeString] ~= nil then |
56 | attacherJointType = DynamicMountUtil[attacherJointTypeString] |
57 | end |
58 | |
59 | if attacherTriggerTriggerNode ~= nil and attacherTriggerRootNode ~= nil and attacherTriggerJointNode ~= nil then |
60 | local forceAcceleration = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.baleGrab#forceAcceleration"), 20) |
61 | addTrigger(attacherTriggerTriggerNode, "baleGrabTriggerCallback", self) |
62 | |
63 | local grabRefComponentJointIndex1 = getXMLInt(self.xmlFile, "vehicle.baleGrab#grabRefComponentJointIndex1") |
64 | local grabRefComponentJointIndex2 = getXMLInt(self.xmlFile, "vehicle.baleGrab#grabRefComponentJointIndex2") |
65 | local componentJoint1, componentJoint2 |
66 | if grabRefComponentJointIndex1 ~= nil then |
67 | componentJoint1 = self.componentJoints[grabRefComponentJointIndex1+1] |
68 | end |
69 | if grabRefComponentJointIndex2 ~= nil then |
70 | componentJoint2 = self.componentJoints[grabRefComponentJointIndex2+1] |
71 | end |
72 | local rotDiffThreshold1 = math.rad(Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.baleGrab#rotDiffThreshold1"), 2)) |
73 | local rotDiffThreshold2 = math.rad(Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.baleGrab#rotDiffThreshold2"), 2)) |
74 | spec.dynamicMountAttacherTrigger = { |
75 | triggerNode=attacherTriggerTriggerNode, rootNode=attacherTriggerRootNode, jointNode=attacherTriggerJointNode, attacherJointType=attacherJointType, forceAcceleration=forceAcceleration, |
76 | componentJoint1=componentJoint1, rotDiffThreshold1=rotDiffThreshold1, cosRotDiffThreshold1=math.cos(rotDiffThreshold1), |
77 | componentJoint2=componentJoint2, rotDiffThreshold2=rotDiffThreshold2, cosRotDiffThreshold2=math.cos(rotDiffThreshold2) |
78 | } |
79 | end |
80 | spec.dynamicMountedObjects = {} |
81 | spec.pendingDynamicMountObjects = {} |
82 | end |
83 | end |
onUpdateTick
DescriptionCalled on update tickDefinition
onUpdateTick(float dt, boolean isActiveForInput, boolean isSelected)Arguments
float | dt | time since last call in ms |
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
104 | function BaleGrab:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
105 | if self.isServer then |
106 | local spec = self.spec_baleGrab |
107 | local attachTrigger = spec.dynamicMountAttacherTrigger |
108 | |
109 | local isClosed = true |
110 | if attachTrigger.componentJoint1 ~= nil then |
111 | isClosed = self:isComponentJointOutsideLimit(attachTrigger.componentJoint1, attachTrigger.rotDiffThreshold1, attachTrigger.cosRotDiffThreshold1) |
112 | end |
113 | if isClosed and attachTrigger.componentJoint2 ~= nil then |
114 | isClosed = self:isComponentJointOutsideLimit(attachTrigger.componentJoint2, attachTrigger.rotDiffThreshold2, attachTrigger.cosRotDiffThreshold2) |
115 | end |
116 | if isClosed then |
117 | for object,_ in pairs(spec.pendingDynamicMountObjects) do |
118 | if spec.dynamicMountedObjects[object] == nil then |
119 | object:unmountDynamic() |
120 | local dynamicMountData = spec.dynamicMountAttacherTrigger |
121 | if object:mountDynamic(self, dynamicMountData.rootNode, dynamicMountData.jointNode, dynamicMountData.attacherJointType, dynamicMountData.forceAcceleration) then |
122 | self:addDynamicMountedObject(object) |
123 | end |
124 | end |
125 | end |
126 | else |
127 | for object,_ in pairs(spec.dynamicMountedObjects) do |
128 | self:removeDynamicMountedObject(object, false) |
129 | object:unmountDynamic() |
130 | end |
131 | end |
132 | end |
133 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
15 | function BaleGrab.prerequisitesPresent(specializations) |
16 | return true |
17 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
37 | function BaleGrab.registerEventListeners(vehicleType) |
38 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", BaleGrab) |
39 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", BaleGrab) |
40 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", BaleGrab) |
41 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
21 | function BaleGrab.registerFunctions(vehicleType) |
22 | SpecializationUtil.registerFunction(vehicleType, "baleGrabTriggerCallback", BaleGrab.baleGrabTriggerCallback) |
23 | SpecializationUtil.registerFunction(vehicleType, "addDynamicMountedObject", BaleGrab.addDynamicMountedObject) |
24 | SpecializationUtil.registerFunction(vehicleType, "removeDynamicMountedObject", BaleGrab.removeDynamicMountedObject) |
25 | SpecializationUtil.registerFunction(vehicleType, "isComponentJointOutsideLimit", BaleGrab.isComponentJointOutsideLimit) |
26 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
30 | function BaleGrab.registerOverwrittenFunctions(vehicleType) |
31 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "addNodeObjectMapping", BaleGrab.addNodeObjectMapping) |
32 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "removeNodeObjectMapping", BaleGrab.removeNodeObjectMapping) |
33 | end |
removeDynamicMountedObject
DescriptionRemove dynamic mount objectDefinition
removeDynamicMountedObject(table object, boolean isDeleting)Arguments
table | object | object |
boolean | isDeleting | is deleting |
147 | function BaleGrab:removeDynamicMountedObject(object, isDeleting) |
148 | local spec = self.spec_baleGrab |
149 | spec.dynamicMountedObjects[object] = nil |
150 | if isDeleting then |
151 | spec.pendingDynamicMountObjects[object] = nil |
152 | end |
153 | end |
removeNodeObjectMapping
DescriptionDefinitionremoveNodeObjectMapping()Code
225 | function BaleGrab:removeNodeObjectMapping(superFunc, list) |
226 | superFunc(self, list) |
227 | |
228 | local spec = self.spec_baleGrab |
229 | if spec.dynamicMountAttacherTrigger ~= nil and spec.dynamicMountAttacherTrigger.triggerNode ~= nil then |
230 | list[spec.dynamicMountAttacherTrigger.triggerNode] = nil |
231 | end |
232 | end |