示例#1
0
        internal IEnumerable <Hex> GetNeighbours(int x, int y, bool passable = true)
        {
            var tile = tiles.Find(t => (t.X == x) && (t.Y == y));

            if (tile == null)
            {
                return(null);
            }

            List <Hex> neighbours = new List <Hex>();

            foreach (var direction in directions)
            {
                int dirX      = direction.Value.X;
                int dirY      = direction.Value.Y;
                var neighbour = tiles.Find(n => (n.X == tile.X + dirX) && (n.Y == tile.Y + dirY));
                if (neighbour == null)
                {
                    double[] coords     = GeoUtils.GetLatitudeLongitude(tile.Latitude, tile.Longitude, tile.Bearing + direction.Key, StepSize, mainBody.Radius);
                    double   newBearing = GeoUtils.FinalBearing(tile.Latitude, tile.Longitude, coords[0], coords[1]);
                    newBearing = (newBearing - direction.Key + 360) % 360;
                    double altitude = GeoUtils.TerrainHeightAt(coords[0], coords[1], mainBody);
                    neighbour = new Hex(coords[0], coords[1], altitude, newBearing, tile.X + dirX, tile.Y + dirY, this);
                }
                neighbours.Add(neighbour);
                tiles.Add(neighbour);
            }
            if (passable)
            {
                switch (tileTypes)
                {
                case TileTypes.Land | TileTypes.Ocean:
                    return(neighbours.Where(
                               n =>
                               ((n.Altitude - tile.Altitude) < StepSize / 2) &&
                               ((n.Altitude - tile.Altitude) > 0 - StepSize / 2)
                               ));

                case TileTypes.Land:
                    return(neighbours.Where(
                               n => (n.Altitude >= 0 || !mainBody.ocean) &&
                               ((n.Altitude - tile.Altitude) < StepSize / 2) &&
                               ((n.Altitude - tile.Altitude) > 0 - StepSize / 2)
                               ));

                case TileTypes.Ocean:
                    return(neighbours.Where(
                               n => (n.Altitude <= 0)
                               ));

                default:
                    return(neighbours);
                }
            }
            else
            {
                return(neighbours);
            }
        }
示例#2
0
        internal IEnumerable <Hex> GetNeighbours(int x, int y, bool passable = true)
        {
            //			Debug.Log (String.Format("bonvoyage - finding neighbours for {0}, {1}", x, y));
            var tile = tiles.Find(t => (t.X == x) && (t.Y == y));

            if (tile == null)
            {
                //				Debug.Log ("bonvoyage - tile not found");
                return(null);
            }
            List <Hex> neighbours = new List <Hex> ();

            foreach (var direction in directions)
            {
                int dirX      = direction.Value.X;
                int dirY      = direction.Value.Y;
                var neighbour = tiles.Find(n => (n.X == tile.X + dirX) && (n.Y == tile.Y + dirY));
                if (neighbour == null)
                {
                    //					Debug.Log ("bonvoyage - neighbour not found");
                    double[] coords     = GeoUtils.GetLatitudeLongitude(tile.Latitude, tile.Longitude, tile.Bearing + direction.Key, StepSize, mainBody.Radius);
                    double   newBearing = GeoUtils.FinalBearing(tile.Latitude, tile.Longitude, coords [0], coords [1]);
                    newBearing = (newBearing - direction.Key + 360) % 360;
                    double altitude = GeoUtils.TerrainHeightAt(coords [0], coords [1], mainBody);
                    neighbour = new Hex(coords [0], coords [1], altitude, newBearing, tile.X + dirX, tile.Y + dirY, this);
                }
                neighbours.Add(neighbour);
                tiles.Add(neighbour);
            }
            if (passable)
            {
                return(neighbours.Where(
                           n => (n.Altitude >= 0 || !mainBody.ocean) &&
                           ((n.Altitude - tile.Altitude) < StepSize / 2) &&
                           ((n.Altitude - tile.Altitude) > 0 - StepSize / 2)
                           ));
            }
            else
            {
                return(neighbours);
            }
        }