Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
impacteffects.c
Go to the documentation of this file.
9
10class ImpactEffectsData
11{
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 FOLIAGE_GREEN = RegisterSurface("Hit_Foliage_Green");
50 static int FOLIAGE_CONIFER = RegisterSurface("Hit_Foliage_Conifer");
51 static int GRASS = RegisterSurface("Hit_Grass");
52 static int WOOD = RegisterSurface("Hit_Wood");
53 static int METAL = RegisterSurface("Hit_Metal");
54 static int GLASS = RegisterSurface("Hit_Glass");
55 static int GLASS_THIN = RegisterSurface("Hit_Glass_Thin");
56 static int WATER = RegisterSurface("Hit_Water");
57 static int RUBBER = RegisterSurface("Hit_Rubber");
58 static int PLASTER = RegisterSurface("Hit_Plaster");
59 static int ICE = RegisterSurface("Hit_Ice");
60 static int SNOW = RegisterSurface("Hit_Snow");
61 static int MEATBONES = RegisterSurface("Hit_MeatBones");
62 static int MEATBONES_SHOVEL = RegisterSurface("Hit_MeatBones_MeleeShovel");
63 static int MEATBONES_PIPEWRENCH = RegisterSurface("Hit_MeatBones_MeleePipeWrench");
64 static int MEATBONES_WRENCH = RegisterSurface("Hit_MeatBones_MeleeWrench");
65 static int MEATBONES_FIST = RegisterSurface("Hit_MeatBones_MeleeFist");
66 static int UNDEFINED = RegisterSurface("Hit_Undefined");
67 static int ERROR_NO_MATERIAL = RegisterSurface("Hit_ErrorNoMaterial");
69
75 static int FIST = RegisterIgnoredAmmo("MeleeFist");
76 static int FIST_HEAVY = RegisterIgnoredAmmo("MeleeFist_Heavy");
77 static int SOFT = RegisterIgnoredAmmo("MeleeSoft");
78 static int SOFT_HEAVY = RegisterIgnoredAmmo("MeleeSoft_Heavy");
79 static int DUMMY = RegisterIgnoredAmmo("Dummy_Light");
80 static int DUMMY_HEAVY = RegisterIgnoredAmmo("Dummy_Heavy");
82
83 static int RegisterSurface(string surface)
84 {
85 if (!m_ImpactEffect)
86 m_ImpactEffect = new map<string, typename>;
87
88 m_ImpactEffect.Insert(surface, surface.ToType());
89
90 return ++m_LastRegisteredMaterial;
91 }
92
93 static bool UnregisterSurface(string surface)
94 {
95 if (m_ImpactEffect)
96 {
97 m_ImpactEffect.Remove(surface);
98 return !m_ImpactEffect.Contains(surface);
99 }
100
101 return false;
102 }
103
104 static int RegisterIgnoredAmmo(string ammo)
105 {
106 if (!m_IgnoredAmmo)
107 m_IgnoredAmmo = new map<string, int>;
108
109 ++m_LastRegisteredIgnoredAmmo;
110
111 m_IgnoredAmmo.Insert(ammo, m_LastRegisteredIgnoredAmmo);
112
113 return m_LastRegisteredIgnoredAmmo;
114 }
115
116 static bool UnregisterIgnoredAmmo(string ammo)
117 {
118 if (m_IgnoredAmmo)
119 {
120 m_IgnoredAmmo.Remove(ammo);
121 return !m_IgnoredAmmo.Contains(ammo);
122 }
123
124 return false;
125 }
126
127 static typename GetImpactEffect(string surface, string ammoType)
128 {
129 string key = string.Format("%1_%2", surface, ammoType);
130
131 typename eff_type = m_ImpactEffect[key];
132
133 if (eff_type)
134 return eff_type;
135 else
136 return m_ImpactEffect[surface];
137 }
138
139 static void EvaluateImpactEffectEx(ImpactEffectsData pData)
140 {
141 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);
142 }
143
144 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)
145 {
146 // No impact effects wanted for this ammo
147 if (m_IgnoredAmmo.Contains(ammoType))
148 return;
149
150 if (impact_type == ImpactTypes.UNKNOWN)
151 impact_type = ImpactTypes.STOP;
152
153 if (deflected)
154 impact_type = ImpactTypes.RICOCHET;
155 else if (outSpeed)
156 impact_type = ImpactTypes.PENETRATE;
157
158 if (isWater)
159 surface = "Hit_Water";
160
161 EffBulletImpactBase eff = EffBulletImpactBase.Cast(GetImpactEffect(surface, ammoType).Spawn());
162
163 if ( !eff && surface == "" ) // handle undefined surface
164 {
165 eff = EffBulletImpactBase.Cast( surface.ToType().Spawn() );
166
167 if (eff)
168 {
169 RegisterSurface(surface);
170 ErrorEx(string.Format("Unregistered surface for bullet impact effect (%1). Register this surface in ImpactMaterials (Script) for better performance.", surface), ErrorExSeverity.WARNING);
171 }
172 else
173 {
174 if (directHit)
175 {
176 string object_type = directHit.GetType();
177
178 if ( object_type == "" )
179 object_type = "OBJECT_WITHOUT_CONFIG_CLASS";
180
181 ErrorEx(string.Format("Object '%1' with model file: %2 has undefined 'Hit_...' material! Cannot play impact effect.", object_type, directHit.GetShapeName()));
182 eff = EffBulletImpactBase.Cast(GetImpactEffect("Hit_ErrorNoMaterial", ammoType).Spawn());
183 }
184 }
185 }
186
187 if ( !eff && surface != "" )
188 {
189 ErrorEx(string.Format("Unregistered surface impact material <%1>! Register this surface in ImpactMaterials (Script).", surface));
190 eff = EffBulletImpactBase.Cast(GetImpactEffect("Hit_Undefined", ammoType).Spawn());
191 }
192
193 if (eff)
194 {
195 eff.EvaluateEffect(directHit, componentIndex, pos, impact_type, surfNormal, exitPos, inSpeed, outSpeed, ammoType);
196 eff.SetAutodestroy(true);
197 SEffectManager.PlayInWorld(eff, pos);
198 }
199 }
200}
void Spawn()
spawn damage trigger
Manager class for managing Effect (EffectParticle, EffectSound)
static int PlayInWorld(notnull Effect eff, vector pos)
Play an Effect.
vector m_Position
Cached world position.
Definition effect.c:43
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
int m_ImpactType
enum ImpactTypes m_DirectHit
vector m_InSpeed
bool m_IsDeflected
vector m_SurfaceNormal
bool m_IsWater
vector m_OutSpeed
string m_AmmoType
int m_ComponentIndex
vector m_ExitPosition
string m_Surface
ImpactTypes
@ RICOCHET
@ MELEE
@ STOP
@ UNKNOWN
@ PENETRATE