mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 18:01:39 +00:00
The client tests a box against the property's boundary path and build height: the box around the path's points, raised to maxBuildHeight above its lowest point and with no floor, then the box's centre and bottom corners against the path as a polygon. The server placed a model wherever UpdateModelFromClient said. PropertyBounds is that test, and UpdateModelPosition runs the model's position through it with the path and height DownloadPropertyData sends. The server has no box for a model, so only the position is tested. A refused placement leaves the item in the inventory and is answered with PlaceModelResponse 12, for which the client shows its placement bounds message. Models already on a property are not tested, moved or removed, wherever they stand; a property without a boundary path refuses nothing. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
40 lines
2.0 KiB
C++
40 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
#include "NiPoint3.h"
|
|
|
|
// Whether a box is inside a property plot, as the client decides it from the boundary path and build height that
|
|
// DownloadPropertyData gives it.
|
|
namespace PropertyBounds {
|
|
// What the check answers (the client's values)
|
|
enum Result : int32_t {
|
|
NoPath = -1, // the property has no boundary path
|
|
Inside = 0,
|
|
TooWide = 1, // the box is wider than the plot (3 when it is too long as well, or instead)
|
|
TooTall = 2, // the box is taller than the plot's build space
|
|
TooLong = 3,
|
|
CentreOutside = 4, // the box's centre is outside the boundary polygon
|
|
Outside = 5 // a side of the box is outside the plot's box, or a bottom corner outside the polygon
|
|
};
|
|
|
|
// The point's side of the boundary edge nearest to it, heights ignored.
|
|
// The path is a closed polygon whose points run so that the inside is on the positive side of every edge; distance,
|
|
// when given, receives the distance to that nearest edge.
|
|
bool PointInPolygonXZ(const NiPoint3& point, const std::vector<NiPoint3>& path, float* distance = nullptr);
|
|
|
|
// The plot is the box around the path's points; with checkHeight
|
|
// and a build height it reaches up to the path's lowest point plus maxBuildHeight (there is no floor). The box must
|
|
// fit in it, and its centre and four bottom corners must be inside the polygon.
|
|
int32_t CheckBoxAgainstPath(const NiPoint3& boxMin, const NiPoint3& boxMax, const std::vector<NiPoint3>& path, bool checkHeight, float maxBuildHeight, float* distance = nullptr);
|
|
|
|
// A placed model's position against the plot. The server does not hold a model's box, so only the point is tested:
|
|
// this never refuses what the box test would allow for a model that stands on its position.
|
|
inline bool IsPositionInside(const NiPoint3& position, const std::vector<NiPoint3>& path, const float maxBuildHeight) {
|
|
const auto result = CheckBoxAgainstPath(position, position, path, true, maxBuildHeight);
|
|
// Nothing to test against is not a refusal
|
|
return result == Inside || result == NoPath;
|
|
}
|
|
}
|