Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
2 | |
3 | ManureHeapShovelTrigger = {}; |
4 | ManureHeapShovelTrigger_mt = Class(ManureHeapShovelTrigger, ShovelFillTrigger); |
5 | |
6 | |
7 | function ManureHeapShovelTrigger:new(mt) |
8 | |
9 | if mt == nil then |
10 | mt = ManureHeapShovelTrigger_mt; |
11 | end; |
12 | |
13 | local self = ShovelFillTrigger:new(mt); |
14 | |
15 | self.fillLevel = 0; |
16 | self.capacity = 800000; |
17 | |
18 | self.vehiclesInRange = {}; |
19 | self.playerInRange = false; |
20 | |
21 | if not g_currentMission:getIsServer() then |
22 | g_currentMission:addUpdateable(self); |
23 | end; |
24 | |
25 | return self; |
26 | end; |
27 | |
28 | function ManureHeapShovelTrigger:delete() |
29 | if self.isShovelTarget then |
30 | if self.triggerId ~= nil then |
31 | g_currentMission:removeNodeObject(self.triggerId); |
32 | end |
33 | end |
34 | |
35 | ManureHeapShovelTrigger:superClass().delete(self); |
36 | end; |
37 | |
38 | function ManureHeapShovelTrigger:load(nodeId, fillLevelObject) |
39 | |
40 | if not ManureHeapShovelTrigger:superClass().load(self, nodeId, Fillable.FILLTYPE_MANURE) then |
41 | return false; |
42 | end |
43 | self.fillLevelObject = fillLevelObject; |
44 | |
45 | local capacityStr = getUserAttribute(nodeId, "capacity"); |
46 | if capacityStr ~= nil then |
47 | self.capacity = Utils.getNoNil(tonumber(capacityStr), self.capacity); |
48 | end; |
49 | |
50 | local minY, maxY = Utils.getVectorFromString(getUserAttribute(nodeId, "moveMinMaxY")); |
51 | if minY ~= nil and maxY ~= nil then |
52 | self.moveMinY = minY; |
53 | self.moveMaxY = maxY; |
54 | self.movingId = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "movingIndex")); |
55 | self.moveYPower = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "moveYPower")), 0.5); |
56 | local minY, maxY = Utils.getVectorFromString(getUserAttribute(nodeId, "triggerMinMaxY")); |
57 | if minY ~= nil and maxY ~= nil then |
58 | self.triggerMinY = minY; |
59 | self.triggerMaxY = maxY; |
60 | self.triggerYPower = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "triggerYPower")), self.moveYPower); |
61 | end |
62 | end; |
63 | |
64 | if fillLevelObject.isServer then |
65 | self.isShovelTarget = Utils.getNoNil(getUserAttribute(nodeId, "isShovelTarget"), true); |
66 | if self.isShovelTarget then |
67 | if self.triggerId ~= nil then |
68 | g_currentMission:addNodeObject(self.triggerId, self); |
69 | end |
70 | end |
71 | end |
72 | |
73 | return true; |
74 | end; |
75 | |
76 | function ManureHeapShovelTrigger:update(dt) |
77 | ManureHeapShovelTrigger:superClass().update(self, dt); |
78 | |
79 | if self:getShowInfo() then |
80 | g_currentMission:addExtraPrintText(g_i18n:getText("fill_level").." "..math.floor(self.fillLevel).." ("..math.floor(100*self.fillLevel/self.capacity).."%)"); |
81 | end; |
82 | end; |
83 | |
84 | function ManureHeapShovelTrigger:getShowInfo() |
85 | if (g_currentMission.controlPlayer and self.playerInRange) then |
86 | return true; |
87 | end; |
88 | if not g_currentMission.controlPlayer then |
89 | for vehicle in pairs(self.vehiclesInRange) do |
90 | if vehicle:getIsActiveForInput(false) then |
91 | return true; |
92 | end; |
93 | end; |
94 | end; |
95 | return false; |
96 | end; |
97 | |
98 | function ManureHeapShovelTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
99 | -- if self.isEnabled and (onEnter or onLeave) then |
100 | -- |
101 | -- if g_currentMission.player ~= nil and otherActorId == g_currentMission.player.rootNode then |
102 | -- if onEnter then |
103 | -- self.playerInRange = true; |
104 | -- else |
105 | -- self.playerInRange = false; |
106 | -- end; |
107 | -- else |
108 | -- local vehicle = g_currentMission.nodeToVehicle[otherActorId]; |
109 | -- if vehicle ~= nil then |
110 | -- if onEnter then |
111 | -- self.vehiclesInRange[vehicle] = true; |
112 | -- else |
113 | -- self.vehiclesInRange[vehicle] = nil; |
114 | -- end; |
115 | -- end; |
116 | -- end; |
117 | -- end |
118 | |
119 | ManureHeapShovelTrigger:superClass().triggerCallback(self, triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId); |
120 | end; |
121 | |
122 | function ManureHeapShovelTrigger:infoTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
123 | if self.isEnabled and (onEnter or onLeave) then |
124 | |
125 | if g_currentMission.player ~= nil and otherActorId == g_currentMission.player.rootNode then |
126 | if onEnter then |
127 | self.playerInRange = true; |
128 | else |
129 | self.playerInRange = false; |
130 | end; |
131 | else |
132 | local vehicle = g_currentMission.nodeToVehicle[otherActorId]; |
133 | if vehicle ~= nil then |
134 | if onEnter then |
135 | self.vehiclesInRange[vehicle] = true; |
136 | else |
137 | self.vehiclesInRange[vehicle] = nil; |
138 | end; |
139 | end; |
140 | end; |
141 | end |
142 | |
143 | ManureHeapShovelTrigger:superClass().infoTriggerCallback(self, triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId); |
144 | end; |
145 | |
146 | function ManureHeapShovelTrigger:fillShovel(shovel, dt) |
147 | if self.fillLevel > 0 then |
148 | local delta = shovel:fillShovelFromTrigger(self, self.fillLevel, Fillable.FILLTYPE_MANURE, dt); |
149 | |
150 | if delta > 0 then |
151 | self:setFillLevel(self.fillLevel - delta); |
152 | end |
153 | end |
154 | end |
155 | |
156 | function ManureHeapShovelTrigger:setFillLevel(fillLevel, noEventSend) |
157 | |
158 | fillLevel = Utils.clamp(fillLevel, 0, self.capacity); |
159 | |
160 | if self.fillLevel ~= fillLevel then |
161 | self.fillLevel = fillLevel; |
162 | |
163 | if noEventSend == nil or not noEventSend then |
164 | self.fillLevelObject:manureFillLevelChanged(fillLevel, Fillable.FILLTYPE_MANURE, self); |
165 | end |
166 | |
167 | if self.movingId ~= nil then |
168 | local x,_,z = getTranslation(self.movingId); |
169 | local alpha = Utils.clamp(self.fillLevel/self.capacity, 0, 1); |
170 | local y = self.moveMinY + (self.moveMaxY - self.moveMinY)*(alpha ^ self.moveYPower); |
171 | setTranslation(self.movingId, x,y,z); |
172 | |
173 | if self.triggerId ~= 0 and self.triggerMinY ~= nil then |
174 | local x,_,z = getTranslation(self.triggerId); |
175 | local y = self.triggerMinY + (self.triggerMaxY - self.triggerMinY)*(alpha ^ self.triggerYPower); |
176 | setTranslation(self.triggerId, x,y,z); |
177 | end |
178 | end; |
179 | end |
180 | end; |
181 | |
182 | function ManureHeapShovelTrigger:getAllowShovelFillType(fillType) |
183 | if fillType == Fillable.FILLTYPE_MANURE then |
184 | return true; |
185 | end |
186 | return false; |
187 | end; |
188 | |
189 | function ManureHeapShovelTrigger:addShovelFillLevel(shovel, fillLevelDelta, fillType) |
190 | if self:getAllowShovelFillType(fillType) then |
191 | local oldFillLevel = self.fillLevel; |
192 | self:setFillLevel(oldFillLevel + fillLevelDelta); |
193 | return self.fillLevel - oldFillLevel; |
194 | end; |
195 | return 0; |
196 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de