Re-format to consistent indent style with "make indent".

This commit is contained in:
Eric S. Raymond 2017-06-18 06:18:51 -04:00
parent a37e578f63
commit b3057f038b
8 changed files with 2516 additions and 2419 deletions

1510
actions.c

File diff suppressed because it is too large Load diff

View file

@ -1,34 +1,34 @@
#include "common.h"
const char advent_to_ascii[] = {
' ', '!', '\"', '\'', '(', ')', '*', '+', ',', '-',
'.', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c',
'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '%', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05',
'\x06', '\x07', '\x08', '\x00', '\x00', '\x0b', '\x0c', '\r', '\x0e', '\x0f',
'\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19',
'\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', '#', '$', '&', '/',
':', ';', '<', '=', '>', '?', '@', '[', '\\', ']',
'^', '_', '`', '{', '|', '}', '~', '\x00',
' ', '!', '\"', '\'', '(', ')', '*', '+', ',', '-',
'.', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c',
'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '%', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05',
'\x06', '\x07', '\x08', '\x00', '\x00', '\x0b', '\x0c', '\r', '\x0e', '\x0f',
'\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19',
'\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', '#', '$', '&', '/',
':', ';', '<', '=', '>', '?', '@', '[', '\\', ']',
'^', '_', '`', '{', '|', '}', '~', '\x00',
};
/* Rendered from the now-gone MPINIT() function */
const char ascii_to_advent[] = {
74, 75, 76, 77, 78, 79, 80, 81, 82, 0,
0, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 0, 1, 2, 106, 107, 63, 108, 3,
4, 5, 6, 7, 8, 9, 10, 109, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 110, 111,
112, 113, 114, 115, 116, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 117, 118, 119, 120, 121, 122, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 123, 124, 125, 126, 83,
74, 75, 76, 77, 78, 79, 80, 81, 82, 0,
0, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 0, 1, 2, 106, 107, 63, 108, 3,
4, 5, 6, 7, 8, 9, 10, 109, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 110, 111,
112, 113, 114, 115, 116, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 117, 118, 119, 120, 121, 122, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 123, 124, 125, 126, 83,
};

825
dungeon.c
View file

@ -24,7 +24,7 @@
// Global variables for use in functions below that can gradually disappear as code is cleaned up
static long LNLENG;
static long LNPOSN;
static char INLINE[LINESIZE+1];
static char INLINE[LINESIZE + 1];
static long OLDLOC;
// Storage for what comes out of the database
@ -34,11 +34,11 @@ long CLSSES;
long TRNVLS;
long TABNDX;
long HNTMAX;
long PTEXT[NOBJECTS+1];
long PTEXT[NOBJECTS + 1];
long RTEXT[RTXSIZ + 1];
long CTEXT[CLSMAX + 1];
long OBJSND[NOBJECTS+1];
long OBJTXT[NOBJECTS+1];
long OBJSND[NOBJECTS + 1];
long OBJTXT[NOBJECTS + 1];
long STEXT[LOCSIZ + 1];
long LTEXT[LOCSIZ + 1];
long COND[LOCSIZ + 1];
@ -51,245 +51,234 @@ long TRNVAL[TRNSIZ + 1];
long TRAVEL[TRVSIZ + 1];
long KTAB[TABSIZ + 1];
long ATAB[TABSIZ + 1];
long PLAC[NOBJECTS+1];
long FIXD[NOBJECTS+1];
long PLAC[NOBJECTS + 1];
long FIXD[NOBJECTS + 1];
long ACTSPK[VRBSIZ + 1];
long HINTS[HNTSIZ + 1][HINTLEN];
static bool is_set(long var, long position)
{
long mask = 1l << position;
bool result = (var & mask) == mask;
return(result);
long mask = 1l << position;
bool result = (var & mask) == mask;
return (result);
}
static long GETTXT(long SKIP,long ONEWRD, long UPPER)
static long GETTXT(long SKIP, long ONEWRD, long UPPER)
{
/* Take characters from an input line and pack them into 30-bit words.
* Skip says to skip leading blanks. ONEWRD says stop if we come to a
* blank. UPPER says to map all letters to uppercase. If we reach the
* end of the line, the word is filled up with blanks (which encode as 0's).
* If we're already at end of line when GETTXT is called, we return -1. */
/* Take characters from an input line and pack them into 30-bit words.
* Skip says to skip leading blanks. ONEWRD says stop if we come to a
* blank. UPPER says to map all letters to uppercase. If we reach the
* end of the line, the word is filled up with blanks (which encode as 0's).
* If we're already at end of line when GETTXT is called, we return -1. */
long TEXT;
static long SPLITTING = -1;
long TEXT;
static long SPLITTING = -1;
if(LNPOSN != SPLITTING)
SPLITTING = -1;
TEXT= -1;
while (true) {
if(LNPOSN > LNLENG)
return(TEXT);
if((!SKIP) || INLINE[LNPOSN] != 0)
break;
LNPOSN=LNPOSN+1;
}
if (LNPOSN != SPLITTING)
SPLITTING = -1;
TEXT = -1;
while (true) {
if (LNPOSN > LNLENG)
return (TEXT);
if ((!SKIP) || INLINE[LNPOSN] != 0)
break;
LNPOSN = LNPOSN + 1;
}
TEXT=0;
for (int I=1; I<=TOKLEN; I++) {
TEXT=TEXT*64;
if(LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0))
continue;
char current=INLINE[LNPOSN];
if(current < 63) {
SPLITTING = -1;
if(UPPER && current >= 37)
current=current-26;
TEXT=TEXT+current;
LNPOSN=LNPOSN+1;
continue;
}
if(SPLITTING != LNPOSN) {
TEXT=TEXT+63;
SPLITTING = LNPOSN;
continue;
}
TEXT = 0;
for (int I = 1; I <= TOKLEN; I++) {
TEXT = TEXT * 64;
if (LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0))
continue;
char current = INLINE[LNPOSN];
if (current < 63) {
SPLITTING = -1;
if (UPPER && current >= 37)
current = current - 26;
TEXT = TEXT + current;
LNPOSN = LNPOSN + 1;
continue;
}
if (SPLITTING != LNPOSN) {
TEXT = TEXT + 63;
SPLITTING = LNPOSN;
continue;
}
TEXT=TEXT+current-63;
SPLITTING = -1;
LNPOSN=LNPOSN+1;
}
TEXT = TEXT + current - 63;
SPLITTING = -1;
LNPOSN = LNPOSN + 1;
}
return(TEXT);
return (TEXT);
}
static void BUG(long NUM) {
static void BUG(long NUM)
{
/* The following conditions are currently considered fatal bugs. Numbers < 20
* are detected while reading the database; the others occur at "run time".
* 0 Message line > 70 characters
* 1 Null line in message
* 2 Too many words of messages
* 3 Too many travel options
* 4 Too many vocabulary words
* 5 Required vocabulary word not found
* 6 Too many RTEXT messages
* 7 Too many hints
* 8 Location has cond bit being set twice
* 9 Invalid section number in database
* 10 Too many locations
* 11 Too many class or turn messages
* 20 Special travel (500>L>300) exceeds goto list
* 21 Ran off end of vocabulary table
* 22 Vocabulary type (N/1000) not between 0 and 3
* 23 Intransitive action verb exceeds goto list
* 24 Transitive action verb exceeds goto list
* 25 Conditional travel entry with no alternative
* 26 Location has no travel entries
* 27 Hint number exceeds goto list
* 28 Invalid month returned by date function
* 29 Too many parameters given to SETPRM */
/* The following conditions are currently considered fatal bugs. Numbers < 20
* are detected while reading the database; the others occur at "run time".
* 0 Message line > 70 characters
* 1 Null line in message
* 2 Too many words of messages
* 3 Too many travel options
* 4 Too many vocabulary words
* 5 Required vocabulary word not found
* 6 Too many RTEXT messages
* 7 Too many hints
* 8 Location has cond bit being set twice
* 9 Invalid section number in database
* 10 Too many locations
* 11 Too many class or turn messages
* 20 Special travel (500>L>300) exceeds goto list
* 21 Ran off end of vocabulary table
* 22 Vocabulary type (N/1000) not between 0 and 3
* 23 Intransitive action verb exceeds goto list
* 24 Transitive action verb exceeds goto list
* 25 Conditional travel entry with no alternative
* 26 Location has no travel entries
* 27 Hint number exceeds goto list
* 28 Invalid month returned by date function
* 29 Too many parameters given to SETPRM */
fprintf(stderr, "Fatal error %ld. See source code for interpretation.\n", NUM);
exit(EXIT_FAILURE);
fprintf(stderr, "Fatal error %ld. See source code for interpretation.\n", NUM);
exit(EXIT_FAILURE);
}
static void MAPLIN(FILE *OPENED) {
/* Read a line of input, from the specified input source,
* translate the chars to integers in the range 0-126 and store
* them in the common array "INLINE". Integer values are as follows:
* 0 = space [ASCII CODE 40 octal, 32 decimal]
* 1-2 = !" [ASCII 41-42 octal, 33-34 decimal]
* 3-10 = '()*+,-. [ASCII 47-56 octal, 39-46 decimal]
* 11-36 = upper-case letters
* 37-62 = lower-case letters
* 63 = percent (%) [ASCII 45 octal, 37 decimal]
* 64-73 = digits, 0 through 9
* Remaining characters can be translated any way that is convenient;
* The "TYPE" routine below is used to map them back to characters when
* necessary. The above mappings are required so that certain special
* characters are known to fit in 6 bits and/or can be easily spotted.
* Array elements beyond the end of the line should be filled with 0,
* and LNLENG should be set to the index of the last character.
*
* If the data file uses a character other than space (e.g., tab) to
* separate numbers, that character should also translate to 0.
*
* This procedure may use the map1,map2 arrays to maintain static data for
* the mapping. MAP2(1) is set to 0 when the program starts
* and is not changed thereafter unless the routines on this page choose
* to do so. */
static void MAPLIN(FILE *OPENED)
{
/* Read a line of input, from the specified input source,
* translate the chars to integers in the range 0-126 and store
* them in the common array "INLINE". Integer values are as follows:
* 0 = space [ASCII CODE 40 octal, 32 decimal]
* 1-2 = !" [ASCII 41-42 octal, 33-34 decimal]
* 3-10 = '()*+,-. [ASCII 47-56 octal, 39-46 decimal]
* 11-36 = upper-case letters
* 37-62 = lower-case letters
* 63 = percent (%) [ASCII 45 octal, 37 decimal]
* 64-73 = digits, 0 through 9
* Remaining characters can be translated any way that is convenient;
* The "TYPE" routine below is used to map them back to characters when
* necessary. The above mappings are required so that certain special
* characters are known to fit in 6 bits and/or can be easily spotted.
* Array elements beyond the end of the line should be filled with 0,
* and LNLENG should be set to the index of the last character.
*
* If the data file uses a character other than space (e.g., tab) to
* separate numbers, that character should also translate to 0.
*
* This procedure may use the map1,map2 arrays to maintain static data for
* the mapping. MAP2(1) is set to 0 when the program starts
* and is not changed thereafter unless the routines on this page choose
* to do so. */
do {
if (NULL == fgets(INLINE + 1, sizeof(INLINE) - 1, OPENED)) {
printf("Failed fgets()\n");
}
}
while (!feof(OPENED) && INLINE[1] == '#');
do {
if (NULL == fgets(INLINE + 1, sizeof(INLINE) - 1, OPENED)) {
printf("Failed fgets()\n");
}
} while (!feof(OPENED) && INLINE[1] == '#');
LNLENG = 0;
for (size_t i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i)
{
char val = INLINE[i];
INLINE[i] = ascii_to_advent[(unsigned)val];
if (INLINE[i] != 0)
LNLENG = i;
}
LNPOSN = 1;
LNLENG = 0;
for (size_t i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i) {
char val = INLINE[i];
INLINE[i] = ascii_to_advent[(unsigned)val];
if (INLINE[i] != 0)
LNLENG = i;
}
LNPOSN = 1;
}
static long GETNUM(FILE *source) {
/* Obtain the next integer from an input line. If K>0, we first read a
* new input line from a file; if K<0, we read a line from the keyboard;
* if K=0 we use a line that has already been read (and perhaps partially
* scanned). If we're at the end of the line or encounter an illegal
* character (not a digit, hyphen, or blank), we return 0. */
static long GETNUM(FILE *source)
{
/* Obtain the next integer from an input line. If K>0, we first read a
* new input line from a file; if K<0, we read a line from the keyboard;
* if K=0 we use a line that has already been read (and perhaps partially
* scanned). If we're at the end of the line or encounter an illegal
* character (not a digit, hyphen, or blank), we return 0. */
long DIGIT, GETNUM, SIGN;
long DIGIT, GETNUM, SIGN;
if(source != NULL) MAPLIN(source);
GETNUM = 0;
if (source != NULL) MAPLIN(source);
GETNUM = 0;
while (INLINE[LNPOSN] == 0) {
if (LNPOSN > LNLENG) return(GETNUM);
++LNPOSN;
}
while (INLINE[LNPOSN] == 0) {
if (LNPOSN > LNLENG) return (GETNUM);
++LNPOSN;
}
if(INLINE[LNPOSN] != 9)
{
SIGN=1;
}
else
{
SIGN= -1;
LNPOSN=LNPOSN+1;
}
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0))
{
DIGIT=INLINE[LNPOSN]-64;
if(DIGIT < 0 || DIGIT > 9)
{
GETNUM=0;
break;
}
GETNUM=GETNUM*10+DIGIT;
LNPOSN=LNPOSN+1;
}
if (INLINE[LNPOSN] != 9) {
SIGN = 1;
} else {
SIGN = -1;
LNPOSN = LNPOSN + 1;
}
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0)) {
DIGIT = INLINE[LNPOSN] - 64;
if (DIGIT < 0 || DIGIT > 9) {
GETNUM = 0;
break;
}
GETNUM = GETNUM * 10 + DIGIT;
LNPOSN = LNPOSN + 1;
}
GETNUM=GETNUM*SIGN;
LNPOSN=LNPOSN+1;
return(GETNUM);
GETNUM = GETNUM * SIGN;
LNPOSN = LNPOSN + 1;
return (GETNUM);
}
/* Sections 1, 2, 5, 6, 10, 14. Read messages and set up pointers. */
static void read_messages(FILE* database, long sect)
{
long KK=LINUSE;
while(true)
{
long loc;
LINUSE=KK;
loc=GETNUM(database);
if(LNLENG >= LNPOSN+70)BUG(0);
if(loc == -1) return;
if(LNLENG < LNPOSN)BUG(1);
do {
KK=KK+1;
if(KK >= LINSIZ)BUG(2);
LINES[KK]=GETTXT(false,false,false);
}
while(LINES[KK] != -1);
LINES[LINUSE]=KK;
if(loc == OLDLOC) continue;
OLDLOC=loc;
LINES[LINUSE]= -KK;
if(sect == 14)
{
TRNVLS=TRNVLS+1;
if(TRNVLS > TRNSIZ)BUG(11);
TTEXT[TRNVLS]=LINUSE;
TRNVAL[TRNVLS]=loc;
continue;
}
if(sect == 10)
{
CLSSES=CLSSES+1;
if(CLSSES > CLSMAX)BUG(11);
CTEXT[CLSSES]=LINUSE;
CVAL[CLSSES]=loc;
continue;
}
if(sect == 6)
{
if(loc > RTXSIZ)BUG(6);
RTEXT[loc]=LINUSE;
continue;
}
if(sect == 5)
{
if(loc > 0 && loc <= NOBJECTS)PTEXT[loc]=LINUSE;
continue;
}
if(loc > LOCSIZ)BUG(10);
if(sect == 1)
{
LTEXT[loc]=LINUSE;
continue;
}
long KK = LINUSE;
while (true) {
long loc;
LINUSE = KK;
loc = GETNUM(database);
if (LNLENG >= LNPOSN + 70)BUG(0);
if (loc == -1) return;
if (LNLENG < LNPOSN)BUG(1);
do {
KK = KK + 1;
if (KK >= LINSIZ)BUG(2);
LINES[KK] = GETTXT(false, false, false);
} while (LINES[KK] != -1);
LINES[LINUSE] = KK;
if (loc == OLDLOC) continue;
OLDLOC = loc;
LINES[LINUSE] = -KK;
if (sect == 14) {
TRNVLS = TRNVLS + 1;
if (TRNVLS > TRNSIZ)BUG(11);
TTEXT[TRNVLS] = LINUSE;
TRNVAL[TRNVLS] = loc;
continue;
}
if (sect == 10) {
CLSSES = CLSSES + 1;
if (CLSSES > CLSMAX)BUG(11);
CTEXT[CLSSES] = LINUSE;
CVAL[CLSSES] = loc;
continue;
}
if (sect == 6) {
if (loc > RTXSIZ)BUG(6);
RTEXT[loc] = LINUSE;
continue;
}
if (sect == 5) {
if (loc > 0 && loc <= NOBJECTS)PTEXT[loc] = LINUSE;
continue;
}
if (loc > LOCSIZ)BUG(10);
if (sect == 1) {
LTEXT[loc] = LINUSE;
continue;
}
STEXT[loc]=LINUSE;
}
STEXT[loc] = LINUSE;
}
}
/* The stuff for section 3 is encoded here. Each "from-location" gets a
@ -299,27 +288,22 @@ static void read_messages(FILE* database, long sect)
* of the first option at location N. */
static void read_section3_stuff(FILE* database)
{
long loc;
while((loc=GETNUM(database)) != -1)
{
long newloc=GETNUM(NULL);
long L;
if(KEY[loc] == 0)
{
KEY[loc]=TRVS;
}
else
{
TRAVEL[TRVS-1]= -TRAVEL[TRVS-1];
}
while((L=GETNUM(NULL)) != 0)
{
TRAVEL[TRVS]=newloc*1000+L;
TRVS=TRVS+1;
if(TRVS == TRVSIZ)BUG(3);
}
TRAVEL[TRVS-1]= -TRAVEL[TRVS-1];
}
long loc;
while ((loc = GETNUM(database)) != -1) {
long newloc = GETNUM(NULL);
long L;
if (KEY[loc] == 0) {
KEY[loc] = TRVS;
} else {
TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
}
while ((L = GETNUM(NULL)) != 0) {
TRAVEL[TRVS] = newloc * 1000 + L;
TRVS = TRVS + 1;
if (TRVS == TRVSIZ)BUG(3);
}
TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
}
}
/* Here we read in the vocabulary. KTAB(N) is the word number, ATAB(N) is
@ -327,13 +311,12 @@ static void read_section3_stuff(FILE* database)
* as an end-marker. */
static void read_vocabulary(FILE* database)
{
for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++)
{
KTAB[TABNDX]=GETNUM(database);
if(KTAB[TABNDX] == -1) return;
ATAB[TABNDX]=GETTXT(true,true,true);
} /* end loop */
BUG(4);
for (TABNDX = 1; TABNDX <= TABSIZ; TABNDX++) {
KTAB[TABNDX] = GETNUM(database);
if (KTAB[TABNDX] == -1) return;
ATAB[TABNDX] = GETTXT(true, true, true);
} /* end loop */
BUG(4);
}
/* Read in the initial locations for each object. Also the immovability info.
@ -341,138 +324,158 @@ static void read_vocabulary(FILE* database)
* objects (including the snake), or = second loc for two-placed objects. */
static void read_initial_locations(FILE* database)
{
long OBJ;
while((OBJ=GETNUM(database)) != -1)
{
PLAC[OBJ]=GETNUM(NULL);
FIXD[OBJ]=GETNUM(NULL);
}
long OBJ;
while ((OBJ = GETNUM(database)) != -1) {
PLAC[OBJ] = GETNUM(NULL);
FIXD[OBJ] = GETNUM(NULL);
}
}
/* Read default message numbers for action verbs, store in ACTSPK. */
static void read_action_verb_message_nr(FILE* database)
{
long verb;
while((verb=GETNUM(database)) != -1)
{
ACTSPK[verb]=GETNUM(NULL);
}
long verb;
while ((verb = GETNUM(database)) != -1) {
ACTSPK[verb] = GETNUM(NULL);
}
}
/* Read info about available liquids and other conditions, store in COND. */
static void read_conditions(FILE* database)
{
long K;
while((K=GETNUM(database)) != -1)
{
long loc;
while((loc=GETNUM(NULL)) != 0)
{
if(is_set(COND[loc],K)) BUG(8);
COND[loc]=COND[loc] + (1l << K);
}
}
long K;
while ((K = GETNUM(database)) != -1) {
long loc;
while ((loc = GETNUM(NULL)) != 0) {
if (is_set(COND[loc], K)) BUG(8);
COND[loc] = COND[loc] + (1l << K);
}
}
}
/* Read data for hints. */
static void read_hints(FILE* database)
{
long K;
HNTMAX=0;
while((K=GETNUM(database)) != -1)
{
if(K <= 0 || K > HNTSIZ)BUG(7);
for (int I=1; I<=4; I++)
{
HINTS[K][I] =GETNUM(NULL);
} /* end loop */
HNTMAX=(HNTMAX>K ? HNTMAX : K);
}
long K;
HNTMAX = 0;
while ((K = GETNUM(database)) != -1) {
if (K <= 0 || K > HNTSIZ)BUG(7);
for (int I = 1; I <= 4; I++) {
HINTS[K][I] = GETNUM(NULL);
} /* end loop */
HNTMAX = (HNTMAX > K ? HNTMAX : K);
}
}
/* Read the sound/text info, store in OBJSND, OBJTXT, LOCSND. */
static void read_sound_text(FILE* database)
{
long K;
while((K=GETNUM(database)) != -1)
{
long KK=GETNUM(NULL);
long I=GETNUM(NULL);
if(I != 0)
{
OBJSND[K]=(KK>0 ? KK : 0);
OBJTXT[K]=(I>0 ? I : 0);
continue;
}
long K;
while ((K = GETNUM(database)) != -1) {
long KK = GETNUM(NULL);
long I = GETNUM(NULL);
if (I != 0) {
OBJSND[K] = (KK > 0 ? KK : 0);
OBJTXT[K] = (I > 0 ? I : 0);
continue;
}
LOCSND[K]=KK;
}
LOCSND[K] = KK;
}
}
static int read_database(FILE* database) {
static int read_database(FILE* database)
{
/* Clear out the various text-pointer arrays. All text is stored in array
* lines; each line is preceded by a word pointing to the next pointer (i.e.
* the word following the end of the line). The pointer is negative if this is
* first line of a message. The text-pointer arrays contain indices of
* pointer-words in lines. STEXT(N) is short description of location N.
* LTEXT(N) is long description. PTEXT(N) points to message for game.prop(N)=0.
* Successive prop messages are found by chasing pointers. RTEXT contains
* section 6's stuff. CTEXT(N) points to a player-class message. TTEXT is for
* section 14. We also clear COND (see description of section 9 for details). */
/* Clear out the various text-pointer arrays. All text is stored in array
* lines; each line is preceded by a word pointing to the next pointer (i.e.
* the word following the end of the line). The pointer is negative if this is
* first line of a message. The text-pointer arrays contain indices of
* pointer-words in lines. STEXT(N) is short description of location N.
* LTEXT(N) is long description. PTEXT(N) points to message for game.prop(N)=0.
* Successive prop messages are found by chasing pointers. RTEXT contains
* section 6's stuff. CTEXT(N) points to a player-class message. TTEXT is for
* section 14. We also clear COND (see description of section 9 for details). */
for (int I=1; I<=NOBJECTS; I++) {
PTEXT[I] = 0;
OBJSND[I] = 0;
OBJTXT[I] = 0;
}
for (int I=1; I<=RTXSIZ; I++) {
RTEXT[I] = 0;
}
for (int I=1; I<=CLSMAX; I++) {
CTEXT[I] = 0;
}
for (int I=1; I<=LOCSIZ; I++) {
STEXT[I] = 0;
LTEXT[I] = 0;
COND[I] = 0;
KEY[I] = 0;
LOCSND[I] = 0;
}
for (int I = 1; I <= NOBJECTS; I++) {
PTEXT[I] = 0;
OBJSND[I] = 0;
OBJTXT[I] = 0;
}
for (int I = 1; I <= RTXSIZ; I++) {
RTEXT[I] = 0;
}
for (int I = 1; I <= CLSMAX; I++) {
CTEXT[I] = 0;
}
for (int I = 1; I <= LOCSIZ; I++) {
STEXT[I] = 0;
LTEXT[I] = 0;
COND[I] = 0;
KEY[I] = 0;
LOCSND[I] = 0;
}
LINUSE = 1;
TRVS = 1;
CLSSES = 0;
TRNVLS = 0;
LINUSE = 1;
TRVS = 1;
CLSSES = 0;
TRNVLS = 0;
/* Start new data section. Sect is the section number. */
/* Start new data section. Sect is the section number. */
while(true)
{
long sect=GETNUM(database);
OLDLOC= -1;
switch (sect)
{
case 0: return(0);
case 1: read_messages(database, sect); break;
case 2: read_messages(database, sect); break;
case 3: read_section3_stuff(database); break;
case 4: read_vocabulary(database); break;
case 5: read_messages(database, sect); break;
case 6: read_messages(database, sect); break;
case 7: read_initial_locations(database); break;
case 8: read_action_verb_message_nr(database); break;
case 9: read_conditions(database); break;
case 10: read_messages(database, sect); break;
case 11: read_hints(database); break;
case 12: break;
case 13: read_sound_text(database); break;
case 14: read_messages(database, sect); break;
default: BUG(9);
}
}
while (true) {
long sect = GETNUM(database);
OLDLOC = -1;
switch (sect) {
case 0:
return (0);
case 1:
read_messages(database, sect);
break;
case 2:
read_messages(database, sect);
break;
case 3:
read_section3_stuff(database);
break;
case 4:
read_vocabulary(database);
break;
case 5:
read_messages(database, sect);
break;
case 6:
read_messages(database, sect);
break;
case 7:
read_initial_locations(database);
break;
case 8:
read_action_verb_message_nr(database);
break;
case 9:
read_conditions(database);
break;
case 10:
read_messages(database, sect);
break;
case 11:
read_hints(database);
break;
case 12:
break;
case 13:
read_sound_text(database);
break;
case 14:
read_messages(database, sect);
break;
default:
BUG(9);
}
}
}
/* Finish constructing internal data format */
@ -489,103 +492,99 @@ static int read_database(FILE* database) {
static void write_0d(FILE* header_file, long single, const char* varname)
{
fprintf(header_file, "LOCATION long %s INITIALIZE(= %ld);\n", varname, single);
fprintf(header_file, "LOCATION long %s INITIALIZE(= %ld);\n", varname, single);
}
static void write_1d(FILE* header_file, long array[], long dim, const char* varname)
{
fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
for (int i = 0; i < dim; ++i)
{
if (i % 10 == 0)
{
if (i > 0)
fprintf(header_file, "\n");
fprintf(header_file, " ");
}
fprintf(header_file, "%ld, ", array[i]);
}
fprintf(header_file, "\n});\n");
fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
for (int i = 0; i < dim; ++i) {
if (i % 10 == 0) {
if (i > 0)
fprintf(header_file, "\n");
fprintf(header_file, " ");
}
fprintf(header_file, "%ld, ", array[i]);
}
fprintf(header_file, "\n});\n");
}
static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, const char* varname)
{
fprintf(header_file, "LOCATION long %s[][%ld] INITIALIZE(= {\n", varname, dim2);
for (int i = 0; i < dim1; ++i)
{
fprintf(header_file, " {");
for (int j = 0; j < dim2; ++j)
{
fprintf(header_file, "%ld, ", matrix[i][j]);
}
fprintf(header_file, "},\n");
}
fprintf(header_file, "});\n");
fprintf(header_file, "LOCATION long %s[][%ld] INITIALIZE(= {\n", varname, dim2);
for (int i = 0; i < dim1; ++i) {
fprintf(header_file, " {");
for (int j = 0; j < dim2; ++j) {
fprintf(header_file, "%ld, ", matrix[i][j]);
}
fprintf(header_file, "},\n");
}
fprintf(header_file, "});\n");
}
static void write_file(FILE* header_file)
{
int MAXDIE;
for (int i=0; i<=4; i++) {
long x = 2*i+81;
if(RTEXT[x] != 0)
MAXDIE=i+1;
}
int MAXDIE;
for (int i = 0; i <= 4; i++) {
long x = 2 * i + 81;
if (RTEXT[x] != 0)
MAXDIE = i + 1;
}
fprintf(header_file, "#ifndef DATABASE_H\n");
fprintf(header_file, "#define DATABASE_H\n");
fprintf(header_file, "\n");
fprintf(header_file, "#ifndef DATABASE_H\n");
fprintf(header_file, "#define DATABASE_H\n");
fprintf(header_file, "\n");
fprintf(header_file, "#include \"common.h\"\n");
fprintf(header_file, "#define TABSIZ 330\n");
fprintf(header_file, "#define HNTSIZ 20\n");
fprintf(header_file, "#define TOKLEN %d\n", TOKLEN);
fprintf(header_file, "#define MAXDIE %d\n", MAXDIE);
fprintf(header_file, "\n");
fprintf(header_file, "#include \"common.h\"\n");
fprintf(header_file, "#define TABSIZ 330\n");
fprintf(header_file, "#define HNTSIZ 20\n");
fprintf(header_file, "#define TOKLEN %d\n", TOKLEN);
fprintf(header_file, "#define MAXDIE %d\n", MAXDIE);
fprintf(header_file, "\n");
fprintf(header_file, "\n");
fprintf(header_file, "#ifdef DEFINE_GLOBALS_FROM_INCLUDES\n");
fprintf(header_file, "#define LOCATION\n");
fprintf(header_file, "#define INITIALIZE(...) __VA_ARGS__\n");
fprintf(header_file, "#else\n");
fprintf(header_file, "#define LOCATION extern\n");
fprintf(header_file, "#define INITIALIZE(...)\n");
fprintf(header_file, "#endif\n");
fprintf(header_file, "\n");
fprintf(header_file, "\n");
fprintf(header_file, "#ifdef DEFINE_GLOBALS_FROM_INCLUDES\n");
fprintf(header_file, "#define LOCATION\n");
fprintf(header_file, "#define INITIALIZE(...) __VA_ARGS__\n");
fprintf(header_file, "#else\n");
fprintf(header_file, "#define LOCATION extern\n");
fprintf(header_file, "#define INITIALIZE(...)\n");
fprintf(header_file, "#endif\n");
fprintf(header_file, "\n");
// content variables
write_0d(header_file, TRNVLS, "TRNVLS");
write_0d(header_file, HNTMAX, "HNTMAX");
write_1d(header_file, OBJSND, NOBJECTS + 1, "OBJSND");
write_1d(header_file, OBJTXT, NOBJECTS + 1, "OBJTXT");
write_1d(header_file, COND, LOCSIZ + 1, "COND");
write_1d(header_file, KEY, LOCSIZ + 1, "KEY");
write_1d(header_file, LOCSND, LOCSIZ + 1, "LOCSND");
write_1d(header_file, CVAL, CLSMAX + 1, "CVAL");
write_1d(header_file, TRNVAL, TRNSIZ + 1, "TRNVAL");
write_1d(header_file, TRAVEL, TRVSIZ + 1, "TRAVEL");
write_1d(header_file, KTAB, TABSIZ + 1, "KTAB");
write_1d(header_file, ATAB, TABSIZ + 1, "ATAB");
write_1d(header_file, PLAC, NOBJECTS + 1, "PLAC");
write_1d(header_file, FIXD, NOBJECTS + 1, "FIXD");
write_1d(header_file, ACTSPK, VRBSIZ + 1, "ACTSPK");
write_hints(header_file, HINTS, HNTSIZ + 1, 5, "HINTS");
// content variables
write_0d(header_file, TRNVLS, "TRNVLS");
write_0d(header_file, HNTMAX, "HNTMAX");
write_1d(header_file, OBJSND, NOBJECTS + 1, "OBJSND");
write_1d(header_file, OBJTXT, NOBJECTS + 1, "OBJTXT");
write_1d(header_file, COND, LOCSIZ + 1, "COND");
write_1d(header_file, KEY, LOCSIZ + 1, "KEY");
write_1d(header_file, LOCSND, LOCSIZ + 1, "LOCSND");
write_1d(header_file, CVAL, CLSMAX + 1, "CVAL");
write_1d(header_file, TRNVAL, TRNSIZ + 1, "TRNVAL");
write_1d(header_file, TRAVEL, TRVSIZ + 1, "TRAVEL");
write_1d(header_file, KTAB, TABSIZ + 1, "KTAB");
write_1d(header_file, ATAB, TABSIZ + 1, "ATAB");
write_1d(header_file, PLAC, NOBJECTS + 1, "PLAC");
write_1d(header_file, FIXD, NOBJECTS + 1, "FIXD");
write_1d(header_file, ACTSPK, VRBSIZ + 1, "ACTSPK");
write_hints(header_file, HINTS, HNTSIZ + 1, 5, "HINTS");
fprintf(header_file, "#undef LOCATION\n");
fprintf(header_file, "#undef INITIALIZE\n");
fprintf(header_file, "#endif\n");
fprintf(header_file, "#undef LOCATION\n");
fprintf(header_file, "#undef INITIALIZE\n");
fprintf(header_file, "#endif\n");
}
int main(void)
{
FILE* database = fopen("adventure.text", "r");
read_database(database);
fclose(database);
FILE* database = fopen("adventure.text", "r");
read_database(database);
fclose(database);
FILE* header_file = fopen("database.h", "w");
write_file(header_file);
fclose(header_file);
FILE* header_file = fopen("database.h", "w");
write_file(header_file);
fclose(header_file);
return(EXIT_SUCCESS);
return (EXIT_SUCCESS);
}

258
init.c
View file

@ -30,7 +30,7 @@
* 1000 non-synonymous vocabulary words
* 300 locations
* 100 objects
* Note:
* Note:
* - the object count limit has been abstracted as NOBJECTS
* - the random message limit has been abstracted as RTXSIZ
* - maximum locations limit has been abstracted as LOCSIZ
@ -173,21 +173,21 @@
void initialise(void)
{
if (oldstyle)
printf("Initialising...\n");
printf("Initialising...\n");
for (int i=1; i<=NOBJECTS; i++) {
game.place[i] = NOWHERE;
game.prop[i] = 0;
game.link[i+NOBJECTS]=game.link[i]=0;
for (int i = 1; i <= NOBJECTS; i++) {
game.place[i] = NOWHERE;
game.prop[i] = 0;
game.link[i + NOBJECTS] = game.link[i] = 0;
}
for (int i=1; i<=LOCSIZ; i++) {
game.abbrev[i]=0;
if (!(locations[i].description.big == 0 || KEY[i] == 0)) {
int k=KEY[i];
if(MOD(labs(TRAVEL[k]),1000) == 1)COND[i]=2;
}
game.atloc[i]=0;
for (int i = 1; i <= LOCSIZ; i++) {
game.abbrev[i] = 0;
if (!(locations[i].description.big == 0 || KEY[i] == 0)) {
int k = KEY[i];
if (MOD(labs(TRAVEL[k]), 1000) == 1)COND[i] = 2;
}
game.atloc[i] = 0;
}
/* Set up the game.atloc and game.link arrays as described above.
@ -197,115 +197,115 @@ void initialise(void)
* This also sets up "game.place" and "fixed" as copies of "PLAC" and
* "FIXD". Also, since two-placed objects are typically best
* described last, we'll drop them first. */
for (int i=1; i<=NOBJECTS; i++) {
int k=NOBJECTS + 1 - i;
if(FIXD[k] > 0) {
DROP(k+NOBJECTS,FIXD[k]);
DROP(k,PLAC[k]);
}
for (int i = 1; i <= NOBJECTS; i++) {
int k = NOBJECTS + 1 - i;
if (FIXD[k] > 0) {
DROP(k + NOBJECTS, FIXD[k]);
DROP(k, PLAC[k]);
}
}
for (int i=1; i<=NOBJECTS; i++) {
int k=NOBJECTS + 1 - i;
game.fixed[k]=FIXD[k];
if(PLAC[k] != 0 && FIXD[k] <= 0)
DROP(k,PLAC[k]);
for (int i = 1; i <= NOBJECTS; i++) {
int k = NOBJECTS + 1 - i;
game.fixed[k] = FIXD[k];
if (PLAC[k] != 0 && FIXD[k] <= 0)
DROP(k, PLAC[k]);
}
/* Treasures, as noted earlier, are objects MINTRS through MAXTRS
* Their props are initially -1, and are set to 0 the first time
* they are described. game.tally keeps track of how many are
* not yet found, so we know when to close the cave. */
game.tally=0;
for (int treasure=MINTRS; treasure<=MAXTRS; treasure++) {
if(object_descriptions[treasure].inventory != 0)
game.prop[treasure]= -1;
game.tally=game.tally-game.prop[treasure];
game.tally = 0;
for (int treasure = MINTRS; treasure <= MAXTRS; treasure++) {
if (object_descriptions[treasure].inventory != 0)
game.prop[treasure] = -1;
game.tally = game.tally - game.prop[treasure];
}
/* Clear the hint stuff. game.hintlc[i] is how long he's been at LOC
* with cond bit i. game.hinted[i] is true iff hint i has been
* used. */
for (int i=1; i<=HNTMAX; i++) {
game.hinted[i]=false;
game.hintlc[i]=0;
for (int i = 1; i <= HNTMAX; i++) {
game.hinted[i] = false;
game.hintlc[i] = 0;
}
/* Define some handy mnemonics. These correspond to object numbers. */
AXE=VOCWRD(12405,1);
BATTER=VOCWRD(201202005,1);
BEAR=VOCWRD(2050118,1);
BIRD=VOCWRD(2091804,1);
BLOOD=VOCWRD(212151504,1);
BOTTLE=VOCWRD(215202012,1);
CAGE=VOCWRD(3010705,1);
CAVITY=VOCWRD(301220920,1);
CHASM=VOCWRD(308011913,1);
CLAM=VOCWRD(3120113,1);
DOOR=VOCWRD(4151518,1);
DRAGON=VOCWRD(418010715,1);
DWARF=VOCWRD(423011806,1);
FISSUR=VOCWRD(609191921,1);
FOOD=VOCWRD(6151504,1);
GRATE=VOCWRD(718012005,1);
KEYS=VOCWRD(11052519,1);
KNIFE=VOCWRD(1114090605,1);
LAMP=VOCWRD(12011316,1);
MAGZIN=VOCWRD(1301070126,1);
MESSAG=VOCWRD(1305191901,1);
MIRROR=VOCWRD(1309181815,1);
OGRE=VOCWRD(15071805,1);
OIL=VOCWRD(150912,1);
OYSTER=VOCWRD(1525192005,1);
PILLOW=VOCWRD(1609121215,1);
PLANT=VOCWRD(1612011420,1);
PLANT2=PLANT+1;
RESER=VOCWRD(1805190518,1);
ROD=VOCWRD(181504,1);
ROD2=ROD+1;
SIGN=VOCWRD(19090714,1);
SNAKE=VOCWRD(1914011105,1);
STEPS=VOCWRD(1920051619,1);
TROLL=VOCWRD(2018151212,1);
TROLL2=TROLL+1;
URN=VOCWRD(211814,1);
VEND=VOCWRD(1755140409,1);
VOLCAN=VOCWRD(1765120301,1);
WATER=VOCWRD(1851200518,1);
AXE = VOCWRD(12405, 1);
BATTER = VOCWRD(201202005, 1);
BEAR = VOCWRD(2050118, 1);
BIRD = VOCWRD(2091804, 1);
BLOOD = VOCWRD(212151504, 1);
BOTTLE = VOCWRD(215202012, 1);
CAGE = VOCWRD(3010705, 1);
CAVITY = VOCWRD(301220920, 1);
CHASM = VOCWRD(308011913, 1);
CLAM = VOCWRD(3120113, 1);
DOOR = VOCWRD(4151518, 1);
DRAGON = VOCWRD(418010715, 1);
DWARF = VOCWRD(423011806, 1);
FISSUR = VOCWRD(609191921, 1);
FOOD = VOCWRD(6151504, 1);
GRATE = VOCWRD(718012005, 1);
KEYS = VOCWRD(11052519, 1);
KNIFE = VOCWRD(1114090605, 1);
LAMP = VOCWRD(12011316, 1);
MAGZIN = VOCWRD(1301070126, 1);
MESSAG = VOCWRD(1305191901, 1);
MIRROR = VOCWRD(1309181815, 1);
OGRE = VOCWRD(15071805, 1);
OIL = VOCWRD(150912, 1);
OYSTER = VOCWRD(1525192005, 1);
PILLOW = VOCWRD(1609121215, 1);
PLANT = VOCWRD(1612011420, 1);
PLANT2 = PLANT + 1;
RESER = VOCWRD(1805190518, 1);
ROD = VOCWRD(181504, 1);
ROD2 = ROD + 1;
SIGN = VOCWRD(19090714, 1);
SNAKE = VOCWRD(1914011105, 1);
STEPS = VOCWRD(1920051619, 1);
TROLL = VOCWRD(2018151212, 1);
TROLL2 = TROLL + 1;
URN = VOCWRD(211814, 1);
VEND = VOCWRD(1755140409, 1);
VOLCAN = VOCWRD(1765120301, 1);
WATER = VOCWRD(1851200518, 1);
/* Objects from MINTRS through MAXTRS are treasures. Here are a few. */
AMBER=VOCWRD(113020518,1);
CHAIN=VOCWRD(308010914,1);
CHEST=VOCWRD(308051920,1);
COINS=VOCWRD(315091419,1);
EGGS=VOCWRD(5070719,1);
EMRALD=VOCWRD(513051801,1);
JADE=VOCWRD(10010405,1);
NUGGET=VOCWRD(7151204,1);
PEARL=VOCWRD(1605011812,1);
PYRAM=VOCWRD(1625180113,1);
RUBY=VOCWRD(18210225,1);
RUG=VOCWRD(182107,1);
SAPPH=VOCWRD(1901161608,1);
TRIDNT=VOCWRD(2018090405,1);
VASE=VOCWRD(22011905,1);
AMBER = VOCWRD(113020518, 1);
CHAIN = VOCWRD(308010914, 1);
CHEST = VOCWRD(308051920, 1);
COINS = VOCWRD(315091419, 1);
EGGS = VOCWRD(5070719, 1);
EMRALD = VOCWRD(513051801, 1);
JADE = VOCWRD(10010405, 1);
NUGGET = VOCWRD(7151204, 1);
PEARL = VOCWRD(1605011812, 1);
PYRAM = VOCWRD(1625180113, 1);
RUBY = VOCWRD(18210225, 1);
RUG = VOCWRD(182107, 1);
SAPPH = VOCWRD(1901161608, 1);
TRIDNT = VOCWRD(2018090405, 1);
VASE = VOCWRD(22011905, 1);
/* These are motion-verb numbers. */
BACK=VOCWRD(2010311,0);
CAVE=VOCWRD(3012205,0);
DPRSSN=VOCWRD(405161805,0);
ENTER=VOCWRD(514200518,0);
ENTRNC=VOCWRD(514201801,0);
LOOK=VOCWRD(12151511,0);
NUL=VOCWRD(14211212,0);
STREAM=VOCWRD(1920180501,0);
BACK = VOCWRD(2010311, 0);
CAVE = VOCWRD(3012205, 0);
DPRSSN = VOCWRD(405161805, 0);
ENTER = VOCWRD(514200518, 0);
ENTRNC = VOCWRD(514201801, 0);
LOOK = VOCWRD(12151511, 0);
NUL = VOCWRD(14211212, 0);
STREAM = VOCWRD(1920180501, 0);
/* And some action verbs. */
FIND=VOCWRD(6091404,2);
INVENT=VOCWRD(914220514,2);
LOCK=VOCWRD(12150311,2);
SAY=VOCWRD(190125,2);
THROW=VOCWRD(2008181523,2);
FIND = VOCWRD(6091404, 2);
INVENT = VOCWRD(914220514, 2);
LOCK = VOCWRD(12150311, 2);
SAY = VOCWRD(190125, 2);
THROW = VOCWRD(2008181523, 2);
/* Initialise the dwarves. game.dloc is loc of dwarves,
* hard-wired in. game.odloc is prior loc of each dwarf,
@ -325,16 +325,16 @@ void initialise(void)
* loc stored in game.chloc2. */
game.chloc = LOC_DEADEND12;
game.chloc2 = LOC_DEADEND13;
for (int i=1; i<=NDWARVES; i++) {
game.dseen[i]=false;
for (int i = 1; i <= NDWARVES; i++) {
game.dseen[i] = false;
}
game.dflag=0;
game.dflag = 0;
game.dloc[1] = LOC_KINGHALL;
game.dloc[2] = LOC_WESTBANK;
game.dloc[3] = LOC_Y2;
game.dloc[4] = LOC_ALIKE3;
game.dloc[5] = LOC_COMPLEX;
game.dloc[6]=game.chloc;
game.dloc[6] = game.chloc;
/* Other random flags and counters, as follows:
* game.abbnum How often we should print non-abbreviated descriptions
@ -357,30 +357,30 @@ void initialise(void)
* game.trnluz # points lost so far due to number of turns used
* game.turns Tallies how many commands he's given (ignores yes/no)
* Logicals were explained earlier */
game.turns=0;
game.trndex=1;
game.thresh= -1;
game.turns = 0;
game.trndex = 1;
game.thresh = -1;
if (TRNVLS > 0)
game.thresh=MOD(TRNVAL[1],100000)+1;
game.trnluz=0;
game.lmwarn=false;
game.iwest=0;
game.knfloc=0;
game.detail=0;
game.abbnum=5;
game.numdie=0;
game.holdng=0;
game.dkill=0;
game.foobar=0;
game.bonus=0;
game.clock1=30;
game.clock2=50;
game.conds=SETBIT(11);
game.saved=0;
game.closng=false;
game.panic=false;
game.closed=false;
game.clshnt=false;
game.novice=false;
game.blklin=true;
game.thresh = MOD(TRNVAL[1], 100000) + 1;
game.trnluz = 0;
game.lmwarn = false;
game.iwest = 0;
game.knfloc = 0;
game.detail = 0;
game.abbnum = 5;
game.numdie = 0;
game.holdng = 0;
game.dkill = 0;
game.foobar = 0;
game.bonus = 0;
game.clock1 = 30;
game.clock2 = 50;
game.conds = SETBIT(11);
game.saved = 0;
game.closng = false;
game.panic = false;
game.closed = false;
game.clshnt = false;
game.novice = false;
game.blklin = true;
}

1523
main.c

File diff suppressed because it is too large Load diff

602
misc.c
View file

@ -12,34 +12,31 @@
char* xstrdup(const char* s)
{
char* ptr = strdup(s);
if (ptr == NULL)
{
fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE);
char* ptr = strdup(s);
if (ptr == NULL) {
fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE);
}
return(ptr);
return (ptr);
}
void packed_to_token(long packed, char token[6])
{
// Unpack and map back to ASCII.
for (int i = 0; i < 5; ++i)
{
char advent = (packed >> i * 6) & 63;
token[4 - i] = advent_to_ascii[(int) advent];
// Unpack and map back to ASCII.
for (int i = 0; i < 5; ++i) {
char advent = (packed >> i * 6) & 63;
token[4 - i] = advent_to_ascii[(int) advent];
}
// Ensure the last character is \0.
token[5] = '\0';
// Ensure the last character is \0.
token[5] = '\0';
// Replace trailing whitespace with \0.
for (int i = 4; i >= 0; --i)
{
if (token[i] == ' ' || token[i] == '\t')
token[i] = '\0';
else
break;
// Replace trailing whitespace with \0.
for (int i = 4; i >= 0; --i) {
if (token[i] == ' ' || token[i] == '\t')
token[i] = '\0';
else
break;
}
}
@ -47,109 +44,97 @@ void packed_to_token(long packed, char token[6])
void newspeak(const char* msg)
{
// Do nothing if we got a null pointer.
if (msg == NULL)
return;
// Do nothing if we got a null pointer.
if (msg == NULL)
return;
// Do nothing if we got an empty string.
if (strlen(msg) == 0)
return;
// Do nothing if we got an empty string.
if (strlen(msg) == 0)
return;
// Print a newline if the global game.blklin says to.
if (game.blklin == true)
printf("\n");
// Print a newline if the global game.blklin says to.
if (game.blklin == true)
printf("\n");
// Create a copy of our string, so we can edit it.
char* copy = xstrdup(msg);
// Create a copy of our string, so we can edit it.
char* copy = xstrdup(msg);
// Staging area for stringified parameters.
char parameters[5][100]; // FIXME: to be replaced with dynamic allocation
// Handle format specifiers (including the custom %C, %L, %S) by adjusting the parameter accordingly, and replacing the specifier with %s.
int pi = 0; // parameter index
for (int i = 0; i < (int)strlen(msg); ++i)
{
if (msg[i] == '%')
{
++pi;
// Staging area for stringified parameters.
char parameters[5][100]; // FIXME: to be replaced with dynamic allocation
// Integer specifier. In order to accommodate the fact that PARMS can have both legitimate integers *and* packed tokens, stringify everything. Future work may eliminate the need for this.
if (msg[i + 1] == 'd')
{
copy[i + 1] = 's';
sprintf(parameters[pi], "%ld", PARMS[pi]);
}
// Handle format specifiers (including the custom %C, %L, %S) by adjusting the parameter accordingly, and replacing the specifier with %s.
int pi = 0; // parameter index
for (int i = 0; i < (int)strlen(msg); ++i) {
if (msg[i] == '%') {
++pi;
// Unmodified string specifier.
if (msg[i + 1] == 's')
{
packed_to_token(PARMS[pi], parameters[pi]);
}
// Integer specifier. In order to accommodate the fact that PARMS can have both legitimate integers *and* packed tokens, stringify everything. Future work may eliminate the need for this.
if (msg[i + 1] == 'd') {
copy[i + 1] = 's';
sprintf(parameters[pi], "%ld", PARMS[pi]);
}
// Singular/plural specifier.
if (msg[i + 1] == 'S')
{
copy[i + 1] = 's';
if (PARMS[pi - 1] > 1) // look at the *previous* parameter (which by necessity must be numeric)
{
sprintf(parameters[pi], "%s", "s");
}
else
{
sprintf(parameters[pi], "%s", "");
}
}
// Unmodified string specifier.
if (msg[i + 1] == 's') {
packed_to_token(PARMS[pi], parameters[pi]);
}
// All-lowercase specifier.
if (msg[i + 1] == 'L')
{
copy[i + 1] = 's';
packed_to_token(PARMS[pi], parameters[pi]);
for (int j = 0; j < (int)strlen(parameters[pi]); ++j)
{
parameters[pi][j] = tolower(parameters[pi][j]);
}
}
// Singular/plural specifier.
if (msg[i + 1] == 'S') {
copy[i + 1] = 's';
if (PARMS[pi - 1] > 1) { // look at the *previous* parameter (which by necessity must be numeric)
sprintf(parameters[pi], "%s", "s");
} else {
sprintf(parameters[pi], "%s", "");
}
}
// First char uppercase, rest lowercase.
if (msg[i + 1] == 'C')
{
copy[i + 1] = 's';
packed_to_token(PARMS[pi], parameters[pi]);
for (int j = 0; j < (int)strlen(parameters[pi]); ++j)
{
parameters[pi][j] = tolower(parameters[pi][j]);
}
parameters[pi][0] = toupper(parameters[pi][0]);
}
}
// All-lowercase specifier.
if (msg[i + 1] == 'L') {
copy[i + 1] = 's';
packed_to_token(PARMS[pi], parameters[pi]);
for (int j = 0; j < (int)strlen(parameters[pi]); ++j) {
parameters[pi][j] = tolower(parameters[pi][j]);
}
}
// First char uppercase, rest lowercase.
if (msg[i + 1] == 'C') {
copy[i + 1] = 's';
packed_to_token(PARMS[pi], parameters[pi]);
for (int j = 0; j < (int)strlen(parameters[pi]); ++j) {
parameters[pi][j] = tolower(parameters[pi][j]);
}
parameters[pi][0] = toupper(parameters[pi][0]);
}
}
}
// Render the final string.
char rendered[2000]; // FIXME: to be replaced with dynamic allocation
sprintf(rendered, copy, parameters[1], parameters[2], parameters[3], parameters[4]); // FIXME: to be replaced with vsprintf()
// Render the final string.
char rendered[2000]; // FIXME: to be replaced with dynamic allocation
sprintf(rendered, copy, parameters[1], parameters[2], parameters[3], parameters[4]); // FIXME: to be replaced with vsprintf()
// Print the message.
printf("%s\n", rendered);
// Print the message.
printf("%s\n", rendered);
free(copy);
free(copy);
}
void PSPEAK(vocab_t msg,int skip)
void PSPEAK(vocab_t msg, int skip)
/* Find the skip+1st message from msg and print it. msg should be
* the index of the inventory message for object. (INVEN+N+1 message
* is game.prop=N message). */
{
if (skip >= 0)
newspeak(object_descriptions[msg].longs[skip]);
else
newspeak(object_descriptions[msg].inventory);
if (skip >= 0)
newspeak(object_descriptions[msg].longs[skip]);
else
newspeak(object_descriptions[msg].inventory);
}
void RSPEAK(vocab_t i)
/* Print the i-th "random" message (section 6 of database). */
{
newspeak(arbitrary_messages[i]);
newspeak(arbitrary_messages[i]);
}
void SETPRM(long first, long p1, long p2)
@ -157,16 +142,16 @@ void SETPRM(long first, long p1, long p2)
* are stored into PARMS(first) and PARMS(first+1). */
{
if (first >= MAXPARMS)
BUG(29);
BUG(29);
else {
PARMS[first] = p1;
PARMS[first+1] = p2;
PARMS[first] = p1;
PARMS[first + 1] = p2;
}
}
bool GETIN(FILE *input,
long *pword1, long *pword1x,
long *pword2, long *pword2x)
long *pword1, long *pword1x,
long *pword2, long *pword2x)
/* Get a command from the adventurer. Snarf out the first word, pad it with
* blanks, and return it in WORD1. Chars 6 thru 10 are returned in WORD1X, in
* case we need to print out the whole word in an error message. Any number of
@ -176,27 +161,27 @@ bool GETIN(FILE *input,
long junk;
for (;;) {
if (game.blklin)
TYPE0();
if (!MAPLIN(input))
return false;
*pword1=GETTXT(true,true,true);
if (game.blklin && *pword1 < 0)
continue;
*pword1x=GETTXT(false,true,true);
do {
junk=GETTXT(false,true,true);
} while
(junk > 0);
*pword2=GETTXT(true,true,true);
*pword2x=GETTXT(false,true,true);
do {
junk=GETTXT(false,true,true);
} while
(junk > 0);
if (GETTXT(true,true,true) <= 0)
return true;
RSPEAK(TWO_WORDS);
if (game.blklin)
TYPE0();
if (!MAPLIN(input))
return false;
*pword1 = GETTXT(true, true, true);
if (game.blklin && *pword1 < 0)
continue;
*pword1x = GETTXT(false, true, true);
do {
junk = GETTXT(false, true, true);
} while
(junk > 0);
*pword2 = GETTXT(true, true, true);
*pword2x = GETTXT(false, true, true);
do {
junk = GETTXT(false, true, true);
} while
(junk > 0);
if (GETTXT(true, true, true) <= 0)
return true;
RSPEAK(TWO_WORDS);
}
}
@ -207,17 +192,17 @@ long YES(FILE *input, vocab_t x, vocab_t y, vocab_t z)
token_t reply, junk1, junk2, junk3;
for (;;) {
RSPEAK(x);
GETIN(input, &reply, &junk1, &junk2, &junk3);
if (reply == MAKEWD(250519) || reply == MAKEWD(25)) {
RSPEAK(y);
return true;
}
if (reply == MAKEWD(1415) || reply == MAKEWD(14)) {
RSPEAK(z);
return false;
}
RSPEAK(PLEASE_ANSWER);
RSPEAK(x);
GETIN(input, &reply, &junk1, &junk2, &junk3);
if (reply == MAKEWD(250519) || reply == MAKEWD(25)) {
RSPEAK(y);
return true;
}
if (reply == MAKEWD(1415) || reply == MAKEWD(14)) {
RSPEAK(z);
return false;
}
RSPEAK(PLEASE_ANSWER);
}
}
@ -234,39 +219,39 @@ long GETTXT(bool skip, bool onewrd, bool upper)
static long splitting = -1;
if (LNPOSN != splitting)
splitting = -1;
text= -1;
splitting = -1;
text = -1;
while (true) {
if (LNPOSN > LNLENG)
return(text);
if ((!skip) || INLINE[LNPOSN] != 0)
break;
++LNPOSN;
if (LNPOSN > LNLENG)
return (text);
if ((!skip) || INLINE[LNPOSN] != 0)
break;
++LNPOSN;
}
text=0;
for (int I=1; I<=TOKLEN; I++) {
text=text*64;
if (LNPOSN > LNLENG || (onewrd && INLINE[LNPOSN] == 0))
continue;
char current=INLINE[LNPOSN];
if (current < ascii_to_advent['%']) {
splitting = -1;
if (upper && current >= ascii_to_advent['a'])
current=current-26;
text=text+current;
++LNPOSN;
continue;
}
if (splitting != LNPOSN) {
text=text+ascii_to_advent['%'];
splitting = LNPOSN;
continue;
}
text = 0;
for (int I = 1; I <= TOKLEN; I++) {
text = text * 64;
if (LNPOSN > LNLENG || (onewrd && INLINE[LNPOSN] == 0))
continue;
char current = INLINE[LNPOSN];
if (current < ascii_to_advent['%']) {
splitting = -1;
if (upper && current >= ascii_to_advent['a'])
current = current - 26;
text = text + current;
++LNPOSN;
continue;
}
if (splitting != LNPOSN) {
text = text + ascii_to_advent['%'];
splitting = LNPOSN;
continue;
}
text=text+current-ascii_to_advent['%'];
splitting = -1;
++LNPOSN;
text = text + current - ascii_to_advent['%'];
splitting = -1;
++LNPOSN;
}
return text;
@ -283,13 +268,13 @@ token_t MAKEWD(long letters)
{
long i = 1, word = 0;
for (long k=letters; k != 0; k=k/100) {
word=word+i*(MOD(k,50)+10);
i=i*64;
if (MOD(k,100) > 50)word=word+i*5;
for (long k = letters; k != 0; k = k / 100) {
word = word + i * (MOD(k, 50) + 10);
i = i * 64;
if (MOD(k, 100) > 50)word = word + i * 5;
}
i=64L*64L*64L*64L*64L/i;
word=word*i;
i = 64L * 64L * 64L * 64L * 64L / i;
word = word * i;
return word;
}
@ -299,16 +284,16 @@ void TYPE0(void)
{
long temp;
temp=LNLENG;
LNLENG=0;
temp = LNLENG;
LNLENG = 0;
TYPE();
LNLENG=temp;
LNLENG = temp;
return;
}
/* Data structure routines */
long VOCAB(long id, long init)
long VOCAB(long id, long init)
/* Look up ID in the vocabulary (ATAB) and return its "definition" (KTAB), or
* -1 if not found. If INIT is positive, this is an initialisation call setting
* up a keyword variable, and not finding it constitutes a bug. It also means
@ -318,21 +303,21 @@ long VOCAB(long id, long init)
{
long lexeme;
for (long i=1; i<=TABSIZ; i++) {
if (KTAB[i] == -1) {
lexeme= -1;
if (init < 0)
return(lexeme);
BUG(5);
}
if (init >= 0 && KTAB[i]/1000 != init)
continue;
if (ATAB[i] == id) {
lexeme=KTAB[i];
if (init >= 0)
lexeme=MOD(lexeme,1000);
return(lexeme);
}
for (long i = 1; i <= TABSIZ; i++) {
if (KTAB[i] == -1) {
lexeme = -1;
if (init < 0)
return (lexeme);
BUG(5);
}
if (init >= 0 && KTAB[i] / 1000 != init)
continue;
if (ATAB[i] == id) {
lexeme = KTAB[i];
if (init >= 0)
lexeme = MOD(lexeme, 1000);
return (lexeme);
}
}
BUG(21);
}
@ -343,10 +328,10 @@ void JUGGLE(long object)
{
long i, j;
i=game.place[object];
j=game.fixed[object];
MOVE(object,i);
MOVE(object+NOBJECTS,j);
i = game.place[object];
j = game.fixed[object];
MOVE(object, i);
MOVE(object + NOBJECTS, j);
}
void MOVE(long object, long where)
@ -357,24 +342,24 @@ void MOVE(long object, long where)
{
long from;
if (object > NOBJECTS)
from=game.fixed[object-NOBJECTS];
if (object > NOBJECTS)
from = game.fixed[object - NOBJECTS];
else
from=game.place[object];
from = game.place[object];
if (from != NOWHERE && from != CARRIED && !SPECIAL(from))
CARRY(object,from);
DROP(object,where);
CARRY(object, from);
DROP(object, where);
}
long PUT(long object, long where, long pval)
/* PUT is the same as MOVE, except it returns a value used to set up the
* negated game.prop values for the repository objects. */
{
MOVE(object,where);
return (-1)-pval;;
MOVE(object, where);
return (-1) - pval;;
}
void CARRY(long object, long where)
void CARRY(long object, long where)
/* Start toting an object, removing it from the list of things at its former
* location. Incr holdng unless it was already being toted. If object>NOBJECTS
* (moving "fixed" second loc), don't change game.place or game.holdng. */
@ -382,20 +367,20 @@ void CARRY(long object, long where)
long temp;
if (object <= NOBJECTS) {
if (game.place[object] == CARRIED)
return;
game.place[object] = CARRIED;
++game.holdng;
if (game.place[object] == CARRIED)
return;
game.place[object] = CARRIED;
++game.holdng;
}
if (game.atloc[where] == object) {
game.atloc[where]=game.link[object];
return;
game.atloc[where] = game.link[object];
return;
}
temp=game.atloc[where];
temp = game.atloc[where];
while (game.link[temp] != object) {
temp=game.link[temp];
temp = game.link[temp];
}
game.link[temp]=game.link[object];
game.link[temp] = game.link[object];
}
void DROP(long object, long where)
@ -403,15 +388,14 @@ void DROP(long object, long where)
* game.holdng if the object was being toted. */
{
if (object > NOBJECTS)
game.fixed[object-NOBJECTS] = where;
else
{
if (game.place[object] == CARRIED)
--game.holdng;
game.place[object] = where;
game.fixed[object - NOBJECTS] = where;
else {
if (game.place[object] == CARRIED)
--game.holdng;
game.place[object] = where;
}
if (where <= 0)
return;
return;
game.link[object] = game.atloc[where];
game.atloc[where] = object;
}
@ -423,17 +407,17 @@ long ATDWRF(long where)
{
long at;
at =0;
at = 0;
if (game.dflag < 2)
return(at);
return (at);
at = -1;
for (long i=1; i<=NDWARVES-1; i++) {
if (game.dloc[i] == where)
return i;
if (game.dloc[i] != 0)
at=0;
for (long i = 1; i <= NDWARVES - 1; i++) {
if (game.dloc[i] == where)
return i;
if (game.dloc[i] != 0)
at = 0;
}
return(at);
return (at);
}
/* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value,
@ -442,7 +426,7 @@ long ATDWRF(long where)
long SETBIT(long bit)
/* Returns 2**bit for use in constructing bit-masks. */
{
return(1 << bit);
return (1 << bit);
}
bool TSTBIT(long mask, int bit)
@ -480,21 +464,20 @@ long RNDVOC(long second, long force)
long rnd = force;
if (rnd == 0) {
for (int i = 1; i <= 5; i++) {
long j = 11 + randrange(26);
if (i == 2)
j = second;
rnd = rnd * 64 + j;
}
for (int i = 1; i <= 5; i++) {
long j = 11 + randrange(26);
if (i == 2)
j = second;
rnd = rnd * 64 + j;
}
}
long div = 64L * 64L * 64L;
for (int i = 1; i <= TABSIZ; i++) {
if (MOD(ATAB[i]/div, 64L) == second)
{
ATAB[i] = rnd;
break;
}
if (MOD(ATAB[i] / div, 64L) == second) {
ATAB[i] = rnd;
break;
}
}
return rnd;
@ -538,7 +521,7 @@ bool MAPLIN(FILE *fp)
bool eof;
/* Read a line of input, from the specified input source.
* This logic is complicated partly because it has to serve
* This logic is complicated partly because it has to serve
* several cases with different requirements and partly because
* of a quirk in linenoise().
*
@ -551,80 +534,79 @@ bool MAPLIN(FILE *fp)
* fed redirected stdin.
*
* The logging is a bit of a mess because there are two distinct cases
* in which you want to echo commands. One is when shipping them to
* in which you want to echo commands. One is when shipping them to
* a log under the -l option, in which case you want to suppress
* prompt generation (so test logs are unadorned command sequences).
* On the other hand, if you redirected stdin and are feeding the program
* On the other hand, if you redirected stdin and are feeding the program
* a logfile, you *do* want prompt generation - it makes checkfiles
* easier to read when the commands are marked by a preceding prompt.
*/
do {
if (!editline) {
if (prompt)
fputs("> ", stdout);
IGNORE(fgets(rawbuf,sizeof(rawbuf)-1,fp));
eof = (feof(fp));
} else {
char *cp = linenoise("> ");
eof = (cp == NULL);
if (!eof) {
strncpy(rawbuf, cp, sizeof(rawbuf)-1);
linenoiseHistoryAdd(rawbuf);
strncat(rawbuf, "\n", sizeof(rawbuf) - strlen(rawbuf) - 1);
linenoiseFree(cp);
}
}
if (!editline) {
if (prompt)
fputs("> ", stdout);
IGNORE(fgets(rawbuf, sizeof(rawbuf) - 1, fp));
eof = (feof(fp));
} else {
char *cp = linenoise("> ");
eof = (cp == NULL);
if (!eof) {
strncpy(rawbuf, cp, sizeof(rawbuf) - 1);
linenoiseHistoryAdd(rawbuf);
strncat(rawbuf, "\n", sizeof(rawbuf) - strlen(rawbuf) - 1);
linenoiseFree(cp);
}
}
} while
(!eof && rawbuf[0] == '#');
(!eof && rawbuf[0] == '#');
if (eof) {
if (logfp && fp == stdin)
fclose(logfp);
return false;
if (logfp && fp == stdin)
fclose(logfp);
return false;
} else {
FILE *efp = NULL;
if (logfp && fp == stdin)
efp = logfp;
else if (!isatty(0))
efp = stdout;
if (efp != NULL)
{
if (prompt && efp == stdout)
fputs("> ", efp);
IGNORE(fputs(rawbuf, efp));
}
strcpy(INLINE+1, rawbuf);
/* translate the chars to integers in the range 0-126 and store
* them in the common array "INLINE". Integer values are as follows:
* 0 = space [ASCII CODE 40 octal, 32 decimal]
* 1-2 = !" [ASCII 41-42 octal, 33-34 decimal]
* 3-10 = '()*+,-. [ASCII 47-56 octal, 39-46 decimal]
* 11-36 = upper-case letters
* 37-62 = lower-case letters
* 63 = percent (%) [ASCII 45 octal, 37 decimal]
* 64-73 = digits, 0 through 9
* Remaining characters can be translated any way that is convenient;
* The "TYPE" routine below is used to map them back to characters when
* necessary. The above mappings are required so that certain special
* characters are known to fit in 6 bits and/or can be easily spotted.
* Array elements beyond the end of the line should be filled with 0,
* and LNLENG should be set to the index of the last character.
*
* If the data file uses a character other than space (e.g., tab) to
* separate numbers, that character should also translate to 0.
*
* This procedure may use the map1,map2 arrays to maintain static data for
* the mapping. MAP2(1) is set to 0 when the program starts
* and is not changed thereafter unless the routines on this page choose
* to do so. */
LNLENG=0;
for (long i=1; i<=(long)sizeof(INLINE) && INLINE[i]!=0; i++) {
long val=INLINE[i];
INLINE[i]=ascii_to_advent[val];
if (INLINE[i] != 0)
LNLENG=i;
}
LNPOSN=1;
return true;
FILE *efp = NULL;
if (logfp && fp == stdin)
efp = logfp;
else if (!isatty(0))
efp = stdout;
if (efp != NULL) {
if (prompt && efp == stdout)
fputs("> ", efp);
IGNORE(fputs(rawbuf, efp));
}
strcpy(INLINE + 1, rawbuf);
/* translate the chars to integers in the range 0-126 and store
* them in the common array "INLINE". Integer values are as follows:
* 0 = space [ASCII CODE 40 octal, 32 decimal]
* 1-2 = !" [ASCII 41-42 octal, 33-34 decimal]
* 3-10 = '()*+,-. [ASCII 47-56 octal, 39-46 decimal]
* 11-36 = upper-case letters
* 37-62 = lower-case letters
* 63 = percent (%) [ASCII 45 octal, 37 decimal]
* 64-73 = digits, 0 through 9
* Remaining characters can be translated any way that is convenient;
* The "TYPE" routine below is used to map them back to characters when
* necessary. The above mappings are required so that certain special
* characters are known to fit in 6 bits and/or can be easily spotted.
* Array elements beyond the end of the line should be filled with 0,
* and LNLENG should be set to the index of the last character.
*
* If the data file uses a character other than space (e.g., tab) to
* separate numbers, that character should also translate to 0.
*
* This procedure may use the map1,map2 arrays to maintain static data for
* the mapping. MAP2(1) is set to 0 when the program starts
* and is not changed thereafter unless the routines on this page choose
* to do so. */
LNLENG = 0;
for (long i = 1; i <= (long)sizeof(INLINE) && INLINE[i] != 0; i++) {
long val = INLINE[i];
INLINE[i] = ascii_to_advent[val];
if (INLINE[i] != 0)
LNLENG = i;
}
LNPOSN = 1;
return true;
}
}
@ -636,15 +618,15 @@ void TYPE(void)
long i;
if (LNLENG == 0) {
printf("\n");
return;
printf("\n");
return;
}
for (i=1; i<=LNLENG; i++) {
INLINE[i]=advent_to_ascii[(int) INLINE[i]];
for (i = 1; i <= LNLENG; i++) {
INLINE[i] = advent_to_ascii[(int) INLINE[i]];
}
INLINE[LNLENG+1]=0;
printf("%s\n", INLINE+1);
INLINE[LNLENG + 1] = 0;
printf("%s\n", INLINE + 1);
return;
}

View file

@ -31,7 +31,8 @@ struct save_t save;
/* Suspend and resume */
int suspend(FILE *input)
{ /* Suspend. Offer to save things in a file, but charging
{
/* Suspend. Offer to save things in a file, but charging
* some points (so can't win by using saved games to retry
* battles or to start over after learning zzword).
* If ADVENT_NOSAVE is defined, do nothing instead. */
@ -43,21 +44,21 @@ int suspend(FILE *input)
FILE *fp = NULL;
RSPEAK(SUSPEND_WARNING);
if (!YES(input,THIS_ACCEPTABLE,OK_MAN,OK_MAN)) return GO_CLEAROBJ;
game.saved=game.saved+5;
if (!YES(input, THIS_ACCEPTABLE, OK_MAN, OK_MAN)) return GO_CLEAROBJ;
game.saved = game.saved + 5;
while (fp == NULL) {
char* name = linenoise("\nFile name: ");
if (name == NULL)
return GO_TOP;
fp = fopen(name, WRITE_MODE);
if (fp == NULL)
printf("Can't open file %s, try again.\n", name);
linenoiseFree(name);
char* name = linenoise("\nFile name: ");
if (name == NULL)
return GO_TOP;
fp = fopen(name, WRITE_MODE);
if (fp == NULL)
printf("Can't open file %s, try again.\n", name);
linenoiseFree(name);
}
DATIME(&i,&k);
k=i+650*k;
DATIME(&i, &k);
k = i + 650 * k;
save.savetime = k;
save.mode = -1;
save.version = VRSION;
@ -71,7 +72,8 @@ int suspend(FILE *input)
}
int resume(FILE *input)
{ /* Resume. Read a suspended game back from a file.
{
/* Resume. Read a suspended game back from a file.
* If ADVENT_NOSAVE is defined, do nothing instead. */
#ifdef ADVENT_NOSAVE
@ -80,25 +82,26 @@ int resume(FILE *input)
FILE *fp = NULL;
if (game.loc != 1 || game.abbrev[1] != 1) {
RSPEAK(RESUME_ABANDON);
if (!YES(input,THIS_ACCEPTABLE,OK_MAN,OK_MAN)) return GO_CLEAROBJ;
RSPEAK(RESUME_ABANDON);
if (!YES(input, THIS_ACCEPTABLE, OK_MAN, OK_MAN)) return GO_CLEAROBJ;
}
while (fp == NULL) {
char* name = linenoise("\nFile name: ");
if (name == NULL)
return GO_TOP;
fp = fopen(name, READ_MODE);
if (fp == NULL)
printf("Can't open file %s, try again.\n", name);
linenoiseFree(name);
char* name = linenoise("\nFile name: ");
if (name == NULL)
return GO_TOP;
fp = fopen(name, READ_MODE);
if (fp == NULL)
printf("Can't open file %s, try again.\n", name);
linenoiseFree(name);
}
return restore(fp);
}
int restore(FILE* fp)
{ /* Read and restore game state from file, assuming
{
/* Read and restore game state from file, assuming
* sane initial state.
* If ADVENT_NOSAVE is defined, do nothing instead. */
#ifdef ADVENT_NOSAVE
@ -108,14 +111,14 @@ int restore(FILE* fp)
IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
fclose(fp);
if (save.version != VRSION) {
SETPRM(1,save.version/10,MOD(save.version,10));
SETPRM(3,VRSION/10,MOD(VRSION,10));
SETPRM(1, save.version / 10, MOD(save.version, 10));
SETPRM(3, VRSION / 10, MOD(VRSION, 10));
RSPEAK(VERSION_SKEW);
} else {
memcpy(&game, &save.game, sizeof(struct game_t));
OBJSND[BIRD] = save.bird;
OBJTXT[OYSTER] = save.bivalve;
game.zzword=RNDVOC(3,game.zzword);
game.zzword = RNDVOC(3, game.zzword);
}
return GO_TOP;
}

110
score.c
View file

@ -34,17 +34,17 @@ void score(enum termination mode)
/* First tally up the treasures. Must be in building and not broken.
* Give the poor guy 2 points just for finding each treasure. */
for (long i=MINTRS; i<=MAXTRS; i++) {
if(object_descriptions[i].inventory != 0) {
long k=12;
if(i == CHEST)k=14;
if(i > CHEST)k=16;
if(game.prop[i] >= 0)
score += 2;
if(game.place[i] == LOC_BUILDING && game.prop[i] == 0)
score += k-2;
mxscor += k;
}
for (long i = MINTRS; i <= MAXTRS; i++) {
if (object_descriptions[i].inventory != 0) {
long k = 12;
if (i == CHEST)k = 14;
if (i > CHEST)k = 16;
if (game.prop[i] >= 0)
score += 2;
if (game.place[i] == LOC_BUILDING && game.prop[i] == 0)
score += k - 2;
mxscor += k;
}
}
/* Now look at how he finished and how far he got. MAXDIE and
@ -53,30 +53,30 @@ void score(enum termination mode)
* indicates whether he reached the endgame. And if he got as far as
* "cave closed" (indicated by "game.closed"), then bonus is zero for
* mundane exits or 133, 134, 135 if he blew it (so to speak). */
score += (MAXDIE-game.numdie)*10;
mxscor += MAXDIE*10;
if(mode == endgame)
score += 4;
score += (MAXDIE - game.numdie) * 10;
mxscor += MAXDIE * 10;
if (mode == endgame)
score += 4;
mxscor += 4;
if(game.dflag != 0)score += 25;
if (game.dflag != 0)score += 25;
mxscor += 25;
if(game.closng)score += 25;
if (game.closng)score += 25;
mxscor += 25;
if(game.closed) {
if(game.bonus == 0)
score += 10;
if(game.bonus == SPLATTER_MESSAGE)
score += 25;
if(game.bonus == DEFEAT_MESSAGE)
score += 30;
if(game.bonus == VICTORY_MESSAGE)
score += 45;
if (game.closed) {
if (game.bonus == 0)
score += 10;
if (game.bonus == SPLATTER_MESSAGE)
score += 25;
if (game.bonus == DEFEAT_MESSAGE)
score += 30;
if (game.bonus == VICTORY_MESSAGE)
score += 45;
}
mxscor += 45;
/* Did he come to Witt's End as he should? */
if(game.place[MAGZIN] == LOC_WITTSEND)
score += 1;
if (game.place[MAGZIN] == LOC_WITTSEND)
score += 1;
mxscor += 1;
/* Round it off. */
@ -84,40 +84,40 @@ void score(enum termination mode)
mxscor += 2;
/* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
for (long i=1; i<=HNTMAX; i++) {
if(game.hinted[i])
score=score-HINTS[i][2];
for (long i = 1; i <= HNTMAX; i++) {
if (game.hinted[i])
score = score - HINTS[i][2];
}
if(game.novice)
score -= 5;
if(game.clshnt)
score -= 10;
score=score-game.trnluz-game.saved;
if (game.novice)
score -= 5;
if (game.clshnt)
score -= 10;
score = score - game.trnluz - game.saved;
/* Return to score command if that's where we came from. */
if(mode == scoregame) {
SETPRM(1,score,mxscor);
SETPRM(3,game.turns,game.turns);
RSPEAK(GARNERED_POINTS);
return;
if (mode == scoregame) {
SETPRM(1, score, mxscor);
SETPRM(3, game.turns, game.turns);
RSPEAK(GARNERED_POINTS);
return;
}
/* that should be good enough. Let's tell him all about it. */
if(score+game.trnluz+1 >= mxscor && game.trnluz != 0)
RSPEAK(TOOK_LONG);
if(score+game.saved+1 >= mxscor && game.saved != 0)
RSPEAK(WITHOUT_SUSPENDS);
SETPRM(1,score,mxscor);
SETPRM(3,game.turns,game.turns);
if (score + game.trnluz + 1 >= mxscor && game.trnluz != 0)
RSPEAK(TOOK_LONG);
if (score + game.saved + 1 >= mxscor && game.saved != 0)
RSPEAK(WITHOUT_SUSPENDS);
SETPRM(1, score, mxscor);
SETPRM(3, game.turns, game.turns);
RSPEAK(TOTAL_SCORE);
for (long i=1; i<=(long)CLSSES; i++) {
if(CVAL[i] >= score) {
newspeak(class_messages[i]);
i=CVAL[i]+1-score;
SETPRM(1,i,i);
RSPEAK(NEXT_HIGHER);
exit(0);
}
for (long i = 1; i <= (long)CLSSES; i++) {
if (CVAL[i] >= score) {
newspeak(class_messages[i]);
i = CVAL[i] + 1 - score;
SETPRM(1, i, i);
RSPEAK(NEXT_HIGHER);
exit(0);
}
}
RSPEAK(OFF_SCALE);
RSPEAK(NO_HIGHER);