private void SetDrawStr() // these keys work for the NUMERIC keypad only while the escape key toggles if the tool is "on" { if (Input.GetKeyDown(KeyCode.Escape)) { canDraw = !canDraw; } else if (Input.GetKeyDown(KeyCode.Keypad0)) { drawStr = HexSize.normal; } else if (Input.GetKeyDown(KeyCode.Keypad1)) { drawStr = HexSize.grade1; } else if (Input.GetKeyDown(KeyCode.Keypad2)) { drawStr = HexSize.grade2; } else if (Input.GetKeyDown(KeyCode.Keypad3)) { drawStr = HexSize.grade3; } else if (Input.GetKeyDown(KeyCode.Keypad4)) { drawStr = HexSize.grade4; } else if (Input.GetKeyDown(KeyCode.Keypad5)) { drawStr = HexSize.grade5; } DrawToolUI.DTH_Num = (int)drawStr; }
/// <summary>TODO</summary> public NavigableBoard(HexSize mapSizeHexes, StepCosts entryCosts, StepCosts exitCosts, int minimumCost) { MapSizeHexes = mapSizeHexes; _entryCosts = entryCosts; _exitCosts = exitCosts; _minimumCost = minimumCost; }
/// <summary>Construct a new instance of extent <paramref name="sizeHexes"/> and /// initialized using <paramref name="initializer"/>.</summary> public BlockedBoardStorage32x32(HexSize sizeHexes, Func <HexCoords, T> initializer) : base(sizeHexes) { backingStore = new List <List <List <T> > >((MapSizeHexes.Height + _buffer) / _grouping); for (var y = 0; y < backingStore.Capacity; y++) { backingStore.Add(new List <List <T> >((MapSizeHexes.Width + _buffer) / _grouping)); for (var x = 0; x < backingStore[y].Capacity; x++) { backingStore[y].Add(new List <T>(_grouping * _grouping)); } } var result = Parallel.For(0, backingStore.Capacity, y => { var boardRow = backingStore[y]; for (var x = 0; x < boardRow.Capacity; x++) { var boardCell = backingStore[y][x]; for (var i = 0; i < _grouping; i++) { for (var j = 0; j < _grouping; j++) { var coords = HexCoords.NewUserCoords(x * _grouping + j, y * _grouping + i); boardCell.Add(IsOnboard(coords) ? initializer(coords) : default(T)); } } } }); }
private static IFastList <IFastListX <T> > InitializeStoreX(HexSize sizeHexes, Func <HexCoords, T> tFactory, IEnumerable <int> rowRange) => (from y in rowRange select(from x in Enumerable.Range(0, sizeHexes.Width) select tFactory(HexCoords.NewUserCoords(x, y)) ).ToArray().ToFastListX() ).ToArray().ToFastList();
internal BlockedBoardStorage(HexSize sizeHexes, Func <HexCoords, T> tFactory, int threadCount) : base(sizeHexes) { var rangeY = (MapSizeHexes.Height + BlockMask) / BlockSide; var rangeX = (MapSizeHexes.Width + BlockMask) / BlockSide; _backingStore = InitializeStore(tFactory, threadCount, rangeY, rangeX); }
public LandmarkPopulator( HexCoords hex, HexSize mapSizeHexes, Func <IPriorityQueue <int, HexCoords> > queueFactory, TryDirectedCost tryDirectedStepCost ) : base(hex, mapSizeHexes, queueFactory, tryDirectedStepCost) { }
/// <summary>Populates and returns a new landmark at the specified board coordinates.</summary> /// <param name="hexCoords"><see cref="HexCoords"/> for the landmark to be created.</param> /// <param name="mapSizeHexes">Hex dimensions of the IBoard{IHex} on which the landmark is to be created.</param> /// <param name="queueFactory">Factory that creates empty instances of <c>IPriorityQueue</c>.</param> /// <param name="tryDirectedCosts">TODO</param> private DirectedLandmark(HexCoords hexCoords, HexSize mapSizeHexes, Func <IPriorityQueue <int, HexCoords> > queueFactory, TryDirectedCost tryDirectedCosts ) { // _hex = hex; _backingStore = new LandmarkPopulatorFunctor(hexCoords, mapSizeHexes, queueFactory, tryDirectedCosts).Fill(); }
public static DirectedLandmark New(HexCoords hexCoords, HexSize mapSizeHexes, Func <IPriorityQueue <int, HexCoords> > queueFactory, TryDirectedCost tryDirectedCosts ) { return(Extensions.InitializeDisposable(() => new DirectedLandmark(hexCoords, mapSizeHexes, queueFactory, tryDirectedCosts))); }
/// <summary>Construct a new instance of extent <paramref name="sizeHexes"/> and /// initialized using <paramref name="factory"/>.</summary> /// <param name="sizeHexes"><c>Size</c> structure speccifying the Width and Height of /// the desired board storage.</param> /// <param name="factory"></param> /// <param name="inParallel">Boolean indicating how the board should be initialized: /// in parallel or serially.</param> public FlatBoardStorage(HexSize sizeHexes, Func <HexCoords, T> factory, bool inParallel) : base(sizeHexes) { var rowRange = inParallel ? ParallelEnumerable.Range(0, sizeHexes.Height).AsOrdered() : Enumerable.Range(0, sizeHexes.Height); BackingStore = InitializeStoreX(sizeHexes, factory, rowRange); }
/// <summary>Returns the location and extent in hexes, as a <see cref="CoordsRectangle"/>, of the current clipping region.</summary> protected CoordsRect GetClipInHexes(RectangleF visibleClipBounds, HexSize boardSizeHexes) { var left = Math.Max((int)visibleClipBounds.Left / GridSize.Width - 1, 0); var top = Math.Max((int)visibleClipBounds.Top / GridSize.Height - 1, 0); var right = Math.Min((int)visibleClipBounds.Right / GridSize.Width + 1, boardSizeHexes.Width); var bottom = Math.Min((int)visibleClipBounds.Bottom / GridSize.Height + 1, boardSizeHexes.Height); return(new CoordsRectangle(left, top, right - left, bottom - top)); }
// Use this for initialization void Awake() { unit = null; passable = true; size = HexSize.normal; cost = 1; tileType = TileType.Grass; // yVector = new Vector3(0.0f, 0.513f, 0.0f); }
/// <summary>Returns an array of six <see cref="HexPoint"/>s describing the corners of a hex on this <see cref="HexBoard{THex,TPath}"/>.</summary> /// <param name="gridSize">Dimensions of a hex on this <see cref="HexBoard{THex,TPath}"/> in pixels.</param> protected static HexPoint[] HexgridPathPoints(HexSize gridSize) { return(new HexPoint[] { new HexPoint(gridSize.Width * 1 / 3, 0), new HexPoint(gridSize.Width * 3 / 3, 0), new HexPoint(gridSize.Width * 4 / 3, gridSize.Height / 2), new HexPoint(gridSize.Width * 3 / 3, gridSize.Height), new HexPoint(gridSize.Width * 1 / 3, gridSize.Height), new HexPoint(0, gridSize.Height / 2) }); }
/// <summary><c>HexCoords</c> for the hex at the screen point, with the given AutoScroll position.</summary> /// <param name="this"></param> /// <param name="point">Screen point specifying hex to be identified.</param> /// <param name="autoScroll">AutoScrollPosition for game-display Panel.</param> static HexCoords GetHexCoordsInner(this IHexgrid @this, HexPoint point, HexSize autoScroll) { // Adjust for origin not as assumed by GetCoordinate(). var grid = new HexSize((int)(@this.GridSizeF().Width *2F / 3F), (int)@this.GridSizeF().Height); point -= autoScroll + grid - @this.Margin; return(HexCoords.NewCanonCoords(@this.GetCoordinate(@this.MatrixX(), point), @this.GetCoordinate(@this.MatrixY(), point))); }
/// <summary>Returns an array of six <see cref="HexPoint"/>s describing the corners of a hex on this <see cref="HexBoard{THex}"/>.</summary> /// <param name="gridSize">Dimensions of a hex on this <see cref="HexBoard{THex}"/> in pixels.</param> private static HexPoint[] HexgridPathPoints(HexSize gridSize) => new HexPoint[] { new HexPoint(gridSize.Width * 1 / 3, 0), new HexPoint(gridSize.Width * 3 / 3, 0), new HexPoint(gridSize.Width * 4 / 3, gridSize.Height / 2), new HexPoint(gridSize.Width * 3 / 3, gridSize.Height), new HexPoint(gridSize.Width * 1 / 3, gridSize.Height), new HexPoint(0, gridSize.Height / 2) };
/// <summary>Returns the location and extent in hexes, as a <see cref="CoordsRect"/>, of the current clipping region.</summary> /// <param name="this">The current {HexBoard}.</param> /// <param name="visibleClipBounds"></param> /// <param name="boardSizeHexes"></param> public static CoordsRect GetClipInHexes(this IPanelModel @this, RectangleF visibleClipBounds, HexSize boardSizeHexes) { var left = Math.Max((int)visibleClipBounds.Left / @this.GridSize.Width - 1, 0); var top = Math.Max((int)visibleClipBounds.Top / @this.GridSize.Height - 1, 0); var right = Math.Min((int)visibleClipBounds.Right / @this.GridSize.Width + 1, boardSizeHexes.Width); var bottom = Math.Min((int)visibleClipBounds.Bottom / @this.GridSize.Height + 1, boardSizeHexes.Height); return(new CoordsRect(left, top, right - left, bottom - top)); }
/// <inheritdoc/> public virtual HexCoords GetHexCoords(HexPoint point, HexSize autoScroll) { // Adjust for origin not as assumed by GetCoordinate(). var grid = new HexSize((int)(GridSizeF.Width * 2F / 3F), (int)GridSizeF.Height); point -= autoScroll + grid - Margin; return(HexCoords.NewCanonCoords(GetCoordinate(_matrixX, point), GetCoordinate(_matrixY, point))); }
/// <summary>By default, landmark all four corners and midpoints of all 4 sides.</summary> /// <remarks>Pre-processing time on start-up can be reduced by decreasing the number of landmarks, /// though at the possible expense of longer path-finding times.</remarks> /// <param name="size"></param> protected static IFastList <HexCoords> DefaultLandmarks(HexSize size) { return(new HexPoint[] { new HexPoint(0, 0), new HexPoint(size.Width / 2, 0), new HexPoint(size.Width - 1, 0), new HexPoint(0, size.Height / 2), new HexPoint(size.Width - 1, size.Height / 2), new HexPoint(0, size.Height - 1), new HexPoint(size.Width / 2, size.Height - 1), new HexPoint(size.Width - 1, size.Height - 1) }.Select(p => HexCoords.NewUserCoords(p)).ToFastList()); }
/// <summary>Creates a new instance of the MapDisplay class.</summary> protected MapDisplay(HexSize sizeHexes, HexSize gridSize, InitializeHex initializeHex, IFastList <HexCoords> landmarkCoords) : base(sizeHexes, gridSize, landmarkCoords, GetGraphicsPath #if FlatBoardStorage , () => new FlatBoardStorage <THex>(sizeHexes, coords => initializeHex(GetGraphicsPath(gridSize), coords)) #else , () => new BlockedBoardStorage32x32 <THex>(sizeHexes, coords => initializeHex(GetGraphicsPath(gridSize), coords)) #endif ) { InitializeProperties(); }
/// <summary>Returns the location and extent in hexes, as a <see cref="CoordsRect"/>, of the current clipping region.</summary> /// <param name="this">The current {HexBoard}.</param> /// <param name="visibleClipBounds"></param> /// <param name="boardSizeHexes"></param> public static CoordsRect GetClipInHexes <THex>(this HexBoard <THex> @this, RectangleF visibleClipBounds, HexSize boardSizeHexes) where THex : IHex { var left = Math.Max((int)visibleClipBounds.Left / @this.GridSize.Width - 1, 0); var top = Math.Max((int)visibleClipBounds.Top / @this.GridSize.Height - 1, 0); var right = Math.Min((int)visibleClipBounds.Right / @this.GridSize.Width + 1, boardSizeHexes.Width); var bottom = Math.Min((int)visibleClipBounds.Bottom / @this.GridSize.Height + 1, boardSizeHexes.Height); return(CoordsRect.New(left, top, right - left, bottom - top)); }
protected HexBoard(HexSize sizeHexes, HexSize gridSize, BoardStorage <Maybe <THex> > boardHexes) { BoardHexes = boardHexes; MapScale = 1.00F; IsTransposed = false; MapSizeHexes = sizeHexes; GridSize = gridSize; HexCentreOffset = new HexSize(GridSize.Width * 2 / 3, GridSize.Height / 2); GridSizePixels = new IntMatrix2D(GridSize.Width, 0, 0, GridSize.Height, GridSize.Width / 3, GridSize.Height / 2); }
/// <summary>By default, landmark all four corners and midpoints of all 4 sides.</summary> /// <remarks>Pre-processing time on start-up can be reduced by decreasing the number of landmarks, /// though at the possible expense of longer path-finding times.</remarks> /// <param name="size"></param> protected static IFastList <HexCoords> DefaultLandmarks(HexSize size) => (from point in new HexPoint[] { new HexPoint(0, 0), // top-left new HexPoint(0, size.Height / 2), // middle-left new HexPoint(0, size.Height - 1), // bottom-left new HexPoint(size.Width / 2, size.Height - 1), // bottom-centre new HexPoint(size.Width - 1, size.Height - 1), // bottom-right new HexPoint(size.Width - 1, size.Height / 2), // middle-right new HexPoint(size.Width - 1, 0), // top-right new HexPoint(size.Width / 2, 0), // top-centre } select HexCoords.NewUserCoords(point) ).ToArray().ToFastList();
public LandmarkPopulatorFunctor( HexCoords hexCoords, HexSize mapSizeHexes, Func <IPriorityQueue <int, HexCoords> > queueFactory, TryDirectedCost tryDirectedStepCost ) { Tracing.FindPathDetail.Trace("Find distances from {0}", hexCoords); _queue = queueFactory(); _store = BlockedBoardStorage.New32x32(mapSizeHexes, c => default(short?)); _tryDirectedStepCost = tryDirectedStepCost; Enqueue(0, hexCoords, _store); }
/// <summary>Creates a new instance of the MapDisplay class.</summary> protected MapDisplay(HexSize sizeHexes, HexSize gridSize, InitializeHex initializeHex, IFastList <HexCoords> landmarkCoords, BoardStorage <Maybe <THex> > storage) : base(sizeHexes, gridSize, storage) { ResetLandmarksAsync(landmarkCoords); GoalHex = HotspotHex = StartHex = HexCoords.EmptyUser; ShadeBrushAlpha = 78; ShowFov = true; ShowHexgrid = true; ShowPath = true; ShowPathArrow = true; HexgridPath = Extensions.InitializeDisposable(() => new GraphicsPath(HexgridPathPoints(gridSize), _hexgridPathPointTypes)); }
protected HexBoard(HexSize sizeHexes, HexSize gridSize, BoardStorage <Maybe <THex> > boardHexes) { BoardHexes = boardHexes; MapScale = 1.00F; IsTransposed = false; MapSizeHexes = sizeHexes; GridSize = gridSize; HexCentreOffset = new HexSize(GridSize.Width * 2 / 3, GridSize.Height / 2); GridSizePixels = new IntMatrix2D(GridSize.Width, 0, 0, GridSize.Height, GridSize.Width / 3, GridSize.Height / 2); EntryCosts = new BlockedBoardStorage32x32 <Maybe <HexsideCosts> >(sizeHexes, hexCoords => HexsideCosts.EntryCosts(boardHexes, hexCoords), 1); ExitCosts = new BlockedBoardStorage32x32 <Maybe <HexsideCosts> >(sizeHexes, hexCoords => HexsideCosts.ExitCosts(boardHexes, hexCoords), 1); }
/// <summary>Return a new instance of <c>Hexgrid</c>.</summary> public Hexgrid(bool isTransposed, HexSize gridSize, float scale, HexSize margin) { GridSize = gridSize; IsTransposed = isTransposed; Margin = margin; Scale = scale; HexCorners = new List <HexPoint>() { new HexPoint(GridSize.Width * 1 / 3, 0), new HexPoint(GridSize.Width * 3 / 3, 0), new HexPoint(GridSize.Width * 4 / 3, GridSize.Height / 2), new HexPoint(GridSize.Width * 3 / 3, GridSize.Height), new HexPoint(GridSize.Width * 1 / 3, GridSize.Height), new HexPoint(0, GridSize.Height / 2), new HexPoint(GridSize.Width * 1 / 3, 0) }.AsReadOnly(); }
/// <summary>TODO</summary> private static StreamGeometry GetGraphicsPath(HexSize gridSize) { StreamGeometry geometry = new StreamGeometry(); geometry.FillRule = FillRule.EvenOdd; using (var context = geometry.Open()) { context.BeginFigure(new Point(gridSize.Width * 1 / 3, 0), false, true); context.LineTo(new Point(gridSize.Width * 3 / 3, 0), true, false); context.LineTo(new Point(gridSize.Width * 4 / 3, gridSize.Height / 2), true, false); context.LineTo(new Point(gridSize.Width * 3 / 3, gridSize.Height), true, false); context.LineTo(new Point(gridSize.Width * 1 / 3, gridSize.Height), true, false); context.LineTo(new Point(0, gridSize.Height / 2), true, false); } geometry.Freeze(); return(geometry); }
/// <summary>Return a new instance of <c>Hexgrid</c>.</summary> protected TransposableHexgrid(HexSize gridSize, float scale, HexSize margin) { GridSize = gridSize; Scale = scale; Margin = margin; GridSizeF = GridSize.Scale(Scale); HexCorners = new List <HexPoint>() { new HexPoint(GridSize.Width * 1 / 3, 0), new HexPoint(GridSize.Width * 3 / 3, 0), new HexPoint(GridSize.Width * 4 / 3, GridSize.Height / 2), new HexPoint(GridSize.Width * 3 / 3, GridSize.Height), new HexPoint(GridSize.Width * 1 / 3, GridSize.Height), new HexPoint(0, GridSize.Height / 2), new HexPoint(GridSize.Width * 1 / 3, 0) }.AsReadOnly(); }
private HexBoard(HexSize sizeHexes, HexSize gridSize, Func <HexSize, TPath> hexgridPath , BoardStorageInitializer <THex, TPath> boardStorage ) { if (hexgridPath == null) { throw new ArgumentNullException("hexgridPath"); } if (boardStorage == null) { throw new ArgumentNullException("boardStorage"); } MapScale = 1.00F; IsTransposed = false; MapSizeHexes = sizeHexes; GridSize = gridSize; HexgridPath = hexgridPath(gridSize); _boardHexes = boardStorage(); }
public DrawTool() { canDraw = true; drawStr = HexSize.normal; multCellRadius = 0; scroll = 0; currMode = DrawMode.Height; currType = MaterialTypes.Grass; currTypeInt = 0; buttonGet = GameObject.Find("Tile Height Button"); heightButton = buttonGet.GetComponent <Button>(); heightButton.onClick.AddListener(HeightButtonTask); buttonGet = GameObject.Find("Tile Type Button"); typeButton = buttonGet.GetComponent <Button>(); typeButton.onClick.AddListener(TypeButtonTask); //Everytime a material type is added to the enum, update this. tileTypeMax = 2; //int of last enum in MaterialTypes }
public static WpfSize ToWpfSize(this HexSize @this) { return(new WpfSize(@this.Width, @this.Height)); }