public BuildingTownRoads(List <Town> townList, ShrunkNode[,] shrunkMap, List <ShrunkPlot> shrunkPlotList, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / townList.Count; loadingInfo.UpdateLoading(LoadingType.ExpandingTowns, percentDone); Point workingPoint; //'' for (int townSiteId = 0; townSiteId < townList.Count; townSiteId++) foreach (Town town in townList) { //set the Id here List <ConnectingPoint> connectingPointsList = new List <ConnectingPoint>(); numberOfRoads = GameController.rnd.Next(CreatingWorld.minTownRoads, CreatingWorld.maxTownRoads); workingPoint = town.GetShrunkPoint(); BuildTownCenterPoints(workingPoint, connectingPointsList, town.id, shrunkMap, shrunkPlotList); for (int p = 0; p < numberOfRoads; p++) { stopRoadCount = 4; if (connectingPointsList.Count > 0) { ConnectingPoint connectingPoint = connectingPointsList[0]; workingPoint = connectingPoint.connectingPoint; LayRoadStretch(workingPoint, connectingPoint.directionToTravel, connectingPoint.distanceToTravel, town.id, connectingPointsList, shrunkMap, shrunkPlotList); connectingPointsList.RemoveAt(0); } } percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.ExpandingTowns, percentDone); } }
public CreatingIntersections(Tile[,] tileGrid, ShrunkNode[,] shrunkMap, List <Intersection> intersectionList, LoadingInfo loadingInfo) { Random rnd = GameController.GetRandomWithSeed(); int id = 1; float percentDone = 0; float percentJump = 100f / CreatingWorld.worldWidth; for (int x = 0; x < ShrunkWorldBuilder.shrunkWorldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.AddingIntersections, percentDone); for (int y = 0; y < ShrunkWorldBuilder.shrunkWorldHeight; y++) { int amount = CountNeighbourRoadsShrunkMap(shrunkMap, new Point(x, y)); Point expanded = new Point(x * 2, y * 2); if (amount > 2 && rnd.Next(0, 100) < chanceToKeepThreeWay || amount > 3) { if (CountNeighbourRoadsNormalMap(tileGrid, expanded) > 2) { AddIntersection(intersectionList, tileGrid, shrunkMap, x, y, expanded, rnd, id); id++; } } else if (amount > 2) { if (CountNeighbourRoadsNormalMap(tileGrid, expanded) > 2) { AddTurningArrows(tileGrid, expanded, 1); } } } } }
//OKAY SO WE NOW HAVE //SOMETHING CALLED A MAP OBJECT //THIS MAP OBJECT WILL INCLUDE THE BUILDING //BECAUSE THIS MAP OBJECT CAN HAVE SOME UNIQUE INFORMATION IN IT //RATHER THAN THE SPECIFIC BUILDING public AddingTownBuildings(List <Building> buildingList, Tile[,] tileGrid, List <Town> townList, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / townList.Count; Random rnd = GameController.GetRandomWithSeed(); int failed = 1; foreach (Town town in townList) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.AddingTownBuildings, percentDone); foreach (Plot plot in town.plotList) { Building building = GetBuilding(buildingList, plot.roadFaceDirection, plot.width, plot.height, rnd); if (building != null) { AddBuildingToMap(GetTopLeft(building, plot), building, tileGrid, rnd); town.IncreaseBuildingCount(); } else { failed++; } } town.DestroyPlotList(); } }
public ExpandShrunkWorld(Tile[,] tileGrid, ShrunkNode[,] shrunkMap, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / ShrunkWorldBuilder.shrunkWorldWidth; for (int x = 0; x < ShrunkWorldBuilder.shrunkWorldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.ExpandingShrunkWorld, percentDone); for (int y = 0; y < ShrunkWorldBuilder.shrunkWorldHeight; y++) { for (int useX = (x * 2); useX < (x * 2) + 2; useX++) { for (int useY = (y * 2); useY < (y * 2) + 2; useY++) { LandType landType = shrunkMap[x, y].landType; if (landType == LandType.PLOT) { landType = LandType.OPEN; } tileGrid[useX, useY].SetTileLogistic(TileLogisticsController.GetTileLogistic(landType, 0)); } } } } }
private void UpdateCreatingLabel(LoadingInfo loadingInfo) { int total = cellsWidth * cellsHeight; int done = (updateCellY * cellsWidth) + updateCellX + 1; float percentDone = (float)done / (float)total * 100; loadingInfo.UpdateLoading(LoadingType.CreatingMiniMap, percentDone); }
public ExpandShrunkPlot(List <ShrunkPlot> shrunkPlotList, List <Town> townList, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / shrunkPlotList.Count; foreach (ShrunkPlot shrunkPlot in shrunkPlotList) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.ExpandingTowns, percentDone); int id = shrunkPlot.townId; townList[id].AddPlot(new Plot(shrunkPlot.pointOne, shrunkPlot.pointTwo, shrunkPlot.plotNum, shrunkPlot.roadFaceDirection)); } }
public TownSitesBuilder(ShrunkNode[,] shrunkMap, List <Town> townList, ref List <Point> connectionList, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / CreatingWorld.numberOfTowns; Random rnd = GameController.GetRandomWithSeed(); InitTownNames(); int numberOfChecks = 5000; bool safeDistance; distanceBetweenTowns = GetDistanceBetweenTowns(); int townId = 0; for (int i = 0; i < numberOfChecks; i++) { //TODO: take this next line out i just like this map for debugging //rndExtras = GameController.rnd; Point checkingPoint = new Point(rnd.Next(offSetFromEdge, ShrunkWorldBuilder.shrunkWorldWidth), rnd.Next(offSetFromEdge, ShrunkWorldBuilder.shrunkWorldHeight - offSetFromEdge)); safeDistance = false; if (ShrunkWorldBuilder.IsOpen(checkingPoint, shrunkMap)) { safeDistance = true; foreach (Town otherTown in townList) { if (IsToCloseDistance(checkingPoint, otherTown.GetShrunkPoint())) { safeDistance = false; break; } } } if (safeDistance) { townList.Add(new Town(checkingPoint, townId, GetTownName(rnd))); townId++; percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.PlottingTownPoints, percentDone); } if (townList.Count == CreatingWorld.numberOfTowns) { break; } } connectionList = CreateConnectionList(townList); }
public AddingRoadTiles(Tile[,] tileGrid, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / CreatingWorld.worldWidth; List <Point> pointsToUpdateList = new List <Point>(); for (int x = 0; x < CreatingWorld.worldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.AddingRoadTiles, percentDone); for (int y = 0; y < CreatingWorld.worldHeight; y++) { if (CheckRoad(x, y, 0, tileGrid)) { int bitCount = BitMaskValue(x, y, tileGrid); if (bitCount > -1) { Tile tile = tileGrid[x, y]; int index = BitMask.GetTileIndexFromBitmask(bitCount); if (index > -1 && index < 56) { if (tile.GetLandType() == LandType.CITYROAD) { tile.AddLayer(GroundLayerController.GetLayerByIndex(LayerType.CITYROAD, index)); tile.SetTileLogistic(TileLogisticsController.GetTileLogistic(LandType.CITYROAD, index)); } else if (tile.GetLandType() == LandType.COUNTRYROAD) { tile.AddLayer(GroundLayerController.GetLayerByIndex(LayerType.COUNTRYROAD, index)); tile.SetTileLogistic(TileLogisticsController.GetTileLogistic(LandType.COUNTRYROAD, index)); } } /*else if (index == 56) * { * pointsToUpdateList.Add(new Point(x, y)); * }*/ } } } } }
public LandMass(Tile[,] tileGrid, double[,] waterMap, LoadingInfo loadingInfo) { //following number is amount of ground layers groundLevels = new double[50]; float value = -5.5f; for (int i = 0; i < groundLevels.Length; i++) { groundLevels[i] = value; value += 0.20f; } float percentDone = 0; float percentJump = 100f / CreatingWorld.worldWidth; for (int x = 0; x < CreatingWorld.worldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.BuildingLandMass, percentDone); for (int y = 0; y < CreatingWorld.worldHeight; y++) { if (tileGrid[x, y] == null) { int layerIndex = GetLayerIndex(waterMap[x, y]); LayerType layerType = (LayerType)layerIndex; if (layerIndex > waterCoastline) { Tile tile = new Tile(GroundLayerController.GetRandomLayer(layerType), TileLogisticsController.GetTileLogistic(LandType.OPEN, 0), x, y); tileGrid[x, y] = tile; } else { Tile tile = new Tile(GroundLayerController.GetRandomLayer(layerType), TileLogisticsController.GetTileLogistic(LandType.WATER, 0), x, y); tileGrid[x, y] = tile; } if (x == 0 || x == CreatingWorld.worldWidth - 1 || y == 0 || y == CreatingWorld.worldHeight - 1) { Tile tile = new Tile(GroundLayerController.GetLayerByIndex(LayerType.BORDER, 0), TileLogisticsController.GetTileLogistic(LandType.BORDER, 0), x, y); tileGrid[x, y] = tile; } } } } }
private void ScanHorizontal(Tile[,] tileGrid, ShrunkNode[,] shrunkMap, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = (100f / CreatingWorld.worldWidth) / 2f; int skipper; bool lightNorth = true; int counter = 0; for (int y = 0; y < ShrunkWorldBuilder.shrunkWorldWidth; y++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.AddingStreetLights, percentDone); for (int x = 0; x < ShrunkWorldBuilder.shrunkWorldHeight; x++) { if (shrunkMap[x, y].IsRoad()) { counter++; skipper = CalculateSkip(shrunkMap, x, y); if (counter % skipper == 0 && !AnyRoadsUpOrDown(x, y, shrunkMap) && !AnyIntersectionsLeftOrRight(x, y, shrunkMap, distanceFromIntersection)) { lightNorth = !lightNorth; if (lightNorth) { AddLight(tileGrid, x * 2, y * 2, 1, skipper); } else { AddLight(tileGrid, x * 2, (y * 2) + 1, 3, skipper); } } } else { counter = 0; } } } }
public ConnectingTowns(ref List <Town> townList, ref List <Point> connectionList, ShrunkNode[,] shrunkMap, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / connectionList.Count; int townStartId; int targetid; Dictionary <int, Boolean> connectedList = new Dictionary <int, bool>(); for (int i = 0; i < townList.Count; i++) { if (i == 0) { connectedList.Add(i, false); } else { connectedList.Add(i, false); } } int numberofTowns = townList.Count; for (int i = 0; i < connectionList.Count; i++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.ConnectingTowns, percentDone); townStartId = connectionList[i].X; targetid = connectionList[i].Y; Point startPoint = townList[townStartId].GetShrunkPoint(); Point endPoint = townList[targetid].GetShrunkPoint(); List <Point> connectingPoints = new List <Point>(); AStarRoadBuildingNew aStar = new AStarRoadBuildingNew(); connectingPoints = aStar.GetTravelList(startPoint, endPoint, shrunkMap, targetid); UpdateShrunkMap(connectingPoints, townStartId, shrunkMap); } }
public double[,] GenerateNoiseMap(int octaves, float frequency, float amplitude, bool reseed, LoadingInfo loadingInfo, bool updateInfo, Random rnd, int width, int height) { float percentDone = 0; float percentJump = 100f / octaves / width; var data = new float[width * height]; double[,] tempArray = new double[width, height]; /// track min and max noise value. Used to normalize the result to the 0 to 1.0 range. var min = float.MaxValue; var max = float.MinValue; if (reseed) { Reseed(rnd); } //var persistence = 0.25f; i dont know what this does for (var octave = 0; octave < octaves; octave++) { for (var i = 0; i < width; i++) { percentDone += percentJump; if (updateInfo) { loadingInfo.UpdateLoading(LoadingType.CreatingPerlinNoise, percentDone); } for (var j = 0; j < height; j++) { var noise = Noise(i * frequency * 1f / width, j * frequency * 1f / height); noise = data[j * width + i] += noise * amplitude; tempArray[i, j] = noise; min = Math.Min(min, noise); max = Math.Max(max, noise); } } frequency *= 2; amplitude /= 2; } return(tempArray); }
public ClearingRoadErrors(ShrunkNode[,] shrunkMap, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / CreatingWorld.worldWidth; for (int x = 0; x < ShrunkWorldBuilder.shrunkWorldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.SmoothingTowns, percentDone); for (int y = 0; y < ShrunkWorldBuilder.shrunkWorldHeight; y++) { if (!IsAnyNeighbourRoads(new Point(x, y), shrunkMap) && shrunkMap[x, y].landType != LandType.PLOT) { if (ShrunkWorldBuilder.IsRoad(new Point(x, y), shrunkMap)) { shrunkMap[x, y].SetLandType(LandType.OPEN); } } } } }
//Instead of just having a level //make the level determine the chance of a tree landing there public AddingTrees(Tile[,] tileGrid, double[,] treeMap, LoadingInfo loadingInfo) { Random rnd = GameController.GetRandomWithSeed(); double treeLevel = 0; //-6 to positive 6 float percentDone = 0; float percentJump = 100f / CreatingWorld.worldWidth; for (int x = 0; x < CreatingWorld.worldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.AddingTrees, percentDone); for (int y = 0; y < CreatingWorld.worldHeight; y++) { //basically between 0 and 200 int i = (int)((treeMap[x, y] + 8)) * 10; if (rnd.Next(0, 200) < i) { if (treeMap[x, y] > treeLevel) { if (tileGrid[x, y].GetChildObject() == null && tileGrid[x, y].GetLandType() == Game.LandType.OPEN) { float p = (float)(rnd.Next(500, 800)) / 1000f; int type = rnd.Next(0, 8); Tree tree = MapObjectController.GetTree(type); MapObject mapObject = new MapObject(tree, x, y, Color.White, p); TileLogistic tileLogistic = TileLogisticsController.GetTileLogistic(LandType.TREE, 0); tileGrid[x, y].AddMapObject(mapObject, false, false, true, tileLogistic, true); } } } } } }
public ModifyingIntersectionRoadId(Tile[,] tileGrid, ShrunkNode[,] shrunkMap, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / CreatingWorld.worldWidth; for (int x = 0; x < ShrunkWorldBuilder.shrunkWorldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.FixingIntersections, percentDone); for (int y = 0; y < ShrunkWorldBuilder.shrunkWorldHeight; y++) { int amount = CountNeighbourRoadsShrunkMap(shrunkMap, new Point(x, y)); Point expanded = new Point(x * 2, y * 2); if (amount > 2) { FixSpot(expanded, tileGrid); } } } }
public ShrunkWorldBuilder(Tile[,] tileGrid, ShrunkNode[,] shrunkMap, LoadingInfo loadingInfo) { float percentDone = 0; float percentJump = 100f / CreatingWorld.worldWidth; for (int x = 0; x < shrunkWorldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.BuildingShrunkWorld, percentDone); for (int y = 0; y < shrunkWorldHeight; y++) { LandType landType = LandType.OPEN; for (int checkX = (x * 2); checkX < (x * 2) + 2; checkX++) { for (int checkY = (y * 2); checkY < (y * 2) + 2; checkY++) { if (tileGrid[checkX, checkY].GetLandType() == LandType.WATER) { landType = LandType.WATER; break; } if (tileGrid[checkX, checkY].GetLandType() == LandType.BORDER) { landType = LandType.BORDER; break; } } if (landType == LandType.WATER) { break; } } shrunkMap[x, y] = new ShrunkNode(landType); } } }
public LandSmoothing(Tile[,] tileGrid, LoadingInfo loadingInfo) { int nX; int nY; int numberOfLayers = Enum.GetNames(typeof(LayerType)).Length; float percentDone = 0; float percentJump = 100f / (numberOfLayers * CreatingWorld.worldWidth); //loadingInfo.UpdateLoading(LoadingType.BuildingLandMass, percentDone); for (int cLayer = numberOfLayers; cLayer > -1; cLayer--) { for (int x = 0; x < CreatingWorld.worldWidth; x++) { percentDone += percentJump; loadingInfo.UpdateLoading(LoadingType.SmoothingLandMass, percentDone); for (int y = 0; y < CreatingWorld.worldHeight; y++) { if (cLayer == tileGrid[x, y].GetBaseSmoothingLayer()) { //Straight edges first for (int xScan = -1; xScan < 2; xScan++) { for (int yScan = -1; yScan < 2; yScan++) { nX = xScan + x; nY = yScan + y; if (xScan + yScan == 1 || xScan + yScan == -1) { if (NextTileAdd(nX, nY, cLayer, out Tile tile, tileGrid)) { AddLayer(nX, nY, tileGrid[x, y].GetBaseLayerType(), BitMaskValue(x, y, nX, nY), tileGrid); } } } } //Corner edges second. We only add the corner edges if there is no corresponding straight edge if (CheckForCorners(tileGrid, x, y)) //We only add corners to the water tiles { for (int xScan = -1; xScan < 2; xScan++) { for (int yScan = -1; yScan < 2; yScan++) { nX = xScan + x; nY = yScan + y; if (xScan != 0 && yScan != 0) { if (NextTileAdd(nX, nY, cLayer, out Tile tile, tileGrid)) { AddLayerCorner(nX, nY, tileGrid[x, y].GetBaseLayerType(), BitMaskValue(x, y, nX, nY), tileGrid); } } } } } } } } } }