Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Posibility to Change Backblast Values in Magazine Config and Add Caching for Backblast #1832

Closed
wants to merge 14 commits into from
14 changes: 7 additions & 7 deletions addons/overpressure/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@ class Extended_PostInit_EventHandlers {
class Extended_FiredBIS_EventHandlers {
class CAManBase {
class ADDON {
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> QUOTE(QGVAR(Damage))) > 0}) then {_this call DFUNC(fireLauncherBackblast)});
firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHBB);};);
};
};

class Tank {
class ADDON {
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> QUOTE(QGVAR(Damage))) > 0}) then {_this call DFUNC(fireOverpressureZone)});
firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};);
};
};
class Car {
class ADDON {
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> QUOTE(QGVAR(Damage))) > 0}) then {_this call DFUNC(fireOverpressureZone)});
firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};);
};
};
class Helicopter {
class ADDON {
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> QUOTE(QGVAR(Damage))) > 0}) then {_this call DFUNC(fireOverpressureZone)});
firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};);
};
};
class Plane {
class ADDON {
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> QUOTE(QGVAR(Damage))) > 0}) then {_this call DFUNC(fireOverpressureZone)});
firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};);
};
};
class Ship_F {
class ADDON {
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> QUOTE(QGVAR(Damage))) > 0}) then {_this call DFUNC(fireOverpressureZone)});
firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};);
};
};
class StaticWeapon {
class ADDON {
firedBIS = QUOTE(if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> QUOTE(QGVAR(Damage))) > 0}) then {_this call DFUNC(fireOverpressureZone)});
firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};);
};
};
};
7 changes: 7 additions & 0 deletions addons/overpressure/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class CfgWeapons {

class LauncherCore;
class Launcher: LauncherCore {
GVAR(priority) = 1;
GVAR(angle) = 60;
GVAR(range) = 10;
GVAR(damage) = 0.7;
Expand All @@ -11,39 +12,45 @@ class CfgWeapons {
class Launcher_Base_F: Launcher {};

class launch_Titan_base: Launcher_Base_F {
GVAR(priority) = 1;
GVAR(angle) = 40;
GVAR(range) = 8;
GVAR(damage) = 0.5;
};

class launch_Titan_short_base: launch_Titan_base {
// Titan is a soft-launch launcher
GVAR(priority) = 1;
GVAR(angle) = 30;
GVAR(range) = 2;
GVAR(damage) = 0.5;
};

class launch_NLAW_F: Launcher_Base_F {
// NLAW is a soft-launch launcher
GVAR(priority) = 1;
GVAR(angle) = 30;
GVAR(range) = 2;
GVAR(damage) = 0.6;
};

class launch_RPG32_F: Launcher_Base_F {
GVAR(priority) = 1;
GVAR(angle) = 60;
GVAR(range) = 15;
GVAR(damage) = 0.7;
};

class CannonCore;
class cannon_120mm: CannonCore {
GVAR(priority) = 1;
GVAR(angle) = 90;
GVAR(range) = 50;
GVAR(damage) = 0.85;
};

class mortar_155mm_AMOS: CannonCore {
GVAR(priority) = 1;
GVAR(angle) = 90;
GVAR(range) = 60;
GVAR(damage) = 1;
Expand Down
4 changes: 3 additions & 1 deletion addons/overpressure/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ PREP(fireLauncherBackblast);
PREP(fireOverpressureZone);
PREP(getDistance);
PREP(overpressureDamage);

PREP(cacheOverPressureValues);
PREP(firedEHOP);
PREP(firedEHBB);
ADDON = true;
76 changes: 76 additions & 0 deletions addons/overpressure/functions/fnc_cacheOverPressureValues.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Author: joko // Jonas
*
* Handle fire of local launchers
*
* Argument:
* 0: Weapon <STRING>
* 1: Magazine <STRING>
* 2: Ammo <STRING>
*
* Return value:
* Array:
* 0: Angle <Number>
* 1: Range <Number>
* 2: Damage <Number>
*
*/
#include "script_component.hpp"

params ["_weapon", "_ammo", "_magazine"];
TRACE_3("Parameter",_weapon,_magazine,_ammo);

private ["_array", "_type", "_return", "_config" /*, "_priority"*/];

// get Priority Array from Config
_array = [
getNumber (configFile >> "CfgWeapons" >> QGVAR(priority)),
getNumber (configFile >> "CfgMagazines" >> QGVAR(priority)),
getNumber (configFile >> "CfgAmmo" >> QGVAR(priority))
];

TRACE_1("Proiroity Array",_array);

/* for CBA Upadte 2.1
_priority = _array call CBA_fnc_findMax;
_type = if (isNil "_priority") then {
0
} else {
_priority select 1
};
*/

// obsolete as CBA Update 2.1 start
_array params ["_max"];

// set Default type
_type = 0;
// get Highest Entry out the the Priority Array
{
if (_max < _x) then {
_max = _x;
_type = _forEachIndex;
};
} forEach _array;
// obsolete end

TRACE_2("Highest Value",_max,_type);
// create the Config entry Point
_config = [
(configFile >> "CfgWeapons" >> _weapon),
(configFile >> "CfgMagazines" >> _magazine),
(configFile >> "CfgAmmo" >> _ammo)
] select _type;
TRACE_1("ConfigPath",_config);

// get the Variables out of the Configes and create a array with then
_return = [
(getNumber (_config >> QGVAR(angle))),
(getNumber (_config >> QGVAR(range))),
(getNumber (_config >> QGVAR(damage)))
];
TRACE_1("Return",_return);
_varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine];
missionNameSpace setVariable [format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine], _return];

_return
33 changes: 19 additions & 14 deletions addons/overpressure/functions/fnc_fireLauncherBackblast.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
*
* 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)
* Arguments:
* 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);
params ["_firer", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile"];

// Prevent AI from causing backblast damage
if !([_firer] call EFUNC(common,isPlayer)) exitWith {};
Expand All @@ -28,11 +28,16 @@ private ["_position", "_direction"];
_position = getPosASL _projectile;
_direction = [0, 0, 0] vectorDiff (vectorDir _projectile);

private ["_backblastAngle", "_backblastRange", "_backblastDamage"];
private ["_var","_varName","_backblastAngle", "_backblastRange", "_backblastDamage"];
// Bake variable name and check if the variable exists, call the caching function otherwise
_varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine];
_var = if (isNil _varName) then {
[_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues);
} else {
missionNameSpace getVariable _varName;
};
_var params["_backblastAngle","_backblastRange","_backblastDamage"];

_backblastAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(angle)) / 2;
_backblastRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(range));
_backblastDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(damage));

// Damage to others
private "_affected";
Expand Down
34 changes: 19 additions & 15 deletions addons/overpressure/functions/fnc_fireOverpressureZone.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
*
* 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)
* Arguments:
* 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);

params ["_firer", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile"];
// Prevent AI from causing overpressure damage
if !([gunner _firer] call EFUNC(common,isPlayer)) exitWith {}; //@todo non-maingun turrets?

Expand All @@ -28,18 +27,23 @@ private ["_position", "_direction"];
_position = getPosASL _projectile;
_direction = vectorDir _projectile;

private ["_dangerZoneAngle", "_dangerZoneRange", "_dangerZoneDamage"];
private ["_var", "_varName", "_dangerZoneAngle", "_dangerZoneRange", "_dangerZoneDamage"];

_dangerZoneAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(angle)) / 2;
_dangerZoneRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(range));
_dangerZoneDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(damage));
// Bake variable name and check if the variable exists, call the caching function otherwise
_varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine];
_var = if (isNil _varName) then {
[_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues);
} else {
missionNameSpace getVariable _varName;
};
_var params["_dangerZoneAngle","_dangerZoneRange","_dangerZoneDamage"];

// Damage to others
private "_affected";
_affected = getPos _projectile nearEntities ["CAManBase", _dangerZoneRange];

// Let each client handle their own affected units
["overpressure", _affected, [_firer, _position, _direction, _weapon]] call EFUNC(common,targetEvent);
["overpressure", _affected, [_firer, _position, _direction, _weapon, _magazine, _ammo]] call EFUNC(common,targetEvent);

// Draw debug lines
#ifdef DEBUG_MODE_FULL
Expand Down
32 changes: 32 additions & 0 deletions addons/overpressure/functions/fnc_firedEHBB.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Author: joko // Jonas
*
* Handle fire of local launchers
*
* Arguments:
* 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
*/
#include "script_component.hpp"
private ["_damage","_varName"];
params ["", "_weapon", "", "", "_ammo", "_magazine", ""];

// Bake variable name and check if the variable exists, call the caching function otherwise
_varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine];
_damage = if (isNil _varName) then {
([_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues)) select 2;
} else {
(missionNameSpace getVariable _varName) select 2;
};

if (_damage > 0) then {
_this call DFUNC(fireLauncherBackblast)
};
32 changes: 32 additions & 0 deletions addons/overpressure/functions/fnc_firedEHOP.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Author: joko // Jonas
*
* Handle fire of Other Weapons
*
* Arguments:
* 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
*/
#include "script_component.hpp"
private ["_damage","_varName"];
params ["", "_weapon", "", "", "_ammo", "_magazine", ""];

// Bake variable name and check if the variable exists, call the caching function otherwise
_varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine];
_damage = if (isNil _varName) then {
([_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues)) select 2;
} else {
(missionNameSpace getVariable _varName) select 2;
};

if (_damage > 0) then {
_this call DFUNC(fireOverpressureZone)
};
10 changes: 5 additions & 5 deletions addons/overpressure/functions/fnc_getDistance.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* 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)
* Arguments:
* 0: Pos ASL of origin (ARRAY>
* 1: Direction <ARRAY>
* 2: Max distance to search <Number>
*
* Return value:
* Distance to intersection (+- 0.1 m)
* Distance to intersection (+- 0.1 m) <NUMBER>
*/
#include "script_component.hpp"

Expand Down
Loading