Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CFDG 5.07 KB | None | 0 0
  1. // #define DEBUG_MODE_FULL
  2. #include "script_component.hpp"
  3.  
  4. #define __unitcfg configFile >> "cfgVehicles" >> _unitType
  5. #define __ammocfg configFile >> "cfgAmmo" >> _ammo
  6.  
  7.  
  8. private ["_to", "_ammo", "_calls", "_firstCall", "_unit", "_allowDamage", "_isPlayer", "_sortedCalls", "_hitCall", "_part", "_partDamage", "_injurer", "_unitType", "_damage", "_armor", "_armorStruct", "_hit", "_typicalSpeed", "_configHit", "_velocity", "_direction", "_calibre", "_bloodLossConstant", "_mass", "_maxPenetraton", "_penetration", "_bloodLoss", "_ee", "_pd", "_ddam", "_bloss", "_isp"];
  9. //PARAMS_5(_unit,_part,_partdamage,_injurer,_ammo);
  10.  
  11. TRACE_1("hd2 start", "");
  12.  
  13. _unit = _this;
  14. _calls = (_unit getVariable "ace_w_hd");
  15. _firstCall = _calls select 0;
  16.  
  17. //
  18. _isPlayer = if (isPlayer _unit) then {true} else {false};
  19.  
  20. // if dead remove event handler
  21. if (!alive _unit) exitwith {
  22.     if (!isNil {_unit getVariable QUOTE(GVAR(hdeh))}) then {
  23.     _unit removeEventHandler ["handleDamage", _unit getVariable QUOTE(GVAR(hdeh))];
  24.     };
  25. };
  26.  
  27. // exit if damage is not allowed
  28. _allowDamage = _unit getVariable "ace_w_allow_dam";
  29. if (!isNil "_allowDamage") exitWith {false};
  30.  
  31. // initialise unit if not initialised
  32. _check = _unit getVariable "ace_w_head_hit";
  33. if (isNil "_check") then {_unit call FUNC(unitinit)};
  34.  
  35. _fsm = _unit getVariable "ace_w_stateHandler";
  36. if (isNil "_fsm") then {_fsm = 0};
  37. if (_fsm == 0) then {
  38.     _unit setVariable ["ace_w_fsm",1];
  39.     [_unit] spawn FUNC(statehandler);
  40. };
  41.        
  42. // create a new array sorted by damage
  43. _sortedCalls = [_calls, 2] call CBA_fnc_sortNestedArray;
  44.  
  45. // find which part was hit
  46. _hitCall = _sortedCalls select ((count _sortedCalls) -1);
  47. if ((_hitCall select 1) == "") then { // first call, not a part
  48.     _hitCall = _sortedCalls select ((count _sortedCalls) -2);
  49. };
  50.  
  51. //
  52. _part = _hitCall select 1;
  53. _partdamage = _hitCall select 2;
  54. _injurer = _hitCall select 3;
  55. _ammo = _hitCall select 4;
  56.  
  57. //
  58. _partId = -1;
  59. _partMaxDepth = 180;
  60. _partBloodLossMultiplier = 1;
  61. switch (_part) do {
  62.     case "head_hit": { // head
  63.         _partId = 0;
  64.         _partMaxDepth = 180;
  65.         _partBloodLossMultiplier = 2;
  66.     };
  67.     case "body": { // body
  68.         _partId = 1;
  69.         _partMaxDepth = 300;
  70.         _partBloodLossMultiplier = 1;
  71.     };
  72.     case "hands": { // hands
  73.         _partId = 2;
  74.         _partMaxDepth = 100;
  75.         _partBloodLossMultiplier = 1;
  76.     };
  77.     case "legs": { // leg
  78.         _partId = 3;
  79.         _partMaxDepth = 160;
  80.         _partBloodLossMultiplier = 1;
  81.     };
  82. };
  83.            
  84. _unitType = typeOf _unit;
  85.    
  86. // _damage - new damage received by unit (0..1)
  87. _damage = _firstCall select 2;
  88.  
  89. // Finding current 'hit' value of projectile. Empiric formula.
  90. _armor = getNumber (__unitcfg >> "armor");
  91. _armorStruct = getNumber (__unitcfg >> "armorstructural");
  92. _hit = 4.0235 * sqrt(_damage * _armor * _armorStruct);
  93.  
  94. // Calculating terminal velocity
  95. _typicalSpeed = getNumber (__ammocfg >> "typicalSpeed");
  96. _configHit = getNumber (__ammocfg >> "hit");
  97. _velocity = _typicalSpeed * _hit / _configHit;
  98.  
  99. TRACE_5("wounds velocity",_velocity,_armor,_armorStruct,_hit,_configHit);
  100.  
  101. // calculate blood loss
  102. _direction = [_unit, _injurer] call BIS_fnc_relativeDirTo;
  103. _calibre = getNumber(__ammocfg >> "caliber");
  104. _bloodLossCoefficient = 0.0000001;
  105. _mass    = getNumber (__ammocfg >> "ace_mass");
  106. _maxPenetraton = ((_velocity * _mass) / (_calibre^2)) * 5;
  107.  
  108. _penetration = _maxPenetraton min _partMaxDepth;
  109.  
  110. _bloodLoss = _penetration * 3.141592654 * _calibre * _bloodLossCoefficient;
  111.  
  112. // define vital areas
  113. _vitals = [
  114.     [ // head
  115.         [0.4, 2], // brain
  116.         [0.05, 2], // spine
  117.         [0.1, 1, 2] // artery
  118.     ],
  119.     [ // body
  120.         [0.05, 2], // spine
  121.         [0.02, 1, 10], // heart
  122.         [0.05, 1, 2] // artery
  123.     ],
  124.     [ // hands
  125.         [0.05, 1, 2] // artery
  126.     ],
  127.     [ // legs
  128.         [0.05, 1, 2] // artery
  129.     ]
  130. ];
  131.  
  132. // get vital areas for current part
  133. _partVitals = _vitals select _partId;
  134.  
  135. // loop through each vital, applying the effects if hit
  136. {
  137.     _vital = _x;
  138.     _chance = _vital select 0;
  139.     _chance = _chance ^ (1 / ((_calibre ^ 0.5) * 2.35));
  140.     _random = (random 1);
  141.     if (_random <= _chance) then {
  142.       _effectType = _vital select 1;
  143.         switch (_effectType) do {
  144.             TRACE_1("vital hit", _vital);
  145.             case 1: { // increased bleed
  146.                 _multiplier = _vital select 2;
  147.                 _bloodLoss = _bloodLoss * _multiplier;
  148.             };
  149.             case 2: { // fatal
  150.                 _unit setDamage 1;
  151.             };
  152.         };
  153.     };
  154. } foreach _partVitals;
  155.  
  156. // create wounds
  157. if (_penetration >= _maxDepth) then { // exit wound
  158.     _wounds = [
  159.         [_partId, _bloodLoss / 2],
  160.         [_partId, _bloodLoss]
  161.     ];
  162. } else {
  163.     _wounds = [
  164.         [_partId, _bloodLoss]
  165.     ];
  166. };
  167.  
  168. _painCoefficient =  0.000001;
  169. _shockCoefficient = 0.000001;
  170. _pain =  0.5 * _mass * (_velocity ^ 2) * _painCoefficient;
  171. _shock = 0.5 * _mass * (_velocity ^ 2) * _shockCoefficient;
  172.  
  173. TRACE_6("wounds blood loss", _calibre, _mass, _maxPenetraton, _penetration, _bloodLoss, _pain);
  174.  
  175. // set blood loss
  176. _unit setVariable ["ace_w_wounds", (_unit getVariable   "ace_w_wounds") + _wounds];
  177. [_unit, _bloodLoss, 0, 0] call FUNC(vchange);
  178. _unit setVariable ["ace_w_state",800]; // state 800 = bleeding signs, pain
  179.  
  180. // hit effects
  181. [_unit, _ammo] call FUNC(effect);
  182.  
  183. // return
  184. _return = 0;
  185. _return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement