Skip to content

Commit

Permalink
Partial port of Community official-antistasi-community#3392
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoodruff40 committed Jan 18, 2025
1 parent 32741c2 commit e026d19
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 125 deletions.
1 change: 1 addition & 0 deletions A3A/addons/core/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CfgFunctions
class Ammunition {
file = QPATHTOFOLDER(functions\Ammunition);
class ACEpvpReDress {};
class addPrimaryAndMags {};
class allMagazines {};
class ammunitionTransfer {};
class arsenalManage {};
Expand Down
68 changes: 68 additions & 0 deletions A3A/addons/core/functions/Ammunition/fn_addPrimaryAndMags.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Equip rebel unit with primary weapon or handgun
Adds magazines by mass. Uses default magazine of selected weapon
Parameters:
0. <OBJECT> Rebel unit to equip with primary weapon.
1. <STRING> Weapon classname
2. <STRING> Optic type preference ("OpticsClose", "OpticsMid", "OpticsLong")
3. <NUMBER> Total mass of primary magazines to add to inventory.
4. <NUMBER> Optional: Number of GL mags to add if secondary.
Returns:
Nothing
Environment:
Scheduled, any machine
*/

#include "..\..\script_component.hpp"
FIX_LINE_NUMBERS()

params ["_unit", "_weapon", "_opticType", "_totalMagWeight", ["_glMags", 5]];

call A3A_fnc_fetchRebelGear; // Send current version of rebelGear from server if we're out of date

// Probably shouldn't ever be executed
if !(primaryWeapon _unit isEqualTo "") then {
if (_weapon == primaryWeapon _unit) exitWith {};
private _magazines = getArray (configFile / "CfgWeapons" / (primaryWeapon _unit) / "magazines");
{_unit removeMagazines _x} forEach _magazines; // Broken, doesn't remove mags globally. Pain to fix.
_unit removeWeapon (primaryWeapon _unit);
};

private _categories = _weapon call A3A_fnc_equipmentClassToCategories;

if ("GrenadeLaunchers" in _categories && {"Rifles" in _categories} ) then {
// lookup real underbarrel GL magazine, because not everything is 40mm
private _config = configFile >> "CfgWeapons" >> _weapon;
private _glmuzzle = getArray (_config >> "muzzles") select 1; // guaranteed by category
_glmuzzle = configName (_config >> _glmuzzle); // bad-case fix. compatibleMagazines is case-sensitive as of 2.12
private _glmag = compatibleMagazines [_weapon, _glmuzzle] select 0;
_unit addMagazines [_glmag, 5];
};

private _magazine = compatibleMagazines _weapon select 0;
private _magweight = 5 max getNumber (configFile >> "CfgMagazines" >> _magazine >> "mass");

_unit addWeapon _weapon;
if ("Handguns" in _categories) then {
_unit addHandgunItem _magazine;
} else {
_unit addPrimaryWeaponItem _magazine;
};
_unit addMagazines [_magazine, round (random 0.5 + _totalMagWeight / _magWeight)];


private _compatOptics = A3A_rebelOpticsCache get _weapon;
if (isNil "_compatOptics") then {
private _compatItems = compatibleItems _weapon;

_compatOptics = _compatItems arrayIntersect (A3A_rebelGear get _opticType);
if (_compatOptics isEqualTo [] and _opticType != "OpticsClose") then {
private _fallbackType = ["OpticsClose", "OpticsMid"] select (_opticType == "OpticsLong");
_compatOptics = _compatItems arrayIntersect (A3A_rebelGear get _fallbackType);
};
A3A_rebelOpticsCache set [_weapon, _compatOptics];
};
if (_compatOptics isNotEqualTo []) then { _unit addPrimaryWeaponItem (selectRandom _compatOptics) };
65 changes: 10 additions & 55 deletions A3A/addons/core/functions/Ammunition/fn_randomRifle.sqf
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/*
Equip unit with random weapon of preferred type using A3A_rebelGear
Adds magazines by mass. Uses default magazine of selected weapon
Select random rebel weapon of preferred type using A3A_rebelGear
Parameters:
0. <OBJECT> Rebel unit to equip with primary weapon.
1. <STRING> Preferred weapon type ("Rifles", "MachineGuns" etc).
2. <NUMBER> Optional, total mass of carried magazines to add.
0. <STRING> Preferred weapon type ("Rifles", "MachineGuns" etc).
Returns:
Nothing
<STRING> Weapon classname selected
Environment:
Scheduled, any machine
Expand All @@ -17,7 +14,7 @@ Environment:
#include "..\..\script_component.hpp"
FIX_LINE_NUMBERS()

params ["_unit", "_weaponType", ["_totalMagWeight", 50]];
params ["_weaponType"];

call A3A_fnc_fetchRebelGear; // Send current version of rebelGear from server if we're out of date

Expand All @@ -27,55 +24,13 @@ if (_pool isEqualTo []) then {
if (_pool isEqualTo []) then {
_pool = A3A_rebelGear get "SMGs";
if (_pool isEqualTo []) then {
_pool = (A3A_rebelGear get "Shotguns") + (A3A_rebelGear get "SniperRifles");
private _pistolPool = A3A_rebelGear get "Handguns";
for "_i" from 1 to (count _pistolPool) step 2 do {
_pistolPool set [_i, 0.5]
};
_pool = (A3A_rebelGear get "Shotguns") + (A3A_rebelGear get "SniperRifles") + _pistolPool;
};
};
};
private _weapon = selectRandomWeighted _pool;

// Probably shouldn't ever be executed
if !(primaryWeapon _unit isEqualTo "") then {
if (_weapon == primaryWeapon _unit) exitWith {};
private _magazines = getArray (configFile / "CfgWeapons" / (primaryWeapon _unit) / "magazines");
{_unit removeMagazines _x} forEach _magazines; // Broken, doesn't remove mags globally. Pain to fix.
_unit removeWeapon (primaryWeapon _unit);
};

private _categories = _weapon call A3A_fnc_equipmentClassToCategories;

if ("GrenadeLaunchers" in _categories && {"Rifles" in _categories} ) then {
// lookup real underbarrel GL magazine, because not everything is 40mm
private _config = configFile >> "CfgWeapons" >> _weapon;
private _glmuzzle = getArray (_config >> "muzzles") select 1; // guaranteed by category
_glmuzzle = configName (_config >> _glmuzzle); // bad-case fix. compatibleMagazines is case-sensitive as of 2.12
private _glmag = compatibleMagazines [_weapon, _glmuzzle] select 0;
if (!isNil "_glmag") then {
_unit addMagazines [_glmag, 5];
};
};

private _magazine = compatibleMagazines _weapon select 0;
private _magweight = 5 max getNumber (configFile >> "CfgMagazines" >> _magazine >> "mass");

_unit addWeapon _weapon;
_unit addPrimaryWeaponItem _magazine;
_unit addMagazines [_magazine, round (random 0.5 + _totalMagWeight / _magWeight)];


private _compatOptics = A3A_rebelOpticsCache get _weapon;
if (isNil "_compatOptics") then {
private _compatItems = compatibleItems _weapon; // cached, should be fast // cached, should be fast
_compatOptics = _compatItems arrayIntersect call {
if (_weaponType in ["Rifles", "MachineGuns"]) exitWith { A3A_rebelGear get "OpticsMid" };
if (_weaponType == "SniperRifles") exitWith { A3A_rebelGear get "OpticsLong" };
A3A_rebelGear get "OpticsClose";
};
if (_compatOptics isEqualTo []) then {
_compatOptics = _compatItems arrayIntersect call {
if (_weaponType in ["Rifles", "MachineGuns"]) exitWith { A3A_rebelGear get "OpticsClose" };
A3A_rebelGear get "OpticsMid";
};
};
A3A_rebelOpticsCache set [_weapon, _compatOptics];
};
if (_compatOptics isNotEqualTo []) then { _unit addPrimaryWeaponItem (selectRandom _compatOptics) };
_weapon;
3 changes: 2 additions & 1 deletion A3A/addons/core/functions/Base/fn_initPetros.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ removeGoggles petros;
private _vest = selectRandomWeighted (A3A_rebelGear get "ArmoredVests");
if (_vest == "") then { _vest = selectRandomWeighted (A3A_rebelGear get "CivilianVests") };
petros addVest _vest;
[petros, "Rifles"] call A3A_fnc_randomRifle;
private _weapon = ["Rifles"] call A3A_fnc_randomRifle;
[petros, _weapon, "OpticsMid", 50] call A3A_fnc_addPrimaryAndMags;
petros selectWeapon (primaryWeapon petros);

if (petros == leader group petros) then {
Expand Down
Loading

0 comments on commit e026d19

Please sign in to comment.