public void MoveUnit(Point unitPos, Point destination) { Unit unit = units[unitPos.Y, unitPos.X]; if (unitPos != destination) { float length = 0.07f * MathExtensions.CellDistance(unitPos, destination); animationQueue.Add(new MoveAnimation(CellToWorld(unitPos).Add(1), CellToWorld(destination).Add(1), unit.GetSprite(game.Textures), length), unit); units[unitPos.Y, unitPos.X] = null; units[destination.Y, destination.X] = unit; unit.Position = destination; } unit.Acted = true; UnselectUnit(); UnselectTiles(); }
private Dictionary <Point, ThreatenedCell> GetThreatenSpaces(HashSet <Point> reach, Unit unit) { var threathenedSpaces = new Dictionary <Point, ThreatenedCell>(); int minimumRange = 1; if (unit.Stats[Stats.Range] > 0 && unit.Stats[Stats.Magic] == 0) { minimumRange = 2; } foreach (var pos in reach) { for (int i = unit.Stats[Stats.Range] + 1; i >= minimumRange; i--) { int currPriority = 1000 - MathExtensions.CellDistance(unit.Position, pos); for (int j = i; j != 0; j--) { Point threatPos = new Point(pos.X - j, pos.Y - (i - j)); if (threathenedSpaces.ContainsKey(threatPos) && threathenedSpaces[threatPos].Priority >= currPriority) { continue; } threathenedSpaces[threatPos] = new ThreatenedCell() { Position = threatPos, From = pos, Priority = currPriority }; } for (int j = i; j != 0; j--) { Point threatPos = new Point(pos.X + (i - j), pos.Y - j); if (threathenedSpaces.ContainsKey(threatPos) && threathenedSpaces[threatPos].Priority >= currPriority) { continue; } threathenedSpaces[threatPos] = new ThreatenedCell() { Position = threatPos, From = pos, Priority = currPriority }; } for (int j = i; j != 0; j--) { Point threatPos = new Point(pos.X + j, pos.Y + (i - j)); if (threathenedSpaces.ContainsKey(threatPos) && threathenedSpaces[threatPos].Priority >= currPriority) { continue; } threathenedSpaces[threatPos] = new ThreatenedCell() { Position = threatPos, From = pos, Priority = currPriority }; } for (int j = i; j != 0; j--) { Point threatPos = new Point(pos.X - (i - j), pos.Y + j); if (threathenedSpaces.ContainsKey(threatPos) && threathenedSpaces[threatPos].Priority >= currPriority) { continue; } threathenedSpaces[threatPos] = new ThreatenedCell() { Position = threatPos, From = pos, Priority = currPriority }; } } } foreach (var u in units) { if (u == null) { continue; } if (u.Enemy == unit.Enemy) { threathenedSpaces.Remove(u.Position); } } return(threathenedSpaces); }