Difference between revisions of "Source:NetHack 3.4.3/src/questpgr.c"
Jump to navigation
Jump to search
(Automated source code upload) |
m (moved Source:Questpgr.c to Source:NetHack 3.4.3/src/questpgr.c: Moving src to subdirs) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | __MIXEDSYNTAXHIGHLIGHT__ | ||
+ | Below is the full text to src/questpgr.c from NetHack 3.4.3. To link to a particular line, write [[questpgr.c#line123|<nowiki>[[questpgr.c#line123]]</nowiki>]], for example. | ||
+ | |||
+ | == Top of file == | ||
− | |||
<span id="line1">1. /* SCCS Id: @(#)questpgr.c 3.4 2000/05/05 */</span> | <span id="line1">1. /* SCCS Id: @(#)questpgr.c 3.4 2000/05/05 */</span> | ||
<span id="line2">2. /* Copyright 1991, M. Stephenson */</span> | <span id="line2">2. /* Copyright 1991, M. Stephenson */</span> | ||
Line 40: | Line 43: | ||
<span id="line35">35. static void NDECL(dump_qtlist);</span> | <span id="line35">35. static void NDECL(dump_qtlist);</span> | ||
<span id="line36">36. </span> | <span id="line36">36. </span> | ||
+ | |||
+ | == dump_qtlist == | ||
+ | |||
<span id="line37">37. static void</span> | <span id="line37">37. static void</span> | ||
<span id="line38">38. dump_qtlist() /* dump the character msg list to check appearance */</span> | <span id="line38">38. dump_qtlist() /* dump the character msg list to check appearance */</span> | ||
Line 56: | Line 62: | ||
<span id="line51">51. #endif /* DEBUG */</span> | <span id="line51">51. #endif /* DEBUG */</span> | ||
<span id="line52">52. </span> | <span id="line52">52. </span> | ||
+ | |||
+ | == Fread == | ||
+ | |||
<span id="line53">53. static void</span> | <span id="line53">53. static void</span> | ||
<span id="line54">54. Fread(ptr, size, nitems, stream)</span> | <span id="line54">54. Fread(ptr, size, nitems, stream)</span> | ||
Line 71: | Line 80: | ||
<span id="line66">66. }</span> | <span id="line66">66. }</span> | ||
<span id="line67">67. </span> | <span id="line67">67. </span> | ||
+ | |||
+ | == construct_qtlist == | ||
+ | |||
<span id="line68">68. STATIC_OVL struct qtmsg *</span> | <span id="line68">68. STATIC_OVL struct qtmsg *</span> | ||
<span id="line69">69. construct_qtlist(hdr_offset)</span> | <span id="line69">69. construct_qtlist(hdr_offset)</span> | ||
Line 92: | Line 104: | ||
<span id="line87">87. }</span> | <span id="line87">87. }</span> | ||
<span id="line88">88. </span> | <span id="line88">88. </span> | ||
+ | |||
+ | == load_qtlist == | ||
+ | |||
<span id="line89">89. void</span> | <span id="line89">89. void</span> | ||
<span id="line90">90. load_qtlist()</span> | <span id="line90">90. load_qtlist()</span> | ||
Line 139: | Line 154: | ||
<span id="line134">134. }</span> | <span id="line134">134. }</span> | ||
<span id="line135">135. </span> | <span id="line135">135. </span> | ||
+ | |||
+ | == unload_qtlist == | ||
+ | |||
<span id="line136">136. /* called at program exit */</span> | <span id="line136">136. /* called at program exit */</span> | ||
<span id="line137">137. void</span> | <span id="line137">137. void</span> | ||
Line 152: | Line 170: | ||
<span id="line147">147. }</span> | <span id="line147">147. }</span> | ||
<span id="line148">148. </span> | <span id="line148">148. </span> | ||
+ | |||
+ | == quest_info == | ||
+ | |||
<span id="line149">149. short</span> | <span id="line149">149. short</span> | ||
<span id="line150">150. quest_info(typ)</span> | <span id="line150">150. quest_info(typ)</span> | ||
Line 166: | Line 187: | ||
<span id="line161">161. }</span> | <span id="line161">161. }</span> | ||
<span id="line162">162. </span> | <span id="line162">162. </span> | ||
+ | |||
+ | == ldrname == | ||
+ | |||
<span id="line163">163. const char *</span> | <span id="line163">163. const char *</span> | ||
<span id="line164">164. ldrname() /* return your role leader's name */</span> | <span id="line164">164. ldrname() /* return your role leader's name */</span> | ||
Line 177: | Line 201: | ||
<span id="line172">172. }</span> | <span id="line172">172. }</span> | ||
<span id="line173">173. </span> | <span id="line173">173. </span> | ||
+ | |||
+ | == intermed == | ||
+ | |||
<span id="line174">174. STATIC_OVL const char *</span> | <span id="line174">174. STATIC_OVL const char *</span> | ||
<span id="line175">175. intermed() /* return your intermediate target string */</span> | <span id="line175">175. intermed() /* return your intermediate target string */</span> | ||
Line 183: | Line 210: | ||
<span id="line178">178. }</span> | <span id="line178">178. }</span> | ||
<span id="line179">179. </span> | <span id="line179">179. </span> | ||
+ | |||
+ | == is_quest_artifact == | ||
+ | |||
<span id="line180">180. boolean</span> | <span id="line180">180. boolean</span> | ||
<span id="line181">181. is_quest_artifact(otmp)</span> | <span id="line181">181. is_quest_artifact(otmp)</span> | ||
Line 190: | Line 220: | ||
<span id="line185">185. }</span> | <span id="line185">185. }</span> | ||
<span id="line186">186. </span> | <span id="line186">186. </span> | ||
+ | |||
+ | == neminame == | ||
+ | |||
<span id="line187">187. STATIC_OVL const char *</span> | <span id="line187">187. STATIC_OVL const char *</span> | ||
<span id="line188">188. neminame() /* return your role nemesis' name */</span> | <span id="line188">188. neminame() /* return your role nemesis' name */</span> | ||
Line 201: | Line 234: | ||
<span id="line196">196. }</span> | <span id="line196">196. }</span> | ||
<span id="line197">197. </span> | <span id="line197">197. </span> | ||
+ | |||
+ | == guardname == | ||
+ | |||
<span id="line198">198. STATIC_OVL const char *</span> | <span id="line198">198. STATIC_OVL const char *</span> | ||
<span id="line199">199. guardname() /* return your role leader's guard monster name */</span> | <span id="line199">199. guardname() /* return your role leader's guard monster name */</span> | ||
Line 209: | Line 245: | ||
<span id="line204">204. }</span> | <span id="line204">204. }</span> | ||
<span id="line205">205. </span> | <span id="line205">205. </span> | ||
+ | |||
+ | == homebase == | ||
+ | |||
<span id="line206">206. STATIC_OVL const char *</span> | <span id="line206">206. STATIC_OVL const char *</span> | ||
<span id="line207">207. homebase() /* return your role leader's location */</span> | <span id="line207">207. homebase() /* return your role leader's location */</span> | ||
Line 215: | Line 254: | ||
<span id="line210">210. }</span> | <span id="line210">210. }</span> | ||
<span id="line211">211. </span> | <span id="line211">211. </span> | ||
+ | |||
+ | == msg_in == | ||
+ | |||
<span id="line212">212. STATIC_OVL struct qtmsg *</span> | <span id="line212">212. STATIC_OVL struct qtmsg *</span> | ||
<span id="line213">213. msg_in(qtm_list, msgnum)</span> | <span id="line213">213. msg_in(qtm_list, msgnum)</span> | ||
Line 228: | Line 270: | ||
<span id="line223">223. }</span> | <span id="line223">223. }</span> | ||
<span id="line224">224. </span> | <span id="line224">224. </span> | ||
+ | |||
+ | == convert_arg == | ||
+ | |||
<span id="line225">225. STATIC_OVL void</span> | <span id="line225">225. STATIC_OVL void</span> | ||
<span id="line226">226. convert_arg(c)</span> | <span id="line226">226. convert_arg(c)</span> | ||
Line 290: | Line 335: | ||
<span id="line285">285. }</span> | <span id="line285">285. }</span> | ||
<span id="line286">286. </span> | <span id="line286">286. </span> | ||
+ | |||
+ | == convert_line == | ||
+ | |||
<span id="line287">287. STATIC_OVL void</span> | <span id="line287">287. STATIC_OVL void</span> | ||
<span id="line288">288. convert_line()</span> | <span id="line288">288. convert_line()</span> | ||
Line 361: | Line 409: | ||
<span id="line356">356. }</span> | <span id="line356">356. }</span> | ||
<span id="line357">357. </span> | <span id="line357">357. </span> | ||
+ | |||
+ | == deliver_by_pline == | ||
+ | |||
<span id="line358">358. STATIC_OVL void</span> | <span id="line358">358. STATIC_OVL void</span> | ||
<span id="line359">359. deliver_by_pline(qt_msg)</span> | <span id="line359">359. deliver_by_pline(qt_msg)</span> | ||
Line 375: | Line 426: | ||
<span id="line370">370. }</span> | <span id="line370">370. }</span> | ||
<span id="line371">371. </span> | <span id="line371">371. </span> | ||
+ | |||
+ | == deliver_by_window == | ||
+ | |||
<span id="line372">372. STATIC_OVL void</span> | <span id="line372">372. STATIC_OVL void</span> | ||
<span id="line373">373. deliver_by_window(qt_msg, how)</span> | <span id="line373">373. deliver_by_window(qt_msg, how)</span> | ||
Line 392: | Line 446: | ||
<span id="line387">387. }</span> | <span id="line387">387. }</span> | ||
<span id="line388">388. </span> | <span id="line388">388. </span> | ||
+ | |||
+ | == com_pager == | ||
+ | |||
<span id="line389">389. void</span> | <span id="line389">389. void</span> | ||
<span id="line390">390. com_pager(msgnum)</span> | <span id="line390">390. com_pager(msgnum)</span> | ||
Line 410: | Line 467: | ||
<span id="line405">405. }</span> | <span id="line405">405. }</span> | ||
<span id="line406">406. </span> | <span id="line406">406. </span> | ||
+ | |||
+ | == qt_pager == | ||
+ | |||
<span id="line407">407. void</span> | <span id="line407">407. void</span> | ||
<span id="line408">408. qt_pager(msgnum)</span> | <span id="line408">408. qt_pager(msgnum)</span> | ||
Line 428: | Line 488: | ||
<span id="line423">423. }</span> | <span id="line423">423. }</span> | ||
<span id="line424">424. </span> | <span id="line424">424. </span> | ||
+ | |||
+ | == qt_montype == | ||
+ | |||
<span id="line425">425. struct permonst *</span> | <span id="line425">425. struct permonst *</span> | ||
<span id="line426">426. qt_montype()</span> | <span id="line426">426. qt_montype()</span> |
Latest revision as of 19:23, 31 January 2011
Below is the full text to src/questpgr.c from NetHack 3.4.3. To link to a particular line, write [[questpgr.c#line123]], for example.
Contents
Top of file
/* SCCS Id: @(#)questpgr.c 3.4 2000/05/05 */
/* Copyright 1991, M. Stephenson */
/* NetHack may be freely redistributed. See license for details. */
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
#include "hack.h"
#include "dlb.h"
/* quest-specific pager routines. */
#include "qtext.h"
#define QTEXT_FILE "quest.dat"
/* #define DEBUG */ /* uncomment for debugging */
static void FDECL(Fread, (genericptr_t,int,int,dlb *));
STATIC_DCL struct qtmsg * FDECL(construct_qtlist, (long));
STATIC_DCL const char * NDECL(intermed);
STATIC_DCL const char * NDECL(neminame);
STATIC_DCL const char * NDECL(guardname);
STATIC_DCL const char * NDECL(homebase);
STATIC_DCL struct qtmsg * FDECL(msg_in, (struct qtmsg *,int));
STATIC_DCL void FDECL(convert_arg, (CHAR_P));
STATIC_DCL void NDECL(convert_line);
STATIC_DCL void FDECL(deliver_by_pline, (struct qtmsg *));
STATIC_DCL void FDECL(deliver_by_window, (struct qtmsg *,int));
static char in_line[80], cvt_buf[64], out_line[128];
static struct qtlists qt_list;
static dlb *msg_file;
/* used by ldrname() and neminame(), then copied into cvt_buf */
static char nambuf[sizeof cvt_buf];
#ifdef DEBUG
static void NDECL(dump_qtlist);
dump_qtlist
static void
dump_qtlist() /* dump the character msg list to check appearance */
{
struct qtmsg *msg;
long size;
for (msg = qt_list.chrole; msg->msgnum > 0; msg++) {
pline("msgnum %d: delivery %c",
msg->msgnum, msg->delivery);
more();
(void) dlb_fseek(msg_file, msg->offset, SEEK_SET);
deliver_by_window(msg, NHW_TEXT);
}
}
#endif /* DEBUG */
Fread
static void
Fread(ptr, size, nitems, stream)
genericptr_t ptr;
int size, nitems;
dlb *stream;
{
int cnt;
if ((cnt = dlb_fread(ptr, size, nitems, stream)) != nitems) {
panic("PREMATURE EOF ON QUEST TEXT FILE! Expected %d bytes, got %d",
(size * nitems), (size * cnt));
}
}
construct_qtlist
STATIC_OVL struct qtmsg *
construct_qtlist(hdr_offset)
long hdr_offset;
{
struct qtmsg *msg_list;
int n_msgs;
(void) dlb_fseek(msg_file, hdr_offset, SEEK_SET);
Fread(&n_msgs, sizeof(int), 1, msg_file);
msg_list = (struct qtmsg *)
alloc((unsigned)(n_msgs+1)*sizeof(struct qtmsg));
/*
* Load up the list.
*/
Fread((genericptr_t)msg_list, n_msgs*sizeof(struct qtmsg), 1, msg_file);
msg_list[n_msgs].msgnum = -1;
return(msg_list);
}
load_qtlist
void
load_qtlist()
{
int n_classes, i;
char qt_classes[N_HDR][LEN_HDR];
long qt_offsets[N_HDR];
msg_file = dlb_fopen(QTEXT_FILE, RDBMODE);
if (!msg_file)
panic("CANNOT OPEN QUEST TEXT FILE %s.", QTEXT_FILE);
/*
* Read in the number of classes, then the ID's & offsets for
* each header.
*/
Fread(&n_classes, sizeof(int), 1, msg_file);
Fread(&qt_classes[0][0], sizeof(char)*LEN_HDR, n_classes, msg_file);
Fread(qt_offsets, sizeof(long), n_classes, msg_file);
/*
* Now construct the message lists for quick reference later
* on when we are actually paging the messages out.
*/
qt_list.common = qt_list.chrole = (struct qtmsg *)0;
for (i = 0; i < n_classes; i++) {
if (!strncmp(COMMON_ID, qt_classes[i], LEN_HDR))
qt_list.common = construct_qtlist(qt_offsets[i]);
else if (!strncmp(urole.filecode, qt_classes[i], LEN_HDR))
qt_list.chrole = construct_qtlist(qt_offsets[i]);
#if 0 /* UNUSED but available */
else if (!strncmp(urace.filecode, qt_classes[i], LEN_HDR))
qt_list.chrace = construct_qtlist(qt_offsets[i]);
#endif
}
if (!qt_list.common || !qt_list.chrole)
impossible("load_qtlist: cannot load quest text.");
#ifdef DEBUG
dump_qtlist();
#endif
return; /* no ***DON'T*** close the msg_file */
}
unload_qtlist
/* called at program exit */
void
unload_qtlist()
{
if (msg_file)
(void) dlb_fclose(msg_file), msg_file = 0;
if (qt_list.common)
free((genericptr_t) qt_list.common), qt_list.common = 0;
if (qt_list.chrole)
free((genericptr_t) qt_list.chrole), qt_list.chrole = 0;
return;
}
quest_info
short
quest_info(typ)
int typ;
{
switch (typ) {
case 0: return (urole.questarti);
case MS_LEADER: return (urole.ldrnum);
case MS_NEMESIS: return (urole.neminum);
case MS_GUARDIAN: return (urole.guardnum);
default: impossible("quest_info(%d)", typ);
}
return 0;
}
ldrname
const char *
ldrname() /* return your role leader's name */
{
int i = urole.ldrnum;
Sprintf(nambuf, "%s%s",
type_is_pname(&mons[i]) ? "" : "the ",
mons[i].mname);
return nambuf;
}
intermed
STATIC_OVL const char *
intermed() /* return your intermediate target string */
{
return (urole.intermed);
}
is_quest_artifact
boolean
is_quest_artifact(otmp)
struct obj *otmp;
{
return((boolean)(otmp->oartifact == urole.questarti));
}
neminame
STATIC_OVL const char *
neminame() /* return your role nemesis' name */
{
int i = urole.neminum;
Sprintf(nambuf, "%s%s",
type_is_pname(&mons[i]) ? "" : "the ",
mons[i].mname);
return nambuf;
}
guardname
STATIC_OVL const char *
guardname() /* return your role leader's guard monster name */
{
int i = urole.guardnum;
return(mons[i].mname);
}
homebase
STATIC_OVL const char *
homebase() /* return your role leader's location */
{
return(urole.homebase);
}
msg_in
STATIC_OVL struct qtmsg *
msg_in(qtm_list, msgnum)
struct qtmsg *qtm_list;
int msgnum;
{
struct qtmsg *qt_msg;
for (qt_msg = qtm_list; qt_msg->msgnum > 0; qt_msg++)
if (qt_msg->msgnum == msgnum) return(qt_msg);
return((struct qtmsg *)0);
}
convert_arg
STATIC_OVL void
convert_arg(c)
char c;
{
register const char *str;
switch (c) {
case 'p': str = plname;
break;
case 'c': str = (flags.female && urole.name.f) ?
urole.name.f : urole.name.m;
break;
case 'r': str = rank_of(u.ulevel, Role_switch, flags.female);
break;
case 'R': str = rank_of(MIN_QUEST_LEVEL, Role_switch,
flags.female);
break;
case 's': str = (flags.female) ? "sister" : "brother";
break;
case 'S': str = (flags.female) ? "daughter" : "son";
break;
case 'l': str = ldrname();
break;
case 'i': str = intermed();
break;
case 'o': str = the(artiname(urole.questarti));
break;
case 'n': str = neminame();
break;
case 'g': str = guardname();
break;
case 'G': str = align_gtitle(u.ualignbase[A_ORIGINAL]);
break;
case 'H': str = homebase();
break;
case 'a': str = align_str(u.ualignbase[A_ORIGINAL]);
break;
case 'A': str = align_str(u.ualign.type);
break;
case 'd': str = align_gname(u.ualignbase[A_ORIGINAL]);
break;
case 'D': str = align_gname(A_LAWFUL);
break;
case 'C': str = "chaotic";
break;
case 'N': str = "neutral";
break;
case 'L': str = "lawful";
break;
case 'x': str = Blind ? "sense" : "see";
break;
case 'Z': str = dungeons[0].dname;
break;
case '%': str = "%";
break;
default: str = "";
break;
}
Strcpy(cvt_buf, str);
}
convert_line
STATIC_OVL void
convert_line()
{
char *c, *cc;
char xbuf[BUFSZ];
cc = out_line;
for (c = xcrypt(in_line, xbuf); *c; c++) {
*cc = 0;
switch(*c) {
case '\r':
case '\n':
*(++cc) = 0;
return;
case '%':
if (*(c+1)) {
convert_arg(*(++c));
switch (*(++c)) {
/* insert "a"/"an" prefix */
case 'A': Strcat(cc, An(cvt_buf));
cc += strlen(cc);
continue; /* for */
case 'a': Strcat(cc, an(cvt_buf));
cc += strlen(cc);
continue; /* for */
/* capitalize */
case 'C': cvt_buf[0] = highc(cvt_buf[0]);
break;
/* pluralize */
case 'P': cvt_buf[0] = highc(cvt_buf[0]);
case 'p': Strcpy(cvt_buf, makeplural(cvt_buf));
break;
/* append possessive suffix */
case 'S': cvt_buf[0] = highc(cvt_buf[0]);
case 's': Strcpy(cvt_buf, s_suffix(cvt_buf));
break;
/* strip any "the" prefix */
case 't': if (!strncmpi(cvt_buf, "the ", 4)) {
Strcat(cc, &cvt_buf[4]);
cc += strlen(cc);
continue; /* for */
}
break;
default: --c; /* undo switch increment */
break;
}
Strcat(cc, cvt_buf);
cc += strlen(cvt_buf);
break;
} /* else fall through */
default:
*cc++ = *c;
break;
}
}
if (cc >= out_line + sizeof out_line)
panic("convert_line: overflow");
*cc = 0;
return;
}
deliver_by_pline
STATIC_OVL void
deliver_by_pline(qt_msg)
struct qtmsg *qt_msg;
{
long size;
for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) {
(void) dlb_fgets(in_line, 80, msg_file);
convert_line();
pline(out_line);
}
}
deliver_by_window
STATIC_OVL void
deliver_by_window(qt_msg, how)
struct qtmsg *qt_msg;
int how;
{
long size;
winid datawin = create_nhwindow(how);
for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) {
(void) dlb_fgets(in_line, 80, msg_file);
convert_line();
putstr(datawin, 0, out_line);
}
display_nhwindow(datawin, TRUE);
destroy_nhwindow(datawin);
}
com_pager
void
com_pager(msgnum)
int msgnum;
{
struct qtmsg *qt_msg;
if (!(qt_msg = msg_in(qt_list.common, msgnum))) {
impossible("com_pager: message %d not found.", msgnum);
return;
}
(void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET);
if (qt_msg->delivery == 'p') deliver_by_pline(qt_msg);
else if (msgnum == 1) deliver_by_window(qt_msg, NHW_MENU);
else deliver_by_window(qt_msg, NHW_TEXT);
return;
}
qt_pager
void
qt_pager(msgnum)
int msgnum;
{
struct qtmsg *qt_msg;
if (!(qt_msg = msg_in(qt_list.chrole, msgnum))) {
impossible("qt_pager: message %d not found.", msgnum);
return;
}
(void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET);
if (qt_msg->delivery == 'p' && strcmp(windowprocs.name, "X11"))
deliver_by_pline(qt_msg);
else deliver_by_window(qt_msg, NHW_TEXT);
return;
}
qt_montype
struct permonst *
qt_montype()
{
int qpm;
if (rn2(5)) {
qpm = urole.enemy1num;
if (qpm != NON_PM && rn2(5) && !(mvitals[qpm].mvflags & G_GENOD))
return (&mons[qpm]);
return (mkclass(urole.enemy1sym, 0));
}
qpm = urole.enemy2num;
if (qpm != NON_PM && rn2(5) && !(mvitals[qpm].mvflags & G_GENOD))
return (&mons[qpm]);
return (mkclass(urole.enemy2sym, 0));
}
/*questpgr.c*/