Epoch/Sources/epoch_code/compile/building/EPOCH_isBuildAllowed.sqf

220 lines
9.1 KiB
Plaintext
Raw Normal View History

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 ]]]
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]]]
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
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;
_useSplitCountLimits = false;
_useGroupCountLimits = true;
2015-09-14 20:55:36 +00:00
_nearestJammer = objNull;
_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;
_JammerConfig = (_config >> "CfgJammers");
_cfgBaseBuilding = 'CfgBaseBuilding' call EPOCH_returnConfig;
if(getNumber(_config >> "useGroupCountLimits") == 0)then{_useGroupCountLimits=false};
if(getNumber(_config >> "splitCountLimits") == 1)then{_useSplitCountLimits=true};
if(getNumber(_config >> "jammerGLOnly") == 0)then{_jammerGLOnly=false};
_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"];
_obj = objNull;
if (_objType isEqualType objNull) then {
_obj = _objType;
_objType = typeOf _objType;
};
2015-12-07 16:24:52 +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");
_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 {
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
}
else {
2015-09-14 20:55:36 +00:00
{
if (alive _x) exitWith{
2015-09-14 20:55:36 +00:00
_nearestJammer = _x;
_JammerConfig = (_JammerConfig >> (typeof _nearestJammer));
2015-09-14 20:55:36 +00:00
};
} foreach _jammer;
if !(isNull _nearestJammer) then {
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;
_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");
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;
[format["Building Disallowed: Max. %1 Storage Objects",_storageCountLimit],5] call Epoch_message
2016-11-14 01:04:08 +00:00
};
}
else {
2018-08-24 18:04:12 +00:00
if ((count (nearestObjects[_nearestJammer,_BuildingClasses,_buildingJammerRange]-[_obj])) >= _buildingCountLimit) exitwith {
_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 {
_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
};
};
}
else {
if (_objType in _JammerCheckClasses) then {
if (!(EPOCH_my_groupUID isequalto "") && !((getplayeruid player) isequalto EPOCH_my_groupUID) && _jammerGLOnly) exitwith {
_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{
_limitNearby = getNumber(_cfgBaseBuilding >> _staticClass >> "limitNearby");
2015-09-14 20:55:36 +00:00
if (_limitNearby > 0) then{
// remove current target from objects
_objectscount = count (nearestObjects[player, [_staticClass, _simulClass], 100]-[_obj]);
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{
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