From: Pasi Kallinen Date: Fri, 25 Feb 2022 12:54:33 +0000 (+0200) Subject: Split force-fight iron bars code out of domove X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b521aa955f77e37588ed2f1d295ec2d6009926d;p=nethack Split force-fight iron bars code out of domove --- diff --git a/src/hack.c b/src/hack.c index fa123691d..b07b2feaf 100644 --- a/src/hack.c +++ b/src/hack.c @@ -17,6 +17,7 @@ static schar u_simple_floortyp(xchar, xchar); static boolean swim_move_danger(xchar, xchar); static boolean domove_bump_mon(struct monst *, int); static boolean domove_attackmon_at(struct monst *, xchar, xchar, boolean *); +static boolean domove_fight_ironbars(xchar, xchar); static void domove_core(void); static void maybe_smudge_engr(int, int, int, int); static struct monst *monstinroom(struct permonst *, int); @@ -1657,6 +1658,31 @@ domove_attackmon_at(struct monst *mtmp, xchar x, xchar y, boolean *displaceu) return FALSE; } +/* force-fight iron bars with your weapon? */ +static boolean +domove_fight_ironbars(xchar x, xchar y) +{ + if (g.context.forcefight && levl[x][y].typ == IRONBARS && uwep) { + struct obj *obj = uwep; + unsigned breakflags = (BRK_BY_HERO | BRK_FROM_INV); + + if (breaktest(obj)) { + if (obj->quan > 1L) + obj = splitobj(obj, 1L); + else + setuwep((struct obj *)0); + freeinv(obj); + breakflags |= BRK_KNOWN2BREAK; + } else { + breakflags |= BRK_KNOWN2NOTBREAK; + } + + hit_bars(&obj, u.ux, u.uy, x, y, breakflags); + return TRUE; + } + return FALSE; +} + void domove(void) { @@ -1912,24 +1938,8 @@ domove_core(void) return; } - if (g.context.forcefight && levl[x][y].typ == IRONBARS && uwep) { - struct obj *obj = uwep; - unsigned breakflags = (BRK_BY_HERO | BRK_FROM_INV); - - if (breaktest(obj)) { - if (obj->quan > 1L) - obj = splitobj(obj, 1L); - else - setuwep((struct obj *)0); - freeinv(obj); - breakflags |= BRK_KNOWN2BREAK; - } else { - breakflags |= BRK_KNOWN2NOTBREAK; - } - - hit_bars(&obj, u.ux, u.uy, x, y, breakflags); + if (domove_fight_ironbars(x, y)) return; - } /* specifying 'F' with no monster wastes a turn */ if (g.context.forcefight