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

Function nameshk

src/shknam.c:486–554  ·  view source on GitHub ↗

extract a shopkeeper name for the given shop type */

Source from the content-addressed store, hash-verified

484
485/* extract a shopkeeper name for the given shop type */
486staticfn void
487nameshk(struct monst *shk, const char *const *nlp)
488{
489 int i, trycnt, names_avail;
490 const char *shname = 0;
491 struct monst *mtmp;
492 int name_wanted = shk->m_id;
493 s_level *sptr;
494
495 if (nlp == shklight && In_mines(&u.uz)
496 && (sptr = Is_special(&u.uz)) != 0 && sptr->flags.town) {
497 /* special-case minetown lighting shk */
498 shname = "+Izchak";
499 shk->female = FALSE;
500 } else {
501 /* We want variation from game to game, without needing the save
502 and restore support which would be necessary for randomization;
503 try not to make too many assumptions about time_t's internals;
504 use ledger_no rather than depth to keep minetown distinct. */
505 int nseed = (int) ((long) ubirthday / 257L);
506
507 name_wanted += ledger_no(&u.uz) + (nseed % 13) - (nseed % 5);
508 if (name_wanted < 0)
509 name_wanted += (13 + 5);
510 shk->female = name_wanted & 1;
511
512 for (names_avail = 0; nlp[names_avail]; names_avail++)
513 continue;
514 assert(names_avail > 0);
515 name_wanted = name_wanted % names_avail;
516
517 for (trycnt = 0; trycnt < 50; trycnt++) {
518 if (nlp == shktools) {
519 shname = shktools[rn2(names_avail)];
520 shk->female = 0; /* reversed below for '_' prefix */
521 } else if (name_wanted < names_avail) {
522 shname = nlp[name_wanted];
523 } else if ((i = rn2(names_avail)) != 0) {
524 shname = nlp[i - 1];
525 } else if (nlp != shkgeneral) {
526 nlp = shkgeneral; /* try general names */
527 for (names_avail = 0; nlp[names_avail]; names_avail++)
528 continue;
529 continue; /* next `trycnt' iteration */
530 } else {
531 shname = shk->female ? "-Lucrezia" : "+Dirk";
532 }
533 if (*shname == '_' || *shname == '-')
534 shk->female = 1;
535 else if (*shname == '|' || *shname == '+')
536 shk->female = 0;
537
538 /* is name already in use on this level? */
539 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
540 if (DEADMONSTER(mtmp) || (mtmp == shk) || !mtmp->isshk)
541 continue;
542 assert(has_eshk(mtmp));
543 if (strcmp(ESHK(mtmp)->shknam, shname))

Callers 1

shkinitFunction · 0.85

Calls 4

In_minesFunction · 0.85
Is_specialFunction · 0.85
ledger_noFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected