mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #3276 from acemod/156selectapply
replace filter and map with select and apply
This commit is contained in:
commit
be8f7f9cc0
@ -16,7 +16,7 @@
|
||||
|
||||
params ["_unit", "_target", ["_exceptions", []]];
|
||||
|
||||
_exceptions = [_exceptions, {toLower _this}] call FUNC(map);
|
||||
_exceptions = _exceptions apply {toLower _x};
|
||||
|
||||
private _owner = _target getVariable [QGVAR(owner), objNull];
|
||||
|
||||
|
@ -21,8 +21,8 @@ ACE_LOGINFO_1("ACE is version %1.",_version);
|
||||
|
||||
//private _addons = activatedAddons; // broken with High-Command module, see #2134
|
||||
private _addons = "true" configClasses (configFile >> "CfgPatches");//
|
||||
_addons = [_addons, {toLower configName _this}] call FUNC(map);//
|
||||
_addons = [_addons, {_this find "ace_" == 0}] call FUNC(filter);
|
||||
_addons = _addons apply {toLower configName _x};//
|
||||
_addons = _addons select {_x find "ace_" == 0};
|
||||
|
||||
{
|
||||
if (getText (configFile >> "CfgPatches" >> _x >> "versionStr") != _version) then {
|
||||
@ -63,7 +63,7 @@ _addons = [_addons, {_this find "ace_" == 0}] call FUNC(filter);
|
||||
///////////////
|
||||
if (isMultiplayer) then {
|
||||
// don't check optional addons
|
||||
_addons = [_addons, {getNumber (configFile >> "CfgPatches" >> _this >> "ACE_isOptional") != 1}] call FUNC(filter);
|
||||
_addons = _addons select {getNumber (configFile >> "CfgPatches" >> _x >> "ACE_isOptional") != 1};
|
||||
|
||||
if (isServer) then {
|
||||
// send servers version of ACE to all clients
|
||||
|
@ -9,15 +9,16 @@
|
||||
* Return Value:
|
||||
* Final array
|
||||
*
|
||||
* Usage:
|
||||
* [[0,1,2,3,4], {_this > 2}] call FUNC(filter) ==> [3,4]
|
||||
*
|
||||
* Public: Yes
|
||||
*
|
||||
* Deprecated
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params [["_array", [], [[]]], ["_code", {}, [{}]]];
|
||||
|
||||
ACE_DEPRECATED("ace_common_fnc_filter","3.7.0","select CODE");
|
||||
|
||||
private _result = [];
|
||||
|
||||
{
|
||||
|
@ -16,4 +16,4 @@ params ["_name", "_cfgClass"];
|
||||
|
||||
private _classes = format ["configName inheritsFrom _x == '%1'", _name] configClasses (configFile >> _cfgClass);
|
||||
|
||||
[_classes, {configName _this}] call FUNC(map) // return
|
||||
_classes apply {configName _x} // return
|
||||
|
@ -14,4 +14,4 @@
|
||||
|
||||
params [["_vehicle", objNull, [objNull]]];
|
||||
|
||||
[crew _vehicle, {getText (configFile >> "CfgVehicles" >> typeOf _this >> "simulation") == "UAVPilot"}] call FUNC(filter) // return
|
||||
crew _vehicle select {getText (configFile >> "CfgVehicles" >> typeOf _x >> "simulation") == "UAVPilot"} // return
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: KoffeinFlummi, commy2
|
||||
* Applies given code to every element in an array, LIKE SOMETHING SQF SHOULD HAVE BY DEFAULT.
|
||||
* Applies given code to every element in an array, LIKE SOMETHING SQF SHOULD HAVE BY DEFAULT. <- :kappa:
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Array to be thingied.
|
||||
@ -9,15 +9,16 @@
|
||||
* Return Value:
|
||||
* Final array
|
||||
*
|
||||
* Usage:
|
||||
* [["2", "gobblecock", "25"], {parseNumber _this}] call FUNC(map) ==> [2, 0, 25]
|
||||
*
|
||||
* Public: Yes
|
||||
*
|
||||
* Deprecated
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params [["_array", [], [[]]], ["_code", {}, [{}]]];
|
||||
|
||||
ACE_DEPRECATED("ace_common_fnc_map","3.7.0","apply");
|
||||
|
||||
// copy array to not alter the original one
|
||||
_array = + _array;
|
||||
|
||||
|
@ -19,7 +19,7 @@ params [["_unit", objNull, [objNull]], ["_magazineType", "", [""]], ["_ammoCount
|
||||
private _isRemoved = false;
|
||||
|
||||
// Check uniform
|
||||
private _magazines = [magazinesAmmoCargo uniformContainer _unit, {_this select 0 == _magazineType}] call FUNC(filter);
|
||||
private _magazines = magazinesAmmoCargo uniformContainer _unit select {_x select 0 == _magazineType};
|
||||
private _index = _magazines find [_magazineType, _ammoCount];
|
||||
|
||||
if (_index > -1) exitWith {
|
||||
@ -39,7 +39,7 @@ if (_index > -1) exitWith {
|
||||
};
|
||||
|
||||
// Check vest
|
||||
_magazines = [magazinesAmmoCargo vestContainer _unit, {_this select 0 == _magazineType}] call FUNC(filter);
|
||||
_magazines = magazinesAmmoCargo vestContainer _unit select {_x select 0 == _magazineType};
|
||||
_index = _magazines find [_magazineType, _ammoCount];
|
||||
|
||||
if (_index > -1) exitWith {
|
||||
@ -59,7 +59,7 @@ if (_index > -1) exitWith {
|
||||
};
|
||||
|
||||
// Check backpack
|
||||
_magazines = [magazinesAmmoCargo backpackContainer _unit, {_this select 0 == _magazineType}] call FUNC(filter);
|
||||
_magazines = magazinesAmmoCargo backpackContainer _unit select {_x select 0 == _magazineType};
|
||||
_index = _magazines find [_magazineType, _ammoCount];
|
||||
|
||||
if (_index > -1) exitWith {
|
||||
|
@ -19,16 +19,7 @@
|
||||
params ["_unit"];
|
||||
TRACE_1("params",_unit);
|
||||
|
||||
private ["_items", "_result", "_config"];
|
||||
|
||||
_items = (items _unit);
|
||||
_result = [];
|
||||
|
||||
{
|
||||
_config = ConfigFile >> "CfgWeapons" >> _x;
|
||||
if (getNumber (_config >> QGVAR(Detonator)) == 1 && {!(_x in _result)}) then {
|
||||
_result pushBack _x;
|
||||
};
|
||||
} forEach _items;
|
||||
private _result = (items _unit) select {getNumber (ConfigFile >> "CfgWeapons" >> _x >> QGVAR(Detonator)) == 1};
|
||||
_result = _result arrayIntersect _result;
|
||||
|
||||
_result
|
||||
|
@ -43,10 +43,7 @@ private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret
|
||||
} count _muzzles;
|
||||
|
||||
// Fix the `in` operator being case sensitive and BI fucking up the spelling of their own classnames
|
||||
private _weaponMagazinesCheck = [];
|
||||
{
|
||||
_weaponMagazinesCheck pushBack (toLower _x);
|
||||
} forEach _weaponMagazines;
|
||||
private _weaponMagazinesCheck = _weaponMagazines apply {toLower _x};
|
||||
|
||||
// Another BIS fix: ShotBullet simulation uses weapon initSpeed, others ignore it
|
||||
if (toLower _magazine in _weaponMagazinesCheck && {_bulletSimulation == "shotBullet"}) exitWith {
|
||||
|
@ -21,10 +21,7 @@ params ["_player", "_target", "_weapon"];
|
||||
private ["_compatibleMags", "_filteredMags", "_magToPass", "_magToPassIndex", "_playerName", "_magToPassDisplayName"];
|
||||
|
||||
_compatibleMags = getArray (configfile >> "CfgWeapons" >> _weapon >> "magazines");
|
||||
_filteredMags = [magazinesAmmoFull _player, {
|
||||
params ["_className", "", "_loaded"];
|
||||
_className in _compatibleMags && !_loaded
|
||||
}] call EFUNC(common,filter);
|
||||
_filteredMags = magazinesAmmoFull _player select {(_x select 0) in _compatibleMags && {!(_x select 2)}};
|
||||
|
||||
//select magazine with most ammo
|
||||
_magToPass = _filteredMags select 0;
|
||||
|
@ -18,7 +18,7 @@ GVAR(Grenades_ItemList) = [];
|
||||
} count getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles");
|
||||
|
||||
// make list case insensitive
|
||||
GVAR(Grenades_ItemList) = [GVAR(Grenades_ItemList), {toLower _this}] call EFUNC(common,map);
|
||||
GVAR(Grenades_ItemList) = GVAR(Grenades_ItemList) apply {toLower _x};
|
||||
|
||||
// filter duplicates
|
||||
GVAR(Grenades_ItemList) = GVAR(Grenades_ItemList) arrayIntersect GVAR(Grenades_ItemList);
|
||||
@ -41,8 +41,11 @@ GVAR(Medical_ItemList) = [];
|
||||
("true" configClasses (configFile >> QEGVAR(Medical,Actions) >> "Advanced"))
|
||||
);
|
||||
|
||||
// remove all numbers from list
|
||||
GVAR(Medical_ItemList) = GVAR(Medical_ItemList) select {_x isEqualType ""};
|
||||
|
||||
// make list case insensitive
|
||||
GVAR(Medical_ItemList) = [GVAR(Medical_ItemList), {if (_this isEqualType "") then {toLower _this}}] call EFUNC(common,map);
|
||||
GVAR(Medical_ItemList) = GVAR(Medical_ItemList) apply {toLower _x};
|
||||
|
||||
// filter duplicates
|
||||
GVAR(Medical_ItemList) = GVAR(Medical_ItemList) arrayIntersect GVAR(Medical_ItemList);
|
||||
|
@ -16,15 +16,14 @@ if (GVAR(BFT_Enabled) and {(!isNil "ACE_player") and {alive ACE_player}}) then {
|
||||
_groupsToDrawMarkers = [];
|
||||
_playerSide = call EFUNC(common,playerSide);
|
||||
|
||||
if !(GVAR(BFT_HideAiGroups)) then {
|
||||
_groupsToDrawMarkers = [allGroups, {side _this == _playerSide}] call EFUNC(common,filter);
|
||||
} else {
|
||||
_groupsToDrawMarkers = [allGroups, {
|
||||
_anyPlayers = {
|
||||
[_x] call EFUNC(common,isPlayer);
|
||||
} count units _this;
|
||||
(side _this == _playerSide) && _anyPlayers > 0
|
||||
}] call EFUNC(common,filter);
|
||||
_groupsToDrawMarkers = allGroups select {side _x == _playerSide};
|
||||
|
||||
if (GVAR(BFT_HideAiGroups)) then {
|
||||
_groupsToDrawMarkers = _groupsToDrawMarkers select {
|
||||
{
|
||||
_x call EFUNC(common,isPlayer);
|
||||
} count units _x > 0;
|
||||
};
|
||||
};
|
||||
|
||||
{
|
||||
|
@ -90,26 +90,21 @@ TRACE_1("Player is on foot or in an open vehicle","");
|
||||
_lightLevel = _lightLevel max ([_unit, _x] call EFUNC(common,lightIntensityFromObject));
|
||||
} forEach nearestObjects [_unit, ["All"], 40];
|
||||
|
||||
|
||||
// @todo: Illumination flares (timed)
|
||||
|
||||
|
||||
// Using chemlights
|
||||
_nearObjects = [_unit nearObjects ["SmokeShell", 4], {
|
||||
alive _this && {(typeOf _this == "Chemlight_red") || {
|
||||
(typeOf _this == "Chemlight_green") || {
|
||||
(typeOf _this == "Chemlight_blue") || {
|
||||
(typeOf _this == "Chemlight_yellow")}}}}}] call EFUNC(common,filter);
|
||||
_nearObjects = (_unit nearObjects ["SmokeShell", 4]) select {alive _x && {toLower typeOf _x in ["chemlight_red", "chemlight_green", "chemlight_blue", "chemlight_yellow"]}};
|
||||
|
||||
if (count (_nearObjects) > 0) then {
|
||||
_light = _nearObjects select 0;
|
||||
|
||||
_ll = (1 - ((((_unit distance _light) - 2)/2) max 0)) * 0.4;
|
||||
if (_ll > _lightLevel) then {
|
||||
_flareTint = switch (typeOf _light) do {
|
||||
case "Chemlight_red" : {[1,0,0,1]};
|
||||
case "Chemlight_green" : {[0,1,0,1]};
|
||||
case "Chemlight_blue" : {[0,0,1,1]};
|
||||
case "Chemlight_yellow" : {[1,1,0,1]};
|
||||
_flareTint = switch (toLower typeOf _light) do {
|
||||
case "chemlight_red" : {[1,0,0,1]};
|
||||
case "chemlight_green" : {[0,1,0,1]};
|
||||
case "chemlight_blue" : {[0,0,1,1]};
|
||||
case "chemlight_yellow" : {[1,1,0,1]};
|
||||
};
|
||||
_lightTint = [_lightTint, _flareTint, (_ll - _lightLevel)/(1 - _lightLevel)] call _fnc_blendColor;
|
||||
_lightLevel = _ll;
|
||||
|
@ -47,8 +47,7 @@ if !(_selection in _selections) exitWith {
|
||||
_unit setHitPointDamage [_selection, _damage];
|
||||
};
|
||||
|
||||
GVAR(unit) = _unit;
|
||||
_damages = [_selections, {GVAR(unit) getHitPointDamage _this}] call EFUNC(common,map);
|
||||
_damages = _selections apply {_unit getHitPointDamage _x};
|
||||
|
||||
_damageOld = damage _unit;
|
||||
_damageSumOld = 0;
|
||||
|
@ -18,23 +18,19 @@
|
||||
|
||||
private["_roleImages", "_player", "_vehicle", "_type", "_config", "_text", "_data", "_isAir", "_turretUnits", "_turretRoles", "_index", "_roleType", "_unit", "_toShow"];
|
||||
|
||||
|
||||
_player = ACE_player;
|
||||
_vehicle = vehicle _player;
|
||||
_type = typeOf _vehicle;
|
||||
_config = configFile >> "CfgVehicles" >> _type;
|
||||
_text = format["<t size='1.4'><img image='%1'></t> <t size='1.7' shadow='true'>%2</t><br/>", getText(_config>>"picture"), getText (_config >> "DisplayName")];
|
||||
|
||||
|
||||
|
||||
_data = [_type] call FUNC(getVehicleData);
|
||||
|
||||
_isAir = _data select 0;
|
||||
_data = _data select 1;
|
||||
|
||||
_turretUnits = [_data, { _vehicle turretUnit (_x select 0) } ] call EFUNC(common,map);
|
||||
_turretRoles = [_data, { _x select 1 } ] call EFUNC(common,map);
|
||||
|
||||
_turretUnits = _data apply {_vehicle turretUnit (_x select 0)};
|
||||
_turretRoles = _data apply {_x select 1};
|
||||
|
||||
_roleType = CARGO;
|
||||
_toShow = [];
|
||||
@ -61,7 +57,6 @@ _toShow = [];
|
||||
_toShow pushBack [_x, _roleType];
|
||||
} forEach crew _vehicle;
|
||||
|
||||
|
||||
_toShow = [
|
||||
_toShow,
|
||||
[],
|
||||
@ -75,7 +70,6 @@ _toShow = [
|
||||
}
|
||||
] call BIS_fnc_sortBy;
|
||||
|
||||
|
||||
_roleImages = ROLE_IMAGES;
|
||||
{
|
||||
_unit = _x select 0;
|
||||
@ -83,7 +77,6 @@ _roleImages = ROLE_IMAGES;
|
||||
_text = _text + format["<t size='1.5' shadow='true'>%1</t> <t size='1.3'><img image='%2'></t><br/>", [_unit] call EFUNC(common,getName), _roleImages select _roleType];
|
||||
} forEach _toShow;
|
||||
|
||||
|
||||
("ACE_CrewInfo_CrewInfo" call BIS_fnc_rscLayer) cutRsc ["ACE_CrewInfo_dialog", "PLAIN", 1, false];
|
||||
|
||||
terminate (missionNamespace getVariable [QGVAR(hideCrewInfoHandle), scriptNull]);
|
||||
|
@ -32,6 +32,6 @@ private _maxAmmo = 0;
|
||||
|
||||
{
|
||||
_maxAmmo = _maxAmmo max (_x select 1);
|
||||
} forEach ([magazinesAmmo _player, {_this select 0 == _magazineType}] call EFUNC(common,filter));
|
||||
} forEach (magazinesAmmo _player select {_x select 0 == _magazineType});
|
||||
|
||||
_maxAmmo > 0
|
||||
|
@ -32,7 +32,7 @@ private _maxAmmo = 0;
|
||||
|
||||
{
|
||||
_maxAmmo = _maxAmmo max (_x select 1);
|
||||
} forEach ([magazinesAmmo _player, {_this select 0 == _magazineType}] call EFUNC(common,filter));
|
||||
} forEach (magazinesAmmo _player select {_x select 0 == _magazineType});
|
||||
|
||||
if (_maxAmmo == 0) exitWith {};
|
||||
|
||||
|
@ -22,7 +22,7 @@ private "_magazines";
|
||||
_magazines = magazines _unit;
|
||||
|
||||
// case sensitvity
|
||||
_magazines = [_magazines, {toLower _this}] call EFUNC(common,map);
|
||||
_magazines = _magazines apply {toLower _x};
|
||||
|
||||
// get reloaders magazine types compatible with targets launcher. No duplicates.
|
||||
[getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"), {toLower _this in _magazines}] call EFUNC(common,filter)
|
||||
getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select {toLower _x in _magazines} // return
|
||||
|
@ -42,7 +42,7 @@ playSound selectRandom ["ACE_Scopes_Click_1", "ACE_Scopes_Click_2", "ACE_Scopes_
|
||||
// slightly rotate the player if looking through optic
|
||||
if (cameraView == "GUNNER") then {
|
||||
// Convert adjustmentDifference from mils to degrees
|
||||
_adjustmentDifference = [_adjustmentDifference, {_this * 0.05625}] call EFUNC(common,map);
|
||||
_adjustmentDifference = _adjustmentDifference apply {_x * 0.05625};
|
||||
_adjustmentDifference params ["_elevationDifference", "_windageDifference"];
|
||||
_pitchBankYaw = [_unit] call EFUNC(common,getPitchBankYaw);
|
||||
_pitchBankYaw params ["_pitch", "_bank", "_yaw"];
|
||||
|
@ -25,7 +25,7 @@ private _leave = false;
|
||||
|
||||
if (GVAR(EnableSafeZone)) then {
|
||||
private _allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers);
|
||||
private _nearestEnemyPlayers = [_allNearestPlayers, {((side GVAR(OriginalGroup)) getFriend (side _this) < 0.6) && !(_this getVariable [QGVAR(IsPlayerControlled), false])}] call EFUNC(common,filter);
|
||||
private _nearestEnemyPlayers = _allNearestPlayers select {((side GVAR(OriginalGroup)) getFriend side _x < 0.6) && !(_x getVariable [QGVAR(IsPlayerControlled), false])};
|
||||
|
||||
if (count _nearestEnemyPlayers > 0) exitWith {
|
||||
_leave = true;
|
||||
|
@ -57,9 +57,9 @@ private _nextGrenade = _grenades select _nextGrenadeIndex;
|
||||
if (_currentGrenade == _nextGrenade) exitWith {false};
|
||||
|
||||
// current best method to select a grenade: remove all grenades except the one you want to select, then add them back
|
||||
private _uniformGrenades = [uniformItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter);
|
||||
private _vestGrenades = [vestItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter);
|
||||
private _backpackGrenades = [backpackItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter);
|
||||
private _uniformGrenades = uniformItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}};
|
||||
private _vestGrenades = vestItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}};
|
||||
private _backpackGrenades = backpackItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}};
|
||||
|
||||
// remove all grenades except those we are switching to --> this breaks the selector
|
||||
{_unit removeItemFromUniform _x; false} count _uniformGrenades;
|
||||
|
Loading…
Reference in New Issue
Block a user