Unify pet and monster digging item checks

This commit is contained in:
Pasi Kallinen
2016-05-19 18:46:25 +03:00
parent de716ec533
commit 0db1e1ca38
3 changed files with 39 additions and 33 deletions

View File

@@ -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));

View File

@@ -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);

View File

@@ -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.