Skip to content

Commit

Permalink
Merge pull request #3129 from acemod/frag-cacheIfWillFrag
Browse files Browse the repository at this point in the history
Frag - only run addPfhRound on ammo that will frag (for master)
  • Loading branch information
PabstMirror committed Jan 20, 2016
2 parents 232fe62 + 46cb902 commit abb01e0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
16 changes: 16 additions & 0 deletions addons/common/CfgLocationTypes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//Create a location type that won't be drawn on the map
//Ref: https://community.bistudio.com/wiki/Location

class CfgLocationTypes {
class ACE_HashLocation {
color[] = {0,0,0,0};
drawStyle = "bananas";
font = "PuristaMedium";
importance = 5;
name = "HashLocation";
shadow = 0;
size = 0;
textSize = 0.0;
texture = "";
};
};
1 change: 1 addition & 0 deletions addons/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CfgPatches {

#include "CfgEventHandlers.hpp"

#include "CfgLocationTypes.hpp"
#include "CfgSounds.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
Expand Down
6 changes: 5 additions & 1 deletion addons/frag/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ if(isServer) then {
[QGVAR(frag_eh), { _this call FUNC(frago); }] call EFUNC(common,addEventHandler);
};

[FUNC(masterPFH), 0, []] call CBA_fnc_addPerFrameHandler;
[FUNC(masterPFH), 0, []] call CBA_fnc_addPerFrameHandler;

//Cache for ammo type configs
GVAR(cacheRoundsTypesToTrack) = createLocation ["ACE_HashLocation", [-10000,-10000,-10000], 0, 0];
GVAR(cacheRoundsTypesToTrack) setText QGVAR(cacheRoundsTypesToTrack);
58 changes: 53 additions & 5 deletions addons/frag/functions/fnc_fired.sqf
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
/*
* Author: nou, jaynus, PabstMirror
* Called from FiredBIS event on AllVehicles
* If spall is not enabled (default), then cache and only track those that will actually trigger fragmentation.
*
* Arguments:
* 0: gun - Object the event handler is assigned to <OBJECT>
* 4: type - Ammo used <STRING>
* 6: round - Object of the projectile that was shot <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [clientFiredBIS-XEH] call ace_frag_fnc_fired
*
* Public: No
*/
// #define DEBUG_ENABLED_FRAG
#include "script_component.hpp"
private["_gun", "_type", "_round"];

_gun = _this select 0;
_type = _this select 4;
_round = _this select 6;
params ["_gun", "", "", "", "_type", "", "_round"];

[_gun, _type, _round] call FUNC(addPfhRound);
private _shouldAdd = GVAR(cacheRoundsTypesToTrack) getVariable _type;
if (isNil "_shouldAdd") then {
TRACE_1("no cache for round",_type);

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",_type);
_shouldAdd = false;
};

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

//Read configs and test if it would actually cause a frag, using same logic as FUNC(pfhRound)
private _skip = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(skip));
private _explosive = getNumber (configFile >> "CfgAmmo" >> _type >> "explosive");
private _indirectRange = getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange");
private _force = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(force));
private _fragPower = getNumber(configFile >> "CfgAmmo" >> _type >> "indirecthit")*(sqrt((getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange"))));

_shouldAdd = (_skip == 0) && {(_force == 1) || {_explosive > 0.5 && {_indirectRange >= 4.5} && {_fragPower >= 35}}};
TRACE_6("SettingCache[willFrag?]",_skip,_explosive,_indirectRange,_force,_fragPower,_shouldAdd);
GVAR(cacheRoundsTypesToTrack) setVariable [_type, _shouldAdd];
};

if (_shouldAdd) then {
TRACE_3("Running Frag Tracking",_gun,_type,_round);
[_gun, _type, _round] call FUNC(addPfhRound);
};

0 comments on commit abb01e0

Please sign in to comment.