From eea0ac7ccb030800b4409dc3f9074e35d814b55c Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 00:54:33 +0100 Subject: [PATCH 01/18] move parseYAML to hashes --- addons/common/fnc_parseYAML.sqf | 356 ------------------ addons/hashes/CfgFunctions.hpp | 6 + addons/hashes/fnc_parseYAML.sqf | 282 ++++++++++++++ addons/hashes/test.sqf | 2 +- addons/{common => hashes}/test_parseYaml.sqf | 64 ++-- .../test_parseYaml_config.yml | 34 +- 6 files changed, 338 insertions(+), 406 deletions(-) delete mode 100644 addons/common/fnc_parseYAML.sqf create mode 100644 addons/hashes/fnc_parseYAML.sqf rename addons/{common => hashes}/test_parseYaml.sqf (95%) rename addons/{common => hashes}/test_parseYaml_config.yml (94%) diff --git a/addons/common/fnc_parseYAML.sqf b/addons/common/fnc_parseYAML.sqf deleted file mode 100644 index bd69ee20a..000000000 --- a/addons/common/fnc_parseYAML.sqf +++ /dev/null @@ -1,356 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_parseYAML - -Description: - Parses a YAML file into a nested array/Hash structure. - - See also: - -Parameters: - _file - Name of Yaml formatted file to parse [String]. - -Returns: - Data structure taken from the file, or nil if file had syntax errors. - -Author: - Spooner ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" -#include "\x\cba\addons\strings\script_strings.hpp" - -#define YAML_MODE_STRING 0 -#define YAML_MODE_ASSOC_KEY 1 -#define YAML_MODE_ASSOC_VALUE 2 -#define YAML_MODE_ARRAY 3 - -#define YAML_TYPE_UNKNOWN 0 -#define YAML_TYPE_SCALAR 1 -#define YAML_TYPE_ARRAY 2 -#define YAML_TYPE_ASSOC 3 - -#define ASCII_YAML_COMMENT ASCII_HASH -#define ASCII_YAML_ASSOC ASCII_COLON -#define ASCII_YAML_ARRAY ASCII_MINUS - -SCRIPT(parseYAML); - -// ----------------------------------------------------------------------------- - -private "_raiseError"; -_raiseError = -{ - params ["_message","_yaml","_pos","_lines"]; - - private ["_errorBlock", "_i", "_lastLine", "_lastChar"]; - - _lastLine = _lines select ((count _lines) - 1); - _lastChar = _lastLine select ((count _lastLine) - 1); - _lastLine resize ((count _lastLine) - 1); - - _lastLine pushBack ASCII_VERTICAL_BAR; - _lastLine pushBack ASCII_HASH; - _lastLine pushBack ASCII_VERTICAL_BAR; - _lastLine pushBack _lastChar; - - _pos = _pos + 1; - while { _pos < (count _yaml) } do { - _char = _yaml select _pos; - - if (_char in [ASCII_YAML_COMMENT, ASCII_CR, ASCII_NEWLINE]) exitWith {}; - - _lastLine pushBack _char; - - _pos = _pos + 1; - }; - - _errorBlock = ""; - for [{ _i = 0 max ((count _lines) - 6) }, { _i < (count _lines)}, { _i = _i + 1 }] do { - _errorBlock = _errorBlock + format ["\n%1: %2", [_i + 1, 3] call CBA_fnc_formatNumber, - toString (_lines select _i)]; - }; - - _message = format ["%1, in ""%2"" at line %3:\n%4", _message, - _file, count _lines, _errorBlock]; - - ERROR_WITH_TITLE("CBA YAML parser error",_message); -}; - -private "_parse"; -_parse = -{ - params ["_yaml","_pos","_indent","_lines"]; - - private ["_error", "_currentIndent", "_key", "_value", "_return", - "_mode", "_dataType", "_data"]; - - _error = false; - _currentIndent = _indent max 0; - _key = []; - _value = []; - _return = false; - _mode = YAML_MODE_STRING; - _dataType = YAML_TYPE_UNKNOWN; - // _data is initially undefined. - - //TRACE_3("Parsing YAML data item",_currentIndent,_pos,count _lines); - - while { (_pos < ((count _yaml) - 1)) and (not _error) and (not _return) } do - { - _pos = _pos + 1; - _char = _yaml select _pos; - - if (_char == ASCII_YAML_COMMENT) then - { - // Trim comments. - while { not (_char in _lineBreaks) } do - { - _pos = _pos + 1; - _char = _yaml select _pos; - }; - - _pos = _pos - 1; // Parse the newline normally. - } else { - if (_char in _lineBreaks) then - { - _currentIndent = 0; - _lines pushBack []; - } else { - (_lines select ((count _lines) - 1)) pushBack _char; - }; - - switch (_mode) do - { - case YAML_MODE_ARRAY: - { - if (_char in _lineBreaks) then - { - _value = [toString _value] call CBA_fnc_trim; - - // If remainder of line is blank, assume - // multi-line data. - if (([_value] call CBA_fnc_strLen) == 0) then - { - private ["_retVal"]; - - _retVal = ([_yaml, _pos, _currentIndent, _lines] call _parse); - _pos = _retVal select 0; - _value = _retVal select 1; - _error = _retVal select 2; - }; - - if (not _error) then - { - //TRACE_1("Added Array element",_value); - _data pushBack _value; - _mode = YAML_MODE_STRING; - }; - } else { - _value pushBack _char; - }; - }; - case YAML_MODE_ASSOC_KEY: - { - if (_char in _lineBreaks) then - { - ["Unexpected new-line, when expecting ':'", - _yaml, _pos, _lines] call _raiseError; - _error = true; - } else { - switch (_char) do - { - case ASCII_YAML_ASSOC: - { - _key = [toString _key] call CBA_fnc_trim; - _mode = YAML_MODE_ASSOC_VALUE; - }; - default - { - _key pushBack _char; - }; - }; - }; - }; - case YAML_MODE_ASSOC_VALUE: - { - if (_char in _lineBreaks) then - { - _value = [toString _value] call CBA_fnc_trim; - - // If remainder of line is blank, assume - // multi-line data. - if (([_value] call CBA_fnc_strLen) == 0) then - { - private ["_retVal"]; - - _retVal = ([_yaml, _pos, _currentIndent, _lines] call _parse); - _pos = _retVal select 0; - _value = _retVal select 1; - _error = _retVal select 2; - }; - - if (not _error) then - { - //TRACE_1("Added Hash element",_value); - [_data, _key, _value] call CBA_fnc_hashSet; - _mode = YAML_MODE_STRING; - }; - } else { - _value pushBack _char; - }; - }; - case YAML_MODE_STRING: - { - switch (_char) do - { - case ASCII_CR: - { - // Already dealt with. - }; - case ASCII_NEWLINE: - { - // Already dealt with. - }; - case ASCII_SPACE: - { - _currentIndent = _currentIndent + 1; - //TRACE_2("Indented",_indent,_currentIndent); - }; - case ASCII_TAB: - { - ["Tab character not allowed for indenting YAML; use spaces instead", - _yaml, _pos, _lines] call _raiseError; - _error = true; - }; - case ASCII_YAML_ASSOC: - { - ["Can't start a line with ':'", - _yaml, _pos, _lines] call _raiseError; - _error = true; - }; - case ASCII_YAML_ARRAY: - { - //TRACE_2("Array element found",_indent,_currentIndent); - - if (_currentIndent > _indent) then - { - if (_dataType == YAML_TYPE_UNKNOWN) then - { - //TRACE_2("Starting new Array",count _lines,_indent); - - _data = []; - _dataType = YAML_TYPE_ARRAY; - - _indent = _currentIndent; - - _value = []; - _mode = YAML_MODE_ARRAY; - } else { - //TRACE_2("BLAH",_indent,_currentIndent); - _error = true; - }; - } - else{if (_currentIndent < _indent) then - { - // Ignore and pass down the stack. - //TRACE_2("End of Array",count _lines,_indent); - _pos = _pos - 1; - _return = true; - } else { - if (_dataType == YAML_TYPE_ARRAY) then - { - //TRACE_2("New element of Array",count _lines,_indent); - _value = []; - _mode = YAML_MODE_ARRAY; - } else { - //TRACE_3("BLEHH",_dataType,_indent,_currentIndent); - _error = true; - }; - }; }; - }; - default // Anything else must be the start of an associative key. - { - if (_currentIndent > _indent) then - { - if (_dataType == YAML_TYPE_UNKNOWN) then - { - //TRACE_2("Starting new Hash",count _lines,_indent); - - _data = [] call CBA_fnc_hashCreate; - _dataType = YAML_TYPE_ASSOC; - - _indent = _currentIndent; - - _key = [_char]; - _value = []; - _mode = YAML_MODE_ASSOC_KEY; - } else { - //TRACE_3("BLAH",_dataType,_indent,_currentIndent); - _error = true; - }; - } - else{if (_currentIndent < _indent) then - { - // Ignore and pass down the stack. - //TRACE_2("End of Hash",count _lines,_indent); - _pos = _pos - 1; - _return = true; - } else { - if (_dataType == YAML_TYPE_ASSOC) then - { - //TRACE_2("New element of Hash",count _lines,_indent); - _key = [_char]; - _value = []; - _mode = YAML_MODE_ASSOC_KEY; - } else { - //TRACE_3("BLEH",_dataType,_indent,_currentIndent); - _error = true; - }; - }; }; - }; - }; - }; - }; - }; - }; - - //TRACE_4("Parsed YAML data item",_indent,_pos,_error,count _lines); - - [_pos, _data, _error]; // Return. -}; - -// ---------------------------------------------------------------------------- - -params ["_file"]; - -private ["_yamlString", "_yaml", "_outerData", "_lineBreaks"]; -_yamlString = loadFile _file; -_yaml = toArray _yamlString; - -_lineBreaks = [ASCII_NEWLINE, ASCII_CR]; - -//TRACE_2("Parsing YAML file",_file,count _yaml); - -// Ensure input ends with a newline. -if (count _yaml > 0) then -{ - if (not ((_yaml select ((count _yaml) - 1)) in _lineBreaks)) then - { - _yaml pushBack ASCII_NEWLINE; - }; -}; - -_pos = -1; - -_retVal = ([_yaml, _pos, -1, [[]]] call _parse); -_pos = _retVal select 0; -_value = _retVal select 1; -_error = _retVal select 2; -//TRACE_2("Parsed",_pos,_error); - -if (_error) then -{ - nil; // Return. -} else { - _value; // Return. -}; diff --git a/addons/hashes/CfgFunctions.hpp b/addons/hashes/CfgFunctions.hpp index a28d6d58b..54e9fb0e1 100644 --- a/addons/hashes/CfgFunctions.hpp +++ b/addons/hashes/CfgFunctions.hpp @@ -57,6 +57,12 @@ class CfgFunctions description = "Internal Self Check. Check the RPT file for results."; file = "\x\cba\addons\hashes\test.sqf"; }; + // CBA_fnc_parseYAML + class parseYAML + { + description = "Parses a YAML file into a nested array/Hash structure."; + file = "\x\cba\addons\hashes\fnc_parseYAML.sqf"; + }; }; }; }; diff --git a/addons/hashes/fnc_parseYAML.sqf b/addons/hashes/fnc_parseYAML.sqf new file mode 100644 index 000000000..01ef3bc31 --- /dev/null +++ b/addons/hashes/fnc_parseYAML.sqf @@ -0,0 +1,282 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_parseYAML + +Description: + Parses a YAML file into a nested array/Hash structure. + + See also: + +Parameters: + _file - Name of Yaml formatted file to parse . + +Returns: + Data structure taken from the file, or nil if file had syntax errors. + +Author: + Spooner +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(parseYAML); + +#include "\x\cba\addons\strings\script_strings.hpp" + +#define YAML_MODE_STRING 0 +#define YAML_MODE_ASSOC_KEY 1 +#define YAML_MODE_ASSOC_VALUE 2 +#define YAML_MODE_ARRAY 3 + +#define YAML_TYPE_UNKNOWN 0 +#define YAML_TYPE_SCALAR 1 +#define YAML_TYPE_ARRAY 2 +#define YAML_TYPE_ASSOC 3 + +#define ASCII_YAML_COMMENT ASCII_HASH +#define ASCII_YAML_ASSOC ASCII_COLON +#define ASCII_YAML_ARRAY ASCII_MINUS +// ----------------------------------------------------------------------------- + +private _raiseError = { + params ["_message", "_yaml", "_pos", "_lines"]; + + private _lastLine = _lines select ((count _lines) - 1); + private _lastChar = _lastLine select ((count _lastLine) - 1); + + _lastLine resize ((count _lastLine) - 1); + + _lastLine pushBack ASCII_VERTICAL_BAR; + _lastLine pushBack ASCII_HASH; + _lastLine pushBack ASCII_VERTICAL_BAR; + _lastLine pushBack _lastChar; + + _pos = _pos + 1; + while { _pos < (count _yaml) } do { + _char = _yaml select _pos; + + if (_char in [ASCII_YAML_COMMENT, ASCII_CR, ASCII_NEWLINE]) exitWith {}; + + _lastLine pushBack _char; + + _pos = _pos + 1; + }; + + private _errorBlock = ""; + + for [{_i = 0 max ((count _lines) - 6)}, {_i < count _lines}, {_i = _i + 1}] do { + _errorBlock = _errorBlock + format ["\n%1: %2", [_i + 1, 3] call CBA_fnc_formatNumber, + toString (_lines select _i)]; + }; + + _message = format ["%1, in ""%2"" at line %3:\n%4", _message, + _file, count _lines, _errorBlock]; + + ERROR_WITH_TITLE("CBA YAML parser error",_message); +}; + +private _parse = { + params ["_yaml", "_pos", "_indent", "_lines"]; + + private _error = false; + private _currentIndent = _indent max 0; + private _key = []; + private _value = []; + private _return = false; + private _mode = YAML_MODE_STRING; + private _dataType = YAML_TYPE_UNKNOWN; + private "_data"; //is initially undefined. + + while {_pos < ((count _yaml) - 1) && !_error && !_return} do { + _pos = _pos + 1; + _char = _yaml select _pos; + + if (_char == ASCII_YAML_COMMENT) then { + // Trim comments. + while {!(_char in _lineBreaks)} do { + _pos = _pos + 1; + _char = _yaml select _pos; + }; + + _pos = _pos - 1; // Parse the newline normally. + } else { + if (_char in _lineBreaks) then { + _currentIndent = 0; + _lines pushBack []; + } else { + (_lines select ((count _lines) - 1)) pushBack _char; + }; + + switch (_mode) do { + case YAML_MODE_ARRAY: { + if (_char in _lineBreaks) then { + _value = [toString _value] call CBA_fnc_trim; + + // If remainder of line is blank, assume + // multi-line data. + if (([_value] call CBA_fnc_strLen) == 0) then { + private _retVal = ([_yaml, _pos, _currentIndent, _lines] call _parse); + + _pos = _retVal select 0; + _value = _retVal select 1; + _error = _retVal select 2; + }; + + if !(_error) then { + _data pushBack _value; + _mode = YAML_MODE_STRING; + }; + } else { + _value pushBack _char; + }; + }; + case YAML_MODE_ASSOC_KEY: { + if (_char in _lineBreaks) then { + ["Unexpected new-line, when expecting ':'", _yaml, _pos, _lines] call _raiseError; + _error = true; + } else { + switch (_char) do { + case ASCII_YAML_ASSOC: { + _key = [toString _key] call CBA_fnc_trim; + _mode = YAML_MODE_ASSOC_VALUE; + }; + default { + _key pushBack _char; + }; + }; + }; + }; + case YAML_MODE_ASSOC_VALUE: { + if (_char in _lineBreaks) then { + _value = [toString _value] call CBA_fnc_trim; + + // If remainder of line is blank, assume + // multi-line data. + if (([_value] call CBA_fnc_strLen) == 0) then { + private _retVal = ([_yaml, _pos, _currentIndent, _lines] call _parse); + + _pos = _retVal select 0; + _value = _retVal select 1; + _error = _retVal select 2; + }; + + if !(_error) then { + //TRACE_1("Added Hash element",_value); + [_data, _key, _value] call CBA_fnc_hashSet; + _mode = YAML_MODE_STRING; + }; + } else { + _value pushBack _char; + }; + }; + case YAML_MODE_STRING: { + switch (_char) do { + case ASCII_CR: { + // Already dealt with. + }; + case ASCII_NEWLINE: { + // Already dealt with. + }; + case ASCII_SPACE: { + _currentIndent = _currentIndent + 1; + }; + case ASCII_TAB: { + ["Tab character not allowed for indenting YAML; use spaces instead", _yaml, _pos, _lines] call _raiseError; + _error = true; + }; + case ASCII_YAML_ASSOC: { + ["Can't start a line with ':'", _yaml, _pos, _lines] call _raiseError; + _error = true; + }; + case ASCII_YAML_ARRAY: { + if (_currentIndent > _indent) then { + if (_dataType == YAML_TYPE_UNKNOWN) then { + _data = []; + _dataType = YAML_TYPE_ARRAY; + + _indent = _currentIndent; + + _value = []; + _mode = YAML_MODE_ARRAY; + } else { + _error = true; + }; + } else { + if (_currentIndent < _indent) then { + // Ignore and pass down the stack. + _pos = _pos - 1; + _return = true; + } else { + if (_dataType == YAML_TYPE_ARRAY) then { + _value = []; + _mode = YAML_MODE_ARRAY; + } else { + _error = true; + }; + }; + }; + }; + default { // Anything else must be the start of an associative key. + if (_currentIndent > _indent) then { + if (_dataType == YAML_TYPE_UNKNOWN) then { + _data = [] call CBA_fnc_hashCreate; + _dataType = YAML_TYPE_ASSOC; + + _indent = _currentIndent; + + _key = [_char]; + _value = []; + _mode = YAML_MODE_ASSOC_KEY; + } else { + _error = true; + }; + } else { + if (_currentIndent < _indent) then { + // Ignore and pass down the stack. + _pos = _pos - 1; + _return = true; + } else { + if (_dataType == YAML_TYPE_ASSOC) then { + _key = [_char]; + _value = []; + _mode = YAML_MODE_ASSOC_KEY; + } else { + _error = true; + }; + }; + }; + }; + }; + }; + }; + }; + }; + + [_pos, _data, _error]; // Return. +}; + +// ---------------------------------------------------------------------------- + +params ["_file"]; + +private _yamlString = loadFile _file; +private _yaml = toArray _yamlString; +private _lineBreaks = [ASCII_NEWLINE, ASCII_CR]; + +// Ensure input ends with a newline. +if (count _yaml > 0) then +{ + if !((_yaml select ((count _yaml) - 1)) in _lineBreaks) then { + _yaml pushBack ASCII_NEWLINE; + }; +}; + +_pos = -1; + +_retVal = ([_yaml, _pos, -1, [[]]] call _parse); +_pos = _retVal select 0; +_value = _retVal select 1; +_error = _retVal select 2; + +if (_error) then { + nil // Return. +} else { + _value // Return. +}; diff --git a/addons/hashes/test.sqf b/addons/hashes/test.sqf index 45e671fe7..b32d3d8bd 100644 --- a/addons/hashes/test.sqf +++ b/addons/hashes/test.sqf @@ -5,7 +5,7 @@ #define DEBUG_MODE_FULL #include "script_component.hpp" -#define TESTS ["hashEachPair", "hashes"] +#define TESTS ["hashEachPair", "hashes", "parseYaml"] SCRIPT(test-hashes); diff --git a/addons/common/test_parseYaml.sqf b/addons/hashes/test_parseYaml.sqf similarity index 95% rename from addons/common/test_parseYaml.sqf rename to addons/hashes/test_parseYaml.sqf index 0292c85b1..795e779aa 100644 --- a/addons/common/test_parseYaml.sqf +++ b/addons/hashes/test_parseYaml.sqf @@ -1,32 +1,32 @@ -// ---------------------------------------------------------------------------- - -#include "script_component.hpp" - -SCRIPT(test_parseYaml); - -// ---------------------------------------------------------------------------- - -private ["_expected", "_result", "_fn", "_data"]; - -_fn = "CBA_fnc_parseYaml"; -LOG("Testing " + _fn); - -TEST_DEFINED("CBA_fnc_parseYaml",_fn); - -_data = ["\x\cba\addons\common\test_parseYaml_config.yml"] call CBA_fnc_parseYaml; - -TEST_TRUE([_data] call CBA_fnc_isHash,_fn); - -_result = [_data, "anotherNumber"] call CBA_fnc_hashGet; -_expected = "42"; -TEST_OP(_result,==,_expected,_fn); - -_result = ([_data, "nestedArray"] call CBA_fnc_hashGet) select 0; -_expected = "first"; -TEST_OP(_result,==,_expected,_fn); - -_result = (([_data, "nestedArray"] call CBA_fnc_hashGet) select 2) select 1; -_expected = "3.2"; -TEST_OP(_result,==,_expected,_fn); - -nil; +// ---------------------------------------------------------------------------- + +#include "script_component.hpp" + +SCRIPT(test_parseYaml); + +// ---------------------------------------------------------------------------- + +private ["_expected", "_result", "_fn", "_data"]; + +_fn = "CBA_fnc_parseYaml"; +LOG("Testing " + _fn); + +TEST_DEFINED("CBA_fnc_parseYaml",_fn); + +_data = ["\x\cba\addons\common\test_parseYaml_config.yml"] call CBA_fnc_parseYaml; + +TEST_TRUE([_data] call CBA_fnc_isHash,_fn); + +_result = [_data, "anotherNumber"] call CBA_fnc_hashGet; +_expected = "42"; +TEST_OP(_result,==,_expected,_fn); + +_result = ([_data, "nestedArray"] call CBA_fnc_hashGet) select 0; +_expected = "first"; +TEST_OP(_result,==,_expected,_fn); + +_result = (([_data, "nestedArray"] call CBA_fnc_hashGet) select 2) select 1; +_expected = "3.2"; +TEST_OP(_result,==,_expected,_fn); + +nil diff --git a/addons/common/test_parseYaml_config.yml b/addons/hashes/test_parseYaml_config.yml similarity index 94% rename from addons/common/test_parseYaml_config.yml rename to addons/hashes/test_parseYaml_config.yml index 7e2776f1e..da850a0ad 100644 --- a/addons/common/test_parseYaml_config.yml +++ b/addons/hashes/test_parseYaml_config.yml @@ -1,18 +1,18 @@ -# Test file for yaml parsing. - -frog: false # If true, the key settings will be ignored. -number: 1 # ` - -nestedHash: - a: alpha - b: bravo - c: charlie # Interesting list, eh? - -nestedArray: - - first - - second - - - - 3.1 - - 3.2 - +# Test file for yaml parsing. + +frog: false # If true, the key settings will be ignored. +number: 1 # ` + +nestedHash: + a: alpha + b: bravo + c: charlie # Interesting list, eh? + +nestedArray: + - first + - second + - + - 3.1 + - 3.2 + anotherNumber: 42 \ No newline at end of file From a74effc588abe48661766a7a04e0484d6156f74b Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 00:57:14 +0100 Subject: [PATCH 02/18] rewrite common inventory functions --- addons/common/fnc_addItem.sqf | 71 +++++++++++++++ addons/common/fnc_addMagazine.sqf | 81 +++++++++++------ addons/common/fnc_addWeapon.sqf | 94 +++++++++++++------- addons/common/fnc_removeItem.sqf | 55 ++++++++++++ addons/common/fnc_removeMagazine.sqf | 124 ++++++++++++++++++++------- addons/common/fnc_removeWeapon.sqf | 55 +++++------- addons/common/test_inventory.sqf | 74 ++++++++++++++++ 7 files changed, 432 insertions(+), 122 deletions(-) create mode 100644 addons/common/fnc_addItem.sqf create mode 100644 addons/common/fnc_removeItem.sqf create mode 100644 addons/common/test_inventory.sqf diff --git a/addons/common/fnc_addItem.sqf b/addons/common/fnc_addItem.sqf new file mode 100644 index 000000000..e01c38f25 --- /dev/null +++ b/addons/common/fnc_addItem.sqf @@ -0,0 +1,71 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addItem + +Description: + Add an item to a unit. + + Function which verifies existence of _item and _unit, returns false in + case of trouble, or when able to add _item to _unit true in case of success. + +Parameters: + _unit - the unit + _item - name of the weapon to add + _verify - if true, then put item on the ground if it can't be added + +Returns: + true on success, false otherwise + +Examples: + (begin example) + _result = [player, "Binocular"] call CBA_fnc_addItem + (end) + +Author: + +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(addItem); + +params [["_unit", objNull, [objNull]], ["_item", "", [""]], ["_verify", false, [false]]]; + +private _return = false; + +if (isNull _unit) exitWith { + TRACE_2("Unit not Object or null",_unit,_item); + _return +}; + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_unit,_item); + _return +}; + +private _config = _item call CBA_fnc_getItemConfig; + +if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith { + TRACE_2("Item does not exist in Config",_unit,_item); + _return +}; + +if (_verify) then { + if (_unit canAdd _item) then { + _unit addItem _item; + _return = true; + } else { + _unit switchMove "ainvpknlmstpslaywrfldnon_1"; + + private _weaponHolder = nearestObject [_unit, "WeaponHolder"]; + + if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then { + _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; + _weaponHolder setPosASL getPosASL _unit; + }; + + [_weaponHolder, _item] call CBA_fnc_addItemCargo; + }; +} else { + _unit addItem _item; + _return = true; +}; + +_return diff --git a/addons/common/fnc_addMagazine.sqf b/addons/common/fnc_addMagazine.sqf index 10eda1d51..a1b10ce19 100644 --- a/addons/common/fnc_addMagazine.sqf +++ b/addons/common/fnc_addMagazine.sqf @@ -8,50 +8,75 @@ Description: case of trouble, or true when able to add _item to _unit. Parameters: - _unit - the unit or vehicle - _item - name of the magazine to add + _unit - the unit or vehicle + _item - name of the magazine to add + _ammo - ammo count + _verify - if true, then put item on the ground if it can't be added Returns: - true on success, false otherwise + true on success, false otherwise Examples: (begin example) - _result = [player, "SmokeShell"] call CBA_fnc_addMagazine + _result = [player, "SmokeShell"] call CBA_fnc_addMagazine (end) Author: ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(addMagazine); -#define __scriptname fAddMagazine +params [["_unit", objNull, [objNull]], ["_item", "", [""]], ["_ammo", -1, [0]], ["_verify", false, [false]]]; -#define __cfg (configFile >> "CfgMagazines") -#define __action addMagazine +private _return = false; -params ["_unit","_item"]; -if (typeName _unit != "OBJECT") exitWith { - TRACE_2("Unit not Object",_unit,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_unit,_item); - false -}; if (isNull _unit) exitWith { - TRACE_2("Unit isNull",_unit,_item); - false + TRACE_2("Unit not Object or null",_unit,_item); + _return }; -if (_item == "") exitWith { - TRACE_2("Empty Item",_unit,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_unit,_item); + _return +}; + +private _config = configFile >> "CfgMagazines" >> _item; + +if (!isClass _config || {getNumber (_config >> "scope") < 2}) exitWith { + TRACE_2("Item does not exist in Config",_unit,_item); + _return }; -if !(isClass (__cfg >> _item)) exitWith { - TRACE_2("Item not exist in Config",_unit,_item); - false + +if (_verify) then { + if (_unit canAdd _item) then { + if (_ammo < 0) then { + _unit addMagazine [_item, 1E6]; // addMagazine STRING is not synched when used on remote units. addMagazine ARRAY is. + } else { + _unit addMagazine [_item, _ammo]; + }; + + _return = true; + } else { + _unit switchMove "ainvpknlmstpslaywrfldnon_1"; + + private _weaponHolder = nearestObject [_unit, "WeaponHolder"]; + + if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then { + _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; + _weaponHolder setPosASL getPosASL _unit; + }; + + [_weaponHolder, _item] call CBA_fnc_addMagazineCargo; + }; +} else { + if (_ammo < 0) then { + _unit addMagazine [_item, 1E6]; // addMagazine STRING is not synched when used on remote units. addMagazine ARRAY is. + } else { + _unit addMagazine [_item, _ammo]; + }; + + _return = true; }; -_unit __action _item; -TRACE_2("Success",_unit,_item); -true + +_return diff --git a/addons/common/fnc_addWeapon.sqf b/addons/common/fnc_addWeapon.sqf index 7baffe2c9..79674eea3 100644 --- a/addons/common/fnc_addWeapon.sqf +++ b/addons/common/fnc_addWeapon.sqf @@ -2,56 +2,92 @@ Function: CBA_fnc_addWeapon Description: - Add a weapon to a unit. + Add a weapon to a unit. Unit has to be local. Function which verifies existence of _item and _unit, returns false in case of trouble, or when able to add _item to _unit true in case of success. Parameters: - _unit - the unit - _item - name of the weapon to add + _unit - the unit + _item - name of the weapon to add + _verify - if true, then put item on the ground if it can't be added Returns: - true on success, false otherwise + true on success, false otherwise Examples: (begin example) - _result = [player, "Binocular"] call CBA_fnc_addWeapon + _result = [player, "Binocular"] call CBA_fnc_addWeapon (end) Author: ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(addWeapon); -#define __scriptname fAddWeapon +#define TYPE_RIFLE 1 +#define TYPE_PISTOL 2 +#define TYPE_LAUNCHER 4 +#define TYPE_BINOCULAR 4096 -#define __cfg (configFile >> "CfgWeapons") -#define __action addWeapon +params [["_unit", objNull, [objNull]], ["_item", "", [""]], ["_verify", false, [false]]]; + +private _return = false; -params ["_unit","_item"]; -if (typeName _unit != "OBJECT") exitWith { - TRACE_2("Unit not Object",_unit,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_unit,_item); - false -}; if (isNull _unit) exitWith { - TRACE_2("Unit isNull",_unit,_item); - false + TRACE_2("Unit not Object or null",_unit,_item); + _return }; -if (_item == "") exitWith { - TRACE_2("Empty Item",_unit,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_unit,_item); + _return }; -if !(isClass (__cfg >> _item)) exitWith { - TRACE_2("Item not exist in Config",_unit,_item); - false + +private _config = configFile >> "CfgWeapons" >> _item; + +if (!isClass _config || {getNumber (_config >> "scope") < 1}) exitWith { + TRACE_2("Item does not exist in Config",_unit,_item); + _return }; -_unit __action _item; -TRACE_2("Success",_unit,_item); -true + +if (_verify) then { + private _canAdd = false; + + switch (getNumber (_config >> "type")) do { + case (TYPE_RIFLE): { + _canAdd = primaryWeapon _unit isEqualTo ""; + }; + case (TYPE_PISTOL): { + _canAdd = handgunWeapon _unit isEqualTo ""; + }; + case (TYPE_LAUNCHER): { + _canAdd = secondaryWeapon _unit isEqualTo ""; + }; + case (TYPE_BINOCULAR): { + _canAdd = binocular _unit isEqualTo ""; + }; + }; + + if (_canAdd) then { + _unit addWeapon _item; + _return = true; + } else { + _unit switchMove "ainvpknlmstpslaywrfldnon_1"; + + private _weaponHolder = nearestObject [_unit, "WeaponHolder"]; + + if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then { + _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; + _weaponHolder setPosASL getPosASL _unit; + }; + + [_weaponHolder, _item] call CBA_fnc_addWeaponCargo; + }; +} else { + _unit addWeapon _item; + _return = true; +}; + +_return diff --git a/addons/common/fnc_removeItem.sqf b/addons/common/fnc_removeItem.sqf new file mode 100644 index 000000000..20b6b249e --- /dev/null +++ b/addons/common/fnc_removeItem.sqf @@ -0,0 +1,55 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_removeItem + +Description: + Remove an item. + + Function which verifies existence of _item and _unit, returns false in case + of trouble, or when able to remove _item from _unit true in case of success. + +Parameters: + _unit - the unit + _item - name of the item to remove + +Returns: + true on success, false otherwise + +Examples: + (begin example) + _result = [player, "FirstAidKit"] call CBA_fnc_removeItem + (end) + +Author: + +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(removeItem); + +params [["_unit", objNull, [objNull]], ["_item", "", [""]]]; + +private _return = false; + +if (isNull _unit) exitWith { + TRACE_2("Unit not Object or null",_unit,_item); + _return +}; + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_unit,_item); + _return +}; + +private _config = _item call CBA_fnc_getItemConfig; + +if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith { + TRACE_2("Item does not exist in Config",_unit,_item); + _return +}; + +if !(configName _config in itemsWithMagazines _unit) exitWith { + TRACE_2("Item not available on Unit",_unit,_item); + _return +}; + +_unit removeItem _item; +true diff --git a/addons/common/fnc_removeMagazine.sqf b/addons/common/fnc_removeMagazine.sqf index dc228a205..0609234a5 100644 --- a/addons/common/fnc_removeMagazine.sqf +++ b/addons/common/fnc_removeMagazine.sqf @@ -8,57 +8,115 @@ Description: of trouble, or when able to remove _item from _unit true in case of success. Parameters: - _unit - the unit or vehicle - _item - name of the magazine to remove + _unit - the unit or vehicle + _item - name of the magazine to remove + _ammo - ammo count. used to remove a specific magazine (optional) Returns: - true on success, false otherwise + true on success, false otherwise Examples: (begin example) - _result = [player, "SmokeShell"] call CBA_fnc_removeMagazine + _result = [player, "SmokeShell"] call CBA_fnc_removeMagazine (end) Author: ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(removeMagazine); -#define __scriptname fRemoveMagazine +params [["_unit", objNull, [objNull]], ["_item", "", [""]], ["_ammo", -1, [0]]]; -#define __cfg (configFile >> "CfgMagazines") -#define __action removeMagazine -#define __ar (magazines _unit) +private _return = false; -private ["_item"]; -params ["_unit"]; -if (typeName _unit != "OBJECT") exitWith { - TRACE_2("Unit not Object",_unit,_item); - false -}; -_item = _this select 1; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_unit,_item); - false -}; if (isNull _unit) exitWith { - TRACE_2("Unit isNull",_unit,_item); - false + TRACE_2("Unit not Object or null",_unit,_item); + _return }; -if (_item == "") exitWith { - TRACE_2("Empty Item",_unit,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_unit,_item); + _return }; -if !(isClass (__cfg >> _item)) exitWith { - TRACE_2("Item not exist in Config",_unit,_item); - false + +private _config = configFile >> "CfgMagazines" >> _item; + +if (!isClass _config || {getNumber (_config >> "scope") < 2}) exitWith { + TRACE_2("Item does not exist in Config",_unit,_item); + _return }; -if !(_item in __ar) exitWith { + +if !(configName _config in magazines _unit) exitWith { TRACE_2("Item not available on Unit",_unit,_item); - false + _return }; -_unit __action _item; -TRACE_2("Success",_unit,_item); -true + +if (_ammo < 0) then { + _unit removeMagazineGlobal _item; // removeMagazine fails on remote units + _return = true; +} else { + private _uniformMagazines = []; + private _vestMagazines = []; + private _backpackMagazines = []; + + private _uniform = uniformContainer _unit; + private _vest = vestContainer _unit; + private _backpack = backpackContainer _unit; + + // magazinesAmmoCargo bugged. returns nil for objNull. + if (!isNull _uniform) then { + _uniformMagazines = magazinesAmmoCargo _uniform select {_x select 0 == _item}; + }; + + if (!isNull _vest) then { + _vestMagazines = magazinesAmmoCargo _vest select {_x select 0 == _item}; + }; + + if (!isNull _backpack) then { + _backpackMagazines = magazinesAmmoCargo _backpack select {_x select 0 == _item}; + }; + + { + if (_x select 1 == _ammo) exitWith { + _uniformMagazines deleteAt _forEachIndex; + _return = true; + }; + } forEach _uniformMagazines; + + if !(_return) then { + { + if (_x select 1 == _ammo) exitWith { + _vestMagazines deleteAt _forEachIndex; + _return = true; + }; + } forEach _vestMagazines; + }; + + if !(_return) then { + { + if (_x select 1 == _ammo) exitWith { + _backpackMagazines deleteAt _forEachIndex; + _return = true; + }; + } forEach _backpackMagazines; + }; + + if (_return) then { + _unit removeMagazines _item; // doc wrong. works on remote units + + { + _uniform addMagazineAmmoCargo [_item, 1, _x select 1]; + } forEach _uniformMagazines; + + { + _vest addMagazineAmmoCargo [_item, 1, _x select 1]; + } forEach _vestMagazines; + + { + _backpack addMagazineAmmoCargo [_item, 1, _x select 1]; + } forEach _backpackMagazines; + }; +}; + +_return diff --git a/addons/common/fnc_removeWeapon.sqf b/addons/common/fnc_removeWeapon.sqf index 79559446a..352cac92b 100644 --- a/addons/common/fnc_removeWeapon.sqf +++ b/addons/common/fnc_removeWeapon.sqf @@ -8,57 +8,48 @@ Description: of trouble, or when able to remove _item from _unit true in case of success. Parameters: - _unit - the unit - _item - name of the weapon to remove + _unit - the unit + _item - name of the weapon to remove Returns: - true on success, false otherwise + true on success, false otherwise Examples: (begin example) - _result = [player, "Binocular"] call CBA_fnc_removeWeapon + _result = [player, "Binocular"] call CBA_fnc_removeWeapon (end) Author: ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(removeWeapon); -#define __scriptname fRemoveWeapon +params [["_unit", objNull, [objNull]], ["_item", "", [""]]]; -#define __cfg (configFile >> "CfgWeapons") -#define __action removeWeapon -#define __ar (weapons _unit) +private _return = false; -private ["_item"]; -params ["_unit"]; -if (typeName _unit != "OBJECT") exitWith { - TRACE_2("Unit not Object",_unit,_item); - false -}; -_item = _this select 1; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_unit,_item); - false -}; if (isNull _unit) exitWith { - TRACE_2("Unit isNull",_unit,_item); - false + TRACE_2("Unit not Object or null",_unit,_item); + _return }; -if (_item == "") exitWith { - TRACE_2("Empty Item",_unit,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_unit,_item); + _return }; -if !(isClass (__cfg >> _item)) exitWith { - TRACE_2("Item not exist in Config",_unit,_item); - false + +private _config = configFile >> "CfgWeapons" >> _item; + +if (!isClass _config || {getNumber (_config >> "scope") < 1}) exitWith { + TRACE_2("Item does not exist in Config",_unit,_item); + _return }; -if !(_item in __ar) exitWith { + +if !(configName _config in weapons _unit) exitWith { TRACE_2("Item not available on Unit",_unit,_item); - false + _return }; -_unit __action _item; -TRACE_2("Success",_unit,_item); + +_unit removeWeaponGlobal _item; // removeWeapon fails on remote units true diff --git a/addons/common/test_inventory.sqf b/addons/common/test_inventory.sqf new file mode 100644 index 000000000..0a8aabc50 --- /dev/null +++ b/addons/common/test_inventory.sqf @@ -0,0 +1,74 @@ +#include "script_component.hpp" +SCRIPT(test_config); + +// 0 spawn compile preprocessFileLineNumbers "\x\cba\addons\common\inventory\test_inventory.sqf"; + +// Note: test requires a player with space in inventory + +private ["_funcName", "_result"]; + +_funcName = "CBA_fnc_addWeapon"; +LOG("Testing " + _funcName); + +TEST_DEFINED("CBA_fnc_addWeapon",""); + +_result = [objNull, "Binocular"] call CBA_fnc_addWeapon; +TEST_FALSE(_result,_funcName); + +_result = [player, ""] call CBA_fnc_addWeapon; +TEST_FALSE(_result,_funcName); + +_result = [player, "Binocular"] call CBA_fnc_addWeapon; +TEST_TRUE(_result,_funcName); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +_funcName = "CBA_fnc_removeWeapon"; +LOG("Testing " + _funcName); + +_result = [objNull, "Binocular"] call CBA_fnc_removeWeapon; +TEST_FALSE(_result,_funcName); + +_result = [player, ""] call CBA_fnc_removeWeapon; +TEST_FALSE(_result,_funcName); + +_result = [player, "Binocular"] call CBA_fnc_removeWeapon; +TEST_TRUE(_result,_funcName); + +_result = [player, "Binocular"] call CBA_fnc_removeWeapon; +TEST_FALSE(_result,_funcName); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +_funcName = "CBA_fnc_addMagazine"; +LOG("Testing " + _funcName); + +TEST_DEFINED("CBA_fnc_addMagazine",""); + +_result = [objNull, "SmokeShell"] call CBA_fnc_addMagazine; +TEST_FALSE(_result,_funcName); + +_result = [player, ""] call CBA_fnc_addMagazine; +TEST_FALSE(_result,_funcName); + +_result = [player, "SmokeShell"] call CBA_fnc_addMagazine; +TEST_TRUE(_result,_funcName); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +_funcName = "CBA_fnc_removeMagazine"; +LOG("Testing " + _funcName); + +_result = [objNull, "SmokeShell"] call CBA_fnc_removeMagazine; +TEST_FALSE(_result,_funcName); + +_result = [player, ""] call CBA_fnc_removeMagazine; +TEST_FALSE(_result,_funcName); + +_result = [player, "SmokeShell"] call CBA_fnc_removeMagazine; +TEST_TRUE(_result,_funcName); + +player removeMagazines "SmokeShell"; + +_result = [player, "SmokeShell"] call CBA_fnc_removeMagazine; +TEST_FALSE(_result,_funcName); From 02133daa14d57725f2054715e7bd714f825797ce Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:01:44 +0100 Subject: [PATCH 03/18] rewrite and add common config functions --- addons/common/fnc_getItemConfig.sqf | 38 ++++++ addons/common/fnc_getMuzzles.sqf | 35 ++++++ addons/common/fnc_getObjectConfig.sqf | 42 +++++++ addons/common/fnc_getTurret.sqf | 50 ++++---- addons/common/fnc_getWeaponModes.sqf | 42 +++++++ addons/common/fnc_inheritsFrom.sqf | 15 +-- addons/common/test_config.sqf | 165 ++++++++++++++++++++++++++ addons/common/test_inheritsFrom.sqf | 55 --------- 8 files changed, 353 insertions(+), 89 deletions(-) create mode 100644 addons/common/fnc_getItemConfig.sqf create mode 100644 addons/common/fnc_getMuzzles.sqf create mode 100644 addons/common/fnc_getObjectConfig.sqf create mode 100644 addons/common/fnc_getWeaponModes.sqf create mode 100644 addons/common/test_config.sqf delete mode 100644 addons/common/test_inheritsFrom.sqf diff --git a/addons/common/fnc_getItemConfig.sqf b/addons/common/fnc_getItemConfig.sqf new file mode 100644 index 000000000..582835035 --- /dev/null +++ b/addons/common/fnc_getItemConfig.sqf @@ -0,0 +1,38 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getItemConfig + +Description: + A function used to return the config of an item. + +Parameters: + _weapon - Any kind of item, weapon or magazine class name + +Returns: + _config - Item config. + +Example: + (begin example) + _config = currentWeapon player call CBA_fnc_getItemConfig; + (currentMagazine cameraOn) call CBA_fnc_getItemConfig; + (goggles player) call CBA_fnc_getItemConfig; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getItemConfig); + +params [["_weapon", "", [""]]]; + +private _result = configNull; + +{ + private _config = configFile >> _x >> _weapon; + + if (isClass _config) exitWith { + _result = _config; + }; +} forEach ["CfgWeapons", "CfgMagazines", "CfgGlasses"]; + +_result diff --git a/addons/common/fnc_getMuzzles.sqf b/addons/common/fnc_getMuzzles.sqf new file mode 100644 index 000000000..3490e3328 --- /dev/null +++ b/addons/common/fnc_getMuzzles.sqf @@ -0,0 +1,35 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getMuzzles + +Description: + Gets the list of possible muzzles for a weapon. + +Parameters: + _weapon - class name of the weapon to examine + +Returns: + _muzzles - All muzzle names + +Examples: + (begin example) + _muzzles = "M4A1_RCO_GL" call CBA_fnc_determineMuzzles + -> ["M4_ACOG_Muzzle", "M203Muzzle"] + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getMuzzles); + +params [["_weapon", "", [""]]]; + +private _muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles"); + +{ + if (_x == "this") then { + _muzzles set [_forEachIndex, _weapon]; + }; +} forEach _muzzles; + +_muzzles diff --git a/addons/common/fnc_getObjectConfig.sqf b/addons/common/fnc_getObjectConfig.sqf new file mode 100644 index 000000000..d4bb07b47 --- /dev/null +++ b/addons/common/fnc_getObjectConfig.sqf @@ -0,0 +1,42 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getObjectConfig + +Description: + A function used to return the config of an object or class name. + +Parameters: + _object - Any kind of object or class name + +Returns: + _config - Objects config. + +Example: + (begin example) + _config = player call CBA_fnc_getObjectConfig; + typeOf cameraOn call CBA_fnc_getObjectConfig; + [_projectile] call CBA_fnc_getObjectConfig; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getObjectConfig); + +params [["_object", "", ["", objNull]]]; + +if (_object isEqualType objNull) then { + _object = typeOf _object; +}; + +private _result = configNull; + +{ + private _config = configFile >> _x >> _object; + + if (isClass _config) exitWith { + _result = _config; + }; +} forEach ["CfgVehicles", "CfgAmmo", "CfgNonAIVehicles"]; + +_result diff --git a/addons/common/fnc_getTurret.sqf b/addons/common/fnc_getTurret.sqf index b58ac547e..9d961d469 100644 --- a/addons/common/fnc_getTurret.sqf +++ b/addons/common/fnc_getTurret.sqf @@ -5,8 +5,8 @@ Description: A function used to find out which config turret is turretpath. Parameters: - Vehicle - Turretpath + _vehicle - Vehicle or vehicle class name + _turretPath - Turret path Example: (begin example) @@ -17,33 +17,29 @@ Returns: Turret Config entry Author: - Sickboy - + Sickboy, commy2 ---------------------------------------------------------------------------- */ - -// #define DEBUG_MODE_FULL #include "script_component.hpp" +SCRIPT(getTurret); -#define __cfg (configFile >> "CfgVehicles" >> (typeof _v)) -private ["_path"]; -params ["_v","_tp"]; -_path = __cfg; - -if (count _tp > 0) then { - { - // First filter non classes - _turrets = (_path >> "turrets"); - _turs = []; - for "_i" from 0 to (count _turrets) - 1 do { - _y = _turrets select _i; - if (isClass(_y)) then { _turs pushBack _y; }; - }; - if ((count _turs)-1 >= _x) then { - _path = (_turs select _x); - }; - - } forEach _tp; +params [["_vehicle", "", ["", objNull]], ["_turretPath", [], [[]]]]; + +if (_vehicle isEqualType objNull) then { + _vehicle = typeOf _vehicle; }; -TRACE_1("Result",_path); -_path; +private _config = configFile >> "CfgVehicles" >> _vehicle; + +// this is used by BI to indicate "driver turrets" +if (_turretPath isEqualTo [-1]) exitWith {_config}; + +{ + if (_x < 0) exitWith { + _config = configNull; + }; + + // config classes ignores inherited classes, just like the engine does with turrets + _config = ("true" configClasses (_config >> "turrets")) param [_x, configNull]; +} forEach _turretPath; + +_config diff --git a/addons/common/fnc_getWeaponModes.sqf b/addons/common/fnc_getWeaponModes.sqf new file mode 100644 index 000000000..965583651 --- /dev/null +++ b/addons/common/fnc_getWeaponModes.sqf @@ -0,0 +1,42 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getWeaponModes + +Description: + Gets the list of possible modes for a weapon. + +Parameters: + _weapon - class name of the weapon to examine + _includeHidden - true - report AI only modes, false - report player modes (default: false) + +Returns: + _modes - All weapon mode names + +Examples: + (begin example) + _modes = "M4A1_RCO_GL" call CBA_fnc_getWeaponModes + -> ["M4_ACOG_Muzzle", "M203Muzzle"] + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getWeaponModes); + +params [["_weapon", "", [""]], ["_includeHidden", false, [false]]]; + +private _config = configFile >> "CfgWeapons" >> _weapon; + +private _modes = []; + +{ + if (_includeHidden || {getNumber (_config >> _x >> "showToPlayer") == 1}) then { + if (_x == "this") then { + _modes pushBack _weapon; + } else { + _modes pushBack _x; + }; + }; +} forEach getArray (_config >> "modes"); + +_modes diff --git a/addons/common/fnc_inheritsFrom.sqf b/addons/common/fnc_inheritsFrom.sqf index 68ccb7ef6..db16942bb 100644 --- a/addons/common/fnc_inheritsFrom.sqf +++ b/addons/common/fnc_inheritsFrom.sqf @@ -25,18 +25,19 @@ Examples: Author: Sickboy ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(inheritsFrom); -params ["_config","_baseConfig"]; +params [["_config", configNull, [configNull]], ["_baseConfig", configNull, [configNull]]]; -private "_valid"; -_valid = false; +private _valid = false; -while { (configName _config) != "" } do { +while {configName _config != ""} do { _config = inheritsFrom _config; - if (_config == _baseConfig) exitWith { _valid = true }; + + if (_config == _baseConfig) exitWith { + _valid = true; + }; }; -_valid; +_valid diff --git a/addons/common/test_config.sqf b/addons/common/test_config.sqf new file mode 100644 index 000000000..3e11adad2 --- /dev/null +++ b/addons/common/test_config.sqf @@ -0,0 +1,165 @@ +#include "script_component.hpp" +SCRIPT(test_config); + +// 0 spawn compile preprocessFileLineNumbers "\x\cba\addons\common\config\test_config.sqf"; + +private ["_funcName", "_result"]; + +_funcName = "CBA_fnc_inheritsFrom"; +LOG("Testing " + _funcName); + +TEST_DEFINED("CBA_fnc_inheritsFrom",""); + +private ["_class", "_base"]; + +_class = configFile >> "CfgWeapons" >> "arifle_MXC_F"; +_base = configFile >> "CfgWeapons" >> "RifleCore"; +_result = [_class, _base] call CBA_fnc_inheritsFrom; +TEST_TRUE(_result,_funcName); + +_class = configFile >> "CfgWeapons" >> "RifleCore"; +_base = configFile >> "CfgWeapons" >> "arifle_MXC_F"; +_result = [_class, _base] call CBA_fnc_inheritsFrom; +TEST_FALSE(_result,_funcName); + +_class = configFile >> "CfgWeapons" >> "arifle_MXC_F"; +_base = configFile >> "CfgWeapons" >> "PistolCore"; +_result = [_class, _base] call CBA_fnc_inheritsFrom; +TEST_FALSE(_result,_funcName); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +_funcName = "CBA_fnc_getMuzzles"; +LOG("Testing " + _funcName); + +TEST_DEFINED("CBA_fnc_getMuzzles",""); + +_result = "" call CBA_fnc_getMuzzles; +TEST_TRUE(_result isEqualTo [],_funcName); + +_result = "arifle_MX_F" call CBA_fnc_getMuzzles; +TEST_TRUE(_result isEqualTo ["arifle_MX_F"],_funcName); + +_result = "arifle_MX_GL_F" call CBA_fnc_getMuzzles; +TEST_TRUE(_result isEqualTo [ARR_2("arifle_MX_GL_F","GL_3GL_F")],_funcName); + +_result = "FirstAidKit" call CBA_fnc_getMuzzles; +TEST_TRUE(_result isEqualTo [],_funcName); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +_funcName = "CBA_fnc_getWeaponModes"; +LOG("Testing " + _funcName); + +TEST_DEFINED("CBA_fnc_getWeaponModes",""); + +_result = "" call CBA_fnc_getWeaponModes; +TEST_TRUE(_result isEqualTo [],_funcName); + +_result = "arifle_MX_F" call CBA_fnc_getWeaponModes; +TEST_TRUE(_result isEqualTo [ARR_2("Single","FullAuto")],_funcName); + +_result = ["arifle_MX_GL_F"] call CBA_fnc_getWeaponModes; +TEST_TRUE(_result isEqualTo [ARR_2("Single","FullAuto")],_funcName); + +_result = ["arifle_MX_F", true] call CBA_fnc_getWeaponModes; +TEST_TRUE(_result isEqualTo [ARR_5("Single","FullAuto","fullauto_medium","single_medium_optics1","single_far_optics2")],_funcName); + +_result = ["FirstAidKit", true] call CBA_fnc_getWeaponModes; +TEST_TRUE(_result isEqualTo ["FirstAidKit"],_funcName); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +_funcName = "CBA_fnc_getItemConfig"; +LOG("Testing " + _funcName); + +TEST_DEFINED("CBA_fnc_getItemConfig",""); + +_result = "" call CBA_fnc_getItemConfig; +TEST_TRUE(isNull _result,_funcName); + +_result = "arifle_MX_F" call CBA_fnc_getItemConfig; +TEST_TRUE(_result isEqualTo (configFile >> "CfgWeapons" >> "arifle_MX_F"),_funcName); + +_result = ["arifle_MX_GL_F"] call CBA_fnc_getItemConfig; +TEST_TRUE(_result isEqualTo (configFile >> "CfgWeapons" >> "arifle_MX_GL_F"),_funcName); + +_result = "FirstAidKit" call CBA_fnc_getItemConfig; +TEST_TRUE(_result isEqualTo (configFile >> "CfgWeapons" >> "FirstAidKit"),_funcName); + +_result = "30Rnd_65x39_caseless_mag" call CBA_fnc_getItemConfig; +TEST_TRUE(_result isEqualTo (configFile >> "CfgMagazines" >> "30Rnd_65x39_caseless_mag"),_funcName); + +_result = "G_Shades_Black" call CBA_fnc_getItemConfig; +TEST_TRUE(_result isEqualTo (configFile >> "CfgGlasses" >> "G_Shades_Black"),_funcName); + +_result = "B_Soldier_F" call CBA_fnc_getItemConfig; +TEST_TRUE(isNull _result,_funcName); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +_funcName = "CBA_fnc_getObjectConfig"; +LOG("Testing " + _funcName); + +TEST_DEFINED("CBA_fnc_getObjectConfig",""); + +_result = "" call CBA_fnc_getObjectConfig; +TEST_TRUE(isNull _result,_funcName); + +_result = [objNull] call CBA_fnc_getObjectConfig; +TEST_TRUE(isNull _result,_funcName); + +_result = "B_Soldier_F" call CBA_fnc_getObjectConfig; +TEST_TRUE(_result isEqualTo (configFile >> "CfgVehicles" >> "B_Soldier_F"),_funcName); + +_result = (typeOf player) call CBA_fnc_getObjectConfig; +TEST_TRUE(isNull player || !isNull _result,_funcName); + +_result = "EmptyDetector" call CBA_fnc_getObjectConfig; +TEST_TRUE(_result isEqualTo (configFile >> "CfgNonAIVehicles" >> "EmptyDetector"),_funcName); + +_result = ["B_65x39_Caseless"] call CBA_fnc_getObjectConfig; +TEST_TRUE(_result isEqualTo (configFile >> "CfgAmmo" >> "B_65x39_Caseless"),_funcName); + +_result = "FirstAidKit" call CBA_fnc_getObjectConfig; +TEST_TRUE(isNull _result,_funcName); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +_funcName = "CBA_fnc_getTurret"; +LOG("Testing " + _funcName); + +TEST_DEFINED("CBA_fnc_getTurret",""); + +_result = "" call CBA_fnc_getTurret; +TEST_TRUE(isNull _result,_funcName); + +_result = [objNull] call CBA_fnc_getTurret; +TEST_TRUE(isNull _result,_funcName); + +_result = "B_MBT_01_TUSK_F" call CBA_fnc_getTurret; +TEST_TRUE(_result isEqualTo (configFile >> "CfgVehicles" >> "B_MBT_01_TUSK_F"),_funcName); + +_result = ["B_MBT_01_TUSK_F", [-1]] call CBA_fnc_getTurret; +TEST_TRUE(_result isEqualTo (configFile >> "CfgVehicles" >> "B_MBT_01_TUSK_F"),_funcName); + +_result = ["B_MBT_01_TUSK_F", []] call CBA_fnc_getTurret; +TEST_TRUE(_result isEqualTo (configFile >> "CfgVehicles" >> "B_MBT_01_TUSK_F"),_funcName); + +_result = ["B_MBT_01_TUSK_F", [0]] call CBA_fnc_getTurret; +TEST_TRUE(_result isEqualTo (configFile >> "CfgVehicles" >> "B_MBT_01_TUSK_F" >> "Turrets" >> "MainTurret"),_funcName); + +_result = ["B_MBT_01_TUSK_F", [0,0]] call CBA_fnc_getTurret; +TEST_TRUE(_result isEqualTo (configFile >> "CfgVehicles" >> "B_MBT_01_TUSK_F" >> "Turrets" >> "MainTurret" >> "Turrets" >> "CommanderOptics"),_funcName); + +_result = ["B_MBT_01_TUSK_F", [0,0,0]] call CBA_fnc_getTurret; +TEST_TRUE(isNull _result,_funcName); + +_result = ["B_MBT_01_TUSK_F", [0,1]] call CBA_fnc_getTurret; +TEST_TRUE(isNull _result,_funcName); + +_result = {isNull _x} count ([[0],[1],[2],[3],[4]] apply {["B_Heli_Transport_03_F", _x] call CBA_fnc_getTurret}); +TEST_TRUE(_result == 0,_funcName); + +_result = {!isNull _x} count ([[0],[1],[2],[3],[4]] apply {["B_Heli_Transport_03_F", _x] call CBA_fnc_getTurret}); +TEST_TRUE(_result == 5,_funcName); diff --git a/addons/common/test_inheritsFrom.sqf b/addons/common/test_inheritsFrom.sqf deleted file mode 100644 index 39749bdef..000000000 --- a/addons/common/test_inheritsFrom.sqf +++ /dev/null @@ -1,55 +0,0 @@ -// ---------------------------------------------------------------------------- - -#include "script_component.hpp" - -SCRIPT(test_inheritsFrom); - -// ---------------------------------------------------------------------------- - -private ["_class", "_base", "_expected", "_result", "_fn", "_game", "_clssname"]; - -_fn = "CBA_fnc_inheritsFrom"; -LOG("Testing " + _fn); - -TEST_DEFINED("CBA_fnc_inheritsFrom",""); - -/* -Game as integer from SLX_XEH_MACHINE -0 = Arma2 -1 = Arma2 OA -2 = TOH -3 = Arma3 -*/ -_game = SLX_XEH_MACHINE select 15; - -if (_game > 3) then { - LOG ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All TEST tests will fail! " + _fn); //Sanity check and reminder - Diag_log ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All TEST tests will fail! " + _fn); -}; - -if (_game < 2) then { - _clssname = "m16a4_acg_gl"; //Arma2 variants - } else { - if (_game == 2) then { - _clssname = "M4A1_H"; //TOH - } else { - _clssname = "arifle_MXC_F"; //Arma3 - }; -}; - -_class = configFile >> "CfgWeapons" >> _clssname; -_base = configFile >> "CfgWeapons" >> "RifleCore"; -_result = [_class, _base] call CBA_fnc_inheritsFrom; -TEST_TRUE(_result,_fn); - -_class = configFile >> "CfgWeapons" >> "RifleCore"; -_base = configFile >> "CfgWeapons" >> _clssname; -_result = [_class, _base] call CBA_fnc_inheritsFrom; -TEST_FALSE(_result,_fn); - -_class = configFile >> "CfgWeapons" >> _clssname; -_base = configFile >> "CfgWeapons" >> "PistolCore"; -_result = [_class, _base] call CBA_fnc_inheritsFrom; -TEST_FALSE(_result,_fn); - -nil; From a83e10d0947fe0c9d8873592cbd1ae853ca7d5ab Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:06:17 +0100 Subject: [PATCH 04/18] rewrite and unify common cargo functions --- addons/common/fnc_addBackpackCargo.sqf | 79 ++++++++++++++++ addons/common/fnc_addItemCargo.sqf | 79 ++++++++++++++++ addons/common/fnc_addMagazineCargo.sqf | 90 ++++++++++-------- addons/common/fnc_addMagazineCargoGlobal.sqf | 69 -------------- addons/common/fnc_addWeaponCargo.sqf | 91 ++++++++++-------- addons/common/fnc_addWeaponCargoGlobal.sqf | 67 ------------- addons/common/fnc_removeBackpackCargo.sqf | 65 ++++++------- .../common/fnc_removeBackpackCargoGlobal.sqf | 92 ------------------ addons/common/fnc_removeItemCargo.sqf | 66 +++++++------ addons/common/fnc_removeItemCargoGlobal.sqf | 91 ------------------ addons/common/fnc_removeMagazineCargo.sqf | 68 +++++++------- .../common/fnc_removeMagazineCargoGlobal.sqf | 93 ------------------- addons/common/fnc_removeWeaponCargo.sqf | 69 +++++++------- addons/common/fnc_removeWeaponCargoGlobal.sqf | 93 ------------------- 14 files changed, 383 insertions(+), 729 deletions(-) create mode 100644 addons/common/fnc_addBackpackCargo.sqf create mode 100644 addons/common/fnc_addItemCargo.sqf delete mode 100644 addons/common/fnc_addMagazineCargoGlobal.sqf delete mode 100644 addons/common/fnc_addWeaponCargoGlobal.sqf delete mode 100644 addons/common/fnc_removeBackpackCargoGlobal.sqf delete mode 100644 addons/common/fnc_removeItemCargoGlobal.sqf delete mode 100644 addons/common/fnc_removeMagazineCargoGlobal.sqf delete mode 100644 addons/common/fnc_removeWeaponCargoGlobal.sqf diff --git a/addons/common/fnc_addBackpackCargo.sqf b/addons/common/fnc_addBackpackCargo.sqf new file mode 100644 index 000000000..753c68535 --- /dev/null +++ b/addons/common/fnc_addBackpackCargo.sqf @@ -0,0 +1,79 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addBackpackCargo + +Description: + Add backpack(s) to vehicle cargo. + + Function which verifies existence of _item and _container, returns false in case + of trouble, or when able to add _item to _container true in case of success. + +Parameters: + _container - the vehicle + _item - name of backpack + _count - number of weapons to add (Default: 1) + _verify - if true, then put item on the ground if it can't be added + +Returns: + true on success, false otherwise + +Examples: + (begin example) + // Add one laser designator to the cargo of SomeTruck + _result = [SomeTruck, "B_Kitbag_cbr"] call CBA_fnc_addBackpackCargo + + // Add two MXC rifles to MyAPC. If the inventory is full, then put the rest on the ground + _result = [MyAPC, "B_Kitbag_cbr", 2, true] call CBA_fnc_addBackpackCargo + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(addBackpackCargo); + +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]], ["_verify", false, [false]]]; + +private _return = false; + +if (isNull _container) exitWith { + TRACE_2("Container not Object or null",_container,_item); + _return +}; + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_container,_item); + _return +}; + +private _config = _item call CBA_fnc_getObjectConfig; + +if (isNull _config || {getNumber (_config >> "scope") < 1} || {getNumber (_config >> "isBackpack") != 1}) exitWith { + TRACE_2("Item not exist in Config",_container,_item); + _return +}; + +if (_verify) then { + if (_container canAdd [_item, _count]) then { + _container addBackpackCargoGlobal [_item, _count]; + _return = true; + } else { + while {_container canAdd _item && {_count > 0}} do { + _container addBackpackCargoGlobal [_item, 1]; + _count = _count - 1; + }; + + private _weaponHolder = nearestObject [_container, "WeaponHolder"]; + + if (isNull _weaponHolder || {_container distance _weaponHolder > 2}) then { + _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; + _weaponHolder setPosATL (getPosATL _container vectorAdd [random 2 - 1, random 2 - 1, 0]); + }; + + _weaponHolder addBackpackCargoGlobal [_item, _count]; + }; +} else { + _container addBackpackCargoGlobal [_item, _count]; + _return = true; +}; + +_return diff --git a/addons/common/fnc_addItemCargo.sqf b/addons/common/fnc_addItemCargo.sqf new file mode 100644 index 000000000..0bbefdb7e --- /dev/null +++ b/addons/common/fnc_addItemCargo.sqf @@ -0,0 +1,79 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addItemCargo + +Description: + Add item(s) to vehicle cargo. + + Function which verifies existence of _item and _container, returns false in case + of trouble, or when able to add _item to _container true in case of success. + +Parameters: + _container - the vehicle + _item - name of item + _count - number of weapons to add (Default: 1) + _verify - if true, then put item on the ground if it can't be added + +Returns: + true on success, false otherwise + +Examples: + (begin example) + // Add one laser designator to the cargo of SomeTruck + _result = [SomeTruck, "FirstAidKit"] call CBA_fnc_addItemCargo + + // Add two MXC rifles to MyAPC. If the inventory is full, then put the rest on the ground + _result = [MyAPC, "LaserDesignator", 2, true] call CBA_fnc_addItemCargo + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(addItemCargo); + +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]], ["_verify", false, [false]]]; + +private _return = false; + +if (isNull _container) exitWith { + TRACE_2("Container not Object or null",_container,_item); + _return +}; + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_container,_item); + _return +}; + +private _config = _item call CBA_fnc_getItemConfig; + +if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith { + TRACE_2("Item not exist in Config",_container,_item); + _return +}; + +if (_verify) then { + if (_container canAdd [_item, _count]) then { + _container addItemCargoGlobal [_item, _count]; + _return = true; + } else { + while {_container canAdd _item && {_count > 0}} do { + _container addItemCargoGlobal [_item, 1]; + _count = _count - 1; + }; + + private _weaponHolder = nearestObject [_container, "WeaponHolder"]; + + if (isNull _weaponHolder || {_container distance _weaponHolder > 2}) then { + _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; + _weaponHolder setPosATL (getPosATL _container vectorAdd [random 2 - 1, random 2 - 1, 0]); + }; + + _weaponHolder addItemCargoGlobal [_item, _count]; + }; +} else { + _container addItemCargoGlobal [_item, _count]; + _return = true; +}; + +_return diff --git a/addons/common/fnc_addMagazineCargo.sqf b/addons/common/fnc_addMagazineCargo.sqf index f7a867583..659e675c0 100644 --- a/addons/common/fnc_addMagazineCargo.sqf +++ b/addons/common/fnc_addMagazineCargo.sqf @@ -4,64 +4,76 @@ Function: CBA_fnc_addMagazineCargo Description: Add magazine(s) to a vehicle's cargo. - Function which verifies existence of _item and _unit, returns false in case - of trouble, or when able to add _item to _unit true in case of success. + Function which verifies existence of _item and _container, returns false in case + of trouble, or when able to add _item to _container true in case of success. Parameters: - _unit - the vehicle [Object] - _item - name of magazine to [String] - _count - number of magazines to add [Number] (Default: 1) + _container - the vehicle + _item - name of magazine to + _count - number of magazines to add (Default: 1) + _verify - if true, then put item on the ground if it can't be added Returns: - true on success, false otherwise + true on success, false otherwise Examples: (begin example) - // Add one mine to the cargo of SomeTruck - _result = [ SomeTruck, "Mine"] call CBA_fnc_AddMagazineCargo + // Add one mine to the cargo of SomeTruck + _result = [SomeTruck, "ATMine"] call CBA_fnc_addMagazineCargo - // Add three smoke cans to MyCar - _result = [ MyCar, "SmokeShell", 3] call CBA_fnc_AddMagazineCargo + // Add three smoke cans to MyCar. If the inventory is full, then put the rest on the ground + _result = [MyCar, "SmokeShell", 3, true] call CBA_fnc_addMagazineCargo (end) Author: ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(addMagazineCargo); -#define __scriptname fnc_addMagazineCargo +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]], ["_verify", false, [false]]]; -#define __cfg (configFile >> "CfgMagazines") -#define __action addMagazineCargo +private _return = false; -params ["_unit","_item", ["_count",1]]; -if (typeName _unit != "OBJECT") exitWith { - TRACE_2("Unit not Object",_unit,_item); - false -}; -//_item = _this select 1; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_unit,_item); - false -}; -if (isNull _unit) exitWith { - TRACE_2("Unit isNull",_unit,_item); - false +if (isNull _container) exitWith { + TRACE_2("Container not Object or null",_container,_item); + _return }; -if (_item == "") exitWith { - TRACE_2("Empty Item",_unit,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_container,_item); + _return }; -if !(isClass (__cfg >> _item)) exitWith { - TRACE_2("Item not exist in Config",_unit,_item); - false + +private _config = configFile >> "CfgMagazines" >> _item; + +if (isNull _config || {getNumber (_config >> "scope") < 2}) exitWith { + TRACE_2("Item not exist in Config",_container,_item); + _return }; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_unit,_item,_count); - false + +if (_verify) then { + if (_container canAdd [_item, _count]) then { + _container addMagazineCargoGlobal [_item, _count]; + _return = true; + } else { + while {_container canAdd _item && {_count > 0}} do { + _container addMagazineCargoGlobal [_item, 1]; + _count = _count - 1; + }; + + private _weaponHolder = nearestObject [_container, "WeaponHolder"]; + + if (isNull _weaponHolder || {_container distance _weaponHolder > 2}) then { + _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; + _weaponHolder setPosATL (getPosATL _container vectorAdd [random 2 - 1, random 2 - 1, 0]); + }; + + _weaponHolder addMagazineCargoGlobal [_item, _count]; + }; +} else { + _container addMagazineCargoGlobal [_item, _count]; + _return = true; }; -_unit __action [_item, _count]; -TRACE_3("Success",_unit,_item,_count); -true + +_return diff --git a/addons/common/fnc_addMagazineCargoGlobal.sqf b/addons/common/fnc_addMagazineCargoGlobal.sqf deleted file mode 100644 index 4ceceab93..000000000 --- a/addons/common/fnc_addMagazineCargoGlobal.sqf +++ /dev/null @@ -1,69 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_addMagazineCargoGlobal - -Description: - Add magazine(s) to a vehicle's cargo. MP synchronized. - - Function which verifies existence of _item and _unit, returns false in case - of trouble, or when able to add _item to _unit true in case of success. - -Parameters: - _unit - the vehicle [Object] - _item - name of magazine to [String] - _count - number of magazines to add [Number] (Default: 1) - -Returns: - true on success, false otherwise - -Examples: - (begin example) - // Add one mine to the cargo of SomeTruck - _result = [ SomeTruck, "Mine"] call CBA_fnc_AddMagazineCargoGlobal - - // Add three smoke cans to MyCar - _result = [ MyCar, "SmokeShell", 3] call CBA_fnc_AddMagazineCargoGlobal - (end) - -Author: - Sickboy (addMagazineCargo) ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" -SCRIPT(addMagazineCargoGlobal); - -params ["_unit","_item", ["_count",1]]; - -if (typeName _unit != "OBJECT") exitWith -{ - TRACE_2("Unit not Object",_unit,_item); - false -}; -//_item = _this select 1; -if (typeName _item != "STRING") exitWith -{ - TRACE_2("Item not String",_unit,_item); - false -}; -if (isNull _unit) exitWith -{ - TRACE_2("Unit isNull",_unit,_item); - false -}; -if (_item == "") exitWith -{ - TRACE_2("Empty Item",_unit,_item); - false -}; -if !(isClass (configFile >> "CfgMagazines" >> _item)) exitWith -{ - TRACE_2("Item does not exist in the game config",_unit,_item); - false -}; -if (typeName _count != "SCALAR") exitWith -{ - TRACE_3("Count is not a number",_unit,_item,_count); - false -}; -_unit addMagazineCargoGlobal [_item, _count]; -TRACE_3("Success",_unit,_item,_count); -true diff --git a/addons/common/fnc_addWeaponCargo.sqf b/addons/common/fnc_addWeaponCargo.sqf index ea958330d..2fc93f524 100644 --- a/addons/common/fnc_addWeaponCargo.sqf +++ b/addons/common/fnc_addWeaponCargo.sqf @@ -4,65 +4,76 @@ Function: CBA_fnc_addWeaponCargo Description: Add weapon(s) to vehicle cargo. - Function which verifies existence of _item and _unit, returns false in case - of trouble, or when able to add _item to _unit true in case of success. + Function which verifies existence of _item and _container, returns false in case + of trouble, or when able to add _item to _container true in case of success. Parameters: - _unit - the vehicle [Object] - _item - name of weapon [String] - _count - number of weapons to add [Number] (Default: 1) + _container - the vehicle + _item - name of weapon + _count - number of weapons to add (Default: 1) + _verify - if true, then put item on the ground if it can't be added Returns: - true on success, false otherwise + true on success, false otherwise Examples: (begin example) - // Add one laser designator to the cargo of SomeTruck - _result = [SomeTruck, "LaserDesignator"] call CBA_fnc_addWeaponCargo + // Add one laser designator to the cargo of SomeTruck + _result = [SomeTruck, "LaserDesignator"] call CBA_fnc_addWeaponCargo - // Add two AK 107 rifles to MyUAZ - _result = [MyUAZ, "AK_107_KOBRA", 2] call CBA_fnc_addWeaponCargo + // Add two MXC rifles to MyAPC. If the inventory is full, then put the rest on the ground + _result = [MyAPC, "arifle_MXC_F", 2, true] call CBA_fnc_addWeaponCargo (end) Author: Sickboy - ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(addWeaponCargo); -#define __scriptname fAddWeaponCargo +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]], ["_verify", false, [false]]]; -#define __cfg (configFile >> "CfgWeapons") -#define __action addWeaponCargo +private _return = false; -params ["_unit","_item", ["_count",1]]; -if (typeName _unit != "OBJECT") exitWith { - TRACE_2("Unit not Object",_unit,_item); - false -}; -_item = _this select 1; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_unit,_item); - false +if (isNull _container) exitWith { + TRACE_2("Container not Object or null",_container,_item); + _return }; -if (isNull _unit) exitWith { - TRACE_2("Unit isNull",_unit,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_unit,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_container,_item); + _return }; -if !(isClass (__cfg >> _item)) exitWith { - TRACE_2("Item not exist in Config",_unit,_item); - false + +private _config = configFile >> "CfgWeapons" >> _item; + +if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith { + TRACE_2("Item not exist in Config",_container,_item); + _return }; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_unit,_item,_count); - false + +if (_verify) then { + if (_container canAdd [_item, _count]) then { + _container addWeaponCargoGlobal [_item, _count]; + _return = true; + } else { + while {_container canAdd _item && {_count > 0}} do { + _container addWeaponCargoGlobal [_item, 1]; + _count = _count - 1; + }; + + private _weaponHolder = nearestObject [_container, "WeaponHolder"]; + + if (isNull _weaponHolder || {_container distance _weaponHolder > 2}) then { + _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; + _weaponHolder setPosATL (getPosATL _container vectorAdd [random 2 - 1, random 2 - 1, 0]); + }; + + _weaponHolder addWeaponCargoGlobal [_item, _count]; + }; +} else { + _container addWeaponCargoGlobal [_item, _count]; + _return = true; }; -_unit __action [_item, _count]; -TRACE_2("Success",_unit,_item); -true + +_return diff --git a/addons/common/fnc_addWeaponCargoGlobal.sqf b/addons/common/fnc_addWeaponCargoGlobal.sqf deleted file mode 100644 index f5c0ef679..000000000 --- a/addons/common/fnc_addWeaponCargoGlobal.sqf +++ /dev/null @@ -1,67 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_addWeaponCargoGlobal - -Description: - Add weapon(s) to vehicle cargo. MP synchronized. - - Function which verifies existence of _item and _unit, returns false in case - of trouble, or when able to add _item to _unit true in case of success. - -Parameters: - _unit - the vehicle [Object] - _item - name of weapon [String] - _count - number of weapons to add [Number] (Default: 1) - -Returns: - true on success, false otherwise - -Examples: - (begin example) - // Add one laser designator to the cargo of SomeTruck - _result = [SomeTruck, "LaserDesignator"] call CBA_fnc_addWeaponCargoGlobal - - // Add two AK 107 rifles to MyUAZ - _result = [MyUAZ, "AK_107_KOBRA", 2] call CBA_fnc_addWeaponCargoGlobal - (end) - -Author: - Sickboy ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" -SCRIPT(addWeaponCargoGlobal); - -params ["_unit","_item", ["_count",1]]; -if (typeName _unit != "OBJECT") exitWith -{ - TRACE_2("Unit not Object",_unit,_item); - false -}; -if (typeName _item != "STRING") exitWith -{ - TRACE_2("Item not String",_unit,_item); - false -}; -if (isNull _unit) exitWith -{ - TRACE_2("Unit isNull",_unit,_item); - false -}; -if (_item == "") exitWith -{ - TRACE_2("Empty Item",_unit,_item); - false -}; -if !(isClass (configFile >> "CfgWeapons" >> _item)) exitWith -{ - TRACE_2("Item does not exist in the config",_unit,_item); - false -}; -if (typeName _count != "SCALAR") exitWith -{ - TRACE_3("Count is not a number",_unit,_item,_count); - false -}; -_unit addWeaponCargoGlobal [_item, _count]; -TRACE_3("Success",_unit,_item,_count); -true diff --git a/addons/common/fnc_removeBackpackCargo.sqf b/addons/common/fnc_removeBackpackCargo.sqf index da210462f..46d936718 100644 --- a/addons/common/fnc_removeBackpackCargo.sqf +++ b/addons/common/fnc_removeBackpackCargo.sqf @@ -9,12 +9,12 @@ Description: global cargo space. Parameters: - _box - Object with cargo [Object] - _item - Classname of backpack(s) to remove [String] - _count - Number of backpack(s) to remove [Number] (Default: 1) + _container - Object with cargo + _item - Classname of backpack(s) to remove + _count - Number of backpack(s) to remove (Default: 1) Returns: - Success [Boolean] + true on success, false otherwise Examples: (begin example) @@ -31,62 +31,57 @@ Author: #include "script_component.hpp" SCRIPT(removeBackpackCargo); -params ["_box", "_item", ["_count", 1]]; +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]]]; -if (typeName _box != "OBJECT") exitWith { - TRACE_2("Box not Object",_box,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_box,_item); - false -}; -if (isNull _box) exitWith { - TRACE_2("Box isNull",_box,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_box,_item); - false +private _return = false; + +if (isNull _container) exitWith { + TRACE_2("Container not Object or null",_container,_item); + _return }; -if !(isClass (configFile >> "CfgVehicles" >> _item)) exitWith { - TRACE_2("Item does not exist in the game config",_box,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_container,_item); + _return }; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_box,_item,_count); - false + +private _config = _item call CBA_fnc_getObjectConfig; + +if (isNull _config || {getNumber (_config >> "scope") < 1} || {getNumber (_config >> "isBackpack") != 1}) exitWith { + TRACE_2("Item not exist in Config",_container,_item); + _return }; + if (_count <= 0) exitWith { - TRACE_3("Count is not a positive number",_box,_item,_count); - false + TRACE_3("Count is not a positive number",_container,_item,_count); + _return }; // Ensure proper count _count = round _count; // Returns array containing two arrays: [[type1, typeN, ...], [count1, countN, ...]] -(getBackpackCargo _box) params ["_allItemsType", "_allItemsCount"]; +(getBackpackCargo _container) params ["_allItemsType", "_allItemsCount"]; // Clear cargo space and readd the items as long it's not the type in question -private _returnVar = false; -clearBackpackCargo _box; +clearBackpackCargoGlobal _container; + { private _itemCount = _allItemsCount select _forEachIndex; if (_x == _item) then { // Process removal - _returnVar = true; + _return = true; _itemCount = _itemCount - _count; if (_itemCount > 0) then { // Add with new count - _box addBackpackCargo [_x, _itemCount]; + _container addBackpackCargoGlobal [_x, _itemCount]; }; } else { // Readd only - _box addBackpackCargo [_x, _itemCount]; + _container addBackpackCargoGlobal [_x, _itemCount]; }; } forEach _allItemsType; -_returnVar +_return diff --git a/addons/common/fnc_removeBackpackCargoGlobal.sqf b/addons/common/fnc_removeBackpackCargoGlobal.sqf deleted file mode 100644 index 4d4b869a7..000000000 --- a/addons/common/fnc_removeBackpackCargoGlobal.sqf +++ /dev/null @@ -1,92 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_removeBackpackCargoGlobal - -Description: - Removes specific backpack(s) from global cargo space. MP synchronized. - Warning: Backpack's inventory information is lost. - - * Use if you want to remove the backpack(s) in - local cargo space. - -Parameters: - _box - Object with cargo [Object] - _item - Classname of backpack(s) to remove [String] - _count - Number of backpack(s) to remove [Number] (Default: 1) - -Returns: - Success [Boolean] - -Examples: - (begin example) - // Remove 1 Kitbag Tan backpack globally from a box - _success = [myCoolBackpackBox, "B_Kitbag_cbr"] call CBA_fnc_removeBackpackCargoGlobal; - - // Remove 2 Carryall Desert Camo backpacks globally from a box - _success = [myCoolBackpackBox, "B_Carryall_ocamo", 2] call CBA_fnc_removeBackpackCargoGlobal; - (end) - -Author: - Jonpas ----------------------------------------------------------------------------- */ -#include "script_component.hpp" -SCRIPT(removeBackpackCargoGlobal); - -params ["_box", "_item", ["_count", 1]]; - -if (typeName _box != "OBJECT") exitWith { - TRACE_2("Box not Object",_box,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_box,_item); - false -}; -if (isNull _box) exitWith { - TRACE_2("Box isNull",_box,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_box,_item); - false -}; -if !(isClass (configFile >> "CfgVehicles" >> _item)) exitWith { - TRACE_2("Item does not exist in the game config",_box,_item); - false -}; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_box,_item,_count); - false -}; -if (_count <= 0) exitWith { - TRACE_3("Count is not a positive number",_box,_item,_count); - false -}; - -// Ensure proper count -_count = round _count; - -// Returns array containing two arrays: [[type1, typeN, ...], [count1, countN, ...]] -(getBackpackCargo _box) params ["_allItemsType", "_allItemsCount"]; - -// Clear cargo space and readd the items as long it's not the type in question -private _returnVar = false; -clearBackpackCargoGlobal _box; -{ - private _itemCount = _allItemsCount select _forEachIndex; - - if (_x == _item) then { - // Process removal - _returnVar = true; - - _itemCount = _itemCount - _count; - if (_itemCount > 0) then { - // Add with new count - _box addBackpackCargoGlobal [_x, _itemCount]; - }; - } else { - // Readd only - _box addBackpackCargoGlobal [_x, _itemCount]; - }; -} forEach _allItemsType; - -_returnVar diff --git a/addons/common/fnc_removeItemCargo.sqf b/addons/common/fnc_removeItemCargo.sqf index c560d9303..db04f7c7e 100644 --- a/addons/common/fnc_removeItemCargo.sqf +++ b/addons/common/fnc_removeItemCargo.sqf @@ -4,16 +4,17 @@ Function: CBA_fnc_removeItemCargo Description: Removes specific item(s) from local cargo space. + * Use if you want to remove the item(s) in global cargo space. Parameters: - _box - Object with cargo [Object] - _item - Classname of item(s) to remove [String] - _count - Number of item(s) to remove [Number] (Default: 1) + _container - Object with cargo + _item - Classname of item(s) to remove + _count - Number of item(s) to remove (Default: 1) Returns: - Success [Boolean] + true on success, false otherwise Examples: (begin example) @@ -30,62 +31,57 @@ Author: #include "script_component.hpp" SCRIPT(removeItemCargo); -params ["_box", "_item", ["_count", 1]]; +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]]]; -if (typeName _box != "OBJECT") exitWith { - TRACE_2("Box not Object",_box,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_box,_item); - false -}; -if (isNull _box) exitWith { - TRACE_2("Box isNull",_box,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_box,_item); - false +private _return = false; + +if (isNull _container) exitWith { + TRACE_2("Container not Object or null",_container,_item); + _return }; -if !(isClass (configFile >> "CfgWeapons" >> _item) || isClass (configFile >> "CfgGlasses" >> _item)) exitWith { - TRACE_2("Item does not exist in the game config",_box,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_container,_item); + _return }; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_box,_item,_count); - false + +private _config = _item call CBA_fnc_getItemConfig; + +if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith { + TRACE_2("Item does not exist in Config",_container,_item); + _return }; + if (_count <= 0) exitWith { - TRACE_3("Count is not a positive number",_box,_item,_count); - false + TRACE_3("Count is not a positive number",_container,_item,_count); + _return }; // Ensure proper count _count = round _count; // Returns array containing two arrays: [[type1, typeN, ...], [count1, countN, ...]] -(getItemCargo _box) params ["_allItemsType", "_allItemsCount"]; +(getItemCargo _container) params ["_allItemsType", "_allItemsCount"]; // Clear cargo space and readd the items as long it's not the type in question -private _returnVar = false; -clearItemCargo _box; +clearItemCargoGlobal _container; + { private _itemCount = _allItemsCount select _forEachIndex; if (_x == _item) then { // Process removal - _returnVar = true; + _return = true; _itemCount = _itemCount - _count; if (_itemCount > 0) then { // Add with new count - _box addItemCargo [_x, _itemCount]; + _container addItemCargoGlobal [_x, _itemCount]; }; } else { // Readd only - _box addItemCargo [_x, _itemCount]; + _container addItemCargoGlobal [_x, _itemCount]; }; } forEach _allItemsType; -_returnVar +_return diff --git a/addons/common/fnc_removeItemCargoGlobal.sqf b/addons/common/fnc_removeItemCargoGlobal.sqf deleted file mode 100644 index 99ee66156..000000000 --- a/addons/common/fnc_removeItemCargoGlobal.sqf +++ /dev/null @@ -1,91 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_removeItemCargoGlobal - -Description: - Removes specific item(s) from global cargo space. MP synchronized. - - * Use if you want to remove the item(s) in - local cargo space. - -Parameters: - _box - Object with cargo [Object] - _item - Classname of item(s) to remove [String] - _count - Number of item(s) to remove [Number] (Default: 1) - -Returns: - Success [Boolean] - -Examples: - (begin example) - // Remove 1 GPS globally from a box - _success = [myCoolItemBox, "ItemGPS"] call CBA_fnc_removeItemCargoGlobal; - - // Remove 2 Compasses globally from a box - _success = [myCoolItemBox, "ItemCompass", 2] call CBA_fnc_removeItemCargoGlobal; - (end) - -Author: - Jonpas ----------------------------------------------------------------------------- */ -#include "script_component.hpp" -SCRIPT(removeItemCargoGlobal); - -params ["_box", "_item", ["_count", 1]]; - -if (typeName _box != "OBJECT") exitWith { - TRACE_2("Box not Object",_box,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_box,_item); - false -}; -if (isNull _box) exitWith { - TRACE_2("Box isNull",_box,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_box,_item); - false -}; -if !(isClass (configFile >> "CfgWeapons" >> _item) || isClass (configFile >> "CfgGlasses" >> _item)) exitWith { - TRACE_2("Item does not exist in the game config",_box,_item); - false -}; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_box,_item,_count); - false -}; -if (_count <= 0) exitWith { - TRACE_3("Count is not a positive number",_box,_item,_count); - false -}; - -// Ensure proper count -_count = round _count; - -// Returns array containing two arrays: [[type1, typeN, ...], [count1, countN, ...]] -(getItemCargo _box) params ["_allItemsType", "_allItemsCount"]; - -// Clear cargo space and readd the items as long it's not the type in question -private _returnVar = false; -clearItemCargoGlobal _box; -{ - private _itemCount = _allItemsCount select _forEachIndex; - - if (_x == _item) then { - // Process removal - _returnVar = true; - - _itemCount = _itemCount - _count; - if (_itemCount > 0) then { - // Add with new count - _box addItemCargoGlobal [_x, _itemCount]; - }; - } else { - // Readd only - _box addItemCargoGlobal [_x, _itemCount]; - }; -} forEach _allItemsType; - -_returnVar diff --git a/addons/common/fnc_removeMagazineCargo.sqf b/addons/common/fnc_removeMagazineCargo.sqf index de2613579..0461c9617 100644 --- a/addons/common/fnc_removeMagazineCargo.sqf +++ b/addons/common/fnc_removeMagazineCargo.sqf @@ -9,12 +9,12 @@ Description: global cargo space. Parameters: - _box - Object with cargo [Object] - _item - Classname of magazine(s) to remove [String] - _count - Number of magazine(s) to remove [Number] (Default: 1) + _container - Object with cargo + _item - Classname of magazine(s) to remove + _count - Number of magazine(s) to remove (Default: 1) Returns: - Success [Boolean] + true on success, false otherwise Examples: (begin example) @@ -26,68 +26,62 @@ Examples: (end) Author: - silencer.helling3r 2012-12-22 - Jonpas + silencer.helling3r 2012-12-22, Jonpas ---------------------------------------------------------------------------- */ #include "script_component.hpp" SCRIPT(removeMagazineCargo); -params ["_box","_item", ["_count",1]]; +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]]]; -if (typeName _box != "OBJECT") exitWith { - TRACE_2("Box not Object",_box,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_box,_item); - false -}; -if (isNull _box) exitWith { - TRACE_2("Box isNull",_box,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_box,_item); - false +private _return = false; + +if (isNull _container) exitWith { + TRACE_2("Container not Object or null",_container,_item); + _return }; -if !(isClass (configFile >> "CfgMagazines" >> _item)) exitWith { - TRACE_2("Item does not exist in the game config",_box,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_container,_item); + _return }; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_box,_item,_count); - false + +private _config = configFile >> "CfgMagazines" >> _item; + +if (isNull _config || {getNumber (_config >> "scope") < 2}) exitWith { + TRACE_2("Item does not exist in Config",_container,_item); + _return }; + if (_count <= 0) exitWith { - TRACE_3("Count is not a positive number",_box,_item,_count); - false + TRACE_3("Count is not a positive number",_container,_item,_count); + _return }; // Ensure proper count _count = round _count; // Returns array containing two arrays: [[type1, typeN, ...], [count1, countN, ...]] -(getMagazineCargo _box) params ["_allItemsType", "_allItemsCount"]; +(getMagazineCargo _container) params ["_allItemsType", "_allItemsCount"]; // Clear cargo space and readd the items as long it's not the type in question -private _returnVar = false; -clearMagazineCargo _box; +clearMagazineCargoGlobal _container; + { private _itemCount = _allItemsCount select _forEachIndex; if (_x == _item) then { // Process removal - _returnVar = true; + _return = true; _itemCount = _itemCount - _count; if (_itemCount > 0) then { // Add with new count - _box addMagazineCargo [_x, _itemCount]; + _container addMagazineCargoGlobal [_x, _itemCount]; }; } else { // Readd only - _box addMagazineCargo [_x, _itemCount]; + _container addMagazineCargoGlobal [_x, _itemCount]; }; } forEach _allItemsType; -_returnVar +_return diff --git a/addons/common/fnc_removeMagazineCargoGlobal.sqf b/addons/common/fnc_removeMagazineCargoGlobal.sqf deleted file mode 100644 index 4478bd45a..000000000 --- a/addons/common/fnc_removeMagazineCargoGlobal.sqf +++ /dev/null @@ -1,93 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_removeMagazineCargoGlobal - -Description: - Removes specific magazine(s) from global cargo space. MP synchronized. - Warning: Magazine's ammo count is lost and becomes full. - - * Use if you want to remove the magazine(s) in local - cargo space. - -Parameters: - _box - Object with cargo [Object] - _item - Classname of magazine(s) to remove [String] - _count - Number of magazine(s) to remove [Number] (Default: 1) - -Returns: - Success [Boolean] - -Examples: - (begin example) - // Remove 1 Smokegrenade globally from a box - _success = [myCoolMagazineBox, "SmokeShell"] call CBA_fnc_removeMagazineCargoGlobal; - - // Remove 2 Handgrenades globally from a box - _success = [myCoolMagazineBox, "HandGrenade_West", 2] call CBA_fnc_removeMagazineCargoGlobal; - (end) - -Author: - silencer.helling3r 2012-12-22 - Jonpas ----------------------------------------------------------------------------- */ -#include "script_component.hpp" -SCRIPT(removeMagazineCargoGlobal); - -params ["_box","_item", ["_count",1]]; - -if (typeName _box != "OBJECT") exitWith { - TRACE_2("Box not Object",_box,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_box,_item); - false -}; -if (isNull _box) exitWith { - TRACE_2("Box isNull",_box,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_box,_item); - false -}; -if !(isClass (configFile >> "CfgMagazines" >> _item)) exitWith { - TRACE_2("Item does not exist in the game config",_box,_item); - false -}; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_box,_item,_count); - false -}; -if (_count <= 0) exitWith { - TRACE_3("Count is not a positive number",_box,_item,_count); - false -}; - -// Ensure proper count -_count = round _count; - -// Returns array containing two arrays: [[type1, typeN, ...], [count1, countN, ...]] -(getMagazineCargo _box) params ["_allItemsType", "_allItemsCount"]; - -// Clear cargo space and readd the items as long it's not the type in question -private _returnVar = false; -clearMagazineCargoGlobal _box; -{ - private _itemCount = _allItemsCount select _forEachIndex; - - if (_x == _item) then { - // Process removal - _returnVar = true; - - _itemCount = _itemCount - _count; - if (_itemCount > 0) then { - // Add with new count - _box addMagazineCargoGlobal [_x, _itemCount]; - }; - } else { - // Readd only - _box addMagazineCargoGlobal [_x, _itemCount]; - }; -} forEach _allItemsType; - -_returnVar diff --git a/addons/common/fnc_removeWeaponCargo.sqf b/addons/common/fnc_removeWeaponCargo.sqf index efe88469b..7a08aa338 100644 --- a/addons/common/fnc_removeWeaponCargo.sqf +++ b/addons/common/fnc_removeWeaponCargo.sqf @@ -9,12 +9,12 @@ Description: global cargo space. Parameters: - _box - Object with cargo [Object] - _item - Classname of weapon(s) to remove [String] - _count - Number of weapon(s) to remove [Number] (Default: 1) + _container - Object with cargo + _item - Classname of weapon(s) to remove + _count - Number of weapon(s) to remove (Default: 1) Returns: - Success [Boolean] + true on success, false otherwise Examples: (begin example) @@ -26,69 +26,62 @@ Examples: (end) Author: - silencer.helling3r 2012-12-22 - Jonpas + silencer.helling3r 2012-12-22, Jonpas ---------------------------------------------------------------------------- */ #include "script_component.hpp" SCRIPT(removeWeaponCargo); -params ["_box","_item", ["_count",1]]; +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]]]; -if (typeName _box != "OBJECT") exitWith { - TRACE_2("Box not Object",_box,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_box,_item); - false -}; -if (isNull _box) exitWith { - TRACE_2("Box isNull",_box,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_box,_item); - false +private _return = false; + +if (isNull _container) exitWith { + TRACE_2("Container not Object or null",_container,_item); + _return }; -if !(isClass (configFile >> "CfgWeapons" >> _item)) exitWith { - TRACE_2("Item does not exist in the game config",_box,_item); - false + +if (_item isEqualTo "") exitWith { + TRACE_2("Item not String or empty",_container,_item); + _return }; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_box,_item,_count); - false + +private _config = configFile >> "CfgWeapons" >> _item; + +if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith { + TRACE_2("Item does not exist in Config",_container,_item); + _return }; + if (_count <= 0) exitWith { - TRACE_3("Count is not a positive number",_box,_item,_count); - false + TRACE_3("Count is not a positive number",_container,_item,_count); + _return }; // Ensure proper count _count = round _count; - // Returns array containing two arrays: [[type1, typeN, ...], [count1, countN, ...]] -(getWeaponCargo _box) params ["_allItemsType", "_allItemsCount"]; +(getWeaponCargo _container) params ["_allItemsType", "_allItemsCount"]; // Clear cargo space and readd the items as long it's not the type in question -private _returnVar = false; -clearWeaponCargo _box; +clearWeaponCargoGlobal _container; + { private _itemCount = _allItemsCount select _forEachIndex; if (_x == _item) then { // Process removal - _returnVar = true; + _return = true; _itemCount = _itemCount - _count; if (_itemCount > 0) then { // Add with new count - _box addWeaponCargo [_x, _itemCount]; + _container addWeaponCargoGlobal [_x, _itemCount]; }; } else { // Readd only - _box addWeaponCargo [_x, _itemCount]; + _container addWeaponCargoGlobal [_x, _itemCount]; }; } forEach _allItemsType; -_returnVar +_return diff --git a/addons/common/fnc_removeWeaponCargoGlobal.sqf b/addons/common/fnc_removeWeaponCargoGlobal.sqf deleted file mode 100644 index 7c3930ab3..000000000 --- a/addons/common/fnc_removeWeaponCargoGlobal.sqf +++ /dev/null @@ -1,93 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_removeWeaponCargoGlobal - -Description: - Removes specific weapon(s) from global cargo space. MP synchronized. - Warning: Weapon's attachments are lost. - - * Use if you want to remove the weapon(s) in local - cargo space. - -Parameters: - _box - Object with cargo [Object] - _item - Classname of weapon(s) to remove [String] - _count - Number of weapon(s) to remove [Number] (Default: 1) - -Returns: - Success [Boolean] - -Examples: - (begin example) - // Remove 1 Binocular globally from a box - _success = [myCoolWeaponBox, "Binocular"] call CBA_fnc_removeWeaponCargoGlobal; - - // Remove 2 M16 globally from a box - _success = [myCoolWeaponBox, "M16A2", 2] call CBA_fnc_removeWeaponCargoGlobal; - (end) - -Author: - silencer.helling3r 2012-12-22 - Jonpas ----------------------------------------------------------------------------- */ -#include "script_component.hpp" -SCRIPT(removeWeaponCargoGlobal); - -params ["_box","_item", ["_count",1]]; - -if (typeName _box != "OBJECT") exitWith { - TRACE_2("Box not Object",_box,_item); - false -}; -if (typeName _item != "STRING") exitWith { - TRACE_2("Item not String",_box,_item); - false -}; -if (isNull _box) exitWith { - TRACE_2("Box isNull",_box,_item); - false -}; -if (_item == "") exitWith { - TRACE_2("Empty Item",_box,_item); - false -}; -if !(isClass (configFile >> "CfgWeapons" >> _item)) exitWith { - TRACE_2("Item does not exist in the game config",_box,_item); - false -}; -if (typeName _count != "SCALAR") exitWith { - TRACE_3("Count is not a number",_box,_item,_count); - false -}; -if (_count <= 0) exitWith { - TRACE_3("Count is not a positive number",_box,_item,_count); - false -}; - -// Ensure proper count -_count = round _count; - -// Returns array containing two arrays: [[type1, typeN, ...], [count1, countN, ...]] -(getWeaponCargo _box) params ["_allItemsType", "_allItemsCount"]; - -// Clear cargo space and readd the items as long it's not the type in question -private _returnVar = false; -clearWeaponCargoGlobal _box; -{ - private _itemCount = _allItemsCount select _forEachIndex; - - if (_x == _item) then { - // Process removal - _returnVar=true; - - _itemCount = _itemCount - _count; - if (_itemCount > 0) then { - // Add with new count - _box addWeaponCargoGlobal [_x, _itemCount]; - }; - } else { - // Readd only - _box addWeaponCargoGlobal [_x, _itemCount]; - }; -} forEach _allItemsType; - -_returnVar From e9b99c78c0a8d0f1937286242f3e9c6c35c2d254 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:08:17 +0100 Subject: [PATCH 05/18] rewrite common vehicle functions --- addons/common/fnc_getVehicleRole.sqf | 27 +++++++++++++++++++++++++++ addons/common/fnc_getVolume.sqf | 20 +++++++++----------- 2 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 addons/common/fnc_getVehicleRole.sqf diff --git a/addons/common/fnc_getVehicleRole.sqf b/addons/common/fnc_getVehicleRole.sqf new file mode 100644 index 000000000..5719d8b17 --- /dev/null +++ b/addons/common/fnc_getVehicleRole.sqf @@ -0,0 +1,27 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getVehicleRole + +Description: + A function used to report the soldiers role in his current vehicle. + Used because assignedVehicleRole reports the role assigned by the group leader instead of the current position. + +Parameters: + _unit - a soldier in a vehicle + +Example: + (begin example) + _role = player call CBA_fnc_getVehicleRole + (end) + +Returns: + Soldiers role in the current vehicle. Can be "driver", "gunner", "commander", "Turret", or "cargo". Empty string if not in vehicle + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getVehicleRole); + +params [["_unit", objNull, [objNull]]]; + +fullCrew vehicle _unit select {(_x select 0) isEqualTo _unit} param [0, [nil, ""]] select 1 diff --git a/addons/common/fnc_getVolume.sqf b/addons/common/fnc_getVolume.sqf index 627a8d995..059621020 100644 --- a/addons/common/fnc_getVolume.sqf +++ b/addons/common/fnc_getVolume.sqf @@ -2,29 +2,27 @@ Function: CBA_fnc_getVolume Description: - Return the volume of an object based on the object's model's bounding - box. + Return the volume of an object based on the object's model's bounding box. Parameters: - _object - an object to calculate the volume of. [Object] + _object - an object to calculate the volume of Returns: - _volume - the volume. [Number] + _volume - the volume Examples: (begin example) - _vol = _vehicle call CBA_fnc_getVolume + _volume = _vehicle call CBA_fnc_getVolume (end) Author: Rommel ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getVolume); -#include +params [["_object", objNull, [objNull]]]; -params ["_object"]; +private _bounds = (boundingBox _object) select 1; -private "_bounds"; -_bounds = (boundingBox _object) select 1; - -((_bounds select 0) * (_bounds select 1) * (_bounds select 2)); +(_bounds select 0) * (_bounds select 1) * (_bounds select 2) From 8a4d6c21d8fd700c0337dcf964bf087ba36a9fdc Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:12:09 +0100 Subject: [PATCH 06/18] rewrite common map functions --- addons/common/fnc_getDistance.sqf | 12 +++- addons/common/fnc_getNearest.sqf | 36 ++++++------ addons/common/fnc_getNearestBuilding.sqf | 14 ++--- addons/common/fnc_getPos.sqf | 28 ++++++---- addons/common/fnc_inArea.sqf | 71 +++++++++++------------- addons/common/fnc_randPos.sqf | 21 ++++--- addons/common/fnc_randPosArea.sqf | 12 ++-- addons/common/fnc_realHeight.sqf | 11 ++-- addons/common/fnc_setHeight.sqf | 18 +++--- addons/common/fnc_setPos.sqf | 52 ++++++++--------- 10 files changed, 141 insertions(+), 134 deletions(-) diff --git a/addons/common/fnc_getDistance.sqf b/addons/common/fnc_getDistance.sqf index 2512601fe..af7ae8ff5 100644 --- a/addons/common/fnc_getDistance.sqf +++ b/addons/common/fnc_getDistance.sqf @@ -5,7 +5,7 @@ Description: A function used to find out the distance between two positions. Parameters: - Array containing two of [Marker, Object, Location, Group or Position] + Array containing two of Example: (begin example) @@ -17,7 +17,13 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getDistance); + +params [ + ["_entity1", objNull, [objNull, grpNull, "", locationNull, taskNull, []]], + ["_entity2", objNull, [objNull, grpNull, "", locationNull, taskNull, []]] +]; -((_this select 0) call CBA_fnc_getPos) distance ((_this select 1) call CBA_fnc_getPos) +(_entity1 call CBA_fnc_getPos) distance (_entity2 call CBA_fnc_getPos) diff --git a/addons/common/fnc_getNearest.sqf b/addons/common/fnc_getNearest.sqf index f9e06482d..a24b8ce89 100644 --- a/addons/common/fnc_getNearest.sqf +++ b/addons/common/fnc_getNearest.sqf @@ -5,15 +5,15 @@ Description: A function used to find out the nearest entity parsed in an array to a position. Compares the distance between entity's in the parsed array. Parameters: - _position - Marker, Object, Location, Group or Position - _array - Array of [Marker, Object, Location, Group and or Positions] - _radius - Maximum distance from _position - _code - Condition to meet (Code) + _position - + _array - of + _radius - Maximum distance from _position + _code - Condition to meet, object is stored in _x variable Example: (begin example) - _nearestVeh = [player, vehicles] call CBA_fnc_getNearest - _nearestGroups = [[0,0,0], allGroups, 50, {count (units _x) > 1}] call CBA_fnc_getNearest + _nearestVeh = [player, vehicles] call CBA_fnc_getNearest + _nearestGroups = [[0,0,0], allGroups, 50, {count (units _x) > 1}] call CBA_fnc_getNearest (end) Returns: @@ -21,23 +21,26 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ - #include "script_component.hpp" +SCRIPT(getNearest); -params ["_position","_array"]; +params [ + ["_position", objNull, [objNull, grpNull, "", locationNull, taskNull, []]], + ["_array", [], [[]]], + ["_radius", 1E5, [0]], + ["_code", {}, [{}]] +]; -DEFAULT_PARAM(2,_radius,10^5); -DEFAULT_PARAM(3,_code,{true}); +private _return = [[], objNull] select (isNil {param [2]}); -private "_return"; -_return = if (count _this > 2) then {[]} else {objNull}; { - _distance = [_position,_x] call CBA_fnc_getDistance; + _distance = [_position, _x] call CBA_fnc_getDistance; + if (_distance < _radius) then { - if !(call _code) exitwith {}; - if (count _this > 2) then { + if !(call _code) exitwith {}; // don't move up. condition has to return false, vs. has to return true. Can be nil! + + if !(_return isEqualType objNull) then { _return pushBack _x; } else { _radius = _distance; @@ -45,4 +48,5 @@ _return = if (count _this > 2) then {[]} else {objNull}; }; }; } foreach _array; + _return diff --git a/addons/common/fnc_getNearestBuilding.sqf b/addons/common/fnc_getNearestBuilding.sqf index 42de26c4e..a4afed705 100644 --- a/addons/common/fnc_getNearestBuilding.sqf +++ b/addons/common/fnc_getNearestBuilding.sqf @@ -5,11 +5,11 @@ Description: A function used to find out the nearest building and appropriate building positions available. Parameters: - Object + _position - Example: (begin example) - _array = player call CBA_fnc_getNearestBuilding + _array = player call CBA_fnc_getNearestBuilding (end) Returns: @@ -18,11 +18,11 @@ Returns: Author: Rommel ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getNearestBuilding); -private ["_building", "_i"]; +[_this] params [["_position", objNull, [objNull, []]]]; -_building = nearestBuilding _this; -_i = 0; +private _building = nearestBuilding _position; -while {str(_building buildingPos _i) != "[0,0,0]"} do {_i = _i + 1;}; -[_building, _i] +[_building, count (_building buildingPos -1)] diff --git a/addons/common/fnc_getPos.sqf b/addons/common/fnc_getPos.sqf index 18f37b8fc..89c936bbe 100644 --- a/addons/common/fnc_getPos.sqf +++ b/addons/common/fnc_getPos.sqf @@ -5,11 +5,11 @@ Description: A function used to get the position of an entity. Parameters: - Marker, Object, Location, Group or Task + _entity - Example: (begin example) - _position = (group player) call CBA_fnc_getPos + _position = (group player) call CBA_fnc_getPos (end) Returns: @@ -17,26 +17,32 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getPos); -params ["_thing"]; +params [ + ["_entity", objNull, [objNull, grpNull, "", locationNull, taskNull, [], 0]] // [] and 0 to handle position +]; -switch (typeName _thing) do { +switch (typeName _entity) do { case "OBJECT" : { - getPos _thing + getPos _entity }; case "GROUP" : { - getPos (leader _thing) + getPos (leader _entity) }; case "STRING" : { - getMarkerPos _thing + getMarkerPos _entity }; case "LOCATION" : { - position _thing + position _entity }; case "TASK" : { - taskDestination _thing + taskDestination _entity + }; + case "ARRAY" : { + _entity }; - default {_this}; + default {_this}; // in case of position being passed not in array }; diff --git a/addons/common/fnc_inArea.sqf b/addons/common/fnc_inArea.sqf index b63296e65..0a727c23c 100644 --- a/addons/common/fnc_inArea.sqf +++ b/addons/common/fnc_inArea.sqf @@ -12,51 +12,52 @@ Description: Parameters: A two-element array, [ position, zone], where - - position: Marker|Object|Location|Group|Position - - zone: Marker|Trigger + - position: + - zone: Example: (begin example) - // Is the marker "playermarker" inside the "safezone" marker area? - _safe = [ "playermarker", "safezone"] call CBA_fnc_inArea; - - // is the player within the safe zone marker area? - _pos = getPos player; - _safe = [ _pos, "safezone" ] call CBA_fnc_inArea; - - // Deny artillery if target is inside the trigger area - if ([_target, cityTrigger] call CBA_fnc_inArea) then - { - // deny fire mission - } - else - { - // fire away! - }; + // Is the marker "playermarker" inside the "safezone" marker area? + _safe = [ "playermarker", "safezone"] call CBA_fnc_inArea; + + // is the player within the safe zone marker area? + _pos = getPos player; + _safe = [ _pos, "safezone" ] call CBA_fnc_inArea; + + // Deny artillery if target is inside the trigger area + if ([_target, cityTrigger] call CBA_fnc_inArea) then + { + // deny fire mission + } + else + { + // fire away! + }; (end) Returns: - Boolean + Author: Rommel - ---------------------------------------------------------------------------- */ #include "script_component.hpp" +SCRIPT(inArea); -params ["_position","_zRef"]; +params ["_position", ["_zRef", objNull, ["", objNull]]]; -_position = (_position call CBA_fnc_getpos); +_position = _position call CBA_fnc_getpos; private ["_zSize","_zDir","_zShape","_zPos"]; + switch (typeName _zRef) do { - case "STRING" : { + case "STRING": { _zSize = markerSize _zRef; _zDir = markerDir _zRef; _zShape = toLower (markerShape _zRef); _zPos = (_zRef call CBA_fnc_getpos); }; - case "OBJECT" : { + case "OBJECT": { _zSize = triggerArea _zRef; _zDir = _zSize select 2; _zShape = if (_zSize select 3) then {"rectangle"} else {"ellipse"}; @@ -66,30 +67,22 @@ switch (typeName _zRef) do { if (isNil "_zSize") exitWith {false}; -_position = [_zPos,_position,_zDir] call CBA_fnc_vectRotate2D; - -private ["_x1","_y1"]; -_x1 = _zpos select 0; -_y1 = _zpos select 1; +_position = [_zPos, _position, _zDir] call CBA_fnc_vectRotate2D; -private ["_x2","_y2"]; -_x2 = _position select 0; -_y2 = _position select 1; +_zPos params ["_x1", "_y1"]; +_position params ["_x2", "_y2"]; -private ["_dx","_dy"]; -_dx = _x2 - _x1; -_dy = _y2 - _y1; +private _dx = _x2 - _x1; +private _dy = _y2 - _y1; -private ["_zx","_zy"]; -_zx = _zsize select 0; -_zy = _zsize select 1; +_zSize params ["_zx", "_zy"]; switch (_zShape) do { case "ellipse": { ((_dx^2)/(_zx^2) + (_dy^2)/(_zy^2)) < 1 }; case "rectangle": { - (abs _dx < _zx) and (abs _dy < _zy) + (abs _dx < _zx) && (abs _dy < _zy) }; default { false diff --git a/addons/common/fnc_randPos.sqf b/addons/common/fnc_randPos.sqf index 7709f28d9..4eaf22fd7 100644 --- a/addons/common/fnc_randPos.sqf +++ b/addons/common/fnc_randPos.sqf @@ -5,11 +5,12 @@ Description: A function used to randomize a position around a given center Parameters: - Marker, Object, Location, Group or Position, Radius + _position - + _radius - random Radius Example: (begin example) - _position = [position, radius] call CBA_fnc_randPos + _position = [position, radius] call CBA_fnc_randPos (end) Returns: @@ -17,13 +18,15 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(randPos); + +params [ + ["_entity", objNull, [objNull, grpNull, "", locationNull, taskNull, []]], + ["_radius", 0, [0]] +]; -private ["_position","_radius"]; -_position = +((_this select 0) call CBA_fnc_getpos); -_radius = _this select 1; +private _position = _entity call CBA_fnc_getPos; -_position set [0,(_position select 0) + (_radius - (random (2*_radius)))]; -_position set [1,(_position select 1) + (_radius - (random (2*_radius)))]; -_position +_position vectorAdd [_radius - 2 * random _radius, _radius - 2 * random _radius, 0] diff --git a/addons/common/fnc_randPosArea.sqf b/addons/common/fnc_randPosArea.sqf index e0dc4109a..74c207555 100644 --- a/addons/common/fnc_randPosArea.sqf +++ b/addons/common/fnc_randPosArea.sqf @@ -7,22 +7,24 @@ Description: * You can to find a position within a simple radius. Parameters: - _zone - The zone to find a position within [Marker or Trigger] - _perimeter - True to return only positions on the area perimeter [Boolean, defaults to false] + _zone - The zone to find a position within + _perimeter - True to return only positions on the area perimeter (optional, default: false) Returns: - Position [Array] (Empty array if non-area object/marker was given) + Position (Empty array if non-area object/marker was given) Examples: (begin example) - _position = [marker, true] call CBA_fnc_randPosArea; + _position = [marker, true] call CBA_fnc_randPosArea; - _position = [trigger] call CBA_fnc_randPosArea; + _position = [trigger] call CBA_fnc_randPosArea; (end) Author: SilentSpike 2015-07-06 ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(randPosArea); private ["_zRef","_zSize","_zDir","_zRect","_zPos","_perimeter","_posVector"]; _zRef = _this select 0; diff --git a/addons/common/fnc_realHeight.sqf b/addons/common/fnc_realHeight.sqf index 0600ae6ac..79d5f5fa0 100644 --- a/addons/common/fnc_realHeight.sqf +++ b/addons/common/fnc_realHeight.sqf @@ -5,23 +5,22 @@ Description: Real z coordinate of an object, for placing stuff on roofs, etc. Parameters: - _obj: an object [Object] + _object - an object Returns: - The z coordinate of the top of that object. [Number] + The z coordinate of the top of that object. Examples: (begin example) - _height = _house call CBA_fnc_realHeight; + _height = _house call CBA_fnc_realHeight; (end) Author: ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(realHeight); -params ["_obj"]; +params [["_object", objNull, [objNull]]]; -((getpos _obj) select 2) + (_obj distance (getpos _obj)) +((getpos _object) select 2) + (_object distance (getpos _object)) diff --git a/addons/common/fnc_setHeight.sqf b/addons/common/fnc_setHeight.sqf index 5c3678d73..5373ead8a 100644 --- a/addons/common/fnc_setHeight.sqf +++ b/addons/common/fnc_setHeight.sqf @@ -5,13 +5,13 @@ Description: A function used to set the height of an object Parameters: - _object - Object or Location - _height - Height in metres - _type - Optional parameter, 0 is getpos, 1 is getpos ASL, 2 is getposATL (Default: 1) + _object - + _height - Height in metres + _type - Mode (optional, default: 1), 0 is AGL, 1 is ASL, 2 is ATL (Default: 1) Example: (begin example) - [this, 10] call CBA_fnc_setHeight + [this, 10] call CBA_fnc_setHeight (end) Returns: @@ -19,19 +19,18 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ - #include "script_component.hpp" +SCRIPT(setHeight); -params ["_object","_height", ["_type",1]]; +params [["_object", objNull, [objNull]], ["_height", 0, [0]], ["_type", 1, [0]]]; -private "_position"; -_position = switch (_type) do { +private _position = switch (_type) do { case 0 : {getPos _object}; case 1 : {getPosASL _object}; case 2 : {getPosATL _object}; }; + _position set [2, _height]; switch (_type) do { @@ -39,4 +38,5 @@ switch (_type) do { case 1 : {_object setPosASL _position}; case 2 : {_object setPosATL _position}; }; + _object setDir (getDir _object); diff --git a/addons/common/fnc_setPos.sqf b/addons/common/fnc_setPos.sqf index 1d1605104..0a8735a6d 100644 --- a/addons/common/fnc_setPos.sqf +++ b/addons/common/fnc_setPos.sqf @@ -5,11 +5,13 @@ Description: A function used to set the position of an entity. Parameters: - Marker, Object, Location, Group or Position + _entity - + _position - + _radius - random Radius (optional) Example: (begin example) - [player, "respawn_west"] call CBA_fnc_setPos + [player, "respawn_west"] call CBA_fnc_setPos (end) Returns: @@ -17,51 +19,43 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(setPos); + +params [ + ["_entity", objNull, [objNull, grpNull, "", locationNull, taskNull]], + ["_position", nil, [objNull, grpNull, "", locationNull, taskNull, []]], + ["_radius", 0, [0]] +]; -private ["_entity","_position","_radius"]; -_entity = _this select 0; -_position = _this select 1; -_radius = if (count _this > 2) then {_this select 2} else {0}; +if (isNil "_position") exitWith {}; -_position = _position call CBA_fnc_getpos; +_position = _position call CBA_fnc_getPos; if (_radius > 0) then { _position = [_position, _radius] call CBA_fnc_randPos; }; -switch (typename _entity) do { +switch (typeName _entity) do { case "OBJECT" : { - _entity setpos _position; + _entity setPos _position; }; case "GROUP" : { - private ["_ldp","_dx","_dy","_dz"]; - _ldp = getpos (leader _entity); - _dx = _position select 0; - _dy = _position select 1; - _dz = _position select 2; + private _leaderPos = getPos (leader _entity); + { - private ["_txyz","_tx", "_ty", "_tz"]; - _txyz = _x worldtomodel _ldp; - _tx = _dx + (_txyz select 0); - _ty = _dy + (_txyz select 1); - _tz = _dz + (_txyz select 2); - _x setpos [_tx,_ty,_tz]; + _x setpos (_position vectorAdd (_x worldToModel _leaderPos)); } foreach (units _entity); }; case "STRING" : { - _entity setmarkerpos _position; + _entity setMarkerPos _position; }; case "LOCATION" : { - if (surfaceiswater _position) then { - _entity setPosition _position; - } else { - _entity setPosition _position; - }; + _entity setPosition _position; }; case "TASK" : { - _entity setsimpletaskdestination _position; + _entity setSimpleTaskDestination _position; }; - default {_entity setpos _position}; + default {}; }; From 7b0c1749b94614ffa06feecdf337e328f4ddf637 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:14:02 +0100 Subject: [PATCH 07/18] params in action argument --- addons/common/fnc_actionArgument.sqf | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/addons/common/fnc_actionArgument.sqf b/addons/common/fnc_actionArgument.sqf index 8c1cc5c60..a4857a921 100644 --- a/addons/common/fnc_actionArgument.sqf +++ b/addons/common/fnc_actionArgument.sqf @@ -10,21 +10,19 @@ Returns: Examples: (begin example) - captive addaction ["rescue",CBA_fnc_actionargument_path,[[],{[_target] join (group _caller)},true]] //captive joins action callers group, action is removed (true) + captive addaction ["rescue",CBA_fnc_actionargument_path,[[],{[_target] join (group _caller)},true]] //captive joins action callers group, action is removed (true) (end) Author: Rommel ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(actionArgument); -private ["_target","_caller","_id","_arguments"]; -_target = _this select 0; -_caller = _this select 1; -_id = _this select 2; -_arguments = _this select 3; +params ["_target", "_caller", "_id", "_arguments"]; (_arguments select 0) call (_arguments select 1); -if (count _arguments > 2 && {_arguments select 2}) then { +if (_arguments param [2, false]) then { _target removeAction _id; -}; \ No newline at end of file +}; From 5ba58852aba60ba7e10cba6ef2ec478e0128809d Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:19:03 +0100 Subject: [PATCH 08/18] rewrite common entities functions --- addons/common/fnc_deleteEntity.sqf | 35 +++++++++++++----------- addons/common/fnc_findEntity.sqf | 23 ++++++++-------- addons/common/fnc_getAlive.sqf | 38 +++++++++----------------- addons/common/fnc_getGroup.sqf | 16 +++++++---- addons/common/fnc_getSharedGroup.sqf | 41 ++++++++++++++-------------- addons/common/fnc_isAlive.sqf | 34 ++++++++++++++--------- addons/common/fnc_nearPlayer.sqf | 27 +++++++++--------- addons/common/fnc_objectRandom.sqf | 28 +++++++++++-------- 8 files changed, 125 insertions(+), 117 deletions(-) diff --git a/addons/common/fnc_deleteEntity.sqf b/addons/common/fnc_deleteEntity.sqf index 4ce9c1e7c..e4559f408 100644 --- a/addons/common/fnc_deleteEntity.sqf +++ b/addons/common/fnc_deleteEntity.sqf @@ -5,7 +5,7 @@ Description: A function used to delete entities Parameters: - Array, Object, Group or Marker + _entity to delete. Can be array of entites. Example: (begin example) @@ -17,36 +17,39 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(deleteEntity); + +[_this] params [["_entity", objNull, [objNull, grpNull, locationNull, "", []]]]; -switch (typeName _this) do { +switch (typeName _entity) do { case "ARRAY" : { { _x call CBA_fnc_deleteEntity; - } foreach _this; + } foreach _entity; }; case "OBJECT" : { - if (vehicle _this != _this) then { - unassignVehicle _this; - _this setPosASL [0,0,0]; + if (vehicle _entity != _entity) then { + unassignVehicle _entity; + _entity setPosASL [0,0,0]; } else { - if (count ((crew _this) - [_this]) > 0) then { - (crew _this) call CBA_fnc_deleteEntity; + if ({_x != _entity} count (crew _entity) > 0) then { + (crew _entity) call CBA_fnc_deleteEntity; }; }; - deleteVehicle _this; + deleteVehicle _entity; }; case "GROUP" : { - (units _this) call CBA_fnc_deleteEntity; - {deleteWaypoint _x} foreach (wayPoints _this); - deleteGroup _this; + (units _entity) call CBA_fnc_deleteEntity; + {deleteWaypoint _x} foreach (wayPoints _entity); + deleteGroup _entity; }; case "LOCATION" : { - deleteLocation _this; + deleteLocation _entity; }; case "STRING" : { - deleteMarker _this + deleteMarker _entity }; - default {deleteVehicle _this}; + default {}; }; diff --git a/addons/common/fnc_findEntity.sqf b/addons/common/fnc_findEntity.sqf index 58b4a7810..27ee43017 100644 --- a/addons/common/fnc_findEntity.sqf +++ b/addons/common/fnc_findEntity.sqf @@ -5,15 +5,15 @@ Description: A function used to find out the first entity of parsed type in a nearEntitys call Parameters: - - Type (Classname, Object) - - Position (XYZ, Object, Location or Group) + - Type (Classname or Object) + - Position Optional: - - Radius (Scalar) + - Radius Example: (begin example) - _veh = ["LaserTarget", player] call CBA_fnc_findEntity + _veh = ["LaserTarget", player] call CBA_fnc_findEntity (end) Returns: @@ -21,17 +21,16 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ - #include "script_component.hpp" - SCRIPT(findEntity); -params ["_type","_position", ["_radius",50]]; +params [["_type", "", [objNull, ""]], ["_position", objNull], ["_radius", 50, [0]]]; + +if (_type isEqualType objNull) then { + _type = typeOf _type; +}; -// this function doesn't return the nearest entity, neither did the previous version +private _return = (_position call CBA_fnc_getPos) nearEntities [[_type], _radius]; -_ret = (_position call CBA_fnc_getpos) nearEntities [[_type], _radius]; -if (count _ret > 0) exitWith {_ret select 0}; -nil +_return param [0] diff --git a/addons/common/fnc_getAlive.sqf b/addons/common/fnc_getAlive.sqf index 1e480bd8e..a2deeb2ce 100644 --- a/addons/common/fnc_getAlive.sqf +++ b/addons/common/fnc_getAlive.sqf @@ -5,42 +5,30 @@ Description: A function used to find out who is alive in an array or a group. Parameters: - Array, Group or Unit + _entities - Array or Group Example: (begin example) - _alive = (Units player) call CBA_fnc_getAlive + _alive = (units player) call CBA_fnc_getAlive (end) Returns: - Array + Author: Rommel - ---------------------------------------------------------------------------- */ - #include "script_component.hpp" +SCRIPT(getAlive); + +[_this] params [["_entities", [], [objNull, grpNull, []]]]; + +if (_entities isEqualType objNull) exitwith { + alive _entities; +}; -private "_typename"; -_typename = typename _this; -if (_typename == "OBJECT") exitwith {alive _this}; - -private ["_return","_array"]; -_array = []; -switch (_typename) do { - case "GROUP" : { - _array = units _this; - }; - case "ARRAY" :{ - _array =+ _this; - }; +if (_entities isEqualType grpNull) then { + _entities = units _entities; }; -_return = []; -{ - if (alive _x) then { - _return pushBack _x; - } -} foreach _array; -_return +_entities select {alive _x} // return diff --git a/addons/common/fnc_getGroup.sqf b/addons/common/fnc_getGroup.sqf index 1c23c1e2c..c61d0d9bf 100644 --- a/addons/common/fnc_getGroup.sqf +++ b/addons/common/fnc_getGroup.sqf @@ -5,11 +5,11 @@ Description: A function used to find out the group of an object. Parameters: - Group or Unit + _entity - Example: (begin example) - _group = player call CBA_fnc_getGroup + _group = player call CBA_fnc_getGroup (end) Returns: @@ -17,8 +17,12 @@ Returns: Author: Rommel - ---------------------------------------------------------------------------- */ -params [["_group", grpNull, [grpNull, objNull]]]; -if ((typeName _group) isEqualTo "GROUP") exitWith {_group}; -group _group +#include "script_component.hpp" +SCRIPT(getGroup); + +params [["_entity", grpNull, [grpNull, objNull]]]; + +if (_entity isEqualType grpNull) exitWith {_entity}; + +group _entity diff --git a/addons/common/fnc_getSharedGroup.sqf b/addons/common/fnc_getSharedGroup.sqf index 255fa9b5a..2e3477971 100644 --- a/addons/common/fnc_getSharedGroup.sqf +++ b/addons/common/fnc_getSharedGroup.sqf @@ -5,39 +5,38 @@ Description: Returns existing group on side, or newly created group when not existent. Parameters: - _side - Side to get group for [Side] + _side - Side to get group for Returns: - Group [Group] + Group Examples: (begin example) + _sharedAlliedGroup = west call CBA_fnc_getSharedGroup (end) Author: - Sickboy + Sickboy, commy2 ---------------------------------------------------------------------------- */ #include "script_component.hpp" +SCRIPT(getSharedGroup); #define SIDES [east, west, resistance, civilian, sideLogic] -params ["_side"]; - -private ["_group", "_idx", "_center"]; -_group = grpNull; -_idx = SIDES find _side; -if (_idx > - 1) then { - if (isNull (GVAR(groups) select _idx)) then { - _center = [_side] call CBA_fnc_createCenter; - _group = createGroup _center; - GVAR(groups) set [_idx, _group]; - // TODO: Evaluate if this doesn't mess things up when multiple clients are requesting groups - publicVariable QGVAR(groups); - } else { - _group = GVAR(groups) select _idx; - }; -} else { - WARNING("Illegal side parameter!"); +params [["_side", sideFriendly, [west]]]; // sideFriendly as pseudo null side, replace with sideEmpty + +private _id = SIDES find _side; + +if (_id < 0) exitWith {grpNull}; + +private _group = GVAR(groups) select _id; + +if (isNull _group) then { + _group = createGroup _side; + GVAR(groups) set [_id, _group]; + + // TODO: Evaluate if this doesn't mess things up when multiple clients are requesting groups + publicVariable QGVAR(groups); }; -_group; +_group diff --git a/addons/common/fnc_isAlive.sqf b/addons/common/fnc_isAlive.sqf index 2db7e2016..35a66a2e2 100644 --- a/addons/common/fnc_isAlive.sqf +++ b/addons/common/fnc_isAlive.sqf @@ -5,37 +5,45 @@ Description: A function used to find out if the group or object is alive. Parameters: - Array, Group or Unit + _entity - Array, Group or Unit Example: (begin example) - _alive = (Units player) call CBA_fnc_getAlive + _alive = (units player) call CBA_fnc_isAlive (end) Returns: - Boolean + Author: Rommel - ---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(isAlive); + +[_this] params [["_entity", objNull, [objNull, grpNull, []]]]; -switch (typename _this) do { +switch (typename _entity) do { case "ARRAY" : { + private _return = false; + { - if (_x call CBA_fnc_isalive) exitwith {true}; - false; - } foreach _this; + if (_x call CBA_fnc_isAlive) exitwith { + _return = true; + }; + } foreach _entity; + + _return }; case "OBJECT" : { - alive _this; + alive _entity; }; case "GROUP" : { - if (isnull (leader _this)) then { - false; + if (isnull (leader _entity)) then { + false } else { - (units _this) call CBA_fnc_isalive; + (units _entity) call CBA_fnc_isAlive }; }; - default {alive _this}; + default {}; }; diff --git a/addons/common/fnc_nearPlayer.sqf b/addons/common/fnc_nearPlayer.sqf index 639850496..c30096577 100644 --- a/addons/common/fnc_nearPlayer.sqf +++ b/addons/common/fnc_nearPlayer.sqf @@ -5,31 +5,32 @@ Description: Check whether these are any players within a certain distance of a unit. Parameters: - _unit: the unit to check the distance from. [Object] - _distance: the desired distance. [Number] + _unit - the entity to check the distance from. + _distance - the desired distance. Returns: - Boolean - true if there are any players within the given - distance of the unit, false if there aren't. - + true if there are any players within the given distance of the unit, false if there aren't. Examples: (begin example) - [unit, distance] call CBA_fnc_nearPlayer + [unit, distance] call CBA_fnc_nearPlayer (end) Author: ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(nearPlayer); -params ["_unit","_distance"]; +params [["_entity", objNull], ["_distance", 0, [0]]]; + +private _position = _entity call CBA_fnc_getPos; +private _return = false; -private "_position"; -_position = _unit call CBA_fnc_getpos; { - if ((_position distance _x) < _distance) exitWith { true }; - false; -} forEach ([] call CBA_fnc_players); + if (_position distance _x < _distance) exitWith { + _return = true; + }; +} forEach allPlayers; + +_return diff --git a/addons/common/fnc_objectRandom.sqf b/addons/common/fnc_objectRandom.sqf index 16ebfa026..3b51a94db 100644 --- a/addons/common/fnc_objectRandom.sqf +++ b/addons/common/fnc_objectRandom.sqf @@ -5,36 +5,42 @@ Description: Creates a "random" number 0-9 based on an object's velocity Parameters: - _o - an object to base the random number on. [Object] + _o - an object to base the random number on. Returns: A number between 0 and 9. Examples: (begin example) - _random = _helicopter call CBA_fnc_objectRandom; + _random = _helicopter call CBA_fnc_objectRandom; (end) Author: ---------------------------------------------------------------------------- */ - #include "script_component.hpp" SCRIPT(objectRandom); -private["_r", "_v", "_s", "_a", "_b", "_c"]; params ["_o"]; + +private ["_r", "_v", "_s", "_a", "_b", "_c"]; + _r = 0; + if !(isNull _o) then { - _v = velocity(vehicle _o); - _s = sqrt((_v select 0)^2+(_v select 1)^2+(_v select 2)^2); + _v = velocity (vehicle _o); + _s = sqrt ((_v select 0) ^ 2 + (_v select 1) ^ 2 + (_v select 2) ^ 2); if (_s > 0) then { - _a = acos((_v select 0)/_s); _b = acos((_v select 1)/_s); _c = acos((_v select 2)/_s); - _r = (_a+_b+_c)%10; - _r = _r-(_r%1); + _a = acos ((_v select 0) / _s); + _b = acos ((_v select 1) / _s); + _c = acos ((_v select 2) / _s); + + _r = (_a + _b + _c) % 10; + _r = _r - (_r % 1); } else { - _r = (getDir _o)%10; - _r = _r-(_r%1); + _r = (getDir _o) % 10; + _r = _r - (_r % 1); }; }; + _r From 8d5d50bbe1baf11299b4634607e904bbc15ba94f Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:19:40 +0100 Subject: [PATCH 09/18] add/tweak common group/mag id functions --- addons/common/fnc_currentMagazineIndex.sqf | 30 ++++++++++++++++ addons/common/fnc_getGroupIndex.sqf | 41 ++++++++-------------- addons/common/fnc_getMagazineIndex.sqf | 26 ++++++++++++++ 3 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 addons/common/fnc_currentMagazineIndex.sqf create mode 100644 addons/common/fnc_getMagazineIndex.sqf diff --git a/addons/common/fnc_currentMagazineIndex.sqf b/addons/common/fnc_currentMagazineIndex.sqf new file mode 100644 index 000000000..bd38ccb4e --- /dev/null +++ b/addons/common/fnc_currentMagazineIndex.sqf @@ -0,0 +1,30 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_currentMagazineIndex + +Description: + Finds out the magazine ID of the currently loaded magazine of given unit. + +Parameters: + _unit - Unit to check + _turret - What turret should be examined. + +Returns: + Magazine ID + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(currentMagazineIndex); + +params [["_unit", objNull, [objNull]], ["_turret", nil, [[]]]]; + +private "_magazine"; + +if (isNil "_turret") then { + _magazine = currentMagazineDetail _unit splitString "[:]"; +} else { + _magazine = (_unit currentMagazineDetailTurret _turret) splitString "[:]"; +}; + +_magazine param [count _magazine - 1, ""] diff --git a/addons/common/fnc_getGroupIndex.sqf b/addons/common/fnc_getGroupIndex.sqf index 19d1c2281..c9b9fddb8 100644 --- a/addons/common/fnc_getGroupIndex.sqf +++ b/addons/common/fnc_getGroupIndex.sqf @@ -12,40 +12,29 @@ Description: (http://www.ofpec.com/ed_depot/index_new.php?action=details&id=139&page=1&game=OFP&type=fu&cat=xyz) Parameters: - _man - Man to check [Object: "Man"] + _unit - Unit to check Returns: - Number of person in his group [Number: 1+] + Number of person in his group +Author: + ?, A3: commy2 ---------------------------------------------------------------------------- */ - #include "script_component.hpp" -#include "\x\cba\addons\strings\script_strings.hpp" - SCRIPT(getGroupIndex); -// ---------------------------------------------------------------------------- - -params ["_man"]; - -private ["_varName", "_manLabel", "_number", "_labelArray", "_groupLabelLen"]; - -// Save and remove the person's varName, so that format doesn't just show that. -_varName = vehicleVarName _man; -_man setVehicleVarName ""; +params [["_unit", objNull, [objNull]]]; -_labelArray = toArray (str _man); -_groupLabelLen = [str (group _man)] call CBA_fnc_strLen; -_number = []; +{ + // Save and remove the person's varName, so that format doesn't just show that. + private _varName = vehicleVarName _unit; + _unit setVehicleVarName ""; -// Read in all digits after the group name and colon in the full player label. -// Format of player label is ": " -for "_i" from (_groupLabelLen + 1) to ((count _labelArray) - 1) do { - if ((_labelArray select _i) == ASCII_SPACE) exitWith {}; - _number pushBack (_labelArray select _i); -}; + private _return = str _unit select [count str group _unit + 1]; + _return = (_return splitString " ") param [0, ""]; -// Go back to the original varName. -_man setVehicleVarName _varName; + // Go back to the original varName. + _unit setVehicleVarName _varName; -parseNumber (toString _number); // Return. + parseNumber _return +} call CBA_fnc_directCall diff --git a/addons/common/fnc_getMagazineIndex.sqf b/addons/common/fnc_getMagazineIndex.sqf new file mode 100644 index 000000000..3d7341741 --- /dev/null +++ b/addons/common/fnc_getMagazineIndex.sqf @@ -0,0 +1,26 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getMagazineIndex + +Description: + Finds out the magazine ID of all magazines of given type in the inventory of given unit. + +Parameters: + _unit - Unit to check + _magazine - Magazines to check + +Returns: + Magazine IDs + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(getMagazineIndex); + +params [["_unit", objNull, [objNull]], ["_magazine", "", [""]]]; + +private _displayName = getText (configFile >> "CfgMagazines" >> _magazine >> "displayName"); + +if (_displayName isEqualTo "") exitWith {[]}; + +magazinesDetail _unit select {_x find _displayName == 0} apply {_x = _x splitString "[:]"; _x select (count _x - 1)}; From 57617b4f424ad9277cc7da6b3402f853df9adf07 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:24:39 +0100 Subject: [PATCH 10/18] rewrite common misc. files --- addons/common/XEH_preStart.sqf | 2 + addons/common/fnc_onTeamColorChanged.sqf | 4 +- addons/common/fnc_synchTeamColors.sqf | 3 +- addons/common/init_functionsModule.sqf | 14 ++ addons/common/init_gauss.sqf | 194 +++++++++++------------ 5 files changed, 115 insertions(+), 102 deletions(-) diff --git a/addons/common/XEH_preStart.sqf b/addons/common/XEH_preStart.sqf index ed1160076..285774c12 100644 --- a/addons/common/XEH_preStart.sqf +++ b/addons/common/XEH_preStart.sqf @@ -1,3 +1,5 @@ #include "script_component.hpp" PREP(perFrameEngine); +PREP(onTeamColorChanged); +PREP(synchTeamColors); diff --git a/addons/common/fnc_onTeamColorChanged.sqf b/addons/common/fnc_onTeamColorChanged.sqf index 29094f452..ce19091b5 100644 --- a/addons/common/fnc_onTeamColorChanged.sqf +++ b/addons/common/fnc_onTeamColorChanged.sqf @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Internal Function: CBA_fnc_onTeamColorChanged +Internal Function: CBA_common_fnc_onTeamColorChanged Description: Assigns the units team color if it changed on the squad leaders machine. @@ -14,8 +14,8 @@ Returns: Author: BaerMitUmlaut ---------------------------------------------------------------------------- */ - #include "script_component.hpp" + params ["_unit", "_team"]; _unit assignTeam _team; diff --git a/addons/common/fnc_synchTeamColors.sqf b/addons/common/fnc_synchTeamColors.sqf index 4d93f650e..dc51271fb 100644 --- a/addons/common/fnc_synchTeamColors.sqf +++ b/addons/common/fnc_synchTeamColors.sqf @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Internal Function: CBA_fnc_synchTeamColors +Internal Function: CBA_common_fnc_synchTeamColors Description: Synchs the team colors. Does not need to be called manually. @@ -13,7 +13,6 @@ Returns: Author: BaerMitUmlaut ---------------------------------------------------------------------------- */ - #include "script_component.hpp" if (leader player == player) then { diff --git a/addons/common/init_functionsModule.sqf b/addons/common/init_functionsModule.sqf index e44e65388..35eb05a4c 100644 --- a/addons/common/init_functionsModule.sqf +++ b/addons/common/init_functionsModule.sqf @@ -1,3 +1,17 @@ +/* + * Prepare BIS functions/MP and precompile all functions we already have + * registered with it. In order to have the functions loaded early, + * we do so in the "init_functionsModule" script. However, to make sure + * everything is done properly, we also create a new BIS functions manager + * module so that the whole BIS MP and functions framework is initialised + * completely. (We need to do it this way since the BIS function manager + * defers initialisation by way of execVM:ing its init script.) + * + * Yes, there's some redundancy in that the functions will be + * loaded and preprocessed twice, but this should only occur once per mission + * and will hopefully ensure forward compatibility with future ArmA II patches. + */ + // Modified by Spooner for CBA in order to allow function initialisation // in preinit phase. diff --git a/addons/common/init_gauss.sqf b/addons/common/init_gauss.sqf index 16b44b447..ae4b3bc9a 100644 --- a/addons/common/init_gauss.sqf +++ b/addons/common/init_gauss.sqf @@ -4,119 +4,117 @@ // Brought to Arma by NWD // Used in generating normally distributed dispersion for tank shells, // canister pellets and unguided rockets. -// Called once from AllVehicles init handler. if !(isNil "CBA_GAUSS_INIT") exitWith {}; CBA_GAUSS_INIT = true; - CBA_PARAM_R = 3.44428647676; /* tabulated values for the height of the Ziggurat levels */ CBA_YTAB = [ - 1, 0.963598623011, 0.936280813353, 0.913041104253, - 0.892278506696, 0.873239356919, 0.855496407634, 0.838778928349, - 0.822902083699, 0.807732738234, 0.793171045519, 0.779139726505, - 0.765577436082, 0.752434456248, 0.739669787677, 0.727249120285, - 0.715143377413, 0.703327646455, 0.691780377035, 0.68048276891, - 0.669418297233, 0.65857233912, 0.647931876189, 0.637485254896, - 0.62722199145, 0.617132611532, 0.607208517467, 0.597441877296, - 0.587825531465, 0.578352913803, 0.569017984198, 0.559815170911, - 0.550739320877, 0.541785656682, 0.532949739145, 0.524227434628, - 0.515614886373, 0.507108489253, 0.498704867478, 0.490400854812, - 0.482193476986, 0.47407993601, 0.466057596125, 0.458123971214, - 0.450276713467, 0.442513603171, 0.434832539473, 0.427231532022, - 0.419708693379, 0.41226223212, 0.404890446548, 0.397591718955, - 0.390364510382, 0.383207355816, 0.376118859788, 0.369097692334, - 0.362142585282, 0.355252328834, 0.348425768415, 0.341661801776, - 0.334959376311, 0.328317486588, 0.321735172063, 0.31521151497, - 0.308745638367, 0.302336704338, 0.29598391232, 0.289686497571, - 0.283443729739, 0.27725491156, 0.271119377649, 0.265036493387, - 0.259005653912, 0.253026283183, 0.247097833139, 0.241219782932, - 0.235391638239, 0.229612930649, 0.223883217122, 0.218202079518, - 0.212569124201, 0.206983981709, 0.201446306496, 0.195955776745, - 0.190512094256, 0.185114984406, 0.179764196185, 0.174459502324, - 0.169200699492, 0.1639876086, 0.158820075195, 0.153697969964, - 0.148621189348, 0.143589656295, 0.138603321143, 0.133662162669, - 0.128766189309, 0.123915440582, 0.119109988745, 0.114349940703, - 0.10963544023, 0.104966670533, 0.100343857232, 0.0957672718266, - 0.0912372357329, 0.0867541250127, 0.082318375932, 0.0779304915295, - 0.0735910494266, 0.0693007111742, 0.065060233529, 0.0608704821745, - 0.056732448584, 0.05264727098, 0.0486162607163, 0.0446409359769, - 0.0407230655415, 0.0368647267386, 0.0330683839378, 0.0293369977411, - 0.0256741818288, 0.0220844372634, 0.0185735200577, 0.0151490552854, - 0.0118216532614, 0.00860719483079, 0.00553245272614, 0.00265435214565 + 1, 0.963598623011, 0.936280813353, 0.913041104253, + 0.892278506696, 0.873239356919, 0.855496407634, 0.838778928349, + 0.822902083699, 0.807732738234, 0.793171045519, 0.779139726505, + 0.765577436082, 0.752434456248, 0.739669787677, 0.727249120285, + 0.715143377413, 0.703327646455, 0.691780377035, 0.68048276891, + 0.669418297233, 0.65857233912, 0.647931876189, 0.637485254896, + 0.62722199145, 0.617132611532, 0.607208517467, 0.597441877296, + 0.587825531465, 0.578352913803, 0.569017984198, 0.559815170911, + 0.550739320877, 0.541785656682, 0.532949739145, 0.524227434628, + 0.515614886373, 0.507108489253, 0.498704867478, 0.490400854812, + 0.482193476986, 0.47407993601, 0.466057596125, 0.458123971214, + 0.450276713467, 0.442513603171, 0.434832539473, 0.427231532022, + 0.419708693379, 0.41226223212, 0.404890446548, 0.397591718955, + 0.390364510382, 0.383207355816, 0.376118859788, 0.369097692334, + 0.362142585282, 0.355252328834, 0.348425768415, 0.341661801776, + 0.334959376311, 0.328317486588, 0.321735172063, 0.31521151497, + 0.308745638367, 0.302336704338, 0.29598391232, 0.289686497571, + 0.283443729739, 0.27725491156, 0.271119377649, 0.265036493387, + 0.259005653912, 0.253026283183, 0.247097833139, 0.241219782932, + 0.235391638239, 0.229612930649, 0.223883217122, 0.218202079518, + 0.212569124201, 0.206983981709, 0.201446306496, 0.195955776745, + 0.190512094256, 0.185114984406, 0.179764196185, 0.174459502324, + 0.169200699492, 0.1639876086, 0.158820075195, 0.153697969964, + 0.148621189348, 0.143589656295, 0.138603321143, 0.133662162669, + 0.128766189309, 0.123915440582, 0.119109988745, 0.114349940703, + 0.10963544023, 0.104966670533, 0.100343857232, 0.0957672718266, + 0.0912372357329, 0.0867541250127, 0.082318375932, 0.0779304915295, + 0.0735910494266, 0.0693007111742, 0.065060233529, 0.0608704821745, + 0.056732448584, 0.05264727098, 0.0486162607163, 0.0446409359769, + 0.0407230655415, 0.0368647267386, 0.0330683839378, 0.0293369977411, + 0.0256741818288, 0.0220844372634, 0.0185735200577, 0.0151490552854, + 0.0118216532614, 0.00860719483079, 0.00553245272614, 0.00265435214565 ]; /* tabulated values for 2^24 times x[i]/x[i+1], * used to accept for U*x[i+1]<= x[i] without any floating point operations */ CBA_KTAB = [ - 0, 12590644, 14272653, 14988939, - 15384584, 15635009, 15807561, 15933577, - 16029594, 16105155, 16166147, 16216399, - 16258508, 16294295, 16325078, 16351831, - 16375291, 16396026, 16414479, 16431002, - 16445880, 16459343, 16471578, 16482744, - 16492970, 16502368, 16511031, 16519039, - 16526459, 16533352, 16539769, 16545755, - 16551348, 16556584, 16561493, 16566101, - 16570433, 16574511, 16578353, 16581977, - 16585398, 16588629, 16591685, 16594575, - 16597311, 16599901, 16602354, 16604679, - 16606881, 16608968, 16610945, 16612818, - 16614592, 16616272, 16617861, 16619363, - 16620782, 16622121, 16623383, 16624570, - 16625685, 16626730, 16627708, 16628619, - 16629465, 16630248, 16630969, 16631628, - 16632228, 16632768, 16633248, 16633671, - 16634034, 16634340, 16634586, 16634774, - 16634903, 16634972, 16634980, 16634926, - 16634810, 16634628, 16634381, 16634066, - 16633680, 16633222, 16632688, 16632075, - 16631380, 16630598, 16629726, 16628757, - 16627686, 16626507, 16625212, 16623794, - 16622243, 16620548, 16618698, 16616679, - 16614476, 16612071, 16609444, 16606571, - 16603425, 16599973, 16596178, 16591995, - 16587369, 16582237, 16576520, 16570120, - 16562917, 16554758, 16545450, 16534739, - 16522287, 16507638, 16490152, 16468907, - 16442518, 16408804, 16364095, 16301683, - 16207738, 16047994, 15704248, 15472926 + 0, 12590644, 14272653, 14988939, + 15384584, 15635009, 15807561, 15933577, + 16029594, 16105155, 16166147, 16216399, + 16258508, 16294295, 16325078, 16351831, + 16375291, 16396026, 16414479, 16431002, + 16445880, 16459343, 16471578, 16482744, + 16492970, 16502368, 16511031, 16519039, + 16526459, 16533352, 16539769, 16545755, + 16551348, 16556584, 16561493, 16566101, + 16570433, 16574511, 16578353, 16581977, + 16585398, 16588629, 16591685, 16594575, + 16597311, 16599901, 16602354, 16604679, + 16606881, 16608968, 16610945, 16612818, + 16614592, 16616272, 16617861, 16619363, + 16620782, 16622121, 16623383, 16624570, + 16625685, 16626730, 16627708, 16628619, + 16629465, 16630248, 16630969, 16631628, + 16632228, 16632768, 16633248, 16633671, + 16634034, 16634340, 16634586, 16634774, + 16634903, 16634972, 16634980, 16634926, + 16634810, 16634628, 16634381, 16634066, + 16633680, 16633222, 16632688, 16632075, + 16631380, 16630598, 16629726, 16628757, + 16627686, 16626507, 16625212, 16623794, + 16622243, 16620548, 16618698, 16616679, + 16614476, 16612071, 16609444, 16606571, + 16603425, 16599973, 16596178, 16591995, + 16587369, 16582237, 16576520, 16570120, + 16562917, 16554758, 16545450, 16534739, + 16522287, 16507638, 16490152, 16468907, + 16442518, 16408804, 16364095, 16301683, + 16207738, 16047994, 15704248, 15472926 ]; /* tabulated values of 2^{ -24 }*x[i] */ CBA_WTAB = [ - 1.62318314817e-08, 2.16291505214e-08, 2.54246305087e-08, 2.84579525938e-08, - 3.10340022482e-08, 3.33011726243e-08, 3.53439060345e-08, 3.72152672658e-08, - 3.8950989572e-08, 4.05763964764e-08, 4.21101548915e-08, 4.35664624904e-08, - 4.49563968336e-08, 4.62887864029e-08, 4.75707945735e-08, 4.88083237257e-08, - 5.00063025384e-08, 5.11688950428e-08, 5.22996558616e-08, 5.34016475624e-08, - 5.44775307871e-08, 5.55296344581e-08, 5.65600111659e-08, 5.75704813695e-08, - 5.85626690412e-08, 5.95380306862e-08, 6.04978791776e-08, 6.14434034901e-08, - 6.23756851626e-08, 6.32957121259e-08, 6.42043903937e-08, 6.51025540077e-08, - 6.59909735447e-08, 6.68703634341e-08, 6.77413882848e-08, 6.8604668381e-08, - 6.94607844804e-08, 7.03102820203e-08, 7.11536748229e-08, 7.1991448372e-08, - 7.2824062723e-08, 7.36519550992e-08, 7.44755422158e-08, 7.52952223703e-08, - 7.61113773308e-08, 7.69243740467e-08, 7.77345662086e-08, 7.85422956743e-08, - 7.93478937793e-08, 8.01516825471e-08, 8.09539758128e-08, 8.17550802699e-08, - 8.25552964535e-08, 8.33549196661e-08, 8.41542408569e-08, 8.49535474601e-08, - 8.57531242006e-08, 8.65532538723e-08, 8.73542180955e-08, 8.8156298059e-08, - 8.89597752521e-08, 8.97649321908e-08, 9.05720531451e-08, 9.138142487e-08, - 9.21933373471e-08, 9.30080845407e-08, 9.38259651738e-08, 9.46472835298e-08, - 9.54723502847e-08, 9.63014833769e-08, 9.71350089201e-08, 9.79732621669e-08, - 9.88165885297e-08, 9.96653446693e-08, 1.00519899658e-07, 1.0138063623e-07, - 1.02247952126e-07, 1.03122261554e-07, 1.04003996769e-07, 1.04893609795e-07, - 1.05791574313e-07, 1.06698387725e-07, 1.07614573423e-07, 1.08540683296e-07, - 1.09477300508e-07, 1.1042504257e-07, 1.11384564771e-07, 1.12356564007e-07, - 1.13341783071e-07, 1.14341015475e-07, 1.15355110887e-07, 1.16384981291e-07, - 1.17431607977e-07, 1.18496049514e-07, 1.19579450872e-07, 1.20683053909e-07, - 1.21808209468e-07, 1.2295639141e-07, 1.24129212952e-07, 1.25328445797e-07, - 1.26556042658e-07, 1.27814163916e-07, 1.29105209375e-07, 1.30431856341e-07, - 1.31797105598e-07, 1.3320433736e-07, 1.34657379914e-07, 1.36160594606e-07, - 1.37718982103e-07, 1.39338316679e-07, 1.41025317971e-07, 1.42787873535e-07, - 1.44635331499e-07, 1.4657889173e-07, 1.48632138436e-07, 1.50811780719e-07, - 1.53138707402e-07, 1.55639532047e-07, 1.58348931426e-07, 1.61313325908e-07, - 1.64596952856e-07, 1.68292495203e-07, 1.72541128694e-07, 1.77574279496e-07, - 1.83813550477e-07, 1.92166040885e-07, 2.05295471952e-07, 2.22600839893e-07 + 1.62318314817e-08, 2.16291505214e-08, 2.54246305087e-08, 2.84579525938e-08, + 3.10340022482e-08, 3.33011726243e-08, 3.53439060345e-08, 3.72152672658e-08, + 3.8950989572e-08, 4.05763964764e-08, 4.21101548915e-08, 4.35664624904e-08, + 4.49563968336e-08, 4.62887864029e-08, 4.75707945735e-08, 4.88083237257e-08, + 5.00063025384e-08, 5.11688950428e-08, 5.22996558616e-08, 5.34016475624e-08, + 5.44775307871e-08, 5.55296344581e-08, 5.65600111659e-08, 5.75704813695e-08, + 5.85626690412e-08, 5.95380306862e-08, 6.04978791776e-08, 6.14434034901e-08, + 6.23756851626e-08, 6.32957121259e-08, 6.42043903937e-08, 6.51025540077e-08, + 6.59909735447e-08, 6.68703634341e-08, 6.77413882848e-08, 6.8604668381e-08, + 6.94607844804e-08, 7.03102820203e-08, 7.11536748229e-08, 7.1991448372e-08, + 7.2824062723e-08, 7.36519550992e-08, 7.44755422158e-08, 7.52952223703e-08, + 7.61113773308e-08, 7.69243740467e-08, 7.77345662086e-08, 7.85422956743e-08, + 7.93478937793e-08, 8.01516825471e-08, 8.09539758128e-08, 8.17550802699e-08, + 8.25552964535e-08, 8.33549196661e-08, 8.41542408569e-08, 8.49535474601e-08, + 8.57531242006e-08, 8.65532538723e-08, 8.73542180955e-08, 8.8156298059e-08, + 8.89597752521e-08, 8.97649321908e-08, 9.05720531451e-08, 9.138142487e-08, + 9.21933373471e-08, 9.30080845407e-08, 9.38259651738e-08, 9.46472835298e-08, + 9.54723502847e-08, 9.63014833769e-08, 9.71350089201e-08, 9.79732621669e-08, + 9.88165885297e-08, 9.96653446693e-08, 1.00519899658e-07, 1.0138063623e-07, + 1.02247952126e-07, 1.03122261554e-07, 1.04003996769e-07, 1.04893609795e-07, + 1.05791574313e-07, 1.06698387725e-07, 1.07614573423e-07, 1.08540683296e-07, + 1.09477300508e-07, 1.1042504257e-07, 1.11384564771e-07, 1.12356564007e-07, + 1.13341783071e-07, 1.14341015475e-07, 1.15355110887e-07, 1.16384981291e-07, + 1.17431607977e-07, 1.18496049514e-07, 1.19579450872e-07, 1.20683053909e-07, + 1.21808209468e-07, 1.2295639141e-07, 1.24129212952e-07, 1.25328445797e-07, + 1.26556042658e-07, 1.27814163916e-07, 1.29105209375e-07, 1.30431856341e-07, + 1.31797105598e-07, 1.3320433736e-07, 1.34657379914e-07, 1.36160594606e-07, + 1.37718982103e-07, 1.39338316679e-07, 1.41025317971e-07, 1.42787873535e-07, + 1.44635331499e-07, 1.4657889173e-07, 1.48632138436e-07, 1.50811780719e-07, + 1.53138707402e-07, 1.55639532047e-07, 1.58348931426e-07, 1.61313325908e-07, + 1.64596952856e-07, 1.68292495203e-07, 1.72541128694e-07, 1.77574279496e-07, + 1.83813550477e-07, 1.92166040885e-07, 2.05295471952e-07, 2.22600839893e-07 ]; From 86d042339a503e5f450f8f69ea162f7f992c840d Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:25:15 +0100 Subject: [PATCH 11/18] common rewrite pre, post init --- addons/common/XEH_postInit.sqf | 28 +++---- addons/common/XEH_preInit.sqf | 127 ++++--------------------------- addons/common/backwards_comp.sqf | 36 +++++++++ 3 files changed, 63 insertions(+), 128 deletions(-) create mode 100644 addons/common/backwards_comp.sqf diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 7a012d410..31661b659 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -18,6 +18,13 @@ SLX_XEH_STR spawn { #endif }; +FUNC(log) = { + diag_log text _this; + sleep 1; + systemChat _this; + hintC _this; +}; + // A2 / Operation Arrowhead, standalone / combined operations check /* TRACE_1("OA Check",nil); @@ -73,22 +80,15 @@ if (_oldPFH && {!CBA_MISSION_START}) then { _oldPFH call FUNC(initPerFrameHandlers); }; -// TODO: Consider a waitUntil loop with tickTime check to wait for some frames as opposed to trying to sleep until time > 0. Re MP Briefings etc. -/* -[CBA_COMMON_ADDONS] spawn { - params ["_addons"]; - TRACE_1("Activating addons",nil); - activateAddons _addons; - sleep 0.001; - if (SLX_XEH_MACHINE select 1) then { sleep 0.001 }; // JIP, sleep uses time, and time skips for JIP. - TRACE_1("Activating addons",nil); - activateAddons _addons; -}; -*/ +// system to synch team colors +PREP(onTeamColorChanged); +PREP(synchTeamColors); + +["CBA_teamColorChanged", FUNC(onTeamColorChanged)] call CBA_fnc_addEventHandler; -["CBA_teamColorChanged", CBA_fnc_onTeamColorChanged] call CBA_fnc_addEventHandler; if (hasInterface) then { - [CBA_fnc_synchTeamColors, 1, []] call CBA_fnc_addPerFrameHandler; + [FUNC(synchTeamColors), 1, []] call CBA_fnc_addPerFrameHandler; + if (didJIP) then { private "_team"; { diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 63fd3d057..2682d52c1 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -1,134 +1,33 @@ -// Any registered functions used in the PreINIT phase must use the uiNamespace copies of the variable. -// So uiNamespace getVariable "CBA_fnc_hashCreate" instead of just CBA_fnc_hashCreate -VM //#define DEBUG_MODE_FULL #include "script_component.hpp" SCRIPT(XEH_preInit); -/* - * Prepare BIS functions/MP and precompile all functions we already have - * registered with it. In order to have the functions loaded early, - * we do so in the "init_functionsModule" script. However, to make sure - * everything is done properly, we also create a new BIS functions manager - * module so that the whole BIS MP and functions framework is initialised - * completely. (We need to do it this way since the BIS function manager - * defers initialisation by way of execVM:ing its init script.) - * - * Yes, there's some redundancy in that the functions will be - * loaded and preprocessed twice, but this should only occur once per mission - * and will hopefully ensure forward compatibility with future ArmA II patches. - */ +[] call COMPILE_FILE(init_functionsModule); // @todo -/* -if (isNil "RE" && isNil "BIS_MPF_logic") then -{ - LOG("Initialising the MP module early."); - _this call COMPILE_FILE2(\ca\Modules\MP\data\scripts\MPframework.sqf); -}; -*/ - -[] call COMPILE_FILE(init_functionsModule); LOG(MSG_INIT); -// if (true) exitWith {}; ADDON = false; -CBA_nil = [nil]; -GVAR(centers) = []; -CBA_actionHelper = QUOTE(PATHTO(actionHelper)); -GVAR(delayless) = QUOTE(PATHTOF(delayless.fsm)); -GVAR(delayless_loop) = QUOTE(PATHTOF(delayless_loop.fsm)); - -// DirectCall, using single-frame-code-executioner -// The directCall function will execute (with parameters) next frame, and without delay -// [[1,2,3], {mycode to execute}] call FUNC(directCall); -// _obj = [[1,2,3], {mycode to execute}] call FUNC(directCall); waitUntil {isNull _obj}; // waits until the code has completed -FUNC(directCall) = { - private "_o"; - params ["_params","_code"]; - _o = SLX_XEH_DUMMY createVehicleLocal [0, 0, 0]; - ["CBA_DC", "onEachFrame", { - params ["_args", "_code", "_o"]; - _args call _code; - _o setDamage 1; - ["CBA_DC", "onEachFrame"] call BIS_fnc_removeStackedEventHandler; - }, [_params, _code, _o]] call BIS_fnc_addStackedEventHandler; - _o -}; - CBA_logic = objNull; -FUNC(log) = { - diag_log text _this; - sleep 1; - CBA_logic globalChat _this; - hintC _this; -}; - -// Nil check -ISNILS(CBA_NIL_CHECKED,false); - -// Prepare all functions -DEPRECATE(fAddMagazine,fnc_addMagazine); -DEPRECATE(fAddMagazineCargo,fnc_addMagazineCargo); -DEPRECATE(fAddWeapon,fnc_addWeapon); -DEPRECATE(fAddWeaponCargo,fnc_addWeaponCargo); -DEPRECATE(fDetermineMuzzles,fnc_determineMuzzles); -DEPRECATE(fDropMagazine,fnc_dropMagazine); -DEPRECATE(fDropWeapon,fnc_dropWeapon); -DEPRECATE(fGetAnimType,fnc_getAnimType); -DEPRECATE(fGetConfigEntry,fnc_getConfigEntry); -DEPRECATE(fGetPistol,fnc_getPistol); -DEPRECATE(fGetUnitAnim,fnc_getUnitAnim); -DEPRECATE(fGetUnitDeathAnim,fnc_getUnitDeathAnim); -DEPRECATE(fGetVehicleAnim,fnc_isTurnedOut); -DEPRECATE(fHeadDir,fnc_headDir); - -OBSOLETE(fMyWeapon,{ currentWeapon player }); - -DEPRECATE(fObjectRandom,fnc_objectRandom); -DEPRECATE(fPlayers,fnc_players); -DEPRECATE(fRealHeight,fnc_realHeight); -DEPRECATE(fRemoveMagazine,fnc_removeMagazine); -DEPRECATE(fRemoveWeapon,fnc_removeWeapon); - -OBSOLETE(fSelectedWeapon,{ currentWeapon _this }); - -DEPRECATE_SYS(DOUBLES(PREFIX,fVectorSum3d),BIS_fnc_vectorAdd); - -DEPRECATE(fAddMagazineVerified,fnc_addMagazineVerified); -DEPRECATE(fCreateMarker,fnc_createMarker); -DEPRECATE(fCreateTrigger,fnc_createTrigger); -DEPRECATE(fGetArg,fnc_getArg); -DEPRECATE(fInheritsFrom,fnc_inheritsFrom); -DEPRECATE(fNearPlayer,fnc_nearPlayer); - -DEPRECATE_SYS(DOUBLES(PREFIX,fRndInt),BIS_fnc_randomInt); -DEPRECATE_SYS(DOUBLES(PREFIX,fRndSelect),BIS_fnc_selectRandom); - -DEPRECATE(fSelectWeapon,fnc_selectWeapon); -DEPRECATE(fShuffle,fnc_shuffle); -DEPRECATE(fSwitchPlayer,fnc_switchPlayer); +// FSM +GVAR(delayless) = QUOTE(PATHTOF(delayless.fsm)); +GVAR(delayless_loop) = QUOTE(PATHTOF(delayless_loop.fsm)); // Initialize Components GVAR(groups) = [grpNull, grpNull, grpNull, grpNull, grpNull]; -call COMPILE_FILE(init_gauss); -call COMPILE_FILE(init_kron_strings); - -OBSOLETE_SYS(KRON_StrUpper,{ toUpper (_this select 0) }); -OBSOLETE_SYS(KRON_StrLower,{ toLower (_this select 0) }); -DEPRECATE_SYS(KRON_StrIndex,DOUBLES(PREFIX,fnc_find)); // CBA_fnc_find does the same and more. -DEPRECATE_SYS(KRON_StrLen,DOUBLES(PREFIX,fnc_strLen)); -DEPRECATE_SYS(KRON_StrToArray,DOUBLES(PREFIX,fnc_split)); // CBA_fnc_split does the same and more. -DEPRECATE_SYS(KRON_Replace,DOUBLES(PREFIX,fnc_replace)); // KRON is faster, but CBA one is 1 line (reuses other functions). - -call COMPILE_FILE(init_tables); +call COMPILE_FILE(init_gauss); call COMPILE_FILE(init_perFrameHandler); +call COMPILE_FILE(init_delayLess); -// NOTE: Due to activateAddons being overwritten by eachother (only the last executed command will be active), we apply this bandaid -call COMPILE_FILE(init_addons); +// Due to activateAddons being overwritten by eachother (only the last executed command will be active), we apply this bandaid +private _addons = ("true" configClasses (configFile >> "CfgPatches")) apply {configName _x}; -call COMPILE_FILE(init_delayLess); +activateAddons _addons; +GVAR(addons) = _addons; + +// BWC +#include "backwards_comp.sqf" -// Announce Initialization Complete ADDON = true; diff --git a/addons/common/backwards_comp.sqf b/addons/common/backwards_comp.sqf new file mode 100644 index 000000000..a8404d4c6 --- /dev/null +++ b/addons/common/backwards_comp.sqf @@ -0,0 +1,36 @@ + +CBA_fnc_createCenter = {_this}; +CBA_fnc_players = {allPlayers}; +CBA_fnc_locked = {locked _this > 1}; + +CBA_fnc_getPistol = { + params [["_unit", objNull, [objNull]]]; + handgunWeapon _unit +}; + +CBA_fnc_systemChat = { + params [["_message", "", [""]]]; + systemChat _message; +}; + +CBA_fnc_defaultParam = { + params [["_params", []], ["_index", -2, [0]], "_defaultValue"]; + _params param [_index, _defaultValue] +}; + +CBA_fnc_determineMuzzles = CBA_fnc_getMuzzles; + +CBA_fnc_addWeaponCargoGlobal = CBA_fnc_addWeaponCargo; +CBA_fnc_addMagazineCargoGlobal = CBA_fnc_addMagazineCargo; +CBA_fnc_removeWeaponCargoGlobal = CBA_fnc_removeWeaponCargo; +CBA_fnc_removeMagazineCargoGlobal = CBA_fnc_removeMagazineCargo; +CBA_fnc_removeItemCargoGlobal = CBA_fnc_removeItemCargo; +CBA_fnc_removeBackpackCargoGlobal = CBA_fnc_removeBackpackCargo; + +FUNC(directCall) = CBA_fnc_directCall; + +CBA_fnc_intToString = { + params [["_int", nil, [0]]]; + if (isNil "_int") exitWith {""}; + str _int +}; From f892ec858a676c4a825556605b3c1a436c89fabe Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:25:42 +0100 Subject: [PATCH 12/18] common rewrite cfgFunctions --- addons/common/CfgFunctions.hpp | 645 ++++++--------------------------- 1 file changed, 114 insertions(+), 531 deletions(-) diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 22c945d99..d91b31eac 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -1,538 +1,121 @@ -// ----------------------------------------------------------------------------- -// Automatically generated by 'functions_config.rb' -// DO NOT MANUALLY EDIT THIS FILE! -// ----------------------------------------------------------------------------- -class CfgFunctions -{ - class CBA - { - class Misc - { - // CBA_fnc_actionArgument - class actionArgument - { - description = "Used to call the code parsed in the addaction argument."; - file = "\x\cba\addons\common\fnc_actionArgument.sqf"; - }; - // CBA_fnc_addMagazine - class addMagazine - { - description = "Add magazine to a vehicle/unit."; - file = "\x\cba\addons\common\fnc_addMagazine.sqf"; - }; - // CBA_fnc_addMagazineCargo - class addMagazineCargo - { - description = "Add magazine(s) to a vehicle's cargo."; - file = "\x\cba\addons\common\fnc_addMagazineCargo.sqf"; - }; - // CBA_fnc_addMagazineCargoGlobal - class addMagazineCargoGlobal - { - description = "Add magazine(s) to a vehicle's cargo. MP synchronized."; - file = "\x\cba\addons\common\fnc_addMagazineCargoGlobal.sqf"; - }; - // CBA_fnc_addMagazineVerified - class addMagazineVerified - { - description = "Add magazines to the unit, but verify that it was successful and doesn't over-burden the recipient."; - file = "\x\cba\addons\common\fnc_addMagazineVerified.sqf"; - }; - // CBA_fnc_addPerFrameHandler - class addPerFrameHandler - { - description = "Add a handler that will execute every frame, or every x number of seconds."; - file = "\x\cba\addons\common\fnc_addPerFrameHandler.sqf"; - }; - // CBA_fnc_addPlayerAction - class addPlayerAction - { - description = "Adds persistent action to player (which will also be available in vehicles and after respawn or teamswitch)."; - file = "\x\cba\addons\common\fnc_addPlayerAction.sqf"; - }; - // CBA_fnc_addWeapon - class addWeapon - { - description = "Add a weapon to a unit."; - file = "\x\cba\addons\common\fnc_addWeapon.sqf"; - }; - // CBA_fnc_addWeaponCargo - class addWeaponCargo - { - description = "Add weapon(s) to vehicle cargo."; - file = "\x\cba\addons\common\fnc_addWeaponCargo.sqf"; - }; - // CBA_fnc_addWeaponCargoGlobal - class addWeaponCargoGlobal - { - description = "Add weapon(s) to vehicle cargo. MP synchronized."; - file = "\x\cba\addons\common\fnc_addWeaponCargoGlobal.sqf"; - }; - // CBA_fnc_canUseWeapon - class canUseWeapon - { - description = "Checks if the unit can currently use a weapon."; - file = "\x\cba\addons\common\fnc_canUseWeapon.sqf"; - }; - // CBA_fnc_createCenter - class createCenter - { - description = "Selects center if it already exists, creates it if it doesn't yet."; - file = "\x\cba\addons\common\fnc_createCenter.sqf"; - }; - // CBA_fnc_createMarker - class createMarker - { - description = "Creates a marker all at once."; - file = "\x\cba\addons\common\fnc_createMarker.sqf"; - }; - // CBA_fnc_createNamespace - class createNamespace - { - description = "Creates a namespace. Used to store and read variables via setVariable and getVariable."; - file = "\x\cba\addons\common\fnc_createNamespace.sqf"; - }; - // CBA_fnc_createTrigger - class createTrigger - { - description = "Create a trigger all at once."; - file = "\x\cba\addons\common\fnc_createTrigger.sqf"; - }; - // CBA_fnc_defaultParam - class defaultParam - { - description = "Gets a value from parameters list (usually _this) with a default."; - file = "\x\cba\addons\common\fnc_defaultParam.sqf"; - }; - // CBA_fnc_deleteEntity - class deleteEntity - { - description = "A function used to delete entities"; - file = "\x\cba\addons\common\fnc_deleteEntity.sqf"; - }; - // CBA_fnc_deleteNamespace - class deleteNamespace - { - description = "Deletes a namespace created with CBA_fnc_createNamespace."; - file = "\x\cba\addons\common\fnc_deleteNamespace.sqf"; - }; - // CBA_fnc_determineMuzzles - class determineMuzzles - { - description = "Gets the list of possible muzzles for a weapon."; - file = "\x\cba\addons\common\fnc_determineMuzzles.sqf"; - }; - // CBA_fnc_directCall - class directCall - { - description = "Executes a piece of code in unscheduled environment."; - file = "\x\cba\addons\common\fnc_directCall.sqf"; - }; - // CBA_fnc_dropMagazine - class dropMagazine - { - description = "Drop a magazine."; - file = "\x\cba\addons\common\fnc_dropMagazine.sqf"; - }; - // CBA_fnc_dropWeapon - class dropWeapon - { - description = "Drops a weapon."; - file = "\x\cba\addons\common\fnc_dropWeapon.sqf"; - }; - // CBA_fnc_findEntity - class findEntity - { - description = "A function used to find out the first entity of parsed type in a nearEntitys call"; - file = "\x\cba\addons\common\fnc_findEntity.sqf"; - }; - // CBA_fnc_getAlive - class getAlive - { - description = "A function used to find out who is alive in an array or a group."; - file = "\x\cba\addons\common\fnc_getAlive.sqf"; - }; - // CBA_fnc_getAnimType - class getAnimType - { - description = "Used to determine which weapon unit is currently holding and return proper animation type."; - file = "\x\cba\addons\common\fnc_getAnimType.sqf"; - }; - // CBA_fnc_getArg - class getArg - { - description = "Get default named argument from list."; - file = "\x\cba\addons\common\fnc_getArg.sqf"; - }; - // CBA_fnc_getAspectRatio - class getAspectRatio - { - description = "Used to determine the Aspect ratio of the screen."; - file = "\x\cba\addons\common\fnc_getAspectRatio.sqf"; - }; - // CBA_fnc_getConfigEntry - class getConfigEntry - { - description = "Gets a configuration entry."; - file = "\x\cba\addons\common\fnc_getConfigEntry.sqf"; - }; - // CBA_fnc_getDistance - class getDistance - { - description = "A function used to find out the distance between two positions."; - file = "\x\cba\addons\common\fnc_getDistance.sqf"; - }; - // CBA_fnc_getFirer - class getFirer - { - description = "A function used to find out which unit exactly fired (Replacement for gunner, on multi-turret vehicles)."; - file = "\x\cba\addons\common\fnc_getFirer.sqf"; - }; - // CBA_fnc_getFov - class getFov - { - description = "Get current camera's field of view in radians and zoom."; - file = "\x\cba\addons\common\fnc_getFov.sqf"; - }; - // CBA_fnc_getGroup - class getGroup - { - description = "A function used to find out the group of an object."; - file = "\x\cba\addons\common\fnc_getGroup.sqf"; - }; - // CBA_fnc_getGroupIndex - class getGroupIndex - { - description = "Finds out the actual ID number of a person within his group as assigned by the game and used in the squad leader's command menu."; - file = "\x\cba\addons\common\fnc_getGroupIndex.sqf"; - }; - // CBA_fnc_getNearest - class getNearest - { - description = "A function used to find out the nearest entity parsed in an array to a position. Compares the distance between entity's in the parsed array."; - file = "\x\cba\addons\common\fnc_getNearest.sqf"; - }; - // CBA_fnc_getNearestBuilding - class getNearestBuilding - { - description = "A function used to find out the nearest building and appropriate building positions available."; - file = "\x\cba\addons\common\fnc_getNearestBuilding.sqf"; - }; - // CBA_fnc_getPistol - class getPistol - { - description = "Returns name of pistol in unit's inventory, if any."; - file = "\x\cba\addons\common\fnc_getPistol.sqf"; - }; - // CBA_fnc_getPos - class getPos - { - description = "A function used to get the position of an entity."; - file = "\x\cba\addons\common\fnc_getPos.sqf"; - }; - // CBA_fnc_getSharedGroup - class getSharedGroup - { - description = "Returns existing group on side, or newly created group when not existent."; - file = "\x\cba\addons\common\fnc_getSharedGroup.sqf"; - }; - // CBA_fnc_getTerrainProfile - class getTerrainProfile - { - description = "A function used to find the terrain profile between two positions"; - file = "\x\cba\addons\common\fnc_getTerrainProfile.sqf"; - }; - // CBA_fnc_getTurret - class getTurret - { - description = "A function used to find out which config turret is turretpath."; - file = "\x\cba\addons\common\fnc_getTurret.sqf"; - }; - // CBA_fnc_getUISize - class getUISize - { - description = "Used to determine the UI size of the screen."; - file = "\x\cba\addons\common\fnc_getUISize.sqf"; - }; - // CBA_fnc_getUnitAnim - class getUnitAnim - { - description = "Get information about a unit's stance and speed."; - file = "\x\cba\addons\common\fnc_getUnitAnim.sqf"; - }; - // CBA_fnc_getUnitDeathAnim - class getUnitDeathAnim - { - description = "Get death animation for a unit."; - file = "\x\cba\addons\common\fnc_getUnitDeathAnim.sqf"; - }; - // CBA_fnc_getVolume - class getVolume - { - description = "Return the volume of an object based on the object's model's bounding box."; - file = "\x\cba\addons\common\fnc_getVolume.sqf"; - }; - // CBA_fnc_headDir - class headDir - { - description = "Get the direction of a unit's head."; - file = "\x\cba\addons\common\fnc_headDir.sqf"; - }; - // CBA_fnc_inArea - class inArea - { - description = "A function used to determine if a position is within a zone."; - file = "\x\cba\addons\common\fnc_inArea.sqf"; - }; - // CBA_fnc_inheritsFrom - class inheritsFrom - { - description = "Checks whether a config entry inherits, directly or indirectly, from another one."; - file = "\x\cba\addons\common\fnc_inheritsFrom.sqf"; - }; - // CBA_fnc_intToString - class intToString - { - description = "Faster int to string, uses an integer lookup table if possible"; - file = "\x\cba\addons\common\fnc_intToString.sqf"; - }; - // CBA_fnc_isAlive - class isAlive - { - description = "A function used to find out if the group or object is alive."; - file = "\x\cba\addons\common\fnc_isAlive.sqf"; - }; - // CBA_fnc_isPerson - class isPerson - { - description = "Checks if an object is a person - soldier or civilian."; - file = "\x\cba\addons\common\fnc_isPerson.sqf"; - }; - // CBA_fnc_isTurnedOut - class isTurnedOut - { - description = "Checks whether a unit is turned out in a vehicle or not."; - file = "\x\cba\addons\common\fnc_isTurnedOut.sqf"; - }; - // CBA_fnc_isUnitGetOutAnim - class isUnitGetOutAnim - { - description = "Checks whether a unit is turned out in a vehicle or not."; - file = "\x\cba\addons\common\fnc_isUnitGetOutAnim.sqf"; - }; - // CBA_fnc_locked - class locked - { - description = "A2/OA/TOH compatible locked function."; - file = "\x\cba\addons\common\fnc_locked.sqf"; - }; - // CBA_fnc_mapDirTo - class mapDirTo - { - description = "Gets the direction between two map grid references."; - file = "\x\cba\addons\common\fnc_mapDirTo.sqf"; - }; - // CBA_fnc_mapGridToPos - class mapGridToPos - { - description = "Converts a 2, 4, 6, 8, or 10 digit grid reference into a Position."; - file = "\x\cba\addons\common\fnc_mapGridToPos.sqf"; - }; - // CBA_fnc_mapRelPos - class mapRelPos - { - description = "Find a position relative to a known position on the map. Passing strings in for the Northing and Easting is the preferred way."; - file = "\x\cba\addons\common\fnc_mapRelPos.sqf"; - }; - // CBA_fnc_modelHeadDir - class modelHeadDir - { - description = "Get the direction of any unit's head."; - file = "\x\cba\addons\common\fnc_modelHeadDir.sqf"; - }; - // CBA_fnc_nearPlayer - class nearPlayer - { - description = "Check whether these are any players within a certain distance of a unit."; - file = "\x\cba\addons\common\fnc_nearPlayer.sqf"; - }; - // CBA_fnc_northingReversed - class northingReversed - { - description = "Checks if the maps northing is reversed (like Chernarus & Utes, or any map pre-OA)"; - file = "\x\cba\addons\common\fnc_northingReversed.sqf"; - }; - // CBA_fnc_objectRandom - class objectRandom - { - description = "Creates a ""random"" number 0-9 based on an object's velocity"; - file = "\x\cba\addons\common\fnc_objectRandom.sqf"; - }; - // CBA_fnc_onTeamColorChanged - class onTeamColorChanged - { - description = "Assigns the units team color if it changed on another machine."; - file = "\x\cba\addons\common\fnc_onTeamColorChanged.sqf"; - }; - // CBA_fnc_parseYAML - class parseYAML - { - description = "Parses a YAML file into a nested array/Hash structure."; - file = "\x\cba\addons\common\fnc_parseYAML.sqf"; - }; - // CBA_fnc_players - class players - { - description = "Get a list of current player objects."; - file = "\x\cba\addons\common\fnc_players.sqf"; - }; - // CBA_fnc_randPos - class randPos - { - description = "A function used to randomize a position around a given center."; - file = "\x\cba\addons\common\fnc_randPos.sqf"; - }; - // CBA_fnc_randPosArea - class randPosArea - { - description = "A function used to randomize a position within a given zone."; - file = "\x\cba\addons\common\fnc_randPosArea.sqf"; - }; - // CBA_fnc_realHeight - class realHeight - { - description = "Real z coordinate of an object, for placing stuff on roofs, etc."; - file = "\x\cba\addons\common\fnc_realHeight.sqf"; - }; - // CBA_fnc_removeBackpackCargo - class removeBackpackCargo - { - description = "Removes specific backpack(s) from local cargo space."; - file = "\x\cba\addons\common\fnc_removeBackpackCargo.sqf"; - }; - // CBA_fnc_removeBackpackCargoGlobal - class removeBackpackCargoGlobal - { - description = "Remove specific backpack(s) from global cargo space. MP synchronized."; - file = "\x\cba\addons\common\fnc_removeBackpackCargoGlobal.sqf"; - }; - // CBA_fnc_removeItemCargo - class removeItemCargo - { - description = "Removes specific item(s) from local cargo space."; - file = "\x\cba\addons\common\fnc_removeItemCargo.sqf"; - }; - // CBA_fnc_removeItemCargoGlobal - class removeItemCargoGlobal - { - description = "Removes specific item(s) from global cargo space. MP synchronized."; - file = "\x\cba\addons\common\fnc_removeItemCargoGlobal.sqf"; - }; - // CBA_fnc_removeMagazine - class removeMagazine - { - description = "Remove a magazine."; - file = "\x\cba\addons\common\fnc_removeMagazine.sqf"; - }; - // CBA_fnc_removeMagazineCargo - class removeMagazineCargo - { - description = "Removes specific magazine(s) from local cargo space."; - file = "\x\cba\addons\common\fnc_removeMagazineCargo.sqf"; - }; - // CBA_fnc_removeMagazineCargoGlobal - class removeMagazineCargoGlobal - { - description = "Removes specific magazine(s) from global cargo space. MP synchronized."; - file = "\x\cba\addons\common\fnc_removeMagazineCargoGlobal.sqf"; - }; - // CBA_fnc_removePerFrameHandler - class removePerFrameHandler - { - description = "Remove a handler that you have added using CBA_fnc_addPerFrameHandler."; - file = "\x\cba\addons\common\fnc_removePerFrameHandler.sqf"; - }; - // CBA_fnc_removePlayerAction - class removePlayerAction - { - description = "Removes player action previously added with ."; - file = "\x\cba\addons\common\fnc_removePlayerAction.sqf"; - }; - // CBA_fnc_removeWeapon - class removeWeapon - { - description = "Remove a weapon."; - file = "\x\cba\addons\common\fnc_removeWeapon.sqf"; - }; - // CBA_fnc_removeWeaponCargo - class removeWeaponCargo - { - description = "Removes specific weapon(s) from local cargo space."; - file = "\x\cba\addons\common\fnc_removeWeaponCargo.sqf"; - }; - // CBA_fnc_removeWeaponCargoGlobal - class removeWeaponCargoGlobal - { - description = "Removes specific weapon(s) from global cargo space. MP synchronized."; - file = "\x\cba\addons\common\fnc_removeWeaponCargoGlobal.sqf"; - }; - // CBA_fnc_selectWeapon - class selectWeapon - { - description = "Selects a weapon including correctly selecting a weapon mode of specified."; - file = "\x\cba\addons\common\fnc_selectWeapon.sqf"; - }; - // CBA_fnc_setHeight - class setHeight - { - description = "A function used to set the height of an object"; - file = "\x\cba\addons\common\fnc_setHeight.sqf"; - }; - // CBA_fnc_setPos - class setPos - { - description = "A function used to set the position of an entity."; - file = "\x\cba\addons\common\fnc_setPos.sqf"; - }; - // CBA_fnc_switchPlayer - class switchPlayer - { - description = "Switch player to another unit."; - file = "\x\cba\addons\common\fnc_switchPlayer.sqf"; - }; - // CBA_fnc_synchTeamColors - class synchTeamColors - { - description = "Synchs the team colors every second."; - file = "\x\cba\addons\common\fnc_synchTeamColors.sqf"; - }; - // CBA_fnc_systemChat - class systemChat - { - description = "Display a message in the global chat channel."; - file = "\x\cba\addons\common\fnc_systemChat.sqf"; - }; +#define F_FILEPATH(func) class func {\ + file = QUOTE(PATHTOF(DOUBLES(fnc,func).sqf));\ +} + +class CfgFunctions { + class CBA { + class Config { + F_FILEPATH(getConfigEntry); + F_FILEPATH(getObjectConfig); + F_FILEPATH(getItemConfig); + F_FILEPATH(getMuzzles); + F_FILEPATH(getWeaponModes); + F_FILEPATH(inheritsFrom); + F_FILEPATH(getTurret); }; - }; - // Missing BIS functions - // OBSOLETE -/* - class BIS { - class variables { - class undefCheck { - file = "\x\cba\addons\common\dummy.sqf"; - }; + + class Entities { + F_FILEPATH(findEntity); + F_FILEPATH(deleteEntity); + F_FILEPATH(isAlive); + F_FILEPATH(getAlive); + F_FILEPATH(getGroup); + F_FILEPATH(getSharedGroup); + F_FILEPATH(nearPlayer); + F_FILEPATH(getArg); + F_FILEPATH(createMarker); + F_FILEPATH(createTrigger); + F_FILEPATH(getGroupIndex); + F_FILEPATH(getMagazineIndex); + F_FILEPATH(currentMagazineIndex); }; - }; - class BIS_PMC { - class PMC_Campaign { - class initIdentity { - file = "\x\cba\addons\common\dummy.sqf"; - }; + + class Soldiers { + F_FILEPATH(isPerson); + F_FILEPATH(canUseWeapon); + F_FILEPATH(selectWeapon); + F_FILEPATH(switchPlayer); }; - }; -*/ + class Vehicles { + F_FILEPATH(getFirer); + F_FILEPATH(isTurnedOut); + F_FILEPATH(getVolume); + F_FILEPATH(getVehicleRole); + }; + + class Anims { + F_FILEPATH(getAnimType); + F_FILEPATH(getUnitAnim); + F_FILEPATH(getUnitDeathAnim); + F_FILEPATH(isUnitGetOutAnim); + F_FILEPATH(headDir); + F_FILEPATH(modelHeadDir); + }; + class Inventory { + F_FILEPATH(addWeapon); + F_FILEPATH(addMagazine); + F_FILEPATH(addItem); + F_FILEPATH(removeWeapon); + F_FILEPATH(removeMagazine); + F_FILEPATH(removeItem); + }; + + class Cargo { + F_FILEPATH(addWeaponCargo); + F_FILEPATH(addMagazineCargo); + F_FILEPATH(addItemCargo); + F_FILEPATH(addBackpackCargo); + F_FILEPATH(removeWeaponCargo); + F_FILEPATH(removeMagazineCargo); + F_FILEPATH(removeItemCargo); + F_FILEPATH(removeBackpackCargo); + }; + + class Maps { + F_FILEPATH(northingReversed); + F_FILEPATH(mapGridToPos); + F_FILEPATH(mapRelPos); + F_FILEPATH(mapDirTo); + F_FILEPATH(getTerrainProfile); + }; + + class Positions { + F_FILEPATH(getDistance); + F_FILEPATH(getPos); + F_FILEPATH(setPos); + F_FILEPATH(realHeight); + F_FILEPATH(setHeight); + F_FILEPATH(randPos); + F_FILEPATH(randPosArea); + F_FILEPATH(inArea); + F_FILEPATH(getNearest); + F_FILEPATH(getNearestBuilding); + }; + + class Misc { + F_FILEPATH(addPerFrameHandler); + F_FILEPATH(removePerFrameHandler); + F_FILEPATH(addPlayerAction); + F_FILEPATH(removePlayerAction); + F_FILEPATH(createNamespace); + F_FILEPATH(deleteNamespace); + F_FILEPATH(directCall); + F_FILEPATH(objectRandom); + }; + + class Ui { + F_FILEPATH(getFov); + F_FILEPATH(getAspectRatio); + F_FILEPATH(getUISize); + }; + + class Broken { + F_FILEPATH(actionArgument); + F_FILEPATH(dropMagazine); + F_FILEPATH(dropWeapon); + }; + }; }; From 98d86ae77d1ec815f081d30e1a16dfc89e42606c Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 01:33:19 +0100 Subject: [PATCH 13/18] common delete obolete --- addons/common/actionHelper.sqf | 22 -- addons/common/dummy.sqf | 2 - addons/common/fnc_addMagazineVerified.sqf | 152 --------- addons/common/fnc_createCenter.sqf | 28 -- addons/common/fnc_defaultParam.sqf | 37 --- addons/common/fnc_determineMuzzles.sqf | 38 --- addons/common/fnc_getPistol.sqf | 42 --- addons/common/fnc_intToString.sqf | 37 --- addons/common/fnc_locked.sqf | 26 -- addons/common/fnc_players.sqf | 45 --- addons/common/fnc_systemChat.sqf | 27 -- addons/common/init_addons.sqf | 26 -- addons/common/init_kron_strings.sqf | 370 ---------------------- addons/common/init_tables.sqf | 106 ------- 14 files changed, 958 deletions(-) delete mode 100644 addons/common/actionHelper.sqf delete mode 100644 addons/common/dummy.sqf delete mode 100644 addons/common/fnc_addMagazineVerified.sqf delete mode 100644 addons/common/fnc_createCenter.sqf delete mode 100644 addons/common/fnc_defaultParam.sqf delete mode 100644 addons/common/fnc_determineMuzzles.sqf delete mode 100644 addons/common/fnc_getPistol.sqf delete mode 100644 addons/common/fnc_intToString.sqf delete mode 100644 addons/common/fnc_locked.sqf delete mode 100644 addons/common/fnc_players.sqf delete mode 100644 addons/common/fnc_systemChat.sqf delete mode 100644 addons/common/init_addons.sqf delete mode 100644 addons/common/init_kron_strings.sqf delete mode 100644 addons/common/init_tables.sqf diff --git a/addons/common/actionHelper.sqf b/addons/common/actionHelper.sqf deleted file mode 100644 index 181a776a7..000000000 --- a/addons/common/actionHelper.sqf +++ /dev/null @@ -1,22 +0,0 @@ -/* - CBA_actionHelper - By BigDawgKS - - Examples: - _obj addAction ["My Action",CBA_actionHelper,_myOnActCode,1,false,true,"",""]; - Or: - _obj addAction ["My Action 2",CBA_actionHelper,[_myOnActCode,_moreArgs],1,false,true,"",""] -*/ - -#include "script_component.hpp" - -// #define DEBUG_MODE_FULL -private ["_param", "_code", "_args"]; -_param = _this select 3; - -if (IS_ARRAY(_param))then{ - EXPLODE_2(_param,_code,_args); - [_this select 0,_this select 1,_this select 2,_args] call _code; -} else { - _code = _param; - [_this select 0,_this select 1,_this select 2] call _code; -}; diff --git a/addons/common/dummy.sqf b/addons/common/dummy.sqf deleted file mode 100644 index e9545efc8..000000000 --- a/addons/common/dummy.sqf +++ /dev/null @@ -1,2 +0,0 @@ -diag_log "Dummy file called, please fix!"; -false; diff --git a/addons/common/fnc_addMagazineVerified.sqf b/addons/common/fnc_addMagazineVerified.sqf deleted file mode 100644 index 7126d0b16..000000000 --- a/addons/common/fnc_addMagazineVerified.sqf +++ /dev/null @@ -1,152 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_addMagazineVerified - -Description: - Add magazines to the unit, but verify that it was successful and doesn't - over-burden the recipient. - - The function has to options to fill all available inventory slots with - the requested magazine type, create excess magazines on the ground or - do nothing. - -Parameters: - _unit - the unit to add magazine too. [Object] - _magazine - the magazine type to add. [String] - _action - 0 (default) do nothing, return false - - 1 create excess magazines on ground - - 2 fill all inventory slots - -Returns: - true, if the unit has sufficient inventory space - for the magazine in question - -Examples: - (begin example) - [player, "SmokeShell",1] call CBA_fnc_AddMagazineVerified - (end) - -Author: - Sickboy, Killswitch, Wolffy.Au - ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" - -SCRIPT(addMagazineVerified); - -#define __pistol 16 -#define __rifle 256 -#define __ruck 4096 - -#define __pistolMax 8 -#define __rifleMax 12 -#define __ruckMax 20 - -private ["_unit", "_magazine", "_action", "_return", "_cfg", "_type", "_pistol", "_rifle", "_num", "_exit", "_ruck"]; -// BWC -if (typeName _this != "ARRAY") then { - _unit = player; - EXPLODE_1(_this,_magazine); - _action = 2; -} else { - EXPLODE_2(_this,_unit,_magazine); - DEFAULT_PARAM(2,_action,0); -}; - -_cfg = (configFile >> "CfgMagazines" >> _magazine); -_type = getNumber (_cfg >> "type"); - -_pistol = 0; -_rifle = 0; -_ruck = 0; -{ - private ["_cfg", "_type"]; - _cfg = (configFile >> "CfgMagazines" >> _x); - _type = getNumber (_cfg >> "type"); - switch _type do { - case __pistol: { - _pistol = _pistol + 1; - }; - case __rifle: { - _rifle = _rifle + 1; - }; - case __ruck: { - _ruck = _ruck + 1; - }; - default { - if (_type > (__rifle * __rifleMax)) exitWith {}; - _num = _type / __rifle; - if (_num == (round _num)) then { - _rifle = _rifle + _num; - } else { - if (_type > (__pistol * __pistolMax)) exitWith {}; - - _num = _type / __pistol; - if (_num == (round _num)) then { - _pistol = _pistol + _num; - }; - }; - }; - }; -} forEach (magazines _unit); - -private ["_j", "_k"]; -_exit = false; -switch _type do { - case __pistol: { - _num = 1; - _j = _pistol; - _k = __pistolMax; - }; - case __rifle: { - _num = 1; - _j = _rifle; - _k = __rifleMax; - }; - case __ruck: { - _num = 1; - _j = _ruck; - _k = __ruckMax; - }; - default { - if (_type > (__rifle * __rifleMax)) exitWith { _exit = true }; - _num = _type / __rifle; - if (_num == (round _num)) then { - _j = _rifle; - _k = __rifleMax; - } else { - if (_type > (__pistol * __pistolMax)) exitWith { _exit = true }; - _num = _type / __pistol; - if (_num == (round _num)) then { - _j = _pistol; - _k = __pistolMax; - }; - }; - }; -}; - -if (_exit && {(_action == 0 || {_action == 2})}) exitWith { diag_log "CBA_fnc_addMagazineVerified: Sorry, can't carry more of these magazines!"; false; }; -_return = false; -if ((_k - _j) >= _num) then { - switch (_action) do { - case 2: { - for "_i" from 1 to ((_k - _j) / _num) do { - [_unit,_magazine] call CBA_fnc_addMagazine; - }; - }; - default { - [_unit,_magazine] call CBA_fnc_addMagazine; - }; - }; - _return = true; -} else { - if (_action == 1) then { - private ["_wh"]; - _unit switchMove "ainvpknlmstpslaywrfldnon_1"; - _wh = createVehicle ["WeaponHolder", position _unit, [], 0, "NONE"]; - [_wh, _magazine] call CBA_fnc_AddMagazineCargo; - _wh setPos ([_wh, 2] call CBA_fnc_randPos); - }; -}; - -_return; diff --git a/addons/common/fnc_createCenter.sqf b/addons/common/fnc_createCenter.sqf deleted file mode 100644 index 73a2130e1..000000000 --- a/addons/common/fnc_createCenter.sqf +++ /dev/null @@ -1,28 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_createCenter - -Description: - Selects center if it already exists, creates it if it doesn't yet. - -Parameters: - _side - [SIDE] - -Returns: - Center [Side] - -Examples: - (begin example) - _group = createGroup ([West] call CBA_fnc_createCenter); - (end) - -Author: - Sickboy ----------------------------------------------------------------------------- */ -#include "script_component.hpp" -private ["_center"]; -params ["_side"]; -// TODO: Add _side if already a unit exists on this side ? by trying to create one or otherwise -if (_side in GVAR(centers)) then { _side } else { _center = createCenter _side; - GVAR(centers) pushBack _center; - _center -}; diff --git a/addons/common/fnc_defaultParam.sqf b/addons/common/fnc_defaultParam.sqf deleted file mode 100644 index 891216ba2..000000000 --- a/addons/common/fnc_defaultParam.sqf +++ /dev/null @@ -1,37 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_defaultParam - -Description: - Gets a value from parameters list (usually _this) with a default. - -Example (direct use of function): -(begin code) - private "_frog"; - _frog = [_this, 2, 12] call CBA_fnc_defaultParam; -(end code) - -Example (macro): -(begin code) - #include "script_component.hpp" - DEFAULT_PARAM(2,_frog,12); -(end code) - -Parameters: - _params - Array of parameters, usually _this [Array] - _index - Parameter index in the params array [Integer: >= 0] - _defaultValue - Value to use if the array is too short [Any] - -Returns: - Value of parameter [Any] ----------------------------------------------------------------------------- */ -#define DEBUG_MODE_NORMAL -#include "script_component.hpp" - -SCRIPT(defaultParam); - -// ----------------------------------------------------------------------------- -params ["_params","_index","_defaultValue"]; - -ISNILS(_params,[]); - -_params param [_index,_defaultValue] diff --git a/addons/common/fnc_determineMuzzles.sqf b/addons/common/fnc_determineMuzzles.sqf deleted file mode 100644 index 566a5fd1c..000000000 --- a/addons/common/fnc_determineMuzzles.sqf +++ /dev/null @@ -1,38 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_determineMuzzles - -Description: - Gets the list of possible muzzles for a weapon. - -Parameters: - _weap - name of the weapon to examine [String] - -Returns: - - array of muzzle names if the weapon has muzzles and the first - muzzle is not "this" - - nil (nothing) otherwise - -Examples: - (begin example) - _muzzles = "M4A1_RCO_GL" call CBA_fnc_determineMuzzles - // _muzzles = ["M4_ACOG_Muzzle", "M203Muzzle"] - (end) - -Author: - ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" -SCRIPT(determineMuzzles); -params ["_weap"]; -#define __cfg configFile >> "CfgWeapons" >> _weap - -private ["_r"]; -_r = [_weap]; -if (isArray(__cfg >> "muzzles")) then { - _ar = getArray(__cfg >> "muzzles"); - if (count _ar == 0 || {(_ar select 0) == "this"}) exitWith {}; - _r = _ar; -}; - -_r; diff --git a/addons/common/fnc_getPistol.sqf b/addons/common/fnc_getPistol.sqf deleted file mode 100644 index c0dad71f6..000000000 --- a/addons/common/fnc_getPistol.sqf +++ /dev/null @@ -1,42 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_getPistol - -Description: - Returns name of pistol in unit's inventory, if any. - -Parameters: - _unit - Unit to check for a pistol in [Object] - -Returns: - Class name of pistol, if carried, otherwise "" [String] - -Examples: - (begin example) - _pistol = [player] call CBA_fnc_getPistol; - // => "", assuming that the player was not carrying any pistol. - // => "Makarov", assuming that the player was carrying a Makarov pistol. - (end) - -Author: - Sickboy ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" - -#define PISTOL_TYPE 2 - -SCRIPT(getPistol); - -private ["_pistol"]; -params ["_unit"]; -if !(_unit isKindOf "man") exitWith {""}; - -_pistol = ""; - -{ - if ((getNumber (configFile >> "CfgWeapons" >> _x >> "Type")) == PISTOL_TYPE) exitWith { - _pistol = _x; - }; -} forEach (weapons _unit); - -_pistol diff --git a/addons/common/fnc_intToString.sqf b/addons/common/fnc_intToString.sqf deleted file mode 100644 index dab4db0d3..000000000 --- a/addons/common/fnc_intToString.sqf +++ /dev/null @@ -1,37 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_intToString - -Description: - Faster int to string, uses an integer lookup table if possible - -Parameters: - _int - Integer number - -Example: - (begin example) - 5 call CBA_fnc_intToString - (end) - -Returns: - String - -Author: - Xeno - ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" -SCRIPT(intToString); - -params ["_int"]; - -if (typeName _int != "SCALAR") exitWith { - WARNING("Expected number as paramater, type was " + (typeName _int)); - "" -}; - -if (_int < count CBA_INT_STRING_TABLE && {_int >= 0}) then { - (CBA_INT_STRING_TABLE select _int) -} else { - str _int -}; diff --git a/addons/common/fnc_locked.sqf b/addons/common/fnc_locked.sqf deleted file mode 100644 index 1154bdf37..000000000 --- a/addons/common/fnc_locked.sqf +++ /dev/null @@ -1,26 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_locked - -Description: - A3 compatible locked function. - - The locked scripting command returns a numeric value. - This function returns a boolean. - -Parameters: - _object - The object the locked check is done for. -Returns: - true if _object is locked otherwise false -Examples: - (begin example) - _islocked = myVehicle call CBA_fnc_locked; - (end) - -Author: - Killswitch ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" -SCRIPT(locked); - -locked _this > 1 diff --git a/addons/common/fnc_players.sqf b/addons/common/fnc_players.sqf deleted file mode 100644 index e139d3867..000000000 --- a/addons/common/fnc_players.sqf +++ /dev/null @@ -1,45 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_players - -Description: - Get a list of current player objects. - - In multi-player missions, returns list of human players, rather than all - playable units (playableUnits includes playable AI). Will include dead - player objects for players who are waiting to respawn. - - In single-player missions, just returns an array containing the current - player object. - - This command is similar to BIS_fnc_listPlayers. In fact, it is the same in - MP, but in SP it returns a result which is consistent to prevent the need - to handle things differently in different types of game - (BIS_fnc_listPlayers uses different criteria for the list in SP and MP). - -Parameters: - None. - -Returns: - List of player objects [Array of Objects]. - -Examples: - (begin example) - _players = call CBA_fnc_players; - (end) - -Author: - Spooner ----------------------------------------------------------------------------- */ - -#include "script_component.hpp" -SCRIPT(players); - -private "_return"; - -_return = if (isMultiplayer) then { - [playableUnits, { isPlayer _x }] call BIS_fnc_conditionalSelect; -} else { - [player]; -}; - -_return; diff --git a/addons/common/fnc_systemChat.sqf b/addons/common/fnc_systemChat.sqf deleted file mode 100644 index 394cc4a70..000000000 --- a/addons/common/fnc_systemChat.sqf +++ /dev/null @@ -1,27 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_systemChat - -Description: - Display a message in the global chat channel. - -Parameters: - _message - the message to display [String] - -Returns: - nothing - -Examples: - (begin example) - "Hello, world!" call CBA_fnc_systemChat - (end) - -Author: - Killswitch ----------------------------------------------------------------------------- */ - -#include - -params ["_message"]; - -CBA_logic globalChat _message; - diff --git a/addons/common/init_addons.sqf b/addons/common/init_addons.sqf deleted file mode 100644 index 260050af0..000000000 --- a/addons/common/init_addons.sqf +++ /dev/null @@ -1,26 +0,0 @@ -// #define DEBUG_MODE_FULL -#include "script_component.hpp" - -private ["_cfg", "_c", "_addons"]; - -// Find and Count CfgPatches -_cfg = (configFile >> "CfgPatches"); -_c = count _cfg; -if (_c == 0) exitWith { - WARNING("Somehow No Addons found to Activate"); -}; - -// Process all CfgPatches -_addons = []; -for "_i" from 0 to (_c - 1) do { - _entry = _cfg select _i; - if (isClass _entry) then { - _addons pushBack (configName _entry); - }; -}; - -// Activate all CfgPatches -activateAddons _addons; -TRACE_1("Activated",count _addons); - -CBA_common_addons = _addons; diff --git a/addons/common/init_kron_strings.sqf b/addons/common/init_kron_strings.sqf deleted file mode 100644 index d6f950bc2..000000000 --- a/addons/common/init_kron_strings.sqf +++ /dev/null @@ -1,370 +0,0 @@ -#include "script_component.hpp" -// ========================================================================================================= -// -// String Functions Library -// Version: 2.2.1 -// Author: Kronzky -// -// ========================================================================================================= -// -// Usage: -// -// ? KRON_StrToArray - Converts a string into an array of characters: -// _array =[_str] call KRON_StrToArray -// -// ? KRON_StrLen - Returns the length of the string -// _len =[_str] call KRON_StrLen -// -// ? KRON_StrLeft - Returns l characters from the left side of the string -// _left =[_str,l] call KRON_StrLeft -// -// ? KRON_StrRight - Returns l characters from the right side of the string -// _right =[_str,l] call KRON_StrRight -// -// ? KRON_StrMid - Returns l characters from the string, starting at position p (zero-based) -// If l is not defined, the rest of the string is returned -// _mid =[_str,p,(l)] call KRON_StrMid -// -// ? KRON_StrInStr - Tests whether string b is present in string a -// _found =[a,b] call KRON_StrInStr -// -// ? KRON_StrIndex - Returns the position of string b in string a -// _index =[a,b] call KRON_StrIndex -// -// ? KRON_StrUpper - Converts a string to uppercase characters -// _upper =[_str] call KRON_StrUpper -// -// ? KRON_StrLower - Converts a string to lowercase characters -// _lower =[_str] call KRON_StrLower -// -// ? KRON_Replace - Replaces every occurrence of string _old in string _str with string _new -// _index =[_str,_old,_new] call KRON_Replace -// -// ? KRON_FindFlag - Checks a mixed array (_this) for the presence of a string (_str) -// _flg =[_this,_str] call KRON_FindFlag -// -// ? KRON_getArg - Searches a mixed array (_this) for a matching string beginning with (_t), and returns the part after a separator (s) -// A default value can be defined as (_d). -// _arg =[_this,_t,(_d)] call KRON_getArg -// -// ? KRON_getArgRev - Works like getArg, but search for the part *after* the colon, and return the part in front of it -// A default value can be defined as (_d). -// _arg =[_this,_t,(_d)] call KRON_getArgRev -// -// ? KRON_Compare - Compares two elements and returns -1 if first is smaller, 1 if second is smaller, and 0 if equal -// If optional parameter "case" is given, capitalization is considered (upper before lowercase) -// _cmp =[_str1,_str2,("case")] call KRON_Compare -// -// ? KRON_ArraySort - Sorts an array of strings in acsending order (Numbers before letters, uppercase before lowercase) -// If array is multi-dimensional, optional parameter (_idx) specifies which column is used for sorting -// If optional parameter "desc" is given, order is reversed -// If optional parameter "case" is given, capitalization is considered (upper before lowercase) -// _srt =[_arr,(_idx),("desc"),("case")] call KRON_ArraySort -// -// ========================================================================================================= - -/* -KRON_StrToArray = { - private["_in", "_i", "_arr", "_out"]; - _in = _this select 0; - _arr = toArray(_in); - _out =[]; - for "_i" from 0 to (count _arr)-1 do - { - _out = _out+[toString([_arr select _i])]; - }; - _out -}; -*/ - -KRON_StrLeft = { - private["_in", "_len", "_arr", "_out"]; - _in = _this select 0; - _len = (_this select 1) - 1; - _arr = [_in] call KRON_StrToArray; - _out =""; - if (_len >= count _arr) then { - _out = _in; - } else { - for "_i" from 0 to _len do { - _out = _out + (_arr select _i); - }; - }; - _out -}; - -/* -KRON_StrLen = { - private["_in", "_arr", "_len"]; - _in = _this select 0; - _arr =[_in] call KRON_StrToArray; - _len = count (_arr); - _len -}; -*/ - -KRON_StrRight = { - private["_in", "_len", "_arr", "_i", "_out"]; - _in = _this select 0; - _len = _this select 1; - _arr = [_in] call KRON_StrToArray; - _out =""; - if (_len > count _arr) then {_len = count _arr}; - for "_i" from ((count _arr) - _len) to ((count _arr) - 1) do { - _out = _out + (_arr select _i); - }; - _out -}; - -KRON_StrMid = { - private["_in", "_pos", "_len", "_arr", "_i", "_out"]; - _in = _this select 0; - _pos = abs(_this select 1); - _arr = [_in] call KRON_StrToArray; - _len = count _arr; - if (count _this > 2) then {_len = _this select 2}; - _out =""; - if ((_pos + _len) >= count _arr) then {_len = (count _arr) - _pos}; - if (_len > 0) then { - for "_i" from _pos to (_pos + _len - 1) do { - _out = _out + (_arr select _i); - }; - }; - _out -}; - -/* -KRON_StrIndex = { - private["_hay", "_ndl", "_lh", "_ln", "_arr", "_tmp", "_i", "_j", "_out"]; - _hay = _this select 0; - _ndl = _this select 1; - _out =-1; - _i = 0; - if (_hay == _ndl) exitWith { 0 }; - _lh =[_hay] call KRON_StrLen; - _ln =[_ndl] call KRON_StrLen; - if (_lh < _ln) exitWith {-1 }; - _arr =[_hay] call KRON_StrToArray; - for "_i" from 0 to (_lh-_ln) do - { - _tmp =""; - for "_j" from _i to (_i+_ln-1) do - { - _tmp = _tmp + (_arr select _j); - }; - if (_tmp == _ndl) exitWith { _out = _i }; - }; - _out -}; -*/ - -KRON_StrInStr = { - (([_this select 0, _this select 1] call KRON_StrIndex) != -1) -}; - -/* -KRON_Replace = { - private["_str", "_old", "_new", "_out", "_tmp", "_jm", "_la", "_lo", "_ln", "_i"]; - _str = _this select 0; - _arr = toArray(_str); - _la = count _arr; - _old = _this select 1; - _new = _this select 2; - _na =[_new] call KRON_StrToArray; - _lo =[_old] call KRON_StrLen; - _ln =[_new] call KRON_StrLen; - _out =""; - for "_i" from 0 to (count _arr)-1 do - { - _tmp =""; - if (_i <= _la-_lo) then - { - for "_j" from _i to (_i+_lo-1) do - { - _tmp = _tmp + toString([_arr select _j]); - }; - }; - if (_tmp == _old) then - { - _out = _out+_new; - _i = _i+_lo-1; - } else { - _out = _out+toString([_arr select _i]); - }; - }; - _out -}; -*/ - -/* -KRON_StrUpper = { - private["_in", "_out"]; - _in = _this select 0; - _out = toUpper(_in); - _out -}; -*/ - -/* -KRON_StrLower = { - private["_in", "_out"]; - _in = _this select 0; - _out = toLower(_in); - _out -}; -*/ - -KRON_ArrayToUpper = { - private["_in", "_i", "_e", "_out"]; - _in = _this select 0; - _out = []; - if (count _in > 0) then { - for "_i" from 0 to (count _in) - 1 do { - _e = _in select _i; - if (typeName _e == "STRING") then { - _e = toUpper _e; - }; - _out set [_i, _e]; - }; - }; - _out -}; - -KRON_Compare = { - private["_k", "_n", "_s", "_i", "_c", "_t", "_s1", "_s2", "_l1", "_l2", "_l"]; - _k = [_this, "CASE"] call KRON_findFlag; - _n = 0; - _s = 0; - for "_i" from 0 to 1 do { - _t = _this select _i; - switch (typeName _t) do { - case "SCALAR": { _n = 1 }; - case "BOOL": { _this set [_i, str _t]}; - case "SIDE": { _this set [_i, str _t]}; - case "STRING": { if !(_k) then { _this = [_this] call KRON_ArrayToUpper }}; - default { _n =-1 }; - }; - }; - _s1 = _this select 0; - _s2 = _this select 1; - if (_n != 0) exitWith { - if (_n == 1) then { - if (_s1 < _s2) then { _s =-1 } else { if (_s1 > _s2) then { _s = 1 }}; - }; - _s - }; - _s1 = toArray _s1; - _s2 = toArray _s2; - _l1 = count _s1; - _l2 = count _s2; - _l = if (_l1 < _l2) then { _l1 } else { _l2 }; - for "_i" from 0 to _l - 1 do { - if ((_s1 select _i) < (_s2 select _i)) then { - _s = -1; - _i = _l; - } else { - if ((_s1 select _i) > (_s2 select _i)) then { - _s = 1; - _i = _l; - }; - }; - }; - if (_s == 0) then { - if (_l1 < _l2) then { - _s =-1; - } else { - if (_l1 > _l2) then { _s = 1 }; - }; - }; - _s -}; - -KRON_ArraySort = { - private["_a", "_d", "_k", "_s", "_i", "_vo", "_v1", "_v2", "_j", "_c", "_x"]; - _a = +(_this select 0); - _d = if ([_this, "DESC"] call KRON_findFlag) then { -1 } else { 1 }; - _k = if ([_this, "CASE"] call KRON_findFlag) then { "CASE" } else { "nocase" }; - _s = -1; - if (typeName (_a select 0) == "ARRAY") then { - _s = 0; - if (count _this > 1 && {typeName (_this select 1) == "SCALAR"}) then { - _s = _this select 1; - }; - }; - for "_i" from 0 to (count _a) - 1 do { - _vo = _a select _i; - _v1 = _vo; - if (_s > -1) then { _v1 = _v1 select _s }; - _j = 0; - for [{ _j = _i-1 }, { _j >= 0 }, { _j = _j - 1 }] do { - _v2 = _a select _j; - if (_s > -1) then { _v2 = _v2 select _s }; - _c = [_v2, _v1, _k] call KRON_Compare; - if (_c != _d) exitWith {}; - _a set [_j + 1, _a select _j]; - }; - _a set [_j + 1, _vo]; - }; - _a -}; - -KRON_findFlag = { - private["_in", "_flg", "_arr"]; - _in = _this select 0; - _flg = toUpper(_this select 1); - _arr = [_in] call KRON_ArrayToUpper; - (_flg in _arr) -}; - -KRON_getArg = { - private["_in", "_flg", "_fl", "_def", "_arr", "_i", "_j", "_as", "_aa", "_org", "_p", "_out"]; - _in = _this select 0; - _flg = toUpper(_this select 1); - _fl = [_flg] call KRON_StrLen; - _out = ""; - if (count _this > 2) then { _out = _this select 2 }; - _arr = [_in] call KRON_ArrayToUpper; - if (count _arr > 0) then { - for "_i" from 0 to (count _in) - 1 do { - _as = _arr select _i; - if (typeName _as =="STRING") then { - _aa = [_as] call KRON_StrToArray; - _p = _aa find ":"; - if (_p == _fl) then { - if (([_as,_fl] call KRON_StrLeft) == _flg) then { - _org = _in select _i; - _out = [_org, _p + 1] call KRON_StrMid; - }; - }; - }; - }; - }; - _out -}; - - -KRON_getArgRev = { - private["_in", "_flg", "_fl", "_def", "_arr", "_i", "_j", "_as", "_aa", "_org", "_p", "_out"]; - _in = _this select 0; - _flg = toUpper(_this select 1); - _fl = [_flg] call KRON_StrLen; - _out =""; - if (count _this > 2) then { _out = _this select 2 }; - _arr = [_in] call KRON_ArrayToUpper; - if (count _arr > 0) then { - for "_i" from 0 to (count _in) - 1 do { - _as = _arr select _i; - if (typeName _as =="STRING") then { - _aa = [_as] call KRON_StrToArray; - _p = _aa find ":"; - if (_p + 1 == (count _aa) - _fl) then { - if (([_as, _p + 1] call KRON_StrMid) == _flg) then { - _org = _in select _i; - _out = [_org, _p] call KRON_StrLeft; - }; - }; - }; - }; - }; - _out -}; diff --git a/addons/common/init_tables.sqf b/addons/common/init_tables.sqf deleted file mode 100644 index 65a1b0adf..000000000 --- a/addons/common/init_tables.sqf +++ /dev/null @@ -1,106 +0,0 @@ -#include "script_component.hpp" - -if (!isNil "CBA_INT_STRING_TABLE") exitWith {}; - -CBA_INT_STRING_TABLE = [ - "0","1","2","3","4","5","6","7","8","9", - "10","11","12","13","14","15","16","17","18","19", - "20","21","22","23","24","25","26","27","28","29", - "30","31","32","33","34","35","36","37","38","39", - "40","41","42","43","44","45","46","47","48","49", - "50","51","52","53","54","55","56","57","58","59", - "60","61","62","63","64","65","66","67","68","69", - "70","71","72","73","74","75","76","77","78","79", - "80","81","82","83","84","85","86","87","88","89", - "90","91","92","93","94","95","96","97","98","99", - "100","101","102","103","104","105","106","107","108","109", - "110","111","112","113","114","115","116","117","118","119", - "120","121","122","123","124","125","126","127","128","129", - "130","131","132","133","134","135","136","137","138","139", - "140","141","142","143","144","145","146","147","148","149", - "150","151","152","153","154","155","156","157","158","159", - "160","161","162","163","164","165","166","167","168","169", - "170","171","172","173","174","175","176","177","178","179", - "180","181","182","183","184","185","186","187","188","189", - "190","191","192","193","194","195","196","197","198","199", - "200","201","202","203","204","205","206","207","208","209", - "210","211","212","213","214","215","216","217","218","219", - "220","221","222","223","224","225","226","227","228","229", - "230","231","232","233","234","235","236","237","238","239", - "240","241","242","243","244","245","246","247","248","249", - "250","251","252","253","254","255","256","257","258","259", - "260","261","262","263","264","265","266","267","268","269", - "270","271","272","273","274","275","276","277","278","279", - "280","281","282","283","284","285","286","287","288","289", - "290","291","292","293","294","295","296","297","298","299", - "300","301","302","303","304","305","306","307","308","309", - "310","311","312","313","314","315","316","317","318","319", - "320","321","322","323","324","325","326","327","328","329", - "330","331","332","333","334","335","336","337","338","339", - "340","341","342","343","344","345","346","347","348","349", - "350","351","352","353","354","355","356","357","358","359", - "360","361","362","363","364","365","366","367","368","369", - "370","371","372","373","374","375","376","377","378","379", - "380","381","382","383","384","385","386","387","388","389", - "390","391","392","393","394","395","396","397","398","399", - "400","401","402","403","404","405","406","407","408","409", - "410","411","412","413","414","415","416","417","418","419", - "420","421","422","423","424","425","426","427","428","429", - "430","431","432","433","434","435","436","437","438","439", - "440","441","442","443","444","445","446","447","448","449", - "450","451","452","453","454","455","456","457","458","459", - "460","461","462","463","464","465","466","467","468","469", - "470","471","472","473","474","475","476","477","478","479", - "480","481","482","483","484","485","486","487","488","489", - "490","491","492","493","494","495","496","497","498","499", - "500","501","502","503","504","505","506","507","508","509", - "510","511","512","513","514","515","516","517","518","519", - "520","521","522","523","524","525","526","527","528","529", - "530","531","532","533","534","535","536","537","538","539", - "540","541","542","543","544","545","546","547","548","549", - "550","551","552","553","554","555","556","557","558","559", - "560","561","562","563","564","565","566","567","568","569", - "570","571","572","573","574","575","576","577","578","579", - "580","581","582","583","584","585","586","587","588","589", - "590","591","592","593","594","595","596","597","598","599", - "600","601","602","603","604","605","606","607","608","609", - "610","611","612","613","614","615","616","617","618","619", - "620","621","622","623","624","625","626","627","628","629", - "630","631","632","633","634","635","636","637","638","639", - "640","641","642","643","644","645","646","647","648","649", - "650","651","652","653","654","655","656","657","658","659", - "660","661","662","663","664","665","666","667","668","669", - "670","671","672","673","674","675","676","677","678","679", - "680","681","682","683","684","685","686","687","688","689", - "690","691","692","693","694","695","696","697","698","699", - "700","701","702","703","704","705","706","707","708","709", - "710","711","712","713","714","715","716","717","718","719", - "720","721","722","723","724","725","726","727","728","729", - "730","731","732","733","734","735","736","737","738","739", - "740","741","742","743","744","745","746","747","748","749", - "750","751","752","753","754","755","756","757","758","759", - "760","761","762","763","764","765","766","767","768","769", - "770","771","772","773","774","775","776","777","778","779", - "780","781","782","783","784","785","786","787","788","789", - "790","791","792","793","794","795","796","797","798","799", - "800","801","802","803","804","805","806","807","808","809", - "810","811","812","813","814","815","816","817","818","819", - "820","821","822","823","824","825","826","827","828","829", - "830","831","832","833","834","835","836","837","838","839", - "840","841","842","843","844","845","846","847","848","849", - "850","851","852","853","854","855","856","857","858","859", - "860","861","862","863","864","865","866","867","868","869", - "870","871","872","873","874","875","876","877","878","879", - "880","881","882","883","884","885","886","887","888","889", - "890","891","892","893","894","895","896","897","898","899", - "900","901","902","903","904","905","906","907","908","909", - "910","911","912","913","914","915","916","917","918","919", - "920","921","922","923","924","925","926","927","928","929", - "930","931","932","933","934","935","936","937","938","939", - "940","941","942","943","944","945","946","947","948","949", - "950","951","952","953","954","955","956","957","958","959", - "960","961","962","963","964","965","966","967","968","969", - "970","971","972","973","974","975","976","977","978","979", - "980","981","982","983","984","985","986","987","988","989", - "990","991","992","993","994","995","996","997","998","999" -]; \ No newline at end of file From e0c339dd968b478a98d548e08144433c20e121fd Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 06:24:17 +0100 Subject: [PATCH 14/18] common fixes, add turret path functions, redo getFirer --- addons/common/CfgFunctions.hpp | 4 +- addons/common/CfgPerFrame.hpp | 89 +---------------- addons/common/CfgRemoteExec.hpp | 3 +- addons/common/XEH_postInit.sqf | 32 ++----- addons/common/backwards_comp.sqf | 14 ++- addons/common/fnc_getFirer.sqf | 96 +++++++++---------- addons/common/fnc_turretPath.sqf | 29 ++++++ addons/common/fnc_turretPathWeapon.sqf | 31 ++++++ ...getVehicleRole.sqf => fnc_vehicleRole.sqf} | 6 +- 9 files changed, 134 insertions(+), 170 deletions(-) create mode 100644 addons/common/fnc_turretPath.sqf create mode 100644 addons/common/fnc_turretPathWeapon.sqf rename addons/common/{fnc_getVehicleRole.sqf => fnc_vehicleRole.sqf} (88%) diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index d91b31eac..df0addb9b 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -42,7 +42,9 @@ class CfgFunctions { F_FILEPATH(getFirer); F_FILEPATH(isTurnedOut); F_FILEPATH(getVolume); - F_FILEPATH(getVehicleRole); + F_FILEPATH(vehicleRole); + F_FILEPATH(turretPath); + F_FILEPATH(turretPathWeapon); }; class Anims { diff --git a/addons/common/CfgPerFrame.hpp b/addons/common/CfgPerFrame.hpp index 11da30bd3..e6e99051a 100644 --- a/addons/common/CfgPerFrame.hpp +++ b/addons/common/CfgPerFrame.hpp @@ -1,86 +1,3 @@ -// Control types -#define CT_STATIC 0 -#define CT_BUTTON 1 -#define CT_EDIT 2 -#define CT_SLIDER 3 -#define CT_COMBO 4 -#define CT_LISTBOX 5 -#define CT_TOOLBOX 6 -#define CT_CHECKBOXES 7 -#define CT_PROGRESS 8 -#define CT_HTML 9 -#define CT_STATIC_SKEW 10 -#define CT_ACTIVETEXT 11 -#define CT_TREE 12 -#define CT_STRUCTURED_TEXT 13 -#define CT_CONTEXT_MENU 14 -#define CT_CONTROLS_GROUP 15 -#define CT_SHORTCUT_BUTTON 16 // Arma 2 - textured button - -#define CT_XKEYDESC 40 -#define CT_XBUTTON 41 -#define CT_XLISTBOX 42 -#define CT_XSLIDER 43 -#define CT_XCOMBO 44 -#define CT_ANIMATED_TEXTURE 45 -#define CT_OBJECT 80 -#define CT_OBJECT_ZOOM 81 -#define CT_OBJECT_CONTAINER 82 -#define CT_OBJECT_CONT_ANIM 83 -#define CT_LINEBREAK 98 -#define CT_USER 99 -#define CT_MAP 100 -#define CT_MAP_MAIN 101 -#define CT_List_N_Box 102 // Arma 2 - N columns list box - - -// Static styles -#define ST_POS 0x0F -#define ST_HPOS 0x03 -#define ST_VPOS 0x0C -#define ST_LEFT 0x00 -#define ST_RIGHT 0x01 -#define ST_CENTER 0x02 -#define ST_DOWN 0x04 -#define ST_UP 0x08 -#define ST_VCENTER 0x0c - -#define ST_TYPE 0xF0 -#define ST_SINGLE 0 -#define ST_MULTI 16 -#define ST_TITLE_BAR 32 -#define ST_PICTURE 48 -#define ST_FRAME 64 -#define ST_BACKGROUND 80 -#define ST_GROUP_BOX 96 -#define ST_GROUP_BOX2 112 -#define ST_HUD_BACKGROUND 128 -#define ST_TILE_PICTURE 144 -#define ST_WITH_RECT 160 -#define ST_LINE 176 - -#define ST_SHADOW 0x100 -#define ST_NO_RECT 0x200 -#define ST_KEEP_ASPECT_RATIO 0x800 - -#define ST_TITLE ST_TITLE_BAR + ST_CENTER - -// Slider styles -#define SL_DIR 0x400 -#define SL_VERT 0 -#define SL_HORZ 0x400 - -#define SL_TEXTURES 0x10 - -// Listbox styles -#define LB_TEXTURES 0x10 -#define LB_MULTI 0x20 - -#define FontM "Bitstream" -#define DEFAULTFONT FontM - -#define true 1 -#define false 0 class RscMapControl { class Task; @@ -112,6 +29,7 @@ class RscMapControl { class WaypointCompleted; class ActiveMarker; }; + class CBA_Dummy_Map: RscMapControl { idc = -1; @@ -438,7 +356,6 @@ class CBA_Dummy_Map: RscMapControl { }; }; - class RscTitles { class CBA_FrameHandlerTitle { idd = 40121; @@ -446,14 +363,14 @@ class RscTitles { enableSimulation = 1; enableDisplay = 1; - onLoad = QUOTE(_this call CBA_common_fnc_perFrameEngine); + onLoad = QUOTE(_this call FUNC(perFrameEngine)); duration = 99999999; fadein = 0; fadeout = 0; name = "CBA_FrameHandlerTitle"; class controlsBackground { - class dummy_map : CBA_Dummy_Map { + class dummy_map: CBA_Dummy_Map { idc = 40122; x = -10; y = -10; diff --git a/addons/common/CfgRemoteExec.hpp b/addons/common/CfgRemoteExec.hpp index f2ae1104f..40612d84f 100644 --- a/addons/common/CfgRemoteExec.hpp +++ b/addons/common/CfgRemoteExec.hpp @@ -1,4 +1,5 @@ -class CfgRemoteExec { + +class CfgRemoteExec { // white listing currently broken! (1.56) class Functions { // Used by CBA_fnc_switchPlayer class GVAR(setVehVarName) { diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 31661b659..a61c610e8 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -3,13 +3,11 @@ LOG(MSG_INIT); -// if (true) exitWith {}; - // NOTE: Due to the way the BIS functions initializations work, and the requirement of BIS_functions_mainscope to be a unit (in a group) // the logic is created locally on MP dedicated client, to still allow this early, called precompilation of the functions. // But initialization doesn't officially finish until the official (server created / mission.sqm included) logic is available. // In SP or as server (dedicated or clientServer), the logic is created with group and createUnit. -SLX_XEH_STR spawn { +0 spawn { waitUntil {!isNil "bis_functions_mainscope"}; waitUntil {!isNull bis_functions_mainscope}; CBA_logic = bis_functions_mainscope; @@ -20,26 +18,13 @@ SLX_XEH_STR spawn { FUNC(log) = { diag_log text _this; - sleep 1; - systemChat _this; - hintC _this; + _this spawn { + sleep 1; + systemChat _this; + hintC _this; + }; }; -// A2 / Operation Arrowhead, standalone / combined operations check -/* -TRACE_1("OA Check",nil); -private ["_hasCbaOa", "_hasCbaA2", "_hasA2", "_hasOa"]; -_hasCbaA2 = isClass(configFile >> "CfgPatches" >> "CBA_A2_main"); -_hasCbaOa = isClass(configFile >> "CfgPatches" >> "CBA_OA_main"); -_hasA2 = isClass(configFile >> "CfgPatches" >> "Chernarus"); -_hasOa = isClass(configFile >> "CfgPatches" >> "Takistan"); - -if (_hasA2 && !_hasCbaA2) then { "Running A2 Content but missing @CBA_A2, please install and enable @CBA_A2, or disable A2 content" spawn FUNC(log) }; -if (_hasOA && !_hasCbaOA) then { "Running OA Content but missing @CBA_OA, please install and enable @CBA_OA, or disable OA content" spawn FUNC(log) }; -if (!_hasA2 && _hasCbaA2) then { "Not Running A2 Content but running @CBA_A2, please disable @CBA_A2 or enable A2 content" spawn FUNC(log) }; -if (!_hasOa && _hasCbaOa) then { "Not Running OA Content but running @CBA_OA, please disable @CBA_OA or enable OA content" spawn FUNC(log) }; - */ - // Upgrade check - Registry for removed addons, warn the user if found // TODO: Evaluate registry of 'current addons' and verifying that against available CfgPatches TRACE_1("Upgrade Check",nil); @@ -50,14 +35,13 @@ for "_i" from 0 to ((count (CFG)) - 1) do { if (isClass(_entry) && {isArray(_entry >> "removed")}) then { { if (isClass(configFile >> "CfgPatches" >> _x)) then { - format["WARNING: Found addon that should be removed: %1; Please remove and restart game", _x] spawn FUNC(log); + format["WARNING: Found addon that should be removed: %1; Please remove and restart game", _x] call FUNC(log); }; } forEach (getArray(_entry >> "removed")); }; }; -private ["_oldPFH"]; -_oldPFH = isNil "BIS_fnc_addStackedEventHandler"; +private _oldPFH = isNil "BIS_fnc_addStackedEventHandler"; FUNC(initPerFrameHandlers) = { if (_this) then { diff --git a/addons/common/backwards_comp.sqf b/addons/common/backwards_comp.sqf index a8404d4c6..d829cfbac 100644 --- a/addons/common/backwards_comp.sqf +++ b/addons/common/backwards_comp.sqf @@ -1,5 +1,9 @@ -CBA_fnc_createCenter = {_this}; +CBA_fnc_createCenter = { + params ["_side"]; + _side +}; + CBA_fnc_players = {allPlayers}; CBA_fnc_locked = {locked _this > 1}; @@ -14,7 +18,8 @@ CBA_fnc_systemChat = { }; CBA_fnc_defaultParam = { - params [["_params", []], ["_index", -2, [0]], "_defaultValue"]; + params [["_params", []], ["_index", -1, [0]], "_defaultValue"]; + if (_index < 0) exitWith {_defaultValue}; _params param [_index, _defaultValue] }; @@ -27,7 +32,10 @@ CBA_fnc_removeMagazineCargoGlobal = CBA_fnc_removeMagazineCargo; CBA_fnc_removeItemCargoGlobal = CBA_fnc_removeItemCargo; CBA_fnc_removeBackpackCargoGlobal = CBA_fnc_removeBackpackCargo; -FUNC(directCall) = CBA_fnc_directCall; +FUNC(directCall) = { + params ["_params", "_code"]; + [_code, _params] call CBA_fnc_directCall; +}; CBA_fnc_intToString = { params [["_int", nil, [0]]]; diff --git a/addons/common/fnc_getFirer.sqf b/addons/common/fnc_getFirer.sqf index 1c1dee826..f32774d13 100644 --- a/addons/common/fnc_getFirer.sqf +++ b/addons/common/fnc_getFirer.sqf @@ -2,76 +2,68 @@ Function: CBA_fnc_getFirer Description: - A function used to find out which unit exactly fired (Replacement for gunner, on multi-turret vehicles). + A function used to find out which unit exactly fired. + Replacement for gunner, on multi-turret vehicles. Parameters: - Vehicle that fired - Weapon that was used + _vehicle - a vehicle with turrets + _weapon - a weapon in the vehicles turret Example: (begin example) - _unit = player call CBA_fnc_getFirer + _turretPath = [cameraOn, "HMG_127_mbt"] call CBA_fnc_getFirer (end) Returns: - Unit - Turretpath + + Firer of the weapon. objNull if the weapon does not exist on the vehicle + Turret path of the firer. [] if firer is not in a turret Author: - Rocko - + Rocko, commy2 ---------------------------------------------------------------------------- */ - -// #define DEBUG_MODE_FULL #include "script_component.hpp" -#define __cfg (configFile >> "CfgVehicles" >> (typeof _veh) >> "turrets") -private ["_tp", "_tc", "_st", "_stc", "_wtp", "_tu", "_mti", "_mtJ", "_sti", "_stJ", "_gunner", "_mainWeapons", "_r", "_cfg", "_entry"]; -params ["_veh","_weap"]; // Vehicle that fired // Weapon that was fired -if (_veh isKindOf "CAManBase") exitWith { _r = [_veh, []]; TRACE_1("Result",_r); _r; }; // return the unit itself when it's a Man -if (_veh isKindOf "Air") exitWith { _gunner = gunner _veh; _r = [if (isNull _gunner) then { driver _veh } else { _gunner }, [0]]; TRACE_1("Result",_r); _r; }; +SCRIPT(getFirer); -_tc = count __cfg; -if (_tc == 0) exitWith { _r = [objNull, []]; TRACE_1("Result",_r); _r }; +params [["_vehicle", objNull, [objNull]], ["_weapon", "", [""]]]; -_tp = []; +_weapon = configName (configFile >> "CfgWeapons" >> _weapon); // fix case sensitivity issues -// TODO: Only supports Main Turrets, and SubTurrets on MainTurrets. No need for infinite level? -// Check MainTurrets -_mtJ = 0; // Custom counter since we ignore class properties (non subclasses) -for "_mti" from 0 to (_tc-1) do { - _cfg = (__cfg select _mti); - if (isClass _cfg) then { - _entry = [_mtJ]; - _tp pushBack _entry; +private _gunner = objNull; +private _turret = []; - // Check SubTurrets - _st = _cfg >> "turrets"; - _stc = count _st; - if (_stc > 0) then { - _stJ = 0; // Custom counter since we ignore class properties (non subclasses) - for "_sti" from 0 to (_stc-1) do { - _stp = _st select _sti; - if (isClass _stp) then { - _entry = [_mtJ, _stJ]; - _tp pushBack _entry; +if (driver _vehicle isEqualTo _vehicle) then { + // handle soldiers + private _weapons = weapons _vehicle; - INC(_stJ); - }; - }; - }; - INC(_mtJ); + _weapons append [ + configName (configFile >> "CfgWeapons" >> "Throw"), + configName (configFile >> "CfgWeapons" >> "Put") + ]; + + if (_weapon in _weapons) then { + _gunner = driver _vehicle; }; -}; +} else { + // handle vehicles + private _turrets = allTurrets _vehicle; + _turrets pushBack [-1]; -_wtp = []; -{ - _weapons = getArray([_veh, _x] call CBA_fnc_getTurret >> "weapons"); - TRACE_3("",_weapons,_x,_veh turretUnit _x); - if (_weap in _weapons) exitWith { _wtp = _x; }; -} foreach _tp; + { + if (_weapon in (_vehicle weaponsTurret _x)) exitWith { + if (_x isEqualTo [-1]) then { + _gunner = driver _vehicle; + } else { + _gunner = _vehicle turretUnit _x; + _turret = _x; + }; -if (count _wtp == 0) exitWith { _r = [objNull, []]; TRACE_1("Result",_r); _r; }; // Or should we exit with gunner _veh ? + // at least return something when pilot used manual fire + if (isNull _gunner && {isManualFire _vehicle}) then { + _gunner = effectiveCommander _vehicle; + }; + }; + } forEach _turrets; +}; -_r = [_veh turretUnit _wtp, _wtp]; -TRACE_1("Result",_r); -_r; +[_gunner, _turret] diff --git a/addons/common/fnc_turretPath.sqf b/addons/common/fnc_turretPath.sqf new file mode 100644 index 000000000..30ee0f4ae --- /dev/null +++ b/addons/common/fnc_turretPath.sqf @@ -0,0 +1,29 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_turretPath + +Description: + A function used to report the soldiers turret path in the current vehicle. + Reverse version of the turretUnit scripting command. + +Parameters: + _unit - a soldier in a vehicle + +Example: + (begin example) + _turretPath = player call CBA_fnc_turretPath + (end) + +Returns: + Soldiers turret path. [] when on foot, driver or in cargo + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(turretPath); + +params [["_unit", objNull, [objNull]]]; + +private _vehicle = vehicle _unit; + +(allTurrets [_vehicle, true] select {(_vehicle turretUnit _x) isEqualTo _unit}) param [0, []] diff --git a/addons/common/fnc_turretPathWeapon.sqf b/addons/common/fnc_turretPathWeapon.sqf new file mode 100644 index 000000000..758ce76aa --- /dev/null +++ b/addons/common/fnc_turretPathWeapon.sqf @@ -0,0 +1,31 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_turretPathWeapon + +Description: + A function used to report the turret path belonging to a weapon of given vehicle. + Reverse version of the weaponsTurret scripting command. + +Parameters: + _vehicle - a vehicle with turrets + _weapon - a weapon in the vehicles turret + +Example: + (begin example) + _turretPath = [cameraOn, "HMG_127_mbt"] call CBA_fnc_turretPathWeapon + (end) + +Returns: + Weapons turret path. [-1] for driver weapon. [] when weapon not found. + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(turretPathWeapon); + +params [["_vehicle", objNull, [objNull]], ["_weapon", "", [""]]]; + +private _turrets = allTurrets _vehicle; +_turrets pushBack [-1]; + +(_turrets select {{_x == _weapon} count (_vehicle weaponsTurret _x) > 0}) param [0, []] diff --git a/addons/common/fnc_getVehicleRole.sqf b/addons/common/fnc_vehicleRole.sqf similarity index 88% rename from addons/common/fnc_getVehicleRole.sqf rename to addons/common/fnc_vehicleRole.sqf index 5719d8b17..7bfadf62b 100644 --- a/addons/common/fnc_getVehicleRole.sqf +++ b/addons/common/fnc_vehicleRole.sqf @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Function: CBA_fnc_getVehicleRole +Function: CBA_fnc_vehicleRole Description: A function used to report the soldiers role in his current vehicle. @@ -10,7 +10,7 @@ Parameters: Example: (begin example) - _role = player call CBA_fnc_getVehicleRole + _role = player call CBA_fnc_vehicleRole (end) Returns: @@ -20,7 +20,7 @@ Author: commy2 ---------------------------------------------------------------------------- */ #include "script_component.hpp" -SCRIPT(getVehicleRole); +SCRIPT(vehicleRole); params [["_unit", objNull, [objNull]]]; From c7d98a633aeb0d1d7666328fad0ec872e2b54cd0 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 21:46:34 +0100 Subject: [PATCH 15/18] remove obsolete init_functionsModule --- addons/common/XEH_postInit.sqf | 16 +---- addons/common/XEH_preClientInit.sqf | 8 ++- addons/common/XEH_preInit.sqf | 11 ++- addons/common/init_actionmonitor.sqf | 13 ---- addons/common/init_delayLess.sqf | 5 +- addons/common/init_functionsModule.sqf | 94 -------------------------- 6 files changed, 22 insertions(+), 125 deletions(-) delete mode 100644 addons/common/init_actionmonitor.sqf delete mode 100644 addons/common/init_functionsModule.sqf diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index a61c610e8..aca26e9ad 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -16,15 +16,6 @@ LOG(MSG_INIT); #endif }; -FUNC(log) = { - diag_log text _this; - _this spawn { - sleep 1; - systemChat _this; - hintC _this; - }; -}; - // Upgrade check - Registry for removed addons, warn the user if found // TODO: Evaluate registry of 'current addons' and verifying that against available CfgPatches TRACE_1("Upgrade Check",nil); @@ -53,8 +44,8 @@ FUNC(initPerFrameHandlers) = { GVAR(lastFrameRender) = diag_frameNo; // Use a trigger, runs every 0.5s, unscheduled execution - GVAR(perFrameTrigger) = createTrigger["EmptyDetector", [0,0,0], false]; - GVAR(perFrameTrigger) setTriggerStatements[QUOTE(call FUNC(monitorFrameRender)), "", ""]; + GVAR(perFrameTrigger) = createTrigger ["EmptyDetector", [0,0,0], false]; + GVAR(perFrameTrigger) setTriggerStatements [QUOTE(call FUNC(monitorFrameRender)), "", ""]; }; // Run the per frame handler init code, bringing up the hidden map control @@ -74,9 +65,8 @@ if (hasInterface) then { [FUNC(synchTeamColors), 1, []] call CBA_fnc_addPerFrameHandler; if (didJIP) then { - private "_team"; { - _team = _x getVariable [QGVAR(synchedTeam), ""]; + private _team = _x getVariable [QGVAR(synchedTeam), ""]; if (_team != "") then { _x assignTeam _team; }; diff --git a/addons/common/XEH_preClientInit.sqf b/addons/common/XEH_preClientInit.sqf index e56b82c21..bc2989484 100644 --- a/addons/common/XEH_preClientInit.sqf +++ b/addons/common/XEH_preClientInit.sqf @@ -2,4 +2,10 @@ LOG(MSG_INIT); -call COMPILE_FILE(init_actionmonitor); +if (hasInterface) then { + // ArmA - actionmonitor.sqf v1.0 Original by BN880, converted by Sickboy (sb_at_dev-heaven.net), 6th Sense - Share the Spirit + GVAR(actionList) = [] call CBA_fnc_hashCreate; + GVAR(actionListUpdated) = false; // Set true to force recreation of actions. + GVAR(nextActionIndex) = 0; // Next index that will be given out. + GVAR(actionListPFEH) = false; +}; diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 2682d52c1..e20237641 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -2,14 +2,21 @@ #include "script_component.hpp" SCRIPT(XEH_preInit); -[] call COMPILE_FILE(init_functionsModule); // @todo - LOG(MSG_INIT); ADDON = false; CBA_logic = objNull; +FUNC(log) = { + diag_log text _this; + _this spawn { + sleep 1; + systemChat _this; + hintC _this; + }; +}; + // FSM GVAR(delayless) = QUOTE(PATHTOF(delayless.fsm)); GVAR(delayless_loop) = QUOTE(PATHTOF(delayless_loop.fsm)); diff --git a/addons/common/init_actionmonitor.sqf b/addons/common/init_actionmonitor.sqf deleted file mode 100644 index 8bfb590f7..000000000 --- a/addons/common/init_actionmonitor.sqf +++ /dev/null @@ -1,13 +0,0 @@ -// #define DEBUG_MODE_FULL -#include "script_component.hpp" -/////////////////////////////////////////////////////////// -// ArmA - actionmonitor.sqf v1.0 Original by BN880, converted by Sickboy (sb_at_dev-heaven.net), 6th Sense - Share the Spirit -// THIS IS FOR PLAYER ACTIONS ONLY CoC Bn880 11/2003 -/////////////////////////////////////////////////////////// - - -GVAR(actionList) = [] call CBA_fnc_hashCreate; -GVAR(actionListUpdated) = false; // Set true to force recreation of actions. -GVAR(nextActionIndex) = 0; // Next index that will be given out. -GVAR(actionListPFEH) = false; - diff --git a/addons/common/init_delayLess.sqf b/addons/common/init_delayLess.sqf index ba35cac03..02a1a8a5c 100644 --- a/addons/common/init_delayLess.sqf +++ b/addons/common/init_delayLess.sqf @@ -3,6 +3,7 @@ // Generic twice-a-second loop instantiator(?) GVAR(d) = []; + FUNC(addTriggerHandler) = { private ["_c"]; // #include "script_component.hpp" @@ -12,9 +13,9 @@ FUNC(addTriggerHandler) = { // Create the trigger, only on first use if (isNil QGVAR(d_trigger)) then { - GVAR(d_trigger) = createTrigger["EmptyDetector", [0,0], false]; + GVAR(d_trigger) = createTrigger ["EmptyDetector", [0,0], false]; GVAR(d_trigger) setTriggerActivation ["ANY", "PRESENT", true]; - GVAR(d_trigger) setTriggerStatements["{ if (count _x == 2) then { (_x select 0) call (_x select 1) } } forEach cba_common_d", "", ""]; + GVAR(d_trigger) setTriggerStatements ["{ if (count _x == 2) then { (_x select 0) call (_x select 1) } } forEach cba_common_d", "", ""]; }; _c; // return index, so can either change array parameter count, or empty? }; diff --git a/addons/common/init_functionsModule.sqf b/addons/common/init_functionsModule.sqf deleted file mode 100644 index 35eb05a4c..000000000 --- a/addons/common/init_functionsModule.sqf +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Prepare BIS functions/MP and precompile all functions we already have - * registered with it. In order to have the functions loaded early, - * we do so in the "init_functionsModule" script. However, to make sure - * everything is done properly, we also create a new BIS functions manager - * module so that the whole BIS MP and functions framework is initialised - * completely. (We need to do it this way since the BIS function manager - * defers initialisation by way of execVM:ing its init script.) - * - * Yes, there's some redundancy in that the functions will be - * loaded and preprocessed twice, but this should only occur once per mission - * and will hopefully ensure forward compatibility with future ArmA II patches. - */ - -// Modified by Spooner for CBA in order to allow function initialisation -// in preinit phase. - -//#define DEBUG_MODE_FULL -#include "script_component.hpp" -scriptName "CBA\common\init_functionsModule"; - -// #define DO_NOT_STORE_IN_MISSION_NS - -private ["_recompile"]; -_recompile = (count _this) > 0; - -if (isNil "CBA_FUNC_RECOMPILE") then { CBA_FUNC_RECOMPILE = ["functions"] call CBA_fnc_isRecompileEnabled; }; -if (CBA_FUNC_RECOMPILE) then { _recompile = true }; - - - -#ifdef DEBUG_MODE_FULL - _timeStart = diag_tickTime; - diag_log [diag_frameNo, diag_tickTime, time, "Initializing function module", _this, _recompile, CBA_FUNC_RECOMPILE, BIS_fnc_init]; - - GVAR(fncInitTest) = { - if (isNil "BIS_fnc_areEqual_uiNamespace") then { BIS_fnc_areEqual_uiNamespace = uiNamespace getVariable "BIS_fnc_areEqual"; }; - if (isNil "BIS_fnc_init_uiNamespace") then { BIS_fnc_init_uiNamespace = uiNamespace getVariable "BIS_fnc_init"; }; - // It seems that in A3 the missionNamespace copy of BIS_fnc_init and all other funcs are delayed in their inits (not available for the Briefing or XEH PreInit Phase. -VM - - if (isNil "CBA_fnc_globalExecute") then { diag_log [diag_frameNo, diag_tickTime, time, "CBA_fnc_globalExecute(missionNamespace) is nil!"]} else { //TRACE_1("",CBA_fnc_globalExecute); }; - - if (isNil "BIS_fnc_areEqual") then { diag_log [diag_frameNo, diag_tickTime, time,"BIS_fnc_areEqual(missionNamespace) is nil!"]}; - - if (isNil "BIS_fnc_areEqual_uiNamespace") then { diag_log [diag_frameNo, diag_tickTime, time,"BIS_fnc_areEqual(uiNamespace) is nil!"]}; - if (isNil "BIS_fnc_init") then { diag_log [diag_frameNo, diag_tickTime, time,"BIS_fnc_init(missionNamespace) is nil!"]}; - if (isNil "BIS_fnc_init_uiNamespace") then { diag_log [diag_frameNo, diag_tickTime, time,"BIS_fnc_init(uiNamespace) is nil!"]} else { TRACE_1("",BIS_fnc_init_uiNamespace) }; - }; -#endif - -#ifdef DEBUG_MODE_FULL - diag_log [diag_frameNo, diag_tickTime, time, diag_tickTime - _timeStart, "Function module starting."]; - // Function Tests - 0 Call GVAR(fncInitTest); -#endif - -//--- Functions are already running -if (BIS_fnc_init && {!_recompile}) exitWith {}; // A3 build 0.11.103003 => observing that during the preInit phase, BIS_fnc_init (uiNamespace) is true, however BIS_fnc_init (missionNamespace) is false - -LOG("CBA: Initialising the Functions module early."); -// The call is used to convert the code to an array -if (isNil QGVAR(BIS_functions_list)) then { GVAR(BIS_functions_list) = call (uiNamespace getVariable "BIS_functions_list"); }; -if (isNil QGVAR(BIS_functions_listForced)) then { GVAR(BIS_functions_listForced) = call (uiNamespace getVariable "BIS_functions_listForced"); }; - - -//----------------------------------------------------------------------------- -//--- PREPROCESS -------------------------------------------------------------- -//----------------------------------------------------------------------------- - - { - _xCode = uinamespace getvariable _x; - - if (isNil "_x") then { - diag_log [diag_frameNo, diag_tickTime, time, diag_tickTime - _timeStart, format["CBA: Exporting %1 to missionNamespace", _x]]; - missionNamespace setvariable [_x,_xCode]; - }; - - } foreach GVAR(BIS_functions_list); - - -private ["_test", "_test2"]; -_test = (_this select 0) setPos (position (_this select 0)); if (isnil "_test") then {_test = false}; -_test2 = (_this select 0) playMove ""; if (isnil "_test2") then {_test2 = false}; -if (_test || {_test2}) then {0 call COMPILE_FILE2(ca\modules\functions\misc\fn_initCounter.sqf) }; - -//-------------------------------------------------------------------------------------------------------- -//--- INIT COMPLETE -------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------------- - -#ifdef DEBUG_MODE_FULL - diag_log [diag_frameNo, diag_tickTime, time, diag_tickTime - _timeStart, "Function module done!"]; - // Function Tests - 0 Call GVAR(fncInitTest); -#endif From 948bcf812b075f1f41152e56b87af192ebe19c75 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 22:11:05 +0100 Subject: [PATCH 16/18] add RPT warnings to deprecated functions --- addons/common/backwards_comp.sqf | 52 ++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/addons/common/backwards_comp.sqf b/addons/common/backwards_comp.sqf index d829cfbac..3734a1f5d 100644 --- a/addons/common/backwards_comp.sqf +++ b/addons/common/backwards_comp.sqf @@ -1,43 +1,77 @@ CBA_fnc_createCenter = { + WARNING('Deprecated function used: OLD_FUNCTION'); params ["_side"]; _side }; -CBA_fnc_players = {allPlayers}; -CBA_fnc_locked = {locked _this > 1}; +CBA_fnc_players = { + WARNING('Deprecated function used: CBA_fnc_players (new: allPlayers)'); + allPlayers +}; + +CBA_fnc_locked = { + WARNING('Deprecated function used: CBA_fnc_locked (new: locked)'); + locked _this > 1 +}; CBA_fnc_getPistol = { + WARNING('Deprecated function used: CBA_fnc_getPistol (new: handgunWeapon)'); params [["_unit", objNull, [objNull]]]; handgunWeapon _unit }; CBA_fnc_systemChat = { + WARNING('Deprecated function used: CBA_fnc_systemChat (new: systemChat)'); params [["_message", "", [""]]]; systemChat _message; }; CBA_fnc_defaultParam = { + WARNING('Deprecated function used: CBA_fnc_defaultParam (new: param)'); params [["_params", []], ["_index", -1, [0]], "_defaultValue"]; if (_index < 0) exitWith {_defaultValue}; _params param [_index, _defaultValue] }; -CBA_fnc_determineMuzzles = CBA_fnc_getMuzzles; +CBA_fnc_addWeaponCargoGlobal = { + WARNING('Deprecated function used: CBA_fnc_addWeaponCargoGlobal (new: CBA_fnc_addWeaponCargo)'); + _this call CBA_fnc_addWeaponCargo; +}; -CBA_fnc_addWeaponCargoGlobal = CBA_fnc_addWeaponCargo; -CBA_fnc_addMagazineCargoGlobal = CBA_fnc_addMagazineCargo; -CBA_fnc_removeWeaponCargoGlobal = CBA_fnc_removeWeaponCargo; -CBA_fnc_removeMagazineCargoGlobal = CBA_fnc_removeMagazineCargo; -CBA_fnc_removeItemCargoGlobal = CBA_fnc_removeItemCargo; -CBA_fnc_removeBackpackCargoGlobal = CBA_fnc_removeBackpackCargo; +CBA_fnc_addMagazineCargoGlobal = { + WARNING('Deprecated function used: CBA_fnc_addMagazineCargoGlobal (new: CBA_fnc_addMagazineCargo)'); + _this call CBA_fnc_addMagazineCargo; +}; + +CBA_fnc_removeWeaponCargoGlobal = { + WARNING('Deprecated function used: CBA_fnc_removeWeaponCargoGlobal (new: CBA_fnc_removeWeaponCargo)'); + _this call CBA_fnc_removeWeaponCargo; +}; + +CBA_fnc_removeMagazineCargoGlobal = { + WARNING('Deprecated function used: CBA_fnc_removeMagazineCargoGlobal (new: CBA_fnc_removeMagazineCargo)'); + _this call CBA_fnc_removeMagazineCargo; +}; + +CBA_fnc_removeItemCargoGlobal = { + WARNING('Deprecated function used: CBA_fnc_removeItemCargoGlobal (new: CBA_fnc_removeItemCargo)'); + _this call CBA_fnc_removeItemCargo; +}; + +CBA_fnc_removeBackpackCargoGlobal = { + WARNING('Deprecated function used: CBA_fnc_removeBackpackCargoGlobal (new: CBA_fnc_removeBackpackCargo)'); + _this call CBA_fnc_removeBackpackCargo; +}; FUNC(directCall) = { + WARNING('Deprecated function used: FUNC(directCall) (new: CBA_fnc_directCall)'); params ["_params", "_code"]; [_code, _params] call CBA_fnc_directCall; }; CBA_fnc_intToString = { + WARNING('Deprecated function used: CBA_fnc_intToString (new: str)'); params [["_int", nil, [0]]]; if (isNil "_int") exitWith {""}; str _int From e03e2016dc00c5b42933db9c8a07165286b62496 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 4 Mar 2016 22:27:35 +0100 Subject: [PATCH 17/18] fix paths to test sqfs --- addons/common/test.sqf | 2 +- addons/common/test_config.sqf | 2 +- addons/common/test_inventory.sqf | 2 +- addons/hashes/test_parseYaml.sqf | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/common/test.sqf b/addons/common/test.sqf index edaedeefe..1d0dc38a7 100644 --- a/addons/common/test.sqf +++ b/addons/common/test.sqf @@ -5,7 +5,7 @@ #define DEBUG_MODE_FULL #include "script_component.hpp" -#define TESTS ["inheritsFrom", "parseYaml"] +#define TESTS ["config", "inventory"] SCRIPT(test-common); diff --git a/addons/common/test_config.sqf b/addons/common/test_config.sqf index 3e11adad2..f3d912a3c 100644 --- a/addons/common/test_config.sqf +++ b/addons/common/test_config.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" SCRIPT(test_config); -// 0 spawn compile preprocessFileLineNumbers "\x\cba\addons\common\config\test_config.sqf"; +// 0 spawn compile preprocessFileLineNumbers "\x\cba\addons\common\test_config.sqf"; private ["_funcName", "_result"]; diff --git a/addons/common/test_inventory.sqf b/addons/common/test_inventory.sqf index 0a8aabc50..8f8b6f799 100644 --- a/addons/common/test_inventory.sqf +++ b/addons/common/test_inventory.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" SCRIPT(test_config); -// 0 spawn compile preprocessFileLineNumbers "\x\cba\addons\common\inventory\test_inventory.sqf"; +// 0 spawn compile preprocessFileLineNumbers "\x\cba\addons\common\test_inventory.sqf"; // Note: test requires a player with space in inventory diff --git a/addons/hashes/test_parseYaml.sqf b/addons/hashes/test_parseYaml.sqf index 795e779aa..e82db8920 100644 --- a/addons/hashes/test_parseYaml.sqf +++ b/addons/hashes/test_parseYaml.sqf @@ -13,7 +13,7 @@ LOG("Testing " + _fn); TEST_DEFINED("CBA_fnc_parseYaml",_fn); -_data = ["\x\cba\addons\common\test_parseYaml_config.yml"] call CBA_fnc_parseYaml; +_data = ["\x\cba\addons\hashes\test_parseYaml_config.yml"] call CBA_fnc_parseYaml; TEST_TRUE([_data] call CBA_fnc_isHash,_fn); From b60eb4aa7f53f83fa314614714aae6cbee1837ee Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 5 Mar 2016 11:34:00 +0100 Subject: [PATCH 18/18] OLD_FUNCTION -> CBA_fnc_createCenter --- addons/common/backwards_comp.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/backwards_comp.sqf b/addons/common/backwards_comp.sqf index 3734a1f5d..99bf8c346 100644 --- a/addons/common/backwards_comp.sqf +++ b/addons/common/backwards_comp.sqf @@ -1,6 +1,6 @@ CBA_fnc_createCenter = { - WARNING('Deprecated function used: OLD_FUNCTION'); + WARNING('Deprecated function used: CBA_fnc_createCenter'); params ["_side"]; _side };