158 | function Pallet:getMeshNodes(superFunc) |
159 | local spec = self.spec_pallet |
160 | if spec.tensionBeltMeshesDirty then |
161 | spec.tensionBeltMeshes = {} |
162 | |
163 | if spec.node ~= nil then |
164 | table.insert(spec.tensionBeltMeshes, spec.node) |
165 | end |
166 | |
167 | for i=1, #spec.contents do |
168 | local content = spec.contents[i] |
169 | for j=1, #content.objects do |
170 | local object = content.objects[j] |
171 | if object.isActive then |
172 | table.insert(spec.tensionBeltMeshes, object.tensionBeltNode or object.node) |
173 | end |
174 | end |
175 | end |
176 | end |
177 | |
178 | if #spec.tensionBeltMeshes > 0 then |
179 | return spec.tensionBeltMeshes |
180 | end |
181 | |
182 | return superFunc(self) |
183 | end |
23 | function Pallet.initSpecialization() |
24 | local schema = Vehicle.xmlSchema |
25 | schema:setXMLSpecializationType("Pallet") |
26 | |
27 | schema:register(XMLValueType.INT, "vehicle.pallet#fillUnitIndex", "Fill unit index", 1) |
28 | schema:register(XMLValueType.NODE_INDEX, "vehicle.pallet#node", "Root visual pallet node") |
29 | |
30 | schema:register(XMLValueType.INT, "vehicle.pallet.content(?)#fillUnitIndex", "Fill unit index for this content", "pallet#fillUnitIndex") |
31 | schema:register(XMLValueType.NODE_INDEX, "vehicle.pallet.content(?).object(?)#node", "Object node") |
32 | schema:register(XMLValueType.NODE_INDEX, "vehicle.pallet.content(?).object(?)#tensionBeltNode", "Object used for tension belt calculations") |
33 | |
34 | SoundManager.registerSampleXMLPaths(schema, "vehicle.pallet.sounds", "unload") |
35 | |
36 | schema:setXMLSpecializationType() |
37 | end |
122 | function Pallet:onFillUnitFillLevelChanged(fillUnitIndex, fillLevelDelta, fillType, toolType, fillPositionData, appliedDelta) |
123 | local spec = self.spec_pallet |
124 | for i=1, #spec.contents do |
125 | local content = spec.contents[i] |
126 | |
127 | if content.fillUnitIndex == fillUnitIndex then |
128 | local fillLevelPct = self:getFillUnitFillLevelPercentage(fillUnitIndex) |
129 | |
130 | local visibleIndex = math.floor(content.numObjects * fillLevelPct) |
131 | if visibleIndex == 0 and fillLevelPct then |
132 | visibleIndex = 1 -- show at least one object if somethign is loaded |
133 | end |
134 | |
135 | for j=1, #content.objects do |
136 | local object = content.objects[j] |
137 | local isActive = j <= visibleIndex |
138 | if object.isActive ~= isActive then |
139 | local unloading = object.isActive and not isActive |
140 | |
141 | if unloading then |
142 | if self.isClient then |
143 | g_soundManager:playSample(spec.samples.unload) |
144 | end |
145 | end |
146 | |
147 | object.isActive = isActive |
148 | setVisibility(object.node, object.isActive) |
149 | spec.tensionBeltMeshesDirty = true |
150 | end |
151 | end |
152 | end |
153 | end |
154 | end |
68 | function Pallet:onLoad(savegame) |
69 | local spec = self.spec_pallet |
70 | |
71 | spec.fillUnitIndex = self.xmlFile:getValue("vehicle.pallet#fillUnitIndex", 1) |
72 | spec.node = self.xmlFile:getValue("vehicle.pallet#node", nil, self.components, self.i3dMappings) |
73 | |
74 | spec.contents = {} |
75 | self.xmlFile:iterate("vehicle.pallet.content", function(_, contentKey) |
76 | local content = {} |
77 | content.objects = {} |
78 | content.fillUnitIndex = self.xmlFile:getValue(contentKey .. "#fillUnitIndex", spec.fillUnitIndex) |
79 | |
80 | self.xmlFile:iterate(contentKey .. ".object", function(index, key) |
81 | local object = {} |
82 | object.node = self.xmlFile:getValue(key .. "#node", nil, self.components, self.i3dMappings) |
83 | if object.node ~= nil then |
84 | object.tensionBeltNode = self.xmlFile:getValue(key .. "#tensionBeltNode", nil, self.components, self.i3dMappings) |
85 | object.isActive = false |
86 | setVisibility(object.node, object.isActive) |
87 | |
88 | table.insert(content.objects, object) |
89 | end |
90 | end) |
91 | |
92 | if #content.objects > 0 then |
93 | content.numObjects = #content.objects |
94 | table.insert(spec.contents, content) |
95 | end |
96 | end) |
97 | |
98 | spec.tensionBeltMeshes = {spec.node} |
99 | spec.tensionBeltMeshesDirty = false |
100 | |
101 | if self.isClient then |
102 | spec.samples = {} |
103 | spec.samples.unload = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.pallet.sounds", "unload", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self) |
104 | end |
105 | |
106 | g_currentMission.slotSystem:addLimitedObject(SlotSystem.LIMITED_OBJECT_PALLET, self) |
107 | end |