From e88677f6ae610d32d79aa7b6e1b05ac1abecb850 Mon Sep 17 00:00:00 2001 From: A Man Date: Sun, 12 Jun 2022 18:43:17 +0200 Subject: [PATCH] Update snapping to fix certain reported bugs Made by @Victor-the-Cleaner and thanks to @DeandlDernai for reporting --- SQF/dayz_code/actions/modular_build.sqf | 12 ++++---- SQF/dayz_code/compile/snap_functions.sqf | 38 +++++++++++++----------- SQF/dayz_code/init/variables.sqf | 3 +- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/SQF/dayz_code/actions/modular_build.sqf b/SQF/dayz_code/actions/modular_build.sqf index 14880d8c7..bf6fe6afb 100644 --- a/SQF/dayz_code/actions/modular_build.sqf +++ b/SQF/dayz_code/actions/modular_build.sqf @@ -580,14 +580,13 @@ if (_canBuild) then { local _detach = { detach _objectHelper; // release object - DZE_memDir = getDir _objectHelper; // get current Z rotation if (DZE_memLeftRight == 0) then { // if object is not banked (left/right) local _absMem = abs DZE_memForBack; - if ((_absMem >= 90) && (_absMem < 270)) then { // but is pitched upside down (forward/back) + if (_absMem >= 90 && {_absMem < 270}) then { // but is pitched upside down (forward/back) DZE_memDir = DZE_memDir + 180; // prevent flipping around X axis }; } else { // if object is banked (left/right) @@ -616,9 +615,9 @@ if (_canBuild) then { /////////////////////////////////////////////////////////////////////////////////////////// local _update = { - DZE_memForBack = DZE_memForBack % 360; // clamp rotation angles - DZE_memLeftRight = DZE_memLeftRight % 360; - DZE_memDir = DZE_memDir % 360; + DZE_memForBack = (DZE_memForBack + 360) % 360; // clamp rotation angles + DZE_memLeftRight = (DZE_memLeftRight + 360) % 360; + DZE_memDir = (DZE_memDir + 360) % 360; [_objectHelper, [DZE_memForBack, DZE_memLeftRight, DZE_memDir]] call fnc_SetPitchBankYaw; @@ -985,7 +984,7 @@ if (_canBuild) then { local _bz = abs (_b0 select 2) + abs (_b1 select 2); local _diag = sqrt (_bx^2 + _by^2 + _bz^2); // get diagonal of boundingBox - DZE_snapRadius = _diag * 0.5 + 9; // 9 is half the largest bounding box diagonal (rounded up) of the largest snappable objects in the game; currently the Land_WarfareBarrier10xTall_DZ and the MetalContainer2D_DZ. + DZE_snapRadius = ceil ((_diag * 0.5) + (DZE_maxSnapObjectDiag * 0.5)); // snap radius is the sum of half the bounding box diagonals of both the current object and the largest object in the game; currently the Land_WarfareBarrier10xTall_DZ _refreshDist = DZE_snapRadius * 0.5; // distance object moves before the snap auto-refresh triggers }; @@ -1595,7 +1594,6 @@ if (_canBuild) then { _builtObject spawn player_fireMonitor; } else { _builtObject setVariable ["ownerPUID", dayz_playerUID, true]; - if (_isPole) then { _friendsArr = [[dayz_playerUID, toArray (name player)]]; diff --git a/SQF/dayz_code/compile/snap_functions.sqf b/SQF/dayz_code/compile/snap_functions.sqf index 6a9568467..c4d6c801f 100644 --- a/SQF/dayz_code/compile/snap_functions.sqf +++ b/SQF/dayz_code/compile/snap_functions.sqf @@ -29,7 +29,7 @@ fnc_snapActionCleanup = { player removeAction s_player_toggleSnapSelect; s_player_toggleSnapSelect = -1; - {player removeAction _x;} count s_player_toggleSnapSelectPoint; + {player removeAction _x;} forEach s_player_toggleSnapSelectPoint; s_player_toggleSnapSelectPoint = []; snapActions = -1; @@ -71,40 +71,44 @@ fnc_initSnapPoints = { _x resize 3; // remove text element _objectSnapGizmo attachTo [_object, _x]; snapGizmos set [count snapGizmos, _objectSnapGizmo]; - } count _points; + } forEach _points; }; fnc_initSnapPointsNearby = { local _object = _this select 0; local _findObjects = nearestObjects [_object, [], DZE_snapRadius] - [_object]; - {deleteVehicle _x;} count snapGizmosNearby; // clean up previous radius + {deleteVehicle _x;} forEach snapGizmosNearby; // clean up previous radius snapGizmosNearby = []; { local _nearbyObject = _x; - local _typeOf = typeOf _x; + local _typeOf = typeOf _nearbyObject; local _pointsNearby = getArray (configFile >> "SnapBuilding" >> _typeOf >> "points"); local _displayName = getText (configFile >> "CfgVehicles" >> _typeOf >> "displayName"); - { - local _objectSnapGizmo = DZE_SNAP_HELPER_CLASS createVehicleLocal [0,0,0]; - _objectSnapGizmo setObjectTexture DZE_SNAP_POINT_RESET; // green - _objectSnapGizmo setDir (_nearbyObject getVariable["memDir",0]); - _objectSnapGizmo setVariable ["snappoint", [_displayName, _x select 3], false]; // store object and snapping point display names - _x resize 3; // remove text element - _objectSnapGizmo attachTo [_nearbyObject, _x]; + if (count _pointsNearby > 0) then { + local _memDir = _nearbyObject getVariable ["memDir",0]; + { + local _objectSnapGizmo = DZE_SNAP_HELPER_CLASS createVehicleLocal [0,0,0]; + _objectSnapGizmo setObjectTexture DZE_SNAP_POINT_RESET; // green + _objectSnapGizmo setPosATL (getPosATL _nearbyObject); + _objectSnapGizmo setVariable ["snappoint", [_displayName, _x select 3, _memDir], false]; // store object display name, snapping point text, and direction - snapGizmosNearby set [count snapGizmosNearby, _objectSnapGizmo]; // rebuild helper list - } count _pointsNearby; + _x resize 3; // remove text element + _objectSnapGizmo attachTo [_nearbyObject, _x]; + + snapGizmosNearby set [count snapGizmosNearby, _objectSnapGizmo]; // rebuild helper list + } forEach _pointsNearby; + }; } forEach _findObjects; }; fnc_initSnapPointsCleanup = { - {deleteVehicle _x;} count snapGizmos; + {deleteVehicle _x;} forEach snapGizmos; snapGizmos = []; - {deleteVehicle _x;} count snapGizmosNearby; + {deleteVehicle _x;} forEach snapGizmosNearby; snapGizmosNearby = []; snapActionState = localize "STR_EPOCH_ACTION_SNAP_OFF"; @@ -123,7 +127,7 @@ fnc_snapDistanceCheck = { _snapObject = { _objectHelper setPosASL (getPosASL _closestNearCurr); // snap object - DZE_memDir = getDir _closestNearCurr; + DZE_memDir = (_closestNearCurr getVariable ["snappoint", ["","",0]]) select 2; [_objectHelper, [DZE_memForBack, DZE_memLeftRight, DZE_memDir]] call fnc_SetPitchBankYaw; waitUntil {uiSleep 0.1; !helperDetach}; @@ -227,7 +231,7 @@ fnc_snapDistanceCheck = { _closestHeldCurr = _x; // update current _closestNearCurr = _nearCurr; // paired points }; - } count snapGizmos; + } forEach snapGizmos; } forEach snapGizmosNearby; if ((isNull _closestHeldCurr) || {_closestHeldCurr != _closestHeldPrev}) then { diff --git a/SQF/dayz_code/init/variables.sqf b/SQF/dayz_code/init/variables.sqf index 472822cee..7f8f6245e 100644 --- a/SQF/dayz_code/init/variables.sqf +++ b/SQF/dayz_code/init/variables.sqf @@ -321,12 +321,13 @@ if (!isDedicated) then { DZE_WaterSources = ["Land_pumpa","Land_Barrel_water","Land_Misc_Well_C_EP1","Land_Misc_Well_L_EP1","land_smd_water_pump","Watertank_DZE","Watertower_DZE","Land_water_tank","MAP_water_tank"]; // Helper Colors Require Reformatting + DZE_maxSnapObjectDiag = 18; // Internal diagonal distance of the largest buildable & snappable object in the game, currently the Land_WarfareBarrier10xTall_DZ. DO NOT MODIFY THIS! DZE_helperSize = [[3,"Sign_sphere100cm_EP1"],[2,"Sign_sphere25cm_EP1"],[1,"Sign_sphere10cm_EP1"]]; // array of helper sizes and corresponding class. Keep in reverse order for optimized lookup DZE_helperSizeDefault = 3; // default to large sphere DZE_NoRefundTransparency = 0.5; // Red Basebuilding Helper Transparency. min = 0.1, max = 1 DZE_removeTransparency = 0.5; // Green Basebuilding Helper Transparency. min = 0.1, max = 1 DZE_deconstructTransparency = 0.5; // Blue Basebuilding Helper Transparency. min = 0.1, max = 1 - DZE_largeObjects = ["MetalContainer2D_DZ","MetalContainer1G_DZ","MetalContainer1B_DZ","MetalContainer1A_DZ","DragonTeeth_DZ","DragonTeethBig_DZ","MetalFloor4x_DZ","Land_metal_floor_2x2_wreck","WoodFloor4x_DZ","Land_wood_floor_2x2_wreck","Scaffolding_DZ","CinderGateFrame_DZ","CinderGate_DZ","CinderGateLocked_DZ","WoodGateFrame_DZ","Land_DZE_WoodGate","Land_DZE_WoodGateLocked","WoodRamp_DZ","Metal_Drawbridge_DZ","Metal_DrawbridgeLocked_DZ","Land_WarfareBarrier10x_DZ","Land_WarfareBarrier10xTall_DZ","SandNestLarge_DZ"]; // adjust _allowedDistance in fn_selfActions.sqf for large modular/crafted objects + DZE_largeObjects = ["Watertower_DZE","DeerStand_DZ","MetalContainer2D_DZ","MetalContainer1G_DZ","MetalContainer1B_DZ","MetalContainer1A_DZ","DragonTeeth_DZ","DragonTeethBig_DZ","MetalFloor4x_DZ","Land_metal_floor_2x2_wreck","WoodFloor4x_DZ","Land_wood_floor_2x2_wreck","Scaffolding_DZ","CinderGateFrame_DZ","CinderGate_DZ","CinderGateLocked_DZ","WoodGateFrame_DZ","Land_DZE_WoodGate","Land_DZE_WoodGateLocked","WoodRamp_DZ","Metal_Drawbridge_DZ","Metal_DrawbridgeLocked_DZ","Land_WarfareBarrier10x_DZ","Land_WarfareBarrier10xTall_DZ","SandNestLarge_DZ"]; // adjust _allowedDistance in fn_selfActions.sqf for large modular/crafted objects DZE_NoRefundTexture = [0, format["#(argb,8,8,3)color(1.00,0.00,0.00,%1,ca)", (DZE_NoRefundTransparency max 0.1)] ]; // red DZE_removeTexture = [0, format["#(argb,8,8,3)color(0.15,1.00,0.40,%1,ca)", (DZE_removeTransparency max 0.1)] ]; // green