Merge branch 'backblastImprovements'

This commit is contained in:
commy2 2015-02-15 15:55:27 +01:00
commit 241bcc1e4a
11 changed files with 336 additions and 151 deletions

View File

@ -1,17 +1,25 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit) );
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_FiredNear_EventHandlers {
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
class Extended_FiredBIS_EventHandlers {
class CAManBase {
class ADDON {
firedNear = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 3 >> 'ACE_Backblast_Damage') > 0}) then {_this call DFUNC(launcherBackblast)});
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> 'ACE_Backblast_Damage') > 0}) then {_this call DFUNC(fireLauncherBackblast)});
};
};
class AllVehicles {
class ADDON {
firedNear = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 3 >> 'ACE_DangerZone_Damage') > 0}) then {_this call DFUNC(tankDangerZone)});
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> 'ACE_DangerZone_Damage') > 0}) then {_this call DFUNC(fireOverpressureZone)});
};
};
};

View File

@ -0,0 +1,4 @@
#include "script_component.hpp"
["backblast", FUNC(backblastDamage)] call EFUNC(common,addEventHandler);
["overpressure", FUNC(overpressureDamage)] call EFUNC(common,addEventHandler);

View File

@ -2,8 +2,10 @@
ADDON = false;
PREP(backblastDamage);
PREP(fireLauncherBackblast);
PREP(fireOverpressureZone);
PREP(getDistance);
PREP(launcherBackblast);
PREP(tankDangerZone);
PREP(overpressureDamage);
ADDON = true;

View File

@ -6,7 +6,7 @@ class CfgPatches {
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
author[] = {"commy2","KoffeinFlummi"};
author[] = {"commy2","KoffeinFlummi","CAA-Picard"};
authorUrl = "https://github.com/commy2/";
VERSION_CONFIG;
};

View File

@ -0,0 +1,67 @@
/*
* Author: Commy2 and CAA-Picard
*
* Calculate and apply backblast damage to potentially affected local units
*
* Argument:
* 0: Unit that fired (Object)
* 1: Pos ASL of the projectile (Array)
* 2: Direction of the projectile (Array)
* 3: Weapon fired (String)
*
* Return value:
* None
*/
#include "script_component.hpp"
EXPLODE_4_PVT(_this,_firer,_posASL,_direction,_weapon);
private ["_backblastAngle","_backblastRange","_backblastDamage"];
_backblastAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Angle") / 2;
_backblastRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Range");
_backblastDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Damage");
TRACE_4("Parameters:",_backblastAngle,_backblastRange,_backblastDamage,_weapon);
_pos = _posASL;
if (!surfaceIsWater _pos) then {
_pos = ASLtoATL _pos;
};
_affected = _pos nearEntities ["CAManBase", _backblastRange];
{
_unit = _x;
if (local _unit && _unit != _firer && vehicle _unit == _unit) then {
_targetPositionASL = eyePos _unit;
_relativePosition = _targetPositionASL vectorDiff _posASL;
_axisDistance = _relativePosition vectorDotProduct _direction;
_distance = vectorMagnitude _relativePosition;
_angle = acos (_axisDistance / _distance);
_line = [_posASL, _targetPositionASL, _firer, _unit];
_line2 = [_posASL, _targetPositionASL];
TRACE_4("Affected:",_unit,_axisDistance,_distance,_angle);
if (_angle < _backblastAngle && {_distance < _backblastRange} && {!lineIntersects _line} && {!terrainIntersectASL _line2}) then {
_alpha = sqrt (1 - _distance / _backblastRange);
_beta = sqrt (1 - _angle / _backblastAngle);
_damage = 2 * _alpha * _beta * _backblastDamage;
// If the target is the ACE_player
if (_unit == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect};
// TODO: Sort this interaction with medical
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then {
[_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage);
_unit spawn {
sleep 0.5;
[_this, "", 0, objNull, objNull] call EFUNC(medical,handleDamage);
};
} else {
_unit setDamage (damage _unit + _damage);
};
};
};
} forEach _affected;

View File

@ -0,0 +1,91 @@
/*
* Author: Commy2 and CAA-Picard
*
* Handle fire of local launchers
*
* Argument:
* 0: Unit that fired (Object)
* 1: Weapon fired (String)
* 2: Muzzle (String)
* 3: Mode (String)
* 4: Ammo (String)
* 5: Magazine (String)
* 6: Projectile (Object)
*
* Return value:
* None
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
EXPLODE_7_PVT(_this,_firer,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile);
// Prevent AI from causing backblast damage
if !([_firer] call EFUNC(common,isPlayer)) exitWith {};
private ["_position","_direction","_distance","_alpha","_beta","_damage","_affected"];
_position = getPosASL _projectile;
_direction = [0, 0, 0] vectorDiff (vectorDir _projectile);
private ["_backblastAngle","_backblastRange","_backblastDamage"];
_backblastAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Angle") / 2;
_backblastRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Range");
_backblastDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Damage");
// Damage to others
_affected = getPos _projectile nearEntities ["CAManBase", _backblastRange];
// Let each client handle their own affected units
["backblast", _affected, [_firer,_position,_direction,_weapon]] call EFUNC(common,targetEvent);
// Damage to the firer
_distance = [_position, _direction, _backblastRange] call FUNC(getDistance);
TRACE_1("Distance", _distance);
if (_distance < _backblastRange) then {
_alpha = sqrt (1 - _distance / _backblastRange);
_beta = sqrt 0.5;
_damage = 2 * _alpha * _beta * _backblastDamage;
[_damage * 100] call BIS_fnc_bloodEffect;
// TODO: Sort this interaction with medical
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then {
[_firer, "HitBody", ([_firer, "", ((_firer getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage);
} else {
_firer setDamage (damage _firer + _damage);
};
};
// Draw debug lines
#ifdef DEBUG_MODE_FULL
[ _position,
_position vectorAdd (_direction vectorMultiply _backblastRange),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
_ref = _direction call EFUNC(common,createOrthonormalReference);
[ _position,
_position vectorAdd (_direction vectorMultiply _backblastRange) vectorAdd ((_ref select 1) vectorMultiply _backblastRange * tan _backblastAngle),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
[ _position,
_position vectorAdd (_direction vectorMultiply _backblastRange) vectorDiff ((_ref select 1) vectorMultiply _backblastRange * tan _backblastAngle),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
[ _position,
_position vectorAdd (_direction vectorMultiply _backblastRange) vectorAdd ((_ref select 2) vectorMultiply _backblastRange * tan _backblastAngle),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
[ _position,
_position vectorAdd (_direction vectorMultiply _backblastRange) vectorDiff ((_ref select 2) vectorMultiply _backblastRange * tan _backblastAngle),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
[ _position,
_position vectorAdd (_direction vectorMultiply (_distance min _backblastRange)),
[1,0,0,1]
] call EFUNC(common,addLineToDebugDraw);
#endif

View File

@ -0,0 +1,65 @@
/*
* Author: Commy2 and CAA-Picard
*
* Handle fire of local vehicle weapons creating overpressure zones
*
* Argument:
* 0: Unit that fired (Object)
* 1: Weapon fired (String)
* 2: Muzzle (String)
* 3: Mode (String)
* 4: Ammo (String)
* 5: Magazine (String)
* 6: Projectile (Object)
*
* Return value:
* None
*///#define DEBUG_MODE_FULL
#include "script_component.hpp"
EXPLODE_7_PVT(_this,_firer,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile);
// Prevent AI from causing backblast damage
if !([gunner _firer] call EFUNC(common,isPlayer)) exitWith {};
private ["_position","_direction","_distance","_alpha","_beta","_damage","_affected"];
_position = getPosASL _projectile;
_direction = vectorDir _projectile;
private ["_dangerZoneAngle","_dangerZoneRange","_dangerZoneDamage"];
_dangerZoneAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Angle") / 2;
_dangerZoneRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Range");
_dangerZoneDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Damage");
// Damage to others
_affected = getPos _projectile nearEntities ["CAManBase", _dangerZoneRange];
// Let each client handle their own affected units
["overpressure", _affected, [_firer,_position,_direction,_weapon]] call EFUNC(common,targetEvent);
// Draw debug lines
#ifdef DEBUG_MODE_FULL
[ _position,
_position vectorAdd (_direction vectorMultiply _dangerZoneRange),
[1,0,0,1]
] call EFUNC(common,addLineToDebugDraw);
_ref = _direction call EFUNC(common,createOrthonormalReference);
[ _position,
_position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorAdd ((_ref select 1) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
[ _position,
_position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorDiff ((_ref select 1) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
[ _position,
_position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorAdd ((_ref select 2) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
[ _position,
_position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorDiff ((_ref select 2) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle),
[1,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
#endif

View File

@ -1,31 +1,40 @@
// by commy2
/*
* Author: Commy2 and CAA-Picard
*
* Calculate the distance to the first intersection of a line
*
* Argument:
* 0: Pos ASL of origin (Array)
* 1: Direction (Array)
* 2: Max distance to search (Number)
*
* Return value:
* Distance to intersection (+- 0.1 m)
*/
#include "script_component.hpp"
private ["_position", "_direction", "_maxDistance", "_distance", "_iteration", "_laser", "_line"];
private ["_distance", "_interval", "_line", "_line"];
_position = + _this select 0;
_direction = + _this select 1;
_maxDistance = _this select 2;
EXPLODE_3_PVT(_this,_posASL,_direction,_maxDistance);
_distance = _maxDistance;
_iteration = _distance;
_laser = [];
_line = [_position, _laser];
_interval = _distance;
_line = [_posASL, []];
while {
_iteration > 0.1
_interval > 0.1
} do {
_iteration = _iteration / 2;
_interval = _interval / 2;
_laser set [0, (_position select 0) - _distance * (_direction select 0)];
_laser set [1, (_position select 1) - _distance * (_direction select 1)];
_laser set [2, (_position select 2) - _distance * (_direction select 2)];
_line set [1, _posASL vectorAdd (_direction vectorMultiply _distance)];
_intersections = {
_x isKindOf "Static" || {_x isKindOf "AllVehicles"}
} count (lineIntersectsWith _line);
_intersections = {
_x isKindOf "Static" || {_x isKindOf "AllVehicles"}
} count (lineIntersectsWith _line);
_distance = _distance + ([1, -1] select (_intersections > 0)) * _iteration;
_distance = _distance + ([1, -1] select (_intersections > 0 || {terrainIntersectASL _line})) * _interval;
if (_distance > _maxDistance) exitWith {_distance = 999};
};
if (_distance > _maxDistance) then {999} else {_distance}
_distance

View File

@ -1,72 +0,0 @@
// by commy2
#include "script_component.hpp"
_unit = _this select 0;
_firer = _this select 1;
_distance = _this select 2;
_weapon = _this select 3;
if (vehicle _unit != _unit || {!([_firer] call EFUNC(common,isPlayer))}) exitWith {};
_backblastAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Angle") / 2;
_backblastRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Range");
_backblastDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Damage");
_position = eyePos _firer;
_direction = _firer weaponDirection currentWeapon _firer;
if (_unit == _firer) then {
_distance = [_position, _direction, _backblastRange] call FUNC(getDistance);
hint format ["%1", _distance];
if (_distance < _backblastRange) then {
_alpha = sqrt (1 - _distance / _backblastRange);
_beta = sqrt 0.5;
_damage = 2 * _alpha * _beta * _backblastDamage;
[_damage * 100] call BIS_fnc_bloodEffect;
// TODO: Sort this interaction with medical
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then {
[_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage);
} else {
_unit setDamage (damage _unit + _damage);
};
};
} else {
_direction = [0, 0, 0] vectorDiff _direction;
_azimuth = (_direction select 0) atan2 (_direction select 1);
_inclination = asin (_direction select 2);
_relativePosition = eyePos _unit;
_relativeDirection = _relativePosition vectorDiff _position;
_relativeAzimuth = (_relativeDirection select 0) atan2 (_relativeDirection select 1);
_relativeInclination = asin (_relativeDirection select 2);
_angle = sqrt ((_relativeAzimuth - _azimuth) ^ 2 + (_relativeInclination - _inclination) ^ 2);
_distance = vectorMagnitude _relativeDirection;
_line = [_position, _relativePosition];
if (_angle < _backblastAngle && {_distance < _backblastRange} && {!lineIntersects _line} && {!terrainIntersectASL _line}) then {
_alpha = sqrt (1 - _distance / _backblastRange);
_beta = sqrt (1 - _angle / _backblastAngle);
_damage = 2 * _alpha * _beta * _backblastDamage;
if (_unit == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect};
// TODO: Sort this interaction with medical
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then {
[_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage);
_unit spawn {
sleep 0.5;
[_this, "", 0, objNull, objNull] call EFUNC(medical,handleDamage);
};
} else {
_unit setDamage (damage _unit + _damage);
};
};
};

View File

@ -0,0 +1,65 @@
/*
* Author: Commy2 and CAA-Picard
*
* Calculate and apply overpressure damage to potentially affected local units
*
* Argument:
* 0: Unit that fired (Object)
* 1: Pos ASL of the projectile (Array)
* 2: Direction of the projectile (Array)
* 3: Weapon fired (String)
*
* Return value:
* None
*/
#include "script_component.hpp"
EXPLODE_4_PVT(_this,_firer,_posASL,_direction,_weapon);
private ["_dangerZoneAngle","_dangerZoneRange","_dangerZoneDamage"];
_dangerZoneAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Angle") / 2;
_dangerZoneRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Range");
_dangerZoneDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Damage");
TRACE_4("Parameters:",_dangerZoneAngle,_dangerZoneRange,_dangerZoneDamage,_weapon);
_pos = _posASL;
if (!surfaceIsWater _pos) then {
_pos = ASLtoATL _pos;
};
_affected = _pos nearEntities ["CAManBase", _dangerZoneRange];
{
_unit = _x;
if (local _unit && _unit != _firer && vehicle _unit == _unit) then {
_targetPositionASL = eyePos _unit;
_relativePosition = _targetPositionASL vectorDiff _posASL;
_axisDistance = _relativePosition vectorDotProduct _direction;
_distance = vectorMagnitude _relativePosition;
_angle = acos (_axisDistance / _distance);
_line = [_posASL, _targetPositionASL, _firer, _unit];
_line2 = [_posASL, _targetPositionASL];
TRACE_4("Affected:",_unit,_axisDistance,_distance,_angle);
if (_angle < _dangerZoneAngle && {_distance < _dangerZoneRange} && {!lineIntersects _line} && {!terrainIntersectASL _line2}) then {
_alpha = sqrt (1 - _distance / _dangerZoneRange);
_beta = sqrt (1 - _angle / _dangerZoneAngle);
_damage = 2 * _alpha * _beta * _dangerZoneDamage;
// If the target is the ACE_player
if (_unit == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect};
// @todo: Sort this interaction with medical
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then {
[_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage);
_unit spawn {
sleep 0.5;
[_this, "", 0, objNull, objNull] call EFUNC(medical,handleDamage);
};
} else {
_unit setDamage (damage _unit + _damage);
};
};
};
} forEach _affected;

View File

@ -1,54 +0,0 @@
// by commy2
#include "script_component.hpp"
#define BARREL_MUZZLE "usti hlavne"
_unit = _this select 0;
_vehicle = vehicle (_this select 1);
_distance = _this select 2;
_weapon = _this select 3;
if (vehicle _unit != _unit || {!([gunner _firer] call EFUNC(common,isPlayer))}) exitWith {};
_dangerZoneAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Angle") / 2;
_dangerZoneRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Range");
_dangerZoneDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Damage");
_position = ATLToASL (_vehicle modelToWorld (_vehicle selectionPosition BARREL_MUZZLE));
_direction = _vehicle weaponDirection _weapon;
if (_unit != _vehicle) then {
_azimuth = (_direction select 0) atan2 (_direction select 1);
_inclination = asin (_direction select 2);
_relativePosition = eyePos _unit;
_relativeDirection = _relativePosition vectorDiff _position;
_relativeAzimuth = (_relativeDirection select 0) atan2 (_relativeDirection select 1);
_relativeInclination = asin (_relativeDirection select 2);
_angle = sqrt ((_relativeAzimuth - _azimuth) ^ 2 + (_relativeInclination - _inclination) ^ 2);
_distance = vectorMagnitude _relativeDirection;
_line = [_position, _relativePosition];
if (_angle < _dangerZoneAngle && {_distance < _dangerZoneRange} && {!lineIntersects (_line + [_vehicle])} && {!terrainIntersectASL _line}) then {
_alpha = sqrt (1 - _distance / _dangerZoneRange);
_beta = sqrt (1 - _angle / _dangerZoneAngle);
_damage = 2 * _alpha * _beta * _dangerZoneDamage;
if (_unit == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect};
// TODO: Sort this interaction with medical
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then {
[_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage);
_unit spawn {
sleep 0.5;
[_this, "", 0, objNull, objNull] call EFUNC(medical,handleDamage);
};
} else {
_unit setDamage (damage _unit + _damage);
};
};
};