2015-12-07 16:24:52 +00:00
/*
Author: Aaron Clark - EpochMod.com
Contributors: Raimonds Virtoss
Description:
2015-12-15 18:46:09 +00:00
check if building is allowed
2015-12-07 16:24:52 +00:00
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
2016-06-13 16:54:19 +00:00
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/building/EPOCH_isBuildAllowed.sqf
2015-12-07 16:24:52 +00:00
Example:
_isAllowed = "" call EPOCH_isBuildAllowed;
_isAllowed = _objType call EPOCH_isBuildAllowed;
Parameter(s):
_this select 0: OBJECT - Base building object
Returns:
BOOL
*/
2016-09-01 00:40:18 +00:00
//[[[cog import generate_private_arrays ]]]
2019-02-18 21:29:02 +00:00
private ["_StorageClasses","_BuildingClasses","_CamCountLimit","_alljammer","_buildingAllowed","_buildingCountLeader","_buildingCountLimit","_buildingCountPerMember","_buildingJammerRange","_bypassJammer","_c","_cfgBaseBuilding","_config","_ghostClass","_isAllowed","_jammer","_jammerGLOnly","_jammerPerGroup","_limitNearby","_maxBuildingHeight","_membercount","_myPosATL","_nearestJammer","_obj","_objType","_objectscount","_ownedJammerExists","_range","_restricted","_restrictedArray","_restrictedLocations","_restrictedLocationsArray","_restrictedLocationsRange","_simulClass","_staticClass","_storageCountLeader","_storageCountLimit","_storageCountPerMember","_useGroupCountLimits","_useSplitCountLimits"];
2016-09-01 00:40:18 +00:00
//[[[end]]]
2016-04-08 20:21:46 +00:00
2015-09-14 20:55:36 +00:00
_buildingAllowed = true;
2015-12-07 16:24:52 +00:00
_ownedJammerExists = false;
2016-12-10 19:20:40 +00:00
_useSplitCountLimits = false;
_useGroupCountLimits = true;
2015-09-14 20:55:36 +00:00
_nearestJammer = objNull;
2017-03-03 00:37:20 +00:00
_jammerGLOnly = true;
2015-09-14 20:55:36 +00:00
2016-04-10 16:16:27 +00:00
// reject building if in vehicle
2016-06-18 01:22:29 +00:00
if (vehicle player != player)exitWith{["Building Disallowed: Inside Vehicle", 5] call Epoch_message; false };
2016-04-10 16:16:27 +00:00
2015-09-14 20:55:36 +00:00
// defaults
_config = 'CfgEpochClient' call EPOCH_returnConfig;
2019-02-18 21:29:02 +00:00
_JammerConfig = (_config >> "CfgJammers");
2016-05-05 16:06:12 +00:00
_cfgBaseBuilding = 'CfgBaseBuilding' call EPOCH_returnConfig;
2016-12-10 19:20:40 +00:00
if(getNumber(_config >> "useGroupCountLimits") == 0)then{_useGroupCountLimits=false};
if(getNumber(_config >> "splitCountLimits") == 1)then{_useSplitCountLimits=true};
2017-03-03 00:37:20 +00:00
if(getNumber(_config >> "jammerGLOnly") == 0)then{_jammerGLOnly=false};
2019-02-18 21:29:02 +00:00
_StorageClasses = ["CfgEpochClient", "StorageClasses", ["Buildable_Storage","Buildable_Storage_SIM","Buildable_Storage_Ghost","Constructions_lockedstatic_F","Secure_Storage_Temp"]] call EPOCH_fnc_returnConfigEntryV2;
_BuildingClasses = ["CfgEpochClient", "BuildingClasses", ["Constructions_static_F","Constructions_foundation_F","Const_Ghost_EPOCH"]] call EPOCH_fnc_returnConfigEntryV2;
_maxBuildingHeight = ["CfgEpochClient", "maxBuildingHeight", 100] call EPOCH_fnc_returnConfigEntryV2;
_jammerPerGroup = ["CfgEpochClient", "jammerPerGroup", 1] call EPOCH_fnc_returnConfigEntryV2;
_JammerClasses = call EPOCH_JammerClasses;
_JammerGhosts = call EPOCH_JammerGhosts;
_JammerCheckClasses = _JammerClasses + _JammerGhosts;
2018-08-24 18:04:12 +00:00
2015-12-07 16:24:52 +00:00
// input
params ["_objType"];
2016-04-24 23:25:03 +00:00
_obj = objNull;
if (_objType isEqualType objNull) then {
_obj = _objType;
_objType = typeOf _objType;
};
2015-12-07 16:24:52 +00:00
2016-05-05 16:06:12 +00:00
_staticClass = getText(_cfgBaseBuilding >> _objType >> "staticClass");
_simulClass = getText(_cfgBaseBuilding >> _objType >> "simulClass");
2016-11-14 01:04:08 +00:00
_ghostClass = getText(_cfgBaseBuilding >> _objType >> "GhostPreview");
2016-05-05 16:06:12 +00:00
_bypassJammer = getNumber(_cfgBaseBuilding >> _staticClass >> "bypassJammer");
2015-09-14 20:55:36 +00:00
// Jammer
2019-02-20 21:31:09 +00:00
_jammer = (nearestObjects[player, _JammerCheckClasses, call EPOCH_MaxJammerRange]) select {player distance _x < (getnumber (_JammerConfig >> (typeof _x) >> "buildingJammerRange"))};
2015-09-14 20:55:36 +00:00
if !(_jammer isEqualTo []) then {
2019-02-18 21:29:02 +00:00
if (_objType in _JammerCheckClasses) then {
2015-09-14 20:55:36 +00:00
{
if (alive _x) exitWith{
_buildingAllowed = false;
2016-06-18 01:22:29 +00:00
["Building Disallowed: Existing Jammer Signal", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
} foreach _jammer;
2017-03-23 19:28:04 +00:00
}
2016-12-10 19:20:40 +00:00
else {
2015-09-14 20:55:36 +00:00
{
2019-02-18 21:29:02 +00:00
if (alive _x) exitWith{
2015-09-14 20:55:36 +00:00
_nearestJammer = _x;
2019-02-18 21:29:02 +00:00
_JammerConfig = (_JammerConfig >> (typeof _nearestJammer));
2015-09-14 20:55:36 +00:00
};
} foreach _jammer;
if !(isNull _nearestJammer) then {
2016-12-10 19:20:40 +00:00
if !((_nearestJammer getVariable["BUILD_OWNER", "-1"]) in[getPlayerUID player, Epoch_my_GroupUID]) exitwith {
_buildingAllowed = false;
["Building Disallowed: Frequency Blocked", 5] call Epoch_message;
};
_ownedJammerExists = true;
2019-02-18 21:29:02 +00:00
_membercount = 0;
Epoch_my_Group params [
["_groupName",""],
["_leaderName",""],
["_groupSize",0],
["_modArray",[]],
["_memberArray",[]]
];
_membercount = count _modArray + count _memberArray;
2019-02-20 21:31:09 +00:00
_buildingJammerRange = getnumber (_JammerConfig >> "buildingJammerRange");
_storageCountLimit = (getnumber (_JammerConfig >> "storageCountLimit")) + ((getnumber (_JammerConfig >> "storageCountPerMember")) * _membercount);
_buildingCountLimit = (getnumber (_JammerConfig >> "buildingCountLimit")) + ((getnumber (_JammerConfig >> "buildingCountPerMember")) * _membercount);
_CamCountLimit = getnumber (_JammerConfig >> "maxCams");
2019-02-18 21:29:02 +00:00
2016-12-10 19:20:40 +00:00
if (_useSplitCountLimits) then {
2018-08-24 18:04:12 +00:00
if({_objType iskindof _x} count _StorageClasses > 0) then {
if ((count (nearestObjects[_nearestJammer,_StorageClasses,_buildingJammerRange]-[_obj])) >= _storageCountLimit) exitwith {
2016-11-14 01:04:08 +00:00
_buildingAllowed = false;
2016-12-10 19:20:40 +00:00
[format["Building Disallowed: Max. %1 Storage Objects",_storageCountLimit],5] call Epoch_message
2016-11-14 01:04:08 +00:00
};
2016-12-10 19:20:40 +00:00
}
else {
2018-08-24 18:04:12 +00:00
if ((count (nearestObjects[_nearestJammer,_BuildingClasses,_buildingJammerRange]-[_obj])) >= _buildingCountLimit) exitwith {
2016-12-10 19:20:40 +00:00
_buildingAllowed = false;
[format["Building Disallowed: Max. %1 Constructions",_buildingCountLimit],5] call Epoch_message
};
};
}
else {
2018-08-24 18:04:12 +00:00
if ((count (nearestObjects [_nearestJammer,(_StorageClasses + _BuildingClasses),_buildingJammerRange]-[_obj])) >= _buildingCountLimit) exitwith {
2016-12-10 19:20:40 +00:00
_buildingAllowed = false;
[format["Building Disallowed, Frequency Overloaded: Limit %1",_buildingCountLimit],5] call Epoch_message
};
};
if !((getPosATL player) select 2 < _maxBuildingHeight) exitwith {
2015-09-14 20:55:36 +00:00
_buildingAllowed = false;
2016-11-14 01:04:08 +00:00
["Building Disallowed: Max building height reached",5] call Epoch_message;
2016-07-07 23:48:34 +00:00
};
2018-05-06 19:06:09 +00:00
if (_objType isequalto "BaseCam_EPOCH" && _buildingAllowed) then {
if ((count (nearestObjects[_nearestJammer,["BaseCam_EPOCH","BaseCam_SIM_EPOCH","BaseCam_Ghost_EPOCH"],_buildingJammerRange]-[_obj])) >= _CamCountLimit) then {
_buildingAllowed = false;
[format["Building Disallowed: Max %1 Cams per Base!", _CamCountLimit], 5] call Epoch_message;
};
};
2016-07-07 23:48:34 +00:00
};
};
2016-12-10 19:20:40 +00:00
}
else {
2019-02-18 21:29:02 +00:00
if (_objType in _JammerCheckClasses) then {
2017-03-03 00:37:20 +00:00
if (!(EPOCH_my_groupUID isequalto "") && !((getplayeruid player) isequalto EPOCH_my_groupUID) && _jammerGLOnly) exitwith {
2017-02-10 19:25:36 +00:00
_buildingAllowed = false;
["The Group Leader must place the Jammer!", 5] call Epoch_message;
};
2016-07-07 23:48:34 +00:00
_c = 0;
{
if ((_x getVariable["BUILD_OWNER", "-1"]) in[getPlayerUID player, Epoch_my_GroupUID]) then {
_c = _c+1;
};
2019-02-20 21:31:09 +00:00
} foreach (missionnamespace getvariable ["Epoch_Plotpoles",call {_allplots = [];{_allplots append (allmissionobjects _x)} foreach (call EPOCH_JammerClasses);_allplots}]);
2016-11-14 01:04:08 +00:00
if (_c >= _jammerPerGroup) then {
2016-07-07 23:48:34 +00:00
_buildingAllowed = false;
2016-11-14 01:04:08 +00:00
[format["Building Disallowed: Max %1 Jammer per Group!", _jammerPerGroup], 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
if !(_buildingAllowed)exitWith{ false };
// Max object
if (!_ownedJammerExists) then{
2016-05-05 16:06:12 +00:00
_limitNearby = getNumber(_cfgBaseBuilding >> _staticClass >> "limitNearby");
2016-04-24 23:25:03 +00:00
2015-09-14 20:55:36 +00:00
if (_limitNearby > 0) then{
2016-04-24 23:25:03 +00:00
// remove current target from objects
2019-02-18 21:29:02 +00:00
_objectscount = count (nearestObjects[player, [_staticClass, _simulClass], 100]-[_obj]);
2016-12-10 19:20:40 +00:00
if (_objectscount >= _limitNearby) then{
2015-09-14 20:55:36 +00:00
_buildingAllowed = false;
2016-06-18 01:22:29 +00:00
[format["Building Disallowed: Limit %1", _limitNearby], 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
if !(_buildingAllowed)exitWith{ false };
// require jammer check if not found as owner of jammer
2016-11-14 01:04:08 +00:00
if (getNumber(_config >> "buildingRequireJammer") == 1 && _bypassJammer == 0) then{
2019-02-18 21:29:02 +00:00
if !(_objType in _JammerCheckClasses) then {
2015-09-14 20:55:36 +00:00
_buildingAllowed = _ownedJammerExists;
if !(_buildingAllowed) then {
2016-06-18 01:22:29 +00:00
["Building Disallowed: Frequency Jammer Needed", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
if !(_buildingAllowed)exitWith{ false };
if (getNumber(_config >> "buildingNearbyMilitary") == 0) then{
_range = getNumber(_config >> "buildingNearbyMilitaryRange");
if (_range > 0) then {
2016-07-14 21:36:24 +00:00
_restrictedArray = ["ProtectionZone_Invisible_F"];
_restrictedArray append getArray(_config >> "buildingNearbyMilitaryClasses");
_restricted = nearestObjects [player, _restrictedArray, _range];
2015-09-14 20:55:36 +00:00
};
} else {
_restricted = nearestObjects [player, ["ProtectionZone_Invisible_F"], 300];
};
if !(_restricted isEqualTo []) then {
_buildingAllowed = false;
2016-07-07 23:48:34 +00:00
["Building Disallowed: Area Blocked", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
2016-07-14 21:36:24 +00:00
_restrictedLocationsArray = getArray(_config >> "restrictedLocations");
_restrictedLocationsRange = getNumber(_config >> "restrictedLocationsRange");
if !(_restrictedLocationsArray isEqualTo []) then {
_restrictedLocations = nearestLocations [player, _restrictedLocationsArray, _restrictedLocationsRange];
if !(_restrictedLocations isEqualTo []) then {
_buildingAllowed = false;
["Building Disallowed: Area Blocked", 5] call Epoch_message;
};
2015-09-14 20:55:36 +00:00
};
_myPosATL = getPosATL player;
{
if ((_x select 0) distance _myPosATL < (_x select 1)) exitWith {
_buildingAllowed = false;
2016-07-07 23:48:34 +00:00
["Building Disallowed: Area Blocked", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
} forEach(getArray(_config >> worldname >> "blockedArea"));
2015-12-07 16:24:52 +00:00
_buildingAllowed