Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spall - Don't throw script errors in doSpall if input is bad #6322

Merged
merged 1 commit into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions addons/frag/functions/fnc_doSpall.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ private _initialData = GVAR(spallHPData) select (_hitData select 0);
_initialData params ["_hpId", "_object", "_roundType", "_round", "_curPos", "_velocity"];

private _hpData = (_hitData select 1) select _hitPartDataIndex;
(_hpData select 0) removeEventHandler ["hitPart", _hpId];
private _objectHit = _hpData param [0, objNull];
TRACE_1("",_objectHit);
if ((isNil "_objectHit") || {isNull _objectHit}) exitWith {WARNING_1("Problem with hitPart data - bad object [%1]",_objectHit);};
_objectHit removeEventHandler ["hitPart", _hpId];

private _caliber = getNumber (configFile >> "CfgAmmo" >> _roundType >> "caliber");
private _explosive = getNumber (configFile >> "CfgAmmo" >> _roundType >> "explosive");
Expand Down Expand Up @@ -54,6 +57,7 @@ if (_exit) exitWith {};
private _unitDir = vectorNormalized _velocity;
private _pos = _hpData select 3;
private _spallPos = [];
if ((isNil "_pos") || {!(_pos isEqualTypeArray [0,0,0])}) exitWith {WARNING_1("Problem with hitPart data - bad pos [%1]",_pos);};
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)));
Expand All @@ -80,9 +84,9 @@ if (_explosive > 0) then {
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
};
// 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];
Expand All @@ -91,6 +95,7 @@ if (_explosive > 0) then {
// diag_log text format ["SPALL POWER: %1", _spallPolar select 0];
private _spread = 15 + (random 25);
private _spallCount = 5 + (random 10);
TRACE_1("",_spallCount);
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));
Expand Down
23 changes: 9 additions & 14 deletions addons/frag/functions/fnc_fired.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,6 @@ private _shouldAdd = GVAR(cacheRoundsTypesToTrack) getVariable _ammo;
if (isNil "_shouldAdd") then {
TRACE_1("no cache for round",_ammo);

if (!EGVAR(common,settingsInitFinished)) exitWith {
//Just incase fired event happens before settings init, don't want to set cache wrong if spall setting changes
TRACE_1("Settings not init yet - exit without setting cache",_ammo);
_shouldAdd = false;
};

if (GVAR(spallEnabled)) exitWith {
//Always want to run whenever spall is enabled?
_shouldAdd = true;
TRACE_2("SettingCache[spallEnabled]",_ammo,_shouldAdd);
GVAR(cacheRoundsTypesToTrack) setVariable [_ammo, _shouldAdd];
};

//Read configs and test if it would actually cause a frag, using same logic as FUNC(pfhRound)
private _skip = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(skip));
private _explosive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosive");
Expand All @@ -45,7 +32,15 @@ if (isNil "_shouldAdd") then {
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);

if (GVAR(spallEnabled) && {!_shouldAdd}) then {
private _caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber");
if !(_caliber >= 2.5 || {(_explosive > 0 && {_indirectRange >= 1})}) exitWith {}; // from check in doSpall: line 34
TRACE_1("Won't frag, but will spall",_caliber);
_shouldAdd = true;
};

TRACE_6("Setting Cache",_skip,_explosive,_indirectRange,_force,_fragPower,_shouldAdd);
GVAR(cacheRoundsTypesToTrack) setVariable [_ammo, _shouldAdd];
};

Expand Down
2 changes: 1 addition & 1 deletion addons/frag/functions/fnc_spallHP.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Author: ACE-Team
*
* Handles the HitPart event
*
* Arguments:
* None
Expand Down
2 changes: 1 addition & 1 deletion addons/frag/functions/fnc_spallTrack.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Author: ACE-Team
*
* Add HitPart EventHandler to objects in the projectile's path
*
* Arguments:
* None
Expand Down