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

Function autoquiver

src/dothrow.c:380–442  ·  view source on GitHub ↗

KMH -- Automatically fill quiver */ Suggested by Jeffrey Bay */

Source from the content-addressed store, hash-verified

378/* KMH -- Automatically fill quiver */
379/* Suggested by Jeffrey Bay <jbay@convex.hp.com> */
380staticfn void
381autoquiver(void)
382{
383 struct obj *otmp, *oammo = 0, *omissile = 0, *omisc = 0, *altammo = 0;
384
385 if (uquiver)
386 return;
387
388 /* Scan through the inventory */
389 for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
390 if (otmp->owornmask || otmp->oartifact || !otmp->dknown) {
391 ; /* Skip it */
392 } else if (otmp->otyp == ROCK
393 /* seen rocks or known flint or known glass */
394 || (otmp->otyp == FLINT
395 && objects[otmp->otyp].oc_name_known)
396 || (otmp->oclass == GEM_CLASS
397 && objects[otmp->otyp].oc_material == GLASS
398 && objects[otmp->otyp].oc_name_known)) {
399 if (uslinging())
400 oammo = otmp;
401 else if (ammo_and_launcher(otmp, uswapwep))
402 altammo = otmp;
403 else if (!omisc)
404 omisc = otmp;
405 } else if (otmp->oclass == GEM_CLASS) {
406 ; /* skip non-rock gems--they're ammo but
407 player has to select them explicitly */
408 } else if (is_ammo(otmp)) {
409 if (ammo_and_launcher(otmp, uwep))
410 /* Ammo matched with launcher (bow+arrow, crossbow+bolt) */
411 oammo = otmp;
412 else if (ammo_and_launcher(otmp, uswapwep))
413 altammo = otmp;
414 else
415 /* Mismatched ammo (no better than an ordinary weapon) */
416 omisc = otmp;
417 } else if (is_missile(otmp)) {
418 /* Missile (dart, shuriken, etc.) */
419 omissile = otmp;
420 } else if (otmp->oclass == WEAPON_CLASS && throwing_weapon(otmp)) {
421 /* Ordinary weapon */
422 if (objects[otmp->otyp].oc_skill == P_DAGGER && !omissile)
423 omissile = otmp;
424 else if (otmp->otyp == AKLYS)
425 continue;
426 else
427 omisc = otmp;
428 }
429 }
430
431 /* Pick the best choice */
432 if (oammo)
433 setuqwep(oammo);
434 else if (omissile)
435 setuqwep(omissile);
436 else if (altammo)
437 setuqwep(altammo);

Callers 1

dofireFunction · 0.85

Calls 2

throwing_weaponFunction · 0.85
setuqwepFunction · 0.85

Tested by

no test coverage detected