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
Merged

Conversation

PabstMirror
Copy link
Contributor

@PabstMirror PabstMirror commented Apr 1, 2024

Includes changes from #9888 (but it can be merged fist)
ref #9716 (comment)

@PabstMirror PabstMirror added the kind/change Release Notes: **CHANGED:** label Apr 1, 2024
@PabstMirror PabstMirror added this to the 3.17.1 milestone Apr 1, 2024
@PabstMirror
Copy link
Contributor Author

test code:

private _ammo = (toString {(getText (_x >> "cartridge")) != ""}) configClasses (configFile >> "CfgAmmo");
private _cartridges = [];
{
    private _cartridge = getText (_x >> "cartridge");
    _cartridges pushBackUnique _cartridge;
} forEach _ammo;

{
    private _cartridge = _x;
    private _oldPath = 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 "":                                { "" };
        default { "A3\Weapons_f\ammo\cartridge.p3d" };
    };
    private _newPath = getText (configFile >> "CfgVehicles" >> _cartridge >> "ace_casings_model");
    if (_oldPath != _newPath) then {
        diag_log text format ["%1: %2 -> %3", _cartridge, _oldPath, _newPath];
    };
} forEach _cartridges;

results with cup:

FxCartridge_338_NM_Ball: A3\Weapons_f\ammo\cartridge.p3d -> A3\Weapons_F_Mark\Ammo\cartridge_338_NM.p3d
FxCartridge_127x54_APDS: A3\Weapons_f\ammo\cartridge.p3d -> A3\Weapons_F_Mark\Ammo\cartridge_127x54.p3d
CUP_FxCartridge_545: A3\Weapons_f\ammo\cartridge.p3d -> \CUP\Weapons\CUP_Weapons_Ammunition\magazines\cartridge545.p3d
CUP_FxCartridge_939: A3\Weapons_f\ammo\cartridge.p3d -> \CUP\Weapons\CUP_Weapons_Ammunition\magazines\cartridge939.p3d

Can't find FxCartridge_338_NM or FxCartridge_127x54 in vanilla, so I think they were just misspellings unless they were from a mod?

@johnb432
Copy link
Contributor

johnb432 commented Apr 2, 2024

Why don't we use the model entry of the cartridge entry? The cartridges I've looked at have the correct models defined.

@Mike-MF
Copy link
Member

Mike-MF commented Apr 2, 2024

Can't find FxCartridge_338_NM or FxCartridge_127x54 in vanilla, so I think they were just misspellings unless they were from a mod?

The model paths are correct. Classes were not.

  • FxCartridge_127x54_APDS
  • FxCartridge_338_NM_Ball

if (_cartridge == "") then { // return (note: can't use exitWith)
""
} else {
getText (configFile >> "CfgVehicles" >> _cartridge >> QGVAR(model))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something like this?

Suggested change
getText (configFile >> "CfgVehicles" >> _cartridge >> QGVAR(model))
private _cartridgeConfig = configFile >> "CfgVehicles" >> _cartridge;
private _model = getText (_cartridgeConfig >> QGVAR(model));
if (_model == "model") then {
_model = getText (_cartridgeConfig >> "model");
if ("a3\weapons_f\empty" in toLowerANSI _model) then {
_model = "";
};
};
// Add file extension if missing (fileExists needs file extension)
if ((_model select [count _model - 4]) != ".p3d") then {
_model = _model + ".p3d";
};
["", _model] select (fileExists _model)

The idea is to allow people to override the casings if necessary. model usually contains valid entries (the empty entry is filtered out), so instead of needing to manually configure every entry, this would allow casing to use already configured models.
It would avoid us (and 3rd party mods) needing to configure casings, unless specifically wanted to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would still need to define QGVAR(model) = "model", no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For FxCartridge and FxCartridge_Small only, as the rest (at least in Vanilla) inherit from those. If a mod doesn't inherit from those, then it won't work.

Tbh I'm not a fan of QGVAR(model) = "model", but I don't think we can check for QGVAR(model) = "".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case people want to undefine it, I imagine they would overwrite it with "", intuitively.
We could force "empty" to signify no casing and write documentation so that people have to adopt it, but it's not very intuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fef0704 is a variation on this,
if ace_casings_model is defined then use is, otherwise just use it's normal model

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer that implementation.

PabstMirror and others added 3 commits April 5, 2024 22:43
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
@PabstMirror
Copy link
Contributor Author

new test code:

private _ammo = (toString {(getText (_x >> "cartridge")) != ""}) configClasses (configFile >> "CfgAmmo");
private _cartridges = [];
{
    private _cartridge = getText (_x >> "cartridge");
    _cartridges pushBackUnique _cartridge;
} forEach _ammo;

{
    private _cartridge = _x;
    private _oldPath = 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 "":                                { "" };
        default { "A3\Weapons_f\ammo\cartridge.p3d" };
    };
    private _newPath = call {
            private _cartridgeConfig = configFile >> "CfgVehicles" >> _cartridge;
    
            // if explicty defined use ace's config
            if (isText (_cartridgeConfig >> "ace_casing_model")) exitWith {
                "#" + getText (_cartridgeConfig >> "ace_casing_model")
            };
            // 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)
        };
    if (_oldPath != _newPath) then {
        diag_log text format ["%1: %2 -> %3", _cartridge, _oldPath, _newPath];
    };
} forEach _cartridges;

note the new leading slashes, but the game doesn't seem to mind

FxCartridge_556: A3\Weapons_f\ammo\cartridge.p3d -> \A3\Weapons_f\ammo\cartridge.p3d
FxCartridge_65: A3\weapons_f\ammo\cartridge_65.p3d -> \A3\weapons_f\ammo\cartridge_65.p3d
FxCartridge_9mm: A3\Weapons_f\ammo\cartridge_small.p3d -> \A3\Weapons_f\ammo\cartridge_small.p3d
FxCartridge_762: A3\weapons_f\ammo\cartridge_762.p3d -> \A3\weapons_f\ammo\cartridge_762.p3d
FxCartridge_slug: A3\weapons_f\ammo\cartridge_slug.p3d -> \A3\weapons_f\ammo\cartridge_slug.p3d
FxCartridge_127: A3\weapons_f\ammo\cartridge_127.p3d -> \A3\weapons_f\ammo\cartridge_127.p3d
FxCartridge_338_Ball: A3\Weapons_F_Mark\Ammo\cartridge_338_LM.p3d -> \A3\Weapons_F_Mark\Ammo\cartridge_338_LM.p3d
FxCartridge_338_NM_Ball: A3\Weapons_f\ammo\cartridge.p3d -> \A3\Weapons_F_Mark\Ammo\cartridge_338_NM.p3d
FxCartridge_127x54_APDS: A3\Weapons_f\ammo\cartridge.p3d -> \A3\Weapons_F_Mark\Ammo\cartridge_127x54.p3d
FxCartridge_93x64_Ball: A3\Weapons_F_Mark\Ammo\cartridge_93x64.p3d -> \A3\Weapons_F_Mark\Ammo\cartridge_93x64.p3d
FxCartridge_762x39: A3\weapons_f_enoch\ammo\cartridge_762x39.p3d -> \A3\weapons_f_enoch\ammo\cartridge_762x39.p3d

Co-authored-by: Jouni Järvinen <rautamiekka@users.noreply.github.com>
@LinkIsGrim LinkIsGrim merged commit 431c4d6 into master Apr 7, 2024
5 checks passed
@LinkIsGrim LinkIsGrim deleted the casingConfig branch April 7, 2024 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/change Release Notes: **CHANGED:**
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants