home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / games / adv / english.c < prev    next >
Text File  |  1988-08-24  |  3KB  |  170 lines

  1.  
  2. /*    program ENGLISH.C                    *\
  3. \*    WARNING: "advent.c" allocates GLOBAL storage space by    *\
  4. \*        including "advdef.h".                *\
  5. \*        All other modules use "advdec.h".        */
  6.  
  7.  
  8. #include    "stdio.h"    /* drv = 1.1st file 2.def 3.A    */
  9. #include    "advent.h"
  10. #include    "advdec.h"
  11.  
  12. /*
  13.     Analyze a two word sentence
  14. */
  15. english()
  16. {
  17.  
  18.     char    *msg;
  19.     int    type1, type2, val1, val2;
  20.  
  21.     verb = object = motion = 0;
  22.     type2 = val2 = -1;
  23.     type1 = val1 = -1;
  24.     msg = "bad grammar...";
  25.  
  26.     getwords();
  27.  
  28.     if (!(*word1))
  29.         return(0);        /* ignore whitespace    */
  30.     if (!analyze(word1, &type1, &val1))    /* check word1    */
  31.         return(0);        /* didn't know it    */
  32.  
  33.     if (type1 == 2 && val1 == SAY) {
  34.         verb = SAY;    /* repeat word & act upon if..    */
  35.         object = 1;
  36.         return(1);
  37.     }
  38.  
  39.     if (*word2)
  40.         if (!analyze(word2, &type2, &val2))
  41.             return(0);    /* didn't know it    */
  42.  
  43.     /* check his grammar */
  44.     if ((type1 == 3) && (type2 == 3) && \
  45.         (val1 == 51) && (val2 == 51)) {
  46.         outwords();
  47.         return(0);
  48.     }
  49.     else if (type1 == 3) {
  50.         rspeak(val1);
  51.         return(0);
  52.     }
  53.     else if (type2 == 3) {
  54.         rspeak(val2);
  55.         return(0);
  56.     }
  57.     else if (type1 == 0) {
  58.         if (type2 == 0) {
  59.             printf("%s\n", msg);
  60.             return(0);
  61.         }
  62.         else
  63.             motion = val1;
  64.     }
  65.     else if (type2 == 0)
  66.         motion = val2;
  67.     else if (type1 == 1) {
  68.         object = val1;
  69.         if (type2 == 2)
  70.             verb = val2;
  71.         if (type2 == 1) {
  72.             printf("%s\n", msg);
  73.             return(0);
  74.         }
  75.     }
  76.     else if (type1 == 2) {
  77.         verb = val1;
  78.         if (type2 == 1)
  79.             object = val2;
  80.         if (type2 == 2) {
  81.             printf("%s\n", msg);
  82.             return(0);
  83.         }
  84.     }
  85.     else
  86.         bug(36);
  87.     return(1);
  88. }
  89.  
  90.  
  91. /*
  92.         Routine to analyze a word.
  93. */
  94. analyze(word, type, value)
  95. char    *word;
  96. int    *type, *value;
  97. {
  98.     int    wordval, msg;
  99.  
  100.     /* make sure I understand */
  101.     if ((wordval = vocab(word, 0)) == -1) {
  102.         switch(rand() % 3) {
  103.         case 0:
  104.             msg = 60;
  105.             break;
  106.         case 1:
  107.             msg = 61;
  108.             break;
  109.         default:
  110.             msg = 13;
  111.         }
  112.         rspeak(msg);
  113.         return(0);
  114.     }
  115.     *type = wordval/1000;
  116.     *value = wordval%1000;
  117.     return(1);
  118. }
  119.  
  120. /*
  121.     retrieve input line (max 80 chars), convert to lower case
  122.      & rescan for first two words (max. WORDSIZE-1 chars).
  123. */
  124. getwords()
  125. {
  126.     char    words[80], *wptr;
  127.  
  128.     fputc('>', stdout);
  129.     word1[0] = word2[0] = '\0';
  130.     fgets(words, 80, stdin);
  131.     wptr = words;
  132.     while (*wptr = tolower(*wptr))
  133.         ++wptr;
  134.     sscanf(words, "%19s %19s", word1, word2);
  135.     if (dbugflg)
  136.         printf("WORD1 = %s, WORD2 = %s\n", word1, word2);
  137.     return;
  138. }
  139.  
  140. /*
  141.     output adventure word list (motion/0xxx & verb/2xxx) only
  142.     6 words/line pausing at 20th line until keyboard active
  143. */
  144. outwords()
  145. {
  146.     int    i, j, line;
  147.     char    words[80];
  148.  
  149.     j = line = 0;
  150.     for (i = 0; i < MAXWC; ++i) {
  151.         if ((wc[i].acode < 1000) || ((wc[i].acode < 3000) && \
  152.                                      (wc[i].acode > 1999))) {
  153.             printf("%-12s", wc[i].aword);
  154.             if ((++j == 6) || (i == MAXWC-1)) {
  155.                 j = 0;
  156.                 fputc('\n', stdout);
  157.                 if (++line == 20) {
  158.                     line = 0;
  159.                     printf("\n\007Enter <RETURN>");
  160.                     printf(" to continue\n\n");
  161.                     fgets(words, 80, stdin);
  162.                 }
  163.             }
  164.         }
  165.     }
  166. }
  167.  
  168.  
  169. 
  170.