예제 #1
0
        public int GetRoadTileIndex(int i, int j)
        {
            if (!this[i,j].Improvements.Contains(road))
                return -1;

            int index = 0, c = 1;
            var loc = new HexPoint(i, j);

            foreach (HexDirection dir in HexDirection.All)
            {
                HexPoint pt = loc.Neighbor(dir);
                if (IsValid(pt))
                {
                    if (this[pt].Improvements.Contains(road))
                        index += c;
                }

                c *= 2;
            }

            return index;
        }
예제 #2
0
        public int GetBorderTileIndex(int i, int j)
        {
            int currentController = this[i,j].ControlledBy;

            if (currentController == -1)
                return 0;

            int index = 0, c = 1;
            var loc = new HexPoint(i, j);
            
            foreach (HexDirection dir in HexDirection.All)
            {
                HexPoint pt = loc.Neighbor(dir);
                if (IsValid(pt))
                {
                    if ((this[pt].ControlledBy != currentController)) 
                        index += c;
                }

                c *= 2;
            }

            return index;
        }
예제 #3
0
        public River GetRiverAt(HexPoint point)
        {
            if (!IsValid(point))
                return null;

            if( this[point].IsRiver)
                return Rivers.FirstOrDefault(river => river.Points.Select( a => a.Point ).Contains(point));

            HexPoint neighbor = point.Neighbor(HexDirection.NorthEast);
            if (IsValid(neighbor) && this[neighbor].IsNEOfRiver)
                return Rivers.FirstOrDefault(river => river.Points.Select(a => a.Point).Contains(neighbor));

            neighbor = point.Neighbor(HexDirection.West);
            if (IsValid(neighbor) && this[neighbor].IsWOfRiver)
                return Rivers.FirstOrDefault(river => river.Points.Select(a => a.Point).Contains(neighbor));

            neighbor = point.Neighbor(HexDirection.NorthWest);
            if (IsValid(neighbor) && this[neighbor].IsNWOfRiver)
                return Rivers.FirstOrDefault(river => river.Points.Select(a => a.Point).Contains(neighbor));

            return null;
        }
예제 #4
0
        public int GetCoastalTileIndex(int i, int j)
        {
            // return rnd.Next(32);

            int index = 0, c = 1;
            var loc = new HexPoint(i, j);

            foreach (HexDirection dir in HexDirection.All /*.Shift(6)*/)
            {
                HexPoint pt = loc.Neighbor(dir);
                if (IsValid(pt))
                {
                    if ((this[pt].IsLand)) // may coast should be removed
                        index += c;
                }

                c *= 2;
            }

            return index;
        }
예제 #5
0
        private float GetHeightAtCorner(int x, int y, HexCorner corner)
        {
            HexPoint pt = new HexPoint(x, y);

            switch (corner)
            {
                case HexCorner.SouthEast:
                    {
                        HexPoint se = pt.Neighbor(HexDirection.SouthEast);
                        HexPoint ea = pt.Neighbor(HexDirection.East);

                        if (IsValid(se) && IsValid(ea))
                            return (this[se].Height + this[ea].Height + Height) / 3.0f;

                        if (IsValid(se))
                            return (this[se].Height + Height) / 2.0f;

                        if (IsValid(ea))
                            return (this[ea].Height + Height) / 2.0f;

                        return Height;
                    }
                case HexCorner.NorthEast:
                    {
                        HexPoint ne = pt.Neighbor(HexDirection.NorthEast);
                        HexPoint ea = pt.Neighbor(HexDirection.East);

                        if (IsValid(ne) && IsValid(ea))
                            return (this[ne].Height + this[ea].Height + Height) / 3.0f;

                        if (IsValid(ne))
                            return (this[ne].Height + Height) / 2.0f;

                        if (IsValid(ea))
                            return (this[ea].Height + Height) / 2.0f;

                        return Height;
                    }
                case HexCorner.North:
                    {
                        HexPoint ne = pt.Neighbor(HexDirection.NorthEast);
                        HexPoint nw = pt.Neighbor(HexDirection.NorthWest);

                        if (IsValid(ne) && IsValid(nw))
                            return (this[ne].Height + this[nw].Height + Height) / 3.0f;

                        if (IsValid(ne))
                            return (this[ne].Height + Height) / 2.0f;

                        if (IsValid(nw))
                            return (this[nw].Height + Height) / 2.0f;

                        return Height;
                    }
                case HexCorner.SouthWest:
                    {
                        HexPoint sw = pt.Neighbor(HexDirection.SouthWest);
                        HexPoint we = pt.Neighbor(HexDirection.West);

                        if (IsValid(sw) && IsValid(we))
                            return (this[sw].Height + this[we].Height + Height) / 3.0f;

                        if (IsValid(sw))
                            return (this[sw].Height + Height) / 2.0f;

                        if (IsValid(we))
                            return (this[we].Height + Height) / 2.0f;

                        return Height;
                    }
                case HexCorner.NorthWest:
                    {
                        HexPoint nw = pt.Neighbor(HexDirection.NorthWest);
                        HexPoint we = pt.Neighbor(HexDirection.West);

                        if (IsValid(nw) && IsValid(we))
                            return (this[nw].Height + this[we].Height + Height) / 3.0f;

                        if (IsValid(nw))
                            return (this[nw].Height + Height) / 2.0f;

                        if (IsValid(we))
                            return (this[we].Height + Height) / 2.0f;

                        return Height;
                    }
                case HexCorner.South:
                    {
                        HexPoint se = pt.Neighbor(HexDirection.SouthEast);
                        HexPoint sw = pt.Neighbor(HexDirection.SouthWest);

                        if (IsValid(se) && IsValid(sw))
                            return (this[se].Height + this[sw].Height + Height) / 3.0f;

                        if (IsValid(se))
                            return (this[se].Height + Height) / 2.0f;

                        if (IsValid(sw))
                            return (this[sw].Height + Height) / 2.0f;

                        return Height;
                    }
            }

            return 0f;
        }