diff --git a/addons/casings/$PBOPREFIX$ b/addons/casings/$PBOPREFIX$ new file mode 100644 index 0000000000..622c48c2bb --- /dev/null +++ b/addons/casings/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\casings diff --git a/addons/casings/CfgEventHandlers.hpp b/addons/casings/CfgEventHandlers.hpp new file mode 100644 index 0000000000..f6503c2479 --- /dev/null +++ b/addons/casings/CfgEventHandlers.hpp @@ -0,0 +1,17 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); + }; +}; + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_postInit)); + }; +}; diff --git a/addons/casings/README.md b/addons/casings/README.md new file mode 100644 index 0000000000..7c1ac9b2a0 --- /dev/null +++ b/addons/casings/README.md @@ -0,0 +1,4 @@ +ace_casings +=============== + +Create persistent empty casing when bullets are fired by infantry weapons. diff --git a/addons/casings/XEH_PREP.hpp b/addons/casings/XEH_PREP.hpp new file mode 100644 index 0000000000..8a0738b272 --- /dev/null +++ b/addons/casings/XEH_PREP.hpp @@ -0,0 +1 @@ +PREP(createCasing); diff --git a/addons/casings/XEH_postInit.sqf b/addons/casings/XEH_postInit.sqf new file mode 100644 index 0000000000..e91ab96c0d --- /dev/null +++ b/addons/casings/XEH_postInit.sqf @@ -0,0 +1,7 @@ +#include "script_component.hpp" + +if (!hasInterface || !GVAR(enabled)) exitWith {}; + +GVAR(cachedCasings) = createHashMap; +GVAR(casings) = []; +["CAManBase", "FiredMan", {call FUNC(createCasing)}] call CBA_fnc_addClassEventHandler; diff --git a/addons/casings/XEH_preInit.sqf b/addons/casings/XEH_preInit.sqf new file mode 100644 index 0000000000..9361d05015 --- /dev/null +++ b/addons/casings/XEH_preInit.sqf @@ -0,0 +1,11 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP_RECOMPILE_START; +#include "XEH_PREP.hpp" +PREP_RECOMPILE_END; + +#include "initSettings.sqf" + +ADDON = true; diff --git a/addons/casings/XEH_preStart.sqf b/addons/casings/XEH_preStart.sqf new file mode 100644 index 0000000000..022888575e --- /dev/null +++ b/addons/casings/XEH_preStart.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +#include "XEH_PREP.hpp" diff --git a/addons/casings/config.cpp b/addons/casings/config.cpp new file mode 100644 index 0000000000..815048a082 --- /dev/null +++ b/addons/casings/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = COMPONENT_NAME; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common"}; + author = ECSTRING(common,ACETeam); + authors[] = {"esteldunedain","Cyruz","diwako"}; + url = ECSTRING(main,URL); + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" diff --git a/addons/casings/functions/fnc_createCasing.sqf b/addons/casings/functions/fnc_createCasing.sqf new file mode 100644 index 0000000000..6d56e5f2bc --- /dev/null +++ b/addons/casings/functions/fnc_createCasing.sqf @@ -0,0 +1,68 @@ +#include "script_component.hpp" +/* + * Author: esteldunedain / Cyruz / diwako + * Produces a casing matching the fired weapons caliber on the ground around the unit + * + * Arguments: + * 0: unit - Object the event handler is assigned to + * 1: ammo - Ammo used + * + * Return Value: + * None + * + * Example: + * [player, "", "","", "B_556x45_Ball"] call ace_casings_fnc_createCasing + * + * Public: No + */ + +params ["_unit", "", "", "", "_ammo"]; + +if (!isNull objectParent _unit) exitWith {}; + +private _modelPath = GVAR(cachedCasings) get _ammo; + +if (isNil "_modelPath") then { + private _cartridge = getText (configFile >> "CfgAmmo" >> _ammo >> "cartridge"); + //Default cartridge is a 5.56mm model + _modelPath = switch (_cartridge) do { + case "FxCartridge_9mm": { "A3\Weapons_f\ammo\cartridge_small.p3d" }; + case "FxCartridge_65": { "A3\weapons_f\ammo\cartridge_65.p3d" }; + case "FxCartridge_762": { "A3\weapons_f\ammo\cartridge_762.p3d" }; + case "FxCartridge_127": { "A3\weapons_f\ammo\cartridge_127.p3d" }; + case "FxCartridge_slug": { "A3\weapons_f\ammo\cartridge_slug.p3d" }; + case "": { "" }; + default { "A3\Weapons_f\ammo\cartridge.p3d" }; + }; + GVAR(cachedCasings) set [_ammo, _modelPath]; +}; + +if (_modelPath isEqualTo "") exitWith {}; + +private _unitPos = getposASL _unit; +// Distant shooters don't produce as many cases +if ((AGLToASL positionCameraToWorld [0,0,0]) vectorDistance _unitPos > 100 && {random 1 < 0.9}) exitWith {}; + +private _weapDir = _unit weaponDirection currentWeapon _unit; +private _ejectDir = _weapDir vectorCrossProduct [0, 0, 1]; +private _pos = _unitPos + vectorAdd (_weapDir vectorMultiply (-0.5 + random 2)) + vectorAdd (_ejectDir vectorMultiply (0.2 + random 2)); + +[ + { + params ["_modelPath", "_pos"]; + + private _lisPos = (lineIntersectsSurfaces [_pos, _pos vectorAdd [0,0,-1e11], objNull, objNull, true, 1, "ROADWAY", "FIRE"]) #0; + private _casing = createSimpleObject [_modelPath, (_lisPos #0 vectorAdd [0,0,0.005]), true]; + _casing setDir (random 360); + _casing setVectorUp _lisPos #1; + private _idx = GVAR(casings) pushBack _casing; + + for "_" from 0 to (_idx - GVAR(maxCasings)) do { + deleteVehicle (GVAR(casings) deleteAt 0); + }; + }, + [_modelPath,_pos], + 0.4 +] call CBA_fnc_waitAndExecute; diff --git a/addons/casings/functions/script_component.hpp b/addons/casings/functions/script_component.hpp new file mode 100644 index 0000000000..88b44122b5 --- /dev/null +++ b/addons/casings/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\casings\script_component.hpp" diff --git a/addons/casings/initSettings.sqf b/addons/casings/initSettings.sqf new file mode 100644 index 0000000000..3dea180e2d --- /dev/null +++ b/addons/casings/initSettings.sqf @@ -0,0 +1,17 @@ +[ + QGVAR(enabled), "CHECKBOX", + [LSTRING(displayName), LSTRING(description)], + LSTRING(Settings_DisplayName), + true, + false, + {}, + true +] call CBA_fnc_addSetting; + +[ + QGVAR(maxCasings), "SLIDER", + [LSTRING(maxCasings_displayName), LSTRING(maxCasings_description)], + LSTRING(Settings_DisplayName), + [100, 500, 250, -1], + false +] call CBA_fnc_addSetting; diff --git a/addons/casings/script_component.hpp b/addons/casings/script_component.hpp new file mode 100644 index 0000000000..c734aca4e3 --- /dev/null +++ b/addons/casings/script_component.hpp @@ -0,0 +1,17 @@ +#define COMPONENT casings +#define COMPONENT_BEAUTIFIED Casings +#include "\z\ace\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE +// #define ENABLE_PERFORMANCE_COUNTERS + +#ifdef DEBUG_ENABLED_CASINGS + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_CASINGS + #define DEBUG_SETTINGS DEBUG_SETTINGS_CASINGS +#endif + +#include "\z\ace\addons\main\script_macros.hpp" diff --git a/addons/casings/stringtable.xml b/addons/casings/stringtable.xml new file mode 100644 index 0000000000..b8d35196f3 --- /dev/null +++ b/addons/casings/stringtable.xml @@ -0,0 +1,20 @@ + + + + + ACE Casings + + + Casings Enabled + + + Enable persistent casings (POTENTIAL performance impact on old/weak systems) + + + Maximum casings + + + Maximum amount of casings to display + + +