fairland: De-duplicate map from elevation to sector type
Both write_sects() and map_symbol() map from elevation to sector type. Factor out as elev_to_sct_type(). Inline map_symbol() into output() and simplify. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
db71fa497c
commit
b53ecacf40
1 changed files with 31 additions and 32 deletions
|
@ -218,7 +218,6 @@ static int write_newcap_script(void);
|
||||||
static int stable(void);
|
static int stable(void);
|
||||||
static void elevate_land(void);
|
static void elevate_land(void);
|
||||||
static void elevate_sea(void);
|
static void elevate_sea(void);
|
||||||
static int map_symbol(int x, int y);
|
|
||||||
static void set_coastal_flags(void);
|
static void set_coastal_flags(void);
|
||||||
|
|
||||||
static void print_vars(void);
|
static void print_vars(void);
|
||||||
|
@ -1028,6 +1027,20 @@ elevate_sea(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
elev_to_sct_type(int elevation)
|
||||||
|
{
|
||||||
|
if (elevation < LANDMIN)
|
||||||
|
return SCT_WATER;
|
||||||
|
if (elevation < HILLMIN)
|
||||||
|
return SCT_RURAL;
|
||||||
|
if (elevation < PLATMIN)
|
||||||
|
return SCT_MOUNT;
|
||||||
|
if (elevation < HIGHMIN)
|
||||||
|
return SCT_RURAL;
|
||||||
|
return SCT_MOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
ADD THE RESOURCES
|
ADD THE RESOURCES
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -1113,23 +1126,13 @@ static void
|
||||||
write_sects(void)
|
write_sects(void)
|
||||||
{
|
{
|
||||||
struct sctstr *sct;
|
struct sctstr *sct;
|
||||||
int x, y, total;
|
int x, y;
|
||||||
|
|
||||||
for (y = 0; y < WORLD_Y; y++) {
|
for (y = 0; y < WORLD_Y; y++) {
|
||||||
for (x = y % 2; x < WORLD_X; x += 2) {
|
for (x = y % 2; x < WORLD_X; x += 2) {
|
||||||
sct = getsectp(x, y);
|
sct = getsectp(x, y);
|
||||||
total = elev[x][y];
|
sct->sct_elev = elev[x][y];
|
||||||
if (total < LANDMIN) {
|
sct->sct_type = elev_to_sct_type(elev[x][y]);
|
||||||
sct->sct_type = SCT_WATER;
|
|
||||||
} else if (total < HILLMIN)
|
|
||||||
sct->sct_type = SCT_RURAL;
|
|
||||||
else if (total < PLATMIN)
|
|
||||||
sct->sct_type = SCT_MOUNT;
|
|
||||||
else if (total < HIGHMIN)
|
|
||||||
sct->sct_type = SCT_RURAL;
|
|
||||||
else
|
|
||||||
sct->sct_type = SCT_MOUNT;
|
|
||||||
sct->sct_elev = total;
|
|
||||||
sct->sct_newtype = sct->sct_type;
|
sct->sct_newtype = sct->sct_type;
|
||||||
sct->sct_dterr = own[sct->sct_x][y] + 1;
|
sct->sct_dterr = own[sct->sct_x][y] + 1;
|
||||||
add_resources(sct);
|
add_resources(sct);
|
||||||
|
@ -1144,7 +1147,7 @@ write_sects(void)
|
||||||
static void
|
static void
|
||||||
output(void)
|
output(void)
|
||||||
{
|
{
|
||||||
int sx, sy, x, y;
|
int sx, sy, x, y, c, type;
|
||||||
|
|
||||||
if (quiet == 0) {
|
if (quiet == 0) {
|
||||||
for (sy = -WORLD_Y / 2; sy < WORLD_Y / 2; sy++) {
|
for (sy = -WORLD_Y / 2; sy < WORLD_Y / 2; sy++) {
|
||||||
|
@ -1154,31 +1157,27 @@ output(void)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
for (sx = -WORLD_X / 2 + y % 2; sx < WORLD_X / 2; sx += 2) {
|
for (sx = -WORLD_X / 2 + y % 2; sx < WORLD_X / 2; sx += 2) {
|
||||||
x = XNORM(sx);
|
x = XNORM(sx);
|
||||||
if (own[x][y] == -1)
|
c = own[x][y];
|
||||||
|
type = elev_to_sct_type(elev[x][y]);
|
||||||
|
if (type == SCT_WATER)
|
||||||
printf(". ");
|
printf(". ");
|
||||||
|
else if (type == SCT_MOUNT)
|
||||||
|
printf("^ ");
|
||||||
|
else if (c >= nc)
|
||||||
|
printf("%% ");
|
||||||
else {
|
else {
|
||||||
printf("%c ", map_symbol(x, y));
|
assert(0 <= c && c < nc);
|
||||||
|
if ((x == capx[c] || x == new_x(capx[c] + 2))
|
||||||
|
&& y == capy[c])
|
||||||
|
printf("%c ", numletter[c % 62]);
|
||||||
|
else
|
||||||
|
printf("# ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
map_symbol(int x, int y)
|
|
||||||
{
|
|
||||||
int c;
|
|
||||||
|
|
||||||
for (c = 0; c < nc; ++c)
|
|
||||||
if ((x == capx[c] && y == capy[c])
|
|
||||||
|| (x == new_x(capx[c] + 2) && y == capy[c]))
|
|
||||||
return numletter[own[x][y] % 62];
|
|
||||||
if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN)
|
|
||||||
|| elev[x][y] >= HIGHMIN)
|
|
||||||
return '^';
|
|
||||||
return own[x][y] >= nc ? '%' : '#';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print a map to help visualize own[][].
|
* Print a map to help visualize own[][].
|
||||||
* This is for debugging.
|
* This is for debugging.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue