MCPcopy Create free account
hub / github.com/NetHack/NetHack / thrwmu

Function thrwmu

src/mthrowu.c:1173–1264  ·  view source on GitHub ↗

monster attempts ranged weapon attack against player */

Source from the content-addressed store, hash-verified

1171
1172/* monster attempts ranged weapon attack against player */
1173void
1174thrwmu(struct monst *mtmp)
1175{
1176 struct obj *otmp, *mwep;
1177 coordxy x, y;
1178 const char *onm;
1179 int rang;
1180 const struct throw_and_return_weapon *arw;
1181 boolean always_toss = FALSE;
1182
1183 /* Rearranged beginning so monsters can use polearms not in a line */
1184 if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) {
1185 mtmp->weapon_check = NEED_RANGED_WEAPON;
1186 /* mon_wield_item resets weapon_check as appropriate */
1187 if (mon_wield_item(mtmp) != 0)
1188 return;
1189 }
1190
1191 /* Pick a weapon */
1192 otmp = select_rwep(mtmp);
1193 if (!otmp)
1194 return;
1195
1196 if (is_pole(otmp)) {
1197 int dam, hitv;
1198
1199 if (otmp != MON_WEP(mtmp))
1200 return; /* polearm, aklys must be wielded */
1201
1202 /*
1203 * MON_POLE_DIST encompasses knight's move range (5): two spots
1204 * away provided it's not on a straight diagonal, same as skilled
1205 * hero. Using polearm while adjacent is allowed but the verb
1206 * is adjusted from "thrusts" to "bashes", where the hero would
1207 * have to switch from applying a polearm to ordinary melee attack
1208 * to accomplish that.
1209 *
1210 * .545.
1211 * 52125
1212 * 41014
1213 * 52125
1214 * .545.
1215 */
1216 rang = dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy);
1217 if (rang > MON_POLE_DIST || !couldsee(mtmp->mx, mtmp->my))
1218 return; /* Out of range, or intervening wall */
1219
1220 if (canseemon(mtmp)) {
1221 onm = xname(otmp);
1222 pline_mon(mtmp, "%s %s %s.", Monnam(mtmp),
1223 /* "thrusts" or "swings", or "bashes with" if adjacent */
1224 mswings_verb(otmp, (rang <= 2) ? TRUE : FALSE),
1225 obj_is_pname(otmp) ? the(onm) : an(onm));
1226 }
1227
1228 dam = dmgval(otmp, &gy.youmonst);
1229 hitv = 3 - distmin(u.ux, u.uy, mtmp->mx, mtmp->my);
1230 if (hitv < -4)

Callers 1

mattackuFunction · 0.85

Calls 15

mon_wield_itemFunction · 0.85
select_rwepFunction · 0.85
dist2Function · 0.85
canseemonFunction · 0.85
xnameFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
mswings_verbFunction · 0.85
obj_is_pnameFunction · 0.85
theFunction · 0.85
anFunction · 0.85
dmgvalFunction · 0.85

Tested by

no test coverage detected