ACE3/addons/overpressure/functions/fnc_overpressureDamage.sqf
Dedmen Miller e2ac18a05d [WIP] Fix script errors reporting wrong line numbers (#6407)
* advanced_ballistics

* advanced_fatigue

* advanced_throwing

* ai

* aircraft

* arsenal

* atragmx

* attach

* backpacks

* ballistics

* captives

* cargo

* chemlights

* common

* concertina_wire

* cookoff

* dagr

* disarming

* disposable

* dogtags

* dragging

* explosives

* fastroping

* fcs

* finger

* frag

* gestures

* gforces

* goggles

* grenades

* gunbag

* hearing

* hitreactions

* huntir

* interact_menu

* interaction

* inventory

* kestrel4500

* laser

* laserpointer

* logistics_uavbattery

* logistics_wirecutter

* magazinerepack

* map

* map_gestures

* maptools

* markers

* medical

* medical_ai

* medical_blood

* medical_menu

* microdagr

* minedetector

* missileguidance

* missionmodules

* mk6mortar

* modules

* movement

* nametags

* nightvision

* nlaw

* optics

* optionsmenu

* overheating

* overpressure

* parachute

* pylons

* quickmount

* rangecard

* rearm

* recoil

* refuel

* reload

* reloadlaunchers

* repair

* respawn

* safemode

* sandbag

* scopes

* slideshow

* spectator

* spottingscope

* switchunits

* tacticalladder

* tagging

* trenches

* tripod

* ui

* vector

* vehiclelock

* vehicles

* viewdistance

* weaponselect

* weather

* winddeflection

* yardage450

* zeus

* arsenal defines.hpp

* optionals

* DEBUG_MODE_FULL 1

* DEBUG_MODE_FULL 2

* Manual fixes

* Add SQF Validator check for #include after block comment

* explosives fnc_openTimerUI

* fix uniqueItems
2018-09-17 14:19:29 -05:00

77 lines
3.0 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: commy2 and esteldunedain
* Calculate and apply backblast damage to potentially affected local units
* Handles the "overpressure" event.
*
* Arguments:
* 0: Unit that fired <OBJECT>
* 1: Pos ASL of the projectile <ARRAY>
* 2: Direction of the projectile (reversed for launcher backblast) <ARRAY>
* 3: Weapon fired <STRING>
* 4: Magazine <STRING>
* 5: Ammo <STRING>
*
* Return Value:
* None
*
* Example:
* [tank, [1727.57,5786.15,7.24899], [-0.982474,-0.185998,-0.0122501], "cannon_125mm", "24Rnd_125mm_APFSDS_T_Green", "Sh_125mm_APFSDS_T_Green"] call ace_overpressure_fnc_overpressureDamage
*
* Public: No
*/
params ["_firer", "_posASL", "_direction", "_weapon", "_magazine", "_ammo"];
// Bake variable name and check if the variable exists, call the caching function otherwise
private _varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine];
private _var = if (isNil _varName) then {
[_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues);
} else {
missionNameSpace getVariable _varName;
};
_var params ["_overpressureAngle","_overpressureRange","_overpressureDamage"];
TRACE_3("cache",_overpressureAngle,_overpressureRange,_overpressureDamage);
{
if (local _x && {_x != _firer} && {vehicle _x == _x}) then {
private _targetPositionASL = eyePos _x;
private _relativePosition = _targetPositionASL vectorDiff _posASL;
private _axisDistance = _relativePosition vectorDotProduct _direction;
private _distance = vectorMagnitude _relativePosition;
private _angle = acos (_axisDistance / _distance);
private _line = [_posASL, _targetPositionASL, _firer, _x];
private _line2 = [_posASL, _targetPositionASL];
TRACE_4("Affected:",_x,_axisDistance,_distance,_angle);
if (_angle < _overpressureAngle && {_distance < _overpressureRange} && {!lineIntersects _line} && {!terrainIntersectASL _line2}) then {
private _alpha = sqrt (1 - _distance / _overpressureRange);
private _beta = sqrt (1 - _angle / _overpressureAngle);
private _damage = _alpha * _beta * _overpressureDamage;
TRACE_1("",_damage);
// If the target is the ACE_player
if (_x == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect};
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical") && {([_x] call EFUNC(medical,hasMedicalEnabled))}) then {
[_x, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit);
} else {
TRACE_1("",isDamageAllowed _x);
if (!isDamageAllowed _x) exitWith {}; // Skip damage if not allowed
_x setDamage (damage _x + _damage);
};
#ifdef DEBUG_MODE_FULL
//Shows damage lines in green
[ _posASL,
_targetPositionASL,
[0,1,0,1]
] call EFUNC(common,addLineToDebugDraw);
#endif
};
};
} forEach ((ASLtoAGL _posASL) nearEntities ["CAManBase", _overpressureRange]);