* defining (mostly) invariant state. A couple of slots are messed with
* at runtime.
*/
-#include "sizes.h"
+#include "common.h"
#define LINESIZE 100
#define RTXSIZ 277
/* hard limit, will be propagated to database.h */
#define NOBJECTS 100
-const char advent_to_ascii[] = {0, 32, 33, 34, 39, 40, 41, 42, 43, 44, 45, 46, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 37, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 35, 36, 38, 47, 58, 59, 60, 61, 62, 63, 64, 91, 92, 93, 94, 95, 96, 123, 124, 125, 126, 0};
-/* Rendered from the now-gone MPINIT() function */
-const char ascii_to_advent[] = {0, 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};
-
// 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 long NEWLOC;
static long OLDLOC;
+static long MAXDIE;
// Storage for what comes out of the database
long LINUSE;
LNLENG = 0;
for (size_t i = 1; i <= sizeof(INLINE) && INLINE[i] != 0; ++i)
{
- char val = INLINE[i] + 1;
+ char val = INLINE[i];
INLINE[i] = ascii_to_advent[(unsigned)val];
if (INLINE[i] != 0)
LNLENG = i;
while(true)
{
- long SECT=GETNUM(database);
+ long sect=GETNUM(database);
OLDLOC= -1;
- switch (SECT)
+ switch (sect)
{
case 0: return(0);
- case 1: read_messages(database, SECT); break;
- case 2: read_messages(database, SECT); break;
+ 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 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 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;
+ case 14: read_messages(database, sect); break;
default: BUG(9);
}
}
/* Sections 1, 2, 5, 6, 10, 14. Read messages and set up pointers. */
-void read_messages(FILE* database, long SECT)
+void read_messages(FILE* database, long sect)
{
long KK=LINUSE;
while(true)
{
- long LOC;
+ long loc;
LINUSE=KK;
- LOC=GETNUM(database);
+ loc=GETNUM(database);
if(LNLENG >= LNPOSN+70)BUG(0);
- if(LOC == -1) return;
+ if(loc == -1) return;
if(LNLENG < LNPOSN)BUG(1);
do {
KK=KK+1;
}
while(LINES[KK] != -1);
LINES[LINUSE]=KK;
- if(LOC == OLDLOC) continue;
- OLDLOC=LOC;
+ if(loc == OLDLOC) continue;
+ OLDLOC=loc;
LINES[LINUSE]= -KK;
- if(SECT == 14)
+ if(sect == 14)
{
TRNVLS=TRNVLS+1;
if(TRNVLS > TRNSIZ)BUG(11);
TTEXT[TRNVLS]=LINUSE;
- TRNVAL[TRNVLS]=LOC;
+ TRNVAL[TRNVLS]=loc;
continue;
}
- if(SECT == 10)
+ if(sect == 10)
{
CLSSES=CLSSES+1;
if(CLSSES > CLSMAX)BUG(11);
CTEXT[CLSSES]=LINUSE;
- CVAL[CLSSES]=LOC;
+ CVAL[CLSSES]=loc;
continue;
}
- if(SECT == 6)
+ if(sect == 6)
{
- if(LOC > RTXSIZ)BUG(6);
- RTEXT[LOC]=LINUSE;
+ if(loc > RTXSIZ)BUG(6);
+ RTEXT[loc]=LINUSE;
continue;
}
- if(SECT == 5)
+ if(sect == 5)
{
- if(LOC > 0 && LOC <= NOBJECTS)PTEXT[LOC]=LINUSE;
+ if(loc > 0 && loc <= NOBJECTS)PTEXT[loc]=LINUSE;
continue;
}
- if(LOC > LOCSIZ)BUG(10);
- if(SECT == 1)
+ if(loc > LOCSIZ)BUG(10);
+ if(sect == 1)
{
- LTEXT[LOC]=LINUSE;
+ LTEXT[loc]=LINUSE;
continue;
}
- STEXT[LOC]=LINUSE;
+ STEXT[loc]=LINUSE;
}
}
/* The stuff for section 3 is encoded here. Each "from-location" gets a
* contiguous section of the "TRAVEL" array. Each entry in travel is
- * NEWLOC*1000 + KEYWORD (from section 4, motion verbs), and is negated if
+ * newloc*1000 + KEYWORD (from section 4, motion verbs), and is negated if
* this is the last entry for this location. KEY(N) is the index in travel
* of the first option at location N. */
void read_section3_stuff(FILE* database)
{
- long LOC;
- while((LOC=GETNUM(database)) != -1)
+ long loc;
+ while((loc=GETNUM(database)) != -1)
{
- long NEWLOC=GETNUM(NULL);
+ long newloc=GETNUM(NULL);
long L;
- if(KEY[LOC] == 0)
+ if(KEY[loc] == 0)
{
- KEY[LOC]=TRVS;
+ KEY[loc]=TRVS;
}
else
{
}
while((L=GETNUM(NULL)) != 0)
{
- TRAVEL[TRVS]=NEWLOC*1000+L;
+ TRAVEL[TRVS]=newloc*1000+L;
TRVS=TRVS+1;
if(TRVS == TRVSIZ)BUG(3);
}
/* Read default message numbers for action verbs, store in ACTSPK. */
void read_action_verb_message_nr(FILE* database)
{
- long VERB;
- while((VERB=GETNUM(database)) != -1)
+ long verb;
+ while((verb=GETNUM(database)) != -1)
{
- ACTSPK[VERB]=GETNUM(NULL);
+ ACTSPK[verb]=GETNUM(NULL);
}
}
long K;
while((K=GETNUM(database)) != -1)
{
- long LOC;
- while((LOC=GETNUM(NULL)) != 0)
+ long loc;
+ while((loc=GETNUM(NULL)) != 0)
{
- if(is_set(COND[LOC],K)) BUG(8);
- COND[LOC]=COND[LOC] + (1l << K);
+ if(is_set(COND[loc],K)) BUG(8);
+ COND[loc]=COND[loc] + (1l << K);
}
}
}
void write_files(FILE* c_file, FILE* header_file)
{
+ int i, MAXDIE;
+ for (i=0; i<=4; i++) {
+ long x = 2*i+81;
+ if(RTEXT[x] != 0)
+ MAXDIE=i+1;
+ }
+
// preprocessor defines for the header
- fprintf(header_file, "#include \"sizes.h\"\n");
- fprintf(header_file, "#define RTXSIZ 277\n");
- fprintf(header_file, "#define CLSMAX 12\n");
- fprintf(header_file, "#define LINSIZ %d\n", LINSIZ);
- fprintf(header_file, "#define TRNSIZ 5\n");
+ fprintf(header_file, "#include \"common.h\"\n");
fprintf(header_file, "#define TABSIZ 330\n");
- fprintf(header_file, "#define VRBSIZ 35\n");
fprintf(header_file, "#define HNTSIZ 20\n");
- fprintf(header_file, "#define TRVSIZ 885\n");
fprintf(header_file, "#define TOKLEN %d\n", TOKLEN);
- fprintf(header_file, "#define HINTLEN %d\n", HINTLEN);
+ fprintf(header_file, "#define MAXDIE %d\n", MAXDIE);
fprintf(header_file, "\n");
// include the header in the C file
fprintf(c_file, "\n");
// content variables
- write_0d(c_file, header_file, LINUSE, "LINUSE");
- write_0d(c_file, header_file, TRVS, "TRVS");
- write_0d(c_file, header_file, CLSSES, "CLSSES");
write_0d(c_file, header_file, TRNVLS, "TRNVLS");
- write_0d(c_file, header_file, TABNDX, "TABNDX");
write_0d(c_file, header_file, HNTMAX, "HNTMAX");
- write_1d(c_file, header_file, PTEXT, NOBJECTS + 1, "PTEXT");
- write_1d(c_file, header_file, RTEXT, RTXSIZ + 1, "RTEXT");
- write_1d(c_file, header_file, CTEXT, CLSMAX + 1, "CTEXT");
write_1d(c_file, header_file, OBJSND, NOBJECTS + 1, "OBJSND");
write_1d(c_file, header_file, OBJTXT, NOBJECTS + 1, "OBJTXT");
- write_1d(c_file, header_file, STEXT, LOCSIZ + 1, "STEXT");
- write_1d(c_file, header_file, LTEXT, LOCSIZ + 1, "LTEXT");
write_1d(c_file, header_file, COND, LOCSIZ + 1, "COND");
write_1d(c_file, header_file, KEY, LOCSIZ + 1, "KEY");
write_1d(c_file, header_file, LOCSND, LOCSIZ + 1, "LOCSND");
- write_1d(c_file, header_file, LINES, LINSIZ + 1, "LINES");
write_1d(c_file, header_file, CVAL, CLSMAX + 1, "CVAL");
- write_1d(c_file, header_file, TTEXT, TRNSIZ + 1, "TTEXT");
write_1d(c_file, header_file, TRNVAL, TRNSIZ + 1, "TRNVAL");
write_1d(c_file, header_file, TRAVEL, TRVSIZ + 1, "TRAVEL");
write_1d(c_file, header_file, KTAB, TABSIZ + 1, "KTAB");