Merge pull request #3276 from acemod/156selectapply

replace filter and map with select and apply
This commit is contained in:
commy2 2016-02-18 14:23:02 +01:00
commit be8f7f9cc0
21 changed files with 54 additions and 78 deletions

View File

@ -16,7 +16,7 @@
params ["_unit", "_target", ["_exceptions", []]]; params ["_unit", "_target", ["_exceptions", []]];
_exceptions = [_exceptions, {toLower _this}] call FUNC(map); _exceptions = _exceptions apply {toLower _x};
private _owner = _target getVariable [QGVAR(owner), objNull]; private _owner = _target getVariable [QGVAR(owner), objNull];

View File

@ -21,8 +21,8 @@ ACE_LOGINFO_1("ACE is version %1.",_version);
//private _addons = activatedAddons; // broken with High-Command module, see #2134 //private _addons = activatedAddons; // broken with High-Command module, see #2134
private _addons = "true" configClasses (configFile >> "CfgPatches");// private _addons = "true" configClasses (configFile >> "CfgPatches");//
_addons = [_addons, {toLower configName _this}] call FUNC(map);// _addons = _addons apply {toLower configName _x};//
_addons = [_addons, {_this find "ace_" == 0}] call FUNC(filter); _addons = _addons select {_x find "ace_" == 0};
{ {
if (getText (configFile >> "CfgPatches" >> _x >> "versionStr") != _version) then { if (getText (configFile >> "CfgPatches" >> _x >> "versionStr") != _version) then {
@ -63,7 +63,7 @@ _addons = [_addons, {_this find "ace_" == 0}] call FUNC(filter);
/////////////// ///////////////
if (isMultiplayer) then { if (isMultiplayer) then {
// don't check optional addons // 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 { if (isServer) then {
// send servers version of ACE to all clients // send servers version of ACE to all clients

View File

@ -9,15 +9,16 @@
* Return Value: * Return Value:
* Final array * Final array
* *
* Usage:
* [[0,1,2,3,4], {_this > 2}] call FUNC(filter) ==> [3,4]
*
* Public: Yes * Public: Yes
*
* Deprecated
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params [["_array", [], [[]]], ["_code", {}, [{}]]]; params [["_array", [], [[]]], ["_code", {}, [{}]]];
ACE_DEPRECATED("ace_common_fnc_filter","3.7.0","select CODE");
private _result = []; private _result = [];
{ {

View File

@ -16,4 +16,4 @@ params ["_name", "_cfgClass"];
private _classes = format ["configName inheritsFrom _x == '%1'", _name] configClasses (configFile >> _cfgClass); private _classes = format ["configName inheritsFrom _x == '%1'", _name] configClasses (configFile >> _cfgClass);
[_classes, {configName _this}] call FUNC(map) // return _classes apply {configName _x} // return

View File

@ -14,4 +14,4 @@
params [["_vehicle", objNull, [objNull]]]; 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

View File

@ -1,6 +1,6 @@
/* /*
* Author: KoffeinFlummi, commy2 * 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: * Arguments:
* 0: Array to be thingied. * 0: Array to be thingied.
@ -9,15 +9,16 @@
* Return Value: * Return Value:
* Final array * Final array
* *
* Usage:
* [["2", "gobblecock", "25"], {parseNumber _this}] call FUNC(map) ==> [2, 0, 25]
*
* Public: Yes * Public: Yes
*
* Deprecated
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params [["_array", [], [[]]], ["_code", {}, [{}]]]; params [["_array", [], [[]]], ["_code", {}, [{}]]];
ACE_DEPRECATED("ace_common_fnc_map","3.7.0","apply");
// copy array to not alter the original one // copy array to not alter the original one
_array = + _array; _array = + _array;

View File

@ -19,7 +19,7 @@ params [["_unit", objNull, [objNull]], ["_magazineType", "", [""]], ["_ammoCount
private _isRemoved = false; private _isRemoved = false;
// Check uniform // 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]; private _index = _magazines find [_magazineType, _ammoCount];
if (_index > -1) exitWith { if (_index > -1) exitWith {
@ -39,7 +39,7 @@ if (_index > -1) exitWith {
}; };
// Check vest // 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]; _index = _magazines find [_magazineType, _ammoCount];
if (_index > -1) exitWith { if (_index > -1) exitWith {
@ -59,7 +59,7 @@ if (_index > -1) exitWith {
}; };
// Check backpack // 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]; _index = _magazines find [_magazineType, _ammoCount];
if (_index > -1) exitWith { if (_index > -1) exitWith {

View File

@ -19,16 +19,7 @@
params ["_unit"]; params ["_unit"];
TRACE_1("params",_unit); TRACE_1("params",_unit);
private ["_items", "_result", "_config"]; private _result = (items _unit) select {getNumber (ConfigFile >> "CfgWeapons" >> _x >> QGVAR(Detonator)) == 1};
_result = _result arrayIntersect _result;
_items = (items _unit);
_result = [];
{
_config = ConfigFile >> "CfgWeapons" >> _x;
if (getNumber (_config >> QGVAR(Detonator)) == 1 && {!(_x in _result)}) then {
_result pushBack _x;
};
} forEach _items;
_result _result

View File

@ -43,10 +43,7 @@ private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret
} count _muzzles; } count _muzzles;
// Fix the `in` operator being case sensitive and BI fucking up the spelling of their own classnames // Fix the `in` operator being case sensitive and BI fucking up the spelling of their own classnames
private _weaponMagazinesCheck = []; private _weaponMagazinesCheck = _weaponMagazines apply {toLower _x};
{
_weaponMagazinesCheck pushBack (toLower _x);
} forEach _weaponMagazines;
// Another BIS fix: ShotBullet simulation uses weapon initSpeed, others ignore it // Another BIS fix: ShotBullet simulation uses weapon initSpeed, others ignore it
if (toLower _magazine in _weaponMagazinesCheck && {_bulletSimulation == "shotBullet"}) exitWith { if (toLower _magazine in _weaponMagazinesCheck && {_bulletSimulation == "shotBullet"}) exitWith {

View File

@ -21,10 +21,7 @@ params ["_player", "_target", "_weapon"];
private ["_compatibleMags", "_filteredMags", "_magToPass", "_magToPassIndex", "_playerName", "_magToPassDisplayName"]; private ["_compatibleMags", "_filteredMags", "_magToPass", "_magToPassIndex", "_playerName", "_magToPassDisplayName"];
_compatibleMags = getArray (configfile >> "CfgWeapons" >> _weapon >> "magazines"); _compatibleMags = getArray (configfile >> "CfgWeapons" >> _weapon >> "magazines");
_filteredMags = [magazinesAmmoFull _player, { _filteredMags = magazinesAmmoFull _player select {(_x select 0) in _compatibleMags && {!(_x select 2)}};
params ["_className", "", "_loaded"];
_className in _compatibleMags && !_loaded
}] call EFUNC(common,filter);
//select magazine with most ammo //select magazine with most ammo
_magToPass = _filteredMags select 0; _magToPass = _filteredMags select 0;

View File

@ -18,7 +18,7 @@ GVAR(Grenades_ItemList) = [];
} count getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles"); } count getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles");
// make list case insensitive // 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 // filter duplicates
GVAR(Grenades_ItemList) = GVAR(Grenades_ItemList) arrayIntersect GVAR(Grenades_ItemList); GVAR(Grenades_ItemList) = GVAR(Grenades_ItemList) arrayIntersect GVAR(Grenades_ItemList);
@ -41,8 +41,11 @@ GVAR(Medical_ItemList) = [];
("true" configClasses (configFile >> QEGVAR(Medical,Actions) >> "Advanced")) ("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 // 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 // filter duplicates
GVAR(Medical_ItemList) = GVAR(Medical_ItemList) arrayIntersect GVAR(Medical_ItemList); GVAR(Medical_ItemList) = GVAR(Medical_ItemList) arrayIntersect GVAR(Medical_ItemList);

View File

@ -16,15 +16,14 @@ if (GVAR(BFT_Enabled) and {(!isNil "ACE_player") and {alive ACE_player}}) then {
_groupsToDrawMarkers = []; _groupsToDrawMarkers = [];
_playerSide = call EFUNC(common,playerSide); _playerSide = call EFUNC(common,playerSide);
if !(GVAR(BFT_HideAiGroups)) then { _groupsToDrawMarkers = allGroups select {side _x == _playerSide};
_groupsToDrawMarkers = [allGroups, {side _this == _playerSide}] call EFUNC(common,filter);
} else { if (GVAR(BFT_HideAiGroups)) then {
_groupsToDrawMarkers = [allGroups, { _groupsToDrawMarkers = _groupsToDrawMarkers select {
_anyPlayers = { {
[_x] call EFUNC(common,isPlayer); _x call EFUNC(common,isPlayer);
} count units _this; } count units _x > 0;
(side _this == _playerSide) && _anyPlayers > 0 };
}] call EFUNC(common,filter);
}; };
{ {

View File

@ -90,26 +90,21 @@ TRACE_1("Player is on foot or in an open vehicle","");
_lightLevel = _lightLevel max ([_unit, _x] call EFUNC(common,lightIntensityFromObject)); _lightLevel = _lightLevel max ([_unit, _x] call EFUNC(common,lightIntensityFromObject));
} forEach nearestObjects [_unit, ["All"], 40]; } forEach nearestObjects [_unit, ["All"], 40];
// @todo: Illumination flares (timed) // @todo: Illumination flares (timed)
// Using chemlights // Using chemlights
_nearObjects = [_unit nearObjects ["SmokeShell", 4], { _nearObjects = (_unit nearObjects ["SmokeShell", 4]) select {alive _x && {toLower typeOf _x in ["chemlight_red", "chemlight_green", "chemlight_blue", "chemlight_yellow"]}};
alive _this && {(typeOf _this == "Chemlight_red") || {
(typeOf _this == "Chemlight_green") || {
(typeOf _this == "Chemlight_blue") || {
(typeOf _this == "Chemlight_yellow")}}}}}] call EFUNC(common,filter);
if (count (_nearObjects) > 0) then { if (count (_nearObjects) > 0) then {
_light = _nearObjects select 0; _light = _nearObjects select 0;
_ll = (1 - ((((_unit distance _light) - 2)/2) max 0)) * 0.4; _ll = (1 - ((((_unit distance _light) - 2)/2) max 0)) * 0.4;
if (_ll > _lightLevel) then { if (_ll > _lightLevel) then {
_flareTint = switch (typeOf _light) do { _flareTint = switch (toLower typeOf _light) do {
case "Chemlight_red" : {[1,0,0,1]}; case "chemlight_red" : {[1,0,0,1]};
case "Chemlight_green" : {[0,1,0,1]}; case "chemlight_green" : {[0,1,0,1]};
case "Chemlight_blue" : {[0,0,1,1]}; case "chemlight_blue" : {[0,0,1,1]};
case "Chemlight_yellow" : {[1,1,0,1]}; case "chemlight_yellow" : {[1,1,0,1]};
}; };
_lightTint = [_lightTint, _flareTint, (_ll - _lightLevel)/(1 - _lightLevel)] call _fnc_blendColor; _lightTint = [_lightTint, _flareTint, (_ll - _lightLevel)/(1 - _lightLevel)] call _fnc_blendColor;
_lightLevel = _ll; _lightLevel = _ll;

View File

@ -47,8 +47,7 @@ if !(_selection in _selections) exitWith {
_unit setHitPointDamage [_selection, _damage]; _unit setHitPointDamage [_selection, _damage];
}; };
GVAR(unit) = _unit; _damages = _selections apply {_unit getHitPointDamage _x};
_damages = [_selections, {GVAR(unit) getHitPointDamage _this}] call EFUNC(common,map);
_damageOld = damage _unit; _damageOld = damage _unit;
_damageSumOld = 0; _damageSumOld = 0;

View File

@ -18,23 +18,19 @@
private["_roleImages", "_player", "_vehicle", "_type", "_config", "_text", "_data", "_isAir", "_turretUnits", "_turretRoles", "_index", "_roleType", "_unit", "_toShow"]; private["_roleImages", "_player", "_vehicle", "_type", "_config", "_text", "_data", "_isAir", "_turretUnits", "_turretRoles", "_index", "_roleType", "_unit", "_toShow"];
_player = ACE_player; _player = ACE_player;
_vehicle = vehicle _player; _vehicle = vehicle _player;
_type = typeOf _vehicle; _type = typeOf _vehicle;
_config = configFile >> "CfgVehicles" >> _type; _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")]; _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); _data = [_type] call FUNC(getVehicleData);
_isAir = _data select 0; _isAir = _data select 0;
_data = _data select 1; _data = _data select 1;
_turretUnits = [_data, { _vehicle turretUnit (_x select 0) } ] call EFUNC(common,map); _turretUnits = _data apply {_vehicle turretUnit (_x select 0)};
_turretRoles = [_data, { _x select 1 } ] call EFUNC(common,map); _turretRoles = _data apply {_x select 1};
_roleType = CARGO; _roleType = CARGO;
_toShow = []; _toShow = [];
@ -61,7 +57,6 @@ _toShow = [];
_toShow pushBack [_x, _roleType]; _toShow pushBack [_x, _roleType];
} forEach crew _vehicle; } forEach crew _vehicle;
_toShow = [ _toShow = [
_toShow, _toShow,
[], [],
@ -75,7 +70,6 @@ _toShow = [
} }
] call BIS_fnc_sortBy; ] call BIS_fnc_sortBy;
_roleImages = ROLE_IMAGES; _roleImages = ROLE_IMAGES;
{ {
_unit = _x select 0; _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]; _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; } forEach _toShow;
("ACE_CrewInfo_CrewInfo" call BIS_fnc_rscLayer) cutRsc ["ACE_CrewInfo_dialog", "PLAIN", 1, false]; ("ACE_CrewInfo_CrewInfo" call BIS_fnc_rscLayer) cutRsc ["ACE_CrewInfo_dialog", "PLAIN", 1, false];
terminate (missionNamespace getVariable [QGVAR(hideCrewInfoHandle), scriptNull]); terminate (missionNamespace getVariable [QGVAR(hideCrewInfoHandle), scriptNull]);

View File

@ -32,6 +32,6 @@ private _maxAmmo = 0;
{ {
_maxAmmo = _maxAmmo max (_x select 1); _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 _maxAmmo > 0

View File

@ -32,7 +32,7 @@ private _maxAmmo = 0;
{ {
_maxAmmo = _maxAmmo max (_x select 1); _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 {}; if (_maxAmmo == 0) exitWith {};

View File

@ -22,7 +22,7 @@ private "_magazines";
_magazines = magazines _unit; _magazines = magazines _unit;
// case sensitvity // 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. // 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

View File

@ -42,7 +42,7 @@ playSound selectRandom ["ACE_Scopes_Click_1", "ACE_Scopes_Click_2", "ACE_Scopes_
// slightly rotate the player if looking through optic // slightly rotate the player if looking through optic
if (cameraView == "GUNNER") then { if (cameraView == "GUNNER") then {
// Convert adjustmentDifference from mils to degrees // 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"]; _adjustmentDifference params ["_elevationDifference", "_windageDifference"];
_pitchBankYaw = [_unit] call EFUNC(common,getPitchBankYaw); _pitchBankYaw = [_unit] call EFUNC(common,getPitchBankYaw);
_pitchBankYaw params ["_pitch", "_bank", "_yaw"]; _pitchBankYaw params ["_pitch", "_bank", "_yaw"];

View File

@ -25,7 +25,7 @@ private _leave = false;
if (GVAR(EnableSafeZone)) then { if (GVAR(EnableSafeZone)) then {
private _allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers); 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 { if (count _nearestEnemyPlayers > 0) exitWith {
_leave = true; _leave = true;

View File

@ -57,9 +57,9 @@ private _nextGrenade = _grenades select _nextGrenadeIndex;
if (_currentGrenade == _nextGrenade) exitWith {false}; 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 // 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 _uniformGrenades = uniformItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}};
private _vestGrenades = [vestItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter); private _vestGrenades = vestItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}};
private _backpackGrenades = [backpackItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter); private _backpackGrenades = backpackItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}};
// remove all grenades except those we are switching to --> this breaks the selector // remove all grenades except those we are switching to --> this breaks the selector
{_unit removeItemFromUniform _x; false} count _uniformGrenades; {_unit removeItemFromUniform _x; false} count _uniformGrenades;