Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
impacteffects.c
Go to the documentation of this file.
2 {
3  UNKNOWN;
4  STOP;
5  PENETRATE;
6  RICOCHET;
8 }
9 
10 class ImpactEffectsData
11 {
16  bool m_IsWater;
17  string m_Surface;
18  string m_AmmoType;
24 
25 
26 }
27 
29 {
30  ref static map<string, typename> m_ImpactEffect;
31  static int m_LastRegisteredMaterial = 0;
32 
34  ref static map<string, int> m_IgnoredAmmo;
35  static int m_LastRegisteredIgnoredAmmo = 0;
36 
42  static int PLASTIC = RegisterSurface("Hit_Plastic");
43  static int SAND = RegisterSurface("Hit_Sand");
44  static int TEXTILE = RegisterSurface("Hit_Textile");
45  static int CONCRETE = RegisterSurface("Hit_Concrete");
46  static int GRAVEL = RegisterSurface("Hit_Gravel");
47  static int DIRT = RegisterSurface("Hit_Dirt");
48  static int FOLIAGE = RegisterSurface("Hit_Foliage");
49  static int GRASS = RegisterSurface("Hit_Grass");
50  static int WOOD = RegisterSurface("Hit_Wood");
51  static int METAL = RegisterSurface("Hit_Metal");
52  static int GLASS = RegisterSurface("Hit_Glass");
53  static int GLASS_THIN = RegisterSurface("Hit_Glass_Thin");
54  static int WATER = RegisterSurface("Hit_Water");
55  static int RUBBER = RegisterSurface("Hit_Rubber");
56  static int PLASTER = RegisterSurface("Hit_Plaster");
57  static int MEATBONES = RegisterSurface("Hit_MeatBones");
58  static int MEATBONES_SHOVEL = RegisterSurface("Hit_MeatBones_MeleeShovel");
59  static int MEATBONES_PIPEWRENCH = RegisterSurface("Hit_MeatBones_MeleePipeWrench");
60  static int MEATBONES_WRENCH = RegisterSurface("Hit_MeatBones_MeleeWrench");
61  static int MEATBONES_FIST = RegisterSurface("Hit_MeatBones_MeleeFist");
62  static int UNDEFINED = RegisterSurface("Hit_Undefined");
63  static int ERROR_NO_MATERIAL = RegisterSurface("Hit_ErrorNoMaterial");
65 
71  static int FIST = RegisterIgnoredAmmo("MeleeFist");
72  static int FIST_HEAVY = RegisterIgnoredAmmo("MeleeFist_Heavy");
73  static int SOFT = RegisterIgnoredAmmo("MeleeSoft");
74  static int SOFT_HEAVY = RegisterIgnoredAmmo("MeleeSoft_Heavy");
75  static int DUMMY = RegisterIgnoredAmmo("Dummy_Light");
76  static int DUMMY_HEAVY = RegisterIgnoredAmmo("Dummy_Heavy");
78 
79  static int RegisterSurface(string surface)
80  {
81  if (!m_ImpactEffect)
82  m_ImpactEffect = new map<string, typename>;
83 
84  m_ImpactEffect.Insert(surface, surface.ToType());
85 
86  return ++m_LastRegisteredMaterial;
87  }
88 
89  static bool UnregisterSurface(string surface)
90  {
91  if (m_ImpactEffect)
92  {
93  m_ImpactEffect.Remove(surface);
94  return !m_ImpactEffect.Contains(surface);
95  }
96 
97  return false;
98  }
99 
100  static int RegisterIgnoredAmmo(string ammo)
101  {
102  if (!m_IgnoredAmmo)
103  m_IgnoredAmmo = new map<string, int>;
104 
105  ++m_LastRegisteredIgnoredAmmo;
106 
107  m_IgnoredAmmo.Insert(ammo, m_LastRegisteredIgnoredAmmo);
108 
109  return m_LastRegisteredIgnoredAmmo;
110  }
111 
112  static bool UnregisterIgnoredAmmo(string ammo)
113  {
114  if (m_IgnoredAmmo)
115  {
116  m_IgnoredAmmo.Remove(ammo);
117  return !m_IgnoredAmmo.Contains(ammo);
118  }
119 
120  return false;
121  }
122 
123  static typename GetImpactEffect(string surface, string ammoType)
124  {
125  string key = string.Format("%1_%2", surface, ammoType);
126 
127  typename eff_type = m_ImpactEffect[key];
128 
129  if (eff_type)
130  return eff_type;
131  else
132  return m_ImpactEffect[surface];
133  }
134 
135  static void EvaluateImpactEffectEx(ImpactEffectsData pData)
136  {
137  EvaluateImpactEffect(pData.m_DirectHit, pData.m_ComponentIndex, pData.m_Surface, pData.m_Position, pData.m_ImpactType, pData.m_SurfaceNormal, pData.m_ExitPosition, pData.m_InSpeed, pData.m_OutSpeed, pData.m_IsDeflected, pData.m_AmmoType, pData.m_IsWater);
138  }
139 
140  static void EvaluateImpactEffect(Object directHit, int componentIndex, string surface, vector pos, int impact_type, vector surfNormal, vector exitPos, vector inSpeed, vector outSpeed, bool deflected, string ammoType, bool isWater)
141  {
142  // No impact effects wanted for this ammo
143  if (m_IgnoredAmmo.Contains(ammoType))
144  return;
145 
146  if (impact_type == ImpactTypes.UNKNOWN)
147  impact_type = ImpactTypes.STOP;
148 
149  if (deflected)
150  impact_type = ImpactTypes.RICOCHET;
151  else if (outSpeed)
152  impact_type = ImpactTypes.PENETRATE;
153 
154  if (isWater)
155  surface = "Hit_Water";
156 
157  EffBulletImpactBase eff = EffBulletImpactBase.Cast(GetImpactEffect(surface, ammoType).Spawn());
158 
159  if ( !eff && surface == "" ) // handle undefined surface
160  {
161  eff = EffBulletImpactBase.Cast( surface.ToType().Spawn() );
162 
163  if (eff)
164  {
165  RegisterSurface(surface);
166  ErrorEx(string.Format("Unregistered surface for bullet impact effect (%1). Register this surface in ImpactMaterials (Script) for better performance.", surface), ErrorExSeverity.WARNING);
167  }
168  else
169  {
170  if (directHit)
171  {
172  string object_type = directHit.GetType();
173 
174  if ( object_type == "" )
175  object_type = "OBJECT_WITHOUT_CONFIG_CLASS";
176 
177  ErrorEx(string.Format("Object '%1' with model file: %2 has undefined 'Hit_...' material! Cannot play impact effect.", object_type, directHit.GetShapeName()));
178  eff = EffBulletImpactBase.Cast(GetImpactEffect("Hit_ErrorNoMaterial", ammoType).Spawn());
179  }
180  }
181  }
182 
183  if ( !eff && surface != "" )
184  {
185  ErrorEx(string.Format("Unregistered surface impact material <%1>! Register this surface in ImpactMaterials (Script).", surface));
186  eff = EffBulletImpactBase.Cast(GetImpactEffect("Hit_Undefined", ammoType).Spawn());
187  }
188 
189  if (eff)
190  {
191  eff.EvaluateEffect(directHit, componentIndex, pos, impact_type, surfNormal, exitPos, inSpeed, outSpeed, ammoType);
192  eff.SetAutodestroy(true);
193  SEffectManager.PlayInWorld(eff, pos);
194  }
195  }
196 }
STOP
@ STOP
Definition: enwidgets.c:508
m_ExitPosition
vector m_ExitPosition
Definition: impacteffects.c:23
m_Position
vector m_Position
Definition: impacteffects.c:21
EffBulletImpactBase
Definition: bulletimpactbase.c:1
UNKNOWN
@ UNKNOWN
24 - Any other error. Can be returned from any call.
Definition: bioserrormodule.c:56
ErrorEx
enum ShapeType ErrorEx
ImpactMaterials
Definition: impacteffects.c:28
Spawn
void Spawn()
spawn damage trigger
Definition: areadamagemanager.c:70
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
ErrorExSeverity
ErrorExSeverity
Definition: endebug.c:61
Object
Definition: objecttyped.c:1
m_SurfaceNormal
vector m_SurfaceNormal
Definition: impacteffects.c:22
m_IsWater
bool m_IsWater
Definition: impacteffects.c:16
MELEE
@ MELEE
Definition: impacteffects.c:7
m_Surface
string m_Surface
Definition: impacteffects.c:17
m_AmmoType
string m_AmmoType
Definition: impacteffects.c:18
m_OutSpeed
vector m_OutSpeed
Definition: impacteffects.c:20
ImpactTypes
ImpactTypes
Definition: impacteffects.c:1
m_ComponentIndex
int m_ComponentIndex
Definition: impacteffects.c:14
m_InSpeed
vector m_InSpeed
Definition: impacteffects.c:19
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
m_ImpactType
int m_ImpactType
Definition: impacteffects.c:13
m_IsDeflected
bool m_IsDeflected
Definition: impacteffects.c:15
m_DirectHit
enum ImpactTypes m_DirectHit