public void CaculateLastAlignment() { if (_npcs.Count == 0) { return; } int x, y; GridService.GetCoordinate(_commander.Position, out x, out y); int radius = 1; int index = _npcs.Count - 1; while (true) { for (int i = radius; i >= -radius; i--) { for (int j = radius; j >= -radius; j--) { if (i != radius && i != -radius) { if (j == radius || j == -radius) { if (GridService.IsEmpty(j + x, i + y)) { for (int k = 0; k < _npcs.Count; k++) { if (_npcs[k].AlignmentX != j || _npcs[k].AlignmentY != i) { _npcs[index].AlignmentX = j; _npcs[index].AlignmentY = i; return; } } } } } else { if (GridService.IsEmpty(j + x, i + y)) { for (int k = 0; k < _npcs.Count; k++) { if (_npcs[k].AlignmentX != j || _npcs[k].AlignmentY != i) { _npcs[index].AlignmentX = j; _npcs[index].AlignmentY = i; return; } } } } } } radius++; } }
public void CaculateAlignment() { var rowCount = FixedMath.Sqrt(_npcs.Count * FixedMath.One).CeilToInt(); int x, y; GridService.GetCoordinate(_commander.Position, out x, out y); int radius = 1; int index = 0; while (true) { for (int i = radius; i >= -radius; i--) { for (int j = radius; j >= -radius; j--) { if (i != radius && i != -radius) { if (j == radius || j == -radius) { if (GridService.IsEmpty(j + x, i + y)) { _npcs[index].AlignmentX = j; _npcs[index].AlignmentY = i; index++; if (index == _npcs.Count) { return; } } } } else { if (GridService.IsEmpty(j + x, i + y)) { _npcs[index].AlignmentX = j; _npcs[index].AlignmentY = i; index++; if (index == _npcs.Count) { return; } } } } } radius++; } }