Skip to content

Commit

Permalink
chore: remove some shit
Browse files Browse the repository at this point in the history
  • Loading branch information
engsr6982 committed Aug 4, 2024
1 parent 84f7c9b commit e58e51d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 240 deletions.
2 changes: 1 addition & 1 deletion src/tpr/TprManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ std::pair<int, int> 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;
Expand Down
244 changes: 5 additions & 239 deletions src/utils/ZoneCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<int, int> randomPoint(const RCircle& reg) {
inline std::pair<int, int> 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<int, int> 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<int, int> randomPoint(const RCenteredSquare& reg) {
double minX = reg.centerX - reg.width;
Expand All @@ -269,38 +67,6 @@ inline std::pair<int, int> 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; // 遍历结束值
Expand Down

0 comments on commit e58e51d

Please sign in to comment.