Re-format to consistent indent style with "make indent".
This commit is contained in:
parent
a37e578f63
commit
b3057f038b
8 changed files with 2516 additions and 2419 deletions
377
dungeon.c
377
dungeon.c
|
@ -24,7 +24,7 @@
|
||||||
// Global variables for use in functions below that can gradually disappear as code is cleaned up
|
// Global variables for use in functions below that can gradually disappear as code is cleaned up
|
||||||
static long LNLENG;
|
static long LNLENG;
|
||||||
static long LNPOSN;
|
static long LNPOSN;
|
||||||
static char INLINE[LINESIZE+1];
|
static char INLINE[LINESIZE + 1];
|
||||||
static long OLDLOC;
|
static long OLDLOC;
|
||||||
|
|
||||||
// Storage for what comes out of the database
|
// Storage for what comes out of the database
|
||||||
|
@ -34,11 +34,11 @@ long CLSSES;
|
||||||
long TRNVLS;
|
long TRNVLS;
|
||||||
long TABNDX;
|
long TABNDX;
|
||||||
long HNTMAX;
|
long HNTMAX;
|
||||||
long PTEXT[NOBJECTS+1];
|
long PTEXT[NOBJECTS + 1];
|
||||||
long RTEXT[RTXSIZ + 1];
|
long RTEXT[RTXSIZ + 1];
|
||||||
long CTEXT[CLSMAX + 1];
|
long CTEXT[CLSMAX + 1];
|
||||||
long OBJSND[NOBJECTS+1];
|
long OBJSND[NOBJECTS + 1];
|
||||||
long OBJTXT[NOBJECTS+1];
|
long OBJTXT[NOBJECTS + 1];
|
||||||
long STEXT[LOCSIZ + 1];
|
long STEXT[LOCSIZ + 1];
|
||||||
long LTEXT[LOCSIZ + 1];
|
long LTEXT[LOCSIZ + 1];
|
||||||
long COND[LOCSIZ + 1];
|
long COND[LOCSIZ + 1];
|
||||||
|
@ -51,8 +51,8 @@ long TRNVAL[TRNSIZ + 1];
|
||||||
long TRAVEL[TRVSIZ + 1];
|
long TRAVEL[TRVSIZ + 1];
|
||||||
long KTAB[TABSIZ + 1];
|
long KTAB[TABSIZ + 1];
|
||||||
long ATAB[TABSIZ + 1];
|
long ATAB[TABSIZ + 1];
|
||||||
long PLAC[NOBJECTS+1];
|
long PLAC[NOBJECTS + 1];
|
||||||
long FIXD[NOBJECTS+1];
|
long FIXD[NOBJECTS + 1];
|
||||||
long ACTSPK[VRBSIZ + 1];
|
long ACTSPK[VRBSIZ + 1];
|
||||||
long HINTS[HNTSIZ + 1][HINTLEN];
|
long HINTS[HNTSIZ + 1][HINTLEN];
|
||||||
|
|
||||||
|
@ -61,10 +61,10 @@ static bool is_set(long var, long position)
|
||||||
{
|
{
|
||||||
long mask = 1l << position;
|
long mask = 1l << position;
|
||||||
bool result = (var & mask) == mask;
|
bool result = (var & mask) == mask;
|
||||||
return(result);
|
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.
|
/* 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
|
* Skip says to skip leading blanks. ONEWRD says stop if we come to a
|
||||||
|
@ -75,46 +75,47 @@ static long GETTXT(long SKIP,long ONEWRD, long UPPER)
|
||||||
long TEXT;
|
long TEXT;
|
||||||
static long SPLITTING = -1;
|
static long SPLITTING = -1;
|
||||||
|
|
||||||
if(LNPOSN != SPLITTING)
|
if (LNPOSN != SPLITTING)
|
||||||
SPLITTING = -1;
|
SPLITTING = -1;
|
||||||
TEXT= -1;
|
TEXT = -1;
|
||||||
while (true) {
|
while (true) {
|
||||||
if(LNPOSN > LNLENG)
|
if (LNPOSN > LNLENG)
|
||||||
return(TEXT);
|
return (TEXT);
|
||||||
if((!SKIP) || INLINE[LNPOSN] != 0)
|
if ((!SKIP) || INLINE[LNPOSN] != 0)
|
||||||
break;
|
break;
|
||||||
LNPOSN=LNPOSN+1;
|
LNPOSN = LNPOSN + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEXT=0;
|
TEXT = 0;
|
||||||
for (int I=1; I<=TOKLEN; I++) {
|
for (int I = 1; I <= TOKLEN; I++) {
|
||||||
TEXT=TEXT*64;
|
TEXT = TEXT * 64;
|
||||||
if(LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0))
|
if (LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0))
|
||||||
continue;
|
continue;
|
||||||
char current=INLINE[LNPOSN];
|
char current = INLINE[LNPOSN];
|
||||||
if(current < 63) {
|
if (current < 63) {
|
||||||
SPLITTING = -1;
|
SPLITTING = -1;
|
||||||
if(UPPER && current >= 37)
|
if (UPPER && current >= 37)
|
||||||
current=current-26;
|
current = current - 26;
|
||||||
TEXT=TEXT+current;
|
TEXT = TEXT + current;
|
||||||
LNPOSN=LNPOSN+1;
|
LNPOSN = LNPOSN + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(SPLITTING != LNPOSN) {
|
if (SPLITTING != LNPOSN) {
|
||||||
TEXT=TEXT+63;
|
TEXT = TEXT + 63;
|
||||||
SPLITTING = LNPOSN;
|
SPLITTING = LNPOSN;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEXT=TEXT+current-63;
|
TEXT = TEXT + current - 63;
|
||||||
SPLITTING = -1;
|
SPLITTING = -1;
|
||||||
LNPOSN=LNPOSN+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
|
/* The following conditions are currently considered fatal bugs. Numbers < 20
|
||||||
* are detected while reading the database; the others occur at "run time".
|
* are detected while reading the database; the others occur at "run time".
|
||||||
|
@ -145,7 +146,8 @@ static void BUG(long NUM) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MAPLIN(FILE *OPENED) {
|
static void MAPLIN(FILE *OPENED)
|
||||||
|
{
|
||||||
/* Read a line of input, from the specified input source,
|
/* Read a line of input, from the specified input source,
|
||||||
* translate the chars to integers in the range 0-126 and store
|
* translate the chars to integers in the range 0-126 and store
|
||||||
* them in the common array "INLINE". Integer values are as follows:
|
* them in the common array "INLINE". Integer values are as follows:
|
||||||
|
@ -175,12 +177,10 @@ static void MAPLIN(FILE *OPENED) {
|
||||||
if (NULL == fgets(INLINE + 1, sizeof(INLINE) - 1, OPENED)) {
|
if (NULL == fgets(INLINE + 1, sizeof(INLINE) - 1, OPENED)) {
|
||||||
printf("Failed fgets()\n");
|
printf("Failed fgets()\n");
|
||||||
}
|
}
|
||||||
}
|
} while (!feof(OPENED) && INLINE[1] == '#');
|
||||||
while (!feof(OPENED) && INLINE[1] == '#');
|
|
||||||
|
|
||||||
LNLENG = 0;
|
LNLENG = 0;
|
||||||
for (size_t i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i)
|
for (size_t i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i) {
|
||||||
{
|
|
||||||
char val = INLINE[i];
|
char val = INLINE[i];
|
||||||
INLINE[i] = ascii_to_advent[(unsigned)val];
|
INLINE[i] = ascii_to_advent[(unsigned)val];
|
||||||
if (INLINE[i] != 0)
|
if (INLINE[i] != 0)
|
||||||
|
@ -189,7 +189,8 @@ static void MAPLIN(FILE *OPENED) {
|
||||||
LNPOSN = 1;
|
LNPOSN = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long GETNUM(FILE *source) {
|
static long GETNUM(FILE *source)
|
||||||
|
{
|
||||||
/* Obtain the next integer from an input line. If K>0, we first read a
|
/* 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;
|
* 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
|
* if K=0 we use a line that has already been read (and perhaps partially
|
||||||
|
@ -198,97 +199,85 @@ static long GETNUM(FILE *source) {
|
||||||
|
|
||||||
long DIGIT, GETNUM, SIGN;
|
long DIGIT, GETNUM, SIGN;
|
||||||
|
|
||||||
if(source != NULL) MAPLIN(source);
|
if (source != NULL) MAPLIN(source);
|
||||||
GETNUM = 0;
|
GETNUM = 0;
|
||||||
|
|
||||||
while (INLINE[LNPOSN] == 0) {
|
while (INLINE[LNPOSN] == 0) {
|
||||||
if (LNPOSN > LNLENG) return(GETNUM);
|
if (LNPOSN > LNLENG) return (GETNUM);
|
||||||
++LNPOSN;
|
++LNPOSN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(INLINE[LNPOSN] != 9)
|
if (INLINE[LNPOSN] != 9) {
|
||||||
{
|
SIGN = 1;
|
||||||
SIGN=1;
|
} else {
|
||||||
|
SIGN = -1;
|
||||||
|
LNPOSN = LNPOSN + 1;
|
||||||
}
|
}
|
||||||
else
|
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0)) {
|
||||||
{
|
DIGIT = INLINE[LNPOSN] - 64;
|
||||||
SIGN= -1;
|
if (DIGIT < 0 || DIGIT > 9) {
|
||||||
LNPOSN=LNPOSN+1;
|
GETNUM = 0;
|
||||||
}
|
|
||||||
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0))
|
|
||||||
{
|
|
||||||
DIGIT=INLINE[LNPOSN]-64;
|
|
||||||
if(DIGIT < 0 || DIGIT > 9)
|
|
||||||
{
|
|
||||||
GETNUM=0;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
GETNUM=GETNUM*10+DIGIT;
|
GETNUM = GETNUM * 10 + DIGIT;
|
||||||
LNPOSN=LNPOSN+1;
|
LNPOSN = LNPOSN + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
GETNUM=GETNUM*SIGN;
|
GETNUM = GETNUM * SIGN;
|
||||||
LNPOSN=LNPOSN+1;
|
LNPOSN = LNPOSN + 1;
|
||||||
return(GETNUM);
|
return (GETNUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sections 1, 2, 5, 6, 10, 14. Read messages and set up pointers. */
|
/* Sections 1, 2, 5, 6, 10, 14. Read messages and set up pointers. */
|
||||||
static void read_messages(FILE* database, long sect)
|
static void read_messages(FILE* database, long sect)
|
||||||
{
|
{
|
||||||
long KK=LINUSE;
|
long KK = LINUSE;
|
||||||
while(true)
|
while (true) {
|
||||||
{
|
|
||||||
long loc;
|
long loc;
|
||||||
LINUSE=KK;
|
LINUSE = KK;
|
||||||
loc=GETNUM(database);
|
loc = GETNUM(database);
|
||||||
if(LNLENG >= LNPOSN+70)BUG(0);
|
if (LNLENG >= LNPOSN + 70)BUG(0);
|
||||||
if(loc == -1) return;
|
if (loc == -1) return;
|
||||||
if(LNLENG < LNPOSN)BUG(1);
|
if (LNLENG < LNPOSN)BUG(1);
|
||||||
do {
|
do {
|
||||||
KK=KK+1;
|
KK = KK + 1;
|
||||||
if(KK >= LINSIZ)BUG(2);
|
if (KK >= LINSIZ)BUG(2);
|
||||||
LINES[KK]=GETTXT(false,false,false);
|
LINES[KK] = GETTXT(false, false, false);
|
||||||
}
|
} while (LINES[KK] != -1);
|
||||||
while(LINES[KK] != -1);
|
LINES[LINUSE] = KK;
|
||||||
LINES[LINUSE]=KK;
|
if (loc == OLDLOC) continue;
|
||||||
if(loc == OLDLOC) continue;
|
OLDLOC = loc;
|
||||||
OLDLOC=loc;
|
LINES[LINUSE] = -KK;
|
||||||
LINES[LINUSE]= -KK;
|
if (sect == 14) {
|
||||||
if(sect == 14)
|
TRNVLS = TRNVLS + 1;
|
||||||
{
|
if (TRNVLS > TRNSIZ)BUG(11);
|
||||||
TRNVLS=TRNVLS+1;
|
TTEXT[TRNVLS] = LINUSE;
|
||||||
if(TRNVLS > TRNSIZ)BUG(11);
|
TRNVAL[TRNVLS] = loc;
|
||||||
TTEXT[TRNVLS]=LINUSE;
|
|
||||||
TRNVAL[TRNVLS]=loc;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(sect == 10)
|
if (sect == 10) {
|
||||||
{
|
CLSSES = CLSSES + 1;
|
||||||
CLSSES=CLSSES+1;
|
if (CLSSES > CLSMAX)BUG(11);
|
||||||
if(CLSSES > CLSMAX)BUG(11);
|
CTEXT[CLSSES] = LINUSE;
|
||||||
CTEXT[CLSSES]=LINUSE;
|
CVAL[CLSSES] = loc;
|
||||||
CVAL[CLSSES]=loc;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(sect == 6)
|
if (sect == 6) {
|
||||||
{
|
if (loc > RTXSIZ)BUG(6);
|
||||||
if(loc > RTXSIZ)BUG(6);
|
RTEXT[loc] = LINUSE;
|
||||||
RTEXT[loc]=LINUSE;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(sect == 5)
|
if (sect == 5) {
|
||||||
{
|
if (loc > 0 && loc <= NOBJECTS)PTEXT[loc] = LINUSE;
|
||||||
if(loc > 0 && loc <= NOBJECTS)PTEXT[loc]=LINUSE;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(loc > LOCSIZ)BUG(10);
|
if (loc > LOCSIZ)BUG(10);
|
||||||
if(sect == 1)
|
if (sect == 1) {
|
||||||
{
|
LTEXT[loc] = LINUSE;
|
||||||
LTEXT[loc]=LINUSE;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
STEXT[loc]=LINUSE;
|
STEXT[loc] = LINUSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,25 +289,20 @@ static void read_messages(FILE* database, long sect)
|
||||||
static void read_section3_stuff(FILE* database)
|
static void read_section3_stuff(FILE* database)
|
||||||
{
|
{
|
||||||
long loc;
|
long loc;
|
||||||
while((loc=GETNUM(database)) != -1)
|
while ((loc = GETNUM(database)) != -1) {
|
||||||
{
|
long newloc = GETNUM(NULL);
|
||||||
long newloc=GETNUM(NULL);
|
|
||||||
long L;
|
long L;
|
||||||
if(KEY[loc] == 0)
|
if (KEY[loc] == 0) {
|
||||||
{
|
KEY[loc] = TRVS;
|
||||||
KEY[loc]=TRVS;
|
} else {
|
||||||
|
TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
|
||||||
}
|
}
|
||||||
else
|
while ((L = GETNUM(NULL)) != 0) {
|
||||||
{
|
TRAVEL[TRVS] = newloc * 1000 + L;
|
||||||
TRAVEL[TRVS-1]= -TRAVEL[TRVS-1];
|
TRVS = TRVS + 1;
|
||||||
|
if (TRVS == TRVSIZ)BUG(3);
|
||||||
}
|
}
|
||||||
while((L=GETNUM(NULL)) != 0)
|
TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
|
||||||
{
|
|
||||||
TRAVEL[TRVS]=newloc*1000+L;
|
|
||||||
TRVS=TRVS+1;
|
|
||||||
if(TRVS == TRVSIZ)BUG(3);
|
|
||||||
}
|
|
||||||
TRAVEL[TRVS-1]= -TRAVEL[TRVS-1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,11 +311,10 @@ static void read_section3_stuff(FILE* database)
|
||||||
* as an end-marker. */
|
* as an end-marker. */
|
||||||
static void read_vocabulary(FILE* database)
|
static void read_vocabulary(FILE* database)
|
||||||
{
|
{
|
||||||
for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++)
|
for (TABNDX = 1; TABNDX <= TABSIZ; TABNDX++) {
|
||||||
{
|
KTAB[TABNDX] = GETNUM(database);
|
||||||
KTAB[TABNDX]=GETNUM(database);
|
if (KTAB[TABNDX] == -1) return;
|
||||||
if(KTAB[TABNDX] == -1) return;
|
ATAB[TABNDX] = GETTXT(true, true, true);
|
||||||
ATAB[TABNDX]=GETTXT(true,true,true);
|
|
||||||
} /* end loop */
|
} /* end loop */
|
||||||
BUG(4);
|
BUG(4);
|
||||||
}
|
}
|
||||||
|
@ -342,10 +325,9 @@ static void read_vocabulary(FILE* database)
|
||||||
static void read_initial_locations(FILE* database)
|
static void read_initial_locations(FILE* database)
|
||||||
{
|
{
|
||||||
long OBJ;
|
long OBJ;
|
||||||
while((OBJ=GETNUM(database)) != -1)
|
while ((OBJ = GETNUM(database)) != -1) {
|
||||||
{
|
PLAC[OBJ] = GETNUM(NULL);
|
||||||
PLAC[OBJ]=GETNUM(NULL);
|
FIXD[OBJ] = GETNUM(NULL);
|
||||||
FIXD[OBJ]=GETNUM(NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,9 +335,8 @@ static void read_initial_locations(FILE* database)
|
||||||
static void read_action_verb_message_nr(FILE* database)
|
static void read_action_verb_message_nr(FILE* database)
|
||||||
{
|
{
|
||||||
long verb;
|
long verb;
|
||||||
while((verb=GETNUM(database)) != -1)
|
while ((verb = GETNUM(database)) != -1) {
|
||||||
{
|
ACTSPK[verb] = GETNUM(NULL);
|
||||||
ACTSPK[verb]=GETNUM(NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,13 +344,11 @@ static void read_action_verb_message_nr(FILE* database)
|
||||||
static void read_conditions(FILE* database)
|
static void read_conditions(FILE* database)
|
||||||
{
|
{
|
||||||
long K;
|
long K;
|
||||||
while((K=GETNUM(database)) != -1)
|
while ((K = GETNUM(database)) != -1) {
|
||||||
{
|
|
||||||
long loc;
|
long loc;
|
||||||
while((loc=GETNUM(NULL)) != 0)
|
while ((loc = GETNUM(NULL)) != 0) {
|
||||||
{
|
if (is_set(COND[loc], K)) BUG(8);
|
||||||
if(is_set(COND[loc],K)) BUG(8);
|
COND[loc] = COND[loc] + (1l << K);
|
||||||
COND[loc]=COND[loc] + (1l << K);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,15 +358,13 @@ static void read_conditions(FILE* database)
|
||||||
static void read_hints(FILE* database)
|
static void read_hints(FILE* database)
|
||||||
{
|
{
|
||||||
long K;
|
long K;
|
||||||
HNTMAX=0;
|
HNTMAX = 0;
|
||||||
while((K=GETNUM(database)) != -1)
|
while ((K = GETNUM(database)) != -1) {
|
||||||
{
|
if (K <= 0 || K > HNTSIZ)BUG(7);
|
||||||
if(K <= 0 || K > HNTSIZ)BUG(7);
|
for (int I = 1; I <= 4; I++) {
|
||||||
for (int I=1; I<=4; I++)
|
HINTS[K][I] = GETNUM(NULL);
|
||||||
{
|
|
||||||
HINTS[K][I] =GETNUM(NULL);
|
|
||||||
} /* end loop */
|
} /* end loop */
|
||||||
HNTMAX=(HNTMAX>K ? HNTMAX : K);
|
HNTMAX = (HNTMAX > K ? HNTMAX : K);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,23 +372,22 @@ static void read_hints(FILE* database)
|
||||||
static void read_sound_text(FILE* database)
|
static void read_sound_text(FILE* database)
|
||||||
{
|
{
|
||||||
long K;
|
long K;
|
||||||
while((K=GETNUM(database)) != -1)
|
while ((K = GETNUM(database)) != -1) {
|
||||||
{
|
long KK = GETNUM(NULL);
|
||||||
long KK=GETNUM(NULL);
|
long I = GETNUM(NULL);
|
||||||
long I=GETNUM(NULL);
|
if (I != 0) {
|
||||||
if(I != 0)
|
OBJSND[K] = (KK > 0 ? KK : 0);
|
||||||
{
|
OBJTXT[K] = (I > 0 ? I : 0);
|
||||||
OBJSND[K]=(KK>0 ? KK : 0);
|
|
||||||
OBJTXT[K]=(I>0 ? I : 0);
|
|
||||||
continue;
|
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
|
/* 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.
|
* lines; each line is preceded by a word pointing to the next pointer (i.e.
|
||||||
|
@ -423,18 +399,18 @@ static int read_database(FILE* database) {
|
||||||
* section 6's stuff. CTEXT(N) points to a player-class message. TTEXT is for
|
* 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). */
|
* section 14. We also clear COND (see description of section 9 for details). */
|
||||||
|
|
||||||
for (int I=1; I<=NOBJECTS; I++) {
|
for (int I = 1; I <= NOBJECTS; I++) {
|
||||||
PTEXT[I] = 0;
|
PTEXT[I] = 0;
|
||||||
OBJSND[I] = 0;
|
OBJSND[I] = 0;
|
||||||
OBJTXT[I] = 0;
|
OBJTXT[I] = 0;
|
||||||
}
|
}
|
||||||
for (int I=1; I<=RTXSIZ; I++) {
|
for (int I = 1; I <= RTXSIZ; I++) {
|
||||||
RTEXT[I] = 0;
|
RTEXT[I] = 0;
|
||||||
}
|
}
|
||||||
for (int I=1; I<=CLSMAX; I++) {
|
for (int I = 1; I <= CLSMAX; I++) {
|
||||||
CTEXT[I] = 0;
|
CTEXT[I] = 0;
|
||||||
}
|
}
|
||||||
for (int I=1; I<=LOCSIZ; I++) {
|
for (int I = 1; I <= LOCSIZ; I++) {
|
||||||
STEXT[I] = 0;
|
STEXT[I] = 0;
|
||||||
LTEXT[I] = 0;
|
LTEXT[I] = 0;
|
||||||
COND[I] = 0;
|
COND[I] = 0;
|
||||||
|
@ -449,28 +425,55 @@ static int read_database(FILE* database) {
|
||||||
|
|
||||||
/* Start new data section. Sect is the section number. */
|
/* Start new data section. Sect is the section number. */
|
||||||
|
|
||||||
while(true)
|
while (true) {
|
||||||
{
|
long sect = GETNUM(database);
|
||||||
long sect=GETNUM(database);
|
OLDLOC = -1;
|
||||||
OLDLOC= -1;
|
switch (sect) {
|
||||||
switch (sect)
|
case 0:
|
||||||
{
|
return (0);
|
||||||
case 0: return(0);
|
case 1:
|
||||||
case 1: read_messages(database, sect); break;
|
read_messages(database, sect);
|
||||||
case 2: read_messages(database, sect); break;
|
break;
|
||||||
case 3: read_section3_stuff(database); break;
|
case 2:
|
||||||
case 4: read_vocabulary(database); break;
|
read_messages(database, sect);
|
||||||
case 5: read_messages(database, sect); break;
|
break;
|
||||||
case 6: read_messages(database, sect); break;
|
case 3:
|
||||||
case 7: read_initial_locations(database); break;
|
read_section3_stuff(database);
|
||||||
case 8: read_action_verb_message_nr(database); break;
|
break;
|
||||||
case 9: read_conditions(database); break;
|
case 4:
|
||||||
case 10: read_messages(database, sect); break;
|
read_vocabulary(database);
|
||||||
case 11: read_hints(database); break;
|
break;
|
||||||
case 12: break;
|
case 5:
|
||||||
case 13: read_sound_text(database); break;
|
read_messages(database, sect);
|
||||||
case 14: read_messages(database, sect); break;
|
break;
|
||||||
default: BUG(9);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -495,10 +498,8 @@ static void write_0d(FILE* header_file, long single, const char* varname)
|
||||||
static void write_1d(FILE* header_file, long array[], long dim, const char* varname)
|
static void write_1d(FILE* header_file, long array[], long dim, const char* varname)
|
||||||
{
|
{
|
||||||
fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
|
fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
|
||||||
for (int i = 0; i < dim; ++i)
|
for (int i = 0; i < dim; ++i) {
|
||||||
{
|
if (i % 10 == 0) {
|
||||||
if (i % 10 == 0)
|
|
||||||
{
|
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
fprintf(header_file, "\n");
|
fprintf(header_file, "\n");
|
||||||
fprintf(header_file, " ");
|
fprintf(header_file, " ");
|
||||||
|
@ -511,11 +512,9 @@ static void write_1d(FILE* header_file, long array[], long dim, const char* varn
|
||||||
static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, const char* varname)
|
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);
|
fprintf(header_file, "LOCATION long %s[][%ld] INITIALIZE(= {\n", varname, dim2);
|
||||||
for (int i = 0; i < dim1; ++i)
|
for (int i = 0; i < dim1; ++i) {
|
||||||
{
|
|
||||||
fprintf(header_file, " {");
|
fprintf(header_file, " {");
|
||||||
for (int j = 0; j < dim2; ++j)
|
for (int j = 0; j < dim2; ++j) {
|
||||||
{
|
|
||||||
fprintf(header_file, "%ld, ", matrix[i][j]);
|
fprintf(header_file, "%ld, ", matrix[i][j]);
|
||||||
}
|
}
|
||||||
fprintf(header_file, "},\n");
|
fprintf(header_file, "},\n");
|
||||||
|
@ -526,10 +525,10 @@ static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, lo
|
||||||
static void write_file(FILE* header_file)
|
static void write_file(FILE* header_file)
|
||||||
{
|
{
|
||||||
int MAXDIE;
|
int MAXDIE;
|
||||||
for (int i=0; i<=4; i++) {
|
for (int i = 0; i <= 4; i++) {
|
||||||
long x = 2*i+81;
|
long x = 2 * i + 81;
|
||||||
if(RTEXT[x] != 0)
|
if (RTEXT[x] != 0)
|
||||||
MAXDIE=i+1;
|
MAXDIE = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -587,5 +586,5 @@ int main(void)
|
||||||
write_file(header_file);
|
write_file(header_file);
|
||||||
fclose(header_file);
|
fclose(header_file);
|
||||||
|
|
||||||
return(EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
244
init.c
244
init.c
|
@ -175,19 +175,19 @@ void initialise(void)
|
||||||
if (oldstyle)
|
if (oldstyle)
|
||||||
printf("Initialising...\n");
|
printf("Initialising...\n");
|
||||||
|
|
||||||
for (int i=1; i<=NOBJECTS; i++) {
|
for (int i = 1; i <= NOBJECTS; i++) {
|
||||||
game.place[i] = NOWHERE;
|
game.place[i] = NOWHERE;
|
||||||
game.prop[i] = 0;
|
game.prop[i] = 0;
|
||||||
game.link[i+NOBJECTS]=game.link[i]=0;
|
game.link[i + NOBJECTS] = game.link[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=1; i<=LOCSIZ; i++) {
|
for (int i = 1; i <= LOCSIZ; i++) {
|
||||||
game.abbrev[i]=0;
|
game.abbrev[i] = 0;
|
||||||
if (!(locations[i].description.big == 0 || KEY[i] == 0)) {
|
if (!(locations[i].description.big == 0 || KEY[i] == 0)) {
|
||||||
int k=KEY[i];
|
int k = KEY[i];
|
||||||
if(MOD(labs(TRAVEL[k]),1000) == 1)COND[i]=2;
|
if (MOD(labs(TRAVEL[k]), 1000) == 1)COND[i] = 2;
|
||||||
}
|
}
|
||||||
game.atloc[i]=0;
|
game.atloc[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up the game.atloc and game.link arrays as described above.
|
/* 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
|
* This also sets up "game.place" and "fixed" as copies of "PLAC" and
|
||||||
* "FIXD". Also, since two-placed objects are typically best
|
* "FIXD". Also, since two-placed objects are typically best
|
||||||
* described last, we'll drop them first. */
|
* described last, we'll drop them first. */
|
||||||
for (int i=1; i<=NOBJECTS; i++) {
|
for (int i = 1; i <= NOBJECTS; i++) {
|
||||||
int k=NOBJECTS + 1 - i;
|
int k = NOBJECTS + 1 - i;
|
||||||
if(FIXD[k] > 0) {
|
if (FIXD[k] > 0) {
|
||||||
DROP(k+NOBJECTS,FIXD[k]);
|
DROP(k + NOBJECTS, FIXD[k]);
|
||||||
DROP(k,PLAC[k]);
|
DROP(k, PLAC[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=1; i<=NOBJECTS; i++) {
|
for (int i = 1; i <= NOBJECTS; i++) {
|
||||||
int k=NOBJECTS + 1 - i;
|
int k = NOBJECTS + 1 - i;
|
||||||
game.fixed[k]=FIXD[k];
|
game.fixed[k] = FIXD[k];
|
||||||
if(PLAC[k] != 0 && FIXD[k] <= 0)
|
if (PLAC[k] != 0 && FIXD[k] <= 0)
|
||||||
DROP(k,PLAC[k]);
|
DROP(k, PLAC[k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Treasures, as noted earlier, are objects MINTRS through MAXTRS
|
/* Treasures, as noted earlier, are objects MINTRS through MAXTRS
|
||||||
* Their props are initially -1, and are set to 0 the first time
|
* Their props are initially -1, and are set to 0 the first time
|
||||||
* they are described. game.tally keeps track of how many are
|
* they are described. game.tally keeps track of how many are
|
||||||
* not yet found, so we know when to close the cave. */
|
* not yet found, so we know when to close the cave. */
|
||||||
game.tally=0;
|
game.tally = 0;
|
||||||
for (int treasure=MINTRS; treasure<=MAXTRS; treasure++) {
|
for (int treasure = MINTRS; treasure <= MAXTRS; treasure++) {
|
||||||
if(object_descriptions[treasure].inventory != 0)
|
if (object_descriptions[treasure].inventory != 0)
|
||||||
game.prop[treasure]= -1;
|
game.prop[treasure] = -1;
|
||||||
game.tally=game.tally-game.prop[treasure];
|
game.tally = game.tally - game.prop[treasure];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the hint stuff. game.hintlc[i] is how long he's been at LOC
|
/* 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
|
* with cond bit i. game.hinted[i] is true iff hint i has been
|
||||||
* used. */
|
* used. */
|
||||||
for (int i=1; i<=HNTMAX; i++) {
|
for (int i = 1; i <= HNTMAX; i++) {
|
||||||
game.hinted[i]=false;
|
game.hinted[i] = false;
|
||||||
game.hintlc[i]=0;
|
game.hintlc[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Define some handy mnemonics. These correspond to object numbers. */
|
/* Define some handy mnemonics. These correspond to object numbers. */
|
||||||
AXE=VOCWRD(12405,1);
|
AXE = VOCWRD(12405, 1);
|
||||||
BATTER=VOCWRD(201202005,1);
|
BATTER = VOCWRD(201202005, 1);
|
||||||
BEAR=VOCWRD(2050118,1);
|
BEAR = VOCWRD(2050118, 1);
|
||||||
BIRD=VOCWRD(2091804,1);
|
BIRD = VOCWRD(2091804, 1);
|
||||||
BLOOD=VOCWRD(212151504,1);
|
BLOOD = VOCWRD(212151504, 1);
|
||||||
BOTTLE=VOCWRD(215202012,1);
|
BOTTLE = VOCWRD(215202012, 1);
|
||||||
CAGE=VOCWRD(3010705,1);
|
CAGE = VOCWRD(3010705, 1);
|
||||||
CAVITY=VOCWRD(301220920,1);
|
CAVITY = VOCWRD(301220920, 1);
|
||||||
CHASM=VOCWRD(308011913,1);
|
CHASM = VOCWRD(308011913, 1);
|
||||||
CLAM=VOCWRD(3120113,1);
|
CLAM = VOCWRD(3120113, 1);
|
||||||
DOOR=VOCWRD(4151518,1);
|
DOOR = VOCWRD(4151518, 1);
|
||||||
DRAGON=VOCWRD(418010715,1);
|
DRAGON = VOCWRD(418010715, 1);
|
||||||
DWARF=VOCWRD(423011806,1);
|
DWARF = VOCWRD(423011806, 1);
|
||||||
FISSUR=VOCWRD(609191921,1);
|
FISSUR = VOCWRD(609191921, 1);
|
||||||
FOOD=VOCWRD(6151504,1);
|
FOOD = VOCWRD(6151504, 1);
|
||||||
GRATE=VOCWRD(718012005,1);
|
GRATE = VOCWRD(718012005, 1);
|
||||||
KEYS=VOCWRD(11052519,1);
|
KEYS = VOCWRD(11052519, 1);
|
||||||
KNIFE=VOCWRD(1114090605,1);
|
KNIFE = VOCWRD(1114090605, 1);
|
||||||
LAMP=VOCWRD(12011316,1);
|
LAMP = VOCWRD(12011316, 1);
|
||||||
MAGZIN=VOCWRD(1301070126,1);
|
MAGZIN = VOCWRD(1301070126, 1);
|
||||||
MESSAG=VOCWRD(1305191901,1);
|
MESSAG = VOCWRD(1305191901, 1);
|
||||||
MIRROR=VOCWRD(1309181815,1);
|
MIRROR = VOCWRD(1309181815, 1);
|
||||||
OGRE=VOCWRD(15071805,1);
|
OGRE = VOCWRD(15071805, 1);
|
||||||
OIL=VOCWRD(150912,1);
|
OIL = VOCWRD(150912, 1);
|
||||||
OYSTER=VOCWRD(1525192005,1);
|
OYSTER = VOCWRD(1525192005, 1);
|
||||||
PILLOW=VOCWRD(1609121215,1);
|
PILLOW = VOCWRD(1609121215, 1);
|
||||||
PLANT=VOCWRD(1612011420,1);
|
PLANT = VOCWRD(1612011420, 1);
|
||||||
PLANT2=PLANT+1;
|
PLANT2 = PLANT + 1;
|
||||||
RESER=VOCWRD(1805190518,1);
|
RESER = VOCWRD(1805190518, 1);
|
||||||
ROD=VOCWRD(181504,1);
|
ROD = VOCWRD(181504, 1);
|
||||||
ROD2=ROD+1;
|
ROD2 = ROD + 1;
|
||||||
SIGN=VOCWRD(19090714,1);
|
SIGN = VOCWRD(19090714, 1);
|
||||||
SNAKE=VOCWRD(1914011105,1);
|
SNAKE = VOCWRD(1914011105, 1);
|
||||||
STEPS=VOCWRD(1920051619,1);
|
STEPS = VOCWRD(1920051619, 1);
|
||||||
TROLL=VOCWRD(2018151212,1);
|
TROLL = VOCWRD(2018151212, 1);
|
||||||
TROLL2=TROLL+1;
|
TROLL2 = TROLL + 1;
|
||||||
URN=VOCWRD(211814,1);
|
URN = VOCWRD(211814, 1);
|
||||||
VEND=VOCWRD(1755140409,1);
|
VEND = VOCWRD(1755140409, 1);
|
||||||
VOLCAN=VOCWRD(1765120301,1);
|
VOLCAN = VOCWRD(1765120301, 1);
|
||||||
WATER=VOCWRD(1851200518,1);
|
WATER = VOCWRD(1851200518, 1);
|
||||||
|
|
||||||
/* Objects from MINTRS through MAXTRS are treasures. Here are a few. */
|
/* Objects from MINTRS through MAXTRS are treasures. Here are a few. */
|
||||||
AMBER=VOCWRD(113020518,1);
|
AMBER = VOCWRD(113020518, 1);
|
||||||
CHAIN=VOCWRD(308010914,1);
|
CHAIN = VOCWRD(308010914, 1);
|
||||||
CHEST=VOCWRD(308051920,1);
|
CHEST = VOCWRD(308051920, 1);
|
||||||
COINS=VOCWRD(315091419,1);
|
COINS = VOCWRD(315091419, 1);
|
||||||
EGGS=VOCWRD(5070719,1);
|
EGGS = VOCWRD(5070719, 1);
|
||||||
EMRALD=VOCWRD(513051801,1);
|
EMRALD = VOCWRD(513051801, 1);
|
||||||
JADE=VOCWRD(10010405,1);
|
JADE = VOCWRD(10010405, 1);
|
||||||
NUGGET=VOCWRD(7151204,1);
|
NUGGET = VOCWRD(7151204, 1);
|
||||||
PEARL=VOCWRD(1605011812,1);
|
PEARL = VOCWRD(1605011812, 1);
|
||||||
PYRAM=VOCWRD(1625180113,1);
|
PYRAM = VOCWRD(1625180113, 1);
|
||||||
RUBY=VOCWRD(18210225,1);
|
RUBY = VOCWRD(18210225, 1);
|
||||||
RUG=VOCWRD(182107,1);
|
RUG = VOCWRD(182107, 1);
|
||||||
SAPPH=VOCWRD(1901161608,1);
|
SAPPH = VOCWRD(1901161608, 1);
|
||||||
TRIDNT=VOCWRD(2018090405,1);
|
TRIDNT = VOCWRD(2018090405, 1);
|
||||||
VASE=VOCWRD(22011905,1);
|
VASE = VOCWRD(22011905, 1);
|
||||||
|
|
||||||
/* These are motion-verb numbers. */
|
/* These are motion-verb numbers. */
|
||||||
BACK=VOCWRD(2010311,0);
|
BACK = VOCWRD(2010311, 0);
|
||||||
CAVE=VOCWRD(3012205,0);
|
CAVE = VOCWRD(3012205, 0);
|
||||||
DPRSSN=VOCWRD(405161805,0);
|
DPRSSN = VOCWRD(405161805, 0);
|
||||||
ENTER=VOCWRD(514200518,0);
|
ENTER = VOCWRD(514200518, 0);
|
||||||
ENTRNC=VOCWRD(514201801,0);
|
ENTRNC = VOCWRD(514201801, 0);
|
||||||
LOOK=VOCWRD(12151511,0);
|
LOOK = VOCWRD(12151511, 0);
|
||||||
NUL=VOCWRD(14211212,0);
|
NUL = VOCWRD(14211212, 0);
|
||||||
STREAM=VOCWRD(1920180501,0);
|
STREAM = VOCWRD(1920180501, 0);
|
||||||
|
|
||||||
/* And some action verbs. */
|
/* And some action verbs. */
|
||||||
FIND=VOCWRD(6091404,2);
|
FIND = VOCWRD(6091404, 2);
|
||||||
INVENT=VOCWRD(914220514,2);
|
INVENT = VOCWRD(914220514, 2);
|
||||||
LOCK=VOCWRD(12150311,2);
|
LOCK = VOCWRD(12150311, 2);
|
||||||
SAY=VOCWRD(190125,2);
|
SAY = VOCWRD(190125, 2);
|
||||||
THROW=VOCWRD(2008181523,2);
|
THROW = VOCWRD(2008181523, 2);
|
||||||
|
|
||||||
/* Initialise the dwarves. game.dloc is loc of dwarves,
|
/* Initialise the dwarves. game.dloc is loc of dwarves,
|
||||||
* hard-wired in. game.odloc is prior loc of each dwarf,
|
* hard-wired in. game.odloc is prior loc of each dwarf,
|
||||||
|
@ -325,16 +325,16 @@ void initialise(void)
|
||||||
* loc stored in game.chloc2. */
|
* loc stored in game.chloc2. */
|
||||||
game.chloc = LOC_DEADEND12;
|
game.chloc = LOC_DEADEND12;
|
||||||
game.chloc2 = LOC_DEADEND13;
|
game.chloc2 = LOC_DEADEND13;
|
||||||
for (int i=1; i<=NDWARVES; i++) {
|
for (int i = 1; i <= NDWARVES; i++) {
|
||||||
game.dseen[i]=false;
|
game.dseen[i] = false;
|
||||||
}
|
}
|
||||||
game.dflag=0;
|
game.dflag = 0;
|
||||||
game.dloc[1] = LOC_KINGHALL;
|
game.dloc[1] = LOC_KINGHALL;
|
||||||
game.dloc[2] = LOC_WESTBANK;
|
game.dloc[2] = LOC_WESTBANK;
|
||||||
game.dloc[3] = LOC_Y2;
|
game.dloc[3] = LOC_Y2;
|
||||||
game.dloc[4] = LOC_ALIKE3;
|
game.dloc[4] = LOC_ALIKE3;
|
||||||
game.dloc[5] = LOC_COMPLEX;
|
game.dloc[5] = LOC_COMPLEX;
|
||||||
game.dloc[6]=game.chloc;
|
game.dloc[6] = game.chloc;
|
||||||
|
|
||||||
/* Other random flags and counters, as follows:
|
/* Other random flags and counters, as follows:
|
||||||
* game.abbnum How often we should print non-abbreviated descriptions
|
* 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.trnluz # points lost so far due to number of turns used
|
||||||
* game.turns Tallies how many commands he's given (ignores yes/no)
|
* game.turns Tallies how many commands he's given (ignores yes/no)
|
||||||
* Logicals were explained earlier */
|
* Logicals were explained earlier */
|
||||||
game.turns=0;
|
game.turns = 0;
|
||||||
game.trndex=1;
|
game.trndex = 1;
|
||||||
game.thresh= -1;
|
game.thresh = -1;
|
||||||
if (TRNVLS > 0)
|
if (TRNVLS > 0)
|
||||||
game.thresh=MOD(TRNVAL[1],100000)+1;
|
game.thresh = MOD(TRNVAL[1], 100000) + 1;
|
||||||
game.trnluz=0;
|
game.trnluz = 0;
|
||||||
game.lmwarn=false;
|
game.lmwarn = false;
|
||||||
game.iwest=0;
|
game.iwest = 0;
|
||||||
game.knfloc=0;
|
game.knfloc = 0;
|
||||||
game.detail=0;
|
game.detail = 0;
|
||||||
game.abbnum=5;
|
game.abbnum = 5;
|
||||||
game.numdie=0;
|
game.numdie = 0;
|
||||||
game.holdng=0;
|
game.holdng = 0;
|
||||||
game.dkill=0;
|
game.dkill = 0;
|
||||||
game.foobar=0;
|
game.foobar = 0;
|
||||||
game.bonus=0;
|
game.bonus = 0;
|
||||||
game.clock1=30;
|
game.clock1 = 30;
|
||||||
game.clock2=50;
|
game.clock2 = 50;
|
||||||
game.conds=SETBIT(11);
|
game.conds = SETBIT(11);
|
||||||
game.saved=0;
|
game.saved = 0;
|
||||||
game.closng=false;
|
game.closng = false;
|
||||||
game.panic=false;
|
game.panic = false;
|
||||||
game.closed=false;
|
game.closed = false;
|
||||||
game.clshnt=false;
|
game.clshnt = false;
|
||||||
game.novice=false;
|
game.novice = false;
|
||||||
game.blklin=true;
|
game.blklin = true;
|
||||||
}
|
}
|
||||||
|
|
192
misc.c
192
misc.c
|
@ -13,19 +13,17 @@
|
||||||
char* xstrdup(const char* s)
|
char* xstrdup(const char* s)
|
||||||
{
|
{
|
||||||
char* ptr = strdup(s);
|
char* ptr = strdup(s);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Out of memory!\n");
|
fprintf(stderr, "Out of memory!\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
return(ptr);
|
return (ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void packed_to_token(long packed, char token[6])
|
void packed_to_token(long packed, char token[6])
|
||||||
{
|
{
|
||||||
// Unpack and map back to ASCII.
|
// Unpack and map back to ASCII.
|
||||||
for (int i = 0; i < 5; ++i)
|
for (int i = 0; i < 5; ++i) {
|
||||||
{
|
|
||||||
char advent = (packed >> i * 6) & 63;
|
char advent = (packed >> i * 6) & 63;
|
||||||
token[4 - i] = advent_to_ascii[(int) advent];
|
token[4 - i] = advent_to_ascii[(int) advent];
|
||||||
}
|
}
|
||||||
|
@ -34,8 +32,7 @@ void packed_to_token(long packed, char token[6])
|
||||||
token[5] = '\0';
|
token[5] = '\0';
|
||||||
|
|
||||||
// Replace trailing whitespace with \0.
|
// Replace trailing whitespace with \0.
|
||||||
for (int i = 4; i >= 0; --i)
|
for (int i = 4; i >= 0; --i) {
|
||||||
{
|
|
||||||
if (token[i] == ' ' || token[i] == '\t')
|
if (token[i] == ' ' || token[i] == '\t')
|
||||||
token[i] = '\0';
|
token[i] = '\0';
|
||||||
else
|
else
|
||||||
|
@ -67,57 +64,45 @@ void newspeak(const char* msg)
|
||||||
|
|
||||||
// Handle format specifiers (including the custom %C, %L, %S) by adjusting the parameter accordingly, and replacing the specifier with %s.
|
// 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
|
int pi = 0; // parameter index
|
||||||
for (int i = 0; i < (int)strlen(msg); ++i)
|
for (int i = 0; i < (int)strlen(msg); ++i) {
|
||||||
{
|
if (msg[i] == '%') {
|
||||||
if (msg[i] == '%')
|
|
||||||
{
|
|
||||||
++pi;
|
++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.
|
// 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')
|
if (msg[i + 1] == 'd') {
|
||||||
{
|
|
||||||
copy[i + 1] = 's';
|
copy[i + 1] = 's';
|
||||||
sprintf(parameters[pi], "%ld", PARMS[pi]);
|
sprintf(parameters[pi], "%ld", PARMS[pi]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmodified string specifier.
|
// Unmodified string specifier.
|
||||||
if (msg[i + 1] == 's')
|
if (msg[i + 1] == 's') {
|
||||||
{
|
|
||||||
packed_to_token(PARMS[pi], parameters[pi]);
|
packed_to_token(PARMS[pi], parameters[pi]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Singular/plural specifier.
|
// Singular/plural specifier.
|
||||||
if (msg[i + 1] == 'S')
|
if (msg[i + 1] == 'S') {
|
||||||
{
|
|
||||||
copy[i + 1] = 's';
|
copy[i + 1] = 's';
|
||||||
if (PARMS[pi - 1] > 1) // look at the *previous* parameter (which by necessity must be numeric)
|
if (PARMS[pi - 1] > 1) { // look at the *previous* parameter (which by necessity must be numeric)
|
||||||
{
|
|
||||||
sprintf(parameters[pi], "%s", "s");
|
sprintf(parameters[pi], "%s", "s");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(parameters[pi], "%s", "");
|
sprintf(parameters[pi], "%s", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// All-lowercase specifier.
|
// All-lowercase specifier.
|
||||||
if (msg[i + 1] == 'L')
|
if (msg[i + 1] == 'L') {
|
||||||
{
|
|
||||||
copy[i + 1] = 's';
|
copy[i + 1] = 's';
|
||||||
packed_to_token(PARMS[pi], parameters[pi]);
|
packed_to_token(PARMS[pi], parameters[pi]);
|
||||||
for (int j = 0; j < (int)strlen(parameters[pi]); ++j)
|
for (int j = 0; j < (int)strlen(parameters[pi]); ++j) {
|
||||||
{
|
|
||||||
parameters[pi][j] = tolower(parameters[pi][j]);
|
parameters[pi][j] = tolower(parameters[pi][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// First char uppercase, rest lowercase.
|
// First char uppercase, rest lowercase.
|
||||||
if (msg[i + 1] == 'C')
|
if (msg[i + 1] == 'C') {
|
||||||
{
|
|
||||||
copy[i + 1] = 's';
|
copy[i + 1] = 's';
|
||||||
packed_to_token(PARMS[pi], parameters[pi]);
|
packed_to_token(PARMS[pi], parameters[pi]);
|
||||||
for (int j = 0; j < (int)strlen(parameters[pi]); ++j)
|
for (int j = 0; j < (int)strlen(parameters[pi]); ++j) {
|
||||||
{
|
|
||||||
parameters[pi][j] = tolower(parameters[pi][j]);
|
parameters[pi][j] = tolower(parameters[pi][j]);
|
||||||
}
|
}
|
||||||
parameters[pi][0] = toupper(parameters[pi][0]);
|
parameters[pi][0] = toupper(parameters[pi][0]);
|
||||||
|
@ -135,7 +120,7 @@ void newspeak(const char* msg)
|
||||||
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
|
/* 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
|
* the index of the inventory message for object. (INVEN+N+1 message
|
||||||
* is game.prop=N message). */
|
* is game.prop=N message). */
|
||||||
|
@ -160,7 +145,7 @@ void SETPRM(long first, long p1, long p2)
|
||||||
BUG(29);
|
BUG(29);
|
||||||
else {
|
else {
|
||||||
PARMS[first] = p1;
|
PARMS[first] = p1;
|
||||||
PARMS[first+1] = p2;
|
PARMS[first + 1] = p2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,21 +165,21 @@ bool GETIN(FILE *input,
|
||||||
TYPE0();
|
TYPE0();
|
||||||
if (!MAPLIN(input))
|
if (!MAPLIN(input))
|
||||||
return false;
|
return false;
|
||||||
*pword1=GETTXT(true,true,true);
|
*pword1 = GETTXT(true, true, true);
|
||||||
if (game.blklin && *pword1 < 0)
|
if (game.blklin && *pword1 < 0)
|
||||||
continue;
|
continue;
|
||||||
*pword1x=GETTXT(false,true,true);
|
*pword1x = GETTXT(false, true, true);
|
||||||
do {
|
do {
|
||||||
junk=GETTXT(false,true,true);
|
junk = GETTXT(false, true, true);
|
||||||
} while
|
} while
|
||||||
(junk > 0);
|
(junk > 0);
|
||||||
*pword2=GETTXT(true,true,true);
|
*pword2 = GETTXT(true, true, true);
|
||||||
*pword2x=GETTXT(false,true,true);
|
*pword2x = GETTXT(false, true, true);
|
||||||
do {
|
do {
|
||||||
junk=GETTXT(false,true,true);
|
junk = GETTXT(false, true, true);
|
||||||
} while
|
} while
|
||||||
(junk > 0);
|
(junk > 0);
|
||||||
if (GETTXT(true,true,true) <= 0)
|
if (GETTXT(true, true, true) <= 0)
|
||||||
return true;
|
return true;
|
||||||
RSPEAK(TWO_WORDS);
|
RSPEAK(TWO_WORDS);
|
||||||
}
|
}
|
||||||
|
@ -235,36 +220,36 @@ long GETTXT(bool skip, bool onewrd, bool upper)
|
||||||
|
|
||||||
if (LNPOSN != splitting)
|
if (LNPOSN != splitting)
|
||||||
splitting = -1;
|
splitting = -1;
|
||||||
text= -1;
|
text = -1;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (LNPOSN > LNLENG)
|
if (LNPOSN > LNLENG)
|
||||||
return(text);
|
return (text);
|
||||||
if ((!skip) || INLINE[LNPOSN] != 0)
|
if ((!skip) || INLINE[LNPOSN] != 0)
|
||||||
break;
|
break;
|
||||||
++LNPOSN;
|
++LNPOSN;
|
||||||
}
|
}
|
||||||
|
|
||||||
text=0;
|
text = 0;
|
||||||
for (int I=1; I<=TOKLEN; I++) {
|
for (int I = 1; I <= TOKLEN; I++) {
|
||||||
text=text*64;
|
text = text * 64;
|
||||||
if (LNPOSN > LNLENG || (onewrd && INLINE[LNPOSN] == 0))
|
if (LNPOSN > LNLENG || (onewrd && INLINE[LNPOSN] == 0))
|
||||||
continue;
|
continue;
|
||||||
char current=INLINE[LNPOSN];
|
char current = INLINE[LNPOSN];
|
||||||
if (current < ascii_to_advent['%']) {
|
if (current < ascii_to_advent['%']) {
|
||||||
splitting = -1;
|
splitting = -1;
|
||||||
if (upper && current >= ascii_to_advent['a'])
|
if (upper && current >= ascii_to_advent['a'])
|
||||||
current=current-26;
|
current = current - 26;
|
||||||
text=text+current;
|
text = text + current;
|
||||||
++LNPOSN;
|
++LNPOSN;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (splitting != LNPOSN) {
|
if (splitting != LNPOSN) {
|
||||||
text=text+ascii_to_advent['%'];
|
text = text + ascii_to_advent['%'];
|
||||||
splitting = LNPOSN;
|
splitting = LNPOSN;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
text=text+current-ascii_to_advent['%'];
|
text = text + current - ascii_to_advent['%'];
|
||||||
splitting = -1;
|
splitting = -1;
|
||||||
++LNPOSN;
|
++LNPOSN;
|
||||||
}
|
}
|
||||||
|
@ -283,13 +268,13 @@ token_t MAKEWD(long letters)
|
||||||
{
|
{
|
||||||
long i = 1, word = 0;
|
long i = 1, word = 0;
|
||||||
|
|
||||||
for (long k=letters; k != 0; k=k/100) {
|
for (long k = letters; k != 0; k = k / 100) {
|
||||||
word=word+i*(MOD(k,50)+10);
|
word = word + i * (MOD(k, 50) + 10);
|
||||||
i=i*64;
|
i = i * 64;
|
||||||
if (MOD(k,100) > 50)word=word+i*5;
|
if (MOD(k, 100) > 50)word = word + i * 5;
|
||||||
}
|
}
|
||||||
i=64L*64L*64L*64L*64L/i;
|
i = 64L * 64L * 64L * 64L * 64L / i;
|
||||||
word=word*i;
|
word = word * i;
|
||||||
return word;
|
return word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,10 +284,10 @@ void TYPE0(void)
|
||||||
{
|
{
|
||||||
long temp;
|
long temp;
|
||||||
|
|
||||||
temp=LNLENG;
|
temp = LNLENG;
|
||||||
LNLENG=0;
|
LNLENG = 0;
|
||||||
TYPE();
|
TYPE();
|
||||||
LNLENG=temp;
|
LNLENG = temp;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,20 +303,20 @@ long VOCAB(long id, long init)
|
||||||
{
|
{
|
||||||
long lexeme;
|
long lexeme;
|
||||||
|
|
||||||
for (long i=1; i<=TABSIZ; i++) {
|
for (long i = 1; i <= TABSIZ; i++) {
|
||||||
if (KTAB[i] == -1) {
|
if (KTAB[i] == -1) {
|
||||||
lexeme= -1;
|
lexeme = -1;
|
||||||
if (init < 0)
|
if (init < 0)
|
||||||
return(lexeme);
|
return (lexeme);
|
||||||
BUG(5);
|
BUG(5);
|
||||||
}
|
}
|
||||||
if (init >= 0 && KTAB[i]/1000 != init)
|
if (init >= 0 && KTAB[i] / 1000 != init)
|
||||||
continue;
|
continue;
|
||||||
if (ATAB[i] == id) {
|
if (ATAB[i] == id) {
|
||||||
lexeme=KTAB[i];
|
lexeme = KTAB[i];
|
||||||
if (init >= 0)
|
if (init >= 0)
|
||||||
lexeme=MOD(lexeme,1000);
|
lexeme = MOD(lexeme, 1000);
|
||||||
return(lexeme);
|
return (lexeme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BUG(21);
|
BUG(21);
|
||||||
|
@ -343,10 +328,10 @@ void JUGGLE(long object)
|
||||||
{
|
{
|
||||||
long i, j;
|
long i, j;
|
||||||
|
|
||||||
i=game.place[object];
|
i = game.place[object];
|
||||||
j=game.fixed[object];
|
j = game.fixed[object];
|
||||||
MOVE(object,i);
|
MOVE(object, i);
|
||||||
MOVE(object+NOBJECTS,j);
|
MOVE(object + NOBJECTS, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MOVE(long object, long where)
|
void MOVE(long object, long where)
|
||||||
|
@ -358,20 +343,20 @@ void MOVE(long object, long where)
|
||||||
long from;
|
long from;
|
||||||
|
|
||||||
if (object > NOBJECTS)
|
if (object > NOBJECTS)
|
||||||
from=game.fixed[object-NOBJECTS];
|
from = game.fixed[object - NOBJECTS];
|
||||||
else
|
else
|
||||||
from=game.place[object];
|
from = game.place[object];
|
||||||
if (from != NOWHERE && from != CARRIED && !SPECIAL(from))
|
if (from != NOWHERE && from != CARRIED && !SPECIAL(from))
|
||||||
CARRY(object,from);
|
CARRY(object, from);
|
||||||
DROP(object,where);
|
DROP(object, where);
|
||||||
}
|
}
|
||||||
|
|
||||||
long PUT(long object, long where, long pval)
|
long PUT(long object, long where, long pval)
|
||||||
/* PUT is the same as MOVE, except it returns a value used to set up the
|
/* PUT is the same as MOVE, except it returns a value used to set up the
|
||||||
* negated game.prop values for the repository objects. */
|
* negated game.prop values for the repository objects. */
|
||||||
{
|
{
|
||||||
MOVE(object,where);
|
MOVE(object, where);
|
||||||
return (-1)-pval;;
|
return (-1) - pval;;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CARRY(long object, long where)
|
void CARRY(long object, long where)
|
||||||
|
@ -388,14 +373,14 @@ void CARRY(long object, long where)
|
||||||
++game.holdng;
|
++game.holdng;
|
||||||
}
|
}
|
||||||
if (game.atloc[where] == object) {
|
if (game.atloc[where] == object) {
|
||||||
game.atloc[where]=game.link[object];
|
game.atloc[where] = game.link[object];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
temp=game.atloc[where];
|
temp = game.atloc[where];
|
||||||
while (game.link[temp] != object) {
|
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)
|
void DROP(long object, long where)
|
||||||
|
@ -403,9 +388,8 @@ void DROP(long object, long where)
|
||||||
* game.holdng if the object was being toted. */
|
* game.holdng if the object was being toted. */
|
||||||
{
|
{
|
||||||
if (object > NOBJECTS)
|
if (object > NOBJECTS)
|
||||||
game.fixed[object-NOBJECTS] = where;
|
game.fixed[object - NOBJECTS] = where;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (game.place[object] == CARRIED)
|
if (game.place[object] == CARRIED)
|
||||||
--game.holdng;
|
--game.holdng;
|
||||||
game.place[object] = where;
|
game.place[object] = where;
|
||||||
|
@ -423,17 +407,17 @@ long ATDWRF(long where)
|
||||||
{
|
{
|
||||||
long at;
|
long at;
|
||||||
|
|
||||||
at =0;
|
at = 0;
|
||||||
if (game.dflag < 2)
|
if (game.dflag < 2)
|
||||||
return(at);
|
return (at);
|
||||||
at = -1;
|
at = -1;
|
||||||
for (long i=1; i<=NDWARVES-1; i++) {
|
for (long i = 1; i <= NDWARVES - 1; i++) {
|
||||||
if (game.dloc[i] == where)
|
if (game.dloc[i] == where)
|
||||||
return i;
|
return i;
|
||||||
if (game.dloc[i] != 0)
|
if (game.dloc[i] != 0)
|
||||||
at=0;
|
at = 0;
|
||||||
}
|
}
|
||||||
return(at);
|
return (at);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value,
|
/* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value,
|
||||||
|
@ -442,7 +426,7 @@ long ATDWRF(long where)
|
||||||
long SETBIT(long bit)
|
long SETBIT(long bit)
|
||||||
/* Returns 2**bit for use in constructing bit-masks. */
|
/* Returns 2**bit for use in constructing bit-masks. */
|
||||||
{
|
{
|
||||||
return(1 << bit);
|
return (1 << bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TSTBIT(long mask, int bit)
|
bool TSTBIT(long mask, int bit)
|
||||||
|
@ -490,8 +474,7 @@ long RNDVOC(long second, long force)
|
||||||
|
|
||||||
long div = 64L * 64L * 64L;
|
long div = 64L * 64L * 64L;
|
||||||
for (int i = 1; i <= TABSIZ; i++) {
|
for (int i = 1; i <= TABSIZ; i++) {
|
||||||
if (MOD(ATAB[i]/div, 64L) == second)
|
if (MOD(ATAB[i] / div, 64L) == second) {
|
||||||
{
|
|
||||||
ATAB[i] = rnd;
|
ATAB[i] = rnd;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -562,13 +545,13 @@ bool MAPLIN(FILE *fp)
|
||||||
if (!editline) {
|
if (!editline) {
|
||||||
if (prompt)
|
if (prompt)
|
||||||
fputs("> ", stdout);
|
fputs("> ", stdout);
|
||||||
IGNORE(fgets(rawbuf,sizeof(rawbuf)-1,fp));
|
IGNORE(fgets(rawbuf, sizeof(rawbuf) - 1, fp));
|
||||||
eof = (feof(fp));
|
eof = (feof(fp));
|
||||||
} else {
|
} else {
|
||||||
char *cp = linenoise("> ");
|
char *cp = linenoise("> ");
|
||||||
eof = (cp == NULL);
|
eof = (cp == NULL);
|
||||||
if (!eof) {
|
if (!eof) {
|
||||||
strncpy(rawbuf, cp, sizeof(rawbuf)-1);
|
strncpy(rawbuf, cp, sizeof(rawbuf) - 1);
|
||||||
linenoiseHistoryAdd(rawbuf);
|
linenoiseHistoryAdd(rawbuf);
|
||||||
strncat(rawbuf, "\n", sizeof(rawbuf) - strlen(rawbuf) - 1);
|
strncat(rawbuf, "\n", sizeof(rawbuf) - strlen(rawbuf) - 1);
|
||||||
linenoiseFree(cp);
|
linenoiseFree(cp);
|
||||||
|
@ -586,13 +569,12 @@ bool MAPLIN(FILE *fp)
|
||||||
efp = logfp;
|
efp = logfp;
|
||||||
else if (!isatty(0))
|
else if (!isatty(0))
|
||||||
efp = stdout;
|
efp = stdout;
|
||||||
if (efp != NULL)
|
if (efp != NULL) {
|
||||||
{
|
|
||||||
if (prompt && efp == stdout)
|
if (prompt && efp == stdout)
|
||||||
fputs("> ", efp);
|
fputs("> ", efp);
|
||||||
IGNORE(fputs(rawbuf, efp));
|
IGNORE(fputs(rawbuf, efp));
|
||||||
}
|
}
|
||||||
strcpy(INLINE+1, rawbuf);
|
strcpy(INLINE + 1, rawbuf);
|
||||||
/* translate the chars to integers in the range 0-126 and store
|
/* translate the chars to integers in the range 0-126 and store
|
||||||
* them in the common array "INLINE". Integer values are as follows:
|
* them in the common array "INLINE". Integer values are as follows:
|
||||||
* 0 = space [ASCII CODE 40 octal, 32 decimal]
|
* 0 = space [ASCII CODE 40 octal, 32 decimal]
|
||||||
|
@ -616,14 +598,14 @@ bool MAPLIN(FILE *fp)
|
||||||
* the mapping. MAP2(1) is set to 0 when the program starts
|
* the mapping. MAP2(1) is set to 0 when the program starts
|
||||||
* and is not changed thereafter unless the routines on this page choose
|
* and is not changed thereafter unless the routines on this page choose
|
||||||
* to do so. */
|
* to do so. */
|
||||||
LNLENG=0;
|
LNLENG = 0;
|
||||||
for (long i=1; i<=(long)sizeof(INLINE) && INLINE[i]!=0; i++) {
|
for (long i = 1; i <= (long)sizeof(INLINE) && INLINE[i] != 0; i++) {
|
||||||
long val=INLINE[i];
|
long val = INLINE[i];
|
||||||
INLINE[i]=ascii_to_advent[val];
|
INLINE[i] = ascii_to_advent[val];
|
||||||
if (INLINE[i] != 0)
|
if (INLINE[i] != 0)
|
||||||
LNLENG=i;
|
LNLENG = i;
|
||||||
}
|
}
|
||||||
LNPOSN=1;
|
LNPOSN = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -640,11 +622,11 @@ void TYPE(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=1; i<=LNLENG; i++) {
|
for (i = 1; i <= LNLENG; i++) {
|
||||||
INLINE[i]=advent_to_ascii[(int) INLINE[i]];
|
INLINE[i] = advent_to_ascii[(int) INLINE[i]];
|
||||||
}
|
}
|
||||||
INLINE[LNLENG+1]=0;
|
INLINE[LNLENG + 1] = 0;
|
||||||
printf("%s\n", INLINE+1);
|
printf("%s\n", INLINE + 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
saveresume.c
25
saveresume.c
|
@ -31,7 +31,8 @@ struct save_t save;
|
||||||
|
|
||||||
/* Suspend and resume */
|
/* Suspend and resume */
|
||||||
int suspend(FILE *input)
|
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
|
* some points (so can't win by using saved games to retry
|
||||||
* battles or to start over after learning zzword).
|
* battles or to start over after learning zzword).
|
||||||
* If ADVENT_NOSAVE is defined, do nothing instead. */
|
* If ADVENT_NOSAVE is defined, do nothing instead. */
|
||||||
|
@ -43,8 +44,8 @@ int suspend(FILE *input)
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
|
||||||
RSPEAK(SUSPEND_WARNING);
|
RSPEAK(SUSPEND_WARNING);
|
||||||
if (!YES(input,THIS_ACCEPTABLE,OK_MAN,OK_MAN)) return GO_CLEAROBJ;
|
if (!YES(input, THIS_ACCEPTABLE, OK_MAN, OK_MAN)) return GO_CLEAROBJ;
|
||||||
game.saved=game.saved+5;
|
game.saved = game.saved + 5;
|
||||||
|
|
||||||
while (fp == NULL) {
|
while (fp == NULL) {
|
||||||
char* name = linenoise("\nFile name: ");
|
char* name = linenoise("\nFile name: ");
|
||||||
|
@ -56,8 +57,8 @@ int suspend(FILE *input)
|
||||||
linenoiseFree(name);
|
linenoiseFree(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
DATIME(&i,&k);
|
DATIME(&i, &k);
|
||||||
k=i+650*k;
|
k = i + 650 * k;
|
||||||
save.savetime = k;
|
save.savetime = k;
|
||||||
save.mode = -1;
|
save.mode = -1;
|
||||||
save.version = VRSION;
|
save.version = VRSION;
|
||||||
|
@ -71,7 +72,8 @@ int suspend(FILE *input)
|
||||||
}
|
}
|
||||||
|
|
||||||
int resume(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. */
|
* If ADVENT_NOSAVE is defined, do nothing instead. */
|
||||||
|
|
||||||
#ifdef ADVENT_NOSAVE
|
#ifdef ADVENT_NOSAVE
|
||||||
|
@ -81,7 +83,7 @@ int resume(FILE *input)
|
||||||
|
|
||||||
if (game.loc != 1 || game.abbrev[1] != 1) {
|
if (game.loc != 1 || game.abbrev[1] != 1) {
|
||||||
RSPEAK(RESUME_ABANDON);
|
RSPEAK(RESUME_ABANDON);
|
||||||
if (!YES(input,THIS_ACCEPTABLE,OK_MAN,OK_MAN)) return GO_CLEAROBJ;
|
if (!YES(input, THIS_ACCEPTABLE, OK_MAN, OK_MAN)) return GO_CLEAROBJ;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fp == NULL) {
|
while (fp == NULL) {
|
||||||
|
@ -98,7 +100,8 @@ int resume(FILE *input)
|
||||||
}
|
}
|
||||||
|
|
||||||
int restore(FILE* fp)
|
int restore(FILE* fp)
|
||||||
{ /* Read and restore game state from file, assuming
|
{
|
||||||
|
/* Read and restore game state from file, assuming
|
||||||
* sane initial state.
|
* sane initial state.
|
||||||
* If ADVENT_NOSAVE is defined, do nothing instead. */
|
* If ADVENT_NOSAVE is defined, do nothing instead. */
|
||||||
#ifdef ADVENT_NOSAVE
|
#ifdef ADVENT_NOSAVE
|
||||||
|
@ -108,14 +111,14 @@ int restore(FILE* fp)
|
||||||
IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
|
IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (save.version != VRSION) {
|
if (save.version != VRSION) {
|
||||||
SETPRM(1,save.version/10,MOD(save.version,10));
|
SETPRM(1, save.version / 10, MOD(save.version, 10));
|
||||||
SETPRM(3,VRSION/10,MOD(VRSION,10));
|
SETPRM(3, VRSION / 10, MOD(VRSION, 10));
|
||||||
RSPEAK(VERSION_SKEW);
|
RSPEAK(VERSION_SKEW);
|
||||||
} else {
|
} else {
|
||||||
memcpy(&game, &save.game, sizeof(struct game_t));
|
memcpy(&game, &save.game, sizeof(struct game_t));
|
||||||
OBJSND[BIRD] = save.bird;
|
OBJSND[BIRD] = save.bird;
|
||||||
OBJTXT[OYSTER] = save.bivalve;
|
OBJTXT[OYSTER] = save.bivalve;
|
||||||
game.zzword=RNDVOC(3,game.zzword);
|
game.zzword = RNDVOC(3, game.zzword);
|
||||||
}
|
}
|
||||||
return GO_TOP;
|
return GO_TOP;
|
||||||
}
|
}
|
||||||
|
|
72
score.c
72
score.c
|
@ -34,15 +34,15 @@ void score(enum termination mode)
|
||||||
|
|
||||||
/* First tally up the treasures. Must be in building and not broken.
|
/* First tally up the treasures. Must be in building and not broken.
|
||||||
* Give the poor guy 2 points just for finding each treasure. */
|
* Give the poor guy 2 points just for finding each treasure. */
|
||||||
for (long i=MINTRS; i<=MAXTRS; i++) {
|
for (long i = MINTRS; i <= MAXTRS; i++) {
|
||||||
if(object_descriptions[i].inventory != 0) {
|
if (object_descriptions[i].inventory != 0) {
|
||||||
long k=12;
|
long k = 12;
|
||||||
if(i == CHEST)k=14;
|
if (i == CHEST)k = 14;
|
||||||
if(i > CHEST)k=16;
|
if (i > CHEST)k = 16;
|
||||||
if(game.prop[i] >= 0)
|
if (game.prop[i] >= 0)
|
||||||
score += 2;
|
score += 2;
|
||||||
if(game.place[i] == LOC_BUILDING && game.prop[i] == 0)
|
if (game.place[i] == LOC_BUILDING && game.prop[i] == 0)
|
||||||
score += k-2;
|
score += k - 2;
|
||||||
mxscor += k;
|
mxscor += k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,29 +53,29 @@ void score(enum termination mode)
|
||||||
* indicates whether he reached the endgame. And if he got as far as
|
* indicates whether he reached the endgame. And if he got as far as
|
||||||
* "cave closed" (indicated by "game.closed"), then bonus is zero for
|
* "cave closed" (indicated by "game.closed"), then bonus is zero for
|
||||||
* mundane exits or 133, 134, 135 if he blew it (so to speak). */
|
* mundane exits or 133, 134, 135 if he blew it (so to speak). */
|
||||||
score += (MAXDIE-game.numdie)*10;
|
score += (MAXDIE - game.numdie) * 10;
|
||||||
mxscor += MAXDIE*10;
|
mxscor += MAXDIE * 10;
|
||||||
if(mode == endgame)
|
if (mode == endgame)
|
||||||
score += 4;
|
score += 4;
|
||||||
mxscor += 4;
|
mxscor += 4;
|
||||||
if(game.dflag != 0)score += 25;
|
if (game.dflag != 0)score += 25;
|
||||||
mxscor += 25;
|
mxscor += 25;
|
||||||
if(game.closng)score += 25;
|
if (game.closng)score += 25;
|
||||||
mxscor += 25;
|
mxscor += 25;
|
||||||
if(game.closed) {
|
if (game.closed) {
|
||||||
if(game.bonus == 0)
|
if (game.bonus == 0)
|
||||||
score += 10;
|
score += 10;
|
||||||
if(game.bonus == SPLATTER_MESSAGE)
|
if (game.bonus == SPLATTER_MESSAGE)
|
||||||
score += 25;
|
score += 25;
|
||||||
if(game.bonus == DEFEAT_MESSAGE)
|
if (game.bonus == DEFEAT_MESSAGE)
|
||||||
score += 30;
|
score += 30;
|
||||||
if(game.bonus == VICTORY_MESSAGE)
|
if (game.bonus == VICTORY_MESSAGE)
|
||||||
score += 45;
|
score += 45;
|
||||||
}
|
}
|
||||||
mxscor += 45;
|
mxscor += 45;
|
||||||
|
|
||||||
/* Did he come to Witt's End as he should? */
|
/* Did he come to Witt's End as he should? */
|
||||||
if(game.place[MAGZIN] == LOC_WITTSEND)
|
if (game.place[MAGZIN] == LOC_WITTSEND)
|
||||||
score += 1;
|
score += 1;
|
||||||
mxscor += 1;
|
mxscor += 1;
|
||||||
|
|
||||||
|
@ -84,37 +84,37 @@ void score(enum termination mode)
|
||||||
mxscor += 2;
|
mxscor += 2;
|
||||||
|
|
||||||
/* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
|
/* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
|
||||||
for (long i=1; i<=HNTMAX; i++) {
|
for (long i = 1; i <= HNTMAX; i++) {
|
||||||
if(game.hinted[i])
|
if (game.hinted[i])
|
||||||
score=score-HINTS[i][2];
|
score = score - HINTS[i][2];
|
||||||
}
|
}
|
||||||
if(game.novice)
|
if (game.novice)
|
||||||
score -= 5;
|
score -= 5;
|
||||||
if(game.clshnt)
|
if (game.clshnt)
|
||||||
score -= 10;
|
score -= 10;
|
||||||
score=score-game.trnluz-game.saved;
|
score = score - game.trnluz - game.saved;
|
||||||
|
|
||||||
/* Return to score command if that's where we came from. */
|
/* Return to score command if that's where we came from. */
|
||||||
if(mode == scoregame) {
|
if (mode == scoregame) {
|
||||||
SETPRM(1,score,mxscor);
|
SETPRM(1, score, mxscor);
|
||||||
SETPRM(3,game.turns,game.turns);
|
SETPRM(3, game.turns, game.turns);
|
||||||
RSPEAK(GARNERED_POINTS);
|
RSPEAK(GARNERED_POINTS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* that should be good enough. Let's tell him all about it. */
|
/* that should be good enough. Let's tell him all about it. */
|
||||||
if(score+game.trnluz+1 >= mxscor && game.trnluz != 0)
|
if (score + game.trnluz + 1 >= mxscor && game.trnluz != 0)
|
||||||
RSPEAK(TOOK_LONG);
|
RSPEAK(TOOK_LONG);
|
||||||
if(score+game.saved+1 >= mxscor && game.saved != 0)
|
if (score + game.saved + 1 >= mxscor && game.saved != 0)
|
||||||
RSPEAK(WITHOUT_SUSPENDS);
|
RSPEAK(WITHOUT_SUSPENDS);
|
||||||
SETPRM(1,score,mxscor);
|
SETPRM(1, score, mxscor);
|
||||||
SETPRM(3,game.turns,game.turns);
|
SETPRM(3, game.turns, game.turns);
|
||||||
RSPEAK(TOTAL_SCORE);
|
RSPEAK(TOTAL_SCORE);
|
||||||
for (long i=1; i<=(long)CLSSES; i++) {
|
for (long i = 1; i <= (long)CLSSES; i++) {
|
||||||
if(CVAL[i] >= score) {
|
if (CVAL[i] >= score) {
|
||||||
newspeak(class_messages[i]);
|
newspeak(class_messages[i]);
|
||||||
i=CVAL[i]+1-score;
|
i = CVAL[i] + 1 - score;
|
||||||
SETPRM(1,i,i);
|
SETPRM(1, i, i);
|
||||||
RSPEAK(NEXT_HIGHER);
|
RSPEAK(NEXT_HIGHER);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue