more common code cleanup

This commit is contained in:
commy2 2015-09-20 00:55:58 +02:00
parent 73a9c1b5f8
commit dfa6d71a64
14 changed files with 181 additions and 135 deletions

View File

@ -9,6 +9,8 @@
* None
*
* Public: Yes
*
* Note: Not functional, because FUNC(localAnim) does no longer exist
*/
#include "script_component.hpp"

View File

@ -1,21 +1,24 @@
/**
* fn_setVolume_f.sqf
* @Descr: Sets the volume of the game, including third party radio modifications such as TFAR and ACRE.
* @Author: Glowbal
/*
* Author: Glowbal
* Sets the volume of the game, including third party radio modifications such as TFAR and ACRE.
*
* @Arguments: [setVolume BOOL]
* @Return: void
* @PublicAPI: true
* Arguments:
* 0: setVolume (default: false) <BOOL>
*
* Return Value:
* None
*
* Public: Yes
*
* Note: Uses player
*/
#include "script_component.hpp"
#define MUTED_LEVEL 0.2
#define NORMAL_LEVEL 1
#define NO_SOUND 0
private ["_setVolume"];
_setVolume = [_this, 0, false, [false]] call BIS_fnc_Param;
params [["_setVolume", false]];
if (_setVolume) then {
// Vanilla Game

View File

@ -1,6 +1,5 @@
/*
* Author: commy2
*
* hint the Variable ACE_isUsedBy from the input Object every frame
*
* Argument:

View File

@ -1,18 +1,22 @@
/**
* fn_sortAlphabeticallyBy.sqf
* @Descr:
* @Author: Glowbal
/*
* Author: Glowbal
* ? deprecated
*
* @Arguments: []
* @Return:
* @PublicAPI: true
* Arguments:
* ?
*
* Return Value:
* ?
*
* Public: Yes
*
* Deprecated
*/
#include "script_component.hpp"
private ["_elements","_indexes", "_theElement", "_tmp", "_tempIndex", "_j", "_i", "_returnArray"];
params ["_array", "_elementN"];
PARAMS_2(_array,_elementN);
private ["_elements", "_indexes", "_theElement", "_tmp", "_tempIndex", "_returnArray"];
_indexes = [];
_elements = [];
@ -37,8 +41,9 @@ for "_i" from 1 to (count _elements) - 1 do {
};
_returnArray = [];
{
_returnArray pushback (_array select _x);
} forEach _indexes;
_returnArray;
_returnArray

View File

@ -1,21 +1,26 @@
/**
* fn_stringTrim.sqf
* @Descr: Removes white spaces from string
* @Author: Glowbal
/*
* Author: Glowbal
* Removes white spaces from string
*
* @Arguments: [string STRING]
* @Return: STRING copy of string
* @PublicAPI: true
* Arguments:
* 0: stringA <STRING>
* 1: stringB <STRING>
*
* Return Value:
* copy of string <STRING>
*
* Public: Yes
*
* Deprecated
*/
#include "script_component.hpp"
#define WHITE_SPACE [20]
params ["_string", ""];
private ["_charArray", "_returnString"];
private ["_string", "_charArray", "_returnString"];
_string = [_this, 0, "",[""]] call bis_fnc_param;
_charArray = toArray _string;
_charArray = _charArray - [((toArray " ") select 0)];
_returnString = toString _charArray;
_returnString;
_returnString

View File

@ -1,45 +1,53 @@
/**
* fn_switchToGroupSide_f.sqf
* @Descr: Stack group switches. Will always trace back to original group.
* @Author: Glowbal
/*
* Author: Glowbal
* Stack group switches. Will always trace back to original group.
*
* @Arguments: [unit OBJECT, switch BOOL, id STRING, side SIDE]
* @Return: void
* @PublicAPI: true
* Arguments:
* 0: Unit <OBJECT>
* 1: switch <BOOLEAN>
* 2: id <STRING>
* 3: side <SIDE>
*
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_unit","_side","_previousGroup","_newGroup", "_currentGroup", "_switch", "_originalSide", "_previousGroupsList", "_id"];
_unit = [_this, 0,ObjNull,[ObjNull]] call BIS_fnc_Param;
_switch = [_this, 1, false,[false]] call BIS_fnc_Param;
_id = [_this, 2, "", [""]] call BIS_fnc_Param;
_side = [_this, 3, side _unit,[west]] call BIS_fnc_Param;
params [["_unit", objNull], ["_switch", false], ["_id", ""], ["_side", side _unit]];
private "_previousGroupsList";
_previousGroupsList = _unit getvariable [QGVAR(previousGroupSwitchTo), []];
_previousGroupsList = _unit getvariable [QGVAR(previousGroupSwitchTo),[]];
if (_switch) then {
// go forward
private ["_previousGroup", "_originalSide", "_newGroup"];
_previousGroup = group _unit;
_originalSide = side group _unit;
if (count units _previousGroup == 1 && _originalSide == _side) exitwith {
[format["Current group has only 1 member and is of same side as switch. Not switching unit %1", _id]] call FUNC(debug);
[format ["Current group has only 1 member and is of same side as switch. Not switching unit %1", _id]] call FUNC(debug);
};
_newGroup = createGroup _side;
[_unit] joinSilent _newGroup;
_previousGroupsList pushback [_previousGroup, _originalSide, _id, true];
_unit setvariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
_previousGroupsList pushBack [_previousGroup, _originalSide, _id, true];
_unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
} else {
// go one back
private ["_currentGroup", "_newGroup"];
{
if (_id == (_x select 2)) exitwith {
_x set [ 3, false];
_previousGroupsList set [_foreachIndex, _x];
_previousGroupsList set [_forEachIndex, _x];
[format["found group with ID: %1", _id]] call FUNC(debug);
};
}foreach _previousGroupsList;
} forEach _previousGroupsList;
reverse _previousGroupsList;
{
@ -55,10 +63,12 @@ if (_switch) then {
if (count units _currentGroup == 0) then {
deleteGroup _currentGroup;
};
_previousGroupsList set [_foreachIndex, ObjNull];
_previousGroupsList set [_forEachIndex, objNull];
};
}foreach _previousGroupsList;
} forEach _previousGroupsList;
_previousGroupsList = _previousGroupsList - [objNull];
reverse _previousGroupsList; // we have to reverse again, to ensure the list is in the right order.
_unit setvariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
_unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
};

View File

@ -1,24 +1,23 @@
/*
* Author: Nou
*
* Execute a event only on specific clients.
*
* Argument:
* 0: Event name (string)
* 1: Event targets (object or array of objects)
* 2: Event args (any)
* Arguments:
* 0: Event name (STRING)
* 1: Event targets <OBJECT, ARRAY>
* 2: Event args <ANY>
*
* Note: If local executor is in list of targets, event will execute with
* network delay, and not immediatly.
*
* Return value:
* Nothing
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
//IGNORE_PRIVATE_WARNING("_handleNetEvent");
PARAMS_3(_eventName,_eventTargets,_eventArgs);
params ["_eventName", "_eventTargets", "_eventArgs"];
#ifdef DEBUG_EVENTS
ACE_LOGINFO_2("* Target Event: %1 - %2",_eventName,_eventTargets);
@ -26,7 +25,8 @@ PARAMS_3(_eventName,_eventTargets,_eventArgs);
#endif
ACEc = [_eventName, _eventTargets, _eventArgs];
if(!isServer) then {
if (!isServer) then {
publicVariableServer "ACEc";
} else {
["ACEc", ACEc] call FUNC(_handleNetEvent);

View File

@ -1,7 +1,18 @@
//#define DEBUG_MODE_FULL
/*
* Author: ?
* ?
*
* Arguments:
* ?
*
* Return Value:
* ?
*
* Public: ?
*/
#include "script_component.hpp"
private["_lastTickTime", "_lastGameTime", "_delta"];
private ["_lastTickTime", "_lastGameTime", "_delta"];
_lastTickTime = ACE_diagTime;
_lastGameTime = ACE_gameTime;
@ -10,7 +21,7 @@ ACE_gameTime = time;
ACE_diagTime = diag_tickTime;
_delta = ACE_diagTime - _lastTickTime;
if(ACE_gameTime <= _lastGameTime) then {
if (ACE_gameTime <= _lastGameTime) then {
TRACE_1("paused",_delta);
ACE_paused = true;
// Game is paused or not running

View File

@ -1,13 +1,12 @@
/*
* Author: commy2
*
* Converts number to binary number
*
* Arguments:
* A number
* A number <NUMBER>
*
* Return Value:
* A binary number, String
* A binary number as string <STRING>
*
* Public: Yes
*/
@ -32,4 +31,4 @@ while {count toArray _bin < _minLength} do {
_bin = "0" + _bin;
};
_sign + _bin
_sign + _bin // return

View File

@ -1,13 +1,12 @@
/*
* Author: commy2
*
* Convert an array of booleans into a number.
*
* Arguments:
* N: Booleans <ARRAY of Booleans>
* N: Booleans <ARRAY>
*
* Return Value:
* Bitmask (Number)
* Bitmask <NUMBER>
*
* Public: Yes
*/
@ -18,6 +17,7 @@ private ["_array", "_result"];
_array = _this;
_result = 0;
{
if (_x) then {_result = _result + 2 ^ _forEachIndex};
} forEach _array;

View File

@ -1,26 +1,28 @@
/*
* Author: commy2, esteldunedain
*
* Converts number to hexadecimal number
*
* Arguments:
* A number between 0 and 255 <NUMBER>
*
* Return Value:
* A hexadecimal number, <STRING>
* A hexadecimal number as string <STRING>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_number"];
_number = ((round abs (_this select 0)) max 0) min 255;
params ["_number"];
_number = ((round abs _number) max 0) min 255;
if (isNil QGVAR(hexArray)) then {
private ["_minLength", "_i", "_num", "_hex", "_rest"];
GVAR(hexArray) = [];
private ["_minLength", "_num", "_hex", "_rest"];
_minLength = 2;
for [{_i = 0;}, {_i < 256}, {_i = _i + 1}] do {
_num = _i;
_hex = ["", "0"] select (_i == 0);
@ -39,11 +41,13 @@ if (isNil QGVAR(hexArray)) then {
_num = floor (_num / 16);
_hex = _rest + _hex;
};
while {count toArray _hex < _minLength} do {
_hex = "0" + _hex;
};
GVAR(hexArray) pushBack _hex;
};
};
(GVAR(hexArray) select _number)
GVAR(hexArray) select _number // return

View File

@ -1,25 +1,23 @@
/*
Name: FUNC(toNumber)
Author(s):
Garth de Wet (LH)
Description:
Takes a string/number and returns the number.
Parameters:
0: TYPE - Value to attempt to convert to number or if number simply return number.
Returns:
NUMBER
Example:
number = ["102"] call FUNC(toNumber);
*/
* Author: Garth de Wet (LH)
*
* Takes a string/number and returns the number.
*
* Arguments:
* 0: Value to attempt to convert to number or if number simply return number. <STRING, NUMBER>
*
* Return Value:
* <NUMBER>
*
* Example:
* number = ["102"] call ace_common_fnc_toNumber;
*
* Public: Yes
*/
#include "script_component.hpp"
if (typeName (_this select 0) == "SCALAR") exitWith {
(_this select 0)
};
params ["_value"];
(parseNumber (_this select 0))
if (typeName _value == "SCALAR") exitWith {_value};
parseNumber _value // return

View File

@ -1,20 +1,25 @@
/*
* Author: ?
*
* ?
*
* Arguments:
* ?
*
* Return Value:
* ?
*
* Public: ?
*/
#include "script_component.hpp"
private["_matrix", "_object", "_offset", "_origin", "_out", "_xVec", "_y", "_yVec", "_z", "_zVec"];
params ["_object", "_matrix", "_offset"];
_object = _this select 0;
private "_origin";
_origin = getPosASL _object;
_matrix = _this select 1;
_xVec = _matrix select 0;
_yVec = _matrix select 1;
_zVec = _matrix select 2;
_offset = _this select 2;
_matrix params ["_xVec", "_yVec", "_zVec"];
_x = _offset select 0;
_y = _offset select 1;
_z = _offset select 2;
_offset params ["_x", "_y", "_z"];
_out = (((_xVec vectorMultiply _x) vectorAdd (_yVec vectorMultiply _y)) vectorAdd (_zVec vectorMultiply _z)) vectorAdd _origin;
_out;
(_xVec vectorMultiply _x) vectorAdd (_yVec vectorMultiply _y) vectorAdd (_zVec vectorMultiply _z) vectorAdd _origin // return

View File

@ -1,26 +1,31 @@
/*
* Author: ?
*
* ?
*
* Arguments:
* ?
*
* Return Value:
* ?
*
* Public: ?
*/
#include "script_component.hpp"
private["_matrix", "_object", "_offset", "_origin", "_out", "_xVec", "_y", "_yVec", "_z", "_zVec"];
params ["_object", "_matrix", "_offset"];
_object = _this select 0;
private "_origin";
_origin = getPosASL _object;
_matrix = _this select 1;
_xVec = _matrix select 0;
_yVec = _matrix select 1;
_zVec = _matrix select 2;
_offset = _this select 2;
_matrix params ["_xVec", "_yVec", "_zVec"];
_offset = _offset vectorDiff _origin;
_x = _offset select 0;
_y = _offset select 1;
_z = _offset select 2;
_offset params ["_x", "_y", "_z"];
_out = [
((_xVec select 0)*_x) + ((_xVec select 1)*_y) + ((_xVec select 2)*_z),
((_yVec select 0)*_x) + ((_yVec select 1)*_y) + ((_yVec select 2)*_z),
((_zVec select 0)*_x) + ((_zVec select 1)*_y) + ((_zVec select 2)*_z)
];
_out;
[
((_xVec select 0) * _x) + ((_xVec select 1) * _y) + ((_xVec select 2) * _z),
((_yVec select 0) * _x) + ((_yVec select 1) * _y) + ((_yVec select 2) * _z),
((_zVec select 0) * _x) + ((_zVec select 1) * _y) + ((_zVec select 2) * _z)
] // return