From e58e51dd2117fd3bc192787e486f8cf985b08199 Mon Sep 17 00:00:00 2001 From: engsr6982 <109733049+engsr6982@users.noreply.github.com> Date: Sun, 4 Aug 2024 17:50:11 +0800 Subject: [PATCH] chore: remove some shit --- src/tpr/TprManager.cc | 2 +- src/utils/ZoneCheck.h | 244 +----------------------------------------- 2 files changed, 6 insertions(+), 240 deletions(-) diff --git a/src/tpr/TprManager.cc b/src/tpr/TprManager.cc index c3c910d..33d8086 100644 --- a/src/tpr/TprManager.cc +++ b/src/tpr/TprManager.cc @@ -126,7 +126,7 @@ std::pair TprManager::randomPosition(Player& player) { if (tpr.RestrictedArea.Enable) { auto pvec = player.getPosition(); if (tpr.RestrictedArea.Type == "Circle") { // 圆形限制区域 - RCircle vec; + RandomArgs vec; vec.width = tpr.RestrictedArea.Radius; vec.centerX = tpr.RestrictedArea.UsePlayerPos ? pvec.x : tpr.RestrictedArea.CenterX; vec.centerZ = tpr.RestrictedArea.UsePlayerPos ? pvec.z : tpr.RestrictedArea.CenterZ; diff --git a/src/utils/ZoneCheck.h b/src/utils/ZoneCheck.h index 1850cf8..0b20c50 100644 --- a/src/utils/ZoneCheck.h +++ b/src/utils/ZoneCheck.h @@ -25,202 +25,6 @@ using string = std::string; namespace tps::utils::zonecheck { -// 根结构体 -namespace root_struct { -struct Center2 { - double centerX, centerZ; -}; -struct Center3 : Center2 { - double centerY; -}; -struct AABB2 { - double leftTopX, leftTopZ; - double rightBottomX, rightBottomZ; -}; -struct AABB3 : AABB2 { - double leftTopY, rightBottomY; -}; -struct Point2 { - double pointX, pointZ; -}; -struct Point3 : Point2 { - double pointY; -}; -struct Width { - double width; -}; -} // namespace root_struct - -// 2D/3D 圆/正方体/中心正方体 -struct Circle2 : root_struct::Center2, root_struct::Point2, root_struct::Width {}; -struct Circle3 : root_struct::Center3, root_struct::Point3, root_struct::Width {}; -struct Square2 : root_struct::AABB2, root_struct::Point2 {}; -struct Square3 : root_struct::AABB3, root_struct::Point3 {}; -struct CenteredSquare2 : root_struct::Center2, root_struct::Point2, root_struct::Width {}; -struct CenteredSquare3 : root_struct::Center3, root_struct::Point3, root_struct::Width {}; - - -// ================================================================================== isInside -// 2D/3D Circle -inline bool isInside(const Circle2& reg) { - double distance = std::sqrt(std::pow(reg.centerX - reg.pointX, 2) + std::pow(reg.centerZ - reg.pointZ, 2)); - return distance <= reg.width; -} -inline bool isInside(const Circle3& reg) { - double distance = std::sqrt( - std::pow(reg.centerX - reg.pointX, 2) + std::pow(reg.centerY - reg.pointY, 2) - + std::pow(reg.centerZ - reg.pointZ, 2) - ); - return distance <= reg.width; -} -// 2D/3D Square -inline bool isInside(const Square2& reg) { - double minX = std::min(reg.leftTopX, reg.rightBottomX); - double maxX = std::max(reg.leftTopX, reg.rightBottomX); - double minZ = std::max(reg.leftTopZ, reg.rightBottomZ); - double maxZ = std::min(reg.leftTopZ, reg.rightBottomZ); - if (reg.pointX < minX || reg.pointX > maxX) return false; - if (reg.pointZ > minZ || reg.pointZ < maxZ) return false; - return true; -} -inline bool isInside(const Square3& reg) { - double minX = std::min(reg.leftTopX, reg.rightBottomX); - double maxX = std::max(reg.leftTopX, reg.rightBottomX); - double minY = std::max(reg.leftTopY, reg.rightBottomY); - double maxY = std::min(reg.leftTopY, reg.rightBottomY); - double minZ = std::min(reg.leftTopZ, reg.rightBottomZ); - double maxZ = std::max(reg.leftTopZ, reg.rightBottomZ); - if (reg.pointX < minX || reg.pointX > maxX) return false; - if (reg.pointY > minY || reg.pointY < maxY) return false; - if (reg.pointZ < minZ || reg.pointZ > maxZ) return false; - return true; -} -// 2D/3D CenteredSquare -inline bool isInside(const CenteredSquare2& reg) { - double minX = reg.centerX - reg.width; - double maxX = reg.centerX + reg.width; - double minZ = reg.centerZ - reg.width; - double maxZ = reg.centerZ + reg.width; - return reg.pointX >= minX && reg.centerX <= maxX && reg.pointZ >= minZ && reg.centerZ <= maxZ; -} -inline bool isInside(const CenteredSquare3& reg) { - double minX = reg.centerX - reg.width; - double maxX = reg.centerX + reg.width; - double minY = reg.centerY - reg.width; - double maxY = reg.centerY + reg.width; - double minZ = reg.centerZ - reg.width; - double maxZ = reg.centerZ + reg.width; - return reg.pointX >= minX && reg.pointX <= maxX && reg.pointY >= minY && reg.pointY <= maxY && reg.pointZ >= minZ - && reg.pointZ <= maxZ; -} - -// ================================================================================== getBoundary - -struct Boundary { - string axis; // 边界轴 x, y, z - double boundary; // 边界位置 - double value; // 当前超出边界的值 - - Boundary() {} - Boundary(string axis, double boundary, double value) : axis(axis), boundary(boundary), value(value) {} -}; - -// 2D/3D Circle -inline Boundary getBoundary(const Circle2& reg) { - Boundary result; - double dx = reg.pointX - reg.centerX; - double dz = reg.pointZ - reg.centerZ; - double distance = std::sqrt(dx * dx + dz * dz); - if (distance > reg.width) { - double angle = std::atan2(dz, dx); - result.axis = std::abs(dx) > std::abs(dz) ? 'x' : 'z'; - result.value = result.axis == "x" ? reg.pointX : reg.pointZ; - result.boundary = - result.axis == "x" ? reg.centerX + reg.width * std::cos(angle) : reg.centerZ + reg.width * std::sin(angle); - } - return result; -} -inline Boundary getBoundary(const Circle3& reg) { - Boundary result; - double dx = reg.pointX - reg.centerX; - double dy = reg.pointY - reg.centerY; - double dz = reg.pointZ - reg.centerZ; - double distance = std::sqrt(dx * dx + dy * dy + dz * dz); - if (distance > reg.width) { - double ratio = reg.width / distance; - string axis = std::abs(dx) > std::abs(dy) ? (std::abs(dx) > std::abs(dz) ? "x" : "z") - : (std::abs(dy) > std::abs(dz) ? "y" : "z"); - result.axis = axis[0]; - result.value = axis == "x" ? reg.pointX : (axis == "y" ? reg.pointY : reg.pointZ); - result.boundary = (axis == "x" ? reg.centerX : (axis == "y" ? reg.centerY : reg.centerZ)) - + ratio * (axis == "x" ? dx : (axis == "y" ? dy : dz)); - } - return result; -} -// 2D/3D Square -inline Boundary getBoundary(const Square2& reg) { - Boundary result; - if (reg.pointX < reg.leftTopX || reg.pointX > reg.rightBottomX) { - result.axis = "x"; - result.value = reg.pointX; - result.boundary = reg.pointX < reg.leftTopX ? reg.leftTopX : reg.rightBottomX; - } else if (reg.pointZ < reg.leftTopZ || reg.pointZ > reg.rightBottomZ) { - result.axis = "z"; - result.value = reg.pointZ; - result.boundary = reg.pointZ < reg.leftTopZ ? reg.leftTopZ : reg.rightBottomZ; - } - return result; -} -inline Boundary getBoundary(const Square3& reg) { - Boundary result; - if (reg.pointX < reg.leftTopX || reg.pointX > reg.rightBottomX) { - result.axis = 'x'; - result.value = reg.pointX; - result.boundary = reg.pointX < reg.leftTopX ? reg.leftTopX : reg.rightBottomX; - } else if (reg.pointY < reg.leftTopY || reg.pointY > reg.rightBottomY) { - result.axis = 'y'; - result.value = reg.pointY; - result.boundary = reg.pointY < reg.leftTopY ? reg.leftTopY : reg.rightBottomY; - } else if (reg.pointZ < reg.leftTopZ || reg.pointZ > reg.rightBottomZ) { - result.axis = 'z'; - result.value = reg.pointZ; - result.boundary = reg.pointZ < reg.leftTopZ ? reg.leftTopZ : reg.rightBottomZ; - } - return result; -} -// 2D/3D CenteredSquare -inline Boundary getBoundary(const CenteredSquare2& reg) { - Boundary result; - if (std::abs(reg.pointX - reg.centerX) > reg.width) { - result.axis = "x"; - result.value = reg.pointX; - result.boundary = reg.pointX < reg.centerX ? reg.centerX - reg.width : reg.centerX + reg.width; - } else if (std::abs(reg.pointZ - reg.centerZ) > reg.width) { - result.axis = "z"; - result.value = reg.pointZ; - result.boundary = reg.pointZ < reg.centerZ ? reg.centerZ - reg.width : reg.centerZ + reg.width; - } - return result; -} -inline Boundary getBoundary(const CenteredSquare3& reg) { - Boundary result; - if (std::abs(reg.pointX - reg.centerX) > reg.width) { - result.axis = 'x'; - result.value = reg.pointX; - result.boundary = reg.pointX < reg.centerX ? reg.centerX - reg.width : reg.centerX + reg.width; - } else if (std::abs(reg.pointY - reg.centerY) > reg.width) { - result.axis = 'y'; - result.value = reg.pointY; - result.boundary = reg.pointY < reg.centerY ? reg.centerY - reg.width : reg.centerY + reg.width; - } else if (std::abs(reg.pointZ - reg.centerZ) > reg.width) { - result.axis = 'z'; - result.value = reg.pointZ; - result.boundary = reg.pointZ < reg.centerZ ? reg.centerZ - reg.width : reg.centerZ + reg.width; - } - return result; -} - -// ================================================================================== randomPoint namespace random { @@ -234,25 +38,19 @@ inline int randomNumber(int min, int max) { return dist(mt); } -struct RCircle : root_struct::Center2, root_struct::Width {}; -struct RSquare : root_struct::AABB2 {}; -struct RCenteredSquare : root_struct::Center2, root_struct::Width {}; +struct RandomArgs { + double centerX, centerZ, width; +}; +struct RCenteredSquare : RandomArgs {}; // 2D Circle x z -inline std::pair randomPoint(const RCircle& reg) { +inline std::pair randomPoint(const RandomArgs& reg) { double minX = reg.centerX - reg.width; double maxX = reg.centerX + reg.width; double minZ = reg.centerZ - reg.width; double maxZ = reg.centerZ + reg.width; return {randomNumber(minX, maxX), randomNumber(minZ, maxZ)}; } -// 2D Square -inline std::pair randomPoint(const RSquare& reg) { - RSquare reg1 = reg; - if (reg1.leftTopX > reg1.rightBottomX) std::swap(reg1.leftTopX, reg1.rightBottomX); - if (reg1.leftTopZ > reg1.rightBottomZ) std::swap(reg1.leftTopZ, reg1.rightBottomZ); - return {randomNumber(reg1.leftTopX, reg1.rightBottomX), randomNumber(reg1.leftTopZ, reg1.rightBottomZ)}; -} // 2D CenteredSquare inline std::pair randomPoint(const RCenteredSquare& reg) { double minX = reg.centerX - reg.width; @@ -269,38 +67,6 @@ inline std::pair randomPoint(const RCenteredSquare& reg) { // ================================================================================== findPos namespace find { - -/* -@code lang=typescript -findPos( - { - x: 0, - z: 0, - dimid: 0 - }, - { - startingValue: 301 - endValue: 0 - stopValue: 10 - }, - [ - "minecraft:lava", - "minecraft:flowing_lava" - ], - { - "offset1": 1, - "offset2": 2 - } -): { - status: 0 | 1, - x: int, - y: int, - z: int, - dimid: int -} -@endcode -*/ - struct FindArgs { int forStart = 320; // 遍历开始值 int forStop = -64; // 遍历结束值