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

Function shkinit

src/shknam.c:627–692  ·  view source on GitHub ↗

create a new shopkeeper in the given room */

Source from the content-addressed store, hash-verified

625
626/* create a new shopkeeper in the given room */
627staticfn int
628shkinit(const struct shclass *shp, struct mkroom *sroom)
629{
630 int sh;
631 coordxy sx, sy;
632 struct monst *shk;
633 struct eshk *eshkp;
634
635 /* place the shopkeeper in the given room */
636 sh = good_shopdoor(sroom, &sx, &sy);
637 if (sh < 0) {
638#ifdef DEBUG
639 /* Said to happen sometimes, but I have never seen it. */
640 /* Supposedly fixed by fdoor change in mklev.c */
641 if (wizard) {
642 int j = sroom->doorct;
643
644 impossible("Where is shopdoor?");
645 pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly, sroom->hx,
646 sroom->hy);
647 pline("doormax=%d doorct=%d fdoor=%d", gd.doorindex, sroom->doorct,
648 sh);
649 while (j--) {
650 pline("door [%d,%d]", svd.doors[sh].x, svd.doors[sh].y);
651 sh++;
652 }
653 display_nhwindow(WIN_MESSAGE, FALSE);
654 }
655#endif
656 return -1;
657 }
658
659 if (MON_AT(sx, sy))
660 (void) rloc(m_at(sx, sy), RLOC_NOMSG); /* insurance */
661
662 /* now initialize the shopkeeper monster structure */
663 if (!(shk = makemon(&mons[PM_SHOPKEEPER], sx, sy, MM_ESHK)))
664 return -1;
665 eshkp = ESHK(shk); /* makemon(...,MM_ESHK) allocates this */
666 shk->isshk = shk->mpeaceful = 1;
667 set_malign(shk);
668 shk->msleeping = 0;
669 mon_learns_traps(shk, ALL_TRAPS); /* we know all the traps already */
670 eshkp->shoproom = (schar) ((sroom - svr.rooms) + ROOMOFFSET);
671 sroom->resident = shk;
672 eshkp->shoptype = sroom->rtype;
673 assign_level(&eshkp->shoplevel, &u.uz);
674 eshkp->shd = svd.doors[sh];
675 eshkp->shk.x = sx;
676 eshkp->shk.y = sy;
677 eshkp->robbed = eshkp->credit = eshkp->debit = eshkp->loan = 0L;
678 eshkp->following = eshkp->surcharge = eshkp->dismiss_kops = FALSE;
679 eshkp->billct = eshkp->visitct = 0;
680 eshkp->bill_p = (struct bill_x *) 0;
681 eshkp->customer[0] = '\0';
682 mkmonmoney(shk, 1000L + 30L * (long) rnd(100)); /* initial capital */
683 if (shp->shknms == shkrings)
684 (void) mongets(shk, TOUCHSTONE);

Callers 1

stock_roomFunction · 0.85

Calls 13

good_shopdoorFunction · 0.85
rlocFunction · 0.85
makemonFunction · 0.85
set_malignFunction · 0.85
mon_learns_trapsFunction · 0.85
assign_levelFunction · 0.85
mkmonmoneyFunction · 0.85
rndFunction · 0.85
mongetsFunction · 0.85
rn2Function · 0.85
nameshkFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected