hit_meatbones.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. class Hit_MeatBones : EffBulletImpactBase
  2. {
  3. float m_ScalingByDistance;
  4. void Hit_MeatBones()
  5. {
  6. SetEnterParticle(ParticleList.IMPACT_MEATBONES_ENTER);
  7. SetExitParticle(ParticleList.IMPACT_MEATBONES_EXIT);
  8. SetRicochetParticle(ParticleList.IMPACT_MEATBONES_RICOCHET);
  9. m_AngledEnter = 10;
  10. m_EnterSplashCoef = 0.002;
  11. m_ExitSplashCoef = 0.006;
  12. m_ScalingByDistance = 0.05;
  13. MIN_SCALING_PARAM = 0.2;
  14. }
  15. override float CalculateStoppingForce(float in_speedf, float out_speedf, string ammoType, float weight)
  16. {
  17. if ( m_ImpactType == ImpactTypes.MELEE )
  18. {
  19. return 400;
  20. }
  21. float projectile_weight_coef = weight / DEFAULT_PROJECTILE_WEIGHT;
  22. float stopping_force = in_speedf * projectile_weight_coef;
  23. if (m_DirectHit)
  24. {
  25. /*
  26. // TO DO: Doesn't work because IsAlive() is false, even when it shouldn't be.
  27. if ( m_DirectHit.IsMan() && m_componentIndex == SURVIVOR_HEAD && m_DirectHit.IsAlive() ) // Is the victim a survivor?
  28. {
  29. stopping_force = stopping_force * 2;
  30. }
  31. */
  32. /*
  33. // TO DO: Doesn't work. Need to recognize a zombie somehow
  34. else if ( m_DirectHit.IsInherited(DayZCreatureAIType) && m_componentIndex == INFECTED_HEAD ) // Is the victim a survivor that's hit in the head?
  35. {
  36. stopping_force = stopping_force * 2;
  37. }*/
  38. }
  39. return stopping_force;
  40. }
  41. override void Event_OnStarted()
  42. {
  43. super.Event_OnStarted();
  44. if (m_ImpactType != ImpactTypes.MELEE)
  45. {
  46. vector in_speed = m_InSpeed * (-1); // Compiler demands to have this variable
  47. BloodSplatGround( GetPosition(), in_speed , 0.5 );
  48. if (m_OutSpeed.Length() > 0)
  49. {
  50. BloodSplatGround( m_ExitPos, m_OutSpeed, 0.8 );
  51. }
  52. }
  53. }
  54. void BloodSplatGround( vector start_pos, vector speed_vector, float decay_coef )
  55. {
  56. vector pos = start_pos;
  57. float power = m_StoppingForce;
  58. float upscale = 1;
  59. float rnd_offset = 0.5;
  60. float rnd_offset_2 = rnd_offset * 0.5;
  61. while (power > 200)
  62. {
  63. pos = pos + ( speed_vector * 0.001 );
  64. pos = pos + Vector( rnd_offset_2 - Math.RandomFloat( 0, rnd_offset ), 0, rnd_offset_2 - Math.RandomFloat( 0, rnd_offset ) );
  65. pos[1] = GetGame().SurfaceY(pos[0], pos[2]);
  66. EffectParticle eff = new BloodSplatter();
  67. eff.SetAutodestroy(true);
  68. SEffectManager.PlayInWorld(eff, pos);
  69. Particle blood = eff.GetParticle(); // TO DO: Handle particle changes inside the Effect instance itself! Not here!
  70. vector ori = GetGame().GetSurfaceOrientation(pos[0], pos[2]);
  71. blood.SetOrientation(ori);
  72. blood.ScaleParticleParam(EmitorParam.SIZE, upscale);
  73. Particle blood_chunks = ParticleManager.GetInstance().PlayInWorld(ParticleList.BLOOD_SURFACE_CHUNKS, pos);
  74. blood_chunks.SetOrientation(ori);
  75. power = power * decay_coef;
  76. upscale = upscale + Math.RandomFloat(0.1, 1);
  77. BloodSplatWall();
  78. }
  79. }
  80. void BloodSplatWall()
  81. {
  82. // Commented out due to age rating process :(
  83. /*
  84. if (m_OutSpeed.Length() > 0)
  85. {
  86. Object projected_surface;
  87. vector hit_pos;
  88. vector hit_normal;
  89. float hit_fraction;
  90. DayZPhysics.RayCastBullet(m_ExitPos, m_ExitPos + m_OutSpeed, PhxInteractionLayers.BUILDING, m_Object, projected_surface, hit_pos, hit_normal, hit_fraction);
  91. hit_normal = hit_normal.VectorToAngles();
  92. hit_normal[1] = hit_normal[1] + 90;
  93. EffectParticle eff = new BloodSplatter();
  94. eff.SetAutodestroy(true);
  95. SEffectManager.PlayInWorld(eff, hit_pos);
  96. Particle blood = eff.GetParticle();
  97. blood.SetOrientation(hit_normal);
  98. }
  99. */
  100. }
  101. override void OnEnterCalculations( Particle p )
  102. {
  103. // Calculate particle's size based on bullet's speed
  104. float velocity_min = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterSplashCoef);
  105. float velocity_max = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterSplashCoef);
  106. float size = MIN_SCALING_PARAM + ( m_StoppingForce * m_EnterSplashCoef);
  107. float birth_rate = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterSplashCoef/2);
  108. if ( m_AmmoType == "Bullet_12GaugePellets" )
  109. {
  110. birth_rate *= 0.5;
  111. velocity_min *= 2;
  112. velocity_max *= 2;
  113. }
  114. // Additional size increase by distance from camera
  115. vector camera_pos = GetGame().GetCurrentCameraPosition();
  116. float distance = vector.Distance(camera_pos, m_Pos);
  117. float scaling_by_distance = (distance*1.2) * m_ScalingByDistance;
  118. // Now scale down the above size increase by player's zoom-in value
  119. float current_FOV = Camera.GetCurrentFOV();
  120. float config_FOV = GetDayZGame().GetUserFOVFromConfig();
  121. float FOV_scale = current_FOV / config_FOV;
  122. scaling_by_distance = scaling_by_distance * FOV_scale;
  123. if (scaling_by_distance > 5)
  124. scaling_by_distance = 5;
  125. size = size + scaling_by_distance;
  126. velocity_min = velocity_min + scaling_by_distance;
  127. velocity_max = velocity_max + scaling_by_distance;
  128. if (velocity_min < MIN_SCALING_PARAM)
  129. velocity_min = MIN_SCALING_PARAM;
  130. if (velocity_max < MIN_SCALING_PARAM * 2)
  131. velocity_max = MIN_SCALING_PARAM * 2;
  132. if (size < MIN_SCALING_PARAM)
  133. size = MIN_SCALING_PARAM;
  134. if (birth_rate < MIN_SCALING_PARAM)
  135. birth_rate = MIN_SCALING_PARAM;
  136. p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
  137. p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
  138. p.ScaleParticleParam(EmitorParam.SIZE, size);
  139. p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
  140. }
  141. override void OnExitCalculations(Particle p, float outSpeedf)
  142. {
  143. float velocity_rnd = outSpeedf * m_ExitSplashCoef;
  144. float birth_rate_rnd_def = outSpeedf * m_ExitSplashCoef;
  145. float size = outSpeedf * m_ExitSplashCoef;
  146. if (velocity_rnd < MIN_SCALING_PARAM)
  147. velocity_rnd = MIN_SCALING_PARAM;
  148. if (size < MIN_SCALING_PARAM)
  149. size = MIN_SCALING_PARAM;
  150. if (size > 1)
  151. size = 1;
  152. if (birth_rate_rnd_def < MIN_SCALING_PARAM)
  153. birth_rate_rnd_def = MIN_SCALING_PARAM;
  154. p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_rnd);
  155. p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate_rnd_def);
  156. p.ScaleParticleParam(EmitorParam.SIZE, size);
  157. }
  158. }