Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
inventoryitemtype.c
Go to the documentation of this file.
2//#define ITEM_SOUND_EVENTS_DEBUG
4{
5 protected string m_Name;
6 protected string m_CfgPath;
9
10 void InventoryItemSoundBase(string name, string cfgPath)
11 {
12 m_Name = name;
13 m_CfgPath = cfgPath;
14
16 }
17
18 protected void LoadSoundEvents();
19
24
29}
30
31class InventoryItemSoundAttach : InventoryItemSoundBase
32{
33 override void LoadSoundEvents()
34 {
35 TStringArray cfgSoundsetArray = new TStringArray();
36 TStringArray cfgSlotArray = new TStringArray();
37 g_Game.ConfigGetTextArray(m_CfgPath + " attachSoundSet", cfgSoundsetArray);
38 g_Game.ConfigGetTextArray(m_CfgPath + " attachSoundSlot", cfgSlotArray);
40 int soundSetCount = cfgSoundsetArray.Count();
41 if (soundSetCount > 0 && soundSetCount == cfgSlotArray.Count())
42 {
44
45 for (int i = 0; i < soundSetCount; ++i)
46 {
47 string soundSet = cfgSoundsetArray[i];
48 if (soundSet == "")
49 {
50 ErrorEx(string.Format("[%1] Try to register attach sound set with empty string not allowed! Please check attachSoundSet configuration for item %2", i, m_Name));
51 continue;
52 }
53
54 string slotName = cfgSlotArray[i];
55 if (slotName == "")
56 {
57 ErrorEx(string.Format("[%1] Try to register attach sound set %2 with empty slot name. Please check attachSoundSlot configuration for item %3", i, soundSet, m_Name));
58 continue;
59 }
60
61 int slotId = InventorySlots.GetSlotIdFromString(slotName);
62 if (slotId == InventorySlots.INVALID)
63 {
64 ErrorEx(string.Format("[%1] Try to register attach sound set %2 with invalid slot ID %3 (slot name: %4). Please check attachSoundSlot configuration for item %5", i, soundSet, slotId, slotName, m_Name));
65 continue;
66 }
67
68 if (!m_AttachSoundSets.Contains(slotId))
69 {
70 m_AttachSoundSets.Insert(slotId, soundSet);
71 #ifdef ITEM_SOUND_EVENTS_DEBUG
72 ErrorEx(string.Format("[%1] Registered attach sound set %2. Slot name: %3 | Slot ID: %4 | Item: %5", i, soundSet, slotName, slotId, m_Name), ErrorExSeverity.INFO);
73 #endif
74 }
75 }
76 }
77 #ifdef ITEM_SOUND_EVENTS_DEBUG
78 else
79 {
80 ErrorEx(string.Format("[%1] No attach sounds cofigurations found for item %1. Path: %2", m_Name, m_CfgPath + " attachSoundSet"), ErrorExSeverity.INFO);
81 }
82 #endif
83 }
84}
85
87{
88 override void LoadSoundEvents()
89 {
90 TStringArray cfgSoundsetArray = new TStringArray;
91 TStringArray cfgSlotArray = new TStringArray;
92 g_Game.ConfigGetTextArray(m_CfgPath + " detachSoundSet", cfgSoundsetArray);
93 g_Game.ConfigGetTextArray(m_CfgPath + " detachSoundSlot", cfgSlotArray);
94
95 if (cfgSoundsetArray.Count() > 0 && cfgSoundsetArray.Count() == cfgSlotArray.Count())
96 {
98
99 for (int i = 0; i < cfgSoundsetArray.Count(); ++i)
100 {
101 string soundSet = cfgSoundsetArray[i];
102 if (soundSet == "")
103 {
104 ErrorEx(string.Format("[%1] Try to register detach sound set %2 but sting is empty! Please check detachSoundSet configuration for item %3", i, soundSet, m_Name));
105 continue;
106 }
107
108 string slotName = cfgSlotArray[i];
109 if (slotName == "")
110 {
111 ErrorEx(string.Format("[%1] Try to register detach sound set %2 with invalid slot name %3. Please check detachSoundSlot configuration for item %4", i, soundSet, slotName, m_Name));
112 continue;
113 }
114
115 int slotId = InventorySlots.GetSlotIdFromString(slotName);
116 if (slotId == InventorySlots.INVALID)
117 {
118 ErrorEx(string.Format("[%1] Try to register detach sound set %2 with invalid slot ID %3 (slot name: %4). Please check detachSoundSlot configuration for item %5", i, soundSet, slotId, slotName, m_Name));
119 continue;
120 }
121
122 if (!m_DetachSoundSets.Contains(slotId))
123 {
124 m_DetachSoundSets.Insert(slotId, soundSet);
125 #ifdef ITEM_SOUND_EVENTS_DEBUG
126 ErrorEx(string.Format("[%1] Registered detach sound set %2. Slot name: %3 | Slot ID: %4 | Item: %5", i, soundSet, slotName, slotId, m_Name), ErrorExSeverity.INFO);
127 #endif
128 }
129 }
130 }
131 #ifdef ITEM_SOUND_EVENTS_DEBUG
132 else
133 {
134 ErrorEx(string.Format("[%1] No detach sounds cofigurations found for item %1. Path: %2", m_Name, m_CfgPath + " detachSoundSet"), ErrorExSeverity.INFO);
135 }
136 #endif
137 }
138}
139
140class InventoryItemType : EntityAIType
141{
143 private ref map<int, ref InventoryItemSoundBase> m_ActionSoundEvents = new map<int, ref InventoryItemSoundBase>(); // id (SoundConstants), InventoryItemSoundBase
144 private string m_DropSoundSet;
145
146 void InventoryItemType()
147 {
149 }
150
151 void ~InventoryItemType()
152 {
153 }
154
155 void LoadSoundEvents()
156 {
157 string name = GetName();
158 string cfgPath = CFG_VEHICLESPATH + " " + name + " AnimEvents SoundWeapon";
159
161
162 int soundCount = g_Game.ConfigGetChildrenCount(cfgPath);
163
164 if (soundCount <= 0)
165 {
166 cfgPath = CFG_WEAPONSPATH + " " + name + " AnimEvents SoundWeapon";
167 soundCount = g_Game.ConfigGetChildrenCount(cfgPath);
168 }
169
170 if (soundCount <= 0)
171 {
172 cfgPath = CFG_MAGAZINESPATH + " " + name + " AnimEvents SoundWeapon";
173 soundCount = g_Game.ConfigGetChildrenCount(cfgPath);
174 }
175
176 if (soundCount <= 0)
177 {
178 cfgPath = CFG_AMMO + " " + name + " AnimEvents SoundWeapon";
179 soundCount = g_Game.ConfigGetChildrenCount(cfgPath);
180 }
181
182 for (int i = 0; i < soundCount; ++i)
183 {
184 string soundName;
185 g_Game.ConfigGetChildName(cfgPath, i, soundName);
186 string soundPath = cfgPath + " " + soundName + " ";
187 AnimSoundEvent soundEvent = new AnimSoundEvent(soundPath);
188 if (soundEvent.IsValid())
189 {
190 m_AnimSoundEvents.Set(soundEvent.m_iID, soundEvent);
191 #ifdef ITEM_SOUND_EVENTS_DEBUG
192 ErrorEx(string.Format("[%1] Registered animation sound event for item %2. Sound name= %3 | Sound path= %4", i, name, soundName, soundPath), ErrorExSeverity.INFO);
193 #endif
194 }
195 #ifdef ITEM_SOUND_EVENTS_DEBUG
196 else
197 {
198 ErrorEx(string.Format("[%1] Skipped registration of animation sound event for item %2. Sound event invalid in configuration class! Sound name= %3 | Sound path= %4", i, name, soundName, soundPath), ErrorExSeverity.INFO);
199 }
200 #endif
201 }
202
203 SetDetachSoundEvent();
204 SetAttachSoundEvent();
205 }
206
207 bool SetDetachSoundEvent()
208 {
209 TStringArray cfgDetachSoundsetArray = new TStringArray;
210 string name = GetName();
211
212 string cfgPath = CFG_VEHICLESPATH + " " + name;
213 string soundPath = cfgPath + " detachSoundSet";
214 g_Game.ConfigGetTextArray(soundPath, cfgDetachSoundsetArray);
215 int soundCount = cfgDetachSoundsetArray.Count();
216
217 if (soundCount <= 0)
218 {
219 cfgPath = CFG_WEAPONSPATH + " " + name;
220 soundPath = cfgPath + " detachSoundSet";
221 g_Game.ConfigGetTextArray(soundPath, cfgDetachSoundsetArray);
222 soundCount = cfgDetachSoundsetArray.Count();
223 }
224
225 if (soundCount <= 0)
226 {
227 cfgPath = CFG_MAGAZINESPATH + " " + name;
228 soundPath = cfgPath + " detachSoundSet";
229 g_Game.ConfigGetTextArray(soundPath, cfgDetachSoundsetArray);
230 soundCount = cfgDetachSoundsetArray.Count();
231 }
232
233 if (soundCount <= 0)
234 {
235 cfgPath = CFG_AMMO + " " + name;
236 soundPath = cfgPath + " detachSoundSet";
237 g_Game.ConfigGetTextArray(soundPath, cfgDetachSoundsetArray);
238 soundCount = cfgDetachSoundsetArray.Count();
239 }
240
241 if (soundCount > 0)
242 {
243 m_ActionSoundEvents.Set(SoundConstants.ITEM_DETACH, new InventoryItemSoundDetach(name, cfgPath));
244 #ifdef ITEM_SOUND_EVENTS_DEBUG
245 ErrorEx(string.Format("Registered detach sound event instance for item %1", GetName()), ErrorExSeverity.INFO);
246 #endif
247 return true;
248 }
249 #ifdef ITEM_SOUND_EVENTS_DEBUG
250 else
251 {
252 ErrorEx(string.Format("Skipped creation of detach sound event instance for item %1. No detach sound in configuration class!", GetName()), ErrorExSeverity.INFO);
253 }
254 #endif
255
256 return false;
257 }
258
259 bool SetAttachSoundEvent()
260 {
261 TStringArray cfgAttachSoundsetArray = new TStringArray;
262 string name = GetName();
263
264 string cfgPath = CFG_VEHICLESPATH + " " + name;
265 string soundPath = cfgPath + " attachSoundSet";
266 g_Game.ConfigGetTextArray(soundPath, cfgAttachSoundsetArray);
267 int soundCount = cfgAttachSoundsetArray.Count();
268
269 if (soundCount <= 0)
270 {
271 cfgPath = CFG_WEAPONSPATH + " " + name;
272 soundPath = cfgPath + " attachSoundSet";
273 g_Game.ConfigGetTextArray(soundPath, cfgAttachSoundsetArray);
274 soundCount = cfgAttachSoundsetArray.Count();
275 }
276
277 if (soundCount <= 0)
278 {
279 cfgPath = CFG_MAGAZINESPATH + " " + name;
280 soundPath = cfgPath + " attachSoundSet";
281 g_Game.ConfigGetTextArray(soundPath, cfgAttachSoundsetArray);
282 soundCount = cfgAttachSoundsetArray.Count();
283 }
284
285 if (soundCount <= 0)
286 {
287 cfgPath = CFG_AMMO + " " + name;
288 soundPath = cfgPath + " attachSoundSet";
289 g_Game.ConfigGetTextArray(soundPath, cfgAttachSoundsetArray);
290 soundCount = cfgAttachSoundsetArray.Count();
291 }
292
293 if (soundCount > 0)
294 {
295 m_ActionSoundEvents.Set(SoundConstants.ITEM_ATTACH, new InventoryItemSoundAttach(name, cfgPath));
296 #ifdef ITEM_SOUND_EVENTS_DEBUG
297 ErrorEx(string.Format("Registered attach sound event instance for item %1", name), ErrorExSeverity.INFO);
298 #endif
299 return true;
300 }
301 #ifdef ITEM_SOUND_EVENTS_DEBUG
302 else
303 {
304 ErrorEx(string.Format("Skipped creation of attach sound event instance for item %1. No attach sound in configuration class!", name), ErrorExSeverity.INFO);
305 }
306 #endif
307
308 return false;
309 }
310
311 AnimSoundEvent GetSoundEvent(int event_id)
312 {
313 return m_AnimSoundEvents.Get(event_id);
314 }
315
316 InventoryItemSoundAttach GetAttachSoundEvent()
317 {
318 return InventoryItemSoundAttach.Cast(m_ActionSoundEvents[SoundConstants.ITEM_ATTACH]);
319 }
320
321 InventoryItemSoundDetach GetDetachSoundEvent()
322 {
323 return InventoryItemSoundDetach.Cast(m_ActionSoundEvents[SoundConstants.ITEM_DETACH]);
324 }
325
326 string GetSlotAttachSoundSet(int slotId = InventorySlots.INVALID)
327 {
328 InventoryItemSoundAttach soundEvent = GetAttachSoundEvent();
329 if (!soundEvent)
330 {
331 #ifdef ITEM_SOUND_EVENTS_DEBUG
332 ErrorEx(string.Format("No attach sound event instance found for item %1", GetName()), ErrorExSeverity.INFO);
333 #endif
334 return "";
335 }
336
337 string soundSet;
338 map<int, string> soundSets = soundEvent.GetAttachSoundSets();
339 if (soundSets && soundSets.Count() > 0)
340 {
341 if (slotId != InventorySlots.INVALID)
342 {
343 soundSets.Find(slotId, soundSet);
344 }
345 else
346 {
347 soundSet = soundSets.GetElement(0);
348 }
349 }
350 return soundSet;
351 }
352
353 string GetSlotDetachSoundSet(int slotId = InventorySlots.INVALID)
354 {
355 InventoryItemSoundDetach soundEvent = GetDetachSoundEvent();
356 if (!soundEvent)
357 {
358 #ifdef ITEM_SOUND_EVENTS_DEBUG
359 ErrorEx(string.Format("No detach sound event instance found for item %1", GetName()), ErrorExSeverity.INFO);
360 #endif
361 return "";
362 }
363
364 string soundSet;
365 map<int, string> soundSets = soundEvent.GetDetachSoundSets();
366 if (soundSets && soundSets.Count() > 0)
367 {
368 if (slotId != InventorySlots.INVALID)
369 {
370 soundSets.Find(slotId, soundSet);
371 }
372 else
373 {
374 soundSet = soundSets.GetElement(0);
375 }
376 }
377 return soundSet;
378 }
379
381 ref array<ref AnimSoundEvent> m_animSoundEvents;
382}
class InventoryItemSoundBase LoadSoundEvents()
string m_Name
string m_CfgPath
InventoryItemSoundDetach m_AnimSoundEvents
ref map< int, string > m_AttachSoundSets
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
PlayerSpawnPreset slotName
ref map< int, string > m_AttachSoundSets
ref map< int, string > m_DetachSoundSets
ref map< int, string > GetAttachSoundSets()
ref map< int, string > GetDetachSoundSets()
void InventoryItemSoundBase(string name, string cfgPath)
provides access to slot configuration
DayZGame g_Game
Definition dayzgame.c:3942
class DayZPlayerTypeAttachmentSoundLookupTable GetSoundEvent(int event_id)
Definition dayzplayer.c:180
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
array< string > TStringArray
Definition enscript.c:712
const string CFG_AMMO
Definition constants.c:223
const string CFG_VEHICLESPATH
Definition constants.c:220
const string CFG_WEAPONSPATH
Definition constants.c:221
const string CFG_MAGAZINESPATH
Definition constants.c:222
proto string GetName()
Suite class name getter. Strictly for UI porposes!
Definition syncedvalue.c:50