some coordxy follow-up

Return a couple of variables that actually held a direction back
to int from coordxy.

bhit() takes int params instead of coordxy.

boomhit() takes int params instead of coordxy.

xytod() renamed to xytodir(), and takes int params (promotion will handle
coordxy params).

dtoxy(coord *, int) renamed to dirtocoord(coord *, int).
This commit is contained in:
nhmall
2026-02-11 09:40:25 -05:00
parent db36ee35de
commit fcd9f5468c
12 changed files with 36 additions and 36 deletions
+4 -4
View File
@@ -449,8 +449,8 @@ extern int enter_explore_mode(void);
extern boolean bind_mousebtn(int, const char *); extern boolean bind_mousebtn(int, const char *);
extern boolean bind_key(uchar, const char *); extern boolean bind_key(uchar, const char *);
extern void dokeylist(void); extern void dokeylist(void);
extern int xytod(coordxy, coordxy); extern int xytodir(int, int);
extern void dtoxy(coord *, int); extern void dirtocoord(coord *, int);
extern int movecmd(char, int); extern int movecmd(char, int);
extern int dxdy_moveok(void); extern int dxdy_moveok(void);
extern int getdir(const char *); extern int getdir(const char *);
@@ -3957,11 +3957,11 @@ extern int spell_damage_bonus(int);
extern const char *exclam(int force) NONNULL; extern const char *exclam(int force) NONNULL;
extern void hit(const char *, struct monst *, const char *) NONNULLPTRS; extern void hit(const char *, struct monst *, const char *) NONNULLPTRS;
extern void miss(const char *, struct monst *) NONNULLPTRS; extern void miss(const char *, struct monst *) NONNULLPTRS;
extern struct monst *bhit(coordxy, coordxy, int, enum bhit_call_types, extern struct monst *bhit(int, int, int, enum bhit_call_types,
int(*)(struct monst *, struct obj *), int(*)(struct monst *, struct obj *),
int(*)(struct obj *, struct obj *), int(*)(struct obj *, struct obj *),
struct obj **) NONNULLARG7; struct obj **) NONNULLARG7;
extern struct monst *boomhit(struct obj *, coordxy, coordxy) NONNULLARG1; extern struct monst *boomhit(struct obj *, int, int) NONNULLARG1;
extern int zhitm(struct monst *, int, int, struct obj **) NONNULLPTRS; extern int zhitm(struct monst *, int, int, struct obj **) NONNULLPTRS;
extern int burn_floor_objects(coordxy, coordxy, boolean, boolean); extern int burn_floor_objects(coordxy, coordxy, boolean, boolean);
extern void ubuzz(int, int); extern void ubuzz(int, int);
+8 -8
View File
@@ -3615,7 +3615,7 @@ rhack(int key)
/* convert an x,y pair into a direction code */ /* convert an x,y pair into a direction code */
int int
xytod(coordxy x, coordxy y) xytodir(int x, int y)
{ {
int dd; int dd;
@@ -3627,7 +3627,7 @@ xytod(coordxy x, coordxy y)
/* convert a direction code into an x,y pair */ /* convert a direction code into an x,y pair */
void void
dtoxy(coord *cc, int dd) dirtocoord(coord *cc, int dd)
{ {
if (dd > DIR_ERR && dd < N_DIRS_Z) { if (dd > DIR_ERR && dd < N_DIRS_Z) {
cc->x = xdir[dd]; cc->x = xdir[dd];
@@ -3733,7 +3733,7 @@ getdir(const char *s)
if (cmdq) { if (cmdq) {
if (cmdq->typ == CMDQ_DIR) { if (cmdq->typ == CMDQ_DIR) {
if (!cmdq->dirz) { if (!cmdq->dirz) {
dirsym = gc.Cmd.dirchars[xytod(cmdq->dirx, cmdq->diry)]; dirsym = gc.Cmd.dirchars[xytodir(cmdq->dirx, cmdq->diry)];
} else { } else {
dirsym = gc.Cmd.dirchars[(cmdq->dirz > 0) ? DIR_DOWN dirsym = gc.Cmd.dirchars[(cmdq->dirz > 0) ? DIR_DOWN
: DIR_UP]; : DIR_UP];
@@ -4501,7 +4501,7 @@ act_on_act(
cmdq_add_dir(CQ_CANNED, dx, dy, 0); cmdq_add_dir(CQ_CANNED, dx, dy, 0);
break; break;
case MCMD_MOVE_DIR: case MCMD_MOVE_DIR:
dir = xytod(dx, dy); dir = xytodir(dx, dy);
cmdq_add_ec(CQ_CANNED, move_funcs[dir][MV_WALK]); cmdq_add_ec(CQ_CANNED, move_funcs[dir][MV_WALK]);
break; break;
case MCMD_RIDE: case MCMD_RIDE:
@@ -4523,7 +4523,7 @@ act_on_act(
} }
break; break;
case MCMD_ATTACK_NEXT2U: case MCMD_ATTACK_NEXT2U:
dir = xytod(dx, dy); dir = xytodir(dx, dy);
cmdq_add_ec(CQ_CANNED, move_funcs[dir][MV_WALK]); cmdq_add_ec(CQ_CANNED, move_funcs[dir][MV_WALK]);
break; break;
case MCMD_TALK: case MCMD_TALK:
@@ -4633,7 +4633,7 @@ there_cmd_menu(coordxy x, coordxy y, int mod)
if (!K) { if (!K) {
/* no menu options, try to move */ /* no menu options, try to move */
if (next2u(x, y) && test_move(u.ux, u.uy, dx, dy, TEST_MOVE)) { if (next2u(x, y) && test_move(u.ux, u.uy, dx, dy, TEST_MOVE)) {
int dir = xytod(dx, dy); int dir = xytodir(dx, dy);
cmdq_add_ec(CQ_CANNED, move_funcs[dir][MV_WALK]); cmdq_add_ec(CQ_CANNED, move_funcs[dir][MV_WALK]);
} else if (flags.travelcmd) { } else if (flags.travelcmd) {
@@ -4727,7 +4727,7 @@ domouseaction(void)
/* directional commands */ /* directional commands */
dir = xytod(x, y); dir = xytodir(x, y);
if (!m_at(u.ux + x, u.uy + y) if (!m_at(u.ux + x, u.uy + y)
&& !test_move(u.ux, u.uy, x, y, TEST_MOVE)) { && !test_move(u.ux, u.uy, x, y, TEST_MOVE)) {
if (IS_DOOR(levl[u.ux + x][u.uy + y].typ)) { if (IS_DOOR(levl[u.ux + x][u.uy + y].typ)) {
@@ -4766,7 +4766,7 @@ domouseaction(void)
cmdq_add_ec(CQ_CANNED, donull); cmdq_add_ec(CQ_CANNED, donull);
return ECMD_OK; return ECMD_OK;
} }
dir = xytod(x, y); dir = xytodir(x, y);
} }
/* move, attack, etc. */ /* move, attack, etc. */
+2 -2
View File
@@ -1256,7 +1256,7 @@ use_pick_axe2(struct obj *obj)
&& (trap_with_u = t_at(u.ux, u.uy)) && (trap_with_u = t_at(u.ux, u.uy))
&& is_pit(trap->ttyp) && is_pit(trap->ttyp)
&& !conjoined_pits(trap, trap_with_u, FALSE)) { && !conjoined_pits(trap, trap_with_u, FALSE)) {
int idx = xytod(u.dx, u.dy); int idx = xytodir(u.dx, u.dy);
if (idx != DIR_ERR) { if (idx != DIR_ERR) {
int adjidx = DIR_180(idx); int adjidx = DIR_180(idx);
@@ -1617,7 +1617,7 @@ zap_dig(void)
if (u.utrap && u.utraptype == TT_PIT if (u.utrap && u.utraptype == TT_PIT
&& (trap_with_u = t_at(u.ux, u.uy))) { && (trap_with_u = t_at(u.ux, u.uy))) {
pitdig = TRUE; pitdig = TRUE;
diridx = xytod(u.dx, u.dy); diridx = xytodir(u.dx, u.dy);
} }
digdepth = rn1(18, 8); digdepth = rn1(18, 8);
tmp_at(DISP_BEAM, cmap_to_glyph(S_digbeam)); tmp_at(DISP_BEAM, cmap_to_glyph(S_digbeam));
+3 -3
View File
@@ -1325,14 +1325,14 @@ dog_move(
if (goodpos(cc.x, cc.y, mtmp, 0)) if (goodpos(cc.x, cc.y, mtmp, 0))
goto dognext; goto dognext;
i = xytod(nx, ny); i = xytodir(nx, ny);
for (j = DIR_LEFT(i); j < DIR_RIGHT(i); j++) { for (j = DIR_LEFT(i); j < DIR_RIGHT(i); j++) {
dtoxy(&cc, j); dirtocoord(&cc, j);
if (goodpos(cc.x, cc.y, mtmp, 0)) if (goodpos(cc.x, cc.y, mtmp, 0))
goto dognext; goto dognext;
} }
for (j = DIR_LEFT2(i); j < DIR_RIGHT2(i); j++) { for (j = DIR_LEFT2(i); j < DIR_RIGHT2(i); j++) {
dtoxy(&cc, j); dirtocoord(&cc, j);
if (goodpos(cc.x, cc.y, mtmp, 0)) if (goodpos(cc.x, cc.y, mtmp, 0))
goto dognext; goto dognext;
} }
+1 -1
View File
@@ -561,7 +561,7 @@ dxdy_to_dist_descr(coordxy dx, coordxy dy, boolean fulldir)
if (!dx && !dy) { if (!dx && !dy) {
Sprintf(buf, "here"); Sprintf(buf, "here");
} else if ((dst = xytod(dx, dy)) != -1) { } else if ((dst = xytodir(dx, dy)) != -1) {
/* explicit direction; 'one step' is implicit */ /* explicit direction; 'one step' is implicit */
Sprintf(buf, "%s", directionname(dst)); Sprintf(buf, "%s", directionname(dst));
} else { } else {
+3 -3
View File
@@ -1046,7 +1046,7 @@ test_move(
else else
Sprintf(buf, "impossible [background glyph=%d]", Sprintf(buf, "impossible [background glyph=%d]",
glyph); glyph);
pline_dir(xytod(dx, dy), "It's %s.", buf); pline_dir(xytodir(dx, dy), "It's %s.", buf);
} }
} }
return FALSE; return FALSE;
@@ -1197,7 +1197,7 @@ test_move(
if (mode != TEST_TRAV && svc.context.run >= 2 if (mode != TEST_TRAV && svc.context.run >= 2
&& !(Blind || Hallucination) && !could_move_onto_boulder(x, y)) { && !(Blind || Hallucination) && !could_move_onto_boulder(x, y)) {
if (mode == DO_MOVE && flags.mention_walls) if (mode == DO_MOVE && flags.mention_walls)
pline_dir(xytod(dx,dy), "A boulder blocks your path."); pline_dir(xytodir(dx,dy), "A boulder blocks your path.");
return FALSE; return FALSE;
} }
if (mode == DO_MOVE) { if (mode == DO_MOVE) {
@@ -2582,7 +2582,7 @@ move_out_of_bounds(coordxy x, coordxy y)
dy = 0; dy = 0;
} }
You("have already gone as far %s as possible.", You("have already gone as far %s as possible.",
directionname(xytod(dx, dy))); directionname(xytodir(dx, dy)));
} }
nomul(0); nomul(0);
svc.context.move = 0; svc.context.move = 0;
+3 -3
View File
@@ -1348,14 +1348,14 @@ hero_behind_chokepoint(struct monst *mtmp)
coordxy x = mtmp->mux + dx; coordxy x = mtmp->mux + dx;
coordxy y = mtmp->muy + dy; coordxy y = mtmp->muy + dy;
int dir = xytod(dx, dy); int dir = xytodir(dx, dy);
int dir_l = DIR_CLAMP(DIR_LEFT2(dir)); int dir_l = DIR_CLAMP(DIR_LEFT2(dir));
int dir_r = DIR_CLAMP(DIR_RIGHT2(dir)); int dir_r = DIR_CLAMP(DIR_RIGHT2(dir));
coord c1, c2; coord c1, c2;
dtoxy(&c1, dir_l); dirtocoord(&c1, dir_l);
dtoxy(&c2, dir_r); dirtocoord(&c2, dir_r);
c1.x += x, c2.x += x; c1.x += x, c2.x += x;
c1.y += y, c2.y += y; c1.y += y, c2.y += y;
+1 -1
View File
@@ -83,7 +83,7 @@ putmesg(const char *line)
void void
set_msg_dir(int dir) set_msg_dir(int dir)
{ {
dtoxy(&a11y.msg_loc, dir); dirtocoord(&a11y.msg_loc, dir);
a11y.msg_loc.x += u.ux; a11y.msg_loc.x += u.ux;
a11y.msg_loc.y += u.uy; a11y.msg_loc.y += u.uy;
} }
+4 -4
View File
@@ -471,7 +471,7 @@ landing_spot(
(void) memset((genericptr_t) try, 0, sizeof try); (void) memset((genericptr_t) try, 0, sizeof try);
n = 0; n = 0;
j = xytod(u.dx, u.dy); j = xytodir(u.dx, u.dy);
if (reason == DISMOUNT_KNOCKED && j != DIR_ERR) { if (reason == DISMOUNT_KNOCKED && j != DIR_ERR) {
/* we'll check preferred location first; if viable it'll be picked */ /* we'll check preferred location first; if viable it'll be picked */
best_j = j; best_j = j;
@@ -479,10 +479,10 @@ landing_spot(
/* the two next best locations are checked second and third */ /* the two next best locations are checked second and third */
i = rn2(2); i = rn2(2);
clockwise_j = DIR_RIGHT(j); /* (j + 1) % 8 */ clockwise_j = DIR_RIGHT(j); /* (j + 1) % 8 */
dtoxy(&cc, clockwise_j); dirtocoord(&cc, clockwise_j);
try[1 + i].x = cc.x, try[1 + i].y = cc.y; /* [1] or [2] */ try[1 + i].x = cc.x, try[1 + i].y = cc.y; /* [1] or [2] */
counterclk_j = DIR_LEFT(j); /* (j + 8 - 1) % 8 */ counterclk_j = DIR_LEFT(j); /* (j + 8 - 1) % 8 */
dtoxy(&cc, counterclk_j); dirtocoord(&cc, counterclk_j);
try[2 - i].x = cc.x, try[2 - i].y = cc.y; /* [2] or [1] */ try[2 - i].x = cc.x, try[2 - i].y = cc.y; /* [2] or [1] */
n = 3; n = 3;
debugpline3("knock from saddle: best %s, next %s or %s", debugpline3("knock from saddle: best %s, next %s or %s",
@@ -500,7 +500,7 @@ landing_spot(
so odd j values are diagonal directions here */ so odd j values are diagonal directions here */
if (reason == DISMOUNT_POLY && NODIAG(u.umonnum) && (j % 1) != 0) if (reason == DISMOUNT_POLY && NODIAG(u.umonnum) && (j % 1) != 0)
continue; continue;
dtoxy(&cc, j); dirtocoord(&cc, j);
try[n++] = cc; try[n++] = cc;
} }
+2 -2
View File
@@ -6473,7 +6473,7 @@ conjoined_pits(
return FALSE; return FALSE;
dx = sgn(trap2->tx - trap1->tx); dx = sgn(trap2->tx - trap1->tx);
dy = sgn(trap2->ty - trap1->ty); dy = sgn(trap2->ty - trap1->ty);
diridx = xytod(dx, dy); diridx = xytodir(dx, dy);
if (diridx != DIR_ERR) { if (diridx != DIR_ERR) {
adjidx = DIR_180(diridx); adjidx = DIR_180(diridx);
if ((trap1->conjoined & (1 << diridx)) if ((trap1->conjoined & (1 << diridx))
@@ -6514,7 +6514,7 @@ adj_nonconjoined_pit(struct trap *adjtrap)
if (trap_with_u && adjtrap && u.utrap && u.utraptype == TT_PIT if (trap_with_u && adjtrap && u.utrap && u.utraptype == TT_PIT
&& is_pit(trap_with_u->ttyp) && is_pit(adjtrap->ttyp)) { && is_pit(trap_with_u->ttyp) && is_pit(adjtrap->ttyp)) {
if (xytod(u.dx, u.dy) != DIR_ERR) if (xytodir(u.dx, u.dy) != DIR_ERR)
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
+1 -1
View File
@@ -663,7 +663,7 @@ hitum_cleave(
int count, umort, x = u.ux, y = u.uy; int count, umort, x = u.ux, y = u.uy;
/* find the direction toward primary target */ /* find the direction toward primary target */
i = xytod(u.dx, u.dy); i = xytodir(u.dx, u.dy);
if (i == DIR_ERR) { if (i == DIR_ERR) {
impossible("hitum_cleave: unknown target direction [%d,%d,%d]?", impossible("hitum_cleave: unknown target direction [%d,%d,%d]?",
u.dx, u.dy, u.dz); u.dx, u.dy, u.dz);
+4 -4
View File
@@ -3814,7 +3814,7 @@ zap_map(
*/ */
struct monst * struct monst *
bhit( bhit(
coordxy ddx, coordxy ddy, int range, /* direction and range */ int ddx, int ddy, int range, /* direction and range */
enum bhit_call_types weapon, /* defined in hack.h */ enum bhit_call_types weapon, /* defined in hack.h */
int (*fhitm)(MONST_P, OBJ_P), /* fns called when mon/obj hit */ int (*fhitm)(MONST_P, OBJ_P), /* fns called when mon/obj hit */
int (*fhito)(OBJ_P, OBJ_P), int (*fhito)(OBJ_P, OBJ_P),
@@ -4134,7 +4134,7 @@ bhit(
* is too obviously silly. * is too obviously silly.
*/ */
struct monst * struct monst *
boomhit(struct obj *obj, coordxy dx, coordxy dy) boomhit(struct obj *obj, int dx, int dy)
{ {
int i, ct; int i, ct;
int boom; /* showsym[] index */ int boom; /* showsym[] index */
@@ -4158,7 +4158,7 @@ boomhit(struct obj *obj, coordxy dx, coordxy dy)
gb.bhitpos.x = u.ux; gb.bhitpos.x = u.ux;
gb.bhitpos.y = u.uy; gb.bhitpos.y = u.uy;
boom = counterclockwise ? S_boomleft : S_boomright; boom = counterclockwise ? S_boomleft : S_boomright;
i = xytod(dx, dy); i = xytodir(dx, dy);
tmp_at(DISP_FLASH, cmap_to_glyph(boom)); tmp_at(DISP_FLASH, cmap_to_glyph(boom));
for (ct = 0; ct < 10; ct++) { for (ct = 0; ct < 10; ct++) {
i = DIR_CLAMP(i); i = DIR_CLAMP(i);
@@ -4947,7 +4947,7 @@ dobuzz(
goto buzzmonst; goto buzzmonst;
} else if (zap_hit((int) u.uac, 0)) { } else if (zap_hit((int) u.uac, 0)) {
range -= 2; range -= 2;
pline_dir(xytod(-dx, -dy), "%s hits you!", pline_dir(xytodir(-dx, -dy), "%s hits you!",
The(flash_str(fltyp, FALSE))); The(flash_str(fltyp, FALSE)));
if (Reflecting) { if (Reflecting) {
if (!Blind) { if (!Blind) {