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 * None
* *
* Public: Yes * Public: Yes
*
* Note: Not functional, because FUNC(localAnim) does no longer exist
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

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

View File

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

View File

@ -1,18 +1,22 @@
/** /*
* fn_sortAlphabeticallyBy.sqf * Author: Glowbal
* @Descr: * ? deprecated
* @Author: Glowbal
* *
* @Arguments: [] * Arguments:
* @Return: * ?
* @PublicAPI: true *
* Return Value:
* ?
*
* Public: Yes
*
* Deprecated
*/ */
#include "script_component.hpp" #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 = []; _indexes = [];
_elements = []; _elements = [];
@ -37,8 +41,9 @@ for "_i" from 1 to (count _elements) - 1 do {
}; };
_returnArray = []; _returnArray = [];
{ {
_returnArray pushback (_array select _x); _returnArray pushback (_array select _x);
} forEach _indexes; } forEach _indexes;
_returnArray; _returnArray

View File

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

View File

@ -1,45 +1,53 @@
/** /*
* fn_switchToGroupSide_f.sqf * Author: Glowbal
* @Descr: Stack group switches. Will always trace back to original group. * Stack group switches. Will always trace back to original group.
* @Author: Glowbal
* *
* @Arguments: [unit OBJECT, switch BOOL, id STRING, side SIDE] * Arguments:
* @Return: void * 0: Unit <OBJECT>
* @PublicAPI: true * 1: switch <BOOLEAN>
* 2: id <STRING>
* 3: side <SIDE>
*
* Return Value:
* None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit","_side","_previousGroup","_newGroup", "_currentGroup", "_switch", "_originalSide", "_previousGroupsList", "_id"]; params [["_unit", objNull], ["_switch", false], ["_id", ""], ["_side", side _unit]];
_unit = [_this, 0,ObjNull,[ObjNull]] call BIS_fnc_Param;
_switch = [_this, 1, false,[false]] call BIS_fnc_Param; private "_previousGroupsList";
_id = [_this, 2, "", [""]] call BIS_fnc_Param; _previousGroupsList = _unit getvariable [QGVAR(previousGroupSwitchTo), []];
_side = [_this, 3, side _unit,[west]] call BIS_fnc_Param;
_previousGroupsList = _unit getvariable [QGVAR(previousGroupSwitchTo),[]];
if (_switch) then { if (_switch) then {
// go forward // go forward
private ["_previousGroup", "_originalSide", "_newGroup"];
_previousGroup = group _unit; _previousGroup = group _unit;
_originalSide = side group _unit; _originalSide = side group _unit;
if (count units _previousGroup == 1 && _originalSide == _side) exitwith { 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; _newGroup = createGroup _side;
[_unit] joinSilent _newGroup; [_unit] joinSilent _newGroup;
_previousGroupsList pushback [_previousGroup, _originalSide, _id, true]; _previousGroupsList pushBack [_previousGroup, _originalSide, _id, true];
_unit setvariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true]; _unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
} else { } else {
// go one back // go one back
private ["_currentGroup", "_newGroup"];
{ {
if (_id == (_x select 2)) exitwith { if (_id == (_x select 2)) exitwith {
_x set [ 3, false]; _x set [ 3, false];
_previousGroupsList set [_foreachIndex, _x]; _previousGroupsList set [_forEachIndex, _x];
[format["found group with ID: %1", _id]] call FUNC(debug); [format["found group with ID: %1", _id]] call FUNC(debug);
}; };
}foreach _previousGroupsList; } forEach _previousGroupsList;
reverse _previousGroupsList; reverse _previousGroupsList;
{ {
@ -55,10 +63,12 @@ if (_switch) then {
if (count units _currentGroup == 0) then { if (count units _currentGroup == 0) then {
deleteGroup _currentGroup; deleteGroup _currentGroup;
}; };
_previousGroupsList set [_foreachIndex, ObjNull]; _previousGroupsList set [_forEachIndex, objNull];
}; };
}foreach _previousGroupsList; } forEach _previousGroupsList;
_previousGroupsList = _previousGroupsList - [objNull]; _previousGroupsList = _previousGroupsList - [objNull];
reverse _previousGroupsList; // we have to reverse again, to ensure the list is in the right order. 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 * Author: Nou
*
* Execute a event only on specific clients. * Execute a event only on specific clients.
* *
* Argument: * Arguments:
* 0: Event name (string) * 0: Event name (STRING)
* 1: Event targets (object or array of objects) * 1: Event targets <OBJECT, ARRAY>
* 2: Event args (any) * 2: Event args <ANY>
* *
* Note: If local executor is in list of targets, event will execute with * Note: If local executor is in list of targets, event will execute with
* network delay, and not immediatly. * network delay, and not immediatly.
* *
* Return value: * Return Value:
* Nothing * None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
//IGNORE_PRIVATE_WARNING("_handleNetEvent"); params ["_eventName", "_eventTargets", "_eventArgs"];
PARAMS_3(_eventName,_eventTargets,_eventArgs);
#ifdef DEBUG_EVENTS #ifdef DEBUG_EVENTS
ACE_LOGINFO_2("* Target Event: %1 - %2",_eventName,_eventTargets); ACE_LOGINFO_2("* Target Event: %1 - %2",_eventName,_eventTargets);
@ -26,7 +25,8 @@ PARAMS_3(_eventName,_eventTargets,_eventArgs);
#endif #endif
ACEc = [_eventName, _eventTargets, _eventArgs]; ACEc = [_eventName, _eventTargets, _eventArgs];
if(!isServer) then {
if (!isServer) then {
publicVariableServer "ACEc"; publicVariableServer "ACEc";
} else { } else {
["ACEc", ACEc] call FUNC(_handleNetEvent); ["ACEc", ACEc] call FUNC(_handleNetEvent);

View File

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

View File

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

View File

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

View File

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

View File

@ -1,25 +1,23 @@
/* /*
Name: FUNC(toNumber) * Author: Garth de Wet (LH)
*
Author(s): * Takes a string/number and returns the number.
Garth de Wet (LH) *
* Arguments:
Description: * 0: Value to attempt to convert to number or if number simply return number. <STRING, NUMBER>
Takes a string/number and returns the number. *
* Return Value:
Parameters: * <NUMBER>
0: TYPE - Value to attempt to convert to number or if number simply return number. *
* Example:
Returns: * number = ["102"] call ace_common_fnc_toNumber;
NUMBER *
* Public: Yes
Example: */
number = ["102"] call FUNC(toNumber);
*/
#include "script_component.hpp" #include "script_component.hpp"
if (typeName (_this select 0) == "SCALAR") exitWith { params ["_value"];
(_this select 0)
};
(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" #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; _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; _offset params ["_x", "_y", "_z"];
_y = _offset select 1;
_z = _offset select 2;
_out = (((_xVec vectorMultiply _x) vectorAdd (_yVec vectorMultiply _y)) vectorAdd (_zVec vectorMultiply _z)) vectorAdd _origin; (_xVec vectorMultiply _x) vectorAdd (_yVec vectorMultiply _y) vectorAdd (_zVec vectorMultiply _z) vectorAdd _origin // return
_out;

View File

@ -1,26 +1,31 @@
/*
* Author: ?
*
* ?
*
* Arguments:
* ?
*
* Return Value:
* ?
*
* Public: ?
*/
#include "script_component.hpp" #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; _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; _offset = _offset vectorDiff _origin;
_x = _offset select 0; _offset params ["_x", "_y", "_z"];
_y = _offset select 1;
_z = _offset select 2;
_out = [ [
((_xVec select 0)*_x) + ((_xVec select 1)*_y) + ((_xVec select 2)*_z), ((_xVec select 0) * _x) + ((_xVec select 1) * _y) + ((_xVec select 2) * _z),
((_yVec select 0)*_x) + ((_yVec select 1)*_y) + ((_yVec 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) ((_zVec select 0) * _x) + ((_zVec select 1) * _y) + ((_zVec select 2) * _z)
]; ] // return
_out;