more common code cleanup

This commit is contained in:
commy2 2015-09-19 20:55:35 +02:00
parent 3ddaa5ed4a
commit 09f133b7f8
4 changed files with 85 additions and 78 deletions

View File

@ -1,36 +1,34 @@
/* /*
Name: FUNC(setForceWalkStatus) * Author: Pabst Mirror (from captivity by commy2)
* Sets the forceWalk status of an unit. This allows the handling of more than one reason to set forceWalk.
Author: Pabst Mirror (from captivity by commy2) * Unit will force walk until all reasons are removed.
*
Description: * Arguments:
Sets the forceWalk status of an unit. This allows the handling of more than one reason to set forceWalk. * 0: Unit <OBJECT>
Unit will force walk until all reasons are removed. * 1: Reason for forcing walking <STRING>
* 2: Is the reason still valid. True to force walk, false to remove restriction. <BOOL>
Parameters: *
0: OBJECT - Unit * Returns:
1: STRING - Reason for forcing walking * None
2: BOOL - Is the reason still valid. True to force walk, false to remove restriction. *
* Example:
Returns: * [ACE_Player, "BrokenLeg", true] call FUNC(setForceWalkStatus)
None *
* Public: No
Example:
[ACE_Player, "BrokenLeg", true] call FUNC(setForceWalkStatus)
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_forceWalkReasons", "_unitForceWalkReasons", "_forceWalkReasonsBooleans", "_bitmaskNumber"]; params ["_unit", "_reason", "_status"];
PARAMS_3(_unit,_reason,_status); private ["_forceWalkReasons", "_unitForceWalkReasons", "_forceWalkReasonsBooleans", "_bitmaskNumber"];
_forceWalkReasons = missionNamespace getVariable ["ACE_forceWalkReasons", []]; _forceWalkReasons = missionNamespace getVariable ["ACE_forceWalkReasons", []];
// register new reason (these reasons are shared publicly, since units can change ownership, but keep their forceWalk status) // register new reason (these reasons are shared publicly, since units can change ownership, but keep their forceWalk status)
if !(_reason in _forceWalkReasons) then { if !(_reason in _forceWalkReasons) then {
_forceWalkReasons pushBack _reason; _forceWalkReasons pushBack _reason;
ACE_forceWalkReasons = _forceWalkReasons; ACE_forceWalkReasons = _forceWalkReasons;
publicVariable "ACE_forceWalkReasons"; publicVariable "ACE_forceWalkReasons";
}; };
// get reasons why the unit is forceWalking already and update to the new status // get reasons why the unit is forceWalking already and update to the new status
@ -38,7 +36,7 @@ _unitForceWalkReasons = [_unit] call FUNC(getForceWalkStatus);
_forceWalkReasonsBooleans = []; _forceWalkReasonsBooleans = [];
{ {
_forceWalkReasonsBooleans set [_forEachIndex, (_forceWalkReasons select _forEachIndex) in _unitForceWalkReasons]; _forceWalkReasonsBooleans set [_forEachIndex, (_forceWalkReasons select _forEachIndex) in _unitForceWalkReasons];
} forEach _forceWalkReasons; } forEach _forceWalkReasons;
_forceWalkReasonsBooleans set [_forceWalkReasons find _reason, _status]; _forceWalkReasonsBooleans set [_forceWalkReasons find _reason, _status];
@ -48,4 +46,4 @@ _bitmaskNumber = _forceWalkReasonsBooleans call FUNC(toBitmask);
_unit setVariable ["ACE_forceWalkStatusNumber", _bitmaskNumber, true]; _unit setVariable ["ACE_forceWalkStatusNumber", _bitmaskNumber, true];
// actually apply the forceWalk command globaly // actually apply the forceWalk command globaly
[[_unit], QUOTE(FUNC(applyForceWalkStatus)), 2] call FUNC(execRemoteFnc); [[_unit], QFUNC(applyForceWalkStatus), 2] call FUNC(execRemoteFnc);

View File

@ -1,23 +1,22 @@
/** /*
* fn_setHearingCapability.sqf * Author: Glowbal
* @Descr: Handle set volume calls. Will use the lowest available volume setting. * Handle set volume calls. Will use the lowest available volume setting.
* @Author: Glowbal
* *
* @Arguments: [id STRING, settings NUMBER, add BOOL (Optional. True will add, false will remove. Default value is true)] * Arguments:
* @Return: nil * 0: id <STRING>
* @PublicAPI: true * 1: settings <NUMBER>
* 2: add (default: true) <BOOL>
*
* Return Value:
* None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_add", "_exists", "_map", "_lowestVolume"]; params ["_id", "_settings", ["_add", true]];
PARAMS_2(_id,_settings); private ["_map", "_exists", "_lowestVolume"];
_add = true;
if (count _this > 2) then {
_add = _this select 2;
};
_map = missionNamespace getVariable [QGVAR(setHearingCapabilityMap),[]]; _map = missionNamespace getVariable [QGVAR(setHearingCapabilityMap),[]];
@ -44,7 +43,8 @@ missionNamespace setVariable [QGVAR(setHearingCapabilityMap), _map];
_lowestVolume = 1; _lowestVolume = 1;
{ {
_lowestVolume = (_x select 1) min _lowestVolume; _lowestVolume = (_x select 1) min _lowestVolume;
} forEach _map; false
} count _map;
// in game sounds // in game sounds
0 fadeSound _lowestVolume; 0 fadeSound _lowestVolume;

View File

@ -4,19 +4,23 @@
* Sets the value of an ACE_Parameter and makes it public. * Sets the value of an ACE_Parameter and makes it public.
* *
* Arguments: * Arguments:
* 0: Parameter name (string) * 0: Parameter name <STRING>
* 1: Value * 1: Value
* *
* Return Value: * Return Value:
* None * None
*
* Public: Yes
*
* Deprecated *@todo commy
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_name,_value); params ["_name", "_value"];
// Hack to keep backward compatibility for the moment // Hack to keep backward compatibility for the moment
if ((typeName (missionNamespace getVariable _name)) == "BOOL") then { if (typeName (missionNamespace getVariable _name) == "BOOL") then {
if ((typeName _value) == "SCALAR") then { if (typeName _value == "SCALAR") then {
_value = _value > 0; _value = _value > 0;
}; };
}; };

View File

@ -1,26 +1,25 @@
/* /*
* Taken From: * Author: Bohemia Interactive edit by KoffeinFlummi
* https://community.bistudio.com/wiki/BIS_fnc_setPitchBank * Sets the value of an ACE_Parameter and makes it public.
* Edited By:
* KoffeinFlummi
* *
* Arguments: * Arguments:
* 0: Unit/Vehicle * 0: Unit/Vehicle <OBJECT>
* 1: Pitch (degrees) * 1: Pitch <NUMBER>
* 2: Yaw (degrees) * 2: Yaw <NUMBER>
* 3: Bank (degrees) * 3: Bank <NUMBER>
* *
* Return Value: * Return Value:
* None * None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_object", "_aroundX", "_aroundY", "_aroundZ", "_dirX", "_dirY", "_dirZ", "_upX", "_upY", "_upZ", "_dir", "_up", "_dirXTemp", "_upXTemp"]; params ["_object", "_aroundX", "_aroundY", "_aroundZ"];
_object = _this select 0; _aroundZ = - _aroundZ;
_aroundX = _this select 1;
_aroundY = _this select 2; private ["_dirX", "_dirY", "_dirZ", "_upX", "_upY", "_upZ", "_dir", "_up"];
_aroundZ = (360 - (_this select 3)) - 360;
_dirX = 0; _dirX = 0;
_dirY = 1; _dirY = 1;
@ -28,28 +27,34 @@ _dirZ = 0;
_upX = 0; _upX = 0;
_upY = 0; _upY = 0;
_upZ = 1; _upZ = 1;
if (_aroundX != 0) then { if (_aroundX != 0) then {
_dirY = cos _aroundX; _dirY = cos _aroundX;
_dirZ = sin _aroundX; _dirZ = sin _aroundX;
_upY = -sin _aroundX; _upY = -sin _aroundX;
_upZ = cos _aroundX; _upZ = cos _aroundX;
};
if (_aroundY != 0) then {
_dirX = _dirZ * sin _aroundY;
_dirZ = _dirZ * cos _aroundY;
_upX = _upZ * sin _aroundY;
_upZ = _upZ * cos _aroundY;
};
if (_aroundZ != 0) then {
_dirXTemp = _dirX;
_dirX = (_dirXTemp* cos _aroundZ) - (_dirY * sin _aroundZ);
_dirY = (_dirY * cos _aroundZ) + (_dirXTemp * sin _aroundZ);
_upXTemp = _upX;
_upX = (_upXTemp * cos _aroundZ) - (_upY * sin _aroundZ);
_upY = (_upY * cos _aroundZ) + (_upXTemp * sin _aroundZ);
}; };
_dir = [_dirX,_dirY,_dirZ]; if (_aroundY != 0) then {
_up = [_upX,_upY,_upZ]; _dirX = _dirZ * sin _aroundY;
_dirZ = _dirZ * cos _aroundY;
_upX = _upZ * sin _aroundY;
_upZ = _upZ * cos _aroundY;
};
if (_aroundZ != 0) then {
private ["_dirXTemp", "_upXTemp"];
_dirXTemp = _dirX;
_dirX = (_dirXTemp* cos _aroundZ) - (_dirY * sin _aroundZ);
_dirY = (_dirY * cos _aroundZ) + (_dirXTemp * sin _aroundZ);
_upXTemp = _upX;
_upX = (_upXTemp * cos _aroundZ) - (_upY * sin _aroundZ);
_upY = (_upY * cos _aroundZ) + (_upXTemp * sin _aroundZ);
};
_dir = [_dirX, _dirY, _dirZ];
_up = [_upX, _upY, _upZ];
_object setVectorDirAndUp [_dir,_up]; _object setVectorDirAndUp [_dir,_up];