Skip to content

Commit

Permalink
monster polearm usage (trunk only)
Browse files Browse the repository at this point in the history
     From newsgroup discussion, reproduced with current dev code (the
missing capitalization is a post-3.4.3 buglet):

  The orc tries to wield a halberd.
  the orc's bow is welded to her hand!
  The orc thrusts a halberd.  You are almost hit by a halberd.

Caused by overloading polearm attacks with throwing.  The monster throwing
code didn't enforce that a polearm must be successfully wielded.
  • Loading branch information
nethack.rankin committed Jun 9, 2007
1 parent 8a1d074 commit 8dbbd1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/fixes35.0
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ fix sequencing issues with dropping #invoked Heart of Ahriman
applying an unpaid stack of potions of oil forced hero to buy all of them
instead of just the one which got split off and lit
sometimes when hero is forced to buy an unpaid shop item its price changed
monster could attack with a polearm even after attempt to wield that failed


Platform- and/or Interface-Specific Fixes
Expand Down
3 changes: 2 additions & 1 deletion src/mthrowu.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SCCS Id: @(#)mthrowu.c 3.5 2007/03/17 */
/* SCCS Id: @(#)mthrowu.c 3.5 2007/06/07 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */

Expand Down Expand Up @@ -499,6 +499,7 @@ struct monst *mtmp;
if (is_pole(otmp)) {
int dam, hitv;

if (otmp != MON_WEP(mtmp)) return; /* polearm must be wielded */
if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) > POLE_LIM ||
!couldsee(mtmp->mx, mtmp->my))
return; /* Out of range, or intervening wall */
Expand Down
17 changes: 13 additions & 4 deletions src/weapon.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ select_rwep(mtmp) /* select a ranged weapon for the monster */
register struct monst *mtmp;
{
register struct obj *otmp;
struct obj *mwep;
boolean mweponly;
int i;

#ifdef KOPS
Expand All @@ -399,13 +401,19 @@ register struct monst *mtmp;
if(throws_rocks(mtmp->data)) /* ...boulders for giants */
Oselect(BOULDER);

/* Select polearms first; they do more damage and aren't expendable */
/* Select polearms first; they do more damage and aren't expendable.
But don't pick one if monster's weapon is welded, because then
we'd never have a chance to throw non-wielding missiles. */
/* The limit of 13 here is based on the monster polearm range limit
* (defined as 5 in mthrowu.c). 5 corresponds to a distance of 2 in
* one direction and 1 in another; one space beyond that would be 3 in
* one direction and 2 in another; 3^2+2^2=13.
*/
if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 13 && couldsee(mtmp->mx, mtmp->my)) {
mwep = MON_WEP(mtmp);
/* NO_WEAPON_WANTED means we already tried to wield and failed */
mweponly = (mwelded(mwep) && mtmp->weapon_check == NO_WEAPON_WANTED);
if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 13 &&
couldsee(mtmp->mx, mtmp->my)) {
for (i = 0; i < SIZE(pwep); i++) {
/* Only strong monsters can wield big (esp. long) weapons.
* Big weapon is basically the same as bimanual.
Expand All @@ -415,7 +423,8 @@ register struct monst *mtmp;
|| !objects[pwep[i]].oc_bimanual) &&
(objects[pwep[i]].oc_material != SILVER
|| !mon_hates_silver(mtmp))) {
if ((otmp = oselect(mtmp, pwep[i])) != 0) {
if ((otmp = oselect(mtmp, pwep[i])) != 0 &&
(otmp == mwep || !mweponly)) {
propellor = otmp; /* force the monster to wield it */
return otmp;
}
Expand Down Expand Up @@ -674,7 +683,7 @@ register struct monst *mon;
} else {
pline("%s tries to wield %s.", Monnam(mon),
doname(obj));
pline("%s %s!", yname(mw_tmp), welded_buf);
pline("%s %s!", Yname2(mw_tmp), welded_buf);
}
mw_tmp->bknown = 1;
}
Expand Down

0 comments on commit 8dbbd1d

Please sign in to comment.