Skip to content

Commit

Permalink
Now use BIS_fnc_itemType
Browse files Browse the repository at this point in the history
- Use https://community.bistudio.com/wiki/BIS_fnc_itemType as suggested by @mharis001
- also use parent class to seperate GM6 Lynx from rifle weapon
  • Loading branch information
Vdauphin committed Jun 13, 2018
1 parent 2247b91 commit 6bca237
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 39 deletions.
2 changes: 1 addition & 1 deletion =BTC=co@30_Hearts_and_Minds.Altis/core/def/param.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class Params {
title = __EVAL(format [" %1", localize "STR_BTC_HAM_PARAM_ARSENAL_ARSENALTYPE"]);
values[]={0,1,2,3,4};
texts[]={$STR_BTC_HAM_PARAM_ARSENAL_ARSENALTYPE_BIS,$STR_BTC_HAM_PARAM_ARSENAL_ARSENALTYPE_BA,$STR_BTC_HAM_PARAM_ARSENAL_ARSENALTYPE_BA_PLUS,$STR_BTC_HAM_PARAM_ARSENAL_ARSENALTYPE_ACE,$STR_BTC_HAM_PARAM_ARSENAL_ARSENALTYPE_ACE_PLUS}; //texts[]={"BIS - Vanilla","BIS - Vanilla and ACE 3","BIS - Vanilla and ACE 3 (scroll wheel action)","ACE 3","ACE 3 (scroll wheel action)"};
default = 3;
default = 4;
};
class btc_p_arsenal_Restrict { // Restricted arsenal (See /define_mod.sqf):
title = __EVAL(format [" %1", localize "STR_BTC_HAM_PARAM_ARSENAL_ARSENALRESTR"]);
Expand Down
44 changes: 30 additions & 14 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/arsenal/ammoUsage.sqf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
params [
["_weapons", [], [[]]],
["_aiAmmoUsageFlags", "256", [""]],
["_irLock", 1, [0]]
["_weapons", ["launch_RPG7_F"], [[]]],
["_itemType_ammo_usageAllowed", ["MissileLauncher", "256", []], [[]]]
];
_itemType_ammo_usageAllowed params [["_itemType", "MissileLauncher", [""]], ["_ammo_usageAllowed", "256", [""]], ["_parent_array", [], [[]]]];

private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";
Expand All @@ -12,23 +12,39 @@ _weapons select {
private _weapon = _x;
private _magazines = getArray (_cfgWeapons >> _weapon >> "magazines");

private _aiAmmoUsage_irLock_magazines = _magazines apply {
private _ammo = getText (_cfgMagazines >> _x >> "ammo");
private _isAllowed = if (_ammo_usageAllowed isEqualTo "") then {
true
} else {
private _aiAmmoUsage_magazines = _magazines apply {
private _ammo = getText (_cfgMagazines >> _x >> "ammo");

private _aiAmmoUsage = getText (_cfgAmmo >> _ammo >> "aiAmmoUsageFlags");
if (_aiAmmoUsage isEqualTo "") then {
_aiAmmoUsage = str getNumber (_cfgAmmo >> _ammo >> "aiAmmoUsageFlags");
private _aiAmmoUsage = getText (_cfgAmmo >> _ammo >> "aiAmmoUsageFlags");
if (_aiAmmoUsage isEqualTo "") then {
_aiAmmoUsage = str getNumber (_cfgAmmo >> _ammo >> "aiAmmoUsageFlags");
};

_aiAmmoUsage;
};

if (btc_debug_log) then {
if ("" in _aiAmmoUsage_magazines) then {
[format ["Weapons: %1 AiAmmoUsage Magazines: %2", _weapon, _aiAmmoUsage_magazines], __FILE__, [false]] call btc_fnc_debug_message;
};
};
private _ammo_irLock = getNumber (_cfgAmmo >> _ammo >> "irLock");

[_aiAmmoUsage, _ammo_irLock];
_ammo_usageAllowed in _aiAmmoUsage_magazines
};

if (btc_debug_log) then {
if ("" in (_aiAmmoUsage_irLock_magazines apply {_x select 0})) then {
[format ["Weapons: %1 AiAmmoUsage Magazines: %2", _weapon, _aiAmmoUsage_irLock_magazines], __FILE__, [false]] call btc_fnc_debug_message;
private _isParent = if (_parent_array isEqualTo []) then {
true
} else {
_parent_array params ["_not", "_parent_type"];
if (_not) then {
_weapon isKindOf [_parent_type, _cfgWeapons]
} else {
!(_weapon isKindOf [_parent_type, _cfgWeapons])
};
};

_aiAmmoUsageFlags in (_aiAmmoUsage_irLock_magazines apply {_x select 0}) && selectMax (_aiAmmoUsage_irLock_magazines apply {_x select 1}) <= _irLock;
(_itemType in (_weapon call BIS_fnc_itemType)) && {_isAllowed} && {_isParent}
};
32 changes: 16 additions & 16 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/arsenal/trait.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ params [
["_player", objNull, [objNull]]
];

// 0 - Rifleman, 1 - Medic Adv, 2 - Medic Basic, 3 - Repair, 4 - Engineer, 5 - Anti-Tank, 6 - Anti Air, 7 - Sniper/Machine gunner, 8 - Diver
// 0 - Rifleman, 1 - Medic Adv, 2 - Medic Basic, 3 - Repair, 4 - Engineer, 5 - Anti-Tank, 6 - Anti Air, 7 - Sniper, 8 - Machine gunner
// https://community.bistudio.com/wiki/CfgAmmo_Config_Reference#aiAmmoUsageFlags
private _type_ammoUsageAllowed = [];
switch (true) do {
case ((_player getUnitTrait "medic") && (ace_medical_level isEqualTo 1)): {
_type_ammoUsageAllowed = [1, ["64"], 0];
_type_ammoUsageAllowed = [1, [["AssaultRifle", "", [false, "Rifle_Long_Base_F"]]]];
};
case ((_player getUnitTrait "medic") && (ace_medical_level isEqualTo 2)): {
_type_ammoUsageAllowed = [2, ["64"], 0];
_type_ammoUsageAllowed = [2, [["AssaultRifle", "", [false, "Rifle_Long_Base_F"]]]];
};
case (_player getVariable ["ace_isEngineer", 0] in [1, 2]): {
_type_ammoUsageAllowed = [3, ["64"], 0];
_type_ammoUsageAllowed = [3, [["AssaultRifle", "", [false, "Rifle_Long_Base_F"]]]];
};
case (_player getUnitTrait "explosiveSpecialist"): {
_type_ammoUsageAllowed = [4, ["64", "16"], 0];
_type_ammoUsageAllowed = [4, [["AssaultRifle", "", [false, "Rifle_Long_Base_F"]]]];
};
case ([typeOf _player, "128 + 512"] call btc_fnc_mil_ammoUsage): {
_type_ammoUsageAllowed = [5, ["64", "128 + 512"], 1];
case ([typeOf _player, ["MissileLauncher", "128 + 512"]] call btc_fnc_mil_ammoUsage): {
_type_ammoUsageAllowed = [5, [["AssaultRifle", "", [false, "Rifle_Long_Base_F"]], ["RocketLauncher", ""], ["MissileLauncher", "128 + 512"]]];
};
case ([typeOf _player] call btc_fnc_mil_ammoUsage): {
_type_ammoUsageAllowed = [6, ["64", "256"], 1];
case ([typeOf _player, ["MissileLauncher", "256"]] call btc_fnc_mil_ammoUsage): {
_type_ammoUsageAllowed = [6, [["AssaultRifle", "", [false, "Rifle_Long_Base_F"]], ["MissileLauncher", "256"]]];
};
case ([typeOf _player, "64 + 128 + 256"] call btc_fnc_mil_ammoUsage): {
_type_ammoUsageAllowed = [7, ["64 + 128 + 256"], 0];
case ([typeOf _player, ["SniperRifle", ""]] call btc_fnc_mil_ammoUsage): {
_type_ammoUsageAllowed = [7, [["AssaultRifle", "64 + 128 + 256", [true, "Rifle_Long_Base_F"]], ["SniperRifle", ""]]];
};
case ([typeOf _player, "64 + 32"] call btc_fnc_mil_ammoUsage): {
_type_ammoUsageAllowed = [8, ["64 + 32"], 0];
case ([typeOf _player, ["MachineGun", ""]] call btc_fnc_mil_ammoUsage): {
_type_ammoUsageAllowed = [8, [["MachineGun", ""]]];
};
default {
_type_ammoUsageAllowed = [0, ["64", "64 + 128", "128 + 512"], 0];
_type_ammoUsageAllowed = [0, [["AssaultRifle", "", [false, "Rifle_Long_Base_F"]], ["RocketLauncher", ""]]];
};
};

Expand All @@ -42,8 +42,8 @@ if (btc_debug || btc_debug_log) then {
(_player getUnitTrait "medic") && (ace_medical_level isEqualTo 2),
_player getVariable ["ace_isEngineer", 0],
_player getUnitTrait "explosiveSpecialist",
[typeOf _player, "128 + 512"] call btc_fnc_mil_ammoUsage,
[typeOf _player] call btc_fnc_mil_ammoUsage
[typeOf _player, ["MissileLauncher", "128 + 512"]] call btc_fnc_mil_ammoUsage,
[typeOf _player, ["MissileLauncher", "256"]] call btc_fnc_mil_ammoUsage
], __FILE__, [btc_debug, btc_debug_log]
] call btc_fnc_debug_message;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
params [
["_trait", [0, ["64", "64 + 128", "128 + 512"], 0], [[]]],
["_trait", [0, [["AssaultRifle", ""], ["RocketLauncher", ""]]], [[]]],
["_custom_arsenal", btc_custom_arsenal, [[]]],
["_arsenalRestrict", btc_p_arsenal_Restrict, [0]],
["_type_units", btc_type_units, [[]]]
];
_trait params ["_type", "_ammo_usageAllowed", "_canlock"];
_trait params ["_type", "_itemType_ammo_usageAllowed"];

private _weapons = ("true" configClasses (configFile >> "CfgWeapons") select {
getNumber (_x >> "scope") isEqualTo 2 &&
Expand All @@ -13,8 +13,8 @@ private _weapons = ("true" configClasses (configFile >> "CfgWeapons") select {

private _allowedWeapons = [];
{
_allowedWeapons append ([_weapons, _x, _canlock] call btc_fnc_arsenal_ammoUsage);
} forEach _ammo_usageAllowed;
_allowedWeapons append ([_weapons, _x] call btc_fnc_arsenal_ammoUsage);
} forEach _itemType_ammo_usageAllowed;

private _enemyWeapons = [];
{
Expand Down
4 changes: 2 additions & 2 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/mil/ammoUsage.sqf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
params [
["_typeof_unit", "", [""]],
["_aiAmmoUsageFlags", "256", [""]]
["_itemType_ammo_usageAllowed", ["MissileLauncher", "256", []], [[]]]
];

private _weapons = getArray (configFile >> "CfgVehicles" >> _typeof_unit >> "weapons");
private _weapons_ammoUsage = [_weapons, _itemType_ammo_usageAllowed] call btc_fnc_arsenal_ammoUsage;

private _weapons_ammoUsage = [_weapons, _aiAmmoUsageFlags] call btc_fnc_arsenal_ammoUsage;
if (btc_debug_log) then {
[format ["%1 Weapons: %2 isAmmoUsage: %3", _typeof_unit, _weapons, _weapons_ammoUsage], __FILE__, [false]] call btc_fnc_debug_message;
};
Expand Down
4 changes: 2 additions & 2 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/mil/class.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (_enemy_side isEqualTo btc_player_side) exitWith {
private _allclass_f = _allclass select {(toUpper getText (_cfgVehicles >> _x >> "faction")) isEqualTo _faction};

//Units
_divers = _allclass_f select {[_x, "64 + 32"] call btc_fnc_mil_ammoUsage};
_divers = _allclass_f select {[_x, ["AssaultRifle", "64 + 32"]] call btc_fnc_mil_ammoUsage};
if (_divers isEqualTo []) then {
_divers = if (_enemy_side isEqualTo east) then {
["O_diver_F", "O_diver_exp_F", "O_diver_TL_F"]
Expand Down Expand Up @@ -79,7 +79,7 @@ if (_enemy_side isEqualTo btc_player_side) exitWith {
//Final filter unwanted units type
if !(_en_AA) then {
//Remove Anti-Air Units
_type_units = _type_units select {!(_x call btc_fnc_mil_ammoUsage)};
_type_units = _type_units select {!([_x, ["MissileLauncher", "256"]] call btc_fnc_mil_ammoUsage)};
};
_type_units = _type_units select {((_x find "pilot_") isEqualTo -1) && ((_x find "_Pilot_") isEqualTo -1) && ((_x find "_Survivor_") isEqualTo -1) && ((_x find "_Story") isEqualTo -1) && ((_x find "_base") isEqualTo -1) && ((_x find "_unarmed_") isEqualTo -1) && ((_x find "_VR_") isEqualTo -1)};
_type_crewmen = _type_units select 0;
Expand Down

0 comments on commit 6bca237

Please sign in to comment.