2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-10-06 08:18:14 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
2019-10-08 00:41:46 +00:00
|
|
|
* Returns the arithmetic result of performing the given operation on a set.
|
2016-10-06 08:18:14 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2019-10-08 00:41:46 +00:00
|
|
|
* 0: Namespace <OBJECT|LOCATION|NAMESPACE>
|
2016-10-06 08:18:14 +00:00
|
|
|
* 1: Number Set ID <STRING>
|
2019-10-08 00:41:46 +00:00
|
|
|
* 2: Operation (max, min, sum, product, avg) (Case Sensitive) <STRING>
|
2016-10-06 08:18:14 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* Value <NUMBER>
|
2016-10-06 08:18:14 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [ace_player, "ace_aimCoefficents", "product"] call ace_common_fnc_arithmeticGetResult
|
|
|
|
* [missionNameSpace, "ace_hearing", "min"] call ace_common_fnc_arithmeticGetResult
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
2019-10-08 00:41:46 +00:00
|
|
|
params ["_namespace", "_setID", "_operation"];
|
|
|
|
TRACE_3("arithmeticGetResult",_namespace,_setID,_operation);
|
2016-10-06 08:18:14 +00:00
|
|
|
|
2021-10-11 18:57:15 +00:00
|
|
|
private _hash = _namespace getVariable [_setID, createHashMapFromArray [["empty", {0}]]];
|
|
|
|
private _data = values _hash;
|
2016-10-06 08:18:14 +00:00
|
|
|
|
2019-10-08 00:41:46 +00:00
|
|
|
switch (_operation) do {
|
|
|
|
case "max": {
|
|
|
|
selectMax (_data apply {call _x})
|
|
|
|
};
|
|
|
|
case "min": {
|
|
|
|
selectMin (_data apply {call _x})
|
2019-05-12 04:13:59 +00:00
|
|
|
};
|
2019-10-08 00:41:46 +00:00
|
|
|
case "sum": {
|
2016-10-06 08:18:14 +00:00
|
|
|
private _result = 0;
|
2019-10-08 00:41:46 +00:00
|
|
|
|
2016-10-06 08:18:14 +00:00
|
|
|
{
|
2019-10-08 00:41:46 +00:00
|
|
|
_result = _result + call _x;
|
|
|
|
} forEach _data;
|
|
|
|
|
|
|
|
_result
|
2016-10-06 08:18:14 +00:00
|
|
|
};
|
2019-10-08 00:41:46 +00:00
|
|
|
case "product": {
|
2016-10-06 08:18:14 +00:00
|
|
|
private _result = 1;
|
2019-10-08 00:41:46 +00:00
|
|
|
|
2016-10-06 08:18:14 +00:00
|
|
|
{
|
2019-10-08 00:41:46 +00:00
|
|
|
_result = _result * call _x;
|
|
|
|
} forEach _data;
|
|
|
|
|
|
|
|
_result
|
2016-10-06 08:18:14 +00:00
|
|
|
};
|
2019-10-08 00:41:46 +00:00
|
|
|
case "avg": {
|
2016-10-06 08:18:14 +00:00
|
|
|
private _result = 0;
|
2019-10-08 00:41:46 +00:00
|
|
|
|
2016-10-06 08:18:14 +00:00
|
|
|
{
|
2019-10-08 00:41:46 +00:00
|
|
|
_result = _result + call _x;
|
|
|
|
} forEach _data;
|
|
|
|
|
|
|
|
_result / count _data
|
2016-10-06 08:18:14 +00:00
|
|
|
};
|
|
|
|
default {3735928559};
|
|
|
|
};
|