Move some hard-coded string arrays into data files.

Random epitaphs, engravings and hallucinatory monsters now
live in text data files.
This commit is contained in:
Pasi Kallinen
2015-03-18 22:05:10 +02:00
parent e93add8cb8
commit debdf7ca48
23 changed files with 420 additions and 174 deletions

View File

@@ -809,10 +809,10 @@ boolean called;
/* Put the actual monster name or type into the buffer now */
/* Be sure to remember whether the buffer starts with a name */
if (do_hallu) {
const char *rname = rndmonnam();
char rnamecode;
char *rname = rndmonnam(&rnamecode);
Strcat(buf, rname);
name_at_start = bogon_is_pname(rname);
name_at_start = bogon_is_pname(rnamecode);
} else if (has_mname(mtmp)) {
char *name = MNAME(mtmp);
@@ -1006,113 +1006,44 @@ char *outbuf;
return outbuf;
}
/*
* Name prefix codes (same as shknam.c):
* dash - female, personal name
* underscore _ female, general name
* plus + male, personal name
* vertical bar | male, general name
* equals = gender not specified, personal name
*/
static const char * const bogusmons[] = {
"jumbo shrimp", "giant pigmy", "gnu", "killer penguin",
"giant cockroach", "giant slug", "maggot", "pterodactyl",
"tyrannosaurus rex", "basilisk", "beholder", "nightmare",
"efreeti", "marid", "rot grub", "bookworm", "master lichen",
"shadow", "hologram", "jester", "attorney", "sleazoid",
"killer tomato", "amazon", "robot", "battlemech",
"rhinovirus", "harpy", "lion-dog", "rat-ant", "Y2K bug",
/* misc. */
"grue", "Christmas-tree monster", "luck sucker", "paskald",
"brogmoid", "dornbeast", /* Quendor (Zork, &c.) */
"Ancient Multi-Hued Dragon", "+Evil Iggy",
/* Moria */
"emu", "kestrel", "xeroc", "venus flytrap",
/* Rogue */
"creeping coins", /* Wizardry */
"hydra", "siren", /* Greek legend */
"killer bunny", /* Monty Python */
"rodent of unusual size", /* The Princess Bride */
"were-rabbit", /* Wallace & Gromit */
"+Smokey Bear", /* "Only you can prevent forest fires!" */
"Luggage", /* Discworld */
"Ent", /* Lord of the Rings */
"tangle tree", "nickelpede", "wiggle", /* Xanth */
"white rabbit", "snark", /* Lewis Carroll */
"pushmi-pullyu", /* Dr. Dolittle */
"smurf", /* The Smurfs */
"tribble", "Klingon", "Borg", /* Star Trek */
"Ewok", /* Star Wars */
"Totoro", /* Tonari no Totoro */
"ohmu", /* Nausicaa */
"youma", /* Sailor Moon */
"nyaasu", /* Pokemon (Meowth) */
"-Godzilla", "+King Kong", /* monster movies */
"earthquake beast", /* old L of SH */
"Invid", /* Robotech */
"Terminator", /* The Terminator */
"boomer", /* Bubblegum Crisis */
"Dalek", /* Dr. Who ("Exterminate!") */
"microscopic space fleet", "Ravenous Bugblatter Beast of Traal",
/* HGttG */
"teenage mutant ninja turtle", /* TMNT */
"samurai rabbit", /* Usagi Yojimbo */
"aardvark", /* Cerebus */
"=Audrey II", /* Little Shop of Horrors */
"witch doctor", "one-eyed one-horned flying purple people eater",
/* 50's rock 'n' roll */
"+Barney the dinosaur", /* saccharine kiddy TV */
"+Morgoth", /* Angband */
"Vorlon", /* Babylon 5 */
"questing beast", /* King Arthur */
"Predator", /* Movie */
"mother-in-law" /* common pest */
};
#define BOGUSMONSIZE 100 /* arbitrary */
/* return a random monster name, for hallucination */
const char *
rndmonnam()
char *
rndmonnam(code)
char *code;
{
const char *mname;
static char buf[BUFSZ];
char *mname = buf;
int name;
if (code) *code = '\0';
do {
name = rn1(SPECIAL_PM + SIZE(bogusmons) - LOW_PM, LOW_PM);
name = rn1(SPECIAL_PM + BOGUSMONSIZE - LOW_PM, LOW_PM);
} while (name < SPECIAL_PM &&
(type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN)));
if (name >= SPECIAL_PM) {
mname = bogusmons[name - SPECIAL_PM];
get_rnd_text(BOGUSMONFILE, buf);
/* strip prefix if present */
if (!letter(*mname)) ++mname;
if (!letter(*mname)) {
if (code) *code = *mname;
++mname;
}
} else {
mname = mons[name].mname;
Strcpy(buf, mons[name].mname);
}
return mname;
}
#undef BOGUSMONSIZE
/* scan bogusmons to check whether this name is in the list and has a prefix */
boolean
bogon_is_pname(mname)
const char *mname;
bogon_is_pname(code)
char code;
{
const char *bname;
int name;
if (!mname || !*mname) return FALSE;
if (!strncmpi(mname, "the ", 4)) mname += 4;
/* scan the bogusmons[] list; case sensitive here */
for (name = 0; name < SIZE(bogusmons); name++) {
bname = bogusmons[name];
/* we can skip all ordinary entries */
if (letter(*bname)) continue;
/* starts with a classification code; does rest of name match? */
if (!strcmp(mname, bname + 1))
return index("-+=", *bname) ? TRUE : FALSE;
}
return FALSE;
if (!code) return FALSE;
return index("-+=", code) ? TRUE : FALSE;
}
const char *

View File

@@ -1252,7 +1252,7 @@ const char *mesg;
what = "chicken";
which = 1; /* suppress pluralization */
} else if (Hallucination) {
what = rndmonnam();
what = rndmonnam(NULL);
} else {
what = mons[mnum].mname;
if (the_unique_pm(&mons[mnum])) which = 2;

View File

@@ -9,33 +9,6 @@
STATIC_VAR NEARDATA struct engr *head_engr;
/* random engravings */
static const char *random_mesg[] = {
"Elbereth",
/* trap engravings */
"Vlad was here", "ad aerarium",
/* take-offs and other famous engravings */
"Owlbreath", "Galadriel",
"Kilroy was here",
"A.S. ->", "<- A.S.", /* Journey to the Center of the Earth */
"You won't get it up the steps", /* Adventure */
"Lasciate ogni speranza o voi ch'entrate.", /* Inferno */
"Well Come", /* Prisoner */
"We apologize for the inconvenience.", /* So Long... */
"See you next Wednesday", /* Thriller */
"notary sojak", /* Smokey Stover */
"For a good time call 8?7-5309",
"Please don't feed the animals.", /* Various zoos around the world */
"Madam, in Eden, I'm Adam.", /* A palindrome */
"Two thumbs up!", /* Siskel & Ebert */
"Hello, World!", /* The First C Program */
#ifdef MAIL
"You've got mail!", /* AOL */
#endif
"As if!", /* Clueless */
"BAD WOLF", /* 200x incarnation of Dr.Who */
};
char *
random_engraving(outbuf)
char *outbuf;
@@ -44,8 +17,10 @@ char *outbuf;
/* a random engraving may come from the "rumors" file,
or from the list above */
if (!rn2(4) || !(rumor = getrumor(0, outbuf, TRUE)) || !*rumor)
Strcpy(outbuf, random_mesg[rn2(SIZE(random_mesg))]);
if (!rn2(4) || !(rumor = getrumor(0, outbuf, TRUE)) || !*rumor) {
char buf[BUFSZ];
Strcpy(outbuf, get_rnd_text(ENGRAVEFILE, buf));
}
wipeout_text(outbuf, (int)(strlen(outbuf) / 4), 0);
return outbuf;
@@ -1232,39 +1207,6 @@ struct engr *ep;
}
/* Epitaphs for random headstones */
static const char *epitaphs[] = {
"Rest in peace",
"R.I.P.",
"Rest In Pieces",
"Note -- there are NO valuable items in this grave",
"1994-1995. The Longest-Lived Hacker Ever",
"The Grave of the Unknown Hacker",
"We weren't sure who this was, but we buried him here anyway",
"Sparky -- he was a very good dog",
"Beware of Electric Third Rail",
"Made in Taiwan",
"Og friend. Og good dude. Og died. Og now food",
"Beetlejuice Beetlejuice Beetlejuice",
"Look out below!",
"Please don't dig me up. I'm perfectly happy down here. -- Resident",
"Postman, please note forwarding address: Gehennom, Asmodeus's Fortress, fifth lemure on the left",
"Mary had a little lamb/Its fleece was white as snow/When Mary was in trouble/The lamb was first to go",
"Be careful, or this could happen to you!",
"Soon you'll join this fellow in hell! -- the Wizard of Yendor",
"Caution! This grave contains toxic waste",
"Sum quod eris",
"Here lies an Atheist, all dressed up and no place to go",
"Here lies Ezekiel, age 102. The good die young.",
"Here lies my wife: Here let her lie! Now she's at rest and so am I.",
"Here lies Johnny Yeast. Pardon me for not rising.",
"He always lied while on the earth and now he's lying in it",
"I made an ash of myself",
"Soon ripe. Soon rotten. Soon gone. But not forgotten.",
"Here lies the body of Jonathan Blake. Stepped on the gas instead of the brake.",
"Go away!"
};
/* Create a headstone at the given location.
* The caller is responsible for newsym(x, y).
*/
@@ -1280,9 +1222,12 @@ const char *str;
levl[x][y].typ = GRAVE;
/* Engrave the headstone */
if (!str) str = epitaphs[rn2(SIZE(epitaphs))];
del_engr_at(x, y);
make_engr_at(x, y, str, 0L, HEADSTONE);
if (str) make_engr_at(x, y, str, 0L, HEADSTONE);
else {
char buf[BUFSZ];
make_engr_at(x, y, get_rnd_text(EPITAPHFILE, buf), 0L, HEADSTONE);
}
return;
}

View File

@@ -283,7 +283,7 @@ int expltype;
so avoid any which begins with a capital letter) */
do {
Sprintf(hallu_buf, "%s explosion",
s_suffix(rndmonnam()));
s_suffix(rndmonnam(NULL)));
} while (*hallu_buf != lowc(*hallu_buf));
str = hallu_buf;
}
@@ -365,7 +365,7 @@ int expltype;
if (do_hallu) { /* (see explanation above) */
do {
Sprintf(hallu_buf, "%s explosion",
s_suffix(rndmonnam()));
s_suffix(rndmonnam(NULL)));
} while (*hallu_buf != lowc(*hallu_buf));
str = hallu_buf;
}

View File

@@ -39,7 +39,7 @@ dowatersnakes() /* Fountain of snakes! */
if (!(mvitals[PM_WATER_MOCCASIN].mvflags & G_GONE)) {
if (!Blind)
pline("An endless stream of %s pours forth!",
Hallucination ? makeplural(rndmonnam()) : "snakes");
Hallucination ? makeplural(rndmonnam(NULL)) : "snakes");
else
You_hear("%s hissing!", something);
while(num-- > 0)

View File

@@ -88,7 +88,7 @@ struct obj *obj;
if (vis) {
pline("As %s opens the bottle, an enormous %s emerges!",
mon_nam(mon),
Hallucination ? rndmonnam() : (const char *)"ghost");
Hallucination ? rndmonnam(NULL) : (const char *)"ghost");
pline("%s is frightened to death, and unable to move.",
Monnam(mon));
}

View File

@@ -2040,7 +2040,7 @@ struct obj *box;
(void) add_to_container(box, deadcat);
}
pline_The("%s inside the box is dead!",
Hallucination ? rndmonnam() : "housecat");
Hallucination ? rndmonnam(NULL) : "housecat");
}
box->owt = weight(box);
return;

View File

@@ -371,7 +371,7 @@ ghost_from_bottle()
return;
}
pline("As you open the bottle, an enormous %s emerges!",
Hallucination ? rndmonnam() : (const char *)"ghost");
Hallucination ? rndmonnam(NULL) : (const char *)"ghost");
if(flags.verbose)
You("are frightened to death, and unable to move.");
nomul(-3);

View File

@@ -284,13 +284,14 @@ char *pname; /* caller-supplied output buffer */
boolean do_hallu = Hallucination,
aligned_priest = mon->data == &mons[PM_ALIGNED_PRIEST],
high_priest = mon->data == &mons[PM_HIGH_PRIEST];
const char *what = do_hallu ? rndmonnam() : mon->data->mname;
char whatcode = '\0';
const char *what = do_hallu ? rndmonnam(&whatcode) : mon->data->mname;
if (!mon->ispriest && !mon->isminion) /* should never happen... */
return strcpy(pname, what); /* caller must be confused */
*pname = '\0';
if (!do_hallu || !bogon_is_pname(what)) Strcat(pname, "the ");
if (!do_hallu || !bogon_is_pname(whatcode)) Strcat(pname, "the ");
if (mon->minvis) Strcat(pname, "invisible ");
if (mon->isminion && EMIN(mon)->renegade)
Strcat(pname, "renegade ");

View File

@@ -266,6 +266,46 @@ rumor_check()
}
}
/* Gets a random line of text from file 'fname', and returns it. */
char *
get_rnd_text(fname, buf)
const char *fname;
char *buf;
{
dlb *fh;
buf[0] = '\0';
fh = dlb_fopen(fname, "r");
if (fh) {
/* TODO: cache sizetxt, starttxt, endtxt. maybe cache file contents? */
long sizetxt = 0, starttxt = 0, endtxt = 0, tidbit = 0;
char *endp, line[BUFSZ], xbuf[BUFSZ];
(void) dlb_fgets(line, sizeof line, fh); /* skip "don't edit" comment */
(void) dlb_fseek(fh, 0L, SEEK_CUR);
starttxt = dlb_ftell(fh);
(void) dlb_fseek(fh, 0L, SEEK_END);
endtxt = dlb_ftell(fh);
sizetxt = endtxt - starttxt;
tidbit = Rand() % sizetxt;
(void) dlb_fseek(fh, starttxt + tidbit, SEEK_SET);
(void) dlb_fgets(line, sizeof line, fh);
if (!dlb_fgets(line, sizeof line, fh)) {
(void) dlb_fseek(fh, starttxt, SEEK_SET);
(void) dlb_fgets(line, sizeof line, fh);
}
if ((endp = index(line, '\n')) != 0) *endp = 0;
Strcat(buf, xcrypt(line, xbuf));
(void) dlb_fclose(fh);
} else impossible("Can't open file %s!", fname);
return buf;
}
void
outrumor(truth, mechanism)
int truth; /* 1=true, -1=false, 0=either */

View File

@@ -1006,7 +1006,7 @@ dochat()
if (!Blind) {
if (Hallucination) {
/* if you're hallucinating, you can't tell it's a statue */
pline_The("%s seems not to notice you.", rndmonnam());
pline_The("%s seems not to notice you.", rndmonnam(NULL));
}
else {
pline_The("statue seems not to notice you.");

View File

@@ -164,7 +164,7 @@ slime_dialogue()
if (!Blind) /* [what if you're already green?] */
pline(buf, hcolor(NH_GREEN));
} else
pline(buf, an(Hallucination ? rndmonnam() : "green slime"));
pline(buf, an(Hallucination ? rndmonnam(NULL) : "green slime"));
} else
pline1(buf);
}

View File

@@ -621,7 +621,7 @@ int *fail_reason;
"statue");
pline("%s %s!", upstart(statuename), comes_to_life);
} else if (Hallucination) { /* They don't know it's a statue */
pline_The("%s suddenly seems more animated.", rndmonnam());
pline_The("%s suddenly seems more animated.", rndmonnam(NULL));
} else if (cause == ANIMATE_SHATTER) {
if (cansee(x, y))
Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue),

View File

@@ -1799,7 +1799,7 @@ struct obj *obj, *otmp;
if (break_statue(obj)) {
if (cansee(obj->ox, obj->oy)) {
if (Hallucination)
pline_The("%s shatters.", rndmonnam());
pline_The("%s shatters.", rndmonnam(NULL));
else
pline_The("statue shatters.");
} else