fairland: Track adjacent land sectors
The next commit will put it to use. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
49c494a8d7
commit
5aa3938b37
1 changed files with 25 additions and 0 deletions
|
@ -188,6 +188,13 @@ static int diry[] = { 0, -1, -1, 0, 1, 1 };
|
|||
|
||||
static int **own; /* owner of the sector. -1 means water */
|
||||
|
||||
/*
|
||||
* Adjacent land sectors
|
||||
* adj_land[XYOFFSET(x, y)] bit d is set exactly when the sector next
|
||||
* to x, y in direction d is land.
|
||||
*/
|
||||
static unsigned char *adj_land;
|
||||
|
||||
/*
|
||||
* Exclusive zones
|
||||
* Each island is surrounded by an exclusive zone where only it may
|
||||
|
@ -494,6 +501,7 @@ allocate_memory(void)
|
|||
capx = calloc(nc, sizeof(int));
|
||||
capy = calloc(nc, sizeof(int));
|
||||
own = calloc(WORLD_X, sizeof(int *));
|
||||
adj_land = malloc(WORLD_SZ() * sizeof(*adj_land));
|
||||
xzone = malloc(WORLD_SZ() * sizeof(*xzone));
|
||||
elev = calloc(WORLD_X, sizeof(int *));
|
||||
for (i = 0; i < WORLD_X; ++i) {
|
||||
|
@ -530,6 +538,7 @@ init(void)
|
|||
own[i][j] = -1;
|
||||
}
|
||||
}
|
||||
memset(adj_land, 0, WORLD_SZ() * sizeof(*adj_land));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -766,6 +775,21 @@ can_grow_at(int c, int x, int y)
|
|||
return own[x][y] == -1 && xzone_ok(c, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
adj_land_update(int x, int y)
|
||||
{
|
||||
int dir, nx, ny, noff;
|
||||
|
||||
assert(own[x][y] != -1);
|
||||
|
||||
for (dir = DIR_FIRST; dir <= DIR_LAST; dir++) {
|
||||
nx = new_x(x + diroff[dir][0]);
|
||||
ny = new_y(y + diroff[dir][1]);
|
||||
noff = XYOFFSET(nx, ny);
|
||||
adj_land[noff] |= 1u << DIR_BACK(dir);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_sector(int c, int x, int y)
|
||||
{
|
||||
|
@ -775,6 +799,7 @@ add_sector(int c, int x, int y)
|
|||
secty[c][isecs[c]] = y;
|
||||
isecs[c]++;
|
||||
own[x][y] = c;
|
||||
adj_land_update(x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue