LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

Foldable

Description
Specialization for vehicle parts with two or three folding states (e.g. tedder, cultivator, sowing machine)
Functions

actionEventFold

Description
Definition
actionEventFold()
Code
1270function Foldable.actionEventFold(self, actionName, inputValue, callbackState, isAnalog)
1271 local spec = self.spec_foldable
1272
1273 if table.getn(spec.foldingParts) > 0 then
1274 local toggleDirection = self:getToggledFoldDirection()
1275 if self:getIsFoldAllowed(toggleDirection, false) then
1276 if toggleDirection == spec.turnOnFoldDirection then
1277 self:setFoldState(toggleDirection, true)
1278 else
1279 self:setFoldState(toggleDirection, false)
1280 end
1281 end
1282 end
1283end

actionEventFoldMiddle

Description
Definition
actionEventFoldMiddle()
Code
1287function Foldable.actionEventFoldMiddle(self, actionName, inputValue, callbackState, isAnalog)
1288 local spec = self.spec_foldable
1289 if table.getn(spec.foldingParts) > 0 then
1290 if self:getIsFoldMiddleAllowed() then
1291 local direction = self:getToggledFoldMiddleDirection()
1292 if direction ~= 0 then
1293 if direction == spec.turnOnFoldDirection then
1294 self:setFoldState(direction, false)
1295 else
1296 self:setFoldState(direction, true)
1297 end
1298
1299 -- equalize moveDown state of the attacher joint with the inverse fold middle state
1300 -- before we execute setJointMoveDown with the AttacherJoints.actionEventLowerImplement below
1301 -- so the fold middle state and the joint move down state are always in line
1302 if self.getAttacherVehicle ~= nil then
1303 local attacherVehicle = self:getAttacherVehicle()
1304 local attacherJointIndex = attacherVehicle:getAttacherJointIndexFromObject(self)
1305 if attacherJointIndex ~= nil then
1306 local attacherJoints = attacherVehicle:getAttacherJoints()
1307 local attacherJoint = attacherJoints[attacherJointIndex]
1308
1309 attacherJoint.moveDown = direction ~= spec.turnOnFoldDirection
1310 end
1311 end
1312 end
1313 end
1314 end
1315
1316 -- also execute the lower implement function if we are using the same action button to control the fold middle state
1317 if spec.foldMiddleLoweringOverwritten ~= nil and spec.foldMiddleLoweringOverwritten then
1318 AttacherJoints.actionEventLowerImplement(self, actionName, inputValue, callbackState, isAnalog)
1319 end
1320end

allowLoadMovingToolStates

Description
Definition
allowLoadMovingToolStates()
Code
556function Foldable:allowLoadMovingToolStates(superFunc)
557 local spec = self.spec_foldable
558
559 if spec.foldAnimTime > spec.loadMovingToolStatesMaxLimit or spec.foldAnimTime < spec.loadMovingToolStatesMinLimit then
560 return false
561 end
562
563 return superFunc(self)
564end

getAllowDynamicMountObjects

Description
Definition
getAllowDynamicMountObjects()
Code
1013function Foldable:getAllowDynamicMountObjects(superFunc)
1014 local spec = self.spec_foldable
1015 local foldAnimTime = self:getFoldAnimTime()
1016 if foldAnimTime < spec.dynamicMountMinLimit or foldAnimTime > spec.dynamicMountMaxLimit then
1017 return false
1018 end
1019
1020 return superFunc(self)
1021end

getAllowsLowering

Description
Returns true if tool can be lowered
Definition
getAllowsLowering()
Return Values
booleandetachAlloweddetach is allowed
stringwarning[optional] warning text to display
Code
822function Foldable:getAllowsLowering(superFunc)
823 local spec = self.spec_foldable
824
825 if spec.foldAnimTime > spec.loweringMaxLimit or spec.foldAnimTime < spec.loweringMinLimit then
826 return false, spec.unfoldWarning
827 end
828
829 return superFunc(self)
830end

getCanAIImplementContinueWork

Description
Definition
getCanAIImplementContinueWork()
Code
1144function Foldable:getCanAIImplementContinueWork(superFunc)
1145 local spec = self.spec_foldable
1146
1147 local ret = true
1148 if table.getn(spec.foldingParts) > 0 and spec.allowUnfoldingByAI then
1149 ret = spec.foldAnimTime == spec.foldMiddleAnimTime or spec.foldAnimTime == 0 or spec.foldAnimTime == 1
1150 end
1151
1152 return superFunc(self) and ret
1153end

getCanBeSelected

Description
Definition
getCanBeSelected()
Code
958function Foldable:getCanBeSelected(superFunc)
959 return true
960end

getCanBeTurnedOn

Description
Definition
getCanBeTurnedOn()
Code
750function Foldable:getCanBeTurnedOn(superFunc)
751 local spec = self.spec_foldable
752 if spec.foldAnimTime > spec.turnOnFoldMaxLimit or spec.foldAnimTime < spec.turnOnFoldMinLimit then
753 return false
754 end
755
756 return superFunc(self)
757end

getCompensationAngleScale

Description
Definition
getCompensationAngleScale()
Code
614function Foldable:getCompensationAngleScale(superFunc, compensationNode)
615 local scale = superFunc(self, compensationNode)
616
617 if compensationNode.foldAngleScale ~= nil then
618 local spec = self.spec_foldable
619 local animTime = 1-spec.foldAnimTime
620 if spec.foldMiddleAnimTime ~= nil then
621 scale = scale * MathUtil.lerp(compensationNode.foldAngleScale, 1, animTime / (1 - spec.foldMiddleAnimTime))
622 else
623 scale = scale * MathUtil.lerp(compensationNode.foldAngleScale, 1, animTime)
624 end
625 end
626
627 return scale
628end

getFoldAnimTime

Description
Definition
getFoldAnimTime()
Code
479function Foldable:getFoldAnimTime()
480 local spec = self.spec_foldable
481 return spec.loadedFoldAnimTime or spec.foldAnimTime
482end

getIsAdditionalCharacterActive

Description
Definition
getIsAdditionalCharacterActive()
Code
999function Foldable:getIsAdditionalCharacterActive(superFunc)
1000 local spec = self.spec_enterable
1001 if spec.additionalCharacterFoldMinLimit ~= nil and spec.additionalCharacterFoldMaxLimit ~= nil then
1002 local foldAnimTime = self:getFoldAnimTime()
1003 if foldAnimTime >= spec.additionalCharacterFoldMinLimit and foldAnimTime <= spec.additionalCharacterFoldMaxLimit then
1004 return true
1005 end
1006 end
1007
1008 return superFunc(self)
1009end

getIsFoldAllowed

Description
Definition
getIsFoldAllowed()
Code
486function Foldable:getIsFoldAllowed(direction, onAiTurnOn)
487 if self.getAttacherVehicle ~= nil and self:getAttacherVehicle() ~= nil then
488 local inputAttacherJoint = self:getActiveInputAttacherJoint()
489 if inputAttacherJoint.foldMinLimit ~= nil and inputAttacherJoint.foldMaxLimit ~= nil then
490 local foldAnimTime = self:getFoldAnimTime()
491 if foldAnimTime < inputAttacherJoint.foldMinLimit or foldAnimTime > inputAttacherJoint.foldMaxLimit then
492 return false
493 end
494 end
495 end
496
497 return true
498end

getIsFoldMiddleAllowed

Description
Definition
getIsFoldMiddleAllowed()
Code
502function Foldable:getIsFoldMiddleAllowed()
503 local spec = self.spec_foldable
504 return spec.foldMiddleAnimTime ~= nil
505end

getIsGroundAdjustedNodeActive

Description
Definition
getIsGroundAdjustedNodeActive()
Code
913function Foldable:getIsGroundAdjustedNodeActive(superFunc, adjustedNode)
914 local spec = self.spec_foldable
915
916 local foldAnimTime = spec.foldAnimTime
917 if foldAnimTime ~= nil and (foldAnimTime > adjustedNode.foldMaxLimit or foldAnimTime < adjustedNode.foldMinLimit) then
918 return false
919 end
920
921 return superFunc(self, adjustedNode)
922end

getIsInputAttacherActive

Description
Returns true if input attacher is active and can be used to attach
Definition
getIsInputAttacherActive(table inputAttacherJoint)
Arguments
tableinputAttacherJointinput attacher joint
Return Values
booleanisActiveinput attacher is active
Code
975function Foldable:getIsInputAttacherActive(superFunc, inputAttacherJoint)
976 if inputAttacherJoint.foldMinLimit ~= nil and inputAttacherJoint.foldMaxLimit ~= nil then
977 local foldAnimTime = self:getFoldAnimTime()
978 if foldAnimTime < inputAttacherJoint.foldMinLimit or foldAnimTime > inputAttacherJoint.foldMaxLimit then
979 return false
980 end
981 end
982
983 return superFunc(self, inputAttacherJoint)
984end

getIsInWorkPosition

Description
Definition
getIsInWorkPosition()
Code
776function Foldable:getIsInWorkPosition(superFunc)
777 local spec = self.spec_foldable
778
779 if spec.turnOnFoldDirection ~= 0 and not (table.getn(spec.foldingParts) == 0 or (spec.turnOnFoldDirection == -1 and spec.foldAnimTime == 0) or (spec.turnOnFoldDirection == 1 and spec.foldAnimTime == 1)) then
780 return false
781 end
782
783 return superFunc(self)
784end

getIsLevelerPickupNodeActive

Description
Definition
getIsLevelerPickupNodeActive()
Code
708function Foldable:getIsLevelerPickupNodeActive(superFunc, levelerNode)
709 local spec = self.spec_foldable
710
711 if not levelerNode.foldLimitedOuterRange then
712 if spec.foldAnimTime > levelerNode.foldMaxLimit or spec.foldAnimTime < levelerNode.foldMinLimit then
713 return false
714 end
715 else
716 if spec.foldAnimTime <= levelerNode.foldMaxLimit and spec.foldAnimTime > levelerNode.foldMinLimit then
717 return false
718 end
719 end
720
721 return superFunc(self, levelerNode)
722end

getIsLowered

Description
Definition
getIsLowered()
Code
834function Foldable:getIsLowered(superFunc, default)
835 local spec = self.spec_foldable
836
837 if self:getIsFoldMiddleAllowed() then
838 if spec.foldMiddleAnimTime ~= nil and spec.foldMiddleInputButton ~= nil then
839
840 if spec.foldMoveDirection ~= 0 then
841 if spec.foldMiddleDirection > 0 then
842 if spec.foldAnimTime < spec.foldMiddleAnimTime + 0.01 then
843 return spec.foldMoveDirection < 0 and spec.moveToMiddle ~= true
844 end
845 else
846 if spec.foldAnimTime > spec.foldMiddleAnimTime - 0.01 then
847 return spec.foldMoveDirection > 0 and spec.moveToMiddle ~= true
848 end
849 end
850 else
851 if spec.foldMiddleDirection > 0 and spec.foldAnimTime < 0.01 then
852 return true
853 elseif spec.foldMiddleDirection < 0 and math.abs(1.0 - spec.foldAnimTime) < 0.01 then
854 return true
855 end
856 end
857
858 return false
859
860 end
861 end
862
863 return superFunc(self, default)
864end

getIsMovingToolActive

Description
Definition
getIsMovingToolActive()
Code
739function Foldable:getIsMovingToolActive(superFunc, movingTool)
740 local foldAnimTime = self:getFoldAnimTime()
741 if foldAnimTime > movingTool.foldMaxLimit or foldAnimTime < movingTool.foldMinLimit then
742 return false
743 end
744
745 return superFunc(self, movingTool)
746end

getIsNextCoverStateAllowed

Description
Definition
getIsNextCoverStateAllowed()
Code
761function Foldable:getIsNextCoverStateAllowed(superFunc, nextState)
762 if not superFunc(self, nextState) then
763 return false
764 end
765
766 local spec = self.spec_foldable
767 if spec.foldAnimTime > spec.toggleCoverMaxLimit or spec.foldAnimTime < spec.toggleCoverMinLimit then
768 return false
769 end
770
771 return true
772end

getIsSpeedRotatingPartActive

Description
Definition
getIsSpeedRotatingPartActive()
Code
588function Foldable:getIsSpeedRotatingPartActive(superFunc, speedRotatingPart)
589 local spec = self.spec_foldable
590
591 if not speedRotatingPart.foldLimitedOuterRange then
592 if spec.foldAnimTime > speedRotatingPart.foldMaxLimit or spec.foldAnimTime < speedRotatingPart.foldMinLimit then
593 return false
594 end
595 else
596 if spec.foldAnimTime <= speedRotatingPart.foldMaxLimit and spec.foldAnimTime > speedRotatingPart.foldMinLimit then
597 return false
598 end
599 end
600
601 return superFunc(self, speedRotatingPart)
602end

getIsSprayTypeActive

Description
Definition
getIsSprayTypeActive()
Code
937function Foldable:getIsSprayTypeActive(superFunc, sprayType)
938 local spec = self.spec_foldable
939
940 if sprayType.foldMinLimit ~= nil and sprayType.foldMaxLimit ~= nil then
941 local foldAnimTime = spec.foldAnimTime
942 if foldAnimTime ~= nil and (foldAnimTime > sprayType.foldMaxLimit or foldAnimTime < sprayType.foldMinLimit) then
943 return false
944 end
945 end
946
947 if sprayType.foldingConfigurationIndex ~= nil then
948 if (self.configurations["folding"] or 1) ~= sprayType.foldingConfigurationIndex then
949 return false
950 end
951 end
952
953 return superFunc(self, sprayType)
954end

getIsSteeringAxleAllowed

Description
Definition
getIsSteeringAxleAllowed()
Code
1057function Foldable:getIsSteeringAxleAllowed(superFunc)
1058 local spec = self.spec_attachable
1059 local foldAnimTime = self:getFoldAnimTime()
1060 if foldAnimTime < spec.foldMinLimit or foldAnimTime > spec.foldMaxLimit then
1061 return false
1062 end
1063
1064 return superFunc(self)
1065end

getIsSupportAnimationAllowed

Description
Returns if support animation is allowed to play
Definition
getIsSupportAnimationAllowed()
Code
1037function Foldable:getIsSupportAnimationAllowed(superFunc, supportAnimation)
1038 local foldAnimTime = self:getFoldAnimTime()
1039 if foldAnimTime < supportAnimation.foldMinLimit or foldAnimTime > supportAnimation.foldMaxLimit then
1040 return false
1041 end
1042
1043 return superFunc(self, supportAnimation)
1044end

getIsUnfolded

Description
Definition
getIsUnfolded()
Code
453function Foldable:getIsUnfolded()
454 local spec = self.spec_foldable
455
456 if table.getn(spec.foldingParts) > 0 then
457 if spec.foldMiddleAnimTime ~= nil then
458 if (spec.turnOnFoldDirection == -1 and spec.foldAnimTime < spec.foldMiddleAnimTime + 0.01) or
459 (spec.turnOnFoldDirection == 1 and spec.foldAnimTime > spec.foldMiddleAnimTime - 0.01)
460 then
461 return true
462 else
463 return false
464 end
465 else
466 if (spec.turnOnFoldDirection == -1 and spec.foldAnimTime == 0) or (spec.turnOnFoldDirection == 1 and spec.foldAnimTime == 1) then
467 return true
468 else
469 return false
470 end
471 end
472 else
473 return true
474 end
475end

getIsVersatileYRotActive

Description
Definition
getIsVersatileYRotActive()
Code
642function Foldable:getIsVersatileYRotActive(superFunc, wheel)
643 local spec = self.spec_foldable
644
645 if spec.foldAnimTime > wheel.versatileFoldMaxLimit or spec.foldAnimTime < wheel.versatileFoldMinLimit then
646 return false
647 end
648
649 return superFunc(self, wheel)
650end

getIsWorkAreaActive

Description
Definition
getIsWorkAreaActive()
Code
674function Foldable:getIsWorkAreaActive(superFunc, workArea)
675 local spec = self.spec_foldable
676
677 if not workArea.foldLimitedOuterRange then
678 if spec.foldAnimTime > workArea.foldMaxLimit or spec.foldAnimTime < workArea.foldMinLimit then
679 return false
680 end
681 else
682 if spec.foldAnimTime <= workArea.foldMaxLimit and spec.foldAnimTime > workArea.foldMinLimit then
683 return false
684 end
685 end
686
687 return superFunc(self, workArea)
688end

getSpecValueWorkingWidth

Description
Definition
getSpecValueWorkingWidth()
Code
1344function Foldable.getSpecValueWorkingWidth(storeItem, realItem, hasRealItem, config, formatted)
1345 if storeItem.specs.workingWidthVar ~= nil then
1346 local workingWidth = storeItem.specs.workingWidthVar[config or 1]
1347 if (formatted == nil or formatted) and workingWidth ~= nil then
1348 return string.format(g_i18n:getText("shop_workingWidthValue"), g_i18n:formatNumber(workingWidth, 1, true))
1349 else
1350 return workingWidth
1351 end
1352 end
1353
1354 return nil
1355end

getToggledFoldDirection

Description
Definition
getToggledFoldDirection()
Code
509function Foldable:getToggledFoldDirection()
510 local spec = self.spec_foldable
511
512 local foldMidTime = 0.5
513 if spec.foldMiddleAnimTime ~= nil then
514 if spec.foldMiddleDirection > 0 then
515 foldMidTime = (1 + spec.foldMiddleAnimTime) * 0.5
516 else
517 foldMidTime = spec.foldMiddleAnimTime * 0.5
518 end
519 end
520 if spec.moveToMiddle then
521 return spec.foldMiddleDirection
522 elseif spec.foldMoveDirection > 0.1 or (spec.foldMoveDirection == 0 and spec.foldAnimTime > foldMidTime) then
523 return -1
524 else
525 return 1
526 end
527end

getToggledFoldMiddleDirection

Description
Definition
getToggledFoldMiddleDirection()
Code
531function Foldable:getToggledFoldMiddleDirection()
532 local spec = self.spec_foldable
533
534 local ret = 0
535 if spec.foldMiddleAnimTime ~= nil then
536 if spec.foldMoveDirection > 0.1 then
537 ret = -1
538 else
539 ret = 1
540 end
541 if spec.foldMiddleDirection > 0 then
542 if spec.foldAnimTime >= spec.foldMiddleAnimTime - 0.01 then
543 ret = -1
544 end
545 else
546 if spec.foldAnimTime <= spec.foldMiddleAnimTime + 0.01 then
547 ret = 1
548 end
549 end
550 end
551 return ret
552end

getTurnedOnNotAllowedWarning

Description
Definition
getTurnedOnNotAllowedWarning()
Code
788function Foldable:getTurnedOnNotAllowedWarning(superFunc)
789 local spec = self.spec_foldable
790
791 if spec.foldAnimTime > spec.turnOnFoldMaxLimit or spec.foldAnimTime < spec.turnOnFoldMinLimit then
792 return spec.unfoldWarning
793 end
794
795 return superFunc(self)
796end

initSpecialization

Description
Definition
initSpecialization()
Code
103function Foldable.initSpecialization()
104 g_configurationManager:addConfigurationType("folding", g_i18n:getText("configuration_folding"), "foldable", nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
105
106 g_storeManager:addSpecType("workingWidthVar", "shopListAttributeIconWorkingWidth", Foldable.loadSpecValueWorkingWidth, Foldable.getSpecValueWorkingWidth)
107end

isDetachAllowed

Description
Returns true if detach is allowed
Definition
isDetachAllowed()
Return Values
booleandetachAlloweddetach is allowed
stringwarning[optional] warning text to display
Code
802function Foldable:isDetachAllowed(superFunc)
803 local spec = self.spec_foldable
804
805 if spec.foldAnimTime > spec.detachingMaxLimit or spec.foldAnimTime < spec.detachingMinLimit then
806 return false, spec.unfoldWarning
807 end
808
809 if not spec.allowDetachingWhileFolding then
810 if (spec.foldMiddleAnimTime == nil or math.abs(spec.foldAnimTime-spec.foldMiddleAnimTime) > 0.001) and (spec.foldAnimTime > 0 and spec.foldAnimTime < 1) then
811 return false, spec.unfoldWarning
812 end
813 end
814
815 return superFunc(self)
816end

loadAdditionalCharacterFromXML

Description
Definition
loadAdditionalCharacterFromXML()
Code
988function Foldable:loadAdditionalCharacterFromXML(superFunc, xmlFile)
989 local spec = self.spec_enterable
990
991 spec.additionalCharacterFoldMinLimit = getXMLFloat(self.xmlFile, "vehicle.enterable.additionalCharacter#foldMinLimit")
992 spec.additionalCharacterFoldMaxLimit = getXMLFloat(self.xmlFile, "vehicle.enterable.additionalCharacter#foldMaxLimit")
993
994 return superFunc(self, xmlFile)
995end

loadCompensationNodeFromXML

Description
Definition
loadCompensationNodeFromXML()
Code
606function Foldable:loadCompensationNodeFromXML(superFunc, compensationNode, xmlFile, key)
607 compensationNode.foldAngleScale = getXMLFloat(self.xmlFile, key.."#foldAngleScale")
608
609 return superFunc(self, compensationNode, xmlFile, key)
610end

loadDynamicWheelDataFromXML

Description
Definition
loadDynamicWheelDataFromXML()
Code
632function Foldable:loadDynamicWheelDataFromXML(superFunc, xmlFile, key, wheelnamei, wheel)
633 local fallbackOldKey = "vehicle.wheels"
634 wheel.versatileFoldMinLimit = ConfigurationUtil.getConfigurationValue(xmlFile, key, wheelnamei, "#versatileFoldMinLimit", getXMLFloat, 0, nil, fallbackOldKey)
635 wheel.versatileFoldMaxLimit = ConfigurationUtil.getConfigurationValue(xmlFile, key, wheelnamei, "#versatileFoldMaxLimit", getXMLFloat, 1, nil, fallbackOldKey)
636
637 return superFunc(self, xmlFile, key, wheelnamei, wheel)
638end

loadGroundAdjustedNodeFromXML

Description
Definition
loadGroundAdjustedNodeFromXML()
Code
897function Foldable:loadGroundAdjustedNodeFromXML(superFunc, xmlFile, key, adjustedNode)
898 if not superFunc(self, xmlFile, key, adjustedNode) then
899 return true
900 end
901
902 XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#foldMinLimit", key..".foldable#minLimit") --FS17 to FS19
903 XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#foldMaxLimit", key..".foldable#maxLimit") --FS17 to FS19
904
905 adjustedNode.foldMinLimit = getXMLFloat(xmlFile, key..".foldable#minLimit") or 0
906 adjustedNode.foldMaxLimit = getXMLFloat(xmlFile, key..".foldable#maxLimit") or 1
907
908 return true
909end

loadInputAttacherJoint

Description
Definition
loadInputAttacherJoint()
Code
964function Foldable:loadInputAttacherJoint(superFunc, xmlFile, key, inputAttacherJoint, index)
965 inputAttacherJoint.foldMinLimit = getXMLFloat(xmlFile, key .. "#foldMinLimit2")
966 inputAttacherJoint.foldMaxLimit = getXMLFloat(xmlFile, key .. "#foldMaxLimit2")
967
968 return superFunc(self, xmlFile, key, inputAttacherJoint, index)
969end

loadLevelerNodeFromXML

Description
Definition
loadLevelerNodeFromXML()
Code
692function Foldable:loadLevelerNodeFromXML(superFunc, levelerNode, xmlFile, key)
693 levelerNode.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false)
694 local minFoldLimit = 0
695 local maxFoldLimit = 1
696 if levelerNode.foldLimitedOuterRange then
697 minFoldLimit = 0.5
698 maxFoldLimit = 0.5
699 end
700 levelerNode.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMinLimit"), minFoldLimit)
701 levelerNode.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMaxLimit"), maxFoldLimit)
702
703 return superFunc(self, levelerNode, xmlFile, key)
704end

loadMovingToolFromXML

Description
Definition
loadMovingToolFromXML()
Code
726function Foldable:loadMovingToolFromXML(superFunc, xmlFile, key, entry)
727 if not superFunc(self, xmlFile, key, entry) then
728 return false
729 end
730
731 entry.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#foldMinLimit"), 0)
732 entry.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#foldMaxLimit"), 1)
733
734 return true
735end

loadSpecValueWorkingWidth

Description
Definition
loadSpecValueWorkingWidth()
Code
1324function Foldable.loadSpecValueWorkingWidth(xmlFile, customEnvironment)
1325 local workingWidths = {}
1326
1327 local i = 0
1328 while true do
1329 local baseKey = string.format("vehicle.foldable.foldingConfigurations.foldingConfiguration(%d)", i)
1330 if not hasXMLProperty(xmlFile, baseKey) then
1331 break
1332 end
1333
1334 workingWidths[i+1] = getXMLFloat(xmlFile, baseKey.."#workingWidth")
1335
1336 i = i + 1
1337 end
1338
1339 return workingWidths
1340end

loadSpeedRotatingPartFromXML

Description
Definition
loadSpeedRotatingPartFromXML()
Code
568function Foldable:loadSpeedRotatingPartFromXML(superFunc, speedRotatingPart, xmlFile, key)
569 if not superFunc(self, speedRotatingPart, xmlFile, key) then
570 return false
571 end
572
573 speedRotatingPart.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false)
574 local minFoldLimit = 0
575 local maxFoldLimit = 1
576 if speedRotatingPart.foldLimitedOuterRange then
577 minFoldLimit = 0.5
578 maxFoldLimit = 0.5
579 end
580 speedRotatingPart.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMinLimit"), minFoldLimit)
581 speedRotatingPart.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMaxLimit"), maxFoldLimit)
582
583 return true
584end

loadSprayTypeFromXML

Description
Definition
loadSprayTypeFromXML()
Code
926function Foldable:loadSprayTypeFromXML(superFunc, xmlFile, key, sprayType)
927 sprayType.foldMinLimit = getXMLFloat(self.xmlFile, key.. "#foldMinLimit")
928 sprayType.foldMaxLimit = getXMLFloat(self.xmlFile, key.. "#foldMaxLimit")
929
930 sprayType.foldingConfigurationIndex = getXMLInt(self.xmlFile, key.. "#foldingConfigurationIndex")
931
932 return superFunc(self, xmlFile, key, sprayType)
933end

loadSteeringAxleFromXML

Description
Definition
loadSteeringAxleFromXML()
Code
1048function Foldable:loadSteeringAxleFromXML(superFunc, spec, xmlFile, key)
1049 spec.foldMinLimit = getXMLFloat(xmlFile, key.."#foldMinLimit") or 0
1050 spec.foldMaxLimit = getXMLFloat(xmlFile, key.."#foldMaxLimit") or 1
1051
1052 return superFunc(self, spec, xmlFile, key)
1053end

loadSupportAnimationFromXML

Description
Loads support animation from xml
Definition
loadSupportAnimationFromXML(table spec, int xmlFile, string key)
Arguments
tablespecspec
intxmlFilexmlFile id
stringkeykey to load from
Code
1028function Foldable:loadSupportAnimationFromXML(superFunc, supportAnimation, xmlFile, key)
1029 supportAnimation.foldMinLimit = getXMLFloat(xmlFile, key.."#foldMinLimit") or 0
1030 supportAnimation.foldMaxLimit = getXMLFloat(xmlFile, key.."#foldMaxLimit") or 1
1031
1032 return superFunc(self, supportAnimation, xmlFile, key)
1033end

loadWorkAreaFromXML

Description
Definition
loadWorkAreaFromXML()
Code
654function Foldable:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key)
655 workArea.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false)
656 local minFoldLimit = 0
657 local maxFoldLimit = 1
658 if workArea.foldLimitedOuterRange then
659 minFoldLimit = 0.5
660 maxFoldLimit = 0.5
661 end
662
663 XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#foldMinLimit", key..".folding#minLimit") --FS17 to FS19
664 XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#foldMaxLimit", key..".folding#maxLimit") --FS17 to FS19
665
666 workArea.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key..".folding#minLimit"), minFoldLimit)
667 workArea.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key..".folding#maxLimit"), maxFoldLimit)
668
669 return superFunc(self, workArea, xmlFile, key)
670end

onAIImplementEnd

Description
Definition
onAIImplementEnd()
Code
1097function Foldable:onAIImplementEnd()
1098 local spec = self.spec_foldable
1099 if spec.allowUnfoldingByAI and spec.foldMiddleAnimTime ~= nil and spec.foldMiddleAIRaiseDirection ~= 0 then
1100 if spec.foldMiddleAIRaiseDirection > 0 then
1101 if spec.foldAnimTime > spec.foldMiddleAnimTime then
1102 self:setFoldState(spec.foldMiddleAIRaiseDirection, false, true)
1103 else
1104 self:setFoldState(spec.foldMiddleAIRaiseDirection, true, true)
1105 end
1106 else
1107 if spec.foldAnimTime < spec.foldMiddleAnimTime then
1108 self:setFoldState(spec.foldMiddleAIRaiseDirection, false, true)
1109 else
1110 self:setFoldState(spec.foldMiddleAIRaiseDirection, true, true)
1111 end
1112 end
1113 end
1114end

onAIImplementEndLine

Description
Definition
onAIImplementEndLine()
Code
1127function Foldable:onAIImplementEndLine()
1128 local spec = self.spec_foldable
1129 if spec.allowUnfoldingByAI and spec.foldMiddleAnimTime ~= nil and spec.foldMiddleAIRaiseDirection ~= 0 then
1130 if spec.foldMiddleAIRaiseDirection > 0 then
1131 if spec.foldAnimTime < spec.foldMiddleAnimTime then
1132 self:setFoldState(1, true)
1133 end
1134 else
1135 if spec.foldAnimTime > spec.foldMiddleAnimTime then
1136 self:setFoldState(-1, true)
1137 end
1138 end
1139 end
1140end

onAIImplementStart

Description
Definition
onAIImplementStart()
Code
1088function Foldable:onAIImplementStart()
1089 local spec = self.spec_foldable
1090 if spec.allowUnfoldingByAI and spec.turnOnFoldDirection ~= 0 then
1091 self:setFoldState(spec.turnOnFoldDirection, true, true)
1092 end
1093end

onAIImplementStartLine

Description
Definition
onAIImplementStartLine()
Code
1118function Foldable:onAIImplementStartLine()
1119 local spec = self.spec_foldable
1120 if spec.allowUnfoldingByAI and spec.foldMiddleAnimTime ~= nil and spec.foldMiddleAIRaiseDirection ~= 0 then
1121 self:setFoldState(-spec.foldMiddleAIRaiseDirection, false)
1122 end
1123end

onDeactivate

Description
Definition
onDeactivate()
Code
1157function Foldable:onDeactivate()
1158 self:setFoldDirection(0, true)
1159end

onLoad

Description
Definition
onLoad()
Code
111function Foldable:onLoad(savegame)
112 local spec = self.spec_foldable
113
114 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.foldingParts", "vehicle.foldable.foldingConfigurations.foldingConfiguration.foldingParts") --FS17 to FS19
115
116 local foldingConfigurationId = Utils.getNoNil(self.configurations["folding"], 1)
117 local configKey = string.format("vehicle.foldable.foldingConfigurations.foldingConfiguration(%d).foldingParts", foldingConfigurationId -1)
118 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.foldable.foldingConfigurations.foldingConfiguration", foldingConfigurationId , self.components, self)
119
120 -- fallback key
121 if not hasXMLProperty(self.xmlFile, configKey) then
122 configKey = "vehicle.foldable.foldingParts"
123 end
124
125 spec.posDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#posDirectionText"), "action_foldOBJECT")
126 spec.negDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#negDirectionText"), "action_unfoldOBJECT")
127 spec.middlePosDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#middlePosDirectionText"), "action_liftOBJECT")
128 spec.middleNegDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#middleNegDirectionText"), "action_lowerOBJECT")
129 spec.startAnimTime = getXMLFloat(self.xmlFile, configKey.."#startAnimTime")
130 spec.foldMoveDirection = 0
131 spec.moveToMiddle = false
132 if spec.startAnimTime == nil then
133 spec.startAnimTime = 0
134 local startMoveDirection = Utils.getNoNil(getXMLInt(self.xmlFile, configKey.."#startMoveDirection"), 0)
135 if startMoveDirection > 0.1 then
136 spec.startAnimTime = 1
137 end
138 end
139 spec.turnOnFoldDirection = 1
140 if spec.startAnimTime > 0.5 then
141 spec.turnOnFoldDirection = -1
142 end
143
144 spec.turnOnFoldDirection = MathUtil.sign(Utils.getNoNil(getXMLInt(self.xmlFile, configKey.."#turnOnFoldDirection"), spec.turnOnFoldDirection))
145
146 spec.allowUnfoldingByAI = Utils.getNoNil(getXMLBool(self.xmlFile, configKey.."#allowUnfoldingByAI"), true)
147
148 local foldInputButtonStr = getXMLString(self.xmlFile, configKey.."#foldInputButton");
149 if foldInputButtonStr ~= nil then
150 spec.foldInputButton = InputAction[foldInputButtonStr];
151 end
152 spec.foldInputButton = Utils.getNoNil(spec.foldInputButton, InputAction.IMPLEMENT_EXTRA2);
153
154 local foldMiddleInputButtonStr = getXMLString(self.xmlFile, configKey.."#foldMiddleInputButton");
155 if foldMiddleInputButtonStr ~= nil then
156 spec.foldMiddleInputButton = InputAction[foldMiddleInputButtonStr];
157 end
158 spec.foldMiddleInputButton = Utils.getNoNil(spec.foldMiddleInputButton, InputAction.LOWER_IMPLEMENT);
159
160 spec.foldMiddleAnimTime = getXMLFloat(self.xmlFile, configKey.."#foldMiddleAnimTime")
161 spec.foldMiddleDirection = Utils.getNoNil(getXMLInt(self.xmlFile, configKey.."#foldMiddleDirection"), 1)
162 spec.foldMiddleAIRaiseDirection = Utils.getNoNil(getXMLInt(self.xmlFile, configKey.."#foldMiddleAIRaiseDirection"), spec.foldMiddleDirection)
163
164 spec.turnOnFoldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#turnOnFoldMaxLimit"), 1)
165 spec.turnOnFoldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#turnOnFoldMinLimit"), 0)
166 spec.toggleCoverMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#toggleCoverMaxLimit"), 1)
167 spec.toggleCoverMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#toggleCoverMinLimit"), 0)
168 spec.detachingMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#detachingMaxLimit"), 1)
169 spec.detachingMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#detachingMinLimit"), 0)
170 spec.allowDetachingWhileFolding = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#allowDetachingWhileFolding"), false)
171 spec.loweringMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#loweringMaxLimit"), 1)
172 spec.loweringMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#loweringMinLimit"), 0)
173 spec.loadMovingToolStatesMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#loadMovingToolStatesMaxLimit"), 1)
174 spec.loadMovingToolStatesMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#loadMovingToolStatesMinLimit"), 0)
175 spec.dynamicMountMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#dynamicMountMinLimit"), 0)
176 spec.dynamicMountMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#dynamicMountMaxLimit"), 1)
177 spec.unfoldWarning = string.format(g_i18n:getText(Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#unfoldWarning"), "warning_firstUnfoldTheTool"), self.customEnvironment), self.typeDesc)
178
179 spec.foldAnimTime = 0
180 spec.maxFoldAnimDuration = 0.0001
181
182 spec.foldingParts = {}
183 local i=0
184 while true do
185 local baseName = string.format(configKey..".foldingPart(%d)", i)
186 if not hasXMLProperty(self.xmlFile, baseName) then
187 break
188 end
189
190 local isValid = false
191 local entry = {}
192 entry.speedScale = Utils.getNoNil(getXMLFloat(self.xmlFile, baseName.."#speedScale"), 1)
193 local componentJointIndex = getXMLInt(self.xmlFile, baseName.. "#componentJointIndex")
194 local componentJoint = nil
195 if componentJointIndex ~= nil then
196 if componentJointIndex == 0 then
197 componentJointIndex = nil
198 g_logManager:xmlWarning(self.configFileName, "Invalid componentJointIndex for folding part '%s'. Indexing starts with 1!", baseName)
199 else
200 componentJoint = self.componentJoints[componentJointIndex]
201 entry.componentJoint = componentJoint
202 end
203 end
204 entry.anchorActor = Utils.getNoNil(getXMLInt(self.xmlFile, baseName.."#anchorActor"), 0)
205
206 entry.animCharSet = 0
207
208 local rootNode = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName.."#rootNode"), self.i3dMappings)
209 if rootNode ~= nil then
210 local animCharSet = getAnimCharacterSet(rootNode)
211 if animCharSet ~= 0 then
212 local clip = getAnimClipIndex(animCharSet, getXMLString(self.xmlFile, baseName.."#animationClip"))
213 if clip >= 0 then
214 isValid = true
215
216 entry.animCharSet = animCharSet
217 assignAnimTrackClip(entry.animCharSet, 0, clip)
218 setAnimTrackLoopState(entry.animCharSet, 0, false)
219 entry.animDuration = getAnimClipDuration(entry.animCharSet, clip)
220
221 end
222 end
223 end
224 -- try AnimatedVehicle specialization support
225 if not isValid then
226 local specAnimatedVehicle = self.spec_animatedVehicle
227 if specAnimatedVehicle ~= nil then --and self.playAnimation ~= nil and self.animations ~= nil then
228 local animationName = getXMLString(self.xmlFile, baseName.."#animationName")
229 if animationName ~= nil then
230 if specAnimatedVehicle.animations[animationName] ~= nil then
231 isValid = true
232 entry.animDuration = self:getAnimationDuration(animationName)
233 entry.animationName = animationName
234 end
235 end
236 end
237 end
238
239 if isValid then
240 spec.maxFoldAnimDuration = math.max(spec.maxFoldAnimDuration, entry.animDuration)
241 if componentJoint ~= nil then
242 local node = self.components[componentJoint.componentIndices[((entry.anchorActor+1)%2)+1] ].node
243 entry.x,entry.y,entry.z = worldToLocal(componentJoint.jointNode, getWorldTranslation(node))
244 entry.upX,entry.upY,entry.upZ = worldDirectionToLocal(componentJoint.jointNode, localDirectionToWorld(node, 0, 1, 0))
245 entry.dirX,entry.dirY,entry.dirZ = worldDirectionToLocal(componentJoint.jointNode, localDirectionToWorld(node, 0, 0, 1))
246 end
247
248 table.insert(spec.foldingParts, entry)
249 end
250 i = i+1
251 end
252
253 if table.getn(spec.foldingParts) > 0 then
254 self.isSelectable = true
255 end
256
257 spec.actionEventsLowering = {}
258
259 if savegame ~= nil and not savegame.resetVehicles then
260 spec.loadedFoldAnimTime = getXMLFloat(savegame.xmlFile, savegame.key..".foldable#foldAnimTime")
261 end
262
263 if spec.loadedFoldAnimTime == nil then
264 spec.loadedFoldAnimTime = spec.startAnimTime
265 end
266
267 if spec.loadedFoldAnimTime <= 0 then
268 spec.foldMoveDirection = -1
269 else
270 spec.foldMoveDirection = 1
271 end
272end

onPostLoad

Description
Definition
onPostLoad()
Code
276function Foldable:onPostLoad(savegame)
277 local spec = self.spec_foldable
278 Foldable.setAnimTime(self, spec.loadedFoldAnimTime, false)
279end

onReadStream

Description
Definition
onReadStream()
Code
290function Foldable:onReadStream(streamId, connection)
291 local direction = streamReadUIntN(streamId, 2)-1
292 local moveToMiddle = streamReadBool(streamId)
293 local animTime = streamReadFloat32(streamId)
294 Foldable.setAnimTime(self, animTime, false)
295 self:setFoldState(direction, moveToMiddle, true)
296end

onRegisterActionEvents

Description
Definition
onRegisterActionEvents()
Code
1069function Foldable:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
1070 if self.isClient then
1071 local spec = self.spec_foldable
1072 self:clearActionEventsTable(spec.actionEvents)
1073
1074 if isActiveForInputIgnoreSelection then
1075 local isOnlyLowering = spec.foldMiddleAnimTime ~= nil and spec.foldMiddleAnimTime == 1
1076 if table.getn(spec.foldingParts) > 0 and not isOnlyLowering then
1077 local _, actionEventId = self:addActionEvent(spec.actionEvents, spec.foldInputButton, self, Foldable.actionEventFold, false, true, false, true, nil)
1078 g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH)
1079 Foldable.updateActionEventFold(self)
1080 end
1081 end
1082 end
1083end

onSetLoweredAll

Description
Definition
onSetLoweredAll()
Code
1163function Foldable:onSetLoweredAll(doLowering, jointDescIndex)
1164 local spec = self.spec_foldable
1165 if spec.foldMiddleAnimTime ~= nil then
1166 if self:getIsFoldMiddleAllowed() then
1167 if doLowering then
1168 self:setFoldState(-spec.foldMiddleAIRaiseDirection, false)
1169 else
1170 self:setFoldState(spec.foldMiddleAIRaiseDirection, true)
1171 end
1172 end
1173 end
1174end

onUpdate

Description
Definition
onUpdate()
Code
311function Foldable:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
312 local spec = self.spec_foldable
313
314 -- update actionEvents
315 if self.isClient then
316 Foldable.updateActionEventFold(self)
317 if spec.foldMiddleAnimTime ~= nil then
318 Foldable.updateActionEventFoldMiddle(self)
319 end
320 end
321
322 if math.abs(spec.foldMoveDirection) > 0.1 then
323 local isInvalid = false
324 local foldAnimTime = 0
325 if spec.foldMoveDirection < -0.1 then
326 foldAnimTime = 1
327 end
328 for _,foldingPart in pairs(spec.foldingParts) do
329 local charSet = foldingPart.animCharSet
330 if spec.foldMoveDirection > 0 then
331 local animTime
332 if charSet ~= 0 then
333 animTime = getAnimTrackTime(charSet, 0)
334 else
335 animTime = self:getRealAnimationTime(foldingPart.animationName)
336 end
337 if animTime < foldingPart.animDuration then
338 isInvalid = true
339 end
340 foldAnimTime = math.max(foldAnimTime, animTime / spec.maxFoldAnimDuration)
341 elseif spec.foldMoveDirection < 0 then
342 local animTime
343 if charSet ~= 0 then
344 animTime = getAnimTrackTime(charSet, 0)
345 else
346 animTime = self:getRealAnimationTime(foldingPart.animationName)
347 end
348 if animTime > 0 then
349 isInvalid = true
350 end
351 foldAnimTime = math.min(foldAnimTime, animTime / spec.maxFoldAnimDuration)
352 end
353 end
354 spec.foldAnimTime = MathUtil.clamp(foldAnimTime, 0, 1)
355
356 if isInvalid and self.isServer then
357 for _,foldingPart in pairs(spec.foldingParts) do
358 if foldingPart.componentJoint ~= nil then
359 self:setComponentJointFrame(foldingPart.componentJoint, foldingPart.anchorActor)
360 end
361 end
362 end
363 end
364end

onWriteStream

Description
Definition
onWriteStream()
Code
300function Foldable:onWriteStream(streamId, connection)
301 local spec = self.spec_foldable
302
303 local direction = MathUtil.sign(spec.foldMoveDirection)+1
304 streamWriteUIntN(streamId, direction, 2)
305 streamWriteBool(streamId, spec.moveToMiddle)
306 streamWriteFloat32(streamId, spec.foldAnimTime)
307end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
19function Foldable.prerequisitesPresent(specializations)
20 return true
21end

registerEventListeners

Description
Definition
registerEventListeners()
Code
86function Foldable.registerEventListeners(vehicleType)
87 SpecializationUtil.registerEventListener(vehicleType, "onLoad", Foldable)
88 SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", Foldable)
89 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Foldable)
90 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Foldable)
91 SpecializationUtil.registerEventListener(vehicleType, "onUpdate", Foldable)
92 SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", Foldable)
93 SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", Foldable)
94 SpecializationUtil.registerEventListener(vehicleType, "onSetLoweredAll", Foldable)
95 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStart", Foldable)
96 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementEnd", Foldable)
97 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStartLine", Foldable)
98 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementEndLine", Foldable)
99end

registerEvents

Description
Definition
registerEvents()
Code
25function Foldable.registerEvents(vehicleType)
26 SpecializationUtil.registerEvent(vehicleType, "onFoldStateChanged")
27end

registerFunctions

Description
Definition
registerFunctions()
Code
31function Foldable.registerFunctions(vehicleType)
32 SpecializationUtil.registerFunction(vehicleType, "setFoldDirection", Foldable.setFoldDirection)
33 SpecializationUtil.registerFunction(vehicleType, "setFoldState", Foldable.setFoldState)
34 SpecializationUtil.registerFunction(vehicleType, "getIsUnfolded", Foldable.getIsUnfolded)
35 SpecializationUtil.registerFunction(vehicleType, "getFoldAnimTime", Foldable.getFoldAnimTime)
36 SpecializationUtil.registerFunction(vehicleType, "getIsFoldAllowed", Foldable.getIsFoldAllowed)
37 SpecializationUtil.registerFunction(vehicleType, "getIsFoldMiddleAllowed", Foldable.getIsFoldMiddleAllowed)
38 SpecializationUtil.registerFunction(vehicleType, "getToggledFoldDirection", Foldable.getToggledFoldDirection)
39 SpecializationUtil.registerFunction(vehicleType, "getToggledFoldMiddleDirection", Foldable.getToggledFoldMiddleDirection)
40end

registerLoweringActionEvent

Description
Definition
registerLoweringActionEvent()
Code
868function Foldable:registerLoweringActionEvent(superFunc, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName, ignoreCollisions)
869 local spec = self.spec_foldable
870 if table.getn(spec.foldingParts) > 0 then
871 if spec.foldMiddleAnimTime ~= nil then
872 self:clearActionEventsTable(spec.actionEventsLowering)
873
874 local state, actionEventId = self:addActionEvent(spec.actionEventsLowering, spec.foldMiddleInputButton, self, Foldable.actionEventFoldMiddle, false, true, false, true, nil, nil, ignoreCollisions)
875 g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH)
876 Foldable.updateActionEventFoldMiddle(self)
877
878 -- if we are using the same button we use only Foldable.actionEventFoldMiddle, if not, we use both
879 if spec.foldMiddleInputButton == inputAction then
880 spec.foldMiddleLoweringOverwritten = true
881 return state, actionEventId
882 end
883 end
884 end
885
886 return superFunc(self, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName)
887end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
44function Foldable.registerOverwrittenFunctions(vehicleType)
45 SpecializationUtil.registerOverwrittenFunction(vehicleType, "allowLoadMovingToolStates", Foldable.allowLoadMovingToolStates)
46 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSpeedRotatingPartFromXML", Foldable.loadSpeedRotatingPartFromXML)
47 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSpeedRotatingPartActive", Foldable.getIsSpeedRotatingPartActive)
48 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadCompensationNodeFromXML", Foldable.loadCompensationNodeFromXML)
49 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCompensationAngleScale", Foldable.getCompensationAngleScale)
50 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadDynamicWheelDataFromXML", Foldable.loadDynamicWheelDataFromXML)
51 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsVersatileYRotActive", Foldable.getIsVersatileYRotActive)
52 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadWorkAreaFromXML", Foldable.loadWorkAreaFromXML)
53 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsWorkAreaActive", Foldable.getIsWorkAreaActive)
54 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadLevelerNodeFromXML", Foldable.loadLevelerNodeFromXML)
55 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsLevelerPickupNodeActive", Foldable.getIsLevelerPickupNodeActive)
56 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadMovingToolFromXML", Foldable.loadMovingToolFromXML)
57 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsMovingToolActive", Foldable.getIsMovingToolActive)
58 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeTurnedOn", Foldable.getCanBeTurnedOn)
59 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsNextCoverStateAllowed", Foldable.getIsNextCoverStateAllowed)
60 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsInWorkPosition", Foldable.getIsInWorkPosition)
61 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getTurnedOnNotAllowedWarning", Foldable.getTurnedOnNotAllowedWarning)
62 SpecializationUtil.registerOverwrittenFunction(vehicleType, "isDetachAllowed", Foldable.isDetachAllowed)
63 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAllowsLowering", Foldable.getAllowsLowering)
64 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsLowered", Foldable.getIsLowered)
65 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanAIImplementContinueWork", Foldable.getCanAIImplementContinueWork)
66 SpecializationUtil.registerOverwrittenFunction(vehicleType, "registerLoweringActionEvent", Foldable.registerLoweringActionEvent)
67 SpecializationUtil.registerOverwrittenFunction(vehicleType, "registerSelfLoweringActionEvent", Foldable.registerSelfLoweringActionEvent)
68 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadGroundAdjustedNodeFromXML", Foldable.loadGroundAdjustedNodeFromXML)
69 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsGroundAdjustedNodeActive", Foldable.getIsGroundAdjustedNodeActive)
70 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSprayTypeFromXML", Foldable.loadSprayTypeFromXML)
71 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSprayTypeActive", Foldable.getIsSprayTypeActive)
72 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", Foldable.getCanBeSelected)
73 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadInputAttacherJoint", Foldable.loadInputAttacherJoint)
74 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsInputAttacherActive", Foldable.getIsInputAttacherActive)
75 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadAdditionalCharacterFromXML", Foldable.loadAdditionalCharacterFromXML)
76 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsAdditionalCharacterActive", Foldable.getIsAdditionalCharacterActive)
77 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAllowDynamicMountObjects", Foldable.getAllowDynamicMountObjects)
78 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSupportAnimationFromXML", Foldable.loadSupportAnimationFromXML)
79 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSupportAnimationAllowed", Foldable.getIsSupportAnimationAllowed)
80 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSteeringAxleFromXML", Foldable.loadSteeringAxleFromXML)
81 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSteeringAxleAllowed", Foldable.getIsSteeringAxleAllowed)
82end

registerSelfLoweringActionEvent

Description
Definition
registerSelfLoweringActionEvent()
Code
891function Foldable:registerSelfLoweringActionEvent(superFunc, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName, ignoreCollisions)
892 return Foldable.registerLoweringActionEvent(self, superFunc, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName, ignoreCollisions)
893end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
283function Foldable:saveToXMLFile(xmlFile, key, usedModNames)
284 local spec = self.spec_foldable
285 setXMLFloat(xmlFile, key.."#foldAnimTime", spec.foldAnimTime)
286end

setAnimTime

Description
Definition
setAnimTime()
Code
1178function Foldable.setAnimTime(self, animTime, placeComponents)
1179 local spec = self.spec_foldable
1180
1181 spec.foldAnimTime = animTime
1182 spec.loadedFoldAnimTime = nil
1183 for _,foldingPart in pairs(spec.foldingParts) do
1184 if foldingPart.animCharSet ~= 0 then
1185 enableAnimTrack(foldingPart.animCharSet, 0)
1186 setAnimTrackTime(foldingPart.animCharSet, 0, spec.foldAnimTime * foldingPart.animDuration, true)
1187 disableAnimTrack(foldingPart.animCharSet, 0)
1188 else
1189 animTime = (spec.foldAnimTime * spec.maxFoldAnimDuration) / self:getAnimationDuration(foldingPart.animationName)
1190 self:setAnimationTime(foldingPart.animationName, animTime, true)
1191 end
1192 end
1193
1194 if placeComponents == nil then
1195 placeComponents = true
1196 end
1197
1198 if self.updateCylinderedInitial ~= nil then
1199 self:updateCylinderedInitial(placeComponents)
1200 end
1201
1202 if placeComponents then
1203 if self.isServer then
1204 for _,foldingPart in pairs(spec.foldingParts) do
1205 if foldingPart.componentJoint ~= nil then
1206 local componentJoint = foldingPart.componentJoint
1207
1208 local jointNode = componentJoint.jointNode
1209 if foldingPart.anchorActor == 1 then
1210 jointNode = componentJoint.jointNodeActor1
1211 end
1212
1213 local node = self.components[componentJoint.componentIndices[ ((foldingPart.anchorActor + 1) % 2) + 1] ].node
1214 local x,y,z = localToWorld(jointNode, foldingPart.x, foldingPart.y, foldingPart.z)
1215 local upX,upY,upZ = localDirectionToWorld(jointNode, foldingPart.upX,foldingPart.upY,foldingPart.upZ)
1216 local dirX,dirY,dirZ = localDirectionToWorld(jointNode, foldingPart.dirX,foldingPart.dirY,foldingPart.dirZ)
1217 setWorldTranslation(node, x,y,z)
1218 I3DUtil.setWorldDirection(node, dirX,dirY,dirZ, upX,upY,upZ)
1219
1220 self:setComponentJointFrame(componentJoint, foldingPart.anchorActor)
1221 end
1222 end
1223 end
1224 end
1225end

setFoldDirection

Description
Definition
setFoldDirection()
Code
368function Foldable:setFoldDirection(direction, noEventSend)
369 self:setFoldState(direction, false, noEventSend)
370end

setFoldState

Description
Definition
setFoldState()
Code
374function Foldable:setFoldState(direction, moveToMiddle, noEventSend)
375 local spec = self.spec_foldable
376
377 if spec.foldMiddleAnimTime == nil then
378 moveToMiddle = false
379 end
380 if spec.foldMoveDirection ~= direction or spec.moveToMiddle ~= moveToMiddle then
381 if noEventSend == nil or noEventSend == false then
382 if g_server ~= nil then
383 g_server:broadcastEvent(FoldableSetFoldDirectionEvent:new(self, direction, moveToMiddle), nil, nil, self)
384 else
385 g_client:getServerConnection():sendEvent(FoldableSetFoldDirectionEvent:new(self, direction, moveToMiddle))
386 end
387 end
388 spec.foldMoveDirection = direction
389 spec.moveToMiddle = moveToMiddle
390
391 for _,foldingPart in pairs(spec.foldingParts) do
392 local speedScale = nil
393 -- We don't do any animations if we are already past the middle time
394 if spec.foldMoveDirection > 0.1 then
395 if not spec.moveToMiddle or spec.foldAnimTime < spec.foldMiddleAnimTime then
396 speedScale = foldingPart.speedScale
397 end
398 elseif spec.foldMoveDirection < -0.1 then
399 if not spec.moveToMiddle or spec.foldAnimTime > spec.foldMiddleAnimTime then
400 speedScale = -foldingPart.speedScale
401 end
402 end
403
404 local charSet = foldingPart.animCharSet
405 if charSet ~= 0 then
406 if speedScale ~= nil then
407 if speedScale > 0 then
408 if getAnimTrackTime(charSet, 0) < 0.0 then
409 setAnimTrackTime(charSet, 0, 0.0)
410 end
411 else
412 if getAnimTrackTime(charSet, 0) > foldingPart.animDuration then
413 setAnimTrackTime(charSet, 0, foldingPart.animDuration)
414 end
415 end
416 setAnimTrackSpeedScale(charSet, 0, speedScale)
417 enableAnimTrack(charSet, 0)
418 else
419 disableAnimTrack(charSet, 0)
420 end
421 else
422 -- always stop to make sure the animation state is reset
423 local animTime
424 if self:getIsAnimationPlaying(foldingPart.animationName) then
425 animTime = self:getAnimationTime(foldingPart.animationName)
426 else
427 animTime = (spec.foldAnimTime * spec.maxFoldAnimDuration) / self:getAnimationDuration(foldingPart.animationName)
428 end
429 self:stopAnimation(foldingPart.animationName, true)
430 if speedScale ~= nil then
431 self:playAnimation(foldingPart.animationName, speedScale, animTime, true)
432
433 if moveToMiddle then
434 local stopAnimTime = (spec.foldMiddleAnimTime * spec.maxFoldAnimDuration)/ self:getAnimationDuration(foldingPart.animationName)
435 self:setAnimationStopTime(foldingPart.animationName, stopAnimTime)
436 end
437 end
438 end
439 end
440 -- slightly move fold anim time, so that fold limits can trigger for different actions
441 if spec.foldMoveDirection > 0.1 then
442 spec.foldAnimTime = math.min(spec.foldAnimTime + 0.0001, math.max(spec.foldAnimTime, 1))
443 elseif spec.foldMoveDirection < -0.1 then
444 spec.foldAnimTime = math.max(spec.foldAnimTime - 0.0001, math.min(spec.foldAnimTime, 0))
445 end
446
447 SpecializationUtil.raiseEvent(self, "onFoldStateChanged", direction, moveToMiddle)
448 end
449end

updateActionEventFold

Description
Definition
updateActionEventFold()
Code
1229function Foldable.updateActionEventFold(self)
1230 local spec = self.spec_foldable
1231 local actionEvent = spec.actionEvents[spec.foldInputButton]
1232 if actionEvent ~= nil then
1233 local direction = self:getToggledFoldDirection()
1234 local state = self:getIsFoldAllowed(direction, false)
1235 g_inputBinding:setActionEventActive(actionEvent.actionEventId, state)
1236 if state then
1237 local text
1238 if direction == spec.turnOnFoldDirection then
1239 text = spec.negDirectionText
1240 else
1241 text = spec.posDirectionText
1242 end
1243 g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format(g_i18n:getText(text, self.customEnvironment), self.typeDesc))
1244 end
1245 end
1246end

updateActionEventFoldMiddle

Description
Definition
updateActionEventFoldMiddle()
Code
1250function Foldable.updateActionEventFoldMiddle(self)
1251 local spec = self.spec_foldable
1252 local actionEvent = spec.actionEventsLowering[spec.foldMiddleInputButton]
1253 if actionEvent ~= nil then
1254 local state = self:getIsFoldMiddleAllowed()
1255 g_inputBinding:setActionEventActive(actionEvent.actionEventId, state)
1256 if state then
1257 local text
1258 if self:getToggledFoldMiddleDirection() == spec.foldMiddleDirection then
1259 text = spec.middlePosDirectionText
1260 else
1261 text = spec.middleNegDirectionText
1262 end
1263 g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format(g_i18n:getText(text, self.customEnvironment), self.typeDesc))
1264 end
1265 end
1266end