Merge branch 'medical-rewrite' of https://github.com/acemod/ACE3 into medical-rewrite

This commit is contained in:
commy2 2016-09-18 15:17:01 +02:00
commit 031bb1ec91
12 changed files with 11 additions and 489 deletions

View File

@ -1,143 +0,0 @@
/*
* Author: KoffeinFlummi, Glowbal, commy2
* Main HandleDamage EH function.
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
* 1: Name Of Hit Selection <STRING>
* 2: Amount Of Damage <NUMBER>
* 3: Shooter <OBJECT>
* 4: Projectile <OBJECT/STRING>
* 5: HitPointIndex (-1 for structural) <NUMBER>
* 6: Shooter <OBJECT>
*
* Return Value:
* Damage To Be Inflicted <NUMBER>
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_selection", "_damage", "_shooter", "_projectile", "_hitPointIndex"];
TRACE_5("ACE_DEBUG: HandleDamage Called",_unit, _selection, _damage, _shooter, _projectile);
// bug, apparently can fire for remote units in special cases
if !(local _unit) exitWith {
TRACE_2("ACE_DEBUG: HandleDamage on remote unit!",_unit, isServer);
nil
};
// bug, assumed fixed, @todo excessive testing, if nothing happens remove
if (_projectile isEqualType objNull) then {
_projectile = typeOf _projectile;
_this set [4, _projectile];
};
TRACE_3("ACE_DEBUG: HandleDamage",_selection,_damage,_unit);
// If damage is in dummy hitpoints, "hands" and "legs", don't change anything
if (_selection == "hands") exitWith {_unit getHit "hands"};
if (_selection == "legs") exitWith {_unit getHit "legs"};
if (_selection == "arms") exitWith {_unit getHit "arms"};
// Deal with the new hitpoint and selection names introduced with Arma v1.50 and later.
// This will convert new selection names into selection names that the medical system understands
// TODO This should be cleaned up when we revisit the medical system at a later stage
// and instead we should deal with the new hitpoints directly
_selection = [_unit, _selection, _hitPointIndex] call FUNC(translateSelections);
_this set [1, _selection]; // ensure that the parameters are set correctly
// If the damage is being weird, we just tell it to fuck off. Ignore: "hands", "legs", "arms"
if (_selection != "" && {!(_selection in GVAR(SELECTIONS))}) exitWith {0};
// Exit if we disable damage temporarily
if !(_unit getVariable [QGVAR(allowDamage), true]) exitWith {
TRACE_3("ACE_DEBUG: HandleDamage damage disabled.",_selection,damage _unit,_unit);
if (_selection == "") then {
damage _unit
} else {
_unit getHit _selection
};
};
// Get return damage
private _damageReturn = _damage;
private _newDamage = _this call FUNC(handleDamage_caching);
// handleDamage_caching may have modified the projectile string
private _typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
TRACE_3("ACE_DEBUG: HandleDamage caching new damage",_selection,_newDamage,_unit);
private _typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
private _minLethalDamage = if (_typeIndex >= 0) then {
GVAR(minLethalDamages) select _typeIndex
} else {
0.01
};
if (!isNull _shooter) then {
_unit setvariable [QGVAR(lastDamageSource), _shooter, false];
};
private _vehicle = vehicle _unit;
private _effectiveSelectionName = _selection;
if ((_vehicle != _unit) && {!(_vehicle isKindOf "StaticWeapon")} && {_shooter in [objNull, driver _vehicle, _vehicle]} && {_projectile == ""} && {_selection == ""}) then {
if (GVAR(enableVehicleCrashes)) then {
_effectiveSelectionName = _this select 1; //pull random selection from HDC
};
};
if ((_minLethalDamage <= _newDamage) && {[_unit, [_effectiveSelectionName] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
_damageReturn = 0.9;
};
if ([_unit, false, true] call FUNC(setDead)) then {
_damageReturn = 1;
} else {
_damageReturn = _damageReturn min 0.89;
};
} else {
_damageReturn = _damageReturn min 0.89;
};
// Start the loop that tracks the unit vitals
[_unit] call FUNC(addVitalLoop);
if (_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)]) exitWith {
private _delayedUnconsicous = false;
if (_vehicle != _unit and {damage _vehicle >= 1}) then {
[_unit] call EFUNC(common,unloadPerson);
_delayedUnconsicous = true;
};
if (_damageReturn >= 0.9 && {_selection in ["", "head", "body"]}) exitWith {
if (_unit getVariable ["ACE_isUnconscious", false]) exitwith {
[_unit, false, true] call FUNC(setDead);
0.89;
};
if (_delayedUnconsicous) then {
[{
[_this select 0, true] call FUNC(setUnconscious);
}, [_unit], 0.7] call CBA_fnc_waitAndExecute;
} else {
[{
[_this select 0, true] call FUNC(setUnconscious);
}, [_unit]] call CBA_fnc_execNextFrame;
};
0.89;
};
_damageReturn min 0.89;
};
if (((_unit getVariable [QGVAR(enableRevive), GVAR(enableRevive)]) > 0) && {_damageReturn >= 0.9} && {_selection in ["", "head", "body"]}) exitWith {
if (vehicle _unit != _unit and {damage (vehicle _unit) >= 1}) then {
[_unit] call EFUNC(common,unloadPerson);
};
[_unit, false, true] call FUNC(setDead);
0.89;
};
TRACE_3("ACE_DEBUG: HandleDamage damage return",_selection,_damageReturn,_unit);
_damageReturn

View File

@ -1,71 +0,0 @@
/*
* Author: Glowbal
* Advanced HandleDamage EH function.
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
* 1: Name Of Hit Selection <STRING>
* 2: Amount Of Damage <NUMBER>
* 3: Shooter <OBJECT>
* 4: Projectile <STRING>
* 5: Hit part index of the hit point <NUMBER>
* 6: Shooter? <OBJECT>
* 7: Current damage to be returned <NUMBER>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfProjectile", "_hitPointNumber", "", "_newDamage"];
// For burning damage we will get a ton of very small hits of damage; they are too small to create any wounds
// Save them up in a variable and run when it is over a noticable amount
if ((_typeOfProjectile == "") && {_newDamage < 0.15} && {
_newDamage = _newDamage + (_unit getVariable [QGVAR(trivialDamage), 0]);
if (_newDamage > 0.15) then {
// if the new sum is large enough, reset variable and continue with it added in
_unit setVariable [QGVAR(trivialDamage), 0];
false
} else {
// otherwise just save the new sum into the variable and exit
_unit setVariable [QGVAR(trivialDamage), _newDamage];
true // exit
};
}) exitWith {};
private _part = [_selectionName] call FUNC(selectionNameToNumber);
if (_part < 0) exitWith {};
private _hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"];
// Sorting out the damage
private _damageBodyParts = _unit getVariable [QGVAR(bodyPartStatus), [0,0,0,0,0,0]];
_damageBodyParts set [_part, (_damageBodyParts select _part) + _newDamage];
_unit setVariable [QGVAR(bodyPartStatus), _damageBodyParts, true];
private _typeOfDamage = [_typeOfProjectile] call FUNC(getTypeOfDamage);
[_unit, _selectionName, _newDamage, _typeOfProjectile, _typeOfDamage] call FUNC(handleDamage_assignWounds);
// TODO Disabled until implemented fully
//if (GVAR(enableAirway)) then {
// [_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_airway);
//};
//if (GVAR(enableFractures)) then {
// [_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_fractures);
//};
//if (GVAR(enableInternalBleeding)) then {
// [_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_internalInjuries);
//};
if (alive _unit && {!(_unit getVariable ["ACE_isUnconscious", false])}) then {
// If it reaches this, we can assume that the hit did not kill this unit, as this function is called 3 frames after the damage has been passed.
if ([_unit, _part, if (_part > 1) then {_newDamage * 1.3} else {_newDamage * 2}] call FUNC(determineIfFatal)) then {
[_unit] call FUNC(setUnconscious);
};
};

View File

@ -1,31 +0,0 @@
/*
* Author: Glowbal
* Handling of the airway injuries upon the handleDamage eventhandler.
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
* 1: Name Of Hit Selection <STRING>
* 2: Amount Of Damage <NUMBER>
* 3: Shooter or source of the damage <OBJECT>
* 4: Type of the damage done <STRING>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfDamage"];
private _bodyPartn = [_selectionName] call FUNC(selectionNameToNumber);
if (_bodyPartn > 1) exitWith {};
if (_amountOfDamage > 0.5) then {
if (random(1) >= 0.8) then {
if !(_unit getVariable[QGVAR(airwayCollapsed), false]) then {
_unit setVariable [QGVAR(airwayCollapsed), true, true];
};
};
};

View File

@ -1,151 +0,0 @@
/*
* Author: KoffeinFlummi, Glowbal
* Cache a handleDamage call to execute it 3 frames later
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
* 1: Name Of Hit Selection <STRING>
* 2: Amount Of Damage <NUMBER>
* 3: Shooter <OBJECT>
* 4: Projectile <STRING>
* 5: HitPointIndex (-1 for structural) <NUMBER>
*
* Return Value:
* <nil>
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_selectionName", "_damage", "_source", "_projectile", "_hitPointIndex"];
private _hitSelections = GVAR(SELECTIONS);
// Calculate change in damage - use getHitIndex because selection is translated (hitdiaphragm->body)
private _newDamage = _damage - (damage _unit);
if (_hitPointIndex >= 0) then {_newDamage = _damage - (_unit getHitIndex _hitPointIndex)};
TRACE_7("ACE_DEBUG: HandleDamage_Caching Called",_unit, _selectionName, _damage, _source, _projectile,_hitPointIndex,_newDamage);
// Check for vehicle crash
private _vehicle = vehicle _unit;
if ((_vehicle != _unit) && {!(_vehicle isKindOf "StaticWeapon")} && {_source in [objNull, driver _vehicle, _vehicle]} && {_projectile == ""} && {_selectionName == ""}) then {
if (GVAR(enableVehicleCrashes)) then {
_selectionName = selectRandom _hitSelections;
_projectile = "vehiclecrash";
_this set [1, _selectionName];
_this set [4, _projectile];
};
};
// Handle falling damage
private _impactVelocity = (velocity _unit) select 2;
if (_impactVelocity < -5 && {_vehicle == _unit}) then {
TRACE_1("Starting isFalling", time);
_unit setVariable [QGVAR(isFalling), true];
_unit setVariable [QGVAR(impactVelocity), _impactVelocity];
} else {
if ((_unit getVariable [QGVAR(isFalling), false]) && {diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2}) then {
TRACE_1("Ending isFalling", time);
_unit setVariable [QGVAR(isFalling), false];
};
};
if (_unit getVariable [QGVAR(isFalling), false]) then {
if !(_selectionName in ["", "leg_l", "leg_r"]) then {
if (_selectionName == "body") then {
_newDamage = _newDamage * abs(_unit getVariable [QGVAR(impactVelocity), _impactVelocity]) / 50;
} else {
_newDamage = _newDamage * 0.5;
};
if (_newDamage < 0.075) then {_newDamage = 0;}; //Filter minor falling damage to non-leg hitpoints
} else {
if (_selectionName == "") then {
_selectionName = selectRandom ["leg_l", "leg_r"];
_this set [1, _selectionName];
};
_newDamage = _newDamage * 0.7;
};
_projectile = "falling";
_this set [4, "falling"];
};
// Finished with the current frame, reset variables
// Note: sometimes handleDamage spans over 2 or even 3 frames.
if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) then {
_unit setVariable [QGVAR(frameNo_damageCaching), diag_frameno];
// handle the cached damages 3 frames later
[{
params ["_args", "_idPFH"];
_args params ["_unit", "_frameno"];
if (diag_frameno >= _frameno + 2) then {
_unit setDamage 0;
private _cache_params = _unit getVariable [QGVAR(cachedHandleDamageParams), []];
private _cache_damages = _unit getVariable QGVAR(cachedDamages);
{
(_x + [_cache_damages select _forEachIndex]) call FUNC(handleDamage_advanced);
} forEach _cache_params;
[_unit] call FUNC(handleDamage_advancedSetDamage);
[_idPFH] call CBA_fnc_removePerFrameHandler;
};
}, 0, [_unit, diag_frameno] ] call CBA_fnc_addPerFrameHandler;
_unit setVariable [QGVAR(cachedProjectiles), []];
_unit setVariable [QGVAR(cachedHitPoints), []];
_unit setVariable [QGVAR(cachedDamages), []];
_unit setVariable [QGVAR(cachedHandleDamageParams), []];
};
// Caching of the damage events
if (_selectionName != "") then {
private _cache_projectiles = _unit getVariable QGVAR(cachedProjectiles);
private _index = _cache_projectiles find _projectile;
// Check if the current projectile has already been handled once
if (_index >= 0 && {_projectile != "falling"}) exitWith {
private _cache_damages = _unit getVariable QGVAR(cachedDamages);
private _otherDamage = (_cache_damages select _index); // Find the previous damage this projectile has done
// Take the highest damage of the two
if (_newDamage > _otherDamage) then {
private _cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
private _cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
// Restore the damage before the previous damage was processed
private _hitPoint = _cache_hitpoints select _index;
private _restore = ((_unit getHitIndex _hitPoint) - _otherDamage) max 0;
_unit setHitIndex [_hitPoint, _restore];
_cache_hitpoints set [_index, _hitPointIndex];
_cache_damages set [_index, _newDamage];
_cache_params set[_index, _this];
_unit setVariable [QGVAR(cachedProjectiles), _cache_projectiles];
_unit setVariable [QGVAR(cachedHitPoints), _cache_hitpoints];
_unit setVariable [QGVAR(cachedDamages), _cache_damages];
_unit setVariable [QGVAR(cachedHandleDamageParams), _cache_params];
};
};
private _cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
private _cache_damages = _unit getVariable QGVAR(cachedDamages);
private _cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
// This is an unhandled projectile
_cache_projectiles pushBack _projectile;
_cache_hitpoints pushBack _hitPointIndex;
_cache_damages pushBack _newDamage;
_cache_params pushBack _this;
// Store the new cached values
_unit setVariable [QGVAR(cachedProjectiles), _cache_projectiles];
_unit setVariable [QGVAR(cachedHitPoints), _cache_hitpoints];
_unit setVariable [QGVAR(cachedDamages), _cache_damages];
_unit setVariable [QGVAR(cachedHandleDamageParams), _cache_params];
};
TRACE_8("ACE_DEBUG: HandleDamage_Caching",_unit, _newDamage, _cache_params, _cache_damages, _unit getVariable QGVAR(cachedProjectiles), _unit getVariable QGVAR(cachedHitPoints), _unit getVariable QGVAR(cachedDamages), _unit getVariable QGVAR(cachedHandleDamageParams));
_newDamage

View File

@ -1,23 +0,0 @@
/*
* Author: Glowbal
* Handling of the internal injuries upon the handleDamage eventhandler.
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
* 1: Name Of Hit Selection <STRING>
* 2: Amount Of Damage <NUMBER>
* 3: Shooter or source of the damage <OBJECT>
* 4: Type of the damage done <STRING>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfDamage"];
private _bodyPartn = [_selectionName] call FUNC(selectionNameToNumber);
// TODO implement internal injuries

View File

@ -1,65 +0,0 @@
/*
* Author: Glowbal
* Handling of the open wounds & injuries upon the handleDamage eventhandler.
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
* 1: Name Of Hit Selection <STRING>
* 2: Amount Of Damage <NUMBER>
* 3: Shooter or source of the damage <OBJECT>
* 4: Type of the damage done <STRING>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_selectionName", "_damage", "_typeOfProjectile", "_typeOfDamage"];
TRACE_6("ACE_DEBUG: HandleDamage Called",_unit, _selectionName, _damage, _shooter, _typeOfProjectile,_typeOfDamage);
if (_typeOfDamage == "") then {_typeOfDamage = "unknown";};
// Administration for open wounds and ids
private _openWounds = _unit getVariable[QGVAR(openWounds), []];
private _woundID = _unit getVariable[QGVAR(lastUniqueWoundID), 1];
private _extensionOutput = "ace_medical" callExtension format ["HandleDamageWounds,%1,%2,%3,%4", _selectionName, _damage, _typeOfDamage, _woundID];
private _painToAdd = 0;
private _woundsCreated = [];
call compile _extensionOutput;
{
_x params ["", "_toAddClassID", "_bodyPartNToAdd"];
_foundIndex = -1;
{
_x params ["", "_compareId", "_comparyBodyPartN"];
// Check if we have an id of the given class on the given bodypart already
if (_compareId == _toAddClassID && {_comparyBodyPartN == _bodyPartNToAdd}) exitWith {
_foundIndex = _forEachIndex;
};
} forEach _openWounds;
if (_foundIndex < 0) then {
// Since it is a new injury, we will have to add it to the open wounds array to store it
_openWounds pushBack _x;
} else {
// We already have one of these, so we are just going to increase the number that we have of it with a new one.
private _injury = _openWounds select _foundIndex;
_injury set [3, (_injury select 3) + 1];
};
} forEach _woundsCreated;
_unit setVariable [QGVAR(openWounds), _openWounds, true];
// Only update if new wounds have been created
if (count _woundsCreated > 0) then {
_unit setVariable [QGVAR(lastUniqueWoundID), _woundID, true];
};
private _painLevel = _unit getVariable [QGVAR(pain), 0];
_unit setVariable [QGVAR(pain), _painLevel + _painToAdd];
TRACE_6("ACE_DEBUG: HandleDamage_WoundsOLD",_unit, _painLevel, _painToAdd, _unit getVariable QGVAR(pain), _unit getVariable QGVAR(openWounds),_woundsCreated);

View File

@ -162,7 +162,10 @@ private _selectionSpecific = getNumber(_damageTypesConfig >> "selectionSpecific"
{
_x params ["_classID", "_selections", "_bloodLoss", "_pain", "_damage", "_causesArray", "_classDisplayName"];
_damage params ["_minDamage", "_maxDamage"];
private _className = GVAR(woundClassNames) select _forEachIndex;
if (_classDisplayName == "") then {_classDisplayName = _className; }; // fall back
private _allowedSelections = "";
{
_allowedSelections = _allowedSelections + _x;

View File

@ -4,7 +4,7 @@ ADDON = false;
#include "XEH_PREP.hpp"
[QGVAR(woundReceived), {
[QEGVAR(medical_engine,woundReceived), {
params ["_unit", "_woundedHitPoint", "_receivedDamage", "", "_ammo"];
private _selectionName = EGVAR(medical,SELECTIONS) param [EGVAR(medical,HITPOINTS) find _woundedHitPoint]; // @todo

View File

@ -19,6 +19,5 @@
private "_bodyPartn";
params ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfDamage"];
_bodyPartn = [_selectionName] call EFUNC(medical,selectionNameToNumber);
// _bodyPartn = [_selectionName] call EFUNC(medical,selectionNameToNumber);
// TODO implement internal injuries

View File

@ -20,6 +20,8 @@
params ["_unit", "_selectionName", "_damage", "_typeOfProjectile", "_typeOfDamage"];
TRACE_6("ACE_DEBUG: woundshandler",_unit, _selectionName, _damage, _shooter, _typeOfProjectile,_typeOfDamage);
if (_typeOfDamage == "") then {_typeOfDamage = "unknown";};
// Administration for open wounds and ids
private _openWounds = _unit getVariable[QEGVAR(medical,openWounds), []];
private _woundID = _unit getVariable[QEGVAR(medical,lastUniqueWoundID), 1];

View File

@ -25,6 +25,8 @@ TRACE_6("ACE_DEBUG: HandleDamage_WoundsOLD Called",_unit, _selectionName, _damag
_bodyPartn = [_selectionName] call EFUNC(medical,selectionNameToNumber);
if (_bodyPartn < 0) exitWith {};
if (_typeOfDamage == "") then {_typeOfDamage = "unknown";};
// Get the injury type information. Format: [typeDamage thresholds, selectionSpecific, woundTypes]
_injuryTypeInfo = missionNamespace getVariable [format[QGVAR(woundInjuryType_%1), _typeOfDamage],[[], false, []]];

View File

@ -29,9 +29,9 @@
#define NAMESPACE_NULL locationNull
#define PRELOAD_CLASS(class) \
LOG_1("Starting preload for ""%1""",class);\
diag_log format["Starting preload for ""%1""",class];\
[{\
1 preloadObject _this;\
}, {\
LOG_1("Preload done for ""%1""",_this);\
diag_log format ["Preload done for ""%1""",_this];\
}, class] call CBA_fnc_waitUntilAndExecute