Skip to content

Commit

Permalink
Reswept dev functions to match ACE code guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdatiger committed Jan 15, 2024
1 parent 63cd1ed commit f28d5d2
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 185 deletions.
76 changes: 33 additions & 43 deletions addons/frag/functions/fnc_dev_addRound.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,87 +12,77 @@
* None
*
* Example:
* [_proj, false, false] call ace_frag_dev_addRound;
* [_projectile, false, false] call ace_frag_dev_addRound;
*
* Public: No
*/
params [
"_proj",
["_addEHs", true, [true]],
["_sidePlayer", true, [true]]
"_projectile",
["_addProjectileEventHandlers", true, [true]],
["_isSidePlayer", true, [true]]
];

// track round on each frame
// Create entry in position array from hashmap
if (_sidePlayer) then
{
GVAR(dev_trackLines) set [getObjectID _proj, [1, [getposATL _proj], [0, 0, 1, 1]]];
} else
{
GVAR(dev_trackLines) set [getObjectID _proj, [1, [getposATL _proj], [1, 0, 0, 1]]];
if (_isSidePlayer) then {
GVAR(dev_trackLines) set [getObjectID _projectile, [[getposATL _projectile], [0, 0, 1, 1]]];
} else {
GVAR(dev_trackLines) set [getObjectID _projectile, [[getposATL _projectile], [1, 0, 0, 1]]];
};
// eventhandler to track round and cleanup when round is "dead"
[
{
if (isGamePaused) exitWith {};
params ["_par", "_h"];
_par params ["_proj"];
if (!alive _proj) exitWith
{
[_h] call CBA_fnc_removePerFrameHandler;
};
private _arr = GVAR(dev_trackLines) getOrDefault [(getObjectID _proj), -1];
if (typeName _arr == "SCALAR") exitWith {};
(_arr#1) pushBack getPosATL _proj;
if (_arr#0 <= 0) exitWith
{
[_h] call CBA_fnc_removePerFrameHandler;
params ["_par", "_handle"];
_par params ["_projectile"];
if (!alive _projectile) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
};
private _projectileArray = GVAR(dev_trackLines) getOrDefault [(getObjectID _projectile), -1];
if (typeName _projectileArray == "SCALAR") exitWith {};
(_projectileArray#0) pushBack getPosATL _projectile;
},
0,
[_proj]
[_projectile]
] call CBA_fnc_addPerFrameHandler;

if (!_addEHs) exitWith {};
if (!_addProjectileEventHandlers) exitWith {};

// Add hitpart eventHandler
_proj addEventHandler [
_projectile addEventHandler [
"HitPart",
{
params ["_proj", "", "", "_posASL"];
private _arr = (GVAR(dev_trackLines) get (getObjectID _proj))#1;
_arr pushBack ASLtoATL _posASL;
if (GVAR(dbgSphere)) then
{
params ["_projectile", "", "", "_posASL"];
private _posArr = (GVAR(dev_trackLines) get (getObjectID _projectile))#0;
_posArr pushBack ASLtoATL _posASL;
if (GVAR(dbgSphere)) then {
[_posASL, "green"] call FUNC(dev_sphereDraw);
};
}
];

// Add explode eventHandler
_proj addEventHandler [
_projectile addEventHandler [
"Explode",
{
params ["_proj", "_posASL"];
private _arr = (GVAR(dev_trackLines) get (getObjectID _proj))#1;
_arr pushBack ASLtoATL _posASL;
if (GVAR(dbgSphere)) then
{
params ["_projectile", "_posASL"];
private _posArr = (GVAR(dev_trackLines) get (getObjectID _projectile))#0;
_posArr pushBack ASLtoATL _posASL;
if (GVAR(dbgSphere)) then {
[_posASL, "red"] call FUNC(dev_sphereDraw);
};
}
];

// Add deflected eventHandler
_proj addEventHandler [
_projectile addEventHandler [
"Deflected",
{
params ["_proj", "_posASL"];
private _arr = (GVAR(dev_trackLines) get (getObjectID _proj))#1;
_arr pushBack ASLtoATL _posASL;
if (GVAR(dbgSphere)) then
{
params ["_projectile", "_posASL"];
private _posArr = (GVAR(dev_trackLines) get (getObjectID _projectile))#0;
_posArr pushBack ASLtoATL _posASL;
if (GVAR(dbgSphere)) then {
[_posASL, "blue"] call FUNC(dev_sphereDraw);
};
}
];
];
7 changes: 3 additions & 4 deletions addons/frag/functions/fnc_dev_clearTraces.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
*
* Public: No
*/
GVAR(dev_trackLines) = createHashMap;
for "_i" from 0 to count GVAR(dev_eventSpheres) - 1 do
{
for "_i" from 0 to count GVAR(dev_eventSpheres) - 1 do {
deleteVehicle (GVAR(dev_eventSpheres)#_i);
};
GVAR(dev_eventSpheres) = +[];
GVAR(dev_eventSpheres) = [];

GVAR(dev_trackLines) = createHashMap;
GVAR(dev_hitBoxes) = createHashMap;
16 changes: 8 additions & 8 deletions addons/frag/functions/fnc_dev_debugAmmo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* 0: Log ammo types that wouldn't normall frag
* 1: Only export ammo classes of classes referenced in cfgAmmo
* and their submunitions.
* 2: Force a CSV format
* 2: Force a CSV format on debug print
*
* Return Value:
* None
Expand All @@ -20,7 +20,7 @@
* Public: No
*/
params [
["_debugForce", false, [false]],
["_logAll", false, [false]],
["_onlyShotAmmoTypes", false, [false]],
["_csvFormat", false, [false]]
];
Expand All @@ -33,7 +33,7 @@ if (_csvFormat) then {
// Gather all configs, either those that could be created from firing or all classes
private _allAmmoConfigs = [];
if (_onlyShotAmmoTypes) then {
private _searchFunc = {
private _configSearchFunc = {
params [
["_ammo", "", [""]]
];
Expand All @@ -44,17 +44,17 @@ if (_onlyShotAmmoTypes) then {
_subMunit = getArray (configFile >> "cfgAmmo" >> _ammo >> "submunitionAmmo");
for "_i" from 0 to count _subMunit - 1 do {
if (_i mod 2 == 0) then {
[toLower (_subMunit#_i)] call _searchFunc;
[toLower (_subMunit#_i)] call _configSearchFunc;
};
};
} else {
[toLower _subMunit] call _searchFunc;
[toLower _subMunit] call _configSearchFunc;
};
};
private _allMagazineConfigs = configProperties [configFile >> "cfgMagazines", "isClass _x", true];

{
[toLower getText (_x >> "ammo")] call _searchFunc;
[toLower getText (_x >> "ammo")] call _configSearchFunc;
} forEach _allMagazineConfigs;
} else {
_allAmmoConfigs = configProperties [configFile >> "cfgAmmo", "isClass _x && !('ace_frag' in configName _x)", true] apply {configName _x};
Expand All @@ -70,7 +70,7 @@ private _printCount = 0;
private _ammoConfig = (configFile >> "cfgAmmo" >> _ammo);
private _shoulFrag = [_ammo] call FUNC(shouldFrag);

if (_shoulFrag || _debugForce) then {
if (_shoulFrag || _logAll) then {

private _warn = false;
private _fragTypes = getArray (_ammoConfig >> QGVAR(CLASSES));
Expand Down Expand Up @@ -100,4 +100,4 @@ private _printCount = 0;
} forEach _allAmmoConfigs;

diag_log text format ["~~~~~~~~~~~~~~End [%1-%2]~~~~~~~~~~~~~~", count _allAmmoConfigs, count _processedCfgAmmos];
diag_log text format ["~~~~~~~~~~~~~~Printed: %1~~~~~~~~~~~", _printCount];
diag_log text format ["~~~~~~~~~~~~~~Printed: %1~~~~~~~~~~~", _printCount];
33 changes: 14 additions & 19 deletions addons/frag/functions/fnc_dev_drawTrace.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "..\script_component.hpp"
#define HB_DRAW_ARRS [[3 , 2 , 1 , 5 , 6 , 7 , 3 , 0 , 4 , 5], [0, 1], [2, 6], [7, 4]]
#define HITBOX_DRAW_PATH [[3 , 2 , 1 , 5 , 6 , 7 , 3 , 0 , 4 , 5], [0, 1], [2, 6], [7, 4]]
/*
* Author: Lambda.Tiger
* Per frame function to draw all dev traces
Expand All @@ -15,38 +15,33 @@
* Public: No
*/

private _deleteArr = [];
{
if (count (_y#1) > 1) then
{
for "_j" from 1 to count (_y#1) - 1 do
{
drawLine3D [_y#1#(_j-1), _y#1#_j, _y#2];
_y params ["_posArray", "_color"]
if (count (_posArray) > 1) then {
for "_j" from 1 to count _posArray - 1 do {
drawLine3D [_posArray#(_j-1), _posArray#_j, _color];
};
};
} forEach GVAR(dev_trackLines);

if (GVAR(drawHitBox)) then {
_deleteArr = [];
private _deleteArr = [];
{
_y params ["_obj", "_pts", "_color"];
if (!alive _obj) then
{
_y params ["_object", "_boxPoints", "_color"];
if (!alive _object) then {
_deleteArr pushBack _x;
continue;
};

{
for "_i" from 1 to count _x -1 do
{
drawLine3D [_obj modelToWorld (_pts#(_x#_i)), _obj modelToWorld (_pts#(_x#(_i-1))), _color];
for "_i" from 1 to count _x -1 do {
drawLine3D [_object modelToWorld (_boxPoints#(_x#_i)), _object modelToWorld (_boxPoints#(_x#(_i-1))), _color];
};
} forEach HB_DRAW_ARRS;
} forEach HITBOX_DRAW_PATH;

} forEach GVAR(dev_hitBoxes);

for "_i" from 0 to count _deleteArr - 1 do
{
GVAR(dev_hitBoxes) deleteAt (_deleteArr#_i);
};
};
GVAR(dev_hitBoxes) deleteAt _x;
} forEach _deleteArr;
};
5 changes: 3 additions & 2 deletions addons/frag/functions/fnc_dev_fired.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
*
* Public: No
*/

[_projectile, true, ((side _unit) getFriend (side ACE_player)) >= 0.6] call FUNC(dev_addRound);
//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle", "_gunner", "_turret"];
TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile, _vehicle, _gunner, _turret);
[_projectile, true, ((side _unit) getFriend (side ACE_player)) >= 0.6] call FUNC(dev_addRound);
55 changes: 21 additions & 34 deletions addons/frag/functions/fnc_dev_fragCalcDump.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/*
* Author: Lambda.Tiger, based on fnc_dev_debugAmmo by "ACE-Team"
* Dumps all ammo types to see if there's any reason to spawn fragments
* given power, distance, and lifetime of each fragement. Good for grasping
* the values used in shouldFrag to cull non-fragementing rounds
* given hit power and distance. Good for grasping the values used in
* shouldFrag to cull non-fragementing rounds
*
* Arguments:
* 0: _dispAll <BOOL> - Display rounds that will never frag (power < 5).
* 0: _logAll <BOOL> - Display rounds that will never frag (power < 5).
* Default value false
* 1: _minFrgPowRng <FLOAT> - minimum range for sqrt power calculation
* 1: _minFragPower <FLOAT> - minimum range for sqrt power calculation
*
* Return Value:
* None
Expand All @@ -19,58 +19,45 @@
* Public: No
*/

params [["_dispAll", false, [false]], ["_minFrgPowRng", 35, [123]]];
params [
["_logAll", false, [false]],
["_minFragPower", 35, [123]]
];

#define DT 0.01

private _allAmmoConfigs = configProperties [configFile >> "cfgAmmo", "isClass _x && !('ace_frag' in configName _x)", true];
private _processedCfgAmmos = [];



private _nPrinted = 0;

diag_log text "//****************** fragCalcDump Beg ******************//";
// Processing ammo types
{
{ // Begin _allAmmoConfigs forEach
private _ammo = toLower configName _x;

if (_ammo == "" || {_ammo in _processedCfgAmmos} ) then {continue};


// calculating hit range
_shouldFrag = [_ammo] call FUNC(shouldFrag);
if (_ammo == "" || {_ammo in _processedCfgAmmos} ) then { continue };

// Gunery equation
private _c = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(CHARGE));
if (_c == 0) then {_c = 1;};
private _m = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(METAL));
if (_m == 0) then {_m = 2;};
private _k = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(GURNEY_K));
if (_k == 0) then {_k = 0.8;};
private _gC = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(GURNEY_C));
if (_gC == 0) then {_gC = 2440;};
private _fragCount = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(fragCount));
if (_fragCount == 0) then {_fragCount = 200;};

private _velocity = 0.8 * _gC * sqrt (_c /(_m + _c * _k));
// number of shrapnel to send a direction
private _count = ceil (random (sqrt (_m / 1000)));
private _fragPowerSpeedRange = [0.5, 1] vectorMultiply _fragPower;
private _shouldFrag = [_ammo] call FUNC(shouldFrag);
if (_nSkip || _logAll) then {
private _fragInfo = [_ammo] call FUNC(getFragInfo);
_fragInfo params ["_fragRange", "_fragMaxVelocity", "", "_modifiedFragCount"]
private _fragCount = 4 * pi* _modifiedFragCount;
private _indirectHitRange = getNumber (configFile >> "cfgAmmo" >> _ammo >> "indirectHitRange");
private _indirectHit = getNumber (configFile >> "cfgAmmo" >> _ammo >> "indirectHit");
private _fragPowerSpeedRange = [0.5, 1] vectorMultiply _fragMaxVelocity;

if (_nSkip || _dispALl) then
{
diag_log text format ["Ammo type: %1 | Should frag: %2", _ammo, _shouldFrag];
diag_log text format [" Indirect hit range: %1", _indirectHitRange];
diag_log text format [" Indirect hit: %1", _indirectHit];
diag_log text format [" Frag sqrtPower: %1", _fragPowerSqrt];
diag_log text format [" Frag range: %1", _fragRange];
diag_log text format [" Frag speed range: %1", _fragPowerSpeedRange];
diag_log text format [" Number frags: %1", _count];
diag_log text format [" Number frags: %1", _fragCount];
INC(_nPrinted);
};

_processedCfgAmmos pushBack _ammo;
} forEach _allAmmoConfigs;

diag_log text "//****************** fragCalcDump End ******************//";
diag_log text format ["//********************** printed %1 *********************//", _nPrinted];
diag_log text format ["//********************** printed %1 *********************//", _nPrinted];
Loading

0 comments on commit f28d5d2

Please sign in to comment.