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

221 lines
9.3 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 ]]]
2017-03-23 19:28:04 +00:00
private ["_alljammer","_buildingAllowed","_buildingCountLeader","_buildingCountLimit","_buildingCountPerMember","_buildingJammerRange","_bypassJammer","_c","_cfgBaseBuilding","_config","_ghostClass","_isAllowed","_jammer","_jammerGLOnly","_jammerPerGroup","_limitNearby","_maxBuildingHeight","_membercount","_minJammerDistance","_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;
_cfgBaseBuilding = 'CfgBaseBuilding' call EPOCH_returnConfig;
2015-09-14 20:55:36 +00:00
_buildingJammerRange = getNumber(_config >> "buildingJammerRange");
_buildingCountLimit = getNumber(_config >> "buildingCountLimit");
2016-11-14 01:04:08 +00:00
_storageCountLimit = getNumber(_config >> "storageCountLimit");
2016-07-07 23:48:34 +00:00
_buildingCountLeader = getNumber(_config >> "buildingCountLeader");
2016-07-07 23:54:50 +00:00
_buildingCountPerMember = getNumber(_config >> "buildingCountPerMember");
2016-11-14 01:04:08 +00:00
_storageCountLeader = getNumber(_config >> "storageCountLeader");
_storageCountPerMember = getNumber(_config >> "storageCountPerMember");
_minJammerDistance = getNumber(_config >> "minJammerDistance");
_maxBuildingHeight = getNumber(_config >> "maxBuildingHeight");
_jammerPerGroup = getNumber(_config >> "jammerPerGroup");
if(getNumber(_config >> "useGroupCountLimits") == 0)then{_useGroupCountLimits=false};
if(getNumber(_config >> "splitCountLimits") == 1)then{_useSplitCountLimits=true};
if(getNumber(_config >> "jammerGLOnly") == 0)then{_jammerGLOnly=false};
2016-11-14 01:04:08 +00:00
if(_buildingJammerRange == 0)then{_buildingJammerRange = 75};
if(_buildingCountLimit == 0)then{_buildingCountLimit = 200};
if(_buildingCountLeader == 0)then{_buildingCountLeader = _buildingCountLimit};
if(_storageCountLeader == 0)then{_storageCountLeader = 100};
if(_minJammerDistance == 0)then{_minJammerDistance = _buildingJammerRange*3};
if(_maxBuildingHeight == 0)then{_maxBuildingHeight = 100};
if(_jammerPerGroup == 0)then{_jammerPerGroup = 2};
2016-07-07 23:48:34 +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
2016-07-07 23:48:34 +00:00
_jammer = nearestObjects[player, ["PlotPole_EPOCH"], _minjammerdistance];
2015-09-14 20:55:36 +00:00
if !(_jammer isEqualTo []) then {
2015-12-07 16:24:52 +00:00
if (_objType in ["PlotPole_EPOCH", "PlotPole_SIM_EPOCH"]) 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 && (_x distance player) <= _buildingJammerRange) exitWith{
_nearestJammer = _x;
};
} 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;
if(_useGroupCountLimits)then{
_membercount = 0;
2017-03-23 19:28:04 +00:00
Epoch_my_Group params [
["_groupName",""],
["_leaderName",""],
["_groupSize",0],
["_modArray",[]],
2017-03-23 20:38:19 +00:00
["_memberArray",[]]
2017-03-23 19:28:04 +00:00
];
2017-03-23 20:38:19 +00:00
_membercount = count _modArray + count _memberArray;
_storageCountLimit = _storageCountLeader + (_storageCountPerMember * _membercount);
_buildingCountLimit = _buildingCountLeader + (_buildingCountPerMember * _membercount);
};
if (_useSplitCountLimits) then {
if(_objType in ["WorkBench_EPOCH","StorageShelf_EPOCH","Tipi_EPOCH","LockBox_EPOCH","Safe_EPOCH","StorageShelf_SIM_EPOCH","LockBox_SIM_EPOCH","Safe_SIM_EPOCH","Workbench_SIM_EPOCH","Tipi_SIM_EPOCH"]) then {
if ((count (nearestObjects[_nearestJammer,["Buildable_Storage","Constructions_lockedstatic_F","LockBox_SIM_EPOCH","Safe_SIM_EPOCH","StorageShelf_SIM_EPOCH","WorkBench_SIM_EPOCH"],_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 {
if ((count (nearestObjects[_nearestJammer,["Constructions_static_F","Constructions_foundation_F","Const_Ghost_EPOCH"],_buildingJammerRange]-[_obj])) >= _buildingCountLimit) exitwith {
_buildingAllowed = false;
[format["Building Disallowed: Max. %1 Constructions",_buildingCountLimit],5] call Epoch_message
};
};
}
else {
if ((count (nearestObjects [_nearestJammer,["Buildable_Storage","Constructions_lockedstatic_F","LockBox_SIM_EPOCH","Safe_SIM_EPOCH","StorageShelf_SIM_EPOCH","WorkBench_SIM_EPOCH","Constructions_static_F","Constructions_foundation_F","Const_Ghost_EPOCH"],_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
};
};
};
}
else {
2016-07-07 23:48:34 +00:00
if (_objType in ["PlotPole_EPOCH", "PlotPole_SIM_EPOCH"]) 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;
};
// TODO: rework not ideal to use allmissionobjects
2016-07-07 23:48:34 +00:00
_alljammer = allmissionobjects 'PlotPole_EPOCH';
_c = 0;
{
if ((_x getVariable["BUILD_OWNER", "-1"]) in[getPlayerUID player, Epoch_my_GroupUID]) then {
_c = _c+1;
};
} foreach _alljammer;
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], _buildingJammerRange]-[_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{
2015-12-07 16:24:52 +00:00
if !(_objType in ["PlotPole_EPOCH", "PlotPole_SIM_EPOCH"]) 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