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
SmartAttach
DescriptionThis is the activable class for smartAttachFunctions
- doSmartAttach
- getCanBeSmartAttached
- initSpecialization
- onDelete
- onLoad
- onPreAttach
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- smartAttachCallback
doSmartAttach
DescriptionDefinitiondoSmartAttach()Code
104 | function SmartAttach:doSmartAttach(targetVehicle, inputJointDescIndex, jointDescIndex, noEventSend) |
105 | SmartAttachEvent.sendEvent(self, targetVehicle, inputJointDescIndex, jointDescIndex, noEventSend) |
106 | |
107 | if self.isServer then |
108 | local attacherVehicle = self:getAttacherVehicle() |
109 | if attacherVehicle ~= nil then |
110 | attacherVehicle:detachImplementByObject(self) |
111 | end |
112 | |
113 | targetVehicle:attachImplement(self, inputJointDescIndex, jointDescIndex, false) |
114 | end |
115 | end |
getCanBeSmartAttached
DescriptionDefinitiongetCanBeSmartAttached()Code
119 | function SmartAttach:getCanBeSmartAttached() |
120 | local spec = self.spec_smartAttach |
121 | |
122 | local targetVehicle = spec.targetVehicle |
123 | if targetVehicle == nil then |
124 | return false |
125 | end |
126 | |
127 | local activeForInput = self:getIsActiveForInput(true) or spec.targetVehicle:getIsActiveForInput(true) |
128 | if not activeForInput then |
129 | return false |
130 | end |
131 | |
132 | local attacherJoint = targetVehicle:getAttacherJoints()[spec.jointDescIndex].jointTransform |
133 | local inputAttacherJoint = self:getInputAttacherJoints()[spec.inputJointDescIndex].node |
134 | local x1, _, z1 = getWorldTranslation(attacherJoint) |
135 | local x2, _, z2 = getWorldTranslation(inputAttacherJoint) |
136 | |
137 | local distance = MathUtil.vector2Length(x1-x2, z1-z2) |
138 | local yRot = Utils.getYRotationBetweenNodes(attacherJoint, inputAttacherJoint) |
139 | |
140 | return distance < SmartAttach.DISTANCE_THRESHOLD and math.abs(yRot) < SmartAttach.ABS_ANGLE_THRESHOLD |
141 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
22 | function SmartAttach.initSpecialization() |
23 | local schema = Vehicle.xmlSchema |
24 | schema:setXMLSpecializationType("SmartAttach") |
25 | |
26 | schema:register(XMLValueType.STRING, "vehicle.smartAttach#jointType", "Joint type name") |
27 | schema:register(XMLValueType.NODE_INDEX, "vehicle.smartAttach#trigger", "Trigger node") |
28 | |
29 | schema:setXMLSpecializationType() |
30 | end |
onDelete
DescriptionDefinitiononDelete()Code
88 | function SmartAttach:onDelete() |
89 | local spec = self.spec_smartAttach |
90 | |
91 | if spec.activatable ~= nil then |
92 | g_currentMission.activatableObjectsSystem:removeActivatable(spec.activatable) |
93 | spec.activatable = nil |
94 | end |
95 | |
96 | if spec.trigger ~= nil then |
97 | removeTrigger(spec.trigger) |
98 | spec.trigger = nil |
99 | end |
100 | end |
onLoad
DescriptionDefinitiononLoad()Code
50 | function SmartAttach:onLoad(savegame) |
51 | local spec = self.spec_smartAttach |
52 | |
53 | spec.inputJointDescIndex = nil |
54 | local jointTypeStr = self.xmlFile:getValue("vehicle.smartAttach#jointType") |
55 | if jointTypeStr ~= nil then |
56 | local jointType = AttacherJoints.jointTypeNameToInt[jointTypeStr] |
57 | if jointType ~= nil then |
58 | for inputJointDescIndex, inputAttacherJoint in pairs(self:getInputAttacherJoints()) do |
59 | if inputAttacherJoint.jointType == jointType then |
60 | spec.inputJointDescIndex = inputJointDescIndex |
61 | break |
62 | end |
63 | end |
64 | spec.jointType = jointType |
65 | |
66 | if spec.inputJointDescIndex == nil then |
67 | print("Warning: SmartAttach jointType not defined in '"..self.configFileName.."'!") |
68 | end |
69 | else |
70 | print("Warning: invalid jointType " .. jointTypeStr) |
71 | end |
72 | end |
73 | |
74 | local triggerNode = self.xmlFile:getValue("vehicle.smartAttach#trigger", nil, self.components, self.i3dMappings) |
75 | if triggerNode ~= nil then |
76 | spec.trigger = triggerNode |
77 | addTrigger(spec.trigger, "smartAttachCallback", self) |
78 | end |
79 | |
80 | spec.targetVehicle = nil |
81 | spec.targetVehicleCount = 0 |
82 | spec.jointDescIndex = nil |
83 | spec.activatable = SmartAttachActivatable.new(self) |
84 | end |
onPreAttach
DescriptionDefinitiononPreAttach()Code
145 | function SmartAttach:onPreAttach() |
146 | local spec = self.spec_smartAttach |
147 | |
148 | spec.targetVehicle = nil |
149 | spec.targetVehicleCount = 0 |
150 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
16 | function SmartAttach.prerequisitesPresent(specializations) |
17 | return true |
18 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
42 | function SmartAttach.registerEventListeners(vehicleType) |
43 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", SmartAttach) |
44 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", SmartAttach) |
45 | SpecializationUtil.registerEventListener(vehicleType, "onPreAttach", SmartAttach) |
46 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
34 | function SmartAttach.registerFunctions(vehicleType) |
35 | SpecializationUtil.registerFunction(vehicleType, "smartAttachCallback", SmartAttach.smartAttachCallback) |
36 | SpecializationUtil.registerFunction(vehicleType, "getCanBeSmartAttached", SmartAttach.getCanBeSmartAttached) |
37 | SpecializationUtil.registerFunction(vehicleType, "doSmartAttach", SmartAttach.doSmartAttach) |
38 | end |
smartAttachCallback
DescriptionTrigger callbackDefinition
smartAttachCallback(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 |
160 | function SmartAttach:smartAttachCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
161 | local spec = self.spec_smartAttach |
162 | |
163 | if onEnter then |
164 | local vehicle = g_currentMission.nodeToObject[otherActorId] |
165 | if vehicle ~= nil then |
166 | if spec.targetVehicle == nil then |
167 | if vehicle ~= nil and vehicle ~= self and vehicle.getAttacherJoints ~= nil then |
168 | for i, jointDesc in ipairs(vehicle:getAttacherJoints()) do |
169 | if jointDesc.jointIndex == 0 and jointDesc.jointType == spec.jointType then |
170 | spec.targetVehicle = vehicle |
171 | spec.jointDescIndex = i |
172 | spec.targetVehicleCount = 0 |
173 | |
174 | local name = Utils.getNoNil(self.typeDesc, "") |
175 | local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName:lower()) |
176 | if storeItem ~= nil then |
177 | name = storeItem.name |
178 | end |
179 | |
180 | if self:getAttacherVehicle() == nil then |
181 | spec.activatable.activateText = string.format(g_i18n:getText("action_doSmartAttachGround", self.customEnvironment), name) |
182 | else |
183 | spec.activatable.activateText = string.format(g_i18n:getText("action_doSmartAttachTransform", self.customEnvironment), name) |
184 | end |
185 | |
186 | g_currentMission.activatableObjectsSystem:addActivatable(spec.activatable) |
187 | break |
188 | end |
189 | end |
190 | end |
191 | end |
192 | |
193 | if vehicle == spec.targetVehicle then |
194 | spec.targetVehicleCount = spec.targetVehicleCount + 1 |
195 | end |
196 | end |
197 | elseif onLeave then |
198 | if spec.targetVehicle ~= nil then |
199 | local object = g_currentMission.nodeToObject[otherActorId] |
200 | if object ~= nil and object == spec.targetVehicle then |
201 | spec.targetVehicleCount = spec.targetVehicleCount - 1 |
202 | if spec.targetVehicleCount <= 0 then |
203 | spec.targetVehicle = nil |
204 | g_currentMission.activatableObjectsSystem:removeActivatable(spec.activatable) |
205 | spec.targetVehicleCount = 0 |
206 | end |
207 | end |
208 | end |
209 | end |
210 | end |