Minor improvements made to handleDamage functions

This commit is contained in:
Thomas Kooi 2015-01-25 14:00:51 +01:00
parent 95cfe5ce3a
commit 73d3869a04
4 changed files with 40 additions and 25 deletions

View File

@ -11,7 +11,7 @@
#include "script_component.hpp"
private ["_unit", "_selectionName","_damage"];
private ["_unit", "_selectionName","_damage", "_source","_projectile","_hitSelections","_hitPoints","_newDamage","_cache_hitpoints","_cache_projectiles","_cache_params","_cache_damages"];
_unit = _this select 0;
_selectionName = _this select 1;
_damage = _this select 2;
@ -47,11 +47,12 @@ if (_unit getVariable [QGVAR(isFalling), false]) then {
// Finished with the current frame, reset variables
// Note: sometimes handleDamage spans over 2 or even 3 frames.
if (diag_frameno > (_unit getVariable [QGVAR(frameNo), -3]) + 2) then {
_unit setVariable [QGVAR(frameNo), diag_frameno];
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
[{
private ["_args","_unit","_frameNo"];
_args = _this select 0;
_unit = _args select 0;
_frameNo = _args select 1;
@ -87,7 +88,7 @@ if (_selectionName != "") then {
// Check if the current projectile has already been handled once
if (_projectile in _cache_projectiles) then {
private ["_index","_otherDamage"];
// if it has been handled, find the index in the cache
_index = _cache_projectiles find _projectile;
@ -98,6 +99,7 @@ if (_selectionName != "") then {
if (_otherDamage > _newDamage) then {
_newDamage = 0;
} else {
private ["_hitPoint", "_restore"];
// Restore the damage before the previous damage was processed
_hitPoint = _cache_hitpoints select _index;
_restore = ((_unit getHitPointDamage _hitPoint) - _otherDamage) max 0;

View File

@ -21,9 +21,9 @@ if ((vehicle _unit != _unit) && {!alive (vehicle _unit)}) exitwith { true };
// Find the correct Damage threshold for unit.
_damageThreshold = [1,1,1];
if (isPlayer _unit) then {
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_Players), GVAR(damageThreshold_Players), GVAR(damageThreshold_Players)]];
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_Players), GVAR(damageThreshold_Players), GVAR(damageThreshold_Players) * 1.7]];
} else {
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_AI), GVAR(damageThreshold_AI), GVAR(damageThreshold_AI)]];
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_AI), GVAR(damageThreshold_AI), GVAR(damageThreshold_AI) * 1.7]];
};
_damageBodyPart = ([_unit,QGVAR(bodyPartStatus),[0,0,0,0,0,0]] call EFUNC(common,getDefinedVariable)) select _part;

View File

@ -42,8 +42,8 @@ if !(_selectionName in ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"]) e
[_unit, _selectionName, _damage, _source, _projectile] call FUNC(cacheHandledamageCall);
// Checking if we should return full damage or not
if (_damage > 0.95) then {
_damage = 0.95;
if (_damage > 0.975) then {
_damage = 0.975;
};
// Check if a unit would die from this hit
@ -53,12 +53,21 @@ if (alive _unit && (vehicle _unit == _unit) && {alive (vehicle _unit)}) then {
// Find the correct Damage threshold for unit.
_damageThreshold = [1,1,1];
if (isPlayer _unit) then {
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_Players), GVAR(damageThreshold_Players), GVAR(damageThreshold_Players)]];
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_Players), GVAR(damageThreshold_Players), GVAR(damageThreshold_Players) * 1.7]];
} else {
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_AI), GVAR(damageThreshold_AI), GVAR(damageThreshold_AI)]];
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_AI), GVAR(damageThreshold_AI), GVAR(damageThreshold_AI) * 1.7]];
};
_damageBodyPart = ([_unit,QGVAR(bodyPartStatus),[0,0,0,0,0,0]] call EFUNC(common,getDefinedVariable)) select _bodyPartn;
_hitSelections = ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"];
_hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"];
// Calculate change in damage.
_newDamage = _damage - (damage _unit);
if (_selectionName in _hitSelections) then {
_newDamage = _damage - (_unit getHitPointDamage (_hitPoints select (_hitSelections find _selectionName)));
};
// Check if damage to body part is higher as damage head
if (_bodyPartn == 0) exitwith {
if (_damageBodyPart >= ((_damageThreshold select 0) + _newDamage) && {(random(1) > 0.2)}) then {

View File

@ -9,56 +9,60 @@
*/
#include "script_component.hpp"
#define ADD_INJURY(BODYPART,TYPE,AMOUNT) _selection = _openWounds select BODYPART; \
_newAmount = (_selection select TYPE) + AMOUNT; \
_selection set [ TYPE, _newAmount]; \
_openWounds set [BODYPART , _selection];
private ["_unit", "_amountOfDamage", "_typeOfInjury", "_bodyPartn"];
private ["_unit", "_amountOfDamage", "_typeOfInjury", "_bodyPartn", "_openWounds","_newAmount","_selection"];
_unit = _this select 0;
_amountOfDamage = _this select 1;
_typeOfInjury = _this select 2;
_bodyPartn = _this select 3;
if (_amountOfDamage > 0.05) exitwith {
_openWounds = [_unit,QGVAR(openWounds)] call EFUNC(common,getDefinedVariable);
switch (toLower _typeOfInjury) do {
case "bullet": {
[_unit, _bodyPartn, round(random(2)), 1, false] call FUNC(addOpenWounds);
ADD_INJURY(_bodyPartn, round(random(2)), 1);
};
case "grenade": {
[_unit, _bodyPartn, round(random(2)), 1] call FUNC(addOpenWounds);
ADD_INJURY(_bodyPartn, round(random(2)), 1);
for "_i" from 0 to round(random(3)) /* step +1 */ do {
[_unit, round(random(6)), round(random(2)), 1, false] call FUNC(addOpenWounds);
ADD_INJURY(round(random(6)), round(random(2)), 1);
};
};
case "explosive": {
[_unit, _bodyPartn, round(random(2)), 1] call FUNC(addOpenWounds);
ADD_INJURY(_bodyPartn, round(random(2)), 1);
for "_i" from 0 to round(random(4)) /* step +1 */ do {
[_unit, round(random(6)), round(random(2)), 1, false] call FUNC(addOpenWounds);
ADD_INJURY(round(random(6)), round(random(2)), 1);
};
};
case "shell": {
[_unit, _bodyPartn, round(random(2)), 1] call FUNC(addOpenWounds);
ADD_INJURY(_bodyPartn, round(random(2)), 1);
for "_i" from 0 to round(random(5)) /* step +1 */ do {
[_unit, round(random(6)), round(random(2)), 1, false] call FUNC(addOpenWounds);
ADD_INJURY(round(random(6)), round(random(2)), 1);
};
};
case "backblast": {
if (random(1)>=0.5) then{
[_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds);
ADD_INJURY(_bodyPartn, round(random(2)), 1);
};
};
case "unknown": {
[_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds);
ADD_INJURY(_bodyPartn, round(random(1)), 1);
};
case "vehiclecrash": {
if (random(1)>=0.5) then{
[_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds);
ADD_INJURY(_bodyPartn, round(random(1)), 1);
};
};
default {
[_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds);
ADD_INJURY(_bodyPartn, round(random(1)), 1);
};
};
// one more call to broadcast the new injuries
[_unit, _bodyPartn, 0, 0, true] call FUNC(addOpenWounds);
[_unit, QGVAR(openWounds),_openWounds] call EFUNC(common,setDefinedVariable);
true;
};