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

View File

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

View File

@ -36,7 +36,7 @@ GVAR(AllMarkerNames) = [];
// create markers // 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; private _markerName = str _x;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,6 +10,6 @@ if (!hasInterface) exitwith {};
TRACE_1("SettingsInitialized eh",GVAR(LockVehicleInventory)); TRACE_1("SettingsInitialized eh",GVAR(LockVehicleInventory));
if (GVAR(LockVehicleInventory)) then { 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; }] 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 _unit) exitWith {ERROR("null unit"); false};
if (isNull _veh) exitWith {ERROR("null vehicle"); false}; if (isNull _veh) exitWith {ERROR("null vehicle"); false};
private _returnValue = false;
//Master can open anything "no matter what" //Master can open anything "no matter what"
private _items = _unit call EFUNC(common,uniqueItems); 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 //Check side key
private _sideKeyName = [_veh] call FUNC(getVehicleSideKey); private _sideKeyName = [_veh] call FUNC(getVehicleSideKey);
if (_sideKeyName in _items) then {_returnValue = true}; if (_sideKeyName in _items) exitWith {true};
//Check custom keys //Check custom keys
private _customKeys = _veh getVariable [QGVAR(customKeys), []]; private _customKeys = _veh getVariable [QGVAR(customKeys), []];
{ private _magazines = magazinesDetail _unit;
if (_x in (magazinesDetail _unit)) then {_returnValue = true;};
} forEach _customKeys;
_returnValue (_customKeys findIf {_x in _magazines}) != -1

View File

@ -32,11 +32,11 @@ if ((locked _veh) == 0) exitWith {false};
//need lockpick item //need lockpick item
if !("ACE_key_lockpick" in (_unit call EFUNC(common,uniqueItems))) exitWith {false}; if !("ACE_key_lockpick" in (_unit call EFUNC(common,uniqueItems))) exitWith {false};
private _vehLockpickStrenth = _veh getVariable[QGVAR(lockpickStrength), GVAR(DefaultLockpickStrength)]; private _vehLockpickStrength = _veh getVariable[QGVAR(lockpickStrength), GVAR(DefaultLockpickStrength)];
if (!(_vehLockpickStrenth isEqualType 0)) exitWith {ERROR("ACE_vehicleLock_LockpickStrength invalid"); false}; if (!(_vehLockpickStrength isEqualType 0)) exitWith {ERROR("ACE_vehicleLock_LockpickStrength invalid"); false};
//-1 indicates unpickable lock //-1 indicates unpickable lock
if (_vehLockpickStrenth < 0) exitWith {false}; if (_vehLockpickStrength < 0) exitWith {false};
//Condition check for progressBar //Condition check for progressBar
private _condition = { private _condition = {
@ -53,7 +53,7 @@ switch (_funcType) do {
_returnValue = !([_unit, _veh] call FUNC(hasKeyForVehicle)) && {(locked _veh) in [2, 3]}; _returnValue = !([_unit, _veh] call FUNC(hasKeyForVehicle)) && {(locked _veh) in [2, 3]};
}; };
case "startLockpick": { 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": { case "finishLockpick": {
[QGVAR(setVehicleLock), [_veh, false], [_veh]] call CBA_fnc_targetEvent; [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"]; params ["_syncedObjects"];
private _listOfVehicles = []; private _listOfVehicles = _syncedObjects select {
{ (_x isKindOf "Car") || {(_x isKindOf "Tank") || {_x isKindOf "Helicopter"}}
if ((_x isKindOf "Car") || (_x isKindOf "Tank") || (_x isKindOf "Helicopter")) then { };
_listOfVehicles pushBack _x;
};
} forEach _syncedObjects;
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; ["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); TRACE_2("params",_unit,_container);
//Only check for player: //Only check for player:
if (_unit != ace_player) exitWith {}; if (_unit != ACE_player) exitWith {};
if (GVAR(LockVehicleInventory) && //if setting not enabled if (GVAR(LockVehicleInventory) && //if setting not enabled
{(vehicle ace_player) == ace_player} && //Player dismounted {(vehicle ACE_player) == ACE_player} && //Player dismounted
{(_container isKindOf "Car") || (_container isKindOf "Tank") || (_container isKindOf "Helicopter")} && //container is a lockable veh {(_container isKindOf "Car") || {(_container isKindOf "Tank") || {_container isKindOf "Helicopter"}}} && //container is a lockable veh
{(locked _container) in [2,3]} && //Vehicle is locked {(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 { ) then {
//Give feedback that vehicle is locked //Give feedback that vehicle is locked
playSound "ACE_Sound_Click"; playSound "ACE_Sound_Click";
@ -41,8 +41,7 @@ if (GVAR(LockVehicleInventory) && //if setting not enabled
(findDisplay 602) closeDisplay 0; (findDisplay 602) closeDisplay 0;
[{ [{
TRACE_1("Opening Player Inventory", _this); TRACE_1("Opening Player Inventory", _this);
ACE_player action ["Gear", objNull] ACE_player action ["Gear", objNull];
}, []] call CBA_fnc_execNextFrame; }, []] call CBA_fnc_execNextFrame;
}, }, []] call CBA_fnc_waitUntilAndExecute;
[]] call CBA_fnc_waitUntilAndExecute;
}; };