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
BaleGrab
DescriptionSpecialization for a balegrab tool adding soft attaching of balesFunctions
- addDynamicMountedObject
- addNodeObjectMapping
- baleGrabTriggerCallback
- initSpecialization
- isComponentJointOutsideLimit
- mountBaleGrabObject
- onDelete
- onLoad
- onUpdateTick
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- removeDynamicMountedObject
- removeNodeObjectMapping
- unmountBaleGrabObject
addDynamicMountedObject
DescriptionAdd dynamic mount objectDefinition
addDynamicMountedObject(table object)Arguments
table | object | object |
160 | function BaleGrab:addDynamicMountedObject(object) |
161 | local spec = self.spec_baleGrab |
162 | spec.dynamicMountedObjects[object] = object |
163 | end |
addNodeObjectMapping
DescriptionDefinitionaddNodeObjectMapping()Code
260 | function BaleGrab:addNodeObjectMapping(superFunc, list) |
261 | superFunc(self, list) |
262 | |
263 | local spec = self.spec_baleGrab |
264 | if spec.dynamicMountAttacherTrigger ~= nil and spec.dynamicMountAttacherTrigger.triggerNode ~= nil then |
265 | list[spec.dynamicMountAttacherTrigger.triggerNode] = self |
266 | end |
267 | 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 |
185 | function BaleGrab:baleGrabTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
186 | local spec = self.spec_baleGrab |
187 | if onEnter then |
188 | local object = g_currentMission:getNodeObject(otherActorId) |
189 | if object == nil then |
190 | object = g_currentMission.nodeToObject[otherActorId] |
191 | end |
192 | if object ~= nil and object ~= self and object.getSupportsMountDynamic ~= nil and object:getSupportsMountDynamic() then |
193 | spec.pendingDynamicMountObjects[object] = Utils.getNoNil(spec.pendingDynamicMountObjects[object], 0) + 1 |
194 | end |
195 | elseif onLeave then |
196 | local object = g_currentMission:getNodeObject(otherActorId) |
197 | if object == nil then |
198 | object = g_currentMission.nodeToObject[otherActorId] |
199 | end |
200 | if object ~= nil then |
201 | if spec.pendingDynamicMountObjects[object] ~= nil then |
202 | local count = spec.pendingDynamicMountObjects[object]-1 |
203 | if count == 0 then |
204 | spec.pendingDynamicMountObjects[object] = nil |
205 | |
206 | if spec.dynamicMountedObjects[object] ~= nil then |
207 | self:unmountBaleGrabObject(object) |
208 | end |
209 | else |
210 | spec.pendingDynamicMountObjects[object] = count |
211 | end |
212 | end |
213 | end |
214 | end |
215 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
21 | function BaleGrab.initSpecialization() |
22 | local schema = Vehicle.xmlSchema |
23 | schema:setXMLSpecializationType("BaleGrab") |
24 | |
25 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleGrab#triggerNode", "Trigger node") |
26 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleGrab#rootNode", "Root node") |
27 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleGrab#jointNode", "Joint node") |
28 | schema:register(XMLValueType.STRING, "vehicle.baleGrab#jointType", "Joint type", "TYPE_AUTO_ATTACH_XYZ") |
29 | schema:register(XMLValueType.FLOAT, "vehicle.baleGrab#forceAcceleration", "Force acceleration", 20) |
30 | schema:register(XMLValueType.INT, "vehicle.baleGrab#grabRefComponentJointIndex1", "Component joint index of grab 1") |
31 | schema:register(XMLValueType.INT, "vehicle.baleGrab#grabRefComponentJointIndex2", "Component joint index of grab 2") |
32 | schema:register(XMLValueType.ANGLE, "vehicle.baleGrab#rotDiffThreshold1", "Rotation difference between component and joint to mount bale", 2) |
33 | schema:register(XMLValueType.ANGLE, "vehicle.baleGrab#rotDiffThreshold2", "Rotation difference between component and joint to mount bale", 2) |
34 | |
35 | schema:setXMLSpecializationType() |
36 | 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 |
223 | function BaleGrab:isComponentJointOutsideLimit(componentJoint, maxRot, cosMaxRot) |
224 | local x,_,z = localDirectionToLocal(self.components[componentJoint.componentIndices[2]].node, componentJoint.jointNode, 0,0,1) |
225 | if (x >= 0) == (maxRot >= 0) then |
226 | if z <= cosMaxRot*math.sqrt(x*x + z*z) then |
227 | return true |
228 | end |
229 | end |
230 | return false |
231 | end |
mountBaleGrabObject
DescriptionMounts a dynamic object to the bale grabDefinition
mountBaleGrabObject(table object)Arguments
table | object | object |
boolean | success | success |
237 | function BaleGrab:mountBaleGrabObject(object) |
238 | local dynamicMountData = self.spec_baleGrab.dynamicMountAttacherTrigger |
239 | if object:mountDynamic(self, dynamicMountData.rootNode, dynamicMountData.jointNode, dynamicMountData.attacherJointType, dynamicMountData.forceAcceleration) then |
240 | self:addDynamicMountedObject(object) |
241 | return true |
242 | end |
243 | |
244 | return false |
245 | end |
onDelete
DescriptionCalled on deletingDefinition
onDelete()Code
113 | function BaleGrab:onDelete() |
114 | local spec = self.spec_baleGrab |
115 | if self.isServer and spec.dynamicMountedObjects ~= nil then |
116 | for object,_ in pairs(spec.dynamicMountedObjects) do |
117 | self:unmountBaleGrabObject(object) |
118 | end |
119 | end |
120 | if spec.dynamicMountAttacherTrigger ~= nil then |
121 | removeTrigger(spec.dynamicMountAttacherTrigger.triggerNode) |
122 | end |
123 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
67 | function BaleGrab:onLoad(savegame) |
68 | local spec = self.spec_baleGrab |
69 | |
70 | if self.isServer then |
71 | local dynamicMountAttacherTrigger = {} |
72 | dynamicMountAttacherTrigger.triggerNode = self.xmlFile:getValue("vehicle.baleGrab#triggerNode", nil, self.components, self.i3dMappings) |
73 | dynamicMountAttacherTrigger.rootNode = self.xmlFile:getValue("vehicle.baleGrab#rootNode", nil, self.components, self.i3dMappings) |
74 | dynamicMountAttacherTrigger.jointNode = self.xmlFile:getValue("vehicle.baleGrab#jointNode", nil, self.components, self.i3dMappings) |
75 | |
76 | local attacherJointTypeString = self.xmlFile:getValue("vehicle.baleGrab#jointType", "TYPE_AUTO_ATTACH_XYZ") |
77 | dynamicMountAttacherTrigger.attacherJointType = DynamicMountUtil.TYPE_AUTO_ATTACH_XYZ |
78 | if DynamicMountUtil[attacherJointTypeString] ~= nil then |
79 | dynamicMountAttacherTrigger.attacherJointType = DynamicMountUtil[attacherJointTypeString] |
80 | end |
81 | |
82 | if dynamicMountAttacherTrigger.triggerNode ~= nil and dynamicMountAttacherTrigger.rootNode ~= nil and dynamicMountAttacherTrigger.jointNode ~= nil then |
83 | dynamicMountAttacherTrigger.forceAcceleration = self.xmlFile:getValue("vehicle.baleGrab#forceAcceleration", 20) |
84 | addTrigger(dynamicMountAttacherTrigger.triggerNode, "baleGrabTriggerCallback", self) |
85 | |
86 | local grabRefComponentJointIndex1 = self.xmlFile:getValue("vehicle.baleGrab#grabRefComponentJointIndex1") |
87 | local grabRefComponentJointIndex2 = self.xmlFile:getValue("vehicle.baleGrab#grabRefComponentJointIndex2") |
88 | if grabRefComponentJointIndex1 ~= nil then |
89 | dynamicMountAttacherTrigger.componentJoint1 = self.componentJoints[grabRefComponentJointIndex1+1] |
90 | end |
91 | if grabRefComponentJointIndex2 ~= nil then |
92 | dynamicMountAttacherTrigger.componentJoint2 = self.componentJoints[grabRefComponentJointIndex2+1] |
93 | end |
94 | |
95 | dynamicMountAttacherTrigger.rotDiffThreshold1 = self.xmlFile:getValue("vehicle.baleGrab#rotDiffThreshold1", 2) |
96 | dynamicMountAttacherTrigger.rotDiffThreshold2 = self.xmlFile:getValue("vehicle.baleGrab#rotDiffThreshold2", 2) |
97 | |
98 | dynamicMountAttacherTrigger.cosRotDiffThreshold1 = math.cos(dynamicMountAttacherTrigger.rotDiffThreshold1) |
99 | dynamicMountAttacherTrigger.cosRotDiffThreshold2 = math.cos(dynamicMountAttacherTrigger.rotDiffThreshold2) |
100 | |
101 | spec.dynamicMountAttacherTrigger = dynamicMountAttacherTrigger |
102 | end |
103 | |
104 | spec.dynamicMountedObjects = {} |
105 | spec.pendingDynamicMountObjects = {} |
106 | else |
107 | SpecializationUtil.removeEventListener(self, "onUpdateTick", BaleGrab) |
108 | end |
109 | 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 |
130 | function BaleGrab:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
131 | if self.isServer then |
132 | local spec = self.spec_baleGrab |
133 | local attachTrigger = spec.dynamicMountAttacherTrigger |
134 | |
135 | local isClosed = true |
136 | if attachTrigger.componentJoint1 ~= nil then |
137 | isClosed = self:isComponentJointOutsideLimit(attachTrigger.componentJoint1, attachTrigger.rotDiffThreshold1, attachTrigger.cosRotDiffThreshold1) |
138 | end |
139 | if isClosed and attachTrigger.componentJoint2 ~= nil then |
140 | isClosed = self:isComponentJointOutsideLimit(attachTrigger.componentJoint2, attachTrigger.rotDiffThreshold2, attachTrigger.cosRotDiffThreshold2) |
141 | end |
142 | if isClosed then |
143 | for object,_ in pairs(spec.pendingDynamicMountObjects) do |
144 | if spec.dynamicMountedObjects[object] == nil then |
145 | self:unmountBaleGrabObject(object) |
146 | self:mountBaleGrabObject(object) |
147 | end |
148 | end |
149 | else |
150 | for object,_ in pairs(spec.dynamicMountedObjects) do |
151 | self:unmountBaleGrabObject(object) |
152 | end |
153 | end |
154 | end |
155 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
15 | function BaleGrab.prerequisitesPresent(specializations) |
16 | return true |
17 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
58 | function BaleGrab.registerEventListeners(vehicleType) |
59 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", BaleGrab) |
60 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", BaleGrab) |
61 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", BaleGrab) |
62 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
40 | function BaleGrab.registerFunctions(vehicleType) |
41 | SpecializationUtil.registerFunction(vehicleType, "baleGrabTriggerCallback", BaleGrab.baleGrabTriggerCallback) |
42 | SpecializationUtil.registerFunction(vehicleType, "addDynamicMountedObject", BaleGrab.addDynamicMountedObject) |
43 | SpecializationUtil.registerFunction(vehicleType, "removeDynamicMountedObject", BaleGrab.removeDynamicMountedObject) |
44 | SpecializationUtil.registerFunction(vehicleType, "isComponentJointOutsideLimit", BaleGrab.isComponentJointOutsideLimit) |
45 | SpecializationUtil.registerFunction(vehicleType, "mountBaleGrabObject", BaleGrab.mountBaleGrabObject) |
46 | SpecializationUtil.registerFunction(vehicleType, "unmountBaleGrabObject", BaleGrab.unmountBaleGrabObject) |
47 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
51 | function BaleGrab.registerOverwrittenFunctions(vehicleType) |
52 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "addNodeObjectMapping", BaleGrab.addNodeObjectMapping) |
53 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "removeNodeObjectMapping", BaleGrab.removeNodeObjectMapping) |
54 | end |
removeDynamicMountedObject
DescriptionRemove dynamic mount objectDefinition
removeDynamicMountedObject(table object, boolean isDeleting)Arguments
table | object | object |
boolean | isDeleting | is deleting |
169 | function BaleGrab:removeDynamicMountedObject(object, isDeleting) |
170 | local spec = self.spec_baleGrab |
171 | spec.dynamicMountedObjects[object] = nil |
172 | if isDeleting then |
173 | spec.pendingDynamicMountObjects[object] = nil |
174 | end |
175 | end |
removeNodeObjectMapping
DescriptionDefinitionremoveNodeObjectMapping()Code
271 | function BaleGrab:removeNodeObjectMapping(superFunc, list) |
272 | superFunc(self, list) |
273 | |
274 | local spec = self.spec_baleGrab |
275 | if spec.dynamicMountAttacherTrigger ~= nil and spec.dynamicMountAttacherTrigger.triggerNode ~= nil then |
276 | list[spec.dynamicMountAttacherTrigger.triggerNode] = nil |
277 | end |
278 | end |
unmountBaleGrabObject
DescriptionUnmounts a dynamic object from the bale grabDefinition
unmountBaleGrabObject(table object)Arguments
table | object | object |
boolean | success | success |
251 | function BaleGrab:unmountBaleGrabObject(object) |
252 | self:removeDynamicMountedObject(object, false) |
253 | object:unmountDynamic() |
254 | |
255 | return true |
256 | end |