Some compiles, start separation of blood system

This commit is contained in:
icomrade
2016-02-27 09:56:53 -05:00
parent 61cbd16de1
commit 18c9e72e15
13 changed files with 684 additions and 2006 deletions

View File

@@ -5,21 +5,22 @@ scriptName "Functions\arrays\fn_selectRandomWeighted.sqf";
Description:
Function to select a random item from an array, taking into account item weights.
The weights should be Numbers between 0 && 1, with a maximum precision of hundreds.
The weights should be Numbers between 0 and 1, with a maximum precision of hundreds.
Parameter(s):
_this select 0: source Array (Array of Any Value)
_this select 1: weights (Array of Number)
Returns:
Any Value selected item
TODO:
[*] Algorithm is inefficient?
*/
private ["_weights","_weighted"];
//_array = _this select 0;
private["_weighted"];
_array = _this select 0;
_weights = _this select 1;
/*
@@ -31,7 +32,7 @@ if ((count _array) > (count _weights)) exitWith {debugLog "Log: [selectRandomWei
//Created weighted array of indices.
_weighted = [];
for "_i" from 0 to ((count _weights) - 1) do
for "_i" from 0 to ((count _weights) - 1) do
{
private ["_weight"];
_weight = _weights select _i;
@@ -39,17 +40,17 @@ for "_i" from 0 to ((count _weights) - 1) do
//Ensure the weight is a Number.
//If it's not, set weight to 0 to exclude it.
if ((typeName _weight) != (typeName 0)) then {diag_log "Log: [selectRandomWeighted] Weights should be Numbers; weight set to 0!"; _weight = 0};
//The weight should be a Number between 0 && 1.
if (_weight < 0) then {diag_log "Log: [selectRandomWeighted] Weights should be more than || equal to 0; weight set to 0!"; _weight = 0};
//if (_weight > 1) then {debugLog "Log: [selectRandomWeighted] Weights should be less than || equal to 1; weight set to 1!"; _weight = 1};
//The weight should be a Number between 0 and 1.
if (_weight < 0) then {diag_log "Log: [selectRandomWeighted] Weights should be more than or equal to 0; weight set to 0!"; _weight = 0};
//if (_weight > 1) then {debugLog "Log: [selectRandomWeighted] Weights should be less than or equal to 1; weight set to 1!"; _weight = 1};
//Normalize the weight for a precision of hundreds.
_weight = round(_weight * 100);
for "_k" from 0 to (_weight - 1) do
for "_k" from 0 to (_weight - 1) do
{
_weighted = _weighted + [_i];
_weighted set [(count _weighted), _i];
};
};
_weighted