Esempio n. 1
0
/* extract a shopkeeper name for the given shop type */
static void nameshk (struct monst *shk, const char *const *nlp) {
    int i, trycnt, names_avail;
    const char *shname = 0;
    struct monst *mtmp;
    int name_wanted;
    s_level *sptr;

    if (nlp == shklight && In_mines(&u.uz)
            && (sptr = Is_special(&u.uz)) != 0 && sptr->flags.town) {
        /* special-case minetown lighting shk */
        shname = "Izchak";
        shk->female = false;
    } else {
        /* We want variation from game to game, without needing the save
           and restore support which would be necessary for randomization;
           try not to make too many assumptions about time_t's internals;
           use ledger_no rather than depth to keep mine town distinct. */
        int nseed = (int)((long)u.ubirthday / 257L);

        name_wanted = ledger_no(&u.uz) + (nseed % 13) - (nseed % 5);
        if (name_wanted < 0) name_wanted += (13 + 5);
        shk->female = name_wanted & 1;

        for (names_avail = 0; nlp[names_avail]; names_avail++)
            continue;

        for (trycnt = 0; trycnt < 50; trycnt++) {
            if (nlp == shktools) {
                shname = shktools[rn2(names_avail)];
                shk->female = (*shname == '_');
                if (shk->female) shname++;
            } else if (name_wanted < names_avail) {
                shname = nlp[name_wanted];
            } else if ((i = rn2(names_avail)) != 0) {
                shname = nlp[i - 1];
            } else if (nlp != shkgeneral) {
                nlp = shkgeneral;   /* try general names */
                for (names_avail = 0; nlp[names_avail]; names_avail++)
                    continue;
                continue;           /* next `trycnt' iteration */
            } else {
                shname = shk->female ? "Lucrezia" : "Dirk";
            }

            /* is name already in use on this level? */
            for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
                if (DEADMONSTER(mtmp) || (mtmp == shk) || !mtmp->isshk) continue;
                if (strcmp(ESHK(mtmp)->shknam, shname)) continue;
                break;
            }
            if (!mtmp) break;       /* new name */
        }
    }
    (void) strncpy(ESHK(shk)->shknam, shname, PL_NSIZ);
    ESHK(shk)->shknam[PL_NSIZ-1] = 0;
}
Esempio n. 2
0
void
onquest()
{
	if(u.uevent.qcompleted || Not_firsttime) return;
	if(!Is_special(&u.uz)) return;

	if(Is_qstart(&u.uz)) on_start();
	else if(Is_qlocate(&u.uz) && u.uz.dlevel > u.uz0.dlevel) on_locate();
	else if(Is_nemesis(&u.uz)) on_goal();
	return;
}
Esempio n. 3
0
void
onquest(const d_level * orig_lev)
{
    if (u.uevent.qcompleted || on_level(orig_lev, &u.uz))
        return;
    if (!Is_special(&u.uz))
        return;

    if (Is_qstart(&u.uz))
        on_start(orig_lev);
    else if (Is_qlocate(&u.uz))
        on_locate(orig_lev);
    else if (Is_nemesis(&u.uz))
        on_goal();
    return;
}
Esempio n. 4
0
/* extract a shopkeeper name for the given shop type */
static void
nameshk(struct monst *shk, const char *const *nlp, struct level *lev)
{
    int i, trycnt, names_avail;
    const char *shname = 0;
    struct monst *mtmp;
    int name_wanted;
    s_level *sptr;

    if (nlp == shklight && In_mines(&lev->z)
        && (sptr = Is_special(&lev->z)) != 0 && sptr->flags.town) {
        /* special-case minetown lighting shk */
        shname = "Izchak";
        shk->female = FALSE;
    } else {
        /* We want variation from game to game, without needing the save and
           restore support which would be necessary for randomization; thus use
           ubirthday for deterministic random numbers, and use ledger_no rather
           than depth to keep mine town distinct. */
        int nseed = ((unsigned)u.ubirthday / 257U);

        name_wanted = ledger_no(&lev->z) + (nseed % 13) - (nseed % 5);
        if (name_wanted < 0)
            name_wanted += (13 + 5);
        shk->female = name_wanted & 1;

        for (names_avail = 0; nlp[names_avail]; names_avail++)
            continue;

        for (trycnt = 0; trycnt < 50; trycnt++) {
            if (nlp == shktools) {
                shname = shktools[rn2(names_avail)];
                shk->female = (*shname == '_');
                if (shk->female)
                    shname++;
            } else if (name_wanted < names_avail) {
                shname = nlp[name_wanted];
            } else if ((i = rn2(names_avail)) != 0) {
                shname = nlp[i - 1];
            } else if (nlp != shkgeneral) {
                nlp = shkgeneral;       /* try general names */
                for (names_avail = 0; nlp[names_avail]; names_avail++)
                    continue;
                continue;       /* next `trycnt' iteration */
            } else {
                shname = shk->female ? "Lucrezia" : "Dirk";
            }

            /* is name already in use on this level? */
            for (mtmp = lev->monlist; mtmp; mtmp = mtmp->nmon) {
                if (DEADMONSTER(mtmp) || (mtmp == shk) || !mx_eshk(mtmp))
                    continue;
                if (mx_name(mtmp) && strcmp(mx_name(mtmp), shname))
                    continue;
                break;
            }
            if (!mtmp)
                break;  /* new name */
        }
    }
    christen_monst(shk, shname);
}
Esempio n. 5
0
/* Locks the live log file and writes 'buffer' */
void livelog_write_string(char* buffer)
{
    FILE* livelogfile;
#ifdef FILE_AREAS
    if (lock_file_area(LOGAREA, LIVELOGFILE, 10)) {
#else
    if (lock_file(LIVELOGFILE, SCOREPREFIX, 10)) {
#endif
        if(!(livelogfile = fopen_datafile_area(LOGAREA, LIVELOGFILE, "a", SCOREPREFIX))) {
            pline("Cannot open live log file!");
        } else {
            fprintf(livelogfile, "%s", buffer);
            (void) fclose(livelogfile);
        }
        unlock_file_area(LOGAREA, LIVELOGFILE);
    }
}

static
char *livelog_prefix()
{
    s_level *lev = Is_special(&u.uz);
    snprintf(prefixbuf, STRBUF_LEN,
             "version=%s-%d.%d.%d:"
             "player=%s:turns=%ld:starttime=%ld:"
             "currenttime=%ld:"
             "dnum=%d:dname=%s:dlev=%d:maxlvl=%d:"
             "dlev_name=%s:"
             "hp=%d:maxhp=%d:deaths=%d:"
#ifdef RECORD_REALTIME
             "realtime=%ld:"
#endif
             "conduct=0x%lx:"
             "role=%s:race=%s:"
             "gender=%s:align=%s:"
             "gender0=%s:align0=%s:"
             "explvl=%d:exp=%ld:"
             "elbereths=%ld:"
             "xplevel=%d:" /* XP level */
             "exp=%ld:" /* Experience points */
             "mode=%s:"
             "gold=%ld",
             GAME_SHORT_NAME, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL,
             plname,
             moves,
             (long)u.ubirthday,
             (long)current_epoch(),
             u.uz.dnum, dungeons[u.uz.dnum].dname, depth(&u.uz), deepest_lev_reached(TRUE),
             lev ? lev->proto : "", /* proto level name if special level */
             u.uhp, u.uhpmax, u.umortality,
#ifdef RECORD_REALTIME
             (long)realtime_data.realtime,
#endif
             encodeconduct(),
             urole.filecode, urace.filecode,
             genders[flags.female].filecode, aligns[1-u.ualign.type].filecode,
             genders[flags.initgend].filecode, aligns[1-u.ualignbase[A_ORIGINAL]].filecode,
             u.ulevel,u.uexp,
             u.uconduct.elbereths,
             u.ulevel, /* XP level */
             (long)u.uexp, /* Experience points */
             (flags.debug ? "debug" : /* mode */
              flags.explore ? "explore" :
              hell_and_hell_mode ? "hah" :
              heaven_or_hell_mode ? "hoh" :
              "normal"),
#ifndef GOLDOBJ
             (u.ugold + hidden_gold())
#else
             (money_cnt(invent) + hidden_gold())
#endif
            );
    return prefixbuf;
}