/// <summary>Calculate Field-of-View from a specified TargetMode, assuming a flat earth.</summary>
 /// <param name="board">A reference to an IFovBoard {IHex} instance.</param>
 /// <param name="coordsObserver">Cordinates of observer;s hex.</param>
 /// <param name="fovRadius">Radius of Field-of-view desired.</param>
 /// <param name="targetMode">TargetMode value for determining target visibility.</param>
 /// <param name="setFieldOfView">Sets a hex as visible in the Field-of-View.</param>
 public static void ComputeFieldOfView(
     IFovBoard board,
     HexCoords coordsObserver,
     int fovRadius,
     FovTargetMode targetMode,
     Action <HexCoords> setFieldOfView
     )
 => ComputeFieldOfView(board, coordsObserver, fovRadius, targetMode, setFieldOfView, 1, 0);
 /// <summary>Calculate Field-of-View from a specified TargetMode, assuming a flat earth.</summary>
 /// <param name="coordsObserver">Cordinates of observer;s hex.</param>
 /// <param name="board">A reference to an IFovBoard {IHex} instance.</param>
 /// <param name="targetMode">TargetMode value for determining target visibility.</param>
 /// <param name="setFieldOfView">Sets a hex as visible in the Field-of-View.</param>
 public static void ComputeFieldOfView(
     HexCoords coordsObserver,
     IFovBoard <IHex> board,
     FovTargetMode targetMode,
     Action <HexCoords> setFieldOfView
     )
 {
     ComputeFieldOfView(coordsObserver, board, targetMode, setFieldOfView, 1, 0);
 }
        /// <summary>Calculate Field-of-View from a specified TargetMode, assuming a spherical earth
        /// and height measured in feet if <code>hexesPerMile</code> is not equal 0.</summary>
        /// <param name="board">A reference to an IFovBoard {IHex} instance.</param>
        /// <param name="coordsObserver">Cordinates of observer;s hex.</param>
        /// <param name="fovRadius">Radius of Field-of-view desired.</param>
        /// <param name="targetMode">TargetMode value for determining target visibility.</param>
        /// <param name="setFieldOfView">Sets a hex as visible in the Field-of-View.</param>
        /// <param name="defaultHeight">Height used for observer and target when targetMode = EqualHeights/</param>
        /// <param name="hexesPerMile">Number of hexes per mile (ie 1/4000 of planet radius).</param>
        /// <remarks>Adjusts visibility for curvature of the Earth. This is the only version of
        /// ComputeFieldOfView that is <b>not</b> scale invariant for height, and assumes that height
        /// is measured in feet.
        /// </remarks>
        /// <a href="http://mathcentral.uregina.ca/qq/database/QQ.09.02/shirley3.html">Hidden by the Curvature of the Earth</a>
        public static void ComputeFieldOfView(
            IFovBoard board,
            HexCoords coordsObserver,
            int fovRadius,
            FovTargetMode targetMode,
            Action <HexCoords> setFieldOfView,
            int defaultHeight,
            int hexesPerMile
            )
        {
            if (fovRadius > int.MinValue)
            {
                fovRadius = fovRadius - 1;
            }
            int CalculationHeightUnits = UseMetric ?   5  // convert metres to  cm  for greater precision
                                                   :  12; // convert feet to inches for greater precision

            Func <HexCoords, int> elevationTarget;
            int elevationObserver;

            switch (targetMode)
            {
            case FovTargetMode.TargetHeightEqualZero:
                elevationTarget   = coords => board.ElevationGroundASL(coords);
                elevationObserver = board.ElevationObserverASL(coordsObserver);
                break;

            default:
            case FovTargetMode.TargetHeightEqualActual:
                elevationTarget   = coords => board.ElevationTargetASL(coords);
                elevationObserver = board.ElevationObserverASL(coordsObserver);
                break;

            case FovTargetMode.EqualHeights:
                elevationTarget   = coords => board.ElevationGroundASL(coords) + defaultHeight;
                elevationObserver = elevationTarget(coordsObserver);
                break;
            }

            var deltaHeight = GetDeltaHeight(coordsObserver, hexesPerMile, CalculationHeightUnits);

            ComputeFieldOfView(
                coordsObserver,
                fovRadius,
                elevationObserver * CalculationHeightUnits,
                hc => board.MapSizeHexes.IsOnboard(hc),
                coords => elevationTarget(coords) * CalculationHeightUnits - deltaHeight(coords),
                (coords, hexside) => board.ElevationHexsideASL(coords, hexside) * CalculationHeightUnits - deltaHeight(coords),
                setFieldOfView
                );
        }
Exemple #4
0
        /// <summary>Gets a Field-of-View for this board synchronously.</summary>
        public static IShadingMask GetFieldOfView(this IFovBoard @this, HexCoords origin,
                                                  int fovRadius, FovTargetMode targetMode, int heightOfMan, int hexesPerMile)
        {
            Tracing.FieldOfView.Trace("GetFieldOfView");
            var fov = new ArrayFieldOfView(@this);

            if (@this.IsOverseeable(origin))
            {
                ShadowCasting.ComputeFieldOfView(@this, origin, fovRadius, targetMode,
                                                 coords => fov[coords] = true, heightOfMan, hexesPerMile);
            }

            return(fov);
        }
        /// <summary>Calculate Field-of-View from a specified TargetMode, assuming a spherical earth
        /// and height measured in feet if <code>hexesPerMile</code> is not equal 0.</summary>
        /// <param name="coordsObserver">Cordinates of observer;s hex.</param>
        /// <param name="board">A reference to an IFovBoard {IHex} instance.</param>
        /// <param name="targetMode">TargetMode value for determining target visibility.</param>
        /// <param name="setFieldOfView">Sets a hex as visible in the Field-of-View.</param>
        /// <param name="defaultHeight">Height used for observer and target when targetMode = EqualHeights/</param>
        /// <param name="hexesPerMile">Number of hexes per mile (ie 1/4000 of planet radius).</param>
        /// <remarks>Adjusts visibility for curvature of the Earth. This is the only version of
        /// ComputeFieldOfView that is <b>not</b> scale invariant for height, and assumes that height
        /// is measured in feet.
        /// </remarks>
        /// <a href="http://mathcentral.uregina.ca/qq/database/QQ.09.02/shirley3.html">Hidden by the Curvature of the Earth</a>
        public static void ComputeFieldOfView(
            HexCoords coordsObserver,
            IFovBoard <IHex> board,
            FovTargetMode targetMode,
            Action <HexCoords> setFieldOfView,
            int defaultHeight,
            int hexesPerMile
            )
        {
            int CalculationHeightUnits = UseMetric ?   5 // convert metres to  cm  for greater precision
                                             :  12;      // convert feet to inches for greater precision

            Func <HexCoords, int> elevationTarget;
            int elevationObserver;

            switch (targetMode)
            {
            case FovTargetMode.TargetHeightEqualZero:
                elevationTarget   = coords => board.ElevationGroundASL(coords);
                elevationObserver = board.ElevationObserverASL(coordsObserver);
                break;

            default:
            case FovTargetMode.TargetHeightEqualActual:
                elevationTarget   = coords => board.ElevationTargetASL(coords);
                elevationObserver = board.ElevationObserverASL(coordsObserver);
                break;

            case FovTargetMode.EqualHeights:
                elevationTarget   = coords => board.ElevationGroundASL(coords) + defaultHeight;
                elevationObserver = elevationTarget(coordsObserver);
                break;
            }

            Func <HexCoords, int> deltaHeight = GetDeltaHeight(coordsObserver, hexesPerMile, CalculationHeightUnits);

            ShadowCasting.ComputeFieldOfView(
                coordsObserver,
                board.FovRadius - 1,
                elevationObserver * CalculationHeightUnits,
                board.IsOnboard,
                coords => elevationTarget(coords) * CalculationHeightUnits - deltaHeight(coords),
                (coords, hexside) => board.ElevationHexsideASL(coords, hexside) * CalculationHeightUnits - deltaHeight(coords),
                setFieldOfView
                );
        }
        public static IFieldOfView GetFieldOfView(IBoard <IGridHex> board, ICoordsUser origin, int range,
                                                  FovTargetMode targetMode)
        {
            DebugTracing.LogTime(TraceFlag.FieldOfView, "FieldOfView - begin");
            var fov = new FieldOfView(board);

            if (board.IsPassable(origin))
            {
                Func <ICoordsCanon, int> target;
                int observer;
                switch (targetMode)
                {
                case FovTargetMode.EqualHeights:
                    observer = board[origin].ElevationASL + 1;
                    target   = canon => board[canon.User].ElevationASL + 1;
                    break;

                case FovTargetMode.TargetHeightEqualZero:
                    observer = board[origin].HeightObserver;
                    target   = canon => board[canon.User].ElevationASL;
                    break;

                default:
                case FovTargetMode.TargetHeightEqualActual:
                    observer = board[origin].HeightObserver;
                    target   = canon => board[canon.User].HeightTarget;
                    break;
                }
                ShadowCasting.ComputeFieldOfView(
                    origin.Canon,
                    range,
                    observer,
                    canon => board.IsOnBoard(canon.User),
                    target,
                    canon => board[canon.User].HeightTerrain,
                    canon => fov[canon.User] = true
                    );
            }
            DebugTracing.LogTime(TraceFlag.FieldOfView, "FieldOfView - end");
            return(fov);
        }
Exemple #7
0
 public static IFov GetFieldOfView(IFovBoard <IHex> board, HexCoords origin, FovTargetMode targetMode)
 {
     return(board.GetFieldOfView(origin, targetMode));
 }
 /// <summary>Gets a Field-of-View for this board synchronously.</summary>
 public static IFov GetFieldOfView(this IFovBoard <IHex> @this, HexCoords origin, FovTargetMode targetMode)
 {
     return(@this.GetFieldOfView(origin, targetMode, 1, 0));
 }
 /// <summary>Gets a Field-of-View for this board asynchronously.</summary>
 public static Task <IFov> GetFieldOfViewAsync(this IFovBoard <IHex> @this, HexCoords origin, FovTargetMode targetMode, int height, int hexesPerMile)
 {
     return(Task.Run <IFov>(
                () => @this.GetFieldOfView(origin, targetMode, height, hexesPerMile)
                ));
 }
 /// <summary>Gets a Field-of-View for this board asynchronously.</summary>
 public static Task <IFov> GetFieldOfViewAsync(this IFovBoard <IHex> @this, HexCoords origin, FovTargetMode targetMode)
 {
     return(@this.GetFieldOfViewAsync(origin, targetMode, 1));
 }
        /// <summary>Gets a Field-of-View for this board synchronously.</summary>
        public static IFov GetFieldOfView(this IFovBoard <IHex> @this, HexCoords origin, FovTargetMode targetMode, int heightOfMan, int hexesPerMile)
        {
            Traces.FieldOfView.Trace("GetFieldOfView");
            var fov = new ArrayFieldOfView(@this);

            if (@this.IsPassable(origin))
            {
                ShadowCasting.ComputeFieldOfView(origin, @this, targetMode, coords => fov[coords] = true, heightOfMan, hexesPerMile);
            }

            return(fov);
        }
Exemple #12
0
 /// <summary>Gets a Field-of-View for this board asynchronously.</summary>
 public static Task <IShadingMask> GetFieldOfViewAsync(this IFovBoard @this, HexCoords origin,
                                                       int fovRadius, FovTargetMode targetMode, int height, int hexesPerMile)
 => Task.Run(() => @this.GetFieldOfView(origin, fovRadius, targetMode, height, hexesPerMile));
 /// <summary>Gets a Field-of-View for this board asynchronously, assuming a flat earth.</summary>
 public static Task <IShadingMask> GetFieldOfViewAsync(this IFovBoard @this, HexCoords origin, int fovRadius, FovTargetMode targetMode)
 //@this.GetFieldOfViewAsync(origin, fovRadius, targetMode, 1);
 => Task.Run(() => @this.GetFieldOfView(origin, fovRadius, targetMode, 1, 0));
Exemple #14
0
        /// <summary>TODO</summary>
        public static IFov GetFieldOfView(this IFovBoard <IHex> @this, HexCoords origin, FovTargetMode targetMode)
        {
            TraceFlags.FieldOfView.Trace("GetFieldOfView");
            var fov = new ArrayFieldOfView(@this);

            if (@this.IsPassable(origin))
            {
                Func <HexCoords, int> target;
                int observer;
                switch (targetMode)
                {
                case FovTargetMode.EqualHeights:
                    observer = @this[origin].ElevationASL + 1;
                    target   = coords => @this[coords].ElevationASL + 1;
                    break;

                case FovTargetMode.TargetHeightEqualZero:
                    observer = @this[origin].HeightObserver;
                    target   = coords => @this[coords].ElevationASL;
                    break;

                default:
                case FovTargetMode.TargetHeightEqualActual:
                    observer = @this[origin].HeightObserver;
                    target   = coords => @this[coords].HeightTarget;
                    break;
                }
                ShadowCasting.ShadowCasting.ComputeFieldOfView(
                    origin,
                    @this.FovRadius,
                    observer,
                    coords => @this.IsOnboard(coords),
                    target,
                    coords => @this[coords].HeightTerrain,
                    coords => fov[coords] = true
                    );
            }
            return(fov);
        }