static void SetRoadsWithCrossingsAroundCrossroads(CityBlock cityBlock) { for (int x = 0; x < cityBlock.size.x; x++) { for (int y = 0; y < cityBlock.size.y; y++) { var road = cityBlock.GetRoadTile(x, y); if (road == RoadPiece.CROSS_N) { cityBlock.SetRoadTile(x, y + 1, RoadPiece.VERTICAL_WITH_CROSSING); } else if (road == RoadPiece.CROSS_S) { cityBlock.SetRoadTile(x, y - 1, RoadPiece.VERTICAL_WITH_CROSSING); } else if (road == RoadPiece.CROSS_E) { cityBlock.SetRoadTile(x + 1, y, RoadPiece.HORIZONTAL_WITH_CROSSING); } else if (road == RoadPiece.CROSS_W) { cityBlock.SetRoadTile(x - 1, y, RoadPiece.HORIZONTAL_WITH_CROSSING); } } } }
static void SetCrossroadBorders(CityBlock cityBlock) { for (int x = 0; x < cityBlock.size.x; x++) { for (int y = 0; y < cityBlock.size.y; y++) { if (cityBlock.GetRoadTile(x, y) == RoadPiece.CROSS_CENTER) { cityBlock.SetRoadTile(x - 1, y - 1, RoadPiece.CROSS_SW); cityBlock.SetRoadTile(x - 1, y, RoadPiece.CROSS_W); cityBlock.SetRoadTile(x - 1, y + 1, RoadPiece.CROSS_NW); cityBlock.SetRoadTile(x, y + 1, RoadPiece.CROSS_N); cityBlock.SetRoadTile(x + 1, y + 1, RoadPiece.CROSS_NE); cityBlock.SetRoadTile(x + 1, y, RoadPiece.CROSS_E); cityBlock.SetRoadTile(x + 1, y - 1, RoadPiece.CROSS_SE); cityBlock.SetRoadTile(x, y - 1, RoadPiece.CROSS_S); } } } }
static CityBlock GenerateGridLayout(CityBlockSettings settings) { var cityBlock = new CityBlock(settings); // add horizontal roads for (int y = 1; y < cityBlock.size.y - 1; y += settings.gap) { for (int x = 1; x < cityBlock.size.x - 1; x++) { cityBlock.SetRoadTile(x, y, RoadPiece.HORIZONTAL); } } // add vertical roads for (int x = 1; x < cityBlock.size.x - 1; x += settings.gap) { for (int y = 1; y < cityBlock.size.y - 1; y++) { if (cityBlock.GetRoadTile(x, y) != RoadPiece.NONE) { cityBlock.SetRoadTile(x, y, RoadPiece.CROSS_CENTER); } else { cityBlock.SetRoadTile(x, y, RoadPiece.VERTICAL); } } } // ground level SetCrossroadBorders(cityBlock); SetPavementWrappedWithRoad(cityBlock); // buildings SetBuildingsOnPavement(cityBlock); // world border SetBorder(cityBlock); // features SetCornerLamps(cityBlock); SetRoadsWithCrossingsAroundCrossroads(cityBlock); return(cityBlock); }
static CityBlock GenerateManualLayout() { int _ = 0; int H = 1; int V = 2; int C = 3; int[,] cityLayout = { { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, }, { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, }, }; // create the city block var settings = new CityBlockSettings(); settings.width = cityLayout.GetLength(1); settings.height = cityLayout.GetLength(0); var cityBlock = new CityBlock(settings); // create road from layout for (int x = 0; x < settings.width; x++) { for (int y = 0; y < settings.height; y++) { var tile = cityLayout[y, x]; if (tile == H) { cityBlock.SetRoadTile(x, y, RoadPiece.HORIZONTAL); } else if (tile == V) { cityBlock.SetRoadTile(x, y, RoadPiece.VERTICAL); } else if (tile == C) { cityBlock.SetRoadTile(x, y, RoadPiece.CROSS_CENTER); } } } // ground level SetCrossroadBorders(cityBlock); SetPavementWrappedWithRoad(cityBlock); // buildings // SetBuildingsOnPavement(cityBlock); // world border SetBorder(cityBlock); // features // SetCornerLamps(cityBlock); // SetRoadsWithCrossingsAroundCrossroads(cityBlock); return(cityBlock); }