Use the '=' operator (not memcpy()) to shallow-copy structs.
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index ba2f7d7597668f7c2eeb84292c76d6f41a405650..f2e107515a70d212a678a7f47757746d7c01562c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -968,7 +968,7 @@ static void listobjects(void)
 static bool do_command()
 /* Get and execute a command */
 {
-    static struct command_t command;
+    static command_t command;
 
     /*  Can't leave cave once it's closing (except by main office). */
     if (OUTSID(game.newloc) && game.newloc != 0 && game.closng) {
@@ -1051,18 +1051,29 @@ Lclearobj:
             game.knfloc = 0;
 
        /* Preserve state from last command for reuse when required */
-       struct command_t preserve;
-       memcpy(&preserve, &command, sizeof(struct command_t));
+       command_t preserve = command;
 
        // Get command input from user
         if (!get_command_input(&command))
             return false;
 
 #ifdef GDEBUG
-       printf("Preserve: type1 = %u, id1 = %ld, type2 = %u, id2 = %ld\n",
-              preserve.word[0].type, preserve.word[0].id, preserve.word[1].type, preserve.word[1].id);
-       printf("Command: type1 = %u, id1 = %ld, type2 = %u, id2 = %ld\n",
-              command.word[0].type, command.word[0].id, command.word[1].type, command.word[1].id);
+       /* Needs to stay synced with enum word_type_t */
+       const char *types[] = {"NO_WORD_TYPE", "MOTION", "OBJECT", "ACTION", "NUMERIC"};
+       /* needs to stay synced with enum speechpart */
+       const char *roles[] = {"unknown", "intransitive", "transitive"};
+       printf("Preserve: role = %s type1 = %s, id1 = %ld, type2 = %s, id2 = %ld\n",
+              roles[preserve.part],
+              types[preserve.word[0].type],
+              preserve.word[0].id,
+              types[preserve.word[1].type],
+              preserve.word[1].id);
+       printf("Command: role = %s type1 = %s, id1 = %ld, type2 = %s, id2 = %ld\n",
+              roles[command.part],
+              types[command.word[0].type],
+              command.word[0].id,
+              types[command.word[1].type],
+              command.word[1].id);
 #endif
 
        /* Handle of objectless action followed by actionless object */
@@ -1109,18 +1120,25 @@ Lclearobj:
                     command.word[0].id = ENTRANCE;
                 }
             }
-            if (!((command.word[0].id != WATER && command.word[0].id != OIL) || (command.word[1].id != PLANT && command.word[1].id != DOOR))) {
+            if ((command.word[0].id == WATER || command.word[0].id == OIL) && (command.word[1].id == PLANT || command.word[1].id == DOOR)) {
                 if (AT(command.word[1].id)) {
-                    command.word[1].id = POUR;
-                    command.word[1].type = ACTION;
-                    strncpy(command.word[1].raw, "POUR", LINESIZE - 1);
+                   command.word[1] = command.word[0];
+                   command.word[0].id = POUR;
+                    command.word[0].type = ACTION;
+                    strncpy(command.word[0].raw, "pour", LINESIZE - 1);
                 }
             }
             if (command.word[0].id == CAGE && command.word[1].id == BIRD && HERE(CAGE) && HERE(BIRD)) {
                 command.word[0].id = CARRY;
                 command.word[0].type = ACTION;
-                strncpy(command.word[1].raw, "CATCH", LINESIZE - 1);
             }
+
+           /* From OV to VO form */
+           if (command.word[0].type==OBJECT && command.word[1].type==ACTION) {
+               command_word_t stage = command.word[0];
+               command.word[0] = command.word[1];
+               command.word[1] = stage;
+           }
         }
 
 Lookup:
@@ -1167,13 +1185,12 @@ Lookup:
         case GO_TOP:
             continue;  /* back to top of main interpreter loop */
         case GO_WORD2:
+#ifdef GDEBUG
+           printf("Word shift\n");
+#endif /* GDEBUG */
             /* Get second word for analysis. */
-            command.word[0].id = command.word[1].id;
-            command.word[0].type = command.word[1].type;
-            strncpy(command.word[0].raw, command.word[1].raw, LINESIZE - 1);
-            command.word[1].id = WORD_EMPTY;
-            command.word[1].type = NO_WORD_TYPE;
-            command.word[1].raw[0] = '\0';
+           command.word[0] = command.word[1];
+           command.word[1] = empty_command_word;
             goto Lookup;
         case GO_UNKNOWN:
             /*  Random intransitive verbs come here.  Clear obj just in case