Skip to content

Commit

Permalink
added array builder command
Browse files Browse the repository at this point in the history
  • Loading branch information
fogleman committed Feb 2, 2014
1 parent 42e6dbc commit fe3e7b3
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,29 @@ void paste() {
}
}

void array(Block *b1, Block *b2, int xc, int yc, int zc) {
if (b1->w != b2->w) {
return;
}
int w = b1->w;
int dx = b2->x - b1->x;
int dy = b2->y - b1->y;
int dz = b2->z - b1->z;
xc = dx ? xc : 1;
yc = dy ? yc : 1;
zc = dz ? zc : 1;
for (int i = 0; i < xc; i++) {
int x = b1->x + dx * i;
for (int j = 0; j < yc; j++) {
int y = b1->y + dy * j;
for (int k = 0; k < zc; k++) {
int z = b1->z + dz * k;
builder_block(x, y, z, w);
}
}
}
}

void cube(Block *b1, Block *b2, int fill) {
if (b1->w != b2->w) {
return;
Expand Down Expand Up @@ -2001,7 +2024,7 @@ void parse_command(const char *buffer, int forward) {
char server_addr[MAX_ADDR_LENGTH];
int server_port = DEFAULT_PORT;
char filename[MAX_PATH_LENGTH];
int radius;
int radius, count, xc, yc, zc;
if (sscanf(buffer, "/identity %128s %128s", username, token) == 2) {
db_auth_set(username, token);
add_message("Successfully imported identity token!");
Expand Down Expand Up @@ -2058,6 +2081,12 @@ void parse_command(const char *buffer, int forward) {
else if (strcmp(buffer, "/tree") == 0) {
tree(&g->block0);
}
else if (sscanf(buffer, "/array %d %d %d", &xc, &yc, &zc) == 3) {
array(&g->block1, &g->block0, xc, yc, zc);
}
else if (sscanf(buffer, "/array %d", &count) == 1) {
array(&g->block1, &g->block0, count, count, count);
}
else if (strcmp(buffer, "/fcube") == 0) {
cube(&g->block0, &g->block1, 1);
}
Expand Down

0 comments on commit fe3e7b3

Please sign in to comment.