woundHandler(SQF), fixes, improvements, more consistent variable naming

This commit is contained in:
commy2 2016-09-27 17:29:49 +02:00
parent 72e2bc72c0
commit 5e35204811
7 changed files with 87 additions and 67 deletions

View File

@ -23,3 +23,7 @@ class CfgPatches {
#include "CfgFactionClasses.hpp" #include "CfgFactionClasses.hpp"
#include "CfgVehicles.hpp" #include "CfgVehicles.hpp"
#include "CfgWeapons.hpp" #include "CfgWeapons.hpp"
class ACE_Extensions {
extensions[] += {"ace_medical"};
};

View File

@ -5,4 +5,4 @@ PREP(internalInjuriesHandler);
PREP(parseConfigForInjuries); PREP(parseConfigForInjuries);
PREP(woundsHandler); PREP(woundsHandler);
PREP(woundsHandlerSqf); PREP(woundsHandlerSQF);

View File

@ -6,14 +6,20 @@ ADDON = false;
call FUNC(parseConfigForInjuries); call FUNC(parseConfigForInjuries);
// decide which woundsHandler to use by whether the extension is present or not
if ("ace_medical" callExtension "version" != "") then {
DFUNC(woundsHandlerActive) = FUNC(woundsHandler);
} else {
DFUNC(woundsHandlerActive) = FUNC(woundsHandlerSQF);
};
[QEGVAR(medical_engine,woundReceived), { [QEGVAR(medical_engine,woundReceived), {
params ["_unit", "_woundedHitPoint", "_receivedDamage", "", "_ammo"]; params ["_unit", "_woundedHitPoint", "_receivedDamage", "", "_ammo"];
// private _selectionName = EGVAR(medical,SELECTIONS) select (EGVAR(medical,HITPOINTS) find _woundedHitPoint); // @todo
private _typeOfDamage = _ammo call FUNC(getTypeOfDamage); private _typeOfDamage = _ammo call FUNC(getTypeOfDamage);
[_unit, _woundedHitPoint, _receivedDamage, _ammo, _typeOfDamage] call FUNC(woundsHandler); // TODO also support the sqf variant [_unit, _woundedHitPoint, _receivedDamage, _ammo, _typeOfDamage] call FUNC(woundsHandlerActive); // TODO also support the sqf variant
[_unit, EGVAR(medical,STATE_MACHINE)] call EFUNC(medical,addStateHandler); ///[_unit, EGVAR(medical,STATE_MACHINE)] call EFUNC(medical,addStateHandler); // @todo disable for now
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
ADDON = true; ADDON = true;

View File

@ -1,5 +1,5 @@
/* /*
* Author: Glowbal * Author: Glowbal, commy2
* Handling of the open wounds & injuries upon the handleDamage eventhandler. * Handling of the open wounds & injuries upon the handleDamage eventhandler.
* *
* Arguments: * Arguments:
@ -16,31 +16,37 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params ["_unit", "_selectionName", "_damage", "_typeOfProjectile", "_typeOfDamage"]; params ["_unit", "_bodyPart", "_damage", "_typeOfProjectile", "_typeOfDamage"];
TRACE_6("ACE_DEBUG: woundshandler",_unit, _selectionName, _damage, _shooter, _typeOfProjectile,_typeOfDamage); TRACE_5("start",_unit,_bodyPart,_damage,_typeOfProjectile,_typeOfDamage);
systemChat format["input: %1", _this]; ///// DELETE THIS AFTER EXTENSION HAS BEEN UPDATED
_bodyPart = EGVAR(medical,SELECTIONS) select (ALL_BODY_PARTS find _bodyPart);
/////
if (_typeOfDamage == "") then {_typeOfDamage = "unknown";}; if (_typeOfDamage isEqualTo "") then {
_typeOfDamage = "unknown";
};
// Administration for open wounds and ids // Administration for open wounds and ids
private _openWounds = _unit getVariable [QEGVAR(medical,openWounds), []]; private _openWounds = _unit getVariable [QEGVAR(medical,openWounds), []];
private _woundID = _unit getVariable [QEGVAR(medical,lastUniqueWoundID), 1]; private _woundID = _unit getVariable [QEGVAR(medical,lastUniqueWoundID), 1];
private _extensionOutput = "ace_medical" callExtension format ["HandleDamageWounds,%1,%2,%3,%4", _selectionName, _damage, _typeOfDamage, _woundID]; private _extensionOutput = "ace_medical" callExtension format ["HandleDamageWounds,%1,%2,%3,%4", _bodyPart, _damage, _typeOfDamage, _woundID];
diag_log format["Extension _extensionOutput: %1", _extensionOutput]; TRACE_1("",_extensionOutput);
// these are default values and modified by _extensionOutput
private _painToAdd = 0; private _painToAdd = 0;
private _woundsCreated = []; private _woundsCreated = [];
call compile _extensionOutput; call compile _extensionOutput;
{ {
_x params ["", "_toAddClassID", "_bodyPartNToAdd"]; _x params ["", "_woundClassIDToAdd", "_bodyPartNToAdd"];
_foundIndex = -1; _foundIndex = -1;
{ {
_x params ["", "_compareId", "_comparyBodyPartN"];
// Check if we have an id of the given class on the given bodypart already // Check if we have an id of the given class on the given bodypart already
if (_compareId == _toAddClassID && {_comparyBodyPartN2 == _bodyPartNToAdd}) exitWith { if ((_woundClassIDToAdd isEqualTo (_x select 1)) && {_bodyPartNToAdd isEqualTo (_x select 2)}) exitWith {
_foundIndex = _forEachIndex; _foundIndex = _forEachIndex;
}; };
} forEach _openWounds; } forEach _openWounds;
@ -66,4 +72,4 @@ if (count _woundsCreated > 0) then {
private _painLevel = _unit getVariable [QEGVAR(medical,pain), 0]; private _painLevel = _unit getVariable [QEGVAR(medical,pain), 0];
_unit setVariable [QEGVAR(medical,pain), _painLevel + _painToAdd]; _unit setVariable [QEGVAR(medical,pain), _painLevel + _painToAdd];
TRACE_6("ACE_DEBUG: woundsHandler",_unit, _painLevel, _painToAdd, _unit getVariable QEGVAR(medical,pain), _unit getVariable QEGVAR(medical,openWounds),_woundsCreated); TRACE_6("exit",_unit, _painLevel, _painToAdd, _unit getVariable QEGVAR(medical,pain), _unit getVariable QEGVAR(medical,openWounds),_woundsCreated);

View File

@ -1,5 +1,5 @@
/* /*
* Author: Glowbal * Author: Glowbal, commy2
* Handling of the open wounds & injuries upon the handleDamage eventhandler. * Handling of the open wounds & injuries upon the handleDamage eventhandler.
* *
* Arguments: * Arguments:
@ -10,55 +10,48 @@
* 4: Type of the damage done <STRING> * 4: Type of the damage done <STRING>
* *
* Return Value: * Return Value:
* None <NIL> * None
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_bodyPartn", "_injuryTypeInfo", "_allInjuriesForDamageType", "_allPossibleInjuries", "_highestPossibleDamage", "_highestPossibleSpot", "_minDamage", "_openWounds", "_woundID", "_toAddInjury", "_painToAdd", "_bloodLoss", "_bodyPartNToAdd", "_classType", "_damageLevels", "_foundIndex", "_i", "_injury", "_maxDamage", "_pain", "_painLevel", "_selections", "_toAddClassID", "_woundsCreated"]; params ["_unit", "_bodyPart", "_damage", "_typeOfProjectile", "_typeOfDamage"];
params ["_unit", "_selectionName", "_damage", "_typeOfProjectile", "_typeOfDamage"]; TRACE_5("start",_unit,_bodyPart,_damage,_typeOfProjectile,_typeOfDamage);
TRACE_6("ACE_DEBUG: HandleDamage_WoundsOLD Called",_unit, _selectionName, _damage, _shooter, _typeOfProjectile,_typeOfDamage);
systemChat format["input: %1", _this];
// Convert the selectionName to a number and ensure it is a valid selection. // Convert the selectionName to a number and ensure it is a valid selection.
_bodyPartn = EGVAR(medical,HITPOINTS) find _selectionName; //[_selectionName] call EFUNC(medical,selectionNameToNumber); private _bodyPartN = ALL_BODY_PARTS find _bodyPart;
if (_bodyPartn < 0) exitWith {}; if (_bodyPartN < 0) exitWith {};
if (_typeOfDamage == "") then {_typeOfDamage = "unknown";}; if (_typeOfDamage isEqualTo "") then {
_typeOfDamage = "unknown";
};
// Get the injury type information. Format: [typeDamage thresholds, selectionSpecific, woundTypes] // Get the damage type information. Format: [typeDamage thresholds, selectionSpecific, woundTypes]
_injuryTypeInfo = [GVAR(allDamageTypesData) getVariable _typeOfDamage] param [0, [[], false, []]]; // WoundTypes are the available wounds for this damage type. Format [[classID, selections, bleedingRate, pain], ..]
private _damageTypeInfo = [GVAR(allDamageTypesData) getVariable _typeOfDamage] param [0, [[], false, []]];
_damageTypeInfo params ["_thresholds", "_isSelectionSpecific", "_woundTypes"];
// This are the available injuries for this damage type. Format [[classtype, selections, bloodloss, minimalDamage, pain], ..]
_allInjuriesForDamageType = _injuryTypeInfo select 2;
// It appears we are dealing with an unknown type of damage. // It appears we are dealing with an unknown type of damage.
if (count _woundTypes == 0) then {
if (count _allInjuriesForDamageType == 0) then {
// grabbing the configuration for unknown damage type // grabbing the configuration for unknown damage type
_injuryTypeInfo = missionNamespace getVariable [QGVAR(woundInjuryType_unknown),[[], false, []]]; _damageTypeInfo = [GVAR(allDamageTypesData) getVariable "unknown"] param [0, [[], false, []]];
_allInjuriesForDamageType = _injuryTypeInfo select 2; _woundTypes = _damageTypeInfo select 2;
}; };
// find the available injuries for this damage type and damage amount // find the available injuries for this damage type and damage amount
_highestPossibleSpot = -1; private _highestPossibleSpot = -1;
_highestPossibleDamage = -1; private _highestPossibleDamage = -1;
_allPossibleInjuries = []; private _allPossibleInjuries = [];
{ {
_damageLevels = _x select 4; _x params ["", "_selections", "", "", "_damageExtrema"];
_minDamage = _damageLevels select 0; _damageExtrema params ["_minDamage", "_maxDamage"];
_maxDamage = _damageLevels select 1;
// Check if the damage is higher as the min damage for the specific injury // Check if the damage is higher as the min damage for the specific injury
if (_damage >= _minDamage && {_damage <= _maxDamage || _maxDamage < 0}) then { if (_damage >= _minDamage && {_damage <= _maxDamage || _maxDamage < 0}) then {
//_classType = _x select 0;
_selections = _x select 1;
//_bloodLoss = _x select 2;
//_pain = _x select 3;
// Check if the injury can be applied to the given selection name // Check if the injury can be applied to the given selection name
if ("All" in _selections || _selectionName in _selections) then { if ("All" in _selections || _bodyPart in _selections) then { // @todo, this is case sensitive!
// Find the wound which has the highest minimal damage, so we can use this later on for adding the correct injuries // Find the wound which has the highest minimal damage, so we can use this later on for adding the correct injuries
if (_minDamage > _highestPossibleDamage) then { if (_minDamage > _highestPossibleDamage) then {
@ -70,41 +63,48 @@ _allPossibleInjuries = [];
_allPossibleInjuries pushBack _x; _allPossibleInjuries pushBack _x;
}; };
}; };
} forEach _allInjuriesForDamageType; } forEach _woundTypes;
// No possible wounds available for this damage type or damage amount. // No possible wounds available for this damage type or damage amount.
if (_highestPossibleSpot < 0) exitWith {}; if (_highestPossibleSpot < 0) exitWith {};
// Administration for open wounds and ids // Administration for open wounds and ids
_openWounds = _unit getVariable[QGVAR(openWounds), []]; private _openWounds = _unit getVariable [QGVAR(openWounds), []];
_woundID = _unit getVariable[QGVAR(lastUniqueWoundID), 1]; private _woundID = _unit getVariable [QGVAR(lastUniqueWoundID), 1];
private _painToAdd = 0;
private _woundsCreated = [];
_painToAdd = 0;
_woundsCreated = [];
{ {
if (_x select 0 <= _damage) exitWith { if (_x select 0 <= _damage) exitWith {
for "_i" from 0 to ((_x select 1)-1) do { for "_i" from 0 to ((_x select 1)-1) do {
// Find the injury we are going to add. Format [ classID, allowdSelections, bloodloss, painOfInjury, minimalDamage] // Find the injury we are going to add. Format [ classID, allowdSelections, bleedingRate, injuryPain]
_toAddInjury = if (random(1) >= 0.85) then {_allInjuriesForDamageType select _highestPossibleSpot} else {selectRandom _allPossibleInjuries}; private _oldInjury = if (random 1 >= 0.85) then {
_toAddClassID = _toAddInjury select 0; _woundTypes select _highestPossibleSpot
_foundIndex = -1; } else {
selectRandom _allPossibleInjuries
};
_oldInjury params ["_woundClassIDToAdd", "", "_injuryBleedingRate", "_injuryPain"];
private _bodyPartNToAdd = [floor random 6, _bodyPartN] select _isSelectionSpecific; // 6 == count ALL_BODY_PARTS
_bodyPartNToAdd = if (_injuryTypeInfo select 1) then {_bodyPartn} else {floor(random(6))};
// If the injury type is selection part specific, we will check if one of those injury types already exists and find the spot for it.. // If the injury type is selection part specific, we will check if one of those injury types already exists and find the spot for it..
if ((_injuryTypeInfo select 1)) then { private _foundIndex = -1;
if (_isSelectionSpecific) then {
{ {
// Check if we have an id of the given class on the given bodypart already // Check if we have an id of the given class on the given bodypart already
if (_x select 1 == _toAddClassID && {_x select 2 == _bodyPartNToAdd}) exitWith { if ((_woundClassIDToAdd isEqualTo (_x select 1)) && {_bodyPartNToAdd isEqualTo (_x select 2)}) exitWith {
_foundIndex = _forEachIndex; _foundIndex = _forEachIndex;
}; };
} forEach _openWounds; } forEach _openWounds;
}; };
_injury = []; private _injury = [];
if (_foundIndex < 0) then { if (_foundIndex < 0) then {
// Create a new injury. Format [ID, classID, bodypart, percentage treated, bloodloss rate] // Create a new injury. Format [ID, classID, bodypart, percentage treated, bleeding rate]
_injury = [_woundID, _toAddInjury select 0, _bodyPartNToAdd, 1, _toAddInjury select 2]; _injury = [_woundID, _woundClassIDToAdd, _bodyPartNToAdd, 1, _injuryBleedingRate];
// Since it is a new injury, we will have to add it to the open wounds array to store it // Since it is a new injury, we will have to add it to the open wounds array to store it
_openWounds pushBack _injury; _openWounds pushBack _injury;
@ -116,14 +116,15 @@ _woundsCreated = [];
_injury = _openWounds select _foundIndex; _injury = _openWounds select _foundIndex;
_injury set [3, (_injury select 3) + 1]; _injury set [3, (_injury select 3) + 1];
}; };
// Store the injury so we can process it later correctly. // Store the injury so we can process it later correctly.
_woundsCreated pushBack _injury; _woundsCreated pushBack _injury;
// Collect the pain that is caused by this injury // Collect the pain that is caused by this injury
_painToAdd = _painToAdd + (_toAddInjury select 3); _painToAdd = _injuryPain + _painToAdd;
}; };
}; };
} forEach (_injuryTypeInfo select 0); // forEach damage thresholds } forEach _thresholds;
_unit setVariable [QGVAR(openWounds), _openWounds, true]; _unit setVariable [QGVAR(openWounds), _openWounds, true];
@ -132,6 +133,7 @@ if (count _woundsCreated > 0) then {
_unit setVariable [QGVAR(lastUniqueWoundID), _woundID, true]; _unit setVariable [QGVAR(lastUniqueWoundID), _woundID, true];
}; };
_painLevel = _unit getVariable [QGVAR(pain), 0]; private _painLevel = _unit getVariable [QGVAR(pain), 0];
_unit setVariable [QGVAR(pain), _painLevel + _painToAdd]; _unit setVariable [QGVAR(pain), _painLevel + _painToAdd];
TRACE_6("ACE_DEBUG: HandleDamage_WoundsOLD",_unit, _painLevel, _painToAdd, _unit getVariable QGVAR(pain), _unit getVariable QGVAR(openWounds),_woundsCreated);
TRACE_6("exit",_unit, _painLevel, _painToAdd, _unit getVariable QGVAR(pain), _unit getVariable QGVAR(openWounds),_woundsCreated);

View File

@ -20,3 +20,5 @@
#define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default}) #define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default})
#define GET_STRING(config,default) (if (isText (config)) then {getText (config)} else {default}) #define GET_STRING(config,default) (if (isText (config)) then {getText (config)} else {default})
#define GET_ARRAY(config,default) (if (isArray (config)) then {getArray (config)} else {default}) #define GET_ARRAY(config,default) (if (isArray (config)) then {getArray (config)} else {default})
#define ALL_BODY_PARTS ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"]

View File

@ -55,7 +55,7 @@
armor = 1;\ armor = 1;\
material = -1;\ material = -1;\
name = "head";\ name = "head";\
passThrough = 1;\ passThrough = 0;\
radius = 1;\ radius = 1;\
explosionShielding = 1;\ explosionShielding = 1;\
visual = "";\ visual = "";\