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

Casing - Move model lookup to cartridge config #9893

Merged
merged 10 commits into from
Apr 7, 2024
6 changes: 6 additions & 0 deletions addons/casings/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class CfgVehicles {
class FxCartridge;
class FxCartridge_65_caseless: FxCartridge {
GVAR(model) = ""; // note: the vanilla 6.5 caseless don't actually use this, just being safe
};
};
1 change: 1 addition & 0 deletions addons/casings/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ class CfgPatches {
};

#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
45 changes: 21 additions & 24 deletions addons/casings/functions/fnc_createCasing.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,30 @@ params ["_unit", "", "", "", "_ammo"];

if (!isNull objectParent _unit) exitWith {};

private _modelPath = GVAR(cachedCasings) get _ammo;

if (isNil "_modelPath") then {
private _modelPath = GVAR(cachedCasings) getOrDefaultCall [_ammo, {
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_762x39": { "A3\weapons_f_enoch\ammo\cartridge_762x39.p3d" };
case "FxCartridge_93x64_Ball": { "A3\Weapons_F_Mark\Ammo\cartridge_93x64.p3d" };
case "FxCartridge_338_Ball": { "A3\Weapons_F_Mark\Ammo\cartridge_338_LM.p3d" };
case "FxCartridge_338_NM": { "A3\Weapons_F_Mark\Ammo\cartridge_338_NM.p3d" };
case "FxCartridge_127": { "A3\weapons_f\ammo\cartridge_127.p3d" };
case "FxCartridge_127x54": { "A3\Weapons_F_Mark\Ammo\cartridge_127x54.p3d" };
case "FxCartridge_slug": { "A3\weapons_f\ammo\cartridge_slug.p3d" };
case "FxCartridge_12Gauge_HE_lxWS": { "lxWS\weapons_1_f_lxws\Ammo\cartridge_he_lxws.p3d" };
case "FxCartridge_12Gauge_Slug_lxWS": { "lxWS\weapons_1_f_lxws\Ammo\cartridge_slug_lxws.p3d" };
case "FxCartridge_12Gauge_Smoke_lxWS": { "lxWS\weapons_1_f_lxws\Ammo\cartridge_smoke_lxws.p3d" };
case "FxCartridge_12Gauge_Pellet_lxWS": { "lxWS\weapons_1_f_lxws\Ammo\cartridge_pellet_lxws.p3d" };
case "CUP_FxCartridge_545": { "CUP\Weapons\CUP_Weapons_Ammunition\magazines\cartridge545.p3d" };
case "CUP_FxCartridge_939": { "CUP\Weapons\CUP_Weapons_Ammunition\magazines\cartridge939.p3d" };
case "": { "" };
default { "A3\Weapons_f\ammo\cartridge.p3d" };
if (_cartridge == "") then { // return (note: can't use exitWith)
""
} else {
private _cartridgeConfig = configFile >> "CfgVehicles" >> _cartridge;

// if explicty defined use ace's config
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
if (isText (_cartridgeConfig >> QGVAR(model))) exitWith {
getText (_cartridgeConfig >> QGVAR(model))
Mike-MF marked this conversation as resolved.
Show resolved Hide resolved
};
// use casing's default model
private _model = getText (_cartridgeConfig >> "model");
if ("a3\weapons_f\empty" in toLowerANSI _model) exitWith { "" };

// Add file extension if missing (fileExists needs file extension)
if ((_model select [count _model - 4]) != ".p3d") then {
_model = _model + ".p3d";
};

["", _model] select (fileExists _model)
};
GVAR(cachedCasings) set [_ammo, _modelPath];
};
}, true];

if (_modelPath isEqualTo "") exitWith {};

Expand Down
2 changes: 1 addition & 1 deletion addons/compat_cup_weapons/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class CfgPatches {
};
};

#include "CfgEventHandlers.hpp"
#include "CfgMagazines.hpp"
#include "CfgWeapons.hpp"
#include "CfgEventHandlers.hpp"