Skip to content

Commit

Permalink
fix: regex & undefined vars
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkIsGrim committed Feb 9, 2025
1 parent 5661fd8 commit fa967e7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 64 deletions.
1 change: 1 addition & 0 deletions addons/casings/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PREP(createCasing);
PREP(createLitter);
PREP(createMagazine);
37 changes: 6 additions & 31 deletions addons/casings/functions/fnc_createCasing.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ if (!isNull objectParent _unit) exitWith {};


private _modelPath = GVAR(cachedCasings) getOrDefaultCall [_ammo, {
private _cartridgeConfig = configNull; // private var in switch condition scope isn't available in the result block.
private _modelOverride = ""; // very annoying.

private _cartridge = getText (configFile >> "CfgAmmo" >> _ammo >> "cartridge");
private _model = switch (true) do {
case (_cartridge == ""): { "" };

private _cartridgeConfig = configFile >> "CfgVehicles" >> _cartridge;
private _modelOverride = getText (_cartridgeConfig >> QGVAR(model));
_cartridgeConfig = configFile >> "CfgVehicles" >> _cartridge;
_modelOverride = getText (_cartridgeConfig >> QGVAR(model));

case (_modelOverride != ""): { _modelOverride }; // Use the override if non-empty
default { getText (_cartridgeConfig >> "model") } // Use the casing's default model
Expand All @@ -41,32 +44,4 @@ private _modelPath = GVAR(cachedCasings) getOrDefaultCall [_ammo, {
["", _model] select (!("a3\weapons_f\empty" in toLowerANSI _model) && {fileExists _model})
}, true];

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;
[_unit, _modelPath] call FUNC(createLitter);
32 changes: 32 additions & 0 deletions addons/casings/functions/fnc_createLitter.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
params ["_unit", "_modelPath", ["_force", false]];

if (_modelPath == "") exitWith {};

// Distant shooters don't produce as many cases
if (!_force && ((AGLToASL positionCameraToWorld [0,0,0]) vectorDistance _unitPos > 100 && {random 1 < 0.9})) exitWith {};

private _unitPos = getPosASL _unit;
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"];
TRACE_2("creating magazine",_modelPath,_pos);

Check failure on line 18 in addons/casings/functions/fnc_createLitter.sqf

View workflow job for this annotation

GitHub Actions / windows

unparseable syntax

unparseable syntax

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.010]), false]; // global
_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;
43 changes: 10 additions & 33 deletions addons/casings/functions/fnc_createMagazine.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,28 @@ _oldMagazine params ["_mag", "_ammo"];
if (_ammo != 0) exitWith {};

private _modelPath = GVAR(cachedMagazines) getOrDefaultCall [_mag, {
private _model = switch (true) do {
private _magConfig = configNull; // private var in switch condition scope isn't available in the result block.
private _modelOverride = ""; // very annoying.

private _model = switch true do {
// Should cover most 40x36
case (_mag in compatibleMagazines ["arifle_Mk20_GL_F", "EGLM"]): { "A3\Weapons_F\MagazineProxies\mag_40x36_HE_1rnd.p3d" };

private _magConfig = configFile >> "CfgMagazines" >> _mag;
private _modelOverride = getText (_magConfig >> QGVAR(model));
_magConfig = configFile >> "CfgMagazines" >> _mag;
_modelOverride = getText (_magConfig >> QGVAR(model));

case (_modelOverride != ""): { _modelOverride }; // Use the override if non-empty
case (getNumber (_magConfig >> "modelSpecialIsProxy") == 1): { getText (_magConfig >> "modelSpecial") }; // Use the magazine's proxy
case (getNumber (_magConfig >> "modelSpecialIsProxy") == 1): {getText (_magConfig >> "modelSpecial")}; // Use the magazine's proxy

default { getText (_magConfig >> "model") } // Use the magazine's dropped model
default { getText (_magConfig >> "model") }; // Use the magazine's dropped model
};

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

["", _model] select (!(_model regexMatch "(?:a3\weapons_f\empty|\ca\weapons\mag_univ).p3d") && fileExists _model)
["", _model] select (!(_model regexMatch "(?:\\)?a3\\weapons_f\\(?:empty|ammo\\mag_univ).p3d") && {fileExists _model})
}, true];

if (_modelPath isEqualTo "") exitWith {};

private _unitPos = getPosASL _unit;
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"];
TRACE_2("creating magazine",_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.010]), false]; // global
_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;
[_unit, _modelPath, true] call FUNC(createLitter);

0 comments on commit fa967e7

Please sign in to comment.