예제 #1
0
 public Tunnel(List <Vector3Int> cellChunkCoordinates, HollowGroup first, HollowGroup second, Vector3Int firstCaveConnectionPoint, Vector3Int secondCaveConnectionPoint)
 {
     CellChunkCoordinates = cellChunkCoordinates;
     _first  = first;
     _second = second;
     FirstCaveConnectionPoint  = firstCaveConnectionPoint;
     SecondCaveConnectionPoint = secondCaveConnectionPoint;
 }
예제 #2
0
    public async Task PlaceInCave(HollowGroup cave)     //TODO different placements
    {
        Vector3Int lowestPointChunkPosition = cave.GetLowestPoint();

        await GenerateNearbyChunksAsync(DestinationChunkCoordinate);

        CaveChunk destinationChunk = await ChunkManager.CreateChunkAsync(DestinationChunkCoordinate);

        Vector3 offsetPosition = (Vector3)ChunkManager.MeshSettings.GridSize / 2.0f;
        Vector3 position       = destinationChunk.GetWorldPosition(lowestPointChunkPosition) + offsetPosition;

        transform.position = position;
    }
예제 #3
0
        private static (HollowGroup hollow, Vector3Int firstPoint, Vector3Int secondPoint) ClosestNotConnectedHollow(HollowGroup hollow, List <HollowGroup> hollows, List <HollowGroup> alreadyConnectedCaves)
        {
            Vector3Int  firstPoint     = default;
            Vector3Int  secondPoint    = default;
            float       minSqrDistance = 0;
            HollowGroup closestHollow  = null;

            foreach (HollowGroup nextHollow in hollows)
            {
                if (nextHollow == hollow || alreadyConnectedCaves.Contains(nextHollow))
                {
                    continue;
                }

                Random rand = new Random();

                int firstPointIndex  = rand.Next(0, hollow.CellChunkCoordinates.Count);
                int secondPointIndex = rand.Next(0, nextHollow.CellChunkCoordinates.Count);

                return(nextHollow, hollow.CellChunkCoordinates[firstPointIndex], nextHollow.CellChunkCoordinates[secondPointIndex]);

                foreach (Vector3Int firstCoordinate in hollow.CellChunkCoordinates)
                {
                    foreach (Vector3Int secondCoordinate in nextHollow.CellChunkCoordinates)
                    {
                        float sqrDistance = 0;
                        //float sqrDistance = (firstCoordinate - secondCoordinate).sqrMagnitude;

                        if (EmergencyShutdown.Instance.CheckForShutdownTimer())
                        {
                            return(null, Vector3Int.zero, Vector3Int.zero);
                        }

                        if (sqrDistance < minSqrDistance || closestHollow == null)
                        {
                            firstPoint     = firstCoordinate;
                            secondPoint    = secondCoordinate;
                            minSqrDistance = sqrDistance;
                            closestHollow  = nextHollow;
                        }
                    }
                }
            }

            return(closestHollow, firstPoint, secondPoint);
        }
예제 #4
0
        private static (HollowGroup hollow, Vector3Int firstPoint, Vector3Int secondPoint) ClosestNotConnectedHollow(HollowGroup hollow, List <HollowGroup> hollows, List <HollowGroup> alreadyConnectedCaves)
        {
            Vector3Int  firstPoint    = default;
            Vector3Int  secondPoint   = default;
            float       minDistance   = 0;
            HollowGroup closestHollow = null;

            foreach (HollowGroup nextHollow in hollows)
            {
                if (nextHollow == hollow || alreadyConnectedCaves.Contains(nextHollow))
                {
                    continue;
                }

                foreach (Vector3Int firstCoordinate in hollow.CellChunkCoordinates)
                {
                    if (firstCoordinate.z != 0)
                    {
                        continue;
                    }

                    foreach (Vector3Int secondCoordinate in nextHollow.CellChunkCoordinates)
                    {
                        if (secondCoordinate.z != 0)
                        {
                            continue;
                        }

                        float distance = Vector3Int.Distance(firstCoordinate, secondCoordinate);

                        if (distance < minDistance || closestHollow == null)
                        {
                            firstPoint    = firstCoordinate;
                            secondPoint   = secondCoordinate;
                            minDistance   = distance;
                            closestHollow = nextHollow;
                        }
                    }
                }
            }

            return(closestHollow, firstPoint, secondPoint);
        }