home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GAMES / colossal.lzh / advent.c < prev    next >
C/C++ Source or Header  |  1991-06-08  |  5KB  |  215 lines

  1. /*    program ADVENT.C                    
  2. *
  3. *    WARNING: "advent.c" allocates GLOBAL storage space by    
  4. *        including "advdef.h".                
  5. *        All other modules use "advdec.h"        
  6. *
  7. *    Ported to OS9/68K by Martin Gregorie, who also added
  8. *    the help option.
  9. */
  10.  
  11.  
  12. #include    "stdio.h"    /* drv = 1.1st file 2.def 3.A    */
  13. #include    "advent.h"    /* #define preprocessor equates    */
  14. #include    "advword.h"    /* definition of "word" array    */
  15. #include    "advcave.h"    /* definition of "cave" array    */
  16. #include    "advtext.h"    /* definition of "text" arrays    */
  17. #include    "advdef.h"
  18.  
  19. extern    int            fclose();
  20. extern    int            fgetc();
  21. extern    FILE        *fopen();
  22. extern    long        ftell();
  23. extern    int            scanf();
  24. extern    int            sscanf();
  25. extern    char        *strcat();
  26. extern    unsigned    strlen();
  27. extern    int            tolower();
  28.  
  29. extern    int            saveadv();
  30. extern    int            restore();
  31.  
  32. main(argc, argv)
  33. int    argc;
  34. char    **argv;
  35. {
  36.     int    rflag;        /* user restore request option    */
  37.     
  38.     void showhelp();
  39.  
  40.     rflag = 0;
  41.     dbugflg = 0;
  42.     while (--argc > 0) {
  43.         ++argv;
  44.         if (**argv !=  '-')
  45.             break;
  46.         switch(tolower(argv[0][1])) {
  47.         case 'r':
  48.             ++rflag;
  49.             continue;
  50.         case 'd':
  51.             ++dbugflg;
  52.             continue;
  53.         case '?': 
  54.             showhelp();
  55.             exit(0);
  56.         default:
  57.             printf("unknown flag: %c\n", argv[0][1]);
  58.             continue;
  59.         }                /* switch    */
  60.     }                    /* while    */
  61.     if (dbugflg < 2)
  62.         dbugflg = 0;    /* must request three times    */
  63.     opentxt();
  64.     initplay();
  65.     if (rflag)
  66.         restore();
  67.     else if (yes(65, 1, 0))
  68.         limit = 1000;
  69.     else
  70.         limit = 330;
  71.     saveflg = 0;
  72.     srand(511);                /* seed random    */
  73.     while(!saveflg)
  74.         turn();
  75.     if (saveflg)
  76.         saveadv();
  77.     fclose(fd1);
  78.     fclose(fd2);
  79.     fclose(fd3);
  80.     fclose(fd4);
  81.     exit(0);                /* exit = ok    */
  82. }                        /* main        */
  83.  
  84. /* ************************************************************    */
  85.  
  86. /*
  87.     Initialize integer arrays with sscanf
  88. */
  89. scanint(pi, str)
  90. int    *pi;
  91. char    *str;
  92. {
  93.  
  94.     while (*str) {
  95.         if  ((sscanf(str, "%d,", pi++)) < 1)
  96.             bug(41);    /* failed before EOS    */
  97.         while (*str++ != ',')    /* advance str pointer    */
  98.             ;
  99.     }
  100.     return 0;
  101. }
  102.  
  103. /*
  104.     Initialization of adventure play variables
  105. */
  106. initplay()
  107. {
  108.     turns = 0;
  109.  
  110.     /* initialize location status array */
  111.     setmem(cond, (sizeof(int))*MAXLOC, 0);
  112.     scanint(&cond[1], "5,1,5,5,1,1,5,17,1,1,");
  113.     scanint(&cond[13], "32,0,0,2,0,0,64,2,");
  114.     scanint(&cond[21], "2,2,0,6,0,2,");
  115.     scanint(&cond[31], "2,2,0,0,0,0,0,4,0,2,");
  116.     scanint(&cond[42], "128,128,128,128,136,136,136,128,128,");
  117.     scanint(&cond[51], "128,128,136,128,136,0,8,0,2,");
  118.     scanint(&cond[79], "2,128,128,136,0,0,8,136,128,0,2,2,");
  119.     scanint(&cond[95], "4,0,0,0,0,1,");
  120.     scanint(&cond[113], "4,0,1,1,");
  121.     scanint(&cond[122], "8,8,8,8,8,8,8,8,8,");
  122.  
  123.     /* initialize object locations */
  124.     setmem(place, (sizeof(int))*MAXOBJ, 0);
  125.     scanint(&place[1], "3,3,8,10,11,0,14,13,94,96,");
  126.     scanint(&place[11], "19,17,101,103,0,106,0,0,3,3,");
  127.     scanint(&place[23], "109,25,23,111,35,0,97,");
  128.     scanint(&place[31], "119,117,117,0,130,0,126,140,0,96,");
  129.     scanint(&place[50], "18,27,28,29,30,");
  130.     scanint(&place[56], "92,95,97,100,101,0,119,127,130,");
  131.  
  132.     /* initialize second (fixed) locations */
  133.     setmem(fixed, (sizeof(int))*MAXOBJ, 0);
  134.     scanint(&fixed[3], "9,0,0,0,15,0,-1,");
  135.     scanint(&fixed[11], "-1,27,-1,0,0,0,-1,");
  136.     scanint(&fixed[23], "-1,-1,67,-1,110,0,-1,-1,");
  137.     scanint(&fixed[31], "121,122,122,0,-1,-1,-1,-1,0,-1,");
  138.     scanint(&fixed[62], "121,-1,");
  139.  
  140.     /* initialize default verb messages */
  141.     scanint(actmsg, "0,24,29,0,33,0,33,38,38,42,14,");
  142.     scanint(&actmsg[11], "43,110,29,110,73,75,29,13,59,59,");
  143.     scanint(&actmsg[21], "174,109,67,13,147,155,195,146,110,13,13,");
  144.  
  145.     /* initialize various flags and other variables */
  146.     setmem(visited, (sizeof(int))*MAXLOC, 0);
  147.     setmem(prop, (sizeof(int))*MAXOBJ, 0);
  148.     setmem(&prop[50], (sizeof(int))*(MAXOBJ-50), 0xff);
  149.     wzdark = closed = closing = holding = detail = 0;
  150.     limit = 100;
  151.     tally = 15;
  152.     tally2 = 0;
  153.     newloc = 3;
  154.     loc = oldloc = oldloc2 = 1;
  155.     knfloc = 0;
  156.     chloc = 114;
  157.     chloc2 = 140;
  158. /*    dloc[DWARFMAX-1] = chloc                */
  159.     scanint(dloc, "0,19,27,33,44,64,114,");
  160.     scanint(odloc, "0,0,0,0,0,0,0,");
  161.     dkill = 0;
  162.     scanint(dseen, "0,0,0,0,0,0,0,");
  163.     clock = 30;
  164.     clock2 = 50;
  165.     panic = 0;
  166.     bonus = 0;
  167.     numdie = 0;
  168.     daltloc = 18;
  169.     lmwarn = 0;
  170.     foobar = 0;
  171.     dflag = 0;
  172.     gaveup = 0;
  173.     saveflg = 0;
  174.     return 0;
  175. }
  176.  
  177. /*
  178.     Open advent?.txt files
  179. */
  180. opentxt()
  181. {
  182.     fd1 = fopen("advent1.txt", TEXTREAD);
  183.     if (!fd1) {
  184.         printf("Sorry, I can't open advent1.txt...\n");
  185.         exit(0);
  186.     }
  187.     fd2 = fopen("advent2.txt", TEXTREAD);
  188.     if (!fd2) {
  189.         printf("Sorry, I can't open advent2.txt...\n");
  190.         exit(0);
  191.     }
  192.     fd3 = fopen("advent3.txt", TEXTREAD);
  193.     if (!fd3) {
  194.         printf("Sorry, I can't open advent3.txt...\n");
  195.         exit(0);
  196.     }
  197.     fd4 = fopen("advent4.txt", TEXTREAD);
  198.     if (!fd4) {
  199.         printf("Sorry, I can't open advent4.txt...\n");
  200.         exit(0);
  201.     }
  202. }
  203.  
  204.  
  205. void showhelp()
  206. {
  207.     printf("\nSyntax  : advent <options>\n");
  208.     printf("Function: Run the Colossal Cavern adventure game;\n");
  209.     printf("          the grandaddy of them all.\n");
  210.     printf("Options:\n");
  211.     printf("          -r         restart a saved game\n");
  212.     printf("          -d         debug mode (must occur 3 times to ");
  213.     printf("take effect)\n");
  214. }
  215.