Some Refactoring (#6607)

* SwitchUnits

* tacticalLadder

* vehiclelock

* vector

* Typo, thanks circleCI

* Fix stuff

* Fix animate loop
This commit is contained in:
Dedmen Miller 2018-10-10 03:21:46 +02:00 committed by PabstMirror
parent f2f5a94549
commit 0633b807fa
21 changed files with 53 additions and 94 deletions

View File

@ -21,16 +21,11 @@
params ["_faction", "_pos"];
_faction params ["", "_sides"];
private _sideNearest = [];
private _nearestObjects = nearestObjects [_pos, ["Man"], 15];
{
if ([_x] call FUNC(isValidAi) && (side group _x in _sides)) then {
_sideNearest pushBack _x;
};
nil
} count (nearestObjects [_pos, ["Man"], 15]);
private _nearestValidUnitIndex = _nearestObjects findIf {(side group _x in _sides) && {[_x] call FUNC(isValidAi)}};
if (count _sideNearest > 0) then {
[_sideNearest select 0] call FUNC(switchUnit);
if (_nearestValidUnitIndex != -1) then {
[_nearestObjects select _nearestValidUnitIndex] call FUNC(switchUnit);
openMap false;
};

View File

@ -32,12 +32,9 @@ if (vehicle _playerUnit == _playerUnit) then {
removeAllWeapons _playerUnit;
removeGoggles _playerUnit;
removeHeadgear _playerUnit;
removeVest _playerUnit;
removeAllAssignedItems _playerUnit;
clearAllItemsFromBackpack _playerUnit;
removeBackpack _playerUnit;
removeAllContainers _playerUnit;
_playerUnit linkItem "ItemMap";
removeUniform _playerUnit;
[_playerUnit, "forceWalk", "ACE_SwitchUnits", true] call EFUNC(common,statusEffect_set);

View File

@ -36,7 +36,7 @@ GVAR(AllMarkerNames) = [];
// create markers
{
if (([_x] call FUNC(isValidAi) && (side group _x in _sides)) || (_x getVariable [QGVAR(IsPlayerControlled), false])) then {
if ((_x getVariable [QGVAR(IsPlayerControlled), false]) || {(side group _x in _sides) && {[_x] call FUNC(isValidAi)}}) then {
private _markerName = str _x;

View File

@ -18,12 +18,4 @@
params ["_position", "_radius"];
private _nearestPlayers = [];
{
if ([_x] call EFUNC(common,isPlayer) && {alive _x}) then {
_nearestPlayers pushBack _x;
};
} forEach (nearestObjects [_position, ["Man"], _radius]);
_nearestPlayers
(nearestObjects [_position, ["Man"], _radius]) select {alive _x && {[_x] call EFUNC(common,isPlayer)}};

View File

@ -20,10 +20,10 @@ params ["_player"];
if (GVAR(EnableSwitchUnits)) then {
private _sides = [];
if(GVAR(SwitchToWest)) then {_sides pushBack west;};
if(GVAR(SwitchToEast)) then {_sides pushBack east;};
if(GVAR(SwitchToIndependent)) then {_sides pushBack independent;};
if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian;};
if (GVAR(SwitchToWest)) then {_sides pushBack west;};
if (GVAR(SwitchToEast)) then {_sides pushBack east;};
if (GVAR(SwitchToIndependent)) then {_sides pushBack independent;};
if (GVAR(SwitchToCivilian)) then {_sides pushBack civilian;};
if (_player getVariable ["ACE_CanSwitchUnits", false]) then {
[_player, _sides] call FUNC(initPlayer);

View File

@ -32,8 +32,7 @@ GVAR(ladder) animate ["rotate", 0];
{
GVAR(ladder) animate [_x, 0];
true
} count __ANIMS;
} forEach __ANIMS; //Don't "optimize" this to a count. See #6607
// remove mouse buttons and hint
call EFUNC(interaction,hideMouseHint);

View File

@ -20,12 +20,6 @@ params ["_ladder"];
private _unitsNearLadder = nearestObjects [_ladder, ["CAManBase"], 4];
TRACE_1("Near Ladder",_unitsNearLadder);
private _ladderEmpty = true;
{
if (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState _x >> "ACE_isLadder") == 1) exitWith {
_ladderEmpty = false;
TRACE_1("On Ladder",_x);
};
} forEach _unitsNearLadder;
private _CfgAnimationStates = configFile >> "CfgMovesMaleSdr" >> "States";
_ladderEmpty
(_unitsNearLadder findIf {getNumber (_CfgAnimationStates >> animationState _x >> "ACE_isLadder") == 1}) == -1

View File

@ -4,13 +4,13 @@
* Clears the vectors control items.
*
* Arguments:
* 0: String <STRING>
* 0: "azimuth" or "distance" <STRING>
*
* Return Value:
* None
*
* Example:
* [5] call ace_vector_fnc_clearDisplay
* ["azimuth"] call ace_vector_fnc_clearDisplay
*
* Public: No
*/

View File

@ -17,7 +17,7 @@
private _distance = call FUNC(getDistance);
private _direction = call FUNC(getDirection);
private _azimuth = _direction select 0;
private _inclination = _direction select 1;
_direction params ["_azimuth", "_inclination"];
//Send Data to connected GPS
[QGVAR(rangefinderData), [_distance, _azimuth, _inclination]] call CBA_fnc_localEvent;

View File

@ -15,14 +15,12 @@
* Public: No
*/
private _distanceP1 = GVAR(pData) select 0;
private _directionP1 = GVAR(pData) select 1;
private _azimuthP1 = _directionP1 select 0;
private _inclinationP1 = _directionP1 select 1;
GVAR(pData) params ["_distanceP1", "_directionP1"];
_directionP1 params ["_azimuthP1", "_inclinationP1"];
private _distanceP2 = call FUNC(getDistance);
private _directionP2 = call FUNC(getDirection);
private _azimuthP2 = _directionP2 select 0;
private _inclinationP2 = _directionP2 select 1;
_directionP2 params ["_azimuthP2", "_inclinationP2"];
private _abscissa = _distanceP1 * sin (_azimuthP1 - _azimuthP2);
private _ordinate = _distanceP1 * cos (_inclinationP1 - _inclinationP2) - _distanceP2 * cos (_azimuthP1 - _azimuthP2);

View File

@ -18,8 +18,7 @@
private _distance = call FUNC(getDistance);
private _direction = call FUNC(getDirection);
private _azimuth = _direction select 0;
private _inclination = _direction select 1;
_direction params ["_azimuth", "_inclination"];
if (_distance < -999) exitWith {
[-1000, -1000] // return

View File

@ -15,15 +15,12 @@
* Public: No
*/
private _distanceP1 = GVAR(pData) select 0;
private _directionP1 = GVAR(pData) select 1;
private _azimuthP1 = _directionP1 select 0;
private _inclinationP1 = _directionP1 select 1;
GVAR(pData) params ["_distanceP1", "_directionP1"];
_directionP1 params ["_azimuthP1", "_inclinationP1"];
private _distanceP2 = call FUNC(getDistance);
private _directionP2 = call FUNC(getDirection);
private _azimuthP2 = _directionP2 select 0;
private _inclinationP2 = _directionP2 select 1;
_directionP2 params ["_azimuthP2", "_inclinationP2"];
private _relDirection = sqrt ((_azimuthP1 - _azimuthP2) ^ 2 + (_inclinationP1 - _inclinationP2) ^ 2);
private _relDistance = sqrt (_distanceP1 ^ 2 + _distanceP2 ^ 2 - 2 * _distanceP1 * _distanceP2 * cos _relDirection);

View File

@ -15,15 +15,11 @@
* Public: No
*/
private _distanceP1 = GVAR(pData) select 0;
private _directionP1 = GVAR(pData) select 1;
private _azimuthP1 = _directionP1 select 0;
private _inclinationP1 = _directionP1 select 1;
GVAR(pData) params ["_distanceP1", "_directionP1"];
_directionP1 params ["_azimuthP1", "_inclinationP1"];
private _distanceP2 = call FUNC(getDistance);
private _directionP2 = call FUNC(getDirection);
private _azimuthP2 = _directionP2 select 0;
private _inclinationP2 = _directionP2 select 1;
_directionP2 params ["_azimuthP2", "_inclinationP2"];
private _relDirection = sqrt ((_azimuthP1 - _azimuthP2) ^ 2 + (_inclinationP1 - _inclinationP2) ^ 2);

View File

@ -4,13 +4,13 @@
*
*
* Arguments:
* 0: String <STRING>
* 0: Enable illumination <BOOL>
*
* Return Value:
* None
*
* Example:
* ["5"] call ace_vector_fnc_illuminate
* [true] call ace_vector_fnc_illuminate
*
* Public: No
*/

View File

@ -4,13 +4,13 @@
*
*
* Arguments:
* 0: String<STRING>
* 0: Name of mode ("settings", "config") <STRING>
*
* Return Value:
* Array <ARRAY>
*
* Example:
* ["5"] call ace_vector_fnc_nextMode
* ["settings"] call ace_vector_fnc_nextMode
*
* Public: No
*/

View File

@ -10,7 +10,7 @@
* None
*
* Example:
* ["5"] call ace_vector_fnc_onKeyDown
* ["azimuth"] call ace_vector_fnc_onKeyDown
*
* Public: No
*/

View File

@ -10,6 +10,6 @@ if (!hasInterface) exitwith {};
TRACE_1("SettingsInitialized eh",GVAR(LockVehicleInventory));
if (GVAR(LockVehicleInventory)) then {
["CAManBase", "InventoryOpened", {_this call FUNC(onOpenInventory);}] call CBA_fnc_addClassEventHandler;
["CAManBase", "InventoryOpened", {_this call FUNC(onOpenInventory)}] call CBA_fnc_addClassEventHandler;
};
}] call CBA_fnc_addEventHandler;

View File

@ -22,20 +22,16 @@ TRACE_2("params",_unit,_veh);
if (isNull _unit) exitWith {ERROR("null unit"); false};
if (isNull _veh) exitWith {ERROR("null vehicle"); false};
private _returnValue = false;
//Master can open anything "no matter what"
private _items = _unit call EFUNC(common,uniqueItems);
if ("ACE_key_master" in _items) then {_returnValue = true};
if ("ACE_key_master" in _items) exitWith {true};
//Check side key
private _sideKeyName = [_veh] call FUNC(getVehicleSideKey);
if (_sideKeyName in _items) then {_returnValue = true};
if (_sideKeyName in _items) exitWith {true};
//Check custom keys
private _customKeys = _veh getVariable [QGVAR(customKeys), []];
{
if (_x in (magazinesDetail _unit)) then {_returnValue = true;};
} forEach _customKeys;
private _magazines = magazinesDetail _unit;
_returnValue
(_customKeys findIf {_x in _magazines}) != -1

View File

@ -32,11 +32,11 @@ if ((locked _veh) == 0) exitWith {false};
//need lockpick item
if !("ACE_key_lockpick" in (_unit call EFUNC(common,uniqueItems))) exitWith {false};
private _vehLockpickStrenth = _veh getVariable[QGVAR(lockpickStrength), GVAR(DefaultLockpickStrength)];
if (!(_vehLockpickStrenth isEqualType 0)) exitWith {ERROR("ACE_vehicleLock_LockpickStrength invalid"); false};
private _vehLockpickStrength = _veh getVariable[QGVAR(lockpickStrength), GVAR(DefaultLockpickStrength)];
if (!(_vehLockpickStrength isEqualType 0)) exitWith {ERROR("ACE_vehicleLock_LockpickStrength invalid"); false};
//-1 indicates unpickable lock
if (_vehLockpickStrenth < 0) exitWith {false};
if (_vehLockpickStrength < 0) exitWith {false};
//Condition check for progressBar
private _condition = {
@ -53,7 +53,7 @@ switch (_funcType) do {
_returnValue = !([_unit, _veh] call FUNC(hasKeyForVehicle)) && {(locked _veh) in [2, 3]};
};
case "startLockpick": {
[_vehLockpickStrenth, [_unit, _veh, "finishLockpick"], {(_this select 0) call FUNC(lockpick)}, {}, (localize LSTRING(Action_LockpickInUse)), _condition, ["isNotInside", "isNotSwimming"]] call EFUNC(common,progressBar);
[_vehLockpickStrength, [_unit, _veh, "finishLockpick"], {(_this select 0) call FUNC(lockpick)}, {}, (localize LSTRING(Action_LockpickInUse)), _condition, ["isNotInside", "isNotSwimming"]] call EFUNC(common,progressBar);
};
case "finishLockpick": {
[QGVAR(setVehicleLock), [_veh, false], [_veh]] call CBA_fnc_targetEvent;

View File

@ -27,14 +27,11 @@ if !(_activated) exitWith {WARNING("Vehicle Lock Sync Module - placed but not ac
[{
params ["_syncedObjects"];
private _listOfVehicles = [];
{
if ((_x isKindOf "Car") || (_x isKindOf "Tank") || (_x isKindOf "Helicopter")) then {
_listOfVehicles pushBack _x;
};
} forEach _syncedObjects;
private _listOfVehicles = _syncedObjects select {
(_x isKindOf "Car") || {(_x isKindOf "Tank") || {_x isKindOf "Helicopter"}}
};
if ((count _listOfVehicles) == 0) exitWith { //Verbose error for mission makers (only shows on server)
if (_listOfVehicles isEqualTo []) exitWith { //Verbose error for mission makers (only shows on server)
["ACE_VehicleLock_fnc_moduleSync: no vehicles synced"] call BIS_fnc_error;
};

View File

@ -20,13 +20,13 @@ params ["_unit", "_container"];
TRACE_2("params",_unit,_container);
//Only check for player:
if (_unit != ace_player) exitWith {};
if (_unit != ACE_player) exitWith {};
if (GVAR(LockVehicleInventory) && //if setting not enabled
{(vehicle ace_player) == ace_player} && //Player dismounted
{(_container isKindOf "Car") || (_container isKindOf "Tank") || (_container isKindOf "Helicopter")} && //container is a lockable veh
{(vehicle ACE_player) == ACE_player} && //Player dismounted
{(_container isKindOf "Car") || {(_container isKindOf "Tank") || {_container isKindOf "Helicopter"}}} && //container is a lockable veh
{(locked _container) in [2,3]} && //Vehicle is locked
{!([ace_player, _container] call FUNC(hasKeyForVehicle))} //player doesn't have key
{!([ACE_player, _container] call FUNC(hasKeyForVehicle))} //player doesn't have key
) then {
//Give feedback that vehicle is locked
playSound "ACE_Sound_Click";
@ -41,8 +41,7 @@ if (GVAR(LockVehicleInventory) && //if setting not enabled
(findDisplay 602) closeDisplay 0;
[{
TRACE_1("Opening Player Inventory", _this);
ACE_player action ["Gear", objNull]
ACE_player action ["Gear", objNull];
}, []] call CBA_fnc_execNextFrame;
},
[]] call CBA_fnc_waitUntilAndExecute;
}, []] call CBA_fnc_waitUntilAndExecute;
};