Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmonize cell order for AoE items #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 51 additions & 31 deletions src/main/java/com/leekwars/generator/maps/MaskAreaCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@ public static int[][] generateCircleMask(int min, int max) {

if (min > max)
return null;
int cellsMin = 0;
if (min > 0) {
if (min > 1)
cellsMin = 1 + (min - 1) * (4 + 4 * (min - 1)) / 2;
else
cellsMin = 1;
}
int cellsMax = 1;
if (max > 0)
cellsMax = max * (4 + 4 * max) / 2 + 1;

int nbCells = cellsMax - cellsMin;
int nbCells = 2 * (min + max) * (max - min + 1);
if (min == 0) {
nbCells += 1;
}
int[][] retour = new int[nbCells][2];

int index = 0;
if (min == 0) {
retour[0] = new int[] { 0, 0 };
index++;
// Center first
retour[index++] = new int[] { 0, 0 };
}

// Go from cells closer to the center to the farther ones
for (int size = (min < 1 ? 1 : min); size <= max; size++) {
// Add cells counter-clockwise
for (int i = 0; i < size; i++) {
retour[index++] = new int[] { size - i, -i };
}
for (int i = 0; i < size; i++) {
retour[index++] = new int[] { -i, -(size - i) };
}
for (int i = 0; i < size; i++) {
retour[index] = new int[] { i, size - i };
retour[index + 1] = new int[] { -i, -(size - i) };
retour[index + 2] = new int[] { size - i, -i };
retour[index + 3] = new int[] { -(size - i), i };
index += 4;
retour[index++] = new int[] { -(size - i), i };
}
for (int i = 0; i < size; i++) {
retour[index++] = new int[] { i, size - i };
}
}
return retour;
Expand All @@ -68,15 +68,17 @@ public static int[][] generatePlusMask(int radius) {
int nbCells = 1 + radius * 4;
int[][] retour = new int[nbCells][2];

// Center first
retour[0] = new int[] { 0, 0 };

int index = 1;
// Go from cells closer to the center to the farther ones
for (int size = 1; size <= radius; size++) {
retour[index] = new int[] { size, 0 };
retour[index + 1] = new int[] { 0, -size };
retour[index + 2] = new int[] { -size, 0 };
retour[index + 3] = new int[] { 0, size };
index += 4;
// Add cells counter-clockwise
retour[index++] = new int[] { size, 0 };
retour[index++] = new int[] { 0, -size };
retour[index++] = new int[] { -size, 0 };
retour[index++] = new int[] { 0, size };
}
return retour;
}
Expand All @@ -86,15 +88,17 @@ public static int[][] generateXMask(int radius) {
int nbCells = 1 + radius * 4;
int[][] retour = new int[nbCells][2];

// Center first
retour[0] = new int[] { 0, 0 };

int index = 1;
// Go from cells closer to the center to the farther ones
for (int size = 1; size <= radius; size++) {
retour[index] = new int[] { size, size };
retour[index + 1] = new int[] { size, -size };
retour[index + 2] = new int[] { -size, size };
retour[index + 3] = new int[] { -size, -size };
index += 4;
// Add cells counter-clockwise
retour[index++] = new int[] { size, -size };
retour[index++] = new int[] { -size, -size };
retour[index++] = new int[] { -size, size };
retour[index++] = new int[] { size, size };
}
return retour;
}
Expand All @@ -104,10 +108,26 @@ public static int[][] generateSquareMask(int radius) {
int nbCells = (1 + 2 * radius) * (1 + 2 * radius);
int[][] retour = new int[nbCells][2];

// Go from cells closer to the center to the farther ones
// First, add cells in the inscribed circle
int index = 0;
for (int x = -radius; x <= radius; x++) {
for (int y = -radius; y <= radius; y++) {
retour[index++] = new int[] { x, y };
for (int[] cell : generateCircleMask(0, radius)) {
retour[index++] = cell;
}
// Then, the corners
for (int d = 0; d < radius; d++) {
// Add cells counter-clockwise
for (int i = 1; i <= radius - d; i++) {
retour[index++] = new int[] { radius + 1 - i, -(d + i) };
}
for (int i = 1; i <= radius - d; i++) {
retour[index++] = new int[] { -(d + i), -(radius + 1 - i) };
}
for (int i = 1; i <= radius - d; i++) {
retour[index++] = new int[] { -(radius + 1 - i), d + i };
}
for (int i = 1; i <= radius - d; i++) {
retour[index++] = new int[] { d + i, radius + 1 - i };
}
}
return retour;
Expand Down
Loading