private void DecodeMap(StreamReader file) { var line = file.ReadLine(); var temp = line.Split(','); // need to assert if not equal to two cells _terrainMap.Width = int.Parse(temp[0]); _terrainMap.Height = int.Parse(temp[1]); // read the map for (var y = 0; y < _terrainMap.Height; y++) { line = file.ReadLine(); var tempRow = line.Split(','); for (var x = 0; x < tempRow.Length; x++) { var cube = HexGridMath.OffsetToCube(x, y); _terrainMap[x, y] = new TerrainCell(cube.X, cube.Y, cube.Z, TerrainDecode(tempRow[x].Trim())); } } }
public void PlotRoad(int startCol, int startRow, int destCol, int destRow) { // find shortest path _shortestPath.ComputeShortestPath(this, startCol, startRow, destCol, destRow, -1); // add the starting cell to the path _shortestPath.WayPoint.Insert(0, new Offset(startCol, startRow)); TerrainCell prevTerrain = null; Cube prevTerrainCube = null; foreach (var wayPointOffset in _shortestPath.WayPoint) { var terrainCube = HexGridMath.OffsetToCube(wayPointOffset.Col, wayPointOffset.Row); var terrain = (TerrainCell)Map[FindMapHash(terrainCube.X, terrainCube.Y, terrainCube.Z)]; // figure out which sides of the cell are touching if (prevTerrain != null) { if (prevTerrainCube.Y == terrainCube.Y) // lower left to upper right { if (terrainCube.X > prevTerrainCube.X) { if (prevTerrain.BackgroundType != 40) { prevTerrain.Roads |= RoadType.Road3; } if (terrain.BackgroundType != 40) { terrain.Roads |= RoadType.Road6; } } else { if (prevTerrain.BackgroundType != 40) { prevTerrain.Roads |= RoadType.Road6; } if (terrain.BackgroundType != 40) { terrain.Roads |= RoadType.Road3; } } } else if (prevTerrainCube.Z == terrainCube.Z) // upper left to lower right { if (terrainCube.Y > prevTerrainCube.Y) { if (prevTerrain.BackgroundType != 40) { prevTerrain.Roads |= RoadType.Road5; } if (terrain.BackgroundType != 40) { terrain.Roads |= RoadType.Road2; } } else { if (prevTerrain.BackgroundType != 40) { prevTerrain.Roads |= RoadType.Road2; } if (terrain.BackgroundType != 40) { terrain.Roads |= RoadType.Road5; } } } else if (prevTerrainCube.X == terrainCube.X) // vertical line { if (terrainCube.Y > prevTerrainCube.Y) { if (prevTerrain.BackgroundType != 40) { prevTerrain.Roads |= RoadType.Road4; } if (terrain.BackgroundType != 40) { terrain.Roads |= RoadType.Road1; } } else { if (prevTerrain.BackgroundType != 40) { prevTerrain.Roads |= RoadType.Road1; } if (terrain.BackgroundType != 40) { terrain.Roads |= RoadType.Road4; } } } else { // should never get here System.Diagnostics.Debug.Assert(false); } } prevTerrain = terrain; prevTerrainCube = terrainCube; } }