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
- 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
FrontloaderAttacher
DescriptionSpecialization providing a frontloader attacher dependent on configurationFunctions
- initSpecialization
- onLoad
- onPreAttachImplement
- onPreDetachImplement
- prerequisitesPresent
- registerEventListeners
initSpecialization
DescriptionDefinitioninitSpecialization()Code
29 | function FrontloaderAttacher.initSpecialization() |
30 | g_configurationManager:addConfigurationType("frontloader", g_i18n:getText("configuration_frontloaderAttacher"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION) |
31 | |
32 | local schema = Vehicle.xmlSchema |
33 | schema:setXMLSpecializationType("FrontloaderAttacher") |
34 | |
35 | local basePath = "vehicle.frontloaderConfigurations.frontloaderConfiguration(?)" |
36 | AttacherJoints.registerAttacherJointXMLPaths(schema, basePath .. ".attacherJoint") |
37 | |
38 | schema:register(XMLValueType.BOOL, basePath .. ".attacherJoint#frontAxisLimitJoint", "Front axis joint will be limited while attached", true) |
39 | schema:register(XMLValueType.INT, basePath .. ".attacherJoint#frontAxisJoint", "Front axis joint index", 1) |
40 | |
41 | ObjectChangeUtil.registerObjectChangeXMLPaths(schema, basePath) |
42 | |
43 | schema:setXMLSpecializationType() |
44 | end |
onLoad
DescriptionDefinitiononLoad()Code
48 | function FrontloaderAttacher:onLoad(savegame) |
49 | if self.configurations["frontloader"] ~= nil then |
50 | local spec = self.spec_frontloaderAttacher |
51 | local attacherJointsSpec = self.spec_attacherJoints |
52 | |
53 | spec.attacherJoint = {} |
54 | local key = string.format("vehicle.frontloaderConfigurations.frontloaderConfiguration(%d)", self.configurations["frontloader"]-1) |
55 | if self.xmlFile:hasProperty(key..".attacherJoint") and self:loadAttacherJointFromXML(spec.attacherJoint, self.xmlFile, key..".attacherJoint", 0) then |
56 | table.insert(attacherJointsSpec.attacherJoints, spec.attacherJoint) |
57 | |
58 | local frontAxisLimitJoint = self.xmlFile:getValue(key..".attacherJoint#frontAxisLimitJoint", true) |
59 | if frontAxisLimitJoint then |
60 | local frontAxisJoint = self.xmlFile:getValue(key..".attacherJoint#frontAxisJoint", 1) |
61 | if self.componentJoints[frontAxisJoint] ~= nil then |
62 | spec.frontAxisJoint = frontAxisJoint |
63 | else |
64 | print("Warning: Invalid front-axis joint '"..tostring(frontAxisJoint).."' in '"..self.configFileName.."'") |
65 | end |
66 | end |
67 | |
68 | ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.frontloaderConfigurations.frontloaderConfiguration", self.configurations["frontloader"], self.components, self) |
69 | else |
70 | -- first config is "no-frontloader"-option |
71 | ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.frontloaderConfigurations.frontloaderConfiguration", 1, self.components, self) |
72 | spec.attacherJoint = nil |
73 | end |
74 | end |
75 | end |
onPreAttachImplement
DescriptionDefinitiononPreAttachImplement()Code
101 | function FrontloaderAttacher:onPreAttachImplement(attachable, inputJointDescIndex, jointDescIndex) |
102 | local spec = self.spec_frontloaderAttacher |
103 | |
104 | if spec.frontAxisJoint ~= nil then |
105 | local attacherJoint = nil |
106 | local attacherJoints = self:getAttacherJoints() |
107 | if attacherJoints ~= nil then |
108 | attacherJoint = attacherJoints[jointDescIndex] |
109 | end |
110 | if attacherJoint ~= nil then |
111 | if attacherJoint.jointType == AttacherJoints.JOINTTYPE_ATTACHABLEFRONTLOADER and self.isServer then |
112 | -- copy rotlimit |
113 | spec.rotLimit = { unpack(self.componentJoints[spec.frontAxisJoint].rotLimit) } |
114 | for i=1, 3 do |
115 | self:setComponentJointRotLimit(self.componentJoints[spec.frontAxisJoint], i, 0, 0) |
116 | end |
117 | end |
118 | end |
119 | end |
120 | end |
onPreDetachImplement
DescriptionDefinitiononPreDetachImplement()Code
79 | function FrontloaderAttacher:onPreDetachImplement(implement) |
80 | local spec = self.spec_frontloaderAttacher |
81 | |
82 | if spec.frontAxisJoint ~= nil then |
83 | local attacherJoint = nil |
84 | local attacherJointIndex = implement.jointDescIndex |
85 | local attacherJoints = self:getAttacherJoints() |
86 | if attacherJoints ~= nil then |
87 | attacherJoint = attacherJoints[attacherJointIndex] |
88 | end |
89 | if attacherJoint ~= nil then |
90 | if attacherJoint.jointType == AttacherJoints.JOINTTYPE_ATTACHABLEFRONTLOADER and self.isServer then |
91 | for i=1, 3 do |
92 | self:setComponentJointRotLimit(self.componentJoints[spec.frontAxisJoint], i, -spec.rotLimit[i], spec.rotLimit[i]) |
93 | end |
94 | end |
95 | end |
96 | end |
97 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
15 | function FrontloaderAttacher.prerequisitesPresent(specializations) |
16 | return SpecializationUtil.hasSpecialization(AttacherJoints, specializations) |
17 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
21 | function FrontloaderAttacher.registerEventListeners(vehicleType) |
22 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", FrontloaderAttacher) |
23 | SpecializationUtil.registerEventListener(vehicleType, "onPreDetachImplement", FrontloaderAttacher) |
24 | SpecializationUtil.registerEventListener(vehicleType, "onPreAttachImplement", FrontloaderAttacher) |
25 | end |