public Vector3i?GetClosestEmptyColumn(int cx, int cz, int rad) { Vector3i center = new Vector3i(cx, 0, cz); Vector3i?closest = null; for (int z = cz - rad; z <= cz + rad; z++) { for (int x = cx - rad; x <= cx + rad; x++) { Vector3i current = new Vector3i(x, 0, z); int dis = center.DistanceSquared(current); if (dis > rad * rad) { continue; } if (IsBuilt(x, z)) { continue; } if (!closest.HasValue) { closest = current; } else { int oldDis = center.DistanceSquared(closest.Value); if (dis < oldDis) { closest = current; } } } } return(closest); }
public Vector3i? GetClosestEmptyColumn(int cx, int cz, int rad) { Vector3i center = new Vector3i(cx, 0, cz); Vector3i? closest = null; for(int z=cz-rad; z<=cz+rad; z++) { for(int x=cx-rad; x<=cx+rad; x++) { Vector3i current = new Vector3i(x, 0, z); int dis = center.DistanceSquared( current ); if(dis > rad*rad) continue; if( IsBuilt(x, z) ) continue; if(!closest.HasValue) { closest = current; } else { int oldDis = center.DistanceSquared(closest.Value); if(dis < oldDis) closest = current; } } } return closest; }
protected Vector3 TryFindLand(Vector3i center) { Vector3i?land = null; for (int x = center.x - 20; x <= center.x + 20; x++) { for (int z = center.z - 20; z <= center.z + 20; z++) { int height = MapLight.GetRaySafe(x, z); Block surface = Map.GetBlockSafe(x, height - 1, z); if (!surface.IsFluid()) { Vector3i current = new Vector3i(x, height, z); if (!land.HasValue) { land = current; } else { int dis = center.DistanceSquared(current); int oldDis = center.DistanceSquared(land.Value); if (dis < oldDis) { land = current; } } } } } if (land.HasValue) { return(land.Value.ToVector3()); } return(new Vector3(center.x, MapLight.GetRay(center.x, center.z), center.z)); }
private static int CompareChunksByDistance(Chunk first, Chunk second, Vector3i pos) { return(Vector3i.DistanceSquared(first.Position, pos).CompareTo(Vector3i.DistanceSquared(second.Position, pos))); }
private PathingNode _parent; //The node that occurs before this one in the potential path public PathingNode(Vector3i _loc, Vector3i goal) { this.loc = _loc; f_score = (int)((loc.DistanceSquared(goal))); }