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

Function dofire

src/dothrow.c:468–586  ·  view source on GitHub ↗

the #fire command -- throw from the quiver or use wielded polearm */

Source from the content-addressed store, hash-verified

466
467/* the #fire command -- throw from the quiver or use wielded polearm */
468int
469dofire(void)
470{
471 int shotlimit;
472 struct obj *obj;
473 /* AutoReturn() verifies Valkyrie if weapon is Mjollnir, but it relies
474 on its caller to make sure hero is strong enough to throw that */
475 boolean uwep_Throw_and_Return = (uwep && AutoReturn(uwep, uwep->owornmask)
476 && (uwep->oartifact != ART_MJOLLNIR
477 || ACURR(A_STR) >= STR19(25))),
478 skip_fireassist = FALSE;
479 int altres, res = ECMD_OK;
480
481 /*
482 * Same as dothrow(), except we use quivered missile instead
483 * of asking what to throw/shoot. [Note: with the advent of
484 * fireassist that is no longer accurate...]
485 *
486 * If hero is wielding a thrown-and-return weapon and quiver
487 * is empty or contains ammo, use the wielded weapon (won't
488 * have any ammo's launcher wielded due to the weapon).
489 * If quiver is empty, use autoquiver to fill it when the
490 * corresponding option is on.
491 * If option is off or autoquiver doesn't select anything,
492 * we ask what to throw.
493 * Then we put the chosen item into the quiver slot unless
494 * it is already in another slot. [Matters most if it is a
495 * stack but also matters for single item if this throw gets
496 * aborted (ESC at the direction prompt).]
497 */
498 if (!ok_to_throw(&shotlimit))
499 return ECMD_OK;
500
501 obj = uquiver;
502 /* if wielding a throw-and-return weapon, throw it if quiver is empty
503 or has ammo rather than missiles [since the throw/return weapon is
504 wielded, the ammo's launcher isn't; the ammo-only policy avoids
505 throwing Mjollnir if quiver contains daggers] */
506 if (uwep_Throw_and_Return && (!obj || is_ammo(obj))) {
507 obj = uwep;
508 skip_fireassist = TRUE;
509
510 } else if (!obj) {
511 if (!flags.autoquiver) {
512 /* if we're wielding a polearm, apply it */
513 if (uwep && is_pole(uwep)) {
514 return use_pole(uwep, TRUE);
515 /* if we're wielding a bullwhip, apply it */
516 } else if (uwep && uwep->otyp == BULLWHIP) {
517 return use_whip(uwep);
518 } else if (iflags.fireassist
519 && uswapwep && is_pole(uswapwep)
520 && !(uswapwep->cursed && uswapwep->bknown)) {
521 /* we have a known not-cursed polearm as swap weapon.
522 swap to it and retry */
523 cmdq_add_ec(CQ_CANNED, doswapweapon);
524 cmdq_add_ec(CQ_CANNED, dofire);
525 return ECMD_OK; /* haven't taken any time yet */

Callers

nothing calls this directly

Calls 12

ok_to_throwFunction · 0.85
use_poleFunction · 0.85
use_whipFunction · 0.85
cmdq_add_ecFunction · 0.85
YouFunction · 0.85
autoquiverFunction · 0.85
prinvFunction · 0.85
doquiver_coreFunction · 0.85
could_pole_monFunction · 0.85
find_launcherFunction · 0.85
cmdq_add_keyFunction · 0.85
throw_objFunction · 0.85

Tested by

no test coverage detected