ACE3/addons/frag/functions/fnc_findReflections.sqf

127 lines
4.6 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
/*
* Author: ACE-Team
*
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* call ace_frag_fnc_findReflections
*
* Public: No
*/
2016-05-30 16:37:03 +00:00
BEGIN_COUNTER(fnc_findReflections);
params ["_args", "_pfhID"];
_args params ["_pos", "_explosiveInfo", "_los", "_nlos", "_zIndex", "_depth", "_rand"];
2016-05-30 16:37:03 +00:00
private _split = 15;
private _radi = 360 / _split * _depth;
2016-05-30 16:37:03 +00:00
// player sideChat format ["p: %1", _explosiveInfo];
_explosiveInfo params ["_indirectHitRange", "_indirectHit"];
private _distanceCount = (floor _indirectHitRange * 4) min 100;
2016-05-30 16:37:03 +00:00
if (_zIndex < 5) then {
private _lastPos = _pos;
private _zAng = _zIndex * 20 + 2;
if (_zAng > 80) then {
2016-05-30 16:37:03 +00:00
_radi = 1;
_zAng = 90;
};
for "_i" from 0 to _radi do {
private _test = true;
private _vec = [1, ((_i * _split) + _rand) % 360, _zAng] call CBA_fnc_polar2vect;
2016-05-30 16:37:03 +00:00
for "_x" from 1 to _distanceCount do {
private _testPos = _pos vectorAdd (_vec vectorMultiply _x);
2016-05-30 16:37:03 +00:00
// drop ["\a3\data_f\Cl_basic","","Billboard",1,15,ASLtoATL _testPos,[0,0,0],1,1.275,1.0,0.0,[1],[[1,0,0,1]],[0],0.0,2.0,"","",""];
private _res = lineIntersectsWith [_pos, _testPos];
if (count _res > 0) exitWith {
2016-05-30 16:37:03 +00:00
_test = false;
_nlos pushBack _lastPos;
// {
// _x addEventHandler ["HandleDamage", { diag_log text format ["this: %1", _this]; }];
2016-05-30 16:37:03 +00:00
// } forEach _res;
// drop ["\a3\data_f\Cl_basic","","Billboard",1,15,ASLtoATL _testPos,[0,0,0],1,1.275,1.0,0.0,[1],[[1,0,0,1]],[0],0.0,2.0,"","",""];
// TEST_PAIRS pushBack [_pos, _lastPos, [1,0,0,1]];
};
// if (terrainIntersectASL [_pos, _testPos]) exitWith {};
2016-05-30 16:37:03 +00:00
_lastPos = _testPos;
};
};
_args set [4, _zIndex + 1];
2016-05-30 16:37:03 +00:00
} else {
INC(_depth);
private _buckets = [];
private _excludes = [];
private _bucketPos = nil;
private _bucketList = nil;
private _c = 0;
while {count _nlos != count _excludes && {_c < (count _nlos)}} do {
2016-05-30 16:37:03 +00:00
scopeName "mainSearch";
{
if (!(_forEachIndex in _excludes)) then {
private _index = _buckets pushBack [_x, [_x]];
2016-05-30 16:37:03 +00:00
_excludes pushBack _forEachIndex;
_bucketPos = _x;
_bucketList = (_buckets select _index) select 1;
breakTo "mainSearch";
};
} forEach _nlos;
{
if (!(_forEachIndex in _excludes)) then {
2016-05-30 16:37:03 +00:00
_testPos = _x;
if (_testPos vectorDistanceSqr _bucketPos <= 30) then {
2016-05-30 16:37:03 +00:00
_bucketList pushBack _x;
_excludes pushBack _forEachIndex;
};
};
} forEach _nlos;
INC(_c);
2016-05-30 16:37:03 +00:00
};
// player sideChat format ["c: %1", count _buckets];
private _explosions = [];
2016-05-30 16:37:03 +00:00
{
private _blist = _x select 1;
private _avg = [0, 0, 0];
2016-05-30 16:37:03 +00:00
{
_avg = _avg vectorAdd _x;
2016-05-30 16:37:03 +00:00
} forEach _blist;
_c = count _blist;
private _bpos = _avg vectorMultiply (1 / _c);
2016-05-30 16:37:03 +00:00
private _distance = _pos vectorDistance _bpos;
private _hitFactor = 1 - (((_distance / (_indirectHitRange * 4)) min 1) max 0);
// _hitFactor = 1 / (_distance ^ 2);
private _hit = (floor (_indirectHit * _hitFactor / 4)) min 500;
SUB(_hit,_hit % 10);
private _range = (floor (_indirectHitRange - (_distance / 4))) min 100;
SUB(_range,_range % 2);
2016-05-30 16:37:03 +00:00
if (_hit >= 10 && {_range > 0}) then {
// TEST_ICONS pushBack [_bpos, format ["h: %1, r: %2, hf: %3 d: %4 ihr: %5", _hit, _range, _hitFactor, _distance, _indirectHitRange*4]];
2016-05-30 16:37:03 +00:00
// TEST_PAIRS pushBack [_pos, _bpos, [1,0,0,1]];
private _refExp = format ["ace_explosion_reflection_%1_%2", _range, _hit];
2016-05-30 16:37:03 +00:00
// _refExp createVehicle (ASLtoATL _bpos);
// drop ["\a3\data_f\Cl_basic","","Billboard",1,15,ASLtoATL _bpos,[0,0,0],1,1.275,1.0,0.0,[1],[[1,0,0,1]],[0],0.0,2.0,"","",""];
_explosions pushBack [_refExp, _bpos, _hit, _distance, _indirectHitRange / 4, _depth];
2016-05-30 16:37:03 +00:00
};
if (count _explosions > (_radi * 2) / _depth) exitWith {};
2016-05-30 16:37:03 +00:00
} forEach _buckets;
// _can = "Land_Bricks_V4_F" createVehicle (ASLtoATL _pos);
// _dirvec = _pos vectorFromTo ((ATLtoASL (player modelToWorldVisual (player selectionPosition "Spine3"))));
// _dirvec = _dirvec vectorMultiply 100;
// _can setVelocity _dirvec;
[DFUNC(doExplosions), 0, [_explosions, 0]] call CBA_fnc_addPerFrameHandler;
[_pfhID] call CBA_fnc_removePerFrameHandler;
2016-05-30 16:37:03 +00:00
};
END_COUNTER(fnc_findReflections);