Esempio n. 1
0
        private void SubdivideAllCurrentSectors()
        {
            List <CoastLineCreationSectorBoundary> currentCoastlinePropagationSectors = coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors();

            coastLinePropagationSectors.SwitchToNextPropagationList();

            CoastLineCreationSectorBoundary previousSector = currentCoastlinePropagationSectors[0];
            CoastLineCreationSectorBoundary currentSector  = currentCoastlinePropagationSectors[0];
            CoastLineCreationSectorBoundary nextSector     = currentCoastlinePropagationSectors[0];

            for (int i = 0; i < currentCoastlinePropagationSectors.Count; i++)
            {
                if (0 != i)
                {
                    if (coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors().Count > 0)
                    {
                        previousSector = coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors()[coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors().Count - 1];
                    }
                    else
                    {
                        previousSector = currentCoastlinePropagationSectors[i - 1];
                    }
                }

                currentSector = currentCoastlinePropagationSectors[i];

                if (currentCoastlinePropagationSectors.Count - 1 != i)
                {
                    nextSector = currentCoastlinePropagationSectors[i + 1];
                }
                else
                {
                    nextSector = currentCoastlinePropagationSectors[0];
                }

                CoastLinePropagationEnterExitPoint currentSectorEntryPoint = DetermineEntryPointFromAdjacentSectors(previousSector, currentSector);
                CoastLinePropagationEnterExitPoint currentSectorExitPoint  = DetermineEntryPointFromAdjacentSectors(nextSector, currentSector);

                if (0 == i && currentCoastlinePropagationSectors.Count > 1 && currentSectorEntryPoint == CoastLinePropagationEnterExitPoint.NONE)
                {
                    currentSectorEntryPoint = DetermineEntryPointFromAdjacentSectors(currentCoastlinePropagationSectors[currentCoastlinePropagationSectors.Count - 1], currentSector);
                }

                if (currentSector.ToX - currentSector.FromX < 2)
                {
                    GenerateCoastlineInTrivialCase(currentSector, currentSectorEntryPoint, currentSectorExitPoint);
                }
                else
                {
                    GenerateCoastLineForFourSectors(currentSector, currentSectorEntryPoint, currentSectorExitPoint);
                }
            }

            if (coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors().Count != 0)
            {
                SubdivideAllCurrentSectors();
            }
        }
Esempio n. 2
0
            public override bool Equals(object other)
            {
                if (other is CoastLineCreationSectorBoundary)
                {
                    CoastLineCreationSectorBoundary otherBoundary = (CoastLineCreationSectorBoundary)other;

                    return(FromX == otherBoundary.FromX &&
                           FromY == otherBoundary.FromY &&
                           ToX == otherBoundary.ToX &&
                           ToY == otherBoundary.ToY);
                }

                return(false);
            }
Esempio n. 3
0
        public List <BlockPosition> GenerateCoastline(int islandEdgeLength)
        {
            edgeLengthOfIsland = islandEdgeLength;
            coastLineMinHeight = randomNumberGenerator.GenerateIntegerBetweenAnd(96, 128);

            if (edgeLengthOfIsland < 3)
            {
                GenerateCoastlineInTrivialCase(new CoastLineCreationSectorBoundary(0, 0, edgeLengthOfIsland - 1, 0, edgeLengthOfIsland - 1), CoastLinePropagationEnterExitPoint.NONE, CoastLinePropagationEnterExitPoint.NONE);
            }
            else
            {
                CoastLineCreationSectorBoundary boundary = new CoastLineCreationSectorBoundary(0, 0, edgeLengthOfIsland - 1, 0, edgeLengthOfIsland - 1);
                coastLinePropagationSectors.PutSector(boundary);

                SubdivideAllCurrentSectors();
            }

            return(coastLineHeightMap);
        }
Esempio n. 4
0
        private bool NextSectorToMoveToIsLegit(int nextSectorNo)
        {
            CoastLineCreationSectorBoundary previousSector = coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors()[coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors().Count - 1];
            short previousSectorNo = previousSector.SectorNo;

            switch (previousSectorNo)
            {
            case TOP_LEFT_SECTOR_ID:
                return(nextSectorNo == TOP_RIGHT_SECTOR_ID || nextSectorNo == BOTTOM_LEFT_SECTOR_ID);

            case TOP_RIGHT_SECTOR_ID:
                return(nextSectorNo == TOP_LEFT_SECTOR_ID || nextSectorNo == BOTTOM_RIGHT_SECTOR_ID);

            case BOTTOM_LEFT_SECTOR_ID:
                return(nextSectorNo == TOP_LEFT_SECTOR_ID || nextSectorNo == BOTTOM_RIGHT_SECTOR_ID);

            case BOTTOM_RIGHT_SECTOR_ID:
                return(nextSectorNo == TOP_RIGHT_SECTOR_ID || nextSectorNo == BOTTOM_LEFT_SECTOR_ID);
            }

            return(false);
        }
Esempio n. 5
0
        private CoastLineCreationSectorBoundary GetSectorBoundaryFromSectorNumber(CoastLineCreationSectorBoundary parentSector, int sectorNumber)
        {
            CoastLineCreationSectorBoundary sector0 = new CoastLineCreationSectorBoundary(TOP_LEFT_SECTOR_ID, parentSector.FromX, parentSector.FromX + (parentSector.ToX - parentSector.FromX) / 2, parentSector.FromY, parentSector.FromY + (parentSector.ToY - parentSector.FromY) / 2);
            CoastLineCreationSectorBoundary sector1 = new CoastLineCreationSectorBoundary(TOP_RIGHT_SECTOR_ID, parentSector.FromX + (parentSector.ToX - parentSector.FromX) / 2 + 1, parentSector.ToX, parentSector.FromY, parentSector.FromY + (parentSector.ToY - parentSector.FromY) / 2);
            CoastLineCreationSectorBoundary sector2 = new CoastLineCreationSectorBoundary(BOTTOM_LEFT_SECTOR_ID, parentSector.FromX, parentSector.FromX + (parentSector.ToX - parentSector.FromX) / 2, parentSector.FromY + (parentSector.ToY - parentSector.FromY) / 2 + 1, parentSector.ToY);
            CoastLineCreationSectorBoundary sector3 = new CoastLineCreationSectorBoundary(BOTTOM_RIGHT_SECTOR_ID, parentSector.FromX + (parentSector.ToX - parentSector.FromX) / 2 + 1, parentSector.ToX, parentSector.FromY + (parentSector.ToY - parentSector.FromY) / 2 + 1, parentSector.ToY);

            switch (sectorNumber)
            {
            case TOP_LEFT_SECTOR_ID:
                return(sector0);

            case TOP_RIGHT_SECTOR_ID:
                return(sector1);

            case BOTTOM_LEFT_SECTOR_ID:
                return(sector2);

            case BOTTOM_RIGHT_SECTOR_ID:
                return(sector3);
            }

            return(sector3);
        }
Esempio n. 6
0
 public bool IsSmallerThan(CoastLineCreationSectorBoundary other)
 {
     return(ToX - FromX < other.ToX - other.FromX &&
            ToY - FromY < other.ToY - other.FromY);
 }
Esempio n. 7
0
        private void PlaceBlockBasedOnNumberAndCurrentSector(int sectorToPlaceBlockAt, CoastLineCreationSectorBoundary coastLineGenerationChunkBoundary)
        {
            BlockPosition placementPosition;

            switch (sectorToPlaceBlockAt)
            {
            case TOP_LEFT_SECTOR_ID:
                placementPosition = new BlockPosition(coastLineGenerationChunkBoundary.FromX, coastLineMinHeight, coastLineGenerationChunkBoundary.FromY);
                PlaceRockBlockAtIfItIsNotAir(placementPosition);

                break;

            case TOP_RIGHT_SECTOR_ID:
                placementPosition = new BlockPosition(coastLineGenerationChunkBoundary.FromX + 1, coastLineMinHeight, coastLineGenerationChunkBoundary.FromY);
                PlaceRockBlockAtIfItIsNotAir(placementPosition);

                break;

            case BOTTOM_LEFT_SECTOR_ID:
                placementPosition = new BlockPosition(coastLineGenerationChunkBoundary.FromX, coastLineMinHeight, coastLineGenerationChunkBoundary.FromY + 1);
                PlaceRockBlockAtIfItIsNotAir(placementPosition);

                break;

            case BOTTOM_RIGHT_SECTOR_ID:
                placementPosition = new BlockPosition(coastLineGenerationChunkBoundary.FromX + 1, coastLineMinHeight, coastLineGenerationChunkBoundary.FromY + 1);
                PlaceRockBlockAtIfItIsNotAir(placementPosition);

                break;
            }
        }
Esempio n. 8
0
        private void GenerateCoastlineInTrivialCase(CoastLineCreationSectorBoundary coastLineGenerationChunkBoundary, CoastLinePropagationEnterExitPoint enterPoint, CoastLinePropagationEnterExitPoint exitPoint)
        {
            if (0 == coastLineGenerationChunkBoundary.ToX - coastLineGenerationChunkBoundary.FromX)
            {
                int shouldSetBlock = randomNumberGenerator.GenerateRandomPositiveInteger(1);

                if (1 == shouldSetBlock)
                {
                    coastLineHeightMap.Add(new BlockPosition(coastLineGenerationChunkBoundary.FromX, coastLineMinHeight, coastLineGenerationChunkBoundary.FromX));
                }
            }
            else if (1 == coastLineGenerationChunkBoundary.ToX - coastLineGenerationChunkBoundary.FromX)
            {
                if (enterPoint == CoastLinePropagationEnterExitPoint.NONE && exitPoint == CoastLinePropagationEnterExitPoint.NONE)
                {
                    int amountOfSubGenerationSteps = randomNumberGenerator.GenerateRandomPositiveInteger(3);
                    int i = 0;

                    while (i < amountOfSubGenerationSteps)
                    {
                        int sectorToPlaceBlockAt = randomNumberGenerator.GenerateRandomPositiveInteger(3);

                        BlockPosition placementPosition;
                        switch (sectorToPlaceBlockAt)
                        {
                        case TOP_LEFT_SECTOR_ID:
                            placementPosition = new BlockPosition(coastLineGenerationChunkBoundary.FromX, coastLineMinHeight, coastLineGenerationChunkBoundary.FromY);

                            if (!coastLineHeightMap.Contains(placementPosition))
                            {
                                coastLineHeightMap.Add(placementPosition);
                                i++;
                            }

                            break;

                        case TOP_RIGHT_SECTOR_ID:
                            placementPosition = new BlockPosition(coastLineGenerationChunkBoundary.FromX + 1, coastLineMinHeight, coastLineGenerationChunkBoundary.FromY);

                            if (!coastLineHeightMap.Contains(placementPosition))
                            {
                                coastLineHeightMap.Add(placementPosition);
                                i++;
                            }

                            break;

                        case BOTTOM_LEFT_SECTOR_ID:
                            placementPosition = new BlockPosition(coastLineGenerationChunkBoundary.FromX, coastLineMinHeight, coastLineGenerationChunkBoundary.FromY + 1);

                            if (!coastLineHeightMap.Contains(placementPosition))
                            {
                                coastLineHeightMap.Add(placementPosition);
                                i++;
                            }

                            break;

                        case BOTTOM_RIGHT_SECTOR_ID:
                            placementPosition = new BlockPosition(coastLineGenerationChunkBoundary.FromX + 1, coastLineMinHeight, coastLineGenerationChunkBoundary.FromY + 1);

                            if (!coastLineHeightMap.Contains(placementPosition))
                            {
                                coastLineHeightMap.Add(placementPosition);
                                i++;
                            }

                            break;
                        }
                    }
                }
                else
                {
                    int amountOfBlocksPlaced = 0;

                    while (amountOfBlocksPlaced < 2)
                    {
                        if (0 == amountOfBlocksPlaced)
                        {
                            if (enterPoint == CoastLinePropagationEnterExitPoint.NONE)
                            {
                                int nextSectorNo = randomNumberGenerator.GenerateRandomPositiveInteger(3);
                                PlaceBlockBasedOnNumberAndCurrentSector(nextSectorNo, coastLineGenerationChunkBoundary);

                                amountOfBlocksPlaced++;
                            }
                            else
                            {
                                int nextSectorNo = randomNumberGenerator.GenerateRandomPositiveInteger(3);

                                if (SectorIsLegitAsEntrySector(nextSectorNo, enterPoint))
                                {
                                    PlaceBlockBasedOnNumberAndCurrentSector(nextSectorNo, coastLineGenerationChunkBoundary);

                                    amountOfBlocksPlaced++;
                                }
                            }
                        }
                        else
                        {
                            int nextSectorNo = randomNumberGenerator.GenerateRandomPositiveInteger(3);

                            if (SectorIsLegitAsExitSector(nextSectorNo, exitPoint))
                            {
                                PlaceBlockBasedOnNumberAndCurrentSector(nextSectorNo, coastLineGenerationChunkBoundary);

                                amountOfBlocksPlaced++;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        private CoastLinePropagationEnterExitPoint DetermineEntryPointFromAdjacentSectors(CoastLineCreationSectorBoundary previousSector, CoastLineCreationSectorBoundary nextSector)
        {
            if (previousSector.IsSmallerThan(nextSector))
            {
                if (previousSector.FromX < nextSector.FromX)
                {
                    if (previousSector.FromY < nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP_LEFT);
                    }
                    else if (previousSector.FromY == nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP_LEFT_LEFT);
                    }
                    else if (previousSector.FromY > nextSector.FromY && previousSector.FromY < nextSector.ToY)
                    {
                        return(CoastLinePropagationEnterExitPoint.BOTTOM_LEFT_LEFT);
                    }

                    return(CoastLinePropagationEnterExitPoint.BOTTOM_LEFT);
                }
                else if (previousSector.FromX == nextSector.FromX)
                {
                    if (previousSector.FromY < nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP_LEFT_UP);
                    }

                    return(CoastLinePropagationEnterExitPoint.BOTTOM_LEFT_DOWN);
                }
                else if (previousSector.FromX > nextSector.FromX && previousSector.FromX < nextSector.ToX)
                {
                    if (previousSector.FromY < nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP_RIGHT_UP);
                    }

                    return(CoastLinePropagationEnterExitPoint.BOTTOM_RIGHT_DOWN);
                }
                else
                {
                    if (previousSector.FromY < nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP_RIGHT);
                    }
                    else if (previousSector.FromY == nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP_RIGHT_RIGHT);
                    }
                    else if (previousSector.FromY > nextSector.FromY && previousSector.FromY < nextSector.ToY)
                    {
                        return(CoastLinePropagationEnterExitPoint.BOTTOM_RIGHT_RIGHT);
                    }

                    return(CoastLinePropagationEnterExitPoint.BOTTOM_RIGHT);
                }
            }
            else
            {
                if (previousSector.FromX < nextSector.FromX)
                {
                    if (previousSector.FromY < nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP_LEFT);
                    }
                    else if (previousSector.FromY == nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.LEFT);
                    }

                    return(CoastLinePropagationEnterExitPoint.BOTTOM_LEFT);
                }
                else if (previousSector.FromX == nextSector.FromX)
                {
                    if (previousSector.FromY < nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP);
                    }
                    else if (previousSector.FromY == nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.NONE);
                    }

                    return(CoastLinePropagationEnterExitPoint.BOTTOM);
                }
                else if (previousSector.FromX > nextSector.FromX)
                {
                    if (previousSector.FromY < nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.TOP_RIGHT);
                    }
                    else if (previousSector.FromY == nextSector.FromY)
                    {
                        return(CoastLinePropagationEnterExitPoint.RIGHT);
                    }

                    return(CoastLinePropagationEnterExitPoint.BOTTOM_RIGHT);
                }
            }

            return(CoastLinePropagationEnterExitPoint.NONE);
        }
Esempio n. 10
0
        private void GenerateCoastLineForFourSectors(CoastLineCreationSectorBoundary parentSector, CoastLinePropagationEnterExitPoint entryPoint, CoastLinePropagationEnterExitPoint exitPoint)
        {
            if (parentSector.ToX - parentSector.FromX < 2)
            {
                GenerateCoastlineInTrivialCase(parentSector, entryPoint, exitPoint);
            }
            else if (entryPoint == CoastLinePropagationEnterExitPoint.NONE && exitPoint == CoastLinePropagationEnterExitPoint.NONE)
            {
                while (coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors().Count < 4)
                {
                    int nextSectorNo = randomNumberGenerator.GenerateRandomPositiveInteger(3);
                    if (coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors().Count > 0)
                    {
                        bool nextSectorIsLegit = NextSectorToMoveToIsLegit(nextSectorNo);

                        if (!nextSectorIsLegit)
                        {
                            continue;
                        }
                    }

                    CoastLineCreationSectorBoundary nextSectorToRunTo = GetSectorBoundaryFromSectorNumber(parentSector, nextSectorNo);

                    if (!coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors().Contains(nextSectorToRunTo))
                    {
                        coastLinePropagationSectors.PutSector(nextSectorToRunTo);
                    }
                }
            }
            else if (entryPoint != CoastLinePropagationEnterExitPoint.NONE)
            {
                bool allSectorsAreFilled  = false;
                int  amountOfAddedSectors = 0;
                while (!allSectorsAreFilled)
                {
                    int nextSectorNo = randomNumberGenerator.GenerateRandomPositiveInteger(3);
                    if (0 == amountOfAddedSectors)
                    {
                        if (SectorIsLegitAsEntrySector(nextSectorNo, entryPoint))
                        {
                            CoastLineCreationSectorBoundary nextSectorToRunTo = GetSectorBoundaryFromSectorNumber(parentSector, nextSectorNo);
                            coastLinePropagationSectors.PutSector(nextSectorToRunTo);
                            amountOfAddedSectors++;
                        }
                    }
                    else if (4 == amountOfAddedSectors)
                    {
                        allSectorsAreFilled = true;
                    }
                    else
                    {
                        if (exitPoint != CoastLinePropagationEnterExitPoint.NONE)
                        {
                            if (NextSectorToMoveToIsLegit(nextSectorNo))
                            {
                                CoastLineCreationSectorBoundary nextSector = GetSectorBoundaryFromSectorNumber(parentSector, nextSectorNo);

                                if (!coastLinePropagationSectors.ContainsSectorInCurrents(nextSector))
                                {
                                    coastLinePropagationSectors.PutSector(nextSector);
                                    amountOfAddedSectors++;
                                }
                            }

                            if (SectorIsLegitAsExitSector(coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors()[coastLinePropagationSectors.GetCurrentCoastLinePropagationSectors().Count - 1].SectorNo, exitPoint))
                            {
                                allSectorsAreFilled = true;
                            }
                        }
                    }
                }
            }
        }