hurtle_step() streamlining

Eliminate some code duplication in hurtling.
This commit is contained in:
PatR
2024-11-27 10:32:09 -08:00
parent 9c0e47785a
commit 5c0834e9d9

View File

@@ -676,14 +676,15 @@ walk_path(
if (dx < 0) {
x_change = -1;
dx = -dx;
} else
} else {
x_change = 1;
}
if (dy < 0) {
y_change = -1;
dy = -dy;
} else
} else {
y_change = 1;
}
i = err = 0;
if (dx < dy) {
while (i++ < dy) {
@@ -767,7 +768,8 @@ hurtle_step(genericptr_t arg, coordxy x, coordxy y)
struct monst *mon;
boolean may_pass = TRUE, via_jumping, stopping_short;
struct trap *ttmp;
int dmg = 0;
struct rm *lev;
int ltyp, dmg = 0;
if (!isok(x, y)) {
You_feel("the spirits holding you back.");
@@ -779,69 +781,52 @@ hurtle_step(genericptr_t arg, coordxy x, coordxy y)
}
via_jumping = (EWwalking & I_SPECIAL) != 0L;
stopping_short = (via_jumping && *range < 2);
lev = &levl[x][y];
ltyp = lev->typ;
if (!Passes_walls || !(may_pass = may_passwall(x, y))) {
boolean odoor_diag = (IS_DOOR(levl[x][y].typ)
&& (levl[x][y].doormask & D_ISOPEN)
&& (u.ux - x) && (u.uy - y));
if (IS_OBSTRUCTED(levl[x][y].typ) || closed_door(x, y) || odoor_diag) {
const char *s;
const char *why = NULL;
boolean diagonal = (u.ux - x) != 0 && (u.uy - y) != 0,
open_door = IS_DOOR(ltyp) && (lev->doormask & D_ISOPEN) != 0,
odoor_diag = open_door && diagonal;
if (IS_OBSTRUCTED(levl[x][y].typ)
|| closed_door(x, y) || odoor_diag) {
why = IS_TREE(ltyp) ? "bumping into a tree"
: IS_OBSTRUCTED(ltyp) ? "bumping into a wall"
: odoor_diag ? "bumping into a door frame"
: "bumping into a closed door";
if (odoor_diag)
You("hit the door edge!");
You("hit the door frame!");
pline("Ouch!");
if (IS_TREE(levl[x][y].typ))
s = "bumping into a tree";
else if (IS_OBSTRUCTED(levl[x][y].typ))
s = "bumping into a wall";
else
s = "bumping into a door";
dmg = rnd(2 + *range);
losehp(Maybe_Half_Phys(dmg), s, KILLED_BY);
wake_nearto(x,y, 10);
return FALSE;
}
if (levl[x][y].typ == IRONBARS) {
} else if (ltyp == IRONBARS) {
why = "crashing into iron bars";
You("crash into some iron bars. Ouch!");
dmg = rnd(2 + *range);
losehp(Maybe_Half_Phys(dmg), "crashing into iron bars",
KILLED_BY);
wake_nearto(x,y, 20);
return FALSE;
}
if ((obj = sobj_at(BOULDER, x, y)) != 0) {
} else if ((obj = sobj_at(BOULDER, x, y)) != 0) {
why = "bumping into a boulder";
You("bump into a %s. Ouch!", xname(obj));
dmg = rnd(2 + *range);
losehp(Maybe_Half_Phys(dmg), "bumping into a boulder", KILLED_BY);
wake_nearto(x,y, 10);
return FALSE;
}
if (!may_pass) {
} else if (!may_pass) {
/* did we hit a no-dig non-wall position? */
why = "touching the edge of the universe";
You("smack into something!");
dmg = rnd(2 + *range);
losehp(Maybe_Half_Phys(dmg), "touching the edge of the universe",
KILLED_BY);
wake_nearto(x,y, 10);
return FALSE;
}
if ((u.ux - x) && (u.uy - y) && bad_rock(gy.youmonst.data, u.ux, y)
&& bad_rock(gy.youmonst.data, x, u.uy)) {
} else if (diagonal
&& bad_rock(gy.youmonst.data, u.ux, y)
&& bad_rock(gy.youmonst.data, x, u.uy)) {
boolean too_much = (gi.invent
&& (inv_weight() + weight_cap() > 600));
/* Move at a diagonal. */
if (bigmonst(gy.youmonst.data) || too_much) {
why = "wedging into a narrow crevice";
You("%sget forcefully wedged into a crevice.",
too_much ? "and all your belongings " : "");
dmg = rnd(2 + *range);
losehp(Maybe_Half_Phys(dmg), "wedging into a narrow crevice",
KILLED_BY);
wake_nearto(x,y, 10);
return FALSE;
}
}
if (why) {
dmg = rnd(2 + *range);
losehp(Maybe_Half_Phys(dmg), why, KILLED_BY);
wake_nearto(x, y, 10);
return FALSE;
}
}
if ((mon = m_at(x, y)) != 0
@@ -918,7 +903,7 @@ hurtle_step(genericptr_t arg, coordxy x, coordxy y)
/* if terrain type changes, levitation or flying might become blocked
or unblocked; might issue message, so do this after map+vision has
been updated for new location instead of right after u_on_newpos() */
if (levl[u.ux][u.uy].typ != levl[ox][oy].typ)
if (ltyp != levl[ox][oy].typ)
switch_terrain();
/* might be entering a special room (treasure zoo, thrown room, &c) that
@@ -957,8 +942,7 @@ hurtle_step(genericptr_t arg, coordxy x, coordxy y)
dotrap(ttmp, NO_TRAP_FLAGS); /* doesn't print messages */
} else if (ttmp->ttyp == FIRE_TRAP) {
dotrap(ttmp, NO_TRAP_FLAGS);
} else if ((is_pit(ttmp->ttyp) || is_hole(ttmp->ttyp))
&& Sokoban) {
} else if ((is_pit(ttmp->ttyp) || is_hole(ttmp->ttyp)) && Sokoban) {
/* air currents overcome the recoil in Sokoban;
when jumping, caller performs last step and enters trap */
if (!via_jumping)