|
@@ -360,6 +360,69 @@ namespace CommonAI.Zone.Instance
|
|
|
return mSpaceDiv.GetNearObjectsCapacity(x, y);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 以目标点为中心,circle为半径,找可行走区域。找到了返回true;找不到返回false;
|
|
|
+ * sx, sy 起始位置
|
|
|
+ * dstx, dsty 目标位置
|
|
|
+ * circle 搜寻半径
|
|
|
+ * outx, outy修改后的目标点
|
|
|
+ */
|
|
|
+ public bool GetNearWay(float sx, float sy, float dstx, float dsty, float circle, ref float outx, ref float outy)
|
|
|
+ {
|
|
|
+ //以目标点为中心,一圈一圈向外查找可行走的块
|
|
|
+ //起始点与终点连线方向上的点优先
|
|
|
+ int W = Terrain.GridCellW;
|
|
|
+ int H = Terrain.GridCellH;
|
|
|
+ float squCircle = circle * circle;
|
|
|
+ int dr = ((int)circle) / W;
|
|
|
+
|
|
|
+ float vx = sx > dstx ? 1 : -1;
|
|
|
+ float vy = sy > dsty ? 1 : -1;
|
|
|
+ bool f = true;
|
|
|
+ for (int r = 1; r <= dr; r++)
|
|
|
+ {
|
|
|
+ for (int v = 1; v <= 4; v++)
|
|
|
+ {
|
|
|
+ float xx = dstx + W * r * vx;
|
|
|
+ float yy = dsty + H * r * vy;
|
|
|
+ for (int dx = f ? 0 : 1; f ? dx <= r : dx < r; dx++)
|
|
|
+ {
|
|
|
+ float x = dstx + dx * W * vx;
|
|
|
+ if (MathVector.getDistanceSquare(x, yy, dstx, dsty) < squCircle)
|
|
|
+ {
|
|
|
+ if (!path_finder.TouchMapBlock(((int)x) / W, ((int)yy) / H))
|
|
|
+ {
|
|
|
+ outx = x;
|
|
|
+ outy = yy;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int dy = f ? 1 : 0; f ? dy < r : dy <= r; dy++)
|
|
|
+ {
|
|
|
+ float y = dsty + dy * H * vy;
|
|
|
+ if (MathVector.getDistanceSquare(xx, y, dstx, dsty) < squCircle)
|
|
|
+ {
|
|
|
+ if (!path_finder.TouchMapBlock(((int)xx) / W, ((int)y) / H))
|
|
|
+ {
|
|
|
+ outx = xx;
|
|
|
+ outy = y;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (f) vy *= -1;
|
|
|
+ else vx *= -1;
|
|
|
+ f = !f;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ outx = -1;
|
|
|
+ outy = -1;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
//---------------------------------------------------------------------------------------------------------------
|
|
|
#region _Deprecated_
|
|
|
/// <summary>
|