Cleanup Frag Component (#4581)

* Cleanup frag component

* Optimize fnc_addTrack

* Add additional cleanup

* Please work?

* Add more cleanup

* Fix script errors

* Fix/optimize spalling

* Add missing changes
This commit is contained in:
Ozan Eğitmen 2016-10-27 01:16:31 +03:00 committed by Glowbal
parent a13441fa85
commit 49b5a0ea86
32 changed files with 441 additions and 504 deletions

View File

@ -34,7 +34,6 @@ class ACE_Settings {
typeName = "SCALAR";
value = 50;
};
class GVAR(enableDebugTrace) {
category = CSTRING(Module_DisplayName);
displayName = CSTRING(EnableDebugTrace);

View File

@ -1,6 +1,6 @@
#define BASE_DRAG -0.01
#define HD_MULT 5
#define BASE_DRAG_HD (BASE_DRAG*HD_MULT)
#define BASE_DRAG -0.01
#define HD_MULT 5
#define BASE_DRAG_HD (BASE_DRAG * HD_MULT)
class CfgAmmo {
//class ace_arty_105mm_m1_m782_time;
@ -104,10 +104,8 @@ class CfgAmmo {
GVAR(gurney_k) = 1/2;
};
class ACE_G_40mm_HEDP: G_40mm_HEDP {
};
class ACE_G_40mm_HE: G_40mm_HE {
};
class ACE_G_40mm_HEDP: G_40mm_HEDP {};
class ACE_G_40mm_HE: G_40mm_HE {};
class ACE_G_40mm_Practice: ACE_G_40mm_HE {
GVAR(skip) = 1;
GVAR(force) = 0;
@ -438,8 +436,6 @@ class CfgAmmo {
indirectHitRange = 0.25;
airFriction = BASE_DRAG_HD*0.65;
caliber = 2;
};
class GVAR(huge): GVAR(large) {

View File

@ -1,5 +1,3 @@
//CfgAmmoReflections.hpp
#define ACE_EXPLOSION_REFLECTION(range, hit)\
class ace_explosion_reflection_##range##_##hit : ace_explosion_reflection_base {\
indirectHitRange = range;\

View File

@ -1,4 +1,3 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));

View File

@ -22,7 +22,6 @@ PREP(addPfhRound);
PREP(removePfhRound); // THIS SHOULD ABE USED SPARINGLY
// Explosive Reflection
GVAR(replacedBisArtyWrapper) = true;
PREP(findReflections);
PREP(doExplosions);
PREP(doReflections);

View File

@ -1,16 +1,15 @@
#include "script_component.hpp"
if(GVAR(EnableDebugTrace) && !isMultiplayer) then {
if (GVAR(EnableDebugTrace) && {!isMultiplayer}) then {
GVAR(traceFrags) = true;
GVAR(autoTrace) = true;
};
if(isServer) then {
[QGVAR(frag_eh), { _this call FUNC(frago); }] call CBA_fnc_addEventHandler;
if (isServer) then {
[QGVAR(frag_eh), {_this call FUNC(frago);}] call CBA_fnc_addEventHandler;
};
["ace_settingsInitialized", {
//If not enabled, exit
if (!GVAR(enabled)) exitWith {};
// Register fire event handler
@ -20,9 +19,8 @@ if(isServer) then {
["ace_firedNonPlayerVehicle", DFUNC(fired)] call CBA_fnc_addEventHandler;
[FUNC(masterPFH), 0, []] call CBA_fnc_addPerFrameHandler;
}] call CBA_fnc_addEventHandler;
//Cache for ammo type configs
GVAR(cacheRoundsTypesToTrack) = createLocation ["ACE_HashLocation", [-10000,-10000,-10000], 0, 0];
// Cache for ammo type configs
GVAR(cacheRoundsTypesToTrack) = createLocation ["ACE_HashLocation", [-10000, -10000, -10000], 0, 0];
GVAR(cacheRoundsTypesToTrack) setText QGVAR(cacheRoundsTypesToTrack);

View File

@ -4,10 +4,11 @@ ADDON = false;
#include "XEH_PREP.hpp"
GVAR(replacedBisArtyWrapper) = true;
GVAR(blackList) = [];
GVAR(traceFrags) = false;
GVAR(TOTALFRAGS) = 0;
GVAR(totalFrags) = 0;
GVAR(spallHPData) = [];
GVAR(spallIsTrackingCount) = 0;

View File

@ -1,4 +1,5 @@
#include "script_component.hpp"
class CfgPatches {
class ADDON {
name = COMPONENT_NAME;

View File

@ -1,3 +1,5 @@
#include "script_component.hpp"
params ["_round"];
GVAR(blackList) set [(count GVAR(blackList)), _round];
GVAR(blackList) pushBack _round;

View File

@ -1,73 +1,67 @@
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
private ["_enabled", "_doSpall", "_spallTrack", "_spallTrackID"];
PARAMS_3(_gun,_type,_round);
DEFAULT_PARAM(3,_doFragTrack,false);
params ["_gun", "_type", "_round", ["_doFragTrack", false]];
if (!GVAR(enabled)) exitWith {};
//_enabled = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(enabled));
//if(_enabled < 1) exitWith {};
//if (_enabled < 1) exitWith {};
if(_round in GVAR(blackList)) exitWith {
GVAR(blackList) = GVAR(blackList) - [_round];
if (_round in GVAR(blackList)) exitWith {
REM(GVAR(blackList),_round);
};
// Exit on max track
if( (count GVAR(objects)) > GVAR(MaxTrack)) exitWith { };
if ((count GVAR(objects)) > GVAR(MaxTrack)) exitWith {};
if(_gun == ACE_player) then {
if (
_gun == ACE_player ||
{(gunner _gun) == ACE_player} ||
{local _gun && {!(isPlayer (gunner _gun))} && {!(isPlayer _gun)}}
) then {
_doFragTrack = true;
} else {
if((gunner _gun) == ACE_player) then {
_doFragTrack = true;
} else {
if(local _gun && {!(isPlayer (gunner _gun))} && {!(isPlayer _gun)}) then {
_doFragTrack = true;
};
};
};
_doSpall = false;
if(GVAR(SpallEnabled)) then {
if(GVAR(spallIsTrackingCount) <= 0) then {
private _doSpall = false;
if (GVAR(SpallEnabled)) then {
if (GVAR(spallIsTrackingCount) <= 0) then {
GVAR(spallHPData) = [];
};
if(GVAR(spallIsTrackingCount) > 5) then {
if (GVAR(spallIsTrackingCount) > 5) then {
// ACE_player sideChat "LIMT!";
} else {
_doSpall = true;
GVAR(spallIsTrackingCount) = GVAR(spallIsTrackingCount) + 1;
INC(GVAR(spallIsTrackingCount));
};
};
// ACE_player sideChat format["c: %1", GVAR(spallIsTrackingCount)];
// ACE_player sideChat format ["c: %1", GVAR(spallIsTrackingCount)];
if(GVAR(autoTrace)) then {
[ACE_player, _round, [1,0,0,1]] call FUNC(addTrack);
if (GVAR(autoTrace)) then {
[ACE_player, _round, [1, 0, 0, 1]] call FUNC(addTrack);
};
// We only do the single track object check here.
// We should do an {!(_round in GVAR(objects))}
// But we leave that out here for optimization. So this cannot be a framework function
// Otherwise, it should only be added once and from the FiredEH
if(_doFragTrack && {alive _round}) then {
_spallTrack = [];
_spallTrackID = [];
if (_doFragTrack && {alive _round}) then {
private _spallTrack = [];
private _spallTrackID = [];
private ["_args"];
_args = [_round, (getPosASL _round), (velocity _round), _type, diag_frameno, _gun, _doSpall, _spallTrack, _spallTrackID,
(getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(skip))),
(getNumber (configFile >> "CfgAmmo" >> _type >> "explosive")),
(getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange")),
(getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(force))),
(getNumber(configFile >> "CfgAmmo" >> _type >> "indirecthit")*(sqrt((getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange")))))
private _args = [
_round, getPosASL _round, velocity _round, _type, diag_frameno, _gun, _doSpall, _spallTrack, _spallTrackID,
getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(skip)),
getNumber (configFile >> "CfgAmmo" >> _type >> "explosive"),
getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange"),
getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(force)),
getNumber (configFile >> "CfgAmmo" >> _type >> "indirecthit") * (sqrt (getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange")))
];
TRACE_1("Initializing track", _round);
GVAR(objects) pushBack _round;
GVAR(arguments) pushBack _args;
if(_doSpall) then {
if (_doSpall) then {
[_round, 1, _spallTrack, _spallTrackID] call FUNC(spallTrack);
};
// ACE_player sideChat "WTF2";

View File

@ -5,16 +5,12 @@ if (GVAR(autoTrace)) then {
};
// setAccTime 0.05;
private _index = count GVAR(traces);
params ["_origin", "_obj"];
private _color = [1,0,0,1];
if((count _this) > 2) then {
_color = _this select 2;
};
params ["_origin", "_obj", ["_color", [1, 0, 0, 1]]];
private _positions = [];
private _objSpd = vectorMagnitude (velocity _obj);
_positions set[(count _positions), [(getPos _obj), _objSpd]];
_positions pushBack [getPos _obj, _objSpd];
private _data = [_origin, typeOf _origin, typeOf _obj, _objSpd, _positions, _color];
GVAR(traces) set[_index, _data];
private _index = GVAR(traces) pushBack _data;
[DFUNC(trackTrace), 0, [_obj, _index, CBA_missionTime]] call CBA_fnc_addPerFrameHandler;

View File

@ -1,7 +1,11 @@
#define DEBUG_MODE_FULL
#include "script_component.hpp"
params [["_debugMissing", true, [false]], ["_debugForce", false, [false]], ["_debugNonFrag", false, [false]]];
params [
["_debugMissing", true, [false]],
["_debugForce", false, [false]],
["_debugNonFrag", false, [false]]
];
diag_log text format ["~~~~~~~~~~~~~Start [%1]~~~~~~~~~~~~~", _this];
@ -10,7 +14,7 @@ private _processedCfgAmmos = [];
{
private _ammo = toLower getText (_x >> "ammo");
if ((_ammo != "") && {!(_ammo in _processedCfgAmmos)}) then {
if (_ammo != "" && {!(_ammo in _processedCfgAmmos)}) then {
_processedCfgAmmos pushBack _ammo;
//Ignore mines/bombs
@ -23,37 +27,37 @@ private _processedCfgAmmos = [];
private _explosive = getNumber (_ammoConfig >> "explosive");
private _indirectRange = getNumber (_ammoConfig >> "indirectHitRange");
private _force = getNumber (_ammoConfig >> QGVAR(force));
private _fragPower = getNumber(_ammoConfig >> "indirecthit")*(sqrt((getNumber (_ammoConfig >> "indirectHitRange"))));
private _fragPower = getNumber (_ammoConfig >> "indirecthit") * (sqrt ((getNumber (_ammoConfig >> "indirectHitRange"))));
private _shouldAdd = (_skip == 0) && {(_force == 1) || {_explosive > 0.5 && {_indirectRange >= 4.5} && {_fragPower >= 35}}};
if (_shouldAdd) then {
if (_debugForce && {((getNumber(_ammoConfig >> "hit")) < 5) || {_fragPower < 10}}) then {
diag_log text format ["Ammo [%1] from Mag [%2] - Weak but will still frag!",_ammo,configName _x];
diag_log text format [" - _force=%1,_fragPower=%2",_force,_fragPower];
diag_log text format ["Ammo [%1] from Mag [%2] - Weak but will still frag!", _ammo, configName _x];
diag_log text format [" - _force=%1,_fragPower=%2", _force, _fragPower];
};
_warn = false;
private _warn = false;
_fragTypes = getArray (_ammoConfig >> QGVAR(CLASSES));
if(_fragTypes isEqualTo []) then {_warn = true;};
if (_fragTypes isEqualTo []) then {_warn = true;};
_c = getNumber(_ammoConfig >> QGVAR(CHARGE));
if(_c == 0) then {_warn = true;};
if (_c == 0) then {_warn = true;};
_m = getNumber(_ammoConfig >> QGVAR(METAL));
if(_m == 0) then {_warn = true;};
if (_m == 0) then {_warn = true;};
_k = getNumber(_ammoConfig >> QGVAR(GURNEY_K));
if(_k == 0) then {_warn = true;};
if (_k == 0) then {_warn = true;};
_gC = getNumber(_ammoConfig >> QGVAR(GURNEY_C));
if(_gC == 0) then { _warn = true;};
if (_gC == 0) then {_warn = true;};
if(_debugMissing && _warn) then {
diag_log text format ["Ammo [%1] from Mag [%2] MISSING frag configs:",_ammo,configName _x];
diag_log text format [" - _c=%1,_m=%2,_k=%3,_gC=%4,_fragTypes=%5",_c,_m,_k,_gC,_fragTypes];
if (_debugMissing && {_warn}) then {
diag_log text format ["Ammo [%1] from Mag [%2] MISSING frag configs:", _ammo, configName _x];
diag_log text format [" - _c=%1,_m=%2,_k=%3,_gC=%4,_fragTypes=%5", _c, _m, _k, _gC, _fragTypes];
};
} else {
if (_debugNonFrag && {isArray (_ammoConfig >> QGVAR(CLASSES))}) then {
diag_log text format ["Ammo [%1] from Mag [%2] has frag configs but will NOT frag:",_ammo,configName _x];
diag_log text format ["- skip=%1,explosive=%2,indirectHitRange=%3,force=%4,fragPower=%5",_skip,_explosive,_indirectRange,_force,_fragPower];
diag_log text format ["Ammo [%1] from Mag [%2] has frag configs but will NOT frag:", _ammo, configName _x];
diag_log text format ["- skip=%1,explosive=%2,indirectHitRange=%3,force=%4,fragPower=%5", _skip, _explosive, _indirectRange, _force, _fragPower];
};
};
};

View File

@ -1,20 +1,22 @@
//fnc_doExplosions.sqf
#include "script_component.hpp"
params ["_args"];
params ["_args", "_pfhID"];
_args params ["_explosions", "_index"];
for "_i" from _index to ((_index+2) min (count _explosions)) do {
for "_i" from _index to ((_index + 2) min (count _explosions)) do {
private _exp = _explosions select _i;
_exp params ["_refExp", "_bpos", "_hit", "_distance", "_indirectHitRange", "_depth"];
_refExp createVehicle (ASLtoATL _bpos);
// if(_hit >= 150 && _distance > _indirectHitRange) then {
// if (_hit >= 150 && _distance > _indirectHitRange) then {
// [_bpos, _refExp, _depth] call FUNC(doReflections);
// };
};
_index = _index + 2;
if(_index >= (count _explosions)) then {
[(_this select 1)] call CBA_fnc_removePerFrameHandler;
ADD(_index,2);
if (_index >= count _explosions) then {
[_pfhID] call CBA_fnc_removePerFrameHandler;
} else {
_params set[1, _index];
_args set [1, _index];
};

View File

@ -1,14 +1,10 @@
//fnc_doReflections.sqf
#include "script_component.hpp"
params ["_pos", "_ammo"];
params ["_pos", "_ammo", ["_depth", 1]];
private _depth = 1;
if(count _this > 2) then {
_depth = _this select 2;
};
// TEST_ICONS pushBack [_pos, format["EXP!", _hit, _range, _hitFactor]];
if(_depth <= 2) then {
// TEST_ICONS pushBack [_pos, format ["EXP!", _hit, _range, _hitFactor]];
if (_depth <= 2) then {
private _indirectHitRange = getNumber(configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange");
private _indirectHit = getNumber(configFile >> "CfgAmmo" >> _ammo >> "indirectHit");
private _testParams = [_pos, [_indirectHitRange, _indirectHit], [], [], -4, _depth, 0];

View File

@ -2,145 +2,126 @@
#include "script_component.hpp"
// ACE_player sideChat "WAAAAAAAAAAAAAAAAAAAAA";
params ["_hitData"];
params ["_hitData", "_hitPartDataIndex"];
private _initialData = GVAR(spallHPData) select (_hitData select 0);
private _hpData = (_hitData select 1) select (_this select 1);
_initialData params ["_hpId", "_object", "_roundType", "_round", "_curPos", "_velocity"];
_hpData params ["_object"];
_object removeEventHandler ["hitPart", _initialData select 0];
private _foundObjects = _initialData select 7;
private _index = _foundObjects find _object;
if(_index != -1) then {
_foundObjects set[_index, nil];
};
private _hpData = (_hitData select 1) select _hitPartDataIndex;
(_hpData select 0) removeEventHandler ["hitPart", _hpId];
_initialData params ["", "_object", "_roundType", "_round"];
private _caliber = getNumber (configFile >> "CfgAmmo" >> _roundType >> "caliber");
private _explosive = getNumber (configFile >> "CfgAmmo" >> _roundType >> "explosive");
private _idh = getNumber (configFile >> "CfgAmmo" >> _roundType >> "indirectHitRange");
private _caliber = getNumber(configFile >> "CfgAmmo" >> _roundType >> "caliber");
private _explosive = getNumber(configFile >> "CfgAmmo" >> _roundType >> "explosive");
private _idh = getNumber(configFile >> "CfgAmmo" >> _roundType >> "indirectHitRange");
if !(_caliber >= 2.5 || {(_explosive > 0 && {_idh >= 1})}) exitWith {};
// ACE_player sideChat format ["BBBB"];
private _exit = false;
private _vm = 1;
private _alive = true;
if(!alive _round && (_initialData select 6) isEqualTo 1) then {
_alive = false;
};
private _oldVelocity = vectorMagnitude _velocity;
private _curVelocity = vectorMagnitude (velocity _round);
if(_alive || {_caliber >= 2.5} || {(_explosive > 0 && {_idh >= 1})}) then {
// ACE_player sideChat format["BBBB"];
private _exit = false;
private _vm = 1;
private _velocity = _initialData select 5;
private _oldVelocity = vectorMagnitude _velocity;
private _curVelocity = vectorMagnitude (velocity _round);
if(alive _round) then {
private _diff = _velocity vectorDiff (velocity _round);
private _polar = _diff call CBA_fnc_vect2polar;
// ACE_player sideChat format["polar: %1", _polar];
if((abs(_polar select 1) > 45 || abs(_polar select 2) > 45)) then {
if(_caliber < 2.5) then {
// ACE_player sideChat format["exit!"];
_exit = true;
} else {
_vm = 1-(_curVelocity/_oldVelocity);
};
};
};
if(!_exit) then {
private _unitDir = vectorNormalized _velocity;
private _pos = _hpData select 3;
private _spallPos = nil;
for "_i" from 0 to 100 do {
private _pos1 = _pos vectorAdd (_unitDir vectorMultiply (0.01 * _i));
private _pos2 = _pos vectorAdd (_unitDir vectorMultiply (0.01 * (_i + 1)));
// _blah = [_object, "FIRE"] intersect [_object worldToModel (ASLtoATL _pos1), _object worldToModel (ASLtoATL _pos2)];
// diag_log text format["b: %1", _blah];
// _data = [nil, nil, nil, 1, [[ASLtoATL _pos1, 1], [ASLtoATL _pos2, 1]]];
// NOU_TRACES set[(count NOU_TRACES), _data];
if(!lineIntersects [_pos1, _pos2]) exitWith {
// ACE_player sideChat format["FOUND!"];
_spallPos = _pos2;
};
};
if(!isNil "_spallPos") then {
private _spallPolar = _velocity call CBA_fnc_vect2polar;
if(_explosive > 0) then {
// ACE_player sideChat format["EXPLOSIVE!"];
private _warn = false;
private _c = getNumber(configFile >> "CfgAmmo" >> _roundType >> QGVAR(CHARGE));
if(_c == 0) then { _c = 1; _warn = true;};
private _m = getNumber(configFile >> "CfgAmmo" >> _roundType >> QGVAR(METAL));
if(_m == 0) then { _m = 2; _warn = true;};
private _k = getNumber(configFile >> "CfgAmmo" >> _roundType >> QGVAR(GURNEY_K));
if(_k == 0) then { _k = 1/2; _warn = true;};
private _gC = getNumber(configFile >> "CfgAmmo" >> _roundType >> QGVAR(GURNEY_C));
if(_gC == 0) then { _gC = 2440; _warn = true;};
if(_warn) then {
WARNING_1("Ammo class %1 lacks proper explosive properties definitions for frag!",_roundType); //TODO: turn this off when we get closer to release
};
private _fragPower = (((_m/_c)+_k)^-(1/2))*_gC;
_spallPolar set[0, _fragPower*0.66];
};
private _fragTypes = [
QGVAR(spall_small), QGVAR(spall_small), QGVAR(spall_small),
QGVAR(spall_small),QGVAR(spall_medium),QGVAR(spall_medium),QGVAR(spall_medium),
QGVAR(spall_medium), QGVAR(spall_large), QGVAR(spall_large), QGVAR(spall_huge),
QGVAR(spall_huge)
];
// diag_log text format["SPALL POWER: %1", _spallPolar select 0];
private _spread = 15+(random 25);
private _spallCount = 5+(random 10);
for "_i" from 1 to _spallCount do {
private _elev = ((_spallPolar select 2)-_spread)+(random (_spread*2));
private _dir = ((_spallPolar select 1)-_spread)+(random (_spread*2));
if(abs _elev > 90) then {
_dir = _dir + 180;
};
_dir = _dir % 360;
private _vel = (_spallPolar select 0)*0.33*_vm;
_vel = (_vel-(_vel*0.25))+(random (_vel*0.5));
private _spallFragVect = [_vel, _dir, _elev] call CBA_fnc_polar2vect;
private _fragType = round (random ((count _fragTypes)-1));
private _fragment = (_fragTypes select _fragType) createVehicleLocal [0,0,10000];
_fragment setPosASL _spallPos;
_fragment setVelocity _spallFragVect;
if(GVAR(traceFrags)) then {
[ACE_player, _fragment, [1,0.5,0,1]] call FUNC(addTrack);
};
};
_spread = 5+(random 5);
_spallCount = 3+(random 5);
for "_i" from 1 to _spallCount do {
private _elev = ((_spallPolar select 2)-_spread)+(random (_spread*2));
private _dir = ((_spallPolar select 1)-_spread)+(random (_spread*2));
if(abs _elev > 90) then {
_dir = _dir + 180;
};
_dir = _dir % 360;
private _vel = (_spallPolar select 0)*0.55*_vm;
_vel = (_vel-(_vel*0.25))+(random (_vel*0.5));
private _spallFragVect = [_vel, _dir, _elev] call CBA_fnc_polar2vect;
private _fragType = round (random ((count _fragTypes)-1));
private _fragment = (_fragTypes select _fragType) createVehicleLocal [0,0,10000];
_fragment setPosASL _spallPos;
_fragment setVelocity _spallFragVect;
if(GVAR(traceFrags)) then {
[ACE_player, _fragment, [1,0,0,1]] call FUNC(addTrack);
};
};
if (alive _round) then {
private _diff = _velocity vectorDiff (velocity _round);
private _polar = _diff call CBA_fnc_vect2polar;
// ACE_player sideChat format ["polar: %1", _polar];
if (abs (_polar select 1) > 45 || {abs (_polar select 2) > 45}) then {
if (_caliber < 2.5) then {
// ACE_player sideChat format ["exit!"];
_exit = true;
} else {
SUB(_vm,_curVelocity / _oldVelocity);
};
};
};
if (_exit) exitWith {};
private _unitDir = vectorNormalized _velocity;
private _pos = _hpData select 3;
private _spallPos = [];
for "_i" from 0 to 100 do {
private _pos1 = _pos vectorAdd (_unitDir vectorMultiply (0.01 * _i));
private _pos2 = _pos vectorAdd (_unitDir vectorMultiply (0.01 * (_i + 1)));
// _data = [nil, nil, nil, 1, [[ASLtoATL _pos1, 1], [ASLtoATL _pos2, 1]]];
// NOU_TRACES pushBack _data;
if (!lineIntersects [_pos1, _pos2]) exitWith {
// ACE_player sideChat format ["FOUND!"];
_spallPos = _pos2;
};
};
if (_spallPos isEqualTo []) exitWith {};
private _spallPolar = _velocity call CBA_fnc_vect2polar;
if (_explosive > 0) then {
// ACE_player sideChat format ["EXPLOSIVE!"];
private _warn = false;
private _c = getNumber (configFile >> "CfgAmmo" >> _roundType >> QGVAR(CHARGE));
if (_c == 0) then {_c = 1; _warn = true;};
private _m = getNumber (configFile >> "CfgAmmo" >> _roundType >> QGVAR(METAL));
if (_m == 0) then {_m = 2; _warn = true;};
private _k = getNumber (configFile >> "CfgAmmo" >> _roundType >> QGVAR(GURNEY_K));
if (_k == 0) then {_k = 1 / 2; _warn = true;};
private _gC = getNumber (configFile >> "CfgAmmo" >> _roundType >> QGVAR(GURNEY_C));
if (_gC == 0) then {_gC = 2440; _warn = true;};
if (_warn) then {
WARNING_1("Ammo class %1 lacks proper explosive properties definitions for frag!",_roundType); //TODO: turn this off when we get closer to release
};
private _fragPower = (((_m / _c) + _k) ^ - (1 / 2)) * _gC;
_spallPolar set [0, _fragPower * 0.66];
};
private _fragTypes = [
QGVAR(spall_small), QGVAR(spall_small), QGVAR(spall_small),
QGVAR(spall_small),QGVAR(spall_medium),QGVAR(spall_medium),QGVAR(spall_medium),
QGVAR(spall_medium), QGVAR(spall_large), QGVAR(spall_large), QGVAR(spall_huge),
QGVAR(spall_huge)
];
// diag_log text format ["SPALL POWER: %1", _spallPolar select 0];
private _spread = 15 + (random 25);
private _spallCount = 5 + (random 10);
for "_i" from 1 to _spallCount do {
private _elev = ((_spallPolar select 2) - _spread) + (random (_spread * 2));
private _dir = ((_spallPolar select 1) - _spread) + (random (_spread * 2));
if (abs _elev > 90) then {
ADD(_dir,180);
};
_dir = _dir % 360;
private _vel = (_spallPolar select 0) * 0.33 * _vm;
_vel = (_vel - (_vel * 0.25)) + (random (_vel * 0.5));
private _spallFragVect = [_vel, _dir, _elev] call CBA_fnc_polar2vect;
private _fragType = round (random ((count _fragTypes) - 1));
private _fragment = (_fragTypes select _fragType) createVehicleLocal [0,0,10000];
_fragment setPosASL _spallPos;
_fragment setVelocity _spallFragVect;
if (GVAR(traceFrags)) then {
[ACE_player, _fragment, [1, 0.5, 0, 1]] call FUNC(addTrack);
};
};
_spread = 5 + (random 5);
_spallCount = 3 + (random 5);
for "_i" from 1 to _spallCount do {
private _elev = ((_spallPolar select 2) - _spread) + (random (_spread * 2));
private _dir = ((_spallPolar select 1) - _spread) + (random (_spread * 2));
if (abs _elev > 90) then {
ADD(_dir,180);
};
_dir = _dir % 360;
private _vel = (_spallPolar select 0) * 0.55 * _vm;
_vel = (_vel - (_vel * 0.25)) + (random (_vel * 0.5));
private _spallFragVect = [_vel, _dir, _elev] call CBA_fnc_polar2vect;
private _fragType = round (random ((count _fragTypes) - 1));
private _fragment = (_fragTypes select _fragType) createVehicleLocal [0, 0, 10000];
_fragment setPosASL _spallPos;
_fragment setVelocity _spallFragVect;
if (GVAR(traceFrags)) then {
[ACE_player, _fragment, [1, 0, 0, 1]] call FUNC(addTrack);
};
};

View File

@ -1,31 +1,23 @@
#include "script_component.hpp"
private ["_color", "_index", "_lastPos", "_lastSpd", "_max", "_positions", "_startSpeed"];
{
_positions = _x select 4;
_color = _x select 5;
_index = 0;
_max = count _positions;
_startSpeed = 0.01 max ((_positions select 0) select 1);
_lastSpd = [];
_lastPos = [];
private _positions = _x select 4;
private _color = _x select 5;
private _index = 0;
private _max = count _positions;
private _lastSpd = [];
private _lastPos = [];
while {_index < _max} do {
_data1 = _positions select _index;
_data2 = nil;
if(_index + ACE_TRACE_DRAW_INC >= _max) then {
_data2 = _positions select (_max - 1);
} else {
_data2 = _positions select (_index + ACE_TRACE_DRAW_INC);
};
_data2 = _positions select ([_index + ACE_TRACE_DRAW_INC, _max - 1] select (_index + ACE_TRACE_DRAW_INC >= _max));
_pos1 = _data1 select 0;
_pos2 = _data2 select 0;
_index = _index + ACE_TRACE_DRAW_INC;
ADD(_index,ACE_TRACE_DRAW_INC);
drawLine3D [_pos1, _pos2, _color];
_lastPos = _pos2;
_lastSpd = _data1 select 1;
};
// drawIcon3D ["", [1,0,0,1], _lastPos, 0, 0, 0, format["%1m/s", _lastSpd], 1, 0.05, "RobotoCondensed"];
// drawIcon3D ["", [1,0,0,1], _lastPos, 0, 0, 0, format ["%1m/s", _lastSpd], 1, 0.05, "RobotoCondensed"];
} forEach GVAR(traces);

View File

@ -1,61 +1,58 @@
//fnc_findReflections.sqf
#include "script_component.hpp"
private ["_lastPos", "_test", "_vec", "_testPos", "_buckets", "_excludes", "_bucketIndex", "_bucketPos", "_bucketList", "_c", "_index", "_blist", "_avgX", "_avgY", "_avgZ", "_bpos", "_distance", "_hitFactor", "_hit", "_range", "_refExp", "_i", "_x", "_res", "_forEachIndex", "_explosions", "_can", "_dirvec", "_zAng"];
BEGIN_COUNTER(fnc_findReflections);
params ["_args"];
params ["_args", "_pfhID"];
_args params ["_pos", "_explosiveInfo", "_los", "_nlos", "_zIndex", "_depth", "_rand"];
private _split = 15;
private _radi = (360/_split*_depth);
private _radi = 360 / _split * _depth;
// player sideChat format["p: %1", _explosiveInfo];
// player sideChat format ["p: %1", _explosiveInfo];
_explosiveInfo params ["_indirectHitRange", "_indirectHit"];
private _distanceCount = (floor _indirectHitRange*4) min 100;
private _distanceCount = (floor _indirectHitRange * 4) min 100;
if(_zIndex < 5) then {
_lastPos = _pos;
_zAng = _zIndex*20+2;
if(_zAng > 80) then {
if (_zIndex < 5) then {
private _lastPos = _pos;
private _zAng = _zIndex * 20 + 2;
if (_zAng > 80) then {
_radi = 1;
_zAng = 90;
};
for "_i" from 0 to _radi do {
_test = true;
_vec = [1, ((_i*_split)+_rand) mod 360, _zAng] call CBA_fnc_polar2vect;
private _test = true;
private _vec = [1, ((_i * _split) + _rand) % 360, _zAng] call CBA_fnc_polar2vect;
for "_x" from 1 to _distanceCount do {
_testPos = _pos vectorAdd (_vec vectorMultiply _x);
private _testPos = _pos vectorAdd (_vec vectorMultiply _x);
// 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,"","",""];
_res = lineIntersectsWith [_pos, _testPos];
if(count _res > 0) exitWith {
private _res = lineIntersectsWith [_pos, _testPos];
if (count _res > 0) exitWith {
_test = false;
_nlos pushBack _lastPos;
// {
// _x addEventHandler ["HandleDamage", { diag_log text format["this: %1", _this]; }];
// _x addEventHandler ["HandleDamage", { diag_log text format ["this: %1", _this]; }];
// } 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 {};
// if (terrainIntersectASL [_pos, _testPos]) exitWith {};
_lastPos = _testPos;
};
};
_args set[4, _zIndex+1];
_args set [4, _zIndex + 1];
} else {
_depth = _depth + 1;
_buckets = [];
_excludes = [];
_bucketIndex = 0;
_bucketPos = nil;
_bucketList = nil;
_c = 0;
while { count(_nlos) != count(_excludes) && _c < (count _nlos) } do {
INC(_depth);
private _buckets = [];
private _excludes = [];
private _bucketPos = nil;
private _bucketList = nil;
private _c = 0;
while {count _nlos != count _excludes && {_c < (count _nlos)}} do {
scopeName "mainSearch";
{
if(!(_forEachIndex in _excludes)) then {
_index = _buckets pushBack [_x, [_x]];
if (!(_forEachIndex in _excludes)) then {
private _index = _buckets pushBack [_x, [_x]];
_excludes pushBack _forEachIndex;
_bucketPos = _x;
_bucketList = (_buckets select _index) select 1;
@ -63,59 +60,58 @@ if(_zIndex < 5) then {
};
} forEach _nlos;
{
if(!(_forEachIndex in _excludes)) then {
if (!(_forEachIndex in _excludes)) then {
_testPos = _x;
if(_testPos vectorDistanceSqr _bucketPos <= 30) then {
if (_testPos vectorDistanceSqr _bucketPos <= 30) then {
_bucketList pushBack _x;
_excludes pushBack _forEachIndex;
};
};
} forEach _nlos;
_c = _c + 1;
INC(_c);
};
// player sideChat format["c: %1", count _buckets];
_explosions = [];
// player sideChat format ["c: %1", count _buckets];
private _explosions = [];
{
_blist = _x select 1;
_avgX = 0;
_avgY = 0;
_avgZ = 0;
private _blist = _x select 1;
private _avgX = 0;
private _avgY = 0;
private _avgZ = 0;
{
_avgX = _avgX + (_x select 0);
_avgY = _avgY + (_x select 1);
_avgZ = _avgZ + (_x select 2);
ADD(_avgX,_x select 0);
ADD(_avgY,_x select 1);
ADD(_avgZ,_x select 2);
} forEach _blist;
_c = count _blist;
_bpos = [_avgX/_c, _avgY/_c, _avgZ/_c];
private _bpos = [_avgX / _c, _avgY / _c, _avgZ / _c];
_distance = _pos vectorDistance _bpos;
_hitFactor = 1-(((_distance/(_indirectHitRange*4)) min 1) max 0);
// _hitFactor = 1/(_distance^2);
_hit = _indirectHit*_hitFactor;
_hit = (floor (_hit/4)) min 500;
_hit = _hit - (_hit%10);
_range = (floor (_indirectHitRange-(_distance/4))) min 100;
_range = _range - (_range%2);
private _distance = _pos vectorDistance _bpos;
private _hitFactor = 1 - (((_distance / (_indirectHitRange * 4)) min 1) max 0);
// _hitFactor = 1 / (_distance ^ 2);
private _hit = _indirectHit * _hitFactor;
_hit = (floor (_hit / 4)) min 500;
SUB(_hit,_hit % 10);
private _range = (floor (_indirectHitRange - (_distance / 4))) min 100;
SUB(_range,_range % 2);
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]];
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]];
// TEST_PAIRS pushBack [_pos, _bpos, [1,0,0,1]];
_refExp = format["ace_explosion_reflection_%1_%2", _range, _hit];
private _refExp = format ["ace_explosion_reflection_%1_%2", _range, _hit];
// _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];
_explosions pushBack [_refExp, _bpos, _hit, _distance, _indirectHitRange / 4, _depth];
};
if(count _explosions > (_radi*2)/_depth) exitWith {};
if (count _explosions > (_radi * 2) / _depth) exitWith {};
} 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;
[(_this select 1)] call CBA_fnc_removePerFrameHandler;
[_pfhID] call CBA_fnc_removePerFrameHandler;
};
END_COUNTER(fnc_findReflections);

View File

@ -42,7 +42,7 @@ if (isNil "_shouldAdd") then {
private _explosive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosive");
private _indirectRange = getNumber (configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange");
private _force = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(force));
private _fragPower = getNumber(configFile >> "CfgAmmo" >> _ammo >> "indirecthit")*(sqrt((getNumber (configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange"))));
private _fragPower = getNumber (configFile >> "CfgAmmo" >> _ammo >> "indirecthit") * (sqrt (getNumber (configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange")));
_shouldAdd = (_skip == 0) && {(_force == 1) || {_explosive > 0.5 && {_indirectRange >= 4.5} && {_fragPower >= 35}}};
TRACE_6("SettingCache[willFrag?]",_skip,_explosive,_indirectRange,_force,_fragPower,_shouldAdd);

View File

@ -6,44 +6,36 @@
#define MAX_FRAG_COUNT 50
if(!isServer) exitWith { };
if (!isServer) exitWith {};
BEGIN_COUNTER(frago);
// _startTime = diag_tickTime;
private ["_fuseDist", "_indirectHitRange", "_fragRange", "_c", "_m", "_k", "_gC", "_fragPower", "_fragPowerRandom", "_manObjects", "_objects", "_crew", "_fragCount", "_fragArcs", "_doRandom", "_boundingBox", "_targetPos", "_distance", "_add", "_bbX", "_bbY", "_bbZ", "_cubic", "_targetVel", "_baseVec", "_dir", "_currentCount", "_count", "_vecVar", "_vec", "_fp", "_vel", "_fragType", "_fragObj", "_randomCount", "_sectorSize", "_sectorOffset", "_i", "_randomDir", "_endTime", "_target"];
params ["_round", "_lastPos", "_lastVel", "_shellType"];
private _gun = nil;
if((count _this) > 5) then {
_gun = _this select 5;
};
params ["_round", "_lastPos", "_lastVel", "_shellType", "_firedFrame", "_gun"];
private _fragTypes = [
QGVAR(tiny), QGVAR(tiny), QGVAR(tiny),
QGVAR(tiny_HD), QGVAR(tiny_HD), QGVAR(tiny_HD),
QGVAR(small),QGVAR(small),QGVAR(small),QGVAR(small),
QGVAR(small_HD),QGVAR(small_HD),QGVAR(small_HD),QGVAR(small_HD),
QGVAR(small), QGVAR(small), QGVAR(small), QGVAR(small),
QGVAR(small_HD), QGVAR(small_HD), QGVAR(small_HD), QGVAR(small_HD),
QGVAR(medium_HD), QGVAR(medium_HD), QGVAR(medium_HD), QGVAR(medium_HD), QGVAR(medium_HD)
];
private _warn = false;
if(isArray (configFile >> "CfgAmmo" >> _shellType >> QGVAR(CLASSES))) then {
if (isArray (configFile >> "CfgAmmo" >> _shellType >> QGVAR(CLASSES))) then {
_fragTypes = getArray (configFile >> "CfgAmmo" >> _shellType >> QGVAR(CLASSES));
} else {
_warn = true;
};
private _atlPos = ASLtoATL _lastPos;
private _isArmed = true;
if(!isNil "_gun") then {
_fuseDist = getNumber(configFile >> "CfgAmmo" >> _shellType >> "fuseDistance");
if (!isNil "_gun") then {
private _fuseDist = getNumber(configFile >> "CfgAmmo" >> _shellType >> "fuseDistance");
_isArmed = ((getPosASL _gun) distance _lastPos > _fuseDist);
};
_indirectHitRange = getNumber(configFile >> "CfgAmmo" >> _shellType >> "indirecthitrange");
_fragRange = 20 * _indirectHitRange * 4;
private _indirectHitRange = getNumber(configFile >> "CfgAmmo" >> _shellType >> "indirecthitrange");
private _fragRange = 20 * _indirectHitRange * 4;
// _c = 185; // grams of comp-b
// _m = 210; // grams of fragmentating metal
// _k = 3/5; // spherical K factor
@ -54,26 +46,27 @@ _fragRange = 20 * _indirectHitRange * 4;
// _k = 1/2; // spherical K factor
// _gC = 2320; // Gurney constant of tritonal in /ms
private _c = getNumber (configFile >> "CfgAmmo" >> _shellType >> QGVAR(CHARGE));
if (_c == 0) then {_c = 1; _warn = true;};
private _m = getNumber (configFile >> "CfgAmmo" >> _shellType >> QGVAR(METAL));
if (_m == 0) then {_m = 2; _warn = true;};
private _k = getNumber (configFile >> "CfgAmmo" >> _shellType >> QGVAR(GURNEY_K));
if (_k == 0) then {_k = 0.5; _warn = true;};
private _gC = getNumber (configFile >> "CfgAmmo" >> _shellType >> QGVAR(GURNEY_C));
if (_gC == 0) then {_gC = 2440; _warn = true;};
_c = getNumber(configFile >> "CfgAmmo" >> _shellType >> QGVAR(CHARGE));
if(_c == 0) then { _c = 1; _warn = true;};
_m = getNumber(configFile >> "CfgAmmo" >> _shellType >> QGVAR(METAL));
if(_m == 0) then { _m = 2; _warn = true;};
_k = getNumber(configFile >> "CfgAmmo" >> _shellType >> QGVAR(GURNEY_K));
if(_k == 0) then { _k = 1/2; _warn = true;};
_gC = getNumber(configFile >> "CfgAmmo" >> _shellType >> QGVAR(GURNEY_C));
if(_gC == 0) then { _gC = 2440; _warn = true;};
if(_warn) then {
if (_warn) then {
WARNING_1("Ammo class %1 lacks proper explosive properties definitions for frag!",_shellType); //TODO: turn this off when we get closer to release
};
_fragPower = (((_m/_c)+_k)^-(1/2))*_gC;
private _fragPower = (((_m / _c) + _k) ^ - (1 / 2)) * _gC;
_fragPower = _fragPower * 0.8; // Gunery equation is for a non-fragmenting metal, imperical value of 80% represents fragmentation
_fragPowerRandom = _fragPower * 0.5;
if((_atlPos select 2) < 0.5) then {
_lastPos set[2, (_lastPos select 2)+0.5];
private _atlPos = ASLtoATL _lastPos;
private _fragPowerRandom = _fragPower * 0.5;
if ((_atlPos select 2) < 0.5) then {
_lastPos set [2, (_lastPos select 2) + 0.5];
};
// _manObjects = _atlPos nearEntities ["CaManBase", _fragRange];
@ -81,134 +74,130 @@ if((_atlPos select 2) < 0.5) then {
// setAccTime 0.01;
//_objects = nearestObjects [_atlPos, ["AllVehicles"], _fragRange]; // Not sure if tracking "ReammoBox" is required, if so revert this change for _objects
_objects = _atlPos nearEntities [["Car", "Motorcycle", "Tank", "StaticWeapon", "CAManBase", "Air", "Ship"], _fragRange];
private _objects = _atlPos nearEntities [["Car", "Motorcycle", "Tank", "StaticWeapon", "CAManBase", "Air", "Ship"], _fragRange];
// _objects = _manObjects;
// Target also people inside vehicles or manning weapons
_crew = [];
// Add unique crews in faster way
{
{
_crew set [count _crew,_x]
_objects pushBackUnique _x;
} forEach (crew _x);
} forEach _objects;
_objects = _objects - _crew;
_objects = _objects + _crew;
private _fragCount = 0;
_fragCount = 0;
_fragArcs = [];
_fragArcs set[360, 0];
private _fragArcs = [];
_fragArcs set [360, 0];
#ifdef DEBUG_MODE_FULL
ACE_player sideChat format["_fragRange: %1", _fragRange];
ACE_player sideChat format["_objects: %1", _objects];
ACE_player sideChat format ["_fragRange: %1", _fragRange];
ACE_player sideChat format ["_objects: %1", _objects];
#endif
_doRandom = true;
if(_isArmed && (count _objects) > 0) then {
private _doRandom = true;
if (_isArmed && {!(_objects isEqualTo [])}) then {
if (GVAR(ReflectionsEnabled)) then {
[_lastPos, _shellType] call FUNC(doReflections);
};
{
//if(random(1) > 0.5) then {
_target = _x;
if(alive _target) then {
_boundingBox = boundingBox _target;
_targetPos = (getPosASL _target);
_distance = _targetPos distance _lastPos;
_add = (((_boundingBox select 1) select 2)/2)+((((_distance-(_fragpower/8)) max 0)/_fragPower)*10);
_bbX = (abs((_boundingBox select 0) select 0))+((_boundingBox select 1) select 0);
_bbY = (abs((_boundingBox select 0) select 1))+((_boundingBox select 1) select 1);
_bbZ = (abs((_boundingBox select 0) select 2))+((_boundingBox select 1) select 2);
_cubic = _bbX * _bbY * _bbZ;
if(_cubic > 1) then {
//if (random(1) > 0.5) then {
private _target = _x;
if (alive _target) then {
private _boundingBox = boundingBox _target;
private _targetPos = getPosASL _target;
private _distance = _targetPos distance _lastPos;
private _add = (((_boundingBox select 1) select 2) / 2) + ((((_distance - (_fragpower / 8)) max 0) / _fragPower) * 10);
private _bbX = (abs ((_boundingBox select 0) select 0)) + ((_boundingBox select 1) select 0);
private _bbY = (abs ((_boundingBox select 0) select 1)) + ((_boundingBox select 1) select 1);
private _bbZ = (abs ((_boundingBox select 0) select 2)) + ((_boundingBox select 1) select 2);
private _cubic = _bbX * _bbY * _bbZ;
if (_cubic > 1) then {
_doRandom = true;
_targetVel = (velocity _target);
private _targetVel = velocity _target;
_targetPos = _targetPos vectorAdd [
(_targetVel select 0) * (_distance / _fragPower),
(_targetVel select 1) * (_distance / _fragPower),
_add
];
_targetPos set[0, (_targetPos select 0)+((_targetVel select 0)*(_distance/_fragPower))];
_targetPos set[1, (_targetPos select 1)+((_targetVel select 1)*(_distance/_fragPower))];
_targetPos set[2, (_targetPos select 2)+_add];
private _baseVec = _lastPos vectorFromTo _targetPos;
_baseVec = _lastPos vectorFromTo _targetPos;
_dir = floor(_baseVec call CBA_fnc_vectDir);
_currentCount = _fragArcs select _dir;
if(isNil "_currentCount") then {
_currentCount = 0;
};
if(_currentCount < 20) then {
_count = ceil(random(sqrt(_m/1000)));
_vecVar = FRAG_VEC_VAR;
if(!(_target isKindOf "Man")) then {
_vecVar = ((sqrt _cubic)/2000)+FRAG_VEC_VAR;
if((count (crew _target)) == 0 && _count > 0) then {
_count = 0 max (_count/2);
private _dir = floor (_baseVec call CBA_fnc_vectDir);
private _currentCount = _fragArcs select _dir;
ISNILS(_currentCount,0);
if (_currentCount < 20) then {
private _count = ceil (random (sqrt (_m / 1000)));
private _vecVar = FRAG_VEC_VAR;
if (!(_target isKindOf "Man")) then {
_vecVar = ((sqrt _cubic) / 2000) + FRAG_VEC_VAR;
if ((crew _target) isEqualTo [] && {_count > 0}) then {
_count = 0 max (_count / 2);
};
};
for "_i" from 1 to _count do {
_vec = +_baseVec;
private _vec = _baseVec vectorDiff [
(_vecVar / 2) + (random _vecVar),
(_vecVar / 2) + (random _vecVar),
(_vecVar / 2) + (random _vecVar)
];
_vec set[0, (_vec select 0)-(_vecVar/2)+(random _vecVar)];
_vec set[1, (_vec select 1)-(_vecVar/2)+(random _vecVar)];
_vec set[2, (_vec select 2)-(_vecVar/2)+(random _vecVar)];
private _fp = _fragPower - (random (_fragPowerRandom));
private _vel = _vec vectorMultiply _fp;
_fp = (_fragPower-(random (_fragPowerRandom)));
_vel = _vec vectorMultiply _fp;
_fragType = round (random ((count _fragTypes)-1));
_fragObj = (_fragTypes select _fragType) createVehicleLocal [0,0,10000];
// diag_log text format["fp: %1 %2", _fp, typeOf _fragObj];
private _fragType = round (random ((count _fragTypes) - 1));
private _fragObj = (_fragTypes select _fragType) createVehicleLocal [0,0,10000];
// diag_log text format ["fp: %1 %2", _fp, typeOf _fragObj];
_fragObj setPosASL _lastPos;
_fragObj setVectorDir _vec;
_fragObj setVelocity _vel;
if(GVAR(traceFrags)) then {
GVAR(TOTALFRAGS) = GVAR(TOTALFRAGS) + 1;
if (GVAR(traceFrags)) then {
INC(GVAR(totalFrags));
[ACE_player, _fragObj, [1,0,0,1]] call FUNC(addTrack);
};
_fragCount = _fragCount + 1;
_currentCount = _currentCount + 1;
INC(_fragCount);
INC(_currentCount);
};
_fragArcs set[_dir, _currentCount];
_fragArcs set [_dir, _currentCount];
};
};
};
//};
if(_fragCount > MAX_FRAG_COUNT) exitWith {};
if (_fragCount > MAX_FRAG_COUNT) exitWith {};
} forEach _objects;
if(_fragCount > MAX_FRAG_COUNT) exitWith {};
_randomCount = ((ceil((MAX_FRAG_COUNT - _fragCount)*0.1)) max 0)+20;
_sectorSize = 360 / (_randomCount max 1);
if (_fragCount > MAX_FRAG_COUNT) exitWith {};
private _randomCount = ((ceil ((MAX_FRAG_COUNT - _fragCount) * 0.1)) max 0) + 20;
private _sectorSize = 360 / (_randomCount max 1);
// _doRandom = false;
if(_doRandom) then {
if (_doRandom) then {
for "_i" from 1 to _randomCount do {
// Distribute evenly
_sectorOffset = 360 * (_i - 1) / (_randomCount max 1);
_randomDir = random(_sectorSize);
_vec = [cos(_sectorOffset + _randomDir), sin(_sectorOffset + _randomDir), sin(30 - (random 45))];
private _sectorOffset = 360 * (_i - 1) / (_randomCount max 1);
private _randomDir = random (_sectorSize);
_vec = [cos (_sectorOffset + _randomDir), sin (_sectorOffset + _randomDir), sin (30 - (random 45))];
_fp = (_fragPower-(random (_fragPowerRandom)));
_fp = (_fragPower - (random (_fragPowerRandom)));
_vel = _vec vectorMultiply _fp;
_fragType = round (random ((count _fragTypes)-1));
_fragObj = (_fragTypes select _fragType) createVehicleLocal [0,0,10000];
_fragType = round (random ((count _fragTypes) - 1));
_fragObj = (_fragTypes select _fragType) createVehicleLocal [0, 0, 10000];
_fragObj setPosASL _lastPos;
_fragObj setVectorDir _vec;
_fragObj setVelocity _vel;
if(GVAR(traceFrags)) then {
GVAR(TOTALFRAGS) = GVAR(TOTALFRAGS) + 1;
if (GVAR(traceFrags)) then {
INC(GVAR(totalFrags));
[ACE_player, _fragObj, [1,0.5,0,1]] call FUNC(addTrack);
};
_fragCount = _fragCount + 1;
INC(_fragCount);
};
};
};
// #ifdef DEBUG_MODE_FULL
// ACE_player sideChat format["total frags: %1", GVAR(TOTALFRAGS)];
// ACE_player sideChat format["total frags: %1", GVAR(totalFrags)];
// ACE_player sideChat format["tracks: %1", (count GVAR(trackedObjects))];
// #endif
// _endTime = diag_tickTime;

View File

@ -15,36 +15,35 @@
if (!GVAR(enabled)) exitWith {};
private ["_gcIndex", "_iter"];
_gcIndex = [];
private _gcIndex = [];
_iter = 0;
while { (count GVAR(objects)) > 0 && { _iter < (GVAR(MaxTrackPerFrame) min (count GVAR(objects))) } } do {
private ["_object", "_args"];
if(GVAR(lastIterationIndex) >= (count GVAR(objects))) then {
private _iter = 0;
private _objectCount = count GVAR(objects);
while {_objectCount > 0 && {_iter < (GVAR(MaxTrackPerFrame) min _objectCount)}} do {
if (GVAR(lastIterationIndex) >= _objectCount) then {
GVAR(lastIterationIndex) = 0;
};
_object = GVAR(objects) select GVAR(lastIterationIndex);
private _object = GVAR(objects) select GVAR(lastIterationIndex);
if(!isNil "_object") then {
_args = GVAR(arguments) select GVAR(lastIterationIndex);
if (!isNil "_object") then {
private _args = GVAR(arguments) select GVAR(lastIterationIndex);
if(!(_args call FUNC(pfhRound))) then {
_gcIndex pushBack GVAR(lastIterationIndex); // Add it to the GC if it returns false
if (!(_args call FUNC(pfhRound))) then {
_gcIndex pushBack GVAR(lastIterationIndex); // Add it to the GC if it returns false
};
};
_iter = _iter + 1;
GVAR(lastIterationIndex) = GVAR(lastIterationIndex) + 1;
INC(_iter);
INC(GVAR(lastIterationIndex));
};
// clean up dead object references
private ["_deletionCount", "_deleteIndex"];
_deletionCount = 0;
// Clean up dead object references
private _deletionCount = 0;
{
TRACE_1("GC Projectile", _x);
_deleteIndex = _x - _deletionCount;
private _deleteIndex = _x - _deletionCount;
GVAR(objects) deleteAt _deleteIndex;
GVAR(arguments) deleteAt _deleteIndex;
_deletionCount = _deletionCount + 1;
INC(_deletionCount);
} forEach _gcIndex;

View File

@ -1,26 +1,26 @@
#include "script_component.hpp"
params ["_round", "_lastPos", "_lastVel", "_type", "_firedFrame", "", "_doSpall", "_spallTrack", "_foundObjectHPIds", "_skip", "_explosive", "_indirectRange", "_force", "_fragPower"];
params ["_round", "_lastPos", "_lastVel", "_type", "_firedFrame", "_gun", "_doSpall", "_spallTrack", "_foundObjectHPIds", "_skip", "_explosive", "_indirectRange", "_force", "_fragPower"];
if(_round in GVAR(blackList)) exitWith {
if (_round in GVAR(blackList)) exitWith {
false
};
if (!alive _round) exitWith {
if((diag_frameno - _firedFrame) > 1) then { //skip if deleted within a single frame
if(_skip == 0) then {
if((_explosive > 0.5 && {_indirectRange >= 4.5} && {_fragPower >= 35}) || {_force == 1} ) then {
if ((diag_frameno - _firedFrame) > 1) then { //skip if deleted within a single frame
if (_skip == 0) then {
if ((_explosive > 0.5 && {_indirectRange >= 4.5} && {_fragPower >= 35}) || {_force == 1}) then {
// shotbullet, shotShell don't seem to explode when touching water, so don't create frags
if (((_lastPos select 2) < 0) && {(toLower getText (configFile >> "CfgAmmo" >> _type >> "simulation")) in ["shotbullet", "shotshell"]}) exitWith {};
[QGVAR(frag_eh), _this] call CBA_fnc_serverEvent;
};
};
};
if(_doSpall) then {
GVAR(spallIsTrackingCount) = GVAR(spallIsTrackingCount) - 1;
// diag_log text format["F: %1", _foundObjectHPIds];
if (_doSpall) then {
DEC(GVAR(spallIsTrackingCount));
// diag_log text format ["F: %1", _foundObjectHPIds];
{
if(!isNil "_x") then {
if (!isNil "_x") then {
_x removeEventHandler ["hitPart", _foundObjectHPIds select _forEachIndex];
};
} forEach _spallTrack;
@ -28,12 +28,12 @@ if (!alive _round) exitWith {
false
};
_this set[1, (getPosASL _round)];
_this set[2, (velocity _round)];
_this set [1, getPosASL _round];
_this set [2, velocity _round];
if(_doSpall) then {
if (_doSpall) then {
private ["_scale"];
_scale = ( (count GVAR(objects)) / GVAR(MaxTrackPerFrame) ) max 0.1;
_scale = ((count GVAR(objects)) / GVAR(MaxTrackPerFrame)) max 0.1;
[_round, _scale, _spallTrack, _foundObjectHPIds] call FUNC(spallTrack);
};

View File

@ -4,8 +4,8 @@
PARAMS_1(_round);
if(_round in GVAR(blackList)) then {
GVAR(blackList) = GVAR(blackList) - [_round];
if (_round in GVAR(blackList)) then {
REM(GVAR(blackList),_round);
};
GVAR(objects) = GVAR(objects) - [_round];
REM(GVAR(objects),_round);

View File

@ -1,12 +1,11 @@
#include "script_component.hpp"
private ["_ret"];
_ret = true;
if(IS_ARRAY((_this select 0))) then {
private _ret = true;
if (IS_ARRAY(_this select 0)) then {
_ret = false;
} else {
if((_this select 0) in GVAR(trackedObjects)) then {
GVAR(trackedObjects) = GVAR(trackedObjects) - [(_this select 0)];
if ((_this select 0) in GVAR(trackedObjects)) then {
REM(GVAR(trackedObjects),_this select 0);
} else {
_ret = false;
};

View File

@ -1,29 +1,27 @@
#include "script_component.hpp"
private ["_initialData", "_hpData", "_round", "_hpRound", "_hpDirect"];
//player sideChat format["f: %1 c: %2", (_this select 0), (count GVAR(spallHPData))];
//player sideChat format ["f: %1 c: %2", (_this select 0), (count GVAR(spallHPData))];
if ((_this select 0) <= (count GVAR(spallHPData))) then {
_initialData = GVAR(spallHPData) select (_this select 0);
if (!isNil "_initialData") then {
_hpRound = ((_this select 1) select 0) select 2;
_round = _initialData select 3;
_hpDirect = ((_this select 1) select 0) select 10;
if (_hpDirect && {_round == _hpRound}) then {
{
_hpData = _x;
_round = _initialData select 3;
// diag_log text format["HPDUMP-------------------------------------"];
// {
// _hp = _x;
// diag_log text format["%1 --", _forEachIndex];
// {
// diag_log text format["%1: %2", _forEachIndex, _x];
// } forEach _hp;
// } forEach (_this select 1);
[DFUNC(doSpall), [_this, _forEachIndex]] call CBA_fnc_execNextFrame;
// player sideChat "WEEE";
} forEach (_this select 1);
};
};
params ["_index", "_hitPartData"];
private _initialData = GVAR(spallHPData) param [_index, []];
if (_initialData isEqualTo []) exitWith {};
private _hpRound = (_hitPartData select 0) select 2;
private _round = _initialData select 3;
private _hpDirect = (_hitPartData select 0) select 10;
if (_hpDirect && {_round == _hpRound}) then {
{
// diag_log text format ["HPDUMP-------------------------------------"];
// {
// _hp = _x;
// diag_log text format ["%1 --", _forEachIndex];
// {
// diag_log text format ["%1: %2", _forEachIndex, _x];
// } forEach _hp;
// } forEach (_this select 1);
[DFUNC(doSpall), [_this, _forEachIndex]] call CBA_fnc_execNextFrame;
// player sideChat "WEEE";
} forEach _hitPartData;
};

View File

@ -3,7 +3,7 @@
params ["_round", "_multiplier", "_foundObjects", "_foundObjectHPIds"];
private _delta = (1/diag_fps) * _multiplier;
private _delta = (1 / diag_fps) * _multiplier;
private _curPos = getPosASL _round;
private _velocity = velocity _round;
@ -12,17 +12,15 @@ private _forwardPos = _curPos vectorAdd _velocityStep;
private _intersectsWith = lineIntersectsWith [_curPos, _forwardPos];
if (count _intersectsWith > 0) then {
// player sideChat format["inter: %1", _intersectsWith];
{
if(!(_x in _foundObjects)) then {
// diag_log text format["Adding HP: %1", _x];
private _index = count GVAR(spallHPData);
private _hpId = _x addEventHandler ["hitPart", compile format["[%1, _this] call " + QFUNC(spallHP), _index]];
_foundObjects set[(count _foundObjects), _x];
_foundObjectHPIds set[(count _foundObjectHPIds), _hpId];
private _data = [_hpId, _x, typeOf _round, _round, _curPos, _velocity, 0, _foundObjects, _foundObjectHPIds];
GVAR(spallHPData) set[_index, _data];
};
} forEach _intersectsWith;
};
if (_intersectsWith isEqualTo []) exitWith {};
// player sideChat format ["inter: %1", _intersectsWith];
{
// diag_log text format ["Adding HP: %1", _x];
private _index = count GVAR(spallHPData);
private _hpId = _x addEventHandler ["hitPart", compile format ["[%1, _this] call " + QFUNC(spallHP), _index]];
_foundObjects pushBack _x;
_foundObjectHPIds pushBack _hpId;
private _data = [_hpId, _x, typeOf _round, _round, _curPos, _velocity, 0, _foundObjects, _foundObjectHPIds];
GVAR(spallHPData) pushBack _data;
} forEach (_intersectsWith select {!(_x in _foundObjects)});

View File

@ -1,5 +1,5 @@
#include "script_component.hpp"
if(!GVAR(tracesStarted)) then {
GVAR(tracesStarted) = true;
GVAR(traceID) = [FUNC(drawTraces), 0, []] call CBA_fnc_addPerFrameHandler;
};
if (GVAR(tracesStarted)) exitWith {};
GVAR(tracesStarted) = true;
GVAR(traceID) = [FUNC(drawTraces)] call CBA_fnc_addPerFrameHandler;

View File

@ -1,5 +1,5 @@
#include "script_component.hpp"
if(GVAR(tracesStarted)) then {
GVAR(tracesStarted) = false;
[GVAR(traceID)] call CBA_fnc_removePerFrameHandler;
};
if (!GVAR(tracesStarted)) exitWith {};
GVAR(tracesStarted) = false;
[GVAR(traceID)] call CBA_fnc_removePerFrameHandler;

View File

@ -1,12 +1,12 @@
#include "script_component.hpp"
params ["_args"];
params ["_args", "_pfhID"];
_args params ["_tracerObj", "_index"];
if (alive _tracerObj && (count GVAR(traces)) > 0) then {
if (alive _tracerObj && {!(GVAR(traces) isEqualTo [])}) then {
private _data = GVAR(traces) select _index;
private _positions = _data select 4;
_positions pushBack [(getPos _tracerObj), vectorMagnitude (velocity _tracerObj)];
_positions pushBack [getPos _tracerObj, vectorMagnitude (velocity _tracerObj)];
} else {
[(_this select 1)] call CBA_fnc_removePerFrameHandler;
[_pfhID] call CBA_fnc_removePerFrameHandler;
};

View File

@ -17,4 +17,4 @@
#include "\z\ace\addons\main\script_macros.hpp"
#define ACE_TRACE_DRAW_INC 1
#define ACE_TRACE_DRAW_INC 1