public P_CubeCoords IndexToCube(int index)
        {
            int XOffset = index % _Width;

            int          Z          = (index - XOffset) / _Width; // Y
            int          Y          = XOffset - (Z - (Z & 1)) / 2;
            int          X          = -Y - Z;
            P_CubeCoords returnthis = new P_CubeCoords(X, Y, Z);

            return(returnthis);
        }
        public bool IsVisable(P_CubeCoords HexA, P_CubeCoords HexB)
        {
            List <P_CubeCoords> coords = P_CubeCoords.cube_linedraw(HexA, HexB);

            for (int i = 0; i < coords.Count; i++)
            {
                if (_MyTiles[CubeToIndex(coords[i])].Role == TileRole.Void)
                {
                    return(false);
                }
            }

            return(true);
        }
        public List <Tile> TileNeighbors(int tileindex)
        {
            P_CubeCoords tilehex   = this.IndexToCube(tileindex);
            List <Tile>  neighbors = new List <Tile>();

            if (!this.IsLeftRow(tileindex))
            {
                if (validindex(this.CubeToIndex(tilehex.Left)))
                {
                    neighbors.Add(this.MyTiles[this.CubeToIndex(tilehex.Left)]);
                }
                if (!this.IsTopRow(tileindex))
                {
                    if (validindex(this.CubeToIndex(tilehex.UpLeft)))
                    {
                        neighbors.Add(this.MyTiles[this.CubeToIndex(tilehex.UpLeft)]);
                    }
                }
                if (!this.IsBottomRow(tileindex))
                {
                    if (validindex(this.CubeToIndex(tilehex.DownLeft)))
                    {
                        neighbors.Add(this.MyTiles[this.CubeToIndex(tilehex.DownLeft)]);
                    }
                }
            }
            if (!this.IsRightRow(tileindex))
            {
                if (validindex(this.CubeToIndex(tilehex.Right)))
                {
                    neighbors.Add(this.MyTiles[this.CubeToIndex(tilehex.Right)]);
                }
                if (!this.IsTopRow(tileindex))
                {
                    if (validindex(this.CubeToIndex(tilehex.UpRight)))
                    {
                        neighbors.Add(this.MyTiles[this.CubeToIndex(tilehex.UpRight)]);
                    }
                }
                if (!this.IsBottomRow(tileindex))
                {
                    if (validindex(this.CubeToIndex(tilehex.DownRight)))
                    {
                        neighbors.Add(this.MyTiles[this.CubeToIndex(tilehex.DownRight)]);
                    }
                }
            }
            return(neighbors);
        }
        public List <P_CubeCoords> CubeCoordNeighbors(P_CubeCoords tilehex)
        {
            int tileindex = this.CubeToIndex(tilehex);
            List <P_CubeCoords> neighbors = new List <P_CubeCoords>();

            if (!this.IsLeftRow(tileindex))
            {
                if (validindex(this.CubeToIndex(tilehex.Left)))
                {
                    neighbors.Add(tilehex.Left);
                }
                if (!this.IsTopRow(tileindex))
                {
                    if (validindex(this.CubeToIndex(tilehex.UpLeft)))
                    {
                        neighbors.Add(tilehex.UpLeft);
                    }
                }
                if (!this.IsBottomRow(tileindex))
                {
                    if (validindex(this.CubeToIndex(tilehex.DownLeft)))
                    {
                        neighbors.Add(tilehex.DownLeft);
                    }
                }
            }
            if (!this.IsRightRow(tileindex))
            {
                if (validindex(this.CubeToIndex(tilehex.Right)))
                {
                    neighbors.Add(tilehex.Right);
                }
                if (!this.IsTopRow(tileindex))
                {
                    if (validindex(this.CubeToIndex(tilehex.UpRight)))
                    {
                        neighbors.Add(tilehex.UpRight);
                    }
                }
                if (!this.IsBottomRow(tileindex))
                {
                    if (validindex(this.CubeToIndex(tilehex.DownRight)))
                    {
                        neighbors.Add(tilehex.DownRight);
                    }
                }
            }
            return(neighbors);
        }
Ejemplo n.º 5
0
        public static List <P_CubeCoords> cube_linedraw(P_CubeCoords a, P_CubeCoords b)
        {
            double N = cube_distance(a, b);

            List <P_CubeCoords> results = new List <P_CubeCoords>();

            if (N == 0)
            {
                return(results);
            }

            for (int i = 0; i <= N; i++)
            {
                results.Add(cube_lerp(a, b, 1.0 / N * i));
            }
            return(results);
        }
Ejemplo n.º 6
0
        public static P_CubeCoords StepForward(P_CubeCoords point, TileNeighborEnum direction)
        {
            switch (direction)
            {
            case TileNeighborEnum.DownLeft:
                return(point.DownLeft);

            case TileNeighborEnum.DownRight:
                return(point.DownRight);

            case TileNeighborEnum.Right:
                return(point.Right);

            case TileNeighborEnum.UpRight:
                return(point.UpRight);

            case TileNeighborEnum.UpLeft:
                return(point.UpLeft);

            case TileNeighborEnum.Left:
                return(point.Left);
            }
            throw new Exception("What THE F**K did you just say to me????");
        }
        public int CubeToIndex(P_CubeCoords cube)
        {
            int returnme = ((cube.Z * _Width) + (cube.Y + (cube.Z - (cube.Z & 1)) / 2));

            return(returnme);
        }
 public Tile GetTile(P_CubeCoords cube)
 {
     return(_MyTiles[CubeToIndex(cube)]);
 }
Ejemplo n.º 9
0
 public static double cube_distance(P_CubeCoords a, P_CubeCoords b)
 {
     return((Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y) + Math.Abs(a.Z - b.Z)) / 2);
 }
Ejemplo n.º 10
0
 public static P_CubeCoords cube_lerp(P_CubeCoords a, P_CubeCoords b, double t)
 {
     return(RoundedCubes(lerp(a.X, b.X, t),
                         lerp(a.Y, b.Y, t),
                         lerp(a.Z, b.Z, t)));
 }
Ejemplo n.º 11
0
        public static List <P_CubeCoords> GetPath(P_TileArray tilearray, P_CubeCoords start, P_CubeCoords end)
        {
            List <P_CubeCoords> ReturnValue = new List <P_CubeCoords>();

            List <HexNode> closedset = new List <HexNode>();
            List <HexNode> openset   = new List <HexNode>();

            HexNode thing = new HexNode(start, end, null);

            thing.H = P_CubeCoords.cube_distance(start, end);
            openset.Add(thing);

            while (openset.Count > 0)
            {
                HexNode current = openset[0];
                for (int i = 1; i < openset.Count; i++)
                {
                    if (openset[i].Score < current.Score)
                    {
                        current = openset[i];
                    }
                }

                if (current.Coords.X == end.X && current.Coords.Y == end.Y && current.Coords.Z == end.Z)
                {
                    return(RebuildPath(current));
                }

                openset.Remove(current);
                closedset.Add(current);

                List <P_CubeCoords> neighbors = tilearray.CubeCoordNeighbors(current.Coords);
                for (int i = 0; i < neighbors.Count; i++)
                {
                    if (tilearray.MyTiles[tilearray.CubeToIndex(neighbors[i])].IsTilePassable() == false)
                    {
                        continue;
                    }
                    bool found = false;
                    for (int j = 0; j < closedset.Count; j++)
                    {
                        if (closedset[j].Coords.X == neighbors[i].X &&
                            closedset[j].Coords.Y == neighbors[i].Y &&
                            closedset[j].Coords.Z == neighbors[i].Z)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                    for (int j = 0; j < openset.Count; j++)
                    {
                        if (openset[j].Coords.X == neighbors[i].X &&
                            openset[j].Coords.Y == neighbors[i].Y &&
                            openset[j].Coords.Z == neighbors[i].Z)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }

                    HexNode NewNode = new HexNode(neighbors[i], end, current);
                    openset.Add(NewNode);
                }
            }
            return(ReturnValue);
        }
Ejemplo n.º 12
0
 public HexNode(TilerIsADummy.PrototypeMapGen.P_CubeCoords location, TilerIsADummy.PrototypeMapGen.P_CubeCoords goal, HexNode parent = null)
 {
     _H      = TilerIsADummy.PrototypeMapGen.P_CubeCoords.cube_distance(location, goal);
     _Parent = parent;
     _Coords = location;
 }