Fixes and removal of duplicate code

This commit is contained in:
Glowbal 2015-08-26 10:04:51 +02:00
parent 7a48f595be
commit 0cfb492916
10 changed files with 80 additions and 229 deletions

View File

@ -22,7 +22,7 @@ _bloodPressure = if (!alive _target) then {
} else {
[_target] call FUNC(getBloodPressure)
};
_bloodPressure params ["_bloodPressureLow", "_bloodPressureLow"];
_bloodPressure params ["_bloodPressureHigh", "_bloodPressureLow"];
_output = "";
_logOutPut = "";
if ([_caller] call FUNC(isMedic)) then {

View File

@ -39,7 +39,7 @@ _litter = getArray (_config >> "litter");
_createLitter = {
private["_position", "_direction"];
params ["_unit", "_litter"];
params ["_unit", "_litterClass"];
// @TODO: handle carriers over water
// For now, don't spawn litter if we are over water to avoid floating litter
if(surfaceIsWater (getPos _unit)) exitWith { false };
@ -55,7 +55,7 @@ _createLitter = {
// Create the litter, and timeout the event based on the cleanup delay
// The cleanup delay for events in MP is handled by the server side
[QGVAR(createLitter), [_litterClass,_position,_direction], 0] call EFUNC(common,syncedEvent);
[QGVAR(createLitter), [_litterClass, _position, _direction], 0] call EFUNC(common,syncedEvent);
true
};
@ -65,7 +65,7 @@ _createdLitter = [];
if (typeName _x == "ARRAY") then {
if (count _x < MIN_ENTRIES_LITTER_CONFIG) exitwith {};
params ["_selection", "_litterCondition", "_litterOptions"];
_x params ["_selection", "_litterCondition", "_litterOptions"];
if (toLower _selection in [toLower _selectionName, "all"]) then { // in is case sensitve. We can be forgiving here, so lets use toLower.

View File

@ -18,8 +18,8 @@
// Exit for basic medical
if (GVAR(level) < 2) exitWith {};
private ["_target", "_show", "_selectionN", "_amountOfGeneric", "_bandagedwounds", "_logCtrl", "_part", "_partText", "_pointDamage", "_severity", "_total", "_totalIvVolume", "_triageStatus", "_type"];
params ["_target", ["_target", true], ["_selectionN", 0]];
private ["_amountOfGeneric", "_bandagedwounds", "_logCtrl", "_part", "_partText", "_pointDamage", "_severity", "_total", "_totalIvVolume", "_triageStatus", "_type"];
params ["_target", ["_show", true], ["_selectionN", 0]];
GVAR(currentSelectedSelectionN) = if (typeName _selectionN == "SCALAR") then {_selectionN} else {0};
GVAR(displayPatientInformationTarget) = if (_show) then {_target} else {ObjNull};
@ -203,7 +203,7 @@ if (_show) then {
_logs = _target getvariable [QGVAR(logFile_Activity), []];
{
// [_message,_moment,_type, _arguments]
_x params ["_message", "_moment", "_arguments"];
_x params ["_message", "_moment", "_type", "_arguments"];
if (isLocalized _message) then {
_message = localize _message;
};

View File

@ -31,79 +31,46 @@ if (typeName _projectile == "OBJECT") then {
if !(_selection in (GVAR(SELECTIONS) + [""])) exitWith {0};
// Exit if we disable damage temporarily
_damageOld = damage _unit;
if (_selection in GVAR(SELECTIONS)) then {
_damageOld = _unit getHit _selection;
if !(_unit getVariable [QGVAR(allowDamage), true]) exitWith {
_damageOld = damage _unit;
if (_selection in GVAR(SELECTIONS)) then {
_damageOld = _unit getHit _selection;
};
_damageOld;
};
if !(_unit getVariable [QGVAR(allowDamage), true]) exitWith {_damageOld};
// Get return damage
_damageReturn = _damage;
if (GVAR(level) < 2) then {
_newDamage = _this call FUNC(handleDamage_basic2);
_projectile = _this select 4;
_typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
_typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
_minLethalDamage = 0.01;
if (_typeIndex >= 0) then {
_minLethalDamage = GVAR(minLethalDamages) select _typeIndex;
_newDamage = _this call FUNC(handleDamage_caching);
// handleDamage_caching may have modified the projectile string
_typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
_typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
_minLethalDamage = 0.01;
if (_typeIndex >= 0) then {
_minLethalDamage = GVAR(minLethalDamages) select _typeIndex;
};
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _shooter} && {_projectile == ""} && {_selection == ""}) then {
if (GVAR(enableVehicleCrashes)) then {
_selection = GVAR(SELECTIONS) select (floor(random(count GVAR(SELECTIONS))));
};
};
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _shooter} && {_projectile == ""} && {_selection == ""}) then {
if (GVAR(enableVehicleCrashes)) then {
_selection = GVAR(SELECTIONS) select (floor(random(count GVAR(SELECTIONS))));
};
if ((_minLethalDamage <= _newDamage) && {[_unit, [_selection] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
_damageReturn = 0.9;
};
if ((_minLethalDamage <= _newDamage) && {[_unit, [_selection] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
_damageReturn = 0.9;
};
if ([_unit] call FUNC(setDead)) then {
_damageReturn = 1;
} else {
_damageReturn = _damageReturn min 0.89;
};
if ([_unit] call FUNC(setDead)) then {
_damageReturn = 1;
} else {
_damageReturn = _damageReturn min 0.89;
};
} else {
if !([_unit] call FUNC(hasMedicalEnabled)) exitwith {
// Because of the config changes, we cannot properly disable the medical system for a unit.
// lets use basic for the ACE_time being..
_damageReturn = _this call FUNC(handleDamage_basic);
};
_newDamage = _this call FUNC(handleDamage_caching);
// handleDamage_caching may have modified the projectile string
_typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
_typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
_minLethalDamage = 0.01;
if (_typeIndex >= 0) then {
_minLethalDamage = GVAR(minLethalDamages) select _typeIndex;
};
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _shooter} && {_projectile == ""} && {_selection == ""}) then {
if (GVAR(enableVehicleCrashes)) then {
_selection = GVAR(SELECTIONS) select (floor(random(count GVAR(SELECTIONS))));
};
};
if ((_minLethalDamage <= _newDamage) && {[_unit, [_selection] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
_damageReturn = 0.9;
};
if ([_unit] call FUNC(setDead)) then {
_damageReturn = 1;
} else {
_damageReturn = _damageReturn min 0.89;
};
} else {
_damageReturn = _damageReturn min 0.89;
};
_damageReturn = _damageReturn min 0.89;
};
[_unit] call FUNC(addToInjuredCollection);
if (_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)]) exitWith {

View File

@ -20,7 +20,7 @@
#include "script_component.hpp"
private ["_typeOfProjectile", "_part", "_damageBodyParts", "_hitPoints"];
params ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfDamage", "_newDamage"];
params ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfProjectile", "_newDamage"];
// Most likely taking exessive fire damage. Lets exit.
if (isNull _sourceOfDamage && {_typeOfProjectile == ""} && {vehicle _unit == _unit} && {(_selectionName == "head" || isBurning _unit)}) exitwith {};
@ -35,7 +35,11 @@ _damageBodyParts set [_part, (_damageBodyParts select _part) + _newDamage];
_unit setvariable [QGVAR(bodyPartStatus), _damageBodyParts, true];
_typeOfDamage = [_typeOfProjectile] call FUNC(getTypeOfDamage);
[_unit, _selectionName, _newDamage, _typeOfProjectile, _typeOfDamage] call FUNC(handleDamage_assignWounds);
systemChat format["ASSIGNING INJURIES: %1", _unit];
[_unit, _selectionName, _newDamage, _typeOfProjectile, _typeOfDamage] call FUNC(handleDamage_wounds); //FUNC(handleDamage_assignWounds);
// TODO Disabled until implemented fully
//if (GVAR(enableAirway)) then {

View File

@ -3,12 +3,6 @@
* 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: Current damage to be returned <NUMBER>
*
* Return Value:
* <nil>
@ -18,151 +12,29 @@
#include "script_component.hpp"
private ["_unit", "_selectionName", "_damage", "_source", "_projectile", "_hitSelections", "_hitPoints", "_impactVelocity", "_newDamage", "_cache_hitpoints", "_cache_projectiles", "_cache_params", "_cache_damages"];
_unit = _this select 0;
_selectionName = _this select 1;
_damage = _this select 2;
_source = _this select 3;
_projectile = _this select 4;
private ["_damageBodyParts", "_cache_params", "_cache_damages"];
params ["_target"];
_hitSelections = GVAR(SELECTIONS);
_hitPoints = GVAR(HITPOINTS);
_damageBodyParts = _target getvariable [QGVAR(bodyPartStatus), [0,0,0,0,0,0]];
_cache_params = _target getVariable [QGVAR(cachedHandleDamageParams), []];
_cache_damages = _target getVariable QGVAR(cachedDamages);
// Calculate change in damage.
_newDamage = _damage - (damage _unit);
if (_selectionName in _hitSelections) then {
_newDamage = _damage - (_unit getHitPointDamage (_hitPoints select (_hitSelections find _selectionName)));
};
//_damage = _damage + _newDamage;
// Check for vehicle crash
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _source} && {_projectile == ""} && {_selectionName == ""}) then {
if (GVAR(enableVehicleCrashes)) then {
_selectionName = _hitSelections select (floor(random(count _hitSelections)));
_projectile = "vehiclecrash";
_this set [1, _selectionName];
_this set [4, _projectile];
{
_x params ["_unit","_selectionName","_amountOfDamage","_sourceOfDamage","_typeOfProjectile","_typeOfDamage"];
if !(isNull _sourceOfDamage && {_typeOfProjectile == ""} && {vehicle _unit == _unit} && {(_selectionName == "head" || isBurning _unit)}) then {
_part = [_selectionName] call FUNC(selectionNameToNumber);
if (_part < 0) exitwith {};
_damageBodyParts set [_part, (_damageBodyParts select _part) + (_cache_damages select _foreachIndex)];
};
};
}foreach _cache_params;
_target setvariable [QGVAR(bodyPartStatus), _damageBodyParts, true];
// Handle falling damage
_impactVelocity = (velocity _unit) select 2;
if (_impactVelocity < -5 && {vehicle _unit == _unit}) then {
_unit setVariable [QGVAR(isFalling), true];
_unit setVariable [QGVAR(impactVelocity), _impactVelocity];
};
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;
};
} else {
if (_selectionName == "") then {
_selectionName = ["leg_l", "leg_r"] select (floor(random 2));
_this set [1, _selectionName];
};
_newDamage = _newDamage * 0.7;
};
_projectile = "falling";
_this set [4, "falling"];
};
EXPLODE_6_PVT(_damageBodyParts,_headDamage,_torsoDamage,_handsDamageR,_handsDamageL,_legsDamageR,_legsDamageL);
_target setHitPointDamage ["hitHead", _headDamage min 0.95];
_target setHitPointDamage ["hitBody", _torsoDamage min 0.95];
_target setHitPointDamage ["hitHands", (_handsDamageR + _handsDamageL) min 0.95];
_target setHitPointDamage ["hitLegs", (_legsDamageR + _legsDamageL) min 0.95];
// 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", "_id"];
_args params ["_target", "_frameNo"];
if (diag_frameno > _frameNo + 2) then {
_target setDamage 0;
_cache_params = _target getVariable [QGVAR(cachedHandleDamageParams), []];
_cache_damages = _target getVariable QGVAR(cachedDamages);
_damageBodyParts = _target getvariable [QGVAR(bodyPartStatus), [0,0,0,0,0,0]];
{
_x params ["_unit","_selectionName","_amountOfDamage","_sourceOfDamage","_typeOfProjectile","_typeOfDamage"];
if !(isNull _sourceOfDamage && {_typeOfProjectile == ""} && {vehicle _unit == _unit} && {(_selectionName == "head" || isBurning _unit)}) then {
_part = [_selectionName] call FUNC(selectionNameToNumber);
if (_part < 0) exitwith {};
_damageBodyParts set [_part, (_damageBodyParts select _part) + (_cache_damages select _foreachIndex)];
};
}foreach _cache_params;
_unit setvariable [QGVAR(bodyPartStatus), _damageBodyParts, true];
EXPLODE_6_PVT(_damageBodyParts,_headDamage,_torsoDamage,_handsDamageR,_handsDamageL,_legsDamageR,_legsDamageL);
_target setHitPointDamage ["hitHead", _headDamage min 0.95];
_target setHitPointDamage ["hitBody", _torsoDamage min 0.95];
_target setHitPointDamage ["hitHands", (_handsDamageR + _handsDamageL) min 0.95];
_target setHitPointDamage ["hitLegs", (_legsDamageR + _legsDamageL) min 0.95];
{
_target setHitPointDamage [_x, (_damageBodyParts select _foreachIndex) min 0.95];
}foreach GVAR(HITPOINTS);
[_id] 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 {
_cache_projectiles = _unit getVariable QGVAR(cachedProjectiles);
private ["_index","_otherDamage"];
_index = _cache_projectiles find _projectile;
// Check if the current projectile has already been handled once
if (_index >= 0 && {_projectile != "falling"}) exitwith {
_cache_damages = _unit getVariable QGVAR(cachedDamages);
// Find the previous damage this projectile has done
_otherDamage = (_cache_damages select _index);
// Take the highest damage of the two
if (_newDamage > _otherDamage) then {
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
private ["_hitPoint", "_restore"];
// Restore the damage before the previous damage was processed
_hitPoint = _cache_hitpoints select _index;
_restore = ((_unit getHitPointDamage _hitPoint) - _otherDamage) max 0;
_unit setHitPointDamage [_hitPoint, _restore];
_cache_hitpoints set [_index, (_hitPoints select (_hitSelections find _selectionName))];
_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];
};
};
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
_cache_damages = _unit getVariable QGVAR(cachedDamages);
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
// This is an unhandled projectile
_cache_projectiles pushBack _projectile;
_cache_hitpoints pushBack (_hitPoints select (_hitSelections find _selectionName));
_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];
};
_newDamage;
{
_target setHitPointDamage [_x, (_damageBodyParts select _foreachIndex) min 0.95];
}foreach GVAR(HITPOINTS);

View File

@ -79,15 +79,17 @@ if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) t
if (diag_frameno > _frameno + 2) then {
_unit setDamage 0;
_cache_params = _unit getVariable [QGVAR(cachedHandleDamageParams), []];
_cache_damages = _unit getVariable QGVAR(cachedDamages);
{
_params = _x + [_cache_damages select _foreachIndex];
_params call FUNC(handleDamage_advanced);
} foreach _cache_params;
[_unit] call FUNC(handleDamage_advancedSetDamage);
if (GVAR(level) < 2 || {!([_unit] call FUNC(hasMedicalEnabled))}) then {
[_unit] call FUNC(handleDamage_basic2);
} else {
_cache_params = _unit getVariable [QGVAR(cachedHandleDamageParams), []];
_cache_damages = _unit getVariable QGVAR(cachedDamages);
{
_params = _x + [_cache_damages select _foreachIndex];
_params 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;

View File

@ -20,11 +20,15 @@
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", "_selectionName", "_damage", "_typeOfProjectile", "_typeOfDamage"];
systemChat format["input: %1", _this];
diag_log format["input: %1", _this];
// Administration for open wounds and ids
_openWounds = _unit getvariable[QGVAR(openWounds), []];
_woundID = _unit getvariable[QGVAR(lastUniqueWoundID), 1];
_extensionOutput = "ace_medical" callExtension format ["HandleDamageWounds,%1,%2,%3,%4", _selectionName, _damage, _typeOfDamage, _woundID];
systemChat format["EXTENSION OUTPUT: %1", _extensionOutput];
_painToAdd = 0;
_woundsCreated = [];

View File

@ -17,7 +17,7 @@
*/
#include "script_component.hpp"
params ["_caller", "_target", "_selectionName", "_className", "_items", ["_specificSpot", -1]];
params ["_caller", "_target", "_selectionName", "_className", "_items", "", ["_specificSpot", -1]];
if !([_target] call FUNC(hasMedicalEnabled)) exitwith {
_this call FUNC(treatmentBasic_bandage);

View File

@ -40,7 +40,8 @@ _effectivenessFound = -1;
_mostEffectiveInjury = _openWounds select 0;
_exit = false;
{
params ["", "_classID", "_partX"];
_x params ["", "_classID", "_partX"];
diag_log format["OPENWOUND: %1", _x];
// Only parse injuries that are for the selected bodypart.
if (_partX == _part) then {
_woundEffectivenss = _effectiveness;
@ -56,6 +57,7 @@ _exit = false;
};
};
diag_log format["_specificClass: %1 vs classId %2", _specificClass, _classID];
if (_specificClass == _classID) exitwith {
_effectivenessFound = _woundEffectivenss;
_mostEffectiveSpot = _foreachIndex;