- goto Lclearobj;
- }
- if (command.id1 == ENTER && command.id2 != WORD_NOT_FOUND && command.id2 != WORD_EMPTY) {
- command.id1 = command.id2;
- command.id2 = WORD_EMPTY;
- } else {
- /* FIXME: Magic numbers related to vocabulary */
- if (!((command.id1 != PROMOTE_WORD(WATER) && command.id1 != PROMOTE_WORD(OIL)) ||
- (command.id2 != PROMOTE_WORD(PLANT) && command.id2 != PROMOTE_WORD(DOOR)))) {
- if (AT(DEMOTE_WORD(command.id2)))
- command.wd2 = token_to_packed("POUR");
- }
- if (command.id1 == PROMOTE_WORD(CAGE) && command.id2 == PROMOTE_WORD(BIRD) && HERE(CAGE) && HERE(BIRD))
- command.wd1 = token_to_packed("CATCH");
- }
-Lookup:
- if (strncasecmp(command.raw1, "west", sizeof("west")) == 0) {
- if (++game.iwest == 10)
- rspeak(W_IS_WEST);
- }
- if (strncasecmp(command.raw1, "go", sizeof("go")) == 0 && !wordempty(command.wd2)) {
- if (++game.igo == 10)
- rspeak(GO_UNNEEDED);
- }
- packed_to_token(command.wd1, word1);
- defn = get_vocab_id(word1);
- if (defn == WORD_NOT_FOUND) {
- if (fallback_handler(command))
- continue;
- /* Gee, I don't understand. */
- sspeak(DONT_KNOW, command.raw1);
- goto Lclearobj;
- }
- /* FIXME: magic numbers related to vocabulary */
- kmod = MOD(defn, 1000);
- switch (defn / 1000) {
- case 0:
- playermove(kmod);
- return true;
- case 1:
- command.part = unknown;
- command.obj = kmod;
+ if (command.word[0].id == WORD_NOT_FOUND) {
+ /* Gee, I don't understand. */
+ sspeak(DONT_KNOW, command.word[0].raw);
+ clear_command(&command);
+ continue;
+ }
+
+ /* Give user hints of shortcuts */
+ if (strncasecmp(command.word[0].raw, "west", sizeof("west")) == 0) {
+ if (++game.iwest == 10)
+ rspeak(W_IS_WEST);
+ }
+ if (strncasecmp(command.word[0].raw, "go", sizeof("go")) == 0 && command.word[1].id != WORD_EMPTY) {
+ if (++game.igo == 10)
+ rspeak(GO_UNNEEDED);
+ }
+
+ switch (command.word[0].type) {
+ case MOTION:
+ playermove(command.word[0].id);
+ command.state = EXECUTED;
+ continue;
+ case OBJECT:
+ command.part = unknown;
+ command.obj = command.word[0].id;
+ break;
+ case ACTION:
+ if (command.word[1].type == NUMERIC)
+ command.part = transitive;
+ else
+ command.part = intransitive;
+ command.verb = command.word[0].id;
+ break;
+ case NUMERIC:
+ if (!settings.oldstyle) {
+ sspeak(DONT_KNOW, command.word[0].raw);
+ clear_command(&command);
+ continue;
+ }
+ break;// LCOV_EXCL_LINE
+ default: // LCOV_EXCL_LINE
+ case NO_WORD_TYPE: // LCOV_EXCL_LINE
+ BUG(VOCABULARY_TYPE_N_OVER_1000_NOT_BETWEEN_0_AND_3); // LCOV_EXCL_LINE
+ }
+
+ switch (action(command)) {
+ case GO_TERMINATE:
+ command.state = EXECUTED;
+ break;
+ case GO_MOVE:
+ playermove(NUL);
+ command.state = EXECUTED;
+ break;
+ case GO_WORD2:
+#ifdef GDEBUG
+ printf("Word shift\n");
+#endif /* GDEBUG */
+ /* Get second word for analysis. */
+ command.word[0] = command.word[1];
+ command.word[1] = empty_command_word;
+ command.state = PREPROCESSED;
+ break;
+ case GO_UNKNOWN:
+ /* Random intransitive verbs come here. Clear obj just in case
+ * (see attack()). */
+ command.word[0].raw[0] = toupper(command.word[0].raw[0]);
+ sspeak(DO_WHAT, command.word[0].raw);
+ command.obj = NO_OBJECT;
+
+ /* object cleared; we need to go back to the preprocessing step */
+ command.state = GIVEN;
+ break;
+ case GO_CHECKHINT: // FIXME: re-name to be more contextual; this was previously a label
+ command.state = GIVEN;
+ break;
+ case GO_DWARFWAKE:
+ /* Oh dear, he's disturbed the dwarves. */
+ rspeak(DWARVES_AWAKEN);
+ terminate(endgame);
+ case GO_CLEAROBJ: // FIXME: re-name to be more contextual; this was previously a label
+ clear_command(&command);
+ break;
+ case GO_TOP: // FIXME: re-name to be more contextual; this was previously a label
+ break;
+ default: // LCOV_EXCL_LINE
+ BUG(ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH); // LCOV_EXCL_LINE
+ }
+ } /* while command has not been fully processed */
+ } /* while command is not yet given */
+ } /* while command is not executed */
+
+ /* command completely executed; we return true. */
+ return true;
+}
+
+/*
+ * MAIN PROGRAM
+ *
+ * Adventure (rev 2: 20 treasures)
+ * History: Original idea & 5-treasure version (adventures) by Willie Crowther
+ * 15-treasure version (adventure) by Don Woods, April-June 1977
+ * 20-treasure version (rev 2) by Don Woods, August 1978
+ * Errata fixed: 78/12/25
+ * Revived 2017 as Open Adventure.
+ */
+
+int main(int argc, char *argv[])
+{
+ int ch;
+
+ /* Options. */
+
+#if defined ADVENT_AUTOSAVE
+ const char* opts = "dl:oa:";
+ const char* usage = "Usage: %s [-l logfilename] [-o] [-a filename] [script...]\n";
+ FILE *rfp = NULL;
+ const char* autosave_filename = NULL;
+#elif !defined ADVENT_NOSAVE
+ const char* opts = "dl:or:";
+ const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [script...]\n";
+ FILE *rfp = NULL;
+#else
+ const char* opts = "dl:o";
+ const char* usage = "Usage: %s [-l logfilename] [-o] [script...]\n";
+#endif
+ while ((ch = getopt(argc, argv, opts)) != EOF) {
+ switch (ch) {
+ case 'd': // LCOV_EXCL_LINE
+ settings.debug +=1; // LCOV_EXCL_LINE
+ break; // LCOV_EXCL_LINE
+ case 'l':
+ settings.logfp = fopen(optarg, "w");
+ if (settings.logfp == NULL)
+ fprintf(stderr,
+ "advent: can't open logfile %s for write\n",
+ optarg);
+ signal(SIGINT, sig_handler);
+ break;
+ case 'o':
+ settings.oldstyle = true;
+ settings.prompt = false;