componentanimalbleeding.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //-----------------------------
  2. // ANIMAL BLEEDING
  3. //-----------------------------
  4. /*
  5. Animal bleeding is handled by this component.
  6. */
  7. class ComponentAnimalBleeding : Component
  8. {
  9. // Member variables
  10. protected ref Timer m_BleedTimer;
  11. protected const float BASE_BLEED_RATE = 250;
  12. protected const float PASS_OUT_AMOUT = 500;
  13. // Constructor
  14. void ComponentAnimalBleeding()
  15. {
  16. }
  17. void InflictWoundDamage( TotalDamageResult damage_result, string zone_name, string ammo )
  18. {
  19. if ( ammo == "MeleeWolf")
  20. {
  21. m_ThisEntityAI.SetHealth( "", "", 0 );
  22. }
  23. if ( !zone_name )
  24. return;
  25. float health_damage_inflicted = damage_result.GetDamage( zone_name, "Health");
  26. //float blood_damage_inflicted = damage_result.GetDamage( zone_name, "Blood");
  27. float wound_healt_damage = health_damage_inflicted;
  28. //float wound_blood_damage = health_damage_inflicted;
  29. m_ThisEntityAI.DecreaseHealth( "", "Health", wound_healt_damage );
  30. //m_ThisEntityAI.DecreaseHealth( "", "Blood", wound_blood_damage );
  31. if ( zone_name != "" )
  32. {
  33. m_ThisEntityAI.DecreaseHealth( zone_name, "Health", wound_healt_damage );
  34. //m_ThisEntityAI.DecreaseHealth( zone_name, "Blood", wound_blood_damage );
  35. }
  36. //Print("Zone hit: " + zone_name );
  37. //Print("damage_result Health: " + damage_result.GetDamage( zone_name, "Health" ) );
  38. //Print("damage_result Blood: " + damage_result.GetDamage( zone_name, "Blood" ) );
  39. }
  40. void CreateWound( TotalDamageResult damage_result, string zone_name, string ammo )
  41. {
  42. //Print( "GetHealth Health before creating wound@: " + zone_name + " " + m_ThisEntityAI.GetHealth( zone_name, "Health" ));
  43. InflictWoundDamage( damage_result, zone_name, ammo );
  44. //Print( "GetHealth Health after creating wood@: " + zone_name + " " + m_ThisEntityAI.GetHealth( zone_name, "Health" ));
  45. float can_bleed = false; //= GetGame().ConfigGetFloat( "CfgVehicles " + m_ThisEntityAI.GetType() + " DamageSystem " + "DamageZones " + zone_name + " canBleed" );
  46. //Print("can_bleed: " + can_bleed );
  47. float bleed_treshold = 0; //= GetGame().ConfigGetFloat( "CfgAmmo " + ammo + " DamageApplied " + "bleedThreshold" );
  48. //Print("bleed_treshold: " + bleed_treshold );
  49. float chance = -1; //Math.RandomFloat01();
  50. //Print("chance: " + chance );
  51. //Print( "GetHealth Health @: " + m_ThisEntityAI.GetHealth( zone_name, "Health" ));
  52. //Print( "GetHealth Blood @: " + m_ThisEntityAI.GetHealth( zone_name, "Blood" ));
  53. //Print( "GetHealth Shock @: " + m_ThisEntityAI.GetHealth( zone_name, "Shock" ));
  54. if ( can_bleed && chance <= bleed_treshold )
  55. {
  56. m_BleedTimer = new Timer();
  57. float wound_intensity = GetWoundIntensity( bleed_treshold );
  58. //Print("wound_intensity: " + wound_intensity);
  59. m_BleedTimer.Run( 1, this, "Bleed", new Param1<float>( wound_intensity ), true );
  60. }
  61. /*
  62. else
  63. {
  64. Print("Not bleeding");
  65. }
  66. */
  67. }
  68. void Bleed( float wound_intensity )
  69. {
  70. if ( m_ThisEntityAI.IsAlive() )
  71. {
  72. float bleeding_intensity = BASE_BLEED_RATE * wound_intensity;
  73. //Print("bleeding_intensity: " + bleeding_intensity);
  74. float global_blood_lvl = m_ThisEntityAI.GetHealth( "", "Blood" );
  75. m_ThisEntityAI.DecreaseHealth( "", "Blood", bleeding_intensity );
  76. if ( global_blood_lvl < PASS_OUT_AMOUT )
  77. {
  78. m_ThisEntityAI.SetHealth( "", "", 0 );
  79. //Print("global_blood_lvl < PASS_OUT_AMOUT => Zabijam zviera.");
  80. }
  81. //Print( "GetHealth Global Health: " + m_ThisEntityAI.GetHealth( "", "Health" ));
  82. //Print( "GetHealth Global Blood: " + m_ThisEntityAI.GetHealth( "", "Blood" ));
  83. //Print( "GetHealth Global Shock: " + m_ThisEntityAI.GetHealth( "", "Shock" ));
  84. }
  85. else
  86. {
  87. m_BleedTimer.Stop();
  88. //Print("Vypinam timer.");
  89. }
  90. }
  91. float GetWoundIntensity( float bleed_treshold )
  92. {
  93. //higher the bleeding treshold => more intense bleeding
  94. return bleed_treshold * 2;
  95. }
  96. }