mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Minor improvements made to handleDamage functions
This commit is contained in:
parent
95cfe5ce3a
commit
73d3869a04
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "script_component.hpp"
|
#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;
|
_unit = _this select 0;
|
||||||
_selectionName = _this select 1;
|
_selectionName = _this select 1;
|
||||||
_damage = _this select 2;
|
_damage = _this select 2;
|
||||||
@ -47,11 +47,12 @@ if (_unit getVariable [QGVAR(isFalling), false]) then {
|
|||||||
|
|
||||||
// Finished with the current frame, reset variables
|
// Finished with the current frame, reset variables
|
||||||
// Note: sometimes handleDamage spans over 2 or even 3 frames.
|
// Note: sometimes handleDamage spans over 2 or even 3 frames.
|
||||||
if (diag_frameno > (_unit getVariable [QGVAR(frameNo), -3]) + 2) then {
|
if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) then {
|
||||||
_unit setVariable [QGVAR(frameNo), diag_frameno];
|
_unit setVariable [QGVAR(frameNo_damageCaching), diag_frameno];
|
||||||
|
|
||||||
// handle the cached damages 3 frames later
|
// handle the cached damages 3 frames later
|
||||||
[{
|
[{
|
||||||
|
private ["_args","_unit","_frameNo"];
|
||||||
_args = _this select 0;
|
_args = _this select 0;
|
||||||
_unit = _args select 0;
|
_unit = _args select 0;
|
||||||
_frameNo = _args select 1;
|
_frameNo = _args select 1;
|
||||||
@ -87,7 +88,7 @@ if (_selectionName != "") then {
|
|||||||
|
|
||||||
// Check if the current projectile has already been handled once
|
// Check if the current projectile has already been handled once
|
||||||
if (_projectile in _cache_projectiles) then {
|
if (_projectile in _cache_projectiles) then {
|
||||||
|
private ["_index","_otherDamage"];
|
||||||
// if it has been handled, find the index in the cache
|
// if it has been handled, find the index in the cache
|
||||||
_index = _cache_projectiles find _projectile;
|
_index = _cache_projectiles find _projectile;
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ if (_selectionName != "") then {
|
|||||||
if (_otherDamage > _newDamage) then {
|
if (_otherDamage > _newDamage) then {
|
||||||
_newDamage = 0;
|
_newDamage = 0;
|
||||||
} else {
|
} else {
|
||||||
|
private ["_hitPoint", "_restore"];
|
||||||
// Restore the damage before the previous damage was processed
|
// Restore the damage before the previous damage was processed
|
||||||
_hitPoint = _cache_hitpoints select _index;
|
_hitPoint = _cache_hitpoints select _index;
|
||||||
_restore = ((_unit getHitPointDamage _hitPoint) - _otherDamage) max 0;
|
_restore = ((_unit getHitPointDamage _hitPoint) - _otherDamage) max 0;
|
||||||
|
@ -21,9 +21,9 @@ if ((vehicle _unit != _unit) && {!alive (vehicle _unit)}) exitwith { true };
|
|||||||
// Find the correct Damage threshold for unit.
|
// Find the correct Damage threshold for unit.
|
||||||
_damageThreshold = [1,1,1];
|
_damageThreshold = [1,1,1];
|
||||||
if (isPlayer _unit) then {
|
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 {
|
} 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;
|
_damageBodyPart = ([_unit,QGVAR(bodyPartStatus),[0,0,0,0,0,0]] call EFUNC(common,getDefinedVariable)) select _part;
|
||||||
|
@ -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);
|
[_unit, _selectionName, _damage, _source, _projectile] call FUNC(cacheHandledamageCall);
|
||||||
|
|
||||||
// Checking if we should return full damage or not
|
// Checking if we should return full damage or not
|
||||||
if (_damage > 0.95) then {
|
if (_damage > 0.975) then {
|
||||||
_damage = 0.95;
|
_damage = 0.975;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if a unit would die from this hit
|
// 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.
|
// Find the correct Damage threshold for unit.
|
||||||
_damageThreshold = [1,1,1];
|
_damageThreshold = [1,1,1];
|
||||||
if (isPlayer _unit) then {
|
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 {
|
} 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;
|
_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
|
// Check if damage to body part is higher as damage head
|
||||||
if (_bodyPartn == 0) exitwith {
|
if (_bodyPartn == 0) exitwith {
|
||||||
if (_damageBodyPart >= ((_damageThreshold select 0) + _newDamage) && {(random(1) > 0.2)}) then {
|
if (_damageBodyPart >= ((_damageThreshold select 0) + _newDamage) && {(random(1) > 0.2)}) then {
|
||||||
|
@ -9,56 +9,60 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#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;
|
_unit = _this select 0;
|
||||||
_amountOfDamage = _this select 1;
|
_amountOfDamage = _this select 1;
|
||||||
_typeOfInjury = _this select 2;
|
_typeOfInjury = _this select 2;
|
||||||
_bodyPartn = _this select 3;
|
_bodyPartn = _this select 3;
|
||||||
|
|
||||||
if (_amountOfDamage > 0.05) exitwith {
|
if (_amountOfDamage > 0.05) exitwith {
|
||||||
|
_openWounds = [_unit,QGVAR(openWounds)] call EFUNC(common,getDefinedVariable);
|
||||||
switch (toLower _typeOfInjury) do {
|
switch (toLower _typeOfInjury) do {
|
||||||
case "bullet": {
|
case "bullet": {
|
||||||
[_unit, _bodyPartn, round(random(2)), 1, false] call FUNC(addOpenWounds);
|
ADD_INJURY(_bodyPartn, round(random(2)), 1);
|
||||||
};
|
};
|
||||||
case "grenade": {
|
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 {
|
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": {
|
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 {
|
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": {
|
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 {
|
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": {
|
case "backblast": {
|
||||||
if (random(1)>=0.5) then{
|
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": {
|
case "unknown": {
|
||||||
[_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds);
|
ADD_INJURY(_bodyPartn, round(random(1)), 1);
|
||||||
};
|
};
|
||||||
case "vehiclecrash": {
|
case "vehiclecrash": {
|
||||||
if (random(1)>=0.5) then{
|
if (random(1)>=0.5) then{
|
||||||
[_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds);
|
ADD_INJURY(_bodyPartn, round(random(1)), 1);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
default {
|
default {
|
||||||
[_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds);
|
ADD_INJURY(_bodyPartn, round(random(1)), 1);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
[_unit, QGVAR(openWounds),_openWounds] call EFUNC(common,setDefinedVariable);
|
||||||
// one more call to broadcast the new injuries
|
|
||||||
[_unit, _bodyPartn, 0, 0, true] call FUNC(addOpenWounds);
|
|
||||||
|
|
||||||
true;
|
true;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user