From: Pasi Kallinen Date: Thu, 19 May 2016 15:46:25 +0000 (+0300) Subject: Unify pet and monster digging item checks X-Git-Tag: NetHack-3.6.1_RC01~761 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0db1e1ca38e5692dd153c84b5e2cae2dd6b4d311;p=nethack Unify pet and monster digging item checks --- diff --git a/include/extern.h b/include/extern.h index 3905c3382..41b024d23 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1420,6 +1420,7 @@ E boolean FDECL(onscary, (int, int, struct monst *)); E void FDECL(monflee, (struct monst *, int, BOOLEAN_P, BOOLEAN_P)); E void FDECL(mon_yells, (struct monst *, const char *)); E int FDECL(dochug, (struct monst *)); +E boolean FDECL(m_digweapon_check, (struct monst *, XCHAR_P, XCHAR_P)); E int FDECL(m_move, (struct monst *, int)); E void FDECL(dissolve_bars, (int, int)); E boolean FDECL(closed_door, (int, int)); diff --git a/src/dogmove.c b/src/dogmove.c index 34fa4a2cd..0ab7994ea 100644 --- a/src/dogmove.c +++ b/src/dogmove.c @@ -888,23 +888,9 @@ newdogpos: } if (!m_in_out_region(mtmp, nix, niy)) return 1; - if (((IS_ROCK(levl[nix][niy].typ) && may_dig(nix, niy)) - || closed_door(nix, niy)) - && mtmp->weapon_check != NO_WEAPON_WANTED - && tunnels(mtmp->data) && needspick(mtmp->data)) { - if (closed_door(nix, niy)) { - if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp) - || !is_axe(mw_tmp)) - mtmp->weapon_check = NEED_PICK_OR_AXE; - } else if (IS_TREE(levl[nix][niy].typ)) { - if (!(mw_tmp = MON_WEP(mtmp)) || !is_axe(mw_tmp)) - mtmp->weapon_check = NEED_AXE; - } else if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp)) { - mtmp->weapon_check = NEED_PICK_AXE; - } - if (mtmp->weapon_check >= NEED_PICK_AXE && mon_wield_item(mtmp)) - return 0; - } + if (m_digweapon_check(mtmp, nix,niy)) + return 0; + /* insert a worm_move() if worms ever begin to eat things */ wasseen = canseemon(mtmp); remove_monster(omx, omy); diff --git a/src/monmove.c b/src/monmove.c index 964db35ee..a5871c126 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -705,6 +705,38 @@ xchar gx, gy; return FALSE; } +boolean +m_digweapon_check(mtmp, nix, niy) +struct monst *mtmp; +xchar nix,niy; +{ + boolean can_tunnel = 0; + struct obj *mw_tmp; + + if (!Is_rogue_level(&u.uz)) + can_tunnel = tunnels(mtmp->data); + + if (can_tunnel && needspick(mtmp->data) + && mtmp->weapon_check != NO_WEAPON_WANTED + && ((IS_ROCK(levl[nix][niy].typ) && may_dig(nix, niy)) + || closed_door(nix, niy))) { + if (closed_door(nix, niy)) { + if (!(mw_tmp = MON_WEP(mtmp)) + || !is_pick(mw_tmp) + || !is_axe(mw_tmp)) + mtmp->weapon_check = NEED_PICK_OR_AXE; + } else if (IS_TREE(levl[nix][niy].typ)) { + if (!(mw_tmp = MON_WEP(mtmp)) || !is_axe(mw_tmp)) + mtmp->weapon_check = NEED_AXE; + } else if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp)) { + mtmp->weapon_check = NEED_PICK_AXE; + } + if (mtmp->weapon_check >= NEED_PICK_AXE && mon_wield_item(mtmp)) + return TRUE; + } + return FALSE; +} + /* Return values: * 0: did not move, but can still attack and do other stuff. * 1: moved, possibly can attack. @@ -1108,22 +1140,9 @@ not_special: if (mmoved == 1 && (u.ux != nix || u.uy != niy) && itsstuck(mtmp)) return 3; - if (mmoved == 1 && can_tunnel && needspick(ptr) - && ((IS_ROCK(levl[nix][niy].typ) && may_dig(nix, niy)) - || closed_door(nix, niy))) { - if (closed_door(nix, niy)) { - if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp) - || !is_axe(mw_tmp)) - mtmp->weapon_check = NEED_PICK_OR_AXE; - } else if (IS_TREE(levl[nix][niy].typ)) { - if (!(mw_tmp = MON_WEP(mtmp)) || !is_axe(mw_tmp)) - mtmp->weapon_check = NEED_AXE; - } else if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp)) { - mtmp->weapon_check = NEED_PICK_AXE; - } - if (mtmp->weapon_check >= NEED_PICK_AXE && mon_wield_item(mtmp)) - return 3; - } + if (mmoved == 1 && m_digweapon_check(mtmp, nix,niy)) + return 3; + /* If ALLOW_U is set, either it's trying to attack you, or it * thinks it is. In either case, attack this spot in preference to * all others.