Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- |
2 | -- Pickup |
3 | -- This is the specialization for vehicles with a pickup |
4 | -- |
5 | -- @author Manuel Leithner |
6 | -- @date 14/01/14 |
7 | -- |
8 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
9 | |
10 | Pickup = {}; |
11 | source("dataS/scripts/vehicles/specializations/PickupSetStateEvent.lua"); |
12 | |
13 | function Pickup.prerequisitesPresent(specializations) |
14 | return true; |
15 | end; |
16 | |
17 | function Pickup:preLoad(xmlFile) |
18 | assert(self.allowPickingUp == nil, "Pickup needs to be the first specialization which implements allowPickingUp"); |
19 | self.allowPickingUp = Pickup.allowPickingUp; |
20 | end |
21 | |
22 | function Pickup:load(xmlFile) |
23 | |
24 | self.setPickupState = Pickup.setPickupState; |
25 | self.isLowered = Utils.overwrittenFunction(self.isLowered, Pickup.isLowered); |
26 | |
27 | self.isPickupLowered = false; |
28 | self.pickupAnimationName = Utils.getNoNil(getXMLString(xmlFile, "vehicle.pickupAnimation#name"), ""); |
29 | if self.playAnimation == nil or self.getIsAnimationPlaying == nil then |
30 | self.pickupAnimationName = ""; |
31 | self.isPickupLowered = true; |
32 | end; |
33 | self.pickupAnimationLowerSpeed = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.pickupAnimation#lowerSpeed"), 1); |
34 | self.pickupAnimationLiftSpeed = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.pickupAnimation#liftSpeed"), -self.pickupAnimationLowerSpeed); |
35 | |
36 | if self.pickupAnimationName ~= "" then |
37 | self.pickupAnimationIsDefaultLowered = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.pickupAnimation#isDefaultLowered"), false); |
38 | local dir = -20; |
39 | if self.pickupAnimationIsDefaultLowered then |
40 | dir = 20; |
41 | self.isPickupLowered = true; |
42 | end; |
43 | self:playAnimation(self.pickupAnimationName, dir, nil, true); |
44 | AnimatedVehicle.updateAnimations(self, 99999999); |
45 | end; |
46 | end; |
47 | |
48 | function Pickup:delete() |
49 | end; |
50 | |
51 | function Pickup:readStream(streamId, connection) |
52 | local isPickupLowered = streamReadBool(streamId); |
53 | self:setPickupState(isPickupLowered, true); |
54 | end; |
55 | |
56 | function Pickup:writeStream(streamId, connection) |
57 | streamWriteBool(streamId, self.isPickupLowered); |
58 | end; |
59 | |
60 | function Pickup:mouseEvent(posX, posY, isDown, isUp, button) |
61 | end; |
62 | |
63 | function Pickup:keyEvent(unicode, sym, modifier, isDown) |
64 | end; |
65 | |
66 | function Pickup:update(dt) |
67 | if self:getIsActiveForInput() then |
68 | if self.pickupAnimationName ~= "" then |
69 | if InputBinding.hasEvent(InputBinding.LOWER_IMPLEMENT) then |
70 | self:setPickupState(not self.isPickupLowered); |
71 | end; |
72 | end; |
73 | end; |
74 | end; |
75 | |
76 | function Pickup:draw() |
77 | if self.isClient then |
78 | if self:getIsActiveForInput(true) then |
79 | if self.pickupAnimationName ~= "" then |
80 | if self.isPickupLowered then |
81 | g_currentMission:addHelpButtonText(string.format(g_i18n:getText("lift_OBJECT"), g_i18n:getText("TypeDesc_Pickup")), InputBinding.LOWER_IMPLEMENT); |
82 | else |
83 | g_currentMission:addHelpButtonText(string.format(g_i18n:getText("lower_OBJECT"), g_i18n:getText("TypeDesc_Pickup")), InputBinding.LOWER_IMPLEMENT); |
84 | end; |
85 | end; |
86 | end; |
87 | end; |
88 | end; |
89 | |
90 | function Pickup:setPickupState(isPickupLowered, noEventSend) |
91 | PickupSetStateEvent.sendEvent(self, isPickupLowered, noEventSend) |
92 | self.isPickupLowered = isPickupLowered; |
93 | |
94 | if self.pickupAnimationName ~= "" then |
95 | local animTime = nil; |
96 | if self:getIsAnimationPlaying(self.pickupAnimationName) then |
97 | animTime = self:getAnimationTime(self.pickupAnimationName); |
98 | end; |
99 | if isPickupLowered then |
100 | self:playAnimation(self.pickupAnimationName, self.pickupAnimationLowerSpeed, animTime, true) |
101 | else |
102 | self:playAnimation(self.pickupAnimationName, self.pickupAnimationLiftSpeed, animTime, true) |
103 | end; |
104 | end; |
105 | end; |
106 | |
107 | function Pickup:allowPickingUp() |
108 | return self.isPickupLowered; |
109 | end; |
110 | |
111 | function Pickup:isLowered(superFunc, default) |
112 | if not self.isPickupLowered then |
113 | return false; |
114 | end |
115 | |
116 | if superFunc ~= nil then |
117 | return superFunc(self, default); |
118 | end |
119 | return default; |
120 | end; |
121 | |
122 | function Pickup:onLowerAll(doLowering, jointDescIndex) |
123 | self:setPickupState(doLowering); |
124 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de