be more consistent with coordxy in mkmap.c

Also closes #1365
This commit is contained in:
nhmall
2025-01-14 10:32:36 -05:00
parent f32e32d447
commit 2354fef2d6
3 changed files with 76 additions and 78 deletions
+4 -4
View File
@@ -619,10 +619,10 @@ struct instance_globals_m {
boolean made_branch; /* used only during level creation */ boolean made_branch; /* used only during level creation */
/* mkmap.c */ /* mkmap.c */
int min_rx; /* rectangle bounds for regions */ coordxy min_rx; /* rectangle bounds for regions */
int max_rx; coordxy max_rx;
int min_ry; coordxy min_ry;
int max_ry; coordxy max_ry;
/* mkobj.c */ /* mkobj.c */
boolean mkcorpstat_norevive; /* for trolls */ boolean mkcorpstat_norevive; /* for trolls */
+2 -2
View File
@@ -1547,8 +1547,8 @@ extern void mineralize(int, int, int, int, boolean);
/* ### mkmap.c ### */ /* ### mkmap.c ### */
extern void flood_fill_rm(int, int, int, boolean, boolean); extern void flood_fill_rm(coordxy, coordxy, int, boolean, boolean);
extern void remove_rooms(int, int, int, int); extern void remove_rooms(coordxy, coordxy, coordxy, coordxy);
extern boolean litstate_rnd(int); extern boolean litstate_rnd(int);
/* ### mkmaze.c ### */ /* ### mkmaze.c ### */
+70 -72
View File
@@ -10,7 +10,7 @@
staticfn void init_map(schar); staticfn void init_map(schar);
staticfn void init_fill(schar, schar); staticfn void init_fill(schar, schar);
staticfn schar get_map(int, int, schar); staticfn schar get_map(coordxy, coordxy, schar);
staticfn void pass_one(schar, schar); staticfn void pass_one(schar, schar);
staticfn void pass_two(schar, schar); staticfn void pass_two(schar, schar);
staticfn void pass_three(schar, schar); staticfn void pass_three(schar, schar);
@@ -23,36 +23,36 @@ void mkmap(lev_init *);
staticfn void staticfn void
init_map(schar bg_typ) init_map(schar bg_typ)
{ {
int i, j; coordxy x, y;
for (i = 1; i < COLNO; i++) for (x = 1; x < COLNO; x++)
for (j = 0; j < ROWNO; j++) { for (y = 0; y < ROWNO; y++) {
levl[i][j].roomno = NO_ROOM; levl[x][y].roomno = NO_ROOM;
levl[i][j].typ = bg_typ; levl[x][y].typ = bg_typ;
levl[i][j].lit = FALSE; levl[x][y].lit = FALSE;
} }
} }
staticfn void staticfn void
init_fill(schar bg_typ, schar fg_typ) init_fill(schar bg_typ, schar fg_typ)
{ {
int i, j; coordxy x, y;
long limit, count; long limit, count;
limit = (WIDTH * HEIGHT * 2) / 5; limit = (WIDTH * HEIGHT * 2) / 5;
count = 0; count = 0;
while (count < limit) { while (count < limit) {
i = rn1(WIDTH - 1, 2); x = (coordxy) rn1(WIDTH - 1, 2);
j = rnd(HEIGHT - 1); y = (coordxy) rnd(HEIGHT - 1);
if (levl[i][j].typ == bg_typ) { if (levl[x][y].typ == bg_typ) {
levl[i][j].typ = fg_typ; levl[x][y].typ = fg_typ;
count++; count++;
} }
} }
} }
staticfn schar staticfn schar
get_map(int col, int row, schar bg_typ) get_map(coordxy col, coordxy row, schar bg_typ)
{ {
if (col <= 0 || row < 0 || col > WIDTH || row >= HEIGHT) if (col <= 0 || row < 0 || col > WIDTH || row >= HEIGHT)
return bg_typ; return bg_typ;
@@ -67,13 +67,13 @@ staticfn const int dirs[16] = {
staticfn void staticfn void
pass_one(schar bg_typ, schar fg_typ) pass_one(schar bg_typ, schar fg_typ)
{ {
int i, j; coordxy x, y;
short count, dr; short count, dr;
for (i = 2; i <= WIDTH; i++) for (x = 2; x <= WIDTH; x++)
for (j = 1; j < HEIGHT; j++) { for (y = 1; y < HEIGHT; y++) {
for (count = 0, dr = 0; dr < 8; dr++) for (count = 0, dr = 0; dr < 8; dr++)
if (get_map(i + dirs[dr * 2], j + dirs[(dr * 2) + 1], bg_typ) if (get_map(x + dirs[dr * 2], y + dirs[(dr * 2) + 1], bg_typ)
== fg_typ) == fg_typ)
count++; count++;
@@ -81,13 +81,13 @@ pass_one(schar bg_typ, schar fg_typ)
case 0: /* death */ case 0: /* death */
case 1: case 1:
case 2: case 2:
levl[i][j].typ = bg_typ; levl[x][y].typ = bg_typ;
break; break;
case 5: case 5:
case 6: case 6:
case 7: case 7:
case 8: case 8:
levl[i][j].typ = fg_typ; levl[x][y].typ = fg_typ;
break; break;
default: default:
break; break;
@@ -100,47 +100,47 @@ pass_one(schar bg_typ, schar fg_typ)
staticfn void staticfn void
pass_two(schar bg_typ, schar fg_typ) pass_two(schar bg_typ, schar fg_typ)
{ {
int i, j; coordxy x, y;
short count, dr; short count, dr;
for (i = 2; i <= WIDTH; i++) for (x = 2; x <= WIDTH; x++)
for (j = 1; j < HEIGHT; j++) { for (y = 1; y < HEIGHT; y++) {
for (count = 0, dr = 0; dr < 8; dr++) for (count = 0, dr = 0; dr < 8; dr++)
if (get_map(i + dirs[dr * 2], j + dirs[(dr * 2) + 1], bg_typ) if (get_map(x + dirs[dr * 2], y + dirs[(dr * 2) + 1], bg_typ)
== fg_typ) == fg_typ)
count++; count++;
if (count == 5) if (count == 5)
new_loc(i, j) = bg_typ; new_loc(x, y) = bg_typ;
else else
new_loc(i, j) = get_map(i, j, bg_typ); new_loc(x, y) = get_map(x, y, bg_typ);
} }
for (i = 2; i <= WIDTH; i++) for (x = 2; x <= WIDTH; x++)
for (j = 1; j < HEIGHT; j++) for (y = 1; y < HEIGHT; y++)
levl[i][j].typ = new_loc(i, j); levl[x][y].typ = new_loc(x, y);
} }
staticfn void staticfn void
pass_three(schar bg_typ, schar fg_typ) pass_three(schar bg_typ, schar fg_typ)
{ {
int i, j; coordxy x, y;
short count, dr; short count, dr;
for (i = 2; i <= WIDTH; i++) for (x = 2; x <= WIDTH; x++)
for (j = 1; j < HEIGHT; j++) { for (y = 1; y < HEIGHT; y++) {
for (count = 0, dr = 0; dr < 8; dr++) for (count = 0, dr = 0; dr < 8; dr++)
if (get_map(i + dirs[dr * 2], j + dirs[(dr * 2) + 1], bg_typ) if (get_map(x + dirs[dr * 2], y + dirs[(dr * 2) + 1], bg_typ)
== fg_typ) == fg_typ)
count++; count++;
if (count < 3) if (count < 3)
new_loc(i, j) = bg_typ; new_loc(x, y) = bg_typ;
else else
new_loc(i, j) = get_map(i, j, bg_typ); new_loc(x, y) = get_map(x, y, bg_typ);
} }
for (i = 2; i <= WIDTH; i++) for (x = 2; x <= WIDTH; x++)
for (j = 1; j < HEIGHT; j++) for (y = 1; y < HEIGHT; y++)
levl[i][j].typ = new_loc(i, j); levl[x][y].typ = new_loc(x, y);
} }
/* /*
@@ -151,14 +151,13 @@ pass_three(schar bg_typ, schar fg_typ)
*/ */
void void
flood_fill_rm( flood_fill_rm(
int sx, coordxy sx,
int sy, coordxy sy,
int rmno, int rmno,
boolean lit, boolean lit,
boolean anyroom) boolean anyroom)
{ {
int i; coordxy i, nx;
int nx;
schar fg_typ = levl[sx][sy].typ; schar fg_typ = levl[sx][sy].typ;
/* back up to find leftmost uninitialized location */ /* back up to find leftmost uninitialized location */
@@ -179,7 +178,7 @@ flood_fill_rm(
levl[i][sy].lit = lit; levl[i][sy].lit = lit;
if (anyroom) { if (anyroom) {
/* add walls to room as well */ /* add walls to room as well */
int ii, jj; coordxy ii, jj;
for (ii = (i == sx ? i - 1 : i); ii <= i + 1; ii++) for (ii = (i == sx ? i - 1 : i); ii <= i + 1; ii++)
for (jj = sy - 1; jj <= sy + 1; jj++) for (jj = sy - 1; jj <= sy + 1; jj++)
if (isok(ii, jj) && (IS_WALL(levl[ii][jj].typ) if (isok(ii, jj) && (IS_WALL(levl[ii][jj].typ)
@@ -260,19 +259,18 @@ join_map(schar bg_typ, schar fg_typ)
{ {
struct mkroom *croom, *croom2; struct mkroom *croom, *croom2;
int i, j; coordxy x, y, sx, sy;
int sx, sy;
coord sm, em; coord sm, em;
/* first, use flood filling to find all of the regions that need joining /* first, use flood filling to find all of the regions that need joining
*/ */
for (i = 2; i <= WIDTH; i++) for (x = 2; x <= WIDTH; x++)
for (j = 1; j < HEIGHT; j++) { for (y = 1; y < HEIGHT; y++) {
if (levl[i][j].typ == fg_typ && levl[i][j].roomno == NO_ROOM) { if (levl[x][y].typ == fg_typ && levl[x][y].roomno == NO_ROOM) {
gm.min_rx = gm.max_rx = i; gm.min_rx = gm.max_rx = x;
gm.min_ry = gm.max_ry = j; gm.min_ry = gm.max_ry = y;
gn.n_loc_filled = 0; gn.n_loc_filled = 0;
flood_fill_rm(i, j, svn.nroom + ROOMOFFSET, FALSE, FALSE); flood_fill_rm(x, y, svn.nroom + ROOMOFFSET, FALSE, FALSE);
if (gn.n_loc_filled > 3) { if (gn.n_loc_filled > 3) {
add_room(gm.min_rx, gm.min_ry, gm.max_rx, gm.max_ry, add_room(gm.min_rx, gm.min_ry, gm.max_rx, gm.max_ry,
FALSE, OROOM, TRUE); FALSE, OROOM, TRUE);
@@ -337,30 +335,30 @@ finish_map(
boolean walled, boolean walled,
boolean icedpools) boolean icedpools)
{ {
int i, j; coordxy x, y;
if (walled) if (walled)
wallify_map(1, 0, COLNO-1, ROWNO-1); wallify_map(1, 0, COLNO-1, ROWNO-1);
if (lit) { if (lit) {
for (i = 1; i < COLNO; i++) for (x = 1; x < COLNO; x++)
for (j = 0; j < ROWNO; j++) for (y = 0; y < ROWNO; y++)
if ((!IS_OBSTRUCTED(fg_typ) && levl[i][j].typ == fg_typ) if ((!IS_OBSTRUCTED(fg_typ) && levl[x][y].typ == fg_typ)
|| (!IS_OBSTRUCTED(bg_typ) && levl[i][j].typ == bg_typ) || (!IS_OBSTRUCTED(bg_typ) && levl[x][y].typ == bg_typ)
|| (bg_typ == TREE && levl[i][j].typ == bg_typ) || (bg_typ == TREE && levl[x][y].typ == bg_typ)
|| (walled && IS_WALL(levl[i][j].typ))) || (walled && IS_WALL(levl[x][y].typ)))
levl[i][j].lit = TRUE; levl[x][y].lit = TRUE;
for (i = 0; i < svn.nroom; i++) for (x = 0; x < svn.nroom; x++)
svr.rooms[i].rlit = 1; svr.rooms[x].rlit = 1;
} }
/* light lava even if everything's otherwise unlit; /* light lava even if everything's otherwise unlit;
ice might be frozen pool rather than frozen moat */ ice might be frozen pool rather than frozen moat */
for (i = 1; i < COLNO; i++) for (x = 1; x < COLNO; x++)
for (j = 0; j < ROWNO; j++) { for (y = 0; y < ROWNO; y++) {
if (levl[i][j].typ == LAVAPOOL) if (levl[x][y].typ == LAVAPOOL)
levl[i][j].lit = TRUE; levl[x][y].lit = TRUE;
else if (levl[i][j].typ == ICE) else if (levl[x][y].typ == ICE)
levl[i][j].icedpool = icedpools ? ICED_POOL : ICED_MOAT; levl[x][y].icedpool = icedpools ? ICED_POOL : ICED_MOAT;
} }
} }
@@ -378,7 +376,7 @@ finish_map(
* region are all set. * region are all set.
*/ */
void void
remove_rooms(int lx, int ly, int hx, int hy) remove_rooms(coordxy lx, coordxy ly, coordxy hx, coordxy hy)
{ {
int i; int i;
struct mkroom *croom; struct mkroom *croom;
@@ -415,7 +413,7 @@ remove_room(unsigned int roomno)
{ {
struct mkroom *croom = &svr.rooms[roomno]; struct mkroom *croom = &svr.rooms[roomno];
struct mkroom *maxroom = &svr.rooms[--svn.nroom]; struct mkroom *maxroom = &svr.rooms[--svn.nroom];
int i, j; coordxy x, y;
unsigned oroomno; unsigned oroomno;
if (croom != maxroom) { if (croom != maxroom) {
@@ -427,10 +425,10 @@ remove_room(unsigned int roomno)
/* since maxroom moved, update affected level roomno values */ /* since maxroom moved, update affected level roomno values */
oroomno = svn.nroom + ROOMOFFSET; oroomno = svn.nroom + ROOMOFFSET;
roomno += ROOMOFFSET; roomno += ROOMOFFSET;
for (i = croom->lx; i <= croom->hx; ++i) for (x = croom->lx; x <= croom->hx; ++x)
for (j = croom->ly; j <= croom->hy; ++j) { for (y = croom->ly; y <= croom->hy; ++y) {
if (levl[i][j].roomno == oroomno) if (levl[x][y].roomno == oroomno)
levl[i][j].roomno = roomno; levl[x][y].roomno = roomno;
} }
} }