public List<BMapCell> GetByTargetFilter(Unit owner, BMapCell ownerCell, Targets appliesOn, int range) { var res = new List<BMapCell>(); if (appliesOn == null) return res; var all = GetCellsInRange(ownerCell.Axial, range); if (appliesOn.Allies) { for (int i = 0; i < all.Count; i++) if (all[i].Unit != null && all[i].Unit.TeamId == owner.TeamId) if (appliesOn.Dead ? all[i].Unit.CharCursI(CharType.Alive) == 0 : all[i].Unit.CharCursI(CharType.Alive) == 1) res.Add(all[i]); } if (appliesOn.Enemies) { for (int i = 0; i < all.Count; i++) if (all[i].Unit != null && all[i].Unit.TeamId != owner.TeamId) if (appliesOn.Dead ? all[i].Unit.CharCursI(CharType.Alive) == 0 : all[i].Unit.CharCursI(CharType.Alive) == 1) res.Add(all[i]); } if (appliesOn.MapCells) { res.AddRange(all.Where(cell => cell.Unit == null )); } if (!appliesOn.Self) { res.Remove(ownerCell); } return res; }
public int GetDirection(BMapCell start, BMapCell target) { for (int i = 0; i < 6; i++) if (start.Neighbors[i] != null && start.Neighbors[i].Axial == target.Axial) return i; return -1; }
public List<BMapCell> GetSheme(BMapCell startPoint, int[] sheme, int goesTo, bool includeStartPoint) { var res = new List<BMapCell>(); var cubes = CubeUtils.GetSheme(startPoint.Cube, sheme, goesTo, includeStartPoint); // Определим какие части схемы попали на карту. for (int cellsCounter = 0; cellsCounter < _notNullCells.Length; cellsCounter++) for (int cubesCounter = 0; cubesCounter < cubes.Count; cubesCounter++) if (_notNullCells[cellsCounter].Cube == cubes[cubesCounter]) res.Add(_notNullCells[cellsCounter]); cubes = null; return res; }
public List<BMapCell> GetAForAction(Unit owner, BMapCell ownerCell, Act action, bool forHero = false) { var res = new List<BMapCell>(); if (action == null || ownerCell == null || ownerCell.Unit == null) return res; if (action.BlockIfEnemyClose) for (int i = 0; i < 6; i++) if (ownerCell.Neighbors[i] != null && ownerCell.Neighbors[i].Unit != null && ownerCell.Unit.TeamId != ownerCell.Neighbors[i].Unit.TeamId) return res; res.AddRange(GetByTargetFilter(owner, ownerCell, action.Targetting, action.Range == 1 ? owner.CharCursI(CharType.MoveRange) + 1 : action.Range)); return res; }
public List<BMapCell> GetPath(Unit unit, BMapCell start, BMapCell goal, List<BMapCell> moveAllowed) { if (unit.CharCursI(CharType.MoveType) == (int)MoveTypes.Walk) { var frontier = new Queue<BMapCell>(); //frontier = Queue() frontier.Enqueue(start); //frontier.put(start ) var came_from = new Dictionary<BMapCell, BMapCell>(); //came_from = {} //came_from.Add(new KeyValuePair<BMapCell, BMapCell>(start, null));// came_from[start] = None BMapCell current; while (frontier.Count > 0) //while not frontier.empty(): { current = frontier.Dequeue(); //current = frontier.get() if (current.Axial == goal.Axial) //if current == goal: break; //break for (int i = 0; i < current.Neighbors.Length; i++) //for next in graph.neighbors(current): { var next = current.Neighbors[i]; if (next == null) continue; if (!moveAllowed.Any(x => x.Axial == next.Axial)) continue; if (came_from.All(x => x.Key.Axial != next.Axial)) //if next not in came_from: { frontier.Enqueue(next); //frontier.put(next) came_from.Add(next, current);//came_from[next] = current } } } current = goal; //current = goal var res = new List<BMapCell>(); //path = [] while (current != start) //while current != start: { res.Add(came_from[current]); //path.append(current) current = came_from[current]; //current = came_from[current] } res.Reverse(); res.Add(goal);//path.append(start) # optional if (res.Count > 1) res.RemoveAt(0); return res; } else { return new List<BMapCell>() { goal }; } }
public List<BMapCell> GetSheme(BMapCell actionStart, Act action, int goesTo, List<BMapCell> availableToAction) { var res = new List<BMapCell>(); switch (action.ShemeType) { case ShemeTypes.Sheme: res.AddRange(GetSheme(actionStart, action.Sheme, goesTo, action.IncludeStartPoint)); break; case ShemeTypes.One: res.Add(actionStart); break; case ShemeTypes.All: res.AddRange(availableToAction); break; default: break; } return res; }
public List<BMapCell> GetAFormMove(BMapCell start, int range, MoveTypes moveType) { if (moveType == MoveTypes.Walk) { var visited = new List<BMapCell>();// # set of hexes //visited.Add(start); var fringes = new List<List<BMapCell>>();//var fringes = [] # array of arrays of hexes fringes.Add(new List<BMapCell>() { start });//fringes.append([start]) for (int k = 1; k <= range; k++)//for each 1 < k ≤ movement: { fringes.Add(new List<BMapCell>());//fringes.append([]) for (int fc = 0; fc < fringes[k - 1].Count; fc++)//for each hex in fringes[k - 1]: { var hex = fringes[k - 1][fc]; for (int dir = 0; dir < 6; dir++)//for each 0 ≤ dir < 6: { var neighbor = hex.GetDir(dir);//var neighbor = hex_neighbor(hex, dir) if (neighbor == null) continue; if (!visited.Contains(neighbor) && neighbor.Unit == null)//if neighbor not in visited and not blocked: { visited.Add(neighbor);//add neighbor to visited fringes[k].Add(neighbor);//fringes[k].append(neighbor) } } } } return visited; } else { var res = new List<BMapCell>(); var all = GetCellsInRange(start.Axial, range); for (int i = 0; i < all.Count; i++) { if (all[i].Unit == null) res.Add(all[i]); } return res; } }
public List<BMapCell> GetAForApply(Unit owner, BMapCell ownerCell, Targets appliesOn) { return GetByTargetFilter(owner, ownerCell, appliesOn, 7); }
public BMap(int sideCellCount, float hexRadius) { SideCellCount = sideCellCount; ArraySize = sideCellCount * 2 - 1; HexOutRadius = hexRadius; // Fill all Cells = new BMapCell[ArraySize, ArraySize]; for (int row = 0; row < ArraySize; row++) for (int col = 0; col < ArraySize; col++) Cells[col, row] = new BMapCell(col, row); int notNullCellsCount = ArraySize * ArraySize; // Remove top-left corner for (int row = 0; row < (sideCellCount - 1); row++) for (int col = 0; col < (sideCellCount - row - 1); col++) { notNullCellsCount--; Cells[col, row] = null; } // Remove bottom-right corner for (int row = sideCellCount; row < ArraySize; row++) for (int col = (ArraySize - row + sideCellCount - 1); col < ArraySize; col++) { notNullCellsCount--; Cells[col, row] = null; } _notNullCells = new BMapCell[notNullCellsCount]; notNullCellsCount = 0; for (int row = 0; row < ArraySize; row++) for (int col = 0; col < ArraySize; col++) if (Cells[col, row] != null) { _notNullCells[notNullCellsCount] = Cells[col, row]; notNullCellsCount++; } // [X] [X] [ ] [ ] [ ] // [X] [ ] [ ] [ ] [ ] // [ ] [ ] [ ] [ ] [ ] // [ ] [ ] [ ] [ ] [X] // [ ] [ ] [ ] [X] [X] HexWidth = (float)Math.Sqrt(3) * HexOutRadius; HexInRadius = HexWidth / 2f; HexHeight = 2f * HexOutRadius; WidthSpacing = HexWidth; HeightSpacing = HexHeight * 3f / 4f; // Fill hexes List<BMapCell> neighs = new List<BMapCell>(); for (int row = 0; row < ArraySize; row++) { for (int col = 0; col < ArraySize; col++) { if (Cells[col, row] != null) { var hex = new Hex( new PointF( HexWidth + (col - (ArraySize - sideCellCount - 1)) * (WidthSpacing) + row * (HexInRadius), HexOutRadius + row * (HeightSpacing) ), HexOutRadius); Cells[col, row].Hex = hex; Cells[col, row].ModelSize = new RectangleF(hex.Center.X - (HexWidth * 0.9f) / 2f, hex.Center.Y - (HexWidth * 0.9f) / 2f, HexWidth * 0.9f, HexWidth * 0.9f); Cells[col, row].StepsSize = new RectangleF(hex.Center.X - (HexWidth * 0.4f) / 2f, hex.Center.Y - (HexWidth * 0.4f) / 2f, HexWidth * 0.4f, HexWidth * 0.4f); neighs.Clear(); if ((col + 1).Between(-1, ArraySize) && (row + 0).Between(-1, ArraySize)) neighs.Add(Cells[col + 1, row + 0]); else neighs.Add(null); if ((col + 1).Between(-1, ArraySize) && (row - 1).Between(-1, ArraySize)) neighs.Add(Cells[col + 1, row - 1]); else neighs.Add(null); if ((col + 0).Between(-1, ArraySize) && (row - 1).Between(-1, ArraySize)) neighs.Add(Cells[col + 0, row - 1]); else neighs.Add(null); if ((col - 1).Between(-1, ArraySize) && (row + 0).Between(-1, ArraySize)) neighs.Add(Cells[col - 1, row + 0]); else neighs.Add(null); if ((col - 1).Between(-1, ArraySize) && (row + 1).Between(-1, ArraySize)) neighs.Add(Cells[col - 1, row + 1]); else neighs.Add(null); if ((col + 0).Between(-1, ArraySize) && (row + 1).Between(-1, ArraySize)) neighs.Add(Cells[col + 0, row + 1]); else neighs.Add(null); Cells[col, row].Neighbors = neighs.ToArray(); } } } neighs = null; // Prepare layout Width = TMath.Round(HexWidth * ArraySize + 1 + (ArraySize*5)); Height = TMath.Round(HexHeight + HeightSpacing * (ArraySize - 1) + 1 + (ArraySize*5)); Bitmap b = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(b); //g.FillRectangle(Brushes.White, new Rectangle(0, 0, b.Width, b.Height)); g.TextRenderingHint = TextRenderingHint.AntiAlias; for (int i = 0; i < _notNullCells.Length; i++) { g.FillPolygon(Brushes.Gainsboro, _notNullCells[i].Hex.K); var s = String.Format("{0}", _notNullCells[i].Axial); var w = g.MeasureString(s, _fnt).Width; g.DrawString(s, _fnt, _brush, _notNullCells[i].Hex.Center.X - w / 2, _notNullCells[i].Hex.Center.Y - 35, _drawFormat); s = String.Format("{0}", _notNullCells[i].Cube); w = g.MeasureString(s, _fnt).Width; g.DrawString(s, _fnt, _brush, _notNullCells[i].Hex.Center.X - w / 2, _notNullCells[i].Hex.Center.Y + 20, _drawFormat); } g.Flush(); GridLayout = new Bitmap(b); g = null; b = null; }
public int GetDirection(BMapCell c, int x, int y) { return c.Hex.Center.Angle(x, y) / 60; }