Reswept dev functions to match ACE code guidelines

This commit is contained in:
lambdatiger 2024-01-15 13:13:59 -06:00
parent 63cd1ed06a
commit f28d5d2372
10 changed files with 153 additions and 185 deletions

View File

@ -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);
};
}
];
];

View File

@ -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;

View File

@ -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
@ -20,7 +20,7 @@
* Public: No
*/
params [
["_debugForce", false, [false]],
["_logAll", false, [false]],
["_onlyShotAmmoTypes", false, [false]],
["_csvFormat", false, [false]]
];
@ -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", "", [""]]
];
@ -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};
@ -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));
@ -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];

View File

@ -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
@ -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;
};

View File

@ -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);

View File

@ -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
@ -19,53 +19,40 @@
* 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};
if (_ammo == "" || {_ammo in _processedCfgAmmos} ) then { continue };
// calculating hit range
_shouldFrag = [_ammo] call FUNC(shouldFrag);
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;
// 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;
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);
};
@ -73,4 +60,4 @@ diag_log text "//****************** fragCalcDump Beg ******************//";
} forEach _allAmmoConfigs;
diag_log text "//****************** fragCalcDump End ******************//";
diag_log text format ["//********************** printed %1 *********************//", _nPrinted];
diag_log text format ["//********************** printed %1 *********************//", _nPrinted];

View File

@ -20,18 +20,15 @@ params [
["_color", "(1,0,0,0.5)", [""]]
];
if (count _posASL < 3) then
{
if (count _posASL < 3) then {
_posASL pushBack 0;
_posASL = ASLtoATL _posASL;
_posASL set [2, 0];
_posASL = ATLtoASL _posASL;
};
if (_color select [0,1] != "(") then
{
switch (toLower _color) do
{
if (_color select [0,1] != "(") then {
switch (toLower _color) do {
case "blue": { _color = "(0,0,0.8,0.5)"; };
case "black": { _color = "(1,1,1,0.5)"; };
case "white": { _color = "(0,0,0,0.5)"; };
@ -42,11 +39,10 @@ if (_color select [0,1] != "(") then
default { _color = "(0.8,0.8,0,0.5)";};
};
};
private _clrStr = "#(argb,8,8,3)color" + _color;
private _colorString = "#(argb,8,8,3)color" + _color;
private _sphere = "Sign_Sphere25cm_F" createVehicle [1,2,34];
_sphere setObjectTextureGlobal [0, _clrStr];
_sphere setPosASL _posASL;
private _sphere = createVehicle ["Sign_Sphere25cm_F", ASLtoATL _posASL, [], 0, "CAN_COLLIDE"];
_sphere setObjectTextureGlobal [0, _colorString];
GVAR(dev_eventSpheres) pushBack _sphere;
_sphere;
_sphere;

View File

@ -15,20 +15,26 @@
*
* Public: No
*/
params ["_lVic", "_cVic"];
params ["_lastUnit", "_currentUnit"];
if (_cVic isEqualTo objNull || {!local _cVic || _lVic isEqualTo _cVic}) exitWith {};
if (_currentUnit isEqualTo objNull || {_lastUnit isEqualTo _currentUnit}) exitWith {};
if (!local _currentUnit) exitWith {
[
{local _currentUnit},
FUNC(dev_switchUnitHandle),
_this,
5
] call CBA_fnc_waitUntilAndExecute;
};
private _aID = missionNamespace getVariable [QGVAR(dev_clearTraceAction), -1];
if (_aID > -1 && {_lVic isNotEqualTo objNull}) then
{
_lVic removeAction _aID;
if (_aID > -1 && {_lastUnit isNotEqualTo objNull}) then {
_lastUnit removeAction _aID;
};
_aID = _cVic addAction
[
_aID = _currentUnit addAction [
"Reset Lines",
FUNC(dev_clearTraces),
nil, // arguments
@ -40,4 +46,4 @@ _aID = _cVic addAction
8
];
missionNamespace getVariable [QGVAR(dev_clearTraceAction), _aID];
missionNamespace getVariable [QGVAR(dev_clearTraceAction), _aID];

View File

@ -4,8 +4,8 @@
* Add a hitbox outline to an object
*
* Arguments:
* 0: Object to draw hitbox <OBJECT>
* 1: Add center sphere <BOOL>
* 0 <OBJECT>: Object to draw hitbox
* 1 <BOOL>: Add sphere at object origin
*
* Return Value:
* None
@ -16,44 +16,44 @@
* Public: No
*/
params [
["_obj", objNull, [objNull]],
["_addSphere", true, [false]]
["_object", objNull, [objNull]],
["_addSphere", true, [turretLocal]]
];
if (isNull _obj) exitWith {};
if (isNull _object) exitWith {};
// Grab the right hitBox
private _box = [];
if (_obj isKindOf "CAManBase") then {
if (vehicle _obj == _obj) then {
_box = 0 boundingBox _obj;
if (_object isKindOf "CAManBase") then {
if (isNull objectParent _object) then {
_box = 0 boundingBox _object;
} else {
_box = boundingBoxReal [_obj, "Geometry"];
_box = boundingBoxReal [_object, "Geometry"];
};
} else {
_box = boundingBoxReal [_obj, "FireGeometry"];
_box = boundingBoxReal [_object, "FireGeometry"];
};
_box params ["_lowP","_upP"];
// adjust with stance
private _stance = stance _obj;
private _stance = stance _object;
switch (true) do {
case (_stance isEqualTo "STAND"): {_upP set [2, 1.9];};
case (_stance isEqualTo "CROUCH"): {_upP set [2, 1.3];};
case (_stance isEqualTo "PRONE"): {_upP set [2, 0.8];};
};
private _centerPoint = ASLToAGL getPosASL _obj;
private _centerPoint = ASLToAGL getPosASL _object;
if (GVAR(dbgSphere) && {_addSphere && {vehicle _obj isEqualTo _obj}}) then {
private _centerSphere = [getPosASL _obj, "yellow"] call FUNC(dev_sphereDraw);
_centerSphere disableCollisionWith vehicle _obj;
_centerSphere attachTo [_obj, _obj worldToModel _centerPoint];
if (GVAR(dbgSphere) && {_addSphere && {isNull objectParent _object}}) then {
private _centerSphere = [getPosASL _object, "yellow"] call FUNC(dev_sphereDraw);
_centerSphere disableCollisionWith vehicle _object;
_centerSphere attachTo [_object, _object worldToModel _centerPoint];
};
// create an optimized outline
private _p1 = _upP;
private _p7 = _lowP;
private _points =[
private _points = [
_upP,
[_p1#0, _p7#1, _p1#2],
[_p7#0, _p7#1, _p1#2],
@ -64,10 +64,10 @@ private _points =[
[_p7#0, _p1#1, _p7#2]
];
_color = switch (side _obj) do {
_color = switch (side _object) do {
case east: {[1, 0, 0, 1]};
case resistance: {[0, 1, 0, 1]};
default {[0, 0, 1, 1]};
};
GVAR(dev_hitBoxes) set [getObjectID _obj, [_obj, _points, _color]];
GVAR(dev_hitBoxes) set [getObjectID _object, [_object, _points, _color]];

View File

@ -4,9 +4,9 @@
* This function adds an object to have it's course tracked (every frame).
*
* Arguments:
* 0: Object to draw hitbox <OBJECT>
* 1: Color of trace <STRING>
* 2: Whether the object is a projectile <BOOL>
* 0 <OBJECT>: Object to draw hitbox
* 1 <STRING>: Color of trace
* 2 <BOOL>: Whether the object is a projectile
*
* Return Value:
* None
@ -17,11 +17,11 @@
* Public: No
*/
params [
"_obj",
"_object",
["_color", "blue", ["blue"]],
["_isProj", false, [false]]
];
TRACE_4("devDraw",_this,_obj,_color,_isProj);
TRACE_3("devDraw",_object,_color,_isProj);
// pick color and add it to the array
private _colorArray = switch (toLower _color) do {
@ -33,72 +33,66 @@ private _colorArray = switch (toLower _color) do {
case "red": {[0.8, 0, 0, 1]};
case "black": {[1, 1, 1, 1]};
case "white": {[0, 0, 0, 1]};
default {[0, 0.8, 0.8, 1]};
default {[0, 0.8, 0.8, 1]};
};
GVAR(dev_trackLines) set [getObjectID _obj, [1, [getposATL _obj], _colorArray]];
GVAR(dev_trackLines) set [getObjectID _object, [1, [getposATL _object], _colorArray]];
// eventhandler to track round and cleanup when round is "dead"
[
{
if (isGamePaused) exitWith {};
params ["_par", "_h"];
_par params ["_obj"];
if (!alive _obj) exitWith {
[_h] call CBA_fnc_removePerFrameHandler;
params ["_par", "_handle"];
_par params ["_object"];
if (!alive _object) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
};
private _arr = GVAR(dev_trackLines) getOrDefault [(getObjectID _obj), -1];
private _arr = GVAR(dev_trackLines) getOrDefault [(getObjectID _object), -1];
if (typeName _arr isEqualTo "SCALAR") exitWith {
[_h] call CBA_fnc_removePerFrameHandler;
[_handle] call CBA_fnc_removePerFrameHandler;
};
(_arr#1) pushBack getPosATL _obj;
if (_arr#0 <= 0) exitWith {
[_h] call CBA_fnc_removePerFrameHandler;
};
(_arr#0) pushBack getPosATL _object;
},
0,
[_obj]
[_object]
] call CBA_fnc_addPerFrameHandler;
// Projectile eventhandlers that add spheres and points for more accurate round tracking
if (!_isProj) exitWith {};
_obj addEventHandler [
_object 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);
};
}
];
_obj addEventHandler [
_object 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);
};
}
];
_obj addEventHandler [
_object 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);
};
}
];
];