unify EPOCH_worldObjectType logic

EPOCH_worldObjectType now supports objects and object string names
This commit is contained in:
vbawol 2017-06-04 19:22:56 -05:00
parent 934b324c35
commit 684bff7e08
7 changed files with 81 additions and 84 deletions

View File

@ -13,7 +13,7 @@
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_chopWood.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_config","_currentPos","_getWorldTypes","_object","_objects","_sel_object","_str","_type","_worldTypes"];
private ["_currentPos","_getWorldTypes","_object","_objects","_sel_object","_type","_worldTypes"];
//[[[end]]]
_currentPos = player modelToWorld[0, 5, 0];
@ -24,13 +24,11 @@ if !(surfaceIsWater _currentPos) then {
_objects = lineIntersectsObjs[eyePos player, _currentPos, player, objNull, true, 2];
_object = objNull;
_type = 0;
_config = 'CfgEpochClient' call EPOCH_returnConfig;
{
_str = str _x;
_sel_object = _x;
_worldTypes = ["tree","bush"];
_getWorldTypes = [_str, _worldTypes] call EPOCH_worldObjectType;
_getWorldTypes = [_x, _worldTypes] call EPOCH_worldObjectType;
{
if (_getWorldTypes param [_worldTypes find _x, false]) exitWith {
_type = _forEachIndex;

View File

@ -13,19 +13,19 @@
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_lootTrash.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_animal","_animalPos","_animals","_bankTerminal","_blood","_bloodPos","_cfgItemInteractions","_cfgObjectInteractions","_config","_configWorldInteractions","_configWorldName","_destroyTrashObj","_found","_foundLootObject","_foundObjConfig","_foundObjType","_foundTerminal","_foundWorldConfig","_getWorldTypes","_id","_index","_inputWorldTypes","_interactAttributes","_lootAnimalObj","_objects","_output","_randomAIClass","_return","_trashType"];
private ["_animal","_animalPos","_animals","_bankTerminal","_blood","_bloodPos","_cfgItemInteractions","_cfgObjectInteractions","_config","_configWorldName","_destroyTrashObj","_found","_foundLootObject","_foundObjConfig","_foundObjType","_foundTerminal","_getWorldTypes","_id","_index","_inputWorldTypes","_interactAttributes","_lootAnimalObj","_objects","_output","_randomAIClass","_return","_trashClasses","_trashType"];
//[[[end]]]
_return = false;
if (diag_tickTime - EPOCH_lastTrash > 2) then {
EPOCH_lastTrash = diag_tickTime;
_config = 'CfgEpochClient' call EPOCH_returnConfig;
_configWorldInteractions = (_config >> "CfgWorldInteractions");
_configWorldName = (_config >> worldname);
_interactAttributes = [];
_cfgObjectInteractions = 'CfgObjectInteractions' call EPOCH_returnConfig;
_inputWorldTypes = ["bankTerminal"];
_inputWorldTypes append getArray(_configWorldName >> "TrashClasses");
_trashClasses = getArray(_config >> worldname >> "TrashClasses");
_inputWorldTypes append _trashClasses;
_destroyTrashObj = objNull;
_lootAnimalObj = objNull;
@ -36,30 +36,22 @@ if (diag_tickTime - EPOCH_lastTrash > 2) then {
_found = false;
_foundTerminal = false;
_foundLootObject = false;
if !(_x isKindOf "All") then {
_foundObjType = typeOf _x;
_foundObjConfig = (_cfgObjectInteractions >> _foundObjType);
if (alive _x) then {
_getWorldTypes = [str(_x), _inputWorldTypes] call EPOCH_worldObjectType;
_getWorldTypes = [_x, _inputWorldTypes] call EPOCH_worldObjectType;
{
_found = _getWorldTypes param [_inputWorldTypes find _x, false];
if (_found) exitWith{ _trashType = _forEachIndex };
} forEach getArray(_configWorldName >> "TrashClasses");
} forEach _trashClasses;
_foundTerminal = _getWorldTypes param [_inputWorldTypes find "bankTerminal", false];
};
} else {
_foundObjType = typeOf _x;
_foundObjConfig = (_cfgObjectInteractions >> _foundObjType);
_foundWorldConfig = (_configWorldInteractions >> _foundObjType);
if (alive _x) then {
{
_found = (getNumber(_foundWorldConfig >> _x) == 1);
if (_found) exitWith{ _trashType = _forEachIndex };
} forEach getArray(_configWorldName >> "TrashClasses");
_foundTerminal = (getNumber(_foundWorldConfig >> "bankTerminal") == 1);
_foundLootObject = ((getNumber(_foundObjConfig >> "interactMode") == 3) && (getNumber (_foundObjConfig >> "aliveState") == 0));
} else {
_foundLootObject = (getNumber(_cfgObjectInteractions >> _foundObjType >> "interactMode") == 3);
};
_foundLootObject = (getNumber(_foundObjConfig >> "interactMode") == 3);
};
if (_found) exitWith{ _destroyTrashObj = _x };
if (_foundLootObject) exitWith{ _lootAnimalObj = _x };
if (_foundTerminal) exitWith{ _bankTerminal = _x };

View File

@ -13,7 +13,7 @@
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_mineRocks.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_config","_currentPos","_found","_foundIndex","_getWorldTypes","_object","_objects","_str","_worldTypes"];
private ["_currentPos","_found","_foundIndex","_getWorldTypes","_object","_objects","_worldTypes"];
//[[[end]]]
if ((diag_tickTime - EPOCH_lastMineRocks) >= 2) then {
EPOCH_lastMineRocks = diag_tickTime;
@ -27,22 +27,17 @@ if ((diag_tickTime - EPOCH_lastMineRocks) >= 2) then {
_objects = lineIntersectsWith[eyePos player, _currentPos, player, objNull, true];
_object = objNull;
_config = 'CfgEpochClient' call EPOCH_returnConfig;
_found = false;
_foundIndex = -1;
{
if !(_x isKindOf "All") then {
_str = str(_x);
_worldTypes = ["rock","cinder","wreck"];
_getWorldTypes = [_str, _worldTypes] call EPOCH_worldObjectType;
_getWorldTypes = [_x, _worldTypes] call EPOCH_worldObjectType;
{
if (_getWorldTypes param [_worldTypes find _x, false]) exitWith {
_found = true;
_foundIndex = _forEachIndex - 1;
};
} forEach _worldTypes;
};
if (_found)exitWith{_object = _x};
}foreach _objects;

View File

@ -13,41 +13,59 @@
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/functions/EPOCH_worldObjectType.sqf
Example:
_isTree = [_objectString, "tree"] call EPOCH_worldObjectType;
_isTree = [_object, "tree"] call EPOCH_worldObjectType;
Parameter(s):
_this select 0: STRING - string name of world object
_this select 0: STRING or OBJECT - string name or world object
_this select 1: STRING or ARRAY - type names ("tree","bush")
Returns:
BOOL or ARRAY of BOOLs
*/
//[[[cog import generate_private_arrays ]]]
private ["_config","_end","_finalConfig","_findStart","_isTree","_p3dName","_return","_start"];
private ["_config","_end","_finalConfig","_findStart","_isTree","_modelInfo","_p3dName","_return","_selectedConfig","_start"];
//[[[end]]]
params ["_str","_checkType"];
params ["_object","_checkType"];
_return = false;
_config = 'CfgEpochClient' call EPOCH_returnConfig;
// find start of p3d name
_findStart = _str find ": ";
if (_findStart != -1) then{
_start = _findStart + 2;
_end = (_str find ".") - _start;
_p3dName = _str select[_start, _end];
_config = ('CfgEpochClient' call EPOCH_returnConfig) >> "CfgWorldInteractions";
_selectedConfig = "";
if (_object isEqualType objNull) then {
if !(_object isKindOf "All") then {
_modelInfo = getModelInfo _object;
_p3dName = _modelInfo select 0;
// replace spaces and periods with underscores
(_p3dName splitString " .") joinString "_";
_selectedConfig = _p3dName;
} else {
_selectedConfig = typeOf _object;
};
} else {
_findStart = _object find ": ";
if (_findStart != -1) then{
_start = _findStart + 2;
_end = (_object find ".") - _start;
_p3dName = _object select[_start, _end];
// replace spaces with underscores
if (_p3dName find " " != -1) then {
(_p3dName splitString " ") joinString "_";
};
_finalConfig = (_config >> "CfgWorldInteractions" >> (_p3dName + "_p3d"));
_selectedConfig = _p3dName + "_p3d";
};
};
if (_checkType isEqualType []) then {
// Do checks
_finalConfig = (_config >> _selectedConfig);
if (_checkType isEqualType []) then {
_return = [];
{
_return pushBack (getNumber(_finalConfig >> _x) == 1);
} forEach _checkType;
} else {
} else {
_return = (getNumber(_finalConfig >> _checkType) == 1);
};
};
_return

View File

@ -13,7 +13,7 @@
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_checkNearby.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_check","_config","_configWorldInteractions","_countAlive","_countOnFire","_find","_nearObjects","_result","_test1","_test2","_tmpResult"];
private ["_check","_countAlive","_countOnFire","_find","_nearObjects","_result","_test1","_test2","_tmpResult"];
//[[[end]]]
params ["","","",["_arr",[2,""]],["_dist",0],["_cnt",1],["_inflamed",0],["_alive",0]];
_arr params ["_type","_check"];
@ -39,18 +39,12 @@ switch (_type) do {
};
case 2:
{
_config = 'CfgEpochClient' call EPOCH_returnConfig;
_configWorldInteractions = (_config >> "CfgWorldInteractions");
_nearObjects = nearestObjects [player, [], _dist];
_check = _check select 0;
_tmpResult = false;
{
if (alive _x) then {
if !(_x isKindOf "All") then {
_tmpResult = [str(_x), _check] call EPOCH_worldObjectType;
} else {
_tmpResult = (getNumber(_configWorldInteractions >> (typeOf _x) >> _check) == 1);
};
_tmpResult = [_x, _check] call EPOCH_worldObjectType;
};
if (_tmpResult) exitWith {_result = _tmpResult};
} forEach _nearObjects;

View File

@ -94,7 +94,7 @@ class base_mode_attach
};
class Drink
{
condition = "_config = 'CfgEpochClient' call EPOCH_returnConfig;_configWorldInteractions = (_config >> 'CfgWorldInteractions');_nearObjects = nearestObjects [player, [], 2];_check = 'water';_ok = false;{if (alive _x) then {if !(_x isKindOf 'All') then {_ok = [str(_x), _check] call EPOCH_worldObjectType;}else {_ok = (getNumber(_configWorldInteractions >> (typeOf _x) >> _check) == 1);};};if (_ok) exitWith {};} forEach _nearObjects;_ok";
condition = "_nearObjects = nearestObjects [player, [], 2];_check = 'water';_ok = false;{if (alive _x) then {_ok = [_x, _check] call EPOCH_worldObjectType;};if (_ok) exitWith {};} forEach _nearObjects;_ok";
action = "if (currentweapon player == '') then {player playmove 'AinvPknlMstpSnonWnonDnon_Putdown_AmovPknlMstpSnonWnonDnon';}else {if (currentweapon player == handgunweapon player) then {player playmove 'AinvPknlMstpSrasWpstDnon_Putdown_AmovPknlMstpSrasWpstDnon';}else { player playmove 'AinvPknlMstpSrasWrflDnon_Putdown_AmovPknlMstpSrasWrflDnon';};};{_output = _x call EPOCH_giveAttributes;if (_output != '') then {[_output, 5] call Epoch_message;};} foreach [['Toxicity',4,1],['Stamina',10],['Thirst',100]];";
icon = "epoch_code\customs\Drink.paa"; // On release change to: "x\addons\a3_epoch_code\Data\UI\buttons\Drink.paa"
tooltip = "Drink";

View File

@ -4,7 +4,7 @@
Contributors:
Description: md5 hash function
Returns md5 hash if only one string is give as imput.
Returns md5 hash if only one string is given as input.
Returns array of md5 hashes if input was an array.
Licence: