mirror of
https://github.com/EpochModTeam/Epoch.git
synced 2024-08-30 18:22:13 +00:00
move weightedArray to Cfgfunctions for both server and client use
This commit is contained in:
parent
a81088645c
commit
e4903fd870
71
Sources/epoch_code/compile/both/EPOCH_weightedArray.sqf
Normal file
71
Sources/epoch_code/compile/both/EPOCH_weightedArray.sqf
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Author: Aaron Clark - EpochMod.com
|
||||
|
||||
Contributors:
|
||||
|
||||
Description:
|
||||
Generates loot tables from configs
|
||||
|
||||
Licence:
|
||||
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
|
||||
|
||||
Github:
|
||||
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/both/EPOCH_weightedArray.sqf
|
||||
*/
|
||||
//[[[cog import generate_private_arrays ]]]
|
||||
private ["_allow","_lootIndex","_lootTableArray","_lootTableName","_return","_value","_weightedArray"];
|
||||
//[[[end]]]
|
||||
params ["_configName","_keyName","_arrayName"];
|
||||
|
||||
_lootTableName = format["EPOCH_LT_%1_%2_%3",_configName,_keyName,_arrayName];
|
||||
_return = missionNamespace getVariable[_lootTableName,[]];
|
||||
|
||||
// check for compiled loot table
|
||||
if(_return isEqualTo[]) then {
|
||||
// Since no cached version is found, make one.
|
||||
_lootTableArray = [];
|
||||
_weightedArray = [];
|
||||
_lootIndex = 0;
|
||||
{
|
||||
if(_x isEqualType []) then {
|
||||
_x params ["_tname","_tqty",["_extraLogicRaw", [] ]];
|
||||
_allow = true;
|
||||
if !(_extraLogicRaw isEqualTo[]) then {
|
||||
_extraLogicRaw params [["_extraLogicType",""],["_extraLogicName",""],["_extraLogicCond",""],["_extraLogicData",""]];
|
||||
// check extra logic
|
||||
_value = switch _extraLogicType do {
|
||||
case "getDate": {
|
||||
date select _extraLogicName
|
||||
};
|
||||
case "getSunorMoon": {
|
||||
sunOrMoon
|
||||
};
|
||||
case "getMissionNamespaceVariable": {
|
||||
missionNamespace getVariable [_extraLogicName, _extraLogicData]
|
||||
};
|
||||
// not really needed
|
||||
default {
|
||||
_extraLogicName
|
||||
};
|
||||
};
|
||||
_allow = [_value,_extraLogicCond,_extraLogicData] call EPOCH_fnc_arrayToLogic;
|
||||
};
|
||||
if (_allow) then {
|
||||
_lootTableArray pushBack _tname;
|
||||
for "_i" from 1 to _tqty do {
|
||||
_weightedArray pushBack _lootIndex;
|
||||
};
|
||||
_lootIndex = _lootIndex + 1;
|
||||
};
|
||||
} else {
|
||||
_lootTableArray pushBack _x;
|
||||
_weightedArray pushBack _lootIndex;
|
||||
_lootIndex = _lootIndex + 1;
|
||||
};
|
||||
}forEach getArray((_configName call EPOCH_returnConfig) >> _keyName >> _arrayName);
|
||||
_return = [_lootTableArray,_weightedArray];
|
||||
// cache loot final loot table
|
||||
missionNamespace setVariable[_lootTableName,_return];
|
||||
};
|
||||
|
||||
_return
|
@ -31,6 +31,10 @@ class cfgFunctions
|
||||
class isAny
|
||||
{
|
||||
file = "epoch_code\compile\both\EPOCH_isAny.sqf";
|
||||
};
|
||||
class weightedArray
|
||||
{
|
||||
file = "epoch_code\compile\both\EPOCH_weightedArray.sqf";
|
||||
};
|
||||
class compiler
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ if (isnull _object && !(_pos isequalto [])) then {
|
||||
_object = createVehicle ["groundWeaponHolder",_pos,[],0,"CAN_COLLIDE"];
|
||||
};
|
||||
if !(isNull _object) then{
|
||||
_lootTable = [_type, "CfgMainTable", "tables"] call EPOCH_weightedArray;
|
||||
_lootTable = ["CfgMainTable", _type, "tables"] call EPOCH_fnc_weightedArray;
|
||||
_lootTable params ["_lootTableArray","_weightedArray"];
|
||||
if !(_lootTableArray isEqualTo []) then {
|
||||
_loots = [];
|
||||
@ -41,7 +41,7 @@ if !(isNull _object) then{
|
||||
_loots pushBack (_lootTableArray select(selectRandom _weightedArray));
|
||||
};
|
||||
{
|
||||
_lootItemWeightedArray = [_x, _lootTableClass, "items"] call EPOCH_weightedArray;
|
||||
_lootItemWeightedArray = [_lootTableClass, _x, "items"] call EPOCH_fnc_weightedArray;
|
||||
_lootItemArray = _lootItemWeightedArray select 0;
|
||||
if !(_lootItemArray isEqualTo[]) then {
|
||||
_weightedItemArray = _lootItemWeightedArray select 1;
|
||||
@ -106,7 +106,7 @@ if !(isNull _object) then{
|
||||
};
|
||||
case "CfgLootTable": {
|
||||
// go down the rabit hole
|
||||
_lootItemWeightedArray = [_randomItem, _lootTableClass, "items"] call EPOCH_weightedArray;
|
||||
_lootItemWeightedArray = [_lootTableClass, _randomItem, "items"] call EPOCH_fnc_weightedArray;
|
||||
_lootItemArray = _lootItemWeightedArray select 0;
|
||||
if !(_lootItemArray isEqualTo[]) then {
|
||||
_weightedItemArray = _lootItemWeightedArray select 1;
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
Author: Aaron Clark - EpochMod.com
|
||||
|
||||
Contributors:
|
||||
|
||||
Description:
|
||||
Uses Epoch server extension to perform various functions like: kick, ban, shutdown, message, unlock/lock
|
||||
|
||||
Licence:
|
||||
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
|
||||
|
||||
Github:
|
||||
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_server/EPOCH_weightedArray.sqf
|
||||
*/
|
||||
//[[[cog import generate_private_arrays ]]]
|
||||
private ["_lootIndex","_lootTableArray","_return","_weightedArray"];
|
||||
//[[[end]]]
|
||||
params ["_keyName","_configName","_arrayName"];
|
||||
_return = missionNamespace getVariable[format["EPOCH_LT_%1_%2_%3",_configName,_keyName,_arrayName],[]];
|
||||
if(_return isEqualTo[]) then {
|
||||
_lootTableArray = [];
|
||||
_weightedArray = [];
|
||||
_lootIndex = 0;
|
||||
{
|
||||
if(_x isEqualType []) then {
|
||||
_x params ["_tname","_tqty"];
|
||||
if (!(_tname isEqualTo "Zombie") || (_tname isEqualTo "Zombie") && EPOCH_mod_Ryanzombies_Enabled) then {
|
||||
_lootTableArray pushBack _tname;
|
||||
for "_i" from 1 to _tqty do {
|
||||
_weightedArray pushBack _lootIndex;
|
||||
};
|
||||
_lootIndex = _lootIndex + 1;
|
||||
};
|
||||
} else {
|
||||
if (!(_x isEqualTo "Zombie") || (_x isEqualTo "Zombie") && EPOCH_mod_Ryanzombies_Enabled) then {
|
||||
_lootTableArray pushBack _x;
|
||||
_weightedArray pushBack _lootIndex;
|
||||
_lootIndex = _lootIndex + 1;
|
||||
};
|
||||
};
|
||||
}forEach getArray(configFile >> _configName >> _keyName >> _arrayName);
|
||||
_return = [_lootTableArray,_weightedArray];
|
||||
missionNamespace setVariable[format["EPOCH_LT_%1_%2_%3",_configName,_keyName,_arrayName],_return];
|
||||
// diag_log format["EPOCH_LT_%1_%2_%3 = %4",_configName,_keyName,_arrayName,_return];
|
||||
};
|
||||
_return
|
@ -101,7 +101,6 @@ class CfgServerFunctions
|
||||
class server_CargoFill {};
|
||||
};
|
||||
class epoch_server {
|
||||
class weightedArray {};
|
||||
class precisionPos {};
|
||||
class serverLootObject {};
|
||||
class server_vehicleInit {};
|
||||
|
Loading…
Reference in New Issue
Block a user