Added support for JIP injury synchronizing

Enabled heart beat sounds
This commit is contained in:
Glowbal 2015-03-01 12:33:05 +01:00
parent fb763a9d57
commit 91a52a4b76
5 changed files with 91 additions and 22 deletions

View File

@ -11,6 +11,7 @@ GVAR(playingHeartBeatSound) = false;
["Medical_treatmentCompleted", FUNC(onTreatmentCompleted)] call ace_common_fnc_addEventHandler;
["medical_propagateWound", FUNC(onPropagateWound)] call ace_common_fnc_addEventHandler;
["medical_woundUpdateRequest", FUNC(onWoundUpdateRequest)] call ace_common_fnc_addEventHandler;
// Initialize all effects
// @todo: make this a macro?
@ -197,28 +198,34 @@ if (isNil QGVAR(level)) then {
};
};
/* @todo
// Heart rate sound effect
_heartRate = _unit getvariable[QGVAR(heartRate), 70];
if (_heartRate > 0.1) then {
if (GVAR(playingHeartBeatSound)) exitwith {};
GVAR(playingHeartBeatSound) = true;
_sleep = 60 / _heartRate;
if (GVAR(level) > 0) then {
// Heart rate sound effect
if (_heartRate < 60) then {
_sound = GVAR(heartBeatSounds_Slow) select (random((count GVAR(heartBeatSounds_Slow)) -1));
playSound _sound;
[{
GVAR(playingHeartBeatSound) = false;
}, [], _sleep, _sleep] call EFUNC(common,waitAndExecute);
} else {
if (_heartRate > 120) then {
_sound = GVAR(heartBeatSounds_Fast) select (random((count GVAR(heartBeatSounds_Fast)) -1));
playSound _sound;
[{
GVAR(playingHeartBeatSound) = false;
}, [], _sleep, _sleep] call EFUNC(common,waitAndExecute);
};
};
};
*/
}, 0, []] call CBA_fnc_addPerFrameHandler;
// broadcast injuries to JIP clients in a MP session
if (isMultiplayer && !isDedicated) then {
[QGVAR(onPlayerConnected), "onPlayerConnected", {
if (isNil QGVAR(InjuredCollection)) then {
GVAR(InjuredCollection) = [];
};
{
_unit = _x;
_openWounds = _unit getvariable [QGVAR(openWounds), []];
{
["medical_propagateWound", [_id], [_unit, _x]] call EFUNC(common,targetEvent);
}foreach _openWounds;
}foreach GVAR(InjuredCollection);
}, []] call BIS_fnc_addStackedEventHandler;
};

View File

@ -44,6 +44,7 @@ PREP(isInMedicalFacility);
PREP(isMedic);
PREP(isMedicalVehicle);
PREP(onMedicationUsage);
PREP(onWoundUpdateRequest);
PREP(onPropagateWound);
PREP(parseConfigForInjuries);
PREP(playInjuredSound);

View File

@ -42,4 +42,9 @@ if ([_unit] call FUNC(hasMedicalEnabled)) then {
};
};
}, 1, [_unit]] call CBA_fnc_addPerFrameHandler;
if (isNil QGVAR(InjuredCollection)) then {
GVAR(InjuredCollection) = [];
};
GVAR(InjuredCollection) pushback _unit;
};

View File

@ -17,33 +17,47 @@
#include "script_component.hpp"
private ["_unit", "_selectionName", "_damage", "_typeOfProjectile", "_typeOfDamage", "_bodyPartn", "_woundType", "_injuryTypeInfo", "_allInjuriesForDamageType", "_allPossibleInjuries", "_highestPossibleDamage", "_highestPossibleSpot", "_minDamage", "_openWounds", "_woundID", "_toAddInjury"];
private ["_unit", "_selectionName", "_damage", "_typeOfProjectile", "_typeOfDamage", "_bodyPartn", "_woundType", "_injuryTypeInfo", "_allInjuriesForDamageType", "_allPossibleInjuries", "_highestPossibleDamage", "_highestPossibleSpot", "_minDamage", "_openWounds", "_woundID", "_toAddInjury", "_painToAdd"];
_unit = _this select 0;
_selectionName = _this select 1;
_damage = _this select 2;
_typeOfProjectile = _this select 3;
_typeOfDamage = _this select 4;
_bodyPartn = [_selectionName] call FUNC(selectionNameToNumber);
// Convert the selectionName to a number and ensure it is a valid selection.
_bodyPartn = [_selectionName] call FUNC(selectionNameToNumber);
if (_bodyPartn < 0) exitwith {};
_injuryTypeInfo = missionNamespace getvariable [format[QGVAR(woundInjuryType_%1), _typeOfDamage],[[],[]]];
// Get the injury type information. Format: [typeDamage thresholds, selectionSpecific, woundTypes]
_injuryTypeInfo = missionNamespace getvariable [format[QGVAR(woundInjuryType_%1), _typeOfDamage],[[], false, []]];
// This are the available injuries for this damage type. Format [[classtype, selections, bloodloss, minimalDamage, pain], ..]
_allInjuriesForDamageType = _injuryTypeInfo select 2;
// find the available injuries for this damage type and damage amount
_highestPossibleSpot = -1;
_highestPossibleDamage = 0;
_allPossibleInjuries = [];
{
_classType = _x select 0;
_selections = _x select 1;
_bloodLoss = _x select 2;
_pain = _x select 3;
_minDamage = _x select 4;
// Check if the damage is higher as the min damage for the specific injury
if (_damage >= _minDamage) 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
if ("All" in _selections || _selectionName in _selections) then {
// 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 {
_highestPossibleSpot = _foreachIndex;
_highestPossibleDamage = _minDamage;
};
// Store the valid possible injury for the damage type, damage amount and selection
_allPossibleInjuries pushback _x;
};
};
@ -56,19 +70,30 @@ if (_highestPossibleSpot < 0) exitwith {
};
};
// admin for open wounds and ids
_openWounds = _unit getvariable[QGVAR(openWounds), []];
_woundID = _unit getvariable[QGVAR(lastUniqueWoundID), 1];
_painToAdd = 0;
_woundsCreated = [];
{
if (_x select 0 <= _damage) exitwith {
for "_i" from 0 to (1+ floor(random(_x select 1)-1)) /* step +1 */ do {
// Find the injury we are going to add. Format [ classType, allowdSelections, bloodloss, painOfInjury, minimalDamage]
_toAddInjury = _allPossibleInjuries select (floor(random (count _allPossibleInjuries)));
// ID, classname, bodypart, percentage treated, bloodloss rate
// Create a new injury. Format [ID, classname, bodypart, percentage treated, bloodloss rate]
_injury = [_woundID, _toAddInjury select 0, if (_injuryTypeInfo select 1) then {_bodyPartn} else {floor(random(6))}, 1, _toAddInjury select 2];
// Store the injury so we can process it later correctly.
_openWounds pushback _injury;
_woundsCreated pushback _injury;
_woundID = _woundID + 1;
// Collect the pain that is caused by this injury
_painToAdd = _painToAdd + (_toAddInjury select 3);
};
};
}foreach (_injuryTypeInfo select 0);
@ -76,6 +101,10 @@ _woundsCreated = [];
_unit setvariable [QGVAR(openWounds), _openWounds];
_unit setvariable [QGVAR(lastUniqueWoundID), _woundID, true];
// Broadcast the new injuries across the net in parts. One broadcast per injury. Prevents having to broadcast one massive array of injuries.
{
["medical_propagateWound", [_unit, _x]] call EFUNC(common,globalEvent);
}foreach _woundsCreated;
_painLevel = _unit getvariable [QGVAR(pain), 0];
_unit setvariable [QGVAR(pain), _painLevel + _painToAdd];

View File

@ -0,0 +1,27 @@
/*
* Author: Glowbal
* Enabled the vitals loop for a unit.
*
* Arguments:
* 0: The Unit <OBJECT>
* 1: the last known ID <NUMBER>
* 2: Origin object <OBJECT>
*
* ReturnValue:
* <NIL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_unit", "_lastId", "_openWounds"];
_unit = _this select 0;
_lastId = _this select 1;
_originOfrequest = _this select 2;
_openWounds = _unit getvariable [QGVAR(openWounds), []];
if (count _openWounds > _lastId) then {
{
["medical_propagateWound", [_originOfrequest], [_unit, _x]] call EFUNC(common,targetEvent);
}foreach _openWounds;
};