/* cscriptr.c */ #include "includes.h" #include "version.h" #define RESPONSES PATH "response.dat" void CScriptor::Load( EFFECT *fxPtr ) /* Loads into array words[] the text pointed to by EFFECT fxPtr. */ { // Abort if the effect is already loaded: if ( ! strcmp( fxPtr->name, wordEffect ) ) return; // Set fxStream file position to read the text: if ( fsetpos( fxStream, &fxPtr->filePtr ) ) gPrintErr( FATAL, "Bad access pointer into file " RESPONSES "." ); // Empty words[] array: words[0] = '\0'; // Read the text: if ( fxPtr->textLength > fread( words, 1, fxPtr->textLength, fxStream ) ) gPrintErr( FATAL, "Read error in file " RESPONSES "." ); // Decode the text: decode( words, coding ); // Terminate the text and save the effect name: words[fxPtr->textLength] = '\0'; strcpy( wordEffect, fxPtr->name ); } char CScriptor::FreeLines( int linesRequested ) /* Allocates memory for story lines. */ { int linesFreed = 0; STORY *newBlockPtr; // points to freshly allocated memory; STORY *thisLine, *oldLine; // line pointers; int i; // a utility variable; while ( linesFreed < linesRequested ) { if ( thisLine = newBlockPtr = (STORY *) malloc( BLOCKSIZE ) ) { for ( i=1; inext = thisLine; } thisLine->next = firstFreeLine; firstFreeLine = newBlockPtr; linesFreed += BLOCKLINES; } else { // Return failure: return 0; } } // end attempt-loop; // Return success: return 1; } STORY *CScriptor::NewLine( void ) /* Pulls a line off the free stack and returns a pointer to it. */ { STORY *newLine; if (! firstFreeLine ) gPrintErr( FATAL, "Out of storyline memory." ); // Pop the requested line off the free stack: newLine = firstFreeLine; firstFreeLine = firstFreeLine->next; newLine->next = NULL; *newLine->text = '\0'; return newLine; } void CScriptor::RebuildPage( void ) { int i; if ( screenTopLine && screenBotLine ) { screenBotLine->next = firstFreeLine; firstFreeLine = screenTopLine; } screenTopLine = screenBotLine = NewLine(); strcpy( screenTopLine->text, "\n" ); for (i=0; i<(pageLength-4); i++) { screenBotLine->next = NewLine(); screenBotLine = screenBotLine->next; strcpy( screenBotLine->text, "\n" ); } } CScriptor::CScriptor( void ) /* CScriptor's constructor function: initialises object variables, loads response data into memory, and initialises the storyline database with introductory text. Leaves fxStream open for use during game. Also seeds the random number generator. */ { EFFECT *fxPtr; char buffer[2048], randomise[6], serialNumber[PAGEWIDTH+2], origin[PAGEWIDTH+2]; int i; // General Initialisations: *words = '\0'; wordEffect[0] = '\0'; firstFreeLine = firstStackLine = lastStackLine = NULL; // Open the responses file: if ( ! (fxStream = fopen( RESPONSES, "rb" )) ) gPrintErr( FATAL, "Could not open file " RESPONSES "." ); // Read the coding status of the responses file: fscanf( fxStream, "%c\r", &coding ); // Read the response data into the fx array: for ( i=0, fxPtr = effect; iname, &fxPtr->next, &fxPtr->currentSpot, &fxPtr->duration, randomise, &fxPtr->textLength ); fxPtr->randomise = (*randomise == 't') ? 1 : 0; fxPtr->written = 0; // Record the location of the text of this response, and then skip over it: fgetpos( fxStream, &fxPtr->filePtr ); fseek( fxStream, fxPtr->textLength+1, SEEK_CUR ); } // end record loop; // Initialise serial number and origin strings then try to read them from the // file and decode them if necessary: strcpy( serialNumber, "No serial number stored." ); strcpy( origin, "No origin stored." ); if ( fscanf( fxStream, "%79[^\r]\r", serialNumber ) != EOF ) decode( serialNumber, coding ); if ( fscanf( fxStream, "%79[^\r]\r", origin ) != EOF ) decode( origin, coding ); // do not close fxStream - it will be needed during the game; // Allocate line memory: if ( !FreeLines( 500 ) ) gPrintErr( FATAL, "No storyline memory." ); screenTopLine = screenBotLine = NULL; RebuildPage(); // Add introductory text to the story database: Write( "intro" ); WriteString( "ET compiler version " VERSION ".\n" ); WriteString( serialNumber ); WriteString( "\n" ); WriteString( origin ); WriteString( "\n\n" ); // Seed the random number generator with the calendar time: srand( time( NULL ) % 65000 ); } CScriptor::~CScriptor( void ) { if (fxStream) fclose( fxStream ); } STORY *CScriptor::GetUnreadLines( int maxLines ) /* Adds printing lines, if available to the current screen. Frees up the lines pushed off the top. Adjusts screenTopLine and firstStackLine accordingly. Returns the last old line left on the screen. */ { int getCount = 0; STORY *scrolledLine, *lastOldLine; // Check for abort conditions: if ( maxLines < 1 ) return NULL; // Remember what was the last old line: lastOldLine = screenBotLine; // Temporarily link the screen and the stack: screenBotLine->next = firstStackLine; // Push new lines on the bottom while popping old ones off the top: while ( (getCount < maxLines) && (screenBotLine->next) ) { screenBotLine = screenBotLine->next; if ( screenBotLine->text[0] != '}' ) { getCount++; scrolledLine = screenTopLine; screenTopLine = screenTopLine->next; scrolledLine->next = firstFreeLine; firstFreeLine = scrolledLine; } } // Disconnect the screen and the stack: firstStackLine = screenBotLine->next; screenBotLine->next = NULL; if ( !firstStackLine ) lastStackLine = NULL; // Return a pointer to the last old line: return lastOldLine; } EFFECT *CScriptor::LookUp( const char *event ) /* Given the string , tries to find an event in the database matching that string specific for this act and scene, then specific for this act, and finally general to the entire game. Returns a pointer to the found event, or NULL if not found.) */ { char searchKey[20], a[3], as[4]; // act, act & scene; EFFECT *foundPtr; if ( !event ) return NULL; // Build act-specific suffix: a[0] = '_'; a[1] = gInterpreter->Act(); a[2] = '\0'; // Build scene-specific suffix: as[0] = '_'; as[1] = a[1]; as[2] = gInterpreter->Scene(); as[3] = '\0'; // Scene-specific search: strcpy( searchKey, event ); strcat( searchKey, as ); if ( ! (foundPtr = (EFFECT*) bsearch( searchKey, effect, FXTALLY, sizeof( EFFECT ), fxcmp )) ) { // Act-specific search: strcpy( searchKey, event ); strcat( searchKey, a ); if ( ! (foundPtr = (EFFECT*) bsearch( searchKey, effect, FXTALLY, sizeof( EFFECT ), fxcmp )) ) { // General search: strcpy( searchKey, event ); if ( ! (foundPtr = (EFFECT*) bsearch( searchKey, effect, FXTALLY, sizeof( EFFECT ), fxcmp )) ) { return NULL; } } } // Cycle through any available nexts until an unwritten description is found: while ( foundPtr->written && foundPtr->next ) foundPtr = effect + foundPtr->next - 1; return foundPtr; } STORY *CScriptor::PrintLines( STORY *oldLine, char *text ) /* Throws as much of text as possible onto the end of oldLine and then starts creating new lines to accommodate the rest of text, tacking them onto the end of oldLine. Returns pointer to the last line tacked on. */ { char *textPtr; int len; STORY *thisLine; thisLine = oldLine; strncat( oldLine->text, text, len = gInterfacer->TextBreak( text, thisLine->text ) ); textPtr = text + len; while ( *textPtr == ' ' ) textPtr++; if ( *textPtr == '\n' && !strchr( thisLine->text, '\n' ) ) { strcat( thisLine->text, "\n" ); textPtr++; } while ( *textPtr != '\0' ) { thisLine->next = NewLine(); thisLine = thisLine->next; strncat( thisLine->text, textPtr, len = gInterfacer->TextBreak( textPtr, NULL ) ); textPtr = textPtr + len; while ( *textPtr == ' ' ) textPtr++; if ( *textPtr == '\n' && !strchr( thisLine->text, '\n' ) ) { strcat( thisLine->text, "\n" ); textPtr++; } } // Return pointer to the last new line created: return thisLine; } char CScriptor::Write( char *event, ... ) /* Prints the effect named after lastStackLine. For every caret (^) found in the text to be written, another argument is grabbed from the variable area (...) and substituted for the caret. If event is "^", the first variable argument is a pointer to the event. */ { va_list argPtr; // points to the next variable argument; EFFECT *fxPtr; char *textPtr, *slashPtr, *caretPtr; int i; va_start( argPtr, event ); // Get a pointer to the response for this act & scene: if ( ! strcmp( event, "^" ) ) { fxPtr = va_arg( argPtr, EFFECT * ); if ( fxPtr < effect || fxPtr > ( effect + FXTALLY - 1 ) ) gPrintErr( FATAL, "Bad pointer passed to Write()." ); } else { if ( ! ( fxPtr = LookUp( event ) ) ) { return 0; } } // Start a stack if it's empty: if ( !lastStackLine ) { firstStackLine = lastStackLine = NewLine(); lastStackLine->next = NULL; lastStackLine->text[0] = '\0'; } // Load the text of the chosen response into array words[]: Load( fxPtr ); // Jump to character position in currentSpot, or pick a random character position: textPtr = words; if ( fxPtr->currentSpot ) { for ( i=1; textPtr && i < fxPtr->currentSpot; i++ ) if ( textPtr = strchr( textPtr, '\\' ) ) textPtr = textPtr + 1; if ( ! textPtr ) { textPtr = words; fxPtr->currentSpot = 1; } } else if ( fxPtr->randomise ) { textPtr = textPtr + (int) ( ( rand() / (double) RAND_MAX ) * strlen( words ) ); if ( textPtr = strchr( textPtr, '\\' ) ) textPtr = textPtr + 1; else textPtr = words; } // Terminate text at next backslash to avoid overrunning a section: if ( slashPtr = strchr( textPtr, '\\' ) ) *slashPtr = '\0'; // Print the text into lines, resolving user substitutions: while ( caretPtr = strchr( textPtr, '^' ) ) { *caretPtr = '\0'; lastStackLine = PrintLines( lastStackLine, textPtr ); lastStackLine = PrintLines( lastStackLine, va_arg( argPtr, char * ) ); textPtr = caretPtr + 1; *caretPtr = '^'; } va_end( argPtr ); lastStackLine = PrintLines( lastStackLine, textPtr ); // Restore the backslash, and advance currentSpot: if ( ! fxPtr->currentSpot ) fxPtr->currentSpot = 1; if ( slashPtr ) { *slashPtr = '\\'; fxPtr->currentSpot++; } if ( fxPtr->randomise ) fxPtr->currentSpot = 0; // Remember that this event has been written: fxPtr->written = 1; // Log the duration of this event: gInterfacer->SetTimeLoggedTo( gInterfacer->TimeLogged() + fxPtr->duration ); return 1; } char CScriptor::WriteOnce( char *event ) { EFFECT *fxPtr; // Get a pointer to the response for this act & scene whose name is this event: fxPtr = LookUp( event ); // If the found response has not been written, write it, else trigger the slugline: if ( fxPtr && ! fxPtr->written ) { gScriptor->Write( "^", fxPtr ); fxPtr->written = 1; return 1; } else { return 0; } } void CScriptor::FakeWrite( char *event ) { EFFECT *fxPtr; // Get a pointer to the response for this act & scene whose name is this event: fxPtr = LookUp( event ); // Set the found response to written but don't write it: if ( fxPtr ) fxPtr->written = 1; } void CScriptor::WriteString( char *text, ... ) /* Prints after lastStackLine. For every caret (^) found in the text to be written, another argument is grabbed from the variable area (...) and substituted for the caret. */ { va_list argPtr; // points to the next variable argument; char *textPtr, *caretPtr; int i; va_start( argPtr, text ); // Start a stack if it's empty: if ( !lastStackLine ) { firstStackLine = lastStackLine = NewLine(); lastStackLine->next = NULL; lastStackLine->text[0] = '\0'; } // Copy the text into junk[]: strcpy( junk, text ); textPtr = junk; // Print the text into lines, resolving user substitutions: while ( caretPtr = strchr( textPtr, '^' ) ) { *caretPtr = '\0'; lastStackLine = PrintLines( lastStackLine, textPtr ); lastStackLine = PrintLines( lastStackLine, va_arg( argPtr, char * ) ); textPtr = caretPtr + 1; *caretPtr = '^'; } va_end( argPtr ); lastStackLine = PrintLines( lastStackLine, textPtr ); } char CScriptor::WriteFromIndex( char *event, char *key ) /* Loads the effect named into memory and looks up "\key\" in it: writes the string that follows matchstring. If the string begins with @, look up the event it points to and write that. */ { EFFECT *fxPtr; char *textPtr, *slashPtr; // Get a pointer to the response for this act & scene: if ( ! ( fxPtr = LookUp( event ) ) ) return 0; // Load the text of the chosen response into array words[]: Load( fxPtr ); *wordEffect = '\0'; // This load will be 'dirty' so forget it was loaded; // Build key: strcpy( junk, "\\" ); strcat( junk, key ); strcat( junk, "\\" ); // Find key in words: if ( ! (textPtr = strstr( words, junk )) ) return 0; textPtr = textPtr + strlen( junk ); // Terminate text at next backslash to avoid overrunning a section: if ( slashPtr = strchr( textPtr, '\\' ) ) *slashPtr = '\0'; // Decide how to go about printing it by checking for the @: if (*textPtr == '@') { return Write( textPtr + 1 ); } else { WriteString( textPtr ); return 1; } } char *CScriptor::GetText( char *event ) /* Returns the slash-resolved text of the effect named . Warning -- the event is still counted as written and its duration is logged, even though this function does not write it. */ { EFFECT *fxPtr; char *textPtr, *slashPtr; int i; // Get a pointer to the response for this act & scene: if ( ! ( fxPtr = LookUp( event ) ) ) return NULL; // Load the text of the chosen response into array words[]: Load( fxPtr ); *wordEffect = '\0'; // This load will be 'dirty' so forget it was loaded; // Jump to character position in currentSpot, or pick a random character position: textPtr = words; if ( fxPtr->currentSpot ) { for ( i=1; textPtr && i < fxPtr->currentSpot; i++ ) if ( textPtr = strchr( textPtr, '\\' ) ) textPtr = textPtr + 1; if ( ! textPtr ) { textPtr = words; fxPtr->currentSpot = 1; } } else if ( fxPtr->randomise ) { textPtr = textPtr + (int) ( ( rand() / (double) RAND_MAX ) * strlen( words ) ); if ( textPtr = strchr( textPtr, '\\' ) ) textPtr = textPtr + 1; else textPtr = words; } // Terminate text at next backslash to avoid overrunning a section: if ( slashPtr = strchr( textPtr, '\\' ) ) *slashPtr = '\0'; // Remember that this event has been written: fxPtr->written = 1; // Log the duration of this event: gInterfacer->SetTimeLoggedTo( gInterfacer->TimeLogged() + fxPtr->duration ); // Return the text: return textPtr; } char *CScriptor::GetTextFromIndex( char *event, char *key ) /* Loads the effect named into memory and looks up "\key\" in it: returns the string that follows matchstring. If the string begins with @, look up the event it points to and return its text. */ { EFFECT *fxPtr; char *textPtr, *slashPtr; // Get a pointer to the response for this act & scene: if ( ! ( fxPtr = LookUp( event ) ) ) return NULL; // Load the text of the chosen response into array words[]: Load( fxPtr ); *wordEffect = '\0'; // This load is going to be dirtied to don't remember it; // Build key: strcpy( junk, "\\" ); strcat( junk, key ); strcat( junk, "\\" ); // Find key in words: if ( ! (textPtr = strstr( words, junk )) ) return NULL; textPtr = textPtr + strlen( junk ); // Terminate text at next backslash to avoid overrunning a section: if ( slashPtr = strchr( textPtr, '\\' ) ) *slashPtr = '\0'; // Decide how to go about printing it by checking for the @: if (*textPtr == '@') { return GetText( textPtr + 1 ); } else { return textPtr; } } char *CScriptor::GetTextFromIndexO( c_interpreter *object, char *index ) { char s[11]; strcat( strcpy( s, "e_" ), object->Id() ); return GetTextFromIndex( s, index ); } void CScriptor::EnsureBlank( void ) { char *lastLine; if ( lastStackLine ) lastLine = lastStackLine->text; else lastLine = screenBotLine->text; while ( *lastLine != '\n' ) { WriteString( "\n" ); lastLine = lastStackLine->text; } } void CScriptor::SetNextOf( const char *event, const char *next ) { EFFECT *fxPtr, *nextPtr; if ( ! ( fxPtr = LookUp( event ) ) || ! ( nextPtr = LookUp( next ) ) ) gPrintErr( FATAL, "Response name not found in database." ); fxPtr->next = nextPtr + 1 - effect; } char CScriptor::WrittenOf( const char *event ) { EFFECT *fxPtr; if ( ! ( fxPtr = LookUp( event ) ) ) gPrintErr( FATAL, "Response name not found in database." ); return fxPtr->written; } void CScriptor::SetWrittenOf( const char *event, char newWritten ) { EFFECT *fxPtr; if ( ! ( fxPtr = LookUp( event ) ) ) gPrintErr( FATAL, "Response name not found in database." ); fxPtr->written = newWritten; } int CScriptor::DurationOf( const char *event ) { EFFECT *fxPtr; if ( ! ( fxPtr = LookUp( event ) ) ) gPrintErr( FATAL, "Response name not found in database." ); return fxPtr->duration; } void CScriptor::SetDurationOf( const char *event, int duration ) { EFFECT *fxPtr; if ( ! ( fxPtr = LookUp( event ) ) ) gPrintErr( FATAL, "Response name not found in database." ); fxPtr->duration = duration; } /* ccmdr.c */ #include "includes.h" #define THESAURUS_SYNONYMS PATH "synonyms.dat" #define THESAURUS_WORDS PATH "words.dat" CCommander::CCommander( void ) { FILE *tsStream, *twStream; char coding; THESSYN *tsPtr; THESWORD *twPtr; char buffer[2048], temp[1024]; int i; // General Initialisations: commandReady = commandLive = rudeness = politeness = commandNeedsCorrection = suggestionWaiting = allInProgress = 0; lastNoun = lastCreature = 0; againCommand.text[0] = '\0'; nextCommand = 101; for (i=0, tsPtr = lSynonym; i<50; i++, tsPtr++) { tsPtr->word = (char *) calloc( 20, sizeof(char) ); tsPtr->word[0] = '\0'; tsPtr->tWord = 0; } tSynonym[0].word = (char*) calloc( 1, sizeof(char) ); // Open the thesaurus synonyms file: if ( ! (tsStream = fopen( THESAURUS_SYNONYMS, "rb" )) ) gPrintErr( FATAL, "Could not open file " THESAURUS_SYNONYMS "." ); // Read the coding status of the thesaurus synonyms file: fscanf( tsStream, "%c\r", &coding ); // Read the synonym data into tSynonym array: for ( i=0, tsPtr = tSynonym + 1; itWord ); tsPtr->word = (char *) calloc( strlen(temp), sizeof(char) ); strcpy( tsPtr->word, temp ); } // Close the thesaurus synonyms file: fclose( tsStream ); if ( coding == 'U' ) { qsort( tSynonym + 1, STALLY, sizeof( THESSYN ), wordsortcmp ); } // Open the thesaurus words file: if ( ! (twStream = fopen( THESAURUS_WORDS, "rb" )) ) gPrintErr( FATAL, "Could not open file " THESAURUS_WORDS "." ); // Read the coding status of the thesaurus words file: fscanf( twStream, "%c\r", &coding ); // Read the word data into tWord array: for ( i=0, twPtr = tWord + 1; iPoS, temp, twPtr->id, &twPtr->alternate ); twPtr->word = (char*) calloc( strlen(temp), sizeof(char) ); strcpy( twPtr->word, temp ); } // Close the thesaurus words file: fclose( twStream ); } CCommander::~CCommander( void ) { } int CCommander::CheckThesaurus( char *word ) /* Returns zero if no match */ { void *result; if ( result = bsearch( word, tSynonym+1, STALLY, sizeof( THESSYN ), wordcmp ) ) { return ( (THESSYN*) result )->tWord; } else { return 0; } } CLASSERROR CCommander::ConsultClassifier( void ) { struct { char *startptr; char *termptr; } word[80]; // pointers to words in command string; char *command, *cPtr, *dPtr, *ePtr, *err, firstPass[512]; char flag = 0; // Boolean; char ch; int h, i, j, k, lastWord; command = liveCommand.text; strcpy( roughWork, commandQ[1].text ); // Check for an all in progress: allInProgress = (*roughWork == '*'); // Remove irrelevant punctuation, cast into lower case, space out leftover punct: for (i=0, j=0; i:\?!", roughWork[i] ) ) { firstPass[j] = ' '; } else if ( strchr( "&;,.", roughWork[i] ) ) { if ( j>0 && firstPass[j-1] != ' ' ) firstPass[j++] = ' '; firstPass[j] = roughWork[i]; if ( roughWork[i+1] != ' ' ) firstPass[++j] = ' '; } else { firstPass[j] = tolower( roughWork[i] ); } } else { firstPass[j] = roughWork[i]; } } firstPass[j] = '\0'; // Split sentence into a list of words: i = 0; cPtr = firstPass; while ( *cPtr != '\0' ) { i++; if ( *( word[i].startptr = cPtr + strspn( cPtr, " " ) ) == '\0' ) break; if ( *(word[i].startptr) == '\"' ) { if ( ! (cPtr = word[i].termptr = strchr( word[i].startptr+1, '\"' )) ) break; } else { if ( ! (cPtr = word[i].termptr = strchr( word[i].startptr, ' ' )) ) break; } *(cPtr) = '\0'; cPtr++; if ( !(*word[i].startptr) ) i--; } if (i) word[i].termptr = word[i].startptr + strlen( word[i].startptr ); word[i+1].termptr = NULL; // Remove words as they copy back into command[]: rudeness = politeness = 0; *command = '\0'; for (i=1, j=flag=0; word[i].termptr; i++) { strcpy( roughWork, "[" ); strcat( roughWork, word[i].startptr ); strcat( roughWork, "]" ); if ( strstr( "[the] [a] [an] [your] [my] [their] [our]" "[its]", roughWork ) ) continue; if ( strstr( "[fucking] [fuck] [fuckin] [fucken] [fuckin'] [hell] [bloody] [damn] [damned] [cursed]", roughWork ) ) { rudeness = 1; politeness = 0; continue; } if ( strstr( "[please]", roughWork ) ) { if (! rudeness) politeness = 1; continue; } word[j].startptr = command + strlen( command ); strcat( command, word[i].startptr ); word[j].termptr = command + strlen( command ); strcat( command, " " ); j++; } word[j--].termptr = NULL; lastWord = j; // Run the command through the thesaurus: for (i=k=0; i<=lastWord; i++, k++) { inputWord[k].start = word[i].startptr; inputWord[k].tWord = 0; inputWord[k].code = '?'; for (j=lastWord; j>=i; j--) { *(word[j].termptr) = '\0'; if (!( inputWord[k].tWord = CheckThesaurus( word[i].startptr ) )) { *(word[j].termptr) = ' '; continue; } inputWord[k].code = tWord[inputWord[k].tWord].PoS; i = j; } if ( inputWord[k].code == '?' ) { *(word[i].termptr) = '\0'; if ( inputWord[k].start[0] == '\"' ) inputWord[k].code = 'n'; } } if (!k) return GENERIC_FLAW; inputWord[k].code = '\0'; // Run the rest through the learned words list: for (i=0; inputWord[i].code != '\0'; i++) { if ( inputWord[i].code == '?' ) { void *result; if ( result = bsearch( inputWord[i].start, lSynonym, 50, sizeof(THESSYN), wordcmp ) ) { inputWord[i].tWord = ( (THESSYN*) result )->tWord; inputWord[i].code = tWord[inputWord[i].tWord].PoS; continue; } } } // Kick out on finding adjacent conjunctions, commas, semicolons: flag = 0; for (i=0; i 19 ) dontlearn = 1; strcpy( roughWork, wrongSentence.part1 ); strcat( roughWork, " " ); strcat( roughWork, inputWord[0].start ); strcat( roughWork, " " ); strcat( roughWork, wrongSentence.part2 ); if ( strlen( roughWork ) > 160 ) return MOD_TOO_LONG; strcpy( commandQ[1].text, roughWork ); if ( ! dontlearn ) { strcpy( lsPtr->word, wrongSentence.wrong ); lsPtr->tWord = inputWord[0].tWord; if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_learn_word" )) ) err = "[OK, from now on \"^\" will be interpreted as \"^\".]\n\n"; gScriptor->WriteString( err, lsPtr->word, inputWord[0].start ); qsort( lSynonym, 50, sizeof( THESSYN ), wordsortcmp ); } commandNeedsCorrection = 0; return DO_AGAIN; } } else if ( wrongSentence.wrong[1] != '>' ) { // Specifying a noun: if ( k == 1 && inputWord[0].code == 'n' ) { strcpy( roughWork, wrongSentence.part1 ); strcat( roughWork, " " ); strcat( roughWork, inputWord[0].start ); strcat( roughWork, " " ); strcat( roughWork, wrongSentence.part2 ); if ( strlen( roughWork ) > 160 ) return MOD_TOO_LONG; strcpy( commandQ[1].text, roughWork ); commandNeedsCorrection = 0; return DO_AGAIN; } } else { // Specifying a prepositional phrase: if ( k==2 && MatchWord(internal,wrongSentence.wrong+2,tWord[inputWord[0].tWord].word) ) { strcpy( roughWork, wrongSentence.part1 ); strcat( roughWork, " " ); strcat( roughWork, inputWord[0].start ); strcat( roughWork, " " ); strcat( roughWork, inputWord[1].start ); strcat( roughWork, " " ); strcat( roughWork, wrongSentence.part2 ); if ( strlen( roughWork ) > 160 ) return MOD_TOO_LONG; strcpy( commandQ[1].text, roughWork ); commandNeedsCorrection = 0; return DO_AGAIN; } else if ( k==1 && !strchr(wrongSentence.wrong,'|') && inputWord[0].code == 'n' ) { strcpy( roughWork, wrongSentence.part1 ); strcat( roughWork, " " ); strcat( roughWork, wrongSentence.wrong + 2 ); strcat( roughWork, " " ); strcat( roughWork, inputWord[0].start ); strcat( roughWork, " " ); strcat( roughWork, wrongSentence.part2 ); if ( strlen( roughWork ) > 160 ) return MOD_TOO_LONG; strcpy( commandQ[1].text, roughWork ); commandNeedsCorrection = 0; return DO_AGAIN; } } Absorb( all ); } commandNeedsCorrection = suggestionWaiting = 0; // Check if 'again' has been requested: if ( !strcmp( "again", tWord[inputWord[0].tWord].word ) ) { if ( k != 1 ) return GENERIC_FLAW; strcpy( commandQ[1].text, againCommand.text ); return DO_AGAIN; } // Check sentence for unknowns: for (i=0; inputWord[i].code != '\0'; i++) { if ( inputWord[i].code == '?' ) { wrongSentence.part1 = cPtr = dPtr = commandQ[0].text; *cPtr = '\0'; for (j=0; jInterpreterID( tWord[j].id )->CanBeGot(in,gInterpreter->PrimeLoc())) { k++; h = j; } } if ( k>1 ) { wrongSentence.part1 = cPtr = dPtr = commandQ[0].text; *cPtr = '\0'; for (j=0; j" ); strcat( cPtr, inputWord[i].start ); wrongSentence.part2 = cPtr = cPtr + strlen( cPtr ) + 1; *cPtr = '\0'; for (j=i+1; inputWord[j].code != '\0'; j++) { strcat( cPtr, inputWord[j].start ); strcat( cPtr, " " ); } commandNeedsCorrection = 1; return CLARIFICATION_REQ; } else if ( k == 1 ) { inputWord[i].tWord = h; } } return CLASS_OK; } void CCommander::Place( PARSEDWORD *pPtr, INPUTWORD *iPtr ) { pPtr->start = iPtr->start; pPtr->tWord = iPtr->tWord; pPtr->i = gInterpreter->InterpreterID( tWord[pPtr->tWord].id ); } GRAMMARERROR CCommander::ConsultGrammarian( void ) { enum { none, n, nv, nvn, nvnp, nvnpn, nvnpnp, nvnpnpn } progress; INPUTWORD *iPtr, *jPtr, *kPtr; THESWORD *twPtr; int i; char *command, flag = 0; // Split first semicolon into a waiting sentence: for (iPtr=inputWord; iPtr->code != '\0'; iPtr++) { if ( iPtr->code != ';' ) { flag = 1; } else if ( flag && (iPtr+1)->code != '\0' ) { nextCommand--; if ( nextCommand < 2 ) return TOO_COMPLEX; command = commandQ[nextCommand].text; *command = '\0'; for (jPtr=iPtr+1; jPtr->code != '\0'; jPtr++) { strcat( command, jPtr->start ); strcat( command, " " ); } iPtr->code = '\0'; iPtr--; } } // Turn the appropriate commas into conjunctions (and kick bad beginnings): iPtr = inputWord; if ( strchr( "&*-,", iPtr->code ) ) return BAD_ORDER; for (iPtr++; iPtr->code != '\0'; iPtr++) if ( ( iPtr->code == ',' ) && ( (iPtr-1)->code == (iPtr+1)->code ) ) iPtr->code = '&'; // Check conjunction grammar: for (iPtr = inputWord + 1; iPtr->code != '\0'; iPtr++) if ( ( iPtr->code == '&' ) && ( (iPtr-1)->code != (iPtr+1)->code ) && strchr( "nvp", (iPtr-1)->code ) ) return BAD_ORDER; // Neutralise conjunctions after an 'ALL BUT': for (iPtr = inputWord + 1; iPtr->code != '\0'; iPtr++) if ( iPtr->code == '-' ) { if ( (iPtr+1)->code == '\0' || (iPtr+2)->code != '&' ) continue; for (jPtr = iPtr + 2; jPtr->code != '\0'; jPtr=jPtr+2) { if ( jPtr->code == '&' ) jPtr->code = 'x'; else break; } iPtr = jPtr - 1; } // Split conjunctions into waiting sentences: for (iPtr=inputWord + 1; iPtr->code != '\0'; iPtr++) { if ( iPtr->code == '&' ) { nextCommand--; if ( nextCommand < 2 ) return TOO_COMPLEX; command = commandQ[nextCommand].text; *command = '\0'; for (jPtr=inputWord; jPtrstart ); strcat( command, " " ); } for (jPtr=iPtr+1; jPtr->code != '\0'; jPtr++) { strcat( command, jPtr->start ); strcat( command, " " ); } for (kPtr = iPtr; kPtr->code != '\0'; kPtr=kPtr+2) { if ( kPtr->code != '&' ) break; } for (jPtr = iPtr; kPtr->code != '\0'; jPtr++, kPtr++) { jPtr->start = kPtr->start; jPtr->tWord = kPtr->tWord; jPtr->code = kPtr->code; } jPtr->code = '\0'; iPtr--; } } // In the case of a get, a drop, or a put, resolve 'ALL' into waiting sentences: for (iPtr = inputWord + 1; iPtr->code != '\0'; iPtr++) if ( iPtr->code == '*' || iPtr->code == '-' ) { c_interpreter *nextMember; if ( !strcmp( "get", tWord[(iPtr-1)->tWord].word ) ) { nextMember = gInterpreter->PrimeLoc()->In(); } else if ( !strcmp( "drop", tWord[(iPtr-1)->tWord].word ) || !strcmp( "put", tWord[(iPtr-1)->tWord].word ) ) { nextMember = gInterpreter->Prime()->In(); } else continue; if ( iPtr->code != '-' || (iPtr+1)->code != 'n' ) { kPtr = iPtr + 1; } else { for (kPtr = iPtr + 2; kPtr->code != '\0'; kPtr=kPtr+2) { if ( kPtr->code != 'x' ) break; } } for (;nextMember;nextMember = nextMember->Beside()) { if ( nextMember == gInterpreter->Prime() ) continue; if ( iPtr->code == '-' ) { for ( flag = 0, jPtr = iPtr + 1; jPtr < kPtr; jPtr = jPtr + 2 ) if ( !strcmp( nextMember->Id(), tWord[jPtr->tWord].id ) ) flag = 1; if ( flag ) continue; } for (i=0, twPtr = tWord + 1; ialternate && !strcmp( nextMember->Id(), twPtr->id ) ) break; if ( i == WTALLY ) continue; nextCommand--; if ( nextCommand < 2 ) return TOO_COMPLEX; command = commandQ[nextCommand].text; *command = '*'; *(command+1) = '\0'; for (jPtr=inputWord; jPtrstart ); strcat( command, " " ); } strcat( command, twPtr->word ); strcat( command, " " ); for (jPtr = kPtr; jPtr->code != '\0'; jPtr++) { strcat( command, jPtr->start ); strcat( command, " " ); } } if ( nextCommand > 100 || commandQ[nextCommand].text[0] != '*' ) { char *err; if ( !strcmp( "get", tWord[inputWord[0].tWord].word ) ) { if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_nothing_here" )) ) err = "\"I don't see what you want me to take,\" says ^.\n"; gScriptor->WriteString( err, gInterpreter->Prime()->Name(def) ); } else { if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_holding_nothing" )) ) err = "\"I'm not holding anything,\" says ^.\n"; gScriptor->WriteString( err, gInterpreter->Prime()->Name(def) ); } Absorb( all ); } return SKIP; } // end ALL resolution loop // Clear variables: parsed[temporary].start = NULL; parsed[temporary].tWord = 0; parsed[temporary].i = NULL; for (i=actor; iPrime(); for (i=0, twPtr = tWord + 1; ialternate && !strcmp( parsed[actor].i->Id(), twPtr->id ) ) break; if ( i < WTALLY ) { parsed[actor].start = twPtr->word; parsed[actor].tWord = twPtr - tWord; } // Check order grammar: progress = none; for (iPtr=inputWord; iPtr->code != '\0'; iPtr++) { switch ( iPtr->code ) { case ',': continue; case '*': case '-': return MISPLACED_ALL; case 'n': // Examine a noun; // Resolve pronouns: if ( lastNoun && ! strcmp( "it", tWord[iPtr->tWord].word ) ) { iPtr->tWord = lastNoun; iPtr->start = tWord[lastNoun].word; } else if ( lastCreature && ! strcmp( "her", tWord[iPtr->tWord].word ) ) { iPtr->tWord = lastCreature; iPtr->start = tWord[lastCreature].word; } else if ( !strcmp( "you", tWord[iPtr->tWord].word ) ) { iPtr->tWord = parsed[actor].tWord; iPtr->start = parsed[actor].start; } switch ( progress ) { case none: // "JOHN, ..." Place( &parsed[actor], iPtr ); progress = n; break; case nv: // "john, put BOX ..." Place( &parsed[obj], iPtr ); progress = nvn; break; case nvnp: // "john, put box in PIT ..." Place( &parsed[indo1], iPtr ); progress = nvnpn; break; case nvnpnp: // "john, put box in pit with FORKLIFT ..." Place( &parsed[indo2], iPtr ); progress = nvnpnpn; break; default: return BAD_ORDER; } break; case 'v': // Examine a verb; switch( progress ) { case none: case n: // "john, PUT ..." Place( &parsed[verb], iPtr ); progress = nv; break; default: return BAD_ORDER; } break; case 'p': // Examine a preposition; switch( progress ) { case none: case n: // "john, NW ..." (allow direction preps to be verbs too) if ( !strstr( cardinals, tWord[iPtr->tWord].word ) ) return BAD_ORDER; Place( &parsed[prep1], iPtr ); parsed[verb].start = "go"; progress = nvnpn; break; case nv: case nvn: // "john, put box IN ..." Place( &parsed[prep1], iPtr ); progress = nvnp; break; case nvnp: case nvnpn: // "john, put box in pit WITH ..." Place( &parsed[prep2], iPtr ); progress = nvnpnp; break; default: return BAD_ORDER; } break; } } switch( progress ) { // Check final progress; case nv: case nvn: case nvnp: case nvnpn: case nvnpnpn: break; default: return BAD_ORDER; } // Set pronouns: if ( parsed[obj].tWord ) { lastNoun = parsed[obj].tWord; } else if ( parsed[indo1].tWord ) { lastNoun = parsed[indo1].tWord; } else if ( parsed[indo2].tWord ) { lastNoun = parsed[indo2].tWord; } if ( parsed[obj].i && parsed[obj].i->ClassID() >= animate ) { lastCreature = parsed[obj].tWord; } else if ( parsed[indo1].i && parsed[indo1].i->ClassID() >= animate ) { lastCreature = parsed[indo1].tWord; } else if ( parsed[indo2].i && parsed[indo2].i->ClassID() >= animate ) { lastCreature = parsed[indo2].tWord; } return GRAMMAR_OK; } void CCommander::SwapPrepositions( void ) { MoveWord( prep1, temporary ); MoveWord( prep2, prep1 ); MoveWord( temporary, prep2 ); MoveWord( indo1, temporary ); MoveWord( indo2, indo1 ); MoveWord( temporary, indo2 ); } void CCommander::MoveWord( WORD source, WORD destination ) { parsed[destination] = parsed[source]; parsed[source].start = NULL; parsed[source].i = NULL; parsed[source].tWord = 0; } void CCommander::ClearWord( WORD word ) { parsed[word].start = NULL; parsed[word].i = NULL; parsed[word].tWord = 0; } char CCommander::ConsultPreInterpreter( void ) { if ( Match( "?/get/_/from/_/*" ) ) { parsed[prep1].start = NULL; parsed[indo1].start = NULL; } else if ( Match( "?/fill/_/with/_" ) ) { parsed[verb].start = "put"; parsed[prep1].start = "in"; parsed[verb].tWord = parsed[prep1].tWord = 0; MoveWord( obj, temporary ); MoveWord( indo1, obj ); MoveWord( temporary, indo1 ); } return 1; } char CCommander::MatchWord( WORD word, char *matchString, ... ) { va_list argPtr; char *cPtr, *sPtr, *mPtr, match = 0; if ( word == internal ) { va_start( argPtr, matchString ); mPtr = va_arg( argPtr, char * ); va_end( argPtr ); } else if ( ! commandLive ) return 0; if ( strlen( matchString ) > 500 ) return 0; strcpy( roughWork, matchString ); cPtr = roughWork; if ( word != internal ) { if ( parsed[word].tWord ) mPtr = tWord[parsed[word].tWord].word; else mPtr = parsed[word].start; } sPtr = cPtr; while ( sPtr && ! match ) { sPtr = strchr( cPtr, '|' ); if ( sPtr ) *sPtr = '\0'; switch (*cPtr) { case '?': match = 1; break; case '_': if ( mPtr ) match = 1; break; case '\0': if ( ! mPtr ) match = 1; break; default: if ( mPtr && ! strcmp ( cPtr, mPtr ) ) match = 1; break; } if ( sPtr ) { *sPtr = '|'; cPtr = sPtr + 1; } } return match; } char CCommander::SubMatch( char *cPtr, PARSEDWORD *parsedword ) { char *sPtr, *mPtr, match = 0; if ( parsedword->tWord ) mPtr = tWord[parsedword->tWord].word; else mPtr = parsedword->start; sPtr = cPtr; while ( sPtr && ! match ) { sPtr = strchr( cPtr, '|' ); if ( sPtr ) *sPtr = '\0'; switch (*cPtr) { case '?': match = 1; break; case '_': if ( mPtr ) match = 1; break; case '\0': if ( ! mPtr ) match = 1; break; default: if ( mPtr && ! strcmp ( cPtr, mPtr ) ) match = 1; break; } if ( sPtr ) { *sPtr = '|'; cPtr = sPtr + 1; } } return match; } char CCommander::Match( const char *matchString ) { char *cPtr, *sPtr; int i; if ( ! commandLive ) return 0; if ( strlen( matchString ) > 500 ) return 0; strcpy( roughWork, matchString ); cPtr = sPtr = roughWork; for (i=actor; iGetTextFromIndex( "e_errors", "et_generic" )) ) err = "[I can't make any sense of that input.]\n"; gScriptor->WriteString( err ); Absorb( all ); return 0; case TOO_MANY_OOPS: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_too_many_oops" )) ) err = "[Please specify a one word correction.]\n"; gScriptor->WriteString( err ); return 0; case MOD_TOO_LONG: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_modification_too_long" )) ) err = "[Your correction makes the sentence too long.]\n"; gScriptor->WriteString( err ); Absorb( all ); return 0; case CORRECTION_REQ: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_word_query" )) ) err = "[What do you mean by \"^\"?]\n"; gScriptor->WriteString( err, wrongSentence.wrong ); return 0; case CLARIFICATION_REQ: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_word_vague" )) ) err = "[Which ^ do you mean?]\n"; gScriptor->WriteString( err, wrongSentence.wrong + 1 ); return 0; case REPEAT_MISTAKE: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_can't_repeat" )) ) err = "[Your last command is no longer available.]\n"; gScriptor->WriteString( err ); Absorb( all ); return 0; default: break; } } // Consult the Grammarian: switch ( ConsultGrammarian() ) { case TOO_COMPLEX: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_grammar_too_complex" )) ) err = "[My analysis of your grammar became too complex to follow." " Try smaller sentences.]\n"; gScriptor->WriteString( err ); Absorb( all ); return 0; case MISPLACED_ALL: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_misplaced_all" )) ) err = "[I am limited to accepting \"all\" or \"everything\" only" " immediately after the commands \"get\", \"drop\"," " and \"put\".]\n"; gScriptor->WriteString( err ); Absorb( all ); return 0; case SKIP: Absorb( one ); return 0; case BAD_ORDER: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_bad_order" )) ) err = "[I don't recognise that word order.]\n"; gScriptor->WriteString( err ); Absorb( all ); return 0; default: break; } // Consult the PreInterpreter: if ( ! ConsultPreInterpreter() ) { Absorb( all ); return 0; } // Check the validity of the directee: if ( parsed[actor].i != gInterpreter->Prime() ) { if ( !parsed[actor].i || parsed[actor].i->ClassID() < animate ) { if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_not_an_actor" )) ) err = "[You can't direct ^.]\n"; gScriptor->WriteString( err, parsed[actor].i ? parsed[actor].i->Name(def) : "that" ); Absorb( all ); return 0; } else if ( ! parsed[actor].i->Sits( in, gInterpreter->PrimeLoc() ) ) { if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_actor_unavailable" )) ) err = "[^ is unavailable right now.]\n"; gScriptor->WriteString( err, cap(parsed[actor].i->Name(def)) ); Absorb( all ); return 0; } else if ( ! parsed[actor].i->BecomePrime() ) { char s[11]; strcat( strcpy( s, "e_" ), parsed[actor].i->Id() ); if ( !(err=gScriptor->GetTextFromIndex( s, "et_actor_not_prime" )) && !(err=gScriptor->GetTextFromIndex( "e_errors", "et_actor_not_prime" )) ) err = "^ ignores your directions.\n"; gScriptor->WriteString( err, cap(parsed[actor].i->Name(def)) ); Absorb( all ); return 0; } } // Check for profanity: if ( gCommander->Rudeness() ) { char s[11]; strcat( strcpy( s, "e_" ), gInterpreter->Prime()->Id() ); if ( !(err=gScriptor->GetTextFromIndex( s, "et_rudeness" )) ) err = "\"That wasn't called for,\" mutters ^.\n\n"; gScriptor->WriteString( err, gInterpreter->Prime()->Name(def) ); } else if ( gCommander->Politeness() ) { char s[11]; strcat( strcpy( s, "e_" ), gInterpreter->Prime()->Id() ); if ( !(err=gScriptor->GetTextFromIndex( s, "et_politeness" )) ) err = "^ smiles.\n\n"; gScriptor->WriteString( err, gInterpreter->Prime()->Name(def) ); } commandReady = commandLive = 1; *againCommand.text = '\0'; for (i=verb;i 100 ) { return 0; } else { if ( x ) { strcpy( commandQ[1].text, commandQ[nextCommand].text ); nextCommand++; } return 1; } } char CCommander::PushCommand( char *text, ... ) { va_list argPtr; // points to the next variable argument; char *command, *textPtr, *caretPtr; if ( nextCommand < 3 ) return 0; nextCommand--; command = commandQ[nextCommand].text; va_start( argPtr, text ); // Copy the text into junk[]: strcpy( gScriptor->junk, text ); textPtr = gScriptor->junk; command[0] = '\0'; // Copy the text into command, resolving user substitutions: while ( caretPtr = strchr( textPtr, '^' ) ) { *caretPtr = '\0'; strcat( command, textPtr ); strcat( command, va_arg( argPtr, char * ) ); textPtr = caretPtr + 1; *caretPtr = '^'; } va_end( argPtr ); strcat( command, textPtr ); return 1; } void CCommander::SuggestCommand( char *text, ... ) { va_list argPtr; // points to the next variable argument; char *textPtr, *caretPtr; va_start( argPtr, text ); // Copy the text into junk[]: strcpy( gScriptor->junk, text ); textPtr = gScriptor->junk; commandQ[0].text[0] = '\0'; // Copy the text into commandQ[0].text, resolving user substitutions: while ( caretPtr = strchr( textPtr, '^' ) ) { *caretPtr = '\0'; strcat( commandQ[0].text, textPtr ); strcat( commandQ[0].text, va_arg( argPtr, char * ) ); textPtr = caretPtr + 1; *caretPtr = '^'; } va_end( argPtr ); strcat( commandQ[0].text, textPtr ); commandNeedsCorrection = suggestionWaiting = 1; } void CCommander::KickCommand( WORD p, char *kicker, char *begin, char *end ) { char *cPtr, *err; int i; wrongSentence.part1 = cPtr = commandQ[0].text; *cPtr = '\0'; if ( parsed[actor].start ) { strcat( cPtr, parsed[actor].start ); strcat( cPtr, " " ); } strcat( cPtr, parsed[verb].start ); switch ( p ) { case obj: wrongSentence.wrong = cPtr = cPtr + strlen( cPtr ) + 1; *cPtr = '\0'; strcat( cPtr, ">noun" ); wrongSentence.part2 = cPtr = cPtr + strlen( cPtr ) + 1; *cPtr = '\0'; for (i=prep1;iGetTextFromIndex( "e_errors", "et_ask_for_obj" )) ) err = "\"^ do you want me to ^?\"\n"; gScriptor->WriteString( err, cap(begin), parsed[verb].start ); commandNeedsCorrection = 1; break; case prep1: case indo1: if ( parsed[obj].start ) { strcat( cPtr, " " ); strcat( cPtr, parsed[obj].start ); } wrongSentence.wrong = cPtr = cPtr + strlen( cPtr ) + 1; *cPtr = '\0'; strcat( cPtr, ">>" ); strncat( cPtr, kicker, 19 ); wrongSentence.part2 = cPtr = cPtr + strlen( cPtr ) + 1; *cPtr = '\0'; for (i=prep2;iGetTextFromIndex( "e_errors", "et_ask_for_indo" )) ) err = "\"^ do you want me to ^^^^^^?\"\n"; gScriptor->WriteString( err, cap(begin), parsed[verb].start, parsed[obj].start ? " " : "", parsed[obj].start ? (parsed[obj].i ? parsed[obj].i->Article(def) : "the " ) : "", parsed[obj].start ? (parsed[obj].i ? parsed[obj].i->Name(alone) : parsed[obj].start ) : "", parsed[obj].start && end && *end != '\0' ? " " : "", end ? end : ""); commandNeedsCorrection = 1; break; default: break; } Absorb( one ); } void CCommander::DoError( WORD noun, REQERROR reqerr ) { char *word, *err, flag = 0; c_interpreter *ip, *loc, *prime; word = parsed[noun].start; ip = parsed[noun].i; loc = gInterpreter->PrimeLoc(); prime = gInterpreter->Prime(); switch ( reqerr ) { case ET_UNNECESSARIES: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_unnecessaries" )) ) err = "[Unnecessary words seem to confuse that sentence.]\n"; gScriptor->WriteString( err ); return; case ET_SUGGEST_GET_OUT: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_suggest_get_out" )) ) err = "\"I'll have to get ^ out first,\" suggests ^.\n"; gScriptor->WriteString( err, ip->Name(def), prime->Name(def) ); return; case ET_ITEM_NOT_HERE: if ( ip && ip->Known() && !tWord[parsed[noun].tWord].alternate ) flag = 1; if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_item_not_here" )) ) err = "\"I don't see ^^ here,\" says ^.\n"; gScriptor->WriteString( err, flag ? ip->Article(indef) : "any ", flag ? ip->Name(alone) : word, prime->Name(def) ); return; case ET_SUGGEST_DROP: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_suggest_drop" )) ) err = "\"I'll have to put down ^ first,\" suggests ^.\n"; gScriptor->WriteString( err, ip->Name(def), prime->Name(def) ); return; case ET_SUGGEST_REMOVE: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_suggest_remove" )) ) err = "\"I'll have to remove ^ first,\" suggests ^.\n"; gScriptor->WriteString( err, ip->Name(def), prime->Name(def) ); return; case ET_SUGGEST_GET: if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_suggest_get" )) ) err = "\"I'll have to pick up ^ first,\" suggests ^.\n"; gScriptor->WriteString( err, ip->Name(def), prime->Name(def) ); return; default: return; } } char CCommander::RequireNoun( WORD noun, REQUIREMENT req, char *begin, char *end ) { char *word; c_interpreter *ip, *loc, *prime; word = parsed[noun].start; ip = parsed[noun].i; loc = gInterpreter->PrimeLoc(); prime = gInterpreter->Prime(); switch ( req ) { case full: return 1; case visible: if ( !ip || !(ip->CanBeSeen(in,loc) || ip->CanBeSeen(in,prime)) ) { if ( ip && (ip->CanBeGot(in,loc) || ip->CanBeGot(in,prime)) ) { DoError( noun, ET_SUGGEST_GET_OUT ); SuggestCommand( "get ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } DoError( noun, ET_ITEM_NOT_HERE ); Absorb( all ); return 0; } return 1; case visible_in_loc: if ( !ip || !ip->CanBeSeen(in,loc) ) { if ( ip ) if ( ip->CanBeSeen(in,prime) ) { DoError( noun, ET_SUGGEST_DROP ); SuggestCommand( "drop ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } else if ( ip->CanBeGot(in,loc) ) { DoError( noun, ET_SUGGEST_GET_OUT ); SuggestCommand( "get ^; drop ^; ^", word, word, commandQ[1].text ); Absorb( one ); return 0; } else if ( ip->CanBeGot(in,prime) ) { DoError( noun, ET_SUGGEST_DROP ); SuggestCommand( "get ^; drop ^; ^", word, word, commandQ[1].text ); Absorb( one ); return 0; } DoError( noun, ET_ITEM_NOT_HERE ); Absorb( all ); return 0; } return 1; case visible_in_prime: if ( !ip || !ip->CanBeSeen(in,prime) ) { if ( ip ) if ( ip->CanBeGot(in,prime) ) { DoError( noun, ET_SUGGEST_GET_OUT ); SuggestCommand( "get ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } else if ( ip->CanBeGot(in,loc) ) { DoError( noun, ET_SUGGEST_GET ); SuggestCommand( "get ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } DoError( noun, ET_ITEM_NOT_HERE ); Absorb( all ); return 0; } return 1; case can_drop_in_prime: if ( !ip || !ip->CanBeSeen(in,prime) ) { if ( ip ) if ( ip->CanBeGot(in,prime) ) { DoError( noun, ET_SUGGEST_GET_OUT ); SuggestCommand( "get ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } else if ( ip->CanBeGot(in,loc) ) { DoError( noun, ET_SUGGEST_GET ); SuggestCommand( "get ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } DoError( noun, ET_ITEM_NOT_HERE ); Absorb( all ); return 0; } else if ( ip->State(worn) ) { DoError( noun, ET_SUGGEST_REMOVE ); SuggestCommand( "remove ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } return 1; case can_get: if ( !ip || !(ip->CanBeGot(in,loc) || ip->CanBeGot(in,prime)) ) { DoError( noun, ET_ITEM_NOT_HERE ); Absorb( all ); return 0; } return 1; case can_get_in_loc: if ( !ip || !ip->CanBeGot(in,loc) ) { if ( ip ) if ( ip->CanBeSeen(in,prime) ) { DoError( noun, ET_SUGGEST_DROP ); SuggestCommand( "drop ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } else if ( ip->CanBeGot(in,prime) ) { DoError( noun, ET_SUGGEST_DROP ); SuggestCommand( "get ^; drop ^; ^", word, word, commandQ[1].text ); Absorb( one ); return 0; } DoError( noun, ET_ITEM_NOT_HERE ); Absorb( all ); return 0; } return 1; case can_get_in_prime: if ( !ip || !ip->CanBeGot(in,prime) ) { if ( ip ) if ( ip->CanBeGot(in,loc) ) { DoError( noun, ET_SUGGEST_GET ); SuggestCommand( "get ^; ^", word, commandQ[1].text ); Absorb( one ); return 0; } DoError( noun, ET_ITEM_NOT_HERE ); Absorb( all ); return 0; } return 1; } } char CCommander::RequireObj( REQUIREMENT req, char *begin ) { switch ( req ) { case anything: return 1; case empty: if ( parsed[obj].start ) { DoError( obj, ET_UNNECESSARIES ); Absorb( all ); return 0; } return 1; default: if ( !parsed[obj].start ) { KickCommand( obj, NULL, begin, NULL ); return 0; } return RequireNoun( obj, req, begin, NULL ); } } char CCommander::ClausesCantExceed( char max ) { char count = 0; if ( parsed[prep1].start ) count++; if ( parsed[prep2].start ) count++; if ( count > max ) { DoError( prep1, ET_UNNECESSARIES ); Absorb( all ); return 0; } else { if ( count == 1 && parsed[prep2].start ) SwapPrepositions(); return 1; } } char CCommander::RequireClause( char *plist, REQUIREMENT req, char *begin, char *end ) { char *c, tmp[80], m1=0, m2=0; if ( !MatchWord( prep1, plist ) ) if ( MatchWord( prep2, plist ) ) { SwapPrepositions(); } else { KickCommand( prep1, plist, begin, end ); return 0; } switch ( req ) { case anything: return 1; case empty: if ( parsed[indo1].start ) { DoError( indo1, ET_UNNECESSARIES ); Absorb( all ); return 0; } return 1; default: if ( !parsed[indo1].start ) { KickCommand( indo1, plist, begin, end ); return 0; } return RequireNoun( indo1, req, begin, end ); } } char *CCommander::Parsed( WORD word ) { if ( ! commandLive || ! parsed[word].start ) return NULL; if ( parsed[word].tWord ) return tWord[parsed[word].tWord].word; else return parsed[word].start; } char *CCommander::Untranslated( WORD word ) { if ( ! commandLive ) return NULL; else return parsed[word].start; } char *CCommander::Translated( WORD word ) { if ( ! commandLive || ! parsed[word].start || ! parsed[word].tWord ) return NULL; else return tWord[parsed[word].tWord].word; } char *CCommander::Thes( c_interpreter *ref ) { THESWORD *twPtr; int i; for (i=0, twPtr = tWord + 1; ialternate && !strcmp( ref->Id(), twPtr->id ) ) break; if ( i == WTALLY ) return NULL; else return twPtr->word; } c_interpreter *CCommander::Interpreter( WORD word ) { if ( ! commandLive || ! parsed[word].start ) return NULL; else return parsed[word].i; } char CCommander::CommandReady( void ) { return commandReady; } char CCommander::CommandLive( void ) { return commandLive; } char CCommander::AllInProgress( void ) { return allInProgress; } char CCommander::Rudeness( void ) { return rudeness; } char CCommander::Politeness( void ) { return politeness; } /* cgintrpr.c */ #include "includes.h" #define INTERPRETERS PATH "intrprtr.dat" CGlobalInterpreter::CGlobalInterpreter( void ) /* CGlobalInterpreter's constructor function. */ { // General Initialisations: primeInterpreter = firstWanderer = NULL; act = 'a'; scene = 'a'; // Initialise all object variables: #include "allintrp.c" } void CGlobalInterpreter::Initialise( void ) /* CGlobalInterpreter's initialise function: loads interpreter data into memory. It seems necessary to do this after the constructor, since the Mac apparently moves the interpreter array after the constructor function is invoked. */ { FILE *objStream; c_interpreter *objPtr; char buffer[2048], coding; int i; // Open the interpreter file: if ( ! (objStream = fopen( INTERPRETERS, "rb" )) ) gPrintErr( FATAL, "Could not open file " INTERPRETERS "." ); // Read the coding status of the interpreters file: fscanf( objStream, "%c\r", &coding ); // Read the prime interpreter off of line 2: fscanf( objStream, "%2047[^\r]\r", buffer ); decode( buffer, coding ); sscanf( buffer, "%d\\", &i ); primeInterpreter = interpreter[i]; // Read the interpreters data into the interpreters array: for ( objPtr = interpreter[i=0]; iScan( buffer ); } // end record loop; // Close the interpreter file: fclose( objStream ); } void CGlobalInterpreter::FullConsultation( void ) /* Run the prime interpreter's interpretation script, then consult for scripts from the current room, and then from the object self. Finally, run the general interpretation script. */ { primeInterpreter->Interpret(); primeInterpreter->Owner()->Consult(); self->Consult(); Interpret(); } void CGlobalInterpreter::SetPrimeLocTo( c_interpreter *newLoc ) { primeInterpreter->PutFollowedIn( newLoc ); } void CGlobalInterpreter::SetActTo( char newAct ) { act = newAct; } void CGlobalInterpreter::SetSceneTo( char newScene ) { scene = newScene; } void CGlobalInterpreter::SetPrimeTo( c_interpreter *newPrime ) { primeInterpreter = newPrime; } c_interpreter *CGlobalInterpreter::InterpreterID( char *id ) { int i; for (i=0; iId() ) ) return interpreter[i]; return NULL; } c_interpreter *CGlobalInterpreter::Interpreter( int number ) { return interpreter[number]; } c_animate *CGlobalInterpreter::FirstWanderer() { return firstWanderer; } void CGlobalInterpreter::SetFirstWandererTo( c_animate *x ) { firstWanderer = x; } char CGlobalInterpreter::Act( void ) { return act; } char CGlobalInterpreter::Scene( void) { return scene; } c_interpreter *CGlobalInterpreter::Prime( void) { return primeInterpreter; } c_interpreter *CGlobalInterpreter::PrimeLoc( void ) { return primeInterpreter->Owner(); } /* cintrpr.c */ #include "includes.h" c_interpreter::c_interpreter( void ) { int i; o_alwaysConsult = NULL; o_state = 0; o_in = o_on = o_under = o_beside = o_owner = NULL; for (i=0; i<10; i++) o_direction[i] = NULL; o_consultations = o_lastConsultation = o_known = 0; } void c_interpreter::Scan( const char *data ) { char fstate[16], fgettable[6]; int fin, fon, funder, fbeside, fowner, fd[10], i, boole; sscanf( data, "%[^\\]\\%[^\\]\\%[^\\]\\%[^\\]\\%d\\%[^\\]\\%ld\\" "%d\\%d\\%d\\%d\\%d\\" "%d\\%d\\%d\\%d\\%d\\%d\\" "%d\\%d\\%d\\%d\\%d\\%d\\%d\\%d\\%d\\%d\\", o_id, o_article, o_name+7, fstate, &o_weight, fgettable, &o_variable, &fin, &fon, &funder, &fbeside, &fowner, &o_inWeight, &o_inCapacity, &o_onWeight, &o_onCapacity, &o_underWeight, &o_underCapacity, fd, fd+1, fd+2, fd+3, fd+4, fd+5, fd+6, fd+7, fd+8, fd+9 ); if ( ! strcmp( o_article, "_" ) ) *o_article = '\0'; if ( ! strcmp( o_name+7, "_" ) ) o_name[7] = '\0'; boole = 16384; for (i=0;i<15;i++) { o_state = o_state + (boole*(fstate[i]-'0')); boole = boole / 2; } o_gettable = (*fgettable == 't') ? 1 : 0; if ( fin ) o_in = gInterpreter->Interpreter(fin); if ( fon ) o_on = gInterpreter->Interpreter(fon); if ( funder ) o_under = gInterpreter->Interpreter(funder); if ( fbeside ) o_beside = gInterpreter->Interpreter(fbeside); if ( fowner ) o_owner = gInterpreter->Interpreter(fowner); for (i=0; i<10; i++) if ( fd[i] ) o_direction[i] = gInterpreter->Interpreter(fd[i]); } char c_interpreter::DescribeOns( void ) /* Give descriptions of all items on this object: */ { c_interpreter *nextMember; char printSlug; printSlug = 0; for ( nextMember = o_on; nextMember; nextMember = nextMember->Beside() ) { if ( gScriptor->WriteOnce( nextMember->Id() ) ) { nextMember->SetKnownTo( 1 ); printSlug = printSlug | 64; } else if ( nextMember != gInterpreter->Prime() ) { if (nextMember->Known()) printSlug = printSlug | 1; else nextMember->SetKnownTo( 1 ); } if ( nextMember->On() ) printSlug = printSlug | nextMember->DescribeOns(); } return printSlug; } void c_interpreter::ListOns( void ) /* Add all items on this object to the slugline: */ { c_interpreter *nextMember; for ( nextMember = o_on; nextMember; nextMember = nextMember->Beside() ) { if ( *nextMember->Name(alone) ) { strcat( gScriptor->words, ", " ); strcat( gScriptor->words, nextMember->Name(indef) ); strcat( gScriptor->words, " (on " ); strcat( gScriptor->words, this->Name(def) ); strcat( gScriptor->words, ")" ); if ( nextMember->On() ) nextMember->ListOns(); } } } void c_interpreter::PrintSlug( POSITION pos ) { c_interpreter *nextMember; char capitalised = 0; gScriptor->junk[0] = '\0'; // If this object has a name, slug it: if ( *Name(alone) ) { switch ( pos ) { case on: strcat( gScriptor->junk, "On " ); strcat( gScriptor->junk, Name(def) ); strcat( gScriptor->junk, ": " ); nextMember = o_on; break; case in: if ( ClassID() == object ) { strcat( gScriptor->junk, "In " ); strcat( gScriptor->junk, Name(def) ); strcat( gScriptor->junk, ": " ); } else if ( ClassID() > object ) { strcat( gScriptor->junk, cap(Name(def)) ); strcat( gScriptor->junk, ": " ); } else { strcat( gScriptor->junk, cap(Name(def)) ); if ( gInterpreter->Prime()->Posture() || gInterpreter->Prime()->OnLoc() ) { switch ( gInterpreter->Prime()->Posture() ) { case standing: strcat( gScriptor->junk, " (standing" ); break; case sitting: strcat( gScriptor->junk, " (sitting" ); break; case lying: strcat( gScriptor->junk, " (lying" ); break; } if ( gInterpreter->Prime()->OnLoc() ) { strcat( gScriptor->junk, " on " ); strcat( gScriptor->junk, gInterpreter->Prime()->OnLoc()->Name(def) ); } strcat( gScriptor->junk, ")" ); } strcat( gScriptor->junk, ". " ); } nextMember = o_in; break; case under: strcat( gScriptor->junk, "Under " ); strcat( gScriptor->junk, Name( def ) ); strcat( gScriptor->junk, ": " ); nextMember = o_under; break; default: strcat( gScriptor->junk, cap(Name( def )) ); strcat( gScriptor->junk, ". " ); nextMember = o_in; break; } } // Slug all the members attached to this object and anything on those members: while ( nextMember ) { if ( *nextMember->Name(alone) && ! nextMember->State(dontlist) && nextMember != gInterpreter->Prime() ) { if ( ! capitalised ) { strcat( gScriptor->junk, cap( nextMember->Name( indef ) ) ); capitalised = 1; } else { strcat( gScriptor->junk, ", " ); strcat( gScriptor->junk, nextMember->Name( indef ) ); } if ( nextMember->State( worn ) ) strcat( gScriptor->junk, " (worn)" ); if ( nextMember->Posture() || nextMember->OnLoc() ) { switch ( nextMember->Posture() ) { case standing: strcat( gScriptor->junk, " (standing" ); break; case sitting: strcat( gScriptor->junk, " (sitting" ); break; case lying: strcat( gScriptor->junk, " (lying" ); break; } if ( nextMember->OnLoc() ) { strcat( gScriptor->junk, " on " ); strcat( gScriptor->junk, nextMember->OnLoc()->Name(def) ); } strcat( gScriptor->junk, ")" ); } if ( nextMember->On() ) nextMember->ListOns(); } nextMember = nextMember->Beside(); } if ( capitalised ) strcat( gScriptor->junk, ".\n" ); else strcat( gScriptor->junk, "\n" ); gScriptor->WriteString( gScriptor->junk ); gScriptor->EnsureBlank(); } char c_interpreter::DescribeAttached( POSITION pos ) { c_interpreter *nextMember; char printSlug; printSlug = 0; switch ( pos ) { case in: nextMember = o_in; break; case on: nextMember = o_on; break; case under: nextMember = o_under; break; default: return printSlug; } while ( nextMember ) { if ( gScriptor->WriteOnce( nextMember->Id() ) ) { nextMember->SetKnownTo( 1 ); printSlug = printSlug | 64; } else if ( nextMember != gInterpreter->Prime() ) { if (nextMember->Known()) printSlug = printSlug | 1; else nextMember->SetKnownTo( 1 ); } if ( nextMember->On() ) printSlug = printSlug | nextMember->DescribeOns(); nextMember = nextMember->Beside(); } return printSlug; } void c_interpreter::Describe( void ) { char printSlug; printSlug = 0; if ( gScriptor->WriteOnce( o_id ) ) { o_known = 1; printSlug = printSlug | 64; } else { if (o_known) { printSlug = printSlug | 1; } else { Examine( 0 ); o_known = 1; } } printSlug = printSlug | DescribeAttached( in ); if ( printSlug & 64 ) gScriptor->EnsureBlank(); if ( printSlug & 1 ) { PrintSlug( in ); gScriptor->EnsureBlank(); } } void c_interpreter::FakeDescribeOns( void ) { c_interpreter *nextMember; for ( nextMember = o_on; nextMember; nextMember = nextMember->Beside() ) { gScriptor->FakeWrite( nextMember->Id() ); nextMember->SetKnownTo( 1 ); if ( nextMember->On() ) nextMember->FakeDescribeOns(); } } void c_interpreter::FakeDescribe( void ) { c_interpreter *nextMember; gScriptor->FakeWrite( o_id ); o_known = 1; for ( nextMember = o_in; nextMember; nextMember = nextMember->Beside() ) { gScriptor->FakeWrite( nextMember->Id() ); nextMember->SetKnownTo( 1 ); if ( nextMember->On() ) nextMember->FakeDescribeOns(); } } char c_interpreter::Examine( char checkStates ) { EFFECT *fxPtr; char responseName[11], hasWritten; hasWritten = 0; // Get a pointer to the x_ response for this act & scene whose name is this object: strcpy( responseName, "x_" ); strcat( responseName, o_id ); fxPtr = gScriptor->LookUp( responseName ); // Write the found response: if ( fxPtr ) { gScriptor->Write( "^", fxPtr ); hasWritten = 64; } if ( ! checkStates ) return hasWritten; if ( State(closed) ) { if ( hasWritten ) gScriptor->EnsureBlank(); gScriptor->WriteString( "^ is closed.\n", cap( Name( def ) ) ); hasWritten = 64; } else if ( State(opened) ) { if ( hasWritten ) gScriptor->EnsureBlank(); gScriptor->WriteString( "^ is open.\n", cap( Name( def ) ) ); hasWritten = 64; } return hasWritten; } void c_interpreter::Consult( void ) /* Run the interpretation scripts for this object, everything on this object, everything under this object, and everything in this object, as well as the alwaysConsult which is attached to this object. */ { c_interpreter *nextMember; if ( this != gInterpreter->Prime() ) Interpret(); for ( nextMember = o_on; nextMember; nextMember = nextMember->Beside() ) nextMember->Consult(); for ( nextMember = o_under; nextMember; nextMember = nextMember->Beside() ) nextMember->Consult(); for ( nextMember = o_in; nextMember; nextMember = nextMember->Beside() ) nextMember->Consult(); if (o_alwaysConsult) o_alwaysConsult->Consult(); } int c_interpreter::Weight( POSITION pos ) { switch (pos) { case nowhere: return o_weight; case in: return o_inWeight; case on: return o_onWeight; case under: return o_underWeight; default: return 0; } } void c_interpreter::ChangeWeightBy( POSITION pos, int deltaWeight ) { switch (pos) { // On and UnderWeights don't affect owner weight: case under: if ( ! o_underCapacity ) return; o_underWeight += deltaWeight; break; case on: if ( ! o_onCapacity ) return; o_onWeight += deltaWeight; break; // Weights and inWeights affect owner weight: case in: if ( ! o_inCapacity ) return; o_inWeight += deltaWeight; if ( (Position() == in) && o_owner ) o_owner->ChangeWeightBy( in, deltaWeight ); break; case nowhere: o_weight += deltaWeight; if ( o_owner ) o_owner->ChangeWeightBy( Position(), deltaWeight ); if ( OnLoc() ) OnLoc()->ChangeWeightBy( nowhere, deltaWeight ); break; } } int c_interpreter::Capacity( POSITION pos ) { switch (pos) { case in: case nowhere: return o_inCapacity; case on: return o_onCapacity; case under: return o_underCapacity; default: return 0; } } void c_interpreter::SetCapacity( POSITION pos, int newCapacity ) { switch (pos) { case in: o_inCapacity = newCapacity; return; case on: o_onCapacity = newCapacity; return; case under: o_underCapacity = newCapacity; return; case nowhere: return; } } char c_interpreter::Fits( POSITION pos, c_interpreter *object ) { switch (pos) { case in: if ( o_weight + o_inWeight + object->Weight( in ) <= object->Capacity( in ) ) return 1; if ( Exists( in, object ) ) return 1; break; case on: if ( o_weight + object->Weight( on ) <= object->Capacity( on ) ) return 1; break; case under: if ( o_weight + object->Weight( under ) <= object->Capacity( under ) ) return 1; break; case nowhere: break; } return 0; } char c_interpreter::Gettable( void ) { return o_gettable; } void c_interpreter::SetGettableTo( char g ) { o_gettable = g; } char c_interpreter::State( MASK theState ) { if ( o_state & theState ) return 1; else return 0; } void c_interpreter::SetState( MASK theState, char setting ) { if ( setting ) o_state = o_state | theState; else o_state = o_state & (~ theState); } long int c_interpreter::Variable( void ) { return o_variable; } void c_interpreter::SetVariableTo( long int newVariable ) { o_variable = newVariable; } char c_interpreter::Sits( POSITION pos, c_interpreter *object ) /* Returns true if this is attached directly to object's list. */ { c_interpreter *nextMember; switch ( pos ) { case in: nextMember = object->In(); break; case on: nextMember = object->On(); break; case under: nextMember = object->Under(); break; default: return 0; } while ( nextMember ) { if ( nextMember == this ) return 1; nextMember = nextMember->Beside(); } return 0; } void c_interpreter::Put( POSITION pos, c_interpreter *object ) /* Puts this in, on, or under object. */ { c_interpreter *prime; int balanceWeight, i; if ( ClassID() >= animate ) { LoseFollowers(); StayPut(); } prime = gInterpreter->Prime(); balanceWeight = Weight( nowhere ) + Weight( in ); ChangeWeightBy( nowhere, - balanceWeight ); Detach(); SetPostureTo( standing ); SetOnLocTo( NULL ); switch ( pos ) { case in: o_beside = object->In(); object->SetInTo( this ); o_owner = object; if ( this != prime && this->BecomePrime() ) { gInterpreter->PrimeLoc()->FakeDescribe(); prime->BecomePrime(); } break; case on: o_beside = object->On(); object->SetOnTo( this ); o_owner = object; break; case under: o_beside = object->Under(); object->SetUnderTo( this ); o_owner = object; break; default: break; } ChangeWeightBy( nowhere, balanceWeight ); } c_interpreter *c_interpreter::Owner( void ) { return o_owner; } void c_interpreter::SetOwnerTo( c_interpreter *object ) { o_owner = object; } void c_interpreter::Detach( void ) { c_interpreter *nextMember, *lastMember; int balanceWeight; POSITION pos; if ( ! o_owner ) return; balanceWeight = Weight( nowhere ) + Weight( in ); ChangeWeightBy( nowhere, - balanceWeight ); lastMember = NULL; switch ( pos = Position() ) { case in: if ( o_owner->In() == this ) o_owner->SetInTo( o_beside ); for ( nextMember = o_owner->In(); nextMember; nextMember = nextMember->Beside() ) { if ( nextMember->Beside() == this ) { nextMember->SetBesideTo( o_beside ); } lastMember = nextMember; } break; case on: if ( o_owner->On() == this ) o_owner->SetOnTo( o_beside ); for ( nextMember = o_owner->On(); nextMember; nextMember = nextMember->Beside() ) { if ( nextMember->Beside() == this ) { nextMember->SetBesideTo( o_beside ); } lastMember = nextMember; } break; case under: if ( o_owner->Under() == this ) o_owner->SetUnderTo( o_beside ); for ( nextMember = o_owner->Under(); nextMember; nextMember = nextMember->Beside() ) { if ( nextMember->Beside() == this ) { nextMember->SetBesideTo( o_beside ); } lastMember = nextMember; } break; default: break; } for ( nextMember = o_on; nextMember; nextMember = nextMember->Beside() ) if ( ! nextMember->Beside() ) nextMember->SetBesideTo( o_under ); if ( lastMember ) lastMember->SetBesideTo( o_on ); else switch ( pos ) { case in: o_owner->SetInTo( o_on ); case on: o_owner->SetOnTo( o_on ); case under: o_owner->SetUnderTo( o_on ); } o_beside = o_on = o_under = o_owner = NULL; ChangeWeightBy( nowhere, balanceWeight ); } char c_interpreter::Exists( POSITION pos, c_interpreter *object ) /* Returns true is object is attached by even the longest route to this at position pos. */ { c_interpreter *nextMember; switch ( pos ) { case in: nextMember = object->In(); break; case on: nextMember = object->On(); break; case under: nextMember = object->Under(); break; default: return 0; } while ( nextMember ) { if ( ( nextMember == this ) || Exists(in,nextMember) || Exists(on,nextMember) || Exists(under,nextMember) ) return 1; nextMember = nextMember->Beside(); } return 0; } char c_interpreter::CanBeSeen( POSITION pos, c_interpreter *object ) /* Returns true if object is either attached directly to this at position pos or is attached through an ON-chain to this at position pos. */ { c_interpreter *nextMember; switch ( pos ) { case in: nextMember = object->In(); break; case on: nextMember = object->On(); break; case under: nextMember = object->Under(); break; default: return 0; } while ( nextMember ) { if ( ( nextMember == this ) || CanBeSeen(on,nextMember) ) return 1; nextMember = nextMember->Beside(); } return 0; } char c_interpreter::CanBeGot( POSITION pos, c_interpreter *object ) /* Returns true if object is either attached directly to this at position pos or is attached through an ON-chain to this at position pos -- or is immediately inside any of the above (as long as they are not closed). */ { c_interpreter *nextMember; switch ( pos ) { case in: nextMember = object->In(); break; case on: nextMember = object->On(); break; case under: nextMember = object->Under(); break; default: return 0; } while ( nextMember ) { if ( ( nextMember == this ) || CanBeGot(on,nextMember) ) return 1; if ( ! nextMember->State(closed) && o_known ) { if ( Sits(in, nextMember) ) return 1; if ( Sits(under, nextMember) ) return 1; } nextMember = nextMember->Beside(); } return 0; } char c_interpreter::CanBeHeard( POSITION pos, c_interpreter *object ) /* Returns true is object is attached by any route to this at position pos, except if that route must pass through a container which is shut. */ { c_interpreter *nextMember; switch ( pos ) { case in: nextMember = object->In(); break; case on: nextMember = object->On(); break; case under: nextMember = object->Under(); break; default: return 0; } while ( nextMember ) { if ( nextMember == this ) return 1; if ( ! nextMember->State(closed) ) { if ( CanBeHeard(in,nextMember) ) return 1; } if ( CanBeHeard(on,nextMember) ) return 1; if ( CanBeHeard(under,nextMember) ) return 1; nextMember = nextMember->Beside(); } return 0; } POSITION c_interpreter::Position( void ) { if ( this->Sits(in,o_owner) ) return in; if ( this->Sits(on,o_owner) ) return on; if ( this->Sits(under,o_owner) ) return under; return nowhere; } c_interpreter *c_interpreter::Direction( CARD theDirection ) { return o_direction[theDirection]; } void c_interpreter::SetDirection( CARD theDirection, c_interpreter *destination ) { o_direction[theDirection] = destination; } char *c_interpreter::Id( void ) { return o_id; } char *c_interpreter::Name( ARTICLE art ) { switch ( art ) { case indef: sprintf( o_name, "%7s%s", o_article, o_name+7 ); return o_name + 7 - strlen( o_article ); case def: sprintf( o_name, " the %s", o_name+7 ); if ( *o_article ) return o_name + 3; else return o_name + 7; default: return o_name + 7; } } char *c_interpreter::Article( ARTICLE art ) { switch( art ) { case indef: return o_article; case def: if (*o_article) return "the "; else return ""; default: return ""; } } void c_interpreter::SetNameTo( char *newName ) { o_name[0] = '\0'; strncat( o_name+7, newName, 30 ); } void c_interpreter::SetArticleTo( char *newArticle ) { o_article[0] = '\0'; strncat( o_article, newArticle, 6 ); } c_interpreter *c_interpreter::In( void ) { return o_in; } c_interpreter *c_interpreter::On( void ) { return o_on; } c_interpreter *c_interpreter::Under( void ) { return o_under; } c_interpreter *c_interpreter::Beside( void ) { return o_beside; } void c_interpreter::SetInTo( c_interpreter *newIn ) { o_in = newIn; } void c_interpreter::SetOnTo( c_interpreter *newOn ) { o_on = newOn; } void c_interpreter::SetUnderTo( c_interpreter *newUnder ) { o_under = newUnder; } void c_interpreter::SetBesideTo( c_interpreter *newBeside ) { o_beside = newBeside; } long int c_interpreter::Consultations( void ) { return o_consultations; } long int c_interpreter::LastConsultation( void ) { return o_lastConsultation; } c_interpreter *c_interpreter::AlwaysConsult( void ) { return o_alwaysConsult; } void c_interpreter::SetAlwaysConsultTo( c_interpreter *object ) { o_alwaysConsult = object; } char c_interpreter::Known( void ) { return o_known; } void c_interpreter::SetKnownTo( char newKnown ) { o_known = newKnown; } CLASSID c_interpreter::ClassID( void ) { return plain; } void c_interpreter::Interpret( void ) {} char c_interpreter::BecomePrime( void ) { return 0; } char c_interpreter::Act( void ) { return ' '; } char c_interpreter::TieToAct( char newAct ) { return 0; } void c_interpreter::PutFollowedIn( c_interpreter *b ) { Put( in, b ); } char c_interpreter::Follow( c_interpreter *target ) { return 0; } void c_interpreter::LoseFollowers( void ) { return; } char c_interpreter::ListFollowers( char unKnowThem ) { return; } void c_interpreter::Wander( void ) { return; } void c_interpreter::StayPut( void ) { return; } void c_interpreter::SetAction( int a, char *b, char c, c_interpreter *d ) { return; } void c_interpreter::SetAskTo( char *a ) { return; } void c_interpreter::SetTellTo( char *a ) { return; } void c_interpreter::SetShowTo( char *a ) { return; } char *c_interpreter::GetAsk( void ) { return NULL; } char *c_interpreter::GetTell( void ) { return NULL; } char *c_interpreter::GetShow( void ) { return NULL; } void c_interpreter::SetOnLocTo( c_interpreter *newOn ) { return; } void c_interpreter::SetPostureTo( POSTURE newPosture ) { return; } c_interpreter *c_interpreter::OnLoc( void ) { return NULL; } POSTURE c_interpreter::Posture( void ) { return standing; } CLASSID c_object::ClassID( void ) { return object; } CLASSID c_location::ClassID( void ) { return location; } CLASSID c_animate::ClassID( void ) { return animate; } CLASSID c_sentient::ClassID( void ) { return sentient; } CLASSID c_prime::ClassID( void ) { return primer; } c_animate::c_animate( void ) { int i; for (i=0;i<16;i++) { action[i].response[0] = '\0'; action[i].chance = 0; action[i].trigger = NULL; } nextWanderer = NULL; } void c_animate::Interpret( void ) { if ( !gCommander->CommandReady() ) { int i; for (i=0;i<16;i++) if ( action[i].response[0] && randomof(100) < action[i].chance ) if ( ! action[i].trigger || action[i].trigger->Sits(in,Owner()) ) gScriptor->Write( action[i].response ); } } void c_animate::PutFollowedIn( c_interpreter *object ) /* Puts this in, on, or under object with followers. */ { c_interpreter *prime; int balanceWeight, i; EFFECT *fxPtr; for (i=1; i<10; i++) if ( Direction(i) && ! Direction(i)->Sits(in,Owner()) ) Direction(i)->StayPut(); prime = gInterpreter->Prime(); balanceWeight = Weight( nowhere ) + Weight( in ); ChangeWeightBy( nowhere, - balanceWeight ); Detach(); SetPostureTo( standing ); SetOnLocTo( NULL ); SetBesideTo( object->In() ); object->SetInTo( this ); SetOwnerTo( object ); fxPtr = gScriptor->LookUp( object->Id() ); if ( this != prime && this->BecomePrime() ) { if ( fxPtr != gScriptor->LookUp( object->Id() ) ) object->FakeDescribe(); prime->BecomePrime(); } ChangeWeightBy( nowhere, balanceWeight ); for (i=1; i<10; i++) if ( Direction(i) ) if ( Direction(i)->ClassID() < animate ) { Direction(i)->Put(in,object); SetDirection(i,NULL); } else { if ( !Direction(i)->Posture() && !Direction(i)->OnLoc() ) Direction(i)->PutFollowedIn( object ); else Direction(i)->StayPut(); } if ( Direction(0) && ! Direction(0)->Sits(in,Owner()) ) StayPut(); } char c_animate::Follow( c_interpreter *target ) { int i; for (i=1; i<10; i++) if (!target->Direction(i)) { StayPut(); target->SetDirection(i,this); SetDirection(0,target); return 1; } return 0; } void c_animate::LoseFollowers( void ) { int i; for (i=1; i<10; i++) if (Direction(i)) Direction(i)->StayPut(); } char c_animate::ListFollowers( char unKnowThem ) { char *err, flag = 0; int i; for (i=1; i<10; i++) if (Direction(i)) { if (Direction(i)->ClassID() < animate ) { Direction(i)->SetDirection(0,NULL); SetDirection(i,NULL); continue; } if ( !(err=gScriptor->GetTextFromIndex( "e_errors", "et_follower" )) ) err = "^ follows ^.\n"; gScriptor->WriteString( err, cap(Direction(i)->Name(def)), Name(def) ); if ( unKnowThem ) Direction(i)->SetKnownTo( 0 ); flag = 1; Direction(i)->ListFollowers( unKnowThem ); } return flag; } void c_animate::Wander( void ) { StayPut(); SetNextWandererTo( gInterpreter->FirstWanderer() ); gInterpreter->SetFirstWandererTo( this ); } void c_animate::StayPut( void ) { c_animate *nextMember; int i; if ( Direction(0) ) { for (i=1; i<10; i++) if (Direction(0)->Direction(i) == this) Direction(0)->SetDirection(i,NULL); SetDirection(0,NULL); } nextMember = gInterpreter->FirstWanderer(); if ( nextMember == this ) { gInterpreter->SetFirstWandererTo( NextWanderer() ); } else { while ( nextMember && nextMember->NextWanderer() != this ) nextMember = nextMember->NextWanderer(); if ( nextMember ) nextMember->SetNextWandererTo( NextWanderer() ); } SetNextWandererTo( NULL ); } void c_animate::SetAction( int a, char *resp, char chan, c_interpreter *trig ) { action[a].response[0] = '\0'; strncat( action[a].response, resp, 13 ); action[a].chance = chan; action[a].trigger = trig; } c_animate *c_animate::NextWanderer( void ) { return nextWanderer; } void c_animate::SetNextWandererTo( c_animate *x ) { nextWanderer = x; } c_sentient::c_sentient( void ) { index.ask[0] = index.tell[0] = index.show[0] = '\0'; } void c_sentient::Interpret( void ) { if ( gCommander->Match( "?/ask/_/about|of/_" ) ) { if ( *index.ask && this == gCommander->Interpreter(obj) ) if ( gScriptor->WriteFromIndex( index.ask, gCommander->Translated(indo1) ) ) gCommander->Absorb( one ); } else if ( gCommander->Match( "?/tell/_/about|of/_" ) ) { if ( *index.tell && this == gCommander->Interpreter(obj) ) if ( gScriptor->WriteFromIndex( index.tell, gCommander->Translated(indo1) ) ) gCommander->Absorb( one ); } else if ( gCommander->Match( "?/show/_/to/_" ) ) { if ( *index.show && this == gCommander->Interpreter(indo1) && gCommander->Interpreter(obj) && gCommander->Interpreter(obj)->CanBeGot(in,gInterpreter->Prime() ) ) if ( gScriptor->WriteFromIndex( index.show, gCommander->Translated(obj) ) ) gCommander->Absorb( one ); } c_animate::Interpret(); } void c_sentient::SetAskTo( char *s ) { index.ask[0] = '\0'; strncat( index.ask, s, 13 ); } void c_sentient::SetTellTo( char *s ) { index.tell[0] = '\0'; strncat( index.tell, s, 13 ); } void c_sentient::SetShowTo( char *s ) { index.show[0] = '\0'; strncat( index.show, s, 13 ); } char *c_sentient::GetAsk( void ) { if (*index.ask) return index.ask; else return NULL; } char *c_sentient::GetTell( void ) { if (*index.tell) return index.tell; else return NULL; } char *c_sentient::GetShow( void ) { if (*index.show) return index.show; else return NULL; } c_prime::c_prime( void ) { act = ' '; onInterpreter = NULL; posture = standing; } char c_prime::BecomePrime( void ) { gInterpreter->SetPrimeTo( this ); if ( act != ' ' ) gInterpreter->SetActTo( act ); return 1; } char c_prime::Act( void ) { return act; } char c_prime::TieToAct( char newAct ) { act = newAct; return 1; } POSTURE c_prime::Posture( void ) { return posture; } void c_prime::SetPostureTo( POSTURE newPosture ) { posture = newPosture; } c_interpreter *c_prime::OnLoc( void ) { return onInterpreter; } void c_prime::SetOnLocTo( c_interpreter *newOn ) { if ( onInterpreter ) onInterpreter->ChangeWeightBy(on,-Weight(nowhere)); onInterpreter = newOn; if ( onInterpreter ) onInterpreter->ChangeWeightBy(on,Weight(nowhere)); } void c_prime::Interpret( void ) { c_sentient::Interpret(); } /* ginterpt.c */ #include "includes.h" #include "shortcut.h" #undef prime #undef loc void CGlobalInterpreter::Interpret( void ) { c_interpreter *prime, *loc, *ref1, *ref2; char *err, status; int i; prime = gInterpreter->Prime(); loc = gInterpreter->PrimeLoc(); ref1 = i(obj); if ( !cmd ) { c_animate *nextMember; nextMember = gInterpreter->FirstWanderer(); for( ; nextMember; nextMember = nextMember->NextWanderer() ) { if ( nextMember == prime ) continue; if ( nextMember->Posture() || nextMember->OnLoc() ) continue; i = randomof( 8 ); if ( i != NE && i != SW && nextMember->owner->direction(i) ) { status = 0; if ( nextMember->owner == loc ) { if ( !(err=GetTextFromIndexO( nextMember, "et_goes_to_the" )) && !(err=GetTextFromIndex( "e_errors", "et_goes_to_the" )) ) err = "^ goes to the ^.\n"; WriteString( err, cap(nextMember->name(def)), longcardinals[i] ); status = 1; } nextMember->PutFollowedIn( nextMember->owner->direction(i) ); if ( nextMember->owner == loc ) { i = i - 4; if ( i < 0 ) i = i + 8; if ( !(err=GetTextFromIndexO( nextMember, "et_enters_from_the" )) && !(err=GetTextFromIndex( "e_errors", "et_enters_from_the" )) ) err = "^ approaches from the ^.\n"; WriteString( err, cap(nextMember->name(def)), longcardinals[i] ); status = 1; } if ( status && nextMember->ListFollowers(0) ) Blank(); } } } // Check to make sure on-links are OK. for ( ref2 = loc->In(); ref2; ref2 = ref2->Beside() ) if ( ref2->onloc && !ref2->onloc->Sits(in,loc) ) { ref2->SetOnLocTo( NULL ); ref2->SetPostureTo( standing ); } if ( ! gCommander->CommandLive() ) return; if ( match( "?/look" ) ) { status = loc->Examine( 0 ) | loc->DescribeAttached( in ); if ( (status & 1) || !status ) { if ( status & 64 ) Blank(); loc->PrintSlug( in ); } Absorb( one ); } else if ( match( "?/inventory" ) ) { status = prime->DescribeAttached( in ); if ( status & 1 ) { if ( status & 64 ) Blank(); prime->PrintSlug( in ); } else if ( !status ) { if ( !(err=GetTextFromIndex( "e_errors", "et_empty_handed" )) ) err = "^ is empty-handed.\n"; WriteString( err, cap(prime->name(def)) ); } Absorb( one ); } else if ( match( "?/lie|sit|stand|jump|go|get|climb|dive//in|on|under/*" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireClause( "in|on|under", visible_in_loc, "where", NULL ) ) return; if ( !RequireNoSelf( indo1 ) ) return; if ( matchwd( verb, "lie" ) ) PushCmd( "put you ^ ^; lie", u(prep1), u(indo1) ); else if ( matchwd( verb, "sit" ) ) PushCmd( "put you ^ ^; sit", u(prep1), u(indo1) ); else PushCmd( "put you ^ ^", u(prep1), u(indo1) ); Absorb(one); } else if ( matchwd( verb, "go|run|sneak" ) ) { c_interpreter *destination; char dir[4]; if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireObj( empty, NULL ) ) return; if ( !RequireClause( "n|ne|e|se|s|sw|w|nw|u|d", empty, "where", NULL ) ) return; sprintf( dir, "%-3s", translated(prep1) ); destination = loc->direction( ( strstr(cardinals,dir) - cardinals ) / 3 ); if ( prime->posture != standing ) { if ( !(err=GetTextFromIndex( "e_errors", "et_should_get_up" )) ) err = "\"Perhaps I should get up first,\" suggests ^.\n"; WriteString( err, prime->name(def) ); SuggestCmd( "get up; go ^", u(prep1) ); Absorb( one ); } else if ( prime->onloc != NULL ) { if ( !(err=GetTextFromIndex( "e_errors", "et_should_get_down" )) ) err = "\"Perhaps I should get down first,\" suggests ^.\n"; WriteString( err, prime->name(def) ); SuggestCmd( "alight; go ^", u(prep1) ); Absorb( one ); } else if (!destination) { if ( !(err=GetTextFromIndex( "e_errors", "et_bad_exit" )) ) err = "[^ can't go in that direction.]\n"; WriteString( err, cap(prime->name(def)) ); Absorb( all ); } else { LocTo( destination ); if ( prime->ListFollowers(1) ) Blank(); Absorb( one ); gInterfacer->oldPrimeLoc = NULL; } for (i=1;i<10;i++) if ( prime->direction(i) && prime->direction(i)->type < animate ) prime->SetDirection(i,NULL); } else if ( matchwd( verb, "exit" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( ref1 && ref1 != prime ) { if ( !(err=GetTextFromIndex( "e_errors", "et_not_in/on/under" )) ) err = "\"I'm not ^ ^^,\" says ^.\n"; WriteString( err, "in", ref1->known ? ref1->art(def) : "any ", ref1->known ? ref1->name(alone) : p(obj), prime->name(def) ); Absorb( all ); } else if ( !loc->state(contains) || !loc->owner ) { if ( !(err=GetTextFromIndex( "e_errors", "et_not_in/on/under" )) ) err = "\"I'm not ^ ^^,\" says ^.\n"; WriteString( err, "in", "anything", "", prime->name(def) ); Absorb( all ); } else if ( loc->state(closed) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_closed" )) ) err = "\"^ is closed,\" says ^.\n"; WriteString( err, cap(loc->name(def)), prime->name(def) ); Absorb( all ); } else if ( prime->posture != standing ) { if ( !(err=GetTextFromIndex( "e_errors", "et_should_get_up" )) ) err = "\"Perhaps I should get up first,\" suggests ^.\n"; WriteString( err, prime->name(def) ); Absorb( one ); SuggestCmd( "get up; exit" ); } else if ( prime->onloc != NULL ) { if ( !(err=GetTextFromIndex( "e_errors", "et_should_get_down" )) ) err = "\"Perhaps I should get down first,\" suggests ^.\n"; WriteString( err, prime->name(def) ); Absorb( one ); SuggestCmd( "alight; exit" ); } else { prime->Put(in,loc->owner); Absorb( one ); } } else if ( matchwd( verb, "jump" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_jumps" )) ) err = "\"I'm an actor, not a circus performer,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( matchwd( verb, "climb" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_climbs" )) ) err = "\"Yeah, right,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( matchwd( verb, "get|steal" ) ) { c_interpreter *onthing = NULL; if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( can_get, "what" ) ) return; if ( !RequireNoSelf( obj ) ) return; onthing = ref1->On(); if (!onthing) { for (ref2 = loc->In(); ref2; ref2 = ref2->Beside()) if ( ref2->onloc == ref1 ) onthing = ref2; } if ( ref1->owner->type >= animate ) { if ( !(err=GetTextFromIndexO( ref1, "et_get_refused" )) && !(err=GetTextFromIndex( "e_errors", "et_get_refused" )) ) err = "^ refuses to relinquish ^.\n"; WriteString( err, cap(ref1->owner->name(def)), ref1->name(def) ); Absorb( all ); } else if ( ref1->Sits(in,prime) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_already_got" )) ) err = "\"I already have ^,\" says ^.\n"; WriteString( err, ref1->name(def), prime->name(def) ); Absorb( all ); } else if ( !RequireGettable( obj ) ) { if ( !gCommander->AllInProgress() ) Absorb( all ); } else if ( !RequireWeightFactor( obj, 1, "carry" ) ) { if ( !gCommander->AllInProgress() ) Absorb( all ); } else if ( onthing == prime ) { if ( !(err=GetTextFromIndexO( ref1, "et_suggest_get_prime_off" )) && !(err=GetTextFromIndex( "e_errors", "et_suggest_get_prime_off" )) ) err = "\"I'll have to get off ^ first,\" suggests ^.\n"; WriteString( err, ref1->name(def), prime->name(def) ); SuggestCmd( "alight; get ^", u(obj) ); Absorb( one ); } else if ( onthing && thes(onthing) ) { if ( !(err=GetTextFromIndexO( ref1, "et_suggest_get_x_off" )) && !(err=GetTextFromIndex( "e_errors", "et_suggest_get_x_off" )) ) err = "\"I'll have to get ^ off ^ first,\" suggests ^.\n"; WriteString( err, onthing->name(def), ref1->name(def), prime->name(def) ); SuggestCmd( "get ^; drop it; get ^", thes(onthing), u(obj) ); Absorb( one ); } else if (!ref1->Fits(in,prime)) { if ( !(err=GetTextFromIndex( "e_errors", "et_too_loaded" )) ) err = "\"I'm too loaded down with other stuff to take ^,\" says ^.\n"; WriteString( err, ref1->name(def), prime->name(def) ); if ( gCommander->AllInProgress() ) Absorb( one ); else Absorb( all ); } else { ref1->Put(in,prime); if ( !(err=GetTextFromIndex( "e_errors", "et_takes" )) ) err = "^ takes ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } } else if ( match( "?/look/?/in|on|under/*" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireObj( empty, NULL ) ) return; if ( !RequireClause( "in|on|under", visible, "where", NULL ) ) return; if ( !RequireNoSelf( indo1 ) ) return; ref2 = i(indo1); if ( matchwd( prep1, "in" ) ) { if ( !RequireInert( indo1 ) ) return; if ( ref2->state(closed) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_closed" )) ) err = "\"^ is closed,\" says ^. \"Perhaps I should open it?\"\n"; WriteString( err, cap(ref2->name(def)), prime->name(def) ); SuggestCmd( "open ^; look in ^", u(indo1), u(indo1) ); Absorb( one ); } else if ( !ref2->state(contains) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_nothing_in" )) ) err = "\"I can't look inside ^,\" says ^.\n"; WriteString( err, ref2->name(indef), prime->name(def) ); Absorb( all ); } else { status = ref2->DescribeAttached( in ); if ( status & 1 ) { if ( status & 64 ) Blank(); ref2->PrintSlug( in ); } else if ( !status ) { if ( !(err=GetTextFromIndex( "e_errors", "et_nothing_in" )) ) err = "\"There is nothing in ^,\" says ^.\n"; WriteString( err, ref2->name(def), prime->name(def) ); } Absorb( one ); } } else if ( matchwd( prep1, "on" ) ) { if ( !ref2->state(supports) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_nothing_on" )) ) err = "\"There is nothing on ^,\" says ^.\n"; WriteString( err, ref2->name(def), prime->name(def) ); Absorb( one ); } else { status = ref2->DescribeAttached( on ); if ( status & 1 ) { if ( status & 64 ) Blank(); ref2->PrintSlug( on ); } else if ( !status ) { if ( !(err=GetTextFromIndex( "e_errors", "et_nothing_on" )) ) err = "\"There is nothing on ^,\" says ^.\n"; WriteString( err, ref2->name(def), prime->name(def) ); } Absorb( one ); } } else if ( matchwd( prep1, "under" ) ) { if ( !ref2->state(spaceunder) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_nothing_under" )) ) err = "\"There is nothing under ^,\" says ^.\n"; WriteString( err, ref2->name(def), prime->name(def) ); Absorb( one ); } else { status = ref2->DescribeAttached( under ); if ( status & 1 ) { if ( status & 64 ) Blank(); ref2->PrintSlug( under ); } else if ( !status ) { if ( !(err=GetTextFromIndex( "e_errors", "et_nothing_under" )) ) err = "\"There is nothing under ^,\" says ^.\n"; WriteString( err, ref2->name(def), prime->name(def) ); } Absorb( one ); } } // end section -- look in/on/under } else if ( matchwd( verb, "put" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( ref1 != prime && !RequireObj( can_drop_in_prime, "what" ) ) return; if ( !RequireClause( "in|on|under", visible, "where", "" ) ) return; if ( !RequireNoSelf( indo1 ) ) return; ref2 = i(indo1); if ( !RequireInert( indo1 ) ) return; if ( matchwd( prep1, "in" ) ) { if (ref2->state(closed)) { if ( !(err=GetTextFromIndex( "e_errors", "et_closed" )) ) err = "\"^ is closed,\" says ^. \"Perhaps I should open it?\"\n"; WriteString( err, cap(ref2->name(def)), prime->name(def) ); SuggestCmd( "get ^; put ^ in ^", u(obj), u(indo1) ); Absorb( one ); } else if (!ref2->state(contains) || !ref1->Fits(in,ref2)) { if ( !(err=GetTextFromIndex( "e_errors", "et_won't_fit" )) ) err = "\"^ won't fit ^ ^,\" says ^.\n"; WriteString( err, ref1 != prime ? cap(ref1->name(def)) : "I", "in", ref2->name(def), prime->name(def) ); if ( gCommander->AllInProgress() ) Absorb( one ); else Absorb( all ); } else { ref1->Put(in,ref2); if ( !(err=GetTextFromIndex( "e_errors", "et_puts" )) ) err = "^ puts ^ ^ ^.\n"; if ( ref1 != prime ) WriteString( err, cap(prime->name(def)), ref1->name(def), "in", ref2->name(def) ); Absorb( one ); } } else if ( matchwd( prep1, "on" ) ) { if (!ref2->state(supports) || !ref1->Fits(on,ref2)) { if ( !(err=GetTextFromIndex( "e_errors", "et_won't_fit" )) ) err = "\"^ won't fit ^ ^,\" says ^.\n"; WriteString( err, ref1 != prime ? cap(ref1->name(def)) : "I", "on", ref2->name(def), prime->name(def) ); if ( gCommander->AllInProgress() ) Absorb( one ); else Absorb( all ); } else if ( ref1 == prime ) { prime->SetPostureTo( standing ); prime->SetOnLocTo( ref2 ); Absorb( one ); } else { ref1->Put(on,ref2); if ( !(err=GetTextFromIndex( "e_errors", "et_puts" )) ) err = "^ puts ^ ^ ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def), "on", ref2->name(def) ); Absorb( one ); } } else if ( matchwd( prep1, "under" ) ) { if (!ref2->state(spaceunder) || !ref1->Fits(under,ref2)) { if ( !(err=GetTextFromIndex( "e_errors", "et_won't_fit" )) ) err = "\"^ won't fit ^ ^,\" says ^.\n"; WriteString( err, ref1 != prime ? cap(ref1->name(def)) : "I", "under", ref2->name(def), prime->name(def) ); if ( gCommander->AllInProgress() ) Absorb( one ); else Absorb( all ); } else { ref1->Put(under,ref2); if ( !(err=GetTextFromIndex( "e_errors", "et_puts" )) ) err = "^ puts ^ ^ ^.\n"; if ( ref1 != prime ) WriteString(err,cap(prime->name(def)),ref1->name(def),"under",ref2->name(def)); Absorb( one ); } } } else if ( matchwd( verb, "compare" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireObj( visible, "what" ) ) return; if ( !RequireClause( "with", visible, "what", "with" ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_they're_different" )) ) err = "\"They're different.\"\n"; WriteString( err ); Absorb( one ); } else if ( matchwd( verb, "emote" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_emotes" )) ) err = "[Your influence extends to the actors' decisions, but not" " to their emotions or states of mind.]\n"; WriteString( err ); Absorb( one ); } else if ( matchwd( verb, "pray" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !matchwd( prep1, "to|for|" ) && !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( empty, NULL ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_prays" )) ) err = "^ prays.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } else if ( matchwd( verb, "say|whisper" ) || match( "?/shout/_/*" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !matchwd( prep1, "to|" ) && !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( full, "what" ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_says" )) ) err = "^ mumbles it unconvincingly. [The actors don't really" " appreciate being spoon-fed dialogue. Try directing them to" " ask or talk to someone about a particular subject.]\n"; WriteString( err, cap(prime->name(def)) ); Absorb( all ); } else if ( matchwd( verb, "shout" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !matchwd( prep1, "at" ) && !ClausesCantExceed( 0 ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_shouts" )) ) err = "\"Aaaaah!\" shouts ^. \"Felt good. What's next?\"\n"; WriteString( err, prime->name(def) ); Absorb( one ); } else if ( matchwd( verb, "sing" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !matchwd( prep1, "to|about|for|" ) && !ClausesCantExceed( 0 ) ) return; if ( ref1 && !RequireObj( empty, NULL ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_sings" )) ) err = "\"La.\"\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } else if ( matchwd( verb, "strip" ) || match( "?/sleep//with/_" ) || match( "?/seduce/_" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !matchwd( prep1, "with|for|" ) && !ClausesCantExceed( 0 ) ) return; if ( !ref1 || ref1->type >= sentient || !i(prep1) || i(prep1)->type >= sentient ) { if ( !(err=GetTextFromIndex( "e_errors", "et_strips" )) ) err = "\"Hey, now wait just a minute,\" says ^. \"That wasn't in my contract.\"\n"; WriteString( err, prime->name(def) ); Absorb( all ); } } else if ( matchwd( verb, "sleep" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireObj( empty, NULL ) ) return; if ( !matchwd( prep1, "on|under|in|" ) && !ClausesCantExceed( 0 ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_sleeps" )) ) err = "\"But I'm not tired,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( matchwd( verb, "smile" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !matchwd( prep1, "at|for|" ) && !ClausesCantExceed( 0 ) ) return; if ( !matchwd( obj, "" ) && !RequireObj( visible, NULL ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_smiles" )) ) err = "^ grins.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } else if ( matchwd( verb, "think" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireObj( empty, NULL ) ) return; if ( !matchwd( prep1, "on|about|" ) && !ClausesCantExceed( 0 ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_thinks" )) ) err = "\"You're supposed to be doing the thinking.\"\n"; WriteString( err, prime->name(def) ); Absorb( one ); } else if ( matchwd( verb, "cry" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !matchwd( prep1, "about|for|" ) && !ClausesCantExceed( 0 ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_cries" )) ) err = "\"Don't you think that would be a little melodramatic?\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( one ); } else if ( matchwd( verb, "laugh" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !matchwd( prep1, "at|about|with|" ) && !ClausesCantExceed( 0 ) ) return; if ( ref1 && !RequireObj( empty, NULL ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_laughs" )) ) err = "^ laughs.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } else if ( match( "?/lock/?" ) ) { if ( !RequireObj( visible, "what" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_locks" )) ) err = "\"^ can't be locked,\" says ^.\n"; WriteString( err, cap(ref1->name(def)), prime->name(def) ); Absorb( all ); } else if ( match( "?/unlock/?" ) ) { if ( !RequireObj( visible, "what" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_unlocks" )) ) err = "\"^ isn't locked,\" says ^.\n"; WriteString( err, cap(ref1->name(def)), prime->name(def) ); Absorb( all ); } else if ( match( "?/fix/?/|with/?" ) ) { if ( !RequireObj( visible, "what" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireNoSelf( indo1 ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_fixes" )) ) err = "\"^ isn't broken,\" says ^.\n"; WriteString( err, cap(ref1->name(def)), prime->name(def) ); Absorb( all ); } else if ( match( "?/wave" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_waves" )) ) err = "^ waves.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } else if ( matchwd( verb, "wave" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireObj( can_drop_in_prime, "what" ) ) return; if ( matchwd( prep1, "at" ) && !RequireClause( "at", visible, "who", "at" ) ) return; if ( !matchwd( prep1, "about" ) && !ClausesCantExceed( 1 ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_waves_something" )) ) err = "^ waves ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "swing" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireObj( can_drop_in_prime, "what" ) ) return; if ( !RequireClause( "at", visible_in_loc, "what", "at" ) ) return; if ( !(err=GetTextFromIndexO( i(prep1), "et_attacks" )) && !(err=GetTextFromIndex( "e_errors", "et_attacks" )) ) err = "\"Look, violence isn't the answer,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( match( "?/throw/_/at/*" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireObj( can_drop_in_prime, "what" ) ) return; if ( !RequireClause( "at", visible_in_loc, "who", "at" ) ) return; if ( !(err=GetTextFromIndexO( ref1, "et_attacks" )) && !(err=GetTextFromIndex( "e_errors", "et_attacks" )) ) err = "\"Look, violence isn't the answer,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( matchwd( verb, "clean" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireObj( visible, "what" ) ) return; if ( !(err=GetTextFromIndex( "e_errors", "et_cleans" )) ) err = "\"I'm an actor not a housekeeper,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( match( "?/quit" ) ) { extern char quitting_time; quitting_time = 1; Absorb( all ); } else if ( matchwd( verb, "call" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( full, "who" ) ) return; if ( !ref1 && !RequireObj( visible, "who" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( ref1->type < animate || ( ref1->type < primer && !ref1->Sits(in,loc) ) ) { if ( !(err = GetTextFromIndex( "e_errors", "et_no_answer" )) ) err = "^ calls but there is no answer.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } else if ( ref1->type != primer || ref1->Sits(in,loc) ) { if ( !(err = GetTextFromIndexO( ref1, "et_calls" )) && !(err = GetTextFromIndex( "e_errors", "et_calls" )) ) err = "^ looks expectantly at ^.\n"; WriteString( err, cap(ref1->name(def)), prime->name(def) ); Absorb( one ); } else { c_interpreter *nxt; char found = 0; if ( !ref1->state(dontcall) ) for (i=0; i<10; i++) if ( loc->direction(i) && ref1->sits(in,loc->direction(i)) ) found = 1; if ( found ) { if ( !(err = GetTextFromIndexO( ref1, "et_calls_in" )) && !(err = GetTextFromIndex( "e_errors", "et_calls_in" )) ) err = "^ comes and looks expectantly at ^.\n"; WriteString( err, cap(ref1->name(def)), prime->name(def) ); ref1->PutFollowedIn( loc ); if ( ref1->ListFollowers(0) ) Blank(); Absorb( one ); } else { if ( !(err = GetTextFromIndex( "e_errors", "et_no_answer" )) ) err = "^ calls but there is no answer.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } } } else if ( match( "?/ask/_/for/_" ) ) { if ( !RequireObj( visible, "who" ) ) return; if ( !RequireClause( "for", full, "what", "for" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireNoSelf( indo1 ) ) return; ref2 = i(indo1); if ( !ref2 || !ref2->Exists(in,ref1) ) { if ( !(err = GetTextFromIndexO( ref1, "et_doesn't_have_it" )) && !(err = GetTextFromIndex( "e_errors", "et_doesn't_have_it" )) ) err = "\"I don't think ^ has ^^,\" says ^.\n"; WriteString( err, ref1->name(def), ref2 && ref2->known ? ref2->article(def) : "any ", ref2 && ref2->known ? ref2->name(alone) : u(indo1), prime->name(def) ); Absorb( all ); } else { if ( !(err=GetTextFromIndexO( ref1, "et_get_refused" )) && !(err=GetTextFromIndex( "e_errors", "et_get_refused" )) ) err = "^ refuses to relinquish ^.\n"; WriteString( err, cap(ref1->name(def)), ref2->name(def) ); Absorb( all ); } } else if ( matchwd( verb, "ask|tell" ) ) { char *s = NULL; if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireObj( visible, "who" ) ) return; if ( !RequireClause( "about", full, "what", "about" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( matchwd( verb, "tell" ) ) { s = ref1->GetTell(); if ( !(err = GetTextFromIndex( s, p(indo1) )) ) err = "^ has a brief discussion with ^, and then pronounces, \"^ doesn't seem too" " interested.\""; } else { s = ref1->GetAsk(); if ( !(err = GetTextFromIndex( s, p(indo1) )) ) err = "^ consults momentarily with ^, and then pronounces, \"^ doesn't seem to" " know anything about that.\""; } WriteString( err, cap(prime->name(def)), ref1->name(def), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "show" ) ) { char *s = NULL; if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireObj( visible_in_prime, "what" ) ) return; if ( !RequireClause( "to", visible, "who", "to" ) ) return; if ( !RequireNoSelf( indo1 ) ) return; ref2 = i(indo1); if ( ref2->type > animate ) s = ref2->GetShow(); if ( !s || !(*s) || !(err = GetTextFromIndex( s, p(obj) )) ) err = "^ ignores ^. \"Alright,\" says ^. \"What next?\""; WriteString( err, cap(ref2->name(def)), ref1->name(def), prime->name(def) ); Absorb( one ); } else if ( matchwd( verb, "find" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( full, "what" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( ref1 ) if ( ref1->Sits(in,loc) ) { if ( !(err = GetTextFromIndex( "e_errors", "et_found" )) ) err = "\"^ is right here,\" says ^.\n"; WriteString( err, cap(ref1->name(def)), prime->name(def) ); Absorb( one ); } else if ( ref1->CanBeSeen(in,loc) ) { if ( !(err = GetTextFromIndex( "e_errors", "et_found_on" )) ) err = "\"^ is on ^,\" says ^.\n"; WriteString( err, cap(ref1->name(def)), ref1->owner->name(def), prime->name(def) ); Absorb( one ); } else if ( ref1->CanBeGot(in,loc) || ref1->CanBeGot(in,prime) ) { if ( ref1->owner->type < animate ) { if ( !(err = GetTextFromIndex( "e_errors", "et_found_in" )) ) err = "\"^ is inside ^,\" says ^.\n"; WriteString( err, cap(ref1->name(def)), ref1->owner->name(def), prime->name(def) ); } else { if ( !(err = GetTextFromIndex( "e_errors", "et_found_possessed" )) ) err = "\"^ is in ^^ possession,\" says ^.\n"; WriteString( err, cap(ref1->name(def)), ref1->owner != prime ? ref1->owner->name(def) : "my", ref1->owner != prime ? "'s" : "", prime->name(def) ); } Absorb( one ); } else { RequireObj( visible, "what" ); } } else if ( matchwd( verb, "give" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireObj( can_drop_in_prime, "what" ) ) return; if ( !RequireClause( "to", visible, "who", "to" ) ) return; if ( !RequireNoSelf( indo1 ) ) return; ref2 = i(indo1); if ( ref1->Fits(in,ref2) ) { ref1->Put(in,ref2); if ( !(err = GetTextFromIndexO( ref2, "et_give_accepted" )) && !(err = GetTextFromIndex( "e_errors", "et_give_accepted" )) ) err = "^ accepts ^ from ^.\n"; WriteString( err, cap(ref2->name(def)), ref1->name(def), prime->name(def) ); Absorb( one ); } else { if ( !(err = GetTextFromIndexO( ref2, "et_give_refused" )) && !(err = GetTextFromIndex( "e_errors", "et_give_refused" )) ) err = "^ refuses ^.\n"; WriteString( err, cap(ref2->name(def)), ref1->name(def) ); Absorb( one ); } } else if ( match( "?/throw/_/n|ne|e|se|s|sw|w|nw|u|d" ) ) { c_interpreter *destination; char dir[4]; if ( !RequireNoSelf( obj ) ) return; if ( !RequireObj( can_drop_in_prime, "what" ) ) return; sprintf( dir, "%-3s", translated(prep1) ); destination = loc->direction( ( strstr(cardinals,dir) - cardinals ) / 3 ); if ( destination ) { ref1->Put(in,destination); } else { ref1->Put(in,loc); } if ( !(err = GetTextFromIndex( "e_errors", "et_throws" )) ) err = "^ throws ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( match( "?/move//n|ne|e|se|s|sw|w|nw|u|d" ) ) { PushCmd( "go ^", t(prep1) ); Absorb( one ); } else if ( match( "?/move|pull/_/n|ne|e|se|s|sw|w|nw|u|d" ) ) { if ( !RequireObj( visible_in_loc, "what" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireInert( obj ) ) return; if (!RequireGettable( obj ) ) { Absorb( all ); } else if ( !RequireWeightFactor( obj, 5, "drag" ) ) { Absorb( all ); } else { for (i=1;i<10;i++) { if ( !prime->direction(i) ) { prime->SetDirection(i,ref1); break; } } PushCmd( "go ^", t(prep1) ); Absorb( one ); } } else if ( matchwd( verb, "follow" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( visible_in_loc, "who" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( ref1->type < animate ) { if ( !(err=GetTextFromIndex( "e_errors", "et_can't_follow" )) ) err = "\"I can't follow ^,\" says ^.\n"; WriteString( err, ref1->name(indef), prime->name(def) ); Absorb( all ); } else if ( ! prime->Follow( ref1 ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_too_many_followers" )) ) err = "\"^ has too many followers already,\" says ^.\n"; WriteString( err, cap(ref1->name(def)), prime->name(def) ); Absorb( all ); } else { if ( !(err=GetTextFromIndex( "e_errors", "et_ok" )) ) err = "\"Okay.\"\n"; WriteString( err ); Absorb( one ); } } else if ( match( "?/attack|choke|cut|shoot|destroy|hit|kick/?/|with/*" ) ) { if ( !ClausesCantExceed( 1 ) ) return; if ( !RequireObj( visible_in_loc, "who" ) ) return; if ( !(err=GetTextFromIndexO( ref1, "et_attacks" )) && !(err=GetTextFromIndex( "e_errors", "et_attacks" )) ) err = "\"Look, violence isn't the answer,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( matchwd( verb, "dodge" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( visible_in_loc, "what" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !(err = GetTextFromIndexO( ref1, "et_dodges" )) && !(err = GetTextFromIndex( "e_errors", "et_dodges" )) ) err = "^ steers clear of ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "embrace|hail|insult|scold|distract" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( visible, "who" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( matchwd( verb, "embrace" ) ) { if ( ref1->type >= animate ) { if ( !(err = GetTextFromIndexO( ref1, "et_hugs" )) && !(err = GetTextFromIndex( "e_errors", "et_hugs" )) ) err = "\"We're not that close,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } } else if ( matchwd( verb, "hail" ) ) { if ( !(err = GetTextFromIndexO( ref1, "et_hails" )) && !(err = GetTextFromIndex( "e_errors", "et_hails" )) ) err = "^ does not respond to ^'s hail.\n"; WriteString( err, cap(ref1->name(def)), prime->name(def) ); Absorb( one ); } else if ( matchwd( verb, "insult|scold" ) ) { if ( !(err = GetTextFromIndexO( ref1, "et_insults" )) ) err = GetTextFromIndex( "e_errors", "et_insults" ); if ( ref1->type < animate ) { if ( !err ) err = "\"I don't know if I should do that,\" says ^ dryly." " \"I might hurt ^'s feelings.\"\n"; WriteString( err, prime->name(def), ref1->name(def) ); Absorb( all ); } else { if ( !err ) err = "\"I don't think I need to resort to that,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } } else if ( matchwd( verb, "distract" ) ) { if ( ref1->type >= animate ) { if ( !(err = GetTextFromIndexO( ref1, "et_distracts" )) && !(err = GetTextFromIndex( "e_errors", "et_distracts" )) ) err = "^ draws ^'s attention for a moment.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } } // end section -- no clauses, one visible "who"; } else if ( matchwd( verb, "search|analyse|knock on|feel|smell|hear|taste|read|indicate|" "move|pull|push|turn|examine|open|close|remove|activate|" "deactivate" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( visible, "what" ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( matchwd( verb, "smell" ) ) { if ( !(err = GetTextFromIndexO( ref1, "et_smells" )) && !(err = GetTextFromIndex( "e_errors", "et_smells" )) ) err = "^ sniffs ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "hear" ) ) { if ( !(err = GetTextFromIndexO( ref1, "et_hears" )) && !(err = GetTextFromIndex( "e_errors", "et_hears" )) ) err = "^ listens to ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "taste" ) ) { if ( !(err = GetTextFromIndexO( ref1, "et_tastes" )) ) err = GetTextFromIndex( "e_errors", "et_tastes" ); if ( ref1->type < animate ) { if ( !err ) err = "^ tastes ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else { if ( !err ) err = "\"I don't think so!\"\n"; WriteString( err, ref1->name(def), prime->name(def) ); Absorb( all ); } } else if ( matchwd( verb, "read" ) ) { if ( !(err = GetTextFromIndexO( ref1, "et_reads" )) && !(err = GetTextFromIndex( "e_errors", "et_reads" )) ) err = "\"There is nothing written on ^.\"\n"; WriteString( err, ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "indicate" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_points" )) ) err = "^ points at ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "examine" ) ) { if ( !ref1->Examine( 1 ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_nothing_special" )) ) err = "^ sees nothing special about ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); } Absorb( one ); } else if ( matchwd( verb, "open" ) ) { if ( ref1->state(opened) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_already_open" )) ) err = "\"^ is already open.\"\n"; WriteString( err, cap(ref1->name(def)) ); Absorb( one ); } else if ( ref1->state(closed) ) { ref1->SetState(closed,0); ref1->SetState(opened,1); if ( !(err=GetTextFromIndex( "e_errors", "et_opens" )) ) err = "^ opens ^. "; WriteString( err, cap(prime->name(def)), ref1->name(def) ); status = ref1->DescribeAttached( in ); if ( status & 1 ) { if ( status & 64 ) Blank(); ref1->PrintSlug( in ); } Absorb( one ); } else { if ( !(err=GetTextFromIndex( "e_errors", "et_can't_open_or_close" )) ) err = "[^ can't be opened or closed.]\n"; WriteString( err, cap(ref1->name(def)) ); Absorb( all ); } } else if ( matchwd( verb, "close" ) ) { if ( ref1->state(closed) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_already_closed" )) ) err = "\"^ is already closed.\"\n"; WriteString( err, cap(ref1->name(def)) ); Absorb( one ); } else if ( ref1->state(opened) ) { ref1->SetState(closed,1); ref1->SetState(opened,0); if ( !(err=GetTextFromIndex( "e_errors", "et_closes" )) ) err = "^ closes ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else { if ( !(err=GetTextFromIndex( "e_errors", "et_can't_open_or_close" )) ) err = "[^ can't be opened or closed.]\n"; WriteString( err, cap(ref1->name(def)) ); Absorb( all ); } } else if ( matchwd( verb, "remove" ) ) { if ( !ref1->state(worn) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_not_wearing" )) ) err = "\"I'm not wearing ^.\"\n"; WriteString( err, ref1->name(def) ); Absorb( all ); } else { ref1->SetState(worn,0); ref1->SetState(wearable,1); if ( !(err=GetTextFromIndex( "e_errors", "et_removes" )) ) err = "^ takes off ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } } else if ( matchwd( verb, "activate|deactivate" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_de/activates" )) ) err = "[^ can't be turned on or off.]\n"; WriteString( err, cap(ref1->name(def)) ); Absorb( all ); } else if ( matchwd( verb, "search|analyse|feel|knock on|move|pull||push|turn" ) ) { if ( !RequireInert( obj ) ) return; if ( matchwd( verb, "search|analyse" ) ) { if ( !(err = GetTextFromIndexO( ref1, "et_searches" )) && !(err = GetTextFromIndex( "e_errors", "et_searches" )) ) err = "^ finds nothing of interest.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } else if ( matchwd( verb, "knock on" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_knocks" )) ) err = "^ raps on ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "feel" ) ) { if ( !(err = GetTextFromIndexO( ref1, "et_feels" )) && !(err = GetTextFromIndex( "e_errors", "et_feels" )) ) err = "^ touches ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "move|pull|push|turn" ) ) { if (!RequireGettable( obj ) ) { Absorb( all ); } else if ( !RequireWeightFactor( obj, 10, "move" ) ) { Absorb( all ); } else { if ( !(err = GetTextFromIndexO( ref1, "et_moves" )) && !(err = GetTextFromIndex( "e_errors", "et_moves" )) ) err = "^ shifts the position of ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } } // end section -- "don't annoy" } // end section -- no clauses, one visible "what"; } else if ( matchwd( verb, "wear" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireObj( visible_in_prime, "what" ) ) return; if ( ref1->state(worn) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_already_worn" )) ) err = "\"I'm already wearing ^.\"\n"; WriteString( err, ref1->name(def) ); Absorb( one ); } else if ( ref1->state(wearable) ) { ref1->SetState(worn,1); ref1->SetState(wearable,0); if ( !(err=GetTextFromIndex( "e_errors", "et_wears" )) ) err = "^ puts on ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else { if ( !(err=GetTextFromIndex( "e_errors", "et_can't_be_worn" )) ) err = "[^ can't be worn.]\n"; WriteString( err, cap(ref1->name(def)) ); Absorb( all ); } } else if ( matchwd( verb, "shake|drop|enter|throw|eat|bit|drink|consume" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireNoSelf( obj ) ) return; if ( !RequireObj( can_drop_in_prime, "what" ) ) return; if ( matchwd( verb, "eat|bite|drink|consume" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_consumes" )) ) err = "\"Yeah, right,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( matchwd( verb, "throw" ) ) { ref1->Put(in,loc); if ( !(err = GetTextFromIndex( "e_errors", "et_throws" )) ) err = "^ throws ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "enter" ) ) { Absorb( one ); PushCmd( "go in ^", ref1 ); } else if ( matchwd( verb, "drop" ) ) { ref1->Put(in,loc); if ( !(err=GetTextFromIndex( "e_errors", "et_drops" )) ) err = "^ drops ^.\n"; WriteString( err, cap(prime->Name(def)), ref1->name(def) ); Absorb( one ); } else if ( matchwd( verb, "shake" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_shakes" )) ) err = "^ shakes ^.\n"; WriteString( err, cap(prime->name(def)), ref1->name(def) ); Absorb( one ); } // end section -- no clauses, one visible-in-prime "what" } else if ( matchwd( verb, "flee|lie|sit|stand|alight|wait|stay" ) ) { if ( !ClausesCantExceed( 0 ) ) return; if ( !RequireObj( empty, NULL ) ) return; if ( matchwd( verb, "flee" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_flees" )) ) err = "[Try ordering ^ to go in a specific direction.]\n"; WriteString( err, prime->name(def) ); Absorb( all ); } else if ( matchwd( verb, "lie" ) ) { if ( prime->posture == lying ) { if ( !(err=GetTextFromIndex( "e_errors", "et_already_lying" )) ) err = "\"I'm already lying down,\" says ^.\n"; WriteString( err, prime->name(def) ); } else { prime->PostureTo( lying ); if ( !(err=GetTextFromIndex( "e_errors", "et_lies" )) ) err = "^ lies down."; WriteString( err, cap(prime->name(def)) ); Blank(); } Absorb( one ); } else if ( matchwd( verb, "sit" ) ) { if ( prime->posture == sitting ) { if ( !(err=GetTextFromIndex( "e_errors", "et_already_sitting" )) ) err = "\"I'm already sitting,\" says ^.\n"; WriteString( err, prime->name(def) ); } else { prime->PostureTo( sitting ); if ( !(err=GetTextFromIndex( "e_errors", "et_sits" )) ) err = "^ sits."; WriteString( err, cap(prime->name(def)) ); Blank(); } Absorb( one ); } else if ( matchwd( verb, "stand" ) ) { if ( loc->state(spaceunder) && loc->owner ) { prime->Put(in,loc->owner); } else if ( prime->posture == standing ) { if ( !(err=GetTextFromIndex( "e_errors", "et_already_standing" )) ) err = "\"I'm already standing,\" says ^.\n"; WriteString( err, prime->name(def) ); Absorb( one ); } else { prime->PostureTo( standing ); prime->OnLocTo( NULL ); if ( !(err=GetTextFromIndex( "e_errors", "et_stands" )) ) err = "^ gets up.\n"; WriteString( err, cap(prime->name(def)) ); Blank(); Absorb( one ); } } else if ( matchwd( verb, "alight" ) ) { if ( !prime->onloc ) { if ( !(err=GetTextFromIndex( "e_errors", "et_not_in/on/under" )) ) err = "\"I'm not ^ ^^,\" says ^.\n"; WriteString( err, "on", "anything", "", prime->name(def) ); Blank(); Absorb( all ); } else { prime->PostureTo( standing ); prime->OnLocTo( NULL ); if ( !(err=GetTextFromIndex( "e_errors", "et_alights" )) ) err = "^ alights.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); } } else if ( matchwd( verb, "wait" ) ) { if ( !(err=GetTextFromIndex( "e_errors", "et_waits" )) ) err = "^ waits for about half a minute.\n"; WriteString( err, cap(prime->name(def)) ); TimeTo( time + INTERVAL ); gCommander->Kill( one ); Blank(); FullConsultation(); Blank(); } else if ( matchwd( verb, "stay" ) ) { prime->StayPut(); if ( !(err=GetTextFromIndex( "e_errors", "et_ok" )) ) err = "\"Alright.\"\n"; WriteString( err ); Absorb( one ); } // end section -- one word commands; } // end of matching; if ( gCommander->CommandLive() ) { if ( !(err=GetTextFromIndex( "e_errors", "et_nonsense" )) ) err = "\"Care to rephrase that so I can understand it?\" snorts ^.\n"; WriteString( err, prime->name(def) ); Absorb( all ); } } /* cintrfcr.c */ #include "includes.h" #define DEBUG 1 #ifdef MAC_1 #include #include #elif MAC_2 #include #elif DOS_1 #include #include #define normal BLACK * 16 | LIGHTGRAY #endif CInterfacer::CInterfacer( void ) { #ifdef MAC_2 InitMacintosh(); SetUpMenus(); #endif Initialise(); CreateEnvironment(); } void CInterfacer::Initialise( void ) { int i; // Initialise variables: strcpy( typing, "[Please wait.]" ); waitingForMore = 1; virginLines = 0; strcpy( statusLine, "Envision this..."); strcpy( timeLine, "12:00 am" ); timeActive = 0; timeLogged = INITIALTIME; lastTimeLogged = (INITIALTIME/60) - 1; statusChanged = 0; oldPrime = oldPrimeLoc = NULL; caretPos = 2; } void CInterfacer::CreateEnvironment( void ) { #ifdef MAC_1 // o console options: console_options.title = "\pTesting Testing"; csetmode( C_RAW, stdin ); cinverse( TRUE, stdout ); #elif MAC_2 textWindow = new ETWindow; pageLength = textWindow->GetNumberOfLines(); #elif DOS_1 textmode(BW80); clrscr(); window( 4, 3, PAGEWIDTH+4, pageLength+2 ); gotoxy( 1, 1 ); textattr(normal); clrscr(); #endif UpdateStatus(); UpdateTyping(); ChangeTyping( "[MORE]" ); } void CInterfacer::DestroyEnvironment( void ) { Initialise(); // Clear the display: #ifdef MAC_1 cgotoxy( 1, 1, stdout ); ccleos( stdout ); #elif MAC_2 delete textWindow; #elif DOS_1 clrscr(); #endif } void CInterfacer::UpdateStatus( void ) { if ( ! statusChanged ) return; // Print the status line: #ifdef MAC_1 cgotoxy( 1, 1, stdout ); ccleol(stdout); printf( "%s\n", statusLine ); ccleol(stdout); #elif MAC_2 textWindow->ClearStatus(); textWindow->InscribeStatus( statusLine ); #elif DOS_1 gotoxy( 1, 1 ); highvideo(); clreol(); cprintf( statusLine ); lowvideo(); gotoxy( caretPos, pageLength ); #endif lastTimeLogged = -1; UpdateTime(); statusChanged = 0; } void CInterfacer::UpdateTime( void ) { char *c; long int t; if ( ! timeActive ) { textWindow->ClearTime(); return; } if ( timeLogged / 60 > lastTimeLogged ) { lastTimeLogged = timeLogged / 60; sprintf( timeLine, "%2ld%c%02ld %s", (t=(timeLogged/3600)%12) ? t : 12, timeLogged % 2 ? ' ' : ':', lastTimeLogged % 60, (timeLogged % 86400 < 43200) ? "am" : "pm" ); #ifdef MAC_1 cgotoxy( PAGEWIDTH-8, 1, stdout ); printf( timeLine ); #elif MAC_2 textWindow->ClearTime(); textWindow->InscribeTime( timeLine ); if ( timeLogged % 2 ) textWindow->FlashColon(); #elif DOS_1 gotoxy( PAGEWIDTH-8, 1 ); highvideo(); cprintf( tim ); lowvideo(); gotoxy( caretPos, pageLength ); #endif } else { #ifdef MAC_1 cgotoxy ( PAGEWIDTH-6, 1, stdout ); if ( timeLogged % 2 ) putchar( ' ' ); else putchar( ':' ); #elif MAC_2 textWindow->FlashColon(); #elif DOS_1 gotoxy( PAGEWIDTH-6, 1 ); highvideo(); if ( timeLogged % 2 ) putch( ' ' ); else putch( ':' ); lowvideo(); gotoxy( caretPos, pageLength ); #endif } } void CInterfacer::UpdateTyping( void ) { #ifdef MAC_1 cgotoxy( 1, pageLength, stdout ); ccleol( stdout ); printf( typing ); putchar( ' ' | 0x80 ); #elif MAC_2 int i; textWindow->ClearTyping(); textWindow->InscribeTyping( typing ); #elif DOS_1 gotoxy( 1, pageLength ); clreol(); cprintf( typing ); #endif } void CInterfacer::UpdateEnvironment( void ) { int i; STORY *line; #ifdef MAC_2 line = gScriptor->screenTopLine; i = 2; while ( line && i<(pageLength-1) ) { textWindow->Inscribe( line->text, i ); line = line->next; i++; } #endif statusChanged = 1; UpdateStatus(); UpdateTyping(); } void CInterfacer::CheckPrime( void ) { c_interpreter *nextMember; if ( oldPrimeLoc != gInterpreter->PrimeLoc() ) { oldPrime = gInterpreter->Prime(); oldPrimeLoc = gInterpreter->PrimeLoc(); oldPrimeLoc->Describe(); for (nextMember=oldPrimeLoc->In(); nextMember; nextMember=nextMember->Beside() ) { if ( nextMember != oldPrime && nextMember->BecomePrime() ) gInterpreter->PrimeLoc()->FakeDescribe(); } oldPrime->BecomePrime(); } } void CInterfacer::CheckQueues( void ) { STORY *line, *prev; char *c; clock_t tickTrigger; // Scroll more text if there is any: if ( waitingForMore ) { #ifdef MAC_1 cgotoxy( 1, pageLength, stdout ); ccleol( stdout ); #elif MAC_2 textWindow->ClearTyping(); #elif DOS_1 window( 4, 5, PAGEWIDTH+4, pageLength+2 ); gotoxy( 1, pageLength - 1 ); clreol(); #endif if ( prev = gScriptor->GetUnreadLines( pageLength - virginLines - 4 ) ) { line = prev->next; tickTrigger = clock(); while ( line ) { while ( clock() < tickTrigger ); tickTrigger = clock() + CLOCKS_PER_SEC/15; if ( line->text[0] == '}' ) { if (c=strchr( line->text, '\n' )) *c = '\0'; PlaySnd( line->text + 1 ); prev->next = line->next; line->next = gScriptor->firstFreeLine; gScriptor->firstFreeLine = line; line = prev->next; continue; } #ifdef MAC_1 if ( line->text[0] != '>' ) { printf( line->text ); if (*(strchr( line->text, '\0' ) - 1) != '\n') printf( "\n" ); } #elif MAC_2 if ( line->text[0] != '>' ) { textWindow->Inscribe( line->text, pageLength - 1 ); textWindow->Scroll(); } #elif DOS_1 if ( line->text[0] != '>' ) { cprintf( line->text ); if (strchr(line->text, '\n')) cprintf( "\r" ); else cprintf( "\n\r" ); } #endif virginLines++; prev = line; line = line->next; } } if ( gScriptor->firstStackLine ) ChangeTyping( "[MORE]" ); else waitingForMore = 0; #ifdef DOS_1 window( 4, 3, PAGEWIDTH+4, pageLength+2 ); gotoxy( caretPos, pageLength ); #endif } // If all text is now scrolled, execute the next waiting command: if ( ! waitingForMore && gCommander->PopCommand(1) ) { if ( gCommander->Parse() ) { gInterpreter->FullConsultation(); } else { gCommander->Kill( one ); } CheckPrime(); if ( gScriptor->firstStackLine ) { if ( !gCommander->PopCommand(0) ) gScriptor->EnsureBlank(); waitingForMore = 1; } CheckQueues(); return; } // If the function gets this far, there's no more to do, clean things up: gCommander->Kill( one ); virginLines = 0; } void CInterfacer::ChangeStatus( const char *status ) { if ( status ) { strcpy( statusLine, status ); } else { sprintf( statusLine, "%s: %s", gInterpreter->Prime()->Name(alone), cap(gInterpreter->PrimeLoc()->Name(def)) ); } statusLine[PAGEWIDTH - 15] = '\0'; statusChanged = 1; } void CInterfacer::ChangeTyping( const char *command ) { strcpy( typing, command ); caretPos = strlen( typing ) + 1; } long int CInterfacer::TimeLogged( void ) { return timeLogged; } char *CInterfacer::TimeLoggedF( void ) { long int t; sprintf( timeLine, "%2ld:%02ld %s", (t=(timeLogged/3600)%12) ? t : 12, lastTimeLogged % 60, (timeLogged % 86400 < 43200) ? "am" : "pm" ); } void CInterfacer::SetTimeLoggedTo( long int seconds ) { timeLogged = seconds; } char CInterfacer::ProcessChar( char letter ) { if ( strchr( "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "1234567890" "!@#$&()_+-=[]{};':\",./<>?~ ", letter ) ) { if ( waitingForMore ) return 0; if ( caretPos == PAGEWIDTH || caretPos == 82 ) return 0; #ifdef MAC_1 typing[caretPos-1] = letter; typing[caretPos] = '\0'; cgotoxy( caretPos, pageLength, stdout ); putchar( letter ); putchar( ' ' | 0x80 ); #elif MAC_2 if ( !textWindow->AddChar( letter ) ) return 0; typing[caretPos-1] = letter; typing[caretPos] = '\0'; #elif DOS_1 if ( letter == '\0' ) { getinput(); return 0; } gotoxy( caretPos, pageLength ); putch( letter ); #endif caretPos++; return 1; } else if ( letter == '\b' ) { if ( waitingForMore ) return 0; if ( caretPos == 2 ) return 0; typing[caretPos-2] = '\0'; caretPos--; #ifdef MAC_1 cgotoxy( caretPos, pageLength, stdout ); putchar( ' ' | 0x80 ); putchar( ' ' ); #elif MAC_2 textWindow->RemoveChar(); #elif DOS_1 gotoxy( caretPos, pageLength ); putch( ' ' ); gotoxy( caretPos, pageLength ); #endif return 1; } else if ( letter == '\r' ) { if ( ! waitingForMore ) { #ifdef MAC_1 cgotoxy( caretPos, pageLength, stdout ); printf( " \n" ); #elif MAC_2 textWindow->EraseCaret(); textWindow->Scroll(); #elif DOS_1 window( 4, 5, PAGEWIDTH+4, pageLength+2 ); gotoxy( caretPos, pageLength - 1 ); cprintf( "\r\n" ); window( 4, 3, PAGEWIDTH+4, pageLength+2 ); gotoxy( 1, pageLength ); #endif gScriptor->WriteString( "^\n", typing ); gCommander->SetCommandTo( typing + 1 ); if ( gCommander->Parse() ) { gInterpreter->FullConsultation(); } else { gCommander->Kill( one ); } CheckPrime(); if ( gScriptor->firstStackLine ) { if ( ! gCommander->PopCommand(0) ) gScriptor->EnsureBlank(); waitingForMore = 1; } } CheckQueues(); if ( ! waitingForMore ) { ChangeStatus( NULL ); ChangeTyping( ">" ); } UpdateEnvironment(); return 1; } else if ( letter == 27 ) { #ifdef MAC_1 #ifdef DEBUG DebugStr( "\pProgram interrupted by user." ); #endif #elif MAC_2 #ifdef DEBUG DebugStr( "\pProgram interrupted by user." ); #endif #endif return 0; // This is provided as a possible breakpoint position; } return 0; } char CInterfacer::TimeChanged( long int secondsDelta ) { timeLogged = timeLogged + secondsDelta; UpdateTime(); if ( !(timeLogged % INTERVAL) ) { gInterpreter->FullConsultation(); CheckPrime(); if ( gScriptor->firstStackLine ) { gScriptor->EnsureBlank(); waitingForMore = 1; // ChangeTyping( ">" ); CheckQueues(); if ( ! waitingForMore ) ChangeStatus( NULL ); } UpdateEnvironment(); return 1; } return 0; } void CInterfacer::PrintErr( enum errstate seriousness, char *message ) { char input; Debugger(); #ifdef MAC_1 printf( "\n%s", message ); if (seriousness == FATAL) while (1) { printf( "" ); } #elif MAC_2 textWindow->Clear(); textWindow->Inscribe( message, 2 ); if (seriousness == FATAL) while (1) { HandleEvent(); } #elif DOS_1 textattr( normal ); cprintf( "\r\n%s", message ); if (seriousness == FATAL) while (1) { cprintf( "" ); } #endif } int CInterfacer::TextBreak( const char *text, const char *line ) { int spacesAvailable, charsWaiting, charsToGrab, c; #ifdef MAC_2 int i, widthAvailable = 0; extern int lineWidth; #endif if ( line ) { if ( strchr( line, '\n' ) ) return 0; spacesAvailable = PAGEWIDTH - strlen( line ); #ifdef MAC_2 widthAvailable = lineWidth - TextWidth( line, 0, strlen( line ) ); #endif } else { spacesAvailable = PAGEWIDTH; #ifdef MAC_2 widthAvailable = lineWidth; #endif } charsWaiting = strcspn( text, "\n" ); c = charsToGrab = (charsWaiting > spacesAvailable) ? spacesAvailable : charsWaiting; #ifdef MAC_2 MeasureText( c, text, charBreaks ); for (i=0;i widthAvailable ) { c = charsToGrab = i-1; break; } #endif if ( text[c] != '\n' && text[c] != '\0' ) while ( c && text[c-1] != ' ' && text[c-1] != '-' ) c--; if ( !c && spacesAvailable == PAGEWIDTH ) return charsToGrab; else return c; } char CInterfacer::PlaySnd( const char *snd ) { #ifdef MAC_1 Handle sound; char psnd[128] = ""; strncat( psnd, snd, 127 ); sound = GetNamedResource('snd ', CtoPstr(psnd) ); if (sound) { SndPlay( NULL, sound, 0); return 1; } return 0; #elif MAC_2 Handle sound; char psnd[128] = ""; strncat( psnd, snd, 127 ); sound = GetNamedResource('snd ', CtoPstr(psnd) ); if (sound) { SndPlay( NULL, sound, 0); return 1; } return 0; #elif DOS_1 return 0; #endif } void CInterfacer::Beep( void ) { #ifdef MAC_1 if ( ! PlaySnd( "etbeep" ) ) SysBeep( 15 ); #elif MAC_2 if ( ! PlaySnd( "etbeep" ) ) SysBeep( 15 ); #elif DOS_1 sound( 500 ); delay( 100 ); nosound(); #endif } char CInterfacer::getinput( void ) { #ifdef MAC_1 return getchar(); #elif MAC_2 return HandleEvent(); #elif DOS_1 if (!kbhit()) return EOF; else return getch(); #endif } void CInterfacer::ActivateTime( void ) { timeActive = 1; lastTimeLogged = -1; } void CInterfacer::DeactivateTime( void ) { timeActive = 0; lastTimeLogged = -1; } void CInterfacer::FontChange( void ) { pageLength = textWindow->GetNumberOfLines(); gScriptor->RebuildPage(); gScriptor->WriteString( "[Font changed.]\n\n" ); ChangeTyping( ">" ); ChangeStatus( NULL ); waitingForMore = 1; textWindow->Draw(); CheckQueues(); } char CInterfacer::WaitingForMore( void ) { return waitingForMore; } /* grequire.c */ #include "includes.h" #include "shortcut.h" char *err; /* Prototype: if ( !(err = GetTextFromIndexO( ref1, "et_searches" )) && !(err = GetTextFromIndex( "e_errors", "et_searches" )) ) err = "^ finds nothing of interest.\n"; WriteString( err, cap(prime->name(def)) ); Absorb( one ); */ char CGlobalInterpreter::RequireNoSelf( WORD word ) { if ( i(word) != prime ) { return 1; } else { if ( !(err = GetTextFromIndex( "e_errors", "et_no_self" )) ) err = "\"I can't ^^^^ myself,\" says ^.\n"; WriteString( err, u(verb), word == indo1 && u(obj) ? " anything" : "", word == indo1 ? " " : "", word == indo1 ? u(prep1) : "", prime->name(def) ); Absorb( all ); return 0; } } char CGlobalInterpreter::RequireGettable( WORD word ) { if ( !i(word) || i(word)->gettable ) { return 1; } else { if ( !(err=GetTextFromIndex( "e_errors", "et_can't_move" )) ) err = "\"It looks like ^ can't be moved,\" says ^.\n"; WriteString( err, i(word)->name(def), prime->name(def) ); Absorb( one ); return 0; } } char CGlobalInterpreter::RequireInert( WORD word ) { if ( !i(word) || i(word)->type < animate ) { return 1; } else { if ( !(err=GetTextFromIndex( "e_errors", "et_don't_annoy" )) ) err = "\"I see no reason to annoy ^,\" says ^.\n"; WriteString( err, i(word)->name(def), prime->name(def) ); Absorb( all ); return 0; } } char CGlobalInterpreter::RequireWeightFactor(WORD word,char f,char *action) { if ( !i(word) || (i(word)->wt + i(word)->Weight(in)) <= (f*prime->incap) ) { return 1; } else { if ( !(err=GetTextFromIndexO( i(word), "et_too_heavy" )) && !(err=GetTextFromIndex( "e_errors", "et_too_heavy" )) ) err = "\"^ looks too heavy for me to ^,\" says ^.\n"; WriteString( err, cap(i(word)->name(def)), action, prime->name(def) ); Absorb( one ); return 0; } } /* utils.c */ #include "includes.h" int randomof( int max ) // returns a number from 0 to max; { return (int) ( ( rand() / (double) RAND_MAX ) * max ); } int wordsortcmp( const void *datum1, const void *datum2 ) { return strcmp( ( (THESSYN *) datum1 )->word, ( (THESSYN *) datum2 )->word ); } int wordcmp( const void *keyval, const void *datum ) { return strcmp( (char *) keyval, ( (THESSYN *) datum )->word ); } int fxcmp( const void *key, const void *data ) { return strcmp ( (char *)key, ((EFFECT *)data)->name ); } char *cap( const char *text ) { static char ctext[81]; strcpy( ctext, text ); *ctext = toupper( *ctext ); return ctext; } void decode( char *cypher, char coding ) { char *c; if ( coding == 'C' ) { for (c = cypher; *c != '\0'; c++) { switch ( *c ) { case 13: *c = '\n'; case -14: break; default: *c = ~(*c); break; } } } else { for (c = cypher; *c != '\0'; c++) if (*c == 13) *c = '\n'; } } /* globals.c */ #include "includes.h" clock_t cycles; CInterfacer *gInterfacer; CCommander *gCommander; CScriptor *gScriptor; CGlobalInterpreter *gInterpreter; int pageLength = PAGELENGTH; char cardinals[] = "n ne e se s sw w nw u d "; char longcardinals[10][10] = { "north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest", "up", "down" }; /* main.c */ #include "includes.h" char quitting_time = 0; main() { char c; clock_t tickTrigger, ticksPassed; gInterfacer = new CInterfacer; gCommander = new CCommander; gInterpreter = new CGlobalInterpreter; gInterpreter->Initialise(); gScriptor = new CScriptor; gInterfacer->CheckPrime(); gScriptor->EnsureBlank(); tickTrigger = clock() + CLOCKS_PER_SEC; while ( !quitting_time ) { c = gInterfacer->getinput(); if ( c != EOF ) { if ( !gInterfacer->ProcessChar( c ) ) gInterfacer->Beep(); } else if ( clock() > tickTrigger ) { ticksPassed = clock() - tickTrigger + CLOCKS_PER_SEC; if (!gInterfacer->WaitingForMore()) gInterfacer->TimeChanged( (long int) (ticksPassed / CLOCKS_PER_SEC) ); tickTrigger = clock() + CLOCKS_PER_SEC; } } } /* cscriptr.h */ typedef struct story { struct story *next; char text[PAGEWIDTH+3]; } STORY; typedef struct { char name[14]; int next; int currentSpot; int textLength; // including NULL int duration; char randomise; char written; // boolean fpos_t filePtr; } EFFECT; class CScriptor : private CThing { /* Variables */ public: STORY *screenTopLine, *screenBotLine, *firstStackLine, *lastStackLine, *firstFreeLine; char words[15000], junk[1000]; char wordEffect[14]; private: EFFECT effect[FXTALLY]; FILE *fxStream; char coding; /* Functions */ void Load( EFFECT *fxPtr ); char FreeLines( int lineCount ); STORY *NewLine( void ); STORY *PrintLines( STORY *oldLine, char *text ); public: CScriptor( void ); // Constructor virtual ~CScriptor( void ); // Deconstructor void RebuildPage( void ); void DoSave( FILE *savestream ); void DoOpen( FILE *openstream ); STORY *GetUnreadLines( int maxLines ); void SetNextOf( const char *event, const char *next ); char WrittenOf( const char *event ); void SetWrittenOf( const char *event, char newWritten ); int DurationOf( const char *event ); void SetDurationOf( const char *event, int duration ); EFFECT *LookUp( const char *event ); void WriteString( char *text, ... ); char Write( char *event, ... ); char WriteOnce( char *event ); char WriteFromIndex( char *event, char *key ); char *GetText( char *event ); char *GetTextFromIndex( char *event, char *key ); char *GetTextFromIndexO( c_interpreter *object, char *index ); void FakeWrite( char *event ); void EnsureBlank( void ); }; /* ccmdr.h */ #include "thes.h" /* #define STALLY xxxx #define WTALLY yyy */ typedef enum { CLASS_OK = 0, GENERIC_FLAW, DO_AGAIN, TOO_MANY_OOPS, MOD_TOO_LONG, CORRECTION_REQ, CLARIFICATION_REQ, REPEAT_MISTAKE } CLASSERROR; typedef enum { GRAMMAR_OK = 0, TOO_COMPLEX, BAD_ORDER, MISPLACED_ALL, SKIP } GRAMMARERROR; typedef enum { ET_UNNECESSARIES, ET_SUGGEST_GET_OUT, ET_ITEM_NOT_HERE, ET_SUGGEST_DROP, ET_SUGGEST_GET, ET_SUGGEST_REMOVE } REQERROR; typedef enum { one, all } ABSORBTYPE; typedef enum { empty, full, visible, can_get, visible_in_loc, visible_in_prime, can_get_in_loc, can_get_in_prime, can_drop_in_prime, anything = INT_MAX } REQUIREMENT; typedef enum { actor, verb, obj, prep1, indo1, prep2, indo2, temporary, internal = INT_MAX } WORD; typedef struct { char *word; int tWord; } THESSYN; typedef struct { char PoS; char *word; char id[9]; int alternate; } THESWORD; typedef struct { char *start; // pointer to starting char of word; int tWord; // thesaurus translation match; char code; /* T thesaurus translation matched & conjunction word ? unknown word \0 there are no more words */ } INPUTWORD; typedef struct { char *start; int tWord; // 0 if it's a quotation; c_interpreter *i; // NULL if none found; } PARSEDWORD; typedef struct { char text[256]; } COMMANDQ; class CCommander : private CThing { /* Variables */ THESSYN tSynonym[STALLY+1]; THESSYN lSynonym[50]; int tIndex[26]; THESWORD tWord[WTALLY+1]; COMMANDQ commandQ[101], liveCommand, againCommand; char roughWork[512]; char nextCommand; /* commandQ[0] is for commands awaiting correction; commandQ[1] is for the current command; waiting commands are built from [100] up; waiting commands are executed from nextCommand down; */ struct { char *part1; char *wrong; char *part2; } wrongSentence; INPUTWORD inputWord[100]; PARSEDWORD parsed[8]; char commandReady; // Boolean Ñ a command has been entered; char commandLive; // Boolean - that command has not been absorbed; char allInProgress; // Boolean - an "all" has not finished running; int lastNoun, lastCreature; // tWord subscripts -- 0 if there are none; char rudeness, politeness; // Boolean; char commandNeedsCorrection; // Boolean; char suggestionWaiting; // Boolean; int vagueObject; // tWord subscript; /* Functions */ int CheckThesaurus( char *word ); void Place( PARSEDWORD *pPtr, INPUTWORD *iPtr ); CLASSERROR ConsultClassifier( void ); GRAMMARERROR ConsultGrammarian( void ); char ConsultPreInterpreter( void ); void SwapPrepositions( void ); char SubMatch( char *cPtr, PARSEDWORD *parsedword ); void KickCommand( WORD p, char *kicker, char *begin, char *end ); void DoError( WORD noun, REQERROR reqerr ); char RequireNoun( WORD noun, REQUIREMENT req, char *begin, char *end ); public: CCommander( void ); // Constructor virtual ~CCommander( void ); // Deconstructor void MoveWord( WORD source, WORD destination ); void ClearWord( WORD word ); char MatchWord( WORD word, char *matchString, ... ); char Match( const char *matchString ); // returns non-zero if it's a match void Absorb( ABSORBTYPE atype ); void Kill( ABSORBTYPE atype ); char Parse( void ); /* Consults Classifier, Grammarian, and PreInterpreter. Returns non-zero if it's a good parse. */ void SetCommandTo( const char *command ); // only works if the command if not ready char PopCommand( char x ); /* Pushes the popped command into the input line. If x == 0 just return whether there is a waiting command. */ char PushCommand( char *text, ... ); /* Pushes command[] onto the list of waiting command. */ void SuggestCommand( char *text, ... ); /* Sets a command to be approved by a simple "OK". */ char RequireObj( REQUIREMENT req, char *begin ); char ClausesCantExceed( char max ); char RequireClause( char *plist, REQUIREMENT req, char *begin, char *end ); /* RequireObj, ClausesCannotExceed, & RequireClause return 0 and absorb the command if the requirements are not met. - plist is in the form "with|about|of" - message might be: " do you want me the ?" */ char *Parsed( WORD ); char *Untranslated( WORD ); char *Translated( WORD ); c_interpreter *Interpreter( WORD ); char *Thes( c_interpreter * ); char CommandReady( void ); char CommandLive( void ); char AllInProgress( void ); char Rudeness( void ); char Politeness( void ); }; /* cgintrpr.h */ class CGlobalInterpreter : public CThing { /* Variables */ c_interpreter *interpreter[INTALLY]; c_interpreter *primeInterpreter; c_animate *firstWanderer; char act, scene; /* Functions */ public: CGlobalInterpreter( void ); // Constructor Ñ only loads file once // virtual ~CGlobalInterpreter( void ); // Destructor void Initialise( void ); void Interpret( void ); /* The standard Get/Drop/Put stuff herein contained. */ char Snapshot( const char *filename ); char ReplayFrom( const char *filename ); void DoSave( FILE *savestream ); void DoOpen( FILE *openstream ); void FullConsultation( void ); char Act( void ); void SetActTo( char ); char Scene( void ); void SetSceneTo( char ); void SetPrimeTo( c_interpreter *newPrime ); void SetPrimeLocTo( c_interpreter *newLoc ); c_interpreter *Prime( void ); c_interpreter *PrimeLoc( void ); c_interpreter *InterpreterID( char *id ); c_interpreter *Interpreter( int number ); c_animate *FirstWanderer( void ); void SetFirstWandererTo( c_animate * ); char RequireNoSelf( WORD ); char RequireGettable( WORD ); char RequireInert( WORD ); char RequireWeightFactor( WORD, char, char * ); }; /* cintrpr.h */ typedef enum { plain = 0, location = 1, object = 2, animate = 3, sentient = 4, primer = 5 } CLASSID; typedef enum { north = 0, northeast, east, southeast, south, southwest, west, northwest, up, down, N = 0, NE, E, SE, S, SW, W, NW, U, D } CARD; typedef enum { contains = 16384, opened = 8192, closed = 4096, supports = 2048, spaceunder = 1024, wearable = 512, worn = 256, dontlist = 128, dontcall = 64 } MASK; typedef enum { alone, indef, def } ARTICLE; typedef enum { nowhere, in, on, under } POSITION; typedef enum { standing, sitting, lying } POSTURE; class c_interpreter : public CThing { /* Variables */ // Data From Files: char o_id[9]; char o_article[7]; char o_name[38]; int o_weight; int o_inWeight; int o_onWeight; int o_underWeight; int o_inCapacity; int o_onCapacity; int o_underCapacity; char o_gettable; int o_state; // accessed as MASK type long int o_variable; c_interpreter *o_in; c_interpreter *o_on; c_interpreter *o_under; c_interpreter *o_beside; c_interpreter *o_owner; c_interpreter *o_direction[10]; // Runtime Data: c_interpreter *o_alwaysConsult; long int o_consultations; long int o_lastConsultation; // in seconds char o_known; // boolean - has the object ever been named? /* Functions */ public: c_interpreter( void ); // Constructor Ñ initializes variables void Scan( const char *data ); virtual void Interpret( void ); void ListOns( void ); void PrintSlug( POSITION pos ); char DescribeOns( void ); char DescribeAttached( POSITION pos ); void Describe( void ); void FakeDescribeOns( void ); void FakeDescribe( void ); char Examine( char checkContents ); void Consult( void ); /* Checks to make sure this is not prime. Handles the alwaysConsults. */ // Object Attribute Functions: int Weight( POSITION pos ); void ChangeWeightBy( POSITION pos, int deltaWeight ); /* Must call other objects' change-weights in a chain to ensure all owners are updated. */ int Capacity( POSITION pos ); void SetCapacity( POSITION pos, int newCapacity ); char Fits( POSITION pos, c_interpreter *object ); // returns 1 if it fits char Gettable( void ); void SetGettableTo( char ); char State( MASK theState ); void SetState( MASK theState, char ); long int Variable( void ); void SetVariableTo( long int newVariable ); virtual CLASSID ClassID( void ); virtual char BecomePrime( void ); virtual char Act( void ); virtual char TieToAct( char ); virtual void PutFollowedIn( c_interpreter *object ); virtual char Follow( c_interpreter *target ); virtual void LoseFollowers( void ); virtual char ListFollowers( char ); virtual void Wander( void ); virtual void StayPut( void ); virtual void SetAction( int, char *, char, c_interpreter * ); virtual void SetAskTo( char * ); virtual void SetTellTo( char * ); virtual void SetShowTo( char * ); virtual char *GetAsk( void ); virtual char *GetTell( void ); virtual char *GetShow( void ); virtual void SetOnLocTo( c_interpreter *newOn ); virtual void SetPostureTo( POSTURE newPosture ); virtual c_interpreter *OnLoc( void ); virtual POSTURE Posture( void ); // Object Linking Functions: char Sits( POSITION pos, c_interpreter *object ); // returns 1 if found void Put( POSITION pos, c_interpreter *object ); c_interpreter *Owner( void ); void SetOwnerTo( c_interpreter *object ); void Detach( void ); // calls ChangeWeightBy char Exists( POSITION pos, c_interpreter *object ); /* Searches infinitely in, on, and under. */ char CanBeSeen( POSITION pos, c_interpreter *object ); char CanBeGot( POSITION pos, c_interpreter *object ); char CanBeHeard( POSITION pos, c_interpreter *object ); POSITION Position( void ); c_interpreter *Direction( CARD theDirection ); void SetDirection( CARD theDirection, c_interpreter *destination ); c_interpreter *In( void ); c_interpreter *On( void ); c_interpreter *Under( void ); c_interpreter *Beside( void ); void SetInTo( c_interpreter *newIn ); void SetOnTo( c_interpreter *newOn ); void SetUnderTo( c_interpreter *newUnder ); void SetBesideTo( c_interpreter *newBeside ); // Object String Functions: char *Id( void ); char *Name( ARTICLE art ); char *Article( ARTICLE art ); void SetNameTo( char *newName ); void SetArticleTo( char *newArticle); // Object Consultation Functions: long int Consultations( void ); // returns total long int LastConsultation( void ); // returns game time c_interpreter *AlwaysConsult( void ); void SetAlwaysConsultTo( c_interpreter *object ); char Known( void ); void SetKnownTo( char ); }; class c_object : public c_interpreter { /* Functions */ public: virtual CLASSID ClassID( void ); }; class c_location : public c_interpreter { /* Functions */ public: virtual CLASSID ClassID( void ); }; class c_animate : public c_interpreter { /* Variables */ struct { char response[14]; // name of response to print when action occurs; char chance; // a percentage chance, from 0 to 100; c_interpreter *trigger; // what must be in the room to trigger action; } action[16]; c_animate *nextWanderer; /* Functions */ public: c_animate( void ); virtual CLASSID ClassID( void ); virtual void Interpret( void ); virtual void SetAction( int, char *, char, c_interpreter * ); c_animate *NextWanderer( void ); void SetNextWandererTo( c_animate * ); virtual void PutFollowedIn( c_interpreter *object ); virtual char Follow( c_interpreter *target ); virtual void LoseFollowers( void ); virtual char ListFollowers( char ); virtual void Wander( void ); virtual void StayPut( void ); }; class c_sentient : public c_animate { /* Variables */ struct { char ask[14]; char tell[14]; char show[14]; } index; /* Functions */ public: c_sentient( void ); // Constructor virtual CLASSID ClassID( void ); virtual void Interpret( void ); virtual void SetAskTo( char * ); virtual void SetTellTo( char * ); virtual void SetShowTo( char * ); virtual char *GetAsk( void ); virtual char *GetTell( void ); virtual char *GetShow( void ); }; class c_prime : public c_sentient { /* Variables */ char act; POSTURE posture; c_interpreter *onInterpreter; /* Functions */ public: c_prime( void ); // Constructor virtual CLASSID ClassID( void ); virtual char BecomePrime( void ); virtual char Act( void ); virtual char TieToAct( char ); virtual void SetOnLocTo( c_interpreter *newOn ); virtual void SetPostureTo( POSTURE newPosture ); virtual c_interpreter *OnLoc( void ); virtual POSTURE Posture( void ); virtual void Interpret( void ); }; /* cintrfcr.h */ #ifdef MAC_2 #include "ETWindow.h" #endif enum errstate { NONFATAL, FATAL }; class CInterfacer : private CThing { /* Variables */ char statusLine[256]; // current state of status line; char statusChanged; char timeLine[10]; // current state of time line; char timeActive; // current activeness of time; char typing[82]; // current state of user character input; int caretPos; // current position of the caret; int virginLines; // number of lines on screen assumed unread; long int timeLogged, lastTimeLogged; // in seconds; public: c_interpreter *oldPrime, *oldPrimeLoc; // last-checked state of these; private: char waitingForMore; // current state of command line; #ifdef MAC_2 short charBreaks[PAGEWIDTH+2]; #endif /* Functions */ void Initialise( void ); void CreateEnvironment( void ); void DestroyEnvironment( void ); void UpdateTime( void ); void UpdateStatus( void ); void UpdateTyping( void ); void CheckQueues( void ); void ChangeStatus( const char *status ); // Standard if NULL; void ChangeTyping( const char *command ); public: void UpdateEnvironment( void ); void CheckPrime( void ); CInterfacer( void ); // Constructor // virtual ~CInterfacer( void ); // Destructor // Interfacing called from main loop: char WaitingForMore( void ); char ProcessChar( char letter ); // funcs of char return zero on failure char TimeChanged( long int secondsDelta ); void FontChange( void ); char DoSave( const char *filename ); char DoSaveAs( const char *filename ); char DoOpen( void ); char DoNew( void ); char DoAbout( void ); void *halloc( size_t size); void Beep( void ); char getinput( void ); // Interfacing called from generic modules: long int TimeLogged( void ); char *TimeLoggedF( void ); void SetTimeLoggedTo( long int seconds ); void ActivateTime( void ); void DeactivateTime( void ); void PrintErr( enum errstate seriousness, char *message ); char PlaySnd( const char *name ); int TextBreak( const char *text, const char *line ); /* returns the number of characters from text which will fit on the end of line for display. If line is NULL ignore it. "\n\0" at the end of a line means it can except more text, "\n\r\0" at the end of a line means it is terminated. */ }; /* umacros.h */ #define gMatch gCommander->Match #define gAbsorb gCommander->Absorb #define gNextOf gScriptor->NextOf #define gSetNextOf gScriptor->SetNextOf #define gWrittenOf gScriptor->WrittenOf #define gSetWrittenOf gScriptor->SetWrittenOf #define gDurationOf gScriptor->DurationOf #define gSetDurationOf gScriptor->SetDurationOf #define gWrite gScriptor->Write #define gWriteLast gScriptor->WriteLast #define gWriteString gScriptor->WriteString #define gTheTime gInterfacer->TheTime #define gSetTheTime gInterfacer->SetTheTime #define gTheAct gInterpreter->TheAct #define gTheScene gInterpreter->TheScene #define gPlot gInterpreter->Plot #define gThePrime gInterpreter->ThePrime #define gThePrimeLoc gInterpreter->ThePrimeLoc #define gTheLastPlotTime gInterpreter->TheLastPlotTime #define gAlwaysDo gInterpreter->AlwaysDo /* shortcut.h */ #define act gInterpreter->Act() #define scene gInterpreter->Scene() #define prime gInterpreter->Prime() #define loc gInterpreter->PrimeLoc() #define ActTo( C ) gInterpreter->SetActTo( C ) #define SceneTo( C ) gInterpreter->SetSceneTo( C ) #define LocTo( OBJ ) gInterpreter->SetPrimeLocTo( OBJ ) #define time gInterfacer->TimeLogged() #define TimeTo( TIME ) gInterfacer->SetTimeLoggedTo( TIME ) #define Play( S ) gInterfacer->PlaySnd( S ) #define ActivateTime() gInterfacer->ActivateTime() #define DeactivateTime() gInterfacer->DeactivateTime() #define cmd gCommander->CommandReady() #define rude gCommander->Rudeness() #define polite gCommander->Politeness() #define interpreter( WORD ) gCommander->Interpreter( WORD ) #define parsed( WORD ) gCommander->Parsed( WORD ) #define untranslated( WORD ) gCommander->Untranslated( WORD ) #define translated( WORD ) gCommander->Translated( WORD ) #define i( WORD ) gCommander->Interpreter( WORD ) #define p( WORD ) gCommander->Parsed( WORD ) #define u( WORD ) gCommander->Untranslated( WORD ) #define t( WORD ) gCommander->Translated( WORD ) #define match( S ) gCommander->Match( S ) #define matchwd( WORD, S ) gCommander->MatchWord( WORD, S ) #define thes( OBJ ) gCommander->Thes( OBJ ) #define ClearWd( WORD ) gCommander->ClearWord( WORD ) #define MoveWd( SWORD, DWORD ) gCommander->MoveWord( SWORD, DWORD ) #define Absorb( E ) gCommander->Absorb( E ) #define PushCmd gCommander->PushCommand #define SuggestCmd gCommander->SuggestCommand #define RequireObj gCommander->RequireObj #define ClausesCantExceed gCommander->ClausesCantExceed #define RequireClause gCommander->RequireClause #define WriteString gScriptor->WriteString #define Write gScriptor->Write #define WriteOnce( S ) gScriptor->WriteOnce( S ) #define WriteFromIndex( S, K ) gScriptor->WriteFromIndex( S, K ) #define GetTextFromIndex( S, K ) gScriptor->GetTextFromIndex( S, K ) #define GetTextFromIndexO( O, K ) gScriptor->GetTextFromIndexO( O, K ) #define FakeWrite( S ) gScriptor->FakeWrite( S ) #define Blank() gScriptor->EnsureBlank() #define wt Weight( nowhere ) #define incap Capacity( in ) #define oncap Capacity( on ) #define undercap Capacity( under ) #define gettable Gettable() #define state State #define var Variable() #define type ClassID() #define owner Owner() #define position Position() #define direction( D ) Direction( D ) #define id Id() #define name( A ) Name( A ) #define article( A ) Article( A ) #define art( A ) Article( A ) #define consultations Consultations() #define lastconsultation LastConsultation() #define alwaysconsult AlwaysConsult() #define known Known() #define fits( E, O ) Fits( E, O ) #define sits( E, O ) Sits( E, O ) #define exists( E, O ) Exists( E, O ) #define canbeseen( E, O ) CanBeSeen( E, O ) #define canbegot( E, O ) CanBeGot( E, O ) #define canbeheard( E, O ) CanBeHeard( E, O ) #define onloc OnLoc() #define posture Posture() #define TieToAct( C ) TieToAct( C ) #define WeightChange( W ) ChangeWeightBy( nowhere, W ) #define IncapTo( W ) SetCapacity( in, W ) #define OncapTo( W ) SetCapacity( on, W ) #define UndercapTo( W ) SetCapacity( under, W ) #define GettableTo( B ) SetGettableTo( B ) #define SetState( E, B ) SetState( E, B ) #define VarTo( V ) SetVariableTo( V ) #define Put( E, O ) Put( E, O ) #define Detach() Detach() #define SetDirection( D, O ) SetDirection( D, O ) #define BecomePrime() BecomePrime() #define NameTo( N ) SetNameTo( N ) #define ArticleTo( A ) SetArticleTo( A ) #define AlwaysconsultTo( O ) SetAlwaysConsultTo( O ) #define KnownTo( K ) SetKnownTo( K ) #define OnLocTo( OBJ ) SetOnLocTo( OBJ ) #define PostureTo( P ) SetPostureTo( P ) /* enviro.h */ #define MAC_2 1 // other platforms might be MAC_2, DOS_1, WIN_1; #ifdef MAC_1 #define PAGELENGTH 25 #define PAGEWIDTH 80 // should not dip below 70 on any platform #elif MAC_2 #define PAGELENGTH 25 #define PAGEWIDTH 160 #elif DOS_1 #define PAGELENGTH 21 #define PAGEWIDTH 74 #endif #define BLOCKSIZE ((size_t) (sizeof(STORY)*(1+15000/sizeof(STORY)))) #define BLOCKLINES ((int) (1+15000/sizeof(STORY))) #define INITIALTIME 0 #define INTERVAL 30 #ifdef MAC_1 #define PATH ":" #elif MAC_2 #define PATH ":" #elif DOS_1 #define PATH "" #endif /* globals.h */ extern clock_t cycles; extern CInterfacer *gInterfacer; extern CCommander *gCommander; extern CScriptor *gScriptor; extern CGlobalInterpreter *gInterpreter; extern int pageLength; extern char cardinals[]; extern char longcardinals[10][10]; /* utils.h */ char *nexttoken( char **ptr ); void decode( char *cypher, char coding ); int randomof( int max ); int wordsortcmp( const void *datum1, const void *datum2 ); int wordcmp( const void *keyval, const void *datum ); int fxcmp( const void *key, const void *data ); char *cap( const char *text ); /* includes.h */ #include #include #include #include #include #include #include #include #include "enviro.h" #include "cthing.h" #include "cintrpr.h" // Standard interpreter class template #include "csintrpr.h" // interpreter subclass declarations #include "uglobals.h" #include "cintrfcr.h" #include "ccmdr.h" #include "cscriptr.h" #include "cgintrpr.h" #include "globals.h" #include "utils.h" #define gPrintErr( A, B ) gInterfacer->PrintErr( A, B ) End of File.