public ArrayFieldOfView(IFovBoard board) { _mapSizeHexes = board.MapSizeHexes; _fovBacking = (from i in Enumerable.Range(0, board.MapSizeHexes.Width) select new BitArray(board.MapSizeHexes.Height) ).ToArray(); }
public ArrayFieldOfView(IFovBoard<IHex> board) { _isOnboard = h => board.IsOnboard(h); _fovBacking = new BitArray[board.MapSizeHexes.Width]; for (var i = 0; i < board.MapSizeHexes.Width; i++) _fovBacking[i] = new BitArray(board.MapSizeHexes.Height); }
public static IFov GetFieldOfView(IFovBoard <IHex> board, HexCoords origin) { if (board == null) { throw new ArgumentNullException("board"); } return(board.GetFieldOfView(origin)); }
/// <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>Gets a Field-of-View for this board synchronously.</summary> public static IFov GetFieldOfView(this IFovBoard <IHex> @this, HexCoords origin, int height) { if (@this == null) { throw new ArgumentNullException("this"); } return(@this.GetFieldOfView(origin, FovTargetMode.EqualHeights, height, 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); }
public ArrayFieldOfView(IFovBoard <IHex> board) { _isOnboard = h => board.IsOnboard(h); _fovBacking = new BitArray[board.MapSizeHexes.Width]; for (var i = 0; i < board.MapSizeHexes.Width; i++) { _fovBacking[i] = new BitArray(board.MapSizeHexes.Height); } }
/// <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>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); }
/// <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 ); }
/// <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 ); }
/// <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); }
/// <summary>Gets a Field-of-View for this board asynchronously.</summary> public static Task <IFov> GetFieldOfViewAsync(this IFovBoard <IHex> @this, HexCoords origin) { return(@this.GetFieldOfViewAsync(origin, 1)); }
/// <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>Elevation of the terrain Above Sea Level</summary> /// <param name="this">The {IFovBoard} to be analyzed.</param> /// <param name="coords">The coordinates of the hex being tested.</param> public static int ElevationTerrainASL(this IFovBoard @this, HexCoords coords) => @this[coords].Match(hex => @this.ElevationASL(hex) + hex.HeightTerrain, MaxValue32);
/// <summary>Returns whether the hex at location <paramref name="coords"/> is passable.</summary> /// <param name="this">The {IFovBoard} to be analyzed.</param> /// <param name="coords">The coordinates of the hex being tested.</param> public static bool IsOverseeable(this IFovBoard @this, HexCoords coords) => @this.MapSizeHexes.IsOnboard(coords);
/// <summary>Elevation of the hexside Above Sea Level</summary> /// <param name="this">The {IFovBoard} to be analyzed.</param> /// <param name="coords">The coordinates of the hex being tested.</param> /// <param name="hexside"></param> public static int ElevationHexsideASL(this IFovBoard @this, HexCoords coords, Hexside hexside) => @this[coords].Match(hex => @this.ElevationASL(hex) + hex.HeightHexside(hexside), MaxValue32);
/// <summary>Elevation of the observer Above Sea Level</summary> /// <param name="this">The {IFovBoard} to be analyzed.</param> /// <param name="coords">The coordinates of the hex being tested.</param> public static int ElevationObserverASL(this IFovBoard @this, HexCoords coords) => @this[coords].Match(hex => @this.ElevationASL(hex) + @this.HeightOfMan, MaxValue32);
/// <summary>Elevation of the ground Above Sea Level</summary> /// <param name="this">The {IFovBoard} to be analyzed.</param> /// <param name="hex">The hex being tested.</param> public static int ElevationASL(this IFovBoard @this, IHex hex) => @this.ElevationBase + hex.ElevationLevel * @this.ElevationStep;
/// <summary>Elevation of the ground Above Sea Level</summary> /// <param name="this">The {IFovBoard} to be analyzed.</param> /// <param name="coords">The coordinates of the hex being tested.</param> public static int ElevationGroundASL(this IFovBoard @this, HexCoords coords) => @this[coords].Match(hex => @this.ElevationASL(hex), MaxValue32);
/// <summary>Gets a Field-of-View for this board asynchronously.</summary> public static Task <IFov> GetFieldOfViewAsync(this IFovBoard <IHex> @this, HexCoords origin, int height) { return(@this.GetFieldOfViewAsync(origin, FovTargetMode.EqualHeights, height)); }
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 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) { return(@this.GetFieldOfView(origin, targetMode, 1, 0)); }
/// <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));
/// <summary>Gets a Field-of-View for this board synchronously.</summary> public static IFov GetFieldOfView(this IFovBoard <IHex> @this, HexCoords origin) { return(@this.GetFieldOfView(origin, 1)); }
/// <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, assuming a flat earth.</summary> public static Task <IShadingMask> GetFieldOfViewAsync(this IFovBoard @this, HexCoords origin, int fovRadius, int height) => Task.Run(() => @this.GetFieldOfView(origin, fovRadius, FovTargetMode.EqualHeights, 1, 0));
/// <summary>Gets a Field-of-View for this board synchronously, assuming a flat earth.</summary> public static IShadingMask GetFieldOfView(this IFovBoard @this, HexCoords origin, int fovRadius) => @this.GetFieldOfView(origin, fovRadius, FovTargetMode.EqualHeights, 1, 0);