2015-02-08 09:01:32 +00:00
|
|
|
/*
|
2016-09-27 15:29:49 +00:00
|
|
|
* Author: Glowbal, commy2
|
2015-02-08 09:01:32 +00:00
|
|
|
* Handling of the open wounds & injuries upon the handleDamage eventhandler.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit That Was Hit <OBJECT>
|
2016-10-07 02:21:01 +00:00
|
|
|
* 1: Name Of Body Part <STRING>
|
2015-02-08 09:01:32 +00:00
|
|
|
* 2: Amount Of Damage <NUMBER>
|
|
|
|
* 3: Shooter or source of the damage <OBJECT>
|
|
|
|
* 4: Type of the damage done <STRING>
|
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-22 14:25:10 +00:00
|
|
|
* None
|
2015-02-08 09:01:32 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-02-07 22:48:24 +00:00
|
|
|
#include "script_component.hpp"
|
2015-02-13 21:55:13 +00:00
|
|
|
|
2016-12-09 13:11:07 +00:00
|
|
|
#define MATH_E 2.71828182846
|
|
|
|
|
2016-09-27 15:29:49 +00:00
|
|
|
params ["_unit", "_bodyPart", "_damage", "_typeOfProjectile", "_typeOfDamage"];
|
|
|
|
TRACE_5("start",_unit,_bodyPart,_damage,_typeOfProjectile,_typeOfDamage);
|
2015-02-07 22:48:24 +00:00
|
|
|
|
2016-09-27 15:29:49 +00:00
|
|
|
if (_typeOfDamage isEqualTo "") then {
|
|
|
|
_typeOfDamage = "unknown";
|
|
|
|
};
|
2016-09-18 11:33:22 +00:00
|
|
|
|
2015-03-03 21:13:22 +00:00
|
|
|
// Administration for open wounds and ids
|
2016-09-27 15:29:49 +00:00
|
|
|
private _openWounds = _unit getVariable [QEGVAR(medical,openWounds), []];
|
|
|
|
private _woundID = _unit getVariable [QEGVAR(medical,lastUniqueWoundID), 1];
|
2015-02-13 21:55:13 +00:00
|
|
|
|
2016-09-27 15:29:49 +00:00
|
|
|
private _extensionOutput = "ace_medical" callExtension format ["HandleDamageWounds,%1,%2,%3,%4", _bodyPart, _damage, _typeOfDamage, _woundID];
|
|
|
|
TRACE_1("",_extensionOutput);
|
2015-05-16 21:21:03 +00:00
|
|
|
|
2016-09-27 15:29:49 +00:00
|
|
|
// these are default values and modified by _extensionOutput
|
2016-06-13 09:05:21 +00:00
|
|
|
private _painToAdd = 0;
|
|
|
|
private _woundsCreated = [];
|
2015-03-01 11:33:05 +00:00
|
|
|
|
2015-05-16 21:21:03 +00:00
|
|
|
call compile _extensionOutput;
|
2016-09-27 15:29:49 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
// todo: Make the pain and bleeding calculations part of the extension again
|
|
|
|
private _painLevel = 0;
|
2016-12-08 10:38:43 +00:00
|
|
|
private _bodyPartDamage = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]];
|
2015-05-16 21:21:03 +00:00
|
|
|
{
|
2016-12-05 20:34:20 +00:00
|
|
|
_x params ["", "_woundClassIDToAdd", "_bodyPartNToAdd", "", "_bleeding"];
|
|
|
|
|
2016-12-08 10:38:43 +00:00
|
|
|
_bodyPartDamage set [_bodyPartNToAdd, (_bodyPartDamage select _bodyPartNToAdd) + _damage];
|
|
|
|
|
2016-12-09 13:11:07 +00:00
|
|
|
// The higher the nastiness likelihood the higher the change to get a painful and bloody wound
|
|
|
|
private _nastinessLikelihood = linearConversion [0, 20, _damage, 0.5, 30, true];
|
|
|
|
private _bloodiness = 0.01 + 0.99 * MATH_E ^ (-(random 30) / _nastinessLikelihood);
|
|
|
|
private _painfullness = 0.05 + 0.95 * MATH_E ^ (-(random 30) / _nastinessLikelihood);
|
2016-12-08 10:38:43 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
_bleeding = _bleeding * _bloodiness;
|
2016-12-08 10:38:43 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
_x set [4, _bleeding];
|
|
|
|
_x set [5, _damage];
|
2016-12-08 10:38:43 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
private _pain = ((GVAR(woundsData) select _woundClassIDToAdd) select 3) * _painfullness;
|
|
|
|
_painLevel = _painLevel max _pain;
|
2016-12-08 10:38:43 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
#ifdef DEBUG_MODE_FULL
|
|
|
|
systemChat format["%1, damage: %2, peneration: %3, bleeding: %4, pain: %5", _bodyPart, round(_damage * 100) / 100, _damage > PENETRATION_THRESHOLD, round(_bleeding * 1000) / 1000, round(_pain * 1000) / 1000];
|
|
|
|
#endif
|
|
|
|
|
2016-12-08 10:38:43 +00:00
|
|
|
if (_bodyPartNToAdd == 0 && {_damage > LETHAL_HEAD_DAMAGE_THRESHOLD}) then {
|
2016-12-05 20:34:20 +00:00
|
|
|
[QEGVAR(medical,FatalInjury), _unit] call CBA_fnc_localEvent;
|
2015-02-07 22:48:24 +00:00
|
|
|
};
|
2016-12-05 20:34:20 +00:00
|
|
|
|
|
|
|
// todo `forceWalk` based on leg damage
|
|
|
|
private _causeLimping = (GVAR(woundsData) select _woundClassIDToAdd) select 7;
|
2016-12-08 10:38:43 +00:00
|
|
|
if (_causeLimping == 1 && {_damage > LIMPING_DAMAGE_THRESHOLD} && {_bodyPartNToAdd > 3}) then {
|
2016-12-05 20:34:20 +00:00
|
|
|
[_unit, true] call EFUNC(medical_engine,setLimping);
|
|
|
|
};
|
|
|
|
|
2016-12-08 11:59:30 +00:00
|
|
|
// if possible merge into existing wounds
|
|
|
|
private _createNewWound = true;
|
|
|
|
{
|
|
|
|
_x params ["", "_classID", "_bodyPartN", "_oldAmountOf", "_oldBleeding", "_oldDamage"];
|
2016-12-09 09:55:24 +00:00
|
|
|
if (_woundClassIDToAdd == _classID && {_bodyPartNToAdd == _bodyPartN && {(_damage < PENETRATION_THRESHOLD) isEqualTo (_oldDamage < PENETRATION_THRESHOLD)}}) then {
|
2016-12-08 11:59:30 +00:00
|
|
|
private _oldCategory = (floor ((0 max _oldBleeding min 0.1) / 0.05));
|
|
|
|
private _newCategory = (floor ((0 max _bleeding min 0.1) / 0.05));
|
|
|
|
if (_oldCategory == _newCategory) exitWith {
|
2016-12-09 09:55:24 +00:00
|
|
|
private _newAmountOf = _oldAmountOf + 1;
|
2016-12-08 11:59:30 +00:00
|
|
|
_x set [3, _newAmountOf];
|
2016-12-09 09:55:24 +00:00
|
|
|
private _newBleeding = (_oldAmountOf * _oldBleeding + _bleeding) / _newAmountOf;
|
|
|
|
_x set [4, _newBleeding];
|
|
|
|
private _newDamage = (_oldAmountOf * _oldDamage + _damage) / _newAmountOf;
|
|
|
|
_x set [5, _newDamage];
|
2016-12-08 11:59:30 +00:00
|
|
|
_createNewWound = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach _openWounds;
|
|
|
|
|
|
|
|
if (_createNewWound) then {
|
|
|
|
_openWounds pushBack _x;
|
|
|
|
};
|
2015-11-30 16:23:48 +00:00
|
|
|
} forEach _woundsCreated;
|
2015-02-21 20:10:57 +00:00
|
|
|
|
2016-06-30 15:33:29 +00:00
|
|
|
_unit setVariable [QEGVAR(medical,openWounds), _openWounds, true];
|
2016-12-08 10:38:43 +00:00
|
|
|
_unit setVariable [QEGVAR(medical,bodyPartDamage), _bodyPartDamage, true];
|
2015-02-28 19:48:34 +00:00
|
|
|
|
2016-10-07 02:21:01 +00:00
|
|
|
[_unit, _bodyPart] call EFUNC(medical_engine,updateBodyPartVisuals);
|
|
|
|
|
2015-03-03 21:13:22 +00:00
|
|
|
// Only update if new wounds have been created
|
|
|
|
if (count _woundsCreated > 0) then {
|
2016-06-30 15:33:29 +00:00
|
|
|
_unit setVariable [QEGVAR(medical,lastUniqueWoundID), _woundID, true];
|
2016-12-05 20:34:20 +00:00
|
|
|
[_unit] call EFUNC(medical,handleIncapacitation);
|
2015-03-03 21:13:22 +00:00
|
|
|
};
|
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
[_unit, _painLevel] call EFUNC(medical,adjustPainLevel);
|
|
|
|
[_unit, "hit", PAIN_TO_SCREAM(_painLevel)] call EFUNC(medical_engine,playInjuredSound);
|
2016-06-30 15:33:29 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
TRACE_5("exit",_unit,_painLevel,_unit getVariable QEGVAR(medical,pain),_unit getVariable QEGVAR(medical,openWounds),_woundsCreated);
|