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
BaleLoader
DescriptionSpecialization for automatic bale loadersFunctions
- actionControllerEvent
- actionEventAbortEmpty
- actionEventEmpty
- actionEventWorkTransport
- addNodeObjectMapping
- baleGrabberTriggerCallback
- baleLoaderMoveTriggerCallback
- createBaleToBaleJoint
- createBaleToBaleJoints
- doStateChange
- getAllowDynamicMountFillLevelInfo
- getAllowsStartUnloading
- getAreControlledActionsAllowed
- getBaleGrabberDropBaleAnimName
- getBaleInRange
- getBaleTypeByBale
- getCanBeSelected
- getConsumingLoad
- getCurrentFoldingAnimation
- getDoConsumePtoPower
- getIsAIPreparingToDrive
- getIsAIReadyToDrive
- getIsAutomaticBaleUnloadingAllowed
- getIsAutomaticBaleUnloadingInProgress
- getIsBaleGrabbingAllowed
- getIsBaleLoaderFoldingPlaying
- getIsPowerTakeOffActive
- getLoadedBales
- getSpecValueBaleSize
- getSpecValueBaleSizeRound
- getSpecValueBaleSizeSquare
- initSpecialization
- loadBaleLoaderAnimationsFromXML
- loadBalePlacesFromXML
- loadBaleTypeFromXML
- loadSpecValueBaleSize
- loadSpecValueBaleSizeRound
- loadSpecValueBaleSizeSquare
- mountBale
- mountDynamicBale
- moveToTransportPosition
- moveToWorkPosition
- onActivate
- onBaleMoverBaleRemoved
- onDeactivate
- onDelete
- onDraw
- onFillUnitFillLevelChanged
- onLoad
- onLoadFinished
- onPostLoad
- onReadStream
- onReadUpdateStream
- onRegisterActionEvents
- onRegisterAnimationValueTypes
- onRootVehicleChanged
- onUpdate
- onUpdateTick
- onWriteStream
- onWriteUpdateStream
- pickupBale
- playBaleLoaderFoldingAnimation
- prerequisitesPresent
- registerAnimationXMLPaths
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- removeNodeObjectMapping
- rotatePlatform
- saveToXMLFile
- setBaleLoaderBaleType
- setBalePairCollision
- startAutomaticBaleUnloading
- unmountBale
- unmountDynamicBale
- updateBalePlacesAnimations
- updateFoldingAnimation
actionControllerEvent
DescriptionDefinitionactionControllerEvent()Code
1756 | function BaleLoader:actionControllerEvent(direction) |
1757 | local spec = self.spec_baleLoader |
1758 | |
1759 | if (direction > 0 and not spec.isInWorkPosition) or (direction < 0 and spec.isInWorkPosition) then |
1760 | BaleLoader.actionEventWorkTransport(self) |
1761 | return true |
1762 | end |
1763 | end |
actionEventAbortEmpty
DescriptionDefinitionactionEventAbortEmpty()Code
3174 | function BaleLoader.actionEventAbortEmpty(self, actionName, inputValue, callbackState, isAnalog) |
3175 | g_client:getServerConnection():sendEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_BUTTON_EMPTY_ABORT)) |
3176 | end |
actionEventEmpty
DescriptionDefinitionactionEventEmpty()Code
3163 | function BaleLoader.actionEventEmpty(self, actionName, inputValue, callbackState, isAnalog) |
3164 | local spec = self.spec_baleLoader |
3165 | if self:getFillUnitFillLevel(spec.fillUnitIndex) >= spec.minUnloadingFillLevel or spec.emptyState ~= BaleLoader.EMPTY_NONE then |
3166 | g_client:getServerConnection():sendEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_BUTTON_EMPTY)) |
3167 | else |
3168 | g_currentMission:showBlinkingWarning(spec.texts.minUnloadingFillLevelWarning, 2500) |
3169 | end |
3170 | end |
actionEventWorkTransport
DescriptionDefinitionactionEventWorkTransport()Code
3180 | function BaleLoader.actionEventWorkTransport(self, actionName, inputValue, callbackState, isAnalog) |
3181 | g_client:getServerConnection():sendEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_BUTTON_WORK_TRANSPORT)) |
3182 | end |
addNodeObjectMapping
DescriptionDefinitionaddNodeObjectMapping()Code
3051 | function BaleLoader:addNodeObjectMapping(superFunc, list) |
3052 | superFunc(self, list) |
3053 | |
3054 | local spec = self.spec_baleLoader |
3055 | if spec.baleGrabber.trigger ~= nil then |
3056 | list[spec.baleGrabber.trigger] = self |
3057 | end |
3058 | end |
baleGrabberTriggerCallback
DescriptionTrigger callbackDefinition
baleGrabberTriggerCallback(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 |
2714 | function BaleLoader:baleGrabberTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId) |
2715 | if otherId ~= 0 then |
2716 | local rigidBodyType = getRigidBodyType(otherId) |
2717 | if (self.isServer and rigidBodyType == RigidBodyType.DYNAMIC) |
2718 | or (not self.isServer and rigidBodyType == RigidBodyType.KINEMATIC) then -- on client side bales are kinematic |
2719 | local object = g_currentMission:getNodeObject(otherId) |
2720 | if object ~= nil then |
2721 | if object:isa(Bale) then |
2722 | local spec = self.spec_baleLoader |
2723 | if onEnter then |
2724 | spec.baleGrabber.balesInTrigger[object] = Utils.getNoNil(spec.baleGrabber.balesInTrigger[object], 0) + 1 |
2725 | elseif onLeave then |
2726 | if spec.baleGrabber.balesInTrigger[object] ~= nil then |
2727 | spec.baleGrabber.balesInTrigger[object] = math.max(0, spec.baleGrabber.balesInTrigger[object] - 1) |
2728 | if spec.baleGrabber.balesInTrigger[object] == 0 then |
2729 | spec.baleGrabber.balesInTrigger[object] = nil |
2730 | end |
2731 | end |
2732 | end |
2733 | end |
2734 | end |
2735 | end |
2736 | end |
2737 | end |
baleLoaderMoveTriggerCallback
DescriptionTrigger callbackDefinition
baleLoaderMoveTriggerCallback(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 |
2747 | function BaleLoader:baleLoaderMoveTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId) |
2748 | if otherId ~= 0 and getRigidBodyType(otherId) == RigidBodyType.DYNAMIC then |
2749 | local object = g_currentMission:getNodeObject(otherId) |
2750 | if object ~= nil then |
2751 | if object:isa(Bale) then |
2752 | local spec = self.spec_baleLoader |
2753 | if onEnter then |
2754 | spec.unloadingMover.balesInTrigger[object] = Utils.getNoNil(spec.unloadingMover.balesInTrigger[object], 0) + 1 |
2755 | if spec.unloadingMover.balesInTrigger[object] == 1 then |
2756 | object:addDeleteListener(self, "onBaleMoverBaleRemoved") |
2757 | end |
2758 | elseif onLeave then |
2759 | if spec.unloadingMover.balesInTrigger[object] ~= nil then |
2760 | spec.unloadingMover.balesInTrigger[object] = math.max(0, spec.unloadingMover.balesInTrigger[object] - 1) |
2761 | if spec.unloadingMover.balesInTrigger[object] == 0 then |
2762 | spec.unloadingMover.balesInTrigger[object] = nil |
2763 | object:removeDeleteListener(self, "onBaleMoverBaleRemoved") |
2764 | end |
2765 | end |
2766 | end |
2767 | end |
2768 | end |
2769 | end |
2770 | end |
createBaleToBaleJoint
DescriptionDefinitioncreateBaleToBaleJoint()Code
2009 | function BaleLoader:createBaleToBaleJoint(bale1, bale2, x, y, z, rx, ry, rz, balePlaceIndex) |
2010 | local spec = self.spec_baleLoader |
2011 | |
2012 | local balePlaceRot = spec.balePlaces[balePlaceIndex].node |
2013 | |
2014 | local constr = JointConstructor.new() |
2015 | constr:setActors(bale1.nodeId, bale2.nodeId) |
2016 | |
2017 | local jointTransform1 = createTransformGroup("jointTransform1") |
2018 | link(bale1.nodeId, jointTransform1) |
2019 | setRotation(jointTransform1, localRotationToLocal(balePlaceRot, bale1.nodeId, 0, 0, 0)) |
2020 | |
2021 | local jointTransform2 = createTransformGroup("jointTransform2") |
2022 | link(bale2.nodeId, jointTransform2) |
2023 | setRotation(jointTransform2, localRotationToLocal(balePlaceRot, bale2.nodeId, 0, 0, 0)) |
2024 | |
2025 | constr:setJointTransforms(jointTransform1, jointTransform2) |
2026 | constr:setEnableCollision(true) |
2027 | |
2028 | constr:setRotationLimit(0, -rx, rx) |
2029 | constr:setRotationLimit(1, -ry, ry) |
2030 | constr:setRotationLimit(2, -rz, rz) |
2031 | |
2032 | constr:setTranslationLimit(0, true, -x, x) |
2033 | constr:setTranslationLimit(1, true, -y, y) |
2034 | constr:setTranslationLimit(2, true, -z, z) |
2035 | |
2036 | local jointIndex = constr:finalize() |
2037 | |
2038 | table.insert(spec.baleJoints, jointIndex) |
2039 | end |
createBaleToBaleJoints
DescriptionDefinitioncreateBaleToBaleJoints()Code
1957 | function BaleLoader:createBaleToBaleJoints(baleLines) |
1958 | if #baleLines > 1 then |
1959 | local dynamicBaleUnloading = self.spec_baleLoader.dynamicBaleUnloading |
1960 | local lineRotLimit = dynamicBaleUnloading.rowConnectionRotLimit |
1961 | local sideRotLimit = dynamicBaleUnloading.rowInterConnectionRotLimit |
1962 | |
1963 | for lineIndex, bales in ipairs(baleLines) do |
1964 | local isRoundbale = bales[1].isRoundbale |
1965 | |
1966 | if dynamicBaleUnloading.connectedRows[lineIndex] then |
1967 | for i=1, #bales-1 do |
1968 | if isRoundbale then |
1969 | self:createBaleToBaleJoint(bales[i], bales[i+1], 0, dynamicBaleUnloading.heightOffset, bales[i].width + dynamicBaleUnloading.widthOffset, lineRotLimit, 0, 0, i) |
1970 | else |
1971 | self:createBaleToBaleJoint(bales[i], bales[i+1], bales[i].width + dynamicBaleUnloading.widthOffset, dynamicBaleUnloading.heightOffset, 0, 0, 0, lineRotLimit * 5, i) |
1972 | end |
1973 | end |
1974 | end |
1975 | |
1976 | for _, connection in ipairs(dynamicBaleUnloading.interConnectedRowStarts) do |
1977 | if connection[1] == lineIndex then |
1978 | local bales2 = baleLines[connection[2]] |
1979 | if bales2 ~= nil then |
1980 | if isRoundbale then |
1981 | self:createBaleToBaleJoint(bales[1], bales2[1], bales[1].diameter + dynamicBaleUnloading.diameterOffset, dynamicBaleUnloading.heightOffset, 0, sideRotLimit, sideRotLimit, sideRotLimit, 1) |
1982 | else |
1983 | self:createBaleToBaleJoint(bales[1], bales2[1], 0, bales[1].height+0.05, 0, lineRotLimit, 0, 0, 1) |
1984 | end |
1985 | end |
1986 | end |
1987 | end |
1988 | |
1989 | for _, connection in ipairs(dynamicBaleUnloading.interConnectedRowEnds) do |
1990 | if connection[1] == lineIndex then |
1991 | local bales2 = baleLines[connection[2]] |
1992 | if bales2 ~= nil then |
1993 | if #bales == #bales2 then |
1994 | if isRoundbale then |
1995 | self:createBaleToBaleJoint(bales[#bales], bales2[#bales2], bales[#bales].diameter + dynamicBaleUnloading.diameterOffset, dynamicBaleUnloading.heightOffset, 0, sideRotLimit, sideRotLimit, sideRotLimit, #bales) |
1996 | else |
1997 | self:createBaleToBaleJoint(bales[#bales], bales2[#bales2], 0, bales[#bales].height+0.05, 0, lineRotLimit, 0, 0, #bales) |
1998 | end |
1999 | end |
2000 | end |
2001 | end |
2002 | end |
2003 | end |
2004 | end |
2005 | end |
doStateChange
DescriptionChange bale loader stateDefinition
doStateChange(integer id, integer nearestBaleServerId)Arguments
integer | id | id of new state |
integer | nearestBaleServerId | server id of nearest bale |
2045 | function BaleLoader:doStateChange(id, nearestBaleServerId) |
2046 | local spec = self.spec_baleLoader |
2047 | |
2048 | if id == BaleLoader.CHANGE_DROP_BALES then |
2049 | local baleLines = {} |
2050 | |
2051 | -- drop all bales to ground (and add to save by mission) |
2052 | if spec.startBalePlace ~= nil then |
2053 | spec.startBalePlace.current = 1 |
2054 | end |
2055 | |
2056 | local packBales = spec.balePacker.node ~= nil and spec.balePacker.filename ~= nil |
2057 | local packedFarmId, packedFillType, packedFillLevel = FarmManager.SPECTATOR_FARM_ID, FillType.UNKNOWN, 0 |
2058 | |
2059 | for _, balePlace in pairs(spec.balePlaces) do |
2060 | if balePlace.bales ~= nil then |
2061 | for i, baleServerId in pairs(balePlace.bales) do |
2062 | local bale = NetworkUtil.getObject(baleServerId) |
2063 | if bale ~= nil then |
2064 | if spec.dynamicMount.enabled then |
2065 | self:unmountDynamicBale(bale) |
2066 | else |
2067 | self:unmountBale(bale) |
2068 | end |
2069 | |
2070 | bale:setCanBeSold(true) |
2071 | |
2072 | -- clear bales in trigger table |
2073 | if spec.baleGrabber.balesInTrigger[bale] ~= nil then |
2074 | spec.baleGrabber.balesInTrigger[bale] = nil |
2075 | end |
2076 | |
2077 | if spec.dynamicBaleUnloading.enabled then |
2078 | if baleLines[i] == nil then |
2079 | table.insert(baleLines, {bale}) |
2080 | else |
2081 | table.insert(baleLines[i], bale) |
2082 | end |
2083 | end |
2084 | |
2085 | if packBales then |
2086 | packedFarmId = bale.ownerFarmId |
2087 | packedFillType = bale.fillType |
2088 | packedFillLevel = packedFillLevel + bale.fillLevel |
2089 | bale:delete() |
2090 | end |
2091 | end |
2092 | spec.balesToMount[baleServerId] = nil |
2093 | end |
2094 | balePlace.bales = nil |
2095 | end |
2096 | end |
2097 | |
2098 | if self.isServer then |
2099 | if packBales then |
2100 | local baleObject = PackedBale.new(self.isServer, self.isClient) |
2101 | local x, y, z = getWorldTranslation(spec.balePacker.node) |
2102 | local rx, ry, rz = getWorldRotation(spec.balePacker.node) |
2103 | if baleObject:loadFromConfigXML(spec.balePacker.filename, x, y, z, rx, ry, rz) then |
2104 | baleObject:setFillType(packedFillType) |
2105 | baleObject:setFillLevel(packedFillLevel) |
2106 | baleObject:setOwnerFarmId(packedFarmId, true) |
2107 | baleObject:register() |
2108 | |
2109 | removeFromPhysics(baleObject.nodeId) |
2110 | addToPhysics(baleObject.nodeId) |
2111 | end |
2112 | end |
2113 | end |
2114 | |
2115 | if spec.dynamicBaleUnloading.enabled then |
2116 | self:createBaleToBaleJoints(baleLines) |
2117 | end |
2118 | |
2119 | local speed = 1 |
2120 | if spec.animations.releaseFrontPlatformFillLevelSpeed then |
2121 | speed = 1 / (self:getFillUnitFillLevel(spec.fillUnitIndex) / self:getFillUnitCapacity(spec.fillUnitIndex)) |
2122 | end |
2123 | |
2124 | self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, -math.huge, self:getFillUnitFirstSupportedFillType(spec.fillUnitIndex), ToolType.UNDEFINED, nil) |
2125 | |
2126 | if self.isServer then |
2127 | if spec.unloadingMover.trigger ~= nil then |
2128 | spec.unloadingMover.isActive = true |
2129 | spec.unloadingMover.frameDelay = 3 -- giving the bale time to be recognized by the trigger |
2130 | |
2131 | for i=1, #spec.unloadingMover.nodes do |
2132 | local unloadingMoverNode = spec.unloadingMover.nodes[i] |
2133 | setFrictionVelocity(unloadingMoverNode.node, unloadingMoverNode.speed) |
2134 | end |
2135 | |
2136 | if self.isClient then |
2137 | g_animationManager:startAnimations(spec.unloadingMover.animationNodes) |
2138 | g_soundManager:playSample(spec.samples.unload) |
2139 | end |
2140 | |
2141 | self:raiseDirtyFlags(spec.unloadingMover.dirtyFlag) |
2142 | end |
2143 | end |
2144 | |
2145 | self:playAnimation(spec.animations.releaseFrontPlatform, speed, nil, true) |
2146 | self:playAnimation(spec.animations.closeGrippers, -1, nil, true) |
2147 | spec.emptyState = BaleLoader.EMPTY_WAIT_TO_SINK |
2148 | elseif id == BaleLoader.CHANGE_SINK then |
2149 | if spec.animations.emptyRotateReset then |
2150 | self:playAnimation(spec.animations.emptyRotate, -1, nil, true) |
2151 | end |
2152 | self:playAnimation(spec.animations.moveBalePlacesToEmpty, spec.animations.moveBalePlacesToEmptyReverseSpeed, nil, true) |
2153 | if spec.animations.moveBalePlacesResetOnSink then |
2154 | self:playAnimation(spec.animations.moveBalePlaces, -999999, nil, true) |
2155 | end |
2156 | self:playAnimation(spec.animations.pusherEmptyHide1, -1, nil, true) |
2157 | self:playAnimation(spec.animations.rotatePlatformEmpty, -1, nil, true) |
2158 | if not spec.isInWorkPosition then |
2159 | self:playAnimation(spec.animations.closeGrippers, 1, self:getAnimationTime(spec.animations.closeGrippers), true) |
2160 | end |
2161 | spec.emptyState = BaleLoader.EMPTY_SINK |
2162 | elseif id == BaleLoader.CHANGE_EMPTY_REDO then |
2163 | self:playAnimation(spec.animations.emptyRotate, 1, nil, true) |
2164 | spec.emptyState = BaleLoader.EMPTY_ROTATE2 |
2165 | elseif id == BaleLoader.CHANGE_EMPTY_START then |
2166 | if GS_IS_MOBILE_VERSION then |
2167 | -- use action controller to move to work position, so we keep the controller in the correct state |
2168 | if self.rootVehicle:getActionControllerDirection() > 0 then |
2169 | spec.controlledAction.parent:startActionSequence() |
2170 | end |
2171 | spec.emptyState = BaleLoader.EMPTY_TO_WORK |
2172 | else |
2173 | -- move to work position in case it is not there now |
2174 | BaleLoader.moveToWorkPosition(self) |
2175 | spec.emptyState = BaleLoader.EMPTY_TO_WORK |
2176 | end |
2177 | elseif id == BaleLoader.CHANGE_EMPTY_CANCEL then |
2178 | self:playAnimation(spec.animations.emptyRotate, -1, nil, true) |
2179 | spec.emptyState = BaleLoader.EMPTY_CANCEL |
2180 | elseif id == BaleLoader.CHANGE_MOVE_TO_TRANSPORT then |
2181 | if spec.isInWorkPosition then |
2182 | spec.grabberIsMoving = true |
2183 | spec.isInWorkPosition = false |
2184 | g_animationManager:stopAnimations(spec.animationNodes) |
2185 | g_soundManager:stopSample(spec.samples.work) |
2186 | -- move to transport position |
2187 | BaleLoader.moveToTransportPosition(self) |
2188 | end |
2189 | elseif id == BaleLoader.CHANGE_MOVE_TO_WORK then |
2190 | if not spec.isInWorkPosition then |
2191 | spec.grabberIsMoving = true |
2192 | spec.isInWorkPosition = true |
2193 | if not spec.animationNodesBlocked then |
2194 | g_animationManager:startAnimations(spec.animationNodes) |
2195 | g_soundManager:playSample(spec.samples.work) |
2196 | end |
2197 | |
2198 | -- move to work position |
2199 | BaleLoader.moveToWorkPosition(self) |
2200 | end |
2201 | elseif id == BaleLoader.CHANGE_GRAB_BALE then |
2202 | local bale = NetworkUtil.getObject(nearestBaleServerId) |
2203 | spec.baleGrabber.currentBale = nearestBaleServerId |
2204 | if bale ~= nil then |
2205 | if spec.dynamicMount.enabled then |
2206 | self:mountDynamicBale(bale, spec.baleGrabber.grabNode) |
2207 | else |
2208 | self:mountBale(bale, self, spec.baleGrabber.grabNode, 0,0,0, 0,0,0, true) |
2209 | end |
2210 | |
2211 | bale:setCanBeSold(false) |
2212 | |
2213 | local baleType = self:getBaleTypeByBale(bale) |
2214 | if baleType ~= nil then |
2215 | self:setBaleLoaderBaleType(baleType.index) |
2216 | end |
2217 | |
2218 | spec.balesToMount[nearestBaleServerId] = nil |
2219 | else |
2220 | spec.balesToMount[nearestBaleServerId] = {serverId=nearestBaleServerId, linkNode=spec.baleGrabber.grabNode, trans={0,0,0}, rot={0,0,0} } |
2221 | end |
2222 | spec.grabberMoveState = BaleLoader.GRAB_MOVE_UP |
2223 | self:playAnimation(spec.animations.baleGrabberWorkToDrop, 1, nil, true) |
2224 | |
2225 | self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, 1, self:getFillUnitFirstSupportedFillType(spec.fillUnitIndex), ToolType.UNDEFINED, nil) |
2226 | |
2227 | if self.isClient then |
2228 | g_soundManager:playSample(spec.samples.grab) |
2229 | |
2230 | if bale ~= nil then |
2231 | g_effectManager:setFillType(spec.grabberEffects, bale:getFillType()) |
2232 | g_effectManager:startEffects(spec.grabberEffects) |
2233 | spec.grabberEffectDisableTime = g_currentMission.time + spec.grabberEffectDisableDuration |
2234 | end |
2235 | end |
2236 | elseif id == BaleLoader.CHANGE_GRAB_MOVE_UP then |
2237 | spec.currentBaleGrabberDropBaleAnimName = self:getBaleGrabberDropBaleAnimName() |
2238 | self:playAnimation(spec.currentBaleGrabberDropBaleAnimName, 1, nil, true) |
2239 | spec.grabberMoveState = BaleLoader.GRAB_DROP_BALE |
2240 | elseif id == BaleLoader.CHANGE_GRAB_DROP_BALE then |
2241 | -- drop bale at platform |
2242 | if spec.startBalePlace ~= nil and spec.startBalePlace.count < spec.startBalePlace.numOfPlaces and spec.startBalePlace.node ~= nil then |
2243 | local attachNode = getChildAt(spec.startBalePlace.node, spec.startBalePlace.count) |
2244 | local bale = NetworkUtil.getObject(spec.baleGrabber.currentBale) |
2245 | if bale ~= nil then |
2246 | if spec.dynamicMount.enabled then |
2247 | self:mountDynamicBale(bale, attachNode) |
2248 | else |
2249 | local rx, ry, rz = 0, 0, 0 |
2250 | if spec.keepBaleRotationDuringLoad then |
2251 | rx, ry, rz = localRotationToLocal(bale.nodeId, attachNode, 0, 0, 0) |
2252 | end |
2253 | |
2254 | self:mountBale(bale, self, attachNode, 0, 0, 0, rx, ry, rz) |
2255 | end |
2256 | |
2257 | spec.balesToMount[spec.baleGrabber.currentBale] = nil |
2258 | else |
2259 | spec.balesToMount[spec.baleGrabber.currentBale] = {serverId=spec.baleGrabber.currentBale, linkNode=attachNode, trans={0,0,0}, rot={0,0,0} } |
2260 | end |
2261 | |
2262 | spec.startBalePlace.count = spec.startBalePlace.count + 1 |
2263 | table.insert(spec.startBalePlace.bales, spec.baleGrabber.currentBale) |
2264 | spec.baleGrabber.currentBale = nil |
2265 | --setRotation(baleNode, 0, 0, 0) |
2266 | --setTranslation(baleNode, 0, 0, 0) |
2267 | |
2268 | self:updateFoldingAnimation() |
2269 | |
2270 | if spec.startBalePlace.count < spec.startBalePlace.numOfPlaces then |
2271 | spec.frontBalePusherDirection = 1 |
2272 | self:playAnimation(spec.animations.balesToOtherRow, 1, nil, true) |
2273 | self:playAnimation(spec.animations.frontBalePusher, 1, nil, true) |
2274 | elseif spec.startBalePlace.count == spec.startBalePlace.numOfPlaces then |
2275 | BaleLoader.rotatePlatform(self) |
2276 | end |
2277 | |
2278 | if spec.animations.baleGrabberDropToWork ~= nil then |
2279 | self:playAnimation(spec.animations.baleGrabberDropToWork, 1, 0, true) |
2280 | else |
2281 | self:playAnimation(spec.currentBaleGrabberDropBaleAnimName, -spec.animations.baleGrabberDropBaleReverseSpeed, nil, true) |
2282 | self:playAnimation(spec.animations.baleGrabberWorkToDrop, -1, nil, true) |
2283 | end |
2284 | spec.grabberMoveState = BaleLoader.GRAB_MOVE_DOWN |
2285 | end |
2286 | elseif id == BaleLoader.CHANGE_GRAB_MOVE_DOWN then |
2287 | spec.grabberMoveState = nil |
2288 | elseif id == BaleLoader.CHANGE_FRONT_PUSHER then |
2289 | if spec.frontBalePusherDirection > 0 then |
2290 | self:playAnimation(spec.animations.frontBalePusher, -1, nil, true) |
2291 | spec.frontBalePusherDirection = -1 |
2292 | else |
2293 | spec.frontBalePusherDirection = 0 |
2294 | end |
2295 | elseif id == BaleLoader.CHANGE_ROTATE_PLATFORM then |
2296 | if spec.startBalePlace ~= nil and spec.rotatePlatformDirection > 0 then |
2297 | -- drop bales |
2298 | local balePlace = spec.balePlaces[spec.startBalePlace.current] |
2299 | spec.startBalePlace.current = spec.startBalePlace.current + 1 |
2300 | for i=1, table.getn(spec.startBalePlace.bales) do |
2301 | local node = getChildAt(spec.startBalePlace.node, i-1) |
2302 | local x,y,z = getTranslation(node) |
2303 | local rx,ry,rz = getRotation(node) |
2304 | local baleServerId = spec.startBalePlace.bales[i] |
2305 | local bale = NetworkUtil.getObject(baleServerId) |
2306 | |
2307 | if bale ~= nil then |
2308 | if spec.keepBaleRotationDuringLoad then |
2309 | x, y, z = localToLocal(bale.nodeId, balePlace.node, 0, 0, 0) |
2310 | rx, ry, rz = localRotationToLocal(bale.nodeId, balePlace.node, 0, 0, 0) |
2311 | end |
2312 | |
2313 | if spec.dynamicMount.enabled then |
2314 | self:mountDynamicBale(bale, balePlace.node) |
2315 | else |
2316 | self:mountBale(bale, self, balePlace.node, x,y,z, rx,ry,rz) |
2317 | end |
2318 | |
2319 | spec.balesToMount[baleServerId] = nil |
2320 | else |
2321 | spec.balesToMount[baleServerId] = {serverId=baleServerId, linkNode=balePlace.node, trans={ x,y,z}, rot={rx,ry,rz} } |
2322 | end |
2323 | end |
2324 | balePlace.bales = spec.startBalePlace.bales |
2325 | spec.startBalePlace.bales = {} |
2326 | spec.startBalePlace.count = 0 |
2327 | |
2328 | self:updateFoldingAnimation() |
2329 | |
2330 | for i=1, spec.startBalePlace.numOfPlaces do |
2331 | local node = getChildAt(spec.startBalePlace.node, i-1) |
2332 | setRotation(node, unpack(spec.startBalePlace.origRot[i])) |
2333 | setTranslation(node, unpack(spec.startBalePlace.origTrans[i])) |
2334 | end |
2335 | |
2336 | if spec.emptyState == BaleLoader.EMPTY_NONE then |
2337 | -- we are not waiting to start emptying, rotate back |
2338 | if self:getAnimationTime(spec.animations.baleGrabberWorkToDrop) < spec.animations.moveBalePlacesMaxGrabberTime or spec.animations.moveBalePlacesMaxGrabberTime == math.huge then |
2339 | spec.rotatePlatformDirection = -1 |
2340 | self:playAnimation(spec.animations.rotatePlatformBack, -1, nil, true) |
2341 | |
2342 | if spec.animations.moveBalePlacesAfterRotatePlatform then |
2343 | -- startBalePlace.current+1 needs to be at the first position |
2344 | if spec.startBalePlace.current <= table.getn(spec.balePlaces) or spec.animations.moveBalePlacesAlways then |
2345 | self:playAnimation(spec.animations.moveBalePlaces, 1, (spec.startBalePlace.current-1)/table.getn(spec.balePlaces), true) |
2346 | self:setAnimationStopTime(spec.animations.moveBalePlaces, (spec.startBalePlace.current)/table.getn(spec.balePlaces)) |
2347 | self:playAnimation(spec.animations.moveBalePlacesExtrasOnce, 1, nil, true) |
2348 | end |
2349 | end |
2350 | else |
2351 | spec.rotatePlatformDirection = -1 |
2352 | spec.moveBalePlacesDelayedMovement = true |
2353 | end |
2354 | else |
2355 | spec.rotatePlatformDirection = 0 |
2356 | end |
2357 | else |
2358 | spec.rotatePlatformDirection = 0 |
2359 | end |
2360 | elseif id == BaleLoader.CHANGE_EMPTY_ROTATE_PLATFORM then |
2361 | spec.emptyState = BaleLoader.EMPTY_ROTATE_PLATFORM |
2362 | if spec.startBalePlace ~= nil and spec.startBalePlace.count == 0 then |
2363 | self:playAnimation(spec.animations.rotatePlatformEmpty, 1, nil, true) |
2364 | else |
2365 | BaleLoader.rotatePlatform(self) |
2366 | end |
2367 | elseif id == BaleLoader.CHANGE_EMPTY_ROTATE1 then |
2368 | self:playAnimation(spec.animations.emptyRotate, 1, nil, true) |
2369 | self:setAnimationStopTime(spec.animations.emptyRotate, 0.2) |
2370 | local balePlacesTime = self:getRealAnimationTime(spec.animations.moveBalePlaces) |
2371 | |
2372 | local pusherAnimSpeed = spec.animations.moveBalePlacesToEmptySpeed |
2373 | if spec.animations.pusherPushBalesOnEmpty and spec.startBalePlace ~= nil then |
2374 | local usedPlaces = spec.startBalePlace.current |
2375 | if #spec.startBalePlace.bales == 0 then |
2376 | usedPlaces = usedPlaces - 1 |
2377 | end |
2378 | |
2379 | local placeTargetTime = 1 - (balePlacesTime/self:getAnimationDuration(spec.animations.moveBalePlacesToEmpty)) |
2380 | local pusherTargetTime = 1 - (usedPlaces / #spec.balePlaces) |
2381 | pusherAnimSpeed = spec.animations.moveBalePlacesToEmptySpeed * (pusherTargetTime / placeTargetTime) |
2382 | self:playAnimation(spec.animations.pusherMoveToEmpty, pusherAnimSpeed, 0, true) |
2383 | self:setAnimationStopTime(spec.animations.pusherMoveToEmpty, pusherTargetTime) |
2384 | else |
2385 | self:playAnimation(spec.animations.pusherMoveToEmpty, spec.animations.moveBalePlacesToEmptySpeed, balePlacesTime/self:getAnimationDuration(spec.animations.pusherMoveToEmpty), true) |
2386 | end |
2387 | |
2388 | -- only allow if we just pushed the bales back and the start bale places are empty |
2389 | local allowOffset = true |
2390 | local lastPlace = spec.balePlaces[spec.startBalePlace.current-1] |
2391 | if lastPlace ~= nil then |
2392 | if #lastPlace.bales < spec.startBalePlace.numOfPlaces then |
2393 | allowOffset = false |
2394 | end |
2395 | end |
2396 | |
2397 | if spec.animations.moveBalePlacesToEmptyPushOffset > 0 and allowOffset then |
2398 | spec.animations.moveBalePlacesToEmptyPushOffsetDelay = spec.animations.moveBalePlacesToEmptyPushOffset * self:getAnimationDuration(spec.animations.pusherMoveToEmpty) / pusherAnimSpeed |
2399 | spec.animations.moveBalePlacesToEmptyPushOffsetTime = spec.animations.moveBalePlacesToEmptyPushOffsetDelay |
2400 | else |
2401 | self:playAnimation(spec.animations.moveBalePlacesToEmpty, spec.animations.moveBalePlacesToEmptySpeed, balePlacesTime/self:getAnimationDuration(spec.animations.moveBalePlacesToEmpty), true) |
2402 | end |
2403 | |
2404 | spec.emptyState = BaleLoader.EMPTY_ROTATE1 |
2405 | |
2406 | if self.isClient then |
2407 | g_soundManager:playSample(spec.samples.emptyRotate) |
2408 | end |
2409 | elseif id == BaleLoader.CHANGE_EMPTY_CLOSE_GRIPPERS then |
2410 | self:playAnimation(spec.animations.closeGrippers, 1, nil, true) |
2411 | spec.emptyState = BaleLoader.EMPTY_CLOSE_GRIPPERS |
2412 | elseif id == BaleLoader.CHANGE_EMPTY_HIDE_PUSHER1 then |
2413 | self:playAnimation(spec.animations.pusherEmptyHide1, 1, nil, true) |
2414 | spec.emptyState = BaleLoader.EMPTY_HIDE_PUSHER1 |
2415 | elseif id == BaleLoader.CHANGE_EMPTY_HIDE_PUSHER2 then |
2416 | if spec.animations.pusherHideOnEmpty then |
2417 | self:playAnimation(spec.animations.pusherMoveToEmpty, -2, nil, true) |
2418 | spec.emptyState = BaleLoader.EMPTY_HIDE_PUSHER2 |
2419 | else |
2420 | if self.isServer then |
2421 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_ROTATE2), true, nil, self) |
2422 | end |
2423 | end |
2424 | elseif id == BaleLoader.CHANGE_EMPTY_ROTATE2 then |
2425 | self:playAnimation(spec.animations.emptyRotate, 1, self:getAnimationTime(spec.animations.emptyRotate), true) |
2426 | spec.emptyState = BaleLoader.EMPTY_ROTATE2 |
2427 | elseif id == BaleLoader.CHANGE_EMPTY_WAIT_TO_DROP then |
2428 | -- wait for the user to react (abort or drop) |
2429 | spec.emptyState = BaleLoader.EMPTY_WAIT_TO_DROP |
2430 | elseif id == BaleLoader.CHANGE_EMPTY_STATE_NIL then |
2431 | spec.emptyState = BaleLoader.EMPTY_NONE |
2432 | |
2433 | if GS_IS_MOBILE_VERSION then |
2434 | -- use action controller to move back to transport position, so we keep the controller in the correct state |
2435 | if self.rootVehicle:getActionControllerDirection() < 0 then |
2436 | spec.controlledAction.parent:startActionSequence() |
2437 | end |
2438 | else |
2439 | if spec.transportPositionAfterUnloading then |
2440 | BaleLoader.moveToTransportPosition(self) |
2441 | if self.isServer then |
2442 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_MOVE_TO_TRANSPORT), true, nil, self) |
2443 | end |
2444 | end |
2445 | end |
2446 | |
2447 | spec.automaticUnloadingInProgress = false |
2448 | elseif id == BaleLoader.CHANGE_EMPTY_WAIT_TO_REDO then |
2449 | spec.emptyState = BaleLoader.EMPTY_WAIT_TO_REDO |
2450 | elseif id == BaleLoader.CHANGE_BUTTON_EMPTY then |
2451 | -- Server only code |
2452 | assert(self.isServer) |
2453 | if spec.emptyState ~= BaleLoader.EMPTY_NONE then |
2454 | if spec.emptyState == BaleLoader.EMPTY_WAIT_TO_DROP then |
2455 | -- BaleLoader.CHANGE_DROP_BALES |
2456 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_DROP_BALES), true, nil, self) |
2457 | elseif spec.emptyState == BaleLoader.EMPTY_WAIT_TO_SINK then |
2458 | -- BaleLoader.CHANGE_SINK |
2459 | if not spec.unloadingMover.isActive then |
2460 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_SINK), true, nil, self) |
2461 | end |
2462 | elseif spec.emptyState == BaleLoader.EMPTY_WAIT_TO_REDO then |
2463 | -- BaleLoader.CHANGE_EMPTY_REDO |
2464 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_REDO), true, nil, self) |
2465 | end |
2466 | else |
2467 | --BaleLoader.CHANGE_EMPTY_START |
2468 | if BaleLoader.getAllowsStartUnloading(self) then |
2469 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_START), true, nil, self) |
2470 | end |
2471 | end |
2472 | elseif id == BaleLoader.CHANGE_BUTTON_EMPTY_ABORT then |
2473 | -- Server only code |
2474 | assert(self.isServer) |
2475 | if spec.emptyState ~= BaleLoader.EMPTY_NONE then |
2476 | if spec.emptyState == BaleLoader.EMPTY_WAIT_TO_DROP then |
2477 | --BaleLoader.CHANGE_EMPTY_CANCEL |
2478 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_CANCEL), true, nil, self) |
2479 | end |
2480 | end |
2481 | elseif id == BaleLoader.CHANGE_BUTTON_WORK_TRANSPORT then |
2482 | -- Server only code |
2483 | assert(self.isServer) |
2484 | if spec.emptyState == BaleLoader.EMPTY_NONE and spec.grabberMoveState == nil then |
2485 | if spec.isInWorkPosition then |
2486 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_MOVE_TO_TRANSPORT), true, nil, self) |
2487 | else |
2488 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_MOVE_TO_WORK), true, nil, self) |
2489 | end |
2490 | end |
2491 | end |
2492 | end |
getAllowDynamicMountFillLevelInfo
DescriptionDefinitiongetAllowDynamicMountFillLevelInfo()Code
3039 | function BaleLoader:getAllowDynamicMountFillLevelInfo(superFunc) |
3040 | local spec = self.spec_baleLoader |
3041 | if spec.dynamicMount.enabled then |
3042 | return false |
3043 | end |
3044 | |
3045 | return superFunc(self) |
3046 | end |
getAllowsStartUnloading
DescriptionReturns if allows to start unloading balesDefinition
getAllowsStartUnloading()Return Values
boolean | allowsUnloading | allows unloading |
2497 | function BaleLoader.getAllowsStartUnloading(self) |
2498 | local spec = self.spec_baleLoader |
2499 | |
2500 | if self:getFillUnitFillLevel(spec.fillUnitIndex) == 0 then |
2501 | return false |
2502 | end |
2503 | |
2504 | if spec.rotatePlatformDirection ~= 0 then |
2505 | return false |
2506 | end |
2507 | |
2508 | if spec.frontBalePusherDirection ~= 0 then |
2509 | return false |
2510 | end |
2511 | |
2512 | if spec.grabberIsMoving or spec.grabberMoveState ~= nil then |
2513 | return false |
2514 | end |
2515 | |
2516 | if spec.emptyState ~= BaleLoader.EMPTY_NONE then |
2517 | return false |
2518 | end |
2519 | |
2520 | return true |
2521 | end |
getAreControlledActionsAllowed
DescriptionReturns if controlled actions are allowedDefinition
getAreControlledActionsAllowed()Return Values
boolean | allow | allow controlled actions |
string | warning | not allowed warning |
3075 | function BaleLoader:getAreControlledActionsAllowed(superFunc) |
3076 | if self:getIsAutomaticBaleUnloadingInProgress() then |
3077 | return false |
3078 | end |
3079 | |
3080 | return superFunc(self) |
3081 | end |
getBaleGrabberDropBaleAnimName
DescriptionReturns bale grabber drop bale animation nameDefinition
getBaleGrabberDropBaleAnimName()Return Values
string | name | name of bale grabber drop bale animation name |
2570 | function BaleLoader:getBaleGrabberDropBaleAnimName() |
2571 | local spec = self.spec_baleLoader |
2572 | local name = string.format("%s%d", spec.animations.baleGrabberDropBale, spec.startBalePlace.count) |
2573 | if self:getAnimationExists(name) then |
2574 | return name |
2575 | end |
2576 | return spec.animations.baleGrabberDropBale |
2577 | end |
getBaleInRange
DescriptionReturns if nearest bale in rangeDefinition
getBaleInRange(integer refNode)Arguments
integer | refNode | id of reference node |
table | bale | bale |
integer | nearestBaleType | id of bale type |
1617 | function BaleLoader.getBaleInRange(self, refNode, balesInTrigger) |
1618 | local spec = self.spec_baleLoader |
1619 | |
1620 | local nearestDistance = spec.baleGrabber.pickupRange |
1621 | local nearestBale = nil |
1622 | local nearestBaleType = nil |
1623 | local warning = spec.texts.baleNotSupported |
1624 | |
1625 | for bale, state in pairs(balesInTrigger) do |
1626 | if state ~= nil and state > 0 then |
1627 | |
1628 | local isValidBale = true |
1629 | local otherBale |
1630 | for _, balePlace in pairs(spec.balePlaces) do |
1631 | if balePlace.bales ~= nil then |
1632 | for _, baleServerId in pairs(balePlace.bales) do |
1633 | local baleInPlace = NetworkUtil.getObject(baleServerId) |
1634 | if baleInPlace ~= nil and baleInPlace == bale then |
1635 | isValidBale = false |
1636 | end |
1637 | otherBale = baleInPlace |
1638 | end |
1639 | end |
1640 | end |
1641 | |
1642 | if spec.startBalePlace ~= nil then |
1643 | for _, baleServerId in ipairs(spec.startBalePlace.bales) do |
1644 | local baleInPlace = NetworkUtil.getObject(baleServerId) |
1645 | if baleInPlace ~= nil and baleInPlace == bale then |
1646 | isValidBale = false |
1647 | end |
1648 | otherBale = baleInPlace |
1649 | end |
1650 | end |
1651 | |
1652 | if bale == nil or not entityExists(bale.nodeId) then |
1653 | isValidBale = false |
1654 | end |
1655 | |
1656 | if isValidBale then |
1657 | local distance = calcDistanceFrom(refNode, bale.nodeId) |
1658 | if distance < nearestDistance then |
1659 | local foundBaleType = self:getBaleTypeByBale(bale) |
1660 | |
1661 | -- ignore bales from a supported bale type when we already have bales from another supported bale type loaded |
1662 | if foundBaleType ~= spec.currentBaleType then |
1663 | if self:getFillUnitFillLevel(spec.currentBaleType.fillUnitIndex) ~= 0 then |
1664 | foundBaleType = nil |
1665 | warning = spec.texts.onlyOneBaleTypeWarning |
1666 | end |
1667 | end |
1668 | |
1669 | if foundBaleType ~= nil and not foundBaleType.mixedFillTypes then |
1670 | if otherBale ~= nil then |
1671 | if bale:getFillType() ~= otherBale:getFillType() then |
1672 | foundBaleType = nil |
1673 | warning = spec.texts.baleDoNotAllowFillTypeMixing |
1674 | end |
1675 | end |
1676 | end |
1677 | |
1678 | if bale.dynamicMountJointIndex ~= nil then |
1679 | foundBaleType = nil |
1680 | end |
1681 | |
1682 | if not bale:getBaleSupportsBaleLoader() then |
1683 | foundBaleType = nil |
1684 | end |
1685 | |
1686 | local activeFarmId = self:getActiveFarm() |
1687 | if activeFarmId ~= bale.ownerFarmId |
1688 | and not g_currentMission.accessHandler:canFarmAccessOtherId(activeFarmId, bale.ownerFarmId) then |
1689 | foundBaleType = nil |
1690 | warning = spec.texts.youDoNotOwnBale |
1691 | end |
1692 | |
1693 | if foundBaleType ~= nil or nearestBaleType == nil then |
1694 | if foundBaleType ~= nil then |
1695 | nearestDistance = distance |
1696 | end |
1697 | nearestBale = bale |
1698 | nearestBaleType = foundBaleType |
1699 | end |
1700 | end |
1701 | |
1702 | end |
1703 | end |
1704 | end |
1705 | return nearestBale, nearestBaleType, warning |
1706 | end |
getBaleTypeByBale
DescriptionDefinitiongetBaleTypeByBale()Code
2674 | function BaleLoader:getBaleTypeByBale(bale) |
2675 | local spec = self.spec_baleLoader |
2676 | |
2677 | local foundBaleType |
2678 | for _, baleType in pairs(spec.baleTypes) do |
2679 | local dimensions = baleType.dimensions |
2680 | if dimensions.isRoundbale then |
2681 | if dimensions.isRoundbale |
2682 | and bale.width >= dimensions.minWidth |
2683 | and bale.width <= dimensions.maxWidth |
2684 | and bale.diameter >= dimensions.minDiameter |
2685 | and bale.diameter <= dimensions.maxDiameter then |
2686 | foundBaleType = baleType |
2687 | break |
2688 | end |
2689 | else |
2690 | if not dimensions.isRoundbale |
2691 | and bale.width >= dimensions.minWidth |
2692 | and bale.width <= dimensions.maxWidth |
2693 | and bale.height >= dimensions.minHeight |
2694 | and bale.height <= dimensions.maxHeight |
2695 | and bale.length >= dimensions.minLength |
2696 | and bale.length <= dimensions.maxLength then |
2697 | foundBaleType = baleType |
2698 | break |
2699 | end |
2700 | end |
2701 | end |
2702 | |
2703 | return foundBaleType |
2704 | end |
getCanBeSelected
DescriptionDefinitiongetCanBeSelected()Code
3033 | function BaleLoader:getCanBeSelected(superFunc) |
3034 | return true |
3035 | end |
getConsumingLoad
DescriptionDefinitiongetConsumingLoad()Code
3119 | function BaleLoader:getConsumingLoad(superFunc) |
3120 | local value, count = superFunc(self) |
3121 | |
3122 | local spec = self.spec_baleLoader |
3123 | local loadPercentage = 0 |
3124 | if spec.isInWorkPosition or spec.grabberIsMoving then |
3125 | loadPercentage = 1 |
3126 | end |
3127 | |
3128 | return value + loadPercentage, count + 1 |
3129 | end |
getCurrentFoldingAnimation
DescriptionDefinitiongetCurrentFoldingAnimation()Code
2979 | function BaleLoader:getCurrentFoldingAnimation() |
2980 | local spec = self.spec_baleLoader |
2981 | |
2982 | if not spec.hasMultipleFoldingAnimations then |
2983 | return spec.animations.baleGrabberTransportToWork |
2984 | end |
2985 | |
2986 | return spec.lastFoldingAnimation |
2987 | end |
getDoConsumePtoPower
DescriptionReturns if should consume pto powerDefinition
getDoConsumePtoPower()Return Values
boolean | consume | consumePtoPower |
3108 | function BaleLoader:getDoConsumePtoPower(superFunc) |
3109 | local spec = self.spec_baleLoader |
3110 | if spec.isInWorkPosition or spec.grabberIsMoving then |
3111 | return true |
3112 | end |
3113 | |
3114 | return superFunc(self) |
3115 | end |
getIsAIPreparingToDrive
DescriptionDefinitiongetIsAIPreparingToDrive()Code
3096 | function BaleLoader:getIsAIPreparingToDrive(superFunc) |
3097 | local spec = self.spec_baleLoader |
3098 | if spec.grabberIsMoving then |
3099 | return true |
3100 | end |
3101 | |
3102 | return superFunc(self) |
3103 | end |
getIsAIReadyToDrive
DescriptionDefinitiongetIsAIReadyToDrive()Code
3085 | function BaleLoader:getIsAIReadyToDrive(superFunc) |
3086 | local spec = self.spec_baleLoader |
3087 | if spec.isInWorkPosition or spec.grabberIsMoving then |
3088 | return false |
3089 | end |
3090 | |
3091 | return superFunc(self) |
3092 | end |
getIsAutomaticBaleUnloadingAllowed
DescriptionDefinitiongetIsAutomaticBaleUnloadingAllowed()Code
2948 | function BaleLoader:getIsAutomaticBaleUnloadingAllowed() |
2949 | if self:getIsAutomaticBaleUnloadingInProgress() then |
2950 | return false |
2951 | end |
2952 | |
2953 | if self.spec_baleLoader.lastPickupTime + self.spec_baleLoader.lastPickupAutomatedUnloadingDelayTime > g_time then |
2954 | return false |
2955 | end |
2956 | |
2957 | if not BaleLoader.getAllowsStartUnloading(self) then |
2958 | return false |
2959 | end |
2960 | |
2961 | return true |
2962 | end |
getIsAutomaticBaleUnloadingInProgress
DescriptionDefinitiongetIsAutomaticBaleUnloadingInProgress()Code
2942 | function BaleLoader:getIsAutomaticBaleUnloadingInProgress() |
2943 | return self.spec_baleLoader.automaticUnloadingInProgress |
2944 | end |
getIsBaleGrabbingAllowed
DescriptionReturns if bale grabbing is allowedDefinition
getIsBaleGrabbingAllowed()Return Values
string | name | name of bale grabber drop bale animation name |
2582 | function BaleLoader:getIsBaleGrabbingAllowed() |
2583 | local spec = self.spec_baleLoader |
2584 | |
2585 | if not spec.isInWorkPosition then |
2586 | return false |
2587 | end |
2588 | |
2589 | if spec.grabberIsMoving or spec.grabberMoveState ~= nil then |
2590 | return false |
2591 | end |
2592 | |
2593 | if spec.startBalePlace.count >= spec.startBalePlace.numOfPlaces then |
2594 | return false |
2595 | end |
2596 | |
2597 | if spec.frontBalePusherDirection ~= 0 then |
2598 | return false |
2599 | end |
2600 | |
2601 | if not spec.animations.rotatePlatformAllowPickup and spec.rotatePlatformDirection ~= 0 then |
2602 | return false |
2603 | end |
2604 | |
2605 | if spec.animations.moveBalePlacesAlways and self:getIsAnimationPlaying(spec.animations.moveBalePlaces) then |
2606 | return false |
2607 | end |
2608 | |
2609 | if spec.emptyState ~= BaleLoader.EMPTY_NONE then |
2610 | return false |
2611 | end |
2612 | |
2613 | if self:getFillUnitFreeCapacity(spec.fillUnitIndex) == 0 then |
2614 | return false |
2615 | end |
2616 | |
2617 | return true |
2618 | end |
getIsBaleLoaderFoldingPlaying
DescriptionDefinitiongetIsBaleLoaderFoldingPlaying()Code
2973 | function BaleLoader:getIsBaleLoaderFoldingPlaying() |
2974 | return self:getIsAnimationPlaying(self:getCurrentFoldingAnimation()) |
2975 | end |
getIsPowerTakeOffActive
DescriptionDefinitiongetIsPowerTakeOffActive()Code
3133 | function BaleLoader:getIsPowerTakeOffActive(superFunc) |
3134 | local spec = self.spec_baleLoader |
3135 | if spec.isInWorkPosition or spec.grabberIsMoving then |
3136 | return true |
3137 | end |
3138 | |
3139 | return superFunc(self) |
3140 | end |
getLoadedBales
DescriptionDefinitiongetLoadedBales()Code
2903 | function BaleLoader:getLoadedBales() |
2904 | local bales = {} |
2905 | |
2906 | local spec = self.spec_baleLoader |
2907 | for _, balePlace in pairs(spec.balePlaces) do |
2908 | if balePlace.bales ~= nil then |
2909 | for _, baleServerId in pairs(balePlace.bales) do |
2910 | local bale = NetworkUtil.getObject(baleServerId) |
2911 | if bale ~= nil then |
2912 | table.insert(bales, bale) |
2913 | end |
2914 | end |
2915 | end |
2916 | end |
2917 | |
2918 | for _, baleServerId in ipairs(spec.startBalePlace.bales) do |
2919 | local bale = NetworkUtil.getObject(baleServerId) |
2920 | if bale ~= nil then |
2921 | table.insert(bales, bale) |
2922 | end |
2923 | end |
2924 | |
2925 | return bales |
2926 | end |
getSpecValueBaleSize
DescriptionDefinitiongetSpecValueBaleSize()Code
3217 | function BaleLoader.getSpecValueBaleSize(storeItem, realItem, configurations, saleItem, returnValues, returnRange, roundBaleLoader) |
3218 | local baleSizeAttributes = roundBaleLoader and storeItem.specs.baleLoaderBaleSizeRound or storeItem.specs.baleLoaderBaleSizeSquare |
3219 | if baleSizeAttributes ~= nil then |
3220 | local minValue = roundBaleLoader and baleSizeAttributes.minDiameter or baleSizeAttributes.minLength |
3221 | local maxValue = roundBaleLoader and baleSizeAttributes.maxDiameter or baleSizeAttributes.maxLength |
3222 | |
3223 | if returnValues == nil or not returnValues then |
3224 | local unit = g_i18n:getText("unit_cmShort") |
3225 | local size |
3226 | if maxValue ~= minValue then |
3227 | size = string.format("%d%s-%d%s", minValue * 100, unit, maxValue * 100, unit) |
3228 | else |
3229 | size = string.format("%d%s", minValue * 100, unit) |
3230 | end |
3231 | |
3232 | return size |
3233 | else |
3234 | if returnRange == true and maxValue ~= minValue then |
3235 | return minValue * 100, maxValue * 100, g_i18n:getText("unit_cmShort") |
3236 | else |
3237 | return minValue * 100, g_i18n:getText("unit_cmShort") |
3238 | end |
3239 | end |
3240 | else |
3241 | if returnValues and returnRange then |
3242 | return 0, 0, "" |
3243 | elseif returnValues then |
3244 | return 0, "" |
3245 | else |
3246 | return "" |
3247 | end |
3248 | end |
3249 | end |
getSpecValueBaleSizeRound
DescriptionDefinitiongetSpecValueBaleSizeRound()Code
3265 | function BaleLoader.getSpecValueBaleSizeRound(storeItem, realItem, configurations, saleItem, returnValues, returnRange) |
3266 | if storeItem.specs.baleLoaderBaleSizeRound ~= nil then |
3267 | return BaleLoader.getSpecValueBaleSize(storeItem, realItem, configurations, saleItem, returnValues, returnRange, true) |
3268 | end |
3269 | end |
getSpecValueBaleSizeSquare
DescriptionDefinitiongetSpecValueBaleSizeSquare()Code
3273 | function BaleLoader.getSpecValueBaleSizeSquare(storeItem, realItem, configurations, saleItem, returnValues, returnRange) |
3274 | if storeItem.specs.baleLoaderBaleSizeSquare ~= nil then |
3275 | return BaleLoader.getSpecValueBaleSize(storeItem, realItem, configurations, saleItem, returnValues, returnRange, false) |
3276 | end |
3277 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
24 | function BaleLoader.initSpecialization() |
25 | g_storeManager:addSpecType("baleLoaderBaleSizeRound", "shopListAttributeIconBaleSizeRound", BaleLoader.loadSpecValueBaleSizeRound, BaleLoader.getSpecValueBaleSizeRound, "vehicle") |
26 | g_storeManager:addSpecType("baleLoaderBaleSizeSquare", "shopListAttributeIconBaleSizeSquare", BaleLoader.loadSpecValueBaleSizeSquare, BaleLoader.getSpecValueBaleSizeSquare, "vehicle") |
27 | |
28 | local schema = Vehicle.xmlSchema |
29 | schema:setXMLSpecializationType("BaleLoader") |
30 | |
31 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#transportPosition", "Transport position text", "action_baleloaderTransportPosition") |
32 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#operatingPosition", "Operating position text", "action_baleloaderOperatingPosition") |
33 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#unload", "Unload text", "action_baleloaderUnload") |
34 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#tilting", "Tilting text", "info_baleloaderTiltingTable") |
35 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#lowering", "Lowering text", "info_baleloaderLoweringTable") |
36 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#lowerPlattform", "Lower platform text", "action_baleloaderLowerPlatform") |
37 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#abortUnloading", "Abort unloading text", "action_baleloaderAbortUnloading") |
38 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#unloadHere", "Unload here text", "action_baleloaderUnloadHere") |
39 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#baleNotSupported", "Bale not supported warning", "warning_baleNotSupported") |
40 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#baleDoNotAllowFillTypeMixing", "Warning to be shown if the fill type is different from loaded fill types", "warning_baleDoNotAllowFillTypeMixing") |
41 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#onlyOneBaleTypeWarning", "Warning to be shown if user tries to collect a different bale type as already loaded", "warning_baleLoaderOnlyAllowOnceSize") |
42 | schema:register(XMLValueType.L10N_STRING, "vehicle.baleLoader.texts#minUnloadingFillLevelWarning", "Warning to be displayed if min fill level is not reached", "warning_baleLoaderNotFullyLoaded") |
43 | |
44 | BaleLoader.registerAnimationXMLPaths(schema, "vehicle.baleLoader") |
45 | |
46 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader#transportPositionAfterUnloading", "Activate transport mode after unloading", true) |
47 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader#useBalePlaceAsLoadPosition", "Use bale place position as load position", false) |
48 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader#balePlaceOffset", "Bale place offset", 0) |
49 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader#keepBaleRotationDuringLoad", "Keep the same bale rotation while loading bale", false) |
50 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader#automaticUnloading", "Automatically unload the bale loader if platform lifted", false) |
51 | schema:register(XMLValueType.INT, "vehicle.baleLoader#minUnloadingFillLevel", "Min. fill level until unloading is allowed", 1) |
52 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader#allowKinematicMounting", "Kinematic mounting of bale is allow (= bales still have collision while loaded)", true) |
53 | |
54 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader.dynamicMount#enabled", "Bales are dynamically mounted", false) |
55 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader.dynamicMount#doInterpolation", "Bale position is interpolated from bale origin position to grabber position", false) |
56 | schema:register(XMLValueType.TIME, "vehicle.baleLoader.dynamicMount#interpolationTimeRot", "Time for bale rotation interpolation", 1) |
57 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.dynamicMount#interpolationSpeedTrans", "Speed of translation interpolation (m/sec)", 0.1) |
58 | schema:register(XMLValueType.VECTOR_TRANS, "vehicle.baleLoader.dynamicMount#minTransLimits", "Min translation limit") |
59 | schema:register(XMLValueType.VECTOR_TRANS, "vehicle.baleLoader.dynamicMount#maxTransLimits", "Max translation limit") |
60 | |
61 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader.dynamicBaleUnloading#enabled", "Bales are joint together during unloading") |
62 | schema:register(XMLValueType.VECTOR_N, "vehicle.baleLoader.dynamicBaleUnloading#connectedRows", "Indices of rows that are connected together") |
63 | schema:register(XMLValueType.STRING, "vehicle.baleLoader.dynamicBaleUnloading#interConnectedRowStarts", "Interconnections at row start between rows (e.g. '1-2 3-4')") |
64 | schema:register(XMLValueType.STRING, "vehicle.baleLoader.dynamicBaleUnloading#interConnectedRowEnds", "Interconnections at row ends between rows (e.g. '1-2 3-4')") |
65 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.dynamicBaleUnloading#widthOffset", "Width offset") |
66 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.dynamicBaleUnloading#heightOffset", "Height offset") |
67 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.dynamicBaleUnloading#diameterOffset", "Diameter offset") |
68 | schema:register(XMLValueType.ANGLE, "vehicle.baleLoader.dynamicBaleUnloading#rowConnectionRotLimit", "Rotation limit for row joints") |
69 | schema:register(XMLValueType.ANGLE, "vehicle.baleLoader.dynamicBaleUnloading#rowInterConnectionRotLimit", "Rotation limit for inter row joints") |
70 | |
71 | schema:register(XMLValueType.STRING, "vehicle.baleLoader.dynamicBaleUnloading.releaseAnimation#name", "Reference animation to remove joints") |
72 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.dynamicBaleUnloading.releaseAnimation#time", "If animation time is higher than this time the joints will be removed", 1) |
73 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader.dynamicBaleUnloading.releaseAnimation#useUnloadingMoverTrigger", "Bale joints will be removed as soon all bales hast left the unloading mover trigger", false) |
74 | |
75 | schema:register(XMLValueType.INT, "vehicle.baleLoader#fillUnitIndex", "Fill unit index", 1) |
76 | |
77 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.grabber#grabNode", "Grab node") |
78 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.grabber#pickupRange", "Pickup range", 3.0) |
79 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.grabber#triggerNode", "Trigger node") |
80 | |
81 | EffectManager.registerEffectXMLPaths(schema, "vehicle.baleLoader.grabber") |
82 | schema:register(XMLValueType.TIME, "vehicle.baleLoader.grabber#effectDisableDuration", "Disable duration", 0.6) |
83 | |
84 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.balePlaces#startBalePlace", "Start bale place node") |
85 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.balePlaces.balePlace(?)#node", "Bale place node") |
86 | |
87 | schema:register(XMLValueType.STRING, "vehicle.baleLoader.foldingAnimations#baseAnimation", "Base animation name", "baleGrabberTransportToWork") |
88 | schema:register(XMLValueType.STRING, "vehicle.baleLoader.foldingAnimations.foldingAnimation(?)#name", "Animation name") |
89 | schema:register(XMLValueType.INT, "vehicle.baleLoader.foldingAnimations.foldingAnimation(?)#baleTypeIndex", "Index of current bale type", "'0' - any bale type") |
90 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.foldingAnimations.foldingAnimation(?)#minFillLevel", "Min. fill level to use this animation", "-inf") |
91 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.foldingAnimations.foldingAnimation(?)#maxFillLevel", "Max. fill level to use this animation", "inf") |
92 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.foldingAnimations.foldingAnimation(?)#minBalePlace", "Min. bales on platform to use this animation", "-inf") |
93 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.foldingAnimations.foldingAnimation(?)#maxBalePlace", "Max. bales on platform to use this animation", "inf") |
94 | |
95 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.unloadingMoverNodes#trigger", "As long as bales are in this trigger the mover nodes are active and the player can not lower the platform") |
96 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.unloadingMoverNodes.unloadingMoverNode(?)#node", "Node that moves bales") |
97 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.unloadingMoverNodes.unloadingMoverNode(?)#speed", "Defines direction and speed of moving in X direction", -1) |
98 | |
99 | AnimationManager.registerAnimationNodesXMLPaths(schema, "vehicle.baleLoader.unloadingMoverNodes.animationNodes") |
100 | |
101 | schema:register(XMLValueType.INT, "vehicle.baleLoader.synchronization#numBitsPosition", "Number of bits to synchronize bale positions", 10) |
102 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.synchronization#maxPosition", "Max. position offset of bales from bale place in meter", 3) |
103 | |
104 | SoundManager.registerSampleXMLPaths(schema, "vehicle.baleLoader.sounds", "grab") |
105 | SoundManager.registerSampleXMLPaths(schema, "vehicle.baleLoader.sounds", "emptyRotate") |
106 | SoundManager.registerSampleXMLPaths(schema, "vehicle.baleLoader.sounds", "work") |
107 | SoundManager.registerSampleXMLPaths(schema, "vehicle.baleLoader.sounds", "unload") |
108 | |
109 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#diameter", "Bale diameter") |
110 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#width", "Bale width") |
111 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#height", "Bale height") |
112 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#length", "Bale length") |
113 | |
114 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#minDiameter", "Bale min diameter", "diameter value") |
115 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#maxDiameter", "Bale max diameter", "diameter value") |
116 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#minWidth", "Bale min width", "width value") |
117 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#maxWidth", "Bale max width", "width value") |
118 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#minHeight", "Bale min height", "height value") |
119 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#maxHeight", "Bale max height", "height value") |
120 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#minLength", "Bale min length", "length value") |
121 | schema:register(XMLValueType.FLOAT, "vehicle.baleLoader.baleTypes.baleType(?)#maxLength", "Bale max length", "length value") |
122 | |
123 | schema:register(XMLValueType.INT, "vehicle.baleLoader.baleTypes.baleType(?)#fillUnitIndex", "Fill unit index", "baleLoader#fillUnitIndex") |
124 | schema:register(XMLValueType.BOOL, "vehicle.baleLoader.baleTypes.baleType(?)#mixedFillTypes", "Allow loading of mixed fill types", true) |
125 | |
126 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.baleTypes.baleType(?).balePlaces#startBalePlace", "Start bale place node") |
127 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.baleTypes.baleType(?).balePlaces.balePlace(?)#node", "Bale place node") |
128 | |
129 | ObjectChangeUtil.registerObjectChangeXMLPaths(schema, "vehicle.baleLoader.baleTypes.baleType(?)") |
130 | |
131 | BaleLoader.registerAnimationXMLPaths(schema, "vehicle.baleLoader.baleTypes.baleType(?)") |
132 | |
133 | AnimationManager.registerAnimationNodesXMLPaths(schema, "vehicle.baleLoader.animationNodes") |
134 | |
135 | schema:register(XMLValueType.NODE_INDEX, "vehicle.baleLoader.balePacker#node", "Node where to create the packed bale") |
136 | schema:register(XMLValueType.STRING, "vehicle.baleLoader.balePacker#packedFilename", "Filename to packed bale") |
137 | |
138 | schema:addDelayedRegistrationFunc("AnimatedVehicle:part", function(cSchema, cKey) |
139 | cSchema:register(XMLValueType.BOOL, cKey .. "#baleLoaderAnimationNodes", "Bale Loader animation nodes turn on/off") |
140 | end) |
141 | |
142 | schema:setXMLSpecializationType() |
143 | |
144 | local schemaSavegame = Vehicle.xmlSchemaSavegame |
145 | schemaSavegame:register(XMLValueType.STRING, "vehicles.vehicle(?).baleLoader#lastFoldingAnimation", "Last folding animation name") |
146 | schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).baleLoader#baleTypeIndex", "Last bale type index") |
147 | schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?).baleLoader#isInWorkPosition", "Is in working Position") |
148 | schemaSavegame:register(XMLValueType.STRING, "vehicles.vehicle(?).baleLoader.bale(?)#filename", "Filename") |
149 | schemaSavegame:register(XMLValueType.VECTOR_TRANS, "vehicles.vehicle(?).baleLoader.bale(?)#position", "Position") |
150 | schemaSavegame:register(XMLValueType.VECTOR_ROT, "vehicles.vehicle(?).baleLoader.bale(?)#rotation", "Rotation") |
151 | schemaSavegame:register(XMLValueType.FLOAT, "vehicles.vehicle(?).baleLoader.bale(?)#fillLevel", "Filllevel") |
152 | schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).baleLoader.bale(?)#balePlace", "Bale place index") |
153 | schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).baleLoader.bale(?)#helper", "Helper index") |
154 | schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).baleLoader.bale(?)#farmId", "Farm index") |
155 | |
156 | Bale.registerSavegameXMLPaths(schemaSavegame, "vehicles.vehicle(?).baleLoader.bale(?)") |
157 | end |
loadBaleLoaderAnimationsFromXML
DescriptionDefinitionloadBaleLoaderAnimationsFromXML()Code
1854 | function BaleLoader:loadBaleLoaderAnimationsFromXML(xmlFile, key, target, defaultTarget) |
1855 | target.animations = {} |
1856 | local default = target.animations |
1857 | if defaultTarget ~= nil then |
1858 | default = defaultTarget.animations or target.animations |
1859 | end |
1860 | |
1861 | target.animations.rotatePlatform = xmlFile:getValue(key..".animations.platform#rotate", default.rotatePlatform or "rotatePlatform") |
1862 | target.animations.rotatePlatformBack = xmlFile:getValue(key..".animations.platform#rotateBack", default.rotatePlatformBack or "rotatePlatform") |
1863 | target.animations.rotatePlatformEmpty = xmlFile:getValue(key..".animations.platform#rotateEmpty", default.rotatePlatformEmpty or "rotatePlatform") |
1864 | target.animations.rotatePlatformAllowPickup = xmlFile:getValue(key..".animations.platform#allowPickupWhileMoving", Utils.getNoNil(default.rotatePlatformAllowPickup, false)) |
1865 | |
1866 | target.animations.baleGrabberDropBaleReverseSpeed = xmlFile:getValue(key..".animations.baleGrabber#dropBaleReverseSpeed", default.baleGrabberDropBaleReverseSpeed or 5) |
1867 | target.animations.baleGrabberDropToWork = xmlFile:getValue(key..".animations.baleGrabber#dropToWork", default.baleGrabberDropToWork) |
1868 | target.animations.baleGrabberWorkToDrop = xmlFile:getValue(key..".animations.baleGrabber#workToDrop", default.baleGrabberWorkToDrop or "baleGrabberWorkToDrop") |
1869 | target.animations.baleGrabberDropBale = xmlFile:getValue(key..".animations.baleGrabber#dropBale", default.baleGrabberDropBale or "baleGrabberDropBale") |
1870 | target.animations.baleGrabberTransportToWork = xmlFile:getValue(key..".animations.baleGrabber#transportToWork", default.baleGrabberTransportToWork or "baleGrabberTransportToWork") |
1871 | |
1872 | target.animations.pusherEmptyHide1 = xmlFile:getValue(key..".animations.pusher#emptyHide", default.pusherEmptyHide1 or "emptyHidePusher1") |
1873 | target.animations.pusherMoveToEmpty = xmlFile:getValue(key..".animations.pusher#moveToEmpty", default.pusherMoveToEmpty or "moveBalePusherToEmpty") |
1874 | target.animations.pusherHideOnEmpty = xmlFile:getValue(key..".animations.pusher#hidePusherOnEmpty", Utils.getNoNil(default.pusherHideOnEmpty, true)) |
1875 | target.animations.pusherPushBalesOnEmpty = xmlFile:getValue(key..".animations.pusher#pushBalesOnEmpty", Utils.getNoNil(default.pusherPushBalesOnEmpty, false)) |
1876 | |
1877 | target.animations.releaseFrontPlatform = xmlFile:getValue(key..".animations.releaseFrontPlatform#name", default.releaseFrontPlatform or "releaseFrontplattform") |
1878 | target.animations.releaseFrontPlatformFillLevelSpeed = xmlFile:getValue(key..".animations.releaseFrontPlatform#fillLevelSpeed", Utils.getNoNil(default.releaseFrontPlatformFillLevelSpeed, false)) |
1879 | |
1880 | target.animations.moveBalePlaces = xmlFile:getValue(key..".animations.moveBalePlaces#name", default.moveBalePlaces or "moveBalePlaces") |
1881 | target.animations.moveBalePlacesExtrasOnce = xmlFile:getValue(key..".animations.moveBalePlaces#extrasOnce", default.moveBalePlacesExtrasOnce or "moveBalePlacesExtrasOnce") |
1882 | target.animations.moveBalePlacesToEmpty = xmlFile:getValue(key..".animations.moveBalePlaces#empty", default.moveBalePlacesToEmpty or "moveBalePlacesToEmpty") |
1883 | target.animations.moveBalePlacesToEmptySpeed = xmlFile:getValue(key..".animations.moveBalePlaces#emptySpeed", default.moveBalePlacesToEmptySpeed or 1.5) |
1884 | target.animations.moveBalePlacesToEmptyReverseSpeed = xmlFile:getValue(key..".animations.moveBalePlaces#emptyReverseSpeed", default.moveBalePlacesToEmptyReverseSpeed or -1) |
1885 | target.animations.moveBalePlacesToEmptyPushOffset = xmlFile:getValue(key..".animations.moveBalePlaces#pushOffset", default.moveBalePlacesToEmptyPushOffset or 0) |
1886 | target.animations.moveBalePlacesToEmptyPushOffsetDelay = 0 |
1887 | target.animations.moveBalePlacesToEmptyPushOffsetTime = 0 |
1888 | |
1889 | target.animations.moveBalePlacesAfterRotatePlatform = xmlFile:getValue(key..".animations.moveBalePlaces#moveAfterRotatePlatform", Utils.getNoNil(default.moveBalePlacesAfterRotatePlatform, false)) |
1890 | target.animations.moveBalePlacesResetOnSink = xmlFile:getValue(key..".animations.moveBalePlaces#resetOnSink", Utils.getNoNil(default.moveBalePlacesResetOnSink, false)) |
1891 | target.animations.moveBalePlacesMaxGrabberTime = xmlFile:getValue(key..".animations.moveBalePlaces#maxGrabberTime", default.moveBalePlacesMaxGrabberTime or math.huge) |
1892 | target.animations.moveBalePlacesAlways = xmlFile:getValue(key..".animations.moveBalePlaces#alwaysMove", Utils.getNoNil(default.moveBalePlacesAlways, false)) |
1893 | |
1894 | target.animations.emptyRotate = xmlFile:getValue(key..".animations.emptyRotate#name", default.emptyRotate or "emptyRotate") |
1895 | target.animations.emptyRotateReset = xmlFile:getValue(key..".animations.emptyRotate#reset", Utils.getNoNil(default.emptyRotateReset, true)) |
1896 | |
1897 | target.animations.frontBalePusher = xmlFile:getValue(key..".animations#frontBalePusher", default.frontBalePusher or "frontBalePusher") |
1898 | target.animations.balesToOtherRow = xmlFile:getValue(key..".animations#balesToOtherRow", default.balesToOtherRow or "balesToOtherRow") |
1899 | target.animations.closeGrippers = xmlFile:getValue(key..".animations#closeGrippers", default.closeGrippers or "closeGrippers") |
1900 | |
1901 | return true |
1902 | end |
loadBalePlacesFromXML
DescriptionDefinitionloadBalePlacesFromXML()Code
1906 | function BaleLoader:loadBalePlacesFromXML(xmlFile, key, target) |
1907 | local useSharedBalePlaces = true |
1908 | |
1909 | target.startBalePlace = {} |
1910 | target.startBalePlace.bales = {} |
1911 | target.startBalePlace.node = self.xmlFile:getValue(key..".balePlaces#startBalePlace", nil, self.components, self.i3dMappings) |
1912 | if target.startBalePlace.node ~= nil then |
1913 | target.startBalePlace.numOfPlaces = getNumOfChildren(target.startBalePlace.node) |
1914 | if target.startBalePlace.numOfPlaces == 0 then |
1915 | target.startBalePlace.node = nil |
1916 | else |
1917 | target.startBalePlace.origRot = {} |
1918 | target.startBalePlace.origTrans = {} |
1919 | for i=1, target.startBalePlace.numOfPlaces do |
1920 | local node = getChildAt(target.startBalePlace.node, i-1) |
1921 | target.startBalePlace.origRot[i] = {getRotation(node)} |
1922 | target.startBalePlace.origTrans[i] = {getTranslation(node)} |
1923 | end |
1924 | end |
1925 | else |
1926 | target.startBalePlace.numOfPlaces = 0 |
1927 | useSharedBalePlaces = false |
1928 | end |
1929 | target.startBalePlace.count = 0 |
1930 | |
1931 | target.startBalePlace.current = 1 |
1932 | target.balePlaces = {} |
1933 | local i = 0 |
1934 | while true do |
1935 | local balePlaceKey = string.format("%s.balePlaces.balePlace(%d)", key, i) |
1936 | if not self.xmlFile:hasProperty(balePlaceKey) then |
1937 | break |
1938 | end |
1939 | local node = self.xmlFile:getValue(balePlaceKey.."#node", nil, self.components, self.i3dMappings) |
1940 | if node ~= nil then |
1941 | local entry = {} |
1942 | entry.node = node |
1943 | table.insert(target.balePlaces, entry) |
1944 | end |
1945 | i = i + 1 |
1946 | end |
1947 | |
1948 | if #target.balePlaces == 0 then |
1949 | useSharedBalePlaces = false |
1950 | end |
1951 | |
1952 | return useSharedBalePlaces |
1953 | end |
loadBaleTypeFromXML
DescriptionDefinitionloadBaleTypeFromXML()Code
1804 | function BaleLoader:loadBaleTypeFromXML(xmlFile, key, baleType) |
1805 | local spec = self.spec_baleLoader |
1806 | |
1807 | local getDimensionValue = function(xml, valueKey, valueName, minValueName, maxValueName) |
1808 | local value = xml:getValue(valueKey .. "#" .. valueName) |
1809 | local minValue = xml:getValue(valueKey .. "#" .. minValueName) |
1810 | local maxValue = xml:getValue(valueKey .. "#" .. maxValueName) |
1811 | |
1812 | minValue = minValue or maxValue or value |
1813 | maxValue = maxValue or minValue |
1814 | |
1815 | if minValue == nil or maxValue == nil then |
1816 | Logging.xmlError(xmlFile, "Unable to load bale dimension. '%s' is not available in '%s'", valueName, valueKey) |
1817 | return 0, 0 |
1818 | end |
1819 | |
1820 | return MathUtil.round(minValue, 2), MathUtil.round(maxValue, 2) |
1821 | end |
1822 | |
1823 | baleType.dimensions = {} |
1824 | local dimensions = baleType.dimensions |
1825 | dimensions.isRoundbale = self.xmlFile:getString(key.."#diameter") ~= nil |
1826 | or self.xmlFile:getString(key.."#minDiameter") ~= nil |
1827 | or self.xmlFile:getString(key.."#maxDiameter") ~= nil |
1828 | if dimensions.isRoundbale then |
1829 | dimensions.minWidth, dimensions.maxWidth = getDimensionValue(self.xmlFile, key, "width", "minWidth", "maxWidth") |
1830 | dimensions.minDiameter, dimensions.maxDiameter = getDimensionValue(self.xmlFile, key, "diameter", "minDiameter", "maxDiameter") |
1831 | else |
1832 | dimensions.minWidth, dimensions.maxWidth = getDimensionValue(self.xmlFile, key, "width", "minWidth", "maxWidth") |
1833 | dimensions.minHeight, dimensions.maxHeight = getDimensionValue(self.xmlFile, key, "height", "minHeight", "maxHeight") |
1834 | dimensions.minLength, dimensions.maxLength = getDimensionValue(self.xmlFile, key, "length", "minLength", "maxLength") |
1835 | end |
1836 | |
1837 | baleType.mixedFillTypes = self.xmlFile:getValue(key.."#mixedFillTypes", true) |
1838 | baleType.fillUnitIndex = self.xmlFile:getValue(key.."#fillUnitIndex", spec.fillUnitIndex) |
1839 | |
1840 | baleType.changeObjects = {} |
1841 | ObjectChangeUtil.loadObjectChangeFromXML(self.xmlFile, key, baleType.changeObjects, self.components, self) |
1842 | |
1843 | self:loadBalePlacesFromXML(xmlFile, key, baleType) |
1844 | |
1845 | if not self:loadBaleLoaderAnimationsFromXML(xmlFile, key, baleType, spec.defaultAnimations) then |
1846 | return false |
1847 | end |
1848 | |
1849 | return true |
1850 | end |
loadSpecValueBaleSize
DescriptionDefinitionloadSpecValueBaleSize()Code
3186 | function BaleLoader.loadSpecValueBaleSize(xmlFile, customEnvironment, baseDir, roundBaleLoader) |
3187 | local rootName = xmlFile:getRootName() |
3188 | |
3189 | local baleSizeAttributes = {} |
3190 | baleSizeAttributes.minDiameter, baleSizeAttributes.maxDiameter = math.huge, -math.huge |
3191 | baleSizeAttributes.minLength, baleSizeAttributes.maxLength = math.huge, -math.huge |
3192 | xmlFile:iterate(rootName .. ".baleLoader.baleTypes.baleType", function(_, key) |
3193 | if (xmlFile:getValue(key.."#diameter") ~= nil |
3194 | or xmlFile:getValue(key.."#minDiameter") ~= nil |
3195 | or xmlFile:getValue(key.."#maxDiameter") ~= nil) == roundBaleLoader then |
3196 | local diameter = MathUtil.round(xmlFile:getValue(key.."#diameter"), 2) |
3197 | local minDiameter = MathUtil.round(xmlFile:getValue(key.."#minDiameter"), 2) |
3198 | local maxDiameter = MathUtil.round(xmlFile:getValue(key.."#maxDiameter"), 2) |
3199 | baleSizeAttributes.minDiameter = math.min(baleSizeAttributes.minDiameter, diameter or baleSizeAttributes.minDiameter, minDiameter or baleSizeAttributes.minDiameter, maxDiameter or baleSizeAttributes.minDiameter) |
3200 | baleSizeAttributes.maxDiameter = math.max(baleSizeAttributes.maxDiameter, diameter or baleSizeAttributes.maxDiameter, minDiameter or baleSizeAttributes.maxDiameter, maxDiameter or baleSizeAttributes.maxDiameter) |
3201 | |
3202 | local length = MathUtil.round(xmlFile:getValue(key.."#length"), 2) |
3203 | local minLength = MathUtil.round(xmlFile:getValue(key.."#minLength"), 2) |
3204 | local maxLength = MathUtil.round(xmlFile:getValue(key.."#maxLength"), 2) |
3205 | baleSizeAttributes.minLength = math.min(baleSizeAttributes.minLength, length or baleSizeAttributes.minLength, minLength or baleSizeAttributes.minLength, maxLength or baleSizeAttributes.minLength) |
3206 | baleSizeAttributes.maxLength = math.max(baleSizeAttributes.maxLength, length or baleSizeAttributes.maxLength, minLength or baleSizeAttributes.maxLength, maxLength or baleSizeAttributes.maxLength) |
3207 | end |
3208 | end) |
3209 | |
3210 | if baleSizeAttributes.minDiameter ~= math.huge or baleSizeAttributes.minLength ~= math.huge then |
3211 | return baleSizeAttributes |
3212 | end |
3213 | end |
loadSpecValueBaleSizeRound
DescriptionDefinitionloadSpecValueBaleSizeRound()Code
3253 | function BaleLoader.loadSpecValueBaleSizeRound(xmlFile, customEnvironment, baseDir) |
3254 | return BaleLoader.loadSpecValueBaleSize(xmlFile, customEnvironment, baseDir, true) |
3255 | end |
loadSpecValueBaleSizeSquare
DescriptionDefinitionloadSpecValueBaleSizeSquare()Code
3259 | function BaleLoader.loadSpecValueBaleSizeSquare(xmlFile, customEnvironment, baseDir) |
3260 | return BaleLoader.loadSpecValueBaleSize(xmlFile, customEnvironment, baseDir, false) |
3261 | end |
mountBale
DescriptionDefinitionmountBale()Code
2851 | function BaleLoader:mountBale(bale, object, node, x,y,z, rx,ry,rz, noKinematicMounting) |
2852 | local spec = self.spec_baleLoader |
2853 | |
2854 | -- remove from triggered bales since bale is no longer dynamic and won't leave the trigger |
2855 | if spec.unloadingMover.balesInTrigger[bale] ~= nil then |
2856 | spec.unloadingMover.balesInTrigger[bale] = nil |
2857 | end |
2858 | |
2859 | if noKinematicMounting == true or not spec.allowKinematicMounting then |
2860 | bale:mount(object, node, x,y,z, rx,ry,rz) |
2861 | else |
2862 | bale:mountKinematic(object, node, x,y,z, rx,ry,rz) |
2863 | |
2864 | if not table.hasElement(spec.kinematicMountedBales, bale) then |
2865 | self:setBalePairCollision(bale, false) |
2866 | |
2867 | table.addElement(spec.kinematicMountedBales, bale) |
2868 | end |
2869 | end |
2870 | end |
mountDynamicBale
DescriptionDefinitionmountDynamicBale()Code
2774 | function BaleLoader:mountDynamicBale(bale, node) |
2775 | local spec = self.spec_baleLoader |
2776 | if self.isServer then |
2777 | if bale.dynamicMountJointIndex ~= nil and bale.baleLoaderDynamicJointNode ~= nil then |
2778 | local x, y, z = getWorldTranslation(bale.baleLoaderDynamicJointNode) |
2779 | local rx, ry, rz = getWorldRotation(bale.baleLoaderDynamicJointNode) |
2780 | link(node, bale.baleLoaderDynamicJointNode) |
2781 | setWorldTranslation(bale.baleLoaderDynamicJointNode, x, y, z) |
2782 | setWorldRotation(bale.baleLoaderDynamicJointNode, rx, ry, rz) |
2783 | setJointFrame(bale.dynamicMountJointIndex, 0, bale.baleLoaderDynamicJointNode) |
2784 | |
2785 | if spec.dynamicMount.jointInterpolation then |
2786 | table.insert(spec.dynamicMount.baleJointsToUpdate, {node=bale.baleLoaderDynamicJointNode, time=0}) |
2787 | end |
2788 | else |
2789 | local jointNode = createTransformGroup("baleJoint") |
2790 | link(node, jointNode) |
2791 | |
2792 | bale.baleLoaderDynamicJointNode = jointNode |
2793 | |
2794 | if spec.dynamicMount.jointInterpolation then |
2795 | setWorldTranslation(jointNode, getWorldTranslation(bale.nodeId)) |
2796 | setWorldRotation(jointNode, getWorldRotation(bale.nodeId)) |
2797 | else |
2798 | local x, y, z = getWorldTranslation(jointNode) |
2799 | local quatX, quatY, quatZ, quatW = getWorldQuaternion(jointNode) |
2800 | |
2801 | removeFromPhysics(bale.nodeId) |
2802 | bale:setWorldPositionQuaternion(x, y, z, quatX, quatY, quatZ, quatW, true) |
2803 | addToPhysics(bale.nodeId) |
2804 | link(jointNode, bale.meshNode) |
2805 | end |
2806 | |
2807 | local jointComponent = self:getParentComponent(node) |
2808 | bale:mountDynamic(self, jointComponent, jointNode, DynamicMountUtil.TYPE_FIX_ATTACH, 0, false) |
2809 | if spec.dynamicMount.minTransLimits ~= nil and spec.dynamicMount.maxTransLimits ~= nil then |
2810 | for i=1, 3 do |
2811 | local active = spec.dynamicMount.minTransLimits[i] ~= 0 or spec.dynamicMount.maxTransLimits[i] ~= 0 |
2812 | if active then |
2813 | setJointTranslationLimit(bale.dynamicMountJointIndex, i-1, active, spec.dynamicMount.minTransLimits[i], spec.dynamicMount.maxTransLimits[i]) |
2814 | end |
2815 | end |
2816 | end |
2817 | if spec.dynamicMount.jointInterpolation then |
2818 | table.insert(spec.dynamicMount.baleJointsToUpdate, {node=bale.baleLoaderDynamicJointNode, time=0}) |
2819 | end |
2820 | |
2821 | spec.dynamicMount.baleMassDirty = true |
2822 | g_currentMission.itemSystem:removeItemToSave(bale) |
2823 | end |
2824 | end |
2825 | end |
moveToTransportPosition
DescriptionMove to transport positionDefinition
moveToTransportPosition()Code
2560 | function BaleLoader.moveToTransportPosition(self) |
2561 | self:playBaleLoaderFoldingAnimation(-1) |
2562 | |
2563 | local spec = self.spec_baleLoader |
2564 | self:playAnimation(spec.animations.closeGrippers, 1, MathUtil.clamp(self:getAnimationTime(spec.animations.closeGrippers), 0, 1), true) |
2565 | end |
moveToWorkPosition
DescriptionMove bale Loader to work positionDefinition
moveToWorkPosition(boolean onLoad)Arguments
boolean | onLoad | called on load |
2542 | function BaleLoader.moveToWorkPosition(self, onLoad) |
2543 | local spec = self.spec_baleLoader |
2544 | |
2545 | local speed = 1 |
2546 | if onLoad then |
2547 | speed = 9999 |
2548 | end |
2549 | |
2550 | self:playBaleLoaderFoldingAnimation(speed) |
2551 | local animTime = nil |
2552 | if self:getAnimationTime(spec.animations.closeGrippers) ~= 0 then |
2553 | animTime = self:getAnimationTime(spec.animations.closeGrippers) |
2554 | end |
2555 | self:playAnimation(spec.animations.closeGrippers, -1, animTime, true) |
2556 | end |
onActivate
DescriptionCalled on activateDefinition
onActivate()Code
1710 | function BaleLoader:onActivate() |
1711 | local spec = self.spec_baleLoader |
1712 | |
1713 | if spec.isInWorkPosition and not spec.animationNodesBlocked then |
1714 | g_animationManager:startAnimations(spec.animationNodes) |
1715 | g_soundManager:playSample(spec.samples.work) |
1716 | end |
1717 | end |
onBaleMoverBaleRemoved
DescriptionDefinitiononBaleMoverBaleRemoved()Code
3026 | function BaleLoader:onBaleMoverBaleRemoved(bale) |
3027 | local spec = self.spec_baleLoader |
3028 | spec.unloadingMover.balesInTrigger[bale] = nil |
3029 | end |
onDeactivate
DescriptionCalled on deactivateDefinition
onDeactivate()Code
1721 | function BaleLoader:onDeactivate() |
1722 | local spec = self.spec_baleLoader |
1723 | g_effectManager:stopEffects(spec.grabberEffects) |
1724 | g_animationManager:stopAnimations(spec.animationNodes) |
1725 | g_soundManager:stopSample(spec.samples.work) |
1726 | end |
onDelete
DescriptionCalled on deletingDefinition
onDelete()Code
773 | function BaleLoader:onDelete() |
774 | local spec = self.spec_baleLoader |
775 | |
776 | if spec.balePlaces ~= nil then |
777 | -- avoid the bale nodes to be deleted twice (because they are linked the vehicle and because the Bale object is deleted) |
778 | for _, balePlace in pairs(spec.balePlaces) do |
779 | if balePlace.bales ~= nil then |
780 | for _, baleServerId in pairs(balePlace.bales) do |
781 | local bale = NetworkUtil.getObject(baleServerId) |
782 | if bale ~= nil then |
783 | if spec.dynamicMount.enabled then |
784 | self:unmountDynamicBale(bale) |
785 | else |
786 | self:unmountBale(bale) |
787 | end |
788 | |
789 | bale:setCanBeSold(true) |
790 | |
791 | -- if the vehicle is reloaded we remove the bale since it will be regenerated on load |
792 | if self.isReconfigurating ~= nil and self.isReconfigurating then |
793 | bale:delete() |
794 | end |
795 | end |
796 | end |
797 | end |
798 | end |
799 | end |
800 | if spec.startBalePlace ~= nil then |
801 | for _, baleServerId in ipairs(spec.startBalePlace.bales) do |
802 | local bale = NetworkUtil.getObject(baleServerId) |
803 | if bale ~= nil then |
804 | if spec.dynamicMount.enabled then |
805 | self:unmountDynamicBale(bale) |
806 | else |
807 | self:unmountBale(bale) |
808 | end |
809 | |
810 | bale:setCanBeSold(true) |
811 | |
812 | -- if the vehicle is reloaded we remove the bale since it will be regenerated on load |
813 | if self.isReconfigurating ~= nil and self.isReconfigurating then |
814 | bale:delete() |
815 | end |
816 | end |
817 | end |
818 | end |
819 | |
820 | if spec.baleGrabber ~= nil then |
821 | if spec.baleGrabber.currentBale ~= nil then |
822 | local bale = NetworkUtil.getObject(spec.baleGrabber.currentBale) |
823 | if bale ~= nil then |
824 | if spec.dynamicMount.enabled then |
825 | self:unmountDynamicBale(bale) |
826 | else |
827 | self:unmountBale(bale) |
828 | end |
829 | |
830 | bale:setCanBeSold(true) |
831 | end |
832 | end |
833 | |
834 | if spec.baleGrabber.trigger ~= nil then |
835 | removeTrigger(spec.baleGrabber.trigger) |
836 | end |
837 | end |
838 | |
839 | if spec.unloadingMover ~= nil then |
840 | if spec.unloadingMover.trigger ~= nil then |
841 | removeTrigger(spec.unloadingMover.trigger) |
842 | end |
843 | |
844 | g_animationManager:deleteAnimations(spec.unloadingMover.animationNodes) |
845 | end |
846 | |
847 | g_effectManager:deleteEffects(spec.grabberEffects) |
848 | g_soundManager:deleteSamples(spec.samples) |
849 | g_animationManager:deleteAnimations(spec.animationNodes) |
850 | end |
onDraw
DescriptionCalled on drawDefinition
onDraw(boolean isActiveForInput, boolean isSelected)Arguments
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
1605 | function BaleLoader:onDraw(isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
1606 | local spec = self.spec_baleLoader |
1607 | if spec.showBaleNotSupportedWarning and spec.baleNotSupportedWarning ~= nil then |
1608 | g_currentMission:showBlinkingWarning(spec.baleNotSupportedWarning, 2000) |
1609 | end |
1610 | end |
onFillUnitFillLevelChanged
DescriptionDefinitiononFillUnitFillLevelChanged()Code
1767 | function BaleLoader:onFillUnitFillLevelChanged(fillUnitIndex, fillLevelDelta, fillType, toolType, fillPositionData, appliedDelta) |
1768 | local spec = self.spec_baleLoader |
1769 | if fillUnitIndex == spec.fillUnitIndex then |
1770 | self:updateFoldingAnimation() |
1771 | end |
1772 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
345 | function BaleLoader:onLoad(savegame) |
346 | local spec = self.spec_baleLoader |
347 | |
348 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleloaderTurnedOnScrollers.baleloaderTurnedOnScroller", "vehicle.baleLoader.animationNodes.animationNode") --FS17 to FS19 |
349 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleGrabber", "vehicle.baleLoader.grabber") --FS17 to FS19 |
350 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.balePlaces", "vehicle.baleLoader.balePlaces") --FS17 to FS19 |
351 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.grabParticleSystem", "vehicle.baleLoader.grabber.grabParticleSystem") --FS17 to FS19 |
352 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader.grabber.grabParticleSystem", "vehicle.baleLoader.grabber.effectNode") --FS17 to FS19 |
353 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#pickupRange", "vehicle.baleLoader.grabber#pickupRange") --FS17 to FS19 |
354 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleTypes", "vehicle.baleLoader.baleTypes") --FS17 to FS19 |
355 | |
356 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#textTransportPosition", "vehicle.baleLoader.texts#transportPosition") --FS17 to FS19 |
357 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#textOperatingPosition", "vehicle.baleLoader.texts#operatingPosition") --FS17 to FS19 |
358 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#textUnload", "vehicle.baleLoader.texts#unload") --FS17 to FS19 |
359 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#textTilting", "vehicle.baleLoader.texts#tilting") --FS17 to FS19 |
360 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#textLowering", "vehicle.baleLoader.texts#lowering") --FS17 to FS19 |
361 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#textLowerPlattform", "vehicle.baleLoader.texts#lowerPlattform") --FS17 to FS19 |
362 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#textAbortUnloading", "vehicle.baleLoader.texts#abortUnloading") --FS17 to FS19 |
363 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#textUnloadHere", "vehicle.baleLoader.texts#unloadHere") --FS17 to FS19 |
364 | |
365 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#rotatePlatformAnimName", "vehicle.baleLoader.animations#rotatePlatform") --FS17 to FS19 |
366 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#rotatePlatformBackAnimName", "vehicle.baleLoader.animations#rotatePlatformBack") --FS17 to FS19 |
367 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#rotatePlatformEmptyAnimName", "vehicle.baleLoader.animations#rotatePlatformEmpty") --FS17 to FS19 |
368 | |
369 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader.animations#grabberDropBaleReverseSpeed", "vehicle.baleLoader.animations.baleGrabber#dropBaleReverseSpeed") --FS19 to FS22 |
370 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader.animations#grabberDropToWork", "vehicle.baleLoader.animations.baleGrabber#dropToWork") --FS19 to FS22 |
371 | |
372 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader.animations#rotatePlatform", "vehicle.baleLoader.animations.platform#rotate") --FS19 to FS22 |
373 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader.animations#rotatePlatformBack", "vehicle.baleLoader.animations.platform#rotateBack") --FS19 to FS22 |
374 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader.animations#rotatePlatformEmpty", "vehicle.baleLoader.animations.platform#rotateEmpty") --FS19 to FS22 |
375 | |
376 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#moveBalePlacesAfterRotatePlatform", "vehicle.baleLoader.animations.moveBalePlaces#moveAfterRotatePlatform") --FS19 to FS22 |
377 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#moveBalePlacesMaxGrabberTime", "vehicle.baleLoader.animations.moveBalePlaces#maxGrabberTime") --FS19 to FS22 |
378 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#alwaysMoveBalePlaces", "vehicle.baleLoader.animations.moveBalePlaces#alwaysMove") --FS19 to FS22 |
379 | |
380 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.baleLoader#resetEmptyRotateAnimation", "vehicle.baleLoader.animations.emptyRotate#reset") --FS19 to FS22 |
381 | |
382 | local baseKey = "vehicle.baleLoader" |
383 | |
384 | spec.balesToLoad = {} |
385 | |
386 | spec.balesToMount = {} |
387 | |
388 | spec.isInWorkPosition = false |
389 | spec.grabberIsMoving = false |
390 | |
391 | spec.rotatePlatformDirection = 0 |
392 | spec.frontBalePusherDirection = 0 |
393 | |
394 | spec.emptyState = BaleLoader.EMPTY_NONE |
395 | |
396 | spec.texts = {} |
397 | spec.texts.transportPosition = self.xmlFile:getValue(baseKey..".texts#transportPosition", "action_baleloaderTransportPosition", nil, self.customEnvironment) |
398 | spec.texts.operatingPosition = self.xmlFile:getValue(baseKey..".texts#operatingPosition", "action_baleloaderOperatingPosition", nil, self.customEnvironment) |
399 | spec.texts.unload = self.xmlFile:getValue(baseKey..".texts#unload", "action_baleloaderUnload", nil, self.customEnvironment) |
400 | spec.texts.tilting = self.xmlFile:getValue(baseKey..".texts#tilting", "info_baleloaderTiltingTable", nil, self.customEnvironment) |
401 | spec.texts.lowering = self.xmlFile:getValue(baseKey..".texts#lowering", "info_baleloaderLoweringTable", nil, self.customEnvironment) |
402 | spec.texts.lowerPlattform = self.xmlFile:getValue(baseKey..".texts#lowerPlattform", "action_baleloaderLowerPlatform", nil, self.customEnvironment) |
403 | spec.texts.abortUnloading = self.xmlFile:getValue(baseKey..".texts#abortUnloading", "action_baleloaderAbortUnloading", nil, self.customEnvironment) |
404 | spec.texts.unloadHere = self.xmlFile:getValue(baseKey..".texts#unloadHere", "action_baleloaderUnloadHere", nil, self.customEnvironment) |
405 | spec.texts.baleNotSupported = self.xmlFile:getValue(baseKey..".texts#baleNotSupported", "warning_baleNotSupported", nil, self.customEnvironment) |
406 | spec.texts.baleDoNotAllowFillTypeMixing = self.xmlFile:getValue(baseKey..".texts#baleDoNotAllowFillTypeMixing", "warning_baleDoNotAllowFillTypeMixing", nil, self.customEnvironment) |
407 | spec.texts.onlyOneBaleTypeWarning = self.xmlFile:getValue(baseKey..".texts#onlyOneBaleTypeWarning", "warning_baleLoaderOnlyAllowOnceSize", nil, self.customEnvironment) |
408 | spec.texts.minUnloadingFillLevelWarning = self.xmlFile:getValue(baseKey..".texts#minUnloadingFillLevelWarning", "warning_baleLoaderNotFullyLoaded", nil, self.customEnvironment) |
409 | spec.texts.youDoNotOwnBale = g_i18n:getText("warning_youDontOwnThisItem") |
410 | |
411 | spec.transportPositionAfterUnloading = self.xmlFile:getValue(baseKey.."#transportPositionAfterUnloading", true) |
412 | spec.useBalePlaceAsLoadPosition = self.xmlFile:getValue(baseKey.."#useBalePlaceAsLoadPosition", false) |
413 | spec.balePlaceOffset = self.xmlFile:getValue(baseKey.."#balePlaceOffset", 0) |
414 | spec.keepBaleRotationDuringLoad = self.xmlFile:getValue(baseKey.."#keepBaleRotationDuringLoad", false) |
415 | |
416 | spec.automaticUnloading = self.xmlFile:getValue(baseKey.."#automaticUnloading", false) |
417 | spec.minUnloadingFillLevel = self.xmlFile:getValue(baseKey.."#minUnloadingFillLevel", 1) |
418 | spec.fillUnitIndex = self.xmlFile:getValue(baseKey.."#fillUnitIndex", 1) |
419 | |
420 | spec.allowKinematicMounting = self.xmlFile:getValue(baseKey.."#allowKinematicMounting", true) |
421 | |
422 | spec.dynamicMount = {} |
423 | spec.dynamicMount.enabled = self.xmlFile:getValue(baseKey..".dynamicMount#enabled", false) |
424 | spec.dynamicMount.jointInterpolation = self.xmlFile:getValue(baseKey..".dynamicMount#doInterpolation", false) |
425 | spec.dynamicMount.jointInterpolationTimeRot = self.xmlFile:getValue(baseKey..".dynamicMount#interpolationTimeRot", 1) |
426 | spec.dynamicMount.jointInterpolationSpeedTrans = self.xmlFile:getValue(baseKey..".dynamicMount#interpolationSpeedTrans", 0.1) / 1000 |
427 | spec.dynamicMount.baleJointsToUpdate = {} |
428 | spec.dynamicMount.minTransLimits = self.xmlFile:getValue(baseKey..".dynamicMount#minTransLimits", nil, true) |
429 | spec.dynamicMount.maxTransLimits = self.xmlFile:getValue(baseKey..".dynamicMount#maxTransLimits", nil, true) |
430 | spec.dynamicMount.baleMassDirty = false |
431 | |
432 | spec.dynamicBaleUnloading = {} |
433 | spec.dynamicBaleUnloading.enabled = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading#enabled", false) |
434 | |
435 | spec.dynamicBaleUnloading.connectedRows = {} |
436 | local connectedRows = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading#connectedRows", nil, true) |
437 | if connectedRows ~= nil then |
438 | for i=1, #connectedRows do |
439 | spec.dynamicBaleUnloading.connectedRows[connectedRows[i]] = true |
440 | end |
441 | end |
442 | |
443 | local getConnectedRows = function(key) |
444 | local connections = {} |
445 | local connectedRowStartsStr = self.xmlFile:getValue(key) |
446 | local connectedRowStartsParts = string.split(connectedRowStartsStr, " ") |
447 | for i=1, #connectedRowStartsParts do |
448 | local subParts = string.split(connectedRowStartsParts[i], "-") |
449 | if #subParts ~= 2 then |
450 | Logging.xmlWarning(self.xmlFile, "Unknown row connection '%s' in '%s' (should look like '1-2 3-4')", connectedRowStartsParts[i], key) |
451 | else |
452 | table.insert(connections, {tonumber(subParts[1]), tonumber(subParts[2])}) |
453 | end |
454 | end |
455 | |
456 | return connections |
457 | end |
458 | |
459 | spec.dynamicBaleUnloading.interConnectedRowStarts = getConnectedRows(baseKey..".dynamicBaleUnloading#interConnectedRowStarts") |
460 | spec.dynamicBaleUnloading.interConnectedRowEnds = getConnectedRows(baseKey..".dynamicBaleUnloading#interConnectedRowEnds") |
461 | |
462 | spec.dynamicBaleUnloading.widthOffset = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading#widthOffset", 0.05) |
463 | spec.dynamicBaleUnloading.heightOffset = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading#heightOffset", 0.05) |
464 | spec.dynamicBaleUnloading.diameterOffset = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading#diameterOffset", 0.05) |
465 | spec.dynamicBaleUnloading.rowConnectionRotLimit = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading#rowConnectionRotLimit", 4) |
466 | spec.dynamicBaleUnloading.rowInterConnectionRotLimit = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading#rowInterConnectionRotLimit", 1) |
467 | |
468 | spec.dynamicBaleUnloading.releaseAnimation = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading.releaseAnimation#name") |
469 | spec.dynamicBaleUnloading.releaseAnimationTime = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading.releaseAnimation#time", 1) |
470 | spec.dynamicBaleUnloading.useUnloadingMoverTrigger = self.xmlFile:getValue(baseKey..".dynamicBaleUnloading.releaseAnimation#useUnloadingMoverTrigger", false) |
471 | |
472 | spec.baleGrabber = {} |
473 | spec.baleGrabber.grabNode = self.xmlFile:getValue(baseKey..".grabber#grabNode", nil, self.components, self.i3dMappings) |
474 | spec.baleGrabber.pickupRange = self.xmlFile:getValue(baseKey..".grabber#pickupRange", 3.0) |
475 | spec.baleGrabber.balesInTrigger = {} |
476 | spec.baleGrabber.trigger = self.xmlFile:getValue(baseKey..".grabber#triggerNode", nil, self.components, self.i3dMappings) |
477 | if spec.baleGrabber.trigger ~= nil then |
478 | addTrigger(spec.baleGrabber.trigger, "baleGrabberTriggerCallback", self) |
479 | else |
480 | Logging.xmlError(self.xmlFile, "Bale grabber needs a valid trigger!") |
481 | end |
482 | |
483 | if self.isClient then |
484 | local grabParticleSystem = {} |
485 | local psName = baseKey..".grabber.grabParticleSystem" |
486 | if ParticleUtil.loadParticleSystem(self.xmlFile, grabParticleSystem, psName, self.components, false, nil, self.baseDirectory) then |
487 | spec.grabParticleSystem = grabParticleSystem |
488 | spec.grabParticleSystemDisableTime = 0 |
489 | end |
490 | |
491 | spec.grabberEffects = g_effectManager:loadEffect(self.xmlFile, baseKey..".grabber", self.components, self, self.i3dMappings) |
492 | spec.grabberEffectDisableDuration = self.xmlFile:getValue(baseKey..".grabber#effectDisableDuration", 0.6) |
493 | spec.grabberEffectDisableTime = 0 |
494 | |
495 | spec.samples = {} |
496 | spec.samples.grab = g_soundManager:loadSampleFromXML(self.xmlFile, baseKey..".sounds", "grab", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self) |
497 | spec.samples.emptyRotate = g_soundManager:loadSampleFromXML(self.xmlFile, baseKey..".sounds", "emptyRotate", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self) |
498 | spec.samples.work = g_soundManager:loadSampleFromXML(self.xmlFile, baseKey..".sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
499 | spec.samples.unload = g_soundManager:loadSampleFromXML(self.xmlFile, baseKey..".sounds", "unload", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
500 | end |
501 | |
502 | |
503 | spec.defaultAnimations = {} |
504 | self:loadBaleLoaderAnimationsFromXML(self.xmlFile, baseKey, spec.defaultAnimations) |
505 | |
506 | -- setting up defaults |
507 | spec.animations = spec.defaultAnimations.animations |
508 | |
509 | spec.defaultBalePlace = {} |
510 | spec.useSharedBalePlaces = false |
511 | if self:loadBalePlacesFromXML(self.xmlFile, baseKey, spec.defaultBalePlace) then |
512 | spec.useSharedBalePlaces = true |
513 | end |
514 | |
515 | spec.startBalePlace = spec.defaultBalePlace.startBalePlace |
516 | spec.balePlaces = spec.defaultBalePlace.balePlaces |
517 | |
518 | spec.baleTypes = {} |
519 | |
520 | local i = 0 |
521 | while true do |
522 | local baleTypeKey = string.format("%s.baleTypes.baleType(%d)", baseKey, i) |
523 | if not self.xmlFile:hasProperty(baleTypeKey) then |
524 | break |
525 | end |
526 | |
527 | local entry = {} |
528 | if self:loadBaleTypeFromXML(self.xmlFile, baleTypeKey, entry) then |
529 | entry.index = i + 1 |
530 | table.insert(spec.baleTypes, entry) |
531 | end |
532 | |
533 | i = i + 1 |
534 | end |
535 | |
536 | if #spec.baleTypes == 0 then |
537 | Logging.xmlError(self.xmlFile, "No bale types defined for baleLoader!") |
538 | else |
539 | if spec.startBalePlace == nil then |
540 | spec.startBalePlace = spec.baleTypes[1].startBalePlace |
541 | end |
542 | |
543 | if spec.balePlaces == nil then |
544 | spec.balePlaces = spec.baleTypes[1].balePlaces |
545 | end |
546 | |
547 | if spec.startBalePlace == nil then |
548 | Logging.xmlError(self.xmlFile, "Could not find startBalePlace for baleLoader!") |
549 | end |
550 | |
551 | if spec.balePlaces == nil then |
552 | Logging.xmlError(self.xmlFile, "Could not find bale places for baleLoader!") |
553 | end |
554 | end |
555 | |
556 | self:setBaleLoaderBaleType(1) |
557 | |
558 | spec.foldingAnimations = {} |
559 | i = 0 |
560 | while true do |
561 | local animationKey = string.format("%s.foldingAnimations.foldingAnimation(%d)", baseKey, i) |
562 | if not self.xmlFile:hasProperty(animationKey) then |
563 | break |
564 | end |
565 | |
566 | local animation = {} |
567 | animation.name = self.xmlFile:getValue(animationKey .. "#name") |
568 | animation.baleTypeIndex = self.xmlFile:getValue(animationKey .. "#baleTypeIndex", 0) |
569 | animation.minFillLevel = self.xmlFile:getValue(animationKey .. "#minFillLevel", -math.huge) |
570 | animation.maxFillLevel = self.xmlFile:getValue(animationKey .. "#maxFillLevel", math.huge) |
571 | animation.minBalePlace = self.xmlFile:getValue(animationKey .. "#minBalePlace", -math.huge) |
572 | animation.maxBalePlace = self.xmlFile:getValue(animationKey .. "#maxBalePlace", math.huge) |
573 | |
574 | if self:getAnimationExists(animation.name) then |
575 | table.insert(spec.foldingAnimations, animation) |
576 | else |
577 | Logging.xmlWarning(self.xmlFile, "Unknown folding animation '%s' in '%s'", animation.name, animationKey) |
578 | end |
579 | |
580 | i = i + 1 |
581 | end |
582 | |
583 | spec.hasMultipleFoldingAnimations = #spec.foldingAnimations > 0 |
584 | spec.lastFoldingAnimation = spec.animations.baleGrabberTransportToWork |
585 | self:updateFoldingAnimation() |
586 | |
587 | spec.unloadingMover = {} |
588 | spec.unloadingMover.trigger = self.xmlFile:getValue(baseKey .. ".unloadingMoverNodes#trigger", nil, self.components, self.i3dMappings) |
589 | if spec.unloadingMover.trigger ~= nil then |
590 | addTrigger(spec.unloadingMover.trigger, "baleLoaderMoveTriggerCallback", self) |
591 | end |
592 | spec.unloadingMover.isActive = false |
593 | spec.unloadingMover.dirtyFlag = self:getNextDirtyFlag() |
594 | spec.unloadingMover.frameDelay = 0 |
595 | spec.unloadingMover.balesInTrigger = {} |
596 | spec.unloadingMover.nodes = {} |
597 | |
598 | spec.unloadingMover.animationNodes = g_animationManager:loadAnimations(self.xmlFile, baseKey..".unloadingMoverNodes.animationNodes", self.components, self, self.i3dMappings) |
599 | |
600 | i = 0 |
601 | while true do |
602 | local moverKey = string.format("%s.unloadingMoverNodes.unloadingMoverNode(%d)", baseKey, i) |
603 | if not self.xmlFile:hasProperty(moverKey) then |
604 | break |
605 | end |
606 | |
607 | local entry = {} |
608 | entry.node = self.xmlFile:getValue(moverKey .. "#node", nil, self.components, self.i3dMappings) |
609 | entry.speed = self.xmlFile:getValue(moverKey .. "#speed", -1) |
610 | |
611 | if entry.node ~= nil then |
612 | table.insert(spec.unloadingMover.nodes, entry) |
613 | else |
614 | Logging.xmlWarning(self.xmlFile, "Unknown node in '%s'", moverKey) |
615 | end |
616 | |
617 | i = i + 1 |
618 | end |
619 | |
620 | spec.balePacker = {} |
621 | spec.balePacker.node = self.xmlFile:getValue(baseKey .. ".balePacker#node", nil, self.components, self.i3dMappings) |
622 | spec.balePacker.filename = self.xmlFile:getValue(baseKey .. ".balePacker#packedFilename") |
623 | if spec.balePacker.filename ~= nil then |
624 | spec.balePacker.filename = Utils.getFilename(spec.balePacker.filename, self.baseDirectory) |
625 | if spec.balePacker.filename ~= nil and not fileExists(spec.balePacker.filename) then |
626 | Logging.xmlError(self.xmlFile, "Unable to find packed bale '%s'", spec.balePacker.filename) |
627 | end |
628 | end |
629 | |
630 | spec.synchronizationNumBitsPosition = self.xmlFile:getValue(baseKey .. ".synchronization#numBitsPosition", 10) |
631 | spec.synchronizationMaxPosition = self.xmlFile:getValue(baseKey .. ".synchronization#maxPosition", 3) |
632 | |
633 | spec.animationNodes = g_animationManager:loadAnimations(self.xmlFile, baseKey..".animationNodes", self.components, self, self.i3dMappings) |
634 | spec.animationNodesBlocked = false |
635 | |
636 | spec.showBaleNotSupportedWarning = false |
637 | spec.baleNotSupportedWarning = nil |
638 | spec.automaticUnloadingInProgress = false |
639 | spec.lastPickupAutomatedUnloadingDelayTime = 15000 |
640 | spec.lastPickupTime = -spec.lastPickupAutomatedUnloadingDelayTime |
641 | spec.kinematicMountedBales = {} |
642 | |
643 | spec.baleJoints = {} |
644 | end |
onLoadFinished
DescriptionCalled after vehicle was added to phyiscsDefinition
onLoadFinished(table savegame)Arguments
table | savegame | savegame |
745 | function BaleLoader:onLoadFinished(savegame) |
746 | local spec = self.spec_baleLoader |
747 | |
748 | for k,v in pairs(spec.balesToLoad) do |
749 | local baleObject = Bale.new(self.isServer, self.isClient) |
750 | local x, y, z = unpack(v.translation) |
751 | local rx, ry, rz = unpack(v.rotation) |
752 | if baleObject:loadFromConfigXML(v.filename, x, y, z, rx, ry, rz) then |
753 | baleObject:applyBaleAttributes(v.attributes) |
754 | baleObject:register() |
755 | |
756 | if spec.dynamicMount.enabled then |
757 | self:mountDynamicBale(baleObject, v.parentNode) |
758 | else |
759 | self:mountBale(baleObject, self, v.parentNode, x,y,z, rx,ry,rz) |
760 | end |
761 | |
762 | baleObject:setCanBeSold(false) |
763 | |
764 | table.insert(v.bales, NetworkUtil.getObjectId(baleObject)) |
765 | end |
766 | |
767 | spec.balesToLoad[k] = nil |
768 | end |
769 | end |
onPostLoad
DescriptionCalled after loadingDefinition
onPostLoad(table savegame)Arguments
table | savegame | savegame |
649 | function BaleLoader:onPostLoad(savegame) |
650 | if savegame ~= nil then |
651 | local spec = self.spec_baleLoader |
652 | |
653 | local baleTypeIndex = savegame.xmlFile:getValue(savegame.key..".baleLoader#baleTypeIndex") |
654 | if baleTypeIndex ~= nil then |
655 | self:setBaleLoaderBaleType(baleTypeIndex, true) |
656 | end |
657 | |
658 | if spec.hasMultipleFoldingAnimations and not savegame.resetVehicles then |
659 | spec.lastFoldingAnimation = savegame.xmlFile:getValue(savegame.key..".baleLoader#lastFoldingAnimation", spec.lastFoldingAnimation) |
660 | end |
661 | |
662 | if savegame.xmlFile:getValue(savegame.key..".baleLoader#isInWorkPosition", false) then |
663 | if not spec.isInWorkPosition then |
664 | spec.grabberIsMoving = true |
665 | spec.isInWorkPosition = true |
666 | BaleLoader.moveToWorkPosition(self, true) |
667 | end |
668 | else |
669 | BaleLoader.moveToTransportPosition(self) |
670 | end |
671 | |
672 | spec.startBalePlace.current = 1 |
673 | |
674 | spec.startBalePlace.count = 0 |
675 | local numBales = 0 |
676 | if not savegame.resetVehicles then |
677 | local i = 0 |
678 | while true do |
679 | local baleKey = savegame.key..string.format(".baleLoader.bale(%d)", i) |
680 | if not savegame.xmlFile:hasProperty(baleKey) then |
681 | break |
682 | end |
683 | local filename = savegame.xmlFile:getValue(baleKey.."#filename") |
684 | if filename ~= nil then |
685 | filename = NetworkUtil.convertFromNetworkFilename(filename) |
686 | |
687 | local x,y,z = savegame.xmlFile:getValue(baleKey.."#position") |
688 | local xRot,yRot,zRot = savegame.xmlFile:getValue(baleKey.."#rotation") |
689 | local balePlace = savegame.xmlFile:getValue(baleKey.."#balePlace") |
690 | local helper = savegame.xmlFile:getValue(baleKey.."#helper") |
691 | if balePlace == nil or (balePlace > 0 and (x == nil or y == nil or z == nil or xRot == nil or yRot == nil or zRot == nil)) or (balePlace < 1 and helper == nil) then |
692 | print("Warning: Corrupt savegame, bale "..filename.." could not be loaded") |
693 | else |
694 | local translation |
695 | local rotation |
696 | if balePlace > 0 then |
697 | translation = {x,y,z} |
698 | rotation={xRot, yRot, zRot} |
699 | else |
700 | translation = {0,0,0} |
701 | rotation={0,0,0} |
702 | end |
703 | local parentNode = nil |
704 | local bales = nil |
705 | if balePlace < 1 then |
706 | if spec.startBalePlace.node ~= nil and helper <= spec.startBalePlace.numOfPlaces then |
707 | parentNode = getChildAt(spec.startBalePlace.node, helper-1) |
708 | if spec.startBalePlace.bales == nil then |
709 | spec.startBalePlace.bales = {} |
710 | end |
711 | bales = spec.startBalePlace.bales |
712 | spec.startBalePlace.count = spec.startBalePlace.count+1 |
713 | end |
714 | elseif balePlace <= table.getn(spec.balePlaces) then |
715 | spec.startBalePlace.current = math.max(spec.startBalePlace.current, balePlace+1) |
716 | parentNode = spec.balePlaces[balePlace].node |
717 | if spec.balePlaces[balePlace].bales == nil then |
718 | spec.balePlaces[balePlace].bales = {} |
719 | end |
720 | bales = spec.balePlaces[balePlace].bales |
721 | end |
722 | if parentNode ~= nil then |
723 | local attributes = {} |
724 | Bale.loadBaleAttributesFromXMLFile(attributes, savegame.xmlFile, baleKey, savegame.resetVehicles) |
725 | |
726 | numBales = numBales + 1 |
727 | table.insert(spec.balesToLoad, {parentNode=parentNode, filename=filename, bales=bales, translation=translation, rotation=rotation, attributes=attributes}) |
728 | end |
729 | end |
730 | end |
731 | i = i +1 |
732 | end |
733 | end |
734 | |
735 | self:updateFoldingAnimation() |
736 | |
737 | -- update animations |
738 | BaleLoader.updateBalePlacesAnimations(self) |
739 | end |
740 | end |
onReadStream
DescriptionCalled on client side on joinDefinition
onReadStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
919 | function BaleLoader:onReadStream(streamId, connection) |
920 | local spec = self.spec_baleLoader |
921 | |
922 | spec.isInWorkPosition = streamReadBool(streamId) |
923 | spec.frontBalePusherDirection = streamReadIntN(streamId, 3) |
924 | spec.rotatePlatformDirection = streamReadIntN(streamId, 3) |
925 | |
926 | if streamReadBool(streamId) then |
927 | local currentBaleTypeIndex = streamReadIntN(streamId, 6) |
928 | self:setBaleLoaderBaleType(currentBaleTypeIndex) |
929 | end |
930 | |
931 | -- note: we do not sync grabberMoveState, this may lead to visual artifacts for a few seconds at the bigging |
932 | |
933 | if spec.isInWorkPosition then |
934 | BaleLoader.moveToWorkPosition(self) |
935 | end |
936 | |
937 | local emptyState = streamReadUIntN(streamId, 4) |
938 | |
939 | spec.startBalePlace.current = streamReadInt8(streamId) |
940 | |
941 | -- read bale at bale grabber |
942 | if streamReadBool(streamId) then |
943 | spec.baleGrabber.currentBale = NetworkUtil.readNodeObjectId(streamId) |
944 | spec.balesToMount[spec.baleGrabber.currentBale] = {serverId=spec.baleGrabber.currentBale, linkNode=spec.baleGrabber.grabNode, trans={0,0,0}, rot={0,0,0} } |
945 | end |
946 | |
947 | -- read bales at start bale places |
948 | spec.startBalePlace.count = streamReadUInt8(streamId) |
949 | for i=1, spec.startBalePlace.count do |
950 | local baleServerId = NetworkUtil.readNodeObjectId(streamId) |
951 | |
952 | local attachNode = getChildAt(spec.startBalePlace.node, i-1) |
953 | spec.balesToMount[baleServerId] = {serverId=baleServerId, linkNode=attachNode, trans={0,0,0}, rot={0,0,0} } |
954 | |
955 | table.insert(spec.startBalePlace.bales, baleServerId) |
956 | self:updateFoldingAnimation() |
957 | end |
958 | |
959 | |
960 | -- read bales at normal bale places |
961 | for i=1, table.getn(spec.balePlaces) do |
962 | local balePlace = spec.balePlaces[i] |
963 | |
964 | local numBales = streamReadUInt8(streamId) |
965 | if numBales > 0 then |
966 | balePlace.bales = {} |
967 | |
968 | for _=1, numBales do |
969 | local baleServerId = NetworkUtil.readNodeObjectId(streamId) |
970 | |
971 | local x, y, z = 0, 0, 0 |
972 | if not spec.dynamicMount.enabled then |
973 | local maxValue = 2 ^ spec.synchronizationNumBitsPosition - 1 |
974 | x = streamReadUIntN(streamId, spec.synchronizationNumBitsPosition) / maxValue * (spec.synchronizationMaxPosition * 2) - spec.synchronizationMaxPosition |
975 | y = streamReadUIntN(streamId, spec.synchronizationNumBitsPosition) / maxValue * (spec.synchronizationMaxPosition * 2) - spec.synchronizationMaxPosition |
976 | z = streamReadUIntN(streamId, spec.synchronizationNumBitsPosition) / maxValue * (spec.synchronizationMaxPosition * 2) - spec.synchronizationMaxPosition |
977 | end |
978 | |
979 | table.insert(balePlace.bales, baleServerId) |
980 | spec.balesToMount[baleServerId] = {serverId=baleServerId, linkNode=balePlace.node, trans={ x,y,z}, rot={0,0,0} } |
981 | end |
982 | end |
983 | end |
984 | |
985 | -- read num bales on platform |
986 | -- read bales on baleloader |
987 | -- ignore |
988 | |
989 | -- grabberMoveState ? int:nil |
990 | -- isInWorkPosition bool |
991 | -- emptyState ? int:nil |
992 | -- rotatePlatformDirection |
993 | -- frontBalePusherDirection |
994 | -- grabberIsMoving: bool |
995 | |
996 | |
997 | -- update animations |
998 | BaleLoader.updateBalePlacesAnimations(self) |
999 | |
1000 | if emptyState >= BaleLoader.EMPTY_TO_WORK then |
1001 | self:doStateChange(BaleLoader.CHANGE_EMPTY_START) |
1002 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1003 | if emptyState >= BaleLoader.EMPTY_ROTATE_PLATFORM then |
1004 | self:doStateChange(BaleLoader.CHANGE_EMPTY_ROTATE_PLATFORM) |
1005 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1006 | if emptyState >= BaleLoader.EMPTY_ROTATE1 then |
1007 | self:doStateChange(BaleLoader.CHANGE_EMPTY_ROTATE1) |
1008 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1009 | if emptyState >= BaleLoader.EMPTY_CLOSE_GRIPPERS then |
1010 | self:doStateChange(BaleLoader.CHANGE_EMPTY_CLOSE_GRIPPERS) |
1011 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1012 | if emptyState >= BaleLoader.EMPTY_HIDE_PUSHER1 then |
1013 | self:doStateChange(BaleLoader.CHANGE_EMPTY_HIDE_PUSHER1) |
1014 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1015 | if emptyState >= BaleLoader.EMPTY_HIDE_PUSHER2 then |
1016 | self:doStateChange(BaleLoader.CHANGE_EMPTY_HIDE_PUSHER2) |
1017 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1018 | if emptyState >= BaleLoader.EMPTY_ROTATE2 then |
1019 | self:doStateChange(BaleLoader.CHANGE_EMPTY_ROTATE2) |
1020 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1021 | if emptyState >= BaleLoader.EMPTY_WAIT_TO_DROP then |
1022 | self:doStateChange(BaleLoader.CHANGE_EMPTY_WAIT_TO_DROP) |
1023 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1024 | if emptyState == BaleLoader.EMPTY_CANCEL or emptyState == BaleLoader.EMPTY_WAIT_TO_REDO then |
1025 | self:doStateChange(BaleLoader.CHANGE_EMPTY_CANCEL) |
1026 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1027 | if emptyState == BaleLoader.EMPTY_WAIT_TO_REDO then |
1028 | self:doStateChange(BaleLoader.CHANGE_EMPTY_WAIT_TO_REDO) |
1029 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1030 | end |
1031 | elseif emptyState == BaleLoader.EMPTY_WAIT_TO_SINK or emptyState == BaleLoader.EMPTY_SINK then |
1032 | self:doStateChange(BaleLoader.CHANGE_DROP_BALES) |
1033 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1034 | |
1035 | if emptyState == BaleLoader.EMPTY_SINK then |
1036 | self:doStateChange(BaleLoader.CHANGE_SINK) |
1037 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1038 | end |
1039 | end |
1040 | end |
1041 | |
1042 | end |
1043 | end |
1044 | end |
1045 | end |
1046 | end |
1047 | end |
1048 | end |
1049 | spec.emptyState = emptyState |
1050 | end |
onReadUpdateStream
DescriptionDefinitiononReadUpdateStream()Code
1117 | function BaleLoader:onReadUpdateStream(streamId, timestamp, connection) |
1118 | local spec = self.spec_baleLoader |
1119 | |
1120 | if connection:getIsServer() then |
1121 | if streamReadBool(streamId) then |
1122 | local moverActive = streamReadBool(streamId) |
1123 | if moverActive ~= spec.unloadingMover.isActive then |
1124 | if moverActive then |
1125 | g_animationManager:startAnimations(spec.unloadingMover.animationNodes) |
1126 | g_soundManager:playSample(spec.samples.unload) |
1127 | else |
1128 | g_animationManager:stopAnimations(spec.unloadingMover.animationNodes) |
1129 | g_soundManager:stopSample(spec.samples.unload) |
1130 | end |
1131 | spec.unloadingMover.isActive = moverActive |
1132 | end |
1133 | end |
1134 | end |
1135 | end |
onRegisterActionEvents
DescriptionDefinitiononRegisterActionEvents()Code
3144 | function BaleLoader:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
3145 | if self.isClient then |
3146 | local spec = self.spec_baleLoader |
3147 | self:clearActionEventsTable(spec.actionEvents) |
3148 | |
3149 | if isActiveForInputIgnoreSelection then |
3150 | local _, actionEventId = self:addPoweredActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA3, self, BaleLoader.actionEventEmpty, false, true, false, true, nil) |
3151 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL) |
3152 | _, actionEventId = self:addPoweredActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA, self, BaleLoader.actionEventWorkTransport, false, true, false, true, nil) |
3153 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL) |
3154 | _, actionEventId = self:addPoweredActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA2, self, BaleLoader.actionEventAbortEmpty, false, true, false, true, nil) |
3155 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL) |
3156 | g_inputBinding:setActionEventText(actionEventId, spec.texts.abortUnloading) |
3157 | end |
3158 | end |
3159 | end |
onRegisterAnimationValueTypes
DescriptionCalled on pre load to register animation value typesDefinition
onRegisterAnimationValueTypes()Code
1776 | function BaleLoader:onRegisterAnimationValueTypes() |
1777 | local spec = self.spec_baleLoader |
1778 | |
1779 | self:registerAnimationValueType("baleLoaderAnimationNodes", "baleLoaderAnimationNodes", "", false, AnimationValueBool, |
1780 | function(value, xmlFile, xmlKey) |
1781 | return true |
1782 | end, |
1783 | function(value) |
1784 | return not spec.animationNodesBlocked |
1785 | end, |
1786 | |
1787 | function(value, state) |
1788 | spec.animationNodesBlocked = not state |
1789 | |
1790 | if not spec.animationNodesBlocked and spec.isInWorkPosition then |
1791 | g_animationManager:startAnimations(spec.animationNodes) |
1792 | g_soundManager:playSample(spec.samples.work) |
1793 | end |
1794 | |
1795 | if spec.animationNodesBlocked and spec.isInWorkPosition then |
1796 | g_animationManager:stopAnimations(spec.animationNodes) |
1797 | g_soundManager:stopSample(spec.samples.work) |
1798 | end |
1799 | end) |
1800 | end |
onRootVehicleChanged
DescriptionCalled if root vehicle changesDefinition
onRootVehicleChanged(table rootVehicle)Arguments
table | rootVehicle | root vehicle |
1731 | function BaleLoader:onRootVehicleChanged(rootVehicle) |
1732 | local spec = self.spec_baleLoader |
1733 | local actionController = rootVehicle.actionController |
1734 | if actionController ~= nil then |
1735 | if spec.controlledAction ~= nil then |
1736 | spec.controlledAction:updateParent(actionController) |
1737 | return |
1738 | end |
1739 | |
1740 | spec.controlledAction = actionController:registerAction("baleLoaderWorkstate", nil, 4) |
1741 | spec.controlledAction:setCallback(self, BaleLoader.actionControllerEvent) |
1742 | local finishedFunc = function(vehicle) |
1743 | return vehicle.spec_baleLoader.isInWorkPosition |
1744 | end |
1745 | spec.controlledAction:setFinishedFunctions(self, finishedFunc, true, false) |
1746 | spec.controlledAction:addAIEventListener(self, "onAIImplementPrepare", -1) |
1747 | else |
1748 | if spec.controlledAction ~= nil then |
1749 | spec.controlledAction:remove() |
1750 | end |
1751 | end |
1752 | end |
onUpdate
DescriptionCalled on updateDefinition
onUpdate(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 |
1187 | function BaleLoader:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
1188 | local spec = self.spec_baleLoader |
1189 | |
1190 | if self.finishedFirstUpdate then |
1191 | for k, baleToMount in pairs(spec.balesToMount) do |
1192 | local bale = NetworkUtil.getObject(baleToMount.serverId) |
1193 | if bale ~= nil then |
1194 | local x,y,z = unpack(baleToMount.trans) |
1195 | local rx,ry,rz = unpack(baleToMount.rot) |
1196 | |
1197 | if spec.dynamicMount.enabled then |
1198 | self:mountDynamicBale(bale, baleToMount.linkNode) |
1199 | else |
1200 | self:mountBale(bale, self, baleToMount.linkNode, x,y,z, rx,ry,rz) |
1201 | end |
1202 | |
1203 | local baleType = self:getBaleTypeByBale(bale) |
1204 | if baleType ~= nil then |
1205 | self:setBaleLoaderBaleType(baleType.index) |
1206 | end |
1207 | |
1208 | spec.balesToMount[k] = nil |
1209 | end |
1210 | end |
1211 | end |
1212 | |
1213 | if self.isClient then |
1214 | if spec.grabberEffectDisableTime ~= 0 and spec.grabberEffectDisableTime < g_currentMission.time then |
1215 | g_effectManager:stopEffects(spec.grabberEffects) |
1216 | spec.grabberEffectDisableTime = 0 |
1217 | end |
1218 | end |
1219 | |
1220 | -- check if grabber is still moving |
1221 | if spec.grabberIsMoving then |
1222 | if not self:getIsBaleLoaderFoldingPlaying() then |
1223 | spec.grabberIsMoving = false |
1224 | end |
1225 | end |
1226 | |
1227 | spec.showBaleNotSupportedWarning = false |
1228 | if self:getIsBaleGrabbingAllowed() then |
1229 | if spec.baleGrabber.grabNode ~= nil and spec.baleGrabber.currentBale == nil then |
1230 | -- find nearest bale |
1231 | local nearestBale, nearestBaleType, warning = BaleLoader.getBaleInRange(self, spec.baleGrabber.grabNode, spec.baleGrabber.balesInTrigger) |
1232 | if nearestBale ~= nil then |
1233 | if nearestBaleType == nil then |
1234 | spec.showBaleNotSupportedWarning = true |
1235 | spec.baleNotSupportedWarning = warning |
1236 | elseif self.isServer then |
1237 | self:pickupBale(nearestBale, nearestBaleType) |
1238 | end |
1239 | end |
1240 | end |
1241 | end |
1242 | if self.isServer then |
1243 | if spec.grabberMoveState ~= nil then |
1244 | if spec.grabberMoveState == BaleLoader.GRAB_MOVE_UP then |
1245 | if not self:getIsAnimationPlaying(spec.animations.baleGrabberWorkToDrop) then |
1246 | --BaleLoader.CHANGE_GRAB_MOVE_UP |
1247 | -- switch to grabberMoveState |
1248 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_GRAB_MOVE_UP), true, nil, self) |
1249 | end |
1250 | elseif spec.grabberMoveState == BaleLoader.GRAB_DROP_BALE then |
1251 | if not self:getIsAnimationPlaying(spec.currentBaleGrabberDropBaleAnimName) then |
1252 | --BaleLoader.CHANGE_GRAB_DROP_BALE |
1253 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_GRAB_DROP_BALE), true, nil, self) |
1254 | end |
1255 | elseif spec.grabberMoveState == BaleLoader.GRAB_MOVE_DOWN then |
1256 | --BaleLoader.CHANGE_GRAB_MOVE_DOWN |
1257 | local name = spec.animations.baleGrabberDropToWork or spec.animations.baleGrabberWorkToDrop |
1258 | if not self:getIsAnimationPlaying(name) then |
1259 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_GRAB_MOVE_DOWN), true, nil, self) |
1260 | self:setAnimationTime(spec.currentBaleGrabberDropBaleAnimName, 0, false) |
1261 | self:setAnimationTime(spec.animations.baleGrabberWorkToDrop, 0, false) |
1262 | end |
1263 | end |
1264 | end |
1265 | if spec.frontBalePusherDirection ~= 0 then |
1266 | if not self:getIsAnimationPlaying(spec.animations.frontBalePusher) then |
1267 | --BaleLoader.CHANGE_FRONT_PUSHER |
1268 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_FRONT_PUSHER), true, nil, self) |
1269 | end |
1270 | end |
1271 | if spec.rotatePlatformDirection ~= 0 then |
1272 | local name = spec.animations.rotatePlatform |
1273 | if spec.rotatePlatformDirection < 0 then |
1274 | name = spec.animations.rotatePlatformBack |
1275 | end |
1276 | if not self:getIsAnimationPlaying(name) and not self:getIsAnimationPlaying(spec.animations.moveBalePlacesExtrasOnce) and not spec.moveBalePlacesDelayedMovement then |
1277 | --BaleLoader.CHANGE_ROTATE_PLATFORM |
1278 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_ROTATE_PLATFORM), true, nil, self) |
1279 | end |
1280 | end |
1281 | |
1282 | if spec.emptyState ~= BaleLoader.EMPTY_NONE then |
1283 | if spec.emptyState == BaleLoader.EMPTY_TO_WORK then |
1284 | if not self:getIsBaleLoaderFoldingPlaying() then |
1285 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_ROTATE_PLATFORM), true, nil, self) |
1286 | end |
1287 | elseif spec.emptyState == BaleLoader.EMPTY_ROTATE_PLATFORM then |
1288 | if not self:getIsAnimationPlaying(spec.animations.rotatePlatformEmpty) then |
1289 | --BaleLoader.CHANGE_EMPTY_ROTATE1 |
1290 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_ROTATE1), true, nil, self) |
1291 | end |
1292 | elseif spec.emptyState == BaleLoader.EMPTY_ROTATE1 then |
1293 | if not self:getIsAnimationPlaying(spec.animations.emptyRotate) and not self:getIsAnimationPlaying(spec.animations.moveBalePlacesToEmpty) then |
1294 | --BaleLoader.CHANGE_EMPTY_CLOSE_GRIPPERS |
1295 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_CLOSE_GRIPPERS), true, nil, self) |
1296 | end |
1297 | elseif spec.emptyState == BaleLoader.EMPTY_CLOSE_GRIPPERS then |
1298 | if not self:getIsAnimationPlaying(spec.animations.closeGrippers) then |
1299 | --BaleLoader.CHANGE_EMPTY_HIDE_PUSHER1 |
1300 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_HIDE_PUSHER1), true, nil, self) |
1301 | end |
1302 | elseif spec.emptyState == BaleLoader.EMPTY_HIDE_PUSHER1 then |
1303 | if not self:getIsAnimationPlaying(spec.animations.pusherEmptyHide1) then |
1304 | --BaleLoader.CHANGE_EMPTY_HIDE_PUSHER2 |
1305 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_HIDE_PUSHER2), true, nil, self) |
1306 | end |
1307 | elseif spec.emptyState == BaleLoader.EMPTY_HIDE_PUSHER2 then |
1308 | if self:getAnimationTime(spec.animations.pusherMoveToEmpty) < 0.7 or not self:getIsAnimationPlaying(spec.animations.pusherMoveToEmpty) then |
1309 | --BaleLoader.CHANGE_EMPTY_ROTATE2 |
1310 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_ROTATE2), true, nil, self) |
1311 | end |
1312 | elseif spec.emptyState == BaleLoader.EMPTY_ROTATE2 then |
1313 | if not self:getIsAnimationPlaying(spec.animations.emptyRotate) then |
1314 | --BaleLoader.CHANGE_EMPTY_WAIT_TO_DROP |
1315 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_WAIT_TO_DROP), true, nil, self) |
1316 | end |
1317 | elseif spec.emptyState == BaleLoader.EMPTY_SINK then |
1318 | if not self:getIsAnimationPlaying(spec.animations.emptyRotate) and |
1319 | not self:getIsAnimationPlaying(spec.animations.moveBalePlacesToEmpty) and |
1320 | not self:getIsAnimationPlaying(spec.animations.pusherEmptyHide1) and |
1321 | not self:getIsAnimationPlaying(spec.animations.rotatePlatformEmpty) |
1322 | then |
1323 | --BaleLoader.CHANGE_EMPTY_STATE_NIL |
1324 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_STATE_NIL), true, nil, self) |
1325 | end |
1326 | elseif spec.emptyState == BaleLoader.EMPTY_CANCEL then |
1327 | if not self:getIsAnimationPlaying(spec.animations.emptyRotate) then |
1328 | --BaleLoader.CHANGE_EMPTY_WAIT_TO_REDO |
1329 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_EMPTY_WAIT_TO_REDO), true, nil, self) |
1330 | end |
1331 | end |
1332 | end |
1333 | end |
1334 | |
1335 | -- re mount bale in grabber, which was unmounted to be saved as normal bale |
1336 | if spec.baleGrabber.currentBaleIsUnmounted then |
1337 | spec.baleGrabber.currentBaleIsUnmounted = false |
1338 | local bale = NetworkUtil.getObject(spec.baleGrabber.currentBale) |
1339 | if bale ~= nil then |
1340 | if spec.dynamicMount.enabled then |
1341 | self:mountDynamicBale(bale, spec.baleGrabber.grabNode) |
1342 | else |
1343 | self:mountBale(bale, self, spec.baleGrabber.grabNode, 0,0,0, 0,0,0) |
1344 | end |
1345 | |
1346 | bale:setCanBeSold(false) |
1347 | end |
1348 | end |
1349 | 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 |
1356 | function BaleLoader:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
1357 | local spec = self.spec_baleLoader |
1358 | |
1359 | if self.isClient then |
1360 | local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA] |
1361 | if actionEvent ~= nil then |
1362 | local showAction = false |
1363 | if spec.emptyState == BaleLoader.EMPTY_NONE then |
1364 | if spec.grabberMoveState == nil then |
1365 | if spec.isInWorkPosition then |
1366 | g_inputBinding:setActionEventText(actionEvent.actionEventId, spec.texts.transportPosition) |
1367 | showAction = true |
1368 | else |
1369 | g_inputBinding:setActionEventText(actionEvent.actionEventId, spec.texts.operatingPosition) |
1370 | showAction = true |
1371 | end |
1372 | end |
1373 | end |
1374 | |
1375 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, showAction) |
1376 | end |
1377 | |
1378 | actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA2] |
1379 | if actionEvent ~= nil then |
1380 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, spec.emptyState == BaleLoader.EMPTY_WAIT_TO_DROP) |
1381 | end |
1382 | |
1383 | actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA3] |
1384 | if actionEvent ~= nil then |
1385 | local showAction = false |
1386 | |
1387 | if spec.emptyState == BaleLoader.EMPTY_NONE then |
1388 | if BaleLoader.getAllowsStartUnloading(self) then |
1389 | g_inputBinding:setActionEventText(actionEvent.actionEventId, spec.texts.unload) |
1390 | showAction = true |
1391 | end |
1392 | elseif spec.emptyState == BaleLoader.EMPTY_WAIT_TO_DROP then |
1393 | g_inputBinding:setActionEventText(actionEvent.actionEventId, spec.texts.unloadHere) |
1394 | showAction = true |
1395 | elseif spec.emptyState == BaleLoader.EMPTY_WAIT_TO_SINK then |
1396 | if not spec.unloadingMover.isActive then |
1397 | g_inputBinding:setActionEventText(actionEvent.actionEventId, spec.texts.lowerPlattform) |
1398 | showAction = true |
1399 | end |
1400 | elseif spec.emptyState == BaleLoader.EMPTY_WAIT_TO_REDO then |
1401 | g_inputBinding:setActionEventText(actionEvent.actionEventId, spec.texts.unload) |
1402 | showAction = true |
1403 | end |
1404 | |
1405 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, showAction) |
1406 | end |
1407 | end |
1408 | |
1409 | if self.isServer then |
1410 | if spec.automaticUnloading or spec.automaticUnloadingInProgress then |
1411 | if spec.emptyState == BaleLoader.EMPTY_WAIT_TO_DROP then |
1412 | self:doStateChange(BaleLoader.CHANGE_BUTTON_EMPTY) |
1413 | end |
1414 | |
1415 | local isPlaying = self:getIsAnimationPlaying(spec.animations.releaseFrontPlatform) |
1416 | if spec.emptyState == BaleLoader.EMPTY_WAIT_TO_SINK and not isPlaying and not spec.unloadingMover.isActive then |
1417 | self:doStateChange(BaleLoader.CHANGE_SINK) |
1418 | end |
1419 | end |
1420 | |
1421 | if #spec.baleJoints > 0 then |
1422 | local removeJoints = false |
1423 | |
1424 | if spec.dynamicBaleUnloading.useUnloadingMoverTrigger then |
1425 | if spec.unloadingMover.frameDelay == 0 and next(spec.unloadingMover.balesInTrigger) == nil then |
1426 | removeJoints = true |
1427 | end |
1428 | end |
1429 | |
1430 | -- if both requirements are defined, both needs to be true |
1431 | if spec.dynamicBaleUnloading.useUnloadingMoverTrigger == nil or removeJoints then |
1432 | removeJoints = false |
1433 | if spec.dynamicBaleUnloading.releaseAnimation ~= nil then |
1434 | local animation = spec.dynamicBaleUnloading.releaseAnimation |
1435 | if self:getAnimationTime(animation) >= spec.dynamicBaleUnloading.releaseAnimationTime or not self:getIsAnimationPlaying(animation) then |
1436 | removeJoints = true |
1437 | end |
1438 | end |
1439 | end |
1440 | |
1441 | if removeJoints then |
1442 | for i=#spec.baleJoints, 1, -1 do |
1443 | removeJoint(spec.baleJoints[i]) |
1444 | spec.baleJoints[i] = nil |
1445 | end |
1446 | end |
1447 | end |
1448 | |
1449 | if spec.unloadingMover.isActive then |
1450 | spec.unloadingMover.frameDelay = math.max(spec.unloadingMover.frameDelay - 1, 0) |
1451 | if spec.unloadingMover.frameDelay == 0 and next(spec.unloadingMover.balesInTrigger) == nil then |
1452 | spec.unloadingMover.isActive = false |
1453 | |
1454 | for i=1, #spec.unloadingMover.nodes do |
1455 | setFrictionVelocity(spec.unloadingMover.nodes[i].node, 0) |
1456 | end |
1457 | |
1458 | if self.isClient then |
1459 | g_animationManager:stopAnimations(spec.unloadingMover.animationNodes) |
1460 | g_soundManager:stopSample(spec.samples.unload) |
1461 | end |
1462 | |
1463 | self:raiseDirtyFlags(spec.unloadingMover.dirtyFlag) |
1464 | end |
1465 | end |
1466 | |
1467 | if spec.dynamicMount.enabled then |
1468 | local jointNodePositionChanged = false |
1469 | -- move bale smoothly to the joint position |
1470 | for i, jointNode in ipairs(spec.dynamicMount.baleJointsToUpdate) do |
1471 | if jointNode.quaternion == nil then |
1472 | local qx, qy, qz, qw = getQuaternion(jointNode.node) |
1473 | jointNode.quaternion = {qx, qy, qz, qw} |
1474 | end |
1475 | |
1476 | if jointNode.time < spec.dynamicMount.jointInterpolationTimeRot then |
1477 | jointNode.time = jointNode.time + dt |
1478 | local qx, qy, qz, qw = 0, 0, 0, 1 |
1479 | if math.abs(jointNode.quaternion[2]) > 0.5 then |
1480 | qx, qy, qz, qw = MathUtil.slerpQuaternionShortestPath(jointNode.quaternion[1], jointNode.quaternion[2], jointNode.quaternion[3], jointNode.quaternion[4], 0, 1, 0, 0, jointNode.time/spec.dynamicMount.jointInterpolationTimeRot) |
1481 | elseif math.abs(jointNode.quaternion[2]) < 0.5 then |
1482 | qx, qy, qz, qw = MathUtil.slerpQuaternionShortestPath(jointNode.quaternion[1], jointNode.quaternion[2], jointNode.quaternion[3], jointNode.quaternion[4], 0, 0, 0, 1, jointNode.time/spec.dynamicMount.jointInterpolationTimeRot) |
1483 | end |
1484 | setQuaternion(jointNode.node, qx, qy, qz, qw) |
1485 | jointNodePositionChanged = true |
1486 | end |
1487 | |
1488 | local x, y, z = getTranslation(jointNode.node) |
1489 | if math.abs(x)+math.abs(y)+math.abs(z) > 0.001 then |
1490 | local move = spec.dynamicMount.jointInterpolationSpeedTrans * dt |
1491 | |
1492 | local function moveValue(old) |
1493 | local limit = MathUtil.sign(old) > 0 and math.max or math.min |
1494 | return limit(old-MathUtil.sign(old)*move, 0) |
1495 | end |
1496 | |
1497 | setTranslation(jointNode.node, moveValue(x), moveValue(y), moveValue(z)) |
1498 | |
1499 | jointNodePositionChanged = true |
1500 | elseif jointNode.time > spec.dynamicMount.jointInterpolationTimeRot then |
1501 | table.remove(spec.dynamicMount.baleJointsToUpdate, i) |
1502 | end |
1503 | end |
1504 | |
1505 | -- update dynamic bale joints as soon one of the available animations is playing |
1506 | local anyAnimationPlaying = false |
1507 | for name,_ in pairs(self.spec_animatedVehicle.animations) do |
1508 | if self:getIsAnimationPlaying(name) then |
1509 | anyAnimationPlaying = true |
1510 | end |
1511 | end |
1512 | |
1513 | if anyAnimationPlaying or jointNodePositionChanged or spec.dynamicMount.baleMassDirty then |
1514 | for _, balePlace in pairs(spec.balePlaces) do |
1515 | if balePlace.bales ~= nil then |
1516 | for _, baleServerId in pairs(balePlace.bales) do |
1517 | local bale = NetworkUtil.getObject(baleServerId) |
1518 | if bale ~= nil then |
1519 | if bale.dynamicMountJointIndex ~= nil then |
1520 | setJointFrame(bale.dynamicMountJointIndex, 0, bale.baleLoaderDynamicJointNode) |
1521 | end |
1522 | |
1523 | if bale.backupMass == nil then |
1524 | local mass = getMass(bale.nodeId) |
1525 | if mass ~= 1 then |
1526 | bale.backupMass = mass |
1527 | setMass(bale.nodeId, 0.1) |
1528 | spec.dynamicMount.baleMassDirty = false |
1529 | end |
1530 | end |
1531 | end |
1532 | end |
1533 | end |
1534 | end |
1535 | |
1536 | if spec.startBalePlace ~= nil then |
1537 | for _, baleServerId in ipairs(spec.startBalePlace.bales) do |
1538 | local bale = NetworkUtil.getObject(baleServerId) |
1539 | if bale ~= nil then |
1540 | if bale.dynamicMountJointIndex ~= nil then |
1541 | setJointFrame(bale.dynamicMountJointIndex, 0, bale.baleLoaderDynamicJointNode) |
1542 | end |
1543 | |
1544 | if bale.backupMass == nil then |
1545 | local mass = getMass(bale.nodeId) |
1546 | if mass ~= 1 then |
1547 | bale.backupMass = mass |
1548 | setMass(bale.nodeId, 0.1) |
1549 | spec.dynamicMount.baleMassDirty = false |
1550 | end |
1551 | end |
1552 | end |
1553 | end |
1554 | end |
1555 | |
1556 | if spec.baleGrabber.currentBale ~= nil then |
1557 | local bale = NetworkUtil.getObject(spec.baleGrabber.currentBale) |
1558 | if bale ~= nil then |
1559 | if bale.dynamicMountJointIndex ~= nil then |
1560 | setJointFrame(bale.dynamicMountJointIndex, 0, bale.baleLoaderDynamicJointNode) |
1561 | end |
1562 | end |
1563 | end |
1564 | end |
1565 | end |
1566 | end |
1567 | |
1568 | if spec.moveBalePlacesDelayedMovement then |
1569 | if self:getAnimationTime(spec.animations.baleGrabberWorkToDrop) < spec.animations.moveBalePlacesMaxGrabberTime then |
1570 | spec.rotatePlatformDirection = -1 |
1571 | self:playAnimation(spec.animations.rotatePlatformBack, -1, nil, true) |
1572 | |
1573 | if spec.animations.moveBalePlacesAfterRotatePlatform then |
1574 | -- startBalePlace.current+1 needs to be at the first position |
1575 | if spec.startBalePlace ~= nil and spec.startBalePlace.current <= #spec.balePlaces or spec.animations.moveBalePlacesAlways then |
1576 | self:playAnimation(spec.animations.moveBalePlaces, 1, (spec.startBalePlace.current-1)/#spec.balePlaces, true) |
1577 | self:setAnimationStopTime(spec.animations.moveBalePlaces, (spec.startBalePlace.current)/#spec.balePlaces) |
1578 | self:playAnimation(spec.animations.moveBalePlacesExtrasOnce, 1, nil, true) |
1579 | end |
1580 | end |
1581 | |
1582 | spec.moveBalePlacesDelayedMovement = nil |
1583 | end |
1584 | end |
1585 | |
1586 | if spec.animations.moveBalePlacesToEmptyPushOffsetTime > 0 then |
1587 | spec.animations.moveBalePlacesToEmptyPushOffsetTime = spec.animations.moveBalePlacesToEmptyPushOffsetTime - dt |
1588 | if spec.animations.moveBalePlacesToEmptyPushOffsetTime <= 0 then |
1589 | local balePlacesTime = self:getRealAnimationTime(spec.animations.moveBalePlaces) |
1590 | local duration = self:getAnimationDuration(spec.animations.moveBalePlacesToEmpty) |
1591 | local startTime = balePlacesTime / duration |
1592 | local speedFactor = (duration - balePlacesTime) / (duration - balePlacesTime - spec.animations.moveBalePlacesToEmptyPushOffsetDelay * spec.animations.moveBalePlacesToEmptySpeed) |
1593 | |
1594 | local speed = spec.animations.moveBalePlacesToEmptySpeed * speedFactor |
1595 | self:playAnimation(spec.animations.moveBalePlacesToEmpty, speed, startTime, true) |
1596 | spec.animations.moveBalePlacesToEmptyPushOffsetTime = 0 |
1597 | end |
1598 | end |
1599 | end |
onWriteStream
DescriptionCalled on server side on joinDefinition
onWriteStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
1056 | function BaleLoader:onWriteStream(streamId, connection) |
1057 | local spec = self.spec_baleLoader |
1058 | |
1059 | streamWriteBool(streamId, spec.isInWorkPosition) |
1060 | streamWriteIntN(streamId, spec.frontBalePusherDirection, 3) |
1061 | streamWriteIntN(streamId, spec.rotatePlatformDirection, 3) |
1062 | |
1063 | if streamWriteBool(streamId, spec.currentBaleType ~= nil) then |
1064 | streamWriteIntN(streamId, spec.currentBaleType.index or 1, 6) |
1065 | end |
1066 | |
1067 | streamWriteUIntN(streamId, spec.emptyState, 4) |
1068 | |
1069 | streamWriteInt8(streamId, spec.startBalePlace.current) |
1070 | |
1071 | -- write bale at bale grabber |
1072 | if streamWriteBool(streamId, spec.baleGrabber.currentBale ~= nil) then |
1073 | NetworkUtil.writeNodeObjectId(streamId, spec.baleGrabber.currentBale) |
1074 | end |
1075 | |
1076 | -- write bales at start bale places |
1077 | streamWriteUInt8(streamId, spec.startBalePlace.count) |
1078 | for i=1, spec.startBalePlace.count do |
1079 | local baleServerId = spec.startBalePlace.bales[i] |
1080 | NetworkUtil.writeNodeObjectId(streamId, baleServerId) |
1081 | end |
1082 | |
1083 | -- write bales at normal bale places |
1084 | for i=1, table.getn(spec.balePlaces) do |
1085 | local balePlace = spec.balePlaces[i] |
1086 | |
1087 | local numBales = 0 |
1088 | if balePlace.bales ~= nil then |
1089 | numBales = table.getn(balePlace.bales) |
1090 | end |
1091 | streamWriteUInt8(streamId, numBales) |
1092 | if balePlace.bales ~= nil then |
1093 | for baleI=1, numBales do |
1094 | local baleServerId = balePlace.bales[baleI] |
1095 | local bale = NetworkUtil.getObject(baleServerId) |
1096 | local nodeId = bale.nodeId |
1097 | local x, y, z = getTranslation(nodeId) |
1098 | NetworkUtil.writeNodeObjectId(streamId, baleServerId) |
1099 | |
1100 | if not spec.dynamicMount.enabled then |
1101 | if math.abs(x) > spec.synchronizationMaxPosition or math.abs(y) > spec.synchronizationMaxPosition or math.abs(z) > spec.synchronizationMaxPosition then |
1102 | Logging.xmlWarning(self.xmlFile, "Position of bale '%d' could not be synchronized correctly. Position out of range (%.2f, %.2f, %.2f) > %.2f. Increase 'vehicle.baleLoader.synchronization#maxPosition'", baleI, x, y, z, spec.synchronizationMaxPosition) |
1103 | end |
1104 | |
1105 | local maxValue = 2 ^ spec.synchronizationNumBitsPosition - 1 |
1106 | streamWriteUIntN(streamId, ((spec.synchronizationMaxPosition + x) / (spec.synchronizationMaxPosition * 2)) * maxValue, spec.synchronizationNumBitsPosition) |
1107 | streamWriteUIntN(streamId, ((spec.synchronizationMaxPosition + y) / (spec.synchronizationMaxPosition * 2)) * maxValue, spec.synchronizationNumBitsPosition) |
1108 | streamWriteUIntN(streamId, ((spec.synchronizationMaxPosition + z) / (spec.synchronizationMaxPosition * 2)) * maxValue, spec.synchronizationNumBitsPosition) |
1109 | end |
1110 | end |
1111 | end |
1112 | end |
1113 | end |
onWriteUpdateStream
DescriptionDefinitiononWriteUpdateStream()Code
1139 | function BaleLoader:onWriteUpdateStream(streamId, connection, dirtyMask) |
1140 | local spec = self.spec_baleLoader |
1141 | |
1142 | if not connection:getIsServer() then |
1143 | if streamWriteBool(streamId, bitAND(dirtyMask, spec.unloadingMover.dirtyFlag) ~= 0) then |
1144 | streamWriteBool(streamId, spec.unloadingMover.isActive) |
1145 | end |
1146 | end |
1147 | end |
pickupBale
DescriptionPickup baleDefinition
pickupBale(table nearestBale, integer nearestBaleType)Arguments
table | nearestBale | nearest bale |
integer | nearestBaleType | nearest bale type |
2624 | function BaleLoader:pickupBale(nearestBale, nearestBaleType) |
2625 | local spec = self.spec_baleLoader |
2626 | spec.lastPickupTime = g_time |
2627 | |
2628 | self:setBaleLoaderBaleType(nearestBaleType.index) |
2629 | |
2630 | g_server:broadcastEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_GRAB_BALE, NetworkUtil.getObjectId(nearestBale)), true, nil, self) |
2631 | end |
playBaleLoaderFoldingAnimation
DescriptionDefinitionplayBaleLoaderFoldingAnimation()Code
2966 | function BaleLoader:playBaleLoaderFoldingAnimation(speed) |
2967 | local animationName = self:getCurrentFoldingAnimation() |
2968 | self:playAnimation(animationName, speed, MathUtil.clamp(self:getAnimationTime(animationName), 0, 1), true) |
2969 | 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 |
18 | function BaleLoader.prerequisitesPresent(specializations) |
19 | return SpecializationUtil.hasSpecialization(FillUnit, specializations) |
20 | end |
registerAnimationXMLPaths
DescriptionDefinitionregisterAnimationXMLPaths()Code
161 | function BaleLoader.registerAnimationXMLPaths(schema, basePath) |
162 | schema:register(XMLValueType.STRING, basePath .. ".animations.platform#rotate", "Rotate platform animation name", "rotatePlatform") |
163 | schema:register(XMLValueType.STRING, basePath .. ".animations.platform#rotateBack", "Rotate platform back animation name", "rotatePlatform") |
164 | schema:register(XMLValueType.STRING, basePath .. ".animations.platform#rotateEmpty", "Rotate platform empty animation name", "rotatePlatform") |
165 | schema:register(XMLValueType.BOOL, basePath .. ".animations.platform#allowPickupWhileMoving", "Allow pickup of next bale while platform is rotating", false) |
166 | |
167 | schema:register(XMLValueType.FLOAT, basePath .. ".animations.baleGrabber#dropBaleReverseSpeed", "Speed of grabber in reverse", 5) |
168 | schema:register(XMLValueType.STRING, basePath .. ".animations.baleGrabber#dropToWork", "Custom grabber animation when moving from drop to work") |
169 | schema:register(XMLValueType.STRING, basePath .. ".animations.baleGrabber#workToDrop", "Bale grabber work to drop animation", "baleGrabberWorkToDrop") |
170 | schema:register(XMLValueType.STRING, basePath .. ".animations.baleGrabber#dropBale", "Bale grabber drop bale animation", "baleGrabberDropBale") |
171 | schema:register(XMLValueType.STRING, basePath .. ".animations.baleGrabber#transportToWork", "Transport to work animation", "baleGrabberTransportToWork") |
172 | |
173 | schema:register(XMLValueType.STRING, basePath .. ".animations.pusher#emptyHide", "Empty hide animation", "emptyHidePusher1") |
174 | schema:register(XMLValueType.STRING, basePath .. ".animations.pusher#moveToEmpty", "Move to empty position", "moveBalePusherToEmpty") |
175 | schema:register(XMLValueType.BOOL, basePath .. ".animations.pusher#hidePusherOnEmpty", "Reverse move to empty animation after execution", true) |
176 | schema:register(XMLValueType.BOOL, basePath .. ".animations.pusher#pushBalesOnEmpty", "Defines if bale are pushed or pulled on empty", false) |
177 | |
178 | schema:register(XMLValueType.STRING, basePath .. ".animations.releaseFrontPlatform#name", "Release front platform animation name", "releaseFrontplattform") |
179 | schema:register(XMLValueType.BOOL, basePath .. ".animations.releaseFrontPlatform#fillLevelSpeed", "Front platform speed is dependent on fill level", false) |
180 | |
181 | schema:register(XMLValueType.STRING, basePath .. ".animations.moveBalePlaces#name", "Move bale places animation", "moveBalePlaces") |
182 | schema:register(XMLValueType.STRING, basePath .. ".animations.moveBalePlaces#extrasOnce", "Move bale places extra once animation", "moveBalePlaces") |
183 | schema:register(XMLValueType.STRING, basePath .. ".animations.moveBalePlaces#empty", "Move bale places empty animation", "moveBalePlaces") |
184 | schema:register(XMLValueType.FLOAT, basePath .. ".animations.moveBalePlaces#emptySpeed", "Speed of move bale places to empty", 1.5) |
185 | schema:register(XMLValueType.FLOAT, basePath .. ".animations.moveBalePlaces#emptyReverseSpeed", "Reverse speed of move bale places to empty", -1) |
186 | schema:register(XMLValueType.FLOAT, basePath .. ".animations.moveBalePlaces#pushOffset", "Delay of empty animation to give pusher time to move to the last bale", 0) |
187 | |
188 | schema:register(XMLValueType.BOOL, basePath .. ".animations.moveBalePlaces#moveAfterRotatePlatform", "Move bale places after rotate platform", false) |
189 | schema:register(XMLValueType.BOOL, basePath .. ".animations.moveBalePlaces#resetOnSink", "Reset move bale places on platform sink", false) |
190 | schema:register(XMLValueType.FLOAT, basePath .. ".animations.moveBalePlaces#maxGrabberTime", "Max. grabber time to move bale places", "inf") |
191 | schema:register(XMLValueType.BOOL, basePath .. ".animations.moveBalePlaces#alwaysMove", "Always move bale places", false) |
192 | |
193 | schema:register(XMLValueType.STRING, basePath .. ".animations.emptyRotate#name", "Empty rotate", "emptyRotate") |
194 | schema:register(XMLValueType.BOOL, basePath .. ".animations.emptyRotate#reset", "Reset empty rotate animation", true) |
195 | |
196 | schema:register(XMLValueType.STRING, basePath .. ".animations#frontBalePusher", "Front bale pusher animation", "frontBalePusher") |
197 | schema:register(XMLValueType.STRING, basePath .. ".animations#balesToOtherRow", "Bales to othe row animation", "balesToOtherRow") |
198 | schema:register(XMLValueType.STRING, basePath .. ".animations#closeGrippers", "Close grippers animation", "closeGrippers") |
199 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
322 | function BaleLoader.registerEventListeners(vehicleType) |
323 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", BaleLoader) |
324 | SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", BaleLoader) |
325 | SpecializationUtil.registerEventListener(vehicleType, "onLoadFinished", BaleLoader) |
326 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", BaleLoader) |
327 | SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", BaleLoader) |
328 | SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", BaleLoader) |
329 | SpecializationUtil.registerEventListener(vehicleType, "onReadStream", BaleLoader) |
330 | SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", BaleLoader) |
331 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", BaleLoader) |
332 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", BaleLoader) |
333 | SpecializationUtil.registerEventListener(vehicleType, "onDraw", BaleLoader) |
334 | SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", BaleLoader) |
335 | SpecializationUtil.registerEventListener(vehicleType, "onActivate", BaleLoader) |
336 | SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", BaleLoader) |
337 | SpecializationUtil.registerEventListener(vehicleType, "onRootVehicleChanged", BaleLoader) |
338 | SpecializationUtil.registerEventListener(vehicleType, "onFillUnitFillLevelChanged", BaleLoader) |
339 | SpecializationUtil.registerEventListener(vehicleType, "onRegisterAnimationValueTypes", BaleLoader) |
340 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
274 | function BaleLoader.registerFunctions(vehicleType) |
275 | SpecializationUtil.registerFunction(vehicleType, "loadBaleTypeFromXML", BaleLoader.loadBaleTypeFromXML) |
276 | SpecializationUtil.registerFunction(vehicleType, "loadBalePlacesFromXML", BaleLoader.loadBalePlacesFromXML) |
277 | SpecializationUtil.registerFunction(vehicleType, "loadBaleLoaderAnimationsFromXML", BaleLoader.loadBaleLoaderAnimationsFromXML) |
278 | |
279 | SpecializationUtil.registerFunction(vehicleType, "createBaleToBaleJoints", BaleLoader.createBaleToBaleJoints) |
280 | SpecializationUtil.registerFunction(vehicleType, "createBaleToBaleJoint", BaleLoader.createBaleToBaleJoint) |
281 | SpecializationUtil.registerFunction(vehicleType, "doStateChange", BaleLoader.doStateChange) |
282 | SpecializationUtil.registerFunction(vehicleType, "getBaleGrabberDropBaleAnimName", BaleLoader.getBaleGrabberDropBaleAnimName) |
283 | SpecializationUtil.registerFunction(vehicleType, "getIsBaleGrabbingAllowed", BaleLoader.getIsBaleGrabbingAllowed) |
284 | SpecializationUtil.registerFunction(vehicleType, "pickupBale", BaleLoader.pickupBale) |
285 | SpecializationUtil.registerFunction(vehicleType, "setBaleLoaderBaleType", BaleLoader.setBaleLoaderBaleType) |
286 | SpecializationUtil.registerFunction(vehicleType, "getBaleTypeByBale", BaleLoader.getBaleTypeByBale) |
287 | SpecializationUtil.registerFunction(vehicleType, "baleGrabberTriggerCallback", BaleLoader.baleGrabberTriggerCallback) |
288 | SpecializationUtil.registerFunction(vehicleType, "baleLoaderMoveTriggerCallback", BaleLoader.baleLoaderMoveTriggerCallback) |
289 | SpecializationUtil.registerFunction(vehicleType, "mountDynamicBale", BaleLoader.mountDynamicBale) |
290 | SpecializationUtil.registerFunction(vehicleType, "unmountDynamicBale", BaleLoader.unmountDynamicBale) |
291 | SpecializationUtil.registerFunction(vehicleType, "mountBale", BaleLoader.mountBale) |
292 | SpecializationUtil.registerFunction(vehicleType, "unmountBale", BaleLoader.unmountBale) |
293 | SpecializationUtil.registerFunction(vehicleType, "setBalePairCollision", BaleLoader.setBalePairCollision) |
294 | SpecializationUtil.registerFunction(vehicleType, "getLoadedBales", BaleLoader.getLoadedBales) |
295 | SpecializationUtil.registerFunction(vehicleType, "startAutomaticBaleUnloading", BaleLoader.startAutomaticBaleUnloading) |
296 | SpecializationUtil.registerFunction(vehicleType, "getIsAutomaticBaleUnloadingInProgress", BaleLoader.getIsAutomaticBaleUnloadingInProgress) |
297 | SpecializationUtil.registerFunction(vehicleType, "getIsAutomaticBaleUnloadingAllowed", BaleLoader.getIsAutomaticBaleUnloadingAllowed) |
298 | SpecializationUtil.registerFunction(vehicleType, "playBaleLoaderFoldingAnimation", BaleLoader.playBaleLoaderFoldingAnimation) |
299 | SpecializationUtil.registerFunction(vehicleType, "getIsBaleLoaderFoldingPlaying", BaleLoader.getIsBaleLoaderFoldingPlaying) |
300 | SpecializationUtil.registerFunction(vehicleType, "getCurrentFoldingAnimation", BaleLoader.getCurrentFoldingAnimation) |
301 | SpecializationUtil.registerFunction(vehicleType, "updateFoldingAnimation", BaleLoader.updateFoldingAnimation) |
302 | SpecializationUtil.registerFunction(vehicleType, "onBaleMoverBaleRemoved", BaleLoader.onBaleMoverBaleRemoved) |
303 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
307 | function BaleLoader.registerOverwrittenFunctions(vehicleType) |
308 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", BaleLoader.getCanBeSelected) |
309 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAllowDynamicMountFillLevelInfo", BaleLoader.getAllowDynamicMountFillLevelInfo) |
310 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "addNodeObjectMapping", BaleLoader.addNodeObjectMapping) |
311 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "removeNodeObjectMapping", BaleLoader.removeNodeObjectMapping) |
312 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAreControlledActionsAllowed", BaleLoader.getAreControlledActionsAllowed) |
313 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsAIReadyToDrive", BaleLoader.getIsAIReadyToDrive) |
314 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsAIPreparingToDrive", BaleLoader.getIsAIPreparingToDrive) |
315 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDoConsumePtoPower", BaleLoader.getDoConsumePtoPower) |
316 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getConsumingLoad", BaleLoader.getConsumingLoad) |
317 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsPowerTakeOffActive", BaleLoader.getIsPowerTakeOffActive) |
318 | end |
removeNodeObjectMapping
DescriptionDefinitionremoveNodeObjectMapping()Code
3062 | function BaleLoader:removeNodeObjectMapping(superFunc, list) |
3063 | superFunc(self, list) |
3064 | |
3065 | local spec = self.spec_baleLoader |
3066 | if spec.baleGrabber ~= nil and spec.baleGrabber.trigger ~= nil then |
3067 | list[spec.baleGrabber.trigger] = nil |
3068 | end |
3069 | end |
rotatePlatform
DescriptionRotate bale loader platformDefinition
rotatePlatform()Code
2525 | function BaleLoader.rotatePlatform(self) |
2526 | local spec = self.spec_baleLoader |
2527 | |
2528 | spec.rotatePlatformDirection = 1 |
2529 | self:playAnimation(spec.animations.rotatePlatform, 1, nil, true) |
2530 | |
2531 | if (spec.startBalePlace.current > 1 and not spec.animations.moveBalePlacesAfterRotatePlatform) or spec.animations.moveBalePlacesAlways then |
2532 | -- startBalePlace.current needs to be at the first position |
2533 | self:playAnimation(spec.animations.moveBalePlaces, 1, (spec.startBalePlace.current-1)/table.getn(spec.balePlaces), true) |
2534 | self:setAnimationStopTime(spec.animations.moveBalePlaces, (spec.startBalePlace.current)/table.getn(spec.balePlaces)) |
2535 | self:playAnimation(spec.animations.moveBalePlacesExtrasOnce, 1, nil, true) |
2536 | end |
2537 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
854 | function BaleLoader:saveToXMLFile(xmlFile, key, usedModNames) |
855 | local spec = self.spec_baleLoader |
856 | |
857 | xmlFile:setValue(key.."#isInWorkPosition", spec.isInWorkPosition) |
858 | |
859 | if spec.currentBaleType ~= nil then |
860 | xmlFile:setValue(key.."#baleTypeIndex", spec.currentBaleType.index) |
861 | end |
862 | |
863 | local baleIndex = 0 |
864 | for i, balePlace in pairs(spec.balePlaces) do |
865 | if balePlace.bales ~= nil then |
866 | for _, baleServerId in pairs(balePlace.bales) do |
867 | local bale = NetworkUtil.getObject(baleServerId) |
868 | if bale ~= nil then |
869 | local baleKey = string.format("%s.bale(%d)", key, baleIndex) |
870 | bale:saveToXMLFile(xmlFile, baleKey) |
871 | |
872 | local startBaleEmpty = table.getn(spec.startBalePlace.bales) == 0 |
873 | local loadPlaceEmpty = self:getFillUnitFillLevel(spec.fillUnitIndex) % spec.startBalePlace.numOfPlaces ~= 0 |
874 | local lastItem = (math.floor(self:getFillUnitFillLevel(spec.fillUnitIndex) / spec.startBalePlace.numOfPlaces) + 1) == i |
875 | local evenCapacity = self:getFillUnitCapacity(spec.fillUnitIndex) % 2 == 0 |
876 | if startBaleEmpty and loadPlaceEmpty and lastItem and evenCapacity then |
877 | xmlFile:setValue(baleKey.."#balePlace", 0) |
878 | xmlFile:setValue(baleKey.."#helper", 1) |
879 | else |
880 | xmlFile:setValue(baleKey.."#balePlace", i) |
881 | end |
882 | |
883 | baleIndex = baleIndex + 1 |
884 | end |
885 | end |
886 | end |
887 | end |
888 | |
889 | for i, baleServerId in ipairs(spec.startBalePlace.bales) do |
890 | local bale = NetworkUtil.getObject(baleServerId) |
891 | if bale ~= nil then |
892 | local baleKey = string.format("%s.bale(%d)", key, baleIndex) |
893 | bale:saveToXMLFile(xmlFile, baleKey) |
894 | xmlFile:setValue(baleKey.."#balePlace", 0) |
895 | xmlFile:setValue(baleKey.."#helper", i) |
896 | |
897 | baleIndex = baleIndex + 1 |
898 | end |
899 | end |
900 | |
901 | if spec.hasMultipleFoldingAnimations and spec.lastFoldingAnimation ~= nil then |
902 | xmlFile:setValue(key.."#lastFoldingAnimation", spec.lastFoldingAnimation) |
903 | end |
904 | |
905 | -- unmount bale in grabber so it can be saved as a normal bale |
906 | if spec.baleGrabber.currentBale ~= nil then |
907 | local bale = NetworkUtil.getObject(spec.baleGrabber.currentBale) |
908 | if bale ~= nil then |
909 | self:unmountBale(bale) |
910 | spec.baleGrabber.currentBaleIsUnmounted = true |
911 | end |
912 | end |
913 | end |
setBaleLoaderBaleType
DescriptionSet bale type indexDefinition
setBaleLoaderBaleType(int baleTypeIndex)Arguments
int | baleTypeIndex | index of bale type |
2636 | function BaleLoader:setBaleLoaderBaleType(baleTypeIndex, forceUpdate) |
2637 | local spec = self.spec_baleLoader |
2638 | |
2639 | local newBaleType = spec.baleTypes[baleTypeIndex] or spec.baleTypes[1] |
2640 | if newBaleType ~= spec.currentBaleType then |
2641 | spec.currentBaleType = newBaleType |
2642 | spec.animations = newBaleType.animations |
2643 | |
2644 | if not spec.useSharedBalePlaces then |
2645 | if newBaleType.startBalePlace.node ~= nil then |
2646 | spec.startBalePlace = newBaleType.startBalePlace |
2647 | else |
2648 | spec.startBalePlace = spec.defaultBalePlace.startBalePlace |
2649 | end |
2650 | |
2651 | if #newBaleType.balePlaces > 0 then |
2652 | spec.balePlaces = newBaleType.balePlaces |
2653 | else |
2654 | spec.balePlaces = spec.defaultBalePlace.balePlaces |
2655 | end |
2656 | end |
2657 | |
2658 | spec.fillUnitIndex = newBaleType.fillUnitIndex |
2659 | |
2660 | -- hide display of empty units fom other bale types |
2661 | for i=1, #spec.baleTypes do |
2662 | local baleType = spec.baleTypes[i] |
2663 | local fillUnit = self:getFillUnitByIndex(baleType.fillUnitIndex) |
2664 | fillUnit.showOnHud = baleType.fillUnitIndex == spec.fillUnitIndex |
2665 | end |
2666 | |
2667 | ObjectChangeUtil.setObjectChanges(newBaleType.changeObjects, true, self, self.setMovingToolDirty, forceUpdate) |
2668 | end |
2669 | end |
setBalePairCollision
DescriptionDefinitionsetBalePairCollision()Code
2889 | function BaleLoader:setBalePairCollision(bale, state) |
2890 | local spec = self.spec_baleLoader |
2891 | for i=1, #self.components do |
2892 | setPairCollision(self.components[i].node, bale.nodeId, state) |
2893 | end |
2894 | |
2895 | for i=1, #spec.kinematicMountedBales do |
2896 | local bale2 = spec.kinematicMountedBales[i] |
2897 | setPairCollision(bale2.nodeId, bale.nodeId, state) |
2898 | end |
2899 | end |
startAutomaticBaleUnloading
DescriptionDefinitionstartAutomaticBaleUnloading()Code
2930 | function BaleLoader:startAutomaticBaleUnloading() |
2931 | local spec = self.spec_baleLoader |
2932 | |
2933 | if spec.emptyState == BaleLoader.EMPTY_NONE then |
2934 | spec.automaticUnloadingInProgress = true |
2935 | |
2936 | g_client:getServerConnection():sendEvent(BaleLoaderStateEvent.new(self, BaleLoader.CHANGE_BUTTON_EMPTY)) |
2937 | end |
2938 | end |
unmountBale
DescriptionDefinitionunmountBale()Code
2874 | function BaleLoader:unmountBale(bale) |
2875 | local spec = self.spec_baleLoader |
2876 | |
2877 | if bale.dynamicMountType == MountableObject.MOUNT_TYPE_DEFAULT then |
2878 | bale:unmount() |
2879 | elseif bale.dynamicMountType == MountableObject.MOUNT_TYPE_KINEMATIC then |
2880 | bale:unmountKinematic() |
2881 | |
2882 | table.removeElement(spec.kinematicMountedBales, bale) |
2883 | self:setBalePairCollision(bale, true) |
2884 | end |
2885 | end |
unmountDynamicBale
DescriptionDefinitionunmountDynamicBale()Code
2829 | function BaleLoader:unmountDynamicBale(bale) |
2830 | if self.isServer then |
2831 | local spec = self.spec_baleLoader |
2832 | |
2833 | bale:unmountDynamic() |
2834 | if bale.baleLoaderDynamicJointNode~= nil then |
2835 | delete(bale.baleLoaderDynamicJointNode) |
2836 | bale.baleLoaderDynamicJointNode = nil |
2837 | end |
2838 | |
2839 | spec.dynamicMount.baleJointsToUpdate = {} |
2840 | |
2841 | if bale.backupMass ~= nil then |
2842 | setMass(bale.nodeId, bale.backupMass) |
2843 | bale.backupMass = nil |
2844 | end |
2845 | g_currentMission.itemSystem:addItemToSave(bale) |
2846 | end |
2847 | end |
updateBalePlacesAnimations
DescriptionUpdate bale place animationsDefinition
updateBalePlacesAnimations()Code
1151 | function BaleLoader.updateBalePlacesAnimations(self) |
1152 | local spec = self.spec_baleLoader |
1153 | |
1154 | if spec.startBalePlace ~= nil and spec.startBalePlace.current > spec.startBalePlace.numOfPlaces or (spec.animations.moveBalePlacesAfterRotatePlatform and spec.startBalePlace.current > 1) then |
1155 | local delta = 1 |
1156 | local numBalePlaces = table.getn(spec.balePlaces) |
1157 | if spec.animations.moveBalePlacesAfterRotatePlatform and not spec.animations.moveBalePlacesAlways and not spec.useBalePlaceAsLoadPosition then |
1158 | delta = 0 |
1159 | end |
1160 | |
1161 | if spec.useBalePlaceAsLoadPosition then |
1162 | numBalePlaces = numBalePlaces - 1 |
1163 | delta = delta + spec.balePlaceOffset |
1164 | end |
1165 | |
1166 | -- startBalePlace.current-1 or -0 needs to be at the first position |
1167 | self:playAnimation(spec.animations.moveBalePlaces, 1, 0, true) |
1168 | self:setAnimationStopTime(spec.animations.moveBalePlaces, (spec.startBalePlace.current-delta)/numBalePlaces) |
1169 | |
1170 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1171 | end |
1172 | |
1173 | if spec.startBalePlace ~= nil and spec.startBalePlace.count >= 1 then |
1174 | self:playAnimation(spec.animations.balesToOtherRow, 20, nil, true) |
1175 | AnimatedVehicle.updateAnimations(self, 99999999, true) |
1176 | if spec.startBalePlace.count >= spec.startBalePlace.numOfPlaces then |
1177 | BaleLoader.rotatePlatform(self) |
1178 | end |
1179 | end |
1180 | end |
updateFoldingAnimation
DescriptionDefinitionupdateFoldingAnimation()Code
2991 | function BaleLoader:updateFoldingAnimation() |
2992 | local spec = self.spec_baleLoader |
2993 | |
2994 | local name = spec.animations.baleGrabberTransportToWork |
2995 | |
2996 | local fillLevel = MathUtil.round(self:getFillUnitFillLevel(spec.fillUnitIndex)) -- use rounding since fill level on client side is synced with low precision |
2997 | local balePlace = #spec.startBalePlace.bales |
2998 | local baleTypeIndex = 1 |
2999 | if spec.currentBaleType ~= nil then |
3000 | baleTypeIndex = spec.currentBaleType.index |
3001 | end |
3002 | |
3003 | for _, foldingAnimation in ipairs(spec.foldingAnimations) do |
3004 | if foldingAnimation.baleTypeIndex == 0 or foldingAnimation.baleTypeIndex == baleTypeIndex then |
3005 | if fillLevel >= foldingAnimation.minFillLevel and fillLevel <= foldingAnimation.maxFillLevel then |
3006 | if balePlace >= foldingAnimation.minBalePlace and balePlace <= foldingAnimation.maxBalePlace then |
3007 | name = foldingAnimation.name |
3008 | break |
3009 | end |
3010 | end |
3011 | end |
3012 | end |
3013 | |
3014 | if name ~= spec.lastFoldingAnimation then |
3015 | if spec.lastFoldingAnimation ~= nil then |
3016 | local animTime = self:getAnimationTime(spec.lastFoldingAnimation) |
3017 | self:setAnimationTime(name, animTime, false) |
3018 | end |
3019 | |
3020 | spec.lastFoldingAnimation = name |
3021 | end |
3022 | end |