Merge pull request #1528 from raymix/master

modular build code optimization + some extras
This commit is contained in:
vbawol
2014-08-15 01:52:04 -05:00
10 changed files with 61 additions and 45 deletions

View File

@@ -55,31 +55,34 @@ _isLandFireDZ = _itemConfig select 10; //bool
//Check for nearby plotpoles. Returns [_IsNearPlot,_nearestPole,_ownerID,_friendlies] [int,Obj,int,array]
[_isPole, _requireplot, _isLandFireDZ] call player_build_plotCheck;
if (DZE_ActionInProgress) then { //needed otherwise _hasRequired gets RPT error
//Check for build requirements (missing tools and items). Returns [_hasrequireditem,_reason] [bool,string]
_hasRequired = [_require, _text, true, true] call player_build_buildReq;
//define item collected from function
_hasrequireditem = _hasRequired select 0; //bool
if (_hasrequireditem and DZE_ActionInProgress) then {
if (_hasrequireditem) then {
//Create object that is attached to a player (i.e Ghost preview if available)
_buildObject = [_classname, _ghost, _offset, true] call player_build_create;
//Create object that is attached to a player (i.e Ghost preview if available)
_buildObject = [_classname, _ghost, _offset, true] call player_build_create;
//define items collected from function
_location1 = _buildObject select 0; //array
_object = _buildObject select 1; //Obj
_position = _buildObject select 2; // array
_objectHelper = _buildObject select 3; //Obj
//define items collected from function
_location1 = _buildObject select 0; //array
_object = _buildObject select 1; //Obj
_position = _buildObject select 2; // array
_objectHelper = _buildObject select 3; //Obj
_controls = [_object, _isAllowedUnderGround, _location1, _position, _objectHelper] call player_build_controls;
_controls = [_object, _isAllowedUnderGround, _location1, _position, _objectHelper] call player_build_controls;
//define items collected from function
_cancel = _controls select 0; //bool
_reason = _controls select 1; //string
_position = _controls select 2; //array
_dir = _controls select 3; //int
//define items collected from function
_cancel = _controls select 0; //bool
_reason = _controls select 1; //string
_position = _controls select 2; //array
_dir = _controls select 3; //int
//Publish item to a database
[_cancel, _position, _classnametmp,_isAllowedUnderGround, _text, _isPole, _lockable,_dir, _reason] call player_build_publish;
//Publish item to a database
[_cancel, _position, _classnametmp,_isAllowedUnderGround, _text, _isPole, _lockable,_dir, _reason] call player_build_publish;
};
};

View File

@@ -1,3 +1,4 @@
if(!DZE_ActionInProgress) exitWith {};
//Check for build requirements like tools and if item is in magazines (check args to disable checks)
private ["_passArray","_missing","_hasrequireditem","_require","_hastoolweapon","_hasbuilditem","_checkMag","_checkTools","_reason"];
@@ -20,11 +21,14 @@ _passArray = [];
_hasbuilditem = DZE_buildItem in magazines player;
_passArray = [_hasrequireditem,_reason];
if (_checkMag) then { //passed argument
if (!_hasbuilditem) exitWith { //End script if magazine was not found
DZE_ActionInProgress = false;
cutText [format[(localize "str_player_31"),_text,"build"] , "PLAIN DOWN"];
_reason = "missing item";
_passArray
};
};
@@ -33,9 +37,8 @@ if (_checkTools) then { //passed argument
DZE_ActionInProgress = false;
cutText [format[(localize "str_epoch_player_137"),_missing] , "PLAIN DOWN"];
_reason = "missing tools";
_passArray
};
};
_passArray = [_hasrequireditem,_reason];
_passArray //[bool,string]

View File

@@ -1,4 +1,4 @@
private ["_canDo","_passArray","_objHDiff","_isOk","_zheightchanged","_zheightdirection","_rotate","_dir","_object","_position","_isAllowedUnderGround","_location2","_cancel","_reason","_lastDir","_objectHelper","_objectHelperDir","_objectHelperPos"];
private ["_canDo","_passArray","_objHDiff","_isOk","_zheightchanged","_zheightdirection","_rotate","_dir","_object","_position","_isAllowedUnderGround","_location1","_location2","_cancel","_reason","_lastDir","_objectHelper","_objectHelperDir","_objectHelperPos"];
_object = _this select 0;
_isAllowedUnderGround = _this select 1;
@@ -142,8 +142,6 @@ while {_isOk} do {
_objectHelper setPosATL _position;
//diag_log format["DEBUG Change BUILDING POS: %1", _position];
if (!helperDetach) then {
_objectHelper attachTo [player];
};
@@ -157,9 +155,9 @@ while {_isOk} do {
if(DZE_5) exitWith {
_isOk = false;
detach _object;
_dir = getDir _object;
_position = getPosATL _object;
//diag_log format["DEBUG BUILDING POS: %1", _position];
_dir = getDir _object;
deleteVehicle _object;
detach _objectHelper;
deleteVehicle _objectHelper;

View File

@@ -1,7 +1,7 @@
// disallow building if too many objects are found within 30m
// disallow building if too many objects are found within 30m (by default)
private ["_cnt"];
_cnt = count ((getPosATL player) nearObjects ["All",30]);
_cnt = count ((getPosATL player) nearObjects ["All",DZE_checkNearbyRadius]);
if (_cnt >= DZE_BuildingLimit) exitWith { //end script if too many objects nearby
DZE_ActionInProgress = false;
cutText [(localize "str_epoch_player_41"), "PLAIN DOWN"];

View File

@@ -1,3 +1,4 @@
if(!DZE_ActionInProgress) exitWith {};
//Build an array of various variables gathered about build object from config files, only applies to legit buildable objects
private ["_passArray","_classname","_classnametmp","_require","_text","_ghost","_lockable","_requireplot","_isAllowedUnderGround","_offset","_isPole","_isLandFireDZ"];

View File

@@ -1,3 +1,4 @@
if(!DZE_ActionInProgress) exitWith {};
//disallow building if required items (defined in config) are not found nearby
private ["_abort","_reason","_distance","_needNear","_isNear"];
@@ -41,5 +42,3 @@ if (_abort) exitWith {
cutText [format[(localize "str_epoch_player_135"),_reason,_distance], "PLAIN DOWN"];
DZE_ActionInProgress = false;
};
_reason //return string to a caller

View File

@@ -1,3 +1,4 @@
if(!DZE_ActionInProgress) exitWith {};
//Check if nearby plotpoles exists
private ["_passArray","_isPole","_needText","_distance","_findNearestPoles","_findNearestPole","_IsNearPlot","_requireplot","_isLandFireDZ","_canBuildOnPlot","_nearestPole","_ownerID","_friendlies"];
@@ -11,7 +12,6 @@ _canBuildOnPlot = false;
_nearestPole = objNull;
_ownerID = 0;
_friendlies = [];
_passArray = [];
if(_isPole) then { //check if object is plotpole and adjust distance accordingly
_distance = DZE_PlotPole select 1;
@@ -31,12 +31,6 @@ _findNearestPole = []; //must define an empty array to avoid problems
_IsNearPlot = count (_findNearestPole); //count our new array of non-destroyed plotpoles. Empty array will return 0
// End script early if item is plot pole and another one exists within defined radius
if(_isPole && _IsNearPlot > 0) exitWith {
DZE_ActionInProgress = false;
cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"];
};
if(_IsNearPlot == 0) then { //No live plotpoles were found nearby
// Allow building of plot
if(_requireplot == 0 || _isLandFireDZ) then {
@@ -68,10 +62,18 @@ if(_IsNearPlot == 0) then { //No live plotpoles were found nearby
};
};
_passArray = [_IsNearPlot,_nearestPole,_ownerID,_friendlies]; //create new array and pass it to caller
// End script if item is plot pole and another one exists within defined radius
if(_isPole && _IsNearPlot > 0) exitWith {
DZE_ActionInProgress = false;
cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"];
_passArray
};
if(!_canBuildOnPlot) exitWith { //end script if requirements were not met
DZE_ActionInProgress = false;
cutText [format[(localize "STR_EPOCH_PLAYER_135"),_needText,_distance] , "PLAIN DOWN"];
_passArray
};
_passArray = [_IsNearPlot,_nearestPole,_ownerID,_friendlies]; //create new array and pass it to caller
_passArray //[int,Obj,int,array]

View File

@@ -1,3 +1,4 @@
if(!DZE_ActionInProgress) exitWith {};
//disallow building if these conditions are not met
private ["_isFine","_onLadder","_vehicle","_inVehicle"];
@@ -10,24 +11,28 @@ if (dayz_isSwimming) exitWith { //end script if player is swimming
DZE_ActionInProgress = false;
cutText [localize "str_player_26", "PLAIN DOWN"];
_isFine = "Swimming";
_isFine
};
if (_inVehicle) exitWith { //end script if player is in vehicle
DZE_ActionInProgress = false;
cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];
_isFine = "In vehicle";
_isFine
};
if (_onLadder) exitWith { //end script if player is climbing on ladder
DZE_ActionInProgress = false;
cutText [localize "str_player_21", "PLAIN DOWN"];
_isFine = "On ladder";
_isFine
};
if (player getVariable["combattimeout", 0] >= time) exitWith { //end script if player is in combat
DZE_ActionInProgress = false;
cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];
_isFine = "In combat";
_isFine
};
_isFine //returns string to caller, default is "ok" if conditions were not met

View File

@@ -3,7 +3,7 @@
// July 10 2014 //
/*--------------------------------*/
private ["_object","_objectSnapGizmo","_objColorActive","_objColorInactive","_classname","_whitelist","_points","_radius","_cfg","_cnt","_pos","_findWhitelisted","_nearbyObject","_posNearby","_selectedAction","_newPos","_pointsNearby","_onWater"];
private ["_object","_objectSnapGizmo","_objColorActive","_objColorInactive","_classname","_whitelist","_points","_radius","_cfg","_cnt","_pos","_findWhitelisted","_nearbyObject","_posNearby","_selectedAction","_newPos","_pointsNearby","_onWater","_waterBase"];
//Args
snapActionState = _this select 3 select 0;
_object = _this select 3 select 1;
@@ -58,8 +58,10 @@ fnc_initSnapPoints = {
fnc_initSnapPointsNearby = {
_pos = getPosATL _object;
_findWhitelisted = []; _pointsNearby = [];
_findWhitelisted = nearestObjects [_pos,_whitelist,(_radius + DZE_snapExtraRange)]-[_object];
_findWhitelisted = []; _pointsNearby = []; _waterBase = 0;
_onWater = surfaceIsWater position player;
if (_onWater) then { _waterBase = (getPosATL player select 2);};
_findWhitelisted = nearestObjects [_pos,_whitelist,(_radius + DZE_snapExtraRange + _waterBase)]-[_object];
snapGizmosNearby = [];
{
_nearbyObject = _x;

View File

@@ -551,6 +551,9 @@ if (isNil "DZE_modularBuild") then {
if (isNil "DZE_snapExtraRange") then {
DZE_snapExtraRange = 0;
};
if (isNil "DZE_checkNearbyRadius") then {
DZE_checkNearbyRadius = 30;
};
// needed on server
if(isNil "DZE_PlotPole") then {