more common code cleanup

This commit is contained in:
commy2 2015-09-19 22:27:23 +02:00
parent bfd5d13de8
commit 6b96c7fd7c
14 changed files with 119 additions and 89 deletions

View File

@ -1,13 +1,18 @@
/**
* fn_hasItem.sqf
* @Descr: Check if unit has item
* @Author: Glowbal
/*
* Author: Glowbal
* Check if unit has item
*
* @Arguments: [unit OBJECT, item STRING (Classname of item)]
* @Return: BOOL
* @PublicAPI: true
* Arguments:
* 0: Unit <OBJECT>
* 1: Item Classname <STRING>
*
* Return Value:
* has Item <BOOL>
*
* Public: yes
*/
#include "script_component.hpp"
#include "script_component.hpp"
// item classname in items unit
((_this select 1) in items (_this select 0));
params ["_unit", "_item"];
_item in items _unit // return

View File

@ -1,22 +1,18 @@
/**
* fn_hasMagazine.sqf
* @Descr: Check if given unit has a magazine of given classname
* @Author: Glowbal
/*
* Author: Glowbal
* Check if given unit has a magazine of given classname
*
* @Arguments: [unit OBJECT, magazine STRING]
* @Return: BOOL True if unith as given magazine
* @PublicAPI: true
* Arguments:
* 0: Unit <OBJECT>
* 1: Magazine Classname <STRING>
*
* Return Value:
* has Magazine <BOOL>
*
* Public: yes
*/
#include "script_component.hpp"
private ["_return"];
PARAMS_2(_unit,_magazine);
params ["_unit", "_magazine"];
if (_magazine != "") then {
_return = (_magazine in magazines _unit);
} else {
_return = false;
};
_return
_magazine in magazines _unit // return

View File

@ -34,7 +34,7 @@ titleCut ["", "BLACK"];
_dummy = createVehicle ["ACE_Headbug_Fix", _pos, [], 0, "NONE"];
_dummy setDir _dir;
_unit moveInAny _dummy;
sleep 0.1;
sleep 0.1; // @todo
unassignVehicle _unit;
_unit action ["Eject", vehicle _unit];

View File

@ -12,4 +12,4 @@
*/
#include "script_component.hpp"
getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState (_this select 0) >> "looped") == 0
getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState (_this select 0) >> "looped") == 0 // return

View File

@ -1,25 +1,36 @@
/**
* fn_inheritsFrom.sqf
* @Descr: Checks whether a given configuration name appears in the inheritance tree of a specific configuration entry.
* @Author: Ruthberg
/*
* Author: Ruthberg
* Checks whether a given configuration name appears in the inheritance tree of a specific configuration entry.
*
* @Arguments: [configEntry CONFIG, configname STRING]
* @Return: BOOL
* @PublicAPI: true
* Arguments:
* 0: configEntry (CONFIG)
* 1: configname (STING)
*
* Return Value:
* BOOLEAN
*
* Public: Yes
*
* Note: Not to be confused with the inheritsFrom scripting command.
*
* Deprecated
*/
#include "script_component.hpp"
private ["_match"];
PARAMS_2(_configEntry,_configMatch);
params ["_configEntry", "_configMatch"];
if (configName _configEntry == _configMatch) exitWith { true };
if (configName _configEntry == ",") exitWith { false };
if (configName _configEntry == _configMatch) exitWith {true};
if (configName _configEntry == ",") exitWith {false};
private "_match";
_match = false;
while {configName _configEntry != ""} do {
if (configName _configEntry == _configMatch) exitWith { _match = true };
_configEntry = inheritsFrom(_configEntry);
if (configName _configEntry == _configMatch) exitWith {
_match = true;
};
_configEntry = inheritsFrom _configEntry;
};
_match
_match

View File

@ -1,34 +1,38 @@
/**
* fn_insertionSort.sqf
* @Descr: Sorts an array of numbers
* @Author: Ruthberg
/*
* Author: Ruthberg
* Sorts an array of numbers
*
* @Arguments: [array ARRAY, (optional) ascending BOOL]
* @Return: sortedArray ARRAY
* @PublicAPI: true
* Arguments:
* 0: array <ARRAY>
* 1: ascending (optional) <BOOL>
*
* Return Value:
* sortedArray (ARRAY)
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_list", "_ascending", "_tmp", "_i", "_j"];
_list = +(_this select 0);
_ascending = true;
if (count _this > 1) then {
_ascending = _this select 1;
};
params ["_list", ["_ascending", true]];
for "_i" from 1 to (count _list) - 1 do {
_list = + _list; // copy array to not alter the original one
private "_tmp";
for "_i" from 1 to (count _list - 1) do {
_tmp = _list select _i;
_j = _i;
while {_j >= 1 && {_tmp < _list select (_j - 1)}} do {
_list set [_j, _list select (_j - 1)];
_j = _j - 1;
};
_list set[_j, _tmp];
_list set [_j, _tmp];
};
if (!_ascending) then {
reverse _list;
};
_list
_list

View File

@ -1,11 +1,23 @@
// by commy2
/*
* Author: commy2
* Interpolates between two set points in a curve.
*
* Arguments:
* 0: List of numbers to interpolate from <ARRAY>
* 1: Value / index <NUMBER>
*
* Return Value:
* Interpolation result <NUMBER>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_min", "_max"];
params ["_array", "_value"];
PARAMS_2(_array,_value);
private ["_min", "_max"];
_min = _array select floor _value;
_max = _array select ceil _value;
_min + (_max - _min) * (_value % 1)
_min + (_max - _min) * (_value % 1) // return

View File

@ -1,14 +1,15 @@
/*
* Author: commy2
*
* Check if wind is set on auto.
*
* Argument:
* None.
* Arguments
* None
*
* Return value:
* This mission has automatic wind? (Bool)
* Return Value:
* This mission has automatic wind? <BOOL>
*
* Public: Yes
*/
#include "script_component.hpp"
["Mission", "Intel", "windForced"] call FUNC(getNumberFromMissionSQM) != 1
["Mission", "Intel", "windForced"] call FUNC(getNumberFromMissionSQM) != 1 // return

View File

@ -1,15 +1,18 @@
/**
* fn_isAwake.sqf
* @Descr: Check if unit is awake. Will be false when death or unit is unconscious.
* @Author: Glowbal
/*
* Author: Glowbal
*
* @Arguments: [unit OBJECT]
* @Return: BOOL True if unit is awake
* @PublicAPI: true
* Check if unit is awake. Will be false when death or unit is unconscious.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* if unit is awake <BOOL>
*
* Public: Yes
*/
#include "script_component.hpp"
PARAMS_1(_unit);
params ["_unit"];
(!(_unit getvariable ["ACE_isUnconscious",false]) && alive _unit && !(_unit getvariable ["ACE_isDead",false]));
!(_unit getvariable ["ACE_isUnconscious", false]) && alive _unit && !(_unit getvariable ["ACE_isDead", false]);

View File

@ -20,4 +20,4 @@
params ["_unit"];
_unit getVariable ["ACE_isEOD", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "canDeactivateMines") == 1]
_unit getVariable ["ACE_isEOD", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "canDeactivateMines") == 1] // return

View File

@ -14,4 +14,4 @@
params ["_unit"];
_unit getVariable ["ACE_isEngineer", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "engineer") == 1]
_unit getVariable ["ACE_isEngineer", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "engineer") == 1] // return

View File

@ -19,9 +19,8 @@
* Example:
* [] call ace_common_fnc_isFeatureCameraActive
*
* Public: No
* Public: Yes
*/
#include "script_component.hpp"
!(
@ -32,4 +31,4 @@
{isNull (GETMVAR(BIS_fnc_camera_cam, objNull))} && // Splendid camera
{isNull (GETUVAR(BIS_fnc_animViewer_cam, objNull))} && // Animation viewer camera
{isNull (GETMVAR(BIS_DEBUG_CAM, objNull))} // Classic camera
)
) // return

View File

@ -10,7 +10,6 @@
*
* Public: Yes
*/
#include "script_component.hpp"
isClass (configFile >> "cfgPatches" >> _this select 0)
isClass (configFile >> "cfgPatches" >> _this select 0) // return

View File

@ -16,4 +16,4 @@
params ["_unit", ["_excludeRemoteControlled", false]];
isPlayer _unit || (!_excludeRemoteControlled && {_unit == call FUNC(player)})
isPlayer _unit || (!_excludeRemoteControlled && {_unit == call FUNC(player)}) // return