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(); } }
private bool SectorIsLegitAsEntrySector(int sectorNo, CoastLinePropagationEnterExitPoint entryPoint) { if (entryPoint == CoastLinePropagationEnterExitPoint.LEFT) { return(sectorNo == TOP_LEFT_SECTOR_ID || sectorNo == BOTTOM_LEFT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.TOP) { return(sectorNo == TOP_LEFT_SECTOR_ID || sectorNo == TOP_RIGHT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.RIGHT) { return(sectorNo == TOP_RIGHT_SECTOR_ID || sectorNo == BOTTOM_RIGHT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.BOTTOM) { return(sectorNo == BOTTOM_LEFT_SECTOR_ID || sectorNo == BOTTOM_RIGHT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.TOP_LEFT) { return(sectorNo == TOP_LEFT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.TOP_RIGHT) { return(sectorNo == TOP_RIGHT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.BOTTOM_LEFT) { return(sectorNo == BOTTOM_LEFT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.BOTTOM_RIGHT) { return(sectorNo == BOTTOM_RIGHT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.TOP_LEFT_LEFT || entryPoint == CoastLinePropagationEnterExitPoint.TOP_LEFT_UP) { return(sectorNo == TOP_LEFT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.TOP_RIGHT_UP || entryPoint == CoastLinePropagationEnterExitPoint.TOP_RIGHT_RIGHT) { return(sectorNo == TOP_RIGHT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.BOTTOM_LEFT_LEFT || entryPoint == CoastLinePropagationEnterExitPoint.BOTTOM_LEFT_DOWN) { return(sectorNo == BOTTOM_LEFT_SECTOR_ID); } else if (entryPoint == CoastLinePropagationEnterExitPoint.BOTTOM_RIGHT_RIGHT || entryPoint == CoastLinePropagationEnterExitPoint.BOTTOM_RIGHT_DOWN) { return(sectorNo == BOTTOM_RIGHT_SECTOR_ID); } return(false); }
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++; } } } } } }
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; } } } } } }