Sprache Deutsch Language English

Script Dokumentation LS 2015 - BaleGrab (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/BaleGrab.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1--
2-- BaleGrab
3-- Class for a balegrab tool
4--
5-- @author Manuel Leithner / Stefan Geiger
6-- @date 07/08/13
7--
8-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
9
10BaleGrab = {};
11
12function BaleGrab.prerequisitesPresent(specializations)
13 return true;
14end;
15
16function BaleGrab:load(xmlFile)
17
18 self.dynamicMountTriggerCallback = BaleGrab.dynamicMountTriggerCallback;
19 self.addDynamicMountedObject = BaleGrab.addDynamicMountedObject;
20 self.removeDynamicMountedObject = BaleGrab.removeDynamicMountedObject;
21
22 if self.isServer then
23 local attacherTriggerTriggerNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.baleGrab#triggerNode"));
24 local attacherTriggerRootNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.baleGrab#rootNode"));
25 local attacherTriggerJointNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.baleGrab#jointNode"));
26 local attacherJointTypeString = Utils.getNoNil(getXMLString(xmlFile, "vehicle.baleGrab#jointType"), "TYPE_AUTO_ATTACH_Y");
27 local attacherJointType = DynamicMountUtil.TYPE_AUTO_ATTACH_Y;
28 if attacherJointTypeString == "TYPE_FORK" then
29 attacherJointType = DynamicMountUtil.TYPE_FORK;
30 elseif attacherJointTypeString == "TYPE_AUTO_ATTACH_XZ" then
31 attacherJointType = DynamicMountUtil.TYPE_AUTO_ATTACH_XZ;
32 elseif attacherJointTypeString == "TYPE_AUTO_ATTACH_XYZ" then
33 attacherJointType = DynamicMountUtil.TYPE_AUTO_ATTACH_XYZ;
34 end;
35 if attacherTriggerTriggerNode ~= nil and attacherTriggerRootNode ~= nil and attacherTriggerJointNode ~= nil then
36 local forceAcceleration = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.baleGrab#forceAcceleration"), 20);
37 addTrigger(attacherTriggerTriggerNode, "dynamicMountTriggerCallback", self);
38
39 local grabRefComponentJointIndex1 = getXMLInt(xmlFile, "vehicle.baleGrab#grabRefComponentJointIndex1");
40 local grabRefComponentJointIndex2 = getXMLInt(xmlFile, "vehicle.baleGrab#grabRefComponentJointIndex2");
41 local componentJoint1, componentJoint2;
42 if grabRefComponentJointIndex1 ~= nil then
43 componentJoint1 = self.componentJoints[grabRefComponentJointIndex1+1];
44 end
45 if grabRefComponentJointIndex2 ~= nil then
46 componentJoint2 = self.componentJoints[grabRefComponentJointIndex2+1];
47 end
48 local rotDiffThreshold1 = math.rad(Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.baleGrab#rotDiffThreshold1"), 2));
49 local rotDiffThreshold2 = math.rad(Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.baleGrab#rotDiffThreshold2"), 2));
50 self.dynamicMountAttacherTrigger = {
51 triggerNode=attacherTriggerTriggerNode, rootNode=attacherTriggerRootNode, jointNode=attacherTriggerJointNode, attacherJointType=attacherJointType, forceAcceleration=forceAcceleration,
52 componentJoint1=componentJoint1, rotDiffThreshold1=rotDiffThreshold1, cosRotDiffThreshold1=math.cos(rotDiffThreshold1),
53 componentJoint2=componentJoint2, rotDiffThreshold2=rotDiffThreshold2, cosRotDiffThreshold2=math.cos(rotDiffThreshold2)
54 };
55 end
56 self.dynamicMountedObjects = {};
57 self.pendingDynamicMountObjects = {};
58 end
59end;
60
61function BaleGrab:delete()
62 if self.isServer then
63 for object,_ in pairs(self.dynamicMountedObjects) do
64 object:unmountDynamic();
65 end
66 end
67 if self.dynamicMountAttacherTrigger ~= nil then
68 removeTrigger(self.dynamicMountAttacherTrigger.triggerNode);
69 end
70end;
71
72function BaleGrab:mouseEvent(posX, posY, isDown, isUp, button)
73end;
74
75function BaleGrab:keyEvent(unicode, sym, modifier, isDown)
76end;
77
78function BaleGrab:update(dt)
79end;
80
81function BaleGrab:updateTick(dt)
82 if self.isServer and self:getIsActive() then
83 local attachTrigger = self.dynamicMountAttacherTrigger
84
85 local isClosed = true;
86 if attachTrigger.componentJoint1 ~= nil then
87 isClosed = BaleGrab.isComponentJointOutsideLimit(self, attachTrigger.componentJoint1, attachTrigger.rotDiffThreshold1, attachTrigger.cosRotDiffThreshold1);
88 end
89 if isClosed and attachTrigger.componentJoint2 ~= nil then
90 isClosed = BaleGrab.isComponentJointOutsideLimit(self, attachTrigger.componentJoint2, attachTrigger.rotDiffThreshold2, attachTrigger.cosRotDiffThreshold2);
91 end
92 if isClosed then
93 for object,_ in pairs(self.pendingDynamicMountObjects) do
94 if self.dynamicMountedObjects[object] == nil then
95 object:unmountDynamic();
96 if object:mountDynamic(self, self.dynamicMountAttacherTrigger.rootNode, self.dynamicMountAttacherTrigger.jointNode, self.dynamicMountAttacherTrigger.attacherJointType, self.dynamicMountAttacherTrigger.forceAcceleration) then
97 self:addDynamicMountedObject(object);
98 end;
99 end
100 end
101 else
102 for object,_ in pairs(self.dynamicMountedObjects) do
103 self:removeDynamicMountedObject(object, false);
104 object:unmountDynamic();
105 end;
106 end;
107 end
108end;
109
110function BaleGrab:draw()
111end;
112
113function BaleGrab:addDynamicMountedObject(object)
114 self.dynamicMountedObjects[object] = object;
115end
116
117function BaleGrab:removeDynamicMountedObject(object, isDeleting)
118 self.dynamicMountedObjects[object] = nil;
119 if isDeleting then
120 self.pendingDynamicMountObjects[object] = nil;
121 end
122end
123
124function BaleGrab:dynamicMountTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
125 if onEnter then
126 local object = g_currentMission:getNodeObject(otherActorId);
127 if object == nil then
128 object = g_currentMission.nodeToVehicle[otherActorId];
129 end;
130 if object ~= nil and object ~= self and object.getSupportsMountDynamic ~= nil and object:getSupportsMountDynamic() then
131 self.pendingDynamicMountObjects[object] = Utils.getNoNil(self.pendingDynamicMountObjects[object], 0) + 1;
132 end
133 elseif onLeave then
134 local object = g_currentMission:getNodeObject(otherActorId);
135 if object == nil then
136 object = g_currentMission.nodeToVehicle[otherActorId];
137 end;
138 if object ~= nil then
139 if self.pendingDynamicMountObjects[object] ~= nil then
140 local count = self.pendingDynamicMountObjects[object]-1;
141 if count == 0 then
142 self.pendingDynamicMountObjects[object] = nil;
143
144 if self.dynamicMountedObjects[object] ~= nil then
145 self:removeDynamicMountedObject(object, false);
146 object:unmountDynamic();
147 end
148 else
149 self.pendingDynamicMountObjects[object] = count;
150 end
151 end
152 end
153 end
154end;
155
156function BaleGrab.isComponentJointOutsideLimit(self, componentJoint, maxRot, cosMaxRot)
157 local x,_,z = localDirectionToLocal(self.components[componentJoint.componentIndices[2]].node, componentJoint.jointNode, 0,0,1);
158 if (x >= 0) == (maxRot >= 0) then
159 --print("angle: "..math.deg(math.acos(z/math.sqrt(x*x + z*z))));
160 if z <= cosMaxRot*math.sqrt(x*x + z*z) then
161 return true;
162 end
163 end
164 return false;
165end
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
Script Dokumentation Übersicht