Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
hit_meatbones.c
Go to the documentation of this file.
2 {
3  float m_ScalingByDistance;
4 
5  void Hit_MeatBones()
6  {
7  SetEnterParticle(ParticleList.IMPACT_MEATBONES_ENTER);
8  SetExitParticle(ParticleList.IMPACT_MEATBONES_EXIT);
9  SetRicochetParticle(ParticleList.IMPACT_MEATBONES_RICOCHET);
10 
11  m_AngledEnter = 10;
12  m_EnterSplashCoef = 0.002;
13  m_ExitSplashCoef = 0.006;
14  m_ScalingByDistance = 0.05;
15 
16  MIN_SCALING_PARAM = 0.2;
17  }
18 
19  override float CalculateStoppingForce(float in_speedf, float out_speedf, string ammoType, float weight)
20  {
21  if ( m_ImpactType == ImpactTypes.MELEE )
22  {
23  return 400;
24  }
25 
26  float projectile_weight_coef = weight / DEFAULT_PROJECTILE_WEIGHT;
27 
28  float stopping_force = in_speedf * projectile_weight_coef;
29 
30  if (m_DirectHit)
31  {
32  /*
33  // TO DO: Doesn't work because IsAlive() is false, even when it shouldn't be.
34  if ( m_DirectHit.IsMan() && m_componentIndex == SURVIVOR_HEAD && m_DirectHit.IsAlive() ) // Is the victim a survivor?
35  {
36  stopping_force = stopping_force * 2;
37  }
38  */
39 
40  /*
41  // TO DO: Doesn't work. Need to recognize a zombie somehow
42  else if ( m_DirectHit.IsInherited(DayZCreatureAIType) && m_componentIndex == INFECTED_HEAD ) // Is the victim a survivor that's hit in the head?
43  {
44  stopping_force = stopping_force * 2;
45  }*/
46  }
47 
48  return stopping_force;
49  }
50 
51  override void Event_OnStarted()
52  {
53  super.Event_OnStarted();
54 
55  if (m_ImpactType != ImpactTypes.MELEE)
56  {
57  vector in_speed = m_InSpeed * (-1); // Compiler demands to have this variable
58 
59  BloodSplatGround( GetPosition(), in_speed , 0.5 );
60 
61  if (m_OutSpeed.Length() > 0)
62  {
63  BloodSplatGround( m_ExitPos, m_OutSpeed, 0.8 );
64  }
65  }
66  }
67 
68  void BloodSplatGround( vector start_pos, vector speed_vector, float decay_coef )
69  {
70  vector pos = start_pos;
71  float power = m_StoppingForce;
72  float upscale = 1;
73  float rnd_offset = 0.5;
74  float rnd_offset_2 = rnd_offset * 0.5;
75 
76  while (power > 200)
77  {
78  pos = pos + ( speed_vector * 0.001 );
79  pos = pos + Vector( rnd_offset_2 - Math.RandomFloat( 0, rnd_offset ), 0, rnd_offset_2 - Math.RandomFloat( 0, rnd_offset ) );
80  pos[1] = GetGame().SurfaceY(pos[0], pos[2]);
81 
82  EffectParticle eff = new BloodSplatter();
83  eff.SetAutodestroy(true);
84  SEffectManager.PlayInWorld(eff, pos);
85 
86  Particle blood = eff.GetParticle(); // TO DO: Handle particle changes inside the Effect instance itself! Not here!
87 
88  vector ori = GetGame().GetSurfaceOrientation(pos[0], pos[2]);
89 
90  blood.SetOrientation(ori);
91  blood.ScaleParticleParam(EmitorParam.SIZE, upscale);
92 
93  Particle blood_chunks = ParticleManager.GetInstance().PlayInWorld(ParticleList.BLOOD_SURFACE_CHUNKS, pos);
94  blood_chunks.SetOrientation(ori);
95 
96  power = power * decay_coef;
97  upscale = upscale + Math.RandomFloat(0.1, 1);
98 
99  BloodSplatWall();
100  }
101  }
102 
103  void BloodSplatWall()
104  {
105  // Commented out due to age rating process :(
106 
107  /*
108  if (m_OutSpeed.Length() > 0)
109  {
110  Object projected_surface;
111  vector hit_pos;
112  vector hit_normal;
113  float hit_fraction;
114  DayZPhysics.RayCastBullet(m_ExitPos, m_ExitPos + m_OutSpeed, PhxInteractionLayers.BUILDING, m_Object, projected_surface, hit_pos, hit_normal, hit_fraction);
115 
116  hit_normal = hit_normal.VectorToAngles();
117  hit_normal[1] = hit_normal[1] + 90;
118 
119  EffectParticle eff = new BloodSplatter();
120  eff.SetAutodestroy(true);
121  SEffectManager.PlayInWorld(eff, hit_pos);
122  Particle blood = eff.GetParticle();
123  blood.SetOrientation(hit_normal);
124  }
125  */
126  }
127 
128  override void OnEnterCalculations( Particle p )
129  {
130  // Calculate particle's size based on bullet's speed
131  float velocity_min = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterSplashCoef);
132  float velocity_max = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterSplashCoef);
133  float size = MIN_SCALING_PARAM + ( m_StoppingForce * m_EnterSplashCoef);
134  float birth_rate = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterSplashCoef/2);
135 
136  if ( m_AmmoType == "Bullet_12GaugePellets" )
137  {
138  birth_rate *= 0.5;
139  velocity_min *= 2;
140  velocity_max *= 2;
141  }
142 
143  // Additional size increase by distance from camera
144  vector camera_pos = GetGame().GetCurrentCameraPosition();
145  float distance = vector.Distance(camera_pos, m_Pos);
146  float scaling_by_distance = (distance*1.2) * m_ScalingByDistance;
147 
148  // Now scale down the above size increase by player's zoom-in value
149  float current_FOV = Camera.GetCurrentFOV();
150  float config_FOV = GetDayZGame().GetUserFOVFromConfig();
151  float FOV_scale = current_FOV / config_FOV;
152  scaling_by_distance = scaling_by_distance * FOV_scale;
153 
154  if (scaling_by_distance > 5)
155  scaling_by_distance = 5;
156 
157  size = size + scaling_by_distance;
158  velocity_min = velocity_min + scaling_by_distance;
159  velocity_max = velocity_max + scaling_by_distance;
160 
161  if (velocity_min < MIN_SCALING_PARAM)
162  velocity_min = MIN_SCALING_PARAM;
163 
164  if (velocity_max < MIN_SCALING_PARAM * 2)
165  velocity_max = MIN_SCALING_PARAM * 2;
166 
167  if (size < MIN_SCALING_PARAM)
168  size = MIN_SCALING_PARAM;
169 
170  if (birth_rate < MIN_SCALING_PARAM)
171  birth_rate = MIN_SCALING_PARAM;
172 
173  p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
174  p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
175  p.ScaleParticleParam(EmitorParam.SIZE, size);
176  p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
177  }
178 
179  override void OnExitCalculations(Particle p, float outSpeedf)
180  {
181  float velocity_rnd = outSpeedf * m_ExitSplashCoef;
182  float birth_rate_rnd_def = outSpeedf * m_ExitSplashCoef;
183  float size = outSpeedf * m_ExitSplashCoef;
184 
185  if (velocity_rnd < MIN_SCALING_PARAM)
186  velocity_rnd = MIN_SCALING_PARAM;
187 
188  if (size < MIN_SCALING_PARAM)
189  size = MIN_SCALING_PARAM;
190 
191  if (size > 1)
192  size = 1;
193 
194  if (birth_rate_rnd_def < MIN_SCALING_PARAM)
195  birth_rate_rnd_def = MIN_SCALING_PARAM;
196 
197  p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_rnd);
198  p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate_rnd_def);
199  p.ScaleParticleParam(EmitorParam.SIZE, size);
200  }
201 }
GetGame
proto native CGame GetGame()
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
EffBulletImpactBase
Definition: bulletimpactbase.c:1
EmitorParam
EmitorParam
Definition: envisual.c:113
m_Pos
vector m_Pos
Definition: remoteplayerstatdebug.c:15
EffectParticle
Wrapper class for managing particles through SEffectManager.
Definition: effectparticle.c:4
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
Hit_MeatBones
Definition: hit_meatbones.c:1
m_AmmoType
string m_AmmoType
Definition: impacteffects.c:18
m_OutSpeed
vector m_OutSpeed
Definition: impacteffects.c:20
BloodSplatter
Definition: bloodsplatter.c:1
ImpactTypes
ImpactTypes
Definition: impacteffects.c:1
Camera
Definition: camera.c:69
Math
Definition: enmath.c:6
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
m_InSpeed
vector m_InSpeed
Definition: impacteffects.c:19
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
m_ImpactType
int m_ImpactType
Definition: impacteffects.c:13
m_DirectHit
enum ImpactTypes m_DirectHit