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

Function select_rwep

src/weapon.c:532–676  ·  view source on GitHub ↗

select a ranged weapon for the monster */

Source from the content-addressed store, hash-verified

530
531/* select a ranged weapon for the monster */
532struct obj *
533select_rwep(struct monst *mtmp)
534{
535 struct obj *otmp;
536 struct obj *mwep;
537 boolean mweponly;
538 int i;
539
540 char mlet = mtmp->data->mlet;
541
542 gp.propellor = &hands_obj;
543 Oselect(EGG); /* cockatrice egg */
544 if (mlet == S_KOP) /* pies are first choice for Kops */
545 Oselect(CREAM_PIE);
546 if (throws_rocks(mtmp->data)) /* ...boulders for giants */
547 Oselect(BOULDER);
548
549 /* Select polearms first; they do more damage and aren't expendable.
550 But don't pick one if monster's weapon is welded, because then
551 we'd never have a chance to throw non-wielding missiles. */
552 /* The limit of 13 here is based on the monster polearm range limit
553 * (defined as 5 in mthrowu.c). 5 corresponds to a distance of 2 in
554 * one direction and 1 in another; one space beyond that would be 3 in
555 * one direction and 2 in another; 3^2+2^2=13.
556 */
557 mwep = MON_WEP(mtmp);
558 /* NO_WEAPON_WANTED means we already tried to wield and failed */
559 mweponly = (mwelded(mwep) && mtmp->weapon_check == NO_WEAPON_WANTED);
560 if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 13
561 && couldsee(mtmp->mx, mtmp->my)) {
562 if (is_art(mwep, ART_SNICKERSNEE)) {
563 gp.propellor = mwep;
564 return mwep;
565 }
566
567 for (i = 0; i < SIZE(pwep); i++) {
568 /* Only strong monsters can wield big (esp. long) weapons.
569 * Big weapon is basically the same as bimanual.
570 * All monsters can wield the remaining weapons.
571 */
572 if (((strongmonst(mtmp->data)
573 && (mtmp->misc_worn_check & W_ARMS) == 0)
574 || !objects[pwep[i]].oc_bimanual)
575 && (objects[pwep[i]].oc_material != SILVER
576 || !mon_hates_silver(mtmp))) {
577 if ((otmp = oselect(mtmp, pwep[i])) != 0
578 && (otmp == mwep || !mweponly)) {
579 gp.propellor = otmp; /* force the monster to wield it */
580 return otmp;
581 }
582 }
583 }
584 }
585 /* Next, try to select a throw-and-return weapon, since they are
586 * also not as expendable. Again, don't pick one if monster's
587 * weapon is welded.
588 */
589 for (i = 0; i < SIZE(arwep); i++) {

Callers 4

mon_wield_itemFunction · 0.85
dochugFunction · 0.85
thrwmmFunction · 0.85
thrwmuFunction · 0.85

Calls 6

mweldedFunction · 0.85
dist2Function · 0.85
is_artFunction · 0.85
mon_hates_silverFunction · 0.85
oselectFunction · 0.85
m_carryingFunction · 0.85

Tested by

no test coverage detected