MCPcopy Index your code
hub / github.com/NetHack/NetHack / monmulti

Function monmulti

src/mthrowu.c:200–258  ·  view source on GitHub ↗

calculate multishot volley count for mtmp throwing otmp (if not ammo) or shooting otmp with mwep (if otmp is ammo and mwep appropriate launcher) */

Source from the content-addressed store, hash-verified

198/* calculate multishot volley count for mtmp throwing otmp (if not ammo) or
199 shooting otmp with mwep (if otmp is ammo and mwep appropriate launcher) */
200staticfn int
201monmulti(
202 struct monst *mtmp,
203 struct obj *otmp, struct obj *mwep)
204{
205 int multishot = 1;
206
207 if (otmp->quan > 1L /* no point checking if there's only 1 */
208 /* ammo requires corresponding launcher be wielded */
209 && (is_ammo(otmp)
210 ? matching_launcher(otmp, mwep)
211 /* otherwise any stackable (non-ammo) weapon */
212 : otmp->oclass == WEAPON_CLASS)
213 && !mtmp->mconf) {
214 /* Assumes lords are skilled, princes are expert */
215 if (is_prince(mtmp->data))
216 multishot += 2;
217 else if (is_lord(mtmp->data))
218 multishot++;
219 /* fake players treated as skilled (regardless of role limits) */
220 else if (is_mplayer(mtmp->data))
221 multishot++;
222
223 /* this portion is different from hero multishot; from slash'em?
224 */
225 /* Elven Craftsmanship makes for light, quick bows */
226 if (otmp->otyp == ELVEN_ARROW && !otmp->cursed)
227 multishot++;
228 /* for arrow, we checked bow&arrow when entering block, but for
229 bow, so far we've only validated that otmp is a weapon stack;
230 need to verify that it's a stack of arrows rather than darts */
231 if (mwep && mwep->otyp == ELVEN_BOW && ammo_and_launcher(otmp, mwep)
232 && !mwep->cursed)
233 multishot++;
234 /* 1/3 of launcher enchantment */
235 if (ammo_and_launcher(otmp, mwep) && mwep->spe > 1)
236 multishot += (long) rounddiv(mwep->spe, 3);
237 /* Some randomness */
238 multishot = rnd((int) multishot);
239
240 /* class bonus */
241 multishot += multishot_class_bonus(monsndx(mtmp->data), otmp, mwep);
242
243 /* racial bonus */
244 if ((is_elf(mtmp->data) && otmp->otyp == ELVEN_ARROW
245 && mwep && mwep->otyp == ELVEN_BOW)
246 || (is_orc(mtmp->data) && otmp->otyp == ORCISH_ARROW
247 && mwep && mwep->otyp == ORCISH_BOW)
248 || (is_gnome(mtmp->data) && otmp->otyp == CROSSBOW_BOLT
249 && mwep && mwep->otyp == CROSSBOW))
250 multishot++;
251 }
252
253 if (otmp->quan < multishot)
254 multishot = (int) otmp->quan;
255 if (multishot < 1)
256 multishot = 1;
257 return multishot;

Callers 1

monshootFunction · 0.85

Calls 3

rounddivFunction · 0.85
rndFunction · 0.85
multishot_class_bonusFunction · 0.85

Tested by

no test coverage detected