Dayz Explorer 1.29.162510
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 DESERT_SAND = RegisterSurface("Hit_Desert_Sand");
45 static int TEXTILE = RegisterSurface("Hit_Textile");
46 static int CONCRETE = RegisterSurface("Hit_Concrete");
47 static int GRAVEL = RegisterSurface("Hit_Gravel");
48 static int DIRT = RegisterSurface("Hit_Dirt");
49 static int FOLIAGE = RegisterSurface("Hit_Foliage");
50 static int FOLIAGE_GREEN = RegisterSurface("Hit_Foliage_Green");
51 static int FOLIAGE_CONIFER = RegisterSurface("Hit_Foliage_Conifer");
52 static int GRASS = RegisterSurface("Hit_Grass");
53 static int WOOD = RegisterSurface("Hit_Wood");
54 static int METAL = RegisterSurface("Hit_Metal");
55 static int GLASS = RegisterSurface("Hit_Glass");
56 static int GLASS_THIN = RegisterSurface("Hit_Glass_Thin");
57 static int WATER = RegisterSurface("Hit_Water");
58 static int RUBBER = RegisterSurface("Hit_Rubber");
59 static int PLASTER = RegisterSurface("Hit_Plaster");
60 static int ICE = RegisterSurface("Hit_Ice");
61 static int SNOW = RegisterSurface("Hit_Snow");
62 static int MEATBONES = RegisterSurface("Hit_MeatBones");
63 static int MEATBONES_SHOVEL = RegisterSurface("Hit_MeatBones_MeleeShovel");
64 static int MEATBONES_PIPEWRENCH = RegisterSurface("Hit_MeatBones_MeleePipeWrench");
65 static int MEATBONES_WRENCH = RegisterSurface("Hit_MeatBones_MeleeWrench");
66 static int MEATBONES_FIST = RegisterSurface("Hit_MeatBones_MeleeFist");
67 static int UNDEFINED = RegisterSurface("Hit_Undefined");
68 static int ERROR_NO_MATERIAL = RegisterSurface("Hit_ErrorNoMaterial");
70
76 static int FIST = RegisterIgnoredAmmo("MeleeFist");
77 static int FIST_HEAVY = RegisterIgnoredAmmo("MeleeFist_Heavy");
78 static int SOFT = RegisterIgnoredAmmo("MeleeSoft");
79 static int SOFT_HEAVY = RegisterIgnoredAmmo("MeleeSoft_Heavy");
80 static int DUMMY = RegisterIgnoredAmmo("Dummy_Light");
81 static int DUMMY_HEAVY = RegisterIgnoredAmmo("Dummy_Heavy");
83
84 static int RegisterSurface(string surface)
85 {
86 if (!m_ImpactEffect)
87 m_ImpactEffect = new map<string, typename>;
88
89 m_ImpactEffect.Insert(surface, surface.ToType());
90
91 return ++m_LastRegisteredMaterial;
92 }
93
94 static bool UnregisterSurface(string surface)
95 {
96 if (m_ImpactEffect)
97 {
98 m_ImpactEffect.Remove(surface);
99 return !m_ImpactEffect.Contains(surface);
100 }
101
102 return false;
103 }
104
105 static int RegisterIgnoredAmmo(string ammo)
106 {
107 if (!m_IgnoredAmmo)
108 m_IgnoredAmmo = new map<string, int>;
109
110 ++m_LastRegisteredIgnoredAmmo;
111
112 m_IgnoredAmmo.Insert(ammo, m_LastRegisteredIgnoredAmmo);
113
114 return m_LastRegisteredIgnoredAmmo;
115 }
116
117 static bool UnregisterIgnoredAmmo(string ammo)
118 {
119 if (m_IgnoredAmmo)
120 {
121 m_IgnoredAmmo.Remove(ammo);
122 return !m_IgnoredAmmo.Contains(ammo);
123 }
124
125 return false;
126 }
127
128 static typename GetImpactEffect(string surface, string ammoType)
129 {
130 string key = string.Format("%1_%2", surface, ammoType);
131
132 typename eff_type = m_ImpactEffect[key];
133
134 if (eff_type)
135 return eff_type;
136 else
137 return m_ImpactEffect[surface];
138 }
139
140 static void EvaluateImpactEffectEx(ImpactEffectsData pData)
141 {
142 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);
143 }
144
145 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)
146 {
147 // No impact effects wanted for this ammo
148 if (m_IgnoredAmmo.Contains(ammoType))
149 return;
150
151 if (impact_type == ImpactTypes.UNKNOWN)
152 impact_type = ImpactTypes.STOP;
153
154 if (deflected)
155 impact_type = ImpactTypes.RICOCHET;
156 else if (outSpeed)
157 impact_type = ImpactTypes.PENETRATE;
158
159 if (isWater)
160 surface = "Hit_Water";
161
162 EffBulletImpactBase eff = EffBulletImpactBase.Cast(GetImpactEffect(surface, ammoType).Spawn());
163
164 if ( !eff && surface == "" ) // handle undefined surface
165 {
166 eff = EffBulletImpactBase.Cast( surface.ToType().Spawn() );
167
168 if (eff)
169 {
170 RegisterSurface(surface);
171 ErrorEx(string.Format("Unregistered surface for bullet impact effect (%1). Register this surface in ImpactMaterials (Script) for better performance.", surface), ErrorExSeverity.WARNING);
172 }
173 else
174 {
175 if (directHit)
176 {
177 string object_type = directHit.GetType();
178
179 if ( object_type == "" )
180 object_type = "OBJECT_WITHOUT_CONFIG_CLASS";
181
182 ErrorEx(string.Format("Object '%1' with model file: %2 has undefined 'Hit_...' material! Cannot play impact effect.", object_type, directHit.GetShapeName()));
183 eff = EffBulletImpactBase.Cast(GetImpactEffect("Hit_ErrorNoMaterial", ammoType).Spawn());
184 }
185 }
186 }
187
188 if ( !eff && surface != "" )
189 {
190 ErrorEx(string.Format("Unregistered surface impact material <%1>! Register this surface in ImpactMaterials (Script).", surface));
191 eff = EffBulletImpactBase.Cast(GetImpactEffect("Hit_Undefined", ammoType).Spawn());
192 }
193
194 if (eff)
195 {
196 eff.EvaluateEffect(directHit, componentIndex, pos, impact_type, surfNormal, exitPos, inSpeed, outSpeed, ammoType);
197 eff.SetAutodestroy(true);
198 SEffectManager.PlayInWorld(eff, pos);
199 }
200 }
201}
void Spawn()
spawn damage trigger
@ UNKNOWN
24 - Any other error. Can be returned from any call.
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
@ PENETRATE