public HexCell this[int x, int y] { get { //return WorldMap[y + Radius, x + Radius + Mathf.Min(0, y)]; Coords c = new Coords(x, y); if (WorldMap.ContainsKey(c)) { return(WorldMap[c]); } //Debug.LogWarning("Map::this[int x, int y] - No HexCell in Map for these coords: " + c.ToString()); return(null); } set { //WorldMap[y + Radius, x + Radius + Mathf.Min(0, y)] = value; Coords c = new Coords(x, y); if (WorldMap.ContainsKey(c)) { WorldMap[c] = value; } else { WorldMap.Add(c, value); } } }
/// <summary> /// Generates A ring of new HexCells in a certain distance, and places them in the map. /// </summary> /// <param name="distanceOfRingFromCenter">The distance of the ring from the center</param> void GenerateRing(int distanceOfRingFromCenter) { Coords coord = new Coords(-distanceOfRingFromCenter, 0); //walk a long a ring with radius i for (int j = 0; j < 6; j++) { for (int k = 0; k < distanceOfRingFromCenter; k++) { //this[coord] = new HexCell(coord); //Debug.Log(coord.ToString() + " Has hash: " + coord.GetHashCode()); WorldMap.Add(coord, new HexCell(coord)); //HandleAreaForCell(this[coord]); coord = Coords.GetNeighborCoords(coord, (HexDirection)j); } } }
/// <summary> /// Generates the map, and areas as well as the texture for the center cell and maybe it sourounding /// cells /// </summary> void Generate() { Debug.LogWarning("WARNING: Not(?) Finsihed IMPLEMENTING SUBJECT TO CHANGE"); //Area centerArea = new Area(0, rng.Next(1, 4)); HexCell center = new HexCell(0, 0); //Debug.Log(center.Coords.ToString() + " Has hash: " + center.Coords.GetHashCode()); WorldMap.Add(center.Coords, center); //set center in world map this[center.Coords] = center; for (int i = 1; i <= Radius; i++) { GenerateRing(i); } GenerateAreas((area) => { return(HexCell.DistanceBetweenCells(area.Cells[0], this[0, 0])); }); GenerateBiomes(); }
public HexCell this[Coords coord] { get { if (WorldMap.ContainsKey(coord)) { return(WorldMap[coord]); } //Debug.LogWarning("Map::this[Coords coord] - No HexCell in Map for these coords: " + coord.ToString()); return(null); } set { if (WorldMap.ContainsKey(coord)) { WorldMap[coord] = value; } else { WorldMap.Add(coord, value); } } }